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

template <typename T, typename _ = void>
struct is_container : std::false_type {};
template <typename T>
struct is_container<T, std::void_t<decltype(std::declval<T>().begin()),
                                   decltype(std::declval<T>().end())>>
    : std::true_type {};
template <typename T, typename _ = void>
struct is_pair : std::false_type {};
template <typename T>
struct is_pair<T, std::void_t<decltype(std::declval<T>().first),
                              decltype(std::declval<T>().second)>>
    : std::true_type {};
template <typename T>
void debug(const T& v) {
  if constexpr (is_pair<T>::value) {
    std::cerr << "{";
    debug(v.first);
    std::cerr << ", ";
    debug(v.second);
    std::cerr << "}";
  } else if constexpr (is_container<T>::value) {
    std::cerr << "{";
    for (auto it = v.begin(); it != v.end(); ++it) {
      if (it != v.begin()) std::cerr << ", ";
      debug(*it);
    }
    std::cerr << "}";
  } else {
    std::cerr << v;
  }
}
template <typename T, typename... Ts>
void debug(const T& value, const Ts&... args) {
  debug(value);
  std::cerr << ", ";
  debug(args...);
}
#if DEBUG
#define dbg(...)                        \
  do {                                  \
    cerr << #__VA_ARGS__ << ": ";       \
    debug(__VA_ARGS__);                 \
    cerr << " (L" << __LINE__ << ")\n"; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define rd(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  if constexpr (std::is_same<T, bool>::value) {
    std::cout << (value ? "Yes" : "No");
  } else {
    std::cout << value;
  }
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  write_to_cout(value);
  std::cout << ' ';
  write_to_cout(args...);
}
#define wt(...)                 \
  do {                          \
    write_to_cout(__VA_ARGS__); \
    cout << '\n';               \
  } while (0)

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& v) {
  for (T& vi : v) is >> vi;
  return is;
}

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

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

#include <boost/hana/functional/fix.hpp>
auto Fix = boost::hana::fix;

using ll = long long;

template <typename T>
using low_priority_queue =
    std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <typename T>
using V = std::vector<T>;
template <typename T>
using VV = V<V<T>>;

using namespace std;

int main() {
  rd(int, a, b, c);
  wt(a + b >= c);
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
const int MAX = 404;
int cs[4][MAX];

using A = array<int, 8>;
A rotH(A x){
  A y;
  y[0]=x[1];
  y[1]=x[2];
  y[2]=x[3];
  y[3]=x[0];

  y[7]=x[6];
  y[6]=x[5];
  y[5]=x[4];
  y[4]=x[7];
  return y;
}

A rotN(A x){
  A y;
  y[0]=x[3];
  y[3]=x[4];
  y[4]=x[7];
  y[7]=x[0];

  y[1]=x[2];
  y[2]=x[5];
  y[5]=x[6];
  y[6]=x[1];
  return y;
}

using ll = long long;
ll make_hash(ll a,ll b,ll c,ll d){
  return (a<<30)|(b<<20)|(c<<10)|d;
}

using P = pair<ll, ll>;
P make_hash(A x){
  return P(make_hash(x[0],x[1],x[2],x[3]),
           make_hash(x[4],x[5],x[6],x[7]));
}

map<ll, int> cnt,idx;
ll hs[4][MAX]={};

void inc(ll v){
  int k=idx[v];
  cnt[hs[0][k]]++;
  cnt[hs[1][k]]++;
  cnt[hs[2][k]]++;
  cnt[hs[3][k]]++;
}

void dec(ll v){
  int k=idx[v];
  cnt[hs[0][k]]--;
  cnt[hs[1][k]]--;
  cnt[hs[2][k]]--;
  cnt[hs[3][k]]--;
}

__int128_t check(A x){
  ll a=make_hash(x[0],x[1],x[2],x[3]);
  ll b=make_hash(x[4],x[5],x[6],x[7]);

  ll c=make_hash(x[3],x[2],x[5],x[4]);
  ll d=make_hash(x[2],x[1],x[6],x[5]);
  ll e=make_hash(x[1],x[0],x[7],x[6]);
  ll f=make_hash(x[0],x[3],x[4],x[7]);

  if(!cnt.count(a)) return 0;
  if(!cnt.count(b)) return 0;
  if(!cnt.count(c)) return 0;
  if(!cnt.count(d)) return 0;
  if(!cnt.count(e)) return 0;
  if(!cnt.count(f)) return 0;

  __int128_t res=1;
  res*=cnt[a];dec(a);
  res*=cnt[b];dec(b);
  res*=cnt[c];dec(c);
  res*=cnt[d];dec(d);
  res*=cnt[e];dec(e);
  res*=cnt[f];dec(f);

  inc(a);
  inc(b);
  inc(c);
  inc(d);
  inc(e);
  inc(f);

  return res;
}

signed main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>cs[0][i]>>cs[1][i]>>cs[2][i]>>cs[3][i];
    for(int z=0;z<4;z++){
      hs[z][i]=make_hash(cs[(z+0)%4][i],
                         cs[(z+1)%4][i],
                         cs[(z+2)%4][i],
                         cs[(z+3)%4][i]);
      cnt[hs[z][i]]++;
      idx[hs[z][i]]=i;
    }
  }

  ll ans=0;
  set<P> used;

  vector<A> vs;
  {
    A w;
    set<A> rs;
    for(int i=0;i<8;i++) w[i]=i;
    for(int p=0;p<4;p++){
      for(int q=0;q<4;q++){
        for(int r=0;r<4;r++){
          rs.emplace(w);
          w=rotH(w);
        }
        w=rotN(w);
      }
      w=rotH(w);
    }
    vs=vector<A>(rs.begin(),rs.end());
  }

  for(int i=0;i<n;i++){
    for(int j=0;j<i;j++){
      for(int z=0;z<4;z++){
        A x;
        for(int k=0;k<4;k++){
          x[k+0]=cs[(k+z)%4][i];
          x[k+4]=cs[k][j];
        }

        int way=0;
        A w(x);
        for(auto v:vs){
          A y;
          for(int k=0;k<8;k++) y[k]=x[v[k]];
          if(x==y) way++;
          chmin(w,y);
        }

        if(used.count(make_hash(w))) continue;
        used.emplace(make_hash(w));

        ans+=check(x)/way;
      }
    }
  }

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


Measured memory_bytes: 20352
#include <stdio.h>


int main(void){
	int a,b,c;
	int bought[100] = {0};
	int colors = 3;
	
	scanf("%d %d %d", &a,&b,&c);
	bought[a]++;
	if (bought[b]) colors--;
	else bought[b]++;
	if (bought[c]) colors--;
	
	printf("%d\n", colors);
	
	return 0;
}

Measured memory_bytes: 128
#import pysnooper
#import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

n,m=map(int,input().split())
ans=0
for _ in range(n):
    a=sum([int(i) for i in input().split()])
    ans=max(a,ans)
print(ans)


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define mset(a,b) memset(a,b,sizeof a)
#define mcpy(a,b) memcpy(a,b,sizeof b)
#define swap(a,b) a^=b^=a^=b
#define lb(x) ((x)&(-(x)))
#define dalao 1000000007
#define inf 0x3f3f3f3f
#define N 100010
using namespace std;
typedef long long ll;/*
int n,m,k,q[19260817+20010910],l,r=-1,d[N][N],num1[N][N],num2[N][N],xx[4]={1,-1,0,0},yy[4]={0,0,1,-1},sx,sy;
bool vis[N][N];
char mp[N][N];
inline bool judge(int x,int y){return x>=1&&x<=n&&y>=1&&y<=m;}*/
int n,m,cnt[N];
int main(){
	cin>>n>>m;
	while(m--){
		int a,b;scanf("%d%d",&a,&b);cnt[a]++,cnt[b]++;
	}
	for(int i=1;i<=n;i++)if(cnt[i]&1)return puts("NO"),0;
	puts("YES");
/*	mset(d,0x3f);
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++)scanf("%s",mp[i]+1);
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)if(mp[i][j]=='S')sx=i,sy=j;
	q[++r]=sx*1000+sy,d[sx][sy]=0;
	while(l<=r){
		int x=q[l]/1000,y=q[l]%1000,r=num1[x][y]/k;l++;
		vis[x][y]=0;
		for(int i=0;i<4;i++){
			int a=x+xx[i],b=y+yy[i];
			if(judge(a,b)){
				if(mp[a][b]=='#'){
					if(num2[x][y]<k*r&&d[a][b]>d[x][y]+1){
						d[a][b]=d[x][y]+1,num1[a][b]=num1[x][y]+1,num2[a][b]=num2[x][y]+1;
						if(!vis[a][b])q[++r]=1000*a+b,vis[a][b]=1;
					}
				}else if(d[a][b]>d[x][y]+1){
					d[a][b]=d[x][y]+1,num1[a][b]=num1[x][y]+1,num2[a][b]=num2[x][y];
					if(!vis[a][b])q[++r]=1000*a+b,vis[a][b]=1;
				}
			}
		}
	}
//	for(int i=1;i<=n;i++,puts(""))for(int j=1;j<=m;j++)cout<<d[i][j]<<" ";
	int ans=0x3f3f3f3f;
	for(int i=1;i<=m;i++)ans=min(ans,min((num1[1][i]+k-1)/k,(num1[n][i]+k-1)/k));
	for(int i=2;i<n;i++)ans=min(ans,min((num1[i][m]+k-1)/k,(num1[i][1]+k-1)/k));
	printf("%d",ans);*/
	return 0;
}

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

int main(){
  int X;
  cin >> X;
  
  if(X <= 3){
    cout << 1 << endl;
  }
  else{
  int a[1000] = {};
  int k = 1;
  

  for(int i = 2; i < X; i++){
    while(X / k >= 1){
      k *= i;
    }
    if(k == i*i){
      a[i] = 0;
    }
    else{
      a[i] = k / i;
    }
    k = 1;
  }
  
  int m = 0;
  
  for(int i = 2; i < X; i++){
    if(m < a[i]){
      m = a[i];
    }
  }
  
  cout << m << endl;
  }
  return 0;
}
    


Measured memory_bytes: 256
import heapq
N,M=map(int,input().split())
a=[0 for i in range(M)]
c=[0 for i in range(M)]
for i in range(M):
    a[i],b=map(int,input().split())
    tmp=[int(i)-1 for i in input().split()]
    for j in tmp:
        c[i]+=2**j
edge=sorted([(a[i],c[i]) for i in range(M)])
q=[]
heapq.heappush(q,(0,0))
dist=[10**15 for i in range(2**N)]
dist[0]=0
while(len(q)!=0):
    prc,src=heapq.heappop(q)
    if dist[src]<prc:
        continue
    for e in edge:
        cost,nxt=e
        dest=nxt|src
        if dest==src:
            continue
        if dist[dest]>dist[src]+cost:
            dist[dest]=dist[src]+cost
            heapq.heappush(q,(dist[dest],dest))
ans=dist[-1]
if ans==10**15:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 53848
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

vector<ll> enum_div(ll n){//nの約数を列挙
  vector<ll> ret;
  for(ll i=1 ; i*i<=n ; ++i){
    if(n%i == 0){
	  ret.push_back(i);
	  if(i!=1 && i*i!=n){
		ret.push_back(n/i);
	  }
    }
  }
  sort(ret.begin(),ret.end());
  return ret;
}

int main(){
  ll ans = 1LL << 60;
  ll n;
  cin >> n;
  vector<ll> r = enum_div(n);
  for(auto r1:r){
    ll a = r1;
    ll b = n / r1;
    string sa = to_string(a);
    string sb = to_string(b);
    ll tmp = max(sa.size(),sb.size());
    //printf("a=%lld, b=%lld, tmp=%lld\n",a,b,tmp);
    chmin(ans, tmp);
  }
  
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
def slove():
    import sys
    input = sys.stdin.readline
    n, m, l = list(map(int, input().rstrip('\n').split()))
    INF = 10 ** 11
    w = [[INF] * n for _ in range(n)]
    wl = [[INF] * n for _ in range(n)]

    for i in range(n):
        w[i][i] = 0

    for i in range(m):
        a, b, c = list(map(int, input().rstrip('\n').split()))
        if c <= l:
            w[a - 1][b - 1] = c
            w[b - 1][a - 1] = c

    for i in range(n):
        for j in range(n):
            for k in range(n):
                w[j][k] = min(w[j][k], w[j][i] + w[i][k])

    for i in range(n):
        for j in range(n):
            if w[i][j] <= l:
                wl[i][j] = 1
    for i in range(n):
        for j in range(n):
            for k in range(n):
                wl[j][k] = min(wl[j][k], wl[j][i] + wl[i][k])

    q = int(input().rstrip('\n'))
    for i in range(q):
        s, t = list(map(int, input().rstrip('\n').split()))
        if wl[s-1][t-1] == INF:
            print(-1)
        else:
            print(wl[s-1][t-1] - 1)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 57308
#include <iostream>
#include <vector>
#include <functional>

using namespace std;

int main()
{
    int N,M;
    cin>>N>>M;
    vector<vector<int>> E(N);
    vector<vector<long long>> D(N);
    for (int i=0; i<M; i++)
    {
        int l,r;
        long long d;
        cin>>l>>r>>d;
        E[l-1].push_back(r-1);
        D[l-1].push_back(d);
        E[r-1].push_back(l-1);
        D[r-1].push_back(-d);
    }
    long long inv = N*99999999LL;
    vector<long long> P(N, inv);

    function<void(int)> BT = [&](int c)
    {
        for (int i=0; i<(int)E[c].size(); i++)
        if (P[E[c][i]] == inv)
        {
            P[E[c][i]] = P[c] + D[c][i];
            BT(E[c][i]);
        }
    };
    for (int i=0; i<N; i++)
        if (P[i]==inv)
        {
            P[i] = 0;
            BT(i);
        }
    bool ok = true;
    for (int i=0; i<N; i++)
    for (int j=0; j<(int)E[i].size(); j++)
        if (P[E[i][j]] - P[i] != D[i][j])
            ok = false;
    cout<<(ok ? "Yes" : "No")<<endl;
}


Measured memory_bytes: 19712
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    long long  N,tmp_int,tmp_ans,ans=1;
    vector<long long> v;
    
    cin >>  N;  

    for(int i=0;i<N;i++){
        cin >> tmp_int;
        if(tmp_int==0){
            ans = 0;
            break;
        }
        v.push_back(tmp_int);
    }
    
    for(int j=0;j<N;j++){
        if(ans==0) break;
        tmp_ans = ans;
        ans *= v[j];
        
        if(tmp_ans>ans){
            ans = -1;
            break;
        }
        if(ans>1000000000000000000){
            ans = -1;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4224
import java.util.*;
class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] num = new int[3];
        for(int i = 0;i<num.length;i++)num[i] = sc.nextInt();
        Arrays.sort(num);
        int count = 0;
        count += (num[1]-num[0])/2+(num[1]-num[0])%2;
        num[2]+= (num[1]-num[0])%2;
        count+= num[2]-num[1];
        System.out.println(count);
    }
}


Measured memory_bytes: 35800
#include <stdio.h>

void array_reset( int*, int );

int main(){
    int n;
    int b, f, r, v;
    int i, j , k;
    int house[4][3][10];
    
    for( i = 0; i < 4; i++ ){
        for( j = 0; j < 3; j++ ){
            array_reset( &house[i][j][0], 10 );
        }
    }
    
    scanf( "%d", &n );
    
    for( i = 0; i < n; i++ ){
        scanf( "%d %d %d %d", &b, &f, &r, &v );
        house[b - 1][f - 1][r - 1] += v;
    }
    
    for( i = 0; i < 4; i++ ){
        for( j = 0; j < 3; j++ ){
            for( k = 0; k < 10; k++ ){
                printf( " %d", house[i][j][k] );
            }
            printf( "\n" );
        }
        
        if( i < 3 ){
            for( j = 0; j < 20; j++ ){
                printf( "#" );
            }
            printf( "\n" );
        }
    }
    
    return 0;
}

void array_reset( int *array, int size )
{
    int i;
    
    for( i = 0; i < size; i++ ){
        *( array + i ) = 0;
    }
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
 
#define int long long
 
#define Vanya Unstoppable
 
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    
    int n, x;
    cin >> n >> x;
    
    int a[n];
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    
    int mn[n];
    for (int i = 0; i < n; ++i){
        mn[i] = 1e18;
    }
    
    int ans = 1e18;
    for (int k = 0; k <= n; ++k) {
        int cur = 0;
        for (int i = 0; i < n; ++i) {
            int id = n + (i - k);
            if (i - k >= 0) {
                id = i - k;
            }
            mn[i] = min(mn[i], a[id]);
            cur += mn[i];
        }
        ans = min(ans, cur + x * k);
    }
    
    cout << ans;
}


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

int main() {
    int n; cin >> n;
    vector<vector<int>> g(n);
    for(int i = 0; i < n - 1; ++i) {
        int a, b; cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    function<int(int, int)> dfs = [&] (int v, int p) {
        int res = 0;
        for(auto to : g[v]) {
            if(to == p) continue;
            res ^= dfs(to, v) + 1;
        }
        return res;
    };

    cout << (dfs(0, -1) ? "Alice" : "Bob") << endl;
}


Measured memory_bytes: 13568
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

bool solve() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> graph(N, vector<int>(N, 10000));
    for(int i = 0; i < M; ++i) {
        string s;
        cin >> s;
        for(char &c : s) {
            if(c == ',') c = ' ';
        }
        istringstream is(s);
        int a, b, c, d;
        is >> a >> b >> c >> d;
        graph[a-1][b-1] = c;
        graph[b-1][a-1] = d;
    }
    int S, T, A, B;
    {
        string s;
        cin >> s;
        for(char &c : s) {
            if(c == ',') c = ' ';
        }
        istringstream is(s);
        is >> S >> T >> A >> B;
        --S; --T;
    }
    for(int k = 0; k < N; ++k) {
        for(int i = 0; i < N; ++i) {
            for(int j = 0; j < N; ++j) {
                graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
            }
        }
    }
    cout << A-B-graph[S][T]-graph[T][S] << endl;
    return false;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 1236
n, m = map(int, input().split())
h = list(map(int, input().split()))
road = [[] for _ in range(n)]
for _ in range(m):
    i, j = map(int, input().split())
    road[i-1].append(j-1)
    road[j-1].append(i-1)

ans = 0
l = [0 for _ in range(n)]
for i in range(n):
    if l[i] == 1:
        continue
    l[i] == 1
    flag = False
    for j in road[i]:
        if h[j] > h[i]:
            flag = True
            break
        elif h[i] > h[j]:
            l[j] = 1
            continue
        else:
            l[j] = 1
            flag = True
            break
    if flag:
        continue

    ans += 1
print(ans)

Measured memory_bytes: 30200
#include <bits/stdc++.h>
#include <time.h>
//#include <random>
//#ifndef _LOCAL
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#endif
#define sz(x) int(x.size())
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
#define N 100500
#define oo ll(1e16)
#define pii pair <int, int>
#define pll pair <ll, ll>
#define ft first
#define sd second
#define pb push_back
#define ppb pop_back
#define el '\n'
#define elf endl
#define base ll(1e9 + 7)
#define re return
#define nins 4294967295
using namespace std;
typedef long long ll;
typedef long double ld;

//mt19937 rnd(0);

int n, a[N];
ll ans = 0;
vector <int> g[3];

void solve() {
    string s;

    cin >> n;
    cin >> s;

    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') a[i] = 0;
        if (s[i] == 'G') a[i] = 1;
        if (s[i] == 'B') a[i] = 2;

        g[a[i]].pb(i);
    }

    for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++) {
        if (a[i] == a[j]) continue;

        int k = 0;
        while (k == a[i] || k == a[j])
            k++;

        int p = upper_bound(g[k].begin(), g[k].end(), j) - g[k].begin();

        if (p == sz(g[k]))
            continue;

        ll kl = sz(g[k]) - p;

        p = lower_bound(g[k].begin(), g[k].end(), 2 * j - i) - g[k].begin();

        if (p < sz(g[k]) && g[k][p] == 2 * j - i)
            kl--;

        ans += kl;
    }

    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifdef _LOCAL
//        in("input.txt");

        int t = 1;
//        cin >> t;
        for (int i = 1; i <= t; i++) {
            cout << "Test #" << i << elf;

            clock_t start_time = clock();

            solve();

            cerr.precision(4); cerr << fixed;
            cerr << elf;
            cerr << "Time :: " << ld(clock() - start_time) / CLOCKS_PER_SEC << elf;

            cout << elf;
        }
    #else
        int t = 1;
//        cin >> t;

        while (t--) {
            solve();
            cout << el;
        }
    #endif
}


Measured memory_bytes: 3676
R, C = map(int, input().split())

A = [list(map(int, input().split())) for _ in range(R)]
B = [list(map(int, input().split())) for _ in range(R)]

dp = [0] * C
dp[0] = s = 1 << 6400

for row_a, row_b in zip(A, B):
    for i, (a, b) in enumerate(zip(row_a, row_b)):
        d = abs(a - b)
        if i > 0:
            dp[i] |= dp[i - 1]
        dp[i] = (dp[i] << d) | (dp[i] >> d)

g = dp[-1]
for i in range(6401):
    if g & (s << i) or g & (s >> i):
        print(i)
        quit()


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

typedef long long ll;

int main() {
	ll N, Y;
	cin >> N >> Y;

	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= N - i; j++) {
			ll sum = 10000 * i + 5000 * j + 1000 * (N - i - j);
			if (Y == sum) {
				cout << i << " " << j << " " << N - i - j << endl;
				return 0;
			}
		}
	}

	cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int expo(int b,int p);
int main(void){
    int A,B,C,K;
    scanf("%d",&A);scanf("%d",&B);scanf("%d",&C);scanf("%d",&K);

    int i,j,max = 1,sum;
    for(i = 0;i <= K;i++){
        for(j = 0;j <= K-i;j++){

            sum = A*expo(2,i) + B*expo(2,j) + C*expo(2,K-i-j);
            if(sum >= max){
                max = sum;
            }
        }
    }

    printf("%d",max);
}
int expo(int b,int p){

    if(p == 0){
        return 1;
    }else if(p == 1){
        return b;
    }else{
        int a = expo(b,p-1);
        return a * b;
    }

}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
lint powint(lint x,lint y){
	if(y==0)return 1;
	if(y%2)return x*powint(x,y-1);
	lint a = powint(x,y/2);
	return a*a;
}

int main(){
	int r;
	cin>>r;
	cout<<3*powint(r,2)<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define int long long

int f(int n) {
	return ((1ll << (n - 1)) - 1) * 9 * 9;
}
void solve(int N) {
	N--;

	// [2,?)
	int n = 2;
	while (1) {
		int x = f(n);
		if (N - x < 0)break;
		N -= x;
		n++;
	}
	//cout << "n:" << n << ", N:" << N << endl;


	auto g = [](int n) {
		return ((1ll << (n - 1)) - 1) * 9;
	};
	vector<int>ans(n, -1);
	int L = 1;
	while (1) {
		int x = g(n);
		if (N - x < 0)break;
		N -= x;
		L++;
	}
	ans[0] = L;
	//cout << "L:" << L << ", N:" << N << endl;

	rep(i, 1, n) {
		if (i == n - 1) {
			//cout << "N:" << N << endl;
			int x = 0;
			while (N--) {
				x++;
				if (ans[i - 1] == x) {
					x++;
				}
			}
			ans[i] = x;
			break;
		}
		else {
			rep(j, 0, 10) {
				int x;
				if (ans[i - 1] == j) {
					x = ((1ll << (n - (i + 1))) - 1) * 9;
				}
				else {
					x = (1ll << (n - (i + 1)));
				}
				if (N - x < 0) {
					ans[i] = j;
					break;
				}
				N -= x;
			}
			if (ans[i] != ans[i - 1]) {
				int m = min(ans[i], ans[i - 1]);
				int M = max(ans[i], ans[i - 1]);
				for (int k = 0; ans[n - 1 - k] == -1; k++) {
					int f = (N >> k)&1;
					if (f) {
						ans[n - 1 - k] = M;
					}
					else {
						ans[n - 1 - k] = m;
					}
				}
				break;
			}

		}
	}

	string a;
	for (auto hoge : ans) {
		a.push_back(hoge + '0');
	}
	cout << a << endl;
}

signed main() {
	for (int N; cin >> N && N;) {
		solve(N);
	}
	return 0;
}


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

#define endl '\n'
#define ll  long long
#define modd(a,b) ((a+2*b)%b)
#define ioso ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define debug(a) cout << #a << ": " << (a) << "\n"
#define kholo freopen("input.txt","r",stdin), freopen("output.txt","w",stdout)
bool ispal(string s) {
	int i = s.length()-1,j=0,k=0;
	while(j<=i) {
		if(s[i]!=s[j]) {
			k = 1; break;
		}
		else {
			i--;j++;
		}
	}
	

	if(k) {
		return false;
	}
	else {
		return true;
	}
}
int main() {
	ioso;// kholo;
	string s; cin >> s;
	int n = s.length();
	int f = (n+3)/2;
	int k = (n-1)/2;
	string f1 = s.substr(0,k);
	string k1 = s.substr(f-1,(n+1)-f);
	//cout << f1 << " " << k1 <<endl; 

	if(ispal(s) and ispal(f1) and ispal(k1)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
}


Measured memory_bytes: 256
import sys
import bisect
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    s = str(readline().rstrip().decode('utf-8'))
    d = collections.defaultdict(list)
    for i in range(len(s)):
        d[s[i]] += [i]
    loop = 0
    pos = 0
    t = str(readline().rstrip().decode('utf-8'))
    for i in range(len(t)):
        if t[i] in d:
            pos = bisect.bisect_left(d[t[i]], pos)
            if pos == len(d[t[i]]):
                loop += 1
                pos = 0
                pos = bisect.bisect_left(d[t[i]], pos)
            pos = d[t[i]][pos] + 1
        else:
            print(-1)
            exit()
    print(loop * len(s) + pos)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 46320
def main():
    A,B = map(int,input().split())
    ans = -1
    for num in range(10001,0,-1):
        a = int(num * 0.08)
        b = int(num * 0.10)
        if A==a and B==b:
            ans = num
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3068
import java.util.*;

class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = 800 * n;
        int y = n /15 * 200;
        System.out.println(x - y);
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int inf = 2e18;
const int mod = 1e9 + 7;

signed main() {
    int N;
    cin >> N;
    --N;
    if (N % 2 == 0) {
        cout << (N + 1) * (N / 2) << endl;
    } else {
        cout << (N + 1) * (N / 2) + (N / 2 + 1) << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long  pre[100000+7];
map<int,int>mp;
int pos=0; 
void fenjie(long long x){
	long long c=sqrt(x);
	for(int i=2;i<c;i++){
		if(x%i==0){
			pre[pos++]=i;
			while(x%i==0){
				x/=i;
				mp[i]++;
			}
		}
	}
	if(x!=1) {
		pre[pos++]=x;
		mp[x]++;
	}
	return ;
}
int num(long long  x){
	x=x*2;
	int n=sqrt(x);
	if(n*(n+1)<=x) return n;
	else return n-1; 
}

int main(){
	long long n;
	cin>>n;
	fenjie(n);
	int ans=0;
	for(int i=0;i<pos;i++){
		ans+=num(mp[pre[i]]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
// Hey! 僕の提出を見てくれてありがとう.
// ロボ子さん可愛いぞ！！！！！君もV沼にはまろう↓
// https://www.youtube.com/channel/UCDqI2jOz0weumE8s7paEk6g
using namespace std;
namespace mp = boost::multiprecision;
// 任意長整数型
using bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using real1024 = mp::number<mp::cpp_dec_float<1024>>;
// ついでに有理数型
using rat = boost::rational<bint>;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
//sortを降順にする時は greater<型>()
void solve(long long N, std::vector<long long> A){
  sort(all(A),greater<ll>());
  vector<ll>x;
  x.pb(0);
  x.pb(A[0]);
  for (int i = 1; i < N; i++) {
    for (int l = 0; l < 2; l++) {
      x.pb(A[i]); 
    }
  }
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans += x[i];
  }
  cout << ans << endl;
}

int main(){
        ll N;
				scanf("%lld",&N);
				std::vector<long long> A(N);
				for(int i = 0 ; i < N ; i++){
								scanf("%lld",&A[i]);
				}
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 8944
#include <bits/stdc++.h>
/*
#include<algorithm>
#include<array>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<typeinfo>
#include<utility>
#include<vector>
*/
#define int long long int
#define double long double
using namespace std;
#define INT_DMAX 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i, n) for (int(i) = 0, i##_len = (n); (i) < i##_len; (i)++)
#define reps(i, x) for (int(i) = 1; (i) <= (int)(x); (i)++)
#define rrep(i, x) for (int(i) = ((int)(x)-1); (i) >= 0; (i)--)
#define rreps(i, x) for (int(i) = ((int)(x)); (i) > 0; (i)--)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1) << (n))
#define all(x) (x).begin(), (x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl
#define nint int
using namespace std;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef pair<int, int> p;
typedef pair<double, double> dop;
template <class T>
bool chmax(T& a, const T& b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b)
{
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct aaa {
    aaa()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} aaaaaaa;


int a, b, c, n;
std::vector<int> l;
std::vector<short> check(8, 0);

int cost(std::vector<short> tcheck, int sum)
{
    int mi = INF;
    if (n == sum) {
        int out = 0;
        int ao = 0;
        int bo = 0;
        int co = 0;
        for (int i = 0; i < n; i++) {
            if (tcheck[i] == 0) {
                if (ao > 0) {
                    out += 10;
                }
                ao += l[i];
            } else if (tcheck[i] == 1) {
                if (bo > 0) {
                    out += 10;
                }
                bo += l[i];
            } else if (tcheck[i] == 2) {
                if (co > 0) {
                    out += 10;
                }
                co += l[i];
            }
        }
        if (!ao && a) {
            return INF;
        } else if (!bo && b) {
            return INF;
        } else if (!co && c) {
            return INF;
        }
        out += abs(ao - a) + abs(bo - b) + abs(co - c);
        return out;
    }
    for (int i = 0; i < 4; i++) {
        tcheck[sum] = i;
        chmin(mi, cost(tcheck, sum + 1));
    }
    return mi;
}


signed main()
{
    cin >> n;
    cin >> a >> b >> c;
    for (int i = 0; i < n; i++) {
        int temp;
        cin >> temp;
        l.pb(temp);
    }
    cout << cost(check, 0) << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    A = []
    B = [''] * m
    for i in range(m):
        p, y = map(int, input().split())
        A += [(p, y, i)]
    A.sort()
    count = 0
    i, x = 1, 1
    for a in A:
        if a[0] == i:
            B[a[2]] = '{:06}{:06}'.format(a[0], x)
        else:
            i, x = a[0], 1
            B[a[2]] = '{:06}{:06}'.format(a[0], x)
        x += 1
    print('\n'.join(B))


if __name__ == '__main__':
    main()

Measured memory_bytes: 31496
#include <iostream>
#include <cmath>

using namespace std;

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

    int count = 0;

    for (int i = 1 ; i <= n; i++) {
        if ((int)log10(i) % 2 == 0) {
            count++;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 512
N, M = map(int, input().split())

AC = [0]*N
WA = [0]*N
wa = 0

for i in range(M):
    j, res = input().split()
    j = int(j)-1

    if AC[j] == 0 and res == "AC":
            AC[j] = 1
            wa += WA[j]
    WA[j] += 1

print(sum(AC), wa)


Measured memory_bytes: 4596
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int n;
    cin >> n;
    cout << ( 1 + n ) * n / 2  << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
//#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>

using namespace std;
#define INF 100100100

#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,a,n) for(int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
typedef long long ll;
typedef pair<ll, ll> PI;

ll ans = 100100100100;

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


    rep(i,k) {
        if('1' != s[i]) { cout << s[i] << endl; return 0;}
    }

    cout << "1" <<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

    N,x=map(int,input().split())
    X=list(map(int,input().split()))
    L=[0]*N

    for i in range(N):
        L[i]=X[i]-x

    from functools import reduce
    from fractions import gcd
    print(abs(reduce(gcd,L)))


resolve()

Measured memory_bytes: 80124
#include <iostream>
#include <queue>

typedef std::pair<int, int> P;

char board[1000][1000];
int d[1000][1000];
int H, W;
int dh[4] = {0, -1, 0, 1};
int dw[4] = {1, 0, -1, 0};

int main() {
  std::cin >> H >> W;
  std::queue<P> que;
  std::memset(d, -1, sizeof(d));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      std::cin >> board[i][j];
      if (board[i][j] == '#') {
        que.push(P(i, j));
        d[i][j] = 0;
      }
    }
  }
  
  int max_d = 0;
  while (que.size()) {
    P p = que.front(); que.pop();
    for (int i = 0; i < 4; i++) {
      int nh = p.first + dh[i], nw = p.second + dw[i];
      if (nh >= 0 && nh < H && nw >= 0 && nw < W && board[nh][nw] == '.' && d[nh][nw] == -1) {
        d[nh][nw] = d[p.first][p.second] + 1;
        que.push(P(nh, nw));
        max_d = std::max(max_d, d[nh][nw]);
      }
    }
  }
  
  std::cout << max_d << std::endl;
  return 0;
}

Measured memory_bytes: 13056
import java.util.*;
//import java.util.stream.Collectors;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		int result = 0;
		for(int i=n; i>0; i--){
			if(Math.sqrt(i) == (int)Math.sqrt(i)){
				result = i;
				break;
			}
		}
		System.out.println(result);
	}
}


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

int main() {

//??AC

    int n, m;
    cin >> n >> m;

    vector<int> A(n);
    for (int i = 0; i < n; i++) cin >> A[i];

    vector<int> B(m), C(m);
    for (int i = 0; i < m; i++) cin >> B[i] >> C[i];

    priority_queue<pair<int, int>> q;

    for (int i = 0; i < n; i++)
        q.push(make_pair(A[i],1));

    for (int i = 0; i < m; i++)
        q.push(make_pair(C[i], B[i]));

    long long ans = 0;

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

        auto p = q.top();
        q.pop();

        ans += p.first;

        if (p.second > 1) {
            p.second --;
            q.push(p);
        }
        
    }

    cout << ans << endl;

    return 0;
    

// TLE
    /*

    int n, m;
    cin >> n >> m;

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

    int b;
    long long c;

    for (int j = 0; j < m; j++) {

        sort(A.begin(), A.end());
        
        cin >> b >> c;

        for (int k = 0; k < b; k++) {
            
            if (A[k] < c) {
                A[k] = c;
            }

        }

    }

    long long sum = 0;

    for (int i = 0; i < n; i++) {
        sum += A[i];
    }

    cout << sum << endl;
    
    return 0;  
    */

}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int a,b;
  string s;
  cin>>a>>b>>s;
  if(s.size()-1 != a+b){cout<<"No"<<endl;return 0;}
  rep(i,s.size()){
    if(i==a && s[i]!='-'){cout<<"No"<<endl;return 0;}
    else if(i==a) continue;
    else if(s[i]>=48 && s[i]<=57) continue;
    else{cout<<"No"<<endl;return 0;}
   
  }
  cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
	// your code goes here
	vector<char> hoge;
	string a,b,c;
	cin>>a>>b>>c;
	if(a[a.length()-1]==b[0]&&b[b.length()-1]==c[0]){
		cout<<"YES";
	}else{
		cout<<"NO";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1LL << 60
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const long long MOD=1000000007;

// vector<p> cut(M); vector<vector<ll> > v(4);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()), sort(v.rbegin(), v.rend()); //sort
// char '' str ""
int main(void)
{
    str S; cin>>S;
    int ans=MOD;
    for(int i=0; i<S.size()-2 ;i++){
      int s = S[i] - '1' + 1;
      int ss = S[i+1] - '1' + 1;
      int sss = S[i+2] - '1' + 1;
      ans = min(ans, abs(s*100 + ss*10 + sss - 753));
    }

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


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	while(1)
	{
		c-=b;
		if(c<=0)  
		{
			cout<<"Yes";
			return 0;
		}
		a-=d;
		if(a<=0)
		{
			cout<<"No";
			return 0;
		}
	}
	return 0;
 } 

Measured memory_bytes: 3636
n, k = map(int, input().split())
LR = []
for _ in range(k):
    l, r = map(int, input().split())
    LR.append([l, r+1])

MOD = 998244353
dp = [0]*(n+1)  # [0,n]
dp[0] = 1
dp[1] = -1

for i in range(n): # i:[0,n-1]
    if i > 0: dp[i] += dp[i-1]
    for j in range(k):
        l, r = LR[j]
        if i+l < n:
            dp[i+l] += dp[i]
            dp[i+l] %= MOD
        if i+r < n:
            dp[i+r] -= dp[i]
            dp[i+r] %= MOD

print((dp[n-1] + MOD) % MOD)


Measured memory_bytes: 20780
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
ll n;
int main(void){
    cin>>n;
    for(int i=1;i<=3500;i++){
        for(int j=1;j<=3500;j++){
            if((4*i*j-n*i-n*j)>0){
                if((n*i*j)%(4*i*j-n*i-n*j)==0){
                    cout<<i<<" "<<j<<" "<<(n*i*j)/(4*i*j-n*i-n*j)<<endl;
                    return 0;
                }
            }
        }
    }
    
}


Measured memory_bytes: 3600
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        long[] a = new long[N];
        a[0] = Long.parseLong(sc.next());
        long min = a[0];
        for(int i=1; i<N; i++) {
            a[i] = Long.parseLong(sc.next());
            if(min > saiyaku(a[i-1], a[i]))  min = saiyaku(a[i-1], a[i]);
        }
        
        System.out.println(min);
    }
    
    static long saiyaku(long a, long b) {
        if(a < b) return saiyaku(b, a);
        if(b == 0) {
            return a;
        }else {
            long w = b;
            a = a % b;
            b = w;
            return saiyaku(a, b);
        }
    }
}

Measured memory_bytes: 47180
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
int compare_int(const void *a, const void *b){
  return *(long int*)b - *(long int*)a; // 大きい順
}
// 5min
int main(void){
  char s[4];
  char t[4];
  int ans = 0;

  scanf("%s%s", s, t);
  
  for(int i = 0; i < 3; i++){
    if(s[i] == t[i]){
      ans++;
    }
 }
  printf("%d\n", ans);
  
  return 0;
}

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

using namespace std;

const uint64_t MOD = 1e+9 + 7;

uint64_t fact(uint64_t n)
{
  uint64_t prd = 1;
  for (uint64_t i = 2; i <= n; ++i) {
    prd = (prd * i) % MOD;
  }
  return prd;
}

int main()
{
  uint64_t N;
  cin >> N;
  
  string S;
  cin >> S;
  
  uint64_t cntL = 1, cntR = 0;
  vector<char> dir(2 * N, ' ');
  dir[0] = 'L';
  for (uint64_t n = 1; n < 2 * N; ++n) {
    if (S[n - 1] == S[n]) {
      dir[n] = (dir[n - 1] == 'L') ? 'R' : 'L';
    } else {
      dir[n] = dir[n - 1];
    }
    
    if (dir[n] == 'L') { ++cntL; } else { ++cntR; }
  }
  
  if ((dir[2 * N - 1] != 'R') || (cntL != cntR) || (S[0] == 'W' || (S[2 * N - 1] == 'W'))) {
    cout << 0 << endl;
    return 0;
  }
  
  vector<uint64_t> csL(2 * N + 1, 0), csR(2 * N + 1, 0);
  for (uint64_t n = 0; n < 2 * N; ++n) {
    csL[n + 1] = csL[n];
    csR[n + 1] = csR[n];
    if (dir[n] == 'L') {
      ++csL[n + 1];
    } else {
      ++csR[n + 1];
    }
  }
  
  uint64_t prd = 1;
  for (uint64_t n = 0; n < 2 * N; ++n) {
    if (dir[n] == 'R') {
      prd = (prd * (csL[n] - csR[n])) % MOD;
    }
  }
  
  uint64_t ans = (prd * fact(N)) % MOD;
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3844
#include <iostream>
#include <cstring>
#include <vector>

using namespace std;

const char table[] = "abcdefghijklmnopqrstuvwxyz";

void reFunc(char *pstr, int *a, int *b) {
	int i, len, index;

	len = strlen(pstr);
	for (i = 0; i < len; i++) {
		for (index = 0; index < 26; index++) {
			if (table[(*a*index + *b) % 26] == pstr[i]) {
				cout << table[index];
			}
		}
	}
}


int findFactor(char *pstr, int *pa, int *pb) {
	int i, j;

	for (i = 1; ; i++) {
		if (i == 26) {
			return 0;
		}
		if (i == 13 || 26 % i == 0) {
			if (i != 1) {
				continue;
			}
		}

		for (j = 0; ; j++) {
			if (table[(i * 19 + j) % 26] == pstr[0]) {     //t
				if (table[(i * 7 + j) % 26] != pstr[1]) {  //h
					break;
				}
				if (table[(i * 0 + j) % 26] != pstr[2] && table[(i * 8 + j) % 26] != pstr[2]) {  //a i
					break;
				}
				if (table[(i * 19 + j) % 26] != pstr[3] && table[(i * 18 + j) % 26] != pstr[3]) {  //t s
					break;
				}

				*pa = i;
				*pb = j;
				return 1;

			}
		}
	}
}

int main(void) {
	int n, i, size, a, b,j;
	char str[260];
	char *pstr;
	vector<char *> vstr;

	cin >> n;
	cin.ignore();
	for (i = 0; i < n; i++) {
		cin.getline(str, 260);
		//cout << "str:"<<str << endl;
		pstr = strtok(str, " ");
		while (pstr != NULL) {
			vstr.push_back(pstr);
			//cout << "substr:" << pstr << endl;
			pstr = strtok(NULL, " ");
		}

		size = vstr.size();
		for (j = 0; j < size; j++) {
			if (strlen(vstr[j]) == 4) {
				if (findFactor(vstr[j], &a, &b)) {
					break;
				}
			}
		}

		for (j = 0; j < size; j++) {
			reFunc(vstr[j], &a, &b);
			if (j != size - 1) {
				cout << " ";
			}
		}
		cout << endl;
		vstr.clear();
	}

	return 0;
}








Measured memory_bytes: 3120
N, C = map(int, input().split())
D = [[int(i) for i in input().split()] for i in range(C)]

L = [[0] * C for i in range(3)]
for i in range(N):
    X = [int(i) for i in input().split()]
    for j in range(N):
        L[(i + j) % 3][X[j] - 1] += 1
        
ans = float('inf')
for i in range(C):
    for j in range(C):
        for k in range(C):
            if i != j and j != k and k != i:
                tmp = 0
                for x in range(C):
                    tmp += L[0][x] * D[x][i] + L[1][x] * D[x][j] + L[2][x] * D[x][k]
                ans = min(ans, tmp)
                    
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main(){
  int h1,m1,h2,m2,k;
  cin>>h1>>m1>>h2>>m2>>k;
  int a=h1*60+m1;
  int b=h2*60+m2;
  cout<<max((b-a)-k,0)<<endl;
  return(0);
}


Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cctype>
#include <queue>
#include <complex>
#include <functional>
#include <sstream>
#include <tuple>

using namespace std;

int main()
{
#ifdef IMPETUS
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int a, b;
    cin >> a >> b;
    cout << a * b - a - b + 1;
    return 0;
}

Measured memory_bytes: 256
/*空港 A, B, C があり、それぞれの空港の間では、双方向に飛行機が運航しています。

空港 A, B 間の飛行時間は片道 
P時間、
空港 B, C 間の飛行時間は片道 
Q時間、
空港 C, A 間の飛行時間は片道 
R時間です。

いずれかの空港からスタートして他の空港に飛行機で移動し、さらにそのどちらでもない空港に飛行機で移動するような経路を考えます。

飛行時間の和は最短で何時間になるでしょうか。*/

#include<iostream>
#include<stdio.h>
#include <algorithm>
#include<vector>

using namespace std;

int main(){

vector<int> v;
int a;
int ans;

for (int i = 0; i < 3; ++i)
{
  cin>>a;
  v.push_back(a);
}

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

v.pop_back();

ans=v[0]+v[1];


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



Measured memory_bytes: 256
#include <iostream>
#define ericxiao ios_base::sync_with_stdio(0);cin.tie(0);
#define int long long int
using namespace std;

const int maxN = 2e5, maxVal = 1e6, MOD = 998244353;
int N, cnt[maxVal + 10], W[maxVal], inv[maxVal], x;

inline void initW(){
    inv[1] = 1;
    for(int i = 2; i <= maxVal; i++){
        inv[i] = (MOD - MOD/i) * inv[(MOD % i)] % MOD;
    }
    W[1] = 1;
    for(int i = 2; i <= maxVal; i++) W[i] = inv[i];
    for(int i = 1; i <= maxVal; i++) {
        for(int j = 2 * i; j <= maxVal; j += i) W[j] = (W[j] + MOD - W[i]) % MOD;
    }
}

signed main(){
    ericxiao;
    cin >> N;
    int su = 0;
    for(int i = 0; i < N; i++){
        cin >> x;
        su = (su + x) % MOD;
        cnt[x]++;
    }
    initW();
    /*
    for(int i = 1; i <= 10; i++){
        cout << inv[i] << " ";
    }
    cout << endl;
    for(int i = 1; i <= 10; i++){
        cout << W[i] << " ";
    }

    cout << endl;
    */
    int ans = 0, tw;
    for(int d = 1; d <= maxVal; d++){
        tw = 0;
        for(int j = d; j <= maxVal; j += d){
            tw = (tw + cnt[j] * j) % MOD;
        }
        ans = (ans + ((tw * tw % MOD) * W[d]) % MOD) % MOD;
    }
    ans = (ans - su + MOD) % MOD;
    ans = ( ans * inv[2] ) % MOD;
    cout << ans << endl;
}


Measured memory_bytes: 23808
#define errOut(s) \
  { std::cerr << __LINE__ << ":" << #s << ":" << (s) << std::endl; }

#include <bits/stdc++.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
//#include <boost/multi_array.hpp>
//#include <boost/optional.hpp>
//#include <boost/range/adaptors.hpp>
//#include <boost/range/algorithm.hpp>
//#include <boost/range/irange.hpp>
#pragma clang diagnostic pop

using namespace std;

int64_t solve(int64_t a) { return a + a * a + a * a * a; }

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int64_t a;
  std::cin >> a;
  auto const res = solve(a);
  std::cout << res << std::endl;
  return 0;
}


Measured memory_bytes: 3652