akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n;
	cin>>n;
	deque<int> que;
	rep(i,n){
		int a;
		cin>>a;
		if(i%2==0) que.push_back(a);
		else que.push_front(a);
	}
	if(n%2){
		reverse(begin(que),end(que));
	}
	for(auto &x:que) cout<<x<<endl;
}

Measured memory_bytes: 3072
#include <cstdio>
#include <cstdlib>
int main(){
	int a[10],i,s=0,ma=10,k=0;
	for(i=0;i<5;i++){
		scanf("%d", &a[i]);
		if(a[i]%10<ma && a[i]%10!=0){
			ma=a[i]%10;
	}
	}
	for(i=0;i<5;i++){
		if(a[i]%10==ma && k==0){
		s+=a[i];
		k++;
		continue;
	}
		if(a[i]%10!=0)
		s+=(a[i]/10+1)*10;
		else
		s+=a[i];	
		
	}
	printf("%d", s);
	
	return 0;
	
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <bitset>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

int n,ans;

int SG(int a,int k)
{
	if (a % k == 0)
		return a / k;
	if (a < k)
		return 0;
	int t = (a - a / k * k - 1) / (a / k + 1) + 1;
	return SG(a - t * (a / k + 1),k);
}

int main()
{
	scanf("%d",&n);
	for (int a,k,i = 1;i <= n;i++)
	{
		scanf("%d%d",&a,&k);
		ans ^= SG(a,k);
	}
	puts(ans ? "Takahashi" : "Aoki");
	return 0;
}

Measured memory_bytes: 384
// Why am I so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

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

#define fi first
#define se second

using namespace std;

typedef long long ll;

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

vector<int> adj[MAXN];

bool u[MAXN];

int n, m;

void solve() {                   
	scanf("%d %d", &n, &m);

    for (int i = 1, u, v; i <= m; ++i) {
		scanf("%d %d", &u, &v);
		adj[u].pb(v);
		adj[v].pb(u);    
    }

    deque<int> q;
    q.pb(1);
    u[1] = 1;

    while (1) {
    	{
    		int nxt = -1;

    		for (int to : adj[q.front()]) {
    			if (!u[to]) {
    				nxt = to;	
    			}
    		}

    		if (nxt != -1) {
    			q.push_front(nxt);
    			u[nxt] = 1;
    			continue;
    		}
    	}

    	{
    		int nxt = -1;

    		for (int to : adj[q.back()]) {
    			if (!u[to]) {
    				nxt = to;	
    			}
    		}

    		if (nxt != -1) {
    			q.push_back(nxt);
    			u[nxt] = 1;
    			continue;
    		}
    	}

    	break;
    }

    printf("%d\n", q.size());

    while (!q.empty()) {
    	printf("%d", q.front());
    	printf(q.size() == 1 ? "\n" : " ");
    	q.pop_front();
    }
}

int main() {    
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 6784
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author EDGE
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, FastReader in, PrintWriter out) {

            int n = in.nextInt();

            int[] ar = new int[n];

            for (int i = 0; i < n; i++) {
                ar[i] = in.nextInt();
            }


            int te = 0;
            for (int i = 0; i < n; i++) {

                for (int j = i + 1; j < n; j++) {

//                ans[i][j]=ar[i]*ar[j];
                    te += ar[i] * ar[j];
//                out.print(ans[i][j]+"  ");
                }
//            out.println();
            }


            out.println(te);
        }

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

int main() {
    int x, y;
    cin >> x >> y;
    vector<set<int>> group(3);
    group.at(0) = {1, 3, 5, 7, 8, 10, 12};
    group.at(1) = {4, 6, 9, 11};
    group.at(2) = {2};
    rep(i, 3) if(group.at(i).find(x) != group.at(i).end()) x = i;
    rep(i, 3) if(group.at(i).find(y) != group.at(i).end()) y = i;
    if(x == y) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
#include <cassert>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<int>VI;
typedef pair<int,int>P;
typedef pair<double,double>P_D;
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define reprev(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define ALL(a)  (a).begin(),(a).end()
#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define fi first
#define se second
#define MAX 100100//5
#define MAX_N 200100
#define MAX_B 1001001//6
#define MAX_S 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
#define MOD 1000000007
#define INF 1 << 29
#define INFTY 1000000000000000000LL
#define MAX_INT INT_MAX

int main(){
    string s;cin>>s;
    int n=(int)s.length();
    string t;
    for(int i=0;i<n-1;i++){
        if(s[i]=='B'&&s[i+1]=='C'){
            t+='D';
            i++;
        }
        else t+=s[i];
    }
    ll a=0,b=0;
    for(int i=0;i<t.length();i++){
        if(t[i]=='A')a++;
        else if(t[i]=='D')b+=a;
        else a=0;
    }
    cout<<b<<endl;
}


Measured memory_bytes: 776
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(void){
    int n,a,b;
    cin >> n >> a >> b;
    if(b > n*a) cout << n*a << endl;
    else cout << b << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
using namespace std;

int main(){
    int n,m=1000000,num;
    cin >> n;
    for(int i=1;i<n;i++){
        int a=i,b=n-i,va=0,vb=0;
        string sa=to_string(a),sb=to_string(b);
        for(int s=0;s<sa.size();s++){
            va += stoi(sa.substr(s,1));
        }
        for(int t=0;t<sb.size();t++){
            vb += stoi(sb.substr(t,1));
        }
        num = va+vb;
        if(m > num)m=num;

    }
    cout << m << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define cmax(a,b) (a<(b)?a=(b):a)
#define cmin(a,b) (a>(b)?a=(b):a)
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
using namespace std; 

#define Pr(f,...) //printf(f,##__VA_ARGS__),fflush(stdout)

typedef long long ll;

int main(){
#ifdef CURIOUSCAT 
	//freopen("dat.in","r",stdin);
#endif	
	ll n,a,b,ans;
	cin>>n>>a>>b;
	if(a>b)ans=0;
	else if(n<=2){
		if(n==1&&a!=b)ans=0;
		else ans=1;
	}else ans=(b-a)*(n-2)+1;
	cout<<ans<<endl;
	return 0;
}


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

struct data {
    data() {}
    data(int x) : x(x) {}
    data(int x, int i, int j) : x(x), i(i), j(j) {}
    int x, i, j;

    bool operator< (const data& b) const { return x < b.x; }
};

int n, ind[10004][2], seg[20004];
data a[20004];

const int maxv = 70000;
vector<int> og[maxv], g[maxv], h[maxv];

void construct(int s, int e, int x) {
    if (s == e) {
        seg[s] = x;
    } else {
        int m = (s+e) / 2;
        construct(s, m, 2*x);
        construct(m+1, e, 2*x+1);
        og[x].push_back(2*x);
        og[x].push_back(2*x+1);
    }
}

void connect(int a, int s, int e, int x, int l, int r) {
    if (l <= s and e <= r) {
        g[a].push_back(x);
    } else if (l <= e and s <= r) {
        int m = (s+e) / 2;
        connect(a, s, m, 2*x, l, r);
        connect(a, m+1, e, 2*x+1, l, r);
    }
}

bool vis[maxv];
int ord[maxv], t;
void dfs1(int x) {
    if (vis[x]) return;
    vis[x] = true;

    for (int i : g[x]) dfs1(i);

    ord[t++] = x;
}

int col[maxv];
void dfs2(int x, int c) {
    if (vis[x]) return;
    vis[x] = true; col[x] = c;

    for (int i : h[x]) dfs2(i, c);
}

bool check(int d) {
    for (int i=0; i<maxv; i++) g[i] = og[i];

    for (int i=0; i<n; i++) for (int j=0; j<2; j++) {
        int x = ind[i][j], y = ind[i][!j];

        connect(seg[x], 0, 2*n-1, 1, upper_bound(a, a+2*n, data(a[y].x - d)) - a, y-1);
        connect(seg[x], 0, 2*n-1, 1, y+1, lower_bound(a, a+2*n, data(a[y].x + d)) - a - 1);
    }

    for (int i=0; i<maxv; i++) h[i].clear();
    for (int i=0; i<maxv; i++) for (int j : g[i]) h[j].push_back(i);

    fill(vis, vis+maxv, 0); t = 0;
    for (int i=0; i<maxv; i++) dfs1(i);

    reverse(ord, ord+maxv);
    fill(vis, vis+maxv, 0);
    for (int i=0, c=1; i<maxv; i++) dfs2(ord[i], c++);

    for (int i=0; i<n; i++) if (col[seg[ind[i][0]]] == col[seg[ind[i][1]]]) return false;
    return true;
}

int main() {
    cin >> n;

    for (int i=0; i<n; i++) {
        int x, y;
        cin >> x >> y;
        a[2*i] = data(x, i, 0);
        a[2*i+1] = data(y, i, 1);
    }

    sort(a, a+2*n);

    for (int i=0; i<2*n; i++) ind[a[i].i][a[i].j] = i;

    construct(0, 2*n-1, 1);

    int l = 0, r = 1e9 + 7;

    while (r-l > 1) {
        int m = (l+r) / 2;
        if (check(m)) l = m;
        else r = m;
    }

    cout << l << '\n';
}

Measured memory_bytes: 21108
#include <stdio.h>
int main()
{
    double x[100], y[100], sum = 0, metric = 0;
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%lf", x + i);
    for (int i = 0; i < n; i++)
        scanf("%lf", y + i);
    for (int i = 0; i < n; i++)
        metric += fabs(x[i] - y[i]);
    printf("%lf\n", metric);
    for (int i = 0; i < n; i++)
        sum += pow(x[i] - y[i], 2);
    printf("%lf\n", sqrt(sum));
    metric = sum = 0;
    for (int i = 0; i < n; i++)
        sum += pow(fabs(x[i] - y[i]), 3);
    printf("%lf\n", cbrt(sum));
    for (int i = 0; i < n; i++)
        if (metric < fabs(x[i] - y[i]))
            metric = fabs(x[i] - y[i]);
    printf("%lf\n", metric);

    return 0;
}



Measured memory_bytes: 2104
import math

n = int(input())
t = 100000 + 10

dp = [10**18] * (t+10)
dp[0] = 0

for i in range(1, t+1):
    dp[i] = dp[i-1] + 1

for i in range(t-1):
    s = t-i
    for j in range(int(math.log(s, 9)+1)):
        dp[i+9**j] = min(dp[i+9**j], dp[i]+1)
    for k in range(int(math.log(s, 6)+1)):
        dp[i+6**k] = min(dp[i+6**k], dp[i]+1)


print(dp[n])

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

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


Measured memory_bytes: 4720
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

int main(){
    int h,w,cnt = 0; cin >> h >> w;
    vector<vector<int>> far(h+2,vector<int> (w+2,-1));
    vector<vector<char>> s(h+2,vector<char> (w+2,'a'));

    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin >> s[i][j];
            if(s[i][j] == '.') cnt++;
        }
    }

    far[1][1] = 1;
    
    queue<pair<int,int>> que;
    que.push(pair<int,int> (1,1));
    while(que.size()){
        pair<int,int> p = que.front();
        que.pop();
        int pf = p.first;
        int ps = p.second;
        for(int i=0;i<4;i++){
            int px = pf + mx4[i];
            int py = ps + my4[i]; 
            if(s[px][py] =='a' || s[px][py]== '#') continue;
            if(far[px][py] != -1) continue;
            far[px][py] = far[pf][ps] + 1;
            que.push(pair<int,int> (px,py));
            }
    }
    if(far[h][w] == -1){
        cout << -1 << endl;
        return 0;
    }

    cout << cnt - far[h][w] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <fstream>

using namespace std;

int nm;

class difs {
public:
    bool operator() (int a,int b) {
        if(nm % 2 == 0)
            return abs(a - nm / 2) < abs(b - nm / 2);
        else
            return abs(a - (nm + 1) / 2) < abs(b - (nm + 1) / 2);
    };
};

int main(void) {    int n,a[100000];
    cin >> n;
    nm = 0;
    for(int i = 0;i < n;i++) {
        cin >> a[i];
        nm = max(nm,a[i]);
    }
    sort(a,a+n,difs());
    if(a[0] == nm)
        a[0] = a[1];
    cout << nm << " " << a[0] << endl;
    return 0;
}


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

int main() {
  int T = 1;
  int N, K;
  cin >> N >> K;
  
  for (int i = 0; i < N; i++) {
    if ((T * 2) >= (T + K)) {
      T += K;
    }
    else { 
      T *= 2;
    }
  } 
  cout << T << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
namespace atCoder
{
    class Program
    {
        struct Task
        {
            public int weight;
            public int limit;

            public Task(int w,int l)
            {
                weight = w;
                limit = l;
            }
        }
        static void Main(string[] args)
        {
            int num = int.Parse(Console.ReadLine());
            List<Task> Tasks = new List<Task>();
            for (int n=0;n< num; n++)
            {
                var input = Console.ReadLine().Split(' ');
                Tasks.Add(new Task(int.Parse(input[0]), int.Parse(input[1])));
            }
            int curtime = 0;
            var result = true;
            foreach(var task in Tasks.OrderBy(_=> _.limit))
            {
                curtime += task.weight;
                if (curtime > task.limit)
                {
                    result = false;
                    break;
                }
            }

            Console.WriteLine(result ? "Yes" : "No");
        }

    }
}


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

int main() {
  int n;
  cin >> n;
  
  int n_temp = n;
  int fn;
  while(n_temp > 0) {
    fn += (n_temp % 10);
    n_temp /= 10;
  }
  int is_ha = (n % fn == 0);
  
  if(is_ha)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

}


Measured memory_bytes: 384
from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue
from heapq import heappop, heappush
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

a = inpl()
k = inp()
a.sort()
print(a[0] + a[1] + a[2]*2**k)

Measured memory_bytes: 39532
#include<cstdio>
#include<vector>
#include<map>
#include<climits>
#include<algorithm>
#include<iostream>
using namespace std;
typedef pair<int,int> Pt;
#define MAX 1000001
#define fr first
#define sc second
int n,dat[MAX * 2 - 1];
void update(int i,int x){
  i += n - 1;
  dat[i] = x;

  while(i > 0){
    i = (i - 1)/2;
    dat[i] = min(dat[i*2+1],dat[i*2+2]);
  }
}
int query(int a,int b,int k,int l,int r){
  if( r<=a || b <= l ) return INT_MAX;
  if( a<=l && r <= b ) return dat[k];
  return min(query(a,b,k*2+1,l,(l+r)/2),query(a,b,k*2+2,(l+r)/2,r));
}
int main(){
  int q,a,b,c,N;
  for(int i=0;i<MAX*2-1;i++) dat[i] = INT_MAX;
  scanf("%d %d",&N,&q);
  n=1;
  while(n < N) n *= 2;
  while(q--){
    scanf("%d %d %d",&a,&b,&c);
    if(!a) update(b,c);
    else printf("%d\n",query(b,c+1,0,0,n));
  }
}


Measured memory_bytes: 11036
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <list>
#include <cmath>
#include <set>
#define ll long long
using namespace std;
const int INF = 0x7fffffff;
const int maxn = 100000;
int a[maxn+10];
int main()
{
	int n, s, p;
	scanf("%d", &n);
	p = INF;
	s = 0;
	ll sum = 0;
	for (int i = 1; i <= n; ++i) {
		scanf("%d", a + i);
		if (a[i] < 0) {
			++s;
			a[i] = -a[i];
		}
		if (a[i] < p)
			p = a[i];
		sum += a[i];
	}
	if (!(s % 2)) p = 0;
	printf("%lld", sum - 2 * p);
	return 0;
}

Measured memory_bytes: 640
//
// Created by moono on 2018/10/27.
//

#include <algorithm>
#include <iostream>
#include <string>
#include <set>
using namespace std;



int main() {
    string S;
    cin >> S;

    //
    bool has_duplication = false;
    set<char> chars;
    for (int i = 0; i < S.size(); ++i) {
        char c = S[i];
        if(chars.find(c) != chars.end()){
            has_duplication = true;
            break;
        }
        chars.insert(c);
    }

    //
    if(has_duplication){
        cout << "no" << endl;
    }else{
        cout << "yes" << endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
    vector<int>a;
    while(1){
        int b;
        cin>>b;
        if(b==0){
            break;
        }
        a.push_back(b);
    }
    for(int i=0;i<a.size();i++){
        cout<<"Case "<<i+1<<": "<<a[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3280
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
//#define MOD (998244353)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");


signed main(){
    FASTER;
    int k,ans=0;cin>>k;
    for(int i=1;i<=k;i++){
        for(int j=1;j<=k;j++){
            for(int kk=1;kk<=k;kk++){
                ans+=__gcd(__gcd(i,j),kk);
            }
        }
    }
    cout<<ans;
}






Measured memory_bytes: 3604
#include<stdio.h>
#define MAX 10000
#define NIL -1


typedef struct Node{int p,left,right;}N;

N T[MAX];
int n;

void preParse(int u){
	if(u == NIL)return;
	printf(" %d",u);
	preParse(T[u].left);
	preParse(T[u].right);
	
}

void inParse(int u){
	if(u == NIL)return;
	inParse(T[u].left);
	printf(" %d",u);
	inParse(T[u].right);
}

void postParse(int u){
	if(u == NIL)return ;
	postParse(T[u].left);
	postParse(T[u].right);
	printf(" %d",u);
}

int main(void){
	int i,v,l,r,root;

	scanf("%d", &n);
	for(i = 0;i < n; i++){
	T[i].p = NIL;
	}
	
	for(i = 0;i < n;i++){
	scanf("%d %d %d",&v,&l,&r);
	T[v].left = l;
	T[v].right = r;
	if(l != NIL)T[l].p = v;
	if(r != NIL)T[r].p = v;
	}

	for(i = 0;i < n;i++){
	if(T[i].p == NIL){
	root = i;
	}
	}
	
	
	printf("Preorder\n");
	preParse(root);
	printf("\n");
	printf("Inorder\n");
	inParse(root);
	printf("\n");
	printf("Postorder\n");
	postParse(root);
	printf("\n");
	
	return 0;
}



Measured memory_bytes: 2064
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
#define int long long
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;

int A[200010],B[200010],num[200010];
int N,M,W,C,D,E,G;
int ans,ans2,sum,sum2,cnt,cnt2,Max=0,Min=INF;
string S,T;
vector<int> V;
set<int> U;
map<int,int> H;
bool F,Q[200010];

signed main(){
	cin>>N;
	REP(i,N){
		cin>>A[i];
	}
	Max=*max_element(A,A+N);
	REP(i,N){
		if(Max==A[i]&&F==false){
			ans+=A[i]/2;
			F=true;
		}
		else{
			ans+=A[i];
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2304
loop do
	h, w = $<.gets.split.map(&:to_i)
	break if w.zero? and h.zero?

	tile = h.times.map{$<.gets.chomp}

	y = x = 0
	route = []
	loop do
		if route.include?([x, y])
			puts 'LOOP'
			break
		end
		route << [x, y]

		case tile[y][x]
		when '^'; y -= 1
		when 'v'; y += 1
		when '>'; x += 1
		when '<'; x -= 1
		else
			puts "#{x} #{y}"
			break
		end
	end
end

Measured memory_bytes: 6116
/* ****GT_18**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        ll n,k;
        cin>>n>>k;
        if(k==1)
        {
            cout<<0<<endl;
            return 0;
        }
        cout<<n-k;
    }
    return 0;
}

Measured memory_bytes: 256
while True:
    H,W = map(int, input().split())
    if H == 0 and W == 0:
        break
    else:
        for i in range(H):
            for j in range(W):
                if j == W-1 and (i+j) % 2 == 0:
                    print("#")
                elif j == W-1 and (i+j) % 2 == 1:
                    print(".")
                elif (i + j) % 2 == 0:
                    print("#", end = "")
                else:
                    print(".", end = "")
    
        print()


Measured memory_bytes: 7044
#pragma GCC optimize (2)
#include<bits/stdc++.h>
using namespace std;
int arr[2000005];
int main()
{
	int flag;
	deque<int>s;
	int n,k,love;
	long long sum,num;
	sum=1000;
	num=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%d",&arr[i]);
	for(int i=1;i<=n;i++)
	{
		love=0;
		flag=0;
		for(int j=i+1;j<=n;j++)
		{
			if(arr[j]>arr[i])
			{
				flag=1;
				break;
			}
			if(arr[j]<arr[i])
			{
				love=1;
				break;
			}
		}
		if(sum>=arr[i]&&flag==1&&i!=n)
		{
		num=sum/arr[i];
		sum=sum-arr[i]*num;	
		}
		else if(num>0&&love==1||(num>0&&i==n))
		{
			sum=sum+num*arr[i];
			num=0;
		}	
	}
	printf("%lld\n",sum);
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;

const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main(){
    int h,w; cin >> h >> w;
    vector<vector<char>> v(h,vector<char>(w));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++) cin >> v[i][j];
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout << v[i][j];
            if(j == w-1) cout << endl;
        }
        for(int j=0;j<w;j++){
            cout << v[i][j];
            if(j == w-1) cout << endl;
        }
    }
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
#include<string>
#include<set>
#include<string>
#include<climits>
using namespace std;


static int c[10][10];
static int H, W, f;


void floyd()
{
	for (int k = 0; k < 10; k++)
	{
		for (int i = 0; i < 10; i++)
		{
			for (int j = 0; j < 10; j++)
			{
				if (c[i][k] + c[k][j] < c[i][j]) c[i][j] = c[i][k] + c[k][j];
			}
		}
	}
}

int main()
{
	while (scanf("%d%d", &H, &W) != EOF)
	{
		for (int i = 0; i < 10; i++)
		{
			for (int j = 0; j < 10; j++)
			{
				scanf("%d", &c[i][j]);
				//if (i == j) c[i][j] = 1 << 20;
			}
		}
		int ans = 0;
		floyd();
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				scanf("%d", &f);
				if (f != -1) ans += c[f][1];
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r;
    cin >> r;
    cout << 3 * r * r << endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2019&lang=jp>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
ll N,M;
ll solve(){
    ll res = 0;
    vector<pll> dp(N);
    for(auto& in:dp) cin >> in.first >> in.second;
    sort(dp.begin(),dp.end(),[](const pll& o1,const pll& o2){return o1.second > o2.second;});
    for(int i = 0; i < N;i++){
        ll X = min(dp[i].first,M);
        M -= X;
        dp[i].first -= X;
        res += dp[i].first*dp[i].second;
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    while(cin >> N >> M,N|M){
        cout << solve() << endl;
    }
    return 0;
}



Measured memory_bytes: 3284
/***
	chauhan176's code

	DO WHATEVER IT TAKES!!!
	Nothing happens , nothing happens and then everything happens.
	But the thing is nothing happens in air:)-
***/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define ld long double
#define fi first
#define se second
#define mod 1000000007
#define maxn 300005
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define stringio cin.ignore(256, '\n')  //to take string input after taking integer inputs
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

typedef pair<int,int>pi;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const int mx = 1000007;
int main()
{
    fastio;
    int a,b;
    cin>>a>>b;
    if(a>9 || b>9)
        cout<<-1<<endl;
    else
        cout<<a*b<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>


int main(void){

  int N, x;
  int a, b, c;
  int l[3];


  scanf("%d", &N);

  while(N>0){
    scanf("%d %d %d", &a, &b, &c);
    l[0]=a*a;
    l[1]=b*b;
    l[2]=c*c;

    if(l[0]<l[1]){
      x=l[0];
      l[0]=l[1];
      l[1]=x;
    }
    if(l[0]<l[2]){
      x=l[0];
      l[0]=l[2];
      l[2]=x;
    }

    if(l[1]<l[2]){
      x=l[1];
      l[1]=l[2];
      l[2]=x;
    }


    if(l[0]==l[1]+l[2]){
      printf("YES\n");
    }
    else{
      printf("NO\n");
    }

    N--;
  
  }

  return(0);
}



Measured memory_bytes: 2028
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <tuple>
#include <utility>
#include <stdlib.h>
#include <set>
#include <map>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define pb push_back
#define mp make_pair
#define setp(x) setprecision(x)
using LL = long long;
using ULL = unsigned long long;

int main() {
	int n, k;
	cin >> n >> k;
	int point = 0;
	double p = 0.0, ans = 0.0;
	rep(i, 1, n + 1) {
		point = i; //ダイスの目を決定
		p = 1.0 / n; //目が出る確率
		//点数がK-1以下のときの処理
		while (point <= k - 1) {
			point *= 2; //点数×2
			p *= 0.5; //表が出る確率
		}
		ans += p; //確率を足し合わせる
	}
	cout << fixed << setp(12) << ans << endl;
	return 0;
}


Measured memory_bytes: 256
//Mir_123
	#include<bits/stdc++.h>
	#include<string>
	#include<vector>
	#include<algorithm>
	#include<map>
	#include<set>
	#include<stack>
	#include<queue>
	#include<iterator>
	using namespace std;
	#define ll long long int
	#define ld long double
	#define pb push_back
	#define mp make_pair
	#define ub upper_bound
	#define lb lower_bound
	#define bin binary_search
	#define vmin *min_element
	#define vmax *max_element
	#define mod 1000000007

	vector<ll>dg[100001],visited(100001,0),dp(100001,0);
	ll dfs(ll indx)
	{
		visited[indx]=1;
		for(ll i=0;i<dg[indx].size();i++)
		{
			if(visited[dg[indx][i]])
				dp[indx]=max(dp[indx],1+dp[dg[indx][i]]);
			else
				dp[indx]=max(dp[indx],1+dfs(dg[indx][i]));
		}
		return dp[indx];
	}
	int main(void)
	{
		ll n,m;
		cin>>n>>m;
		for(ll i=0;i<m;i++)
		{
			ll x,y;
			cin>>x>>y;
			dg[x].pb(y);
		}
		ll ans=INT_MIN;
		for(ll i=1;i<=n;i++)
		{
			if(visited[i])
				continue;
			ans=max(ans,dfs(i));
		}
		cout<<ans;
		return 0;
	}


Measured memory_bytes: 9344
#include <cstdio>
#include <queue>
#include <vector>
#define maxn 200005
using namespace std;

vector<int> G[maxn];
bool vis[maxn];

int bfs(int x)
{
	queue<int> q;
	q.push(x);
	int cnt = 0;
	while(!q.empty())
	{
		x = q.front(); q.pop();
		if(vis[x]) continue;
		vis[x] = true, cnt ++;
		for(int v: G[x])
			q.push(v);
	}
	return cnt;
}

int main(int argc, char** argv)
{
	int n, m;
	scanf("%d%d", &n, &m);
	for(int i=0; i<m; i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	int ans = bfs(0);
	for(int i=1; i<n; i++)
		if(!vis[i])
		{
			int cnt = bfs(i);
			if(cnt > ans)
				ans = cnt;
		}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 14804
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func solve(N int, A, B, C []int) int {
	sum := 0
	prev := -100
	for i := range A {
		j := A[i] - 1
		sum += B[j]
		if i > 0 {
			if j-prev == 1 {
				sum += C[prev]
			}
		}
		prev = j
	}
	return sum
}

func newSplitScanner(r io.Reader) *bufio.Scanner {
	sc := bufio.NewScanner(r)
	sc.Split(bufio.ScanWords)
	return sc
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	var sc = newSplitScanner(os.Stdin)
	n := nextInt(sc)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt(sc)
	}

	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = nextInt(sc)
	}

	c := make([]int, n-1)
	for i := 0; i < n-1; i++ {
		c[i] = nextInt(sc)
	}

	fmt.Println(solve(n, a, b, c))
}


Measured memory_bytes: 640
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <cstdlib>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}





int main() {
	ll A, B, K;
	cin >> A >> B >> K;
	if (B - A >= 2 * K) {
		rep(i, K) {
			cout << A + i << endl;
		}
		rep(i, K) {
			cout << B - K+i+1 << endl;
		}
	}
	else {
		rep(i, B - A + 1) {
			cout << A + i << endl;
		}
	}

}

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

int main()
{
    int N;
    double ans = 0.0, A;
    cin >> N;
    for (int i = 1; i <= N; ++i) {
        cin >> A;
        ans += 1.0 / A;
    }
    ans = 1.0 / ans;
    cout << setprecision(16) << ans << endl;
}


Measured memory_bytes: 256
n, m, k = map(int, input().split())

a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))

sum = 0
for i in b:
    sum += i

ans = 0
j = m
for i in range(0, n+1):
    sum += a[i]
    while j > 0 and sum > k:
        sum -= b[j]
        j -= 1
    if sum <= k:
        ans = max(ans, i+j)

print(ans)

Measured memory_bytes: 120400
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

////////////////////////////////////////////////////////


int main() {
    ll h, w, k; cin >> h >> w >> k;
    vector<string> c(h);
    rep(i, 0, h) cin >> c[i];
    ll ans = 0;
    for(int tmp = 0; tmp < (1<<h); tmp++){
        bitset<8> s(tmp);
        for(int wi = 0; wi < (1<<w); wi++){
            ll cnt = 0;
            bitset<8> t(wi);
            rep(i, 0, h){
                rep(j, 0, w){
                    if(s.test(i) || t.test(j)) continue;
                    if(c[i][j] == '#') cnt++;
                }
            }
            if(cnt == k) ans++;
        }
    }
    co(ans);

    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
#else
	#define DBG(X)
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }

const int MAXN = (int)1e5 + 4321;

ll a[MAXN], n;
ll answ = 0;

ll dp[MAXN][3];

void solve() {
	cin >> n;

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

		if(a[i] > 2) {
			ll old = a[i];
			a[i] = (a[i] & 1 ? 1 : 2);
			answ += (old - a[i]) / 2;
		}
	}

	/*cout << "a: ";

	for(int i = 0; i < n; ++i) {
		cout << a[i] << ' ';
	}

	cout << '\n';*/

	for(int t = 1; t <= 2; ++t) {
		dp[0][t] = -LL_INF;
	}

	for(int pos = 1; pos <= n; ++pos) {
		ll val = a[pos - 1];

		for(int t = 0; t <= 2; ++t) {
			dp[pos][t] = -LL_INF;
		}

		for(int prv = 0; prv <= 2; ++prv) {
			dp[pos][val] = max(dp[pos][val], dp[pos - 1][prv]);

			if(val >= 1 && prv >= 1) {
				dp[pos][val - 1] = max(dp[pos][val - 1], dp[pos - 1][prv] + 1);
			}

			if(val == 2) {
				dp[pos][0] = max(dp[pos][0], dp[pos - 1][prv] + 1);
			}
		}

		/*for(int t = 0; t <= 2; ++t) {
			cout << pos << ' ' << t << ' ' << dp[pos][t] << '\n';
		}*/
	}

	ll best = 0;

	for(int t = 0; t <= 2; ++t) {
		best = max(best, dp[n][t]);
	}

	answ += best;
	cout << answ << '\n';
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 3456
S = gets.to_i
a = [nil, S]

def f(n)
  if n.odd?
    3 * n + 1
  else
    n / 2
  end
end

2.upto(1000000) do |i|
  a[i] = f(a[i - 1])
  if a[1..(i-1)].any? { |aa| aa == a[i] }
    puts i
    break
  end
end


Measured memory_bytes: 1916
#include <iostream>
#include <string>

using namespace std;

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

    int end;
    if (s.length() % 2 == 0)
        end = s.length();
    else
        end = s.length() - 1;

    for (int i = end - 2; end >= 0; i -= 2) {
        bool flag = true;
        int limit = i / 2;
        for (int i = 0; i < limit; ++i) {
            if (s[i] != s[i + limit]) {
                flag = false;
                break;
            }
        }

        if (flag) {
            cout << i << '\n';
            return 0;
        }
    }
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define inf 1000000007
#define double long double
using namespace std;
typedef pair<ll, ll>P;
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
ll mod_pow(ll x, ll n, ll mod) {
	ll bit = 1;
	while (n) {
		if (n & 1)bit = bit * x % mod;
		x = x * x % mod;
		n /= 2;
	}
	return bit;
}
ll a[224514], b[224514];
signed main() {
	ll n, k;
	cin >> n >> k;
	rep(i, n)cin >> a[i];
	rep(i, n)cin >> b[i];
	sort(a, a + n);
	sort(b, b + n);
	ll left = -1, mid, right = 10000000000000;
	ll memo = 0;
	while (right - left > 1) {
		mid = left + (right - left) / 2;
		rep(i, n)memo += max((ll)0,a[n - 1 - i] - (mid / b[i]));
		if (memo > k)left = mid;
		else right = mid;
		memo = 0;
	}
	cout << right << endl;
	ggr
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main() {
  int h, w, n;
  cin >> h >> w >> n;
  if (h < w) swap(h, w);
  cout << (n + (h - 1)) / h << endl;
  return 0;
}

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

using namespace std;

int main() {
	string s; cin >> s;
	
	sort(s.begin(), s.end());
	
	if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) cout << "Yes";
	else cout << "No";
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<math.h>
#include<algorithm>
#include<cmath>
#include<iomanip>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
int main() {
	int n;
	cin >> n;
	vector<ll>a(n);
	vector<ll>b(n);
	int flag = 0;
	rep(i, n) {
		cin >> a[i];
		if (a[i] == 0) {
			flag = 1;
		}
	}
	if (flag == 1) {
		cout << 0 << endl;
		return 0;
	}
	else {
		b[0] = a[0];
		for (int i = 1; i < n; i++) {
			b[i] = b[i - 1] * a[i];
			if (b[i] / a[i] != b[i - 1]) {
				cout << -1 << endl;
				return 0;
			}
		}
		if (b[n - 1] > 1000000000000000000) {
			cout << -1 << endl;
			return 0;
		}
		else {
			cout << b[n - 1] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 4768
use std::env;
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn main() {
    // main の引数
    /*
        引数なしのときargs.len() = 1;
    */
    let args: Vec<String> = env::args().collect();

    let N = read::<i32>();
    if N%10 == 9 || N/10 == 9 {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	int n,a[102],b[102];
	scanf("%d",&n);
	rep(i,n)scanf("%d%d",&a[i],&b[i]);
	
	int ret = 0;
	priority_queue<int,vector<int>,greater<int>> que;
	rep1(i,31){
		rep(j,n)if(a[j] == i)que.push(b[j]);
		while(que.size() > 0 && que.top() < i)que.pop();
		if(que.size() > 0){
			ret ++;
			que.pop();
		}
	}
	cout << (31+ret)*50 << endl;
}

Measured memory_bytes: 1220
/*
  AUTHOR:SOURABH
  CREATED:26:10:19
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<pll , null_type, less< pll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 1000000007
#define MAX 100005
#define M 32
#define PI 3.14159265

using namespace std;
using namespace __gnu_pbds;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    ll n,i,j;
    cin>>n;
    fs(i,1,10)
    {
        fs(j,1,10)
        {
            if(n==i*j)
            {cout<<"Yes";return 0;}
        }
    }
    cout<<"No";
    return 0;
}

















Measured memory_bytes: 256
#include<stdio.h>
int main(){
  	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
  	if(((a*100+b*10+c)%4)==0){
    	printf("YES\n");
    } else{
    	printf("NO\n");
    }
  return 0;
}

Measured memory_bytes: 128