akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 15
#define MAXM 15
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll ans = 0;
int N, M, tmp, num[MAXM];
vi K, S[MAXM]; 
bool P[MAXM], flag;


void solve(){
    for(int i = 0; i < (1 << N); i++) {
        fill(num, num+M, 0);

		for(int j = 0; j < M; j++) {
            rep(k, S[j].size()){
                if(i & (1 << S[j][k])) {
                    num[j]++;
                }
            }
		}

        flag = true;
        rep(i, M){
            if(num[i] % 2 != P[i]) flag = false;
        }

        if(flag){
            ans++;
        } 
    }

    cout << ans << endl;
}

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

    K.resize(M);

    rep(i, M){
        cin >> K[i];
        rep(j, K[i]){
            cin >> tmp;
            tmp--;
            S[i].push_back(tmp);
        }
    }

    rep(i, M) cin >> P[i];

    solve();
}


Measured memory_bytes: 256
// ABC177D - Friends

#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;

struct UnionFind {
	vector<int> par;
	vector<int> rank;

	// n要素で初期化
	UnionFind(int n) {
		par.resize(n);
		rank.resize(n);
		for (int i = 0; i < n; i++) {
			par[i] = i;
			rank[i] = 0;
		}
	}

	// 木の根を求める。
	int find(int x) {
		if (par[x] == x) {
			return x;
		} else {
			return par[x] = find(par[x]);
		}
	}

	// xとyの属する集合を併合
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) {
			return;
		}
		if (rank[x] < rank[y]) {
			par[x] = y;
		} else {
			par[y] = x;
			if (rank[x] == rank[y]) {
				rank[x]++;
			}
		}
	}

	// xとyが同じ集合に属するか否か
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

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

	UnionFind tree(N);
	for (int i = 0; i < M; i++) {
		int A, B;
		cin >> A >> B;
		tree.unite(A-1, B-1);
	}

	map<int, int> par;
	for (int i = 0; i < N; i++) {
		par[tree.find(i)]++;
	}

	int ans = 0;
	for (auto it = par.begin(); it != par.end(); it++) {
		pair<int, int> t = *it;
		ans = max(ans, t.second);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 13892
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
#define endl "\n"
#define print_array(name,n) for(ll o=0;o<n;o++) cout<<name[o]<<" "
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 2e18
#define pll pair<ll,ll>
#define pii pair<int,int>
bool sortbysecond(const pair<int,int> &a,const pair<int,int> &b){
	return (a.ss>b.ss);
}
 
ll gcd(ll a,ll b){ if(b==0) return a; return gcd(b,a%b) ;} 

template <typename T>
string NumberTostring(T Number )
{
	ostringstream ss;
	ss<<Number;
	return ss.str();
}
 
void solve(){
	ll d,t,s;cin>>d>>t>>s;
	ll rt = d/s;
	ll rem = d%s;
	if(rt<t){
		cout<<"Yes"<<endl;
	}
	else if(rt==t and rem==0){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}
 
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
	ll t;
	// cin>>t;
	t=1;
	while(t--){
		solve();
	}    
    return 0;
}

Measured memory_bytes: 3664
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int tmp;
		int[] max = new int[2];
		max[0] = 0;
		max[1] = 0;
		int[] pos = new int[2];

		for(int i = 0 ; i < n ; i++){
			tmp = sc.nextInt();
			if(tmp > max[0]){
				max[1] = max[0];
				max[0] = tmp;
				pos[1] = pos[0];
				pos[0] = i;
			}else if(tmp > max[1]){
				max[1] = tmp;
				pos[1] = i;
			}
		}

		for(int i = 0 ; i < n ; i++){
			if(i == pos[0]){
				System.out.println(max[1]);
			}else{
				System.out.println(max[0]);
			}
		}
	}

}

Measured memory_bytes: 94612
import java.io.*;
import java.util.*;
import java.math.*;
     
public class Main {
	//static int dir[][]={{0,1},{0,-1},{1,0},{-1,0}};
	public static void main(String[] args) throws Exception {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      OutputStream outputStream = System.out;
      PrintWriter out = new PrintWriter(outputStream);

      int i, j, u=0, v=0;
      StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
      int m = Integer.parseInt(st.nextToken());
      if(n>9 || n<1 || m>9 || m<1)
        out.print("-1");
      else
        out.print(n*m);
    	out.flush();
    	out.close();
    	}
    }

Measured memory_bytes: 21204
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class Main{
	public static void main(String[] args) throws IOException{
		Scanner stdIn=new Scanner(System.in);
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		double r=stdIn.nextDouble();
		double s=r*r*Math.PI;
		double l=2*r*Math.PI;
		System.out.printf("%f %f\n", s,l);
	}
}

Measured memory_bytes: 28164
import sys
readline = sys.stdin.readline

class WeightedUnionFind:
    def __init__(self, n):
        self.parents = [i for i in range(n)]
        self.rank = [0] * n
        # 根への距離を管理
        self.weight = [0] * n

    def find(self, x):
        if self.parents[x] == x:
            return x
        else:
            y = self.find(self.parents[x])
            # 親への重みを追加しながら根まで走査
            self.weight[x] += self.weight[self.parents[x]]
            self.parents[x] = y
            #self.parents[x] = self.find(self.parents[x])
            return y
            #return self.parents[x]

    def union(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        # xの木の高さ < yの木の高さ
        if self.rank[rx] < self.rank[ry]:
            self.parents[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        # xの木の高さ ≧ yの木の高さ
        else:
            self.parents[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            # 木の高さが同じだった場合の処理
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

    # xからyへのコスト
    def diff(self, x, y):
        return self.weight[x] - self.weight[y]

def main():
    N, M = map(int, readline().rstrip().split())    
    uf = WeightedUnionFind(N)

    for _ in range(M):
        l, r, d = map(int, readline().rstrip().split())
        l -= 1
        r -= 1
        if uf.same(l, r):
            if uf.diff(l, r) != d:
                print('No')
                return

        uf.union(l, r, d)
    
    print('Yes')

if __name__ == '__main__':
    main()

Measured memory_bytes: 15848
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b;
  cin>>a>>b;
  if(a+b==3)
    cout<<"3"<<endl;
  else if(a+b==4)
    cout<<"2"<<endl;
  else if(a+b==5)
    cout<<"1"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define pb puhs_back
using namespace std;
typedef pair< ll, ll> pll;


ll n;
string s;
ll ans[100005];
ll ee(ll x)
{
        return x/2;
}
ll oo(ll x)
{
        return (x+1)/2;
}
int main()
{
        cin >> s;
        n = s.length();
        for(ll i=0;i<n;i++) {
                //cout << i << " ";
                ll j=i;
                while(j < n && s[j] == 'R') {
                        j++;
                }
                ll rcnt = j-i;
                rcnt--;
                ll R = j-1;
                while(j < n && s[j] == 'L') {
                        j++;
                }
                ll lcnt = j - (R+1);
                lcnt--;
                //cout << rcnt << " " << lcnt << endl;
                ll rm = j;
                ll L = R+1;
                i = rm - 1;
                ans[R]= 1+ (ee(rcnt) + oo(lcnt));
                ans[L] = 1+ oo(rcnt) + ee(lcnt);
        }
        for(ll i=0;i<n;i++) cout << ans[i] << " ";
        return 0;
}


Measured memory_bytes: 1408
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    n = I()
    ali = LI()
    gusu = 0
    flag = []
    for i in ali:
        if i % 2 == 0:
            gusu += 1
            if i % 3 == 0 or i % 5 == 0:
                flag.append(True)
    if gusu == len(flag):
        print('APPROVED')
    else:
        print('DENIED')


# Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e6+5;
int cnt[maxn]={0};
int max_=0;
void solve()
{
    int n;
    int ans;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        if(i==1)
        {
            cin>>ans;
            cnt[ans]++;
            if(ans>max_)
                max_=ans;
        } else
        {
            int x;
            cin>>x;
            cnt[x]++;
            if(x>max_)
                max_=x;
            ans=__gcd(ans,x);
        }
    }
    if(ans!=1)
    {
        cout<<"not coprime";
        return ;
    }
    int sum=0;
    int flag=0;
    for(int i=2;i<=max_;i++)
    {
        sum=0;
        for(int j=i;j<=max_;j+=i)
            sum+=cnt[j];
        if(sum>1)
        {
            flag=1;
            break;
        }
    }
    if(flag)
    {
        cout<<"setwise coprime";
    } else
        cout<<"pairwise coprime";
}
int main() {
    int __=1;
    while(__--)
    {
        solve();
    }

    return 0;
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
   bool flg=true;
   ll k,x;
   cin >>k>>x;
   if(500*k<x)flg=false;
   if(flg)puts("Yes");
   else puts("No");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, less<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 1'000'000;
const int LOGN = 18;

int n, m, k;

void solve(int test)
{
  string s;
  cin >> s;
  if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]
      || s[0] == s[2] && s[1] == s[3] && s[0] != s[1]
      || s[0] == s[3] && s[1] == s[2] && s[0] != s[1]) {
    cout << "Yes\n";
  }
  else {
    cout << "No\n";
  }
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
    solve(i);
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 384
# Fermat's little theorem
def is_prime(x):
    if x == 2:
        return 1
    elif x % 2 == 0:
        return 0
    else:
        return pow(2, x - 1, x) == 1

import sys

def solve():
    file_input = sys.stdin
    N = file_input.readline()
    cnt = 0
    for n in map(int, file_input):
        cnt += is_prime(n)
    print(cnt)

solve()

Measured memory_bytes: 7696
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define int long long
#ifndef FAST_IO
  #define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
#endif
#define ff first
#define ss second
#define endl "\n"
#define all(c) c.begin(),c.end()
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" "; cout<<endl;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve(){
     int n,k;
     cin>>n>>k;
     cout<<(n-k+1)<<endl;
}
int32_t main(){
   IOS;
   solve();
   //debug();
  #ifdef LOCAL_DEFINE
   cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
  #endif	
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.InteropServices;
using System.Runtime.Remoting.Messaging;
using System.Security.Principal;
using System.Text;
class Simple
{
    int H, W;
    string[,] S;
    void Solve() {
        //input
        H = io.Int;
        W = io.Int;
        S = new string[H, W];
        for(int i = 0; i < H; ++i) {
            for(int j = 0; j < W; ++j) {
                S[i, j] = io.String;
            }
        }
        //cal       
        Func<string, bool> isSnuke = (str) => str == "snuke";
        var alpArr = Enumerable.Range('A', 'Z').ToArray();
        for (int i = 0; i < H; ++i) {
            for (int j = 0; j < W; ++j) {
                if (isSnuke(S[i, j])) {
                    //ret
                    Console.WriteLine(Convert.ToChar(alpArr[j])+ (i + 1).ToString());
                    return;
                }
            }
        }
        
    }
    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) => new Simple().Stream();
    void Stream() {
        Solve();
        io.writeFlush();
    }
}
class SimpleIO
{
    string[] nextBuffer;
    int BufferCnt;
    char[] cs = new char[] { ' ' };
    StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    public SimpleIO() {
        nextBuffer = new string[0];
        BufferCnt = 0;
        Console.SetOut(sw);
    }
    public string Next() {
        if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        BufferCnt = 0;
        return nextBuffer[BufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void writeFlush() { Console.Out.Flush(); }
}


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

int main() {
    int sum = 0;
    vector<int> value(3);
    for (int i = 0; i < value.size(); i++)
    {
        cin >> value[i];
    }
    sort(value.begin(), value.end());
    int k;
    cin >> k;
    for (int i = 0; i < k; i++)
    {
        value[2] *= 2;
    }
    
    
    for (int i = 0; i < value.size(); i++)
    {
        sum += value[i];
    }
    
    cout << sum << endl;


}

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

N = int(input())
hmin = INF
xyh = []
for i in range(N):
    x,y,h = inpl()
    hmin = min(h,hmin)
    xyh.append([x,y,h])

for H in range(hmin,hmin+210):
    for cx in range(101):
        for cy in range(101):
            flag= True
            for x,y,h in xyh:
                if max(H-abs(cx-x)-abs(cy-y),0) != h:
                    flag = False
                    break

            if flag:
                print(cx,cy,H)
                sys.exit()


Measured memory_bytes: 55896
#include<iostream>
using namespace std;
long a[1<<17];int n;
long c(bool f)
{
	long s=0,cnt=0;
	for(int i=0;i<n;i++)
	{
		s+=a[i];
		if(f&&s>=0)
		{
			cnt+=s+1;
			s=-1;
		}
		else if(!f&&s<=0)
		{
			cnt+=-s+1;
			s=1;
		}
		f=s>0;
	}
	return cnt;
}
main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	long cnt1=c(true),cnt2=c(false);
	cout<<(cnt1<cnt2?cnt1:cnt2)<<endl;
}


Measured memory_bytes: 1024
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, y;
    cin >> n >> y;
    for(int i = 0; i <= 2000; i++){
        for(int j = 0; j <= 2000; j++){
            int k = n - i - j;
            if(k < 0){ continue; }
            if(i * 10000 + j * 5000 + k * 1000 == y){
                cout << i << ' ' << j << ' ' << k << '\n';
                return 0;
            }
        }
    }
    cout << -1 << ' ' << -1 << ' ' << -1 << '\n';
}


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

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        long x = Math.abs(sc.nextLong());
        long k = sc.nextLong();
        long d = sc.nextLong();

        long tmp = x / d;

        if (tmp <= k) {
            long t = k - tmp;
            if (t % 2 == 0) {
                System.out.println(Math.abs(x - d * tmp));
            } else {
                System.out.println(Math.abs(x - d * (tmp+1)));
            }
        } else {
            System.out.println(Math.abs(x - d * k));
        }
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

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

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

Measured memory_bytes: 32728
#include <iostream>
#define ll long long
using namespace std;
ll cnt[100100];
int main(){
    int N; scanf("%d", &N);
    ll sum = 0;
    for(int i = 1; i <= N; i++){
        int A; scanf("%d", &A);
        ++cnt[A];
        sum += A;
    }
    int Q; scanf("%d", &Q);
    for(int i = 1; i <= Q; i++){
        int B, C; scanf("%d%d", &B, &C);
        sum -= cnt[B] * B;
        sum += cnt[B] * C;
        cnt[C] += cnt[B];
        cnt[B] = 0;
        printf("%lld\n", sum);
    }
    return 0;
}

Measured memory_bytes: 4584
#include<bits/stdc++.h>
#define re register
int f[3010][3010];
const int mod=998244353;
int main(){
  re int a, b, c, d;
  scanf("%d%d%d%d", &a, &b, &c, &d);
  f[a][b] = 1;
  for(re int i=a+1; i<=c; i++){
    re int nw = 0;
    for(re int j=b; j<=d; j++){
      f[i][j] = (nw+1ll * f[i-1][j] * j) % mod;
      nw = (1ll * (nw + f[i-1][j]) * (i-1)) % mod;
    }
  }
  re int ans = 0;
  for(re int j=b; j<=d; j++){
    ans = (1ll * ans * c + f[c][j]) % mod;
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 38800
import math

N = int(input())

i=0
num=0

#桁数
while 10**i <= N:
  i=i+1
    


if i==1:
  num=N
elif i==2:
  num=9
elif i==3:
  num=9+N-99
elif i==4:  
  num=9+999-99
elif i==5:  
  num=9+900+N-9999
elif i==6:  
  num=9+900+99999-9999
  
print(num)

  

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
#define print(x) cerr << (#x) << "is "<< x << "\n"
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10;
 
int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n;
   cin >> n;
   vector<vector<int>> cnt(n,vector<int>(26));
   string s;
   f(i,0,n){
      cin >> s;
      f(j,0,10){
         cnt[i][s[j]-'a']++;
      }
   }
   sort(all(cnt));
   int c = 1;
   int ans = 0;
   f(i,1,n){
      int flag = 1;
      f(j,0,26){
         if(cnt[i-1][j] != cnt[i][j]){
            flag = 0;
            break;
         }
      }
      if(flag) c++;
      else{
         ans += (c*(c-1))/2;
         c = 1;
      }
      if(i == n-1){
         ans += (c*(c-1))/2;
      }
   }
   cout << ans << '\n';
   return 0;
}

Measured memory_bytes: 24448
from collections import deque
def main():
    S=input()
    Q=int(input())
    d = deque(S)
    is_forward = True
    for _ in range(Q):
        q=input()
        if q[0] == '1':
            is_forward = not is_forward
        else:
            _, F, C = q.split()
            if F == '1':
                if is_forward:
                    d.appendleft(C)
                else:
                    d.append(C)
            else:
                if is_forward:
                    d.append(C)
                else:
                    d.appendleft(C)
    if is_forward:
        for s in d:
            print(s, sep="", end="")
    else:
        for s in reversed(d):
            print(s, sep="", end="")
    print()
    return

if __name__ == '__main__':
    main()

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

int main()
{
  int n,m;
  cin>>n>>m;
  int al,ar=1000000000;
  for(int i=0;i<m;i++)
  {
    int lm,rm;
    cin>>lm>>rm;
    al=max(al,lm);
    ar=min(rm,ar);
  }
  if(al>ar)cout<<0<<endl;
  else cout<<ar-al+1<<endl;
  return 0;
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/


string S;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> S;

    if (S[0] == '9' || S[1] == '9') printf("Yes\n");
    else printf("No\n");
}


Measured memory_bytes: 256
n, y = map(int, input().split())
for i in range(0, n+1):
  for j in range(0, n+1-i):
    k = n - (i + j)
    sum_price = 10000*i + 5000*j + 1000*k
    if n == i + j + k and sum_price == y:
      print(i, j, k)
      exit()
print(-1, -1, -1)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S; cin >> S;
  int AA = stoi(S.substr(0, 2));
  int BB = stoi(S.substr(2, 2));
  if(AA > 12 || AA < 1){
    if(BB >12 || BB < 1){
      cout << "NA" << endl;
      return 0;
    }else{
      cout << "YYMM" << endl;
      return 0;
    }
  }else{
    if(BB > 12 || BB < 1){
      cout << "MMYY" << endl;
      return 0;
    }else{
      cout << "AMBIGUOUS" << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n;
ll arr[1000000];
ll dp[1000000];
ll pk(ll i)
{
    if(i==n-1)
       return 0;
    if(dp[i]!=-1)
       return dp[i];
    ll left=abs(arr[i]-arr[i+1])+pk(i+1);
    ll right=INT32_MAX;
    if(i<n-2)
    right=abs(arr[i]-arr[i+2])+pk(i+2);
    return dp[i]=min(left,right);
}
int main() 
{ 
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    memset(dp,-1,sizeof dp);
	ll t=1;
    //cin>>t;
    cin>>n;
    for(ll i=0;i<n;i++)
       cin>>arr[i];
    cout<<pk(0);
} 


Measured memory_bytes: 15300
INF = float('inf')

def solve():
    N, Ma, Mb = map(int, input().split())
    l = []
    for _ in range(N):
        a, b, c = map(int, input().split())
        l.append((a, b, c))
 
    dp = [[[INF] * 401 for _ in range(401)] for _ in range(N + 1)]
    dp[0][0][0] = 0
    for i in range(len(l)):
        for a in range(len(dp[0])):
            for b in range(len(dp[0][0])):
                if dp[i][a][b] != INF:
                    dp[i + 1][a][b] = min(dp[i + 1][a][b], dp[i][a][b])
                    dp[i + 1][a + l[i][0]][b + l[i][1]] = min(dp[i + 1][a + l[i][0]][b + l[i][1]], dp[i][a][b] + l[i][2])
 
    ans = INF
    for i in range(len(dp)):
        for a in range(1, len(dp[0])):
            for b in range(1, len(dp[0][0])):
                if dp[i][a][b] != INF:
                    if Ma * b == Mb * a:
                        ans = min(ans, dp[i][a][b])
 
    print(-1 if ans == INF else ans)
 
 
if __name__ == '__main__':
    solve()

Measured memory_bytes: 60784
/*
(1)for binary shift operator always use 'LL' 1LL<<63

*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set_pair tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
  const double  pi=3.1415926535; 
  const ll M=1e9+7;
  struct pair_hash
{
	template <class T1, class T2>
	std::size_t operator () (std::pair<T1, T2> const &pair) const
	{
		std::size_t h1 = std::hash<T1>()(pair.first);
		std::size_t h2 = std::hash<T2>()(pair.second);

		return h1 ^ h2;
	}
};
ll dfs(map<ll,set<ll>> &adj,bool vis[],ll src){
	vis[src]=true;
	ll c=0;
	for(auto it: adj[src]){
		if(!vis[it])
			c+=dfs(adj,vis,it);
	}
	c++;
	return c;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,m;cin>>n>>m;
	ll i,j,mx=1;
	map<ll,set<ll>> adj;
	for(i=0;i<m;i++){
		ll a,b;cin>>a>>b;
		if(adj[a].count(b)==0)
		{
			adj[a].insert(b);
			adj[b].insert(a);
		}
	}
	bool vis[n+1]={};
	for(i=1;i<=n;i++){
		if(!vis[i])
			mx=max(mx,dfs(adj,vis,i));
	}
	cout<<mx;

	return 0;
} 

Measured memory_bytes: 60020
n = int(input())
nums = [int(s) for s in input().split()]

box = []

for i,j in enumerate(nums):
  box.append([i + 1,j])
  
answer = []
for i in sorted(box, key=lambda x: x[1]):
	answer.append(str(i[0]))

print(" ".join(answer))

Measured memory_bytes: 28500
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <sstream>

using namespace std;

int main()
{
	long long ans = 0;
	string s;

	cin >> s;

	long long a = s.size()/2;

	if (a * 2 < s.size())
		a++;

	for (long long i = 0; i < s.size() / 2; i++)
	{
		if (s[i] != s[s.size() - 1 - i])
			ans++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
signed main()
{
   SPEED;
  int x;
  cin>>x;
  int a[1001];
  for(int i=0;i<1001;i++)
  {
    a[i]=powl(i,5);
  }
  for(int i=0;i<1001;i++)
  {
    for(int j=0;j<1001;j++)
    {
      if(a[i]+a[j]==x)
      {
        cout<<i<<" "<<-j;
        return 0;
      }
      if(a[i]-a[j]==x)
      {
        cout<<i<<" "<<j;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<LL> VI;
typedef vector<VI> VVI;
typedef pair<LL, LL> PII;
typedef vector<string> VS;
inline LL toInt(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(x,c) for(auto x: (c))
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define ALL(c) (c).begin(), (c).end()
#define REVERSE(c) reverse(ALL(c))
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define STABLE_SORT(c) stable_sort(ALL(c))
#define STABLE_RSORT(c) stable_sort((c).rbegin(),(c).rend())
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)), (c).end());
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double INF = 1e7;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define dump(x)  cerr << #x << " = " << (x) << endl;


int main() {
	LL X, Y, Z, K;
	cin >> X >> Y >> Z >> K;
	VI A(X), B(Y), C(Z), D(X * Y);
	REP(i, X) {
		cin >> A[i];
	}
	REP(i, Y) {
		cin >> B[i];
	}
	REP(i, Z) {
		cin >> C[i];
	}
	LL index = 0;
	REP(i, X) {
		REP(j, Y) {
			D[index] = A[i] + B[j];
			index++;
		}
	}
	SORT(C);
	RSORT(D);
	VI E;
	LL N = min(K, SZ(D));
	REP(i, N) {
		REP(j, Z) {
			E.PB(D[i] + C[j]);
		}
	}
	RSORT(E);
	REP(i, K) {
		cout << E[i] << endl;
	}

    return 0;
}


Measured memory_bytes: 42856
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string a,b;
int n,m;

int solve(int x, int y){
    int ret=0,cnt=0;
    while(x < n && y < m){
        if(a[x] == b[y]){
            cnt++;
        }else{
            ret = max(ret,cnt);
            cnt = 0;
        }
        x++;
        y++;
    }
    return max(ret,cnt);
}

int main(){
    while(cin >> a >> b){
        int x=0,y=0,t=1,tmp=0,ret=0;
        n=a.size();
        m=b.size();
        for(int i=0;i<n;i++){
            ret = max(ret,solve(i,0));
        }
        for(int i=0;i<m;i++){
            ret = max(ret,solve(0,i));
        }
        cout << ret << endl;
    }
}

Measured memory_bytes: 936
N,K=input().split()
n,k=int(N),int(K)
p=list(input().split())
ans = 0

for i in range (len(p)):
    p[i]=int(p[i])

pre=[0 for i in range (n+1)]
q=[0 for i in range (n-k+100)]


pre[0]=p[0]
for i in range(n):
    pre[i+1]=pre[i]+p[i]

for i in range(n-k+1):
    tmp = pre[i+k]-pre[i]
    ans = max(ans , tmp)

print ((ans + k) / 2)

Measured memory_bytes: 20072
#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);
   
   free(l);free(r);
   
   return 0;
}


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

public class Main {
  private static void execute(ContestReader reader, PrintWriter out) {
    int a = reader.nextInt();
    int b = reader.nextInt();
    int h = reader.nextInt();
    out.println((a + b) * h / 2);
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 22996
n = int(input())
num_list = []
for i in range(n):
  num_list.append(list(map(int,input().split())))

k = 0
for i in range(n-2):
  if num_list[i][0] == num_list[i][1]:
    if num_list[i+1][0] == num_list[i+1][1]:
      if num_list[i+2][0] == num_list[i+2][1]:
        print('Yes')
        k += 1
        break
if k == 0:
  print('No')

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

template<class T> inline bool chmin(T& a, T b) {
    if (a > b){
        a = b;
        return true;
    }
    return false;
}

const long long INF = 1LL << 60;

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

    long long dp[100010];

    for (int i=0; i < 100010; i++) dp[i] = INF;

    dp[0] = 0;
    dp[1] = 1;
    dp[6] = 1;
    dp[9] = 1;

    for (int x=2; x <= N; x++) {
        chmin(dp[x], dp[x-1] + 1);

        for (int i=0; i <= 7; i++) {
            int m=6;
            for (int j=0; j < i; j++) m*=6;

            if (x >= m) chmin(dp[x], dp[x-m] + 1);
        }

        for (int i=0; i <= 6; i++) {
            int m=9;
            for (int j=0; j < i; j++) m*=9;

            if (x >= m) chmin(dp[x], dp[x-m] + 1);
        }
    }

    cout << dp[N] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
using namespace std;
unordered_set<string> S;
int main() {
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        S.insert(s);
    }
    cout << S.size() << '\n';
    return 0;
}

Measured memory_bytes: 17788
// AtCoder AGC095 C - Many Medians
// 2020.1.22 bal4u

#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int in() {   // 非負整数の入力
	int n = 0; int c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void outs(char *s) { while (*s) pc(*s++); }

char *out(char *b, int n) { // 非負整数の表示（出力）
	int i;

	i = 15, b[i] = 0;
	b[--i] = '\n';
	while (n) b[--i] = n % 10 + '0', n /= 10;
	return b+i;
}

typedef struct { int x, id; } T;
T a[200005];
int N;
int id[200005];

void Qsort(T *a, int l, int r) {
	int i, j, m; T t;
	
	i = l, j = r, m = a[(l+r) >> 1].x;
	while (1) {
		while (a[i].x < m) i++;
		while (m < a[j].x) j--;
		if (i >= j)	break;
		t = a[i], a[i] = a[j], a[j] = t;
		i++, j--;
	}
	if (l+1 < i) Qsort(a, l, i-1);
	if (j+1 < r) Qsort(a, j+1, r);
}

char s1[20], s2[20];
int main()
{
	int i, n;
	char *a1, *a2;
	
	N = in(), n = N / 2;
	for (i = 0; i < N; ++i) a[i].x = in(), a[i].id = i;
	Qsort(a, 0, N-1);
	a1 = out(s1, a[n-1].x), a2 = out(s2, a[n].x);
	for (i = 0; i < N; ++i) id[a[i].id] = i;
//	for (i = 0; i < N; ++i) printf("[%d] %d\n", i, id[i]);
	
	for (i = 0; i < N; ++i) outs((id[i] >= n)? a1: a2);
	return 0;
}


Measured memory_bytes: 4480
#include <iostream>
#include <cstring>

using namespace std;
char dic[256];

int main(void){
  int n;
  cin >> n;
  while(n){
    memset(dic,0,sizeof(dic));

    for(int i=0; i<n; i++){
      char to;
      char from;
      cin >> from >> to;
      dic[from] = to;
    }

    int m; cin >> m;
    
    for(int i=0; i<m; i++){
      char from; cin >> from;
      if(dic[from] == 0)
	cout << from;
      else
	cout << dic[from];
    }
    cout << endl;
    cin >> n;
  }
  return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include<stdio.h>
using namespace std;

int main(){
    while(1){
        int sum=0;
        string num;
        cin >> num;
        if(num[0] =='0') break;
        for(int i=0; num[i]!='\0'; i++){
            sum+= num[i] - '0';
        }
           cout <<sum<<endl;
    }
 
   

}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
#define int long long 
#define float long double 
#define el '\n'
#define all(a) (a).begin(),(a).end()
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
        enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
        ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
        *this << "[";
        for (auto it = d.b; it != d.e; ++it)
                *this << ", " + 2 * (it == d.b) << *it;
        ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int dp[1001][1001];
const int hell = 1e9 + 7 ;

signed main(){         
        IOS;
        
	int n ,m ; 
	cin >> n >> m ; 
	string grid[n];
	for(string& a : grid) cin >> a;

	dp[0][0] = 1;

	for(int i=1;i<n;i++) dp[i][0] = (dp[i-1][0])*(grid[i][0] == '.');
	for(int j=1;j<m;j++) dp[0][j] = (dp[0][j-1])*(grid[0][j] == '.');

	for(int i=1;i<n;i++){
		for(int j=1;j<m;j++){
			( dp[i][j] = (dp[i-1][j]+dp[i][j-1])*(grid[i][j] == '.') ) %= hell;
		}
		debug() << imie(range(dp[i],dp[i]+m)) ;
	}

	cout << dp[n-1][m-1] << endl; 

        return 0;
}


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

int main() {
    uint N;
    cin >> N;
    vector<int> A(N, 0);
    for (auto &a: A) cin >> a;
    auto iter = minmax_element(A.begin(), A.end());
    int ans = *iter.second - *iter.first;
    cout << ans << endl;
}


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

N = int(input())

ans = float('inf')

a = 1
while a <= N**0.5:
    if N % a == 0:
        b = int(N/a)
        ans = min(ans, max(len(str(a)), len(str(b))))
    a += 1

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  char b, ans;
  cin >> b;

  if (b == 'A') {
    ans = 'T';
  } else if (b == 'T') {
    ans = 'A';
  } else if (b == 'C') {
    ans = 'G';
  } else {
    ans = 'C';
  }
  cout << ans;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
#define OUT(n) cout << (n) << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int fh, h, ft;
    cin >> fh >> h >> ft;
    int x; cin >> x;

    int ans = 0;
    REP(i,fh+1) REP(j,h+1) REP(k,ft+1) {
        if (i*500+j*100+k*50 == x) ans++;
    }

    cout << ans << endl;

    return 0;
}

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

int main(int argc, char **argv)
{
	ll N, K; cin >> N >> K;

	vector<ll> vec(K, 0);
	for (ll i = 1; i <= N; ++i) ++vec[i%K];
	
	ll res{0};
	for (ll a = 0; a < K; ++a)
	{
		ll b = (K-a) % K;
		ll c = (K-a) % K;

		if ((b + c) % K != 0) continue;
		res += vec[a] * vec[b] * vec[c];
	}

	std::cout << res << std::endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rf(x) (x)=0;while(*p<48)p++;while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);
//#define rf(x) (x)=0;while(*p<48)im=*p=='-';while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);if(im)(x)=-(x);
#define pb push_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[(sz(V)-2)])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define cb(x) (x)=(!(x))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
#define INFST (0x7f7f7f7f)
#define INFLLST (0x7f7f7f7f7f7f7f7fll)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
typedef complex<ld> base;
const ld EPS = (ld)1e-7;
const ld PI = acos(0) * 2;
bool isZero(const ld& x) { return abs(x) <= EPS; }
int sign(const ld& x) { return isZero(x) ? 0 : (0 < x ? 1 : -1); }
ll gcd(ll a, ll b) { for(;b;a%=b,swap(a,b)){} return abs(a); }
pll operator + (const pll& a, const pll& b) { return pll(a.first+b.first, a.second+b.second); }
pll operator - (const pll& a, const pll& b) { return pll(a.first-b.first, a.second-b.second); }
pll operator * (const pll& a, const ll& b) { return pll(a.first*b, a.second*b); }
ll operator * (const pll& a, const pll& b) { return a.first*b.second - b.first*a.second; }
ll ccw(const pll& a, const pll& b, const pll& c) { return a*b + b*c + c*a; }
void fg(vector<int> G[], int a, int b) { G[a].pb(b); G[b].pb(a); }
void fg(vector<pii> G[], int a, int b, int c) { G[a].pb({b, c}); G[b].pb({a, c}); }

ll a, b;

int main() {
	cin >> a >> b;
	cout << (a - gcd(a, b))*3 << endl;
	return 0;
}

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

int main(){
  int n,m;
  cin>>n>>m;
  ll x[n];
  ll y[n];
  ll z[n];
  rep(i,0,n) cin>>x[i]>>y[i]>>z[i];
  ll ans=0;
  rep(i,0,8){
    int p=i%2;
    int q=i/2%2;
    int r=i/4%2;
    p=2*p-1;
    q=2*q-1;
    r=2*r-1;
    ll a[n];
    rep(j,0,n){
      a[j]=x[j]*p+y[j]*q+z[j]*r;
    }
    sort(a,a+n);
    reverse(a,a+n);
    ll cur=0;
    rep(j,0,m){
      cur+=a[j];
    }
    ans=max(ans,cur);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>

struct Point{
  double x;
  double y;
};

double Xcoordinate(Point s,Point t,double ratio){
  return (t.x-s.x)*ratio+s.x;
}

double Middlecoordinate(Point s,Point t,double ratio){
  return (t.x-s.x)*ratio+s.y;
}

double Ycoordinate(Point s,Point t,double ratio){
  if(s.y<=t.y){
    return (t.y-s.y)*ratio+s.y;
  }else{
    return s.y-(s.y-t.y)*ratio;
  }
}


Point knock(int n,Point s,Point t){
  if(n==0){
    return t;
  }
  Point a,b,c;
  a.x=Xcoordinate(s,t,1.0/3.0);
  a.y=Ycoordinate(s,t,1.0/3.0);
  c.x=Xcoordinate(s,t,2.0/3.0);
  c.y=Ycoordinate(s,t,2.0/3.0);
  if(((t.y-s.y)/(t.x-s.x))>0){
    b.x=s.x;
    b.y=c.y;
  }else if(s.y==t.y){
    b.x=Xcoordinate(s,t,1.0/2.0);
    b.y=Middlecoordinate(s,t,(sqrt(3)/6));
  }else{
    b.x=t.x;
    b.y=a.y;
  }

  knock(n-1,s,a);
  std::cout<<std::fixed<<std::setprecision(8)<<a.x<<' '<<a.y<<'\n';
  knock(n-1,a,b);
  std::cout<<std::fixed<<std::setprecision(8)<<b.x<<' '<<b.y<<'\n';
  knock(n-1,b,c);
  std::cout<<std::fixed<<std::setprecision(8)<<c.x<<' '<<c.y<<'\n';
  knock(n-1,c,t);
}

int main(){
  Point p;
  Point q;
  p.x=0;
  p.y=0;
  q.x=100;
  q.y=0;
  int n;
  std::cin>>n;
  std::cout<<std::fixed<<std::setprecision(8)<<p.x<<' '<<p.y<<'\n';
  knock(n,p,q);
  std::cout<<std::fixed<<std::setprecision(8)<<q.x<<' '<<q.y<<'\n';
  return 0;
}



Measured memory_bytes: 3200
//
// Created by Myabu on 2020/01/25.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;


int main(void){
    int N;
    cin>>N;
    vector<int> L(N);

    for (int i = 0; i < N; ++i) {
        cin>>L[i];
    }
    sort(L.begin(), L.end());

    int sum =0;
    for (int i = 0; i < N - 1; ++i) {
        sum += L[i];
//        cout<<L[i]<<endl;
    }

//    cout<<sum<<endl;

    if(L[N-1] < sum){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }


    return 0;
}

Measured memory_bytes: 256
import math
N = int(input())

sosu_dict = {}
a = N
b = N
#print(int(math.sqrt(N+1)))
for i in range(1, int(math.sqrt(N))+1):
    if a % i == 0:
        sosu_dict[i] = int(a/i)
        b = a/i
 

if b > 1:
    sosu_dict[int(b)] = int(a/b)

#print(sosu_dict)

sum = 10 ** 15 +1
for key in sosu_dict:
    if (key + sosu_dict[key]) < sum:
        sum = key + sosu_dict[key]

print(sum-2)




Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[1000];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a, a+n);
    cout << a[n-1]-a[0] << endl;
    return 0;
}

Measured memory_bytes: 256