akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define DEBUG(x)           cout << '>' << #x << ':' << x << endl;
#define forn(i,n)          for(int i=0;i<(int)n;++i)
#define for1(i,n)          for(int i=1;i<=(int)n;++i)
#define forr(i,n)          for(int i=(int)n-1;i>=0;--i)
#define forre(i,a,b)       for(int i=(int)b;i>=(int)a;--i)
#define fore(i,a,b)        for(int i=(int)a;i<=(int)b;++i)
#define input(arr,n)       for(int i=0;i<n;i++)cin>>arr[i]
#define output(arr,n)      for(int i=0;i<n;i++)cout<<arr[i]<<" "
#define for_each(arr)      for(auto& it:arr)cout<<it<<" "
#define ff                 first
#define ss                 second
#define PI                 acos(-1.0)
#define all(a)             a.begin(),a.end()
#define rall(a)            a.rbegin(),a.rend()
#define Unique(a)          sort(all(a)),a.erase(unique(all(a)),a.end())
#define pb(x)              push_back(x)
#define eb(x)              emplace_back(x) 
#define ppb(x)             pop_back(x)
#define pf(x)              push_front(x)
#define ppf(x)             pop_front(x)
#define in(x,y)            insert({x,y})
#define Sort(a)            sort(a.begin(),a.end())
#define mem(arr,a)         memset(arr,a,sizeof arr)
#define ins(a)             insert(a)
#define max2(a,b)          max(a,b)
#define max3(a,b,c)        max(a,max(b,c))
#define max4(a,b,c,d)      max(a,max3(b,c,d))
#define min2(a,b)          min(a,b)
#define min3(a,b,c)        min(a,min(b,c))
#define min4(a,b,c,d)      min(a,min3(b,c,d))
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<char> vc;
typedef vector<double> vd;
/*inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void Set(int & n, int b) { n |= two(b); }
inline void Reset(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }*/
/*int fx1[]={+1,-1,+0,+0};
int fy1[]={+0,+0,+1,-1};
int fx2={+0,+0,+1,-1,-1,+1,-1,+1};
int fy2={-1,+1,+0,+0,+1,+1,-1,-1};
*/

ll a,b,c,n,ans,cn1,cn2,cn3,t;
string s,s1,s2;


int main()
{
    FIO;
   // #ifndef ONLINE_JUDGE
  //  freopen("input.txt","r",stdin);
  //  freopen("output.txt","w",stdout);
   // #endif
    cin>>a>>b;
    for(int i=0;i<a;i++){
    	s+=to_string(b);
    }
    for(int i=0;i<b;i++){
    	s1+=to_string(a);
    }
    if(s<=s1)cout<<s<<endl;
    else cout<<s1<<endl;
    
    

    
   	
    #ifdef ONLINE_JUDGE
    cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
    #endif
   return 0;
}
 


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

bool binarySearch(int *A,unsigned n,int key){
    int left = 0;
    int right = n;
    while(left<right){
        int mid = (left+right)/2;
        if(A[mid]==key)
            return true;
        else if(key<A[mid])
            right = mid;
        else
            left = mid+1;
    }
    return false;
}

int main(){
    unsigned n, q, count = 0;
    int *S,*T;
    
    cin >> n;
    S = new int[n];
    for(int i=0;i<n;i++)
        cin >> S[i];

    cin >> q;
    T = new int[q];
    for(int i=0;i<q;i++)
        cin >> T[i];

    for(int i=0;i<q;i++){
        if(binarySearch(S,n,T[i]))
            count++;
    }

    cout << count << endl;

    return 0;

}


Measured memory_bytes: 3616
import bisect
import math

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29

DIV = (10**9) + 7


def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def ncr(n, r, mod=DIV):
	r = min(r, n-r)
	ret = 1
	for i in range(1, r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % mod) % mod
    return CONV()


def main():
    a,b,c = isRaw()

    if (c-a-b)<0:
        return "No"
    return "Yes" if (4*a*b < (c-a-b)**2) else "No"


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 38384
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　 ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl

#define rep(i, n) REP(i, 0, n)                  // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++) // x, x + 1, ..., n-1
#define FOREACH(x, a) for(auto &(x) : (a))

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    while(1) {
        int n;
        cin >> n;
        if(n == 0) break;
        vector<ll> dp(31);

        dp[0] = dp[1] = 1;
        dp[2]         = 2;

        for(int i = 3; i <= 30; i++) {
            dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3];
        }
        cout << (dp[n] / 10 / 365 + 1) << endl;
    }
}



Measured memory_bytes: 3008
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i,n) for(ll i=0; i<(n); ++i)
#define all(x) x.begin(),x.end()
typedef long long int ll;

int main(){
    ll n; cin >> n;
    ll vertex=0, side =0, ans=0;
    vector<ll> u(n-1),v(n-1); 
    rep(i,n-1){
        cin >> u[i] >> v[i];
        if (u[i]<v[i]) side+=u[i]*(n-v[i]+1);
        else side+= v[i]*(n-u[i]+1);
    } 
    rep(i,n) vertex+=(i+1)*(n-i);
    ans = vertex - side;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6392
import java.util.*;

public class Main {
    private static Scanner scanner;

    public static int[] inputIntArray(int n) {
        int[] res = new int[n];
        for (int i = 0; i < n; ++i) {
            res[i] = scanner.nextInt();
        }

        return res;
    }

    // public static String[] <T> ToStringArray(T[] arr) {
    // String[] res = new String[arr.length];
    // for(int i = 0; i < arr.length; ++i) {
    // res[i] = String.valueOf(arr[i]);
    // }

    // return res;
    // }

    private static List<Integer> asIntergerList(int[] arr) {
        List<Integer> intList = new ArrayList<Integer>();
        for (int i = 0; i < arr.length; i++) {
            intList.add(arr[i]);
        }

        return intList;
    }

    private static boolean func(int i, List<Integer> list, int left) {
        if (i == list.size()) {
            return left == 0;
        }

        return func(i + 1, list, left - list.get(i)) || func(i + 1, list, left);
    }

    public static void main(String[] args) {
        scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int[] A = inputIntArray(n);

        int q = scanner.nextInt();
        int[] m = inputIntArray(q);

        for (int i = 0; i < q; ++i) {
            int t = m[i];

            boolean flag = func(0, asIntergerList(A), t);

            System.out.println(flag ? "yes" : "no");
        }
    }
}



Measured memory_bytes: 27508
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
template<class T> using pq = priority_queue<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -MOD * MOD;
const long double pi = 3.141592653589793;
int main() { // 問題文はしっかり読め!!!
	int n;
	cin >> n;
	V a(n), b(n);
	rep(i, n) {
		cin >> a[i];
		b[i] = i - a[i];
		a[i] += i;
	}
	map<int, int> mp;
	ll ans = 0;
	rep(i, n) {
		ans += mp[b[i]];
		mp[a[i]]++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 21836
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

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, x, y;
  cin >> n >> x >> y;
  x--; y--;
  vector<int> a(n);
  REP(i, n-1) {
    FOR(j, i+1, n) {
      int d = min(j-i, 1+abs(i-x)+abs(y-j));
      a[d]++;
    }
  }
  FOR(i, 1, n) cout << a[i] << endl;

  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int main(void){
	int a[10000];
	int b[10000];
	int c[10000];
	int d[10000];
	int k;
	int n, m;
	int s, t;
	int x, y, z;


	scanf("%d %d", &n,&m);

	for (int i = 0; i < n; i++){
		scanf("%d %d", &a[i],&c[i]);
	}
	for (int i = 0; i < m; i++){
		scanf("%d %d", &b[i],&d[i]);
	}
	for (int i = 0; i < n; i++){
		y = 1500000000;
		z = 0;
		for (int j = 0; j < m; j++){
			s = a[i] - b[j];
			t = c[i] - d[j];
			if (s < 0)s = -s;
			if (t < 0)t = -t;
			if (s + t < y){
				y = s + t;
				z = j;
			}
		}
		printf("%d\n", z + 1);
	}



	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>

int main(int argc, char *argv[]){
	//std::ifstream datafile(argv[1]); //input datafile
	std::string str;
	int num1, num2; //a, b
	int sum; //a + b
	int digit = 0; //digit

	// if(datafile.fail()){
	// 	std::cout << "error : can't open this file." << std::endl;
	// 	exit(1);
	// }

	while(std::getline(std::cin, str)){
		sscanf(str.c_str(), "%d%d", &num1, &num2);

		if(num1 < 0 || num1 > 1000000 || num2 < 0 || num2 > 1000000){
			std::cout << "error : out of constraints" << std::endl;
			exit(1);
		}

		sum = num1 + num2;

		if(sum == 0){ //when sum is 0, its digit is 1
			std::cout << 1 << std::endl;
		}else{ //when sum is not 0
			while(sum != 0){
				digit++;
				sum = sum / 10;
			}
			std::cout << digit << std::endl;
			digit = 0;
		}
	}

	return 0;
}

Measured memory_bytes: 3228
#include <iostream>

using namespace std;
 
int main(){
  int N;
  char S[50];
  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;
  
}

Measured memory_bytes: 256
object Main {
    def main(args: Array[String]) = {
        val dates = List("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
        val days = List(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31).scanLeft(0)(_ + _)
        val in = io.Source.stdin.getLines.map(_.split(" ").map(_.toInt))
        in.takeWhile(!_.contains(0)).foreach(p => println(dates((days(p(0) - 1) + p(1) + 2) % 7)))
    }
}

Measured memory_bytes: 44220
#include<iostream>
using namespace std;
long long p=998244353,jc[200010],n,m,k,f[200010],ans;
long long ksm(long long a,long long b)
{
     long long x=1;
     for(;b;a=(a*a)%p,b/=2) if(b%2==1) x=(x*a)%p;
     return x;
}
long long c(long long x,long long y)
{
     long long z=jc[x];
     if(y<=0) return 1;
     z=(z*ksm(jc[y],p-2))%p;
     z=(z*ksm(jc[x-y],p-2))%p;
     return z;
}
int main()
{
    int i;
    cin>>n>>m>>k;
    jc[0]=1;
    for(i=1;i<=n;i++) jc[i]=(jc[i-1]*i)%p;
    f[1]=m;
    for(i=2;i<=n;i++) f[i]=(f[i-1]*(m-1))%p;
    for(i=0;i<=k;i++) ans=(ans+c(n-1,n-i-1)*f[n-i])%p;
    cout<<ans;
    cin>>i;
}
    


Measured memory_bytes: 6656
N=input()
N=int(N)

if N<105:
  print(0)
else:
   if  N<135:
     print(1)
   else:
      if N<165:
       print(2)
      else:
        if N<189:
         print(3)
        else:
          if N<195:
           print(4)
          else:
            print(5)

Measured memory_bytes: 2940
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


//改造
typedef long long int ll;
using namespace std;




//ここから編集する
ll gcd(ll a,ll b){
    if(a < b) swap(a,b);
    if(a % b == 0) return b;
    return gcd(b, a % b);

}

ll lcm(ll a,ll b){
    return a / gcd(a,b) * b;
}


int main() {
    int n;
    cin >> n;
    vector<ll> t(n);
    REP(i,0,n){
        cin >> t[i];
    }
    ll ans = 1;
    REP(i,0,n){
        ans = lcm(ans,t[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <vector>

using namespace std;

const int MAX_N = 2e5 + 5;

int color [MAX_N];
set<int> adj [MAX_N][2];

int in_to_del [MAX_N];
vector<int> to_del;

int check (int u) {
  return adj[u][0].empty() || adj[u][1].empty();
}

void del (int u) {
  vector<int> nbs;
  for (int v : adj[u][0]) nbs.push_back(v);
  for (int v : adj[u][1]) nbs.push_back(v);

  adj[u][0].clear();
  adj[u][1].clear();

  for (int v : nbs) {
    adj[v][color[u]].erase(u);
  }

  for (int v : nbs) {
    if (!in_to_del[v] && check(v)) {
      in_to_del[v] = 1;
      to_del.push_back(v);
    }
  }
}

int main () {
  int n, m;
  cin >> n >> m;

  string s;
  cin >> s;

  for (int i = 0; i < n; i++) {
    if (s[i] == 'A') {
      color[i + 1] = 0;
    } else {
      color[i + 1] = 1;
    }
  }

  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;

    adj[u][color[v]].insert(v);
    adj[v][color[u]].insert(u);
  }

  for (int i = 1; i <= n; i++) {
    if (check(i)) {
      in_to_del[i] = 1;
      to_del.push_back(i);
    }
  }

  int delc = 0;
  while (!to_del.empty()) {
    int u = to_del.back();
    to_del.pop_back();
    delc++;
    del(u);
  }

  if (delc == n) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 39044
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<iomanip>
using namespace std;

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

	int a, b;
	int d, r;
	double f;
	cin >> a >> b;
	d = a / b;
	r = a % b;
	f = static_cast<double>(a) / b;
	cout << fixed;
	cout << d << " " << r << " " << setprecision(6) << f << "\n";

	return 0;
}


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

int main(){
    int L,R,d;
    cin >> L >> R >> d;
    int cnt = 0;
    for(int i = L; i <= R; i++){
        if(i%d == 0) cnt++;
    }
    cout << cnt;
    return 0;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e5 + 5);

int n, m;
vector<vector<pair<int, ll>>> graph(MAX_N);

ll pos[MAX_N];
bool visited[MAX_N];

bool check(int node, ll suppose) {
  if (visited[node]) {
    return pos[node] == suppose;
  }

  pos[node] = suppose;
  visited[node] = true;

  for (auto &e : graph[node]) {
    if (!check(e.first, pos[node] + e.second)) {
      return false;
    }
  }

  return true;
}

int main(void) {
  // Here your code !
  scanf("%d %d", &n, &m);

  for (int i = 0; i < m; ++i) {
    int l, r;
    ll d;
    scanf("%d %d %lld", &l, &r, &d);
    graph[l].push_back(make_pair(r, d));
    graph[r].push_back(make_pair(l, -d));
  }

  for (int i = 1; i <= n; ++i) {
    visited[i] = false;
  }

  for (int i = 1; i <= n; ++i) {
    if (visited[i] || graph[i].empty()) continue;
    if (!check(i, 0LL)) {
      printf("No\n");
      return 0;
    }
  }

  printf("Yes\n");

  return 0;
}


Measured memory_bytes: 15616
#include <stdio.h>
 
int rot[5][7] = {
{0,1,2,3,4,5,6},{0,2,6,3,4,1,5},{0,4,2,1,6,5,3},{0,3,2,6,1,5,4},{0,5,1,3,4,6,2}};
int assign[7];      // サイコロの1～6の各面に割り当てる数字
int tr['Z'];
 
void dice_init(int *a)
{
    int i;
    int t[5] = {0,'N','E','W','S'};
    for (i = 1; i <= 6; i++) assign[i] = a[i];
    for (i = 1; i <= 4; i++) tr[t[i]] = i;
}
 
char s[102];
int main()
{
    int i, k1, k2;
    int a[7], dice[2][7];
    char *p;
 
    for (i = 1; i <= 6; i++) scanf("%d", a+i);
    dice_init(a);
    scanf("%s", p=s);
    for (i = 1; i <= 6; i++) dice[0][i] = rot[0][i];
    for (k1 = 0, k2 = 1; *p; k1 = k2, k2 = !k2) {
        for (i = 1; i <= 6; i++) dice[k2][i] = dice[k1][rot[tr[*p]][i]];
        p++;
    }
    printf("%d\n", assign[dice[k1][1]]);
    return 0;
}


Measured memory_bytes: 2144
void main() {
	auto N = ri;
	dchar[][] arr;
	foreach(i; 0..N) arr ~= rs.to!(dchar[]);
	arr.sort.uniq.array.length.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 28420
#include <bits/stdc++.h>
     
    using namespace std;
     
    #define MOD 1000000007
    #define PI 3.1415926535897932384626433832795
    #define INF (int)1e9
    typedef long long int int64;
     
    void print() {
        cout << endl;
    }
     
    void print(string s, bool endline = true) {
        cout << s;
        if (endline) print();
    }
     
    void print(int64 s, bool endline = true) {
        cout << s;
        if (endline) print();
    }
     
    template <typename T, typename T2>
    void print(pair<T, T2>& p, bool endline = true) {
        print("(", false);
        print(p.first, false);
        print(", ", false);
        print(p.second, false);
        print(")", false);
     
        if (endline) print();
    }
     
    template <typename T, typename T2>
    void print(map<T, T2>& m, bool endline = true) {
        print("{");
        for (auto& p : m) {
            print("  ", false);
            print(p);
        }
        print("}");
     
        if (endline) {}
    }
     
    template<typename T>
    void print(vector<T>& v, bool endline = true) {
        print("[", false);
        for (size_t i = 0; i < v.size(); ++i) {
            print(v[i], false);
            if(i != v.size() - 1) print(",", false);
        }
        print("]", false);
     
        if(endline) print();
    }
     
    template <typename T>
    vector<T> operator+(const vector<T> &a, const vector<T> &b)
    {
        vector<T> ret;
        ret.reserve( a.size() + b.size() );                // preallocate memory
        ret.insert( ret.end(), a.begin(), a.end() );        // add A;
        ret.insert( ret.end(), b.begin(), b.end() );        // add B;
     
        return ret;
    }
     
    template <typename T>
    vector<T> &operator+=(vector<T> &a, const vector<T> &b)
    {
        a.reserve( a.size() + b.size() );                // preallocate memory without erase original data
        a.insert( a.end(), b.begin(), b.end() );         // add B;
        return a;
    }

    int main() {
        // g++ -Wall -Wextra -O2 -std=c++17 helloworld.cpp
        string s;
        cin >> s;

        int count = 0;

        for(size_t i = 0; i < s.size() / 2; ++i) {
            if(s[i] != s[s.size() - i - 1]) {
                count++;
            }
        }

        print(count);

        return 0;
    }

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef unsigned long long ll;


int main(){
	int N; cin >> N;
	string S; cin >> S;
	set<char> C;
	set<char> A;
	int count = 0;
	int ans = 0;
	for(int i = 0; i < N; i++){
		C.insert(S[i]);
		for(int j = i+1; j < N; j++){
			if(C.count(S[j])){
				if (! A.count(S[j])){
				count++;
				A.insert(S[j]);
				}
			}
		}
		ans = max(ans,count);
		count = 0;
		A.clear();
	}
		cout << ans << endl;
	}

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

queue< pair<string, int> > que;

void solve(int q){
  int timer = 0;
  while (!que.empty()){
    //pair<string, int>* tp;
    //tp =  &que.front();
    //int* tmp = &tp->second;

    if(que.front().second > 0){
      if(que.front().second <= q){
        timer += que.front().second;
        cout << que.front().first << " " << timer << endl;;
      }else{
        timer += q;
        que.front().second -= q;
        que.push(que.front());
      }
      que.pop();
    }
  }
  return ;
}

int main(){
  int n, q;
  cin >> n >> q;
  for(int i = 0; i < n; i++){
    string name;
    int tmp;
    cin >> name >> tmp;
    que.push(make_pair(name, tmp));
  }
  solve(q);
  return 0;
}

Measured memory_bytes: 6324
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <string.h>
#define rep(i, N) for (int i = 0;i < N;++i)

using namespace std;
using LL = long long;

struct point{
	int to, cost;
};

vector<point> a[100001];


int N, M;
int dis[100001];
bool check[100001];

bool solve(int start) {
	memset(dis, -1, sizeof(int) * 100001);
	queue<int> que;
	dis[start] = 0;
	que.push(start);
	while (!que.empty()) {
		int now = que.front(); que.pop();
		check[now] = true;
		for(point elm: a[now]) {
			if (dis[elm.to] == -1) {
				dis[elm.to] = elm.cost + dis[now];
				if (!check[elm.to]) {
					que.push(elm.to);
				}
			}
			else {
				if (dis[elm.to] != elm.cost + dis[now]) {
					return false;
				}
			}
		}
	}
	return true;
}


int main(void)
{
	memset(check, true, sizeof(bool) * 100001);
	bool ans = true;
	scanf("%d %d", &N, &M);
	rep(i, M) {
		int r, l, d;
		scanf("%d %d %d", &r, &l, &d);
		point s = { l, d };
		a[r].push_back(s);
		s = { r, -1 * d };
		a[l].push_back(s);
		check[r] = false;
	}
	for (int i = 1; i < N + 1;i++) {
		if (!check[i]) {
			if (solve(i)) {
				continue;
			}
			else {
				ans = false;
				break;
			}
		}
	}
	if (ans) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 9344
#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() {
  ll k, a, b;
  cin >> k >> a >> b;

  if(b-a<=2||k<a+1) cout << k+1 << endl;
  else cout << a+(k-a+1)/2*(b-a)+(k-a+1)%2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<ll> R(N);
  rep(i, N)
  {
    cin >> R[i];
  }
  ll maxv = -1 * 1e10;
  ll minv = 1e10;
  rep(i, N)
  {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }
  cout << maxv << endl;
  return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

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

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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 (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_N 100'000
i64 N, M;
i64 A[MAX_N + 1];  // 1-indexed

void solve() {
    vector<i64> C(N + 1, 0);
    REPS(i, N) {
        C[i] = (C[i - 1] + A[i]) % M;
    }

    i64 cnt = 0;
    map<i64, i64> dist;
    REP(r, N + 1) {
        cnt += dist[C[r]];
        dist[C[r]]++;
    }

    cout << cnt << endl;
}

int main() {
    cin >> N >> M;
    REP(i, N) cin >> A[i + 1];
    A[0] = 0;

    solve();

    return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(x=from;x<to;x++)

using namespace std;

double smen(double x1, double y1, double x2, double y2, double x3, double y3){
	return abs((x3-x2) * (y1-y2) - (x1-x2)*(y3-y2) )* 0.5;
	
}

int main(void){

double x1,y1,x2,y2,x3,y3,xp,yp;

	while(cin >> x1 ){
		cin >> y1 >> x2 >> y2 >> x3 >> y3;
		cin >> xp >> yp;
			
		double saa = smen(x1,y1,x2,y2,x3,y3);
		double sa1 = smen(x1,y1,x2,y2,xp,yp);
		double sa2 = smen(x1,y1,xp,yp,x3,y3);
		double sa3 = smen(xp,yp,x2,y2,x3,y3);
		
		if(saa == sa1 + sa2 + sa3) cout << "YES" <<endl;
		else  cout << "NO" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1216
#include <stdio.h>
#include <string.h>

int main() {
	int tall;
	int top[3];

	for(int i=0;i<3;i++){
		top[i] = 0;
	}

	for(int i=0;i<10;i++){
		scanf("%d",&tall);
		if(tall >= top[0]){
			top[2] = top[1];
			top[1] = top[0];
			top[0] = tall;
		}else if(tall >= top[1]){
			top[2] = top[1];
			top[1] = tall;
		}else if(tall >= top[2]){
			top[2] = tall;
		}
	}

	for(int i=0;i<3;i++)
		printf("%d\n",top[i]);
	
	return 0;
}


Measured memory_bytes: 2752
#include <cstdio>
#include <algorithm>
using namespace std;

int main(void){
    int a, b, c, k;

    scanf("%d%d%d%d", &a, &b, &c, &k);
    if (a<b) swap(a, b);
    if (a<c) swap(a, c);
    printf("%d\n", b+c+(a<<k));

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
ll K,X;
  cin>>K>>X;
  if(500*K>=X) {
cout<<"Yes"<<endl;
  }
  else {
cout<<"No"<<endl;
  }
}


Measured memory_bytes: 3632
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	var sum int64
	for i := 1; i <= n; i++ {
		if i%3 > 0 && i%5 > 0 {
			sum += int64(i)
		}
	}
	fmt.Printf("%d\n", sum)
}


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

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (LLONG_MAX - 1e5)
#define fcout cout << fixed << setprecision(10)

using namespace std;

int H, W;
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> H >> W;
    map<char, int> map;
    REP(i, H) REP(j, W) {
        char c;
        cin >> c;
        map[c]++;
    }

    bool ok = true;
    if (W & 1 && H & 1) {
        int oddnum = 0;
        for (auto& kv : map) {
            if (kv.second % 4 == 1) {
                kv.second--;
                oddnum++;
            }
        }
        if (oddnum > 1) ok = false;

        int twonum = 0;
        for (auto& kv : map) {
            if (kv.second % 4 == 2) {
                twonum++;
                kv.second -= 2;
            }
        }
        if (twonum > H / 2 + W / 2) ok = false;

        for (auto kv : map) {
            if (kv.second % 4 != 0) ok = false;
        }
    } else if ((W & 1) == 0 && (H & 1) == 0) {
        for (auto kv : map) {
            if (kv.second % 4 != 0) ok = false;
        }
    } else {
        int twonum = 0;
        for (auto& kv : map) {
            if (kv.second % 4 == 2) {
                twonum++;
                kv.second -= 2;
            }
        }
        int t = H & 1 ? W : H;
        if (twonum > t / 2) ok = false;

        for (auto kv : map) {
            if (kv.second % 4 != 0) {
                ok = false;
            }
        }
    }

    ok ? cout << "Yes" << endl : cout << "No" << endl;
    return 0;
}


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

string s;
int dp[2][1000003];
int main() {
  cin >> s;
  reverse(s.begin(), s.end());
  s += '0';
  
  for (int i = 0; i <= s.size(); ++i) {
    for (int k : { 0, 1 }) {
      dp[k][i] = 1e9;
    }
  }
  dp[0][0] = 0;
  dp[1][0] = 0;
  for (int i = 1; i <= s.size(); ++i) {
    int c = s[i - 1] - '0';
    for (int k : { 0, 1 }) {
      int d = k ? c : 9 - c;
      if (i == 1) d = k ? c : 10 - c;
      dp[k][i] = min(dp[k][i - 1] + d, dp[!k][i - 1] + d + 1);
    }
  }
  cout << min(dp[0][s.size()], dp[1][s.size()]) << endl;
}

Measured memory_bytes: 9220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
const int MOD = 1e9 + 7;
const int INF = 2e9;
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 GCD(int x, int y) { return y ? GCD(y, x % y) : x; }
int LCM(int x, int y) { return x * y / GCD(x, y); }

int main(){
    vvi c(3);
    for(int i=0; i<3; i++){
        c[i].resize(3);
        for (int j = 0; j<3; j++){
            cin >> c[i][j];
        }
    }
    for (int i = -100; i<=100; i++){
        for (int j = -100; j <= 100; j++){
            for (int k = -100; k<=100; k++){
                if(c[0][0]-i == c[0][1]-j && c[0][1]-j == c[0][2]-k){
                    if (c[1][0] - i == c[1][1] - j && c[1][1] - j == c[1][2] - k)
                    {
                        if (c[2][0] - i == c[2][1] - j && c[2][1] - j == c[2][2] - k)
                        {
                            cout << "Yes" << endl;
                            return 0;
                        }
                    }
                }
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

struct UnionFind {
	std::vector<int> data;
	
	UnionFind(int n) {
		data.assign(n, -1);
	}
	bool unite(int x, int y) {
		x = find(x); y = find(y);
		if(x == y) return false;
		if(data[x] > data[y]) std::swap(x, y);
		data[x] += data[y];
		data[y] = x;
		return true;
	}
	int find(int k) {
		if(data[k] < 0) return k;
		return find(data[k]);
	}
	int size(int k) {
		return -data[find(k)];
	}
	int size(int x, int y) {
		x = find(x); y = find(y);
		if(x == y) return size(x);
		return size(x) + size(y);
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

int main() {
	int n, m, k; scanf("%d%d%d", &n, &m, &k);
	std::vector<int> c(n);
	for(int i = 0; i < n; i++) scanf("%d", &c[i]);
	std::vector<std::pair<i64, std::pair<int, int>>> vec;
	std::vector<std::vector<std::pair<int, int>>> g(n);
	for(int i = 0; i < m; i++) {
		int a, b, w; scanf("%d%d%d", &a, &b, &w);
		
		g[a - 1].push_back({b - 1, w});
		g[b - 1].push_back({a - 1, w});
		vec.push_back({w, {a - 1, b - 1}});
	}
	sort(begin(vec), end(vec));
	
	int K = 1, free = 0;
	std::vector<bool> used(n, false);
	for(int i = 0; i < n; i++) {
		if(used[i]) continue;
		
		int count = 0;
		std::set<int> st;
		std::function<void (int)> dfs = [&](int v) {
			if(used[v]) return; used[v] = true;
	
			if(c[v] == 0) count++;
			else st.insert(c[v]);
			for(auto e: g[v]) {
				dfs(e.first);
			}
		};
		dfs(i);
		K += st.size() + count - 1;
		free += count;
	}
	if(K < k) {
		printf("-1\n");
		return 0;
	}
	
	i64 ans = 0, tmp = 0, count = 0;
	std::set<std::pair<int, int>> st;
	UnionFind uf(n + k + 2);
	used.assign(n + 1, false);
	for(auto v: vec) {
		int x = v.second.first, y = v.second.second;
		if(x == y) continue;
		int nx = c[x], ny = c[y];
		if(c[x] == 0) nx = x + k + 1;
		if(c[y] == 0) ny = y + k + 1;
		
		if(uf.unite(nx, ny)) {
			ans += v.first;
			count++;
		}
		if(count == k - 1) break;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 13040
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;
    if(a==b){
        cout << "Draw" << endl;
    }else if(a<b){
        if(a==1){
            cout << "Alice" << endl;
        }else{
            cout << "Bob" << endl;
        }
    }else{
        if(b==1){
            cout << "Bob" << endl;
        }else{
            cout << "Alice" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static int N;
    static int M;

    class Comare : IComparer<int>
    {
        public int Compare(int x, int y)
        {
            return x - y;
        }
    }

    class CityInfo
    {
        public CityInfo(int k, int y, int c)
        {
            Ken = k;
            Year = y;
            CityNo = c;
        }

        public int Ken;
        public int Year;
        public int CityNo;
    }

    public static void Main(string[] args)
    {
        N = Input.NextInt();
        M = Input.NextInt();

        var Cities = new List<CityInfo>();
        var Kens = new Dictionary<int, List<CityInfo>>();
        for (int i = 0; i < M; i++)
        {
            var l = Input.LineInt();
            var ken_no = l[0];
            var city_born = l[1];

            if (!Kens.ContainsKey(ken_no))
                Kens[ken_no] = new List<CityInfo>();
            var city = new CityInfo(ken_no, city_born, 0);
            Cities.Add(city);
            Kens[ken_no].Add(city);
        }
        foreach (var en in Kens)
        {
            en.Value.Sort((a, b) => (a.Year - b.Year));
            for (int i = 0; i < en.Value.Count; i++)
            {
                en.Value[i].CityNo = i + 1;
            }
        }

        foreach (var city in Cities)
        {
            Console.WriteLine($"{Make6(city.Ken)}{Make6(city.CityNo)}");
        }
    }

    static string Make6(int x)
    {
        string s;
        s = "000000" + x.ToString();
        return s.Substring(s.Length - 6);
    }
}

public static class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

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

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

const int N = (int) 2e5 + 7;
int n, f[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n - 1; i++) {
    int x;
    cin >> x;
    f[x]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << f[i] << "\n";
  }
  return 0;
}


Measured memory_bytes: 4364
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long long int s;
  cin>>s;
  map<long long int,long long int> hoge;
  hoge[s]++;
  long long int count=2;
  while(true){
    if(s%2==0){
      s/=2;
    }else{
      s=s*3+1;
    }
    if(hoge.count(s)){
      break;
    }else{
      count++;
      hoge[s]++;
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n;
  cin>>n;
  ll a,t;
  cin>>a>>t;
  ll aa,tt;
  for(int i=1;i<n;i++){
    cin>>aa>>tt;
    if(a/aa>t/tt){
      if(a%aa==0){
        t=(a/aa)*tt;
        a=(a/aa)*aa;
      }else{
        t=(a/aa+1)*tt;
        a=(a/aa+1)*aa;
      }
    }else if(a/aa<t/tt){
      if(t%tt==0){
        a=(t/tt)*aa;
        t=(t/tt)*tt;
      }else{
        a=(t/tt+1)*aa;
        t=(t/tt+1)*tt;
      }
    }else{
      if(a%aa==0&&t%tt==0){
        t=(a/aa)*tt;
        a=(a/aa)*aa;
      }else{
        t=(a/aa+1)*tt;
        a=(a/aa+1)*aa;
      }
    }
  }
  cout<<t+a;
}

Measured memory_bytes: 256
n = int(input())
lst = [list(map(int, input().split())) for _ in range(n)]
 
current = []
for i in range(n):
    current.append(lst[i].pop(0))

count = 0
players = set(range(1, n+1))
while True:
    index_lst = []
    for i in players:
        candidate = current[i-1]
        if candidate in index_lst:
            continue
        if current[candidate-1] == i:
            index_lst += [i, candidate]   
    if len(index_lst) == 0:
        if sum(current) == 0:
            print(count)
            break
        else:
            print(-1)
            break
    for i in index_lst:
        if len(lst[i-1]) == 0:
            current[i-1] = 0
        else:
            current[i-1] = lst[i-1].pop(0)
    players = set(index_lst)
    count += 1

Measured memory_bytes: 63324
#include<iostream>
using namespace std;
int main() {
  int N;
  cin >> N;
  int a,now = 0;
  long long ans = 0;
  int i;
  for(i=0;i<N;i++) {
    cin >> a;
    if(now>a)ans += now-a;
    else now = a;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include <stdio.h>

main()
{

  int i, j, n, k, flag, count=0;
  int A[100];

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

  flag=1;
  while(flag){
	flag=0;
	for(j=n-1; j>=1; j--){
	  if(A[j]<A[j-1]){
		k = A[j];
		A[j] = A[j-1];
		A[j-1] = k;
		flag=1;
		count++;
	  }
	}
  }
  
  
  for(i=0; i<n; i++){
	printf("%d", A[i]);
	if(i== n-1) printf("\n");
	else printf(" ");
  }
  printf("%d\n", count);

  return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
#define MAX     	500005
using namespace std;
int t , tst , n , m;
int tree[4*MAX] , ara[MAX] , now[MAX], val[MAX] , ans[MAX];
vector<int>edg[MAX];

struct info {
    int uu , vv , id;
};

vector<info>range;

bool comp(info in1 , info in2) {
    if( in1.uu == in2.uu) {
        if( in1.vv == in2.vv) {
            return in1.id < in2.id;
        }
        return in1.vv < in2.vv;
    }
    return in1.uu< in2.uu;
}

void build(int node ,int l , int r) {
    if(l == r) {
        tree[node] = val[l];
        return;
    }
    int mid = (l+r)>>1;
    build(node<<1 , l , mid);
    build(node<<1|1 , mid+1 , r);
    tree[node] = tree[node<<1] + tree[node<<1|1];
}

void update(int node, int l ,int r , int key, int val) {
    if( l > r || l > key || r < key ) return;
    if( l == r) {
        tree[node] = val;
        return;
    }
    int mid = (l+r)>>1;
    update(node<<1 , l , mid , key , val);
    update(node<<1|1 , mid+1 , r , key , val);
    tree[node] = tree[node<<1] + tree[node<<1|1];
}

int query(int node ,int l ,int r , int frm , int to ) {
    if( l > r || l > to || r < frm ) return 0;
    if(  l>= frm && r <=to ) {
        return tree[node];
    }
    int mid = (l+r)>>1;
    int q1 = query(node<<1 , l , mid , frm , to);
    int q2 = query(node<<1|1 , mid+1 , r , frm , to);
    return q1+ q2;
}


int main()
{
    scanf("%d %d",&n,&m);
    for(int i = 0 ; i < n ; i++ ) {
        scanf("%d",&ara[i]);
        edg[ara[i]].push_back(i);
    }
    for(int i =0 ; i < m ; i++ ) {
        int frm , to;
        scanf("%d %d",&frm , &to);
        frm-- ;
        to--;
        info tmp;
        tmp.uu = frm;
        tmp.vv = to;
        tmp.id = i;
        range.push_back(tmp);
    }
    sort( range.begin() , range.end() ,comp);

    for(int i =0 ; i < n ; i++) {
        if( edg[ ara[i] ] [ now[ara[i]] ] == i ) {
            val[i] = 1;
        }
    }
    build( 1 ,0 , n-1);
    int prev= 0;

    for(int i =0 ; i < range.size() ; i++ ) {

        int frm = range[i].uu;
        int to = range[i].vv;

        for(int j = prev ; j < frm ; j++) {

            if(val[j] == 1) {
                update(1 ,0 , n-1 , j, 0);
                val[j] = 0;
                now[ara[j]]++;
                if( now[ara[j]] < edg[ara[j]].size() ) {
                    int id = edg[ ara[j] ][ now[ara[j]] ];
                    val[ id ] =1;
                    update( 1 , 0 , n-1 , id , 1);
                }
            }
        }
        prev = frm;
        ans[range[i].id] = query(1 , 0 , n-1 , frm , to);
    }
    for(int i =0 ; i < m ; i++ ) {
        printf("%d\n",ans[i]);
    }
    return 0;
}


Measured memory_bytes: 49004
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;

typedef pair <long long, long long> pii;
typedef pair <pii, long long> piii;

const int mod = 1000000007;

int a[110], vis[110][110];
vector <int> all;

long long power(int a, int b){
	if (b <= 0) return 1;
	long long tmp = power(a, b >> 1);
	return b & 1 ? tmp * tmp % mod * a % mod : tmp * tmp % mod;
}

void add(long long &a, long long b){
	a = (a + b % mod + mod) % mod;
}

piii dfs(int l, int r, int now){
	int last = l;
	int left = r - l + 1;
	piii ans = mp(mp(1ll, 1ll), 1ll);
	vector <int> dp(r - l + 2, 0);
	dp[0] = 1;
	for (int i = l; i <= r + 1; i++){
		if (i > r || vis[now + 1][i]){
			if (last > i - 1){
				last = i + 1;
				continue;
			}
			piii tmp = dfs(last, i - 1, now + 1);
			ans.fi.fi = ans.fi.fi * (tmp.fi.fi + tmp.fi.se) % mod;
			ans.fi.se = ans.fi.se * (tmp.fi.se + tmp.fi.fi) % mod;
			ans.se = ans.se * ((tmp.fi.fi + tmp.fi.se) * 2 + tmp.se) % mod;
			left -= i - last;
			last = i + 1;
		}
	}
	ans.se = ans.se * power(2, left) % mod, add(ans.se, -ans.fi.fi - ans.fi.se);
	int cnt = all[now] - (now ? all[now - 1] : 0);
	if (cnt > 1){
		long long xx = ans.fi.fi, yy = ans.fi.se;
		ans.fi.fi = (xx * power(2, cnt - 2) + yy * power(2, cnt - 2)) % mod;
		ans.fi.se = (xx * power(2, cnt - 2) + yy * power(2, cnt - 2)) % mod;
	}
	return ans;
}

int main(){
	int n; scanf("%d", &n);
	for (int i = 0; i < n; i++){
		scanf("%d", &a[i]);
		all.push_back(a[i]);
	}
	sort(all.begin(), all.end());
	all.resize(unique(all.begin(), all.end()) - all.begin());
	for (int i = 0; i < all.size(); i++){ 
		for (int j = 0; j < n; j++){
			vis[i + 1][j] = (a[j] == all[i]);
		}
	}
	piii ans = dfs(0, n - 1, 0);
	printf("%lld\n", (ans.fi.fi + ans.fi.se + ans.se) % mod);
	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;


public class Main {
	public static void main(String [] args){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		//??°?????????
		while(true){
			//x???????????????
			int x = sc.nextInt();
			//y???????????????
			int y = sc.nextInt();
			//?????¶??? ??????x??¨y???0?????¨?????????
			if(x ==0 && y ==0){
				break;
			}
			//?????¶??? X???Y???????°???????????????¨???
			if(x < y){
				System.out.println(x + " " + y);
			//
			}else{
				System.out.println(y + " " + x);
			}
		}
	}
}

Measured memory_bytes: 35684