akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define N 100

int main(){
 
 int M[N][N];
 int a,b,c,d;
 int i,j;
 
 scanf("%d",&a);
 
 for( i = 0 ; i < a ; i++){
  for( j = 0 ; j < a ; j++){
    M[i][j]=0;
  }
 }
 
 for( i = 0 ; i < a ; i++ ){
   scanf("%d%d",&b,&c);
   b--;
   for( j = 0 ; j < c ; j++){
     scanf("%d",&d);
     d--;
     M[b][d] = 1;
   }
 }

 for( i = 0 ; i < a ; i++){
  for( j = 0 ; j < a ; j++ ){
   if(j == a-1)printf("%d\n",M[i][j]);
   else printf("%d ",M[i][j]);
  }
 }
 return 0 ;
}

Measured memory_bytes: 632
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

struct Aho{
	using NP = Aho*;
	map<char,NP> nx;
	NP fail = nullptr, skip = nullptr;
	V<int> matched;		//string ids for this node

	void add(const string& s, int id, int i = 0){
		if(i == (int)s.size()){
			matched.pb(id);
			return;
		}
		if(nx[s[i]] == nullptr){
			nx[s[i]] = new Aho();
		}
		nx[s[i]] -> add(s,id,i+1);
	}
	template<class OP> NP count(OP op, int r){
		if(fail == nullptr) return this;	//root now
		for(int id: matched){
			op(id,r);
		}
		if(skip){
			skip -> count(op,r);
		}else{
			skip = fail -> count(op,r);
		}
		return matched.empty() ? skip : this;
	}

	template<class OP> void match(const string& s, OP op, int i = 0){
		if(i == (int)s.size()) return;
		if(nx.count(s[i]) && nx[s[i]] != nullptr){
			nx[s[i]] -> count(op,i+1);
			nx[s[i]] -> match(s,op,i+1);
		}else{
			if(fail == nullptr){	//root now
				match(s,op,i+1);
			}else{
				fail -> match(s,op,i);
			}
		}
	}

	static NP build(V<string> v){
		NP r = new Aho();
		rep(i,v.size()){
			r -> add(v[i],i);
		}
		queue<NP> que;
		que.push(r);
		assert(r -> fail == nullptr);
		while(!que.empty()){
			NP v = que.front(); que.pop();
			for(auto e: v->nx){
				auto c = e.fs;
				NP u = e.sc;
				NP fail = v -> fail;
				while(fail != nullptr && !fail->nx.count(c)){
					fail = fail -> fail;
				}
				u -> fail = (fail == nullptr) ? r : fail -> nx[c];
				que.push(u);
			}
		}
		return r;
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	string s;
	int N;
	cin >> s >> N;
	V<string> p(N);
	rep(i,N) cin >> p[i];
	auto AC = Aho::build(p);
    int num = 0;
    int prev = -1;
	AC -> match(s,[&](int id,int r){
        int l = r - (int)p[id].size();
        if(l <= prev) return;
        num++;
        prev = r-1;
	});
	cout << num << endl;
}



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

struct Tree;

typedef shared_ptr<Tree> P;

struct Tree{
  Tree(P l,P r,int n){
    lef=l;
    rig=r;
    num=n;
  }
  P lef;
  P rig;
  int num=-1;
};

int get_num(int& i,string& s){
  int prei=i;
  while(isdigit(s[i])) i++;
  int res=stoi(s.substr(prei,i-prei));
  return res;
}

P build_tree(int& i,string &s){
  if(s[i]==')'){

    P _lef(nullptr);
    P _rig(nullptr);
    int _num=-1;
    P res(new Tree(_lef,_rig,_num));

    return res;
  }
  else{
    i++;
    P _lef(build_tree(i,s));
    i+=2;
    int _num=get_num(i,s);

    i+=2;
    P _rig(build_tree(i,s));
    i++;
    P res(new Tree(_lef,_rig,_num));
    return res;
  }
}

P sum_t(P a_t,P b_t){
  if((a_t->num)==-1 || (b_t->num)==-1){
    P _lef(nullptr);
    P _rig(nullptr);
    int _num=-1;
    P res(new Tree(_lef,_rig,_num));
    return res;
  }
  else{
    P _lef=sum_t(a_t->lef,b_t->lef);
    P _rig=sum_t(a_t->rig,b_t->rig);
    int _num=(a_t->num)+(b_t->num);
    P res(new Tree(_lef,_rig,_num));
    return res;
  }
}

string coder(P t){
  if((t->num)==-1){
    return "";
  }
  string s="["+to_string(t->num)+"]";
  string lef=coder(t->lef);
  string rig=coder(t->rig);
  return "("+lef+")"+s+"("+rig+")";
}

int main(){
  string a;
  string b;
  cin>>a>>b;
  int i=0;
  P a_t=build_tree(i,a);

  i=0;
  P b_t=build_tree(i,b);

  P res_t=sum_t(a_t,b_t);
  string res=coder(res_t);


  cout<<res<<endl;
  return 0;
}

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

dp = [[[0] * (n + 1) for _ in range(2501)] for _ in range(n + 1)]

dp[0][0][0] = 1
for i in range(1, n+1):
    for s in range(2501):
        for k in range(i):
            # no use
            dp[i][s][k] += dp[i-1][s][k]

            # use
            if s + x[i-1] <= 2500:
                dp[i][s + x[i-1]][k+1] += dp[i-1][s][k]

ans = 0
for k in range(1, n + 1):
    target = k * a
    ans += dp[-1][target][k]
print(ans)


Measured memory_bytes: 103260
#include <cstdio>
using namespace std;
int v[25];
int main() {
    int n;
    scanf("%d",&n);
    for (int i = 1; i <=n; ++i) {
        scanf("%d",&v[i]);
    }
    int s=0;
    for(int i=2;i<n;i++){
        if(v[i]>v[i-1]&&v[i]<v[i+1])
            s++;
        else if(v[i]>v[i+1]&&v[i-1]>v[i])
            s++;
    }
    printf("%d\n",s);
    //std::cout << "Hello, World!" << std::endl;
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;

int main(){
  int R,G,B,n;
  cin >> R >> G >> B >> n;
  int64_t ans =0 ;
  for(int i=n/R;i>=0;i--){
    for(int j=(n-i)/G;j>=0;j--){
      if((n-R*i-G*j)>=0&&(n-R*i-G*j)%B==0) ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,x,t;
	cin>>n>>x>>t;
	long long int z=floor(n/x);
   if(n%x!=0)
     z=z+1;
	 cout<<t*z<<endl;
	
	
	
}

Measured memory_bytes: 3632
///not today

#include<bits/stdc++.h>
using namespace std;

#define SZ(x) (int)(x).size()
#define pb push_back
#define ll long long
#define xmax(x, y) (x) = max((x), (y))
#define xmin(x, y) (x) = min((x), (y))
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define int long long
#define pipii pair<int, pair<int, int> >

int32_t main(){
    int n, a, b;
    cin >>n >>a >>b;
    if(a > b or (n == 1 and a != b))
        cout <<0 <<endl;
    else
        cout <<((n - 1)*b + a) - ((n - 1)*a + b) + 1 <<endl;
    return false;
}


Measured memory_bytes: 256
def main():  
    h,w,k = map(int,input().split())
    s = [input() for _ in range(h)]
    number = 0
    sb_list = []
    ans = []
    for i in s:
        sb = []
        for j in range(w):
            if i[j] == "#":
                sb.append(j)
        sb_list.append(sb)
    c = 0
    for i in range(h):
        if sb_list[0]:
            c = i
            break
        else:
            del sb_list[0]
    for i in range(len(sb_list)):
        if len(sb_list[i]) == 1:
            number += 1
            ans.append([number]*w)
        elif len(sb_list[i]) == 0:
            ans.append(ans[-1])
        else:
            number += 1
            tmp = [number]*sb_list[i][1]
            del sb_list[i][0]
            for j in range(len(sb_list[i])-1):
                number += 1
                tmp.extend([number]*(sb_list[i][j+1]-sb_list[i][j]))
            number += 1
            tmp.extend([number]*(w-sb_list[i][-1]))
            ans.append(tmp)
    
    for i in range(c):
        print(" ".join([str(j) for j in ans[0]]))
    for i in range(len(ans)):
        print(" ".join([str(j) for j in ans[i]]))
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 43756
#include <bits/stdc++.h>
using namespace std;
#define inf 1000000007
#define MOD 1000000007
#define rep(i, a, b) for(i=a; i<b; i++)
#define lbnd lower_bound
#define ubnd upper_bound
#define x first
#define y second
#define ll long long
#define ii pair<ll, ll>
#define vi vector<ll>
#define vii vector<ii>
#define pb push_back
#define mp make_pair
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = 1e5 + 5;
ll n, k, tim=0;



int main()
{
	ios
	ll i, j, c, a, b;
	ll t;
	cin>>n>>a>>b;
	if(a<b){{
		if((b-a)%2==0)
			cout<<"Alice";
		else cout<<"Borys";
	}}
	else{
		if((a-b)%2==0)
			cout<<"Borys";
		else cout<<"Alice";
	}
} 

Measured memory_bytes: 256
#include <algorithm>
#include <iterator>
#include <iostream>
#include <sstream>
#include <bitset>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <time.h>
#include <limits>
#include <math.h>
#include <climits>
#include <numeric>
#include <utility>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <functional>
#include<unordered_map>

using namespace std;
const double pi=acos(-1.0);
//memset ( a , 0 , n * sizeof(ll) ) ;

#define 	boost  		ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); // don't use if small inpts
#define 	endl 		'\n'
#define 	sl(n) 		scanf("%lld",&n)
#define		mp 			make_pair
#define 	pb 			push_back
#define 	ppb 		pop_back
#define 	fi 			first
#define 	se 			seconchutd
#define 	ll 			long long
#define 	ull 		unsigned long long
#define 	pii 		pair<int, int>
#define 	f(i,a,b) 	for(ll i = (ll)(a); i < (ll)(b); i++)
#define 	rf(i,a,b) 	for(ll i = (ll)(a); i > (ll)(b); i--)
#define 	ms(a,b) 	memset((a),(b),sizeof(a))
#define 	max(a,b) 	((a>b)?(a):(b))
#define 	min(a,b) 	((a<b)?(a):(b))
#define 	vec(g1) 	int temp;cin>>temp;g1,push_back(temp);
#define 	abs(x) 		((x<0)?(-(x)):(x))
#define 	MAX 		1000005
#define 	inf 		LLONG_MAX
#define 	MIN 		INT_MIN

//typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;


int mod = 1e9 + 7 ;
ll gcd(ll a , ll b){return b==0?a:gcd(b,a%b);}
ll powmod(ll a,ll b) {ll res=1;if(a>=mod)a%=mod;for(;b;b>>=1){if(b&1)res=res*a;if(res>=mod)res%=mod;a=a*a;if(a>=mod)a%=mod;}return res;}// ll fac[200005];
// ll inverse(ll n){return powmod(n, mod-2);}
// ll nCr(ll n, ll r){return (fac[n] * inverse(fac[r]) % mod * inverse(fac[n-r]) % mod) % mod;}

/**.................................................................................................................................*/

int main() {

  boost;
  int n,w;
  cin>>n>>w;
  int weight[n+1];
  int value[n+1];
  for(int i=1;i<=n;i++){cin>>weight[i]; cin>>value[i];}
  
  ll total_val=0;
  
  for(int i=1;i<=n;i++)total_val+=value[i];
  
  ll dp[n+1][total_val+1];
  
  for(int i=0;i<=n;i++)for(int j=0;j<=total_val;j++)dp[i][j]=INT_MAX;
  
    dp[0][0]=0;


  for(int i=1;i<=n;i++){
       
  	for(int j=0;j<=total_val;j++){ 
  		  		 dp[i][j]=dp[i-1][j];

  		if(j>=value[i]){
  			 dp[i][j]=min(dp[i-1][j],dp[i-1][j-value[i]]+weight[i]);
  		}

  	}
  }
   
  ll ans= 0;
    for(int i=0;i<=total_val;i++){
    	  if(dp[n][i]<=w )ans=max(ans,i);
    }
    
 cout<<ans<<endl;
     return 0;
}


Measured memory_bytes: 79232
while True:
    inVal = input().split()
    if inVal[1] == "?":
        break
    if inVal[1] == "+":
        print(int(inVal[0]) + int(inVal[2]))
    elif inVal[1] == "-":
        print(int(inVal[0]) - int(inVal[2]))
    elif inVal[1] == "*":
        print(int(inVal[0]) * int(inVal[2]))
    elif inVal[1] == "/":
        print(int(inVal[0]) // int(inVal[2]))


Measured memory_bytes: 5600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		for(int i = N; i > 0; i--) {
			if(Math.sqrt(i) - (int)Math.sqrt(i) == 0) {
				System.out.println(i);
				break;
			}
		}
		scan.close();

	}

}


Measured memory_bytes: 23124
#include <iostream>
#include <string>
using namespace std;
 
int main(){
  string S;
  cin >> S;
  if(S == "Sunny"){
    cout << "Cloudy" << endl;
  }else if(S == "Cloudy"){
    cout << "Rainy" << endl;
  }else{
   cout << "Sunny" << endl;
  }

 return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

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

func main() {
	var (
		s string
		k int
	)
	fmt.Scan(&s, &k)

	m := make(map[string]bool)
	for i := 0; i < len(s); i++ {
		for j := i + 1; j < min(len(s)+1, i+1+k); j++ {
			m[s[i:j]] = true
		}
	}

	var ss []string
	for key := range m {
		ss = append(ss, key)
	}
	sort.Strings(ss)

	fmt.Println(ss[k-1])
}


Measured memory_bytes: 3200
s = int(input())
s_hold = s
sum = 0
i = 0

while i < 9:
  sum = sum + s % 10
  s = s // 10
  i = i + 1

if sum == 0:
  print("Yes")
elif s_hold % sum == 0:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 2940
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 100000;

int main() {
    int H, W;
    int dp[100][100][2][2] = {};
    dp[0][0][0][0] = 1;
    dp[0][0][1][0] = 1;
    // dp[i][j][k][l]
    // 直前にkの方向に進み、lは直前に曲がったかどうか
    for(int i = 0; i < 100; i++) {
        for(int j = 0; j < 100; j++) {
            if(i == 0) {
                dp[i][j][0][0] = 1;
                continue;
            }
            if(j == 0) {
                dp[i][j][1][0] = 1;
                continue;
            }
            if(i > 0) {
                dp[i][j][1][0] += dp[i - 1][j][1][0] + dp[i - 1][j][1][1];
                dp[i][j][1][1] += dp[i - 1][j][0][0];
            }
            if(j > 0) {
                dp[i][j][0][0] += dp[i][j - 1][0][0] + dp[i][j - 1][0][1];
                dp[i][j][0][1] += dp[i][j - 1][1][0];
            }
            dp[i][j][0][0] %= MOD;
            dp[i][j][0][1] %= MOD;
            dp[i][j][1][0] %= MOD;
            dp[i][j][1][1] %= MOD;
        }
    }
    while(cin >> H >> W, H | W) {
        cout << (dp[H - 1][W - 1][0][0] + dp[H - 1][W - 1][0][1] +
                 dp[H - 1][W - 1][1][0] + dp[H - 1][W - 1][1][1]) %
                    MOD
             << endl;
    }
    return 0;
}


Measured memory_bytes: 3176
import numpy as np
import math
import collections
import bisect
from collections import Counter


N = int(input())

A = list(map(int, input().split()))

A.sort()
Set = set()

Amax = A[len(A) - 1]

counter = Counter(A)
ans = 0
for a in A:
    if a in Set:
        continue
    x = a
    while(x <= Amax):
        Set.add(x)
        x += a

    if counter[a] == 1:
        ans += 1

print(ans)


Measured memory_bytes: 120048
#include <bits/stdc++.h>
using namespace std;
char s[100005];
bool t[100005];
int main()
{
	int n;
	cin>>n>>s;
	s[0];
	for(int i=0;i<2;i++)
	{
		for(int j=0;j<2;j++)
		{
			t[0]=i;
			t[1]=j;
			for(int k=1;k<n-1;k++)
				t[k+1]=t[k]^t[k-1]^(s[k]=='x');
			if((s[n-1]=='x')==t[n-2]^t[n-1]^t[0]&&(s[0]=='x')==t[n-1]^t[0]^t[1])
			{
				for(int k=0;k<n;k++)
				{
					if(t[k])
						cout<<'W';
					else
						cout<<'S';
				}
				return 0;
			}
		}
	}
	cout<<"-1";

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;

int main() {
    int N;
    cin >> N;
    set<string> st;
    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        st.insert(s);
    }
    cout << st.size() << endl;
}


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

int main(){
  int n;
  cin>>n;
  int a[n],b[n],c[n];
  rep(i,0,n) cin>>a[i]>>b[i]>>c[i];
  int ap[n+1],bp[n+1],cp[n+1];
  ap[0]=0;
  bp[0]=0;
  cp[0]=0;
  rep(i,0,n){
    ap[i+1]=max(bp[i]+a[i],cp[i]+a[i]);
    bp[i+1]=max(cp[i]+b[i],ap[i]+b[i]);
    cp[i+1]=max(ap[i]+c[i],bp[i]+c[i]);
  }
  cout<<max(ap[n],max(bp[n],cp[n]))<<endl;
}

Measured memory_bytes: 2560
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
 
#define Rep(i, n) for (int i = 1; i <= n; i ++)
#define Rep0(i, n) for (int i = 0; i <= n; i ++)
#define RepG(i, x) for (int i = head[x]; i; i = edge[i].next)
#define v edge[i].to
#define mp(a, b) make_pair(a, b)
 
using namespace std;

const int N = 200100;
typedef long long LL;

struct Edge{ int to, next;} edge[N * 2];
int head[N],num;
void add_edge(int a, int b) { edge[++ num] = (Edge){b, head[a]}, head[a] = num;}

bool vis[N], flag;
int col[N], cn;

void dfs(int x)
{
	vis[x] = true, cn ++;
	RepG(i, x){
		if (!vis[v]){ col[v] = col[x] ^ 1; dfs(v);}
		else if (col[v] == col[x]) flag = true; 
	}
}

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	Rep(i, m) {
		int a, b;
		scanf("%d%d", &a, &b);
		add_edge(a, b); add_edge(b, a);
	}
	LL t0 = 0, t1 = 0, t2 = 0;
	Rep(i, n) if (!vis[i]) {
		flag = false, cn = 0;
		dfs(i);
		if (cn == 1) t0 ++;
		else if (flag) t1 ++;
		else t2 ++;
	}
	
	printf("%lld\n", t0 * n * 2 - t0 * t0 + t1 * t1 + 2 * t1 * t2 + t2 * t2 * 2);
	
	return 0;
}

Measured memory_bytes: 6016
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

int main(){
	int a,b;
	cin >> a >> b;
	int ans=0;
	for(int i=a; i<=b; i++){
		string s = to_string(i);
		bool same = true;
		REP(j, s.size()/2){
			if(s[j] != s[s.size()-1-j]) same=false;
		}
		if(same) ans++;
	}
	cout << ans << endl;
	
	return 0;
}

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

namespace atcoder135
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] B = A.Select(x => x).ToArray();
            Array.Sort(B);
            int cnt = 0;
            for (int i = 0; i < n; ++i)
                if (B[i] != A[i])
                    ++cnt;
            if(cnt <= 2)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
        }
    }
}


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

int main(){
  int n, a, t1=0, t2=0;
  bool j = true;
  vector<int> v;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a;
    v.push_back(a);
  }
  sort(v.begin(), v.end());
  vector<int>::iterator itr;
  itr = v.begin();
  for(int i=0;i<n;i++){
    if(j==true){
      t1 += *itr;
      j = false;
    }
    else{
      t2 += *itr;
      j = true;
    }
    ++itr;
  }
  if(t1 - t2 < 0)cout << t2 - t1 << endl;
  else cout << t1 - t2 << endl;
  return 0;
}


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

void solve() 
{
    int n,k,c;cin>>n>>k>>c;
    string s;cin>>s;
    vector<bool>f(n,0);int sum=0;
    REP(i,s.size()){
        if(s[n-1-i]=='o'){
            sum++;
            f[n-1-i]=1;
            i+=c;
        }
    }
    if(sum>k){return;}
    REP(i,s.size()){
        if(s[i]=='o'){
            if(f[i]==1){
                cout<<i+1<<endl;
            }
            i+=c;
        }
    }
}

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

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

int main() {
  int n;
  cin >> n;
  int a[n], a_num_sum[100010] = {}, a_max = 0;
  int i;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    a_num_sum[a[i]]++;
    a_max = max(a_max, a[i]);
  }
  int result = 0;
  for (i = 1; i < a_max + 2; i++) {
    result = max(result, a_num_sum[i - 1] + a_num_sum[i] + a_num_sum[i + 1]);
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
typedef long long ll;
const int mo=1000000007;
char s[1050][1050];
int sta[80];
int a[2][2],ans[2][2],dis[2][2],o[2][2];
int i,j,l,t,n,m,top,cnt,t1,t2,p1,p2,num;
ll k;
char get(){
	char ch=getchar();
	while (ch!='.'&&ch!='#') ch=getchar();
	return ch;
}
int qsm(int x,ll y){
	if (!y) return 1;
	int t=qsm(x,y/2);
	t=(ll)t*t%mo;
	if (y%2) t=(ll)t*x%mo;
	return t;
}
void mult(int a[2][2],int b[2][2],int c[2][2]){
	int i,j,k;
	fo(i,0,1)
		fo(j,0,1)
			o[i][j]=0;
	fo(k,0,1)
		fo(i,0,1)
			fo(j,0,1)
				o[i][j]=(o[i][j]+(ll)a[i][k]*b[k][j]%mo)%mo;
	fo(i,0,1)
		fo(j,0,1)
			c[i][j]=o[i][j];
}
int main(){
	scanf("%d%d%lld",&n,&m,&k);
	fo(i,1,n)
		fo(j,1,m){
			s[i][j]=get();
			if (s[i][j]=='#'){
				cnt++;
				if (j>1&&s[i][j-1]=='#') t1++;
				if (i>1&&s[i-1][j]=='#') t2++;
			}
		}
	fo(i,1,n)
		if (s[i][1]=='#'&&s[i][m]=='#') p1++;
	fo(i,1,m)
		if (s[1][i]=='#'&&s[n][i]=='#') p2++;
	if (p1<p2){
		swap(p1,p2);
		swap(t1,t2);
	}
	if (k==1||p2){
		printf("1\n");
		return 0;
	}
	if (!p1&&!p2){
		printf("%d\n",qsm(cnt,k-1));
		return 0;
	}
	if (k==2){
		printf("%d\n",cnt-t1);
		return 0;
	}
	fo(i,0,1) ans[i][i]=1;
	a[0][0]=cnt-t1;a[0][1]=-p1;
	dis[0][0]=cnt;dis[1][0]=t1;dis[1][1]=p1;
	k-=2;
	while (k){
		sta[++top]=k%2;
		k/=2;
	}
	while (top){
		mult(ans,ans,ans);
		if (sta[top]) mult(ans,dis,ans);
		top--;
	}
	mult(a,ans,a);
	num=a[0][0];
	(num+=mo)%=mo;
	printf("%d\n",num);
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin >> n;
    vector<ll> A(n);
    vector<ll> sumA(n);
    
    for(int i=0; i<n; i++){
        cin >> A[i];
        if(i==0) sumA[i]= A[i];
        else sumA[i]= sumA[i-1]+A[i];
    }
    for(ll x:sumA) cerr << x << endl;
    ll ans= 9999999999;
    int l=0,r=2;
    for (int i = 1; i<n-2; i++) {
        cerr << l << " " << i << " " << r << endl;
        while (abs(sumA[i] -2*sumA[l])>abs(sumA[i] -2*sumA[l+1])) l++;
        while (abs(sumA[n-1] -sumA[i] -2*(sumA[r] - sumA[i])) >
           abs(sumA[n-1]-sumA[i] -2*(sumA[r+1] -sumA[i])))r++;
        ll w= sumA[l], x= sumA[i] -sumA[l], y= sumA[r]- sumA[i], z= sumA[n-1] -sumA[r];
        // cerr << w << " " << x << " " << y << " " << z << endl;
        ans = min(ans, max({w, x, y, z}) - min({w, x, y, z}));
        cerr << ans << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
// const int k_mod = 1e9 + 7;
const int k_mod = 998244353;

template <typename T, typename K> struct P {
	T a; K b;
};
typedef struct {
	vector <int> to;
	bool is_visited = false;
} node;
typedef struct {
	int to;
	int cost;
	P <int, int> change;
} edge;
int main( void ){
	int N, M; cin >> N >> M;
	map<int, vector<int>> mp;
	vector<map<int, int>> order(N);
	vector<pair<int, int>> input(M);
	rep(i,0,M){
		int p, y; cin >> p >>y;
		mp[p].push_back(y);
		input[i] = make_pair(p, y);
	}
	for(auto m:mp){
		sort_asc(m.second);
		rep(i,0,m.second.size()){
			order[m.first-1][m.second[i]] = i+1;
		}
	}
	for(auto i:input){
		printf("%06d%06d\n", i.first, order[i.first-1][i.second]);
	}
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 22528
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <string.h>

#ifdef LOCAL
	#define eprintf(...) printf(__VA_ARGS__)
#else 
	#define eprintf(...) 1
#endif

#define ROUNDUP(a, b) ( ((a) + ((b) - 1) ) / b)

typedef long long int lli;

using namespace std;

int main(void) {
	int N;
	scanf("%d", &N);
	int A[2][N];
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[0][i]);
	}
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[1][i]);
	}

	int sum[2][N];
	sum[0][0] = A[0][0];
	sum[1][0] = A[1][0];
	for (int i = 1; i < N; i++) {
		sum[0][i] = sum[0][i-1] + A[0][i];
		sum[1][i] = sum[1][i-1] + A[1][i];
	}

	int max = 0;
	for (int i = 0; i < N; i++) {
		int candy = (i==0? sum[0][0] + sum[1][N-1]:
				sum[0][i] + sum[1][N-1] - sum[1][i-1]);
		if (max < candy) {
			max = candy;
		}
	}

	printf("%d\n", max);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;

int A, B, C, X, counter, total;

int main() {
    cin >> A;
    cin >> B;
    cin >> C;
    cin >> X;
  
    counter = 0;
    REP(a,A+1){
        REP(b,B+1){
            REP(c,C+1){
                total = 500*a + 100*b + 50*c;
                if (total == X) {
                    counter++;
                }
            }
        }
    }
    cout << counter << endl;
}

Measured memory_bytes: 256
def solve(l: list):
    x, y = 1, 1

    for t, a in l:
        nx = x // t + 1 - (x%t==0)
        ny = y // a + 1 - (y%a==0)
        n = max(nx, ny)
        x = n * t
        y = n * a
    return x + y


def main():
    N = int(input())
    l = []
    for i in range(N):
        a, b = map(int, input().split())
        l.append((a,b))
    print(solve(l))


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int n;
int a[100001];
int ans;
int main(){
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;i++){
    	int b,c;
    	cin>>b>>c;
    	for(int j=b;j<=c;j++){
    		a[j]=1;
		}
	}
	for(int i=1;i<=100000;i++){
		if(a[i]==1) ans++;
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

const int N = 1e5 + 20 ;
int n , gnd[N] ;
vector <int> g[N] ;

void dfs (int v , int par = -1) {
	for (int u : g[v]) {
		if (u == par) continue ;

		dfs(u , v) ;

		gnd[v] ^= (gnd[u] + 1) ;
	}
}

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

	cin >> n ;

	for (int i = 0 , u , v ; i < n - 1 ; i ++) {
		cin >> u >> v ;
		u -- , v -- ;

		g[u].push_back(v) ;
		g[v].push_back(u) ;
	}

	dfs(0) ;

	cout << (gnd[0] ? "Alice" : "Bob") << '\n' ;
}


Measured memory_bytes: 12416
N = int(input())
S = ''
ans_l = []
if N != 0:
	while N != 0:
		if N % 2 == 0:
			N = N // (-2)
			S = '0' + S
		else:
			N = (N-1) // (-2)
			S = '1' + S
else:
	S = '0'
print(S)



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

using namespace std;
typedef long long ll;

class SegTree {
public:
	//Range Max Query
	vector<ll> ar;
	int length;
	SegTree(int n) {
		length = 1;
		while (n > length)length *= 2;
		ar.resize(2 * length - 1);
		for (int i = 0; i < 2 * length - 1; i++)ar[i] = 0;
	}

	void update(int k, ll a) {
		//k番目をaにする
		k += length - 1;
		ar[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			ar[k] = max(ar[2 * k + 1], ar[2 * k + 2]);
		}
	}

	ll getval(int a, int b, int k, int l, int r) {
		//[a, b)を求める
		if (r <= a || b <= l)return 0;
		else if (a <= l && r <= b)return ar[k];
		else {
			ll v1, v2;
			v1 = getval(a, b, 2 * k + 1, l, (l + r) / 2);
			v2 = getval(a, b, 2 * k + 2, (l + r) / 2, r);
			return max(v1, v2);
		}
	}

};

int N;
ll dp[200001];//dp[i]:=高さiで終わる際の美しさの和の最大値
ll H[200001], I[200001];
ll pos1[200001];

int main() {

	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> H[i];
		pos1[H[i]] = i;
	}
	for (int i = 1; i <= N; i++) {
		cin >> I[i];
	}

	SegTree st(N + 1);

	dp[0] = 0;
	for (int i = 1; i <= N; i++) {

		dp[i] = st.getval(0, pos1[i], 0, 0, st.length) + I[pos1[i]];//[0, i)の中の最大値をlog nで求める。0番は便宜上の配置であり、実際は1,2...番の順にデータが格納される
		st.update(pos1[i], dp[i]);
	} 
	ll ans = 0;
	for (int i = 1; i <= N; i++) {
		ans = max(ans, dp[i]);;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 10624
open System

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f

    let readInts() =
        read string
        |> Seq.toArray
        |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

[<EntryPoint>]
let main _ =
    let n = read int
    let ans =
        if n % 2 = 0 then n / 2 - 1
        else n / 2
    let ans = if n < 3 then 0 else ans

    ans |> printfn "%d"
    0 // return an integer exit code


Measured memory_bytes: 13916
def calc(a1,c):
    As=[a1]
    Bs=[]
    Bs.append(c[0][0]-As[0])
    As.append(c[1][0]-Bs[0])
    As.append(c[2][0]-Bs[0])
    Bs.append(c[0][1]-As[0])
    Bs.append(c[0][2]-As[0])
    for a in range(3):
        for b in range(3):
            if As[a]+Bs[b]!=c[a][b]: return False
    return True

c=[]
for i in range(3):
    c.append(list(map(int,input().split())))

flag=False
for i in range(-int(1e4),100):
    if (calc(i,c)): 
        print('Yes')
        flag=True
        break
if not flag: print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main(){
    int d, r;
    double x = 0, y = 0, nr = 0;
    while( scanf("%d,%d", &d, &r), d || r ){
        double rad = nr/180*M_PI;
        x += (cos(rad)*d);
        y += (sin(rad)*d);
        nr += r;
    }
    cout << (int)y << endl;
    cout << (int)x << endl;
}

Measured memory_bytes: 3464
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define F first
#define S second


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

bool app[50][50][50][50];

main(){
  int w,h;
  while(cin>>w>>h,w|h){
    memset(app,0,6250000);
    string lr[h],rr[h];
    rep(i,h){
      cin>>lr[i]>>rr[i];
    }

    string ans="No";
    int rsx,rsy,lsx,lsy;
    rep(i,h)rep(j,w){
      if(lr[i][j]=='L')lsx=i,lsy=j;
      if(rr[i][j]=='R')rsx=i,rsy=j;
    }

    queue<pair<PI,PI> > Q;
    Q.push(mp(mp(lsx,lsy),mp(rsx,rsy)));

    while(!Q.empty()){
      PI tp=Q.front().F;
      int clx,cly,crx,cry;
      clx=tp.F,cly=tp.S;
      tp=Q.front().S;Q.pop();
      crx=tp.F,cry=tp.S;
      if(lr[clx][cly]=='%' && rr[crx][cry]=='%'){
        ans="Yes";
        break;
      }
      if(lr[clx][cly]=='%' || rr[crx][cry]=='%')continue;
      app[clx][cly][crx][cry]=true;

      rep(i,4){
        int nrx=crx+dx[i],nlx=clx+dx[i],nry=cry+dy[i],nly=cly-dy[i];
        if(nrx<0 || nry<0 || nrx>=h || nry>=w || rr[nrx][nry]=='#')nrx=crx,nry=cry;
        if(nlx<0 || nly<0 || nlx>=h || nly>=w || lr[nlx][nly]=='#')nlx=clx,nly=cly;
        if(app[nlx][nly][nrx][nry])continue;
        app[nlx][nly][nrx][nry]=true;
        Q.push(mp(mp(nlx,nly),mp(nrx,nry)));
      }
/*      
      rep(i,h){
        rep(j,w){
          if(clx==i && cly==j)cout<<'L';
          else if(lr[i][j]=='L')cout<<'.';
          else cout<<lr[i][j];
        }
        cout<<" ";
        rep(j,w){
          if(crx==i && cry==j)cout<<'R';
          else if(rr[i][j]=='R')cout<<'.';
          else cout<<rr[i][j];
        }
        cout<<endl;
      }
      cout<<endl;
*/
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 7928
// #include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <bitset>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define trace(x) cerr << #x << ": " << x << " " << endl;
 
typedef int64_t ll;
 
#define endl '\n'
#define int ll
ll mod=998244353;
ll mod1=1e9+5;
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power(((((a)%mod)*((a)%mod))%mod),b/2)%mod;
    else return (((a)%mod)*(power(((((a)%mod)*((a)%mod))%mod),b/2)%mod))%mod;
}
inline ll inverse(ll a) {
  a %= mod;
  if (a < 0) a += mod;
  ll b = mod, u = 0, v = 1;
  while (a) {
    ll t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += mod;
  return u;
}
  
  
 //using namespace __gnu_pbds;
 //#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
//find_by_order(k)  returns iterator to kth element starting from 0;
//order_of_key(k) returns count of elements strictly smaller than k;
//erase,insert same as normal set
// mt19937 mrand(chrono::high_resolution_clock::now().time_since_epoch().count()); for randomized solution
const int ce=1e9+7;
ll fast_mod(ll input)
{
    return input < ce ? input : input%ce;
}

int32_t main()
{
    IOS


    int n,s;
    cin>>n>>s;
    int a[n+1];
    for(int i=1;i<=n;i++)
    	cin>>a[i];
    int dp[n+1][s+1];
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    for(int i=1;i<=n;i++)
    {
    	dp[i][0]=1;
    	for(int j=1;j<=s;j++)
    	{
    		dp[i][j]=dp[i-1][j];
    		if(j-a[i]>=0)
    		{
    			dp[i][j]+=dp[i-1][j-a[i]]*inverse(2);
    		}
    		dp[i][j]%=mod;
    	}
    }
    cout<<(dp[n][s]*power(2,n))%mod;
}       

Measured memory_bytes: 74016
#include <bits/stdc++.h>
using namespace std;
int m,n;
char a[505][505];
int main(){
	cin >> m >> n;
	for(int i = 1; i <= m; i++)
		for(int j = 1; j <= n; j++)
			cin >> a[i][j];
	for(int i = 1; i <= m; i++){
		for(int j = 1; j <= n; j++)
			if(i != m && (i == 1 || j%2 == 0)) cout << '#';
			else cout << a[i][j];
		cout << endl;
	}
	cout << endl;
	for(int i = 1; i <= m; i++){
		for(int j = 1; j <= n; j++)
			if(i != 1 && (i == m || j%2 == 1)) cout << '#';
			else cout << a[i][j];
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 1024
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int bit = 0;
        for (int i = 0; i<N; i++) {
            bit |= sc.nextInt();
        }
        System.out.println(Integer.numberOfTrailingZeros(bit));
    }
}

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

int main(){
   int n;
   cin>>n;
   int h[n];
   long int dp[n];
   for(int i = 0;i<n;i++){
    cin>>h[i];
    dp[i] = 0;
   }


   dp[1] = abs(h[0]-h[1]);

   for(int i = 2;i<n;i++){
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
   } 


   cout<<dp[n-1];


      
}


Measured memory_bytes: 1408
#include <cstdio>
#include <iostream>
#include <vector>
#define rep(i, n) for(ll i = 0; i < n; i++)
typedef long long ll;
const ll MOD=1e9+7;

int main(){
    ll n, k;
    std::cin >> n >> k;
    std::vector<ll> c(n);
    rep(i, k){
        ll d;
        std::cin >> d;
        rep(j, d){
            ll a;
            std::cin >> a;
            a--;
            c[a]++;
        }
    }
    ll cnt = 0;
    rep(i, n){
        if(c[i] == 0) cnt++;
    }
    std::cout << cnt << std::endl;
}

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

void search(string s, int n){
    char big = 'a';
    if(n == 1){
        cout << s << endl;
        return;
    }
    for(char t : s){
        big = max(big, t);
    }
    for(char c = 'a'; c < big + 2; c++){
        if(s.length() + 1 < n)search(s+c, n);
        else if(s.length() + 1 == n) cout << s + c << endl;
    }
}

int main() {
    int n;
    cin >> n;
    search("a", n);
}

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

int main() {

    string s ,t;

    cin >> s >> t;
    
    sort(s.begin() ,s.end());
    sort(t.rbegin() ,t.rend());    

    cout << ((s < t) ? "Yes" : "No") << endl;   
        
    return 0; 

}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

int n;
int t[9][9];
int win[9],lose[9];
int ans;

void f(int x,int y){
    if(x==n-1){
        bool f=true;
        rep(i,n-1)f&=win[i]==win[i+1];
        ans+=f;
        return;
    }
    int nx=x,ny=y+1;
    if(ny==n){
        nx++;
        ny=nx+1;
    }
    if(t[x][y]==-1){
        win[x]++;
        lose[y]++;
        t[x][y]=1;
        t[y][x]=0;
        if(win[x]<=n/2&&lose[y]<=n/2)f(nx,ny);
        win[x]--;
        lose[y]--;
        win[y]++;
        lose[x]++;
        t[x][y]=0;
        t[y][x]=1;
        if(win[y]<=n/2&&lose[x]<=n/2)f(nx,ny);
        win[y]--;
        lose[x]--;
        t[x][y]=-1;
        t[y][x]=-1;
    }
    else f(nx,ny);
}

void run(){
    cin>>n;
    if(!n)return;
    memset(t,-1,sizeof(t));
    MEMSET(win);
    MEMSET(lose);
    int m;
    cin>>m;
    while(m--){
        int x,y;
        cin>>x>>y;
        x--,y--;
        t[x][y]=1;
        t[y][x]=0;
        win[x]++;
        lose[y]++;
    }
    ans=0;
    f(0,1);
    cout<<ans<<endl;
    run();
}


Measured memory_bytes: 3180
import numpy as np


def main():
    INF = 10**15
    V = 10**5 + 1
    N, W = list(map(int, input().split(' ')))
    items = np.array([list(map(int, input().split(' '))) for _ in range(N)])
    dp = np.full((N, V + 1), INF)
    dp[0, :(items[0, 1] + 1)] = items[0, 0]
    dp[0, 0] = 0
    for n in range(1, N):
        weight, value = items[n, 0], items[n, 1]
        dp[n, :] = dp[n - 1, :]
        dp[n, value:] = np.fmin(
            dp[n, value:],
            weight + dp[n - 1, :(- value)]
        )
    ans = 0
    for v in range(V):
        if dp[N - 1, v] <= W:
            ans = v
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 92700
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_B&lang=jp
// Recursion / Divide and Conquer - Merge Sort

#define SUBMIT

#include <algorithm>
#include <iostream>
#include <vector>
#include <array>
#include <numeric>
#include <set>
#include <climits>

using namespace std;
using i64 = long long;

const int MAX_N = 500000;

int cmp_count = 0;
int A[MAX_N + 1];

void merge(int left, int mid, int right) {
    auto n1 = mid - left;
    auto n2 = right - mid;
    int L[n1 + 1], R[n2 + 1];
    for (int i = 0; i < n1; ++i) L[i] = A[left + i];
    for (int i = 0; i < n2; ++i) R[i] = A[mid + i];
    L[n1] = R[n2] = INT_MAX;

    auto i = 0, j = 0;
    for (int k = left; k < right; ++k) {
        cmp_count++;
        if (L[i] <= R[j]) {
            A[k] = L[i];
            i++;
        } else {
            A[k] = R[j];
            j++;
        }
    }
}

void merge_sort(int left, int right) {
    if (left + 1 < right) {
        auto mid = (left + right) / 2;
        merge_sort(left, mid);
        merge_sort(mid, right);
        merge(left, mid, right);
    }
}

int main() {
    int n;
#ifdef SUBMIT
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> A[i];
#else
    n = 10;
    int inputs[] = {8, 5, 9, 2, 6, 3, 7, 1, 10, 4};
    for (int i = 0; i < n; ++i) A[i] = inputs[i];
#endif
    merge_sort(0, n);

    for (int i = 0; i < n; ++i) {
        cout << A[i];
        if (i != n - 1) cout << " ";
        else cout << endl;
    }
    cout << cmp_count << endl;
    return 0;
}


Measured memory_bytes: 6988
n,x = map(int,input().split())
a = sorted(list(map(int,input().split())))
count = 0
for i in range(n):
    if x >= a[i]:
        count += 1
        x -= a[i]
    else:
        break
if count == n:
    if x != 0:
        count -= 1
print(count)

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

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

    int ans = 0;
    for (int i = 1; i < n - 1; i++)
    {
        if (((p[i - 1] < p[i]) & (p[i] < p[i + 1])) | ((p[i - 1] > p[i]) & (p[i] > p[i + 1])))
        {
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3608
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif
#define LDcout(x,n) fixed<<setprecision(n)<<x

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
ll dp[10][100000];
ll fun(ll a){
    ll ret=1;
    reep(i,1,a+1) ret*=i;
    return ret;
}
void mainmain(){
    vint v(10);
    rep(i,10) v[i]=i;
    do{
        int t=0;
        rep(i,10){
            t+=v[i]*(i+1);
            dp[i][t]++;
        }
    }while(next_permutation(ALL(v)));
    int n,s;
    while(cin>>n>>s){
        cout<<dp[n-1][s]/fun(10-n)<<endl;
    }
}


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

Measured memory_bytes: 5308
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		int b = 0;
		boolean c = false;
		// 文字列の入力
		int[] d = new int[a];
		int[] e = new int[a];
		for(int i = 0; i < a; i++){
			d[i] = sc.nextInt();
			e[i] = sc.nextInt();
			if(d[i] == e[i]){
				b++;
				if(b == 3){
					c = true;
				}
			}else{
				b = 0;
			}
		}
		if(c){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		} 
		
		
	}
}

Measured memory_bytes: 35992
X, N = map(int, input().split())
if N == 0:
  print(X)
  exit()
p = list(map(int, input().split()))
ans = -float('inf')
d = float('inf')
for i in range(-10, 2100):
  if i not in p:
    if abs(X-i) < d:
      d = abs(X-i)
      ans = i

print(ans)

Measured memory_bytes: 63172
#include <bits/stdc++.h>
using namespace std;
int main (){
    string s;
    cin >> s;
    vector<int> v(26,0);
    
    for (int i=0;i<s.size();i++){
        v.at(s.at(i)-'a') = 1;
    }
    for (int i=0;i<26;i++){
        if(v.at(i) == 0){
            char c = 'a'+i;
            cout << c << endl;
            break;
        }
        else if(i == 25){
            cout << "None" << endl;
        }
    }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30 - 1)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> A >> B >> C;
    if (A == B && B == C) {
        cout << "No" << endl;
    } else if (A != B && B != C && C != A) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

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

int main() {
  string s,t;
  cin >> s >> t;
  int a,b;
  cin >> a >> b;
  string u;
  cin >> u;
  if (u==s) a--;
  else b--;
  cout << a << ' ' << b << endl;
}

Measured memory_bytes: 256