akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    int a, b;
    cin >> a >> b;

    int diff = b - a;

    int towerL = 1;
    for (int i = 2; i <= 999; i++) {
        if (diff == i) {
            cout << towerL - a << endl;
            return 0;
        }
        towerL += i;
    }
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c;cin>>a>>b>>c;
  if((a==b&b!=c)|(b==c&c!=a)|(c==a&a!=b)){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
import string
A = [chr(i) for i in range(ord('a'), ord('z')+1)]
B = {}
for i in range(26):
    B[A[i]] = i
s = input()
n = len(s)
def a():
    C = [0] * 26
    for i in range(n):
        C[B[s[i]]] = 1

    if n < 26:
        i = 0
        while C[i] == 1:
            i += 1
        return s + A[i]
    else:
        for i in range(25, -1, -1):
            t = s[i]
            for j in range(B[s[i]]+1, 26):
                if C[j] == 0:
                    return s[:i] + A[j]
            C[B[t]] = 0
        return -1
print(a())
                




Measured memory_bytes: 38512
N,M = map(int,input().split())
edge_list = [list() for i in range(N)]
for i in range(M):
        a,b = map(int,input().split())
        edge_list[a-1].append(b-1)
        edge_list[b-1].append(a-1)
done = [0] * N
chk = 0
def dfs(s,done):
    done = done[:]
    global chk
    done[s] = True
    if all(done):
        chk += 1
    for i in edge_list[s]:
        if not done[i]:
            dfs(i,done)
    return 0
dfs(0,done)
print(chk)

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

using namespace std;

int n, k;
int a[200000];
map<int, vector<int>> e;
long long ans = 0;

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

    cin >> n >> k;

    e[0].push_back(0);
    int t, sum = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> t;
        sum = (sum + t) % k;
        a[i] = ((sum - i - 1) % k + k)%k;
        e[a[i]].push_back(i + 1);
    }

    for (auto a : e)
    {
        int tail = 0;
        for (int i = 1; i < a.second.size(); i++)
        {
            while (a.second[i] - a.second[tail] >= k)
                tail++;

            ans += i - tail;
        }
    }

    cout << ans;

	return 0;
}


Measured memory_bytes: 22912
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
ll p,ans,a,b,c,d,x;
int T;

int main() {
	p=1;for(int i=1;i<=30;i++)p*=3;
	scanf("%d",&T); 
	while(T--) {
		scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
		a--;b--;c--;d--;
		if(abs(a-c)>abs(b-d)) swap(a,b),swap(c,d);
		x=p; ans=abs(a-c)+abs(b-d);
		while(x) {
			ll A=a/x,C=c/x,B=b/x,D=d/x;
			if(A^C) {ans=abs(a-c)+abs(b-d);break;}
			if(A==1&&abs(B-D)>1) {ans=min(a%x+c%x+2,2*x-a%x-c%x)+abs(b-d);break;}
			a%=x;c%=x;x/=3;
		}
		printf("%lld\n",ans);
	}
	return 0;
}
		


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

const ll mod = 1000000007;
const double eps = 1e-8;
const ll INF = 1e9+1;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int main() {
    int N;
    cin >> N;
    vector<int> h(N);
    for (int i=0; i<N; ++i) cin >> h[i];

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

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

class Info {
public:
	int id;
	int pos;
	int left;
	Info() {}
	Info(int id, int pos, int left) {
		this->id = id;
		this->pos = pos;
		this->left = left;
	}
	bool operator< (const Info &a) const {
		return pos < a.pos;
	}
};

vector<Info> infos;
map<int, int> posmap;

signed main() {
	int n;
	cin >> n;

	vector<int> x(n);
	rep(i, n) cin >> x[i];

	rep(i, n) {
		posmap[x[i]] = i;
		infos.push_back(Info(i, x[i], i));
	}

	sort(all(infos));

	int infoPt = 0;
	int last = n * n;
	vector<int> ret(last + 1);
	queue<int> trash;
	for (int i = 1; i <= last; i++) {
		if (posmap.find(i) != posmap.end()) {
			int tmp = 0;
			while (infos[tmp].id != posmap[i]) tmp++;
			if (infos[tmp].left > 0) {
				cout << "No" << endl;
				return 0;
			}
			rep(j, n - infos[tmp].id - 1) {
				trash.push(infos[tmp].id + 1);
			}
			infos[tmp].left = 0;
			ret[i] = posmap[i] + 1;
			continue;
		}

		while (infoPt < n && infos[infoPt].left == 0) infoPt++;
		
		if (infoPt == n) {
			if (trash.size() == 0) {
				cout << "No" << endl;
				return 0;
			}
			ret[i] = trash.front();
			trash.pop();
		} else {
			ret[i] = infos[infoPt].id + 1;
			infos[infoPt].left--;
		}
	}

	cout << "Yes" << endl;
	for (int i = 1; i <= last; i++) {
		if (i < last) {
			cout << ret[i] << ' ';
		} else {
			cout << ret[i];
		}
	}
	cout << endl;

    return 0;
}


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

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
#define all(a) (a).begin(),(a).end()
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
constexpr ll mod = 1e9+7;
template<class T>void add(T &a, const T &b){ a+=b; a%=mod; }

signed main(){
  int n, w; cin >> n >> w;
  vi ws(n); rep(i,n) cin >> ws[i];
  sort(all(ws));
  int ans = 0;
  rep(i,n){ // [0,i)を使いiを使わない場合
    vvi dp(n+1,vi(w+1,0)); // dp[i][j] : i-1個目まででjになる場合の数
    int tmp = accumulate(ws.begin(),ws.begin()+i,0);
    if(tmp > w) break;
    dp[i+1][tmp] = 1;
    FOR(j,i+1,n) FOR(k,tmp,w+1){
      add(dp[j+1][k], dp[j][k]);
      if(k + ws[j] <= w){
	add(dp[j+1][k+ws[j]], dp[j][k]);
      }
    }
    FOR(k,max(tmp,w+1-ws[i]),w+1){
      add(ans, dp[n][k]);
    }
  }
  if(accumulate(all(ws),0) <= w) ans++;
  cout << ans << endl;
}


Measured memory_bytes: 18608
#include <bits/stdc++.h>
using namespace std;
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL);                \
    cout.tie(NULL);
#define endl '\n'
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define fr1(i, a, b) for (ll i = a; i >= b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector<pair<ll, ll>>
#define viii vector<pair<ll, pair<ll, ll>>>
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define mp(i, j) make_pair(i, j)
#define fi first
#define se second
#define input(a, n) fr(i, 0, n) cin >> a[i]
#define output(a, n) fr(i, 0, n) cout << a[i] << " "
#define dbg cout << "hurr" << endl;
#define dbg2 cout << "hurr2" << endl;
#define md 1000000007
#define inf 999999999999999999
#define sp << " " <<
#define pi 3.14159265358979323846
#define fixd(x) cout << fixed << setprecision(x);
#define sz size()

int main()
{
    fast;

    string s;
    cin>>s;
    ll n = s.length();
    char arr[n + 1];
    strcpy(arr, s.c_str());
    ll sum = 0;
    fr(i,0,n)
    {
      sum = sum + arr[i] - '0';
    }
    if(sum%9==0)
    {
      cout<<"Yes";
    }
    else cout<<"No";


return 0;}


Measured memory_bytes: 3920
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	ll N;
	cin >> N;
	vector <ll> h(N, 0);
	for (int ii = 0; ii < N; ++ii){
		cin >> h[ii];
	}

	vector <ll> dp(N, 0);
	dp[0] = 0;
	dp[1] = abs(h[1]-h[0]);
	for (int ii = 2; ii < N; ++ii){
		dp[ii] = min(dp[ii-2] + abs(h[ii]-h[ii-2]), dp[ii-1] + abs(h[ii]-h[ii-1]));
	}
	
	cout << dp[N-1] << endl;

	return 0;
}


Measured memory_bytes: 1792
from collections import deque 
n = int(input())

a = list(input().split())
b = []

q = deque()

for i in range(n):
    x = a[i]
    if n%2 == i%2:
        q.append(x)
    else:
        q.appendleft(x)

    
print(" ".join(q))    

Measured memory_bytes: 118360
#include <bits/stdc++.h>
#define LL long long
using namespace std;
LL A[4];
int main()
{
#ifdef hk_cnyali
	freopen("A.in", "r", stdin);
	freopen("A.out", "w", stdout);
#endif
	for (int i = 1; i <= 3; ++i) scanf("%lld", &A[i]);
	for (int i = 1; i <= 3; ++i) if (!(A[i] & 1)){cout<<0<<endl; return 0;}
	sort(A + 1, A + 3 + 1);
	printf("%lld\n", A[1] * A[2]);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int a,b;
string s;

int main(){
	while(cin>>s>>a>>b){
		cout<<s<<" "<<a+b<<" "<<a*200+b*300<<endl;
	}
}

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

int main(){
    int n;
    cin>>n;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    map<ll,ll>mp;
    rep(i,n){
        mp[a[i]]++;
    }
    ll cnt=0;
    for(auto p:mp){
        if(p.first==p.second)cnt+=0;
        else if(p.second>p.first)cnt+=p.second-p.first;
        else cnt+=p.second;
    }
    cout<<cnt<<endl;
}




Measured memory_bytes: 7040
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007LL;
const int INF = LLONG_MAX;

signed main(){
    
    int n; cin >> n;
    int cnt = 0;
    bool flag = false;
    for(int i = 0; i < n; i++){
        int a; cin >> a;
        if(a % 2 != 0) cnt--;
        else if(a % 4 == 0) cnt++;
        else flag = true;
    }

    if(flag) cnt--;
    if(cnt >= -1) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#define N 101
using namespace std;
int A[N][N];
bool visited[N];
int n;
int d[N];
int distance;
queue<int> node;

void bfs(){
    while(!node.empty()){
        int temp=node.front();
        for(int i=0;i<n;i++){
            if(temp==i) continue;
            if(!visited[i] && A[temp][i]==1){
                d[i]=d[temp]+1;
                visited[i]=true;
                node.push(i);
            }
        }
        node.pop();
    }
}

int main(){
    int k,num;
    int e;
    cin>>n;
    for(int i=0;i<n;i++){
        visited[i]=false;
        d[i]=-1;
        for(int j=0;j<n;j++)
            A[i][j]=0;
    }
    for(int i=0;i<n;i++){
        cin>>k;
        k--;
        cin>>num;
        for(int j=0;j<num;j++){
            cin>>e;
            e--;
            A[k][e]=1; //A[e][k]=1;
        }
    }

    node.push(0);
    visited[0]=true;
    d[0]=0;
    bfs();

    for(int i=0;i<n;i++){
        cout<<i+1<<' '<<d[i]<<endl;
    }

    return 0;

}



Measured memory_bytes: 3124
#虚無疲れAC
mod=10**9+7
n,m=map(int,input().split())
broken={i:False for i in range(n+1)}
for i in range(m):
    a=int(input())
    broken[a]=True
way_to_go=[0 for i in range(n+1)]
way_to_go[0]=1
if broken[1]==True:
    way_to_go[1]=0
else:
    way_to_go[1]=1
for j in range(2,n+1):
    if broken[j]==False:
        if broken[j-1]==False:
            way_to_go[j]+=way_to_go[j-1]
        if broken[j-2]==False:
            way_to_go[j]+=way_to_go[j-2]
        way_to_go[j]%=mod
print(way_to_go[n])    

Measured memory_bytes: 16192
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

char board[101 * 101];

int solve(int pos) {
	char c = board[pos];
	board[pos] = '0';
	if (c == '.') return pos;
	else if (c == '0') return -1;
	else if (c == '>') return solve(pos + 1);
	else if (c== '<') return solve(pos - 1);
	else if (c == '^') return solve(pos - 101);
	else return solve(pos + 101);
}

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

	while (cin >> H >> W, H) {
		for(int y = 0; y < H; y++)
			for(int x = 0; x < W; x++)
				cin >> board[y*101 + x];
		int ret = solve(0);
		if (ret == -1)
			cout << "LOOP" << endl;
		else
			cout << ret % 101 << " " << ret / 101 << endl;
	}
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int A[101010];
int L[101010];
int R[101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	for(i=1;i<=N;i++) {
		cin>>A[i];
		L[i]=__gcd(A[i],L[i-1]);
	}
	
	int ma=0;
	for(i=N;i>=1;i--) {
		R[i]=__gcd(R[i+1],A[i]);
		ma=max(ma,__gcd(L[i-1],R[i+1]));
	}
	cout<<ma<<endl;

}

int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
#include <locale>
#include <cmath>
#include <iomanip>
#include <numeric>

using namespace std;

int main() {
    vector<int> data = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;
    cin >> K;
    cout << data[K-1] << endl;
    return 0;
}

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

using namespace std;

typedef long long int ll;

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

    int a, b, c;

    cin >> a >> b >> c;

    if((a <= c && c <= b) || (b <= c && c <= a)){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }

    return 0;
}



Measured memory_bytes: 256
import java.util.*;
 
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int M = Integer.parseInt(sc.next());
        int[] l = new int[M+1];
        int[] r = new int[M+1];
        l[0] = Integer.parseInt(sc.next());
        r[0]= Integer.parseInt(sc.next());
        int max = r[0];
        int min = l[0];
        for(int i = 1; i < M; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
            if(l[i] > min) {
                min = l[i];
            }
            if(r[i] < max) {
                max = r[i];
            }
            if(max - min < 0) {
                max = -1;
                min = 0;
                break;
            }
        }
        
        System.out.println(max - min + 1);
    }
}

Measured memory_bytes: 49344
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N, K;
        cin >> N >> K;
        vll rcnt(K);
        rep(i, 1, N+1) ++rcnt[i % K];

        ll ans = 0;
        rep(r, 0, K) {
                ll b = (K - r) % K;
                ll c = (K - r) % K;
                if ((b+c) % K == 0) {
                        ans += rcnt[r] * rcnt[b] * rcnt[c];
                }
        }
        cout << ans << endl;
}

Measured memory_bytes: 4844
import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;

T RD(T = string)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }

long mod = pow(10, 9) + 7;
long moda(long x, long y) { return (x + y) % mod; }
long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; }
long modm(long x, long y) { return (x * y) % mod; }

void main()
{
	auto N = RD!long;
	long[] C, S, F;
	foreach (i; 0..N-1)
	{
		C ~= RD!long;
		S ~= RD!long;
		F ~= RD!long;
	}

	foreach (i; 0..N-1)
	{
		long t;
		foreach (j; i..N-1)
		{
			t = max(t, S[j]);
			t = (t / F[j] + (t % F[j] != 0 ? 1 : 0)) * F[j];
			t += C[j];
		}
		writeln(t);
	}
	writeln(0);

	stdout.flush();
}

Measured memory_bytes: 380
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
vi rui(111111);
bool prime[111111]={};
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll q;cin>>q;
  prime[2] = true;
  for(ll i=3;i<111111;i+=2){
    bool fl = true;
    for(ll j=2;j<=sqrt(i);j++){
      if(i%j == 0){
	fl = false;
	break;
      }
    }
    prime[i] = fl;
  }
  for(ll i=3;i<111111;i++){
    if(i%2&&prime[i] && prime[(i+1)/2])rui[i] += rui[i-1]+1;
    else rui[i] += rui[i-1];
  }
  //for(int i=0;i<100;i++)cout<<rui[i]<<" ";
  while(q--){
    ll l,r;cin>>l>>r;
    cout<<rui[r]-rui[l-1]<<endl;
  }
  return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int n,k;
    cin >> n >> k;
    int arr[200000] = {};
    int x;
    for(int i=0;i<n;i++){
        cin >> x;
        arr[x-1]++;
    }
    sort(arr, arr+n);
    int ans = 0;
    for(int i=n-1;i>n-k-1;i--){
        ans += arr[i];
    }
    cout << n-ans << endl;
}


Measured memory_bytes: 1024
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)

def main():
    a = ni()
    b = ni()

    print(6 - a - b)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <stack>
#include <memory.h>
#include <list>
#include <numeric>
#include <functional>
#include <complex>
#include <cassert>
#include <regex>
#include <random>

#define ll long long
#define ld long double
#define ull unsigned ll
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pii pair<int,int> 
#define vi vector<int>
#define vpii vector<pii>
#define vvi vector<vector<int>>
#define forn(it,from,to) for(int (it)=from; (it)<to; (it)++)
const int  Inf = 2 * 1000 * 1000 * 1000;
ll LINF = (ll)4e18;
using namespace std;
#define M_PI       3.14159265358979323846   // pi

void min_self(ll &a, ll b) {
	a = min(a, b);
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("sum.in", "r", stdin);
	//freopen("sum.out", "w", stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, W;
	cin >> n >> W;

	ll maxval = n * 1000;
	vector<ll>D(maxval + 1, 1e18);

	D[0] = 0;

	for (int i = 1; i <= n; i++) {
		ll w, cost;
		cin >> w >> cost;

		for (int j = maxval - cost; j >= 0; j--) {
			min_self(D[j + cost], D[j] + w);
		}
	}
	ll mx = 0;
	for (ll i = 0; i <= maxval; i++) {
		if (D[i] <= W) {
			mx = max(mx, i);
		}
	}
	cout << mx;
 	return 0;
}

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

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

    int n, input, count = 0;
    ;
    vector<int> vi1, vi2;

    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> input;
        if (input != i)
            count++;
    }

    if (count <= 2)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

Measured memory_bytes: 256
n,m,q = map(int, input().split())

a = [[0]*(n+1) for i in range(n+1)]

for i in range(m):
    l,r = map(int, input().split())
    a[l][r]+=1

b = [[0]*(n+1) for i in range(n+1)]

for i in range(1,n+1):
    for j in range(1,n+1):
        b[i][j]=b[i-1][j]+b[i][j-1]-b[i-1][j-1]+a[i][j]

for i in range(q):
    p,q = map(int, input() .split())
    ans = b[q][q]-b[p-1][q]-b[q][p-1]+b[p-1][p-1]
    print(ans)


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

int main() {
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  int ans = 1e9;
  for (int i = 0; i <= n - k; i++) {
    ans = min(ans, a[i + k - 1] - a[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <chrono>
#include <random>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

template<typename T> T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

template<typename T> T lcm(const T a, const T b) {
    return a / gcd(a, b) * b;
}

template<typename T> bool chmin(T& a, const T& b) {
    if (a > b) return a = b, true; else return false;
}

template<typename T> bool chmax(T& a, const T& b) {
    if (a < b) return a = b, true; else return false;
}

// End of template.

int main() {
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // cin.read(buf, sizeof buf); // 注意: ./a.out < in か pbp | ./a.out で入力すること

    int h, n;
    pii p[1010];
    cin >> h >> n;
    rep(i, n) cin >> p[i].first >> p[i].second;

    int dp[10200];
    fill(begin(dp), end(dp), INF);
    dp[0] = 0;

    rep(i, h) {
        rep(j, n) {
            chmin(dp[min(h, i + p[j].first)], dp[i] + p[j].second);
        }
    }

    print(dp[h]);

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
#define ll long long 
int main(void){
 ll x,y;
 cin>>x>>y;
int ans=0;
while(x<=y){
    ans++;
    x*=2;
}
cout<<ans<<endl;
}

Measured memory_bytes: 256
from math import sqrt
def calc_digit(n):
    res = 0
    while n != 0:
        res += 1
        n //= 10
    return res

n = int(input())
res = calc_digit(n)
for a in range(1, int(sqrt(n)) + 1):
    if n % a != 0:
        continue
    b = n // a
    f = max(calc_digit(a), calc_digit(b))
    res = min(res, f)
print(res)


Measured memory_bytes: 3060
import java.util.Scanner;

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

        int result = 0;
        for (int i = 1; i <= n; i = i+2) {
            int divisor = divisorCounter(i);
            if (divisor == 8) {
                result++;
            }
        }
        System.out.println(result);
    }

    private static int divisorCounter(int x) {
        int counter = 0;
        for (int i = 1; i <= x; i++) {
            if (x%i == 0) {
                counter++;
            }
        }
        return counter;
    }
}

Measured memory_bytes: 35680
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
int main() {
  int N,M,i,j;
  cin>>N;
  if(N%2==1){
    cout<<(N-3)*(N-1)/2+N-1<<endl;
  for(i=1;i<N;i++){
  cout<<N<<" "<<i<<endl;
  }
  M=N-1;
     for(i=1;i<N;i++){
       for(j=1;j<i;j++){
       if(i+j!=N){
  cout<<i<<" "<<j<<endl;
       }
  }
  }
  }else{
    cout<<(N-2)*N/2<<endl;
       for(i=1;i<N+1;i++){
       for(j=1;j<i;j++){
       if(i+j-1!=N){
  cout<<i<<" "<<j<<endl;
       }
  }
  }
  }
}


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

int main(){
  int N;
  string S;
  cin >> N >> S;
  int cnt = 1;
  for(int i = 1; i < N; ++i){
    if(S[i] != S[i-1]) cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main()
{

	int A,B,X ;
	cin>>A>>B>>X ;
	if (A==B && B==X)
		cout<<"YES" ;
	else if (A<=X && A+B>X)
		cout<<"YES" ;
	else
		cout<<"NO" ;



	return 0;

}

Measured memory_bytes: 256
#include<stdio.h>

int n,N[50];

int solve(int i,int m){
  if(m==0)return 1;
  if(i>=n)return 0;
  int res = solve(i+1,m)||solve(i+1,m-N[i]);
  return res;
}

int main(){
  int x,y;
    int i;

    scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&N[i]);
  scanf("%d",&x);
  for(i=0;i<x;i++){
    scanf("%d",&y);
    if(solve(0,y))printf("yes\n");
    else printf("no\n");

}
  return 0;
}



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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

int get(int x) {
    if (x == 0) return 0;
    int b = __builtin_popcount(x);
    return get(x % b) + 1;
}

int main() {
    int N;
    string X;
    cin >> N >> X;
    int cnt = 0;
    rep(i, N) if (X[i] == '1') cnt++;
    map<int, int> md;
    map<int, V<int>> p2;

    for (int m : {cnt - 1, cnt + 1}) {
        if (m <= 0) continue;
        int x = 0;
        for (auto c : X) {
            x = x * 2 + (c == '1');
            x %= m;
        }
        md[m] = x;

        p2[m].resize(N + 1);

        p2[m][0] = 1;
        for (int i = 1; i <= N; ++i) {
            p2[m][i] = p2[m][i - 1] * 2 % m;
        }
    }

    rep(i, N) {
        int np = cnt - (X[i] == '1' ? 1 : -1);
        int ans;
        if (np == 0) {
            ans = 0;
        } else {
            ans = md[np];
            int v = p2[np][N - 1 - i];

            if (X[i] == '1') {
                ans -= v;
            } else {
                ans += v;
            }
            ans = (ans % np + np) % np;
            ans = 1 + get(ans);
        }
        cout << ans << '\n';
    }

    return 0;
}

Measured memory_bytes: 5160
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

std::vector<int64_t> sftnum;

void bfs(int64_t n, bool seven, bool five, bool three) {
  if (n < std::pow(10, 9)) {
    bfs(n * 10 + 3, seven, five, true);
    bfs(n * 10 + 5, seven, true, three);
    bfs(n * 10 + 7, true, five, three);
  } else
    return;

  if (seven && five && three) {
    sftnum.push_back(n);
  }
  return;
}

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

  int64_t n;
  cin >> n;

  bfs(0, false, false, false);
  std::sort(sftnum.begin(), sftnum.end());
  int i;
  for (i = 0; i < sftnum.size(); i++) {
    if (sftnum[i] > n) break;
  }
  cout << i << endl;

  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>
#define true 1
#define false 0

int isprime(int x) {
  int i;
  if(x == 2) return true;
  if(x < 2 || !(x % 2)) return false;
  for(i = 3; i <= sqrt(x); i += 2) {
    if(!(x % i)) return false;
  }
  return true;
}

int main() {
  int n, i, x, count = 0;
  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    scanf("%d", &x);
    if(isprime(x)) count++;
  }
  printf("%d\n", count);
  return 0;
}



Measured memory_bytes: 2000
#include <stdio.h>

int main(void){
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if ((a == b)&&(b == c)){
        printf("1\n");
    }else if((a != b)&&(b != c)&&(c != a)){
        printf("3\n");
    }else{
        printf("2\n");
    }
    return 0;
}

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

const int D = 1e9;
const int SIZE = 2e5 + 5;
int n;
struct P{
ll dat;
int c[4];
} a[SIZE], d[SIZE];
int cnt[50][50];

int main()
{
	double b;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
	{
		scanf("%lf", &b);
		a[i].dat = llround(b * D);
		ll p = a[i].dat;
		while (p % 2 == 0)
		{
			++a[i].c[2];  p /= 2;
		}
		while (p % 5 == 0)
		{
			++a[i].c[3]; p /= 5;
		}
		++cnt[a[i].c[2]][a[i].c[3]];
	}
	ll ans = 0;
	for (int i = 0; i <= 49; ++i)
	{
		for (int j = 0; j <= 49; ++j)
		{
			for (int k = 0; k <= 49; ++k)
			{
				for (int l = 0; l <= 49; ++l)
				{
					if (min(i + k, j + l) >= 18)
					{
						if (i == k && j == l) ans += (ll)cnt[i][j] * (cnt[k][l] - 1);
						else ans += (ll)cnt[i][j] * cnt[k][l];
					}
				}
			}
		}
	}
	printf("%lld\n", ans >> 1);
	return 0;
}

Measured memory_bytes: 8468
let s = readLine()!.split(separator: " ").map { Int($0)! }
let n = s[0], k = s[1]
let a = readLine()!.split(separator: " ").map { Int($0)! }

var now = 0
if k < 2*n {
  (0..<k).forEach { _ in now = a[now] - 1 }
} else {
  var past = [Bool](repeating: false, count: n)
  var step1 = 0, step2 = 0
  for i in 0..<n+1 {
    now = a[now] - 1
    if past[now] {
      step1 = i + 1
      break
    } else {
      past[now] = true
    }
  }
  step2 = now
  for i in 1..<n+1 {
    now = a[now] - 1
    if now == step2 {
      step2 = i
      break
    }
  }
  for _ in 0..<((k-step1)%step2) {
    now = a[now] - 1
  }
}
print(now+1)

Measured memory_bytes: 19280
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
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 ll INF = 1LL << 60;
//const int INF = 1001001001;
string t[7]={"SUN","MON","TUE","WED","THU","FRI","SAT"};

int main(void){
    string s;
    cin >> s;
    int ans=0;
    REP(i,7){  
        if(t[i]==s) ans=7-i;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3628
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		List<Integer> results = new ArrayList<>();
		while(true) {
			
			String[] input = sc.nextLine().split(" ");
			if(input[1].equals("?")) break;
			
			int a = Integer.parseInt(input[0]);
			int b = Integer.parseInt(input[2]);
			
			switch (input[1]) {
			case "+":
				results.add(a + b);
				break;

			case "-":
				results.add(a - b);
				break;
				
			case "*":
				results.add(a * b);
				break;
				
			case "/":
				results.add(a / b);
				break;
				
			default:
				break;
			}
			
		}
		sc.close();
		
		results.forEach(System.out::println);
		
	}

}

Measured memory_bytes: 31740
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np
# import sys
# sys.setrecursionlimit(10**4)

def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]
MOD = 10**9 + 7


def gcd(a, b):
    """ Greatest Common Divisor(最大公約数) """
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    """ Least Common Multiple(最小公倍数) """
    return a * (b // gcd(a, b))


def calc_inverse_element_with_Fermat(a, MOD):
    """
    法をMODとしたときのaの逆元bを返す
    Fermatの小定理を用いる
    a * b = 1 (mod = MOD)

    Attention
    ---------
    MOD は素数の必要がある
    """
    return pow(a, MOD-2, MOD)


N = _i()
a_list = _li()

a_lcm = 1
for a in a_list:
    a_lcm = lcm(a_lcm, a)

a_lcm %= MOD
ans = 0
for a in a_list:
    ans = (ans + a_lcm * calc_inverse_element_with_Fermat(a, MOD)) % MOD
print(ans)


Measured memory_bytes: 4084
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

ll X;

int main() {

	cin >> X;

	ll a = 100;
	for (ll i = 0; ; ++i) {
		if (a >= X) {
			cout << i << endl;
			return 0;
		}
		a *= 1.01;
	}



	return 0;
}


Measured memory_bytes: 3636
// atcoder/abc092/C/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

struct edge {
  int to, cap, rev;
};

const int N = 200 + 10;
vector<int> g[N];

void add_edge(int src, int dst)
{
  g[src].push_back(dst);
  g[dst].push_back(src);
  return ;
}

int match[N];
int vis[N], x;
bool rec(int curr)
{
  vis[curr] = x;
  each (next, g[curr]) {
    int w = match[next];
    if (w < 0 || (vis[w] != x && rec(w))) {
      match[curr] = next;
      match[next] = curr;
      return true;
    }
  }
  return false;
}

int matching(int n = N)
{
  int res = 0;
  fill(match, match + N, -1);
  x = 1;
  fill(vis, vis + N, 0);
  for (int i = 0; i < n; ++i) {
    if (match[i] < 0) {
      res += rec(i);
      ++x;
    }
  }
  return res;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    fill(g, g + N, vector<int>());

    vector<pair<int, int>> a(n);
    vector<pair<int, int>> b(n);
    cin >> a >> b;

    random_shuffle(a.begin(), a.end());
    random_shuffle(b.begin(), b.end());

    for (int i = 0; i < a.size(); ++i) {
      for (int j = 0; j < b.size(); ++j) {
        if (a[i].first < b[j].first && a[i].second < b[j].second) {
          add_edge(i, j + n);
        }
      }
    }

    cout << matching() << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
  
int main(){
  int G[100][100];
   
  for(int i=0;i<100;i++)
    for(int j=0;j<100;j++)
      G[i][j]=(i==j?0:1000);
   
  int n,e;
  cin>>n>>e;
   
  for(int i=0;i<e;i++){
    int a,b;
    cin>>a>>b;
    G[a][b]=-1;
  }
   
  for(int k=0;k<n;k++)
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
        G[i][j]=min(G[i][j],G[i][k]+G[k][j]);
   
  for(int i=0;i<n;i++){
    if(G[i][i]<0){
      cout<<1<<endl;
      return 0;
    }
  }
   
  cout<<0<<endl;
  return 0;
}

Measured memory_bytes: 3128
// Date: 2020-03-13

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int n, m, du[N], dp[N];
VI g[N];

void bfs() {
    queue<int> q;
    rep(i, 1, n) if(du[i] == 0) q.push(i);
    while(!q.empty()) {
        int u = q.front(); q.pop();
        for(auto v : g[u]) {
            chkmax(dp[v], dp[u] + 1);
            du[v]--;
            if(du[v] == 0) q.push(v);
        }
    }
}

int main() {
    cin >> n >> m;
    while(m--) {
        int u, v;
        cin >> u >> v;
        g[v].pb(u);
        du[u]++;
    }
    bfs();
    int ans = 0;
    rep(i, 1, n) chkmax(ans, dp[i]);
    cout << ans;

    return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(n); i++)
#define REPR(i,n) for(int i=n; i>=0; i--)
#define FOR(i,m,n) for(int i=m; i<(n); i++)
#define ALL(v) v.begin(),v.end()
#define INF 2e9
using namespace std;
typedef long long ll;
 
 
int main()
{

    int H, W, h, w;

    cin >> H >> W;
    cin >> h >> w;
    
    cout << H*W - H*w -W*h + w*h << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int>L(N);
  for(int i=0;i<N;i++){
    cin >> L[i];
  }
  sort(L.begin(),L.end());
  int ans=0;
  for(int i=N-1;i>=0;i--){
    for(int j=i-1;j>=0;j--){
      auto itr = lower_bound(L.begin(),L.end(),L[i]+L[j]);
      int itr1 =L.end()-itr;
      ans += (N-1-i)-itr1;
    }
  }
  cout << ans << endl;
      
}
      


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

using namespace std;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if (2*max({a,b,c})==a+b+c) {
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }


    void calc()
    {
        Scanner cin = new Scanner();
        while (true)
        {
            int N = cin.nextInt();
            if (N == 0) break;
            int min = 99999999;
            int max = 0;
            int sum = 0;
            for (int i = 0; i < N; i++)
            {
                int now = cin.nextInt();
                sum += now;
                min = Math.Min(now, min);
                max = Math.Max(now, max);
            }
            sum -= max + min;
            Console.WriteLine(sum / (N-2));
        }
    }
}




class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        do
        {
            s = Console.ReadLine().Split(cs, StringSplitOptions.RemoveEmptyEntries);
        } while ((s.Length == 1 && s[0] == "") || s.Length == 0);
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}

Measured memory_bytes: 5640
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int a,b;
  cin>>a>>b;
  cout<<max(a+b,max(a-b,a*b))<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


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

int main()
{
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    
    string t;
    cin >> t;
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    
    if (s < t) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    
    
}

Measured memory_bytes: 384
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		for(int i=0; i<N; i++)
			A[i] = sc.nextInt();
		
		int ans = 1;
		int type=0;
		for(int i=1; i<N; i++) {
			int nextType = A[i-1]==A[i] ? 0 : (A[i-1]<A[i] ? 1 : -1);
			if(type==0) {
				type = nextType;
			} else {
				if(type*nextType<0) {
					ans++;
					type = 0;
				}
			}
		}
		
		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 52304