akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

vl cnt;
void printRLE(string str) { 
    int n = str.length(); 
    for (int i = 0; i < n; i++) { 
        // Count occurrences of current character 
        ll count = 1; 
        while (i < n - 1 && str[i] == str[i + 1]) { 
            count++; 
            i++; 
        } 
        // Print character and its count 
        cnt.pb(count);
    } 
}

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

    string S; cin >> S;
    printRLE(S);
    ll ans = 0;
    if(S[0] == '<') {
        if(cnt.size() % 2 != 0) cnt.pb(0);
        for(int i = 0; i < cnt.size(); i += 2) {
            ll l = cnt[i];
            ll r = cnt[i+1];
            ll ma = max(l,r);
            ll mi = min(l,r);
            ans += ma * (ma+1) / 2 + (mi-1) * mi / 2;
        }
        cout << ans << endl;
    }else {
        if(cnt.size() %2 == 0) cnt.pb(0);
        ans += cnt[0] * (cnt[0]+1) / 2;
        for(int i = 1; i < cnt.size(); i += 2) {
            ll l = cnt[i];
            ll r = cnt[i+1];
            ll ma = max(l,r);
            ll mi = min(l,r);
            ans += ma * (ma+1) / 2 + (mi-1) * mi / 2;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3864
//                                 Alisher_2211
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        # include <bits/stdc++.h>
# define  long          long long
# define  all(vc)       vc.begin(),vc.end()
# define  allr(vc)      vc.rbegin(),vc.rend()
# define  pb            push_back
# define  fi            first 
# define  se            second
# define  pi            pair <long, long>    
# define  lcm(a, b)     (a * b) / __gcd(a, b)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        using namespace std;
const long N = 100100;
void read(){freopen("input.txt" , "r" , stdin );freopen("output.txt", "w" , stdout );}
long dp[N];
long n, k;
void solve(){
    cin >> n >> k;
    vector <long> v(n + 1);
    for (int i = 1; i <= n; ++i) cin >> v[i];
    for (long i = 2; i <= n; ++i){
        long mn = 1e9;
        for (long j = 1; j <= min(k, i - 1); ++j){
            mn = min(mn, dp[i - j] + abs( v[i] - v[i - j] ));
        }
        dp[i] = mn;
    }
    cout << dp[n];
}
int32_t main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); 
        long T = 1;
        //cin >> T;
        while( T-- ){
            solve();
            cout<<'\n';
        }
cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}

Measured memory_bytes: 4688
import sys
sys.setrecursionlimit(10**5)

# スペース区切りの整数入力
N,M = map(int, input().split())
#指定数分の３つの整数を順番に受けてリストに入力
move = {}
for i in range(M):
    x,y = map(int, input().split())
    move.setdefault(x,[]).append(y)

dp = [-1] * (N+10)

def findpath(now_x):
    if dp[now_x] > -1:
        return dp[now_x]
    maxpath = 0
    if now_x in move.keys():
        for y in move[now_x]:
            maxpath = max(maxpath,findpath(y) + 1)
    dp[now_x] = maxpath
    return maxpath

Ans = 0
for do_x in range(1,N+1):
    Ans = max(Ans,findpath(do_x))

print(Ans)


Measured memory_bytes: 67472
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

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

int x, y, z;
int main(){
    cin >> x >> y >> z;
    int ans = 0;
    x -= z;
    ans += x / (y + z);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
module.exports=function(r){var e={};function t(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return r[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=r,t.c=e,t.d=function(r,e,n){t.o(r,e)||Object.defineProperty(r,e,{enumerable:!0,get:n})},t.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},t.t=function(r,e){if(1&e&&(r=t(r)),8&e)return r;if(4&e&&"object"==typeof r&&r&&r.__esModule)return r;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:r}),2&e&&"string"!=typeof r)for(var o in r)t.d(n,o,function(e){return r[e]}.bind(null,o));return n},t.n=function(r){var e=r&&r.__esModule?function(){return r.default}:function(){return r};return t.d(e,"a",e),e},t.o=function(r,e){return Object.prototype.hasOwnProperty.call(r,e)},t.p="",t(t.s=0)}([function(r,e,t){t(1)(t(2).readFileSync("/dev/stdin","UTF-8").split("\n"))},function(r,e){function t(r,e){return function(r){if(Array.isArray(r))return r}(r)||function(r,e){var t=[],n=!0,o=!1,u=void 0;try{for(var i,f=r[Symbol.iterator]();!(n=(i=f.next()).done)&&(t.push(i.value),!e||t.length!==e);n=!0);}catch(r){o=!0,u=r}finally{try{n||null==f.return||f.return()}finally{if(o)throw u}}return t}(r,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}r.exports=function(r){var e=t(r[0].split(" ").map(function(r){return Number(r)}),2),n=e[0],o=e[1],u=r[1].split(" ").map(function(r){return Number(r)});dp=[];for(var i=0;i<=n;i++){for(var f=[],a=0;a<=n;a++)f.push(new Array(50*n+1).fill(0));dp.push(f)}dp[0][0][0]=1;for(var l=1;l<=n;l++)for(var c=0;c<=n;c++)for(var p=0;p<=50*n;p++){var d=0;d=dp[l-1][c][p],c>0&&p>0&&p>=u[l-1]&&(d+=dp[l-1][c-1][p-u[l-1]]),dp[l][c][p]=d}for(var s=0,v=1;v<=n;v++)s+=dp[n][v][v*o];console.log(s)}},function(r,e){r.exports=require("fs")}]);

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

public class Main {
	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String a = br.readLine();
		String b = br.readLine();
		String c = br.readLine();
		String n = a;

		while (n.length() > 0) {
			if (n.equals(a)) {
				if (a.substring(0, 1).equals("a")) {
					a = a.substring(1);
					n = a;
				} else if (a.substring(0, 1).equals("b")) {
					a = a.substring(1);
					n = b;
				} else if (a.substring(0, 1).equals("c")) {
					a = a.substring(1);
					n = c;
				}
			} else if (n.equals(b)) {
				if (b.substring(0, 1).equals("a")) {
					b = b.substring(1);
					n = a;
				} else if (b.substring(0, 1).equals("b")) {
					b = b.substring(1);
					n = b;
				} else if (b.substring(0, 1).equals("c")) {
					b = b.substring(1);
					n = c;
				}
			} else if (n.equals(c)) {
				if (c.substring(0, 1).equals("a")) {
					c = c.substring(1);
					n = a;
				} else if (c.substring(0, 1).equals("b")) {
					c = c.substring(1);
					n = b;
				} else if (c.substring(0, 1).equals("c")) {
					c = c.substring(1);
					n = c;
				}
			}
		}
		if (n == a) {
			System.out.println("A");
		} else if (n == b) {
			System.out.println("B");
		} else if (n == c) {
			System.out.println("C");
		}
	}
}


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

char str[8][9];

void Rotation(void)
{
	int i, j, k, l;
	char str2[8][9];
	
	for (i = 0; i < 8; i++){
		strcpy(str2[i], str[i]);
	}
	
	for (i = 0, k = 7; i < 8; i++, k--){
		for (j = 0, l = 0; j < 8; j++, l++){
			str[l][k] = str2[i][j];
		}
	}
}

int main(void)
{
	int i, j;
	
	for (i = 0; i < 8; i++){
		scanf("%s", str[i]);
	}
	
	for (i = 0; i < 3; i++){
		printf("%d\n", (i + 1) * 90);
		Rotation();
		
		for (j = 0; j < 8; j++){
			printf("%s\n", str[j]);
		}
	}
	
	return (0);
}

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

int minn, ans;
int n;
vector<int> ve;

int main(void) {
    cin >> n;
    while (n --){
        int a;
        cin >> a;
        ve.push_back(a);
    }
    for (int i = 0; i < ve.size(); i ++) {
        if (i == 0) {
            minn = ve[i];
        }
        else {
            if (i == 1) {
                ans = ve[i] - minn;
                if (ve[i] < minn) minn = ve[i];
            }
            else {
                if (ve[i] - minn > ans) ans = ve[i] - minn;
                if (ve[i] < minn) minn = ve[i];
            }
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3944
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t s, w;
    cin >> s >> w;
    string res = w >= s ? "unsafe" : "safe";
    cout << res << endl;
}


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

int main(){
  long long h, w, ans;
  cin >> h >> w;
  ans = (h * w) / 2;
  if(h == 1 || w == 1)
    ans = 1;
  else if(h % 2 == 1 && w % 2 == 1)
    ans++;
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
using namespace std;

int main(void){
       char s[10];
       scanf("%s",s);
       if(s[1] == 'B'){
                printf("ARC\n");
       } else {
               printf("ABC\n");
       }
       return 0;

       
}



Measured memory_bytes: 1660
local n = io.read("*n")
local a, b = {}, {}
for i = 1, n do
  a[i] = 30000 * i
  b[i] = 30000 * (n + 1 - i)
end
for i = 1, n do
  local p = io.read("*n")
  a[p] = a[p] + i
end
print(table.concat(a, " "))
print(table.concat(b, " "))


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 3010

template <typename T> T gcd(T a, T b) { while (a) { b %= a; swap(a, b); } return b; }
template <typename T> T lcm(T a, T b) { return a / gcd(a,b) * b; }

int N;
int A[MAX_N];

signed main()
{
    cin >> N;
    int val = 1;
    REP(i, N) {
        cin >> A[i];
        val = lcm(val, A[i]);
    }
    val--;

    int ans = 0;
    REP(i, N) {
        //ans += val % A[i];
        ans += A[i]-1;
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

int numOfDigits(ll n) {int num = 0; while (n > 0) {n /= 10; ++num;} return num;}

int main() {
ll N, M; cin >> N;
int mini = 1e9, F;

for (ll a = 1; a <= sqrtl(N); ++a){
	if (N%a == 0){
		M = max(a, N/a);
		F = numOfDigits(M);
		mini = min(mini, F);
	}
}
cout << mini << "\n";

return 0;
}

// 境界のチェック


Measured memory_bytes: 256
coin_list = sorted([1] + [ 6**i for i in range(1,7) ] + [ 9**i for i in range(1,6) ])

num_list = [ i for i in range(10**5+1) ]

for i in range(1,10**5+1):
    candidate = [ num_list[i-j] for j in coin_list if j <= i ]
    num_list[i] = min(candidate) + 1

n = int(input())
print(num_list[n])

Measured memory_bytes: 44784
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(n) (n).begin(),(n).end()
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
	string s;
	cin >> s;
	if(s[2]==s[3] &&s[4]==s[5]){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);

int main(){
    cin>>N;
    vec two(N, 0), five(N, 0);
    ll res = 0;
    rep(i,N){
        long double c;
        cin>>c;
        c *= 1e+9;
        A = ll(c + 0.5);
        //cout<<A<<endl;
        if(A%(ll(1e+9)) == 0) --res;
        while(A%2 == 0) {
            ++two[i];
            A /= 2;
        }
        while(A%5 == 0){
            ++five[i];
            A /= 5;
        }
    }
    mat sum(20, vec(20, 0));
    rep(i, N){
        ++sum[min((ll)19, two[i])][min((ll)19, five[i])];
    }
    Rrep(i, 20){
        Rrep(j, 20){
            if(i + 1 < 20) sum[i][j] += sum[i+1][j];
            if(j + 1 < 20) sum[i][j] += sum[i][j+1];
            if(i + 1 < 20 && j + 1 < 20) sum[i][j] -= sum[i+1][j+1];
        }
    }
    /*
    rep(i,20){
        rep(j, 20) cout<<sum[i][j]<<' ';
        cout<<endl;
    }
    cout<<res<<endl;
     */
    rep(i,N){
        ll num = sum[18 - min((ll)18, two[i])][18 - min((ll)18, five[i])];
        res += num;
    }
    //cout<<res<<endl;
    res /= 2;
    cout<<res<<endl;
}


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

using namespace std;

int main(){
    int n;
    while(cin >> n && n){
        vector<int> p(n);
        for(auto&& i : p){
            cin >> i;
        }
        vector<int> j(n - 1);
        for(auto&& i : j){
            cin >> i;
        }
        long long sumsize = accumulate(begin(p), end(p), 0);
        long long ans = sumsize * n;
        sort(rbegin(j), rend(j));
        for(int i = 0; i < n - 1; i++){
            sumsize += j[i];
            ans = max(ans, sumsize * (n - 1 - i));
        }
        cout << ans << "\n";
    }
}


Measured memory_bytes: 3384
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
string alphabet = "abcdefghijklmnopqrstuvwxyz";
string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
  int n;
  cin >> n;
  int k = n / 500;
  int l = (n - k * 500) / 5;
  cout << k * 1000 + l * 5 << endl;
}



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

int p2(int a){
	int ret=0;
	while(a%2==0){ret++;a/=2;}
	return ret;
}
int p5(int a){
	int ret=0;
	while(a%5==0){ret++;a/=5;}
	return ret;
}

int main(){
	int n;
	while(cin >> n && n){
		int t=0,f=0;
		for(int i=2;i<=n;i++){
			t+=p2(i);	
			f+=p5(i);
		}
		cout << min(t,f) << endl;
	}
}

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

using ll = long long;
using namespace std;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;
int N,M,Q;
int a[100],b[100],c[100],d[100];

vector<int> x;
int ans(0);
void dfs(int now,int cnt){
  if(now != 0){
    x.push_back(now);
  }
  if(cnt == N){
    //for(int i(0);i<cnt;i++){
      //cout << x[i] << " ";
    //}
    int tmp(0);
    for(int i(0);i<Q;i++){
      if(x[b[i]-1] - x[a[i]-1] == c[i]){
        tmp += d[i];
      }
    }
    //cout << tmp;
    //cout << endl;
    ans = max(ans,tmp);
  }else{
    for(int i(max(1,now));i<=M;i++){
      dfs(i,cnt+1);
    }
  }
  x.pop_back();
}

int main(){
  cin>>N>>M>>Q;
  for(int i(0);i<Q;i++){
    cin>>a[i]>>b[i]>>c[i]>>d[i];
  }
  dfs(0,0);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3600
package main

import (
	"fmt"
	"math"
)

func main() {
	var n, tmp, count int
	fmt.Scan(&n)

	for i := 0; i < n; i++ {
		fmt.Scan(&tmp)
		if isPrime(tmp) {
			count++
		}
	}

	fmt.Println(count)
}

func isPrime(n int) bool {
	if n == 2 {
		return true
	}

	if n <= 1 || n%2 == 0 {
		return false
	}

	for i := 3; i <= int(math.Sqrt(float64(n))); i += 2 {
		if n%i == 0 {
			return false
		}
	}

	return true
}

Measured memory_bytes: 1652
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e15;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    bool ans = true;
    if(s[0] == '0') ans = false;
    if(s[n - 1] == '1') ans = false;
    rep(i, 0, n / 2){
        if(s[i] != s[n - 2 - i]) ans = false;
    }
    if(!ans){
        cout << -1 << endl;
        return 0;
    }
    vector<P> g;
    int now = 0, pr = 0;
    rep(i, 0, n / 2){
        if(s[i] == '1'){
            now++;
            g.push_back({pr, now});
            pr = now;
        }else{
            now++;
            g.push_back({now, pr});
        }
    }
    int root = pr;
    for(int i = 0; i < (n - 1) / 2; i++){
        g.push_back({n - 1 - i, root});
    }
    for(int ii = 0; ii < g.size(); ii++){
        cout << g[ii].first + 1 << ' ' << g[ii].second + 1 << endl;
    }
}

Measured memory_bytes: 3264
#include<stdio.h>
#include<string.h>
typedef struct item{
	char n[105];
	int p,f,k,m[105];
}ITEM;
ITEM d[105];
int func(int n){
	int sp=0,i;
	if(d[n].f==0)return d[n].p;
	else{
		for(i=0;i<d[n].k;i++){
			sp+=func(d[n].m[i]);
		}
		if(sp<d[n].p)d[n].p=sp;
		return d[n].p;
	}
}
int main(){
	FILE *fp;
	//fp=fopen("test.txt","r");
	fp=stdin;
	int n,m,i,j,k,x,y,f,p;
	char s[105];
	while(1){
		fscanf(fp,"%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++){
			fscanf(fp,"%s%d",d[i].n,&d[i].p);
			d[i].f=d[i].k=0;
		}
		fscanf(fp,"%d",&m);
		for(i=0;i<m;i++){
			fscanf(fp,"%s%d",s,&x);
			for(j=0;j<n;j++){
				if(strcmp(d[j].n,s)==0){
					y=j;
					d[y].f=1;
					d[y].k=x;
					break;
				}
			}
			f=p=0;
			for(j=0;j<x;j++){
				fscanf(fp,"%s",s);
				for(k=0;k<n;k++){
					if(strcmp(d[k].n,s)==0){
						d[y].m[j]=k;
						//p+=d[k].p;
						//if(d[k].f==1)f=1;
						break;
					}
				}
			}
			//if(f==0 && d[y].p>p)d[y].p=p,d[y].f=0;
		}
		/*while(1){
			f=0;
			for(i=0;i<n;i++){
				if(d[i].f==1){
					x=p=0;
					for(j=0;j<d[i].k;j++){
						p+=d[ d[i].m[j] ].p;
						if(d[ d[i].m[j] ].f==1)x=1;
					}
					if(x==0)f=1;
				}
				
			}
			if(f==0)break;
		}*/
		fscanf(fp,"%s",s);
		for(i=0;i<n;i++){
			if(strcmp(d[i].n,s)==0){printf("%d\n",func(i));break;}
		}
		/*for(i=0;i<n;i++){
			printf("%2d:%s %d %d\n",i,d[i].n,d[i].p,d[i].f);
			printf("   ");for(j=0;j<d[i].k;j++)printf("%d ",d[i].m[j]);
			printf("\n");
		}*/
	}
	return 0;
}

Measured memory_bytes: 0
from collections import Counter

N = int(input())
A = Counter([int(_) for _ in input().split()])
Q = int(input())

operates = [tuple(map(int, input().split())) for _ in range(Q)]
result = 0
for k, n in A.items():
  result += k * n

for b, c in operates:
  n_b = A.get(b, 0)
  if n_b > 0:
    A[b] = 0
    A[c] += n_b
    result -= b * n_b
    result += c * n_b
  print(result)

Measured memory_bytes: 28604
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N;
  cin>>N;
  
  vector<long long> L(87);
  L[0]=2;
  L[1]=1;
  for(int i=2;i<87;i++){
    L[i]=L[i-1]+L[i-2];
  }
  
  cout<<L[N]<<endl;
}

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

using namespace std;

typedef long long ll;


int main(){
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,k;
	cin>>n>>k;
	int h[n];
	ll dp[n];
	for (int i = 0; i < n; ++i)
	{
		/* code */
		cin>>h[i];
	}
	dp[0]=0;
	dp[1]=abs(h[1]-h[0]);
	for(int i=2;i<n;i++){
		ll temp=1e15,j=1;
		while(j<=k && (i-j)>=0){
			temp=min(temp, abs(h[i]-h[i-j]) + dp[i-j]);
			j++;
		}
		dp[i]=temp;
	}
	cout<<dp[n-1]<<'\n';
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	string s; cin >> s;
	for (int i = 0; i < s.size();){
		if (s[i] == 'd'&&s[i + 1] == 'r'&&s[i + 2] == 'e'&&s[i + 3] == 'a'&&s[i + 4] == 'm') {
			i += 5;
			if (s[i] == 'e'&&s[i + 1] == 'r') {
				if (s[i + 2] == 'a'&&s[i + 3] == 's'&&s[i + 4] == 'e') {
					i += 5;
					if (s[i] == 'r')i++;
				}
				else i += 2;
			}
		}
		else if (s[i] == 'e'&&s[i + 1] == 'r'&&s[i + 2] == 'a'&&s[i + 3] == 's'&&s[i + 4] == 'e') {
			i += 5;
			if (s[i] == 'r')i++;
		}
		else{
			cout << "NO\n";
			char c; cin >> c; return 0;
		}
	}
	cout << "YES\n";
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
    int n, w;
    cin >> n >> w;
    pair<long long, long long> arr [n];
    for (int i = 0 ; i < n; ++i) 
    {
        int a, b;
        cin >> a >> b;
        arr[i] = make_pair(a, b);
    }
    long long dp [n + 1][w + 1];
    for (int i = 0; i <= n; ++i)
    {
        dp[i][0] = 0;
    }
    for (int i = 0; i <= w; ++i)
    {
        dp[0][i] = 0;
    }
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= w; ++j)
        {
            if (j - arr[i - 1].first >= 0) {
                dp[i][j] = max(arr[i - 1].second + dp[i - 1][j - arr[i - 1].first], dp[i - 1][j]);
            } else {
                dp[i][j] = dp[i - 1][j];
            }
        }
    }
    // long long val = 0;
    // for (int i = 0; i < n + 1; ++i) {
    //     for (int j = 0; j <= w; ++j)
    //     {
    //         val = max(val, dp[i][j]);
    //         cout << dp[i][j] << "\t";
    //     }
    //     cout << endl;
    // }
    cout << dp[n][w] << endl;
    return 0;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, a, b, c);
  print(b - a == c - b ? "YES" : "NO");
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    long long a,b,k;
    long long i=0;
    scanf("%lld %lld %lld",&a,&b,&k);
    
    if(a>=k)
    {
        printf("%lld %lld",a-k,b);
    }
    else if(a<=k && (a+b)>=k)
    {
        printf("0 %lld",b-(k-a));
    }
    else printf("0 0");
}


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


int main(){
    int i=1;
    while(1){
        int x;
        cin >> x;

        if(x==0) break;

        cout << "Case " << i << ": " << x << endl;
        ++i;
    }
}



Measured memory_bytes: 3056
#include<stdio.h>

#define MAX 100000

int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i + 1;
}

int main(){
  int i,p,l,r,H;
  int A[MAX];

    scanf("%d", &H);

  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }
  for(i=1;i<=H;i++){
    printf("node %d:",i);
    printf(" key = %d,",A[i]);
    p=parent(i);
    if(i!=1)printf(" parent key = %d,",A[p]);
    l=left(i);
    r=right(i);
    if(l<=H)printf(" left key = %d,",A[l]);
    if(r<=H)printf(" right key = %d,",A[r]);
    printf(" \n");

  }

  return 0;
}



Measured memory_bytes: 2108
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
#include<stdio.h>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

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

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}

int main(){
    int N;
    cin >> N;
    int p[N];
    REP(i,N) cin >> p[i];
    int num=0;
    for(int i=0;i<N;++i){
        if(p[i]!=i+1){
            ++num;
        }
    }
    if(num>2) cout << "NO";
    else cout << "YES";
    }

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define rep(i,j,k) for (i=j;i<=k;i++)
using namespace std;
const int N=1e5+5;
int n,i,l,r,x,y,f,bn,son[N],fs[N],bro[N],fa[N],q[N],b[N],g[N];
void add(int x,int y) {
	bro[y]=fs[x]; fs[x]=y;
}
int main()
{
//	freopen("tournament.in","r",stdin);
//	freopen("tournament.out","w",stdout);
	scanf("%d",&n);
	rep(i,2,n) scanf("%d",&fa[i]),son[fa[i]]++,add(fa[i],i);
	rep(i,1,n) if (!son[i]) q[++r]=i;
	for (l=1;l<=r;l++)
	{
		x=q[l];
		if (fs[x]) {
			for (y=fs[x],bn=0;y;y=bro[y]) b[++bn]=g[y];
			sort(b+1,b+1+bn);
			rep(i,1,bn) g[x]=max(g[x],b[i])+1;
		}
		if (x==1) break;
		f=fa[x]; son[f]--; if (!son[f]) q[++r]=f;
	}
	printf("%d\n",g[1]);	
	return 0;
}

Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
  static void Main(){
    var n = int.Parse(Console.ReadLine());
    var dic = new Dictionary<string,int>(n);
    int max = 0, max2 = 0, diccnt=0;
    var maxword = "";
    for(int c=n; c>=max-max2 && c>0; c--){
      string input = Console.ReadLine();
      int count;
      if(dic.ContainsKey(input)){
        count = ++dic[input];
      }else{
        dic.Add(input, 1);
        count=1;
        diccnt++;
      }
      if(count>max){
        if(input!=maxword){
          max2 = max;
          maxword=input;
        }
        max = count;
      }else if (count>max2){
        max2 = count;
      }
      //Console.WriteLine($"{input} max:{max},max2:{max2},c:{c}");
    }
    var ss = new string[diccnt];
    int ii=0;
    foreach(var xx in dic){
      if(xx.Value==max) ss[ii++] = xx.Key;
    }
    var sss = new string[ii];
    for(int i=0;i<ii;i++){
      sss[i]=ss[i];
    }
    Array.Sort(sss, StringComparer.Ordinal);
    foreach(var word in sss){
      Console.WriteLine(word);
    }
  }
}

Measured memory_bytes: 35660
n,m=map(int,input().split())
ans=0
head=1
from operator import itemgetter as it
for x,y in sorted([list(map(int,input().split()))for i in range(m)],reverse=0,key=lambda x:(it(1)(x)*(n+1)*10-it(0)(x))):
    if not(x<head <=y):
        head=y
        ans+=1
print(ans)

Measured memory_bytes: 32724
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <tuple>

using namespace std;


int counting(int N_H, int N_W, vector< vector<int> > &Graph, queue< pair<int, int> > &PaintingPos)
{
    /*
    PaintingPosは黒色の座標, Graph[y][x] = 1
    */
    int count = 0;
    pair<int, int> pos_y_x;
    queue< pair<int, int> > PaintingPos_new;
    int x, y;
    pair<int, int> dy_dx[4] = { make_pair(-1, 0), make_pair(1, 0), make_pair(0, 1), make_pair(0, -1) };
    while( PaintingPos.size() >0 || PaintingPos_new.size()>0 )
    {
        // cout << "SIZE* " << PaintingPos.size() << "  " << PaintingPos_new.size() << endl;
        while( PaintingPos.size()>0 )
        {
            pos_y_x = PaintingPos.front(); PaintingPos.pop();
            for(int i=0; i<4; i++)
            {
                y = pos_y_x.first + dy_dx[i].first, x = pos_y_x.second + dy_dx[i].second;
                if(x <0 || x>= N_W || y<0 || y>= N_H || Graph[y][x] == 1) continue;
                Graph[y][x] = 1;
                PaintingPos_new.push(make_pair(y, x) );
            }
        }
        count++;
        swap( PaintingPos, PaintingPos_new );
    }

    return count-1; // 1回分多く数えている
}



int main(void)
{
    /*
    ARC 037 B バウムテスト
    https://atcoder.jp/contests/arc037/tasks/arc037_b
    */
    int N_H, N_W;
    cin >> N_H >> N_W;

    vector< vector<int> > Graph(N_H, vector<int>(N_W) );
    queue< pair<int, int> > PaintingPos; // height, width

    char color; // black -> #, 1. white->., 0で
    for(int i=0; i<N_H; i++)
    {
        for(int j=0; j<N_W; j++)
        {
            cin >> color;
            if(color == '#')
            {
                Graph[i][j] = 1;
                PaintingPos.push(make_pair(i, j) );
            }
        }
    }

    if(PaintingPos.size() == 0)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << counting(N_H, N_W, Graph, PaintingPos) << endl;
    }


    return 0;
}


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

int main() {
  int num;
  cin >> num;
  bool y = false;
  
  for (int i=0; i<num; i++){
    char s;
    cin >> s;
    
    if (s == 'Y'){
      y = true;
      break;
    }
    else{
      continue;
    }
  }
  
  if (y == true){
    cout << "Four" <<endl;
    }
  else{
    cout << "Three" <<endl;
  } 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int main(void) {
	int n,K; cin >> n >> K;
	vi d(K); rep(i,K) cin >> d[i];
	rep(i,100000){
		if(i<n) continue;
		vi a;
		int ni = i;
		while(ni){
			a.push_back(ni%10);
			ni /= 10;
		}
		bool flg = true;
		rep(j,a.size()){
			rep(k,K){
				if(a[j]==d[k]) flg = false;
			}
		}
		if(flg){
			cout << i << endl;
			break;
		}
	}
}




Measured memory_bytes: 256
d,n=map(int,input().split())

if n!= 100:
    if d==0:
        print(n)
    elif d==1:
        print(n*100)
    elif d==2:
        print(n*10000)
else:
    if d==0:
        print(101)
    elif d==1:
        print(10100)
    elif d==2:
        print(1010000)

Measured memory_bytes: 3064
///   ***   ---   |||         In the name of ALLAH        |||   ---   ***   ///



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


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define endl '\n'
#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define mod 1000000007

#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

ll gcd ( ll a, ll b ) { return __gcd ( a, b ); }
ll lcm ( ll a, ll b ) { return a * ( b / gcd ( a, b ) ); }


main()
{
    optimize();
ll n,t=0,c,y=0,i,p;
cin>>n;

for(i=1;i<=n;i++)
{
    cin>>c;
    t=t+c;
    if(c>y)
        y=c;
    //v.PB({c,y});
}
p=y/2;
t=t-y+p;
cout<<t<<endl;
















    return 0;
}












































Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <unordered_set>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
static const int INF = 1000010000;
static const int NIL = -1;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.begin(), v.end(), greater<int>);
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue
 
int gcd(int a, int b) { int c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
int lcm(int a, int b) { int c = gcd(a, b); a /= c; return a*b; }
int nCr(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
int pow(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llpow(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llgcd(long long a, long long b) { long long c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
long long lllcm(long long a, long long b) { long long c = llgcd(a, b); a /= c; return a*b; }
long long llnCr(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
 
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge{
    int to, cost;
};


// dijikstra
/* int V;
vector<edge> G[10];
int d[10];

void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d, d + V + 1, INF);
    d[s] = 0;
    que.push(P(0, s));

    while(!que.empty()){
        P p = que.top(); que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        REP(i, G[v].size()){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}
*/

int main(){
    ll n, m;
    cin >> n >> m;
    if(n + 1 < m || n - 1 > m){
        cout << 0 << endl;
        return 0;
    }
    if(n == m){
        ll ans = 2;
        for(ll i = n; i > 0; --i){
            ans = ans * i % MOD;
            ans = ans * i % MOD;
        }
        cout << ans << endl;
    }else{
        ll ans = 1;
        for(ll i = max(m, n); i > 0; --i){
            if(i == max(m, n)){
                ans = ans * i % MOD;
            }else{
                ans = ans * i % MOD;
                ans = ans * i % MOD;
            }
        }
        cout << ans << endl;        
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    ll A, B, N; cin >> A >> B >> N;
    // REP(i, 0, max(B, N) + 1) cout << "i : " << i << " " << (A * i / B) - A * (i / B) << endl;

    ll b = min(B - 1, N);
    // cout << "b : " << b << endl;
    cout << (A * b / B) - A * (b / B) << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <limits>
#define rep(i,a) for(int i=0;i<(a);++i)

struct edge
{ 
  int to, cap, rev; 

  edge( int to, int cap, int rev )
  : to(to), cap(cap), rev(rev)
  {}
};

int V, E;
std::vector<std::vector<edge> > G;
bool used[100];

void addEdge( int from, int to, int cap )
{
  G[from].push_back( edge( to, cap, G[to].size() ) );
  G[to].push_back( edge( from, 0, G[from].size()-1 ) );

  return;
}

int dfs( int v, int t, int f )
{
  if( v == t )
    return f;

  used[v] = true;

  rep( i, G[v].size() )
  {
    edge &e = G[v][i];

    if( !used[e.to] && e.cap > 0 )
    {
      int resF = dfs( e.to, t, std::min( f, e.cap ) );

      if( resF > 0 )
      {
        e.cap -= resF;
        G[e.to][e.rev].cap += resF;
        
        return resF;
      }
    }
  }

  return 0;
}

int maxFlow( int s, int t )
{
  int f = 0;

  while( true )
  {
    memset( used, false, sizeof(used) );

    int resF = dfs( s, t, std::numeric_limits<int>::max()>>2 );

    f += resF;

    if( resF == 0 )
      break;
  }

  return f;
}

int main()
{
  scanf( "%d%d", &V, &E );

  G.resize(V);

  rep( i, E )
  {
    int u, v, c;
    scanf( "%d%d%d", &u, &v, &c );
    addEdge( u, v, c );
  }

  printf( "%d\n", maxFlow( 0, V-1 ) );

  return 0;
}

Measured memory_bytes: 2784
#include<iostream>
#include<vector>
using namespace std;
using ll = long long;

int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    
    ll ans=1000,c=0;
    for(int i=0;i<n-1;i++){
        if(a[i]<a[i+1]){
            c+=ans/a[i];
            ans%=a[i];
        }else if(a[i]>a[i+1]){
            ans+=c*a[i];
            c=0;
        }
    }
    ans+=c*a[n-1];
    cout<<ans<<endl;
}

Measured memory_bytes: 3628
S1 = input()
T = input()

S1_r = S1[::-1]
T_r = T[::-1]
if len(S1) < len(T):
    print("UNRESTORABLE")
else:    
    for i in range(len(S1)-len(T)+1):
        flag1 = True
        flag2 = True
        for s,t in zip(S1_r[i:i+len(T)],T_r):
            if s == "?" or s == t:
                pass
            else:
                flag1 = False 
                break
        if flag1:
            flag2 = False
            S1_r = S1_r.replace(S1_r[i:i+len(T)],T_r,1)
            S_r = ["a" if s1 == "?" else s1 for s1 in S1_r]
            print("".join(S_r[::-1]))
            break
    if flag2:
        print("UNRESTORABLE")

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
int main(){
  char x[20];
  char y[20];
  int i,j=0;
  scanf("%s", x);
  for(i=0;i<strlen(x);i++){
    if(x[i]>='A'&&x[i]<='Z'){
      y[j]=x[i];
      j++;
    }
  }
  if(x[0]=='A'&&j==2&&y[1]=='C'&&x[strlen(x)-1]!='C'&&x[1]!='C'){
    printf("AC\n");
  }
  else{
    printf("WA\n");
  }
  return 0;
}


Measured memory_bytes: 128
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
 
public class Main {
	public static void main(String[] args) throws Exception {
		FastScanner sc = new FastScanner();
		int a = sc.nextInt();
		int cnt= 0;
		int b = sc.nextInt();
		for(int i=a; i <= b; i++) {
			String s = ""+i;
			String rev = new StringBuffer(s).reverse().toString();
			if(rev.equals(s)) ++cnt;
		}
		System.out.println(cnt);
	}
	static class FastScanner {
		public BufferedReader reader;
		public StringTokenizer tokenizer;
 
		public FastScanner() {
			reader = new BufferedReader(new InputStreamReader(System.in), 32768);
			tokenizer = null;
		}
 
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
 
		public int nextInt() {
			return Integer.parseInt(next());
		}
 
		public long nextLong() {
			return Long.parseLong(next());
		}
 
		public double nextDouble() {
			return Double.parseDouble(next());
		}
 
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
 
	}
}

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

int main() {
	long long n,i,a[10000],j,k,sum,ans=0;
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	for(i=0;i<n-2;i++) {
		for(j=i+1;j<n-1;j++) {
			sum=a[i]+a[j];
			for(k=j+1;k<n;k++) {
				if(a[k]>=sum) break;
				ans++;
			}
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  string A, B, C;
  cin >> A >> B >> C;
  char X, Y, Z;
  int o = 'A' - 'a';
  X = A.at(0) + o;
  Y = B.at(0) + o;
  Z = C.at(0) + o;
  cout << X << Y << Z << endl;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(x) __builtin_ctz(x)

// #define DEBUG

#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif

using namespace std;
using ll=long long;

const int nmax=3010;
using node=struct{int to,cost;};
vector<node> graph[nmax];

const int inf=1<<28;
using tii=tuple<int,int>;
int dist[nmax];

int main(void){
	int n,m,k;
	cin >> n >> m >> k;
	rep(i,n) dist[i]=inf;
	
	rep(i,m){
		int a,b,c;
		cin >> a >> b >> c;
		graph[a-1].push_back({b-1,c});
		graph[b-1].push_back({a-1,c});
	}


	priority_queue<tii,vector<tii>,greater<tii>> q;
	rep(loop,k){
		int v;
		cin >> v;
		dist[v-1]=0;
		q.push(tii(0,v-1));
	}

	while(!q.empty()){
		int v,cost;
		tie(cost,v)=q.top();q.pop();
		for(auto &e:graph[v]){
			int nv=e.to,ncost=cost+e.cost;
			if(dist[nv]>ncost){
				dist[nv]=ncost;
				q.push(tii(ncost,nv));
			}
		}
	}

	int ans=0;
	rep(i,n){
		ans=max(ans,dist[i]);
		for(auto &e:graph[i]){
			int a=i,b=e.to,l=e.cost;
			if(dist[a]>dist[b]) continue;
			if(dist[a]+l<=dist[b]) continue;
			if(dist[b]+l<=dist[a]) continue;
			int add=(l+(dist[b]-dist[a])+1)/2;
			ans=max(ans,dist[a]+add);
		}
	}
	//  dist[a]+a=dist[b]+b (a+b)==l 
	//        a-b=dist[b]-dist[a] (a+b)==l 
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5944
#include<iostream>

using namespace std;

int main()
{
    int a;
    cin>>a;
    if(a % 10 == 9)
    {
        cout<<"Yes"<<endl;
        return 0;
    }
    else if(a / 10 == 9)
    {
        cout<<"Yes"<<endl;
        return 0;
    }
    else
    {
        cout<<"No"<<endl;
        return 0;
    }
}


Measured memory_bytes: 3640
import numpy as np
N = int(input())
c = np.zeros((10, 10), dtype='int')

for k in range(1, N + 1):
    k = str(k)
    i, j = int(k[0]), int(k[-1])
    c[i, j] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += c[i, j] * c[j, i]
print(ans)


Measured memory_bytes: 12496
N = int(input())
A = [int(x) - 1 for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
cnt = 0
for i in range(N):
  cnt += B[A[i]]
for i in range(N - 1):
  if A[i] + 1 == A[i + 1]:
    cnt += C[A[i]]
print(cnt)

Measured memory_bytes: 3064