akhauriyash/Code-Regression huggingface dataset:
#include <numeric>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<algorithm>
#include <sstream>
using namespace std;
long long inf=100000000000007;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
typedef pair<int,int>  P;
string alph("abcdefghijklmnopqrstuvwxyz");
struct edge{int to,cost;};
vector<edge> G[22];
vector<int> O[10];
char fi[1005][1005];
P sg[10];
int d[1005][1005];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
pair<int,double> s[1005];
int c=0;
int n,k;

signed main(){
    int n;cin>>n;
    int m=n;
    int key=0;
    while(m!=0){
        key+=m%10;
        m/=10;
    }
    if(n%key==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
/*input
7 14
10 5
7 4
11 4
9 8
3 6
6 2
8 9
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

int a[maxn],b[maxn];

int main()
{
	//IOS;
	int n,k;
	cin>>n>>k;
	k++;
	REP(i,n) cin>>a[i]>>b[i];

	ll cur=0;
	ll ans=0;
	for(int i=30;i>=0;i--){
		if(k&(1<<i)){
			ll nw=cur+(1<<i)-1;
			ll meow=0;
			REP(j,n) if(nw>=a[j]&&(nw-a[j]==(nw^a[j]))){
				meow+=b[j];
			}
			ans=max(ans,meow);
			cur+=(1<<i);
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
    int i,j,x,y,size,paper[10][10]={0},ans1=0,ans2=0;
    while(scanf("%d,%d,%d",&x,&y,&size)!=EOF)
    {
        if(x>=0&&x<10&&y>=0&&y<10)
        {
            paper[x][y]++;
            if(x!=0)
                paper[x-1][y]++;
            if(x!=9)
                paper[x+1][y]++;
            if(y!=0)
                paper[x][y-1]++;
            if(y!=9)
                paper[x][y+1]++;
            if(size>1)
            {
            if(x!=0&&y!=0)
                paper[x-1][y-1]++;
            if(x!=0&&y!=9)
                paper[x-1][y+1]++;
            if(x!=9&&y!=0)
                paper[x+1][y-1]++;
            if(x!=9&&y!=9)
                paper[x+1][y+1]++;
            }
            if(size>2)
            {
            if(x!=0&&x!=1)
                paper[x-2][y]++;
            if(x!=9&&x!=8)
                paper[x+2][y]++;
            if(y!=0&&y!=1)
                paper[x][y-2]++;
            if(y!=9&&y!=8)
                paper[x][y+2]++;
            }
        }
    }
    for(i=0;i<10;i++)
        for(j=0;j<10;j++)
        {
            if(paper[j][i]==0)
                ans1++;
            if(paper[j][i]>ans2)
                ans2=paper[j][i];
        }
    /*
    for(i=0;i<10;i++){
        for(j=0;j<10;j++)
            printf("%d ",paper[j][i]);
        printf("\n");
    }
    */

    printf("%d\n%d\n",ans1,ans2);
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> cards(n);
  for(int i=0; i<n; i++){
    cin >> cards.at(i);
  }
  
  sort(cards.begin(), cards.end(), greater<int>());
  int sumA = 0;
  int sumB = 0;
  
  for(int i=0; i<cards.size(); i++){
    if(i%2==0){
      sumA += cards[i];
    }else{
      sumB += cards[i];
    }
  }
  
  cout << sumA - sumB <<endl;

  
}


Measured memory_bytes: 256
# 入力が多いので高速化が図れる
import sys
input = sys.stdin.readline

n, m = map(int, input().split())

# 1-indexed にしたいので最初に入れておく
ab = [[0, 0]]
for _ in range(m):
    a, b = map(int, input().split())
    ab.append([a, b])


class UnionFind:
    # http://at274.hatenablog.com/entry/2018/02/02/173000
    def __init__(self):
        # 最初は 数字 == 根(root) (== 一番上)
        self.root = [i for i in range(n + 1)]
        # 木の大きさを保存しておく
        self.size = [1] * (n + 1)

        self.rank = [0] * (n + 1)

    def find(self, x):
        # 番号と根が一致すれば探索しなくていい
        if self.root[x] == x:
            return x
        # 根ではないならどれが根なのかを探索する
        # が，深くなってくると再帰し続けて時間がかかるのでそれなら順次 self.root[x] を書き換えて計算を少なくしていく
        else:
            self.root[x] = self.find(self.root[x])
            return self.root[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.root[x] = y
        else:
            self.root[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same_check(self, x, y):
        return self.find(x) == self.find(y)


uf = UnionFind()

# 解答は逆から求めていくのでとりあえず ans にためておく
# 初期状態 (=最後の出力) はすべての島がつながっていない状態なので
# 不便度は (n + (n - 1)) // 2 で出る
ans = [(n * (n - 1)) // 2]
s = ans[0]

for i in reversed(range(1, m + 1)):
    a, b = ab[i]
    if not uf.same_check(a, b):
        root_a = uf.find(a)
        root_b = uf.find(b)
        uf.union(a, b)
        s -= uf.size[root_a] * uf.size[root_b]
        tmp = uf.size[root_a] + uf.size[root_b]
        uf.size[root_a] = tmp
        uf.size[root_b] = tmp
    ans.append(s)

for i in reversed(range(m)):
    print(ans[i])

# よくわからん！

Measured memory_bytes: 30312
#include<iostream>
#include<cstdio>
#include<cstring>
const int N=10;
bool got(){for(char c;;)if((c=getchar())=='.')return 0;else if(c=='#')return 1;}
bool G[N][N];
int cnt[N*2];
int n,m;
int main()
{
//	freopen("in","r",stdin);
	scanf("%d%d",&n,&m);
	bool flag=1;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			G[i][j]=got();
			if((i>1 || j>1) && G[i][j] && !G[i-1][j] && !G[i][j-1])
				flag=0;
			cnt[i+j]+=G[i][j];
		}

	for(int i=2;i<=n+m;i++)
		flag&=(cnt[i]==1);
	printf("%s\n",flag?"Possible":"Impossible");
	return 0;
}


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

vector<int> AdjList[200005];
int dist[200005];

void bfs(int s){
    memset(dist, -1, sizeof(dist));
    dist[s] = 0;
    queue<int> q;
    q.push(s);
    while(!q.empty()){
        int u = q.front(); q.pop();
        for(int v: AdjList[u]){
            if(dist[v] == -1){
                dist[v] = dist[u]+1;
                q.push(v);
                //printf("debug: %d %d\n", v, dist[v]);
            }
        }
    }
}

int main(){
    int N;
    scanf("%d", &N);

    for(int i = 0; i < N-1; i ++){
        int a, b;
        scanf("%d%d", &a, &b);
        //printf("%d %d\n", a, b);
        AdjList[a].push_back(b);
        AdjList[b].push_back(a);
    }

    bfs(1);
    int maxDist = 0;
    int indx = 0;
    for(int i = 1; i <= N; i ++){
        if(dist[i] > maxDist){
            maxDist = dist[i];
            indx = i;
        }
    }
    bfs(indx);
    maxDist = 0;
    for(int i = 1; i <= N; i ++){
        if(dist[i] > maxDist){
            maxDist = dist[i];
        }
    }
    if(maxDist%3 == 1){
        printf("Second");
    }else{
        printf("First");
    }
}




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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m, q;
    cin >> n >> m >> q;
    vector<vector<long long>> p(n + 1, vector<long long> (n + 1));
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        p[a][b]++;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            p[i][j] += p[i][j - 1];
        }
    }
    for (int i = 0; i < q; i++) {
        int a, b;
        cin >> a >> b;
        long long res = 0;
        for (int j = a; j <= b; j++) {
            res += p[j][b];
        }
        cout << res << endl;
    }


}


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

#define w cout
#define e '\n'
#define int long long
#define sz(x) (int)x.size()
#define re return 
#define vi vector<int>
#define vii vector<pair<int ,int > >
#define F first
#define S second
#define pussy push_back
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

const int N = 1e6 , mod = 1e9 + 7;


signed main() {
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);	
	int n; cin >> n;
	string ans;
	while(n){
		int left = n % 26;
		if(left == 0) ans.push_back('z') , n--;
		else
		ans.push_back('a'+left - 1);
		n/=26;
	}
	reverse(begin(ans),end(ans));
	w << ans;
}


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

#define fi first
#define se second
#define show(x) cerr << #x << "=" << "\n"
typedef long long ll;
typedef unsigned long long ull;

using namespace std;
const ll llinf = LLONG_MAX;
const ull ullinf = ULLONG_MAX;

ll a, b, c, k;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  //FILE *stream2;
  stream1 = freopen("in.txt", "r", stdin);
  //stream2 = freopen("out.txt", "w", stdout);
  if (stream1 == NULL) return 0;
  //if (stream2 == NULL) return 0;:w
#endif
  cin >> a >> b >> c >> k;
  if (k & 1) {
    cout << b - a << endl;
  } else {
    cout << a - b << endl;
  }
#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
  fclose(stream1);
  //fclose(stream2);
#endif
  return 0;
}



Measured memory_bytes: 256
N, Q = map(int, input().split())
S = input()
q =[]
temp = [0] * (N+1)
tmp = 0
for i in range(1,N):
    if S[i-1] == "A":
        if S[i] == "C":
            tmp +=1
    temp[i+1] = tmp
for j in range(Q):
    inp = input().split()
    print(temp[int(inp[1])] - temp[int(inp[0])])

Measured memory_bytes: 6060
#include<bits/stdc++.h>
#define int long long
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
        string s; cin>>s;
        vector<char> v;
        REP(i,s.size()){
                if(s[i]=='B'){
                        if(!v.empty()) v.pop_back();
                }
                else v.push_back(s[i]);
        }
        REP(i,v.size()) cout<<v[i]; cout<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N;
  cin >> N;
  string s;
  cin >> s;
  vvi dp(N,vi(N));
  drep(j,N) {
    drep(i,N) {
      if(j==N-1||i==N-1) {
        if(s[i]==s[j]) {
          dp[i][j] = 1;
        } else {
          dp[i][j] = 0;
        }
        continue;
      }
      if(s[i]==s[j]) {
        dp[i][j] = dp[i+1][j+1]+1;
      } else {
        dp[i][j] = 0;
      }
    }
  }
  int ans = 0;
  rep(i,N) {
    srep(j,i+1,N) {
      if(j-dp[i][j]>=i) {
        ans = max(ans,dp[i][j]);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 100224
#include "bits/stdc++.h"
using namespace std;
#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
typedef long long ll;

const int INF = 1e9;
const long long LLINF = 1e18;

int n, p;
int a[51];
int main() {
    int even=0;
    cin>>n>>p;
    REP(i, 0, n){
        cin>>a[i];
        if(a[i]%2==0) even++;
    }

    if(even==n && p==0) cout<<(1LL<<n)<<endl;
    else if(even==n && p==1) cout<<0<<endl;
    else cout<<(1LL<<(n-1))<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    private struct Pair { public int x, y; public Pair(int xx, int yy) { x = xx; y = yy; } }
    private static int[] dx = { 1, 0, -1, 0 };
    private static int[] dy = { 0, -1, 0, 1 };
    public static void Main()
    {
        int N = NextInt();
        long[] A = LineLong();
        long[] memo1 = new long[N];
        long[] memo2 = new long[N];
        memo1[0] = A[0];
        for (int i = 1; i < N; i++)
            memo1[i] = GCD(memo1[i - 1], A[i]);
        Array.Reverse(A);
        memo2[0] = A[0];
        for (int i = 1; i < N; i++)
            memo2[i] = GCD(memo2[i - 1], A[i]);
        Array.Reverse(memo2);
        long ans = Math.Max(memo2[1], memo1[N - 2]);
        for (int i = 1; i < N - 1; i++)
            ans = Math.Max(ans, GCD(memo1[i - 1], memo2[i + 1]));

        //memo1.ToList().ForEach(v => Console.Write(v + " "));
        //Console.WriteLine();
        //memo2.ToList().ForEach(v => Console.Write(v + " "));
        //Console.WriteLine();
        Console.WriteLine(ans);
    }
    public static long GCD(long a, long b)
    {
        if (a < b) GCD(b, a);
        long d = a % b;
        while (b != 0)
        {
            d = a % b;
            a = b;
            b = d;
        }
        return a;
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static char NextChar() { Confirm(); return char.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 28124
#include<bits/stdc++.h>
using namespace std;
const int _=1e5+7;
const int __=3e5+7;
struct com{
  int l,r,len;
}c[__];
int n,m,tr[_],ans;
bool rule(com a,com b){ return a.len<b.len; }
void add(int x,int w){
  for(int i=x;i<=m;i+=i&(-i))
    tr[i]+=w;
}
void modify(int l,int r,int w){
  add(l,w);
  add(r+1,-w);
}
int query(int x){
  int res=0;
  for(int i=x;i;i-=i&(-i))
    res+=tr[i];
  return res;
}
int main(){
  //#ifndef ONLINE_JUDGE
  //freopen("x.in","r",stdin);
  //#endif
  cin>>n>>m;
  for(int i=1;i<=n;i++){
    scanf("%d%d",&c[i].l,&c[i].r);
    c[i].len=c[i].r-c[i].l+1;
  }
  sort(c+1,c+1+n,rule);
  int p=1;
  for(int i=1;i<=m;i++){
    while(p<=n&&c[p].len<i){
      modify(c[p].l,c[p].r,1);
      p++;
    }
    //printf("p: %d\n",p);
    ans=n-p+1;
    for(int j=i;j<=m;j+=i)
      ans+=query(j);
    printf("%d\n",ans);
  }
  return 0;
}


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

typedef unsigned long long ll ;
#define rep (i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

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

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

	ll N, P;
	
	cin >> N >> P;

	ll ret = 1;
	//cout << (ll)pow(P, 1.0 / N) << ";" << P << endl;
	ll rr = (ll)pow(P, 1.0 / N);

	if (pow(rr, N) < P)
	{
		if (pow(rr+1, N) == P)
		{
			rr++;
		}
	}

	for (ll i = rr; i >= 1; i--)
	{
		//cout << i << endl;

		ll tmp = pow(i, N);

		if (P % tmp == 0)
		{
			ret = i;
			break;
		}
		
	}
	
	cout << ret << endl;

	return 0;
}

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

int main() {
  string s;
  cin>>s;
  int cnt0=0,cnt1=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='0') cnt0++;
    else cnt1++;
  }
  cout<<2*min(cnt0,cnt1);
}

Measured memory_bytes: 3720
'use strict'
 
function main(n) {
  let num = n.split("\n")[0]*1;
  let ans = "No"
  for(let s = 0; s<=100; s++ ){
    if(( (num - 7*s ) % 4 === 0)  && (num - 7*s >= 0)){
    	ans = "Yes";
    }
  }
  
  
  console.log(ans);
  
}
 
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001,INF=1<<30;

int main(){

  int N,Q,ans=0;cin>>N>>Q;
    string S;cin>>S;
    string A,B;
    for(int i=0;i<Q;i++){
        string a,b;cin>>a>>b;
        A+=a;
        B+=b;
    }
    int left=0,right=N-1;
    while(left!=right){
        int mid=(left+right)/2;
        int now=mid;
        bool okleft=false,okright=false;
        for(int i=0;i<Q;i++){
            if(A[i]==S[now]){
                if(B[i]=='L') now--;
                else now++;
            }
            if(now==-1){
                okleft=true;
                break;
            }
            if(now==N){
                okright=true;
                break;
            }
        }
        if(okleft) left=mid+1;
        else right=mid;
    }
    
    bool okleft=false,okright=false;
    int now=left;
    for(int i=0;i<Q;i++){
        if(A[i]==S[now]){
            if(B[i]=='L') now--;
            else now++;
        }
        if(now==-1){
            okleft=true;
            break;
        }
        if(now==N){
            okright=true;
            break;
        }
    }
    if(okleft) ans+=left+1;
    else ans+=left;
    
    //cout<<left<<" "<<ans<<endl;
    
    left=0;right=N-1;
    while(left!=right){
        int mid=(left+right)/2;
        int now=mid;
        bool okleft=false,okright=false;
        for(int i=0;i<Q;i++){
            if(A[i]==S[now]){
                if(B[i]=='L') now--;
                else now++;
            }
            if(now==-1){
                okleft=true;
                break;
            }
            if(now==N){
                okright=true;
                break;
            }
        }
        if(okright) right=mid;
        else left=mid+1;
    }
    
    okleft=false;okright=false;
    now=left;
    for(int i=0;i<Q;i++){
        if(A[i]==S[now]){
            if(B[i]=='L') now--;
            else now++;
        }
        if(now==-1){
            okleft=true;
            break;
        }
        if(now==N){
            okright=true;
            break;
        }
    }
    if(okright) ans+=(N-left);
    else ans+=(N-1-left);
    
    //cout<<ans<<endl;
    
    cout<<N-ans<<endl;
    
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" \
                              << "\n";

int main()
{
  int x, y, z;
  cin >> x >> y >> z;
  cout << z <<" "<< x <<" "<< y << "\n";
  return 0;
}


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

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

#define RFOR(i, b, a) for(int(i)=(b); (i)>=(a); (i)--)
#define RREP(i, n) FOR((i), (n), 0)

#define pb push_back
#define mp make_pair 

using namespace std;

const int INF=INT_MAX/4;
const int MOD=1000000007;
const double EPS=1e-14;

const bool debug_flag=true;

void debug(string str){
	if(debug_flag){
		cout<<str<<endl;
	}
}

void debugs(string str){
	if(debug_flag){
		cout<<str;
	}
}

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout.precision(10);

	int W, H;
	cin>>W>>H;
	vector<long> p(W), q(H);
	REP(i, W){
		cin>>p[i];
	}
	REP(i, H){
		cin>>q[i];
	}
	sort(p.begin(), p.end());
	sort(q.begin(), q.end());
	
	int i=0, j=0;
	long ans=0;
	while(H>0 && W>0){
		if(p[i]<q[j]){
			ans+=p[i]*(H+1);
			W--;
			i++;
		}else{
			ans+=q[j]*(W+1);
			H--;
			j++;
		}
	}
	if(H==0){
		while(W>0){
			ans+=p[i]*(H+1);
			W--;
			i++;
		}
	}else{
		while(H>0){
			ans+=q[j]*(W+1);
			H--;
			j++;
		}
	}

	cout<<ans<<endl;

	return 0;
}



Measured memory_bytes: 1792
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.typecons;
import std.numeric, std.math;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }

long mod = 10^^9 + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto n = RD;
	auto cnt = new long[30][](n);
	foreach (i; 0..n)
	{
		auto S = RD!string;
		foreach (c; S)
		{
			++cnt[i][c-'a'];
		}
	}
	string ans;
	foreach (i; 0..30)
	{
		long least = long.max;
		foreach (j; 0..n)
		{
			least = min(least, cnt[j][i]);
		}
		foreach (j; 0..least) ans ~= i + 'a';
	}
	writeln(ans);
	stdout.flush();
}

Measured memory_bytes: 256
from fractions import gcd
n,m = map(int,input().split())
a = list(map(int,input().split()))
lcm = a[0] // 2
for x in a:
    x //= 2
    g = gcd(lcm, x)
    if (lcm//g)%2!= (x//g)%2:
        print(0)
        exit()
    lcm = lcm * x // g
print((m // lcm + 1) // 2)


Measured memory_bytes: 16280
#include<iostream>
#include<cmath>
#include<vector>
#include<map>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  map<int, long> ct;
  for(int j=0; j<N; j++){
    int ai;
    cin >> ai;
    if(ct.find(ai)==ct.end()) ct[ai]=0;
    ct[ai]++;
  }
  for(int i=0; i<M; i++){
    int bi, ci;
    cin >> bi >> ci;
    if(ct.find(ci)==ct.end()) ct[ci]=0;
    ct[ci] += bi;
  }
  long cc = 0;
  long s = 0;
  for_each(ct.rbegin(), ct.rend(), [&N, &cc, &s](const auto cti) {
    long ad = min(N-cc, cti.second);
    s += ad*cti.first;
    cc += ad;
  });
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 12800
w,h,x,y = map(int,input().split())

if (x == 0 and y == 0) or (x==0 and y==h) or (x==w and y==0) or(x==w and y==h):
    print(w*h/2,'0')
    exit()

a = min(x*h,(w-x)*h)
b = min(y*w,(h-y)*w)
tmp = '0'
if a == b:
    tmp = '1'
print(w*h/2,tmp)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
int main()
{
	long long n,ans=1;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		ans*=i;
		ans%=1000000007;
	}
	cout<<ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
string s;
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>s;
	s[0]='2';
	s[1]='0';
	s[2]='1';
	s[3]='8';
	cout<<s<<"\n";
}

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

typedef long long  LL;
LL a,b,k,ans;

void work()
{
	scanf("%lld %lld",&a,&b),k=a^b;
	if (!k)  puts("1"),exit(0);
	while (k!=(k&-k))  k-=k&-k;
	a&=2*k-1,b&=k-1;
	while (b!=(b&-b))  b-=b&-b;
	b=b?2*b-1:0;
	if (b<a)  printf("%lld",2*(k-a)+b+1);
	else  printf("%lld",2*k-a);
}

int main()
{
	work();
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <deque>
#include <numeric>
#include <map>
#include <stack>
#include <iomanip>
#include <math.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF 100000
 
using namespace std;
 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
double PI = atan2(0, -1);

int main () {
	string S;
	cin >> S;
	int N = S.size();
	vector<string> v;
	string cur = "R";
	for (int i = 1; i < N; ++i) {
		if (S[i-1] == 'L' && S[i] == 'R') {
			v.push_back(cur);
			cur = "R";
		} else {
			cur += S[i];
		}
	}
	v.push_back(cur);
	vector<int> ans;
	rep(i,v.size()) {
		string cr = v[i];
		int n = cr.size();
		int l = find(cr.begin(), cr.end(), 'L') - cr.begin();
		int r = l-1;
		int even_dist_away_from_L = l/2;
		int odd_dist_away_from_L = l/2 + (l%2);
		int even_dist_away_from_R = (n-1-r)/2;
		int odd_dist_away_from_R = (n-1-r)/2 + ((n-1-r)%2);
		vector<int> cur_res(n,0);
		cur_res[l] += even_dist_away_from_L + odd_dist_away_from_R;
		cur_res[r] += odd_dist_away_from_L + even_dist_away_from_R;
		rep(i,n) cout << cur_res[i] << " ";
	}
	cout << endl;
    return 0;
}

Measured memory_bytes: 1976
import java.util.*;
import java.lang.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = gcd(A > B ? A : B, A > B ? B : A);
        int D = (int)Math.sqrt((double)C) + 1;
        int result = 1;
        for(int i = 2; i <= D && i <= C; i++){
            if(C % i == 0){
                result++;
                while(C % i == 0 && C > 1){
                    C = C / i;
                }
            }
        }
        if(C != 1){
            result++;
        }
        System.out.println(result);
        
    }
    
    public static long gcd(long a, long b){
        long c = a % b;
        if (c == 0){
            return b;
        }else{
            return gcd(b, c);
        }
    }
}


Measured memory_bytes: 21972
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <numeric>
#include <cstring>
#include <cmath>
#include <set>

const int MOD = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < (n); i++)

using ll = long long int;
using namespace std;

class DisjointSet
{
  public:
    vector<int> rank, p;

    DisjointSet() {}
    DisjointSet(int size)
    {
        rank.resize(size, 0);
        p.resize(size, 0);
        for (int i = 0; i < size; i++)
            makeSet(i);
    }

    void makeSet(int x)
    {
        p[x] = x;
        rank[x] = 0;
    }

    bool same(int x, int y)
    {
        return findSet(x) == findSet(y);
    }

    void unite(int x, int y)
    {
        link(findSet(x), findSet(y));
    }

    void link(int x, int y)
    {
        if (rank[x] > rank[y])
        {
            p[y] = x;
        }
        else
        {
            p[x] = y;
            if (rank[x] == rank[y])
            {
                rank[y]++;
            }
        }
    }

    int findSet(int x)
    {
        if (x != p[x])
        {
            p[x] = findSet(p[x]);
        }
        return p[x];
    }
};

int main()
{
    int n, a, b, q;
    int t;
    cin >> n >> q;
    DisjointSet ds = DisjointSet(n);

    for (int i = 0; i < q; i++)
    {
        cin >> t >> a >> b;
        if (t == 0)
            ds.unite(a, b);
        else if(t == 1)
        {
            if(ds.same(a, b))
                cout << 1 << endl;
            else 
                cout << 0 << endl;
        }
    }
    
    return 0;
}


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

int main() {
  int h,w,k;
  cin >>h>>w>>k;
  long long maisuu=0;
  for(int i=0;i<=h;i++){
    for(int j=0;j<=w;j++){
      maisuu=i*w-j*i+(h-i)*j;
      if(maisuu==k){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <stack>
#include <bitset>
#include <utility>
#include<iomanip>
// #include <numeric>
using namespace std;



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector<vector<ll>> vvint;
typedef vector<string> vstring;
typedef vector<vector<string>> vvstring;
typedef vector<char> vchar;
typedef vector<vector<char>> vvchar;
typedef vector<long double> vdouble;
typedef vector<vector<long double>> vvdouble;
typedef vector<vector<vector<long double>>> vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INT_MAX 2147483647
#define LLONG_MAX 9223372036854775807
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define DIVIDER 1000000007


//
// struct Node{
//   vint children;
//   ll index;
//   ll prop;
// };
// struct edge{ll to; ll cost;};



int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0,};

// ll X,Y,Z,K;
// ll pmax = 30000000000;
// vint A,B,C;




// int binary_search(int key){
//  //isOKを満たす要素のうち最小のインデックスを返す。（要ソート）
//   int left = -1;
//   int right = N;
//
//   while(right - left > 1){
//     int mid = left + (right - left)/2;
//
//     if(isOK(mid, key)) right=mid;
//     else left=mid;
//   }
//
//   return right;
// }

// ll gcd(ll m, ll n){
//   if(m<n) swap(m,n);
//   if(n==0) return m;
//   return gcd(n, m%n);
// }

// ll get_pow(ll x, ll y){
//   ll ret=0;
//   ll temp = y;
//   while(true){
//     if(x<=temp) break;
//     ret++;
//     temp *= 2;
//   }
//   return ret;
// }






int main() {
  cout<<fixed<<setprecision(10);

  string s;cin>>s;

  string snew = "";
  ll ans = 0;

  ll i = 0;
  while(i<s.size()-1){
    if(s.substr(i,2)=="BC"){
      snew+='D';
      i+=2;
    }else{
      snew+=s[i];
      i++;
    }
  }

  ll cnt = 0;
  rep(i,snew.size()){
    if(snew[i]=='A'){
      cnt++;
    }else if(snew[i]=='B' || snew[i]=='C'){
      cnt=0;
    }else{// D
      ans += cnt;
    }
  }





  cout << ans << endl;

}

















//


Measured memory_bytes: 776
#include <iostream>
#include <cmath>
#include <cstring>
#include <limits>

const int wmax = 1e5+5;
const int nmax = 1e2+5;

int weights[nmax];
long long value[nmax];

long long dp[wmax];

int main() {

	std::ios_base::sync_with_stdio(false);

	int N, W;
	std::cin >> N >> W;

	for (int i=0; i<N; i++) {
		std::cin >> weights[i] >> value[i];
	}

	memset(dp, 0, sizeof(dp));

	for (int i=0; i<N; i++) {
		for (int j=W-weights[i]; ~j; j--) {
			dp[j+weights[i]] = std::max(dp[j+weights[i]], dp[j]+value[i]);
		}
	}

	//for (int i=0; i<=W; i++) std::cout << dp[i] << " ";

	std::cout << dp[W];

	return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define re register
#define SIZE 3005
using namespace std;
string s1,s2;
int dp[SIZE][SIZE];
string ans;
inline void dfs(int i,int j)
{
	if(i==0 || j==0)
		return;
	if(s1[i]==s2[j])
		ans+=s1[i],dfs(i-1,j-1);
	else
		if(dp[i-1][j]>dp[i][j-1])
			dfs(i-1,j);
		else
			dfs(i,j-1);
}
int main()
{
	cin>>s1>>s2;
	s1=' '+s1;
	s2=' '+s2;
	for(re int i=1;i<s1.size();++i)
		for(re int j=1;j<s2.size();++j)
			if(s1[i]==s2[j])
				dp[i][j]=dp[i-1][j-1]+1;
			else
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
	dfs(s1.size()-1,s2.size()-1);
	for(re int i=ans.size()-1;i>=0;--i)
		cout<<ans[i];
	cout<<endl;
	return 0;
} 

Measured memory_bytes: 35456
/*

  _|_|                              _|  _|    _|
_|    _|  _|  _|_|  _|_|_|_|        _|  _|  _|
_|    _|  _|_|          _|          _|  _|_|
_|    _|  _|          _|      _|    _|  _|  _|
  _|_|    _|        _|_|_|_|    _|_|    _|    _|

*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
//#define ls (rt<<1)
//#define rs (rt<<1|1)
#define vi vector<int>
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;i++)
#define fi first
#define se second
typedef long long ll;
using namespace std;
const int maxn=1e6+1000;
const int mod=1e9+7;
int ksm(int num,int t){
    int res=1;
    for(;t;t>>=1,num=1ll*num*num%mod){
        if(t&1)res=1ll*res*num%mod;
    }
    return res;
}
int inv(int num){return ksm(num,mod-2);}
int main(){
    int n;cin>>n;
    ll ans=0;
    rep(i,1,n)ans=(ans+inv(1ll*ksm(3,i)*n%mod*(n+1-i)%mod))%mod;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <limits>
using namespace std;
// 素因数分解
typedef pair<long long, long long> P;
vector<P> prime_factorize(long long n)
{
vector<P> res;
for (long long p = 2; p * p <= n; ++p)
{
if (n % p != 0)
continue;
int num = 0;
while (n % p == 0)
{
++num;
n /= p;
}
res.push_back(make_pair(p, num));
}
if (n != 1)
res.push_back(make_pair(n, 1));
return res;
}
// 因数分解
long long gcd(long long x, long long y)
{
  if (y == 0)
  {
    return x;
  }
  else
  {
    return gcd(y, x % y);
  }
}
const int MOD = 1000000007;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)

int main()
{
    string s;
    cin >> s;
    deque<char> d;
    for (int i = 0; i < s.size(); i++)
    {
        d.push_back(s[i]);
    }
    int q;
    cin >> q;
    bool left_top = true;
    rep(i, q)
    {
        int query;
        cin >> query;
        if(query==1){
            left_top = !left_top;
        }
        else
        {
            int f;
            cin >> f;
            char c;
            cin>>c;
            if(f==1){
                if(left_top){
                    d.push_front(c);
                }else{
                    d.push_back(c);
                }
            }else{
                if(left_top){
                    d.push_back(c);
                }else{
                    d.push_front(c);
                }
            }
        }
    }
    if(!left_top){
        reverse(d.begin(), d.end());
    }
    while(!d.empty()){
        char ans = d.front();
        d.pop_front();
        cout << ans;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3980
#include<cstdio>
#define f(i,a,b) for(register int i=(a);i<=(b);i=-(~(i)))
int n,sum,a,b;
int split(int x)
{int y=0;while(x)y+=x%10,x/=10;return y;} 
int main()
{
	int x;
	scanf("%d%d%d",&n,&a,&b);
	f(i,1,n)if((x=split(i))>=a&&x<=b)sum+=i;
	printf("%d\n",sum);
} 

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
int main() {
	lli t,n,m,a,b,c,ans;
	char ch;
	cin >> ch;
	if(ch>='A' && ch<='Z'){
		cout<<"A";
	}
	else if(ch>='a' && ch<='z'){
		cout<<"a";
	}
	return 0;
}

Measured memory_bytes: 3628
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 998244353;
const ll MAX = 200001;

ll mod(ll a){
  return a % MOD;
}

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

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}
int main(){
  ll n; cin >> n; ll a,b; a = 0; b = 0; ll ans = 0;
  
  for(ll i = sqrt(n)/1 + 1; i >= 1; i--){
    if(n % i == 0){
      a = i;
      b = n / i;
      break;
    }
  }
  
  ll c = max(a,b);
  
  while(c != 0){
    c /= 10;
    ans++;
  }
  
  cout << ans << endl;
  

}

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

constexpr int MAX_N = 20;

int N;
int V[MAX_N], C[MAX_N];

int main() {
  cin >> N;
  for (int i{}; i < N; ++i) cin >> V[i];
  for (int i{}; i < N; ++i) cin >> C[i];

  int len{N};

  int ans{};
  for (int i{}; i < (1 << len); ++i) {
    int X{}, Y{};
    for (int j{}; j < len; ++j) {
      if (i & (1 << j)) {
        X += V[j], Y += C[j];
      }
    }
    ans = max(ans, X - Y);
  }

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


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

int h, w;
int dp[1001][1001];
char m[1001][1001];

int main()
{
	cin >> h >> w;
	
	for(int i = 1; i <= h; i++)
	{
		for(int j = 1; j <= w; j++)
		{
			cin >> m[i][j];
		}
	}
	
	for(int i = 1; i <= h; i++)
	{
		if(m[i][1] == '#') break;
		dp[i][1] = 1;
	}
	
	for(int i = 1; i <= w; i++)
	{
		if(m[1][i] == '#') break;
		dp[1][i] = 1;
	}
	
	for(int i = 2; i <= h; i++)
	{
		for(int j = 2; j <= w; j++)
		{
			if(m[i][j] == '.')
			{
				dp[i][j] = ((dp[i-1][j] % 1000000007) + (dp[i][j-1] % 1000000007)) % 1000000007;
			}
			else dp[i][j] = 0;
		}
	}
	
	cout << dp[h][w];
	return 0;
}

Measured memory_bytes: 5120
#include<iostream>
#include <algorithm>
#include<string>
#include<math.h>
#include <functional>
using namespace std;

int main(void) {
	int N=0;
	long long int A[200000] = { 0 };
	cin >> N;
	for (int i=0; i < N;i++) {
		cin >> A[i];
		A[i] -= i;
	}
	sort(A, A + N);
	long int mid = A[N / 2];
	long int min = 0;
	for (int d = mid - 100; d <= mid + 100;d++) {
		long int v = 0;
		for (int i = 0;i < N;i++) {
			v += abs(A[i]-d);
		}
		if (d == mid - 100)
			min = v;
		else if (v < min)
			min = v;
	}
	cout << min << endl;
	return 0;
}


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

import collections
lst=collections.Counter(A).most_common()
lst_larger=[el for el in lst if el[1]>=2]
#print(lst)
#print(lst_larger)
if len(lst_larger) >= 2:
    lst_larger=sorted(lst_larger, key=lambda x:x[0], reverse=True)
    if lst_larger[0][1]>=4:
        print(lst_larger[0][0]**2)
    else:
        print(lst_larger[0][0]*lst_larger[1][0])
else:
    print(0)


Measured memory_bytes: 21384
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using namespace std;

#define INF 100000

int main() {
    int N;
    cin >> N;
    vector<string>W(N);
    set<string>s;
    for (int i = 0; i < N; i++) {
        cin >> W[i];
        if (s.find(W[i]) == s.end())s.insert(W[i]);
        else {
            cout << "No" << endl;
            return 0;
        }
    }
    for (int i = 0; i < N-1; i++) {
        if (W[i].back() != W[i + 1].front()) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
p = list(map(int, input().split()))
s = [0 for _ in range(n + 1)]
ans = 0
for i in range(n):
    s[i+1] = p[i] + s[i]

for i in range(n - k + 1):
    ans = max(ans, s[i + k] - s[i])

print((ans + k) * 0.5)

Measured memory_bytes: 25060
N,Y = map(int,input().split())
ans_10000 = -1
ans_5000 = -1
ans_1000 = -1

for i in range(N+1):
    for j in range(N-i+1):
        if 10000 * i + 5000 * j + 1000 * (N - i - j) == Y:
            ans_10000 = i
            ans_5000 = j
            ans_1000 = N - i - j
            break
    if ans_1000 != -1:
        break
print(ans_10000,ans_5000,ans_1000)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define rep(...) _overload3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)

#define repr(i, n) for(int i = n;i >= 0;--i)
#define reparr(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl

int main(){
	int n,m,q;
	cin>>n>>m>>q;
	vvi t(n);
	rep(i,m){ // O(M)
		int l,r;
		cin>>l>>r;
		t[l-1].pb(r-1);
	}
	cerr<<"input end"<<endl;
	rep(i,n){ // O(n^2 log n)
		sort(all(t[i]));
		reparr(j,t[i]){
			cerr<<t[i][j]<<" ";
		}cerr<<endl;
	}
	cerr<<"sort end"<<endl;
	rep(i,q){ // q
		int ql,qr;
		cin>>ql>>qr;
		ql--;qr--; // normalize
		int ans=0;
		rep(j,ql,qr+1){ // n log n
			int r=upper_bound(all(t[j]),qr)-t[j].begin();

			ans+=r;
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 2176
package main

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

func main() {
	var n int
	fmt.Scan(&n)

	var min, max int
	fmt.Scan(&min)
	fmt.Scan(&max)
	
	var imin int
	if min < max {
		imin = min
	} else {
		imin = max
	}

	s := bufio.NewScanner(os.Stdin)
	for i := 2; i < n; i++ {
		s.Scan()
		r, _ := strconv.Atoi(s.Text())
		if r - imin > max - min {
			max = r
			min = imin
		}
		if r < imin {
			imin = r
		}
	}
	fmt.Println(max - min)
}



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

using namespace std;

int main() {

	int n;
	cin >> n;
	map<string,int> a;
	string aa;

	for (int i= 0; i < n; i++) {
		cin >> aa;
		if (a.find(aa)!=a.end()) {
			a[aa]++;
		}
		else {
			a.insert(make_pair(aa,1));
		}
	}
	int counter = 0;
	for (auto itr = a.begin(); itr != a.end(); itr++) {
		if (itr->second != 0 && stoi(itr->first)!= itr->second) {
			if (stoi(itr->first) <itr->second) {
				counter += itr->second-stoi(itr->first) ;
			}
			else {
				counter+=itr->second;
			}
		}
	}
	cout << counter << endl;
}

Measured memory_bytes: 12160
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <valarray>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <tuple>
#include <random>

using namespace std;
using ll = long long;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  int h, w;
  while (cin >> h >> w, h)
  {
    int d = h * h + w * w;
    int aw = 1000, ah = 1000;
    int sum = 1000000;
    for (int i = 1; i < 150; ++i)
    {
      for (int j = i + 1; j < 150; ++j)
      {
        int t = i * i + j * j;
        if (d == t)
        {
          if (h < i && (sum > t || ah > i))
          {
            ah = i, aw = j;
            sum = t;
          }
        }
        if (d < t && sum > t)
        {
          ah = i, aw = j;
          sum = t;
        }
      }
    }
    cout << ah << ' ' << aw << endl;
  }

  return 0;
}



Measured memory_bytes: 3068
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] p = new int[n];
    long[] c = new long[n];
    for(int i = 0; i < n; i++) {
      p[i] = sc.nextInt() - 1;
    }
    for(int i = 0; i < n; i++) {
      c[i] = sc.nextLong();
    }
    long ans = (-1) * (long)Math.pow(10, 18);
    for(int i = 0; i < n; i++) {
      ArrayList<Integer> list = new ArrayList<Integer>();
      list.add(i);
      int q = i;
      long[] d = new long[n];
      long[] d2 = new long[n];
      for(int j = 0; j <= n; j++) {
        q = p[q];
        if(j == 0) {
          d[j] = c[q];
        } else {
          d[j] = d[j - 1] + c[q];
        }
        if(j == 0) {
          d2[j] = d[j];
        } else {
          d2[j] = Math.max(d2[j - 1], d[j]);
        }
        if(q == i) {
          break;
        } else {
          list.add(q);
        } 
      }
      int t = list.size();
      if(k <= t) {
        ans = Math.max(ans, d2[k - 1]);
      } else {
        if(d[t - 1] <= 0) {
          ans = Math.max(ans, d2[t - 1]);
        } else {
          for(int j = 0; j < t; j++) {
            int m = (k - j - 1) / t;
            ans = Math.max(ans, ((long)m * d[t - 1]) + d[j]);
          }
        }
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 57872