akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string.h>
#include<queue>
#include<map>
#include<vector>
#include <cstdlib>
#include<algorithm>
#include <cstdio>
#include <cctype>
using namespace std;
const long long INF=10000000000000LL;
typedef long long ll;
typedef pair<ll,ll> P;
ll N,M,K=1;
ll T,a,b;
ll A,B,C,Q,l,r;
ll D[100005]={};
ll S[100005]={};
string str;
map<string,int> m;

int main(){
	for(int i=2;i<100000;++i)D[i]=1;
	for(int i=2;i<100000;i++){
		if(D[i]==0)continue;
		for(int j=i+i;j<100000;j+=i){
			D[j]=0;
		}
	}
	D[1]=0;
	for(int i=1;i<=100000;++i){
		if(D[(i+1)/2]==1&&D[i]==1)S[i]++;
		S[i]+=S[i-1];
	}
	cin>>Q;
	for(int i=0;i<Q;++i){
		cin>>l>>r;
//		for(int j=l;j<=r;++j){
//			cout<<S[j]<<endl;
//		}
		cout<<S[r]-S[l-1]<<endl;
	}
	return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;

#define int long long
signed main(){
//int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.rbegin(),a.rend());

    int ans=0;
    for(int i = 0; i < n/2; i++) ans+=a[i];
    for(int i = n/2; i < n; i++) ans-=a[i];
    ans*=2;
    ans+=a[n/2];
    if(n%2) ans+=a[n/2+1];
    else ans-=a[n/2-1];

    sort(a.begin(),a.end());
    int rans=0;
    for(int i = 0; i < n/2; i++) rans+=a[i];
    for(int i = n/2; i < n; i++) rans-=a[i];
    rans*=2;
    rans+=a[n/2];
    if(n%2) rans+=a[n/2+1];
    else rans-=a[n/2-1];
    rans*=-1;

    ans=max(rans,ans);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3940
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll h, w, k;
    cin >> h >> w >> k;
    vector<string> c(h);
    rep(i, h) cin >> c[i];
    vll ch(h), cw(w);
    ll call = 0;
    for(ll i = 0; i < h; i++) {
        for(ll j = 0; j < w; j++) {
            if(c[i][j] == '#') {
                ch[i]++;
                cw[j]++;
                call++;
            }
        }
    }
    ll ans = 0;
    for(ll i = 0; i < (1 << h); i++) {
        ll cminus = 0;
        for(ll i2 = 0; i2 < h; i2++) {
            if(i & (1 << i2)) cminus += ch[i2];
        }
        for(ll j = 0; j < (1 << w); j++) {
            ll cminus2 = cminus;
            for(ll j2 = 0; j2 < w; j2++) {
                if(j & (1 << j2)) cminus2 += cw[j2];
            }
            for(ll i2 = 0; i2 < h; i2++) {
                for(ll j2 = 0; j2 < w; j2++) {
                    if((i & (1 << i2)) && (j & (1 << j2)) && c[i2][j2] == '#') {
                        cminus2--;
                    }
                }
            }
            if(call - cminus2 == k) ans++;
        }
    }
    cout << ans << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 3656
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# Summarize count of factor within list -- START --
def summarizeList(l):
  sl=sorted(l)

  a=sl[0]
  c=1
  res=[]

  for x in sl[1:]:
    if x==a:
      c+=1
    else:
      res.append([a,c])
      a=x
      c=1
  res.append([a,c])

  return res
# Summarize count of factor within list --- END ---

def main():
  s=S()
  n=len(s)
  s=s[::-1]

  rl=[0]*(n+1)
  for i,x in enumerate(s):
    rl[i+1]=(int(x)*pow(10,i,2019))%2019

  for i in range(n):
    rl[i+1]+=rl[i]
    rl[i+1]%=2019


  sl=summarizeList(rl)
  # print(sl)

  ans=0
  for x,c in sl:
    ans+=(c*(c-1))//2

  return ans

# main()
print(main())


Measured memory_bytes: 21352
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define sz(x) (int)(x).size()
#define _USE_MATH_DEFINES
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin >> n;
    if (n == 1 || n == 2 || n == 3 || n == 5 || n == 6 || n == 9 || n == 10 || n == 13 || n == 17)
        cout << "No";
    else
        cout << "Yes";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define REP(i,n) for (int i = 0; i < n; ++ i)
#define FOR(i,a,b) for (int i = a; i <= b; ++ i)
#define FORD(i,b,a) for (int i = b; i >= a; -- i)
#define debug(x) cerr << #x << ": " << x << "\n"
#define task "0"
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> li;
typedef vector<int> vi;

const int N = 105;
int a, b, f[N][N];
bool ok(int i, int j) {
	if (i > 1 && f[i-1][j] != f[i][j]) return false;
	if (i < 100 && f[i+1][j] != f[i][j]) return false;
	if (j > 1 && f[i][j-1] != f[i][j]) return false;
	if (j < 100 && f[i][j+1] != f[i][j])  return false;
	return true;
}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	//freopen(task".inp", "r", stdin);
	//freopen(task".out", "w", stdout);
	cin >> a >> b;
	a --; b--;
	FOR(i, 1, 50) FOR(j, 1, 100) f[i][j] = 1;
	for (int i = 1; i <= 50 && a > 0; i += 2) {
		for (int j = 1; j <= 100 && a > 0; j += 2) {
			f[i][j] = 0;
			a--;
		}
	}
	for (int i = 52; i <= 100 && b > 0; i += 2) {
		for (int j = 1; j <= 100 && b > 0; j += 2) {
			f[i][j] = 1;
			b--;
		}
	}
	cout << "100 100\n";
	FOR(i, 1, 100) {
		FOR(j, 1, 100) cout << (f[i][j] ? '#' : '.');
		cout << "\n";
	}
}


Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>
 
int main(void){
 
  char ch;
 
  while(1){
    scanf("%c",&ch);
    if(ch == '\n'){
      break;
    }
    if(islower(ch)){
      ch = toupper(ch);
      printf("%c",ch);
    }else if(isupper(ch)){
      ch = tolower(ch);
      printf("%c",ch);
    }else{
      printf("%c",ch);
    }
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 524
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, d;  cin >> n >> d;
    int ans = 0;
    vector<int> tree(n);
    while (tree[n - 1] == 0) {
      int left;
      for (left = 0; left < n; ++left) {
        if (tree[left] == 0) {
          break;
        }
      }
      FOR(right, left, min(left + 2 * d + 1, n)) {
        tree[right] = 1;
      }
      ans += 1;
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
    string S;
    cin >> S;
    for(int i=0;S[i]!='\0';i++){
        if(i%2==1){
            if(S[i]=='R') {
                cout << "No" << endl;
                return 0;
            }
        }
        else{
            if(S[i]=='L'){
            cout << "No" << endl;
            return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

#define rep(i,n) for(int i = 0;i<n;i++)
#define vv(Type,Name, n,m,d)vector<vector<Type>> vv(n, vector<Type>(m, d));

using namespace std;
using ll = long long;


int main(void) {

	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int k, x;
	cin >> k >> x;
	k *= 500;

	if (k >= x) cout << "Yes" << endl;
	else cout << "No" << endl;



	return 0;
}


Measured memory_bytes: 3632
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
struct node{
	int ne,tow;
};
node pth[200000+10];
int mp[100000+10],szp;
int vis[100000+10];
int n;
int deg[100000+10];
int root=-1;
int son[100000+10];
int bro[100000+10];
int dp[100000+10];
int left[100000+10];
void addpath(int i,int j){
	++szp;
	pth[szp].ne=mp[i];
	pth[szp].tow=j;
	mp[i]=szp;
	deg[i]++;
}

void dfs1(int i,int j){
	if (vis[i]!=0) return;
	vis[i]=j;
	int po=mp[i];
	while (po!=-1){
		if (vis[pth[po].tow]==0){
			bro[pth[po].tow]=son[i];
			son[i]=pth[po].tow;
		}
		dfs1(pth[po].tow,j+1);
		po=pth[po].ne;
	}	
}
void dfs2(int i){
	int j=son[i];
	if (j==-1){
		left[i]=1;
		dp[i]=1;
		return;
	}
	while (j!=-1){
		dfs2(j);
		left[i]+=left[j];
		dp[i]+=dp[j];
		j=bro[j];
	}
	j=son[i];
	if (j!=-1&&bro[j]!=-1)
	while (j!=-1){
		if (dp[j]==1&&left[j]==1){
			dp[i]--;
			return;
		}
		j=bro[j];
	}

}


int main(){
	scanf("%d",&n);
	for (int f1=0;f1<n;f1++){
		mp[f1]=-1;
		vis[f1]=0;
	}
	
	for (int f1=1;f1<n;f1++){
		int i,j;
		scanf("%d%d",&i,&j);
		addpath(i,j);
		addpath(j,i);
		if (deg[i]>2)root=i;
		if (deg[j]>2)root=j;
	}
	if (root==-1){
		printf("1\n");
		return 0;
	}
	for (int f1=0;f1<n;f1++){
		son[f1]=-1;
		bro[f1]=-1;
		left[f1]=0;
		dp[f1]=0;
	}
	dfs1(root,1);
	dfs2(root);
	printf("%d\n",dp[root]);
	//for (int f1=0;f1<n;f1++)printf("%d ",dp[f1]);
}


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

#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

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

    int N,T,A; cin >> N>>T>>A;
    vector<int> H(N); cin >> H;

    double min_diff = DBL_MAX;
    int point;
    for (int i = 0; i < N; i++) {
        double diff = fabs(A - T + H[i]*0.006);
        if (diff < min_diff) {
            min_diff = diff;
            point = i + 1;
        }
    }

    cout << point << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)


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


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

  ll cB = 0;
  ll ans = 0;
  REP(i, S.size()) {
    if (S[i] == 'B') cB++;
    if (S[i] == 'W') ans += cB;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 640
N,M=map(int,input().split())
L=[0]*N
R=[0]*N
right=0
pena=0
for _ in range(M):
    p,s=input().split()
    p=int(p)
    p-=1
    if R[p]==0:
        if s=='AC':
          right+=1
          R[p]=1
          pena+=L[p]
        else:
            L[p]+=1

print(right,pena)

Measured memory_bytes: 10320
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

using namespace std;

#define li long long int
#define ld long double
const int MX1 = 1e5 + 5;
const int MX2 = 1e6 + 5;
const li inf = 4e18;
const li mod = 1e9 + 7;

li power(li a, li b) { li res = 1; while (b) { if (b % 2) res = (res * a) % mod;
a = (a * a) % mod; b /= 2; } return res; }

li mmi(li a) { return power(a, mod - 2); }

li cntbit(li n) { li cnt = 0; while (n) { n &= (n - 1); cnt++; } return cnt; }

int n;

void solve() {
    cin >> n;
    if (n == 1) {
        cout << "Hello World";
    } else {
        int x, y;
        cin >> x >> y;
        cout << x + y;
    }
}

int main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
  int N;
  cin >> N;
  int a,w,t,r;
  a = w = t = r = 0;
  int i;
  string s;
  for(i=0;i<N;i++) {
    cin >> s;
    if(s[0] == 'A')a++;
    else if(s[0] == 'W')w++;
    else if(s[0] == 'T')t++;
    else r++;
  }
  printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n",a,w,t,r);
}

Measured memory_bytes: 3724
nu = gets.to_i
array = Array.new(nu - 1).map{Array.new(3, 0)}
for i in 0..nu - 2
  array[i] = gets.chomp.split(" ").map(&:to_i)
end
time = 0
check = 0
inst = 0
for i in 1..nu
  check = i - 1
  while check < nu - 1
    if time < array[check][1]
      time = array[check][1]
    elsif time % array[check][2] != 0
      inst = array[check][2] - (time % array[check][2])
      time += inst
    end
    time += array[check][0]
    check += 1
  end
  puts time
  time = 0
end


Measured memory_bytes: 1788
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000


S = str(input())
win = 0
for i in range(len(S)):
    if S[i] == "o":
        win += 1


if 15-len(S)+win >= 8:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 6468
<?php
list($s) = sscanf(trim(fgets(STDIN)), "%s");
list($t) = sscanf(trim(fgets(STDIN)), "%s");
$x = [];
for ($i = 0; $i < strlen($s) - strlen($t) + 1; $i++) {
    $cnt = 0;
    for ($j = 0; $j < strlen($t); $j++)
        if ($s[$i + $j] != $t[$j])
            $cnt++;
    $x[$i] = $cnt;
}
asort($x);
print(array_shift($x));


Measured memory_bytes: 16160
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;
//debug 
#ifdef _DEBUG
#define debug(var)  do{cout << #var << " :";view(var);}while(0)
#else
#define debug(...)
#endif
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//modをとった余りは循環する
//鳩の巣原理


int main(){
  ll n,x,m;
  cin >> n >> x >> m;
  vector<int> id(m, -1);
  vector<int> a;    //配列

  int len = 0;   //配列の長さ
  ll tot = 0;   //ループの値の合計
  //ループの検出
  while(id[x] == -1){
    a.push_back(x);
    id[x] = len;
    len++;
    tot += x;
    x = (x*x)%m;
  }
  
  int c = len - id[x]; // サイクルの長さ
  ll sum = 0;   //サイクルの合計
  for(int i = id[x]; i < len; ++i) sum += a[i];

  ll ans = 0;
  if(n <= len){ //サイクルに入る前に打ち切り　-> 普通に求める
      REP(i,n) ans += a[i]; 
  }
  else{
    ans += tot;   //ρ (チョロ＋一周分を加算)
    n -= len;     //ρ　分の長さを減算
    ans += sum*(n/c);   //ループの合計　×　ループ数
    n %= c;
    REP(i,n) ans += a[id[x]+i]; //余り分を加算する
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3944
while True:
    H,W = map(int,input().split())
    if H == 0 and W == 0:
        break
    else:
        for i in range(H):
            for j in range(W):
                if i % 2== 0:
                    if j % 2== 0:
                        print("#",end ="")
                    else:
                         print(".",end ="")                       
                else:
                    if j % 2== 0:
                        print(".",end ="")
                    else:
                         print("#",end ="") 
            print()
        print()


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

fn main() {
    let a = read1::<usize>();
    let b = read1::<usize>();
    let h = read1::<usize>();

    println!("{}", (a + b) * h / 2);
}

Measured memory_bytes: 4352
import java.util.Arrays;
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		long[] bbnwa=new long[N+1];
		bbnwa[0]=0;

		for(int i=1; i<=N; i++) {
			bbnwa[i]=bbnwa[i-1]+sc.nextLong();
		}

		Arrays.sort(bbnwa);

		long wa=0;

		long tmpwa=0;
		long kasanari=0;

		kasanari=1;
		tmpwa=bbnwa[0];
		for(int i=1; i<=N; i++) {
			if(tmpwa!=bbnwa[i]) {
				wa+=kasanari*(kasanari-1)/2;
				kasanari=1;
				tmpwa=bbnwa[i];
			}
			else {
				kasanari++;
			}
		}

		wa+=kasanari*(kasanari-1)/2;
		System.out.println(wa);
	}
}

Measured memory_bytes: 90020
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

int w, h;
int b[101][101];
int xg, yg;
bool is_reachable(int x, int y, int c)
{
	if (x < 1 || y < 1 || x > w || y > h || b[y][x] != c)
		return false;
	if (x == xg && y == yg)
		return true;
	b[y][x] = -1;
	int dx[] = { 0, 1, 0, -1 };
	int dy[] = { -1, 0, 1, 0 };
	bool res = false;
	for (int i = 0; i < 4 && !res; ++i)
		res = is_reachable(x+dx[i], y+dy[i], c);
	return res;
}
int main()
{
	while (scanf("%d %d", &w, &h), w | h)
	{
		int xs, ys;
		scanf("%d %d %d %d", &xs, &ys, &xg, &yg);
		int n;
		scanf("%d", &n);
		memset(b, -1, sizeof(b));
		for (int i = 0; i < n; ++i)
		{
			int c, d, x, y;
			scanf("%d %d %d %d", &c, &d, &x, &y);
			int w[2][2] = { { 2, 4 }, { 4, 2 } };
			for (int j = 0; j < w[d][0]; ++j)
				for (int k = 0; k < w[d][1]; ++k)
					b[y+j][x+k] = c;
		}
		if (b[ys][xs] != -1 && is_reachable(xs, ys, b[ys][xs]))
			puts("OK");
		else
			puts("NG");
	}

	return 0;
}

Measured memory_bytes: 0
N = int(input())
A = [int(a) for a in input().split()]
cnt = 0
for i in range(N):
    minj = i
    for j in range(i+1, N):
        if A[j] < A[minj]:
            minj = j
    if minj != i:
        tmp = A[i]
        A[i] = A[minj]
        A[minj] = tmp
        cnt += 1
A = [str(a) for a in A]
print(" ".join(A))
print(cnt)


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
#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 F first
#define S second
#define INF 1000000000000
#define MOD 10000007
#define PI 3.14159265359
#define dij priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>
typedef long long ll;
//
int main(){
    int d,g;cin>>d>>g;
    vector<pair<int,int>> v;
    rep(i,d){
        int a,b;cin>>a>>b;
        v.push_back(make_pair(a,b));
    }
    //reverse(all(v));
    ll mi=INF;
    rep(i,1<<d){
        ll score=0,times=0;
        int mask=1;
        vector<bool> flag(d,false);
        //vector<pair<int,int>> vv=v;
        rep(j,d){
            if(i&mask<<j){
                times+=v[j].F;
                score+=v[j].S+100*(j+1)*v[j].F;
                flag[j]=true;  
            }
        }
        //cout<<times<<" "<<score<<endl;
        if(score>=g){
            mi=min(mi,times);
        }else{
            for(int k=d-1;k>=0;k--){
                if(!flag[k]){
                    //int z=v[k].F;
                    rep(a,v[k].F){
                        times++;
                        score+=100*(k+1);
                        if(score>=g)break;
                    }
                }
                if(score>=g)break;
            }
            mi=min(mi,times);
        }
        //cout<<times<<endl;
    }
    cout<<mi<<endl;
}

Measured memory_bytes: 3632
#include<stdio.h>
#define ll long long
int main()
{
    int n,a[3005];
    ll sum=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        sum=sum+a[i];
    }
    printf("%lld\n",sum-n);
    return 0;
}

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

int main() {
  int a,b;
  cin >> a >> b;
  int sum=0;
  for(int i=a;i<=b;i++){
    if(i/10000==i%10&&i/1000%10==i%100/10){
      sum++;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <numeric>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int INF = 1001001001;

int main()
{
    int h, n;
    cin >> h >> n;
    vector<int> dp(h+1, INF);
    dp[0] = 0;
    rep(i,n)
    {
        int a, b;
        cin >> a >> b;
        rep(j,h) //9回まわす
        {
            int nj = min(j+a, h);
            dp[nj] = min(dp[nj], dp[j]+b);
        }
    }
    cout << dp[h] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;
 
#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;

ll modexp(ll a,ll b,ll m)
{
	ll r=1;
	a=a%m;
	while(b>0)
	{
		if(b&1)
		    r=(r*a)%m;
		b>>1;
		a=(a*a)%m;
	}
	return r%m;
}

int main(){
ll k,n; cin>>k>>n;
if(k*500>=n)cout<<"Yes\n";
else cout<<"No\n";
}

Measured memory_bytes: 256
N,M = list(map(int,input().split()))
K = [input().split() for l in range(N)]

hantei = [0] * 30
count = [0] * 30
for j in range(0,30):
    hantei[j] = j + 1

for i in range(N):
    for j in range(1,int(K[i][0])+1):
        for k in range(0,30):
            if int(K[i][j]) == hantei[k]:
                count[k] += 1

ans = 0
for  k in range(0,30):
    if count[k] == N:
        ans += 1

print(ans)


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

long long n;
long long b,r;

int main()
{
	scanf("%lld %lld %lld",&n,&b,&r);
	long long cnt=n/(r+b);
	long long ans=cnt*b+(n%(r+b)>b?b:n%(r+b));
	printf("%lld",ans);
}

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

def comb(n, r):
    res = 1
    for i in range(n-r+1, n+1):
        res *= i
    for i in range(2, r+1):
        res /= i
    return res

nn = comb(N, 2)
mm = comb(M, 2)

ans = int(nn + mm)

print(ans)

Measured memory_bytes: 38256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

int n;
int masu[15][15];
int nowx, nowy;

int main()
{
	while (cin >> n, n)
	{
		rep(i, n) rep(j, n) masu[i][j] = 0;
		masu[n/2+1][n/2] = 1;
		nowx = n / 2;
		nowy = n / 2 + 1;

		for (int i=2; i<=n*n; i++)
		{
			nowx = (nowx + 1) % n;
			nowy = (nowy + 1) % n;
			if (masu[nowy][nowx] == 0)
			{
				masu[nowy][nowx] = i;
			} else {
				while (masu[nowy][nowx] != 0)
				{
					nowy = (nowy + 1) % n;
					nowx = nowx - 1;
					if (nowx < 0) nowx = n + nowx;
				}
				masu[nowy][nowx] = i;
			}
		}

		rep(i, n)
		{
			rep(j, n)
			{
				printf("%4d", masu[i][j]);
			}
			printf("\n");
		}
	}
	
	return 0;
}

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

const int C = 4.01e6;

int main() {
#ifdef HOME
    freopen("in", "r", stdin);
#endif

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

        bitset<C> bt;
        bt[0] = 1;
        for (int x : a) {
            bt |= bt << x;
        }
        int sum = 0;
        for (int x : a) sum += x;

        sum = (sum + 1) / 2;
        while (!bt[sum]) sum++;
        cout << sum << endl;
    }

    return 0;
}


Measured memory_bytes: 1664
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

a=ni()
b=ni()
c=ni()
x=ni()

cnt=0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if 500*i+100*j+50*k==x:
        cnt+=1
print(cnt)


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

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
constexpr int INF = 1<<30;
constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  int R, G, B, N;
  cin >> R >> G >> B >> N;

  ll ret = 0;
  for (int r=0; r<=N/R; r++) {
    for (int g=0; g<=N/G; g++) {
      int b = N - (R*r + G*g);
      if (0<=b && b%B==0) {
        ret++;
      }
    }
  }

  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;
 
template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
 
const double PI = acos(-1.0);
const int INF = 1e9 + 47;
const LL LINF = 1LL * INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 3020;

LL val[N][N];
LL dpT[N][N][4];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, m, z;
	cin >> n >> m >> z;
	FOR(i, 0, z)
	{
		int r, c;
		cin >> r >> c;
		r--; c--;
		cin >> val[r][c];
	}
	FOR(i, 0, n)
	{
		FOR(j, 0, m)
		{
			FOR(k, 0, 4)
			{
				if(k != 3)
				{
					setmax(dpT[i][j + 1][k + 1], dpT[i][j][k] + val[i][j]);
					setmax(dpT[i + 1][j][0], dpT[i][j][k] + val[i][j]);
				}
				setmax(dpT[i][j + 1][k], dpT[i][j][k]);
				setmax(dpT[i + 1][j][0], dpT[i][j][k]);
			}
		}
	}
	LL ans = 0;
	FOR(i, 0, 4)
		setmax(ans, dpT[n - 1][m - 1][i] + (i != 3) * val[n - 1][m - 1]);
	cout << ans << endl;
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}
 


Measured memory_bytes: 357652
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


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;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n;
  cin>>n;
  vector<string> v(n);
  rep(i,n) cin>>v[i];
  map<char,ll> mp;
  rep(i,26){
    char c='a'+i;
    mp[c]=51;
  }
  rep(i,n){
    rep(j,26){
      char c='a'+j;
      ll tmp=0;
      rep(k,v[i].size()) if(v[i][k]==c) tmp++;
      mp[c]=min(mp[c],tmp);
    }
  }
  for(auto c:mp){
    rep(i,c.second){
      cout<<c.first;
    }
  }
  cout<<endl;
}

Measured memory_bytes: 256
def is_palindrome(s):
    return s == s[::-1]

S = input()
N = len(S)
S_head = S[:(N-1)//2]
S_tail = S[(N+3)//2-1:]
if is_palindrome(S) and is_palindrome(S_head) and is_palindrome(S_tail):
    print('Yes')
else:
    print('No')


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

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    map<char, ll> mp;
    rep(i, n) {
        ++mp[s[i]];
    }
    ll ans = mp['R'] * mp['G'] * mp['B'];
    for ( int i = 1; i < n; ++i ) {
        rep(j, n) {
            if ( i - j < 0 || i + j >= n ) continue;
            if ( s[i-j] != s[i] && s[i] != s[i+j] && s[i-j] != s[i+j] ) {
                --ans;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3604
N = int(input())
L=[input() for i in range(N)]

print("AC" + " x "+ str(L.count("AC")))
print("WA" + " x "+ str(L.count("WA")))
print("TLE" + " x "+ str(L.count("TLE")))
print("RE" + " x "+ str(L.count("RE")))

Measured memory_bytes: 16160
#include <bits/stdc++.h>
#define ll long long
#define MODV 998244353
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

long long modPow(long long x, long long n, long long mod = MODV){
    if(n == 0) return 1;
    if(n%2 == 0) return modPow(x*x%mod, n/2, mod)%mod;
    return x%mod * modPow(x%mod, n-1, mod)%mod;
}

int main(){
    Init();
    ll n, md = 0; cin >> n;
    vi d(n);
    map<ll, ll> cnt;
    rep(i, n){
        cin >> d[i];
        cnt[d[i]]++;
        chmax(md, d[i]);
    }
    // 根が1個以外だとダメ
    if(cnt[0] != 1 || d[0] != 0){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1;
    ll sum = 0;
    for(ll i=0; i<md; i++){
        sum += cnt[i];
        ans *= modPow(cnt[i], cnt[i+1]);
        ans %= MODV;
    }
    cout << ans << endl;
}

Measured memory_bytes: 10204
#include <stdio.h>
int main() {
	int a, b, c, d;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	int x = a - c;
	int y = b - d;
	printf("%d %d %d %d\n", c + y, d - x, a + y, b - x);
	return 0;
}

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

#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9 + 7;

void FAST(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int main(){
  FAST();

  int n, l;
  cin >> n >> l;

  int left = l;             // 0-indexed
  int right = l + n - 1;

  int eat;
  if (right <= 0)
    eat = right;
  else if (left >= 0)
    eat = left;
  else
    eat = 0;

  int sum = (n * l) + n * (n - 1) / 2;
  cout << sum - eat << endl;

  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

t = [int]*5
amari = [int]*5

for i in range(5):
	t[i] = int(input())
	amari[i] = t[i]%10
	amari[i] = int(str(10-amari[i])[-1:])

ind = amari.index(max(amari))
time = t[ind]

for i in range(5):
	if i != ind:
		time += t[i] + amari[i]

print(time)

Measured memory_bytes: 3064
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in=new Scanner(System.in);
		while(in.hasNext())
		{
			int l=in.nextInt();
			if(l==0)
				return;
			int h=in.nextInt();
			int ans=0;
			for(int i=l;i<=h;i++)
			{
				int tmp=i;
				for(;;)
				{
					if(tmp==1)
					{
						ans++;
						break;
					}
					if(tmp%5==0)
						tmp/=5;
					else if(tmp%3==0)
						tmp/=3;
					else if(tmp%2==0)
						tmp/=2;
					else break;
				}
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 12000
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

// https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/1/DSL_1_A

// snip
struct UnionFindTree {
    parent: Vec<usize>,
    size: Vec<i64>
}

impl UnionFindTree {
    fn new(n: usize) -> UnionFindTree {
        UnionFindTree {
            parent: (0..(n + 1)).collect(),
            size: vec![1; n + 1]
        }
    }
    fn find(&mut self, x: usize) -> usize {
        if self.parent[x] != x {
            let parent_x = self.parent[x];
            self.parent[x] = self.find(parent_x);
        }
        self.parent[x]
    }
    fn same(&mut self, x: usize, y: usize) -> bool {
        self.find(x) == self.find(y)
    }
    fn size(&mut self, x: usize) -> i64 {
        let i = self.find(x);
        self.size[i]
    }
    fn union(&mut self, x: usize, y: usize) {
        let parent_x = self.find(x);
        let parent_y = self.find(y);
        if !self.same(x, y) {
            if self.size[parent_x] < self.size[parent_y] {
                self.size[parent_y] += self.size[parent_x];
                self.parent[parent_x] = parent_y;
            } else {
                self.size[parent_x] += self.size[parent_y];
                self.parent[parent_y] = parent_x;
            }
        }
    }
}
// snip

fn main() {
    let (n, q): (usize, usize) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };
    let (com, x, y): (Vec<i64>, Vec<usize>, Vec<usize>) = {
        let (mut com, mut x, mut y) = (vec![], vec![], vec![]);
        for _ in 0..q {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            com.push(iter.next().unwrap().parse().unwrap());
            x.push(iter.next().unwrap().parse().unwrap());
            y.push(iter.next().unwrap().parse().unwrap());
        }
        (com, x, y)
    };

    let mut uft = UnionFindTree::new(n - 1);
    let ans = {
        let mut ans = vec![];
        for i in 0..q {
            if com[i] == 0 {
                uft.union(x[i], y[i]);
            } else {
                if uft.same(x[i], y[i]) {
                    ans.push(1);
                } else {
                    ans.push(0);
                }
            }
        }
        ans.iter().map(std::string::ToString::to_string).collect::<Vec<_>>().join("\n")
    };

    println!("{}", ans);
}



Measured memory_bytes: 11068
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
//大きな数を扱うときは素因数分解した形で持っておく
// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;
//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    int n,c; cin >> n >> c;
    vector<pair<int,int>> v;
    vector<pair<pair<int,int>,int>> v2;
    rep(i,n){
        int s,t,c; cin >> s >> t >> c;
        v2.pb({{s,c},0}); //追加
        v2.pb({{t,c},1}); //削除
    }
    sort(ALL(v2));
    
    rep(i,2*n){
        auto p=v2[i];
        if(i==2*n-1){
            v.pb({p.fi.fi,p.se});
            break;
        }
        auto p2=v2[i+1];
        if(p.fi.fi==p2.fi.fi&&p.fi.se==p2.fi.se&&p.se!=p2.se){
            i++;
        }else{
            v.pb({p.fi.fi,p.se});
        }
    }
    
    int ans=0,num=0;
    sort(ALL(v));
    for(auto p:v){
        //cout <<p.fi<<" "<<p.se<<endl;
        if(p.se==0) num++;
        else num--;
        chmax(ans,num);
    }
    cout << ans << endl;
}


Measured memory_bytes: 6896
#include <iostream>
using namespace std;
int main(void){
    int num[] = {0,1,3,1,2,1,2,1,1,2,1,2,1};
    int x,y;
    cin >> x >> y;
    (num[x] == num[y])?cout << "Yes" << endl :cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <set>
#include <cmath>
#include <string>
#include <algorithm>

using namespace std;

const int CMax = 100002;

string S;
bool tik;
int c;

int main() {
    cin >> S;

    tik = true;

    for (int i = 0; i < S.length(); i++) {
        if (i == 0 && S[i] != 'A') tik = false;
        else if (i > 1 && i < S.length() - 1 && S[i] == 'C') {
            c++;
            if (c > 1) tik = false;
        }
        else if (S[i] != 'A' && S[i] - 'a' < 0) tik = false;
    }

    if (tik && c == 1) cout << "AC" << endl;
    else cout << "WA" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main()
{
    char x;
    int count[128] = {0};
    while (scanf("%c", &x) != EOF)
    {
        count[x]++;
    }

    for (char c = 'a'; c <= 'z'; c++)
    {
        printf("%c : %d\n", c, count[c] + count[c - 32]);
    }
    return 0;
}


Measured memory_bytes: 2032
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b && b==c) cout << 1 << endl;
  else if((a==b && b!=c) || (a==b&&a!=c) || (a==c && a!=b) || (a==c&&b!=c)||(b==c&&a!=b)||(b==c&&a!=c)) cout << 2<< endl;
  else cout << 3 << endl;
  return 0;
}

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

long int *Marge(long int *A,long int N){
	
	if(N==1){
		long int *C=malloc(sizeof(long int));
		C=A;
		return C;
	}

	if (N>1){
		long int N1=N/2;
		long int N2=N-N1;
		long int *A1=malloc(N1*sizeof(long int));
		long int *A2=malloc(N2*sizeof(long int));
		long int i=0;
		for (i=0;i<N1;i++){
			A1[i]=A[i];
		}
		for (i=N1;i<N;i++){
			A2[i-N1]=A[i];
		}
		long int *B1=Marge(A1,N1);
		long int *B2=Marge(A2,N2);

		long int *C=malloc(N*sizeof(long int));

		long int k=0;
		long int l=0;
		long int m=0;

		while(1){
			if (k>=N1){
				for (m;m<N;m++){
					C[m]=B2[l];
					l++;
				}
				break;
			}
			if (l>=N2){
				for (m;m<N;m++){
					C[m]=B1[k];
					k++;
				}
				break;
			}		
			else{
				if (B1[k]<=B2[l]){
					C[m]=B1[k];
					m++;
					k++;
				}
				if (B1[k]>B2[l]){
					C[m]=B2[l];
					m++;
					l++;
				}
			}
		}
		return C;
	}

}



int main(){
	long int N;
	scanf("%ld",&N);

	long int *A=malloc(N*sizeof(long int));
	long int i;
	for (i=0;i<N;i++){
		scanf("%ld",&A[i]);
	}

	long int *B=malloc(N*sizeof(long int));
	B=Marge(A,N);

	long int j=0;
	long int sum;
	long int ans=0;
	while(j<N){
		sum=0;
		long int b=B[j];
		while (j<N && B[j]==b) {
			sum++;
			j++;
		}
		ans+=sum%2;
	}	
	printf("%ld\n",ans);
}

Measured memory_bytes: 31872
#include<iostream>
using namespace std;
int main(){
        int n;
        cin >> n;
        int a[100];
        for (int i = 0; i < n; i++){
                cin >> a[i];
        }
        for (int i = 0; i < n; i++){
                int v = a[i];
                int j = i - 1;
                while (j >= 0 && a[j] > v){
                        a[j+1] = a[j];
                        a[j] = v;
                        j--;
                }
                for (int k = 0; k < n; k++) {
                        cout << a[k]; 
                        if (k != n-1) cout << " ";
                }
                cout << endl;
        }
        return 0;
}


Measured memory_bytes: 3068
import sys

input = sys.stdin.readline


def main():
    N, M = [int(x) for x in input().split()]
    if N >= 2 and M >= 2:
        print((N - 2) * (M - 2))
    else:
        if N == 1 == M:
            print(1)
        else:
            print(max(N, M) - 2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws java.lang.Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader((System.in)));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
        int total = 0;
        if (n > 1) {
            total += (n * (n-1) / 2);
        }
        if (m > 1) {
            total += (m * (m-1) / 2);
        }
        System.out.println(total);
//        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
//        bw.write("\n");
//        bw.close();
    }

}

Measured memory_bytes: 22996