akhauriyash/Code-Regression huggingface dataset:
S = input()
INF = 10 ** 9 + 7
length = len(S)
tmp = 1
mod = 0
cnt = 0
arr = []
for i in reversed(range(length)):
    if S[i] == "?":
        arr.append(tmp)
        cnt += 1
    else:
        mod += (tmp * int(S[i])) % 13
        mod %= 13
    tmp = (tmp * 10) % 13
tar = (5 - mod) % 13

dp = [[0 for _ in range(13)] for _ in range(cnt + 3)]
dp[0][0] = 1
for i in range(1, cnt + 1):
    for j in range(13):
        for k in range(10):
            dp[i][(j + arr[i - 1] * k) % 13] += dp[i - 1][j]
            dp[i][(j + arr[i - 1] * k) % 13] %= INF
ans = dp[cnt][tar]
print(ans)

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

using namespace std;


typedef long long int ll;
typedef vector<int>vi;
typedef deque<int> di;
#define f(i, a, b) for(int i = a; i < b; i++)

int main () {
int n;
cin >> n;
int x[n];
int sum = 0;
f(i, 0, n) {
cin >> x[i];

}
f(j , 0 , n) {

    f(k, 0, n) {
    if (j!=k) {
    sum+=(x[j]*x[k]);
    }
    }
}
cout << sum/2;
return 0;

}


Measured memory_bytes: 3584
#include<iostream>
using namespace std;
int main(){
char code[1000],str[2];
cin>>code;
for(int i=0;;i++){
if(code[i]=='\0')break;
if(code[i]=='C')cout<<'Z';
else if(code[i]=='B')cout<<'Y';
else if(code[i]=='A')cout<<'X';
else{
    str[0]=code[i]-3;
cout<<str;
}
}
cout<<endl;
return 0;
}

Measured memory_bytes: 1132
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

int main(){
    vec a(3);
    rep(i,3) cin>>a[i];
    sort(all(a));
    cout<<a[0]+a[1]<<endl;
}

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

using i64 = long long int;

int main(){
    i64 n;
    cin >> n;
    vector<i64> a;
    for(i64 i=1;i<=n;++i){
        i64 tmp;
        cin >> tmp;
        tmp -= i;
        a.push_back(tmp);
    }

    sort(a.begin(), a.end());
    i64 ans = LLONG_MAX;
    for(i64 j=max(n/2-1000,0ll);j<=min(n/2+1000,n-1);++j){
        i64 tmp = 0;
        for(int i=0;i<n;++i){
            tmp += abs(a[i] - a[j]);
        }
        ans = min(ans, tmp);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2420
n = int(input())
step = list(map(int, input().split()))

ans = [float('inf')]*n
ans[0] = 0
ans[1] = abs(step[1] - step[0])

def dp(n):
  for i in range(2, n):
    ans[i] = min(ans[i], ans[i-1] + abs(step[i] - step[i-1]))
    ans[i] = min(ans[i], ans[i-2] + abs(step[i] - step[i-2]))
  return ans[n-1]

print(dp(n))

Measured memory_bytes: 13980
#include<stdio.h>
main(){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a>b){
        printf("a > b\n");
    }
    else if(a<b){
        printf("a < b\n");
    }
    else{
        printf("a == b\n");
    }
    return 0;
}


Measured memory_bytes: 2032
#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;}

const int INF = 1 << 30;
int n,m;
vector<vector<int>> d;


void warshall_floyd(int n){ //nはノード数
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      for(int k = 0; k < n; k++){
        if(d[j][i] == INF || d[i][k] == INF) continue;
        d[j][k] = min(d[j][k],d[j][i]+d[i][k]);
      }
    }
  }
}


int main(){
  int h,w; cin >> h >> w;
  n = 10;
  d.resize(n,vector<int>(n,INF));
  
  rep(i,n)rep(j,n){
    cin >> d[i][j];
  }
  int A[h][w];
  warshall_floyd(n);
  
  rep(i,h)rep(j,w){
    cin >> A[i][j];
  }
  
  int ans = 0;
  rep(i,h)rep(j,w){
    if(A[i][j] != -1){
      ans += d[A[i][j]][1];
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

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

const ll INF = 1001001001;

int main(){
  int n;
  string s,t;
  cin>>n>>s>>t;
  vector<char>vec(2*n);
  for(int i=0;i<2*n;i++){
    if(i%2==0){
      vec[i]=s.at(i/2);
    }else{
      vec[i]=t.at(i/2);
    }
    cout<<vec[i];
  }

  
  
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
     
#define ll long long
#define loop(i,a,n) for(ll i=a;i<n;++i)
#define revloop(i,a,b) for(ll i=a;i>=b;--i)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 99999999999999
#define MOD 1000000007
 
void func()
{
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll cnt=0;
    loop(i,0,n){
        if(s[i]=='R') ++cnt;
    }
    ll ans=0;
    loop(i,0,cnt){
        if(s[i]=='W') ++ans;
    }
    cout<<ans<<"\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w" , stdout);
    #endif
 
    ll t=1;
    //cin>>t;
    while(t--)
    {
        func();
    }

}

Measured memory_bytes: 3732
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
 
typedef long long ll;
typedef vector<int> vi;
typedef unsigned long ul;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef set<int> si;
typedef multiset<int> mi;
 
const ll INF = 1e18;
const int MOD = 1e9+7;

int main() {
	
	ll n, ans=0;
	cin>>n;
	
	for(ll i=1; i<=n; ++i) {
		ll x=n/i;
		ans+=i*((x+1)*x)/2;
	}
	
	cout<<ans<<"\n";
}


Measured memory_bytes: 3604
n = int(input())

ss = []
ps = []
sps = []

for i in range(n):
    temp = input().split()
    ss.append(temp[0])
    ps.append(temp[1])
    sps.append(temp[0] + ' ' + temp[1] + ' ' + str(i))

def check(sps):
    city = sps[0].split()[0]
    score = int(sps[0].split()[1])
#    score = sps[0].split()[1]
    index = int(sps[0].split()[2])
    target = 0


    for i in range(1, len(sps)):
#        print(sps[i].split()[1])
#        print(score)

        if sps[i].split()[0] == city and score < int(sps[i].split()[1]):
#        if sps[i].split()[0] == city and score < sps[i].split()[1]:
            city = sps[i].split()[0]
            score = int(sps[i].split()[1])
            index = int(sps[i].split()[2])
            target = i
        elif sps[i].split()[0] < city:
            city = sps[i].split()[0]
            score = int(sps[i].split()[1])
            index = int(sps[i].split()[2])
            target = i

    # print(index + 1)
    # del sps[i]
#    return index
    return target, index

for i in range(n):
    target, index = check(sps)
    print(index + 1)
    del sps[target]


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int int_sort(const void*a,const void *b) {
    return *(long long int *) b - *(long long int *) a;
    //qsort(b, a, sizeof(long long int), int_sort);
}
int main() {
  double a,n,t;
  double max,flag=0;
  int h[100000];
  double tm[10000];
  cin >>n>>t>>a;
  for(int i=0;i<n;i++) {
      cin>>h[i];
      tm[i]=t-(h[i]*0.006);
      tm[i]-=a;
      if(tm[i]<0) tm[i]*=-1;
      //cout<<tm[i]<<"\n" ;
  }
  max=tm[0];
  for(int i=1;i<n;i++){
      if(max>tm[i]){
          flag=i;
          max=tm[i];
      }
  }
    cout<<flag+1;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
int count(int k)
{
	int ret=0;
	for(;k;k/=10) ret++;
	return ret;
}
int main()
{
	long long n;
	scanf("%lld",&n);
	int x=sqrt(n);
	while(n%x) x--;
	printf("%d\n",count(n/x));
	return 0;
}

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

/**
 * vector<int>ar(3);
 * for(auto&e:ar){
 *     scanf("%d",&e);
 * }
 * sort(ar.begin(),ar.end())
 * int sum=accumulate(ar.begin(),ar.end(),0);
 ***/

int main(){
    double pai=3.141592653589;
    int x,y;
    while(true){
        scanf("%d %d",&x,&y);
        if(x==y && x==0){
            break;
        }else if(x>y){
            printf("%d %d\n",y,x);
        }else{
            printf("%d %d\n",x,y);
        }
    }
    return 0;
}

Measured memory_bytes: 1172
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class Edge{
public:
    int to, cost;
    Edge(int to0, int cost0){
        to = to0;
        cost = cost0;
    }
};

int main()
{
    for(;;){
        int n, m, l, k, a, h;
        cin >> n >> m >> l >> k >> a >> h;
        if(n == 0)
            return 0;

        vector<bool> isFreeze(n, false);
        for(int i=0; i<l; ++i){
            int x;
            cin >> x;
            isFreeze[x] = true;
        }

        vector<vector<Edge> > edges(n);
        for(int i=0; i<k; ++i){
            int x, y, t;
            cin >> x >> y >> t;
            edges[x].push_back(Edge(y, t));
            edges[y].push_back(Edge(x, t));
        }

        vector<vector<int> > dp(n, vector<int>(m+1, INT_MAX));
        dp[a][m] = 0;
        multimap<int, pair<int, int> > mm;
        mm.insert(make_pair(0, make_pair(a, m)));
        while(!mm.empty()){
            int cost = mm.begin()->first;
            int curr = mm.begin()->second.first;
            int rest = mm.begin()->second.second;
            mm.erase(mm.begin());
            if(cost > dp[curr][rest])
                continue;

            if(isFreeze[curr] && rest < m && cost + 1 < dp[curr][rest+1]){
                dp[curr][rest+1] = cost + 1;
                mm.insert(make_pair(cost+1, make_pair(curr, rest+1)));
            }

            for(unsigned i=0; i<edges[curr].size(); ++i){
                int cost2 = cost + edges[curr][i].cost;
                int to = edges[curr][i].to;
                int rest2 = rest - edges[curr][i].cost;
                if(rest2 >= 0 && cost2 < dp[to][rest2]){
                    dp[to][rest2] = cost2;
                    mm.insert(make_pair(cost2, make_pair(to, rest2)));
                }
            }
        }

        int ret = *min_element(dp[h].begin(), dp[h].end());
        if(ret == INT_MAX)
            cout << "Help!" << endl;
        else
            cout << ret << endl;
    }
}

Measured memory_bytes: 1688
#include <bits/stdc++.h>
using namespace std;
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;}
using Int = long long;
const char newl = '\n';


template<typename T,T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD-2);}

  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}

  Mint operator+(Mint a) const{return Mint(v)+=a;}
  Mint operator-(Mint a) const{return Mint(v)-=a;}
  Mint operator*(Mint a) const{return Mint(v)*=a;}
  Mint operator/(Mint a) const{return Mint(v)/=a;}

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}

  static Mint comb(long long n,int k){
    Mint num(1),dom(1);
    for(int i=0;i<k;i++){
      num*=Mint(n-i);
      dom*=Mint(i+1);
    }
    return num/dom;
  }
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}


template<typename F>
struct FixPoint : F{
  FixPoint(F&& f):F(forward<F>(f)){}
  template<typename... Args>
  decltype(auto) operator()(Args&&... args) const{
    return F::operator()(*this,forward<Args>(args)...);
  }
};
template<typename F>
inline decltype(auto) MFP(F&& f){
  return FixPoint<F>{forward<F>(f)};
}

//INSERT ABOVE HERE

using M = Mint<int>;
const int MAX = 5050;
M po[MAX],op[MAX];


M dfs(int h,int w);

M dp2[MAX][MAX];
int used2[MAX][MAX]={};
M sum(int h,int w){
  M &res=dp2[h][w];
  if(used2[h][w]) return res;
  used2[h][w]=1;

  res=M(0);
  if(w>0) res+=sum(h,w-1);
  res+=dfs(h,w)*op[w+1]*M(w);
  return res;
}

M dp[MAX][MAX];
int used[MAX][MAX]={};
M dfs(int h,int w){
  M &res=dp[h][w];
  if(used[h][w]) return res;
  used[h][w]=1;

  assert(h>=0 and w>=0);
  if(h==0 or w==0) return res=M(1);
  if(w==1) return res=po[h];
  if(h==1) return res=po[w];

  res=M(0);
  res+=dfs(h-1,w)*M(w+1);
  res+=sum(h-1,w-1)*po[w];
  return res;
};
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n,m;
  cin>>n>>m;
  po[0]=op[0]=M(1);
  for(int i=0;i+1<MAX;i++) po[i+1]=po[i]*M(2);
  for(int i=0;i+1<MAX;i++) op[i+1]=op[i]*M(2).inv();

  cout<<dfs(n,m)<<newl;
  return 0;
}


Measured memory_bytes: 400828
/*
    Reference :-
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forn1(i, n) for (int i = 1; i < int(n); i++)
#define PI pair<int,int>
ll mod=1000000007;

ll power(ll n,ll k){
    ll ans=1;
    while(k){
        if(k&1)ans=(ans*n)%mod;
        k/=2;
        n=(n*n)%mod;
    }
    //ans=(ans-1+mod)%mod;
    return ans;
}

int main(){
    //std::ios::sync_with_stdio(false);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    string s;
    cin>>s;
    int ans=0;
    for(int i=0;i<n-2;i++){
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')ans++;
    }
    cout<<ans;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
const int INF=1000000000+5;
const int N=2e5+5;
const ll oo=1e18+5;
const ll mod=1e9+7;

vector<int> v[N];
vector<bool> used;

int dfs(int u){
	int ans=1;
	used[u]=1;
	for(int x:v[u]){
		if(used[x]) continue;
		ans+=dfs(x);
	}
	return ans;
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	int n,m;
	cin>>n>>m;
	used.resize(n+1);
	for(int i=0;i<m;++i){
		int x,y;
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	int maxx=0;
	for(int i=1;i<=n;++i){
		if(!used[i]){
			maxx=max(maxx,dfs(i));
		}
	}
	cout<<maxx;
	return 0;
}


Measured memory_bytes: 23904
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
  int a,b,c;
    cin >> a >> b >> c;
    if(c>=a && c<=b){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}
 

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

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

  for(int i = 0;i <= (n / 4); ++i) {
    for(int j = 0; j <= (n / 7); ++j) {
      if((i * 4 + j * 7) == n) {
        cout << "Yes";
        return 0;
      }
    }
  }

  cout << "No";
}


Measured memory_bytes: 256
import java.io.BufferedReader;   
import java.io.InputStreamReader;     
public class Main {   
    public static void main(String args[]) throws Exception {   
        final BufferedReader br = new BufferedReader   
                                 (new InputStreamReader(System.in));   
  
        while(true) {   
            final int n = Integer.parseInt(br.readLine());   
            if(n == 0)   
                break;   
  
            final int[] inputs = new int[n];   
            for(int i = 0; i < inputs.length; i++)   
                inputs[i] = Integer.parseInt(br.readLine());   
  
            int max = Integer.MIN_VALUE;   
            int sum;   
  
            for(int i = 0; i < inputs.length; i++) {   
                sum = 0;   
  
                for(int j = i; j < inputs.length; j++) {   
                    sum += inputs[j];   
                    max = Math.max(sum, max);   
                }   
            }   
  
            System.out.println(max);   
        }   
    }   
} 

Measured memory_bytes: 9908
a = []
for i in range(3):
    x = list(map(int, input().split()))
    a.append(x)
n = int(input())

num = [[0] * 3 for _ in range(3)]
for i in range(n):
    x = int(input())
    for j in range(3):
        for k in range(3):
            if x == a[j][k]:
                num[j][k] = 1


ans = False
for i in range(3):
    cnt = 0
    for j in range(3):
        if num[i][j] == 1:
            cnt += 1
    if cnt == 3:
        ans = True

for i in range(3):
    cnt = 0
    for j in range(3):
        if num[j][i] == 1:
            cnt += 1
    if cnt == 3:
        ans = True

if num[0][0] == 1 and num[1][1] == 1 and num[2][2] == 1:
    ans = True
if num[0][2] == 1 and num[1][1] == 1 and num[2][0] == 1:
    ans = True

if ans:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
    string o, e;
    cin >> o >> e;
    for(int i = 0; i < e.size(); i++)
        cout << o.at(i) << e.at(i);
    if(o.size() > e.size()) cout << o.at(o.size() - 1);
}

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

int main() {
  string s; cin >> s;
  int cnt = 0;
  for (int i = 0; i < s.size(); i++) {
    char t; cin >> t;
    if(s.at(i) != t) {
      cnt++;
    }
  }
  cout << cnt;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    string s;
    cin >> s;
    int len = s.size();
    ll cnt = 0, bla = len-1;
    for(int i=len-1;i>=0;i--){
        if(s[i]=='B'){
            cnt += bla - i;
            bla--;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int n;
int a[200001],b[200001];
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	rep(i,n){
		cin>>a[i];
		b[i]=a[i];
	}
	sort(b,b+n);
	rep(i,n)
	if(a[i]<b[n/2])
	cout<<b[n/2]<<"\n";
	else
	cout<<b[n/2-1]<<"\n";	
	re 0;
}


Measured memory_bytes: 3712
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;

int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	
	int x1,x2,y1,y2;
	cin>>x1>>y1>>x2>>y2;
	int dx=abs(x2-x1),dy=abs(y2-y1);
//	cout<<dx<<" "<<dy<<endl;
	int x3,x4,y3,y4;
	if(x1<x2){
		if(y1<y2){
			x3=x2-dy;
			y3=y2+dx;
			x4=x3-dx;
			y4=y3-dy;
		}
		else{
			x3=x2+dx;
			y3=y2+dy;
			x4=x3-dy;
			y4=y3+dx;
		}
	}else{
		if(y1<y2){
//			cout<<dx<<" "<<dy<<endl;
			x3=x2-dy;
			y3=y2-dx;
			x4=x3+dx;
			y4=y3-dy;
		}
		else{
			x3=x2+dy;
			y3=y2-dx;
			x4=x3+dx;
			y4=y3+dy;
		}
	}
	cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
	
	
	
	
	
//////////////////////////////////////////////////////
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define MP make_pair
#define pb push_back
const int INF = 1e18;
const int MOD = INF+7;
using P = pair<int,int>;

signed main(){
    int N;
    cin >> N;
    vector<int> A(N),B(N);
    int sum_A = 0,sum_B = 0;
    rep(i,N) cin >> A[i],sum_A += A[i];
    rep(i,N) cin >> B[i],sum_B += B[i];

    if(sum_A < sum_B){
        cout << -1 << endl;
        return 0;
    }

    int ans = N;
    sum_B = 0;
    vector<P> mini;
    rep(i,N){
        if(A[i] < B[i]) sum_A -= B[i];
        else mini.push_back({A[i]-B[i],i}),sum_B += B[i];
    }
    sort(all(mini));
    rep(i,mini.size()){
        if(sum_A - A[mini[i].second] - (sum_B-B[mini[i].second]) >= 0) sum_B -= B[mini[i].second] ,sum_A -= A[mini[i].second],--ans;
        else break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3956
#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;


int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

const string MINUSINF = "-";

void chmax(string &a, string b){
  if(a == MINUSINF) a = b;
  else if(a.size() < b.size()) a = b;
  else if(a.size() == b.size()){
    if(a<b) a = b;
  }
}

ll match[10] = {2,5,5,4,5,6,3,7,6};
string dp[11000];

int main(){
  int n,m; cin >> n >> m;
  vector<int> a(m);
  rep(i,m) cin >> a[i];
  rep(i,11000) dp[i] = MINUSINF;
  dp[0] = "";
  
  for(int i = 0; i <= n; i++){
    if(dp[i] == MINUSINF) continue;
    for(auto a1:a) chmax(dp[i+match[a1-1]], dp[i] + (char)('0'+a1));
  }
  cout << dp[n] << endl;
  
  return 0;
}

Measured memory_bytes: 43776
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=150000;
const int MAXM=MAXN-1;

int n;
int ghead[MAXN],gnxt[2*MAXM],gto[2*MAXM];

double Edown[MAXN];
double Enotto[MAXN];
double E[MAXN];

void dfs1(int at,int par) {
	Edown[at]=0; int cnt=0;
	for(int x=ghead[at];x!=-1;x=gnxt[x]) {
		int to=gto[x]; if(to==par) continue;
		dfs1(to,at);
		Edown[at]+=1+Edown[to];
		++cnt;
	}
	if(cnt!=0) Edown[at]/=cnt;
}

void dfs2(int at,int par) {
	double sum=0; int cnt=0;
	for(int x=ghead[at];x!=-1;x=gnxt[x]) {
		int to=gto[x]; if(to==par) continue;
		sum+=1+Edown[to],++cnt;
	}
	if(par!=-1) sum+=1+Enotto[at],++cnt;
	for(int x=ghead[at];x!=-1;x=gnxt[x]) {
		int to=gto[x]; if(to==par) continue;
		Enotto[to]=cnt==1?0:(sum-(1+Edown[to]))/(cnt-1);
		dfs2(to,at);
	}
	E[at]=cnt==0?0:sum/cnt;
}


void run() {
	scanf("%d",&n);
	REP(i,n) ghead[i]=-1;
	REP(i,n-1) {
		int a,b; scanf("%d%d",&a,&b); --a,--b;
		gnxt[2*i+0]=ghead[a],ghead[a]=2*i+0,gto[2*i+0]=b;
		gnxt[2*i+1]=ghead[b],ghead[b]=2*i+1,gto[2*i+1]=a;
	}
	dfs1(0,-1);
	dfs2(0,-1);
	REP(i,n) printf("%.9lf\n",E[i]);
}

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


Measured memory_bytes: 14336
#include <iostream>
#include <vector>
using namespace std;
typedef vector <double> dvector;

int nums_out(dvector &A){
	int n=A.size();
	for (int i=0; i<n; i++){
		cout << A[i];
		if (i!= n-1) cout<<" ";
		else cout<<endl;
	}
	return 0;
}

int insertionsort(dvector &A){
	double key;
	int i, n=A.size();
	nums_out(A);
	for (int j=1; j<n; j++){
		key = A[j];
		i = j-1;
		while (i>=0){
			if (A[i] <= key) break;
			A[i+1] = A[i];
			i--;
		}
		A[i+1] = key;
		nums_out(A);
	}
	return 0;
}

int main(void){
	int n;
	cin>>n;
	dvector A(n);

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

	return 0;
}

Measured memory_bytes: 1284
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int A,B; cin>>A>>B;
  string ans="Zero";
  if(0<A)
    ans="Positive";
  else if(B<0){
    if((B-A)%2==0)
      ans="Negative";
    else
      ans="Positive";
  }
  cout<<ans<<endl;
  }


Measured memory_bytes: 256
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li_())
b = list(li())
c = list(li())

ans = 0
bef = -10

for i, ai in enumerate(a):
    ans += b[ai]
    if bef == (ai - 1):
        ans += c[ai - 1]

    bef = ai

print(ans)

Measured memory_bytes: 3064
n=int(input())
a,b,c=map(int,input().split())
dp=[[a,b,c]]
for i in range(1,n):
    a,b,c=map(int,input().split())
    el0=max(dp[i-1][1],dp[i-1][2])+a
    el1=max(dp[i-1][0],dp[i-1][2])+b
    el2=max(dp[i-1][0],dp[i-1][1])+c
    dp.append([el0,el1,el2])
print(max(dp[n-1][0],dp[n-1][1],dp[n-1][2]))


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

int max(int x, int y){
  if(x>y) return x;
  return y;
}
int min(int x, int y){
  if(x<y) return x;
  return y;
}

int n;
long long a[3010];
long long dp[3010][3010];
int main() {
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a[i];
    dp[i][i]=0;
  }
  for(int l=1;l<=n;l++){
    for(int i=0;i<=n-l;i++){
      if((n-l)%2==0) dp[i][i+l]=max(dp[i][i+l-1]+a[i+l-1],dp[i+1][i+l]+a[i]);
      if((n-l)%2==1) dp[i][i+l]=min(dp[i][i+l-1]-a[i+l-1],dp[i+1][i+l]-a[i]);
    }
  }
  cout << dp[0][n] << endl;
}

Measured memory_bytes: 70016
// Example program
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

typedef long long ll;

int main() {
      int n = 0;
      cin >> n;
      ll l = 0, r = 0;
      ll res = 0;
      for(int i = 0; i < n; ++i){
            cin >> l >> r;
            r-=l;
            res+=r;
            ++res;
        } 
      cout << res << endl;

}


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

n, m, l = map(int, input().split())
INF = float("inf")

def warshall_floyd(d, n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d

d = [[INF] * n for _ in range(n)]
for i in range(n):
    d[i][i] = 0
for i in range(m):
    a, b, c = map(int, input().split())
    d[a - 1][b - 1] = c
    d[b - 1][a - 1] = c
d = warshall_floyd(d, n)

d2 = [[INF] * n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if d[i][j] <= l:
            d2[i][j] = 1
    d2[i][i] = 0
d2 = warshall_floyd(d2, n)

q = int(input())
for _ in range(q):
    s, t = map(int, input().split())
    res = d2[s - 1][t - 1]
    print(-1 if res == INF else res - 1)

Measured memory_bytes: 127708
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

n = inp[0]
s = gets.chomp.split("").map &:to_i
at = na3(10,10,10,false)
dp = na(10,false)
dp2 = na(100,false)

s.reverse.each do |d|

  (0..99).each do |dd|
    if(dp2[dd] == true)
      at[d*100+dd] = true
    end
  end
  (0..9).each do |dd|
    if(dp[dd] == true)
      dp2[d*10 + dd] = true
    end
  end
  dp[d] = true
end

p at.flatten.count(true)

Measured memory_bytes: 4092
en = list(map(int,input().split()))
sum = 0
for i in range(2):
	if en[i] == 1:
		sum += 300000;
	elif en[i] == 2:
		sum += 200000;
	elif en[i] == 3:
		sum +=100000;
if en[0] ==1 and en[1] == 1:
	sum += 400000
print(sum)

Measured memory_bytes: 3064
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int main() {
    int q;
    ll sum=0;
    cin>>q;
    while(q-->0) {
        int p,n;
        char c;
        cin>>p>>c>>n;
        if(c=='(') sum+=n;
        else sum-=n;
        if(sum==0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 1156
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (a > b) {
            int b_end = b + w;
            if (a - b_end > 0) {
                System.out.println(a - b_end);
            } else {
                System.out.println(0);
            }
            return;
        } else if (b > a) {
            int a_end = a + w;
            if (b - a_end > 0) {
                System.out.println(b - a_end);    
            } else {
                System.out.println(0);
            }
            return;
        } else {
            System.out.println(0);
        }
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653

int main(){
	ll x; cin >> x;
	ll y = 100;
	ll ans = 0;
	while(y<x){
		y = y/100+y;
		ans++;
	}
	cout << ans << endl;
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

vector<string> v;
ll N;

inline void dfs(vector<ll> &u) {
    if (u.size() == N - 1) {
        string s = "a";
        char c = 'b';
        REP(i, u.size()) {
            if (s.size() > u[i]) {
                s.push_back(s[u[i]]);
            }
            else {
                s.push_back(c);
                c = (char) (c + 1);
            }
        }
        v.push_back(s);
        return;
    }

    for (ll i = 0; i <= u.size() + 1; ++i) {
        bool exist = false;
        for (ll j = u.size() - 1; j > i; --j) {
            if (u[j] == i) {
                exist = true;
                break;
            }
        }
        if (exist)
            continue;
        u.push_back(i);
        dfs(u);
        u.pop_back();
    }
}

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

    v.clear();
    vector<ll> u;
    dfs(u);

    sort(v.begin(), v.end());
    //cout << v.size() << endl;
    v.erase(unique(v.begin(), v.end()), v.end());
    //cout << v.size() << endl;
    REP(i, v.size()) {
        cout << v[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 44520
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 S          PIC X(30).
01 i          PIC 9(10).
01 flg        PIC 9(10) VALUE ZERO.

PROCEDURE DIVISION.
  ACCEPT S.
  PERFORM VARYING i FROM 2 BY 1 UNTIL FUNCTION STORED-CHAR-LENGTH(S) < i
    IF S(i - 1:1) = S(i:1)
      MOVE 1 TO flg
      EXIT PERFORM
    END-IF
  END-PERFORM.
  IF ZERO <> flg
    DISPLAY "Bad"
  ELSE
    DISPLAY "Good"
  END-IF.
  STOP RUN.


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

int main(){
  string s;
  cin >> s;
  int n,t=0;
  n=s.size();
  for(int i=0;i<n;i++){
    t += (s.at(i)-'0');
  }
  if(t%9==0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3752
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

ll solve(int N, int D){
  ll ret = 127*(N-1);
  if(N%2==1){
    ret += D;
  }else{
    ret += (127^D);
  }

  return ret;
}

int main(){
  ios::sync_with_stdio(false);
  int T;
  cin >> T;
  rep(t,T){
    int N, D;
    cin >> N >> D;
    cout << solve(N, D) << endl;
  }
  return 0;
}


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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}

int main(){
    string S;
    cin >> S;
    int N = S.size();
    // idx, 1個前, 0ゾーンの長さの偶奇, 1が連続中かどうか, 収支+2
    static int64_t dp[300001][2][2][2][6];
    dp[0][0][0][0][2] = 1;
    for(int i=0; i<N; i++) for(int b=0; b<2; b++) for(int z=0; z<2; z++) for(int l=0; l<2; l++) for(int g=0; g<6; g++){
        int64_t v = dp[i][b][z][l][g];
        if(v == 0) continue;
        for(int a=0; a<2; a++) if(S[i] - '0' != 1-a){
            int b2 = a, z2 = z, l2 = l, g2 = g;
            if(a && (b || i==0 || i==N-1)){
                l2 = 1;
                if(l){
                    g2++;
                }else{
                    if(b) z2 = 1-z;
                    if(i > 0) g2 -= 2-z2;
                    g2 += 1+b;
                    z2 = 0;
                }
            }else{
                l2 = 0;
                z2 = 1-z;
            }
            g2 = min(5, g2);
            add(dp[i+1][b2][z2][l2][g2], v);
        }
    }

    int64_t ans = 0;
    for(int b=0; b<2; b++) for(int z=0; z<2; z++) for(int l=0; l<2; l++) for(int g=0; g<6; g++){
        int g2 = g;
        if(!l) g2 -= 2-z;
        if(g2 > 2) add(ans, dp[N][b][z][l][g]);
    }
    cout << ans << endl;
}

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

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;


//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)


struct Edge {
    int to, from;
    ll cost;
    Edge(int from, int to, ll cost): from(from), to(to), cost(cost) {}
};

typedef vector<vector<Edge>> AdjList;
AdjList graph;

int A[510];
int N, K; 

bool f(int n){
    vector<ll> v;
    vector<ll> vv;
    REP(i, N) v.push_back(A[i]%n);
    sort(all(v));

    
    vv.push_back(0);
    REP(i, N){
        vv.push_back(vv.back() + v[i]);
    }
    for(int i=0; i<N; ++i){
        ll A = vv[i];
        ll B = (N-i)*1LL*n - (vv[N] - vv[i]);

        if(max(A, B) <= K) return 1;
    }
    return 0;
}
int main() {
    //cin.tie(0);
    //ios::sync_with_stdio(false);
    //cout << fixed << setprecision(10);

    cin >> N >> K;
    
    int S = 0;
    REP(i, N) {
        cin >> A[i];
        S += A[i];
    }

    int ans = 0;
    for(int x = 1; x*x<=S; ++x){
        if(S%x == 0){
            if(f(x)) ans = max(ans, x);
            if(f(S/x)) ans = max(ans, S/x);
        }
    }
    
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int x,n,s,f;
int p[105];
int main(){
	scanf("%d%d",&x,&n);
	for(int i=1;i<=n;++i){
		scanf("%d",p+i);
	}
	p[n+1]=100001;
	p[0]=-100001;
	sort(p+1,p+1+n);
	for(int i=0;i<=n;++i){
		if(p[i]<=x&&x<p[i+1]){
			s=i;
			f=i+1;
			break;
		}
	}
	for(int i=0;i<=1000;++i){
		if(p[s]!=x-i){
			printf("%d\n",x-i);
			return 0;
		}
		else s--;
		if(i==0)continue;
		if(p[f]!=x+i){
			printf("%d\n",x+i);
			return 0;
		}
		else f++;
	}
	return 0;
}


Measured memory_bytes: 1724
//84104971101048411497 - Can you guess what does this mean?
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define maxK 4005
#define oo 1000000000000000007LL
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

ll mul(ll a, ll b) {
    if (a*b/a != b) return oo;
    return min(oo, a*b);
}

int n, k, f[2][maxK][maxK];

int Calc(int c, int x1, int y1, int x2, int y2) {
    return f[c][x2][y2]-f[c][x1-1][y2]-f[c][x2][y1-1]+f[c][x1-1][y1-1];
}

int main () {
    scanf("%d%d", &n, &k);
    fto(i, 1, n) {
        int x, y; char s[2];
        scanf("%d%d%s", &x, &y, s);

        int c = (s[0] == 'W') ? 0 : 1;
        ++f[c][x%(2*k)+1][y%(2*k)+1];
    }

    fto(c, 0, 1) {
        fto(i, 1, 2*k) fto(j, 1, 2*k) f[c][i+2*k][j] = f[c][i][j+2*k] = f[c][i+2*k][j+2*k] = f[c][i][j];
    }

//    fto(c, 0, 1) {
//        debug(c);
//        fto(i, 1, 4*k) {
//            fto(j, 1, 4*k) printf("%d ", f[c][i][j]);
//            puts("");
//        }
//    }

    fto(c, 0, 1) {
        fto(i, 1, 4*k) fto(j, 1, 4*k) f[c][i][j] += f[c][i-1][j]+f[c][i][j-1]-f[c][i-1][j-1];
    }

    int ans = 0;
    fto(x, 1, 2*k) fto(y, 1, 2*k)
        ans = max(ans, Calc(0, x, y, x+k-1, y+k-1)+Calc(0, x+k, y+k, x+2*k-1, y+2*k-1)+Calc(1, x, y+k, x+k-1, y+2*k-1)+Calc(1, x+k, y, x+2*k-1, y+k-1));
    printf("%d", ans);

    return 0;
}


Measured memory_bytes: 125568
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] A = new int[M];
		int[] B = new int[M];
		int[] C = new int[M];
		for (int i = 0; i < M; ++i) {
			A[i] = sc.nextInt();
			B[i] = sc.nextInt();
			C[i] = sc.nextInt();
		}
		int[] d = new int[N];
		Arrays.fill(d, -1);
		d[0] = 0;
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < M; ++j) {
				if (d[A[j]] == -1) continue;
				d[B[j]] = Math.max(d[B[j]], d[A[j]] + C[j]);
			}
		}
		System.out.println(d[N - 1]);
	}
}

Measured memory_bytes: 25188
#include <iostream>
#include <algorithm>

using namespace std;

int table[2][101010];
int v[101010];

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        table[i % 2][v[i]]++;
    }
    int max1 = 0;
    int max_index1 = 0;
    for (int i = 0; i < 101010; i++) {
        if (max1 < table[0][i]) {
            max1 = table[0][i];
            max_index1 = i;
        }
    }
    int max1_2 = 0;
    for (int i = 0; i < 101010; i++) {
        if (i == max_index1) continue;
        if (max1_2 < table[0][i]) {
            max1_2 = table[0][i];
        }
    }
    int max2 = 0;
    int max_index2 = 0;
    for (int i = 0; i < 101010; i++) {
        if (max2 < table[1][i]) {
            max2 = table[1][i];
            max_index2 = i;
        }
    }
    int max2_2 = 0;
    for (int i = 0; i < 101010; i++) {
        if (i == max_index2) continue;
        if (max2_2 < table[1][i]) {
            max2_2 = table[1][i];
        }
    }
    if (max_index1 == max_index2) {
        cout << min(n - max1 - max2_2, n - max1_2 - max2) << endl;
    }
    else {
        cout << n - max1 - max2 << endl;
    }
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <stdlib.h>
 
int main(void)
{
	int num[101], min, max, i, n;
	scanf("%d", &n);
	for(i = 0; i < n; i++){
		scanf("%d", &num[i]);
	}
	min = num[0];
	max = num[0];
	for(i = 1; i < n; i++){
		if(max < num[i])
			max = num[i];
		if(min > num[i])
			min = num[i];
	}
	printf("%d", max - min);
	return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> P;

string s[3];

int main(){
    for(int i=0;i<3;i++)    cin >> s[i];

    for(int i=0;i<3;i++)    cout << s[i][i];
    cout << endl;
}

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

typedef long long ll;


int main(){
    int N,M;
    int sum = 0;
    cin>>N>>M;
    vector<int> A(N);
    for(int i=0; i<N; i++){
        cin>>A[i];
        sum += A[i];
    }

    bool flag = false;
    int cnt = 0;

    for(int i=0; i<N; i++){
        if((double)A[i] < (double)sum/(4*M)) continue;
        else cnt++;
    }

    if(cnt >= M) flag = true;

    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 256
K = gets.to_i
def s(n)
  res = 0
  while n > 0
    res += n % 10
    n /= 10
  end
  res
end

def t(n)
  n.fdiv s(n)
end

n = 0
add = 1
K.times{
  if t(n + add) < t(n + add * 10)
    p n += add
  else
    p n += add *= 10
  end
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using vec_b = vector<bool>;
using vec_str = vector<string>;
using graph = mat;
using edge = pair<ll,ll>;
using wgraph = vector<vector<edge>>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back


int main()
{
    ll N, K;
    cin >> N >> K;
    ll R, S, P;
    cin >> R >> S >> P;
    string _T;
    cin >> _T;
    vec T(N+K, 3);
    REP(i,0,N) {
        if(_T[i] == 'r') T[i] = 0;
        else if(_T[i] == 's') T[i] = 1;
        else T[i] = 2;
    } 

    ll sum = 0;
    vector<ll> prev(K, 3);
    map<ll,ll> score;
    score[0] = R;
    score[1] = S;
    score[2] = P;
    ll kachi;

    REP(i,0,N) {
        kachi = (T[i] + 2) % 3;
        if(kachi != prev[i%K]) {
            sum += score[kachi];
            prev[i%K] = kachi;
        }
        else {
            ll h;
            REP(j,0,3) {
                if(j != prev[i%K] && j != (T[i+K] + 2) % 3) h = j;
            }
            prev[i%K] = h;
        }
    }
    _PR(sum);


    return 0;
}

/*



*/

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).rbegin(), (x).rend()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    string s;
    int x, y;
    cin >> s >> x >> y;

    int forx       = true;
    bool firstTurn = true;
    vec<int> xs, ys;
    int nowF = 0;
    for (auto e : s) {
        if (firstTurn && e == 'F')
            --x;
        else if (e == 'T') {
            firstTurn = false;
            if (nowF != 0 && forx)
                xs.push_back(nowF);
            else if (nowF != 0 && !forx)
                ys.push_back(nowF);
            forx = !forx;
            nowF = 0;
        } else
            ++nowF;
    }
    if (nowF != 0 && forx)
        xs.push_back(nowF);
    else if (nowF != 0 && !forx)
        ys.push_back(nowF);

    sort(all(xs));
    sort(all(ys));

    for (auto e : xs) {
        if (x >= 0)
            x -= e;
        else
            x += e;
    }

    for (auto e : ys) {
        if (y >= 0)
            y -= e;
        else
            y += e;
    }

    if (x == 0 && y == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 256