akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
 
public class Main {
    Scanner sc = new Scanner(System.in);
 
    public static void main(String[] args) {
    	new Main(); 
    }
 
    public Main() {
    	new A().doIt();
    }
    class A{
    	char alf[][] = {{},
    			{'.',',','!','?',' '},
    			{'a','b','c'},
    			{'d','e','f'},
    			{'g','h','i'},
    			{'j','k','l'},
    			{'m','n','o'},
    			{'p','q','r','s'},
    			{'t','u','v'},
    			{'w','x','y','z'},
    			};
    	void doIt(){
    		int n = sc.nextInt();
//    		for(int i = 0;i < alf.length;i++){
//    			for(int j = 0;j < alf[i].length;j++){
//    				System.out.print(alf[i][j]+" ");
//    			}
//    			System.out.println();
//    		}
    		for(int i = 0;i < n;i++){
    			String str = sc.next();
    			char ctr[] = str.toCharArray();
    			StringBuilder sb = new StringBuilder();
    			int length = ctr.length;
    			int cnt[] = new int [10];
    			int pos = 0;
    			for(int j = 0;j < length;j++){
    				int num = Integer.parseInt(""+ctr[j]);
    				if(num == 0){
    					cnt[pos]--;
    					if(pos == 0 || cnt[pos] == -1);
    					else if(pos == 7 || pos == 9){
    						sb.append(alf[pos][(cnt[pos])%4]);
    					}else if(pos == 1){
    						sb.append(alf[pos][(cnt[pos])%5]);
    					}else{
    						sb.append(alf[pos][(cnt[pos])%3]);
    					}
    					cnt[pos] = 0;
    					pos = 0;
    				}else{
    					cnt[num]++;
    					pos = num;
    				}
    			}
    			System.out.println(sb);
    		}
    	}
    }
}

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

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

	int N;
	cin >> N;

	vector<string> S(N);
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}

	// cout << S.size();
	// for (auto a : S) {
	// 	cout << a << "\n";
	// }

	sort(S.begin(), S.end());

	// for (auto a : S) {
	// 	cout << a << "\n";
	// }

	int count = 1;
	for (int i = 1; i < N; i++) {
		if (S[i] != S[i - 1]) {
			count++;
		}
	}

	// for (auto a : S) {
	// 	cout << a << "\n";
	// }
	cout << count;
	// S.erase(unique(S.begin(), S.end()), S.end());
	// cout << S.size();
	// for (auto a : S) {
	// 	cout << a << "\n";
	// }
	return 0;
}

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

typedef vector<int> vi;
typedef pair<int, int> pi;

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

#define pb push_back
#define mp make_pair

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, b, e) for (int i = (b); i <= (int)(e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) cout << #a << ": "; for (const auto& v: (a)) cout << v << endl

signed main() {
    int N;
    cin >> N;
    int A[N];
    REP(i, N) cin >> A[i];
    sort(A, A+N);
    auto p = lower_bound(A, A+N, 0);

    int ans = A[0];
    int current = A[0];
    vector<pi> v;
    REP2(i, 1, N-2) {
        if (A[i] < 0) continue;
        v.pb(mp(current, A[i]));
        ans -= A[i];
        current = ans;
    }
    v.pb(mp(A[N-1], current));
    ans = A[N-1] - current;
    current = ans;
    REP2(i, 1, N-2) {
        if (A[i] >= 0) continue;
        v.pb(mp(current, A[i]));
        ans -= A[i];
        current = ans;
    }
    cout << ans << endl;
    REP(i, v.size()) cout << v[i].first << " " << v[i].second << endl;

    return 0;
}


Measured memory_bytes: 4336
(r,c) = [int(i) for i in input().split()]

table = []
for rc in range(r):
    table.append([int(i) for i in input().split()])

table.append([0 for  _  in range(c + 1)])


for rc in range(r):
    row_total = 0
    for cc in range(c):
        table[r][cc] += table[rc][cc]
        row_total += table[rc][cc]

    table[rc].append(row_total)
    table[r][c] += row_total

for row in table:
   print(' '.join([str(column) for column in row]))

Measured memory_bytes: 6728
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

int cnt[200010];

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

    rep(i,n){
        int a;
        cin >> a;
        cnt[a-1] ++;
    }
    sort(cnt,cnt+n);
    int ans=0;
    rep(i,n-k){
        ans += cnt[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 4412
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
#define INF 99999999

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef unordered_map<int,Edges> Graph;

void shortestPath(Graph &g, int s,
    unordered_map<int,Weight> &dist, unordered_map<int,int> &prev) {
  for(auto &f:g)dist[f.first]=INF; dist[s] = 0;
  priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
    Edge e = Q.top(); Q.pop();
    if (prev.find(e.dst) != prev.end()) continue;
    prev[e.dst] = e.src;
    for(auto &f:g[e.dst]) {
      if (dist[f.dst] > e.weight+f.weight) {
        dist[f.dst] = e.weight+f.weight;
        Q.push(Edge(f.src, f.dst, e.weight+f.weight));
      }
    }
  }
}

char buf[1001];
int W;
int coor(int x,int y){return (y)*(W*2+2)+x;}
int main(){
	int H,N,X1,Y1,X2,Y2;
	scanf("%d%d%d%d%d%d%d",&W,&H,&N,&X1,&Y1,&X2,&Y2);
	X1=coor(X1*2,Y1*2),X2=coor(X2*2,Y2*2);
	vector<vector<int> >m(H*2+1);
	for(auto &&e:m)e.resize(W*2+1);
	for(int i=0;i<N;i++){
		int x,y,t,l;
		scanf("%d%d%d%s",&x,&y,&t,buf);
		l=strlen(buf);
		x=2*x+1,y=2*y+1;
		for(int j=0;j<t;j++){
			for(int k=0;k<l;k++){
				int c=buf[k];
				if(c=='L'&&1<x)m[y][x-1]++,x-=2;
				if(c=='U'&&1<y)m[y-1][x]++,y-=2;
				if(c=='R'&&x<W*2-1)m[y][x+1]++,x+=2;
				if(c=='D'&&y<H*2-1)m[y+1][x]++,y+=2;
			}
		}
	}
	Graph g;
	for(int h=0;h<=H*2;h+=2)for(int w=0;w<=W*2;w+=2){
		int a=coor(w,h),b;
		if(h<H*2-1)b=coor(w,h+2),g[a].push_back(Edge(a,b,m[h+1][w])),g[b].push_back(Edge(b,a,m[h+1][w]));
		if(w<W*2-1)b=coor(w+2,h),g[a].push_back(Edge(a,b,m[h][w+1])),g[b].push_back(Edge(b,a,m[h][w+1]));
	}
	unordered_map<int,Weight> dist;
	unordered_map<int,int> prev;
	shortestPath(g,X1,dist,prev);
	printf("%d\n",dist[X2]);
}

Measured memory_bytes: 57168
arr = []
3.times do |i|
  arr[i] = gets.strip
end
idx = 0
mem = "ABC"

loop do
  break if arr[idx].empty?
  card = arr[idx].slice!(0, 1)
  if(card == "a")
    idx = 0
  elsif(card == "b")
    idx = 1
  else
    idx = 2
  end
end

puts mem[idx]

Measured memory_bytes: 1788
import heapq

N = int(input())
h = [4, 7]
heapq.heapify(h)

while True:
    n = heapq.heappop(h)

    if n > N:
        print('No')
        break

    if n == N:
        print('Yes')
        break

    heapq.heappush(h, n + 4)
    heapq.heappush(h, n + 7)

Measured memory_bytes: 7748
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
typedef  pair<int,int> P;

int n;
ll a[200005];
ll mod=1000000007;

int main()
{
cin>>n;
rep(i,n){cin>>a[i];}
ll ans=0;
ll sum=0;
rep(i,n)
{
sum+=a[i];

}
for(int i=0;i<n;i++)
{
sum-=a[i];
ans +=((a[i]%mod)*(sum%mod))%mod;
ans=ans%mod;


}

ans=ans%mod;
cout <<ans;
}



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

int a[101];

int main()
{
	int n, x;
	cin >> n;
	
	for(int i=1; i<=n; i++)
	{
		cin >> x;
		a[x]=1;
	}
	
	int s=0;
	for(int i=1; i<=100; i++)
	{
		if(a[i]==1) s++;
	}
	
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
f=(r=(0...n=gets.to_i)).map{gets.split.join.to_i 2}
q=r.map{gets.split.map &:to_i}
p (1..1023).map{|e|r.map{|i|q[i][(e&f[i]).to_s(2).count('1')]}.inject:+}.max

Measured memory_bytes: 1916
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


int  c[100002];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	rep(i,n){
		int a;
		cin>>a;
		c[a]++;
		c[a+1]++;
		c[a+2]++;
	}
	cout << *max_element(c, c + 100002)<<endl;

	return 0;
}

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


int main(){
    ll N ,M, ans = 0;
    cin >> N >> M;
    vector<ll> v(N + 1, 0);
    ll L, R;
    L = 0;
    R = N;
    for(int i = 0; i < M; i++){
        ll tmp_R,tmp_L;
        cin >> tmp_L >> tmp_R;
        R = min(R , tmp_R);
        L = max(L , tmp_L);
    }


    if( R >= L){
        cout << R - L + 1 << endl;
    }else{
        cout << 0 << endl;
    }
    

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int N,A,B,K;
int s[100000];
int cnt=0;

bool solve(){
  int f=0;
  for(int i=0;i<N;i++)f^=s[i]%(K+1);
  
  if(A==B||cnt==N)return (f>0);

  if(A>B)return true;
  if(cnt<N-1)return false;
  
  f^=s[N-1]%(K+1);
  return (s[N-1]-A<=f && f<=A);
}

int main(){
  cin>>N>>A>>B;
  K=min(A,B);
  for(int i=0;i<N;i++){
    cin>>s[i];
    if(s[i]<=K)cnt++;
  }
  sort(s,s+N);
  cout<< (solve()?"Hanako":"Jiro") <<endl;
  return 0;
}

Measured memory_bytes: 3492
from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for _ in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
tests = lambda: range(1, int_in() + 1)
case_out = lambda i, o: out("Case #{}: {}".format(i, o))


def solve(s, t):
    result = 0
    for i in range(len(s)):
        if s[i] != t[i]:
            result += 1
    return result


if __name__ == "__main__":
    s = str_in()
    t = str_in()
    out(solve(s, t))

Measured memory_bytes: 67948
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long lint;
typedef vector<lint> vlint;
typedef vector<vlint> vvlint;
typedef pair<lint, lint> plint;
typedef double ld;

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

int mod = 1000000007;
struct mint {
	lint x;
	mint(lint x=0):x((x%mod+mod)%mod){}
	mint operator-() const { return mint(-x);}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res*=a;
	}
	mint pow(lint t) const {
		if (!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if (t&1) a *= *this;
		return a;
	}
	mint inv() const {
		return pow(mod-2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res/=a;
	}
};

int main() {	
    ios::sync_with_stdio(false);
	cin.tie(0);
	
	//int n, m;
	//cin >> n >> m;
	//int a[n];
	//int sum = 0;
	//forn(i, n)cin >> a[i], sum += a[i];
	//sort(a, a + n);
	//reverse(a, a + n);
	//int i = 0;
	//int x = m;
	//while(m--){
		//if(a[i] < sum / (4 * x)){
			//cout << "No";
			//return 0;
		//}
		//i++;
	//}
	//cout << "Yes";
	lint n, k;
	cin >> n >> k;
	if(n < k){
		cout << min(n, k - n);
		return 0;
	}
	n %= k;
	cout << min(n, k - n);
	return 0;
}


Measured memory_bytes: 256
#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 < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (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 (b < a) a = b; return true; }

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

constexpr ll MOD = 1000000007;

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

  rep(i, n) {
    int a; cin >> a;
    if (a % 2) {
      cout << "first" << endl;
      return (0);
    }
  }

  cout << "second" << endl;
  
  return (0);
}

Measured memory_bytes: 3628
#include<stdio.h>
int isprime(int n){
    int i;
    for(i = 2;  i < n; i ++ ){
        if(n % i == 0)return 0;
    }
    return 1;
}
int main(void){
    const int NUM = 10001;
    int i,n,prime[NUM],p1,q1;
    for(i = 2; i < NUM; i ++ ){
        prime[i] = isprime(i);
    }
    
    while(1){
        scanf("%d",&n);
        if(n == 0)break;
        for(i = n; i >= 2; i --){
            if(prime[i] == 1 && prime[i - 2] == 1){
                    q1 = i;
                    p1 = i - 2;
                    printf("%d %d\n",p1,q1);
                    break;
            }
        }
    }
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  int count;
  
  for (int i = 0; i < N; i++) {
    cin >> vec[i];
  }
  
  sort(vec.begin(), vec.end());
  
  count = 0;
  
  for (int i = 1; i < N; i++) {
    if (vec[i-1] != vec[i]) {
      count++;
    }
  }
  cout << count + 1 << endl;
}

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

int main(void){
    char a[12]; int b[50];
    int N,K,s;
    
    scanf("%d",&N);
   
    scanf("%s",a);
   
    scanf("%d",&K);
    
   for(int i=0;i<=N-1;i++){
       b[i]=(int)a[i];
   }
   
   for(int i=0;i<=N-1;i++){
       if((int)a[i] != b[K-1]){
           a[i]='*';
       }
   }
   
   printf(a);
    
   
        return 0;
    }



Measured memory_bytes: 384
#include<stdio.h>
int a[200000];
int main()
{
	int n;
	int i,j,sum=0,f=1,x=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(i=0;i<n;i++)
	{
		if(a[i]==f)
		{
			sum=sum+i-x;
			f++;
			x=i+1;
		}
	}
	if(n==1&&a[0]==1) printf("0");
	else if(x==0) printf("-1");
	else{
	for(i=x;i<n;i++)
	{
		sum++;
	}
	printf("%d",sum);
    }
 }

Measured memory_bytes: 896
N = int(input())
A= list(map(int,input().split()))
output=0

for i in range(N):
        hoge = 0
        for k in range(i):
                if A[k] <= A[i]:
                        hoge += 1
                else:
                        break
        if hoge == i:
                output += 1

print(output)

Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("0"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}

const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;

int n, k;
vi to[MX];

int dfs(int v, int d, int p=-1) {
  if (!d) return 0;
  int res = 1;
  for (int u : to[v]) if (u != p) {
    res += dfs(u,d-1,v);
  }
  return res;
}

int main() {
  scanf("%d%d",&n,&k);
  rep(i,n-1) {
    int a, b;
    scanf("%d%d",&a,&b);
    --a; --b;
    to[a].pb(b);
    to[b].pb(a);
  }
  int ans = 0;
  rep(i,n) {
    int m = sz(to[i]);
    vp p(m);
    rep(j,m) {
      p[j].fi = dfs(to[i][j],k/2,i);
      p[j].se = dfs(to[i][j],k-k/2,i);
    }
    int sum = 1;
    rep(j,m) sum += p[j].fi;
    int mx = 0;
    rep(j,m) maxs(mx, p[j].se-p[j].fi);
    sum += mx;
    maxs(ans, sum);
  }
  ans = n-ans;
  cout<<ans<<endl;
  return 0;
}







Measured memory_bytes: 2688
#include<stdio.h>
int main(void)
{
  int A,B,C,D,ABCD;

  scanf("%d",&ABCD);

  D=ABCD%10;
  C=(ABCD%100-D)/10;
  B=(ABCD%1000-D-C*10)/100;
  A=(ABCD-B*100-D-C*10)/1000;

  if(A+B+C+D==7){
    printf("%d+%d+%d+%d=7\n",A,B,C,D);
  } else if(A+B+C-D==7){
    printf("%d+%d+%d-%d=7\n",A,B,C,D);
  } else if(A+B-C+D==7){
    printf("%d+%d-%d+%d=7\n",A,B,C,D);
  } else if(A+B-C-D==7){
    printf("%d+%d-%d-%d=7\n",A,B,C,D);
  } else if(A-B+C+D==7){
    printf("%d-%d+%d+%d=7\n",A,B,C,D);
  } else if(A-B+C-D==7){
    printf("%d-%d+%d-%d=7\n",A,B,C,D);
  } else if(A-B-C+D==7){
    printf("%d-%d-%d+%d=7\n",A,B,C,D);
  } else if(A-B-C-D==7){
    printf("%d+%d-%d-%d=7\n",A,B,C,D);
  }
  
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
char d[200010],dp[600][600];

int main(){
  vp vec;
  cin >> n >> m;
  rep(i,0,n){
    ll a,b;
    cin >> a >> b;
    vec.pb(P(a,b));
  }
  sort(all(vec));
  rep(i,0,vec.sz){
    m -= vec[i].second;
    if(m <= 0){
      print(vec[i].first);
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 1400
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] t = new int[n];
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			t[i] = scan.nextInt();
			a[i] = scan.nextInt();
		}
		long[] Tdp = new long[n+1];
		long[] Adp = new long[n+1];
		long T = 0;
		long A = 0;
		Tdp[0] = 1;
		Adp[0] = 1;
		for (int i = 0; i < n; i++) {
			if ((Tdp[i]%t[i])==0) {
				T = Tdp[i]/t[i];
			} else {
				T = (Tdp[i]/t[i])+1;
			}
			if ((Adp[i]%a[i])==0) {
				A = Adp[i]/a[i];
			} else {
				A = (Adp[i]/a[i])+1;
			}
			long x = Math.max(T, A);
			Tdp[i+1] = t[i]*x;
			Adp[i+1] = a[i]*x;
		}
		System.out.println(Tdp[n]+Adp[n]);
	}
}


Measured memory_bytes: 25068
# coding: utf-8
while True:
    n, s = map(int, input().split()) # nとsの入力
    ans = 0 #解答の初期化
    if [n, s] == [0, 0]: # 終了処理
        break
    else:
        for t in range(2 ** 10): # ビット表現で[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]の部分集合を列挙
            a = [] # 列挙のためのlistを用意し、初期化
            for i in range(10):
                if t >> i & 1:
                    a += [i]
            if len(a) == n: # 要素数がnのもののみ考察する
                if sum(a) == s:
                    ans += 1
        print(ans) #解答の出力


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

#define ALL(v) v.begin(), v.end()
typedef long long ll;



using namespace std;
int main() {
	string A,B,C;
	
	string turn = "a";
	int as = 0, bs = 0, cs = 0;

	
	cin >> A >> B >> C;
	



	for (int i = 0;; i++)
	{
		if (turn == "a") {
			turn = A[as];
			as++;
			
			if (A.length()+1 == as) {
				cout << "A" << endl;
				break;
			}
		}

		if (turn == "b") {
			turn = B[bs];
			bs++;
			if (B.length() + 1 == bs) {
				cout << "B" << endl;
				break;
			}
		}

		if (turn == "c") {
			turn = C[cs];
			cs++;
			if (C.length() + 1 == cs) {
				cout << "C" << endl;
				break;
			}
		}

	}

	
	

}

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

int main() {

  string c;
  
  cin >> c;
    if(c[0]==c[1]&&c[2]==c[3]&&c[1]!=c[2])
      cout << "Yes" << endl;
  	else if(c[0]==c[2]&&c[1]==c[3]&&c[2]!=c[1])
      cout << "Yes" << endl;
  	else if(c[0]==c[3]&&c[1]==c[2]&&c[3]!=c[2])
      	cout << "Yes" << endl;
  	else
      cout << "No" << endl;
   
  
}


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

const ll INF = 1e18;
const int MAX_L = 101010;

int main()
{
    int N;
    cin >> N;
    vector<P> a(N+1); //first:weight, second:value
    rep(i,N) cin >> a[i+1].second >> a[i+1].first; //1-indexed
    
    int K = 9;
    int n1 = (1 << K) - 1; //深さKまでの要素数
    vector<vector<ll>> dp(n1+1, vector<ll>(MAX_L+1, 0));
    for(int i = 1; i <= min(n1, N); i++)
    {
        rep(j,MAX_L)
        {
            int w = a[i].first, v = a[i].second;
            dp[i][j] = max(dp[i][j], dp[i/2][j]);
            if(j - w >= 0)
                dp[i][j] = max(dp[i][j], dp[i/2][j-w] + v);

        }
    }

    int Q;
    cin >> Q;
    while(Q--)
    {
        int v, l;
        cin >> v >> l;
        //既に計算してあるならそのまま使う
        if(v <= n1)
        {
            cout << dp[v][l] << endl;
            continue;
        }
        //計算していない部分の要素を取得
        vector<P> b(0);
        while(v > n1)
        {
            b.emplace_back(a[v]);
            v /= 2;
        }
        //for(auto x:b) cout << x.first << " ";cout << endl;
        //全列挙
        int n2 = b.size();
        ll ans = 0;
        for(int bits = 0; bits < (1 << n2); bits++)
        {
            int sw = 0, sv = 0;
            rep(i,n2) if(bits & (1 << i))
            {
                sw += b[i].first;
                sv += b[i].second;
            }
            if(l - sw >= 0)
            {
                ll tv = dp[v][l - sw];
                ans = max(ans, sv + tv);
            }
        }
        
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 413740
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
int main()
{
	int a, b;
	scanf("%d%d", &a, &b);
	if (a > b)swap(a, b);
	ll r = 1;
	for (int i = 1; i <= a; i++)r = r*i%mod;
	for (int i = 1; i <= b; i++)r = r*i%mod;
	if (a == b)r *= 2, r %= mod;
	else if (a + 1 != b)r = 0;
	printf("%lld\n", r);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array);

int main(){
	ll n,m;
	cin>>n>>m;
	ll ans=1;
	if(n>=2) ans=(n)*(n-1)/2;
	else ans=0;
	if(m>=2) ans=ans+((m-1))*m/2;
	else ;
	cout<<ans<<endl;
	
}

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

int main() {

  int W, a, b;
  cin >> W >> a >> b;

  int answer = 0;

  if (b < a) {
    swap(a, b);
  }

  if (W + a < b) {
    answer = b - (W + a);
  }

  cout << answer << endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdint>
#include <iostream>
#include <unordered_map>
#include <vector>

using namespace std;
void Check(bitset<1000001>& bs, int64_t i, int64_t max_num) {
  if (bs.test(i)) {
    for (int64_t j = 1; i * (j + 1) <= max_num; ++j) {
      bs.reset(i * (j + 1));
    }
  }
}
       
int main() {
  int64_t N;
  cin >> N;
  
  vector<int64_t> nums(N);
  unordered_map<int64_t, int64_t> num_map;
  int64_t m = 0;
  for (int n = 0; n < N; ++n) {
    cin >> nums[n];
    ++num_map[nums[n]];
    m = max(m, nums[n]);
  }
  bitset<1000001> checker = ~bitset<1000001>();
  sort(nums.begin(), nums.end());
  {
    int64_t pre = -1;
    for (int64_t n : nums) {
      if (pre != n) {
        Check(checker, n, m);
        pre = n;
      }
    }
  }
  int64_t res = 0;
  for (int64_t n : nums) {
    if (num_map[n] > 1) continue;
    if (checker.test(n)) {
      ++res;
    }
  }
  cout << res << endl;

  return 0;
}


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

if (A==1 and B!=1):
    print("Alice")
    exit()
elif(B==1 and A!=1):
    print("Bob")   
    exit()




if (A>B):
    print("Alice")
elif(A<B):
    print("Bob")
elif(A==B):
    print("Draw")
     


Measured memory_bytes: 3060
N=int(input())
pf={}
m=0
insuu=[0]*(N+1)
p=10**9+7
for i in range(1,N+1):
    m=i
    for j in range(2,int(m**0.5)+1):
        while m%j==0:
            pf[j]=pf.get(j,0)+1
            m//=j
    if m>1:pf[m]=1
    #print(pf)
    keys=list(pf.keys())
    values=list(pf.values())
    pf={}
    for j in range(len(keys)):
        insuu[keys[j]]=insuu[keys[j]]+values[j]
    #print(insuu)
    #input()
    #print(l)	#これでlistになった
ans=1
for i in range(N+1):
    if insuu[i]>0:
        ans=(ans*(insuu[i]+1))%p
print(ans%p)

Measured memory_bytes: 44140
import java.util.*;

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

    public static void main(String[]$) {
        String s = scanner.next();
        char[] t = s.replace("x", "").toCharArray();
        int[] c = new int[t.length + 1];

        for (int i = 0; i < (t.length + 1) / 2; i++) {
            if (t[i] != t[t.length - i - 1]) {
                System.out.println(-1);
                return;
            }
        }

        for (int i = 0, j = 0; i < s.length(); i++) {
            if (s.charAt(i) == 'x') {
                c[j]++;
            } else {
                j++;
            }
        }

        long ans = 0;
        for (int i = 0; i < (t.length + 1) / 2; i++) {
            ans += Math.abs(c[i] - c[t.length - i]);
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 32928
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <iomanip>
using namespace std;
#define Pi 3.14159265

int main(){
    int a, b, h, m;
    double angle, ans;
    cin >> a >> b >> h >> m;

    angle = abs((h * 30.0 + (30.0/60.0) * m) - m * 6.0);
    if(angle>180.0){
        angle = 360.0 - angle;
    }

    ans = (a * a) + (b * b) - (2 * a * b * cos((angle * 2 * acos(0)) / 180.0));
    ans = sqrt(ans);
    cout << setprecision(20) << ans;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
 
#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
void ans1(bool x){
  if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){
  if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){
  if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){
  if(x) cout<<y<<endl;else cout<<z<<endl;}   
 
 
int main(){
  ll i,j;
  ll result = 0;
  ll buf = 0;
  ll buf2 = 0;
  ll buf3 = 0;
  bool judge = true;
  ll n; cin >> n;
 
  for(buf=n;buf!=0;buf/=10)buf2+=buf%10;
  ans1(n%buf2==0);
 
  return 0;
}

Measured memory_bytes: 384
n= int(input())
a= list(map(int, input().split()))

num = [[0,0] for i in range(n+1)]
num[0] = [1,0]

if(n==0):
    if(a[0]==1):
        print(1)
    else:
        print(-1)
    exit()
else:
    if(a[0]>=1):
        print(-1)
        exit()

for i in range(n):
    here = a[1+i]
    possible = num[i][0]*2
    num[i+1] = [possible-here,here]
    
#print(num)

if(num[-1][0]<=-1):
    print(-1)
    exit()

num[-1][0] = 0

for i in range(n-1,-1,-1):
    if(num[i+1][0]+num[i+1][1]<num[i][0]):
        num[i][0] = num[i+1][0]+num[i+1][1]

#print(num)

if(num[n][0]>=1):
    print(-1)
    exit()

for i in range(n):
    if(num[i][0]<=0):
        print(-1)
        exit()

s = sum([sum(num[i]) for i in range(n+1)])
print(s)



Measured memory_bytes: 711448
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

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

    bool is_A = false, is_B = false;
    REP(i, 3) {
        if(S[i]=='A') is_A = true;
        if(S[i]=='B') is_B = true;
    }

    if(is_A && is_B) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll A, B, Q; cin >> A >> B >> Q;
    vector<ll> s(A + 2), t(B + 2);
    // 左右端の処理が面倒なので-INF/INFを詰める
    rep(i, A){cin >> s.at(i + 1);} s.at(0) = -INF;  s.at(A + 1) = INF;
    rep(i, B){cin >> t.at(i + 1);} t.at(0) = -INF;  t.at(B + 1) = INF;

    vector<ll> vec;
    rep(i, Q){
        ll x; cin >> x;
        auto iter_s = upper_bound(s.begin(), s.end(), x);
        ll right_ind_s = distance(s.begin(), iter_s);
        ll left_ind_s = right_ind_s - 1;

        auto iter_t = upper_bound(t.begin(), t.end(), x);
        ll right_ind_t = distance(t.begin(), iter_t);
        ll left_ind_t = right_ind_t - 1;

        // ll ans = INF;
        vector<ll> answers;

        // 4パターン網羅しなきゃいけない
        answers.push_back(x - min(s.at(left_ind_s), t.at(left_ind_t))); // (左，左)
        answers.push_back(max(s.at(right_ind_s), t.at(right_ind_t)) - x); // (右，右)
        answers.push_back(min(
            2 * (x - s.at(left_ind_s)) + (t.at(right_ind_t) - x),
            (x - s.at(left_ind_s)) + 2 * (t.at(right_ind_t) - x)
        )); // (左，右)
        answers.push_back(min(
            2 * (x - t.at(left_ind_t)) + (s.at(right_ind_s) - x),
            (x - t.at(left_ind_t)) + 2 * (s.at(right_ind_s) - x)
        )); // (右，左)
        vec.push_back(*min_element(answers.begin(), answers.end()));
    }
    for (auto v: vec){cout << v << endl;}
}

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


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

int main() {
  string s;
  cin >> s;
  int maxPrefix = 0, prefix[s.size() + 1];
  prefix[0] = 0;
  for (int i = 1; i <= s.size(); ++i) {
    if (s[i - 1] == '1') {
      prefix[i] = prefix[i - 1] + 1;
    } else {
      prefix[i] = prefix[i - 1] - 1;
    }
    maxPrefix = max(maxPrefix, prefix[i]);
  }
  auto solve = [&](int maxPrefix) {
    int capacity[s.size()];
    for (int i = s.size(), j = numeric_limits<int>::max(); i > 0; --i) {
      j = min(j, maxPrefix - prefix[i]);
      capacity[i - 1] = j / 2;
    }
    int sum = 0, result = 0, count = 0;
    for (int i = 0; i < s.size(); ++i) {
      if (s[i] == '1') {
        ++sum;
      } else if (s[i] == '0') {
        --sum;
      } else if (capacity[i] > count) {
        ++sum;
        ++count;
      } else {
        --sum;
      }
      result = min(result, sum);
    }
    return result;
  };
  cout << min(maxPrefix - solve(maxPrefix), maxPrefix + 1 - solve(maxPrefix + 1));
  return 0;
}

Measured memory_bytes: 11808
import java.io.*
import java.util.*

object Input {
    private var i = 0
    private var line = listOf<String>()

    fun next(): String = if (i < line.size) {
        line[i++]
    } else {
        line = readLine()?.split(" ") ?: throw Exception("EOF")
        i = 0
        next()
    }

    fun int() = next().toInt()

    fun long() = next().toLong()

    fun double() = next().toDouble()
}

object Out {
    private val buffer = mutableListOf<Any>()

    fun writeln(obj: Any) = writeSep(obj, "\n")

    fun writeSep(obj: Any, sep: String = " ") = write("$obj$sep")

    fun write(obj: Any) = buffer.add(obj)

    fun flush() {
        print(buffer.joinToString(""))
        buffer.clear()
    }
}

inline fun run(action: () -> Unit) {
    try {
        action()
    } finally {
        Out.flush()
    }
}

fun main(args: Array<String>) = run {
    val a = Input.next()
    val b = Input.next()

    val c = (a + b).toInt()

    for (i in 1..c) {
        if (i * i == c) {
            Out.writeln("Yes")
            return
        }
    }

    Out.writeln("No")
}

Measured memory_bytes: 37952
import scala.collection.mutable

object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  val Array(n, m, c) = readLine.trim.split(' ').map(_.toInt)
  val limits = readLine.trim.split(' ').map(_.toInt)
  val queue = mutable.PriorityQueue()(Ordering.by[(Int, Int), Int](_._2))
  for (_ ← 0 until n){
    val Array(color, weight) = readLine.trim.split(' ').map(_.toInt)
    queue.enqueue((color - 1, weight))
  }
  var sum = 0
  for (_ ← 0 until m){
    while (queue.nonEmpty && limits(queue.head._1) == 0) {
      queue.dequeue()
    }
    if (queue.nonEmpty){
      val (color, weight) = queue.dequeue()
      limits(color) -= 1
      sum += weight
    }
  }
  println(sum)
  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}


Measured memory_bytes: 217976
# https://img.atcoder.jp/abc119/editorial.pdf
# bisect_right ---> bisect_left
import bisect
A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_left(s, x), bisect.bisect_left(t, x)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)


Measured memory_bytes: 17508
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

struct edge {
  ll to;
  ll id;
};

ll use[55][55];
vector<edge> g[55];

void dfs(ll now, ll root, ll used) {
  use[root][now] = used;
  for (auto x : g[now])
    if (((used >> x.id) & 1) == 0) dfs(x.to, root, used | (1ll << x.id));
}

ll pow(ll n, ll a) {
  ll res = 1;
  for (int i = 0; i < a; i++) res *= n;
  return res;
}

// ====================================================================

int main() {
  // 入力
  ll n;
  cin >> n;
  for (ll i = 0; i < n - 1; i++) {
    ll a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back((edge){b, i});
    g[b].push_back((edge){a, i});
  }
  ll m;  // 条件の個数
  cin >> m;
  vector<pair<ll, ll>> joken(m);
  for (ll i = 0; i < m; i++) {
    cin >> joken[i].first >> joken[i].second;
    joken[i].first--;
    joken[i].second--;
  }

  // DFSをして、iからjに行くのに必要な辺を求める
  for (ll i = 0; i < n; i++) dfs(i, i, 0);

  ll ans = 0;
  for (ll i = 1; i < (1ll << m); i++) {  // bit全探索、包除原理
    ll count = 0;                        // 使う辺の数をここに入れたい
    for (ll d = 0; d < m; d++) {         // 条件の辺のOR
      if ((i >> d) & 1)
        count |= use[joken[d].first][joken[d].second];
    }
    count = __builtin_popcountll(count);
    ans += pow(2ll, n - 1 - count) * (__builtin_popcountll(i) % 2 ? 1 : -1);
  }

  cout << pow(2ll, n - 1) - ans << endl;
}


Measured memory_bytes: 384
import collections
N = int(input())
A = list(map(int,input().split()))
A.sort()
A = collections.Counter(A)

ans = 1
count = 0
if N == 1:
    if A[0] == 1:
        ans = 1
    else:
        ans = 0

elif N % 2 == 0:
    for i in range(1, int(N/2)+1):
        if A[i*2-1] == 2:
            count += 1
        else:
            ans = 0
else:
    if A[0] == 1:
        for i in range(1, int(N/2)+1):
            if A[i*2] == 2:
                count += 1

            else:
                ans = 0
    else:
        ans = 0
for i in range(count):
    ans *= 2
    ans %= 1000000007
print(ans)


Measured memory_bytes: 14820
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int main() {
  int a;
  cin >> a;
  cout << a + a * a + a * a * a << endl;

  return 0;
}


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

public class Main {

	private static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int[] a = new int[3];
		for (int i = 0; i < 3; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		System.out.println(a[0] == 5 && a[1] == 5 && a[2] == 7 ? "YES" : "NO");
	}
}


Measured memory_bytes: 22732
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = [INT() for i in range(N)]

S = set(A)
C = Counter(A)

cnt = 0
for s in S:
    if C[s] % 2 != 0:
        cnt += 1
print(cnt)

Measured memory_bytes: 28288
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	N := nextInt()
	Q := nextInt()
	S := nextString()
	table := make([]int, N)
	table[0] = 0
	afterA := false
	if string(S[0]) == "A" {
		afterA = true
	}

	for i := 1; i < N; i++ {
		if string(S[i]) == "C" && afterA {
			table[i] = table[i-1] + 1
			afterA = false
		} else if string(S[i]) == "A" {
			afterA = true
			table[i] = table[i-1]
		} else {
			afterA = false
			table[i] = table[i-1]
		}
	}

	for i := 0; i < Q; i++ {
		l := nextInt()
		r := nextInt()
		fmt.Printf("%v\n", table[r-1]-table[l-1])
	}
}

func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}

func nextString() string {
	return nextReader()
}

func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func Min(a int, b int) int {
	if a > b {
		return b
	}
	return a
}

func MaxIn2Values(a int, b int) int {
	if a > b {
		return a
	}
	return b
}

func MinIn2Values(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

func Abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}


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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] In = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int k = int.Parse(Console.ReadLine());
            int a = In[0];
            int b = In[1];
            int c = In[2];
            int cnt = 0;
            while (a >= b)
            {
                b *= 2;
                cnt++;
            }
            while (b >= c)
            {
                c *= 2;
                cnt++;
            }
            if (k >= cnt) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 28284
#include <iostream>
#include <vector>
#define rep(a, b, c) for(int a=b;a<=N;a++)
using namespace std;
double dp[303][303][303];
//---------------------------------------------------------------------------------------------------
int main(int argc, char const *argv[]) {
  for(int i=0;i<=302;i++) for(int j=0;j<303;j++) for(int k=0;k<303;k++) dp[i][j][k] = 0;
    int N, C[4]={0, 0, 0, 0};
    cin >> N;
    int a;
    for(int i=0;i<N;i++) std::cin >> a, C[a]++;
    rep(c3, 0, N + 1) rep(c2, 0, N + 1) rep(c1, 0, N + 1) {
        int sm = c1 + c2 + c3;
        if (sm == 0) continue;
        dp[c1][c2][c3] = 1.0 * N / sm;
        if(c1>0) dp[c1][c2][c3] += dp[c1 - 1][c2][c3] * c1/sm;
        if(c2>0) dp[c1][c2][c3] += dp[c1 + 1][c2 - 1][c3] * c2/sm;
        if(c3>0) dp[c1][c2][c3] += dp[c1][c2 + 1][c3 - 1] * c3/sm;
    }
    printf("%.10f\n", dp[C[1]][C[2]][C[3]]);
    return 0;
}


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


int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n;
    cin>>n;
    vector<int> v(n);
    for(auto &i:v)        cin>>i;

    vector<int> dp(n);
    dp[n-1]=0;
    dp[n-2]=abs(v[n-1]-v[n-2]);

   for(int i=n-3 ; i>=0 ; i--)
    {
        int a = abs(v[i]-v[i+1]);
        int b = abs(v[i]-v[i+2]);
        dp[i] = min(a+dp[i+1] , b + dp[i+2]);
    }

    cout<< dp[0];


}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define tam 300010

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <ll, ll> dl;
typedef pair <int, int> ii;
typedef vector <ii> vii;
typedef vector <vi> graph;

bool comp(ll a, ll b) {
	return a > b;
}

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

    int n;
    cin >> n;
    ll arr[n];
    ll suma = 0;
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
        suma += arr[i];
    }
    ll suma2 = 0;
    for (int i = 0; i < n; i++) {
        suma2 += (arr[i] * (suma - arr[i]));
        suma -= arr[i];
    }
    cout << suma2 << "\n";
	return 0;
}

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

int main(){
  string A,B,C;
  cin >> A >> B >> C;
  if(A[A.size()-1] == B[0] && B[B.size()-1] == C[0]) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using static System.Console;
using static System.Math;
using System.Linq;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] tmp = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int N = tmp[0];
            int K = tmp[1];
            char[] S = ReadLine().ToCharArray();
            S[K - 1] = char.ToLower(S[K - 1]);

            WriteLine(string.Join("", S));
        }
    }
}

Measured memory_bytes: 13396