akhauriyash/Code-Regression huggingface dataset:
n, k = (int(i) for i in input().split())  
s = input()

if k == 1:
  s = s[:1].lower() + s[1:]
elif k == n:
  s = s[:-1] + s[-1:].lower()
else:
  s = s[:k-1] + s[k-1:k].lower() + s[k:] 
  
print(s) 

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N, K;
  cin >> N >> K;
  vector<pair<long, long>> data(N);
  vector<long> sub(30);
  for(int i = 0; i < N; i++)cin >> data.at(i).first >> data.at(i).second;
  for(int i = 0; i < 30; i++){
    sub.at(i) = K % 2;
    K /= 2;
  }
  long X = 0, subK, ans = 0, sum;
  for(int i = 29; i >= 0; i--){
    sum = 0;
    if(i != 29)X += pow(2, i + 1) * sub.at(i + 1);
    if(sub.at(i) == 1 && i != 0){
      subK = X + pow(2, i) - 1;
      for(int j = 0; j < N; j++){
        if((subK | data.at(j).first) == subK)sum += data.at(j).second;
      } 
    } else if(i == 0){
      X += pow(2, 0) * sub.at(0);
      for(int j = 0; j < N; j++){
        if((X | data.at(j).first) == X)sum += data.at(j).second;
      } 
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;
  return 0;
}


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

int a[4];
bool flag = true;

void calc(vector<int> v) {
  if (flag) {
    int tmp = a[0];
    for (int i = 0; i < 3; i++) {
      if (v[i] == 0) {
        tmp += a[i + 1];
      }
      else {
        tmp -= a[i + 1];
      }
    }
    if (tmp == 7) {
      string ans = to_string(a[0]);
      for (int i = 0; i < 3; i++) {
        if (v[i] == 0) {
          ans += '+';
          ans += to_string(a[i + 1]);
        }
        else {
          ans += '-';
          ans += to_string(a[i + 1]);
        }
      }
      ans += "=7";
      cout << ans << endl;
      flag = false;
    }
  }
  return;
}

void dfs(vector<int> v) {
  if (v.size() == 3) {
    calc(v);
    return;
  }
  v.push_back(0);
  dfs(v);
  v.pop_back();
  v.push_back(1);
  dfs(v);
  return;
}

int main() {
  string s;
  cin >> s;
  for (int i = 0; i < 4; i++) {
    a[i] = s[i] - '0';
  }
  vector<int> v;
  dfs(v);
  return 0;
}

Measured memory_bytes: 256
h,w=map(int,input().split())

if h%3==0:
    case1=0
else:
    case1=w

if w%3==0:
    case2=0
else:
    case2=h

case3=float('inf')
for i in range(1, h):
    if w%2==0:
        case3=min(case3, abs((h-i)*(w//2)-i*w))
    else:
        s1=i*w
        s2=(h-i)*(w//2)
        s3=(h-i)*(w//2+1)
        case3_min=min(s1, s2, s3)
        case3_max=max(s1, s2, s3)
        case3=min(case3, abs(case3_max-case3_min))

case4=float('inf')
for i in range(1, w):
    if h%2==0:
        case4=min(case4, abs((w-i)*(h//2)-i*h))
    else:
        s1=i*h
        s2=(w-i)*(h//2)
        s3=(w-i)*(h//2+1)
        case4_min=min(s1, s2, s3)
        case4_max=max(s1, s2, s3)
        case4=min(case3, abs(case4_max-case4_min))

print(min([case1, case2, case3, case4]))


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner();
		long n = sc.nextLong();
		long p = sc.nextLong();

		long max = 1;
		long x;
		for(long i = 1;(x = (long)Math.pow(i, n)) <= p; i++){
			if(p % x == 0 && max < x)
				max = i;

			long r = p+1 - i;
			long pow = (long)Math.pow(r,n);
			if(p % r == 0 && pow <= p){
				max = r;
				break;
			}
		}

		System.out.println(max);
	}
}

class Scanner {
	private static final int SPACE = (int)' ';
	private static final int LINE_END_0 = 13;
	private static final int LINE_END_1 = 10;
	private static final int BEFORE = -1;
	private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	
	public String next(){
		StringBuilder sb = new StringBuilder();
		
		int length = BEFORE;
		readLoop: while(true) {
			try {
				int value = br.read();
				switch(value) {
				case LINE_END_1:
					if(length == BEFORE)
						break;
					
					if((int)sb.charAt(length) == LINE_END_0)
						sb.deleteCharAt(length);
				case SPACE:
					break readLoop;
				}
				sb.append((char)value);
				length++;

			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return sb.toString();
	}
	
	public String[] nextArray(int length) {
		String[] array = new String[length];
		for(int i = 0; i < length; i++)
			array[i] = next();
		return array;
	}
	
	public double nextDouble() {
		return Double.parseDouble(next());
	}
	
	public double[] nextDoubleArray(int length) {
		double[] array = new double[length];
		for(int i = 0; i < length; i++)
			array[i] = nextDouble();
		return array;
	}
	
	public int nextInt() {
		return Integer.parseInt(next());
	}
	
	public int[] nextIntArray(int length) {
		int[] array = new int[length];
		for(int i = 0; i < length; i++)
			array[i] = nextInt();
		return array;
	}
	
	public long nextLong() {
		return Long.parseLong(next());
	}
	
	public long[] nextLongArray(int length) {
		long[] array = new long[length];
		for(int i = 0; i < length; i++)
			array[i] = nextLong();
		return array;
	}
	
	public boolean ready() {
		try {
			return br.ready();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}
}


Measured memory_bytes: 22484
'''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7 #998244353
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"


def main():
    q = int(ipt())
    for _ in range(q):
        a,b = map(int,ipt().split())
        if a > b:
            a,b = b,a
        tgt = a*b
        rt = int(tgt**0.5+0.0000000000001)
        ans = rt*2-1
        if a == b:
            ans -= 1
        elif rt**2 == tgt:
            ans -= 2
        elif rt*(rt+1) < tgt:
            pass
        elif rt**2-1 < tgt:
            ans -= 1
        print(ans)

    return None

if __name__ == '__main__':
    main()


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

int main() {
	int n;
	cin >> n;
	int arr[20] = {};
	int i=0;
	int j = 0;
	while(i<n)	{
		cin >> arr[i];
		i++;
	}
	int count=0;
	
	while (j < n - 2) {
		if ((arr[j] - arr[j + 1])*(arr[j + 2] - arr[j + 1]) < 0) {
			count +=1;
		}
		j++;
	}


	cout << count << endl;



}

Measured memory_bytes: 384
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val wordCount: Int = sc.nextInt
  val wordsSorted = List.fill(wordCount)(sc.next).map(word => word.sorted)
  var wordsMap = collection.mutable.Map[String, Long]()
  var ans: Long = 0l
  wordsSorted.map(word => {
    ans += wordsMap.getOrElse(word, 0l)
    wordsMap += (word -> (wordsMap.getOrElse(word, 0l) + 1l))
  })
  println(ans)
}

Measured memory_bytes: 76844
def sieve_of_eratosthenes(ub):
    # O(n loglog n) implementation.
    # returns prime numbers <= ub.
    if ub < 2:
        return []
    prime = [True]*(ub+1)
    prime[0] = False
    prime[1] = False
    p = 2
    while p*p <= ub:
        if prime[p]:
            # don't need to check 2p ~ (p-1)p (they've already been checked).
            for i in range(p*p, ub+1, p):
                prime[i] = False
        p += 1
    return [i for i in range(ub+1) if prime[i]]

primes = sieve_of_eratosthenes(10**6)
X = int(input())
for i in range(X, 10**6):
    if i in primes:
        print(i)
        break

Measured memory_bytes: 14044
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

const int infI=1e9+5;
const long long infL=1e16;
const int MOD=1e9+7;
const int MAX=5e5+5;

#define mp make_pair
#define in &
#define pb push_back
#define ii pair<int,int>
#define iii pair<ii,int>
#define ll long long
#define pll pair<ll,ll>
#define vvl vector<vector<ll> >
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define eb emplace_back
#define forn(i,a,b) for(ll i=a;i<b;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define endl '\n'
#define popb pop_back()
#define se second
#define fi first
#define test(t) int t;cin>>t;while(t--)
#define debug(x) cerr<<"=>"<<#x<<" = "<<x<<endl

ll power(ll a,ll b){
    if(b==0){
        return 1;
    }
    if(b==1){
        return a;
    }
    ll temp=power(a,b/2);
    temp=(temp*temp)%MOD;
    if(b%2){
        temp=(temp*a)%MOD;
    }
    return temp;
}

//only use if mod is prime
ll mod_inv(ll a,ll mod){
    a%=mod;
    return power(a,mod-2);
}

void extended_gcd(ll a,ll b,ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return;
    }
    ll x1,y1;
    extended_gcd(b,a%b,x1,y1);
    x=y1;
    y=x1-((a/b)*y1);
    return;
}

//TLE can also occur if vectors are not passed by reference
//priority_queue implements max heap by default

ll f[MAX],f_inv[MAX];

ll ncr(ll a,ll b){
    assert(a>=b);
    ll ans = f[a];
    ans = (ans*f_inv[b])%MOD;
    ans = (ans * f_inv[a-b])%MOD;
    return ans;
}

int main(){
    fastio;
    // think about edge cases like n=1,n=MAX etc.
    int n,m;
    cin>>n>>m;
    f[0]=f[1]=1;
    forn(i,2,MAX){
        f[i] = (i*f[i-1])%MOD;
    }
    f_inv[MAX-1] = mod_inv(f[MAX-1],MOD);
    for(int i = MAX-1;i>0;--i){
        f_inv[i-1] = (i*f_inv[i])%MOD;
    }
    ll ans = 0;
    int c= 1;
    forn(i,0,n+1){
        ll u = (ncr(n,i)*ncr(m,i))%MOD;
        ll t = (ncr(m-i,n-i)*f[n-i])%MOD;
        t = (t*t)%MOD;
        t = (t*f[i])%MOD;
        u = (u*t)%MOD;
        ans = (ans+c*u)%MOD;
        ans = (ans+MOD)%MOD;
        // debug(u);
        c*=-1;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 11452
using System;
using System.Linq;

namespace abc176.a
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = getIntParams();

            Console.WriteLine(((input[0] / input[1]) + (input[0] % input[1] > 0 ? 1 : 0)) * input[2]);
        }

        //↓↓↓ shared function ↓↓↓
        static int getIntParam()
        {
            return int.Parse(Console.ReadLine());
        }
        static int[] getIntParams()
        {
            return Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
        }
        static long getLongParam()
        {
            return long.Parse(Console.ReadLine());
        }
        static long[] getLongParams()
        {
            return Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
        }
        static string getStringParam()
        {
            return Console.ReadLine();
        }
        static string[] getStringParams()
        {
            return Console.ReadLine().Split(' ');
        }
    }
}


Measured memory_bytes: 28268
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <tuple>
#include <queue>
#include <bitset>
#include <unordered_map>
#include <tuple>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <sys/time.h>

using namespace std;

void solve(long long N, long long K, vector<long long> V){
  long long ans = 0;
  for (long long k = 0; k <= K; k++) {
    if (k > N) {
      break;
    }
    vector<long long> li(k);
    for (long long r = 0; r <= k; r++) {
      for (long long i = 0; i < r; i++) {
        li[i] = V[i];
      }
      for (long long i = 0; i < k-r; i++) {
        li[r+i] = V[N-1-i];
      }
      sort(li.begin(), li.end());
      for (long long i = 0; i < min(K-k, k); i++) {
        li[i] = max(0LL, li[i]);
      }
      ans = max(accumulate(li.begin(), li.end(), 0LL), ans);
    }
  }
  std::cout << ans << std::endl;
}

int main(){
  long long N;
  long long K;
  scanf("%lld",&N);
  vector<long long> V(N);
  scanf("%lld",&K);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&V[i]);
  }
  solve(N, K, V);
  return 0;
}


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

#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<ll,ll>
#define vi vector<int>
#define vpi vector< pi > 
#define IOS ios_base::sync_with_stdio(false),cin.tie(NULL)
const int N=100002;
ll pwr(ll a, ll b)
{
	ll r=1;
	while(b)
	{
		if(b%2) r=(r*a)%mod;
		b/=2;
		a=a*a%mod;
	}
	return r;
}
ll f[N],p[N],sm[N],res[N],b[N];
int main()
{
	sm[1]=1;
	for(int i=2;i<N;i++)
	{
		if(p[i]) continue;
		for(int j=i;j<N;j+=i)
		{
			p[j]=i;
		}
	}
	for(int i=2;i<N;i++)
	{
		int j=0,x=i;
		while(x>1)
		{
			
			if((x/p[x])%p[x]==0){
				j=-1;break;
			}
			x/=p[x];
			j++;
		}
		if(j==-1) sm[i]=0;
		else if(j%2) sm[i]=1;
		else sm[i]=-1;
		//cout<<i<<" "<<sm[i]<<"\n";
	}

	ll n,k;
	cin>>n>>k;
	f[0]=1;
	for(int i=1;i<N;i++)
		f[i]=1ll*i*f[i-1]%mod;
	ll ans=0,add=0;
	for(ll i=k;i>=1;i--)
	{
		res[i]=pwr(k/i,n);
		for(int j=2*i;j<=k;j+=i)
		{
			res[i]-=res[j]%mod;
			// b[i]+=sm[j]*b[i*j]%mod;
			// if(b[i]<0) b[i]+=mod;
			res[i]%=mod;
			if(res[i]<0) res[i]+=mod;
		}
		add+=b[i];
		ans=(ans+ i*res[i]%mod)%mod;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 6720
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000



int main(){
	
	int N;
	cin>>N;
	
	string S;
	cin>>S;
	int ans = 0;
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			for(int k=0;k<10;k++){
				string s = "";
				s += (char)('0'+i);
				s += (char)('0'+j);
				s += (char)('0'+k);
				int now = 0;
				for(int x=0;x<S.size();x++){
					if(now==3)break;
					if(S[x]==s[now]){
						now++;
					}
				}
				if(now==3)ans++;
			}
		}
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class F
{
	static void Main()
	{
		Func<int[]> read = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
		var h = read();
		var n = h[0];
		var map = new int[h[1]].Select(_ => read()).ToLookup(r => r[0], r => r[1]).ToDictionary(g => g.Key, g => g.ToArray());

		var m = double.MaxValue;
		for (int k = 1; k < n; k++)
		{
			var dp = new double[n + 1];
			for (int i = n - 1; i > 0; i--)
			{
				if (i == k && map[i].Length > 1)
				{
					var sum = 0.0;
					var max = 0.0;
					foreach (var j in map[i])
					{
						sum += dp[j];
						max = Math.Max(max, dp[j]);
					}
					dp[i] = (sum - max) / (map[i].Length - 1) + 1;
				}
				else
				{
					var sum = 0.0;
					foreach (var j in map[i])
					{
						sum += dp[j];
					}
					dp[i] = sum / map[i].Length + 1;
				}
			}
			m = Math.Min(m, dp[1]);
		}
		Console.WriteLine(m);
	}
}


Measured memory_bytes: 22688
n, m = map(int, input().split())

# 隣接リストの雛形
D = dict()
for i in range(n):
    D[i] = []

# グラフを入力
for _ in range(m):
    s, t = map(int, input().split())
    D[s].append(t)
    D[t].append(s)

group = [-1]*n
cnt = 0
for i in range(n):
    if group[i] == -1:
        group[i] = cnt
        stack = [i]
        while stack:
            v = stack.pop()
            for c in D[v]:
                if group[c] == -1:
                    group[c] = cnt
                    stack.append(c)
        cnt += 1

q = int(input())
for _ in range(q):
    s, t = map(int, input().split())
    print('yes' if group[s] == group[t] else 'no')


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

int main(){
    ll a, b, r, x, tmp;
    cin>>a>>b;
    x = a * b;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    cout<<x/b<<endl;
    return 0;
}

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

int main(){
    int N, X;
    cin >> N >> X;
    int sum = 0, m = INT_MAX;
    rep(i,N) {
        int a;
        cin >> a;
        sum += a;
        m = min(m, a);
    }
    X -= sum;
    int ans = N;
    ans += X / m;
    cout << ans << endl;
}

Measured memory_bytes: 3596
# ABC111C - /\/\/\/
from collections import Counter


def main():
    N, *V = open(0).read().split()
    N = int(N)
    even, odd = Counter(V[::2]).most_common(2), Counter(V[1::2]).most_common(2)
    if even[0][0] != odd[0][0]:  # replace except the modes of both parities
        ans = N - even[0][1] - odd[0][1]
    else:
        if len(even) == 1 or len(odd) == 1:
            ans = N // 2  #  replace half of the sequence
        else:  # replace smaller pair of even no.1 & odd 2 / even 2 & odd 1
            ans = N - max(even[0][1] + odd[1][1], even[1][1] + odd[0][1])
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 16116
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl

int main() {
    int n; cin >> n;
    vector<string> s;

    if(n==1){
        cout << "a" << endl;
        return 0;
    }

    s.push_back("a");
    for(int i=1; i<n; i++){
        int size = s.size();
        for(int j=0; j<size; j++){
            string tmp = s.at(j);
            string tmp4 = s.at(j);
            sort(tmp4.rbegin(), tmp4.rend());
            char tmp2 = tmp4.at(0);
            dump(tmp2);
            for(char m = 'a'; m<=tmp2+1; ++m){
                tmp.push_back(m);
                s.push_back(tmp);
                tmp.pop_back();
            }

        }
        rep(l, 3){
            dump(s.at(l));
        }

        size = s.size();
        vector<string> tt;
        for(int j=0; j<size; j++){
            if(s.at(j).size()!=i){
                tt.push_back(s.at(j));
            }
        }

        s = tt;
    }

    sort(s.begin(), s.end());
    for(auto ans:s){
        cout << ans << endl;
    }
}


Measured memory_bytes: 11464
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n; cin>>n;
    ll d; cin>>d;
    ll ans=0;
    vector<ll> x(n), y(n);
    rep(i,n){
        cin>>x[i]>>y[i];
    }
    rep(i,n){
        if(x[i]*x[i]+y[i]*y[i]<=d*d){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6368
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define mod ((ull)(1e9)+7)

vector<ll> v(2*(ll)(1e5+50),0);
vector<ll> v_inv(2*(ll)(1e5+50),0);

ll pmod(ll n, ll p){
	ll m=n%mod;
	if(p==1) return m;
	ll ans=pmod((m*m)%mod, p/2)%mod;
	if(p%2==1) ans=ans*m%mod;
	return ans;
}

void factorial(ll n){
	v[0]=1;
	for(ll i=1; i<=n; i++){
		v[i]=v[i-1]*i%mod;
	}
	return;
}

void factorial_inv(ll n){
	for(ll i=0; i<=n; i++){
		v_inv[i]=pmod(v[i],mod-2);
	}
}

ll binom(ll n, ll k){
	ll tmp=v_inv[k]*v_inv[n-k]%mod;
	return v[n]*tmp%mod;
}

vector<ll> get_prime(ll n){
    bool is_prime[n+1];
    is_prime[0]=false;
    is_prime[1]=false;
    for(ll i=2; i<=n; i++) is_prime[i]=true;
    for(ll i=2; i*i<=n; i++){
		if(!is_prime[i]) continue;
		for(ll j=2*i; j<=n; j+=i){
			is_prime[j]=false;
        }
    }
    vector<ll> p;
    for(ll i=2; i<=n; i++){
        if(is_prime[i]) p.push_back(i);
    }
    return p;
}

int main(){
	factorial(2*(ll)(1e5+50));
	factorial_inv(2*(ll)(1e5+50));

	ll n, m;
	cin >> n >> m;
	vector<ll> p=get_prime(sqrt(m));
	vector<ll> exp(p.size(), 0);
	ll t=m;
	for(int i=0; i<p.size(); i++){
		while(t%p[i]==0){
			exp[i]++;
			t/=p[i];
		}
	}
 
	ll ans=1;
	for(int i=0; i<p.size(); i++) ans=ans*binom(exp[i]+n-1, exp[i])%mod;
	if(t>1) ans=ans*n%mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3456
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n = input().strip()[::-1]
  dp = [[0, 0] for _ in range(len(n))]
  dp[0][0] = int(n[0])
  dp[0][1] = 10 - int(n[0])
  for i, d in enumerate(map(int, n[1:]), 1):
    dp[i][0] = min(dp[i-1][0] + d,      dp[i-1][1] + 1 + d)
    dp[i][1] = min(dp[i-1][0] + 10 - d, dp[i-1][1] + 10 - (d + 1))
  print(min(dp[-1][0], dp[-1][1]+1))  

if __name__=='__main__':
  main()



Measured memory_bytes: 142364
#include <iostream>

int main()
{
    int a, b;

    std::cin >> a >> b;

    if((b*2) >= a)
    {
        std::cout << 0 << std::endl;
    }
    else
    {
        std::cout << (a-(b*2)) << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<vector>
double F(double r,double s)
{
	return sqrt((r+s)*(r+s)-(r-s)*(r-s));
}
int main()
{
	int l,a[12],n,i,j,k;
	char*p,s[256];
	while(fgets(s,256,stdin))
	{
		p=strtok(s," ");
		l=atoi(p);
		for(n=0;p;)
		{
			p=strtok(0," ");
			if(p)a[n++]=atoi(p);
		}
		double d[12][12];
		for(i=0;i<n;++i)for(j=i+1;j<n;++j)d[i][j]=d[j][i]=F(a[i],a[j]);
		std::vector<int>u,v;
		double dp[1<<12][12];
		std::fill(dp[0],dp[1<<12],1e10);
		for(i=0;i<n;++i)dp[1<<i][i]=a[i];
		for(i=1;i<(1<<n);++i)
		{
			u.clear();
			v.clear();
			for(j=0;j<n;++j)
			{
				if(i&(1<<j))u.push_back(j);
				else v.push_back(j);
			}
			for(j=0;j<u.size();++j)
			{
				for(k=0;k<v.size();++k)
				{
					double&r=dp[i|(1<<v[k])][v[k]];
					r=std::min(r,dp[i][u[j]]+d[u[j]][v[k]]);
				}
			}
		}
		k=(1<<n)-1;
		for(i=0;i<n;++i)dp[k][i]+=a[i];
		puts(*std::min_element(dp[k],dp[k]+n)-1e-7<l?"OK":"NA");
	}
	return 0;
}

Measured memory_bytes: 0
import sys
def main():
    input = sys.stdin.readline
    NK = list(map(int, input().split()))
    N = NK[0]
    K = NK[1]
    hs = list(map(int, input().split()))
    ans = 0
    for i in range(N):
        if hs[i] >= K:
            ans += 1
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 49904
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

typedef long long cat;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	string S;
	cin >> S;
	int N =S.length();
	int cnt[3] ={0,0,0};
	for(int i =0; i < N; i++) cnt[S[i]-'a']++;
	for(int i =0; i < 3; i++) for(int j =0; j < 3; j++) if(i != j) {
		int P[3];
		P[0] =i, P[1] =j, P[2] =3-i-j;
		int cntx[] ={0,0,0};
		for(int k =0; k < N; k++) cntx[P[k%3]]++;
		bool ok =true;
		for(int k =0; k < 3; k++) if(cntx[k] != cnt[k]) ok =false;
		if(ok) {
			cout << "YES\n";
			return 0;
		}
	}
	cout << "NO\n";
	return 0;}

// look at my code
// my code is amazing


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

import sys
from fractions import gcd

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

def lcm(x, y): return (x * y) // gcd(x, y)

N = INT()
A = LIST()

l = 1
for a in A:
    l = lcm(l, a)

ans = 0
for i, a in enumerate(A):
    ans += l // a
print(ans%MOD)


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

using ll = long long;
const ll MOD = 998244353;

int main() {
    int N;
    cin >> N;
    int m = 0;
    while (m * (m + 1) / 2 < N) m++;
    for (int i = 1; i <= m; i++) {
        if (i == m * (m + 1) / 2 - N) continue;
        cout << i << endl;
    }
}

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

int main()
{
    int N; cin >> N;
    int A[100005] = {};
    for (int n = 1; n <= N; n++)
    {
        cin >> A[n];
    }


    long cnt[100005] = {}; // Aiは高々3である

    long ans = 1, cnt_0 = 3, mod = 1000000007;

    for (int n = 1; n <= N; n++)
    {
        int An = A[n];
        cnt[An]++;
        if (An == 0)
        {
            ans *= cnt_0;
            ans %= mod;
            cnt_0--;
        }
        else
        {
            ans *= cnt[An - 1];
            ans %= mod;
            cnt[An - 1]--;
        }
    }

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

Measured memory_bytes: 1408
abcd = input()
a = int(abcd[0])
b = int(abcd[1])
c = int(abcd[2])
d = int(abcd[3])


def to_char(op):
    if op == 1:
        return '+'
    else:
        return '-'


for op1 in [1, -1]:
    for op2 in [1, -1]:
        for op3 in [1, -1]:
            val = a + op1 * b + op2 * c + op3 * d
            if val == 7:
                print('{}{}{}{}{}{}{}=7'.format(
                    a, to_char(op1), b, to_char(op2), c, to_char(op3), d))
                exit(0)

Measured memory_bytes: 3064
n = int(input())
m = list(map(int, input().split()))

l = {}
ll = {}

if n % 2 == 0:
  for i in m:
    l[2*(i//2)+1] = 2
    if i in ll:
      ll[i] += 1
    else:
      ll[i] = 1
else:
  for i in m:
    if 2*(i//2) == 0:
      l[2*(i//2)] = 1
    else:
      l[2*(i//2)] = 2
    if i in ll:
      ll[i] += 1
    else:
      ll[i] = 1

if l != ll:
  print(0)
  exit()

print((1 << (n // 2)) % ((10 ** 9) + 7))


Measured memory_bytes: 17260
function Main(input) {
	let C = 1e9 + 7;
	input = input.trim().split("\n").map(function(x) { return x.split(" ")});
	let N = parseInt(input[0][0], 10);
	let K = parseInt(input[0][1], 10);
	let a = input[1].map(e => parseInt(e, 10));
	a.sort((a, b) => b - a);
	for (let i = N - 1; i >= 0; i--){
		if (a[i] === 0) a.pop();
		else break;
	}
	if (a.length === 0) {
		if (K === 0 ) console.log(1);
		else console.log(0);
		return;
	}
	a.reverse();

	let DP = Array.from({length: a.length}, () => []);
	let capacityMax = Math.min(a[0], K);
	DP[0].push(1);
	for (let j = 0; j < capacityMax; j++){
		DP[0].push(1);
	}
	let ruisekiwa = [0];
	let tmp;
	for (let i = 1; i < DP.length; i++){
		capacityMax += a[i];
		capacityMax = Math.min(capacityMax, K);
		// console.log(capacityMax);
		for (let j = 0; j < DP[i - 1].length; j++){
			ruisekiwa[j + 1] = ruisekiwa[j] + DP[i - 1][j];
			ruisekiwa[j + 1] %= C;
		}
		// console.log("r", ruisekiwa);

		for (let j = 0; j < a[i]; j++){
			DP[i].push(ruisekiwa[Math.min(ruisekiwa.length - 1, j + 1)]);
		}
		
		for (let j = a[i]; j <= capacityMax; j++){
			tmp = Math.min(ruisekiwa.length - 1, j + 1);
			DP[i].push(mod(ruisekiwa[tmp] - ruisekiwa[j - a[i]], C));
		}
		// console.log(DP);
	}
	// console.log(DP);
	let line = DP.pop();
	if (line.length <= K) {
		console.log(0);
	} else {
		console.log(line[K]);
	}

}

function mod(i, j) {
    return (i % j) < 0 ? (i % j) + 0 + (j < 0 ? -j : j) : (i % j + 0);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 142816
N,M=map(int,input().split())#N段、m-broken
cango=[True]*(N+1) #x段目が安全か
mod=10 ** 9 + 7
for i in range(M):
    cango[int(input())]=False
dp=[0]*(N+1) #dp[x]=x段目まで行く総数
dp[0]=1 #地上
dp[1]=int(cango[1])
for x,ok in enumerate(cango):#もらうdp
    if x==0 or x==1 :continue
    if ok:
        dp[x] += (dp[x - 1] + dp[x - 2])%mod
print(dp[N])

Measured memory_bytes: 7732
#include <cstdio>
#include <deque>
 
using namespace std;
 
int main(){
  deque<int> st;
  int n;
  while(~scanf("%d",&n)){
    if(n){
      st.push_back(n);
    }else{
      printf("%d\n",st.back());
      st.pop_back();
    }
  }
}

Measured memory_bytes: 2604
/**********************************************************/
/**            Bismillahir-rahmanir-rahim                **/
/**  In the name of Allah, the Beneficent, the Merciful. **/
/**********************************************************/
/**@author: Sayed Sohan, CSE 13th batch(2016), MBSTU*/
/**status : */
/**url: */
/* Generate with Contest-Helper **/
/* https://github.com/goldenbijoy/Contest_Helper */
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
typedef long long  ll;
typedef unsigned long long ull;
#define clr(arr,value) memset(arr,value,sizeof(arr))
#define MOD 1000000007
#define PI acos(-1)
#define PB push_back
#define MP make_pair
#define SP " "
#define NL "\n"
#define DE cout<<"HERE"<<endl;
#define INF 1e18
#define __FAST_IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr2V(x,sz) for(int iii=0;i<=sz;iii++) x[iii].clear();
#define NUM1(x) __builtin_popcount(x)
#define Pause system("pause");
#define MAX 100050/** can increase another 0 */

//** your code goes from here


int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    __FAST_IO;
    ll i,j,k,arr[MAX],l,m,n,x,y,coun,sum,ans,T,check;
    vector<ll> v;
    string s;

    ll a,b;
    cin>>a>>b;
    x = __gcd(a,b);

    ll z = (a*b)/x;
    cout<<z<<NL;

    //if(x==1) cout<<a*b<<NL;
    //else cout<<max(a,b)*x<<NL;



    /// Don't forget to initialize array....
    return 0;
}


Measured memory_bytes: 256
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))

def third(x, y):
    return (set('ABC')-set([x,y])).pop()

def other(S, c):
    if S[0] == c:
        return S[1]
    return S[0]

def _solve(A, B, C, S):
    counter = {'A': A, 'B': B, 'C': C}
    answer = []
    i = 0
    while i < len(S):
        s = S[i]
        if counter[s[0]] > 0:
            counter[s[0]] -= 1
            counter[s[1]] += 1
            answer.append(s[1])
        elif counter[s[1]] > 0:
            counter[s[0]] += 1
            counter[s[1]] -= 1
            answer.append(s[0])
        else:
            if i == 0:
                return None
            if S[i-1][0] in s:
                prev_dest = S[i-1][1]
                prev_src = S[i-1][0]
            else:
                prev_dest = S[i-1][0]
                prev_src = S[i-1][1]
            answer.pop()
            answer.append(prev_src)
            counter[prev_dest] -= 2
            counter[prev_src] += 2
            if counter[prev_dest] < 0:
                return None
            i -= 1
        i += 1
    return answer



def solve():
    N, A, B, C = read_ints()
    S = []
    for _ in range(N):
        S.append(input().strip())
    answer = _solve(A, B, C, S)
    if answer is None:
        print('No')
        return
    print('Yes')
    for a in answer:
        print(a)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 17128
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define FOR(I,a,b) for(int I=a;I<b;I++)
#define FORit(it,a) for(auto it=a.begin();it!=a.end();it++)
#define ROF(I,a,b) for(int I=a;I>=b;I--)
#define vec vector
#define vi vec<int>
#define vll vec<ll>
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define testcases ll t;cin>>t;while(t--)
#define mem(a,k) memset(a,k,sizeof(a))
#define FF first
#define SS second
#define MP(x,y) make_pair(x,y)
#define rt return
#define br break
#define ct continue
#define elif else if
#define ii pair<int,int>
#define vecin(a,n,index) for(int I=index;I<n;I++)cin>>a[I]
#define vecout(a,n,index) for(int I=index;I<n;I++)cout<<a[I]<<" ";cout<<endl;
//ll mod = 1000000007;
void solve() {
	int k; cin >> k;
	string s = "ACL";
	while (k--) {
		cout << s;
	}
	cout << endl;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
	// START FROM HERE :)
	solve();
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <fstream>
#include <cstdio>
using namespace std;
// vector<pair<int,int> > v;
// cin.ignore();//twice getline(cin,s);
// g++ iterator.cpp -std=c++17
// cout<<(A + B == C ? "YES" : "NO")<<endl;
// __gcd(a,b)
// string s=to_string(i);
// sort(arr, arr+n, greater<int>());
// const long double pi = acos(-1.0);
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define vll vector<ll>
#define mll map<ll,ll >
#define mlli map<ll,ll>::iterator
#define size size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast(){ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);}


int main(void)
{
	fast();
	int k;
	cin>>k;
	int a,b;
	cin>>a>>b;
	for(int i=a;i<=b;i++)
	{
		if(i%k==0)
		{
			cout<<"OK"<<endl;
			return 0;
			break;
		}
	}
	cout<<"NG"<<endl;
}

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

int  main()
{
	vector <int> x(5);
	int ans = 0;
	rep(i, 5)
	{
		cin >> x[i];
		if (x[i] == 0)
			ans = i + 1;
	}
	cout << ans << endl;
	return (0);
}

Measured memory_bytes: 3628
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m;
vector<P> vec;

bool flag[200005];

int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		P p;
		scanf("%d%d",&p.first,&p.second);
		vec.push_back(p);
	}
	sort(vec.begin(),vec.end());
	reverse(vec.begin(),vec.end());
	priority_queue<P> que;
	priority_queue<P,vector<P>,greater<P> > que2;
	int l=0,cnt=1;
	memset(flag,false,sizeof(flag));
	for(int i=m;i>=1;i--){
		while(l<n && vec[l].first>=i){
			que.push(P(vec[l].second,l));
			l++;
		}
		if(que.size()){
			P p=que.top();
			que.pop();
			cnt++;
		}
	}
	for(;l<n;l++){
		que.push(P(vec[l].second,l));
	}
	while(que.size()){
		P p=que.top();
		que.pop();
		que2.push(p);
	}
	for(int i=cnt;i<=m;i++){
		if(!flag[i]){
			if(que2.size()){
				P p=que2.top();
				if(i>=p.first){
					que2.pop();
				}
			}
		}
	}
	int res=(int)que2.size();
	printf("%d\n",res);
	return 0;
}


Measured memory_bytes: 6640
def function():
    N,M,X = map(int, input().split())
    maxCost=0
    Aij = []
    for n in range(0,N):
        Aj = list(map(int, input().split()))
        maxCost += Aj[0]
        Aij.append(Aj)

    maxCost += 1
    minCost = maxCost
    total = pow(2, N)
    for n in range(1,total):
        x = [0]*M
        cost = 0
        i = 0
        while n>>i != 0:
            if (n>>i) & 1 == 1:
                Aj = Aij[i]
                cost += Aj[0]
                for j in range(1,len(Aj)):
                    x[j-1] += Aj[j]
            i += 1
        
        # check his understanding is higher than X
        higher = True
        for xv in x:
            if xv < X:
                higher = False
                break
        if higher == True:
            minCost = min(cost, minCost)
    if minCost == maxCost:
        minCost = -1
    print(minCost)

if __name__ == '__main__':
    function()


Measured memory_bytes: 9120
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include<string>
#include<stack>
#include<queue>
#include<stdio.h>
#include <algorithm>
#include<set>
#include<vector>

#define _CRT_SECURE_NO_WARNINGS

using namespace std;
struct Human
{
	int age;
	double weight;
	char name[256];
};

int findSumOfDigits(int n) {
	int sum = 0;
	while (n > 0) { // n が 0 になるまで
		sum += n % 10;
		n /= 10;
	}
	return sum;
}

int main()
{
	//cin>>N;
	// for (int i = 0; i < N; ++i) cin >> A[i];
	//while(true){break; ++res;}
	//cout << res << endl;
	//sort(a, a+N, greater<int>()) 大きい順ソート sort(v.begin(), v.end()); // vector
	//set<int>values; values.insert() values.size()
	//map<string,int>salary; salary["John"] = 1400;
	// string num = to_string(counter);

	int l[10000];
	int n = 6;
	int v[3];
	int a, b, c, d;
	int sum = 0;
	int count=0;
	int kari = 0;
	int w, h;
	int x, y, r;
	vector<string> lang;
	vector<int> data;
	string s; // s.size() to_string char string %s

	cin >>w>>h>>x>>y>>r;

	if (x+r <= w && x-r>=0 && y + r <= h && y-r>=0)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}


	return 0;
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
vector<int>S;
int bisearch(int n,int a){
    int left=0,right=n;
    while(left<right){
        int mid=left+(right-left)/2;
        if(a==S[mid]) return 1;
        else if(a<S[mid]) right=mid;
        else left=mid+1;
    }
    return 0;
}
int main()
{
    int n,a,q,cnt=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a);
        S.push_back(a);
    }
    scanf("%d",&q);
    for(int i=0;i<q;i++){
        scanf("%d",&a);
        cnt+=bisearch(n,a);
    }
    printf("%d\n",cnt);
}



Measured memory_bytes: 3416
#include <bits/stdc++.h>
#define ll long long
#define MAX 500005
using namespace std;

template<typename T>
void read(T &n){
    n = 0;
    T f = 1;
    char c = getchar();
    while(!isdigit(c) && c != '-') c = getchar();
    if(c == '-') f = -1, c = getchar();
    while(isdigit(c)) n = n*10+c-'0', c = getchar();
    n *= f;
}
template<typename T>
void write(T n){
    if(n < 0) putchar('-'), n = -n;
    if(n > 9) write(n/10);
    putchar(n%10+'0');
}

int n;
char s[20];
vector<int> ans;
ll a[5];

int main()
{
    cin >> n >> a[0] >> a[1] >> a[2];
    if(a[0]+a[1]+a[2] > 2){
        for(int i = 1; i <= n; i++){
            scanf("%s", s+1);
            int x = s[1]-'A', y = s[2]-'A';
            if(a[x] == 0 && a[y] == 0){
                puts("No");
                return 0;
            }
            ans.push_back(a[x] > a[y]?y:x);
            if(a[x] > a[y]) a[x]--, a[y]++;
            else a[x]++, a[y]--;
        }
    }
    else{
        for(int i = 1; i <= n; i++){
            scanf("%s", s+1);
            int x = s[1]-'A', y = s[2]-'A';
            if(a[x] == 0 && a[y] == 0){
                puts("No");
                return 0;
            }
            if(!a[x]) ans.push_back(x), a[y]--, a[x]++;
            else if(!a[y]) ans.push_back(y), a[x]--, a[y]++;
            else{
                if(i == n){
                    ans.push_back(x);
                    break;
                }
                scanf("%s", s+1);
                int u = s[1]-'A', v = s[2]-'A';
                if(u == x && v == y){
                    ans.push_back(x), ans.push_back(y);
                    i++;
                }
                else{
                    int p;
                    if(u == x || v == x) p = x;
                    else p = y;
                    ans.push_back(p);
                    ans.push_back(u+v-p);
                    a[x+y-p]--, a[u+v-p]++;
                    i++;
                }
            }
        }
    }
    puts("Yes");
    for(int i = 0; i < ans.size(); i++){
        putchar(ans[i]+'A'), puts("");
    }

    return 0;
}


Measured memory_bytes: 4040
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define ll long long
#define db double
#define P pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define INF 0x3f3f3f3f3f3f3f3f
#define N 200100
#define M 
using namespace std;

ll n,m,l,x,y;
char S[N],T[N];

int main()
{
    ll i,j,p,q;
    cin>>m>>n>>l>>x>>y;
    scanf("%s%s",S+1,T+1);
    p=1,q=n;
    for(i=l;i>=1;i--)
    {
	if(T[i]=='R') p=max(p-1,1ll);
	else if(T[i]=='L') q=min(q+1,n);
	if(S[i]=='R') q--;
	else if(S[i]=='L') p++;
	if(p>q)
	{
	    puts("NO");
	    return 0;
	}
    }
//    cout<<p<<" "<<q<<endl;
    if(y<p || y>q)
    {
	puts("NO");
	return 0;
    }
    p=1,q=m;
    for(i=l;i>=1;i--)
    {
	if(T[i]=='D') p=max(p-1,1ll);
	else if(T[i]=='U') q=min(q+1,m);
	if(S[i]=='D') q--;
	else if(S[i]=='U') p++;
	if(p>q)
	{
	    puts("NO");
	    return 0;
	}
    }
    if(x<p || x>q)
    {
	puts("NO");
	return 0;
    }
    puts("YES");
}


Measured memory_bytes: 640
#include <stack>
#include <iostream>
using namespace std;
int main()
{
	stack<int> data;
	int input;
	
	while (cin >> input)
	{
		if (input)
		{
			data.push(input);
		}
		else
		{
			cout << data.top() << endl;
			data.pop();
		}
	}
}

Measured memory_bytes: 3096
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <ctime>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P a, const P b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int main() {
    int a, b;
    vector<int> r[101];
    while(cin >> a >> b) {
        if(a == 0 && b == 0) {
            int even = 0, odd = 0, ng = 0;
            rep(i,0,101) {
                if(r[i].size() == 0) continue;
                else if(r[i].size() % 2 == 0) even++;
                else if(r[i].size() % 2 == 1 && (i == 1 || i == 2)) odd++;
                else ng++;
            }
            if(odd == 2 && ng == 0) cout << "OK" << endl;
            else cout << "NG" << endl;
            rep(i,0,101) r[i].clear();
        }
        else {
            r[a].pb(b);
            r[b].pb(a);
        }
    }
    return 0;
}

Measured memory_bytes: 1208
/* C++14 (Clang 3.8.0) for AtCoder */

#include <iostream>
#include <vector>
#include <string>
// #include <cmath>
// #include <math.h>
// #include <map>
// #include <algorithm>

namespace AtCoder {
	using Str = std::vector<std::string>;
	using Num = std::vector<int>;
	using BigNum = std::vector<long long>;

	class InputData {
	public:
		void getInput(void);
		void skipInput(void);
		Str getStr(void);
		Num getNum(void);
		BigNum getBigNum(void);
	private:
		Str str;
		Num num;
		BigNum bNum;
	};
	Str AtCoder::InputData::getStr(void) {
		return this->str;
	}
	Num AtCoder::InputData::getNum(void) {
		return this->num;
	}
	BigNum AtCoder::InputData::getBigNum(void) {
		return this->bNum;
	}
	void AtCoder::InputData::skipInput(void) {
		std::string buf = "";
		std::getline(std::cin, buf);
	}
	void AtCoder::InputData::getInput(void) {
		this->str.clear();
		this->num.clear();
		this->bNum.clear();

		std::string buf = "", row = "";
		std::getline(std::cin, buf);
		for (unsigned int i = 0; i < buf.size(); i++) {
			if (' ' == buf[i]) {
				this->str.push_back(row);
				this->num.push_back(std::atoi(row.c_str()));
				this->bNum.push_back(std::atoll(row.c_str()));
				row = "";
			} else {
				row += buf[i];
			}
		}
		this->str.push_back(row);
		this->num.push_back(std::atoi(row.c_str()));
		this->bNum.push_back(std::atoll(row.c_str()));
	}

	class Ans {
	public:
		void showResult(void);
		void increment(void);
		void increment(long long);
		void decrement(void);
		void decrement(long long);
		long long getResult(void);
	private:
		long long result;
	};
	void Ans::showResult(void) {
		printf("%lld\n", this->result);
	}
	void AtCoder::Ans::increment(void) {
		this->result++;
	}
	void AtCoder::Ans::increment(long long value) {
		this->result += value;
	}
	void AtCoder::Ans::decrement(void) {
		this->result--;
	}
	void AtCoder::Ans::decrement(long long value) {
		this->result -= value;
	}
	long long AtCoder::Ans::getResult(void) {
		return this->result;
	}

	void exp(std::string* str,  Str* newStr) {
		std::string pre = *str;
		newStr->clear();
		for (unsigned int i = 0; i < pre.length(); i++) {
			newStr->push_back(pre.substr(i, 1));
		}
	}
}

int main(void) {

	AtCoder::InputData* data = new AtCoder::InputData();

	data->getInput();

	AtCoder::Str str = data->getStr();

	if ("AAA" == str[0] || 
		"BBB" == str[0]) {
		printf("No\n");
	} else {
		printf("Yes\n");
	}

	delete(data);

	return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ull unsigned long long
#define endl "\n"
#define pb push_back
#define mp make_pair
#define fast_io ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ini(a, i) memset(a, i, sizeof(a))
#define forf(i,a,b) for(int i=a;i<b;i++)
#define forb(i,a,b) for(int i=b-1;i>=a;i--)
#define debug(ar, n) for(int i=0 ; i<n ; ++i) cout<<ar[i]<<' ';cout<<endl;
const int MAX_VALUE = LONG_MAX;
const int MIN_VALUE = LONG_MIN;
const ull U_MAX_VALUE = ULLONG_MAX;
typedef pair<int, int> pi;
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
int max(int a, int b) {if (a > b) return a; else return b;}
int min(int a, int b) {if (a < b) return a; else return b;}


ll mod_power(ll x, ull y, ll p)
{
	ll res = 1;
	x = x % p;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % p;
		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}

ll find_no_of_bits(ll n)
{
	ll bits = 0;
	while (n)
	{
		n /= 2;
		bits++;
	}
	return bits;
}

void solve()
{
	ll n, w;
	cin >> n >> w;
	ll arr[n + 1][2];
	for (ll i = 1; i <= n; i++)
		cin >> arr[i][0] >> arr[i][1];
	ll dp[n + 1][w + 1];
	ini(dp, 0);
	bool picked[n];
	ini(picked, 0);
	for (ll i = 1; i <= n; i++)
	{
		for (ll j = 1; j <= w; j++)
		{
			dp[i][j] = dp[i - 1][j];
			if (j - arr[i][0] >= 0)
				dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - arr[i][0]] + arr[i][1]);
			// cout << dp[i][j] << " ";
		}
		// cout << "\n";
	}
	cout << dp[n][w];
}
signed main()
{
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	fast_io;
	// ll t = 1;
	// cin >> t;
	// while (t--)
	// {
	solve();
	cout << "\n";
	// }

}

Measured memory_bytes: 79232
import sys
from collections import deque, Counter
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())
 
def Main():
    n = I()
    a = list(IL())
    C = Counter(a)
    m = sum(a)
    q = I()
    s = []
    for rep in range(q):
        b,c = IL()
        if b in C:
            m += (c-b)*C[b]
            C[c] += C[b]
            C[b] = 0
        s.append(m)
    for rep in s:
        print(rep)
    return
 
if __name__=='__main__':
    Main()

Measured memory_bytes: 21456
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
using namespace std;

int main(){
  int N,ans;
  double T,A,delta_tmp,tmp_1,tmp_2;
  cin>>N;
  cin>>T;
  cin>>A;
  ans=0;
  delta_tmp=fabs(10000);
  for(int k=1;k<=N;++k){
    cin>>tmp_1;
    tmp_2=T-0.006*tmp_1-A;
    tmp_2=fabs(tmp_2);
    if(tmp_2<delta_tmp){
      delta_tmp=tmp_2;
      ans=k;
    }
  }
cout<<ans;
return 0;
}


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

int func(int x) {
  if (x % 100 != 0) {
    return 0;
  }
  return func(x / 100) + 1;
}

int main(void) {
  int D, N;
  cin >> D >> N;

  int counter = 0;
  
  for (int x = 1; ; x++) {
    if (func(x) == D) {
      counter++;
      if (counter == N) {
        cout << x << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256