akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n;
    cin >> n;
    int ans = 0;
    for(int i=1;i<=n;i += 2){
        int tmp = 2;
        for(int j=2;j<i;j++){
            if(i%j==0){
                tmp++;
            }
        }
        if(tmp==8) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  int X[5];
  rep(i, 5) cin >> X[i];
  rep(i, 5) {
    if (X[i] == 0) {
      cout << (i + 1) << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3576
antena = [int(input()) for _ in range(5)]
k = int(input())

flg = True
for i in range(len(antena)):
  for j in range(len(antena)):
    if antena[i] - antena[j] > k:
      flg = False
      break
    
if flg:
  print('Yay!')
else:
  print(':(')

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "-1" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N,M;
    int A[1040],B[1040];
    int C[1040][15];
    int c[1040]={};
    int dp[1140][5140];
    cin >>  N >> M;
    REP(i,M){
        cin >> A[i] >> B[i];
        REP(j,B[i]){
            cin >> C[i][j];
            C[i][j]--;
            c[i]+=(1<<C[i][j]);
        }
    }
    REP(i,M){
        REP(j,(1<<N)){
            dp[i][j]=INF;
        }
    }
    dp[0][0]=0;
    
    REP(i,M){
        REP(j,(1<<N)){
            dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
            dp[i+1][j|c[i]]=min(dp[i+1][j|c[i]],dp[i][j]+A[i]);
        }
    }
    //REP(i,M){REP(j,(1<<N)){cout << dp[i][j] << " ";}cout << endl;}
    
    int Ans=dp[M-1][(1<<N)-1];
    if(Ans==INF)GOODBYE;
    cout << Ans << endl;
    return 0;
}



Measured memory_bytes: 42112
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using tl = tuple<ll, ll, ll>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n; cin>>n;
    vl as(n); cin>>as;

    map<ll, ll> mp;
    rep(i, n) mp[as[i]]++;
    ll Q; cin>>Q;

    ll ans = 0;
    rep(i, n) ans += as[i];
    rep(q, Q) {
        ll b, c; cin>>b>>c;

        ans -= b * mp[b];
        ans += c * mp[b];
        mp[c] += mp[b];
        mp[b] = 0;
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 10080
using System;
using System.Collections.Generic;
using System.Linq;

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {
            var day = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            if (day[0] <= day[1])
            {
                Console.WriteLine(day[0]);
            }
            else
            {
                Console.WriteLine(day[0] - 1);
            }
        }
    }
}


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

#define ln "\n"
#define SORT(X) sort(X.begin(), X.end())
#define SORTi(X) sort(X.begin(), X.end(), greater<ll>())
#define REP(x, a, b) for (auto x = a; x <= b; x++)
#define REPi(x, b, a) for (auto x = b; x >= a; x--)
#define REPit(x, A) for (auto x = A.begin(); x != A.end(); x++)
#define REPr(x, A) for (auto x : A)
#define ll long long
#define ull unsigned long long
#define PB push_back
#define EB emplace_back
#define UMP unordered_map
#define UST unordered_set

using namespace std;

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

    int n, m, a = 0, b = 0;
    map<int, int> mp;
    cin >> n >> m;
    REP(i, 0, m - 1)
    {
        cin >> a >> b;
        mp[a]++;
        mp[b]++;
    }
    REP(i, 1, n)
    {
        cout << mp[i] << ln;
    }
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

void solve(){
    int n, k, sum=0;
    cin>>n>>k;
    vector<int> a(n);
    for(auto &it:a)cin>>it;
    sort(a.begin(),a.end());
    for(int i=0;i<k;i++){
        sum+=a[i];
    }
    cout<<sum;
}

int main()
{
    //freopen("IN.txt","r",stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 3616
import heapq

def main2(l, n):
    ans = 0
    lis = []
    heapq.heapify(lis)
    for i in range(1, n):
        for j in l[i]:
            heapq.heappush(lis, j)
        while len(lis) > i:
            ans += heapq.heappop(lis)
    return ans

def main():
    from sys import stdin
    def input():
        return stdin.readline().strip()

    t = int(input())

    answer = []
    for _ in range(t):

        n = int(input())
        ans = 0
        l = [[] for _ in range(n+1)]
        r = [[] for _ in range(n+1)]
        for _ in range(n):
            i, j, k = map(int, input().split())
            if j > k:
                ans += j
                l[i].append(j-k)
            elif j < k:
                if i == n:
                    ans += j
                else:
                    ans += k
                    r[n-i].append(k-j)
            else:
                ans += j

        ans -= main2(l, n) + main2(r, n)
        answer.append(ans)

    for i in answer:
        print(i)

main()

Measured memory_bytes: 104172
#include<stdio.h>
int main(){
  int x,y,a,b;
  scanf("%d%d",&x,&y);
  if(x==1 || x==3 || x==5 || x==7 || x==8 || x==10 || x==12){
    a=1;
  }
  else if(x==2){
    a=2;
  }
  else{
    a=3;
  }
  if(y==1 || y==3 || y==5 || y==7 || y==8 || y==10 || y==12){
    b=1;
  }
  else if(y==2){
    b=2;
  }
  else{
    b=3;
  }
  if(a==b){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
  return 0;
}


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

using namespace std;
#define X first
#define Y second
#define pb push_back
typedef double db;
typedef long long ll;
typedef pair<ll,db> P;
const int MAXN=5e5+10;
db res=0;ll all;
int n,L,l=0,r=-1,top;P q[MAXN];

int main()
{
    scanf("%d%d",&n,&L);
    for(int i=1;i<=n;i++)
    {
        db t;ll v;scanf("%lf%lld",&t,&v);
        while(all+v>L)
        {//按温度从小到大放水
            ll d=min(q[l].X,all+v-L);
            q[l].X-=d;all-=d;res-=d*q[l].Y;
            if(!q[l].X) l++;
        }
        all+=v;res+=v*t;
        
        while(l<=r&&t<q[r].Y)
        {//
            t=(v*t+q[r].X*q[r].Y)/(v+q[r].X);
            v+=q[r].X;r--;
        }
        q[++r]=P(v,t);
        printf("%.6lf\n",res/L);
    }
    return 0;
}

Measured memory_bytes: 16384
/*******************************************************************************

                          BISMILLA HIRRAHMANIR RAHIM

*******************************************************************************/

#include <stdio.h>
#include <math.h>

int main()
{
  int x;
  scanf("%d",&x);
  if(x==0)
  {
      printf("1");
  }
  else
  {
      printf("0");
  }
    

    return 0;
}


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

#define pb  push_back
#define mp  make_pair
#define ll  long long
#define itr iterator

typedef pair<ll,ll> pii;

const ll MAX=2e6+9;
const ll INF=1e12;

ll N,L,start,last,final,res,X[MAX],prefix[MAX],suffix[MAX];

signed main()
{
	ios_base::sync_with_stdio(false);
  
	cin>>L>>N;	 
	for(int A=1;A<=N;A++)
		cin>>X[A];
	for(int it=0;it<2;it++)
	{
		for(int A=N;A>=1;A--)
			suffix[A]=suffix[A+1]+L-X[A];
		for(int A=1;A<=N;A++)
			prefix[A]=prefix[A-1]+X[A];
		for(int A=0;A<N;A++)
		{
			last=N-(A+1)/2+1;
			res=2*suffix[last];
			if(A%2==1)
				res-=L-X[last];
			start=last-(A/2+1);
			res+=2*prefix[last-1]-2*prefix[start-1];			
			if(A%2==0)
				res-=X[last-1];
			final=max(final,res);
		}
		for(int A=1;A<=N;A++)
			X[A]=L-X[A];
		sort(X+1,X+N+1);
	}
	cout<<final;
	return 0;
}

Measured memory_bytes: 9984
N = int(input())
nums = []
for _ in range(N):
    nums.append(int(input()))

nums.sort()
s = sum(nums)
ans = 0
if s % 10 != 0:
    ans = s
else:
    for num in nums:
        if num % 10 != 0:
           ans = s -num
           break

print(ans)

Measured memory_bytes: 38448
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int N,K;
  cin>>N>>K;
  int A[200100];
  for(int i=0;i<N;i++)cin>>A[i];
  int baket[200100]={0};
  for(int i=0;i<N;i++){
    baket[A[i]-1]++;
  }
  sort(baket,baket+N);
  reverse(baket,baket+N);
  int cnt=0;
  for(int i=0;i<N;i++){
    if(baket[i]!=0)cnt++;
  }
  int ans=0;
  if(cnt<=K){
    cout<<ans<<endl;
  }else{
    sort(baket,baket+cnt);
    for(int i=0;i<cnt-K;i++)ans+=baket[i];
    cout<<ans<<endl;
  }

  return 0;
}


Measured memory_bytes: 1792
n=int(input())
if n==1:
    print(1)
    exit()
x=[0]*n
y=[0]*n
for i in range(n):
    x[i],y[i]=map(int,input().split())

from collections import Counter
cnt = Counter()
    
for i in range(n):
    for j in range(n):
        if i!=j:
            cnt[str((x[j]-x[i],y[j]-y[i]))]+=1

print(n-cnt.most_common()[0][1])


Measured memory_bytes: 3820
#include <iostream>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::string;

int main(int argc, char* argv[]) {
  std::vector<string> ws = {"Sunny", "Cloudy", "Rainy"};
  std::string w;
  cin >> w;
  for (int i = 0; i < 3; ++i) {
    if (w == ws[i]) {
      cout << ws[(i + 1) % 3];
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <set>
#include <assert.h>
#include <numeric>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define MOD 1000000007
#define pb push_back
#define int long long
#ifdef int
const long long INF = LLONG_MAX / 10;
#else
const int INF = 1010101010;
#endif
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<ll> > mat;
typedef pair<int, int> P;
//typedef pair<double, double> P;
const int dx[9] = {-1, 0, 0, 1, -1, -1, 1, 1, 0};
const int dy[9] = {0, -1, 1, 0, -1, 1, -1, 1, 0};

int N, A, B;
 
signed main()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cin >> N >> A >> B;
  if ((B - A - 1) & 1) {
    cout << "Alice" << endl;
  } else {
    cout << "Borys" << endl;
  }
}

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    A = [LIST() for i in range(3)]
    N = INT()

    for i in range(N):
        b = INT()
        for j in range(3):
            for k in range(3):
                if b == A[j][k]: A[j][k] = 0

        flag = False
        if A[0][0] + A[0][1] + A[0][2] == 0:
            flag = True
        if A[1][0] + A[1][1] + A[1][2] == 0:
            flag = True
        if A[2][0] + A[2][1] + A[2][2] == 0:
            flag = True
        if A[0][0] + A[1][0] + A[2][0] == 0:
            flag = True
        if A[0][1] + A[1][1] + A[2][1] == 0:
            flag = True
        if A[0][2] + A[1][2] + A[2][2] == 0:
            flag = True
        if A[0][0] + A[1][1] + A[2][2] == 0:
            flag = True
        if A[2][0] + A[1][1] + A[0][2] == 0:
            flag = True

        if flag:
            print("Yes")
            sys.exit()

    print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 38640
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int N;
long long int A[100010],X[100010];
int main()
{
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
	{
		scanf("%lld",&A[i]);
		if(i%2==1)
		    X[1]=X[1]+A[i];
		else
		    X[1]=X[1]-A[i];
	}
	for(int i=1;i<N;i++)
		X[i+1]=2*A[i]-X[i];
	for(int i=1;i<=N;i++)
	    printf("%lld ",X[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 2816
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

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

    double x[n] = {};
    for(int i = 0; i < n; i++)
        cin >> x[i];

    double y[n] = {};
    for(int i = 0; i < n; i++)
        cin >> y[i];

    double p1 = 0.0;
    double p2 = 0.0;
    double p3 = 0.0;
    double p4 = 0.0; 
    for(int i = 0; i < n; i++){
        p1 += fabs(x[i] - y[i]);
        p2 += pow(fabs(x[i] - y[i]), 2);
        p3 += pow(fabs(x[i] - y[i]), 3);
        if(fabs(x[i] - y[i]) >= p4)
            p4 = fabs(x[i] - y[i]);
    }

    printf("%.5f\n", p1);
    printf("%.5f\n", sqrt(p2));
    printf("%.5f\n", pow(p3, 1.0 / 3.0));
    printf("%.5f\n", p4);

    return 0;
}


Measured memory_bytes: 3420
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>

// #include <unordered_set>
// #include <unordered_map>

#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())

#define pb push_back
#define mp make_pair

int gcd(int a, int b) {
    int c;
    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return a;
}

int lcm(int a, int b) {
    int c = gcd(a, b);
    a /= c;
    return a * b;
}

typedef std::pair<int, int> P;
typedef long long ll;
typedef long double ld;

const int MOD = 1000000007;
const int INF = 1e9;
const ll LINF = INF * 1ll * INF;
const ld DINF = 1e200;
const double EPS = 1e-10;
const double PI = acos(-1.0);

using namespace std;

// #define int long long

signed main() {


    ios::sync_with_stdio(false);
    cin.tie(0);
    //cin高速化

   int n;
   int h[101];

   cin >> n;
   for (int i = 0;i < n ;i++) {
       cin >> h[i];
   }

   int ans =0;
   int max_h = -1;

   for (int i = 0;i < n;i++) {
       if (max_h <= h[i])ans++;
       max_h = max(max_h, h[i]);

   }
   cout << ans << endl;

    return 0;

}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
using namespace std;
const int MAXN = 100005;
int n, m, Q, sa[MAXN], sb[MAXN];
char S[MAXN], T[MAXN];

int main() {
	scanf("%s%s%d", S + 1, T + 1, &Q);
	n = strlen(S + 1);
	m = strlen(T + 1);
	
	for(int i = 1; i <= n; ++i) sa[i] = (sa[i-1] + (S[i] == 'A' ? 1 : 2)) % 3;
	for(int i = 1; i <= m; ++i) sb[i] = (sb[i-1] + (T[i] == 'A' ? 1 : 2)) % 3;
	
	for(int a, b, c, d; Q--; ) {
		scanf("%d%d%d%d", &a, &b, &c, &d);
		puts((sa[b] - sa[a-1] - sb[d] + sb[c-1] + 6) % 3 == 0 ? "YES" : "NO");
	}
	return 0;
}

Measured memory_bytes: 1408
def main():
    import sys
    N=int(input())
    MOD=1000000007
    
    a=list(map(int,input().split()))
    c=[0,0,0]
    ans=1
    for i in range(N):

        if a[i]!=c[0] and a[i]!=c[1] and a[i]!=c[2]:
            print(0)
            sys.exit()

        if c[1]==c[0] and c[2]==c[0]:
            ans=(ans*3)%MOD
            c[0]+=1

        elif c[0]==c[1]:
            if c[0]==a[i]:
                c[0]+=1
                ans=(ans*2)%MOD
            else:
                c[2]+=1

        elif c[0]>c[1] and c[1]==c[2]:
            if c[0]==a[i]:
                c[0]+=1
            else:
                ans=(ans*2)%MOD
                c[1]+=1
            
        else:
            if c[0]==a[i]: c[0]+=1
            if c[1]==a[i]: c[1]+=1
            if c[2]==a[i]: c[2]+=1
        
        c.sort(reverse=True)
    print(ans)


 
if __name__ == '__main__':
    main()

Measured memory_bytes: 14396
#include <stdio.h>
#define min(X, Y) ((X) < (Y) ? (X) : (Y))

int main()
{
	int a[5];
	int b[5];
	int sum = 0;
	int ans = 10000000;

	for (int i = 0; i < 5; i++) {
		scanf("%d", &a[i]);
		b[i] = (a[i] + 9) / 10 * 10;

		sum = sum + b[i];
	}

	for (int i = 0; i < 5; i++) {
		ans = min(ans, sum - b[i] + a[i]);
	}

	printf("%d\n", ans);

	return 0;
}


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

int main() {
    int N;
    string s;
    cin >> N >> s;
    int cnt = 0, mi = 0;
    for(int i = 0; i < N; ++i) {
        if(s[i] == ')') {
            cnt--;
        } else {
            cnt++;
        }
        mi = min(mi, cnt);
    }
    if(mi < 0) {
        s = string(-mi, '(') + s;
    }
    cnt += -mi;
    s = s + string(cnt, ')');
    cout << s << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define boost ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define M 1000000007
#define eb emplace_back
#define watch(x) cout << (#x) <<" is "<< x <<"\n";


using namespace std;
//const int N = 1e6;

int32_t main(){
  boost;
  int tc = 1; //cin >> tc;
  while(tc--)
  {
    string s; cin >> s;
    if(s.back() == 's')
    {
      s += 'e';
      s += 's';
    }
    else
      s += 's';
    cout << s <<"\n";
  }
}



Measured memory_bytes: 3648
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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; }
typedef pair<int, int>P;
const int INF = 1e8;

signed main() {
	int a, b;
	cin >> a >> b;
	if ((a * b) & 1)cout << "Odd";
	else cout << "Even";
}

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

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> way(N);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    way.at(a - 1)++;
    way.at(b - 1)++;
  }
  
  for (int i = 0; i < N; i++) {
    cout << way.at(i) << endl;
  }
}

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

int main(){
  int N;
  cin >> N;
  vector<int> d(N);
  for(int i=0; i<N; i++) cin >> d.at(i);
  sort(d.begin(), d.end());
  d.erase( unique(d.begin(), d.end()), d.end());
  cout << d.size();
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
//1 2 3 4 100 1
/*
配列を持っているa
四こに分ける
どれぞれの総和をおんなじくらいへ
配列の総和を半分にカットする関数

1回めのカット
右に
*/
#define N_INFTY -2147483648

int main(void){
    int n;
    scanf("%d",&n);
    int a[2][n];
    int i,j,ans = N_INFTY,counter = 0;
    for(j=0;j<2;j++){
        for(i=0;i<n;i++){
            scanf("%d",&a[j][i]);
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            if(j<i){
                counter += a[0][j];
            }else if(j==i){
                counter += a[0][j] + a[1][j];
            }else if(j>i){
                counter += a[1][j];
            }
        }
        if(counter > ans){
            ans = counter;
        }
        counter = 0;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
    static void Main(string[] args) {
		new Calc().calc();
    }
	public class Calc {
		public Calc() { }
		public void calc() {
			int[] NM = ReadLine<int>(' ');
			List<string> A = new List<string>(), B = new List<string>();
			for (int i = 0; i < NM[0]; i++) {
				A.Add(Console.ReadLine());
			}
			for (int i = 0; i < NM[1]; i++) {
				B.Add(Console.ReadLine());
			}
			var B_docked = B.Docking();
			for (int i = 0; i < NM[0] - NM[1] + 1; i++) {
				for (int n = 0; n < NM[0] - NM[1] + 1; n++) {
					var STR = A.RangeDocking(n,n+NM[1], _ => _.Substring(i, NM[1]));
					if (B_docked == STR) {
						Console.WriteLine("Yes");
						return;
					}
				}
			}
			Console.WriteLine("No");
			return;
		}
	}

	public static T ReadLine<T>() =>
		(T)Convert.ChangeType(Console.ReadLine(), typeof(T));
	
	public static T[] ReadLine<T>(params char[] separators) =>
		Console.ReadLine()
		.Split(separators)
		.Select(_ => (T)Convert.ChangeType(_, typeof(T)))
		.ToArray();
	
	public static List<T> ReadLines<T>(int readCount) {
		List<T> rt = new List<T>();
		for (int i = 0; i < readCount; i++) {
			rt.Add(ReadLine<T>());
		}
		return rt;
	}
}
public static class Utils {
	public static string Docking<T>(this IEnumerable<T> s, int sequenceRange, Func<T, string> filter = null) {
		string str = "";
		int c = 0;
		foreach (var item in s) {
			str += filter == null ? item.ToString() : filter(item);
			c++;
			if (c == sequenceRange) break;
		}
		return str;
	}

	public static string Docking<T>(this IEnumerable<T> s, Func<T, string> filter = null) {
		return s.Docking(s.Count(), filter);
	}

	public static string RangeDocking<T>(this IEnumerable<T> s,int start,int end,Func<T,string> filter = null) {
		string str = "";
		end = end < s.Count() ? end : s.Count();
		var items = s.ToArray();
		for (int i = start; i < end; i++) {
			str+= filter == null ? items[i].ToString() : filter(items[i]);
		}
		return str;
	}
}

Measured memory_bytes: 17608
#include<stdio.h>

int main(void)

{

int a,b,c;

int count=0;

int i;

 scanf("%d %d %d",&a,&b,&c);

for(i=a;i<=b;i++)

{

if(c%i==0) count++;

}

printf("%d\n",count);

return 0;

}
 

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

//cmdで g++ test.cpp とするとコンパイルできる

int main() {
  int A,B;
  string S,T,U;
  cin>>S>>T;
  cin>>A>>B;
  cin>>U;
  if(S==U)A--;
  if(T==U)B--;
  cout<<A<<" "<<B<<endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define rep2(i, a)for(auto i : a)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll co(ll n, ll k) { ll a = 1; rep(i, 1ll, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main(void) {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	printf("%lld\n", max(max(a * c, b * d), max(a * d, b * c)));
	return 0;
}


Measured memory_bytes: 3768
# AOJ ITP2_8_A: Map: Search
# Python3 2018.6.24 bal4u

dict = {}
q = int(input())
for i in range(q):
	a = list(input().split())
	if a[0] == '0':	dict[a[1]] = int(a[2])
	else: print(dict[a[1]])


Measured memory_bytes: 37500
#include<iostream>

using namespace std;

int n;

string func(int x,int y,int z){
	if(x - 100 && y - 100 && z - 100){
		if(x+y>=180){
			return "A";
		}
		if(x+y+z >= 240){
			return "A";
		}
		if(x+y+z >= 210){
			return "B";
		}
		if(x+y+z>=150){
			if(x>=80||y>=80){
				return "B";
			}
		}
		return "C";
		
	}else{
		return "A";
	}
}

int main(void){
	cin >> n;
	while(n){
		for(int i =0 ; i< n ; i++){
			int pm,pe,pj;
			cin >> pm >> pe >> pj;
			string ans = func(pm,pe,pj);
			cout << ans << endl;
		}
		cin >> n;
	}
}

Measured memory_bytes: 0
#include <algorithm>
#include <climits>
#include <functional>
#include <iterator>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#ifdef _MSC_VER
using ll = __int64;
using ull = unsigned __int64;
#else
using ll = long long int;
using ull = unsigned long long int;
#endif

// 二乗を計算する。
ll sq(ll x) { return x * x; }

// 領域内にいるか。
bool within(ll x, ll min, ll max) {
	return min <= x && x <= max;
}

// container の中から key より小さい値を見つける。
// 見つからない場合は container.end() を返す。
template<typename T>
typename T::iterator less_than(T& container, typename T::key_type& key) {
	typename T::iterator prev = container.lower_bound(key);
	if (prev == container.begin()) prev = container.end();
	else prev--;
	return prev;
}

// container の中から key より大きい値を見つける。
// 見つからない場合は container.end() を返す。
template<typename T>
typename T::iterator greater_than(T& container, typename T::key_type& key) {
	return container.upper_bound(key);
}

// b^e (mod m) を求める
ll modpow(ll b, ll e, ll m) {
	ll result = 1;
	while (e > 0) {
		if ((e & 1) == 1) result = (result * b) % m;
		e >>= 1;
		b = (b * b) % m;
	}
	return result;
}


// ここから解法

int main(void) {
	int N;
	cin >> N;
	vector<ll> p(N);
	for (int i = 0; i < N; ++i) cin >> p[i];
	auto is_ok = [](vector<ll> &a) {
		for (int i = 0; i < a.size() - 1; ++i) {
			if (a[i] > a[i + 1]) {
				return false;
			}
		}
		return true;
	};
	bool ok = is_ok(p);
	for (int i = 0; i < p.size(); ++i) {
		for (int j = i + 1; j < p.size(); ++j) {
			swap(p[i], p[j]);
			ok = ok || is_ok(p);
			swap(p[i], p[j]);
		}
	}
	cout << (ok ? "YES" : "NO") << endl;
	return 0;
}



Measured memory_bytes: 256
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <numeric>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
//#define int long long
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define loop(s, v, it) for (s::iterator it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (int i = head[x]; i; i = e[i].nxt)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, sum) memset(a, sum, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define iv inline void
#define enter cout << endl
#define siz(x) ((int)x.size())
#define file(x) freopen(#x".in", "r", stdin),freopen(#x".out", "w", stdout)
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <int, int> pii ;
typedef vector <int> vi ;
typedef vector <pii> vii ;
typedef queue <int> qi ;
typedef queue <pii> qii ;
typedef set <int> si ;
typedef map <int, int> mii ;
typedef map <char, int> mci ;
const int N = 100010 ;
const int INF = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const int MOD = 1000000007 ;
const double eps = 1e-7 ;
void print(int x) { cout << x << endl ; exit(0) ; }
void PRINT(string x) { cout << x << endl ; exit(0) ; }
void douout(double x){ printf("%lf\n", x + 0.0000000001) ; }
template <class T> void chmin(T &a, T b) { if (a > b) a = b ; }
template <class T> void chmax(T &a, T b) { if (a < b) a = b ; }
void upd(int &a, int b) { (a += b) %= MOD ; }
void mul(int &a, int b) { a = 1ll * a * b % MOD ; }

mci app ;
int n, ans = 1 ;
char s[N] ;

signed main(){
//	freopen("test.in", "r", stdin) ;
//	freopen("test.out", "w", stdout) ;
	scanf("%d", &n) ;
	scanf("%s", s) ;
	rep(i, 0, n - 1) app[s[i]]++ ;
	loop(mci, app, it) mul(ans, (*it).se + 1) ;
	printf("%d\n", ans - 1) ;
	return 0 ;
}

/*
写代码时请注意：
	1.ll？数组大小，边界？数据范围？
	2.精度？
	3.特判？
	4.至少做一些
思考提醒：
	1.最大值最小->二分？
	2.可以贪心么？不行dp可以么
	3.可以优化么
	4.维护区间用什么数据结构？
	5.统计方案是用dp？模了么？
	6.逆向思维？
*/




Measured memory_bytes: 384
<?php
// # 整数の入力
// fscanf(STDIN, "%d", $a);
# スペース区切りの整数の入力
// fscanf(STDIN, "%d %d %d", $a, $b, $c);
// # 文字列の入力
// fscanf(STDIN, "%s", $s);
// 一行分をそのまま変数に格納
// $n = trim(fgets(STDIN));
// 空白で区切られたのを配列に格納
// $arr = explode(' ', trim(fgets(STDIN)));
$arr = explode(' ', trim(fgets(STDIN)));
$t_hp = $arr[0];
$t_atk = $arr[1];
$a_hp = $arr[2];
$a_atk = $arr[3];

while($a_hp >= 0){
    $a_hp = $a_hp - $t_atk;
    if($a_hp <= 0){
        // 初回高橋くんの攻撃で青木くんが負けた場合
        echo('Yes');
        break;
    }else{
        // 初回の高橋くんの攻撃で青木くんが負けなかった場合
        $t_hp = $t_hp - $a_atk;
        if($t_hp <= 0){
            // 青木くんのターンで高橋くんが負けた場合
            echo('No');
        break;
        }else{
            continue;
        }
    }

}

Measured memory_bytes: 16176
#include <iostream>
#define BOARD_SIZE 8

using namespace std;

int queen[BOARD_SIZE];
int board[BOARD_SIZE][BOARD_SIZE];

void print(){
    for(int i = 0; i < BOARD_SIZE; i++){
        for(int j = 0; j < BOARD_SIZE; j++){
            if(queen[i] == j){ cout << "Q"; }
            else{ cout << "."; }
        }
        cout << endl;
    }
}

void boardUpdate(int x, int y, int d){
    for(int i = 0; i < BOARD_SIZE; i++){
        board[x][i] += d;
        board[i][y] += d;
        if(x-i >= 0 && y-i >= 0){ board[x-i][y-i] += d; }
        if(x-i >= 0 && y+i < BOARD_SIZE){ board[x-i][y+i] += d; }
        if(x+i < BOARD_SIZE && y-i >= 0){ board[x+i][y-i] += d; }
        if(x+i < BOARD_SIZE && y+i < BOARD_SIZE){ board[x+i][y+i] += d; }
    }
}

void findQueenPos(int progress){
    if(progress == BOARD_SIZE){
        print();
        return;
    }
    for(int i = 0; i < BOARD_SIZE; i++){
        if(board[progress][i] == 6){
            findQueenPos(progress + 1);
        }
        else if(board[progress][i] == 0){
            queen[progress] = i;
            boardUpdate(progress, i, 1);
            findQueenPos(progress + 1);
            boardUpdate(progress, i, -1);
        }
    }
}

int main(){
    int k, r, c;

    cin >> k;
    for(int i = 0; i < k; i++){
        cin >> r >> c;
        queen[r] = c;
        boardUpdate(r, c, 1);
    }

    findQueenPos(0);

    return 0;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const long long N = 300100;
long long n, to_add[N], aib[N], m, l, r, ans[N];
vector <long long> to_erase[N], v[N];

long long lsb(long long k) { return k & (-k); }

void upd(long long pos, long long val) {
	for(; pos < N; pos += lsb(pos))
		aib[pos] += val;
}

long long que(long long pos) {
	long long ret = 0;
	for(; pos; pos -= lsb(pos))
		ret += aib[pos];
	return ret;
}

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

	cin >> n >> m;
	for(long long i = 1; i<= n; i++) {
		cin >> l >> r;
		to_erase[r + 1].push_back(l);
		to_add[l]++;
	}

	for(long long i = 1; i <= m; i++)
		for(long long j = i; j <= m; j += i)
			v[j].push_back(i);

	for(long long i = 1; i <= m; i++) {
		upd(i, to_add[i]);
		for(auto j : to_erase[i])
			upd(j, -1);

		for(auto j : v[i]) {
			//[i - j + 1, i]
			ans[j] += que(i) - que(i - j);
		}
	}
	for(long long i = 1; i <= m; i++) cout << ans[i] << '\n';
}	

	 

Measured memory_bytes: 39296
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n := nextInt()
	min, max := -100, 100
	a := make([]int, n)
	for i := range a {
		a[i] = nextInt()
		if a[i] < min {
			min = a[i]
		}
		if a[i] > max {
			max = a[i]
		}
	}

	ans := 200 * 200 * 100
	for i := min; i <= max; i++ {
		sum := 0
		for j := range a {
			sum += cost(a[j], i)
		}
		if sum < ans {
			ans = sum
		}
	}

	puts(ans)
}

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func cost(x, y int) int {
	return (x - y) * (x - y)
}


Measured memory_bytes: 640
from collections import defaultdict


def ok(l, s):
    for i in range(len(s) * 2):
        now = i % len(l)
        pre = now - 1
        nex = (now + 1) % len(l)
        if (l[now] == -1 and s[now] == 'x') or (l[now] == 1 and s[now] == 'o'):
            if l[nex] is None:
                l[nex] = l[pre]
            else:
                if l[nex] != l[pre]:
                    return False
        else:
            if l[nex] is None:
                l[nex] = -1 * l[pre]
            else:
                if l[nex] != -1 * l[pre]:
                    return False

    return True


def main():
    N = int(input())
    s = input()

    for x in [(-1, -1), (-1, 1), (1, -1), (1, 1)]:
        l = [None] * N
        l[-1], l[0] = x[0], x[1]
        if ok(l, s):
            print("".join(['W' if x == -1 else 'S' for x in l]))
            return
    print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5612
while 1:
  n=int(input())
  if not n:break
  X={0}
  Y=set(range(n))-X
  s=0
  l=[tuple(map(int,input().split(","))) for _ in range(int(input()))]

  while Y:
    cd=[i for i in l if (i[0] in X and i[1] in Y) or (i[0] in Y and i[1] in X)]
    cd=sorted(cd,key=lambda x:x[2])[0]
    if cd[0] in X and cd[1] in Y:
      X.add(cd[1])
      Y=Y-X
    elif cd[0] in Y and cd[1] in X:
      X.add(cd[0])
      Y=Y-X
    s+=int(cd[2]/100-1)
  print(s)


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

int main(){
  int N,x;
  cin>>N>>x;
  int m[N];
  for(int i=1;i<N+1;i++){
    cin>>m[i];
	x=x-m[i];}
	
  for(int j=1;j<N+1;j++){
    if(m[1]>m[j]){
	 m[1]=m[j];}
	 }

  int item=N;
  while(x>=m[1]){
    x=x-m[1];
	item++;
	}
 
  cout<<item<<endl;
  return 0;
 }
 
    
  
  

Measured memory_bytes: 256
def is_month(input_str):
  if 1 <= int(input_str) and int(input_str) <= 12:
    return True
  else:
    return False
    
def is_year(input_str):
  if 0 <= int(input_str) and int(input_str) <= 99:
    return True
  else:
    return False

s=input().strip()
first_half = [is_month(s[:2]), is_year(s[:2])]
second_half = [is_month(s[2:]), is_year(s[2:])]

if (first_half == [True, True] and second_half == [True, True]):
  print('AMBIGUOUS')
elif first_half[0] is True and second_half[1] is True:
  print('MMYY')
elif first_half[1] is True and second_half[0] is True:
  print('YYMM')
else:
  print('NA')
  

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main()
{
  long long n;
  cin>>n;
  long long sum=0;
  for(long long i=1;i<=n;i++)
  {
    if(i%15!=0 && i%3!=0 && i%5!=0)
      sum+=i;
  }
  cout<<sum;
  return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
int main()
{
    int N;
    std::cin >> N;
    std::vector<char> D(N);
    std::vector<int> L(N);
    std::vector<bool> done(N, false);
    constexpr int MAX = 1000;
    for (int i = 0; i < N; i++) { std::cin >> D[i] >> L[i]; }
    std::vector<int> S;
    for (int i = 0; i <= MAX; i++) {
        for (int j = 0; j < N; j++) {
            if (L[j] == i and D[j] == 'y') { S.push_back(j); }
        }
    }
    int ans = 0;
    for (const int s : S) {
        if (done[s]) { continue; }
        ans++;
        for (int i = s; i < N; i++) {
            if (L[i] >= L[s] and D[i] == 'n') { break; }
            done[i] = true;
        }
        for (int i = s; i >= 0; i--) {
            if (L[i] >= L[s] and D[i] == 'n') { break; }
            done[i] = true;
        }
    }
    std::cout << ans << std::endl;
    return 0;
}



Measured memory_bytes: 3172
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();  //999以下
    int N_1 = N % 10 ;
    
    if( N_1 == 3 )
      System.out.println("bon");
    else{
      if (N_1 == 0 || N_1 == 1 || N_1 == 6 || N_1 == 8)
        System.out.println("pon");
      else
        System.out.println("hon");
    }
    
  }
}

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

using namespace std;

int main(){
	int n;
	cin>>n;
	vector<int> hoge(26,0);

	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		vector<int> fuga(26,0);

		for(auto a:s){
			fuga.at(a-'a')++;
		}

		if(i==0) hoge=fuga;
		else{
			for(int i=0;i<26;i++){
				hoge.at(i)=min(hoge.at(i),fuga.at(i));
			}
		}
	}

	priority_queue<char,vector<char>,greater<char>> pq;

	for(char i='a';i<='z';i++){
		int cnt=hoge.at(i-'a');

		for(int j=0;j<cnt;j++) pq.push(i);
	}

	while(!pq.empty()){
		cout<<pq.top();
		pq.pop();
	}

	cout<<endl;

	return 0;
}


Measured memory_bytes: 256
I=lambda:list(map(int,input().split()))
n,m,q=I()
k=n+2
l=[0]*k**2
for _ in range(m):
  s,g=I()
  l[s*k+g]+=1
for i in range(1,n+1):
  for j in range(1,n+1):
    l[i*k+j]+=l[i*k+j-1]
for i in range(1,n+1):
  for j in range(1,n+1):
    l[i*k+j]+=l[(i-1)*k+j]
for _ in range(q):
  s,g=I()
  print(l[g*k+g]-l[(s-1)*k+g]-l[g*k+s-1]+l[(s-1)*k+s-1])

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

using namespace std;

int main(){
  char c;
  cin >> c ;
  if(c == 'a' || c== 'i' || c == 'u' || c == 'e'|| c== 'o'){
    cout << "vowel";
  }else{
    cout << "consonant";
  }


}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a * b / gcd(a, b);
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}

int main() {
	string s; cin >> s;
	vector<string> a(s.size()), b(s.size());
	for (int i = 0; i < s.size(); i++) {
		a[i] = s[i];
	}
	b = a;
	ssort(a);
	eerase(a);
	if (a.size() != b.size()) cout << "no";
	else cout << "yes";

	
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <math.h>
#include <map>
#include <stack>
using namespace std;
static const int INF = 1e9+7;
// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

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

int main(){

    int n; cin >> n;
    int k; cin >> k;
    // vector<int> x(n);
    int sum = 0;
    rep(i, n){
        int x; cin >> x;
        if(x*2 < abs(x - k) * 2){
            sum += (x * 2);
        }else{
            sum += (k - x) * 2;
        }
    }

    cout << sum << endl;

    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<vector<ll> , vector<ll> > vp;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16

vector<ll> reg(const vector<ll> &a){
  vector<ll> res=a;
  repl(d,1,4){
    vector<ll> b;
    rep(i,4)b.push_back(a[(i+d)%4]);
    minch(res,b);
  }
  return res;
}

ll vcnt(const vector<ll> &a){
  if(a[0]==a[2]&&a[1]==a[3]){
    if(a[0]==a[1])return 4;
    else return 2;
  }else return 1;
}

ll n;
vector<ll> c[404][2];
map<vector<ll> ,ll> cnt;

int main(){
	cin>>n;
  ll res=0;
  rep(i,n){
    rep(j,4){
      ll cc;
      cin>>cc;
      c[i][0].push_back(cc);
    }
    c[i][0]=reg(c[i][0]);
    c[i][1]=c[i][0];
    reverse(all(c[i][1]));
    c[i][1]=reg(c[i][1]);
    cnt[c[i][0]]++;
  }
  rep(i,n){
    cnt[c[i][0]]--;
    repl(j,i+1,n){
      cnt[c[j][0]]--;
      rep(d,4){
        vector<ll> vi,vj;
        rep(k,4)vj.push_back(c[j][1][(k+d)%4]);
        vi=c[i][0];
        map<vector<ll> ,ll> sccnt;
        rep(k,4){
          vector<ll> sc;
          sc.push_back(vi[k]);
          sc.push_back(vj[k]);
          sc.push_back(vj[(k+1)%4]);
          sc.push_back(vi[(k+1)%4]);
          sc=reg(sc);
          sccnt[sc]++;
        }
        ll sum=1;
        for(auto it : sccnt){
          rep(k,it.se)sum*=(cnt[it.fi]-k)*vcnt(it.fi);
        }
        res+=max(0LL,sum);
      }
      cnt[c[j][0]]++;
    }
    cnt[c[i][0]]++;
  }
  cout<<res/3<<endl;
  return 0;
}


Measured memory_bytes: 160000
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>

using namespace std;

typedef long long ll;
#define rep(i,n) for(ll i = 0; i < (n); i++)



int main() {
	

	ll n;

	cin >> n;

	vector<ll>a(n + 1);
	vector<ll>b(n + 1);
	vector<ll>c(n);


	rep(i, n) {
		cin >> a[i]; 
		a[i]--;
	}
	rep(i, n)cin >> b[i];
	rep(i, n - 1)cin >> c[i];

	ll ans = 0;

	rep(i, n) {
		ans += b[i];
		if (a[i + 1] - a[i] == 1) {
			ans += c[a[i]];
		}
	}

	

	cout << ans;

	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<map>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cerr << v[a][b] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	string str;
	cin >> str;
	
	int a = 0,b = str.size()-1,ans = 0;
	
	while(b - a > 0)
	{
		if(str[a] == str[b])
		{
			a++;b--;
		}
		else if(str[a] == 'x')
		{
			a++;
			ans++;
		}
		else if(str[b] == 'x')
		{
			b--;
			ans++;
		}
		else
		{
			cout << -1 << endl;
			return 0;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main()
{	
	int n;
	cin >> n;
	vector<int> v(n);
	REP(i, n) cin >> v[i];
	int ans = 0;
	int tmp;
	REP(i, n){
		ans = max(ans, v[i]);
		if(ans == v[i]){
			tmp = i;
		}
	}

	sort(ALL(v));
	REP(i, n){
		if(i == tmp){
			cout << v[n-2] << endl;
		}
		else{
			cout << ans << endl;
		}
	}
	//cout << tmp << endl;
}


Measured memory_bytes: 2432
s = input()

for i in range(len(s)) :
    if i % 2 != 0 :
        if s[i] != "L" and s[i] != "U" :
            if s[i] != "D" :
                print("No")
                break
    elif i % 2 == 0 :
        if s[i] != "R" and s[i] != "U" :
            if  s[i] != "D" :
                print("No")
                break

else :
    print("Yes")


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

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

	ll a,b,c,x,y;
	cin>>a>>b>>c>>x>>y;
	ll cost1 = 2 * max(x,y) * c; // Buy all from c
	cost1 = min( cost1, a * x + b * y ); // Buy all individual
	ll mx = min(x,y);
	if( mx == x ){
		ll cst2 = mx * 2 * c + (y-mx) * b;
		cost1 = min(cost1, cst2);
	}
	if( mx == y ){
		ll cst2 = mx * 2 * c + (x-mx) * a;
		cost1 = min(cost1, cst2);
	}
	cout<<cost1<<endl;

	return 0;
}


Measured memory_bytes: 256