akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;

#define MAX_VERTEX 100
#define INF 1000000

int d[MAX_VERTEX][MAX_VERTEX];

int main() {
  int vertex_num;
  cin >> vertex_num;

  for(int i = 0; i < vertex_num; i++) {
    for(int j = 0; j < vertex_num; j++) {
      if (i == j) d[i][i] = 0;
      else d[i][j] = INF;
    }
  }

  for (int i = 0; i < vertex_num; i++) {
    int vertex, out;
    cin >> vertex >> out;
    for(int j = 0; j < out; j++) {
      int to, c;
      cin >> to >> c;
      d[vertex][to] = c;
    }
  }

  for (int k = 0; k < vertex_num; k++) {
    for (int i = 0; i < vertex_num; i++) {
      for (int j = 0; j < vertex_num; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }

  for(int i = 0; i < vertex_num; i++) {
    cout << i << " " << d[0][i] << endl;
  }

  return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll A[300005];
ll di[60];
ll t;
ll ret = 0;

void input() {
  IN(N);
  REP(i, N) {
    IN(t);
    A[i] = t;
  }
}

void solve() {
  REP(j, 60) {
    ll x = 0;
    REP(i, N) {
      x += (A[i] >> j) & 1;
    }
    // DEBUG(x);
    ll p = x * (N - x) % MOD;
    REP(k, j) p = p * 2 % MOD;
    ret += p;
    ret %= MOD;
  }
  PRINT(ret);
}

int main(void){
  input();
  solve();
}


Measured memory_bytes: 2560
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    int cnt = 0;
    for (int i = 0; i < S.length() / 2; i++) {
      if (S.charAt(i) != S.charAt(S.length() - i - 1)) {
        cnt++;
      }
    }
    System.out.println(cnt);
  }
}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
int l,t=1;
string st;
int main()
{
	cin>>st;
	l=st.size();
	st=' '+st;
	if(st[1]=='0') 
	{
		cout<<-1;
		return 0;
	}
    if(st[l]=='1') 
	{
		cout<<-1;
		return 0;
	}
    for(int i=1;i<l;i++)
    {
        if(st[i]!=st[l-i]) 
		{
			cout<<-1;
			return 0;
		}
    }
    for(int i=1;i<l;i++)
	{
        cout<<i+1<<" "<<t<<endl;
        if(st[i]=='1') t=i+1;
    }
    return 0;
}

Measured memory_bytes: 3816
#include<iostream>
#include<cmath>
using ll = long long;
using namespace std;
int main(){
    ll n,a,b,ans=0;
    cin >> n;
    for(ll i=1;i<=sqrt(n);i++){
        if(n%i==0)  a=i,b=n/i;
    }
while(a!=0||b!=0){
        a/=10;
        b/=10;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> w(n);
    int sum_all = 0;
    for (int i = 0; i < n; i++) {
        cin >> w[i];
        sum_all += w[i];
    }
    
    int sum = 0;
    int ans = 1e9;
    for (int t = 0; t <= n - 2; t++) {
        sum += w[t];
        int rest = sum_all - sum;
        ans = min(ans, abs(rest - sum));
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
#define INF (1<<28)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long

signed main(){
  int h,w,a,b;
  cin>>h>>w>>a>>b;
  cout<<(h%a)*w+(w%b)*h-(h%a)*(w%b)<<endl;
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define forin(in) for(int i=0; i<(int)in.size(); i++) cin>>in[i]
#define forout(out) for(int i=0; i<(int)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for(int i=0; i<(n); i++)

int main(){
    int N, M; cin>> N >> M;
    vector<int> s(M), c(M);
    rep(i, M){
        cin>> s[i] >> c[i];
        s[i]--;
    }

    for(int i = 0; i<= 999; i++){
        stringstream iss;
        iss << i;
        string ii = iss.str();
        if(ii.size() == N){
            bool judge = true;
            rep(i, M){
                if(ii[s[i]] != c[i] + '0') judge = false;
            }
            if(judge){
                cout<< i << endl;
                return 0;
            }
        }
    }
    cout<< -1 << endl;
}

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

bool pal(string s) {
  string t = s;
  reverse(t.begin(), t.end());
  return s == t;
}

int main() {
  string S;
  cin >> S;
  cout << ((pal(S)) ? "Yes" : "No") << "\n";
}

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

int main() {
	long long K, A, B;
	cin >> K >> A >> B;
	if (B - A < 2) cout << K + 1 << endl;
	else {
		if (K - 2 + 1 < A) cout << K + 1 << endl;
		else cout << A + (K - A + 1) / 2 * (B - A) + (K - A + 1) % 2;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }




void solve() {
    int r, g;
    cin >> r >> g;
    cout << 2 * g - r << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int T;
    // cin >> T;
    T = 1;
    
    while (T--) {
        solve();
    }
}





Measured memory_bytes: 256
# ABC061B
N,M = map(int, input().split())
AB = [[] for _ in range(N)]
for _ in range(M):
    a,b = map(int, input().split())
    AB[a-1].append(b-1)
    AB[b-1].append(a-1)
for i in range(N):
    print(len(AB[i]))

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

public class Main {
    static long[] food;
    static long[] team;
    static long k;

    public static boolean poss(long t){
        long count = 0;
        for(int i = 0; i<food.length; i++){
            if(food[i]*team[i] > t){
                count += team[i] - t/food[i];
            }
        }
        if(count > k){
            return false;
        }
        return true;
    }

    public static void main(String[] args) throws IOException{
        //Scanner sc = new Scanner(System.in);
        FastReader sc = new FastReader();
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        k = sc.nextLong();
        team = new long[n];
        food = new long[n];
        for(int i = 0; i<n; i++){
            team[i] = sc.nextInt();
        }
        for(int j = 0; j<n; j++){
            food[j] = sc.nextInt();
        }
        Arrays.sort(team);
        Arrays.sort(food);
        long[] foodRev = new long[n];
        for(int i = 0; i<n; i++){
            foodRev[i] = food[n-i-1];
        }
        for(int i = 0; i<n; i++){
            food[i] = foodRev[i];
        }


        long max = (long)1e12+10;
        long min = 0;
        for(int i = 0; i<= 50; i++){
            long mid = (max + min) / 2;
            if(poss(mid)){
                max = mid;
            }
            else{
                min = mid + 1;
            }
        }
        if(poss(Math.min(max,min))){
            pw.println(Math.min(max,min));
        }
        else{
            pw.println(Math.max(max,min));
        }
        pw.close();
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 56028
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


int main()
{
	int n;
	cin >> n;
	if (n >= 1000) cout << "ABD";
	else cout << "ABC" << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
int main() {
    int a, b, ans = 0;
    scanf("%d %d", &a, &b);
    if (a >= 13) {
        ans = b;
    } else if (a >= 6) {
        ans = b>>1;
    }
    printf("%d\n", ans);
}


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

using namespace std;
using ll = long long;

#define rep(i,n) for(int i=0; i<n; i++)
#define INFL 0x3f3f3f3f3f3f3f3f

long long n;
int a, b, c, d;
unordered_map<long long, long long> memo;

long long solve(long long n) {
    if (memo.count(n) > 0) {
        return memo[n];
    }
    if (n <= 1) {
        return n * d;
    }

    long long ret = INFL;
    if (log10(n) + log10(d) < 16) ret = min(ret, n*d);
    ret = min(ret, (n%2)*d + a + solve(n/2));
    if (n != 2) ret = min(ret, (2 - n%2)*d + a + solve(n/2 + 1));
    ret = min(ret, (n%3)*d + b + solve(n/3));
    ret = min(ret, (3 - n%3)*d + b + solve(n/3 + 1));
    ret = min(ret, (n%5)*d + c + solve(n/5));
    ret = min(ret, (5 - n%5)*d + c + solve(n/5 + 1));

    return memo[n] = ret;
}

int main() {
    int t;
    cin >> t;
    rep(_, t) {
        cin >> n >> a >> b >> c >> d;
        memo.clear();
        cout << solve(n) << endl;
    }
}

Measured memory_bytes: 4624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

string s, t;

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

    cin >> s;
    if(s[0] == 'M') cout << 6 << endl;
    else if(s[0] == 'W') cout << 4 << endl;
    else if(s[0] == 'F') cout << 2 <<endl;
    else if(s[2] == 'N') cout << 7 << endl;
    else if(s[2] == 'E') cout << 5 << endl;
    else if(s[2] == 'T') cout << 1 << endl;
    else if(s[2] == 'U') cout << 3 <<endl;



    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {

    int count = 0;
    public static void main(String[] args) {
        new Main().runner();
    }

    public void runner() {
        Scanner in = new Scanner(System.in);
        int n=Integer.parseInt(in.next());
        int A[] = new int[n];
        for(int i=0; i<n; i++) {
            A[i] = Integer.parseInt(in.next());
        }
        MergeSort(A, 0, n);
        System.out.print(A[0]);
        for (int i = 1; i < n; i++) {
            System.out.print(" " +A[i]);
        }
        System.out.println();
        System.out.println(count);
        
    }

    public void Merge(int[] A, int left,int  mid, int right) {
        int n1 = mid - left;
        int n2 = right - mid;
        int[] l = new int[n1 + 1];
        int[] r = new int[n2 + 1];
        for (int i = 0; i < n1; i++) {
            l[i] = A[left + i];
        }
        for (int i = 0; i < n2; i++) {
            r[i] = A[mid + i];
        }
        l[n1] = Integer.MAX_VALUE;
        r[n2] = Integer.MAX_VALUE;

        int L = 0;
        int R = 0;
        for (int k = left; k < right; k++) {
            if (l[L] <= r[R]) {
                A[k] = l[L++];
            } else {
                A[k] = r[R++];
            }
            count++;
        }
    }


    public void MergeSort(int[] A, int left, int right) {
        if (left + 1 < right) {
            int mid = (left + right) / 2;
            MergeSort(A, left, mid);
            MergeSort(A, mid, right);
            Merge(A, left, mid, right);
        }
    }
}


Measured memory_bytes: 109424
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  int result = 0, r = 0;
  F0R(i, N) {
    int a, b;
    cin >> a >> b;
    if (a == b) {
      r++;
    }
    else {
      r = 0;
    }
    chmax(result, r);
  }
  cout << (result >= 3 ? "Yes" : "No");
}
#endif


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

int n, k;
bool d[11];

int main(){
    cin >> n >> k;
    rep(i,k) {
        int tmp;
        cin >> tmp;
        d[tmp] = true;
    }
    for (int i = n;; i++) {
        int j = i;
        bool ok = true;
        while (j) {
            if (d[j%10]) {
                ok = false;
                break;
            }
            j /= 10;
        }
        if (ok) {
            cout << i << endl;
            return 0;
        }
    }
}
































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

#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>

using namespace std;


//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int power(int a,int n)
{
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return a*power(a*a,n/2);
    return power(a*a,n/2);
}
const int md = 998244353;
const int inf = (int) 1e18;

/*int inverse(int x){

    return power(x,mod-2)%mod;//little fermat....
}*/


signed main()
{
    showoff;
    int a,p;
    cin >> a >> p;
    cout << (3*a+p)/2;
    
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...    

Measured memory_bytes: 256
def matrix(n):
    x = [[0 for i in range(len(n))] for j in range(len(n))]
    for l in range(2, len(n)+1):
        for i in range(0, len(n)-l+1):
            j = i + l - 1
            x[i][j] = min(x[i][k] + x[k+1][j] + X[i][0]*X[k][1]*X[j][1] for k in range(i, j))

    print x[0][len(n)-1]

n = input()
X = []

for i in range(n):
    X.append(map(int, raw_input().split()))

matrix(X)

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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  string S;
  cin >> S;
  char one = S[S.size()-1];
  if(one == '2' || one == '4' || one == '5'|| one == '7'|| one == '9'){
    cout << "hon" <<endl;
  } else if(one == '0' ||one == '1' ||one == '6' ||one == '8'){
    cout << "pon" <<endl;
  } else{
    cout << "bon" <<endl;
  }
}


Measured memory_bytes: 3596
// D - Integer Cards
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rp(i,n) for(int i=0;i<(n);i++)
#define pb(x) push_back(x)

int main(){
	int N,M; cin>>N>>M;

	vector<ll> A(N);
	rp(i,N) cin>>A[i];
	sort(A.begin(), A.end());

	vector<pair<ll,int>> B;
	rp(i,M){
		int b; ll c; cin>>b>>c;
		B.pb(make_pair(c,b));
	}
	sort(B.begin(), B.end());

	vector<ll> C;
	int n=N-1;
	ll value; int count;
	for(int m=M-1; m>=0 && C.size()<N; --m){
		tie(value, count) = B[m];
		while(C.size()<N && n>=0 && value <= A[n]) C.pb(A[n--]);
		if(n<0 || C.size()>=N) break;
		while(C.size()<N && n>=0 && count-->0) C.pb(value);
		if(n<0 || C.size()>=N) break;
	}

	if(C.size()<N) while(n && C.size()<N) C.pb(A[n--]);

	ll ans = 0; rp(i,C.size()) ans += C[i];
	cout<< ans <<endl;
}

Measured memory_bytes: 4464
def dfs(p, ans):
    c[p] = False
    terminal = True
    for x in e[p]:
        if c[x]:
            terminal = False
            ans = dfs(x, ans)
    
    if terminal:
        if not any(c):
            ans += 1
    c[p] = True
    
    return ans

(n,m), *s = [list(map(int, s.split())) for s in open(0)]

e = [[] for _ in range(n)]
for i,j in s:
    e[i-1].append(j-1)
    e[j-1].append(i-1)

c = [True]*n

ans = dfs(0, 0)

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<queue>
using namespace std;
int main () {
  int H, W;
  cin >> H >> W;
  char maze[60][60];
  int sum = 0;
  for (int i = 1; i <= H; i ++) {
    for (int j = 1; j <= W; j ++) {
      cin >> maze[i][j];
      if (maze[i][j] == '.') sum ++;
    }
  }
  for (int i = 1; i <= H; i ++) {
    maze[i][0] = maze[i][W + 1] = '#';
  }
  for (int i = 1; i <= W; i ++) {
    maze[0][i] = maze[H + 1][i] = '#';
  }
  int ans[60][60];
  for (int i = 1; i <= H; i ++) {
    for (int j = 1; j <= W; j ++) {
      ans[i][j] = -1;
    }
  }
  ans[1][1] = 0;
  queue<int>qx;
  queue<int>qy;
  qx.push(1);
  qy.push(1);
  int x[] = {0, 1, 0, -1};
  int y[] = {1, 0, -1, 0};
  while(!qx.empty()) {
    int ux = qx.front();
    int uy = qy.front();
    for (int i = 0; i < 4; i ++) {
      int vx = ux + x[i];
      int vy = uy + y[i];
      if (maze[vx][vy] == '.' && ans[vx][vy] == -1) {
        qx.push(vx);
        qy.push(vy);
        ans[vx][vy] = ans[ux][uy] + 1;
      }
    }
    qx.pop();
    qy.pop();
  }
  if (ans[H][W] == -1) cout << -1 << endl;
  else cout << sum - ans[H][W] - 1 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		bubbleSort(A, N);
		sc.close();
	}

	public static void bubbleSort(int[] A, int N) {
		int count = 0;
		boolean flag = true;
		for (int i = 0; flag; i++) {
			flag = false;
			for (int j = N - 1; j >= i + 1; j--) {
				if (A[j] < A[j - 1]) {
					int tmp = A[j];
					A[j] = A[j - 1];
					A[j - 1] = tmp;
					flag = true;
					count++;
				}
			}
		}
		for (int i = 0; i < N; i++) {
			if (i > 0) {
				System.out.print(" ");
			}
			System.out.print(A[i]);
		}
		System.out.printf("\n");
		System.out.println(count);
	}
}



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

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using uint=unsigned int;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

ll readLL(){
	ll i;
	scanf("%lld",&i);
	return i;
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

int main(){
	int n=read(),x=read();
	if(n==2){
		if(x==2)
			cout<<"Yes\n1 2 3"<<endl;
		else
			cout<<"No"<<endl;
	}else{
		if(x==1||x==2*n-1){
			cout<<"No"<<endl;
			return 0;
		}
		cout<<"Yes"<<endl;
		vector<int> use;
		FOR(i,2,2*n-1)
			if(i!=x)
				use.PB(i);
		REP(i,n-2)
			cout<<use[i]<<" ";
		cout<<2*n-1<<" ";
		cout<<x<<" ";
		cout<<1;
		FOR(i,n-2,(n-2)*2)
			cout<<" "<<use[i];
		cout<<endl;
	}
}


Measured memory_bytes: 2420
#include <iostream>
using namespace std;
int main()
{
    int num,score1=0,score2=0;
    string str1,str2;
    cin>>num;
    for(int i=0;i<num;i++)
    {
        cin>>str1>>str2;
        if(str1==str2)
        {score1++;score2++;}
        else if(str1>str2)
            score1+=3;
        else
            score2+=3;
    }
    cout<<score1<<" "<<score2<<endl;
    return 0;
}


Measured memory_bytes: 3160
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var w = cin.nextInt();
            var a = cin.nextInt();
            var b = cin.nextInt();

            Console.WriteLine(Math.Abs(a-b)<=w?0: Math.Abs(a - b)-w);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}

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


#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define pli pair<long long,int>
#define pil pair<int,long long>
#define ll long long
#define el '\n'

using namespace std;

const int N = 1e5 + 10;

int n;
ll ar[N], cnt[N];
int q;
ll tot = 0;

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

    cin >> n;
    for (int i=1;i<=n;i++){
        cin >> ar[i];
        cnt[ar[i]]++;
        tot += ar[i];
    }
    cin >> q;
    while (q--){
        ll a, b;
        cin >> a >> b;
        tot += (b - a) * cnt[a];
        cnt[b] += cnt[a];
        cnt[a] = 0;
        cout << tot << el;
    }

    return 0;
}

Measured memory_bytes: 5176
'use strict';

function main(stdin) {
  const input = stdin.split('\n');
  const N = Number(input.shift());
  const params = input[0].split(' ').map(v => parseInt(v, 10));

  let max = 0;
  let cur = 0;

  params.reduce((a, b) => {
    if (a >= b) {
      ++cur;
      if (cur > max) max = cur;
    } else {
      cur = 0;
    }
    return b;
  })
  
  console.log(max);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim());

Measured memory_bytes: 17932
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long int;
using ull = unsigned long long int;
using P = pair<int, int>;
using P3 = pair<int,P>;
using PP = pair<P ,P>;
constexpr ll MOD = ll(1e9+7);
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e6) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int n, m;
vector<ll> d, len, color;
vector<P> ord;
vector<vector<P> > g;
vector<bool> used;

int main(){
    cin >> n >> m;
    d.resize(n);
    g.resize(n);
    used.resize(n);
    color.resize(n,-1);
    len.resize(m);
    for(int i=0;i<n;i++){
        cin >> d[i];
        ord.push_back(P(d[i],i));
    }
    for(int i=0;i<m;i++){
        int u, v;
        cin >> u >> v;
        u--; v--;
        g[u].push_back(P(v,i));
        g[v].push_back(P(u,i));
    }
    SORT(ord);
    bool ok = true;
    for(int i=0;i<n;i++){
        int idx = ord[i].second;
        if(used[idx]) continue;
        for(auto &e : g[idx]){
            int v = e.first;
            if(d[v] <= d[idx]){
                len[e.second] = d[idx];
                if(used[v]){
                    color[idx] = color[v]^1;
                }else{
                    color[idx] = 0;
                    color[v] = 1;
                    used[v] = true;
                }
                used[idx] = true;
                break;
            }
        }
        if(!used[idx]) ok = false;
    }
    if(ok){
        for(int i=0;i<n;i++){
            cout << (color[i]==0 ? 'W' : 'B');
        }
        cout << endl;
        for(int i=0;i<m;i++){
            cout << (len[i]>0 ? len[i] : int(1e9)) << endl;
        }
    }else{
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 14328
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
int main(){
    int n;cin>>n;
    vector<ll> v[n+1];
    rep(i,0,n-1){
        ll a,b;cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    ll r[n+1];
    fill(r,r+n+1,-inf);
    ll k;cin>>k;
    priority_queue<pll,vector<pll>,greater<pll>> q;
    rep(i,0,k){
        ll a,b;cin>>a>>b;
        r[a]=b;
        q.push({b,a});
    }
    while(q.size()>0){
        pll p=q.top();q.pop();
        ll now=p.second;
        //rep(i,1,n+1)cout<<r[i]<<" ";
        //cout<<endl;
        rep(i,0,v[now].size()){
            ll ne=v[now][i];
            if(r[ne]==-inf){
                q.push({p.first+1,ne});
                r[ne]=p.first+1;
            }
            else{
                if(r[ne]!=p.first+1&&r[ne]!=p.first-1){
                    cout<<"No"<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"Yes"<<endl;
    rep(i,1,n+1)cout<<r[i]<<endl;
}


Measured memory_bytes: 9460
import java.util.*

fun addOne(tree:TreeMap<Int,Int>,key:Int) = tree.put(key,(tree[key]?:0)+1)
fun removeOne(tree:TreeMap<Int,Int>,key:Int) = if(tree[key]==1)tree.remove(key) else tree.put(key,tree[key]!!-1)
fun readList() = readLine()!!.split(" ").map{it.toInt()}
fun main(args:Array<String>){
  val (N,M) = readList()
  val A = readList()
  val T = TreeMap<Int,Int>()
  var answer = 0L
  for(x in A){
    addOne(T,x)
  }
  for(i in 0 until M){
    val x = T.lastKey()
    removeOne(T,x)
    addOne(T,(x/2).toInt())
  }
  T.forEach{answer += it.key.toLong()*it.value.toLong()}
  println(answer)
}

Measured memory_bytes: 74480
#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono; 
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> > 
#define pb push_back
#define f first
// #define s second
#define int long long
#define float long double
#define all(c) (c).begin(), (c).end()
#define endl '\n'
#define pi 3.14159265358979323846

ll pow(ll a,ll p,ll m=mod)
{ll res=1;while(p>0){if(p&1)res=(res*a)%m;a=(a*a)%m;p>>=1;}
return res;}


int32_t main()
{
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     cout.tie(0);
   	
 //    int t;
 //     cin >> t;

 //     while(t--){


 // }

     int n,m;
     cin >> n >> m;
     vi height(n);
     vi adj[n];
     fo(i,0,n)cin >> height[i];
     fo(i,0,m){
     	int a,b;
     	cin >> a >> b;
     	a--;
     	b--;
     	adj[a].pb(b);
     	adj[b].pb(a);
     }
     vi greater(n);
     for(int i = 0;i < n;i++){
     	if(adj[i].size() == 0)greater[i] = 1;
     	else{
     		int ma = height[i];
     		int flag = 0;
     		for(int j = 0;j < adj[i].size();j++){
     			if(ma <= height[adj[i][j]]){
     				flag = 1;
     				break;
     			}
     		}
     		if(flag)continue;
     		greater[i] = 1;
     	}
     }
     int count = 0;
     fo(i,0,n)
     	if(greater[i])count++;

     cout << count << endl;
     

return 0;
	
	}




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

int main(){
    int H, W;
    cin >> H >> W;
    vector<vector<char>> V(H+1, vector<char>(W+1));
    for(int i = 1; i <= H; ++i){
        for(int j = 1; j <= W; ++j){
            cin >> V[i][j];
        }
    }
    for(int i = 1; i <= H; ++i){
        for(int j = 1; j <= W; ++j){
            if(V[i][j] == '#') break;
            else if(j == W){
                for(int k = 1; k <= W; ++k) V[i][k] = '@';
            }
        }
    }
    for(int j = 1; j <= W; ++j){
        for(int i = 1; i <= H; ++i){
            if(V[i][j] == '#') break;
            else if(i == H){
                for(int k = 1; k <= H; ++k) V[k][j] = '@';
            }
        }
    }
    for(int i = 1; i <= H; ++i){
        int flag = 0;
        for(int j = 1; j <= W; ++j){
            if(V[i][j] != '@'){
                flag = 1;
                cout << V[i][j];
            }
        }
        if(flag) cout << endl;
    }
    return 0;
}

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

int count_div(int v) {
  int ret = 0;
  while (v % 100 == 0) {
    ++ret;
    v /= 100;
  }
  return ret;
}

int main(int, char**) {
  int D, N;
  cin >> D >> N;

  int counter = 0, value = 0;
  while (counter < N) {
    ++value;
    if (count_div(value) == D)
      ++counter;
  }
  cout << value << endl;
  return 0;
}

Measured memory_bytes: 256
class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n)) #親ノード
        self.size = [1]*n #グループの要素数
 
    def root(self, x): #root(x): xの根ノードを返す．
        while self.parent[x] != x:
            self.parent[x] = self.parent[self.parent[x]]
            x = self.parent[x]
        return x 
 
    def merge(self, x, y): #merge(x,y): xのいる組とyのいる組をまとめる
        x, y = self.root(x), self.root(y)
        if x == y: return False
        if self.size[x] < self.size[y]: x,y=y,x #xの要素数が大きいように
        self.size[x] += self.size[y] #xの要素数を更新
        self.parent[y] = x #yをxにつなぐ
        return True
 
    def issame(self, x, y): #same(x,y): xとyが同じ組ならTrue
        return self.root(x) == self.root(y)
        
    def getsize(self,x): #size(x): xのいるグループの要素数を返す
        return self.size[self.root(x)]


# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n = int(readline())
xyi = []

for i in range(n):
    x,y = map(int,readline().split())
    xyi.append((x,y,i))

UF = UnionFind(n)
xyi.sort(key = lambda p:p[0])
#print(xyi)

q = []
for x,y,i in xyi:
    #print(q)
    if q and q[-1][0] < y: Y,I = q[-1]
    else: Y,I = y,i
    while q and q[-1][0] < y:
        yy,ii = q.pop()
        UF.merge(i,ii)
    q.append((Y,I))
    #print(i,idx)

for i in range(n):
    print(UF.getsize(i))



Measured memory_bytes: 114004
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
#define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n";

int main()
{
    int n;
    cin >> n;
    int mai = n / 1000;
    if (n % 1000 != 0) mai++;
    int ans = mai * 1000 - n;
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3596
def divisors(n):
    d=[]
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            d.append(i)
            if i!=n//i:
                d.append(n//i)
    d.sort()
    return d

a,b,k=map(int,input().split())
print(sorted(list(set(divisors(a))&set(divisors(b))))[::-1][k-1])

Measured memory_bytes: 9352
import collections
N=int(input())
A=[int(x) for x in input().split()]
A_1=collections.Counter(A)
i=0
if 2<=N<=2*10**5:
    for i in range(0,N-1):
        if 0<=i<=N-2:
            if 1<=A[i]<i+2:
                j=i+1
                print(A_1[j])
                i+=1
        if i==N-1:
            print(0)

Measured memory_bytes: 35492
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <queue>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <random>
#include <functional>

using namespace std;

#define F first
#define S second
#define pb push_back
#define epr(...) fprintf(stderr, __VA_ARGS__)
#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; 
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"
#define dbv(a) cerr << #a << ": "; for (auto& xxxx: a) cerr << xxxx << " "; cerr << endl;
#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)a.size()
#define pw(n) (1ll << (n))
#define equal equalll
#define less lesss

typedef double dbl;
typedef long long ll;
const int N = -1;
const int INF = 1.01e9;
typedef vector<int> vi;



int main() {
#ifdef HOME 
    assert(freopen("in", "r", stdin));
#endif
    for (int n = 1000; n <= 2000; n++) {
        for (int k = 1; k <= 1000; k++) {
            if (n * (n - 1) / 2 == n * k * (k - 1) / 2) {
                db2(n, k);
            }
        }
    }


    int p = 37;
    int n = p * p + p + 1;
    vector<vector<int>> answer(n);
    int cur = 0;
    for (int a = 0; a < p; a++) {
        for (int b = 0; b < p; b++, cur++) {
            for (int x = 0; x < p; x++) {
                int y = (a * x + b) % p;
                int id = x * p + y;
                answer[id].pb(cur);
            }
            int id = p * p + a;
            answer[id].pb(cur);
        }
    }

    for (int a = 0; a < p; a++, cur++) {
        for (int y = 0; y < p ;y++) {
            int id = a * p + y;
            answer[id].pb(cur);
        }
        answer[p * p + p].pb(cur);
    }

    for (int i = 0; i < p; i++) {
        answer[p * p + i].pb(cur);
    }
    answer[p * p + p].pb(cur);
    cur++;
    db(cur);
    assert(cur == n);

    for (int i = 0; i < n; i++) {
        set<int> q(all(answer[i]));
        for (int j = i + 1; j < n; j++) {
            int g = 0; 
            for (auto x: answer[j]) {
                g += q.count(x);
            }
            //db3(g, i, j);
            assert(g == 1);
        }
        assert((int)answer[i].size() == p + 1);
    }

    cout << n << " " << p + 1 << endl;
    for (auto x: answer) {
        for (auto y: x) {
            cout << y + 1 << " ";
        }
        cout << endl;
    }

    //db2(n, p);



#ifdef HOME 
    epr("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
#endif
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <queue>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include <map>
#include <stack>
#include <iomanip>
#include <set>
#include <sstream>
#include <cmath>
#include <deque>
#include <list>
#include <bitset>
using namespace  std;
typedef pair<string, int> Psi;
typedef pair<long long , long long> P;
typedef long long int64;
typedef long long lint;
#define REP(i, n) for(int (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(int (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define FST first
#define SND second
lint func(lint n){
    if(n%2==0){
        if((n/2)%2 == 1) return 1^n;
        else return 0^n;
    }
    else{
        if(((n+1)/2)%2 ==0) return 0;
        else return 1;
    }
}
signed main(){
    lint A, B; cin >> A >> B;
    lint res = func(A-1);
    res ^= func(B);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

	static Scanner scan = new Scanner(System.in);
	static PrintWriter out = new PrintWriter(System.out);

	static int cnt = 0;

	public static void main(String[] args) {
		while(true){
			int n = si(),m = si();
			if(n==0) break;
			out.println(gcd(n,m)+" "+(cnt-1));
			cnt = 0;
		}
		out.flush();
	}

	static int gcd(int a,int b){
		cnt++;
		if(b==0) return a;
		if(a<b) return gcd(a,b%a);
		else return gcd(b,a%b);
	}

	static int si() {
		return Integer.parseInt(scan.next());
	}
}

Measured memory_bytes: 23200
#include <iostream>

using namespace std;

int main()
{
    string goal="ABC";
    int N;cin>>N;
    string S;cin>>S;

    string findd="";

    int counter=0;
    for(int i=0;i<N;i++)
    {
    findd+=S[i];
    findd+=S[i+1];
    findd+=S[i+2];
    if(findd==goal)
    {
        counter++;
    }
    findd="";
    }
    cout<<counter;
      return 0;
}


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

using namespace std;
typedef long long ll;
#define sz size()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
const ll MOD=1000000007;

//a,b x
int main(){
	string s; cin>>s;
	ll dp[100000][4];//dp[x][y]:x(0-origin)文字まで決めてy個は決めた
	//ans=dp[s.sz-1][3]

	rep(i,100000)rep(j,4) dp[i][j]=0;

	if(s[0]=='A'){
		dp[0][0]=1;
		dp[0][1]=1;
	}
	else if(s[0]=='?'){
		dp[0][0]=3;
		dp[0][1]=1;
	}
	else dp[0][0]=1;

	rep1(i,s.sz-1){
		if(s[i]=='A'){
			rep(j,4) dp[i][j]=dp[i-1][j];
			dp[i][1]+=dp[i-1][0];
			dp[i][1]%=MOD;
		}
		else if(s[i]=='B'){
			rep(j,4) dp[i][j]=dp[i-1][j];
			dp[i][2]+=dp[i-1][1];
			dp[i][2]%=MOD;
		}
		else if(s[i]=='C'){
			rep(j,4) dp[i][j]=dp[i-1][j];
			dp[i][3]+=dp[i-1][2];
			dp[i][3]%=MOD;
		}
		else{
			rep(j,4) dp[i][j]=(dp[i-1][j]*3)%MOD;
			dp[i][1]+=dp[i-1][0];
			dp[i][2]+=dp[i-1][1];
			dp[i][3]+=dp[i-1][2];
			dp[i][1]%=MOD;
			dp[i][2]%=MOD;
			dp[i][3]%=MOD;
		}
	}
	cout<<dp[s.sz-1][3];	
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define N 200005
 

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	
	int x,n;
	cin>>x>>n;

	int i,a[N]={0},s;
	for(i=0;i<n;i++){
		cin>>s;
		a[s]++;
	}


	int ans=1e9,val=0;
	for(i=x;i>=0;i--){
		if(!a[i] && (x-i)<ans){
			ans=x-i;
			val=i;
		}
	}
	for(i=x+1;i<=101;i++){
		if(!a[i] && (i-x)<ans){
			ans=x-i;
			val=i;
		}	
	}
	cout<<val<<endl;
	return 0;
}

Measured memory_bytes: 4412