akhauriyash/Code-Regression huggingface dataset:
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <list>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <iterator> 
#include <limits>

#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define ALL(a) (a).begin(),(a).end()
#define RALL(A) (a).rbegin(),(a).rend()
#define PB push_back
#define MP make_pair

#define dump(x) cerr << #x << " = " << (x) << endl;

using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

int N, M;
const int MAX_N = 100 + 10;
int d[MAX_N][MAX_N];
struct edge {
    int u, v, cost;
};
vector<edge> edges;

void solve() {
    REP(i, MAX_N) {
        REP(j, MAX_N) {
            d[i][j] = INF;
        }
        d[i][i] = 0;
    }
    for (auto e : edges) {
        d[e.u][e.v] = e.cost;
        d[e.v][e.u] = e.cost;
    }
    for (int k = 1; k <= N; k++) {
        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= N; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    /*
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            cout << d[i][j] << " ";
        }
        cout << endl;
    }
    */

    int ans = 0;
    for (auto e : edges) {
        bool flg = false;
        for (int u = 1; u <= N; u++) {
            for (int v = 1; v <= N; v++) {
                if (d[u][v] == d[u][e.u] + e.cost + d[e.v][v]) {
                    flg = true;
                    break;
                }
            }
        }
        if (!flg) {
            ans += 1;
        }
    }
    cout << ans << endl;
}

int main(int argc, char const* argv[])
{
    cin >> N >> M;
    REP(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        edges.PB({a, b, c});
    }
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  string S;
  cin >> S;
  int N = (int)(S.size());
  ll DP[N+1][3];
  ll three[100300];
  three[0] = 1;
  for (int i = 1; i < 100300; i++) {
    three[i] = three[i-1] * 3;
    three[i] %= Mod;
  }
  DP[0][0] = 0;
  DP[0][1] = 0;
  DP[0][2] = 0;
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'A') {
      DP[i+1][0] = DP[i][0];
      DP[i+1][1] = DP[i][1];
      DP[i+1][2] = DP[i][2];
      DP[i+1][0] += three[cnt];
      DP[i+1][0] %= Mod;
    } else if (S[i] == 'B') {
      DP[i+1][0] = DP[i][0];
      DP[i+1][1] = DP[i][1];
      DP[i+1][2] = DP[i][2];
      DP[i+1][1] += DP[i+1][0];
      DP[i+1][1] %= Mod;
    } else if (S[i] == 'C') {
      DP[i+1][0] = DP[i][0];
      DP[i+1][1] = DP[i][1];
      DP[i+1][2] = DP[i][2];
      DP[i+1][2] += DP[i+1][1];
      DP[i+1][2] %= Mod;
    } else {
      DP[i+1][0] = DP[i][0] * 3;
      DP[i+1][1] = DP[i][1] * 3;
      DP[i+1][2] = DP[i][2] * 3;
      DP[i+1][0] += three[cnt];
      DP[i+1][1] += DP[i][0];
      DP[i+1][2] += DP[i][1];
      DP[i+1][0] %= Mod;
      DP[i+1][1] %= Mod;
      DP[i+1][2] %= Mod;
      cnt++;
    }
  }
  cout << DP[N][2] << endl;
  return 0;
}

Measured memory_bytes: 6888
#include <stdio.h>
#include <math.h>

int cube(int x){
    int y = 0;
    y = pow(x, 3);
    return y;
}

int main(void){
    int num = 0;
    scanf("%d", &num);
    printf("%d\n", cube(num));

    return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef long long ull;
typedef long double ld;
#define inp_arr(name,size) for(int i = 0;i<size;i++)\
cin >> name[i];
#define QUICK cin.tie(0);
#define MOD 1e9+7

int main(){
    QUICK

    int a;
    cin >> a;
    int b = a/500;
    int c = a%500;
    int d = c/5;
    cout << (ull)b*1000+(ull)d*5;

    return 0;
}





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

using namespace std;

using ll = long long;

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

    if (2 * x <= y && y <= 4 * x && y % 2 == 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <atcoder/all>

// g++-10 c.cpp -std=c++17 -I .

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	ll n,i,ans=INFLL;
	std::vector<ll> r(2),m(2);
	std::pair<ll, ll> v;
	r[0] = 0ll; r[1] = 1ll;
	std::cin >> n;
	n *= 2;
	for(i=1; i*i<=n; ++i){
		if(n%i){
			continue;
		}
		m[0] = i; m[1] = n/i;
		v = atcoder::crt(r,m);
		if(v.first || v.second){
			--v.first;
			if(v.first<1){
				v.first += v.second;
			}
			ans = std::min(ans,v.first);
		}
		std::swap(m[0],m[1]);
		v = atcoder::crt(r,m);
		if(v.first || v.second){
			--v.first;
			if(v.first<1){
				v.first += v.second;
			}
			ans = std::min(ans,v.first);
		}
	}
	std::cout << ans << std::endl;
	return 0;
}


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

#define TRACE
#ifdef TRACE
#define TR(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define TR(...)
#endif

typedef long long                LL;
typedef vector < int >           VI;
typedef pair < int,int >         II;
typedef vector < II >            VII;

#define MOD                      1000000007
#define EPS                      1e-12
#define N                        200100
#define PB                       push_back
#define MP                       make_pair
#define F                        first 
#define S                        second
#define ALL(v)                   v.begin(),v.end()
#define SZ(a)                    (int)a.size()
#define FILL(a,b)                memset(a,b,sizeof(a))
#define SI(n)                    scanf("%d",&n)
#define SLL(n)                   scanf("%lld",&n)
#define PLLN(n)                  printf("%lld\n",n)
#define PIN(n)                   printf("%d\n",n)
#define REP(i,j,n)               for(LL i=j;i<n;i++)
#define PER(i,j,n)               for(LL i=n-1;i>=j;i--)
#define endl                     '\n'
#define fast_io                  ios_base::sync_with_stdio(false);cin.tie(NULL)

#define FILEIO(name) \
  freopen(name".in", "r", stdin); \
  freopen(name".out", "w", stdout);
 
inline int mult(int a , int b) { LL x = a; x *= LL(b); if(x >= MOD) x %= MOD; return x; }
inline int add(int a , int b) { return a + b >= MOD ? a + b - MOD : a + b; }
inline int sub(int a , int b) { return a - b < 0 ? MOD - b + a : a - b; }
LL powmod(LL a,LL b) { if(b==0)return 1; LL x=powmod(a,b/2); LL y=(x*x)%MOD; if(b%2) return (a*y)%MOD; return y%MOD; }

int cnt(LL n) {
  int ret = 0;
  while(n > 0) {
    ret ++;
    n /= 10;
  }
  return ret;
}
 
int main() {
  LL n; cin >> n;
  int ans = cnt(n);
  for(LL i = 1; i*i <= n; i ++) {
    if(n % i) continue;
    int k = max(cnt(i), cnt(n/i));
    ans = min(ans, k);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define SORT(v) sort((v).begin(), (v).end())
#define REV(v) sort((v).begin(), (v).end(), greater<int>())
typedef long long ll;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};

int main() {
  int n, l;
  cin >> n >> l;
  int a = 20000000;
  long long su = 0;
  for(int i = 0; i < n; i++) {
    su += i + l;
    if(a > abs(i + l)) a = abs(i + l);
  }
  // if(l > 0) cout << su - l << endl;
  // else {
  //   if(abs(l) <= n) cout << 0 << endl;
  //   else cout << su + (l - n + 1) << endl;
  // }
  if(l >= 0) cout << su - l << endl;
  else {
    if(n <= abs(l)) cout << su + (abs(l) - n + 1) << endl;
    else cout << su << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import math

n = int(input())
town = [list(map(int, input().split())) for _ in range(n)]

dist = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        dist += math.sqrt((town[i][0] - town[j][0]) **2 + (town[i][1] - town[j][1]) **2)
ans = dist / n
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
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;
typedef unsigned long long ull;


int main(){
  char c;
  cin >> c;

  if(c=='A') cout << "T" << endl;
  if(c=='T') cout << "A" << endl;
  if(c=='C') cout << "G" << endl;
  if(c=='G') cout << "C" << endl;
  
  return 0;
}



Measured memory_bytes: 256
n = int(input())
s = [input() for i in range(n)]
# print(n)
# print(s)
s = list(map(list, s))
# print(s)
for i in range(n):
    s[i].sort()
    s[i] = "".join(s[i])
# print(s)
dic = {}
for i in range(n):
    if s[i] in dic:
        dic[s[i]] += 1
    else:
        dic.setdefault(s[i],1)
a = list(dic.values())
# print(a)
import math
count = 0
for i in range(len(a)):
    if a[i] >= 2:
        count += math.factorial(a[i])//(math.factorial(a[i]-2)*2)
print(count)

Measured memory_bytes: 123864
#include <bits/stdc++.h>
 
struct time {
    int cost;
    int time;
    int a;
};
 
int main () {
    int n, t;
    int count = 0;
    std::cin >> n >> t;
    struct time a[n];
    for (int i = 0; i < n; ++i) {
        std::cin >> a[i].cost >> a[i].time ;
        if (a[i].time > t) {
            a[i].a = 1;
        }
        else {
            a[i].a = 0;
            ++count;
        }
    }
    
  if ( count == 0 ) {
    std::cout << "TLE" << std::endl;
  }
  else {
    int b[count];
    int j = 0;
    for (int i = 0; i < n ; ++i) {
        if (a[i].a == 0) {
            b[j] = a[i].cost;
            ++j;
        }
        else {
        }
    }
    std::sort(b, b + count);
    std::cout << b[0] << std::endl;
  }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (i % 2 == 0) {
                if (c == 'L') {
                    System.out.println("No");
                    return;
                }
            } else {
                if (c == 'R') {
                    System.out.println("No");
                    return;
                }
            }
        }
        
        System.out.println("Yes");
    }
}


Measured memory_bytes: 23124
#include<stdio.h>
void CountingSort(int A[],int k);
int A[2000001],B[2000001],n,C[10001];

int main(){
  int i,j;
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    scanf("%d",&A[i]);
  CountingSort(A,10000);
  for(i=1;i<=n;i++){
    printf("%d",B[i]);
    if(i<n) printf(" ");
  }
  printf("\n");
  return 0;
}

void CountingSort(int A[],int k){
  int i,j;
  for(i=0;i<k;i++)
    C[i]=0;
  for(j=1;j<=n;j++)
    C[A[j]]++;
  for(i=1;i<=k;i++)
    C[i]=C[i]+C[i-1];
  for(j=n;j>0;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }
}

Measured memory_bytes: 16268
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int n, k;
    cin >> n >> k;
    double ans = 0;

    for(int i = 1; i <= n; i++) {
        double p = 1;
        int x = i;
        while(x < k) {
            p *= 0.5;
            x *= 2;
        }
        ans += p/n;
    }
    printf("%.10f\n", ans);

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
AC = [0] * N #N問題に対してACフラグ立てるリスト
WA = [0] * N #N問題に対してWC回数リスト

for i in range(M):
  p, s = map(str, input().split())
  p = int(p)
  if AC[p-1] == 1: #前の問題がACの場合：描き判定を飛ばす
    continue
  if s == 'AC':#今回の結果はACの場合
    AC[p-1] = 1#ACリストにフラグ立てる
  if s == 'WA':#今回の結果はWAの場合
    WA[p-1] += 1#WCリストに該当問題のWA回数をCNT
#ペナルティの回数はACが出た時に限りカウントするため、AC＝０の問題はカウントしない
#ペナルティの回数=ACした問題で初めてACまでのWAの回数=ACフラグ立っている問題＊WA回数
result = [x * y for (x, y) in zip(AC, WA)]
AC_sum = sum(AC)
WA_sum = sum(result)

print(AC_sum, WA_sum)


Measured memory_bytes: 5552
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#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())
#define PB push_back
#define MP make_pair
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; }



int main() {
    ll a;
    cin >> a;
    ll ans = a*(a-1)/2;

    cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#define ll long long
#define add push_back
 
using namespace std; 


int main() {

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

    int t;  t = 1; //cin >> t;
    while(t--){
        char arr[26];
        arr[0] = 'z';
        for(int i = 1; i < 26; i++)
            arr[i] = 'a' + i - 1;
        ll n; cin >> n;
        string str = "";
        while(n > 0){
            str = arr[n % 26] + str;
            if(n % 26 == 0) n-= 26;
            n /= 26;
        }     
        cout << str << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
const int mod = 1e9 + 7;

using namespace std;

set<long long> factorization;
map<long long, int> app;

void factoTrial(long long n) 
{
    while (n % 2 == 0) 
    {
        factorization.insert(2);
        app[2]++;
        n /= 2;
    }
    for (long long d = 3; d * d <= n; d += 2) 
    {
        while (n % d == 0) 
        {
            factorization.insert(d);
            app[d]++;
            n /= d;
        }
    }
    if (n > 1)
    {
        factorization.insert(n);
        app[n]++;
    }

}

int main()
{
	#ifdef ME
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	long long n, ans = 0; cin >> n;
	factoTrial(n);
	for (auto &x : factorization)
	{
		//watch(x);
		for(int j = 1; j <= app[x]; j++)
		{
			//watch(app[x]);
			app[x] -= j;
			ans++;
		}
	}

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

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	int i;
	char ch[10005];
	scanf("%[^\n]",ch);
	int len=strlen(ch);
	int mid=(len-1)/2;
	int find=0;
	for(i=0;i<mid;i++)
	{
		if(ch[i]!=ch[mid-1-i])
		{
			find=1;
			break;
		}
	}
	if(find==1)
	printf("No");
	else
	{
		int max=(len+3)/2;
		for(i=max-1;i<len;i++)
		{
			if(ch[i]!=ch[len-i-1])
			{
				find=1;
				break;
			}
		}
		if(find==1)
		printf("No");
		else
		printf("Yes"); 
	}
}


Measured memory_bytes: 256
'''
https://atcoder.jp/contests/abc145/tasks/abc145_c
'''
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    N = int(input())
    grid = [list(map(int, input().split())) for _ in range(N)]
    res = 0
    for path in permutations(grid, N):
        for i in range(N-1):
            res += ((path[i][0]-path[i+1][0])**2 + (path[i][1]-path[i+1][1])**2)**0.5
    a = 1
    for i in range(2, N+1):
        a *= i
    print(res/a)


if __name__ == '__main__':
    main()

Measured memory_bytes: 40048
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

using namespace std;

typedef long long ll;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>pb_ds;

#define IN freopen("in.txt","r",stdin)
#define OUT freopen("out.txt","w",stdout)
#define pi pair<int,int>
#define F first
#define S second
#define pb push_back
#define pp pop_back
#define eps 10E-10
#define mod 998244353
#define pai acos(-1)
#define N 1000000

ll ar[N],cnt[N],exact[N];

ll bigmod(ll a,ll p)
{
   ll res,x;
   res=1%mod,x=a%mod;
   while(p){
      if(p&1) res=((res%mod)*(x%mod))%mod;
      x=((x%mod)*(x%mod))%mod;
      p>>=1;
   }
   return res;
}

ll mod_Inverse(ll n){
   return bigmod(n,mod-2);
}

int main ()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
      int ar;cin>>ar;
      cnt[ar]++;
    }
    for(int i=1;i<=N;i++){
      for(ll j=i;j<=N;j+=i) ar[i]+=(j*cnt[j]);
      ar[i]=(ar[i]%mod);
    }
    ll ans=0;
    for(ll i=N;i>=1;i--){
      exact[i]=(ar[i]*ar[i])%mod;
      for(int j=i+i;j<=N;j+=i){
         exact[i]=(exact[i]-exact[j])%mod;
      }
      ans=(ans+exact[i]*mod_Inverse(i))%mod;
      ans=(ans-i*cnt[i])%mod;
    }
    ans=(ans*mod_Inverse(2ll))%mod;
    ans=(ans+mod)%mod;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 27008
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define debug(x) cerr << #x << " = " << x << endl

int main(int qtd, char* nome[])
{
	ios::sync_with_stdio(false);
	cin.tie(0);
 
	string s;
	cin >> s;
	if(s[2] == s[3] && s[4] == s[5])
		cout << "Yes\n";
	else
		cout << "No\n";
	
	return 0;
}

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

int main() {
    int H, W;
    while (true) {
        scanf("%d %d", &H, &W);
        if (H == 0 && W == 0) break;

        for (int h = 0; h < H; h++) {
            for (int w = 0; w < W; w++) {
                if (h % 2 == 0 && w % 2 == 0) {
                    printf("#");
                } else if (h % 2 == 1 && w % 2 == 1) {
                    printf("#");
                } else {
                    printf(".");
                }
            }
            printf("\n");
        }

        printf("\n");
    }
}

Measured memory_bytes: 1160
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <cassert>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;

constexpr int kMOD = 1000000007;

int main() {
    int N;
    cin >> N;
    map<int, uint64_t> oddFreq;
    map<int, uint64_t> evenFreq;
    rep(i, N) {
        int tmp;
        cin >> tmp;
        if(i%2) {
            evenFreq[tmp]++;
        } else {
            oddFreq[tmp]++;
        }
    }

    // sort by freq
    vector<pair<uint64_t, int>> vodd; 
    vector<pair<uint64_t, int>> veven; 
    for(auto itr: oddFreq) {
        vodd.push_back({itr.second, itr.first});
    }
    for(auto itr: evenFreq) {
        veven.push_back({itr.second, itr.first});
    }
    sort(vodd.rbegin(), vodd.rend());
    sort(veven.rbegin(), veven.rend());

#if 0
    for(auto itr: veven) {
        cout << "(" << itr.first << "," << itr.second << ")" << endl; 
    }
#endif


    uint64_t Nodd  = N / 2;
    uint64_t Neven = N / 2;

    if(vodd[0].second != veven[0].second) {
        Nodd  -= vodd[0].first;
        Neven -= veven[0].first;
    } else {
        // all same
        if(vodd.size() == 1 && veven.size() == 1) {
            Nodd = 0;
        }
        else if (vodd.size() == 1) {
            Nodd  -= vodd[0].first;
            Neven -= veven[1].first;
        } else if (veven.size() == 1) {
            Nodd  -= vodd[1].first;
            Neven -= veven[0].first;
        } else if (vodd[1] > veven[1]) {
            Nodd  -= vodd[1].first;
            Neven -= veven[0].first;
        } else {
            Nodd  -= vodd[0].first;
            Neven -= veven[1].first;
        }
    }
    cout << Nodd + Neven << endl;
    return 0;
}



Measured memory_bytes: 11384
#include<iostream>

using namespace std;
using LL = long long;

struct node{
    LL ci, si, fi;
}a[500 + 5];

int main(){
    int n;
    cin >> n;
    for(int i = 1; i < n; i++)
        cin >> a[i].ci >> a[i].si >> a[i].fi;


    for(int i = 1; i < n; i++){
        LL sum = a[i].ci + a[i].si;

        for(int j = i + 1; j < n; j++){
            if(sum == a[j].si) sum += 0;
            else if(sum < a[j].si) sum += a[j].si - sum;
            else if(sum % a[j].fi != 0) sum += (a[j].fi - (sum%a[j].fi));
            sum += a[j].ci;
        }
        cout << sum << endl;
    }
    cout << 0 << endl;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }
    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out){
            int n = in.nextInt();
            int k = in.nextInt();
            int R = in.nextInt();
            int S = in.nextInt();
            int P = in.nextInt();
            String t = in.next();
            char[] arr = new char[n];
            long ans = 0;
            Map<Character , Character> map = new HashMap<>(3);
            Map<Character , Integer> val = new HashMap<>(3);

            map.put('r' , 'p');
            val.put('r' , R);
            map.put('p' , 's');
            val.put('p' , P);
            map.put('s' , 'r');
            val.put('s' , S);
            for (int i = 0; i <n; i++) {
                if (i < k){
                   if (i+k<n)arr[i+k]=map.get(t.charAt(i));
                    ans+=val.get(map.get(t.charAt(i)));
                }
                else {
                    if (arr[i] != map.get(t.charAt(i))){
                        if (i+k<n) arr[i+k]=map.get(t.charAt(i));
                        ans+=val.get(map.get(t.charAt(i)));
                    }
                    else if (i+k < n)arr[i+k]='d';
                }
            }
            System.out.println(ans);











        }




    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt(){return  Integer.parseInt(next());}
        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}

Measured memory_bytes: 25172
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stdlib.h>
#include <map>
#include <cmath>
#define MOD_P 1000000007
#define ll long long
using namespace std;



int main()
{
	int n, q;
	cin >> n >> q;
	vector<int> p(n + 1, 0);
	vector<bool> use(n + 1, true);
	vector<vector<int>> edge(n + 1);
	queue<int> bfs;

	for (int i = 1; i < n; i++) {
		int a, b;
		cin >> a >> b;
		edge[a].emplace_back(b);
		edge[b].emplace_back(a);
	}

	for (int i = 0; i < q; i++) {
		int a, x;
		cin >> a >> x;
		p[a] += x;
	}

	/*for (int i = 1; i <= n; i++) {
		printf("%d->", i);
		for (int j = 0; j < edge[i].size(); j++) {
			printf("%d ", edge[i][j]);
		}
		printf("\n");
	}*/

	bfs.push(1);
	use[1] = false;
	int size;
	while (!bfs.empty()) {
		int t = bfs.front();
		use[t] = false;
		bfs.pop();
		size = edge[t].size();
		for (int i = 0; i < size; i++) {
			if (use[edge[t][i]] == false)continue;
			bfs.push(edge[t][i]);
			p[edge[t][i]] += p[t];
		}
	}

	for (int i = 1; i <= n; i++) {
		printf("%d ", p[i]);
	}
	
	return 0;
}

Measured memory_bytes: 15604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
constexpr int MOD = 1e9+7;
int n;
ll ac, a, ans;
int main(){
	scanf("%d", &n);
	rep(i,n){
		scanf("%lld", &a);
		(ac += a) %= MOD;
		(ans -= a * a) %= MOD;
	}
	(ans += ac * ac) %= MOD;
	if(ans < 0) ans += MOD;
	if(ans % 2) ans += MOD;
	printf("%lld\n", ans / 2);
}

Measured memory_bytes: 3824
#include<iostream>
#include<deque>
#include<vector>
using namespace std;

int main()
{
    int N;
    int x;
    cin>>N>>x;
    long *a = new long[N];
    for(int i=0;i<N;i++)
    {
        cin>>a[i];
    }
    long count = 0;
    for(int i=0;i<N-1;i++)
    {
        while(a[i]+a[i+1]>x)
        {   long candies=(a[i]+a[i+1])-x;
            if(a[i+1]>=candies)
            {
                count = count+candies;
                a[i+1]-=candies;
            }
            else
            {
                count = count+candies;
                candies-=a[i+1];
                a[i+1]-=a[i+1];
                a[i]-=candies;
            }
        }
    }
    cout<<count;
    return 0;

}


Measured memory_bytes: 1024
local mce, mfl, msq, mmi, mma = math.ceil, math.floor, math.sqrt, math.min, math.max
local s = io.read()
local a, b = s:match("(%d%d)(%d%d)")
a, b = tonumber(a), tonumber(b)
local my, ym = false, false
if(1 <= a and a <= 12) then
  my = true
end
if(1 <= b and b <= 12) then
  ym = true
end
if my and ym then print("AMBIGUOUS")
elseif my then print("MMYY")
elseif ym then print("YYMM")
else print("NA")
end


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
using namespace atcoder;

int main(){
    int n,q;
    std::cin >> n >> q;
    fenwick_tree<ll> fw(n);
    REP(i,n){
        int input;
        std::cin >> input;
        fw.add(i,input);
    }
    REP(i,q){
        int f,p,x;
        std::cin >> f >> p >> x;
        if(f==0){
            fw.add(p,x);
        }
        else{
            std::cout << fw.sum(p,x) << std::endl;
        }
    }
}

Measured memory_bytes: 8216
#include <cstdio>
using ll = long long;
constexpr int MOD = 1e9 + 7;
inline ll quick_pow(ll a, int n)
{
	ll res = 1;
	while (n)
	{
		if (n & 1)
			res = res * a % MOD;
		a = a * a % MOD;
		n >>= 1;
	}
	return res;
}
ll sum[100005], ans;
int arr[100005];
int main()
{
	// freopen("AGC028-B.in", "r", stdin);
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", arr + i);
	for (int i = 1; i <= n; i++)
		sum[i] = (sum[i - 1] + quick_pow(i, MOD - 2)) % MOD;
	for (int i = 0; i < n; i++)
		(ans += arr[i] * (sum[i + 1] + sum[n - i] - 1)) %= MOD;
	for (int i = 1; i <= n; i++)
		ans = ans * i % MOD;
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int mod=998244353,maxn=3e5+10;
int ksm(int x,int y){
	int res=1;
	while(y){
		if(y&1) res=(ll)res*x%mod;
		y>>=1;
		x=(ll)x*x%mod;
	}
	return res;
}
int fac[maxn],ifac[maxn];
int C(int n,int m){
	return (ll)fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
int main(){
	int n=read(),A=read(),B=read();
	int ans=0;
	ll Caon=readll();
	fac[0]=1;
	REP(i,1,n) fac[i]=(ll)i*fac[i-1]%mod;
	ifac[n]=ksm(fac[n],mod-2);
	DREP(i,n-1,0) ifac[i]=(ll)(i+1)*ifac[i+1]%mod;
	REP(i,0,n){
		ll res=Caon-(ll)i*A;
		if(res%B || res<0) continue;
		ll j=res/B;
		if(j>n) continue;
		ans=((ll)C(n,i)*C(n,j)+ans)%mod;
	}
	printf("%d\n",ans);
	return 0;
}


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

string S;
int main()
{
    cin >> S;
    if( S[0] != 'A') {
        cout << "WA" << endl; return 0;
    }
    int Cnum = 0;
    if( 'A' <= S[1] && S[1] <= 'Z') {
        cout << "WA" << endl; return 0;
    }
    if( 'A' <= S[S.length()-1] && S[S.length()-1] <= 'Z') {
        cout << "WA" << endl; return 0;
    }
    int Lnum = 1;
    for( int i = 2; i < S.length()-1;i++) {
        if( S[i]== 'C') Cnum++;
        if( 'A' <= S[i] && S[i] <= 'Z') Lnum++;
    }
    if( Cnum != 1 || Lnum != 2 ) {
        cout << "WA" << endl; return 0;
    }
    cout << "AC" << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<functional>
#include <random>
#include<iostream>
#include<iomanip>
using namespace std;

int main() {
	int L;
	double a;
	cin >> L;
	a = (double)L / 3;
	printf("%10f\n", a*a*a);

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int n;cin>>n;
    int result=0;
    if(n>=105){result++;}
    if(n>=135){result++;}
    if(n>=165){result++;}
    if(n>=189){result++;}
    if(n>=195){result++;}
    cout<<result<<endl;

    return 0;
}


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

using namespace std;

int field[50][50];

void Count(int h,int w)
{
    int dx[8] = {-1,0,1,-1,1,-1,0,1};
    int dy[8] = {-1,-1,-1,0,0,1,1,1};

    for(int row = 0;row < h;row++) {
        for(int col = 0;col < w;col++) {
            int sum = 0;
            if(field[row][col] == -1)
                continue;
            for(int i = 0;i < 8;i++) {
                if(row+dy[i] < 0 || row+dy[i] >= h || col+dx[i] < 0 || col+dx[i] >= w)
                    continue;
                else if(field[row+dy[i]][col+dx[i]] == -1) {
                    sum++;
                }
            }
            field[row][col] = sum;
        }
    }

    return;
}

int main(void)
{
    string s;
    int w,h;
    cin>>h>>w;

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

    Count(h,w);

    for(int i = 0;i < h;i++) {
        for(int j = 0;j < w;j++) {
            if(field[i][j] >= 0)
                cout<<field[i][j];
            else
                cout<<"#";
        }
        cout<<endl;
    }
            

    return 0;
}


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

ac = wa = tle = re = 0

for si in s:
  if si == 'AC':
    ac += 1
  elif si == 'WA':
    wa += 1
  elif si == 'TLE':
    tle += 1
  elif si == 'RE':
    re += 1
    
print(f'AC x {ac}')
print(f'WA x {wa}')
print(f'TLE x {tle}')
print(f'RE x {re}')


Measured memory_bytes: 16336
#include <bits/stdc++.h>
using namespace std;
#define ll  long long int
#define mod 1000000007
#define modd 998244353
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int main()
{
    fast; 
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll f  = 0;
    while(k--)
    {
        if(c <= b)
        {
            c= c*2;
        }
        else if(b <= a)
        {
            b = 2*b;
        }
        if(a< b && b < c)
        {
            f=1;
            break;
        }
    }
    // cout<<a<<" "<<b<<" " <<c;
    if(f)
    cout<<"Yes"<<"\n";
    else 
    cout<<"No"<<"\n";
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll f(vector<ll> a, ll r) {
  vector<int> c(r + 1);
  int n = a.size();
  for (int i = 0; i <= r; i++)
    c[i] = n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j * a[i] <= r; j++) {
      c[j * a[i]] = min(c[j * a[i]], i);
    }
  }
  ll ret = 0;
  for (int i = 0; i <= r; i++) {
    if (c[i] == n) {
      if (n % 2 == 0)
        ret++;
    } else {
      if (c[i] % 2 == 0)
        ret++;
    }
  }
  return ret;
}

int main() {
  while (true) {
    ll n, l, r;
    cin >> n >> l >> r;
    if (n == 0)
      break;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
      cin >> a[i];
    cout << f(a, r) - f(a, l - 1) << endl;
  }
  return 0;
}


Measured memory_bytes: 3148
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt(); // ninzu
        int M = sc.nextInt(); // firend
        int K = sc.nextInt(); // block

        int[] kouho = new int[N];
        UnionFindTree uft = new UnionFindTree(N);

        for (int i = 0; i < M; i++) {
            int A = sc.nextInt() - 1;
            int B = sc.nextInt() - 1;
            kouho[A]--;
            kouho[B]--;
            uft.union(A, B);
        }

        for (int i = 0; i < K; i++) {
            int C = sc.nextInt() - 1;
            int D = sc.nextInt() - 1;
            if (uft.same(C, D)) {
                kouho[C]--;
                kouho[D]--;
            }
        }

        for (int i = 0; i < N; i++) {
            if (i != 0) {
                System.out.print(" ");
            }

            System.out.print(kouho[i] + uft.getSize(i) - 1);
        }
    }
}

//copied by :https://gist.github.com/keitin/e5ba4ba4ccd6cd3afb3485c5ea85846c#file-union-find-java
class UnionFindTree {

    int[] parent; //インデックスにとノードを対応させ、そのルートノードのインデックスを格納 
    int[] rank; //parentと同様に、木の高さを格納
    int[] size; // 集合のサイズ

    public UnionFindTree(int size) {
        this.parent = new int[size];
        this.rank = new int[size];
        this.size = new int[size];

        for (int i = 0; i < size; i++) {
            makeSet(i);
        }
    }

    public void makeSet(int i) {
        parent[i] = i;
        rank[i] = 0; //集合の高さ
        size[i] = 1;
    }

    public void union(int x, int y) {
        int xRoot = find(x);
        int yRoot = find(y);
        
        // サイズの更新
        if(xRoot != yRoot) {
            int xSize = size[xRoot];
            int ySize = size[yRoot];
            size[xRoot] = ySize + xSize;
            size[yRoot] = ySize + xSize;
        }

        //xが属する木の方が大きい場合
        if (rank[xRoot] > rank[yRoot]) {
            parent[yRoot] = xRoot; //yの親をxに更新 

        } else if (rank[xRoot] < rank[yRoot]) {
            parent[xRoot] = yRoot;

        } else if (xRoot != yRoot) {
            parent[yRoot] = xRoot;
            rank[xRoot]++; //同じ高さの木がルートの子として着くから大きさ++;
        }

    }
    
    public int getSize(int i) {
        return size[find(i)];
    }

    //引数の属する木のルートのidを返す
    public int find(int i) {
        if (i != parent[i]) {
            parent[i] = find(parent[i]);
        }
        return parent[i];
    }

    //同じ木に属しているか
    public boolean same(int x, int y) {
        return find(x) == find(y);
    }
}

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

int sum_place(int n){
  string s=to_string(n);
  int sum=0;
  for(int i=0;i<s.size();i++){
    sum+=s.at(i)-'0';
  }
  return sum;
}

int main(){
  int N;
  cin >> N;
  int A,B;
  int ans=1e9;
  for(A=1;A<=N/2;A++){
    B=N-A;
    ans=min(ans, sum_place(A)+sum_place(B));
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
	
	int n;
	cin >> n;
	int mx = 0;
	int ans = 1;
	for(int i = 1; i <= n; i++){
		int tmp = i;
		int cnt = 0;
		while(tmp%2 == 0){
			tmp /= 2;
			cnt++;
		}
		if(mx < cnt){
			mx = cnt;
			ans = i;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;

 main()

{
    fast
    int n,q;
    cin>>n>>q;
    vector<int>a(n);
    f(i,0,n-1)cin>>a[i];
    vector<int>x(q);
    f(i,0,q-1)cin>>x[i];
    vector<int>s(n+1);
    f(i,0,n-1)s[i+1]=s[i]+a[i];
    vector<int>s2(n);
    f(i,0,n-1)
    {
        s2[i]=a[i];
        if(i>1)s2[i]+=s2[i-2];
    }
    f(i,0,q-1)
    {
        int lo=0,hi=n;
        int val=x[i];
        while(lo+1<hi)
        {
            int mid=(lo+hi)/2;
            int flag=1;
            if(a[n-mid]<val)
            {
                flag=0;
            }
            else
            {
                int gap=a[n-mid]-val;
                int bam=lower_bound(a.begin(),a.end(),val-gap)-a.begin();
                if(n-mid-bam+1<mid)flag=0;
            }
            if(flag==0)hi=mid;
            else lo=mid;
        }
        int ses=s[n]-s[n-lo];
        if(n-1-2*lo>=0)ses+=s2[n-1-2*lo];
        cout<<ses<<"\n";
    }
    return 0;

}





































Measured memory_bytes: 6336
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;


typedef long long int lli;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii; 


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vi ab(n+1);
    for (int i = 1; i <= n; i++)
    {
        cin>>ab[i];
    }
    for (int i = n; i >= 1; i--)
    {
        for(int j=i+i;j<=n;j+=i){ab[i] ^= ab[j];}
        // ac[i] %= 2;
    }
    vi ad;
    for (int i = 1; i <= n; i++)
    {
        if(ab[i]==1){
            ad.push_back(i);
        }
    }
    cout<<ad.size()<<endl;
    for (int i = 0; i < ad.size(); i++)
    {
        cout<<ad[i]<<" ";
    }
    return 0;
}

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

bool dp[101][10001];
int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	int n;
	cin >> n;
	vector<int> s;
	s.pb(0);

	ll W = 0;
	for(int i=0; i<n; i++){
		int t;
		cin >> t;
		W += t;
		s.pb(t);
	}

	dp[0][0] = true;
	for(int i=1; i<=n; i++){
		for(int j=W; j>=0; j--){
			if(j-s[i] >= 0){
				dp[i][j] = dp[i-1][j] || dp[i-1][j-s[i]];
			}else{
				dp[i][j] = dp[i-1][j];
			}
		}
		/*
		for(int j=0; j<=W; j++){
			printf("%d ", dp[i][j]);
		}
		puts("");
		*/
	}


	int ma = -1;
	for(int j=W; j>=0; j--){
		if(dp[n][j]){
			if(j % 10 == 0){
				ma = max(ma, 0);
			}else{
				ma = max(ma, j);
			}
		}
	}
	cout << ma << endl;
	
	return 0;
}


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

int main(){
  while(1){
    string s;
  cin >> s;
  if(s[0]=='#')break;
  string left = "qwertasdfgzxcvb";
  int ans = 0;
  for(int i=1;i<s.size();i++){
    bool flag[2]={false, false};
    for(int j=0;j<left.size();j++){
      if(s[i] == left[j])flag[0] = true;
      if(s[i-1] == left[j])flag[1] = true;
    }
    if(flag[0] ^ flag[1])ans++;
  }
  printf("%d\n", ans);
  }
  return 0;
}



Measured memory_bytes: 3088
from sys import stdin
N = int(stdin.readline().rstrip())
A = [0] * N
for i in range(N):
    A[i] = int(stdin.readline().rstrip())

if A[0] != 0:
    print(-1)
else:
    ans = 0
    for j in range(N-1):
        if A[j]+1 == A[j+1]:
            ans += 1
        else:
            ans += A[j+1]
        if A[j+1] - A[j] > 1:
            ans = -1
            break
    print(ans)

Measured memory_bytes: 10996
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int, int>
#define PLL pair<LL, LL>
#define f first
#define s second 
using namespace std;
const int MAXN = 250005;
const LL M1 = 1000000009;
const LL M2 = 1000000007;

LL qpow(LL a, LL pw, LL mod) {
	LL res = 1;
	while (pw) {
		if (pw & 1) res = res * a % mod;
		pw >>= 1;
		a = a * a % mod;
	}
	return res;
}

PLL norm(PLL p) {
	return PLL((p.f % M1 + M1) % M1, (p.s % M2 + M2) % M2);
}

PLL neg(PLL p) {
	return PLL(M1 - p.f, M2 - p.s);
}

PLL get_inv(PLL p) {
	return PLL(qpow(p.f, M1 - 2, M1), qpow(p.s, M2 - 2, M2));
}

PLL mul(PLL p, PLL q) {
	return PLL(p.f * q.f % M1, p.s * q.s % M2);
}

PLL add(PLL p, PLL q) {
	return PLL((p.f + q.f) % M1, (p.s + q.s) % M2);
}

int n;
string s;
PLL pw[2*MAXN], pinv[2*MAXN], pref[MAXN];
LL pos[MAXN];

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

	PLL base = PLL(1234567, 7654321), inv = get_inv(base);
	pw[0] = pinv[0] = {1, 1};
	for (int i = 1; i < 2 * MAXN; i++) {
		pw[i] = mul(pw[i - 1], base);
		pinv[i] = mul(pinv[i - 1], inv);
	}

	cin >> n >> s;
	pref[0] = PLL(0, 0);
	pos[0] = n;
	map<PLL, int> cnt;
	for (int i = 1; i <= n; i++) {
		char t = s[i - 1];
		pos[i] = pos[i - 1];
		pref[i] = pref[i - 1];
		if (t == '<') pos[i]--;
		if (t == '>') pos[i]++;
		if (t == '+') pref[i] = add(pref[i], pw[pos[i]]);
		if (t == '-') pref[i] = add(pref[i], neg(pw[pos[i]]));
		cnt[pref[i]]++;
	}
	
	LL ans = 0; 
	PLL tgt = pref[n], mulf = PLL(1, 1), addf = PLL(0, 0);
	for (int i = 1; i <= n; i++) {
		ans += cnt[add(mul(get_inv(mulf), tgt), neg(mul(get_inv(mulf), addf)))];
//		cout << "At " << i << ' ' << cnt[add(mul(tgt, mulf), addf)] << '\n';
		
		char t = s[i - 1];
		cnt[pref[i]]--;
		if (t == '<') {
			// a *= base, b *= base
			mulf = mul(mulf, pw[1]);
			addf = mul(addf, pw[1]);
		}
		if (t == '>') {
			// a /= base, b /= base
			mulf = mul(mulf, pinv[1]);
			addf = mul(addf, pinv[1]);
		}
		if (t == '+') {
			// b -= pw[n]
			addf = add(addf, neg(pw[n]));
		}
		if (t == '-') {
			// b += pw[n]
			addf = add(addf, pw[n]);
		}
	}
	
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 53268
r, c = map(int, input().split())
table = []

for _ in range(r):
  table.append(list(map(int, input().split())))

for i in range(r):
  for j in range(c):
    print(table[i][j], end = ' ')
  print(sum(table[i]))
for j in range(c):
  print(sum([table[i][j] for i in range(r)]), end = ' ')
print(sum([table[i][j] for i in range(r) for j in range(c)]))


Measured memory_bytes: 6252
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)

	ss := strings.Split(s,"")

	count := 0
	for i := 0; i < len(s)/2; i ++ {
		if ss[i] != ss[len(ss)-1 -i] {
			count ++
		}
	}
	fmt.Println(count)
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        int H =sc.nextInt();
        int N =sc.nextInt();
        
        int A =0;
        
        for(int i=0;i<N;i++){
            A +=sc.nextInt();
        }
        
        if(H<=A){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
        
    }
    
    
}


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

int main(){
    vector<int> n(3);
    for(int i=0; i<3; i++) cin >> n.at(i);
    sort(n.begin(), n.end());
    if(n.at(0) + n.at(1) == n.at(2)) puts("Yes");
    else puts("No");
}

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


int main() {
    int a,b,k;
    cin>>a>>b>>k;
    for(int i=min(a,b);i>=0;--i) {
      if(a%i==0 && b%i==0){
        --k;
        if(k==0) {
          cout << i << endl;
          return 0;
        }
      }
    }
}



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

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

using namespace std;

int main(){

	int n,k;
	cin>>n>>k;
	int arr[n];
	int i,j;
	for(i=0;i<n;i++) cin>>arr[i];
	int dp[n]={0};
	for(i=1;i<n;i++){
		int ma=INT_MAX;
		for(j=1;j<=k;j++){
			if(i-j>=0){
				ma=min(ma,dp[i-j]+abs(arr[i]-arr[i-j]));
			}
			else break;
		}
		dp[i]=ma;
	}
	cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1024
def main():

  S=input()
  if len(S)%2==1:
    print('No')
    return

  for i in range(len(S)):
    if i%2==0:
      if S[i]!='h':
        print('No')
        return
    else:
      if S[i]!='i':
        print('No')
        return
  print('Yes')
  return

main()

Measured memory_bytes: 2940