akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

import sys

limit = 1000000

prime01List = [1]*limit
prime01List[0] = 0 # 1 is not prime
for i in xrange(2, int(limit**0.5)+1):
    n = 2*i
    while(n <= limit):
        prime01List[n-1] = 0
        n += i


ansList = [0]*limit
cnt = 0
for i in xrange(limit):
    cnt += prime01List[i]
    ansList[i] = cnt


#for line in ["999999"]:
for line in sys.stdin.readlines():
    List = map(int, line.strip().split())

    n = List[0]
    print ansList[n-1]

Measured memory_bytes: 43668
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
//int dx[4] = { 1,0,0,-1 };
//int dy[4] = { 0,1,-1,0 };
#define MOD 1000000007
#define ARRAY_MAX 100005

const int INF = 1e9 + 7;




int main() {


	ios::sync_with_stdio(false);
	cin.tie(0);

	map<string, int> mp;
	int n, m;
	cin >> n;
	for (int i = 0; i < n ; i++)
	{
		string s;
		cin >> s;
		mp[s]++;
	}
	cin >> m;
	for (int i = 0; i < m; i++)
	{
		string t;
		cin >> t;
		mp[t]--;
	}
	
	int ans = 0;
	for (auto itr : mp)
	{
		if (itr.second > 0) {
			ans = max(ans, itr.second);
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    long long n, a, b, c, d, e;
    cin >> n >>  a >>  b >> c >> d >> e;
    cout << max({ (n - 1) / a, (n - 1) / b, (n - 1) / c, (n - 1) / d, (n - 1) / e }) + 5 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,k;
    int d=0;
    cin>>a>>b>>c>>k;
    if(a>=k){
        d+=k;
        
    }else if(a+b>=k){
        d+=a;
    }else{
        d=a-(k-a-b);
    }
    cout<<d<<endl;
}

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

int main() {
    int temp;
    set<int> st;
    rep(i, 3) {
        cin >> temp;
        st.insert(temp);
    }
    cout << st.size() << endl;
}

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

int dp[500];

vector<pair<int,int> > g[500];

int n,m;
int dfs(int x){
	if( x == n - 1 ) return 0;
	if( dp[x] != -1 ) return dp[x];
	int ans = 0;
	for(int i = 0 ; i < g[x].size() ; i++)
		ans = max(ans,dfs(g[x][i].first)+g[x][i].second);
	return dp[x] = ans;
}
int main(){
	for(int i = 0 ; i < 500 ; i++)
		dp[i] = -1;
	
	cin >> n >> m;
	n += 2;
	for(int i = 0 ; i < m ; i++){
		int a,b,c;
		cin >> a >> b >> c;
		g[a].push_back(make_pair(b,c));
	}
	cout << dfs(0) << endl;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    
    int k[n];
    // int a[n][m] = {0};
    int a[n][m];
    bool ans[m] = {1};
    int tmp;

    rep(i, n){
        rep(j, m){
            a[i][j] = 0;
        }
    }

    rep(i, n){
        cin >> k[i];
        rep(j, k[i]){
            cin >> tmp;
            a[i][tmp-1] = 1;
        }
    }

    int sum = 0;
    int cnt=0;

    rep(j, m){
        sum = 0;
        rep(i, n){
            sum += a[i][j];
        }
        if(sum==n){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N, L;
    cin >> N >> L;
    vector<int> ta(N);
    //リンゴの番号と配列の番号分ずらす必要がある
    for (int i = 0; i < N; i++) {
        ta[i] = L + i;
    }
    int nearzero = 100;
    int sum = 0;
    for (int i = 0; i < N; i++) {
        if (abs(ta[i]) < abs(nearzero)) nearzero = ta[i]; 
        sum += ta[i];
    }
    cout << sum - nearzero << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <cassert>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
    /*int n, x, t; cin >> n >> x >> t;
    int ans = ceil(double(n) / x) * t;
    cout << ans << endl;
    */

    /*string n; cin >> n;
    int s = n.size();
    int num = 0;
    rep(i, s) {
        num += n[i] - '0';
    }
    if (num % 9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    */

    int n; cin >> n;
    ll mx = 0;
    ll ans = 0;
    rep(i, n) {
        ll a; cin >> a;
        mx = max(mx, a);
        if (a < mx) ans += mx - a;
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

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

  std::vector<ll> va(101, 0LL);
  for (ll i = 0; i < 3; i++) {
    ll x;
    std::cin >> x;
    va[x]++;
  }

  ll ans = 0LL;
  for (ll i = 1; i <= 100; i++) {
    if (va[i] > 0) ans++;
  }

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


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

#define FOR(i,a,b) for(int i = (a); i < b; ++i)
#define REP(i,n) for(int i = 0; i < n; ++i)

using ll = long long;
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	cout << "ABC" << n << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = s; i < e; ++i)
#define sort_(a) sort(a.begin(), a.end())
#define rsort(a) sort(a.rbegin(), a.rend())
#define sum(a) accumulate(a.begin(), a.end(), 0LL)
#define __lcm(a, b) std::__detail::__lcm(a, b)
typedef long long ll;
const long mod = 1e9 + 7;

int main(void) {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

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

  long A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  long ans = 0;
  long min_ = min({A, B, C * 2});
  if (A + B > C * 2) {
    int n = abs(X - Y);
    if (X > Y) {
      ans += min(C * 2 * max(X, Y), C * 2 * min(X, Y) + A * n);
    } else {
      ans += min(C * 2 * max(X, Y), C * 2 * min(X, Y) + B * n);
    }
  } else if (min_ == A) {
    ans += A * X;
    ans += min(B, C * 2) * Y;
  } else if (min_ == B) {
    ans += B * Y;
    ans += min(A, C * 2) * X;
  } else {
    ans += C * 2 * max(X, Y);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
ls_w = [input() for _ in range(n)]

for i in range(n-1):
    if (ls_w[i][-1:] != ls_w[i+1][:1]) or (ls_w[i] in ls_w[i+1:]):
        print("No")
        break
    elif i == n - 2:
        print("Yes")

Measured memory_bytes: 3060
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main(){
	char a[N + 1];
	int b[N + 1];
	int na[N + 1];
	int nb[N + 1];
	long long dp[N + 1];
	f(i, N + 1)a[i] = 0;
	int n, k;
	int x, y, z;
	int r[3];
	long long s, ans;
	bool v = true;
	ans = 0;
	scanf("%s", a);
	n = strlen(a);
	f(i, n){
		if (i % 2 == 0 && a[i] != a[0])v = false;
		if (i % 2 == 1 && a[i] == a[0])v = false;
	}
	if (v){
		printf("1\n");
		return 0;
	}
	if (a[0] == 'a')b[0] = 1;
	else b[0] = 2;
	f(i, n-1){
		if (a[i + 1] == 'a')b[i + 1] = (b[i] + 1) % 3;
		else b[i + 1] = (b[i] + 2) % 3;
	}
	r[0] = n;
	r[1] = n;
	r[2] = n;
	for (int i = n - 1; i >= 0; i--){
		na[i] = r[((b[i] + 1) % 3)];
		nb[i] = r[((b[i] + 2) % 3)];
		r[b[i]] = i;
	}
	ans = 0;
	f(i, N)dp[i] = 0;
	dp[r[1]]++;
	dp[r[2]]++;
	for(int i=0;i<n;i++){
		dp[na[i]] = (dp[na[i]] + dp[i]) % MOD;
		dp[nb[i]] = (dp[nb[i]] + dp[i]) % MOD;
		if (b[i] == b[n - 1])ans = (ans + dp[i]) % MOD;
	}

	printf("%lld\n", ans);


	return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
static const int MAXN = 66;
char data[MAXN][MAXN] = {'\0'};
bool vis[MAXN][200] = {0};
vector <char> ans;
int n;
bool cmp(char a , char b)    {return a < b;}
int main()
{
    scanf("%d" , &n);
    for(int i = 0 ; i < n ; ++i)
    {
        scanf(" %s" , data[i]);
    }
    int len = strlen(data[0]);
    for(int i = 0 ; i < len ; ++i)
    {
        char a = data[0][i];
        bool flag = 0;
        bool dou = 1;
        for(int j = 1 ; j < n ; ++j)
        {
            int t = strlen(data[j]);flag = 0;
            for(int w = 0 ; w < t ; ++w)
            {
                if(data[j][w] == a)
                {
                    data[j][w] = 'A';
                    flag = 1;
                    break;
                }
            }
            if(!flag)
            {
                dou = 0;
                break;
            }
        }
        if(dou)
            ans.push_back(a);
    }
    sort(ans.begin() , ans.end() , cmp);
    int si = ans.size();
    for(int i = 0 ; i < si ; ++i)
        printf("%c" , ans[i]);
    printf("\n");
}


Measured memory_bytes: 256
using System;

class Program {
    static void Main (string[] args) {
        

        string[] a1 = Console.ReadLine ().Split (' ');
        double W = double.Parse(a1[0]);
        double H = double.Parse(a1[1]);
        double x = double.Parse(a1[2]);
        double y = double.Parse(a1[3]);
        
        int rtn2 =0;
        double rtn1 =  W * H /2; 
        
        if(x == W/2 && y == H/2){
            rtn2 = 1;
        }else{
            rtn2 = 0;
        }

        //Console.WriteLine(ans);
        Console.WriteLine(rtn1 + " " + rtn2);
    }
}

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

const int M = 1e9+7;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, k; cin >> n >> k;
    ll ans = 0;
    for (ll i = k; i <= n+1; i++) {
        ll mn = i*(i-1)/2;
        ll mx = (n-i+1+n)*i/2;
        ans += (mx-mn+1);
        ans %= M;
        //cout << i << ": " << mn << ' ' << mx << '\n';
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3628
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <numeric>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
//#define int long long
#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 loop(s, v, it) for (s::iterator it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (int i = head[x]; i; i = e[i].nxt)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, sum) memset(a, sum, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define pof pop_front
#define pob pop_back
#define fi first
#define se second
#define iv inline void
#define enter cout << endl
#define siz(x) ((int)x.size())
#define file(x) freopen(#x".in", "r", stdin),freopen(#x".out", "w", stdout)
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <int, int> pii ;
typedef vector <int> vi ;
typedef vector <pii> vii ;
typedef queue <int> qi ;
typedef queue <pii> qii ;
typedef set <int> si ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int N = 5010 ;
const int INF = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const int MOD = 1000000007 ;
const double eps = 1e-7 ;
void print(int x) { cout << x << endl ; exit(0) ; }
void PRINT(string x) { cout << x << endl ; exit(0) ; }
void douout(double x){ printf("%lf\n", x + 0.0000000001) ; }
template <class T> void chmin(T &a, T b) { if (a > b) a = b ; }
template <class T> void chmax(T &a, T b) { if (a < b) a = b ; }
template <class T> void upd(T &a, T b) { (a += b) %= MOD ; }
template <class T> void mul(T &a, T b) { a = (ll) a * b % MOD ; }

int a[N], vis[N][N] ;
ll dp[N][N] ; // dp[i][j] 表示将第 i 个数搬移到前 j 个位置的最小价值
int n, ca, cb ;

ll dfs(int i, int j) {
	if (i == n + 1) return 0 ;
	if (vis[i][j]) return dp[i][j] ;
	vis[i][j] = 1 ; dp[i][j] = linf ;
	if (j == 1 || a[j - 1] < a[i]) {
		chmin(dp[i][j], dfs(i + 1, i + 1)) ;
		chmin(dp[i][j], dfs(i + 1, j) + ca) ;
	} else {
		chmin(dp[i][j], dfs(i + 1, j) + cb) ;
	}
	return dp[i][j] ;
}

signed main(){
//	freopen("test.in", "r", stdin) ;
//	freopen("test.out", "w", stdout) ;
	scanf("%d%d%d", &n, &ca, &cb) ;
	rep(i, 1, n) scanf("%d", &a[i]) ;
	printf("%lld\n", dfs(1, 1)) ;
	return 0 ;
}

/*
写代码时请注意：
	1.ll？数组大小，边界？数据范围？
	2.精度？
	3.特判？
	4.至少做一些
思考提醒：
	1.最大值最小->二分？
	2.可以贪心么？不行dp可以么
	3.可以优化么
	4.维护区间用什么数据结构？
	5.统计方案是用dp？模了么？
	6.逆向思维？
*/



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

int main(){
    int X;
    cin >> X;
    if(X>=400 && X<= 599) cout << 8 << endl;
    else if(X>=600 && X<= 799) cout << 7 << endl;
    else if(X>=800 && X<= 999) cout << 6 << endl;
    else if(X>=1000 && X<= 1199) cout << 5 << endl;
    else if(X>=1200 && X<= 1399) cout << 4 << endl;
    else if(X>=1400 && X<= 1599) cout << 3 << endl;
    else if(X>=1600 && X<= 1799) cout << 2 << endl;
    else if(X>=1800 && X<= 1999) cout << 1 << endl;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int inf = INT_MAX;
const int MOD = 1000000007;
const long long INF = LLONG_MAX;
const long long MINF = LLONG_MIN;

// -------------------------------------------------------
// 少し多めに確保すること
// ぴったりだと正しく動かないので注意
const long long MAX_V = 1010101;

struct edge {
  long long to, cost;
};

using Pll = pair<long long, long long>;

long long V;
vector<edge> Graph[MAX_V];
long long dist[MAX_V];

void dijkstra(long long s) {
  priority_queue<Pll, vector<Pll>, greater<Pll>> que;

  // 0-indexedと1-indexedの両方に対応
  fill(dist, dist + MAX_V, INF);

  dist[s] = 0;
  que.push(Pll(0, s));

  while (!que.empty()) {
    auto elem = que.top();
    que.pop();

    auto cv = elem.second;

    if (elem.first > dist[cv]) {
      continue;
    }

    for (auto e : Graph[cv]) {
      if (dist[e.to] > dist[cv] + e.cost) {
        dist[e.to] = dist[cv] + e.cost;
        que.push(Pll(dist[e.to], e.to));
      }
    }
  }
}

bool used[200][200];

ll N, M;

void dfs(int cur, int cost) {
  for (auto nv : Graph[cur]) {
    if (dist[nv.to] == cost + nv.cost) {
      used[cur][nv.to] = true;
      used[nv.to][cur] = true;
      dfs(nv.to, cost + nv.cost);
    }
  }
}

int main() {
  cin >> N >> M;
  rep(i, 0, M) {
    ll a, b, c;
    cin >> a >> b >> c;
    Graph[a].push_back(edge{b, c});
    Graph[b].push_back(edge{a, c});
  }

  repe(i, 1, N) {
    dijkstra(i);
    dfs(i, 0);
  }

  ll ans = 0;
  repe(i, 1, N) {
    auto cv = Graph[i];
    for (auto nv : cv) {
      if (!used[i][nv.to]) {
        ++ans;
      }
    }
  }
  cout << ans / 2 << endl;
}


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

string s;
bool isPalindrome(int l, int r)
{
 if(l >= r)
   return true;
 if(s[l] == s[r])
   return isPalindrome(l + 1, r - 1); 
 return false; 
}
int main() {
  cin >> s;
  int n = s.size();
  	reverse(s.begin(), s.end());
	s.push_back('A');
	reverse(s.begin(), s.end());
	bool ok = isPalindrome(1, n) & isPalindrome(1, (n - 1) / 2) & isPalindrome((n + 3) /2, n) ;
	cout << (ok ? "Yes\n" : "No\n" );

}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define int long long
#define p (int)(1e9 + 7)

int MOD(int a){
	a %= p;
	return a >= 0 ? a : a + p;
}

int MODM(int a, int M){
	a %= M;
	return a >= 0 ? a : a + M;
}

signed main(){
	int N, D, i, j, k;
	char *SK = (char *)malloc(sizeof(char) * 10001);
	scanf("%s", SK);
	for(N = 0; SK[N] != '\0'; N++);
	int *K = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		K[i] = (int)SK[i] - (int)'0';
	}
	scanf("%lld", &D);
	int **dp1 = (int **)malloc(sizeof(int *) * (N + 1));
	int **dp2 = (int **)malloc(sizeof(int *) * (N + 1));
	for(i = N; i >= 0; i--){
//		printf("i = %lld\n", i);
		dp1[i] = (int *)malloc(sizeof(int) * D);
		dp2[i] = (int *)malloc(sizeof(int) * D);
		if(i == N){
			dp1[i][0] = 1;
			dp2[i][0] = 1;
			for(j = 1; j < D; j++){
				dp1[i][j] = 0;
				dp2[i][j] = 0;
			}
		}
		else{
			for(j = 0; j < D; j++){
				dp1[i][j] = 0;
				dp2[i][j] = 0;
				for(k = 0; k < 10; k++){
					dp1[i][j] = MOD(dp1[i][j] + dp1[i + 1][MODM(j - k, D)]);
				}
				for(k = 0; k < K[i]; k++){
					dp2[i][j] = MOD(dp2[i][j] + dp1[i + 1][MODM(j - k, D)]);
				}
				dp2[i][j] = MOD(dp2[i][j] + dp2[i + 1][MODM(j - k, D)]);
//				printf("dp1[%lld][%lld] = %lld\n", i, j, dp1[i][j]);
//				printf("dp2[%lld][%lld] = %lld\n", i, j, dp2[i][j]);
			}
		}
//		printf("\n");
	}
	printf("%lld\n", MOD(dp2[0][0] - 1));
	return 0;
}

Measured memory_bytes: 16384
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N;

// 最大公約数（Greatest Common Divisor）
uint64_t gcd(uint64_t m, uint64_t n)
{
	// ユークリッドの互除法
	for (;;)
	{
		if (0 == m) { return n; }
		n %= m;
		if (0 == n) { return m; }
		m %= n;
	}
}
// 最小公倍数（Least Common Multiple）を返す。
uint64_t lcm(uint64_t m, uint64_t n)
{
	if (0 == m) { return n; }
	if (0 == n) { return m; }
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;
	uint64_t g = 0;
	in >> g;
	for (size_t i = 1; i < N; i++)
	{
		uint64_t a;
		in >> a;
		g = gcd(g, a);
	}
	out << g << endl;

	return 0;
}
#endif


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
int main() {
  map<int, ll> m;
  ll n, k;
  cin >> n >> k;
  int a;
  ll b, sum = 0;
  rep(i, n)
  {
    cin >> a >> b;
    sum += b;
    if (m.find(a) == m.end()) {
      m[a] = b;
    } else {
      m[a] += b;
    }
  }
  for (auto itr = m.rbegin(); itr != m.rend(); ++itr) {
    if (k > sum) {
      itr--;
      cout << itr->first;
      return 0;
    }
    sum -= itr->second;
  }
  cout << m.begin()->first;
}


Measured memory_bytes: 4224
#include <stdio.h>
#include <math.h>
#define M 2000

int solve(int , int);
int A[M],n;

int main(){
    int fact,i,q;

    scanf("%d", &n);
    for(i =0; i < n; i ++){
        scanf("%d", &A[i]);
    }
    scanf("%d", &q);
    for(i =0; i < q; i ++){
        scanf("%d", &fact);
            if(solve(0, fact)){
                printf("yes\n");
            }else printf("no\n");
        }
    return 0;
}

int solve(int i,int m){
    int res;
    if(m == 0){
        return 1;
    }
    if(i >= n){
        return 0;
    }
    res = solve (i + 1,m) || solve (i + 1, m - A[i]);
    return res;
}



Measured memory_bytes: 2052
package main

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

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() (ret string) {

	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			return ""
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

type Utls struct {
}

type uString string

var utls = &Utls{}

func (u *Utls) readLineU() uString {
	return uString(readLine())
}

func (u *Utls) atoi(str string) int {
	r, _ := strconv.Atoi(str)
	return r
}
func (u *Utls) itoa(n int) string {
	r := strconv.Itoa(n)
	return r
}
func (u uString) atoi() int {
	r, err := strconv.Atoi(string(u))
	if err != nil {
		return -1
	}
	return r
}
func (u uString) atoiArr() []int {
	ret := make([]int, 0)

	l := strings.Split(string(u), " ")

	for i := 0; i < len(l); i++ {
		s := (uString(l[i]))

		ret = append(ret, s.atoi())

	}
	return ret
}
func (u uString) String() string {
	return string(u)
}

func main() {
	n:=	utls.readLineU().atoi()

	fmt.Println( (1000 - ( n%1000) ) % 1000)
}



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

int main()
{
    int l,a,b,c,d;
    int n,m;
    cin >>l>>a>>b>>c>>d;
    n=a/c+(a%c==0?0:1);
    m=b/d+(b%d==0?0:1);
    cout << l-max(n,m) << endl;
    return 0;
}



Measured memory_bytes: 3108
import java.util.*;

public class Main{
	
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int n=sc.nextInt(),f=0,ans=0;
    int[] a=new int[n],b=new int[n];
    for(int i=0;i<n;i++){
      a[i]=sc.nextInt();
      b[i]=sc.nextInt();
      if(a[i]>f){
        f=a[i];
        ans=a[i]+b[i];
      }
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 64852
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    ll a,b,n;
    cin>>a>>b>>n;
    if(n<b){
        cout<<a*n/b<<endl;
    }else{
        cout<<a*(b-1)/b<<endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
using namespace std;
int main()
{
    int a,b,c,k,ans=0;
    cin>>a>>b>>c>>k;
    if(k<=a) ans=k;
	else {
		ans=a;
		k-=a;
		if(k>b) ans-=k-b;
	}
	cout<<ans<<endl;
	return 0;

}


Measured memory_bytes: 3632
#include <iostream>
#include <sstream>
#include <stdio.h>
//#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))

using namespace std;
int GCD(lli a, lli b) {
	lli x = more(a, b);
	lli y = less(a, b);
	lli r = x % y;
	while (r > 0) {
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}

int main(void)
{
	lli N, M; cin >> N >> M;
	string S, T; cin >> S >> T;
	int gcd = GCD(N, M);
	lli ans = (lli)N * M / gcd;
	int alpha = N / gcd, beta = M / gcd;
	rep(i, 0, gcd) {
		if (S[alpha * i] != T[beta * i]) {
			ans = -1;
			break;
		}
	}


	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 512
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	nk := nextIntArray()
	n, k := nk[0], nk[1]
	h := make([]int, n)
	for i := 0; i < n; i++ {
		h[i] = nextInt()
	}
	sort.Ints(h)

	diff := 1<<31 - 1
	for i := 0; i < n-k+1; i++ {
		if d := h[i+k-1] - h[i]; d < diff {
			diff = d
		}
	}
	fmt.Println(diff)

}

func lcm(a, b int64) int64 {
	return (a / gcd(a, b)) * b
}

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

const size = 1000000

var reader = bufio.NewReaderSize(os.Stdin, size)

func nextLine() string {
	var line, buffer []byte
	isPrefix := true
	var err error
	for isPrefix {
		line, isPrefix, err = reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
	}
	return string(buffer)
}
func nextStringArray() []string {
	return strings.Split(nextLine(), " ")
}
func nextInt() int {
	n, _ := strconv.Atoi(nextLine())
	return n
}

func nextIntArray() []int {
	s := strings.Split(nextLine(), " ")
	n := len(s)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i], _ = strconv.Atoi(s[i])
	}
	return a
}

func min(i, j int) int {
	if i > j {
		return j
	}
	return i
}

func max(i, j int) int {
	if i < j {
		return j
	}
	return i
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
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++)
typedef int64_t Int;

int main(){
  string S, T, U;
  cin >> S >> T;
  U = T + S;
  
  cout << U << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, A, B;
  cin>>N>>A>>B;
  cout<<min(A, B)<<" "<<max(0, A+B-N)<<endl;
}



Measured memory_bytes: 3568
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] p = new int[N];
            for (int i = 0; i < N; i++) {
                p[i] = in.nextInt() - 1;
            }
            int[] a = new int[N];
            int[] b = new int[N];
            for (int i = 0; i < N; i++) {
                a[i] = 40000 * i;
                b[N - 1 - i] = 40000 * i;
            }
            for (int i = 0; i < N; i++) {
                a[p[i]] += i;
            }

//            int[] sum = new int[N];
//            for (int i = 0; i < N; i++) {
//                sum[i] = a[i] + b[i];
//            }
//            for (int i = 0; i < N; i++) {
//                if (i - 1 >= 0 && a[i - 1] >= a[i]) {
//                    Utils.debug("a[i - 1] >= a[i]");
//                }
//                if (i - 1 >= 0 && b[i - 1] <= b[i]) {
//                    Utils.debug("b[i - 1] <= b[i]");
//                }
//                if (i - 1 >= 0 && sum[p[i - 1]] >= sum[p[i]]) {
//                    Utils.debug("sum[p[i - 1]] >= sum[p[i]]");
//                }
//            }

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < N; i++) {
                if (i > 0) {
                    sb.append(" ");
                }
                sb.append(a[i] + 1);
            }
            sb.append("\n");
            for (int i = 0; i < N; i++) {
                if (i > 0) {
                    sb.append(" ");
                }
                sb.append(b[i] + 1);
            }
            System.out.println(sb.toString());
        }
    }
}


Measured memory_bytes: 42676
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w,res=0;
  cin>>h>>w;
  vector<string> s(h);
  vector<vector<int>> mh(h,vector<int>(w,0)), mv(h,vector<int>(w,0));;
  for(auto& str:s)cin>>str;
  for(int i=0;i<h;++i){
    int cnt=0;
    for(int j=0;j<w;++j){
      if(s[i][j]=='#'){
        if(cnt)mh[i][j-1]=cnt;
        cnt=0;
      }
      else cnt++;
    }
    if(s[i][w-1]=='.'&&cnt)mh[i][w-1]=cnt;
  }
  for(int i=0;i<h;++i){
    int cnt=0;
    for(int j=w-1;j>=0;--j){
      if(s[i][j]=='#')cnt=0;
      else{
        cnt=max(cnt,mh[i][j]);
        mh[i][j]=cnt;
      }
    }
  }
  
  for(int i=0;i<w;++i){
    int cnt=0;
    for(int j=0;j<h;++j){
      if(s[j][i]=='#'){
        if(cnt)mv[j-1][i]=cnt;
        cnt=0;
      }
      else cnt++;
    }
    if(s[h-1][i]=='.'&&cnt)mv[h-1][i]=cnt;
  }
  for(int i=0;i<w;++i){
    int cnt=0;
    for(int j=h-1;j>=0;--j){
      if(s[j][i]=='#')cnt=0;
      else{
        cnt=max(cnt,mv[j][i]);
        mv[j][i]=cnt;
      }
    }
  }
  for(int i=0;i<h;++i)for(int j=0;j<w;++j)res=max(res,mh[i][j]+mv[i][j]);
  cout<<res-1;
}

Measured memory_bytes: 35712
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a) begin(a),end(a)
#define FOR(x,val,to) for(int x=(val);x<int((to));++x)
#define FORE(x,val,to) for(auto x=(val);x<=(to);++x)
#define FORR(x,arr) for(auto &x: arr)
#define FORS(x,plus,arr) for(auto x = begin(arr)+(plus); x != end(arr); ++x)
#define FORREV(x,plus,arr) for(auto x = (arr).rbegin()+(plus); x !=(arr).rend(); ++x)
#define REE(s_) {cout<<s_<<'\n';exit(0);}
#define GET(arr) for(auto &i: (arr)) sc(i)
#define whatis(x) cerr << #x << " is " << (x) << endl;
#define e1 first
#define e2 second
#define INF 0x7f7f7f7f
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::vector<std::string> vs;
typedef int64_t ll;
typedef uint64_t ull;
#define umap unordered_map
#define uset unordered_set
using namespace std;
using namespace __gnu_pbds;
 
#ifdef ONLINE_JUDGE
#define whatis(x) ;
#endif
#ifdef _WIN32
#define getchar_unlocked() _getchar_nolock()
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
template<class L, class R> ostream& operator<<(ostream &os, map<L, R> P) { for(auto const &vv: P)os<<"("<<vv.first<<","<<vv.second<<")"; return os; }
template<class T> ostream& operator<<(ostream &os, set<T> V) { os<<"[";for(auto const &vv:V)os<<vv<<","; os<<"]"; return os; }
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os<<"[";for(auto const &vv:V)os<<vv<<","; os<<"]"; return os; }
template<class L, class R> ostream& operator<<(ostream &os, pair<L, R> P) { os<<"("<<P.first<<","<<P.second<<")"; return os; }
inline int fstoi(const string &str){auto it=str.begin();bool neg=0;int num=0;if(*it=='-')neg=1;else num=*it-'0';++it;while(it<str.end()) num=num*10+(*it++-'0');if(neg)num*=-1;return num;}
inline void getch(char &x){while(x = getchar_unlocked(), x < 33){;}}
inline void getstr(string &str){str.clear(); char cur;while(cur=getchar_unlocked(),cur<33){;}while(cur>32){str+=cur;cur=getchar_unlocked();}}
template<typename T> inline bool sc(T &num){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){if(c == EOF) return false;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; return true;}template<typename T, typename ...Args> inline void sc(T &num, Args &...args){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; sc(args...); }
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; //s.find_by_order(), s.order_of_key() <- works like lower_bound
template<typename T> using ordered_map = tree<T, int, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 1000001
 
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    string s;
    cin >> n >> s;
    s.erase(unique(all(s)),s.end());
    cout << s.size();
}



Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		
		long a=sc.nextLong();
		long b=sc.nextLong();
		long c=sc.nextLong();
		long d=sc.nextLong();
		a=a-1;
 
        long s1=a-(a/c+a/d-a/lcm(c,d));
        long s2=b-(b/c+b/d-b/lcm(c,d));
 
        System.out.println(s2-s1);
        sc.close();
    }
 
    static long gcd(long a,long b) {
        if(b%a==0) {
            return a;
        }
        return gcd(b%a,a);
    }
 
    static long lcm(long a,long b) {
        return a*b/gcd(a,b);
	}

}


Measured memory_bytes: 27044
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main {
    private static int MIN = -1000000;
    private static int MAX = 1000000;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try {
            int n = Integer.parseInt(sc.nextLine());
            int min = MAX;
            int max = MIN;
            double total = 0;
            while (sc.hasNext()) {
                int a = sc.nextInt();
                max = Integer.max(a, max);
                min = Integer.min(a, min);
                total += a;
            }
            System.out.printf("%d %d %.0f\n", min, max, total);
        } catch (NoSuchElementException
                | NumberFormatException e) {
            System.out.println(e);
        }
    }
}



Measured memory_bytes: 43128
#include <iostream>
#include <map>
using namespace std;
typedef pair<int, int> P;
int main(void){
    int h, w, n;
    long long v[10];
    map<P, int> m;
    cin >> h >> w >> n;
    for(int i=0;i<n;i++){
        int a, b;
        cin >> a >> b;
        for(int j=0;j<9;j++){
            int na = a + j/3 - 1;
            int nb = b + j%3 - 1;
            if(1 < na && na < h && 1 < nb && nb < w){
                m[P(na, nb)]++;
            }
        }
    }
    
    fill(v, v+10, 0);
    for(auto x : m){
        v[(x.second)]++;
        //cout << x.first.first << " " << x.first.second << " " << (x.second) << endl;
    }
    
    v[0] = (long long)(h-2) * (w-2);
    for(int j=1;j<=9;j++){
        v[0] -= v[j];
    }
    
    for(int j=0;j<=9;j++){
        cout << v[j] << endl;
    }
}


Measured memory_bytes: 56448
<?php
$N = trim(fgets(STDIN));
//list($A,$B) =  explode(" ",trim(fgets(STDIN)));
$A =  explode(" ",trim(fgets(STDIN)));

$st = 1;
foreach($A as $v) {
  if ($v == $st) $st++;
}
if ($st==1) {
  printf("-1\n");
}
else {
  printf("%d\n",$N-$st+1);
}


Measured memory_bytes: 18932
N,*as = `dd`.split.map &:to_i

# corner case
if as.max < 0
  mx = as.max
  # p as
  ops = []
  j = (0...N).max_by{ |i| as[i] }
  p as[j]
  (j+1...N).reverse_each{ |i| 
    ops << i+1 
    as.delete_at(i)
  }
  (0...j).each{ |i| 
    ops << 1 
    as.delete_at(0)
  }
  fail if as[0] != mx
  puts ops.size, ops
  exit
end

ss = [0,0]
(0...N).each{ |i|
  ss[i%2] += as[i] >= 0 ? as[i] : 0
}

eo = [0,1].max_by{ |i| ss[i] }

Max = ss[eo]
p Max
# p [Max, eo], as
ops = []

(0...N).reverse_each{ |i|
  next if i % 2 != eo
  next if as[i] >= 0
  ops << i+1
  if 0 < i && i < as.size-1
    as[i] = as[i-1] + as[i+1]
    as.delete_at(i+1)
    as.delete_at(i-1)
  else
    as.delete_at(i)   
    eo ^= 1 if i == 0
  end
  # p as
}

(0...as.size).reverse_each{ |i|
  next if i % 2 == eo
  ops << i+1
  if 0 < i && i < as.size-1
    as[i] = as[i-1] + as[i+1]
    as.delete_at(i+1)
    as.delete_at(i-1)
  else
    eo ^= 1 if i == 0
    as.delete_at(i)   
  end  
  # p as
}

# p ss, eo, as
puts ops.size, ops
fail if as[0] != Max


Measured memory_bytes: 2420
#!/usr/bin/env python3
import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)


def solve(N: int, A: "List[int]"):
    if N == 1:
        print(0)
    else:
        m1 = max(A)
        max_idx = np.where(np.array(A) == max(A))
        if len(max_idx[0]) > 1:
            for i in range(N):
                print(m1)
        else:
            m2 = sorted(set(A))[-2]
            max_idx = np.argmax(np.array(A))
            for i in range(N):
                if i == max_idx:
                    print(m2)
                else:
                    print(m1)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools
# (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()


Measured memory_bytes: 26676
#include<stdio.h>

int main(){
	
	int n;
	scanf("%d",&n);
	if(n%1000==0) puts("0");
	else{
		int sisa=n/1000;
		sisa++;
		sisa=(sisa*1000)-n;
		printf("%d",sisa);
	}
	return 0;
}

Measured memory_bytes: 1724
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Numerics;

namespace msol2020
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            if (File.Exists("input.txt"))
            {
                Console.SetIn(new StreamReader("input.txt"));
            }
            solve_msol2020C();
            Console.Out.Flush();
        }
        public static void solve_msol2020D()
        {
        }

        public static void solve_msol2020C()
        {
            int[] nk = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int n = nk[0];
            int k = nk[1];
            List<string> ans = new List<string>();
            for (int i = 0; i < n; i++)
            {
                if (i + 1 > k)
                {
                    if (a[i - k] <a[i])
                    {
                        ans.Add("Yes");
                    }
                    else
                    {
                        ans.Add("No");
                    }
                }
            }
            for (int i = 0; i < ans.Count; i++)
            {
                Console.WriteLine(ans[i]);
            }
        }

        public static void solve_msol2020B()
        {
            int[] abc = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int k = Convert.ToInt32(Console.ReadLine());
            int a = abc[0];
            int b = abc[1];
            int c = abc[2];
            while (k > 0 && b >= c)
            {
                c = c * 2;
                k--;
            }
            while (k > 0 && a >= b)
            {
                b = b * 2;
                k--;
            }
            while (k > 0 && b >= c)
            {
                c = c * 2;
                k--;
            }
            if (a < b && b < c)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

        }

        public static void solve_msol2020A()
        {
            int x = Convert.ToInt32(Console.ReadLine());
            int q = 8;
            for (int i = 400; i <= 1800; i += 200)
            {
                if (i <= x && i + 199 >= x)
                {
                    Console.WriteLine(q);
                    break;
                }
                q--;
            }

        }
    }
}

Measured memory_bytes: 50820
#include<bits/stdc++.h>
 
#define array_size(a) (sizeof(a)/sizeof(a[0]))
#define lpi(n) for(int i=0; i<n; i++)
#define lpiv(v,n) for(int i=v; i<n; i++)
#define lpj(n) for(int j=0; j<n; j++)
#define lpjv(v,n) for(int j=v; j<n; j++)
#define iii pair<int,pair<int,int>>
#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mp make_pair
#define vi vector<int>
#define vip vector<pair<int,int>>
#define pqig priority_queue<int>
#define pqil priority_queue<int, vector<int>, greater<int>>
#define filein(ff) freopen(ff, "r", stdin)
#define fileout(ff) freopen(ff, "w", stdout)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); 
using namespace std;
 
typedef long long ll;
 
 
ll fastpow(ll nodess, ll num) {
    if (!num)
        return 1;
    if (num % 2)
        return nodess * fastpow(nodess, num - 1)/*%mod*/;
    ll p = fastpow(nodess, num / 2);
    // p %= mod;
    p *= p;
    // p %= mod;
    return p;
}
 
ll my_mod(ll num, ll mod) {
    ll reto = num % mod;
    while (reto < 0)
        reto += mod;
    return reto;
}
 
ll gcd(ll u, ll v) { return !u ? v : gcd(v % u, u); }
 
ll dist(pair<ll, ll> u, pair<ll, ll> v) {
    return abs(u.fi - v.fi)  + abs(u.se - v.se);
}

ll lcm(ll a, ll b){
    return a / __gcd(a, b) * b;
}


string lcs(string s, string t){

    int dp[s.length()+1][t.length()+1];
    string ans="";

    for(int i =0; i <= s.length(); i++){
        for(int j = 0; j <= t.length(); j++){
            if(i==0 || j==0) dp[i][j] = 0;
            else if(s[i-1]==t[j-1]){
                dp[i][j] = dp[i-1][j-1]+1;
            } else {
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }

    int i = s.length(), j = t.length();
    while (i > 0 && j > 0) { 
        if (s[i-1] == t[j-1]){ 
            ans+= s[i-1];
            i--; 
            j--;     
        } 

        else if (dp[i-1][j] > dp[i][j-1]) 
            i--; 
        else
            j--; 
    } 
    reverse(ans.begin(), ans.end());
    return ans;
}

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

    string s,t;
    cin >> s>>t;

    cout << lcs(s,t) << endl;

    return 0; 
}   

Measured memory_bytes: 35456
#include<stdio.h>
int main()
{
	long s, c, sum=0;
	
	
	// スペース区切りの整数の入力
	scanf("%ld %ld", &s, &c);

	if (s*2 < c)
	{
		
		sum += s;
		c -= 2*s;
		sum += (c / 4);
	}
	else
	{
		sum = c / 2;
	}
	
	// 出力
	printf("%ld", sum);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#define MAX 100001
#define NIL -1

struct Node{
  int p;
  int l;
  int r;
};

struct Node T[MAX];
int n;
int D[MAX];

void print(int);
void Depth(int,int);


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

  int i,j,d,v,c,l,r;

  scanf("%d",&n);

  // ?????????
  for( i = 0 ; i < n ; i++ ){
    T[i].p = T[i].l = T[i].r = NIL;
  }

  // ??\???
  for( i = 0 ; i < n ; i++ ){

    scanf("%d %d",&v,&d);

    for( j = 0 ; j < d ; j++ ){
      scanf("%d",&c);
      if( j == 0 ){
        T[v].l = c;
      }else{
        T[l].r = c;
      }
      l = c;
      T[c].p = v;
    }

  }

  for( i = 0 ; i < n ; i++ ){
    if( T[i].p == NIL ){
      r = i;
    }
  }


  Depth(r,0);

  for( i = 0 ; i < n ; i++ ){
    print(i);
  }

  return 0;
}

void print(int i){

  int c;

  printf("node %d: ",i);
  printf("parent = %d, ",T[i].p);
  printf("depth = %d, ",D[i]);

  if( T[i].p == NIL ){
    printf("root, ");
  }else if( T[i].l == NIL ){
    printf("leaf, ");
  }else{
    printf("internal node, ");
  }

  printf("[");
  c = T[i].l;

  while( c != NIL ){
    if( c == T[i].l ){
      printf("%d",c);
    }else{
      printf(", %d",c);
    }
    c = T[c].r;
  }
  printf("]\n");

}


void Depth(int i, int dep){
  D[i] = dep;
  if( T[i].r != NIL ){
    Depth(T[i].r,dep);
  }

  if( T[i].l != NIL ){
    Depth(T[i].l,dep+1);
  }

}

Measured memory_bytes: 5296
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
#define REP(i, n) for (Int i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (Int i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<Int, Int>;
template <class T> inline bool chmax(T& a, const T& b) {
    if (a >= b) return false;
    a = b;
    return true;
}
template <class T> inline bool chmin(T& a, const T& b) {
    if (a <= b) return false;
    a = b;
    return true;
}
struct in {
    int n;
    in() {}
    in(int n_) : n(n_){};
    template <class T> operator T() {
        T ret;
        cin >> ret;
        return ret;
    }
    template <class T> operator vector<T>() {
        vector<T> ret(n);
        for (int i = 0; i < n; i++) cin >> ret[i];
        return ret;
    }
};
struct SetupIO {
    SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }
} setup_io;

#ifdef _MY_DEBUG
#include "/Users/knshnb/.competitive_local.hpp"
#else
#define dump(...)
#endif

/**
 *    author:  knshnb
 *    created: Sun Dec  1 21:00:11 JST 2019
 **/

signed main() {
    Int a = in(), b = in();
    Int c = in(), d = in();
    cout << (int)(a != c) << endl;
}


Measured memory_bytes: 256
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long n = in.nextLong();
        long m = in.nextLong();
        PriorityQueue<Long> pq = new PriorityQueue<>(Collections.reverseOrder());
        for (int i = 0; i < n; i++) {
            pq.add(in.nextLong());
        }
        for (int i = 0; i < m; i++) {
            long current = pq.poll();
            pq.add(current/2);
        }
        long res = 0;
        while(!pq.isEmpty()) {
            res += pq.poll();
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 60100
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int N,M;
  cin >> N >> M;
  
  vector<int>food(M);
  int p,k;
  
  for(int i=0;i<N;i++){
    cin >> k;
    for(int j=0;j<k;j++){
      cin >> p;
      food[p-1]++;
    }
  }
  
  int ans = 0;
  for(int i=0;i<M;i++){
    if(food[i] == N)
      ans++;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder out = new StringBuilder();
		while (true) {
			int H = sc.nextInt();
			int W = sc.nextInt();
			if (H == 0 && W == 0)
				break;
			for (int h = 0; h < H; ++h) {
				for (int w = 0; w < W; ++w)
					if ((h + w) % 2 == 0)
						out.append("#");
					else
						out.append(".");
				out.append("\n");
			}
			out.append("\n");
		}
		System.out.print(out);
	}
}


Measured memory_bytes: 27408
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <map>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <set>
#include <queue>
#include <list>

using namespace std;
int ha[100010];
int main()
{
    int n,k,su=0;
    scanf("%d",&n);
    for(int i=0;i<n;++i)
    {
        scanf("%d",&k);
        ++ha[k];
    }
    bool ju=false;
    for(int i=1;i<100001;++i)
    {
        if(ha[i]>1)
        {
            if(ha[i]>2)
            {
                if(ha[i]&1)
                {
                    su+=ha[i]/2;
                    ha[i]=1;
                }
                else
                {
                    su+=ha[i]/2-1;
                    ha[i]=2;
                }
            }
            if(ha[i]==2)
            {
                if(ju)
                {
                    ha[i]=1;
                    su++;
                    ju=false;
                }
                else
                    ju=true;
            }
        }
    }
        if(ju) ++su;
        cout<<n-2*su<<endl;
    return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;
//1125~1330
void solve()
{
  ll n;
  cin >> n;
  vector<ll> a(n);

  ll ans = n;
  int num = 0;
  int si = 0;
  for(int i = 0; i < n; ++i)
  {
    cin >> a[i];
    while((num & a[i]) > 0) 
    {
      num ^= a[si];
      si++;
    }
    num ^= a[i];
    ans += (i - si);
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 4764