akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

ll gcd(ll x, ll y){ return y==0? x: gcd(y, x%y); }

int main(){
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	
	VI a(n), t(n);
	rep(i, n) cin >>t[i] >>a[i];
	
	ll aa = 1, tt= 1;
	rep(i, n){
		ll wt = (tt + t[i] -1)/t[i];
		ll at = (aa + a[i] -1)/a[i];
		tt = max(wt, at) * t[i];
		aa = max(wt, at) * a[i];
		
	}
	
	cout << aa + tt <<"\n";
	
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	public static void main(String[] args) {
		String S=sc.next();
		int v[]=new int[200];
		boolean x=true;
		for(int i=0;i<3;i++) {
			if(v[S.charAt(i)]==1) {
				x=false;
				break;
			}
			v[S.charAt(i)]++;
		}
		if(x)p("Yes");
		else p("No");
		
	}
	
	
	
	
	/*static boolean v(int i,long sum1,long sum2) {
		if(i==N) {
			long b=Math.abs(sum1-sum2);
			if(b==0) {
				if(sum1<=K) {
					return true;
				}else return false;
			}else if(b%D==0) {
				if(Math.max(sum1, sum2)<=K)return true;
				else return false;
			}
			else return false;
		}
		
		if(v(i+1,sum1,sum2+v[i]%D))return true;
		
		if(v(i+1,sum1+D-v[i]%D,sum2))return true;
		return false;
		
	}*/
	
	
	
	
	

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<int> in(N,0);
  vector<vector<int>> G(N,vector<int>(0));
  vector<vector<int>> P(N,vector<int>(0));  
  for(int i=0; i<N+M-1; i++){
    int a, b;
    cin >> a >> b;
    a--; b--;
    G.at(a).push_back(b);
    P.at(b).push_back(a);
    in[b]++;
  }
  queue<int> Q;
  vector<int> topo(0);
  for(int i=0; i<N; i++){
    if(in[i] == 0){
      Q.push(i);
      topo.push_back(i);
    }
  }
  while(Q.size()){
    int x = Q.front();
    Q.pop();
    for(int i=0; i<G[x].size(); i++){
      in[G[x][i]]--;
      if(in[G[x][i]] == 0){
        Q.push(G[x][i]);
        topo.push_back(G[x][i]);
      }
    }
  }
  
  vector<int> idx(N);
  for(int i=0; i<N; i++){
    int x = topo[i];
    idx[x] = i;
  }
  
  vector<int> par(N,-1);
  for(int i=0; i<N; i++){
    int t = topo[i];
    if(i == 0){
      par[t] = 0;
    }
    else{
      int IDX = -1;
      for(int j=0; j<P[t].size(); j++){
        IDX = max(IDX, idx[P[t][j]]);
      }
      par[t] = topo[IDX]+1;
    }
  }
  for(int i=0; i<N; i++){
    cout << par[i] << endl;
  }                                
}

Measured memory_bytes: 13436
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): return k.join(list(map(str, lst)))
INF = float('inf')

def solve():
    r = II()
    print(r ** 2)


if __name__ == '__main__':
    solve()


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

int n, m, ans;
bool G[10][10];
bool used[10];

int dfs(int num, bool used[]){
    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(used[i]) cnt++;
    }
    //~~???
    if(cnt == n){
        return 1;
    }

    int ans = 0;
    for(int i = 0; i < n; i++){
        if(!(G[num][i]) or used[i]){
            continue;
        }
        used[i] = true;
        ans += dfs(i, used);
        used[i] = false;
    }
    return ans;
}

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

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

    used[0] = true;

    cout << dfs(0, used) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define us unsigned short int
#define fin freopen("/home/imtiaz/Desktop/in.txt", "r", stdin)
#define fout freopen("/home/imtiaz/Desktop/out.txt","w", stdout)
#define dbg(x) cerr << #x << ": " << x << endl
#define fastio ios::sync_with_stdio (false); cin.tie (0);
using namespace std;


int main(){
    ll n;
    cin>>n;
    ll ac,wa,tle,re;
    ac=wa=tle=re=0;
    string s;
    for (ll i = 0; i < n; i++)
    {
        cin>>s;
        if(s=="AC") ac++;
        else if(s=="WA") wa++;
        else if(s=="TLE") tle++;
        else re++;
    }
    printf("AC x %lld\n",ac);
    printf("WA x %lld\n",wa);
    printf("TLE x %lld\n",tle);
    printf("RE x %lld\n",re);

        return 0;
}

Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr char sp=' ';
constexpr ll mod=1000000007;

int k,q,d[5000];

int main(){
	cin>>k>>q;
	for(int i=0;i<k;i++){
		cin>>d[i];
	}
	while(q--){
		ll n,x,m;
		ll a=0;
		cin>>n>>x>>m;
		ll s,t;
		s=t=0;
		for(int i=0;i<k;i++){
			t+=d[i]%m;
			if(d[i]%m==0)a++;
		}
		x%=m;
		s=x+t*((n-1)/k);
		a*=(n-1)/k;
		for(int i=0;i<(n-1)%k;i++){
			s+=d[i]%m;
			if(d[i]%m==0)a++;
		}
		cout<<n-a-1-s/m<<endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,a,b;
  cin>>n;
  if(n==1)
  {
    cout<<"Hello World\n";
    return 0;//直接结束程序
  }
  //注意：此处可以不加else
  cin>>a>>b;
  cout<<a+b<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    long k;
    cin >> k;
    int a[n];
    for(int i=0;i<n;i++)cin >> a[i];
    vector<set<int> >num(200001);
    for(int i=0;i<n;i++){
        if(num[a[i]].empty()){
            num[a[i]].insert(i);
            num[a[i]].insert(i + n);
        }else{
            num[a[i]].insert(i);
        }
    }
    int repeat = 0;
    int cur = 0;

    // for(int i=0;i<=200000;i++){
    //     for(int j:num[i]){
    //         cout << j << endl;
    //     }
    // }
    
    while(k>=2){
        int now = a[cur];
        // auto it = upper_bound(num[now].begin(),num[now].end(),now);
        auto it = num[now].upper_bound(cur);
        int next = *it;

        // cout << now << " "<<cur<<" "<<k<<endl;


        if(next >= n){
            k--;
            next%=n;
            repeat++;
        }
        
        
        
        if(next == n-1){
            k--;
            repeat++;
            k%=repeat;
            cur = 0;
        }else{
            cur = next+1;
        }
        


        


    }

    vector<int>ans;

    while(cur<n && k>0){
        int now = a[cur];
        // auto it = upper_bound(num[now].begin(),num[now].end(),now);
        auto it = num[now].upper_bound(cur);
        int next = *it;
        // int next = (int)(it - num[now].begin());
        if(next >= n){
            ans.push_back(now);
            cur++;
        }else{
            cur = next+1;
        }

        // cout << now << " "<<cur<<endl;
    }
    if(ans.size()==0)cout<<endl;
    else if(ans.size()==1)cout<<ans[0]<<endl;
    else{
        for(int i=0;i<ans.size()-1;i++)cout<<ans[i]<<" ";
        cout<<ans[ans.size()-1]<<endl;
    }
    
    
}

Measured memory_bytes: 31352
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vi vector <ll> 
#define qu queue <ll>
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e9;
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


void solve()
{
    int K; cin >> K; ll s=0;
    for (int i=1; i<=K; i++) {
        for (int j=1; j<=K; j++) {
            for (int k=1; k<=K; k++) s+=__gcd(__gcd(i,j),k);
        }
    }
    nout(s);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define pb push_back
#define ll long long 
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1; 
    for(int T = 0; T < t ; T++){
        ll ans = 0;
        string s, t;
        cin >> s >> t;
        for(int i = 0; i < s.size(); i++){
            if(s[i] != t[i])
                ans++;
        }
        std::cout << ans << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
  int n;
  cin >> n;
  string s;
  cin >> s;
  if (n%2 == 1)
  {
    cout << "No";
    return 0;
  }
  string t;
  for (int i=0;i<n/2;i++)
    	t += s[i];
  t += t;
  if (t == s)
    cout << "Yes";
  else
    cout << "No";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;
ll mod = pow(10,9) + 7;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}


int main(void){
    string A,B,C; cin >> A >> B >> C;
    
  
  char x = A[0];
 
  
   while( A.size() != 0 || B.size() != 0 || C.size() != 0){
    if(x == 'a'){ 
     if( A.size() == 0){ cout << 'A' << endl; return 0;}
       x = A[0];  A = A.substr(1,A.size() - 1);}
   
    else if(x == 'b'){ 
      if(B.size() == 0){ cout << 'B' << endl; return 0;}
      x = B[0]; B = B.substr(1,B.size() - 1);}
   
    else if(x == 'c'){ 
      if(C.size() == 0){ cout << 'C' << endl; return 0;}
      x = C[0]; C = C.substr(1,C.size() - 1);}
  }
}


Measured memory_bytes: 256
from collections import deque
import sys

input = sys.stdin.readline

N = int(input())
e = [[] for _ in range(N)]
# 隣接リスト

for _ in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    e[a].append(b)
    e[b].append(a)


# BFS*2で直径を求める
def bfs(i):
    """
    :param i: bfsの始点, 0-indexed
    :return: (v,d), iの最遠点vまでの距離d
    """
    dist = [-1 for _ in range(N)]
    dist[i] = 0

    q = deque((i,))
    while q:
        v = q.popleft()
        d = dist[v]
        for nv in filter(lambda x: dist[x] == -1, e[v]):
            dist[nv] = d + 1
            q.append(nv)
    return v, d


x, _ = bfs(0)
_, d = bfs(x)

print('Second' if d % 3 == 1 else 'First')


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

using namespace std;

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

    int a,b;
    cin>>a>>b;
    
    if(a<=9 && b<=9)
        cout<<a*b;
    else 
        cout<<"-1";
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Set;
import java.util.HashSet;
import java.util.Arrays;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) throws Exception {
        
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        br.readLine();
        Set<Integer> s = Arrays.stream(br.readLine().split(" ")).map(Integer::parseInt).collect(Collectors.toSet());
        br.readLine();
        Set<Integer> t = Arrays.stream(br.readLine().split(" ")).map(Integer::parseInt).collect(Collectors.toSet());
        
        s.retainAll(t);
        System.out.println(s.size());
    }
}


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

#define mod 1000000007
#define fer( a , b , c ) for( register int a = b ; a <= c ; a ++ )
#define der( a , b , c ) for( register int a = b ; a >= c ; a -- )

  using namespace std ;
  
long long n ;
long long f[ 1000005 ][ 4 ] ;

inline long long Mul( int a , int b ){
    long long ans = 1 , base = a ;
    while( b != 0 ) {
        if( b & 1 ){
            ans *= base ;
            ans = ans % mod ;
		}
        base = base * base % mod ;
        b >>= 1 ;
    }
    return ans % mod ;
}

inline int read(){
	int sum = 0 , f = 1 ;
	char ch = getchar() ;
	while( ch < '0' || ch > '9' ){
		if( ch == '-' ){
			f = -1 ;
		}
		ch = getchar() ;
	}
	while( ch >= '0' && ch <= '9' ){
		sum = ( sum << 1 ) + ( sum << 3 ) + ( ch ^ 48 ) ;
		ch = getchar() ;
	}
	return sum * f ;
}

signed main(){
	n = read() ;
	f[ 0 ][ 0 ] = 1 ;
	fer( i , 1 , n ){
		f[ i ][ 0 ] = ( f[ i - 1 ][ 0 ] * 10 ) % mod ;
		f[ i ][ 1 ] = ( f[ i - 1 ][ 1 ] * 9 + f[ i - 1 ][ 0 ] ) % mod ;
		f[ i ][ 2 ] = ( f[ i - 1 ][ 2 ] * 9 + f[ i - 1 ][ 0 ] ) % mod ;
		f[ i ][ 3 ] = ( f[ i - 1 ][ 3 ] * 8 + f[ i - 1 ][ 1 ] + f[ i - 1 ][ 2 ] ) % mod ;
	}
	printf( "%lld" , f[ n ][ 3 ] ) ;
	return 0 ;
}



Measured memory_bytes: 34776
import re

S = input()
max = 0

for i in range(len(S)) :
    for j in range(i + 1, len(S) + 1) :
        pattern = re.compile(r'[A|T|C|G]{%d}' % int(j - i))
        subStr = S[i:j]

        if pattern.match(subStr) and j - i > max :
            max = j - i

print(max)


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



int main()
{
    long rod[100];
    int n;
    int cnt = 0;
    int p[300];
    int temp[3];

    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> rod[i];

    sort(rod, rod + n); //1 4 6 6 6 6 8 9 9 10
                       //3 3 4 4 5 5 

    for (int i = 0; i < n - 2; i++) {
        
        
        for (int j = 1 + i; j < n - 1; j++) {



            for (int k = 1 + j; k < n; k++) {



                if (rod[i] + rod[j] > rod[k] && rod[j] + rod[k] > rod[i] && rod[k] + rod[i] > rod[j] && rod[i] != rod[j] && rod[i] != rod[k] && rod[j] != rod[k]) {
                    cnt++;

                }
            }
        }
    }

    cout << cnt << endl;

    return 0;
}

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

#define ll long long

int main(void){
    int x;
    cin >> x;
    int ans=0;
    for(int i=1;i<=x+1;i++){
        for(int j=2;j<=x+2;j++){
            int p = pow(i,j);
            // cout << p << endl;
            if(x < p) break;
            if(ans < p) ans = p;
        }
        // if(pow(i,2)>x){
        //     cout << pow(i-1,2) <<endl;
        //     return 0;
        // }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int a, b; char op;
    cin >> a >> op >> b;
    if(op == '+') cout << a+b << endl;
    else cout << a-b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int n,ans=0;
    cin >> n;
    int a[n+1];
    for(int i=1;i<=n;i++)
        cin >> a[i];
    map <int,int> m;
    for(int i=1;i<=n;i++){
        ans+=m[i-a[i]];
        m[i+a[i]]++;
    }
    cout << ans;
}

Measured memory_bytes: 27952
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

int main() {
    int N;
    cin >> N;
    vector<int> p(N);
    rep(i, N) cin >> p.at(i);

    string ans = "NO";

    // 操作しない場合
    bool isAsc = true;
    rep(k, N - 1) {
        if (p.at(k + 1) <= p.at(k)) isAsc = false;
    }
    if (isAsc) ans = "YES";

    // 操作する場合
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            swap(p.at(i), p.at(j));
            isAsc = true;
            rep(k, N - 1) {
                if (p.at(k + 1) <= p.at(k)) isAsc = false;
            }
            if (isAsc) ans = "YES";
            // rep(k, N) cout << p.at(k) << " ";
            // cout << endl;
            swap(p.at(i), p.at(j));  // 元に戻す
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int A,B,K,d,p,t;
    cin>>A>>B>>K;
    t=A+B;
    d=K-A;
    if(t<=K)
        cout<<"0"<<" "<<"0"<<endl;
    else if(d>=0)
    {
        p=B-d;
        cout<<"0"<<" "<<p<<endl;
    }
    else
        cout<<A-K<<" "<<B<<endl;
}

Measured memory_bytes: 3544
/*
 ID: bradyawn
 PROG: contest
 LANG: C++11
 */

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <deque>
#include <string>
#include <cmath>
#include <map>
#include <unordered_map>
#include <utility>
#include <set>
#include <unordered_set>
#include <ctime>
#include <queue>
#include <stack>
#include <bitset>
#include <random>
#include <cstring>
#include <complex>
#include <cassert>

using namespace std;

typedef long long ll;
typedef pair<int,int> i2;
typedef pair<ll,ll> ll2;

int n, x;

int a[101];

int main()
{
    //ifstream inf("");
    //ofstream outf("");
    //cout << setprecision(10);
    ios::sync_with_stdio(0); cin.tie(0);
    
    cin >> n >> x;
    
    for (int i = 1; i <= n; i++) cin >> a[i];
    sort(a+1, a+1+n);
    
    for (int i = 1; i <= n-1; i++)
    {
        x -= a[i];
        if (x < 0)
        {
            cout << i-1 << '\n';
            return 0;
        }
    }
    
    //nth iteration
    
    if (x == a[n]) cout << n << '\n';
    else cout << n-1 << '\n';
    
    return 0;
    
}




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

using namespace std;

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  int cnt = 0;
  for (int i = min(A, B); i >= 1; --i) {
    if (A % i == 0 && B % i == 0) {
      cnt++;
    }
    if (cnt == K) {
      cout << i << endl;
      break;
    }
  }

  return 0;
}



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

int main(){
  vector<string>devide={"dream","dreamer","erase","eraser"};
  for(int i=0;i<4;i++){
    reverse(devide.at(i).begin(),devide.at(i).end());
  }
  string s,d;
  cin >> s;
  reverse(s.begin(),s.end());
  for(int i=0;i<s.size();i++){
    for(int j=0;j<4;j++){
      d=devide.at(j);
      if(s.substr(i,d.size())==d){
        i+=d.size()-1;
        break;
      }
      else if(j==3){
        cout <<"NO"<<endl;
        return 0;
      }
    }
  }
  cout <<"YES"<<endl;
}

Measured memory_bytes: 512
import java.util.*;

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

    String s = sc.next();
    String[] sList = s.split("");

    for (int i = 0; i < 3; i++) {
      String current = sList[i];
      String next = sList[i+1];

      if(current.equals(next)) {
        System.out.println("Bad");
        return;
      }
    }

    System.out.println("Good");
  }
}


Measured memory_bytes: 21716
n = int(input())
ans = [0] * 4
for i in range(n):
    s = input()
    if s == "AC":
        ans[0] += 1
    if s == "WA":
        ans[1] += 1
    if s == "TLE":
        ans[2] += 1
    if s == "RE":
        ans[3] += 1

print("AC x ", end = "")
print(ans[0])
print("WA x ", end = "")
print(ans[1])
print("TLE x ", end = "")
print(ans[2])
print("RE x ", end = "")
print(ans[3])


Measured memory_bytes: 69900
#include <stdio.h>
#include <string.h>

int n, memo[100010], bigmod = 1000000007;
bool broken[100010];

int dp(int p) {
	if (p > n)
		return 0;
	if (p == n)
		return 1;
	if (broken[p])
		return 0;
	if (memo[p] == -1)
		memo[p] = (dp(p + 1) + dp(p + 2)) % bigmod;
	return memo[p];
}

int main() {
	int m, a;
	scanf("%d %d", &n, &m);
	memset(broken, false, sizeof broken);
	while (m--) {
		scanf("%d", &a);
		broken[a] = true;
	}
	memset(memo, -1, sizeof memo);
	a = dp(0);
	printf("%d\n", a);
	return 0;
}

Measured memory_bytes: 3712
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let mut s: Vec<char> = read::<String>().chars().rev().collect();
    let v : Vec<Vec<char>> = vec!["dream","dreamer","erase","eraser"]
        .iter()
        .map(|x| x.chars().rev().collect())
        .collect();
    let mut flag = true;
    while s.len() > 0{
        let check = v.iter().find(|&x| s.starts_with(x) );
        if let Some(x) = check{
            s = s[x.len()..].to_vec();
        } else {
            flag = false;
            break;
        }
    }
    println!("{}", if flag { "YES" } else { "NO" } );
}


Measured memory_bytes: 4352
#define _CRT_SECURE_NO_WARNINGS
#include<sstream>
#include<iostream>
#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>
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 ans[100000];


vector<pair<int,int>> query[100000];
vector<int> child[100000];
vector<int> par;


int N;
int x[100000];
int L, Q;

void dfs(int u) {
	for (auto p : query[u]) {
		ans[p.second] = lower_bound(par.rbegin(),par.rend(), p.first) - par.rbegin() + 1;
	}

	par.push_back(u);
	for (int v : child[u]) {
		dfs(v);
	}
	par.pop_back();
}


int main() {
	scanf("%d", &N);
	rep(i, N)scanf("%d", x + i);
	scanf("%d", &L);
	scanf("%d", &Q);
	rep(i, Q) {
		int a, b;
		scanf("%d%d", &a, &b);
		a--; b--;
		if (a > b)swap(a, b);
		query[a].emplace_back(b, i);
	}
	rep(i,N-1) {
		if (query[i].empty() && child[i].empty())continue;
		int nxt = upper_bound(x, x + N, x[i] + L) - 1 - x;
		child[nxt].push_back(i);
	}
	par.reserve(N);
	dfs(N - 1);
	rep(i, Q)cout << ans[i] << endl;

	return 0;
}

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

using namespace std;

#define ll long long
ll input(){
	ll x=0,f=0;char ch=getchar();
	while(ch<'0'||ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return f? -x:x;
}

const int N=1e4+7,M=107;
const ll mod=1e9+7;

int K[N],D;
ll dp[N][M],vis[N][M];
int n;

ll dfs(int pos,int sum,int lim){
	if(!lim&&vis[pos][sum]) return dp[pos][sum];
	if(pos==n+1){if(!sum) return 1;return 0;}
	int mx=lim? K[pos]:9;ll res=0;
	for(int i=0;i<=mx;i++){
		res=(res+dfs(pos+1,(sum+i)%D,lim&&(i==mx)))%mod;
	}
	if(!lim) dp[pos][sum]=res,vis[pos][sum]=1;
	return res;
}

int main(){
	char ch=getchar();
	while(ch>='0'&&ch<='9') K[++n]=ch-'0',ch=getchar();
	D=input();
	printf("%lld\n",(dfs(1,0,1)-1+mod)%mod);
}

Measured memory_bytes: 17792
import java.util.*;
import java.io.*;
public class Main {
    static int INF = 1001001009;
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    long mod = 1000000000+7;
    long[] inv, fac;
    public static void main(String[] args) throws Exception {
        // Your code here!
        Main main = new Main();
        main.solve();
//        long ans = main.solve();
//        out.println(ans);
//        main.solve();
        out.flush();
    }
    void solve() throws Exception{
        int k = sc.nextInt();
        String s = sc.next();
        int n = s.length();
        int maxn = n+k;
        inv = new long[maxn+1]; fac = new long[maxn+1];
        fac[0] = 1;
        for(int i=1; i<=maxn; i++) fac[i] = fac[i-1]*i%mod;
        inv[0] = 1;
        inv[maxn] = power(fac[maxn], mod-2);
        for(int i=maxn-1; i>0; i--) inv[i] = inv[i+1]*(i+1)%mod;
        long ans = 0, prev = 1L;
        for(int end = n; end<=maxn; end++){
            // the last char of s is on place end (1-based)
            long cur = prev*comb(end-1, n-1)%mod;
            long rest = maxn-end;
            cur = cur*power(26, rest)%mod;
            ans = (ans+cur)%mod;
            prev = prev*25%mod;
        }
        out.println(ans);
    }
    long comb(int n, int m){
        if(n<m) return 0;
        return fac[n]*inv[m]%mod*inv[n-m]%mod;
    }
    int paIn(String s){return Integer.parseInt(s);}
    long power(long base, long p){
        long ans = 1;
        while(p>0){
            if(p%2==1) ans = ans*base%mod;
            base = base*base%mod;
            p /= 2;
        }
        return ans;
    }
}

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

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

 int ispoor =0;
 if(a==b && b!=c) ispoor=1;
  if(b==c && c!=a) ispoor=1;
  if(c==a && a!=b) ispoor=1;

  if(ispoor){
  cout << "Yes" << endl;
  }else{
      cout << "No" << endl;
  }
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define inf 10000000000000
#define LL long long
using namespace std;

int main() {
    fio;
//    freopen("input.txt", "r", stdin);
    int k;
    cin >> k;
    set<int> odd;
    set<int> even;
    for(int i=1; i<=k; i++) {
        if(i%2==0)
            even.insert(i);
        else
            odd.insert(i);
    }
    cout << even.size() * odd.size();
    return 0;
}


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


int main(){

    int N, K, h, cnt=0;
    cin >> N >> K;
    for(int i=0;i<N;i++){
        cin >> h;
        if(h>=K){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  cout << std::fixed << std::setprecision(15);

  double a, b, x;
  cin >> a >> b >> x;

  double ab = a * b;
  x /= a;

  double c = (ab - x) * 2 / a;
  if (c <= b) {
    double r = atan(c / a) * 180 / M_PI;
    cout << r;
    return 0;
  }

  c = x * 2 / b;
  double r = atan(b / c) * 180 / M_PI;
  cout << r;
}
#endif


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int,int>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

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

	int A,B;
	cin>>A>>B;
	
	if(A<=5){
		cout<<0<<endl;
		return 0;
	}
	
	if(A<=12){
		cout<<B/2<<endl;
		return 0;
	}
	
	cout<<B<<endl;
	

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int peopleNum = sc.nextInt();  // 人数
      	int snackNum = sc.nextInt();  // お菓子の数
      	
      	List<Integer> ownList = new ArrayList<Integer>();
      	for(int i = 0; i < snackNum; i++){
          	int ownNum = sc.nextInt();  // お菓子を持っている人数
          	for(int j = 0; j < ownNum; j++){
              int people = sc.nextInt();  // お菓子を持っている人
              ownList.add(people);
            }
        }
      
      	// お菓子を持っている人の重複を排除 -> お菓子を持っている人数
      	List<Integer> ownListB = new ArrayList<Integer>(new LinkedHashSet<>(ownList));
      	int size = ownListB.size();
      
      	// 全人数 - お菓子を持っている人数 = お菓子を持っていない人数
      	System.out.println(peopleNum - size);
    }
}

Measured memory_bytes: 38100
import java.util.*;

public class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        int m = sc.nextInt();
        int n = sc.nextInt();
        int max = 0;
        for(int i=0; i<m; i++){
            int sum = 0;
            for(int j=0; j<n; j++){
                sum += sc.nextInt();
            }
            max = Math.max(max,sum);
        }

        System.out.println(max);
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 12000
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstdint>

using namespace std;

template <class T, class Updater, class Aggregator>
class LazySegmentTree {
    size_t n, m;
    vector<T> tree, buf;
    vector<bool> buffering;
    Updater update;
    Aggregator aggregate;
    const T e;
    void buffer(size_t i, T x) {
        buffering[i] = true;
        buf[i] = update(buf[i], x);
        tree[i] = update(buf[i], x);
    }
    inline void propagate(size_t i) {
        if (!buffering[i]) return;

        buffer(i<<1|0, buf[i]);
        buffer(i<<1|1, buf[i]);
        buf[i] = e;
        buffering[i] = false;
    }
    inline void modify(size_t l, size_t r, const T &x, size_t i, size_t a, size_t b) {
        if (r <= a || b <= l) return;
        if (l <= a && b <= r) {
            buffer(i, x);
            return;
        }
        propagate(i);

        size_t c=(a+b)>>1;
        modify(l, r, x, i<<1|0, a, c);
        modify(l, r, x, i<<1|1, c, b);
        tree[i] = aggregate(tree[i<<1|0], tree[i<<1|1]);
    }
    T query(size_t l, size_t r, size_t i, size_t a, size_t b) {
        if (r <= a || b <= l) return e;
        if (l <= a && b <= r) return tree[i];

        propagate(i);
        size_t c=(a+b)>>1;
        T vl=query(l, r, i<<1|0, a, c);
        T vr=query(l, r, i<<1|1, c, b);

        return aggregate(vl, vr);
    }
public:
    LazySegmentTree(size_t m, T e=T()): n(1), m(m), e(e) {
        while (n < m) n <<= 1;

        tree.assign(n<<1, e);
        buf.assign(n<<1, e);
        buffering.assign(n<<1, false);
    }
    void modify(size_t l, size_t r, const T &x) {
        modify(l, r, x, 1, 0, n);
    }
    T query(size_t l, size_t r) {
        return query(l, r, 1, 0, n);
    }
};

template <class T>
struct Updater {
    T operator ()(const T &lhs, const T &rhs) {
        return rhs;
    }
};

template <class T>
struct Min {
    T operator ()(const T &lhs, const T &rhs) {
        return min(lhs, rhs);
    }
};

int main() {
    size_t n;
    int q;
    scanf("%zu %d\n", &n, &q);

    int64_t e=(1LL<<31)-1;
    LazySegmentTree<int64_t, Updater<int64_t>, Min<int64_t>> tree(n, e);
    for (int i=0; i<q; ++i) {
        int query;
        scanf("%d", &query);

        if (query == 0) {
                size_t s, t;
                int64_t x;
                scanf("%zu %zu %lld", &s, &t, &x);
                tree.modify(s, t+1, x);
        } else if (query == 1) {
                size_t s;
                scanf("%zu", &s);
                printf("%lld\n", tree.query(s, s+1));
        } else {
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 6632
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int l = sc.nextInt();
        String[] strArr = new String[n];

        for (int i = 0; i < n; i++) {
            strArr[i] = sc.next();
        }

        Arrays.sort(strArr);
        String ans = "";
        for (int i = 0; i < n; i++) {
            ans += strArr[i];
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 26068
#include <stdio.h>
#include <math.h>

typedef struct point{
  int x_elem;
  int y_elem;
}point;

point shift_point(point a,point b);

int main(void){
  point vertice1,vertice2,vertice3,vertice4;
  scanf("%d %d ",&vertice1.x_elem,&vertice1.y_elem);
  scanf("%d %d",&vertice2.x_elem,&vertice2.y_elem);
  vertice3 = shift_point(vertice1,vertice2);
  printf("%d %d ",vertice3.x_elem,vertice3.y_elem);
  vertice4 = shift_point(vertice2,vertice3);
  printf("%d %d",vertice4.x_elem,vertice4.y_elem);
  return 0;
}

point shift_point(point a,point b){
  point c;
  c.x_elem = b.x_elem - b.y_elem + a.y_elem;
  c.y_elem = b.y_elem + b.x_elem - a.x_elem;
  return(c);
}

Measured memory_bytes: 1712
#121_B
N,M=map(int,input().split())
Drink=[]
for _ in range(N):
    a,b=map(int,input().split())
    Drink.append((a,b))
Drink.sort(key=lambda x:x[0])

Sum=0
cnt=0
for i in range(N):
    a,b=Drink[i]
    tmp=min(M-cnt,b)
    Sum+=tmp*a
    cnt+=tmp
    if cnt==M:
        break

print(Sum)

Measured memory_bytes: 18180
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

S = read().decode().rstrip()
ans = 0

for l in range(0, len(S)):
    for r in range(l + 1, len(S) + 1):
        flag = True
        for c in [
                "B", "D", "E", "F", "H", "I", "J", "K", "L", "M", "N", "O", "P",
                "Q", "R", "S", "U", "V", "W", "X", "Y", "Z"
        ]:
            if c in S[l:r]:
                flag = False
        if flag:
            ans = max(ans, r - l)

print(ans)

Measured memory_bytes: 3064
/**
 *   created: 12 April 2019  00:37:24
**/
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef vector< pair<int , int> > vii;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long> pll;
typedef vector< pair<long long , long long> > vll;

#define PB push_back
#define PPB pop_back
#define all(c) (c).begin,(c).end()
#define F(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================
int main(){
	int tc=1;
	// cin>>tc;
	while(tc--){
		int a,b;
		cin>>a>>b;
		int res=0;
		res = max(a,b);
		if(a>b)
			a--;
		else
			b--;
		res += max(a,b);
		cout<<res;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[5010][5010], _min[5010][5010];
int n, A, B;
int a[5010], pos[5010];
int main() {
    cin >> n >> A >> B;
    for(int i = 1; i <= n; i++) cin >> a[i], pos[a[i]] = i;
    for(int i = 1; i <= n; i++) {
        for(int j = 0; j <= n; j++) {
            if(j != pos[i]) {
                dp[i][j] = _min[i - 1][j] + (j > pos[i] ? A : B);
            }
            else if(j == pos[i]) {
                dp[i][j] = min(_min[i - 1][j] + B, _min[i - 1][j - 1]);
            }
            if(j == 0) _min[i][j] = dp[i][j];
            else _min[i][j] = min(_min[i][j - 1], dp[i][j]);
        }
    }
    return cout << _min[n][n] << endl, 0;
}

Measured memory_bytes: 392064
#include <stdio.h>

int main(void){
    int N,M,Z=0,SUM=0;
    int A[101];
    scanf("%d%d",&N,&M);
    for (int i=0; i<N; i++) {
        scanf("%d",&A[i]);
        SUM+=A[i];
    }
    int m;
    m=M;
    int H;
    H=SUM/(4*M);
    if (SUM%(4*M)!=0) {
        H++;
    }
    for (int i=0; i<N; i++) {
        if(A[i]>=H){
            m--;
        }
    }
    if (m>0) {
        printf("No\n");
        
    }
    else{
        printf("Yes\n");
    }
    return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
#include <bitset>
typedef long long ll;
typedef long double ld;

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
vector<vector<ll>>A;


int main() {
	string ABCD;
	cin >> ABCD;
	rep(bit,1<<ABCD.length()) {
		vector<ll> vecABCD;
		rep(i,ABCD.length()) {
			if (i==0) {
				vecABCD.push_back(ABCD[i]-'0');
			}
			else if (bit&(1<<i)) {
				vecABCD.push_back(ABCD[i] - '0');
			}
			else {
				vecABCD.push_back((ABCD[i] - '0')*(-1));
			}
		}
		ll tmp = 0;
		rep(i,vecABCD.size()) {
			tmp += vecABCD[i];
		}
		if (tmp==7) {
			A.push_back(vecABCD);
		}
		
	}

	if (0<A.size()) {
		string ans;
		rep(i, A[0].size()) {
			if (i==0) {
				ans = ans + to_string(A[0][i]);
			}
			else if (0<=A[0][i]) {
				ans = ans + "+";
				ans = ans + to_string(A[0][i]);
			}
			else {
				ans = ans + to_string(A[0][i]);
			}
			 if (i == A[0].size() - 1) {
			ans = ans + "=7";
	}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define popcnt(a) __builtin_popcount(a)
#define FastIO() ios::sync_with_stdio(false), cin.tie(0);
#define IO() freopen("palindrome.in","rw",stdin)
#define error(args...)                       \
{                                            \
    cerr<<"LINE "<<__LINE__;                 \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr<<endl;                              \
}
void err(istream_iterator<string> it)
{
} 
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
  cerr<<' '<< *it << " = " << a ;
  err(++it, args...);
} 
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e2+9, M = 1e5+9, OO = 0x3f3f3f3f;
LL memo[N][M];
LL W[N],w;
int n,V[N],val=0;
LL  solve(int idx=0,int v=val)
{
  if(v<=0) return 0;
  if(idx==n) return OO;

  LL &ret = memo[idx][v];
  if(~ret) return ret;

  ret = solve(idx+1,v);
  if(v-V[idx]>=0) ret = min(ret,solve(idx+1,v-V[idx])+W[idx]);

  return ret; 
}
int main()
{
  memset(memo,-1,sizeof memo);
  scanf("%d%lld",&n,&w);
  for(int i=0;i<n;++i)
  {
    scanf("%lld%d",W+i,V+i);
    val+=V[i];
  }
  for(int i=M-1;~i;--i)
  {
    LL ans=solve(0,i);
    error(ans);
    if(ans<=w)
    {
      printf("%d\n",i);
      break;
    }

  }
  #ifdef _LOCAL_DEFINE
  cerr << (double)clock() * 1.0 / CLOCKS_PER_SEC << endl;
  #endif
  return 0; 
}

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

int main(){
	int N,M,Q;
	cin >> N >> M >> Q;
	vector<vector<int>> train(N,vector<int>(N,0));
	rep(i,M){
		int L,R;
		cin >> L >> R;
		L--;R--;
		train[L][R]++;
	}
	
	vector<vector<int>> s(N+1,vector<int>(N+1,0));
	
	rep(i,N){
		rep(j,N){
			s[i+1][j+1] = s[i][j+1] + s[i+1][j] - s[i][j] + train[i][j];
 		}
	}
	
	rep(i,Q){
		int l,r;
		cin >> l >> r;
		l--;
		cout << s[r][r] - s[l][r] - s[r][l] + s[l][l] << endl;
	}
	
    return 0;
}



Measured memory_bytes: 2944
#include<iostream>
#include<array>
#include<vector>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <utility>
#include <set>

using llint = long long int;
using namespace std;

namespace CsF {
#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define FOR(I,J,K) for(int I = 0;I < J;I+=K)

	string ConvertBit(int N, int e) {
		string s = "";
		int r = 0;
		while (N != 0) {
			r = N % e;
			s = to_string(r) + s;
			N -= r;
			N /= e;
		}
		return s;
	}

	int GCD(int a, int b) {
		if (a < b)swap(a, b);
		int r = a % b;
		while (r != 0) {
			a = b;
			b = r;
			r = a % b;
		}
		return b;
	}

	int LCM(int a, int b) {
		int n = a * b;
		return (n / GCD(a, b));
	}

	int Count(string s, char c) {
		int cou = 0;
		FOR(i, s.length(), 1) {
			if (s[i] == c)cou++;
		}
		return cou;
	}

	vector<int> SieveOfEratosthenes(int N) {
		vector<bool> memo(N + 1);
		vector<int> ret;
		memo[0] = true;
		memo[1] = true;
		for (int i = 2; i < N; i++) {
			if (memo[i])continue;
			ret.push_back(i);
			for (int b = 2; true; b++) {
				if (i*b <= N) {
					memo[i*b] = true;
				}
				else break;
			}
		}
		return ret;
	}

	vector<int> SpInput(int N) {
		vector<int> ret(N);
		FOR(i, N, 1) { cin >> ret[i]; }
		return ret;
	}
}

using namespace CsF;


int main() {
	int N;
	cin >> N;
	bool dp[10010];
	FOR(i, 10010, 1)dp[i] = false;
	dp[0] = true;
	int s;
	FOR(i, N, 1) {
		cin >> s;
		for (int j = 10000; j != -1; j--) {
			if (dp[j])dp[j + s] = true;
		}
	}
	for (int j = 10000; j != -1; j--) {
		if (j % 10 == 0)continue;
		if (dp[j]) {
			cout << j << "\n";
			return 0;
		}
	}
	cout << "0\n";
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int n; cin >> n;
    string s; cin >> s;
    int need_left = 0;
    int pointer = 0;
    for(int i = 0; i < n; ++i){
        if(s[i] == '(') ++pointer;
        else{
            if(pointer==0)++need_left;
            else --pointer;
        }
    }
    int need_right = pointer;
    string ans = "";
    rep(i,need_left) ans += '(';
    ans += s;
    rep(i,need_right) ans += ')';
    cout << ans << endl;
}

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

int main(){
  int n;
  std::cin >> n;
  int num = 1;
  int group = 0;
  int mode = 0;
  bool sw = false;
  for( int i=0; i<n; ++i ){
    int tmp; std::cin >> tmp;
    if (sw)break;
    switch(mode){
      case 0:
        group = tmp; ++mode;
        break;
      case 1:
        if ( group + 1 == tmp ){
          ++group; ++mode;
        } else if ( group - 1 == tmp ){
          num = 1; ++mode;
        } else if ( group == tmp ){
          ++num;
        } else { sw = true; }
        break;
      case 2:
        if ( group - 1 == tmp ){
          ++num;
        } else if ( group != tmp ){
          sw = true;
        }
        break;
    }
  }
  if (sw) {
    puts("No");
    return 0;
  }

  if ( mode == 1 ){
    //std::cout << group << " " << num << std::endl;
    if ( ( group + 1 == n ) || ( group <= n/2 ) ){
      puts("Yes");
    } else {
      puts("No");
    }
  } else {
    group -= num;
    num = n - num;
    //std::cout << group << " " << num << std::endl;
    if ( ( 0 < group ) && ( group <= num/2 ) && ( 1 < num ) ){
      puts("Yes");
    } else {
      puts("No");
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  char c;
  cin >> c;
  if (c == 'a' || c == 'i' || c == 'u' ||c == 'e' || c == 'o'){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256