akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;

namespace program
{
    class Program
    {
        static void Main()
        {
          int n = Input.ScanInt();
          int m = Input.ScanInt();
          
          Console.WriteLine(n+(m-n)*2);
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


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

int main(){
    while(1){
        int H,W;
        cin >> H >> W;
        if(H == 0 && W == 0) break;
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                if((i + j) % 2 == 0){
                    cout << "#";
                }else{
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <bitset>

using namespace std;
using ll = long long;
using ld = long double;
const ll mod =  1000000007;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll power(ll base, ll exponent, ll module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ ll root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2, mod);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

int bsearch(const vector<ll>& a, ll x){
  int lft = 0;
  int rgt = a.size();
  while (rgt - lft > 1) {
    int mid = (lft + rgt) / 2;
    if(a[mid] < x) {
      lft = mid;
    }
    else {
      rgt = mid;
    }
  }
  return lft;
}

signed main() {
  ios::sync_with_stdio(false);
  ll n, m, R;
  cin >> n >> m >> R;
  vector<ll> r(R);
  REP(i, R) cin >> r[i];
  REP(i, R) r[i]--;
  vector<vector<ll>> g = vector<vector<ll>>(n, vector<ll>(n));
  REP(i, n) {
    REP(j, n) {
      g[i][j] = 1e9;
    }
  }
  REP(i, m) {
    ll x, y, z;
    cin >> x >> y >> z;
    x--;
    y--;
    g[x][y] = z;
    g[y][x] = z;
  }
  // REP(i, n) {
  //   REP(j, n) {
  //     cout << g[i][j] << " ";
  //   }
  //   cout << endl;
  // }
  REP(k, n) {
    REP(i, n) {
      REP(j, n) {
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
  // REP(i, n) {
  //   REP(j, n) {
  //     cout << g[i][j] << " ";
  //   }
  //   cout << endl;
  // }
  sort(all(r));
  ll ans = 1<<29;
  do {
    // REP(i, R) cout << r[i] << " ";
    // cout << endl;
    ll tmp = 0;
    REP(i, R-1) {
      tmp += g[r[i]][r[i+1]];
    }
    // cout << tmp << endl;
    ans = min(ans, tmp);
  } while(next_permutation(all(r)));
  cout << ans << endl;
  return 0;
}


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

int main(){
    int x=0,n=0,kaisuu=0;
    cin >> x >> n;
    map<int,int> Map;
    for(int i=0;i<n;i++){
        int a=0;
        cin >> a;
        Map[a]++;
    }
    int ans=x;
    bool jud=false;
    while(1){
        if(!Map[ans-kaisuu]){
            cout << ans-kaisuu << endl;
            jud=true;
        }
        else if(!Map[ans+kaisuu]){
            cout << ans+kaisuu << endl;
            jud=true;
        }
        if(jud)break;
        kaisuu++;
    }
    return 0;
}

Measured memory_bytes: 3632
s = input()
q = int(input())

flg = True

mae = ''
ato = ''

for i in range(q):
    query = input()
    if query[0] == '1':
        flg = not flg
    else:
        if query[2] == '1':
            if flg:
                mae += query[4]
            else:
                ato += query[4]
        else:
            if flg:
                ato += query[4]
            else:
                mae += query[4]

mae = mae[::-1]
ans = mae + s + ato
if not flg:
    ans = ans[::-1]

print(ans)

Measured memory_bytes: 4388
def solve():
    base = []
    for a, s in zip(A[::-1], S[::-1]):
        x = a
        for y in base:
            x = min(x, x ^ y)
        if s == "0":
            if x:
                base.append(x)
        else:
            if x:
                return 1
    return 0


t = int(input())
for i in range(t):
    n = int(input())
    *A, = map(int, input().split())
    S = input()
    print(solve())


Measured memory_bytes: 9068
# S = input()
N = int(input())
A = input()
B = input()
C = input()

# a = list(map(int, input().split()))
# X = [int(input()) for _ in range(N)]

ans = 0


for i in range(N):
    if(A[i] == B[i] and A[i] == C[i]):
        ans += 0
    elif(A[i] == B[i] or A[i] == C[i] or B[i] == C[i]):
        ans += 1
    else:
        ans += 2

print(ans)


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

d={}
for i in range(N):
  d[i]=A[i]
  
#print(A)  
#print(d)
#print(sorted(d.items(), key=lambda x:x[0]))
#print(sorted(d.items(), key=lambda x:x[1]))
ans=sorted(d.items(), key=lambda x:x[1])
for i in range(N):
  print(ans[i][0]+1,end=' ')

Measured memory_bytes: 26296
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define bgn begin()
#define sz size()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int,vector<int>,greater<int>>
#define PriP priority_queue<P<int,int>,vector<P<int,int>>,greater<P<int,int>>>
#define all(a)  (a).begin(),(a).end()
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second

signed main(){
  int n, k;
  cin >> n >> k;

  V<int> a(n);
  fo(i, n){
    cin >> a[i];
  }
  V<int> b(n+5 , -1);
  V<int> c;
  int d = 1, e = 0;
  int now = 1;
  while(b[now] == -1){
    b[now] = c.sz;
    c.pb(now);
    now = a[now - 1];
  }
  d = c.sz - b[now];
  e = b[now];
  if(k < e)
    cout << c[k] << endl;
  else{
    k -= e;
    k %= d;
    cout << c[e + k] << endl;
  }
}


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

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

  int c[10][10];
  for ( int i = 0; i < 10; i++ ) {
    for ( int j = 0; j < 10; j++ ) {
      c[i][j] = 0;
    }
  }
  for ( int i = 1; i <= n; i++ ) {
    int hd = to_string(i)[0] - '0';
    int tl = i%10;
    c[hd][tl]++;
  }

  int ans = 0;
  for ( int i = 0; i < 10; i++ ) {
    for ( int j = 0; j < 10; j++ ) {
      ans += c[i][j]*c[j][i];
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
    vector<int> a(4);
    vector<int> b(2);
    for (int i = 0; i<4; i++) {
        cin >> a[i];
    }
    for (int i = 0; i<2; i++) {
        cin >> b[i];
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    cout << a[3] + a[1] + a[2] +b[1] << endl;
    
    return 0;
}



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

#ifdef MYDEBUG
#define dbp(x) cout<<#x<<": "<<x<<endl
#define dbp2(x,y) cout<<#x<<","<<#y<<": "<<x<<","<<y<<endl
#define dbp3(x,y,z) cout<<#x<<","<<#y<<","<<#z<<": "<<x<<","<<y<<","<<z<<endl
#else
#define dbp(x)
#define dbp2(x,y)
#define dbp3(x,y,z)
#endif
#define ll long long
#define ull unsigned long long
#define eps 1e-14
#define all(x) x.begin(), x.end()
#define rep(i, from, to) for(int i=from; i<to; ++i)

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  out << "[";
  size_t last = v.size() - 1;
  for (size_t i = 0; i < v.size(); ++i) {
    out << v[i];
    if (i != last)
      out << ",";
  }
  out << "]";
  return out;
}

const int maxn = 2010;
const int maxm = maxn;
int n, m, q;
int s[maxn][maxm];
int v[maxn][maxm]; //vertex
int ei[maxn][maxm]; //edge(vertical)
int ej[maxn][maxm]; //edge(horizontal)

int edge_in_area(int x1, int y1, int x2, int y2) {
  int ret = ei[x2][y2] + ej[x2][y2];
  ret = ret - ej[x2][y1] - ej[x1 - 1][y2] + ej[x1 - 1][y1];
  ret = ret - ei[x1][y2] - ei[x2][y1 - 1] + ei[x1][y1 - 1];
  return ret;
}

void solve() {
  cin >> n >> m >> q;
  for (int i = 1; i <= n; ++i) {
    string str;
    cin >> str;
    for (int j = 1; j <= m; ++j) {
      s[i][j] = str[j - 1] - '0';
    }
  }

  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      v[i][j] = v[i - 1][j] + v[i][j - 1] - v[i - 1][j - 1] + s[i][j];
      ei[i][j] = ei[i - 1][j] + ei[i][j - 1] - ei[i - 1][j - 1];
      ej[i][j] = ej[i - 1][j] + ej[i][j - 1] - ej[i - 1][j - 1];
      ei[i][j] += (s[i - 1][j] == 1 && s[i][j] == 1 ? 1 : 0);
      ej[i][j] += (s[i][j - 1] == 1 && s[i][j] == 1 ? 1 : 0);
    }
  }

  rep(query_index, 0, q)
  {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int edges = edge_in_area(x1, y1, x2, y2);
    int vertices = v[x2][y2] - v[x1 - 1][y2] - v[x2][y1 - 1] + v[x1 - 1][y1 - 1];
    cout << vertices - edges << endl;
  }

}

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


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

#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define rng(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rbf(i, v) for (auto& (i) : (v))
#define All(x) (x).begin(),(x).end()
#define cAll(x) (x).cbegin(),(x).cend()
#define COL(x) cout << x << endl
#define CO(x) cout << x
//#define int long long

template<typename T> inline constexpr auto square(T x) { return (x) * (x); }

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

const int MOD = 1000000007;
const int INF = INT_MAX;

signed main()
{
	int N, Q;
	cin >> N >> Q;

	VI oya(N);
	int a, b;
	rep(i, N - 1) {
		cin >> a >> b;
		oya[b - 1] = a - 1;
	}

	VI c(N, 0);
	int p, x;
	rep(i, Q) {
		cin >> p >> x;
		c[p - 1] += x;
	}

	rng(i, 1, N) {
		c[i] += c[oya[i]];
	}

	rbf(ans, c) {
		CO(ans);
		CO(' ');
	}

	CO(endl);

	return 0;
}

Measured memory_bytes: 3968
#include <stdio.h>

int main(void){

	int a, b;
	double menseki;
	
	scanf("%d %d", &a, &b);
	
	menseki = (double)a * b;
	
	menseki = menseki / 3.305785;
	
	printf("%f\n", menseki);
	
	return 0;
}

Measured memory_bytes: 632
N,K = map(int,input().split())
X = list(map(int,input().split()))
tmin = 10**13
for i in range(N-K+1):
    x = X[i]
    y = X[i+K-1]
    if y<0:
        T = -x
    elif x>0:
        T = y
    elif x<=0 and y>=0:
        T = min(2*(-x)+y,-x+2*y)
    tmin = min(tmin,T)
print(tmin)

Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(ll a,ll b){
  ll ans;
  while(b>0){
    ll r=a%b;
    a=b;
    b=r;
  }
  return a;
}
int main(){
  ll n,x;
  cin >> n >> x;
  vector<ll> a(n);
  rep(i,n){
    cin >> a.at(i);
  }
  vector<ll> p(n);
  rep(i,n){
    p.at(i)=abs(a.at(i)-x);
  }
  ll maxi=p.at(0);
  rep(i,n-1){
    maxi=gcd(maxi,p.at(i+1));
  }
  cout << maxi;
  
}

Measured memory_bytes: 4740
#include <iostream>
#include <stack>
using namespace std;
int main()
{
	string s;
	cin >> s;
	stack<char> st;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'T' && !st.empty() && st.top() == 'S')
			st.pop();
		else
			st.push(s[i]);
	}
	cout << st.size();
	return 0;
}

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

using namespace std;

int main()
{	
	char c;
	cin >> c;
	switch(c)
	{
		case 'A':
		cout << "T";
		break;

		case 'T':
		cout << "A";
		break;

		case 'G':
		cout << "C";
		break;
		
		case 'C':
		cout << "G";
		break;
	}
    return 0;
}

Measured memory_bytes: 256
import numpy as np

N = int(input())
lis = [int(i) for i in input().split()]
height = np.array([int(i) for i in input().split()])

temperature = [abs(lis[1] - (lis[0] - 0.006*i)) for i in height]

print(temperature.index(min(temperature)) + 1)

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

int main(){
  int n;
  cin>>n;
  if(n>=64)cout<<64<<endl;
  else if(n>=32)cout<<32<<endl;
  else if(n>=16)cout<<16<<endl;
  else if(n>=8)cout<<8<<endl;
  else if(n>=4)cout<<4<<endl;
  else if(n>=2)cout<<2<<endl;
  else cout<<1<<endl;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%s %s %s", $w, $a, $b);

if($a>$b){
    $tmp = $a;
    $a = $b;
    $b = $tmp;
}

if($a + $w >= $b){
    $res = 0;
}elseif($a + $w < $b){
    $res = $b - ($a + $w);
}

echo $res
?>

Measured memory_bytes: 3700
#include<bits/stdc++.h>
#define INFTY 1<<20
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const int MOD=1000000007;
int n;
int x[102],cnt=0;

int main(){
    cin>>n;
    vector<int>h(n);
    rep(i,n)cin>>h[i];
    int res=0;
    while(true){
        if(*max_element(h.begin(),h.end())==0)break;
        int i = 0;
        while(i<n){
            if(h[i]==0)++i;
            else{
                ++res;
                while(i<n&&h[i]>0){
                    --h[i];
                    ++i;
                }
            }
        }
    }

    cout<< res <<endl;
return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = Long.parseLong(sc.next());
        long num = 100;
        long cnt = 0;

        while (num < x) {
            num *= 1.01;
            cnt++;
        }
        System.out.println(cnt);
        sc.close();
    }
}

Measured memory_bytes: 35824
M = int(input())
A=list(map(int,input().split()))
A.sort()
ma=A[-1]
is_prime = [True] * (ma + 1)
for i in A:
    if not is_prime[i]:
        continue
    for j in range(i * 2, ma + 1, i):
        is_prime[j] = False
k=[i for i in range(ma + 1) if is_prime[i]]
N=[]
if len(A)==1:
    print(1)
else:
    if A[0] !=A[1]:
        N.append(A[0])
    for i in range(1,len(A)-1):
        if A[i-1]!=A[i] and A[i]!=A[i+1]:
            N.append(A[i])
    if A[len(A)-2] != A[len(A)-1]:
        N.append(A[len(A)-1])
    s=set(k) & set(N)
    print(len(s))

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

int main(){
	int n, t;
	cin >> n >> t;
	int tmp_min = INT_MAX;
	int tmp_max_diff = 0;
	int max_diff_count = 0;
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		if (a < tmp_min) {
			tmp_min = a;
		} else {
			if (a - tmp_min > tmp_max_diff) {
				tmp_max_diff = a - tmp_min;
				max_diff_count = 1;
			} else if (a - tmp_min == tmp_max_diff) {
				max_diff_count++;
			}
		}
	}
	cout << max_diff_count;
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define chmax(x,y) x = max(x,y)

 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int> > VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;
typedef vector<LL> VL;
typedef vector<vector<long long>> VVLL;
typedef vector<set<int>> VSI;
const int MOD = 1e9+7;
const int INF = 1e9;
const LL LINF = 1e18;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

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


int main() {
    VI a(5);
    rep(i,5) cin >> a[i];

    rep(i,5) {
        if(a[i] == 0) {
            cout << i + 1 << endl;
            return 0;
        }
    }

}


Measured memory_bytes: 3620
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <algorithm>
#include <set>

using namespace std;

using ll = long long;

bool isPerfectSquare(long double x)
{
	// Find floating point value of  
	// square root of x. 
	long double sr = sqrt(x);

	// If square root is an integer 
	return ((sr - floor(sr)) == 0);
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, D, cnt = 0;
	cin >> N >> D;
	vector<vector<int>> X(N, vector<int>(D, 0));
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < D; ++j) {
			cin >> X[i][j];
		}
	}
	for (int i = 0; i < N - 1; ++i) {
		for (int j = i + 1; j < N; ++j) {
			int sum = 0;
			for (int k = 0; k < D; ++k) {
				sum += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
			}
			if (isPerfectSquare(sum)) {
				++cnt;
			}
		}
	}
	cout << cnt;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
import sys

bingo=[]

for _ in range(3):
  bingo.append(list(map(int, input().split())))

n=int(input())

for i in range(n):
  a=int(input())
  for j in range(3):
    for k in range(3):
      if bingo[j][k] == a:
        bingo[j][k]=0

#print(bingo)

for i in range(3):
  if (bingo[i][0]==0) & (bingo[i][1]==0) & (bingo[i][2]==0):
    print('Yes')
    sys.exit()
  
  if (bingo[0][i]==0) & (bingo[1][i]==0) & (bingo[2][i]==0):
    print('Yes')
    sys.exit()

if (bingo[0][0]==0) & (bingo[1][1]==0) & (bingo[2][2]==0):
  print('Yes')
  sys.exit()

if (bingo[0][2]==0) & (bingo[1][1]==0) & (bingo[2][0]==0):
  print('Yes')
  sys.exit()

print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define f(i,n) for(int i=0;i<n;++i)
typedef vector<int> vi;

//UNION FIND
vi siz(200001);
vi par(200001);
void initialize(int n){
    f(i,n){
        par[i]=i;
        siz[i]=1;
    }
}
int find_set(int v){
    if(par[v]==v) return v;
    return par[v]=find_set(par[v]);//Does two things, finds parent of currently asked vertex and also makes all vertices in the path connected to the root vertex
    /*Faster Implementation
        while(v!=par[v]){
            par[v]=par[par[v]];
            v=par[v];
        }
        return v;
    *///log*(n))
}
void union_sets(int a,int b){
    a=find_set(a);
    b=find_set(b);
    if(a!=b){
        if(siz[a]<siz[b])swap(a,b);
        par[b]=a;
        siz[a]+=siz[b];
    }
}
int main(){
    int n,q;
    cin>>n>>q;
    int z,x,y;
    initialize(n);
    f(i,q){
        cin>>z>>x>>y;
        if(z==0){
            union_sets(x,y);
        }
        else{
            if(find_set(x)==find_set(y))cout<<1<<endl;
            else cout<<0<<endl;
        }
    }


    return 0;
}

Measured memory_bytes: 4676
import java.util.Scanner;

public class Main {

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

		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());

		long[] a = new long[n];
		long[] b = new long[m];
		a[0] = Long.parseLong(sc.next());
		for (int i = 1; i < n; i++)
			a[i] = a[i - 1] + Long.parseLong(sc.next());
		b[0] = Long.parseLong(sc.next());
		for (int i = 1; i < m; i++)
			b[i] = b[i - 1] + Long.parseLong(sc.next());

		int max_a = -1;
		for (int i = 0; i < n; i++) {
			if (a[i] > k)
				break;
			else
				max_a = i;
		}
		int max_b = -1;
		for (int i = 0; i < m; i++) {
			if (b[i] > k)
				break;
			else
				max_b = i;
		}

		int count = 0;
		if (max_a != -1)
			count = max_a + 1;
		if (max_b != -1) {
			for (int i = 0; i <= max_b; i++) {
				if (max_a != -1) {
					while (b[i] + a[max_a] > k) {
						max_a--;
						if (max_a == -1)
							break;
					}
				}

				int tmp_count = i + 1;
				if (max_a != -1)
					tmp_count += max_a + 1;

				if (count < tmp_count)
					count = tmp_count;
			}
		}
		System.out.println(count);
	}

}


Measured memory_bytes: 63124
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            int a, b;
            while ((a = scanner.nextInt()) != 0 && (b = scanner.nextInt()) != 0) {
                for (int i = 0; i < a; i++) {
                    for (int j = 0; j < b; j++) {
                        if ((i % 2 == j % 2)) {
                            System.out.print("#");
                        } else {
                            System.out.print('.');
                        }
                    }
                    System.out.println();
                }
                System.out.println();
            }
        }
    }
}

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

using namespace std;

long double j(long double k, long double i){
	long double ret = log2(k/i);
	if (ret - static_cast<long>(ret) < 0.0000001) {
		return ret;
	} else {
		return static_cast<long double>(static_cast<long>(ret)+1);
	}
}

int main() {
	long n, k;
	cin >> n >> k;
	long double n_d = static_cast<long double>(n);
	long double k_d = static_cast<long double>(k);

	long double ans = 0;
	if (n_d < k_d) {
		for (long i=1; i<=n; ++i) {
			ans += (1/n_d) * (1/pow(2.0,j(k_d, static_cast<long double>(i))));
		}
	} else {
		for (long i=1; i<=k-1; ++i) {
			ans += (1/n_d) * (1/pow(2.0,j(k_d, static_cast<long double>(i))));
		}
		ans += (n_d-k_d+1)/n_d;
	}

	cout << setprecision(14) <<  ans << endl;

	return 0;
}

Measured memory_bytes: 256
import Data.List

main = interact $ show . sol . map read . words

sol [n,m] = if abs (n-m) > 1 then 0 
  else f @*@ f @*@ if n==m then 2 else max n m
  where
  f = foldl1' (@*@) [1..min n m]

infixl 7 @*@
(@*@) a b = a*b `mod` (10^9+7) :: Int

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

int n;
long long k;

// map<int, vector<vector<long long>> > mp;

vector<vector<long long>> mul(vector<vector<long long>> a, vector<vector<long long>> b) {
    vector<vector<long long>> c(a);
    
    for(int i = 0; i < n; i++) 
    { 
        for(int j = 0; j < n; j++) 
        { 
            c[i][j] = 0; 
            for(int k = 0; k < n; k++) {
                c[i][j] += a[i][k] * b[k][j];
                c[i][j] %= 1000000007;
            }
        }
    }
    return c;
}

vector<vector<long long>> f(vector<vector<long long>>& a, long long exponent) {
    // if(exponent == 1) return a;
    // if(mp.find(n) != mp.end()) {
    //     auto it = mp.find(exponent);
    //     return it->second;
    // }
    // if(exponent%2 == 0) {
    //     vector<vector<long long>> x = mul(f(a, exponent/2), f(a, exponent/2));
    //     mp[exponent] = x;
    //     return x;
    // }
    // else {
    //     vector<vector<long long>> x = mul(a, mul(f(a, exponent/2), f(a, exponent/2)));
    //     mp[exponent] = x;
    //     return x;
    // }
    
    vector<vector<long long>> I(n, vector<long long>(n, 0));
    for(int i = 0; i < n; i++) {
        I[i][i] = 1;
    }
    
    while(exponent > 0) {
        if(exponent%2) {
            I = mul(I, a);
        }
        
        exponent /= 2;
        a = mul(a, a);
    }
    
    return I;
}

int main() {
	// your code goes here
	ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
	cin >> n >> k;
	vector<vector<long long>> ajinkya(n, vector<long long>(n, 0));
	for(int i = 0; i < n; i++) {
	    for(int j = 0; j < n; j++) {
	        cin >> ajinkya[i][j];
	    }
	}
	auto x = f(ajinkya, k);
	long long res = 0;
	for(int i = 0; i < n; i++) {
	    for(int j = 0; j < n; j++) {
	        res += x[i][j];
	        res %= 1000000007;
	    }
	}
	cout << res;
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <unordered_map>

using namespace std;

int main()
{
	const int MAX_N = 200000;
	long long l, r;
	cin >> l;
	cin >> r;

	long long answer = 2019;
	for (long long i = l; i < r; i++)
	{
		for (long long j = l + 1; j < r + 1; j++)
		{
			answer = min(answer, (i*j) % 2019);
			if (answer == 0)
			{
				cout << 0;
				return 0;
			}
		}
	}

	cout << answer;
	return 0;

}


Measured memory_bytes: 256
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
using namespace std;

int main(){
int x;
scanf("%d",&x);//cin>>x;
if( x==1 ) puts("0");//cout<<0<<endl;
else if( x==0 ) puts("1");//cout<<1<<endl;
//after else condition is ng
//return 0;
    //std::cout << "Hello, Wandbox!" << std::endl;
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://cppreference.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   https://www.boost.org/doc/


Measured memory_bytes: 3756
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
uf = UnionFind(N)
ans = [N*(N-1)//2]
ABlist = [tuple(map(int, input().split())) for _ in range(M)]
for a, b in reversed(ABlist[1::]):
    if uf.same(a-1, b-1):
        ans.append(ans[-1])
    else:
        ans.append(ans[-1] - uf.size(a-1)*uf.size(b-1))
    uf.union(a-1, b-1)

for a in ans[::-1]:
    print(a)


Measured memory_bytes: 24508
#include <iostream>
#include <set>
#include <string>
using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    int n; cin>>n;
    set<string> a;
    while (n--) {
        string s; cin>>s;
        a.insert(s);
    }
    cout<<a.size()<<endl;
}



Measured memory_bytes: 19236
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define debug(x) cerr <<__LINE__<< ": " <<#x<< " = " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" = ";rep(i,v.size())cerr<<" "<<v[i];cerr<<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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int A[202020];
vector<int> G[202020];
vector<int> dp(202020, INF);
vector<int> ans(202020);

void dfs(int v, int p = -1) {
    int tmp = *lower_bound(all(dp), A[v]);
    int idx = lower_bound(all(dp), A[v]) - dp.begin();
    *lower_bound(all(dp), A[v]) = A[v];
    ans[v] = lower_bound(all(dp), INF) - dp.begin();
    for (auto nxt : G[v]) {
        if (nxt == p) continue;
        dfs(nxt, v);
    }
    dp[idx] = tmp;
}

void solve() {
    int n;
    cin >> n;
    rep(i, n) cin >> A[i];
    rep(i, n - 1) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }
    dfs(0);
    rep(i, n) cout << ans[i] << endl;
}

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


Measured memory_bytes: 27956
N, K = list(map(int, input().strip().split()))
M = 10**9 + 7
l = list(range(N+1))
l2 = [0]
for i in range(1, N+1):
  l2.append(l2[i-1] + l[i])
#print(l2)
ans = 0
for i in range(K, N+1):
  #minimum = sum(l[0:i])
  minimum = l2[i-1]
  #maximum = sum(l[-i::])
  maximum = l2[-1] - l2[N-i]
  n = maximum - minimum + 1
  #print(n)
  #print(minimum)
  #print(maximum)
  ans += n
ans += 1
print(ans % M)

Measured memory_bytes: 27260
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;double x,a=0;string u;cin>>n;
  for(int i=0;i<n;i++){
    cin>>x>>u;
    if(u=="JPY")a+=x;
    if(u=="BTC")a+=x*380000.0;
  }
  cout<<a<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lld;
 
#define forn(i,n) for(ll i = 0;i<n;i++)
#define forne(i,j,n) for(ll i = j;i<n;i++)
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ll INF = 3e18;
const ll N = 100001;
const lld PI = 3.141593;
#define F first
#define pb(a) push_back(a)
#define S second
#define pii pair<int,int>
typedef pair<ll,ll> pll;

int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output1.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

ll x,k,d;
cin>>x>>k>>d;
x = abs(x);
ll t = x/d;
ll fa = 0;
if(k > t){
	if((k&1) == (t&1)) fa = x-t*d;
	else{
		fa = abs(x-(t+1)*d);
	}
}
else fa = x-k*d;
cout<<fa<<endl;
}

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

int main(){
    ll n, a;
    cin >> n >> a;
    ll x, y, z;
    a /= 1000;
//x+y+z=n
//x+5y+10z=a
    int i = 0;
    //exist (y,z) s.t 4y+9z=a-n
    while(1){
        if(a-n-4*i<0||n-i-(a-n-4*i)/9<0){
            i = -1;
            break;
        }
        if((a-n-4*i)%9==0){
            y = i;
            break;
        }
        i++;
    }
    if(i==-1){
        cout << -1<<" "<< - 1<<" "<< - 1 << endl;
    }else{
        z = (a - n - 4 * y) / 9;
        x = n - z - y;
        cout << z <<" "<< y <<" "<< x << endl;
    }


}

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

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	int n,k,c;
	string s;
	cin>>n>>k>>c>>s;

	vector<int> l(k),r(k);
	int cnt=0, cur=0;
	while(cnt<k&&cur<n){
		if(s[cur]=='o'){
			l[cnt]=cur;
			cnt++;
			cur+=c+1;
		}else{
			cur++;
		}
	}
	cnt=k-1,cur=n-1;
	while(cnt>=0&&cur>=0){
		if(s[cur]=='o'){
			r[cnt]=cur;
			cnt--;
			cur-=c+1;
		}else{
			cur--;
		}
	}

	rep(i,k){
		if(l[i]==r[i])cout<<l[i]+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 5140
#include <iostream>
using namespace std;
 //Compiler version g++ 6.3.0

 int main()
 {
 	char x,y;
 	cin >> x>>y;
 	if(x-'0'>y-'0'){
 		cout << '>' << endl;
 	}else if(x-'0'<y-'0'){
 		cout << '<' << endl;
 	}else{
 		cout << '=' << endl;
 	}
 }

Measured memory_bytes: 256
#include<stdio.h>

#define NUM_MAX 10000
#define NUM_MIN 0
#define VAL_MAX 1000000
#define VAL_MIN -1000000

int main()
{
	int n,a[NUM_MAX];
	char en;
	int min=VAL_MAX, max=VAL_MIN;
	long sum=0;
	
	if( scanf("%d%c", &n, &en)!=2 )
	{
		return -1;
	}
	
	if((n<=NUM_MIN) || (n>NUM_MAX))
	{
		return -1;
	}
	
	for(int i=0; i<n; i++)
	{
		if( scanf("%d ", &a[i])!=1 )
		{
			return -1;
		}
		
		if((a[i]>=VAL_MIN) && (a[i]<=VAL_MAX))
		{
			if(a[i]<min)
			{
				min=a[i];
			}
			if(a[i]>max)
			{
				max=a[i];
			}
			
			sum+=a[i];
		}
		else
		{
			return -1;
		}
	}
	
	printf("%d %d %ld\n", min, max, sum);
	
	return 0;
}

Measured memory_bytes: 1888
#include <iostream>
#include <algorithm>
#include <vector>


int main () {
    int n;
    std::cin >> n;

    std::vector<int> l (n);

    for (int i = 0; i < n; i++) {
        std::cin >> l[i];
    }

    std::sort(l.begin(), l.end(), std::greater<int>());

    int sum = 0;
    for (auto i = l.begin() + 1; i != l.end(); i++)
    {
        sum += *i;
    }

    std::string ans;

    if(sum > l[0]) {
        ans = "Yes";
    } else {
        ans = "No";
    }

        std::cout << ans << std::endl;
}
    

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

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

int gcd(vector<int> a){
  int ans = a[0];
  for(int i = 1; i < a.size(); i++) ans = gcd(ans, a[i]);
  return ans;
}

vector<int> A(100010);

int main(){
  int N, ans;
  cin >> N;
  for(int i = 0; i < N; ++i) cin >> A[i];
  ans = gcd(A);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <functional>
#include <queue>
#include <string>
#include <map>
#include <vector>

using namespace std;

int main() {
  const char *ws[7] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
  int ms[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 
  for (int i = 2; i <= 12; i++)
    ms[i] += ms[i-1];
  for (;;) {
    int m, d;
    cin >> m >> d;
    if (!m && !d) return 0;
    cout << ws[(2+ms[m-1]+d)%7] << endl;
  }
  return 0;
}

Measured memory_bytes: 0
N = int(input())
p = list(map(int, input().split()))

res = 0
for i in range(len(p) - 1):
    if i + 1 != p[i]:
        continue

    res += 1
    tmp = p[i]
    p[i] = p[i+1]
    p[i+1] = tmp

if N == p[N-1]:
    res += 1

print(res)


Measured memory_bytes: 83856
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    auto s = iota(3).map!(i => readln.chomp).array;
    auto n = iota(3).map!(i => s[i].length.to!int).array;

    // s[x] の左から k 番目に s[y] が重なることは出来るか
    bool check(int x, int y, int k) {
        if (k >= n[x]) {
            return true;
        }
        foreach (i ; 0 .. n[y]) {
            if (k + i >= n[x]) break;
            if (s[x][k + i] == '?' || s[y][i] == '?') continue;
            if (s[x][k + i] !=  s[y][i]) {
                return false;
            }
        }

        return true;
    }

    auto ok = new bool[][][](3, 3, 2001);
    foreach (i ; 0 .. 3) {
        foreach (j ; 0 .. 3) {
            if (i == j) continue;
            foreach (k ; 0 .. 2001) {
                ok[i][j][k] = check(i, j, k);
            }
        }
    }

    int ans = inf;

    foreach (lb ; -4000 .. 4001) {
        foreach (lc ; -4000 .. 4001) {
            bool valid = true;

            if (abs(lb) >= 2000) {
            }
            else if (lb < 0) {
                valid &= ok[1][0][-lb];
            }
            else {
                valid &= ok[0][1][lb];
            }

            if (abs(lc) >= 2000) {
            }
            else if (lc < 0) {
                valid &= ok[2][0][-lc];
            }
            else {
                valid &= ok[0][2][lc];
            }

            if (abs(lb - lc) >= 2000) {
            }
            else if (lb < lc) {
                valid &= ok[1][2][lc - lb];
            }
            else {
                valid &= ok[2][1][lb - lc];
            }

            if (valid) {
                int l = min(lb, lc, 0);
                int r = max(lb + n[1], lc + n[2], n[0]);
                chmin(ans, r - l);
            }
        }
    }

    writeln(ans);
}



void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


Measured memory_bytes: 380
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
struct edge{int from, to;};

int main(){
    int n;
    cin >> n;
    int a,b;
    cin >> a >> b;
    int count=0;
    for(int i=1;i<=n;i++){
        int x=i;
        int sum=0;
        while(x>0){
            sum+=x%10;
            x/=10;
        }
        if(a<=sum&&sum<=b) {
            count+=i;
            //cout << i <<" ";
        }
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>
#include<cctype>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stack>
#include<ctime>
#define mst(a,b) memset(a,b,sizeof(a));
const int N = 1e9;
const int mod=(int)1e9+7;
const int INF=0x3f3f3f3f;
typedef long long LL;
//#define LOCAL
const double PI = acos(-1.0);
const int maxn=1e5+5;
char s[100];
using namespace std;


bool cmp(int a, int b)
{
    return a>b;
}

int gcd(int a, int b)
{
    return (b==0)?a:gcd(b,a%b);
}


#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())

int main()
{
#ifdef LOCAL
    freopen("test.txt", "r", stdin);
#endif // LOCAL
    int a, b;
    int i;
    bool is;
    is = false;
    scanf("%d%d", &a, &b);
    scanf("%s", s);
    int len = strlen(s);
    if(len!=a+b+1) printf("No");
    else
    {
        for(i = 0; i < a;i++)
        {
            if(!isdigit(s[i])) {printf("No");return 0;}
        }
        if(s[a] != '-'){printf("No");return 0;}
        for(i = a+1; i < a+b+1;i++)
        {
            if(!isdigit(s[i])) {printf("No");return 0;}
        }
        printf("Yes");
    }
    return 0;
}


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

int main() {
    string s, t;  cin >> s >> t;
    int ans = 0;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == t[i]) ++ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3580
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Joy
 */

#include <bits/stdc++.h>

#define REP(i, N) for (ll i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF ll(1e9)
#define INFL ll(1e18)
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int ctoi(char c) {return c - '0';}

class CTravelingSalesmanAroundLake {
public:
	void solve(std::istream& in, std::ostream& out) {
	    ll K, N; in >> K >> N;
	    int A[N];
	    REP(i, N) in >> A[i];
	    int dist = A[0] + (K - A[N-1]);
	    REP(i, N-1) dist = max(dist, A[i+1]-A[i]);
	    out << K - dist << '\n';
	}
};


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

	CTravelingSalesmanAroundLake solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
int main(){
    long long int N,count=0;
    cin >>N;
    int B[N];
    for(long long int i=0;i<N-1;i++){
        cin >>B[i];
    }
    count+=B[0];
    if(N==2)count+=B[0];
    else{
        count+=B[N-2];
    for(long long int i=0;i<N-2;i++){
        count+=min(B[i],B[i+1]);
    }
    }
cout <<count;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n; cin >> n;
  vector<int> f(n + 1, 1);
  for (int i = 2; i <= n; ++i) {
    for (int k = i; k <= n; k += i) ++f[k];
  }
  ll ans = 0;
  FOR(k, 1, n + 1) ans += 1LL * k * f[k];
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 42272
#include<iostream>
#include<map>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// pair 型
template<class S,class T>
std::ostream& operator<<(std::ostream& os, const pair<T,S>& p){
  cout << "(" << p.first << "," << p.second << ")";
  return os;
}
// map 型
template<class S,class T>
std::ostream& operator<<(std::ostream& os, const map<S,T>& mp){
  for(const pair<S,T>& x: mp){
    cout << "[" << x.first << "]=" << x.second << " ";
  }
  return os;
}

int main(){
  li n; cin >>n;
  int q; cin >>q;
  li ans=(n-2)*(n-2);
  map<int,int> row,col;
  row[n]=n-2;
  col[n]=n-2;
  rep(_,q){
    int a,b; cin >>a >>b; a--;
    if(a){
      auto itr=row.upper_bound(b);
      if(itr!=row.begin()){
        itr--;
        if(df)print(*itr);
        ans-=itr->second;
      }else{
        itr=col.begin();
        int x=(itr->first)-2;
        ans-=x;
        row[b]=x;
        if(df)print(b,x);
      }
      if(df)print("r",row);
    }else{
      auto itr=col.upper_bound(b);
      if(itr!=col.begin()){
        itr--;
        if(df)print(*itr);
        ans-=itr->second;
      }else{
        itr=row.begin();
        int x=itr->first-2;
        ans-=x;
        col[b]=x;
        if(df)print(b,x);
      }
      if(df)print("c",col);
    }
  }
  print(ans);
}


Measured memory_bytes: 12972
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#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, s, n) for (int i = (s); i <= (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int,int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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

    ll x,y;cin>>x>>y;
    ll ans=1;
    while(1){
        if(x*2<=y)ans++;
        else break;
        x*=2;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 3640
#92B
n = int(input())
d,x = map(int,input().split())
a = list(map(int, [input() for i in range(n)]))
answer = 0

for i in range(1,d+1):
	for j in a:
		if (i-1)%j == 0:
			answer += 1
print(answer+x)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <deque>

#define ll long long
#define ull unsigned long long
#define mod 1000000007

using namespace std;

class game {
public:
	vector<pair<int, int>> flowIn;
	vector<pair<int, int>> flowOut;
};

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

	int n;
	cin >> n;
	game** games;
	games = new game*[n];
	for (int i = 0; i < n; ++i) {
		games[i] = new game[n];
	}

	vector<pair<int, int>> que;

	for (int i = 0; i < n; ++i) {
		int beforeA;
		for (int j = 0; j < n - 1; ++j) {
			int a;
			cin >> a;

			int t, s;
			t = min(i, a - 1);
			s = max(i, a - 1);
			if (j != 0) {
				int x, y;
				x = min(i, beforeA - 1);
				y = max(i, beforeA - 1);
				games[t][s].flowIn.push_back(pair<int, int>(x, y));
				games[x][y].flowOut.push_back(pair<int, int>(t, s));
			}
			else {
				que.push_back(pair<int, int>(t, s));
			}
			beforeA = a;
		}
	}


	int day = 0;
	int counter = 0;

	sort(que.begin(), que.end());
	que.erase(unique(que.begin(), que.end()), que.end());
	for (int i = 0; i < que.size(); ++i) {
		if (games[que[i].first][que[i].second].flowIn.size() != 0) {
			que.erase(que.begin() + i);
			--i;
		}
		else {
			++counter;
		}
	}

	while (!que.empty()) {
		vector<pair<int, int>> altque = que;
		que.clear();
		for (int k = 0; k < altque.size(); ++k) {
			for (int i = 0; i < games[altque[k].first][altque[k].second].flowOut.size(); ++i) {
				int x, y;
				x = games[altque[k].first][altque[k].second].flowOut[i].first;
				y = games[altque[k].first][altque[k].second].flowOut[i].second;
				for (int j = 0; j < games[x][y].flowIn.size(); ++j) {
					if (games[x][y].flowIn[j] == altque[k]) {
						games[x][y].flowIn.erase(games[x][y].flowIn.begin() + j);
						--j;
					}
				}
				if (games[x][y].flowIn.size() == 0) {
					++counter;
					que.push_back(pair<int, int>(x, y));
				}
			}
		}

		++day;
	}

	if (counter != (n * (n - 1)) / 2) {
		cout << -1 << "\n";
	}
	else {
		cout << day << "\n";
	}

	delete[] games;
	return 0;
}


Measured memory_bytes: 78336