akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
// 293206GT
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <unordered_set>
#include <stack>
#include <string>
#include<algorithm>
#include <random>
#include <bitset>
#include <chrono>

typedef long long ll;
#define int ll
using namespace std;
#define put(a) cout << (a) << '\n'
#define sqr(x) ((x) * (x))
typedef pair<int, int> pii;
typedef long double ld;
typedef pair<ld, ld> pld;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<pii> vpii;
#define rep(x, y, a) for (int x = (y); x < (int)(a); ++x)
#define all(a) a.begin(), a.end()
#define chkmax(a, b) a = max(a, (b))
#define chkmin(a, b) a = min(a, (b))
#define prev asasdasd
#define next aasdasda
#define left asdasdasdasd
#define right asnabsdkasdl
#define rank asdasdknlasd
#define move asdasdas
#define fname "parray"
#define fin fname".in"
#define fout fname".out"
#define files freopen(fin, "r", stdin);freopen(fout, "w", stdout);
namespace IO {

    template<class A, class B>
    ostream &operator<<(ostream &out, vector<pair<A, B>> a);

    template<class A>
    ostream &operator<<(ostream &out, vector<A> a);

    template<class A, class B>
    ostream &operator<<(ostream &out, pair<A, B> a) {
        out << a.first << " " << a.second;
        return out;
    }

    template<class A, class B>
    ostream &operator<<(ostream &out, vector<pair<A, B>> a) {
        for (pair<A, B> x: a)
            out << x.first << " " << x.second << '\n';
        return out;
    }

    template<class A>
    ostream &operator<<(ostream &out, vector<A> a) {
        for (A x: a) out << x << ' ';
        return out;
    }

    template<class A, class B>
    istream &operator>>(istream &in, pair<A, B> &a) {
        in >> a.first >> a.second;
        return in;
    }

    template<class A>
    istream &operator>>(istream &in, vector<A> &a) {
        for (A &x: a) in >> x;
        return in;
    }
}
using namespace IO;


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

void solve() {
    int k;
    cin >> k;
    if (k % 2 == 0) {
        put(-1);
        return;
    }
    int cur = 0;
    rep(it, 1, 1e6 + 12) {
        cur *= 10;
        cur += 7;
        cur %= k;
        if (cur == 0) {
            put(it);
            return;
        }
    }
    put(-1);
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(30);
//    freopen("input.txt", "r", stdin);
//    files
    int q = 1;
//    cin >> q;
    while (q--) solve();
}



Measured memory_bytes: 3224
n, k, c = map(int, input().split())
s = input()
# record positions of included work days for leftmost and rightmost solutions
leftmost_solution = list()
rightmost_solution = list()
timer = -1
for idx in range(n):
  if s[idx] == "o" and timer <= 0:
    leftmost_solution.append(idx)
    if len(leftmost_solution) == k:
      break
    timer = c+1
  timer -= 1
timer = -1
for idx in range(n-1, -1, -1):
  if s[idx] == "o" and timer <= 0:
    rightmost_solution.append(idx)
    if len(rightmost_solution) == k:
      break
    timer = c+1
  timer -= 1
rightmost_solution.reverse()
for left, right in zip(leftmost_solution, rightmost_solution):
  if left == right:
    print(left+1)

Measured memory_bytes: 83992
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        final int M = scan.nextInt();
        final int D = scan.nextInt();
        scan.close();
        int result = 0;
        for(int i = 1; i <= M; i++){
            for(int j = 22; j <= D; j++){
                if(j % 10 >= 2 && j / 10 >= 2 && 
                    ((j % 10) * (j / 10) == i)){
                        result++;
           }
            }
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 21716
from sys import stdin
from collections import deque
H, W = map(int, stdin.readline().split())
C = [list(map(int, stdin.readline().split())) for i in range(H)]
prev = [0] * W
def height(C):
    global prev
    P = []
    for i in range(W):
        if C[-1][i] == 1:
            p = 0
        else:
            p = prev[i] + 1
        P.append(p)
    prev = P[:]
    return P
def square(C):
    P = height(C)
    G = deque()
    L = deque()
    for i, v in enumerate(P):
        if not L or v > L[-1][1]:
            L.append((i, v))
        elif v < L[-1][1]:
            k = i - 1
            while L and v < L[-1][1]:
                a = L.pop()
                G.append((k - a[0] + 1) * a[1])
            L.append((a[0], v))
    len_P = len(P)
    while L:
        a = L.pop()
        G.append((len_P - a[0]) * a[1])
    return max(G)
print(max([square(C[:i + 1]) for i in range(H)]))

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

using namespace std;

int main() 
{
string s1,s2;
cin>>s1;
cin>>s2;

int cnt=0;

for(int i=0;i<s1.size();i++)
{
	if(s1[i]==s2[i])
	{
		cnt+=1;
	}
}
cout<<cnt;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=5010;
const int mod=1e9+7;
int dp[maxn][maxn][2],f[maxn][2],pair_way[maxn],size[maxn];
vector<int> g[maxn];
void dfs(int u,int fa){
	size[u]=1;
	dp[u][1][0]=1;
	for(int i=0;i<(int)g[u].size();i++){
		int v=g[u][i];
		if(v==fa) continue;
		dfs(v,u);
	}
	for(int i=0;i<(int)g[u].size();i++){
		int v=g[u][i];
		if(v==fa) continue;
		for(int i=1;i<=size[u]+size[v];i++)
			f[i][0]=f[i][1]=0;
		for(int i=1;i<=size[u];i++){
			for(int j=1;j<=size[v];j++){
				for(int s=0;s<2;s++){
					for(int ss=0;ss<2;ss++){
						f[i+j][(s+ss)&1]=(f[i+j][(s+ss)&1]+(ll)dp[u][i][s]*dp[v][j][ss]%mod)%mod;
						f[i][(s+ss+1)&1]=(f[i][(s+ss+1)&1]+(ll)dp[u][i][s]*dp[v][j][ss]%mod*pair_way[j]%mod)%mod;
					}
				}
			}
		}
		size[u]+=size[v];
		for(int i=1;i<=size[u];i++)
			dp[u][i][0]=f[i][0],dp[u][i][1]=f[i][1];
	}
}
int32_t main(){
	int n,u,v;
	scanf("%lld",&n);
	for(int i=1;i<n;i++){
		scanf("%lld%lld",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	pair_way[0]=pair_way[2]=1;
	for(int i=4;i<=n;i+=2)
		pair_way[i]=(pair_way[i-2]+(ll)pair_way[i-4]*(i-2)%mod*(i-3)%mod)%mod;
	dfs(1,-1);
	int ans=0;
	for(int i=1;i<=n;i++){
		ans=(ans+dp[1][i][0]*pair_way[i]%mod)%mod;
		ans=(ans+mod-dp[1][i][1]*pair_way[i]%mod)%mod;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 391552
#include <iostream>
#define ll long long int
#define N 200009

using namespace std;

int n;
ll a[N];

int main()
{
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>> n;
    for(int i=1; i<=n; i++){
        cin >> a[i];
    }
    ll sum = 0;
    for(int i=2;i<=n;i++){
        if(a[i-1]>a[i]){
            sum += a[i-1] -a [i];
            a[i] += a[i-1] -a [i];
        }
    }
    cout<< sum << endl;
    return 0;
}


Measured memory_bytes: 5172
import sys

dictionary = {}

for line in sys.stdin:
    line = line[:-1]

    word, page = line.split(" ")
    page = int(page)

    if word in dictionary:
        dictionary[word].append(page)
    else:
        dictionary[word] = [page]

keys = list(dictionary)
keys.sort()

output = []

for key in keys:
    output.append(key)
    pages = sorted(dictionary[key])
    pages = [str(item) for item in pages]
    pages = " ".join(pages)
    output.append(pages)

print("\n".join(output))



Measured memory_bytes: 5608
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#define INF 0x3f3f3f3f
#define ll long long
#define N 500010
using namespace std;
ll a[N];
int main()
{
	int n,k,t;
	cin>>n>>k;
     t=n%k;
     
     if(t==0)
     cout<<t<<endl;
     else
    cout<<1<<endl;
	
	

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <cmath>
#include <map>
#include <algorithm>
#include <stack>
#include <cstring>
 
#define ll long long
#define MP make_pair
#define PB push_back
#define P push
#define f first
#define se second
#define S size()
#define B begin()
#define E end()
#define rB rbegin()
#define rE rend()
#define PI acos(-1)

 
const int N = 1e5 + 100;
const int M = 1e6 + 100;
const ll oo = 1e18;
 
ll n, m, k, t, q, h, a, b, d, c, e, w, x, y, z;
using namespace std;

char gh[1001][1001]; 
ll dp[3000][3000];

const ll MOD = 1e9 + 7;

int main() {

	cin >> n >> m;
	dp[1][1] = 1;

	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++) {
			cin >> gh[i][j];
			if(gh[i][j] == '#' || (i == 1 && j == 1)) continue;

			dp[i][j] = (dp[i - 1][j] % MOD + dp[i][j - 1] % MOD) % MOD;
		}
	}


	cout << dp[n][m];



    return 0;
}




Measured memory_bytes: 24832
#include <bits/stdc++.h>
using namespace std;
string s,t,tem;
long long tms=0,lft=0;
int main(){
	long long i,pos1,pos2;
	cin>>s>>t;
	lft=s.find(t[0]);
	if(lft==-1)
	{
		cout<<-1<<endl;
		return 0;
	}
	for(i=1;i<t.size();i++)
	{
		tem=s.substr(lft+1);
		pos1=tem.find(t[i]);
		pos2=s.find(t[i]);
		if(pos1!=-1)
		{
			lft+=pos1+1;
		}
		else if(pos2==-1)
		{
			cout<<-1<<endl;
			return 0;
		}
		else
		{
			tms++;
			lft=pos2;
		}
	}
	cout<<tms*s.size()+lft+1<<endl;
	return 0;
}

Measured memory_bytes: 640
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int k, x;
    cin >> k >> x;
    if (k * 500 >= x) cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
n,x,y = map(int, input().split())
x -= 1
y -= 1

ans = [0] * (n-1)

for j in range(n):
  for i in range(j):
    ans[min(j-i, abs(x-i)+1+abs(j-y)) - 1] += 1

print("\n".join([str(d) for d in ans]))

Measured memory_bytes: 3188
/* Stay hungry, stay foolish. */
/* Copyright by HenryLi */
#include<iostream>
#include<algorithm>
#include<queue>
#include<string>
#include<map>
#include<vector>
#include<set>
#include<sstream>
#include<stack>
#include<ctime>
#include<cmath>
#include<cctype>
#include<climits>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<iomanip>
#include<bitset>
#include<complex>
using namespace std;
template <class _T> inline void read(_T &_x) {
	int _t; bool _flag=false;
	while((_t=getchar())!='-'&&(_t<'0'||_t>'9')) ;
	if(_t=='-') _flag=true,_t=getchar(); _x=_t-'0';
	while((_t=getchar())>='0'&&_t<='9') _x=_x*10+_t-'0';
	if(_flag) _x=-_x;
}
typedef long long LL;
int n, a, b;
int main() {
	//freopen("A.in","r",stdin);
	//freopen("A.out","w",stdout);
	read(n), read(a), read(b);
	if ((b - a) & 1) puts("Borys");
	else puts("Alice");
	return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;
using pl = pair<ll,ll>;
signed main(){
	ll n,p; cin >> n >> p;
	vl vec(n); rep(i,0,n) cin >> vec[i];
	vvl dp(55,vl(10000));
	dp[0][0]=1;
	rep(i,0,n){
		rep(j,0,10000){
			dp[i+1][j]=dp[i][j];
			if(j-vec[i]>=0)dp[i+1][j]+=dp[i][j-vec[i]];
		}
	}
	ll ans=0;
	rep(i,0,10000){
		if(i%2==p){
			ans+=dp[n][i];
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 7692
from collections import Counter

n = int(input())
a = list(map(int, input().split()))

s = sorted(Counter(a).items(), reverse = True)


count = 0
ans = 0
for i, j in s:
        if count == 2:
            break
        if count == 1 and j >= 2:
            ans *= i
            count += 1
        if count == 0:
            if j >= 4:
                ans = i**2
                count += 2
            elif j >= 2:
                ans = i
                count += 1
print(ans)

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

int main()
{
    std::string s;
    std::cin >> s;

    if (s[2] == s[3] && s[4] == s[5])
        std::cout << "Yes" << std::endl;
    else
        std::cout << "No" << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MAX 1000000000
#define fast_read ios::sync_with_stdio(0);cin.tie(0);
using namespace std;
int main()
{
    fast_read;
    ll n;
    cin>>n;
    vector<ll>v;
    for (int i = 1;i*i<=MAX;i++)v.push_back(i*i);
    for (int i = 0;i<v.size();i++) {
        if (i == v.size() - 1)cout<<v[i]<<endl;
        else if (v[i] <= n && v[i + 1] > n){
            cout<<v[i]<<endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main() {
	int a,b,c,d;
	scanf("%d%d%d%d", &a, &b, &c, &d);

	if (a > c) c = a;
	if (b > d) b = d;
	if (c < b) printf("%d\n", b-c);
	else printf("0\n");
	return 0;
}

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


int main(){
    unsigned n; cin >> n;
    cout << n << ":";
    for(unsigned i = 2;i * i <= n; i++){
        while(n % i == 0){
            cout << " " << i;
            n/=i;
        }
    }
    if(n != 1) cout << " " << n;
    cout << endl;
    return 0;
}



Measured memory_bytes: 3088
from collections import deque

from heapq import heappush, heappop


def main():
    K = int(input())

    q = []

    for i in range(1, 10):
        heappush(q, i)

    while True:
        v = heappop(q)
        K -= 1
        if K == 0:
            print(v)
            exit()
        u = v % 10
        nv = v * 10 + u

        heappush(q, nv)
        if u == 0:
            heappush(q, nv + 1)
        elif u == 9:
            heappush(q, nv - 1)
        else:
            heappush(q, nv - 1)
            heappush(q, nv + 1)


main()


Measured memory_bytes: 12004
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();;
		int c;
		if(a<=b&&a+w>=b) {
			c=0;
		}else if(a<=b+w&&a+w>=b+w) {
			c=0;
		}
		else if(a+w<b+w) c=b-(a+w);
		else c=b-a+w;
		if(c<0)c=-c;
		System.out.println(c);
	}
}

Measured memory_bytes: 23892
import java.util.Arrays;
import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] ar = new long[n];
        for (int i = 0; i < ar.length; i++) {
            ar[i] = sc.nextLong();
        }
        Arrays.sort(ar);
        long curr = ar[0];
        int start = 0;
        for(int i = 1; i < n; i++){
            if(2 * curr >= ar[i])
                curr += ar[i];
            else{
                start = i;
                curr += ar[i];
            }
        }
        System.out.println(n - start);
    }
}


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

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

    vector<int> p(n);
    int x_exist = false;
    for(int i = 0; i < n; i++) {
        cin >> p[i]; 
        if(p[i] == x) {
            x_exist = true;
        }
    }
    if(x_exist == false) {
        cout << x << endl;
        return 0;
    }
    sort(p.begin(), p.end());

    int index_x;
    for(int i = 0; i < n; i++) {
        if(p[i] == x) {
            index_x = i;
        }
    }
    int d = 1;
    int i = index_x;
    int ans;
    while(true) {
        if((i - d < 0)) {
            ans = x - d;
            break;
        }
        if(p[i-d] == x - d) {
        } else {
            ans = x - d;
            break;
        }
        if((i + d > n)) {
            ans = x + d;
            break;
        }
        if(p[i+d] == x + d) {
        } else {
            ans = x + d;
            break;
        }
        d++;
    }
    cout << ans << endl;
}



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

using namespace std ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	int n ;
	cin>>n ;
	vector< pair<long long , int> >vp ;
	long long ans[n+2] ;
	memset(ans , 0 , sizeof(ans)) ;
	for(int i = 0 ; i < n ; ++i)
	{
		long long x ;
		cin>>x ;
		vp.push_back({x , i}) ;
	}
	vp.push_back({0 , n}) ;
	sort(vp.rbegin() , vp.rend()) ;
	long long prv = -1 ;
	int idx = n ;
	for(int i = 0 ; i < vp.size() ; ++i)
	{
		if(vp[i].first != prv)
		{
			ans[idx] += (prv - vp[i].first) * i ;
			prv = vp[i].first ;
			idx = min(idx , vp[i].second) ;
		}
		else
			idx = min(idx , vp[i].second) ;
	}
	for(int i = 0 ; i < n ; ++i)
		cout<<ans[i]<<"\n";
	return 0 ;
}

Measured memory_bytes: 3568
N = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)

killCount = 0
(0...N).each do |i|
  enableKill = b[i]

  if a[i] <= enableKill
    killCount += a[i]
    remain = enableKill - a[i]
    a[i] = 0

    if a[i+1] <= remain
      killCount += a[i+1]
      a[i+1] = 0
    else
      killCount += remain
      a[i+1] -= remain
    end

  else 
    killCount += enableKill
  end
end

puts killCount


Measured memory_bytes: 26828
// 今回でいえば、A問題の方が実装難しいです･･･。
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
      // 準備
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      String s;

      int[] ans = new int[4];

      for(int i=0; i<n; ++i) {
        s = sc.next();
        if("AC".equals(s))
          ans[0]++;
        if("WA".equals(s))
          ans[1]++;
        if("TLE".equals(s))
          ans[2]++;
        if("RE".equals(s))
          ans[3]++;
      }

      System.out.println("AC x " + ans[0]);
      System.out.println("WA x " + ans[1]);
      System.out.println("TLE x " + ans[2]);
      System.out.println("RE x " + ans[3]);
    }
}

Measured memory_bytes: 58380
N, K = map(int, input().split())
Ans = 0

if K == 0:
    print(N**2)
else:
    def Mods(i, N, K): #iで割った余りがK以上のN以下の数
        lim = N//i
        pattern = i - K
        total = lim * pattern
        if N - i * lim < K:
            return total
        else:
            extra = N - i * lim - K + 1
            return total + extra

    for i in range(K+1, N+1):
        Ans += Mods(i, N, K)
    print(Ans)

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

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

    set<int> seen;
    seen.insert(0);
    int count = 0;
    for (int i = 0; i<n; i++)
    {
        int x; cin>>x;
        if (seen.find(x-1) != seen.end() and seen.find(x) == seen.end())
        {
            seen.insert(x);
            count++;
        }
    }

    if (count == 0)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<n-count<<endl;
    }
}

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

long long n;
string s;
set<string> st;
long long dp[200015][2] = {0};

long long solve();

int main() {
  cin >> s;

  cout << solve() << endl;
  return 0;
}

long long solve() {
  n = s.size();
  dp[1][0] = 1;
  dp[2][1] = 1;
  for(int i = 1; i < n; ++i) {
    if(s[i] != s[i - 1])
      dp[i + 1][0] = max(dp[i][0], dp[i][1]) + 1;
    else
      dp[i + 1][0] = dp[i][1] + 1;
    dp[i + 1][1] = dp[i - 1][0] + 1;
    if(i < 3) continue;
    string x, y;
    x = s[i - 3] + s[i - 2];
    y = s[i - 1] + s[i];
    if(x != y)
      dp[i + 1][1] = max(dp[i + 1][1], dp[i - 1][1] + 1);
  }
  return max(dp[n][0], dp[n][1]);
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;
 
int main(){
  using namespace std;
  long long n, k;
  cin>>n>>k;
  n %= k;
  long long ans = min(n, k - n);
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int f(int x) {
    int y = 0;
    for (int i = 8; i >= 0; i--) {
        y += x / (int)pow(10, i);
        x = x % (int)pow(10, i);
    }
    return y;
}

int main(void){
    int n;
    cin >> n;
    cout << (n % f(n) == 0 ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<iostream>
#include<map>
#include<string>

#define maxn 3000005
#define MOD 998244353
#define inv2 499122177

using namespace std;

inline int getint()
{
	int num=0,flag=1;char c;
	while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;
	while(c>='0'&&c<='9')num=num*10+c-48,c=getchar();
	return num*flag;
}

int n,N;
int E[maxn],P[maxn],I[maxn];

inline int ksm(int num,int k)
{
	int ret=1;
	for(;k;k>>=1,num=1ll*num*num%MOD)if(k&1)ret=1ll*ret*num%MOD;
	return ret;
}
inline void FWT_xor(int *a,int opt,int N)
{
	for(int i=1;i<N;i<<=1)for(int j=0;j<N;j+=(i<<1))
		for(int k=0;k<i;k++)
		{
			int x=a[j+k],y=a[i+j+k];
			a[j+k]=(x+y)%MOD,a[i+j+k]=(x-y+MOD)%MOD;
			if(!~opt)a[j+k]=1ll*a[j+k]*inv2%MOD,a[i+j+k]=1ll*a[i+j+k]*inv2%MOD;
		}
}

int main()
{
	n=getint(),N=1<<n;int s=0;
	for(int i=0;i<N;i++)s+=P[i]=getint(),s%=MOD;
	s=ksm(s,MOD-2);
	for(int i=0;i<N;i++)P[i]=1ll*P[i]*s%MOD;P[0]--;
	I[0]=N-1,s=0;
	for(int i=1;i<N;i++)I[i]=MOD-1;
	FWT_xor(P,1,N),FWT_xor(I,1,N);
	for(int i=1;i<N;i++)E[i]=1ll*I[i]*ksm(P[i],MOD-2)%MOD,s=(s+E[i])%MOD;
	E[0]=MOD-s;
	FWT_xor(E,-1,N);
	for(int i=0;i<N;i++)printf("%d\n",E[i]);
}

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

int main()
{
	int n, q;
	string s;
	cin >> n >> q >> s;
	vector<char> ts(q), ds(q);
	for (int i = 0; i < q; i++)
	{
		cin >> ts[i] >> ds[i];
	}

	int ans = n;

	{
		int l = -1, r = n;
		while (1 < r - l)
		{
			int mid = (l + r) / 2;

			bool f = false;
			int pos = mid;

			for (int i = 0; i < q; i++)
			{
				if (s[pos] == ts[i])
				{
					if (ds[i] == 'L')
					{
						pos--;
						if (pos < 0)
						{
							f = true;
							break;
						}
					}
					else
					{
						pos++;
						if (n <= pos)
						{
							break;
						}
					}
				}
			}

			(f ? l : r) = mid;
		}
		ans -= l + 1;
	}

	{
		int l = -1, r = n;
		while (1 < r - l)
		{
			int mid = (l + r) / 2;

			bool f = false;
			int pos = mid;

			for (int i = 0; i < q; i++)
			{
				if (s[pos] == ts[i])
				{
					if (ds[i] == 'L')
					{
						pos--;
						if (pos < 0)
						{
							break;
						}
					}
					else
					{
						pos++;
						if (n <= pos)
						{
							f = true;
							break;
						}
					}
				}
			}

			(f ? r : l) = mid;
		}

		ans -= n - r;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <cctype>
#include <fstream>

using namespace std;

#define ll long long
#define MOD 1000000007
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define du(x) cout<<#x<<'='<<x<<endl
#define du2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define du3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf());

vector<pair<int, int>>A;//文字、個数

int main() {
    int N, K;
    string S;
    cin >> N >> K >> S;
    //個数を入れる
    int cnt = 0;
    rep(i, N) {
        if (A.empty() || A.back().first != S[i]) {
            A.emplace_back(S[i], 1);
        }
        else {
            A.back().second++;
        }
    }


    int ret = 0, ptr = 0, sum = 0, all = 0;
    for (auto &p : A) {
        while (ptr < A.size() && sum + (A[ptr].first == '0') <= K) {
            if (A[ptr].first == '0')sum++;//0であれば+1
            all += A[ptr].second;//個数を足す
            ptr++;//サイズの管理
        }
        ret = max(ret, all);
        if (p.first == '0')sum--;
        all -= p.second;
    }


    cout << ret << endl;
}


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

 struct node{
   struct node *left, *right, *me;
  int key;
  bool operator<( const node& right) const {
    return key < right.key;
  }
   bool operator>( const node& right) const {
    return key > right.key;
  }
};

string s;

int dfs(node temp, int depth){
  if(temp.right == NULL && temp.left == NULL) return depth*temp.key;
  else return dfs(*(temp.right),depth+1)+dfs(*(temp.left),depth+1);
}

int solve(){
  int size = s.size(), r[30] = {}, count = 0, num = 0;
  priority_queue<node,vector<node>,greater<node> > Q;
  
  for(int i = 0; i < size; i++){
    r[s[i]-'a']++;
  }

  for(int i = 0; i < 26; i++){
    if(r[i]){
      node *temp = new node;
      temp->key = r[i];
      temp->right = NULL;
      temp->left = NULL;
      temp->me = temp;
      Q.push(*temp);
      count++;
      num = r[i];
    }
  }

  if(count == 1) return num;
  
  while(Q.size() >= 2){
    node temp1 = Q.top(); Q.pop();
    node temp2 = Q.top(); Q.pop();
    node *temp = new node;
    temp->key = temp1.key+temp2.key;
    temp->right = temp1.me;
    temp->left = temp2.me;
    temp->me = temp;
    
    Q.push(*temp);
  }
  return dfs(Q.top(),0);
}

int main(){
  
  cin>>s;


  cout<<solve()<<endl;
  
  return 0;
}



Measured memory_bytes: 3340
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL INF = ~0ULL >> 1;
const int mul[3] = {2, 3, 5};
int cost[5];
unordered_map<LL, LL> Hash;
LL dfs(LL N) {
	auto it = Hash.find(N);
	if(it != Hash.end())
		return it -> second;
	LL ret = INF;
	for(int i = 0; i < 3; ++i) {
		LL M = N / mul[i], R = N % mul[i];
		ret = min(ret, dfs(M) + cost[i] + R * cost[3]);
		if(R > 0 && M + 1 < N)
			ret = min(ret, dfs(M + 1) + cost[i] + (mul[i] - R) * cost[3]);
	}
	if(ret / cost[3] >= N)
		ret = min(ret, N * cost[3]);
	return Hash[N] = ret;
}
int main() {
	int T = 1;
	scanf("%d", &T);
	for(int Case = 1; Case <= T; ++Case) {
		LL N;
		scanf("%lld", &N);
		for(int i = 0; i < 4; ++i)
			scanf("%d", cost + i);
		Hash.clear();
		Hash[0] = 0;
		Hash[1] = cost[3];
		printf("%lld\n", dfs(N));
	}
	return 0;
}

Measured memory_bytes: 4204
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  long long ans=1;
  cin >> N >> M;
  if (abs(N-M) >= 2){
    cout << 0 << endl;
  }else if (abs(N-M) == 1){
    for (int i = 1; i < min(N,M)+1; i++){
      ans *= i;
      ans = ans % ((long)pow(10,9.0)+7);
    }
    ans = ans * ans;
    ans = ans % ((long)pow(10,9.0)+7);
    ans = ans * max(N,M);
    ans = ans % ((long)pow(10,9.0)+7);
    cout << ans << endl;
  }else if (abs(N-M) == 0){
    for (int i = 1; i < N+1; i++){
      ans *= i;
      ans = ans % ((long)pow(10,9.0)+7);
    }
    ans = ans * ans * 2;
    ans = ans % ((long)pow(10,9.0)+7);
    cout << ans << endl;
  }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
//debug
#ifdef grief
#define debug(...) do{\
	fprintf(stderr , "%s - %d : (%s) = " , __PRETTY_FUNCTION__ , __LINE__ , #__VA_ARGS__ );\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> 				void _DO(I&&x){	cerr<<x<<endl;	}
template<typename I,typename...T>	void _DO(I&&x,T&&...tail){	cerr<<x<<" , ";	_DO(tail...);	}
template<typename _a,typename _b> 	ostream& operator << (ostream &_s,const pair<_a,_b> &_p)
{	return _s<<'('<<_p.first<<','<<_p.second<<')';	}
#define IOS
#else
#define debug(...)
#define IOS do{ios_base::sync_with_stdio(0); cin.tie(0);}while(0);
#endif
//type
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef priority_queue<pll,vector<pll>,greater<pll> > heap;
//macro
#define SZ(x) ((ll)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define stp setprecision(30)<<fixed
const ll INF=0x3f3f3f3f3f3f3f3f;
const int NF=0x3f3f3f3f;
const ll MAX=1e5+5,Mlg=__lg(MAX)+2;
const ll MOD=1e9+7;
// ready~ go!
// let's coding and have fun!
// I can't solve this problem!
int dis[20][20];
int main(){
	IOS
	int h,w;	cin>>h>>w;	h*=w;
	for(int i=0;i<10;i++)	for(int j=0;j<10;j++)	cin>>dis[i][j];
	for(int k=0;k<10;k++){
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
			}
		}
	}
	int ans=0;
	while(h--){
		cin>>w;	if(w==-1)	continue;
		ans+=dis[w][1];
	}
	cout<<ans<< '\n';
	return 0;
}

Measured memory_bytes: 256
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")


P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}



int main(){
  
  vector<int> N(3);
  for(int i = 0; 3 > i; i++){
    cin>>N[i];
  }
  sort(N.begin(),N.end());
  if((N[0]==N[1]&&N[1]!=N[2]) || (N[2]==N[1]&&N[1]!=N[0]))cout << "Yes" << endl;
  else cout << "No" << endl;

}

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

int N, M;
long long int A[100005], B[100005];

vector<pair<long long int, long long int> > V;

int IsPossible(long long int X) {

	int num = 0;
	for (int i = 0; i < (int)V.size(); i++) {
		long long int y = X / (V[i].first);
		//cout << "y= " << y << endl;
		y = min(y, V[i].second);
		//cout << "y= " << y << endl;
		num += y;
		X -= y*(V[i].first);
	}
	if (num >= M) { return 1; }
	
	return 0;
}

long long int BINARY_SEARCH(long long int X1, long long int X2) {

	long long int left = X1;
	long long int right = X2;

	while (right-left>1) {
		long long int med = (left + right) / 2;
		if (IsPossible(med) == 1) {
			right = med;
		}
		else {
			left = med;
		}
	}
	return right;
}

int main(void) {

	cin >> N >> M;

	for (int i = 1; i <= N; i++) {
		cin >> A[i] >> B[i];

		V.push_back(pair<long long int, long long int>(A[i], B[i]));
	}

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

	


	cout << BINARY_SEARCH(0, 999999999999999) << endl;

	/*for (int i = 1; i <= 20; i++) {
		cout << i << " " << IsPossible(i) << endl;
	}*/

	//system("pause");
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> a(3*N);
  for (int i=0; i<3*N; i++) cin >> a[i];
  long long mae = 0;
  priority_queue<int, vector<int>, greater<int> > maeval;
  for (int i=0; i<N; i++){
    mae += a[i];
    maeval.push(a[i]);
  }
  long long usiro = 0;
  priority_queue<int> usiroval;
  for (int i=0; i<N; i++){
    usiro += a[3*N-1-i];
    usiroval.push(a[3*N-1-i]);
  }

  vector<long long> maescore(N+1);
  vector<long long> usiroscore(N+1);
  maescore[0] = mae;
  usiroscore[0] = usiro;
  for (int i=0; i<N; i++){
    if (a[N+i] > maeval.top()){
      mae += a[N+i]-maeval.top();
      maeval.pop();
      maeval.push(a[N+i]);
    }
    maescore[i+1] = mae;
    if (a[2*N-1-i] < usiroval.top()){
      usiro -= usiroval.top() - a[2*N-1-i];
      usiroval.pop();
      usiroval.push(a[2*N-1-i]);
    }
    usiroscore[i+1] = usiro;
  }
  long long ans = -100000000000000;
  for (int i=0; i<N+1; i++) ans = max(ans, maescore[i]-usiroscore[N-i]);
  // for (int i=0; i<N+1; i++) {
  //   cout << "mae" << i << ": " << maescore[i] << endl;
  //   cout << "usiro" << i << ": " << usiroscore[i] << endl;
  //   cout << endl;
  // }
  cout << ans << endl;
}


Measured memory_bytes: 3960
"use strict";
function main(input) {
  let kari = input[0].trim().split(" ").map(i => parseInt(i));
  let k = kari[0];
  let n = kari[1];

  let a = input[1].trim().split(" ").map(i => parseInt(i));

  let b = [];
  b[0] = 0;
  for(let i=1;i<n;i++){
    b[i] = a[i] - a[i-1];
  }
  b[n] = a[0] + (k - a[n-1]);
  //console.log(b);
  
  b.sort(function(a, b) {
    return b - a;
  });

  let sum = 0;

  for(let i=1;i<b.length;i++){
    sum += b[i];
  }

  console.log(sum)

}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));

Measured memory_bytes: 50912
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 998244353;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
vector<pair<int, int>> a;
vector<int> tree;
int query(int t, int nl, int nr, int l, int r) {
	if (nl > r || nr < l) {
		return -inf;
	}
	if (nl >= l && nr <= r) {
		return tree[t];
	}
	int mid = nl + (nr - nl) / 2;
	return max(query(2 * t, nl, mid, l, r), query(2 * t + 1, mid + 1, nr, l, r));
}
void update(int t, int nl, int nr, int ind, int val) {
	if (nl > ind || nr < ind) {
		return;
	}
	if (nl == nr) {
		tree[t] = val;
		return;
	}
	int mid = nl + (nr - nl) / 2;
	update(2 * t, nl, mid, ind, val);
	update(2 * t + 1, mid + 1, nr, ind, val);
	tree[t] = max(tree[2 * t], tree[2 * t + 1]);
}
int ind(int x) {
	return lower_bound(a.begin(), a.end(), make_pair(x, -inf)) - a.begin();
}
int add(int x, int y) {
	x += y;
	if (x >= mod) {
		x -= mod;
	}
	return x;
}
void add_self(int& x, int y) {
	x = add(x, y);
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n;
	cin >> n;
	a.resize(n);
	tree.resize(4 * (n + 1));
	for (int i = 0; i < n; ++i) {
		cin >> a[i].first >> a[i].second;
	}
	sort(a.begin(), a.end());
	vector<int> next(n);
	for (int i = 0; i < n; ++i) {
		next[i] = lower_bound(a.begin(), a.end(), make_pair(a[i].first + a[i].second, -inf)) - a.begin();
	}
	vector<int> good(n);
	good[n - 1] = n;
	update(1, 0, n, n, n);
	for (int i = n - 1; i >= 0; --i) {
		good[i] = max(next[i], query(1, 0, n, i + 1, next[i] - 1));
		update(1, 0, n, i, good[i]);
	}
	vector<int> dp(n + 1);
	dp[n] = 1;
	for (int i = n - 1; i >= 0; --i) {
		add_self(dp[i], dp[i + 1]);
		add_self(dp[i], dp[good[i]]);
	}
	cout << dp[0] << '\n';
 	return 0;
}


Measured memory_bytes: 7296
#include<iostream>
#include<string>
#include <vector>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
#define PI 3.141592653589793
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 1e9 + 7;

int main() {
	int n, k;
	cin >> n >> k;
	map<int, int> a;
	rep(i, n) {
		int t;
		cin >> t;
		if (!a.count(t))  a[t] = 1;
		else a[t]++;
	}
	vector<int> c;
	int ans = 0;
	for (auto i : a) {
		int v = i.second;
		c.push_back(v);
		//cout << i.first << " " << i.second << endl;
	}
	vsort(c);
	if (c.size() > k) {
		rep(i, c.size() - k) ans += c[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 10748
import sys
sys.setrecursionlimit(10 ** 8)

N, M = map(int,  input().split())

G = [[] for i in range(N + 1)]
for i in range(M):
    l, r, d = map(int, input().split())
    G[l].append([r, d])
    G[r].append([l, - d])
    
def dfs(i):
    for x, d in G[i]:
        if dp[x] == inf:
            dp[x] = dp[i] + d
            if not dfs(x):
                return False
        elif dp[x] != dp[i] + d:
            return False
    return True
    
inf = float('inf')
dp = [inf] * (N + 1)
for i in range(1, N + 1):
    if dp[i] == inf:
        dp[i] = 0
        if not dfs(i):
            print('No')
            break
else:
    print('Yes')

Measured memory_bytes: 135208
N = int(input())
A= []

A = list(map(int, input().split(" ")))

#ユークリッド互除法の関数の定義
def gcd(a,b):
    if b==0:return a
    return gcd(b,a%b)


if N==1:
    print(A[0])
else:
    element = gcd(A[0], A[1])
    if N==2:
        print(element)
    else:
        for i in range(2,N):
            element=gcd(element,A[i])
        print(element)


Measured memory_bytes: 14252
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
 
   int N = sc.nextInt();
   char[] c = sc.next().toCharArray();
   
   int tmp = 0;
   int ans = 0;
   for(int i=0;i<N;i++)
   {
     if(c[i]=='I')
     {
       tmp++;
     }  
     else
     {
       tmp--;
     }
     if(tmp>ans) ans=tmp;
   } 
   System.out.println(ans);
 }
}

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

using namespace std;

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> v(h);
  for(int i = 0; i < h; i++)cin >> v[i];
  vector<bool> r(h, false), c(w, false);
  
  for(int i = 0; i < h; i++){
  	for(int j = 0; j < w; j++){
      if(v[i][j] == '#'){
        r[i] = true;
        c[j] = true;
      }
    }
  }
  
  for(int i = 0 ; i < h; i++){
    if(r[i]){
      for(int j = 0; j < w; j++){
		if(c[j]){
          cout << v[i][j];
        }
      }
      cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int A,B,C,D,E,F;
    scanf("%d", &A);
    if(A < -1000){
      return 0;
    }
    scanf("%d", &B);
    if(B > 1000){
      return 0;
    }
    C = A+B;
    D = A-B;
    E = A*B;
    if((C-D) >= 0){
      if((C-E) >= 0){
        printf("%d", C);
      }else{
      printf("%d", E);
    }
    }else if((C-D)<0){
      if((D-E)>=0){
        printf("%d", D);
      }else{
      printf("%d", E);
    }
  }
}


Measured memory_bytes: 1708
#include <stdio.h>

int main(void){
  int i,n,a[100];
  scanf("%d",&n);
  
  for(i=0;i<n;i++) 
    scanf("%d",&a[i]);

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



Measured memory_bytes: 2056
main = do
  contents <- getContents
  let ls = tail $ lines contents
  let lss = map words ls
  print $ foldl1 (+) $ map mkNum lss

mkNum :: [String] -> Int
mkNum (x:y:_) = (rInt y) - (rInt x) + 1

rInt :: String -> Int
rInt = read


Measured memory_bytes: 1276
#include<stdio.h>
int main ()
{
    int x,y,z,temp1,temp2;
    scanf("%d %d %d", &x,&y, &z);
    temp1=x;
    x=y;
    y=temp1;
    temp2=x;
    x=z;
    z=temp2;
     printf("%d %d %d\n", x, y, z);
     return 0;


}


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

int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
int w, h;
int sx,sy;
int ans = 100;

bool outofrange(int y,int x)
{
	if (y < 0 || y >= h || x < 0 || x >= w) {
		return true;
	}
	else {
		return false;
	}
}

void dfs(vector<vector<int>> grid, int sy, int sx, int depth)
{
	if (depth + 1 >= ans || depth + 1 > 10) {
		return;
	}

	for (int i = 0; i < 4; i++) {
		int ny = sy + dy[i];
		int nx = sx + dx[i];

		if (outofrange(ny, nx) == true || grid[ny][nx] == 1) {
			continue;
		}

		while (outofrange(ny, nx) == false) {
			if (grid[ny][nx] == 3) {
				ans = min(ans, depth + 1);
				return;
			}

			if (grid[ny][nx] == 1) {
				grid[ny][nx] = 0;
				dfs(grid, ny - dy[i], nx - dx[i], depth + 1);
				grid[ny][nx] = 1;
				break;
			}

			ny += dy[i];
			nx += dx[i];
		}
	}
}

int main()
{
	while (true) {
		cin >> w >> h;

		if (w == 0 && h == 0) {
			break;
		}

		ans = 100;
		vector<vector<int>> grid(h, vector<int>(w));
		pair<int, int> start, goal;

		for (int y = 0; y < h; y++) {
			for (int x = 0; x < w; x++) {
				cin >> grid[y][x];

				if (grid[y][x] == 2) {
					sy = y;
					sx = x;
				}
			}
		}
		
		dfs(grid, sy, sx, 0);

		cout << (ans <= 10 ? ans : -1) << endl;
	}

	return 0;
}

Measured memory_bytes: 3220
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

use std::collections::HashSet;

fn yakusu(a: i64, b: i64) -> usize {
    let mut a = a;
    let mut b = b;
    let mut s = HashSet::new();
    let mut common = HashSet::new();
    for p in 2..a+1 {
        if a % p == 0 {
            s.insert(p);
            while a % p == 0 { a /= p }
            if a == 1 { break }
        }
        if p * p > a && a > 2 {
            s.insert(a);
            break
        }
    }
    for p in 2..b+1 {
        if b % p == 0 {
            if s.contains(&p) {
                common.insert(p);
            }
            while b % p == 0 { b /= p }
            if b == 1 { break }
        }
        if p * p > b && b > 2 {
            if s.contains(&b) {
                common.insert(b);
            }
            break
        }
    }
    // trace!(&s);
    // trace!(&common);
    common.len()
}

fn main() {
    let mut sc = Scanner::new();
    let a: i64 = sc.cin();
    let b: i64 = sc.cin();
    put!(yakusu(a, b) + 1);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <fstream>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>
#include <assert.h>
#include <vector>
#include <cstring>
#include <bitset>
#include <random>

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back

using namespace std;

typedef long long ll;
//typedef __int128 ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef double ld;

int main() {

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

    int a, b;
    cin >> a >> b;

    if (a + b == 15) {
        cout << "+\n";
    } else if (a * b == 15) {
        cout << "*\n";
    } else {
        cout << "x\n";
    }

}

Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
cnt = 0
while True:
    for i in range(n):
        if A[i] % 2 == 0:
            A[i] //= 2
        else:
            print(cnt)
            exit()
    cnt += 1


Measured memory_bytes: 10384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;
typedef long long ll;

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

vector<ll> prime;

void prime_factorize(ll n){
    if(n<=1) return;
    ll l=sqrt(n);
    for(int i=2;i<=l;i++){
        if(n%i==0){
        prime_factorize(i);
	prime_factorize(ll(n/i));
	return;
        }
    }
    prime.push_back(n);
    return;
}

int main(){
  ll A,B;
  cin >> A >> B;
  ll max= GCD(A,B);
  prime_factorize(max);
  ll ans = 0;
  prime.push_back(0);
  for(int i=0;i<prime.size();i++){
    if(prime[i]!=prime[i+1]) ans++;
  }
  ans++;
  cout << ans << endl;
}


Measured memory_bytes: 3096
N = int(input())
X = list(map(int, input().split()))
M = int(input())
A = list(map(int, input().split()))
for x in A:
    if X[x-1] + 1 in X or X[x-1] == 2019:
        continue
    else:
        X[x-1] += 1
for i in range(N):
    print(X[i])


Measured memory_bytes: 5604