akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(){
  int n;
  char S[100],T[100];
  scanf("%s%s",S,T);
  for(n=0;n<100;n++){
    if(S[n]=='\0'){
      printf("Yes\n");
      break;
    }
    else if(S[n]!=T[n]){
      printf("No\n");
      break;}
  }
  return 0;
}
  

Measured memory_bytes: 1644
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <map>
using namespace std;

int main() {
	int n,k;
	char s[256];
	map<int,int> da1,da2;
	map<int,int>::iterator it;
	while(true) {
		n=atoi(gets(s));
		if (strlen(s)==0) break;
		if (da1.find(n)!=da1.end()) da1[n]++; else da1.insert(map<int,int>::value_type(n,1)); 
	}
	while(scanf("%d,%d",&n,&k)!=EOF) {
		if (da1.find(n)!=da1.end()) {
			if (da2.find(n)!=da2.end()) da2[n]++; else da2.insert(map<int,int>::value_type(n,da1[n]+1));
		}
	}
	for (it=da2.begin();it!=da2.end();it++) cout << (*it).first << ' ' << (*it).second << endl;    
    return 0;
}

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

int main(void){
vector<int> v;
int flg;

for (int i=0; i<12; i++){
int t;
cin >> t;
v.push_back(t);
}
sort(v.begin(), v.end());
flg = true;
for (int i=0; i<3; i++){
for (int j=0; j<3; j++){
if (v[j*4+i]!=v[j*4+i+1]) flg = false;
}
}
cout << (flg?"yes":"no") << endl;
return 0;
} 


Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int , int>
#define fast ios_base::sync_with_stdio(0)
#define mx 3002
char str1[mx], str2[mx];
int dp[mx][mx];
int len1, len2;
int main()
{
    scanf("%s%s",str1,str2);
    memset(dp, 0, sizeof dp);
    len1 = strlen(str1);
    len2 = strlen(str2);
    for(int i=1; i<=len1; i++){
        for(int j=1; j<=len2; j++){
            if(str1[i-1] == str2[j-1]){
                dp[i][j] = 1 + dp[i-1][j-1];
            }
            else{
                dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
            }
        }
    }
    stack<char> ans;
    int i = len1, j = len2;
    while(i>=1 && j>=1){
        if(i>0 && dp[i][j] == dp[i-1][j]){
            i = i-1;
        }
        else if( j>0 && dp[i][j] == dp[i][j-1]){
            j = j-1;
        }
        else{
            i--;
            j--;
            ans.push(str1[i]);
        }
    }
    while(!ans.empty()){
        printf("%c",ans.top());
        ans.pop();
    }
    printf("\n");
}



Measured memory_bytes: 35456
import sys
input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    L = 1
    R = 10**5
    for _ in range(M):
        l, r = map(int, input().split())
        L = max(L, l)
        R = min(R, r)
    
    print(max(R-L+1, 0))


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;

vector<int>E[1010];
int n, m, b[200020][2];
bool vis[1010], f[200020][2];
int q[1010], h, t, l[1010], r[1010];
int st[1010], tp;

void dfs1(int v, int a[], int w) {
	vis[v] = 1, a[v] = w;
	for (auto u : E[v])if (!vis[u])dfs1(u, a, w);
}

void work(int v) {
	tp = 0;
	for (auto u : E[v])st[++tp] = u;
	memset(vis + 1, 0, n); vis[v] = 1;
	for (int i = 1; i <= tp; i++)if (!vis[st[i]])dfs1(st[i], l, i);
	memset(vis + 1, 0, n); vis[v] = 1;
	for (int i = tp; i; i--)if (!vis[st[i]])dfs1(st[i], r, i);
	for (int i = 1; i <= m; i++)if (b[i][0] == v)f[i][0] = l[b[i][1]] != r[b[i][1]];
}

void dfs(int v) {
	vis[v] = 1;
	for (auto u : E[v])if (!vis[u])dfs(u);
}

int main() {
	scanf("%d %d", &n, &m);
	int x, y;
	for (int i = 1; i <= m; i++)scanf("%d %d", &x, &y), E[x].emplace_back(y), b[i][0] = x, b[i][1] = y;
	for (int i = 1; i <= n; i++) {
		memset(vis + 1, 0, n);
		dfs(i);
		for (int j = 1; j <= m; j++)if (b[j][1] == i)f[j][1] = vis[b[j][0]];
	}
	for (int i = 1; i <= n; i++)work(i);
	for (int i = 1; i <= m; i++) {
		if (f[i][0] != f[i][1])puts("diff");
		else puts("same");
	}

	return 0;
}

Measured memory_bytes: 4736
#include<bits/stdc++.h> 
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
typedef long long ll;
using namespace std;
inline int read(){
	int n=0,f=1;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if (c=='-') c=getchar(),f=-1;
	for(;c>='0'&&c<='9';c=getchar()) n=n*10+c-48;
	return n*f;
}
const int maxn=(1<<20)+5,mo=1e9+7;
int f[2][21][maxn],ne[maxn][21];
int i1,ans,i,j,n,m,k,s,t,w[25][25];
bool bz[25][25];
void mod(int &x){
	x-=(x>=mo)?mo:0;
}
int work(int s,int t){
	s>>=t,s&=-s;
	return s<<t;
}
int main(){
	n=read(),m=read(),k=read();
	n--;
	fo(i,1,k){
		int a=read(),b=read(),c=read();
		b--,bz[a][b]=1,w[a][b]=c;
	}
	s=(1<<n)-1;
	fo(k,0,s) 
	fo(i,0,n-1) if (!(k&(1<<i)))ne[k][i]=k+(1<<i)-work(k,i+1);
	f[1][0][0]=1;
	fo(i,1,m){
		i1^=1;
		fo(j,0,n-1){
			bool b=bz[i][j],x=w[i][j];
			int now=1<<j;
			fo(k,0,s) if (f[i1][j][k]){
				int sum=f[i1][j][k];
				fo(t,0,1){
					if (b&&t!=x) continue;
					int p=(k&now)>0;
					if (!t&&p) continue;
					if (t==p) mod(f[i1][j+1][k]+=sum);else
					mod(f[i1][j+1][ne[k][j]]+=sum);
				}
			}
		}
		memset(f[i1^1],0,sizeof(f[i1^1]));
		fo(k,0,s) f[i1^1][0][k]=f[i1][n][k];
	}i1^=1;
	fo(k,0,s) mod(ans+=f[i1][0][k]);
	printf("%d\n",ans);
} 

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

int main(void) {
	int a, b;
	cin >> a >> b;
	if (a < b)
		cout << "a < b" << endl;
	else if (a > b)
		cout << "a > b" << endl;
	else
		cout << "a == b" << endl;
	return 0;
}

Measured memory_bytes: 1156
import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
sys.setrecursionlimit(int(1e+6))
MOD = int(1e+9) + 7
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3

def main():
    N = i2n()
    H = i2nn()
    op = 0
    while True:
        b = False
        hmax = 0
        for i in range(N):
            if H[i] > 0:
                if b == False:
                    b = True
                    op += 1
                H[i] -= 1
                if hmax < H[i]:
                    hmax = H[i]
            else:
                b = False
        if hmax == 0:
            break
    print(op)

main()


Measured memory_bytes: 9432
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
    string s;
    int q;
    cin >> s >> q;
    bool rev = false;
    for (int i = 0; i < q; i++) {
        int ti;
        cin >> ti;
        if (ti == 1) {
            rev = !rev;
            continue;
        }
        int fi;
        char ci;
        cin >> fi >> ci;
        if ((!rev && fi == 1) || (rev && fi == 2))
            s.insert(s.begin(), ci);
        else
            s.insert(s.end(), ci);
    }
    
    if (rev)
        reverse(s.begin(), s.end());

    cout << s << endl;
    
    return 0;
}


Measured memory_bytes: 900
#include <stdio.h>
#include <stdlib.h>
 
int value[100];
int sp = 0;
 
void push(const int val)
{
    value[sp++] = val;
}
 
int pop()
{
    return value[--sp];
}
 
void operand(const char operand)
{
    int ch, val = operand - '0';
    while( (ch = getchar()) != ' ' ){
        val = val * 10 + (ch - '0'); 
    }
    push(val);
}
 
void operator(const char operator)
{
    int tmp1 = pop(), tmp2 = pop();
 
    switch( operator ){
    case '+': push(tmp2 + tmp1); break;
    case '-': push(tmp2 - tmp1); break;
    case '*': push(tmp2 * tmp1); break;
    default : break;
    }
}
 
int main()
{
    while( 1 ){
        int ch = getchar();
        if( ch == ' ' || ch == '\n' ) continue;
        if( ch == EOF ) break;
 
        switch( ch ){
        case '+': case '-': case '*': operator(ch); break;
        default : operand(ch); break;
        }
    }
 
    printf("%d\n", pop());
 
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  string ans = "APPROVED";
  vector<int> a(n);
  for(auto i:a){
    cin >> a.at(i);
    if(a.at(i)%2==0 and a.at(i)%3!=0 and a.at(i)%5!=0){
      ans = "DENIED";
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;

const int N = 200003;
int n, k, a[N];
string s;


int main()
{
	cin >> n >> k;
	for(int i = 0; i < n; ++i) scanf("%d", &a[i]);
	int lo = 1, hi = 1e9, cnt;
	while(lo < hi)
	{
		int m = lo + hi >> 1;
		cnt = 0;
		for(int i = 0; i < n; ++i)
			cnt += (a[i] - 1) / m;
		if(cnt > k) lo = m + 1;
		else hi = m;
	}
	cout << lo << endl;
	return 0;
}


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

using namespace std;

const int N = 55;

int a[N];
int b[N];
int n;

long long ans = 0;

bool reach[N][N];

void make(int w) {
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      reach[i][j] = (i == j);
    }
  }
  for (int i = 1; i < N; i++) {
    if (i < w || ((ans >> i) & 1)) {
      for (int j = i; j < N; j++) {
        reach[j][j % i] = 1;
      }
    }
  }
}

void floyd() {
  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        reach[i][j] |= (reach[i][k] & reach[k][j]);
      }
    }
  }
}

bool Solve(int w) {
  make(w);
  floyd();
  for (int i = 0; i < n; i++) {
    if (!reach[a[i]][b[i]]) {
      return false;
    }
  }
  return true;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  if (!Solve(N)) {
    cout << -1 << '\n';
    return 0;
  }
  int mx = *max_element(a, a + n);
  for (int i = mx; i >= 1; i--) {
    if (!Solve(i)) {
      ans |= (1ll << i);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
#define MAX 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ub upper_bound
#define lb lower_bound
#define zoom ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define precise cout.precision(8); cout << fixed;
#define seed srand(chrono::steady_clock::now().time_since_epoch().count());
const double PI = acos(-1);
using namespace std;

int main() {


    zoom;    
    int N, ans = 0; cin >> N;
    for(int i = 1; i <= N; i += 1) {
        int x; cin >> x;
        if(i % 2 == 0)
            continue;
        if(x % 2 == 0)
            continue;
        ans += 1;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3652
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define ll long long int
#define FOR(i, a, b) for(int i=(a);i<=(b);++i)
#define REP(i, n) for(int i=0;i<n;++i)
#define FOREACH(x, a) for(auto& (x) : (a))
#define ALL(a) (a).begin(),(a).end()
#define OUT(x) out << (x) << endl;
#define M0(x) memset(x,0,sizeof(x))
#define MINF(x) memset(x,0x3f,sizeof(x))
#define MMINUS(a) memset(a,0xff,sizeof(a))
#define ten(n) ((int)1e##n)

const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double EPS = 1.0/LINF;
const char ENDL = '\n'; // for JetBrains IDE only supports yen

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 gcd(int a,int b){return b?gcd(b,a%b):a;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

using namespace std;

class DXXOR {
public:
    int N;
    ll K;
    ll A[ten(5)+1];
    int bit[41];
    int bit_K[41]{0};

    void solve(std::istream& in, std::ostream& out) {
        in >> N >> K;
        REP(i, N) in >> A[i];
        M0(bit);

        // O(1e6)
        ll mask = 0;
        int keta = -1;
        while(mask <= K) {
            keta++;
            mask = 1ll << keta;
            REP(i, N) bit[keta] += ((A[i] & mask) > 0); // any better way?

            if (bit[keta] >= (N+1)/2) bit_K[keta] = 0;
            else bit_K[keta] = 1;
        }

        int keta_K = keta-1;

        // herasu
        ll argmax = 0;
        for (int k = keta_K; k >= 0; k--) {
            if (bit_K[k] == 0) continue;
            else {
                ll tmp = argmax + (1ll << k);
                if (tmp <= K) argmax = tmp;
                else continue;
            }
        }

        OUT(f(argmax));
    }

    ll f(ll xi) {
        ll ans = 0;
        REP(i, N) {
            ans += A[i] ^ xi;
        }
        return ans;
    }
};

int main() {
    DXXOR solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout <<" "<<kbrni;cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 200005;

vector<int> G[MAX_N];
int d[MAX_N];

int main()
{
    int n,m;
    cin >> n >> m;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        G[a-1].pb(b-1);
        G[b-1].pb(a-1);
    }
    rep(i,n){
        d[i] = INF;
    }
    queue<int> que;
    d[0] = 0;
    que.push(0);
    while(!que.empty()){
        int p = que.front();
        que.pop();
        rep(i,G[p].size()){
            if(d[G[p][i]]>d[p]+1){
                d[G[p][i]] = d[p]+1;
                que.push(G[p][i]);
            }
        }
    }
    if(d[n-1] == 1 || d[n-1] > 2){
        cout << "IMPOSSIBLE\n";
    }else{
        cout << "POSSIBLE\n";
    }
    return 0;
}


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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

struct UnionFind{
    vector<int> par; // par[i]:iの親の番号
    vector<int> s; // s[i]:iの属する木のノード数
    int n_group; // 木の数
    
    UnionFind(int N) : par(N) {
        for(int i=0; i<N; i++) par[i] = i;
        s.assign(N, 1);
        n_group = N;
    }
    
    int root(int x){ // xが属する木の根
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    
    void unite(int x, int y){ // xとyの木を併合
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        par[rx] = ry;
        s[ry] += s[rx];
        s[rx] = 0;
        n_group--;
    }
    
    bool same(int x, int y){ // xとyが同じ木に属するかどうか
        return root(x) == root(y);
    }

    int size(int x){ // xが属する木のノード数
        return s[root(x)];
    }
};

void Main(){
    int N,M; cin >> N >> M;
    UnionFind uf(N);
    REP(i,M){
        int a,b; cin >> a >> b; a--; b--;
        uf.unite(a,b);
    }
    int ans = uf.n_group-1;
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 3992
#include <bits/stdc++.h>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}
int main(void){
    string s;
    cin>>s;
    int s_len=s.size();
    ll ans=0;
    for(int bit=0;bit<(1<<s_len-1);bit++){
        string t;t+=s[0];
        for(int i=0;i<s_len-1;i++){
            if(bit&(1<<i)){
                ll num=stoll(t);
                ans+=num;
                t="";
            }
            t+=s[i+1];
        }
        ll num=stoll(t);
        ans+=num;
    }
    cout<<ans<<endl;
    return 0;
}

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

public class Main {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out, false);
        String s = scanner.next();
        s += s;
        char[] str = s.toCharArray();
        char[] cpy = Arrays.copyOf(str, str.length);
        long k = scanner.nextLong();
        Arrays.sort(cpy);
        if (cpy[0] == cpy[cpy.length-1]) {
            long ans = k * str.length/4;
            out.println(ans);
            out.flush();
            return;
        }
        long ans = 0;
        int n = str.length/2;
        long temp = 0;
        for(int i = 1; i < n*2; i++) {
            if (str[i] == str[i-1]) {
                str[i] = 0;
                if (i >= n) temp++;
                else ans++;
            }
        }
        ans += (k-1) * temp;
        out.println(ans);
        out.flush();
    }
    
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(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 readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 21204
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

class Ruiwa():
    def __init__(self, a):
        self.H = h = len(a)
        self.W = w = len(a[0])
        self.R = r = a
        for i in range(h):
            for j in range(1,w):
                r[i][j] += r[i][j-1]

        for i in range(1,h):
            for j in range(w):
                r[i][j] += r[i-1][j]

    def search(self, x1, y1, x2, y2):
        if x1 > x2 or y1 > y2:
            return 0

        r = self.R
        rr = r[y2][x2]
        if x1 > 0 and y1 > 0:
            return rr - r[y1-1][x2] - r[y2][x1-1] + r[y1-1][x1-1]
        if x1 > 0:
            rr -= r[y2][x1-1]
        if y1 > 0:
            rr -= r[y1-1][x2]

        return rr

def main():
    n,m = LI()
    na = [LI() for _ in range(n)]
    xd = set()
    yd = set()
    for x,y in na:
        xd.add(x)
        yd.add(y)

    xl = sorted(list(xd))
    yl = sorted(list(yd))
    xx = {}
    yy = {}
    for i in range(len(xl)):
        xx[xl[i]] = i
    for i in range(len(yl)):
        yy[yl[i]] = i
    a = [[0]*(len(yl)+1) for _ in range(len(xl)+1)]
    for x,y in na:
        a[xx[x]][yy[y]] += 1
    rui = Ruiwa(a)
    r = []
    for _ in range(m):
        x1,y1,x2,y2 = LI()
        xx1 = bisect.bisect_left(xl, x1)
        yy1 = bisect.bisect_left(yl, y1)
        xx2 = bisect.bisect(xl, x2) - 1
        yy2 = bisect.bisect(yl, y2) - 1
        r.append(rui.search(yy1,xx1,yy2,xx2))


    return '\n'.join(map(str,r))



print(main())



Measured memory_bytes: 959732
while True:
    N, M, P, A, B = map(int, input().split())
    if not (N | M | P | A | B):
        break
    A, B = A - 1, B - 1
    T = [int(x) for x in input().split()]
    dp = [[float("inf")] * M for _ in range(1 << N)]
    dp[0][A] = 0
    edges = []
    for _ in range(P):
        s, t, c = map(int, input().split())
        s, t = s - 1, t - 1
        edges.append((s, t, c))
        edges.append((t, s, c))
    ans = float('inf')
    for state in range(1 << N):
        for s, t, c in edges:
            for k in range(N):
                if state >> k & 1:
                    dp[state][t] = min(dp[state][t], dp[state & ~(1 << k)][s] + c / T[k])
    ans = min(dp[state][B] for state in range(1 << N))
    print("Impossible" if ans == float("inf") else "{:.05f}".format(ans))

Measured memory_bytes: 7904
#n = int(input())
import random
import sys
sys.setrecursionlimit(10 ** 7)
n, m = map(int, input().split())
#n=200000
#m=200000
#al = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
adjl = [[] for _ in range(n+1)]
NIL = -1
appear = {}
isalone = {}
for i in range(m):
    a, b = map(int, input().split())
    #a=random.randrange(1,n+1)
    #b=random.randrange(1,n+1)
    #while a==b:
    #    b=random.randrange(1,n+1)
    #print(a,b)
    if appear.get((a, b), False) or appear.get((a, b), False):
        continue
    appear[(a, b)] = True
    appear[(b, a)] = True
    isalone[a] = False
    isalone[b] = False
    adjl[a].append(b)
    adjl[b].append(a)

color = [NIL for i in range(n+1)]
color_id = 0


def dfs(u, color_id):
    global color
    color[u] = color_id
    for v in adjl[u]:
        if color[v] == NIL:  # 未到達なら再起呼び出し
            color[v] = color_id
            dfs(v, color_id)


for u in range(1, n+1):
    if color[u] == NIL:
        color_id += 1
        dfs(u, color_id)

group = {}
for i in range(1, n+1):
    if isalone.get(i, True):
        continue
    group[color[i]] = group.get(color[i], 0)+1

mx = 1
for k, v in group.items():
    mx = max(mx, v)

print(mx)


Measured memory_bytes: 575372
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
    int k, x;
    cin >> k >> x;
    for (int i = -k + 1; i < k; i++) {
        cout << x + i;
        if (i == k - 1) {
            cout << endl;
        } else {
            cout << " ";
        }
    }
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ALL(a) (a).begin(), (a).end()

const ll mod = 1000000007;
const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;

template <class T>
void Swap(T &r, T &l) {
  T tmp = r;
  r = l;
  l = tmp;
}

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;  // for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}

// void numlist( vector<ll> &li , n ,){

// }

int main() {
  ll n;
  cin >> n;
  vector<ll> p(n);
  vector<ll> q(n);

  vector<ll> bb(9);
  bb[1] = 1;
  for (ll i = 2; i <= 8; i++) {
    bb[i] = bb[i - 1] * i;
  }

  cin >> p;
  cin >> q;

  ll pp = 0;
  ll qq = 0;
  for (ll i = 0; i < n; i++) {
    pp = pp * 10 + p[i];
    qq = qq * 10 + q[i];
  }

  ll ans = 0;
  ll a, b;
  cerr << pp << " : " <<qq <<endl;

  vector<ll> list;
  for (ll i = 0; i < n; i++) {
    list.push_back(i + 1);
  }
  vector<char> cl(9);
  cl[1] = '1';
  cl[2] = '2';
  cl[3] = '3';
  cl[4] = '4';
  cl[5] = '5';
  cl[6] = '6';
  cl[7] = '7';
  cl[8] = '8';
  cl[9] = '9';

  for (ll i = 1; i < n; i++) {
    // cerr << list.size() <<endl;
    vector<ll> list2;
    for (ll j = 0; j < list.size(); j++) {
      string ss = to_string(list[j]);
    //   cerr << ss <<endl;
      for (ll k = 1; k <= n; k++) {
        //   cerr << cl[k] << ",";
        if (ss.find(cl[k]) == string::npos) {
          list2.push_back(list[j] * 10 + k);
        }
      }
    //   cerr << endl;
    }
    // for(auto x:list2){
    //     cerr << x << ":";
    // }
    
    list.clear();
    list.resize(list2.size());
    copy(list2.begin(), list2.end(), list.begin());
    // cerr <<endl << "=========" <<endl;;
  }


    cerr << pp << " : " <<qq <<endl;
  for (ll i = 0; i < list.size(); i++) {
    //   cerr << list[i] <<endl;
    if (pp == list[i]) {
      a = i + 1;
    }
    if (qq == list[i]) {
      b=  i + 1;
    }
  }

//   cerr << a << " : " <<b <<endl;

  ans = abs(a - b);
  cout << ans << endl;

}


Measured memory_bytes: 1408
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

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

    int a,b;cin>>a>>b;
    if(a<=b) cout<<a<<endl;
    else cout<<a-1<<endl;
}


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

int ketasu(int n) {
  int ans=0;
  while (n!=0) {
    n/=10;
    ans++;
  }
  return ans;
}

int main() {
  int a,b;
  while (cin>>a>>b) {
    cout<<ketasu(a+b)<<endl;
  }
  return 0;
}



Measured memory_bytes: 3088
#include<iostream>
using namespace std;
int main() {
    int x, y;
    while (1) {
        cin >> x >> y;
        if (x == 0 && y == 0) {
            break;
        } else if (x <= y) {
            cout << x << " " << y << endl;
        } else {
            cout << y << " " << x << endl;
        }
    }
}


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

const string YES = "YES";
const string NO = "NO";

void solve(std::string S){
    vector<int> cnt(3, 0);
    for(auto s : S){
        if(s == 'a') cnt[0]++;
        else if(s == 'b') cnt[1]++;
        else if(s == 'c') cnt[2]++;
    }
    int ab = abs(cnt[0] - cnt[1]);
    int bc = abs(cnt[1] - cnt[2]);
    int ca = abs(cnt[2] - cnt[0]);
    if(ab <= 1 && bc <= 1 && ca <= 1) cout << YES << endl;
    else cout << NO << endl;
    return;
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 3816
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
using namespace std;
int main()
{
  ios::sync_with_stdio(false);
  string s,t;
  cin>>s>>t;
  int sl,tl;
  sl=s.length();
  tl=t.length();
  vector<string> dp1(tl+1,""),dp2(tl+1,"");
  for(int i=1;i<sl+1;i++)
  {
    for(int j=1;j<tl+1;j++)
    {
      if(i%2)
      {
        dp1[j]=max({dp2[j],dp1[j-1]},[](string a,string b){return a.size()<b.size();});
        if(s[i-1]==t[j-1])
        {
          if(dp2[j-1].length()+1>dp1[j].length())
          {
            dp1[j]=dp2[j-1];
            dp1[j]+=s[i-1];
          }
        }

      }
      else
      {
        dp2[j]=max({dp1[j],dp2[j-1]},[](string a,string b){return a.size()<b.size();});
        if(s[i-1]==t[j-1])
        {
          if(dp1[j-1].length()+1>dp2[j].length())
          {
            dp2[j]=dp1[j-1];
            dp2[j]+=s[i-1];
          }
        }
      };
      //cout<<dp1[j]<<dp2[j]<<endl;
    }
    //cout<<endl;
  }
  cout<<max({dp1[tl],dp2[tl]},[](string a,string b){return a.length()<b.length();})<<endl;

}

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

using namespace std;

int main() {
  vector<bool> V(1010, false);
  V[1] = true;
  for (int b = 2; b <= 40; b++) {
    for (int p = 2; p < 11; p++) {
      int K = pow(b, p);
      if (K > 1000) break;
      V[K] = true;
    }
  }

  int X;
  cin >> X;
  for (int i = X; i >= 1; i--) {
    if (V[i]) {
      cout << i;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 512
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;

#define  GODSPEED       ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define  f              first                 
#define  s              second
#define  newl           cout<<"\n";
#define  pb             push_back  
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<"\n";
#define  deb2(a,b)      cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());
#define  all(a)         a.begin(),a.end()           
 
typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const int  N     =  5e5+5;
const int  mod   =  998244353;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const int  LEVEL =  log2(N)+1;

ll n, x, m, vis[N];

void solve(){
	cin >> n >> x >> m;
	ll ans = x;
	vis[x] = 1;
	x = (x*x)%m;
	n--;
	while(n > 0 and !vis[x]){
		vis[x] = 1;
		ans += x;
		x = (x*x)%m;
		n--;
	}
	ll st = x, res = 0, ct = 0;
	while(n > 0){
		res += x;
		x = (x*x)%m;
		n--;
		ct++;
		if(x == st) break;
	}
	ans += res;
	if(ct){
		ans += ((ll)n / ct) * res;
		n %= ct;
	}
	while(n > 0){
		ans += x;
		x = (x*x)%m;
		n--;
	}
	deb1(ans)
}

int main(){
	GODSPEED;
	int test = 1;
	//cin >> test;
	for(int i = 1; i <= test; i++){
		solve();
	}
	#ifndef ONLINE_JUDGE
	cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}

Measured memory_bytes: 4360
/* ex5_4
   moka223711 */

#include <stdio.h>
#define SIZE 11

int main(void){
    char input;
    int count = 0, ans = 0;
    while((input = getchar()) != EOF){ // EOF = End Of File ファイルの終端に入っている文字、stdio.h内で定義されている
        if(input=='A'||input=='C'||input=='G'||input=='T')count++; // 受け取った入力が'A'、'C'、'G'、'T'のいずれかであればcountをインクリメント
        else{ // そうでなければcountとansの大小関係を比較して、大きければansにcountを代入し、その後countを0にする
            if(count > ans)ans = count;
            count = 0;
        }
    }
    if(ans == 0)ans = count; // 文字列がすべてAGCTだったとき
    printf("%d\n", ans); // ansを出力
    return 0;
}


Measured memory_bytes: 1588
/*
 AUTHOR : ANSHU BABU RAJPUT
 
    JAI MAA SARASWATI
    OM NAMAH SHIVAY
    JAI SHRI KRISHNA
    JAI SHRI RAM
    BHARAT MATA KI JAI

    #PKMKB	
    #CKMKB
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define int  long long 
#define endl    ("\n")
#define ff       first
#define ss      second
#define pb   push_back
#define pf  push_front
#define ppb   pop_back
#define ppf  pop_front
#define mp   make_pair
#define mod 1000000007

#define L(x)    x.length()
#define B(x)     x.begin()
#define E(x)       x.end()
#define F(x)     x.front()
#define SZ(x)     x.size()
#define CLR(x)   x.clear()

#define all(x)                      x.begin(),x.end()
#define sortD(x) sort(x.begin(),x.end(),greater<int>)
#define rev(x)             reverse(x.begin(),x.end())

#define intV vector<int>

#define PI          (3.141592653589)
#define PMAX     priority_queue<int>
#define PMIN             priority_queue<int,vi,greater<int>>
#define setbits(x)                   __builtin_popcountll(x)
#define zrobits(x)                        __builtin_ctzll(x)

#define KING(i, n) for (int(i) = 0; (i) < n; (i)++)
#define MAHAKAL(i, n) for (int(i) = n-1; (i) >= 0; (i)--)

#define Anshu        int t; cin>>t; while(t--)
#define SITARAM(n,type) type* input=new type[n]

mt19937                          rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void ViLiFY_KiNG()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt","w",stderr);
#endif
}
 
int32_t main()
{
    ViLiFY_KiNG();
    int n;
    cin>>n;
    int ans = n%10;

    if(ans == 3) {
        cout<<"bon"<<endl;
    } else if(ans == 0 || ans == 1 || ans == 6 || ans == 8) {
        cout<<"pon"<<endl;

    } else {
        cout<<"hon"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3640
import java.util.Scanner;

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

	public static void main(String[] args) {
		int[] goods = new int[2];
		int sum = 0;
		int num = 0;
		int count = 0;
		while(sc.hasNext()) {
			String[] str = sc.next().split(",");
			for(int $ = 0; $ < str.length; $++) {
				goods[$] = Integer.parseInt(str[$]);
			}

			sum += goods[0] * goods[1];
			num += goods[1];
			count++;
		}

		System.out.println(sum);
		System.out.println(Math.round((double)num / count));
	}
}

Measured memory_bytes: 25696
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			int count = 0;
			while (n != 1) {
				if (n % 2 == 0) {
					n /= 2;
				} else {
					n = n * 3 + 1;
				}
				count++;
			}
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 17200
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;

int main(){
    int H, W;
    while(cin >> H >> W){
        int a[101][101];
        REP(y, H) REP(x, W) cin >> a[y][x];
        int ans = 0;
        REP(y, H) {
            int row_ans = 0;
            REP(mx, W){
                int b[100] = {};
                for(int x = 0; x < mx; x++){
                    b[x + 1] ^= 1;
                }
                for(int x = W - 1; x > mx; x--){
                    b[x - 1] ^= 1;
                }
                int sum = 0;
                REP(x, W) sum += a[y][x] ^ b[x];
                row_ans = max(row_ans, sum);
            }
            ans += row_ans;
            REP(x, W) a[y + 1][x] ^= 1;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1200
#include "bits/stdc++.h"
using namespace std;
#define INF 1000000000
#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(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
#define SZ(x) ((int)(x).size)
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> Vl;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef map<int, int> MP;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;

int main(){
    double x=0,y,d=0,n,h,w,k,m,ans=0,ptr=0;
    string s,s1,s2;
    cin >> w >> h >> x >> y;
    cout << w*h/2.0 << " ";
    if(x+x==w && y+y==h) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}






Measured memory_bytes: 256
var
	N,i:Longint;
	p,A,T:int64;
begin
	read(N,p);
	T:=1000;
	for i:=2 to N do begin
		read(A);
		if p<A then begin
			T:=T mod p+T div p*A;
		end;
		p:=A;
	end;
	writeln(T);
end.

Measured memory_bytes: 1392
#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

int main() {
  priority_queue<int> q;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    q.push(a);
  }
  for (int i = 0; i < m; i++) {
    int v = q.top();
    q.pop();
    q.push(v / 2);
  }
  long long ans = 0;
  while (!q.empty()) {
    ans += q.top();
    q.pop();
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
    string s;
    ll k;
    cin>>s>>k;
    int cnt=0;
    int ans=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='1') cnt++;
        else{
            ans=s[i]-'0';
            break;
        }
    }
    if(cnt>=k) cout<<1<<endl;
    else cout<<ans<<endl;
}


Measured memory_bytes: 256
from collections import Counter
import sys
h,w=map(int,input().split())
a=list(sys.stdin.read())
c=Counter(a)
c["\n"]=0
n1=0
n2=0
if h*w%2:
  n1=1
if h%2:
  n2+=w//2
if w%2:
  n2+=h//2
n4=(h//2)*(w//2)
n1r,n2r,n4r=0,0,0
for i in c.values():
  n1r += i%2
  n2r += (i//2)%2
  n4r += i//4
if n1==n1r and n4r>=n4:
  print("Yes")
else:
  print("No")

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

public class Main {

	public static int getRank(int val) {
		if(val <= 399) return 0;
		if(val <= 799) return 1;
		if(val <= 1199) return 2;
		if(val <= 1599) return 3;
		if(val <= 1999) return 4;
		if(val <= 2399) return 5;
		if(val <= 2799) return 6;
		if(val <= 3199) return 7;
		return 8;
	}

	public static void main(String[] args) {

		int rankNum = 9;
		int[] count = new int[rankNum];
		Arrays.fill(count, 0);

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i=0; i<n; i++)
			count[getRank(sc.nextInt())]++;
		sc.close();

		int colorNum = 0;
		for(int i=0; i<count.length - 1; i++) {
			if(count[i] != 0)
				colorNum++;
		}
		int minColorNum = (int)Math.max(colorNum, 1);
		int maxColorNum = colorNum+count[count.length-1];
		System.out.println(minColorNum + " " + maxColorNum);
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>

using namespace std;

#define lli long long int
#define REP(i,n) for(int i=0;i<n;i++)
#define DEBUG 0



int main(){

	lli n,m;
	vector<lli> a;
	vector<lli> b;
	cin>>n>>m;
	REP(i,m){
		lli tmpA,tmpB;
		cin>>tmpA>>tmpB;
		a.push_back(tmpA);
		b.push_back(tmpB);
	}

	lli ans=0;
	/*1本1本橋がない状態で幅優先探索を行う*/
	REP(x,m){
	map<lli,vector<lli>> v;
	lli flag[60]={0};
	REP(i,m){
		if(i==x)continue;
		lli tmpA = a.at(i);
		lli tmpB = b.at(i);
		v[tmpA].push_back(tmpB);
		v[tmpB].push_back(tmpA);
	}

	queue<lli> q;
	q.push(1);
	flag[1]=1;
	while(q.size()!=0){
		lli top = q.front();
		q.pop();
		REP(j,v[top].size()){
			lli next = v[top].at(j);
			if(flag[next]==0){
				q.push(next);
				flag[next]=1;
			}
		}
	}
	lli ansFlag =0;
	for(lli j=1;j<=n;j++){
		if(flag[j]==0){
			ansFlag=1;
			break;
		}
	}
	if(ansFlag==1){
		ans++;
	}

	}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstdio>
#include <queue>
using namespace std;

typedef pair<int, int> lake;

int main(void){
  int n, q;
  cin >> n;
  vector<int> s(n);
  for(int i=0;i<n;i++) cin >> s[i];
  cin >> q;
  vector<int> t(q);
  for(int i=0;i<q;i++) cin >> t[i];
  //sort(s.begin(), s.end());
  //sort(t.begin(), t.end());
  int count =0;
  for(int i=0;i<q;i++){
    int left = 0;
    int right = n;
    while(left < right){
      int mid = (left + right) / 2;
      if(s[mid] == t[i]){
        count++;
        break;
      }else if(s[mid] < t[i]){
        left = mid + 1; 
      }else {
        right = mid;
      }
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 1564
#include<iostream>
#include<algorithm>
using namespace std;
int a[100];
int main()
{
	int n,s=0,s1=0,i;
	cin>> n;
	for(i=0;i<n;i++)
	{	cin>> a[i];
		
	}
	
	sort(a,a+n);
	for(i=0;i<n;i++)
	{
if(i%2==0)
		s=s+a[i];
		else
		s1=s1+a[i];	}
		
		
		if(s>s1)
	cout <<s-s1;
	else 
	cout<<s1-s;


		
}


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;

int main() {
  int K;
  string S;
  cin >> K >> S;
  if(S.size() <= K) cout << S << endl;
  else cout << S.substr(0,K)+"..." << endl; 
}

Measured memory_bytes: 3636
import sys
N, C = map(int, input().split())
x = [None]*N
v = [None]*N
for i in range(N):
    x[i], v[i] = map(int, input().split())
cw = [0]*(N+1)
ccw = [0]*(N+1)
for i in range(N):
    cw[i+1] = cw[i] + v[i]
    ccw[i+1] = ccw[i] + v[N-1-i]
for i in range(1, N+1):
    cw[i] -= x[i-1]
    ccw[i] -= (C - x[N-i])
maxccw = [0]*(N+1)
maxcw = [0]*(N+1)
for i in range(1, N+1):
    maxccw[i] = max(maxccw[i-1], ccw[i])
    maxcw[i] = max(maxcw[i-1], cw[i])
ans = max(0, maxcw[-1], maxccw[-1])
for i in range(1, N+1):
    ans = max(ans, cw[i] - x[i-1] + maxccw[N-i])
    ans = max(ans, ccw[i] - C + x[N-i] + maxcw[N-i])
print(ans)

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

struct union_find{
    vector<int> par,r;
    
    union_find(int n){
        par.resize(n);
        r.resize(n);
        for(int i=0;i<n;i++){
            par[i]=i;
            r[i]=0;
        }
    }
    
    int find(int x){
        if(par[x]==x) return x;
        else return find(par[x]);
    }
    
    void unite(int x,int y){
        x=find(x);
        y=find(y);
        if(r[x]<r[y]){
            par[x]=y;
        }
        else{
            par[y]=x;
            if(r[x]==r[y]) r[x]++;
        }
    }
    
    bool same(int x,int y){
        return find(x)==find(y);
    }
};

int main(){
    int n,k,l;
    cin>>n>>k>>l;
    
    union_find road(n),train(n);
    for(int i=0;i<k;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        if(!road.same(a,b)) road.unite(a,b);
    }
    for(int i=0;i<l;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        if(!train.same(a,b)) train.unite(a,b);
    }
    
    vector<pair<int,int>> com(n);
    map<pair<int,int>,int> s;
    for(int i=0;i<n;i++){
        com[i].first=road.find(i);
        com[i].second=train.find(i);
        s[com[i]]++;
    }
    for(int i=0;i<n;i++){
        cout<<s[com[i]]<<" ";
    }
    cout<<endl;
    
}

Measured memory_bytes: 16640
from itertools import accumulate

N = int(input())
card = list(map(int, input().split()))

acc = list(accumulate(card))
s = acc[-1]
ans = float('inf')
for i in range(N-1):
    t = acc[i]
    a = s-t
    ans = min(ans, abs(t-a))
print(ans)


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

const int MAX = 2007;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

//read_kaisetsu & COMinit

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    // 前処理
    COMinit();
    
    int n,k;cin>>n>>k;
    for(int i=1;i<=k;++i)cout<< COM(n-k+1,i) * COM(k-1, i-1) % MOD <<endl;
}

Measured memory_bytes: 3608
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

const ll mod = 998244353;

ll modpow(ll a, ll k) {
	if (k == 0) return 1;
	ll tmp = modpow(a, k / 2);
	if (k & 1)
		return tmp * tmp % mod * a % mod;
	return tmp * tmp % mod;
}

signed main() {
	int n; cin >> n;
	vector<ll> x(n+1);
	for (int i = 1; i < n+1; ++i)
		cin >> x[i];

	vector<ll> ans(n+1);
	ans[0] = 0;
	for (int i = 1; i <= n; ++i) {
		ans[i] = 2 * ans[i - 1] % mod;
		ll add = x[i] * (modpow(x[i] + 1, (ll)i - 1)) % mod;
		ans[i] += add;
		ans[i] %= mod;
	}

	cout << ans[n ] << endl;

	return 0;
}


Measured memory_bytes: 18304
import java.util.Scanner;

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

		int a = scan.nextInt();
		int b = scan.nextInt();

		String str1 = a < b ? "a < b" : "";
		String str2 = a > b ? "a > b" : "";
		String str3 = a == b ? "a == b" : "";

		String str[] = {str1,str2,str3};

		for(String ss : str){
			if(!ss.equals("")){
				System.out.println(ss);
			}
		}

		scan.close();
	}
}

Measured memory_bytes: 26232
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define ll long long
//{{{ read()
inline int read(){
	register int x=0,f=1;
	register char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')	f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')	x=x*10+(ch^48),ch=getchar();
	return x*f;
}
//}}}
const int N=1e7+5;
int n,mx,cnt,ans,now,las,a[N],mc[N],vs[N],vi[N];
bool dfs(int x,int tg){
	if(vs[x]==tg) return false;
	else	vs[x]=tg;
	for(int i=1;i<=cnt;i++)
		if(!vi[abs(a[x]-a[i])]&&(!mc[i]||dfs(mc[i],tg))){
			mc[i]=x; return true;
		}
	return false;
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++){
		int x=read();
		if(!las) a[++cnt]=x;
		else	if(x!=las+1){
			a[++cnt]=x;
			a[++cnt]=las+1;
		}
		las=x;
	}
	a[++cnt]=las+1,mx=las+1,vi[0]=vi[1]=1;
	for(int i=2;i<=mx;i++){
		if(vi[i]) continue;
		for(int j=i*2;j<=mx;j+=i) vi[j]=1;
	} vi[2]=1;
	for(int i=1;i<=cnt;i++)
		if(a[i]&1) ans+=dfs(i,i);
	int A=-ans,B=-ans;
	for(int i=1;i<=cnt;i++)
		if(a[i]&1) ++A;
		else	++B;
	if(A&1)	ans+=3;
	ans+=A/2*2+B/2*2;
	printf("%d\n",ans);
	return 0;
}


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

int main()
{
	int x, y, ans = 0;
	cin >> x >> y;
	
	switch(x)
	{
		case 1:
			ans += 300000;
			break;
		case 2:
			ans += 200000;
			break;
		case 3:
			ans += 100000;
			break;
	}
	
	switch(y)
	{
		case 1:
			ans += 300000;
			break;
		case 2:
			ans += 200000;
			break;
		case 3:
			ans += 100000;
			break;
	}
	
	if (x == 1 && y == 1)
	{
		ans += 400000;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256