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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()

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

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

int N,M;
string A[50];
string B[50];
int main(){
    /* やるだけ */
    ios::sync_with_stdio(false);
    cin >> N >> M;
    REP(i,N) cin >> A[i];
    REP(i,M) cin >> B[i];
    
    int ans = 0;
    
    REP(i,N) REP(j,N) {
        int flag = 1;
        REP(k,M) REP(l,M) {
            if(i+k>=N || j+l>=N) {
                flag = 0; break;
            }
            else if(A[i+k][j+l]!=B[k][l]) {
                flag = 0; break;
            }
        }
        if (flag) ans++;
    }
    
    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

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

using namespace std;

long long gcd(long long x, long long y){
    if(y == 0) return x;
    return gcd(y, x % y);
}

int main(void){
    int N;
    cin >> N;
    vector<long long> A(N), L(N), R(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    L[0] = A[0];
    for(int i = 1; i < N; i++) L[i] = gcd(L[i - 1], A[i]);
    R[N - 1] = A[N - 1];
    for(int i = N - 2; i >= 0; i--) R[i] = gcd(R[i + 1], A[i]);
    long long ans = 0;
    for(int i = 0; i < N; i++){
        long long g;
        if(i == 0) g = R[1];
        else if(i == N - 1) g = L[N - 2];
        else g = gcd(L[i - 1], R[i + 1]);
        ans = max(ans, g);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
/* Generated by powerful Codeforces Tool
 * You can download the binary file in here https://github.com/xalanq/cf-tool (win, osx, linux)
 * Author: step_by_step
 * Time: 2020-03-19 17:35:03
**/

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
  
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <assert.h>
#include <memory.h>
#include <time.h>
#include <bitset>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define repb(i, r, l) for (int i = (r); i > (l); i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define rank qwertyuio
#define next dfghjk
#define prev fhsgfhjf
#define plus fsghsf
#define minus ytryr
  
using namespace std;
  
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }
  
const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const ld eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;

int main()
{
    //freopen("circus.in", "r", stdin);
    //freopen("circus.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    //ll TL = 10.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int x;
    cin >> x;
    cout << (x / 500) * 1000 + (x % 500 / 5) * 5 << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
	
	void run() {
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		System.out.println(n-k+1);
		
	}
}


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

using namespace std;

int main(){
    int n,x, l[109];
    cin >> n >> x;
    for(int i=0;i<n;i++){
        cin >> l[i];
    }

    int ans=1, _sum=0;
    for(int i=0;i<n;i++){
        _sum+=l[i];
        if(_sum<=x){
            ans++;
        }
        else{
            break;
        }
    }
    cout << ans << endl;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  int n;
  double x;
  string u;
  cin >> n;
  double ans = 0;
  for(int i = 0; i < n; ++i)
  {
    cin >> x >> u;
    ans += (u == "JPY" ? x : x * 380000.0);
  }

  printf("%.7f\n", ans);
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
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;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  i64 D, N;
  cin >> D >> N;

  i64 ans = pow(100,D);
  if(N!=100) ans *= N;
  else ans *= 101;

  cout << ans << "\n";
}

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

Measured memory_bytes: 256
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,k,s = inm()
r = 10**9
if s==10**9:
    r = 1
for i in range(k):
    printn(str(s)+' ')
for i in range(n-k):
    printn(str(r)+' ')
print('')


Measured memory_bytes: 42588
# -*- coding: utf-8 -*-

n = int(input())
A = list(map(int, input().split()))

count = 0
flag = False
for a in A:
    if a % 4 == 0:
        count += 2
        flag = True
    elif a % 2 == 0:
        count += 1

if count >= n:
    print('Yes')
elif n % 2 == 1 and flag:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 15020
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
int main() {
    long long n, c[200005], d[200005], x;
    cin >> n;
    long long a[n], b[n];
    for (long long i = 0; i < 200005; i++) 
    {
        c[i] = 0;
        d[i] = 0;
    }
    for (long long i = 0; i < n; i++)
    {
        cin >> a[i];
        c[a[i]]++;
    }
    for (long long i = 0; i < n; i++)
    {
        cin >> b[i];
        d[b[i]]++;
    }
    for (long long i = 0; i < 200005; i++)
    {
        if (c[i] + d[i] > n)
        {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes" << endl;
    for (int i = 1; i <= n; i++)
    {
	    c[i] += c[i - 1];
	    d[i] += d[i - 1];
    }
    for (int i = 1; i <= n; i++) x = max(x, c[i] - d[i - 1]);
    for (int i = 0; i < n; i++)
    	cout << b[(i + n - x) % n] << ' ';
}


Measured memory_bytes: 9852
#include <bits/stdc++.h>
#define ll long long
using namespace std;
char s[20];
ll n,x=0,P=1,ma=-1,ans=-1;
bool used[10]={0};
void dfs(int now,ll tot){
	if (now>n){
		if (min(abs(tot-x),P-abs(tot-x))>ma){
			ma=min(abs(tot-x),P-abs(tot-x));
			ans=tot;
		}
		return ;
	}
	for (int i=0;i<10;i++){
		if (used[i]) continue;
		used[i]=1;
		dfs(now+1,tot*10+i);
		used[i]=0;
	}
}
int main(){
	scanf ("%s",s);
	n=strlen(s);
	for (int i=0;i<n;i++)
		x=x*10+s[i]-'0';
	for (int i=1;i<=n;i++) P*=10;
	dfs(1,0);
	if (ans<P/10){
		printf ("0%lld\n",ans);
		return 0;
	}
	printf ("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
int n,m,a[2],x,y;
vector<int>v[1001];
bool used[1001];
int dfs(int p){
  int res=1;
  used[p]=1;
  r(i,v[p].size()){
    if(!used[v[p][i]]){
      res+=dfs(v[p][i]);
    }
  }
  return res;
}
int main(){
  cin>>n>>m;
  r(i,m){
    cin>>x>>y;
    x--,y--;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  r(i,n)if(!used[i])a[dfs(i)>=2]++;
  cout<<abs(a[0]-a[1])<<endl;
}

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

int main() {
  int k;
  std::cin >> k;
  std::string s;
  std::cin >> s;
  if(s.size() <= k) std::cout << s << '\n';
  else {
    for (size_t i = 0; i < k; i++) {
        std::cout << s.at(i);
    }
    std::cout << "..." << '\n';
  }
}


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

// clang-format off
#define forn(i, x, y) for(int i = x; i < y; i++)
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(NULL)
// clang-format on

using LL = long long;
using VI = vector<int>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;

int main()
{
  IOS;
  int N;
  cin >> N;
  VI A(N);
  forn(i, 0, N) cin >> A[i];

  VVLL dp(N, VLL(N, 0));
  for (int i = N - 1; i >= 0; i--)
  {
    dp[i][i] = A[i];
    for (int j = i + 1; j < N; j++)
    {
      LL a = A[i] - dp[i + 1][j];
      LL b = A[j] - dp[i][j - 1];
      dp[i][j] = max(a, b);
    }
  }
  cout << dp[0][N - 1] << endl;

  return 0;
}


Measured memory_bytes: 73660
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);
    if(a[0] + a[1] == a[2])cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

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

int main(void){
   int n,ans=0;
   long int a[100001];
   long int *l = calloc(100001,sizeof(long int)),*r = calloc(100001,sizeof(long int));
   
   scanf("%d",&n);
   for(int i=1;i<=n;i++){
       scanf("%ld",&a[i]);
   }
   
   for(int i=0;i<n;i++){
       l[i+1]=gcd(l[i],a[i+1]);
   }
   for(int i=n;i>0;i--){
       r[i]=gcd(r[i+1],a[i]);
   }
   
   for(int i=1;i<=n;i++){
       if(ans<gcd(l[i-1],r[i+1])){
           ans=gcd(l[i-1],r[i+1]);
       }
   }
   printf("%d",ans);
   
}


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

int main() {
  int n,d; cin >> n>>d;
  int x, y;
  int cnt = 0;
  long long ok = pow(d, 2.0);
  long long j;
  for (int i=0; i<n; i++){
    cin >> x >> y;
    j = pow(x, 2.0) + pow(y, 2.0);
    if (j <= ok) cnt++;
  }
  cout << cnt << endl;
}

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

// a^n mod 998244353 を計算する
long long modpow(long long a, int n) {
  long long res = 1;
  while (n > 0) {
    // &はビット単位の論理積
    if (n & 1) res = res * a % 998244353;
    a = a * a % 998244353;
    // n>>=1はnの2進数表記を1ビット分右シフトするの意
    n >>= 1;
  }
  return res;
}

int main() {
  int N, flag = 0;
  cin >> N;
  long long count = 1;
  vector<int> Nei(N);
  bool end = false;
  // D1 != 0は問答無用に答え0
  int D1;
  cin >> D1;
  if (D1 != 0) end = true;
  Nei.at(D1)++;
  for (int i = 1; i < N; i++) {
    int D;
    cin >> D;
    Nei.at(D)++;
    if (flag < D) flag = D;
  }
  for (int i = 1; i < flag + 1; i++) {
    if (Nei.at(i - 1) == 0) {
      end = true;
      break;
    }
    else if (Nei.at(i - 1) > 1) count = count * modpow(Nei.at(i - 1), Nei.at(i)) % 998244353;
  }
  if (Nei.at(0) != 1 || end) cout << 0 << endl;
  else cout << count << endl;
}

Measured memory_bytes: 640
n = int(input())
p = list(map(int,input().split()))

cnt = 0

for i in range(1,n-1):
    if (p[i-1]<=p[i] and p[i]<=p[i+1])or\
        (p[i-1]>=p[i] and p[i]>=p[i+1]):
        cnt += 1
    else:
        pass
    
print(cnt)

Measured memory_bytes: 3060
List = list(map(int, input().split()))
A = list(map(int, input().split()))

for i in range(0,List[1]):
    A.append(A[i]+List[0])

D = []
for i in range(0,List[1]):
    D.append(A[i+List[1]-1]-A[i])

print(min(D))

Measured memory_bytes: 28100
//Print a rectangle
#include <stdio.h>
int main()
{
    int H, W, i, j;
    while (1)
    {
        scanf("%d%d", &H, &W);
        if (H == 0 && W == 0)
            break;
        for (i = 0; i < H; i++)
        {
            for (j = 0; j < W; j++)
            {
                putchar('#');
            }
            putchar('\n');
        }
        putchar('\n');
    }

    return 0;
}


Measured memory_bytes: 2032
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {

	class Vertex {
		int id;
		int[] vertices;
	}
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		Vertex[] vertices = new Vertex[n];
		int d[] = new int[n];
		int c[] = new int[n];
		for (int i = 0; i < n; i++) {
			vertices[i] = new Vertex();
			StringTokenizer st = new StringTokenizer(reader.readLine());
			int id = Integer.parseInt(st.nextToken());
			vertices[i].id = id;
			int cnt = Integer.parseInt(st.nextToken());
			vertices[i].vertices = new int[cnt];
			for (int j = 0; j < cnt; j++) {
				vertices[i].vertices[j] = Integer.parseInt(st.nextToken());
			}
			d[i] = c[i] = -1;
		}
		reader.close();
		
		DFS(vertices, d, c, n);
		
		for (int i = 0; i < n; i++) {
			Vertex vertex = vertices[i];
			System.out.println(vertex.id + " " + d[i] + " " + c[i]);
		}
	}

	private void DFS(Vertex[] vertices, int[] d, int[] c, int n) {
		int time = 0;
		for (int i = 0; i < n; i++) {
			Vertex vertex = vertices[i];
			Stack<Integer> stack = new Stack<Integer>();
			if (d[vertex.id - 1] == -1) {
				stack.push(vertex.id);
			}
			while (!stack.isEmpty()) {
				vertex = vertices[stack.peek()-1];
				if (d[vertex.id - 1] == -1) {
					d[vertex.id - 1] = ++time;
				}
				int id = next(vertices, d, vertex);
				if (id != -1) {
					d[id-1] = ++time;
					stack.push(id);
				} else {
					c[vertex.id - 1] = ++time;
					stack.pop();
				}
			}
		}
	}

	private int next(Vertex[] vertices, int[] d, Vertex vertex) {
		for (int i = 0; i < vertex.vertices.length; i++) {
			int id = vertex.vertices[i];
			if (d[id - 1] == -1) return id;
		}
		return -1;
	}
}



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


long gcd(long a,long b){
  if(a%b==0) return b;
  else return gcd(b,a%b);
}

int main(int argc,char* argv[]){
  long N,X,point,mod,before;
  cin >> N >> X;
  cin >> point;
  mod = abs(point-X);
  before = point;
  for(int i=1;i<N;i++){
    cin >> point;
    mod = gcd(mod,abs(point-before));
    before = point;
  }
  cout << mod << endl;
  return 0;
}


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

Measured memory_bytes: 3844
def solve():
    N = int(input())
    B = [int(i) for i in input().split()]
    ans = 0
    for i in range(N):
        if i == 0:
            ans += B[0]
        elif i == N - 1:
            ans += B[N - 2]
        else:
            ans += min(B[i - 1], B[i])
    print(ans)


if __name__ == "__main__":
    solve()

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

using namespace std;

#define rep(i,n) for(int i =0;i < (n); i++)
#define MAX 2147483647
#define ARRAY 100000
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))


int Pa[ARRAY];
int Pb[ARRAY];
int main() {
    int min = MAX;
    int A, B, M;
    cin >> A >> B >> M;
    rep(i, ARRAY) {
        Pa[i] = MAX;
        Pb[i] = MAX;
    }
    rep(i, A) {
        cin >> Pa[i];
    }
    rep(i, B) {
        cin >> Pb[i];
    }

    rep(i, M) {
        int x, y, d;
        cin >> x >> y >> d;
        int sum = Pa[x-1] + Pb[y-1] - d;
        if(min > sum) {
            min = sum;
        }
    }
    std::sort(Pa, Pa + SIZE_OF_ARRAY(Pa));
    std::sort(Pb, Pb + SIZE_OF_ARRAY(Pb));

    for(int i = 0;i < A; ++i) {
        for(int j =0;j < B; ++j){
            int sum = Pa[i] + Pb[j];
            if(min > sum) {
                min = sum;
            } else {
                //cout << sum << "HERE" << endl;
                break;
            }
        }
    }

    cout << min << endl;

    return 0;
}

Measured memory_bytes: 1024
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//#include <ext/pb_ds/detail/standard_policies.hpp>
#include<set>
#include<map>
#include <unordered_map>
#include <unordered_set>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include<math.h>
#include <strings.h>
#include <fstream>


#define f first
#define s second
#define pb push_back
#define lp(i,a,n) for(int (i)=(a);(i)<=(int)(n);(i)++)
#define lpd(i,n,a) for(int (i)=(n);(i)>=(a);--(i))
#define mp make_pair
#define clr(a, b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define mod 1000000007
#define eps 1e-8
#define infi 2e9
#define infll 1e18
#define MX 1000000
#define X real()
#define Y imag()
#define polar(r,t) ((r)* exp(point(0,(t))))
#define length(a) hypot( (a).X , (a).Y )
#define angle(a) atan2( (a).Y , (a).X )
#define vec(a,b) ( (b) - (a) )
#define dot(a,b) (conj(a)*(b)).X
#define cross(a,b) (conj(a)*(b)).Y
#define lengthsqr(a) dot(a,a)
#define reflect(V,M) (conj((V)/(M)) * (M))
//#define rotate(a, theta) (a) * (polar(1.0, (theta) ))
#define normalize(a)   ((a)/length(a))
#define ccw(a,b,c) cross(vec(a,b) , vec(a,c)) > eps
#define cosRule(a,b,c) (acos(((a)*(a)+(b)*(b)-(c)*(c))/(2*(a)*(b))))
#define cosDot(a,b) (acos(dot(a,b)/length(a)/length(b)))
#define EQ(a,b) (fabs((a) - (b)) <= eps) /* equal to */
#define NE(a,b) (fabs((a) - (b)) > eps)  /* not equal to */
#define LT(a,b) ((a) < (b) - eps)        /* less than */
#define GT(a,b) ((a) > (b) + eps)        /* greater than */
#define LE(a,b) ((a) <= (b) + eps)       /* less than or equal to */
#define GE(a,b) ((a) >= (b) - eps)       /* greater than or equal to */
#define mod1 100050001
#define mod2 100030001
#define base1 37
#define base2 31
#define PI acos(-1)
#define sz(a) (int) (a).size()

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef set<int> si;
typedef map<int, int> mii;
typedef complex<long double> point;
typedef pair<point, point> line;
typedef pair<double , point> Circle;
typedef long double ld;


const int N = 100002;

int n,a[N];
bool isComp[N];


int main() {
    scanf("%d",&n);
    
    vi a;
    lp(i, 2, N-1) if(!isComp[i]) {
        if(i%5 == 1) a.pb(i);
        if(sz(a) == n) break;
        
        for(ll j = 1ll*i*i ; j < N ; j += i)
            isComp[j] = true;
    }
    
    for(int x: a) printf("%d ", x);
    printf("\n");
    
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
   string s,ss="";
    cin>>s;
   stack<char>st;
   for(int i=0;i<s.size();i++)
   {
       if(s[i]!='B')st.push(s[i]);
       else
       {
           if(st.size()!=0)st.pop();
       }
   }
   while(!st.empty())
   {
       ss+=st.top();
       st.pop();
   }
   if(ss.size()!=0)
   reverse(ss.begin(),ss.end());
   cout<<ss<<endl;

}


Measured memory_bytes: 256
code = r"""
# distutils: language=c++
# distutils: include_dirs=/opt/ac-library
from libcpp cimport bool
from libcpp.vector cimport vector
cdef extern from "<atcoder/segtree>" namespace "atcoder" nogil:
    cdef cppclass segtree[S, OP, E]:
        segtree(vector[S] v)
        void set(int p, S x)
        S get(int p)
        S prod(int l, int r)
        S all_prod()
        int max_right[F](int l)
        int min_left[F](int r)
ctypedef long seg_t
cdef extern from *:
    ctypedef int op_t "myop"
    ctypedef int e_t "mye"
    ctypedef int f_t "myf"
    cdef seg_t myop(seg_t a, seg_t b) nogil
    cdef seg_t mye() nogil
    cdef bool myf(seg_t k) nogil
cdef seg_t myop(seg_t a, seg_t b) nogil:
    if a > b:
        return a
    else:
        return b
cdef seg_t mye() nogil:
    return 0
cdef seg_t v
cdef bool myf(seg_t k) nogil:
    return k < v

from cython.parallel cimport prange
from libc.stdio cimport getchar, printf
cdef inline long read() nogil:
    cdef long b, c = 0
    while 1:
        b = getchar() - 48
        if b < 0: return c
        c = c * 10 + b
cdef main():
    cdef long n = read(), k = read(), i
    cdef seg_t a
    cdef segtree[seg_t, op_t, e_t] *seg = new segtree[seg_t, op_t, e_t](vector[seg_t](600001, 0))
    for i in range(n):
        a = read()
        seg.set(a, seg.prod(myop(0, a - k), a + k + 1) + 1)
    printf('%ld\n', seg.all_prod())
main()
"""
import os, sys
if sys.argv[-1] == 'ONLINE_JUDGE':
    open('solve.pyx', 'w').write(code)
    os.system('cythonize -i -3 -b solve.pyx')
import solve

Measured memory_bytes: 30832
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


int main(){
    string s;cin  >> s;
    ll cnt=0;
    rep(i,3)if(s[i]=='R')cnt++;
    if(cnt==0)cout << 0 <<endl;
    if(cnt==1)cout << 1 <<endl;
    if(cnt==2){
        if(s[0]=='R'&&s[2]=='R')cout << 1 <<endl;
        else cout << 2 << endl;
    }
    if(cnt==3)cout << 3 <<endl;
}

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

  int N ;
  cin >> N ; 
  vector<int> h(N) ;
  rep(i,N) cin >> h.at(i) ;
  int count =  h[0] ;
  rep(i,N-1){
     if( h[i] < h[i+1] ) count += h[i+1] - h[i] ; 
  }
  cout << count << endl;
}

Measured memory_bytes: 256
import math

k = int(input())

l = [1, 2, 3, 4, 5, 6, 7, 8, 9]

c = 0
while k > len(l):
    f = l[c] - (l[c] // 10 * 10)

    if f != 0:
        l.append(l[c] * 10 + f - 1)

    l.append(l[c] * 10 + f)

    if f != 9:
        l.append(l[c] * 10 + f + 1)

    c += 1

print(l[k - 1])

Measured memory_bytes: 7160
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

class edge{
public:
	Int cost;
	size_t from, to;
	edge(Int c, size_t f, size_t t){
		cost = c;
		from = f;
		to = t;
	}
};
using edges = vector<edge>;
using graph = vector<edges>;
void readgraph(graph &g, size_t E, bool D, bool C, bool Z){ // E:num_of_edges, D:directed, C:costed, Z:already 0-indexed
	for(size_t i=0; i<E; ++i){
		edge e(1, 0, 0);
		if(!C) cin >> e.from >> e.to;
		else cin >> e.from >> e.to >> e.cost;
		if(!Z){
			--e.from;
			--e.to;
		}
		g[e.from].push_back(e);
		if(!D){
			swap(e.from, e.to);
			g[e.from].push_back(e);
		}
	}
}
bool operator<(const edge &e, const edge &f){
	return e.cost != f.cost ? e.cost > f.cost : e.from != f.from ? e.from < f.from : e.to < f.to;
}
void dijkstra(const graph &g, size_t s, vector<Int> &dist, vector<Int> &prev){
	size_t V = g.size();
	dist = vector<Int>(V, 1e18);
	prev = vector<Int>(V, -1);
	priority_queue<edge> q;
	for(auto e:g[s]){
		dist[e.to] = 1;
		q.push(edge(1, s, e.to));
	}
	while(!q.empty()){
		edge e = q.top(); q.pop();
		if(dist[e.to] < e.cost) continue;
		for(edge f:g[e.to]){
			if(dist[f.to] > dist[e.to] + f.cost){
				dist[f.to] = dist[e.to] + f.cost;
				prev[f.to] = f.from;
				q.push(edge(dist[f.to], s, f.to));
			}
		}
	}
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	Int n, m; cin >> n >> m;
	graph g(n);
	readgraph(g, m, true, false, false);
	vector<vector<Int>> d(n, vector<Int>(n, 1e18));
	vector<vector<Int>> p(n, vector<Int>(n, -1));
	for(Int i=0; i<n; ++i) dijkstra(g, i, d[i], p[i]);
//	for(Int i=0; i<n; ++i)
//		for(Int j=0; j<n; ++j)
//			cout << d[i][j] << " \n"[j+1==n];
	Int s = 1e9, v = -1;
	for(Int i=0; i<n; ++i)
		if(d[i][i] < s){
			s = d[i][i];
			v = i;
		}
	if(s == 1e9){
		cout << -1 << "\n";
		return 0;
	}
	cout << s << "\n";
	set<Int> st;
	st.insert(v);
	Int t = v;
	while(st.find(p[v][t]) == st.end() && p[v][t] != -1){
		st.insert(p[v][t]);
		t = p[v][t];
	}
	for(auto ite=st.begin(); ite!=st.end(); ++ite)
		cout << (*ite) + 1 << "\n";
}

Measured memory_bytes: 16000
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> T;
#define INF (1 << 30)
int n, dist[2][210], window[2][210];
vector<T> edge[2][210];
bool come[2][210];
int main(){
    while(cin >> n, n){
	for(int j = 0;j < 2;j++){
	    for(int i = 0;i < n;i++){
		cin >> window[j][i];
		dist[j][i] = INF;
		come[j][i] = false;
		edge[j][i].clear();
	    }
	}
	for(int j = 0;j < 2;j++){
	    for(int i = 0;i < n;i++){
		if(window[j][i] == 0 ||(window[j][i] == 1 && window[j][i + 1] != 1)){
		    for(int k = 0;k <= 2;k++){
			edge[j][i].push_back(T(1, P(!j, i + k)));
		    }
		}
		if(window[j][i + 1] == 1 && window[j][i] == 1){
		    edge[j][i].push_back(T(0, P(j, i + 1)));
		}
		if(window[j][i] == 2){
		    edge[j][i].push_back(T(0, P(j, i - 1)));
		}
	    }
	}
	priority_queue<T, vector<T>, greater<T> > pq;
	pq.push(T(0, P(0, 0)));
	pq.push(T(0, P(1, 0)));
	dist[0][0] = dist[1][0] = 0;
	while(!pq.empty()){
	    T tmp = pq.top();pq.pop();
	    int d = tmp.first, x = tmp.second.first, y = tmp.second.second;
	    come[x][y] = true;
	    if(dist[x][y] < d)continue;
	    for(int i = 0;i < edge[x][y].size();i++){
		P to = edge[x][y][i].second;
		int r = edge[x][y][i].first, tx = to.first, ty = to.second;
		if(dist[tx][ty] <= d + r)continue;
		dist[tx][ty] = d + r;
		pq.push(T(dist[tx][ty], to));
	    }
	}
	int res = min((window[0][n - 1]==2)?INF:dist[0][n - 1], (window[1][n - 1]==2)?INF:dist[1][n - 1]);
	if(res == INF)cout << "NA" << endl;
	else cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 1220
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define PRECISION(x) std::fixed << std::setprecision(x)

using namespace std;

using ll = long long;
using VI = std::vector<int>;
using VI2D = std::vector<vector<int>>;
using VLL = std::vector<long long>;
using VLL2D = std::vector<vector<long long>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	int n;
	cin >> n;
	VLL a(n);
	REP(i, n) { cin >> a[i]; }
	sort(ALL(a), greater<ll>());
	ll result[2] = {};
	VLL b1(n);
	REP(i, n) {
		if(i == 0) {
			b1[0] = 1;
			continue;
		}
		if(i == n - 1) {
			b1[n - 1] = (i % 2 == 0 ? 1 : -1);
			continue;
		}
		b1[i] = (i % 2 == 0 ? 2 : -2);
	}
	sort(ALL(b1), greater<ll>());
	REP(i, n) { result[0] += a[i] * b1[i]; }
	VLL b2(n);
	REP(i, n) {
		if(i == 0) {
			b2[0] = -1;
			continue;
		}
		if(i == n - 1) {
			b2[n - 1] = (i % 2 ? 1 : -1);
			continue;
		}
		b2[i] = (i % 2 ? 2 : -2);
	}
	sort(ALL(b2), greater<ll>());
	REP(i, n) { result[1] += a[i] * b2[i]; }
	cout << max(result[0], result[1]) << endl;
	return 0;
}


Measured memory_bytes: 5580
#include <iostream>

using namespace std;

int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
    if(A + B > C + D) {
        cout << "Left" << endl;
    } else if(A + B < C + D) {
        cout << "Right" << endl;
    } else {
        cout << "Balanced" << endl;
    }
}


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

using namespace std;

int main() {
#ifdef  DEBUG
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
#endif  // for local.
  int a, b;
  cin >> a >> b;
  int ans;
  ans = a + b;
  ans = ans / 2 + (ans & 0x1);

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <climits>
#include <queue>
using namespace std;

const int M = 1e5 + 5;

struct Edge {
  int v, c, d;
};

struct Query {
  int id, x, y, delta;
};

int n, m;
vector<Edge> g[M];
vector<Query> qr[M];
int fa[M][19], dep[M], dis[M], ans[M], cnt[M], len[M];

void Link(int u, int v, int c, int d) {
  g[u].push_back({v, c, d});
}

void Dfs(int u) {
  for (auto &e : g[u]) {
    int v = e.v;
    if (v == fa[u][0]) continue;
    dep[v] = dep[u] + 1;
    fa[v][0] = u;
    for (int i = 1; i < 19; i++) {
      fa[v][i] = fa[fa[v][i - 1]][i - 1];
    }
    dis[v] = dis[u] + e.d;
    Dfs(v);
  }
}

int LCA(int u, int v) {
  if (dep[u] > dep[v]) swap(u, v);
  int diff = dep[v] - dep[u];
  for (int i = 0; i < 19; i++) {
    if (diff >> i & 1) {
      v = fa[v][i];
    }
  }
  if (u == v) return u;
  for (int i = 18; i >= 0; i--) {
    if (fa[u][i] != fa[v][i]) {
      u = fa[u][i];
      v = fa[v][i];
    }
  }
  return fa[u][0];
}

void Dfs2(int u) {
  for (auto &q : qr[u]) {
    ans[q.id] += (dis[u] - len[q.x] + cnt[q.x] * q.y) * q.delta;
  }

  for (auto &e : g[u]) {
    int v = e.v;
    if (v == fa[u][0]) continue;
    int c = e.c, d = e.d;
    cnt[c]++;
    len[c] += d;
    Dfs2(v);
    cnt[c]--;
    len[c] -= d;
  }
}

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

  for (int i = 1; i < n; i++) {
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    Link(a, b, c, d);
    Link(b, a, c, d);
  }

  Dfs(1);

  for (int i = 1; i <= m; i++) {
    int x, y, u, v;
    scanf("%d %d %d %d", &x, &y, &u, &v);
    int lca = LCA(u, v);
    qr[u].push_back({i, x, y, 1});
    qr[v].push_back({i, x, y, 1});
    qr[lca].push_back({i, x, y, -2});
  }

  Dfs2(1);

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


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

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

    int x;
    cin>>x;

    int c=(x%100)/5;
    c+=((x%100)%5+4)/5;

    puts(c<=(x/100)?"1":"0");

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
 
using namespace std;
const int mx=1000009;
typedef long long ll;
//int dp[100][100][300];
ll mod=1000000007;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
  
   int d,t,s;
   cin>>d>>t>>s;

   int zz=0;int time=0;
   while(zz<d){
       time++;
       zz+=s;
   }
if(time<=t){cout<<"Yes";}else{cout<<"No";}
}

Measured memory_bytes: 3644
x = input()

st_10_2 = "S" * 10 * 10 + "T" * 10 * 10
st_10_3 = "S" * 10 * 10 * 10 + "T" * 10 * 10 * 10

while True:
    x = x.replace(st_10_3,"").replace(st_10_2,"").replace("ST","")
    if "ST" not in x:
        break

print(len(x))

Measured memory_bytes: 3560
while True:
    N, M = map(int, input().split())
    if (N | M) == 0:
        break

    A = [int(x) for x in input().split()]

    ans = 0

    M //= N

    for a in A:
        if a < M:
            ans += a
        else:
            ans += M

    print(ans)



Measured memory_bytes: 5616
from collections import Counter

N,*A = map(int,open(0).read().split())
#j - i = Aj + Ai
#j - Aj = Ai + i
#L = i + Ai, R = j - Aj とおく
L = []
R = []
for i in range(N):
    L.append(i+1 + A[i])
    R.append(i+1 - A[i])
l = Counter(L)
r = Counter(R)
 
#print(l)
#print(r)

cnt = 0
a=[]
for i in range(1,N+1):
    if i in l and i in r:
        cnt += l[i]*r[i]
        a.append(i)
print(cnt)

Measured memory_bytes: 64528
// inputに入力データ全体が入る
function Main(input) {
    var N = input[0]-0;
    var map = {};
    var map2 = {};
    var list = input[1].split(" ").map(v=>v-0).sort((a,b)=>a-b);
    var ansmap = {};
    var sum = 0;
    list.forEach((v,i)=>{
        if(ansmap[v]){
            ansmap[v]++;
            if(list[i+1]!=v)
                sum += ansmap[v]*(ansmap[v]-1)/2;
        }else{
            ansmap[v] = 1;
            if(list[i+1]!=v)
                sum += ansmap[v]*(ansmap[v]-1)/2;
        }
    });
    var anss = [];
    input[1].split(" ").forEach(v=>{
        anss.push(sum-((ansmap[v]-1)));
    });

    console.log(anss.join("\n"));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n"));

Measured memory_bytes: 91600
N,M,C = (int(X) for X in input().split())
B = [int(X) for X in input().split()]
Count = 0
for T in range(0,N):
    A = [int(X) for X in input().split()]
    if sum([X*Y for X,Y in zip(A,B)])+C>0:
        Count += 1
print(Count)

Measured memory_bytes: 9140
#include<bits/stdc++.h>
#define int long long
#define dd second
#define mp make_pair
#define pb push_back
#define ff first
#define dd second
#define pp pair<int,int>
using namespace std;

int tab[2001];

int32_t main()
{
    ios_base::sync_with_stdio(false);
    int n; int sum = 0;
    cin >> n;
    for(int i = 0; i < n; ++i)
    {
        int temp; cin >> temp; sum += temp;
        tab[i] = temp;
    }
    bitset<4000001> s;
    s.set(0);
    s.set(0,1);
    for(int i = 0; i < n; ++i)
    {
        s |= (s << tab[i]);
    }
    for(int i = (sum-1)/2+1; ; ++i)
    {
        if(s[i])
        {
            cout << i << "\n"; exit(0);
        }
    }
    return 0;
}



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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;

int main()
{
    int y, m, d;
    scanf("%d/%d/%d", &y, &m, &d);

    string S;
    if (y >= 2019 && m >= 4) {
        if (y == 2019 && m == 4) {
            S = "Heisei";
        }
        else {
            S = "TBD";
        }
    }
    else {
        S = "Heisei";
    }

    cout << S << endl;
    
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

n = int(input())

X = list(map(int, input().split()))
Y = list(map(int, input().split()))

D1 = 0
D2 = 0
D3 = 0
max = 0
for i in range(n):
   diff = abs(X[i] - Y[i])
   D1 += diff
   D2 += diff**2
   D3 += diff**3
   if diff > max:
      max = diff

print('{:.6f}'.format(D1))
print(D2**(1 / 2))
print(D3**(1.0 / 3.0))
print('{:.6f}'.format(max))


      



Measured memory_bytes: 5648
#include<iostream>
using namespace std;
typedef long long ll;
int main(){
  ll n,cnt=0;
  cin >> n;
  ll a[n+1],b[n];
  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;i++){
    if(a[i]>=b[i]){
      a[i]-=b[i];
      cnt+=b[i];
      b[i]=0;
    }else{
      b[i]-=a[i];
      cnt+=a[i];
      a[i]=0;
    }
    if(a[i+1]>=b[i]){
      a[i+1]-=b[i];
      cnt+=b[i];
      b[i]=0;
    }else{
      b[i]-=a[i+1];
      cnt+=a[i+1];
      a[i+1]=0;
    }
  }
  cout << cnt <<endl;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#ifndef INFINITY
#define INFINITY 2147483647
#endif

void merge(int *, int, int, int);
void mergeSort(int *, int, int);

int count=0;

int main(){
  int A[500000];
  int n, i, left, right;

  scanf("%d", &n);
  for(i=0;i<n;i++) scanf("%d", &A[i]);
  left=0;
  right=n;
  mergeSort(A, left, right);

  for(i=0;i<n-1;i++) printf("%d ", A[i]);
  printf("%d\n%d\n", A[i], count);

  return 0;
}

void merge(int *A, int l, int mid, int r){
  int i, j, k, n1, n2 ,*L, *R;
  n1 = mid - l;
  n2 = r - mid;
  L = (int *)malloc((n1+1)*sizeof(int));
  R = (int *)malloc((n2+1)*sizeof(int));
  
  for(i=0;i<n1;i++) L[i] = A[l+i];
  for(i=0;i<n2;i++) R[i] = A[mid+i];
  L[n1] = INFINITY;
  R[n2] = INFINITY;
  i=j=0;
  for(k=l;k<r;k++){
    if(L[i]<=R[j]){
      A[k] = L[i];
      i++;
    }
    else {
      A[k] = R[j];
      j++;
    }
    count++;
  }
  free(L);
  free(R);
}

void mergeSort(int *A, int l, int r){
  int mid;
  if(l+1<r){
    mid = (l+r)/2;
    mergeSort(A, l, mid);
    mergeSort(A, mid, r);
    merge(A, l, mid, r);
  }
}

Measured memory_bytes: 4480
#include <stdio.h>
#include <iostream>
#include <map>
#include <algorithm>
#include <string.h>
#include <vector>

using namespace std;

int main() {
    map<string, int> m;
    int n;
    vector<string> c;

    scanf("%d", &n);

    int i, j, k;

    for(i = 0; i < n; i++) {
        string str;
        cin >> str;
        if (m.find(str) == m.end()) {
            m[str] = 1;
        } else {
            m[str]++;
        }
    }

    map<string, int>::iterator it = m.begin();

    int max = -100;
    while (it != m.end()) {
        if (max < it->second)
            max = it->second;
        it++;
    }

    int pos = 0;

    for(it = m.begin(); it != m.end(); it++) {
        if (max == it -> second) {
            c.push_back(it -> first);
        }
    }

    sort(c.begin(), c.end());

    vector<string>::iterator itstr;

    for(itstr = c.begin(); itstr != c.end(); itstr++) {
        cout<<*itstr<<endl;
    }

    return 0;
}



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

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

const int MOD = 1000000007;

int main() {
	int h, w;
	cin >> h >> w;
	long long dp[1000] = {0};
	dp[0]++;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			char a;
			cin >> a;
			if (a == '#') dp[j] = 0;
			else {
				if (j >= 1) dp[j] = (dp[j] + dp[j-1]) % MOD;
			}
		}
	}
	int ans = dp[w-1];
	cout << ans << endl;
	return 0;
}

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

class Robot {
    public int start;
    public int end;
    public int dup = 0;
    public Robot(int pos, int len) {
        start = pos - len;
        end = pos + len;
    }
}

class Program {
    static void Main(string[] args) {
        int N, K, S;
        Input(out N, out K, out S);
        int[] X = new int[N];
        for(int i = 0; i < K; i++) {
            X[i] = S;
        }
        if(S == 1000000000) {
            for(int i = K; i < N; i++) {
                X[i] = 1;
            }
        } else {
            for(int i = K; i < N; i++) {
                X[i] = 1000000000;
            }
        }
        Console.WriteLine(string.Join(" ", X));
    }
    static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T));
    static void Input<A>(out A a) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
    }
    static void Input<A, B>(out A a, out B b) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
    }
    static void Input<A, B, C>(out A a, out B b, out C c) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
    }
    static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
    }
    static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
    }
    static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
        f = ChangeT<F>(words[5]);
    }
    static void InputArray<T>(out T[] array) {
        array = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries).Select(s => ChangeT<T>(s)).ToArray();
    }
}

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

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()

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

    vector<int> A(N);
    vector<int> B(N);
    REP(i,N){
        cin >> A[i];
    }
    REP(i,N){
        cin >> B[i];
    }

        int total = 0;
        REP(i,N/2 + 1){
            total += A[i];
        }
        FOR(i,N/2,N){
            total += B[i];
        }
    int t = total, max1=total, max2= total;
        FOR(i,N/2 + 1, N){
            total = total + A[i] - B[i - 1];
max1 = max(total,max1);
        }
        for(int i = N/2 - 1; i >= 0; i--){
            t = t + B[i] - A[i+1];
max2 = max(t, max2);
        }
if(max1 >= max2) cout << max1;
else cout << max2;
}

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

int main() {
  string S; cin >> S;
  int N = S.length();

  bool right = true;
  vector<int> count;
  int c = 0;
  for (int i=0; i<N; i++) {
    if (right && S[i]=='R' || !right && S[i]=='L') {
      c++;
    } else {
      count.push_back(c);
      right = !right;
      c = 1;
    }
  }
  count.push_back(c);

  // S[i] == 'R' && dist[i] == d
  // -> Rの右端までの距離はd
  // S[i] == 'L' && dist[i] == d
  // -> Lの左端までの距離はd
  right = true;
  int dist[N] = {};
  int idx = 0;
  for (int x: count) {
    for (int j=0; j<x; j++) {
      if (right) {
        dist[idx+j] = x-j-1;
      } else {
        dist[idx+j] = -j;
      }
    }
    right = !right;
    idx += x;
  }
  int ans[N] = {};
  for (int i=0; i<N; i++) ans[i+dist[i]+dist[i]%2]++;
  for (int i=0; i<N-1; i++) cout << ans[i] << " ";
  cout << ans[N-1] << endl;
}


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

priority_queue<int> Q;
vector<P> v;

int main() {
    ll n, m; cin >> n >> m;
    ll ans; 
    for (int i=0; i<n; ++i) {
        int a, b;
        cin >> a >> b;
        v.push_back(make_pair(a, b));
    }
    sort(v.begin(), v.end());
    
    int j = 0;
    for (int i=1; i<=m; ++i) {
        while (v[j].first<=i && j<v.size()) {
            Q.push(v[j].second);
            j++;
        }
        if (Q.size()==0) continue;
        int k = Q.top(); Q.pop();
        ans += k;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 2672
n = int(raw_input())
s = [0,0,0,0,0,0,0,0,0,0,0,0,0,0]
h = [0,0,0,0,0,0,0,0,0,0,0,0,0,0]
c = [0,0,0,0,0,0,0,0,0,0,0,0,0,0]
d = [0,0,0,0,0,0,0,0,0,0,0,0,0,0]

for i in range(n):
    x = raw_input().split()
    x[1] = int(x[1])
    if x[0] == "S":
        s[x[1]] = 1
    elif x[0] == "H":
        h[x[1]] = 1
    elif x[0] == "C":
        c[x[1]] = 1
    elif x[0] == "D":
        d[x[1]] = 1

for i in range(1,14):
    if s[i] != 1:
        print "S %d" %i
for i in range(1,14):
    if h[i] != 1:
        print "H %d" %i
for i in range(1,14):
    if c[i] != 1:
        print "C %d" %i
for i in range(1,14):
    if d[i] != 1:
        print "D %d" %i

Measured memory_bytes: 6412