akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define eps 1e-6
#define mp make_pair
const long long INF=1e18+2;
const int MX=200002;
int N, M, k;
vector<char> v;
int arr[MX], cnt[MX];

int main()
{
    cin>>N;
    ll a, b;
    cin>>a>>b;
    ll ma=a, mb=b;
    for(int i=2; i<=N; i++)
    {
        ll c, d;
        cin>>c>>d;
        ll m=(c+a-1)/c;
        m=max(m, (d+b-1)/d);
        a=m*c;
        b=m*d;

    }
    cout<<a+b<<'\n';
}


Measured memory_bytes: 256
while True:
  s = input().rstrip().split(' ')
  H = int(s[0])
  W = int(s[1])
  if H == 0 and W == 0:
    break;
  ans = ""
  anscen = ""
  for i in range(W):
    ans += "#"
  anscen += "#"
  for k in range(W-2):
    anscen += "."
  anscen += "#"
  print(ans)
  for j in range(H-2):
    print(anscen)
  print(ans)
  print("")



Measured memory_bytes: 5608
#include<stdio.h>
int main(){
int a,b,c;

  scanf("%d%d%d",&a,&b,&c);
  if(a<=b&&b<=c){
     printf("%d %d %d\n",a,b,c);
}
 else if(a<=c&&c<=b){
     printf("%d %d %d\n",a,c,b);
}
 else if(b<=a&&a<=c){
     printf("%d %d %d\n",b,a,c);
}
 else if(b<=c&&c<=a){
     printf("%d %d %d\n",b,c,a);
}
 else if(c<=a&&a<=b){
     printf("%d %d %d\n",c,a,b);
}
 else {
     printf("%d %d %d\n",c,b,a);
}

  return 0;
}

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

int main() {
	int a,max=INT_MIN;
	vector<int> A;
	map<int, int> mp;
	while (cin >> a) {
		A.push_back(a);
		mp[a] = 0;
	}
	for (auto itr = mp.begin(); itr != mp.end(); itr++) {
		for (int i = 0; i < A.size(); i++) {
			if (itr->first == A[i])itr->second++;
		}
	}
	for (auto itr = mp.begin(); itr != mp.end(); itr++) {
		if (max < itr->second)max = itr->second;
	}
	for (auto itr = mp.begin(); itr != mp.end(); itr++) {
		if (itr->second == max)cout << itr->first << endl;
	}
	return 0;
}

Measured memory_bytes: 3108
#include <iostream>
#include <cstring>
using namespace std;
char str[10000];
int main()
{
    cin>>str;
    int n=strlen(str);
    if(str[n-1]=='s'){
        cout<<str<<"es"<<endl;
    }else{
        cout<<str<<'s'<<endl;
    }
}

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

int main(){
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll cmn, cmx, dmn, dmx, cdmn, cdmx;
  cmn = (a+c-1)/c;
  cmx = b/c;
  dmn = (a+d-1)/d;
  dmx = b/d;
  ll cd = lcm(c, d);
  cdmn = (a+cd-1)/cd;
  cdmx = b/cd;
  //cout << cmx << cmn << endl;
  //cout << dmx << dmn << endl;
  //cout << cdmx << cdmn << endl;
  ll ans = b-a+1 - ((cmx-cmn+1) + (dmx-dmn+1) - (cdmx-cdmn+1));
  cout << ans << endl;
}


Measured memory_bytes: 3580
# coding: utf-8
# Your code here!

N,M = map(int,input().split(" "))
A = []
B = []

for i in range(N):
    a,b = map(int,input().split(" "))
    A.append(a)
    B.append(b)
    
L = list(zip(A,B))
L.sort()

#N 店の軒数


#M 買いたい本数
#A 一本の価格
#B 買える本数
yen = 0

while True:
    i = 0#i = A.index(min(A))
    #y = min(A)
    #print(A,B,M)
    if L[0][1] >= M:
        yen += M*L[0][0]
        break
    else:#B[i] < M
        yen += L[0][1] * L[0][0]
        M -= L[0][1]
        del L[0]
        
        
print(yen)

Measured memory_bytes: 18644
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) {
	Main m = new Main();
	m.answer();
    }

    private Scanner scan = new Scanner(System.in);
    private PriorityQueue<Data> dataQueue;

    public Main() {
	int N = Integer.parseInt(scan.next());
	dataQueue = new PriorityQueue<Data>(N);
	IntStream.range(0, N).forEach(i -> {
		int A = Integer.parseInt(scan.next());
		int B = Integer.parseInt(scan.next());
		dataQueue.add(new Data(A, B));
	    });
	scan.close();
    }

    public final void answer() {
	Data minData = dataQueue.poll();
	int result = minData.A + minData.B; 
	System.out.println(result);
    }

    private static class Data implements Comparable<Data> {
	int A;
	int B;

	public Data(int A, int B) {
	    this.A = A;
	    this.B = B;
	}

	@Override
	public int compareTo(Data o) {
	    return -(this.A - o.A);
	}
    }
}


Measured memory_bytes: 63988
using System;
using System.Collections.Generic;

namespace Dice
{
    class Program
    {
        private static bool Eql(string[] x, string[] y)
        {
            var g = true;
            for (int o = 0; o < x.Length; o++)
              if (x[o] != y[o]) g = false;
            return g;
        }

        private static bool Check(string[] x, string[] y)
        {
            if (Eql(x, y)) return true;
            for (int p = 0; p < 2; p++)
            {
                for(int q = 0; q < 4; q++)
                {
                    var a = x[0]; var b = x[1]; var c = x[2];
                    var d = x[3]; var e = x[4]; var f = x[5];
                    x = p == 0 ? new string[] { e, a, c, d, f, b } :
                                 new string[] { d, b, a, f, e, c };
                    if (Eql(x, y)) return true;
                    var h = x;
                    for(int r = 0; r < 4; r++)
                    {
                        var i = h[0]; var j = h[1]; var k = h[2];
                        var l = h[3]; var m = h[4]; var n = h[5];
                        h = new string[] { i, k, m, j, l, n };
                        if (Eql(h, y)) return true;
                    }
                }
            }
            return false;
        }

        static void Main()
        {
            int s = int.Parse(Console.ReadLine());
            var t = new string[s][];
            for(int u = 0; u < s; u++)
                t[u] = Console.ReadLine().Split(' ');
            for (int v = 0; v < s; v++)
                for (int w = v + 1; w < s; w++)
                    if (Check(t[v], t[w]))
                    {
                        Console.WriteLine("No");
                        return;
                    }
            Console.WriteLine("Yes");
        }
    }
}

Measured memory_bytes: 9280
#include <iostream>
#include <algorithm>
#include <complex>
#include <cmath>
#include <string>
#include <sstream>
using namespace std;

typedef complex<double> P;

const double eps = 1e-10;
bool equals(double a, double b) { return fabs(a-b) < eps; }

double dot(P a, P b) { return a.real()*b.real() + a.imag()*b.imag(); }

bool isOrthogonal(P a1, P a2, P b1, P b2) {
  return equals(dot(a1-a2, b1-b2), 0.0);
}

int main() {
  string line;
  while(getline(cin, line)) {
    stringstream ss;
    ss << line;
    P p[4];
    for(int i = 0; i < 4; ++i) {
      ss >> p[i].real() >> p[i].imag();
    }
    cout << (isOrthogonal(p[0],p[1],p[2],p[3]) ? "YES" : "NO") << endl;
  }
  return 0;
}

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

int main() { 
    int n;
    cin >> n;
    vector<int> B(n-1);
    for(int i = 0; i < n-1; i++) cin >> B[i];
    vector<int> A(n);
    A[0] = B[0];
    A[n-1] = B[n-2];
    for (int i = 1; i < n - 1; i++) {
      A[i] = min(B[i], B[i - 1]);
    }
    cout << accumulate(A.begin(), A.end() , 0) << endl;
    return 0;
}

Measured memory_bytes: 3632
from bisect import bisect_right, bisect_left

N = int(input())
L = list(map(int, input().split()))
L.sort()

ans = 0
for i, a in enumerate(L):
    for j, b in enumerate(L[i + 1:], start=i + 1):
        left = bisect_right(L, abs(a - b))
        right = bisect_left(L, a + b)
        ans += right - left

        if left <= i < right:
            ans -= 1
        if left <= j < right:
            ans -= 1

print(ans // 3)


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

int main(){
    int n;
    cin >> n;
    int a[n];
    deque<int> b;
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(i%2==0) b.push_front(a[i]);
        else b.push_back(a[i]);
    }
    for(int i=0;i<n;i++){
        if(n%2==1){
            cout << b.front() << " ";
            b.pop_front();
        }
        else{
            cout << b.back() << " ";
            b.pop_back();
        }
    }
    cout << endl;
}

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

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

	bool even = true;
	for (int i = 0; i < n; i++)
	{
		if(a[i] % 2 != 0) even = false;
	}

	if(even) cout << "second" << endl;
	else cout << "first" << endl;
	return 0;
}



Measured memory_bytes: 4364
n = gets.chomp.to_i
edge = Array.new(n+1).map{Array.new}
(n-1).times do
    a, b = gets.chomp.split(" ").map(&:to_i)
    edge[a] << b
    edge[b] << a
end

cost_a = Array.new(n+1,0)
cost_b = Array.new(n+1,0)

done = Array.new(n+1,false)

queue = [1]
done[1] = true
while(queue.size > 0)
    v = queue.pop
    
    edge[v].each do |i|
        if done[i] == false
            done[i] = true
            queue.push(i)
        else
            cost_a[v] = cost_a[i] + 1
        end
    end
end

done = Array.new(n+1,false)

queue = [n]
done[n] = true
while(queue.size > 0)
    v = queue.pop
    
    edge[v].each do |i|
        if done[i] == false
            done[i] = true
            queue.push(i)
        else
            cost_b[v] = cost_b[i] + 1
        end
    end
end

b = 0
w = 0
1.upto(n) do |i|
    if cost_a[i] <= cost_b[i]
        b+=1
    else
        w+=1
    end
end
if b <= w
    puts 'Snuke'
else
    puts 'Fennec'
end

Measured memory_bytes: 15228
n,k=map(int,input().split())
d = tuple(map(int, input().split()))
e = [0]*n

for i in range(n):
    s = (1+d[i])*d[i]/2
    e[i] = s / d[i]

max1 = 0
tmp = 0
for j in range(n-k+1):
#    if len(e[j:j+k]) < k:
#        break
    if j == 0:
        tmp = sum(e[j:j+k])
    else:
        tmp = tmp - e[j-1] + e[j+k-1]
    if max1 < tmp:
        max1 = tmp
print(max1)


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

typedef long long ll;
const int inf = 1e9;

int n, res;
string s, t;

int main(){
	res = 0;
	cin>>s>>t;
	int n = s.size();
	for(int i = 0; i < n; ++i){
		if(s[i] != t[i])res++;
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 3868
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T> bool INRANGE(T x,T a,T b) { return a<=x&&x<=b; }
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;


typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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


    int N, Q;
    string S;
    cin >> N >> Q >> S;
    vi l(Q), r(Q);
    REP(i,Q) cin >> l[i] >> r[i];

    vi v(N,0);
    FOR(i,1,N){
        if (S[i]=='C' and S[i-1]=='A') v[i] = v[i-1]+1;
        else v[i] = v[i-1];
    }

    //for (int i : v) cout << i << " ";

    REP(i,Q){
        cout << v[r[i]-1] - v[l[i]-1] << endl;
    }

    return 0;
}

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int ind;
string str;

int operate(void);

int main(void){
    int n; cin >> n;
    while(n--){
        cin >> str;
        ind = 0;

        cout << operate() << endl;
    }

	return 0;
}

int operate(void){
    int ret = 0;

    if(str.at(++ind) == '['){
        vi nums;
        while(str.at(ind) == '['){
            nums.pb(operate());
        }

        sort(all(nums));

        rep(i, nums.size() / 2 + 1){
            ret += nums[i];
        }
    }
    else{
        int pos = str.find(']', ind);
        ret = toInt(str.substr(ind, pos - ind)) / 2 + 1;
        ind = pos;
    }

    ++ind;
    return ret;
}

Measured memory_bytes: 1296
#include<iostream>
#include<cstdio>
using namespace std;
int n,p,C[3030][3030],S[3030][3030];
long long ksm(long long x,int t,int P)
{
	long long res=1;
	for(;t;t>>=1,x=x*x%P) if(t&1) res=res*x%P;
	return res;
}
void init()
{
	S[0][0]=1;
	for(int i=1;i<=n+1;i++)
	for(int j=1;j<=i;j++)
	S[i][j]=(1LL*j*S[i-1][j]+S[i-1][j-1])%p;
	for(int i=0;i<=n;i++) C[i][i]=C[i][0]=1;
	for(int i=1;i<=n;i++)
	for(int j=1;j<i;j++) C[i][j]=(C[i-1][j-1]+C[i-1][j])%p;
}
int main()
{
	scanf("%d%d",&n,&p);
	init();
	int ans=0;
	for(int i=0,fl=1;i<=n;i++,fl=p-fl)
	{
		int sum=0,fc=ksm(2,n-i,p),mul=1;
		for(int j=0;j<=i;j++,mul=1LL*mul*fc%p)
		(sum+=1LL*S[i+1][j+1]*mul%p)%=p;
		(ans+=1LL*fl*sum%p*C[n][i]%p*ksm(2,ksm(2,n-i,p-1),p)%p)%=p;
	}
	printf("%d\n",ans);
	return 0;
}
	

Measured memory_bytes: 70656
#include <cstdio>
#include <set>
#include <vector>
#include <cstring>

using namespace std;

typedef long long ll;
const ll mod = 1e9+7;
ll dp[333][333][333];

ll pl(ll a, ll b) {
  return (a+b)%mod;
}
ll ml(ll a, ll b) {
  return (a*b)%mod;
}

int main(void) {
  int n, m;
  scanf("%d%d", &n, &m);
  dp[0][1][0] = 1;
  for (int i = 0; i < m; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 0; k < n; k++) {
        // 強連結でない頂点から強連結でない頂点，新しく加える
        if (n-j-k >= 0) {
          dp[i+1][j][k+1] = pl(dp[i+1][j][k+1], ml(dp[i][j][k], n-j-k));
        }
        // 強連結でない頂点から強連結でない頂点へ
        dp[i+1][j][k] = pl(dp[i+1][j][k], ml(dp[i][j][k], k));
        // 強連結でない頂点から強連結な頂点へ
        if (j+k <= n) {
          dp[i+1][j+k][0] = pl(dp[i+1][j+k][0], ml(dp[i][j][k], j));
        }
      }
    }
  }
  printf("%lld\n", dp[m][n][0]);
  return 0;
}


Measured memory_bytes: 235392
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  while(cin >> n >> m, n | m) {
    vector<int> sum = {0};
    for(int i = 0; i < n; ++i) {
      int K;
      cin >> K;
      sum.push_back((sum.back() + (K % m)) % m);
    }
    int answer = 0;
    set<int> used = {m};
    for(auto j: sum) {
      answer = max(answer, (j - *used.upper_bound(j) + m) % m);
      used.insert(j);
    }
    cout << answer << endl;
  }
}

Measured memory_bytes: 2392
#include<bits/stdc++.h>
#define int long long
#define rg register
#define file(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
using namespace std;
const int N=200000+10;
const int mod=1e9+7;
const int inf=1e10;
int read(){
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
    while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();
    return f*x;
}
int X[N],Y[N],W,H,n,res;
map<int,int> Map,f;
void calc(int x,int y){
	int X1,Y1,X2,Y2;
	for(int i=1;i<=3;i++)
		for(int j=1;j<=3;j++){
			if(i==1&&j==1) X1=x-2,Y1=y-2,X2=x,Y2=y;
			if(i==1&&j==2) X1=x,Y1=y-2,X2=x+2,Y2=y;
			if(i==1&&j==3) X1=x-1,Y1=y-2,X2=x+1,Y2=y;
			if(i==2&&j==1) X1=x-2,Y1=y,X2=x,Y2=y+2;
			if(i==2&&j==2) X1=x,Y1=y,X2=x+2,Y2=y+2;
			if(i==2&&j==3) X1=x-1,Y1=y,X2=x+1,Y2=y+2;
			if(i==3&&j==1) X1=x-2,Y1=y-1,X2=x,Y2=y+1;
			if(i==3&&j==2) X1=x,Y1=y-1,X2=x+2,Y2=y+1;
			if(i==3&&j==3) X1=x-1,Y1=y-1,X2=x+1,Y2=y+1;
			if(X1<1||Y1<1||X2>H||Y2>W) continue;
			if(f[X1*inf+Y1]) continue;
			f[X1*inf+Y1]=1;
			int ans=0;
			res++;
			for(int i=X1;i<=X2;i++)
				for(int j=Y1;j<=Y2;j++)
					if(Map[i*inf+j])
						ans++;
			//		if(ans==0) cout<<x<<" "<<y<<" "<<X1<<" "<<Y1<<" "<<X2<<" "<<Y2<<endl;
			f[ans]++;
		}
}
main(){
	H=read(),W=read(),n=read();
	for(int i=1;i<=n;i++)
		X[i]=read(),Y[i]=read(),Map[X[i]*inf+Y[i]]=1;
	for(int i=1;i<=n;i++)
		calc(X[i],Y[i]);
//	exit(0);
	cout<<(H-2)*(W-2)-res<<endl;
	for(int i=1;i<=9;i++)
		cout<<f[i]<<endl;
}


Measured memory_bytes: 214272
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>

using namespace std;

typedef long long ll;

int n;

string Ask(const vector<int> a) {
  string s = "?";
  for (int x : a) {
    s += " " + to_string(x);
  }
  cout << s << endl;
  cout.flush();
  string result;
  cin >> result;
  return result;
}

string GetColor(int p) {
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    a[i] = p + i + 1;
  }
  return Ask(a);
}

string Other(string color) {
  if (color == "Red") return "Blue";
  return "Red";
}

string AskColor(int left, int what, int to) {
  vector<int> a;
  for (int i = 0; i < n; ++i) {
    if (left + i == what) continue;
    a.push_back(left + i + 1);
  }
  a.push_back(to + 1);
  return Ask(a);
}

int main()
{
  cin >> n;

  string leftColor = GetColor(0);

  int l = 0; int r = n;
  while (r - l > 1) {
    int m = (l + r) / 2;
    string curColor = GetColor(m);
    if (curColor != leftColor) {
      r = m;
    } else {
      l = m;
    }
  }

  string result(2 * n, ' ');
  result[l] = leftColor[0];
  r = l + n;
  result[r] = Other(leftColor)[0];

  for (int i = 0; i < 2 * n; ++i) {
    if (i == l || i == r) continue;
    string curColor;
    if (i < l || i > r) {
      curColor = AskColor(l, l, i);
    } else {
      curColor = Other(AskColor(l, i, r));
    }
    result[i] = curColor[0];
  }
  
  cout << "! " + result << endl;
  cout.flush();

  return 0;
}


Measured memory_bytes: 724
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

ans=0
pre=-100
for i in A:
    ans+=B[i-1]

    if(i-pre==1):
        ans+=C[i-2]

    pre=i

print(ans)


Measured memory_bytes: 3060
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  int x,y,z,ans=0;
  std::cin >> x >> y >> z;
  int p=y+z;
  while(x-z>=0){
    x=x-p;
    ans++;
  }

  std::cout << ans-1 << '\n';


  return 0;
}


Measured memory_bytes: 256
public class Main {
		 
		public static void main(String[] args) {
	 
			java.util.Scanner scan = new java.util.Scanner(System.in);
		

			String a = scan.next();
			
			if ( a .equals("ABC")) {
				System.out.println("ARC");
			} else {
				System.out.println("ABC");
			}
			
		}
	 
	}

Measured memory_bytes: 35688
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,i;string S;cin>>A>>B>>S;
  for(i=0;i<A+B+1;i++){
    if(i==A){if(S.at(i)!='-')break;}
    else if(S.at(i)<'0'||S.at(i)>'9')break;
  }
  if(i==A+B+1)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
//xtwakioi! xtwddYnoi(双重含义)!
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int n,f[N];
char s[N];
inline bool Check()
{
    for(ri int i=1;i<=n;i++)
    {
        int p,q;
        p=i-1, q=i+1;
        if(!p) p=n;
        if(q>n) q=1;
        if(f[i]==1)
        {
            if(s[i]=='o'&&f[p]!=f[q]) return 0;
            if(s[i]=='x'&&f[p]==f[q]) return 0;
        }
        else
        {
            if(s[i]=='o'&&f[p]==f[q]) return 0;
            if(s[i]=='x'&&f[p]!=f[q]) return 0;
        }
    }
    return 1;
}
signed main()
{
    scanf("%lld",&n);
    scanf("%s",s+1);
    for(ri int i=1;i<=2;i++)
    for(ri int j=1;j<=2;j++)
    {
        f[1]=i, f[2]=j;
        for(ri int k=2;k<n;k++)
        {
            if(f[k]==1)
            {
                if(s[k]=='o') f[k+1]=f[k-1];
                else f[k+1]=(f[k-1]==1?2:1);
            }
            else
            {
                if(s[k]=='x') f[k+1]=f[k-1];
                else f[k+1]=(f[k-1]==1?2:1);
            }
        }
        if(Check())
        {
            for(ri int k=1;k<=n;k++) printf("%c",f[k]==1?'S':'W');
            puts("");
            return 0;
        }
    }
    puts("-1");
    return 0;
}

Measured memory_bytes: 4504
<?php
  $k = intval(fgets(STDIN));
 
  $total = 0;
  $list = [];
 
  for($i=0; $i<$k; $i++){
    $list[$i+1] = [];
  }
 
  for($a=1; $a<=$k; $a++){
    for($b=1; $b<=$k; $b++){
      if(isset($list[$a][$b])){
        $tmp = $list[$a][$b];
      }else{
        $tmp = gmp_strval(gmp_gcd($a, $b));
        $list[$a][$b] = $tmp;
      }
      
      for($c=1; $c<=$k; $c++){
        if(isset($list[$tmp][$c])){
          $tmp2 = $list[$tmp][$c];
        }else{
          $tmp2 = gmp_strval(gmp_gcd($tmp, $c));
          $list[$tmp][$c] = $tmp2;
        }
        $total += $tmp2;
      }
    }
  }
 
  echo $total."\n";

Measured memory_bytes: 19000
def sub(a, b):
    if (a%b == 0):
        return a//b-1
    return a//b

def mod(a, b):
    if a%b==0:
        return b
    return a%b

n, x = map(int, input().split(' '))
ans = n
c = [x, n-x]
while (c[0] != c[1]):
    c = [min(c), max(c)]
    ans += 2*sub(c[1], c[0])*c[0]
    c[1] = mod(c[1], c[0])
print(ans+c[0])


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
  ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
      if(b&1)res = res * x % MOD;
      x = x * x % MOD;
      b>>=1;
    }
    return res;
  }

  ll modinv(ll x){
    return modpow(x, MOD-2);
  }

  bool was_output = false;
  template<class t>
  void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
  }
  void outendl(){
    was_output = false;
    cout << endl;
  }
  ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  void in(t&x){
    cin >> x;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

int main(){
    vector<ll> line(3);
    foreach(i,line)i=in();
    int k = in();
    int need = 0;
    rep(i,1,3){
        while(line[i-1]>=line[i]){
            line[i] *= 2;
            ++need;
        }
    }
    cout << (need<=k?"Yes":"No") << endl;
  return 0;
}


Measured memory_bytes: 3676
/** Author : Izanagi **/

#pragma warning(disable:4996)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")

#include <bits/stdc++.h>

using namespace std;

const long long Mod = 1e9 + 7;
const long long inf = 1e18;
const long long INF = 1e9 + 7;
const long long Lim = 1e5 + 1e3;
const double eps = 1e-10;

typedef long long int ll;
typedef vector <int> vi;
typedef vector <vi> vii;
typedef vector <ll> vl;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define mem(a,val) memset(a,val,sizeof(a))
#define all(v) v.begin(), v.end()
#define faster ios_base:: sync_with_stdio(false),cin.tie(0),cout.tie(0)

// Debugging Function

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

//------------------------X-----------------------------------//

int main()
{
    int n;

    cin >> n;

    vector <int> h(n);

    for(int i=0; i<n; i++)
    {
        cin >> h[i];
    }

    vector <int> dp(n,INF);

    dp[0] = 0;

    for(int i=0; i<n; i++)
    {
        for(int j : {i+1, i+2})
        {
           if(j<n)
           {
               dp[j] = min(dp[j],dp[i] + abs(h[i] - h[j]));
           }
        }
    }

    cout << dp[n-1] << endl;

    return 0;
}


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

int main() {

	string s; cin >> s;

	int n = stoi(s);
	int sum = 0;
	for ( int i = 0; i < s.size(); i++)	{
		sum += (int)(s.at(i) - '0');
	}

	if (n % sum == 0) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
q=int(input())
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]
p=primes(10**5)
accum=[0]*(10**5+1)
s=set(p)
for i in range(1,10**5+1):
  if i%2:
    if i in s and (i+1)//2 in s:
      accum[i]+=1
for i in range(10**5):
  accum[i+1]+=accum[i]
for _ in range(q):
  l,r=map(int,input().split())
  if l==1:
    print(accum[r])
  else:
    print(accum[r]-accum[l-1])

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

int main(){
    ll N, D;
    cin >> N >> D;
    ll X, Y;
    int cnt = 0;

    rep(i, N){
        cin >> X >> Y;
        if (X * X + Y * Y <= D * D){
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include<stdlib.h>
#include<algorithm>
using namespace std;

int main(){
    string s;
    int a, b;
    cin >> s;

    a = atoi(s.substr(0,2).c_str());
    b = atoi(s.substr(2,2).c_str());

    if(1 <= a && a <= 12){
        if(1 <= b && b <= 12){
            cout << "AMBIGUOUS" << endl;
        }
        else{
            cout << "MMYY" << endl;
        }
    }
    else{
        if(1 <= b && b <= 12){
            cout << "YYMM" << endl;
        }
        else{
            cout << "NA" << endl;
        }
    }
}

Measured memory_bytes: 256
from itertools import accumulate

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
INF = 10 ** 18

acc_a = [0] + list(accumulate(a))
acc_b = [0] + list(accumulate(b))
j = m
ans = 0
for i, e in enumerate(acc_a):
    while j >= 0 and acc_b[j] > k - acc_a[i]:
        j -= 1

    if j == -1:
        break

    ans = max(ans, i + j)

print(ans)


Measured memory_bytes: 50936
package main

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

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

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

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
        buf := make([]byte, 0, 1000000)
        for {
                l, p, e := rdr.ReadLine()
                if e != nil {
                        panic(e)
                }
                buf = append(buf, l...)
                if !p {
                        break
                }
        }
        return string(buf)
}

func strSprit(str string) []string {
        cols := strings.Split(str, " ")
        return cols
}

func parseInt(str string) int {
        n, _ := strconv.Atoi(str)
        return n
}

type SortSlice []int

func (s SortSlice) Len() int {
        return len(s)
}

func (s SortSlice) Swap(i, j int) {
        s[i], s[j] = s[j], s[i]
}

func (s SortSlice) Less(i, j int) bool {
        return s[i] < s[j]
}

func reverseString(str string) string {
        buf := []rune(str)
        for i, j := 0, len(buf)-1; i < j; i, j = i+1, j-1 {
                buf[i], buf[j] = buf[j], buf[i]
        }
        return string(buf)
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////

func main() {
        line := nextLine()
        N := parseInt(line)

        div := 1000000007

        power := 1

        for i := 1; i <= N; i++ {
                power = power * i % div
        }

        fmt.Println(power)

}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
 
int main() {
    long long x, quo_11, quo_6, quo_5,rem_11,rem_6,rem_5;
    
    std::cin >> x;
    if (x > 11)
    {
        quo_11 = x / 11;
        rem_11 = x % 11;
        if (rem_11 > 6)
        {
            std::cout << quo_11 * 2 + 2 << std::endl;
        }
        else if (rem_11 == 0)
        {
            std::cout << quo_11 * 2 << std::endl;
        }
        else
        {
            std::cout << quo_11 * 2 + 1 << std::endl;
        }
    }else if (x > 6)
    {
        std::cout << "2" << std::endl;
    }else
    {
        std::cout << "1" << std::endl;
    }
 
 
 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
bool read(int ind){
	cout << ind << endl;
	char s[10];
	scanf("%s",s);
	if(s[0] == 'V')exit(0);
	return s[0] == 'M';
}
int l,r;
bool isr,isl;
int main(){
	// freopen("readin.txt","r",stdin);
	scanf("%d",&n);
	int l = 0,r = n - 1;
	isl = read(l);
	while(l <= r){
		int mid = (l + r)/2;
		bool temp = read(mid);
		if(!(mid&1) && temp != isl || mid&1 && temp == isl)r = mid - 1;
		else l = mid + 1;
	}
	if(l < n)read(l);
	if(r)read(r);
	if((l + r)/2 && (l + r)/2 < n)read((l + r)/2);
}

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

int main() {
	int N, K;
	cin >> N >> K;
	int A = 1;
	for (int i = 0; i < N; i++) {
		if (A < K) {
			A *= 2;
		}
		else {
			A += K;
		}
	}
	cout << A << endl;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)

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

struct edge {
	int to,cost;
	edge(int t,ll c):to(t),cost(c) {}
};

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

ll mypow(ll x,ll n,ll m) {
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}

//-----------------------------------------------------------------------------

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

	string s; cin>>s;
	string t=s;
	reverse(ALL(t));
	if(s==t) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define ts puts("test  check")
#define xh1(a,b) for(int i=a;i<b;i++)
#define xh2(a,b) for(int j=a;j<b;j++)
#define stlbl(a) for(it=a.begin();it!=a.end();it++)
#define dzkt int T;cin>>T;while(T--)
#define mst(a,i) memset(a,i,sizeof(a))
#define iosks std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int N=3e5+10,M=3e4+10,inf=1e9+10,mod=1e9+7;
const db pi=atan(1)*4;
ll pow2(ll a,ll b) {ll s=1; while(b) {if(b&1) s=(s*a)%mod; a=(a*a)%mod; b/=2; } return s;}
int gcd(int a,int b) {return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) {return a/gcd(a,b)*b; }
ll prime(ll x) {for(ll i=2;i<=sqrt(x+0.5);i++) if(x%i==0) return 0; return 1; }
int read()
{
    int s=0,f=1;
    char ch=getchar();
    while(ch<'0'&&ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') {s=s*10+ch-'0'; ch=getchar();} return s*f;
}
set<ll> st;
vector<ll> vec;

int vis[N][26],nex[N][26],vv[M],len,tot=1,f,n;
string s[M];

int main()
{
    iosks;
    int n,a[105],ans=0;
    cin>>n;
    xh1(0,n) cin>>a[i];
    for(int i=0;i<n;i+=2) if(a[i]&1) ans++;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4536
var n:Int = 0
var A: MutableList<Int> = mutableListOf<Int>()
fun main(args: Array<String>) {
    n = readLine()!!.toInt()
    A.addAll(readLine()!!.split(" ").map { it.toInt() })
    val q = readLine()!!.toInt()
    val M: List<Int> = readLine()!!.split(" ").map { it.toInt() }
    //MをAから作成可能か判定
    for (i in (0..q-1))
    {
        if (solve(0,M[i])==1)
        {
            println("yes")
        }
        else
        {
            println("no")
        }
    }

}
private fun solve(i:Int,m:Int):Int
{
    if (m==0)
    {
        return 1
    }
    if (m < 0)
    {
        return 0
    }
    if(i >= n)
    {
        return 0
    }

    if ((solve(i+1,m)==1) || (solve(i+1,m-A[i])==1))
    {
        return 1
    }
    else
    {
        return 0
    }
}


Measured memory_bytes: 32816
#include <iostream>
using namespace std;
int main(){
	int n,m,sum,a[100][100],b[100];
	cin >> n >> m;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < m; i++) cin >> b[i];
	
	for (int i = 0; i < n; i++){
		sum = 0;
		for (int j = 0; j < m; j++){
			sum += a[i][j]*b[j];
		}
		cout << sum << '\n';
	}	
}


Measured memory_bytes: 3140
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String cup = "A";
		while(sc.hasNext()){
			String[] c = sc.next().split(",");
			if(c[0].equals(cup)){
				cup = c[1];
			}else if(c[1].equals(cup)){
				cup = c[0];
			}
		}
		System.out.println(cup);
	}

}

Measured memory_bytes: 25940
#include <iostream>
#include <cstdlib>

using namespace std;

int main(){
  int i,N;
  int dp[100001],h[100001];
  cin >> N;
  for (i=0;i<N;++i) {
    cin >> h[i];
  }
  dp[0]=0;
  dp[1]=abs(h[0]-h[1]);
  for (i=2;i<N;++i) {
    dp[i]=min(dp[i-1]+abs(h[i-1]-h[i]), dp[i-2]+abs(h[i-2]-h[i]));
  }
  cout << dp[N-1] << endl;
  return 0;
}


Measured memory_bytes: 1024
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        int n = in.nextInt();
        int a[] = new int[n];
        int l=100000,r=0;
        for(int i=0;i<n;i++){
            a[i] = in.nextInt();
            l = Math.min(l,a[i]);
            r = Math.max(r,a[i]);
        }
        long sum=0L,ans = Integer.MAX_VALUE;
        for(int i=l;i<=r;i++){
            sum=0;
            for(int j:a){
                sum+=(j-i)*(j-i);
            }
            ans = Math.min(ans,sum);
        }
        out.println(ans);
    }
    
    /************* SOLUTION ENDS HERE **********/
}

Measured memory_bytes: 21332
n, w = map(int, input().split())
V, W = [], []
for i in range(n):
    vi, wi = map(int, input().split())
    V.append(vi)
    W.append(wi)

# dp[i][sum_w] := i-1 番目までの品物から重さがsum_wを超えないように選んだときの、価値の総和の最大値
dp = [[0] * (w+1) for _ in range(n+1)]

for i in range(n):
    for sum_w in range(w + 1):
        # i番目の商品を選ぶ場合
        if sum_w - W[i] >= 0:
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - W[i]] + V[i])
        # i番目の商品を選ばない場合
        dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w])
print(dp[-1][-1])


Measured memory_bytes: 41888
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}



struct UnionFind
{

  vector<int> par;
  vector<int> sizes;

  UnionFind(int n) : par(n), sizes(n, 1) {
    rep(i,n) par[i] = i;
  }

  int root(int x) {
    if (x == par[x]) return x;
    return par[x] = root(par[x]); 
  }

  bool unite(int x, int y) {

    x = root(x);
    y = root(y);

    if (x == y) return false;

    if (sizes[x] < sizes[y]) swap(x, y);

    par[y] = x;
    sizes[x] += sizes[y];

    return true;
  }

  bool find(int x,int y){
    return root(x)==root(y);
  }

  int size(int x) {
    return sizes[root(x)];
  }
};

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n,q;
  cin>>n>>q;
  UnionFind uf(n);
  while(q--){
    int t,x,y;
    cin>>t>>x>>y;
    if(t==0){
      uf.unite(x,y);
    }else{
      cout<<(uf.root(x)==uf.root(y))<<endl;
    }
  }


}


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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var T = Console.ReadLine();

            if (Check(S, T)) return;

            // 一周してダメなら終了
            for (var i = 0; i < S.Length; i++)
            {
                S = S[S.Length - 1] + S.Substring(0, S.Length - 1);
                if (Check(S, T)) return;
            }

            Console.WriteLine("No");
        }

        static bool Check(string S, string T)
        {
            if (S == T)
            {
                Console.WriteLine("Yes");
                return true;
            }
            return false;
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
ll dp[310][310][310]={0};
int main(){
	ll MOD=1000000007;
	int n,m;
	cin>>n>>m;
	if(n>m){
		cout<<0<<endl;
		return 0;
	}
	dp[0][1][1]=1;
	rep(q,m)loop(i,1,n+1)loop(j,1,n+1){
			if(i!=n)(dp[q+1][i+1][j]+=dp[q][i][j]*(n-i))%=MOD;
			        (dp[q+1][i  ][j]+=dp[q][i][j]*(i-j))%=MOD;
			        (dp[q+1][i  ][i]+=dp[q][i][j]*(j  ))%=MOD;
	}
	cout<<dp[m][n][n]<<endl;
}









Measured memory_bytes: 219392
input()
nums = [int(n) for n in input().split()]

def swap(x, i, j):
    x[i], x[j] = x[j], x[i]

count = 0
for i in range(len(nums) - 1):
    n = nums[i]
    nn = nums[i + 1]
    if (i + 1) == n and (i + 2)== nn:
        count += 1
        swap(nums, i, i + 1)

for i in range(len(nums)):
    n = nums[i]
    if (i + 1) == n:
        count += 1

print(count)


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

using namespace std;

int main(){
  long long n,a,b;
  cin>>n>>a>>b;
  long long ans=a*(n/(a+b))*1ll;
  ans+=(n%(a+b)>a?a:n%(a+b));
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>

int main(void){
	int A,B,C;
	scanf("%d %d %d\n",&A,&B,&C);
	if((A==B && A!=C) || (B==C && B!=A) || (C==A && C!=B))
	printf("Yes");
	else printf("No");

    return 0;
}


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

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var firstLine = Console.ReadLine().Split(' ').Select(value => int.Parse(value)).ToList();
			var n = firstLine[0];
			var k = firstLine[1];

			var buildings = Console.ReadLine().Split(' ').Select(value => long.Parse(value)).ToList();

			var min = long.MaxValue;

			for(var bit = 0; bit < (1 << n); bit++)
			{
				var count = 0;
				for(var i = 0; i < n; i++)
				{
					if(((bit >> i) & 1) == 1)
					{
						count++;
					}
					else if(i == 0)
					{
						break;
					}
				}

				if(count != k)
				{
					continue;
				}

				long maxHeight = 0;
				long cost = 0;

				for(var i = 0; i < n; i++)
				{
					if(i == 0)
					{
						maxHeight = buildings[i];
						continue;
					}

					if(((bit >> i) & 1) == 1)
					{
						if(maxHeight >= buildings[i])
						{
							cost += maxHeight - buildings[i] + 1;
							maxHeight++;
						}
						else
						{
							maxHeight = buildings[i];
						}
					}
					else if(maxHeight < buildings[i])
					{
						maxHeight = buildings[i];
					}
				}

				min = Math.Min(min, cost);
			}

			Console.WriteLine(min);
		}
	}
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){

    ll h;
    cin>>h;

    ll ans=0;
    ll monster=1;
    while(h>0){
        ans+=monster;
        h/=2;
        monster*=2;
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

vector<ll> vcand;

void dfs(ll nd, ll cnt, ll now, ll bitused){
    if(cnt == nd){
        if(bitused == 0b111){
            // cout << nd << " " << cnt << " " << now << " " << bitused << endl;
            vcand.push_back(now);
        }
        return;
    }

    dfs(nd, cnt+1, 10 * now + 3, bitused | 0b001);
    dfs(nd, cnt+1, 10 * now + 5, bitused | 0b010);
    dfs(nd, cnt+1, 10 * now + 7, bitused | 0b100);
}

int main(){

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

    ll n; cin >> n;

    reps(i, 3, 10){
        dfs(i, 0, 0, 0);
    }

    // for(auto x : vcand){
    //     cout << x << endl;
    // }

    ll ans = 0;
    for(auto x : vcand){
        if(x <= n){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
using namespace std;
 
int main()
{
    int a[4],b[4],i,j,hit,blow;
    while(cin >> a[0]){
        for (i = 1 ; i < 4 ; i++){
            cin >> a[i];
        }
        for(i = 0 ; i < 4 ; i++){
            cin >> b[i];
        }
        hit = 0;
        blow = 0;
        for(i = 0 ; i < 4 ; i++){
            if(a[i] == b[i]){
                hit++;
            } else {
                for(j = 0 ; j < 4 ; j++){
                    if(a[i] == b[j]){
                        blow++;
                    }
                }
            }
             
        }
        cout << hit << " " << blow << endl;
    }
    return 0;
}

Measured memory_bytes: 1160