akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

int GCD(int a, int b) {
  return b ? GCD(b, a%b) : a;
}

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for(int i = 1; i<=n; i++) {
    for(int j = 1; j<=n; j++) {
      for(int k = 1; k<=n; k++) {
        int a = i;
        int b = j;
        int c = k;
        ans += GCD(a, GCD(b,c));
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>

#define REP(n) for(int i = 0;i < n;i++)
#define LLREP(n) for(long long int  i = 0;i < n;i++)
typedef long long int ll;
using namespace std;
#define MAX_A 100010

int num[MAX_A],dis[MAX_A];

int dfs(int x);


int main(){

    int n,m;
    cin >> n >> m;
    bool ans = true;
    int l,r,d;
    for(int i = 1;i <=n;i++){
        num[i] = i;
        dis[i] = 0;
    }

    for(int i = 1;i <= m;i++){

        cin >> l >> r >> d;
        if(!ans){
            continue;
        }
        int num_f=dfs(l),num_r=dfs(r);
        if(num_f == num_r){

            if(dis[l]-dis[r]!=d){
                ans = false;
            }

        }else{
            num[num_f]=num_r;
            dis[num_f]=dis[r]-dis[l]+d;
        }
    }

    if(ans){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }


    return 0;
}


int dfs(int x){
    
    if(num[x] == x){
        return x;
    }
    
    int tmp = dfs(num[x]);
    dis[x]+=dis[num[x]];
    num[x]=tmp;
        
    return tmp;
}
    

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;

long long modpow(long long x,long long n,long long mod)
{
  if(n==0)return 1;
  long long res=modpow(x*x%mod,n/2,mod);
  if(n&1)res=res*x%mod;
  return res;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  int mod= 998244353;
  cin>>n;
  vector<int>a(n);
  rep(i,n)cin>>a[i];
  int sa=0;
  rep(i,n)sa+=a[i];
  int l=sa/2;
  vector<int>dp(l+1,0);
  dp[0]=1;
  rep(i,n)
  {
    for(int j=l-a[i];j>=0;j--)
    {
      dp[j+a[i]]+=dp[j]*2%mod;
      if(dp[j+a[i]]>=mod)dp[j+a[i]]-=mod;
    }
  }
  ll res=modpow(3,n,mod);
  rep(i,l+1)dp[i]=(ll)dp[i]*3%mod;
  for(auto i:dp){res+=mod-i;if(res>=mod)res-=mod;}
  if(!(sa&1))
  {
    fill(all(dp),0);
    dp[0]=1;
    rep(i,n)
    {
      for(int j=l-a[i];j>=0;j--)
      {
        dp[j+a[i]]+=dp[j];
        if(dp[j+a[i]]>=mod)dp[j+a[i]]-=mod;
      }
    }
    res+=(ll)dp.back()*3;
  }
  cout<<res%mod<<endl;


  return 0;

}


Measured memory_bytes: 384
MOD = 10**9 + 7
m = 100
COMB_table = [[0]*(m+1) for _ in range(m+1)]


def make_COMB_table(m):
    for i in range(m+1):
        for j in range(i+1):
            if j == 0 or j == i:
                COMB_table[i][j] = 1
            else:
                COMB_table[i][j] = COMB_table[i-1][j-1] + COMB_table[i-1][j]


def COMB_2(n, k):
    return COMB_table[n][k]


make_COMB_table(m)


def main():
    from collections import Counter
    N, A, B = (int(i) for i in input().split())
    V = [int(i) for i in input().split()]
    V.sort(reverse=True)
    ans = sum(v for v in V[:A])/A
    c = Counter(V)
    c_ans = Counter(V[:A])
    cnt = 0
    if V[0] != V[A-1]:
        cnt = COMB_2(c[V[A-1]], c_ans[V[A-1]])
    else:
        for i in range(A, B+1):
            cnt += COMB_2(c[V[0]], i)
    print(ans)
    print(cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39536
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
#include <tuple>
using namespace std;
typedef long long ll;

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

    ll a[n];
    ll sortVec[n];
    for (ll i = 0; i< n; i++) {
        cin >> a[i];
        sortVec[i] = a[i];
    }

    sort(sortVec, sortVec + n);
    for (ll i = 0; i < n; i++) {
        if (a[i] == sortVec[n - 1]) cout << sortVec[n - 2] << endl;
        else cout << sortVec[n - 1] << endl;
    }
}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void){
    int a,b;cin>>a>>b;
    int ans=-1;
    for(double i=1.0;i<=1000;i+=1.0){
        if(int(floor(i*0.08))==a&&int(floor(i*0.1))==b){ans=int(i);break;}
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
h, w = map(int, input().split())
s = []
dx = [1, 1, 0, -1, -1, -1, 0, 1]
dy = [0, 1, 1, 1, 0, -1, -1, -1]
for i in range(h):
    s.append(list(input()))

for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            cnt = 0
            for k in range(8):
                x = i + dx[k]
                y = j + dy[k]
                if 0 <= x < h and 0 <= y < w and s[x][y] == "#":
                    cnt += 1
            s[i][j] = str(cnt)
for i in range(h):
    print("".join(s[i]))

Measured memory_bytes: 3188
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
	Scanner sc = new Scanner(System.in);
	public void run(){
		int x;
		int y;
		int s;
		while(true){
			x = sc.nextInt();
			y = sc.nextInt();
			s = sc.nextInt();
			if(x == 0 && y == 0 && s == 0){
				break;
			}
			calc(x, y, s);
		}
	}
	public void calc(int x, int y, int s){
		int max = 0;
		for(int p1 = 1; p1 <= s/2+1; p1++){
			for(int p2 = 1; p2 < s; p2++){
				int sx = (p1*(100+x))/100 + (p2*(100+x))/100;
				if(sx > s){
					break;
				}
				else if(sx == s){
					int sy = (p1*(100+y))/100 + (p2*(100+y))/100;
					if (sy > max) max = sy;
				}
			}
		}
		System.out.println(max);
	}
	
	public static void main(String[] args){
		new Main().run();
	}
	
}

Measured memory_bytes: 29204
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;
typedef unsigned int uint;
typedef long long ll;

#define fori(n) for(ll i=0; i<(n); i++)
#define forn(i, n) for(ll i=0; i<(n); i++)
#define forn3(i, x, n) for(ll i=(x); i<(n); i++)

int main() {
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    string s, t;
    cin>>s>>t;

//cout<<s<<endl;
//cout<<t<<endl;
    vector<vector<int>> dp(s.size()+1, vector<int>(t.size()+1));

    for(uint i=0; i<=s.size(); i++) {
        for(uint j=0; j<=t.size(); j++) {
            if(i==0 || j==0)
                dp[i][j]=0;
            else if(s[i-1]==t[j-1])
                dp[i][j]=dp[i-1][j-1]+1;
            else
                dp[i][j]=max(dp[i][j-1], dp[i-1][j]);
        }
    }
    int len=dp[s.size()][t.size()];
//cout<<"len="<<len<<endl;

    /* recover */
    string ans;
    int n=(int)s.size();
    int m=(int)t.size();
    //while(ans.size()<len) {
    while(n>0 && m>0) {
        if(s[n-1]==t[m-1]) {
//cout<<"n="<<n<<" m="<<m<<endl;
            ans=s[n-1]+ans;
            n--;
            m--;
        } else if(dp[n-1][m]>dp[n][m-1]) {
           n--;
        } else {
           m--;
        }
    }

    cout<<ans<<endl;

}



Measured memory_bytes: 35584
#pragma GCC optimize("O2,unroll-loops")
#include<bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using vi = vector<int>;
using ll = long long;
const int maxn = 1<<20;
int n, a[maxn], l[maxn], r[maxn];
void solve() {
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	a[0] = a[n+1] = -1;
	{
		vi s {0};
		for(int i = 1; i <= n; i++) {
			while(a[s.back()] > a[i]) s.pop_back();
			l[i] = s.back();
			s.push_back(i);
		}
	}
	{
		vi s {n+1};
		for(int i = n; i; i--) {
			while(a[s.back()] > a[i]) s.pop_back();
			r[i] = s.back();
			s.push_back(i);
		}
	}
	ll ans = 0;
	for(int i = 1; i <= n; i++)
		ans += (r[i]-i)*1l*(i-l[i])*1ll*a[i];
	cout << ans;
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	solve();
}


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

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

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

#define pb push_back
#define mp make_pair

using namespace std;

const bool DEBUG=true;

template<class T>
void debug(T head){
    cerr<<head<<endl;
}

template <class Head, class... Body>
void debug(Head head, Body... body){
    if(DEBUG){
        cerr<<head<<" ";
        debug(body...);
    }
}

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

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

    int N, K;
    cin>>N>>K;
    vector<long> a(N), b(N);
    cin>>a[0];
    if(a[0]>0){
        b[0] = a[0];
    }else{
        b[0] = 0;
    }
    for(int i=1; i<N; ++i){
        cin>>a[i];
        if(a[i]>0){
            b[i] = b[i-1] + a[i];
        }else{
            b[i] = b[i-1];
        }
    }

    long sum_K_length = 0;
    for(int i=0; i<K; ++i){
        sum_K_length += a[i];
    }
    long ans = max(b[N-1] - b[K-1] + sum_K_length, b[N-1] - b[K-1]);
    for(int i=K; i<N; ++i){
        sum_K_length = sum_K_length - a[i-K] + a[i];
        ans = max(ans, max(b[i-K] + sum_K_length + b[N-1] - b[i], b[i-K] + b[N-1] - b[i]));
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

int p[200005];
set<long long> s;
long long ans = 0;

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

	rep(i,n){
		long long a;
		cin >> a;
		p[ a - 1 ] = i;
	}

	s.emplace(-1);
	s.emplace(n);
	rep(i,n){
		auto pr = s.emplace(p[i]);
		auto it = pr.first;
		ans += (i + 1) * ((*next(it,1) - *it) * (*it - *prev(it,1)) );
	}
	cout << ans << endl;
}


Measured memory_bytes: 10368
N, K = map(int, input().split())
S = input()
L = [0]
X = ['1']
pos = 0
for i in range(N):
  if S[i] != X[pos]:
    L.append(1)
    X.append(S[i])
    pos += 1
  else:
    L[pos] += 1
while pos < 2 * K + 4:
  L.append(0)
  X.append('1')
  pos += 1
L.append(0)
X.append('1')
n = len(L)
for i in range(1, n):
  L[i] += L[i-1]
M = L[2*K]
for i in range(1, n-2*K):
  if X[i] == '1':
    M = max(L[2*K+i] - L[i-1], M)
print(M)

Measured memory_bytes: 18632
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
#include <map>
using namespace std;
const int maxn = 5e5+5;
int n = 0, q = 0;

struct Query{
	int id, l, r;
	bool operator< (Query a) const{
		return r < a.r;
	}
}query[maxn];



int v[maxn], sum[maxn], ans[maxn];

int lowbit(int x){
	return x & (-x);
}

void change(int i, int a){
	while(i <= n){
		sum[i] += a;
		i += lowbit(i);
	}
}

int getsum(int i){
	int sum_t = 0;
	while(i > 0){
		sum_t += sum[i];
		i -= lowbit(i);
	}
	return sum_t;
}

int main() {

	while(~scanf("%d", &n)){
            scanf("%d", &q);
		memset(v, 0, sizeof(v));
		memset(sum, 0, sizeof(sum));
		memset(ans, 0, sizeof(ans));

		int t = 0;
		for(int i = 1; i <= n; i++){
			scanf("%d", &v[i]);
		}
		for(int i = 1; i <= q; i++){
			scanf("%d%d", &query[i].l, &query[i].r);
			query[i].id = i;
		}
		sort(query + 1, query + q + 1);

		int pre = 1;
		map<int, int> mymap;
		for(int i = 1; i <= q; i++){
			for(int j = pre; j <= query[i].r; j++){
				//已存在
				if(mymap[v[j]]){
					change(mymap[v[j]], -1);
				}
				mymap[v[j]] = j;
				change(j, 1);
			}
			pre = query[i].r + 1;
			ans[query[i].id] = getsum(query[i].r) - getsum(query[i].l - 1);
		}

		for(int i = 1; i <= q; i++){
			cout << ans[i] << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 38876
def gcd(a, b):
    if(a < b):
        a, b = b, a
    if(b == 0):
        return a
    return gcd(b, a % b)

def lcm(a, b):
    return a // gcd(a, b) * b

if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    l = A[0]
    for a in A:
        l = lcm(l, a)
    ans = 0
    mod = int(1e9+7)
    for a in A:
        ans += (l * pow(a, mod-2, mod))%mod
        ans %= mod
    print(ans)


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

int num5(int x) {
  int ans = 0;
  while(1) {
    if(x % 5 == 0) {
      x /= 5;
      ans++;
    } else {
      return ans;
    }
  }
}
int num2(int x) {
  int ans = 0;
  while(1) {
    if(x % 2 == 0) {
      x /= 2;
      ans++;
    } else {
      return ans;
    }
  }
}

int main() {
  while(1) {
    int n;
    cin >> n;
    if(n == 0) break;

    int numof2 = 0, numof5 = 0;
    for(; n > 0; n--) {
      numof2 += num2(n);
      numof5 += num5(n);
    }
    cout << min(numof2, numof5) << endl;
  }
  return 0;
}

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

long long modPow(long long a, long long n, long long p)
{
    if (n == 1)
        return a % p;
    if (n % 2 == 1)
        // 奇数のとき
        return (a * modPow(a, n - 1, p)) % p;
    // 偶数のとき
    long long t = modPow(a, n / 2, p);
    return (t * t) % p;
}

long long modFactorial(long long n, long long a, long long p)
{
    long long ans = n;
    for (int i = 1; i < a; i++)
    {
        ans = ((ans % p) * ((n - i) % p)) % p;
    }
    return ans;
}

long long mod(long long val, long long m)
{
    long long res = val % m;
    if (res < 0)
        res += m;
    return res;
}

int main()
{
    long long n;
    long long a, b;
    cin >> n >> a >> b;

    long long ans, n2, na, nb;
    long long xa, xb, ya, yb;

    n2 = modPow(2, n, MOD);

    xa = modFactorial(n, a, MOD);
    ya = modFactorial(a, a, MOD);
    na = ((xa % MOD) * modPow(ya, MOD - 2, MOD)) % MOD;

    xb = modFactorial(n, b, MOD);
    yb = modFactorial(b, b, MOD);
    nb = ((xb % MOD) * modPow(yb, MOD - 2, MOD)) % MOD;

    ans = mod(n2 - na - nb - 1, MOD);

    cout << ans << endl;
}


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

int main() {
	long long X, K, D;
	cin >> X >> K >> D;
	if (X < 0) X *= -1ll;
	if (X / D >= K) {
		cout << X - K * D << endl;
		return 0;
	}
	K -= X / D;
	X = X % D;
	cout << (K % 2ll == 0ll ? X : D - X) << endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define en puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check();


// bool cmp(pair<int,int>p,pair<int,int>q) {
//     return p.first>q.first;//descending by first
//     return p.first<q.first;//ascending by first
//     return p.second>q.second;//descending by second
//     return p.second<q.second;//ascending by second
// }

bool cmp(int p,int q) {
    return p>q;//descending
    // return p<q;//ascending
}

int main() {

    int t;
    // cin>>t;
    t=1;
    while(t-->0) {
        clue();
    }
    return 0;
}
int clue() {

    lli a,b,c,k;
    cin>>a>>b>>c>>k;

    lli sum=min(a,k);
    lli x,y,z;
    if(k>a) {
        x=k-a;
        if(x>b) {
        y=x-b;
        sum-=min(c,y);
        }
    }
    

    cout<<sum<<endl;
    return 0;
}

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

int main(){
    int n, m, a[100][100], b[100];
    long long s[100];
    cin >> n >> m;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> a[i][j];
        }
    }
    
    for(int k = 0; k < m; k++){
        cin >> b[k];
    }
    
    for(int l = 0; l < n; l++){
        s[l] = 0;
        for(int t = 0; t < m; t++){
            s[l] += a[l][t] * b[t];
        }
    }
    for(int u = 0; u < n; u++){
        cout << s[u] << endl;
    }
    return 0;
}


Measured memory_bytes: 3116
#include "bits/stdc++.h"
using namespace std;


typedef long long ll;
typedef pair <int, int> ii;
typedef pair <int, ii> iii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;

#define iINF (1<<30)
#define INF (1LL<<59)
#define forn(i) for(int i = 0;i < n; ++i)
#define form(i,n) for(int i = 0 ;i < n; ++i)
#define NIL -1

const ll mod = 998244353;
int n;
int m;
int ans;
string str;

int main(){
    ll t;
    cin>>str;
    t=10000000*(str[0]-'0')+1000000*(str[1]-'0')+100000*(str[2]-'0')+10000*(str[3]-'0');
    t+=1000*(str[5]-'0')+100*(str[6]-'0');
	t+=10*(str[8]-'0')+(str[9]-'0');
    if(t<=20190430){
        cout<<"Heisei"<<endl;
    }else{
        cout<<"TBD"<<endl;
    }
    return 0;
}

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

using namespace std;

#define loop(i,a,b) for(int i=(a); i<(b); i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int n;
    while(cin>>n,n){
        int a[12];
        rep(i,n) cin>>a[i];
        int c=0;
        while(1){
            map<int,int> m;
            rep(i,n) m[a[i]]++;
            bool update=false;
            rep(i,n){
                if(a[i]!=m[a[i]]){
                    a[i]=m[a[i]];
                    update=true;
                }
            }
            if(!update) break;
            else c++;
        }
        cout<<c<<endl;
        rep(i,n) cout<<a[i]<<(i==n-1 ? '\n' : ' ');
    }
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  int t=1;
  while(t--)
  {
      double r;
      cin>>r;
      printf("%.12f",(double)2*3.142*r);
  }  
  return 0;
}

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

int main()
{
    string S, T;
    cin >> S >> T;

    string ans = "UNRESTORABLE";
    if (S.size() < T.size())
    {
        cout << ans << endl;
        return 0;
    }
    for (int i = 0; i <= S.size() - T.size(); i++)
    {
        bool flag = true;
        for (int j = 0; j < T.size(); j++)
        {
            if (S[i + j] != '?' && (S[i + j] != T[j]))
            {
                flag = false;
                break;
            }
        }
        if (flag)
        {
            string tmp = S;
            replace(tmp.begin(), tmp.end(), '?', 'a');
            tmp.replace(i, T.size(), T);
            if (ans.compare("UNRESTORABLE") == 0)
            {
                ans = tmp;
            }
            else
            {
                ans = min(ans, tmp);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <tuple>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repdm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)
string S = "753";

bool isOk(string s)
{
  return s.find("7") != string::npos && s.find("5") != string::npos && s.find("3") != string::npos;
}

int dfs(int depth, int cnt, string s, string N)
{
  if (depth == 0)
  {
    if (stoi(s) > stoi(N))
      return cnt;
    if (isOk(s))
    {
      // cout << s << endl;
      cnt++;
    }
    return cnt;
  }

  rep(i, 3)
  {
    string tmp = s + S[i];
    cnt = dfs(depth - 1, cnt, tmp, N);
  }

  return cnt;
}

int main()
{
  string N;
  cin >> N;

  int ans = 0;
  string s = "";

  repd(i, 3, N.size() + 1)
  {
    ans = dfs(i, ans, s, N);
  }

  cout << ans;
}

Measured memory_bytes: 256
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
from functools import reduce


x,y,a,b,c = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p = sorted(p, reverse=True)[:x]
q = sorted(q, reverse=True)[:y]
r = sorted(r, reverse=True)

pq = sorted(p+q)
ans = sum(pq)

for i in range(len(r)):
    if pq[i] < r[i]:
        ans = ans + r[i] -pq[i]
    else:
        break

print(ans)


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

int main(){
    vector<long long int> v1;
    long long int sum = 0,n,b;
    cin >> n;
    for(int i = 0;i < n;i++){
        int x;
        cin >> x;
        v1.push_back(x);
        v1[i] -= i + 1;
    }
    vector<long long int> v2 = v1;
    sort(v1.begin(),v1.end());
    //if(n % 2 == 0)
    //    b = (v1[(n/2)-1] + v1[n/2] - n + 1)/2;
    //else
    //    b = v1[n/2] - n / 2 - 1;
    //for(int i = 0;i < n;i++){
    //    sum += abs(v2[i] - (b + (i+1)));
    //}
    long long mid = v1[n/2];
    for(int i = 0;i < n;i++)
        sum += abs(mid - v1[i]);
    cout << sum << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;

int getScore(vector<vector<int>>& v, vector<int>& here){
    int ret = 0;
    for(int i = 0 ; i < v.size(); ++i){
        int a = v[i][0];
        int b = v[i][1];
        if(here[b] - here[a] == v[i][2]){
            ret += v[i][3]; 
        }
    }
    return ret;
}

void permuation(vector<vector<int>>& v, vector<int>& here, int N, int M, int pos, int& ret){
    if(pos == N){
        ret = max(ret, getScore(v, here));
        return;
    }
    int last = here.back();
    for(int i = last ; i <= M; ++i){
        here.push_back(i);
        permuation(v, here, N, M, pos+1, ret);
        here.pop_back();
    }
    return;
}

int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<vector<int>> v(Q);
    for(int i = 0 ; i < Q; ++i){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        v[i] = {a, b, c, d};
    }

    int ret = 0;
    vector<int> here;
    here.push_back(1);
    permuation(v, here, N, M, 0, ret);
    cout << ret << endl;



    return 0;


}

Measured memory_bytes: 3636
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int[] a = { sc.nextInt(), sc.nextInt(), sc.nextInt()};
	Arrays.sort(a);
	System.out.println(a[2]*10+a[1]+a[0]);

    }
}

Measured memory_bytes: 22996
#include <iostream>

using namespace std;

int main()
{
    long long sum=0;
    long long a;
    cin>>a;
    long long now=1;
    while(a!=0)
    {
        a=a/2;
        sum=sum+now;
        now=now*2;
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define inf 1e9
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define repf(i, x, n) for (ll i = (ll)(x); i < (ll)(n); i++)
#define repfr(i, x, n) for (ll i = (ll)(x)-1; i >= (ll)(n); i--)
using ll = int64_t;

void Main() {
  string s;
  std::cin >> s;
  std::cout << ((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3])
                    ? "Yes"
                    : "No")
            << '\n';

  return;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


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

int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> v(n);
    int cnt = 0;
    for(int i =0;i<n;i++){
        cin >> v[i];
        if(v[i]>=k){
            cnt++;
        }
    }
    cout << cnt << endl;
}

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

#define INF64 1LL << 60;
#define INF32 1 << 29;

using namespace std;

void execute()
{
	long long int A, B;
	cin >> A >> B;
	int ans = 0;

	for (; A <= B; A *= 2)
	{
		ans++;
	}
	cout << ans << endl;

	return;
}

int main()
{
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    string w[n];
    set<string> st;
    rep(i, 0, n) {
        cin >> w[i];
        st.insert(w[i]);
    }

    if ((int)st.size() != n) {
        cout << "No" << endl;
        return 0;
    }

    rep(i, 0, n - 1) {
        if (w[i][w[i].size() - 1] != w[i + 1][0]) {
            cout << "No" << endl;
            return 0;
        }
    }

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


Measured memory_bytes: 256
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    m = [ii() for _ in range(ii())]
    print(len(set(m)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
import java.util.*;

public class Main {
    static ArrayList<Integer>[] graph;
    static long count = 0;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		graph = new ArrayList[n + 1];
        for (int i = 1; i <= n; i++) {
            graph[i] = new ArrayList<Integer>();
        }
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            graph[a].add(b);
            graph[b].add(a);
        }
        search(1, new boolean[n + 1]);
		System.out.println(count);
	}
	
	static void search(int idx, boolean[] visited) {
	    if (visited[idx]) {
	        return;
	    }
	    visited[idx] = true;
	    boolean flag = true;
	    for (int i = 1; i < visited.length && flag; i++) {
	        flag = visited[i];
	    }
	    if (flag) {
	        count++;
	        visited[idx] = false;
	        return;
	    }
	    for (int x : graph[idx]) {
	        search(x, visited);
	    }
	    visited[idx] = false;
	}
}


Measured memory_bytes: 22100
N, K = map(int, input().split())

# 各人がもっているお菓子の個数を足しこんでいく
item_num_list = [0 for i in range(N)]
for i in range(K):
    d = int(input())
    Aid = map(int, input().split())
    for a in Aid:
        item_num_list[a - 1] += 1

result = len([i for i in item_num_list if i == 0])
print(result)




Measured memory_bytes: 67204
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		sc.nextLine();

		List<Integer> stickLenList = new ArrayList<Integer>();
		for (int i = 0; i < n; i++) {
			stickLenList.add(sc.nextInt());
		}
		Collections.sort(stickLenList, Collections.reverseOrder());

		int[] ans = { 0 };
		stickLenList.subList(0, k).stream().forEach(e -> ans[0] += e);

		System.out.println(ans[0]);

		sc.close();
	}
}

Measured memory_bytes: 28620
#include <iostream>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <iomanip>
#include <vector>
#include <functional>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <cstdlib>
#include <unordered_map>
#include <string.h>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    int num = A;
    while (num < A * B)
    {
        if (num % B == C)
        {
            cout << "YES" << endl;
            return 0;
        }
        num += A;
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())

S = 3 * C
a = S - (A + B)
b = S - (2 * A + B - C)
c = 2 * A + B - 2 * C
d = A + B - C
e = S - (B + C)
f = S - (A + C)

print(" ".join(map(str, [A, B, a])))
print(" ".join(map(str, [b, C, c])))
print(" ".join(map(str, [d, e, f])))


Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sn = new Scanner(System.in);
        
        int n = sn.nextInt();
        int a[] = new int[n + 1];
        int cnt = 0;

        
        // aに入力値を入れる
        for(int ai = 1; ai <= n; ai++) {
            a[ai] = sn.nextInt();
        }
        
        for(int ai = 1; ai <= n; ai++) {
            // マスの番号は奇数
            if(ai % 2 == 1) {
                // マスに書かれた整数は奇数
                if(a[ai] % 2 == 1) {
                    cnt++;
                }
            }
        }
        
        System.out.print(cnt);
        
    }
}


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

Int cnt;
Int N;

vector<Int> f(vector<Int> ans) {
    vector<Int> v(N,0);
        rep(i,N) {
            int start, end;
            if (i >= ans[i]) start = i-ans[i];
            else start = 0;
            if (i+ans[i] <= N-1) end = i+ans[i];
            else end = N-1;
            v[start]++;
            if (end < N-1) v[end + 1]--;
        }
    vector<Int> w(N);
    w[0] = v[0];
    if (ans[0] != N && w[0] == N) cnt++;
    rep1(i,N-1) {
        w[i] = w[i-1] + v[i];
        if (ans[i] != N && w[i] == N) cnt++;
    }
    return w;
}

int main(){
    Int K;
    cin >> N >> K;
    vector<Int> A(N), ans(N);
    cnt = 0;
    rep(i,N) {
        cin >> A[i];
        ans[i] = A[i];
        if (A[i] == N) cnt++;
    }

    rep(i,K) {
        ans = f(ans);
        cnt = 0;
        rep(i,N) if (ans[i] == N) cnt++;
        if (cnt == N) break;
    }

    if(N > 1) rep(i,N-1) cout << ans[i] << " ";
    cout << ans[N-1] << endl;




}

Measured memory_bytes: 11124
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


int main()
{
	bool www = false;
	int n;
	while (cin >> n, n)
	{
		if (www)
			cout << endl;

		static int v[] = { 10, 50, 100, 500 };
		int num[4];
		rep (i, 4)
			cin >> num[i];

		int res = 13333, pay_n[4];
		int p[4];
		for (p[0] = 0; p[0] <= num[0]; ++p[0])
			for (p[1] = 0; p[1] <= num[1]; ++p[1])
				for (p[2] = 0; p[2] <= num[2]; ++p[2])
					for (p[3] = 0; p[3] <= num[3]; ++p[3])
					{
						int pay = 0, left[4];
						rep (i, 4)
						{
							pay += v[i] * p[i];
							left[i] = num[i] - p[i];
						}
						if (pay < n)
							continue;
						
						int t = pay - n;
						for (int i = 3; i >= 0; --i)
						{
							int w = t / v[i];
							left[i] += w;
							t -= v[i] * w;
						}

						int r = accumulate(left, left + 4, 0);
						if (r < res)
						{
							res = r;
							copy(p, p + 4, pay_n);
						}
					}

		for (int i = 0; i < 4; ++i)
			if (pay_n[i])
				cout << v[i] << " " << pay_n[i] << endl;
		www = true;
	}
}

Measured memory_bytes: 0
import sys


def int1(x): return int(x) - 1
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def mi1(): return map(int1, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def lli(rows_number): return [li() for _ in range(rows_number)]


if __name__ == "__main__":
    k = ii()
    s = input()
    if len(s) <= k:
        print(s)
    else:
        print(s[:k] + '...')

Measured memory_bytes: 9208
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, m, l, r, a, b;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    b = 100009;
    for (int i = 0; i < m; i++) {
        cin >> l >> r;
        a = max(l, a); b = min(b, r);
    }
    cout << max(b - a + 1, 0) << "\n";
    //system("pause");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

int main(void){
    char a[1000];
    char b[1000];
    cin>>a>>b;
    int lena=strlen(a),lenb=strlen(b);
    char c[500];
    int cur=0;
    for(int i=0;i<lena;i++) c[cur++]=a[i];
    for(int i=0;i<lenb;i++) c[cur++]=b[i];
    c[cur]='\0';
    ll ans=atoi(c);
    //cout << ans << endl;
    int t=sqrt(ans);
    if(t*t==ans)    cout<<"Yes"<<endl;
    else    cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

const int dy[] = {-1, 0, 1, 0}, dx[] = {0, -1, 0, 1};
int h, w, n, next[1000001][4];
string s, in[1000];
bool v[1000][1000][4];


int main(){
	while(cin >> h >> w >> n, h){
		memset(v, 0, sizeof(v));
		int y, x, d = 0;
		cin >> s;
		rep(i, h){
			cin >> in[i];
			rep(j, w) if(in[i][j] == 'S') y = i, x = j;
		}
		rep(i, n) d = (d + (s[i] == 'L' ? 1 : 3)) % 4;
		rep(i, 4) next[n][i] = n + 1;
		next[n][d] = n;
		for(int i = n - 1; i >= 0; i--){
			d = (d + (s[i] == 'L' ? 3 : 1)) % 4;
			rep(j, 4) next[i][j] = j == d ? i : next[i + 1][j];
		}
		
		priority_queue<pair<pi, pi> > q;
		q.push(mp(mp(0, 0), mp(y, x)));
		while(!q.empty()){
			y = q.top().second.first; x = q.top().second.second;
			int co = q.top().first.first, d = q.top().first.second;
			q.pop();
			
			if(v[y][x][d]) continue;
			v[y][x][d] = 1;
			if(in[y][x] == 'G'){
				cout << "Yes" << endl;
				goto END;
			}
			
			int ny = y + dy[d], nx = x + dx[d];
			if(0 <= ny && ny < h && 0 <= nx && nx < w){
				if(!v[ny][nx][d] && in[ny][nx] != '#') q.push(mp(mp(co, d), mp(ny, nx)));
			}
			rep(i, 4) if(!v[y][x][i]){
				int nc = next[-co][i];
				if(nc <= n) q.push(mp(mp(-nc, i), mp(y, x)));
			}
		}
		cout << "No" << endl;
		END:;
	}
	return 0;
}

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

int main(){
    
    int N,K;cin>>N>>K;
    if(N*(N-1)/2-(N-1)<K) cout<<-1<<endl;
    else{
        int diff=(N*(N-1)/2-(N-1))-K;
        vector<int> A(N*(N-1)/2-(N-1),0),B(N*(N-1)/2-(N-1),0);
        int now=0;
        for(int i=2;i<=N;i++){
            for(int j=i+1;j<=N;j++){
                A[now]=i;
                B[now]=j;
                now++;
            }
        }
        
        cout<<N-1+diff<<endl;
        
        for(int i=2;i<=N;i++){
            cout<<1<<" "<<i<<endl;
        }
        
        for(int i=0;i<diff;i++){
            cout<<A[i]<<" "<<B[i]<<endl;
        }
    }
}


Measured memory_bytes: 256
using System;

namespace Test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var expression = Console.ReadLine().Split();

            var capacity = 0;
            if (expression.Length <= 100)
            {
                capacity = expression.Length;
            }
            else
            {
                capacity = 100;
            }
            Stack<int> stack = new Stack<int>(capacity);
            foreach (var item in expression)
            {
                switch (item)
                {
                    case "+":
                        stack.Push(stack.Pop() + stack.Pop());
                        break;
                    case "-":
                        var temp = stack.Pop();
                        stack.Push(stack.Pop() - temp);
                        break;
                    case "*":
                        stack.Push(stack.Pop() * stack.Pop());
                        break;
                    default:
                        stack.Push(int.Parse(item));
                        break;
                }
            }

            Console.WriteLine(stack.Pop());
            Console.Read();
        }


    }
    class Stack<T>
    {
        private T[] array;
        private int index = 0;

        public Stack(int capacity)
        {
            array = new T[capacity];
        }
        public void Push(T item)
        {
            array[index++] = item;
        }
        public T Pop()
        {
            return array[--index];
        }
    }
}

Measured memory_bytes: 20048
N=int(input())
W=list(map(int,input().split()))
M=sum(W)
S=0
ANS=sum(W)
for i in range(N):
    S+=W[i]
    M-=W[i]
    if abs(S-M)<ANS:
        ANS=abs(S-M)
print(ANS)

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

int main() {
  string S;
  cin >> S;

  int year = stoi(S.substr(0, 4));
  int month = stoi(S.substr(5, 2));
  if (year <= 2019 && month <= 4) {
    cout << "Heisei" << endl;
  } else {
    cout << "TBD" << endl;
  }
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<iomanip>
#include<sstream>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#define rep(i,x,n) for(int i=x;i<=n;i++)
#define per(i,n,x) for(int i=n;i>=x;i--)
#define sz(a) int(a.size())
#define rson mid+1,r,p<<1|1
#define pii pair<int,int>
#define lson l,mid,p<<1
#define ll long long
#define pb push_back
#define mp make_pair
#define se second
#define fi first
using namespace std;
const double eps=1e-8;
const int mod=1e9+7;
const int N=1e5+10;
const int inf=1e9;
int n,q;
map<int,int>a;
int main(){
    //ios::sync_with_stdio(false);
    //freopen("in","r",stdin);
    scanf("%d",&n);
    ll ans=0;
    rep(i,1,n){
        int x;
        scanf("%d",&x);
        a[x]++;
        ans+=x;
    }
    scanf("%d",&q);
    rep(i,1,q){
        int b,c;
        scanf("%d%d",&b,&c);
        ans-=1ll*b*a[b];
        ans+=1ll*c*a[b];
        a[c]+=a[b];
        a[b]=0;
        printf("%lld\n",ans);
    }
    return 0;
}

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

using namespace std;

int ans = -1;

inline void solve(string a, string b, string c) {
    for (int i = 0; i <= (int)a.size(); ++i) {
        int ok = 1;
        for (int j = i; j < min((int)a.size(), i + (int)b.size()) && ok; ++j) {
            if (a[j] != b[j - i] && a[j] != '?' && b[j - i] != '?') ok = 0;
        }
        if (ok == 0) continue;
        int N = max((int)a.size(), i + (int)b.size());
        for (int j = 0; j <= N; ++j) {
            int nxt = max(N, j + (int)c.size());
            if (ans != -1 && nxt >= ans) break;
            ok = 1;
            for (int z = j; z < min(N, j + (int)c.size()) && ok; ++z) {
                if (c[z - j] == '?') continue;
                char f = '?';
                if (z < (int)a.size() && a[z] != '?') f = a[z];
                if (z < i + (int)b.size() && b[z - i] != '?') f = b[z - i];
                if (f == '?') continue;
                if (f != c[z - j]) ok = 0;
            }
            if (ok) {
                ans = nxt;
            }
        }
    }
}

main() {
#ifdef HOME
    freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string a, b, c;
    cin >> a >> b >> c;
    solve(a, b, c);
    solve(a, c, b);
    solve(b, a, c);
    solve(b, c, a);
    solve(c, a, b);
    solve(c, b, a);
    cout << ans << '\n';
    return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1000000007;
const ll N=998244353;
ll power(ll x,ll n){ll res=1;while(n>0){if(n&1) res=res*x%MOD;x=x*x%MOD;n>>=1;}return res;}
ll modinverse(ll a){return power(a, MOD-2);}
void solve()
{
	string str;
	cin>>str;
	if(str[0]=='R')
	{
		if(str[1]=='R')
		{
			if(str[2]=='R')
				cout<<3<<endl;
			else
				cout<<2<<endl;
		}
		else
			cout<<1<<endl;
		return;
	}
	else if(str[1]=='R')
	{
		if(str[2]=='R')
			cout<<2<<endl;
		else
			cout<<1<<endl;
		return;
	}
	if(str[2]=='R')
		cout<<1<<endl;
	else
		cout<<0<<endl;
}
int main()
{
	#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll test=1;
    //cin>>test;
    while(test--)
    {
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//最大公約数
ll gcd(ll a,ll b)
{
    if(a%b == 0)
        return b;
    else
        return gcd(b, a % b);
}
ll n, m;
double arr[10];
int main(){
    //cin >> n;
    string s;
    cin >> s;
    int ss[4]={0,0,0,0};
    int p[26];

    for (int i = 0; i < 26;i++)
    {
        p[i] = 0;
    }
        for (int i = 0; i < 4; i++)
        {
            ss[i] = s[i] - 'A';
            p[ss[i]] += 1;
        }
        bool c = false;
    for (int i = 0; i < 26;i++)
    {
        if(p[i] == 2 && !c)
        {
            c = true;
        }
        else if(p[i] == 2)
        {
            cout << "Yes" << endl;
            return 0;
        }
        else if(p[i] == 1 || p[i] == 3 || p[i] ==4)
        {
            cout << "No" << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
ll n,a[100009],b[100009],c[100009],dp[100009][5];
int main (){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i=1; i<=n; i++){
		cin >> a[i] >> b[i] >> c[i];
	}
	for (int i=n; i>=1; i--){
		dp[i][1]=a[i]+max(dp[i+1][2],dp[i+1][3]);
		dp[i][2]=b[i]+max(dp[i+1][1],dp[i+1][3]);
		dp[i][3]=c[i]+max(dp[i+1][1],dp[i+1][2]);
	}
	ll jwb=0;
	for (int i=1; i<=3; i++){
		jwb=max(jwb,dp[1][i]);
	}
	cout << jwb << endl;
}

Measured memory_bytes: 6528
n, m, s = gets.chomp.split(" ")

cnt5 = 0
cnt7 = 0

if n == "5" then
    cnt5 += 1
else
    cnt7 += 1
end

if m == "5" then
    cnt5 += 1
else
    cnt7 += 1
end

if s == "5" then
    cnt5 += 1
else
    cnt7 += 1
end


if cnt5 == 2 && cnt7 == 1
    puts "YES"
else
    puts "NO"
end

Measured memory_bytes: 1788