akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <set>
#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 llong long long
#define pb(a) push_back(a)

#define INF 100000000

#define writeln(n) cout<<n<<endl

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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

llong pownew(llong m, llong n) {
    if (n == 0) { return 1; }
    if (n % 2 == 0) { return pow(m*m, n/2); }
    return pow(m, n-1) * m;
}

bool isprime(int p) {
    if (p == 1) return false;
    for (int i = 2; i < p; i++) {
        if (p%i == 0) return false;
    }
    return true;
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

const int inf=100000000;

long long modpow(long long a, long long n, long long mod) //a^n
{
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

llong gcd(llong a, llong b) {
        return b != 0 ? gcd(b, a % b) : a;
}
//setprecision(10);

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s ; cin>>s;
    string ans="No";
    for(int i=0; i<s.size()-1; i++)
    {
        for(int j=i; j<s.size(); j++)
        {
            if(s[i]=='C'&&s[j]=='F') ans="Yes";
        }
    }
    cout<<ans<<endl;
}

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

using namespace std;

int main(){
    int n;
    long long k;
    cin >> n >> k;
    int max=100*1000+1;
    vector<long long> c(max);
    for(int i=0; i<n; ++i){
        int a, b; cin >> a >> b;
        c[a]+=b;
    }
    for(int i=0; i<max; ++i){
        k-=c[i];
        if(k<=0){
            cout << i << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<n; i++)
template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    REP(i, N) cin >> a[i];

    int cur = 0;
    REP(i, N)
        if(a[i] == cur+1) cur++;
    if(cur == 0) cout << -1 << endl;
    else cout << N - cur << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define ii pair<int,int>
#define MAX 1000000007

using namespace std;


int main(void){
  int n;
  cin >> n;
  int a[n][2];
  rep(i,n) cin >> a[i][0];
  rep(i,n) cin >> a[i][1];

  int ans = 0;
  rep(i,n){
	int work = 0;
	rep(j,n){
	  if(j <= i) work += a[j][0];
	  if(i <= j) work += a[j][1];
	}
	ans = max(ans,work);
  }

  cout << ans << endl;
  return 0;

}


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

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

  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int count = 1;
  int tmp = a[0];
  if (tmp == 2) {
    cout << count << '\n';
    return 0;
  }
  for (int i = 0; i < n; i++) {
    tmp = a[tmp-1];
    count++;
    if (tmp == 2) {
      cout << count << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
}

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		String p = sc.nextLine();
		String[] S = s.split("");
		int slength = s.length();
		int plength = p.length();
		int same =0;
		for (int i = 0; i < slength; i++) {
			if (same == 1) {
				break;
			}
			StringBuilder smalls =new StringBuilder();
			int k = 0;
			int j = i;
			while (true) {
				smalls.append(S[j]);
				j++;
				k++;
				if (j >= slength) {
					j = 0;
				}
				if (k == plength) {
					if (smalls.toString().equals(p)) {
						System.out.println("Yes");
						same = 1;
					}
					break;
				}
			}
		}
		if (same == 0) {
			System.out.println("No");
		}
	}
}

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

struct data {
  int h,w,num;
  bool operator < (const data &p)const{
    return num<p.num;
  }
};
int n,w,d,p,s,cnt;
vector < data > t;

int main(){
  while(cin>>n>>w>>d){
    if(n==0&&w==0&&d==0)break;

    t.clear();
    t.push_back( (data){d,w,1} );
    cnt=1;

    for(int i=1;i<=n;i++){
      cin>>p>>s;
      p--;
      data d = t[p];
      data e = t[p];

      s=s%(d.h*2+d.w*2);
      if(s>d.h+d.w)s-=(d.h+d.w);

      if(s>d.w){
	d.h=s-d.w;
	e.h=e.h-d.h;
      }else{
	d.w=s;
	e.w=e.w-d.w;
      }

      if(e.h*e.w<d.h*d.w){
	e.num=cnt+1;
	d.num=cnt+2;
	t[p]=e;
	t.push_back(d);
      }else{
	d.num=cnt+1;
	e.num=cnt+2;
	t.push_back(e);
	t[p]=d;
      }
      cnt+=2;
      sort(t.begin(),t.end());
    }//i

    for(int i=0;i<(int)t.size();i++){
      t[i].num=t[i].h*t[i].w;
    }
    sort(t.begin(),t.end());
    for(int i=0;i<(int)t.size();i++){
      if(i)cout<<' ';
      cout<<t[i].num;
    }
    cout<<endl;
  }
  return 0;
}

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


public class Main{ 

	public static void main(String args[]){
		
		Scanner scan = new Scanner(System.in);
		DiceExtend d01 = new DiceExtend(scan.nextLine());
		Dice d02 = new Dice(scan.nextLine());
		if(d01.rollAllPattern(d02))
			System.out.println("Yes");
		else
			System.out.println("No");
	}

}
class DiceExtend extends Dice{
	public DiceExtend(String line){
		super(line);
	}
	public void printTop(){
		System.out.println(this.top);
	}
	public boolean rotateCheck(Dice d){
		for(int j=0;j<4;j++){
			rotate();
			if(this.equals(d))
				return true;
		}
		return false;
	}
	public boolean rollAllPattern(Dice d){
		for(int i=0; i<4;i++){
			roll('N');
			if(rotateCheck(d))
				return true;
		}
		roll('W');
		if(rotateCheck(d))
			return true;		
		roll('E');
		roll('E');		
		if(rotateCheck(d))
			return true;		
		return false;				
	}
	
}
class Dice{
	int top;
	int back;
	int right;
	int left;
	int front;
	int bottom;
	public Dice(String line){
		String[] face = line.split(" ");
		top = Integer.parseInt(face[0]);
		back = Integer.parseInt(face[1]);
		right = Integer.parseInt(face[2]);		
		left = Integer.parseInt(face[3]);
		front = Integer.parseInt(face[4]);
		bottom = Integer.parseInt(face[5]);
	}
	void rotate(){
		int tmp = front;
		front = right;
		right=back;
		back = left;
		left = tmp;
	}
	public void roll(char c){
		int tmp = top;
		switch(c){
			case 'N':
				top = back;
				back=bottom;
				bottom = front;
				front = tmp;
				break;
			case 'E':
				top = left;
				left = bottom;
				bottom = right;
				right = tmp;
				break;
			case 'S':
				top = front;
				front = bottom;
				bottom = back;
				back = tmp;
				break;
			case 'W':
				top = right;
				right = bottom;
				bottom = left;
				left = tmp;
				break;
		}
	}
	boolean equalFace(Dice d){
		if(this.top == d.top && 
		   this.bottom==d.bottom &&
		   this.right == d.right &&
		   this.left == d.left &&
		   this.front == d.front &&
		   this.back == d.back)
			return true;
		else
			return false;
	}
	@Override
	public int hashCode() {
	    final int prime = 31;
	    int result = 1;
	    result = prime * result + top;
	    result = prime * result +bottom;
	    result = prime * result + right;
	    result = prime * result + left;
	    result = prime * result + front;
	    result = prime * result + back;
	    return result;
    }
	@Override
	public boolean equals(Object obj) {
		Dice d = (Dice) obj;
		if(this.top == d.top && 
		   this.bottom==d.bottom &&
		   this.right == d.right &&
		   this.left == d.left &&
		   this.front == d.front &&
		   this.back == d.back)
			return true;
		else
			return false;
	}
}	
	
	

Measured memory_bytes: 17300
#include<iostream>
using namespace std;
#include<string>
int main()
{
    string a;
    getline(cin, a);
    for (unsigned i = 0; i < a.length(); i++) {
        if (islower(a[i]))
            a[i] = toupper(a[i]);
        else
            a[i] = tolower(a[i]);
    }
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 1180
#define MOD 998244353

#include <iostream>
#include <vector>
using namespace std;

long pow(long a, long b) {
	if (!b) return 1;
	long c = pow(a, b / 2);
	if (b % 2) c = a * c % MOD * c % MOD;
	else c = c * c % MOD;
	return c;
}

int main() {
	int N;
	cin >> N;
	vector<int> D(N);
	for (int& i : D) cin >> i;
	if (D.front()) {
		cout << 0;
		return 0;
	}
	vector<long> a(N);
	for (int& i : D) a[i]++;
	if (a.front() != 1) {
		cout << 0;
		return 0;
	}
	while (!a.back()) a.pop_back();
	long ans = 1;
	for (int i = 1; i < a.size(); i++) {
		ans *= pow(a[i - 1], a[i]);
		ans %= MOD;
	}
	cout << ans;
}

Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    int a[3]; for(int i=0; i<3; i++) cin >> a[i];
    int a_abs[3];
    a_abs[0]=abs(a[0]-a[1]);
    a_abs[1]=abs(a[1]-a[2]);
    a_abs[2]=abs(a[0]-a[2]);
    sort(a_abs,a_abs+3);
    int sum = a_abs[0]+a_abs[1];
    cout << sum << endl;
}

Measured memory_bytes: 256
I = lambda:list(map(int,input().split()))
n,=I()
k=int(n**0.5)
i=2;l=[]
while i<=k and n>1:
  c=0
  while n%i==0:
    n//=i;c+=1
  if c!=0:
    l.append(c)
  i+=1
if n!=1:
  l.append(1)
an=0
for i in l:
  d=int((2*i)**0.5)
  x=d if (d*d+d)//2<=i else d-1
  an+=x
print(an)

Measured memory_bytes: 9472
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int gcd(int a,int b)
{
	return b?gcd(b,a%b):a;
}

struct Edge{
	int src,dst;
	Edge(){}
	Edge(int s,int d):src(s),dst(d){}
};
typedef vector<vector<Edge> > Graph;

bool BFS(const Graph& g,int left,const vi& match,vi& level)
{
	int n=g.size();
	level.assign(n,n);
	queue<pii> q;
	rep(i,left) if(match[i]==-1)
		q.push(mp(i,0));
	bool res=false;
	while(!q.empty()){
		pii cur=q.front(); q.pop();
		int u=cur.first,l=cur.second;
		if(level[u]<=l) continue;
		level[u]=l;
		rep(i,g[u].size()){
			int v=g[u][i].dst;
			if(match[v]==-1)
				res=true;
			else
				q.push(mp(match[v],l+2));
		}
	}
	return res;
}

bool DFS(const Graph& g,int left,int u,vi& vis,vi& match,vi& level)
{
	rep(i,g[u].size()){
		int v=g[u][i].dst;
		if(vis[v]) continue;
		vis[v]=1;
		if(match[v]==-1 || level[v]>level[u] && DFS(g,left,match[v],vis,match,level)){
			match[u]=v;
			match[v]=u;
			return true;
		}
	}
	return false;
}

int HopcroftKarp(const Graph& g,int left,vi& match)
{
	int n=g.size();
	match.assign(n,-1);
	int res=0;
	for(vi level;BFS(g,left,match,level);)
		rep(i,left) if(match[i]==-1){
			vi vis(n);
			res+=DFS(g,left,i,vis,match,level);
		}
	return res;
}

int main()
{
	for(int m,n;scanf("%d%d",&m,&n),m|n;){
		vi bs(m),rs(n);
		rep(i,m) scanf("%d",&bs[i]);
		rep(i,n) scanf("%d",&rs[i]);
		
		Graph g(m+n);
		rep(i,m) rep(j,n) if(gcd(bs[i],rs[j])>1){
			g[i].push_back(Edge(i,m+j));
			g[m+j].push_back(Edge(m+j,i));
		}
		
		vi match;
		printf("%d\n",HopcroftKarp(g,m,match));
	}
	
	return 0;
}

Measured memory_bytes: 4792
function main (s) {
    s=s.split(" ");
	for(var i=0;i<3;i++)s[i]=parseInt(s[i]);
	console.log((s[1]-s[0]==s[2]-s[1])?"YES\n":"NO\n");
}
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree < int,  null_type,  less<int>,  rb_tree_tag,  tree_order_statistics_node_update > ordered_set;
typedef long long ll;
#define pb push_back
#define pi (acos(-1))
#define ull  unsigned long long
#define ld long double
#define all(v) v.begin(), v.end()
///freopen("input.txt","r",stdin);
///freopen("output.txt","w",stdout);
ll LCM(ll a, ll b)
{
    ll g = __gcd(a,b);
    return (a/g)*b ;
}
string numtostr(ll n)
{
    ostringstream str1 ;
    str1 << n ;
    return str1.str();
}
ll strtonum(string s)
{
    ll x ;
    stringstream str1(s);
    str1 >> x ;
    return x ;
}
ld d,t,s;
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>d>>t>>s;
    if(d/t<=s)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
const	int maxn = 2e5+100;
struct SECTION {
	ll l,r;
	SECTION() {}
	SECTION(ll l,ll r):l(l),r(r) {}
	bool operator<(const SECTION& oth) const {
		if(l==oth.l) return r < oth.r;
		return l < oth.l;
	}
	bool operator==(const SECTION& oth) const { return l==oth.l&&r==oth.r; }
};
map<ll,int> idx;
vector<SECTION> sec[maxn];
ll N,X,D;
 
int main() {
	std::ios::sync_with_stdio(false);
	ll kl=0,kr=0,key,cnt = 0,ans = 0;
	cin >> N >> X >> D;
	if(D==0) {
		if(!X) cout << 1 << endl;
		else cout << N+1 << endl;
		return 0;
	} else if(D<0) {
		X*=-1;
		D*=-1;
	}
	ll l,r;
	for(int i=0; i<=N; i++) {
		key = i*X;
		ll bb = key%D;
		l = r = key/D;
		l+=kl; r+=kr;
		if(idx[bb]==0ll) idx[bb] = ++cnt;
		sec[idx[bb]].push_back({--l,r});
		kl+=i,kr+=N-i-1;
	}
	for(int i=1; i<=cnt; i++) {
		SECTION tp;
		sort(sec[i].begin(),sec[i].end());
		tp = sec[i][0];
		for(SECTION now: sec[i]) {
			if(now.l <= tp.r) tp.r = max(tp.r,now.r);
			else {
				ans += tp.r-tp.l;
				tp = now;
			}
 
			if(now == sec[i].back()) {
				ans += tp.r-tp.l;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


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

using ll=long long;
#define int ll

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(a>b)a=b;}

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class t,class u>
ostream& operator<<(ostream&os, const pair<t,u>&p){
	return os<<"{"<<p.a<<","<<p.b<<"}";
}

template<class t> ostream&operator <<(ostream&os,const vc<t>&v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

template<class t>
void mkuni(vc<t>&v){
	sort(all(v));
	v.erase(unique(all(v)),v.ed);
}

const int inf=LLONG_MAX/4;

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	
	int n;cin>>n;
	vi p(n);rep(i,n){cin>>p[i];p[i]--;}
	vi q(n);rep(i,n){cin>>q[i];q[i]--;}
	
	int a=0,b=1;
	
	vi dp(n,0);
	rep(i,n){
		int s=0;
		int x=p[i];
		do{x=q[x];s++;}while(x!=p[i]);
		int y=0;
		while(y<s&&x!=i){
			x=q[x];
			y++;
		}
		if(y==s){
			cout<<-1<<endl;
			return 0;
		}
		x=p[i];
		int cnt=0;
		while(cnt<s&&a<inf&&a%s!=y){a+=b;cnt++;}
		if(cnt==s){
			cout<<-1<<endl;
			return 0;
		}
		cnt=0;
		int c=b;
		while(cnt<s&&c<inf&&c%s){c+=b;cnt++;}
		if(cnt==s){
			cout<<-1<<endl;
			return 0;
		}
		b=c;
	}
	if(a>=inf)cout<<-1<<endl;
	else cout<<a<<endl;
}



Measured memory_bytes: 3176
import java.io.*;


class Main {
    public static void main(String[] args) throws IOException{
	BufferedReader br =
	    new BufferedReader(new InputStreamReader(System.in));

	String str = br.readLine();
	String[] str2 = str.split(" ",0);
	int[] num = new int[3];
	for (int i = 0; i < 3; i++) {
	    num[i] = Integer.parseInt(str2[i]);
	}
	int a,b,c,temp1,temp2;
	if (num[0]<=num[1]) {
	    temp1 = num[1];
	    temp2 = num[0];
	}
	else{
	    temp1 = num[0];
	    temp2 = num[1];
	}
	if (temp1<=num[2]) {
	    a = num[2];
	    b = temp1;
	    c = temp2;
	}
	else if (temp1>=num[2] && num[2] >=temp2) {
	    a = temp1;
	    b = num[2];
	    c = temp2;
	}
	else{
	    a = temp1;
	    b = temp2;
	    c = num[2];
	}
	System.out.println(c+" "+b+" "+a);	
    }
}

Measured memory_bytes: 24368
a = int(input())
b = []
e = 0
for i in range(a):
    c, d = input().split()
    b.append([ i + 1, c, int(d)])
b = sorted(b, key=lambda x: x[2], reverse=True)
b = sorted(b, key=lambda x: x[1])
for i in b:
    print(i[0])


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstdio>
using namespace std;
int a,b,c,m;
int main()
{
    cin>>a>>b>>c;
    m=min(a+b,a+c);
    if(b+c<=m)
    cout<<b+c;
    else
    cout<<m;
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
using namespace std;

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

int main(){
	int n,a,b,c;
	scanf("%d",&n);
	rep(i,n){
		scanf("%d%d%d",&a,&b,&c);
		if( a*a+b*b==c*c || a*a+c*c==b*b || b*b+c*c==a*a ){
			puts("YES");
		}else{
			puts("NO");
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

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

Measured memory_bytes: 596
//https://atcoder.jp/contests/abc126/tasks/abc126_e
//E - 1 or 2
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}

struct uf_tree {
    std::vector<int> parent;
    int __size;
    uf_tree(int size_) : parent(size_, -1), __size(size_) {}
    void unite(int x, int y) {
        if ((x = find(x)) != (y = find(y))) {
            if (parent[y] < parent[x]) std::swap(x, y);
            parent[x] += parent[y];
            parent[y] = x;
            __size--;
        }
    }
    bool is_same(int x, int y) { return find(x) == find(y); }
    int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
    int size(int x) { return -parent[find(x)]; }
    int size() { return __size; }
};

int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-1.in");
    //std::ifstream in("./input.txt");
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll N,M; cin>>N>>M;
    uf_tree uft(N+1);
    REP(i,M){
        ll x,y,z;
        cin>>x>>y>>z; //zいる?
        uft.unite(x,y);
    }
    set<ll> ans;
    FOR(i,1,N+1){
        ans.insert(uft.find(i));
    }
    cout<<ans.size()<<endl;
    return 0;
}

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

using namespace std;

int C(int m, int n, int x, int c)
{
    if (c == 1) return(m <= x && x <= n);

    int sol = 0;
    for (int i = m; i <= n - c + 1; i++)
        sol += C(i + 1, n, x - i, c - 1);

    return sol;
}
int main()
{
    while(true)
    {
        int n, x; cin >> n >> x;
        if (n == 0 && x == 0) break;

        cout << C(1, n, x, 3) << '\n';
    }
    return 0;
}



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

def main():
  n,k = map(int,input().split())
  sl = [0]*n
  tree = [[] for i in range(n)]
  mod = 10**9+7
  q = []
  ans = k

  for i in range(n-1):
    a,b = map(int,input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

  if len(tree[0]) > 0:
    q = tree[0]
    for x in range(k-1, k-1-len(tree[0]), -1):
      ans = ans * x % mod
    sl[0] = 1
  else:
    print(k)
    exit()
  
  while q:
    pos = q.pop(0)
    sl[pos] = 1
    lent = len(tree[pos]) - 1
    if lent > 0:
      for x in range(k-2, k-2-lent, -1):
        ans = ans * x % mod
    for i in tree[pos]:
      if sl[i] == 0:
        q.append(i)
  print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 24940
import sys

def main():
  input = sys.stdin.readline
  S = str(input().strip())
  T = str(input().strip())
  
  C1, C2 = [], []
  ans = 'Yes'
  S2T = dict()
  T2S = dict()
  for c1, c2 in zip(S, T):
    if (c1 in S2T) and (c2 in T2S):
      if (S2T[c1] == c2) and (T2S[c2] == c1):
        continue
      else:
        ans = 'No'
        break
    elif (c1 in S2T):
      if S2T[c1] == c2:
        T2S[c2] = c1
        continue
      else:
        ans = 'No'
        break
    elif (c2 in T2S):
      if T2S[c2] == c1:
        S2T[c1] == c2
        continue
      else:
        ans = 'No'
        break
    else:
      S2T[c1] = c2
      T2S[c2] = c1
  print(ans)


if __name__ == '__main__':
  main()

Measured memory_bytes: 3632
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define df 0
#define MAX 100010

typedef struct{
  int damage;
  int flag;
}data;

data swords[2*MAX];

int comp(const void* a,const void* b){
  data x=*((data*) a),y=*((data*) b);
  return y.damage-x.damage;
}

int main(){
  int i,n,h;
  scanf("%d%d",&n,&h);
  for(i=0;i<n;i++){
    int a,b;
    scanf("%d%d",&a,&b);
    swords[2*i].damage=a;
    swords[2*i].flag=1;
    swords[2*i+1].damage=b;
    swords[2*i+1].flag=0;
  }
  qsort(swords,2*n,sizeof(data),comp);
  if(df){
    for(i=0;i<2*n;i++){
      printf("%d(%d) ",swords[i].damage,swords[i].flag);
    }
    printf("\n");
  }

  int count=0;
  i=0;
  while(h>0){
    if(swords[i].flag){
      int k=(h+swords[i].damage-1)/swords[i].damage;
      if(df)printf("k:%d\n",k);
      count+=k;
      h=0;
    }
    else{
      count++;
      h-=swords[i].damage;
    }
    i++;
  }

  printf("%d",count);
  return 0;
}


/// confirm df==0 ///


Measured memory_bytes: 3324
using System;
using System.Linq;

namespace ITP1_4_D
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var nums = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            int min = int.MaxValue;
            int max = int.MinValue;
            long sum = 0;
            foreach (var n in nums)
            {
                min = Math.Min(n, min);
                max = Math.Max(n, max);
                sum += n;
            }
            Console.WriteLine("{0} {1} {2}", min, max, sum);
        }
    }
}

Measured memory_bytes: 10412
package scc;
sub new{
	return bless[map[],1..$_[1]],$_[0];
}
sub add_edge{
	my$self=shift;
	push@{$self->[$_[0]]},$_[1];
}
sub scc{
	my$self=shift;
	my$now_ord=0,$group_num=0,@low=(0)x@{$self},@ord=(-1)x@{$self},@ids=(0)x@{$self};
	my@visited;
	my$dfs;
	$dfs=sub{
		my$v=shift;
		$low[$v]=$ord[$v]=$now_ord++;
		push@visited,$v;
		for$to(@{$self->[$v]}){
			if($ord[$to]==-1){
				$dfs->($to);
				$low[$v]=$low[$to]if$low[$v]>$low[$to];
			}
			else{
				$low[$v]=$ord[$to]if$low[$v]>$ord[$to];
			}
		}
		if($low[$v]==$ord[$v]){
			my$u=-1;
			while($u!=$v){
				$u=pop@visited;
				$ord[$u]=@{$self};
				$ids[$u]=$group_num;
			}
			$group_num++;
		}
	};
	for$i(0..$#ord){
		$dfs->($i)if$ord[$i]==-1;
	}
	$_=$group_num-1-$_ for@ids;
	@groups=map[],1..$group_num;
	for$i(0..$#ids){
		push@{$groups[$ids[$i]]},$i;
	}
	return\@groups;
}
package main;
my($N,$M)=split$",<>;
my$scc=scc->new($N);
for(1..$M){
	my($a,$b)=split$",<>;
	$scc->add_edge($a,$b);
}
$groups=$scc->scc();
print scalar(@{$groups}),$/;
for$L(@{$groups}){
	print scalar(@{$L}),$","@{$L}",$/;
}


Measured memory_bytes: 288380
/*  Success may not come to me immediately,
 *  but it will come definitely....
 */
#include<bits/stdc++.h>
//=====================================================================
using namespace std;
//=====================================================================
#define opt ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//=====================================================================
#define li  int64_t
#define ld  double_t
#define ulli    uint64_t
//=====================================================================
#define rep(i,a,b)  for(i=a;i<b;i++)
#define repr(i,a,b) for(i=a;i>b;i--)
#define repi(i,v)   for(i=v.begin();i!=v.end();i++)
#define elif        else if
#define mset(a,b)   memset(a,b,sizeof(a))
#define nl      cout<<'\n'
//=====================================================================
typedef vector<li>       vli;
typedef vector<string>   vstr;
typedef pair<li,li>      pli;
typedef pair<li,pli >    ppli;
typedef pair<li,ppli >   pppli;
typedef vector<pli >     vpl;
typedef vector<ppli >    vppli;
typedef vector<pppli >   vpppli;
//=====================================================================
#define pb  push_back
#define pob pop_back
#define pf  push_front
#define pof pop_front
#define all(v)  v.begin(),v.end()
#define itr iterator
#define sz  size()
#define lb  lower_bound
#define ub  upper_bound
#define bs  binary_search
#define mp  make_pair
#define F   first
#define S   second
//=====================================================================
#define mod (li)(1e9+7)
#define inf (li)(1e18)
#define MX1 (li)(1e5+5)
#define MX2 (li)(1e6+5)
#define pi  acos(-1)
//=====================================================================
li power(li a,li b){li ans=1;while(b){if(b&1){ans=(ans*a)%mod;}
a=(a*a)%mod;b>>=1;}return ans;}
//=====================================================================
li mmi(li n){return power(n,mod-2);}
//=====================================================================
li two(li n){return 1<<n;}
//=====================================================================
void onbit(li &n,li x){n|=two(x);}
//=====================================================================
void offbit(li &n,li x){n&=~two(x);}
//=====================================================================
li cntbit(li n){li res=0;while(n and ++res)n-=n&-n;return res;}
//=====================================================================
li dx[]={-1,0,1,0},dy[]={0,-1,0,1};
//=====================================================================
/*------------------------MAIN CODE BEGINS NOW!------------------------*/

li n,a[2*MX1];

void solve(){
    li i;cin>>n;
    rep(i,1,n+1) cin>>a[i],a[i]+=a[i-1];
    li ans=abs(a[n]-2*a[1]);
    rep(i,2,n){
        ans=min(ans,abs(a[n]-2*a[i]));
    }
    cout<<ans;
}

int main(){
    opt
    #ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif
    li t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  int64_t y=0;
  for(int i=0;i<n;i++){
    cin>>a.at(i);
    y+=(i==0?0:a.at(i));
  }
  int64_t x=a.at(0);
  int64_t m=abs(x-y);
  for(int i=1;i+1<n;i++){
    x+=a.at(i);
    y-=a.at(i);
    m=min(m,abs(x-y));
  }
  cout<<m<<endl;
}

Measured memory_bytes: 1024
x, y, a, b, c = map(int, input().split())
p = sorted(list(map(int, input().split())), reverse=True)
q = sorted(list(map(int, input().split())), reverse=True)
r = sorted(list(map(int, input().split())), reverse=True)
print(sum(sorted(p[:x]+q[:y]+r, reverse=True)[:(x+y)]))

Measured memory_bytes: 29408
#include <stdio.h>

int main(void){
	int i,p,q,r,min[10],_min=0;
	scanf("%d %d %d",&p,&q,&r);
	min[0]=p+q;
	min[1]=r+q;
	min[2]=p+r;
	_min = min[0];
	for(i=1;i<3;i++){
		if(_min > min[i]){
			_min = min[i];
		}
	}
	printf("%d\n",_min);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
#define _GLIBCXX_DEBUG
using namespace std;

int main(){
  string s;
  cin >> s;
  vector<int> count(3);
  rep(i,s.size()){
    count[(s[i]-'a')]++;
  }
  /*rep(i,3){
    cout << count[i];
  }*/
  bool dame = false;
  for(int i=0;i < 3;i++){
    for(int j=i+1;j < 3;j++){
      dame = dame || (abs(count[i]-count[j]) > 1);
    }
  }
  if(!dame){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}
      
    

Measured memory_bytes: 512
def main():
  a,b = map(int,input().split())
  if a == 1:
    a = 14
  if b == 1:
    b = 14
  if a > b:
    print('Alice')
  elif a == b:
    print('Draw')
  else:
    print('Bob')
if __name__ == '__main__':
  main()

Measured memory_bytes: 2940
n = input()
if len(n)==1:
  print(n)
elif len(n)==2:
  print("9")
elif len(n)==3:
  print(int(n)-90)
elif len(n)==4:
  print("909")
elif len(n)==5:
  print(909+int(n)-10000+1)
else:
  print(90909)
  

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string n;
  cin >> n;
  
  int ans = 0;
  for(int i = 0; i < 4; i++) if(n.at(i) == '2') ans++;
  
  cout << ans << '\n';
}

Measured memory_bytes: 256
N = int(input())
A = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N)]

M = N*N

def c(a,b):
    if a>b: a,b=b,a
    return a*N+b

G = [[] for _ in range(M)]
for i in range(N):
    a = A[i]
    x = i
    for j in range(N-1-1):
        y1 = a[j]
        y2 = a[j+1]
        G[c(x,y1)].append(c(x,y2))

dp = [0]*M
started = [False]*M
finished = [False]*M
for i in range(N):
    for j in range(i+1, N):
        s = c(i,j)
        if started[s]: continue
        stk = [(s, 0)]
        while stk:
            v, s = stk.pop()
            if s == 0:
                if started[v]:
                    if not finished[v]:
                        print(-1)
                        exit()
                    continue
                started[v] = True
                stk.append((v, 1))
                for to in G[v]:
                    stk.append((to, 0))
            else:
                finished[v] = True
                for to in G[v]:
                    dp[v] = max(dp[v], dp[to] + 1)

print(max(dp) + 1)

Measured memory_bytes: 158576
import sys
N,K=list(map(int,sys.stdin.readline().split()))
H=list(map(int,sys.stdin.readline().split()))

dp=[0]*N

for i in range(1,N):
    mn=10**9
    for j in range(max(0,i-K),i):
        mn=min(mn,dp[j]+abs(H[j]-H[i]))

    dp[i]=mn

print(dp[-1])

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */



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

	LL A, B, C, D, E, F; cin >> A >> B >> C >> D >> E >> F;
	auto  f = [](int a, int b) {
		VI dp(3001, 0);
		dp[0] = 1;
		FOR(i, a, 3001) {
			if (dp[i - a])dp[i] = 1;
		}
		FOR(i, b, 3001) {
			if (dp[i - b])dp[i] = 1;
		}
		return dp;
	};
	auto usew = f(100 * A, 100 * B);
	auto uses = f(C, D);
	// どちらもokな集合のとき、check
	LL answ = INF;
	LL anss = 0;
	FOR(w, 0, 3001) {
		FOR(s, 0, 3001) {
			if (usew[w] && uses[s]) {
				if (w + s <= F) {
					// Eまで溶ける
					if (s*(100 + E) <= E * (w + s)) {
						if (anss*(w + s) <= s*(answ + anss)) {
							answ = w;
							anss = s;
						}
					}
				}
			}
		}
	}
	if (answ == INF)answ = 0;
	cout << answ + anss << " " << anss << endl;

	return 0;
}


Measured memory_bytes: 256
const D=Dict{Pair{Int32,Int32},Int8}()
function f(H,W,x,y,cnt)
	for (dx,dy)=zip([1,1,1,0,0,0,-1,-1,-1],[1,0,-1,1,0,-1,1,0,-1])
		tx,ty=x+dx,y+dy
		if 1<tx<H&&1<ty<W
      v=Int32(tx)=>Int32(ty)
			t=get(D,v,0)
			cnt[t+1]-=1
			cnt[t+2]+=1
			D[v]=t+1
		end
	end
end
function main()
	H,W,N=map(x->parse(Int,x),split(readline()))
	cnt=zeros(Int,10)
	cnt[1]=(H-2)*(W-2)
	for s=readlines()
		x,y=map(x->parse(Int32,x),split(s))
		f(H,W,x,y,cnt)
	end
	println(join(cnt,'\n'))
end
main()


Measured memory_bytes: 180836
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
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); }

/*--------------------template--------------------*/

int main()
{
	string s;
	while (cin >> s, s != "#")
	{
		vector<string> ans;
		int n = s.size();
		REP(i, 1 << n)
		{
			string tmp = s;
			bool f = true;
			REP(j, n)
			{
				if ((i >> j) & 1)
				{
					if (s[j] == 'z')
					{
						f = false;
						break;
					}
					else tmp[j]++;
				}
			}
			if (f)
			{
				string cp = tmp;
				bool used[26] = {};
				REP(i, cp.size())
				{
					if (!used[cp[i] - 97] && cp[i] != 'a')
					{
						used[cp[i] - 97] = true;
						cp[i]--;
					}
					if (cp[i] != s[i]) break;
				}
				if (s == cp) ans.push_back(tmp);
			}
		}
		sort(ALL(ans));
		int sz = ans.size();
		printf("%d\n", sz);
		if (sz > 10)
		{
			REP(i, 5) printf("%s\n", ans[i].c_str());
			FOR(i, sz - 5, sz) printf("%s\n", ans[i].c_str());
		}
		else
		{
			REP(i, sz) printf("%s\n", ans[i].c_str());
		}
	}
	return 0;
}

Measured memory_bytes: 4280
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var N = cin.ReadInt;
            var d = cin.ReadIntArray(N).Distinct();
            WriteLine(d.Count());                 
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}


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

int main() {
	int n,k;
	cin >> n >> k;
	int l[55];
	int ans=0;
	for(int i=0;i<n;i++) cin >> l[i];
	sort(l,l + n,greater<int>());
	for(int i=0;i<k;i++) ans = ans + l[i];
	cout << ans << endl;
}

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

#define ll long long int
#define str string
#define ALL(a)  (a).begin(),(a).end()
#define P pair<ll,ll>

using Graph = vector<vector<int>>;

const int dy[] = { 0, 0, 1, -1 }, dx[] = { 1, -1, 0, 0 };
ll INFL = 1ll << 60, INF = 1 << 30, mod = 1e9 + 7, Min = INFL, Max = -1;
ll a, b, c, n, sum, A[500010], B[500000], rui[500000], dp[5000];
str S; bool check = true;	vector<ll> v;



int main() {
	//Code Line
	cin >> a >> n;
	for (int i = 0; i < n; i++) {
		cin >> A[i];
		sum += A[i];
	}
	if (a <= sum)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 4352
from collections import deque
N = int(input())
S = [list(input()) for _ in range(N)]


def bfs(i):

    d = [-1 for _ in range(N)]
    d[i] = 0

    que = deque([(i, 0, -1)])

    finished = set()
    while que:
        ci, dist, p = que.popleft()
        # print(ci, dist, p)

        for j in range(N):
            if S[ci][j] == '1':
                if j != p and d[j] >= 0:
                    if d[j] == dist or (d[j] != dist+1 and j not in finished):
                        # print(ci, j)
                        return -1
                elif d[j] == -1:
                    d[j] = dist+1
                    que.append((j, dist+1, ci))
        finished.add(ci)

    return dist+1


ans = -1
for i in range(N):
    b = bfs(i)
    ans = max(ans, b)

print(ans)


Measured memory_bytes: 46380
// 12.1 交換ソート
#include<bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> data(n);
    for(int i=0; i<n; i++){
        cin>>data[i];
    }
    int count=0;

    for(int i=0; i<n-1; i++){
        for(int j=n-1; j>i; j--){
            if(data[j-1]>data[j]){
                swap(data[j-1],data[j]);
                count++;
            }
        }
    }

    for(int i=0; i<n-1; i++){
        cout<<data[i]<<" ";
    }

    cout<<data[n-1]<<endl<<count<<endl;
}


Measured memory_bytes: 3088
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC073A
{
    class Program
    {
        static void Main(string[] args)
        {
            String  n;        //文字列型変数ｎ

            n = Console.ReadLine();//キーボードから整数を読み込む

            if (n[0]=='9'  || n[1]=='9')//１文字目が’９’または
                Console.WriteLine("Yes");//２もじめが’９’なら”Yes"

            else
                Console.WriteLine("No");//それ以外は”No"

            Console.ReadKey();//キー入力待ち

          
        }
    }
}


Measured memory_bytes: 13140
// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define N 1000005
#define ll long long
#define debug(a) cout<<#a<<": ";for(auto i:a)cout<<i<<" ";cout<<endl;
#define trace(a) cout<<#a<<": "<<a<<endl;
#define int ll
// int a[N];
int a,b;
bool check(int val) {
	int mid = val/2;
	int ma = 0;
	for(int i = max(mid-10,1LL);i <= min(mid+10,val);i++) {
		// 1 -> val, 2 -> val-1, i -> val-i+1
		if(i == a || val-i+1 == b) continue;
		ma = max(ma,i*(val - i + 1));
	}
	// cout << val << " " << ma << endl;
	if(ma < a*b) {
		return true;
	}
	return false;
}
signed main() {
	ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);
	int i,j,k,l,m,n,t;
	cin >> t;
	while(t--) {
		// ll a,b;
		cin >> a >> b;
		if(a > b) swap(a,b);
		if(a == 1 && b == 1) {
			cout << "0" << endl;
			continue;
		}
		l = 0;
		int r = 2e9;
		ll ans = 0;
		while(l <= r) {
			int mid = (l+r)/2;
			if(check(mid)) {
				ans = mid;
				l = mid+1;
			}
			else {
				r = mid-1;
			}
		}
		cout << ans-1 << endl;
	}
}

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

using namespace std;

typedef long long ll;

vector<int> Zalgo(const string &s){
	int n = (int) s.size();
	vector<int> res(n);
	res[0] = n;
	int i = 1, j = 0;
	while(i < n){
		while(i + j < n && s[j] == s[i + j]) j++;
		res[i] = j;
		if(j == 0){
			i++;
			continue;
		}

		int k = 1;
		while(i + k && k + res[k] < j){
			res[i + k] = res[k];
			k++;
		}

		i += k, j -= k;
	}

	return res;
}

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

	int n;
	cin >> n;

	string s;
	cin >> s;

	int res = 0;
	rep(i, n){
		string t = s.substr(i);
		auto lcp = Zalgo(t);

		rep(j, t.size()){
			int l = min(lcp[j], j);
			res = max(res, l);
		}
	}

	cout << res << endl;
}


Measured memory_bytes: 256
n,m = (int(i) for i in input().split())
x = [int(i) for i in input().split()]
if n>=m: print(0)
elif n==1: print(max(x)-min(x))
else:
	x,y = sorted(x),[]
	for i in range(m-1): y.append(x[i+1]-x[i]) 
	print(sum(sorted(y)[:-(n-1)]))

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

int main(){
  int k,n,l[55],s=0;
  cin>>n>>k;
  fr(i,n) cin>>l[i];
  sort(l,l+n);
  fr(i,k) s+=l[n-1-i];
  cout<<s<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   string s;
   
   cin>>s;
   
   int q;
   cin>>q;
   int re=0;
   while (q--)
   {
       
       int t;
       cin>>t;
       if (t==1)
       {
           re++;
       }
       else
       {
           int f;
           char c;
           cin>>f>>c;
           if ((f+re)%2)
           s.insert(s.begin(),1,c);
           else
           s.push_back(c);
           
           
       }
   }
   if (re%2)
   reverse(s.begin(),s.end());
   cout<<s;
}


Measured memory_bytes: 900
#include <iostream>
using namespace std;
 
#define check cnt=0;for(j=0;j<6;j++)if(d[q][j]==d[r][j])cnt++;
#define m tmp=d[r][1];d[r][1]=d[r][3];d[r][3]=d[r][4];d[r][4]=d[r][2];d[r][2]=tmp;
#define y tmp=d[r][0];d[r][0]=d[r][3];d[r][3]=d[r][5];d[r][5]=d[r][2];d[r][2]=tmp;
 
bool same(int d[][6],int q,int r){
 int tmp,cnt,j,a=1,i,k;
 check
   if(cnt==6)a=0;
 
 while(a){
  for(i=0;i<5;i++){
   for(k=0;k<4;k++){
    check
    if(cnt==6)break;
    m
   }
   check
   if(cnt==6)break;
   tmp=d[r][0];
   d[r][0]=d[r][1];
   d[r][1]=d[r][5];
   d[r][5]=d[r][4];
   d[r][4]=tmp;
  }
  if(cnt==6)break;
  y
  for(k=0;k<4;k++){
   check
   if(cnt==6)break;
   m
  }
  if(cnt==6)break;
  y
  y
  for(k=0;k<4;k++){
   check
   if(cnt==6)break;
   m
  }
  a=0;
 }
 
 if(cnt==6)return true;
 return false;
 
}
 
 
int main(){
 int n,tmp,cnt,a=1,i,j,judge=0;
 
 cin >> n;
 
 int d[n][6];
 
 for(i=0;i<n;i++){
  for(j=0;j<6;j++){
   cin >> d[i][j] ;
  }
 }
 
 for(int q=0;q<n-1;q++){
  for(int r=q+1;r<n;r++){
  if(same(d,q,r))judge++;
  }
 }
 if(judge>0)cout << "No" << endl ;
 else cout << "Yes" << endl ;
 
 return 0;
}

Measured memory_bytes: 3088
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N,M,ans=inf,res;
  cin>>N>>M;
  res=M-N;
  if(res>0)chmin(ans,res);
  res=M+N+1;
  if(res>0)chmin(ans,res);
  res=-M-N+1;
  if(res>0)chmin(ans,res);
  res=N-M+2;
  if(res>0)chmin(ans,res);
  cout<<ans<<endl;
  return 0;
}

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

int up(const void*a,const void*b){
    return*(long long*)a<*(long long*)b?-1:*(long long*)a>*(long long*)b?1:0;
}
int down(const void*a,const void*b){
    return*(long long*)a<*(long long*)b?1:*(long long*)a>*(long long*)b?-1:0;
}
void upsort(long long*a,int n){
    qsort(a,n,sizeof(long long),up);
}
void downsort(long long*a,int n){
    qsort(a,n,sizeof(long long),down);
}
int judge(long long*a,long long*b,long long n,long long k,long long x){
    long long time=0;
    for(int i=0;i<n;i++){
        time+=(a[i]*b[i]-x>0)?a[i]-x/b[i]:0;
    }
    return time<=k;
}

int main(void){
    long long n,k;
    scanf("%lld%lld",&n,&k);
    long long a[n],f[n];
    for(int i=0;i<n;i++)scanf("%lld",a+i);
    upsort(a,n);
    for(int i=0;i<n;i++)scanf("%lld",f+i);
    downsort(f,n);
    long long high=a[n-1]*f[0],low=0,mid;
    long long sum=0;
    for(int i=0;i<n;i++){
        sum+=a[i];
    }
    if(sum<=k){
        printf("0\n");
        return 0;
    }
    else{
        while(high>low+1){
            mid=(high+low)/2;
            if(judge(a,f,n,k,mid))high=mid;
            else low=mid;
        }
        printf("%lld\n",high);
        return 0;
    }
}



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

int		main(void)
{
	char c[3][3];
	
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
			cin >> c[i][j];
	}
	for (int i = 0; i < 3; i++)
		cout << c[i][i];
	cout << endl;
}


Measured memory_bytes: 384