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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n; cin >> n;
  vector<pair<int, int>> p(n);
  for (int i = 0; i < n; i++) {
    int a; cin >> a;
    p[i] = make_pair(a, i + 1);
  }
  sort(p.begin(), p.end());
  for (int i = 0; i < n; i++) {
    char tail = (i == n - 1) ? '\n' : ' ';
    cout << p[i].second << tail;
  }
  return 0;
}

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

int main()
{
    int n;
    char s[100000];

    cin >> n >> s;

    int cnt = 0;
    for( int i = 0; i < n; i++ )
    {
        if( s[i] == 'x' && s[i+1] == 'x' )
        {
            cnt++;
            break;
        }
        cnt++;
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3220
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;
int w[28],bef1[3005][28],bef2[3005][28];
pair<int,pair<int,int> > dp[3005][3005],ans;
string s1,s2,S;
int main() {
	ios_base::sync_with_stdio(false);
	cin>>s1>>s2;
	s1='@'+s1;
	s2='@'+s2;
	for(int i=0; i<26; i++)
		w[i]=-1;
	for(int i=1; i<s1.size(); i++) {

		for(int j=0; j<26; j++) {
		 bef1[i][j]=w[j];
		}
		w[s1[i]-'a']=i;
	}
	for(int i=0; i<26; i++)
		w[i]=-1;
	for(int i=1; i<s2.size(); i++) {

		for(int j=0; j<26; j++) {
		 bef2[i][j]=w[j];
		}
		w[s2[i]-'a']=i;
	} 
	for(int i=1; i<s1.size(); i++) {
		for(int j=1; j<s2.size(); j++) {
            if(s1[i]!=s2[j]) continue;
            dp[i][j].f=1;
			for(int c=0; c<26; c++) {

				if(bef1[i][c]!=-1 && bef2[j][c]!=-1){
					
					if(dp[bef1[i][c]][bef2[j][c]].f+1>dp[i][j].f){
						
						dp[i][j].f=dp[bef1[i][c]][bef2[j][c]].f+1;
						dp[i][j].s={bef1[i][c],bef2[j][c]};
					}
				
				}
				}
					if(dp[i][j].f>ans.f){
						ans.f=dp[i][j].f;
						ans.s={i,j};
					}
		}
	}
	
	while(ans.s.f!=0){
		S+=s1[ans.s.f];
		ans.s=dp[ans.s.f][ans.s.s].s;
	}
	reverse(S.begin(),S.end());
	cout<<S;


}

Measured memory_bytes: 109928
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    ll A, B, C, D;
    cin >> A >> B >> C >> D;

    ll g = C * D / __gcd(C, D);

    auto cnt = [&] (ll x) {
        return B / x - (A - 1) / x;
    };

    print(cnt(1) - cnt(C) - cnt(D) + cnt(g));
    
}


Measured memory_bytes: 3600
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
 
using namespace std;
typedef long long int lli;
typedef vector<int> vi;
const int MAX=1e5+5;
 
int N,M;
 
//隣接リスト
vi nb[MAX];
vi pa[MAX];
//入次数の管理
int id[MAX];
//トポロジカルソートをvectorで管理
//ts は頂点のソート、ordは頂点iが何番目かを表す。
vi ts;
int ord[MAX];
 
void top_sort(){
	//入次数0の箱
	stack<int> st;
	rep(i,N)if(id[i]==0)st.push(i);
	while(!st.empty()){
		int i=st.top();st.pop();
		ts.push_back(i);
		rep(j,(int)nb[i].size()){
			id[nb[i][j]]--;
			if(id[nb[i][j]]==0)st.push(nb[i][j]);
		}
	}
	rep(i,N)ord[ts[i]]=i;
}
 
int main(){
	cin>>N>>M;
	rep(i,N-1+M){
		int a,b;
		cin>>a>>b;
		nb[a].push_back(b);
      	pa[b].push_back(a);
		id[b]++;
	}
	top_sort();
	rep1(i,N){
      	int l=pa[i].size();
    	if(l==0)cout<<0<<endl;
        else if(l==1)cout<<pa[i][0]<<endl;
      	else{
          int mxi=pa[i][0];
          rep1(j,l-1){
          	int w=pa[i][j];
            if(ord[mxi]<ord[w])mxi=w;
          }
          cout<<mxi<<endl;
        }
    }
}

Measured memory_bytes: 13052
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                string x = Console.ReadLine();
                string y = Console.ReadLine();

                int lenX = x.Length;
                int lenY = y.Length;

                int[,] lcs = new int[lenX + 1, lenY + 1];

                for (int j = 1; j <= lenX; j++)
                {
                    for (int k = 1; k <= lenY; k++)
                    {
                        if (x[j - 1] == y[k - 1]) lcs[j, k] = lcs[j - 1, k - 1] + 1;
                        else lcs[j, k] = Math.Max(lcs[j - 1, k], lcs[j, k - 1]);
                    }
                }
                sb.AppendLine(lcs[lenX, lenY].ToString());
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 18400
#include<stdio.h>
#include<string.h>
int main(void){
char s[101];
  scanf("%s",&s);
  int ans=0;
  for(int i=0;i<strlen(s)/2;i++){
    if(s[i]!=s[strlen(s)-1-i])ans++;
       }
       
       printf("%d",ans);
       return 0;
       }
    
       

    
    

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define mod 1000000007
#define inf 1e18+9
#define fr first
#define sc second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pll pair<ll,ll>
#define vll vector<ll>
#define umap unordered_map<ll,ll>
#define lpq priority_queue<ll,vector<ll>,greater<ll>>
ll globe=0;
ll powe(ll n,ll r){if(!r)return 1;else if(r%2==0)return powe(n*n,r/2);else return n*powe(n*n,(r-1)/2);}

vll Dijkstras(vector<vll> &graph,vector<vll> &cst,ll src){
	//Time Complexity: O(V+ELogV)
	ll nodes=graph.size();
	vll par(nodes,-1);
	vector<bool> vis(nodes,false);
	vll dist(nodes,inf);
	multiset<pll> ms;
	ms.insert(make_pair(0,src));
	while(!ms.empty()){
		pll p=*ms.begin();
		ms.erase(ms.begin());
		ll r=p.second;
		if(vis[r])
			continue;
		vis[r]=true;
		dist[r]=p.first;
		for(ll i=0;i<graph[r].size();i++){
			if(dist[graph[r][i]]>dist[r]+cst[r][graph[r][i]]){
				dist[graph[r][i]]=dist[r]+cst[r][graph[r][i]];
				ms.insert(make_pair(dist[graph[r][i]],graph[r][i]));
				par[graph[r][i]]=r;
			}
		}
	}
	return dist;
}

int32_t main(){
 
	ios::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    
	ll t=1;
	//cin>>t;
	while(t--){
	    ll n,x,y;
	    cin>>n>>x>>y;
	    vector<vll> graph(n);
	    vector<vll> cost(n,vll (n,inf));
	    for(ll i=0;i<n;i++)
	        cost[i][i]=0;
	    for(ll i=1;i<n;i++){
	        graph[i].pb(i-1);
	        graph[i-1].pb(i);
	        cost[i][i-1]=1;
	        cost[i-1][i]=1;
	    }
	    graph[x-1].pb(y-1);
	    graph[y-1].pb(x-1);
	    cost[x-1][y-1]=1;
	    cost[y-1][x-1]=1;
	    vector<vll> ans(n);
	    for(ll i=0;i<n;i++){
	        ans[i]=Dijkstras(graph,cost,i);
	    }
	    vll h(n,0);
	    for(ll i=0;i<n;i++){
	        for(ll j=0;j<n;j++){
	            if(ans[i][j]<=n-1)
	                h[ans[i][j]]++;
	        }
	    }
	    for(ll i=1;i<n;i++)
	        cout<<h[i]/2<<endl;
	}
 
	return 0;
 
}
//BitMasking->setBit: n|(1<<i); unsetBit: n&!(1<<i); checkBit: n&(1<<i);
//ll idx=upper_bound(v.begin(),v.end(),val)-v.begin();
//v.erase(unique(v.begin(),v.end()),v.end());
//ll cnt=count(v.begin(),v.end(),val);
//bool f=find(v.begin(),v.end(),val);

Measured memory_bytes: 63104
#include<stdio.h>
int main(void){
  int N, max1=1, max2=0;
  scanf("%d", &N);
  int A[N+1];
  for(int i=0; i<N; i++){
    scanf("%d", &A[i]);
  }
  for(int i=0; i<N; i++){
    if(max1<A[i]){max1=A[i];}
    else if(max2<A[i]){max2=A[i];}
  }
  for(int i=0; i<N; i++){
    if(max1==A[i]){printf("%d\n",max2);}
    else{printf("%d\n",max1);}
  }
      
}


Measured memory_bytes: 2304
S = input()
ACGT = ['A', 'C', 'G', 'T']
length_S = len(S)
ans = 0

for i in range(length_S):
	length_substr = 0

	# i + 1文字目から始まる部分文字列の長さを算出
	for j in range(length_S - i):
		if S[i + j] in ACGT:
			length_substr += 1
		else:
			break

	ans = max(ans, length_substr)

print(ans)


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

typedef long long ll;

ll solve(ll a, ll b){
    if (b%a == 0) return 2*b-a;
    return 2*a*floor((double)b/(double)a)+solve(b%a, a);
}

int main(){
    ll n, x;
    scanf("%lld %lld", &n, &x);
    printf("%lld\n", n+solve(x, n-x));
    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Sparsh Sanchorawala
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AKthTerm solver = new AKthTerm();
        solver.solve(1, in, out);
        out.close();
    }

    static class AKthTerm {
        public void solve(int testNumber, InputReader s, PrintWriter w) {
            int[] a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
            w.println(a[s.nextInt() - 1]);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



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

const int INF = 1e8;

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

string D = "DRUL";

const int var = 4;

int trans(char c) {
	switch (c)
	{
	case 'R': return 0;
	case 'D': return 1;
	case 'L': return 2;
	case 'U': return 3;
	default: break;
	}
	exit(EXIT_FAILURE);
}
struct node {
	node *fail;
	vector<node*> next;
	vector<int> ok;
	node() : fail(nullptr), next(var, nullptr) {}
};

node* getnext(node* p, char c) {
	while (p->next[trans(c)] == nullptr) p = p->fail;
	return p->next[trans(c)];
}

class Aho_Corasick {
	vector<int> unite(const vector<int>& a, const vector<int>& b) {
		vector<int> res;
		set_union(a.begin(), a.end(), b.begin(), b.end(), back_inserter(res));
		return res;
	}
	int K;
public:
	node *root;
	Aho_Corasick(const vector<string>& Ts) : K(Ts.size()), root(new node) {
		node *now;
		root->fail = root;
		for (int i = 0; i < K; i++) {
			auto &T = Ts[i];
			now = root;
			for (auto c : T) {
				if (now->next[trans(c)] == nullptr) {
					now->next[trans(c)] = new node;
				}
				now = now->next[trans(c)];
			}
			now->ok.push_back(i);
		}
		queue<node*> q;
		for (int i = 0; i < var; i++) {
			if (root->next[i] == nullptr) {
				root->next[i] = root;
			}
			else {
				root->next[i]->fail = root;
				q.push(root->next[i]);
			}
		}
		while (!q.empty()) {
			now = q.front(); q.pop();
			for (int i = 0; i < var; i++) {
				if (now->next[i] != nullptr) {
					node *nx = now->fail;
					while (nx->next[i] == nullptr) {
						nx = nx->fail;
					}
					now->next[i]->fail = nx->next[i];
					now->next[i]->ok = unite(now->next[i]->ok, nx->next[i]->ok);
					q.push(now->next[i]);
				}
			}
		}
	}
};

using T = tuple<int, int, node*>;

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, m, p;
	while (cin >> n >> m, n | m) {
		vector<string> S(n);
		int sx = 0, sy = 0, gx = 0, gy = 0;
		for (int i = 0; i < n; i++) {
			cin >> S[i];
			for (int j = 0; j < (int)S[i].size(); j++) {
				if (S[i][j] == 'S') {
					sx = i;
					sy = j;
				}
				else if (S[i][j] == 'G') {
					gx = i;
					gy = j;
				}
			}
		}
		cin >> p;
		vector<string> pts(p);
		for (int i = 0; i < p; i++) {
			cin >> pts[i];
		}
		Aho_Corasick aho(pts);
		vector<vector<map<node*, int>>> f(n, vector<map<node*, int>>(m));
		queue<T> q;
		q.push(make_tuple(sx, sy, aho.root));
		f[sx][sy][aho.root] = 0;
		while (!q.empty()) {
			auto p = q.front(); q.pop();
			for (int i = 0; i < 4; i++) {
				int tx = get<0>(p) + dx[i], ty = get<1>(p) + dy[i];
				node *t = getnext(get<2>(p), D[i]);
				if (0 <= tx && tx < n && 0 <= ty && ty < m && S[tx][ty] != '#' && t->ok.empty() && f[tx][ty].count(t) == 0) {
					q.push(make_tuple(tx, ty, t));
					f[tx][ty][t] = f[get<0>(p)][get<1>(p)][get<2>(p)] + 1;
				}
			}
		}
		int res = INF;
		for (auto p : f[gx][gy]) {
			res = min(res, p.second);
		}
		cout << (res != INF ? res : -1) << endl;
	}
	return 0;
}

Measured memory_bytes: 9684
/**
 *      ABC 83 C
 *      author  : kyomukyomupurin
 *      created : 2018-09-16 11:26:46
**/

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

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

    ll X, Y; cin >> X >> Y;
    int count = 0;

    while (X <= Y){
        X *= 2;
        ++count;
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int i;
    int c;
    int ans;
    
    while (scanf("%d", &c)!= EOF){
        ans = c % 39;
        if (ans == 0){
            printf("3C39\n");
        }
        else if (ans < 10){
            printf("3C0%d\n", ans);
        }
        else {
            printf("3C%d\n", ans);
        }
    }
    
    return (0);
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
#define repi(i,x,n) for(int i = x; i < n; i++)
#define rep(i,n) repi(i,0,n)
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
map<string, int> mp;
map<string, vector<string>> G;
map<string, int> used;
int dfs(string s, int &sz)
{
    int res = mp[s];
    sz++;
    for(int u = 0; u < (int)G[s].size(); u++)
    {
        if(used[G[s][u]]) continue;
        used[G[s][u]] = 1;
        res = min(res, dfs(G[s][u], sz));
    }
    return res;
}
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<string> s;
    for(int i = 0; i < n; i++)
    {
        string a; cin >> a;
        s.push_back(a);
        int x; cin >> x;
        mp[a] = x;
    }
    int m; cin >> m;
    for(int i = 0; i < m; i++)
    {
        string s, t; cin >> s >> t;
        G[s].push_back(t);
        G[t].push_back(s);
    }
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        if(used[s[i]]) continue;
        used[s[i]] = 1;
        int sz = 0;
        ans += dfs(s[i], sz) * sz;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 4584
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

typedef long long int  ll;
typedef unsigned long long int ull;


int main()
{
	FAST;
	double arr[1000];

	int n;
	cin >> n;
	double t,a;
	
	cin >> t >> a;
	for(int i=0 ; i<n ; i++)
		cin >> arr[i];

    
    int m = INT_MAX;
	int index = -1;
	for(int i=0 ; i<n ; i++)
	{
	    int d = (t*1000 - arr[i]*6) - a*1000;
	    if(d < 0)   d = -d;
	    if(d < m){
	        m = d;
	        index = i;
	    }
	    
	}
	
    cout << index+1;

    
	return 0;
}


Measured memory_bytes: 256
def check():
    N = int(input())
    X = [list(map(int, input().split())) for _ in range(N)]
    X.sort(key=lambda x:x[1])
    now = 0
    for a,b in X:
        now += a
        if now>b:
            return 'No'
    return 'Yes'
print(check())

Measured memory_bytes: 53728
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1)

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int ans=0;
    if(k<=a){
        ans+=k;
        k-=k;
    }
    else{
        ans+=a;
        k-=a;
    }
    if(k<=b){
        k-=k;
    }
    else{
        k-=b;
    }
    if(k<=c){
        ans+=(k*(-1));
        k-=k;
    }
    else{
        ans+=(c*(-1));
        k-=c;
    }

    cout<<ans<<"\n";
    
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;


int main() {
  int A,B;
  string s;
  cin>>A>>B>>s;
  if(s[A]!='-'){
    cout<<"No\n";
    return 0;
  }
  sort(All(s));
  if(s[0]=='-'&&s[1]>='0'&&s[A+B]<='9'){
    cout<<"Yes\n";
  }else cout<<"No\n";

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const int INF = 1e9 + 6;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()

const int MAX_N = 3 * 1e2 + 1;

int dist[MAX_N][MAX_N];
int gas[MAX_N][MAX_N];

int main() {
    int N, M, L;
    cin >> N >> M >> L;
    rep(i, N)
        rep(j, N)
            dist[i][j] = INF;
    rep(i, N)
        dist[i][i] = 0;
    rep(i, M) {
        int a, b, c; cin >> a >> b >> c; --a, --b;
        if(c <= L) {
            dist[a][b] = dist[b][a] = c;
        }
    }
    //Warshall-Floyd algorithm
    for(int k = 0; k < N; ++k) {
        for(int i = 0; i < N; ++i) {
            for(int j = 0; j < N; ++j) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    rep(i, N)
        rep(j, N)
            gas[i][j] = INF;
    rep(i, N) {
        rep(j, N) {
            if(dist[i][j] <= L)
                gas[i][j] = 1;
        }
    }
    rep(i, N)
        gas[i][i] = 0;
    for(int k = 0; k < N; ++k) {
        for(int i = 0; i < N; ++i) {
            for(int j = 0; j < N; ++j) {
                gas[i][j] = min(gas[i][j], gas[i][k] + gas[k][j]);
            }
        }
    }
    int Q; cin >> Q;
    int s[Q], t[Q];
    rep(i, Q) {
        cin >> s[i] >> t[i]; --s[i], --t[i];
    }
    rep(i, Q) {
        if(gas[s[i]][t[i]] == INF) {
            cout << -1 << endl;
        }else {
            cout << gas[s[i]][t[i]] - 1 << endl;
        }
    }
}


Measured memory_bytes: 1920
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"from fractions import gcd\n"
"n,m=map(int,input().split())\n"
"s=input()\n"
"t=input()\n"
"g=gcd(n,m)\n"
"a=n//g\n"
"b=m//g\n"
"for i in range(g):\n"
"  if s[a*i]!=t[b*i]:\n"
"    print(-1)\n"
"    break\n"
"else:\n"
"  print(n*m//g)\n"
"\"";
  system(s);
  return 0;
}            

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

//g++ -g -o yourexe yourfile.cpp
//./yourexe < yourinput.in > youroutput.out

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 1000000007

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define print(v) for (auto i: v) cout << i << " ";

int main() {
    fast;
    ld n;
    ld p = 3.14159265358979323846;
    cin >> n;
    cout << fixed << setprecision(30) << p*n*2.0 << endl;
}


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

int upper_b(int x){
  int cnt=1;
  while(x){
    x/=2;
    cnt*=2;
  }
  return cnt;
}

int main(){
  int N,a,ans=0;
  cin>>N;
  multiset<int> S;
  for(int i=0;i<N;i++){
    cin>>a;
    S.insert(a);
  }
  auto it=S.end();
  while(!S.empty()){
    it=S.end();
    it--;
    a=upper_b(*it);
    a-=*it;
    S.erase(it);
    
    it=S.find(a);
    if(it!=S.end()){
      S.erase(it);
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 9600
def root(x):
    path_to_root = []
    while P[x] != x:
        path_to_root.append(x)
        x = P[x]
    for node in path_to_root:
        P[node] = x
    return x
def is_same_set(x,y):
    return root(x) == root(y)
def unite(x,y):
    P[root(x)] = root(y)
N,Q = map(int,input().strip().split(" "))
P = [i for i in range(N)]
for i in range(Q):
    com,x,y = map(int,input().strip().split(" "))
    if com == 0:
        unite(x,y)
    else:
        if is_same_set(x,y):
            print(1)
        else:
            print(0)


Measured memory_bytes: 5984
#include <stdio.h>
#include <math.h>
int main() {
    int n, x[100], y[100], i, t;
    double d1=0, d2=0, d3=0, di=0;
    
    scanf("%d", &n);
    for(i=0; i<n; i++) {
        scanf("%d",&x[i]);
    }
    for(i=0; i<n; i++) {
        scanf("%d",&y[i]);
    }
    for(i=0; i<n; i++) {
        t = x[i] - y[i];
        if(t<0)
            t = -t;
        d1 += t;
        d2 += t*t;
        d3 += t*t*t;
        if(di<t)
            di=t;
    }
    
    d2 = pow(d2,1./2);
    d3 = pow(d3,1./3);
    
    printf("%f %f %f %f",d1,d2,d3,di);
    return 0;
}



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

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

    sort(a.begin(), a.end());
    double sum = a[0];
    for (int i = 1; i < n; i++)
    {
        sum += a[i];
        sum /= 2;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
/*  /$$                                     /$$
      | $$                                    | $$
  /$$$$$$$  /$$$$$$   /$$$$$$$  /$$$$$$   /$$$$$$$  /$$$$$$   /$$$$$$
 /$$__  $$ /$$__  $$ /$$_____/ /$$__  $$ /$$__  $$ /$$__  $$ /$$__  $$
| $$  | $$| $$$$$$$$| $$      | $$  \ $$| $$  | $$| $$$$$$$$| $$  \__/
| $$  | $$| $$_____/| $$      | $$  | $$| $$  | $$| $$_____/| $$
|  $$$$$$$|  $$$$$$$|  $$$$$$$|  $$$$$$/|  $$$$$$$|  $$$$$$$| $$
 \_______/ \_______/ \_______/ \______/  \_______/ \_______/|__//$$$$$$ /$$$$$$
                                                               |______/|______/

*/
#include <bits/stdc++.h>
#define fastio        ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ln            cout << endl;
#define vi            vector<int>
#define vll           vector<long long>
#define sortl(vec)    sort(vec.begin(), vec.end());
#define sortr(vec)    sort(vec.rbegin(), vec.rend());
#define forn(i, x, n) for(long long i = x; i < n; i++)
#define revn(i, n, x) for(long long i = n; i >= x; i--)
#define in(vec)       for(auto &it : vec) cin >> it;
#define loop(vec)     for(auto &it : vec)
#define	out(vec)      for(auto &it : vec) cout << it << " "; ln
#define ll            long long
#define mod           1000000007
#define debug(x)      cout << x << endl;
#define pb            emplace_back
#define mp            make_pair
#define um            unordered_map
#define pii           pair<int, int>
#define pll           pair<ll, ll>
#define f             first
#define s             second
#define pi            3.14159265359
#define CLOCK         cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
using namespace std;

ll bS(ll l, ll r, ll x, vll arr) {
	while (l <= r) {
		ll m = l + (r - l) / 2;

		if (arr[m] == x)
			return m;

		if (arr[m] < x)
			l = m + 1;

		else
			r = m - 1;
	}

	return -1;
}

void primeFactors(ll n) {
	while (n % 2 == 0) {
		//cout << 2 << " ";
		n = n / 2;
	}

	for (ll i = 3; i <= sqrt(n); i += 2) {
		while (n % i == 0) {
			//cout << i << " ";
			n = n / i;
		}
	}

	if (n > 2)
		cout << n << " ";
}

ll power(ll x, ll y, ll p) {
	ll res = 1;
	x = x % p;

	while (y > 0) {
		if (y & 1)
			res = (res * x) % p;

		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}

ll modulo(ll a, ll b) {
	ll c = a % b;
	return (c < 0) ? c + b : c;
}

int main() {
// in(vec) works for size-defined type vectors

#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input1.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output1.txt", "w", stdout);
#endif

	fastio
	ll t = 1;
	while (t--) {
		ll n, k;
		cin >> n >> k;
		ll count = 0, count1 = 0;
		forn(i, 1, n + 1) {
			if (i % k == 0) {
				count++;
			}
			if (k % 2 == 0 && i % k == k / 2)
				count1++;
		}
		cout << count1*count1*count1 + count*count*count << endl;
	}
	CLOCK
	return 0;
}



Measured memory_bytes: 3744
import math
N, K = map(int,input().rstrip().split())
A = list(map(int,input().rstrip().split()))
maxX = max(A)
minX = 0
X = (maxX + minX)//2

while X!=minX:
    num = sum([math.ceil(A[i]/X)-1 for i in range(N)])
    if num<=K:
        maxX = X
    else:
        minX = X
    X = (maxX + minX)//2
num = sum([math.ceil(A[i]/maxX)-1 for i in range(N)])
if num<=K:
    print(maxX)
else:
    print(minX)

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

int main()
{
	string a,b;
	cin>>a>>b;
	
	int al=a.length(),bl=b.length();
	if(al>bl){
		cout<<"GREATER"<<endl;
		return 0;
	}else if(al<bl){
		cout<<"LESS"<<endl;
		return 0;
	}else{
		for(int i=0;i<al;i++){
			if(a[i]>b[i]){
				cout<<"GREATER"<<endl;
				return 0;
			}
			if(a[i]<b[i]){
				cout<<"LESS"<<endl;
				return 0;
			}
		}
	}
	cout<<"EQUAL"<<endl;
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n;
    cin >> n;
    int p[10][2];
    double sum=0;
    for(int i = 0; i < n; i++)cin >> p[i][0] >> p[i][1];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            sum += pow(pow(p[i][0]-p[j][0], 2)+pow(p[i][1]-p[j][1], 2), 0.5);
        }
    }
    sum /= (n*(n-1)/2);
    sum *= (n-1);
    cout << setprecision(10) << scientific << sum/2 << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, s, n) for(int i=s; i<(n); ++i)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> mat;

const ll MAX = 400000;
const ll MOD = 998244353;

ll fact[MAX], fact_inv[MAX];

ll pow_mod(ll n, ll r, ll p){
    // n^r mod p   O(logn)
    if (r == 0) return 1;
    if (r % 2 == 0) return pow_mod(n*n%p , r/2, p) % p;
    else return n * pow_mod(n, r-1, p) % p;
}

void factorial(ll n, ll p){
    fact[0] = 1;
    fact[1] = 1;
    FOR(i, 2, n+1) fact[i] = i * fact[i-1] % p;
    fact_inv[n] = pow_mod(fact[n], p-2, p);
    for(int i=n-1; i>=0; --i) fact_inv[i] = fact_inv[i+1] * (i+1) % p;
}

ll comb(ll n, ll r, ll p){
    // nCr mod p
    if (n < 0 || r < 0 || r > n) return 0;
    return (fact[n] * fact_inv[r] % p) * fact_inv[n-r] % p;
}

int main(){
    ll N, A, B, K;
    cin >> N >> A >> B >> K;
    ll ans = 0;

    factorial(N, MOD);
    REP(a, N+1){
        if (K - a*A < 0 || (K - a*A) % B != 0) continue;
        ll b = (K - a*A) / B;
        ans += comb(N, a, MOD) * comb(N, b, MOD) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}


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

#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()

using namespace std;
using namespace __gnu_pbds;

typedef tree< int, null_type, less< int >, rb_tree_tag, tree_order_statistics_node_update> ost;
// name.find_by_order(x) or name.order_of_key(x)
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vii;
typedef vector<vector<int>> vvi;

void yes() {printf("YES\n");}
void no() {printf("NO\n");}

int dx4[] = {-1, 1, 0, 0};
int dy4[] = {0, 0, -1, 1};
int dx8[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1};

const int maxn = 2e5 + 5, maxv = 2e6 + 5;
const int MOD = 1e9 + 7;

int mult(ll a, ll b) {return (a * b) % MOD;}
int pot(int n, int k) {
	int ret = 1, pot = n;
	for(;k > 0;k >>= 1, pot = mult(pot, pot)) 
		ret = mult(ret, (k & 1) ? pot : 1);
	return ret;
}
int divide(int a, int b) {return mult(a, pot(b, MOD - 2));}
int add(int a, int b) {a += b;if(a >= MOD) a -= MOD;return a;}
int sub(int a, int b) {a -= b;if(a < 0) a += MOD;return a;}

vector<int> fact;
void calc_fact(int n) {
	fact = vector<int>(n + 1, 1);
	for(int i = 1;i <= n;i++) fact[i] = mult(fact[i - 1], i);
}
int choose(int n, int k) {return divide(fact[n], mult(fact[n - k], fact[k]));}

bool prime(ll a) {
	if (a == 1) return 0;
	for(ll i = 2;i * i <= a;i++) 
		if (a % i == 0) return 0;
	return 1;
}

ll gcd(ll a, ll b) {return (b == 0 ? a : gcd(b, a % b));}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}

ll phi(ll x) {
	double ret = x;
	for(ll i = 2;i * i <= x;i++) {
		if (x % i) continue;
		ret *= (1.0 - 1.0 / (double)i);
		while (x % i == 0) x /= i;
	}
	if (x > 1) ret *= (1.0 - 1.0 / (double)x );
	return (ll)ret;
}

void solve() {
	int n;
	scanf("%d", &n);
	vi v;
	vvi divs(n + 1, v);
	ll ans = 0;
	for(int i = 1;i < n;i++) {
		for(int j = i;j < n;j += i) ans++;
	}
	printf("%lld\n", ans);
}

int main() {
	int t = 1;
	//scanf("%d", &t);
	while(t--) solve();
	return 0;
}


Measured memory_bytes: 26744
#include <bits/stdc++.h> 
#include <chrono>
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<LL, LL> 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))

LL prime_factor(LL x){
    LL p=x;
    for(LL i=2;i*i<=x;i++){
        if(x%i==0){
            p=i;break;
        }
    }
    return p;
}
LL gcd(LL a,LL b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int counter[(LL)1e6+3];
int main(){
    CLR(counter);
    map<LL,LL>mp;
    FOR(i,1,1e6+1){
        LL p=prime_factor(i);//iを割り切る最小の素数
        if(p==i){//mp[i]:iを割り切る最大の数
            mp[i]=p;
        }else{
            mp[i]=i/p;
        }
    }
    LL N;cin>>N;
    vector<LL>A(N);
    LL maxA=0;
    REP(i,N){
        cin>>A[i];maxA=max(A[i],maxA);
    }
    int g=gcd(A[0],A[1]);
    FOR(i,1,N){
        g=gcd(A[i],g);
    }
    if(g!=1){
        cout<<"not coprime"<<endl;
        return 0;
    }
    REP(i,N){
        LL t=A[i];
        counter[t]+=1;
        if(t>=2&&counter[t]>=2){
            cout<<"setwise coprime"<<endl;return 0;
        }
        while(t!=mp[t]){
            t=mp[t];
            counter[t]++;
            if(t>=2&&counter[t]>=2){
                cout<<"setwise coprime"<<endl;return 0;
            }
        }
    }
    bool resb=true;
    FOR(i,2,maxA+1)if(counter[i]>1){
        resb=false;break;
    }
    if(resb){
        cout<<"pairwise coprime"<<endl;
    }else{
        cout<<"setwise coprime"<<endl;
    }
    return 0;
}
/*
3
1 1 1
*/

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - Attention
            int n = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();

            //リーダーの方向を向く人数を記憶
            //左端からリーダーを1人ずつズラしていく
            var turns = new int[n];

            //東を向いている人はリーダーの方向を向く必要がある
            int east = s.Count(x => x == 'E');
            int west = 0;

            for (int i = 0; i < n; i++)
            {
                if (s[i] == 'E')
                {
                    east--;
                }
               
                //リーダーはどちらを向いていてもよい
                turns[i] = east + west;

                if (s[i] == 'W')
                {
                    west++;
                }
            }

            Console.WriteLine(turns.Min());
        }
    }
}

Measured memory_bytes: 13408
#include <iostream>
// #include <string>
// #include <cstdio>
// #include <functional>
#include <algorithm>
#include <vector>
// #include <stack>
// #include <cmath>
// #include <climits>
// #include <bitset>
// #include <array>
using namespace std;
typedef long long ll;

int V, Mod;
vector<vector<int>> es;
vector<ll> dp0, dp1, y;

void erase(vector<int>& v, int x) { v.erase(remove(v.begin(), v.end(), x), v.end()); }

// par[0]=-1 は常に白とする
// dp0[u]=(uを黒, par[u]を白に塗る場合の数)
ll dfs0(int u, int p)
{
	erase(es[u], p);
	for (int v : es[u]) dp0[u] = dp0[u] * (dfs0(v, u) + 1) % Mod;
	return dp0[u];
}

// dp1[u]=(uを白, par[u]を黒に塗る場合の数)
void dfs1(int u)
{
	int W = es[u].size();
	y[W] = 1;
	// for (int i = 0; i < W; i++) x[i + 1] = x[i] * (dp0[es[u][i]] + 1) % Mod; // 前からの累積積, x[i] = t[0]*...*t[i-1]
	for (int i = W - 1; i >= 0; i--) y[i] = y[i + 1] * (dp0[es[u][i]] + 1) % Mod; // 後ろからの累積積, y[i] = t[i]*...*t[W-1]
	ll x = 1;
	for (int i = 0; i < W; i++)
	{
		dp1[es[u][i]] = (dp1[u] + 1) * x % Mod * y[i + 1] % Mod;
		x = x * (dp0[es[u][i]] + 1) % Mod;
	}
	for (int v : es[u]) dfs1(v);
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> V >> Mod;
	dp0 = vector<ll>(V, 1);
	dp1 = vector<ll>(V);
	// x = vector<ll>(V + 1, 1);
	y = vector<ll>(V + 1, 1);
	for (int i = 0; i < V; i++) es.emplace_back(vector<int>());
	for (int i = 0; i < V - 1; i++)
	{
		int x, y; cin >> x >> y;
		es[x - 1].push_back(y - 1);
		es[y - 1].push_back(x - 1);
	}
	dfs0(0, -1);
	dfs1(0);
	for (int u = 0; u < V; u++) cout << dp0[u] * (dp1[u] + 1) % Mod << endl;
    return 0;
}


Measured memory_bytes: 13424
n = int(input())
a = list(map(int, input().split()))

from collections import Counter
c = Counter(a)

tmp = []
for key in c.keys():
    tmp.append(c[key] * (c[key] - 1) // 2)

tmpsum = sum(tmp)

for k in a:
    print(tmpsum - c[k] * (c[k] - 1) // 2 + (c[k] - 1) * (c[k] - 2) // 2)


Measured memory_bytes: 90316
def resolve():
    N = int(input())
    K = int(input())
    ans = 0
    X = list(map(int,input().split()))
    for i in range(N): 
        if X[i] > K - X[i] :
            ans = ans + K - X[i]
        else:
            ans = ans + X[i]
    print(ans*2)
resolve()

Measured memory_bytes: 3060
// https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_b
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, w, ans = 0, count = 0;
  string s, t;
  int n;
  cin >> n;
  a = n * 100 / 108;
  b = (a + 1) * 1.08;
  if (a * 1.08 == n)
  {
    cout << a << endl;
  }
  else if (b == n)
  {
    cout << a + 1 << endl;
  }
  else
  {
    cout << ":(" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;

int main(){
	int n, K;
	scanf("%d %d", &n, &K);
	std::vector<P> xy(n);
	for(int i=0; i<n; i++) scanf("%ld %ld", &xy[i].first, &xy[i].second);
	std::sort(xy.begin(), xy.end());
	ll x[n], y[n];
	for(int i=0; i<n; i++){
		x[i] = xy[i].first;
		y[i] = xy[i].second;
	}	

	ll ans = 5e18;
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			if(y[j]>y[i]) continue;
			for(int k=0; k<n; k++){
				if(y[k]>y[i] or y[k]<y[j] or x[k]>x[i] or x[k]>x[j]) continue;
				int cnt = 3-(i==j or j==k or k==i) - (i==j and j==k);
				for(int l=0; l<n; l++){
					if(y[l]>y[i] or y[l]<y[j] or x[l]<x[k]) continue;
					cnt += (l!=i and l!=j and l!=k);
					if(cnt>=K){
						ll area = (y[i]-y[j]) * (std::max({x[l],x[i],x[j]})-x[k]);
						if(area>0) ans = std::min(ans, area);
					}
				}
			}
		}
	}
	printf("%ld\n", ans);
	return 0;
}


Measured memory_bytes: 256
N = gets.to_i
plan = []
N.times do
  plan.push gets.chomp.split.map(&:to_i)
end
cur = [0,0,0]
while !plan.empty?
  nextPos = plan.shift
  d = ((nextPos[1]-cur[1])+(nextPos[2]-cur[2])).abs
  if nextPos[0] >= d
    if ((nextPos[0]-cur[0])+d)%2!=0
      print "No\n"
      exit
    end
  else
    print "No\n"
    exit
  end
  cur = nextPos
end
print "Yes\n"

Measured memory_bytes: 9724
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=100005;
int ux[MAXN],uy[MAXN],len;
int rt[MAXN],n,Q;LL m;
int findrt(int x){return rt[x]==x?rt[x]:rt[x]=findrt(rt[x]);}
int main()
{
	n=read();m=read();Q=read();
	for(int i=1;i<=n;i++)rt[i]=i;
	int cnt=n;
	for(int i=1;i<=Q;i++)
	{
		int x=read()+1,y=read()+1,o=read();
		int p=findrt(x),q=findrt(y);
		if(o&&p==q)return puts("No"),0;
		if(!o&&p!=q)rt[p]=q,--cnt;
		if(m==n-1&&o)return puts("No"),0;
		if(o)ux[++len]=x,uy[len]=y;
	}
	if(m==n-1)return puts("Yes"),0;
	for(int i=1;i<=len;i++)if(findrt(ux[i])==findrt(uy[i]))return puts("No"),0;
	LL down=n,up=n+1LL*cnt*(cnt-3)/2;
	if(m>=down&&m<=up)puts("Yes");
	else puts("No");
	return 0;	
}


Measured memory_bytes: 1280
#line 1 "/home/parallels/kyopro/cplib/template.cpp"
#include<bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i = 0;i < n;i++)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()

template<class T> bool chmax(T& a,T b){ if(a < b){ a = b; return true; }else return false; }
template<class T> bool chmin(T& a,T b){ if(a > b){ a = b; return true; }else return false; }

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;
using vpi = vector<Pi>;
using vpl = vector<Pl>;

void lyn(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}

#line 1 "/home/parallels/kyopro/cplib/debug.cpp"
#define debug(arr) cout << #arr << " = " << arr << '\n'
#define debug2(a,b) cout << "[" << #a << "," << #b << "] = " << "[" << a << "," << b << "]" << '\n'
template<class T> ostream &operator << (ostream& out, const vector<T>& arr) {
	cout << "{"; for (int i = 0; i < arr.size(); i++)cout << (!i ? "" : ", ") << arr[i]; cout << "}";
	return out;
}
template<class T> ostream &operator << (ostream& out, const vector<vector<T> >& arr) {
	cout << "{\n"; for (auto& vec : arr)cout << "  " << vec << ",\n"; cout << "}";
	return out;
}
template<class S,class T> ostream &operator << (ostream& out, const pair<S,T>& p){
  cout << "{" << p.first << "," << p.second << "}" << '\n';
  return out;
}
template<class T> istream &operator >> (istream& in, vector<T>& arr) {
	for (auto& i : arr)cin >> i; return in;
}
#line 2 "main.cpp"
#define MAX_N 2000000
class UnionFind {
public:
	//UnionFind
	int par[MAX_N];
	int ufrank[MAX_N];
	int ufsize[MAX_N];
	UnionFind(int ufsize_of_tree) {
		for (int i = 0; i < ufsize_of_tree; i++)
		{
			par[i] = i;
			ufrank[i] = 0;
			ufsize[i] = 1;
		}
	}
	int find(int x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (ufrank[x] < ufrank[y]) {
			par[ x] = y;
			int sx = ufsize[x], sy = ufsize[y];
			ufsize[x] = ufsize[y] = sx + sy;
		}
		else {
			par[y] = x;
			if (ufrank[x] == ufrank[y]) ufrank[x]++;
			int sx = ufsize[x], sy = ufsize[y];
			ufsize[x] = ufsize[y] = sx + sy;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};
#define maxn 200020

vector<int> g[maxn];

int n,m;
int cnt[maxn];
int used[maxn];
int ans = 1;
void dfs(int s,int x){
  used[x]++;
  cnt[s]++;
  for(int i : g[x]){
    if(!used[i]){
      dfs(s,i);
    }
  }
}
int main(int argc, char const* argv[])
{
  lyn();
  cin >> n >> m;
  REP(i,m){
    int a,b;cin >> a >> b;
    a--,b--;
    g[a].pb(b);
    g[b].pb(a);
  }
  REP(i,n){
    if(!used[i]){
      dfs(i,i);
    }
  }
  REP(i,n)chmax(ans,cnt[i]);
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 24636
# https://atcoder.jp/contests/abc144/tasks/abc144_d

from math import pi, tan

a, b, x = map(int, input().split())
eps = 10e-8

def f(a, b, theta):
    if theta > pi / 2.0 - eps:
        return 0.0
    ret = 0.0
    if a * tan(theta) <= b:
        ret = a * a * b - a * a * a * tan(theta) / 2.0
    else:
        ret = b * b / tan(theta) * a / 2.0
    return ret

ng = 0.0
ok = pi / 2.0
for _ in range(100000):
    mid = (ok + ng) / 2.0
    if f(a, b, mid) < x:
        ok = mid
    else:
        ng = mid
print("{:.10f}".format(ok / pi * 180))

Measured memory_bytes: 66640
# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])
    s = args[1]
    ret = 0

    index = [[] for _ in range(10)]
    for i in range(n):
        index[int(s[i])].append(i)

    for i in range(1000):
        iii = '{:03d}'.format(i)
        cur = -1
        found = False

        for e, j in enumerate(iii):
            found = False

            for k in index[int(j)]:
                if cur < k:
                    found = True
                    cur = k
                    break

            if not found:
                break

        if found:
            ret += 1

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 4328
import java.util.*;

public class Main{

	static void print(int n, int[] a){
		
		System.out.print(a[0]);
		for(int i = 1; i < n; i++) System.out.print(" "+a[i]);
		System.out.println();
	}

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
		
        int N = sc.nextInt();
		int[] A = new int[N];
		
		for(int i = 0; i < N; i++) A[i] = sc.nextInt();
		
		int v, j;
		
		print(N, A);
		
		for(int i = 1; i < N; i++){
			v = A[i];
			j = i - 1;
			while(j >= 0 && A[j] > v){
				A[j+1] = A[j];
				j--;
			}
			A[j+1] = v;
			print(N, A);
		}
	}
}


Measured memory_bytes: 31024
while True:
    n,p = map(int,input().split())
    if n==p==0: break
    l = [0]*n
    i,k = 0,p
    while True:
        i %= n
        if k==0: k,l[i] = l[i],0
        else:
            k-=1
            l[i]+=1
            if l[i]==p: break
        i+=1
    print(i)

Measured memory_bytes: 7552
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
using namespace std;
using ll = long long;
using graph = std::vector<std::vector<long long>>;
int main(){
    ll H,W,N;
    cin >> H >> W >> N;
    queue<ll> c;
    for(int i =0 ; i< N; i++){
        ll tmp;
        cin >> tmp;
        for(int j =0; j < tmp; j++){
            c.push(i+1);
        }
    }
    ll m[H][W];
    for(int yi = 0; yi < H; yi++){
        for(int xi = 0; xi < W; xi++){
            if(yi % 2 == 0){
                m[yi][xi] = c.front();c.pop();
            }else{
                m[yi][W - 1 - xi] = c.front();c.pop();
            }
        }
    }

    for(int yi = 0; yi < H; yi++){
        for(int xi = 0; xi < W; xi++){
            cout << m[yi][xi] << " ";
        }
        cout << endl;
    }

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    int A[N];
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    int mx1 = 0;
    int mx2 = 0;

    for(int i=0; i<N; i++){
        if(mx1 < A[i]){
            mx2 = mx1;
            mx1 = A[i];
        }else{
            if(mx2 < A[i]){
                mx2 = A[i];
            }
        }
    }
    for(int i=0;i<N;i++){
        if(A[i] != mx1){
            cout << mx1 << endl;
        }else{
            cout << mx2 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 2432
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let n : u64 = read();
    let an = read_vec::<i64>();
    let ans = std::cmp::min(solve(true, &an),solve(false, &an));
    println!("{}",ans );
    
}
fn solve(mut symbol: bool, v:&Vec<i64>) -> i64{
    let mut sum = 0;
    let mut ans = 0;
    for &a in v{
        sum += a;
        if !symbol && sum >= 0 {
            let next = sum - -1;
            ans += next;
            sum -= next;
        } else if symbol && sum <= 0{
            let next = 1 -sum;
            sum += next;
            ans += next;
        }
        symbol = !symbol;
    }
    ans
}

Measured memory_bytes: 8444