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

using namespace std;

#define int long long

// index l <= x <= r
int get_imos(vector<int> &v, int l, int r){
    return v[r+1]-v[l];
}

signed main(){
    int N;
    cin >> N;
    string S;
    cin >>S;

    string rgb = "RGB";
    // int s
    vector<int> is(N);
    for(int i=0;i<N;i++){
        for(int j=0;j<3;j++){
            if(S[i] == rgb[j])
                is[i] = j;
        }
    }

    // 全ての文字が異なるものの総和
    int ad = 0;

    vector<vector<int>> imos(3, vector<int>(N+1, 0));
    for(int i=0;i<N;i++){
        for(int j=0;j<3;j++){
            if(j == is[i]){
                imos[j][i+1] = imos[j][i] + 1;
            }else{
                imos[j][i+1] = imos[j][i];
            }
        }
    }

    for(int i=0;i<N-2;i++){
        for(int j=i+1;j<N-1;j++){
            if(is[i]!=is[j]){
                int last = 3-is[i]-is[j];
                ad += get_imos(imos[last], j+1, N-1);
            }
        }
    }

    // 全て異なり，文字の間が同じ距離もの
    int sd = 0;
    for(int d=0;2*d+3<=N;d++){
        for(int i=0;2*d+2+i<N;i++){
            int i1 = i;
            int i2 = i + d + 1;
            int i3 = i + 2*d+2;
            if(is[i1]!=is[i2] && is[i2]!=is[i3]&&is[i1]!=is[i3])sd++;
        }
    }

    cout << ad - sd <<endl;
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int v[1000];
  int c[1000];
  int vc[1000];
  int ans = 0;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> v[i];
  }
  for(int i=0;i<n;i++){
    cin >> c[i];
  }
  for(int i=0;i<n;i++){
    vc[i]=v[i]-c[i];
    if(vc[i]>0){
      ans = ans + vc[i];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#pragma region
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(x,arr) for(auto& x:arr)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define VPII vector<PII>
#define VPLL vector<PLL>
#define FI first 
#define SE second
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1;
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
#pragma endregion
//-------------------
const int MX = 100000+7;
int dp[MX];

int main(){
    cin.tie(0); ios::sync_with_stdio(false); //cout << fixed << setprecision(15);
    int n; cin >> n;
    fill(dp+1, dp+n+1, INF);
    FOR(i,0,n-1) {
        for(int k=6; i+k<MX; k*=6) chmin(dp[i+k], dp[i] + 1);
        for(int k=9; i+k<MX; k*=9) chmin(dp[i+k], dp[i] + 1);
        chmin(dp[i+1], dp[i]+1);
    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 3972
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;



int main()
{
    int n,m;
    cin >> n >> m;
    int ans[n];
    for(int i = 0; i < n; i++){
        ans[i] = -1;
    }
    bool ex = true;
    for(int i = 0; i < m; i++){
        int s,c;
        cin >> s >> c;
        if(ans[s-1] == -1){
            ans[s-1] = c;
        }else{
            if(ans[s-1] != c){
                ex = false;
            }
        }
        if(s == 1 && c == 0 && n != 1){
            ex = false;
        }
    }
    if(n == 1 && ans[0] == -1){
        cout << 0 << endl;
      return 0;
    }
    for(int i = 0; i < n; i++){
        if(ans[i] == -1 && i != 0) ans[i] = 0;
        if(ans[i] == -1 && i == 0) ans[i] = 1;
    }

    if(ex){
        int k = 0;
        int a = 1;
        for(int i = n-1; i >= 0; i--){
            k += a * ans[i];
            a *= 10;
        }
        cout << k;
    }else{
        cout << -1;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
using gragh = vector<vector<int>>;


int main() {
    int N;
    cin>>N;
    string S;
    cin>>S;
    int ans = 0;

    for (int i = 0; i < 1000; ++i) {
        string t;
        int x = i;
        for (int j = 0; j < 3; ++j) {
            t += to_string(0 + x%10);
            x /= 10;
        }
        int ti = 0;
        for (int k = 0; k < N; ++k) {
            if(S[k]==t[ti]){
                ti++;
                if(ti == 3 ){
                    break;
                }
            }
        }
        if (ti == 3){
            ans ++;
        }
    }

    cout<<ans<<endl;



}


Measured memory_bytes: 256
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/

#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
ll gcd(ll a, ll b) {
	if(b == 0) return a;
	return gcd(b, a % b);
}

const ll MAX_N = 1e5;
ll N;
ll A[MAX_N];
// d[0-iまでの数列][右端は増加/減少中]
ll dp[MAX_N+1][2]; // メモ化テーブル
 
// // i番目以降の品物から重さの総和がj以下になるように選ぶ
void rec(ll i){
	if (i==0){
		dp[i][0] = 1;
		dp[i][1] = 1;
	}
	else if (A[i-1]==A[i]){ // A[i] は増加
		dp[i][0] = dp[i-1][0];
		dp[i][1] = dp[i-1][1];
	}
	else if (A[i-1]<A[i]){ // A[i] は増加
		dp[i][0] = min(dp[i-1][0], dp[i-1][1]+1);
		dp[i][1] = min(dp[i-1][0]+1, dp[i-1][1]+1);
	}
	else{ // A[i] は減少
		dp[i][0] = min(dp[i-1][0]+1, dp[i-1][1]+1);
		dp[i][1] = min(dp[i-1][0]+1, dp[i-1][1]);
	}
	return;
}
 
 
int main() {
	// 入力
	ll N;
	cin >> N;
	for (ll i = 0; i < N; ++i) cin >> A[i];
 
	// 解法
	// DP
	memset(dp, -1, sizeof(dp));
	REP(i,N) rec(i);
	// REP(i,N){
	// 	printf("i: %lld, num: %lld, up: %lld, down: %lld\n",
	// 	i, A[i], dp[i][0], dp[i][1]);
	// }
	
	//出力
	cout << min(dp[N-1][0], dp[N-1][1]) << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h> 
using namespace std; 
//#define endl "\n";
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
const long long int mod=pow(10,9)+7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n;
	cin>>n;
    vector<ll> arr(n);
    for(int i=0;i<n;i++)
    	cin>>arr[i];
	ll g=arr[n-1];
	ll ans=0;
	for(int i=n-2;i>=0;i--)
	{
		ans=(ans%mod+((arr[i]%mod)*(g%mod))%mod)%mod;
		g=(g%mod+arr[i]%mod)%mod;
	}
	cout<<ans<<endl;
    return 0;
}


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

int main()
{
  string s;
  cin >> s;
  
  for (int i = 0; i < s.size(); i+=2) {
    if (!(s[i] == 'h' && s[i+1] == 'i') ) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int k;
	cin >> k;
	queue<ll> q;
	rep2(i, 1, 10){
		q.push(i);
	}

	ll ans;
	while(k > 0){
		ans = q.front(); q.pop();
		ll nx = ans*10;
		int bc = ans % 10;
		if(bc > 0) q.push(nx + bc - 1);
		q.push(nx + bc);
		if(bc < 9) q.push(nx + bc + 1);
		k--;
		// cerr << ans << " ";
	}
	// cerr << endl;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main(){
	int n,full=100000;
	cin>>n;
	for(int i=0;i<n;i++){
		full*=1.05;
		if(full%1000!=0){
			full +=1000-(full%1000);
		}
	}
	cout<<full<<endl;
}


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

int main() {
  string s;
  cin >> s;
  if(s=="hi" || s=="hihi" || s=="hihihi" || s=="hihihihi" || s=="hihihihihi"){
    cout << "Yes" << endl; 
  } else {
    cout << "No" << endl; 
  }
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
type Pi = (i32, i32);
fn pri<T: std::fmt::Display>(x: T) {
    println!("{}", x);
}

fn main() {
    input!{
        s: chars,
    }
    let mut ans = 0;
    for i in 1..s.len() {
        if s[i-1] != s[i] {ans += 1;}
    }
    pri(ans);
}

Measured memory_bytes: 4352
#define M 1000000007
char s[100002], t[100002];
int  cnt[128];

int main()
{
	int i, N;

	scanf("%d%s%s", &N, s, t);
	cnt[s[0]] = 1;
	for (N--, i = 1; i < N; i++) {
		cnt[s[i]] += cnt[t[i]];
		if (cnt[s[i]] >= M) cnt[s[i]] -= M;
	}
	printf("%d\n", cnt[t[N]]);
	return 0;
}



Measured memory_bytes: 2104
//
//  main.cpp
//  ATcode131
//
//  Created by didi on 2020/1/16.
//  Copyright © 2020年 didi. All rights reserved.
//

#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cassert>
#include <queue>
#include <list>
using namespace std;

#define ll long long

class Solution {
private:
    vector<int> fa;
    int find(int x) {
        return fa[x] == x ? x : fa[x] = find(fa[x]);
    }
    void merge(int x, int y) {
        int rx = find(x);
        int ry = find(y);
        if (rx != ry) {
            fa[rx] = ry;
        }
    }
    void init(int len) {
        for (int i = 0; i < len; ++i) {
            fa.push_back(i);
        }
    }
public:
    ll solve() {
        int N;
        cin >> N;
        int K = 100000;
        int len = 2 * K + 2;
        init(len);
        
        for (int i = 0; i < N; ++i) {
            int x, y;
            cin >> x >> y;
            merge(x, y + K);
        }
        ll sum = 0;
        vector<int> resx(len);
        vector<int> resy(len);
        for (int i = 1; i <= K; ++i) {
            int r = find(i);
            resx[r]++;
        }
        for (int i = K+1; i < len; ++i) {
            int r = find(i);
            resy[r]++;
        }
        for (int i = 1; i < len; ++i) sum += resx[i] * resy[i];
        return sum - N;
    }
};

int main(int argc, const char * argv[]) {
    Solution obj;
    cout << obj.solve() << endl;
    return 0;
}



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

int main(){
  int n, m, r, INF = 1e9;
  cin >> n >> m >> r;
  vector<int> R(r);
  for(int i = 0; i < r; ++i){
    cin >> R[i];
    --R[i];
  }
  vector< vector<int> > D(n,vector<int>(n,INF));
  int a, b, c;
  for(int i = 0; i < m; ++i){
    cin >> a >> b >> c;
    --a;--b;
    D[a][b] = c;
    D[b][a] = c;
  }
  for(int k = 0; k < n; ++k){
    for(int i = 0; i < n; ++i){
      for(int j = 0; j < n; ++j){
        D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
      }
    }
  }
  sort(R.begin(), R.end());
  int ans = INF;
  do{
    int t = 0;
    for(int i = 1; i < r; ++i) t += D[R[i-1]][R[i]];
    ans = min(ans, t);
  }while(next_permutation(R.begin(), R.end()));
  cout << ans << endl;
  return 0;
}


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


using namespace std;
typedef long long ll;

ll f[2] , g[2];
int n , p , v;
int main(){
	f[0] = 1;
	f[1] = 0;
	scanf("%d%d",&n,&p);
	for (int i = 1;i <= n;i++){
		g[0] = f[0];g[1] = f[1];
		cin >> v;
		f[0] += g[v & 1];
		f[1] += g[(v & 1) ^ 1];
	}
	cout<<f[p];
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		List<Long> list = new ArrayList<>();
		for(int i = 0; i < n; i++) {
			list.add(sc.nextLong());
		}
		Collections.sort(list);
		long ans = 0;
		for(int i = 0; i < n - k; i++) {
			ans += list.get(i);
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 95524
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
A.sort()
count = defaultdict(lambda:0)
for a in A:
    count[a] += 1
dp = [True]*(A[-1]+1)

ans = 0
for a in A:
    if dp[a] and count[a]==1:
        ans += 1
    for i in range(1,len(dp)):
        if a*i>A[-1]:
            break
        dp[a*i] = False

print(ans)

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

using i64 = int_fast64_t;
using f64 = double;

void solve() {
    i64 n, k;
    cin >> n >> k;
    cout << (k == 1 ? 0 : n - k) << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


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

#define REP(i, n) for(int i=0; i<n; i++)
#define REPR(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)

#define INF 2e9
#define ll long long

int main(){
    string s;
    cin>>s;
    int i;
    for(i=1; i<=3; i++){
        if(s[i] == s[i-1]){
            cout<<"Bad"<<endl;
            return 0;
        }
    }
    cout<<"Good"<<endl;
    

    return 0;
}

Measured memory_bytes: 256
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N, K = map(int, input().split())
    P = list(map(int, input().split()))
    P.sort()
    print(sum(P[:K]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 9060
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.concurrent.PriorityBlockingQueue;

public class Main {


    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        long a = sc.nextLong();
        System.out.println(a + a*a + a*a*a);
    }

    private static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte())
                return buffer[ptr++];
            else
                return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr]))
                ptr++;
            return hasNextByte();
        }

        public String next() {
            if (!hasNext())
                throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong() {
            if (!hasNext())
                throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
                throw new NumberFormatException();
            return (int) nl;
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }

}


Measured memory_bytes: 32436
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
struct edge {
    int u, v;
    edge reverse() const { return {v, u}; }
    friend ostream& operator<<(ostream& os, const edge& e) {
        return os << "(" << e.u << ", " << e.v << ")";
    }
};
template <bool Directed, typename TEdge, bool Index> struct graph {
    using EType = TEdge;
    vector<TEdge> edges;
    vector<vector<int>> adj;
    graph(int n) : adj(n + Index) {}
    graph(int n, int m) : graph(n) { edges.reserve(m << not Directed); }
    TEdge& operator()(int e) { return edges[e]; }
    vector<int>& operator[](int u) { return adj[u]; }
    int size() { return adj.size() - Index; }
    void add_edge(const TEdge& e) {
        adj[e.u].push_back(edges.size());
        edges.push_back(e);
        if(not Directed) {
            adj[e.v].push_back(edges.size());
            edges.push_back(e.reverse());
        }
    }
};
template <typename TEdge, bool Index> pair<vector<int>, bool> toposort(graph<1, TEdge, Index>& g) {
    vector<int> indeg(g.adj.size());
    for(int u = Index; u < g.adj.size(); u++) {
        for(int e : g[u]) {
            indeg[g(e).v]++;
        }
    }
    queue<int> q;
    for(int u = Index; u < g.adj.size(); u++) {
        if(indeg[u] == 0) {
            q.push(u);
        }
    }
    vector<int> ans;
    bool has2 = false;
    while(not q.empty()) {
        has2 |= q.size() > 1;
        int u = q.front(); q.pop();
        ans.push_back(u);
        for(int e : g[u]) {
            if(--indeg[g(e).v] == 0) {
                q.push(g(e).v);
            }
        }
    }
    return {ans, has2};
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    graph<1, edge, 1> g(n, m);
    for(int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        g.add_edge({u, v});
    }
    auto ans = toposort(g);
    for(int i : ans.first) {
        cout << i << endl;
    }
    cout << ans.second << endl;
    return 0;
}



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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  string s, t; cin >> s >> t;
  int n = s.size(), m = t.size();
  string ans = "UNRESTORABLE";
  for (int i = n - m; i >= 0; --i) {
    if (not (s[i] == '?' or s[i] == t[0])) { continue; }
    int j = 0;
    string u = s;
    while (i + j < n and j < m and (s[i + j] == t[j] or s[i + j] == '?')) {
      ++j;
    }
    if (j == m) {
      for (int p = 0; p < m; ++p) {
        u[i + p] = t[p];
      }
      for (int p = 0; p < n; ++p) {
        if (u[p] == '?') { u[p] = 'a'; }
      }
      ans = u;
      break;
    }
  }

  printf("%s\n", ans.c_str());
  return 0;
}


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

using namespace std;
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;
typedef unsigned long long int ull;
typedef long long int ll;
#define rep(i,a,b) for (ll i=(a); i<(b); i++)
typedef pair<ll,ll> PLL;
// }}}

signed main() {
    map<ll,ll> mp; // rate max value -> color
    mp.emplace(399,  1);
    mp.emplace(799,  2);
    mp.emplace(1199, 3);
    mp.emplace(1599, 4);
    mp.emplace(1999, 5);
    mp.emplace(2399, 6);
    mp.emplace(2799, 7);
    mp.emplace(3199, 8);

    set<ll> colours;

    ll N, t=0;
    cin>>N;
    rep(i,0,N){
        ll a;
        cin>>a;
        if (a>=3200){
            t++;
        }else{
            auto it = mp.lower_bound(a);
            colours.insert(it->second);
        }
    }
    if (colours.size()==0){
        cout<<1<<" "<<t<<endl;
    }else{
        cout<<colours.size()<<" "<<(colours.size()+t)<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.nextLine();
		String[] list = sc.nextLine().split(" ");
		sc.close();
		int cnt = 0;
		for(int i=0;i<list.length;i++) {
			if(list[i] == null) continue;
			int n = Integer.parseInt(list[i]);
			if(list[n-1] == null) continue;
			if(Integer.parseInt(list[n-1]) == i+1) {
				cnt++;
				list[n-1] = null;
			}
		}
		System.out.print(cnt);
	}
}

Measured memory_bytes: 47628
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 10000007

int main()
{
    ll n;
    cin>>n;
    ll cost[n+1];
    ll dp[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>cost[i];

    }
    dp[n]=0;
   // dp[n-1]=abs(cost[n]-cost[n-1]);

    for(int i=n-1;i>0;i--)
    {
        if((i+2)<=n)
        {dp[i]=min((dp[i+1]+abs(cost[i+1]-cost[i])),(dp[i+2]+abs(cost[i+2]-cost[i])));}
        else
        {
            dp[i]=(dp[i+1]+abs(cost[i+1]-cost[i]));
        }
    }
    //
    cout<<dp[1]<<endl;
}

Measured memory_bytes: 5072
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int INTMAX = 2147483647;
const int INTMIN = -2147483648;
const unsigned int UINTMAX = 4294967295;
const long LONGMAX = 9223372036854775807;
const long LONGMIN = -9223372036854775808;
const unsigned long ULONGMAX = 18446744073709551615;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

bool isprime(int p) {
  if (p==1) return false;
  FOR(i,2,p) {
    if (p%i==0) return false;
  }
  return true;
}

int dig(int n, int a) {return n/(int)pow(10,a)%10;}
int digl(long n, int a) {return n/(long)pow(10,a)%10;}
int digsum(int n) {int r=0;REP(i,10){r+=dig(n,i);}return r;}
int digsuml(long n) {int r=0;REP(i,19){r+=digl(n,i);}return r;}
int dignum(int n) {return n?to_string(n).length():0;}
int dignuml(long n) {return n?to_string(n).length():0;}

int main(){
  string s;
  int k;
  cin >> s >> k;
  REP(i,s.length()-1){
    if(s[i]=='a'){
      cout << 'a';
    } else if (26-alp.find(s[i])<=k) {
      cout << 'a';
      k -= 26-alp.find(s[i]);
    } else {
      cout << s[i];
    }
  }
  cout << alp[(alp.find(s[s.length()-1])+k)%26];
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
//#define int ll
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  int N;
  cin >> N;
  
  set<string> s;
  rep(i, N) {
    string ss;
    cin >> ss;
    if(s.find(ss) == s.end()) {
      s.emplace(ss);
    }
  }
  
  fin(s.size());

}

Measured memory_bytes: 19184
#include <bits/stdc++.h>
#define int long long
using namespace std;
int N;
int m[55];
vector<pair<int,int>> v;
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>N;
    for(int i=0;i<N;i++)cin>>m[i];
    auto p=max_element(m,m+N);
    auto q=min_element(m,m+N);
    if(*p+*q>0){
        if(m[0]>0){
            v.push_back({p-m,0});
            m[0]+=*p;
        }
        v.push_back({p-m,0});
        m[0]+=*p;
        for(int i=1;i<N;i++){
            if(m[i]>=m[i-1])continue;
            if(m[i]<0){
                v.push_back({i-1,i});
                m[i]+=m[i-1];
            }
            v.push_back({i-1,i});
            m[i]+=m[i-1];
        }
    }
    else {
        if(m[N-1]>0){
            v.push_back({q-m,N-1});
            m[N-1]+=*q;
        }
        v.push_back({q-m,N-1});
        m[N-1]+=*q;
        for(int i=N-2;i>=0;i--){
            if(m[i]<=m[i+1])continue;
            if(m[i]>0){
                v.push_back({i+1,i});
                m[i]+=m[i+1];
            }
            v.push_back({i+1,i});
            m[i]+=m[i+1];
        }
    }
    cout<<v.size()<<'\n';
    for(auto p:v)cout<<p.first+1<<' '<<p.second+1<<'\n';
    return 0;
}

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

int main() {
  while(true) {
    int N; cin >> N;
    if(N == 0) break;
    vector<int> sqmod;
    sqmod.reserve(N);
    for(int i = 1; i < N; ++i)
      sqmod.emplace_back((i*i)%N);
    sort(begin(sqmod), end(sqmod));
    sqmod.erase(unique(begin(sqmod), end(sqmod)), end(sqmod));
    vector<int> cnt((N - 1) / 2 + 1, 0);
    for(int i : sqmod) {
      for(int j : sqmod) {
        if(i == j) continue;
        int diff = i - j;
        if(diff < 0) diff += N;
        if(diff > (N - 1)/2) diff = N - diff;
        cnt[diff]++;
      }
    }
    for(int i = 1; i < (int)cnt.size(); ++i) {
      cout << cnt[i] << endl;
    }
  }
}

Measured memory_bytes: 1268
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int letter_to_int(char c) {
  return tolower(c) - 'a';
}

int compare_array(vector<int> a1, vector<int>a2) {
  if (a1.size() != a2.size()) {
    return a1.size() - a2.size();
  }
  for (int i=0; i<a1.size(); i++) {
    if (a1.at(i) != a2.at(i)) {
      return a1.at(i) - a2.at(i);
    }
  }
  return 0;
}

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

char int_to_char(int a) {
  if (a == -1) {
    return 'z';
  }
  else {
    return 'a' + a;
  }
}

long nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

int divide_count(int a, int divider) {
  int r = 0;
  while(a % divider == 0) {
    a /= divider;
    r++;
  }
  return r;
}

bool is_prime(int a) {
  int i = 2;
  while(i * i <= a) {
    if(a % i == 0) {
      return false;
    }
    i++;
  }
  return true;
}

int main() {
  std::cout << std::setprecision(9);
  int a, b, c, k;
  cin >> a >> b >> c >> k;

  int count = 0;
  while(a >= b) {
    b *= 2;
    count++;
  }
  while(b >= c) {
    c *= 2;
    count++;
  }

  if(count <= k) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
int main(void)
{
    string str;
    cin>>str;
    str.resize(4);
    puts(str == "YAKI" ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 256
using System;

namespace AtCoder_ABC089_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');

            int train = int.Parse(s[0]);
            int bus = int.Parse(s[1]);

            int n = train + bus / 2;

            Console.WriteLine(n);
        }
    }
}


Measured memory_bytes: 11092
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#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(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	int n;
	cin >> n;
	vector<int>h(n);
	rep(i, n) {
		cin >> h[i];
	}
	int active = 0;
	int ans = 0;
	rep(i, n) {
		if (h[i] <= active) {
			active = h[i];
		}
		else {
			ans += h[i] - active;
			active = h[i];
		}
	}
	print(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;
const int MAXN = 1005;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int n, m;
int dist[MAXN][MAXN];
char str[MAXN][MAXN];

bool ok(int x, int y){
	return x >=0 && x < n && y >= 0 && y < m;
}

int main(){
	queue<pi> que;
	scanf("%d %d",&n,&m);
	for(int i=0; i<n; i++) scanf("%s", str[i]);
	memset(dist, 0x3f, sizeof(dist));
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			if(str[i][j] == '#'){
				dist[i][j] = 0;
				que.emplace(i, j);
			}
		}
	}
	while(!que.empty()){
		auto x = que.front();
		que.pop();
		for(int i=0; i<4; i++){
			if(ok(x.first + dx[i], x.second + dy[i]) && dist[x.first + dx[i]][x.second + dy[i]] > dist[x.first][x.second] + 1){
				dist[x.first + dx[i]][x.second + dy[i]] = dist[x.first][x.second] + 1;
				que.emplace(x.first + dx[i], x.second + dy[i]);
			}
		}
	}
	int ret = 0;
	for(int i=0; i<n; i++) ret = max(ret, *max_element(dist[i], dist[i] + m));
	cout << ret << endl;
}


Measured memory_bytes: 13328
unittest
{
	assert( [ "2", "10000 JPY", "0.10000000 BTC" ].parse.expand.solve == 48000.0 );
	assert( [ "3", "100000000 JPY", "100.00000000 BTC", "0.00000001 BTC" ].parse.expand.solve == 138000000.0038 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}
auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	auto xs = new real[ n ];
	auto us = new string[ n ];
	foreach( ref x, ref u; lockstep( xs, us ) )
	{
		input.popFront;
		auto t = input.front.split;
		x = t[ 0 ].to!( real );
		u = t[ 1 ];
	}
	return tuple( xs, us );
}

auto solve( real[] xs, string[] us )
{
	const BTC_RATE = 380000.0f;
	
	real ans = 0f;
	
	foreach( x, u; lockstep( xs, us ) )
	{
		switch( u )
		{
			case "JPY": ans += x;            break;
			case "BTC": ans += x * BTC_RATE; break;
			default   : assert( false );
		}
	}
	
	return ans;
}


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

using namespace std;

int main() {
    string s;
    cin >> s;
    int ans;
    if(s == "SUN")
        ans = 7;
    if(s == "MON")
        ans = 6;
    if(s == "TUE")
        ans = 5;
    if(s == "WED")
        ans = 4;
    if(s == "THU")
        ans = 3;
    if(s == "FRI")
        ans = 2;
    if(s == "SAT")
        ans = 1;
    cout << ans;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N, 0);
  rep(i, N) cin >> A.at(i);

  int now = 0;
  ll ans = 0;
  rep(i, N) {
    if (A.at(i) < now) {
      ans += now - A.at(i);
    } else {
      now = A.at(i);
    }
  }

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

Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;

int main() {
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++) cin >> a[i];

	deque<int> que;
	for(int i = 0; i < n; i++)
		if(i % 2)
			que.push_back(a[i]);
		else
			que.push_front(a[i]);

	if(n % 2)
		for(int i = 0; i < n; i++) cout << que[i] << " ";
	else
		for(int i = n - 1; i >= 0; i--) cout << que[i] << " ";
	return 0;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char b; cin>>b;
  if(b=='A') cout<<"T"<<endl;
  if(b=='T') cout<<"A"<<endl;
  if(b=='C') cout<<"G"<<endl;
  if(b=='G') cout<<"C"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
#define SortAsc(c) std::sort(c.begin(), c.end())
#define SortDesc(c) std::sort(c.rbegin(), c.rend())
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};

int main()
{
    string s;
    cin >> s;
    int maxLen = 0;
    int currentLen = 0;

    for (int i = 0; i < s.length(); i++)
    {
        char c = s[i];
        if (c == 'A' || c == 'C' || c == 'G' || c == 'T')
        {
            currentLen++;
        }
        else
        {
            currentLen = 0;
        }

        if (currentLen > maxLen)
        {
            maxLen = currentLen;
        }
    }

    cout << maxLen << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+7;
int a[maxn],ans[maxn];
int n;
int main()
{
   scanf("%d",&n);
   for(int i=1;i<=n;i++){
    scanf("%d",&a[i]);
   }
   int l=1,r=n,k=n,cnt=1;
   for(int i=1;i<=n;i++){
        if(cnt&1)
            ans[l++]=a[k--];
        else
            ans[r--]=a[k--];
        cnt++;
   }
   for(int i=1;i<=n-1;i++)
    printf("%d ",ans[i]);
   printf("%d\n",ans[n]);
}
/*
1 2 3 4
4 2 1 3

0 6 7 6 7 0
0 6 6 0 7 7
*/


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] ABCD = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            long num = Math.Max(ABCD[0], ABCD[2]);
            long bdNum = Math.Min(ABCD[1], ABCD[3]);
            if (num < bdNum)
            {
                Console.WriteLine(bdNum - num);
            }
            else
            {
                Console.WriteLine(0);
            }
        }
    }
}
// 文字列の入力
//string s = Console.ReadLine();

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

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

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


//Console.WriteLine(ans);


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

ll string_to_ll(string s){
    istringstream ss = istringstream(s);
    ll num;
    ss >> num;
    return num;
}

int main() {
    string s; cin >> s;
    int n = s.size() - 1;
    ll ans = 0;

    // {0, 1, ..., n-1} の部分集合の全探索
    for (int bit = 0; bit < (1<<n); ++bit)
    {
        /* bit で表される集合の処理を書く */

        /* きちんとできていることを確認してみる */
        // bit の表す集合を求める


        int fidx = 0;
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) { // i が bit に入るかどうか
                // あるbitのときの処理
                ans += string_to_ll(s.substr(fidx, i - fidx + 1));
                fidx = i+1;
            }
        }
        ans += string_to_ll(s.substr(fidx));

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


Measured memory_bytes: 256
n, t = map(int, input().split())
c_list = []
t_list = []

for i in range(n):
    c1, t1 = map(int, input().split())
    c_list.append(c1)
    t_list.append(t1)

ans = 0
for i in range(n):
    if ans == 0:
        if t_list[i] <= t:
            ans = c_list[i]
    else:
        if t_list[i] <= t and c_list[i] < ans:
            ans = c_list[i]

if ans == 0:
    print("TLE")
else:
    print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define printYes() cout << "Yes" << endl;
#define printNo() cout << "No" << endl;
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  string S, T;
  cin >> S >> T;
  string a_ume = S;
  rep(i, S.size())
  {
    if (a_ume[i] == '?')
      a_ume[i] = 'a';
  }
  for (int i = S.size() - T.size(); 0 <= i; i--)
  {
    string ans = a_ume;
    rep(j, T.size())
    {
      if (S[i + j] == T[j] || S[i + j] == '?')
      {
        ans[i + j] = T[j];
        if (j == T.size() - 1)
        {
          cout << ans << endl;
          return 0;
        }
        continue;
      }
      else
        break;
    }
  }

  cout << "UNRESTORABLE" << endl;
  return 0;
}

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

using namespace std;

int main() {
    while(1) {
        int H, W;

        cin >> H >> W;
        if(H == 0 && W == 0) break;
        
        const string base(W,'#');
        const string side(W-2,'.');

        cout << base << endl;
        for(int i = 1; i < H-1; i++)
            cout << '#' << side << '#' << endl;
        cout << base << endl;
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3164
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args)throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int r = Integer.parseInt(str[0]);
    int d = Integer.parseInt(str[1]);
    int[] x = new int[11];
    x[0] = Integer.parseInt(str[2]);
    
    for(int i=0; i<10; i++) {
      x[i+1] = r * x[i] - d;
      System.out.println(x[i+1]);
    }
  }
}

Measured memory_bytes: 21204
#include <iostream>
using namespace std;
int main() {
	int a,b,k,x,z=0;
	cin>>a>>b>>k;
	int list[k]= {0};
	if (a>=b) {
		x=b;
	} else {
		x=a;
	}
	for(int i=x; i>=1; i--) {
		if (a%i==0&&b%i==0) {
			list[z]=i;
			z++;
		}
	}
	//for (int i=0;i<=k;i++){cout<<list[i]<<" ";}
	cout<<list[k-1];

	return 0;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long a,b,g;
int main(){
    scanf("%lld %lld",&a,&b);
    if(a>b)swap(a,b);
    while(a!=0LL&&b!=0LL){
        b-=(b/a)*a;
        swap(a,b);
    }
    g=a+b;
    int t=1;
    for(long long i=2;i*i<=g;i++){
        if(!(g%i)){
            t++;
            while(!(g%i))g/=i;
        }
    }
    if(g!=1LL)t++;
    printf("%d",t);
}

Measured memory_bytes: 256
#include <cassert>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <set>

using namespace std;

// vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  return s;
}
// 2 dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

typedef long long ll;

struct Range {
  ll l, r;
  Range() {}
  Range(ll l, ll r): l(l), r(r) {}
};

int main() {
  int k;
  cin >> k;
  vector<ll> la(k);
  for (ll &a: la) { cin >> a; }
  Range range = Range(2, 2);
  for (int i = k-1; i >= 0; --i) {
    ll nl = ((range.l-1)/la[i]+1)*la[i];
    ll nr = (range.r/la[i])*la[i]+la[i]-1;
    // cerr << nl << " " << nr << endl;
    if (nl > range.r || nr < range.l) {
      cout << -1 << endl;
      return 0;
    }
    assert(nl < nr);
    range = Range(nl, nr);
  }
  cout << range.l << " " << range.r << endl;
}


Measured memory_bytes: 1024
// Aizu 1149: Cut the Cake
// 2017.9.18 bal4u@uu

#include <stdio.h>
#include <stdlib.h>

typedef struct { int no, w, d, s, f; } CK;
CK cake[110]; int len;

int cmp(CK *a, CK *b) {
	if (b->f - a->f) return b->f - a->f; 
	if (a->no - b->no) return a->no - b->no; 
	return a->s - b->s; 
}
int cmp2(CK *a, CK *b) { return a->s - b->s; }

int main()
{
	int n, w, d, p, s, i;
	CK *c, *n1, *n2;

	while (scanf("%d%d%d", &n, &w, &d) && w) {
		c = cake, c->no = 0, c->w = w, c->d = d, c->s = w*d, c->f = 1, len = 1;
		for (i = 1; i <= n; i++) {
			scanf("%d%d", &p, &s), c = cake + (p-1); n1 = cake + len++, n2 = cake + len++;
			s %= 2*(c->w + c->d);
			if (s < c->w) {
				n1->w =        s, n1->d = c->d;
				n2->w = c->w - s, n2->d = c->d;
				goto Done;
			}
			s -= c->w;
			if (s < c->d) {
				n1->w = c->w, n1->d =        s;
				n2->w = c->w, n2->d = c->d - s;
				goto Done;
			}
			s -= c->d;
			if (s < c->w) {
				n1->w = c->w - s, n1->d = c->d;
				n2->w =        s, n2->d = c->d;
				goto Done;
			}
			s -= c->w;
				n1->w = c->w, n1->d =        s;
				n2->w = c->w, n2->d = c->d - s;

Done:		n1->s = n1->w * n1->d, n1->f = 1;
			n2->s = n2->w * n2->d, n2->f = 1;
			if (n1->s < n2->s) n1->no = 2*i-1, n2->no = 2*i;
			else               n2->no = 2*i,   n1->no = 2*i;
			c->f = 0;
			qsort(cake, len, sizeof(CK), cmp), len--;
		}
		qsort(cake, len, sizeof(CK), cmp2);
		printf("%d", cake[0].s);
		for (i = 1; i < len; i++) printf(" %d", cake[i].s);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1788
n = int(input())
a = [int(i) for i in input().split()]
ans1 = 0
ans2 = 0
summ = 0
summ2 = 0
a2 = a[:]


for i in range(n):
    if i % 2 == 0:
        if summ + a[i] <= 0:
            ans1 += abs(summ + a[i]) + 1
            a[i] = -summ + 1
            summ = 1
        else:
            summ += a[i]
    else:
        if summ + a[i] >= 0:
            ans1 += abs(summ + a[i]) + 1
            a[i] = -summ -1
            summ = -1
        else:
            summ += a[i]
#-+-
for i in range(n):
    if i % 2 != 0:
        if summ2 + a2[i] <= 0:
            ans2 += abs(summ2 + a2[i]) + 1
            a2[i] = -summ2 + 1
            summ2 = 1
        else:
            summ2 += a2[i]
    else:
        if summ2 + a2[i] >= 0:
            ans2 += abs(summ2 + a2[i]) + 1
            a2[i] = -summ2 -1
            summ2 = -1
        else:
            summ2 += a2[i]


print(min(ans1, ans2))


Measured memory_bytes: 14468