akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define F0R(i, a) for (int i = 0; i < (a); i++)
const int mod = 1e9 + 7;
const char nl = '\n';

ll binpow(ll x, ll n){
    if(n == 0) return 1;
    if(n % 2 == 0) return binpow(x * x % mod, n / 2);
    else return x * binpow(x, n - 1) % mod;
}

int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin >> n;
    ll tmp1 = 0, tmp2 = 0;
    F0R(i, n){
        ll a;
        cin >> a;
        tmp1 = (tmp1 + a) % mod;
        tmp2 = (tmp2 + a * a % mod) % mod;
    }
    tmp1 = tmp1 * tmp1 % mod;
    cout << (tmp1 - tmp2 + mod) % mod * binpow(2, mod - 2) % mod << nl;
    return 0;
}

Measured memory_bytes: 3584
import java.util.Scanner;

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

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

int main(){
  char s[100001],t1[6],t2[7],t3[8];
  int i,j,len,flag=0;
  
  scanf("%s",s);
  len=strlen(s);
  i=len-1;
  while(i>=4 && flag==0){
    if(i>=4){
      strncpy(t1, &s[i-4], 5);
    } else {
      t1[0]='\0';
    }
    
    if(i>=5){
      strncpy(t2, &s[i-5], 6);
    } else {
      t2[0]='\0';
    }
    
    if(i>=6){
      strncpy(t3, &s[i-6], 7);
    } else {
      t3[0]='\0';
    }
    
    if(strcmp(t1,"dream")==0 || strcmp(t1,"erase")==0){
      i-=5;
    } else if(strcmp(t2,"eraser")==0){
      i-=6;
    } else if(strcmp(t3,"dreamer")==0){
      i-=7;
    } else {
      flag=1;
    }
  }
  
  if(flag==1){
    printf("NO");
  } else {
    printf("YES");
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const double PI  = acos(-1.0);

#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 
int main()
{
    int K, A, B;
    cin >> K >> A >> B;
    for (int i = A; i <= B; i++){
        if (i % K == 0){
            cout << "OK";
            return 0;
        }
    }
    
    cout << "NG";
    return 0;
}



Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main(){
  int n;
  while(cin >> n){
    int count = 0;
    rep(i,10){
      rep(j,10){
        rep(k,10){
          rep(l,10){
            if(i+j+k+l == n) count++;
          }
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}



Measured memory_bytes: 3080
n, m, x = map(int, input().split())

arr = []
for _ in range(n):
    arr.append(list(map(int, input().split())))

best = float("inf")
for i in range(1<<n):
    sk = [0] * m
    pr = 0
    for j in range(n):
        if i&(1<<j):
            for k in range(m):
                sk[k] += arr[j][k+1]
            pr += arr[j][0]

    gud = True
    for e in sk:
        if e < x:
            gud = False
            break

    if gud:
        best = min(best, pr)

if best == float("inf"):
    best = -1
print(best)


Measured memory_bytes: 68496
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <set>

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

using namespace std;

int mo(int r, int d, int xi) {
	return xi * r - d;
}


int main() {
	int r, d, x, xnew;
	cin >> r >> d >> xnew;

	rep(i, 10) {
		x = xnew;
		xnew = mo(r, d, x);
		cout << xnew << endl;
	}



	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

/* 基本要素 */
typedef complex<double> Point;
typedef pair<Point, Point> Line;
typedef vector<Point> VP;
const double EPS = 1e-6; // 許容誤差^2
const double INF = 1e9;
#define X real()
#define Y imag()
// #define LE(n,m) ((n) < (m) + EPS)
#define LE(n,m) ((n) - (m) < EPS)
// #define GE(n,m) ((n) + EPS > (m))
#define GE(n,m) (EPS > (m) - (n))
#define EQ(n,m) (abs((n)-(m)) < EPS)

// 内積　dot(a,b) = |a||b|cosθ
double dot(Point a, Point b) {
  return a.X*b.X + a.Y*b.Y;
}

// 外積　cross(a,b) = |a||b|sinθ
double cross(Point a, Point b) {
  return a.X*b.Y - a.Y*b.X;
}

// 点の進行方向
int ccw(Point a, Point b, Point c) {
  b -= a;  c -= a;
  if (cross(b,c) >  EPS) return +1;  // counter clockwise
  if (cross(b,c) < -EPS) return -1;  // clockwise
  if (dot(b,c)   < -EPS) return +2;  // c--a--b on line
  if (norm(b) < norm(c)) return -2;  // a--b--c on line or a==b
  return 0;                          // a--c--b on line or a==c or b==c
}

const double pi = acos(-1);

double areaCC(Point a, double ar, Point b, double br) {
  double d = abs(a-b);
  if (ar + br - d <= EPS) {
    return 0.0;
  } else if (d - abs(ar-br)<= EPS) {
    double r = min(ar,br);
    return r * r * pi;
  } else {
    double rc = (d*d + ar*ar - br*br) / (2*d);
    double theta = acos(rc / ar);
    double phi = acos((d - rc) / br);
    return ar*ar*theta + br*br*phi - d*ar*sin(theta);
  }
}

double find_R(double area){
    return sqrt(area/pi);
}

int uw,uh,A,B,AandB;
void solve(){
    double ra = find_R(A), rb = find_R(B);

    bool flg = false;
    if(A<B){
        flg = true;
        swap(ra,rb);
        swap(A,B);
    }

    if(2*ra > min(uw,uh)){
        printf("impossible\n");
        return;
    }

    Point p_a(ra, ra), p_b(uw-rb, uh-rb);
    double dx = p_b.X - p_a.X, dy = p_b.Y - p_a.Y;
    double D = sqrt(dx*dx+dy*dy);
    dx /= D;
    dy /= D;

    auto calc_area = [&](Point q){
        return areaCC(p_a, ra, q, rb);
    };

    double l=0, r=D;
    rep(loop,80){
        double m=(l+r)/2;
        Point cand(p_a.X+dx*m, p_a.Y+dy*m);

        // printf(" m %f : area %.10f\n", m, calc_area(cand));
        if(calc_area(cand) <= AandB) r=m;
        else l=m;
    }

    p_b = Point(p_a.X+dx*l, p_a.Y+dy*l);
    if( EQ(calc_area(p_b), AandB) ){
        // dbg(abs(p_a-p_b));
        if(flg){
            swap(p_a, p_b);
            swap(ra,rb);
        }
        printf("%.10f %.10f %.10f %.10f %.10f %.10f\n", p_a.X, p_a.Y, ra, p_b.X, p_b.Y, rb);
    }
    else printf("impossible\n");
}

int main(){
    while(cin >>uw >>uh >>A >>B >>AandB,uw) solve();
    return 0;
}



Measured memory_bytes: 3476
#include <iostream>
#include <string>
#include <vector>
using namespace std;
const int alphabet = 26;
//---------------------------------------
void count(string str, vector<int>& table);   //??¢???????????????????????°?????°??????
void output(vector<int> table);  //??¨???
//---------------------------------------

int main(void)
{
	string str;  
	vector<int> table(alphabet, 0);
	
	while(getline(cin, str)){  //??????
		count(str, table);
	}
	output(table);
	
	return 0;
}

//------------------------------------------
void count(string str, vector<int>& table)
{
	
	
	for(int i = 0; i < str.size(); i++){
		if(str[i] >= 'A' && str[i] <= 'Z') {
			int table_num = str[i] - 'A';
			table[table_num] += 1;
		}
		else if(str[i] >= 'a' && str[i] <= 'z'){
			int table_num = str[i] - 'a';
			table[table_num] += 1;
		}
	}
}
//------------------------------------------
void output(vector<int> table)
{	
	for(int i = 0; i < 26; i++){
		char alp = 'a' + i;
		cout << alp << " : "
		     	<< table[i] << endl;
	}
}

Measured memory_bytes: 3160
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>

using namespace std;

int main()
{
    string train;
    string dtrain[2][2];
    set<string> result;
    int n;
    int len;
    cin >> n;
    while(cin >> train){
        len = train.size();
        result.insert(train);
        for(int i=1;i<len;++i)
        {
            dtrain[0][0] = train.substr(0,i);
            dtrain[1][0] = train.substr(i);
            string::reverse_iterator ritA = dtrain[0][0].rbegin();
            string::reverse_iterator ritB = dtrain[1][0].rbegin();
            while(ritA != dtrain[0][0].rend())
            {
                dtrain[0][1] += *ritA;
                ++ritA;
            }
            while(ritB != dtrain[1][0].rend())
            {
                dtrain[1][1] += *ritB;
                ++ritB;
            }
            for(int i=0;i<2;++i){
                for(int j=0;j<2;++j){
                    for(int k=0;k<2;++k) {
                        if(result.find(dtrain[i][j]+dtrain[1-i][k])==result.end())
                        {
                            result.insert(dtrain[i][j]+dtrain[1-i][k]);
                        }
                    }
                }
            }
            for(int i=0;i<2;++i){
                for(int j=0;j<2;++j){
                    dtrain[i][j].clear();
                }
            }
        }
        cout << result.size() << endl;
        result.clear();
    }
}

Measured memory_bytes: 1288
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long
#define pii pair<int,int>
#define pll pair<LL,LL>

using namespace std;

int main(){

    int sx,sy,tx,ty;cin>>sx>>sy>>tx>>ty;
    string ans="";

    int ver = ty-sy;
    int hol = tx-sx;

    REP(i,hol)ans+="R";
    REP(i,ver)ans+="U";
    REP(i,hol)ans+="L";
    REP(i,ver)ans+="D";
    ans+="D";
    REP(i,hol+1)ans+="R";
    REP(i,ver+1)ans+="U";
    ans+="L";
    ans+="U";
    REP(i,hol+1)ans+="L";
    REP(i,ver+1)ans+="D";
    ans+="R";
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <fstream>
#define inputtxt() std::ifstream in("input.txt"); std::cin.rdbuf(in.rdbuf())
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define foreach(e, v) for (auto e : v)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];

int main(){
    vector<int> antennas(5);
    collect(antennas, 5);
    int k; cin >> k;
    if(antennas[4] - antennas[0] <= k){
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import math
x,y=map(int,input().split())
b=math.floor(y/2)
if x%2==0 and y%2==0:
  for i in range(int(x/2)):
    print("#."*b,sep="")
    print(".#"*b,sep="")
elif x%2==1 and y%2==0:
  for i in range(int((x-1)/2)):
    print("#."*b,sep="")
    print(".#"*b,sep="")
  print("#."*b,sep="")
elif x%2==0and y%2==1:
  for i in range(int(x/2)):
    print("#."*b,"#",sep="")
    print(".#"*b,".",sep="")
else:
  for i in range(int((x-1)/2)):
    print("#."*b,"#",sep="")
    print(".#"*b,".",sep="")
  print("#."*b,"#",sep="")

while True:
  x,y=map(int,input().split())
  b=math.floor(y/2)
  print()
  if x==0 and y==0:
    break
  else:
    if x%2==0 and y%2==0:
      for i in range(int(x/2)):
        print("#."*b,sep="")
        print(".#"*b,sep="")
    elif x%2==1 and y%2==0:
      for i in range(int((x-1)/2)):
        print("#."*b,sep="")
        print(".#"*b,sep="")
      print("#."*b,sep="")
    elif x%2==0and y%2==1:
      for i in range(int(x/2)):
        print("#."*b,"#",sep="")
        print(".#"*b,".",sep="")
    else:
      for i in range(int((x-1)/2)):
        print("#."*b,"#",sep="")
        print(".#"*b,".",sep="")
      print("#."*b,"#",sep="")


Measured memory_bytes: 5700
import math
import itertools
K = int(input())
A = [ i for i in range(1,K+1)]
L = list(itertools.combinations_with_replacement(A,3))
ans = 0
for i in range(len(L)):
    if L[i][0] == L[i][1] and L[i][1] == L[i][2]:
        ans += math.gcd((math.gcd(L[i][0],L[i][1])),L[i][2])
    elif L[i][0] == L[i][1] or L[i][1] == L[i][2] or L[i][0] == L[i][2]:
        ans += 3 * math.gcd((math.gcd(L[i][0],L[i][1])),L[i][2])
    else:
        ans += 6 * math.gcd((math.gcd(L[i][0],L[i][1])),L[i][2])
print(ans)

Measured memory_bytes: 105580
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <deque>
#include <numeric>
#include <utility>
#define sign(a) ((a>0)-(a<0))
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define LL long long
#define INF (LL)(1LL<<60)
#define all(a) a.begin(), a.end()
#define gr greater<LL>()

using namespace std;
typedef pair<pair<LL, LL>, int> P;

void solve(long long N, long long M, long long L, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C, long long Q, std::vector<long long> s, std::vector<long long> t){
    vector<vector<LL>> edges(N, vector<LL>(N, INF));

    rep(i, M){
        if(C[i]>L)continue;
        edges[A[i]-1][B[i]-1] = C[i];
        edges[B[i]-1][A[i]-1] = C[i];
    }

    vector<vector<pair<LL, LL>>> shortests(N,vector<pair<LL, LL>>(N,make_pair(INF,-INF)));

    rep(S, N){
        priority_queue<P, std::vector<P>, std::greater<P>> q;
        q.push(make_pair(make_pair(0, -L), S));

        while(!q.empty()){
            LL src = q.top().second;
            auto l0 = q.top().first;
            q.pop();
            if(l0 > shortests[S][src])continue;
            
            for(LL dst=0ll; dst<N; dst++){
                auto l = edges[src][dst];
                if(l>=INF)continue;

                auto cnt = l0.first;
                auto rem = -l0.second;
                auto l1 = (l>rem ? make_pair(cnt+1, -(L-l)) : make_pair(cnt, -(rem-l)));

                if(l1 < shortests[S][dst]){
                    shortests[S][dst] = l1;
                    q.push(make_pair(l1, dst));
                }
            }
        }
        
    }

    rep(i,Q){
        LL S = s[i]-1;
        LL G = t[i]-1;
        auto ans = shortests[S][G];
        cout <<  (ans.first < INF ? ans.first : -1) << endl;
    }
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    long long L;
    scanf("%lld",&L);
    std::vector<long long> A(M);
    std::vector<long long> B(M);
    std::vector<long long> C(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
        scanf("%lld",&C[i]);
    }
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> s(Q);
    std::vector<long long> t(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&s[i]);
        scanf("%lld",&t[i]);
    }
    solve(N, M, L, std::move(A), std::move(B), std::move(C), Q, std::move(s), std::move(t));
    return 0;
}


Measured memory_bytes: 4992
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1001001001
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
int main() {
    ll n;
    cin >> n;
    ll max=0;
    ll sum=0;
    REP(i,n){
        ll reg;
        cin >> reg;
        if(reg > max){
            max = reg;
        }
        else sum += max - reg;
    }
    cout << sum << endl;
}

Measured memory_bytes: 3580
#include <atcoder/segtree>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
int nmax = 300005;

int op(int a, int b) {
    return max(a, b);
}

int e() {
    return 0;
}

int main() {
  int n,k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  
  segtree<int,op,e> dp(nmax);
  
  for(int i=0;i<n;i++){
    int x = a[i];
    int l = max(x-k,0);
    int r = min(x+k+1,nmax);
    int now = dp.prod(l,r)+1;
    dp.set(x,now);
  }

  int ans = dp.prod(0,nmax);
  cout << ans << endl;
  
  return(0);
}

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

int main(){
  string s;
  map<string,int> m;
  m["SUN"]=7;
  m["MON"]=6;  
  m["TUE"]=5;
  m["WED"]=4;
  m["THU"]=3;
  m["FRI"]=2;
  m["SAT"]=1;
  cin>>s;
  cout<<m[s];
  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <assert.h>
#include <queue>
#include <stack>
#include <string.h>
using namespace std;

#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define left  (2*idx)+1
#define right (2*idx)+2
#define pb push_back
#define ll long long
#define all(x) x.begin(),x.end()


int main()
{
	vector<string> v;
	v.pb("Sunny");
	v.pb("Cloudy");
	v.pb("Rainy");

	string s;
	cin >> s;

	for(int i=0; i<=2; i++)
	{
		if(v[i] == s)
		{
			cout << v[(i+1)%3] << "\n";
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi frist
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> void read(T &x){
	int f=0; x=0; char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) f|=(ch=='-');
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	if(f) x=-x;
}



int main(){
	char s[10005];
	scanf("%s",s+1);
	printf("%c%c%c\n",s[1],s[2],s[3]);

	return 0;
}


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

public class Hello
{
    public static Hello hello;

    public static void Main()
    {
        hello = new Hello();
        hello.Run();
    }
    private string[] ReadInputS()
    {
        var line = System.Console.ReadLine();
        return line.Split();
    }
    private int[] ReadInputN()
    {
        return ReadInputS().Select(x => int.Parse(x)).ToArray();
    }


    public void Run()
    {
        int[] tmp = ReadInputN();
        int height = tmp[0];
        int width = tmp[1];
        string header = "";
        for(int i = 0; i < width+2; i++)
        {
            header += "#";
        }

        IList<string> body = new List<string>();
        for(int i = 0; i < height; i++)
        {
            body.Add(ReadInputS().ElementAt(0));
        }

        string output = "";
        for(int i = 0; i < height+2; i++)
        {
            if (i == 0 || i == height+1)
            {
                Console.WriteLine(header);
                continue;
            }
            output = "#";
            output += body.ElementAt(i - 1);
            output += "#";
            Console.WriteLine(output);
        }

        Console.Read();
    }
}


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



int main () {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int n; cin >> n;
  vector<int> A[1000];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n - 1; ++j) {
      int a; cin >> a;
      A[i].push_back(a - 1);
    }
    reverse(A[i].begin(), A[i].end());
  }
  int d = 0;
  vector<int> q;
  for (int i = 0; i < n; ++i) {
    if (A[A[i].back()].back() == i) q.push_back(i);
  }
  for (;q.size(); ++d) {
    vector<int> non_fixed;
    while (q.size()) 
      A[q.back()].pop_back(), non_fixed.push_back(q.back()), q.pop_back();
    set<int> S;
    for (int v : non_fixed) {
      if (A[v].size() and A[A[v].back()].size() and A[A[v].back()].back() == v) {
        S.insert(A[v].back());
        S.insert(v);
      }
    }
    q = vector<int>(S.begin(), S.end());
  }
  for (int i = 0; i < n; ++i) if (A[i].size()) cout << -1 << '\n', exit(0);
  cout << d << '\n';
}



Measured memory_bytes: 4352
gets
numbers = gets.split(' ').map(&:to_i)
numbers.each do |number|
  if number == 0
    p 0
    exit
  end
end
result = 1
numbers.each do |num|
  result *= num

  if result > 1000000000000000000
    p -1
    break
  end
end

p result if result <= 1000000000000000000

 

Measured memory_bytes: 21560
//ProblemA

//#define USE_STDIO
//#define USE_LOG
//#define FILE_ERR

#ifdef _MYPC
#include "mypc.h"
#endif // _MYPC

#ifndef debug
#define debug(...)
#endif // !LOG

#ifndef REDIRECT_STDIO
#define REDIRECT_STDIO {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
#endif // REDIRECT_STDIO

//include
#include <iostream>
#include <string>
#include <vector>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <memory>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iomanip>

using namespace std;

//int
using ll = long long;
using ull = unsigned long long;
using uint = unsigned;

//pair
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

//vector
template<typename T> using vt = std::vector<T>;
template<typename T> using vvt = vt<vt<T>>;
template<typename T> using vvvt = vt<vvt<T>>;
using vi = vt<int>;
using vvi = vvt<int>;
using vvvi = vvvt<int>;
using vl = vt<ll>;
using vvl = vvt<ll>;
using vvvl = vvvt<ll>;
using vb = vt<bool>;
using vpii = vt<pii>;

static inline void Solve();

int main(int argc, char* argv[]) {
	REDIRECT_STDIO;

	Solve();
	return 0;
}

constexpr ll MAXA = 100000000000LL;

//ProblemA
void Solve() {
	int n, k;
	cin >> n >> k;
	vl sp, sn;
	sp.push_back(0);
	for(int i = 0; i < n; i++) {
		int x; cin >> x;

		if(x >= 0) {
			sp.push_back(x);
		} else {
			sn.push_back(-x);
		}
	}
	sn.push_back(0);
	std::reverse(sn.begin(), sn.end());

	ll ans = MAXA * 3 + 1;
	for(int i = 1; i < k; i++) {
		if(i < (int)sp.size() && k - i < (int)sn.size()) {
			ans = min(ans, 2 * sp[i] + sn[k-i]);
			ans = min(ans, sp[i] + 2 * sn[k-i]);
		}
	}
	if(k < (int)sp.size()) {
		ans = min(ans, sp[k]);
	}
	if(k < (int)sn.size()) {
		ans = min(ans, sn[k]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 1656
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net.Mail;

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;

        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }

            var res = line[index];
            index++;
            return res;
        }

        public int NextInt()
        {
            return int.Parse(Next());
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }

        public int[] IntArray()
        {
            var array = Array();
            var result = new int[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = int.Parse(array[i]);
            }

            return result;
        }

        public long[] LongArray()
        {
            var array = Array();
            var result = new long[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = long.Parse(array[i]);
            }

            return result;
        }
    }


    class Program
    {
        private int N;
        private void Scan()
        {
            var sc = new Scanner();
            N = sc.NextInt();
        }

        public void Solve()
        {
            Scan();
            int min = int.MaxValue;
            for (int a = 1; a <= N - 1; a++)
            {
                int b = N - a;
                min = Math.Min(min, Sum(a) + Sum(b));
            }
            Console.WriteLine(min);
        }

        private int Sum(int n)
        {
            if (n < 10)
            {
                return n;
            }

            return n % 10 + Sum(n / 10);
        }

        static void Main() => new Program().Solve();
    }
}


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

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		
		while(in.hasNext()) {
			String str1=in.next(),str2=in.next();
			char CA1[]=str1.toCharArray(),CA2[]=str2.toCharArray();
			int dp[][]=new int[str1.length()][str2.length()];
			
			for(int i=0;i<str2.length();i++) {
				if(CA1[0]==CA2[i])dp[0][i]=1;
			}
			
			for(int i=0;i<str1.length();i++) {
				if(CA1[i]==CA2[0])dp[i][0]=1;
			}
			
			int max=0;
			
			for(int i=1;i<str1.length();i++) {
				for(int j=1;j<str2.length();j++) {
					if(CA1[i]==CA2[j]) {
						dp[i][j]=dp[i-1][j-1]+1;
						max=Math.max(max, dp[i][j]);
					}
					else dp[i][j]=0;
				}
			}
			
			
			System.out.println(max);
		}
	}

}



Measured memory_bytes: 290580
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    int a[2][n], dp[2][n];
    for (int i = 0; i < 2; i++)
        for (int j = 0; j < n; j++) cin >> a[i][j];
    dp[0][0] = a[0][0];
    dp[1][0] = a[1][0] + a[0][0];
    for (int i = 1; i < n; i++) dp[0][i] = dp[0][i - 1] + a[0][i];
    for (int i = 1; i < n; i++) dp[1][i] = max(dp[1][i - 1], dp[0][i]) + a[1][i];
    cout << dp[1][n - 1] << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  vector<double>vec(N);
  for (int X=0;X<N;X++){
    cin>>vec.at(X);
  }
  sort(vec.begin(), vec.end());
  double M=vec.at(0);
  for (int X=1;X<N;X++){
    M+=vec.at(X);
    M/=2;
  }
  cout << M << endl;
}


Measured memory_bytes: 3792
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N;
	cin>>N;
	vector<ll> A(N);
	ll sum = 0LL;
	rep(i,N){
		ll a;
		cin>>a;
		A[i] = a;
		sum += a;
	}
	ll dif = INF;
	ll e_sum = 0LL;
	rep(i,N-1){
		e_sum += A[i];
		ll e_dif = abs(sum - e_sum - e_sum);
		dif = min(e_dif, dif);
	}
	cout<<dif<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cstring>
#include <queue>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <bitset>

using namespace std;

using ll = long long;
using Vec = vector<ll>;
using P = pair<ll, ll>;
using VecP = vector<P>;
#define rep(i, n) for(ll i=0;i<(n);i++)
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

//static const ll MOD = 1000000007;
//static const ll INF = 1000000000;
//#define PI 3.14159265359

int main() {
    // input
    ll N;
    cin >> N;
    Vec A(N, 0);
    rep(i, N) {
        cin >> A[i];
    }

    // process
    sort(A.begin(), A.end(), greater<ll>());

    ll ans = 0;
    ans += A[0];
    for (ll i = 2; i < N; i++) {
        ans += A[i / 2];
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4452
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define PI 3.1415926535897932
#define MOD 1000000007;
using namespace std;
long long GCD(long long A,long long B){
  if(B==0){
    return A;
  }
  else{
    return GCD(B,A%B);
  }
}
long long LCM(long long A,long long B){
  long long g=GCD(A,B);
  return A/g*B;
}
long long num_order(long long X){
  long long ans=0;
  while(true){
    if(X==0){
      break;
    }
    else{
      X/=10;
      ans++;
    }
  }
  return ans;
}
int main() {
  
  int N;
  cin>>N;
  
  vector<string> S(N);
  for(int i=0;i<N;i++){
    cin>>S[i];
  }
  
  vector<long long> app(5);
  for(int i=0;i<N;i++){
    if(S[i][0]=='M'){
      app[0]++;
    }
    else if(S[i][0]=='A'){
      app[1]++;
    }
    else if(S[i][0]=='R'){
      app[2]++;
    }
    else if(S[i][0]=='C'){
      app[3]++;
    }
    else if(S[i][0]=='H'){
      app[4]++;
    }
  }
  
  long long sum=0;
  
  sum+=app[0]*app[1]*app[2];
  sum+=app[0]*app[1]*app[3];
  sum+=app[0]*app[1]*app[4];
  sum+=app[0]*app[2]*app[3];
  sum+=app[0]*app[2]*app[4];
  sum+=app[0]*app[3]*app[4];
  sum+=app[1]*app[2]*app[3];
  sum+=app[1]*app[2]*app[4];
  sum+=app[1]*app[3]*app[4];
  sum+=app[2]*app[3]*app[4];
  
  cout<<sum<<endl;
}


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

int main() {
  long long n, k;
  cin >> n >> k;
  
  if (n > k) {
    if (n%k > k - n%k)
      cout << k - n%k << endl;
    else 
      cout << n%k << endl;
  }
  else if (n == k)
    cout << 0 << endl;
  else {
    if (k - n < n)
      cout << k - n << endl;
    else
      cout << n << endl;
  }
    
}

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

int main() {
    int32_t n;
    cin >> n;
    int32_t a[100001];
    int32_t b[] = { 1, 6, 36, 216, 1296, 7776, 46656, 9, 81, 729, 6561, 59049 };

    a[0] = 0;
    for (int32_t i = 1; i <= n; i++) {
        int32_t min = 100000;
        for (int16_t j = 0; j <= 11; j++) {
            if (i >= b[j] && a[i - b[j]] < min) {
                min = a[i - b[j]];
            }
        }
        a[i] = min + 1;
    }
    cout << a[n] << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int A, B;
    cin >> A >> B;
    if(B%A==0) cout << A+B << endl;
    else cout << B-A << endl;
    return 0;
}


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

bool    IsPN(int N) {
        for (int i=2; N>=i*i; i++) {
                if (0==N%i)
                        return false;
        }
        return true;
}

int     NextPN(int N) {
        int i=N+1;
        while (!IsPN(i))
                i++;
        return i;
}

bool    CheckN(vector<int> &A4, int A) {
        for (int i=0; i<A4.size(); i++) {
                if (IsPN(A4.at(i)+A))
                        return false;
        }
        return true;
}

bool    AddNext(int N, vector<int> &a, int i, vector<int> A1, vector<int> A2, vector<int> A3, vector<int> A4) {
        if (N<=A1.size()) {
                for (int j=0; j<A1.size(); j++) {
                        cout <<A1.at(j) <<' ';
                }
                cout <<endl;
                return true;
        }
        if (!CheckN(A4, a.at(i))) {
                return false;
        }
        for (int j=0; j<A3.size(); j++)
                A4.push_back(A3.at(j)+a.at(i));
        for (int j=0; j<A2.size(); j++)
                A3.push_back(A2.at(j)+a.at(i));
        for (int j=0; j<A1.size(); j++)
                A2.push_back(A1.at(j)+a.at(i));
        A1.push_back(a.at(i));
        for (int j=i+1; j<a.size(); j++) {
                if (AddNext(N, a, j, A1, A2, A3, A4))
                        return true;
        }
        return false;
}

int     main() {
        int N;
        cin >>N;
        vector<int> a(0);
        for (int i=5; i<=55555; i++) {
                if (IsPN(i))
                        if (1==i%5)
                                a.push_back(i);
        }
        vector<int> A1(0);
        vector<int> A2(0);
        vector<int> A3(0);
        vector<int> A4(0);
        int A=1;
        for (int i=0; i<a.size(); i++) {
                if(AddNext(N, a, i, A1, A2, A3, A4))
                        return 0;
        }
        return 0;
};

Measured memory_bytes: 19532
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

int main() {
  LL n, m;
  cin >> n >> m;
  LL min_id = 1;
  LL max_id = n;
  for (LL i = 0; i < m; ++i) {
    LL left, right;
    cin >> left >> right;
    if (left > min_id) min_id = left;
    if (right < max_id) max_id = right;
  }
  const auto diff = max_id - min_id + 1;
  const auto result = (diff < 0 ? 0 : diff);
  cout << result << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MOD 1000000007
#define INF 1000000000000000007LL

const int N = 200005;
 
// it's swapnil07 ;)
 
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif

int arr[N];

signed main()
{
    fast
    #ifdef SWAPNIL07
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    int k, n; cin>>k>>n;

    For(i, 0, n){
        cin>>arr[i];
    }
    int ans = INF;
    For(i, 0, n){
        int j = (i-1+n)%n;
        int dist = (arr[j]-arr[i]+k)%k;
        ans = min(dist, ans);
    }
    cout<<ans;
    return 0;
}





Measured memory_bytes: 1792
a,b,c,k = map(int,input().split())

ans = 0

if k > a:
    ans += a
else:
    ans += k
    print(ans)
    exit()

k = k-a

if k > b:
    k = k-b
else:
    print(ans)
    exit()


if k > c:
    ans -= c
else:
    ans -= k
    print(ans)
    exit()

print(ans)

Measured memory_bytes: 9200
n = int(input())
r = [int(input()) for i in range(n)]
v_max = -10**9
r_min = r[0]
for i in range(1,n):
    v_max = max(v_max,r[i] - r_min)
    r_min = min(r_min,r[i])
print(v_max)

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

int A,B,C;

bool ao=true,bo=true,co=true;


int main(){
  cin >> A >> B >> C;
  if(A%2 == 0) ao = false;
  if(B%2 == 0) bo = false;
  if(C%2 == 0) co = false;
  int ans = 0;
	if(!((ao && bo && co) || (!ao && !bo && !co))) {
		if(ao != bo && bo == co){
			B++;C++;
		}
		else if(co != bo && bo == ao){
			B++;A++;
		}
		else if(bo != ao && ao == co){
			A++;C++;
		}
		ans++;
	}
	int maxi = max(A,B);
	maxi = max(maxi,C);
  ans += (maxi-A)/2 + (maxi-B)/2 + (maxi-C)/2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

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

constexpr ll INF = 1ll<<60;

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; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

const ll mod = 998244353;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  std::vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

ll N, M, K;
mint mpow[200010];
combination comb( 200010 );
mint ans;

int main()
{
  std::cin >> N >> M >> K;

  rep( i, N ) 
    mpow[i] = mint(M)*mint(M-1).pow(N-i-1);

  ans = mpow[0];

  repi( k, 1, K+1 )
  {
    ans += mpow[k]*comb(N-1,k);

  }

  std::cout << ans.x << std::endl;

  return 0;
}

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

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

  long x[100], y[100], h[100];
  for(int i = 0; i < N; i++){
    cin >> x[i] >> y[i] >> h[i];
  }

  long X, Y, H;
  bool ok;
  for(int i = 0; i <= 100; i++){
    for(int j = 0; j <= 100; j++){
      ok = true;
      H = -1;
      for(int k = 0; k < N; k++){
        if(h[k] != 0){
          if(H == -1){
            H = h[k] + abs(j - x[k]) + abs(i - y[k]);
            break;
          }
        }
      }
      for(int k = 0; k < N && ok == true; k++){
        if(h[k] != max(H - abs(j - x[k]) - abs(i - y[k]), (long)0)){
          ok = false;
          break;
        }
      }
      if(ok == true){
        X = j;
        Y = i;
        break;
      }
    }
    if(ok == true)break;
  }
  cout << X << " ";
  cout << Y << " ";
  cout << H << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n, a, b) = readLongList()

    if (a > b) {
        println(0)
        return
    }
    if (a != b && n == 1L) {
        println(0)
        return
    }
    println((2 - n) * (a - b) + 1)
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

Measured memory_bytes: 36528
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
#include <x86intrin.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <assert.h>
#include <string>
#include <bitset> 
#include <vector>
#include <cmath>                                    
#include <deque>                                    
#include <queue>
#include <iomanip>
#include <ctime>
#include <random>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
//#include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
//using namespace __gnu_pbds;
using namespace std;

 
//template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;
 
const double pi = acos (-1.0);
const double eps = 1e-9;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, m, sz, ans, used[N];
vector <int> g[N];

void dfs (int v) {
   used[v] = 1;
   sz ++;
   for (auto to : g[v])
      if (!used[to])
         dfs (to);
}
 
inline void boost () {
   ios_base :: sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
}

inline void Solve () {
   cin >> n >> m;
   for (int i = 1; i <= m; i ++) {
      int x, y;
      cin >> x >> y;
      g[x].pb (y);
      g[y].pb (x);
   }
   for (int i = 1; i <= n; i ++) 
      if (!used[i]) {
         sz = 0;
         dfs (i);
         ans = max (ans, sz);
      }
   cout << ans;
}               
 
signed main () {                                       
   #ifdef QWERTY
     freopen("input", "r", stdin);
   #endif
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}                 


Measured memory_bytes: 23972
fun main(args: Array<String>) {
    // String? を返す
    var n = readLine()!!.toInt()
    var input = readLine()!!.split(" ").map { it.toInt() }.toMutableList()

    var flag = false
    var cnt = 0
    while (true) {
        for (i in 0..(n - 1)) {
            if (input[i] % 2 == 0) {
                input[i] /= 2
            } else {
                flag = true
                break
            }
        }
        if(flag) break
        cnt += 1
    }
    print(cnt)
}


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

int main(void){
  int a, b;
  cin >> a >> b;
  
  int wa = 0;
  for( int i = a ; i < b+1 ; i++ ){
    int c[4];
    c[0] = i / 10000;		//5ケタ目の数の抽出
    c[1] = i % 10;			//1ケタ目の数の抽出    
    c[2] = i / 1000 % 10;	//4ケタ目の数の抽出
    c[3] = i % 100 / 10;	//3ケタ目の数の抽出
//    cout << c[0] << "  " << c[2] << " ? "  << c[3] << "  "  << c[1] << "  " << endl;
    if( c[0] == c[1] ){
      if( c[2] == c[3] ){
        wa++;
      }
    }
  }
  cout << wa << endl;
}

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

signed main () {
	string s;
	cin >> s;
	int n = s.size();
	vector < vector < int > > dp(n + 1, vector < int > (2, 0));
	dp[n][1] = 1;
	for (int i = n - 1; i >= 0; --i) {
		dp[i][0] = min(dp[i + 1][1] + 1 + int(s[i] - '0'), dp[i + 1][0] + int(s[i] - '0'));
		dp[i][1] = min(dp[i + 1][1] + 10 - int(s[i] - '0') - 1, dp[i + 1][0] + 10 - int(s[i] - '0'));
	}
	cout << min(dp[0][0], dp[0][1] + 1) << '\n';
}


Measured memory_bytes: 55940
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e9;
const long long int mod = 1e9+7;
typedef pair<ll,ll> pairs;
vector<pairs> p;


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

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

vector<vector<ll>> combination(ll n, ll r){
    vector<vector<ll>> v(n + 1, vector<ll>(n + 1, 0));
    for(ll i=0;i<v.size();++i){
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for(ll i=1;i<v.size();++i){
        for(ll j=0;j<i;++j){
            v[i][j] = (v[i - 1][j - 1] + v[i - 1][j]);
        }
    }
    return v;
}
// ------------------------------------

int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    ll x = 0;
    for(ll i=0;i<n;++i){
        cin>>a[i];
        if(a[i]%2==0){
            x++;
        }
    }

    ll ans = pow(3, n);
    ans -= pow(2, x);
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>

#define INPUT_FROM_FILE (0)

#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
#endif // INPUT_FROM_FILE
	int r = 0;
	int c = 0;
	std::vector<int> sums;
	
#if INPUT_FROM_FILE
	ifs >> r >> c;
#else
	std::cin >> r >> c;
#endif
	sums.resize(c + 1, 0);

	for(int i = 0; i < r; i++){
		int sum = 0;
		for(int j = 0; j < c; j++){
			int t = 0;
#if INPUT_FROM_FILE
			ifs >> t;
#else
			std::cin >> t;
#endif
			std::cout << t << " ";
			sum += t;
			sums[j] += t;
		}
		std::cout << sum << std::endl;
		sums[c] += sum;
	}
	for(int j = 0; j < c + 1; j++){
		std::cout << sums[j];
		if(j < c){
			std::cout << " ";
		}
	}
	std::cout << std::endl;
	return 0;
}

Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vvi vector<vector<int>> 
#define vi vector<int> 
#define vpii vector<pair<int,int>> 
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define ffor(i,n) for(int i = 0; i < n; ++i)
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int N,W;
    cin >> N >> W;
    vi wt(N),val(N);
    ffor(i,N) cin >> wt[i] >> val[i];
    // take item or not take
    // dp[i][j] -> total value for i items and total weight taken is j until now

    vvi dp(N + 1,vi(W + 1,0));
    
    for(int i = 1; i <= N; ++i)
    {
        for(int j = 0;j <= W; ++j)
        {
            // don't take current element
            dp[i][j] = dp[i - 1][j];
            // take current element if possible
            if(j - wt[i - 1] >= 0)
            {
                dp[i][j] = max(dp[i][j],dp[i - 1][j - wt[i - 1]] + val[i - 1]);
            }
        }
    }
    // answer will be dp[N][W];
    cout << dp[N][W];
}

Measured memory_bytes: 80256
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(0);
    
    int a, b, c;
    cin >> a >> b >> c;

    bool poor = ((a == b && b != c) || (b == c && c != a) || (c == a && a != b));

    cout << (poor ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAXN 250000
#define ll long long
#define rint register int
inline int read(){int r;int s=0,c;for(;!isdigit(c=getchar());s=c);for(r=c^48;isdigit(c=getchar());(r*=10)+=c^48);return s^45?r:-r;}
#define BS 998244353
#define EV1 669690699
#define EV2 679604188
#define MOD1 1004535809
#define MOD2 1061109589
struct Hash
{
	int h1,h2; Hash(){} Hash(int _h1, int _h2){h1=_h1;h2=_h2;} inline Hash operator + (Hash b){return Hash((h1+b.h1)%MOD1,(h2+b.h2)%MOD2);} inline ll v(){return (ll)h1<<32|h2;}
	inline Hash operator - (Hash b){return Hash((h1+MOD1-b.h1)%MOD1,(h2+MOD2-b.h2)%MOD2);} inline Hash operator * (Hash b){return Hash(1ll*h1*b.h1%MOD1,1ll*h2*b.h2%MOD2);}
}P[MAXN+5], H[MAXN+5], B(BS,BS), E(EV1,EV2), I(1,1), _; char s[MAXN+5]; int n; unordered_map<ll,int> G; ll Ans;
int main()
{
	n = read(); scanf("%s",s+1); P[0] = I; for(rint i = 1; i <= n; i++) switch(P[i]=P[i-1],H[i]=H[i-1],s[i]){case'<':P[i]=P[i]*E;break;case'>':P[i]=P[i]*B;break;case'+':H[i]=H[i]+P[i];break;case'-':H[i]=H[i]-P[i];break;}
	for(rint i = n; i; ++G[H[i].v()], Ans += G[(H[n]*P[i-1]+H[i-1]).v()], i--); return !printf("%lld\n",Ans);
}

Measured memory_bytes: 24052