akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const int INF = 1e9 + 1;

  // O(|E||V|^2)
template< class Abel > class Dinic {
public:
  Dinic(int _V = 575) : V(_V) { init(_V); }

  void init(int _V) {
    G.resize(_V);
    level.resize(_V);
    iter.resize(_V);
  }
  
  // fromからtoに向かう容量capの辺グラフに追加する
  void add_edge(int _from, int _to, Abel _cap) {
    G[_from].emplace_back(Edge(_to, _cap, G[_to].size()));
    G[_to].emplace_back(Edge(_from, 0, G[_from].size() - 1));
  }

  // sからの最短距離をBFSで探す
  void bfs(int s) {
    level.assign(V, -1);
    queue< int > q;
    level[s] = 0;
    q.push(s);

    while (!q.empty()) {
      int from = q.front(); q.pop();
      for (int i = 0; i < G[from].size(); ++i) {
	Edge &e = G[from][i];
	if (e.cap > 0 && level[e.to] < 0) {
	  level[e.to] = level[from] + 1;
	  q.push(e.to);
	}
      }
    }
  }


  // 増加パスをDFSで探す
  Abel dfs(int from, int to, int cost) {
    if (from == to) return cost;
    for (int &i = iter[from]; i < G[from].size(); ++i) {
      Edge &e = G[from][i];
      if (level[from] < level[e.to] && e.cap > 0) {
	Abel d = dfs(e.to, to, min(cost, e.cap));
	if (d > 0) {
	  e.cap -= d;
	  G[e.to][e.rev].cap += d;
	  return d;
	}
      }
    }
    return 0;
  }


  // sからtへの最大流を求める
  Abel max_flow(int s, int t) {
    int flow = 0;
    for ( ; ; ) {
      bfs(s);
      if (level[t] < 0) return flow;
      iter.assign(V, 0);
      Abel f;
      while ((f = dfs(s, t, INF)) > 0) { 
	flow += f;
      }
    }
  }

private:
  struct Edge {
    Edge(int _to, Abel _cap, int _rev)
      : to(_to), cap(_cap), rev(_rev) {}
    int to;
    Abel cap; // 容量
    int rev; // 逆辺
  };

  int V;
  vector< vector< Edge > > G; // グラフの隣接リスト表現
  vector< int > level;        // sからの距離
  vector< int > iter;         // どこまで調べ終わったか

};

int main()
{
  int V, E, u, v, c;
  cin >> V >> E;

  Dinic< int > d(V + 1);
  while (E--) {
    cin >> u >> v >> c;
    d.add_edge(u, v, c);
  }
  cout << d.max_flow(0, V - 1) << endl;
  
  return 0;
}



Measured memory_bytes: 3128
n,m = map(int,input().split())
d = [None]*n
for i in range(n):
    a,b = map(int,input().split())
    d[i] = [a,b]

d.sort(key=lambda x: x[0])

ryoukin = 0
cnt = 0
for lst in d:
    for i in range(lst[1]):
        ryoukin += lst[0]
        cnt += 1
        if cnt == m:
            break
    if cnt == m:
        break    
print(ryoukin)

Measured memory_bytes: 21204
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rrep(i,n) REP(i,1,n+1)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> PII;
typedef vector<ll> Vl;
typedef vector<int> VI;
typedef tuple<int, int, int> TT;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
const int MAX = 500000;
const int inf = 1000000007;
const ll mod = 1000000007;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

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


int n, m, q, ans;
int a[55], b[55], c[55], d[55];
int total[10];

void dfs(int cnt, int num) {
	if (cnt == n) {
		int x = 0;
		rep(i, q) {
			if (total[b[i] - 1] - total[a[i] - 1] == c[i])x += d[i];
		}
		ans = max(x, ans);
		return;
	}
	else if (num == m + 1) {
		return;
	}
	else {
		total[cnt] = num;
		dfs(cnt + 1, num);
		dfs(cnt, num + 1);
	}
	return;
}

int main() {

	cin >> n >> m >> q;
	rep(i, q) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}

	dfs(0, 1);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

int main()
{
  string s;
  ll k;
  cin >> s >> k;

  for(int i = 0; i < s.size(); i++){
    if(s[i] != '1'){
      cout << s[i] << endl;
      break;
    } else {
      k--;
      if(k == 0){
        cout << 1 << endl;
        break;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll
int going[10][10];

string calc(string a) {
	int now = 0;
	REP(q, a.length()) {
		now = going[now][a[q] - '0'];
	}
	if(a.length() == 4){
		a.push_back(now + '0');
		return a;
	}
	if (now != 0) {
		a.clear();
	}
	return a;
}

void solve() {
	REP(i, 10) {
		REP(q, 10) {
			cin >> going[i][q];
		}
	}
	int ans = 0;
	REP(i, 10000) {
		string s = to_string(i);
		reverse(ALL(s));
		while (s.size() != 4) {
			s.push_back('0');
		}
		reverse(ALL(s));
		s = calc(s);
		int cnt = 0;
		REP(i, s.length()) {
			REP(q, 10) {
				string b = s;
				if (b[i] == q + '0') continue;
				b[i] = q + '0';
				if (calc(b).empty() == false) {
					cnt = 1;
				}
			}
		}
		REP(i, s.length()) {
			for (int q = i + 1; q < s.length()&&q < i+2; ++q) {
				string b = s;
				if (b[i] == b[q]) continue;
				swap(b[i], b[q]);
				if (calc(b).empty() == false) {
					cnt = 1;
				}
			}
		}
		ans += cnt;
	}
	cout << ans << endl;
}

#undef int
int main() {
	init();
	solve();
}


Measured memory_bytes: 3296
while(True):
    A=[]
    B=[]
    a=int(input())
    for i in range(a):
     b,c=map(int, input().split(' '))
     d=int(b)+int(c)
     if int(b)>int(c):
        A.append(int(d))
      
     if int(b)<int(c):
         B.append(int(d))

     if int(b)==int(c):
         A.append(int(b))
         B.append(int(c))

    
    if int(a)==0:
        break
    print(sum(A),sum(B))



Measured memory_bytes: 5728
#include<stdio.h>
#include<math.h>
#include<stdio.h>
#ifndef min
#define min(a,b) (a) < (b) ? (a) : (b)
#endif
#define INF 9999999
int e,*d;

int all(){
	int x,y,p,q,minm=INF;
	for(y=(int)sqrt(e);y>=0;y--){
		p=y*y;
		for(x=(int)pow(e,5.0/12.0);x>=0;x--){
			q=x*x*x+p;
			if(q>e)continue;
			minm=min(minm,x+y+(e-q));
			//printf("x=%d,y=%d,x+y+(e-q)=%d\n",x,y,x+y+(e-q));
		}
	}
	return minm;
}
/*void init(){
	int x,y,z,p;
	for(x=0;x<=100;x++)for(y=0;y<=1000;y++){
		p=x*x*x+y*y;
		if(p<=1000000){
			if(d[p])d[p]=min(d[p],x+y);
			else d[p]=x+y;
		}
	}
	for(x=2;x<1000000;x++)if(!d[x])for(y=x-1,z=1;;y--,z++)if(d[y]){
					d[x]=d[y]+z;
					break;
	}
}*/
int main(){
	int i,j;
	d=(int *)malloc(sizeof(int)*1000000);
	for(i=0;i<=1000000;i++)d[i]=0;
	//init();
	while((scanf("%d",&e))!=-1){
		if(e==0)break;
		printf("%d\n",all());
	}
	return 0;
}

Measured memory_bytes: 4572
a,b = map(int, input().split())

l= [1]
x = 0
for i in range(1,1000):
    x = l[i-1] + i+1
    l.append(x)

for j in range(len(l)-1):
    if l[j+1] - l[j] == b-a:
        print(l[j] - a)
        break



Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;

int N, K;
vector<int> V;
int main(void){
    cin >> K >> N;
    int A;
    REP(i, N) {
        cin >> A;
        V.push_back(A);
    }
    sort(V.begin(), V.end());
    int m = V[N-1] - V[0];
    for(int i=1;i<N;i++) m = min(K + V[i-1] - V[i], m);
    cout << m << endl;
    return 0;
}



Measured memory_bytes: 1400
#include<bits/stdc++.h>
#define INF 2147483647
#define inf 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
lol a,b;
lol i[3000];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  lol c=1,d=1,e=0,f=0,g=0,h=0;
  cin >>a;
  for(int n=0;n<a;n++) cin >>i[n];
  sort(i,i+a);
  for(int n=0;n<a-2;n++){
      for(int m=n+1;m<a-1;m++){
	  for(int nm=m+1;nm<a;nm++){
	      if(i[n]<i[m]+i[nm]&&i[m]<i[n]+i[nm]&&i[nm]<i[n]+i[m]) e++;
	      else break;
	  }
      }
  }
  cout <<e<<'\n';
  return (0);
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

#define rep(i, s, n) for(int i = s;i<n;i++)
#define repe(i, s, n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<int> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
static const ll maxLL = (ll) 1 << 62;
const ll MOD = 1000000007, INF = 1e18;
int dy[] = {-1, 0, 1, 0};
int dx[] = {0, 1, 0, -1};

template<typename T1, typename T2>
bool pairCompare(const pair<T1, T2> &firstElof, const pair<T1, T2> &secondElof) {
    return firstElof.second > secondElof.second;
}

int mapMaxValue(std::map<ll, int> m) {
    int max = 0;
    for (std::map<ll, int>::iterator it = m.begin(); it != m.end(); it++) {
        if (max < it->second) max = it->second;
    }
    return max;
}

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

Measured memory_bytes: 256
res = {1:300000, 2:200000, 3:100000}
a, b = map(int, input().split())
if a == b == 1:
	c = 400000
else:
	c = 0
try:
	a = res[a]
except:
	a = 0
try:
	b = res[b]
except:
	b = 0
print(c+a+b)

Measured memory_bytes: 3316
#include <stdio.h>

int main(){
  int a,b,c;

  scanf ("%d%d%d",&a,&b,&c);

  if (a>=b&&b>=c)printf("%d %d %d\n",c,b,a);
  else if (a>=b&&b<=c&&a>=c)printf ("%d %d %d\n",b,c,a);
  else if (a>=b&&b<=c&&a<=c)printf ("%d %d %d\n",b,a,c);
  else if (a<=b&&b>=c&&a>=c)printf ("%d %d %d\n",c,a,b);
  else if (a<=b&&b>=c&&a<=c)printf ("%d %d %d\n",a,c,b);
  else printf ("%d %d %d\n",a,b,c);
  
  return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define int long
#define mod 1000000007
#define inf 10000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
using namespace std;


int32_t main(){
    int n,cap;
    cin>>n>>cap;
    int value[n];
    int wt[n];
    for (size_t i = 0 ; i < n; i++) {
        cin>>wt[i]>>value[i];
    }
    int maxval = n*1000 + 1;
    int dp[n+1][maxval];
    dp[1][0] = 0;
    for (size_t val = 1 ; val < maxval; val++) {
        dp[1][val] = inf;
    }
    dp[1][value[0]] = wt[0];
    for (size_t items = 2 ; items <= n; items++ ) {
        for (size_t val = 0 ; val < maxval; val++) {
            int op1 = ((val >= value[items-1]) ? (wt[items-1] + dp[items-1][val - value[items-1]]) : inf);
            int op2 = dp[items - 1][val];
            dp[items][val] = min(op1,op2);
        }
    }
    int ans = 0;
    for (size_t i = 0 ; i < maxval; i++) {
        if (dp[n][i] <= cap) {
            ans = i;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

int     main() {
        vector<vector<int>> A(26, vector<int> (1, 0));
        string s;
        cin >>s;
        for (int i=0; i<s.size(); i++) {
                int c=s.at(i)-'a';
                A.at(c).push_back(i+1);
        }
        for (int i=0; i<26; i++) {
                if (A.at(i).size()<=2)
                        continue;
                int L=1;
                int R=A.at(i).size()-1;
                while ((A.at(i).at(R)-A.at(i).at(L))+1>=(R-L+1)*2) {
                        if (R==L)
                                break;
                        if (A.at(i).at(L+1)-A.at(i).at(L)>A.at(i).at(R)-A.at(i).at(R-1))
                                L++;
                        else
                                R--;
                }
                if (R!=L) {
                        cout <<A.at(i).at(L) <<' ' <<A.at(i).at(R) <<endl;
                        return 0;
                }
        }
        cout <<"-1 -1" <<endl;
        return 0;
};

Measured memory_bytes: 1148
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;

int main(){
    int N;
    ll Y;
    cin >> N >> Y;

    for(int x=0; x<=N; x++){
        for(int y=0; y<=N-x; y++){
            if(10000*x + 5000*y + 1000*(N-x-y) == Y){
                cout << x << " "<< y << " " << N-x-y << endl;
                return 0;
            }
        }
    }
    cout << -1 << " "<<  -1 << " " << -1 << endl;
}


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

class MyClass
{
    public static void Main(string[] args)
    {
        var input = Console.ReadLine().Split();
        var a = int.Parse(input[0]);
        var b = int.Parse(input[1]);
        var C = int.Parse(input[2]);
        var c = Math.Sqrt(a * a + b * b - 2 * a * b * Math.Cos(C * Math.PI / 180));
        var h = b * Math.Sin(C * Math.PI / 180);
        var S = a*h/2;
        var L = a + b + c;
        Console.WriteLine(S);
        Console.WriteLine(L);
        Console.WriteLine(h);
   }
}


Measured memory_bytes: 15980
def resolve():
    '''
    code here
    '''
    N, M = [int(item) for item in input().split()]
    As = [[int(item) for item in input().split()] for _ in range(N)]

    memo = [0 for _ in range(M+1)]

    for k, *items in As:
        for item in items:
            memo[item] += 1
    res = 0
    for item in memo:
        if item == N:
            res += 1

    print(res)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9200
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <map>
using namespace std;
typedef long long ll;
#define GG puts("FUCK")
#define N 200050
int n,a[N],h[30],num;
void add(int x) {
	int i;
	for(i=19;i>=0;i--) if(x&(1<<i)) {
		h[i]++; if(h[i]==2) num++;
	}
}
void del(int x) {
	int i;
	for(i=19;i>=0;i--) if(x&(1<<i)) {
		h[i]--; if(h[i]==1) num--;
	}
}
int main() {
	scanf("%d",&n);
	int i;
	for(i=1;i<=n;i++) {
		scanf("%d",&a[i]);
	}
	ll ans=0;
	int j=1;
	for(i=1;i<=n;i++) {
		add(a[i]);
		while(j<=i&&num) del(a[j]),j++;
		ans+=(i-j+1);
	}
	printf("%lld\n",ans);
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;

template<typename A,typename B> inline void chmin(A &a,B b){if(a>b) a=b;}
template<typename A,typename B> inline void chmax(A &a,B b){if(a<b) a=b;}
//-----------------------------------------------------------------------

const int N=123456*2;
bool isPrime[N+1];

void calc()
{
// N=123456*2?????§????´???°????±???????
    for(int i=2;i<=N;i++) isPrime[i]=true;
    for(int i=2;i<=N;i++){
        if(!isPrime[i]) continue;
        for(int j=2*i;j<=N;j+=i){
            isPrime[j]=false;
        }
    }
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    calc();

    int n;
    while(cin>>n,n)
    {
        int cnt=0;
        for(int i=n+1;i<=2*n;i++){
            if(isPrime[i]) cnt++;
        }
        cout<<cnt<<endl;
    }
}

Measured memory_bytes: 3392
#include"bits/stdc++.h"
using namespace std;

vector<int> G[105000];
int dist[2][100500] = {};
int ans = 0;

void DFS(int node, int parent, int man)
{
  for(auto it: G[node]){
    if(it != parent){
      dist[man][it] = dist[man][node] + 1;
      DFS(it, node, man);
    }
  }
}
int main()
{
  int n, v, u;
  cin >> n >> u >> v;
  for(int i=0; i<n-1; i++){
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  DFS(u, -1, 0);
  DFS(v, -1, 1);

  for(int i=1; i<=n; i++){
    if(dist[0][i]<dist[1][i]){
      ans = max(ans, dist[1][i]-1);
    }
  }

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


Measured memory_bytes: 13056
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define repr(i,n) for (int i = n; i >= 0; --i)
#define P pair<int, int>
#define ALL(x) (x).begin(),(x).end()
const int INF = 1e9;
using namespace std;

const int MAX_N = 100000;

int main() {	
	int n, s[MAX_N], t[MAX_N];
	P tips[MAX_N];
	cin >> n;
	rep(i,n) cin >> s[i] >> t[i];
	rep(i,n) {
		tips[i] = P(s[i]+t[i], s[i]-t[i]);	
		}
	sort(tips, tips+n);
	
	int count=0, previousRobotArm=-INF;
	rep(i,n) {
		if(previousRobotArm <= tips[i].second) {
			count++;
			previousRobotArm = tips[i].first;
		}
	}
	cout << count << endl;
	}

Measured memory_bytes: 5160
#include "bits/stdc++.h"
using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 2e18 * 2;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };


int main() {
	int l, i;
	cin >> l;
	string s, t;
	cin >> s >> t;
	string s2 = s + s + t + t;
	string t2 = t + t + s + s;
	if (s2 > t2) {
		swap(s, t);
	}
	int a, b;
	for (a = l / s.size(); a >= 0; a--) {
		if ((l - a*s.size()) % t.size() == 0) {
			b = (l - a*s.size()) / t.size();
			break;
		}
	}
	string ans;
	for (i = 0; i < a; i++) {
		ans += s;
	}
	for (i = 0; i < b; i++) {
		ans += t;
	}
	string ans2;
	if (l%s.size() == 0) {
		for (int i = 0; i < l / s.size(); i++) {
			ans2 += s;
		}
		ans = min(ans, ans2);
	}
	ans2.clear();
	if (l%t.size() == 0) {
		for (int i = 0; i < l / t.size(); i++) {
			ans2 += t;
		}
		ans = min(ans, ans2);
	}
	ans2.clear();
	if ((l - s.size())%t.size() == 0) {
		ans2 += s;
		for (int i = 0; i < (l - s.size()) / t.size(); i++) {
			ans2 += t;
		}
		ans = min(ans, ans2);
	}
	ans2.clear();
	if ((l - t.size()) % s.size() == 0) {
		ans2 += t;
		for (int i = 0; i < (l - t.size()) / s.size(); i++) {
			ans2 += s;
		}
		ans = min(ans, ans2);
	}
	cout << ans << endl;
}

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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

int n;
string s[1001];

int main(){
  while( cin >> n, n ){
    int maxi = 0;
    rep(i,n) { cin >> s[i]; maxi = max(maxi,(int)s[i].size()); }
    rep(x,maxi){
      int plus = 0;
      vector<int> ys;
      rep(y,n) if( x < s[y].size() ){
	if( s[y][x] == '.' && ( x+1 < s[y].size() && s[y][x+1] != '.' ) ) {
	  ++plus;
	  s[y][x] = '+';
	  ys.push_back(y);
	}
      }
      rep(i,(int)ys.size()-1){
	int sp = ys[i], ep = ys[i+1];
	bool success = true;
	REP(y,sp+1,ep) if( ( x >= s[y].size() ) || s[y][x] != '.' ) { success = false; break; }
	if( success ) {
	  REP(y,sp+1,ep) s[y][x] = '|';
	}
      }
      rep(y,n) if( x < s[y].size() && s[y][x] == '.' )  s[y][x] = ' ';
    }
    rep(i,n) cout << s[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 2008
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e3+5;

long long a;
long long b;
long long c;
long long d;

long long get(long long A , long long B){
        return A / B;
}

int main(){
    cin >> a >> b >> c >> d;
    long long ans = (b - a + 1) - (get(b , c) + get(b , d) - get(b , c*d/__gcd(c , d)));
    ans +=  get(a-1 , c) + get(a-1 , d) - get(a-1 , c*d/__gcd(c , d));
    cout << ans << endl;
}

// a <= b


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

int main() {
  
  int N, A, B;
  cin >> N >> A >> B;
  
  if(N*A < B)
  cout << A*N << endl;
  
  if(N*A > B)
  cout << B << endl;
  
  if(N*A == B)
  cout << B << endl;

}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int h = sc.nextInt();
		int w = sc.nextInt();
		int k = sc.nextInt();
		int MOD = 1000000007;

		// 計算
		long result = 0;
		long[][] c = new long[w][2];
		c[0][0] = 1;
		c[0][1] = 1;
		if(w > 1){
		    c[1][0] = 1;
		    c[1][1] = 2;
		}
		for(int i = 2; i < w; i++){
		    c[i][0] = (c[i-2][0] + c[i-2][1])%MOD;
		    c[i][1] = (c[i-1][0] + c[i-1][1])%MOD;
		}
		long[][] d = new long[h+1][w+2];
		d[0][1] = 1;
		for(int i = 1; i <= h; i++){
		    for(int j = 1; j <= w; j++){
		        long cr = 1;
		        long cl = 1;
		        long cr2 = 1;
		        long cl2 = 1;
		        if(w-j-1 > 0) cr = (c[w-j-2][0] + c[w-j-2][1])%MOD;
		        if(w-j-2 > 0) cr2 = (c[w-j-3][0] + c[w-j-3][1])%MOD;
		        if(j-2 > 0) cl = (c[j-3][0] + c[j-3][1])%MOD;
		        if(j-3 > 0) cl2 = (c[j-4][0] + c[j-4][1])%MOD;
		        d[i][j] = (d[i-1][j-1] * cl2 * cr)%MOD
		                + (d[i-1][j] * cl * cr)%MOD
		                + (d[i-1][j+1] * cl * cr2)%MOD;
		        d[i][j] %= MOD;
		    }
		}
		result = d[h][k];

		// 出力
		System.out.println(result);
		
	}
}

Measured memory_bytes: 23124
#K : XYZそれぞれは、0以上K以下
#S : X+Y+Zの合計値を示すS

K,S = map(int,input().split())

X=Y=Z=0
result = 0
for x in range(K+1):
    for y in range ( K+1 ):
        if 0 <= S-X-Y <=K:
            result +=1
        # Z = S-X-Y
        # # print("XYZ",X,Y,Z)
        # if X+Y+Z == S:
        #     if  Z<=K :
        #         result+=1 
        Y+=1
    Y=0
    X+=1

print(result)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int a,i,c=0;
    cin>>a>>s;
    for(i=0;i<s.size();i++)
    {
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
        {
            c++;
        }
    }
    cout<<c<<endl;

    return 0;

}



Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#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 <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int dp[10010];
signed main() {
    int C, N, M; cin >> C >> N >> M;
    fill(dp, dp + C + 1, -1);
    dp[0] = 0;
    for(int i=0; i<N; i++) {
        int s, p; cin >> s >> p;
        for(int j=C-s; j>=0; j--) {
            if(dp[j] < 0) continue;
            chmax(dp[j+s], dp[j] + p);
        }
    }

    for(int i=1; i<=C; i++) {
        chmax(dp[i], dp[i-1]);
    }

    for(int k=1; k<=M; k++) {
        cout << dp[C/k] * k << endl;
    }
    return 0;
}



Measured memory_bytes: 3164
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

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

int main(){
	string s;
	cin >> s;
	int k;
	cin >> k;
	vector<string> a;
	for(int i=1; i<=k && i<=s.length(); i++){
		for(int j=0; j<=s.length()-i; j++){
			a.push_back(s.substr(j, i));
		}
	}
	sort(a.begin(), a.end());
	a.erase(unique(a.begin(), a.end()), a.end());
	cout << a[k-1] << endl;
	return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n, k);
    Cins(int, n, a);

    ll ans = 0;
    For(i, n){
        if(a[i] >= k) ans ++;
    }
    Cout(ans);
}




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

int main() {
    vector<char> vec(4);
    for(int i = 0; i < 4; i++){
        cin >> vec.at(i);
    }
    int count = 0;
    for(int i = 0; i < 4; i++){
        if(vec.at(i) == '+'){
            count = count + 1;
        } else if(vec.at(i) == '-'){
            count = count - 1;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N + 1);
  for (int i = 0; i <= N; i++){
    cin >> A[i];
  }
  if (N == 0){
    if (A[0] != 1){
      cout << -1 << endl;
    } else {
      cout << 1 << endl;
    }
  } else if (A[0] != 0){
    cout << -1 << endl;
  } else {
    vector<long long> sum(N + 1, 0);
    sum[N] = 0;
    for (int i = N; i >= 1; i--){
      sum[i - 1] = sum[i] + A[i];
    }
    /*
    for (int i = 0; i <= N; i++){
      cout << sum[i] << ' ';
    }
    cout << endl;
    */
    vector<long long> B(N + 1, 0);
    B[0] = 1;
    for (int i = 0; i < N; i++){
      long long tmp = B[i] * 2 - A[i + 1];
      B[i + 1] = min(tmp, sum[i + 1]);
    }
    /*
    for (int i = 0; i <= N; i++){
      cout << B[i] << ' ';
    }
    cout << endl;
    */
    bool ok = true;
    for (int i = 0; i <= N; i++){
      if (B[i] < 0){
        ok = false;
      }
    }
    if (!ok){
      cout << -1 << endl;
    } else {
      long long ans = 0;
      for (int i = 0; i <= N; i++){
        ans += A[i];
        ans += B[i];
      }
      cout << ans << endl;
    }
  }
}

Measured memory_bytes: 5372
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n,cnt=1;
  cin >> n;
  long long int a[n],x,ans=0;
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  sort(a,a+n);
  for(long long int i=0;i<n;i++){
      if(cnt==1) {
        x=a[i];
      }
      if(x==a[i+1]) cnt++;
      if(x>cnt&&a[i+1]!=x){
        ans+=cnt;
        cnt=1;
      }
      if(x<cnt&&a[i+1]!=x){
        ans+=(cnt-x);
        cnt=1;
      }
      if(x==cnt&&a[i+1]!=x) cnt=1;
}
cout<< ans<<endl;
}


Measured memory_bytes: 1024
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vim:fenc=utf-8 ff=unix


def solv(S, T, A, B, U):
    if S == U:
        A -= 1
    elif T == U:
        B -= 1
    return A, B


if __name__ == "__main__":

    S, T = input().split()
    A, B = map(int, input().split())
    U = input()
    a1, a2 = solv(S, T, A, B, U)

    print(a1, a2)


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	string s, t;
	cin >> s >> t;
	int count = 0;
	for (int i = 0; i < 3; i++) {
		
		if (s[i] == t[i]) {
			count++;
		}
		
	}
	cout << count << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.Closeable;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

public class Main {
	static ContestScanner in;
	static Writer out;
	public static void main(String[] args) {
		try {
			in = new ContestScanner();
			out = new Writer();
			new Main().solve();
			in.close();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	void solve() throws IOException {
		int n = in.nextInt();
		tree = new List[n];
		for(int i = 0; i < n; i++) tree[i] = new ArrayList<>();
		for(int i = 0; i < n - 1; i++) {
			int a = in.nextInt() - 1;
			int b = in.nextInt() - 1;
			tree[a].add(b);
			tree[b].add(a);
		}
		int root = -1;
		for(int i = 0; i < n; i++) {
			if(tree[i].size() == 1) {
				root = i;
				break;
			}
		}
		System.out.println(dfs(root, -1) > 0 ? "First" : "Second");
		
	}
	
	List<Integer>[] tree;
	int dfs(int cur, int par) {
		int cnt = 0;
		for(int v: tree[cur]) {
			if(v == par) continue;
			cnt += dfs(v, cur);
		}
		return cnt > 1 ? cnt : (cnt ^ 1);
	}
}


class Writer extends PrintWriter{
	public Writer(String filename)throws IOException
	{super(new BufferedWriter(new FileWriter(filename)));}
	public Writer()throws IOException{super(System.out);}
}
class ContestScanner implements Closeable{
	private BufferedReader in;private int c=-2;
	public ContestScanner()throws IOException 
	{in=new BufferedReader(new InputStreamReader(System.in));}
	public ContestScanner(String filename)throws IOException
	{in=new BufferedReader(new InputStreamReader(new FileInputStream(filename)));}
	public String nextToken()throws IOException {
		StringBuilder sb=new StringBuilder();
		while((c=in.read())!=-1&&Character.isWhitespace(c));
		while(c!=-1&&!Character.isWhitespace(c)){sb.append((char)c);c=in.read();}
		return sb.toString();
	}
	public String readLine()throws IOException{
		StringBuilder sb=new StringBuilder();if(c==-2)c=in.read();
		while(c!=-1&&c!='\n'&&c!='\r'){sb.append((char)c);c=in.read();}
		return sb.toString();
	}
	public long nextLong()throws IOException,NumberFormatException
	{return Long.parseLong(nextToken());}
	public int nextInt()throws NumberFormatException,IOException
	{return(int)nextLong();}
	public double nextDouble()throws NumberFormatException,IOException 
	{return Double.parseDouble(nextToken());}
	public void close() throws IOException {in.close();}
}

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

typedef long long ll;

main()
{
    string s, t;
    cin >> s >> t;
    int c = 0;
    for(int i = 0; i < 3; i++){
        if(s[i] == t[i]){
            c++;
        }
    }
    cout << c;



}





///promy_pompom
//hello world


Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {

    static long[][] dp;

    static long max(long a, long b){
        if(a > b)
            return a;
        return b;
    }

    static long calculate(int[][] arr, int pos, int currentWeigth){
        if(pos >= arr.length)
            return 0;
        if(arr[pos][0] <= currentWeigth){
            if(dp[pos][currentWeigth] != -1)
                return dp[pos][currentWeigth];
            dp[pos][currentWeigth] = max(arr[pos][1]+calculate(arr,pos+1,currentWeigth-arr[pos][0]),
                    calculate(arr,pos+1,currentWeigth));
            return dp[pos][currentWeigth];
        }
        else{
            dp[pos][currentWeigth] = calculate(arr,pos+1,currentWeigth);
            return dp[pos][currentWeigth];
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int w = sc.nextInt();

        dp = new long[n][w+1];

        int[][] arr = new int[n][2];

        for(int i = 0; i < n; i++){
            arr[i][0] = sc.nextInt();
            arr[i][1] = sc.nextInt();
        }

        for(int i = 0; i < n; i++){
            for(int j = 0; j < w+1 ; j++){
                dp[i][j] = -1;
            }
        }

        System.out.println(calculate(arr,0,w));
    }
}


Measured memory_bytes: 125652
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        exit()
    ans = 0
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            for k in range(j+1, n+1):
                if i+j+k == x:
                    ans += 1
    print(ans)


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

using namespace std;
using ll = long long;
using pii = pair<ll, ll>;

string S;
int N;

int main(){

    cin >> N;
    cin >> S;
    int cnt = 0;
    for(int i = 0; i < N - 2; i++){
        if(S.substr(i, 3) == "ABC"){
            cnt++;
        }
    }
    cout << cnt << endl;
    

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define clr(x) memset(x, 0, sizeof x)
using namespace std;

const int N = 20005;

int m, tab[N], pos[N];
int id[N], x[N];

namespace Graph {
#define mid ((L + R) >> 1)
#define ID(L, R) ((L + R) | (L != R))
#define no ID(L, R)
#define lc ID(L, mid)
#define rc ID(mid + 1, R)
	struct edge {
		int nxt, to;
	} e[8000000];
	int fir[N << 2], cnt;
	int dfn[N << 2], low[N << 2], bel[N << 2], clo, cnt_bcc;
	int sta[N << 2], top;
	
	inline void addedge(int x, int y) {
		e[++ cnt] = (edge){fir[x], y};
		fir[x] = cnt;
	}
	
	inline void Addedge(int l, int r, int x, int L = 0, int R = m) {
		if (L == l && R == r) return (void)(addedge(x, no));
		if (r <= mid) Addedge(l, r, x, L, mid);
		else if (l > mid) Addedge(l, r, x, mid + 1, R);
		else {
			Addedge(l, mid, x, L, mid);
			Addedge(mid + 1, r, x, mid + 1, R);
		}
	}
	
	inline void tarjan(int x) {
		dfn[x] = low[x] = ++ clo;
		sta[++ top] = x;
		for (int i = fir[x]; i; i = e[i].nxt) {
			if (!dfn[e[i].to]) {
				tarjan(e[i].to);
				low[x] = min(low[x], low[e[i].to]);
			}
			else if (!bel[e[i].to]) low[x] = min(low[x], dfn[e[i].to]);
		}
		if (dfn[x] == low[x]) {
			int cur = -1;
			cnt_bcc ++;
			while (cur != x) {
				cur = sta[top --];
				bel[cur] = cnt_bcc;
			}
		}
	}
	
	inline void Build(int L = 0, int R = m) {
		if (L == R) return;
		Build(L, mid);
		Build(mid + 1, R);
		addedge(no, lc);
		addedge(no, rc);
	}
	
	inline bool check(int ans) {
		clr(fir); clr(dfn); clr(low); clr(bel); cnt = 0; cnt_bcc = 0; clo = 0;
		Build();
		int l, r;
		for (int i = 0; i <= m; i ++) {
			l = lower_bound(tab, tab + m + 1, x[i] - ans) - tab;
			r = upper_bound(tab, tab + m + 1, x[i] + ans) - tab - 1;
			if (l <= pos[i] && pos[i] <= r) {
				if (l < pos[i]) Addedge(l, pos[i] - 1, ID(pos[i ^ 1], pos[i ^ 1]));
				if (pos[i] < r) Addedge(pos[i] + 1, r, ID(pos[i ^ 1], pos[i ^ 1]));
			}
			else Addedge(l, r, ID(pos[i ^ 1], pos[i ^ 1]));
		}
		for (int i = 0; i <= ID(m, m); i ++)
			if (!dfn[i]) {
				top = 0;
				tarjan(i);
			}
		for (int i = 0; i <= m; i ++)
			if (bel[ID(pos[i], pos[i])] == bel[ID(pos[i ^ 1], pos[i ^ 1])]) return false;
		return true;
	}
}
using namespace Graph;

inline bool cmp(int a, int b) {return x[a] < x[b];}

int main() {
	int n;
	scanf("%d", &n);
	m = (n << 1) - 1;
	for (int i = 0; i <= m; i ++) scanf("%d", &x[i]), id[i] = i, tab[i] = x[i];
	sort(id, id + m + 1, cmp);
	sort(tab, tab + m + 1);
	for (int i = 0; i <= m; i ++) pos[id[i]] = i;
	int L = 0, R = 1e9, ans = -1;
	while (L <= R) {
		if (check(mid)) {
			ans = mid;
			L = mid + 1;
		}
		else R = mid - 1;
	}
	printf("%d\n", ans + 1);
	return 0;
}

Measured memory_bytes: 9216
using System;

namespace Project
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			string s = Console.ReadLine();
			string[] sar = s.Split(' ');
			int[] a = new int[3];
			for (int i = 0; i < a.Length; i++)
			{
				a[i] = int.Parse(sar[i]);
			}
			Array.Sort(a);
			Console.WriteLine("{0} {1} {2}", a[0], a[1], a[2]);
		}
	}
}

Measured memory_bytes: 9304
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
a = list(map(int, input().split()))
if N == 1:
  print(max(a))
  exit(0)

mod = 10 ** 9 + 7
mn = []
zr = 0
pl = []
t = []
for x in a:
  if x < 0:
    mn.append(-x)
    t.append((-x, 0))
  elif x == 0: zr += 1
  else:
    pl.append(x)
    t.append((x, 1))

if N - zr < K:
  print(0)
  exit(0)

t.sort(reverse = True)
#print(t)
c = 0
res = 1
lpl = -1
lmn = -1
for x, cc in t[: K]:
  res *= x
  res %= mod
  c ^= (cc == 0)
  if cc: lpl = x
  else: lmn = x
if c == 0:
  print(res)
  exit(0)

respl = -1
resmn = -1
plt = 0
mnt = 0
if lpl != -1:
  respl = res + 0
  for x, cc in t[K: ]:
    if cc == 0:
      respl *= pow(lpl, mod - 2, mod)
      respl %= mod
      respl *= x
      respl %= mod
      plt = x
      break
  else: respl = -1

if lmn != -1:
  resmn = res + 0
  for x, cc in t[K: ]:
    if cc:
      resmn *= pow(lmn, mod - 2, mod)
      resmn %= mod
      resmn *= x
      resmn %= mod
      mnt = x
      break
  else: resmn = -1
#print(respl, resmn)
if (respl != -1) ^ (resmn != -1):
  print(max(respl, resmn))
  exit(0)
if (respl != -1) and (resmn != -1):
  if plt * lmn > mnt * lpl: print(respl)
  else: print(resmn)
  exit(0)

if len(pl) >= K:
  res = 1
  for x in pl[: K]:
    res *= x
    res %= mod
  print(res)
  exit(0)
if zr:
  print(0)
  exit(0)
res = 1
t.reverse()
for x, _ in t[: K]:
  res *= x
  res %= mod
print(-res % mod)

Measured memory_bytes: 116316
N = int(input())
A = [int(i) for i in input().split()]
for i in range(1,N):
    v = A[i]
    j = i -1
    print(' '.join(map(str,A)))
    while j >=0 and A[j] > v:
        A[j+1] = A[j]
        A[j] = v
        j-=1
print(' '.join(map(str,A)))


Measured memory_bytes: 5604
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
using namespace std;
typedef long long int ll;

#define rep(i,n) for(int i = 0;i<n;++i)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

struct Asked {
	ll a;
	ll b;
	bool solved ;
	static bool LessB(const Asked& rLeft, const Asked& rRight)
		{return rLeft.b < rRight.b;}
};
int main() {
	cin.tie(0);
        ios::sync_with_stdio(false);	
	ll n,m;
	cin >> n >> m;
	vector<Asked> Request(m);
	rep(i,m)
		cin >> Request[i].a >> Request[i].b;
	sort(Request.begin(),Request.end(),Asked::LessB);
	ll ans = 0;
	for(auto itr = Request.begin(); itr != Request.end(); ++itr){
		if(itr->solved)continue;
		itr->solved = true;
		ll bp = itr->b-1;
		ans++;
		for(auto itr2 = itr; itr2 != Request.end(); ++itr2){
			if(itr2->solved)continue;
			if(itr2->a<=bp&&itr2->b>bp) itr2->solved = true;
		}
	}
	cout << ans << endl;
		
	return 0;
}


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

string s[100];

bool search(string A, int i);

int main() {
	int N;
	cin >> N;
	cin >> s[0];
	for (int i = 1; i < N; i++) {
		cin >> s[i];
		if (s[i - 1].back() != s[i].front()) {
			cout << "No" << endl;
			exit(0);
		}
		if (search(s[i], i))
		{
			cout << "No" << endl;
			exit(0);
		}
		//if (s[i - 1].back() != s[i].front()) {
		//	cout << "No" << endl;
		//	exit(0);
		//}
	}

	cout << "Yes" << endl;
}

bool search(string A, int i) {
	for (int t = 0; t < i; t++) {
		if (A == s[t])return true;
	}
	return false;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int>> vvint;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<int, vector<int>, greater<int>> spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int>> bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;        //大きい順に取り出し

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)

int INF = 1e9;
int NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
double EPS = 1e-9;
double PI = M_PI;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes(){ cout << "POSSIBLE" << endl;}
void no(){ cout << "IMPOSSIBLE" << endl;}
//-----------------------------------------

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::chrono::system_clock::time_point start,end;
    start = std::chrono::system_clock::now();
    int n, k ;
    cin >> n >> k ;
    vll a(n) ;
    REP(i,n){
        cin >> a[i] ;
    }
    ll g = a[0] ;
    FOR(i,1,n){
        g = gcd(g,a[i]) ;
    }
    sort(ALL(a)) ;
    bool f = false ;
    REP(i,n){
        if(a[i]>=k){
            if((a[i]-k)%g==0){
                f = true; 
            }
        }
    }
    if(f){
        yes() ;
    }
    else{
        no() ;
    }






    end = std::chrono::system_clock::now();
    auto elapsed = std::chrono::duration_cast< std::chrono::milliseconds >(end - start).count();
    //std::cout << elapsed <<"ms"<< std::endl;

    

    return 0;
}



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

using ll = long long;
const int INF = 1001001001;

#define rep(i,n) for (int i = 0; i < (n); ++i)

int main()
{
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<ll> p(a);
    vector<ll> q(b);
    vector<ll> r(c);
    rep(i, a) cin >> p[i];
    rep(i, b) cin >> q[i];
    rep(i, c) cin >> r[i];

    sort(p.begin(), p.end(), greater<ll>());
    sort(q.begin(), q.end(), greater<ll>());
    sort(r.begin(), r.end(), greater<ll>());

    vector<ll> queue;
    rep(i, x) queue.push_back(p[i]);
    rep(i, y) queue.push_back(q[i]);
    rep(i, r.size()) queue.push_back(r[i]);

    sort(queue.begin(), queue.end(), greater<ll>());
    ll result = 0;
    rep(i, x+y) result += queue[i];
    cout << result << endl;
}


Measured memory_bytes: 8816
import copy

n, m = map(int, input().split())
xyz = []
for i in range(n):
    xyz.append(list(map(int, input().split())))
a = [1, -1]
ans = []
for i in range(2):
    for j in range(2):
        for k in range(2):
            count = 0
            xyz0 = copy.deepcopy(xyz)
            for l in range(n):
                xyz0[l] = [xyz[l][0] * a[i], xyz[l][1] * a[j], xyz[l][2] * a[k]]
            xyz0.sort(key = lambda x: sum(x), reverse = True)
            for l in range(m):
                count += sum(xyz0[l])
            ans.append(count)
print(max(ans))

Measured memory_bytes: 4312
#include <iostream>
#include <string>
 
using namespace std;
 
int main()
{
	string T;
	cin >> T;
	for (int i = 0; i < (int)T.length(); ++i)
	{
		if (T[i] == '?')
		{
			
				T[i] = 'D';
        }
			
	}
	cout << T << endl;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) v.erase(unique(ALL(v)), v.end())
#define bit(i) (1LL<<i)
#define sz(v) ((LLI)(v).size())

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

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


  int N,K;
  while(cin >> N >> K){
    int ans = (N-K);

    if(K == 1) ans = 0;
    
    cout << ans << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256