akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FASTIO
using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    int A, B;
    cin >> A >> B;
    cout << 6 - A - B << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pi pair<ll,ll>
#define fr freopen("in.txt","r",stdin)
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define frep(i,n) for(int i=1;i<=n;i++)
#define ll long long
#define f first
#define s second
#define maxn 50
const ll mod = 1e9+7;
int main() {
    int N,K;
    cin >> N >> K;
    int x;
    int cur = 0;
    map<int,int>freq;
    rep(i,N) {
        cin >> x;
        freq[x]++;
        if(freq[x]==1) cur++;
    }
    vector<pi>v;
    for(auto x:freq) {
        v.pb({x.s,x.f});
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    int ans = 0;
    while(v.size()>K) {
        ans+=v.back().f;
        v.pop_back();
    }
    cout << ans;
}

Measured memory_bytes: 14324
// IN the name of GOD

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int M = 1e9 + 7, N = 1e6 + 20;

void solve () {
    int n;
    cin >> n;
    vector <int> a(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    bool chk[N];
    memset(chk, 0, sizeof chk);
    for (int i = 1; i <= n; ++i) {
        if (a[i] == a[i - 1]) {
            chk[a[i]] = 1;
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        if (!chk[a[i]]) {
            ans++;
        }
        if (a[i] != a[i - 1]) {
            for (int j = 2*a[i]; j < N; j += a[i]) {
                chk[j] = 1;
            }
        }
    }
    cout << ans;

}

int main () {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int tt = 1;
        // scanf("%d", &tt);
    while (tt--)
        solve();
 
}

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

using namespace std;
typedef long long ll;

int N, M;
vector<pair<ll, ll> > s, p;

int main() {
  cin >> N >> M;
  s.resize(N);
  for(int i = 0; i < N; i++) {
    ll a, b;
    cin >> a >> b;
    s[i] = {a, b};
  }

  p.resize(M);
  for(int i = 0; i < M; i++) {
    ll c, d;
    cin >> c >> d;
    p[i] = {c, d};
  }

  for(int i = 0; i < N; i++) {
    ll x = s[i].first, y = s[i].second;
    ll md = 1e9, n = -1;
    for(int j = 0; j < M; j++) {
      ll d = abs(x - p[j].first) + abs(y - p[j].second);
      if (d < md) {
        md = d;
        n = j + 1;
      }
    }
    cout << n << endl;
  }

  return 0;
}

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

using namespace std;

#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

int n;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  vector<int> a(n);
  range(i, 0, n) cin >> a[i];
  if(a[n - 1] != 2) {
    cout << -1;
    return 0;
  }
  a.pop_back();
  reverse(a.begin(), a.end());
  long long x = 2;
  long long y = 3;
  for(int i : a) {
    x = ((x + i - 1) / i) * i;
    y = (y / i) * i + i - 1;
    if(y < x) {
      cout << -1;
      return 0;
    }
  }
  cout << x << " " << y;
  return 0;
}


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

#define all(x) (x).begin(), (x).end()
using lli = long long int;

constexpr int N = 1020;

int n, cnt;
char cur = 'a';
int rc[N], cc[N];
char field[N][N];

void clear() {
  cur = 'a';
  memset(rc, 0, N*sizeof(int));
  memset(cc, 0, N*sizeof(int));
  memset(field, 0, N*N*sizeof(char));
}

bool check() {
  for (int i = 0; i < n; ++i) if (rc[i] != cnt || cc[i] != cnt) return false;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) cout << (field[i][j] == 0 ? '.' : field[i][j]);
    cout << endl;
  }
  return true;
}

bool dfs(int r, int c) {
  if (c >= n) {
    c = 0;
    r++;
  }
  if (r >= n) return false;
  if (r && rc[r - 1] < cnt) return false;
  if (field[r][c]) return dfs(r, c + 1);
  if (c + 1 < n && field[r][c + 1] == 0 && rc[r] < cnt && cc[c] < cnt && cc[c + 1] < cnt) {
    rc[r]++; cc[c]++; cc[c + 1]++;
    field[r][c] = field[r][c + 1] = cur++;
    if (check()) return true;
    if (dfs(r, c + 1)) return true;
    field[r][c] = field[r][c + 1] = 0;
    rc[r]--; cc[c]--; cc[c + 1]--; cur--;
  }
  if (r + 1 < n && field[r + 1][c] == 0 && rc[r] < cnt && cc[c] <cnt && rc[r + 1] < cnt) {
    rc[r]++; cc[c]++; rc[r + 1]++;
    field[r][c] = field[r + 1][c] = cur++;
    if (check()) return true;
    if (dfs(r, c + 1)) return true;
    field[r][c] = field[r + 1][c] = 0;
    rc[r]--; cc[c]--; rc[r + 1]--; cur--;
  }
  return dfs(r, c + 1);
}

map<int, string> precomputed = {
  {4,
"aabc"
"ddbc"
"efgg"
"efhh"},
  {5,
"aabbc"
"dde.c"
"ffegg"
"..hij"
"..hij"},
  {6,
"aabbcc"
"ddeeff"
"ghi..."
"ghi..."
"...jkl"
"...jkl"},
  {7,
"aabbcc."
"ddeef.."
"gg..fhh"
"..ij..k"
"..ij..k"
"....lmn"
"....lmn"}
};

void write(int s, int n) {
  int cnt = 0;
  for (int i = s; i < s + n; ++i) for (int j = s; j < s + n; ++j)
    field[i][j] = precomputed[n][cnt++];
}

int main() {
  ios_base::sync_with_stdio(false);
  //for (cnt = 3; cnt < N; ++cnt) for (n = 3; n < N; ++n) {
    //cout << n << ' ' << cnt << endl;
    //clear();
    //dfs(0, 0);
    //cout << endl;
  //}
  int n;
  cin >> n;
  if (n == 2) cout << -1;
  else if (n == 3) cout << "aa.\n..b\n..b";
  else {
    int st = (n % 4) + 4;
    write(0, st);
    for (int i = st; i < n; i += 4) write(i, 4);
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) cout << (field[i][j] == 0 ? '.' : field[i][j]);
      cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 2176
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;


int main()
{
	int n;
	cin >> n;
	vector<long long int> a(n);
	int f = 0;
	long long int ans = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (a[i]<0)
		{
			f++;
		}
		ans += abs(a[i]);
		a[i] = abs(a[i]);
	}
	
	if (f % 2 == 0)
	{
		cout << ans << endl;
	}
	else
	{
		sort(a.begin(), a.end());
		cout << ans - 2 * (abs(a[0]));
	}

	
}


Measured memory_bytes: 1024
import sys
INF = float("inf")
n = int(input())
m = [[0] * (n + 1) for _ in range(n + 1)]
li = [list(map(int, a.split())) for a in sys.stdin]
z = (li[0][0], ) + list(zip(*li))[1]
for l in range(1, n):
    for i in range(1, n - l + 1):
        j = i + l
        m[i][j] = INF
        for k in range(i, j):
            m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + z[i - 1] * z[k] * z[j])
print(m[1][n])



Measured memory_bytes: 5720
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int X;
    cin >> X;
    int cnt1 = X/500, cnt2 = (X%500)/5;
    cout << cnt1*1000 + cnt2*5 << endl;
}   

Measured memory_bytes: 256
//g++  7.4.0

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAXX 1e18

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll N,K; cin>>N>>K;
    ll P[N];
    ll C[N];
    
    for(ll i=0;i<N;++i)
    {
        cin>>P[i]; 
        P[i]--;
    }
    
    for(ll i=0;i<N;++i)
        cin>>C[i];
    
    ll ans = LLONG_MIN;
    for(ll i=0;i<N;++i)
    {
        ll start = P[i];
        vector<ll> cost;
        
        while(start != i)
        {
            cost.push_back(C[start]);
            start = P[start];
        }
        
        cost.push_back(C[i]);
        
        ll mx_sm = LLONG_MIN;
        ll mx_in = -1;
        ll sum = 0;
        
        ll M = cost.size();
        for(ll j=0;j<M;++j)
        {
            sum += cost[j];
            if(mx_sm < sum)
            {
                mx_sm = sum;
                mx_in = j;
            }
        }
        
        mx_in++;
        
        if(mx_sm < 0 || K < mx_in || sum < 0)
        {
            sum = 0;
            ll cur_ans = LLONG_MIN;
            
            for(ll j=0;j<min(K,M);++j)
            {
                sum += cost[j];
                cur_ans = max(cur_ans,sum);
            }
            
            ans = max(ans,cur_ans);
        }
        else
        {
            ll term = (K - mx_in)/M;
            ans = max(ans,term*sum + mx_sm);
            
            term = K/M;
            ll rem = K%M;
            
            ll cur_ans = term*sum;
            sum = 0;
            for(ll j=0;j<rem;++j)
            {
                sum += cost[j];
                ans = max(ans,cur_ans + sum);
            }
        }
    }
    
    cout<<ans<<endl;
}

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

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

using namespace std;

int main(){
    int n,c;
    cin >>n>>c;
    int p;
    int k=0;
    rep(i,c){
        scanf("%d",&p);
        k+=p;
    }
    int a;
    if(k%(n+1)!=0)a=1;
    else a=0;
    cout <<k/(n+1)+a<<endl;
    return 0;
}


Measured memory_bytes: 3252
# -*- coding: utf-8 -*-
S= list(input())
T= list(input())

ans = 0
for i in range(len(S) - len(T) + 1):
  S2 = S[i:i+len(T)]
  tmp=0
  for j in range(len(T)):
    if S2[j] == T[j]:
      tmp+=1
  ans = max(ans,tmp)

print(len(T) - ans)


Measured memory_bytes: 9116
#include <iostream>
//#include <math.h>


using namespace std;

int main(void){
    long long int N,K,x;
    cin >> N >> K;

    x=N%K;

    if(x<abs(x-K)) cout << x << endl;
    else cout << abs(x-K) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <math.h>
#include <tuple>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;

int main() {
    int n, x[10], y[10], f = 1;
    vector<int> v;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        v.push_back(i);
        f *= i + 1;
    }


    double s = 0;
    do {
        double d = 0;
        for (int i = 0; i < n - 1; i++) {
            d += sqrt(pow(x[v[i]] - x[v[i + 1]], 2) + pow(y[v[i]] - y[v[i + 1]], 2));
        }
        s += d;
    } while (next_permutation(v.begin(), v.end()));

    cout << setprecision(12) << s / f << endl;
}


Measured memory_bytes: 256
n = int(input())
alist = [0] + list(map(int, input().split()))
total = 0
for i in range(n):total += abs(alist[i]-alist[i+1])
total += abs(alist[-1])

for i in range(1,n):
  print(total-abs(alist[i]-alist[i-1])-abs(alist[i+1]-alist[i])+ abs(alist[i+1]-alist[i-1]))
print(total-abs(alist[-1]-alist[-2])-abs(alist[-1]-alist[0])+abs(alist[-2]-alist[0]))

Measured memory_bytes: 14048
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
static const ll MOD = 1000000007;

int main(){
  ll a,b,c;
  cin >> a >> b >> c;
  if(c < a + b){
    cout << "No" << endl;
  }else{
    ll tmp = c - a - b;
    tmp = tmp * tmp;
    if(tmp > 4 * a * b){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 256
using System;

class MyClass
{
    static void Rotate(ref int a, ref int b, ref int c, ref int d)
    {
        int _a = a;
        a = b;
        b = c;
        c = d;
        d = _a;
    }

    static void Main(string[] args)
    {
        int n;
        while ((n = int.Parse(Console.ReadLine())) != 0)
        {
            int sum = 1;
            int top = 1;
            int north = 5;
            int east = 3;
            int south = 2;
            int west = 4;
            int bottom = 6;
            for (int i = 0; i < n; i++)
            {
                switch (Console.ReadLine())
                {
                    case "North":
                        Rotate(ref top, ref south, ref bottom, ref north);
                        break;
                    case "East":
                        Rotate(ref top, ref west, ref bottom, ref east);
                        break;
                    case "South":
                        Rotate(ref top, ref north, ref bottom, ref south);
                        break;
                    case "West":
                        Rotate(ref top, ref east, ref bottom, ref west);
                        break;
                    case "Right":
                        Rotate(ref south, ref east, ref north, ref west);
                        break;
                    case "Left":
                        Rotate(ref south, ref west, ref north, ref east);
                        break;
                    default:
                        break;
                }
                sum += top;
            }
            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 5864
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>


#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define LOWER(a,x) lower_bound(ALL(a), x) - a.begin() - 1;
#define COUNT(a,x)  upper_bound(ALL(a), x) - lower_bound(ALL(a), x);
#define MCOUNT(a,x,y) upper_bound(ALL(a), y) - lower_bound(ALL(a), x);
#define scan(x) scanf("%lld",&x);
#define inf 5555555555555555555
#define mod 1000000007
#define pi 3.14159265358979323846
#define pb push_back
#define F first
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool flag, ok;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111



int main(void) {
  map<char, ll> mp[55];

  cin >> n;
  cin >> s;
  FOR(i, 0, s.length()) mp[0][s[i]]++;

  FOR(i, 1, n) {
	cin >> s;
	FOR(j, 0, s.length()) mp[i][s[j]]++;
	for (char c = 'a';c <= 'z';c++) {
	  mp[i][c] = min(mp[i - 1][c], mp[i][c]);
	}
  }

  for (auto it : mp[n-1]) {
	FOR(i, 0, it.second) cout << it.first;
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define N 300010
using namespace std;
int n;
char s[N];
int f1[N];
int f2[N];
int main()
{
	scanf("%d%s", &n, s);
	for(int i = 1; i <= n; ++ i)
		if(s[i - 1] == 'W')
			f1[i] = f1[i - 1] + 1;
		else
			f1[i] = f1[i - 1];
	for(int i = n; i >= 1; -- i)
		if(s[i - 1] == 'E')
			f2[i] = f2[i + 1] + 1;
		else
			f2[i] = f2[i + 1];
	int Ans = n;
	for(int i = 1; i <= n; ++ i)
		Ans = min(Ans, f1[i - 1] + f2[i + 1]);
	printf("%d", Ans);
	return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
#define rg register
#define file(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
using namespace std;
int read() {
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
    while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();
    return f*x;
}
main(){
    char c;
    cin>>c;
    if(c=='A') puts("T");
    if(c=='T') puts("A");
    if(c=='G') puts("C");
    if(c=='C') puts("G");
}


Measured memory_bytes: 256
mod = 10**9 + 7
h, w = list(map(int, input().split()))
arr = [[] for _ in range(h)]
for i in range(h):
    raw = list(input())
    arr[i] = raw
    
count = [[0 for _ in range(w+1)] for _ in range(h+1)]
count[1][1] = 1
for i in range(1, h+1):
    for j in range(1, w+1):
        if i == 1 and j == 1:
            continue
        if arr[i-1][j-1] == '.':
            count[i][j] = count[i-1][j] + count[i][j-1]
            count[i][j] = count[i][j] % mod
        else:
            count[i][j] = 0
print(count[h][w])

Measured memory_bytes: 52408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={1,1,1,0,0,-1,-1,-1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll par[100010];
int len[100010];
void init(ll n){
  for(int i=0;i<n;i++){
    par[i]=i;
    len[i]=0;
  }
}
ll root(ll n){
  if(par[n]==n)return n;
  return par[n]=root(par[n]);
}
void unit(ll a,ll b){
  a=root(a);
  b=root(b);
  if(a==b)return;
  if(len[a]<len[b]){
    par[a]=b;
  }
  else{
    par[b]=a;
    if(len[a]==len[b])len[a]++;
  }
}
int main(){
  int n;cin>>n;
  string s;cin>>s;
  int dp[n][2];
  if(s[0]=='.'){
    dp[0][0]=0;
    dp[0][1]=1;
  }
  else{
    dp[0][0]=1;
    dp[0][1]=0;
  }
  for(int i=1;i<n;i++){
    if(s[i]=='.'){
      dp[i][0]=dp[i-1][0];
      dp[i][1]=min(dp[i-1][1]+1,dp[i-1][0]+1);
    }
    else{
      dp[i][0]=dp[i-1][0]+1;
      dp[i][1]=min(dp[i-1][0],dp[i-1][1]);
    }
  }
  cout<<min(dp[n-1][0],dp[n-1][1])<<endl;
  //for(int i=0;i<n;i++)cout<<dp[i][0]<<" "<<dp[i][1]<<endl;
}
  
  
  
  
  
  
  
  
  
  

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

using namespace std;

int main(void)
{
	long long a, b, x;
	cin >> a >> b >> x;
	if (a == b) {
		cout << ((a % x == 0) ? 1 : 0) << endl;

		return 0;
	}
	long long ans = (b == 0) ? 1 : b / x;
	ans -= (a == 0) ? -1 : (a - 1) / x;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(void) {
	int p, q;
	while(scanf("%d %d", &p, &q) == 2) {
		int s = p + q;
		int ans = (int)log10((double)s) + 1;
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 0
import sys
S,T = input().split()
A,B = map(int,input().split())
U = input()

if not ( S.islower() and T.islower() and U.islower() ): sys.exit()
if not ( 1 <= len(S) <= 10 and 1 <= len(T) <= 10 ): sys.exit()
if not ( S != T ): sys.exit()
if not ( S == U or T == U ): sys.exit()
if not ( isinstance(A,int) and isinstance(B,int) ): sys.exit()

print(A-1,B,sep=' ') if U == S else print(A,B-1,sep=' ')

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

struct QuickFind {
    vector<int>          r, p;
    vector<vector<int> > v;
    QuickFind() {}
    QuickFind(int size) { init(size); }
    void init(int size) {
        r.resize(size, 0);
        p.resize(size, 0);
        v.resize(size);
        for (int i = 0; i < size; i++) {
            r[i] = 1, p[i] = i;
            v[i].resize(1, i);
        }
    }
    bool same(int x, int y) { return p[x] == p[y]; }
    void unite(int x, int y) {
        x = p[x];
        y = p[y];
        if (x == y) return;
        if (r[x] < r[y]) swap(x, y);
        r[x] += r[y];
        for (int i = 0; i < (int)v[y].size(); i++) {
            p[v[y][i]] = x;
            v[x].push_back(v[y][i]);
        }
        v[y].clear();
    }
};
signed main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<int> b(a);
    sort(b.begin(), b.end());
    map<int, int> p, q;
    for (int i = 0; i < n; i++) {
        p[a[i]] = i;
        q[b[i]] = i;
    }
    QuickFind qf(n);
    for (int i = 0; i < n; i++) qf.unite(i, p[b[i]]);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int k = qf.v[i].size();
        if (qf.p[i] != i || k == 1) continue;
        int m   = a[qf.v[i][0]];
        int tmp = 0;
        for (int j = 0; j < k; j++) {
            tmp += a[qf.v[i][j]];
            m = min(m, a[qf.v[i][j]]);
        }
        ans += min(tmp + m * (k - 2), tmp + m + b[0] * (k + 1));
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3400
// 基本テンプレート
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int search(vector<int> &vec, int target) {
    auto itr = lower_bound(vec.begin(), vec.end(), target);

    int res = INF;
    if(itr != vec.begin()) {
        auto nitr = itr; nitr--;
        chmin(res, abs(target - *nitr));
    }
    if(itr != vec.end()) {
        chmin(res, abs(target - *itr));
    }
    return res;
}

signed main() {
    int D, N, M;
    while(cin >> D, D) {
        cin >> N >> M;
        vector<int> d(N), k(M);
        for(int i=1; i<N; i++) cin >> d[i];
        for(int i=0; i<M; i++) cin >> k[i];

        vector<int> vec;
        for(int i=0; i<N; i++) {
            vec.push_back(d[i]);
            vec.push_back(d[i] + D);
        }
        sort(vec.begin(), vec.end());

        int ans = 0;
        for(int i=0; i<M; i++) {
            int plus = INF;
            chmin(plus, search(vec, k[i]));
            chmin(plus, search(vec, k[i] + D));
            ans += plus;
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 5712
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

char col[] = {'R', 'G', 'B'};
string board[4];
int n, d[1<<16], h[20], w[20];
signed main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  REP(i, n) cin >> h[i] >> w[i];
  REP(i, 4) cin >> board[i];

  REP(i, 1<<16) d[i] = INF;
  d[0] = 0;
  queue<int> que;
  que.push(0);

  while(que.size()) {
    int bit = que.front(); que.pop();
    // cout << bit << endl;
    if(bit == (1LL<<16)-1) break;
    REP(i, n) FOR(y, -h[i]+1, 4) FOR(x, -w[i]+1, 4) REP(c, 3) {
      int n_bit = bit;
      FOR(ny, max(0LL, y), min(y+h[i],4LL)) FOR(nx, max(0LL, x), min(x+w[i],4LL)) {
        if(board[ny][nx] == col[c]) n_bit |= 1<<(ny*4+nx);
        else n_bit &= ~(1<<(ny*4+nx));
      }
      // cout << bitset<16>(n_bit) << endl;
      if(d[n_bit] == INF) {
        d[n_bit] = d[bit] + 1;
        que.push(n_bit);
      }
    }
  }

  if(d[(1LL<<16)-1] == INF) cout << -1 << endl;
  else cout << d[(1LL<<16)-1] << endl;

  return 0;
}



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

using namespace std ; 

int main ( ) 
{
	int a , b , c , d ; 
	cin >> a >> b >> c >> d ; 
	
	if (c >b) 
	{
		cout << 0 ;	
	}
	else if (c>=a && d<=b)
	{
		cout << d - c;
	}
	else if (c>=a && d>=b)
	{
		cout << b - c ;
	}
	else if (a>d) 
	{
		cout << 0 ;
	}
	else if (a>=c && b<=d)
	{
		cout << b - a ;
	}
	else if (a>=c && b>=d) 
	{
		cout << d - a;
	}
	else if ( a == c && b == d)
	{
		cout << b - a ;
	}
		return 0 ; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;
const int MAX = 2100;

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

    COMinit();

    for (int i = 1; i <= k; i++) {
        if (i > n-k+1) {
            cout << "0" << endl;
            continue;
        }

        lint res = COM(n-k+1, i);
        res *= COM(k-1, i-1);
        res %= MOD;

        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 256
from math import pi, cos, fabs
A, B, H, M = map(int, input().split())
theta = (H + M / 60) / 12 * 2 * pi
phi = M / 60 * 2 * pi
alpha = fabs(theta - phi)
x = A ** 2 + B ** 2 - 2 * A * B * cos(alpha)
print(x ** (1/2))

Measured memory_bytes: 9504
import java.io.*;

class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder(br.readLine());
        for (int i = 0; i < sb.length(); i++) {
            char c = sb.charAt(i);
            if (Character.isUpperCase(c)) {
                sb.setCharAt(i, Character.toLowerCase(c));
            } else {
                sb.setCharAt(i, Character.toUpperCase(c));
            }
        }
        System.out.println(sb.toString());
    }
}

Measured memory_bytes: 24172
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) 
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }

string str;
int num;
map<string,vint> ma;

int main() {
    ma.clear();
    while (cin >> str >> num) {
        ma[str].PB(num);
    }
    EACH(it,ma) {
        cout << it->first << endl;
        vint res = it->second;
        sort(ALL(res));
        for (int i = 0; i < res.size(); ++i) {
            cout << res[i];
            if (i != res.size()-1) cout << " ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 1244
import itertools
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        S = input().rstrip()

        ans = int(S)
        for i in range(1, len(S)):
            for c in itertools.combinations(range(1, len(S)), i):
                tmp = S
                for j, v in enumerate(c):
                    index = j + v
                    tmp = tmp[:index] + '+' + tmp[index:]
                ans += eval(tmp)

        print(ans)


# Run main
if __name__ == '__main__':
    AtCoder().main()


Measured memory_bytes: 38768
S = list(input())
odd = ['R','U','D']
even = ['L','U','D']
boolean = []
for i in range(0,len(S)):
    if (i+1) % 2 == 1:
        boolean.append(S[i] in odd)
    else:
        boolean.append(S[i] in even)
if all(boolean):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			
			long[] array = new long[N];
			for(int i = 0; i < N; i++) {
				array[i] = sc.nextLong();
			}
			
			long[] pre_max = new long[N];
			long[] post_max = new long[N];
			
			pre_max[0] = array[0];
			post_max[N - 1] = array[N - 1];
			for(int i = 1; i < N; i++) {
				pre_max[i] = Math.max(pre_max[i - 1], array[i]);
			}
			for(int i = N - 2; i >= 0; i--) {
				post_max[i] = Math.max(post_max[i + 1], array[i]);
			}
			
			for(int i = 0; i < N; i++) {
				final long pre  = i == 0 ? 0 : pre_max[i - 1];
				final long post = i == N - 1 ? 0 : post_max[i + 1];
				System.out.println(Math.max(pre, post));
			}
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 60576
// 写経 of けんちょん
#include <bits/stdc++.h>

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line
int N, M;
int a[1100], b[1100], c[1100];
int dist[110][110];
const int INF = 1e9;
int main()
{
	cin >> N >> M;
	rep(i,N){
		rep(j,N) dist[i][j] = INF;
		dist[i][i] = 0;
	}

	rep(i,M){
		cin >> a[i] >> b[i] >> c[i];
		--a[i], --b[i];
		dist[a[i]][b[i]] = c[i];
		dist[b[i]][a[i]] = c[i];
	}
	
	rep(k,N){
		rep(i,N){
			rep(j,N){
				chmin(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
	int res = 0;
	for (int i = 0; i < M; i++){
		if(c[i] > dist[a[i]][b[i]]) ++res;
	}
	cout << res << endl;
}


Measured memory_bytes: 3656
#include<stdio.h>
#pragma GCC optimize("Os")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,N) for(int i=0;i<(int)N;i++)
const int MOD=1e9+7,MAX=1e6;
int A[10000];
static inline char CH()
{
  static char buf[100000],*ptr1=buf,*ptr2=buf;
  return ptr1==ptr2&&(ptr2=(ptr1=buf)+fread(buf,1,100000,stdin),ptr1==ptr2)?EOF:*ptr1++;
}
static inline int IN(void)
{
  int x=0,f=0,c=CH();while(c<48||c>57){f^=c==45,c=CH();}
  while(c>47&&c<58){x=x*10+c-48,c=CH();}return f?-x:x;
}
typedef struct{int SPF[1000001];int Primes[168];int sz;}Template;
Template P;
static inline int MPow(int a,int b){return b?1l*MPow(1l*a*a%MOD,b>>1)*(b&1?a:1)%MOD:1;}
static inline void ready(void)
{
  *P.SPF=1,*P.Primes=2,P.sz=1;
  rep(i,MAX/2)P.SPF[2*(i+1)]=2,P.SPF[2*(i+1)-1]=2*(i+1)-1;
  rep(i,MAX/2-1)
  {
    int x=2*(i+1)+1;if(P.SPF[x]==x){P.Primes[P.sz++]=x;}if(x*x>MAX)break;
    rep(j,P.sz){if(P.Primes[j]<=P.SPF[x]&&x*P.Primes[j]<=MAX)P.SPF[x*P.Primes[j]]=P.Primes[j];else break;}
  }
}
static inline int count(const int prime,const int sz)
{
  int max=0;rep(i,sz){int now=0;while(A[i]%prime==0){now++;A[i]/=prime;}if(max<now)max=now;}return max;
}
int main(void)
{
  int N=IN(),x=0;ready();
  rep(i,N){A[i]=IN();x=(x+1l*MPow(A[i],MOD-2))%MOD;}
  rep(i,168)x=1l*x*MPow(P.Primes[i],count(P.Primes[i],N))%MOD;
  rep(i,N){if(A[i]>1){rep(j,N-1-i){if(A[i]==A[i+j+1]){A[i+j+1]=1;}}x=1l*x*A[i]%MOD;}}
  return printf("%d\n",x),0;
}

Measured memory_bytes: 5604
import sys
def input(): return sys.stdin.readline().rstrip()
class UnionFind():
    def __init__(self, n):
        self.n=n
        self.parents=[-1]*n # 親(uf.find()で経路圧縮して根)の番号。根の場合は-(そのグループの要素数)
    def find(self,x):
        #グループの根を返す
        if self.parents[x]<0:return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]
    def unite(self,x,y):
        #要素x,yのグループを併合
        x,y=self.find(x),self.find(y)
        if x==y:return
        if self.parents[x]>self.parents[y]:#要素数の大きい方をxに
            x,y=y,x
        self.parents[x]+=self.parents[y]
        self.parents[y]=x #要素数が大きい方に併合
    def size(self,x):
        #xが属するグループの要素数
        return -self.parents[self.find(x)]
    def same(self,x,y):
        #xとyが同じグループ？
        return self.find(x)==self.find(y)
    def members(self,x):
        #xと同じグループに属する要素のリスト
        root=self.find(x)
        return [i for i in range(self.n) if self.find(i)==root]
        
def main():
    n,m,k=map(int,input().split())
    AB=[tuple(map(int,input().split())) for i in range(m)]
    CD=[tuple(map(int,input().split())) for i in range(k)]
    un=UnionFind(n)
    friend=[[] for _ in range(n)]
    for a,b in AB:
        un.unite(a-1,b-1)
        friend[a-1].append(b-1)
        friend[b-1].append(a-1)
    blockc=[0]*n
    for c,d in CD:
        if un.same(c-1,d-1):
            blockc[c-1]+=1
            blockc[d-1]+=1
    for i in range(n):
        print(un.size(i)-1-blockc[i]-len(friend[i]))
 
if __name__=='__main__':
    main()

Measured memory_bytes: 123740
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))

def main():
    a, b, k = MII()
    if b-a <= k:
        for i in range(a, b+1): print(i)
    else:
        n = []
        for i in range(a, a+k): n.append(i)
        for i in reversed(range(b-k+1, b+1)): n.append(i)
        n = sorted(list(set(n)))
        for i in n: print(i)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

int N;
vector<ll> A;

int main() {
	cin>>N;
	A.resize(N);
	rep(i,N) cin>>A[i];
	vector<ll> plus,minus;
	rep(i,N){
		if(A[i]>=0) plus.push_back(A[i]);
		else minus.push_back(A[i]);
	}
	sort(all(plus),greater<ll>());
	sort(all(minus));
	if(minus.empty()) minus.push_back(plus.back()), plus.pop_back();
	if(plus.empty()) plus.push_back(minus.back()), minus.pop_back();

	vector<pair<ll,ll>> res;
	ll cur=minus[0];
	for(int i=0;i+1<plus.size();i++){
		res.push_back({cur,plus[i]});
		cur-=plus[i];
	}
	res.push_back({plus.back(),cur});
	cur=plus.back()-cur;

	for(int i=1;i<minus.size();i++){
		res.push_back({cur,minus[i]});
		cur-=minus[i];
	}
	cout<<cur<<endl;
	for(auto p : res) cout<<p.first<<" "<<p.second<<endl;
}

Measured memory_bytes: 5872
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/rope"
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
mt19937 rng(high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rngll(high_resolution_clock::now().time_since_epoch().count());
#define lambdify(x) [&](auto &&...args){ return x(forward<decltype(args)>(args)...); }
template<typename T, typename U> T &ctmax(T &x, const U &y){ return x = max<T>(x, y); }
template<typename T, typename U> T &ctmin(T &x, const U &y){ return x = min<T>(x, y); }
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



int main(){
	cin.tie(0)->sync_with_stdio(0);
	int n;
	cin >> n;
	vector<array<int, 2>> a(n + 1);
	for(auto i = 1; i <= n; ++ i){
		for(auto j = 0; j < 2; ++ j){
			cin >> a[i][j];
		}
	}
	const int h = 10, mx = 1e5;
	vector<vector<long long>> dp(1 << h, vector<long long>(mx + 1));
	for(auto u = 1; u < min(1 << h, n + 1); ++ u){
		int p = u >> 1;
		dp[u] = dp[p];
		for(auto x = a[u][1]; x <= mx; ++ x){
			ctmax(dp[u][x], max(dp[u][x - 1], dp[p][x - a[u][1]] + a[u][0]));
		}
	}
	int qq;
	cin >> qq;
	while(qq --){
		int u, x;
		cin >> u >> x;
		if(__lg(u) < h){
			cout << dp[u][x] << "\n";
		}
		else{
			int d = __lg(u) - h + 1;
			long long res = dp[u >> d][x], sv = 0, sw = 0;
			for(auto mask = 1; mask < 1 << d; ++ mask){
				for(auto bit = 0; bit < d; ++ bit){
					if(mask & 1 << bit){
						sv += a[u >> bit][0];
						sw += a[u >> bit][1];
						break;
					}
					else{
						sv -= a[u >> bit][0];
						sw -= a[u >> bit][1];
					}
				}
				if(sw <= x) ctmax(res, dp[u >> d][x - sw] + sv);
			}
			cout << res << "\n";
		}
	}
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 808916
#include<bits/stdc++.h>          
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define mk_p(a,b)	make_pair((a),(b))
#define fixed(n) fixed<<setprecision((n))
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr long long MOD = 1000000007;

int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

vector<int> a(30);
vector<int> b(30);
vector<int> c(30);

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	rep(i,n){
		cin >> a[i];
	}
	reps(i,n){
		cin >> b[i];
	}
	int sum = 0;
	reps(i,n-1){
		cin >> c[i];
	}
	rep(i,n){
		sum += b[a[i]];
		if(i != 0 && a[i] - a[i-1] == 1) sum += c[a[i-1]];
	}
	cout << sum << '\n';
	return 0;
}


Measured memory_bytes: 256
n = int(input())
A = list(map(int,input().split()))

b = 1
B=[0]*(n+1)
count = 0

t=len(A)-1
for i in range(t):
    B[i] = b
    if 2*(b - A[i]) < A[i+1]:
        count += 1
        break
    b = 2*(b - A[i])
B[n] = b

if n == 0 and A[0] > 1:
    count += 1

j = 0
while count == 0 and A[t] > B[j]:
    if j == n:
        break
    j += 1

total = 0
for i in range(j):
    total += B[i]

s = A[t]
for i in range(t-1,j-1,-1):
    total += min(B[i],s+A[i])
    s+=A[i]

if count==0:
    print(total+A[t])
else:
    print('-1')

Measured memory_bytes: 674388
#include<bits/stdc++.h>
using namespace std;
int main (){
  int a,b;
  cin >> a >> b;
  if(a%3 == 0||b%3==0||(a+b)%3==0){
    cout<<"Possible"<<endl;
  }else{
    cout<<"Impossible"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
use text_io::*;
use std::process::exit;
use im_rc::HashMap;

fn main(){
    let mut n:isize = read!();
    let mut map= HashMap::new();
    let mut sum:usize = 0;
    for i in 0..n {
        let mut s:String = read!();
        let mut t: &i32 = map.get(&s).unwrap_or(&0);
        let mut o: &i32 = &0;
        if t == o {
            map.insert(String::from(s),1);
            sum += 1;
        }
    }
    println!("{}",sum);
}

Measured memory_bytes: 73324
# coding: utf-8

# 標準入力 <int>
N = int(input())

# 標準入力 <int> list[]
P = list(map(int, input().split()))

count = 0
comp = 2 * (10**5)

for i in range(N):
    if comp >= P[i]:
        count += 1
        comp = P[i]

print(count)


Measured memory_bytes: 24744
package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {

	body, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		log.Println(err)
	}
	scanner := bufio.NewScanner(strings.NewReader(string(body)))
	scanner.Split(bufio.ScanWords)
	if err := scanner.Err(); err != nil {
		fmt.Fprintln(os.Stderr, "reading input:", err)
	}
	inputs := make([]int, 0)
	for scanner.Scan() {
		word, _ := strconv.Atoi(scanner.Text())
		inputs = append(inputs, word)
	}

	alice := make([]int, 0, 100)
	bob := make([]int, 0, 100)

	cards := inputs[1:]
	sort.Sort(sort.Reverse(sort.IntSlice(cards)))
	turn := 1
	for i := 0; i < len(cards); i++ {
		if turn%2 == 1 {
			alice = append(alice, cards[i])
		} else {
			bob = append(bob, cards[i])
		}
		turn++
	}

	aliceSum := 0
	for _, i := range alice {
		aliceSum = aliceSum + i
	}
	bobSum := 0
	for _, i := range bob {
		bobSum = bobSum + i
	}

	fmt.Println(aliceSum - bobSum)
}


Measured memory_bytes: 640
s = str(input())

if s == "SUN":
	print(7)
elif s == "MON":
	print(6)
elif s == "TUE":
	print(5)
elif s == "WED":
	print(4)
elif s == "THU":
	print(3)
elif s == "FRI":
	print(2)
elif s == "SAT":
	print(1)

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
    public void solve(BufferedReader stdin, PrintWriter stdout) throws NumberFormatException, IOException {
        String s = stdin.readLine();
        if (s.equals("SUN")) stdout.println(7);
        if (s.equals("MON")) stdout.println(6);
        if (s.equals("TUE")) stdout.println(5);
        if (s.equals("WED")) stdout.println(4);
        if (s.equals("THU")) stdout.println(3);
        if (s.equals("FRI")) stdout.println(2);
        if (s.equals("SAT")) stdout.println(1);
    }


    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter stdout = new PrintWriter(System.out, false);
        new Main().solve(stdin, stdout);
        stdout.flush();
    }
}


Measured memory_bytes: 23380
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let k: usize = read();
    let array = [
        1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4,
        1, 51,
    ];

    println!("{}", array[k - 1]);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  long long int n,k,h[200005],i,ans;
  cin >> n >>k;
  for(i=0;i<n;i++){
    cin >> h[i];
  }
  sort(h,h+n,greater<int>());
  for(i=k;i<n;i++){
    ans=ans+h[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)

int main(){
	int d[101][101];
	rep(i,101)rep(j,101)d[i][j] = INF;
	rep(i,101)d[i][i]=0;
	int v,e;
	cin>>v>>e;
	rep(i,e){
		int s,t;
		cin>>s>>t;
		d[s][t] = -1;
	}
	rep(k,v)rep(i,v)rep(j,v)d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
	
	bool f=false;
	rep(i,v){
		if(d[i][i]<0)f=true;
	}
	cout<<f<<endl;
}

Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int N = 1e5 + 7;

int n, m;
int x[N], y[N];

int fix(int a)
{
	if (a < 0)
		a += MOD;
	if (a >= MOD)
		a -= MOD;
	return a;
}

int main()
{
	ios::sync_with_stdio(false);

	cin >> n >> m;
	for (int i=0; i<n; i++)
		cin >> x[i];
	for (int i=0; i<m; i++)
		cin >> y[i];
	sort(x, x+n);
	sort(y, y+m);
	ll sum = 0, SUM = 0;
	for (int i=0; i<m; i++)
		sum = (sum + 1LL * fix(-y[i]) * (m - 1 - i) + 1LL * fix(y[i]) * i) % MOD;
	for (int i=0; i<n; i++)
		SUM = (SUM + 1LL * fix(-x[i]) * (n - 1 - i) + 1LL * fix(x[i]) * i) % MOD;
	cout << 1LL * sum * SUM % MOD << "\n";

	return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int n;
    string s;
    cin >> n >> s;
    string s1 = s, s2 = s;
    vector<int> c1(n + 1), c2(n + 1);
    for(int i = 1; i < n + 1; i++){
        if(s[i - 1] == '.'){
            c1[i]++;
        }else{
            c2[i]++;
        }
    }
    partial_sum(begin(c1), end(c1), begin(c1));
    partial_sum(begin(c2), end(c2), begin(c2));
    int ans = INF;
    for(int i = 0; i < n; i++){
        ans = min(ans, c2[i] + c1[n] - c1[i + 1]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2308
#pragma clang diagnostic push
#pragma ide diagnostic ignored "cert-err34-c"
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

int main() {
    int n, W;
    scanf("%d%d", &n, &W);
    vector<ll> dp(W + 1); // 0 ... W

    // dp[i] - the maximum total value of items with total weight exactly i
    for (int item = 0; item < n; ++item) {
        int weight, value;
        scanf("%d%d", &weight, &value);

        // dp[0] -> dp[3] -> dp[6]
        for (int weight_already = W - weight; weight_already >= 0; --weight_already) {

//        for(int weight_already = 0; weight_already <= W - weight; ++weight_already) {
            dp[weight_already + weight] = max(dp[weight_already + weight], dp[weight_already] + value);
        }
    }
    cout <<dp[W];
}
#pragma clang diagnostic pop

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


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

int main()
{
	ll a,b,x;
	cin >> a >> b >> x;
	if (a != 0)
	{
		cout << b/x - (a-1)/x << endl;
	}
	else
	{
		cout << b/x + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256