akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

int dp[200001];

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n; cin >> n;
  rep(i, 200001) dp[i] = MOD;
  dp[0] = 0;

  rep(i, n+1) {
    for (int j = 6; i+j <= n; j *= 6) chmin(dp[i+j], dp[i]+1);
    for (int j = 9; i+j <= n; j *= 9) chmin(dp[i+j], dp[i]+1);
    chmin(dp[i+1], dp[i]+1);
  }

  cout << dp[n] << endl;

  return (0);
}


Measured memory_bytes: 4292
#include <iostream>
#include <string>
#include <set>

int main()
{
  std::set<int> s {};
  int n;
  std::cin >> n;
  for (int i = 0; i < n; i++)
  {
	int v;
    std::cin >> v;
    if (s.find(v) != s.end())
    {
      std::cout << "NO";
      return 0;
    }
    s.insert(v);
  }
  std::cout << "YES";
  return 0;
}

Measured memory_bytes: 9600
using System;
using static System.Console;

namespace dp
{
    class Program
    {
        static int[] ReadNumList()
        {
            var line = ReadLine().Split(' ');
            if (line.Length == 1 && string.IsNullOrEmpty(line[0]))
            {
                return new int[0];
            }
            var numList = new int[line.Length];
            for (var i = 0; i < line.Length; ++i)
            {
                numList[i] = int.Parse(line[i]);
            }
            return numList;
        }
        static int Default = -1;
        static void Main()
        {
            var nk = ReadLine().Split(' ');
            var k = int.Parse(nk[1]);
            var aList = ReadNumList();

            var dp = new int[k + 1];
            dp[0] = 0;
            for (var i = 1; i < dp.Length; ++i)
            {
                dp[i] = Default;
            }

            for (var i = 1; i < dp.Length; ++i)
            {
                var won = false;
                foreach (var a in aList)
                {
                    if (i - a >= 0 && dp[i - a] == 0)
                    {
                        won = true;
                        break;
                    }
                }
                dp[i] = won ? 1 : 0;
            }

            WriteLine(dp[k] == 1 ? "First" : "Second");
        }
    }
}


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

class MainClass
{
    static void Main()
    {
        int N = int.Parse(ReadLine());
        if (N <= 999)
        {
            WriteLine("ABC");
        }
        else
        {
            WriteLine("ABD");
        }
    }
}


Measured memory_bytes: 27308
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    ll n,ab[201],cd[201];
    Fill(ab,-1);
    Fill(cd,-1);
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        ll tmpx,tmpy;
        std::cin >> tmpx>>tmpy;
        ab[tmpx] = tmpy;
    }
    for (int i = 0; i < n; i++) {
        ll tmpx,tmpy;
        std::cin >> tmpx>>tmpy;
        cd[tmpx] = tmpy;
    }
    
    ll result = 0;
    for (int i = 0; i < 2*n; i++) {
        if(cd[i]!=-1){
            vector<ll> tmp;
            for (int j = 0; j < i; j++) {
                if(ab[j]<cd[i] && ab[j]!=-1){
                    tmp.push_back(j);
                }
            }
            if(tmp.size()==0){
                continue;
            }else{
                ll max_v =-1;
                ll max_i =-1;
                
                for (auto e : tmp) {
                    // std::cout << e << " e "<<ab[e] << std::endl;
                    if(max_v<ab[e]){
                        max_v = ab[e];
                        max_i = e;
                    }
                }
                
                // std::cout << i<<" "<<max_i << std::endl;

                result++;
                ab[max_i] = -1;
            }
        }
    }
    
    std::cout << result << std::endl;
    
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
  int a, b, c;
  int i, cnt = 0;

  scanf("%d %d %d", &a, &b, &c);

  for (i = a; i <= b; i++) {
    if (c % i == 0) {
      cnt++;
    }
  }

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

  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define N 100005
#define M 200005
#define INF 0x3f3f3f3f
using namespace std;
struct edge{
	int t,next,dis;
}e[8*M];int ecnt,head[M*4+N];
void addedge(int f,int t,int val){
	e[++ecnt]=(edge){t,head[f],val};head[f]=ecnt;
}
int dis[M*4+N];
void SPFA(int S,int T){
	memset(dis,0x3f,sizeof(dis));
	deque<int> q;
	q.push_front(S);dis[S]=0;
	while( !q.empty() ){
		int u=q.front();q.pop_front();
		for(int i=head[u];i;i=e[i].next){
			if(dis[e[i].t]>dis[u]+e[i].dis){
				dis[e[i].t]=dis[u]+e[i].dis;
				if(e[i].dis==0) q.push_front(e[i].t);
				else q.push_back(e[i].t);
			}
		}
	}
}
//-----
int n,m,pcnt;
int ci[M*2],phead[N];
bool cmp(int a,int b){
	return ci[a]<ci[b];
}
vector<int> sta[N];//每个点内装的是指向外面的边 
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1,f,t,d;i<=m;i++) 
		scanf("%d%d%d",&f,&t,&d),
		sta[f].push_back(i*2),sta[t].push_back((i*2)^1),
		ci[i*2]=ci[(i*2)^1]=d;
	
	pcnt=m*2+1+n;
	for(int i=1;i<=n;i++){
		sort(sta[i].begin(),sta[i].end(),cmp);
		int len=sta[i].size();int now=0;
		while(now<len){
			int p;
			for(p=now;p+1<len&&ci[sta[i][p+1]]==ci[sta[i][p]];p++);
			int t=++pcnt;
			for(int j=now;j<=p;j++) addedge(t,sta[i][j],0),addedge(sta[i][j]^1,t,0);
			now=p+1;
		}
		
		for(int j=0;j<len;j++) addedge(m*2+1+i,sta[i][j],1),addedge(sta[i][j]^1,m*2+1+i,0);
	}
	
	int S=m*2+1+1,T=m*2+1+n;
	
	SPFA(S,T);
	if(dis[T]!=INF) printf("%d\n",dis[T]);
	else printf("-1\n");
 
	return 0;
}

Measured memory_bytes: 34808
#二分ヒープ
class binaryHeap:
    def __init__(self):
        self.ls = []
    def add(self,n):
        self.ls.append(n)
        i = len(self.ls)-1
        while True:
            parent = i // 2
            if i == 0 or self.ls[parent] > self.ls[i]:break
            else:
                self.ls[parent],self.ls[i] = self.ls[i],self.ls[parent]
                i = parent
    def pop(self):
        n = self.ls.pop()
        if len(self.ls) == 0:return n
        ans = self.ls[0]
        self.ls[0] = n
        i = 0
        while True:
            child = 0
            if 2*i >= len(self.ls):return ans
            elif 2*i+1 >= len(self.ls):child = 2*i
            elif self.ls[2*i] > self.ls[2*i+1]:
                child = 2*i
            else:
                child = 2*i+1
            if self.ls[child] <= self.ls[i]:
                return ans
            else:
                self.ls[child],self.ls[i] = self.ls[i],self.ls[child]
                i = child

n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
heap = binaryHeap()
for i in a:
    heap.add(i)
for i in range(m):
    n = heap.pop()
    n //= 2
    heap.add(n)
print(sum(heap.ls))

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

typedef long long ll;
typedef pair<int, int> P;

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    vector<int> a(3);
    for(int i=0; i<3; i++) cin>>a[i];
    sort(a.begin(), a.end());
    cout << 10*a[2]+a[1]+a[0] << endl;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int S;
     cin >> S;
    int left = S/100;
    int right = S - left*100;

    if(1<=left && left<=12 && 1<=right && right <= 12){
        cout << "AMBIGUOUS" << endl;
    }
    if((1<=left && left<=12) && (right<1 || 12<right)){
        cout << "MMYY" << endl;
    }
    if((left<1 || 12<left) && (1<=right && right<=12)){
        cout << "YYMM" << endl;
    }
    if((left<1 || 12<left) && (right<1 || 12<right)){
        cout << "NA" << endl;
    }
    return 0;
}

Measured memory_bytes: 3608
x,k,d = map(int, input().split())
ans=0
p=abs(x)//d
if abs(x)>=k*d:
    ans=abs(x)-k*d
elif abs(x)<=d:
    if k%2==0:
        ans=abs(x)
    else:
        if x<=0:
            ans=x+d
        else:
            ans=d-x
else:
    if (k-p)%2==0:
        ans=abs(x)-p*d
    else:
        ans=abs(abs(x)-p*d-d)        
print(ans)

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

int main(){
  int n;
  int i,j;
  int card[4][13]={{}};   // これで、リスト構造を作れている。 すべての要素に0が代入済み
  cin >> n;
  char a;  // char は一文字なら、英単語には用いてよい。また、charは数値として処理されるから、switchなどが用いることができる。
  int b;
  for (i=0;i<n;i++){
      cin >> a >> b ;
      switch(a){
          case 'S':
              card[0][b-1]=1;
              break;
          case 'H':
              card[1][b-1]=1;
              break;
          case 'C' :
              card[2][b-1]=1;
              break;
          case 'D':
              card[3][b-1]=1;
              break;
      }
  }
  
  for (j=0;j<52;j++){
      switch(j/13){
          case 0:
              if(card[0][(j%13)]==0){
                  cout << "S " << j+1 << endl;
              }
                  break;
              
          case 1:
              if(card[1][j%13] == 0){
                  cout << "H "<< (j%13)+1 << endl;
              }
                  break;
              
          case 2:
              if(card[2][j%13] == 0){
                  cout << "C "<< (j%13)+1 << endl;
              }
                  break;
              
          case 3:
              if(card[3][j%13] == 0){
                  cout << "D "<< (j%13)+1 << endl;
              }
                  break;
              
          
      }
  }
  
  return 0;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
int main(){
	int k[105];
	int n,m=0,x=10001;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>k[i];
		m+=k[i];
	}
	int y=0;
	for(int i=0;i<n;i++){
		y+=k[i];
		m-=k[i];
		x=min(max(y,m)-min(y,m),x);
	}
	cout<<x;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int num,rnd,i,j,ans;
  long pt;
  
  scanf("%d",&num);
  int ansr[num];
  scanf("%ld",&pt);
  scanf("%d",&rnd);
  for(i=0;i<num;i++){
    ansr[i] = pt-rnd;
  }
  
  for(i=0;i<rnd;i++){
    scanf("%d",&ans);
    ansr[ans-1]++;
  }
  for(i=0;i<num;i++){
    if(ansr[i]>0)
      printf("Yes\n");
    else
      printf("No\n");
  }
}

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

int main(void){
    int x,y;
    for(int i=0; i<3000; i++){
        cin >> x >> y;
        if(x==0 && y==0) break;
        if(x <= y) cout << x << " " << y << endl;
        else if(x > y) cout << y << " " << x << endl;
    }

    return 0;
}

Measured memory_bytes: 2996
q,h,s,d = list(map(int, input().strip().split()))
n = int(input())

h = min(h, q*2)
s = min(s, h*2)
d = min(d, s*2)

d_num, s_num = n//2, n%2
cost = d_num*d + s_num*s
print(cost)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll x,a,b;
    cin >>x>>a>>b;
    
    if ((abs(x-a))> (abs(x-b))) cout << "B" << endl;
    else cout << "A" << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int N, A[100], i, j;
  int  c=0, minj, x;

  scanf("%d",&N);
  for(i = 0 ; i < N ; i++)
    scanf("%d",&A[i]);

  for(i = 0 ; i < N ; i++){
    minj = i;
    for(j = i ; j < N ; j++){
      if(A[j] < A[minj])
	minj = j;
    }
    x = A[i];
    A[i] = A[minj];
    A[minj] = x;
    if(minj != i)
      c++; 
    }
  i=0;
  while(1){
    printf("%d",A[i]); 
    if(i == N-1)break;
    printf(" ");
    i++;
  }
  printf("\n");
  printf("%d\n",c);

  return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
    int n,m;
    cin>>n>>m;

    vector<ll> a(n);
    rep(i,n)cin>>a[i];

    sort(a.begin(),a.end());
    vector<pair<ll,int>> bc;
    rep(i,m){
        int b;
        ll c;
        cin>>b>>c;
        bc.push_back({c,b});
    }
    sort(bc.rbegin(),bc.rend());
    int p = 0;
    int bcp = 0;
    while(p<n){
        if(bc[bcp].first>=a[p]){
            a[p]=bc[bcp].first;
            p++;
        }else{
            break;
        }

        bc[bcp].second--;
        if(bc[bcp].second==0){
            bcp++;
            if(bcp==m)break;
        }
    }
    ll sum = 0;
    rep(i,n){
        sum+=a[i];
    }
    cout<<sum<<endl;
    
return 0;
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define ll long long
#define inf 9999999999999999
#define F first
#define S second
#define eb emplace_back
#define mpp make_pair
#define P(x) cout<<__LINE__ <<": "<<#x<<' '<<(x)<<'\n'
#define dbg cout<<__LINE__ <<": 0manush\n"
#define read(x) freopen("input.txt","r",stdin)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pi 2*acos(0.0)
#define ee exp(1)
#define mx 100009
#define mod 10000007
using namespace std;
int main(){//read(x);
//fast;
ll r,g,h,i,j,x,y,t,e,a,b,c,d,n,l,k;

    cin>>n;
    ll m[n+5][3],dp[n+55][3];
    for(i=0;i<n;i++)
        for(j=0;j<3;j++)
            cin>>m[i][j];

    dp[n][0]=dp[n][1]=dp[n][2]=0;
    l=0;
    for(i=n-1;i>=0;i--){
        dp[i][0]=max(m[i][1]+dp[i+1][1],m[i][2]+dp[i+1][2]);
        dp[i][1]=max(m[i][0]+dp[i+1][0],m[i][2]+dp[i+1][2]);
        dp[i][2]=max(m[i][1]+dp[i+1][1],m[i][0]+dp[i+1][0]);
    }
    //cout<<dp[0][0]<<' '<<dp[0][1]<<' '<<dp[0][2]<<endl;
    l=max(dp[0][0],max(dp[0][1],dp[0][2]));
    cout<<l<<endl;
}





















Measured memory_bytes: 8252
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
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; }
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
#define pll pair<ll,ll>
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

int main(){
    string s,t;
    cin>>s>>t;
    ll ans=0;
    rep(i,0,s.length())if(s[i]!=t[i])ans++;
    cout<<ans;
}



Measured memory_bytes: 3924
M=10**9+7
gets
hw=0;t=gets.split.map{|s|[hw<hw=h=s.to_i,h]}
hw=0;a=gets.split.reverse.map{|s|[hw<hw=h=s.to_i,h]}.reverse
p t.zip(a).reduce(1){|p,((f1,h1),(f2,h2))|
  break 0 if f1&&f2&&h1!=h2 || f1&&!f2&&h1>h2 || !f1&&f2&&h1<h2
  !f1&&!f2 ? p*[h1,h2].min%M : p
}


Measured memory_bytes: 31732
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int r,g,b,n,cnt;
main(){
    cin>>r>>g>>b>>n;
    for(int i=0;i*r<=n;i++){
        for(int j=0;i*r+j*g<=n;j++){
                if((n-i*r-j*g)%b==0)cnt++;
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
var
  n,i,x,min,max:longint;
begin
  readln(n);
  max:=-maxlongint;min:=maxlongint;
  for i:=1 to n do begin read(x);if x>max then max:=x;if x<min then min:=x;end;
  writeln(max-min);
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,l;	cin >> n >> l;
  int sum=0;
  int eat=400;
  for(int i=1;i<=n;i++){
    sum+=l+i-1;
    if(abs(l+i-1)<abs(eat))	eat=l+i-1;
  }
  cout << sum-eat;
}

Measured memory_bytes: 3616
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ITP1_6B
{
    class Program
    {
        static void Main(string[] args)
        {
            var cardCount = int.Parse(Console.ReadLine());

            var cards = new int[4];

            for (var i = 0; i < cardCount; ++i)
            {
                var words = Console.ReadLine().Split(' ');

                var cardType = -1;
                switch (words[0])
                {
                    case "S": cardType = 0; break;
                    case "H": cardType = 1; break;
                    case "C": cardType = 2; break;
                    case "D": cardType = 3; break;
                }
                if (cardType < 0)
                {
                    continue;
                }

                cards[cardType] |= 1 << (int.Parse(words[1]) - 1);
            }

            for (var i = 0; i < cards.Length; ++i) 
            {
                var cardType = "";
                switch (i) {
                    case 0: cardType = "S"; break;
                    case 1: cardType = "H"; break;
                    case 2: cardType = "C"; break;
                    case 3: cardType = "D"; break;
                }

                var cardsOfKind = cards[i];
                for (var h = 0; h < 13; ++h)
                {
                    var hasAnyCards = cardsOfKind != 0;
                    if (hasAnyCards == false || (cardsOfKind & 0x01) == 0)
                    {
                        Console.WriteLine("{0} {1}", cardType, h + 1);
                    }
                    if (hasAnyCards) 
                    {
                        cardsOfKind >>= 1;
                    }
                }

            }


        }
    }
}

Measured memory_bytes: 5732
#include<bits/stdc++.h>
using namespace std;
typedef       long long int      ll;
#define       READ               freopen("in.txt", "r", stdin);
#define       WRITE              freopen("out.txt", "w", stdout);
#define       optimize           ios::sync_with_stdio(0);cin.tie(0);
#define       RESET(a, b)        memset(a, b, sizeof(a))
#define       gcd(a, b)          __gcd(a, b)
#define       MX                 300005
#define       MOD               1000000007
#define       inf               (int)(1e18)
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p & 1LL) r = modMul(r, b); b = modMul(b, b); p >>= 1LL; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
inline ll mod(ll a, ll m){ if(a<0) return ((a%m)+m)%m; else if(a<m) return a; else return (a%m); }
/*bool cmp(ll x,ll y)
{
   return x>y;
}*/
bool cmp(pair<int,int>a, pair<int,int>b)
{
   if(a.first==b.first)
      return a.second<b.second;
   else
      return a.first<b.first;
}
int main(void)
{
   optimize
   ll t,n,m,k,x,y,a[200001];
   vector<ll> v,v1,v2;
   vector< pair<ll,ll> > p,p1,p2;
   set<ll> st;
   map<ll,ll> mp;
   priority_queue<ll> pq;
   priority_queue< ll,vector<ll>,greater<ll> > lpq;
   priority_queue< pair<ll,ll> > phpq;
   priority_queue< pair<ll,ll>,vector< pair<ll,ll> >,greater< pair<ll,ll> > > plpq;
   string s;
   ll b[101];
   ll flag=0,cnt=0;
      cin>>n;
      for(ll i=0;i<n;i++)
      {
         cin>>a[i]>>b[i];
         if(a[i]==b[i])
            cnt++;
         else
         {
            if(cnt>=3)
               flag=1;
            cnt=0;
         }
      }
      if(cnt>=3)
         flag=1;
      if(flag)
         cout<<"Yes";
      else
         cout<<"No";
   return 0;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,f[200009],g[200009],fen[200009],pas;
void update(long long q){
	while(q<=a){
		if(fen[q]<d) fen[q]=d;
		q=q+(q&(-q));
	}
}
void read(long long q){
	while(q>=1){
		if(d<fen[q]) d=fen[q];
		q=q-(q&(-q));
	}
}
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>a;
	for(b=1; b<=a; b++) cin>>f[b];
	for(b=1; b<=a; b++) cin>>g[b];
	for(b=1; b<=a; b++){
		if(f[b]==1){
			if(pas<g[b]) pas=g[b];
			d=g[b];
		}else{
			d=0;
			read(f[b]);
      d+=g[b];
			if(pas<d) pas=d;
		}
		update(f[b]);
	}
	cout<<pas;
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
 
using namespace std;
 
#define DEBUG 0
#define lli long long int
#define REP(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007

#define B 0
#define L 1

lli data[2][200010];

int main(){
	lli n,k;
	string str;

	cin>>n;
	cin>>str;

	REP(i,2)REP(j,200010)data[i][j]=0;

	for(lli i=0;i<str.size();i++){
		if(i ==0){
			if(str.at(i)=='#')data[B][i]=1;
			else data[L][i]=1;
		}
		else{
			if(str.at(i)=='#'){
				data[B][i] = data[B][i-1]+1;
				data[L][i] = data[L][i-1];
			}
			else{
				data[B][i] = data[B][i-1];
				data[L][i] = data[L][i-1]+1;
			}
		}
	}
	/*すべてBLACKのとき*/
	lli ans = data[L][n-1];

	REP(i,str.size()){
		if(DEBUG)cout<<"i="<<i<<"B="<<data[B][i]<<" L="<<data[L][i]<<endl;
	}
	if(DEBUG)cout<<"start="<<ans<<endl;

	for(lli i=0;i<n;i++){
		lli leftB = data[B][i];
		lli leftL = data[L][i];

		lli rightB = data[B][n-1] - leftB;
		lli rightL = data[L][n-1] - leftL;

		ans = min(ans,leftB+rightL);
		if(DEBUG)cout<<"i="<<i<<"leftB="<<leftB<<"rightL="<<rightL<<endl;
	}

	cout<<ans<<endl;



	return 0;
}

Measured memory_bytes: 3716
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int k, x;
  cin >> k >> x;
  cout << (x <= 500 * k ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

const int MAX = 1000010;
//const int MOD = 1000000007;

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

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

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

int main(){
  int S; cin >> S;
  ll ans = 0;
  COMinit();
  rep(i, S / 3 + 1){
    if(i == 0) continue;
    int now = S - 3 * i;
    ans = (ans + COM(now + i - 1,i - 1)) % MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 27036
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>

using namespace std;

void Cockie(int &a, int &b, int k) {
   
   if (k%2 == 0) {
      b = b + a/2;
      a = a/2;
   } else {
      a = a + b/2;
      b = b/2;
   }
}

int main() {
   
   int A, B, K;
   cin >> A >> B >> K;

   for (int i = 0; i < K; i++) {
      // cout << A << " " << B << " " << i << endl;
      Cockie(A, B, i);
   }
   cout << A << " " << B << endl;
   return 0;
}


Measured memory_bytes: 256
N, M, V, P = map(int, input().split())
A = sorted(map(int, input().split()), reverse=True)


def is_possible(idx):
    if idx < P:
        return True
    if A[P - 1] <= A[idx]:
        return True
    if A[idx] + M < A[P - 1]:
        return False
    t = P * M
    for i in range(P - 1, idx):
        t += A[idx] + M - A[i]
    for i in range(idx + 1, N):
        t += M
    if t < M * V:
        return False
    return True


left, right = 0, N
while left + 1 < right:
    middle = (left + right) // 2
    if is_possible(middle):
        left = middle
    else:
        right = middle
print(right)

Measured memory_bytes: 62576
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        String input = scan.nextLine();

		if ((input.charAt(2)==input.charAt(3)) &&
			(input.charAt(4)==input.charAt(5))) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	    scan.close();	

    }
}

Measured memory_bytes: 22100
#include <stdio.h>

int main(void){
  int all_mt, hotel_num = 0, max_mt = 0;
  scanf("%d\n", &all_mt);
  int mt_num[all_mt];
  mt_num[0] = 0;
  for(int i=1; i <= all_mt; i++){
    scanf("%d ", &mt_num[i]);
    if(max_mt <= mt_num[i]){
      max_mt = mt_num[i];
    }
    if(mt_num[i-1] <= mt_num[i] && mt_num[1] <= mt_num[i] && max_mt <= mt_num[i]){
      hotel_num++;
    }
  }
  printf("%d\n", hotel_num);
  return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <atcoder/all>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;
using namespace atcoder;

int main(){
    int n,d;
    cin >> n >> d;
    two_sat ts(n);
    vector<int> x(n),y(n);
    rep(i,n){
        cin >> x[i] >> y[i];
    }
    rep(i,n){
        for(int j=i+1;j<n;j++){
            if(abs(x[i]-x[j])<d){
                ts.add_clause(i,false,j,false);
            }
            if(abs(y[i]-y[j])<d){
                ts.add_clause(i,true,j,true);
            }
            if(abs(x[i]-y[j])<d){
                ts.add_clause(i,false,j,true);
            }
            if(abs(y[i]-x[j])<d){
                ts.add_clause(i,true,j,false);
            }
        }
    }
    if(!ts.satisfiable()){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    auto ans=ts.answer();
    rep(i,n){
        if(ans[i]) cout << x[i] << endl;
        else cout << y[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3760
n = int(input())
home = [[0 for i in range(20)] for j in range(15)]  #横最大20→間の#,縦最大3階*4棟+3行の空行
for i in range(n) :
  b, f, r, v = map(int, input().split())
  h = (b - 1) * 4 + f - 1
  w = r * 2 - 1
  s = v
  home[h][w] += s
for y in range(15) :
  for x in range(20) :
    if(y % 4 == 3) :
      home[y][x] = "#"
    elif(x % 2 == 0) :
      home[y][x] = " "
    print(home[y][x], end = "")
  print() 


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

int main(){
  long long int n,k;
  cin >> n >> k;
  vector<int> a(n);
  for(int i=0;i<n;i++)
    cin >> a.at(i);
  
  vector<int> b(0);
  vector<int> kanri(n,-1);
  int y=0;//現在地-1
  
  while(kanri.at(y)==-1){
    kanri.at(y)=b.size();
    b.push_back(y+1);
    y=a.at(y)-1;
  }
  y=kanri.at(y);//yは例外の数
  
  if(k<=y) cout << b.at(k) << endl;
  else cout << b.at((k-y)%(b.size()-y)+y) << endl;
}

Measured memory_bytes: 5808
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;
import java.util.Collections;

public class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    List<Integer> a = new ArrayList<Integer>();
    for (int i = 0; i < n; i++) {
      a.add(s.nextInt());
    }
    Collections.reverse(a);
    for (int i = 0; i < a.size(); i++) {
      System.out.print(a.get(i));
      if (i != a.size() - 1)
        System.out.print(" ");
    }
    System.out.println();
    s.close();
  }
}



Measured memory_bytes: 26284
import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;
import core.bitop, std.functional;

int solve(immutable int n, immutable int s, immutable size_t b=(1<<10)-1)
{
    if(n<=0) return s==0?1:0;
    if(s<0) return 0;
    int c=0;
    size_t a=b;
    while(a)
    {
        auto m = bsf(a);
        c+=memoize!solve(n-1,s-n*m,b&~(1<<m));
        a&=a-1;
    }
    return c;
}

void main()
{
    foreach(s;stdin.byLine())
    {
        auto m=s.split().map!(to!int);
        writeln(solve(m[0],m[1]));
    }
}

Measured memory_bytes: 48508
def dp():
    n, W = map(int, input().split())
    wv = (map(int, input().split()) for _ in range(n))
    dp = [0] * (W+1)

    for w, v in wv:
        for j in range(W, w-1, -1):
            DP = dp[j-w] + v
            if dp[j] < DP:
                dp[j] = DP
    return max(dp)
print(dp())


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

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

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#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,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
const LL INF = 1e15;

LL dp[1<<15][101];

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

  int N, M;
  while(cin >> N >> M,N){
	VL xs(N), ys(M);
	REP(i,N) cin >> xs[i];
	REP(i,M) cin >> ys[i];
	SORT(xs);
	SORT(ys);

	fill((LL*)dp, (LL*)dp+(1<<15)*101, INF);
	dp[0][0] = 0;
	
	REP(i,M){
	  REP(b,1<<N){
		REP(j,N) if(b>>j&1) mini(dp[b][i], dp[b^(1<<j)][i]);

		LL S = 0;
		REP(k,N) if(b>>k&1) S += xs[k];
		mini(dp[b][i+1], dp[b][i] + abs(ys[i] - S));
	  }
	}

	LL ans = INF;
	REP(b,1<<N) mini(ans, dp[b][M]);
	cout << ans << endl;
  }

  return 0;
}

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

int main(){
    int n,m;
    while(cin>>n>>m,n|m){
        bool found=false;
        bool *T = new bool[101];
        bool *H = new bool[101];
        rep(i,101)T[i]=H[i]=false;
        int sumT=0,sumH=0,tmp;
        rep(i,n){
            cin>>tmp;
            T[tmp]=true;
            sumT+=tmp;
        }
        rep(i,m){
            cin>>tmp;
            H[tmp]=true;
            sumH+=tmp;
        }
        int d=sumT-sumH;
        if(d%2){
            cout<<-1<<endl;
            continue;
        }
        d/=2;

        for(int i=max(d,0);i<=100;i++){
            if(T[i]&&H[i-d]){
                cout<<i<<" "<<i-d<<endl;
                found=true;
                break;
            }
        }
        if(!found)cout<<-1<<endl;
    }
    return 0;
}

Measured memory_bytes: 1192
#include<stdio.h>

int main(void){
  int i;
  int num[5];
  int swp;
  int swpCount;

  for(i=0;i<5;i++){
    scanf("%d",&num[i]);
  }
  for(;;){
    swpCount=0;
    for(i=0;i<4;i++){
      if(num[i]<num[i+1]){
        swpCount++;
        swp=num[i];
        num[i]=num[i+1];
        num[i+1]=swp;
      }
    }
    if(swpCount==0) break;
  }
  for(i=0;i<5;i++){
    printf("%d",num[i]);
    if(i<4) printf(" ");
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<utility>
#include<tuple>
#include<set>
#include<list>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FUNCTION__ << endl;
#define int long long

const long long MAXN = 1e6;
const long long MOD = 1e9+7;
const long long INF = __LONG_LONG_MAX__ / 2;

using namespace std;

enum class Color { None, White, Black };

struct Point {
  Color color = Color::None;
  vector<int> next;
};

vector<Point> points;



int N;
vector<int> shortest_path;
bool visited[MAXN];
// find the path from 1 to N
bool find(int position){
  visited[position] = true;
//  cout << "pos:" << position << endl;
  for(auto next : points[position-1].next){
    if (next == N){
      shortest_path.push_back(N);
      shortest_path.push_back(position);
      return true;
    } else if (!visited[next]){
      if (find(next)){
        shortest_path.push_back(position);
        return true;  
      }
    }
  }
  return false;
}

int find_graph_size(int position, int prohibited){
  visited[position] = true;
  int gsize = 1;
 // cout << "pos:" << position << endl;
  for(auto next : points[position-1].next){
    if (next == prohibited){
      continue;
    } else if (!visited[next]){
      gsize += find_graph_size(next, prohibited);
    }
  }
  return gsize;
}

signed main(){
    cin >> N;

    for (int i = 0; i < N; i++){
      points.push_back(Point());
      visited[i+1] = false;
    }
    points[0].color = Color::Black;
    points[N-1].color = Color::White;

    for (int i = 0; i < N-1; i++){
      int a,b;
      cin >> a >> b;
      points[a-1].next.push_back(b);
      points[b-1].next.push_back(a);
    }
    // find the path from 1 to N
    find(1);
   // cout << "hoge"<< endl;
  //  for (auto sp : shortest_path)
   // {
    //  cout << sp << " "<< endl;
   // }

    int black_endpoint = shortest_path[shortest_path.size() - (shortest_path.size() + 1)/2];
    int white_endpoint = shortest_path[shortest_path.size() - (shortest_path.size() + 1)/2 - 1];

  //  cout << black_endpoint << " " << white_endpoint<< endl;

// find_graph_size
    for (int i = 0; i < N; i++) visited[i+1] = false;
    int white_graph_size = find_graph_size(N, black_endpoint);


    for (int i = 0; i < N; i++) visited[i+1] = false;
    int black_graph_size = find_graph_size(1, white_endpoint);

//    cout << white_graph_size << "llll" << black_graph_size<<endl;

    if (black_graph_size > white_graph_size){
      cout << "Fennec" << endl;
    } else {
      cout << "Snuke" << endl;
    }
    return 0;
}


Measured memory_bytes: 13676
a,b,c,x,y=map(int,input().split())
yasui=False
yasuia=False
yasuib=False
ans=0
sa=max([x,y])-abs(x-y)
if a+b>2*c:
  yasui=True
if a>2*c:
  yasuia=True
if b>2*c:
  yasuib=True
if yasui:
  ans+=sa*2*c
else:
  ans+=sa*(a+b)
x-=sa
y-=sa

if x>0:
  if yasuia:
    ans+=2*c*x
  else:
    ans+=a*x
if y>0:
  if yasuib:
    ans+=2*c*y
  else:
    ans+=b*y
print(ans)

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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    int N,K;
    cin >> N >> K;

    put_double(K * pow((K-1),N-1));
}


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

using ll = long long;

int main() {
    int N, K, D;
    cin >> N >> K;
    bool b[10];
    rep(i, 10) b[i] = false;
    rep(i, K) {
        cin >> D;
        b[D] = true;
    }
    for (int i = N; i < 100000; i++) {
        string s = to_string(i);
        bool f = false;
        rep(i, s.size()) {
            if (b[s[i] - '0']) {
                f = true;
                break;
            }
        }
        if (!f) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
def gcd(a, b):  # greatest common divisor
    if (a < b):
        a,b = b,a
    while(b>0):
        a,b = b ,a%b
    return a


def lcm(a, b):  #  least common multiple
    return int(a*b/gcd(a,b))


A, B, C, D = [int(n) for n in input().split()]
intnum = B-A  + 1
CmulA = A // C
CmulB = B // C
Cmulnum = CmulB - CmulA
if A % C == 0:
    Cmulnum += 1
DmulA = A // D
DmulB = B // D
Dmulnum = DmulB - DmulA
if A % D == 0:
    Dmulnum += 1
CD = lcm(C,D)
CDmulA = A // CD
CDmulB = B // CD
CDmulnum = CDmulB - CDmulA
if A % CD == 0:
    CDmulnum += 1
print(intnum - (Cmulnum + Dmulnum) + CDmulnum)


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

const double PI = acos(-1);
const double EPS = 1e-15;
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;
const ll MOD1 = 998244353;
//typedef pair<int,int> P;

#define REP(i,n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

ll dist;
ll dd;
int node;
bool used[100010];
vector<int> G[100010];

void dfs(int n, ll d) {
  used[n] = 1;
  REP(i,G[n].size()) {
    if (used[G[n][i]]) continue;
    dfs(G[n][i], d + 1);
  }
  dd += d;
}

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

  ll n;
  cin >> n;

  //現在のノード数に対応する次のノードまでのsumの変化値
  ll diff[n/2+1] = {};
  for (int i = 1; i <= n / 2; i++) {
    diff[i] = n - i * 2;
  }

  //sumとノード番号の対応
  map<ll,ll> mp;
  //sumを入れるところ
  vector<ll> v;
  for (ll i = 0; i < n; i++) {
    ll a;
    cin >> a;
    mp[a] = i+1;
    v.pb(a);
  }
  dist = v[0];
  node = 1;
  sort(v.rbegin(),v.rend());

  //答え
  vector<pair<ll,ll>> ans;

  //最後尾のノードをsetに入れる
  //つながってたら消す
  set<ll> st;

  //予測するため，つぎのノードのsumをnextに入れる
  set<ll> next;
  //前のノードを記録する
  vector<ll> pre[100010];
  //次への変化値を知るため，ノード数をlvに記録する
  map<ll,ll> lv;

  /*****手順*******/
  //現在のノードがnext候補にあるとき
  ////グラフを構築する
  ////前のノードをstから消す
  ////lvを数える

  ////lv++
  ////現在のノードをnextから消す
  ////現在のノードをstに入れる
  ////次のノードをnextに入れる

  //最後にnextに要素があるときは-1
  //nextが一つだけの時はok

  for (ll i = 0; i < n; i++) {
    if (next.count(v[i])) {
      for (int j = 0; j < pre[mp[v[i]]].size(); j++) {
        ans.pb({mp[v[i]], mp[pre[mp[v[i]]][j]]});
        st.erase(pre[mp[v[i]]][j]);
        lv[v[i]] += lv[pre[mp[v[i]]][j]];
      }
    }
    lv[v[i]]++;
    next.erase(v[i]);
    st.insert(v[i]);
    if (!mp.count(v[i] - diff[lv[v[i]]]) && i != n - 1) {
      cout << -1 << endl;
      return 0;
    }
    if (i != n - 1) {
      pre[mp[v[i] - diff[lv[v[i]]]]].pb(v[i]);
      next.insert(v[i] - diff[lv[v[i]]]);
    }
  }

  if (next.size()) {
    cout << -1 << endl;
    return 0;
  }

  REP(i,sz(ans)) {
    G[ans[i].fi].pb(ans[i].se);
    G[ans[i].se].pb(ans[i].fi);
  }


  dfs(1,0);

  if (dist != dd) {
    cout << -1 << endl;
    return 0;
  }

  REP(i,sz(ans)) {
    cout << ans[i].fi << " " << ans[i].se << endl;
  }
  return 0;
}


Measured memory_bytes: 32240
N, K, Q = map(int, input().split())
A = [K-Q] * N
for _ in range(Q):
    i = int(input())
    A[i-1] += 1
cnt = 0
for i in range(N):
    if A[i] > 0:
        ans = 'Yes'
    else:
        ans = 'No'
    print(ans)

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

int main() {
    int x, y;
    cin >> x >> y;
    int legs;
    rep(i,x+1) {
        legs = 2 * i + 4 * (x - i);
        if(legs == y) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3672
n, x = map(int, input().split())
l = list(map(int, input().split()))

count = 0
d = [0]
for i in range(1, n+1):
    d.append(d[i - 1] + l[i - 1])

for i in range(len(d)):
    if d[i] <= x:
        count += 1

print(count)


Measured memory_bytes: 3060
let () =
    let m = 1_000_000_000 + 7 in
    let ( +@ ) a b = (a + b) mod m in
    let ( *@ ) a b = ((a mod m) * (b mod m)) mod m in
    let pow4 b =
        let rec loop a b acc =
            if b = 0 then acc else
                let acc = if b land 1 = 1 then acc *@ a else acc in
                let a = a *@ a in
                loop a (b lsr 1) acc
        in
        loop 4 b 1
    in

    let main () =
        let n = int_of_string (read_line ()) in
        let c = Array.init n (fun _ -> Scanf.scanf " %d" (fun c -> c)) in
        Array.sort compare c;
        let q = pow4 (n - 1) in
        let rec loop i acc =
            if i < 0 then acc else loop (i - 1) (acc +@ q *@ c.(i) *@ (n + 1 - i))
        in
        loop (n - 1) 0 |> Printf.printf "%d\n"
    in
    main ()

Measured memory_bytes: 6272
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    string T;
    cin >> T;
    int n = T.length();

    for (auto& c : T) {
        if (c == '?') {
            c = 'D';
        }
    }

    cout << T << '\n';

    return 0;
}

Measured memory_bytes: 3720
#include<iostream>
using namespace std;
int main(void){
    int c[3][3];
    for(int i(0);i<3;i++){
        for(int j(0);j<3;j++){
            cin>>c[i][j];
        }
    }
    bool yes(true);
    for(int i(0);i<2;i++){
        int diff0 = c[0][i] -c[0][i+1];
        int diff1 = c[1][i] -c[1][i+1];
        int diff2 = c[2][i] -c[2][i+1];
        if(diff0 == diff1 && diff1 == diff2)continue;
        else yes = false;
    }
    for(int i(0);i<2;i++){
        int diff0 = c[i][0] -c[i+1][0];
        int diff1 = c[i][1] -c[i+1][1];
        int diff2 = c[i][2] -c[i+1][2];
        if(diff0 == diff1 && diff1 == diff2)continue;
        else yes = false;
    }
    if(yes)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int h, w, Ch, Cw, Dh, Dw;
	cin >> h >> w >> Ch >> Cw >> Dh >> Dw;
	Ch--; Cw--;
	Dh--; Dw--;
	
	vector<string> s(h);
	for(int i = 0; i < h; ++i) {
		cin >> s[i];
	}
	
	vector<int> dx = {0, 1, 0, -1};
	vector<int> dy = {1, 0, -1, 0};
	
	constexpr ll INF = 1e9 + 10;
	vector< vector<ll> > dist(h, vector<ll>(w, INF));
	deque< pair<int, int> > q;

	dist[Ch][Cw] = 0;
	q.push_back( {Ch, Cw} );
	
	vector< pair<int, int> > restart;
	
	while( !q.empty() ) {
		int nowx = q.front().first;
		int nowy = q.front().second;
		q.pop_front();
		
		for(int k = 0; k < 4; ++k) {
			int nx = nowx + dx[k];
			int ny = nowy + dy[k];
					
			if( nx < 0 || nx >= h || ny < 0 || ny >= w ) continue;
			if( s[nx][ny] == '#' ) continue;
					
			if( dist[nx][ny] > dist[nowx][nowy] ) {
				dist[nx][ny] = dist[nowx][nowy];
				q.push_front( {nx, ny} );
			}
		}

		for(int magicx = -2; magicx <= 2; ++magicx) {
			for(int magicy = -2; magicy <= 2; ++magicy) {
				int mx = nowx + magicx;
				int my = nowy + magicy;
				
				if( mx < 0 || mx >= h || my < 0 || my >= w ) continue;
				if( s[mx][my] == '#' ) continue;
				
				if( dist[mx][my] > dist[nowx][nowy] + 1LL ) {
					dist[mx][my] = dist[nowx][nowy] + 1LL;
					q.push_back( {mx, my} );
				}
			}
		}
	}
	
	if( dist[Dh][Dw] != INF ) {
		cout << dist[Dh][Dw] << endl;
	} else {
		cout << -1 << endl;
	}
	
	return 0;
}


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

using namespace std;

const int N = (1<<19) , mod = 1e9 +7 , mx = 1e6 +5;

int n , m ;
int mat[55][55] , res[51][51];
long long dp[55][1<<21];
int rx[55] , ry[55] , ex[55] , ey[55];

int up[55][22] , hei[55] , vis[55] , low[55] , hi[55] , t;
vector<int> adj[55];

bool is_a(int a, int b)
{
    return low[b]>=low[a]&&hi[b]<=hi[a];
}
int lca(int a, int b)
{
    if(is_a(a,b))return a;
    if(is_a(b,a))return b;
    for(int i=21;i>=0;i--)
        if(!is_a(up[a][i],b) )
            a = up[a][i];
    return up[a][0];
}
int dfs(int x,int l,int h=0)
{
    vis[x]=1;
    low[x]=t++;
    up[x][0]=l;
    hei[x]=h;
    for(int i=1;i<22;i++)
        up[x][i] = up[ up[x][i-1] ][i-1];
    for(auto u : adj[x])
        if(u!=x&&!vis[u])
            dfs(u,x,h+1);
    hi[x]=t++;
}

int lift(int x ,int y)
{
    int ret=0;
    if(y==1)return hei[x];
    for(int i=21;i>=0;i--)
        if(is_a(y,up[x][i]))
        {
            x = up[x][i];
            ret+=(1<<i);
        }
    return ret;
}

int dist(int a , int b)
{
    int lc = lca(a,b);
    return lift(a,lc)+lift(b,lc);
}

int get_mask(int ix)
{
    int ret = 0;
    int iex = ex[ix];
    int iey = ey[ix];
    for(int i = 0;i<m;i++)
    {
        int irx = rx[i];
        int iry = ry[i];
        int dst = dist(irx , iry) ;
        if( dist(irx , iex) + dist(iey, iry) +  1 == dst || dist(irx,iey) + dist(iex,iry) + 1 ==dst )
            ret|=(1<<i);
    }
    return ret;
}

int main()
{
    int n;
    cin>>n ;
    for(int i = 1 ; i<= n-1 ; i++)
    {
        int a , b ;
        cin>>a >> b ;
        mat[a][b] = mat[b][a] = 1;
        ex[i] = a;
        adj[a].push_back(b);
        adj[b].push_back(a);
        ey[i] = b;
    }
    dfs(1,1);
    cin>> m ;
    for(int i = 0 ; i< m ; i++)
    {
        cin>>rx[i] >> ry[i] ;
        res[rx[i] ][ry[i]] = res[ry[i]][rx[i]] = 1;
    }
    dp[0][0] = 1LL;
    for(int i = 1;i<n;i++)
    {
        int l = ex[i] , r = ey[i];
        int sub_mask = get_mask(i);
        for(int j = 0; j < (1<<m) ; j++ )
        {
            int akid = (j|sub_mask);
            dp[i][j] +=dp[i-1][j];
            dp[i][akid]+=dp[i-1][j];
        }
    }
    cout<<dp[n-1][(1<<m)-1];
    return 0;
}



Measured memory_bytes: 502016