akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
 using namespace std;
 
 // #define  int           long long
 #define pb                push_back
 #define ppb               pop_back
 #define pf                push_front
 #define ppf               pop_front
 #define all(x)            (x).begin(),(x).end()
 #define uniq(v)           (v).erase(unique(all(v)),(v).end())
 #define sz(x)             (int)((x).size())
 #define fr                first
 #define sc                second
 #define pint              pair<int,int>
 #define rep(i,a,b)        for(int i=a;i<b;i++)
 #define mem1(a)           memset(a,-1,sizeof(a))
 #define mem0(a)           memset(a,0,sizeof(a))
 #define ppc               __builtin_popcount
 #define ppcll             __builtin_popcountll
 #define vint			   vector<int>
 #define vpint			   vector<pair<int,int>>
 #define mp                make_pair


 void reader() 
 { 
 #ifndef ONLINE_JUDGE 
 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout); 
 #endif
 }
 
 void fastIO() {ios_base::sync_with_stdio(false); cin.tie(NULL);}
 
 
 
 void solve()
 {
 string s;
 cin>>s;
 int n=s.length();
 if(s[n-1]=='s')
 {
 	s.push_back('e');
 	s.push_back('s');
 	cout<<s;
 }
 else
 {
 	s.push_back('s');
 	cout<<s;
 }
 
 
 
 cout<<"\n";
 }
 
 
 
 signed main()
 {
 	reader(); fastIO();
 	long long t=1;
 	//cin>>t;
 	while(t--) solve();
 	return 0;
 }

Measured memory_bytes: 3656
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 13 02:01:40 2020

@author: liang
"""

N = int(input())
A = list()
T = [list() for i in range(N)]

#データ挿入
for i in range(N):
    a = int(input())
    A.append(a)
    for a in range(a):
        x, y = map(int,input().split())
        x -= 1 #配列のインデックスに対応
        T[i].append((x,y))
ans = 0
#bit全探索
for i in range(2**N):
    #正直者のインデックスを格納
    persons = list()
    for j in range(N):
        if i>>j&1 == 1:
            persons.append(j)
    #正直者　= True
    d = [False]*N
    for p in persons:
        d[p] = True 

    judged = [False]*N
    #全ての人に対してループ
    for num in range(N):
        #正直者のみ採用
        f = False
        if d[num]:
            for t in T[num]:
                x, y = t[0], t[1]
                #dのテーブルを更新
                if y == 1 and d[x] != True:
                    f = True
                    break
                if y == 0 and d[x] != False:
                    f = True
                    break
        if f:
            break
    else:
        #print(d)
        ans = max(ans, len(persons))
print(ans)
    

Measured memory_bytes: 9120
from itertools import accumulate

N = int(input())
A = list(map(int, input().split()))
A_cumsum = list(accumulate(A))
ans = 0
for i in range(N-1):
    S = (A_cumsum[-1]-A_cumsum[i])%(10**9+7)
    ans += A[i]*S
    ans %= 10**9+7
print(ans)

Measured memory_bytes: 102180
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;

int main(void){
	int a, b, c, k;
	cin >> a >> b >> c;
	cin >> k;

	while(b <= a){
		b *= 2;
		k--;
	}
	while(c <= b){
		c *= 2;
		k--;
	}
	if(k < 0){
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define ALL(a) (a).begin(),(a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;
typedef vector<vector<ll>> Graph;
typedef vector<pii> vpii;

int main() {
    ll N; cin>>N;
    vi A(N); REP(i,N) cin>>A[i];
    ll x=0;
    ll ans=0;
    REP(i,N) {
      if(A[i]==0) {
        ans+=x/2;
        x=0;
      }
      x+=A[i];
    }
    ans+=x/2;
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
a,s=map(int,input().split())
def c(d,f):
  if d==0:return f
  else:return c(f%d,d)
  
j=c(a,s)
if j==1:print(1);exit()
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

print(len(factorization(j))+1)

Measured memory_bytes: 3064
N = int(input())
S = input()
black_cnt = 0
white_cnt = 0
for i in range(N):
    if S[i] == '#':
        black_cnt += 1
    else:
        white_cnt += 1
ans = min(black_cnt, white_cnt)
tmp_ans = white_cnt
for i in range(N):
    if S[i] == '#':
        tmp_ans += 1
    else:
        tmp_ans -= 1
    ans = min(ans, tmp_ans)
print(ans)

Measured memory_bytes: 9416
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const int Hmax = 100;
int H, W;
string A[Hmax];

const ll INF = 1e18;

struct edge {
	int to, rev; // destination, index for reversed edge
	ll cap; // capacity
};

class FlowGraph{
	vector<vector<edge> > graph;
	ll dfs(int v, int t, ll f, vector<bool> &used){
		if(v == t) return f;
		used[v] = true;
		for(int i=0; i<graph[v].size(); i++){
			edge &e = graph[v][i];
			if(!used[e.to] && e.cap > 0){
				ll d = dfs(e.to, t, min(e.cap, f), used);
				if(d>0){
					e.cap -= d;
					graph[e.to][e.rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}

	public:
	FlowGraph(int n_vertex){
		graph = vector<vector<edge> >(n_vertex);
	}

	void add_edge(int from, int to, ll cap){
		graph[from].push_back((edge){to, (int)graph[to].size(), cap});
		graph[to].push_back((edge){from, (int)graph[from].size()-1, 0});
	}

	unsigned int size(){
		return graph.size();
	}

	ll max_flow(int s, int t){
		ll flow = 0;
		while(true){
			vector<bool> used(size(), false);
			ll f = dfs(s, t, INF, used);
			if(f==0) return flow;
			flow += f;
		}
	}

};

int main(){
	cin >> H >> W;
	for(int i=0; i<H; i++) cin >> A[i];

	FlowGraph flow(2*H*W+H+W);

	int s, t;
	for(int x=0; x<H; x++){
		for(int y=0; y<W; y++){
			if(A[x][y]=='.') continue;
			if(A[x][y]=='S') s = y*H+x;
			if(A[x][y]=='T') t = y*H+x;
			flow.add_edge(y*H+x+H*W, y*H+x, 1);
			//cout << y*H+x+H*W << " " <<  y*H+x << endl;

			flow.add_edge(y*H+x, 2*H*W+x, INF);
			flow.add_edge(y*H+x, 2*H*W+H+y, INF);
			//cout << y*H+x << " " << 2*H*W+x << endl;
			//cout << y*H+x << " " << 2*H*W+H+y << endl;

			flow.add_edge(2*H*W+x, y*H+x+H*W, INF);
			flow.add_edge(2*H*W+H+y, y*H+x+H*W, INF);
			//cout << 2*H*W+x << " " << y*H+x+H*W << endl;
			//cout << 2*H*W+H+y << " " << y*H+x+H*W << endl;
		}
	}

	//cout << s << " " <<  t+H*W << endl;
	if(s/H==t/H || s%H==t%H) cout << -1 << endl;
	else cout << flow.max_flow(s, t+H*W) << endl;

	return 0;
}


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

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

typedef long long int ll;

//const ll INF=(ll)1e18;
const int INF=(1<<30);

int main(){
  int N;
  cin >> N;
  vector<int> a(N),b(N),c(N);
  REP(i,N){
    cin >> a[i] >> b[i] >> c[i];
  }

  vector<int> dp(3,0);

  REP(i,N){
    int s,t,u;
    s = max(dp[1]+a[i], dp[2]+a[i]);
    t = max(dp[0]+b[i], dp[2]+b[i]);
    u = max(dp[0]+c[i], dp[1]+c[i]);
    dp[0]=s;dp[1]=t;dp[2]=u;
  }

  cout << max(dp[0],max(dp[1],dp[2])) << endl;
}



Measured memory_bytes: 1408
#include <iostream>
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

const int UNDEFINED = -1;

struct Node {
    Node() : color(UNDEFINED) {}
    vector<pair<int, int>> to;
    int color;
};

vector<Node> nodes;

void dfs(int curr, int from, int col)
{
    if (nodes[curr].color == UNDEFINED) {
        nodes[curr].color = col;
        for (auto next: nodes[curr].to) {
            if (next.first != from) {
                int nextCol = (col + next.second % 2) % 2;
                dfs(next.first, curr, nextCol);
            }
        }        
    }
}


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

    nodes.resize(N);
    rep(i, N-1) {
        int u, v, w;
        cin >> u >> v >> w;
        --u;
        --v;
        nodes[u].to.push_back({v, w});
        nodes[v].to.push_back({u, w});
    }

    dfs(0, -1, 0);
    rep(i, N) {
        cout << nodes[i].color << endl;
    }

    return 0;
}


Measured memory_bytes: 8576
#pragma GCC optimize(3)
#include <stdio.h>
__attribute__((always_inline)) __inline__
long long max(long long x,long long y) {
	return ((y-x>>64-1)&(x^y))^y;
}
int n,a[17][17];
long long f[1<<17],g[1<<17];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;++i)
		for (int j=1;j<=n;++j) scanf("%d",a[i]+j);
	for (int i=0;i<(1<<n);++i)
		for (int j=1;j<=n;j++) if (i&(1<<j-1))
			for (int k=1;k<=n;k++) if (i&(1<<k-1)) f[i]+=a[j][k];
	for (int i=0;i<(1<<n);++i) g[i]=f[i];
	for (int i=0;i<(1<<n);++i)
		for (int j=i&i-1;j;j=i&j-1)
			g[i]=max(g[i],g[i^j]+f[j]);
	printf("%lld\n",g[(1<<n)-1]>>1);
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'

int main(){
	int n, k;
	cin >> n >> k;
	int arr[n];
	for(int& i : arr) cin >> i;
	int DP[n];
	DP[n-1] = 0;
	for(int i = n-2; i >=0; --i){
		int mincost = INT_MAX;
		for(int j = i+1; j <= i+k && j < n; ++j){
			mincost = min(mincost, abs(arr[i] - arr[j]) + DP[j]);
		}
		DP[i] = mincost;
	}
	cout << DP[0] << endl;	
}

Measured memory_bytes: 4412
#include <string>
#include <vector>
#include <map>
#include <deque>
#include <iostream>
#include <queue>
#include <math.h>
#include <algorithm>
#include <fstream>

using namespace std;
typedef long long ll;


int main(void) {
	int n,c=0;
	cin >> n;
	vector<int>h(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	int tmp, max = 0;
	for (int i = 0; i < n-1; i++) {
		if (h[i] >= h[i + 1]) {
			c++;
		}
		else {
			if (max < c) {
				max = c;
			}
			c = 0;
		}
	}
	if (max < c) {
		max = c;
	}
	cout << max;
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(void){
 int N,A,B,i,num1,dig,sum1=0,sum2;
 scanf("%d",&N);
 scanf("%d",&A);
 scanf("%d",&B);
 for(i=1;i<=N;i++){
 num1=i;
 sum2=0;
 while(num1!=0){
  dig=num1%10;
 sum2=sum2+dig;
  num1=num1/10;
}
  if((A<=sum2)&&(sum2<=B)) sum1+=i;
 }
 printf("%d",sum1);
 return 0;
} 

Measured memory_bytes: 128
#include <iostream>
#include <string>
using namespace std;
int main()
{
  int n;
  string s;
  cin >> n;
  cin >> s;
  string substr = s.substr(0,n/2);
  if ((n % 2) == 0 && substr == s.substr(n/2,n/2))
  {
    cout << "Yes";
  }
  else
  {
    cout << "No";
  }
  
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		if(n<=111) {
			System.out.println(111);
		}else if(n<=222){
			System.out.println(222);
		}else if(n<=333){
			System.out.println(333);
		}else if(n<=444){
			System.out.println(444);
		}else if(n<=555){
			System.out.println(555);
		}else if(n<=666){
			System.out.println(666);
		}else if(n<=777){
			System.out.println(777);
		}else if(n<=888){
			System.out.println(888);
		}else if(n<=999){
			System.out.println(999);
		}
	}
}




Measured memory_bytes: 23252
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    string s;
    cin >> s;
    for( int i = 1; i < s.size() - 1; ++i ) {
        set< char > st;
        st.insert( s[i - 1] );
        st.insert( s[i] );
        st.insert( s[i + 1] );
        if( st.size() != 3 ) {
            cout << i << " " << i + 2 << endl;
            return 0;

        }
    }

    if( s.size() == 2 && s[0] == s[1] ) {
        cout << 1 << " " << 2 << endl;

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

    }
    return 0;
}



Measured memory_bytes: 512
h,w=map(int,input().split())
c=[list(map(int,input().split())) for _ in range(10)]
a=[list(map(int,input().split())) for _ in range(h)]
INF=10**18
for k in range(10):
  for i in range(10):
    if c[i][k] == INF:
      continue
    for j in range(10):
      if c[k][j] == INF:
        continue
      c[i][j] = min(c[i][j], c[i][k] + c[k][j])
ans=0
for i in a:
  for k in i:
    if k!=-1:
      ans+=c[k][1]
print(ans)

Measured memory_bytes: 68100
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

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

using namespace std;

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

 main()

{
    fast
    string s;
    cin>>s;
    int sz=s.size();
    for(int i=0;i<sz;i++)
    {
        if(s[i]=='?')s[i]='D';
    }
    cout<<s<<endl;
    return 0;

}





































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

using namespace std;

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

    int score[2] = {0};
    for (int q = 0; q < N; ++q) {
        string S[2];
        for (int i = 0; i < 2; ++i) {
            cin >> S[i];
        }

        if (S[0] > S[1]) {
            score[0] += 3;
        } else if (S[0] == S[1]) {
            score[0]++;
            score[1]++;
        } else {
            score[1] += 3;
        }
    }

    cout << score[0] << " " << score[1] << endl;
    return 0;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  while (true) {
    int n; cin >> n;
    if (n == 0) break;
    V<> a(n), b(n); for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];
    int sa = 0, sb = 0;
    for (int i = 0; i < n; ++i) {
      if (a[i] == b[i]) {
        sa += a[i];
        sb += b[i];
      } else {
        (a[i] > b[i] ? sa : sb) += a[i] + b[i];
      }
    }
    cout << sa << ' ' << sb << '\n';
  }
}


Measured memory_bytes: 3192
//by kcz 1552920354@qq.com
//if you find any bug in my code
//please tell me
#include<bits/stdc++.h>
using namespace std;

template <typename T> void chmin(T &x,const T &y)
{
	if(x>y)x=y;
}
template <typename T> void chmax(T &x,const T &y)
{
	if(x<y)x=y;
}
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define pb push_back
#define mp make_pair
#define gc (c=getchar())
char readc()
{
	char c;
	while(gc<'-');
	return c;
}
int read()
{
    char c;
    while(gc<'-');
    if(c=='-')
    {
        int x=gc-'0';
        while(gc>='0')x=x*10+c-'0';
        return -x;
    }
    int x=c-'0';
    while(gc>='0')x=x*10+c-'0';
    return x;
}
#undef gc

const int N=100+5;
int a[N],cnt[N];
int n,L,L2;

ll ans;
void dfs(int x,ll s)
{
	if(x>L)
	{
		rep(i,L+1,L2)
		if(!cnt[i])
		{
			if(!cnt[i*2])
			{
				if(a[i]+a[i*2]<0)s-=a[i]+a[i*2];
			}
			else
			{
				if(a[i]<0)s-=a[i];
			}
		}
		chmax(ans,s);
		return ;
	}
	dfs(x+1,s);
	if(cnt[x])return ;
	for(int y=x;y<=n;y+=x)
	if(++cnt[y]==1)s-=a[y];
	dfs(x+1,s);
	for(int y=x;y<=n;y+=x)--cnt[y];
}

int main()
{
	//freopen("1.in","r",stdin);//freopen("1.out","w",stdout);
	cin>>n;
	rep(i,1,n)cin>>a[i];
	n=100;
	L=n/3;L2=n/2;
	rep(i,L2+1,n)
	if(a[i]<0)a[i]=0;
	
	ll s=0;
	rep(i,1,n)s+=a[i];
	ans=s;
	dfs(1,s);
	cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int d[] = new int[N];
		for(int i = 0; i < N; i++) {
			d[i] = sc.nextInt();
		}
		
		long ans = 0;
		for(int i = 0; i < N; i++) {
			for(int j = i + 1; j < N; j++){
				ans += d[i] * d[j];
			}
		}
		
		System.out.println(ans);
	}
}


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

static const int MAX = 300005;
int N, l[MAX], r[MAX];

int main() {
  string S;

  cin >> N >> S;

  l[0] = 0;
  for (int i = 1; i < N; i++) {
    if (S[i - 1] == 'W') {
      l[i] = l[i - 1] + 1;
    } else {
      l[i] = l[i - 1];
    }
  }

  r[N - 1] = 0;
  for (int i = N - 2; i >= 0; i--) {
    if (S[i + 1] == 'E') {
      r[i] = r[i + 1] + 1;
    } else {
      r[i] = r[i + 1];
    }
  }

  int ans = MAX;
  rep(i, N) {
    ans = min(ans, l[i] + r[i]);
  }

  cout << ans << endl;

  return 0;

}

Measured memory_bytes: 3076
s = gets.chomp
if ((s.include?("W") && s.include?("E")) || (!(s.include?("W")) && !(s.include?("E")))) && ((s.include?("N") && s.include?("S")) || (!(s.include?("N")) && !(s.include?("S"))))
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 3836
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

# 各queryについてO(n)で答える
# 問題を言い換えると　　

# 地点Xに到着するのは時間 Di + Xの時
# S <= Di + X < Tとなる[S, T, N]がなければ通過できる
# SについてXの早い順にソートする

# 各Dについて、どのSまで通過できるかを各O(1)で答える？

N,Q = getNM()
# taskに
# 0:通行止め時間帯のスタート
# 1:通行止め時間帯のゴール
# 2:人
# を入れ、全部まとめて処理する
task = []

STX = [getList() for _ in range(N)]
for s, t, x in STX:
    task.append((t - x, 0, x)) # xで止まらなくなる
    task.append((s - x, 1, x)) # xで止まる

for i in range(Q):
    d = getN()
    task.append((d, 2, i)) # 止まる位置を答える
answer = [-1] * Q

task.sort()

# 引っかかってる場所の管理
se = set()
se_hp = [] # heapで最小値を先頭に保つ
heapq.heapify(se_hp)

# 小さい時刻から順に見ていく
for a, b, c in task:
    # ゴール位置についての情報なら
    if b == 0:
        # とり除く
        se.remove(c)
    # スタートについての情報なら
    elif b == 1:
        se.add(c)
        heapq.heappush(se_hp, c)
    # 人についての情報なら
    else:
        # se_hpを抜き切るか、se_hpの最小値がseにある場合はエンド
        while se_hp and se_hp[0] not in se:
            heapq.heappop(se_hp)
        if se_hp:
            answer[c] = se_hp[0]
        else:
            answer[c] = -1

for i in answer:
    print(i)

Measured memory_bytes: 214552
#include <bits/stdc++.h>
#define mod 26
#define S str[i]
using namespace std;
string str;
 
string solve(){
  string res;
  stack <int> st;
  for(int i=0;i<str.size();i++){
    int cnt=0;
    while(S=='+'||S=='-')cnt+=(S=='+')-(S=='-'),i++;
    
    if(cnt) res+=((S-'A')+cnt%mod+mod)%mod+'A';
    else if(S!='['&&S!=']')res += S;
    if(S=='?')res.back()='A';
    if(S=='[')st.push(res.size());
    if(S==']')reverse(res.begin()+st.top(),res.end()),st.pop();
  }
  return res;
}
 
int main(){
  while(cin>>str&&str!=".")cout <<solve()<<endl;
  return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using namespace std;
typedef long long ll;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;

#define INCANT cin.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define out(a) cout << a << endl
#define PRINT(V) for (auto v : (V)) cout << v << " "

const int MOD = 1000000007;
const double PI = acos(-1.0);

void solve() {
    int N;
    ll S = 0;
    cin >> N;
    map<int, int> A;
    rep(i, N){
        int a;
        cin >> a;
        A[a]++;
        S += a;
    }
    int Q;
    cin >> Q;
    rep(i, Q){
        int b, c;
        cin >> b >> c;
        S += (c-b)*A[b];
        out(S);
        A[c] += A[b];
        A[b] = 0;
    }
}
int main() {
    INCANT;
    solve();
    return 0;
}




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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

template<typename T> void  Asort(T * a, int n) { sort(a, a + n,    less<T>()); }
template<typename T> void RAsort(T * a, int n) { sort(a, a + n, greater<T>()); }

LL n, ans;
array<LL, 3> a[100000];

int main() {
	cin >> n;
	inc(i, n) { cin >> a[i][1] >> a[i][2]; a[i][0] = a[i][1] + a[i][2]; }
	RAsort(a, n);
	
	inc(i, n) {
		if(i % 2 == 0) { ans += a[i][1]; } else { ans -= a[i][2]; }
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

struct GSB{
    long B;
    long C;

    GSB(long B2, long C2)
    {
        B=B2;
        C=C2;
    }

    bool operator < (const GSB & another) const
    {
        return B < another.B;
    }
};

int main()
{
    long N,M;
    std::cin >> N >> M;
    std::vector<GSB> sc;
    for(long i=0; i<M; i++){
        long temp1,temp2;
        std::cin >> temp1 >> temp2;
        sc.push_back(GSB(temp1,temp2));
    }

    long R[3];
    for(long i=0; i<3; i++){
        R[i]=-1;
    }

    bool flag=0;
    for(long i=0; i<M; i++){
        if(R[sc[i].B-1]==-1){
            R[sc[i].B-1]=sc[i].C;
        }
        if(R[sc[i].B-1]!=sc[i].C){
            flag=1;
            break;
        }
    }

    for(long i=0; i<3; i++){
        if(R[i]==-1 && i!=0){
            R[i]=0;
        }
        if(R[i]==-1 && i==0){
            R[i]=1;
        }
    }
    if(flag==1){
        std::cout << -1 << std::endl;
    }else if(M==0 && N==1){
        std::cout << 0 << std::endl;
    }else if(M==0 && N==2){
        std::cout << 10 << std::endl;
    }else if(M==0 && N==3){
        std::cout << 100 << std::endl;
    }
    else if(R[0]==0 && N!=1){
       std::cout << -1 << std::endl; 
    }else{
        for(long i=0; i<N; i++){
            std::cout << R[i];
        }
        std::cout << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  if ((N/1000 == N/100 - (N/1000)*10 && N/100 - (N/1000)*10 == N/10 - (N/100)*10) || (N/100 - (N/1000)*10 == N/10 - (N/100)*10 && N/10 - (N/100)*10 == N - (N/10)*10)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

}

Measured memory_bytes: 3616
INF = 1 << 30
loop {
	n, m = gets.split.map(&:to_i)
	break if n == 0 && m == 0
	a = []
	b = []
	if n != 0
		a += gets.split.map(&:to_i)
	end
	if m != 0
		b += gets.split.map(&:to_i)
	end
	a += [INF]
	b += [INF]
	na = nb = tmp = ans = d = 0
	loop {
		if a[na] <= b[nb]
			break if a[na] == INF
			d = a[na] - tmp
			tmp = a[na]
			na += 1
		else
			d = b[nb] - tmp
			tmp = b[nb]
			nb += 1
		end
		ans = d if d > ans
	}
	p ans
}

Measured memory_bytes: 9880
n,w=map(int,input().split())
A=[list(map(int,input().split())) for i in range(n)]

dp=[float("inf")]*(10**5+1)
dp[0]=0
for i in range(n):
  for j in range(10**5,A[i][1]-1,-1):
    dp[j]=min(dp[j],dp[j-A[i][1]]+A[i][0])
ans=0
for v,e in enumerate(dp):
  if e<=w:
    ans=v
print(ans)


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

int R[4010],G[4010],B[4010];

signed main(void){ 
  int N; cin >> N;
  string S; cin >> S;
  for(int i = N-1; i >= 0; i--){ 
    if( S[i] == 'R' ){ R[i]++;}
    if( S[i] == 'G' ){ G[i]++;}
    if( S[i] == 'B' ){ B[i]++;}
    
    R[i] += R[i+1];
    G[i] += G[i+1]; 
    B[i] += B[i+1];
    
  }
  
  int ans = 0;
  
  for(int i = 0; i < N; i++){ 
    for(int j = i+1; j < N; j++){ 
      
      if( S[i] == 'R' ){ 
        if( S[j] == 'G' ){ ans += B[j+1]-(S[2*j-i] == 'B');}
        if( S[j] == 'B' ){ ans += G[j+1]-(S[2*j-i] == 'G');}
      }
      if( S[i] == 'G' ){ 
        if( S[j] == 'R' ){ ans += B[j+1]-(S[2*j-i] == 'B');}
        if( S[j] == 'B' ){ ans += R[j+1]-(S[2*j-i] == 'R');}
      }
      if( S[i] == 'B' ){ 
        if( S[j] == 'G' ){ ans += R[j+1]-(S[2*j-i] == 'R');}
        if( S[j] == 'R' ){ ans += G[j+1]-(S[2*j-i] == 'G');}
      }
    }
  }
  
  cout << ans << endl;
  
  return 0;
} 

Measured memory_bytes: 3700
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(in.readLine());
        BigDecimal a = new BigDecimal(st.nextToken());
        BigDecimal b = new BigDecimal(st.nextToken());
        BigDecimal mul = a.multiply(b);
        st = new StringTokenizer(mul.toString(), ".");
        System.out.println(st.nextElement());
    }
}


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

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

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  vi vec(3); rep(i, 3) std::cin >> vec[i];
  sort(rng(vec));
  int ans = vec[2] - vec[1];
  vec[0] += ans;
  int tmp = vec[2] - vec[0];
  if (tmp) {
    ans += (tmp + 1) / 2;
    if (tmp % 2) ans++;
  }
  std::cout << ans << "\n";
}


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

using namespace std;
#define ll long long
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
const ll mod = 1e9 + 7;

int main (){
    int n;
    cin >> n;
	char s;
  
    int mini = 1000000;
    int ce = 0;
    int cw = 0;
    int w[n] = {};
    for(int i = 1; i <= n; i++){
      cin >> s;
        if(s == 'W'){ //iばんめまでにwを向いている人数 これが累積和の書き方
            w[i] = w[i-1]+1;
        }else w[i] = w[i-1];
    }
    
    REPS(i,n){
        int left = w[i-1];
        int right = n-w[n] - i + w[i];
        int turn = left + right;
        mini = min(mini,turn);
    }

    cout << mini << endl;
    

    return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
//#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
//cerr
using namespace std;
int f1(int a, int p) {
	if (p == 1)return a;
	if (p % 2)return f1(a, p - 1)*a%mod;
	else {
		return f1(a*a%mod, p / 2) % mod;
	}
}
signed main() {
	int n, a, b; cin >> n >> a >> b;
	int ans = f1(2, n) - 1;
	int c = 1;
	for0(i, a) { c *= n - i; c %= mod; }
	for1(i, a) { c *= f1(i, mod - 2); c %= mod; }
	ans -= c;
	c = 1;
	for0(i, b) { c *= n - i; c %= mod; }
	for1(i, b) { c *= f1(i, mod - 2); c %= mod; }
	ans -= c; while (ans < 0)ans += mod;
	cout << ans<< endl;
}

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

using namespace std;

int gridA[2005][2005] ;
int gridB[2005][2005];

int main()
{
	
	int h, w;
	cin >> h >> w;
	for (int i = 0; i <2005; i++) {
		for (int j = 0; j < 2005; j++) {
			gridA[i][j] = 0;
			gridB[i][j] = 0;
		}
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			char c;
			cin >> c;
			if (c == '.') {
				gridA[i][j]++; 
				gridB[i][j]++;
			}
		}
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (gridA[i][j-1]>0&&gridA[i][j]==1) {
				gridA[i][j] = gridA[i][j - 1]+1;
			}
		}
		for (int j = w; j >= 1; j--) {
			if (gridA[i][j + 1] > 0 && gridA[i][j]>0) {
				gridA[i][j] = gridA[i][j+1];
			}
		}
	}
	for (int j = 1; j <= w; j++) {
		for (int i = 1; i <= h; i++) {
			if (gridB[i - 1][j] > 0 && gridB[i][j]==1) {
				gridB[i][j] = gridB[i -1][j]+1;
			}

		}
		for (int i = h; i >= 1; i--) {
			if (gridB[i+1][j] > 0 && gridB[i][j] > 0) {
				gridB[i][j] = gridB[i+1][j];
			}
		}
	}	
	int ans = 0;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			int t = gridA[i][j] + gridB[i][j] - 1;
			//cout << gridB[i][j];
			if (t>ans) {
				ans = t;
			}
		
		}	//cout << endl;
	}
	cout << ans << endl;


}

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

int main(){
int N;
  cin>>N;
  vector<int>p(N);
  int sum=0;
  for(int i=0; i<N; i++){
   cin>>p[i];
   sum+=p[i];
  }
  
int max=*max_element(p.begin(), p.end());
  cout<<sum-(max/2);
}


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

const int N=2008;

int m,n,q;
int a[N][N], r[N][N], c[N][N];
string s;
int main()
{	
	cin.sync_with_stdio(0);
	cin >> m >> n >> q;
	for (int i = 1; i <= m; i++)
	{
		cin >> s; 
		for (int j = 1; j <= n; j++) a[i][j] = s[j-1] - '0';
	}
	for (int i = 1; i <= m; i++)
		for (int j = 1; j <= n; j++)
		{
			if (a[i][j] && a[i - 1][j])			
			{
				r[i][j]++;
			} 
			if (a[i][j] && a[i][j - 1])
			{
				c[i][j]++;
			}
		}
	
	/*for (int i = 1; i <= m; i++)
	{
		for (int j = 1; j <= n; j++)
			cout << r[i][j] << " ";
		cout << endl;
	}
	cout << endl;*/
	for (int i = 1; i <= m; i++) 
		for (int j = 1; j <= n; j++)
		{
			c[i][j] = c[i][j - 1] + c[i][j];
			r[i][j] = r[i][j - 1] + r[i][j];
			a[i][j] = a[i][j - 1] + a[i][j];
		}	
	for (int i = 1; i <= m; i++)		
		for (int j = 1; j <= n; j++)
		{
			c[i][j] = c[i - 1][j] + c[i][j];
			r[i][j] = r[i - 1][j] + r[i][j];
			a[i][j] = a[i - 1][j] + a[i][j];
		}
	/*for (int i = 1; i <= m; i++)
	{
		for (int j = 1; j <= n; j++)
			cout << r[i][j] << " ";
		cout << endl;
	}
	cout << endl;*/
	for (int i = 0; i < q; i++)
	{
		int x1,y1,x2,y2;
		cin >> x1 >> y1 >> x2 >> y2;
		int ans = a[x2][y2] + a[x1 - 1][y1 - 1] - a[x1 - 1][y2]  - a[x2][y1 - 1];
		if (y1 < y2) ans -= c[x2][y2] + c[x1 - 1][y1] - c[x1 - 1][y2]  - c[x2][y1];
		if (x1 < x2) ans -= r[x2][y2] + r[x1][y1 - 1] - r[x1][y2] - r[x2][y1 - 1];
	   cout << ans << endl;	

	}
}

/*
3 4 1
1101
0110
1101
1 1 3 4

 */


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

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long a[] = new long[3*N];

		for (int i = 0; i < N*3; i++) {
			a[i] = sc.nextInt();
		}

		long sum = 0;

		Arrays.sort(a);

		for (int i = N; i < 3 * N; i++) {

			if (N%2 == 0) {
				if(i%2==0) {
					sum += a[i];
				}
			} else {
				if(i%2==1) {
					sum += a[i];
				}
			}
		}
		System.out.println(sum);
	}
}


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

int n, a[300000];

int main(){
  cin >> n;
  rep(i, n){
    cin >> a[i];
  }
  sort(a, a + n);
  
  string res = "YES";
  rep(i, n - 1){
    if(a[i] == a[i + 1]){
      res = "NO";
      break;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


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

    int N;
    cin >> N;
    int D[N];
    int cnt[24] = {};
    int rnd[240] = {};
    rep(i, N) cin >> D[i];
    rep(i, N) cnt[D[i]]++;
    cnt[0]++;

    // 同じ時差の人が3人以上なら s == 0
    rep(i, 24) {
        if (cnt[i] >= 3) {
            cout << "0" << endl;
            return 0;
        }
    }

    // 同じ時差の人が2人なら一人ずらす
    rep(i, 24) {
        if (cnt[0] >= 2) {
            cout << "0" << endl;
            return 0;
        }
        if (cnt[i] == 2) {
            cnt[i]--;
            cnt[24-i]++;
        }
    }

    int ANS = 0;
    rep(k, 2500) {
        int ans = 24;
        int A = 0, B = 0;
        int flag = 0;
        int tmp = 0;
        rep(i, 24) {
            flag = 0;
            if (cnt[i] != 0) A = i;
            for (int j = i+1; j < 24; j++){
                if (cnt[j] != 0) {
                    B = j;
                    //dump(B);
                    flag = 1;
                    break;
                }
            }
            if (flag == 1) {
                if ( ans >= abs(A-B)) {
                    ans = abs(A-B);
                    if (cnt[24-A] == 0) {
                        rnd[tmp++] = A;
                    }
                    if (cnt[24-B] == 0) {
                        rnd[tmp++] = B;
                    }
                    //cout << ans << endl; 
                }
            } else {
                B = 24;
                    if ( ans >= abs(A-B)) {
                    ans = abs(A-B);
                    if (cnt[24-A] == 0) {
                        rnd[tmp++] = A;
                    }
                    if (cnt[24-B] == 0) {
                        rnd[tmp++] = B;
                    }
                    //cout << ans << endl; 
                }
            }
            //dump(tmp);
        }
            rep(i, 24) {
        if ( cnt[i] != 0) {
            //cout << i << ":" << cnt[i] << endl; 
        }
    }
        ANS = max(ans, ANS);
        if (tmp >= 1) {
            int T = rand() % tmp;
            //dump(T);
            cnt[rnd[T]]--;
            cnt[24-rnd[T]]++;
        }
    }
    
    cout << ANS << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <cctype>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define dum(x) cout<<#x<<'='<<x<<endl
#define dum2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define dum3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf());

ll a[3300];

int main() {
    int N;
    cin >> N;
    rep(i, N)cin >> a[i];
    ll sum = 0;
    rep(i, N) {
        sum += a[i]-1;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N,A,B = inpl()

if A > B:
	print(0)
else:
	if N == 1:
		if A == B:
			print(1)
		else:
			print(0)
	elif N == 2:
		print(1)
	else:
		print((B-A)*(N-2)+1)


Measured memory_bytes: 4592
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif
vector<int> Zalgo(string s){
	int N = s.size();
	vector<int> Z(N);
	Z[0] = N;
	int i = 1, j = 0;
	while(i<N){
		while(i+j<N && s[j]==s[i+j]) ++j;
		Z[i] = j;
		if(j==0){
			++i;
			continue;
		}
		int k = 1;
		while(i+k<N && k+Z[k]<j) Z[i+k]=Z[k],++k;
		i += k, j -= k;
	}
	return Z;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	string s,t;
	cin >> s >> t;
	int N = s.size(), M = t.size();
	while(s.size() < N+M) s = s+s;
	V<int> to(N,-1);
	{
		string f = t + "$" + s;
		auto v = Zalgo(f);
		rep(i,N){
			bool match = v[M+1+i] >= M;
			if(match) to[i] = (i+M)%N;
		}
	}
	V<int> memo(N,-1);
	function<int(int)> dfs = [&](int v){
		if(memo[v] == -2){
			cout << -1 << endl;
			exit(0);
		}
		if(memo[v] != -1) return memo[v];
		if(to[v] == -1) return memo[v] = 0;
		memo[v] = -2;
		return memo[v] = dfs(to[v]) + 1;
	};
	int ans = 0;
	rep(i,N) chmax(ans,dfs(i));
	cout << ans << endl;
}


Measured memory_bytes: 22300
#include "bits/stdc++.h"

using namespace std;
using LL = long long;

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

    int n;
    cin >> n;
    vector< int> A(n), B(n), C(n - 1);
    for (int i = 0; i < n; i ++) cin >> A[i];
    for (int i = 0; i < n; i ++) cin >> B[i];
    for (int i = 0; i < n - 1; i ++) cin >> C[i];

    int res = 0;
	for (int i = 0; i < n; i ++) {
		int x = A[i];
		res += B[x - 1];
		if (i > 0) {
			if (x == A[i - 1] + 1) {
				res += C[x - 2];
			}
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
string s;
long long p,f;
int main(){
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='C'){
			p=i;
			f=1;	
		}
	}
	if(f==0){
		printf("No\n");
		return 0;
	}
	for(int i=p;i<s.size();i++){
		if(s[i]=='F'){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILL(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define INF (1 << 29)
#define MOD 1000000007
//int dx[4] = {1,0,0,-1};
//int dy[4] = {0,1,-1,0};




int main(){

  int n,res = 0;
  cin >> n;
  vector<int> v(n);
  REP(i,n)cin >> v[i];
  for(int i = 1;i < n-1;i++){
    if(max({v[i-1],v[i],v[i+1]}) != v[i] && min({v[i-1],v[i],v[i+1]}) != v[i])res++;
  }

  cout << res;

  return 0;
}

Measured memory_bytes: 256
import itertools
N,M = map(int,input().split())
data = [0,1]
state_list = list(itertools.product(data, repeat=N))
l = [[int(x) for x in input().split()] for i in range(M)]
p = list(map(int,input().split()))
ans = 0
for i in range(2**N):
  k_count = 0
  for j in range(M):
    tmp = l[j][0]
    tmp_s = l[j][1:]
    count = 0
    for k in range(tmp):
      if state_list[i][tmp_s[k]-1] == 1:
        count += 1
    if count%2 == p[j]:
      k_count += 1
  if k_count == M:
    ans += 1
print(ans)

Measured memory_bytes: 3444
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <iostream>
#include <fstream>
#include <chrono>

using namespace std;

const int DIV = 1000000007;

int main(int argc, char *argv[]) {
#ifdef VLAD_LOCAL
    ifstream in("in.txt");
    auto start = std::chrono::steady_clock::now();
#else
    istream &in = cin;
#endif
    int n;
    in >> n;
    vector<int> a(n);
    int m = 2;
    for (int i = 0; i < n; i++) {
        in >> a[i];
        if (a[i] + 1 > m)
            m = a[i] + 1;
    }

    vector<char> cnt(m, 0);
    for (int i = 0; i < n; i++) {
        if (cnt[a[i]] >= 2)
            continue;
        int tmp = a[i], x = 1;
        while (tmp < m) {
            cnt[tmp]++;
            x++;
            tmp = a[i] * x;
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (cnt[a[i]] == 1)
            ans++;
    }
    printf("%d\n", ans);
#ifdef VLAD_LOCAL
    auto end = std::chrono::steady_clock::now();
    double seconds = (double)std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() / 1000;
    printf("%.3lf seconds\n", seconds);
#endif
	return 0;
}


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

int main(){
  int N;
  cin>>N;
  int K;
  cin>>K;
  vector<char>D(K);
  int a;
  for (int i=0;i<K;i++){
    cin>>a;
    D[i]='0'+a;
  }
  bool flag=1;
  while(1){
    string temp=to_string(N);
    for(int i=0;i<temp.length();i++){
      for(int j=0;j<K;j++){
        if(temp.at(i)==D[j]){
          flag=0;
          break;
        }
      }
    }
    if(flag){
      cout<<N<<endl;
      return 0;
    }
    flag=1;
    N++;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e18)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))




int main(){
	
	ll N;
	cin >> N;
	double ans=0.0;
	FOR(i,0,N){
		double k;
		cin >> k;
		ans += 1.0/k;
	} 
	out(10) << 1.0/ans << endl;
}


Measured memory_bytes: 256
n=int(input())
a=[int(x) for x in input().split()]
b=[y for y in a if y%2 == 0]
c=0
for i in b:
    if i%3 == 0 or i%5 == 0:
        pass
    else:
        print("DENIED")
        c=1
        break
        
if c==0:
    print("APPROVED")

Measured memory_bytes: 9184