akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)
 
const ULL M = 998244353;

struct RQ {
 using RQV = ULL;
 struct RQRV{ ULL b,c; };
 static RQV Zero(){ return 0; }
 static RQRV RZero(){ return { 1,0 }; }
 // addition
 static RQV f(RQV a,RQV b){ return (a+b) % M; }
 // update function
 static void uf(RQV& a,RQV b){ a = b; }
 // effect of range queries n-sized
 static void ef(RQV& a,RQRV b,int n){ a = (b.b*a + b.c*n) % M; }
 // range query update
 static void ruf(RQRV& a,RQRV b){
  a.b = (a.b * b.b) % M; 
  a.c = (a.c * b.b + b.c) % M;
 }
 // comparation
 static bool cmp(RQV l,RQV r){ return l<=r; }
 struct Node{
  RQV v; RQRV r;
 };
 int N;
 vector<Node> V;

 void init(int n){
  N=1; while (N<n) N*=2;
  V.assign(N*2,{Zero(),RZero()});
 }

 void spread(int i,int z){
  ef(V[i].v,V[i].r,z);
  if (z!=1) {
   ruf(V[i*2].r,V[i].r);
   ruf(V[i*2+1].r,V[i].r);
  }
  V[i].r = RZero();
 }

 void upd(int p,RQV v){
  for(int d=N; d>=1; d/=2) spread(p/d,d);
  p+=N; uf(V[p].v,v);
  int z=1;
  while(p!=1){
   p/=2; z*=2;
   V[p].v = f(V[p*2].v,V[p*2+1].v);
   ef(V[p].v,V[p].r,z);
  }
 }

 void updr(int l,int r,RQRV v,int a=0,int b=0,int i=-1){
  if(i==-1){ a=0; b=N; i=1; }
  if(r<=a || b<=l){ spread(i,b-a); return; }
  else if(l<=a && b<=r){ ruf(V[i].r,v); spread(i,b-a); return; }
  spread(i,b-a);
  updr(l,r,v,a,(a+b)/2,i*2);
  updr(l,r,v,(a+b)/2,b,i*2+1);
  V[i].v = f(V[i*2].v,V[i*2+1].v);
 }

 RQV query(int l,int r,int a=0,int b=0,int i=-1){
  if(i==-1){ a=0; b=N; i=1; }
  if(r<=a || b<=l) return Zero();
  spread(i,b-a);
  if(l<=a && b<=r) return V[i].v;
  RQV q1 = query(l,r,a,(a+b)/2,i*2);
  RQV q2 = query(l,r,(a+b)/2,b,i*2+1);
  q1 = f(q1,q2);
  ef(q1,V[i].r,min(r,b)-max(l,a));
  return q1;
 }

 int find(int l,RQV v,int a=0,int b=0,int i=-1){
  static RQV x;
  if(i==-1){ a=0; b=N; i=1; x=Zero(); }
  spread(i,b-a);
  if(b<=l) return N;
  if(l<=a && !cmp(v,f(x,V[i].v))){ x=f(x,V[i].v); return N; }
  if(b-a==1) return a;
  int q1 = find(l,v,a,(a+b)/2,i*2);
  if(q1!=N) return q1;
  return find(l,v,(a+b)/2,b,i*2+1);
 }
};

int N,Q;
RQ G;
 
int main(){
 scanf("%d%d",&N,&Q);
 G.init(N);
 rep(i,N){
  int a; scanf("%d",&a);
  G.upd(i,a);
 }
 rep(q,Q){
  int c; scanf("%d",&c);
  if(c==0){
   int l,r,b,c; scanf("%d%d%d%d",&l,&r,&b,&c);
   G.updr(l,r,{(ULL)b,(ULL)c});
  }
  if(c==1){
   int l,r; scanf("%d%d",&l,&r);
   printf("%llu\n",G.query(l,r));
  }
 }
 
 return 0;
}

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

using namespace std;

int main() {
    int n,a=0,b=0,c=0,d=0;
    string s;
    cin>>n;
    while(n--)
    {
        cin>>s;
        if(s=="AC")
           a++;
        else if(s=="WA")
           b++;
        else if(s=="TLE")
           c++;
        else d++;
    }
    
    cout<<"AC x "<<a<<"\n";
    cout<<"WA x "<<b<<"\n";
    cout<<"TLE x "<<c<<"\n";
    cout<<"RE x "<<d<<"\n";
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;

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

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

  int rootn = sqrt(n), m = n / (rootn + 1), s = rootn + m + 1;
  ll dp[k][s], cnt[s];
  memset(dp, 0, sizeof(dp));
  cnt[0] = 0;

  FOR(i, 1, rootn + 1) cnt[i] = 1;
  cnt[rootn + 1] = n / m - rootn;
  for (int i = rootn + 2, j = m - 1; i < s; i++, j--) {
    cnt[i] = n / j - n / (j + 1);
  }

  FOR(j, 1, s) {
    dp[0][j] = (cnt[j] + dp[0][j - 1]) % mod;
  }

  FOR(i, 1, k) {
    for (int j = 1, idx = s - 1; j < s; j++, idx--) {
      dp[i][j] = (dp[i - 1][idx] * cnt[j]) % mod;
      dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
    }
  }

  cout << dp[k - 1][s - 1] << endl;





  
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll N,L;
ll A[10010];

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

  cin>>N>>L;
  ll sum=0;
  rep(i,N){
    A[i]=L+i;
    sum+=A[i];
  }
  ll resa=INF,resb=-1;
  rep(i,N){
    if(resa>abs(sum-(sum-A[i]))){
      resa=abs(sum-(sum-A[i]));
      resb=sum-A[i];
    }
  }
  cout<<resb<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	long int K;
  	cin >>K;
  	queue<int>c;
  	int count=9;
 	long int ans;
if(K<9){ans=K;}
else{
  for(int i=0;i<9;i++){
  	c.push(i+1);
  } 
  	long int countst=0,counten=8;
 for(int p=0;p<=10;p++){
  for(int l=countst;l<=counten;l++){
  	long int g=c.front();
    c.pop();
    
    int memo=g%10;
    if(memo==0){
    c.push(10*g);count++;if(count==K){ans=10*g;}
    c.push(10*g+1);count++; if(count==K){ans=10*g+1;}
    }
    else if(memo==9){
    c.push(10*g+8);count++;if(count==K){ans=10*g+8;}
    c.push(10*g+9);count++;if(count==K){ans=10*g+9;}
    }
    else{
    c.push(10*g+memo-1);count++;if(count==K){ans=10*g+memo-1;}
    c.push(10*g+memo);count++;if(count==K){ans=10*g+memo;}
    c.push(10*g+memo+1);count++; if(count==K){ans=10*g+1+memo;}   
    }
  }
  countst=counten+1;
  counten=count-1;   
 }//ｐの 
}//elseの 
  
cout <<ans<<endl;
  
  
}

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

int main() {
    string O, E;
    cin >> O >> E;
    string res="";
    for (int i=0; i<E.length(); i++) {
        res = res + O.at(i) + E.at(i);
    }
    if (O.length()!=E.length()) res = res + O.at(O.length()-1);
    cout << res << "\n";
}

Measured memory_bytes: 256
N = int(input())
W = [input().strip() for _ in range(N)]

already_used = set()
current_word = W[0][0]

ans = 'Yes'
for word in W:
    if word in already_used or current_word[-1] != word[0]:
        ans = 'No'
        break
    already_used.add(word)
    current_word = word
print(ans)


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

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("2");
            WillReturn.Add("1 5");
            WillReturn.Add("2 4");
            WillReturn.Add("3 6");
            //3
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("3");
            WillReturn.Add("1 1 1");
            WillReturn.Add("2 2 2");
            WillReturn.Add("3 3 3");
            //27
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("6");
            WillReturn.Add("3 14 159 2 6 53");
            WillReturn.Add("58 9 79 323 84 6");
            WillReturn.Add("2643 383 2 79 50 288");
            //87
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static int UB_A;
    static int UB_C;

    static void Main()
    {
        List<string> InputList = GetInputList();

        int[] wkArr = { };
        Action<string> SplitAct = pStr =>
            wkArr = pStr.Split(' ').Select(X => int.Parse(X)).ToArray();

        SplitAct(InputList[1]);
        int[] AArr = wkArr;
        UB_A = AArr.GetUpperBound(0);

        SplitAct(InputList[2]);
        int[] BArr = wkArr;

        SplitAct(InputList[3]);
        int[] CArr = wkArr;
        UB_C = CArr.GetUpperBound(0);

        Array.Sort(AArr);
        Array.Sort(BArr);
        Array.Sort(CArr);

        long Answer = 0;
        foreach (int EachInt in BArr) {

            int wkInd1 = ExecNibunhou1(AArr, EachInt);
            long CurrCnt = wkInd1 + 1;

            int wkInd2 = ExecNibunhou2(CArr, EachInt);
            CurrCnt *= (UB_C - wkInd2 + 1);

            Answer += CurrCnt;
        }
        Console.WriteLine(Answer);
    }

    //2分法で指定した値未満の最大の添字を求める
    static int ExecNibunhou1(int[] pArr, int pVal)
    {
        if (pArr[0] >= pVal) return -1;
        int UB = pArr.GetUpperBound(0);
        if (pArr[UB] < pVal) return UB;

        int L = 0;
        int R = UB;

        while (L + 1 < R) {
            int Mid = (L + R) / 2;

            bool IsOK = (pArr[Mid] < pVal);
            if (IsOK) L = Mid;
            else R = Mid;
        }
        return L;
    }

    //2分法で指定した値超えの最小の添字を求める
    static int ExecNibunhou2(int[] pArr, int pVal)
    {
        if (pArr[0] > pVal) return 0;
        int UB = pArr.GetUpperBound(0);
        if (pArr[UB] <= pVal) return UB + 1;

        int L = 0;
        int R = UB;

        while (L + 1 < R) {
            int Mid = (L + R) / 2;

            bool IsOK = (pArr[Mid] > pVal);
            if (IsOK) R = Mid;
            else L = Mid;
        }
        return R;
    }
}


Measured memory_bytes: 43280
//
// Created by Pulak on 06-10-2019.
//

#include <stdio.h>
#define min(a,b) ((a>b? b:a))
#define max(a,b) ((a>b? a:b))
int main()
{
    int n =0;
    scanf("%d",&n);
    int p[n];
    for (int j = 0; j < n; ++j) {
        scanf("%d",&p[j]);    }
    int c =0;
    for (int i = 1; i < n -1 ; ++i) {
          if((min(p[i],min(p[i-1],p[i+1])) != p[i] )&& (max(p[i],max(p[i-1],p[i+1])) != p[i])){
              
          //    printf("%d",p[i]);
              c++;
          }
    }
    printf("%d ",c);






}

Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return int(i)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	n := nextInt()

	fmt.Println(n * n * n)
}


Measured memory_bytes: 640
#include <stdio.h>
int main(void)
{
    int a,b=0;
    scanf("%d %d",&a,&b);
    if(a<b)
    {
        printf("a < b\n");
    }
    else if(a>b)
    {
        printf("a > b\n");
    }
    else
    {
        printf("a == b\n");
    }
    return 0;
}



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

int a[200010];
int b[200010];

int main() {
	long long n,q;
	long long ans;
	int x,y,a_min,b_min;

	cin >> n >> q ;
	a_min=n-2;
	b_min=n-2;
	ans=(n-2)*(n-2);
	rep(i,n) a[i]=n-2;
	rep(i,n) b[i]=n-2;
	if (q==0){
		cout << ans << endl;
		return 0;
	}
	rep(i, q){
		cin >> x >> y ;
		if(x==1){
			if(y<a_min+2){
				rep2(j,y,a_min+2) a[j]=b_min;
				a_min=y-2;
			}
			ans-=a[y];
		}else{
			if(y<b_min+2){
				rep2(j,y,b_min+2) b[j]=a_min;
				b_min=y-2;
			}
			ans-=b[y];
		}
	}

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

Measured memory_bytes: 5144
#include <stdio.h>

int main(void)
{
	int a, b, d, r;
	double f;

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

	d = a / b;
	r = a%b;
	f = a / (double)b;

	printf("%d %d %.5f\n", d, r, f);

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

vector<string> T;
int N;
void dfs(string S = "", int depth = 0, int c = 1) {
    if (depth >= N) {
        T.push_back(S);
        return;
    }
    rep(i, c) {
        S.push_back('a' + i);
        dfs(S, depth + 1, max(c, i + 2));
        S.pop_back();
    }
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    dfs();
    for(auto& e: T) {
        cout << e << endl;
    }

    return 0;
}


Measured memory_bytes: 7324
import sys
from fractions import gcd

input = sys.stdin.readline


def main():
    N, X = map(int, input().split())
    x = list(map(int, input().split()))

    y = [abs(i - X) for i in x]
    ans = y[0]
    for i in range(1, N):
        ans = gcd(ans, y[i])

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 16276
#include <bits/stdc++.h>
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fastIO(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<ll> vll;
typedef vector<pii> vpii;

struct Edge{
	int to; //dastination edge
	int flow,cap;
	Edge* rev;
	Edge(int to, int flow, int cap, Edge* rev): to(to), flow(flow), cap(cap), rev(rev){}
};

vi dist; //distances
vector<vector<Edge*>> adj;
vector<int> parent;
vector<int> mini; //minimun residual capcaity
vector<Edge*> from;

//adds a new edge to the flow network
void add(int u, int v, int cap){
	Edge* uv = new Edge(v,0,cap,NULL);
	Edge* vu = new Edge(u,0,0,NULL); //set cap of vu to cap in undirected edges
	adj[u].pb(uv);
	adj[v].pb(vu);
	uv->rev = vu;
	vu->rev = uv;
}

//searchs for a  increasing path
void bfs(int s){
	queue<int> q;
	dist.assign(adj.size(),-1);
	parent.resize(adj.size());
	from.resize(adj.size());
	mini.assign(adj.size(),1e9);
	dist[s] = 0;
	q.push(s);
	while(q.size()){
		int u = q.front();
		q.pop();
		for(auto* e: adj[u]){
			int v = e->to;
			int capRes = e->cap - e->flow;
			if(capRes > 0 && dist[v] == -1){
				dist[v] = dist[u]+1;
				from[v] = e;
				parent[v] = u;
				mini[v] = min(capRes, mini[u]);
				q.push(v);
			}

		}

	}
}

//retuns the max flow of the flow network
int maxFlow(int s, int t){
	int f = 0;
	while(true){
		bfs(s);
		if(dist[t] == -1) break;
		int v = t;
		int mn = mini[t];
		while(v != s){
			Edge* e = from[v];
			e->flow += mn;
			e->rev->flow -= mn;
			v = parent[v];
		}
		f += mn;
	}
	return f;
}

int n,x,y;
vpii R,B;

void build(){
	auto le = [](pii a, pii b){ return a.fi < b.fi && a.se < b.se; };
	adj.resize(2*n+2);
	forn(i,n){
		forn(j,n){
			if( le(R[i],B[j]) )
				add(i+1,n+j+1,1);
		}
		add(0,i+1,1);
		add(i+n+1,2*n+1,1);
	}
}

int main () {
	fastIO();
	cin >> n;
	R.resize(n);
	B.resize(n);
	forn(i,n) cin >> R[i].fi >> R[i].se;
	forn(i,n) cin >> B[i].fi >> B[i].se;
	build();
	cout << maxFlow(0,2*n+1) << endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin)-1;i>=(end);i--)
#define IREP(i, n) IFOR(i,n,0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" << v[0]; FOR(i_debug, 1, v.size()){ cout << "," << v[i_debug]; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;


template<typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) { REP(i, a.size()) {cin >> a[i]; a[i]--;} }

ll mod = 1000000007;

int main()
{
	ll N;
	cin >> N;
	vec a(N + 1);
	REP(i, N) {
		cin >> a[i + 1];
	}

	vec ans(N + 1, -1);

	IFOR(i, N + 1, 1) {
		ll sum = a[i];
		for (ll j = i; j <= N; j += i) {
			if (ans[j] != -1) sum += ans[j] % 2;
		}
		sum %= 2;
		// debug(sum);
		ans[i] = sum % 2;
		// vdebug(ans);
	}

	ll M = 0;
	vec b(0);
	FOR(i, 1, N + 1) {
		if (ans[i]) {
			M++;
			b.emplace_back(i);
		}
		// cout << ans[i] << endl;
	}
	cout << M << endl;
	REP(i, M - 1) {
		cout << b[i] << " ";
	}
	if (M > 0)cout << b[M - 1] << endl;

	return 0;
}

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll x; cin >> x;
    cout << (x / 500) * 1000 + ((x % 500) / 5) * 5 << endl;
}


Measured memory_bytes: 256
import javax.swing.text.MutableAttributeSet;
import java.util.*;

public class Main {

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

        String s = sc.next();

        if(n == 1){
            System.out.println("0");
            System.exit(0);
        }
        
        List<Integer> list = new ArrayList<>();
        int index = 0;
        int ans = 0;
        for (int i = 1; i < n; i++) {
            while (s.charAt(i) == s.charAt(i - 1)) {
                i++;
                if(i >= n){
                    break;
                }
            }
            list.add(i - index);
            ans += i - index - 1;
            index = i;
        }
        if(s.charAt(n-1) != s.charAt(n-2)){
            list.add(1);
        }

        if(list.size() % 2 == 0){
            if(((list.size()/2)-1) >= k){
                ans += k * 2;
            } else {
                ans = n-1;
            }

        } else {
            ans += Math.min(list.size()-1, k*2);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 28132
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define mp(x,y) make_pair(x,y) 
#define ll long long
#define MN 200005
using namespace std;
inline ll in(){
    ll x=0;bool f=0;char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
typedef pair<ll,int> pr;
//priority_queue<pr,vector<pr>,greater<pr> >q;
priority_queue<ll,vector<ll>,greater<ll> >q;
struct edge{
	int to,nxt;
}e[MN<<1];
ll a[MN],res;
int d[MN],fa[MN],rk[MN],num[MN],h[MN],ch[2][MN];
int n,m,x,y,cnt,tot,fx,fy,rt,ct;
bool vis[MN];
ll mn[MN];bool tmp[MN];
inline int gf(int x){return fa[x]?fa[x]=gf(fa[x]):x;}
inline void ins(int x,int y){
	e[++cnt].to=y;e[cnt].nxt=h[x];h[x]=cnt;
}
inline void dfs(int u){
	mn[tot]=min(mn[tot],a[u]);
	for (int i=h[u];i;i=e[i].nxt){
		int v=e[i].to;
		if (vis[v]) continue;
		vis[v]=1;num[v]=tot;dfs(v);
	}
}
inline int merge(int x,int y){
    if (!x) return y;if (!y) return x;
    if (a[x]>a[y]||(a[x]==a[y]&&x>y)) swap(x,y);
    ch[1][x]=merge(ch[1][x],y);fa[ch[1][x]]=x;
    if (d[ch[0][x]]<d[ch[1][x]]) swap(ch[0][x],ch[1][x]);
    d[x]=d[ch[1][x]]+1;return x;
}
inline int pop(int x){
    a[x]=-1;fa[x]=-1;fa[ch[0][x]]=fa[ch[1][x]]=0;
    return merge(ch[0][x],ch[1][x]);
}
int main()
{
	n=in();m=in();
	memset(mn,0x3f,sizeof(mn));
	for (int i=1;i<=n;++i) a[i]=in();
	for (int i=1;i<=m;++i){
		x=in()+1;y=in()+1;
		ins(x,y);ins(y,x);
	}
	for (int i=1;i<=n;++i)
	if (!vis[i]){
		vis[i]=1;num[i]=(++tot);
		rk[tot]=i;dfs(i);
	}
	if (tot==1) {printf("0");return 0;}
	for (int i=1;i<=tot;++i) res+=1ll*mn[i];
	for (int i=1;i<=n;++i){
		if (!tmp[num[i]]&&a[i]==mn[num[i]]) {tmp[num[i]]=1;continue;}
		else q.push(a[i]);
	}
	while (!q.empty()){
		if (ct==tot-2) break;
		ll x=q.top();q.pop();++ct;res+=1ll*x;
	} 
	if (ct==tot-2) printf("%lld",res);else printf("Impossible");
	/*
	for (int i=1;i<=n;++i){
		if (rk[num[i]]==i) continue;
		fx=gf(i),fy=gf(rk[num[i]]);merge(fx,fy);
	}
	for (int i=1;i<=tot;++i){
		fx=gf(rk[i]);q.push(mp(a[fx],fx));
	}
	while (!q.empty()){
		pr x=q.top();q.pop();
		if (q.empty()) break;pr y=q.top();q.pop();
		res+=1ll*x.first+y.first;++ct;
		fx=gf(x.second),fy=gf(y.second);printf("%d %d\n",fx,fy);
		fx=pop(fx);fy=pop(fy);rt=merge(fx,fy);
		if (rt) q.push(mp(a[rt],rt));
	}*/
//	if (ct+m!=n-1) printf("Impossible");
//	else 
//	printf("%lld",res);
	return 0;
}

Measured memory_bytes: 11512
#include<stdio.h>
int G[100][100] = { 0 };
int main(){
	int n, u, k, v;
	int i, j;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &u);
		scanf("%d", &k);
		for (j = 0; j < k; j++) {
			scanf("%d", &v);
			G[u - 1][v - 1] = 1;
		}
	}
	// ??????
	for (i = 0; i < n; i++) {
		printf("%d", G[i][0]);
		for (j = 1; j < n; j++) {
			printf(" %d", G[i][j]);
		}
		printf("\n", G[i][0]);
	}
	return 0;
}

Measured memory_bytes: 632
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define addf(T) [](T a, T b){return (a + b);}
#define minf(T) [](T a, T b){return min(a, b);}
#define maxf(T) [](T a, T b){return max(a, b);}


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acos(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

ll lcm(ll number1, ll number2) {
	return number1 / gcd(number1, number2) * number2;
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/


int main() {

	int n, m, dice;
	scanf("%d%d", &n, &m);
	double ans = 0;
	rep(i, n){
	  dice = 0;
	  while(m > (i + 1) * pow(2, dice))++dice;
	  ans += 1 / (double)n * 1 / pow(2, dice);
	}
	printdb(ans);
	
	Please AC;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
import java.util.HashMap;

public class Main
{
    int n, l;
    String[] strs;
    
    public static void main(String args[])
    {
	new Main().solve();
    }
    
    void solve()
    {
	in();
	
	Arrays.sort(strs);
	String ans = "";
	for(int i = 0; i < n; i++) ans += strs[i];
	
	out(ans);
    }

    void in()
    {
	Scanner sc = new Scanner(System.in);
	n = sc.nextInt();
	l = sc.nextInt();
	strs = new String[n];
	for(int i = 0; i < n; i++) strs[i] = sc.next();
    }

    void out()
    {
	
    }
    
    void out(int n)
    {
	System.out.println(n);
    }

    void out(double n)
    {
	System.out.println(n);
    }

    void out(long n)
    {
	System.out.println(n);
    }
    
    void out(char c)
    {
	System.out.print(c);
    }
    
    void out(String s)
    {
	System.out.println(s);
    }
}


Measured memory_bytes: 24020
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
using namespace std;


int main(){
    int n,c;
    cin>>n;
    c=n;
    for(int i=2;i<=n;i++){
        if(n%i==0){
            while(n%i==0){n=n/i;}
            c=c/i*(i-1);
        }
    }
    cout<<c<<endl;
    
    
    return 0;
}


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

typedef long long lint;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<psi, int> psii;

const int INF = 2e9;
const int MOD = 1e9+7;
const int MAX = 1e5+10;
const lint LNF = 2e18;

int n;
psii A[MAX];

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

	cin>>n;
	for(int i=1; i<=n; i++){
		cin>>A[i].first.first>>A[i].first.second;
		A[i].first.second *= -1;
		A[i].second = i;
	}
	sort(A+1, A+n+1);
	for(int i=1; i<=n; i++) cout<<A[i].second<<'\n';

	return 0;
}


Measured memory_bytes: 2560
N,A,B = gets.split.map(&:to_i)
min = 0
max = 0
sum = 0

sum = A + B 

if A < B
    max = A
else
    max = B
end
if sum - N <= 0
    min = 0
else
    min = sum - N
end
puts "#{max} #{min}"

Measured memory_bytes: 1788
import sys

sys.setrecursionlimit(10**6)
input = sys.stdin.readline

def main():
    S = input()[:-1]
    if S == 'RRR':
        print(3)
    elif S in ['RRS', 'SRR']:
        print(2)
    elif S == 'SSS':
        print(0)
    else:
        print(1)

if __name__ == "__main__":
    main()


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

int main() {
	long long A[3];
	for(int i = 0; i<3; i++) cin>>A[i];
	
	for(int i = 0; i < 3; i++){
		if(A[i] % 2 == 0){
			//cout<<A[(i+1)%3]*A[(i+2)%3]*(A[i] / 2)<<endl;
			cout<<0<<endl;
			return 0;
		}
	}
	
	sort(A,A+3);
	
	//cout<<A[0]*A[1]*((A[2]+1LL)/2LL - A[1]/2LL)<<endl;
	cout<<A[0]*A[1]<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (LLONG_MAX - 1e5)

using namespace std;

int N, L, A[100005], sum[100005];

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

    cin >> N >> L;
    REP(i, N) cin >> A[i];

    int t = -1;
    REP(i, N - 1) {
        if (A[i] + A[i+1] >= L)
        {
            t = i;
            break;
        }
    }
    if (t == -1)
    {
        cout << "Impossible" << endl;
        return 0;
    }

    cout << "Possible" << endl;
    FOR(i, 1, N-1) {
        if (i >= t+1) break;
        cout << i << endl;
    }
    REV(i, N-1, 1) {
        if (i <= t) break;
        cout << i << endl;
    }
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
using namespace std;
typedef long long unsigned int ll;
 
int main() {
 
  int a,b,c,d;
  cin >> a;
  cin >>b;
  cin >>c;
  if(a+b>9){
	cout <<"error" <<endl;
  }else{
	cout << a+b <<endl;
  }
    return 0;
}


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

int main(){
    int X,A,B,C,sum = 0,count = 0;
    cin >> A >> B >> C >> X;
    for (int i = 0; i <= A; i++){
        for (int j = 0; j <= B; j++){
            for (int k = 0; k <= C; k++){
                sum = 500*i + 100*j + 50*k;
                if (sum == X) count++;
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
//#include "Local_Debug.h"
using namespace std;
#define Endl endl
#define debug(x) cout << #x << " = " << (x) << endl
typedef long long ll;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)2e5 + 5;
ll a, b;
ll gcd(ll a, ll b)
{
	return b ? gcd(b, a%b) : a;
}
int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	while (cin >> a >> b)
	{
		vector<ll> v;
		ll g = gcd(a, b), len = ll(sqrt(g));
		for (ll i = 1; i <= len; ++i)
			if (g%i == 0)
			{
				v.emplace_back(i);
				if (g != i*i)
					v.emplace_back(g / i);
			}
		sort(v.begin(), v.end());
		for (auto it = v.begin(); it != v.end(); ++it)
			if (*it != 1)
				for (auto it2 = it + 1; it2 != v.end();)
				{
					if (*it2%*it == 0)
						it2 = v.erase(it2);
					else
						it2++;
				}
		cout << v.size() << endl;
	}
}
/*
12 18

420 660

1 2019
*/

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll                      long long
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     3e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll> >
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll T;cin>>T;while(T--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define prll(a)                 cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,cur)               lower_bound(all(v),cur)-v.begin()
#define ub(v,cur)               upper_bound(all(v),cur)-v.begin()
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
long long pows(long long a, long long b) {
  long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll powm(ll x,ll y,ll m=MOD){x=x%m;ll res=1;while(y){if(y&1)res=res*x;res%=m;y=y>>1;x=x*x;x%=m;}return res;}
ll modInverse(ll a, ll m=MOD){if(m == 1)return 0;ll m0=m,y=0,x=1;while(a>1){ll q=a/m,t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0) x+=m0;return x;}
int main()
{
fastIO
ll n,m;
cin>>n>>m;
ll ar[m];
ll ans=0;
for(ll i=0;i<m;i++)
{
  cin>>ar[i];
  ans+=ar[i];
}
if(ans>n)
{
  cout<<"-1";
}
else
{
  cout<<n-ans;
}
}


Measured memory_bytes: 3736
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}
#define DEBUG_VLL(vec) REP(i, vec.size()) cerr<<vec[i]<<(i==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

ll merge(vll &b, ll n, ll left, ll mid, ll right) {
    ll cnt = 0;
    ll n1 = mid - left;
    ll n2 = right - mid;
    vll L(n1+1), R(n2+1);
    REP(i, n1) L[i] = b[left+i];
    REP(i, n2) R[i] = b[mid+i];
    L[n1] = R[n2] = HIGHINF;
    ll i = 0, j = 0;
    rep(k, left, right) {
        if (L[i] <= R[j]) {
            b[k] = L[i++];
        } else {
            b[k] = R[j++];
            cnt += n1 - i;
        }
    }
    return cnt;
}

ll merge_sort(vll &b, ll n, ll left, ll right) {
    if (left+1 < right) {
        ll mid = (left + right) / 2;
        ll ans1 = merge_sort(b, n, left, mid);
        ll ans2 = merge_sort(b, n, mid, right);
        ll ans3 = merge(b, n, left, mid, right);
        return ans1 + ans2 + ans3;
    } else return 0;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k; cin >> n >> k;
    vll a(n), b(n+1, 0);
    REP(i, n) {
        cin >> a[i];
        b[i+1] = b[i] + a[i] - k;
    }
    cout << n*(n+1)/2 - merge_sort(b, n+1, 0, n+1) << '\n';
    return 0;
}


Measured memory_bytes: 5064
#include <functional>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, P> PP;

template <typename S>   //semi group
struct UnionFind
{
    using F = function<S(S, S)>;
    
    const F f;
    
    vector<int> par, rank;
    vector<S> dat;
    
    UnionFind(int n, const F f = [](S a, S b){return a + b;}, const S e = 1) : f(f){
        par.resize(n);
        rank.resize(n);
        dat.assign(n, e);
        for(int i = 0; i < n; i++){
            par[i] = i;
            rank[i] = 0;
        }
    }
    
    int find(int i){
        if(i == par[i]) return i;
        return par[i] = find(par[i]);
    }
    
    bool same(int i, int j){
        return find(i) == find(j);
    }
    
    void unite(int i, int j){
        if(same(i, j)) return;
        i = find(i), j = find(j);
        if(rank[i] < rank[j]){
            par[i] = j;
            dat[j] = f(dat[i], dat[j]);
        }
        else{
            par[j] = i;
            dat[i] = f(dat[i], dat[j]);
            if(rank[i] == rank[j]) rank[i]++;
        }
    }
    
    S query(int i){
        return dat[find(i)];
    }
};

int main()
{
    int n, h, w;
    cin >> n >> h >> w;
    PP p[100005];
    for(int i = 0; i < n; i++){
        int r, c;
        ll a;
        cin >> r >> c >> a;
        r--; c--;
        p[i] = PP(a, P(r, c));
    }
    sort(p, p + n, greater<PP>());
    int x[100005], y[100005];
    for(int i = 0; i < h; i++) x[i] = -1;
    for(int i = 0; i < w; i++) y[i] = -1;
    UnionFind<P> uf(n, [](P a, P b){return P(a.first + b.first, a.second + b.second);}, P(1, 1));
    ll ans = 0;
    for(int i = 0; i < n; i++){
        int u = p[i].second.first, v = p[i].second.second;
        ans += p[i].first;
        if(x[u] == -1 && y[v] == -1){
            uf.dat[i].second++;
            x[u] = i;
            y[v] = i;
        }
        else if(x[u] == -1){
            uf.unite(i, y[v]);
            x[u] = i;
        }
        else if(y[v] == -1){
            uf.unite(i, x[u]);
            y[v] = i;
        }
        else{
            int l = uf.find(x[u]);
            int r = uf.find(y[v]);
            if(uf.dat[l].first + uf.dat[r].first < uf.dat[l].second + uf.dat[r].second){
                uf.unite(i, x[u]);
                uf.unite(i, y[v]);
                int w = uf.find(i);
                uf.dat[w].second--;
            }
            else{
                ans -= p[i].first;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 7204
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <complex>

using ll = long long int;
using namespace std;

int main(){
  ll N, M, tmp, sum_A = 0;
  vector<ll> A;

  cin >> N >> M;
  for(ll i = 0; i < N; i++){
    cin >> tmp;
    A.push_back(tmp);
    sum_A += A[i];
  }

  ll count = 0;
  for(ll i = 0; i < N; i++){
    if(4*M*A[i] >= sum_A){
      count++;
    }
  }

  if(count >= M){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

  return 0;
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ss string 
int main()

{ 
	int n;
	cin >> n;
	int rem=n%1000;
	if(rem==0)
	{
		cout << 0;
	}
	else
	{
		cout << 1000-rem;
	}
	
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 32;
int main(){
  int n;
  long long dp[105][105];
  int e,u,v,c;
  cin>>n>>e;
  //dpの初期化
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      //iとjが等しければコストは0
      dp[i][j]=((i==j)?0:INF);
    }
  }  

  for(int i=0;i<e;i++){
    cin>>u>>v>>c;
    dp[u][v]=c;
  }

  //ここから更新
  for(int k=0;k<n;k++){
    for(int i=0;i<n;i++){
      if(dp[i][k]==INF) continue;
      for(int j=0;j<n;j++){
        if(dp[k][j]==INF) continue;
        dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
      }
    }
  }
  
  //負の経路の検出
  bool negative=false;
  for(int i=0;i<n;i++) if(dp[i][i]<0) negative=true;

  if(negative){
    cout<<"NEGATIVE CYCLE"<<'\n';
  }
  else{
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        if(j) cout<<" ";
        if(dp[i][j]==INF) cout<<"INF";
        else cout<<dp[i][j];
      }
      cout<<'\n';
    }
  }
  return(0);
}


Measured memory_bytes: 3212
#include <iostream>
#include <utility>
#include <vector>
#include <tuple>
#include <cstdint>
#include <algorithm>

using namespace std;

// Type aliases
using i8  =  int8_t; using  u8 =  uint8_t;
using i16 = int16_t; using u16 = uint16_t;
using i32 = int32_t; using u32 = uint32_t;
using i64 = int64_t; using u64 = uint64_t;

template <class T> using V = vector<T>;

// Loops
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, n, m) for (int i = n; i < m; ++i)
#define FORR(i, n, m) for (int i = m - 1; i >= n; --i)

// Input
template <class T>
T read() {
    T t;
    cin >> t;
    return t;
}

template <class T>
vector<T> read(const int length) {
    vector<T> ts(length);
    for (auto& t: ts) {
        cin >> t;
    }
    return ts;
}

// Output
namespace debug {
    template <class F, class S>
    ostream &operator<<(ostream& stream, const pair<F, S> &pair) {
        stream << "{" << pair.first << ", " << pair.second << "}";
        return stream;
    }
    template <class Arg, class ...Args>
    void output(ostream& stream, tuple<Arg, Args...> tuple) {
        stream << get<1>(tuple) << ", ";
        // TODO
    }
    template <class Arg>
    void output(ostream& stream, tuple<Arg> tuple) {
        stream << get<1>(tuple);
    }
    template <class ...Args>
    ostream &operator<<(ostream& stream, const tuple<Args...> &tuple) {
        stream << "{";
        output(stream, tuple);
        stream << "}";
        return stream;
    }

    template <class T, class Alloc>
    ostream &operator<<(ostream& stream, const vector<T, Alloc> &vector) {
        stream << "[";

        for (auto i = 0; i < vector.size(); i++) {
            stream << vector[i];

            if (i != vector.size() - 1) {
                stream << "," << ((i % 10 == 9) ? "\n " : "\t");
            }
        }

        stream << "]";
        return stream;
    }
}

// Body
void body() {
    auto N = read<u32>();
    auto K = read<u64>();
    auto xs = vector<pair<u32, u32>>(N);
    for (auto &x: xs) {
        x.first = read<u32>();
        x.second = read<u32>();
    }

    sort(xs.begin(), xs.end(), [](auto &x1, auto& x2) { return x1.first < x2.first; });

    u64 index = 0;
    for (auto &x: xs) {
        auto a_i = x.first;
        auto b_i = x.second;

        if (index < K && K <= index + b_i) {
            cout << a_i << endl;
            break;
        }
        index += b_i;
    }
}

// main function (DO NOT EDIT)
int main () {
    ios_base::sync_with_stdio(false);
    body();
    return 0;
}

Measured memory_bytes: 1024
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reads f = stdin.ReadLine().Split() |> Array.map f

[<EntryPoint>]
let main _ =
    let S = read string |> Seq.toArray
    let revS = Array.rev S

    // eprintfn "%A" S
    // eprintfn "%A" revS

    Array.zip S revS
    |> Array.sumBy (fun (x, y) -> if x <> y then 1 else 0)
    |> fun x -> x / 2
    |> printfn "%i"
    0

Measured memory_bytes: 14044
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define C 0.5772156649
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1

using namespace std;

const double g=10.0,eps=1e-7;
const int N=100000+10,maxn=60000+10,inf=0x3f3f3f3f;

int main()
{
    string s;
    cin>>s;
    cout<<s.substr(0,s.size()-8)<<endl;
    return 0;
}
/********************

********************/


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

#define INF 1000010
#define MAX_V 110

using namespace std;

int cost[MAX_V][MAX_V];

int main(){
    int n;

    for(int i=0; i < MAX_V; i++) for(int j=0; j < MAX_V; j++) cost[i][j] = INF;
    for(int i=0; i < MAX_V; i++) cost[i][i] = 0;

    cin >> n;
    for(int i=0; i < n; i++){
        int e1;
        int m;
        cin >> e1 >> m;
        for(int j=0; j < m; j++){
            int e2;
            cin >> e2;
            cost[e1-1][e2-1] = 1;
        }
    }

    for(int k=0; k < n; k++){
        for(int i=0; i < n; i++){
            for(int j=0; j < n; j++) cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j]);
        }
    }

    cin >> n;
    for(int i=0; i < n; i++){
        int e1, e2, t;
        cin >> e1 >> e2 >> t;
        if(cost[e1-1][e2-1] != INF && cost[e1-1][e2-1]+1 <= t) cout << cost[e1-1][e2-1]+1 << endl;
        else cout << "NA" << endl;
    }
}

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

int main() {
	long long a, b, x;
	cin >> a >> b >> x;
	long long da, db;
	da = a % x;
	db = b % x;
	long long e;
	if (da == 0) e = (b - db) - a;
	else e = (b - db) - (a - da + x);

	long long temp = e / x;
	cout << temp + 1 << endl;
	//cin >> a;
}

Measured memory_bytes: 256
N,M = map(int,input().split())

d = int(M**(1/2))
div_list = []
while d >= 1:
    if M%d == 0:
        div_list.append(d)
        div_list.append(M//d)
    d -= 1

div_list.sort(reverse = True)
for i in range(len(div_list)):
    if div_list[i] <= M//N:
        print(div_list[i])
        break

Measured memory_bytes: 3188
// C - Factors of Factorial
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 

int sieve[1005];
vi primes;

int32_t main()
{
    fast;
    int n, ans = 1; cin >> n;
    for(int x = 2; x <= n; x++) {
        if(sieve[x]) continue;
        for(int u = 2*x; u <= n; u += x) {
            sieve[u] = x;
        }
    }

    Rep(i, 2, n) {
        int cnt = 0;
        if(sieve[i] == 0) {
            int exp = 1;
            while(pow(i, exp) <= n) {
                int x = pow(i, exp);
                cnt += (n/x);
                exp++;
            }
            ans *= (cnt+1);
            ans %= MOD;
        }
    }

    cout << ans;
   
    
    return 0;
}

Measured memory_bytes: 4068
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a>b)
    {
        cout<<"a > b"<<endl;
    }else if(a<b)
    {
        cout<<"a < b"<<endl;
    }else
    {
        cout<<"a == b"<<endl;
    }
}


Measured memory_bytes: 3080
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;
 
#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
 
const ll MAX_N = 100000;
 
int main(void){
    ll a,b,c,d;
    string s,t;
 
    cin >> a >> b>> c >> d;
    //cin >> s >> t;
    if (a<=c&&c<=b) cout << "Yes";
    else cout << "No";



    return 0;
}

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

vector<int>E[100000];
int d[100000], par[17][100000];
void dfs(int v, int p, int d1) {
	d[v] = d1; par[0][v] = p;
	for (int u : E[v])dfs(u, v, d1 + 1);
}
int lca(int a, int b) {
	if (d[a] > d[b])swap(a, b);
	rep(i, LOG + 1) {
		if ((d[b] - d[a]) >> i & 1)b = par[i][b];
	}
	if (a == b)return a;
	for (int i = LOG; i >= 0; i--) {
		if (par[i][a] != par[i][b]) {
			a = par[i][a]; b = par[i][b];
		}
	}
	return par[0][a];
}
int main() {
	int n; scanf("%d", &n);
	rep(i, n) {
		int k; scanf("%d", &k);
		rep(j, k) {
			int c; scanf("%d", &c);
			E[i].push_back(c);
		}
	}
	dfs(0, -1, 0);
	for (int i = 1; i <= LOG; i++) {
		rep(j, n) {
			if (par[i - 1][j] == -1)par[i][j] = -1;
			else par[i][j] = par[i - 1][par[i - 1][j]];
		}
	}
	int q; scanf("%d", &q);
	rep(i, q) {
		int u, v; scanf("%d%d", &u, &v);
		printf("%d\n", lca(u, v));
	}
}

Measured memory_bytes: 20316