akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

const int inf = 1001001001;
int di[] = { -1,0,1,0 };
int dj[] = { 0,-1,0,1 };

int h, w;
vector<vector<char>> mp;

void bfs(vector<vector<int>>& c,int a,int b) {
	queue<pair<int, int>> que;
	que.push(make_pair(a, b));
	while (!que.empty()) {
		int i = que.front().first; int j = que.front().second;
		que.pop();
		rep(k, 4) {
			int dx = i + di[k], dy = j + dj[k];
			if (dx < 0 || dx >= h || dy < 0 || dy >= w) continue;
			if (c[dx][dy] != inf) continue;
			if (mp[dx][dy] == '#') continue;
			que.push(make_pair(dx, dy));
			c[dx][dy] = c[i][j] + 1;
		}
	}
	return;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> h >> w;
	mp.resize(h, vector<char>(w));
	rep(i, h)rep(j, w) cin >> mp[i][j];
	int just_ans = 0;
	rep(i, h)rep(j, w) {
		vector<vector<int>> ans(h,vector<int>(w,inf));
		if (mp[i][j] == '#') continue;
		ans[i][j] = 0;
		bfs(ans,i, j);
		rep(ri, h)rep(rj, w) {
			if (ans[ri][rj] == inf || mp[ri][rj] == '#') continue;
			just_ans = max(just_ans, ans[ri][rj]);
		}
	}
	dunk(just_ans);
	return 0;
}

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

int main ()
{
  int N=0;
  long long res = 1;
  cin >> N;
  long long num[N];
  for (int i=0; i<N; i++)
    {
      cin >> num[i];
      if (num[i]==0)
        {
          cout << 0 << endl;
          return 0;
        }
    }
  for (int i=0; i<N; i++)
    {
      if (num[i] > 1000000000000000000/res)
        {
          cout << -1 << endl;
          return 0;
        }
      else
        res *= num[i];
    }
  cout << res << endl;
  return 0;
}

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

int main(){
    long long n, mini = 10000000, maxi = -10000000, sum = 0;
    cin >> n;
    long long a[n];
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    for (int i = 0; i < n; i++){
        if (mini > a[i]) {
            mini = a[i];
        }
        if (maxi < a[i]) {
            maxi = a[i];
        }
        sum += a[i];
    }
    cout << mini << " " << maxi << " " << sum << endl;

    
    return 0;
}


Measured memory_bytes: 3176
import java.util.Scanner;

public class Main{
	static int[] p;
	static int n;
	
	// a i-1 人までの A の合計
	// b 
	static int choice(int i,int a,int b) {
		if(i < p.length) {
		//case 1
		int m1 = choice(i+1,a+p[i],b);
		//case 2
		int m2 = choice(i+1,a, p[i]+b);
		return Math.min(m1, m2);
		}
		else {
			return Math.abs(a-b);
		}
		
	}
	
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)){
        	while(true) {
        		int n = sc.nextInt();
        		if(n==0) break;
        		p =  new int[n];
        		for(int i=0;i<n;i++) {
        			p[i] = sc.nextInt();        		}
        		System.out.println(choice(0,0,0));
        	}
        }
    }
}
 


Measured memory_bytes: 28692
n, m = map(int, input().split())
a = [0] * m
b = [0] * m
for i in range(m):
    a[i], b[i] = map(int, input().split())

ans = [0] * n

for i in range(m):
    ans[a[i]-1] += 1
    ans [b[i]-1] += 1

for i in ans:
    print(i)

Measured memory_bytes: 9040
#include <iostream>

using namespace std;
int cnt[26];
char buf[256];

int main(void){
  int flg = true;
  
  cin >> buf;
  for (char *p=buf; *p; p++){
    if (cnt[*p-'a']) flg = false;
    cnt[*p-'a'] ++;
  }
  cout << (flg?"yes":"no") << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
using namespace std;
using lli = long long int;

lli nc2(lli l) {
	if (l < 2)return 0;
	lli ret = l;
	return (l * (l - 1)) / 2;
}

int main() {
	int N;
	cin >> N;
	vector<lli> v(N+1);
	for (int i = 1; i <= N; i++) {
		cin >> v[i];
	}

	for (int i = 1; i <= N; i++) {
		v[i] += v[i - 1];
	}



	map<lli, lli> m;


	for (int i = 0; i <= N; i++) {
		m[v[i]]++;
	}
	lli ans = 0;
	for (auto i : m) {
		ans += nc2(i.second);
		//cerr << i.first << " : " << i.second << endl;
	}
	
	cout << ans << endl;

}

Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
int m,d,ans;
signed main(){
    cin >> m >> d;
    for(int i = 1;  i <= m; i++) {
        
        for(int j=1; j <= d; j++) {
            int ge = j%10, shi=j/10;
            if(ge>=2 && shi>=2 && ge*shi==i) {
                ans++;
                // printf("%d %d\n",i,j);
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
  ll n; cin >>n;
  vector<ll> a(n);
  rep(i,n) cin >>a[i];
  ll count=1;
  int k=0;
  rep2(i,0,n-1){
    if(a[i+1]-a[i]>0){
      if(k==-1){
        count++;
        k=0;
      }else{
        k=1;
      }
    }
    if(a[i+1]-a[i]<0){
      if(k==1){
        count++;
        k=0;
      }else{
        k=-1;
      }
    }
       
  }
  cout <<count<<endl;
} 

Measured memory_bytes: 4000
import java.util.Scanner;
class Main {
	public static void main(String[] args){
		 Scanner scn = new Scanner(System.in);
		    int a = scn.nextInt();
		    int b = scn.nextInt();
		    int c = scn.nextInt();

	    	 if(c>b&b>a){
			     System.out.println(a+" "+b+" "+c);
			 }
			 if(b>c&c>a){
				 System.out.println(a+" "+c+" "+b);
			 }
			 if(a>c&c>b){
				 System.out.println(b+" "+c+" "+a);
			 }
			 if(c>a&a>b){
				 System.out.println(b+" "+a+" "+c);
			 }
			 if(b>a&a>c){
				 System.out.println(c+" "+a+" "+b);
			 }
			 if(a>b&b>c){
				 System.out.println(c+" "+b+" "+a);
			 }
			 if(a==b&b==c){
				 System.out.println(a+" "+a+" "+a);
			 }
			 if(a==b&b>c){
				 System.out.println(c+" "+a+" "+a);
			 }
			 if(a==b&c>b){
				 System.out.println(a+" "+a+" "+c);
			 }

			 if(a>c&b==c){
				 System.out.println(b+" "+b+" "+a);
			 }
			 if(c>a&b==c){
				 System.out.println(a+" "+b+" "+b);
			 }
			 if(b>a&a==c){
				 System.out.println(a+" "+c+" "+b);
			 }
	}
}

Measured memory_bytes: 26272
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(void)
{
char S[11], T[11], U[11];
long A, B;
  scanf("%s %s", S, T);
  scanf("%ld %ld", &A, &B);
  scanf("%s", U);
  if (strcmp(S, U) == 0) {
    A--;
  } else {
    B--;
  }
  printf("%ld %ld\n", A, B);

  return 0;
}

Measured memory_bytes: 128
package main

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

func main() {
	A, P := nextInt(), nextInt()
	fmt.Println((A*3 + P) / 2)
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextFloat() float64 {
	sc.Scan()
	f64, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}

	return f64
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func abs(x int) int {
	return int(math.Abs(float64(x)))
}

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

// ---------- Util.


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/








string S; int N;
//---------------------------------------------------------------------------------------------------
string solve() {
    map<char, int> cnt;

    string ans = "zzzzzzzzzzzzzzzzzzzzzzzzzz";
    char las = 'a' - 1;
    S += las;
    N++;

    rep(i, 0, N) {
        string s = S.substr(0, i);
        rep(j, 0, 26) {
            char c = 'a' + j;
            if (S[i] < c and cnt[c] == 0) {
                string ss = s + c;
                if (S < ss and ss < ans) ans = ss;
            }
        }
        cnt[S[i]]++;
        if (cnt[S[i]] == 2) break;
    }

    if (ans == "zzzzzzzzzzzzzzzzzzzzzzzzzz") return "-1";
    return ans;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> S;
    N = S.length();
    cout << solve() << endl;
}

Measured memory_bytes: 256
import Foundation

let args = readLine()!.split(separator: " ")
let N = Int(args[0])!
let M = Int(args[1])!
let a = [Int](unsafeUninitializedCapacity: M) { buffer, _ in
    for m in 0 ..< M {
        buffer[m] = Int(readLine()!)!
    }
}

var step = 0
var s1 = 1
var s2 = 0

var n = N - 1
var m = M - 1
while 0 <= n {
    let isStepBroken = 0 <= m && a[m] == n
    if isStepBroken {
        step = 0
        m -= 1
    } else {
        step = (s1 + s2) % 1_000_000_007
    }
    s2 = s1
    s1 = step
    n -= 1
}
let answer = step

print(answer)


Measured memory_bytes: 14296
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
const int maxn=3005;
char s1[maxn];
char s2[maxn];
int len1,len2;
int dp[maxn][maxn];
int pre[maxn][maxn];
inline void print(int x,int y){
	if(x==0||y==0) return;
	if(pre[x][y]==0){
		print(x-1,y-1);
		printf("%c",s1[x]);
	}else if(pre[x][y]==-1) print(x,y-1);
	else print(x-1,y);
}
int main(){
	scanf("%s",s1+1);
	scanf("%s",s2+1);
	len1=strlen(s1+1);
	len2=strlen(s2+1);
	for(int i=1;i<=len1;i++)
		for(int j=1;j<=len2;j++){
			if(s1[i]==s2[j]){
				dp[i][j]=dp[i-1][j-1]+1;
				pre[i][j]=0;
			}else{
				if(dp[i][j-1]>=dp[i-1][j]){
					dp[i][j]=dp[i][j-1];
					pre[i][j]=-1;
				}else{
					dp[i][j]=dp[i-1][j];
					pre[i][j]=1;
				}
			}
		}
	if(dp[len1][len2]==0) printf(" ");
	else print(len1,len2);
	printf("\n");
	return 0;
}

Measured memory_bytes: 70784
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

struct mint {
  ll x;
  mint(ll x = 0) : x(x % MOD) {}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  REP(i, 1, 10) {
    ll x = 111 * i;
    if (n <= x) {
      cout << x << endl;
      return 0;
    }
  }
  return 0;
}


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

int main ()
{
	int t1,t2,t3;
	cin>>t1>>t2>>t3;
	cout<<max(max(t1,t2),t3)-min(min(t1,t2),t3)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
        char x[1001];

        while(1){
                scanf("%s", x);

                int sum = 0, len = 0;
                if(x[0] == '0'){
                        break;
                }else{
                        while(x[len])
                                len++; 
                        while(len-- > 0)
                                sum += (x[len] - '0');
                        printf("%d\n", sum);
                }
        }

        return 0;
}

Measured memory_bytes: 536
// ------------------------------------
// Date:2018/ 3/15
// Problem:AGC 012 AtCoderGroupContest a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;

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

  int N;
  cin >> N;
  vector< int > A(3 * N);
  REP(i, 3 * N) cin >> A[i];

  sort(ALL(A));

  ll ans = 0ll;
  for (int i = N; i < 3 * N; i += 2) {
    ans += A[i];
  }
  cout << ans << endl;
  
  return 0;
}



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


void solve(long long D, long long N){
    cout << (N==100 ? 101 : N)*(int)pow(10, 2*D) << endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long D;
    scanf("%lld",&D);
    long long N;
    scanf("%lld",&N);
    solve(D, N);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);i++)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;i--)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 998244353;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> void chmin(T& t, const U& u){if(t>u)t=u;}
template<typename T,typename U> void chmax(T& t, const U& u){if(t<u)t=u;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T mpow(T a, T n) {
   T res = 1;
   for(;n;n>>=1) {
      if (n & 1) res = res * a;
      a = a * a;
   }
   return res;
}

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

const ll MAX = 300010;//設定して

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;//＊１
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

signed main(){
    COMinit();
    ll n,a,b,k,ans=0;cin>>n>>a>>b>>k;
    rep(i,0,n+1){
        if((k-a*i)%b==0 && 0<=(k-a*i)/b && (k-a*i)/b<=n){
            ans+=(COM(n,i)*COM(n,(k-a*i)/b))%mod;
            ans%=mod;
        }
    }
    cout<<ans<<endl;
}

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

int main() {
  int N;
  cin>>N;
  string S;
  cin>>S;
  int ans=1;
  for(int i=0;i<N-1;i++){
    if(S[i]!=S[i+1]) ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <functional>

using namespace std;

int INF = 10000000;

int n,m;

int t[100];
int h[100];

int main()
{

	while(cin >> n >> m && n && m)
	{
		int tmax = 0;
		int hmax = 0;

		for(int i = 0;i < n;i++)
		{
			cin >> t[i];
			tmax += t[i];
		}
		for(int i = 0;i < m;i++)
		{
			cin >> h[i];
			hmax += h[i];
		}


		int Min = INF;
		int mh = -1;
		int mt = -1;

		for(int i = 0;i < n;i++)
		{
			for(int j = 0;j < m;j++)
			{
				if(hmax + t[i] - h[j] == tmax + h[j] - t[i])
				{
					if(Min > h[j] + t[i])
					{
						mh = h[j];mt = t[i];
						Min = h[j] + t[i];
					}
				}
			}
		}

		if(mt == -1 ) cout << -1 << endl;
		else cout << mt << " " << mh << endl;

	}

  return 0;
}

Measured memory_bytes: 1160
A, B, C, X, Y = map(int,input().split())
 
if A + B < 2 * C:
    print(A * X + B * Y)
elif min(X, Y) * 2 * C + abs(X - Y)*( A if X > Y  else B) > (max(X , Y) * 2 * C):
    print(max(X , Y) * 2 * C)
else:
    print(min(X, Y) * 2 * C + abs(X - Y)*( A if X > Y  else B) )

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

bool used[26];

signed main()
{   
    string s; cin>>s;
    REP(i,s.size()) used[s[i]-'a']=true;
    REP(i,26) if(!used[i]){
        s+='a'+i;
        cout<<s<<endl;
        return 0;
    }
    
    int i=s.size()-1;
    while(i>=1 and s[i-1]>s[i]) i--;
    if(i==0){
        cout<<-1<<endl;
        return 0;
    }
    char c='~';
    for(int j=i;j<s.size();j++) if(s[j]>s[i-1]) c=min(c,s[j]);
    s[i-1]=c;
    cout<<s.substr(0,i)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include<list>
#include<iomanip>
#include<cmath>
#include<queue>
#include <functional>
#include<stdio.h>
#include<assert.h>
#include<stack>
#include<sstream>
#include <cstdlib>
#include<map>
#include<algorithm>
#include<iostream>
#include<set>
#include<utility>
#include<memory.h>
#include<string>
#include<vector>
#include<numeric>
using namespace std;
#define ll  long long
#define pb push_back
#define sz(v)               ((int)((v).size()))
#define all(x)          (x).begin(),(x).end()
#define REP(i, v)       for(int i=0;i<sz(v);i++)
typedef pair<int,int> pii;
#define ios std::ios_base::sync_with_stdio(false);
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <utility>
#include <cstring>
#include <cassert>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

const int MAXN = 205000;

int len;
string s;
ll f[26];
int main()
{
	cin >> s;
	len = sz(s);
	ll ans = 0;
	for(int i = 0 ; i < len ; ++i)
	{
		for(int j = 0 ; j < 26 ; ++j)
		{
			if(j == s[i] - 'a')
				continue;
			ans += f[j];
		}
		f[s[i] -'a']++;
	}
	cout << 1 + ans << "\n";


}


Measured memory_bytes: 640
N = gets.to_i
A = N.times.map { gets.to_i }

ans = 0

N.times do |i|
  if A[i] >= 2
    cnt = A[i] / 2
    ans += cnt
    A[i] -= 2 * cnt
  end

  if i < N - 1 && A[i] > 0 && A[i + 1] > 0
    cnt = [A[i], A[i + 1]].min

    ans += cnt
    A[i] -= cnt
    A[i + 1] -= cnt
  end
end

puts ans


Measured memory_bytes: 2996
N, M =map(int, input().split())
ls = []
pcount =[]
for i in range(N):
    pcount.append(0)
for i in range(M):
    p, y = map(int, input().split())
    ls.append([i, p, y])
ls.sort(key = lambda x:x[2])

for l in ls:
    pcount[l[1]-1] += 1
    l.append(pcount[l[1]-1])
ls.sort(key = lambda x:x[0])
for l in ls:
    print(str(l[1]).zfill(6) + str(l[3]).zfill(6))


Measured memory_bytes: 31824
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdlib>

int main(int argc, char *argv[]){
	//std::ifstream datafile(argv[1]); //input datafile
	std::string str;
	int num[3] = {}; //a, b, c
	int N; //N
	int tmp;

	// if(datafile.fail()){
	// 	std::cout << "error : can't open this file." << std::endl;
	// 	exit(1);
	// }

	//read N
	std::getline(std::cin, str);
	sscanf(str.c_str(), "%d", &N);

	if(N < 0 || N > 1000){
		std::cout << "error : out of constraints" << std::endl;
		exit(1);
	}

	//read dataset
	while(std::getline(std::cin, str)){
		sscanf(str.c_str(), "%d%d%d", &num[0], &num[1], &num[2]);

		for(size_t i = 0; i < 3; i++){
			if(num[i] < 1 || num[i] > 1000){
				std::cout << "error : out of constraints" << std::endl;
				exit(1);
			}
		}

		//bubble sort
		for(size_t i = 0; i < 2; i++){
			for(size_t j = 2; j > i; j--){
				if(num[j-1] > num[j]){
					tmp = num[j-1];
					num[j-1] = num[j];
					num[j] = tmp;
				}
			}
		}

		//Pythagorean theorem
		if(std::pow(num[2], 2) == std::pow(num[0], 2) + std::pow(num[1], 2)){
			std::cout << "YES" << std::endl;
		}else{
			std::cout << "NO" << std::endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3232
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int (i)=0;(i) < (N); (i)++)
#define all(V) V.begin(), V.end()
using i64 = int_fast64_t;
using P = pair<i64,i64>;

int main(){
    int N,M;
    cin >> N >> M;
    priority_queue<double> que;
    rep(i,N){
        int x;
        cin >> x;
        que.push(x);
    }

    while(M){
        double d = que.top();
        que.pop();
        d /= 2.0;
        que.push(d);
        M--;
    }

    i64 ans = 0;
    while(!que.empty()){
        double d = que.top();
        que.pop();
        ans += floor(d);
    }

    cout << ans << endl;
}


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

int main()
{
int a,b,c,d,e = 0;
 cin >> a >> b >> c >>d>>e;
if(a ==0){cout << 1<<endl; 
     }
if(b ==0){cout << 2<<endl; 
     }
if(c ==0){cout << 3<<endl; 
     }
if(d ==0){ cout << 4<<endl; 
     }
if(e ==0){cout << 5<<endl; 
     }
}

Measured memory_bytes: 3628
N = int(input())

count = 0
result = 0
for i in range(1, N+1):
    if 0 != i % 2:
        count = 0
        for j in range(1, i+1):
            if 0 == i % j:
                count += 1
            if 8 == count:
                result += 1
print(result)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long n,sum,sum1,m3,m5,m15,s3,s5,s15;
    cin>>n;
    sum=n*(n+1)/2;
    m3=n/3;
    m5=n/5;
    m15=n/15;
    s3= m3*(2*3 +(m3 -1)*3)/2;
    s5= m5*(2*5 +(m5 -1)*5)/2;
    s15= m15*(2*15 +(m15 -1)*15)/2;
    sum1=s3+s5-s15;
    cout<<sum-sum1;
    return 0;
}

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

namespace ARC081
{
    class C
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            long[] A = Console.ReadLine().Split().Select(long.Parse).OrderByDescending(x => x).ToArray();

            long res = 1;
            int count = 0;
            for (int i = 0; i < N - 1; i++)
            {
                if (i < N && A[i] == A[i + 1]) { res *= A[i]; count++; i++; }
                if (count == 2) break;
            }

            if (count < 2) Console.WriteLine(0);
            else Console.WriteLine(res);
        }
    }
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int sx = 0, sy = 0, gx, gy;
    cin >> gx >> gy;
    int i = 0;
    while (i < s.length() && s[i] == 'F') {
        sx++;
        i++;
    }
    i++;
    vector<int> vx, vy;
    bool direc_x = false;
    int F_cnt = 0;
    for (i; i < s.length(); ++i) {
        if (s[i] == 'F' && i != s.length() - 1) F_cnt++;
        else {
            if (s[i] == 'F') F_cnt++; //最後のF
            if (direc_x) vx.push_back(F_cnt);
            else vy.push_back(F_cnt);
            direc_x ^= 1;
            F_cnt = 0;
        }
    }
    set<int> st_x, st_y;
    st_x.insert(sx);
    st_y.insert(sy);
    for (auto move : vx) {
        set<int> before_pos = st_x;
        st_x.clear();
        for (auto b : before_pos) {
            st_x.insert(b + move);
            st_x.insert(b - move);
        }
    }
    for (auto move : vy) {
        set<int> before_pos = st_y;
        st_y.clear();
        for (auto b : before_pos) {
            st_y.insert(b + move);
            st_y.insert(b - move);
        }
    }
    cout << (st_x.count(gx) && st_y.count(gy) ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 768
fun main(args : Array<String>) {
    var (A, B, K) = readLine()!!.split(" ").map { it.toInt() }

    (1..K).forEach {
        if (it % 2 == 1) {
            if (A % 2 == 1) {
                A--
            }
            B += A / 2
            A = A /2
        } else {
            if (B % 2 == 1) {
                B--
            }
            A += B / 2
            B = B / 2
        }
    }

    println("${A} ${B}")
}

Measured memory_bytes: 37500
N = int(input())
X = list(map(int, input().split()))
Y = X.copy()
Y.sort()
for i in range(len(X)):
	if X[i] <= Y[int(N/2) - 1]:
		print(Y[int(N/2)])
	else:
		print(Y[int(N/2) - 1])

Measured memory_bytes: 25228
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(void)
{
 ll i,j,k,t,n;
 cin>>n;
 ll a[n+1];
 for(i=1;i<=n;i++)
    cin>>a[i];
 ll dp[n+1]={};
 dp[0]=0;
 dp[1]=0;
 dp[2]=abs(a[2]-a[1]);
 for(i=3;i<=n;i++)
    {
     dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
	}
 cout<<dp[n]<<endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		System.out.println(facto(n));
	}

	public static long facto(int n) {
		if (n == 1) return 1;

		return n * facto(n-1);
	}
}

Measured memory_bytes: 26060
#include<iostream>
#include<map>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;

typedef pair<int,int> P;
typedef pair<int,P> P2;

int n,m,l,k;
int u,v,c;
int s,g,t;
int b[7];

int dis[51][1<<7][10],vis[51][1<<7];
vector<P> G[51];
const int INF = 100000000;

int main(){
  while(cin >> n >> m >> l >> k,n+m+l+k){
    for(int i=1;i<=n;i++)G[i].clear();
    for(int i=0;i<m;i++){
      cin >> u >> v >> c;
      G[u].push_back(P(c,v));
      G[v].push_back(P(c,u));
    }
    cin >> s >> g;
    for(int i=0;i<l;i++)cin >> b[i];

    for(int i=1;i<=n;i++)
      for(int j=0;j<(1<<l);j++){
	for(int x=0;x<k;x++)dis[i][j][x] = INF;
	vis[i][j] = 0;
      }

    int st = 0;
    for(int i=0;i<l;i++)if(s==b[i])st |= 1<<i;

    priority_queue< P2,vector<P2>,greater<P2> > q;
    q.push(P2(0,P(s,st)));
    
    while(q.size()){
      P2 p = q.top(); q.pop();
      int dist = p.first, pos = p.second.first, state = p.second.second;

      if(vis[pos][state] < k){
	dis[pos][state][vis[pos][state]] = dist;
	vis[pos][state]++;
	if(pos==g && state==(1<<l)-1 && vis[pos][state]==k)break;
      }else continue;

      for(int i=0;i<G[pos].size();i++){
	int cost = G[pos][i].first, nxt = G[pos][i].second;
	int nstate = state;
	for(int j=0;j<l;j++)if(nxt==b[j])nstate |= 1<<j;

	if(vis[nxt][nstate] < k)q.push(P2(dist+cost,P(nxt,nstate)));
      }
    }
    int res = dis[g][(1<<l)-1][k-1];
    if(res==INF)cout << "NA\n";
    else cout << res << endl;
  }
}
      

Measured memory_bytes: 41336
#include<stdio.h>
main(){
  int mount[11],i,j,k,tmp;
  for(i=0;i<10;i++){
    scanf("%d",&mount[i]);
  }
  for(i=0;i<10;i++){
    for(j=9;j>i;j--){
      if(mount[j]<mount[j-1]){
	tmp=mount[j];
	mount[j]=mount[j-1];
	mount[j-1]=tmp;
      }
    }
  }
  printf("%d\n%d\n%d\n",mount[9],mount[8],mount[7]);
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define LL long long
#define INF 0x7FFFFFFF//or 0x3f3f3f3f ? -Wall
using namespace std;

template<class T> inline
void read(T& x) {
	int f = 1; x = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9')   {if (ch == '-') f = -1; ch = getchar();}
	while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}

/*============ Header Template ============*/

const int N = 100000 + 5;

int n;
char s[N];
int a[N];

int cc(int x) {
	if (a[x] == 1) {
		if (s[x] == 'o') {
			if (a[x - 1] != a[x + 1]) return 0;
		}
		if (s[x] == 'x') {
			if (a[x - 1] == a[x + 1]) return 0;
		}
	}
	if (a[x] == 2) {
		if (s[x] == 'x') {
			if (a[x - 1] != a[x + 1]) return 0;
		}
		if (s[x] == 'o') {
			if (a[x - 1] == a[x + 1]) return 0;
		}
	}
	return 1;
}

int check() {
	for (int i = 2; i <= n; i++) {
		if (a[i] == 1) {
			if (s[i] == 'o') {
				a[i + 1] = a[i - 1];
			} else if (s[i] == 'x') {
				a[i + 1] = 3 - a[i - 1];
			}
		} else if (a[i] == 2) {
			if (s[i] == 'x') {
				a[i + 1] = a[i - 1];
			} else if (s[i] == 'o') {
				a[i + 1] = 3 - a[i - 1];
			}
		}
	}
	a[0] = a[n];
	a[n + 1] = a[1];
	if (!cc(1) || !cc(n)) return 0;
	return 1;
}

void print() {
	for (int i = 1; i <= n; i++) if (a[i] == 1) printf("S");
		else printf("W");
}

int main() {
	read(n);
	scanf("%s", s + 1);
	for (int i = 1; i <= 2; i++)
		for (int j = 1; j <= 2; j++) {
			memset(a, 0, sizeof a);
			a[1] = i;
			a[2] = j;
			if (check()) {
				print();
				return 0;
			}
		}
	printf("-1\n");
	return 0;
}

Measured memory_bytes: 768
def solve(n, m, v, p, a)
  a = a.sort.reverse
  a.unshift nil

  xmin = 0
  xmax = n + 1
  loop do
    break if xmin + 1 == xmax
    x = ((xmin + xmax) / 2).floor
    r = if x <= p
          true
        elsif a[x] + m < a[p]
          false
        else
          b = [0]
          1.upto(n) do |i|
            if p <= i && i < x
              b[i] = a[x] + m - a[i]
            else
              b[i] = m
            end
          end
          b.inject(:+) >= m * v
        end

    if r
      xmin = x
    else
      xmax = x
    end
  end
  return xmin
end

n, m, v, p = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
puts solve(n, m, v, p, a)


Measured memory_bytes: 24316
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
using Graph = vector<vector<ll>>;

int main(){
  int n;cin>>n;
  n %= 10;
  if(n == 2 ||
  n == 4 ||
  n == 5 ||
  n == 7 ||
  n == 9 ) cout << "hon" << endl;
  else if(n == 0 ||
  n == 1 ||
  n == 6 ||
  n == 8 ) cout << "pon" << endl;
  else cout << "bon" << endl;

}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define pb push_back
#define mp make_pair
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s, t, res = "";
    cin>>s>>t;
    res = t + s;
    cout<<res;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define all(x) begin((x)), end((x))
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}


int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll l,r,d;cin>>l>>r>>d;
    ll cnt = 0;
    repr(i,l,r+1) {
        if (i%d==0) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3644
K=input()

def sunuke(m):
	a=sum( map(int,list(str(m))) )
	return float(m)/a

def f(n):
	res=n
	snk=sunuke(n)

	for keta in range(1,15):
		val=n%10
		n/=10
		for i in range(val,10):
			t=n*(10**keta)+i*(10**(keta-1))+(10**(keta-1))-1
			if sunuke(t)<snk:
				snk=sunuke(t)
				res=t
	return res


N=1
for i in range(K):
	N=f(N)
	print N
	N+=1



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

// B - Bingo
struct Bingo {
    int no;
    bool match;
};
Bingo bingoes[3][3];

int main() {
    int A;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> A;
            bingoes[i][j].no = A;
            bingoes[i][j].match = false;
        }
    }

    int N, B;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> B;

        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (B == bingoes[i][j].no) {
                    bingoes[i][j].match = true;
                }
            }
        }
    }

    for (int i = 0; i < 3; i++) {
        if (bingoes[i][0].match && 
            bingoes[i][1].match &&
            bingoes[i][2].match) {
                cout << "Yes";
                return 0;
        }
        if (bingoes[0][i].match && 
            bingoes[1][i].match &&
            bingoes[2][i].match) {
                cout << "Yes";
                return 0;
        }
    }

    if (bingoes[0][0].match && 
        bingoes[1][1].match &&
        bingoes[2][2].match) {
            cout << "Yes";
            return 0;
    }

    if (bingoes[2][0].match && 
        bingoes[1][1].match &&
        bingoes[0][2].match) {
            cout << "Yes";
            return 0;
    }

    cout << "No";
}


Measured memory_bytes: 3632
fn main() {
    let (a, b): (String, String) = readln();
    let c = a + &b;
    let x = c.parse::<i64>().unwrap();
    let y = (x as f64).sqrt() as i64;
    if y * y == x {
        println!("Yes");
    } else {
        println!("No");
    }
}

// --- template ---
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::HashSet;

pub trait FromLn {
    fn fromln(s: &str) -> Self;
}
pub fn readln<T: FromLn>() -> T {
    let mut buf = String::new();
    let _ = ::std::io::stdin().read_line(&mut buf).unwrap();
    T::fromln(buf.trim())
}
pub fn readlns<T: FromLn>(n: usize) -> Vec<T> {
    let mut vs = vec![];
    for _ in 0..n {
        vs.push(readln());
    }
    vs
}
macro_rules! fromln_primitives {
    ($($t:ty),*) => { $(
        impl FromLn for $t {
            fn fromln(s: &str) -> $t {
                s.parse().unwrap()
            }
        }
    )* }
}
fromln_primitives!(
    String,
    bool,
    f32,
    f64,
    isize,
    i8,
    i16,
    i32,
    i64,
    usize,
    u8,
    u16,
    u32,
    u64
);
impl<T> FromLn for Vec<T>
where
    T: FromLn,
{
    fn fromln(s: &str) -> Vec<T> {
        s.split_whitespace().map(T::fromln).collect()
    }
}
impl FromLn for Vec<char> {
    fn fromln(s: &str) -> Vec<char> {
        s.chars().collect()
    }
}
macro_rules! fromln_tuple {
    ($($t:ident),*) => {
        impl<$($t),*> FromLn for ($($t),*) where $($t: FromLn),* {
            fn fromln(s: &str) -> ($($t),*) {
                let mut it = s.split_whitespace();
                let t = ($($t::fromln(it.next().unwrap())),*);
                assert_eq!(it.next(), None);
                t
            }
        }
    }
}
fromln_tuple!(A, B);
fromln_tuple!(A, B, C);
fromln_tuple!(A, B, C, D);
fromln_tuple!(A, B, C, D, E);
fromln_tuple!(A, B, C, D, E, F);


Measured memory_bytes: 4352
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n = INT()
a = LIST()
if len(set(a)) == n:
    print("YES")
else:
    print('NO')

Measured memory_bytes: 113776
#include <stdio.h>
#include <string.h>
#include <math.h>

int main(void)
{
    int n, i, j;
    scanf("%d", &n);
    int a[200000], ball[200000], bsum;//bsumはボールの合計,ballはボールの有無
    for(i=0; i<n; i++) scanf("%d", &a[i]);
    for(i=0; i<n; i++) ball[i]=0;

    for(i=n; i>0; i--)
    {
        j=1;
        bsum=0;
        while(i*(j+1)<=n)
        {
            if(ball[i*(j+1)-1]==1) bsum++;
            j++;
        }
        if(bsum%2 != a[i-1]) ball[i-1]=1;
    }

    bsum=0;
    for(i=0; i<n; i++)
    {
        if(ball[i]==1) bsum++;
    }
    printf("%d\n", bsum);
    for(i=0; i<n; i++)
    {
        if(ball[i]==1) printf("%d ", i+1);
    }

    return 0;
}

Measured memory_bytes: 2432
#include <stdio.h>

int main(void){
	int day, a, b, c, d;
	scanf("%d %d %d %d %d", &day, &a, &b, &c, &d);
	
	while(a>0 || b>0){
		a -= c;
		b-= d;
		day--;
	}
	
	printf("%d\n", day);

	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>

using namespace std;

int main(void) {
	string s;
	cin >> s;
	int l = 0, r = s.size() - 1, ans = 0;
	while (l < r) {
		if (s[l] == s[r]) {
			l++;
			r--;
		}
		else if (s[l] == 'x') {
			ans++;
			l++;
		}
		else if (s[r] == 'x') {
			ans++;
			r--;
		}
		else {
			ans = -1;
			break;
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

int main(){
    int n, k;
    vector<int> vec;

    cin >> n >> k;

    for(int i = 0; i < n; i++){
        int kuda;
        cin >> kuda;
        vec.push_back(kuda);
    }

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

    int sum = 0, ct = 0;
    for(const auto& e : vec){
        if(ct == k) break;
        ct++;
        sum += e;
    }
        cout << sum << endl;

}

Measured memory_bytes: 3612
N=int(input())
b=list(map(int,input().split()))
sa=[i-b[i-1] for i in range(1,N+1)]
ans=[0 for i in range(N)]#k番目にans[k-1]が入ったよの表
for i in reversed(range(1,N+1)):#頭からi番目
    cnt=0
    for j in range(1,N+1):
        if ans[-1*j]==0:
            if cnt!=sa[i-1]:
                cnt+=1
            else:
                ans[-1*j]=b[i-1]
                break
if all(k!=0 for k in ans):
    for i in ans:
        print(i)
else:
    print("-1")
                

Measured memory_bytes: 3064
#include <cstdio>
#include <vector>
using namespace std;

const int N = 50;
int n, m, q;
int qd[N][4];

std::vector<int> seq(int bit) 
{
	int j = 1;
	std::vector<int> r;
	for (int i = 0; i < m + n - 1; ++i) {
		if ((bit >> i) & 1) ++j;
		else r.push_back(j);
	}
	return r;
}
int get(std::vector<int> a) 
{
	int s = 0;
	for (int i = 0; i < q; ++i) if (a[qd[i][1] - 1] - a[qd[i][0] - 1] == qd[i][2]) s += qd[i][3];
	return s;
}

int main() 
{
	scanf("%d%d%d", &n, &m, &q);
	for (int i = 0; i < q; ++i) for (int j = 0; j < 4; ++j) scanf("%d", qd[i] + j);
	int mask = 1 << (m + n - 1);
	int ans = 0;
	for (int bit = 0; bit < mask; ++bit) if (__builtin_popcount(bit) == m - 1) ans = max(ans, get(seq(bit)));
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    int L, R;
    if(n == 1) {
        L = 0;
        R = 9;
    } else if(n == 2) {
        L = 10;
        R = 99;
    } else {
        L = 100;
        R = 999;
    }
    vector<int> s(m), c(m);
    for(int i = 0; i < m; i++) {
        cin >> s[i] >> c[i];
    }
    int ans = -1;
    for(int num = L; num <= R; num++) {
        int cnt = 0;
        string t = to_string(num);
        for(int i = 0; i < m; i++) {
            if(c[i] == (int)(t[s[i] - 1] - '0')) {
                cnt++;
            }
        }
        if(cnt == m) {
            ans = num;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
void fail(){
    cout << "No" << endl;
    exit(0);
}
 
int main(){
    int N;
    cin >> N;
    vector<pair<int, int>> task_p, task_n;
    for(int i=0; i<N; i++){
        string S;
        cin >> S;
        int s = 0, mn = 0;
        for(char c : S){
            s += (c == '(' ? 1 : -1);
            mn = min(mn, s);
        }
        int a = -mn, b = s;
        (b >= 0 ? task_p : task_n).emplace_back(a, b);
    }
    sort(task_p.begin(), task_p.end());
    int R = 0;
    for(auto& p : task_p){
        if(R < p.first) fail();
        R += p.second;
    }
    sort(task_n.begin(), task_n.end(), [](auto a , auto b){ return a.first+a.second > b.first+b.second; });
    for(auto& p : task_n){
        if(R < p.first) fail();
        R += p.second;
    }
    if(R) fail();
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 11468
import java.util.Scanner;

class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int[] p = new int[5];
    int k;
    for (int i = 0; i < 5; i++) {
      p[i] = scanner.nextInt();
    }
    k = scanner.nextInt();
    boolean ans = true;
    for (int i = 0; i < 5; i++) {
      for (int j = i; j < 5; j++) {
        if (p[j] - p[i] > k) {
          ans = false;
        }
      }
    }
    System.out.println(ans ? "Yay!" : ":(");
  }

}


Measured memory_bytes: 22740
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstring;
typedef pair<int, int> pint;
typedef pair<pint, int> ppint;
typedef pair<int, pint> pintp;
typedef unsigned int uint;
typedef long long llint;
typedef unsigned long long int ullint;

//container util
//------------------------------------------
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define EXIST(v,i) (find((v).begin(), (v).end(), i) != (v).end())
#define ERASE(v,i) (v).erase(remove((v).begin(),(v).end(),i),(v).end())
#define me (*this)

//repetition
//------------------------------------------
#define rep(i,s) for(int i=0; i<(int)(s); i++)

//constant
//--------------------------------------------
const int INF = 100000000;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLEAR(a) memset((a), 0 ,sizeof(a))

//debug
#define debug(x)  cerr << #x << " = " << (x) << endl

struct MONEY {
	string str;
	ullint pay;
};

int main() {
	while(1) {
		static int m, n;
		cin >> m >> n;
		if(!m && !n)
			break;
		vector<MONEY> mdata;
		rep(i,m) {
			string str;
			cin >> str;
			int start = static_cast<int>(str.find_first_not_of("*"));
			string cmpx;
			if(start != -1) {
				cmpx = str.substr(start, distance(all(str)));
			} else {
				cmpx = str;
			}
			static ullint pay;
			cin >> pay;
			MONEY m = {cmpx, pay};
			mdata.push_back(m);
		}

		ullint sum = 0;
		rep(i,n) {
			string str;
			cin >> str;
			rep(j,mdata.size()) {
				string cmpx = mdata.at(j).str;
				string cmpy = str.substr(str.length() - cmpx.length(), cmpx.length());
				if(cmpx == cmpy) {
					sum += mdata.at(j).pay;
				}
			}
		}
		cout << sum << endl;
	}

	return 0;
}

Measured memory_bytes: 936
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define INF (int) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int x, y;

int main() {
	fastio; cin >> x >> y;
	if (2*x <= y and y <= 4*x and y % 2 == 0) cout << "Yes";
	else cout << "No";
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

#define getmid(l,r) ((l) + ((r) - (l)) / 2)
#define MEM(a,b) memset(a,b,sizeof(a))
#define MP(a,b) make_pair(a,b)
#define PB push_back

typedef long long ll;
typedef pair<int,int> pii;
const double eps = 1e-8;
const int INF = (1 << 30) - 1;

vector<int> V[100010];
int fa[100010];

int Find(int x){
	return fa[x] == x ? x : fa[x] = Find(fa[x]);
}

int main(){
	int N,M;
	scanf("%d%d",&N,&M);
	for(int i = 1; i <= N; ++i){
		int K;
		scanf("%d",&K);
		for(int j = 1; j <= K; ++j){
			int a;
			scanf("%d",&a);
			V[a].PB(i);
		}
		fa[i] = i;
	}
	
	for(int i = 1; i <= M; ++i){
		if(V[i].size() == 0) continue;
		int x = Find(V[i][0]);
		for(int j = 1; j < V[i].size(); ++j){
			int y = Find(V[i][j]);
			//printf("%d %d\n",V[i][0],V[i][j]);
			if(x != y){
				fa[y] = x;
			}
		}
	}
	int num = 0;
	for(int i = 1; i <= N; ++i){
		if(fa[i] == i) num++;
	}
	if(num == 1){
		printf("YES\n");
	}
	else printf("NO\n");
	return 0;
}

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

using namespace std;

int main(){
	int a,b,k;
	cin>>a>>b>>k;
	for(int i=0;i<k;i++){
		if(i%2==0){
			if(a%2==1)a--;
				a/=2;
				b+=a;
		}
		else {
			if(b%2==1)b--;
			b/=2;
			a+=b;
	}
	}
	cout<<a<<" "<<b<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

#define FLAG3 0x01
#define FLAG5 0x02
#define FLAG7 0x04
#define FLAG_OK 0x07

int N = 0;
int cnt = 0;

void cnt753(long long num, int flag)
{
	if (num > N) return;
	else if (flag == FLAG_OK) cnt++;

	cnt753(10 * num + 3, flag | FLAG3);
	cnt753(10 * num + 5, flag | FLAG5);
	cnt753(10 * num + 7, flag | FLAG7);
}

int main()
{
	cin >> N;

	cnt753(0, 0);

	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 256