akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <algorithm>
#include <map>
#include <set>

using namespace std;
const int N = 100;
const int INF = 100000000;
typedef pair<int, int> P;

class State{
public:
  int x, y, cost;
  State(int y, int x, int cost) : y(y), x(x), cost(cost) {}
  //State(int y = 0, int x = 0, int cost = 0) : y(y), x(x), cost(cost) {}
};

int w, h, s, t;
int dist[11][N][N];
int dy[2][6] = {{-1, -1, 0, 1, 1, 0},{-1, -1, 0, 1, 1, 0}};
int dx[2][6] = {{-1, 0, 1, 0, -1, -1},{0, 1, 1, 1, 0, -1}};
vector<P> cs;

void print(int p){
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cout << dist[p][i][j] << ' ';
    }
    cout << endl;
  }
  cout << endl;
}

void bfs(int sy, int sx, int p){
  for(int i=0;i<h;i++) for(int j=0;j<w;j++) dist[p][i][j] = INF;
  queue<State> que;
  que.push(State(sy, sx, 0));
  dist[p][sy][sx] = 0;
  while(!que.empty()){
    State u = que.front(); que.pop();
    for(int i=0;i<6;i++){
      int ny = u.y + dy[u.y%2][i];
      int nx = u.x + dx[u.y%2][i];
      if(ny<0 || ny>=h) continue;
      if(nx<0 || nx>=w) continue;
      if(dist[p][ny][nx] != INF) continue;
      dist[p][ny][nx] = u.cost+1;
      que.push(State(ny, nx, u.cost+1));
    }
   }
}

int solve(){
  int res = 0;
  bfs(cs[s].first, cs[s].second, s);
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      bool f = false;
      int valm = INF, col;
      for(int k=0;k<=s;k++){
        if(valm > dist[k][i][j]){
          f = false;
          valm = dist[k][i][j];
          col = k;
        }else if(valm == dist[k][i][j]) f = true;
      }
      if(!f && col == s) res++;
    }
  }
  return res;
}

main(){
  while(cin >> w >> h && (w|h)){
    cs.clear();
    int x, y;
    cin >> s;
    for(int i=0;i<s;i++){
      cin >> x >> y;
      cs.push_back(P(y-1, x-1));
    }
    for(int i=0;i<cs.size();i++) bfs(cs[i].first, cs[i].second, i);
    //for(int i=0;i<cs.size();i++) print(i);
    int ans = 0;
    cin >> t;
    for(int i=0;i<t;i++){
      cin >> x >> y;
      cs.push_back(P(y-1, x-1));
      ans = max(ans, solve());
      cs.pop_back();
    }
    cout << ans << endl;
    //return 0;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
using namespace std;
int x,y,z,kk;
long long a[1005],b[1005],c[1005];
long long ans[1000005];
int cur=0;

bool cmp(long long a1,long long a2){
	return a1>a2;
}

int main()

{
	ios::sync_with_stdio(false);
	cin>>x>>y>>z>>kk;
	for (int i=1;i<=x;i++) cin>>a[i];
	for (int i=1;i<=y;i++) cin>>b[i];
	for (int i=1;i<=z;i++) cin>>c[i];

	sort(a+1,a+1+x,cmp);
	sort(b+1,b+1+y,cmp);
	sort(c+1,c+1+z,cmp);

	for (int i=1;i<=x;i++){
		for (int j=1;j<=y;j++){
			for (int k=1;k<=z;k++){
				if (i*j*k>kk) break;
				ans[++cur]=a[i]+b[j]+c[k];
			}
		}
	}

	sort(ans+1,ans+cur+1,cmp);
	for (int i=1;i<=kk;i++){
		cout<<ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
 
using namespace std;
using S = set<long long>;
using D = deque<long long>;
using L = vector<long long>;
using M = map<int,long long>;
using A = vector<vector<long long>>;
using Q = priority_queue<long long>;
using U = unordered_map<int,long long>; //mapとの違いはkeyの順番を保持していない

#define sorted(vector) sort(vector.begin(),vector.end()) //O(nlongn)
#define vmin(vector) *min_element(vector.begin(),vector.end()) //O(N)
#define vmax(vector) *max_element(vector.begin(),vector.end()) //O(N)
#define vsum(vector) accumulate(vector.begin(),vector.end(),0) //O(N)
#define vcount(vector,a) count(vector.begin(), vector.end(),a) //O(N)
#define bisect_left(vector,a) (lower_bound(vector.begin(),vector.end(),a)-vector.begin())
#define bisect_right(vector,a) (upper_bound(vector.begin(),vector.end(),a)-vector.begin())
#define vfind(vector,a) find(vector.begin(), vector.end(), a) != vector.end() //遅いからあんまり使うな
//存在確認はmap!!!!!!!!!!!!!
//__gcd(a,b)はコンパイラがGCC時のみ

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    long long n,pre;
    cin>>n;
    L l(n,0);
    
    for(int i=n-1  ;i>-1  ;i--){
        cin>>l[i];
    }
    pre=l[0];
    for(int i=1  ;i<n  ;i++){
        if (l[i-1]<l[i]){
            l[i]-=1;
        }
        if (l[i-1]<l[i]){
            cout<<"No"<<endl;
            exit(0);
        }
            
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include<algorithm>
#include <stdio.h>
#include <map>
#include <random>
#include <string>
#include<vector>
#include<stack>
#include <cstdlib>


using namespace std;

int main() {
	int n;
	string s;
	int cnt = 0;
	cin >> n >> s;
	for (int i = 0; i < n - 2; i++) {
		if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
			cnt++;
		}
	}
	cout << cnt;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int n,i,j,count=0,k,min,num;
    int a[100];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<n-1;i++){
        min = a[i];
        num = i;
        for(j=i+1;j<n;j++){
            if(min>a[j]){
                min = a[j];
                num = j;
                
            }
        }
        if(num!=i){
            count++;
            k=a[i];
            a[i]=a[num];
            a[num]=k;
        }
    }
    for(i=0;i<n;i++){
        printf("%d",a[i]);
        if(i!=n-1){
            printf(" ");
        }
    }
    printf("\n%d\n",count);
    return 0;
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define F first
#define S second
#define fast std::ios_base::sync_with_stdio(false)
#define mod 1000000007
#define pi 3.14159265
int main() {
	fast;
	lli n,k;
	cin>>n>>k;
	lli a[n],i;
	fr(i,n)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	lli sum=0;
	fr(i,k)
	{
		sum+=a[i];
	}
	cout<<sum;
	
	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int>pa;
map<int,int>mp;
const int N=1e7+100;
int n,m;
set<int>s;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    int n;cin>>n;
    int cnt=0;
    for(int i=1;i<=n;i++){
        int x;cin>>x;
        if(s.find(x)!=s.end()) cnt++;
        else s.insert(x);
    }
    int ans=s.size();
    if(cnt&1) ans--;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 8188
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	
    public static void main(String[] args) throws IOException {
    	Scanner s = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String[] input;
		int x = s.nextInt();
		int ans = 0;
		if (x < 600) {
			ans = 8;
		} else if(x < 800) {
			ans = 7;
		} else if (x < 1000) {
			ans = 6;
		} else if(x < 1200) {
			ans = 5;
		} else if(x < 1400) {
			ans = 4;
		} else if(x < 1600) {
			ans = 3;
		} else if(x < 1800) {
			ans = 2; 
		} else {
			ans = 1;
		}
		out.print(ans);
		out.flush();
		out.close();
    }
}


Measured memory_bytes: 35764
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,command,x;
    string key;
    map<string,int> myMap;
    cin >> n;
    
    for(int i = 0;i < n;++i){
        cin >> command >> key;
        // insert
        if(command == 0){
            cin >> x;
            myMap[key] = x;
        }else if(command == 1){
            // find
            cout << myMap[key] << endl;
        }
        // delete
        else if(command == 2){
            myMap.erase(key);
        }
    }
}



Measured memory_bytes: 25872
N, M = map(int, input().split())

ab = []
for n in range(N):
    ab.append(list(map(int, input().split())))

ab = sorted(ab)

now_M = 0
money = 0
for ab_i in ab:
    if M <= now_M:
        break
    elif M <= now_M + ab_i[1]:
        money += ab_i[0] * (M - now_M)
        now_M += M - now_M
    else:
        money += ab_i[0] * ab_i[1]
        now_M += ab_i[1]

print(money)

Measured memory_bytes: 28656
ans_data = []

def get_num_shugou(num):
    num_shuugou = -1
    for i in range(1, num + 2):
        if 2 * num == i * (i - 1):
            num_shuugou = i
            break
        elif 2 * num < i * (i - 1):
            break
    return num_shuugou

def get_piramid(num_shuugou):
    piramid = [[1]]
    for i in range(num_shuugou - 2):
        data = [piramid[-1][-1] + j + 1 for j in range(len(piramid) + 1)]
        piramid.append(data)
    return piramid


def data_append(now_list):
    print('{} {}'.format(len(now_list), ' '.join(list(map(str, now_list)))))


def make_data(high, width, piramid, now_list_kari, down_flg):
    now_list = now_list_kari.copy()
    now_list.append(piramid[high][width])

    if len(now_list) == len(piramid):
        data_append(now_list)
        return

    if down_flg:
        make_data(high + 1, width, piramid, now_list, down_flg)

    elif width == len(piramid[high]) - 1:
        down_flg = 1
        make_data(high + 1, width, piramid, now_list, down_flg)
    else:
        make_data(high, width + 1, piramid, now_list, down_flg)


def write_shugou(num_shuugou):
    piramid = get_piramid(num_shuugou)

    now_list = [piramid[i][-1] for i in range(len(piramid))]
    data_append(now_list)
    for i in range(num_shuugou - 1):
        make_data(i, 0, piramid, [], 0)

def main():
    num = int(input())
    num_shuugou = get_num_shugou(num)
    if num_shuugou == -1:
        print('No')
    else:
        print('Yes')
        print(num_shuugou)
        write_shugou(num_shuugou)



if __name__ == '__main__':
    main()

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

const int MOD = (int)1e9+7;

int main(){
	int N;
	cin >> N;
	vector<pair<int,int>> Ai(N);
	for(int i=0;i<N;i++){
		int a;
		cin >> a;
		Ai.at(i)=make_pair(a,i+1);
	}

	sort(Ai.begin(),Ai.end());
	for(int i=0;i<N-1;i++)	cout << Ai.at(i).second << " ";
	cout << Ai.at(N-1).second << endl;
	
	return 0;
}


Measured memory_bytes: 1536
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	static final int MOD = (int)1e9 + 7;
	int N,M;
	char[] ch;
	int[] r,l,newR,sum;
	long[][] dp;


	public long dfs(int L,int R,int C){

		if(L == N){
			return 1;
		}

		if(dp[L][C] != -1)return dp[L][C];

		long ret = 0;
		int add = 0;

		if(R < newR[L+1]){
			add = sum[newR[L+1]] - sum[R];
		}

		//1を配置
		if(C > 0){
			ret += dfs(L + 1,newR[L+1],C - 1 + add) % MOD;
		}

		//0を配置
		if(C < R - L  + 1){
			ret += dfs(L + 1,newR[L+1],C + add) % MOD;
		}
		ret %= MOD;
		return dp[L][C] = ret;

	}

	public void solve() {
		N = nextInt();
		M = nextInt();
		ch = next().toCharArray();

		l = new int[M];
		r = new int[M];
		for(int i = 0;i < M;i++){
			l[i] = nextInt() - 1;
			r[i] = nextInt() - 1;
		}

		newR = new int[N + 1];
		for(int i = 0;i < N;i++){
			newR[i] = i;
		}
		for(int i = 0;i < M;i++){
			newR[l[i]] = Math.max(newR[l[i]],r[i]);
		}
		for(int i = 1;i < N;i++){
			newR[i] = Math.max(newR[i], newR[i-1]);
		}

		sum = new int[N];
		for(int i = 0;i < N;i++){
			sum[i] = ch[i] - '0';
		}
		for(int i = 0;i < N - 1;i++){
			sum[i + 1] += sum[i];
		}

		dp = new long[N + 1][N + 1];
		for(int i = 0;i < N + 1;i++){
			Arrays.fill(dp[i], -1);
		}

		out.println(dfs(0,newR[0],sum[newR[0]]));
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 108132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rp(i,n) for(int i=1;i<=(int)n;i++)
int main() {
string s;cin>>s;
if(s[2]==s[3]&&s[4]==s[5])cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

#define MAX_N 100000
#define CUT 1000

double ans[MAX_N+1] = {0};
double b[MAX_N+1];
double memo[3][CUT+1] = {0};

double E(int rest, int con) {
	if (con == 0 && ans[rest] > 0) return ans[rest];
	if (rest == 0) return 0;
//	if (con > 1000) return E(rest-1, 0);

	double p = b[con];
	double ret = p * (E(rest-1, con+1) + 1) + (1-p) * E(rest-1, 0);
	if (con == 0) ans[rest] = ret;
	return ret;
}

int main() {
	b[0] = 1.0;
	for (int i = 1; i <= MAX_N; ++i) {
		b[i] = b[i-1] / 2;
	}
	for (int i = 1; i <= MAX_N; ++i) {
		for (int j = 0; j < min(CUT, MAX_N-i+1); ++j) {
			if (j == CUT) b[j] * ((1-b[j+1])*memo[(i+1)%3][0]+1) + (1-b[j]) * memo[(i-1)%3][0];
			else memo[i%3][j] = b[j] * (memo[(i-1)%3][j+1]+1) + (1-b[j]) * memo[(i-1)%3][0];
		}
		ans[i] = memo[i%3][0];
	}
	ans[0] = 0;

//	E(MAX_N, 0);

	int n;
	while ( cin >> n, n ) {
//		printf("%.10f\n", E(MAX_N, 0));
		printf("%.10f\n", ans[n]);
	}
//	for (int i = 0; i < 100; ++i) printf("%.10f\n", ans[i]);
//	printf("%.10f\n", E(MAX_N, 0));
//	printf("%.10f\n", ans[MAX_N]);
}

Measured memory_bytes: 2776
#pragma GCC optimize("Ofast")
#pragma GCC target("tune=native")
#pragma GCC target("avx")
#include <bits/stdc++.h>
#define show(x) std::cerr << #x << " = " << x << std::endl
using ll = long long;
using ld = long double;
constexpr ll MOD = 1000000007LL;
template <typename T>
constexpr T INF = std::numeric_limits<T>::max() / 10;
std::mt19937 mt{std::random_device{}()};
int main()
{
    int H, W;
    std::cin >> H >> W;
    std::vector<std::vector<int>> S(H + W - 1, std::vector<int>(H + W - 1));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            char c;
            std::cin >> c;
            S[i + j][i - j + W - 1] = (c == '#' ? 1 : 0);
        }
    }
    auto yoko = S, tate = S;
    for (int i = 0; i < H + W - 1; i++) {
        for (int j = 1; j < H + W - 1; j++) { yoko[i][j] += yoko[i][j - 1]; }
    }
    for (int j = 0; j < H + W - 1; j++) {
        for (int i = 1; i < H + W - 1; i++) { tate[i][j] += tate[i - 1][j]; }
    }
    ll ans = 0;
    for (int y = 0; y < H + W - 1; y++) {
        for (int i = 0; i < H + W - 1; i++) {
            for (int j = i + 1; j < H + W - 1; j++) {
                if (S[y][i] * S[y][j] == 0) { continue; }
                const int l = j - i;
                if (y >= l) {
                    const int point = yoko[y - l][j] - (i == 0 ? 0 : yoko[y - l][i - 1]);
                    ans += point;
                }
                if (y + l < H + W - 1) {
                    const int point = yoko[y + l][j] - (i == 0 ? 0 : yoko[y + l][i - 1]);
                    ans += point;
                }
            }
        }
    }
    for (int x = 0; x < H + W - 1; x++) {
        for (int i = 0; i < H + W - 1; i++) {
            for (int j = i + 1; j < H + W - 1; j++) {
                if (S[i][x] * S[j][x] == 0) { continue; }
                const int l = j - i;
                if (x >= l) {
                    const int point = tate[j - 1][x - l] - tate[i][x - l];
                    ans += point;
                }
                if (x + l < H + W - 1) {
                    const int point = tate[j - 1][x + l] - tate[i][x + l];
                    ans += point;
                }
            }
        }
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 4608
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from fractions import gcd

N,M = map(int,readline().split())
S = readline().rstrip().decode('utf-8')
T = readline().rstrip().decode('utf-8')

G = gcd(N,M)

# G回overlapする

A = ''.join(S[::N//G])
B = ''.join(T[::M//G])

if A == B:
    answer = N * M // G
else:
    answer = -1
print(answer)

Measured memory_bytes: 5472
#include<stdio.h>

static const int N = 100;
static const int INFTY = 1000000;

int main(){
  
  int M[N][N];
  int n, u, k, v; 
  int i, j;


  scanf("%d", &n);

  
  for ( i = 0; i <n; i++ ){
    for ( j = 0; j <n; j++ ) {
      M[i][j] = 0;
    }
  }
  
  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &u, &k);
    u--;
    
    for ( j = 0; j < k; j++ ){
      scanf("%d", &v);
      v--;
      M[u][v] = 1;

    }
  }
  
  for ( i = 0; i < n; i++ ){
    for ( j = 0; j < n; j++ ){
      if ( j ) printf(" ");
      printf("%d", M[i][j]);
      if(j == n-1){
	printf("\n");
      }
    }
  }

  return 0;
}

Measured memory_bytes: 636
#include <iostream>
using namespace std;
int main(void){
    int n,a[100]={0}; //100個
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    cout << a[n-1];
    for(int i = 1; i < n; i++){
        int x = (n-1) - i;
        cout << " " << a[x];
    }
    cout << endl;
}


Measured memory_bytes: 3076
/**************************************************************************
Coded by: Saba Karimi(_VINTAGE)
Institution: AIT PUNE
***************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int 
/**************************************************************************/
signed main()
{
    fast;
    stack<char> st;
    string s;
    cin>>s;
    int n = s.size();
    int ans = 0;
    for(int i=0;i<n;i++)
    {
        if(st.empty()||st.top()==s[i])
            st.push(s[i]);
        else
        {
            st.pop();
            ans+=2;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 512
import java.util.*;

public class Main{
	public static void main(String[] args){
		Double a;
		Scanner scan = new Scanner(System.in);

		while(scan.hasNextLine()){
			String[] s = scan.nextLine().split(" ");
			Stack<Double> stack = new Stack<Double>();

			for(int i=0;i<s.length;i++){
				if(s[i].equals("-")){
					a = stack.pop();
					stack.push(stack.pop() - a);
				}
				else if(s[i].equals("/")){
					a = stack.pop();
					stack.push(stack.pop() / a);
				}
				else if(s[i].equals("*")){
					a = stack.pop();
					stack.push(stack.pop() * a);
				}
				else if(s[i].equals("+")){
					a = stack.pop();
					stack.push(stack.pop() + a);
				}
				else
					stack.push(Double.parseDouble(s[i]));
			}

			System.out.printf("%.6f\n",stack.pop());
		}
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
#define endl '\n';
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

int main(){
  int N,M;
  cin >> N >> M;
  vector<vector<int>> G(N);
  for(int i=0; i<M; i++){
    int u,v;
    cin >> u >> v;
    u--;
    v--;
    G[u].push_back(v);
  }
  int S,T;
  cin >> S >> T;
  S--;
  T--;
  vector<vector<int>> dist(N,vector<int> (3,-1));
  dist[S][0] = 0;
  queue<P> que;
  que.emplace(S,0);
  while(que.size()){
    P v = que.front();
    que.pop();
    for(int nv: G[v.first]){
      if(dist[nv][(v.second+1)%3] != -1) continue;
      dist[nv][(v.second+1)%3] = dist[v.first][v.second] + 1;
      que.emplace(nv,(v.second+1)%3);
    }
  }
  if(dist[T][0] == -1){
    cout << -1 << endl;
  }else{
    cout << dist[T][0]/3 << endl;
  }
  return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>

#define fst first
#define snd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
}

const ld PI = 4*atan((ld)1);
const int INF = 1e9+7;
const ll _INF = 1e18+7;

int main(){
	setIO();
	int n, ct = 0; cin >> n;
	for (int i = 0; i < n; i++){
		int a, b;
		cin >> a >> b;
		if (a==b) ct++;
		else ct = 0;
		if (ct >= 3){
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";
}

Measured memory_bytes: 3592
#include <cstdio>
#include <stdlib.h>
using namespace std;
int main() {
	long long N;
	scanf("%lld", &N);
    long long sum = 0;
    for (long long i=1; i <= N; i = i+3) {
        if (i%5 != 0) {
            sum += i;
        }
    }
    for (long long i=2; i <= N; i = i+3) {
        if (i%5 != 0) {
            sum += i;
        }
    }
	printf("%lld\n", sum);
}

Measured memory_bytes: 1724
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
  int n;
  scanf("%d",&n);

  int a[n];
  int x=0;
  for(int i=0;i<n;i++)
  {
    scanf("%d",&a[i]);
    x ^= a[i];
  }

  for(int i=0;i<n;i++)
  {
    printf("%d",x^a[i]);
    if(i<n-1) printf(" ");
    else printf("\n");
  }

  return 0;
}

Measured memory_bytes: 3200
#include <iostream>
        #include <vector>
        #include <algorithm>
        using namespace std;
        typedef long long ll;
        ll n, m, c[1000000];
        int main() {
            vector<ll> v, v1;
            cin >> n >> m;
            for(ll i = 2; i < 1000000; ++i)
                if(!c[i])
                    for(ll j = i * 2; j < 1000000; j += i)
                        c[j] = 1;
            v.push_back(1);
            for(ll i = 2; i < 1000000 && n != 1; ++i) 
                if(!c[i] && n % i == 0)
                    n /= i, v.push_back(i), --i;
            ll cnt = 0;
            if(n > 1)
            v.push_back(n);
            v.resize(unique(v.begin(), v.end()) - v.begin());
            for(ll i: v) 
                if(m % i == 0)
                    ++cnt;
            cout << cnt  << endl;
            return 0;
        }

Measured memory_bytes: 8064
#include<stdio.h>
int n;
int A[21];
int rec(int num,int sum,int i){
  int k;
  for(k=i;k<n;k++){
    if(sum+A[k]==num) return 1;
    else if(sum+A[k]<num) {
      if(rec(num,sum+A[k],k+1)) return 1;
      else continue;
    }
    else continue;
  }
  return 0;
}
  int main(){
  int q;
  int m[201];
  int i;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++) {
    scanf("%d",&m[i]);
    if(rec(m[i],0,0)) printf("yes\n");
    else printf("no\n");
  }
      
  return 0;
}



Measured memory_bytes: 2060
use std::cmp::*;
use std::io::*;
fn main() {
    let mut s: String = String::new();
    stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let mut m = vec![0; 9];
    for &x in a.iter() {
        if x < 400 {
            m[0] += 1;
        } else if x < 800 {
            m[1] += 1;
        } else if x < 1200 {
            m[2] += 1;
        } else if x < 1600 {
            m[3] += 1;
        } else if x < 2000 {
            m[4] += 1;
        } else if x < 2400 {
            m[5] += 1;
        } else if x < 2800 {
            m[6] += 1;
        } else if x < 3200 {
            m[7] += 1;
        } else {
            m[8] += 1;
        }
    }
    let mut ans = 0;
    for i in 0..8 {
        if m[i] > 0 {
            ans += 1;
        }
    }
    println!("{} {}", max(1, ans), ans + m[8]);
}


Measured memory_bytes: 4352
n=int(input())
l=list(map(int,input().split()))
l1={}
l2=[]
for i in l:
  if i in l1:
    if l1[i]%2==0:
      l1[i]+=1
    else:
      l2.append(i)
      l1[i]+=1
  else:
    l1[i]=1
if len(l2)<2:
  print(0)
else:
  l2=sorted(l2)
  print(l2[-1]*l2[-2])


Measured memory_bytes: 18060
#include "bits/stdc++.h"

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }
const double EPS = 1e-9;
signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N; cin >> N;
	vector<double>x(N), y(N); rep(i, 0, N) { cin >> x[i] >> y[i]; }

	auto f = [&](double r) {
		rep(i, 0, N) {
			rep(j, 0, N) {
				if (i == j)continue;
				double dx = x[i] - x[j], dy = y[i] - y[j];
				double d = sqrt(dx*dx + dy * dy);
				if (d > 2 * r + EPS)continue;

				double rr = sqrt(r*r - d * d / 4);
				double vx = -dy / d * rr;
				double vy = dx / d * rr;

				double xx = (x[i] + x[j]) / 2 + vx;
				double yy = (y[i] + y[j]) / 2 + vy;
				int cnt = 0;
				rep(k, 0, N) {
					if ((x[k] - xx)*(x[k] - xx) + (y[k] - yy)*(y[k] - yy) < r*r + EPS)cnt++;
				}
				if (cnt == N)return true;
			}
		}
		return false;
	};
	//dump(f(0.5));
	double l = 0, r = 1e3;
	loop(100) {
		double m = (l + r) / 2;
		dump(m, f(m));
		if (f(m)) {
			r = m;
		}
		else {
			l = m;
		}
	}
	cout << r << endl;


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	string s[50];
	cin >> n;
	for(int i=0; i<n; i++) cin >> s[i];

	string ans;
	for(int i=0; i<26; i++){
		int cnt[50] = {0};
		for(int j=0; j<n; j++){
			for(int k=0; k<s[j].length(); k++){
				if(s[j][k] == 'a' + i){
					cnt[j]++;
				}
			}
		}
		int cmin = 51;
		for(int l=0; l<n; l++){
			cmin = min(cmin, cnt[l]);
		}
		for(int l=0; l<cmin; l++){
			ans += 'a' + i;
		}
	}

	cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;
ll INF = 1e9+10;
#define what_is(x) cerr << #x << " is " << x << endl;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
vector<pair<ll, ll> > pairs;

ll n, mod = 998244353;
const ll MAX = 1e7 + 1;
vector<ll> v(MAX);

ll inv[MAX];

int main()
{
    ll A, B, K;
    cin >> A >> B >> K;
    
    ll res = max(0LL, K - A);
    cout << max(0LL, A - K) << " " << max(0LL, B - res);
    return 0;    
}


Measured memory_bytes: 78336
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define mp make_pair
#define F first
#define S second
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
typedef long long ll;
double n;
double x[10],y[10];
int main()
{
    while(cin>>n)
    {
        rep(i,n) cin>>x[i]>>y[i];
        double sum=0;
        rep(i,n)
        {
            rep(j,n)
            {
                if(i!=j)
                {
                    sum+=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
                }
            }
        }
        cout<<fixed<<setprecision(6)<<sum/n<<"\n";
    }
}



Measured memory_bytes: 256
# graph = [{} for _ in range(V)]
# when there is an edge u -> v (maxflow f)
#  graph[u][v] = f
#  graph[v][u] = f (if undirected) 0 (if directed)

class FordFulkerson():
    def __init__(self, start, finish, graph, INF=10**18):
        self.INF = INF
        self.start = start
        self.finish = finish
        self.graph = graph
        self.N = len(graph)

    def dfs(self):
        self.Flow = [self.INF]*self.N
        self.used = [False]*self.N
        self.Par = [-1]*self.N
        self.stack = [self.start]
        self.used[self.start] = True
        while self.stack:
            v = self.stack.pop()
            if v == self.finish:
                d = self.Flow[v]
                while v != self.start:
                    nv = self.Par[v]
                    self.graph[nv][v] -= d
                    self.graph[v][nv] += d
                    v = nv
                return d
            for i, (nv, ncap) in enumerate(self.graph[v].items()):
                if not self.used[nv] and ncap > 0:
                    self.used[nv] = True
                    self.stack.append(nv)
                    self.Par[nv] = v
                    self.Flow[nv] = min(self.Flow[v], ncap)
        return 0

    # solve
    def flow(self):
        flow = 0
        while True:
            f = self.dfs()
            if f == 0: return flow
            flow += f


import sys
input = sys.stdin.readline

INF = 10**18

H, W = map(int, input().split())
V = H+W


def make():
    state = [list(input().rstrip()) for _ in range(H)]
    graph = [{} for _ in range(V+2)]

    start = V
    finish = V+1

    for h in range(H):
        for w in range(W):
            u, v = h, w+H
            if state[h][w] == "o":
                graph[u][v] = 1
                graph[v][u] = 1
            if state[h][w] == "S":
                graph[v][start] = INF
                graph[start][v] = INF
                graph[u][start] = INF
                graph[start][u] = INF
            if state[h][w] == "T":
                graph[u][finish] = INF
                graph[finish][u] = INF
                graph[v][finish] = INF
                graph[finish][v] = INF
    
    return graph, start, finish



def main():
    graph, start, finish = make()
    ff = FordFulkerson(start, finish, graph)
    ans = ff.flow()

    if ans > INF//2:
        print(-1)
    else:
        print(ans)


if __name__ == "__main__":
    main()

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

ll GetDigit(ll num){
    return to_string(num).length();
}

int main(){
    ll N;
    cin >> N;

    ll count=0;
    for(ll i=1;i<=N;i++){
        if(GetDigit(i)%2!=0) count++;
    }
    
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 384
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
	}

	public static void solution(String[] args) throws Exception{

		
		System.out.println((nextInt()-1)*(nextInt()-1));

	}
	
	public static boolean isPalindromicStr(String s) {
		int h = 0;
		int t = s.length() - 1;
		while (h <= t) {
			if (s.charAt(h) != s.charAt(t)) {
				break;
			}
			h++;
			t--;
		}
		if (h > t) {
			return true;
		}
		return false;
	}
	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 21076
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const double PI  =3.141592653589793238463;
long long MOD = 1000000007;
int stringToInteger(string x){
    int gg=0;
    stringstream geek(x);
    geek >> gg;
    return gg;
}

ll powmod(ll a,ll b,ll m)
{
    ll ans=1;
    while(b>0){ if(b%2)
        {ans*=a; ans%=m;}
         b/=2; a=a*a; a=a%m;
        }
        return ans%m;
}
ll gcd(ll a,ll b)
{

    return __gcd(a,b);
}
ll mulmod(ll a,ll b,ll m)
{  ll ans=0;
    a %=m;
    while (b>0)
    {       if(b&1) ans = (ans + a) % m;
        a = (a * 2)%m;
        b /= 2;
    }
    return ans % m;
}


ll f[5000001];

ll pow(ll a, ll b, ll MOD)
{
 ll x=1,y=a;
 while(b > 0)
 	{
 		if(b%2 == 1)
 	{
 		x=(x*y);
 		if(x>MOD) x%=MOD;
 	}
 	y = (y*y);
 	if(y>MOD) y%=MOD;
 	b /= 2;
 	}
 return x;
}

/* Modular Multiplicative Inverse
 Using Euler's Theorem
 a^(phi(m)) = 1 (mod m)
 a^(-1) = a^(m-2) (mod m) */
ll InverseEuler(ll n, ll MOD)
{
 return pow(n,MOD-2,MOD);
}

ll C(ll n, ll r, ll MOD)
{

 return (f[n]*((InverseEuler(f[r], MOD) * InverseEuler(f[n-r], MOD)) % MOD)) % MOD;
}

int main()
{
    string s;
    cin>>s;
    ll k;
    cin>>k;
    if(k==1) cout<<s[0]<<endl;
    else
    {
        int j=0;
        while(s[j]=='1') j++;
        if(k<=j) cout<<1<<endl;
        else
            cout<<s[j]<<endl;

    }
}


Measured memory_bytes: 256
A,B,H,M = map(int, input().split())
import math
h = ((H*60+M)/720)*2*math.pi
m = (M/60)*2*math.pi
s = A*math.cos(h)-B*math.cos(m)
t = A*math.sin(h)-B*math.sin(m)
print((s**2 + t**2)**0.5)

Measured memory_bytes: 9464
use strict;
use warnings;
use utf8;

$_ = <>;

my ($a, $b, $c, $d) = split / /;

my $max = $a * $c;

my $tmp = $a * $d;
$max = $tmp if ($max < $tmp);

$tmp = $b * $c;
$max = $tmp if ($max < $tmp);

$tmp = $b * $d;
$max = $tmp if ($max < $tmp);

print $max;

print "\n";

0;


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

int main() {
	int n;
	cin >> n;
	vector<int> v1, v2;
	for(int i=0; i<n; i++){
	    int x, y;
	    cin >> x >> y;
	    v1.push_back(x + y);
	    v2.push_back(x - y);
	}
	sort(v1.begin(), v1.end());
	sort(v2.begin(), v2.end());
	cout << max(v1[n-1] - v1[0], v2[n-1] - v2[0]);
	return 0;
}

Measured memory_bytes: 5084
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
using v1 = vector<int>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int N;

struct tramp
{
	char suit;
	int num;
	int stable;
};

void judge(vector<tramp> o){
	rep(i, N){
		for(int j = 0; j<N;j++){
			if(o.at(i).num==o.at(j).num){
				o.at(j).stable = o.at(i).stable;
			}
		}
	}
}

bool judges(vector<tramp> bubble, vector<tramp> select){
	rep(i, N){
		for(int j = i; j<N; j++){
			if(select.at(i).num == select.at(j).num){
				if(select.at(i).suit != bubble.at(i).suit)
				return false;
			}
		}
	}
	return true;
}

int main(){
	cin >> N;
	vector<tramp> bubble(N);
	vector<tramp> select(N);
	rep(i, N){
		string s;
		cin>>s;
		bubble.at(i).suit = s.at(0);
		bubble.at(i).num = s.at(1)-48;
		bubble.at(i).stable = i;
	}
	int flag = 0;
	judge(bubble);
	select = bubble;
	bool bubble_judge = true;
	bool select_judge = true;
	rep(i, N){
		flag = 1;
		for(int j = N-1; j>i; j--){
			tramp J = bubble.at(j);
			tramp J1 = bubble.at(j-1);
			if(J.num < J1.num){
				bubble.at(j) = J1;
				bubble.at(j - 1) = J;
				flag = 0;
			}
		}
		if(flag == 1) break;
	}

	rep(i, N){
		int minj = i;
		for(int j = i; j<N;j++){
			if(select.at(j).num < select.at(minj).num) minj = j;
		}
		if(minj != i){
			tramp min = select.at(minj);
			select.at(minj) = select.at(i);
			select.at(i) = min;
		}
	}

	rep(i, N){
		if(i != N-1){
			cout << bubble.at(i).suit << bubble.at(i).num << " ";
		}else{
			cout << bubble.at(i).suit << bubble.at(i).num <<endl;
		}
	}
	if(bubble_judge){
	cout << "Stable" << endl;
	}else{
		cout << "Not stable" << endl;
	}
	rep(i, N){
		if(i != N-1){
			cout << select.at(i).suit << select.at(i).num << " ";
		}else{
			cout << select.at(i).suit << select.at(i).num <<endl;
		}
	}
	if(!judges(bubble, select)) cout << "Not stable" << endl;
	if(judges(bubble, select)) cout << "Stable" << endl;
}



Measured memory_bytes: 3168
#s = list(input())
s = input()
n = len(s)
count = 1   #消した数
 
if n % 2 == 1 - count:
    count += 1
 
while s[0 : int((n-count)/2)] != s[int((n-count)/2) : n-count]:
    count += 2
 
print(n-count)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;


const int MXN=1e5;
vector<int> g[MXN+1];
vector<int> vis(MXN+1);
vector<int> dp(MXN+1);
vector<int> t;
int n,m;
void dfs(int u){
	vis[u]=1;
	for(auto v:g[u]){
		if(!vis[v])dfs(v);
	}
	t.push_back(u);
}
int32_t main()
{
   IOS
   cin>>n>>m;
   for(int i=1;i<=m;i++){
	   int u,v;cin>>u>>v;
	   g[u].push_back(v);
	  // g[v].push_back(u);
   }
   for(int i=1;i<=n;i++){
	   if(!vis[i])dfs(i);
   }
   int ans=0;
   for(auto u:t){
	   int mx=0;
	   for(auto v:g[u]){
		   mx=max(mx,dp[v]);
	   }
	   dp[u]=mx+1;
	   ans=max(ans,dp[u]);
	   //cout<< u << ":" << dp[u] << endl;
   }
   cout << ans -1<< endl;
   
   
  
   
}


Measured memory_bytes: 10488
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int x1,x2,x3;
    int a,b;
    int i=1;
    scanf("%d%d",&a,&b);
    x1=a+b;
    x2=a-b;
    x3=a*b;
    if(x1>x2)
        swap(x1,x2);
    if(x1>x3)
        swap(x1,x3);
    if(x2>x3)
        swap(x2,x3);
    printf("%d\n",x3);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    int a,b;
        
    public void solve(){
     int x = 0;
     Scanner sc = new Scanner(System.in);
     while(x < 7){

        int a = sc.nextInt();
        int b = sc.nextInt();

        System.out.println(a - b);
        x++;
    }
    }
    
    public static void main(String[] args){
        
        new Main().solve();
                
    }

}

Measured memory_bytes: 17240
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int X,N;
  cin >> X >> N;
  if(N==0){
    cout << X << endl;
    return 0;
  }
  int tmp=0;
  vector<int> P(N);
  for(int i=0; i<N; i++){
    cin >> tmp;
    P.at(i)=tmp;
  }
  sort(P.begin(), P.end());

  vector<int> P_non;
  bool flag = true;
  for(int i=1; i<=100; i++){
    for(int j=0; j<N; j++){
      if(i == P.at(j)) flag = false;
    }
    if(flag) P_non.push_back(i);
    flag=true;
  }
  P_non.push_back(0);
  P_non.push_back(101);
  sort(P_non.begin(), P_non.end());

  int diff=1000;
  int num=1000;
  for(unsigned int i=0; i<P_non.size(); i++){
    if(abs(P_non.at(i)-X) < diff){
      diff = abs(P_non.at(i)-X);
      num = i;
    } 
  } 
  cout << P_non.at(num) << endl;
  return 0;
}


Measured memory_bytes: 3640
#include<iostream>
    #include<cstdio>
    using namespace std;
     
    int n,ans,a[1000],b[1000];
     
    inline int get(int x){
    	int now=0;
    	for(int i=1;i<=x;i++)now+=a[i];
    	for(int i=x;i<=n;i++)now+=b[i];
    	return now;
    }
     
    int main(){
    	cin>>n;
    	for(int i=1;i<=n;i++)cin>>a[i];
    	for(int i=1;i<=n;i++)cin>>b[i];
    	for(int i=1;i<=n;i++){
    		ans=max(ans,get(i));
    	}
    	cout<<ans;
    	return 0;
    }

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    int ans = 0;
    for (int a = 1; a <= n; a++) {
      for (int b = 1; b <= n; b++) {
        int m = a * b;
        if (n - m >= 1) {
          ans++;
        } else {
          break;
        }
      }
    }
    pw.println(ans);
  }
}


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

int main(){
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i=0;i<n;i++) cin >> A[i];
    int count = 0;

    for(int i=0;i<n;i++){
        int minj = i;
        for(int j=i;j<n;j++){
            if(A[j]<A[minj]) minj = j;
        }
      	if(i!=minj){
        swap(A[i],A[minj]);
        count++;
        }
    }
  	for(int i=0;i<n;i++){
        if(i>0) cout << " ";
        cout << A[i];
    }
    cout << endl << count << endl;
}


Measured memory_bytes: 3060
import queue

H,W = map(int, input().split())
S = [input() for _ in range(H)]

def nexts(h, w):
    l = []
    if h > 0   and S[h-1][w] == '.':
        l.append((h-1, w))
    if h < H-1 and S[h+1][w] == '.':
        l.append((h+1, w))
    if w > 0   and S[h][w-1] == '.':
        l.append((h, w-1))
    if w < W-1 and S[h][w+1] == '.':
        l.append((h, w+1))
    return l

def bfs(h, w):
    d = [[0]*W for _ in range(H)]
    q = queue.Queue()
    q.put((h,w))

    while not q.empty():
        v = q.get()
        vh, vw = v[0], v[1]

        for nxt in nexts(vh, vw):
            nh, nw = nxt[0], nxt[1]
            if d[nh][nw] > 0:
                continue
            d[nh][nw] = d[vh][vw] + 1
            q.put((nh, nw))
    d[h][w] = 0
    return d

ans = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            continue

        d = bfs(h,w)
        mx = 0
        for th in range(H):
            for tw in range(W):
                mx = max(mx, d[th][tw])
        ans = max(ans, mx)
print(ans)


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

int main(){
    while(1){
        int n;
        cin >> n;
        if(n==0) break;

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

        for(int i=0; i<n; i++){
            int sp[5] = {5,7,5,7,7};
            int now = 0;
            for(int j=0; j<n; j++){
                sp[now] -= str[i+j].length();
                if(sp[now]<0) break;
                if(sp[now]==0) now++;
                if(now==5){
                    cout << i+1 << endl;
                    i=1e9;
                    break;
                }
            }
        }
    }   
    return 0;
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    int N,K;
    cin >> N >> K;
    int ans=1;
    rep(i,N){
        ans=min(ans+K,ans*2);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def f_c():
    import fractions
    a, b, c, d = map(int, input().split())
    c_n = b//c-a//c+1 if a%c==0 else b//c-a//c
    d_n = b//d-a//d+1 if a%d==0 else b//d-a//d
    cd = c*d//fractions.gcd(c, d)
    cd_n = b//cd-a//cd+1 if a%cd==0 else b//cd-a//cd
    print(b-a+1-(c_n+d_n-cd_n))

if __name__ == "__main__":
    f_c()


Measured memory_bytes: 5048
#include <stdio.h>

int main() {

int al[30] = {0};
char b[2000]= {0};
int i,j,n;

i=0;

while( scanf("%c",&b[i]) != EOF) {

if (b[i] >= 'A' && 'Z' >= b[i] ) {
n = b[i] - 'A';
al[n] += 1;

} else if(b[i] >=  'a' && b[i] <= 'z' ) {
n = b[i] - 'a';
al[n] += 1;
}
i=i+1;
}

for(j=97; j<=122; j++) {
n = j - 'a';
printf("%c : %d\n",j,al[n]);
}

return 0;

}



Measured memory_bytes: 2144
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import copy

def dfs(A, times):
    if times == N:
        if min(A[1:M+1]) >= X:
            ans[0] = min(A[0], ans[0])
        return
    dfs(copy.copy(A), times+1)
    for i in range(M+1):
        A[i] = A[i] + L[times][i]
    dfs(copy.copy(A), times+1)

N, M, X = map(int, input().split())
L = [0] * (N)
for i in range(N):
    L[i] = [int(x) for x in input().split()]

INF = float('inf')
ans = [INF]
tmp = [0] * (M+1)
dfs(tmp, 0)
if ans[0] == INF:
    ans[0] = -1
print(ans[0])

Measured memory_bytes: 70844
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<utility>
#include<cmath>
#include<functional>
using namespace std;
const int N=1000001;
struct Edge
{
    int to,next;
};
struct graph
{
    Edge edge[N<<1];   
    int head[N],cnt;
    void add_edge(int u,int v)
    {
        cnt++;
        edge[cnt].to=v;
        edge[cnt].next=head[u];
        head[u]=cnt;
        return;
    }
};
graph g1,g2,g;
int fa[N];
int fb[N];
int a1[N];
int a2[N];
int st[N];
int top;
int b[N];
int c[N];
void dfs1(int x)
{
    for(int i=g1.head[x];i;i=g1.edge[i].next)
    {
        int v=g1.edge[i].to;
        dfs1(v);
    }
    if(a1[x]) st[++top]=x;
    while(top>=2)
    {
        g.add_edge(st[top],st[top-1]);
        g.add_edge(st[top-1],st[top]);
        top-=2;
    }
}
void dfs2(int x)
{
    for(int i=g2.head[x];i;i=g2.edge[i].next)
    {
        int v=g2.edge[i].to;
        dfs2(v);
    }
    if(a2[x]) st[++top]=x;
    while(top>=2)
    {
        g.add_edge(st[top],st[top-1]);
        g.add_edge(st[top-1],st[top]);
        top-=2;
    }
}
void dfs(int x,int v)
{
    c[x]=v;
    b[x]=1;
    for(int i=g.head[x];i;i=g.edge[i].next)
        if(!b[g.edge[i].to]) dfs(g.edge[i].to,-v);
}
int main()
{
    int n;
    scanf("%d",&n);
    int i;
    int rt1,rt2;
    for(int i=1;i<=n;i++)
        a1[i]=a2[i]=1;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&fa[i]);
        if(fa[i]==-1) rt1=i;
        else
        {
            g1.add_edge(fa[i],i);
            a1[fa[i]]^=1;
        }
    }
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&fb[i]);
        if(fb[i]==-1) rt2=i;
        else
        {
            g2.add_edge(fb[i],i);
            a2[fb[i]]^=1;
        }
    }
    for(int i=1;i<=n;i++)
        if(a1[i]!=a2[i])
        {
            printf("IMPOSSIBLE\n");
            return 0;
        }
    printf("POSSIBLE\n");
    top=0;
    dfs1(rt1);
    top=0;
    dfs2(rt2);
    for(int i=1;i<=n;i++)
        if(!b[i]) dfs(i,1);
    for(int i=1;i<=n;i++)
        if(!a1[i]) printf("0 ");
        else printf("%d ",c[i]);
    return 0;
}

Measured memory_bytes: 35840