akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll modpow(ll a, ll b){

    ll ans=1;
    while(b){
        if(b&1){
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b=b/2;
    }
    return ans;
}
int vis[100010];

ll dis[100010];

vector<pair<int,ll> > vt[100010];

int main(){

	int n;
    cin>>n;

    for(int i=1;i<n;i++){
        int a,b,c;
        cin>>a>>b>>c;

        vt[a].pb(mk(b,c));
        vt[b].pb(mk(a,c));
    }

    int q,k;
    cin>>q>>k;

    queue<int> qq;
    qq.push(k);

    dis[k]=0;

    while(!qq.empty()){
        int x = qq.front();
        qq.pop();
        if(vis[x]==1) continue;
        vis[x]=1;

        for(int i=0;i<vt[x].size();i++){
            if(vis[vt[x][i].ff]==0){
                dis[vt[x][i].ff]=dis[x]+vt[x][i].ss;
                qq.push(vt[x][i].ff);
            }
        }
    }

    while(q--){
        int a,b;
        cin>>a>>b;
        ll ans = (dis[a]+dis[b]);
        cout<<ans<<endl;
    }


}


Measured memory_bytes: 11264
#include<cstdio>
inline int read()
{
	int x;char c;
	while((c=getchar())<'0'||c>'9');
	for(x=c-'0';(c=getchar())>='0'&&c<='9';)x=x*10+c-'0';
	return x; 
}
#define MN 100000
int n,a[MN+5];
int gcd(int x,int y){return y?gcd(y,x%y):x;}
bool check()
{
	int s=n&1,i;
	for(i=1;i<=n;++i)s^=a[i]&1;
	if(s)return true;
	for(i=1;i<=n;++i)if(a[i]>1&&(a[i]&1))break;
	if(i>n)return false;
	for(--a[i],i=1,s=0;i<=n;++i)s=gcd(s,a[i]);
	for(i=1;i<=n;++i)a[i]/=s;
	return !check();
}
int main()
{
	n=read();
	if(n==1)return 0*puts("Second");
	for(int i=1;i<=n;++i)a[i]=read();
	puts(check()?"First":"Second");
}

Measured memory_bytes: 512
#include <stdio.h>
int main(){
int a,b,d,c,e;
scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
	c=c+e;
	d=d+e;
if(a>=c&&c>0&&d>0){
		if(b>=d){printf("Yes\n");
		}else{printf("No\n");}
	}else{printf("No\n");}
return 0;
}


Measured memory_bytes: 2680
#include<bits/stdc++.h>
using namespace std;
int digit(long long n)
{
        int  f1,d1;
   d1=((int)(log10(n)));
   f1=(int) (n/(int)(pow(10,d1)));
   return f1;
}
int main()
{
    long long n,i,j,k=0,p;
    cin>>n;
    int a[10][10]={0};
    for(i=1;i<=n;i++)
    {
         if(i%10==0)continue;
         else
         {
             j=digit(i);
             a[j][i%10]++;
         }
    }
    for(i=1;i<=9;i++)
    {
        for(j=1;j<=9;j++)
        {

           k+=a[i][j]*a[j][i];
        }
    }
    cout<<k<<endl;
    return 0;

}


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    int len = 0;
    rep(i, n) {
        if (s.substr(n-1-i, i+1) == t.substr(0, i+1)) len = i+1;
    }
    cout << (2*n-len) << endl;
    return 0;
}


Measured memory_bytes: 3600
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int k = sc.nextInt();
		int l = sc.nextInt();
		UnionFind uf1 = new UnionFind(n);
		for(int i = 0; i < k; i++){
		    int p = sc.nextInt()-1;
		    int q = sc.nextInt()-1;
		    uf1.union(p, q);
		}
		UnionFind uf2 = new UnionFind(n);
		for(int i = 0; i < l; i++){
		    int p = sc.nextInt()-1;
		    int q = sc.nextInt()-1;
		    uf2.union(p, q);
		}
		
		// 計算
		long result = 0;
		int[] parent1 = new int[n];
		for(int i = 0; i < n; i++){
		    parent1[i] = uf1.find(i);
		}
		int[] parent2 = new int[n];
		for(int i = 0; i < n; i++){
		    parent2[i] = uf2.find(i);
		}
		HashMap<String, Integer> hm = new HashMap<String, Integer>();
		String[] key = new String[n];
		for(int i = 0; i < n; i++){
		    String s = parent1[i] + "-" + parent2[i];
		    key[i] = s;
		    hm.put(key[i], hm.getOrDefault(key[i], 0)+1);
		}
		
		// 出力
		for(int i = 0; i < n; i++){
		    System.out.print(hm.get(key[i]));
		    System.out.print(" ");
		}
		//System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}

class UnionFind {
	int[] parent;
	int[] rank;
	int[] cnt;
	
	UnionFind(int n){
		this.parent = new int[n];
		this.rank = new int[n];
		this.cnt = new int[n];
		for(int i = 0; i < n; i++){
			parent[i] = i;
			rank[i] = 0;
			cnt[i] = 1;
		}
	}
	
	public int find(int i){
		if(i == parent[i]) return i;
		parent[i] = find(parent[i]);
		return parent[i];
	}
	
	public boolean union(int x, int y){
		int xRoot = find(x);
		int yRoot = find(y);
		if(xRoot == yRoot) return false;
		if(rank[xRoot] < rank[yRoot]){
			parent[xRoot] = yRoot;
			cnt[yRoot] += cnt[xRoot];
		}else if(rank[xRoot] > rank[yRoot]){
			parent[yRoot] = xRoot;
			cnt[xRoot] += cnt[yRoot];
		}else{
			parent[yRoot] = xRoot;
			rank[xRoot]++;
			cnt[xRoot] += cnt[yRoot];
		}
		return true;
	}
	
	public boolean same(int x, int y){
		return find(x) == find(y);
	}

	public int cnt(int x){
		return cnt[find(x)];
	}
}

Measured memory_bytes: 91756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll x,a;
	cin>>x>>a;
	if(x<a){
		cout << 0;
	}
	else{
		cout << 10;
	}
	// your code goes here
	return 0;
}

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


int main(){
    int n;
    cin >> n;
    vector<pair<int, int>> vec(n);
    rep(i,n){
        int a;
        cin >> a;
        vec[i] = make_pair(a, i+1);
    }
    sort(vec.begin(), vec.end());

    for(auto v : vec){
        cout << v.second << " ";
    }
    cout << endl;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
// greater<int>()
typedef long long ll;
ll GCD(ll x, ll y) { return y ? GCD(y, x % y) : x; }
ll LCM(ll x, ll y) { return x * y / GCD(x, y); }

using namespace std;
int main() {
	char z;
	cin >> z;
	cout << char(z + 1) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main(){
    FIN;
    ll n,a,b;
    cin >> n >> a >> b;
    vector<ll> x(n);
    for(ll i=0;i<n;i++) cin >> x[i];

    ll ans = 0;
    for(ll i=0;i<n-1;i++){
        if( a*(x[i+1]-x[i]) > b) ans += b;
        else ans += a*(x[i+1]-x[i]);
    }

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


Measured memory_bytes: 4000
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int t = sc.nextInt();

		int cookies = 0;
		int next = a;

		while(next < t+0.5){
			cookies += b;
			next += a;
		}

		System.out.println(cookies);
	}

}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
double f=380000.0;
int main()
{
	int n;double t,ans=0;
	char s[10];
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%lf%s",&t,s);
		if (s[0]=='J') ans+=t;
			else ans+=t*f;
	}
	printf("%.5f\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
using namespace std;

double dis(double x1, double y1, double x2, double y2) {
	return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}

double ldis(double x1, double y1, double x2, double y2, double x3, double y3) {
	
	if ((x1 - x2) * (x3 - x2) + (y1 - y2) * (y3 - y2) > 0 &&
		(x1 - x3) * (x2 - x3) + (y1 - y3) * (y2 - y3) > 0)
		return abs((y3 - y1) * (x2 - x1) - (x3 - x1) * (y2 - y1)) / dis(x2, y2, x3, y3);
	else
		return min(dis(x1, y1, x2, y2), dis(x1, y1, x3, y3));
}

int main()
{
	int q = 0;

	cin >> q;

	for (int i = 0; i < q; i++) {
		double p0x = 0, p0y = 0, p1x = 0, p1y = 0, p2x = 0, p2y = 0, p3x = 0, p3y = 0,
			   u = 0, s = 0, t = 0, d = 0;

		cin >> p0x >> p0y >> p1x >> p1y >> p2x >> p2y >> p3x >> p3y;

		u = (p3y - p0y) * (p2x - p0x) - (p3x - p0x) * (p2y - p0y);
		d = min({ ldis(p0x, p0y, p2x, p2y, p3x, p3y), ldis(p1x, p1y, p2x, p2y, p3x, p3y),
			ldis(p2x, p2y, p0x, p0y, p1x, p1y), ldis(p3x, p3y, p0x, p0y, p1x, p1y)});

		if (u != 0) {
			s = ((p3y - p0y) * (p1x - p0x) - (p3x - p0x) * (p1y - p0y)) / u;
			t = -((p2y - p0y) * (p1x - p0x) - (p2x - p0x) * (p1y - p0y)) / u;

			if (s >= 0 && t >= 0) {
				if (s + t >= 1)
					d = 0;
			}
		}
		else {
			if ((p1y - p0y) * (p2x - p0x) - (p1x - p0x) * (p2y - p0y) != 0) {
				if ((p2x - p0x) * (p3x - p0x) + (p2y - p0y) * (p3y - p0y) <= 0)
					d = 0;
			}
			else if (((p2x - p0x) * (p3x - p0x) + (p2y - p0y) * (p3y - p0y) <= 0) | 
				((p2x - p1x) * (p3x - p1x) + (p2y - p1y) * (p3y - p1y) <= 0))
				d = 0;
		}

		cout << setiosflags(ios::showpoint|ios::fixed) << setprecision(10)
			 << d << endl;
	}

	return 0;
}


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

int main(){
    string str;
    int cnt = 0;
    cin >> str;
    for(int i=0;i<str.size();i++){
        if(str[i]=='x') cnt++;
    }
    if(cnt<=7)  cout << "YES\n";
    else    cout << "NO\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100005
using namespace std;
int n,f[N],x[N],y[N];
long long ans;
vector<int>X[N];
set<int>S[N];
int find(int x){
	return f[x]==x?x:f[x]=find(f[x]);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=N-5;i++)f[i]=i;
	for(int i=1;i<=n;i++){
		scanf("%d%d",&x[i],&y[i]);
		X[x[i]].push_back(y[i]);
	}
	for(int i=1;i<=N-5;i++){
		int size=X[i].size();
		if(size){
			int fa=find(X[i][0]);
			for(int j=1;j<size;j++){
				int x=find(X[i][j]);
				f[x]=fa;
			}
		}
	}
	for(int i=1;i<=N-5;i++){
		int size=X[i].size();
		if(size){
			int fa=find(X[i][0]);
			for(int j=0;j<size;j++){
				S[fa].insert(X[i][j]);
			}
		}
	}
	for(int i=1;i<=N-5;i++){
		if(X[i].size()){
			int fa=find(X[i][0]);
			ans+=1ll*S[fa].size();
		}
	}
	printf("%lld\n",ans-1ll*n);
	return 0;
}

Measured memory_bytes: 12416
def ri():
    return int(input())


def rii():
    return [int(v) for v in input().split()]


def solve():
    N = ri()
    D = []
    for _ in range(N):
        D.append(rii())

    ans = c = 0
    double = False
    for r1, r2 in D:
        if r1 == r2:
            if not double:
                count = 0
            double = True
            count += 1
            ans = max(ans, count)
        else:
            double = False

    print("Yes" if ans >= 3 else "No")


if __name__ == "__main__":
    solve()

Measured memory_bytes: 9196
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

def lcm(a,b):
    return a*b//gcd(a,b)


A,B,C,D = list(map(int, input().split()))
A -= 1

CD = lcm(C,D)
cnta = (A//C) + (A//D) - (A//(CD))
cntb = (B//C) + (B//D) - (B//(CD))

print(B - A - (cntb - cnta))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    string s;
    cin >> s;
    ll k;
    cin >> k;
    int n=s.size();
    rp(i,min(k,(ll)n)){
        if(s[i]!='1'){
            cout << s[i] << endl;
            return 0;
        }
    }
    cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

S=get_nsp
puts S[0..2].join("")

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

using i64 = long long int;

int main(){
    i64 n, l;
    cin >> n >> l;

    int last = -1;
    i64 a_pre = -1, a_cur = -1;
    for(int i=0;i<n;++i){
        a_pre = a_cur;
        cin >> a_cur;
        if(i == 0)continue;
        if(a_pre + a_cur < l)continue;
        last = i;
    }

    if(last == -1)cout << "Impossible" << endl;
    else{
        cout << "Possible" << endl;
        for(int i=1;i<last;++i)cout << i << endl;
        for(int i=n-1;i>last;--i)cout << i << endl;
        cout << last << endl;
    }

    return 0;
}


Measured memory_bytes: 768
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int wTotal = 0;
		while(scan.hasNext()){
			int f = 0;
			int s = 0;
			int t = 0;
			for(int i = 0;i < 20;i++){
				int temp = scan.nextInt();
				if(i == 10){
					wTotal = f + s + t;
					f = temp;
					s = 0;
					t = 0;
				}else{
					if(temp > f){
						t = s;
						s = f;
						f = temp;
					}else if(temp > s){
						t = s;
						s = temp;
					}else if(temp > t){
						t = temp;
					}
				}
			}
			System.out.println(wTotal + " " + (f+s+t));
		}
	}
}

Measured memory_bytes: 17180
#include<bits/stdc++.h>
using namespace std;
#define ms(x,y) memset(x, y, sizeof(x))
#define lowbit(x) ((x)&(-x))
#define sqr(x) ((x)*(x))
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;


void run_case() {
    int h, n;
    cin >> h >> n;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; ++i) cin >> a[i] >> b[i];
    vector<LL> dp(h+5, 0x3f3f3f3f3f3f3f3f);
    dp[0] = 0;
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j <= h; ++j)
            dp[min(j+a[i], h)] = min(dp[min(j+a[i], h)], dp[j]+b[i]);
    } 
    cout << dp[h];
}


int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(9);
    //int t; cin >> t;
    //while(t--)
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;

int main()
{
	char a,b,c,d;
	int A,B,C,D;
	scanf("%c%c%c%c",&a,&b,&c,&d);
	A=a-48;
	B=b-48;
	C=c-48;
	D=d-48;
	if(A+B+C+D==7)	printf("%d+%d+%d+%d=7\n",A,B,C,D);
	else if(A+B+C-D==7)	printf("%d+%d+%d-%d=7\n",A,B,C,D);
	else if(A+B-C-D==7)	printf("%d+%d-%d-%d=7\n",A,B,C,D);
	else if(A+B-C+D==7)	printf("%d+%d-%d+%d=7\n",A,B,C,D);
	else if(A-B+C+D==7)	printf("%d-%d+%d+%d=7\n",A,B,C,D);
	else if(A-B-C+D==7)	printf("%d-%d-%d+%d=7\n",A,B,C,D);
	else if(A-B+C-D==7)	printf("%d-%d+%d-%d=7\n",A,B,C,D);
	else if(A-B-C-D==7)	printf("%d-%d-%d-%d=7\n",A,B,C,D);

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int H = sc.nextInt();
            int W = sc.nextInt();
            if (H == 0 && W == 0) {
                break;
            }
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    System.out.print("#");
                }
                System.out.println("");
            }
            System.out.println("");
        }
    }
}


Measured memory_bytes: 34504
#include<bits/stdc++.h>                          
using namespace std;
int a[100005],n,m,ans1,ans2,num,f[100005];
string s;
int main(){
	cin>>n>>m;
	if(m==0) {cout<<0<<" "<<0;return 0;}
	for(int i=1;i<=m;i++)
	{
		cin>>num>>s;
		if(f[num]!=0) continue;
		if(s=="AC") {ans2+=a[num],ans1++,f[num]=1;continue;}
		a[num]++;
	}
	cout<<ans1<<" "<<ans2;
	return 0;
}

Measured memory_bytes: 1024
def d_recording(N, C, R):
    # N:録画する番組の数
    # C:テレビが受信できるチャンネルの数
    # R:録画する番組の情報 [開始時刻s,終了時刻t,チャンネルc]
    from itertools import accumulate

    # いつまで録画機を動かすか。終了時刻の最大値10**5, 単位時間を0.5とするので*2
    # 時刻を0からスタートさせるので+1, 累積和のために+1
    l = 10**5 * 2 + 2
    running_recorder = [0] * l  # [k]:ある時刻に動作中の録画機の数

    for channel in range(1, C + 1):
        rec = [0] * l  # [k]:チャンネルkを録画しているか否か
        # 累積和を取る
        for s, t, c in R:
            if c == channel:
                # 録画開始時刻の0.5前を+1,終了時刻を-1
                # (終了時刻は含まないという録画機の条件より、このようにする)
                rec[s * 2 - 1] += 1
                rec[t * 2] -= 1
        rec = accumulate(rec)
        # あるチャンネルを録画している時間帯では、録画機を1個使わねばならない
        for j, running in enumerate(rec):
            if running > 0:
                running_recorder[j] += 1
    ans = max(running_recorder)
    return ans

N, C = [int(i) for i in input().split()]
R = [[int(i) for i in input().split()] for j in range(N)]
print(d_recording(N, C, R))

Measured memory_bytes: 24336
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>
#include<set>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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; }

#define keta setprecision(10) //10桁表示


int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int r, g, b, n;
	int ans = 0;
	cin >> r >> g >> b >> n;

	for (int i = 0; i < 3001; i++)
	{
		for (int j = 0; j < 3001; j++)
		{
			if(n-i*r-j*g>=0)
			if ((n - (i * r + j * g)) % b == 0)
			{
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int N;
  cin>> N;
  for (int i = 0; i < N; i++) {
    string c;
    cin >> c;
    if(c=="Y"){
      cout << "Four" << endl;
      break;
    }
    else if(i==N-1 && c!="Y"){
      cout << "Three" << endl;
    }
  }
}

Measured memory_bytes: 256
#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 FORR(i, m, n) for(int i = (m);i >= (n);i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define ALL(obj) (obj).begin(),(obj).end()

using namespace std;

const int INF = 99999999;
const ll LINF = 9999999999999;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
int vx[4] = { 0,1,0,-1 };
int vy[4] = { 1,0,-1,0 };

int n, k,num;

signed main() {

	std::ios::sync_with_stdio(false);
	std::cin.tie(0);

	cin >> n >> k;

	num = 1;

	REP(i, n) {
		if (num < k) {
			//倍する
			num *= 2;
		}
		else {
			//kたす
			num += k;
		}


	}

	cout << num << endl;

	return 0;

}


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

int main() {
  int n,m;cin>>n>>m;
  vi fri[n];
  int a, b;
  rep(i,m) {
    cin>>a>>b;
    a--;b--;
    fri[a].push_back(b);
    fri[b].push_back(a);
  }//*/
  /*int n=20,m=20;
  vi fri[n];
  int a, b;
  rep(i,m-1) {
    a=(i*3)%n,b=(i*11)%n;
    fri[a].push_back(b);
    fri[b].push_back(a);
    cout<<(a+1)<<" "<<(b+1)<<endl;
  }//*/
  
  // BFS のためのデータ構造
  vi group(n, 0);
  queue<int> que;
  int g = 0;
  int min_v = 0;

  // BFS 開始 (キューが空になるまで探索を行う)
  while (min_v<n) {
    if (group[min_v] != 0) { min_v++; continue; }
    
    g++;
    // 初期条件 (頂点 0 を初期ノードとする)
    group[min_v] = g;
    que.push(min_v); // 0 を橙色頂点にする

    while (!que.empty()) {
      int v = que.front(); // キューから先頭頂点を取り出す
      que.pop();

      // v から辿れる頂点をすべて調べる
      for (int nv : fri[v]) {
        if (group[nv] != 0) continue; // すでに発見済みの頂点は探索しない

        // 新たな白色頂点 nv について距離情報を更新してキューに追加する
        group[nv] = g;
        que.push(nv);
      }
    }
  }
    

  
  /*vi group(n, 0);
  int g = 0, x;
  rep(i, n) {
    if (group[i] != 0) x = group[i];
    else {
      g++;
      group[i] = i+1;
      x = i+1;
    }
    for (int j: fri[i]) {
      group[j] = x;
    }
  }//*/
  //rep(i, n) cout<<group[i]<<" ";cout<<endl;
  
  vi cnt(n, 0);
  rep(i, n) {
    cnt[ group[i]-1 ] ++;
  }
  int ans = 0;
  rep(i, n) ans = max(ans, cnt[i]);
  //rep(i, n) cout<<cnt[i]<<" ";cout<<endl;
  
  cout<<ans<<endl;
}


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

using namespace std;

typedef long int li;
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pt;

#define fi first
#define se second
#define dump(x) cout << #x << " = " << x << endl

li n, k, a, b, tmp[100007];
ll res, M, cl[100007];
vector <li> g[100007];

void dfs(int v, int pr) {
    if (v!=1) tmp[v]=1;
    cl[v]=max(0, int(k-tmp[pr]));
    for(auto i : g[v]) {
        if (i == pr) continue;
        tmp[v]+=1;
        dfs(i, v);
    }
}

int main () {
    cin >> n >> k;
    for (li i = 0; i < n-1; i++) {
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
        tmp[a]=0;
        tmp[b]=0;
    }
    tmp[0]=0;
    tmp[1]=0;
    dfs(1, 0);
    cl[1]=k;

    M = 1000000007;
    res=1;
    for(li i=1; i <= n; i++) {
        res=cl[i]*res%M;
    }
    cout << res << endl;
}


Measured memory_bytes: 10752
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, M, k, s;
    cin >> N >> M;
    vector<int> l[M];
    int p[M];
    REP(i, M) {
        cin >> k;
        REP(j, k) {
            cin >> s;
            l[i].push_back(s - 1);
        }
    }
    REP(i, M) cin >> p[i];

    int ans = 0;
    REP(i, 1 << N) {
        bool ok = true;
        REP(j, M) {
            int state = p[j];
            REP(k, l[j].size()) {
                state ^= (i >> l[j][k]) & 1;
            }
            if (state != 0) {
                ok = false;
                break;
            }
        }
        if (ok) ans++;
    }
    cout << ans << endl;
    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>;

int main() {
    int n, p;
    cin >> n >> p;
    string s;
    cin >> s;

    if (10%p == 0) { // 2,5
        ll ans = 0;
        rep(r,n) {
            if ((s[r]-'0') % p == 0) ans += r+1;
        }
        cout << ans << endl;
        return 0;
    }
    
    vector<int> d(n+1);
    int ten = 1;
    for (int i = n-1; i >= 0; --i) {
        int a = ((s[i]-'0') * ten) % p;
        d[i] = (d[i+1]+a) % p;
        ten *= 10; ten %= p;
    }
    vector<int> a(p);
    ll ans = 0;
    for (int i = n; i >= 0; --i) {
        ans += a[d[i]];
        a[d[i]] += 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1412
n, m = list(map(int, input().split()))

h = list(map(int, input().split()))

yoi_warui = [0]*n
dokuritsu = [0]*n

for i in range(m):
    a, b = list(map(int, input().split()))
    dokuritsu[a-1] = 1
    dokuritsu[b-1] = 1
    if h[a-1] == h[b-1]:
        yoi_warui[a-1] = 1
        yoi_warui[b-1] = 1
    elif h[a-1] < h[b-1]:
        yoi_warui[a-1] = 1
    elif h[b-1] < h[a-1]:
        yoi_warui[b-1] = 1

print(yoi_warui.count(0))



Measured memory_bytes: 19968
n = int(input())
ans = 0
 
def solve(x):
    df = str(x)[0]
    dl = str(x)[-1]
    return df, dl
 
numMap = {}
 
for i in range(1, n+1):
    # print(i)
    # print(solve(i))
    pair = solve(i)
    if pair in numMap:
        numMap[pair] += 1
    else:
        numMap[pair] = 1
 
for i in range(1, n+1):
    key = solve(i)
    rev = key[::-1]
    # print('key:', key)
    # print('rev:', rev)
    if rev in numMap:
        ans += numMap[rev]
 
# print(numMap)
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		while(in.hasNext())
		{
			int L=in.nextInt();
			int A=in.nextInt(),B=in.nextInt(),C=in.nextInt(),D=in.nextInt();
			int cnt=0;
			for(;;)
			{
				if(A<1&&B<1)
					break;
				A-=C;
				B-=D;
				++cnt;
			}
			System.out.println(L-cnt);
		}
	}
}

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

using namespace std;

int main()
{
    long long int x;
    cin>>x;
    if(x>=400&&x<=599)
        cout<<8;
    else if(x>=600&&x<=799)
        cout<<7;
    else if(x>=800&&x<=999)
        cout<<6;
    else if(x>=1000&&x<=1199)
        cout<<5;
    else if(x>=1200&&x<=1399)
        cout<<4;
    else if(x>=1400&&x<=1599)
        cout<<3;
    else if(x>=1600&&x<=1799)
        cout<<2;
    else
        cout<<1;
    return 0;
}


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

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

        int min = Math.min(x, y);
        int cheaper = Math.min(a + b, 2 * c);
        int sum = min * cheaper;
        if (x > y) {
            cheaper = Math.min(a, 2 * c);
            sum += (x - y) * cheaper;
        }
        else {
            cheaper = Math.min(b, 2 * c);
            sum += (y - x) * cheaper;
        }
        System.out.println(sum);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

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


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

#include<vector>
#include<string>

#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;
const ll INF = 1e9+1;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}

int A[3];

int main() {

    cin >> A[0] >> A[1] >> A[2];
    sort(A,A+3);
    int odd = 0;
    if ((A[2] - A[0]) % 2 == 1) odd++;
    if ((A[2] - A[1]) % 2 == 1) odd++;

    int res = 0;
    res += ((A[2]-A[0]) / 2);
    res += ((A[2]-A[1]) / 2);
    if (odd == 2) res++;
    if (odd == 1) res+=2;
    cout << res << endl;
}


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

vector<int> divisor(int n) { 
  vector<int> ret;
  for (int i = 1; (int)i*i <= n; ++i) { 
    if (n % i == 0) {
      ret.push_back(i);
      if (i*i != n) { ret.push_back(n/i); }
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
};

int main() {
  int n; cin >> n;
  vector<int> ans;
  map<int, int> divs; 
  vector<int> la(n);
  for (int &a: la) cin >> a;
  for (int i = n-1; i >= 0; --i) {
    int a = la[i];
    int d = i+1;
    int c = 0;
    if (divs.find(d) != divs.end()) c = divs[d];
    if (c % 2 == a) continue;
    ans.push_back(d);
    vector<int> div = divisor(d);
    for (int e : div) {
      if (divs.find(e) == divs.end()) {
        divs[e] = 1;
      }
      else { 
        divs[e] += 1;
      }
    }
  }
  cout << ans.size() << endl;
  for (int b : ans) { 
    cout << b << " ";
  }
  cout << endl;
}



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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	string s, t;
	cin >> s >> t;
	vector<int> a[26];
	for(int i=0; i<s.length(); i++) a[s[i]-'a'].push_back(i+1);

	vector<int> b(26, 0);
	ll lcnt=0, curr=0;
	for(int i=0; i<t.length(); i++){
		int c=t[i]-'a';
		if(a[c].size()==0){
			cout << -1 << endl;
			return 0;
		}

		vector<int>::iterator it=upper_bound(a[c].begin(), a[c].end(), curr);
		if(distance(it, a[c].end())==0){
			lcnt++;
			curr=a[c][0];
		}else curr=*it;
	}
	cout << lcnt*s.length()+curr << endl;
	return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin>>s;
    long long k;
    cin>>k;
    long long a=1,b=0,c1=1,c2=1;
    long long n=s.size();
    long long renketu=0;
    for(int i=1;i<n;i++){
        if(s.at(i-1)==s.at(i)){
            a++;
        }
        else{
            b+=a/2;
            a=1;
        }
    }
    b+=a/2;
    if(n>=3){
        for(int i=1;i<n;i++){
            if(s.at(0)==s.at(i)){
                c1++;
            }
            else break;
        }
        for(int i=n-2;i>=0;i--){
            if(s.at(n-1)==s.at(i)){
                c2++;
            }
            else break;
        }
        if(s.at(0)==s.at(n-1)&&(c1+c2)%2==0) renketu=1;
    }
    bool onaji=true;
    for(int i=1;i<n;i++){
        if(s.at(i-1)!=s.at(i)){
            onaji=false;
            break;
        }
    }
    long long answer=0;
    if(onaji) cout<<n*k/2<<endl;
    else{
        answer=b*k+renketu*(k-1);
        cout<<answer<<endl;
    }
}


Measured memory_bytes: 256
import math
import sys
 
a,b = map(int,input().split())
 
a_min = math.ceil(a/0.08)
a_max = math.ceil((a+1)/0.08-1)
 
b_min = math.ceil(b/0.1)
b_max = math.ceil((b+1)/0.1-1)
 
a_list = list(range(a_min,a_max+1))
b_list = list(range(b_min,b_max+1))
 
 
for num in a_list:
    if num in b_list:
        print(num)
        sys.exit()
 
print('-1')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
signed main(){
    int N,M; cin >> N >> M;
    int ans = 0;
    for(int i = 1; i * i <= M; ++i){
        if(M % i != 0)continue;
        if(i * N  <= M)
            ans = max(ans,i);
      	if((M / i) * N <= M)
          	ans = max(ans,M / i);

    }
    cout << ans << endl;
}


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

INF = 10**9
dp = [INF]*N

def chmin(val1, val2):
    if val1 < val2:
        return val1
    else:
        return val2
        
for i in range(len(A)):
    if i == 0:
        dp[0] = 0
    elif i == 1:
        dp[1] = abs(A[1]-A[0])
    else:
        dp[i] = chmin(dp[i-1]+abs(A[i]-A[i-1]), dp[i-2]+abs(A[i]-A[i-2]))

print(dp[N-1])

Measured memory_bytes: 13976
#include<iostream>
using namespace std;
int main() {
    int x, y;
    string op;
    int a;
    
    while (true) {
        cin >> x >> op >> y;
        if (op == "+") a = x + y;
        else if (op == "-") a = x - y;
        else if (op == "*") a = x * y;
        else if (op == "/") a = x / y;
        else break;
        cout << a << endl;
    }
    return 0;
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rnfor(i,a,b) for(ll (i) = (a) - 1; (i) >= (b); --(i))
#define ll long long
#define mod (1000000007)
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()

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

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

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    rep1(i, k)r = r * n-- / i;
    return r;
}

int main(){
    string s;
    cin >> s;
    rep0(i, s.size())cout << 'x';
    pf("");
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INF 10000000000
#define mod 1000000007
#define X 1000000
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll usort(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll dsort(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll ssort(const void *a, const void *b){return strcmp((char*)a,(char*)b);}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll z(ll a){return max(a,-a);}
ll gcd(ll a,ll b){if(!b){return a;}else{return gcd(b,a%b);}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll kt(ll a){
  ll sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
ll ks(ll a){
  ll sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
void ppp(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (int i=2;i<X;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
}
ll nCr(int n,int k){
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

int jank(int a){
  char s[4]="spr";
  FOR(3)if(a==s[i])return i;
}

int main(void){
  int n,k,point[3];
  scanf("%d %d %d %d %d",&n,&k,&point[0],&point[1],&point[2]);
  char s[n+1];
  scanf("%s",s);
  int ans=0;
  FOR(k){
    int cnt=0,t;
    for(int j=i;j<n;j+=k){
      if(j>=k){
        if(s[j]==s[j-k]){
          cnt++;
        }else{
          ans+=cnt/2*point[jank(s[j-k])]+point[jank(s[j])];
          cnt=0;
        }
      }else{
        ans+=point[jank(s[j])];
      }
      t=j;
    }
    ans+=cnt/2*point[jank(s[t])];
  }
  PRN(ans);
  return 0;
}


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

int main(void){
    long long N;
    int ans = 0;
    cin >> N;

    while(N > 1){
        ans++;
        N = max(N / 3, N - 2 * N / 3);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
#define rint register int
#define ll long long 
using namespace std;
int N,A[101010],tong[110100],Max,Min;
int main(){
	cin>>N;
	Max=-1,Min=10000;
	for(rint i=1;i<=N;++i) cin>>A[i],tong[A[i]]++;
	for(rint i=1;i<=N;++i) {
		Max=max(Max,A[i]);
		Min=min(Min,A[i]);
	}
	if(Max==1) {
		if(N==2) {
			cout<<"Possible";
		}
		else cout<<"Impossible";
		return 0;
	}
	if(tong[Max]<2) {
		cout<<"Impossible\n";
		return 0;
	}
	
	if(Max&1) {
		for(rint i=Min;i<=Max;++i) {
			if(tong[i]<2) {
			cout<<"Impossible\n";
			return 0;}
		}
		if(tong[Min]!=2) {
			cout<<"Impossible\n";
			return 0;
		}
		if(Min!=(Max+1)/2) {
			cout<<"Impossible\n";
			return 0;
		}
	}
	else {
		if(Min!=Max/2) {
			cout<<"Impossible\n";
			return 0;
		}
		for(rint i=Min+1;i<=Max;++i) {
			if(tong[i]<2) {
			cout<<"Impossible\n";
			return 0;}
		}
		if(tong[Min]!=1) {
			cout<<"Impossible\n";
			return 0;
		}
	}
	cout<<"Possible\n";
	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <time.h>

using namespace std;
typedef long long ll;

int N = 0;
int M = 0;
int x = 0;
int y = 0;

//?????????????????

struct UnionFind{
    //ご本体
    vector<ll > tree;
    //高さ
    vector<ll > rank;
    //グループごとのサイズ
    vector<ll > size;
 
    //定義
    UnionFind(ll N) : tree(N), rank(N), size(N){
        for(int i = 0; i < N; i++){
            tree[i] = i;
            rank[i] = 0;
            size[i] = 1;
        }
    }

    //どの根っこに属しているのか？さかのぼり続ける
    int root(int x){
        if(tree[x] == x){
            return x;
        }
        //経路圧縮
        return tree[x] = root(tree[x]);
    }

    //木と木を(高さが低い方に)くっつける
    ll unite(int x, int y){
        int tx = root(x);
        int ty = root(y);
        //xとyの根が同じならくっつけない
        if(tx == ty){
            return 0;
        }
        
        ll s = size[tx] + size[ty];
        ll r = size[tx] * size[ty];
        size[tx] = s;
        size[ty] = s;

        //tree[tx] = ty;
        //高くない方にくっつけたい：効果がいまいちわからん
        //下：ランク付けのつもり 
        if(rank[tx] < rank[ty]){
            //小さい方を大きい方
            //txの根が大きい方の根に更新
            tree[tx] = ty; 
        }else{
            tree[ty] = tx;
            //つなげるときに同じ高さだったらつなげた後に高さを＋１する
            if(rank[tx] == rank[ty]){
                rank[tx]++;
            }
        }

        return r;

    }

    //同じ木に属しているか？根っこをさかのぼって調べてみる
    bool same(int x, int y){
        int tx = root(x);
        int ty = root(y);
        if(tx == ty){
            return true;
        }else{
            return false;
        }
    }
    //グループのサイズを返す
    int FindSize(int x){
        return size[root(x)];
    }

};

int main(){

    cin >> N >> M;

    UnionFind test(N);

    vector<ll > ans;
    ll t_ans = 0;
    //初期状態：どの組み合わせも橋がないのでとても不便
    //ans.push_back((N * (N - 1)) / 2);
    //t_ans = (N * (N - 1)) / 2;
    for(ll i = N; i >= 1; i--){
        t_ans += i - 1;
    }

    vector<ll> X;
    vector<ll> Y;
    for(ll i = 0; i < M; i++){
        cin >> x >> y;
        X.push_back(x - 1);
        Y.push_back(y - 1);
    }

    //入力
    for(ll i = M - 1; i >= 0; i--){
        ans.push_back(t_ans);
        if(test.same(X[i], Y[i])){
            continue;
        }
        
        //cout << test.FindSize(X[i]) * test.FindSize(Y[i]) << endl;
        //t_ans -= test.FindSize(X[i]) * test.FindSize(Y[i]);
        ll r = test.unite(X[i], Y[i]);
        t_ans -= r;

    }

    for(ll i = M - 1 ; i >= 0 ; i--){
        cout << ans[i] << endl;
    }

}

Measured memory_bytes: 6124
#pragma gcc optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i=(ll)(r);i<(ll)(n);++i)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define pb(n) push_back(n)
#define endl '\n'
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c
#define VIN(V) for(int ii = 0; ii < (V).size(); ii++) {cin >> (V).at(ii);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(ii,(V).size()){cout << (V)[ii] << " ";} cout<<endl;
#define VOUT2(V) REP(jj,(V).size()){VOUT(V[jj])}
#define debug(x) cout << #x << " = " << (x) << endl
#define debugv(x) cout << #x << " = "; VOUT(x);
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<vi > vvi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
ll n, m, k, ans, sum, cnt = 0; string s; char c;

int main(){
  cin.tie(0);ios::sync_with_stdio(false);
  IN(n);
  vi a(n);
  VIN(a);

  vi ansv;
  ansv.pb(a[0]);
  FOR(i,1,n) {
    ll now = a[i];
    if (now <= ansv[0]) {
      ansv.insert(ansv.begin(), a[i]);
    } else {
      ll index = lower_bound(ALL(ansv), now) - ansv.begin();
      //debug(index);
      ansv[index-1] = a[i];
    }
    //debugv(ansv);
  }

  OUT(ansv.size());
}


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

#define all(v) v.begin(), v.end()
#define mp make_pair
#define EPS (int)1e-9
#define PI acos(-1)
#define endl '\n'
#define pb push_back
#define fi first
#define se second

using namespace std;
using ld = long double;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

const int mod = 1000000007;

bool moveR(int x, int l, int r, int obstacle)
{
	if(x+1 != obstacle and x+1 <= r)
		return true;

	return false;
}

bool moveL(int x, int l, int r, int obstacle)
{
	if(x-1 != obstacle and x-1 >= l)
		return true;

	return false;
}


int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n, a, b;
	cin >> n >> a >> b;

	int inturn = a;
	int notturn = b;
	string ans = "Borys";
	int i = 1;
	while(moveR(inturn, 1, n, notturn) or moveL(inturn, 1, n, notturn))
	{
		if(i == 1)
		{
			if(moveR(a, 1, n, b))
				a++;
			else
				a--;

			ans = "Alice";
			i = 2;
			inturn = b;
			notturn = a;
		}
		else if(i == 2)
		{
			if(moveL(b, 1, n, a))
				b--;
			else
				b++;

			ans = "Borys";
			i = 1;
			inturn = a;
			notturn = b;
		}
		
	}

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

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

typedef long long ll;

class MaxFlow{
public:
  struct edge{int to, rev, cap;};

  const int INF = 2e9;
  static const int MAX_V = 100000;

  vector<edge> G[MAX_V];
  bool used[MAX_V] = {};
  void add_edge(int frm, int to, int cap) {
    G[frm].push_back((edge){to, G[to].size(), cap});
    G[to].push_back((edge){frm, G[frm].size() - 1, 0});
  }
  int dfs(int frm, int to, int flow) {
    if (frm == to) return flow;
    used[frm] = 1;
    for (int i = 0; i < G[frm].size(); i++) {
      edge &e = G[frm][i];
      if (!used[e.to] && e.cap > 0) {
        int d = dfs(e.to, to, min(flow, e.cap));
        if (d > 0) {
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }
  int maxflow(int s, int t) {
    int flow = 0;
    while (1) {
      memset(used, 0, sizeof(used));
      int f = dfs(s, t, INF);
      if (f == 0) return flow;
      flow += f;
    }
  }
};


int main() {
    MaxFlow mf;
    int h,w,s,t,S,T;
    int sx,sy,tx,ty;
    S = 40000, T = 40001;
    cin >> h >> w;
    string maze[h];
    for (int i = 0; i < h; i++) {
        cin >> maze[i];
        for (int j = 0; j < w; j++) {
            if (maze[i][j] == 'S') {
                sx = i;
                sy = j;
                mf.add_edge(S,i + 1000,mf.INF);
                mf.add_edge(S,j,mf.INF);
            } else if (maze[i][j] == 'T') {
                tx = i;
                ty = j;
                mf.add_edge(i + 1000,T,mf.INF);
                mf.add_edge(j,T,mf.INF);
            } else if (maze[i][j] == 'o') {
                mf.add_edge(i + 1000, j, 1);
                mf.add_edge(j, i + 1000, 1);
            }
        }
    }
    if (sx == tx || sy == ty) {
        cout << -1 << endl;
        return 0;
    }
    cout << mf.maxflow(S,T) << endl;
    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

using namespace std;
typedef long long ll;

#define MAX_N 1000000
#define INF 1000000

int main() {

  // ---------------------
  // Input
  
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  ll H, W;
  cin >> H >> W;

  // ---------------------
  // 

  ll blk = H/2;

  ll res;

  if (H == 1 || W == 1) res = 1;
  
  else if (H%2==0) {
    res = W*blk;
  }
  else {
    res = W*blk;
    if(W%2==0) res += W/2;
    else res += W/2 + 1;
  }

  cout << res << endl;

  return 0;
  
}


Measured memory_bytes: 256