akhauriyash/Code-Regression huggingface dataset:
//gcc -o program test.c
//./program
//time ./program で時間計測
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node{
    int key;//格納する値
    struct node *prev,*next;//前の値、後ろの値のメモリの位置
};
struct node *nil;//番兵ノード
void init(){//リスト初期化用関数。
    nil=(struct node *)malloc(sizeof(struct node));//nodeが格納されるメモリを確保して、ポインタ型にキャストし番地をnilにいれる
    nil->next=nil;//一個も要素がないからnextにnilが入る。
    nil->prev=nil;
}
void insert(int key){//値xを先頭に追加
    struct node *x=(struct node *)malloc(sizeof(struct node));
    x->key=key;//ノードにkeyを代入
    x->next=nil->next;//番兵の直後にxを代入するため、番兵の元々次のノードをxの次のノードに設定する。
    x->prev=nil;//xは番兵の次に設定するのでprevには番兵を入れる
    nil->next->prev=x;//番兵の元々次のノードの前のノードにxを設定する
    nil->next=x;//番兵の元々次のノードの設定が終わりかつ、xに次のノードを設定したので番兵の次のノードにxを設定する
    return;
}
void delete(int key){//最初に見つけた値xを削除
    struct node *searcher=nil->next;//番兵の次のノードから探索を始める。
    while(searcher!=nil &&searcher->key!=key){//searcherが番兵に戻ってくるまで、または、searcherが目的のノードを見つけるまで繰り返す。
        searcher=searcher->next;//一個先のノードに移動
    }
    if(searcher==nil){//一周していたら値が見つからなかったと判断し何もせずに戻る。
        return;
    }
    searcher->prev->next=searcher->next;//searcherの前のノードの次をsearcherの次のノードに設定する
    searcher->next->prev=searcher->prev;//searcherの次のノードの前をsearcherの前のノードに設定する
    free(searcher);//searcherのメモリを開放(削除)する。
    return;
}
void deleteFirst(){//リストの先頭の値を削除
    struct node *target=nil->next;//番兵の次のノードを削除するので、targetに番兵の次のノードを設定する。
    nil->next=target->next;
    target->next->prev=nil;
    free(target);
    return;
}
void deleteLast(){//リストの末尾を削除
    struct node *target=nil->prev;//番兵の前（一番後ろ）をtargetにする
    nil->prev=target->prev;
    target->prev->next=nil;
    free(target);
    return;
}

int main(void){
    int command_number;
    int key;
    init();
    scanf("%d",&command_number);
    for(int i=0;i<command_number;i++){
        char command[16];
        int num;
        scanf("%s",command);
        if(strcmp(command,"deleteFirst")==0){
            deleteFirst();
        }else if(strcmp(command,"deleteLast")==0){
            deleteLast();
        }
        else{
            scanf("%d",&num);
            if(strcmp(command,"insert")==0){
                insert(num);
            }else if(strcmp(command,"delete")==0){
                delete(num);
            }
        }
    }
    struct node *output=nil->next;//一番最初のノードから始める
    while(1){
        printf("%d",output->key );
        if(output->next!=nil){
            output=output->next;
            printf(" ");
        }else{
            break;
        }
        
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 32968
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int W = sc.nextInt();
		int w[] = new int[n+1];
		int v[] = new int[n+1];
		int dp[][] = new int[n+1][3*n+1];
		
		int w1 = sc.nextInt();
		w[1] = 0;
		v[1] = sc.nextInt();
		for(int i=2;i<=n;i++){
			w[i] = sc.nextInt() - w1;
			v[i] = sc.nextInt();
		}
		
		for(int i=1;i<=n;i++){
			for(int j=i;j>=1;j--){
				for(int k=w[i];k<=3*n;k++){
					dp[j][k] = Math.max(dp[j-1][k-w[i]] + v[i], dp[j][k]);
				}
			}
		}
		
		
		int ans = 0;
		for(int i=1;i<=n &&w1 * i <= W;i++){
			int t = W - w1 * i;
			t = Math.min(t, 3*n);
			ans = Math.max(ans, dp[i][t]);
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 24140
N, M = map(int, input().split())
A = list(map(int, input().split()))
B, C = (
    zip(*(map(int, input().split()) for _ in range(M))) if M else
    ((), ())
)

xs = [(a, 1) for a in A]
for b, c in zip(B, C):
    xs.append((c, b))
ans = 0
k = 0
for x, y in sorted(xs, reverse=True):
    m = min(y, N - k)
    ans += m * x
    k += m
print(ans)


Measured memory_bytes: 62504
#include <iostream>
#include <vector>
#include <map>
using namespace std;
typedef vector <int> VI;
typedef map <int,int> MII;
int main( void )
{
	int n;
	while ( cin >> n && n )
	{
		VI colors( n );
		MII numbers;
		for ( int i = 0; i < n; i++ )
		{
			cin >> colors[i];
		}

		bool not_found = true;
		for ( int i = 0; not_found && i < n; i++ )
		{
			numbers[colors[i]]++;
			if ( numbers[colors[i]] > n / 2 )
			{
				cout << colors[i] << endl;
				not_found = false;
			}
		}

		if ( not_found ) cout << "NO COLOR" << endl;
	}
	return 0;
}

Measured memory_bytes: 5848
n,p=map(int,input().split())
s=input()
ans=0
if p==2:
    for i in range(n):
        if int(s[i])%2==0:
            ans+=i+1
    print(ans)
elif p==5:
    for i in range(n):
        if int(s[i])%5==0:
            ans+=i+1
    print(ans)
else:
    s=s[::-1]
    accum=[0]*n
    d=dict()
    for i in range(n):
        accum[i]=int(s[i])*pow(10,i,p)%p
    for i in range(n-1):
        accum[i+1]+=accum[i]
        accum[i+1]%=p
    accum[-1]%=p
    #print(accum)
    for i in range(n):
        if accum[i] not in d:
            if accum[i]==0:
                ans+=1
            d[accum[i]]=1
        else:
            if accum[i]==0:
              ans+=1
            ans+=d[accum[i]]
            d[accum[i]]+=1
    #print(d)
    print(ans)

Measured memory_bytes: 11716
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            string S = Console.ReadLine();
            //xとyで比較してカウントが大きいのを表示
            string x = "";
            string y = "";
            int cnt = 0;
            for (int i = 0; i < N ; i++)
            {
                x = S.Substring(0, i + 1);
                y = S.Substring(x.Length ,S.Length - x.Length);
                HashSet<string> checkX = new HashSet<string>();
                for (int j = 0; j < x.Length; j++)
                {
                    if (y.Contains(x.Substring(j, 1)))
                    {
                        checkX.Add(x.Substring(j, 1));
                    }
                }
                if (cnt < checkX.Count())
                {
                    cnt = checkX.Count();
                }
            }
            Console.WriteLine(cnt);
        }
    }
}
// 文字列の入力
//string s = Console.ReadLine();

// 整数の入力
//long n = long.Parse(Console.ReadLine());

// 文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');

// 整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();


Measured memory_bytes: 28444
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

#define ll long long
#define ull unsigned long long
#define REP(i, n) for(int i=0; i<n; i++)

long long X[200000];
long long tmp[200000];
int main(){
    int N;
    cin >> N;
    long long inp;
    REP(i,N){
        cin >> inp;
        X[i] = tmp[i] = inp;
    }
    sort(tmp, tmp+N);
    long long med = tmp[N/2];
    long long med_left = tmp[N/2 - 1];

    REP(l, N){
        if(X[l] < med) 
            cout << med << endl;
        else
            cout << med_left << endl;
    }
    return 0;
}


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

int dp[100050][2][110];
int seen[100050][2][110];
string digit;
int D, l;

int solve(int id, int can, int r)
{
	if(id == l) return !r;
	int num = digit[id] - '0', ans = 0;
	if(seen[id][can][r]) return dp[id][can][r];
	for(int i = 0; i < 10; i++)
		if(can or i <= num)
			ans = (ans + solve(id + 1, can or i < num, (r + (i % D)) % D)) % 1000000007LL;
	seen[id][can][r] = 1;
	return dp[id][can][r] = ans;
}

int32_t main()
{
	cin >> digit >> D;
	l = digit.size();
	int ans = (solve(0, 0, 0) - 1) % 1000000007LL;
	if(ans < 0) ans += 1000000007LL;
	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 39936
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;


int main() {
    int n; cin >> n;
    multimap<string,int> m;
    for(int i = 0;i < n;i++){
        string s; cin >> s;
        auto x = m.find(s);
        if(x == m.end()){
            m.insert(make_pair(s,1));
        }else{
            x->second++;
        }
    }
    int z = 0;
    for(auto x:m){
        z = max(z,x.second);
    }
    for(auto x:m){
        if(x.second == z) cout << x.first << endl;
    }
}




Measured memory_bytes: 19184
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<sstream>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<ctime>
using namespace std;
const int MAXN = 100000+5;
int n, m;
struct node
{
    int i;
    node * next;
};
int h[MAXN];
node *con[MAXN] = {0};
int main()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
    {
        cin >> h[i];
    }
    for(int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        node *nd = (node *)malloc(sizeof(node));
        nd->i = b;
        nd->next = con[a];
        con[a] = nd;
        nd = (node *)malloc(sizeof(node));
        nd->i = a;
        nd->next = con[b];
        con[b] = nd;
    }
    int cnt = 0;
    for(int i = 1; i <= n; i++)
    {
        int good = 1;
        node *nd = con[i];
        while(nd != NULL)
        {
            if(h[i] <= h[nd->i])
            {
                good = 0;
                break;
            }
            nd = nd->next;
        }
        if(good) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 11016
#include<stdio.h>
#include<algorithm>
#include<utility>
#include<string>
#include<cstdlib>
#include<iostream>

using namespace std;

int main(){
    int a[199];
    int num = 0;
    string  str;
    while(cin >> str){
        if(str[0] == '+'){
            a[num-2] += a[num-1];
            num--;
        }
        else if(str[0] == '-'){
            a[num-2] -= a[num-1];
            num--;
        }
        else if(str[0] == '*'){
            a[num-2] *= a[num-1];
            num--;
        }
        else{
            a[num] = atoi(str.c_str());
            num++;
        }
    }
    printf("%d\n", a[0]);
}


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

typedef long long ll;

int main() {
  ll n;
  std::cin >> n;
  std::vector< ll > va(n, 0);

  ll cnt = 0;
  for (ll i = 0; i < n; i++) {
    std::cin >> va[i];
    if (va[i] % 2 == 1) {
      cnt++;
    }
  }

  std::string judge = "YES";
  if (cnt % 2 == 1) {
    judge = "NO";
  }

  std::cout << judge << std::endl;
  return 0;
}


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

int main() {
  int an[3];rep(i,3)cin>>an[i];
  sort(an, an+3);
  if (an[0]+an[1]==an[2])cout << "Yes";
  else cout << "No";
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
# define rr
const int N=100010,INF=0x3f3f3f3f;
char s[N],t[N];
int len;
inline int read(void){
	int res,f=1;
	char c;
	while((c=getchar())<'0'||c>'9')
		if(c=='-')f=-1;
	res=c-48;
	while((c=getchar())>='0'&&c<='9')
		res=res*10+c-48;
	return res*f;
}
int main(void){
	scanf("%s%s",s+1,t+1);
	len=strlen(s+1);
	for(rr int i=1;i<=len;++i){
		if(s[i]!=t[i]){
			printf("No");
			return 0;
		}
	}
	printf("Yes");
	return 0;
}


Measured memory_bytes: 3752
#include <stdio.h>
#include <stdlib.h>
 
typedef struct _node{
    int key;
    struct _node *left;
    struct _node *right;
}NODE;
NODE* makeNode(int x){
    NODE *n=(NODE*)malloc(sizeof(NODE));
    n->key=x;
    n->left=NULL;
    n->right=NULL;
     
    return n;
}
NODE* insert(NODE *t,int x){
    if(t==NULL)return makeNode(x);
 
    if(t->key<x)t->right=insert(t->right,x);
    else t->left=insert(t->left,x);
     
    return t;
}
void inorder(NODE *t){
    if(t==NULL)return;
     
    if(t->left!=NULL)inorder(t->left);
    printf(" %d",t->key);
    if(t->right!=NULL)inorder(t->right);
     
    return;
}
void preorder(NODE *t){
    if(t==NULL)return;
     
    printf(" %d",t->key);
    if(t->left!=NULL)preorder(t->left);
    if(t->right!=NULL)preorder(t->right);
     
    return;
}
void find(NODE *t,int x){
    if(t==NULL){
        printf("no\n");
        return;
    }
     
    if(t->key==x){
        printf("yes\n");
        return;
    }
    else if(t->key<x)find(t->right,x);
    else find(t->left,x);
}
int main(void){
    NODE *root;
    root=NULL;
     
    int n;
    scanf("%d\n",&n);
     
    char com[6+1];
    int x;
    while(n--){
        scanf("%s",com);
        switch(com[0]){
            case 'i':
                //insert
                scanf("%d\n",&x);
                root=insert(root,x);
                break;
            case 'p':
                //print
                inorder(root);
                printf("\n");
                preorder(root);
                printf("\n");
                break;
            case 'f':
                scanf("%d\n",&x);
                find(root,x);
                break;
        }
    }
     
    return 0;
}


Measured memory_bytes: 14208
from sys import stdin
import math

order = {'0': 0, '9': 1, '8': 2, '7': 3, '6': 4, '5': 5, '4': 6, '3': 7, '2': 8, '1': 9}
r = 0
foods = sorted([stdin.readline().rstrip() for _ in range(5)], key=lambda food: order[food[-1]])

for i, food in enumerate(foods):
    if food[-1] == '0' or i == 4:
        r += int(food)
    else:
        r += 10 * (math.floor(int(food) / 10) + 1)

print(r)

Measured memory_bytes: 3064
# include <stdio.h>

int main(void){
  char buf[1000];
  int A, P;
  int x;
  
  fgets(buf, sizeof(buf), stdin); //改行文字またはファイルの終了までよみこむ
  sscanf(buf, "%d %d\n", &A, &P);
  
  x = (3 * A + P) / 2;
  printf("%d\n", x);
  
  return 0;
}
  
  

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

class Program
{
    static void Main(string[] args)
    {
        var sx = sc.ReadInt();
        var sy = sc.ReadInt();
        var tx = sc.ReadInt();
        var ty = sc.ReadInt();
        var ans = "";
        for (int i = 0; i < ty - sy; i++)
        {
            ans += "U";
        }
        for (int i = 0; i < tx - sx; i++)
        {
            ans += "R";
        }
        for (int i = 0; i < ty - sy; i++)
        {
            ans += "D";
        }
        for (int i = 0; i < tx - sx; i++)
        {
            ans += "L";
        }

        ans += "L";
        for (int i = 0; i <= ty - sy; i++)
        {
            ans += "U";
        }
        for (int i = 0; i <= tx - sx; i++)
        {
            ans += "R";
        }
        ans += "D";
        ans += "R";
        for (int i = 0; i <= ty - sy; i++)
        {
            ans += "D";
        }
        for (int i = 0; i <= tx - sx; i++)
        {
            ans += "L";
        }
        ans += "U";
        Console.WriteLine(ans);
    }
    static Scanner sc = new Scanner();
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }
    public string ReadStr()
    {
        return this.Next();
    }
    public char ReadChar()
    {
        return this.Next()[0];
    }
    public int ReadInt()
    {
        return int.Parse(this.Next());
    }
    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }
    public long ReadLong()
    {
        return long.Parse(this.Next());
    }
    public double ReadDouble()
    {
        return double.Parse(this.Next());
    }
    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }
    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }
    public double[] ReadDoubleArray(int n)
    {
        var array = new double[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadDouble();
        }
        return array;
    }
    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}


Measured memory_bytes: 34772
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MOD = 998244353;

int power(int x, int t)
{
	int ret = 1;
	while(t > 0) {
		if(t & 1) ret = 1LL * ret * x % MOD;
		x = 1LL * x * x % MOD;
		t >>= 1;
	}
	return ret;
}

int n, m;
int dp[100005];
bool hv[100005];
vector<int> G[100005];
int cur[131072];
int cnt[131072];

void gen_cnt(int x)
{
	scanf("%d", &m);
	rep1(i, n) G[i].clear();
	rep(i, m) {
		int u, v;
		scanf("%d%d", &u, &v);
		G[min(u, v)].push_back(max(u, v));
	}
	for(int i = n; i >= 1; i --) {
		rep(j, G[i].size()) hv[dp[G[i][j]]] = true;
		for(dp[i] = 0; hv[dp[i]]; dp[i] ++);
		rep(j, G[i].size()) hv[dp[G[i][j]]] = false;
	}
	
	rep(i, 131072) cur[i] = 0;
	rep1(i, n) cur[dp[i]] = (cur[dp[i]] + power(10, 18 * i)) % MOD;
	rep(i, 17) rep(j, 131072) if(!(j >> i & 1)) {
		int ev = cur[j], od = cur[j | 1 << i];
		cur[j] = (ev + od) % MOD;
		cur[j | 1 << i] = (ev - od + MOD) % MOD;
	}
	rep(i, 131072) cnt[i] = 1LL * cnt[i] * cur[i] % MOD;
}

int main()
{
	scanf("%d", &n);
	int ans = 0;
	rep(i, 131072) cnt[i] = 1;
	rep(i, 3) gen_cnt(i);
	rep(i, 131072) ans = (ans + cnt[i]) % MOD;
	ans = 1LL * ans * power(131072, MOD - 2) % MOD;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 6656
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
    
    
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)
#define dout(n) cout<<# n<<" = "<<n<<endl;
    
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ld x;
    cin>>x;
    ld y = x/3;
    ld ans = y*y*y;
    cout(10)<<ans<<endl;
}

Measured memory_bytes: 256
#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;
int main(){
    int a,b; cin >> a >> b;
    string ans = "";
    if(a < b) {
        rep(i,b) ans += to_string(a);
    }else{
        rep(i,a) ans += to_string(b); 
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define ll                    long long int
#define ll_MAX                LLONG_MAX
#define ll_MIN                LLONG_MIN
#define pi                    3.14159265358979323846
#define count_1(n)            __builtin_popcountll(n)
#define MOD                   1000000007
#define MAX                   1e9
#define MIN                   -1e9
#define itoc(c)               ((char)(((int)'0')+c))
#define mid(s,e)              (s+(e-s)/2)
const int MX=10010896;
const int lmt=3164;
const int N=10000001;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
ll extgcd(ll a,ll b,ll& x,ll& y){if(b==0){x=1;y=0;return a;}else{int g=extgcd(b,a%b,y,x);y-=a/b*x;return g;}}
ll modpow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
#define print_upto(a,n)        for(int i=0;i<n;i++)    cout<<a[i]<<" "; cout<<endl
#define print(a)        for (auto x : a) cout << x << " "; cout << endl

inline void solve(){
	ll n;cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	ll sm=0;
	for(ll i=1;i<n;i++){
		if(a[i]<a[i-1]){
			//cout<<(a[i-1]-a[i])<<" ";
			sm+=(a[i-1]-a[i]);
			a[i]+=(a[i-1]-a[i]);
		}
	}
	cout<<sm<<"\n";
}

int main()
{
	cout<<fixed<<setprecision(12);
	fastio;ll  t=1,tc=1;
	#ifndef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout);
	#endif
	//cin>>t;
	while(t--){solve();}return 0;
}

Measured memory_bytes: 5172
#include <stdio.h>
int twoCount(int tk,int ts){
    if(tk>=ts)
        return ts+1;
    else if(tk*2<ts)
        return 0;
    else
        return tk*2-ts+1;
}

int main(void){
    
    int k,s,cnt,st;
    scanf("%d",&k);
    scanf("%d",&s);
    cnt=0;
    if(k>s)
        st=s;
    else
        st=k;
    for(int i=st;i>=0;i--){
        cnt+=twoCount(k,s-i);
    }
    printf("%d",cnt);
    
}

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

int main(){
    ll a,b,c,m,n,sm=0,i,j,x,y,ar[200010];
    scanf("%lld %lld %lld",&a,&b,&c);
    if(b*c>=a) printf("Yes\n");
    else printf("No\n");

    return 0;
}


Measured memory_bytes: 3740
package main

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

var si = bufio.NewScanner(os.Stdin)

func readInt() int {
        si.Scan()
        r, _ := strconv.Atoi(si.Text())
        return r
}

func main() {
        si.Split(bufio.ScanWords)
        si.Buffer(make([]byte, 0), 10000000)

        N, M, C := readInt(), readInt(), readInt()
        B := make([]int, M)
        for i := 0; i < M; i++ {
                B[i] = readInt()
        }
        ans := 0
        for i := 0; i < N; i++ {
                ret := C
                for j := 0; j < M; j++ {
                        ret += B[j] * readInt()
                }
                if ret > 0 {
                        ans += 1
                }
        }
        fmt.Println(ans)
}

Measured memory_bytes: 640
#include<stdio.h>

int main(){
    int n, k;
    scanf("%d%d", &n, &k);
    int c = 0;
    for(int i=0; i<n; i++){
        int a;
        scanf("%d", &a);
        if(a >= k){
            c++;
        }
    }
    printf("%d", c);

    return 0;
}

Measured memory_bytes: 128
from collections import defaultdict

mod = 10 ** 9 + 7

memo = defaultdict(int)


def cmb(n, r):
    if (n, r) in memo:
        return memo[(n, r)]

    if n < r or r < 0:
        return 0

    if r > n - r:
        return cmb(n, n - r)

    res = f[n] * pow(f[n - r], mod - 2, mod) * pow(f[r], mod - 2, mod) % mod
    memo[(n, r)] = res
    return res


n, m, k = map(int, input().split())

f = [1]
for i in range(1, 2 * 10 ** 5 + 1):
    f.append(f[-1] * i % mod)

ans = 0
for d in range(1, m):
    ans += d * (m - d) * n ** 2
    ans %= mod

for d in range(1, n):
    ans += d * (n - d) * m ** 2
    ans %= mod

ans *= cmb(n * m - 2, k - 2)
ans %= mod

print(ans)


Measured memory_bytes: 11384
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i =a; i<n; i++) 
#define ll long long
#define MOD 1000000007
using namespace std;
  
int main() {
  int N; cin >> N;
  bool D[N]; rep(i,0,N) D[i] = false;
  rep(i,0,N) {
    int a,b; cin >> a >> b;
    if (a == b) D[i] = true;
  }
  
  int z =0; bool check = false;
  rep(i,0,N) {
    if (D[i]) z++;
    else z =0;
    if (z ==3) {
      check = true; break;
    }
  }
  if (check) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main() {
  int N,sum;
  cin >> N;
  
  for (int i = 0; i < N; i++){
    int l,r;
    cin >> l >> r;
    sum += (r - l + 1);
  }
  
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n;
vector <int> a;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    a.resize(n);
    ll sum = 0;
    for(auto &i : a){
        cin >> i;
        sum += i;
    }
    ll s = 1LL * n * (n + 1) / 2;
    if(sum % s) finish("NO");
    ll h = sum / s;
    ll cnt = 0;
    for(int i = 0 ; i < n ; i++){
        ll d = a[i] - a[(i - 1 + n) % n] - h;
        if(d % n) finish("NO");
        cnt += abs(d / n);
    }
    if(cnt == h) cout << "YES\n";
    else cout << "NO\n";
}


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

int main() {
    int N;
    cin >> N;
    if (N % 2 == 0) cout << N << endl;
    else cout << 2*N << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <tuple>
#include <deque>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <unordered_set>
#define int long long
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()

using namespace std;

const int MOD = 1e9 + 7;
const int INF = 1e9;

void fast()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

signed main()
{
    fast();
    int x;
    cin >> x;
    cout << 1 - x << '\n';
    return 0;
}

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

using namespace std;

int N, p[200009], closest[200009];
bool x[200009], ap[200009];

bool atLeast (int K)
{
    for (int i=1; i<2 * N; i++)
        x[i] = (p[i] >= K), ap[i] = 0;
    bool atLeastOneStableSubarray = 0;
    for (int i=1; i<2 * N - 1; i++)
        if (x[i] == x[i + 1])
            ap[i] |= 1, ap[i + 1] |= 1, atLeastOneStableSubarray = 1;
    if (!atLeastOneStableSubarray) return x[1];
    if (ap[N]) return x[N];
    int lst = -2 * N;
    for (int i=1; i<2 * N; i++)
        if (ap[i]) lst = i;
        else closest[i] = lst;
    lst = 4 * N;
    for (int i=2 * N - 1; i>=1; i--)
        if (ap[i]) lst = i;
        else
        if (lst - i < i - closest[i]) closest[i] = lst;
    return x[closest[N]];
}

int binarySearch ()
{
    int p = 3, u = 2 * N - 2, ans = 2, mij;
    while (p <= u)
    {
        mij = (p + u) >> 1;
        if (atLeast (mij)) ans = mij, p = mij + 1;
        else u = mij - 1;
    }
    return ans;
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=1; i<2 * N; i++)
    scanf ("%d", &p[i]);
printf ("%d\n", binarySearch ());
return 0;
}


Measured memory_bytes: 2176
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;
//struct edge{lint to,num;};
//vector<int> bucket[MAX_N/1000];

int main(void){
    lint a[4];
    rep(i,4) cin >> a[i];
    lint ans=a[0]*a[2];
    ans=max(ans,a[0]*a[3]);
    ans=max(ans,a[1]*a[2]);
    ans=max(ans,a[1]*a[3]);
    cout << ans << endl;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

int main() {
  string s;
  cin >> s;
  if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) cout << "Bad" << endl;
  else cout << "Good" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
int A,B,i,k;
cin >> A >> B;
	i=(A-1)/50;
	k=(B-1)/50;
	cout << 2*i+2*k+5 << " " << 100 << endl;
for(k=1;k<=(A-1)/50;k++){
for(i=1;i<=50;i++){
cout<< "."<< "#";
}
cout << endl;
for(i=1;i<=100;i++){
cout<< "#";
}
cout << endl;
}
k=(A-1)%50;
for(i=1;i<=k;i++){
cout<< ".";
cout<< "#";
}
for(i=1;i<=200-2*k;i++){
cout<< "#";
if(i==100-2*k){
cout << endl;
}
}
	cout << endl;
for(i=1;i<=100;i++){
cout<< ".";
}
cout << endl;
for(k=1;k<=(B-1)/50;k++){
for(i=1;i<=50;i++){
cout<< "#"<< ".";
}
cout << endl;
for(i=1;i<=100;i++){
cout<< ".";
}
cout << endl;
}
k=(B-1)%50;
for(i=1;i<=k;i++){
cout<< "#";
cout<< ".";
}
for(i=1;i<=200-2*k;i++){
cout<< ".";
if(i==100-2*k){
cout << endl;
}
}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

pair<int, int> dish[3010];
int dp[3010][3010];

int main() {
	int N, T;
	cin >> N >> T;
	for(int i=0; i<N; ++i){
		int A, B;
		cin >> A >> B;
		dish[i]=make_pair(A, B);
	}
	sort(dish, dish+N);
	int ans=dish[0].second;
	for(int i=0; i+1<N; ++i){
		for(int j=1; j<T; ++j){
			dp[i+1][j]=max(dp[i+1][j-1], dp[i][j]);
			if(dish[i].first<=j){
				dp[i+1][j]=max(dp[i+1][j], dp[i][j-dish[i].first]+dish[i].second);
			}
		}
		ans=max(ans, dp[i+1][T-1]+dish[i+1].second);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
using namespace std;
int h,w;
vector<string> f;
int cost[310][310][310];
int frmemo[310][310][310];
int fr(int d,int l,int r){
  int he=h-max(l,r);
  if(he==0) return 0;
  if(frmemo[d][l][r]!=-1) return frmemo[d][l][r];
  if(f[h-l-1][d]==f[h-r-1][d+1]) frmemo[d][l][r]=fr(d,l+1,r+1)+1;
  else frmemo[d][l][r]=fr(d,l+1,r+1);
  return frmemo[d][l][r];
}
int solve(int d,int l,int r)
{ 
  int he=h-max(l,r);
  if(he==0) return 0;
  if(cost[d][l][r]!=-1) return cost[d][l][r];
  cost[d][l][r]=fr(d,l,r)+min(solve(d,l+1,r),solve(d,l,r+1));
  return cost[d][l][r];
}
int main(void)
{
  cin >> h >> w;
  f.resize(h);
  REP(i,h) cin >> f[i];
  REP(i,310) REP(j,310)REP(k,310) cost[i][j][k]=-1;
  REP(i,310) REP(j,310)REP(k,310) frmemo[i][j][k]=-1;
  int answer=0;
  REP(i,w-1) answer+=solve(i,0,0);
  cout << answer << endl;
  return 0;
}

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

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

#define pb push_back
#define in ,
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int n;
  cin >> n;
  rep(i, 0, n) {
    int x, y, b, p;
    cin >> x >> y >> b >> p;
    cout << min((double)(x * b + y * p), (double)(x * max(b, 5) + y * max(p, 2)) * 0.8) << endl;
  }
}

Measured memory_bytes: 3256
#include<bits/stdc++.h>
    using namespace std;
    int  x[52]  , A , N;
    long long int dp[2580][52][52] = {0};
    long long int f(int sum , int co , int j)
    {
        long long int dd = 0;
        if(j == N)
            return 0;
        if(dp[sum][co][j] != -1) return dp[sum][co][j];
        if((co+1)*A == sum + x[j])
        {
            dd++;
        }
        dd += f(sum+x[j],co+1,j+1);
        dd += f(sum,co,j+1);
        dp[sum][co][j] =dd;
        return dd;
    }
    int main()
    {
        ios_base::sync_with_stdio(false);
        int i ;
        long long int ans ;
        memset(dp,-1,sizeof(dp));
        cin >> N >> A;
        for(i=0;i<N;i++)
            {
                cin >> x[i];
            }
        ans = f(0,0,0);
        cout << ans << "\n";
        return 0;
    }

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

using namespace std;

int main() {

	int n, b, x;
	vector<int> a[100];
	int cnt = 0;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> b;
		a->push_back(b);
	}

	x = a->at(0);

	for (int i = 0; i < n; i++) {
		if (x != 2) {
			x = a->at(x-1);
			cnt++;
		}
		else if (x == 2) {
			cnt++;
			cout << cnt << endl;
			return 0;
		}
	}
	
	cout << -1 << endl;
	return 0;

}



Measured memory_bytes: 892
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();
		int[]c = new int[26];
		for(int i = 0; i < S.length(); i++) {
			int k = S.charAt(i) - 'a';
			c[k]++;
		}
		for(int i = 0; i < 26; i++) {
			if(c[i] > 1) {
				System.out.println("no");
				System.exit(0);
			}
		}
		System.out.println("yes");
	}
}

Measured memory_bytes: 22996
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
  
#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 rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
  
using namespace std;
  
typedef long long ll;
typedef pair<int, int> P;

const int INF = 1<<29;

int main(){
	int n, m;
	cin >> n >> m;
	vector<vector<P > > G(n);
	rep(i, m){
		int a, b, c;
		cin >> a >> b >> c;
		G[a].push_back(MP(b, c));
	}

	vector<int> dist(n, 0), inq(n, 0);
	queue<int> q;
	q.push(0);
	dist[0] = 0;
	inq[0] = 1;

	while(!q.empty()){
		int pos = q.front();
		q.pop();
		inq[pos] = 0;

		rep(i, G[pos].size()){
			int next = G[pos][i].first;
			int d = G[pos][i].second;
			if(dist[next] < dist[pos] + d){
				dist[next] = dist[pos] + d;
				if(!inq[next]) q.push(next);
			}
		}
	}

	cout << dist[n-1] << endl;


    return 0;
}

Measured memory_bytes: 1236
import sys
from collections import defaultdict, deque
from heapq import *
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, M, = map(int, input().split())
N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
S = input().strip()

c = ""
ans = []
for i in range(len(S)):
    if c == "":
        c = S[i]
        ans.append(c)
    else:
        if ans[-1] != S[i]:
            ans.append(S[i])

print(len(ans))

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

bool is_prime(int x){
  if(x<=1){
    return false;
  }else{
  for(int i=2;i*i<=x;i++){
    if(x%i==0){
    return false;
    }
  }
  return true;
  }
}
int main(){
  int x;
  cin>>x;
  int p=x;
  while(!is_prime(p))p++;
  cout<<p<<endl;
}


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

int main()
{
	int k, t, MAXN=INT_MIN;
	cin >> k >> t;
	while(t --) {
		int tmp;cin>>tmp;
		MAXN = max(MAXN, tmp);
	} cout<<max(2*MAXN-1-k,0);
}

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

int main()
{
    string s;
    cin>>s;
    int y=0,m=0,d=0;
    int flag=0;
   // cout<<s[0]<<endl;
    for(int i=0;i<4;i++)
    {
        y*=10;
        y+=s[i]-'0';
    }
    if(y<2019)
        flag=1;
    if(y==2019)
    {

        for(int i=5;i<7;i++)
        {
            m*=10;
            m+=s[i]-'0';
        }
        if(m<4)
            flag=1;
        if(m==4)
        {

            for(int i=8;i<10;i++)
            {
                d*=10;
                d+=s[i]-'0';
            }
            if(d<=30)
                flag=1;
        }

    }
    //cout<<y<<' '<<m<<' '<<d;
    if(flag)
        cout<<"Heisei"<<endl;
    else
        cout<<"TBD"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
#define maxn 100010

using namespace std;
typedef long long llg;

int hd[maxn],nt[maxn<<1],to[maxn<<1],c[maxn<<1],tt;
int n,m,co[maxn],SIZ,cm,du[maxn];
bool vis[maxn],su;
llg ans,ci[3];

void dfs(int u){
	vis[u]=1; SIZ++; ci[co[u]]++; cm+=du[u];
	for(int i=hd[u],v;v=to[i],i;i=nt[i])
		if(!vis[v]) co[v]=(co[u]+c[i])%3,dfs(v);
		else if(co[v]!=(co[u]+c[i])%3) su=1;
}

int main(){
	scanf("%d %d",&n,&m);
	for(int i=1,x,y;i<=m;i++){
		scanf("%d %d",&x,&y);
		to[++tt]=y;nt[tt]=hd[x];hd[x]=tt;
		to[++tt]=x;nt[tt]=hd[y];hd[y]=tt;
		c[tt-1]=1; c[tt]=2; du[x]++,du[y]++;
	}
	for(int i=1,now;i<=n;i++)
		if(!vis[i]){
			dfs(i);
			if(su) ans+=1ll*SIZ*SIZ;
			else{
				now=(!ci[0])+(!ci[1])+(!ci[2]);
				if(!now) ans+=ci[0]*ci[1]+ci[1]*ci[2]+ci[2]*ci[0];
				else ans+=cm>>1;
			}
			ci[0]=ci[1]=ci[2]=0; SIZ=cm=0; su=0;
		}
	printf("%lld",ans);
	return 0;
}

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

bool prime(int x){
    for(int i=2; i*i <=x;i++){
      if(x%i==0)  return false;
   }
  return true;
}

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

  while(!prime(n)){
      n++;
   }
cout << n << endl;
} 

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        double w = scanner.nextInt();
        double h = scanner.nextInt();
        double x = scanner.nextInt();
        double y = scanner.nextInt();
        System.out.println(w * h / 2 + " " + (x * 2 == w && y * 2 == h ? 1 : 0));
    }
}

Measured memory_bytes: 21716
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

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

#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          begin(x),end(x)
#define     rz(x)           resize(x)
#define     asn(x,y)        assign(x,y)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)(x.size()))
#define     eb              emplace_back
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     vi              vector<int>
#define     pii             pair<int,int>
#define     mii             map<int,int>
#define     F               first
#define     S               second
#define     makep           make_pair
#define     maket           make_tuple
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n,x)      (((n)+(x)-1)/(x))
#define     gcd(a,b)        (__gcd((a),(b)))
#define     lcm(a,b)        ((a)*((b)/gcd((a),(b))))
#define     dbug(x)         cout<<#x<<": "<<(x)<<"\n"
#define     flush           fflush(stdout)
#define     show(x)         for(auto zz:x)cout<<zz<<" ";cout<<"\n";
#define     show2(x)        for(auto zz:x)cout<<zz.F<<" "<<zz.S<<"\n";

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const ld pi=acos(-1);
const ll inf=1e18,M=1e9+7;
const int N=1e5+10;

vi v[N];

void solve()
{
    int n,m;
    cin>>n>>m;

    int a,b;
    for(int i=0;i<m;++i)
    {
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }

    queue<int> q;
    vi vis(n+1,0),ans(n+1,0);

    q.push(1);
    vis[1]=1;

    int x;
    while(!q.empty())
    {
        x=q.front();
        q.pop();

        for(auto c:v[x])
        {
            if(!vis[c])
            {
                vis[c]=1;
                ans[c]=x;

                q.push(c);
            }
        }
    }

    for(int i=2;i<=n;++i)
    {
        if(ans[i]==0)
        {
            cout<<"No";
            return;
        }
    }

    cout<<"Yes\n";
    for(int i=2;i<=n;++i)
        cout<<ans[i]<<"\n";
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    for(int z=1;z<=t;++z)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}



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


int b[3]={1,0,-1};
int main(void){
    int a[3],k;
    int ans=0;
    cin>>a[0]>>a[1]>>a[2]>>k;
    
    for(int i=0;i<3;i++){
        if(k>0){
            ans+=b[i]*min(a[i],k);
            k-=min(a[i],k);
        }
    }

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

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

int main() {
	vector<int>n(4);
	for (int i = 0; i < 4; i++)cin >> n.at(i);
	sort(n.begin(), n.end());
	if (n.at(0) == 1 && n.at(1) == 4 && n.at(2) == 7 && n.at(3) == 9)cout << "YES" << endl;
	else cout << "NO" << endl;
}

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

bool isMonth(char s[])
{
    if (s[0] == '0' && s[1] >= '1' && '9' >= s[1])
    {
        return true;
    }
    else if (s[0] == '1' && ('2' >= s[1] && s[1] >= '0'))
    {
        return true;
    }
    return false;
}

bool isYear(char s[])
{
    bool a = true;
    for (int i = 0; i < 2; i++)
    {
        if ('0' <= s[i] && s[i] <= '9')
        {
            a = a || true;
        }
        else
        {
            a = false;
        }
    }

    return a;
}

int main()
{
    char s[4];

    cin >> s;

    if (isYear(s) && isMonth(&s[2]) && isMonth(s) && isYear(&s[2]))
    {
        cout << "AMBIGUOUS" << endl;
    }
    else if (isYear(s) && isMonth(&s[2]))
    {
        cout << "YYMM" << endl;
    }
    else if (isMonth(s) && isYear(&s[2]))
    {
        cout << "MMYY" << endl;
    }
    else
    {
        cout << "NA" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
using namespace std;
//#define mp make_pair
#define pb push_back
#define re return
#define fi first
#define se second
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<vi> vvi;
int n;
map<string,bool>mp;
bool f=1;
char last;
string s;
int main() {
	cin>>n;
	cin>>s;
	mp[s]=1;
	last=s[s.size()-1];
	for(int i=0;i<n-1;i++){
		cin>>s;
		if(s[0]!=last)f=0;
		if(mp[s]==1)f=0;
		last=s[s.size()-1];
		mp[s]=1;
	}
	if(f)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
    return 0;
}

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

int main(void){
    string s;
    cin >> s;
    int a=s.size();
    for(int i=0;i<a;i+=2){
        cout << s[i];
    }
    cout <<endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
long long H, W, h, w, t, ans, a[501][501];
int main()
{
    cin >> H >> W >> h >> w;
    for (int i = 1; i <= H; ++i) {
        for (int j = 1; j <= W; ++j) {
            a[i][j] = 4000;
        }
    }
    t = - h * w * 4000 + 3999;
    for (int i = 0; i <= H; i += h) {
        for (int j = 0; j <= W; j += w) {
            a[i][j] = t;
        }
    }
    for (int i = 1; i <= H; ++i) {
        for (int j = 1; j <= W; ++j) {
            ans += a[i][j];
        }
    }
    if (ans < 0) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
        for (int i = 1; i <= H; ++i) {
            for (int j = 1; j <= W; ++j) {
                cout << a[i][j] << ' ';
            }
            cout << endl;
        }
    }
    return 0;
}


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

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
bool chmax(T &a, const T &b) {if (a < b){ a = b; return 1;} return 0;}
template <class T>
bool chmin(T &a, const T &b) {if (a > b){ a = b; return 1;}return 0;}
template <class T>
void printv(vector<T> v) {for (T t : v) {cout << t << " ";}cout << '\n';}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" <<endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    vvi a(N,vi(N-1));

    REP(i,N) {
        REP(j,N-1) {
            cin >> a[i][j];
            a[i][j]--;
        }
        reverse(ALL(a[i]));
    }

    vector<pii> q;

    auto check = [&](int i) { 
        if (a[i].size() == 0) return;
        int j = a[i].back();
        if (a[j].size() == 0) return;
        if (a[j].back() == i) {
            pii p(i,j);
            if (p.second < p.first) swap(p.first,p.second);
            q.emplace_back(p);
        }
    };

    REP(i,N) check(i);

    int day = 0;
    while (q.size() > 0)
    {
        day++;
  
        sort(ALL(q));
        q.erase(unique(ALL(q)),q.end());
        vector<pii> prevQ; 
        swap(prevQ,q);
        for (pii p : prevQ) {
            int i = p.first;
            int j = p.second;
            a[i].pop_back();
            a[j].pop_back();
        }
        for (pii p : prevQ) {
            int i = p.first;
            int j = p.second;
            check(i);
            check(j);
        }

    }
    REP(i,N) {
        if (a[i].size() != 0) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << day << endl;
    return 0;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
 
const ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// head
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
 
    ll n;
    cin >> n;
 
    int ans = 0;
    int ans2 = 0;
    while(n > 0) {
        int del = 9;
        if(n / 10 == 0) {
            del = n - 1;
        }
        ans2 += n % 10;
        ans += del;
        n /= 10;
    }
    cout << max(ans, ans2) << endl;
    return 0;
}

Measured memory_bytes: 3612
#include<stdio.h>

int gcd( int, int );

int main( void ){
	int x, y;
	
	scanf("%d %d", &x, &y);
	
	printf("%d\n", gcd(x,y));
	
	return 0;
}

int gcd( int a, int b ){
	
	int tmp, r;
	
	if( a < b ){
		tmp = a;
		a = b;
		b = tmp;
	}
	
	r = a % b;
	while( r != 0 ){
		a = b;
		b = r;
		r = a % b;
	}
	
	return b;
}


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

int main(void)
{
    string S;
    cin >> S;
    deque<char> dq;
    for (int i = 0; i < S.size(); i++)
    {
        dq.push_back(S.at(i));
    }

    int Q;
    cin >> Q;

    long long memo = 0;
    for (int i = 0; i < Q; i++)
    {
        int T;
        cin >> T;
        if (T == 1)
        {
            // swap(S.at(0), S.at(S.size() - 1));
            memo++;
        }
        else if (T == 2)
        {
            int F = 0;
            cin >> F;
            if (F == 1)
            {
                char C;
                cin >> C;
                if (memo % 2 == 0)
                {
                    dq.push_front(C);
                }
                else
                {
                    dq.push_back(C);
                    // S.insert(0, C);
                }
            }
            else if (F == 2)
            {
                char C;
                cin >> C;
                if (memo % 2 == 1)
                    dq.push_front(C);
                else
                    dq.push_back(C);
                // S.push_back(C.at(i));
            }
        }
    }

    if (memo % 2 != 0)
    {
        reverse(dq.begin(), dq.end());
    }
    for (int i = 0; i < dq.size(); i++)
    {
        cout << dq.at(i);
    }
    cout << endl;
    // cout << S << endl;
    return (0);
}

Measured memory_bytes: 896