akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<tuple>
#include<sstream>
#include<functional>
#include<list>
#include<queue>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
typedef pair<ll, ll> p;
typedef vector<int> vec;
using Graph = vector<vector<int>>;
using graph = vector<vector<ll>>;


const ll inf = (1LL << 31) - 1;
const long long MOD = 1000000007;


int main() {
    ll h, w, m;
    cin >> h >> w >> m;
    vector<p> v1;
    vector<ll> v2, v3;
    rep(i, m) {
        ll a, b;
        cin >> a >> b;
        v1.push_back(p(a, b));
        v2.push_back(a);
        v3.push_back(b);
    }
    sort(all(v1));
    sort(all(v2));
    sort(all(v3));
    graph g1(m), g2(m);
    ll c, d;
    c = v2[0];
    d = v3[0];
    ll cnt = 1, CNT = 1;
    ll memo = 0,MEMO = 0;
    ll n = -1,N = -1;
    repd(i,1, m) {
        if (v2[i] == c)cnt++;
        else {
            if (cnt > memo) {
                memo = cnt;
                n++;
                g1[n].push_back(c);
            }
            if (cnt == memo) {
                g1[n].push_back(c);
            }
            cnt = 1;
            c = v2[i];
        }
        if (v3[i] == d)CNT++;
        else {
            if (CNT > MEMO) {
                MEMO = CNT;
                N++;
                g2[N].push_back(d);
            }
            if (CNT == MEMO) {
                g2[N].push_back(d);
            }
            CNT = 1;
            d = v3[i];
        }
    }
    if (cnt > memo) {
        memo = cnt;
        n++;
        g1[n].push_back(c);
    }
    if (cnt == memo) {
        g1[n].push_back(c);
    }
    if (CNT > MEMO) {
        MEMO = CNT;
        N++;
        g2[N].push_back(d);
    }
    if (CNT == MEMO) {
        g2[N].push_back(d);
    }
    int f = 1;
    rep(i, g1[n].size()) {
        rep(j, g2[N].size()) {
            if (*lower_bound(all(v1), p(g1[n][i], g2[N][j])) != p(g1[n][i], g2[N][j]))f = 0;
            if (f==0)break;
        }
        if (f==0)break;
    }
    cout << memo + MEMO -f << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

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

void dfs(int u, int d, vector<int>& dist, vector<vector<int>>& adj)
{
  dist[u] = d;
  ++d;
  for (int v : adj[u]) {
    if (dist[v] == -1) {
      dfs(v, d, dist, adj);
    }
  }
}

int main()
{
  int N; scanf("%d", &N);
  vector<vector<int>> adj(N + 5);
  int a, b;
  for (int i = 0; i < N - 1; ++i) {
    scanf("%d %d", &a, &b);
    adj[a].push_back(b);
    adj[b].push_back(a);
  }

  vector<int> distA(N + 5, -1), distB(N + 5, -1);
  distA[1] = 0;
  distB[N] = 0;
  dfs(1, 0, distA, adj);
  dfs(N, 0, distB, adj);

  int cntA = 0, cntB = 0;
  for (int i = 2; i <= N - 1; ++i) {
    if (distA[i] <= distB[i]) { ++cntA; }
    else { ++cntB; }
  }
  printf("%s\n", cntA > cntB ? "Fennec" : "Snuke");
  return 0;
}


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

int main(void){
  string s = "CODEFESTIVAL2016";
  string s2;
  cin >> s2;
  int res = 0;
  for(int i = 0;i < (int)s.size();++i){
    if(s[i] != s2[i])++res;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int n;
int f[366];

int cl[3][3]={};

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

#define IN(x,y) (0<=x && x<=2 && 0<=y && y<=2)
int dp[366][3][3][7][7][7][7];
int dfs(int d, int y, int x, int lu, int ru, int lb, int rb)
{
    if(d==n) return 1;
    if(dp[d][y][x][lu][ru][lb][rb]>=0) return dp[d][y][x][lu][ru][lb][rb];

    if(f[d]&cl[y][x]) return 0;

    int ret = 0;
    rep(i,9)
    {
        int ny = y+dy[i], nx = x+dx[i];
        if(!IN(nx,ny)) continue;

        int nlu = lu-1;
        int nru = ru-1;
        int nlb = lb-1;
        int nrb = rb-1;
        if(nx==0 && ny==0) nlu=6;
        if(nx==2 && ny==0) nru=6;
        if(nx==0 && ny==2) nlb=6;
        if(nx==2 && ny==2) nrb=6;

        if(nlu<0 || nru<0 || nlb<0 || nrb<0) continue;

        ret |= dfs(d+1,ny,nx,nlu,nru,nlb,nrb);
    }

    return dp[d][y][x][lu][ru][lb][rb] = ret;
}

int main()
{
    rep(y,3)rep(x,3)
    {
        int p = 4*y+x;
        for(const auto &a:vector<int>({0,1,4,5})) cl[y][x] |= 1<<(p+a);
    }
    while(scanf(" %d", &n),n)
    {
        rep(i,n)
        {
            f[i]=0;
            rep(j,16)
            {
                int a;
                scanf(" %d", &a);
                f[i] |= a<<j;
            }
        }
        memset(dp,-1,sizeof(dp));
        printf("%d\n", dfs(0,1,1,5,5,5,5));
    }
    return 0;
}

Measured memory_bytes: 34068
N=parse(Int,readline())
S=Array{String}(0)
T=Array{Int}(0)
for i=1:N
	s,t=split(readline())
	push!(S,String(s))
	push!(T,parse(Int,t))
end
id=1:N
for i=sort(id,lt=(a,b)->S[a]<S[b]?true:S[a]==S[b]&&T[a]>T[b])
	println(i)
end


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

string s;
int main()
{
	int n, k;
	cin >> n >> k;
	cin >> s;
	
	int* p = new int[n];
	
	int a = 0;
	bool flag = 0;
	int front = 0;
	for (int i = 0; i < n; i ++)
	{
		if (s[i] - '0' != flag)
		{
			p[a] = i;
			flag = !flag;
			a++;
			
		}
		
	}
	p[a] = n;
	
	int max = 0;
	int temp;
	if (k == 0)
	{
		for (int i = 1; i <= a; i += 2)
		{
			if (p[i] - p[i - 1] > max) max = p[i] - p[i - 1];
			
		}
	}
	else if (2 * k > a)
	{
		max = n;
	}
	else
	{
		max = p[2 * k - 1];
		for (int i = 2 * k + 1; i <= a; i += 2)
		{
			temp = p[i] - p[i - 2 * k - 1];
			if (temp > max) max = temp;
		}
		if (a % 2 == 0)
		{
			temp = p[a] - p[a - 2 * k];
			if (temp > max) max = temp;
		}
	}
	cout << max << endl;
}

Measured memory_bytes: 896
import sys
import os

N, M = map(int, input().split())

A = list(map(int, input().split()))

A = sorted(A)[::-1]

thr_A = sum(A) / (4 * M)

result = "Yes"

for m in range(M):
    if A[m] < thr_A:
        result = "No"
        break

print(result)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pi 3.141592653
#define pb push_back
#define pp pop_back
#define mp make_pair
#define in insert
#define ff first
#define ss second
#define mod 1000000007
#define rep(i,n) for(int i = 0 ; i<n ; i++)
#define repr(i,n) for(int i = n-1 ; i>=0 ; i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define SORT(v) sort(v.begin(),v.end())
void solve();
ll gc(ll a,ll b)
{
    if(b==0) return a;
    return gc(b,a%b);
}
signed main()
{
    fast;
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}
void solve() 
{
    int h,n;
    cin>>h>>n;
    int a[n];
    int b[n];
    for(int i=0;i<n;i++)cin>>a[i]>>b[i];
    int dp[h+1];
    dp[0]=0;
    for(int i=1;i<=h;i++){
        int m=1000000007;
        for(int j=0;j<n;j++){
            int x = b[j];
            if(a[j]<i){
                x+=dp[i-a[j]];
            }
            m =m<x?m:x;
        }
        dp[i]=m;
    }
    cout<<dp[h]<<endl;
}

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

using namespace std;

#define FOR(i,n) for(int i=0; i<n; ++i)
#define FORR(i,a,n) for(int i=a; i<n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

const int INF = 0x3f3f3f3f;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
 
//int in() { int x; scanf("%d", &x); return x; }
//ll lin() { ll x; scanf("%lld", &x); return x; }
//void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }

int main(void){

    int n;
    cin >> n;

    ll ans = 0;
    FOR(i, n){
        if((i+1)%3 == 0 || (i+1)%5 == 0) continue;

        ans += i+1;
    }

    cout << ans;
    
    return 0;
}


Measured memory_bytes: 3636
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  int n,m;cin>>n>>m;
  V<int> s(m),c(m);
  rep(i,0,m){
    cin>>s[i]>>c[i];
    s[i]=n-s[i];
  }

  if(n>1){
  rep(i,mpow(10,n-1),mpow(10,n)){

    bool ok=true;
    rep(j,0,m){
      if((i/mpow(10,s[j]))%10!=c[j])ok=false;
    }
    if(ok){
      cout<<i<<ENDL;
      return 0;
    }

  }
  }else{
    rep(i,0,mpow(10,n)){

    bool ok=true;
    rep(j,0,m){
      if((i/mpow(10,s[j]))%10!=c[j])ok=false;
    }
    if(ok){
      cout<<i<<ENDL;
      return 0;
    }

  }
  }

  cout<<-1<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<cassert>
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define FOREACH(i,c) for(__typeof((c).begin())i = (c).begin();i!=(c).end(); ++i)

//v4
int cond = 1;
string to_string(char c){return'\''+string(1,c)+'\'';}
string to_string(const string&s){return'"'+s+'"';}
string to_string(const char*s){return to_string((string)s);}
string to_string(bool b){return(b?"true":"false");}
string to_string(std::vector<bool>::reference&r){return to_string((bool)r);}
template<typename A,typename B>string to_string(const pair<A,B>&p){return"("+to_string(p.first)+", "+to_string(p.second)+")";}
template<typename A>string to_string(A v){int f=1;string r="{";for(auto x:v){if(!f){r+=", ";}f=0;r+=to_string(x);}r+="}";return r;}
template<typename A,typename B>string to_string(map<A,B>v){int f=1;string r="{";for(auto x:v){if(!f){r+=", ";}f=0;r+=to_string(x.first)+" -> "+to_string(x.second);}r+="}";return r;}
void __db(int i,const vector<string>&s){cerr<<endl;}
template<typename T,typename... A>void __db(int i,const vector<string>&s,T t,A... a){if(i)cerr<<", ";cerr<<s[i]<<" = "<<to_string(t);__db(i+1,s,a...);}

string __cl(string s){while(!s.empty()&&s[0]==' ')s.erase(0,1);while(!s.empty()&&s.back()==' ')s.pop_back();return s;}
vector<string>__vars(string s){vector<string>r;s+=",";string n="";int d=0;for(auto x:s)if(x==','&&d==0){if(!n.empty())r.push_back(__cl(n));n="";}else{n+=x;if(x=='('||x=='[')d++;else if(x==')'||x==']')d--;}return r;}
#define DB(...){if(cond){cerr<<"Line:"<<__LINE__<<" ";__db(0,__vars(#__VA_ARGS__),__VA_ARGS__);}}

int rep(int a, int b) {
  int r = b;
  REP(i, a - 1) {
    r = r * 10 + b;
  }
  return r;
}


int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  int v1 = rep(a, b);
  int v2 = rep(b, a);
  printf("%d\n", max(v1, v2));
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int BUF = 500005;
const int MOD = 1000000007;


int mul(int a, int b) {
    return 1LL * a * b % MOD;
}


int add(int a, int b) {
    return (a + b) % MOD;
}


int modPow(int p, int n) {
    if (n == 0) return 1;
    int t = modPow(p, n / 2);
    return n & 1 ? mul(mul(t, t), p) : mul(t, t);
}


int inv(int n) {
    return modPow(n, MOD - 2);
}


int factorial[BUF];
int invFactorial[BUF];

void makeTable() {
    factorial[0] = invFactorial[0] = 1;

    for (int i = 1; i < BUF; ++i) {
        factorial[i] = mul(i, factorial[i - 1]);
        invFactorial[i] = inv(factorial[i]);
    }
}


int nPk(int n, int k) {
    return mul(factorial[n], invFactorial[n - k]);
}


int nCk(int n, int k) {
    return mul(factorial[n], mul(invFactorial[k], invFactorial[n - k]));
}


int N, M;

void read() {
    cin >> N >> M;
}


void work() {
    int ans = 0;
    for (int i = 0; i <= N; ++i) {
        int toAdd;
        toAdd = i % 2 == 0 ? 1 : MOD - 1;
        toAdd = mul(toAdd, nCk(N, i));
        toAdd = mul(toAdd, nPk(M, i));
        toAdd = mul(toAdd, nPk(M - i, N - i));
        toAdd = mul(toAdd, nPk(M - i, N - i));
        ans = add(ans, toAdd);
     }
    cout << ans << endl;
}


int main() {
    makeTable();
    read();
    work();
    return 0;
}

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

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

	for(int n, r; cin >> n >> r, n;) {
		vector<int> cards;
		cards.reserve(n);
		for(int i = n; i > 0; --i)
			cards.push_back(i);

		for(int i = 0; i < r; ++i) {
			int p, c;
			cin >> p >> c;

			vector<int> tmp(cards);
			for(int i = 0; i < p - 1; ++i)
				tmp[i + c] = cards[i];

			for(int i = 0; i < c; ++i)
				tmp[i] = cards[i + p - 1];

			cards.swap(tmp);
		}

		cout << cards[0] << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1224
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => long.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Console.WriteLine(Solve());
		Out.Flush();
	}
	long N, k;
	long[] w, d;
	long Solve()
	{
		var I = GL();
		N = I[0];
		k = I[1];
		w = new long[N];
		d = new long[N];
		for (int i = 0; i < N; i++)
		{
			I = GL();
			w[i] = I[0];
			d[i] = I[1];
		}
		return FirstBinary(0, w.Max() + (k - 1L) * d.Max() + N, Calc);
	}
	bool Calc(long max)
	{
		var c = 0L;
		for (int i = 0; i < N; i++) if (max >= w[i]) c += (max - w[i]) / d[i] + 1;
		return c >= k;
	}
	public static long FirstBinary(long min, long max, Predicate<long> pred)
	{
		while (min < max)
		{
			var mid = min + (max - min) / 2;
			if (pred(mid)) max = mid;
			else min = mid + 1;
		}
		return min;
	}
}


Measured memory_bytes: 18860
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    s = S()
    r = []
    d = {}
    for i in range(26):
        d[string.ascii_uppercase[i]] = string.ascii_uppercase[(i+n)%26]
    for c in s:
        r.append(d[c])

    return JA(r, "")


print(main())





Measured memory_bytes: 6732
#include <bits/stdc++.h>
using std::cerr;using std::cin;using std::cout;using std::abs;using std::min;using std::max;using std::swap;using std::map;using std::multiset;using std::unordered_map;using std::unordered_set;using std::bitset;using std::pair;using std::set;using std::string;using std::vector;using std::sort;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);std::iostream::sync_with_stdio(0);cout<<std::fixed<<std::setprecision(10);cerr<<std::fixed<<std::setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}

int32_t main(){
    multiset<int,std::greater<int>> l;
    multiset<int> r;
    int sl=0,sr=0,s=0;
    int q;
    cin>>q;
    while(q--){
        int t,x,b;
        cin>>t;
        if(t==1){
            cin>>x>>b;
            s+=b;
            if(!l.empty()&&x>*l.begin()){r.insert(x);sr+=x;}
            else{l.insert(x);sl+=x;}
            if(l.size()>r.size()+1){
                x=*l.begin();
                l.erase(l.begin());
                sl-=x;
                r.insert(x);
                sr+=x;
            }
            if(r.size()>l.size()){
                x=*r.begin();
                r.erase(r.begin());
                sr-=x;
                l.insert(x);
                sl+=x;
            }
        }else{
            x=*l.begin();
            int y=(x*l.size()-sl)+(sr-x*r.size())+s;
            cout<<x<<' '<<y<<'\n';
        }
    }
    return 0;
}


Measured memory_bytes: 9600
#include <stdio.h>
#include <stdlib.h>

int main()
{
    long long int n,k;
    scanf("%lld %lld",&n,&k);
    if(n>=k){
        if(n%k<=k/2){
            n=n%k;
        }

    else if(n%k>k/2){
        n=k-(n%k);
    }
    }
    if(n<k){
        if(k<2*n){
            n=k-n;
        }
    }
    printf("%lld",n);


    return 0;
}


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

int main(){

  long long n, m, a[50], b[50], c[50], d[50], p[50], min;

  cin>>n>>m;
  for(int i=0;i<n;i++) cin>>a[i]>>b[i];
  for(int i=0;i<m;i++) cin>>c[i]>>d[i];

  for(int i=0;i<n;i++){
    min=10000000000000000;
    for(int j=0;j<m;j++){
      if(llabs(a[i]-c[j])+llabs(b[i]-d[j])<min){
        min=llabs(a[i]-c[j])+llabs(b[i]-d[j]);
        p[i]=j;
      }
    }
  }

  for(int i=0;i<n;i++) cout<<p[i]+1<<endl;

  return 0;
}


Measured memory_bytes: 256
program kadai
implicit none
integer  ::  n
integer,allocatable  ::  p(:)
integer  ::  i,check


read(*,*) n
allocate(p(n))
read(*,*) p

check=0
do i=1,n
    if (i==p(i)) then
        check=check+1
    end if
end do
if (check==n-2 .or. check==n) then
    write(*,*) "YES"
else
    write(*,*) "NO"
end if


stop

end program kadai


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

int main(){
    long long h, w;
    cin >> h >> w;

    long long n;
    cin >> n;

    vector<long long> a(n);
    for(long long i = 0; i < n; i++) cin >> a[i];
    //for(long long i = 0; i < n; i++) printf("%lld ", a[i]);
    //printf("\n");

    long long ans[h][w];
    long long x = 0;
    long long y = 0;
    long long j = 0;

    //printf("start\n");
    while(y < h){
        //printf("y %lld\n", y);
        x = 0;
        while(y < h and x < w){
            //printf("y %lld x %lld\n", y, x);
            //printf("a[%lld] %lld\n", i, a[i]);
            if(a[j] <= 0) j++;
            
            ans[y][x] = j+1;
            a[j]--;
            x++;
            //printf("y %lld x %lld\n", y, x);
        }
        //printf("a\n");
        y++;
        x = w - 1;
        while(y < h and x >= 0){
            //printf("y %lld x %lld\n", y, x);
            //printf("a[%lld] %lld\n", i, a[i]);
            if(a[j] <= 0) j++;
            //printf("c\n");
            ans[y][x] = j+1;
            
            a[j]--;
            
            x--;
            //printf("y %lld x %lld\n", y, x);
        }
        //printf("b\n");
        y++;
    }

    //printf("finish\n");

    for(long long e = 0; e < h; e++){
        //printf("aaa\n");
        for(long long f = 0; f < w; f++){
            printf("%lld ", ans[e][f]);
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 3744
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include<set>
#include<bitset>
#include<stdio.h>
#include<deque>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;

int main()
{
    int n, ans = 1e5;
    cin >> n;
    vector<int> w(n);
    rep(i, n)cin >> w[i];
    for(int i = 1; i < n; i++){
        int sum1 = 0, sum2 = 0;
        for(int j = 0; j < i; j++){
            sum1 += w[j];
        }
        for(int j = i; j < n; j++){
            sum2 += w[j];
        }
        ans = min(ans, abs(sum1-sum2));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import collections
N=int(input())
D_list=[int(thing) for thing in input().split(" ")]
maxx=max(D_list)
if D_list[0] !=0:
    print(0)
    exit()
C=collections.Counter(D_list)
if C[0] != 1:
    print(0)
    exit()

ret=1
for i in range(0,maxx):
    if maxx-i not in C:
        print(0)
        exit()
    if maxx-i==0:
        pass
    else:
        ret=ret*C[maxx-i-1]**C[maxx-i]

print(ret%998244353)

Measured memory_bytes: 19936
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
using namespace std;
using ll = long long;

int main() {
    int N; cin >> N;
    vvi vec(N, vi(2));

    for (int i = 0; i < N; i++) {
        int x, s; cin >> x >> s;
        vec[i][0] = x - s;
        vec[i][1] = x + s;
    }
    sort(ALL(vec));

    vi left(N), right(N);
    rep(i, N) {
        left[i] = vec[i][0];
        right[i] = vec[i][1];
    }

    vi dp(N + 1);
    dp[N] = 0;
    //dp[N-1] = 1;
    for (int i = N - 1; i >= 0; i--) {
        auto iter = lower_bound(ALL(left), right[i]);

        int j = distance(left.begin(), iter);

        dp[i] = max(dp[i + 1], dp[j] + 1);
    }

    cout << dp[0] << endl;
}

Measured memory_bytes: 9852
//abc127_d.cpp
//Sun Jun 16 13:56:23 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;

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

	priority_queue<ll, vector<ll>, greater<ll>> pq; //小さい順 
	for (int i=0;i<n;i++){
		ll a;
		cin >> a;
		pq.push(a);
	}

	vector<P> cb;
	for (int i=0;i<m;i++){
		P temp;
		cin >> temp.second >> temp.first;
		cb.push_back(temp);
	}

	sort (cb.begin(),cb.end(),greater<P>());

	for (int i=0;i<m;i++){
		ll num = cb[i].first;
		ll count = cb[i].second;
		while (count>0){
			ll temp = pq.top();
			if (num>temp){
				pq.pop();
				pq.push(num);
			}else {
				break;
			}
			count--;
		}
	}

	ll ans = 0;
	for (int i=0;i<n;i++){
		ans += pq.top();
		pq.pop();
	}
	cout << ans << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 4212
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<deque>
#define ll long long
#define mp make_pair
using namespace std;
int a[22],n;
int main(){
	cin>>n;
	int i,j,ans=0;
	for(i=0;i<n;++i) cin>>a[i];
	for(i=1;i<n-1;++i){
		if((a[i-1]<a[i] and a[i]<a[i+1]) or (a[i-1]>a[i] and a[i]>a[i+1])){
//			cerr<<i<<endl;
			++ans;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 888
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>

#define ll long long
#define vl vector<ll>
#define vvl vector< vector<ll> >
#define vb vector<bool>
#define vbb vector< vector<bool> >
#define vs vector<string>
#define vc vector<char>
#define vvc vector< vector<char> >

#define all(a) (a).begin(),(a).end()
using namespace std;

int main(){
	vl a(3); cin >> a[0] >> a[1] >> a[2];
	ll n; cin >> n;
	sort(all(a));
	cout << a[0] + a[1] + a[2] * pow(2, n);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll a, b;
  char op;
  cin>>a>>op>>b;
  if(op=='+') cout<<a+b<<endl;
  else cout<<a-b<<endl;
}



Measured memory_bytes: 3600
dataset = []
while True:
    s = list(map(int,input().split()))

    if sum(s) == 0:
        break
    else:
        dataset.append(s)

for data in dataset:
    for cnt_r in range(data[0]):
        for cnt_c in range(data[1]):
            print('#',end='')
        print()
    print()

Measured memory_bytes: 8940
#include <iostream>

using namespace std;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,i,a[6];

int main(){
	for(i=1;i<=5;i++)
	cin>>a[i];
	
	for(i=1;i<=5;i++)
	if(a[i]==0) cout<<i;
	
	return 0;
}

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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

#define PQ(T) priority_queue<T>
#define RPQ(T) priority_queue<T,vector<T>,greater<T>>

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }

inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
template <typename T>
inline T mod(T a, T b) { return ((a % b) + b) % b; }


void solve(int N, int K){
    int maxk = (N-1)*(N-2)/2;
    if (K > maxk) {
        cout << -1 << endl;
        return;
    }

    vvi conn(N, vi(N, 0));
    for(int j=1; j<N; ++j){
        conn[0][j] = 1;
    }
    int cnt = maxk;
    repC2(i,j,N){
        if (cnt == K) break;
        if (conn[i][j]) continue;

        conn[i][j] = 1;
        --cnt;
    }

    int M = 0;
    repC2(i,j,N){
        if (conn[i][j]) ++M;
    }

    printf("%d\n", M);
    repC2(i,j,N) {
        if (conn[i][j]) {
            printf("%d %d\n", 1+i, 1+j);
        }
    }
}

int main() {
    int N, K; cin >> N >> K;
    solve(N,K);
    return 0;
}


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

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

Measured memory_bytes: 256
import fractions
def LCM(X,Y):
  return X*(Y//fractions.gcd(X,Y))
N,M=[int(s) for s in input().split()]
ls=[int(s) for s in input().split()]

def Oddcheck(lst):
  for num in lst:
    if num%2==0:
      return False
      break
  else:
    return True
def Evencheck(lst):
  for num in lst:
    if num%2==1:
      return False
      break
  else:
    return True

c=1
while Oddcheck(ls)==False:
  if Evencheck(ls)==True:
    c*=2
    for i in range(N):
      ls[i]//=2
  else:
    print(0)
    break
else:
  g=1
  for num in ls:
    g=LCM(g,num)
  g*=c//2
  print((M+g)//(2*g))

Measured memory_bytes: 16308
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

const string er = "er";
const string dream = "dream";
const string eraser = "eraser";
const string erase = "erase";

int main() {
    fastio();

    string s;
    cin >> s;
    bool is_dream = false;
    int i = 0;
    while (i < s.length()) {
        if (s.substr(i, dream.length()) == dream) {
            i += dream.length();
            is_dream = true;
        } else if (s.substr(i, eraser.length()) == eraser) {
            i += eraser.length();
            is_dream = false;
        } else if (s.substr(i, erase.length()) == erase) {
            i += erase.length();
            is_dream = false;
        } else if (is_dream && s.substr(i, er.length()) == er) {
            i += er.length();
            is_dream = false;
        } else {
            cout << "NO\n";
            return 0;
        }
    }

    cout << "YES\n";

    return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	string a,b,c;
	cin>>a>>b>>c;
	string ans="";
	int q,w,e;
	q=a[0]-'a';
	w=b[0]-'a';
	e=c[0]-'a';
	char x;
	x='A'+q;
	ans=ans+x;
	x='A'+w;
	ans=ans+x;
	x='A'+e;
	ans=ans+x;
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;
 
int main()
{
	int N, K;
	cin >> N >> K;
 
	double ans = 0.0;
	for(int i = 1; i <= N; ++i)
	{
		int count = 0;
		for(; static_cast<double>(i) * pow(2.0, count) < K; ++count) {}
		ans += pow(0.5, count) / static_cast<double>(N);
	}
	cout << setprecision(10) << ans << endl;
}

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

using namespace std;

int main() {
	long long n, m, start = 1, end, l, r;
	cin >> n >> m;
    end = n;

    for (int i = 0; i < m; i++) {
        cin >> l >> r;
        if (l > start) {
            start = l;
        }
        if (r < end) {
            end = r;
        }
    }

    long long result = 0;
    if (end < start) {
        result = 0;
    } else {
        result = end - start + 1;
    }

    cout << result;
}


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

int main() {

  vector<int> A(9);
  for(int i=0;i<9;i++){
    cin>>A.at(i);
  }
  
  int N,x=1;
  cin>>N;
  
  vector<int> B(N);
  vector<int> C(9);
  
  for(int i=0;i<N;i++){
    cin>>B.at(i);
  }
  
  for(int i=0;i<9;i++){
    for(int j=0;j<N;j++){
      if(A.at(i)==B.at(j)){
        C.at(i)=1; 
        break;
      }
    }
  }
  
  for(int i=0;i<=6;i+=3){
    if(C.at(i)==1 && C.at(i+1)==1 && C.at(i+2)==1 ){
      x*=0;
      break;
    }
  }
  
  for(int i=0;i<=2;i+=1){
    if(C.at(i)==1 && C.at(i+3)==1 && C.at(i+6)==1 ){
      x*=0;
      break;
    }
  }
  
  
    if(C.at(0)==1 && C.at(4)==1 && C.at(8)==1 ){
      x*=0;
      
    }
  
    if(C.at(2)==1 && C.at(4)==1 && C.at(6)==1 ){
      x*=0;
      
    }
  
  
      
  
  if(x==0){
    cout<<"Yes";
  }
  else{
    cout<<"No";
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
const int ININF = 1000000;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
int main() {
    long long K;
    cin >> K;
    vector<long long> run;
    vector<vector<long long>> mae(10, vector<long long>());
    rep(i, 1, 10) {
        mae[i].push_back(i);
        run.push_back(i);
    }
    rep(i, 0, 100) {
        vector<vector<long long>> nex(10, vector<long long>());
        rep(n, 0, 10) {
            for(auto a : mae[n]) {
                if(n != 0) {
                    nex[n-1].push_back(a * 10 + n - 1);
                    run.push_back(a * 10 + n - 1);
                    // cout << "i:" << i << ",n:" << n << ",mae:" << a
                    //      << "plus:" << a * 10 + n - 1 << endl;
                }
                nex[n].push_back(a * 10 + n);
                run.push_back(a * 10 + n);
                // cout << "i:" << i << ",n:" << n << ",mae:" << a
                //      << "plus:" << a * 10 + n << endl;
                if(n != 9) {
                    nex[n+1].push_back(a * 10 + n + 1);
                    run.push_back(a * 10 + n + 1);
                    // cout << "i:" << i << ",n:" << n << ",mae:" << a
                    //      << "plus:" << a * 10 + n + 1 << endl;
                }
            }
        }
        mae = nex;
        if(run.size() >= K) {
            break;
        }
    }
    sort(run.begin(), run.end());
    cout << run[K - 1] << endl;
}


Measured memory_bytes: 4080
import sys,heapq
R=lambda:map(int,sys.stdin.readline().split())
x=list(R())
k=x.pop()
a=[sorted(R())for _ in range(3)]
h=set()
q=[[-sum(e[-1] for e in a)]+[e-1 for e in x]]
for _ in range(k):
	y=heapq.heappop(q)
	x=y.pop(0)
	print(-x)
	for i in range(3):
		ny=list(y)
		ny[i]-=1
		if y[i] and tuple(ny) not in h:
			h.add(tuple(ny))
			heapq.heappush(q,[x+a[i][y[i]]-a[i][y[i]-1]]+ny)

Measured memory_bytes: 35560
n = int(input())
x = list(map(float, input().split(' ')))
y = list(map(float, input().split(' ')))
p1 = 0.0
p2 = 0.0
p3 = 0.0
pm = 0.0
i = 0
while i < n:
    p1 += abs(x[i] - y[i])
    p2 += pow(abs(x[i] - y[i]), 2)
    p3 += pow(abs(x[i] - y[i]), 3)
    pm = max(pm, abs(x[i] - y[i]))
    i += 1
p2 = pow(p2, 0.5)
p3 = pow(p3, 0.333333333333333)
ans = '{0:.8f}'.format(p1) + '\n'
ans += '{0:.8f}'.format(p2) + '\n'
ans += '{0:.8f}'.format(p3) + '\n'
ans += '{0:.8f}'.format(pm)
print(ans)


Measured memory_bytes: 5668
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

using namespace std;
using ll = long long;

int main() {
  string s;
  cin >> s;
  ll n = static_cast<ll>(s.size());

  ll a = 0;
  ll b = 1;
  vector<ll> vec(2020, 0);
  vec[0] = 1;
  for (ll i = n - 1; 0 <= i; --i) {
    a = (a + b * (s[i] - '0')) % 2019;
    ++vec[a];
    b = (b * 10) % 2019;
  }

  ll ans = 0;
  for (auto &v : vec)
    ans += (v * (v - 1)) / 2;

  cout << ans << endl;
}

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

template<typename T>
ostream& operator<<(ostream &os, vector<T> &v){
	string sep = " ";
	if(v.size()) os << v[0];
	for(int i=1; i<v.size(); i++) os << sep << v[i];
	return os;
}

template<typename T>
istream& operator>>(istream &is, vector<T> &v){
	for(int i=0; i<v.size(); i++) is >> v[i];
	return is;
}

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
	cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__)
#else
#define dbg(...)
#endif

int main() {
	ios_base::sync_with_stdio(false);
	cout << setprecision(20) << fixed;
	int n; cin >> n;
	cout << (n+999)/1000*1000 - n << endl;
	return 0;
}


Measured memory_bytes: 3644
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 998244353
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
    int N;
    string S,T;
    cin >> N >> S >> T;
    int ans=2*N;
    for(int i=N;i>0;i--){
        if(S.substr(N-i,i)==T.substr(0,i)){
            ans-=i;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for (int i = 0; i < n; ++i)
#define REP(i,k,n) for (int i = k; i <= n; ++i)
#define REPR(i,k,n) for (int i = k; i >= n; --i)
#define pb push_back
#define F first
#define mp make_pair
#define debug1(a) cout<<" a : "<<a<<"\n"
#define debug2(a,b) cout<<" a : "<<a<<" b : "<<b<<"\n"
#define debug3(a,b,c) cout<<" a : "<<a<<" b : "<<b<<" c : "<<c<<"\n"
#define M 1000000007

char A[1000][1000];
int B[1000][1000];
int vis[1000][1000];
int h=0,w=0;
void dfs(int a, int b)
{
	rep(i,h)
	{
		rep(j,w) cout<<B[i][j]<<" ";
		cout<<"\n";
	}
	cout<<"\n";
	if ((a-1>=0 && A[a-1][b]=='.') && (b-1>=0 && A[a][b-1]=='.'))
	{
		dfs(a-1,b); dfs(a,b-1);
		B[a][b]+=B[a-1][b]+B[a][b-1];
	}
	else if (a-1>=0 && A[a-1][b]=='.')
	{
		dfs(a-1,b); 
		B[a][b]+=B[a-1][b];
	}
	else if (b-1>=0 && A[a][b-1]=='.')
	{
		dfs(a,b-1);
		B[a][b]+=B[a][b-1];
	}
}

int f(int a, int b)
{
	if (B[a][b]>=0)
		return B[a][b];
	else if ((a-1>=0 && A[a-1][b]=='.') && (b-1>=0 && A[a][b-1]=='.'))
	{
		B[a-1][b]=f(a-1,b)%M; B[a][b-1]=f(a,b-1)%M;
		return (f(a-1,b) + f(a,b-1))%M;
	}
	else if (a-1>=0 && A[a-1][b]=='.')
	{
		B[a-1][b]=f(a-1,b);
		return f(a-1,b); 
	}
	else if (b-1>=0 && A[a][b-1]=='.')
	{
		B[a-1][b]=f(a-1,b);
		return f(a,b-1);
	}
	else return 0;
}

signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>h>>w;
	rep(i,h)
	{
		rep(j,w)
		{
			cin>>A[i][j];
			vis[i][j]=0;
			if (A[i][j]=='.')
			{
				B[i][j]=-1;
			}
			else
			{
				B[i][j]=-1;
			}
		}
	}
	B[0][0]=1;
	cout<<f(h-1,w-1)<<"\n";
	// rep(i,h)
	// {
	// 	rep(j,w) cout<<f(i, j)<<" ";
	// 	cout<<"\n";
	// }
	// cout<<(B[h-2][w-1]+B[h-1][w-2])*((B[h-2][w-1]+B[h-1][w-2])>=0)%M;
}

Measured memory_bytes: 17024
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]

field = 0
for v in b:
	for i in range(9):
		if A[i // 3][i % 3] == v:
			field = field | (1 << i)
ans = False
for v in sum([[273,84],sum([[73<<i,7<<i*3]for i in range(3)],[])],[]):
  ans = ans or field&v==v;
print('Yes' if ans else 'No')


Measured memory_bytes: 9212
#include <iostream>

using namespace std;

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

    long long ans = 0;
    for (int i = 0; i < n; i++) {
        int b;
        cin >> b;

        int x = min(a[i], b);
        a[i] -= x;
        b -= x;
        ans += x;
        x = min(a[i+1], b);
        a[i+1] -= x;
        ans += x;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int main(void) {
    int N,D;

    cin>>N>>D;

    cout<<(N+2*D)/(2*D+1)<<endl;

    return 0;
}




Measured memory_bytes: 256
s = input()
t = input()
len_s = len(s)

import bisect
point_dic = {}
for i in range(26):
    alp = chr( ord('a') + i )
    point_dic[alp] = []

for i in range(len_s):
    i_alp = s[i]
    point_dic[i_alp].append(i+1)

now = 1
cycle = 0
for i in t:
    points = point_dic[i]
    if(len(points) == 0):
        print(-1)
        exit()
    tmp = bisect.bisect_left(points, now)
    if(tmp == len(points)):
        now = points[0]+1
        cycle += 1
    else:
        now = points[tmp]+1

ans = cycle * len_s + now - 1
print(ans)

Measured memory_bytes: 45680
import java.util.*;
public class Main{
	public static void main(String args[]) {
		Scanner sc=new Scanner(System.in);
		int L=sc.nextInt();
		int R=sc.nextInt();
		int Mi,Mj;
		int answer=Math.floorMod(L*R, 2019);
		sc.close();
		for(int i=L;i<R;i++) {
			if((R-L+1)>=2019) {
				answer=0;
				break;
			}
			for(int j=(i+1);j<=R;j++) {
				Mi=Math.floorMod(i, 2019);
				Mj=Math.floorMod(j, 2019);
				if(Math.floorMod(Mi*Mj, 2019)<answer) {
					answer=Math.floorMod(Mi*Mj, 2019);
				}
			}
		}
		System.out.println(answer);
	}
}

Measured memory_bytes: 23124
N = int(input())
A = list(map(int, input().split()))
my_sum = 0
count = 0
r, l = 0, 0

while r < N:
    boo = my_sum + A[r]
    foo = my_sum ^ A[r]
    if boo == foo:
        my_sum += A[r]
        r += 1
        count += (r - l)
    else:
        my_sum -= A[l]
        l += 1

print(count)

Measured memory_bytes: 24840
#include<stdio.h>
int main(void)
{int x,sum,i;
  for(i=0; i<5; i++){
  scanf("%d",&x);
  if(x<=40)
    x=40;
  sum=sum+x;
  }

  sum=sum/5;

  printf("%d\n",sum);

  return(0);

}

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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<ll, ll> ll_ll;
const int MOD = 1e9 + 7;
const ll INF = LLONG_MAX / 2;
struct edge { int i, v, w; };

int main() {
	int H, W; cin >> H >> W;
	vector<vector<ll> > c(10, vector<ll>(10));
	rep(x, 10) rep(y, 10) cin >> c[x][y];
	rep(k, 10) rep(x, 10) rep(y, 10) c[x][y] = min(c[x][y], c[x][k] + c[k][y]);
	ll ans = 0;
	rep(i, H) rep(j, W) {
		int x; cin >> x;
		if (x != -1) ans += c[x][1];
	}
	cout << ans << endl;
}


Measured memory_bytes: 256