akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(V) (V).begin(), (V).end() 
#define x first
#define y second
using namespace std;
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cout << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}

using namespace std;

typedef long long ll;
template <typename T> using V = vector <T>;

int main() {fio;
	int N;
	double p;
	cin >> N;

	V <double> P(N + 1);
	P[0] = 1;
	for(int i = 0; i < N; i++) {
		auto las = P; 
		fill(all(P), 0);
		cin >> p;
		for(int i = 0; i <= N; i++) {
			if(i) {
				P[i] += las[i - 1] * p;
			}
			P[i] += las[i] * (1 - p);
		}
	}
	double ans = 0;
	for(int i = 0; i <= N; i++) {
		if(i > N - i) {
			ans += P[i];
		}  
	}
	cout << fixed << setprecision(10) << ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb emplace_back
#define mp make_pair
#define MOD 1000000007
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL))
int main()
{
     ll a,b;
     cin>>a>>b;
     b = 2*b;
     cout<<max(0LL,a-b);
}

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

int main() {
    int k;
    char s[300];
    
    scanf("%d", &k);
    scanf("%s", s);

    if (strlen(s) > k) {
        for (int i = 0; i < k; ++i)
            printf("%c", s[i]);
        printf("...\n");
    } else
        printf("%s\n", s);
    
    return 0;
}


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

int main() {
    string S, T;
    cin >> S >> T;
    int N = S.length();

    map<char, char> pair;
    for (int i = 0; i < N; i++) {
        if (pair[T[i]] == NULL) {
            pair[T[i]] = S[i];
        } else if (pair[T[i]] != S[i]) {
            cout << "No" << endl;
            return 0;
        }
    }

    map<char, int> check;
    for (auto c : pair) {
        check[c.second]++;
        if (check[c.second] >= 2) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 3900
n=int(input())
d=dict()
for i in map(int,input().split()):
  if i not in d:
    d[i]=1
  else:
    d[i]+=1
  if i-1 not in d:
    d[i-1]=1
  else:
    d[i-1]+=1
  if i+1 not in d:
    d[i+1]=1
  else:
    d[i+1]+=1
print(max(d.values()))

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

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<ll>size;
 
    UnionFind(int N){ //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) {
        	par.push_back(i);
        	size.push_back(1);
        }
    }
 
    ll root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
 
    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        size[ry]+=size[rx];
    }
 
    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
 
    ll getSize(ll x){
    	return size[root(x)];
    }
};

int main(){
	ll n,m;
	cin>>n>>m;
	ll p[n+1];
	for(ll i=1;i<=n;i++)cin>>p[i];
	ll x[m+1],y[m+1];
    UnionFind tree(n);
	for(ll i=1;i<=m;i++){
	    cin>>x[i]>>y[i];
        tree.unite(x[i],y[i]);
	}
    ll ans = 0;
    for(ll i=1;i<=n;i++){
        if(tree.same(i,p[i])){
            ans++;
        }
    }
    cout<<ans<<endl;
}

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



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

	int N;
	cin >> N;
	bitset<60> bs(N);
	vector<VI> dp(61, VI(3, 0));
	dp[60][0] = 1;
	
	for (int i = 59; i >= 0; --i) {
		if (bs[i]) {
			dp[i][0] = dp[i + 1][0];
			dp[i][1] = dp[i + 1][0] + dp[i + 1][1];
			dp[i][2] = 2 * dp[i + 1][1] + 3 * dp[i + 1][2];
		}
		else {
			dp[i][0] = dp[i + 1][0] + dp[i + 1][1];
			dp[i][1] = dp[i + 1][1];
			dp[i][2] = dp[i + 1][1] + 3 * dp[i + 1][2];
		}
		dp[i][0] %= mod;
		dp[i][1] %= mod;
		dp[i][2] %= mod;
	}
	cout << (((dp[0][0] + dp[0][1]) % mod) + dp[0][2]) % mod << endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define int ll
#define MOD (ll)(1e9+7)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

struct Node
{
	int par;
	vector<int> son;
	int cnt;
	int k;
};vector<Node> tree;

void dfs(int n,vector<set<int>> &con)
{
	for(auto &i:con[n])
	{
		tree[i].par=n;
		tree[n].son.emplace_back(i);
		con[i].erase(n);
		dfs(i,con);
	}
}

void build(int n)
{
	tree.resize(n);
	vector<set<int>> con(n);
	int a,b;
	For(i,1,n-1)
	{
		cin>>a>>b;
		a--; b--;
		con[a].emplace(b);
		con[b].emplace(a);
	}
	tree[0].par=-1;
	dfs(0,con);
	tree[0].cnt=1;
	For(i,1,n-1) tree[i].cnt=2;
}

void dfs2(int n,int k)
{
	if(tree[n].par==-1) tree[n].k=k;
	else
	{
		tree[n].k=k-tree[tree[n].par].cnt;
		tree[tree[n].par].cnt++;
	}
	for(auto &i:tree[n].son) dfs2(i,k);
}

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,k; cin>>n>>k;
	build(n);
	//For(i,0,n-1) cout<<tree[i].cnt<<" "; cout<<"\n";
	dfs2(0,k);
	int ans=1;
	For(i,0,n-1)
	{
		//cout<<i<<" "<<tree[i].par<<"\n";
		ans=ans*tree[i].k%MOD;
	}
	cout<<ans<<"\n";
	return 0;
}









Measured memory_bytes: 25984
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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; }

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[20][20];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}
ll dp[20500];
int main() {
	cin >> s;
	ll res = INF;
	rep(i, s.size() - 2) {
		ll tmp = (s[i]-'0') * 100 + (s[i + 1]-'0') * 10 + s[i + 2]-'0';
		chmin(res, abs(753 - tmp));
	}
	cout << res << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep0(i,b) for(int i=0 ; i< b ;i++)
#define rep1(i,b) for(int i=1 ; i<=b ;i++)
#define reps(i,a,b) for(int i=a ; i< b.length() ;i++)
typedef long long ll;
#define MOD 1000000007
# define M_PI     3.14159265358979323846

using namespace std;


int main()
{
  string str1,str2;
  cin>>str1>>str2;

  if(str1 == str2.substr(0,str2.length()-1))
    cout<<"Yes";
  else
    cout<<"No";


  return 0 ;
}


Measured memory_bytes: 3624
n=int(input())
a_list_sum = []
for i in range(n):
    a_tmp=int(input())
    a_list_tmp=[list(map(int,input().split())) for _ in range(a_tmp)]
    a_list_sum_tmp=[]
    a_list_sum_tmp.append(a_tmp)
    a_list_sum_tmp.append(a_list_tmp)
    a_list_sum.append(a_list_sum_tmp)
    
import itertools
L = [0, 1] #生成する数字
bit_list = list(itertools.product([0, 1], repeat=n))

for i in range(len(bit_list)):
    count = 0
    for j in range(len(a_list_sum)):
        if bit_list[i][j] == 1:
#             print(a_list_sum[j][1])
            for k in range(len(a_list_sum[j][1])):
                person_id = a_list_sum[j][1][k][0] - 1
                is_honest = a_list_sum[j][1][k][1]
                if bit_list[i][person_id] != is_honest:
                    count += 1
    if count == 0:
        ans = sum(bit_list[i])
print(ans)

Measured memory_bytes: 8948
# from collections import Counter, defaultdict
# n = int(input())
# li = list(map(int, input().split()))
# n = int(input())
# a, b, c = map(int, input().split())
# d = defaultdict(lambda: 0)
s = set([1, 2, 3])
s.discard(int(input()))
s.discard(int(input()))
print(*s)

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

int main() {
  int X;
  cin >> X;
  if(360%X == 0) {
    cout << 360 / X << endl;
  }
  else {
    for(int i = 1; i < 361; i++) {
      if((360*i)%X == 0) {
        cout << 360*i/X << endl;
        break;
      }
    }
  }
}


Measured memory_bytes: 3604
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if(n==0 && m==0) break;
			double[][] map = new double[n][n];
			for(int i=0;i<n;i++){
				for(int j=0;j<n;j++) map[i][j] = sc.nextDouble();
			}
			
			double[][] dp = new double[m][n];
			Arrays.fill(dp[0], 1);
			for(int k=1;k<m;k++){
				for(int i=0;i<n;i++){
					for(int j=0;j<n;j++){
						dp[k][i] = Math.max(dp[k][i], dp[k-1][j]*map[j][i]);
					}
				}
			}
			double max = 0;
			for(int i=0;i<n;i++) max = Math.max(max, dp[m-1][i]);
			System.out.printf("%.2f\n", max);
		}
	}
}

Measured memory_bytes: 66416
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;

ll harr[200006];

int main()
{
    ll n , k;
    while(cin >> n >> k)
    {
        for(ll i = 0 ; i < n;++i)
        {
            cin >> harr[i];
        }

        sort(harr, harr+n);
        ll sum = 0;
        ll max_k = min(k, n);
        for(ll i = n - 1 - max_k; i >= 0; --i)
        {
            sum += harr[i];
        }
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 1920
// #includes {{{
#ifdef MY_DEBUG
#include "header/header.hpp"
#else
#include <bits/stdc++.h>
#endif

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

template<class T>
T inf(){
	return numeric_limits<T>::has_infinity?numeric_limits<T>::infinity():(numeric_limits<T>::max()/2);
}

typedef pair<int,int> pii;

#ifdef MY_DEBUG
#include"print.hpp"
#include"debug.hpp"
#endif
// }}}

int main(){
	int N,K;
	string S;
	cin>>N>>K>>S;
	K--;
	S[K] -= 'A';
	S[K] += 'a';
	cout<<S<<endl;
}


Measured memory_bytes: 256
x, y = map(int, input().split())
if x in [4,6,9,11] and y in [4,6,9,11]:
    ans = 'Yes'
elif x in [1,3,5,7,8,10,12] and y in [1,3,5,7,8,10,12]:
    ans = 'Yes'
else:
    ans = 'No'
print(ans)

Measured memory_bytes: 3064
import operator
from functools import reduce

N = int(input())
a = []
for i in range(N):
	a.append(int(input()))
a = sorted(a)

aa = []
aa.append(a[0])
for i in range(N - 1):
	aa.append(a[i + 1] - a[i])

b = []

for i in range(N):
	if aa[-1 - i] % 2 == 0:
		b.append(0)
	else:
		b.append(1 + i)

if N == 1:
	if b[0] != 0:
		print("first")
	else:
		print("second")
else:
	ans = reduce(operator.xor, b)
	if ans != 0:
		print("first")
	else:
		print("second")

Measured memory_bytes: 12208
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.List (unfoldr)
import Control.Monad
import Control.Monad.ST
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Builder as BSB
import System.IO (stdout)
import Data.Monoid

warshallFloyd1 :: Int -> U.Vector (Int, Int, Int) -> V.Vector (U.Vector Int)
warshallFloyd1 !n !edges = runST $ do
  !arr <- V.replicateM n (UM.replicate n (10^9+1))
  U.forM_ edges $ \(a,b,c) -> do
    UM.write (arr V.! a) b c
    UM.write (arr V.! b) a c
  forM_ [0..n-1] $ \a -> do
    UM.write (arr V.! a) a 0
  flip V.imapM_ arr $ \ !k !a_k -> do
    V.forM_ arr $ \ !a_i -> do
      forM_ [0..n-1] $ \j -> do
        a_ik <- UM.read a_i k
        a_kj <- UM.read a_k j
        UM.modify a_i (min (a_ik + a_kj)) j
  V.mapM U.unsafeFreeze arr

warshallFloyd2 :: Int -> Int -> V.Vector (U.Vector Int) -> V.Vector (U.Vector Int)
warshallFloyd2 !n !l !graph = runST $ do
  !arr <- V.replicateM n (UM.replicate n (10^9+1))
  flip V.imapM_ (V.zip graph arr) $ \ !a (!g_a,!a_a) -> do
    flip U.imapM_ g_a $ \ !b !v -> do
      when (v <= fromIntegral l) $ do
        UM.write a_a b 1
    UM.write a_a a 0
  flip V.imapM_ arr $ \ !k !a_k -> do
    V.forM_ arr $ \ !a_i -> do
      forM_ [0..n-1] $ \j -> do
        a_ik <- UM.read a_i k
        a_kj <- UM.read a_k j
        UM.modify a_i (min (a_ik + a_kj)) j
  V.mapM U.unsafeFreeze arr

main = do
  [n,m,l] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  edges <- U.replicateM m $ do
    [a,b,c] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    return (a-1,b-1,c)
  let !w1 = warshallFloyd1 n edges
      !w2 = warshallFloyd2 n l w1
  q <- readLn
  queries <- U.replicateM q $ do
    [s,t] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    return (s,t)
  BSB.hPutBuilder stdout $ mconcat
    [ BSB.intDec (if d > 10^9 then -1 else d - 1) <> BSB.char7 '\n'
    | (s,t) <- U.toList queries
    , let d = w2 V.! (s-1) U.! (t-1)
    ]


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

#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl

int main()
{
    int h,a;
    cin >> h >> a;
    int b=h/a;
    if(h%a!=0){
        b+=1;
    }
    cout << b << endl;
}

Measured memory_bytes: 3632
import sys
from bisect import bisect_left


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    # divisors.sort()
    return divisors


def main():
    X = int(input())
    d = set()
    for i in range(100000):
        d.add(i ** 5)
    D = sorted(d)
    idx = {v: i for i, v in enumerate(D)}
    for i in d:
        if X - i in d:
            print(idx[i], -idx[X - i])
            break
        elif i - X in d:
            print(idx[i], idx[i - X])
            break


if __name__ == "__main__":
    main()


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

int main(){
    int N;  cin >> N;
    int M = 1e9+7;
    vector<int> dp[4][4][4];
    for(int i=0; i<4; i++) for(int j=0; j<4; j++) for(int k=0; k<4; k++){
        dp[i][j][k] = vector<int>(N+1, 0);
    }

    // 長さ 3 の文字列は AGC, ACG, GAC 以外が許される。
    for(int i=0; i<4; i++) for(int j=0; j<4; j++) for(int k=0; k<4; k++){
        if(!((i==0 && j==1 &&k==2)||(i==1 && j==0 && k==2)||(i==0 && j==2 && k==1))){
            dp[i][j][k][3] = 1;
        }
    }

    for(int n=3; n<N; n++){
        for(int i=0; i<4; i++) for(int j=0; j<4; j++) for(int k=0; k<4; k++){
            if(j==0 && k==2){
                // ?AC の後ろには G 以外が入る
                dp[j][k][0][n+1] = (dp[j][k][0][n+1] + dp[i][j][k][n])%M;
                dp[j][k][2][n+1] = (dp[j][k][2][n+1] + dp[i][j][k][n])%M;
                dp[j][k][3][n+1] = (dp[j][k][3][n+1] + dp[i][j][k][n])%M;
            }else if((i==0 && k==1) || (i==0 && j==1) || (j==0 && k==1) || (j==1 && k==0)){
                // A?G, AG?, ?AG, ?GA の後ろには C 以外が入る
                dp[j][k][0][n+1] = (dp[j][k][0][n+1] + dp[i][j][k][n])%M;
                dp[j][k][1][n+1] = (dp[j][k][1][n+1] + dp[i][j][k][n])%M;
                dp[j][k][3][n+1] = (dp[j][k][3][n+1] + dp[i][j][k][n])%M;
            }else {
                // 上記以外は n+1 文字目としてなんでも使える
                for(int m=0; m<4; m++){
                    dp[j][k][m][n+1] = (dp[j][k][m][n+1] + dp[i][j][k][n])%M;
                }
            }
        }
    }

    int ret = 0;
    for(int i=0; i<4; i++) for(int j=0; j<4; j++) for(int k=0; k<4; k++){
        ret = (ret + dp[i][j][k][N])%M;
    }
    cout << ret << endl;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a: u32 = read();

    println!("{}", a*a*a);
}



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

int main(){
	int n;
	cin>>n;
	vector<int> boxsum(n,1);
	vector<int> boxred(n,0);
	boxred[0]=1;
	int m;
	cin>>m;
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		x--,y--;
		boxsum[y]++;
		if(boxred[x]==1) boxred[y]=1;
		boxsum[x]--;
		if(boxsum[x]==0) boxred[x]=0;

	}
	int res=accumulate(boxred.begin(),boxred.end(),0);
	cout<<res<<endl;

	
	
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<numeric>
#include<vector>
#include<limits.h>
#include<float.h>
#define foreach(t,p) for(t::iterator it=p.begin();it!=p.end();++it)
#define rforeach(t,p) for(t::reverse_iterator it=p.begin();it!=p.rend();++it)
#define all(p) p.begin,p.end()
using namespace std;

int main()
{
    int a,b;
    while(cin >> a >> b &&(a||b))
    {
        int h=0,f=0,t=0;
        int turi =b-a;
        while(turi!=0)
        {
            if(turi >=1000)
            {
                t++;
                turi-=1000;
                continue;
            }
            if(turi>=500)
            {
                f++;
                turi -=500;
                continue;
            }
            if(turi>=100)
            {
                h++;
                turi-=100;
                continue;
            }
        }
        cout << h <<" "<<f<<" "<<t << endl;
    }
    return 0;
}

Measured memory_bytes: 0
def main():
    N, M, K = map(int, input().split())

    for n in range(N + 1):
        for m in range(M + 1):
            overlap = 2 * n * m
            cnt = n * M + m * N - overlap
            if cnt == K:
                print("Yes")
                return
    else:
        print("No")
        return


main()


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <regex>
using namespace std;

#define FOR(i, a, b)   for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)  for(int i = (a); i > (b); --i)

typedef long long ll;

int main()
{
    int N;
    cin >> N;
    int t[100001],x[100001],y[100001];

    FOR(i,0,N) cin>>t[i+1]>>x[i+1]>>y[i+1];

    bool ans;
    FOR(i,0,N){
        int dt = t[i+1] - t[i];
        int dist = abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
        if(dt<dist){
            ans=false;
            break;
        } 
        if(dt%2 == dist%2) ans=true;
        else{
            ans=false;
            break;
        } 
    }
    if(ans)cout << "Yes" <<endl;
    else cout<<"No"<<endl;
}



Measured memory_bytes: 1408
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>

using namespace std;

int main(){
	int n, tmp, max;
	int sum;
	vector<int> v;

	while(cin >> n){
		if(n == 0){
			break;
		}
		v.clear();
		while(n--){
			cin >> tmp;
			v.push_back(tmp);
		}
		max = v[0];
		for(int i = 0; i < v.size(); i++){
			sum = 0;
			for(int j = i; j < v.size(); j++){
				sum += v[j];
				if(sum > max){
					max = sum;
				}
			}
		}
		cout << max << endl;
	}

	return 0;
}

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




int main(void){
    int w, h, m, n,a,b;
    cin >> n >> m;
    cout << n * (n-1)/2 + m*(m-1)/2<< endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<int> a(n+1, 0);
        for(int i=1; i<=n; ++i)
            cin >> a[i];

        int r;
        double b, v, e, f;
        cin >> b >> r >> v >> e >> f;

        vector<double> time(a[n]+1, 0.0);
        for(int i=0; i<a[n]; ++i){
            time[i+1] = time[i];
            if(i >= r)
                time[i+1] += 1.0 / (v - e * (i - r));
            else
                time[i+1] += 1.0 / (v - f * (r - i));
        }

        vector<double> dp(n+1, DBL_MAX/100);
        dp[0] = -b;
        for(int i=0; i<n; ++i){
            for(int j=i+1; j<=n; ++j)
                dp[j] = min(dp[j], dp[i] + time[a[j]-a[i]] + b);
        }

        printf("%.10f\n", dp[n]);
    }
}

Measured memory_bytes: 0
n,w = map(int, input().split())
WV = [list(map(int, input().split())) for _ in range(n)]

dp = [[float("inf")]*(n*10**3+1) for _ in range(n+1)]
dp[0][0] = 0

for n_i in range(1, n+1):
  for v_i in range(n*10**3+1):
    if v_i-WV[n_i-1][1]>=0:
      dp[n_i][v_i] = min(dp[n_i-1][v_i], dp[n_i-1][v_i-WV[n_i-1][1]]+WV[n_i-1][0])
    else:
      dp[n_i][v_i] = min(dp[n_i][v_i], dp[n_i-1][v_i])
      
ans = 0
for v_i in range(n*10**3+1):
  if dp[n][v_i]<=w:
    ans = v_i
  
print(ans)

Measured memory_bytes: 249268
items = ['A', 'C', 'G', 'T']

s = input()
n = len(s)
t = [0] * (n+1)

for i in range(n):
    if s[i] in items:
        t[i + 1] += t[i] + 1
    else:
        t[i + 1] += 0
print(max(t))



Measured memory_bytes: 8968
#include <stdio.h>

#define White 2
#define Gray 3
#define Black 4

int d[103],f[103];
int n,time,r;
int A[103][103];
int color[103];

typedef struct Input{
  int u;
  int k;
  int v[1000];
}input;

void DFSvisit(int u){
  int i,j,v;
  
  color[u] = Gray;
  time++;

  d[u] = time;
  //printf("d[%d]=%d\n",u,d[u]);

  for(v = 1 ; v <= n ; v++){
    if(A[u][v] == 1 && color[v] == White){
      DFSvisit(v);  
    }
  }
  
  color[u] = Black;
  time++;

  f[u] = time;
  //printf("f[%d]=%d\n",u,f[u]);
}

int main(void){
  int i,j;
  input Adj[103];
  
  time = 0;

  scanf("%d",&n);

  for(i = 1 ; i <= n ; i++){
    scanf("%d",&Adj[i].u);
    scanf("%d",&Adj[i].k);

    if(Adj[i].k != 0){
      for(j = 1 ; j <= Adj[i].k ; j++){
	scanf("%d",&Adj[i].v[j]);
      }
    }
    
  }

  for(i = 1 ; i <= n ; i++){
    for(j = 1 ; j <= n ; j++){
      A[i][j] = 0;
    }
  }

  for(i = 1 ; i <= n ; i++){
    for(j = 1 ; j <= Adj[i].k ; j++){
      A[Adj[i].u][Adj[i].v[j]] = 1;
    } 
  }
  

  for(i = 1 ; i <= n ; i++){
    color[Adj[i].u] = White;
  }

  for(i = 1 ; i <= n ; i++){
    for(j = 1 ; j <= n ; j++){
      if(A[i][j] == 1){
	if(color[j] == White)
	  DFSvisit(Adj[i].u);
      }
    }
  }
  
  for(i = 1 ; i <= n ; i++){
    printf("%d",Adj[i].u);
    printf(" %d %d\n",d[i],f[i]);
  }
  
  return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Y;
    cin >> N >> Y;
    rep(i, N + 1) {
        rep(j, N + 1) {
            int k = N - i - j;
            if (k < 0) continue;
            if (i * 10000 + j * 5000 + k * 1000 == Y) {
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }

    cout << "-1 -1 -1" << endl;

    return 0;
}


Measured memory_bytes: 256
/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */
 
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define pf push_front
#define mp make_pair
#define F first
#define S second
#define all(x)     x.begin(),x.end()
#define tc   int tt; scf(tt); while(tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll mod =1e9+7;
const int N = 1e6+7;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)


int main() 
{ 
    int n;
    scf(n);  

    prin((n+1)%2);


        //printf("\n");     
      
  
}

Measured memory_bytes: 3824
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T>
struct BIT{
    //1-index
    //0-indexで取ると無限ループする
    private:
    V<T> arr;
    int n;

    public:
    BIT(int siz){
        n=siz;
        arr.assign(n+1,0);
    }
    //一点更新 aにvを加える
    void add(T a,T v){
        //x+=(x&-x) 初項a,それ以降a<=2^Nが列挙
        for(T x=a;x<=n;x+=(x&-x)){
            arr[x]+=v;
        }
    }
    T sum(T a){
        // 1からaまでの区間和
        T ret=0;
        for(T x=a;x>0;x-=(x&-x))ret+=arr[x];
        return ret;
    }
    T get(T x){//x番目に大きい数　// 区間和がw以上となる最小のindを返す
        if(x<=0) return 0;
        T N=1;
        while(N*2<=n)N*=2;
        T v=0;
        for(T i=N;i>0;i/=2){
            if(v+i<=n&&arr[v+i]<x){
                x-=arr[v+i];
                v+=i;
            }
        }
        return v+1;
    }
    T query(int l,int r){
        return sum(r)-sum(l);
    }
};
struct Q{
    ll a,b,c;
};
priority_queue<ll> l;
priority_queue<ll,V<ll>,greater<ll>> r;
void addmid(ll v){
    if(l.size()==r.size()){
        if(l.size()&&l.top()>v){
            r.emplace(l.top());
            l.pop();
            l.emplace(v);
        }
        else r.emplace(v);
    }else{
        if(r.top()<v){
            l.emplace(r.top());
            r.pop();
            r.emplace(v);
        }else l.emplace(v);
    }
}
ll getmid(){
    if(l.size()==r.size())return l.top();
    return r.top();
}
int main(){
    int q;
    cin>>q;
    V<Q> d(q);
    V<ll> tmp;
    for(int i=0;i<q;i++){
        cin>>d[i].a;
        if(d[i].a==1){
            cin>>d[i].b>>d[i].c;
            tmp.push_back(d[i].b);
        }
    }
    sort(all(tmp));
    int siz=1;
    map<ll,int> mp;
    for(ll v:tmp){
        if(!mp.count(v))mp[v]=siz++;
    }
    BIT<ll> t(siz),ind(siz);
    ll sum=0,cnt=0;
    for(int i=0;i<q;i++){
        if(d[i].a==1){
            sum+=d[i].c;
            t.add(mp[d[i].b],d[i].b);
            addmid(d[i].b);
            ind.add(mp[d[i].b],1);
            cnt++;
        }else{
            ll res=sum;
            ll mid=getmid();
            if(l.size()==r.size()){
            ll id=ind.sum(mp[mid]);
            res+=abs(t.sum(mp[mid])-id*mid);
            res+=t.sum(siz)-t.sum(mp[mid])-(cnt-id)*mid;
            }else{
            ll id=ind.sum(mp[mid]-1);
            res+=abs(t.sum(mp[mid]-1)-id*mid);
            res+=t.sum(siz)-t.sum(mp[mid]-1)-(cnt-id)*mid;
            }
            cout<<mid<<" "<<res<<"\n";
        }
    }
}

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

using namespace std;

#define ll long long int
#define ld long double
#define Size 100001


ll n,capacity;
ll* price,*weight;
ll dp[101][Size];
ll knapsack2(int maxprofit){
	ll inf=1e11;
	for(ll N=0;N<=n;N++){
		for(ll profit=0;profit<=maxprofit;profit++){
			if(N==0 && profit==0)
				dp[N][profit]=0;
			else if(N==0)dp[N][profit]=inf;
			else if(price[N-1]<=profit)
				dp[N][profit]=min(weight[N-1]+dp[N-1][profit-price[N-1]],dp[N-1][profit]);
			else
				dp[N][profit]=dp[N-1][profit];
		}
	}
	ll ans=0;
	for(ll i=0;i<=maxprofit;i++){
		if(dp[n][i]<=capacity)ans=i;
	}
	return ans;
}
int main()
{
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	cin>>n>>capacity;
	weight=new ll[n];
	price=new ll[n];
	ll maxprofit=0;
	for(int i=0;i<n;i++){
		cin>>weight[i]>>price[i];
		maxprofit+=price[i];
	}
	cout<<knapsack2(maxprofit);
	return 0;
}

Measured memory_bytes: 79232
#include <iostream>
using namespace std;
long long dp[101][100001];

int main() {
    int N,W;
    int w[101], v[101];
    cin >> N >> W;
    for(int i=1; i<=N; ++i) cin >> w[i] >> v[i];
    for(int j=0; j<=W; ++j) dp[0][j] = 0;
    for(int i=1; i<=N; ++i) {
        for(int j=0; j<=W; ++j) {
            if(j >= w[i]) dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]] + v[i]);
            else dp[i][j] = dp[i-1][j];
        }
    }
    cout << dp[N][W] << endl;
}

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

int main(){
  long long  A , B , K ;
  cin >> A >> B >> K ;
  if(A+B<=K) cout << 0 << ' ' << 0 << endl;
  else if(A>=K) cout << A-K << ' ' << B << endl;
  else if(B>=K-A) cout << 0 << ' ' << B-K+A << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <complex>
using namespace std;

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

#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define ERASE(v,i) (v).erase(remove(all(v),i),(v).end())
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define debug(x) cerr<<#x<<" = "<<(x)<<endl;
#define LINE cerr<<"LINE: "<<__LINE__<<endl;

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();}
template<class T> void preview(T a,T b){for(T it=a;it!=b;++it)cerr<<*it<<" ";cerr<<endl;}

const int INF = 100000000;
const double PI = acos(-1.0), EPS = 1e-10;

int dist[101][101];

int main() {
	for(int n, k; cin >> n >> k, n || k;) {
		for(int i = 1; i <= n; i++) fill(dist[i], dist[i] + 101, INF);
		for(int i = 1; i <= n; i++) dist[i][i] = 0;
		rep(K, k) {
			int p; cin >> p;
			if(p == 0) {
				int a, b;
				cin >> a >> b;
				if(dist[a][b] == INF) {
					cout << -1 << endl;
				} else {
					cout << dist[a][b] << endl;
				}
			} else {
				int c, d, e;
				cin >> c >> d >> e;
				if(dist[c][d] > e) {
					dist[c][d] = e;
					dist[d][c] = e;
					for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) {
						dist[i][j] = min(dist[i][j], dist[i][c] + dist[c][j]);
						dist[i][j] = min(dist[i][j], dist[i][d] + dist[d][j]);
						dist[j][i] = dist[i][j];
					}
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 908
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define mod 1000000007 //1e9+7
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 1001

bool calc(){
  int t,p,r;
  int tid,pid,ti;
  char mes[20];
  int wa[SIZE][SIZE]={},ac[SIZE]={},pen[SIZE]={};

  pair<int,pair<int,int> > team[SIZE];
  
  scanf("%d%d%d",&t,&p,&r);
  if(t==0) return false;

  for(int i=0;i<r;i++){
    scanf("%d%d%d%s",&tid,&pid,&ti,mes);

    if(mes[0]=='C'){
      ac[tid]++;
      pen[tid] += wa[tid][pid] * 1200 + ti;
    }else{
      wa[tid][pid]++;
    }
  }

  for(int i=1;i<=t;i++){
    team[i-1] = {-ac[i],{pen[i],i}};
  }

  sort(team,team+t);

  for(int i=0;i<t;i++){
    printf("%d %d %d\n",team[i].second.second,-team[i].first,team[i].second.first);
  }
    
  
  return true;
}
  
int main(){
  
  while(calc());
  
  return 0;
}

Measured memory_bytes: 7144
#include<bits/stdc++.h>
using namespace std;
int n, m, a, b;
long long sum;
vector<int> arrn[100005];
priority_queue<int> pq;
int arrm[100005];
int main(void){
	cin >> n >> m;
	for (int i = 0; i < n; i++){
		cin >> a >> b;
		arrn[a].push_back(b);
	}
	for (int i = 1; i <= m; i++){
		for (int j = 0; j < arrn[i].size(); j++)
			pq.push(arrn[i][j]);
		if (!pq.empty()){
			sum += pq.top();
			pq.pop();
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 5632
n = int(input())
t, x, y = 0, 0, 0
for _ in range(n):
    t2, x2, y2 = map(int, input().split())
    T = t2 - t
    d = abs(x2 - x) + abs(y2 - y)
    if T < d or (T % 2 != d % 2):
        print('No')
        break
    t, x, y = t2, x2, y2
else:
    print('Yes')

Measured memory_bytes: 3064
using System;
class Program
{
	static void Main(string[] args)
	{
		string[] input = Console.ReadLine().Split(' ');
		int a = int.Parse(input[0]);
		int b = int.Parse(input[1]);
        int answer = b/a;
      while(answer>0){
      if((answer*a<=b) && (b%answer==0)){
      break;
      }
        else{
        answer=answer-1;
        }
      }
		Console.WriteLine(answer);
	}
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
int i,j,k,m,n;
char s[100000];
int main()
{
	scanf("%d%d",&n,&k);
	scanf("%s",&s);
	for(int i=0;i<n;i++)
	{
		if(i==k-1)
		{
			switch (s[i])
			{
				case 'A':{
					s[i]='a';
					break;
				}
				case 'B':{
					s[i]='b';
					break;
				}
				case 'C':{
					s[i]='c';
					break;
				}
			}
		}
	}
	printf("%s",s);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll n; cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];

    ll ans = 0, i = n-1;
    // a0が0以外の場合は明らかに達成不可能
    if(a[0] != 0){
        ans = -1;
        goto LAST;
    }
    // 先頭から順に見ていく
    for(ll i=1; i<n; i++){
        if(a[i] == 0) continue;
        // 前回から2以上の差がある場合は達成不可
        if(a[i]-a[i-1] >= 2){
            ans = -1;
            goto LAST;
        }
        // 前回からの差が1なら
        if(a[i]-a[i-1] == 1) ans++;
        else if(a[i] == a[i-1]) ans += a[i];
        else if(a[i] < a[i-1]) ans += a[i];
    }
LAST:
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4788
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000000)
n=int(input())
s=list(map(int,list(input()[:-1])))
edge=[[]for _ in range(n)]
for _ in range(n-1):
  a,b=map(int,input().split())
  a-=1
  b-=1
  edge[a].append(b)
  edge[b].append(a)
def f(lrc):
  l1,r1,c1,x1=lrc[0]
  for l2,r2,c2,x2 in lrc[1:]:
    l1,r1=max(max(l1,l2)-min(r1,r2),0),r1+r2
    if r1%2!=l1%2:l1+=1
    c1+=c2
    x1+=x2
  return [l1,r1,c1,x1]
def dfs(root,node):
  lrcx=[]
  for mode in edge[node]:
    if root!=mode:
      lrcx.append(dfs(node,mode))
  if len(lrcx)==0:
    return [s[node]]*4
  l,r,c,x=f(lrcx)
  c+=s[node]
  return [l+c,r+c,c,x+c]
anss=[]
for i in range(n):
  l,r,c,x=dfs(-1,i)
  if l==c:
    anss.append(x-c)
if len(anss)==0:print(-1)
else:print(min(anss)//2)

Measured memory_bytes: 225940
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    int n, i, j, al[60][30], almax[30];
    string S[60], T;

    cin >> n;

    for(i=0; i<60; i++){
        for(j=0; j<30; j++){
            al[i][j] = 0;
        }
    }

    for(i=0; i<30; i++){
        almax[i] = 100;
    }

    for(i=1; i<=n; i++){
        cin >> S[i];
    }

    for(i=1; i<=n; i++){
        for(j=0; j<S[i].size(); j++){
            al[i][S[i][j]-'a']++;
        }
    }

    for(i=1; i<=n; i++){
        for(j=0; j<26; j++){
            chmin(almax[j], al[i][j]);
        }
    }

    for(i=0; i<26; i++){
        for(j=1; j<=almax[i]; j++){
            T = 'a';
            cout << (char)(T[0]+i);
        }
    }

    cout << endl;

    return 0;
}

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

struct List
{
	int key;
	List *prev, *next;
};

List root, last;

void Insert(int x)
{
	List *input = (List *)malloc(sizeof(List));
	if (root.next == NULL) {
		root.next = input;
		input->prev = &root;
		input->next = &last;
		last.prev = input;
	}
	else {
		input->next = root.next;
		input->next->prev = input;
		input->prev = &root;
		root.next = input;
	}
	input->key = x;
}

//List *SearchLast()
//{
//	List *ptr = &root;
//	while (ptr->next != NULL) {
//		ptr = ptr->next;
//	}
//	return ptr;	
//}

List *SearchKey(int x) 
{
	for (List *ptr = root.next; ptr != &last; ptr = ptr->next)
		if (ptr->key == x)  return ptr;
	return NULL;
}

void Delete(List *ptr)
{
	if (ptr == NULL) return;
	ptr->prev->next = ptr->next;
	if (ptr->next != NULL) ptr->next->prev = ptr->prev;
	free(ptr);
}

void ShowList()
{
	for (List *ptr = root.next; ptr != &last; ptr = ptr->next) {
		printf("%d", ptr->key);
		if (ptr->next != &last) printf(" ");
	}
	printf("\n");		
}

//void FreeData(List *ptr)
//{
//	if (ptr == NULL) return;
//	FreeData(ptr->next);
//	free(ptr);
//}

int main()
{
	root.next = NULL;
	root.prev = NULL;

	last.next = NULL;
	last.prev = NULL;

	int n, x;
	char order[12];

	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		scanf("%s", order);
		switch (order[0])
		{
		case 'i':
			scanf("%d", &x);
			Insert(x);
			break;
		case 'd':
			switch (strlen(order))
			{
			case 6:
				scanf("%d", &x);
				Delete(SearchKey(x));
				break;
			case 10:
				Delete(last.prev);
				break;
			case 11:
				Delete(root.next);
				break;
			default:
				break;
			}
		default:
			break;
		}
	}
	ShowList();
	//FreeData(&root);
	
	return 0;
}

Measured memory_bytes: 32364
#include <bits/stdc++.h>
#define rt "\n"
#define sp " "
#define test(n) cout << "test" << n << endl;
#define fixsp(n) fixed << setprecision(n)
#define defsp(n) defaultfloat << setprecision(n)
#define kyopro ios::sync_with_stdio(false);cin.tie(NULL)
#define MOD 1000000007
#define iikae auto&
#define zenbu(a) a.begin(), a.end()
#define rzenbu(a) a.rbegin(), a.rend()
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, N, s) for(ll i{N}; i > s; i--)
using namespace std;using ll = long long;using ld = long double;using P = pair<ll,ll>;
template<typename T> T gcd(T a, T b){return b != 0 ? gcd(b, a % b) : a;}
template<typename T> struct UnionFind{vector<T> par;UnionFind(T n) : par(n, -1){}void init(T n){par.assign(n, -1);}T root(T x){if (par[x] < 0) return x;else return par[x] = root(par[x]);}bool issame(T x, T y){return root(x) == root(y);}bool merge(T x, T y){x = root(x); y = root(y);if(x == y) return false;if(par[x] > par[y]) swap(x, y);par[x] += par[y];par[y] = x;return true;}int size(int x) {return -par[root(x)];}};

/* ここからコード開始 */

int main(){
  kyopro;
  ll X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  vector<ll> A(X), B(Y), C(Z);
  for(auto& i : A){
    cin >> i;
  }
  for(auto& i : B){
    cin >> i;
  }
  for(auto& i : C){
    cin >> i;
  }
  ll xy{};
  vector<ll> AB(X * Y);
  rep(i, 0, X){
    rep(j, 0, Y){
      AB.at(xy) = A.at(i) + B.at(j);
      xy++;
    }
  }
  sort(rzenbu(AB));
  while(AB.size() > 3000){
    AB.pop_back();
  }
  ll xyz{};
  vector<ll> ABC(3000 * Z);
  rep(i, 0, min(3000LL, (ll)AB.size())){
    rep(j, 0, Z){
      ABC.at(xyz) = AB.at(i) + C.at(j);
      xyz++;
    }
  }
  sort(rzenbu(ABC));
  rep(i, 0, K){
    cout << ABC.at(i) << rt;
  }
}

Measured memory_bytes: 31616