akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

int w, h, t, p;
int field[1000][1000];

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    while (1)
    {
        cin >> w >> h >> t >> p;
        if (w == 0)
            break;
        rep(i, 1000) rep(j, 1000) field[i][j] = 0;
        rep(i, h) rep(j, w) field[i][j] = 1;
        int oy = 0, ox = 0;
        rep(i, t)
        {
            int d, c;
            cin >> d >> c;
            if (d == 1) //横
            {
                int l = ox + c - 1, r = ox + c;
                rep(j, c)
                {
                    rep(k, 1000)
                    {
                        field[k][r + j] += field[k][l - j];
                        field[k][l - j] = 0;
                    }
                }
                ox += c;
            }
            else //縦
            {
                int l = oy + c - 1, r = oy + c;
                rep(j, c)
                {
                    rep(k, 1000)
                    {
                        field[r + j][k] += field[l - j][k];
                        field[l - j][k] = 0;
                    }
                }
                oy += c;
            }
        }
        rep(i, p)
        {
            int x, y;
            cin >> x >> y;
            cout << field[oy + y][ox + x] << endl;
        }
    }
}



Measured memory_bytes: 10936
from collections import deque
n = int(input())
l = [[] for i in range(n)]
for i in range(n-1):
    u,v,w = map(int,input().split())
    l[u-1].append([v-1,w])
    l[v-1].append([u-1,w])
l2 = [0 for i in range(n)]
ans = [0 for i in range(n)]
q = deque()
q.append([0,0])
while q:
    x,y = q.popleft()
    if l2[x] == 0:
        l2[x] = 1
        ans[x] = y
        for i,j in l[x]:
            if l2[i] == 0:
                q.append([i,y+j])
for i in range(n):
    print(ans[i]%2)

Measured memory_bytes: 50224
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

/**
 * AOJ id=0118
 * PropertyDistribution
 * @author scache
 *
 */
public class Main {
	public static void main(String[] args) {
		Main p = new Main();
	}
	
	char[][] field;
	public Main(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int h = sc.nextInt();
			int w = sc.nextInt();
			if(h==0 && w==0)
				break;
			
			field = new char[h+2][w+2];
			for(int i=1;i<=h;i++){
				String line = sc.next();
				for(int j=1;j<=w;j++){
					field[i][j] = line.charAt(j-1);
				}
			}
			for(int i=0;i<h+2;i++){
				field[i][0] = 'a';
				field[i][w+1] = 'a';
			}
			for(int i=0;i<w+2;i++){
				field[0][i]='a';
				field[h+1][i] = 'a';
				
			}
			
			solve(h, w);
		}
	}
		
	private void solve2(int h, int w){
		int res = 0;
		for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++){
				if(field[i][j]!='a'){
					res++;
					rec(j, i);
				}
			}
		}
		
		System.out.println(res);
	}
	
	
	int[] dx = {-1, 0, 1, 0};
	int[] dy = {0, -1, 0, 1};
	private void rec(int x, int y){
		char cur = field[y][x];
		field[y][x]='a';

		for(int i=0;i<4;i++){
			int nx = x+dx[i];
			int ny = y+dy[i];
			if(field[ny][nx]==cur){
				rec(nx, ny);
			}
		}
	}
	
	private void solve(int h, int w){
		int res = 0;
		Queue<int[]> q = new ArrayDeque<int[] >();
		for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++){
				if(field[i][j] != 'a'){
					res++;
					char c = field[i][j];
					q.add(new int[]{j, i});
					
					while(!q.isEmpty()){
						int[] cur = q.poll();
						for(int k=0;k<4;k++){
							int nx = cur[0]+dx[k];
							int ny = cur[1]+dy[k];
							if(field[ny][nx]==c){
								field[ny][nx] = 'a';
								q.add(new int[]{nx, ny});
								
							}
						}
					}
					
				}
			}
		}
		System.out.println(res);
	}
}

Measured memory_bytes: 20736
/*
    author: kartik8800
*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fr(a,b) for(ll i = a; i < b; i++)
#define mod 1000000007
#define inf (1LL<<60)
#define all(x) (x).begin(), (x).end()
#define prDouble(x) cout << fixed << setprecision(10) << x 
#define triplet pair<ll,pair<ll,ll>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;

struct flower
{
    ll hi;
    ll bty;
};

ll solve(vector<flower>& v, int n)
{
    vector<ll> dp(n+1);
    map<ll,ll> meaningful;
    dp[1] = v[1].bty;
    meaningful[v[1].hi] = dp[1];
    ll ans = dp[1];

    for(int i = 2; i <= n; i++)
    {
        dp[i] = v[i].bty;
        auto it = meaningful.lower_bound(v[i].hi + 1);
        if(it != meaningful.begin())
        {
            it--;
            dp[i] += it->second;
        }        
        meaningful[v[i].hi] = dp[i];
        it = meaningful.upper_bound(v[i].hi);
        while(it!=meaningful.end() && it->second <= dp[i])
        {
            auto temp = it;
            temp++;
            meaningful.erase(it);
            it = temp;
        }
        ans = max(ans, dp[i]);
    }
    return ans;
}


int main() {
   int n;
   cin >> n ;
   vector<flower> v(n+1); 
   for(int i = 1; i <= n; i++)
        cin >> v[i].hi;
   for(int i = 1; i <= n; i++)
        cin >> v[i].bty;
   cout << solve(v, n);
   return 0;
}


Measured memory_bytes: 17408
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> h(n);
  int i;
  for(i=0;i<n;i++){
    cin >> h.at(i);
  }
  string s="Yes";
  for(i=0;i<n-1;i++){
    if(h.at(i)<h.at(i+1)){
      h.at(i+1)-=1;
    }
    if(h.at(i)>h.at(i+1)){
      s="No";
    }
  }
  cout << s;
}


Measured memory_bytes: 768
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;
const int MAXN = 3100;
const int MOD = 1e9 + 7;

int n, m;
string s, s0;
int mn[MAXN];
int mx[MAXN];
int dp[MAXN][MAXN];
int l[MAXN];
int r[MAXN];

void add(int &a, int b) {
	a += b;
	if (a >= MOD)
		a -= MOD;
}

int main() {
	cin >> n >> m;
	cin >> s;
	for (int i = 0; i < m; ++i)
		cin >> l[i] >> r[i], --l[i];
	s0 = s;
	for (int i = 0; i < m; ++i)
		sort(s0.begin() + l[i], s0.begin() + r[i]);
	int now = 0;
	mn[0] = 0;
	for (int i = 0; i < n; ++i) {
		now += (s0[i] == '1' ? 1 : 0);
		mn[i + 1] = now;
	}
	s0 = s;
	for (int i = 0; i < m; ++i) {
		sort(s0.begin() + l[i], s0.begin() + r[i]);
		reverse(s0.begin() + l[i], s0.begin() + r[i]);
	}
	now = 0;
	mx[0] = 0;
	for (int i = 0; i < n; ++i) {
		now += (s0[i] == '1' ? 1 : 0);
		mx[i + 1] = now;
	}
	dp[0][0] = 1;
	for (int i = 0; i < n; ++i) {
		for (int j = mn[i]; j <= mx[i]; ++j) {
			if (j >= mn[i + 1] && j <= mx[i + 1])
				add(dp[i + 1][j], dp[i][j]);
			if (j + 1 >= mn[i + 1] && j + 1 <= mx[i + 1])
				add(dp[i + 1][j + 1], dp[i][j]);
		}
	}
	cout << dp[n][mn[n]] << "\n";
	return 0;
}




Measured memory_bytes: 12544
K,N = map(int,input().split())
A = list(map(int,input().split()))

L = []
for i in range(N-1):
  l = abs(A[i]-A[i+1])
  L.append(l)

b = K -abs(A[0]-A[N-1])
L.append(b)

ans = K - max(L)

print(ans)



Measured memory_bytes: 26420
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;

int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    if(A==B){
        cout << 1;
        return 0;
    }
    if(N==1){
        cout << 0;
        return 0;
    }
    if(A>B){
        cout << 0;
        return 0;
    }
    if(N==2){
        cout << 1;
        return 0;
    }
    cout << (A+B*(N-1))-(B+A*(N-1))+1;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long

ll mod = 1e9+7;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    if (A[0] != 0) {
        cout << 0 << endl;
        return 0;
    }
    
    vector<int> same(100000, 0);
    same[0] = 1;
    ll ans = 3;
    ll used = 1;
    for (int i = 1; i < N; i++) {
        if (A[i] == 0) {
            if (used >= 3) {
                cout << 0 << endl;
                return 0;
            }
            ans *= 3-used;
            ans %= mod;
            used++;
            same[0]++;
        }
        else {
            ans *= same[A[i]-1];
            ans %= mod;
            same[A[i]-1]--;
            same[A[i]]++;
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1024
////////////////////////////////////////////////////////////////////
// This source code is for Visual Studio
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <stack>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <deque>
#include <math.h>

#define	numberof(a)	(sizeof(a) / sizeof(a[0]))
#define	INF		UINT64_MAX
#define Rep(i,n) for(int i = 0; i < (n); ++i )

using namespace std;

typedef vector< vector<int> > MAT;
typedef pair<int, int> PINT;
typedef long long ll;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int32_t s32;
typedef int64_t s64;

int main()
{
	string S = "";
	string ret = "";

	cin >> S;
	ret = S.substr(0, S.length() - 8);

	cout << ret << endl;

	return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num,init) vector<ll> name((num),(init));
#define op(i) cout<<(i)<<endl;
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define mat(name,fnum,snum,init); vector<vector<ll>> name((fnum),vector<ll>((snum),(init)));

int main(){
    ll n;
    cin>>n;
    mat(c,2,n,0);
    rep(i,2){
        rep(j,n){
            cin>>c[i][j];
        }
    }    
    ll ans=LLONG_MIN;
    rep(i,n){
        ll tmp=0;
        rep(j,i+1){
            tmp+=c[0][j];
        }
        repf(j,i,n){
            tmp+=c[1][j];
        }
        ans=max(ans,tmp);
    }
    op(ans);
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define MOD = 998244353;
#define int long long int
#define double long double
#define inf (int)(1e15)
#define all(x) (x).begin(), (x).end()
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define isYes(x) printf("%s\n", (x) ? "Yes" : "No")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define isIn(x, y, h, w) (x >= 0 && x < h && y >= 0 && y < w)
#define pair pair<int, int>
typedef vector<int> vi;   // Vector of long long
typedef vector<vi> vvi;   // Vector of vi
typedef vector<pair> vii; // Vector of pairs
typedef vector<vii> vvii; // Vector of Vector of pairs
typedef vector<bool> vb;  // Vector of bool
#define pq priority_queue // Max heap (To convert to min heap, use negative sign before every value)
#define ff first          // For pairs
#define ss second
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, -1, 0, 1};
const int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}, dy8[] = {1, -1, 1, 0, -1, 1, -0, -1};
#define testcases(t) \
    int(t);          \
    cin >> (t);      \
    while ((t)--)
#define range(c, r) (c).begin(), (c).begin() + (r)    // Mainly used in sorting
#define present(c, x) ((c).find(x) != (c).end())      // for sets, maps, multi-maps
#define cpresent(c, x) (find(all(c), x) != (c).end()) // for vectors
#define run(x, c) for ((x) = (c).begin(); (x) != (c).end(); (x)++)
#define fo0 (i, n) for (i = 0; i < n; i++)
#define fo1 (i, n) for (i = 1; i <= n; i++)
#define rfo(i, n) for (i = n - 1; i >= 0; i--)
#define rfor(i, n) for (i = n; i > 0; i--)
vi a(100), b(100), c(100), d(100), seq;
int n, m, q, ans = 0;
void solve(int i)
{
    if (i == n)
    {
        int temp = 0;
        for (int i = 0; i < q; i++)
        {
            if ((seq[b[i] - 1] - seq[a[i] - 1]) == c[i])
                temp += d[i];
        }
        ans = max(ans, temp);
        return;
    }
    int j;
    if (seq.empty())
        j = 1;
    else
        j = seq.back();
    for (; j <= m; j++)
    {
        seq.pb(j);
        solve(i + 1);
        seq.pop_back();
    }
    return;
}
signed main()
{
    cin >> n >> m >> q;
    for (int i = 0; i < q; i++)
    {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    solve(0);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
using namespace std;
#include<map>
#include<unordered_map>
#include<vector>
#include<cmath>
#include<set>
#include<algorithm>
#define int long long int
#define mod 1000000007
int power(int a,int b)
{
	int x=pow(a,b);
	return x;
}
int function2(int arr[],int initial,int final,int mat[][13],int value,int total,int n,int memo[][4101])
{
	if(initial>final)
	{
		if(value==total)
		   return 0;
		else
		   return 1000000000;
	}
	if(memo[initial][value]!=-1)
	    return memo[initial][value];
	else
	{
		int newval=value;
		int j;
		for(j=0;j<n;j++)
		{
			if(mat[initial][j]==1)
			{
				newval|=power(2,j);
			}
		}
		int x=arr[initial]+function2(arr,initial+1,final,mat,newval,total,n,memo);
		int y=function2(arr,initial+1,final,mat,value,total,n,memo);
		memo[initial][value]=min(x,y);
		return memo[initial][value];
	}
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	int position[n+1];
	int j;
	int arr[n+1];
	for(j=1;j<=n;j++)
	{
		cin>>arr[j];
		position[arr[j]]=j;
	}
	for(j=1;j<=n;j++)
	{
		cout<<position[j]<<" ";
	}
	cout<<endl;
}


Measured memory_bytes: 5104
//long time no ac
#include <bits/stdc++.h>
using namespace std;

#define 	ll				long long
#define 	vii				vector<int>
#define		rep(i,n) 		for(i=0;i<n;i++)
#define		repe(i,I1,I2) 	for(i=I1;i<I2;i++)
#define		INF  			1e9 + 7
#define		pb  			push_back
#define		mp  			make_pair
#define		endl			'\n'
#define 	mod				1000000007


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,k,t,c=0,i,j,m;
	t=1;
	//cin>>t;
	
	while(t--)
	{
		cin>>n>>m;
		string s[n];
		rep(i,n)
		{
			cin>>s[i];
		}
		rep(i,n)
		{
			rep(j,m)
			{
				if(s[i][j]=='#')
				{
					if( (i>0 && s[i-1][j]=='#') || (i<n-1 && s[i+1][j]=='#') || (j>0 && s[i][j-1]=='#') || (j<n-1 && s[i][j+1]=='#'))
					{
						continue;
					}
					c=1;
					break;
				}
			}
		}
		if (c==1)
		{

			cout<<"No";
			/* code */
		}
		else
			cout<<"Yes";
		if(t!=0)
	   		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <functional>
#include <tuple>
using namespace std;

int A, B, d[100][100], e[100][100]; bool used[100][100]; vector<tuple<int, int, int>>X;

int main() {
	cin >> A >> B;
	for (int i = 1; i <= A; i++) {
		for (int j = 1; j <= B; j++) cin >> d[i][j];
	}
	for (int i = 1; i <= A; i++) {
		for (int j = 1; j <= B; j++) {
			if (used[i][j] == true) continue;
			bool flag2 = false;
			for (int k = 0; k <= 100; k++) {
				int P1 = i*k; if (P1 > d[i][j]) continue;
				for (int l = 0; l <= 100; l++) {
					int P2 = j*l; if (P1 + P2 > d[i][j]) continue;
					int X1 = k, X2 = l, X3 = d[i][j] - P1 - P2;
					
					bool flag = true;
					for (int m = 1; m <= A; m++) {
						for (int n = 1; n <= B; n++) {
							int K = m*X1 + n*X2 + X3;
							if (d[m][n] > K) { flag = false; break; }
						}
						if (flag == false) break;
					}
					if (flag == true) {
						X.push_back(make_tuple(X1, X2, X3));
						for (int m = 1; m <= A; m++) {
							for (int n = 1; n <= B; n++) {
								int K = m*X1 + n*X2 + X3;
								if (d[m][n] == K) used[m][n] = true;
							}
						}
						flag2 = true;
						break;
					}
				}
				if (flag2 == true) break;
			}
			if (flag2 == false) {
				cout << "Impossible" << endl;
				return 0;
			}
		}
	}
	vector<tuple<int, int, string>>G;
	for (int i = 1; i <= 100; i++) G.push_back(make_tuple(i, i + 1, "X"));
	for (int i = 102; i <= 201; i++) G.push_back(make_tuple(i, i + 1, "Y"));
	for (int i = 0; i < X.size(); i++) {
		G.push_back(make_tuple(get<0>(X[i]) + 1, 202 - get<1>(X[i]), to_string(get<2>(X[i]))));
	}
	cout << "Possible" << endl;
	cout << "202 " << G.size() << endl;
	for (int i = 0; i < G.size(); i++) {
		cout << get<0>(G[i]) << " " << get<1>(G[i]) << " " << get<2>(G[i]) << endl;
	}
	cout << "1 202" << endl;
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
INF = 10 ** 20
edgeList = []
dist = [[INF] * n for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    dist[a][b] = dist[b][a] = c
    edgeList.append((a, b, c))

for k in range(n):
    for i in range(n):
        for j in range(n):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

print(sum([dist[a][b] < c for a, b, c in edgeList]))

Measured memory_bytes: 3560
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;

#define rp(i,t) for(int i=0;i<(t);i++)
#define rep(i,s,t) for(int i=(s);i<=(t);i++)
#define rsp(i,s,t) for(int i=(s);i<(t);i++)
#define rrp(i,t,s) for(int i=(t);i>=(s);i--)
#define rcp(i,s,b,d) for(int i=(s);b;d)
#define mst(a,x) memset(a,x,sizeof(a))
#define INF 0x3f3f3f3f
#define N

#define Dp puts("")
#define Dw printf
#define Ds printf("#")

typedef long long ll;
char ch;
int n,x,sgl,two,four;

inline void read(int &x){x=0;do{ch=getchar();}while(ch<'0'||'9'<ch);do{x=x*10+ch-'0';ch=getchar();}while('0'<=ch&&ch<='9');}

int main(void)
{
	read(n);
	rep(i,1,n)
	{
		read(x);
		if((x&3)==0)four++;
		else if((x&1)==0)two++;
		else sgl++;
	}
	if(four==sgl-1&&two==0)puts("Yes");
	else if(four>=sgl)puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;

int A[1000][1000]={{}};
int b[1000]={};

int main(void){
   int n, m, i, j;
   int sum;
   
   
   cin >> n >> m;
 
   for(i=0; i<n; i++){
       for(j=0;j<m;j++){
           cin >> A[i][j];
       }
   }
   
   for(i=0; i<m; i++){
       cin >>b[i];
   }
   
  
   for(i=0; i<n; i++){
       sum = 0;
       for(j=0; j<m; j++){
           sum += A[i][j] * b[j];
       }
       cout << sum << endl;
   }
}



Measured memory_bytes: 3448
/*
How to lambda
  ex) sort(ALL(cont),[](dat a,dat b){return a.l<b.l;});
lower_bound/upper_bound
  1 2 2 2 3 3 
    ^lb   ^ub */
#include <bits/stdc++.h>
#define BR "\n"
#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a,b) ((((a) % (b) ) + (b)) % (b))
#define FEACH(it,cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it,cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
  cout << fixed << setprecision(10);
  string S;
  cin >> S;
  int cb=0;
  FEACH(it,S)
    if (*it=='B')
      cb++;
  ll ans=0;
  for(int i=0;i<S.length();++i) {
    if (S[i]=='B') {
      ans += S.length()-cb-i;
      cb--;
    }
  }
  cout << ans<<endl;

  return 0;
}


Measured memory_bytes: 640
N , X = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
A = [0] + A
for i in range(N):
  A[i+1] = A[i]+A[i+1]
  if A[i+1]>X:
    break
if i==N-1 and X==A[N]:
  print(N)
else:
  print(i)


Measured memory_bytes: 9188
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        String s = String.valueOf(n);
        for(int i=0;i<s.length();i++){
        if (s.charAt(i) == '7') {
            System.out.println("Yes");
           return;  
        }
        }
            System.out.println("No");
      
      
    }

}


Measured memory_bytes: 27044
#include <bits/stdc++.h>
using namespace std;

int main() {
    int a, b, k;
    cin >> a >> b >> k;

    for (int i = a; i <= b; i++) {
        if (i < a + k) {
            cout << i << endl;
        } else if (i > b - k) {
            cout << i << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if (s.equals("ABC")) {
            System.out.println("ARC");
        } else {
            System.out.println("ABC");
        }
    }

}


Measured memory_bytes: 35620
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    string s; cin>>s;
    int sl=s.size();
    int naka=0;
    if(sl%2==0){
        int mid=sl/2-1,now1=sl/2-1,now2=sl/2;
        naka=0;
        while(naka<=sl-2 && s[mid]==s[now1] && s[mid]==s[now2]){
            now1--; now2++;
            naka+=2;
        }
    }else{
        int mid=sl/2,now1=mid-1,now2=mid+1;
        naka=1;
        while(naka<=sl-2 && s[mid]==s[now1] && s[mid]==s[now2]){
            now1--; now2++;
            naka+=2;
        }
        
    }
    cout<<(sl+naka)/2;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD =1e9+7;
using ll=long long;
using Graph = vector<vector<int>>;

int main() {
    int n;
    cin >> n;
    vector<int> cnt(3);
    rep(i,n){
        string J;
        cin >> J;
        if(J=="AC") cnt[0]++;
        if(J=="WA") cnt[1]++;
        if(J=="TLE") cnt[2]++;
        if(J=="RE") cnt[3]++;
    }
    cout << "AC" << " " << "x" << " " << cnt[0] << endl;
    cout << "WA" << " " << "x" << " " << cnt[1] << endl;
    cout << "TLE" << " " << "x" << " " << cnt[2] << endl;
    cout << "RE" << " " << "x" << " " << cnt[3] << endl;
}

Measured memory_bytes: 3628
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	R, C, K := io.NextInt(), io.NextInt(), io.NextInt()
	values := make([][]int, R)
	for i := range values {
		values[i] = make([]int, C)
	}
	for i := 0; i < K; i++ {
		ri, ci, vi := io.NextInt()-1, io.NextInt()-1, io.NextInt()
		values[ri][ci] = vi
	}
	ans := solve(values)
	io.Println(ans)
}

func solve(values [][]int) int {
	R, C, L := len(values), len(values[0]), 3
	dp := make([][][]int, R)
	for i := range dp {
		dp[i] = make([][]int, C)
		for j := range dp[i] {
			dp[i][j] = make([]int, L+1)
		}
	}
	dp[0][0][1] = values[0][0]
	for i := 0; i < R; i++ {
		for j := 0; j < C; j++ {
			for l := 0; l < L+1; l++ {
				if i+1 < R {
					dp[i+1][j][0] = Max(dp[i+1][j][0], dp[i][j][l])
					dp[i+1][j][1] = Max(dp[i+1][j][1], dp[i][j][l]+values[i+1][j])
				}
				if j+1 < C {
					dp[i][j+1][l] = Max(dp[i][j+1][l], dp[i][j][l])
					if l+1 < L+1 {
						dp[i][j+1][l+1] = Max(dp[i][j+1][l+1], dp[i][j][l]+values[i][j+1])
					}
				}
			}
		}
	}
	return Max(dp[R-1][C-1]...)
}

// Max returns max value of inputs
func Max(a ...int) (max int) {
	for i, ai := range a {
		if i == 0 || ai > max {
			max = ai
		}
	}
	return max
}

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// NextInt returns an integer from stdin
func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


Measured memory_bytes: 598780
import sys

abcd = input()

n = len(abcd)-1
xx = abcd
for x in range(2**n):
    j = 0
    abcd = list(abcd)
    for i in range(n):
        if (x>>i)&1:
            abcd.insert(i+j+1, "+")
            j += 1

        else:
            abcd.insert(i+j+1, "-")
            j += 1

    abcd = "".join(abcd)
    sum = eval(abcd)
    if sum==7:
        print(abcd+"=7")
        sys.exit()

    abcd = xx






Measured memory_bytes: 3064
#include <algorithm>
#include <deque>
#include <iostream>
#include <optional>
#include <vector>

#define REP(i, n) for (decltype(n) i = 0; i < (n); ++i)
using namespace std;
using i64 = long long;
using u64 = unsigned long long;

int N, M;
i64 INF = 1LL << 60;

optional<u64> bfs(const vector<i64>& xv, const vector<i64>& yv,
                  vector<vector<char>>& grid) {
  vector<tuple<int, int>> steps{{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
  deque<tuple<int, int>> que;
  int c0 = lower_bound(xv.begin(), xv.end(), 0) - xv.begin();
  int r0 = lower_bound(yv.begin(), yv.end(), 0) - yv.begin();
  que.emplace_back(2 * r0 + 1, 2 * c0 + 1);

  while (que.size()) {
    const auto& [r, c] = que.front();
    que.pop_front();
    for (const auto& [dr, dc] : steps) {
      int rn = r + dr, cn = c + dc;
      if (rn < 0 || rn >= int(grid.size()) || cn < 0 ||
          cn >= int(grid[0].size())) {
        return nullopt;
      }
      if (grid[rn][cn] != 0) {
        continue;
      }
      grid[rn][cn] = 1;
      que.emplace_back(rn, cn);
    }
  }

  u64 area = 0;
  REP(r, yv.size()) {
    REP(c, xv.size()) {
      char s = grid[2 * r + 1][2 * c + 1];
      if (s == 1) {
        area += (xv[c + 1] - xv[c]) * (yv[r + 1] - yv[r]);
      }
    }
  }
  return area;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> N >> M;
  vector<tuple<i64, i64, i64>> verticals(N);
  vector<tuple<i64, i64, i64>> horizontals(M);
  vector<i64> xv, yv;
  xv.reserve(N + 2 * M + 10);
  yv.reserve(2 * N + M + 10);
  xv.push_back(0);
  yv.push_back(0);
  yv.push_back(INF);
  yv.push_back(-INF);
  REP(i, N) {  // vertical lines
    i64 a, b, c;
    cin >> a >> b >> c;
    verticals[i] = make_tuple(a, b, c);
    yv.push_back(a);
    yv.push_back(b);
    xv.push_back(c);
  }
  REP(i, M) {  // horizontal lines
    i64 d, e, f;
    cin >> d >> e >> f;
    horizontals[i] = make_tuple(d, e, f);
    yv.push_back(d);
    xv.push_back(e);
    xv.push_back(f);
  }
  sort(xv.begin(), xv.end());
  xv.erase(unique(xv.begin(), xv.end()), xv.end());
  sort(yv.begin(), yv.end());
  yv.erase(unique(yv.begin(), yv.end()), yv.end());
  vector<vector<char>> grid(yv.size() * 2, vector<char>(xv.size() * 2, 0));
  REP(i, N) {
    auto [a, b, c] = verticals[i];
    int r1 = lower_bound(yv.begin(), yv.end(), a) - yv.begin();
    int r2 = lower_bound(yv.begin(), yv.end(), b) - yv.begin();
    int ci = lower_bound(xv.begin(), xv.end(), c) - xv.begin();
    for (int rd = 2 * r1; rd < 2 * r2; ++rd) {
      grid[rd][2 * ci] = 2;
    }
  }
  REP(i, M) {
    auto [d, e, f] = horizontals[i];
    int ri = lower_bound(yv.begin(), yv.end(), d) - yv.begin();
    int c1 = lower_bound(xv.begin(), xv.end(), e) - xv.begin();
    int c2 = lower_bound(xv.begin(), xv.end(), f) - xv.begin();
    for (int cd = 2 * c1; cd < 2 * c2; ++cd) {
      grid[2 * ri][cd] = 2;
    }
  }

  auto result = bfs(xv, yv, grid);
  if (!result) {
    cout << "INF" << endl;
  } else {
    cout << *result << endl;
  }
}


Measured memory_bytes: 38812
#include<stdio.h>

int main(){
	int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        if(a<b){
            if(b<c){
                printf("%d %d %d\n",a,b,c);
            }else if(c>a){
                printf("%d %d %d\n",c,a,b);
            }else{
                printf("%d %d %d\n",a,c,b);
            }
        }
        if(a>b){
            if(b>c){
                printf("%d %d %d\n",c,b,a);
            }else if(c>a){
                printf("%d %d %d\n",b,a,c);
            }else{
                printf("%d %d %d\n",b,c,a);
            }
        }
	return 0;
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int N, D;
  	cin >> N >> D;
  	int X, Y;
  	
   int  res = 0;
  	for(int i=0;i<N;i++){
    	cin >> X >> Y;
      
      if(pow(D, 2.0) >= pow(X, 2.0) + pow(Y, 2.0)) res++;
    }
  	cout << res << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  while (true) {
    int n;
    cin >> n;

    if (n == 0) {
      break;
    }
    
    vector<string> w(n);
    for (int i = 0; i < n; i++) {
      cin >> w[i];
    }

    int cnt1 = 0;
    int cnt2 = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i; j < n; j++) {
	cnt2 += w[j].size();
	if ((cnt1 == 0 || cnt1 == 2) && cnt2 > 5 || cnt2 > 7) {
	  cnt1 = 0;
	  cnt2 = 0;
	  break;
	}

	if ((cnt1 == 0 || cnt1 == 2) && cnt2 == 5 ||
	    (cnt1 == 1 || cnt1 == 3) && cnt2 == 7) {
	  cnt1++;
	  cnt2 = 0;
	}
	if (cnt1 == 4 && cnt2 == 7) {
	  cout << i + 1 << endl;
	  i = n;
	  break;
	}
      }
    }
  }

  return 0;
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;

bool solve() {
    int w, h, r, c, R;
    cin >> w >> h >> c >> r >> R;
    if (c - R < 0) return false;
    if (r - R < 0) return false;
    if (c + R > w) return false;
    if (r + R > h) return false;
    return true;
}

int main() {
    if (solve()) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3096
import java.util.Scanner;

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		int D = sc.nextInt();
		int N = sc.nextInt();
		if (D == 0){
			System.out.println(N == 100 ? 101 : N);
		} else if (D == 1){
			System.out.println(N == 100 ? 10100 : 100 * N);
		} else {
			System.out.println(N == 100 ? 1010000 : 10000 * N);
		}
	}
}

class Main {
	public static void main(String... args) {
		Scanner in = new Scanner(System.in);

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
const static long long int MOD = 1000000000 + 7;
int dy[] = {0, 1, 0, -1};
int dx[] = {1, 0, -1, 0};

int main() {
    int n[4];
    rep(i, 4) {
        cin >> n[i];
    }
    sort(n, n + 4);
    if (n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	cin >> n;
	
	if( n == 3 || n == 5 || n == 7 ) cout << "YES" << endl;
	else cout << "NO" << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int a,b,c,ans;
	scanf("%d%d%d",&a,&b,&c);
	if(b<=c)
		c-=b,ans+=b+b;
	else
	{
		printf("%d\n",b+c);
		return 0;
	}
	if(a<=c)
	{
		c-=a;
		ans+=a;
		if(c>0)
			ans++;
	}
	else
	{
		ans+=c;
	}
	printf("%d\n",ans);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
 	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = (ll)1e18;

struct edge {
  ll to, cost;

  edge(ll f, ll t, ll c) {
    to = t;
    cost = c;
  }
};

struct graph {
  ll V;
  vector<vector<edge>> G;
  vector<ll> d;

  graph(ll n) { init(n); }

  void init(ll n) {
    V = n;
    G.resize(V);
    d.resize(V);
  }

  void add_edge(ll s, ll t, ll cost) { G[s].push_back(edge(s, t, cost)); }

  void Dijkstra(ll s) {
    for (int i = 0; i < V; i++) {
      d[i] = INF;
    }
    d[s] = 0;

    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(0, s));

    while (!que.empty()) {
      P p = que.top();
      que.pop();
      ll v = p.second;

      if (d[v] < p.first) {
        continue;
      }

      for (auto e : G[v]) {
        if (d[e.to] > d[v] + e.cost) {
          d[e.to] = d[v] + e.cost;
          que.push(P(d[e.to], e.to));
        }
      }
    }
  }
};

ll N, Q, K;
vector<ll> x, y;
graph G = graph(N);

void abc070d() {
  G.Dijkstra(K - 1);
  for (int i = 0; i < Q; i++) {
    cout << G.d[x[i] - 1] + G.d[y[i] - 1] << "\n";
  }
  return;
}

int main() {
  cin >> N;
  G.init(N);
  for (int i = 0; i < N - 1; i++) {
    ll a, b, c;
    cin >> a >> b >> c;
    G.add_edge(a - 1, b - 1, c);
    G.add_edge(b - 1, a - 1, c);
  }
  cin >> Q >> K;
  x.resize(Q);
  y.resize(Q);
  for (int i = 0; i < Q; i++) {
    cin >> x[i] >> y[i];
  }
  abc070d();
  return 0;
}


Measured memory_bytes: 12656
#include<bits/stdc++.h>
using namespace std;

int main(){
    int h,w,i,j;
    while(true){
        cin>>h>>w;
        if(h==0&&w==0)break;
        else{
            for(i=0;i<h;i++){
                for(j=0;j<w;j++){
                    if(i==0||i==h-1||j==0||j==w-1)cout<<"#";
                    else cout<<".";
                }
                cout<<"\n";
            }
            cout<<"\n";
        }
    }
    return 0;
}


Measured memory_bytes: 3016
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define pb push_back
#define MOD 1000000007
#define INF 1000000000000
#define EPS 0.00000000001
typedef long long ll;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    string s;
    cin>>s;
    int n=s.size();
    n-=2;
    cout<<s[0]<<n<<s[n+1]<<endl;
    
}


Measured memory_bytes: 256
n = int(input())

l = list(map(int, input().split(" ")))
l.sort()

ans = 0

for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            if l[i] != l[j] != l[k]:
                if l[i] + l[j] > l[k]:
                    ans += 1

print(ans)

Measured memory_bytes: 9144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

void solve() {
	int n, w; cin >> n >> w;
	// weights and values
	vector<pair<ll, ll>> vec(n);
	for (int i = 0; i < n; ++i) {
		cin >> vec[i].first >> vec[i].second;
	}
	sort(vec.begin(), vec.end(), [](pair<ll, ll> a, pair<ll, ll> b){
		return a.first == b.first ? a.second > b.second : a.first < b.first;
	});
	vector<vector<ll>> dp(n + 1, vector<ll>(w + 1, 0));
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= w; ++j) {
			if (vec[i - 1].first <= j) {
				dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - vec[i - 1].first] + vec[i - 1].second);
			} else {
				dp[i][j] = dp[i - 1][j];
			}
		}
	}
	// for (auto rows : dp) { for (auto val : rows) cout << val << "\t"; cout << "\n"; }
	cout << dp[n][w];
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	// #ifndef ONLINE_JUDGE
	//     freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	// #endif
	solve();
	return 0;
}


Measured memory_bytes: 80256
import itertools

input_ = input()
A, B, C, D = [int(input_[i]) for i in range(4)]

ops_str = ["+", "-"]
find_flag = 0
for ops in itertools.product((0, 1), repeat=3):
    equation = A
    if ops[0] == 0:
        equation += B
    else:
        equation -= B
       
    if ops[1] == 0:
        equation += C
    else:
        equation -= C
        
    if ops[2] == 0:
        equation += D
    else:
        equation -= D
    
    if equation == 7:
        find_flag = 1
        print(str(A)+ops_str[ops[0]], end="")
        print(str(B)+ops_str[ops[1]], end="")
        print(str(C)+ops_str[ops[2]], end="")
        print(str(D), end="=7")
        break

Measured memory_bytes: 3064
n=int(input())
if n==2:
  print(-1)
  exit()
if n==3:
  print("abb")
  print("a.c")
  print("ddc")
  exit()
if n==5:
  print("aabbc")
  print("hi..c")
  print("hi..d")
  print("g.jjd")
  print("gffee")
  exit()
if n==7:
  print("..abc..")
  print("..abc..")
  print("aax..aa")
  print("bbx..bb")
  print("cc.yycc")
  print("..abc..")
  print("..abc..")
  exit()
a=[n*["."]for _ in range(n)]
if n%2:
  a[-5][-5],a[-5][-4],a[-5][-3],a[-5][-2],a[-5][-1]=list("aabbc")
  a[-4][-5],a[-4][-4],a[-4][-3],a[-4][-2],a[-4][-1]=list("hi..c")
  a[-3][-5],a[-3][-4],a[-3][-3],a[-3][-2],a[-3][-1]=list("hi..d")
  a[-2][-5],a[-2][-4],a[-2][-3],a[-2][-2],a[-2][-1]=list("g.jjd")
  a[-1][-5],a[-1][-4],a[-1][-3],a[-1][-2],a[-1][-1]=list("gffee")
  n-=5
for i in range(0,n,2):
  a[i][i],a[i][i+1]="a","a"
  a[i+1][i],a[i+1][i+1]="b","b"
if n%4==0:
  for i in range(0,n,2):
    a[n-i-2][i],a[n-i-2][i+1]="c","d"
    a[n-i-1][i],a[n-i-1][i+1]="c","d"
else:
  for i in range(0,n-2,2):
    a[i][i+2],a[i][i+3]="c","d"
    a[i+1][i+2],a[i+1][i+3]="c","d"
  a[n-2][0],a[n-2][1]="c","d"
  a[n-1][0],a[n-1][1]="c","d"
for i in a:print("".join(i))

Measured memory_bytes: 12020
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

func chmin(a *int, b int) bool {
	if *a > b {
		*a = b
		return true
	}
	return false
}
func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func newLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func main() {
	var n int
	n, _ = strconv.Atoi(newLine())
	h := make([]int, n+20)
	inputLine := strings.Split(newLine(), " ")
	for i, v := range inputLine {
		h[i], _ = strconv.Atoi(v)
	}
	dp := make([]int, n+20)
	for i := 0; i < n+20; i++ {
		dp[i] = math.MaxInt64
	}
	dp[0] = 0
	chmin(&dp[1], dp[0]+abs(h[1]-h[0]))
	for i := 2; i < n; i++ {
		chmin(&dp[i], dp[i-1]+abs(h[i]-h[i-1]))
		chmin(&dp[i], dp[i-2]+abs(h[i]-h[i-2]))
	}
	fmt.Println(dp[n-1])
}


Measured memory_bytes: 5888
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define ll long long int
#define MOD ((int)(1e9) + 7)

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  map<int, int> st;
  for(int i=0; i<n; i++) {
    int tp; cin >> tp;
    auto k = st.find(tp);
    if(k == st.end())
      st.insert({tp, 1});
    else
    {
      k->second++;
    }
  }
  ll cum = 0;
  bool flag = true;
  for(auto x=st.begin(); x!= st.end(); x++) {
    cum += x->second;
    if(2*cum == n) {
      int lf = x->first+1;
      x++;
      int rf = x->first;
      cout << rf - lf + 1 << '\n';
      flag = false;
      break;
    }
  }
  if(flag)
  cout << 0 << '\n';
  return 0;
}


Measured memory_bytes: 3328
#define _GLIBCXX_DEBUG
#include<iostream>
#include<cstdio>
#include<bits/stdc++.h>//"geometry.cpp"
#include<iomanip>//"cout<<fixed<<setprecision(n)<<sth<<endl;"
#include<queue>
#include<string>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<algorithm>//"lower_bound(it,it,v)", "next_permutation(a,a+n)"
#include<functional>//"greater<T>" Ex. sort(a,a+n,greater<int>());
#include<cmath>//"abs", "sqrt"
using namespace std;
#define pb push_back
#define fi first
#define sc second
#define mp make_pair
#define is insert
typedef map<long long,int> mli;//Add other types in the same way.

int main(){
	int n,v[100];
	long long ws,w[100];
	mli m;
	cin>>n>>ws;
	for(int i=0;i<n;++i){
		cin>>w[i]>>v[i];
	}
	m.is(mp(0,0));
	for(int i=0;i<n;++i){
		vector<pair<long long,int> > vec;
		for(mli::iterator it=m.begin();it!=m.end();++it){
			long long w0=w[i]+it->fi;
			int v0=v[i]+(it->sc);
			if(w0>ws) continue;
			mli::iterator j=m.find(w0);
			if(j==m.end()){
				vec.pb(mp(w0,v0));
			}else{
				if(j->sc>=v0) continue;
				vec.pb(mp(w0,v0));
			}
		}
		for(int j=0;j<vec.size();++j){
			if(m.find(vec[j].fi)==m.end()){
				m.is(mp(vec[j].fi,vec[j].sc));
			}else{
				m[vec[j].fi]=max(vec[j].sc,m[vec[j].fi]);
			}
		}
	}
	int ans=0;
	for(mli::iterator it=m.begin();it!=m.end();++it){
		ans=max(it->sc,ans);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 512
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    a = int(input())
    b = int(input())
    h = int(input())

    print((a+b) * h // 2)


main()


Measured memory_bytes: 5156
#include <iostream>
using namespace std;

int main()
{
	int k, t, a[100], x;
	int maxa = 0;

	cin >> k;
	cin >> t;
	for(int i=0; i<t; i++){
		cin >> a[i];
	}

	for(int i=0; i<t; i++){
		if(a[i] > maxa){
			maxa = a[i];
		}
	}

	if(k%2 == 0){
		if(maxa <= k/2){
			x = 0;
		}
		else{
			x = (maxa - k/2) * 2 - 1;
		}
	}
	else{
		if(maxa <= k/2+1){
			x = 0;
		}
		else{
			x = (maxa - k/2 - 1) * 2;
		}
	}

	cout << x << "\n";

	return 0;
}


Measured memory_bytes: 384
# 1 "e.cpp"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "e.cpp"
# 1 "/home/tysm/dev/cpplib/bin/../include/cpplib/stdinc.hpp" 1
       
# 12 "/home/tysm/dev/cpplib/bin/../include/cpplib/stdinc.hpp"
# 1 "/home/tysm/dev/cpplib/bin/../stdlib/bits/stdc++.h" 1
 #include <bits/stdc++.h>
# 13 "/home/tysm/dev/cpplib/bin/../include/cpplib/stdinc.hpp" 2
# 1 "/home/tysm/dev/cpplib/bin/../stdlib/ext/pb_ds/assoc_container.hpp" 1
 #include <ext/pb_ds/assoc_container.hpp>
# 14 "/home/tysm/dev/cpplib/bin/../include/cpplib/stdinc.hpp" 2
# 1 "/home/tysm/dev/cpplib/bin/../stdlib/ext/pb_ds/tree_policy.hpp" 1
 #include <ext/pb_ds/tree_policy.hpp>
# 15 "/home/tysm/dev/cpplib/bin/../include/cpplib/stdinc.hpp" 2







using namespace std;
using namespace __gnu_pbds;

using ii = pair<long long, long long>;
using vi = vector<long long>;
using vd = vector<long double>;
using vb = vector<bool>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vvd = vector<vd>;
using vvb = vector<vb>;
using vvii = vector<vii>;
# 50 "/home/tysm/dev/cpplib/bin/../include/cpplib/stdinc.hpp"
inline long long mod(const long long n, const long long m = ((long long)1e9+7)){
    return (n%m + m)%m;
}

/**
 * Euclidean GCD.
 *
 * Time Complexity: O(log(min(a, b))).
 * Space Complexity: O(log(min(a, b))).
 */
long long gcd(const long long a, const long long b){
    if(a < 0 or b < 0)
        return gcd(abs(a), abs(b));
    if(a == 0)
        return b;
    return gcd(b%a, a);
}

/**
 * Euclidean derivated LCM.
 *
 * Time Complexity: O(log(min(a, b))).
 * Space Complexity: O(log(min(a, b))).
 */
long long lcm(const long long a, const long long b){
    // same as a*b/gcd(a, b) but avoiding overflow.
    return a/gcd(a, b)*b;
}
# 2 "e.cpp" 2

int32_t main(){
    (ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL));
    long long n, m;
    cin >> n >> m;
    long long max_v = n*(1e3);
    vvi dp(2, vi(max_v+1, ((long long)1e9+1)));
    dp[0][0] = dp[1][0] = 0;
    long long ans = 0;
    for(long long i=1; i<=n; ++i){
        long long w, v;
        cin >> w >> v;
        for(long long j=1; j<=max_v; ++j){
            dp[0][j] = dp[1][j];
            if(j >= v)
                dp[0][j] = min(dp[0][j], dp[1][j-v] + w);
            if(dp[0][j] <= m)
                ans = max(ans, j);
        }
        swap(dp[0], dp[1]);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;

void solver() {
  int n;
  cin >> n;

  int n_max = -1;
  map<string, int> mp;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    mp[s]++;
    n_max = max(mp[s], n_max);
  }

  vector<string> ss;
  for(map<string, int>::iterator it = mp.begin(); it != mp.end(); ++it) {
    int n_s = it->second;
    if (n_s == n_max) ss.push_back(it->first);
  }

  sort(ss.begin(), ss.end());

  for (int i = 0; i < ss.size(); i++) {
    cout << ss[i] << "\n";
  }
}

int main() {
  solver();
  return 0;
}


Measured memory_bytes: 26868