akhauriyash/Code-Regression huggingface dataset:
#define rep(i,n) REP(i,0,n)
#define REP(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;

// const ll MAXN = (ll)1e3+10;
const ll DIV = (ll)1e9+7;
// ll dp[MAXN][MAXN];

int main(void) {
   ll N;
   cin>>N;
   vector<vector<ll>> A;
   A.resize(N);
   rep(i,N) A[i].resize(N);
   rep(i,N) rep(j,N) cin>>A[i][j];

   multimap<ll,ll> As;
   rep(i,N) {
      for (int j = i+1; j<N;j++) {
         As.insert(make_pair(A[i][j],i*N+j));
      }
   }

   vector<vector<ll>> L;
   L.resize(N);
   rep(i,N) L[i].resize(N);
   rep(i,N) rep(j,N) L[i][j] = INF;
   rep(i,N) L[i][i] = 0;

   ll ans = 0;
   for (auto itr = As.begin();itr!=As.end();itr++) {
      int i = (itr->second)%N;
      int j = (itr->second)/N;
      int len = itr->first;
      if (L[i][j] == len) continue;
      else if (L[i][j] < len){
         ans =-1;
         break; 
      } else {
         // connect i,j with len.
         ans += len;

         rep(k,N) rep(l,N) {
            chmin(L[k][l],L[k][i]+len+L[l][j]);
            chmin(L[k][l],L[k][j]+len+L[l][i]);
         }
      }
   }
   cout<<ans<<endl;

   return 0;
}

Measured memory_bytes: 4480
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstdio>
using namespace std;

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

	int a[1000000];

	for(i=1; i<n+1 ; i++){
		cin >> a[i];
	}

	int b[1000000];
	for(i=1; i<n+1; i++){
		b[a[i]] = i;
	}

	for(i=1; i<n+1; i++){
		cout << b[i] << " ";
	}
	cout << endl;
}

Measured memory_bytes: 7168
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
static const long long mod = 1e9+7;

long long modpow(long long a, int p) {
  if (p == 0) return 1;

  if (p % 2 == 0) {
    int halfP = p / 2;
    long long half = modpow(a, halfP);
    return half * half % mod;
  } else {
    return a * modpow(a, p-1) % mod;
  }
}

long long modComb(int a, int b) {
  if (b > a - b) return modComb(a, a-b);

  long long ansMul = 1, ansDiv = 1;
  for (int i = 0; i < b; i++) {
    ansMul *= a - i;
    ansDiv *= i + 1;
    ansMul %= mod;
    ansDiv %= mod;
  }

  long long ans = ansMul * modpow(ansDiv, mod-2) % mod;

  return ans;
}

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

  for (int i = 1; i <= K; i++) {
    if ((N-K) < (i-1)) {
      cout << 0 << endl;
      continue;
    }
    long long ansb, ansr, ans;
    ansb = modComb(K-1, i-1);
    ansr = modComb(N-K+1, i);
    ans = (ansb * ansr) % mod;
    cout << ans << endl;
  }

  return 0;
}

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

#define vd vector<double>
 
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define vc vector<char>
#define vcc vector< vector<char> >
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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; }
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
// #define mp make_pair
//#define endl '\n'
 
int main() {
    int n, m;
    cin >> n >> m;
    int ans, l = 1, r = n;
    bool flag = 0;
    rep(i, m){
        int l_i, r_i;
        cin >> l_i >> r_i;
        if(r_i < l || r < l_i){
            flag = 1;
            break;
        }
        else{
            if(l <= l_i) l = l_i;
            if(r_i <= r) r = r_i;
        }
    }
    if(flag) ans = 0;
    else ans = r - l + 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main {
	
	private static final Scanner sc = new Scanner(System.in);
	
	public static void main(String... args) {
		new Main().run();
	}
	
	public void run() {
		List<Time> ts = new ArrayList<Time>();
		final int N = sc.nextInt();

		for (int i = 0; i < N; i++) {
			ts.add(new Time(sc.nextInt(), sc.nextInt()));
		}
		
		final int M = sc.nextInt();
		for (int i = 0; i < M; i++) {
			ts.add(new Time(sc.nextInt(), sc.nextInt()));
		}
		
		Collections.sort(ts);
		Set<Time> tset = new TreeSet<Time>(ts); 
		Object[] tss = tset.toArray();
		for (int i = 0; i < tss.length - 1; i++) {
			System.out.print(tss[i] + " ");
		}

		System.out.println(tss[tss.length - 1]);
	}
	
	public class Time implements Comparable<Time> {
		int h, m;
		
		Time(int h, int m) {
			this.h = h;
			this.m = m;
		}

		@Override
		public String toString() {
			return String.format("%d:%02d", this.h, this.m);
		}
		
		@Override
		public int compareTo(Time t) {
			return (this.h * 60 + this.m) - (t.h * 60 + t.m);
		}
	}
}

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

int main(void){
    int N;
    cin >> N;
    int a[N+1];
    a[0] = 0;
    int counter = 0;
    
    for(int i = 1 ; i <= N ; i++){
        cin >> a[i];
        if(i % 2 != 0 && a[i] % 2 != 0) counter++;
    }
    
    cout << counter << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
using namespace std;
int main(){
    
    int n,x,a[4][13]={0};
    char ch;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>ch>>x;
        if(ch=='S'){a[0][x-1]=1;}
        if(ch=='H'){a[1][x-1]=1;}
        if(ch=='C'){a[2][x-1]=1;}
        if(ch=='D'){a[3][x-1]=1;}
    }
    for(int k=0;k<4;k++){
        for(int j=0;j<13;j++){
            if(a[k][j]!=1&&k==0){cout<<"S "<<j+1<<endl;}
            if(a[k][j]!=1&&k==1){cout<<"H "<<j+1<<endl;}
            if(a[k][j]!=1&&k==2){cout<<"C "<<j+1<<endl;}
            if(a[k][j]!=1&&k==3){cout<<"D "<<j+1<<endl;}
        }
        
    }
    return 0;
}



Measured memory_bytes: 3096
import Control.Applicative

solve :: Integer -> [Integer] -> Integer
solve n [x]       = n
solve n (x:x':xs) = (min n $ x'-x) + solve n (x':xs) 

main = do
    [_,n] <- map read . words <$> getLine
    xs    <- map read . words <$> getLine
    putStrLn $ show $ solve n xs


Measured memory_bytes: 70012
n = int(input())
a = [int(input()) for i in range(n)]

a.sort()
ans = 0
flag = 1
for i in range(n-1):
    if a[i] == a[i+1]:
        flag += 1
    else:
        if flag % 2 == 1:
            ans += 1
        flag = 1
if flag % 2 == 1:
    ans += 1
print(ans)

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



int main(){

  int n,m,g,ans=0;
  bool j=true; 
  cin>>n>>m>>g;
  if(n+m<g){j=false;}
  if(g>n){ans=g-n;}
  if(j){cout<<ans<<endl;}
  if(!j){cout<<"NA"<<endl;}


  return 0;
}



Measured memory_bytes: 3076
# -*- coding:utf-8 -*-

n = int(input())

for i in range(2,n+1):
    a = i // 10
    a = a % 10
    b = i // 100
    b = b % 10
    if i % 3 == 0:
        print(' ',i,sep='',end='')
    elif i % 10 == 3:
        print(' ',i,sep='',end='')
    elif a == 3:
        print(' ',i,sep='',end='')
    elif i // 100 == 3:
        print(' ',i,sep='',end='')
    elif i // 1000 == 3:
        print(' ',i,sep='',end='')
    elif i // 10000 == 3:
        print(' ',i,sep='',end='')
    elif b == 3:
        print(' ',i,sep='',end='')
print('')

Measured memory_bytes: 8284
#include<iostream>
#include<string>
using namespace std;
int main(){
    int a, b;
    string op;
    while (true){
        cin >> a >> op >> b;
        if (op == "+"){
            cout<< a + b << endl;
        }else if (op == "-"){
            cout<< a - b << endl;
        }else if (op == "*"){
            cout<< a * b << endl;
        }else if (op == "/"){
            cout<< a / b << endl;
        }else if(op == "?"){
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3136
// https://atcoder.jp/contests/abc106/tasks/abc106_b
#include <iostream>
#include <vector>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int_fast32_t i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int_fast32_t i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

vector<int> a = {105, 135, 165, 189, 195};

signed main() {
    // ios::sync_with_stdio(false);
    // cin.tie(0);
    int N;
    cin >> N;
    if (N >= 195) {
        cout << "5\n";
    } else if (N >= 189) {
        cout << "4\n";
    } else if (N >= 165) {
        cout << "3\n";
    } else if (N >= 135) {
        cout << "2\n";
    } else if (N >= 105) {
        cout << "1\n";
    } else {
        cout << "0\n";
    }
    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <set>
using namespace std;
using ll = long long;
int main(void){
    string n;
    cin >> n;
    int ans =0;
    for(int i=0;i<n.length();i++){
        if(n[i]=='2'){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 764
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0
for count_500 in range(A+1):
    for count_100 in range(B+1):
        for count_50 in range(C+1):
            sum_money = 500*count_500 + 100*count_100 + 50*count_50
            if sum_money == X:
                ans += 1
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <algorithm>
 
using namespace std;
 
int main(){
  int X, ans = 0, max_ans = 1;
  cin >> X;
  for (int i=2; i<=X; ++i){
      int j = 2;
      while(pow(i, j) <= X){
          ans = pow(i, j);
          max_ans = max(max_ans, ans);
          ++j;
      }
  }
  cout << max_ans << endl;
}

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

#define ll long long
#define pb push_back
#define iter std::vector<int>::iterator

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

	ll n; cin >> n;
	while (n != 0)
	{

		if (n % 10 == 7) {
			cout << "Yes";
			return 0;
		}

		n = n - (n % 10);
		n = n / 10;

	}

	cout << "No";



	return 0;	
}

Measured memory_bytes: 3596
#include<iostream>
using namespace std;
const int maxn = 22;
int a[maxn],b[maxn],c[maxn];
int main() {
	int n;
	cin>>n;
	for(int i=1;i<=n;++i) {
		cin>>a[i];
	}
	for(int i=1;i<=n;++i) {
		cin>>b[i];
	}
	for(int i=1;i<n;++i) {
		cin>>c[i];
	}
	int ans = 0;
	int prev = 0;
	for(int i=1;i<=n;++i) {
		ans += b[a[i]];
		if(prev == a[i]-1) {
			ans += c[prev];
		}
		prev = a[i];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int m, f, r;
	int sum, flag;
	
	while (1){
		scanf("%d %d %d", &m, &f, &r);
		
		sum = m + f;
		
		if (m == -1 && f == -1 && r == -1){
			break;
		}
		else if (m == -1 || f == -1){
			printf("F\n");
		}
		else if (sum >= 80){
			printf("A\n");
		}
		else if (sum >= 65){
			printf("B\n");
		}
		else if (sum >= 50){
			printf("C\n");
		}
		else if (sum >= 30 && r >= 50){
			printf("C\n");
		}
		else if (sum >= 30){
			printf("D\n");
		}
		else {
			printf("F\n");
		}
	}
	
	return 0;
}



Measured memory_bytes: 2036
s = input().split()

n = int(s[0])
t = int(s[1])

arrays = []

for i in range(n):
    v = input().split()
    w = int(v[1])
    if w <= t:
        arrays.append(int(v[0]))

arrays.sort()
if len(arrays) == 0:
    print('TLE')
else:
    answer = arrays[0]
    print(answer)

Measured memory_bytes: 9120
#include <stdio.h>

int main(void){
	int a, b, c, d, e, f, t;
	double x, y;
	while(scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f) != EOF){
		t = 1.0*a*e - 1.0*b*d;
		x = (1.0*e*c - 1.0*b*f)/t + 0.0001;
		y = (1.0*a*f - 1.0*d*c)/t + 0.0001;
		printf("%.3f %.3f\n", x, y);
	}
	
	return 0;
}

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

/*
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <ctype.h>
*/


using namespace std;

typedef pair<int , int > pii;
typedef pair<long , long> pll;
typedef pair<pii , int > piii;
typedef pair<pll , long > plll;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector <pii> vii;
typedef vector<pll> vll;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef unsigned long long int ulli;
typedef long long int lli;
typedef double d;
typedef float f;
typedef string s;
typedef char ch;
typedef pair<int,ll> pill;

#define loop(n) for(int i = 0; i < (n); i++)
#define lp(x , s , e) for(int x = (s); x < (e); x++)
#define lpe(x , s , e) for(int x = (s); x <= (e); x++)
#define readline(s) getline(cin,s)
#define NumofDigits(n) ((int)log10(n)+1)
#define CountofNumber(array,n,x)  (upper_bound(array, array+n, x)-lower_bound(array, array+n, x))
#define F first
#define S second
#define EPS 1e-7
#define modulo ll (1e9 + 7)
const long double PI = 3.141592653589793238L;
#define MP make_pair
#define PB push_back
#define all(a) a.begin(),a.end()
#define clr(x , val) memset((x) , (val) , sizeof(x))
#define endl '\n'

ll power(ll a, ll b)
{
    ll res = 1;
    for(int i = 0; i<b; i++)
       res *= a;

    return res;
}


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	int out = n * (n + 1) / 2;
	cout << out << endl;
    return 0;
}


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

int minCost(vector<int>& nums)
{
	int n = nums.size();
	if(n<2)
		return 0;
	vector<int> cost(n);
	cost[0] = 0;
	cost[1] = abs(nums[0] - nums[1]);
	for(int i = 2; i < n; i++)
		cost[i] = min(cost[i-1]+abs(nums[i] - nums[i-1]), cost[i-2] + abs(nums[i] - nums[i-2]));
	return cost[n-1];
}

int main(){
	int n;
	cin>>n;
	vector<int> vec(n);
	for(int i = 0; i < n; i++)
		cin>>vec[i];
	cout<<minCost(vec)<<endl;
}

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

#define mp make_pair

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef pair<i64,int> pli;
typedef pair<int,i64> pil;
typedef pair<i64,i64> pll;
typedef vector<int> vi;
typedef vector<i64> vl;

template <typename T>
T id(T b) {return b;};
template <class It>
bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It>
bool any(It f,It l){return std::any_of(f,l,id<bool>);}

int c[3][3];
int a[3], b[3];

int main()
{
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      cin >> c[i][j];
    }
  }

  for (int i = 1; i < 3; i++) {
    if (!(c[0][0] - c[0][1] == c[i][0] - c[i][1])
        || !(c[0][1] - c[0][2] == c[i][1] - c[i][2])
        || !(c[0][0] - c[1][0] == c[0][i] - c[1][i])
        || !(c[1][0] - c[2][0] == c[1][i] - c[2][i])) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;

int main(){
    int h,w;cin>>h>>w;
    char s[h+2][w+2];bool ans=1;
    for(int i=1;i<h+1;i++) for(int j=1;j<w+1;j++) cin>>s[i][j];
    for(int i=0;i<h+2;i++) {s[i][0]='a';s[i][w+1]='a';}
    for(int i=0;i<w+2;i++) {s[0][i]='a';s[h+1][i]='a';}
    
    /*for(int i=0;i<h+2;i++){
        for(int j=0;j<w+2;j++){
            cout<<s[i][j];
        }
        cout<<endl;
    }*/

    for(int i=1;i<h+1;i++){
        for(int j=1;j<w+1;j++){
            if(s[i][j]=='#'){
                bool chk=0;
                if(s[i-1][j]=='#'||s[i+1][j]=='#'||s[i][j-1]=='#'||s[i][j+1]=='#') chk=1;
                if(!chk){
                    ans=0;
                    break;
                }
            }
        }
    }
    if(ans) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static int findGreatestDivisor(int num1, int num2) {
		int checking = Math.max(num1, num2) % Math.min(num1, num2);
		if (checking == 0) return num1;
		int result = 0;
		
		while (checking > 0) {
			if (num1 % checking == 0 && num2 % checking == 0) {
				result = checking;
				break;
			}
			checking--;
		}
		
		return result;
	}
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int num1 = scanner.nextInt();
		int num2 = scanner.nextInt();
		scanner.close();
		
		System.out.println(findGreatestDivisor(num1, num2));
	}
}



Measured memory_bytes: 26428
#include <stdio.h>
const int N=1e3+10;
int main(){
    int n,a,b,dp[N];
    while(true){
        scanf("%d",&n);
        if(n==0)return 0;
        dp[0]=1;
        for(int i=1;i<N;i++)dp[i]=0;
        while(n--){
            scanf("%d%d",&a,&b);
            for(int i=N-1;i>=0;i--)for(int j=1;j<=b;j++)if(j*a<=i)dp[i]+=dp[i-j*a];
        }
        scanf("%d",&n);
        while(n--){
            scanf("%d",&a);
            printf("%d\n",dp[a]);
        }
    }
}


Measured memory_bytes: 2752
import { Hash } from "crypto";
import { access } from "fs";

class Input {
    private lines: string[];
    constructor(lines: string[]) {
        this.lines = lines;
    }

    public string(): string { return this.lines.shift() as string; }
    public int(): number { return parseInt(this.string()); }
    public intArray(): number[] { return this.string().split(" ").map(n => parseInt(n)); }
    public stringArray(): string[] { return this.string().split(" "); }

    public allLines(): string[] { return this.lines; }
    public allLinesInt(): number[] { return this.lines.map(s => parseInt(s)); }
    public allLinesIntArray(): number[][] { return this.lines.map(s => s.split(" ").map(n => parseInt(n))); }
    public allLinesStringArray(): string[][] { return this.lines.map(s => s.split(" ")); }
}


function calc(stdin: Input) {
    stdin.string();
    const a = stdin.intArray();

    let sum = 0;
    a.forEach(x => {
        for (var count = 0; (x & 1) == 0; count++ , x = x >> 1) { }
        sum+= count;
    });
    return sum;
}

function main(stdin: string) {
    console.log(calc(new Input(stdin.split("\n"))));
}

if (require.main && require.main.filename.indexOf("Main") >= 0) {
    main(require('fs').readFileSync('/dev/stdin', 'utf8'));
} else {
    main(require('fs').readFileSync('input.txt', 'utf8').trim());
}

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

using namespace std;

#define int long long
#define pii pair<int,int>
#define fi first
#define se second

const int N = 1e5 + 7;

int n, ans[N];
pii a[N];

bool cmp(pii x, pii y){
	return (x.fi > y.fi || (x.fi == y.fi && x.se < y.se));
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; ++i) cin >> a[i].fi, a[i].se = i;
	sort(a + 1, a + n + 1, cmp);
	
	
	for(int i = 1, pick = i, cur = a[pick].fi; i <= n; ){
		if(i <= n && a[i].fi == a[i + 1].fi) ++i;
		int ptr = i + 1;
		ans[a[pick].se] += (ptr - 1) * (cur - a[ptr].fi);
		cur = a[ptr].fi;
		pick = (a[pick].se > a[ptr].se ? ptr : pick);
		i = ptr;
	}
	
	for(int i = 1; i <= n; ++i) cout << ans[i] << endl;
}


Measured memory_bytes: 6000
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>

#define ff first
#define ss second

using namespace std;
using pii=pair<int,int>;
using ll=long long;

int main()
{
    ios::sync_with_stdio(false);
	cin.tie(0);
    
    ll n,k;
    cin>>n>>k;
    vector<ll> a(n);
    for(int i=0; i<n; i++) cin>>a[i];
    ll maxa=*max_element(a.begin(),a.end());
    ll lo=0,hi=maxa;

    while(lo<hi){
        ll mid=(lo+hi)/2;
        ll m=maxa-mid;
        ll cnt=0;
        for(int i=0; i<n; i++){
            cnt+=a[i]/m;
            if(a[i]%m==0) cnt-=1;
        }
        if(cnt<=k) lo=mid+1;
        else hi=mid;
    }
    cout<<maxa-lo+1;

    return 0;
}


Measured memory_bytes: 4776
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#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 FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
    return scanf("%lld", &x);
}

int GI(int& x) {
    return scanf("%d", &x);
}

const int MAXN = 200005;
int p[MAXN], incycle[MAXN], visited[MAXN];

int grundy[MAXN], nextgrundy[MAXN], s[MAXN];

int n;

vector<vector<int>> adj;

vector<int> cycle;

void dfs(int u) {
    visited[u] = 1;

    for (auto& v : adj[u]) {
        if (!visited[v] && !incycle[v]) dfs(v);
    }

    for (auto& v : adj[u]) {
        if (!incycle[v]) s[grundy[v]] = u;
    }

    grundy[u] = 0;
    while (s[grundy[u]] == u) {
        grundy[u]++;
    }

    nextgrundy[u] = grundy[u] + 1;
    while (s[nextgrundy[u]] == u) {
        nextgrundy[u]++;
    }
}

int main() {
    GI(n);

    adj.resize(n+1);

    FOR1(i, n) {
        GI(p[i]);
        adj[p[i]].PB(i);
    }

    memset(visited, 0, sizeof visited);

    int i = 1;

    while (!visited[i]) {
        visited[i] = 1;
        i = p[i];
    }

    // i is in cycle

    memset(incycle, 0, sizeof incycle);

    while (!incycle[i]) {
        cycle.PB(i);
        incycle[i] = 1;
        i = p[i];
    }

//    PR0(cycle, cycle.size());

    memset(visited, 0, sizeof visited);
    memset(s, -1, sizeof s);

    for (i = 1; i <= n; i++) {
        if (!visited[i]) {
            dfs(i);
        }
    }

//    PR0(grundy, n+1);
//    PR0(nextgrundy, n+1);

    // case 1
    set<int> x = {grundy[cycle[0]]};

    for (i = 1; i < cycle.size(); i++) {
        int u = cycle[i];

        set<int> y;

        if (x.count(grundy[u])) {
            y.insert(nextgrundy[u]);
        }

        if (x.count(grundy[u]) == 0 || x.size() > 1) {
            y.insert(grundy[u]);
        }

        x = y;
    }

    if (x.count(grundy[cycle[0]]) == 0 || x.size() > 1) {
        printf("POSSIBLE\n");
        return 0;
    }

    x = {nextgrundy[cycle[0]]};

    for (i = 1; i < cycle.size(); i++) {
        int u = cycle[i];

        set<int> y;

        if (x.count(grundy[u])) {
            y.insert(nextgrundy[u]);
        }

        if (x.count(grundy[u]) == 0 || x.size() > 1) {
            y.insert(grundy[u]);
        }

        x = y;
    }

    if (x.count(grundy[cycle[0]])) {
        printf("POSSIBLE\n");
        return 0;
    }

    printf("IMPOSSIBLE\n");
    return 0;
}


Measured memory_bytes: 15604
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
using namespace std;

int main()
{
    int N, Q, K;
    cin >> N;
    vector<int> a(N - 1), b(N - 1), c(N - 1);

    vector<vector<pair<int, int> > > connect(N);

    REP (i, N - 1) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        connect[a].emplace_back(b, c);
        connect[b].emplace_back(a, c);
    }

    cin >> Q >> K;
    vector<int> x(Q), y(Q);
    REP (i, Q) {
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
    }

    K--;
    vector<long long> cost_from_K(N, LLONG_MAX);
    cost_from_K[K] = 0;
    priority_queue<int> pq;
    pq.push(K);

    vector<long long> ans(Q);

    while (!pq.empty()) {
        int curr = pq.top();
        pq.pop();

        for (auto next : connect[curr]) {
            long long cost = cost_from_K[curr] + next.second;
            if (cost < cost_from_K[next.first]) {
                cost_from_K[next.first] = cost;
                pq.push(next.first);
            }
        }
    }

    REP (i, Q)
        cout << cost_from_K[x[i]] + cost_from_K[y[i]] << endl;
}


Measured memory_bytes: 12020
#include <iostream>

using namespace std;
int main(void) {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    bool passed = true;
    for (int i = 0; i < n; i++) {
        if (a[i] % 2 == 0) {
            if (a[i] % 3 != 0 && a[i] % 5 != 0) {
                passed = false;
                break;
            }
        }
    }
    if (passed) cout << "APPROVED\n";
    else cout << "DENIED\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<ll> vec(n);
    ll ans=0;
    rep(i,0,n){
        int a,b;
        cin>>a>>b;
        ans-=b;
        vec[i]=a+b;
    }
    sort(all(vec),greater<ll>());
    rep(i,0,n) if(i%2==0) ans+=vec[i];
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
// *st.find_by_order(index), 0-based
// order_of_key(e)

const int mx=2e5+777;
int memo[mx];

int brute(string s, int idx) {
	if(s[idx]=='1') s[idx]='0';
	else s[idx]='1';
	int ret=0, ct=0;
	for (char ch : s)
		if(ch=='1')
			ct++;
	for (char ch : s)
		ret=(ret*2+(ch-'0'))%ct;
	return ret;
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	memo[0]=0;
	for (int i=1; i<mx; i++)
		memo[i]=memo[i%__builtin_popcount(i)]+1;
	int N; cin>>N;
	string X; cin>>X;
	int ct=0;
	for (int i=0; i<N; i++)
		if(X[i]=='1')
			ct++;
	vector<int> minus(N+1,0), plus(N+1,0);
	int x=1, y=1;
	for (int i=1; i<=N; i++) {
		minus[i]=x;
		plus[i]=y;
		if(ct>1) x=(x*2)%(ct-1);
		y=(y*2)%(ct+1);
	}

	int dec=0, inc=0;
	for (int i=0; i<N; i++) {
		int cur=X[i]-'0';
		if(ct>1) dec=(dec*2+cur)%(ct-1);
		inc=(inc*2+cur)%(ct+1);
	}
	for (int i=0; i<N; i++) {
		if(X[i]=='1' && ct==1) {
			cout<<0<<"\n";
		} else {
			int cur=N-i;
			int x=-1;
			if(X[i]=='1') x=(dec+(ct-1)-minus[cur])%(ct-1);
			else x=(inc+plus[cur])%(ct+1);
			int add=memo[x];
			cout<<1+add<<"\n";
		}
	}
	return 0;
}

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

string A;

int main(){
  cin >> A;
  
  for(int i = 0 ; i<3;i++){
  	if(A[i] == A[i+1]){
      cout << "Bad" << endl;
      break;
    }
    if(i == 2) cout << "Good" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <math.h>
#include <set>
#include <stack>
#include <bitset>
#include <map>
#include <queue>
#include <random>
#include <unordered_set>
#include <unordered_map>
#define DEBUG
#define fi first
#define se second
#define pqueue priority_queue
#define pb(x) push_back(x)
#define endl '\n'
#define all(x) x.begin(), x.end()
#define int long long
#define mk(a, b) make_pair(a, b)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ull> vull;
typedef vector<ll> vll;
// typedef tuple<int, int, int> tiii;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector< vector<int> > vvi;
typedef vector<char> vc;

const int INF = 1e9;
const ll INFLL = 1e16;
const int MOD = 1000000007;
const int MAXN = 3e5;
//const ld eps = 1e-6;
const ld eps2 = 1e-9;
const int MOD2 = 998244353;
const int dosz = 5e5;
const int SZ = (1<<18);
const ld PI = atan2l(0, -1);


void fast_io(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifdef DEBUG
        // freopen("a.in", "r",stdin);
#else
       // freopen("substrcmp.in", "r", stdin);
       // freopen("substrcmp.out", "w", stdout);
#endif
}

void solve(){
    int n, k;
    cin >> k >> n;
    vi nums(n);
    for(int &i:nums)
        cin >> i;
    int ans = INFLL;
    for(int i=0; i<n-1; i++){
        ans = min(ans, nums[i] + (k-nums[i+1]));
    }
    ans = min(nums[n-1]-nums[0], ans);
    for(int i=1; i<n; i++){
        ans = min(ans, nums[i]-nums[i-1]+k);
    }
    cout << ans << endl;
}

signed main() {
    fast_io();
    int q = 1;
    // cout << fixed << setprecision(6);
    // cin >> q;
    // cout << 1 << endl;
    while(q--){
        solve();
    }
    return 0;
}


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

#define ll long long int
#define ull unsigned long long int
#define Max 1000005
#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ALL(x) x.begin(),x.end()
#define pi acos(-1.0)
#define pb push_back
#define load(array,size)  for(ll i=0 ; i<size ; i++) cin>>array[i] ;
#define endl '\n'

#define sc(n) scanf("%d",&n)
#define scan(n) scanf("%lld",&n)
/*        speed up       */
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define sci(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define load1(array,size)  for(ll i=1 ; i<=size ; i++) cin>>array[i] ;
#define INF    1LL<<19
#define pll pair<ll,ll>
#define mst(arr,value) memset(arr,value,sizeof(arr));
#define tst() _fastio;int testsalam;cin >> testsalam;while(testsalam--)
#define Mod 100000007
#define YES cout<<"Yes"<<endl;
#define NO cout<<"No"<<endl;

//void inversemod(ll n, ll mod, ll invmod[],ll MOD){for(int i=2; i<=n; ++i) invmod[i]=MOD-MOD/i*invmod[MOD%i]%MOD;}
//void bigmod( ll a, ll b ,ll mod){ll r = 1;a = a%mod;while(b){if( b%2 ) r = (r*a)%mod;b = b/2;a = (a*a)%mod; }return (ll)r;}
string inttostr(ll n){std::stringstream ss;ss << n;string out=ss.str();return out;}
ll stringtoint(string s){istringstream iss (s);ll n;iss >> n;return n;}
template <typename T> T gcd(T a,T b){if(a < 0)return gcd(-a,b);if(b < 0)return gcd(a,-b);return (b == 0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {if(a < 0)return lcm(-a,b);if(b < 0)return lcm(a,-b);return a*(b/gcd(a,b));}
typedef vector<ll>vec;
typedef pair<ll,ll> pii;
typedef map<ll,ll>mpll;
typedef set<ll>seet;
typedef tuple<ll,ll,ll>tpl;

ll f(int x,int y,int z)
{
    return x*x+y*y+z*z+x*y+y*z+z*x;
}

int main()
{
    int n;
    cin >> n;
    int m=sqrt(n+1);
    map<int,int>bal;
    for(int x=1;x<=m;x++)
    {
        for(int y=1;y<=m;y++)
        {
            for(int z=1;z<=m;z++)
            {
                bal[f(x,y,z)]++;
            }
        }
    }
    for(int i=1;i<=n;i++)cout<<bal[i]<<endl;
}
/*
     remember:
     ll vs int
     array size
     case for 1 2 3 
*/



Measured memory_bytes: 5464
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let x: usize = iterator.next().unwrap().parse().unwrap();
    let l: Vec<usize> = (0..n).map(|_| iterator.next().unwrap().parse().unwrap()).collect();

    let mut current: usize = 0;
    let mut count: usize = 1;
    for i in 0..n {
        current += l[i];
        if current <= x {
            count += 1;
        } else {
            break;
        }
    }
    return count.to_string();
}


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

cnt = 0
for i in range(1,N-1):
    if (list[i-1] < list[i] and list[i] < list[i+1]) or (list[i-1] > list[i] and list[i] > list[i+1]):
        cnt += 1
        
print(cnt)

Measured memory_bytes: 3064
let rec gcd m n = match m,n with | m,0 -> m | m,n -> gcd n (m mod n);;
Scanf.(Array.(scanf " %d" @@ fun n ->
  let a = init n (fun _ -> scanf " %d" @@ fun v -> v)
  in print_int @@ fold_left gcd a.(0) a))

Measured memory_bytes: 5120
#include <iostream>
using namespace std;
int n,a[100005],ans=1,dir,st;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	st=n+1;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(st==n+1 && i>1 && a[i]!=a[i-1])st=i;
	}
	dir=(a[st-1]<a[st]);
	for(int i=st+1;i<=n;i++){
		if(a[i-1]==a[i])continue;
		if((a[i-1]<a[i])!=dir){
			ans++;
			while(i<n){
				if(a[i]!=a[i+1]){
					dir=(a[i]<a[i+1]);
					break;
				}
				i++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int check(int data){
    
    if(data % 2 == 0){
        if(data % 3 == 0 || data % 5 == 0) return true;
        else return false;
    }
    
    return true;
}

int main(void){
    
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    
    for(int i = 0; i < N; i++){
        if(!check(A[i])){
            cout << "DENIED" << endl;
            return 0;
        }
    }
    
    cout << "APPROVED" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int i,k,n;
char s[10];
int main(void){
    scanf("%d",&n);
    scanf("%s",s);
    scanf("%d",&k);
    for(i = 0;i < n;i++){
        if(s[i] != s[k-1]){
        s[i] = '*';
        }
    }
    printf("%s",s);
}

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

using namespace std;

int main()
{
	int N;
	int ans = 0;
	vector<int> C;
	cin >> N;

	vector<int> A(N);

	for (int i = 0; i < N; i++)
		cin >> A[i];

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

	C.push_back(A[0]);
	for (int i = 0; i < N - 1; i++)
	{
		if (A[i] != A[i + 1])
			C.push_back(A[i + 1]);
	}

	vector<int> Cv(C.size());
	int j = 0;
	for (int i = 0; i < C.size();i++)
	{
		while (j < A.size() && A[j] == C[i])
		{
			Cv[i]++;
			j++;
		}
	}

	int even = 0;
	for (int i = 0; i < Cv.size(); i++)
	{
		if (Cv[i] % 2 == 0)
			even++;
	}

	ans = C.size();

	if (even % 2 != 0)
		ans--;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1528
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e15;
const int MOD = 1e9 + 7;

signed main() {
	string s;
	cin >> s;
	for (auto i : s) {
		if (i == ',')cout << " ";
		else cout << i;
	}
}

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

// 8:20 ?
//
int main () {
	int N;
	cin >> N;
	
	// N=3
	// (1,2),(2,3),(3,1): OK
	// N=4
	// N=5
	// 1, 2, 3, 4, 5
	// (1,2,3,4), (2,3,4,5), (5,1): NG because of ((1,2,3,4),(2,3,4,5)) violates the condition 1
	// (1,2),(2,3),(3,4),(4,5),(5,1): NG because of ((1,2),(3,4)) violates the condition 2
	// (1,2,3), (1,4,5), (2,4): NG
	// (1,2,3), (1,4), (2,4), (3,5): NG
	// N=6
	// (1,2,3), (1,4,5), (2,4,6), (3,5,6): OK
	// Nは3の倍数だろう...?
	// N=8
	// (1,2,3,4),(2,5,6,7),(3,5,...?
	// N=9
	// (1,2,3,4), (1,5,6,7), (2,5,8,9), (3,6,8,9):NG
	// 
	// the condition 2 => each subset must have the size of ge N/2
	// 
	// 2つのK個の部分集合の共通部分の要素は1つ
	// 1~NはK個の部分集合にそれぞれ2回含まれる
	// => KC2 = K(K-1)/2 個の共通部分は、重複含めてK(K-1)/2個の要素であり、同時にN個の要素である。
	// N = K(K-1)/2  
	// これが成立する必要条件
	// Nが奇数 -> 誤り
	// 2N = K(K-1) なるKが存在するか.
	// N=3ならば、K=3
	// N=5ならばなし
	// N=7 => なし
	// N=9 => なし
	// N=11 => なし
	// N=13 => なし
	// N=15 => K=6 
	// N=17 => なし
	//
	// N=15の場合
	// (1,2,3,4,5), (1,6,7,8,9), (2,6,10,11,12), (3,7,10,13,14), (4,8,11,13,15), (5,9,12,14,15)
	// 
	// K^2 - K - 2N = 0
	// (K-1/2)^2 -2N - 1/4 = 0
	double K0 = 1.0/2.0 + sqrt(2*N + 1./4.); 
	int K = floor(K0);
	if (!(K*(K-1) == 2*N)) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	cout << K << endl;
	// K個のsubsetを作る
	// 各subsetのサイズはK-1. (K(K-1)が2Nとなるようになっている)
	// 後は走査して決定する 
	vector<int> t_0;
	vector<vector<int> > subsets(K+1,t_0);
	int pivot = 1;
	int offset = 1; // これの導入で解決した...と思ったがまだダメ
	// K subsets whose sizes are K-1
	for (int i=1; i<=N; ++i) {
		int ii = offset + pivot;
		if (ii > K) {
			pivot++;
			offset = 1;
			ii = offset + pivot;
		}
		subsets[pivot].push_back(i);
		subsets[ii].push_back(i);
		offset++;
	}
	for (int k=1; k<=K; ++k) {
		cout << K-1 << " ";
		for (int l=0;l<subsets[k].size();++l) {
			cout << subsets[k][l] << " ";
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 2304
#include <iostream>
#include <algorithm>

using namespace std;

const int INF = 1000000000;

int c, n, m, s, d;
int visited[100][11];
int edge[100][100];


void dfs(int p, int rem, int cost){
   if(visited[p][rem] < cost) return;
   visited[p][rem] = cost;
   if(p == d) return;
   for(int i=0;i<n;i++){
      if(edge[p][i] == INF) continue;
      if(rem > 0 ) dfs(i, rem-1, cost+(edge[p][i]/2));
      dfs(i, rem, cost+edge[p][i]);
   }
}

main(){
   while(cin >> c >> n >> m >> s >> d && (c || n || m || s || d)){
      fill(edge[0], edge[100], INF);
      fill(visited[0], visited[100], INF);
      --s; --d;
      for(int i=0;i<m;i++){
         int a, b, f;
         cin >> a >> b >> f;
         --a; --b;
         edge[a][b] = edge[b][a] = f;
      }
      dfs(s, c, 0);
      int ans = INF;
      for(int i=0;i<c;i++){
         ans = min(ans, visited[d][i]);
      }
      cout << ans << endl;
   }
   return 0;
}

Measured memory_bytes: 912
def main():
	S = input()
	ac = S[0] == "A"
	ac = ac and S[2:-1].count("C") == 1
	ac = ac and S.replace("A", "").replace("C", "") == S.replace("A", "").replace("C", "").lower()

	if ac:
		print("AC")
	else:
		print("WA")

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
using namespace std;
using namespace __gnu_pbds;
using ll = int64_t;
using ld = long double;
using ull = uint64_t;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

ll a, b;

ll anw[100][100];

int main() {
  ios::sync_with_stdio(0);
  cout.precision(10);

  cin >> a >> b;

  for (int i = 0; i < 50; i++) {
    for (int j = 0; j < 100; j++)
      anw[i][j] = 1;
  }

  a--, b--;

  for (int i = 0; i < 50; i+=2) {
    for (int j = 0; j < 100; j+=2) {
      if (a == 0) break;
      anw[i][j] = 0;
      a--;
    }
  }
  for (int i = 52; i < 100; i+=2) {
    for (int j = 0; j < 100; j+=2) {
      if (b == 0) break;
      anw[i][j] = 1;
      b--;
    }
  }


  cout << "100 100" << endl;
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j < 100; j++) {
      if (anw[i][j]) cout << '#';
      else cout << '.';
    }
    cout << endl;
  }
}

Measured memory_bytes: 384
n = int(input())
a = list(map(int, input().split()))
q = int(input())

nums = [0]*100001
for i in a:
  nums[i] += 1

ans = sum(a)
for _ in range(q):
  b,c = map(int, input().split())
  ans -= b * nums[b]
  ans += c * nums[b]
  nums[c] += nums[b]
  nums[b] = 0
  print(ans)


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

int main() {
    int N;
    cin >> N;
    vector <int> a(3 * N);
    for(int i = 0; i < 3 * N; i++){
        cin >> a[i];
    } 
    ll total = 0;
    sort(a.begin() , a.end());
    for(int i = 1; i <= N; i++){
        total += a.at(3 * N - i * 2);
    }
    cout << total << endl;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
char s[1100],t[1100];
int main(){
	scanf("%s %s",s,t);
	int ans = 10000;
	int cont;
	int a=strlen(s),b=strlen(t);
	for(int i = 0; i < a-b+1; i++){
		cont = 0;
		for(int j = 0; j < b; j++)
			if(s[i+j] != t[j])
				cont++;
		ans = min(ans,cont);
	}
	printf("%d\n", ans);

	return 0;
}

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

int main() {

    int  n;
    cin >> n;

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

    sort(a.rbegin(), a.rend());

    int Alice = 0;
    int Bob = 0;

    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) Alice += a[i];
        else Bob += a[i]; 
    }

    cout << Alice - Bob << endl;

    return 0;  

}


Measured memory_bytes: 256
S = input()
T = input()

from collections import deque

if T in S:
    print(0)

else:
    n = len(S) - len(T)
    lst = []
    for x in range(n + 1):
        s = S[x:(len(T) + x)]
        ds = deque(s)
        dt = deque(T)
        count = 0
        while ds:
            if ds.popleft() == dt.popleft():
                count += 1
        lst.append(count)
    print(len(T) - max(lst))

Measured memory_bytes: 9196
#include<stdio.h>

int main(void)
{
        int a[3],b[3],c[10],i = 0;

        for(i = 0;i < 3;i++) {
                scanf("%d %d",&a[i],&b[i]);
        }

        i = 0;
        for(i = 0;i < 10;i++) {
                c[i] = 0;
        }

        i = 0;
        for(i = 0;i < 3;i++) {
                c[a[i]]++;
                c[b[i]]++;

                if(c[a[i]] > 2 || c[b[i]] > 2) {
                        printf("NO\n");
                        break;
                }

                if(i == 2) {
                        printf("YES\n");
                        break;
                }

        }

        return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define reps(i,x) for(ll i=1;i<=(ll)(x);i++)
#define rrep(i,x) for(ll i=((ll)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(ll)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int p[10],c[10];
int main() {
  int n;
  cin >> n;
  int e = n / 4 + 2;
  rep(i, e){
    rep(j, e){
      rep(k, e){
        if(4*i+ j*7+k*11 == n){
          cout << "Yes" << endl; 
          return 0;
        }
      }
    }
  }
  cout << "No" << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int MOD = 1e9 + 7;

ll N,M,K,H,W;

int main(){
    string str;
    cin >> str >> K;
    int n = str.length();
    int dp[2][4][n+1];
    // 1 : obviously smaller than N
    for(int i = 0; i <= n; ++i){
      	for(int j = 0; j <= 1; ++j){
              for(int k= 0; k < 4; ++k){
                dp[j][k][i] = 0;
              }
        }
    }
    dp[0][0][0] = 1;
    for(int i = 1; i <= n; ++i){
        int num = str[i-1]- '0'; 
        dp[1][0][i] = 1;
        for(int k = 1; k < 4; ++k){

            dp[1][k][i] += 9 * dp[1][k-1][i-1] + dp[1][k][i-1];

            if(num == 0) dp[0][k][i] = dp[0][k][i-1];

            else{
                dp[0][k][i] = dp[0][k-1][i-1];
                dp[1][k][i] += dp[0][k][i-1] + dp[0][k-1][i-1] * (num-1);
            }

        }
    }
    cout << dp[0][K][n] + dp[1][K][n];
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

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

int main()
{
	ll H,W;
	cin >> H >> W;

	ll ans = INF*INF;
	ll a=0,b=0,c=0;

	for(int h = 0; h <= H; h++){
		if(W%2==0) a = h*W/2,b = h*W/2;
		else a = h*(W-1)/2,b = h*(W+1)/2;
		c = W*(H-h);

		ll s_max = max(max(a,b),c);
		ll s_min = min(min(a,b),c);
		if(s_max - s_min < ans) ans = s_max - s_min;

		a = h*W;
		if((H-h)%2==0) b = (H-h)/2 * W,c = b;
		else b = (H-h-1)/2 * W,c = (H-h+1)/2 * W;

		s_max = max(max(a,b),c);
		s_min = min(min(a,b),c);
		if(s_max - s_min < ans) ans = s_max - s_min;
	}

	for(int w = 0; w <= W; w++){
		if(H%2==0) a = H/2*w, b = a;
		else a = (H-1)/2*w, b = (H+1)/2*w;
		c = H*(W-w);

		ll s_max = max(max(a,b),c);
		ll s_min = min(min(a,b),c);
		if(s_max - s_min < ans) ans = s_max - s_min;

		a = w*H;
		if((W-w)%2==0) b = H*(W-w)/2 , c = b;
		else b = H*(W-w-1)/2, c = H*(W-w+1)/2;
		s_max = max(max(a,b),c);
		s_min = min(min(a,b),c);
		if(s_max - s_min < ans) ans = s_max - s_min;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int n;
	cin >> n;
	string s[n];
	map<string, int>m;
	zip(i, 0, n)
	{
		cin >> s[i];
		m[s[i]]++;
	}
	int lar = 0;
	zip(i, 0, n)
	{
		lar = max(lar, m[s[i]]);
	}
//vector<string>v;

	set<string>v;
	zip(i, 0, n)
	{
		if (m[s[i]] == lar)
		{
			v.insert(s[i]);
		}
	}
	for (string x : v)
	{
		cout << x << en;
	}



	return 0;
}



Measured memory_bytes: 34816
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    char c;
    cin >> c;

    cout << (char)(c + 1) << "\n";
    return 0;
}

Measured memory_bytes: 760