akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#include <limits>
#include <iomanip>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
    string S;
    cin >> S;
    int num = S.size();
    bool frg = false;
    int max_num;
    for(int i=1;i<=num/2;i++){
        vector<char> s0((num/2)-i);
        vector<char> s1((num/2)-i);
        for(int j=0;j<(num/2)-i;j++){
            s0[j]=S[j];
            s1[j]=S[(num/2)-i+j];
        }
        if(s0==s1){
            frg = true;
            max_num = s1.size()+s0.size();
            break;
        }
    }
    cout << max_num << endl;
}

Measured memory_bytes: 3624
#include<stdio.h>
int main() 
{
    long long int n, i, a[500000]={}, x;
    scanf("%lli", &n) ;
    
    	while(scanf("%lli",&x)!=EOF) 
    	a[x]+=1;
    
   for(i=1;i<=n;i++) 
   printf("%lli\n", a[i]) ;
   
   return 0;
} 

Measured memory_bytes: 5636
#include <bits/stdc++.h>
using namespace std;
#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, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    vll a(3);
    REP(i, 3) cin >> a[i];
    VSORT(a);
    ll res = a[0] + a[1];
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF INT_MAX

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

// ????????¨???????????????????¨???????????§???????
struct Edge {
    int from, to, cost;
    Edge(int s, int d) : to(s), cost(d) {}
    Edge(int f, int s, int d) : from(f), to(s), cost(d) {}

    bool operator<(const Edge &e) const {
        return cost < e.cost;
    }
    bool operator>(const Edge &e) const {
        return cost > e.cost;
    }
};

// 1??????????????????????????????????????±????????????????????????????????? vector
// Edges????????????????????????????????????????????°??????????????????
typedef vector<Edge> Edges;

// ???????????±??????????????? vector
// Graph??????????????????????????°?????????????????§??? V ??§?????????
typedef vector<Edges> Graph;

/*int prim(Graph &G) {
    int V = G.size();
    int mincost[V];
    bool used[V];
    for(int i=0; i<V; i++) {
        mincost[i] = INF;
        used[i] = false;
    }
    mincost[0] = 0;
    int res = 0;

    priority_queue< pii, vector<pii>, greater<pii> > que;
    que.push(pii(0,0));
    while(!que.empty()) {
        int v = -1;

        // X????±?????????????????????????X???????????????????????????????°?????????????????????¢???
        for(int i=0; i<V; i++) {
            for(int j=0; j<G[i].size(); j++) {
                mincost[]
            }
        }
    }
}*/

int prim(Graph &G) {
    int V = G.size(), ans = 0;
    vector<bool> used(V, false);
    priority_queue< Edge, vector<Edge>, greater<Edge> > q;
    q.push(Edge(0, 0, 0));
    while(!q.empty()) {
        Edge temp = q.top(); q.pop();
        if(used[temp.to]) continue;
        used[temp.to] = true;
        ans += temp.cost;

        rep(i,0,G[temp.to].size()) q.push(G[temp.to][i]);
    }
    return ans;
}

namespace std {
    bool operator<(const P a, const P b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int main() {
    int V, E;
    cin >> V >> E;
    Graph G(V);
    int s, t, d;
    rep(i,0,E) {
        cin >> s >> t >> d;
        G[s].push_back(Edge(t,d));
        G[t].push_back(Edge(s,d)); // ????????°??????????????§
    }

    int ans = prim(G);
    cout << ans << endl;
    return 0;
}

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

#define int long long
#define ll long long
#define f1(i,a,b) for(i=a;i<b;i++)
#define f2(i,a,b) for(i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;
int i,j;
ll temp;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    //     freopen("/home/akmittal/Desktop/Competitive Programming/in.txt","r",stdin);
    //     freopen("/home/akmittal/Desktop/Competitive Programming/out.txt","w",stdout);
    // #endif
    int n;
    cin>>n;
    int a[n];
    f1(i,0,n)
    cin>>a[i];

    multiset<int, greater<int>> ans;
    f1(i,0,n)
    {
        auto it=ans.upper_bound(a[i]);
        if(it==ans.end())
        {
            ans.insert(a[i]);
        }
        else
        {
            ans.erase(it);
            ans.insert(a[i]);
        }
        // for(auto j=ans.begin();j!=ans.end();j++)
        //     cout<<*j<<gp;
        // cout<<endl;
    }
    cout<<ans.size();
    return 0;
}

Measured memory_bytes: 5760
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');
		int n = int.Parse(input[0]);
		int q = int.Parse(input[1]);
		string s = Console.ReadLine();
		int[] sums = new int[n+1];//i文字目まで見た

    for(int i = 2; i <= n; i++)
    {
      sums[i] = sums[i-1];
      if(s[i-2] == 'A' && s[i-1] == 'C') sums[i]++;
      //Console.WriteLine(sums[i]);
    }

    for(int i = 0; i < q; i++)
    {
      string[] inputa = Console.ReadLine().Split(' ');
      int l = int.Parse(inputa[0]);
      int r = int.Parse(inputa[1]);

      Console.WriteLine(sums[r]-sums[l]);
    }
	}
}

Measured memory_bytes: 17816
// C - Walk on Multiplication Table
#include <stdio.h>
#include <math.h>
typedef long long ll;

int main(void){
    ll i=1, n, ans=0;
    scanf("%lld", &n);
    ans = n-1;
    for(i=1; i<=sqrt(n); i++){
        if(n%i==0){ans=i;}
    }
    printf("%lld\n", ans+n/ans-2);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = s; i < e; ++i)
#define sort_(a) stable_sort(a.begin(), a.end())
#define rsort(a) stable_sort(a.rbegin(), a.rend())
#define sum(a) accumulate(a.begin(), a.end(), 0LL)
#define join(a, d) accumulate(a.begin() + 1, a.end(), a[0], [](string s, string t) {return s + d + t;})
#define all(a) a.begin(), a.end()
#define __lcm(a, b) std::__detail::__lcm(a, b)
typedef long long ll;
const long mod = 1e9 + 7;

int main(void) {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  string S, T;
  cin >> S;
  cin >> T;
  rep(i, 0, int(S.size())) {
    rotate(S.rbegin(), S.rbegin() + 1, S.rend());
    if (S == T) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>

using namespace std;

const int Inf = 10000 * 100000 + 100;

int main(){
  int V,E,R;
  cin >> V >> E >> R;
  vector<int> s(E),t(E),d(E);
  vector<vector<int> > edge(V);
  for(int i = 0; i < E; i++){
    cin >> s[i] >> t[i] >> d[i];
    edge[s[i]].push_back(i);
  }
  vector<int> cost(V, Inf);
  cost[R] = 0;

  // < ?§??????????????????¢, ?????????id >
  priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > q;
  q.push({0, R});

  // ????????????????????????
  vector<bool> fin(V, false);

  // vector<vector<int> > edge(V);
  // for(int i = 0; i < V; i++){
  //   edge[i] = {};
  //   // ?????? i ?????????????????????????????????
  //   for(int j = 0; j < E; j++){
  //     if(s[j] == i) edge[i].push_back(j);
  //   }
  // }


  while(!q.empty()){
    // ?¢?????????????????????? u ??¨??????
    auto npair = q.top();
    int nd = npair.first, nu = npair.second;
    // cout << nd << " : " << nu << endl;

    q.pop();
    if(fin[nu]) continue; // ?¢??????????????????????
    fin[nu] = true;
    cost[nu] = nd;
    for(auto i : edge[nu]){
      // u ????§??????§?¢????????????§???????????????????????????????????????
      if(!fin[t[i]]){
        // ????????? v ??¨??????.
        int nv = t[i];
        // ????????§?????????????????????
        if(cost[nu] + d[i] < cost[nv]){
          cost[nv] = cost[nu] + d[i];
          q.push({cost[nv], nv});
        }
      }
    }
  }

  for(int i = 0; i < V; i++){
    if(cost[i] == Inf)
      cout << "INF";
    else
      cout << cost[i];

    cout << endl;
  }
}

Measured memory_bytes: 16416
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	if((n <= 0 && m>=0)||(n >= 0 && m <= 0)){
		cout<<"Zero"<<'\n';
		return 0;
	}
	if(n>=0&&m>=0){
		cout<<"Positive"<<'\n';
		return 0;
	}
	if(abs(abs(n)-abs(m))%2==0){
		cout<<"Negative"<<'\n';
		return 0;
	}
	cout<<"Positive"<<'\n';
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
    #include <string>
    #include <set>  
    #include <stack>
    #include <algorithm>
    #include <vector>
    #include <cmath>
    #include <queue>
    #include <deque>
    #include <cstring>
    #include <cstdio>
    #include <map>
    #include <numeric>
    #include <cassert>
    #include <iomanip>
    #include <sstream>
    #include <ctime>
    using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const db PI = acos(-1);
const db ERR = 1e-12;

const int MX = 500005;

char buf[MX];
int D[MX];

int main()
{
	int N;
	scanf("%d%s", &N, buf+1);
	int ans = 0, cur = 0;
	vector<int> L;
	for(int i = 1; i <= N; i++){
		if( buf[i] == '1' ) cur++;
		else cur = 0;
		D[i] = max(D[i], D[i-1]);
		if( cur && buf[i+1] == '0' && buf[i+2] == '1' )
{ D[i+2] = max(D[i+2], D[i-cur] + cur);D[i+2] = max(D[i+2], D[i-cur+1] + cur-1);}
		if( cur && i >= cur+2 && buf[i-cur] == '0' && buf[i-cur-1] == '1' ) D[i] = max(D[i-cur-2] + cur, D[i]);
	}
	printf("%d\n", D[N]);
	return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
int N;
int a[6] = {0, 9, 9, 909, 909, 90909};
int b[6] = {1, 0, 100, 0, 10000, 0};

int countDigits(int x) {
    int cnt = 0;
    while(x > 0) {
        cnt ++;
        x = x / 10;
    }
    return cnt;
}

int main() {
    cin>>N;
    int cnt = countDigits(N);
    int cnt_b = 0;
    
    if(cnt % 2 == 1) {
        cnt_b = (N - b[cnt - 1] + 1);
    }
    int ret = a[cnt - 1] + cnt_b;
    cout<<ret<<endl;
	return 0;
}

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

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n; cin >> n;
  string s, t; cin >> s >> t;
  for (int i = 0; i < n; i++) {
    bool f = true;
    for (int j = 0; j < n - i; j++) if (s[i + j] != t[j]) f = false;
    if (f) {
      cout << i + n << "\n";
      return 0;
    }
  }
  cout << 2 * n << "\n";
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    int i=0,L,f=0,d=0;
    char A[10000];
    scanf("%s",A);
    L=strlen(A);
    for(i=2;i<L-1;i++)
    {
       if(A[i]=='C')
       {
           f++;
           A[i]='c';
       }
    }
    for(i=1;i<L;i++)
    {
       if(A[i]>=97)
       {
           d++;
       }
    }
    if(A[0]=='A' && f==1 && d==L-1)
    {
        printf("AC\n");
        return 0;
    }
    else
    {
        printf("WA\n");
        return 0;
    }


}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

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

		boolean nine = true;
		int sum = 0;
		for (int i = 1; i < n.length(); i++) {
			if (Character.getNumericValue(n.charAt(i)) != 9) nine = false;
			sum += 9;
		}

		if (nine) {
			sum += Character.getNumericValue(n.charAt(0));
		} else {
			sum += Character.getNumericValue(n.charAt(0)) - 1;
		}

		System.out.println(sum);

		sc.close();
	}

}


Measured memory_bytes: 35616
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,c;
	cin>>n>>m>>c;
	vector<int>B(m);
	for(int i=0;i<m;i++)
		cin>>B[i];
	int count=0;
	while(n--){
		int sum=0;
		for(int i=0;i<m;i++){
			int temp;
			cin>>temp;
			sum+=B[i]*temp;
		}
		sum+=c;
		if(sum>0)
			count++;
	}
	cout<<count<<endl;
	return 0;
}

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

C=A+B
d=N//C
N -= C*d

b=0
r=0
while N>0:
    N-=A
    b+=A
    if N<=0:
        b+=N
        break

    N-=B
    r+=B
    if N<=0:
        break

print(b+d*A)

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

int main()
{
	int a,b,c,d,e;
	int x,y,w,h,r;

	cin >> c >> d >> a >> b >> e;

	if(-100 <= a && a <= 100){
		x = a;
	}

	if(-100 <= b && b <= 100){
		y = b;
	}

	if(0 <= c && c <= 100){
		w = c;
	}

	if(0 <= d && d <= 100){
		h = d;
	}

	if(0 <= e && e <= 100){
		r = e;
	}

	if(r <= x && x <= w-r && r <= y && y <= h-r){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 1156
function main(arg) {
	arg = arg.split("\n")[0].split(" ")
	var N = Number(arg[0])
	var K = Number(arg[1])
	var count = 0
	for (var i = 1; i <= N; i+=2 ) {
		count++
	}
	if (K > count) {
		console.log("NO")
	} else {
		console.log("YES")
	}
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21956
from functools import reduce
from operator import mul
N = int(input())
S = input()
appearances = {"R": 0, "G": 0, "B": 0}
for c in S:
    appearances[c] += 1
print(reduce(mul, list(appearances.values())) - sum(sum(len(set(S[start] + S[start + step] + S[start + step * 2])) == 3 for start in range(N - step * 2)) for step in range(1, N // 2 + 1)))


Measured memory_bytes: 76036
#include <stdio.h>

int main(void){

	int x,y;

	while(1){
		scanf("%d %d",&x,&y);
		if(x==0&&y==0)break;
		if(x>y)printf("%d %d\n",y,x);
		else if(x<=y)printf("%d %d\n",x,y);
	}

	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rel register ll
#define rec register char
#define gc getchar
//#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<23,stdin),p1==p2)?-1:*p1++)
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
char buf[1<<23],*p1=buf,*p2=buf;
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) pc('-'),x=-x;
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
const int yuzu=1e5;
char c[yuzu|10];
int main() {
  scanf("%s",c+1);
  int i,n=strlen(c+1);
  if (c[1]^'1'||c[n]^'0') return puts("-1")&0;
  for (i=1;i<=n/2;++i) if (c[i]^c[n-i]) return puts("-1")&0;
  int last=n;
  for (i=n-1;i;--i) {
    printf("%d %d\n",last,i);
    if (c[i]=='1') last=i;
  }
}

Measured memory_bytes: 3884
#include<bits/stdc++.h>
#include<random>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

ll N = 100010;
ll bit[100010];
void add(ll a, ll w) {
	a++;
	for (ll x = a; x <= N; x += x & -x) bit[x] += w;
}
ll sum(ll a) {
	a++;
	ll ret = 0;
	for (ll x = a; x > 0; x -= x & -x) ret += bit[x];
	return ret;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,a,b;
	cin>>n>>a>>b;
	if(a>b) swap(a,b);
	vector<ll> s(n);
	REP(i,n) cin>>s[i];
	REP(i,n-2) {
		if(s[i+2]-s[i]<a) {
			cout<<0<<endl;
			return 0;
		}
	}
	REP(i,n-1) if(s[i+1]-s[i]<a) add(i,1);
	vector<vector<ll>> dp(n,vector<ll>(2,0));
	dp[0][0]=dp[0][1]=1;
	FOR(i,1,n) REP(j,2) {
		if(j==0) { // X
			dp[i][j]+=dp[i-1][1];
			if(s[i]-s[i-1]>=a) dp[i][j]+=dp[i-1][0];
		} else { // Y
			if(s[i]-s[i-1]>=b) {
				dp[i][j]+=dp[i-1][1];
				dp[i][j]+=dp[i-1][0];
			} else {
				ll idx=upper_bound(ALL(s),s[i]-b)-s.begin();
				ll tmp=0;
				if(i>1) tmp+=sum(i-2);
				if(idx>0) tmp-=sum(idx-1);
				if(tmp==0) dp[i][j]+=dp[idx][0];
			}
		}
		dp[i][j]%=MOD;
	}
	cout<<(dp[n-1][0]+dp[n-1][1])%MOD<<endl;
	return 0;
}


Measured memory_bytes: 7296
while True:
  n = int(raw_input())
  if n == 0:
    break

  data = []

  for i in range(n):
    elements = list(map(int, raw_input().split(' ')))
    uid = elements[0]
    uid = i+1
    ps = elements[1:]
    ps = list(set(ps))
    ps = sorted(ps)

    data.append((uid, ps))

  elements = list(map(int, raw_input().split(' ')))
  query = elements[1:]
  query = list(set(query))
  query = sorted(query)

  ans = []

  for uid, ps in data:
    plausible = True

    for q in query:
      if q not in ps:
        plausible = False

    if plausible:
      ans.append(uid)

  if len(ans) == 1:
    print(ans[0])

  else:
    print(-1)

Measured memory_bytes: 6564
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

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

using namespace std;

long long Lcm(int a, int b){
    return (long long)a / __gcd(a, b) * b;
}

int main(){
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;
    int a = n / __gcd(n, m), b = m / __gcd(n, m), c = __gcd(n, m);
    bool is_good = true;
    for (int i = 0; i < c; i++)
        if (s[a * i] != t[b * i])
            is_good = false;
    if (is_good)
        cout << Lcm(n, m) << endl;
    else
        cout << -1 << endl;
}


Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<fstream>
#include<stdlib.h>
#include<set>
#include<climits>
#include<cmath>  
#include<memory.h> 
#include<sstream>
#include<time.h>
#include<iomanip>
using namespace std;
const unsigned long long BIGEST=1000000000000000000+1000000000000000000;
const long long BIGER=1000000000000000000;
const int BIG=1000000000;
const int MOD=1000000007;
const long long LMOD=998244353;
//const long long LMOD=1000000007;
#define Fi first
#define Se second
#define P2 pair
#define Pii pair<int,int>
#define Cb make_pair
#define Ll long long
#define Ull unsigned long long
#define Snf scanf
#define Prf printf
#define Pb push_back
#define Stc stack
#define Vct vector
#define Ret return
#define Sz size
#define Ins insert
int n;
Pii a[55];
Vct<Pii>v;
set<Pii>S;
int main()
{
	int a,b;
	cin>>a>>b;
	if(b==1)cout<<0;
	else cout<<a-b;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <string>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
using namespace std;

map<long long, long long> pf(long long n){
  map<long long, long long> ret;
  for(long long i=2; i*i<=n; i++) {
    while(n%i==0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long n, now=1;
  long long count=0;
  vector<long long> al(1);
  cin >> n;
  
  if(n<=1){
    cout << 0 << endl;
    return 0;
  }
  
  for(auto p : pf(n)) {
    while(p.second--){
      bool ok=1, r=1;
      now *= p.first;
      for(int i=0; i<al.size(); i++){
        if(p.first==al[i]) r=0;
        if(now==al[i]) ok=0;
      }
      if(r){
        ok = 1;
        now = p.first;
      }
      if(ok){
        n /= now;
        al.push_back(now);
        now = 1;
        count++;
        if(n==1){
          cout << count << endl;
  		  return 0;
        }
      }
    }
  }
  
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3676
n,m = gets.split.map &:to_i
s = gets.chomp
t = gets.chomp

gcd,lcm = n.gcdlcm(m)

ans = true
gcd.times do |i|
  if s[i*lcm/m] != t[i*lcm/n]
    ans = false
    break
  end
end

puts ans ? lcm : -1


Measured memory_bytes: 2044
# A - Round One
A = int(input())
B = int(input())

if A == 2 and B == 1:
    print(3)
elif B == 2 and A == 1:
    print(3)
elif A == 3 and B == 1:
    print(2)
elif B == 3 and A == 1:
    print(2)
elif A == 2 and B == 3:
    print(1)
else:
    print(1)

Measured memory_bytes: 38720
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#include<functional>
#include<list>
#include<map>
#include<unordered_map>
#define P pair<int,int>
using namespace std;

int main() {
	int a, b; cin >> a >> b;
	int ruisekiwa[108]{};
	vector<P>k;
	int sum = 0;
	for (int c = 0; c < b; c++) {
		int d, e; cin >> d >> e;
		d--;
		ruisekiwa[d]++; ruisekiwa[e]--;
		e--;
		bool f = true;
		auto u = k.begin();
		for (int g = 0; g < sum; g++,u++) {
			if (k[g].first <= d&&k[g].second >= e)f = false;
			else if (k[g].first >= d&&k[g].second <= e) {
				k.erase(u); u--; g--; sum--;
			}
		}
		if (f) {  k.push_back(P(d, e)); sum++; }
	}
	bool o = true;
	int q = 0;
	for (int n = 0; n < a; n++) {
		q += ruisekiwa[n];
		if (q == 0)o = false;
	}
	if (!o) { puts("Impossible"); return 0; }
	if (a == 1) { puts("1");return 0; }
	sort(k.begin(),k.end());
	int now = 0, ans = 0;
	while(now!=a){
		auto t = upper_bound(k.begin(), k.end(), P(now, 1<<29));
		t--;
		now = (*t).second+1;
		ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3052
#include<stdio.h>
char str[1000][33];
int main() {
  int i, j, n, s, N, maximum, max_index, Max_index;
  maximum = 0;
  for (N = 0; scanf("%s", str[N]) != EOF; N ++);
  for (i = 0; i < N; i ++) {
    for (j = 0; str[i][j] != 0; j ++) {
      if ('A' <= str[i][j] && str[i][j] <= 'Z') str[i][j] += 'a' - 'A';
    }
    if (j - 1 > maximum) {
      max_index = i; maximum = j - 1;
    }
  }
  maximum = 0;
  for (i = 0; i < N; i ++) {
    n = 0;
    for (j = 0; j < N; j ++) {
      for (s = 0;; s ++) {
	if (str[i][s] != str[j][s]) break;
	else if (str[i][s] == 0) {
	  n ++; break;
	}
      }
    }
    if (n > maximum) {
      Max_index = i; maximum = n;
    }
  }
  printf("%s %s\n", str[Max_index], str[max_index]);
  return 0;
}

Measured memory_bytes: 544
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>

#define DIV 1000000007
using namespace std;

int log_six(int x) {
    int ans = -1;
    while(x>0){
        ans++;
        x /= 6;
    }

    return ans;
}

int log_nine(int x) {
    int ans = -1;
    while (x > 0) {
        ans++;
        x /= 9;
    }

    return ans;
}
int main() {
    int N;
    cin >> N;

    vector<long long> cost(N + 1, LLONG_MAX);
    cost[0] = 0;
    int temp = 1;
    while(temp<= N) {
        cost[temp] = 1;
        temp *=6 ;       
    }
    temp = 1;
    while (temp <= N) {
        cost[temp] = 1;
        temp *= 9;
    }

    for (int i = 1; i <= N; i++) {
        int m_six = log_six(i);
        int m_nine = log_nine(i);
        //cout << "i=" << i << "  ";
        //cout << "m_six=" << m_six << "  m_nine=" << m_nine << "  ";
        cost[i] = min(cost[i],cost[i-pow(6,m_six)] +cost[pow(6,m_six)]);
        cost[i] = min(cost[i], cost[i - pow(9, m_nine)] + cost[pow(9, m_nine)]);
       // cout << cost[i] << endl;
    }
    cout << cost[N] << endl;
}

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

#define pb push_back
#define ll long long int
#define mpi map<int, int>
#define vi vector<int>
#define qi queue<int>
#define si set<int>
#define pii pair<int, int>
#define vpi vector<pii>
#define vs vector<string>
#define pri priority_queue<int>
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define For(i, n) for (int i = 0; i < n; i++)
#define Ford(i, a, b) for (int i = a; i >= b; i--)
#define Rep(i, x, y) for (int i = x; i <= y; i++)
#define mem(a, b) memset(a, b, sizeof(a))
#define fastio                    \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)

double tick()
{
    static clock_t oldt, newt = clock();
    double diff = 1.0 * (newt - oldt) / CLOCKS_PER_SEC;
    oldt = newt;
    return diff;
}

ll fastExpo(ll a, ll n)
{
    ll res = 1;
    while (n)
    {
        if (n % 2)
            res = res * a;
        n /= 2;
        a = a * a;
    }
    return res;
}

int main()
{
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;
    cerr << "execution time is: " << tick() << "\n";
}


Measured memory_bytes: 3788
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
struct edge{
    int to,cost;
};
V<edge>graph[20];
int main(){
  int n;
  cin>>n;
  n--;
  for(int i=0;i<19;i++){
      graph[i].emplace_back(edge{i+1,0});
  }
  int ind=-1;
  if(~n&(1<<20)){
  for(int i=19;i>=0;i--){
      if(n&(1<<i)){
          ind=i;
          break;
      }
  }
  if(ind==-1){
      int sum=0;
  for(int i=0;i<20;i++)sum+=(int)graph[i].size();
  cout<<20<<" "<<sum<<"\n";
  for(int i=0;i<20;i++){
      for(int j=0;j<graph[i].size();j++){
          cout<<i+1<<" "<<graph[i][j].to+1<<" "<<graph[i][j].cost<<"\n";
      }
  }
  return 0;
  }
  for(int i=18;i>=0;i--){
      if(18-i!=ind)graph[i].emplace_back(edge{i+1,(1<<(18-i))});
      else break;
  }
  graph[0].emplace_back(edge{19,(1<<ind)});
  int x=(1<<ind);
  for(int i=ind-1;i>=0;i--){
      if(n&(1<<i)){
          graph[0].emplace_back(edge{19-i,x+1});
          x+=(1<<i);
      }
  }
  }else{
      graph[0].emplace_back(edge{19,(1<<20)});
      graph[0].emplace_back(edge{19,(1<<19)});
  int x=(1<<20);
  for(int i=18;i>=0;i--){
      if(n&(1<<i)){
          graph[0].emplace_back(edge{19-i,x+1});
          x+=(1<<i);
      }
  }
  x=(1<<19);
  for(int i=18;i>=0;i--){
      if(n&(1<<i)){
          graph[0].emplace_back(edge{19-i,x+1});
          x+=(1<<i);
      }
  }
  if(n&(1<<19)){
      x=(1<<20)+(1<<19);
      for(int i=18;i>=0;i--){
      if(n&(1<<i)){
          graph[0].emplace_back(edge{19-i,x+1});
          x+=(1<<i);
      }
  }
  }
  }
  int sum=0;
  for(int i=0;i<20;i++)sum+=(int)graph[i].size();
  cout<<20<<" "<<sum<<"\n";
  for(int i=0;i<20;i++){
      for(int j=0;j<graph[i].size();j++){
          cout<<i+1<<" "<<graph[i][j].to+1<<" "<<graph[i][j].cost<<"\n";
      }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  int N;
  cin>>N;
  vector<string> S(N);
  rep(i,N) cin>>S[i];

  vector<int> ans(4,0);
  rep(i,N){
    if(S[i]=="AC") ans[0]++;
    else if(S[i]=="WA") ans[1]++;
    else if(S[i]=="TLE") ans[2]++;
    else ans[3]++;
  }

  cout<<"AC"<<" x "<<ans[0]<<endl;
  cout<<"WA"<<" x "<<ans[1]<<endl;
  cout<<"TLE"<<" x "<<ans[2]<<endl;
  cout<<"RE"<<" x "<<ans[3]<<endl;

  return 0;
}


Measured memory_bytes: 6368
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
const int maxn=2000000+10;
const int maxv=10000+10;
int n;
int C[maxv];
int *A=NULL, *B=NULL;
void count_sort(int A[],int B[],int n)
{

    for(int i=0;i<maxv;i++) C[i]=0;
    for(int i=0;i<n;i++) C[A[i]]++;
    for(int i=1;i<maxv;i++)
    {
        C[i]=C[i]+C[i-1];
    }

    for(int i=0;i<n;i++)
    {
        B[C[A[i]]]=A[i];
        C[A[i]]--;
    }

}
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&n);
    A=(int *)malloc(sizeof(int)*n+1);
    B=(int *)malloc(sizeof(int)*n+1);
    for(int i=0;i<n;i++) scanf("%d",&A[i]);
    count_sort(A,B,n);

    for(int i=1;i<=n;i++)
    {
        if(i>1) printf(" ");
        printf("%d",B[i]);
    }
    printf("\n");
    free(A);
    free(B);

    return 0;
}

Measured memory_bytes: 18348
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	int n,ans=0,maxans=0,inf=1000000007;
	cin>>n;
	vector <int> h(n+1);
	rep(i,n)cin>>h[i];
	h[n]=inf;
    rep(i,n){
        if(h[i]>=h[i+1]){
            ans++;
        }
        else{
            maxans=max(maxans,ans);
            ans=0;
        }
    }
	cout<<maxans;
	return 0;
}


Measured memory_bytes: 640
X, K, D = map(int, input().split())
if X > 0:
  px = X % D
  cnt = X // D
  if cnt > K:
    print(abs(X - D * K))
    exit()
  nx = px - D
  K -= cnt
  if K % 2 == 0:
    print(abs(px))
  else:
    print(abs(nx))
elif X == 0:
  if K % 2 == 0:
    print(X)
  else:
    print(abs(D))
else:
  cnt = int(-X / D)
  nx = X + cnt * D
  if cnt > K:
    print(abs(X + D * K))
    exit()
  px = nx + D
  K -= cnt
  if K % 2 == 0:
    print(abs(nx))
  else:
    print(abs(px))

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

int main(){
  ll X,K,D,f,left;
  cin>>X>>K>>D;
  X=abs(X);
  if(K<=X/D){
    cout<<abs(X-K*D)<<endl;
  }
  else{
    f=floor(X/D);
    left=K-f;
    X-=D*f;
    cout<<(left%2==0?X:abs(X-D))<<endl;
  }
}

Measured memory_bytes: 3636
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static System.Console;

namespace ConsoleApp2
{
    class Program
    {
        static public int[] Sarray() { return ReadLine().Split().Select(int.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static void Main(string[] args)
        {
            var X = Sarray()[0];
            long sum = 0;
            var i = 0;
            for( ; sum < X;)
            {
                i++;
                sum += i;
            }
            WriteLine(i);
        }

    }
}


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

using namespace std;

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

#define X first
#define Y second

const int N=2e5+10;

int n,m;
int h[N][2];
vector <int> v[N];
queue <ii> q;


void BFS(int st){
    h[st][0]=1;
    q.push(ii(st,0));
    while (!q.empty()){
        ii cur=q.front();q.pop();
//        cout<<cur.X<<" "<<cur.Y<<'\n';
        for(auto y:v[cur.X]) if (!h[y][cur.Y^1]){
            h[y][cur.Y^1]=1;
            q.push(ii(y,cur.Y^1));
        }
    }
}
ll solve(){
    ll isolated=0;
    int odd=0,even=0;
    for(int st=1;st<=n;st++) if (!h[st][0]&&!h[st][1]){
        if (v[st].empty()) isolated++;
        else {
            BFS(st);
            if (h[st][1]) odd++;
            else even++;
        }
    }
    ll ans=2*n*isolated-isolated*isolated;
//    cout<<isolated<<" "<<odd<<" "<<even<<'\n';
    ans+=1LL*odd*odd+2LL*odd*even+2LL*even*even;
    return ans;
}
int main(){
    scanf("%d%d",&n,&m);
    while (m--){
        int x,y;
        scanf("%d%d",&x,&y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    cout<<solve()<<'\n';
}


Measured memory_bytes: 11264
N, K = map(int, input().split())

lh = list()
for i in range(N):
    lh.append(int(input()))

lh = sorted(lh)

ldes = list()
for i in range(N-K+1):
    ldes.append(lh[i+K-1] - lh[i])

print(min(ldes))

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

int main(){
	int a,b,c,k;
	long long max;
	long long sum;
	
	cin >> a >> b >> c;
	cin >> k;
	max=a;
	if(max<b){
		max=b;
	}
	if(max<c){
		max=c;
	}
	sum=a+b+c-max;
	max = max << k;
	cout << sum+max << endl;
	return 0;
}

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

using namespace std;

int main(){
	vector<int> v={};
	auto it=v.begin();
	int  N;
	long  count=1,count_p=0,count_q=0;
	int  P[9],Q[9];
	int  i,j,ans;

	cin>>N;

	for(i=0;i<N;i++) cin>>P[i];
	for(i=0;i<N;i++) cin>>Q[i];

	for(i=1;i<=N;i++){
		it=v.insert(it,i);  //vectorに1~Nまでの値を挿入する
		it++;
	}

	do{
		for(i=0;i<N && P[i]==v[i];i++);
		for(j=0;j<N && Q[j]==v[j];j++);
		if(i==N) count_p=count;
		if(j==N) count_q=count;
		count++;
	}while(next_permutation(v.begin(),v.end()) && (count_p==0 || 
		   count_q==0));

	ans=count_p-count_q;
	if(ans<0) ans*=-1;

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


Measured memory_bytes: 256
(defun read-prob ()
  (let ((lst nil))
    (dotimes (cnt 4 (nreverse lst))
      (push (read) lst)
      )))

(defun solve (lst)
  (let* ((st (max (nth 0 lst) (nth 2 lst)))
         (en (min (nth 1 lst) (nth 3 lst)))
         (ans (- en st)))
    (if (< ans 0)
        0 ans)))

(format t "~A" (solve (read-prob)))

Measured memory_bytes: 12520
#include<stdio.h>
#include<algorithm>
using namespace std;
int g[210];
int h[11000];
int main(){
	int a,b,c,d,e,f;
	scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
	for(int i=0;i<a;i++)scanf("%d",g+i);
	for(int i=0;i<a;i++)h[g[i]]=1;
	int last=0;
	double ret=0;
	int now=0;
	for(int i=1;i<=f;i++){
		if(now)ret+=1.0/e;
		else ret+=1.0/d;
		if(now&&last+c*e==i){
			now--;
			last=i;
		}
		if(h[i]){
			now++;
			if(now==1)last=i;
			if(now>b+1){
				now--;
				last=i;
			}
		}
	}
	printf("%.12f\n",ret);
}

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

int main()
{
    int a, b, c, d;
    std::cin >> a >> b >> c >> d;
    std::cout << std::max(std::max(1ll * a * c, 1ll * b * d), std::max(1ll * a * d, 1ll * b * c)) << std::endl;
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
 
#define coutv(v) for (int i = 0; i < (v).size(); ++i) cout << v[i] << ' '; cout << endl;
#define coutvv(v) for (int i = 0; i < (v).size(); ++i) {for (int j = 0; j < (v[i]).size(); ++j) cout << v[i][j] << ' '; cout << endl;}
#define debugv(v) {for (int i = 0; i < (v).size(); ++i) cerr << v[i] << ' '; cerr << endl;}
#define debugvv(v) {for (int i = 0; i < (v).size(); ++i) {for (int j = 0; j < (v[i]).size(); ++j) cerr << v[i][j] << ' '; cerr << endl;}}
#define TC int TESTCASE; cin >> TESTCASE; while (TESTCASE--)
typedef long long ll;


int main() {
	int a,b;
	cin >> a >> b;
	if (a < 10 && b < 10) {
		cout << a*b;
	} else {
		cout << -1;
	}
}
 


Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int r = 0, n;
    cin >> n;
    map<int, vector<int>> m;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        int a;
        scanf("%d", &a);
        r ^= a;
        v[i] = a;
        m[__builtin_ffs(a)-1].emplace_back(a);
    }
    int x = 1 << 30, ans = 0;
    for (int p = 30; p  >= 0; --p) {
        if(r & x){
            if(m[p].empty()) {
                puts("-1");
                return 0;
            }else {
                r ^= m[p][0];
                r ^= (m[p][0]-1);
                ans++;
            }
        }
        x /= 2;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
const unsigned long long size=100001;
unsigned long long N,M;//N:vertex M:edge
unsigned long long relate[size];unsigned long long par[size];
unsigned long long root(unsigned long long v){
	if(relate[v]==v){
		return v;
	}else{
		return root(relate[v]);
	}
}
void unite(unsigned long long x,unsigned long long y){//union by size
	x=root(x);y=root(y);
	if(x==y){
		return;
	}else if(par[x]<par[y]){
		swap(x,y);
	}relate[y]=x;
	par[x]+=par[y];
	return;
}
bool issame(unsigned long long x,unsigned long long y){
	return root(x)==root(y);
}
unsigned long long volume(unsigned long long x){
	return par[root(x)];
}
int main(){
	cin>>N>>M;
	unsigned long long A[M],B[M];unsigned long long ans[M];
    unsigned long long result=N*(N-1)/2;
	int a,b;
	for(int i=0;i<M;i++){
		cin>>A[i]>>B[i];
		A[i]--;B[i]--;
	}for(int i=0;i<N;i++){//initialize
		relate[i]=i;
        par[i]=1;
	}for(int i=M-1;i>=0;i--){
		ans[i]=result;
        a=root(A[i]);b=root(B[i]);
        if(a!=b){
            result-=par[a]*par[b];
            unite(a,b);
		}
	}for(int j=0;j<M;j++){
		cout<<ans[j]<<endl;
	}
}


Measured memory_bytes: 5248
#include<iostream>
#include<map>
using namespace std;
struct rode{int x,y;}a[100001];
struct subway{int x,y;}b[100001];
int rtree[200100],stree[200100];
map< pair<int,int>,int>  num;
int findrroot(int root)
{
    int start,t;
    start=root;
    while(root!=rtree[root])
        root=rtree[root];
    while(start!=root)
    {
        t=rtree[start];
        rtree[start]=root;
        start=t;
    }
    return root;
}
int findsroot(int root)
{
    int start,t;
    start=root;
    while(root!=stree[root])
        root=stree[root];
    while(start!=root)
    {
        t=stree[start];
        stree[start]=root;
        start=t;
    }
    return root;
}
int main()
{
    int N,K,L;
    int root1,root2;
    cin>>N>>K>>L;
    for(int i=1;i<=K;i++)
        cin>>a[i].x>>a[i].y;
    for(int i=1;i<=L;i++)
        cin>>b[i].x>>b[i].y;
    for(int i=1;i<=N;i++)
    {
        rtree[i]=i;
        stree[i]=i;
    }
    for(int i=1;i<=K;i++)
    {
        root1=findrroot(a[i].x);
        root2=findrroot(a[i].y);
        if(root1!=root2)
            rtree[root2]=root1;
        //for(int i=1;i<=N;i++)
//cout<<stree[i]<<" ";
        //cout<<endl;
    }
    for(int i=1;i<=L;i++)
    {
        root1=findsroot(b[i].x);
        root2=findsroot(b[i].y);
        if(root1!=root2)
            stree[root2]=root1;
    }
    for(int i=1;i<=N;i++)
    {
        findrroot(i);
        findsroot(i);
    }
    for(int i=1;i<=N;i++)
    {
        num[make_pair(rtree[i],stree[i])]++;
    }
    for(int i=1;i<=N;i++)
        cout<<num[make_pair(rtree[i],stree[i])]<<" ";
    return 0;
}


Measured memory_bytes: 15104
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		 Scanner sc = new Scanner(System.in);
		 for(int i = 0 ;; i++) {
			 int x = sc.nextInt();
			 int y = sc.nextInt();
			 if(x == 0 && y == 0) {
				 break;
			 }
			 if(x > y) {
			 System.out.println(y + " " + x);
			 }else {
			 System.out.println(x + " " + y);
			}
		 }
		 sc.close();
	 }
}


Measured memory_bytes: 36844
n,m=map(int,input().split())
uv=[list(map(int, input().split())) for _ in range(m)]
s,t=map(int,input().split())

graph = [[] for _ in range(n)]
for v in uv:
    graph[v[0]-1].append(v[1]-1)
# print(graph)
s-=1
t-=1

is_checked=[[0]*3 for _ in range(n)]
is_checked[s][0]=1

ans=-1

from collections import deque
q=deque()
q.append([s,0])

while q:
    v, cnt=q.popleft()
    if v==t and cnt%3==0:
        ans=cnt//3
        break
    for i in graph[v]:
        if is_checked[i][(cnt+1)%3]==0:
            q.append([i, cnt+1])
            is_checked[i][(cnt+1)%3]=1
# print(is_checked)
print(ans)



Measured memory_bytes: 48280
// Problem : F - path pass i
// Contest : AtCoder - AtCoder Beginner Contest 163
// URL : https://atcoder.jp/contests/abc163/tasks/abc163_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

int n, c[maxN], sz[maxN], prv[maxN], parent[maxN];
ll ans[maxN];
vi graph[maxN];
int odj[maxN];
bool first[maxN];

void DFS(int u, int par) {
	for(auto x: graph[u]) {
		if (x != par) {
			parent[x] = u;
			DFS(x, u);
			sz[u] += sz[x];
		}
	}
	sz[u]++;
}

ll calc(vector<ll>& vec) {
	ll sum = 0;
	ll tmp = 0;
	for (auto x: vec) sum += x;
	for (auto x: vec) {
		sum -= x;
		tmp += x * sum;
		sum += x;
	}
	tmp /= 2;
	tmp += sum;
	tmp++;
	return tmp;
}

void DFS2(int u, int par) {
	vector<ll> vec;
	for (auto x: graph[u]) {
		if (x != par) {
			vec.pb(sz[x]);
		}
	}
	int val = odj[c[u]];
	if (prv[c[u]] == 0) {
		vec.push_back(n - sz[u] - odj[c[u]]);
	} else {
		vec.push_back(sz[prv[c[u]]] - sz[u] - odj[c[u]]);
	}
	ans[c[u]] += calc(vec);
	for (auto x: graph[u]) {
		if (x != par) {
			int k = prv[c[u]];
			prv[c[u]] = x;
			odj[c[u]] = 0;
			DFS2(x, u);
			prv[c[u]] = k;
		}
	}
	odj[c[u]] = val;
	odj[c[u]] += sz[u];
}

// sprawdz MODULO!
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n;
	RI(i, n) cin >> c[i];
	REP(_, n - 1) {
		int a, b;
		cin >> a >> b;
		graph[a].pb(b);
		graph[b].pb(a);
	}
	DFS(1, -1);
	RI(i, n) {
		prv[i] = 0;	
	}
	DFS2(1, -1);
	RI(i, n) cout << ans[i] << "\n";
	return 0;
}
 


Measured memory_bytes: 73072
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <bitset>
using namespace std;
bitset<2000*2000+3>p;
int n,x,y;
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	p[0]=1;
	y=0;
	for(int i=1;i<=n;i++){
		cin>>x;
		p|=p<<x;
		y+=x;
	}
	for(int i=(y+1)/2;;i++){
		if(p[i]){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

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

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

using namespace std;

// gcd
int gcd(int a, int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

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

    vector<string> v;

    for(int i=0; i<K;i++){
        for(int j=0; j<S.length()-i; j++){
            v.push_back(S.substr(j,i+1));
        }
    }

    sort(v.begin(),v.end());
    auto q = unique(v.begin(),v.end());
    v.erase(q,v.end());

    cout << v[K-1] <<endl;
    return 0;
}



Measured memory_bytes: 1660
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var n = IO.RInt;
            var a = IO.RSInt;

            // 0は負として扱う
            var miscnt = a.Where(x => x <= 0).Count();

            long ans = 0;
            if (miscnt % 2 == 0)
            {
                for (int i = 0; i < a.Length; i++)
                {
                    ans += Abs(a[i]);
                }
            }
            else
            {
                int zerotikainum = int.MaxValue;
                for (int i = 0; i < a.Length; i++)
                {
                    ans += Abs(a[i]);
                    zerotikainum = Min(zerotikainum, Abs(a[i]));
                }
                ans += -2 * zerotikainum;
            }
            WriteLine(ans);
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

Measured memory_bytes: 30172