akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fi first
#define se second
#define endl '\n'
#define fn(i,x) for(i=0;i<x;i++)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define vii vector<int>
#define vll vector<ll>
#define mx 1e18
#define mod 1000000007
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define sii set<int>
#define sll set<ll>
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{io
int n;cin>>n;ll ans=0;
for(int i=1;i<=n;i++)
{
	if(i%3!=0&&i%5!=0)
	{
		ans+=i;
	}
}cout<<ans;


	


 
}


Measured memory_bytes: 3648
#include<iostream>
#include<iomanip>
#include<sstream>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<numeric>

using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define np string::npos
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define repc(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto n :(array))

typedef long long ll ;
typedef deque<int> di ;
typedef deque<ll> dl ;
typedef map<string,int> dict;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
const double PI = atan(1.0) * 4 ;
double eps = 1e-10 ;

template <typename T>
void out(deque < T > d)
{
  for(size_t i = 0; i < d.size(); i++)
  {
    debug(d[i]);
  }
}

template<typename T>
T ston(string str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string str,ans;
  int n;
  while(cin>>str){
    ans = "" ;
    rep(i,str.size()){
      if(str[i]=='@'){
        ++i;
        n = str[i] - '0' ;
        ++i;
        rep(j,n){
          ans += str[i] ;
        }
      }
      else{
        ans += str[i] ;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

int linear(int key,int a[],int n){

	a[n]=key;
	int i=0;
	
	while(a[i]!=key){
		i++;
	}
	if(i==n){
		return -1;
	}

	return i;
}

int main(){
	
	int n;
	cin>>n;
	
	int s[10001];
	for(int i=0;i<n;i++){
		cin>>s[i];
	}

	int x;
	cin>>x;
	
	int t[500];
	for(int i=0;i<x;i++){
		cin>>t[i];
	}

	int count=0;
	
	for(int i=0;i<x;i++){
		if(linear(t[i],s,n)!=(-1)){
			count++;
		}
	}
	cout<<count<<endl;
	
	return 0;
}
	

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

int ans[100005];

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  string s;cin>>s;
  int r=0;
  int l=-1;
  int rp=1;
  for(int i=1;i<s.size();i++){
    if(s[i]=='L'){
      int dist = (i-r);
      if(l==-1)l=i;
      if(dist%2==0){
        ans[r]++;
      }else{
        ans[l]++;
      }
      if(rp>0){
        ans[r] += rp/2;
        ans[l] += rp/2;
        ans[r] += rp%2;
      }
      rp=0;
    } else {
      rp++;
      r=i;
      l=-1;
    }
  }
  for(int i=0;i<s.size();i++){
    if(i)cout<<' ';
    cout<<ans[i];
  }
  cout<<endl;

  return 0;
}


Measured memory_bytes: 1104
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <set>

using namespace std;
typedef long long ll;

int main(){
    ll N,M;
    cin >> N >> M;
    vector<ll> L(M),R(M);
    for(int i=0;i<M;i++){
        cin >> L[i] >> R[i];
    }
    sort(L.rbegin(),L.rend());
    sort(R.begin(),R.end());
    //cout << L[0] <<" " << R[0] << endl;
    cout << max((ll)0,R[0]-L[0]+1) << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

using ll = long long;
using namespace std;
ll mod = 1e9 + 7;

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    REP(i, H) {
        cin >> S[i];
    }

    vector<vector<int>> L(H, vector<int>(W)), R(H, vector<int>(W)), U(H, vector<int>(W)), D(H, vector<int>(W));
    REP(h, H) {
        //右
        for (int w = W - 1; w >= 0; w--) {
            if (S[h][w] == '#') {
                R[h][w] = 0;
            }

            else if (w == W - 1) {
                R[h][w] = 1;
            }
            else {
                R[h][w] = R[h][w + 1] + 1;
            }
        }

        //左
        REP(w, W) {
            if (S[h][w] == '#') {
                L[h][w] = 0;
            }
            else if (w == 0) {
                L[h][w] = 1;
            }
            else {
                L[h][w] = L[h][w - 1] + 1;
            }
        }
    }

    REP(w, W) {
        //上
        REP(h, H) {
            if (S[h][w] == '#') {
                U[h][w] = 0;
            }
            else if (h == 0) {
                U[h][w] = 1;
            }
            else {
                U[h][w] = U[h - 1][w] + 1;
            }
        }
        //下
        for (int h = H - 1; h >= 0; h--) {
            if (S[h][w] == '#') {
                D[h][w] = 0;
            }
            else if (h == H - 1) {
                D[h][w] = 1;
            }
            else {
                D[h][w] = D[h + 1][w] + 1;
            }
        }
    }

    int ans = 0;
    REP(h, H) {
        REP(w, W) {
            ans = max(ans, L[h][w] + R[h][w] + U[h][w] + D[h][w] - 3);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 67200
#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 main(){
    int n, d;
    cin >> n >> d;
    if(n%(2*d+1)==0){
        cout << n/(2*d+1) << endl;
    }
    else{
        cout << n/(2*d+1)+1 << endl;
    }
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <set>
#include <cstdio>
using namespace std;

#define EPS (1e-10)
#define EQ(a,b) ((abs((a)-(b)))<EPS)

typedef complex<double> P;

struct edge{
	int to;
	double cost;
};

int n,m;
vector<edge> G[10001];
vector<edge> G2[10001];
P points[10001];
const double INF=1000000000;
double mincost[10001];
bool used[10001];

// _s©çÅ¬SæØðì¬
double prim(int s,int V){
	for(int i=0;i<V;i++)mincost[i]=INF;
	mincost[s]=0;
	double res=0;
	while(1){
		int v=-1;
		// xÉ®³È¢¸_Ì¤¿,x©çÌÓÌRXgªÅ¬ÆÈé_ð³ª·
		for(int u=0;u<V;u++)
			// Ü¾IÎêÄ¢È¢©ÂA»±ÖÌRXgªÅ¬
			if(!used[u]&&(v==-1||mincost[u]<mincost[v]))v=u;
		if(v==-1||EQ(mincost[v],INF))break;
		// xÉvðÇÁ
		used[v]=true;
		// vÖÌRXgðÁ¦é
		res+=mincost[v];
		// »ê¼êÌÓÖÌÅ¬RXgðXV
		for(int i=0;i<(int)G[v].size();i++){
			int u=G[v][i].to;
			mincost[u]=min(mincost[u],G[v][i].cost);
		}
	}
	return res;
}

int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		points[i]=P(x,y);
	}
	double sum=0;
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		b--;a--;
		edge e;
		e.to=b;
		e.cost=-abs(points[a]-points[b]);
		sum+=-e.cost;
		G[a].push_back(e);
		e.to=a;
		G[b].push_back(e);
	}
	double res=0;
	for(int i=0;i<n;i++){
		if(used[i])continue;
		res+=prim(i,n);
	}
	printf("%.10f\n",sum+res);
	return 0;
}

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

int main() {

  int N;
  cin >> N;

  map<string, int> s;
  string tmp;

  for(int i = 0; i < N; i++){
    cin >> tmp;
    s[tmp]++;
  }

  cout << "AC x " << s["AC"] << endl;
  cout << "WA x " << s["WA"] << endl;
  cout << "TLE x " << s["TLE"] << endl;
  cout << "RE x " << s["RE"] << endl;
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			int n=sc.nextInt();
			for(int i=0; i<n; i++) {
				String s=sc.next();
				String m=sc.next();
				int length=m.length();
				String m2="";
				for(int j=s.length()-1; j>=0; j--) {
					if(s.charAt(j)=='J') {
						for(int k=0; k<length; k++) {
							if(k==0) m2+=m.charAt(length-1);
							else m2+=m.charAt(k-1);
						}
						m=m2;
						m2="";
					}
					if(s.charAt(j)=='C') {
						for(int k=0; k<length; k++) {
							if(k==length-1) m2+=m.charAt(0);
							else m2+=m.charAt(k+1);
						}
						m=m2;
						m2="";
					}
					if(s.charAt(j)=='E') {
						if(length%2==1) {
							for(int k=length/2+1; k<length; k++) {
								m2+=m.charAt(k);
							}
							m2+=m.charAt(length/2);
							for(int k=0; k<length/2; k++) {
								m2+=m.charAt(k);
							}
						}else {
							for(int k=length/2; k<length; k++) {
								m2+=m.charAt(k);
							}
							for(int k=0; k<length/2; k++) {
								m2+=m.charAt(k);
							}
						}
						m=m2;
						m2="";
					}
					if(s.charAt(j)=='A') {
						for(int k=length-1; k>=0; k--) {
							m2+=m.charAt(k);
						}
						m=m2;
						m2="";
					}
					if(s.charAt(j)=='P') {
						for(int k=0; k<length; k++) {
							if(Character.isDigit(m.charAt(k))) {
								int num=m.charAt(k)-'0';
								num--;
								if(num<0) num=9;
								m2+=String.valueOf(num);
							}else {
								m2+=m.charAt(k);
							}
						}
						m=m2;
						m2="";
					}
					if(s.charAt(j)=='M') {
						for(int k=0; k<length; k++) {
							if(Character.isDigit(m.charAt(k))) {
								int num=m.charAt(k)-'0';
								num++;
								if(num>9) num=0;
								m2+=String.valueOf(num);
							}else {
								m2+=m.charAt(k);
							}
						}
						m=m2;
						m2="";
					}
				}
				System.out.println(m);
				
				
			}
			

		}
	}
}


Measured memory_bytes: 26328
#include<cstdio>
int main(){
    int n,a,b;
    char s;
    bool flag;
    scanf("%d%d%d\n",&n,&a,&b);
    for(int i=0;i<n;i++){
        scanf("%c",&s);
        flag=false;
        if(s=='a'){
            if(a>0){
                flag=true;
                a--;
            }else if(b>0){
                flag=true;
                b--;
            }
        }else if(s=='b'){
            if(b>0){
                flag=true;
                b--;
            }
        }
        printf("%s\n",(flag)?"Yes":"No");
    }
}

Measured memory_bytes: 512
for(;scanf("%d%d",&n,&k),n;){
    for(i=0;i<k;i++)scanf("%d",a+i);
    for(;n--;)
      for(i=0;i<k;a[i++]-=x)scanf("%d",&x);
    for(i=0;i<k&&a[i]>=0;i++);
    puts(k-i?"No":"Yes");
  }
  return 0;
}

Measured memory_bytes: 0
from itertools import product

N = int(input())

#2^N通りの全仮説　e.g. [[0,0],[0,1],[1,0],[1,1]]　0:不親切 1:正直
L = list(product([0,1], repeat=N))

T = [[]for i in range(N)]#証言
for i in range(N):
    A = int(input())
    for j in range(A):
        x, y = map(int, input().split())
        T[i].append((x, y))

ans= 0

for l in L:
  F  = True
  for i,katei in enumerate(l):
    if katei == 1:#正直者のみを確認(正直者でなければ証言は矛盾しても良い)
      for j in T[i]:#正直者のiさんの証言T[i]とlの整合性を確認
        #j[0]-1 :対象　j[1]: 証言内容　
        #l[j[0]-1]:　j[0]-1さんのが正直かの仮定
        if l[j[0]-1] != j[1]:#仮定lと証言が矛盾(iさんは正直者ではなかった)
          F = False
  if F:
    ans = max(ans,sum(l))
print(ans)

Measured memory_bytes: 8820
N = int(input())
lis = [list(map(int, input().split())) for i in range(N)]
A = 'No'
for j in range(N-2):
  if lis[j][0] == lis[j][1]:
    if lis[j+1][0] == lis[j+1][1]:
      if lis[j+2][0] == lis[j+2][1]:
        A = 'Yes'
        break
print(A)


Measured memory_bytes: 62576
n = int(input())
h = list(map(int,input().split()))
ans = "Yes"
for i in reversed(range(n-1)):
 
    if h[i] - h[i+1] >= 1:
        h[i] -= 1
    
    if h[i] - h[i+1] >= 1:
        ans = "No"
        break
        
print(ans)

Measured memory_bytes: 14396
#include <iostream>

using lint = long long;

void solve() {
    int n;
    std::cin >> n;

    lint ans = 0;
    for (int a = 1; a <= n; ++a) ans += (n - 1) / a;
    std::cout << ans << "\n";
}

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

    solve();

    return 0;
}


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

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

int main()
{
    int N;
    int A[100050] = {0};
    cin >> N;
    for (int i = 0; i < N; i++) cin >> A[i];

    int ans = 0;
    for (int i = 0; i < N; i++) {
        ans = gcd_i(ans, A[i]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#define N 2000000

int n, k, A[N], B[N], X[N];

int searchk(int X[], int n){
    int max = X[0], tmp;
    for(int i=1 ; i<n ; i++){
        if(max < X[i]){
            tmp = X[i];
            X[i] = max;
            max = tmp;
        }
    }
    return max;
}

void ContingSort(int A[], int B[], int k){
    int C[k];
    /*initialize 0 to k*/
    for(int i=0 ; i<k+1 ; i++)  C[i] = 0;
    /*A record 1 to n*/
    for(int i=0 ; i<n ; i++)    C[A[i]]++;
    /*under-A record 1 to k*/
    for(int i=1 ; i<k+1 ; i++)  C[i] += C[i-1];

    /*copying to B*/
    for(int i=n-1 ; i>=0 ; i--){
        B[C[A[i]]] = A[i];
        C[A[i]]--;
    }

}

int main(void){
    scanf("%d", &n);
    for(int i=0 ; i<n ; i++){
        scanf("%d", &A[i]);
        X[i] = A[i];    //useing searchk
    }
    int k = searchk(X, n);
    ContingSort(A, B, k);
    for(int i=1 ; i<n ; i++)
        printf("%d ", B[i]);
    printf("%d\n", B[n]);
    return 0;
    }



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

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> grid(h, vector<char>(w));
    rep(i, h) {
        rep(j, w) {
            cin >> grid.at(i).at(j);
        }
    }

    bool flg;
    rep(i, h) {
        flg = true;
        rep(j, w) {
            if(grid.at(i).at(j) == '#') {
                flg = false;
            }
        }
        if(flg) {
            rep(j, w) {
                grid.at(i).at(j) = 'o';
            }
        }
    }
    rep(j, w) {
        flg = true;
        rep(i, h) {
            if(grid.at(i).at(j) == '#') {
                flg = false;
            }
        }
        if(flg) {
            rep(i, h) {
                grid.at(i).at(j) = 'o';
            }
        }
    }

    rep(i, h) {
        int cnt = 0;
        rep(j, w) {
            if(grid.at(i).at(j) != 'o') {
                cout << grid.at(i).at(j);
            }
            else {
                cnt++;
            }
        }
        if(cnt < w) {
            cout << endl;
        }
    }
}


Measured memory_bytes: 3644
#include<stdio.h>
 
int main(){
  int height,width,area,circumference;

  scanf("%d", &height);
  scanf("%d", &width);
 
 area=height*width;
 circumference=height*2+width*2;
 
  printf("%d ",area);
  printf("%d\n",circumference);
  
  return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N,j=0;
        cin>>N;
    
    for(int i=0;i<N;i++){
        char S;
        cin>>S;
        if(S=='Y'){
            j++;
        }
    }
    
    if(j!=0){
        cout<<"Four"<<endl;
    }
    else{
        cout<<"Three"<<endl;
    }   
}

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

int main()
{
    int x, n, p, check[N] = {0}, min, sub = -1;

    scanf("%d %d", &x, &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &p);
        check[p] = 1;
    }

    if (n == 0)
    {
        printf("%d", x);
        return 0;
    }

    for (int i = 0; i < N; i++)
    {
        if (check[i] == 0)
        {
            if (abs(x - i) < sub || sub == -1)
            {
                min = i;
                sub = abs(x - i);
            }
        }
    }

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

Measured memory_bytes: 1716
#include <iostream>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <climits>
#include <numeric>
#include <queue>
#include <cmath>
#include <iomanip>
#include <array>
#include <string>
#include <stack>
#include <cassert>
#include <memory>


int main() {
	int n; std::cin >> n;
	std::vector<int> num(n); for (auto& a : num) std::cin >> a;
	const auto sum = std::accumulate(num.begin(), num.end(), 0);
	int min_cost{ INT_MAX };
	for (auto i = 0; i < 2; ++i) {
		const auto target = sum / n + i;
		int sum_cost{ 0 };
		for (const auto a : num) {
			sum_cost += (a - target) * (a - target);
		}
		min_cost = std::min(min_cost, sum_cost);
	}
	std::cout << min_cost << '\n';
}


Measured memory_bytes: 256
def main():
    MOD = 998244353
    N, S = map(int, input().split())
    A = list(map(int, input().split()))
    dp = [0] * (S + 1)
    ans = 0
    for i in range(N):
        dp[0] += 1
        dp2 = [0] * (S + 1)
        for j in range(S+1):
            dp2[j] += dp[j]
            if j + A[i] <= S:
                dp2[j + A[i]] += dp[j] 
                dp2[j + A[i]] %= MOD

        dp = dp2

        ans += dp[S]
        ans %= MOD

    
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 41452
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt(), sum = 0;
            int[] arr = new int[n];
            for (int i = 0; i < n; ++i) {
                arr[i] = in.nextInt();
                sum += arr[i];
            }
            if (sum % 10 != 0) {
                out.println(sum);
            } else {
                Arrays.sort(arr);
                for (int i = 0; i < n; ++i) {
                    if ((sum - arr[i]) % 10 != 0) {
                        out.println(sum - arr[i]);
                        return;
                    }
                }
                out.println(0);
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
int read(){
	int x=0,f=1;
	char ch=getchar();
	while (!isdigit(ch)&&ch!='-')
		ch=getchar();
	if (ch=='-')
		f=-1,ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x*f;
}
const int N=1050005;
int n,v;
int x[N];
int R[20][N],L[20][N],mR[N],mL[N];
int Max[N];
int main(){
	n=read(),v=read();
	for (int i=1;i<=n;i++)
		x[i]=read();
	int d;
	for (d=0;d<20;d++){
		int k=v>>d;
		for (int i=1,j;i<=n;i=j+1){
			for (j=i;j<n&&x[j+1]-x[j]<=k;j++);
			for (int k=i;k<=j;k++)
				L[d][k]=i,R[d][k]=j;
		}
		if (k==0)
			break;
	}
	for (int i=0;i<=d;i++)
		R[i][n+1]=n,L[i][0]=1;
	for (int i=0;i<(1<<d);i++)
		mR[i]=0,mL[i]=n+1;
	for (int i=1;i<(1<<d);i++)
		for (int j=0;j<d;j++)
			if (i>>j&1){
				mR[i]=max(mR[i],R[j+1][mR[i^(1<<j)]+1]);
				mL[i]=min(mL[i],L[j+1][mL[i^(1<<j)]-1]);
			}
	int base=(1<<d)-1;
	memset(Max,-1,sizeof Max);
	for (int i=0;i<(1<<d);i++){
		int x=i,y=i^base;
		Max[mL[x]]=max(Max[mL[x]],mR[y]);
	}
	for (int i=2;i<=n+1;i++)
		Max[i]=max(Max[i],Max[i-1]);
	for (int i=1;i<=n;i++){
		int l=L[0][i],r=R[0][i];
		puts(Max[r+1]>=l-1?"Possible":"Impossible");
	}
	return 0;
}

Measured memory_bytes: 90496
import math

while True:
    n = int(input())
    if n == 0:
        break
    s = [int(i) for i in input().split()]
    average = sum(s) / n
    dispersion = 0
    for i in range(n):
        dispersion += (s[i] - average) ** 2 / n
    dispersion = math.sqrt(dispersion)
    print("{:.8f}".format(dispersion))



Measured memory_bytes: 5712
import java.util.Scanner;
 
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int count = 0;
        for (int x = a; x <= b; x++){
             if(c % x == 0)count++;
        }
        System.out.printf("%d\n",count);
    }
}



Measured memory_bytes: 26356
#include<bits/stdc++.h>
#define mod 1000000007
#define INF 10000000000000001
#define F first
//#define S second
#define LB lower_bound
#define UB upper_bound
#define vc vector
#define vll vector<long long>
#define pll pair<long long,long long>
#define pb push_back
#define all(v) v.begin(),v.end()
#define T ll test;cin>>test; while(test--)
#define rep(i,a,n) for(ll i=a;i<(long long)n;++i)
#define repr(i,n,a) for(ll i=n;i>(long long)a;--i)
#define MAX 100005
#define sz(x) (ll)x.size()
#define ins insert
#define mp make_pair
#define int  long long
typedef long long ll;
typedef long double ld;
using namespace std;



signed  main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<max({b*c,b*d,a*c,a*d})<<endl;
}

Measured memory_bytes: 3644
#include<iostream>
using namespace std;
int main(){
	int a, b, c, rect = 0, rhom = 0;
	char d;
	while(cin >> a >> d >> b >> d >> c){
		if( a * a + b * b == c * c ) rect++;
		else if( a == b ) rhom++;
	}
	cout << rect << endl << rhom << endl;
}

Measured memory_bytes: 1160
import sys, itertools
input = sys.stdin.readline

def main():

    # d[i][j]は2頂点間i, j間の移動コストを格納, Vは頂点数
    def warshall_floyd(d, V):
        for k in range(V):
            for i in range(V):
                for j in range(V):
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j])

        return d # d[i][j]に頂点i, j間の最短距離を格納

    n,m,r = map(int,input().split())
    R = list(map(int,input().split()))
    for i in range(r):
        R[i] -= 1

    d = [[10**10] * n for _ in range(n)]
    for _ in range(m):
        a,b,c = map(int,input().split())
        d[a-1][b-1] = c
        d[b-1][a-1] = c

    d = warshall_floyd(d, n)
    ans = 10**10

    ptr = list(itertools.permutations(R, len(R))) # 順列列挙 5P3
    for i in ptr:
        tmp = 0
        for j in range(len(i)-1):
            tmp += d[i[j]][i[j+1]]
        ans = min(ans, tmp)

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 52700
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    int n;
    cin >> n;
    ll s[n + 1];
    s[0] = 0;

    repi(i, n + 1, 1)
    {
        int a;
        cin >> a;
        s[i] = a + s[i - 1];
    }
    sort(s, s + n + 1);
    ll ans = 0;
    repi(i, n + 1, 0)
    {

        ll cnt = 0;
        ll j = i;
        while(true)
        {
            if (s[i] == s[j])
                cnt++;
            else
            {
                i = j - 1;
                break;
            }
            j ++ ;
            if(j >= n + 1){
                i = j - 1;
                break;
            }
        }
        ans += cnt * (cnt - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main(){
	int k;
	cin >> k;
	cout << a[k-1] << endl;
	return 0;
}

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

using namespace std;

int main(){
  int le[4]={0},re[4]={0};
  double l,r;

  while(cin>>l>>r){
    if(l>=1.1)
      le[0]++;
    else if (l>=0.6 && l<1.1)
      le[1]++;
    else if (l>=0.2 && l<0.6)
      le[2]++;
    else
      le[3]++;

    if(r>=1.1)
      re[0]++;
    else if (r>=0.6 && r<1.1)
      re[1]++;
    else if (r>=0.2 && r<0.6)
      re[2]++;
    else
      re[3]++;
  }

  for(int i=0;i<4;i++){
    cout<<le[i]<<" "<<re[i]<<endl;
  }

  return 0;
}



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 5;
ll a[maxn];
int main() {
	int n;
	cin >> n;
	ll sum1 = 0, sum2 = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		sum1 += a[i]; sum2 += a[i] * a[i];
	}
	ll x1 = sum1 / n;
	ll x2 = sum1 / n + 1;
	if (2 * sum1 < n * (2 * x1 + 1)) {
		cout << sum2 - 2 * sum1 * x1 + n * x1 * x1 << endl;
	} else {
		cout << sum2 - 2 * sum1 * x2 + n * x2 * x2 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr int INF = 2147483000;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    int N;cin >> N;
    int F[N][10];
    REP(i,N) REP(j,10) cin >> F[i][j];
    int P[N][11];
    REP(i,N) REP(j,11) cin >> P[i][j];
    int ans = -1 * INF;
    REPP(bit,1,(1 << 10)){
        int now = 0;
        REP(i,N){
            int cnt = 0;
            REP(j,10){
                if(F[i][j] == 1) if(bit & (1 << (9 - j))){
                    cnt++;
                }
            }

            now += P[i][cnt];
        }

        ans = max(ans,now);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(){
    int i,count=0,n;
    char a[6];
    scanf("%s",a);
    n=strlen(a);
    for(i=0;i<n-2;i++){
        if(a[i]==a[i+1] && a[i]==a[i+2]){
           count++;
           break;
        }
    }
    if(count!=0) printf("Yes\n");
    else printf("No\n");
    return 0;
}


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

#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({a*c, a*d, b*d, b*c}) << endl;
}


Measured memory_bytes: 3604
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
int memo[32][32][32];
int solve(int a, int b, int c){
  if(memo[a][b][c]) return memo[a][b][c];
  if(a * 200 + b * 300 + c * 500 > n) return 999999999;
  if(a * 200 + b * 300 + c * 500 == n) return 0;
  int ret = 999999999;
  ret = min(ret, min(solve(a + 1, b, c) + 380, solve(a + 5, b, c) + (int)(380 * 5 * 0.8)));
  ret = min(ret, min(solve(a, b + 1, c) + 550, solve(a, b + 4, c) + (int)(550 * 4 * 0.85)));
  ret = min(ret, min(solve(a, b, c + 1) + 850, solve(a, b, c + 3) + (int)(850 * 3 * 0.88)));
  return memo[a][b][c] = ret;
}
int main(void){
  for( ; ; ){
    scanf("%d", &n);
    if(!n) break;
    memset(memo, 0, sizeof(memo));
    printf("%d\n", solve(0, 0, 0));
  }
}


Measured memory_bytes: 1168
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<bitset>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

int N, M;
vector<vector<pair<int,int>>> tree;
vector<pair<int,int>> edge;
vector<int> temp, con;

bool dfs(int now, int per, int tar, int num){
	// cout<<"now = "<<now<<" tar = "<<tar<<endl;
	if(tar == now) {
		// cout<<"[][] "<<endl;
		return true;
	}
	
	bool flag = false;
	
	for(pair<int,int> next : tree[now]){
		if(per == next.first) continue;
		bool flag2 = dfs(next.first, now, tar, num);
		
		if(flag2) {
			// cout<<"<><> "<<endl;
			temp[next.second] |= (1<<num);
			flag = true;
		}
	}
	
	
	return flag;
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int ans = 0;
	
	cin>>N;
	
	tree.resize(N);
	edge.resize(N-1);
	temp.resize(N-1);
	
	for(int i = 0; i < N - 1; i++){
		int a, b;
		
		cin>>a>>b;
		
		a--, b--;
		
		tree[a].push_back({b, i});
		tree[b].push_back({a, i});
		
		edge.push_back({a,b});
	}
	
	cin>>M;
	
	con.resize(1ll<<M);
	
	for(int i = 0; i < M; i++){
		int u, v;
		
		cin>>u>>v;
		
		u--, v--;
		
		dfs(u, -1, v, i);
	}
	
	// for(int i = 0; i < N-1; i++){
		// cout<<"i = "<<i<<" "<<bitset<10>(temp[i])<<endl;
	// }
	
	for(int i = 1; i < (1<<M); i++){
		for(int j = 0; j < N-1; j++){
			if(!(temp[j]&i)) con[i]++;
		}
		con[i] = 1ll<<con[i];
	}
	
	con[0] = 1ll<<(N-1);
	
	for(int i = 0; i < (1<<M); i++){// cout<<i<<" "<<con[i]<<endl;
		int c = 0, t = i;
		
		while(t){
			if(t&1) c++;
			t >>= 1;
		}
		
		if(c%2 == 0) ans += con[i];
		else ans -= con[i];
	}
	
	// cout<<"ans "<<endl;
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 8448
#include<iostream>
using namespace std;
int main()
{
  int n,m;
  cin>>n>>m;
  int t=0,k=0;
  if(n>1)
     t=(n*(n-1)/2);
  if(m>1)
    k=(m*(m-1)/2);
  cout<<t+k;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
 
int main() {
 	int N, L;
  	cin >> N >> L;
  	string S[N];
  
	for(int i=0; i<N; i++){
      cin >> S[i];
    }
  	sort(S, S+N);
	for(int i=0; i<N; i++){
      cout << S[i];
    }
}

Measured memory_bytes: 256
/**
 *    author:  math2do
 *    created: 21.12.2019 00:03:29
**/

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  vector <int> arr = {1, 2, 3};
  int com = 0;
  for (int val : arr) com ^= val;
  com ^= a;
  com ^= b;
  cout << com << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll MOD = 1e9+7;
const static ll INF = 1e14;

//素数判定
bool isPrime(int x){
    int i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

int main() {
    ll N, M, M_; cin >> N >> M;
    if(N == 1){
        cout << M << endl;
        return 0;
    }
    M_ = M;
    vector<ll> P = {1};
    for(int i = 2; i*i < M; i++){
        if(M % i == 0) {
            P.push_back(i);
            P.push_back(M/i);
        }
    }
    ll ans = 0;
    for(auto p : P){
        if(p*N <= M_) ans = max(ans, p);
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
n = gets.to_i
arr = n.times.map{gets.split}

$root = {}
$none = {}

def tree_minimum(x)
  while x[:left] != $none
    x = x[:left]
  end
  x
end

def find(u, k)
  while u != $none && k != u[:key]
    if k < u[:key]
      u = u[:left]
    else
      u = u[:right]
    end
  end
  u
end

def tree_successor(x)
  if x[:right] != $none
    return tree_minimum(x[:right])
  end

  y = x[:parent]

  while y != $none && x == y[:right]
    x = y
    y = y[:parent]
  end
  y
end

def tree_delete(z)
  if z[:left] == $none || z[:right] == $none
    y = z
  else
    y = tree_successor(z)
  end

  if y[:left] != $none
    x = y[:left]
  else
    x = y[:right]
  end

  if x != $none
    x[:parent] = y[:parent]
  end

  if y[:parent] == $none
    $root = x
  else
    if y == y[:parent][:left]
      y[:parent][:left] = x
    else
      y[:parent][:right] = x
    end
  end

  if y != z
    z[:key] = y[:key]
  end
end

def insert(k)
  y = $none
  x = $root
  z = {}

  z[:key] = k
  z[:left] = $none
  z[:right] = $none

  while x != $none
    y = x
    if z[:key] < x[:key]
      x = x[:left]
    else
      x = x[:right]
    end
  end

  z[:parent] = y
  if y == $none
    $root = z
  else
    if z[:key] < y[:key]
      y[:left] = z
    else
      y[:right] = z
    end
  end
end

def inorder(u)
  return if u[:key].nil?
  inorder(u[:left])
  print " #{u[:key]}"
  inorder(u[:right])
end

def preorder(u)
  return if u[:key].nil?
  print " #{u[:key]}"
  preorder(u[:left])
  preorder(u[:right])
end

arr.each do |a|
  if a[0][0] == 'f'
    t = find($root, a[1].to_i)
    puts (t != $none) ? 'yes' : 'no'
  elsif a[0] == 'insert'
    insert(a[1].to_i)
  elsif a[0] == 'print'
    inorder($root)
    print "\n"
    preorder($root)
    print "\n"
  elsif a[0] == 'delete'
    tree_delete(find($root, a[1].to_i))
  end
end


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

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	
	int n;
	cin >> n;

	vector< int> ans(n);
	for (int i = 1; i < n; i++) {
		int x;
		cin >> x;
		ans[x - 1]++;
	}

	for (int x : ans) cout << x << "\n";
}

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


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string S;
	cin >> S;
	ll p = 0;
	vector<ll> B(0);
	rep(i, S.size()) {
		if (S.at(i) == 'W') p++;
		else B.push_back(i);
	}
	ll s = 0;
	ll ans = 0;
	rep(i, S.size()) {
		if (S.at(i) == 'W' && i > p - 1) {
			ans += i - B[s];
			s++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 2700
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int m = sc.nextInt();
    int c = sc.nextInt();

    int[] array1 = new int[m];
    int[] array2 = new int[m];
    int sum = 0;
    int count = 0;

    for(int i=0; i<m; i++){
      array2[i] = sc.nextInt();
    }

    for(int i=0; i<n; i++){
      for(int j=0; j<m; j++){
        array1[j] = sc.nextInt();
        sum += array1[j] * array2[j];
      }
      sum += c;
      if(sum>0){
        count +=1;
      }
      sum =0;
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 22356
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
道路間の中でも最短＝直通
短いほうからとっていけばOKか

ちがった・・・
全部いれてからWFで、まず-1判定
そのあと、使ってない直通を消すんだけど、どうすればいいかな
そのほうしんであってそう

A 0 10 12 20
B 10 0 23 30
C 12 23 0 26
D 20 30 26 0
頂点ごとに、最短だけとるってこと？
CDの26をはらないとだめだからそうでもなさそう

あああ意味わかった
まず全部つなぐ
中継したほうが小さい、はありえないから-1
同じなら直通はぶく

はぶいてからやりなおさなくていい？
あってもなくても同じだから別に、か

*/
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll N,ans=0; cin>>N;
  vector<vector<ll>> A(310,vector<ll>(310,0)),B(310,vector<ll>(310,1));
  for(ll i=0; i<N; i++) for(ll j=0; j<N; j++) cin>>A[i][j];
  for(ll k=0; k<N; k++) for(ll i=0; i<N; i++) for(ll j=0; j<N; j++){
    ll z=A[i][k]+A[k][j];
    if(A[i][j]>z){
      cout<<-1<<endl;
      return 0;
    }
    if(A[i][j]==z && k!=i && k!=j) B[i][j]=0;
  }
  for(ll i=0; i<N; i++) for(ll j=i+1; j<N; j++)ans+=A[i][j]*B[i][j];
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;
const int MAX=100000;
int n;
vector< pair<int,int> >G[MAX];
vector<int>dia;
int deg[MAX];
bool V[MAX];
void dfs(int u)
{
    int S[MAX],top=0,maxu=0;
    long long maxd=0,sum=0;
    int j;
    S[top++]=u;
    V[u]=true;
    while(top!=0){
        int i=S[top-1];
        for(j=0;j<G[i].size();j++)
        {
            int v=G[i][j].first;
            if(!V[v]){
                S[top++]=v;
                V[v]=true;
                sum+=G[i][j].second;
                break;
            }
        }
        if(j>=G[i].size()){
            if(deg[i]==1) {
                //maxd = max(maxd, sum);
                if(sum>=maxd){
                    maxd=sum;
                    maxu=i;
                }
            }
            if(top>1)
                for(int k=0;k<G[S[top-2]].size();k++)
                    if(G[S[top-2]][k].first==i){
                        sum-=G[S[top-2]][k].second;
                        break;
                    }
            top--;
        }
    }
    //cout<<maxd<<endl;
    dia.push_back(maxu);
    dia.push_back(maxd);

}
int main()
{
    int s,t,w;
    cin>>n;
    for(int i=0;i<n;i++){
        deg[i]=0;
        V[i]=false;
    }
    for(int i=0;i<n-1;i++)
    {
        cin>>s>>t>>w;
        G[s].push_back(make_pair(t,w));
        G[t].push_back(make_pair(s,w));
        deg[s]++;
        deg[t]++;
    }
    dfs(0);
    for(int i=0;i<n;i++){
        //deg[i]=0;
        V[i]=false;
    }
    dfs(dia[0]);
    cout<<dia[3]<<endl;
    return 0;
}


Measured memory_bytes: 9836
#include<stdio.h> 

int main (void) 
{   
	int m,f,r;  
	while(1)
	{     
		scanf("%d%d%d",&m,&f,&r);    
		if((m==-1)&&(f==-1)&&(r==-1))
			break;    
		if((m==-1||f==-1)||((m+f)<30))
		{       
			printf("F\n");    
		}
		else if(80<=(m+f))
		{      
			printf("A\n");          
		}
		else if(65<=(m+f)&&(m+f)<80)
		{       
				printf("B\n");      
		}
		else if(50<=(m+f)&&(m+f)<65)
		{       
				printf("C\n");       
		}
		else if(50<=r)
		{      
				printf("C\n"); 
		}
		else if(((m+f)<50)&&((m+f)>=30))
		{    
			printf("D\n");       
		}      
	}     
	return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD=1000000007;
const long double PI=3.14159265358979;

int main() {
  string s;
  cin>>s;
  if(s=="ABC"){
    cout<<"ARC";
  }
  else{
    cout<<"ABC";
  }
}


Measured memory_bytes: 3624
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
 
        while(sc.hasNext()){
            String op = sc.next();
            char[] s1 = sc.next().toCharArray();
            char[] s2 = sc.next().toCharArray();
 
            s = "";
            int p1 = 0, p2 = 0;
            int l1 = s1.length, l2 = s2.length;
            while(p1 < l1 && p2 < l2){
                if(s1[p1] == s2[p2]){
                    s += s1[p1];
                    p1++;
                    p2++;
                }
                else if(s1[p1] == '('){
                    p1 = read(s1,p1,(op.equals("u") ? true : false));
                }
                else{
                    p2 = read(s2,p2,(op.equals("u") ? true : false));
                }
            }
 
            if(op.equals("u")){
                while(p1 < l1) s += s1[p1++];
                while(p2 < l2) s += s2[p2++];
            }
 
            System.out.println(s);
        }
    }
 
    private static String s;
 
    private static int read(char[] t,int p,boolean flg){
        int level = 0;
        do{
            if(flg) s += t[p];
            if(t[p] == '(') level++;
            else if(t[p] == ')') level--;
            p++;
        }while(level != 0);
        return p;
    }
}

Measured memory_bytes: 26020
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

int n;

bool query(string s) {
  cout << "? " << s << endl;
  string ret;
  cin >> ret;
  if(ret == "Y") return true;
  else return false;
  /*if((stoll(s) <= n && s <= to_string(n))
    || (stoll(s) > n && s > to_string(n))) {
    cout << "Yes" << endl;
    return true;
  }
  cout << "No" << endl;
  return false;*/
}

signed main(void)
{
  // cin >> n;
  // int nn;
  // cin >> nn;
  // REP(cc, nn) {
  // n = cc+1;
  // Nが何桁か特定する
  int cnt = 1, num = -1;
  REP(i, 10) {
    if(!query(to_string(cnt))) {
      num = i+1;
      break;
    }
    cnt *= 10;
  }
  // 1, 10, 100, … の判定
  if(num == -1) {
    string s = "9";
    bool flag = false;
    REP(i, 9) {
      if(query(s)) {
        cout << "! 1" + string(i, '0') << endl;
        // flag = true;
        // break;
        return 0;
      }
      s += '9';
    }
    // if(flag) continue;
    cout << "! 1000000000" << endl;
    return 0;
  }

  //i桁目をにぶたんで決定
  string ans(num, '0');
  REP(i, num-1) {
    int l = 0, r = 10;
    while(r-l>1) {
      int m = (l+r)/2;
      // cout << l << " " << m << " " << r << endl;
      string t = ans;
      t[i] = char(m + '0');

      if(query(t)) {
        r = m;
      } else {
        l = m;
      }
    }
    ans[i] = (char)(l+'0');
  }

  ans = ans.substr(0, ans.size()-1);
  cout << "! " << stoll(ans) + 1 << endl;
  // if(cc+1 != stoi(ans) + 1) cout << "///" << cc+1 << endl;
  // }

  return 0;
}


Measured memory_bytes: 660
#include <stdio.h>

int		main()
{
	int		N, now;
	int		count;
	int		min;
	int		i;

	i = 0;
	count = 0;
	min = 0;
	scanf("%d\n", &N);
	while(i < N)
	{
		i++;
		if (i == N)
			scanf("%d\n", &now);
		else
			scanf("%d ", &now);
		if (i == 1 || now < min)
		{
			count++;
			min = now;
		}
	}
	printf("%d\n", count);
	return (0);
}


Measured memory_bytes: 128
#include <ext/pb_ds/assoc_container.hpp> 	// Common file
#include <ext/pb_ds/tree_policy.hpp> 		// Including tree_order_statistics_node_update
#include<bits/stdc++.h>
#define int            		long long
#define x              		first
#define y              		second
#define all(aaa)       		(aaa).begin(),(aaa).end()
#define REP(i,sss,eee) 		for(int i=sss;i<=eee;++i)
#define pb             		push_back
#define pii            		pair<int,int>
#define vi             		vector<int>
#define speed          		ios_base::sync_with_stdio(0);cin.tie(0);
#define N              		1000000007
#define inf					1000000000000000000
using namespace __gnu_pbds;
using namespace std;
template <class T>
T MAX(T a, T b){return ((a>b)?a:b);}
template <class T>
T MIN(T a, T b){return ((a<b)?a:b);}
template <class T>
T MOD(T a){return ((a>=0)?a:(-1*a));}
template <class T>
void SWAP(T &a,T &b){T temp=a;a=b;b=temp;}

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

inline int ex(int a, int b){
	if(b==0||a==1){return 1;}
	if(a==0||b==1){return a;}
	int tmp=ex(a,(b/2));
	if(b%2){return ((((tmp*tmp)%N)*a)%N);}
	else{return ((tmp*tmp)%N);}
}
inline int inv(int k){
	if(k==1){return 1;}
	else{return ex(k,N-2);}
}
/*****************default********************/
int solve()
{
	string str;cin>>str;
	int zro=0,one=0,n=str.length();
	for(auto it:str)
	{
		if(it=='0'){++zro;}
		else{++one;}
	}
	cout<<(n-MAX(zro,one)+MIN(zro,one))<<"\n";
}
signed main(){
	speed
	int tt=1;
	//cin>>tt;
	while(tt--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstdlib>
#include<map>
#include<vector>
#include<ctime>
#include<stack>
#define mp make_pair
#define pa pair<int,int>
#define INF 0x3f3f3f3f
#define inf 0x3f
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ull unsigned long long

using namespace std;

inline ll read()
{
	long long f=1,sum=0;
	char c=getchar();
	while (c<'0' || c>'9')
	{
		if (c=='-')	f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9')
	{
		sum=sum*10+c-'0';
		c=getchar();
	}
	return sum*f;
}
const int MAXN=200010;
int a[MAXN],b[MAXN];
int main()
{
	int n;
	scanf("%d",&n);
	int minn=INF;
	ll ans=0;
	for (int i=1;i<=n;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
		ans+=a[i];
		if (a[i]>b[i])
			minn=min(minn,b[i]);
	}
/*	for (int i=1;i<=n;i++)
		cout<<a[i]<<' '<<b[i]<<endl;*/
	if (minn!=INF) cout<<ans-minn;
	else cout<<0;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h> 
 
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<long, long> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
const double EPS=1e-10;

LL fc(vector<LL>&B,LL num){
    LL res=0;
    REP(i,SZ(B))res+=num^B[i];
    return res;
}
int main(){
    LL N,K;
    cin>>N>>K;vector<LL>A(N);
    vector<int>C(100,0);
    int maxcc=0;
    REP(i,N){
        LL t;
        cin>>t;A[i]=t;
        int cc=0;
        while(t!=0){
            maxcc=max(maxcc,cc);
            C[cc]+=(t%2);
            cc++;
            t/=2;
        }
    }
    /*REP(i,K+1){
        cout<<fc(A,i)<<" "<<i<<endl;
    }*/
    int cnt=1;
    LL tt=1;
    while(tt*2LL<=K){
        tt*=2LL;cnt++;
    }
    LL res=0;
    REP(cc,cnt){
        if(C[cnt-cc-1]<=N/2){
            if(res+pow(2,cnt-cc-1)<=K)res+=pow(2,cnt-cc-1);
        }
    }
    //cout<<res<<endl;
    cout<<fc(A,res)<<endl;
    return 0;
}
/*
4 8
7 4 1 3
*/

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-


if __name__ == '__main__':
    n, m = map(int, input().split())
    C = [int(x) for x in input().split()]
    T = [float("inf") for _ in range(n+1)]
    T[0] = 0

    for i in range(m):
        for j in range(C[i], n+1):
            T[j] = min(T[j], T[j - C[i]] + 1)

    print(T[n])



Measured memory_bytes: 7652
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(d)]
sat = 0
last = [0]*26
for i in range(d):
  t = int(input())
  sat += s[i][t-1]
  last[t-1]=i+1
  for j in range(26):
    sat -= c[j]*(i+1-last[j])
  print(sat)


Measured memory_bytes: 69804
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 55);

int main(){
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n, vector<int>(n, 0));
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    g[a][b] = 1;
    g[b][a] = 1;
  }
  vector<int> v(n);
  rep(i,n) v[i] = i;
  int res = 0;
  do {
    int ok = 1;
    for (int i = 0; i < n-1; i++) {
      ok &= (g[v[i]][v[i+1]]);
    }
    res += ok;
  } while (next_permutation(v.begin() + 1, v.end()));
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256