akhauriyash/Code-Regression huggingface dataset:
/*
[ ( ^ _ ^ ) ]
*/

import java.io.*;
import java.util.*;


public class Main {
    int INF = (int)1e9;
    long MOD = 1000000007;


    void solve(InputReader in, PrintWriter out) throws IOException {
        int n = in.nextInt();
        int m = in.nextInt();
        char wall = '#';
        char[][] g = new char[n][];
        for(int i=0; i<n; i++) {
            g[i] = in.next().trim().toCharArray();
        }
        long[][] dp = new long[n][m];
        dp[n-1][m-1] = 1;
        for(int i=n-2; i>=0; i--) {
            if(g[i][m-1]==wall) break;
            dp[i][m-1] = 1;
        }
        for(int j=m-2; j>=0; j--) {
            if(g[n-1][j]==wall) break;
            dp[n-1][j] = 1;
        }
        for(int i=n-2; i>=0; i--) {
            for(int j=m-2; j>=0; j--) {
                if(g[i][j]!=wall) {
                    dp[i][j] = (dp[i+1][j]+dp[i][j+1])%MOD;
                }
            }
        }
        out.println(dp[0][0]%MOD);
    }
    

    public static void main(String[] args) throws IOException {
        if(args.length>0 && args[0].equalsIgnoreCase("d")) {
            DEBUG_FLAG = true;
        }
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;//in.nextInt();
        long start = System.nanoTime();
        while(t-- >0) {
            new Main().solve(in, out);
        }
        long end = System.nanoTime();
        debug("\nTime: " + (end-start)/1e6 + " \n\n");
        out.close();
    }
    
    static boolean DEBUG_FLAG = false;
    static void debug(String s) {
        if(DEBUG_FLAG) System.out.print(s);
    }
    
    public static void show(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
    
    static class InputReader {
        static BufferedReader br;
        static StringTokenizer st;
    
        public InputReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 36664
s=input()
if len(s)%2==0:
  
  if s[:len(s)//2]==s[len(s)//2:]:
    print("Yes")
  else:
    print("No")
else:
  if s[:len(s)//2]==s[len(s)//2+1:]:
    print("Yes")
  else:
    print("No")
    
 

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

int main(){
    string s;
    cin >> s;
    if(s=="SUN") cout << 7 << endl;
    else if(s=="MON") cout << 6 << endl;
    else if(s=="TUE") cout << 5 << endl;
    else if(s=="WED") cout << 4 << endl;
    else if(s=="THU") cout << 3 << endl;
    else if(s=="FRI") cout << 2 << endl;
    else if(s=="SAT") cout << 1 << endl;
}

Measured memory_bytes: 256
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
count = Counter(a)
kind = list(set(a))
ans_count = dict()
sum_ans = 0
for i in range(len(kind)):
    num = kind[i]
    k = count[num] 
    sum_ans += k*(k-1)//2
for i in range(n):
    ans = sum_ans
    num = a[i]
    k = count[num]
    ans -= k*(k-1) // 2
    ans += (k-1)*(k-2)//2
    print(ans)


Measured memory_bytes: 92624
s = list(input())
count_left = 0
last = s[0]
for one_color in s:
  if last != one_color:
    count_left += 1
    last = one_color

count_right = 0
last = s[-1]
for one_color in s[::-1]:
  if last != one_color:
    count_right += 1
    last = one_color

print(min(count_left, count_right))

Measured memory_bytes: 4652
#include <bits/stdc++.h>
#define MAX 2005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<ll,ll>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);
#define INT_SIZE 32
using namespace std;
 
ll gcd(ll n1,ll n2){
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent)
{
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
int arr[MAX],n;
int ans[MAX][MAX];
int msis[MAX][MAX],msis2[MAX][MAX];
int pre[MAX];
int len[MAX][MAX];
void maxSumIS(int x)
{
    int i, j, max = 0;

    for ( i = x; i < n; i++ )
        msis[x][i] = arr[i];
    for ( i = x+1; i < n; i++ )
        for ( j = x; j < i; j++ )
            if ( arr[i] > arr[j] && msis[x][i] < msis[x][j] + arr[i])
                msis[x][i] = msis[x][j] + arr[i];
 
    for ( i = x; i < n; i++ )
    {
    	ans[x][i]=ans[x][i-1];
        if ( ans[x][i] < msis[x][i] )
            ans[x][i] = msis[x][i];
    }
}
int main()
{
	csl;
	cin>>n;
	if(n<1200)
		cout<<"ABC"<<endl;
	else
		cout<<"ARC"<<endl;
}

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

using namespace std;

int main()
{
	long long n, m;
	cin >> n >> m;
	vector<int> a;
	for (long long i = 1; i * i <= m; i++) {
		if (m % i == 0) {
			a.emplace_back(i);
			a.emplace_back(m / i);
		}
	}
	sort(a.rbegin(), a.rend());

	for (int i = 0; i < a.size(); i++) {
		if (a[i] * n <= m) {
			cout << a[i] << endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long A,B,C,K;
  cin>>A>>B>>C>>K;
  for(int X=0;X<K;X++){
    long long AA=B+C;
    long long BB=A+C;
    long long CC=A+B;
    A=AA;
    B=BB;
    C=CC;
  }
  if(A-B<1000000000000000000){
    cout<<A-B<<endl;
  }
  else{
    cout<<"Unfair"<<endl;
  }
}

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

// ----------- define --------------
#define int long long
#define ii pair<int,int>
#define fi first
#define sc second
#define all(x) (x).begin(),(x).end()
// ---------------------------------

void MAIN() {
  int k; cin >> k;
  for (int i = 7 % k, ans = 1; ans <= (int)(1e6); i = (i * 10 + 7) % k, ans++) {
    if (i == 0) {
      cout << ans << '\n';
      return;
    }
  }
  cout << -1 << '\n';
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3628
#include <stdio.h>
#include <math.h>

int main(void) {
  int t1, t2;
  float a;
  scanf("%d%d", &t1, &t2);
  if(t1 > t2) {
    if(t1 - t2 < 180) a = (float)(t1 + t2) / 2;
    else a = (float)(t1 + t2 + 360) / 2;
    if(a >= 360) a -= 360;
  } else {
    if(t2 - t1 < 180) a = (float)(t1 + t2) / 2;
    else a = (float)(t1 + t2 + 360) / 2;
    if(a >= 360) a -= 360;
  }
  printf("%.1f\n", a);
  return 0;
}


Measured memory_bytes: 2752
#include <stdio.h>
#include <string.h>

char A[101], B[101], C[101];
int L[4], x, a, b, c;

int f(int i)
{
	int value = i;
	
	if(L[i] == 0) return i;
	
	if(i==1)
	{
		if(A[a] == 'b') i = 2;
		if(A[a] == 'c') i = 3;
		a++;
	}
	else if(i==2)
	{
		if(B[b] == 'a') i = 1;
		if(B[b] == 'c') i = 3;
		b++;
	}
	else if(i==3)
	{
		if(C[c] == 'a') i = 1;
		if(C[c] == 'b') i = 2;
		c++;
	}
	L[value]--;
	
	return f(i);
}

int main()
{
	scanf("%s %s %s", A, B, C);
	L[1] = strlen(A);
	L[2] = strlen(B);
	L[3] = strlen(C);

	x = f(1);
	printf("%c", x+'A'-1);
		
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n,m;
vector<int> L,R;


int main(){
    cin >> n >> m;
    for(int i=0; i<m; i++){
        int l,r;
        cin >> l >> r;
        L.push_back(l);
        R.push_back(r);
    }
    int ans = *min_element(R.begin(),R.end()) - *max_element(L.begin(),L.end()) + 1 ;
    if(ans < 0) cout << 0 << endl;
    else cout << ans << endl;
    return 0;
}


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

int main()
{
    int n;
    cin >> n ;
    int a[n][3];
    for(int i=0;i<n;i++)
    cin >> a[i][0] >> a[i][1]>> a[i][2];
    for(int i=n-2;i>=0;i--)
    {
        a[i][0]+=max(a[i+1][1],a[i+1][2]);
        a[i][1]+=max(a[i+1][0],a[i+1][2]);
        a[i][2]+=max(a[i+1][1],a[i+1][0]);
    }
    cout << max(max(a[0][0],a[0][1]),a[0][2]);
    return 0;
}

Measured memory_bytes: 4708
#include <cstdio>
#include <unordered_map>
#include <vector>
using namespace std;
using Int = int64_t;
class FastIO {
  static const int rdata_sz = (1 << 25), wdata_sz = (1 << 25);
  char rdata[rdata_sz], wdata[wdata_sz], *rb, *wb;
  char tmp_s[20];
 
public:
  FastIO() {
    fread(rdata, 1, rdata_sz, stdin);
    rb = rdata; wb = wdata;
  }
  ~FastIO() {
    fwrite(wdata, 1, wb - wdata, stdout);
  }
 
  template<typename T>
  inline void read_i(T &x) {
    bool neg = false;
    x = 0;
    while((*rb < '0' || *rb > '9') && *rb != '-') ++rb;
    if(*rb == '-') {
      neg = true;
      ++rb;
    }
    while('0' <= *rb && *rb <= '9') {
      x = 10 * x + (*rb - '0');
      ++rb;
    }
    if(neg) x = -x;
  }
 
#define pc(x) *(wb++) = x
  template<typename T>
  inline void writeln_i(T x) {
    if (x == 0) { pc('0'); pc('\n'); return; }
    if(x < 0) { pc('-'); x = -x; }
    char *t = tmp_s;
    while(x) {
      T y = x / 10;
      *(t++) = (x - y*10) + '0';
      x = y;
    }
    while(t != tmp_s) pc(*(--t));
    pc('\n');
  }
#undef pc
};
FastIO io;
int main() {
    Int N, sum = 0;
    io.read_i(N);
    vector<Int> A(N);
    unordered_map<Int, Int> cnt;
    for (auto& i : A) {
        io.read_i(i);
        cnt[i]++;
    }
    for (const auto& p : cnt) sum += p.second * (p.second - 1) / 2;
    for (int i : A) io.writeln_i(sum - cnt[i] * (cnt[i] - 1) / 2 + (cnt[i] - 1) * (cnt[i] - 2) / 2);
}

Measured memory_bytes: 11080
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        HashSet<Integer> set = new HashSet<Integer>();
        for (int i = 0; i <= 9 ; i++) {

            for (int j = 0; j <= 9 ; j++) {

                set.add(i * j);

            }

        }

        int x = in.nextInt();
        if (set.contains(x)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }

}


Measured memory_bytes: 23124
import java.util.*;
import java.io.*;

public class Main {
	static final Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		int x = sc.nextInt();
		String s = sc.next();
		int y = sc.nextInt();
		
		if (s.equals("+")) {
			System.out.println(x + y);
		} else {
			System.out.println(x - y);
		}
	}

}


Measured memory_bytes: 35668
<?php
fscanf(STDIN, "%d %d %d %d", $a, $b, $h, $m);

$angle = abs($m*6 - ((30 * $h) + (30 * $m / 60)));
echo sqrt($a*$a + $b*$b - 2*$a*$b*cos(deg2rad($angle)));
?>


Measured memory_bytes: 16628
#include<bits/stdc++.h>
using namespace std;
string a,b;
int dp[3010][3010];

int f(int i , int j){
    if(i >= (int)a.size() or j >= (int)b.size()) return 0;
    int &e = dp[i][j];
    if(e != -1 ) return e;
    e = -1e9;
    if(a[i] == b[j]) {
        e = max( e , f(i+1 , j+1) +1)  ;
    }else{
        e = max( f(i+1 , j)  , f(i , j+1));
    }
    return e;
}

int main(){
    while(cin>>a>>b){
        memset(dp,-1,sizeof dp);
        int r = f(0,0);
        int i,j;
        i = j = 0;
        if(r == 0 ){

        }else{
            while(!(i >= (int)a.size() or j >= (int)b.size())){
                if(a[i] == b[j]){
                    cout<<a[i];
                    i++;
                    j++;
                }
                else{
                    if(dp [i+1][j] > dp[i][j+1]){
                        i++;
                    }else{
                        j++;
                    }
                }
            }
        }
        cout<<"\n";
    
    }
    return 0;
}

Measured memory_bytes: 39280
#include<cmath>
#include<vector>
#include<climits>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<unordered_map>
using namespace std;

#define ld long double
#define ll long long int
#define pb push_back
#define mp make_pair
#define M 1000000007
#define f(i,a,b) for(int i=a;i<b;i++)

const int N=200;

struct hash_pair{
	template <class T1, class T2>
	size_t operator()(const pair<T1, T2>& p) const{
		auto hash1 = hash<T1>{}(p.first);
		auto hash2 = hash<T2>{}(p.second);
		return hash1 ^ hash2;
	}
};

void sieve(){
	bool prime[N+1];
	memset(prime,true,sizeof(prime));
	for(int p=2;p*p<=N;p++){
		if(prime[p] == true){
			for(int i=p*p;i<=N;i+=p)
				prime[i] = false;
		}
	}
}

ll power(ll x,ll y,ll p){
	ll res = 1;
	x = x%p;
	while(y > 0){
		if(y&1)
			res = (res*x)%p;
		y = y>>1;
		x = (x*x)%p;
	}
	return res;
}

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

	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif

	int n,m,a,b;
	cin>>n>>m;
	int A[n];
	bool check = true;
	memset(A,-1,sizeof(A));
	for(int i=0;i<m;i++){
		cin>>a>>b;
		a--;
		if(A[a] == -1 || A[a] == b)
			A[a] = b;
		else
			check = false;
	}
	if(check == false)
		cout<<-1;
	else{
		if(n == 1)
			cout<<max(A[0],0);
		else{
			if(A[0] == 0)
				check = false;
			else if(A[0] == -1)
				A[0] = 1;
			if(check == false)
				cout<<-1;
			else{
				for(int i=0;i<n;i++)
					cout<<max(0,A[i]);
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
enum Query
{
    pushBack = 0,
    randomAccess = 1,
    popBack = 2,
};
std::istream &operator>>(std::istream &is, Query &i)
{
    int tmp;
    if (is >> tmp)
        i = static_cast<Query>(tmp);
    return is;
} //オペレーターオーバーロード
int main()
{
    vector<int> v;
    int q;
    cin >> q;

    for (int i = 0; i < q; i++)
    {
        int query;
        cin >> query;
        if (query == pushBack)
        {
            int x;
            cin >> x;
            v.push_back(x);
        }
        else if (query == randomAccess)
        {
            int p;
            cin >> p;
            cout << v[p] << endl;
        }
        else if (query == popBack)
        {
            v.pop_back();
        }
    }
}


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

int main() {
  int H,M,h,m,K;
  cin >> H >> M >> h >> m >> K;
  h -= H;
  m -= M;
  if (h > 0){
    m += h *60;
  }
  m -= K;
  cout << m << endl;
}

Measured memory_bytes: 3636
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    d = ni()
    ans = 'Christmas'
    num = 25 - d
    eve = ' Eve'
    print(ans + num * eve)


if __name__ == '__main__':
    main()


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

int main()
{
  int N;
  cin>>N;
  vector<pair<int,int>> N_A(N);
  for(int i=0;i<N;i++)
  {
    cin>>N_A[i].first;
    N_A[i].second=i+1;
    //cout<<N_A[i].first<<N_A[i].second<<endl;
  }
  sort(N_A.begin(),N_A.end());
    for(int i=0;i<N;i++)
    {
     cout<<N_A[i].second<<" ";
    }
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;


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

    int score = 0;
    rep(i,N-1){
        if (S[i]==S[i+1]) score++;
    }

    int ans = min(score+2*K, N-1);

    cout << ans << endl;

}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
pii a[125252];

int main(){
  scanf("%d",&n);
  REP(i,n)scanf("%d",&a[i].first);
  REP(i,n)a[i].second = 0;
  int base = 1<<30;
  int ans = 0;
  REP(_,30){
    base>>=1;
    sort(a,a+n);
    int x = lower_bound(a,a+n,pii(base,0))-a;
    if((n-x)%2==1){
      // should eat
      bool flag = false;
      FOR(i,x,n){
        if(a[x].first!=base){
          puts("-1");
          return 0;
        }
        if(a[x].second==0){
          a[x].first--;
          a[x].second = 1;
          x++;
          ans++;
          flag = true;
          break;
        }
      }
      if(!flag){
        puts("-1");
        return 0;
      }
    }
    FOR(i,x,n)a[i].first^=base;
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

ll INF = -4e18;
ll n, m;
ll u[2005], v[2005], w[2005];
ll a[1005];

int main()
{
    //freopen("input.txt", "r", stdin);
    scanf("%lld%lld", &n, &m);
    for(ll i = 1; i <= n; i++) a[i] = INF;
    a[1] = 0;
    for(ll i = 0; i < m; i++)
    {
        scanf("%lld%lld%lld", &u[i], &v[i], &w[i]);
    }
    for(ll i = 0; i < n; i++)
    {
        for(ll j = 0; j < m; j++)
        {
            if(a[u[j]] != INF) if(a[v[j]] < a[u[j]] + w[j]) a[v[j]] = a[u[j]] + w[j];
        }
    }
    ll t = a[n];
    for(ll j = 0; j < m; j++)
    {
        if(a[u[j]] != INF) if(a[v[j]] < a[u[j]] + w[j]) a[v[j]] = a[u[j]] + w[j];
    }
    if(t < a[n])
    {
        printf("inf");
    }
    else
    {
        printf("%lld", a[n]);
    }
    return 0;
}


Measured memory_bytes: 256
import Control.Monad
import qualified Data.Map as M
main = do
    [h, w] <- map read . words <$> getLine 
    gridMap <- toMap h w <$> replicateM h getLine
    putStrLn $ if and [check gridMap i j|i<-[1..h],j<-[1..w]] then "Yes" else "No"

toMap h w xss = toMap' h w 1 1 xss
  where
    toMap' h w _ _ [] = M.fromList [((i,j),'.')|i<-[0..h+1],j<-[0..w+1],i==0||i==h+1||j==0||j==w+1]
    toMap' h w i j ([]:xss) = toMap' h w (i+1) 1 xss
    toMap' h w i j ((x:xs):xss) = M.insert (i,j) x (toMap' h w i (j+1) (xs:xss))

check g i j | ij == '.' = True
            | any (=='#') neighbors = True
            | otherwise = False
    where ij = g M.! (i,j)
          neighbors = map (g M.!) [(i-1, j), (i+1, j), (i, j-1), (i, j+1)]

Measured memory_bytes: 1404
from math import factorial
n,m = map(int,input().split())

if n == 0:
   N = 0
elif n == 1:
    N = 0
else:
    N = factorial(n)/factorial(2)/factorial(n-2)
if m == 0:
   M = 0
elif m == 1:
    M = 0
else:
    M = factorial(m)/factorial(2)/factorial(m-2)

print(int(N+M))


Measured memory_bytes: 3060
//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<string>
#include<cstdlib>
#include<bitset>
#include<sstream>
#include<queue>
#include<stack>
#include<list>
#include<limits>
#include<iomanip>

using namespace std;

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

#define Max 1000001
#define intinf 2147483647
#define longlonginf 9223372036854775807
#define MOD 998244353
#define MOD2 1000000007
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define vint vector<int>
#define vll vector<long long>
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define F(i,n) for(int i = 0;i<n;i++)
#define Fr(i,l,r) for(int i = l;i <= r;i++)
#define rF(i,n) for(int i = n-1;i>=0;i--)


//#define min(a,b) a>b?b:a
//#define max(a,b) a>b?a:b
#define all(arr) arr.begin(),arr.end()
//#define sort(vec) sort(vec.begin(),vec.end())
//#define reverse(vec) reverse(vec.begin(),vec.end())


ll Lpow(ll a,ll b)
{
    ll ans = 1;
    while(b > 0)
    {
        if(b%2)
            ans = (ans*a);
        a = (a*a);
        b = b/2;
    }
    return ans;
}

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

ll dp[100005];
vector<vector<int>> adj(100005);

void dfs(int node)
{
    for(auto x : adj[node])
    {
        if(dp[x] == -1)
            dfs(x);
        dp[node] = max(dp[node],dp[x]);
    }
    dp[node]++;
}

signed main()
{
    fastio;
    
    int n,m;
    cin >> n >> m;
    
    for(int i = 1;i<=100000;i++)
        dp[i] = -1;
    
    int a,b;
    F(i,m)
    {
        cin >> a >> b;
        adj[a].push_back(b);
    }
    
    for(int i = 1;i<=n;i++)
    {
        if(dp[i] == -1)
            dfs(i);
    }
    
    ll ans = 0;
    for(int i = 1;i<=n;i++)
    {
        ans = max(ans,dp[i]);
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 8576
import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner();
		PrintWriter out = new PrintWriter(System.out);
		long sum=0;
		char []s=sc.next().toCharArray();
		for(char c:s)
			sum+=c-'0';
		out.println(sum%9==0?"Yes":"No");
		out.close();

	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		Scanner(String fileName) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(fileName));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		String nextLine() throws IOException {
			return br.readLine();
		}

		int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}

		boolean ready() throws IOException {
			return br.ready();
		}

		int[] nxtArr(int n) throws IOException {
			int[] ans = new int[n];
			for (int i = 0; i < n; i++)
				ans[i] = nextInt();
			return ans;
		}

	}

	static void sort(int[] a) {
		shuffle(a);
		Arrays.sort(a);
	}

	static void shuffle(int[] a) {
		int n = a.length;
		Random rand = new Random();
		for (int i = 0; i < n; i++) {
			int tmpIdx = rand.nextInt(n);
			int tmp = a[i];
			a[i] = a[tmpIdx];
			a[tmpIdx] = tmp;
		}
	}

}


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

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

using namespace std;
using ll = long long;
int mod = 1000000007;

int main(void){
    vector<int> val_list;
    int N, T; cin >> N >> T;
    int A[N+1], B[N+1];
    A[0] = 0; B[0] = 0;
    rep(i, N){
        cin >> A[i+1] >> B[i+1];
    }
    
    pair<pair<int, int>, int> dp[N+1][T]; //遷移元と美味しさのpair
    rep(i, N+1) rep(j, T) dp[i][j] = make_pair( make_pair(0, 0), 0);
    for(int i = 1; i <= N; i++){
        int a = A[i]; int b = B[i];
        for(int j = 0; j < T; j++){
            if(j-a >= 0){
                if(dp[i-1][j].second < dp[i-1][j-a].second + b){
                    dp[i][j] = make_pair(make_pair(i-1, j-a), dp[i-1][j-a].second + b);
                }
                else dp[i][j] = make_pair(make_pair(i-1, j), dp[i-1][j].second);
            }
            else{
                dp[i][j] = make_pair(make_pair(i-1, j), dp[i-1][j].second);
            }
        }
    }
    //cout << "reach" << endl;
    pair<int, int> nl = make_pair(0,0);
    pair<pair<int, int>, int> op = dp[N][T-1];
    while(op.first != nl){
        if(dp[op.first.first][op.first.second].second != op.second){
            val_list.push_back(op.second - dp[op.first.first][op.first.second].second);
        }
        op = dp[op.first.first][op.first.second];
    }
    sort(val_list.begin(), val_list.end(), greater<int>());
    sort(B, B+N+1, greater<int>());
    rep(i, val_list.size()+1){
        if(i == val_list.size()){
            cout << dp[N][T-1].second + B[i] << endl;
            return 0;
        }
        if(val_list[i] != B[i]){
            cout << dp[N][T-1].second + B[i] << endl;
            return 0;
        }
    }
    cout << dp[N][T-1].second << endl;
    return 0;
}

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

int N;
int A[1000000];

int main(){
	scanf("%d",&N);
	for(int i = 0; i <N; i++){
		scanf("%d",&A[i]);
	}
	long long sm = 0;
	for(int i = 1; i < N; i++){
		if(A[i] < A[i-1]){
			sm += A[i-1] - A[i];
			A[i] = A[i-1];
		}
	}
	printf("%lld\n",sm);
	return 0;
}


Measured memory_bytes: 4608
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in(),M=in();
	
	out(N*(N-1)/2+M*(M-1)/2);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	REP(i, N) scanf("%d", &A[i]);
	
	int idx = min_element(ALL(A)) - A.begin();
	
	int ans = 0;
	// front idx 個
	int d = (idx + K - 2) / (K - 1);
	ans += d;
	int last = d * (K - 1) + 1;
	
	// back N - idx - 1 個
	ans += (N - last + K - 2) / (K - 1);
	cout << ans << endl;
	return 0;
}


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

int main(){
  int n;
  int p[101] = {};
  cin >> n;
  for(int i=1; i <= n; i++){
    int a;
    cin >> a;
    p[a]++;
  }
  int m = 0;
  int ans;
  for(int i=100; i > 0 ; i--){
    m += p[i];
    if(m >= i){
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3108
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cout << #x << ": " << x << ", "
#define debugln(x) cout << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const int mod = 1e9+7;

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

  int n; cin >> n;
  int t, a; cin >> t >> a;

  double mi = 999999999;
  int pos = -1;

  rep(i, n) {
    int h; cin >> h;
    double now = (double)-0.006*h+t-a;
    if (now < 0) {
      now = -now;
    }
    if (now < mi) {
      pos = i;
      mi = now;
    }
  }
  cout << pos+1 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define int long long

int N;

int check(int m){
	if(m == 0){
		return 0;
	}
	else if(N / m == N % m){
		return m;
	}
	else{
		return 0;
	}
}

signed main(){
	int i, j, ans = 0;
	scanf("%lld", &N);
	for(i = 1; i * i <= N; i++){
		if(N % i == 0){
			ans += check(i - 1);
			j = N / i;
			if(i != j){
				ans += check(j - 1);
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
// Package main provides
//
// File:  d.go
// Author: ymiyamoto
//
// Created on Tue Dec 25 02:07:30 2018
//
package main

import "fmt"

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var N, C int
	fmt.Scan(&N, &C)

	D := make([][]int, C)
	for i := range D {
		D[i] = make([]int, C)
		for j := range D[i] {
			fmt.Scan(&D[i][j])
		}
	}

	m1 := map[int]int{}
	m2 := map[int]int{}
	m3 := map[int]int{}
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			var c int
			fmt.Scan(&c)
			c--
			switch (i + j) % 3 {
			case 0:
				m1[c]++
			case 1:
				m2[c]++
			case 2:
				m3[c]++
			}
		}
	}

	ans := 1 << 60
	for ci := 0; ci < C; ci++ {
		for cj := 0; cj < C; cj++ {
			for ck := 0; ck < C; ck++ {
				if ci == cj || cj == ck || ck == ci {
					continue
				}
				tmp := 0
				for k, v := range m1 {
					tmp += v * D[k][ci]
				}
				for k, v := range m2 {
					tmp += v * D[k][cj]
				}
				for k, v := range m3 {
					tmp += v * D[k][ck]
				}
				ans = min(ans, tmp)
			}
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 5504
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a < b ? a : b)
const int inf = 1000000000; // 10^9

int main(){
   int n;scanf("%d",&n);
   for(int i = 0;;i++){
      if(i*i>n){printf("%d\n",(i-1)*(i-1));return 0;}
   }
}

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

struct fentree {
  vector<int> bit;
  int n;

  fentree(int n) {
    this->n = n;
    bit.assign(n, 0);
  }

  fentree(vector<int> a) : fentree(a.size()) {
    for (size_t i = 0; i < a.size(); ++i) 
      add(i, a[i]);
  }

  int sum(int r) {
    if (r < 0)
      return 0;
    int ret = 0;
    for (; r >= 0; r = (r & (r + 1)) - 1)
      ret += bit[r];
    return ret;
  }

  void add(int idx, int delta) {
    for (; idx < n; idx = idx | (idx + 1))
      bit[idx] += delta;
  }
};

int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  fentree ft(4141);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    ft.add(a[i], 1);
  }
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int x = a[i], y = a[j];
      ft.add(x, -1);
      ft.add(y, -1);
      if (x + y >= abs(x - y) + 1) {
        ans += ft.sum(x + y - 1);
        ans -= ft.sum(abs(x - y));
      }
      ft.add(x, 1);
      ft.add(y, 1);
    }
  }
  printf("%lld\n", ans / 3);
  return 0;
}

Measured memory_bytes: 256
nk = gets.chomp.split
n = nk[0].to_i
k = nk[1].to_i

h = gets.chomp.split
n.times do |i|
  h[i] = h[i].to_i
end

h.sort!

k.times do
  h.pop
end

attack_count = 0
h.each do |hp|
  attack_count += hp
end

puts attack_count

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

if K == 0:
    if S == 10 ** 9:
        ans = [S - 1] * N
    else:
        ans = [S + 1] * N
elif K == N:
    ans = [S] * N
else:
    ans = [S] * N
    if S - (N - K) >= 2:
        ans[0] = S - (N - K)
        for i in range(1, N - K + 1):
            ans[i] = 1
    else:
        for i in range(K, N):
            ans[i] = 10 ** 9
        


print (*ans)


Measured memory_bytes: 6684
#include <math.h>
#include <ctype.h>
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define REP(i, n) for(int i = 0; i < n; i++)
struct omt{omt(){ios::sync_with_stdio(false);cin.tie(0);}}star;

int main(){
    string op[3] = {"+", "-", "*"};
    stack<int> st;
    
    string s;
    while(cin >> s){
        int f = 0, idx;
        REP(i, 3){
            if(s == op[i]){
                f = 1;
                idx = i;
                break;
            }
        }
        if(f){
            int a, b, tmp;
            a = st.top();
            st.pop();
            b = st.top();
            st.pop();
            if(op[idx] == "+") tmp = b + a;
            else if(op[idx] == "-") tmp = b - a;
            else if(op[idx] == "*") tmp = b * a;
            st.push(tmp);
        }else st.push(stoi(s));
    }
    cout << st.top() << endl;

    return 0;
}


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

using namespace std;

vector<vector<int>> G;
vector<int> colors;
unordered_map<int64_t, int> edge_index_map;

int64_t V(int64_t a, int64_t b) {
  if (a > b) swap(a, b);
  return a << 20 | b;
}

int64_t EdgeIndex(int64_t a, int64_t b) { return edge_index_map[V(a, b)]; }

void dfs(int from, int to, int color) {
  colors[EdgeIndex(from, to)] = color;

  int next_color = 1;
  if (next_color == color) next_color++;
  for (int v : G[to]) {
    if (v == from) continue;

    dfs(to, v, next_color);

    next_color++;
    if (next_color == color) next_color++;
  }
}

int main() {
  int N;
  cin >> N;
  G.resize(N);
  colors = vector<int>(N, 0);
  for (int i = 0; i < N - 1; i++) {
    int64_t A, B;
    cin >> A >> B;
    A--;
    B--;
    if (A > B) swap(A, B);
    G[A].push_back(B);
    G[B].push_back(A);
    edge_index_map[V(A, B)] = i;
  }

  int K = 0;
  for (int v = 0; v < N; v++) {
    K = max(int(G[v].size()), K);
  }

  dfs(0, G[0][0], 1);
  dfs(G[0][0], 0, 1);

  cout << K << endl;
  for (int i = 0; i < N - 1; i++) {
    cout << colors[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 10636
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int r = scn.nextInt();
      	int ans = 0;
      	if(n>=10) ans = r;
      	if(n<10) ans = r + 100*(10-n);
      	System.out.println(ans);
	}
}


Measured memory_bytes: 35652
import fractions
a,b,c,d = map(int,input().split())
e = c * d // fractions.gcd(c,d)

c_count = b // c - (a - 1) // c
d_count = b // d - (a - 1) // d
e_count = b // e - (a - 1) // e

ans = b - a + 1 - c_count - d_count + e_count
print(ans)

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

using namespace std;

int main()
{
    int n, temp;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++)
    {
        a[i] = 0;
    }
    for (int i = 0; i < n - 1; i++)
    {
        cin >> temp;
        a[temp - 1]++;
    }
    for (int i = 0; i < n; i++)
    {
        cout << a[i] << endl;
    }
    // cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 4420
inf = 10**9
n, m, x = map(int, input().split())
a = [0] * n
c = [0] * n
y = [0] * n
for i in range(n):
    data = list(map(int, input().split()))
    c[i] = data[0]
    a[i] = data[1:]
ans = inf
for i in range(2**n):
    lis = [0]*n
    money = 0
    know = [0] * m
    for j in range(n):
        if (i >> j) & 1:
            money += c[j]
            for l in range(m):
                know[l] += a[j][l]
    for z in know:
        if z < x:
            break
    else:
        ans = min(ans, money)

if ans == inf:
    print(-1)
else:
    print(ans)

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

#define PI 3.14159265
#define ll long long
#define hell 1e9
   
    
 
int main(){
	int n;
	cin>>n;
	int a[n],b[n],c[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		cin>>b[i];
	}
	for(int i=0;i<n-1;i++){
		cin>>c[i];
	}
	int ans=0;
	for(int i=0;i<n;i++){
		ans+=b[i];
	}
	for(int i=0;i<n-1;i++){
		if(a[i]+1==a[i+1]){
			ans+=c[a[i]-1];
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

//smaller names
#define int long long
#define double long double
#define Int signed
#define vi vector<int>
#define vvi vector<vi>
#define vd vector<double>
#define vvd vector<vd>
#define pii pair<int, int>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define mii map<int, int>
#define unordered_map gp_hash_table

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, b) for(int i = a; i < b; i++)
#define repd2(i, a, b) for(int i = b - 1; i >= a; i--)
#define repd(i, n) for(int i = n-1; i >= 0; i--)

#define F first
#define S second

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(v) v.begin(),v.end()

const int INF = 1e9;
const double EPS = 1e-9;
const double PI = acosl(-1);

//order_of_key(k) - number of elements e such that func(e, k) returns true, where func is less or less_equal
//find_by_order(k) - kth element in the set counting from 0

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

typedef tree <
    int,
    null_type,
    less_equal<int>,
    rb_tree_tag,
    tree_order_statistics_node_update
>
ordered_multiset;

const int mod = 1e9 + 7;
const int maxn = 2e5 + 5;
const int maxa = 1e6 + 5;
const int logmax = 25;

//fast exponentiation

template <typename T>
T power (T a, int n = 1, T id = 1) {
    T ans = id;
    while(n) {
        if(n & 1) ans *= a;
        a *= a;
        n >>= 1;
    }
    return ans;
}

//custom hash

struct custom_hash {
    // http://xorshift.di.unimi.it/splitmix64.c
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int sumdigs (int n) {
    int ans = 0;
    while (n) {
        ans += n % 10;
        n /= 10;
    }
    return ans;
}


void solve() {
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    int x = 0;
    for(int i = 2; i < n; i++){
        x ^= a[i];
    }
    int s = a[0] + a[1];
    if((s - x) & 1) {
        cout << -1 << endl;
        return;
    }
    int d = (s - x) / 2;
    if(d < 0 || d > a[0] || d & x){
        cout << -1 << endl;
        return;
    } 
    int m = 1LL << 40;
    int w = 41;
    rep(i, 41){
        if(m & x) {
            if(d + m <= a[0]) d += m;
        }
        m >>= 1;
    }
    if(d <= 0) {
        cout << -1 << endl;
        return;
    }
    cout << a[0] - d << endl;
}

signed main(){
    fastio;
    cout << setprecision(6) << fixed;
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 3648
using System;
using System.IO;
using System.Linq;

namespace AtCoder {
    class abc051b {
        static void Main(){
            var arr = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

            int x = arr[2] - arr[0];
            int y = arr[3] - arr[1];

            Console.Write(new string('U', y));
            Console.Write(new string('R', x));
            Console.Write(new string('D', y));
            Console.Write(new string('L', x));

            Console.Write('L');
            Console.Write(new string('U', y+1));
            Console.Write(new string('R', x+1));
            Console.Write('D');
            Console.Write('R');
            Console.Write(new string('D', y+1));
            Console.Write(new string('L', x+1));
            Console.Write('U');
            Console.WriteLine("");
        }
    }
}


Measured memory_bytes: 3032
#include<iostream>
#include<vector>

using namespace std;

int n, q;
int parent[10009], root[10009];

void init(int n){
  for(int i=0;i<n;i++){
    parent[i] = i;
    root[i] = i;
  }
}

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

void unite(int x, int y){
  if(find_root(x) == find_root(y))return;
  root[find_root(y)] = find_root(x); 
};

bool same(int x, int y){
  return find_root(x) == find_root(y);
};

int main(){
  cin >> n >> q;
  init(n);
  for(int i=0;i<q;i++){
    int com, x, y;
    cin >> com >> x >> y;
    if(com == 0){
      unite(x, y);
    }
    else if(com == 1){
      cout << (same(x, y)?'1': '0') << endl;
    }
  }
}



Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9


int main(){
	int n,k;
	cin>>n>>k;
	int sum = 0;
	int h = 0;
	int y = 1;
	while(n-y>=0){
	//	cout<<n<<endl;
		if((double)sum/y <= k){
			sum+=y;
			n-=y;
			h++;
		}else{
			while( ( (double) sum/y) > (double)k){
				y++;
			//	cout<<y<<' '<<k<<endl;	
			}
			n-=y;
			if(n < 0) break;
			sum+=y;
			h++;	
		}

	}
	cout<<h<<endl;


	return 0;
}



Measured memory_bytes: 3104
N,M=map(int,input().split())
c=[0]*(M+1)
for _ in range(N):
    KA=list(map(int,input().split()))
    for i in range(1,KA[0]+1):
        c[KA[i]]+=1
cnt=0
for i in range(1,M+1):
    if c[i]==N:
        cnt+=1
print(cnt)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define sz(x) ((int)(x).size())
#define rep(i,a,b) for (int i=(a); i<(b); i++)
#define per(i,a,b) for (int i=(b-1); i>=(a); i--)
#define debug(x) cout << #x << " => " << x << endl
using namespace std;

#define fi first
#define se second
#define mp make_pair
typedef pair<int,int> pii;

#define pb push_back
typedef vector<int> vi;

typedef long long ll;
typedef long double ld;

const int MAX_N = 7 + 100000;
///----------------------------------------------
int dig[MAX_N];
int nex[MAX_N][20];
int main() {

	//read
	int n; cin>>n;
	rep(i,0,n) scanf("%d",&dig[i]);
	int L; cin>>L;
	

	///prework
	int tmp=0;
	rep(i,0,n) {
		for (; tmp+1<n&&dig[tmp+1]-dig[i]<=L; tmp++);
		nex[i][0]=tmp;
	}
	rep(j,1,18) rep(i,0,n) 
		nex[i][j] = nex[nex[i][j-1]][j-1];
	
	//rep(i,0,n) debug(nex[i][0]);

	//work
	int qn; cin>>qn;
	rep(i,0,qn) {
		int a,b; scanf("%d%d",&a,&b);
		if (a>b) swap(a,b); a--; b--;
		int ans=1;
		per(j,0,18) if (nex[a][j]<b) {
			ans+=1<<j;
			a=nex[a][j];
			//debug(a);
		}
		printf("%d\n",ans);
	}



}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef long double ld;
#define A 1000000007
#define D 100000000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define M 4000
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<pair<ll,ll>, null_type,less_equal<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" 

int main() 
{
    FAST;
    ll n;
    cin>>n;
    ll a[n];
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if((a[i]&1) &&((i+1)&1))
            ans++;
    }
    cout<<ans;
    subt;
    return 0;
}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % 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; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i, N) cin >> A[i];

  int ind_1 = 0;
  rep(i, N){
    if(A[i]==1){
      ind_1 = i;
    }
  }

  int ans = 1e8;
  for(int i = 0; i + K - 1< N; i++){

    int left = i;
    int right = i + K-1;
    
    if(!(left<=ind_1 && ind_1 <= right)) continue;

    int tmp_ans = 1;

    tmp_ans += (left + K -1 -1) / (K-1);
    tmp_ans += (N-1-right + K - 1 -1) / (K-1);

    chmin(ans, tmp_ans);

  }

  cout << ans  << endl;


  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
using namespace std;

int main(){
    int N,A,B,C;
    int L[8]={};
    cin>>N>>A>>B>>C;
    for(int i=0;i<N;i++) cin>>L[i];
    int ans=1000000;
    for(int comb=0;comb<(1<<(2*N));comb++){
        int take[3]={};
        int mp=0;
        for(int i=0;i<N;i++){
            int t = ((comb>>(i*2))&3);
            if(t==3) continue;
            if(take[t]!=0){
                take[t]+=L[i];
                mp+=10;
            }else{
                take[t]=L[i];
            }
        }
        if(take[0]&&take[1]&&take[2]){
            mp+=abs(take[0]-A);
            mp+=abs(take[1]-B);
            mp+=abs(take[2]-C);
            ans=min(ans,mp);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <map>
#include <queue>
#include <cstring>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	ll h,w; cin >> h >> w;
	if(h==1||w==1){
		cout << 1 << endl;
		return 0;
	}
	cout << h/2*w+(h%2)*((w+1)/2) << endl;
}


Measured memory_bytes: 256