akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <bitset>
using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define pill pair<int, int>
#define mst(a, b)    memset(a, b, sizeof a)
#define REP(i, x, n)    for(int i = x; i <= n; ++i)
#define INF 0x3f3f3f3f
#define ll long long
#define pi acos(-1.0)
int main(){
	int n,k;
	int Min = 2000000000;
	int a[100010];
	scanf("%d %d",&n,&k);
	for(int i = 1 ; i <= n ; i++){
		scanf("%d",&a[i]);
	}
	sort(a+1,a+n+1);
	for(int i = k ; i <= n ; i++){
		Min = min(Min,min(abs(a[i]),abs(a[i-k+1]))+a[i]-a[i-k+1]);
	}
	printf("%d\n",Min);
}
/*
10
5 9 5 9 8 9 3 5 4 3
*/

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <string>
#include <set>
#include <map>

using namespace std;

int main() {
	int X;
	cin >> X;
	int curr = 0;
	for (int i = 1;; i++) {
		curr += i;
		if (curr >= X) {
			cout << i << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll  long long
//#define int long long
#define inf 0x3f3f3f3f
#define fi first
#define se second
#define pb push_back
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
const int N=2e5+10;
const int mod=998244353;
using namespace std;

 
int32_t main()
{
   //ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
   int x1,y1,x2,y2; scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
   double k,b;
   if(x1!=x2) k=(y1-y2)*1.0/(x1-x2),b=y1-k*x1;
   int q; scanf("%d",&q);
   while(q--)
   {
   	  int x,y; scanf("%d%d",&x,&y);
   	  if(x1==x2) {printf("%d %d\n",x1,y); continue; }
   	  if(y1==y2) {printf("%d %d\n",x,y1); continue; }
   	  double bb=y+1.0/k*x;
   	  double xx=(bb-b)*1.0/(k+1.0/k);
   	  double yy=k*xx+b;
   	  printf("%.10f %.10f\n",xx,yy);
   }
return 0;
}
/*

*/


Measured memory_bytes: 3224
int main(){
  int i;
  int x;
  int first;
  int second;
  int third;

  first = second = third = 0;

  for(i = 0; i< 10; i++){
    scanf("%d", &x);
    if(x>first){
      third = second;
      second = first;
      first = x;
    }else{
      if(x>second){
      third = second;
      second = x;
      }else{
      if(x>third){
      third = x;
      }
    }
  }
  }
  printf("%d\n", first);
  printf("%d\n", second);
  printf("%d\n", third);

  return 0;
}

Measured memory_bytes: 0
from collections import deque, defaultdict

N = int(input())
ab = [[int(i) for i in input().split()] for _ in range(N-1)]

#print(ab)
outs = defaultdict(list)
ins = defaultdict(int)

for v1, v2 in ab:
    outs[v1].append(v2)
    ins[v2] += 1

q = deque(v1 for v1 in range(1,N+1) if ins[v1] == 0)
dicthoji = {1: 0}

while q:
    v1 = q.popleft()
    count = 0
    for v2 in outs[v1]: #v1のノードから出ている矢印をみる．
        count += 1
        if dicthoji[v1] == count: #前に色を使っていたら飛ばす
            count += 1
        ins[v2] -= 1
        q.append(v2)
        dicthoji.update([(v2,count)])
#print(dicthoji)

print(max(dicthoji.values()))
for i in range(N-1):
    print(dicthoji[ab[i][1]])

Measured memory_bytes: 54076
#include<bits/stdc++.h>
#define IO cin.tie(0),ios::sync_with_stdio(0);
#define ff first
#define ss second
#define eb emplace_back
#define iter(v) v.begin() ,v.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define print(v) for(auto x: v) cout<<x<<' ';
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vec;

int main()
{
    IO;
    ll h;
    cin>>h;
    ll d=1,sum=0;
    while(h)
    {
        sum+=d;
        h/=2;
        d<<=1;
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 256
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, input().rstrip('\n').split()))
    pw = 2 ** n
    dp = [10 ** 20] * pw
    dp[0] = 0
    for i in range(m):
        a, b = list(map(int, input().rstrip('\n').split()))
        c = sum(2 ** (i - 1) for i in list(map(int, input().rstrip('\n').split())))
        for j in range(pw):
            if dp[j | c] > dp[j] + a:
                dp[j | c] = dp[j] + a
    if dp[-1] == 10 ** 20:
        print(-1)
    else:
        print(dp[-1])


if __name__ == '__main__':
    solve()


Measured memory_bytes: 43228
#include <iostream>

using namespace std;

#define endl "\n"

typedef long long ll;

/*ll mem[51];

ll fact(ll n)
{
	if(n <= 1)return 1;
	if(mem[n] != -1) return mem[n];
	return n * fact(n-1);
}*/

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll n,k;
	cin >> n >> k;
	cout << n-k+1 << endl;
	
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int h=sc.nextInt();
		int w=sc.nextInt();
		
		while(true){
			if(h==0 && w==0) break;
			
	        StringBuilder shp1=new StringBuilder();
	        for(int p=0;p<w;p++){
	        	shp1.append("#");
	        }
	         
	        StringBuilder shp2=new StringBuilder();
	        shp2.append("#");
		    for(int p=0;p<w-2;p++){
	        	shp2.append(".");
	        }
	        shp2.append("#");
	                
	        System.out.println(shp1);
	        for (int i=0;i<h-2;i++){
	        	System.out.println(shp2);
	        }
	        System.out.println(shp1+"\n");
	        
			h=sc.nextInt();
			w=sc.nextInt();

		}
	}

}

Measured memory_bytes: 20968
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(ll i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	ll t, a;
	cin >> n >> t >> a;
	rep (i, n - 1) {
		int p, q;
		ll mul;
		cin >> p >> q;
		mul = max((t - 1) / p, (a - 1) / q) + 1;
		t = mul * p;
		a = mul * q;
	}
	cout << t + a << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define fs first
#define sc second

using namespace std;
typedef double D;
typedef pair<int,int> P;
typedef pair<P,P> L;
typedef pair<D,int> pdi;

const D EPS = 1e-8;

inline D func(int x, P &a, P &b){
  int difx = b.fs - a.fs;
  D dify = b.sc - a.sc;
  return dify/difx * (x-a.fs) + a.sc;
}

int main(){
  int m,l,r;
  P p[110];
  L s[110];
  while(scanf("%d",&m),m){
    l = 10000, r = -10000;
    rep(i,m){
      scanf("%d%d",&p[i].fs,&p[i].sc);
      p[i].fs*=2;
      l = min(l,p[i].fs);
      r = max(r,p[i].fs);
    }
    rep(i,m){
      s[i] = L(p[i],p[(i+1)%m]);
      if(s[i].fs > s[i].sc)swap(s[i].fs,s[i].sc);
    }

    int ans = 0;
    for(int x=l+1;x<r;x+=2){
      vector<pdi> inv; inv.reserve(110);
      rep(i,m){
	if(s[i].fs.fs<x+EPS && x<s[i].sc.fs+EPS){
	  inv.push_back(pdi(func(x,s[i].fs,s[i].sc), i));
	}
      }

      sort(all(inv));
      int prv = -10000;
      for(int i=0;i<(int)inv.size();i+=2){
	int u = inv[i+1].sc, b = inv[i].sc;
	int up = ceil(max(func(x-1,s[u].fs,s[u].sc),
			  func(x+1,s[u].fs,s[u].sc))-EPS);
	int bot = floor(min(func(x-1,s[b].fs,s[b].sc),
			    func(x+1,s[b].fs,s[b].sc))+EPS);
	if(bot<prv)bot = prv;
	ans += up - bot;
	prv = up;
      }
    }
    printf("%d\n",ans);
  }
}

Measured memory_bytes: 1196
import numpy as np
N, M = map(int, input().split())
ans = np.zeros(M)
for i in range(N):
  KA = list(map(int, input().split()))
  for j in range(KA[0]):
    idx = KA[j+1]-1
    ans[idx] += 1

count = 0
for i in range(M):
  if ans[i] == N:
    count += 1
print(count)

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

pair<int, int> get_dmt(const vector<vector<int>> g) {
  int t;
  queue<int> que;
  vector<int> vis1(g.size());
  que.emplace(0);
  vis1[0] = 1;
  while (que.size()) {
    int x = que.front();
    que.pop();
    t = x;
    for (int y : g[x]) {
      if (vis1[y]) continue;
      vis1[y] = 1;
      que.emplace(y);
    }
  }
  int res;
  vector<int> vis2(g.size());
  queue<pair<int, int>> q;
  q.emplace(0, t);
  vis2[t] = 1;
  while (q.size()) {
    int d, x;
    tie(d, x) = q.front();
    q.pop();
    res = x;
    for (int y : g[x]) {
      if (vis2[y]) continue;
      vis2[y] = 1;
      q.emplace(d + 1, y);
    }
  }
  return make_pair(t, res);
}

bool mark(const vector<vector<int>> &g, int u, int fa, int ed, vector<int> &stem) {
  if (u == ed) return stem[u] = 1;
  bool ok = false;
  for (int v : g[u]) {
    if (v == fa) continue;
    ok |= mark(g, v, u, ed, stem);
  }
  return stem[u] = ok;
}

bool check(const vector<vector<int>> &g, int u, int fa, const vector<int> &stem) {
  if (stem[u]) {
    for (int v : g[u]) {
      if (stem[v]) continue;
      if (!check(g, v, u, stem)) return false;
    }
  } else {
    return g[u].size() == 1;
  }
  for (int v : g[u]) {
    if (v == fa) continue;
    if (stem[v]) {
      if (!check(g, v, u, stem)) return false;
    }
  }
  return true;
}

void dfs(const vector<vector<int>> &g, int u, int fa, vector<int> &p, int &clk, const vector<int> &stem) {
  int t = clk;
  ++clk;
  for (int v : g[u]) {
    if (stem[v]) continue;
    p.emplace_back(clk++);
  }
  p.emplace_back(t);
  for (int v : g[u]) {
    if (v == fa) continue;
    if (stem[v]) {
      dfs(g, v, u, p, clk, stem);
    }
  }
}

signed main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<vector<int>> G(N);
  for (int i = 0; i + 1 < N; ++i) {
    int V, W;
    cin >> V >> W;
    G[V - 1].emplace_back(W - 1);
    G[W - 1].emplace_back(V - 1);
  }
  int st, ed;
  tie(st, ed) = get_dmt(G);
  vector<int> stem(N);
  mark(G, st, -1, ed, stem);
  if (!check(G, st, -1, stem)) {
    cout << -1 << endl;
  } else {
    vector<int> p1, p2;
    int clk = 0;
    dfs(G, st, -1, p1, clk, stem);
    clk = 0;
    dfs(G, ed, -1, p2, clk, stem);
    if (p1 > p2) swap(p1, p2);
    for (int i = 0; i < p1.size(); ++i) {
      cout << p1[i] + 1 << " \n"[i + 1 == p1.size()];
    }
  }
  return 0;
}


Measured memory_bytes: 20424
#include <algorithm>
#include <cassert>
#include <cstdlib>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

template<class T> inline void chmax(T& a, const T& b) { if(b > a) a = b; }
template<class T> inline void chmin(T& a, const T& b) { if(b < a) a = b; }

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

	string s;
	cin >> s;

	const int len = static_cast<int>(s.size());
	vector<pair<char, int>> vp;
	vp.reserve(len);

	char prev = 'p';
	for(int i = 0; i < len; ++i) {
		if(prev == s[i]) {
			++vp.back().second;
		}
		else {
			vp.emplace_back(s[i], 1);
			prev = s[i];
		}
	}

	int k = 0;
	int p = 0;
	prev = 'p';
	for(int i = 0; i < static_cast<int>(vp.size()); ++i) {
		switch(vp[i].first) {
		case 'J':
			p = vp[i].second;
			break;
		case 'O':
			if(prev != 'J' || p < vp[i].second) p = 0;
			else chmin(p, vp[i].second);
			break;
		case 'I':
			if(prev == 'O' && p <= vp[i].second) chmax(k, p);
			p = 0;
			break;
		default:
			assert(false);
		}
		prev = vp[i].first;
	}

	cout << k << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 10088
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;


int main() {
	int A, B, C, D, E, F;
	cin >> A >> B >> C >> D >> E >> F;
	set<int> waters;
	set<int> sugars;
	for (int i = 0; i <= F; i++) {
		int water, sugar;
		for (int j = 0; j <= F; j++) {
			water = 100 * B * i + 100 * A * j;
			sugar = D * i + C * j;
			if (water <= F && water > 0) waters.insert(water);
			if (sugar <= F) sugars.insert(sugar);
			if (water > F&& sugar > F) break;
		}
	}

	int max_sugar = 0;
	int max_water = 0;
	double max_noudo = -1;
	for (int water : waters) {
		for (int sugar : sugars) {
			if (water + sugar > F) break;
			double noudo = sugar * 100.0 / (1.0 * sugar + 1.0 * water);
			if (noudo > E * 100.0 / (100.0 + 1.0 * E)) break;
			if (max_noudo < noudo) {
				max_noudo = noudo;
				max_water = water;
				max_sugar = sugar;
			}
		}
	}

	cout << max_water + max_sugar << " " << max_sugar;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
    static int bridge;
    static int cnt;
    static int[] pre;
    static int[] low;

    private static void dfs(Map<Integer, List<Integer>> G, int u, int v) {
        pre[v - 1] = cnt++;
        low[v - 1] = pre[v - 1];

        for (int w : G.get(v)) {
            if (pre[w - 1] == -1) {
                dfs(G, v, w);
                low[v - 1] = Math.min(low[v - 1], low[w - 1]);
                if (low[w - 1] == pre[w - 1])
                    bridge++;
            } else if (w != u)
                low[v - 1] = Math.min(low[v - 1], pre[w - 1]);
        }
    }

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

        Map<Integer, List<Integer>> G = new HashMap<>();
        for (int i = 1; i <= v; i++) {
            G.put(i, new ArrayList<Integer>());
        }

        for (int j = 0; j < e; j++) {
            int u = sc.nextInt();
            int w = sc.nextInt();
            G.get(u).add(w);
            G.get(w).add(u);
        }

        low = new int[v];
        pre = new int[v];

        for (int i = 0; i < v; i++) {
            low[i] = -1;
            pre[i] = -1;
        }

        for (int k = 1; k <= v; k++) {
            if (pre[k - 1] == -1)
                dfs(G, k, k);
        }

        System.out.println(bridge);
    }

}


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

void solve()
{
    ll n;
    cin >> n;
    vector<ll> a(n + 1);
    ll sum = 0;
    for (ll &ai : a) {
        cin >> ai;
        sum += ai;
    }
    ll cnt = 0;
    ll ver = 1;
    for (ll i = 0; i <= n; ++i) {
        cnt += ver;
        /* cout << ver << ' '; */
        if (ver < a[i]) {
            cout << -1 << endl;
            return;
        }
        ver -= a[i];
        sum -= a[i];
        ver = min(ver * 2, sum);
    }
    cout << cnt << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    solve();
    return 0;
}


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

int main()
{
	char arr[5];
	cin>>arr;
	for(int i=0;i<3;i++){
		if(arr[i]=='7'){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3576
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
#define out(args...){vector<string> a_r_g_s=s_p_l_i_t(#args, ','); e_r_r(a_r_g_s.begin(), args); }
vector<string> s_p_l_i_t(const string &s, char c){vector<string> v;int d=0,f=0;string t;for(char c:s){if(!d&&c==',')v.pb(t),t="";else t+=c;if(c=='\"'||c=='\'')f^=1;if(!f&&c=='(')++d;if(!f&&c==')')--d;}v.pb(t);return move(v);}
void e_r_r(vector<string>::iterator it) {}
template<typename T, typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args){ if(*it==" 1"||*it=="1") cerr<<endl; else cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; e_r_r(++it, args...);}
const ll MOD=1e9+7;

ll mM(vector<pll> ps){
  ll a=min(ps[0].X,ps[0].Y);
  ll b=max(ps[0].X,ps[0].Y);
  ll A=a,B=b;
  for(pll p:ps){
    MN(a,min(p.X,p.Y));
    MX(A,min(p.X,p.Y));
    MN(b,max(p.X,p.Y));
    MX(B,max(p.X,p.Y));
  }
  return (B-b)*(A-a);
}
ll srt(vector<pll> ps){
  multiset<ll> a,b;
  for(pll p:ps) a.insert(p.X), b.insert(p.Y);
  sort(all(ps),[](const pll &p,const pll &q){return p.X+p.Y<q.X+q.Y;});
  ll re=(*b.rbegin()-*b.begin())*(*a.rbegin()-*a.begin());
  for(pll p:ps){
    a.erase(a.find(p.X));
    b.erase(b.find(p.Y));
    a.insert(p.Y);
    b.insert(p.X);
    MN(re,(*b.rbegin()-*b.begin())*(*a.rbegin()-*a.begin()));
  }
  return re;
}

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n;
  cin>>n;
  vector<pll> ps(n);
  rep(i,n) cin>>ps[i].X>>ps[i].Y;
  for(pll &p:ps) if(p.X>p.Y) swap(p.X,p.Y);
  cout<<min(mM(ps), srt(ps))<<endl;
  return 0;
}


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

int main (){
  int a,b,c,k,n=0;
  cin >> a >> b >> c >> k;
  while (!(a<b)){
    b*=2;
    n++;
  }
  while (!(b<c)){
    c*=2;
    n++;
  }
  if (k>=n) cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 3132
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
	int N, A, B;
	cin >> N >> A >> B;

	cout << min(A, B) << " ";

	int min = 0;
	if (A + B > N) min = A + B - N;

	cout << min << endl;
	
	return 0;
}

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

int n, t=1;
vector<int> d, f;
vector<vector<int>> graph;
vector<int> flg;
void dfs(int v){
    flg[v]=1;
    d[v]=t;
    t++;

    for(int i : graph[v]){
        if(!flg[i]) dfs(i);
    }

    f[v]=t;
    t++;
}

int main() {

    cin >> n;
    d.assign(n+1, 0);
    f.assign(n+1, 0);
    graph.assign(n+1, {});
    flg.assign(n+1, 0);
    int u, k, tmp;
    for(int i=1; i<=n; i++){
        cin >> u >> k;
        for(int j=0; j<k; j++){
            cin >> tmp;
            graph[i].push_back(tmp);
        }
    }
    
    for(int i=1; i<=n; i++){
        if(!flg[i]) dfs(i);
    }

    for(int i=1; i<=n; i++){
        cout << i << " " << d[i] << " " << f[i] << endl;
    }
}


Measured memory_bytes: 3168
from collections import defaultdict

CHRtoINT = defaultdict(int)
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]
for i, c in enumerate(atoz):
    CHRtoINT[c] = i

# 文字列 S の長さ x の連続した部分文字列を b, m (base, mod は互いに素)でハッシュ化したリストを返す
def RollingHash(S, x, b1 = 1009, b2 = 1007, m1 = 10**9+7, m2 = 10**9+9):
    h1, h2, B1, B2 = 0, 0, 1, 1
    for c in S[:x]:
        h1 = (h1 * b1 + CHRtoINT[c]) % m1
        h2 = (h2 * b2 + CHRtoINT[c]) % m2
        B1 *= b1
        B2 *= b2
    hash = [(h1, h2)] + [None] * (len(S)-x)
    for i, c in enumerate(S[:-x]):
        h1 = (h1 * b1 - CHRtoINT[c] * B1 + CHRtoINT[S[i+x]]) % m1
        h2 = (h2 * b2 - CHRtoINT[c] * B2 + CHRtoINT[S[i+x]]) % m2
        hash[i+1] = (h1, h2)
    return hash

n, S = int(input()), input()
l, r = 0, n//2+1
while l+1 < r:
    m = (l+r)//2
    OK = False
    hash = RollingHash(S, m)
    dic = defaultdict(int)
    for i, h in enumerate(hash):
        if h in dic:
            if i - dic[h] >= m:
                OK = True
                break
        else:
            dic[h] = i
    if OK:
        l = m
    else:
        r = m
print(l)


Measured memory_bytes: 5388
#include <stack>
#include <queue>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
#define INF (1<<29)
#define test cout << "test" << endl;

int main (){
	int d,nn;
	cin >>d >>nn;
	if(nn==100){
		nn++;
	}
	cout << nn;
	rep(i,d){
		cout << "00";
	}
	cout <<endl;
	return 0;
}


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

int main(){
  string s;
  cin >> s;
  vector<int> map(s.size());
  
  for(int i=0; i<s.size()-1;){
    if(s.at(i) == 'A'){
      map.at(i) = 1;
      i++;
    }else if(s.at(i) == 'B'){
      if(s.at(i+1) == 'C'){
        map.at(i) = 2;
        i += 2;
      }else{
        map.at(i) = 3;
        i++;
      }
    }else if(s.at(i) == 'C'){
      map.at(i) = 3;
      i++;
    }
  }
  
  long long position = 0;
  long long tmp=0;
  long long count = 0;
  long long answer = 0;
  
  while(position < s.size()){
    if(map.at(position) == 0){
      position++;
    }else if(map.at(position) == 1){
      tmp++;
      position++;
    }else if(map.at(position) == 2){
      count += tmp;
      position++;
    }else if(map.at(position) == 3){
      answer += count;
      tmp=0;
      count=0;
      position++;
    } 
  }
  
  answer += count;
  
  
  cout << answer << endl;
  
}

Measured memory_bytes: 1412
/*input
4664
*/
#include <bits/stdc++.h>
using namespace std;
int main(){
	#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	#endif
	long long n,q,m,k,h,ans=0,sum=0,p,x,y;
	cin>>n;
	for(long long i=1;i<=3500;++i)
		for(long long j=1;j<=3500;++j){
			if((4*i*j-n*i-n*j)<=0 || (4*i*j-n*i-n*j)>n*i*j) continue;
			if(n*i*j%(4*i*j-n*i-n*j)==0){
				long long k=n*i*j/(4*i*j-n*i-n*j);
				assert(4*i*j*k/(i*j+i*k+j*k)==n);
				return cout<<i<<' '<<j<<' '<<k,0;
			}
		}
	assert(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, T;
  cin >> N >> T;
  vector<int> vecc(N);
  vector<int> vect(N);
  vector<bool> Tika(N);
  bool Tikaa = false;
  int mincost = 1000;
  for(int i=0; i<N; i++){
    cin >> vecc.at(i) >> vect.at(i);
  }
  for(int i=0; i<N; i++){
    if(vect.at(i) <= T){
      Tika.at(i) = true;
      Tikaa = true;
    }
    if(mincost > vecc.at(i) && Tika.at(i)){
      mincost = vecc.at(i);
    }
  }
  if(Tikaa == false){
    cout << "TLE" << endl;
  }else{
    cout << mincost << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma region Macros
#define ios\
    ios::sync_with_stdio(false);\
    cin.tie(nullptr);
#define VEC(type, name, size)\
    V<type> name(size);\
    IN(name)
#define VVEC(type, name, h, w)\
    VV<type> name(h, V<type>(w));\
    IN(name)
#define INT(...)\
    int __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LL(...)\
    ll __VA_ARGS__;\
    IN(__VA_ARGS__)
#define STR(...)\
    string __VA_ARGS__;\
    IN(__VA_ARGS__)
#define CHAR(...)\
    char __VA_ARGS__;\
    IN(__VA_ARGS__)
#define DOUBLE(...)\
    DOUBLE __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LD(...)\
    LD __VA_ARGS__;\
    IN(__VA_ARGS__)
template <class T> void scan(T &a) { cin >> a; }
template <class T> void scan(vector<T> &a) { for(auto &i : a) scan(i); }
template <class T, class L> void scan(pair<T, L> &p){ scan(p.first); scan(p.second); }
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &... tail) { scan(head); IN(tail...); }
template <class T> inline void print(T x){ cout << x << '\n';}
#define ll long long
#define ld long double
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
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; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T Roundup_div(T x, T y) {return (x+(y-1))/y;}
template <typename T> T pow(T a, long long n, T e = 1) {T ret = e; while (n) {if (n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
const ll INF = 1e18;
#pragma endregion

int main(){
    ios;
    INT(n);
    VEC(ll, p, n);
    V<> a(n), b(n);
    REP(i, n){
        a[i] = 20000 * (i + 1);
        b[i] = 20000 * (n - i);
    }
    REP(i, n) a[p[i] - 1] += i;
    for(auto v : a) cout << v << " "; cout << '\n';
    for(auto v : b) cout << v << " "; cout << '\n';
}

Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int main(){
    int h,w,countw=0;cin>>h>>w;
    vector<vector<char> >bw(h+2,vector<char>(w+2));
    rep(i,h){
        rep(j,w){
            char c;cin>>c;
            if(c=='.')countw++;
            bw[i+1][j+1]=c;
        }
    }
    vector<vector<int> >visited(h+2,vector<int>(w+2,-1));
    queue<pii>q;
    q.push(make_pair(1,1));
    visited[1][1]=0;
    while(!q.empty()){
        int x=q.front().first,y=q.front().second;
        q.pop();
        rep(i,4){
            int nx=x+dx[i],ny=y+dy[i];
            if(nx>=1&&ny>=1&&nx<=h&&ny<=w&&visited[nx][ny]==-1&&bw[nx][ny]=='.'){
                q.push(make_pair(nx,ny));
                visited[nx][ny]=visited[x][y]+1;
            }
            if(nx==h&&ny==w)break;
        }
    }
    if(visited[h][w]>0)cout<<countw-visited[h][w]-1<<endl;
    else if(visited[h][w]==-1)cout<<-1<<endl;
}

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

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }


void run() {
	int x; scanf("%d",&x);
	int ret=0;
	while((ll)ret*(1+ret)/2<x) ++ret;
	printf("%d\n",ret);
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MP make_pair
#define vi vector<int>
#define vll vector<ll>
const ll MAX = 20000002;
#define MOD 1000000007
int a[1111];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<2*n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+2*n);
    int ans=0;
    for(int i=0;i<2*n;i+=2)
        ans+=a[i];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
x, y, a, b, c = map(int, input().split())
p = sorted([int(i) for i in input().split()], reverse=True)
q = sorted([int(i) for i in input().split()], reverse=True)
r = sorted([int(i) for i in input().split()], reverse=True)
p = p[:x]
q = q[:y]
apple = sorted(p + q + r, reverse=True)
print(sum(apple[:x+y]))

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

int N, M, Q;
vector<tuple<int, int, int, int>> A;
int ans;

void dfs(vector<int> V, int pre) {
  if (V.size() == N) {
    int sum = 0;
    for (auto[a, b, c, d] : A) if (V.at(b) - V.at(a) == c) ans = max(ans, sum += d);
    return;
  }
  for (int i = pre; i <= M; i++) {
    V.push_back(i);
    dfs(V, i);
    V.pop_back();
  }
}

int main() {
  cin >> N >> M >> Q;
  for (int i = 0, a, b, c, d; cin >> a >> b >> c >> d; i++) A.push_back({--a, --b, c, d});
  vector<int> start;
  dfs(start, 1);
  cout << ans << "\n";
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
	while(1){
		int n; cin >> n;
		if(n == 0) return 0;
		set<int> tarou;
		set<int> hanako;

		rep(i,n){
			int a; cin >> a;
			tarou.insert(a);
		}

		rep(i,2*n){
			if(!tarou.count(i+1)){
				hanako.insert(i+1);
			}
		}

		int player = 1;
		int cur = 0;

		while(1){
			bool jud = false;
			if(player == 1){
				for(auto e: tarou){
					if(cur <= e){
						tarou.erase(e);
						cur = e;
						jud = true;
						break;
					}
				}
				if(!tarou.size()) break;
				if(!jud) cur = 0;
				player ^= 1;				
			}

			else{
				for(auto e: hanako){
					if(cur <= e){
						hanako.erase(e);
						cur = e;
						jud = true;
						break;
					}
				}
				if(!hanako.size()) break;
				if(!jud) cur = 0;
				player ^= 1;					
			}

		}

		cout << hanako.size() << endl;
		cout << tarou.size() << endl;

	}

}


Measured memory_bytes: 3088
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <cstdlib>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int n; cin >> n;
	vector<ll> a(n);
	map<ll, ll> mp;
	rep(i, n)
	{
		cin >> a[i];
		a[i] -= i;
		++mp[a[i]];
	}
	ll res = 0;
	rep(i, n - 1)
	{
		--mp[a[i]];
		ll tmp = a[i] + i + i;
		res += mp[-tmp];
	}
	cout << res << endl;
}

Measured memory_bytes: 27392
local n=io.read("n","l")
local s=io.read()

local w={}
local e={}
local west=0
local east=0

for i=1,n do
    if s:sub(n-i+1,n-i+1)=="E" then
        west=west+1
    end
    if s:sub(i,i)=="W" then
        east=east+1
    end
    w[n-i+1]=west
    e[i]=east
end

local counter=10^9
for i=1,n do
    counter=math.min(counter,w[i]+e[i]-1)
end
print(counter)

Measured memory_bytes: 23108
//#pragma GCC optimize("-O3")
/*
				C++
				encoding: UTF-8
				Last Modified: 12/Apr/20 05:53:27 PM
*/

#include <bits/stdc++.h>
#ifdef H4wk3ye
#	include <prettypr.hpp>
#endif

using namespace std;

// clang-format off

#define		int                    long long
#define		ve                     vector
#define		pb                     push_back
#define		endl                   "\n"
#define		ff                     first
#define		ss                     second
#define		pii                    pair<int, int>
#define		len(v)                 (int)v.size()
#define		all(v)                 v.begin(), v.end()
#define		reset(a, b)            memset(a, b, sizeof(a));
#define		fr(i, s, n)            for (int i = s ; i < n ; ++i)
#define		dfr(i, s, n)           for (int i = s ; i > n ; --i)

template < typename T > void pr (const T& t) {
    cout << t << "\n";
}

template < typename T, typename U, typename... ARGS >
void pr (const T& t, const U& u, const ARGS&... args) {
    cout << t << " ";
    pr (u, args...);
}

// clang-format on


signed main () {
	ios_base::sync_with_stdio (false), cin.tie (nullptr);
	int n;
	cin >> n;
	string s;
	cin >> s;
	ve< ve< int > > cnt (n + 1, ve< int > (3));
	cnt[0][0] = cnt[0][1] = cnt[0][2] = 0;
	fr (i, 1, n + 1) {
		cnt[i] = cnt[i - 1];
		if (s[i - 1] == 'R') {
			cnt[i][0]++;
		} else if (s[i - 1] == 'G') {
			cnt[i][1]++;
		} else {
			cnt[i][2]++;
		}
	}

	int ans = 0;

	fr (i, 1, n) {
		fr (j, i + 1, n) {
			if (s[i - 1] == s[j - 1]) continue;

			if ((s[i - 1] == 'R' and s[j - 1] == 'G') or (s[i - 1] == 'G' and s[j - 1] == 'R')) { // find k count ahead of j
				ans += cnt[n][2] - cnt[j][2];

				int r = j - i;
				if (j + r > n) continue;
				if (s[j + r - 1] == 'B') ans--;
			} else if ((s[i - 1] == 'B' and s[j - 1] == 'G') or (s[i - 1] == 'G' and s[j - 1] == 'B')) {
				ans += cnt[n][0] - cnt[j][0];

				int r = j - i;
				if (j + r > n) continue;
				if (s[j + r - 1] == 'R') ans--;
			} else {
				ans += cnt[n][1] - cnt[j][1];

				int r = j - i;
				if (j + r > n) continue;
				if (s[j + r - 1] == 'G') ans--;
			}
		}
	}
	pr (ans);

	return 0;
}

Measured memory_bytes: 3872
#include <bits/stdc++.h> 
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<long, long> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 

int main(){
    int N;
    cin>>N;
    string S;
    cin>>S;
    int res=N;
    vector<int>ar(N+1);
    ar[0]=0;//i番目より左にある#の個数
    int sum=0;
    REP(i,N){
        if(S[i]=='#'){
            ar[i+1]=ar[i]+1;sum+=1;
        }else{
            ar[i+1]=ar[i];
        }
    }
    REP(i,N+1){
        int cnt=ar[i]+(N-i-(sum-ar[i]));//前半部のシャープの個数+後半部の.の個数
        res=min(res,cnt);
    }
    cout<<res<<endl;
    return 0;
}

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

int LIS(vector<int> &a) {
  const int INF = 2e9;
  int l = a.size();
  vector<int> dp(l, INF);
  rep(i,l) *lower_bound(dp.begin(),dp.end(),a[i]) = a[i];
  return lower_bound(dp.begin(),dp.end(),INF) - dp.begin();
}

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  cout << LIS(a) << endl;
  return 0;
}


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

r=n
l=1
ans=0
for i in range(1,m+1):
	lt, rt = map(int, input().split())
	if lt > l:
		l=lt
	if rt < r:
		r=rt
	#print(l,r)

ans = r-l+1
if ans < 0:
	ans = 0
print(ans)

Measured memory_bytes: 3064
//agrawal117
//chahatagrawal117
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
typedef long long int ll;
using namespace std;
#define MAX 100005
ll power(ll a ,ll b)
{
	ll res=1LL;
	while(b>0){
		if(b&1) res=(res*a) % mod;
		a=(a*a) % mod;
		b=b>>1;
	}
	return res % mod;
}

ll inv_mod(ll a) { return (power(a, mod-2) % mod ) ;  }
ll fact[200007];
ll invv[200007];
void factorial()
{
	fact[0]=1;
	invv[0]=inv_mod(fact[0]);
	for(int i=1;i< 200007;i++){
		fact[i]=(fact[i-1]*i)%mod;
		invv[i]=inv_mod(fact[i]);
	}
	
}

ll ways(ll x1,ll y1 , ll x2, ll y2)
{
    if(x1>x2 || y1>y2) return 0;
    ll num=x2-x1+y2-y1;
    num=fact[num];
    ll denom=(invv[x2-x1]*invv[y2-y1])%mod;
    return (num*denom)%mod;
}
ll answer(vector<pair<ll,ll>> v) // in this vector 0th index is starting pos. and last ind is destination pos. and in between all index are block cells
{                                                       // in which we dont have to go and this funct. return no. of ways to go to 0th ind. to last. index 
    int n=v.size()-2;
    ll total=ways(v[0].first,v[0].second,v.back().first,v.back().second);
    ll dp[v.size()];
    for(int i=1;i<=n;i++){
        ll ans=0;
        for(int j=1;j<i;j++){
            ll val=(dp[j]*ways(v[j].first,v[j].second,v[i].first,v[i].second))%mod;
            ans=(ans+val)%mod;
        }
        dp[i]=(ways(v[0].first,v[0].second,v[i].first,v[i].second))-ans;
        dp[i]%=mod;
        dp[i]+=mod; dp[i]%=mod;
    }
    ll ans=0;
    for(int i=1;i<=n;i++){
        ll val=(dp[i]*ways(v[i].first,v[i].second,v.back().first,v.back().second) ) %mod;
        ans=(ans+val)%mod;
    }
    total=(total-ans+mod)%mod;
    total%=mod;
    total+=mod;
    total%=mod;
    return total;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    factorial();
    vector<pair<ll,ll>> v;
    ll h,w,n; cin>>h>>w>>n;
    v.emplace_back(1,1);
    for(int i=0;i<n;i++){
        ll a,b; cin>>a>>b;
        v.emplace_back(a,b);
    }
    v.emplace_back(h,w);
    sort(v.begin(),v.end());
    ll ans=answer(v);
    cout<<ans<<endl;
}

Measured memory_bytes: 6920
#include<bits/stdc++.h>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
 
#ifdef _WIN32
    #define gx getchar
    #define px putchar
    #define ps putchar(' ')
    #define pn putchar('\n')
    #define DEBUG 1
#else
    #define gx getchar_unlocked
    #define px putchar_unlocked
    #define ps putchar_unlocked(' ')
    #define pn putchar_unlocked('\n')
    #define DEBUG 0
#endif
 
//input
void scan(int &n)
{
    int sign = 1;
    n = 0;
    char c = gx();
    while( c < '0' || c > '9' )
    {
        if( c == '-' ) sign = -1;
        c = gx();
    }
    while( c >= '0' && c <= '9' ) n = (n<<3) + (n<<1) + c - '0', c = gx();  n = n * sign;
}
void lscan(ll &n)
{
    int sign = 1;
    n = 0;
    char c = gx();
    while( c < '0' || c > '9' )
    {
        if( c == '-' )
        sign = -1;
        c = gx();
    }
    while( c >= '0' && c <= '9' ) n = (n<<3) + (n<<1) + c - '0', c = gx();  n = n * (ll)(sign);
}
int sscan(char a[])
{
    char c = gx();
    while(c==' ' || c=='\n') c=gx();
    int i=0;
    while(c!='\n')a[i++] = c,c=gx();
    a[i]=0;
    return i;
}
int wscan(char a[])
{
    char c = gx();
    while(c==' ' || c=='\n') c=gx();
    int i=0;
    while(c!='\n' && c!=' ')a[i++] = c,c=gx();
    a[i]=0;
    return i;
}
 
//output
void print(int n)
{
    if(n<0)
    {
        n=-n;
        px('-');
    }
    int i=10;
    char o[10];
    do{o[--i] = (n%10) + '0'; n/=10;}while(n);
    do{px(o[i]);}while(++i<10);
}
void lprint(ll n)
{
    if(n<0LL)
    {
        n=-n;
        px('-');
    }
    int i=21;
    char o[21];
    do{o[--i] = (n%10LL) + '0'; n/=10LL;}while(n);
    do{px(o[i]);}while(++i<21);
}
void sprint(const char a[])
{
    const char *p=a;
    while(*p)px(*p++);
}
 
 
ll po(ll a, ll b, ll m)
{
	ll x=1,y=a;
	while(b > 0)
	{
		if(b%2 == 1)
		{
			x=(x*y);
			if(x>m) x%=m;
		}
		y = (y*y);
		if(y>m) y%=m;
		b /= 2;
	}
	return x;
}
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main()
{
	ll n;
	cin>>n;
	ll a[n];
	unordered_map<int,int> m;
	for(ll i=0;i<n;i++)
	{	
		cin>>a[i];
		m[a[i]]++;
	}
	ll ans = 0;
	for(auto &it:m) {
		if(m[it.first]>1) {
			ans = ans+(1L*m[it.first]*(m[it.first]-1))/2;
		}
	}
	for(ll i=0;i<n;i++) {
		cout<<ans-m[a[i]]+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 9160
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int, int> P;
 
int main(){
  int k;
  cin >> k;
  
  vector<ll> a;
  for(int i=1; i<10; i++) a.push_back(i);

  while(true){
    if(k<=a.size()){
      cout << a[k-1] << endl;
      return 0;
    }
    k -= a.size();
    
    vector<ll> old;
    swap(old, a);
    for(ll x : old){
      for(int i=-1; i<=1; i++){
        int d = x%10 + i;
        if(d<0||d>9) continue;
        ll nx = x*10 + d;
        a.push_back(nx);
      }
    }
    
  }
  
  return 0;
}



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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	int s1 = a * b;
	int s2 = c * d;
	cout << (s1 > s2 ? s1 : s2) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	int t=n,ans=0;
	do
	{
		ans+=n%10;n/=10;
	}
	while (n!=0);
	if (t%ans==0) printf("Yes\n"); else printf("No\n");
	return 0;
}

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

int main(void) {

	// TODO: submit前にprintf-debugの削除確認！
	int A, B;
	//long long N, M;
	//double d, e;
	//string s, t;
	//vector<int> v;
	//vector<pair<int, int>> pl;

	//while() {}
	//for(int i=0; i<N; i++) {}
	
	cin >> A >> B;
	int ans;
	if(B%A == 0) ans = A+B;
	else ans = B-A;

	cout << ans;
	// cout << "[deb: val ]" << val <<endl;
	return 0;
}



Measured memory_bytes: 256
row1 = list(map(int,input().split(" ")))
row2 = list(map(int,input().split(" ")))
row3 = list(map(int,input().split(" ")))

col1 = [row1[0],row2[0],row3[0]]
col2 = [row1[1],row2[1],row3[1]]
col3 = [row1[2],row2[2],row3[2]]

dig1 = [row1[0],row2[1],row3[2]]
dig2 =[row1[2],row2[1],row3[0]]

n = int(input())
res = []
for _ in range(n):
    res.append(int(input()))

if all([ele in res for ele in row1]) or all([ele in res for ele in row2]) or all([ele in res for ele in row3]) or all([ele in res for ele in col1]) or all([ele in res for ele in col2]) or all([ele in res for ele in col3]) or all([ele in res for ele in dig1]) or all([ele in res for ele in dig2]):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a,b;
    cin>>a>>b;
    string c=a+b;
    int k = stoi(c); 
    double kk= sqrt(k);
    
    if(kk-floor(kk)==0)
    {
        cout<<"Yes"<<"\n";
    }
    else
    {
        cout<<"No"<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3724
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long ll;
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod;
#define mul(a,b) a=a*b%mod;
#define N 710
bool e[N][N];
ll n,m;
ll c[N],sum;
bool dfs(ll x,bool col){
    if(~c[x]){
        return c[x]==col;
    }
    c[x]=col;
    if(col==0)sum++;
    else sum--;
    for(int y=1;y<=n;y++){
        if(e[x][y]==0&&x!=y){
          if(dfs(y,col^1)==0)return 0;
        }
    }
  return 1;
}
int main(){
  cin>>n>>m;
  for(int i=0;i<m;i++){
      ll a,b; cin>>a>>b;
      e[a][b]=e[b][a]=1;
  }
  for(int i=1;i<=n;i++)c[i]=-1;
  bool th[N];
  for(int i=0;i<N;i++)th[i]=0; th[0]=1;
  ll als=0;
  for(int i=1;i<=n;i++){
      if(-1==c[i]){
          sum=0;
          if(dfs(i,0)==0){
              cout<<-1<<endl;
              return 0;
          }
        sum=abs(sum);
          for(int j=N-sum-1;j>=0;j--){
              th[j+sum]|=th[j];
          }
          als+=sum;
      }
  }
  ll mi=als;
  for(ll i=0;i<=als;i++){
      if(th[i])chmin(mi,abs(i-(als-i)));
  }
  ll a=(n+mi)/2,b=(n-mi)/2; //cout<<a<<" "<<b<<endl;
  cout<<a*(a-1)/2+b*(b-1)/2<<endl;
  return 0;
}



Measured memory_bytes: 768
#include <iostream>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[])
{
	int A, B;

	cin >> A >> B;
	int a = A + B;
	int b = A - B;
	int c = A * B;
	int mx = -100000;

	mx = max(a, b);
	mx = max(mx, c);

	cout << mx << endl;

	return 0;
}

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

int main() {
    int N;
    string S;
    cin >> N;
    cin >> S;

    int answer = 0;
    int i = N-1;
    while (i > 0) {
        int now = 0;
        int max = 0;
        int j = 0;
        while (j < N-i) {
            if (S[j] == S[j+i]) {
                now += 1;
            }
            else {
                if (now > i) {
                    now = i;
                }
                if (now > max) {
                    max = now;
                }
                now = 0;
            }   
        j++;
        }
        if (now > i) {
            now = i;
        }
        if (now > max) {
            max = now;
        }
        if (max > answer) {
            answer = max;
        }
        i--;
    }

    cout << answer << endl;
}

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

int main() {
    int N;
    cin >> N;
    map<string, int> m;
    for(int i = 0; i < N; i++){
        string S;
        cin >> S;
        m[S]++;
    }

    int num = 0;
    for(auto value : m){
        auto v = value.second;
        num = max(num, v);
    }

    for(auto value : m){
        auto v = value.second;
        if(v == num){
            cout << value.first << endl;
        }
    }    
}

Measured memory_bytes: 19240
from collections import deque
n, m = map(int, input().split())
M = [[] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    M[a].append(b)
    M[b].append(a)
#print(M)

R = [-1 for i in range(n)]
Q = deque([(0, -2)])
while len(Q) > 0:
    t = Q[0][0]
    b = Q[0][1]
    #print(t)
    #print(b)
    Q.popleft()
    if R[t] == -1:
        R[t] = b
        for i in range(len(M[t])):
            if R[M[t][i]] == -1:
                Q.append((M[t][i], t))
            else:
                pass
    else:
        pass
#print(R)

f = 0
for i in range(n):
    if R[i] == -1:
        f = 1
        break  
    else:
        pass

if f == 1:
    print('No')
else:
    print('Yes')
    for i in range(1, n):
        print(R[i] + 1)

Measured memory_bytes: 39852
N, M, K = gets.split.map(&:to_i)

0.upto(N) do |i|
  0.upto(M) do |j|
    cnt = M * i + N * j - 2 * i * j

    if cnt == K
      puts 'Yes'
      exit
    end
  end
end

puts 'No'


Measured memory_bytes: 1788
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

int main() {
  //
  ll cnt = 0;
  rep(i, 3) {
    ll a;
    cin >> a;
    cnt += a;
  }
  if (cnt >= 22)
    cout << "bust" << endl;
  else
    cout << "win" << endl;
  return 0;
}


Measured memory_bytes: 256