akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    ll N, ans;
    cin >> N;
    vector<ll> A(N),B(N);
    REP(int,i,0,N){
        cin >> A.at(i);
        B.at(i) = A.at(i);
    }
    sort(A.begin(),A.end());
    ll Med1 = A.at(N/2-1);
    ll Med2 = A.at(N/2);
    REP(int,i,0,N){
        if ( B.at(i) <= Med1 ) cout << Med2 << endl;
        else cout << Med1 << endl;
    }
    return 0;
}

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

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("1000 15 80");
            //Yes
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("2000 20 100");
            //Yes
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("10000 1 1");
            //No
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray();

        int D = wkArr[0];
        int T = wkArr[1];
        int S = wkArr[2];

        if (D <= T * S) {
            Console.WriteLine("Yes");
        }
        else {
            Console.WriteLine("No");
        }
    }
}


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

typedef long long ll;


struct Node{
    ll key;
    Node *parent,*left,*right;
};


struct Tree{
    Node *nil,*root;

    void init(){
        root=nil;
    }

    void add(ll key){
        Node *newnode;
        Node *p;
        newnode = (Node*)malloc(sizeof(Node));

        newnode->key = key;
        newnode->parent = newnode->right = newnode->left = nil;

        Node *pa = find_parent(key);
        if(pa == nil){
            root = newnode;
        }else if(key < pa->key){
            pa->left = newnode;
        }else{
            pa->right = newnode;
        }
    }

    Node* find_parent(int key){
        Node *pa=nil;
        Node *loc=root;
        while(loc != nil){
            pa = loc;
            if(key < loc->key){
                loc = loc->left;
            }else{
                loc = loc->right;
            }
        }
        return pa;
    }

    void find_x(int x){
        Node *p=root;
        bool flg = false;
        while(p != nil){
            if(x == p->key){
                flg = true;
                break;
            }else if(x < p->key){
                p = p->left;
            }else{
                p = p->right;
            }
        }
        if(flg)cout << "yes\n";
        else cout << "no\n";
    }

    void print_in(Node *r){
        if(r==nil)return;
        print_in(r->left);
        cout << " " << r->key;
        print_in(r->right);
    }

    void print_pre(Node *r){
        if(r==nil)return;
        cout << " " << r->key;
        print_pre(r->left);
        print_pre(r->right);
    }
    void print(){
        print_in(root);
        cout << endl;
        print_pre(root);
        cout << endl;
    }
};


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

    Tree tree;
    tree.init();
    int n;
    cin >> n;
    string s;
    int k;
    for(int i=0;i<n;i++){
        cin >> s;
        if(s=="insert"){
            cin >> k;
            tree.add(k);
        }else if(s=="find"){
            cin >> k;
            tree.find_x(k);
        }else{
            tree.print();
        }
    }
    return 0;
}



Measured memory_bytes: 21880
#include<stdio.h>
    int main(){
    int N,M,c,d,i;
    int a[200001]={0},b[200001]={0};
    scanf("%d%d",&N,&M);
    for(i=0;i<M;i++){
    scanf("%d%d",&c,&d);
      if(c==1){
      a[d]=1;
      }
      if(d==N){
      b[c]=1;
      }
    }
    for(i=0;i<N;i++){
      if(a[i]==1){
        if(b[i]==1){
        printf("POSSIBLE\n");
        return 0;
        }
      }
    }
    printf("IMPOSSIBLE\n");
    return 0;
    }

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

long long N, dp[59][59][59], nr[59][59], mod = 1000000007;

void init() {
	for (int i = 0; i < 59; i++) {
		for (int j = 0; j < 59; j++) {
			if (i == 0 || j == 0) nr[i][j] = 1;
			else nr[i][j] = (nr[i - 1][j] + nr[i][j - 1]) % mod;
		}
	}
}

long long ncr(long long n, long long r) {
	return nr[n - r][r];
}

long long solve(int pos, int ca, int cb) {
	if (pos == N) {
		if (ca == 0 && cb == 0) return 1;
		return 0;
	}
	if (dp[pos][ca][cb] >= 0) return dp[pos][ca][cb];

	long long sum = 0;
	for (int i = 0; i <= N - pos; i++) {
		for (int j = 0; j <= N - pos; j++) {
			if ((i + j) < (ca + cb)) continue;
			if ((i + j) % 2 != (ca + cb) % 2) continue;
			if (pos + i + j > N || i + j == 0) continue;

			long long la = 0, lb = 0;
			if ((ca - cb) > (i - j)) la = ((ca - cb) - (i - j)) / 2; 
			else lb = ((i - j) - (ca - cb)) / 2;

			long long P1 = ncr(pos + i, i);
			long long P2 = ncr(pos + i + j, j);
			long long P3 = solve(pos + i + j, la, lb);
			sum += (P1*P2%mod)*P3%mod; sum %= mod;
		}
	}
	dp[pos][ca][cb] = sum;
	return sum;
}

int main() {
	cin >> N; init();
	for (int i = 0; i <= N; i++) { for (int j = 0; j <= N; j++) { for (int k = 0; k <= N; k++) dp[i][j][k] = -1; } }

	long long A = solve(1, 0, 0);
	long long B = solve(1, 1, 0);
	cout << (A + B) % mod << endl;
	return 0;
}

Measured memory_bytes: 1664
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var H = input[0];
            var W = input[1];
            var grid = new char[H, W];

            for (int i = 0; i < H; i++)
            {
                var line = Console.ReadLine();
                for (int j = 0; j < W; j++)
                {
                    grid[i, j] = line[j];
                }
            }

            var hSkip = new bool[H];
            var wSkip = new bool[W];

            for (int i = 0; i < H; i++)
            {
                var skip = true;
                for (int j = 0; j < W; j++)
                {
                    if (grid[i, j] == '#') skip = false;
                }
                if (skip) hSkip[i] = true;
            }

            for (int i = 0; i < W; i++)
            {
                var skip = true;
                for (int j = 0; j < H; j++)
                {
                    if (grid[j, i] == '#') skip = false;
                }
                if (skip) wSkip[i] = true;
            }

            for (int i = 0; i < H; i++)
            {
                if (hSkip[i]) continue;
                for (int j = 0; j < W; j++)
                {
                    if (wSkip[j]) continue;
                    Console.Write(grid[i, j]);
                }
                Console.WriteLine();
            }
        }
    }
}

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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin >> s;
	int ans = 0;
	for(int i = 0; i<s.length();i++)
	{
		if(s[i]=='?')
			s[i] = 'D';
	}
	cout <<s;

}


Measured memory_bytes: 3736
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC115A
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = int.Parse(Console.ReadLine());


            switch(x)
            {
                case 24:
                    Console.WriteLine("Christmas Eve");
                break;

                case 25:
                    Console.WriteLine("Christmas");
                    break;

                case 23:
                    Console.WriteLine("Christmas Eve Eve");
                    break;

                case 22:
                    Console.WriteLine("Christmas Eve Eve Eve");
                    break;

            }
            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 9044
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> l(m), r(m);
  int x = 1, y = n;
  for (int i = 0; i < m; i++) {
    cin >> l[i] >> r[i];
    x = max(x, l[i]);
    y = min(y, r[i]);
  }
  int ans = 0;
  if (y >= x) {
    ans = y - x + 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
while True:
    mfr=list(map(int,input().split()))
    if mfr[0]==-1 and mfr[1]==-1 and mfr[2]==-1:
        break
    
    if mfr[0]==-1 or mfr[1]==-1:
        s='F'
        
    elif mfr[0]+mfr[1]>=80:
        s='A'
    elif mfr[0]+mfr[1]>=65:
        s='B'
    elif mfr[0]+mfr[1]>=50:
        s='C'
    elif mfr[0]+mfr[1]>=30:
        if mfr[2]>=50:
            s='C'
        else:
            s='D'
    elif mfr[0]+mfr[1]<30:
        s='F'

    print(s)
    
        
    


Measured memory_bytes: 5596
#include <iostream>
#include <cstdio>

int main(int argc, const char * argv[])
{
    double a, b, c, d, e, f, x, y;
    //cin >> a >> b >> c >> d >> e >> f
//    while (scanf("%lf %lf %lf %lf %lf %lf ", &a, &b, &c, &d, &e, &f) != EOF) {
    
    while (std::cin >> a >> b >> c >> d >> e >> f) {
        x = y = 0;
        x = (b*f - c*e) / (b*d - a*e);
        if (b*f == c*e) {
            x = 0;
        }
        y = ((a*b*f - a*c*e) / (a*b*e- b*b*d) + c / b);
        printf("%.3f %.3f\n", x, y);
    }
    
    return 0;
}

Measured memory_bytes: 1236
#include <stdio.h>
#include <cmath>


int main() {
  double x1,y1,x2,y2;
  scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
  double d = sqrt(pow((x1-x2),2) + pow((y1 - y2),2));
  printf("%lf",d);
}


Measured memory_bytes: 2736
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    string s;
    cin >> s;
 
    bool ok = false;
    rep(i, 3) {
        if(s[i] == '7') {
            ok = true;
        }
    }
 
    if(ok) {
        out("Yes");
    }
    else {
        out("No");
    }
 
    re0;
}

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



int main()
{
    ios::sync_with_stdio(false);
    string s;
    ll k;
    cin >> s >> k;

    for (int i = 0; i < s.size(); i++) {
        if (s[i] != '1' && i < k) {
            cout << s[i] << endl;
            return 0;
        }
    }
    cout << 1 << endl;

    return 0;
}


Measured memory_bytes: 256
def exe_matrix():
    n,m=tuple(map(int,input().split()))
    
    A=[]
    
    for i in range(n):
        row=list(map(int,input().split()))
        
        A.append(row)
        
    v=[]
    
    for i in range(m):
        x=int(input())
        v.append(x)
        
        
    out=[0 for i in range(n)]
    
    for i in range(n):
        for j in range(m):
            out[i]+=A[i][j]*v[j]
            
            
    for i in out:
        print(i)


exe_matrix()


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

bool isACGT(char a){
    if (
        a == 'A'
        || a == 'C'
        || a == 'G'
        || a == 'T') return true;
    else return false;
}

int main() {
    string S;
    cin >> S;
    int ans = 0;
    for (int i = 0; i < S.length(); ++i){
        int counter = 0;
        for (int j = i; j < S.length(); ++j){
            if ( isACGT(S[j]) ) counter++;
            else break;
        }
        ans = (counter > ans ? counter : ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#!usr/bin/env python3

import sys


def main():
    # s: spades
    # h: hearts
    # c: clubs
    # d: diamonds
    card_deck = {'S': [], 'H': [], 'C': [], 'D': []}
    card_symbols = ['S', 'H', 'C', 'D']

    n = int(sys.stdin.readline())
    for i in range(n):
        lst = [card for card in sys.stdin.readline().split()]
        card_deck[lst[0]].append(lst[1])

    for key, value in card_deck.items():
        card_deck[key].sort()

    for i in card_symbols:
        for card in range(1, 14):
            if not str(card) in card_deck[i]:
                print(i, card)


if __name__ == '__main__':
    main()

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

# define Rep(i,a,b) for(int i=a;i<=b;i++)
# define _Rep(i,a,b) for(int i=a;i>=b;i--)
# define RepG(i,u) for(int i=head[u];~i;i=e[i].next)

typedef long long ll;

const int N=2e5+5;

template<typename T> void read(T &x){
   x=0;int f=1;
   char c=getchar();
   for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
   for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+c-'0';
    x*=f;
}

# define int long long

int n,m,k;
int a[N],b[N];
int sum[N];
int ans;

signed main()
{
    read(n),read(m),read(k);
    Rep(i,1,n)read(a[i]),a[i]+=a[i-1];
    Rep(i,1,m)read(b[i]),b[i]+=b[i-1];
    Rep(i,0,n){
        if(a[i]>k)break;
        ans=max(ans,1ll*(i+upper_bound(b+1,b+m+1,k-a[i])-b-1));
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 6892
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <map>

#define mod 1000000007
#define ten5 100005
#define PI 3.1415926
using namespace std;

int num[201];

int main()
{
    //int m,n,o=0,i,j,k;
    long long int sum=0,sum2=0,n1=0,n2=0,n3;
    double ans=0.0,half;
    long long int m,n,o,i,j,k=1,now=1;
    long long int a,a1,a2,a3,a4;
    //float f,g,h;
    char c;
    string s,s1;
    //priority_queue<int> pq;
    //map<string,int> mp;
    //map<string,int>::iterator iter;
    cin>>n>>a1>>a2;
    if((a2-a1)%2==0)
        cout<<(a2-a1)/2;
    else
    {
        sum=a2-1;
        sum2=n-a1;
        a3=a1+(a2-a1-1)/2;
        a4=(n-a2)+(a2-a1+1)/2;
        a=min(sum,sum2);
        a=min(a,a3);
        a=min(a,a4);
        cout<<a;
    }
    return 0;
}



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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> S(n);
    REP(i, 0, n) {
        cin >> S[i];
    }
    int q;
    cin >> q;
    int ans = 0;
    REP(i, 0, q) {
        int ti;
        cin >> ti;
        ans += binary_search(begin(S), end(S), ti);
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3236
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<stack>
#include<queue>
using namespace std;
typedef long long ll;
 
const int maxn = 200010;
 
int n;
ll T,ans;
ll t[maxn],pre[maxn];
 
ll read(){ ll s=0,f=1; char ch=getchar(); while(ch<'0' || ch>'9'){ if(ch=='-') f=-1; ch=getchar(); } while(ch>='0' && ch<='9'){ s=s*10+ch-'0'; ch=getchar(); } return s*f; }
 
int main(){
	memset(pre,0,sizeof(pre));
	ans = 0;
	n = read(),T = read();
	
	for(int i=1;i<=n;i++){
		t[i]=read();
		pre[i]=t[i];
	} 
	pre[n+1]=1e18+7;
	
//	for(int i=1;i<=n;i++){
//		printf("%d ",pre[i]);
//	}printf("\n");
	
	int nex = 1;
	
	for (int i = 1;i <= n ;i = nex){
		nex = lower_bound(pre+1,pre+1+n,pre[i]+T)-pre;
		ans+=pre[nex-1]-pre[i]+min(pre[nex]-pre[nex-1],T);
//		printf("%lld %d\n",ans,nex);
	}
	
//  ans += T;
	printf("%lld\n",ans);
	
	return 0;
}

Measured memory_bytes: 6820
#include <iostream>
#include <utility>

#define _USE_MATH_DEFINES   // required or compile error
#include <cmath>
#include <cstdio>


using namespace std;

int main(void) {

    double r;
    cin >> r;

    printf("%lf %lf\n", (r * r * M_PI), (r * 2 * M_PI));

    return 0;
}

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

const LL inf = 1e9 + 7;
int n, m;
LL l, r, d;
int vis[100005];
vector<pair<LL, LL> > v[100005];
int flag;

void dfs(int u, int pre)
{
    vector<pair<LL, LL> >::iterator it = v[u].begin();
    for(; it != v[u].end(); ++it)
    {
        int v = it->first;
        int d = it->second;
        if(v == pre) continue;
        if(vis[v] == -inf)
        {
            vis[v] = vis[u] + d;
            dfs(v, u);
        }
        else
        {
            if(vis[u] + d != vis[v]) flag = 1;
        }
    }
}

int main()
{
    while(~scanf("%d %d", &n, &m))
    {
        for(int i = 0; i <= n; ++i)
        {
            v[i].clear();
            vis[i] = -inf;
        }
        for(int i = 0; i < m; ++i)
        {
            scanf("%lld %lld %lld", &l, &r, &d);
            v[l].push_back(make_pair(r, d));
            v[r].push_back(make_pair(l, -d));
        }
        flag = 0;
        for(int i = 1; i <= n; ++i)
        {
            if(vis[i] == -inf)
            {
                vis[i] = 1;
                dfs(i, -1);
            }
        }
        if(flag) printf("No\n");
        else printf("Yes\n");
    }
}


Measured memory_bytes: 16128
N = int(input())
monsters = list(map(int, input().split()))

while not(len(monsters) == 1):
    monsters = [monster for monster in monsters if monster != 0]
    minNum = min(monsters)
    ind = monsters.index(min(monsters))
    for i in range(len(monsters)):
        if i != ind:
            monsters[i] = monsters[i] % minNum
print(monsters[0])

Measured memory_bytes: 14252
#include <stdio.h>

int main(void) {

  long a,b,q;
  scanf("%ld %ld %ld", &a, &b, &q);
  long s[a],t[b],x[q];
  for (long i = 0; i < a; i++) {
    scanf("%ld", &s[i]);
  }
  for (long i = 0; i < b; i++) {
    scanf("%ld", &t[i]);
  }
  for (long i = 0; i < q; i++) {
    scanf("%ld", &x[i]);
  }
  long west_s,east_s,west_t,east_t;
  long start,end,center;
  long move,min,max,ans;
  for (long i = 0; i < q; i++) {
    if (x[i] < s[0]) {
      west_s = -1;
      east_s = s[0];
    } else if (x[i] > s[a-1]) {
      west_s = s[a-1];
      east_s = -1;
    } else {
      start = 0;
      end = a-1;
      while (start+1 != end) {
        center = (start+end)/2;
        if (s[center] < x[i]) {
          start = center;
        } else {
          end = center;
        }
      }
      west_s = s[start];
      east_s = s[end];
    }
    if (x[i] < t[0]) {
      west_t = -1;
      east_t = t[0];
    } else if (x[i] > t[b-1]) {
      west_t = t[b-1];
      east_t = -1;
    } else {
      start = 0;
      end = b-1;
      while (start+1 != end) {
        center = (start+end)/2;
        if (t[center] < x[i]) {
          start = center;
        } else {
          end = center;
        }
      }
      west_t = t[start];
      east_t = t[end];
    }
    ans = -1;
    if (west_s != -1 && east_t != -1) {
      min = x[i]-west_s;
      if (east_t-x[i] < min) {
        min = east_t-x[i];
      }
      ans = east_t-west_s+min;
    }
    if (east_s != -1 && west_t != -1) {
      min = east_s-x[i];
      if (x[i]-west_t < min) {
        min = x[i]-west_t;
      }
      move = east_s-west_t+min;
      if (ans == -1 || move < ans) {
        ans = move;
      }
    }
    if (west_s != -1 && west_t != -1) {
      max = west_s;
      if (west_t < max) {
        max = west_t;
      }
      move = x[i]-max;
      if (ans == -1 || move < ans) {
        ans = move;
      }
    }
    if (east_s != -1 && east_t != -1) {
      max = east_s;
      if (east_t > max) {
        max = east_t;
      }
      move = max-x[i];
      if (ans == -1 || move < ans) {
        ans = move;
      }
    }
    printf("%ld\n", ans);
  }

  return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

#define MAX_N 1000000
#define MAX_M 1000000
#define INF 1000000

int a[MAX_M];
int b[MAX_M];

int main() {

  // ---------------------
  // Input
  
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;

  priority_queue<P, vector<P>, greater<P> > pq;
  
  for (int i = 0; i < M; i++) {
    cin >> a[i] >> b[i];

    int s = a[i]; // start
    int t = b[i]; // end
    
    pq.push( P(t, s) ); // end, start
    
  }

  // ---------------------
  // 

  int pos = 0;
  int cnt = 0;
  
  while (pq.size() != 0) {
    P p = pq.top();
    pq.pop();

    if (p.second >= pos) {
      pos = p.first;
      cnt++;
    }
  }
  
  cout << cnt << endl;

  return 0;
  
}


Measured memory_bytes: 5752
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
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 fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

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

a, b, c = MAP()
# s = c ** 2 + a ** 2 + b ** 2 - 2 * a * c - 2*b*c + 2 * a * b  - 4 * a - 4 * b
# if 0 < s:
if c - (a + b) > 0:
    if 4 * a * b < ((c - (a + b))) ** 2:
        print("Yes")
        exit()

print("No")

# exit()
# if sqrt(a * b) < (c - (a + b ))/2:
#     print("Yes")
# else:
#     print("No")

# exit()
# if sqrt(a) + sqrt(b) < sqrt(c):
#     print("Yes")
# else:
#     print("No")

Measured memory_bytes: 5200
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for(int i=a; i<b; i++)

#define N 45
int a[N], b[N]; // first info, second info
int c[N]; // first index -> comfortable index
int d[N]; // b gyakubiki
int e[N]; // comfortable index -> first index

bool first=true;
void tadori(int p, int q, int r, int s){ // [p, q): comfortable, [r, s): index of b, p is also root of this subtree
    if(q-p==0) return;
    int mid=d[p]; // koreha index of b
    int x=mid-r, y=s-mid-1; // left and right size
    // printf("tadori[%d, %d)[%d, %d) -> %d %d\n", p, q, r, s, x, y);
    tadori(p+1, p+1+x, r, r+x); //migigawa
    tadori(p+1+x, p+1+x+y, r+x+1, r+x+1+y); // hidarigawa tte eigo de left da
    if(first) first=false; else printf(" ");
    printf("%d", e[p]);
}
int main(){
    int n;
    scanf("%d", &n);
    REP(i, n) scanf("%d", a+i);
    REP(i, n) scanf("%d", b+i);
    REP(i, n) c[a[i]]=i;
    FOR(i, 1, n+1) e[c[i]]=i;
    REP(i, n) b[i]=c[b[i]];
    REP(i, n) d[b[i]]=i;
    tadori(0, n, 0, n);
    printf("\n");
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
#include <vector>
#include <queue>
#include <iostream>
#include <iomanip>
using namespace std;
typedef long long LL;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

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

    int count_max_man = min({Y/10000, (LL)N});

    for(int i=count_max_man; i>=0; i--){
        for(int j=N-i; j>=0; j--){
            int k = N - i - j;
            if(k < 0)continue;

            if(10000*i + 5000*j + 1000*k == Y){
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }

    }

    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}

Measured memory_bytes: 3600
import java.util.*;
public class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    HashMap<Integer, Integer> hashmap = new HashMap<Integer, Integer>();

    hashmap.put(0, 0);
    for (int i = 1; i < n; i++) {
      hashmap.put(i, 0);
    }
    for (int i = 1; i < n; i++) {
      int a = sc.nextInt() - 1;
      int old = hashmap.get(a);
      hashmap.replace(a, old + 1);
    }
    for (int i = 0; i < n; i++) {
      System.out.println(hashmap.get(i));
    }

    sc.close();

  }
}

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

using namespace std;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int h, n;
    cin >> h >> n;
    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].first >> a[i].second;
    }
    vector<vector<int>> dp(h+1, vector<int>(n));
    for (int j = 1; j <= h; j++) {
        for (int i = 0; i < n; i++) {
            int cur = dp[max(j-a[i].first, 0)][i] + a[i].second;
            if (i > 0) {
                cur = min(cur, dp[j][i-1]);
            }
            dp[j][i] = cur;
        }
    }
    cout << dp[h][n-1] << endl;
}



Measured memory_bytes: 39680
#include <stdio.h>
int solve(int a[20], int n, int m, int index) {
	if (!m)
		return 1;
	if (m > 0 && index < n) {
		if (solve(a, n, m-a[index], index+1) || solve(a, n, m, index+1))
			return 1;
	}
	return 0;
}

int main(void) {
	int n, q, a[20], ms[200], i;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", a+i);
	}
	scanf("%d", &q);
	for (i = 0; i < q; i++) {
		scanf("%d", ms+i);
	}
	for (i = 0; i < q; i++) {
		if (solve(a, n, ms[i], 0))
			puts("yes");
		else
			puts("no");
	}
	return 0;
}

Measured memory_bytes: 580
#include <stdio.h>
int main(void){
    int p, r, a, b, i_p;
    int stack[100];
    char c;
    char input[399];
    int state; // 0 = normal 1 = number
    
    for (int i=0; i<399; i++) {
        input[i] = 0;
    }
    
    scanf("%399[^\n]", input);

    p = 0; r = 0; i_p = 0; state = 0;
    for (int i=0; i<100; i++) {
        stack[i] = 0;
    }

    while (i_p <= 398 && input[i_p] != 0) {
        c = input[i_p++];
        switch (c) {
            case ' ':
                if (state == 1) {
                    state = 0;
                    stack[p++] = r;
                }
                break;
            case '+':
                a = stack[--p];
                b = stack[--p];
                stack[p++] = b + a;
                break;
            case '-':
                a = stack[--p];
                b = stack[--p];
                stack[p++] = b - a;
                break;
            case '*':
                a = stack[--p];
                b = stack[--p];
                stack[p++] = b * a;
                break;
            default:
                if (state == 0) {
                    state = 1;
                    r = c - '0';
                } else {
                    r = (10 * r) + (c - '0');
                }

                break;
            
        }
    }
    
    printf("%d\n", stack[--p]);
    
}



Measured memory_bytes: 2756
package main

import "fmt"

const rate = 380000.0

func main() {
	var n int
	_, _ = fmt.Scan(&n)
	totalJPY := 0
	totalBTC := 0.0
	for i := 0; i < n; i++ {
		var currency string
		var amount string
		jpy := 0
		btc := 0.0
		_, _ = fmt.Scanf("%s %s", &amount, &currency)
		switch currency {
		case "JPY":
			_, _ = fmt.Sscan(amount, &jpy)
			totalJPY += jpy
		case "BTC":
			_, _ = fmt.Sscan(amount, &btc)
			totalBTC += btc
		}
	}
	fmt.Println(float64(totalJPY) + totalBTC * rate)
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cassert>

using namespace std;


bool solve(){
	vector<string> a(10);
	a[1] = ".,!? ";
	a[2] = "abc";
	a[3] = "def";
	a[4] = "ghi";
	a[5] = "jkl";
	a[6] = "mno";
	a[7] = "pqrs";
	a[8] = "tuv";
	a[9] = "wxyz";
	a[0] = "";
	
	string str;
	cin>> str;
	int n = str.size();
	int pre;
	int cnt = 0;
	for(int i=0;i<n;i++){
		int num = str[i] - '0';
		if(i==0){
			pre = num;
			continue;
		}
		if(pre == num){
			cnt++;
		}else{
			if(pre != 0){
				cout<< a[pre][cnt % a[pre].size()];
			}
			cnt = 0;
		}
		pre = num;
	}
	cout<< endl;
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	int n;
	cin>> n;
	for(int i=0;i<n;i++){
		solve();
	}
	
	return 0;
}

 

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

#define MAX_N 2000005
ll inv[MAX_N], fac[MAX_N], finv[MAX_N];
void make() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for(int i=2; i<MAX_N; i++) {
    inv[i] = mod - inv[mod%i] * (mod/i) % mod;
    fac[i] = fac[i-1] * (ll)i % mod;
    finv[i] = finv[i-1] * inv[i] % mod;
  }
}
ll perm(ll n, ll r) {
  if(n < 0)       return 0;
  else if(n < r)  return 0;
  else            return (fac[n] * finv[n-r]) % mod;
}
ll comb(ll n, ll r) {
  ll ans = 1;
  ans = perm(n, r);
  ans = (ans * finv[r]) % mod;
  return ans;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  make();
  int n; cin >> n;
  vector<int> A(n+1); rep(i, n+1) cin >> A[i];
  map<int, vector<int>> pos;
  rep(i, n+1) pos[A[i]].push_back(i);
  int p1, p2;
  for(auto ele: pos) {
    if(ele.second.size() == 2) {
      p1 = ele.second[0];
      p2 = ele.second[1];
    }
  }
  for(int i=1; i<=n+1; i++) {
    if(i == 1) cout << n << endk;
    else {
      ll ans = 0;
      (ans += comb(n-1, i)) %= mod;
      (ans += comb(n-1, i-2)) %= mod;
      (ans += comb(n-1, i-1) * 2 - comb(p1+n-p2, i-1) + mod) %= mod;
      cout << ans << endk;
    }
  }
  return 0;
}


Measured memory_bytes: 61452
N = int(input())
l = [int(x) for x in input().split(" ")]

import numpy as np
ans=0
while len(l) !=0:
    x=0
    y=0
    x+=max(l)
    l.pop(np.argmax(l))
    y+=max(l)
    l.pop(np.argmax(l))
    ans+=min(x,y)
print(ans)

Measured memory_bytes: 12500
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int B=131,P[2]={998244353,1000000007},MAXN=250010;
int n,nw[MAXN],nt[2],INV[2];
int hs[2][MAXN];
ll ans;
char s[MAXN];
map <int,int> mp[2];
int qpow (int a,int b,int p) {
	if (b<0) {a=qpow(a,p-2,p),b=-b;}
	int res=1;
	while (b) {
		if (b&1) {res=(1ll*res*a)%p;}
		a=(1ll*a*a)%p,b>>=1;
	}
	return res;
}
int main () {
	INV[0]=qpow(B,P[0]-2,P[0]),INV[1]=qpow(B,P[1]-2,P[1]);
	nt[0]=qpow(B,n,P[0]),nt[1]=qpow(B,n,P[1]);
	scanf("%d%s",&n,s+1);
	nw[0]=0;
	mp[0][0]++,mp[1][0]++;
	for (int i=1;i<=n;i++) {
		if (s[i]=='+') {
			hs[0][i]=(hs[0][i-1]+nt[0])%P[0];
			hs[1][i]=(hs[1][i-1]+nt[1])%P[1];
			nw[i]=nw[i-1];
		} else if (s[i]=='-') {
			hs[0][i]=(hs[0][i-1]-nt[0]+P[0])%P[0];
			hs[1][i]=(hs[1][i-1]-nt[1]+P[1])%P[1];
			nw[i]=nw[i-1];
		} else if (s[i]=='<') {
			nt[0]=(1ll*nt[0]*INV[0])%P[0];
			nt[1]=(1ll*nt[1]*INV[1])%P[1];
			hs[0][i]=hs[0][i-1],hs[1][i]=hs[1][i-1],nw[i]=nw[i-1]+1;
		} else {
			nt[0]=(1ll*nt[0]*B)%P[0];
			nt[1]=(1ll*nt[1]*B)%P[1];
			hs[0][i]=hs[0][i-1],hs[1][i]=hs[1][i-1],nw[i]=nw[i-1]-1;
		}
		mp[0][hs[0][i]]++,mp[1][hs[1][i]]++;
		//cout << i << "  " << hs[0][i] << "  " << hs[1][i] << "  " << nw[i] << endl;
	}
	for (int i=0;i<=n-1;i++) {
		mp[0][hs[0][i]]--,mp[1][hs[1][i]]--;
		int tmp0=(1ll*(hs[0][n]+(1ll*hs[0][i]*qpow(B,nw[i],P[0]))%P[0])*qpow(INV[0],nw[i],P[0]))%P[0];
		int tmp1=(1ll*(hs[1][n]+(1ll*hs[1][i]*qpow(B,nw[i],P[1]))%P[1])*qpow(INV[1],nw[i],P[1]))%P[1];
		//cout << i << "  " << tmp0 << "  " << tmp1 << endl;
		if (mp[0].find(tmp0)==mp[0].end()||mp[1].find(tmp1)==mp[1].end()) {continue;}
		ans+=min(mp[0][tmp0],mp[1][tmp1]);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 26880
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cstdio>
using namespace std;

static const int INF=100000;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n;
    cin >> n;
    int d[n];
    for(int i=0;i<n;i++){
        cin >> d[i];
    }
    sort(d,d+n);
    int K=n/2;
    int ans=d[K]-d[K-1];
    cout << ans << endl;
}


Measured memory_bytes: 640
def c_2d_plane_2n_points_bipartite_graph():
    import networkx as nx
    from networkx.algorithms.flow import dinitz
    N = int(input())
    Red_point_pos = [[int(i) for i in input().split()] for j in range(N)]
    Blue_point_pos = [[int(i) for i in input().split()] for j in range(N)]

    # 1 から N 番を赤い点に割り当て，N+1 番から 2N 番を青い点に割り当てる
    # ソースを 0 番とし，シンクを 2N+1 番とする
    graph = nx.DiGraph()
    graph.add_nodes_from(range(2 * N + 2))
    for i in range(N):
        for j in range(N):
            a, b = Red_point_pos[i]
            c, d = Blue_point_pos[j]
            if a < c and b < d:  # i 番の赤い点と j 番の青い点はペアにできうる
                graph.add_edge(i + 1, j + N + 1, capacity=1)
    for i in range(1, N + 1):
        graph.add_edge(0, i, capacity=1)
    for j in range(N + 1, 2 * N + 1):
        graph.add_edge(j, 2 * N + 1, capacity=1)
    return dinitz(graph, 0, 2 * N + 1).graph['flow_value']

print(c_2d_plane_2n_points_bipartite_graph())

Measured memory_bytes: 56068
N, L = map(int, input().split())

tastes = [L + i - 1 for i in range(1, N+1)]
# ダサい解法...
# sum_taste = sum(tastes)
#
# prev_taste_diff = 10 ** 10
#
# ans = 0
# for i in range(N):
#     s = sum(tastes[:i] + tastes[i+1:])
#     curr_taste_diff = abs(s - sum_taste)
#     if curr_taste_diff < prev_taste_diff:
#         ans = s
#     prev_taste_diff = curr_taste_diff

# エレガント?
hoge = sorted([abs(t) for t in tastes])[0]
if hoge in tastes:
    tastes.remove(hoge)
else:
    tastes.remove(-hoge)
print(sum(tastes))


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  int a, b, c, d;
  cin >> a >> b >> c >> d;
  while (true) {
    c -= b;
    if (c <= 0) {
      cout << "Yes" << endl;
      return 0;
    }
    a -= d;
    if (a <= 0) {
      cout << "No" << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3652
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

int main() {
    int n; cin >> n;
    vector<vector<int>> a(2, vector<int>(n));
    for (auto &ai: a) for (int &aij: ai) cin >> aij;
    vector<vector<int>> dp(2, vector<int>(n));
    dp[0][0] = a[0][0];
    for (int i: {0, 1}) for (int j = 0; j < n; j++) {
        if (j) chmax(dp[i][j], dp[i][j - 1] + a[i][j]);
        if (i) chmax(dp[i][j], dp[i - 1][j] + a[i][j]);
    }
    cout << dp.back().back() << endl; 
    return 0;
}

Measured memory_bytes: 384
N = int(input())

def f(n):
    count=0
    repeat=True
    while n%2==0:
        n=n//2
        count+=1
    return count
       
max=0
number=1
for i in range(2,N+1):
    if f(i)>max:
        max=f(i)
        number=i
        

print(number)

   
    

Measured memory_bytes: 2940
#include <fstream>
#include <vector>

using namespace std;

//ifstream cin("tema.in");
//ofstream cout("tema.out");

const int MAXN = 500;

int answer[1 + MAXN * MAXN];
bool marked[1 + MAXN * MAXN];

int main() {
    //freopen("tema.in", "r", stdin);
    //freopen("tema.out", "w", stdout);
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        int x;
        scanf("%d", &x);
        marked[x] = true;
        answer[x] = i;
    }
    for (int i = 1, j = 1; i <= n * n; i++)
        if (marked[i]) {
            int x = answer[i], need = x - 1;
            while (j < i && need) {
                if (!answer[j]) {
                    answer[j] = x;
                    need--;
                }
                j++;
            }
            if (need) {
                printf("No\n");
                return 0;
            }
        }
    for (int i = n * n, j = n * n; i >= 1; i--)
        if (marked[i]) {
            int x = answer[i], need = n - x;
            while (j > i && need) {
                if (!answer[j]) {
                    answer[j] = x;
                    need--;
                }
                j--;
            }
            if (need) {
                printf("No\n");
                return 0;
            }
        }
    printf("Yes\n");
    for (int i = 1; i <= n * n; i++)
        printf("%d ", answer[i]);
    return 0;
}


Measured memory_bytes: 2176
import sys
from collections import  Counter
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7



def main():
    S = input()
    count = Counter(S)
    count['a'] += 0
    count['b'] += 0
    count['c'] += 0
    if max(count.values()) - min(count.values()) <= 1:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(),B = sc.nextInt(),C = sc.nextInt();
		if(A == B) System.out.println(C);
		else if(A == C) System.out.println(B);
		else System.out.println(A);
	}
}


Measured memory_bytes: 21844
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		
		int n = sc.nextInt();
		boolean flag = true;
		int x1 = 0, y1 = 0, time = 0;
		
		for(int i = 0; i < n; i++) {
			int t = sc.nextInt();
			int sa = t - time;
			int x2 = sc.nextInt();
			int y2 = sc.nextInt();
			int dist = Math.abs(x1 - x2) + Math.abs(y1 - y2);
			if (dist > sa || sa % 2 != dist % 2) {
				flag = false;
				break;
			}
			x1 = x2;
			y1 = y2;
			time = t;
		}
		if (flag) out.println("Yes");
		else out.println("No");
	
		out.close();
	}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}



Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

int main(){
    int n,m; cin >> n >> m;
    UnionFind uf(n);
    vector<int> x(m), y(m), z(m);
    rep(i,m){
        cin >> x[i] >> y[i] >> z[i];
        x[i]--; y[i]--;
    }

    rep(i,m) uf.unite(x[i], y[i]);
    set<int> s;
    rep(i,n) s.insert(uf.find(i));
    int ans = s.size();
    cout << ans << endl;
}


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


int main() {

  int n,d,x;
  cin>>n>>d>>x;

  vector<int> A(n);
  for(int i=0;i<n;i++){
    cin>>A.at(i);
  }

  int sum=0;
  for(int i=0;i<n;i++){
    int eating_day=0;
    for(int j=0;j<d;j++){
      if(j==0){
        sum++;
        eating_day=A.at(i)+1;
      }
      else if(j==eating_day-1){
        sum++;
        eating_day+=A.at(i);
      }
    }
  }

  cout<<sum+x<<endl;

    return 0;
}


Measured memory_bytes: 256
""" minesweeper """

import re

H, W = map(int, input().split())
S = []
for _ in range(H):
    S.append(list(input()))
MINE = '#'

def get_context(h, w, field):
    # list[start:end] returns list from list[start] to list[end - 1]
    span_h = (max(0, h - 1), min(h + 1, H - 1) + 1)
    span_w = (max(0, w - 1), min(w + 1, W - 1) + 1)

    context = ''
    for row in field[span_h[0]:span_h[1]]:
        # print("row ---> {0}".format(row))
        context += ''.join(row[span_w[0]:span_w[1]])
    # print("context:{0}".format(context))
    return context

def main():
    """
    main function
    """

    """
    print(H)
    print(W)
    print(S)
    #"""

    field = S

    for h in range(H):
        for w in range(W):
            pos_char = field[h][w]
            # print(pos_char)
            if pos_char != MINE:
                context = get_context(h, w, field)
                mine_num = len(re.findall(MINE, context))
                field[h][w] = str(mine_num)

    for row in field:
        print(''.join(row))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define ULL unsigned long long
#define LL long long
#define Max 100005
#define mem(a,b) memset(a,b,sizeof(a));
#define pb push_back
#define mp make_pair
const LL mod=1e9+7;
const ULL base=131;
const LL LL_MAX=9223372036854775807;
using namespace std;
int a[2*Max],b[2*Max];
vector<int>ans;
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=n;i>=1;i--){
        int sum=0;
        for(int j=i+i;j<=n;j+=i)
            sum+=b[j];
        if(sum%2!=a[i])
            b[i]=1,ans.push_back(i);
    }
    printf("%d\n",ans.size());
    for(int i=0;i<ans.size();i++)
        printf("%d ",ans[i]);
    printf("\n");
    return 0;
}



Measured memory_bytes: 2936
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<30;

enum FACE { TOP, BOTTOM, FRONT, BACK, LEFT, RIGHT };
template <class T>
class dice {
public:
  dice(T *v) {
    id[TOP] = 0; id[FRONT] = 1; id[LEFT] = 3;
    id[RIGHT] = 2; id[BACK] = 4; id[BOTTOM] = 5;
    REP(i,6)
      var[i] = v[i];
  }
  T& operator[] (FACE f) { return var[id[f]]; }
  const T& operator[] (FACE f) const { return var[id[f]]; }
  bool operator==(const dice<T>& b) const {
    const dice<T> &a = *this;
    return a[TOP] == b[TOP] && a[BOTTOM] == b[BOTTOM] &&
           a[FRONT] == b[FRONT] && a[BACK] == b[BACK] &&
           a[LEFT] == b[LEFT] && a[RIGHT] == b[RIGHT];
  }
  void roll_x() { roll(TOP, BACK, BOTTOM, FRONT); }
  void roll_y() { roll(TOP, LEFT, BOTTOM, RIGHT); }
  void roll_z() { roll(FRONT, RIGHT, BACK, LEFT); }
  vector<dice> all_rolls() {
    vector<dice> ret;
    for (int k = 0; k < 6; (k&1?roll_y():roll_x()),++k)
      for (int i = 0; i < 4; roll_z(), ++i)
        ret.push_back(*this);
    return ret;
  }
  bool equivalent_to(const dice& di) {
    for (int k = 0; k < 6; (k&1?roll_y():roll_x()),++k)
      for (int i = 0; i < 4; roll_z(), ++i)
        if (*this == di) return true;
    return false;
  }
private:
  void roll(FACE a, FACE b, FACE c, FACE d) {
    int tmp = id[a];
    id[a] = id[b]; id[b] = id[c];
    id[c] = id[d]; id[d] = tmp;
  }
  T var[6];
  int id[6];
};

int main() {
  int n;
  while(cin>>n,n) {
    vector<dice<string> > v;
    REP(i,n) {
      string s[6];
      REP(j,6)
        cin >> s[j];
      v.push_back(dice<string>(s));
    }
    vector<bool> f(n);
    int num = 0;
    REP(i,n) {
      if (f[i]) continue;
      num++;
      for(int j=i+1; j<n; ++j) {
        if (f[j]) continue;
        if (v[i].equivalent_to(v[j])) {
          f[j] = true;
        }
      }
    }
    cout << n-num << endl;
  }
}

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

int n,m=4000000;
bool ns[300005]={0};
int est[300005]={0};

int main(){
  int i,j,co=0;
  int e=0,w=0;
  char c;
  cin >> n;
  for(i=0;i<n;i++){
    cin >> c;
    if(i>0)est[i]=est[i-1];
    if(c=='E')est[i]++;
    //cout << est[i];
  }
  m = est[n-1]-est[0];
  for(i=1;i<n-1;i++){
    co = 0;
    co +=i-est[i-1];
    co+=est[n-1]-est[i];
    if(m>co)m=co;
    
  }
  if(m>n-1-est[n-2])m=n-1-est[n-2];
  

  cout <<m<< endl;

  return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<string>
using namespace std;
int main(){
    string S;
    cin >> S;
    for(int i=0;i<S.length();i++){
        if((i%2==0 && S.at(i)=='L') || (i%2==1 && S.at(i)=='R')){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
unsigned long long sum=0;
int n,a[300001],k;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{	
		cin>>a[i];
		a[i]-=i;
	}
	sort(a+1,a+n+1);
	if(n%2)
		k=a[n/2+1];
	else
			k=((a[n/2]+a[n/2+1])/2+0.5);
	for(int i=1;i<=n;i++)
		sum+=abs(a[i]-k);
	cout<<sum;
	return 0;
}//https://abc102.contest.atcoder.jp/submissions/2783177

Measured memory_bytes: 1024