akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
//ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 1e7;
vector<int> pr;
int z[N+1];
int d(int a){
  int p=-1, c=1, r=1;
  while(a>1){
    if(z[a] != p){
      r *= c;
      c = 1;
    }
    a /= p = z[a];
    c++;
  }
  return r*c;
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  for (int i=2; i<=N; ++i) {
    if(!z[i]) pr.push_back(z[i]=i);
    for(int j=0, k, p=pr.size(); j<p && (k=pr[j])<=z[i] && i*k<=N; ++j) z[i*k]=k;
  }
  int n;
  cin >> n;
  ll ans = 0;
  FOR(i, 1, n+1) ans += ll(i) * d(i);
  cout << ans << endl;
}


Measured memory_bytes: 46404
#include <bits/stdc++.h>
#define REP(i, n) for(ll 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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    ll N,Q,sum=0,a=0,A[100005],B[100005],C[100005];
    cin  >> N;
    memset(A, 0, sizeof(100005));
    REP(i,N){
        cin >> a;
        A[a]++;
        sum +=a;
    }
    cin >> Q;
    REP(i,Q){
        cin >> B[i] >> C[i];
    }
    REP(i,Q){
        if(A[B[i]] > 0){
            sum += (C[i]-B[i])*A[B[i]];
            A[C[i]] += A[B[i]];
            A[B[i]] = 0;
        }
        cout<<sum<<endl;
    }

    return 0;  
}


Measured memory_bytes: 5876
def max(a, b)
  a > b ? a : b
end

L = '>' # >
R = '<' # <

arr = gets.chomp.split('')

targets = []

last_dir = R
count = -1
arr.each do |dir|
  if last_dir == dir
    count += 1
    next
  end

  targets << count + 1
  if dir == L
    targets << nil
  end
  last_dir = dir
  count = 0
end

if last_dir == L
  targets << count + 1
else
  targets << count + 2
end


counter = 0
targets.each_with_index do |num, index|
  if num.nil?
    add = max(targets[index - 1], targets[index + 1])
  else
    add = (num * (num - 1)) / 2
  end
  counter += add
end

puts counter

Measured memory_bytes: 30732
#include <iostream>
#include <stdio.h>
#include <string>

#define MAX_N 100'000

using namespace std;

bool A[MAX_N]{};
int B[MAX_N]{};

int main() {
  int N, M;
  cin >> N >> M;
  int cnt = 0;
  for (int i = 0; i < M; ++i) {
    int p;
    string S;
    cin >> p >> S;
    if (!A[p - 1]) {
      if (S == "AC") {
        ++cnt;
        A[p - 1] = true;
      } else {
        ++B[p - 1];
      }
    }
  }
  int _cnt = 0;
  for (int i = 0; i < N; ++i) {
    _cnt += A[i] * B[i];
  }
  printf("%d %d\n", cnt, _cnt);
}

Measured memory_bytes: 3720
import java.util.*;
public class Main {
    public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
    	int n=sc.nextInt();
    	int i,j,reg,k;
    	int[] ary = new int[n];
    	for(i=0;i<n;i++){
    		ary[i]=sc.nextInt();
    	}
    	for(k=0;k<n;k++){
	        System.out.print(ary[k]);
	        if(k!=n-1){
	        	 System.out.print(" ");
	        }else{
	        	System.out.println();
	        }
    	}
    	for(i=0;i<n;i++){
    		j=i;
    		if(i!=0){
    		    while(j!=0&&ary[j]<ary[j-1]){
    			    reg=ary[j-1];
    			    ary[j-1]=ary[j];
    			    ary[j]=reg;
    			        j--;
    		   }
			    for(k=0;k<n;k++){
			        System.out.print(ary[k]);
			        if(k!=n-1){
			        	 System.out.print(" ");
			        }else{
			        	System.out.println();
			        }
			    }
    		}
    	}
    }
}


Measured memory_bytes: 34624
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
public class Main {
	public static void main(final String[] args){
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();

    int sum = n*(n-1)/2 + m*(m-1)/2;
    System.out.println(sum);




    
    
    
	}
}

Measured memory_bytes: 23764
using System;
using System.Text;
using System.Linq;

class Program
{
    static void Main(string[] args) {
        String ret;
        ret = process(new System.IO.StreamReader(Console.OpenStandardInput()));
        //ret = process("3\n1 0 0");

        Console.WriteLine(ret);
        //Console.ReadLine();
    }

    static string process(System.IO.TextReader input) {
        int n     = int.Parse(input.ReadLine());
        int[] ary = ToIntArray(input.ReadLine(), n);

        int[] ans = new int[n];

        for(int i=n; i>=1;  i--) {
            int c = ary[idx(i)];
            for(int k=2; ; k++) {
                if (idx(i * k) > idx(n)) {
                    break;
                } else {
                    c += ans[idx(i * k)];
                }
            }
            ans[idx(i)] = c % 2;
        }

        int count = ans.Count(x => x == 1);
        
        StringBuilder ret = new StringBuilder();
        ret.AppendLine(count.ToString());
        for (int i=0; i<n; i++) {
            if (ans[i] == 1) {
                ret.Append(i+1);
                ret.Append(' ');
            }
        }

        return ret.ToString();
    }
    static int idx(int n) {
        return n - 1;
    }

    static string process(string input) {
        return process(new System.IO.StringReader(input));
    }

    static int[] ToIntArray(string strs, int n) {
        int[] ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++) ret[i] = int.Parse(spl[i]);
        return ret;
    }
}

Measured memory_bytes: 29272
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
//#include <unordered_map>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a-1); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
ll mod=1000000007;
//ll mod=67280421310721;
//ll mod=998244353;
ll INF=1e18;
ll po(ll a,ll b)
{
	ll re=1;
	while(b)
	{
		if(b%2==1)
		{
			re=(re*a);
			re%=mod;
		}
		a=(a*a);
		a%=mod;
		b>>=1;
	}
	return re;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
//	cin>>test;
	while(test--)
	{
		int n;
		cin>>n;
		bool f=1;
		int a;
		FOR(i,0,n)
		{
			cin>>a;
			if((a%2)==0)
			{
				if((a%3)!=0 && (a%5)!=0)
				f=0;
			}
		}
		if(f)
		cout<<"APPROVED";
		else
		cout<<"DENIED";
	}
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include<iostream>

using namespace std;

int main(){
	
	while(1){
		string s;
		cin>>s;
		if(cin.eof())break;
		int a = 0,b = 0;
		
		for(int i=0;i<s.size()-2;i++){
			if(s[i]=='J' && s[i+1]=='O' && s[i+2]=='I') a++;
			if(s[i]=='I' && s[i+1]=='O' && s[i+2]=='I') b++;
		}
		
		printf("%d\n%d\n",a,b);
	}
}

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

int main (){
  int N;
  int j = 0;
  
  cin >> N ;
  
  rep (i, N){
    int x, y;
    
    cin >> x >> y ;
    j += (y - x + 1);
  }
  cout << j << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define ll          long long int
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         100000000000000000
#define MAXN        1000005
#define mod         1000000007  
#define pi          3.1415926535897932384626433
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,j,sum=0,x;
    cin>>n;
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            if((i*j)>n){
                break;
            }
            x=n-i*j;
            if(x>0){
                sum++;
            }
        }
    }
    cout<<sum;
}

Measured memory_bytes: 3648
N = int(input())
S = str(input())

Wsum = [0]
for i in range(N):
    if S[i] == 'W':
        Wsum.append(Wsum[i] + 1)
    else:
        Wsum.append(Wsum[i])
del Wsum[0]

S = S[::-1]
Esum = [0]
for i in range(N):
    if S[i] == 'E':
        Esum.append(Esum[i] + 1)
    else:
        Esum.append(Esum[i])
del Esum[0]
Esum = Esum[::-1]

Sum = []
for i in range(0,N):
    Sum.append(Wsum[i] + Esum[i]-1)

print(min(Sum))

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

int main(){
    int n;
    cin >> n;
    int ans = 0;
    for(int i=0; i<n; i++){
        string s;
        cin >> s;
        if(s == "E869120"){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3220
#include <cstdint>
#include <cstdlib>
#include <iostream>

using namespace std;

int64_t f(int64_t a) {
  if (a <= 0) return 0;
  const int64_t m = a % 4;

  switch (m) {
    case 1:
      return 1;
    case 2:
      return a + 1;
    case 3:
      return 0;
  }
  // case 0
  return a;
}

int64_t exact(int64_t a, int64_t b) {
  int64_t x = a;
  for (int64_t i = a + 1; i <= b; ++i) {
    x ^= i;
  }
  return x;
}

int main() {
  int64_t a, b;
  cin >> a >> b;
  const auto ans = f(a - 1) ^ f(b);
  cout << ans << endl;
  return 0;
}


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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using namespace std;

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

    int n; cin >> n;
    vector<int> vc;
    REPI(i, n){
        int x; cin >> x;
        vc.push_back(x);
    }
    int a = 0;
    int ans = 1;
    REPI(i, n){
        if(vc[a] == 2) i += n;
        else ans++, a = vc[a] - 1;
        //cout << ans << endl;
    }

    ans <= n ? cout << ans : cout << -1;
}


Measured memory_bytes: 892
#include<iostream>
#include<vector>
#include<math.h>
#include<algorithm>
#include<stack>
#include<queue>
using namespace std;

int main()
{
	
		int n;
		cin >> n;
		int i = 1;
		while (((360 * i) % n) != 0)
		{
		i++;
        }
		cout << (360 * i) / n << endl;
}


Measured memory_bytes: 3628
#!/usr/bin/env python3
n = int(input()) 
def make_divisors(n):
    div = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            div.append(i)
            if i != n // i:
                div.append(n//i)
    return div
ans = 0
for i in range(1, n + 1):
    if i % 2 != 0:
        div = make_divisors(i)
        if len(div) == 8:
            ans += 1
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n; ll m, v, p;
    cin >> n >> m >> v >> p;
    vector<ll> a(n);
    for(int i=0;i<n;++i) cin >> a[i];
    sort(a.rbegin(), a.rend());

    int ok = p-1, ng = n;
    while(ng-ok > 1) {
        int mid = (ok+ng) / 2;

        if(a[mid] + m < a[p-1]) {
            ng = mid;
            continue;
        }

        ll votes = m * (v - (n-mid) - (p-1));
        for(int i=p-1;i<mid;++i) {
            votes -= max(a[mid]+m - a[i], 0LL);
        }

        if(votes <= 0) {
            ok = mid;
        } else {
            ng = mid;
        }
    }

    cout << ok+1 << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
const int MOD = 1000000007;
const int INF = 1e9;
typedef long long ll;

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

    vector<int> b(m);
    for(int i=0;i<m;i++){
        cin >> b[i];
    }

    vector<vector<int>> a(n,vector<int>(m));

    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin >> a[i][j];
        }
    }

    int sum=0;
    int count = 0;

    for(int i=0;i<n;i++){
        sum = 0;
        for(int j=0;j<m;j++){
            sum += a[i][j] * b[j];
        }
        sum += c;
        if(sum>0){
            count++;
        }
    }

    cout << count << endl;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	string S; cin >> S;
	if (S.find('7') == string::npos) {
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 3652
mass = input()
mass = list(mass) #入力した文字列をリストで管理する
mass = [int(n) for n in mass]
count = 0

for i in range(0, len(mass)):
    try:
        if(mass[i] == mass[i+1]): #同じ数字が続くか判定する
            mass[i+1] = (mass[i+1] + 1) % 2 #0なら1に、1なら0に数字を入れ替える
            count += 1
    except IndexError: #すべての文字を比較したときの処理
        print(count)


Measured memory_bytes: 4652
#include <stdio.h>

int main(void) {
	int N;
	int p[1024][3];
	int i, j, k;
	int count = 0;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d%d%d", &p[i][0], &p[i][1], &p[i][2]) != 3) return 1;
		for (j = 2; j > 0; j--) {
			for (k = 0; k < j; k++) {
				if (p[i][k] > p[i][k + 1]) {
					int t = p[i][k];
					p[i][k] = p[i][k + 1];
					p[i][k + 1] = t;
				}
			}
		}
	}
	for (i = 0; i < N; i++) {
		int yes = 1;
		for (j = 0; j < i; j++) {
			if (p[i][0] == p[j][0] && p[i][1] == p[j][1] && p[i][2] == p[j][2]) {
				yes = 0;
				break;
			}
		}
		if (yes) count++;
	}
	printf("%d\n", N - count);
	return 0;
}



Measured memory_bytes: 2124
A,B = map(int,input().split())

if B%A == 0:
    print(-1)
    exit()

_k = -(-B//A)

for k in range(_k, _k+10**7):
    bn, rem = divmod(k*A, B)
    an, rem = divmod(rem, A)
    n = bn + an + rem
    if n > k:
        print(k*A)
        exit()
print(-1)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
#define mp make_pair
#define sqr(x) (x)*(x)
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int maxn=100007;
const ll inf=1<<29;
int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int main(){
    int n=read();ll sum=0;
    for(int i=1;i<=n;i++){
        if(i%3&&i%5) sum+=i;
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>

int main(){
  int w[10];
  int i;
  int wt=512;
  int n;

  for(i=0;i<10;i++){
    w[i]=wt;
    wt=wt/2;
  }

  while(scanf("%d",&n)!=EOF){
    int a[10];
    int f=0;
    for(i=0;i<10;i++){
      a[i]=0;
    }
    for(i=0;i<10;i++){
      if(n>=w[i]){
	n=n-w[i];
	a[i]=1;
      }
    }
    for(i=9;i>=0;i--){
      if(a[i]==1){
	if(f==1){
	  printf(" ");
	}
	printf("%d",w[i]);
	f=1;
      }
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<utility>
#include<algorithm>
#include<map>
#include<set>
#include<functional>

using namespace std;

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

int N, M;

int main() {
	cin >> N >> M;
	priority_queue<int, vector<int>, greater<int> > A;
	priority_queue<P> CB;

	int a;
	for (int i = 0; i < N; i++) {
		cin >> a;
		A.push(a);
	}
	int b, c;
	for (int i = 0; i < M; i++) {
		cin >> b >> c;
		CB.push(make_pair(c, b));
	}

	while (CB.size()) {
		c = CB.top().first;
		if (c < A.top()) { break; }
		b = CB.top().second;
		while (b > 0) {
			if (A.top() < c) {
				A.push(c);
				A.pop();
			}
			else { break; }
			b--;
		}
		CB.pop();
	}

	long long ans = 0;
	while (A.size()) {
		ans += A.top();
		A.pop();
	}
	cout << ans << "\n";
}

Measured memory_bytes: 1784
#include <bits/stdc++.h>
#define ll long long
#define MAX_N 51
using namespace std;

int n,m;
int a[MAX_N], b[MAX_N];
bool G[MAX_N][MAX_N];
bool visited[MAX_N];

bool dfs(int u){
    visited[u] = true;

    for(int v = 0; v < n; ++v){
        if(G[u][v] == false ) continue;
            if( visited[v] == true ) continue;
            dfs(v);
    }
}

int main(){
    cin>>n>>m;
    for(int i = 0; i< m; ++i){
        cin>>a[i]>>b[i];
        a[i]--;
        b[i]--;
        G[a[i]][b[i]] = G[b[i]][a[i]] = true;
    }
    int ans =0;

    for(int i = 0; i <m; ++i){
        for(int d=0; d<n; ++d) visited[d] = false;

        G[a[i]][b[i]] = G[b[i]][a[i]] = false;

        dfs(0);

        bool must_b = false;
        for(int j=0; j<n; ++j){
            if(visited[j] == false) must_b = true;
        }
        if(must_b) ans++;
        G[a[i]][b[i]] = G[b[i]][a[i]] = true;
    }
    cout<< ans <<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n,ans=0;
  scanf("%d",&n);
  int p[n];
  for(int i=0;i<n;i++){
    scanf("%d",&p[i]);
  }
  for(int i=0;i<n-2;i++){
    if(p[i] < p[i+1] && p[i+1] < p[i+2]){
      ans+=1;
    }else if(p[i] > p[i+1] && p[i+1] > p[i+2]){
      ans+=1;
    }
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	int n;
	cin >> n;
	if (n / 10 == 9 || n % 10 == 9)
		Yes();
	else
		No();

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <atcoder/fenwicktree>

using namespace std;

int main() {
  int N, Q, a;
  cin >> N >> Q;
  atcoder::fenwick_tree<long long> f(N);
  for (int i = 0; i != N; ++i) {
    cin >> a;
    f.add(i,a);
  }

  int t,l,r;
  while (cin >> t >> l >> r) {
    if (t) cout << f.sum(l,r) << endl;
    else f.add(l,r);
  }
}


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

int main()
{
  int n, m;
  int a, b, c;
  string s1,s2,s3;

  cin >> s1 >> s2 >> s3;

  cout << s1[0] << s2[1] << s3[2] << endl;
  return (0);
}

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

int main()
{
    int n;
    cin>>n;
    long long arr[n+5];
    for(int i=0;i<=n;i++)
    {
        cin>>arr[i];
    }
    long long hero[n+5];
    for(int i=0;i<n;i++)cin>>hero[i];
    long long sum=0;
    for(int i=0;i<n;i++)
    {
      sum+=min(arr[i],hero[i]);
      if(hero[i]>arr[i])
      {
          hero[i]-=arr[i];
          sum+=min(hero[i],arr[i+1]);
          arr[i+1]-=hero[i];
          if(arr[i+1]<0)arr[i+1]=0;
      }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <set>

using namespace std;

int main()
{
    int N, K;
    cin>>N>>K;
    vector<int> P(N);
    for (int &p: P)
        cin>>p;

    if (N==K)
    {
        cout<<1<<endl;
        return 0;
    }

    vector<int> S(N);
    for (int i=1; i<N; i++)
        if (P[i-1]<P[i])
            S[i] = 1;

    vector<int> T(N);
    T[0] = S[0];
    for (int i=1; i<N; i++)
        T[i] = T[i-1]+S[i]-(0<=i-K+1 ? S[i-K+1] : 0);

    //for (int s: T)
    //    cout<<" "<<s;
    //cout<<endl;

    bool f = T[K-1]==K-1;
    set<int> SS;
    for (int i=0; i<K; i++)
        SS.insert(P[i]);
    int ans = 1;
    for (int i=K; i<N; i++)
    {
        SS.insert(P[i]);
        auto t = SS.end();
        t--;
        if (f && T[i]==K-1 ||
            *SS.begin()==P[i-K] && *t==P[i])
        {
        }
        else
            ans++;

        if (T[i]==K-1)
            f = true;
        SS.erase(P[i-K]);
    }
    cout<<ans<<endl;
}


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



int main()
{
        ll X, Y, Z;
        cin >> X >> Y >> Z;
        ll tmp = X / (Y+Z) - 1;
        X -= (Y+Z) * tmp;
        
        cout << tmp + X / (Y+2*Z) << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
using node = array<int, 2>;

int main()
{
    int N, M;
    cin >> N >> M;
    int ai, bi, ci;
    vector<pair<int, int>> keys(M);
    for(int i=0;i<M;i++){
        cin >> ai >> bi;
        int bit = 0;
        for(int j=0;j<bi;j++){
            cin >> ci;
            bit |= 1 << (ci-1);
        }
        keys[i] = make_pair(ai, bit);
    }

    priority_queue<node, vector<node>, greater<node>> q;
    map<int, int> nodes;
    nodes[0] = 0;
    q.push(node{0, 0});
    while(!q.empty()){
        auto u = q.top(); q.pop();
        if(u[1] == (1 << N) - 1){
            cout << u[0] << endl;
            return 0;
        }
        for(auto p : keys){
            auto node_new = u[1] | p.second;
            auto weight = u[0] + p.first;
            if(nodes.count(node_new)==0
            || weight < nodes[node_new]){
                nodes[node_new] = weight;
                q.push(node{weight, node_new});
            }
        }
    }
    cout<<"-1"<<endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
  int K, N;
  cin >> K >> N;
  vector<int> A(N);
  for(int i = 0;i < N;i++){
    cin >> A.at(i);
  }
  vector<int> a(N);
  for(int j = 0;j < N - 1;j++){
      a.at(j) = A.at(j + 1) - A.at(j);
    }
  a.at(N - 1) = A.at(0) + K - A.at(N - 1);
  sort(a.begin(), a.end());
  a.pop_back();
  int S = 0;
  for(int i = 0;i < N - 1;i++){
    S += a.at(i);
  }
  cout << S << endl;
}


Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define all(x) x.begin(), x.end()
#define F first
#define S second
const ll inf = 1e18;
const ll mod = 1e9 + 7;

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

// mod. m での a の逆元 a^(-1) を計算する。
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

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



int main(){
    int n;
    cin >> n;
    vint a(n);
    ll all_xor = 0;
    rep(i,n){
        cin >> a[i];
        all_xor = all_xor^a[i];
    }
    rep(i,n){
        int ans = all_xor^a[i];
        cout << ans << " ";
    }
}



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

long long s2i(string str, int s, int e) {
	long long base = 1;
	long long ans = 0;
	for (int i = e-1; i >= s; i--) {
		ans += base*(str[i]-'0');
		base*=10;
	}
	return ans;
}

int main() {
	string str;
	cin >> str;
	int sl = str.length();
	long long ans = 0;
	vector<long long> pro;
	for (int i = 0; i < pow(2, sl-1); i++) {
		pro.clear();
		int sta = 0;
		for (int j = 0; j < sl; j++) {
			long long b = pow(2, j);
			if (i&b) {
				pro.push_back(s2i(str, sta, j+1));
				sta = j+1;
			}
		}
		pro.push_back(s2i(str, sta, sl));
		long long  tmp = 0;
		for (int j = 0; j < pro.size(); j++) {
			tmp += pro[j];
		}
		ans += tmp;
	}
	cout << ans << endl;
	return 0;
}


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

using ll = long long;
using ull = unsigned long long;
#define repi(n) for (long long i = 0; i < (n); ++i)
#define repj(n) for (long long j = 0; j < (n); ++j)
#define repk(n) for (long long k = 0; k < (n); ++k)
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(itr) for (auto&& v : (itr))
#define updatemax(t, v) (t = std::max(t, (v)))
#define updatemin(t, v) (t = std::min(t, (v)))

int main() {
  ll n, k, r = 0;
  cin >> n >> k;
  while (n > 0) {
    n /= k;
    ++r;
  }
  cout << r << endl;
}


Measured memory_bytes: 3576
#include<stdio.h>
int main(void)
{
	int p1[4],p2[4],n,m;
	int a,b;
	int i,j;
	int hit,blow;
	scanf("%d",&a);
	scanf("%d",&b);	
	while(a!=0 && b!=0){
		for(i=0;i<4;i++){
			p1[i]=a%10;
			a=a/10;
		}
		for(i=0;i<4;i++){
			p2[i]=b%10;
			b=b/10;
		}
		hit=0;
		blow=0;
		for(i=0;i<4;i++){
			if(p1[i]==p2[i]){
				hit++;
			}
		}
		for(i=0;i<4;i++){
			for(j=0;j<4;j++){
				if(p1[i]==p2[j]){
					blow++;
				}
			}
		}
		blow=blow-hit;
		printf("%d %d\n",hit,blow);

		scanf("%d",&a);
		scanf("%d",&b);
	}
	return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int N, M, Q;
int a[100005];
int used[100005];
int pro[100005];

int res[100005];

int main(void)
{
	cin >> N >> M >> Q;
	for(int i = 0; i < Q; i++) cin >> a[i];
	reverse(a, a+Q);
	
	for(int i = 1; i <= M; i++) used[i] = -1;
	for(int i = 0; i < N; i++) pro[i] = -1;
	
	int id = 0;
	for(int i = 0; i < Q; i++){
		if(used[a[i]] == -1){
			used[a[i]] = id++;
			pro[N-1]++;
		}
		else{
			int p = lower_bound(pro, pro+N, used[a[i]]) - pro;
			if(p > 0 && pro[p-1] == used[a[i]]-1){
				pro[p-1]++;
			}
		}
	}
	
	for(int i = 1; i <= M; i++){
		if(used[i] == -1) used[i] = id++;
	}
	for(int i = 1; i <= M; i++) res[used[i]] = i;
	
	vector<int> vec, ans;
	for(int i = 0; i <= pro[0]; i++) vec.push_back(res[i]);
	for(int i = 1; i <= M; i++) vec.push_back(i);
	
	for(int i = 1; i <= M; i++) used[i] = 0;
	for(int i = 0; i < vec.size(); i++){
		if(used[vec[i]] == 0){
			used[vec[i]] = 1;
			ans.push_back(vec[i]);
		}
	}
	
	for(int i = 0; i < ans.size(); i++){
		if(res[i] != ans[i]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	
	return 0;
}

Measured memory_bytes: 2936
mojiretsu = list(input())
q = int(input())
text = ""

for i in range(q):
    order = list(input().split())
    a = int(order[1])
    b = int(order[2])
    if order[0] == "print":
        for i in range(a, b+1):
            text += mojiretsu[i]
        print(text)
        text = ""

    elif order[0] == "reverse":
        if a == 0:
            mojiretsu = mojiretsu[b::-1] + mojiretsu[b+1:]
        else:
            mojiretsu = mojiretsu[:a] + mojiretsu[b:a-1:-1] + mojiretsu[b+1:]

    elif order[0] == "replace":
        replace_word = list(order[3])
        mojiretsu = mojiretsu[:a] + replace_word + mojiretsu[b+1:]



Measured memory_bytes: 5640
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
int A[200010],B[200010];
P p[200010];

signed main(){
	cin>>N;
	REP(i,N){
		cin>>A[i]>>B[i];
		p[i]=make_pair(B[i],A[i]);
	}
	sort(p,p+N);
	int C=0;
	REP(i,N){
		C+=p[i].second;
		if(C>p[i].first){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 6528
from itertools import permutations
def myAnswer(ABCD:list) -> str:
   ans = ""
   l = ["+","+","+","-","-","-"]
   # l = ["+","-"]
   for c in permutations(l,3):
      total = int(ABCD[0])
      ans = ABCD[0]
      for n,i in enumerate(c):
         if(i=="+"):
            total += int(ABCD[n+1])
            ans += "+" + ABCD[n+1]
         else:
            total -= int(ABCD[n+1])
            ans += "-" + ABCD[n+1]
      if(total == 7):
         return ans + "=7"




def modelAnswer():
   tmp=1
def main():
   ABCD = list(input())
   print(myAnswer(ABCD[:]))

if __name__ == '__main__':
   main()

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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);


int main(void)
{
    string t; cin>>t;
    rep(i,t.size()) if(t[i]=='?') t[i]='D';
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

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

  cout << (N % 500 <= A ? "Yes" : "No") << endl;

  return 0;
}

Measured memory_bytes: 3624
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string input = Console.ReadLine();
            string[] array = input.Split(' ');
            int min = 0, max = 0;
            long sum = 0;
            int[] outp = new int[n];

            for (int t = 0; t < array.Length; t++)
            {
                outp[t] = int.Parse(array[t]);
                sum = sum + outp[t];
            }

             for (int i = 0; i < outp.Length; i++)
             {
                    for (int j = outp.Length - 1; j > i; j--)
                    {                       
                       if(outp[i] > outp[j])
                       {
                           int w = outp[i];
                           outp[i] = outp[j];
                           outp[j] = w;
                       }
                    }
              }
             min = outp[0];
             max = outp[outp.Length-1];

             Console.WriteLine(string.Format("{0} {1} {2}", min, max, sum));
        }
    }
}

Measured memory_bytes: 9916
import java.util.Scanner;
import java.util.Stack;

public class Main {
	public static void main(String args[]) {
		
		Scanner scan = new Scanner(System.in);
		Stack<Stack<Integer>> st = new Stack<>();
		
		int n = scan.nextInt();
		for(int i=0; i<n; i++) {
			st.add(new Stack<Integer>());
		}
		
		int count = scan.nextInt();
		
		for(int i=0; i<count; i++) {
			int query = scan.nextInt();
			int a = scan.nextInt();

			switch(query) {
			
			case 0:
				int b = scan.nextInt();
				st.get(a).push(b);
				break;
				
			case 1:
				if(!st.get(a).isEmpty())
				System.out.println(st.get(a).peek());
				
				break;
				
			case 2:
				if(!st.get(a).isEmpty())
				st.get(a).pop();
				
				break;
			}
		}
	}
}



Measured memory_bytes: 169424
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
using namespace std;
using ll = long long;
using pii = pair<int,int>;
template<typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a){
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os, vector<T> v){
    for(auto x:v)os << x << ' ';
    return os;
}
void debug(){cerr << '\n';}
template<typename H, typename... T>
void debug(H a, T... b){
    cerr << a;
    if(sizeof...(b))cerr << ", ";
    debug(b...);
}
int main(){
    int a[5];
    int sum = 0;
    rep(i,5){
        cin >> a[i];
        sum += (a[i]+9)/10*10;
    }
    int ans = sum;
    rep(i,5){
        ans = min(ans, sum - (100000-a[i])%10);
    }
    cout << ans << endl;
}

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

signed main()
{

  int A, B, V, W;
  int T;
  cin >> A >> V;
  cin >> B >> W;
  cin >> T;

  int lA = A-V*T;
  int rA = A+V*T;
  int lB = B-W*T;
  int rB = B+W*T;

  if (lB < lA || rA < rB) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }

  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int p[N*5];
int main()
{
	p[1] = 1;
	for(int i = 2; i * i <= 1000000; i ++)
	for(int j = i; j * i <= 1000000; j ++)
		p[i * j] = 1;
	ll x;
	cin >> x;
	for(ll i = x; ; i ++)
	{
		if(!p[i])
			return cout << i, 0;
	}





	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Measured memory_bytes: 4352
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
	static void result(long n)
	{
		long rem = n%10;
		if(rem==3) {
			System.out.println("bon");
		}
		else if(rem==0 || rem==1 || rem==6 || rem==8)
		{
			System.out.println("pon");
		}
		else
		{
			System.out.println("hon");
		}
	}
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		result(n);
	}
}

Measured memory_bytes: 27056
import { homedir } from 'os';

const main = lines => {
  console.log(solve(lines));
};

const solve = (lines: string[]): string => {
  const [[N], B] = parseLines(lines);

  // メモ A[i] = max(B[i-1], B[i]);

  let cnt = 0;
  cnt += B[0] + B[N - 2];
  for (let i = 1, e = N - 1; i < e; i++) cnt += Math.min(B[i - 1], B[i]);

  return cnt.toString();
};

const parseLines = (lines: string[]) => {
  const obj = lines.map(l => l.split(' ').map(n => +n));
  debug(obj);
  return obj;
};

const debug = (message?: any, ...optionalParams: any[]) => {
  if (!!process.env.LOCAL_DEBUG) console.log(message, ...optionalParams);
};

if (!process.env.LOCAL_DEBUG) {
  const { stdin: input, stdout: output } = process;
  input.resume();
  input.setEncoding('utf8');
  const lines = [];
  require('readline')
    .createInterface({ input, output })
    .on('line', line => lines.push(line))
    .on('close', () => main(lines));
}

export default solve;


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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;
typedef vector<int>				V;
typedef vector<V>				VV;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define MAX 		2505

const ll LINF = (ll)1e18+7;		//
const int INF = 1e9+7;			//2,147,483,647 (Max int)
const int MOD = 1e9+7;
// テンプレ終了
//====================================================================//

//
int main(){
	string S;
	cin >> S;

	int N = S.size();

	int flag = true;
	for(int i=N-1;i>=0;--i){
		if(S[i]=='m'){
			if(i<4){flag = false;break;}
			if(S.substr(i-4,5) != "dream"){flag = false;break;}
			i -= 4;
		}else if(S[i]=='r'){
			if(i>=5 && S[i-5]=='e'){
				if(S.substr(i-5,6) != "eraser"){flag = false;break;}
				i -= 5;continue;
			}else if(i>=6 && S[i-6]=='d'){
				if(S.substr(i-6,7) != "dreamer"){flag = false;break;}
				i -= 6;continue;
			}
			flag = false;break;
		}else if(S[i]=='e'){
			if(i<4){flag = false;break;}
			if(S.substr(i-4,5) != "erase"){flag = false;break;}
			i -= 4;
		}else{
			flag = false;
			break;
		}
	}

	puts(flag?"YES":"NO");

	return 0;
}




Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int w[1000000],v[1000000],dp[1000000];
main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,W;
    cin>>n>>W;
    for(int i=1; i<=n; i++)
    {
        cin>>w[i]>>v[i];
    }
    dp[0]=0;
    for(int j=1; j<=n; j++)
    {
        for(int i=W; i>=0; i--)
        {
            if(i+w[j]<=W)
            {
                dp[i+w[j]]=max(dp[i+w[j]],dp[i]+v[j]);
            }
        }
    }
    int m=0;
    for(int i=1; i<=W; i++)
    {
        m=max(m,dp[i]);
    }
    cout<<m<<endl;
    return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
bool check(string& s, vector<pair<int,int>>& q)
{
	for(int i=0; i<q.size(); i++)
	{
		if(s[q[i].first-1]-'0' != q[i].second)
			return false;
	}
	return true;
}
int main() {
	ld w,h,x,y;
	cout<<setprecision(10)<<fixed;
	cin>>w>>h>>x>>y;
	cout<<(w*h)/2.0 <<" ";
	if(2*x == w && 2*y == h)
		cout<<1;
	else
		cout<<0;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define MOD 1000000007
#define INF 99999999 
using namespace std;
 
int main()
{
    int K,A,B;
    cin >> K >> A >> B;
    for (int i = 0; i < B-A+1; i++)
    {
        if((i+A)%K == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}

Measured memory_bytes: 3632
import itertools

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
v = P[:]
v.sort()
p = tuple(P)
q = tuple(Q)
ans_a = 0
ans_b = 0
if p == q:
    print(0)
else:
    for i, l in enumerate(itertools.permutations(v)):
        if p == l:
            ans_a = i + 1
        elif q == l:
            ans_b = i + 1
    print(abs(ans_a - ans_b))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    if (A % 3 == 0 || B % 3 == 0 || (A+B) % 3 == 0) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }

    return 0;
}


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

using namespace std;

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

const int N = 1e5 + 5;

inline int gcd(int x,int y) {
  return y ? gcd(y,x % y) : x;
}

inline void yeah() {
  cout << "POSSIBLE" << endl;
  exit(0);
}

int n,k,a[N],d;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cin >> n >> k;
  for (int i = 1 ; i <= n ; i++) {
    cin >> a[i];
    d = gcd(d,a[i]);
  }
  for (int i = 1 ; i <= n ; i++)
    if (a[i] >= k && (a[i] - k) % d == 0)
      yeah();
  cout << "IMPOSSIBLE";
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define out(S) cout<<(S)<<endl;
#define ShowAll(collection) for(auto i:collection){out(i);}
#define beginend(v) v.begin(),v.end()

using pii=pair<int,int>;
using ll=long long;
template<typename T> void removeAt(vector<T>& v, int index) { v.erase(v.begin() + index); }

struct node {
    vector<node*> next;
    ll cost;
    node* before;
    node(ll c) : cost(c){};
    node():cost(0){};
};

node* make(string s){
    node* root = new node();
    auto pos=root;
    int c=0,n=s.size();
    while (1){
        if(c>=n) break;
        if(s[c]=='['){
            node* tmp=new node();
            tmp->before=pos;
            pos->next.push_back(tmp);
            pos=tmp;
            c++;
        }else if(s[c]==']'){
            pos=pos->before;
            c++;
        }else{
            int i=c;
            int num=0;
            while(1) {
                if(!isdigit(s[i])) break; else num=num*10+(s[i]-'0');
                i++;
            }
            c=i;
            pos->cost=(num+1)/2;
        }
    }
    return root;
}

ll dfs(node* now){
    if(now->cost!=0) return now->cost;
    int n=(now->next).size();
    vector<ll> sum;
    rep(i,n){
        sum.push_back(dfs(now->next[i]));
    }
    sort(beginend(sum));
    ll rt=0;
    for (int j = 0; j < (n + 1) / 2; ++j) {
        rt+=sum[j];
    }
    return rt;
}

int solve(){
  string s;
  cin >> s;
  auto root=make(s);
  cout<<dfs(root)<<endl;
}

int main()
{
    int n;
    cin >> n;
    rep(i,n) solve();
  return 0;
}



Measured memory_bytes: 5356