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

lint dp[1000][2001];

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

    vector<tuple<lint, lint, lint>> edge; // (from, to, cost)
    for(lint i=0; i<m; i++) {
        lint a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        edge.emplace_back(a, b, -c);
    }

    fill(dp[0], dp[1000], 1e18);
    dp[0][0] = 0;
    for(lint len=1; len<=2000; len++)
    for(auto& e : edge) {
        lint from, to, cost;
        tie(from, to, cost) = e;
        dp[to][len] = min(dp[to][len], dp[from][len-1] + cost);
    }

    auto it = min_element(begin(dp[n-1]), end(dp[n-1]));
    if(it - dp[n-1] > n-1)  cout << "inf" << endl;
    else  cout << -(*it) << endl;
}

Measured memory_bytes: 16000
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  int ans = 0;
  sort(all(a));
  map<vi, int> cnt;
  rep(i, n - 2){
    for(int j = i + 1; j < n - 1; j++){
      for(int k = j + 1; k < n; k++){
        if(a[i] != a[j] && a[j] != a[k] && a[k] != a[i] && a[k] < a[i] + a[j]) ans++;
      }
    }
  }
  cout << ans << endl;
}

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

int main() {
    string s;
    cin >> s;
    int a = s[0] - '0', b = s[1] - '0', c = s[2] - '0', d = s[3] - '0';
    if (a - b - c - d == 7) printf("%d-%d-%d-%d=7\n", a, b, c, d);
    else if (a - b - c + d == 7) printf("%d-%d-%d+%d=7\n", a, b, c, d);
    else if (a - b + c - d == 7) printf("%d-%d+%d-%d=7\n", a, b, c, d);
    else if (a - b + c + d == 7) printf("%d-%d+%d+%d=7\n", a, b, c, d);
    else if (a + b - c - d == 7) printf("%d+%d-%d-%d=7\n", a, b, c, d);
    else if (a + b - c + d == 7) printf("%d+%d-%d+%d=7\n", a, b, c, d);
    else if (a + b + c - d == 7) printf("%d+%d+%d-%d=7\n", a, b, c, d);
    else if (a + b + c + d == 7) printf("%d+%d+%d+%d=7\n", a, b, c, d);
    
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
def main():
	N = int(input())
	A = list(map(int, input().split()))

	if all(map(lambda a: a==0, A)):
		print("Yes")
		return

	ans_dict = defaultdict(int)
	for a in A:
		ans_dict[a] += 1
	if len(ans_dict) == 3:
		xor = 0
		num = [0, 0, 0]
		i = 0
		for k in ans_dict:
			num[i] = ans_dict[k]
			xor ^= k
			i += 1
		if num[0] == num[1] and num[1] == num[2] and xor == 0:
			print("Yes")
			return
	if len(ans_dict) == 2 and 0 in ans_dict:
		num = [ans_dict[0], 0]
		for k in ans_dict:
			if k == 0:
				continue
			num[1] = ans_dict[k]
		if num[0]*2 == num[1]:
			print("Yes")
			return
	print("No")


if __name__ == '__main__':
	main()

Measured memory_bytes: 14468
#151c
n,w=map(int,input().split())
ac=0
wa=[0]*n
wa_cnt=[0]*n
ac_flg=[0]*n
for i in range(w):
	p,s=input().split()
	p=int(p)-1
	if ac_flg[p]==1:
		continue
	else:
		if s=='AC':
			ac_flg[p]=1
			ac+=1
			wa[p] =wa_cnt[p]
			#wa_cnt=0
		else:
			wa_cnt[p]+=1

wa_ans=0
for i in range(n):
	wa_ans+=wa[i]

print(ac,wa_ans)


Measured memory_bytes: 5364
#include<iostream>
#include<vector>
using namespace std;
int main()
{
	string s;
	cin>>s;
	vector<int> a(s.size());
    int n=s.length();
	for(int i=0;i<=n-1;i++)
	{
		if((s[i]=='R') && (s[i+1]=='L'))
		{
			a[i]+=1;
		

		for(int j=i+2;j<=n-1;j+=2)
		{
			if((s[j]=='L') && (s[j-1]=='L'))
				a[i]++;
			else
				break;
		}

		for(int j=i-2;j>=0;j-=2)
		{
			if((s[j]=='R') && (s[j+1]=='R'))
				a[i]++;
			else
				break;
		}
		a[i+1]++;
		for(int j=i+3;j<=n-1;j+=2)
		{
			if((s[j]=='L') && (s[j-1]=='L'))
				a[i+1]++;
			else
				break;
		}

		for(int j=i-1;j>=0;j-=2)
		{
			if((s[j]=='R') && (s[j+1]=='R'))
				a[i+1]++;
			else
				break;
		}

	}
	}
	for(int i=0;i<n;i++)
		cout<<a[i]<<" ";
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

ll mod_pow(ll x, ll n, ll mod = MOD) {
	if (n == 0) return 1;
	ll res = mod_pow(x * x % mod, n / 2, mod);
	if (n & 1) res = res * x % mod;
	
	return res;
}

const ll mod = 998244353;
int N;
int A[300];
ll dp[301][300*300+1], dp2[301][300*300+1];

int main() {
	cin >> N;
	REP(i, N) scanf("%d", A + i);
	dp[0][0] = 1;
	dp2[0][0] = 1;
	int sum = accumulate(A, A + N, 0);
	REP(i, N) {
		REP(j, sum) if (dp[i][j]) {
			(dp[i + 1][j] += dp[i][j] * 2) %= mod;
			(dp[i + 1][j + A[i]] += dp[i][j]) %= mod;
		}
		REP(j, sum) if (dp2[i][j]) {
			(dp2[i + 1][j] += dp2[i][j]) %= mod;
			(dp2[i + 1][j + A[i]] += dp2[i][j]) %= mod;
		}
	}
	
	ll ans = 0;
	FOR(i, (sum + 1) / 2, sum + 1) (ans += 3 * dp[N][i]) %= mod;
	if (sum % 2 == 0) ans = ((ans - 3 * dp2[N][sum / 2]) % mod + mod) % mod;
	ans = ((mod_pow(3, N, mod) - ans) % mod + mod) % mod;
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 421504
#include<bits/stdc++.h>
using namespace std;
int N,M,a,b,ans[100001];
int main(){
    cin>>N>>M;
    while(M--){
        cin>>a>>b;
        ans[a]^=1,ans[b]^=1;
    }
    cout<<(*max_element(ans,ans+N+1)?"NO":"YES")<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 105
#define INF 1000000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 100005;
const int MOD = 1000000007;

int main(){
    int a,b;
    cin>>a>>b;
    OUT(a+b/2);
    return 0;
}

Measured memory_bytes: 256
<?php
$n = intval(fgets(STDIN));
$min = 10**18;
$c = 0;
for($i = 0; $i < $n; $i++){
  $A[] = -intval(fgets(STDIN));
}
echo lis($A);

function lis($A){
    $dp = array_fill(0, count($A)+1, PHP_INT_MAX);
    $dp[0] = PHP_INT_MIN;
    $longest = 0;
    foreach($A as $a){
        $b = lower_bound($dp, $a+1);
        $dp[$b] = $a;
        $longest = max($longest, $b);
    }
    return $longest;
}
function lower_bound($array, $key){
  $min = -1;
  $max = count($array);
  while($max - $min > 1){
    $c = intdiv($min + $max, 2);
    if($array[$c] >= $key){
      $max = $c;
    }else{
      $min = $c;
    }
  }
  return $max;
}

Measured memory_bytes: 13044
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ "; for(auto v : V) os << v << " "; return os << "]"; }
template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ "; for(auto s:S) os<<s<<" ";return os<<"}"; }
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) { return os << "(" << P.first << "," << P.second << ")";}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) { os << "{ "; for(auto m:M) os<<"("<<m.first<<":"<<m.second<<") "; return os<<"}"; }
#ifdef LMAO
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | "; __f(comma+1, args...); }
#else
    #define trace(...) 42
#endif
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define tcase int tt; cin>>tt; while(tt--)
#define tcase2 int tt; cin>>tt; for(int qq=1;qq<=tt;qq++)
#define all(x) x.begin(), x.end()
typedef long long int ll;
typedef  unsigned long long int ull;
typedef long double ld;
const int MAX = 1000010;
const int MOD2 = 998244353;
const int MOD = 1000000007; 
const int INF = 1e8;    
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const ld EPS = 1e-7;
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)   
/*****************start************/

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout<<fixed<<setprecision(25);cerr<<fixed<<setprecision(10);
    vector<vector<int>> dp;
    int n;
    cin>>n;
    dp.resize(n+1,vector<int>(3,0));
    for(int i=1;i<=n;i++)
    {
        vector<int> act(3);
        for(int &j: act)
            cin>>j;
        for(int j=0;j<3;j++)
            for(int k=0;k<3;k++)
            {
                if(k==j)
                    continue;
                dp[i][j]=max(dp[i][j],dp[i-1][k]+act[j]);
            }
    }
    trace(dp);
    cout<<max(dp[n][0],max(dp[n][2],dp[n][1]))<<endl;

    return 0;
}


Measured memory_bytes: 8724
f=s=input()
for i in range(len(s)-2):
	for j in (i+1,i+2):
		if s[i]==s[j]:
			print(i+1,j+1)
			exit()
if s[-1]!=s[-2]:f=''
l=len(f)
print(l-1,l if l else-1)

Measured memory_bytes: 3188
#include<iostream>
using namespace std;
int main(){
    int n,m;
    int i,j;
    int mat[100][100]={{}};
    int ve[100]={};
    
    cin >> n >> m;
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            cin >> mat[i][j];
        }
    }
    for(j=0;j<m;j++) cin >> ve[j];
    for(i=0;i<n;i++){
        int x=0;
        for(j=0;j<m;j++) x+=mat[i][j]*ve[j];
        cout << x << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int x=n%10;
    if(x==2||x==4||x==5||x==7||x==9)
    cout<<"hon\n";
    else if(x==0||x==1||x==6||x==8)
    cout<<"pon\n";
    else
    cout<<"bon\n";
    return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=1e5+10;
int a[maxn];
int cmp(const int a,const int b)
{
    return a>b;
}
int n,m,v,p;
int b[maxn];
bool judge(int mid){
    if(mid<=p)return true;
    if(a[mid]+m<a[p])return false;
    if(v<=p-1&&a[mid]+m>=a[p])return true;
    for(int i=1;i<=n;i++)b[i]=a[i];
    int temp=0;
    for(int i=1;i<=p-1;i++){
        b[i]+=m;
        temp+=m;
    }
    int inx=n,cnt=v-p+1;
    while(inx>mid&&cnt>1){
        temp+=m;
        inx--;
        cnt--;
        b[inx]+=n;
    }
    temp+=m;
    int now=a[mid]+m;
    int res=m*v-temp;
    for(int i=p;i<mid;i++){
        int add=min(m,max(now-a[i],0ll));
        if(add>res)add=res;
        res-=add;
        b[i]+=add;
    }
    return now>=b[p]&&res<=0;
}
signed main(){
    cin>>n>>m>>v>>p;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a+1,a+n+1,cmp);
    int low=1,high=n;
    int ans=0;
    while(low<=high){
        int mid=(low+high)>>1;
        if(judge(mid)){
            low=mid+1;
            ans=mid;
        }
        else{
            high=mid-1;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;

//少数点表示
//cout <<std::fixed << std::setprecision(14) <<double値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int n;
    string s;
    cin >> n;
    cin >> s;
    int count = 1;
    rep1(i,1,n){
        if(s[i] == s[i-1]){
            continue;
        }
        count++;
    }
    cout << count;

}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line = "";
		while(sc.hasNext()) {
			String str = sc.nextLine();
			line += str;
		}

		int[] count = new int[26];
		for(int i=0;i<26;i++) {
			count[i] = 0;
		}

		for(int i = 0; i < line.length(); i++) {
			char current = line.charAt(i);
			if(current >= 'a' && current <= 'z') {
				int index = (int) current - 97;
				count[index]++;
			} else if(current >= 'A' && current <= 'Z') {
				int index = (int) current - 65;
				count[index]++;
			}
		}

		for(char c = 'a'; c <= 'z'; c++) {
			System.out.println(c + " : " + count[(int)c - 97]);
		}

		sc.close();
	}

}



Measured memory_bytes: 26280
#include<bits/stdc++.h>
using namespace std;
int main(){
    int Q;
    long long a,b;
    scanf("%d",&Q);
    while(Q--){
        scanf("%lld%lld",&a,&b);
        if(a>b)swap(a,b);
        long long ans=0,c=a*b,d=sqrt(c);
        if(d*d==c)d--;
        if(a==b||a==b+1)ans=2*a-2;
        else if(d*(d+1)>=a*b)ans=2*d-2;
        else ans=2*d-1;
       	printf("%lld\n",ans);
    }
    return 0;
}

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

while True:

    H, W, N = MAP()
    if H == W == H == 0:
        break

    grid = list2d(H, W, 0)
    for i in range(H):
        row = LIST()
        for j in range(W):
            grid[i][j] = row[j]

    # dp[i][j] := (i, j)のマスをN回目の前までに何回通るか
    dp = list2d(H+1, W+1, 0)
    dp[0][0] = N - 1
    for i in range(H):
        for j in range(W):
            # 通る回数が偶数なら半分ずつ
            if dp[i][j] % 2 == 0:
                dp[i+1][j] += dp[i][j] // 2
                dp[i][j+1] += dp[i][j] // 2
            else:
                # 通る回数が奇数なら、元のグリッドの状態に応じて1回多く行く方が決まる
                if grid[i][j] == 0:
                    dp[i+1][j] += dp[i][j] // 2 + 1
                    dp[i][j+1] += dp[i][j] // 2
                else:
                    dp[i+1][j] += dp[i][j] // 2
                    dp[i][j+1] += dp[i][j] // 2 + 1

    # N-1回終了時の状態にグリッドを更新
    for i in range(H):
        for j in range(W):
            grid[i][j] ^= dp[i][j]
            grid[i][j] &= 1

    # N回目の散歩をシミュレーション
    i = j = 0
    while i < H and j < W:
        if grid[i][j] == 0:
            i += 1
        else:
            j += 1
    print(i+1, j+1)



Measured memory_bytes: 28344
while True:
    a,b,c = input().split()
 
    if b == "?":
        break
    elif b == "+":
        s = int(a)+int(c)
    elif b == "-":
        s = int(a)-int(c)
         
    elif b == "*":
        s = int(a)*int(c)
         
    else :
        s = int(a)/int(c)
    print(int(s))

Measured memory_bytes: 7640
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() ll t;cin>>t;while(t--)
#define pb push_back
#define mkp make_pair
#define nl cout<<endl
#define MOD 1000000007
#define loop(i,start,end) for(ll i=start;i<end;i++)
#define N 100001
#define all(v) v.begin(),v.end()
#define oa(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";nl
#define ov(a) for(int i=0;i<a.size();i++)cout<<a[i]<<" ";nl
int main() 
{
    fastio();
  ll n;cin>>n;
  vector<ld>v(n+1);
  loop(i,0,n)cin>>v[i+1];
  ld dp[n+1][n+1];

  memset(dp,0,sizeof(dp));
  dp[0][0] = 1;
  for(int i = 1;i<=n;i++)
  {
  	for(int j = 0;j<=i;j++)
  	{
  		dp[i][j] = (1-v[i])*dp[i-1][j];
  		if(j)
  			dp[i][j]+=v[i]*dp[i-1][j-1];
  	}
  }
  ld ans = 0;
  for(int i = (n+1)/2;i<=n;i++)
  {
  	ans+=dp[n][i];
  }
  cout<<fixed<<setprecision(10)<<ans<<endl;

  return 0;
}

Measured memory_bytes: 140928
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

void hoge(int n, vector<int> vec = {}) {
  if (n == 0) {
    cout << vec[0];
    for_each(vec.begin() + 1, vec.end(), [](auto &v) {cout << " " << v;});
    cout << endl;
    return;
  }

  int h = (vec.size() != 0) ? min(*vec.rbegin(), n) : n;

  for (int i = h; 1 <= i; --i) {
    vector<int> vec2 = vec;
    vec2.push_back(i);
    hoge(n - i, vec2);
  }
}

int main() {
  int n;
  while (cin >> n, n)
    hoge(n);
}


Measured memory_bytes: 3012
H,W=list(map(int,input().split()))
l=[]
for i in range(H):
   l.append(list(input()))
from collections import Counter
l=sum(l,[])
l=Counter(l)
one=(H%2)*(W%2)
two=(H%2)*(W//2)+(W%2)*(H//2)
four=(H//2)*(W//2)
for i in l.values():
   j=i//4
   i=i%4
   four-=j
   if i==1:
      one-=1
   elif i==2:
      two-=1
   elif i==3:
      one-=1;two-=1
if set([0]) == set([one,two,four]):
   print("Yes")
else:
   if four<0:
      two+=four*2
   four=0
   if set([0]) == set([one,two,four]):
      print("Yes")
   else:
      print("No")

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

int main(){
  int X, N;
  cin >> X >> N;
  vector<int> p(N);
  for(int i=0;i<N;i++){
    cin >> p.at(i);
  }
  
  //0,101も答えとしてありうる
  vector<int> all(102);
  for(int i=0;i<102;i++){
      all.at(i) = i;
  }
  
  //入力された値を0~101の整数リストから除く
  for(int i=0; i<N;i++){
    all.erase(remove(all.begin(),all.end(),p.at(i)),all.end());
  }
  
  int abs_min = 1000;
  int ans = X;
  for(int i=0; i<(int)all.size();i++){
    if(abs(X - all.at(i)) < abs_min){
      abs_min = abs(X - all.at(i));
      ans = all.at(i);
    }else if(abs(X - all.at(i)) == abs_min){
      if(ans > all.at(i)){
        ans = all.at(i);
      }
    }
  }
  
  cout << ans << endl;

}

Measured memory_bytes: 3640
#include<cstdio>
#include<cstring>
using namespace std;
int jud;
char s[200005],x[200005],ch[150],sh[150];
int main(){
	scanf("%s",s);	scanf("%s",x);
	for(int i = 0; i < strlen(s); i++){
		if(ch[s[i]] == '\0'){
			ch[s[i]] = x[i];
		}
		if(sh[x[i]] == '\0'){
			sh[x[i]] = s[i];
		}
		if(ch[s[i]] != x[i] || sh[x[i]] != s[i]){
			printf("No");
			jud = 1;
			break;
		}
	}
	if(!jud) printf("Yes");
}

Measured memory_bytes: 640
import copy
a = [int(input())]
t = []
i = 1


def f(n):
    if n % 2 == 0:
        return int(n / 2)
    else:
        return int(3 * n + 1)


while True:
    a.append(f(a[i - 1]))
    t = copy.copy(a)
    t = [j for j, x in enumerate(t, 1) if t.count(x) > 1]
    if 0 < len(t):
        print(t[1])
        break
    i += 1

Measured memory_bytes: 3444
package main

import (
    "fmt"
	"strings"
	"os"
)

func main() {
    var H,W int
    fmt.Scan(&H, &W)
	map_ := [50+2]string{}
	map_[0] = strings.Repeat(".", W+2)
	map_[H+1] = strings.Repeat(".", W+2)
	for i:= 1; i <= H; i++ {
		fmt.Scan(&map_[i])
		map_[i] = `.` + map_[i] + `.`
	}
	
	for i:= 1; i <= H; i++ {
		for j:= 1; j <= W; j++ {
			if(map_[i][j]!=`#`[0]){
				continue
			}
			is_ok := false
			diff := [5]int{0,1,0,-1,0}
			for d:=0;d<4;d++ {
				if(map_[i+diff[d]][j+diff[d+1]]==`#`[0]) {
					is_ok = true
				}
			}
			if(is_ok == false){
				fmt.Println("No")
				os.Exit(0)
			}
		}
	}
	fmt.Println("Yes")
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)

using namespace std;

vector<int> vec;

int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }

int main(void) {
	double a;

	long long ans;

	ans = 0;

	cin >> a;

	cout << a * 3.14*2;


}




Measured memory_bytes: 3792
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <vector>
using namespace std;

int main()
{
	int h, w, n;
	cin >> h >> w >> n;
	for (int i = 1; i <= h*w; i++)
	{
		if (n <= max(h, w) * i)
		{
			cout << i;
			return 0;
		}
	}
	system("pause>0");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

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

using namespace std;

int n;
double a[1005];

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	sort(a+1, a+n+1);
	
	double ans = a[1];
	for(int i = 2; i <= n; i++) ans = (ans+a[i])/2;
	printf("%.11f\n", ans);
	
	return 0;
}

Measured memory_bytes: 256
function main(input) {
  input=input.trim();
  //input=parseInt(input.split(" ")[0], 10)
  var arr=0
  for(var i=0; i<input.length; i++){
    if(input.substr(i,1)=="9"){
      arr++
    }
  }
  if(arr>0){
    console.log("Yes");
  }else{
    console.log("No");
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import deque

k = ni()
que = deque([(1,1)])

kmod = [0]*k

while kmod[0] == 0:
    cost, idx = que.popleft()
    if kmod[idx] == 0:
        kmod[idx] = cost
        que.appendleft((cost, (10*idx%k)))
        que.append((cost+1, (idx+1)%k))            
        
print(kmod[0])

Measured memory_bytes: 14444
from itertools import product
N = int(input())

element = [3,5,7]
ans = 0
for i in range(3, len(str(N))+1) :
    L = product(element, repeat=i)
    for l in L :
        if ((3 not in l) or (5 not in l) or (7 not in l)) :
            continue
        number = int("".join(list(map(str,l))))
        if number <= N :
            ans += 1
print(ans)


Measured memory_bytes: 3188
#include <iostream>
using namespace std;
int main(){
	int a,b,k;
	cin >> a >> b >> k;
	int cnt = 0;
	for(int i=100;i>0;--i){
		if(!(a % i) && !(b % i)){
			++cnt;
			if(cnt >= k){
				cout << i << endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
	int n;
	cin >> n;
	if (n == 3) {
		cout << 2 << endl;
		cout << 1 << " " << 3 << endl;
		cout << 2 << " " << 3 << endl;
		return 0;
	}
	int m = n * (n - 1) / 2;
	if (n % 2 == 1) {
      m-=n/2;
		cout << m << endl;
		for (int i = 1; i <= n - 1; i++) {
			for (int j = i + 1; j <= n; j++) {
              if(i+j==n) continue;
              cout<<i<<" "<<j<<endl;
			}
		}
	}
	else {
		m -= n / 2;
		cout << m << endl;
		for (int i = 1; i <= n - 1; i++) {
			for (int j = i + 1; j <= n; j++) {
				if (i + j == n+1) continue;
				cout << i << " " << j << endl;
			}
		}
	}
}

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

#define lli long long int
#define pb push_back

lli dp[3002][3002];
lli dir[3002][3002];

main()
{
    lli a,b,j,i,c,n,m;
    string s,t,ans="";

    cin>>s;
    cin>>t;
    n = s.length();
    m = t.length();
    for(i=0;i<n;i++)
    {
        dp[i][0] = 0;
        dir[i][0] = 1;
    }
    for(i=0;i<m;i++)
    {
        dp[0][i] = 0;
        dir[0][i] = 3;
    }

    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(s[i-1] == t[j-1])
            {
                dp[i][j] = dp[i-1][j-1]+1;
                dir[i][j] = 2;
            }
            else
            {
                if(dp[i-1][j] >= dp[i][j-1] )
                {
                    dp[i][j] = dp[i-1][j];
                    dir[i][j] = 1;
                }
                else
                {
                    dp[i][j] = dp[i][j-1];
                    dir[i][j] = 3;
                }
            }
        }
    }
    i = n;
    j = m;
    while(dp[i][j] > 0)
    {
        if(dir[i][j] == 1)
        {
            i--;
        }
        else if(dir[i][j] == 3)
        {
            j--;
        }
        else
        {
            ans += s[i-1];
            i--;
            j--;
        }
    }
    if(dp[n][m] == 0)
    {
        cout<<"";
        return 0;
    }

    for(i=ans.length()-1;i>=0;i--)
    {
        cout<<ans[i];
    }
}


Measured memory_bytes: 141056
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

int[] compact(int[] xs) {
    auto ys = xs.dup;
    ys.sort;

    int[int] m;
    foreach (i, y; ys) {
        m[y] = cast(int) i + 1;
    }

    auto ret = new int[xs.length];
    for (int i = 0; i < xs.length; i++)
        ret[i] = m[xs[i]];
    return ret;
}

// long calc(int[] xs) {
//     // auto n = xs.maxElement;
//     auto n = xs.reduce!max;
//     auto bit = new BinaryIndexedTree(n);
//     long ans = 0;
//     for (int i = 0; i < xs.length; i++) {
//         ans += i - bit.sum(xs[i]);
//         bit.add(xs[i], 1);
//     }
//     return ans;
// }

long calc2(int[] xs) {
    // auto n = xs.maxElement;
    auto n = xs.reduce!max;
    auto bit = new BinaryIndexedTree(n);
    long ans = 0;
    for (int i = 0; i < xs.length; i++) {
        int x = xs[i];
        ans += x - 1 - bit.sum(x);
        bit.add(x, 1);
    }
    return ans;
}

void main() {
    readln;
    auto xs = readints;

    auto ans = calc2(compact(xs));
    writeln(ans);
}

class BinaryIndexedTree {
    private int[] _data;

    this(int n) {
        _data = new int[n + 1];
    }

    /// [1, p] ??????(1 based)
    int sum(int p) {
        assert(0 < p && p < _data.length);

        int s = 0;
        while (p > 0) {
            s += _data[p];
            p -= p & -p;
        }
        return s;
    }

    /// p ????????? x ????????????(1 based)
    void add(int p, int x) {
        assert(0 < p && p < _data.length);

        while (p < _data.length) {
            _data[p] += x;
            p += p & -p;
        }
    }
}

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

using namespace std;

typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli>> mat;
typedef vector<unordered_map<lli,lli>> graph;

lli k;
vll a;
lli ans_min = 2;
lli ans_max = 2;

void error(){
  cout << -1 << endl;
  exit(0);
}

int main(){
  cin >> k;
  a = vll(k+1);
  for(lli i = 1;i <= k;i++) cin >> a[i];
  a[0] = 1;
  reverse(a.begin(),a.end());
  for(lli i = 1;i <= k;i++){
    if(ans_min%a[i-1] != 0 || ans_max%a[i-1] != 0) error();
    ans_min = ans_min + a[i] - (ans_min%a[i] ? ans_min%a[i] : a[i]);
    ans_max = (ans_max+a[i-1]-1)/a[i]*a[i];
    if(ans_min > ans_max) error();
  }
  cout << ans_min << " " << ans_max << endl;
  return 0;
}


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

typedef long long ll;
typedef vector<long long> vll;
typedef vector<vector<long long>> mll;
typedef vector<pair<long long, long long>> vpl;
typedef pair<long long, long long> pll;
#define minimize(var, val) (var = min((val), var))
#define maximize(var, val) (var = max((val), var))

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    // Taking the input
    ll n;
    cin >> n;
    const ll subsets = 1 << n;
    int a[n][n];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a[i][j];
        }
    }
    // Computing the Full matching value for all subsets
    ll val[subsets];
    for (int i = 0; i < subsets; i++) {
        val[i] = 0;
        for (int x = 0; x < n; x++) {
            for (int y = 0; y < n; y++) {
                if ((i & (1 << x)) && (i & (1 << y))) {
                    val[i] += a[x][y];
                }
            }
        }
    }
    for (int i = 0; i < subsets; i++)
        val[i] /= 2;
    // Computing the answer as all possible 2-partitions
    ll ans[subsets];
    memset(ans, 0, sizeof(ll) * subsets);
    for (int i = 0; i < subsets; i++) {
        ll present = __builtin_popcount(i);
        ll subsets = 1ll << present;
        int pos[present];
        for (int bit = 0, found = 0; bit < n; bit++)
            if (i & (1 << bit))
                pos[found++] = bit;
        for (int j = 0; j < subsets; j++) {
            // Preparing the j-th subset of i
            unsigned int subset = 0;
            for (int y = 0; y < present; y++) {
                if (j & 1 << y)
                    subset |= 1 << pos[y];
            }
            // Minimizing using further 2-splits
            unsigned int complement = i & ~(subset);
            maximize(ans[i], ans[complement] + ans[subset]);
        }
        // Considering the atomic expressions
        maximize(ans[i], val[i]);
    }
    cout << ans[(1 << n) - 1] << endl;
}

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

int main(){
  char s[3][3];
  rep(i,3){
    rep(j,3){
      cin>>s[i][j];
    }
  }
  rep(i,3)cout<<s[i][i];
}

Measured memory_bytes: 256
use input::{Input, ReadMode};

fn main() {
    let mut input = Input::new(ReadMode::Line);

    let a: u64 = input.parse();
    let b: u64 = input.parse();
    let n: u64 = input.parse();

    let x = (a * n.min(b - 1)) / b;
    println!("{}", x);
}

#[allow(dead_code)]
pub mod input {
    use std::io::{BufRead, Read};
    use std::str::{FromStr, SplitAsciiWhitespace};

    pub enum ReadMode {
        Full,
        Line,
    }

    pub struct Input<'a> {
        lock: std::io::StdinLock<'static>,
        iter: Option<SplitAsciiWhitespace<'a>>,
        mode: ReadMode,
    }

    impl<'a> Input<'a> {
        fn naive_read(&mut self) -> Option<SplitAsciiWhitespace<'a>> {
            let mut s = Box::leak(Box::new(String::new()));
            let res = match self.mode {
                ReadMode::Full => self.lock.read_to_string(&mut s),
                ReadMode::Line => self.lock.read_line(&mut s),
            };
            res.ok().expect("failed to read");
            Some(s.split_ascii_whitespace())
        }
        pub fn new(mode: ReadMode) -> Self {
            let lock = Box::leak(Box::new(std::io::stdin())).lock();
            let iter = None;
            Self { lock, iter, mode }
        }
        pub fn read_line(&mut self) -> String {
            let mut s = String::new();
            self.lock.read_line(&mut s).ok().expect("failed to read");
            s
        }
        pub fn parse<T: FromStr>(&mut self) -> T {
            match &mut self.iter {
                Some(iter) => {
                    let x = match iter.next() {
                        Some(x) => x,
                        None => {
                            self.iter = self.naive_read();
                            self.iter.as_mut().unwrap().next().expect("reached EOF")
                        }
                    };
                    x.parse().ok().expect("failed to parse")
                }
                None => {
                    self.iter = self.naive_read();
                    self.parse()
                }
            }
        }
    }
}


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

int main() {
	int a, b, c;
	cin >> a >> b >> c;

	if( a > b ) { swap( a, b ); }
	if( b > c ) { swap( b, c ); }
	if( a > b ) { swap( a, b ); }

	cout << a << ' ' << b << ' ' << c << endl;
}



Measured memory_bytes: 3084
from math import *
n=int(input())
l=[]
for i in range(1,int(sqrt(n))+1):
    if(n%i==0):
        l.append([i,n//i])
d=[]
for i in range(len(l)):
    x=str(l[i][0])
    y=str(l[i][1])
    d.append(max(len(x),len(y)))
print(min(d))


Measured memory_bytes: 68356
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
   
   for(int i = 0;i < n;i++){
    cin >> a.at(i);
   }
   sort(a.begin(), a.end());
	long tmp;
  	long ans = 99999999;
  
   for(int i = a[0];i <=a[n-1];i++){
     tmp = 0;
     for(int j = 0;j < n;j++){
       tmp += pow((a.at(j)-i),2.0);
     }
     ans = min(ans,tmp);
   }
    
    cout << ans;

}
   


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll isPrime(int n) 
{ 
	// Corner cases 
	if (n <= 1) 
		return 1; 
	if (n <= 3) 
		return 2; 

	// This is checked so that we can skip 
	// middle five numbers in below loop 
	if (n % 2 == 0 || n % 3 == 0) 
		return 1; 

	for (int i = 5; i * i <= n; i = i + 6) 
		if (n % i == 0 || n % (i + 2) == 0) 
			return 1; 

	return 2; 
} 

ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i,res%=1000000007; 
    return res; } 
 
 int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b); 
} 
  
 
ll findlcm(ll arr[], int n) 
{ 
   
    ll ans = arr[0]; 
  
    
    for (int i = 1; i < n; i++) 
        ans = (((arr[i] * ans)) / 
                (gcd(arr[i], ans))); 
  
    return ans; 
} 
 
 
int main() 
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll n;
    cin>>n;
    vector<ll> v(n);
    ll sum=0;
    for(ll i=0;i<n;i++)
        cin>>v[i],sum+=v[i];
    
    ll x[n];
    ll sum2{};
    for(ll i=1;i<n;i+=2)
        sum2 += v[i];
    x[0] = sum - 2*sum2;
    for(ll i=0;i<n-1;i++)
    {
        x[i+1] = 2*v[i] - x[i];
    }
    for(ll i=0;i<n;i++)
        cout<<x[i]<<" ";
	
    } 
    return 0;
}


Measured memory_bytes: 4760
#include <bits/stdc++.h>
using namespace std;
string s;
int main(){
    //freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> s;
    if(s.find("9") != string::npos) puts("Yes");
    else  puts("No");
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N,M,R;
ll r[10];
ll d[210][210];
int main(){
    cin>>N>>M>>R;
    for(ll i=0;i<R;i++){
        cin>>r[i];
    }
    for(ll i=1;i<=N;i++){
        for(ll j=1;j<=N;j++){
            d[i][j]=INF;
        }
    }
    for(ll i=0;i<M;i++){
        ll a,b,c;
        cin>>a>>b>>c;
        d[a][b]=d[b][a]=c;
    }
    for(ll k=1;k<=N;k++){
        for(ll i=1;i<=N;i++){
            for(ll j=1;j<=N;j++){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    vector<ll> v(R);
    for(ll i=0;i<R;i++){
        v[i]=i;
    }
    ll ans=INF;
    do{
        ll sum=0;
        for(ll i=0;i<R-1;i++){
            sum+=d[r[v[i]]][r[v[i+1]]];
        }
        ans=min(ans,sum);
    }while( next_permutation(v.begin(),v.end()) );
    cout<<ans<<endl;
    return 0;
}

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

vector<vector<int> > G(101010);
int N;

int solve(int v){
  vector<int> res;
  int n=G[v].size();
  rep(i,n){
    res.push_back(solve(G[v][i]));
  }
  sort(res.begin(),res.end());
  int ret=0;
  rep(i,n) ret=max(ret,res[i]+n-(i+1));
  return (ret+1);
}

int main(){
  cin>>N;
  for(int i=2;i<=N;i++){
    int a; cin>>a;
    G[a].push_back(i);
  }
  cout<<solve(1)-1<<endl;
  return 0;
}


Measured memory_bytes: 15104
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

int main() {
  int n;
  scanf("%d", &n);
  vll a(3*n);
  rep (i, 3*n) {
    scanf("%lld", &a[i]);
  }
  ll accum = 0;
  priority_queue<int, vi, greater<int> > pq;
  rep (i, n) {
    pq.push(a[i]);
    accum += a[i];
  }

  vll score_first(2*n, 0);
  score_first[n-1] = accum;
  FOR (i, n, 2*n) {
    if (pq.top() < a[i]) {
      accum -= pq.top();
      accum += a[i];
      pq.pop();
      pq.push(a[i]);
    }
    score_first[i] = accum;
  }

  accum = 0;
  priority_queue<int> pql;
  for (int i = 3*n-1; i >= 2*n; --i) {
    pql.push(a[i]);
    accum += a[i];
  }

  vll score_second(2*n+1, 0);
  score_second[2*n-1] = accum;
  for (int i = 2*n-1; i >= n; --i) {
    if (pql.top() > a[i]) {
      accum -= pql.top();
      accum += a[i];
      pql.pop();
      pql.push(a[i]);
    }
    score_second[i-1] = accum;
  }

  ll ans = LLONG_MIN;
  FOR (i, n-1, 2*n) {
    ans = max(ans, score_first[i] - score_second[i]);
  }
  printf("%lld\n", ans);

  return 0;
}


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

int main()
{
    int n,q;
    std::cin >> n >> q;
    std::string s;
    std::cin >> s;
    std::vector<int> l(q), r(q), v(n,0);
    for (int i = 0; i < q; i++) {
        int tmpl,tmpr;
        std::cin >>tmpl>>tmpr;
        l[i] = tmpl-1;
        r[i] = tmpr-1;
    }


    for (int i = 1; i < n+1; i++) {
        v[i] = v[i-1] + ((s[i-1] == 'A' && s[i] == 'C') ? 1 : 0);
    }

    // for (int i = 0; i < n; i++) {  std::cout << v[i]; }std::cout << std::endl;

    for (int i = 0; i < q; i++) {
        size_t li = std::max(l[i]-1,0);
        int ans = v[r[i]] - v[li];
        if (s[li] == 'A' && s[l[i]] == 'C')
            ans--;
        std::cout << ans << std::endl;
    }

    return 0;
}


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

int main(){
    int a,b,c,d,e,k=0;
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    scanf("%d",&d);
    scanf("%d",&e);
    if(a%10!=0) k=a%10, a/=10, a+=1, a*=10;
    if(b%10!=0){
        if(k>b%10) k=b%10;
        b/=10, b+=1, b*=10;
    }
    if(c%10!=0){
        if(k>c%10) k=c%10;
        c/=10, c+=1, c*=10;
    }
    if(d%10!=0){
        if(k>d%10) k=d%10;
        d/=10, d+=1, d*=10;
    }
    if(e%10!=0){
        if(k>e%10) k=e%10;
        e/=10, e+=1, e*=10;
    }
    if(k==0) printf("%d",a+b+c+d+e);
    else printf("%d",a+b+c+d+e-10+k);
    return 0;
}

Measured memory_bytes: 128
{-# LANGUAGE RankNTypes #-}
    
import Control.Monad.State
import Control.Monad.ST
import Data.Array.ST
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Set as S

main :: IO ()
main = readLine >>= main'
    where
        main' [n, m] = replicateM m (head <$> readLine) >>= print . solve n

solve :: Int -> [Int] -> Int
solve n as = runST (initialize >>= stAction)
    where
        initialize :: ST s (Table s Int a)
        initialize = newArray (0, 10 ^ 6) Nothing

        s = S.fromList as
        
        stAction = evalMemo calc 0

        calc f i
            | i > n = return 0
            | i == n = return 1 
            | S.member i s = return 0
            | otherwise = add <$> f (i + 1) <*> f (i + 2)

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

infixl 6 `add`
infixl 7 `mul`

add :: Int -> Int -> Int
add x y = val $ x + y

mul :: Int -> Int -> Int
mul x y = val $ x * y

inv :: Int -> Int
inv x = pow x $ modVal - 2

pow :: Int -> Int -> Int
pow b e
    | e == 0 = 1
    | odd e = mul b . pow b $ e - 1
    | otherwise = mul v v
    where
        v = pow b $ e `div` 2

val :: Int -> Int
val = (`mod` modVal)

modVal :: Int
modVal = 10 ^ 9 + 7

primes :: [Int]
primes = build [2..]
    where
        build (x : xs) = x : build (filter (\n -> n `mod` x /= 0) xs)
        
isPrime :: Int -> Bool
isPrime n = check primes
    where
        check (x : xs)
            | x == n = True
            | x > n = False
            | otherwise = check xs

type Table s a b = STArray s a (Maybe b)
type Memo s a b = a -> StateT (Table s a b) (ST s) b

evalMemo :: (Ix a) => (forall s. Memo s a b -> Memo s a b) -> a -> Table s a b -> ST s b
evalMemo f k = evalStateT (memoizeFix f k)

runMemo :: (Ix a) => (forall s. Memo s a b -> Memo s a b) -> a -> Table s a b -> ST s (b, Table s a b)
runMemo f k = runStateT (memoizeFix f k)

memoizeFix :: (Ix a) => (forall s. Memo s a b -> Memo s a b) -> forall s. Memo s a b
memoizeFix f k = get >>= (\arr -> lift (readArray arr k) >>= maybe (f (memoizeFix f) k >>= ((<$) <*> (lift . writeArray arr k . Just))) return)

Measured memory_bytes: 41084
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i=(a); i<(n); ++i)
#define rrep(i,a,n) for(ll i=(a); i>(n); --i)
#define erep(i,a,n) for(ll i=(a); i<=(n); ++i)
#define rerep(i,a,n) for(ll i=(a); i>=(n); --i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int) x.size())
#define print(X) cout << (X) << endl
#define _ << " " <<
static const int INF = 1e+9+7;

int main(){
  int a,b;
  cin >> a >> b;
  if(max(a,b) <= 8){
    print("Yay!");
  }
  else{
    print(":(");
  }

  return 0;
}


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

int main()
{
    string s;  cin >> s;

    if (s.length() == 1)  cout << s;
    else {
        rep(i, s.length()) {
            if ((i + 1) % 2 == 0)  continue;
            else  cout << s[i];
        }
    }
    cout << '\n';
}

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

typedef long long ll;
typedef pair<int,int> pii;
const int INF=2e9+10;
#define fi first
#define se second
#define pb push_back
#define mp make_pair

int read() {
	int xx=0,ww=1;
	char ch=getchar();
	while(ch>'9'||ch<'0') {
		if(ch=='-') ww=-ww;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') {
		xx=10*xx+ch-48;
		ch=getchar();
	}
	return xx*ww;
}

int n,m,de[100010];
int from,to,fa[100010];
vector<int>ed[100010];
queue<int>q;

int main() {
	n=read();
	m=read();
	for(int i=1; i<=n+m-1; i++) {
		from=read();
		to=read();
		ed[from].pb(to);
		de[to]++;
	}
//	for(int i=1; i<=n; i++) printf("%d\n",de[i]);
	for(int i=1; i<=n; i++)
		if(de[i]==0) {
			q.push(i);
			while(!q.empty()) {
				int u=q.front();
				q.pop();
				for(int j=0; j<ed[u].size(); j++) {
					int v=ed[u][j];
					de[v]--;
					if(de[v]==0) {
						fa[v]=u;
						q.push(v);
					}
				}
			}
			fa[i]=0;
			break;
		}
	for(int i=1; i<=n; i++) printf("%d\n",fa[i]);
	return 0;
}

Measured memory_bytes: 7040
// In the name of God //
 
#include <bits/stdc++.h>
#define ll long long
#define all(x) (x).begin(), (x).end()
#define pii pair <int, int>
using namespace std;
const int N = 1e6 + 5;
const int mod = 1e9 + 7;


void solve() {
    int a;
    cin >> a;
    cout << a + a*a + a*a*a;
}


int main()  {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int tt = 1;
    // cin >> tt;
    for (int tc = 1; tc <= tt; ++tc) {
        solve();
    } 
}                                   

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

int main() {
  int N, K;
  cin >> N >> K;
  int sum = 0;
  
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    if (2 * x < K) {
      sum = sum + x;
    }
    else {
      sum = sum + K - x; 
    }
  }
  cout << 2 * sum << endl;
}

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

#define llint long long int
#define pb push_back

using namespace std;

int main(){
  int n, t;
  cin >> n >> t;
  int ans = 10001;
  while(n--){
  	int a, b;
  	cin >> a >> b;
    if(b <= t){
      if(a < ans)
        ans = a;
    }
  }
  if(ans > 1000){
    cout << "TLE";
  	return 0;
  }
  cout << ans;
  return 0;
}

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

int main()
{
	long double N, D, Y, X;
	int count = 0;
	std::cin >> N >> D;

	for (; N--;)
	{
		std::cin >> Y >> X;

		if(sqrt(pow(Y, 2) + pow(X, 2)) <= D)
			count++;
	}
	std::cout << count;

}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int H, W;
    cin >> H >> W;
    int N;
    cin >> N;
    vector<pair<int, long long>> a(N);
    REP(i, N) {
        long long tmp;
        cin >> tmp;
        a[i] = make_pair(i + 1, tmp);
    }
    vector<int> b;
    REP(i, N) {
        REP(j, a[i].second) { b.push_back(a[i].first); }
    }

    vector<vector<string>> Res(H, vector<string>(W));
    REP(i, H) {
        vector<string> S(W);
        REP(j, W) {
            if(i % 2 == 0) {
                S[j] = to_string(b[i * W + j]);
            } else {
                S[W - 1 - j] = to_string(b[i * W + j]);
            }
        }
        REP(j, W) { Res[i][j] = S[j]; }
    }
    REP(i, H) {
        REP(j, W) { cout << Res[i][j] << " "; }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define all(x) x.begin(),x.end()
#define y1 omg
#define INF 1000000010
#define FOR(x, n) for(int x=0; x<n; x++)
#define ini(x, n) memset(x, n, sizeof(x));
#define MOD ((int)1e9 + 7)
#define atoi(x) ((x)-'0')
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

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

ll n, d, a, b, ans;

int main() {
	cin >> n >> d;
	FOR(i, n) {
		cin >> a >> b;
		if (a * a + b * b <= d * d) ans++;
	}
	cout << ans;
}

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

int main()
{
  int A, B, C, X;
  cin >> A >> B >> C >> X;

  int ans = 0;
  for(int i=0; i<=A; ++i) {
    for(int j=0; j<=B; ++j) {
      for(int k=0; k<=C; ++k) {
        if(500*i + 100*j + 50*k == X) ++ans;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256