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

using namespace std;

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

// #define MOD 1000000007
#define MOD 998244353
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  cin >> n;
  int d[n];
  REP(i, n) cin >> d[i];
  if (d[0] != 0) {
    cout << 0 << endl;
    return 0;
  }
  REP(i, n) {
    if (0 < i && d[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  map<int, int> mp;
  REP(i, n) mp[d[i]]++;
  ll ans = 1;
  for (int i = 1; i < n; ++i) {
    ans *= mp[d[i] - 1];
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	std::string s; cin >> s;
	
	int ans = 0;
	ans += (s[0] == '1');
	ans += (s[1] == '1');
	ans += (s[2] == '1');
	printf("%d\n", ans);
	return 0;
}


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

void solve(long long s, long long c) {
    ll res = 0;
    ll beforeConvert = (s*2 <= c) ? s : (c/2);
    res+=beforeConvert;
    s-=beforeConvert;
    c-=beforeConvert*2;
    res+=c/4;
    cout << res << endl;
}

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

  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  solve(N, M);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define SIZE 1000000

int main(){
  int n,min,num=0;
  char s[SIZE];
  int i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %c",&s[i]);
  }
  for(i=1;i<n;i++){
    if(s[i]=='E'){
      num++;
    }
  }
  min=num;
  for(i=0;i<n-1;i++){
    if(s[i]==s[i+1]){
      if(s[i]=='E') num--;
      else num++;
    }
    if(num<min) min=num;
  }
  printf("%d\n",min);
  
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 3000
#define SIZE 1000

enum Type{
	pre_no,
	pre_yes,
};

int num_item,num_event;
int price[NUM],add[NUM];
int TIME[SIZE],need_value[SIZE];
int max_value[SIZE+1][NUM+1][2];

int main(){

	scanf("%d %d",&num_item,&num_event);

	for(int i = 0; i < num_item; i++){

		scanf("%d %d",&price[i],&add[i]);
		if(i == 0)continue;
		price[i] += price[i-1];
	}

	for(int i = 0; i < num_event; i++){
		scanf("%d %d",&TIME[i],&need_value[i]);
	}

	for(int event = 0; event <= num_event; event++){
		for(int item = 0; item <= num_item; item++){
			max_value[event][item][pre_no] = -1;
			max_value[event][item][pre_yes] = -1;
		}
	}

	max_value[0][0][pre_no] = 0;

	int no_value,yes_value;

	for(int event = 0; event < num_event; event++){
		for(int item = 0; item <= num_item; item++){

			no_value = max_value[event][item][pre_no];
			yes_value = max_value[event][item][pre_yes];

			if(no_value != -1){

				if(item < num_item && price[item] <= TIME[event]){
					max_value[event][item+1][pre_yes] = max(max_value[event][item+1][pre_yes],no_value+add[item]);
				}

				if(no_value >= need_value[event]){
					max_value[event+1][item][pre_no] = max(max_value[event+1][item][pre_no],no_value);
				}
			}

			if(yes_value == -1)continue;

			if(item < num_item && price[item] <= TIME[event]){
				max_value[event][item+1][pre_yes] = max(max_value[event][item+1][pre_yes],yes_value+add[item]+abs(add[item]-add[item-1]));
			}
			if(yes_value >= need_value[event]){
				max_value[event+1][item][pre_no] = max(max_value[event+1][item][pre_no],yes_value);
			}
		}
	}

	int ans = -1;

	for(int item = 1; item <= num_item; item++){
		if(max_value[num_event][item][pre_no] >= 0){
			ans = TIME[num_event-1]-price[item-1];
			break;
		}
	}

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

	return 0;
}



Measured memory_bytes: 26736
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int main(){

	int N;
	scanf("%d",&N);

	int table[N];
	for(int i = 0; i < N; i++)scanf("%d",&table[i]);

	bool dp[N][N][10];

	for(int left = 0; left < N; left++){
		for(int right = 0; right < N; right++){
			for(int num = 0; num <= 9; num++)dp[left][right][num] = false;
		}
	}

	for(int i = 0; i < N; i++){
		dp[i][i][table[i]] = true;
	}

	for(int length = 2; length <= N; length++){
		for(int left = 0; left+length-1 <= N-1; left++){
			int right = left+length-1;
			for(int mid = left; mid <= right-1; mid++){
				for(int num = 0; num <= 9; num++){
					if((dp[left][mid][0] == true && dp[mid+1][right][0] == true)||(dp[left][mid][num] == true && dp[mid+1][right][num] == true)){
						dp[left][right][0] = true;
					}
					if(num == 0)continue;

					if((dp[left][mid][0] == true && dp[mid+1][right][num] == true) || (dp[left][mid][num] == true && dp[mid+1][right][0] == true) ||
							(dp[left][mid][num] == true && dp[mid+1][right][num] == true)){
						dp[left][right][num] = true;
					}
				}
			}
		}
	}


	if(dp[0][N-1][0]){
		printf("yes\n");
		return 0;
	}

	printf("no\n");

	return 0;

}

Measured memory_bytes: 3232
// ABC140A.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>

using namespace std;
int main()
{
	int N;
	cin >> N;

	int ans;

	ans = N * N * N;

	cout << ans << endl;
}


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
count = 0
a, b = MAP()
while 1:

    a = a // b
    count += 1
    if a == 0:
        print(count)
        exit()

Measured memory_bytes: 5700
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<lint> vlint;

#define inf 1e+9
#define endl "\n"
#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 all(x) (x).begin(), (x).end()

#define pb push_back
#define eb emplace_back
#define Size(c) (int)(c).size()

#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))

template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

template <class T, class S> inline bool chmax(T &a, S b) {
    if(a < b) {a = b;return 1;} return 0;
}
template <class T, class S> inline bool chmin(T &a, S b) {
    if(a > b) {a = b;return 1;} return 0;
}
template <class T>
void line(vector<T> &x){for (auto&& xi : x) cin >> xi;}

inline void IN(void){ return;}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){ cin >> first; IN(rest...); return;}

#define INT(...) int __VA_ARGS__; IN (__VA_ARGS__)
#define LINT(...) lint __VA_ARGS__; IN (__VA_ARGS__)
#define STR(...) string __VA_ARGS__; IN(__VA_ARGS__)

template <class T> void UNIQUE(vector<T> &x) {
    sort(all(x)); x.erase(unique(all(x)), x.end());
}
template <class T> void print_vec(T first, T end){
    for (auto i = first; i < end - 1; i++) cout << *i << " ";
    cout << *(end-1) << endl;
}
template <class T> void print(T a){ cout << a << endl;};
vector<string> Yes = {"No", "Yes"};
vector<string> YES = {"NO", "YES"};

lint popcount(lint n){
    int res = 0;
    for (int i = 0; i < 32; ++i){
        if (n & (1 << i)) res++;
    }
    return res;
};

vlint ans(300000, -1);

int main(){
    INT(n);
    ans[0] = 0;
    ans[1] = 1;
    rep1(i, n+1){
        ans[i+1] = ans[(i+1)%popcount(i+1)]+1;
    }
  	STR(x); lint pc = 0;
    rep(i, n){
        if (x[i] == '1') pc++;
    }
    lint m_a = pc-1; lint m_b = pc+1;
    if (m_a == 0) m_a = -2;
    vlint cnt_a(n+3, 1), cnt_b(n+3, 1);
  	cnt_a[0] = 1 % m_a; cnt_b[0] = 1 % m_b;
    rep1(i, n+1) {
        cnt_a[i] = cnt_a[i-1] * 2 % m_a;
        cnt_b[i] = cnt_b[i-1] * 2 % m_b;
    }
    lint x_a = 0; lint x_b = 0;
    rep(i, n){
        if (x[i] == '1'){
            x_a += cnt_a[n-1-i] % m_a;
            x_a %= m_a;
            x_b += cnt_b[n-1-i] % m_b;
            x_b %= m_b;
        }
    }
  	rep(i, n+1){
      cnt_a[i] = (x_a - cnt_a[i]) % m_a;
      cnt_b[i] = (x_b + cnt_b[i]) % m_b;
    }

  	lint k; lint ret;
    rep(i, n){
        k = n - 1 - i;
        if (x[i] == '1'){
            ret = cnt_a[k];
          	if (ret < 0) ret += m_a;
            
            if (m_a == -2){
                print(0); continue;
            };
        }
        else{
            ret = cnt_b[k];
          	if (ret > m_b) ret %= m_b;
        }
        print(ans[ret] + 1);
    }
  
}


Measured memory_bytes: 9096
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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 (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll n;
vector<ll> a, b;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    a.resize(n);
    b.resize(n);
    rep(i, n) cin >> a[i] >> b[i];
    sort(ALL(a));
    sort(ALL(b),greater<ll>());
    if(n%2){
        ll ans=b[n/2]-a[n/2];
        cout<<ans+1<<"\n";
    }
    else{
        ll aa=a[n/2]+a[n/2-1];
        ll bb=b[n/2-1]+b[n/2];
        cout<<bb-aa+1<<"\n";
    }
}


Measured memory_bytes: 6332
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>
//#include <bits/stdc++.h>

template<typename T> bool chmax(T &a,T b){
    if(a<b){
        a=b;
        return true;
    }
    return false;
}

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

using namespace std;
#define ALL(X) X.begin(),X.end()
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=2147483647;
const ll LLMAX=9223372036854775807;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N;cin>>N;
    vll a(N);
    for(ll i=0;i<N;i++)cin>>a[i];
    vll sum(N);
    sum[0]=a[0];
    for(ll i=1;i<N;i++){
        sum[i]=sum[i-1]+a[i];
    }
    ll ans=LLMAX;
    for(ll i=0;i<N-1;i++){
        ll A=sum[i];
        ll B=sum[N-1]-sum[i];
        chmin(ans,abs(A-B));
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 3456
package main

import (
	"fmt"
	"sort"
)

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func main() {
	var N int
	fmt.Scan(&N)
	A := make([]int, N)
	B := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&A[i])
		B[i] = A[i] - (i + 1)
	}
	sort.Ints(B)
	b := B[len(B)/2]
	ans := 0
	for i := 0; i < N; i++ {
		ans += abs(B[i] - b)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 7808
#![allow(dead_code)]
#![allow(unused_imports)]
use ascii::{AsciiChar, AsciiStr, AsciiString};
use indexmap::IndexMap;
use itertools::*;
use libm::*;
use num::*;
use ordered_float::OrderedFloat;
use permutohedron::LexicalPermutation;
use proconio::marker::{Bytes, Chars};
use proconio::{fastout, input};
use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::mem::swap;

fn main() {
    input!(a:isize, b:isize);
    println!("{}", if a <= b * 2 {0} else {a - b * 2});
}


Measured memory_bytes: 2180
# ABC067C - Splitting Pile
def main():
    n = int(input())
    lst = list(map(int, input().rstrip().split()))
    l, r, ans = 0, sum(lst), float("inf")
    for i in lst[:-1]:
        l += i
        r -= i
        ans = min(ans, abs(l - r))
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 23800
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define gc getchar
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define x1 uvuvwevwevwe
#define y1 onyetenyevwe
#define x2 ugwemubwem
#define y2 ossas
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
template <typename T> void scan(T &angka){
	angka=0;char input=gc();T kali=1;
	while(!(48<=input&&input<=57)){	if(input=='-')	kali=-1;input=gc();}
	while(48<=input&&input<=57)	angka=(angka<<3)+(angka<<1)+input-48,input=gc();angka*=kali;
}
template <typename T1,typename T2> void scan(T1 &angka1,T2 &angka2){
	scan(angka1);scan(angka2);
}
const int MAXN=2000;
int n,awal[2],dp[2][MAXN+5][MAXN+5],arr[MAXN+5];
vector <int> press;
int topdown(int id,int lawan,int pos){
	int &ret=dp[id][lawan][pos];
	if(ret!=-1)
		return ret;
	ret=abs(press[lawan]-press[arr[n]]);
	for(int i=pos;i<=n-1;i++)
	{
		if(id==0)
			ret=max(ret,topdown(id^1,arr[i],i+1));
		else
			ret=min(ret,topdown(id^1,arr[i],i+1));
	}
	return ret;
}
int idx(int angka){
	return lower_bound(all(press),angka)-press.begin();
}
int main()
{
	memset(dp,-1,sizeof(dp));
	scan(n);
	for(int ulang=0;ulang<2;ulang++)
	{
		scan(awal[ulang]);
		press.pb(awal[ulang]);
	}
	for(int i=1;i<=n;i++)
	{
		scan(arr[i]);
		press.pb(arr[i]);
	}
	sort(all(press));
	press.resize(unique(all(press))-press.begin());
	for(int i=1;i<=n;i++)
		arr[i]=idx(arr[i]);
	cout<<topdown(0,idx(awal[1]),1)<<endl;
}

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

int main() {
  char b;
  cin >> b;
  if (b == 'A') {
    cout << "T" << endl;
  }
  else if (b == 'T') {
    cout << "A" << endl;
  }
  else if (b == 'G') {
    cout << "C" << endl;
  }
  else cout << "G" << endl;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())

cnt = 0
for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            if i * 500 + j * 100 + k * 50 == x:
                cnt = cnt + 1

print(cnt)


Measured memory_bytes: 39536
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,sum=0;
  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: 3576
#include<iostream>
#include<vector>

using namespace std;

#define rep(i,n) for(int i=0;i<n;++i)

int main(){
  int N, M;
  cin >> N >> M;
  vector<pair<int,int>> LR(M);
  rep(i,M) cin >> LR[i].first >> LR[i].second;
  int Lm = 0, Rm = N+1;
  rep(i,M){
    Lm = max(LR[i].first, Lm);
    Rm = min(LR[i].second, Rm);
  }
  cout << max(0, Rm-Lm+1) << endl;    
}

Measured memory_bytes: 1024
import java.util.*;
import java.awt.Frame;
import java.io.*;

public class Main {
	// static ArrayList<Integer>[] g;

	static pair[] a;
	static int[][] memo;


	public static void main(String[] args) throws NumberFormatException, IOException, InterruptedException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		
		sieve(1000002);
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		int[] a = new int[n];
		int gcd = -1;
		st = new StringTokenizer(br.readLine());
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(st.nextToken());
			if (i == 0)
				gcd = a[i];
			else
				gcd = (int) gcd(gcd, a[i]);
		}
		if (gcd != 1) {
			pw.println("not coprime");
		} else {
			boolean f = true;
			HashSet<Integer> hs = new HashSet<>();
			for (int i = 0; i < a.length; i++) {
				HashSet<Integer> arr = primeFactors(a[i]);
				for (int x : arr) {
					if (hs.contains(x))
						f = false;
					hs.add(x);
				}
			}
			if(f) {
				pw.println("pairwise coprime");
			}
			else
				pw.println("setwise coprime");

		}
		pw.flush();
		pw.close();

	}

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

	static ArrayList<Integer> primes;
	static int[] isComposite;

	static void sieve(int N) // O(N log log N)
	{
		isComposite = new int[N + 1];
		isComposite[0] = isComposite[1] = 1; // 0 indicates a prime number
		primes = new ArrayList<Integer>();

		for (int i = 2; i <= N; ++i) // can loop till i*i <= N if primes array is not needed O(N log log sqrt(N))
			if (isComposite[i] == 0) // can loop in 2 and odd integers for slightly better performance
			{
				primes.add(i);
				if (1l * i * i <= N)
					for (int j = i * i; j <= N; j += i) // j = i * 2 will not affect performance too much, may alter in
														// modified sieve
						isComposite[j] = 1;
			}
	}

	static HashSet<Integer> primeFactors(int N)		// O(sqrt(N) / ln sqrt(N))
	{
		HashSet<Integer> factors = new HashSet();		//take abs(N) in case of -ve integers
		int idx = 0, p = primes.get(idx);

		while(p * p <= N)
		{
			while(N % p == 0) { factors.add(p); N /= p; }
			p = primes.get(++idx);
		}

		if(N != 1)						// last prime factor may be > sqrt(N)
			factors.add(N);				// for integers whose largest prime factor has a power of 1
		return factors;
	}

	static long pow(long a, long e, int mod) // O(log e)
	{
		long res = 1;
		while (e > 0) {
			if ((e & 1) == 1) {
				res *= a;
				res %= mod;
			}
			a *= a;
			a %= mod;
			e >>= 1;
		}
		return res;
	}

	static class pair implements Comparable<pair> {
		int x;
		int y;

		public pair(int d, int u) {
			x = d;
			y = u;
		}

		@Override
		public int compareTo(pair o) {
			// TODO Auto-generated method stub
			int x1 = y - x;
			int x2 = o.y - o.x;
			return x1 - x2;
		}

	}

}

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

typedef long long lint;
typedef long double ldouble;
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = 1e18;
const lint MOD = 1e9 + 7;
const lint inv = MOD - 2;

struct edge{
    int to, cost;
};

int n;
vector< vector<edge> > g;
vector<bool> done;

void init(void){
    g.resize(n);
    done.resize(n);
    rep(i, n){
        g[i].resize(0);
        done[i] = false;
    }
    return;
}

void input(void){
    rep(i, n-1){
        int a, b, t;
        cin >> a >> b >> t;
        a--;
        b--;
        g[a].push_back(edge{b, t});
        g[b].push_back(edge{a, t});
    }
    return;
}

void giveRoot(int t){
    done[t] = true;
    int i = 0;
    while(i < g[t].size()){
        if(done[g[t][i].to]){
            g[t].erase(g[t].begin() + i);
            continue;
        }else{
            giveRoot(g[t][i].to);
            i++;
        }
    }
    return;
}

int twice(edge e){
    int t = e.to;
    int res = e.cost * 2;
    rep(i, g[t].size()){
        if(g[g[t][i].to].size() != 0){
            res += twice(g[t][i]);
        }
    }
    return res;
}

int solve(int t){
    int res = IINF, tmp = 0;
    rep(i, g[t].size()){
        if(g[g[t][i].to].size() == 0){
            continue;
        }
        tmp = 0;
        rep(j, g[t].size()){
            if(g[g[t][j].to].size() == 0){
                continue;
            }
            if(i == j){
                tmp += g[t][j].cost + solve(g[t][j].to);
            }else{
                tmp += twice(g[t][j]);
            }
        }
        res = min(res, tmp);
    }
    res = min(res, tmp);
    return res;
}

int main(){
    while(cin >> n && n){
        init();
        input();
        giveRoot(0);
        int ans = solve(0);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 2924
#include <stdio.h>
#include <string.h>

int main(){
  char s[5000];
  int K, i, j, k=0;
  char sort[26];
  int count=0;
  char hicaku[6];

  scanf("%s", s);
  scanf("%d", &K);

  int slen = strlen(s);

  for(i=0;i<26;i++){
    for(j=0;j<slen;j++){
      if(s[j] == 'a' + i){
        sort[k] = 'a' + i;
        k++;
        j = slen;
      }
    }
  }
  sort[k] = '\0';

  int l, m;
  int len = strlen(sort);

  for(i=0;i<len;i++){
    hicaku[0] = sort[i];
    hicaku[1] = '\0';
    hicaku[2] = '\0';
    hicaku[3] = '\0';
    hicaku[4] = '\0';
    if(strstr(s,hicaku) != NULL) count++;
    if(count == K){
      printf("%s\n", hicaku);
      return 0;
    }
    if(slen > 1){
      for(j=0;j<len;j++){
        hicaku[1] = sort[j];
        hicaku[2] = '\0';
        hicaku[3] = '\0';
        hicaku[4] = '\0';
        if(strstr(s,hicaku) != NULL) count++;
        if(count == K){
          printf("%s\n", hicaku);
          return 0;
        }
        if(slen > 2){
          for(k=0;k<len;k++){
            hicaku[2] = sort[k];
            hicaku[3] = '\0';
            hicaku[4] = '\0';
            if(strstr(s,hicaku) != NULL) count++;
            if(count == K){
              printf("%s\n", hicaku);
              return 0;
            }
            if(slen > 3){
              for(l=0;l<len;l++){
                hicaku[3] = sort[l];
                hicaku[4] = '\0';
                if(strstr(s,hicaku) != NULL) count++;
                if(count == K){
                  printf("%s\n", hicaku);
                  return 0;
                }
                if(slen > 4){
                  for(m=0;m<len;m++){
                    hicaku[4] = sort[m];
                    hicaku[5] = '\0';
                    if(strstr(s,hicaku) != NULL) count++;
                    if(count == K){
                      printf("%s\n", hicaku);
                      return 0;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

Measured memory_bytes: 128
kMod = 1000000007

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

if (X+Y) % 3 != 0:
    print(0)
    exit()

offset = (X+Y)//3
X, Y = X-offset, Y-offset
if X < 0 or Y < 0:
    print(0)
    exit()

X, Y = max(X, Y), min(X, Y)

ans = 1
for i in range(X+1, X+Y+1):
    ans *= i
    ans %= kMod

for i in range(2, Y+1):
    ans *= pow(i, kMod-2, kMod)
    ans %= kMod

print(ans)

Measured memory_bytes: 9148
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;

int main() {
    // dp
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    vector<int> dp;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        auto it = upper_bound(dp.begin(), dp.end(), -A[i]);
        if (it == dp.end()) {
            ans++; dp.push_back(-A[i]);
        } else {
            *it = -A[i];
        }        
    }
    cout << sz(dp) << '\n';
    return 0;
}

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

int main () {
    int N;
    cin >> N;
    int four[50];
    int seven[50];

    fill(four, four+50, 0);
    fill(seven, seven+50, 0);
    for(int i = 0;i < 50;i++){
        four[i] = (i+1)*4;
    }
    for(int i = 0;i < 50;i++){
        seven[i] = (i+1)*7;
    }

    if(N%4 == 0 || N%7 == 0) {
        cout << "Yes" << endl;
        return 0;
    }

    for(int i = 0;i < 50;i++){
        for(int j = 0;j < 50;j++){
            if(four[i]+seven[j] == N){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

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

typedef long long ll;
typedef int keytype;

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

void quicksort(keytype a[], int first, int last)
{
    int i, j;
    keytype x, t;

    x = a[(first + last) / 2];
    i = first;  j = last;
    for ( ; ; ) {
        while (a[i] < x) i++;
        while (x < a[j]) j--;
        if (i >= j) break;
        t = a[i];  a[i] = a[j];  a[j] = t;
        i++;  j--;
    }
    if (first  < i - 1) quicksort(a, first , i - 1);
    if (j + 1 < last) quicksort(a, j + 1, last);
}

int is_prime(int x){
    if(x <= 1) return 0;
    for(int i = 2; i * i <= x; i++){
        if(x % i == 0) return 0;
    }
    return 1;
}

int is_substr(char s[], char t[], int i){
    int flag = 1;

    if(s[i] == '\0') flag = 0;

    for(int j = 0; j < strlen(t); ++j, ++i){
        if(s[i] != t[j]){
            flag = 0;
            break;
        }
    }
    return flag;
}

// factor list, number of factors, natural number
void factorize(int ftr[], int *num, int n){
    int a = 2, cnt = 0;

    while(n >= a){
        if(n % a == 0){
            n = n / a;
            ftr[cnt++] = a;
        }else{
            a++;
        }
    }
    *num = cnt;
}

void comb(int size1, int size2, int v[size1][size2]){
  for(int i = 0; i < size1; i++){
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for(int k = 1; k < size1; k++){
    for(int j = 1; j < k; j++){
      v[k][j] = (v[k-1][j-1] + v[k-1][j]);
    }
  }
}

int abs_val(int a, int b){
    if(a > b) return a - b;
    else return b - a;
}

int main(){
    int x, a, b;

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

    int dis_a = abs_val(x, a);
    int dis_b = abs_val(x, b);

    if(dis_a < dis_b) puts("A");
    else puts("B");

    return 0;
}


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

using namespace std;

int main() {
	string s, t;
	cin >> s >> t;
	int n = s.length();

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

	cout << "Yes";
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
};

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i,n) cin >> v[i];
  mint ans=1;
  int r=0,b=0,g=0;
  rep(i,n){
    int col=0;
    int x=v[i];
    if(r==x) col++;
    if(b==x) col++;
    if(g==x) col++;
    ans*=col;
    if(col==0) break;
    if(r==x){
      r++;
      continue;
    }
    if(g==x){
      g++;
      continue;
    }
    if(b==x){
      b++;
      continue;
    }
  }
  cout << ans.x << endl;
    
    
}

Measured memory_bytes: 3784
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
int main()
{
    int H, W;
    cin >> H >> W;
    char a[H][W];
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cin >> a[i][j];
        }
    }
    queue<pair<int,int> > que;
    int dist[H][W];
    int max = -1;
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (a[i][j] == '.')
            {
                for(int s = 0;s < H;s++){
                    for(int l = 0;l < W;l++){
                        dist[s][l] = -1;
                    }
                }
                dist[i][j] = 0;
                que.push(make_pair(i, j));
                while (!que.empty())
                {
                    pair<int, int> p = que.front();
                    que.pop();
                    for (int s = 0;s < 4;s++)
                    {
                        int _dx = p.first + dx[s];
                        int _dy = p.second + dy[s];
                        if (0 <= _dx && _dx < H && 0 <= _dy && _dy < W)
                        {
                            if (a[_dx][_dy] == '.' && dist[_dx][_dy] == -1)
                            {
                                dist[_dx][_dy] = dist[p.first][p.second] + 1;
                                que.push(make_pair(_dx, _dy));
                            }
                        }
                    }
                }
                for (int k = 0; k < H; k++)
                {
                    for (int l = 0; l < W; l++)
                    {
                        max = std::max(max,dist[k][l]);
                    }
                }
            }
        }
    }
    cout << max << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#define dis(p,q) ((p)*(p)+(q)*(q))
using namespace std;
void cc(double px,double py,double pr,double qx,double qy,double qr,double& rx,double& ry,double& sx,double& sy){
  double a=atan2(qy-py,qx-px);
  double b=acos((dis(px-qx,py-qy)+pr*pr-qr*qr)/2/pr/sqrt(dis(px-qx,py-qy)));
  rx=px+cos(a+b)*pr;
  ry=py+sin(a+b)*pr;
  sx=px+cos(a-b)*pr;
  sy=py+sin(a-b)*pr;
  return;
}
int main(){
  int i,j,k;
  int n;
  while(cin>>n&&n){
    double x[100],y[100];
    for(i=0;i<n;i++)
      scanf("%lf,%lf",&x[i],&y[i]);
    int mx=1;
    for(i=0;i<n-1;i++){
      for(j=i+1;j<n;j++){
	if(dis(x[i]-x[j],y[i]-y[j])<=4){
	  double px,py,qx,qy;
	  cc(x[i],y[i],1,x[j],y[j],1,px,py,qx,qy);
	  int ct=2,cu=2;
	  for(k=0;k<n;k++){
	    if(i!=k&&j!=k){
	      if(dis(x[k]-px,y[k]-py)<=1)
		ct++;
	      if(dis(x[k]-qx,y[k]-qy)<=1)
		cu++;
	    }
	  }
	  mx=max(mx,max(ct,cu));
	}
      }
    }
    cout<<mx<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int a[10];
int main(){
	scanf("%d%d%d",&a[1],&a[2],&a[3]);
	sort(a+1,a+4);
	if ((a[2]-a[1])&1) printf("%d",((a[3]+1)*3-a[1]-a[2]-a[3])/2);
	else printf("%d",((a[3])*3-a[1]-a[2]-a[3])/2);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <list>
#include <map>
#include <set>
using namespace std;

int len,maxv,t,f[5005][5005];
char s[5005];

int main(void) {
	scanf("%d %s",&len,s);
	maxv = 1;
	for(int i = 0;i < len;i ++) {
		for(int j = i + maxv;j < len;j ++) {
			f[i][j] = 1;
		}
	}
	for(int i = len - 2;i >= 0;i --) {
		for(int j = len - 1;j >= i + maxv;j --) {
			if(s[i] == s[j] && f[i][j] < j - i && j + f[i][j] < len) {
				t = f[i][j];
				if(i + t >= j) t = j - i - 1;
				if(s[i + t] == s[j + t]) {
					f[i][j] += f[i + t][j + t];
					if(f[i][j] > j - i) f[i][j] = j - i;
					maxv = max(maxv,f[i][j]);
				}
			}
		}
	}
	cout << (maxv == 1 ? 0 : maxv) << endl;
	return 0;
}


Measured memory_bytes: 96768
input = gets().split(" ")
W, H, x, y, r = input[0].to_i, input[1].to_i, input[2].to_i, input[3].to_i.to_i, input[4].to_i

if x + r <= W && x - r >= 0 && y + r <= H && y - r >= 0
	puts "Yes"
else
	puts "No"
end

Measured memory_bytes: 6100
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define fi first
#define se second
signed main(){
  int x;
  cin>>x;
  if(x%500==0) cout<<x/500*1000<<"\n";
  else cout<<x/500*1000+(x%500)/5*5<<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ELEM(array)  (sizeof (array) / sizeof *(array))
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

int main(){
    int a,b;
    cin>>a>>b;
    int k=a,ans=1;
    if(b==1)cout<<0;
  else if(a>=b) cout<<1;
  
   else{
     while(true){
       k+=(a-1);
       ans++;
       if(k>=b){
         
         cout<<ans;
         return 0;
       }
     }
   }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#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 all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    long long H, attack = 0, monster = 1; cin >> H;
    while (true) {
        if (H == 1) {
            cout << (2 * monster) - 1 << endl;
            return 0;
        }
        else if (H > 1) {
            ++attack;
            monster *= 2;
            H = floor(H/2);
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */

int main() {
  string s; cin >> s;
  string ans;
  FOREACH(x,s){
    if(x=='B'){
      ll n = ans.size();
      if(n>0) ans = ans.substr(0,n-1); 
    }
    else ans = ans + x;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1ll << 60;

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

int n;
int a[3010];
ll dp[3010][3010];
int vis[3010][3010];

ll rec(int l, int r) {
    if(l > r) return 0;
    if(vis[l][r]) return dp[l][r];

    vis[l][r] = 1;
    ll rsl = 0;

    if((n - r + l) % 2 == 1) { // 先攻
        rsl = -INF;
        chmax(rsl, rec(l + 1, r) + a[l]);
        chmax(rsl, rec(l, r - 1) + a[r]);
    } else {
        rsl = INF;
        chmin(rsl, rec(l + 1, r) - a[l]);
        chmin(rsl, rec(l, r - 1) - a[r]);
    }
    return dp[l][r] = rsl;
}


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

    cin >> n;
    rep(i, 0, n) cin >> a[i];
    cout << rec(0, n - 1) << endl;

}


Measured memory_bytes: 105216
import math
n = int(input())
cnt = 0
for _ in range(n):
    x = int(input())
    if x == 2: cnt += 1
    if x < 2 or x%2 == 0: continue
    i = 3
    while i <= math.sqrt(x):
        if x%i == 0: break
        i += 2
    if not i <= math.sqrt(x): cnt += 1
print(cnt)



Measured memory_bytes: 5668
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

	int n;
	set<string> mys;
	cin >> n;
	for(int i = 0; i < n; i++) {
		string str;
		cin >> str;
		mys.insert(str);
	}
	cout << mys.size() << '\n';
}



Measured memory_bytes: 19212
using System;
//using System.Collections.Generic;

namespace Project
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			string[] s = Console.ReadLine().Split(' ');
			int[] a = new int[3];
			for (int i = 0; i < 3; i++)
			{
				a[i] = int.Parse(s[i]);
			}
			Array.Sort(a);
			if(a[0] + a[1] == a[2])
				Console.WriteLine("Yes");
			else
				Console.WriteLine("No");
		}
	}
}


Measured memory_bytes: 2904
from heapq import heappop, heappush
manhattan = tuple(tuple(abs((i % 4) - (j % 4)) + abs((i // 4) - (j // 4)) for j in range(16)) for i in range(16))
movables = ((1, 4), (0, 2, 5), (1, 3, 6), (2, 7), (0, 5, 8), (1, 4, 6, 9), (2, 5, 7, 10), (3, 6, 11),
            (4, 9, 12), (5, 8, 10, 13), (6, 9, 11, 14), (7, 10, 15), (8, 13), (9, 12, 14), (10, 13, 15), (11, 14))
swap_mul = tuple(tuple((1 << mf) - (1 << mt) for mt in range(0, 64, 4)) for mf in range(0, 64, 4))
destination = 0xfedcba9876543210
i = 0
board_init = 0
blank_init = 0
for _ in range(4):
    for n in map(int, input().split()):
        if n:
            n -= 1
        else:
            n = 15
            blank_init = i
        board_init += n * 16 ** i
        i += 1
estimation_init = sum(manhattan[i][((board_init >> (4 * i)) & 15)] for i in range(16) if i != blank_init)
queue = [(estimation_init, board_init, blank_init)]
visited = set()
while True:
    estimation, board, blank = heappop(queue)
    if board in visited:
        continue
    elif board == destination:
        print(estimation)
        break
    visited.add(board)
    for new_blank in movables[blank]:
        num = (board >> (4 * new_blank)) & 15
        new_board = board + swap_mul[new_blank][blank] * (15 - num)
        if new_board in visited:
            continue
        new_estimation = estimation + 1 - manhattan[new_blank][num] + manhattan[blank][num]
        if new_estimation > 45:
            continue
        heappush(queue, (new_estimation, new_board, new_blank))


Measured memory_bytes: 161616
#include <iostream>
#include<vector>
#include <math.h>

using namespace std;
int main(void) {
  int x;
  int max = 0, b = 1;
  int p, power;
  scanf("%d", &x);
  for (b=1;b<=1000;b++) {
    if (pow(b, 2) > x) {
      break;
    }
    for (p=2;p<=1000;p++) {
      power = pow(b, p);
      if (power <= x) {
        if (power > max) {
          max = power;
        }
      } else {
        break;
      }
    }
  }
  cout << max << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    int ti = clock();
    int D; cin >> D;
    vector<ll> c(26);
    rep(i, 26) cin >> c[i];
    vector<vector<ll>> s(D, vector<ll>(26));
    rep(i, D)rep(j, 26) cin >> s[i][j];
    vector<ll> t(D);
    rep(i, D) t[i] = 26-i%26;
    ll ans = 0;
    vector<ll> last(26);
    vector<ll> t_ans(ALL(t));
    for (int d = 1; d <= D; d++) {
        for (int i = 1; i <= 26; i++) {
            if (t[d-1] == i) {
                ans += s[d-1][i-1];
                last[i-1] = d;
            }
            else {
                ans -= c[i-1]*(d-last[i-1]);
            }
        }
    }
    ll tmp;
    while ((double)(clock() - ti)/CLOCKS_PER_SEC <= 1.5) {
        t[rand()%365] = rand()%26 + 1;
        last.clear();
        last.resize(26);
        tmp = 0;
        for (int d = 1; d <= D; d++) {
            for (int i = 1; i <= 26; i++) {
                if (t[d-1] == i) {
                    tmp += s[d-1][i-1];
                    last[i-1] = d;
                }
                else {
                    tmp -= c[i-1]*(d-last[i-1]);
                }
            }
        }
        if (tmp > ans) {
            tmp = ans;
            swap(t_ans, t);
            t.clear();
            t.resize(D);
            rep(i, D) t[i] = t_ans[i];
        }
    }
    rep(i, D) cout << t_ans[i] << endl;
}

Measured memory_bytes: 3760
n=int(input())
d={"AC":0,"WA":0,"TLE":0,"RE":0}
for i in range(n):
  a=input()
  d[a]=d[a]+1
print("AC","x",d["AC"])
print("WA","x",d["WA"])
print("TLE","x",d["TLE"])
print("RE","x",d["RE"])

Measured memory_bytes: 9140
#include <iostream>

int main()
{
    // given : A, B, N
    // 求めるもの: floor(Ax/B) - A*floor(x/B) のx <= Nについての最大値

    // floor(a/b) = (a - (a mod b))/b
    // floor(Ax/B) - A*floor(x/B)
    // = (Ax - (Ax mod B))/B - A*(x - (x mod B))/B
    // = (Ax - (Ax mod B) - Ax + A(x mod B))/B
    // = (- (Ax mod B) + A(x mod B))/B
    // = (A(x mod B) - (Ax mod B))/B >= 0
    // ここで x = CB + D (0 <= D <= B-1) とすると
    // = (A (CB+D mod B) - (A(CB+D) mod B))/B
    // = (A(D mod B) - (ACB+AD mod B))/B
    // = (A(D mod B) - (AD mod B))/B
    // C = 0 としてすると、0 <= x <= B-1
    // = (Ax - (Ax mod B))/B を最大にするようなx
    // <=> Ax - (Ax mod B) を最大にするようなx

    // x <= N かつ 0 <= x <= B-1
    long A, B, N;
    std::cin >> A >> B >> N;
    long x = std::min(N, B - 1);
    std::cout << (A * x - ((A * x) % B)) / B << std::endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N;
//	bool F = false;
	while (1) {
		cin >> N;
		if (N == 0)break;
		string S;
		cin >> S;

		int ba = 0;
		int j = 0;
		VI ans(N,0);
		REP(i, S.size()) {
			if (S[i] == 'M') {
				ans[j]++;
			}
			else if (S[i] == 'S') {
				ba += ans[j] + 1;
				ans[j] = 0;
			}
			else {
				ans[j] += ba + 1;
				ba = 0;
			}
			j++;
			if (j == N)j = 0;
		}
		SORT(ans);
		REP(i, ans.size())cout << ans[i] << " ";
		cout << ba << endl;

	}
	return 0;
}




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

int main(void){
    long long int i, j, k, n, a, b, v, w, t, ans=0, po=0;
    scanf("%lld %lld %lld %lld %lld", &a, &v, &b, &w, &t);
    if(abs(a-b)<=(v-w)*t) printf("YES");
    else printf("NO");
    
}

Measured memory_bytes: 1720
from collections import deque
n = int(input())
a = list(map(int, input().split()))
b = deque([])
for i in range(n):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.appendleft(a[i])
if n % 2 == 0:
    print(*list(b))
else:
    print(*list(b)[::-1])

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

int main(){
  int N;
  cin >> N;
  int ans=0;
  vector<int> A(N);
  vector< vector< pair<int,int> > > xy(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
    xy.at(i).resize(A.at(i));
    for(int j=0;j<A.at(i);j++){
      cin >> xy.at(i).at(j).first >> xy.at(i).at(j).second;
    }
  }

  for(int i=0;i<(1<<N);i++){
    bitset<15> bit(i);
    bool flag=true;
    vector<int> judge(N,0);
    for(int j=0;j<N;j++){
      if(bit.test(j)){
        if(judge.at(j)==0){
          judge.at(j)=1;
        }else if(judge.at(j)==-1){
          flag=false;
          break;
        }
        for(int k=0;k<A.at(j);k++){
          auto p=xy.at(j).at(k);
          if(p.second==1){
            if(judge.at(p.first-1)==0){
              judge.at(p.first-1)=1;
            }else if(judge.at(p.first-1)==-1){
              flag=false;
              break;
            }
          }else{
            if(judge.at(p.first-1)==0){
              judge.at(p.first-1)=-1;
            }else if(judge.at(p.first-1)==1){
              flag=false;
              break;
            }
          }
        }
        if(!flag){
          break;
        }
      }else{
        if(judge.at(j)==0){
          judge.at(j)=-1;
        }else if(judge.at(j)==1){
          flag=false;
          break;
        }
      }
    }
    if(flag){
      ans=max(ans,static_cast<int>(bit.count()));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    int N;
    cin >> N;
    vector<long long> A(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
        A[i] -= i+1;
    }

    long long a,b;
    a = -MOD; b = MOD;
    long long c1,c2;



    for ( int i = 0; i < 100; i++ ) {

        c1 = a + (b-a)/3;
        c2 = a + (b-a)*2/3;

        long long x,y;
        x = y = 0;
        for ( int j = 0; j < N; j++ ) {
            x += abs(c1-A[j]);
        }
        for ( int j = 0; j < N; j++ ) {
            y += abs(c2-A[j]);
        }
        if ( x > y ) {
            a = c1;            
        }
        else {
            b = c2;
        }
    }
    // cout << a << " " << b << endl;

    long long ans = LLONG_MAX;
    for ( long long x = a; x <= b; x++ ) {
        long long t = 0;
        for ( int j = 0; j < N; j++ ) {
            t += abs(x-A[j]);
        }
        ans = min( ans, t );
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
'''A - Red or Not
https://atcoder.jp/contests/abc138/tasks/abc138_a

>>> main(3200, 'pink')
pink
>>> main(3199, 'pink')
red
>>> main(4049, 'red')
red
'''


def main(a, s):
    if a >= 3200:
        print(s)
    else:
        print('red')


if __name__ == '__main__':
    a, s = int(input()), input()
    main(a, s)


Measured memory_bytes: 2940
list=input().split(" ")
n=int(list[0])
k=int(list[1])

list=input().split(" ")
for l in range(len(list)):
    list[l]=int(list[l])

#print(list)
maxpoint=0

for i in range(k+1):
    for j in range(i+1):
        if i>len(list):
            juery=list
        elif j==0:
            if j-i==0:
                juery=[]
            else:
                juery=list[j-i:]
        else:
            if j-i==0:
                juery=list[:j]
            else:
                juery=list[:j]+list[j-i:]
        juery=sorted(juery)
        #print(juery, sum(juery), k-len(juery))
        point=0
        magic=min(k-len(juery), len(juery))
        for x in range(magic):
            if juery[x]<0:
                point-=juery[x]
        point+=sum(juery)
        #print(juery, point)
        if point>maxpoint:
            maxpoint=point

print(maxpoint)

Measured memory_bytes: 3064