akhauriyash/Code-Regression huggingface dataset:
N = int(input())
A = [-1 for i in range(N)]

color = 1
A[0] = int(input())


def search(A, color, a):
        left = 0
        right = color - 1
        signal = 0
        while left < right:
                mid = (left + right) // 2
                if A[mid] == a - 1:
                        return mid
                        signal = 1
                elif a <= A[mid]:
                        left = mid + 1
                else:
                        right = mid
        if signal == 0:
                return left


for i in range(N - 1):
        
        a = int(input())
        num = search(A, color, a)
        if num == color - 1 and a <= A[num]:
                A[color] = a
                color += 1
        else:
                A[num] = a

print(color)

Measured memory_bytes: 7052
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
typedef long long ll;
ll mod_pow(ll, ll, ll);
ll mod_fact(ll, ll);
ll mod_inv(ll, ll);
//
int main(){
    string s; cin >> s;
    int dig[4];
    for(int i = 0; i < 4; i++){
        dig[i] = (s[i] - '0');
    }
    for(int i = 0; i < 8; i++){
        int sum = dig[0];
        for(int j = 0; j < 3; j++){
            if(i >> j & 1){
                sum += dig[j + 1];
            }else{
                sum -= dig[j + 1];
            }
        }
        if(sum == 7){
            char op[3];
            for(int j = 0; j < 3; j++){
                if(i >> j & 1) op[j] = '+';
                else op[j] = '-';
            }
            cout << dig[0] << op[0] << dig[1] << op[1] << dig[2] << op[2] << dig[3] << "=7";
            return 0;
        }
    }
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;

	void run() {
		Scanner sc = new Scanner(System.in);
		int d = sc.nextInt(), n = sc.nextInt();
		int[] ts = new int[d], abcs[] = new int[n][3];
		
		for(int i=0;i<d;i++) ts[i] = sc.nextInt();
		for(int i=0;i<n;i++)for(int j=0;j<3;j++) abcs[i][j] = sc.nextInt();
		
		int[][] dp = new int[d][n];
		for(int i=0;i<n;i++) if(!(abcs[i][0] <= ts[0] && ts[0] <= abcs[i][1])) dp[0][i] = -INF;
		for(int j=1;j<d;j++) for(int i=0;i<n;i++) {
			if(abcs[i][0] <= ts[j] && ts[j] <= abcs[i][1]) for(int k=0;k<n;k++) 
				dp[j][i] = max(dp[j][i], dp[j-1][k] + abs(abcs[i][2] - abcs[k][2]));
			else dp[j][i] = -INF;
		}
//		debug(dp);
		int max = 0;
		for(int i=0;i<n;i++) max = max(max, dp[d-1][i]);
		System.out.println(max);
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

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

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


int main(void){
    int n,m;
    cin >> n >> m;
    ll a[100100][3];
    rep(i,n){
        rep(j,3){
            cin >> a[i][j];
        }
    }
    ll maxn = 0;
    rep(i,8){
        vector<ll>vc;
        rep(j,n){
            ll s = 0;
            rep(k,3){
                if(((i / (1 << k))) % 2 == 0){
                    s += a[j][k];
                }
                else{
                    s -= a[j][k];
                }
            }
            vc.push_back(s);
        }
        sort(vc.begin(),vc.end(),greater<ll>());
        ll ans = 0;
        rep(j,m){
            ans += vc[j];
        }
        maxn = max(ans,maxn);
    }
    
    cout << maxn <<endl;
    
    return 0;
}
































































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

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#define int long long

using namespace std;

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

const int N = 2000 + 10;
const int MOD = 1000000007;
const int LOG = 20;
const int INF = 1000000010;
const int delta = 11353;

struct edge{
	int id, v, u, w;
};

int n, m, X, sm, par[N], sz[N], mx[N][N], P2[N], mark[N];
vector<pii> G[N];
vector<edge> E;

int getpar(int v){
	return (v == par[v]?v:par[v] = getpar(par[v]));
}

bool cmp(edge x, edge y){
	return (x.w < y.w);
}

void merge(int v, int u, int w, int id){
	int vv = v, uu = u;
	v = getpar(v), u = getpar(u);
	//cout << vv << ' ' << uu << ' ' << v << ' ' << u << '\n';
	if (v == u) return;
	sm += w;
	if (sz[v] < sz[u]) swap(v, u);
	sz[v] += sz[u];
	par[u] = v;
	G[vv].pb({uu, w}), G[uu].pb({vv, w});
	mark[id] = 1;
}

void DFS(int jad, int v, int p){
	for (auto u:G[v]){
		if (u.F == p) continue;
		mx[jad][u.F] = max(u.S, mx[jad][v]);
		DFS(jad, u.F, v);
	}
}

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m >> X;
	P2[0] = 1;
	for (int i = 1; i < N; i++) P2[i] = P2[i - 1] * 2ll % MOD;
	for (int i = 1; i <= m; i++){
		edge e;
		cin >> e.v >> e.u >> e.w;
		e.id = i;
		E.pb(e);
	}
	sort(all(E), cmp);
	for (int i = 1; i <= n; i++) par[i] = i, sz[i] = 1;
	for (auto u:E){
		//cout << u.v << ' ' << u.u << ' ' << u.w << ' ' << u.id << '\n';
		merge(u.v, u.u, u.w, u.id);
	}
	//for (int i = 1; i <= n; i++) par[i] = i, sz[i] = 1;
	for(int i = 1; i <= n; i++) DFS(i, i, 0);
	int eq = 0, la = 0;
	for (auto e:E){
		if (mark[e.id]) continue;
		if (sm - mx[e.v][e.u] + e.w == X) eq++;
		if (sm - mx[e.v][e.u] + e.w > X) la++;
	}
	//if(X == sm) assert(0);
	int ans = 0;
	ans = 2 * (P2[eq] - 1) % MOD;
	ans = ans * P2[la] % MOD;
	//cout << sm << '\n';
	if (X == sm){
		int res = P2[n - 1] - 2;
		res = res * P2[m - n + 1] % MOD;
		ans = (ans + res) % MOD;
	}
	ans %= MOD;
	if (ans < 0) ans += MOD;
	cout << ans;
	return 0;
}


Measured memory_bytes: 15720
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,sum,var;
    sum=0;
    var=0;
    cin>>N;
    int Wgt[N];
if(N>=2&&N<=100){
    for(int i=0;i<N;i++)
    {
        cin>>Wgt[i];
        sum=sum+Wgt[i];
    }
    int tot=sum;
    for(int i=0;i<N;i++)
    {
        var=var+Wgt[i];
        tot=min(tot,abs(var-(sum-var)));
    }

    cout<<tot;
}
    
return 0;
}

Measured memory_bytes: 3632
#include <cstdio>

int main(){
    int A, B, C;
    scanf("%d %d %d", &A, &B, &C);

    int hoge_max, hoge_a, hoge_b;
    if(A < B){
        hoge_max = B;
        hoge_a = A;
    }else{
        hoge_max = A;
        hoge_a = B;
    }

    if(hoge_max > C){
        hoge_b = C;
    }else{
        hoge_b = hoge_max;
        hoge_max = C;
    }

    int diff = hoge_max * 2 - hoge_a - hoge_b;

    int ans;
    if(diff % 2 == 1){
        ans = 1 + (diff + 1) / 2;
    }else{
        ans = diff / 2;
    }

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 128
from collections import deque

a,b = map(int,input().split()) 
a=sorted(list(map(int,input().split())))
di = {}
for i in range(b):
    x,y = map(int,input().split()) 
    if y in di:
        di[y] += x
    else:
        di[y] = x
keys = sorted(list(di.keys()))
keys.reverse()
# print(keys)
ichi = 0
# print(a)
for i in range(len(a)):
    try:
        if keys[ichi] > a[i]:
            a[i] = keys[ichi]
            di[keys[ichi]] -= 1
        else:
            break
        if di[keys[ichi]] == 0:
            ichi += 1
    except:
        pass
# print(a)
print(sum(a))


Measured memory_bytes: 23840
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <stack>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i, m, n) for (ll(i) = (ll)(m); i < (ll)(n); ++i)
#define REP2(i, m, n) for (ll(i) = (ll)(n)-1; i >= (ll)(m); --i)
#define rep(i, n) REP(i, 0, n)
#define rep2(i, n) REP2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using Edge = pair<int, long long>;
using Graph = vector<vector<Edge>>;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
// constexpr long long MOD = (ll)1e9 + 7;
// constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
template <class T> inline void print(T x) { cout << x << '\n'; }
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;
}

long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }

// ~~~~~~~~~~~~~~memo~~~~~~~~~~~~~~
// for (int i = 0; i < n; ++i)
// v ector<long long> v(n), c(n);
// cout << res << endl;
// cout << res << '\n';
// int型の2次元配列(h×w要素の)の宣言
// vector<vector<int>> data(h, vector<int>(w));
// rotate(s.begin(), s.begin() + 1, s.end());
// sort(all(a),greater<int>());
// s.substr(0,2) 先頭から2文字切り出す
// for (auto it = mp.rbegin();it != mp.rend(); ++it)
// vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(w + 1, vector<int>(k+1, 0)));

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    vector<string> s(n);
    vector<ll> t(n);
    rep(i,n) {
        cin >> s[i] >> t[i];
    }
    string x;
    cin >> x;
    ll res = 0;
    bool f = false;
    rep(i,n) {
        if (s[i] == x) {
            f = true;
            continue;
        }
        if (f) res += t[i];

    }
    print(res);

    return 0;
}


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

int main(){
    int E,Y;
    cin>>E>>Y;
    switch(E){
        case 0 :{
            if(Y<1912){
                cout<<'M'<<Y-1867<<endl;
            }else if(Y>1911&&Y<1926){
                cout<<'T'<<Y-1911<<endl;
            }else if(Y>1925&&Y<1989){
                cout<<'S'<<Y-1925<<endl;
            }else{
                cout<<'H'<<Y-1988<<endl;
            }
            break;
        }
        case 1 : cout<<Y+1867<<endl; break;
        case 2 : cout<<Y+1911<<endl; break;
        case 3 : cout<<Y+1925<<endl; break;
        case 4 : cout<<Y+1988<<endl; break;
    }
    return 0;
}


Measured memory_bytes: 3108
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<tuple>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

const ll mod = 1e9+7;
const ll INF = ll(1e18)+1;
const ll MAXN = 1e6;

const int MAX=510000;

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

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


int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    a--;

    ll l=lcm(c,d);
   
    ll ansb=b-(b/c+b/d)+b/l;


    ll ansa=a-(a/c+a/d)+a/l;

    cout<<ansb-ansa;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
typedef long long int ll;
using namespace std;
int main()
{
	string s;
	cin >> s;
	int cnt=0;
	for(int i=0; i<s.size(); i++){
		if(s.at(i)=='x'){
			cnt++;
		}
	}
	if(cnt>7){
		cout << "NO" << endl;
	}else{
		cout << "YES" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	char a[6];
	scanf("%s",a);
	if(a[0]=='S'){
		printf("Cloudy\n");
	}
	else if(a[0]=='C'){
		printf("Rainy\n");
	}
	else{
		printf("Sunny\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
#define mp make_pair
#define fi first
#define se second
#define All(x) (x).begin(),(x).end()
#define Y1 "YES"
#define N1 "NO"
#define ENDL '\n'
#define count2(x) _builtin_popcount(x)
int main(){
	ll a,v,b,w,t;
	cin>>a>>v>>b>>w>>t;
	if(a<b){
		a+=v*t;
		b+=w*t;
		if(a>=b)cout<<Y1;
		else cout<<N1;	
	} 
	else{
		a-=v*t;
		b-=w*t;
		if(a<=b)cout<<Y1;
		else cout<<N1;	
	}
	return 0;
}



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

int main(){
  int time = 0;
  long long x, money = 100;
  
  cin >> x;
  
  while(true){
    if(money >= x) break;
    money *= 1.01;
    time++;
  }
  
  cout << time << endl;
  
  return 0;
}

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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;

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

    bool ok[n];
    fill(ok, ok + n, true);
    for (int i = 0; i < m; i++) {
    	int a, b;
    	cin >> a >> b;
    	a--; b--;
    	if (h[a] > h[b]) ok[b] = false;
    	else if (h[a] < h[b]) ok[a] = false;
    	else {
    		ok[a] = false;
    		ok[b] = false;
    	}
    }

    int ret = 0;
    for (int i = 0; i < n; i++) {
    	if (ok[i]) {
    		ret++;
    	}
    }

    cout << ret << endl;

    return 0; 
} 


Measured memory_bytes: 4152
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

// int n;
set<int> d;

int is_ng(int n) {
    // nがdに含まれている数字で構成されていないか判定
    while (n != 0) {
        int tn = n % 10;
        if (d.count(tn)) {
            return 1;
        }
        n /= 10;
    }
    return 0;
}

int main() {
    cout << fixed << setprecision(10);
    
    int n, k; cin >> n >> k;
    // set<int> d
    rep(i, k) {
        int a; cin >> a;
        d.insert(a);
    }
    while (is_ng(n)) {
        n += 1;
    }
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())

table = ['x'] + ([0] * N)
for i in range(1,N+1):
    for j in range(i,N+1,i):
        table[j] += 1

ans = 0

for i in range(1,N+1,2):
    if table[i] == 8:
       ans += 1

print(ans)


Measured memory_bytes: 63940
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int result = 0;
		
		for (int i = 0; i <= N; i++) {
			int sum = i / 10000 + (i / 1000) % 10 + (i / 100) % 10 + (i / 10) % 10 + i % 10;
			if (sum >= A && sum <= B) {
				result += i;
			}
		}
		System.out.println(result);
	}
}


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

// グローバル変数
ll a, b, c;
const int max_val = 50000;

// 関数プロトタイプ
void input();
void solve();
bool check(int);

int main(void)
{
    input();
    solve();  
}

// 標準入力
void input() {
    cin >> a >> b >> c;
}

void solve() {
    int i = 0;
    for (; i < max_val;i++) {
        bool ca = check(a);
        bool cb = check(b);
        bool cc = check(c);
        if(!ca || !cb || !cc) {
            break;
        }
        if (ca && cb && cc) {
            ll tmpa = a / 2;
            ll tmpb = b / 2;
            ll tmpc = c / 2;
            a = tmpb + tmpc;
            b = tmpa + tmpc;
            c = tmpa + tmpb;
        }
    }
    if(i == max_val){
        i = -1;
    }
    cout << i << endl;
}

bool check(int n) {
    if(n%2 != 0) {
        return false;
    }
    return true;
}

Measured memory_bytes: 256
n = int(input())
cards = list(map(int, input().split()))
cards.sort(reverse=True)
alice = 0
bob = 0
alice_cards = cards[::2]
bob_cards = cards[1::2]
alice_sum = sum(alice_cards)
bob_sum = sum(bob_cards)
print(alice_sum - bob_sum)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define rep(i,n) for(ll i=0;i<(n);i++)  
#define pii pair<int,int>
#define piii pair<int,pii>
#define mp make_pair
#define pb push_back  
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-5;
const double PI = M_PI;  
#define DEB cout<<"!"<<endl
#define SHOW(a,b) cout<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cout<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
  
#define DIV 1000000007
typedef vector<ll> Array;
typedef vector<Array> matrix;
typedef tuple<int,int,int> tiii;
#define mt make_tuple


int main(){
  ll q,h,s,d; cin >> q >> h >> s >> d;
  ll n; cin >> n;
  s = min(s,min(2*h,4*q));
  d = min(2*s,d);
  ll ans = 0;
  ans += d *(n/2);
  ans += s *(n%2);
  cout << ans << endl;
}

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

if n % 2 == 1:
    for i in range(n - 1, -1, -2):
        print(a[i], end=" ")
    for i in range(1, n, 2):
        print(a[i], end=" ")
else:
    for i in range(n - 1, -1, -2):
        print(a[i], end=" ")
    for i in range(0, n, 2):
        print(a[i], end=" ")


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int A, B, C; cin >> A >> B >> C;
  int a = C - (A - B);
  if(a < 0) cout << 0 << endl;
  else cout << a << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+2,mod=998244353;
int n,x,a[N],inv[N],w[N];
int main()
{inv[1]=1;
	for(int i=2;i<N;i++)inv[i]=(-1ll*inv[mod%i]*(mod/i)%mod+mod)%mod;
	scanf("%d",&n);int ans=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);(a[x]+=x)%=mod;(ans+=mod-x)%=mod;
	}//w[1]=1;
	for(int i=1;i<N;i++)
	{int cnt=0;(w[i]+=inv[i])%=mod;
		for(int j=i+i;j<N;j+=i)(w[j]+=mod-w[i])%=mod,(cnt+=a[j])%=mod;(cnt+=a[i])%=mod;
		//cout<<cnt<<" "<<i<<" "<<w[i]<<endl;
		(ans+=1ll*cnt*cnt%mod*w[i]%mod)%=mod;
	}ans=(1ll*ans*inv[2]%mod+mod)%mod;cout<<ans;
}


Measured memory_bytes: 11904
import itertools
import math
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
Nl = list(range(1, N+1))
p = list(itertools.permutations(Nl,N))
NN = math.factorial(N)
c1 = 1
c2 = 1
for v in range(NN):
    if list(p[v]) == P:
        break
    else:
        c1 += 1
for v in range(NN):
    if list(p[v]) == Q:
        break
    else:
        c2 += 1
print(abs(c1-c2))

Measured memory_bytes: 7972
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {

	private class DisjointSet {
		
		int[] p, rank;
		
		public DisjointSet(int size) {
			p = new int[size];
			rank = new int[size];
			for (int i = 0; i < size; i++) {
				makeSet(i);
			}
		}

		private void makeSet(int x) {
			p[x] = x;
			rank[x] = 0;
		}
		
		public boolean same(int x, int y) {
			return findSet(x) == findSet(y);
		}

		private int findSet(int x) {
			
//			List<Integer> list = new ArrayList<>();
			
			while (x != p[x]) {
//				list.add(x);
				x = p[x];
			}
			
//			for (int i : list) {
//				p[i] = p[x];
//			}
			
			return p[x];
		}
		
		public void unite(int x, int y) {
			link(findSet(x), findSet(y));
		}

		private void link(int x, int y) {
			if (rank[x] > rank[y]) {
				p[y] = x;
			} else {
				p[x] = y;
				if (rank[x] == rank[y]) {
					rank[y]++;
				}
			}
		}
	}
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(reader.readLine());
		int n = Integer.parseInt(st.nextToken());
		DisjointSet ds = new DisjointSet(n);
		int q = Integer.parseInt(st.nextToken());
		for (int i = 0; i < q; i++) {
			st = new StringTokenizer(reader.readLine());
			int c = Integer.parseInt(st.nextToken());
			int x= Integer.parseInt(st.nextToken());
			int y = Integer.parseInt(st.nextToken());
			if (c == 0) {
				ds.unite(x, y);
			} else {
				System.out.println(ds.same(x, y)?"1":"0");
			}
		}
		reader.close();
	}
}


Measured memory_bytes: 61216
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define vpi vector<ppi>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/

int main()
{
    fast


        
    string a,b,c;
    cin>>a>>b>>c;

    cout<<a[0]<<b[0]<<c[0];    












    return 0;
}

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

int main(){
  long long N,x=pow(10,18),ans=1;
  cin >> N;
  vector<long long> A(N);
  for(int i=0;i<N;i++) cin >> A[i];
  sort(A.begin(),A.end());
  
  for(int i=0;i<N;i++){
    if(A[i]!=0){
      if(x/A[i]<ans){
        cout << -1 << endl;
        return 0;
      }
    }
    ans *= A[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define int long long
#define inf (int)1e18+7

int n;
int a[3003];
int dp[2][3003][3003];
bool used[2][3003][3003] = {false};

int solve(int who, int beg, int fin) {
  if (beg > fin) return 0;
  if (used[who][beg][fin]) return dp[who][beg][fin];
  int res;
  if (who == 0) {
    res = solve(who ^ 1, beg + 1, fin) + a[beg];
    res = max(res, solve(who ^ 1, beg, fin - 1) + a[fin]);
  } else {
    res = solve(who ^ 1, beg + 1, fin) - a[beg];
    res = min(res, solve(who ^ 1, beg, fin - 1) - a[fin]);
  }
  used[who][beg][fin] = true;
  dp[who][beg][fin] = res;
  return res;
}


signed main() {

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

  int res = solve(0, 0, n - 1);
  cout << res << endl;


  return 0;
}

Measured memory_bytes: 158208
n,m=map(int,input().split())
a = [0]*n
if n!=1:
  if m!=0:
    for i in range(m):
      a[int(input())-1] = 1

  s=[0]*n
  if a[0]==1 and a[1] == 1:
    s[0] = 0
    s[1] = 0
  elif a[0] == 1:
    s[0] = 0
    s[1] = 1
  elif a[1] == 1:
    s[0] = 1
    s[1] = 0
  else:
    s[0] = 1
    s[1] = 2

  for i in range(2,n):
    #壊れている
    if a[i] == 1:
      s[i] = 0
    else:
      s[i] = s[i-1]+s[i-2]
  print(s[n-1]%1000000007)
else:
  print(1)


Measured memory_bytes: 470520
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n,m;
	int ans=0;
	cin >>n>>m;
	VPi data(n);
	rep(i,n){
		cin>>data[i].F>>data[i].S;
	}
	sort(all(data));
	auto ter=data.begin();
	priority_queue<int>dis;
	rep(i,m){
		while((ter->F) <=i+1){
			dis.push(ter->S);
			ter++;
			if(ter==data.end()){
				data[0].F=INF;
				ter=data.begin();
				
			}
		}
		if(!dis.empty()){
			ans+=dis.top();
			dis.pop();
		}
	}
	cout<<ans<<endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> h(N);
  for (int i = 0; i < N; i++)
    cin >> h[i];
  int ans = 0;
  while (true) {
    bool flag = false;
    int l = -1, r = -1;
    for (int i = 0; i < N; i++) {
      if (h[i] >= 1 && !flag)
        flag = true, l = i, r = i + 1;
      else if (h[i] >= 1)
        r++;
      else if (flag)
        break;
    }
    if (flag) {
      ans++;
      for (int i = l; i < r; i++)
        h[i]--;
    } else
      break;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000000
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;
    map<int,int> mp;
    rep(i,n){
        int a;
        cin >> a;
        a;
        mp[a]++;
        if(mp[a]!=1){
            cout << "NO" << endl;
            return 0;
        } 
    }
    cout << "YES" << endl;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
 
template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double
 
int mod = 998244353;
int n,s;
int arr[3005];
int cache[3005][3005];

int dp(int pos,int sum)
{
    if(sum==s)
        return n-pos+1;

    if(pos==n || sum>s)
        return 0;

    int &ans=cache[pos][sum];
    if(ans!=-1)
        return ans;

    ans=dp(pos+1,sum)+dp(pos+1,sum+arr[pos]);
    ans%=mod;
    return ans;
}
int32_t main() 
{
    IOS;
    cin>>n>>s;
    for(int i=0;i<n;i++)
        cin>>arr[i];
    memset(cache,-1,sizeof(cache));
    int ans=0;
    for(int i=0;i<n;i++)
        ans+=dp(i,0);
    ans%=mod;
    print(ans);
}   

Measured memory_bytes: 74392
A = int(input())
B = int(input())
C = int(input())
X = int(input())
ans = 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:
                ans += 1
print(ans)


Measured memory_bytes: 3060
import sys
import collections
import math
from collections import Counter
from collections import deque

N = int(input())

S = [None] * N
for i in range(N):
    S[i] = int(input())

total = sum(S)

if total % 10 != 0:
    print(total)
    sys.exit(0)

S = sorted(S)

ret = 0
for s in S:
    if s % 10 != 0:
        ret = total - s
        break

print(ret)
sys.exit(0)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define pb push_back
#define ff first 
#define ss second  
typedef pair<int,int> pp;
bool com(pp x,pp y){
    return x.ff<y.ff;
} 
int N=1e5+9;
vector<vector<int>> dp(1002,vector<int> (1002,0));
vector<vector<bool>> vis(1002,vector<bool> (1002,0));
vector<string> s;
int n,m;
bool valid(int x,int y){
    if(x<1||x>n||y<1||y>m) return false;
    if(s[x-1][y-1]=='#') return false;
    return true;
}
int dfs(int x,int y){
    if(x==n&&y==m) return dp[n][m]=1;
    if(vis[x][y]) return dp[x][y];
    vis[x][y]=1; 
    if(valid(x+1,y)&&valid(x,y+1)){
        dp[x][y]=(dfs(x+1,y)%mod+dfs(x,y+1)%mod)%mod;
    }
    else if(valid(x+1,y)) dp[x][y]+=dfs(x+1,y)%mod;
    else if(valid(x,y+1)) dp[x][y]+=dfs(x,y+1)%mod;
    return dp[x][y]%mod;
}
void solve(){
    cin>>n>>m;
    for(int i=0;i<n;i++){
        string st;
        cin>>st;
        s.pb(st);
    }
    dp[1][1]=dfs(1,1);
    cout<<dp[1][1];
}
int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--) 
	    solve();
	return 0; 
	
}


Measured memory_bytes: 8868
import fractions
from functools import reduce
n,m=map(int,input().split())
a=list(map(int,input().split()))
last_cnt = 0
v=a[0]
while v%2==0:
  v//=2
  last_cnt+=1
for v in a[1:]:
  cnt = 0
  while v%2 == 0:
    v //=2
    cnt += 1
  if last_cnt != cnt:
    print(0)
    exit()
    
a=[v//2 for v in a]

def lcm_base(x,y):
  return (x*y)//fractions.gcd(x,y)
def lcm_list(numbers):
  return reduce(lcm_base, numbers, 1)

l = lcm_list(a)
if l>m:
  print(0)
  exit()
print(1+(m-l)//(l*2))
#print(lcm_list(a))

Measured memory_bytes: 16280
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(void){
  int n,i,a[100005],ans=0;
  
  cin >> n;
  for (i=1;i<=n;i++) cin >> a[i];
  
  for (i=1;i<=n;i++){
    if (a[a[i]]==i) ans++;
  }
  
  cout << ans/2 << endl;
  
  return 0;
}

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

int check( string str ){
  stack <char> ch;
  int i;
  int len = str.size();
  for( i = 0; i < len; i++ ){
    if( !(str[i] == '(' || str[i] == ')' || str[i] == '[' || str[i] == ']' ))continue;
    if( str[i] == '(' || str[i] == '[') ch.push(str[i]);
    else {
     
      if( ch.empty() ){
	  return 0;
	}
    
      if( ch.top() != '(' && str[i] == ')' ) return 0;
      else if( ch.top() == '(' && str[i] == ')' ) ch.pop();
      else if( ch.top() != '[' && str[i] == ']' ) return 0;
      else if( ch.top() == '[' && str[i] == ']' ) ch.pop();

    }
  }
    
  if( !( ch.empty() ) ) return 0;
  return 1;
}

int main(){
 
  string str;
  while( getline(cin,str) ){
    if( str == "." ) break;
    if( check(str) == 1 ) cout << "yes" << endl;
    else cout << "no" << endl;
  }

  return 0;
}

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

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

int main() {
    string s;
    string ans;
    cin >> s;
    if (s == "Sunny")
        ans = "Cloudy";
    else if (s == "Cloudy")
        ans = "Rainy";
    else {
        ans = "Sunny";
    }

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

Measured memory_bytes: 256
import string, heapq

def solve():
    s = input()
    s_len = len(s)
    k = int(input())
    alpha = string.ascii_lowercase
    subs = []
    for a in alpha:
        a_indexs = [i for i, x in enumerate(s) if x == a]
        for index in a_indexs:
            for i in range(index, min(index+5, s_len)):
                sub = s[index:i+1]
                if sub in subs:
                    continue
                else: 
                    heapq.heappush(subs, s[index:i+1])                
        if len(subs) >= k:
            break
    for i in range(k-1):
        heapq.heappop(subs)
    print(heapq.heappop(subs))

if __name__ == "__main__":
    solve()

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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int> vec(M);
  int a=0;
  for(int i=0; i<M; i++){
    cin >> vec.at(i);
    a+=vec.at(i);
  }
  if(a>N)
    cout << "-1" << endl;
  else
    cout << (N-a) << endl;
  
}

Measured memory_bytes: 3604
#include <stdio.h>

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

Measured memory_bytes: 3256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for (int i=0,_n=(int)(n); i < _n; i++)
template<class T> bool chmax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<class T> bool chmin(T &a, T b) { return a > b ? (a = b, true) : false; }
 
typedef long long ll;

int A[100000 + 10];
ll B[100000 + 10];

int main2() {
  int N;
  scanf("%d", &N);
  ll sA = 0;
  REP(i, N) {
    scanf("%d", &A[i]);
    sA += A[i];
  }
  REP(i, N) {
    B[i] = A[(i+1) % N] - A[i];
  }
  ll S = (ll)N * (N+1) / 2;
  if (sA % S != 0) {
    cout << "NO" << endl;
    return 0;
  }
  ll K = sA / S;
  REP(i, N) {
    B[i] -= K;
    if (B[i] > 0 || B[i] % N != 0) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}

Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String args[]) {
        FastReader sc = new FastReader();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        int train = a;
        if (a > b) train = b;
        int bus = c;
        if (c > d) bus = d;
        System.out.println(train + bus);
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

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

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                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());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

const int MAXM = 1000000;

int n, m;
char iois[MAXM];

void removeio() {
  for (int i = 1; i < m - 1; i++)
    if (iois[i] == 'O' and (iois[i - 1] != 'I' or iois[i + 1] != 'I'))
      iois[i] = ' ';

  iois[0] = iois[m - 1] = ' ';

  for (int i = 1; i < m - 1; i++)
    if (iois[i] == 'I')
      iois[i] = ' ';
}

int count() {
  int val = 0;
  for (int i = 0; i + 2 * n < m; i++) {
    bool flag = true;
    for (int j = 0; j < 2 * n ; j += 2) {
      if (iois[i + j] != 'O') {
        flag = false;
        break;
      }
    }
    if (flag) val++;
  }
  return val;
}

int main() {
  while (cin >> n and n != 0) {
    cin >> m;

    string s;
    cin >> s;

    for (int i = 0; i < m; i++)
      iois[i] = s[i];

    removeio();

    cout << count() <<  endl;
  }
}

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

int main() {
  int A,B,N=0;
  string j,k="";
  cin>>A>>B;
  	for(int i=A;i<=B;i++){
      j=to_string(i);
      k=to_string(i);
      reverse(j.begin(),j.end());
      	if(j==k) N++;
    }
  cout<<N<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int a[100000][3];
int cmpint(const void *x, const void *y) {
	if (*(int *)x != *(int *)y)
		return *(int *)x - *(int *)y;
	else
		return *(int *)(x + sizeof(int)) - *(int *)(y + sizeof(int));
}
int main() {
	int n, m, id[100000][2], p = 0, num = 0;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &a[i][0], &a[i][1]);
		a[i][2] = i;
	}
	qsort(a, m, sizeof(a[0]), cmpint);
	for (int i = 0; i < m; i++) {
		id[a[i][2]][0] = a[i][0];
		if (p == a[i][0]) {
			num++;
			id[a[i][2]][1] = num;
		} else {
			num = 1;
			p = a[i][0];
			id[a[i][2]][1] = num;
		}
	}
	for (int i = 0; i < m; i++) {
		printf("%06d%06d\n", id[i][0], id[i][1]);
	}
	return 0;
}

Measured memory_bytes: 3436
while line=gets
n=line.to_i
a,result=0,0
while a<10
b=0
while b<10
c=0
while c<10
d=0
while d<10
if n==a+b+c+d
result+=1
end
d+=1
end
c+=1
end
b+=1
end
a+=1
end
puts result
end

Measured memory_bytes: 6088
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

struct www_t{
  string name;
  int w;
  int l;
  int d;
  int p;
  int num;
};

bool asc(www_t left,www_t right) {
    return left.p == right.p ? left.num < right.num : left.p > right.p;
}

int main(){
  int n;
  scanf ("%d",&n);
  while(n){
    vector<www_t> a(n);
    for(int t=0;t<n;++t){
      cin >> a[t].name >> a[t].w >> a[t].l >> a[t].d;
      a[t].num=t;
      a[t].p=a[t].w*3+a[t].d;
    }
    sort(a.begin(), a.end(),asc);
    for(int t=0;t<n;++t){
      cout << a[t].name << "," << a[t].p << endl;
    }
    scanf ("%d",&n);
    if(n){
      printf("\n");
    }
  }
}



Measured memory_bytes: 3236
//Abhinav ---IIIT_A
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define f(i,x,n) for(int i=x;i<(int)n;++i)
#define vpii vector<pair<int,int>>
#define vi vector<int>
#define mpii map<pair<int,int>,int>
#define mpivpii map<int,vector<pair<int,int>>>
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define mpi map<int,int>
#define vvi vector<vector<int>>
#define vvvi vector<vvi>
ld pie=3.141592653589;
int mod=1e9+7;


void solve(){
 	int n,w; cin>>n>>w;
 	int val[n],wei[n]; 
 	f(i,0,n) cin>>wei[i]>>val[i];
 	int dp[n+1][w+1];	
 	f(i,0,n+1) f(j,0,w+1) dp[i][j]=0;
 	f(i,0,n){
 		f(j,0,w+1) if(j>=wei[i]) dp[i+1][j] = max(dp[i][j],dp[i][j-wei[i]]+val[i]); 
 		else dp[i+1][j]=dp[i][j];
   }
 	cout<<dp[n][w];
}

signed main(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
  int t=1; //cin>>t;
  while(t--) solve();
  return 0;
}
// check for overflows dummy !!!


Measured memory_bytes: 82424
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
    WRITER:kakitamasziru/OxOmisosiru
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#include <iostream> // cout, endl, cin
#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 <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
//#include <unordered_map> // unordered_map
//#include <unordered_set> // unordered_set
#include <bitset> // bitset
//#include <cctype> // isupper, islower, isdigit, toupper, tolower
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

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; }
const long long INF = 100100100100100100;
const int MOD = 1000000007;
typedef pair<bool,long long> P;
//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long dist[114][114];
//隣接行列で辺を管理
//E[][].first = 辺の有無,E[][].second = 辺の重み
P E[114][114];
int V;

void warshall_floyd(){
    for(int i = 1;i<=V;i++){
        for(int j = 1;j<=V;j++){
            //そもそも辺が存在しないならそのままで良い
            if(dist[j][i] == INF) continue;
            for(int k = 1;k<=V;k++){
                if(dist[i][k] == INF) continue;
                dist[j][k] = min(dist[j][k],dist[j][i]+dist[i][k]);
            }
        }
    }
}

int main() {
    int edge;cin >> V >> edge;
    for(int i = 0;i<114;i++){
        for(int j = 0;j<114;j++) {
            dist[i][j] = INF;
            E[i][j].first = false;
        }
    }

    for(int i = 1;i<=V;i++) dist[i][i] = 0;
    
    //とりあえず現時点ではE[i][j]に辺が存在すればdist[i][j]の最短距離はiとjの一辺の重み
    for(int i = 0;i<edge;i++){
        int from,to;
        cin >> from >> to;
        from++;to++;
        E[from][to].first = true;
        int d;cin >> d;
        E[from][to].second = d;
        dist[from][to] = E[from][to].second;
    }

    

    warshall_floyd();

    //負の閉路を持っているかの判定
    //負の閉路を持っている=dist[i][i]が初期の0より小さくなりえる
    for(int i = 1;i<=V;i++){
        if(dist[i][i] < 0) {
            cout << "NEGATIVE CYCLE" << endl;
            return 0;
        }
    }

    for(int i = 1;i<=V;i++){
        for(int j = 1;j<=V;j++){
            if(dist[i][j] == INF) cout << "INF";
            else cout << dist[i][j];
            //ここにNEGATIVE CYCLEの処理
            if(j != V) cout << " ";
        }
        cout << endl;
    }





    // PLEASE GIVE ME THE "ACCEPTED" !
}


Measured memory_bytes: 3400
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#define rep(i,n) for (long long i=0; i < (n); ++i)
#define rep2(i,n,m) for(long long i=n;i<=m;i++)
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
int main() {
 ll n ;
 cin >> n ;
 vector<int> A(n) ;
 rep(i,n) cin >>A[i] ;
 vector<int> B(n) ;
 rep(i,n) B[A[i]-1] =i;
 ll ans=0 ;
 ll len=1 ;
 rep(i,n-1){
   if(B[i]<B[i+1]) {
    len ++ ;
  }
  else len=1 ;
   ans= max(ans,len) ;
 }
  if(n==1)
  cout <<0 <<endl ;
   else
   cout << n-ans <<endl ;
     return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
const int N=2e5+5;
int dist[200005];

signed main()
{
 int a,b;
 cin>>a>>b;
 cout<<a*b<<"\n";
}


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

using namespace std;

typedef long long int ll;
typedef pair<int, int> P;
#define INF 10000000000000
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
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; }

int main()
{
	int K, X;
	int min, max;

	cin >> K >> X;

	if (X - K < -1000000)
		min = -1000000;
	else
		min = X - K + 1;

	if (X + K > 1000000)
		max = 1000000;
	else
		max = X + K - 1;

	for (int i = min; i <= max; i++)
	{
		cout << i;
		if (i != max)
			cout << " ";
	}

	return 0;
}

Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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

    int N, M, Q; cin >> N >> M >> Q;
    vi L(M), R(M); REP(i, M) cin >> L[i] >> R[i];
    vi p(Q), q(Q); REP(i, Q) cin >> p[i] >> q[i];

    vvi s(N + 1, vi(N + 1, 0));
    REP(i, M) s[L[i]][R[i]]++;

    FOR(i,1,N+1) {
        FOR(j,1,N+1) {
            s[i][j] += s[i - 1][j];
            s[i][j] += s[i][j - 1];
            s[i][j] -= s[i - 1][j - 1];
        }
    }

    REP(i,Q) {
        int ans = s[q[i]][q[i]] - s[p[i]-1][q[i]] - s[q[i]][p[i]-1] + s[p[i]-1][p[i]-1];
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	ll n,x;
	ll a[100001];

	cin>>n>>x;

	rep(i,n){
		cin>>a[i];
	}
	ll total=0;
	if(a[0]>x){
		total=a[0]-x;
		a[0]=x;
	}

	for(ll i=1; i<n; i++){
		if(a[i]+a[i-1]>x){
			total+=a[i]+a[i-1]-x;
			a[i]=x-a[i-1];
		}
	}
	cout<<total<<endl;

	return 0;
}


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

using namespace std;

int n;
string arr[100005];

int main()
{
	cin >> n;
	int a=0,b=0,ab=0,ans=0;
	for(int i=0;i<n;i++) cin >> arr[i];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<arr[i].size()-1;j++)
		{
			ans+=(arr[i][j]=='A'&&arr[i][j+1]=='B');
		}
		if(arr[i][0]=='B'&&arr[i].back()=='A') ab++;
		else if(arr[i][0]=='B') b++;
		else if(arr[i].back()=='A') a++;
	}
	//cout << a << " " << ab << " " << b << " " << ans << endl;
	if(a&&ab)
	{
		// A BA BA BA ... B A B A B
		a--; ans+=ab;
		ab=0;
		if(b){b--; ans++;}
		ans+=min(a,b);
	}
	else if(a)
	{
		// A B A B ...
		ans+=min(a,b);
	}
	else if(ab)
	{
		// BA BA BA BA ... B
		ans+=ab-1;
		if(b) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1536