akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;

#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
 
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}

void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
////////////////////////////

int main(){fastio
    
    ll n;cin>>n;
    string s[n];
    ll a[n];
    rep(i,0,n-1)cin>>s[i]>>a[i];
    string k;cin>>k;
    ll ans=0;
    bool f=false;
    rep(i,0,n-1){
        if(f){
            ans+=a[i];
        }
        if(s[i]==k)f=true;
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
import sys
A, B, C, D = input()

for i in range(2**3):
    op = ['+', '+', '+']
    for j in range(3):
        if (i >> j) & 1 == 1:
            op[j] = '-'
    if eval(A + op[0] + B + op[1] + C + op[2] + D) == 7:
        print(A + op[0] + B + op[1] + C + op[2] + D + '=7')
        sys.exit()

Measured memory_bytes: 61016
#include <stdio.h>
int main()
{
   int a,b,c;
   scanf("%d",&a);
   scanf("%d",&b);
   scanf("%d",&c);
   {
   if((a<b)&&(b<c))
   printf("Yes\n");
   else 
   printf("No\n");
   }
 return 0;
}
  

Measured memory_bytes: 580
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
 
using namespace std;
 
#define int long long
//typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,m,a[100000],imos[100001] = {},add[100001] = {},ans = 0;
	cin >> n >> m;
	for(int i = 0;i < n;i++) {
		cin >> a[i];
		if(i){
			if(a[i - 1] < a[i]){
				imos[a[i - 1]]++;
				imos[a[i] - 1]--;
				add[a[i] - 1] += a[i] - a[i - 1] - 1;
				ans += a[i] - a[i - 1];
			}else{
				imos[0]++;
				imos[a[i] - 1]--;
				imos[a[i - 1]]++;
				imos[m]--;
				add[a[i] - 1] += a[i] + m - a[i - 1] - 1;
				ans += a[i];
			}
		}
	}
	for(int i = 1;i <= m;i++) imos[i] += imos[i - 1];
	int mi = ans;
	for(int i = 0;i < m - 1;i++){
		ans -= imos[i];
		ans += add[i];
		mi = min(mi,ans);
	}
	cout << mi << endl;
	return 0;
}

Measured memory_bytes: 2560
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const lines = input.trim().split('\n');

while (line = lines.shift()) {
  const numbers = line.split(' ');
  const a = numbers[0];
  const b = numbers[1];
  const c = numbers[2];

  if (a < b && b < c) {
    console.log("Yes");
  } else {
  console.log("No");
  }
} 


Measured memory_bytes: 15096
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>

typedef int32_t i32;

void trans(uint8_t *dp,i32 k,i32 a){
  for(i32 i=k-1;i>=a;i--){
    dp[i]|=dp[i-a];
  }
}

i32 calc(i32 *a,i32 n,uint8_t *dp,i32 k){
  if(n==1){
    i32 v=a[0];
    if(v>=k) return 0;
    for(i32 i=k-v;i<k;i++) if(dp[i]) return 0;
    return 1;
  }
  i32 m=n/2;
  uint8_t *save=(uint8_t *)calloc(k,sizeof(uint8_t));
  memcpy(save,dp,sizeof(uint8_t)*k);
  for(i32 i=m;i<n;i++) trans(dp,k,a[i]);
  i32 p=calc(a,m,dp,k);
  memcpy(dp,save,sizeof(uint8_t)*k);
  free(save);
  for(i32 i=0;i<m;i++) trans(dp,k,a[i]);
  return p+calc(a+m,n-m,dp,k);
}

void run(void){
  i32 n,k;
  scanf("%" SCNi32 "%" SCNi32,&n,&k);
  i32 *a=(i32 *)calloc(n,sizeof(i32));
  for(i32 i=0;i<n;i++) scanf("%" SCNi32,a+i);
  uint8_t *dp=(uint8_t *)calloc(k,sizeof(uint8_t));
  dp[0]=1;
  i32 ans=calc(a,n,dp,k);
  printf("%" PRIi32 "\n",ans);
}

int main(void){
  run();
  return 0;
}


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

int main(){
  int n,b;
  cin >> n;
  map<int,bool>fa;
  vector<int64_t>ok;
  for(int i=0;i<n;i++){
    cin >> b;
    if(fa[b]){
      ok.push_back(b);
      fa[b]=false;
    }else{
      fa[b]=true;
    }
  }
  sort(ok.begin(),ok.end(),greater());
  int64_t ans=0;
  if(ok.size()>=2)
    ans=ok.at(0)*ok.at(1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8128
def calc_largest_rect_in_hist(heights):
    heights.append(0)
    stack = []
    left = [0] * len(heights)
    ans = 0
    for i, height in enumerate(heights):
        while stack and heights[stack[-1]] >= height:
            idx = stack.pop()
            ans = max(ans, (i - left[idx] - 1) * heights[idx])
        left[i] = stack[-1] if stack else -1
        stack.append(i)
    heights.pop()
    return ans


def aoj_hist():
    # https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/all/DPL_3_C
    input()
    print(calc_largest_rect_in_hist([int(x) for x in input().split()]))


def aoj_rect():
    # https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/all/DPL_3_B
    H, W = map(int, input().split())
    board = [[int(x) for x in input().split()] for _ in range(H)]
    dp = [0] * W
    ret = 0
    for r in range(H):
        for c in range(W):
            dp[c] = dp[c] + 1 if board[r][c] == 0 else 0
        ret = max(ret, calc_largest_rect_in_hist(dp))
    print(ret)


if __name__ == "__main__":
    # aoj_hist()
    aoj_rect()



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

int main(){
    int n;
    int a[4] = {10, 50, 100, 500};
    bool first = true;
    while(cin >> n, n){
        int coin[4], oturi[4];
        for(int i = 0; i < 4; i++)  cin >> coin[i];

        n = -n;
        for(int i = 0; i < 4; i++)  n += coin[i]*a[i];

        for(int i = 3; i >= 0; i--){
            oturi[i] = n / a[i];
            n -= oturi[i] * a[i];
        }

        if(first)   first = false;
        else        cout << endl;

        for(int i = 0; i < 4; i++){
            if(coin[i] > oturi[i])
                cout << a[i] << " " << coin[i]-oturi[i] << endl;
        }

    }
    return 0;
}


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

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 1e18
#define M 1000000007
#define pie 3.141592653589793238
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define UQ(x) (x).resize(distance((x).begin(),unique(x.begin(),x.end())))

using namespace std;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rnd64(chrono::high_resolution_clock::now().time_since_epoch().count());

ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2) ans*=a, ans%=(mod);
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}


void init(ll* a,ll n,ll val){
	for(ll i=0;i<n;i++)
		a[i]=val;
}

void solve(){
	ll i,j,_;
	ll a,b,c,d;
	cin >> a >> b >> c >> d;
	cout << max({a*d,a*c,b*c,b*d}) << endl;
}

int main()
{
	ios::sync_with_stdio(0);
 	cin.tie(0);
	ll T=1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}




Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#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++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    rep(i, 365) {
        cout << i%26 + 1 << endl;
    }
}

Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int h,m,d;
    int s;
    while (cin >> s)
    {
        if (0 <= s && s <= 86400)
        {
            h = s / 3600;
            m = (s-(h*3600))/60;
            d = s - (h * 3600) - (m * 60);
            cout << h << ":" << m << ":" << d << endl;
        }
    }
    return (0);
}

Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

void change(string &s,int num){
  int length = (int)s.size();
  char ch = num + '0';

  for(int i = 0 ; i < length ; i++){
    if(s[i] == 'X'){
      s[i] = ch;
    }
  }

}

bool check(char ch,int size){
  if(ch == 'X' && size > 1) return true;
  return false;
}

char calc(char x,char y,char z,bool &C){
  int a = x - '0',b = y - '0',c = z - '0';
  int d = a + b + c;

  if(d >= 10){
    C = true;
    d -= 10;
  }

  return d + '0';
}

string sum(string a,string b){
  string res = "";

  reverse(a.begin(),a.end());
  reverse(b.begin(),b.end());

  int length;
  if((int)a.size() > (int)b.size()){
    length = (int)a.size();
    
    for(int i = (int)b.size() ; i < length ; i++){
      b += '0';
    }

  }
  else{
    length = (int)b.size();

    for(int i = (int)a.size() ; i < length ; i++){
      a += '0';
    }

  }

  for(int i = 0 ; i <= length ; i++)
    res += '0';

  for(int i = 0 ; i < length ; i++){
    bool C = false;
    res[i] = calc(a[i],b[i],res[i],C);
    if(C) res[i+1] = ((res[i+1]-'0') + 1) + '0';
  }

  for(int i = length ; i > 0; i--){
    
    if(res[i] == '0'){
      res.erase(res.begin()+i);
    }
    else{
      break;
    }
    
  }

  reverse(res.begin(),res.end());  

  return res;
}

int main(){
  string str;

  while(cin >> str){
    int pos_plus = str.find('+'),pos_equal = str.find('=');    

    string x = str.substr(0,pos_plus);
    string y = str.substr(pos_plus+1,pos_equal-pos_plus-1);
    string z = str.substr(pos_equal + 1);

    int start = 0;
    if(check(x[0],x.size()) || 
       check(y[0],y.size()) || 
       check(z[0],z.size())) {

      start = 1;

    }    

    int ans;
    bool found = false;
    for(int i = start ; i < 10 ; i++){
      string a = x, b = y, c = z;
   
      change(a,i); change(b,i); change(c,i);

      if(sum(a,b) == c){
	found = true;
	ans = i;
	break;
      }
    }

    if(found) cout << ans << endl;
    else cout << "NA" << endl;
  }

  return 0;
}

Measured memory_bytes: 1200
use proconio::*;

const MOD: usize = 1000000007;

fn main() {
    input!{
        s: usize,
    }

    let mut dp = vec![0usize; s + 100];
    dp[0] = 1;

    for i in 0..s {
        for j in i+3..=s {
            dp[j] += dp[i];
            dp[j] %= MOD;
        }
    }

    println!("{}", dp[s]);
}


Measured memory_bytes: 2188
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int n;
	std::cin >> n;
	std::vector<std::string> g(n);
	rep(i,n) std::cin >> g[i];
	std::vector<std::vector<int> > connected(n, std::vector<int>());
	rep(i,n) {
		rep(j,n) {
			if(g[i][j]=='1') connected[i].emplace_back(j);
		}
	}
	int max = 0;
	rep(l,n) {
		std::vector<int> dist(n,-1);
		std::queue<std::pair<int,int> > q;
		q.emplace(l,0);
		dist[l] = 0;
		// bfs;
		while(!q.empty()) {
			auto x = q.front(); q.pop();
			int i = x.first; int d = x.second;
			for(auto to:connected[i]) {
				if(dist[to]==-1) {
					q.emplace(to,d+1);
					dist[to] = d+1;
				} else if((dist[to]+d)%2==0) {
					print(-1);
					return 0;
				}
			}
		}
		for(auto i:dist) {
			max = std::max(max,i+1);
		}
	}
	print(max);

	return 0;
}


Measured memory_bytes: 768
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <climits>
#include <ctime>
#include <random>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define eps 1e-9
#define inf 0x3f3f3f3f
#define mod 1000000007
using namespace std;

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

Measured memory_bytes: 3160
n,m=map(int,input().split())
*q, = map(int,input().split())
#print(q)
l = [list(map(int,input().split())) for _ in range(m)]
l.sort(key=lambda x:x[1], reverse=True)
#print(l)
for b,c in l:
  q.extend([c]*b)
  if len(q) > n*2:
    break

print(sum(sorted(q,reverse=True)[:n]))

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

const int MAX_N = 1 << 17;
int n, dat[2 * MAX_N - 1];

// Range Minimum Query 蟻本
void init(int n_)
{
    // ２のべき乗にする
    n = 1;
    while (n < n_)
        n *= 2;
    for (int i = 0; i < 2 * n - 1; i++)
        dat[i] = INT_MAX;
}

void update(int k, int a)
{
    k += n - 1;
    dat[k] = a;
    while (k > 0)
    {
        k = (k - 1) / 2;
        dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
}

int query(int a, int b, int k, int l, int r)
{
    if (r <= a || b <= l)
        return INT_MAX;

    if (a <= l && r <= b)
        return dat[k];

    int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);
}

struct Query{
    int c;
    int x;
    int y;
};

int main(void)
{
    int n_, q_num;
    cin >> n_ >> q_num;

    init(n_);
    vector<Query> v(q_num);

    for (size_t i = 0; i < q_num; ++i)
    {
        cin >> v[i].c >> v[i].x >> v[i].y;
    }
    
    for (size_t i = 0; i < q_num; ++i)
    {
        if(0 == v[i].c){
            update( v[i].x,  v[i].y);
        }
        else{
            int answer = query(v[i].x, v[i].y + 1, 0, 0, n);
            cout << answer << std::endl;
        }
    }

    return 0;
}


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

int main()
{
	int prime[1000000];
	bool is_prime[1000000];
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i < 1000000; i++)
		is_prime[i] = true;
	for (int i = 2; i*i < 1000000; i++) {
		if (is_prime[i]) {
			for (int j = i*i; j < 1000000; j += i) {
				is_prime[j] = false;
			}
		}
	}
	
	int count = 0;
	for (int i = 0; i < 1000000; i++) {
		if (is_prime[i])
			count++;
		prime[i] = count;
	}
	int n;
	while (cin >> n) {
		cout << prime[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 7960
#include <stdio.h>

int main() {
	long long int n, a[200000], max[200000] = { 0 }, t = 0;
	long long int ans = 0;
	scanf("%lld", &n);
	for (int i = 0; i < n; i++)scanf("%lld", &a[i]);
	max[0] = a[0];
	for (int i = 1; i < n; i++) {
		if (a[i] > max[t]) {
			max[i] = a[i];
			t = i;
		}
		else max[i] = max[t];
	}
	for (int i = 0; i < n; i++)ans += max[i] - a[i];
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 4852
#include <stdio.h>

int main()
{
	int n,num,i,j,k,l;
	while(~scanf("%d",&n)){
		num=0;
		for(i=0;i<=9;i++)
			for(j=0;j<=9;j++)
				for(k=0;k<=9;k++)
					for(l=0;l<=9;l++)
						if(i+j+k+l==n)
							num++;
		printf("%d\n",num);					
	}
	return 0;
 } 



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

#define cel(n, k) ((n-1)/k+1)
#define sets(a) memset(a, 1, sizeof(a))
#define clr(a) memset(a, 0, sizeof(a))
#define dbg(x) cout << "Line " << __LINE__ <<": " << x << nl
#define pb push_back
#define nl "\n"
#define sp " "

#define _ ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define file() freopen("in.txt", "r", stdin), freopen("out.txt", "w", stdout)

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

const int N = 1e3+5;

int tc = 1;

int n, k, ara[N], cnt;

int main(){_

   	//file();

   	//cin >> tc;

    while(tc--){

    	cin >> n >> k;

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

    	sort(ara, ara+n);

    	for(int i = 0; i < k; i++){
    		cnt += ara[i];
    	}

    	cout << cnt << nl;

    	
    	
    }
    

    return 0;
}


Measured memory_bytes: 3660
#include <string.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <cstring>
#include <math.h>
#include <set>
#include <vector>
#include <algorithm>
#include <map>


using namespace std;

typedef long long ll;
const double PI = acos(-1.0);
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

char s[105];

int main(){
    ios::sync_with_stdio(false);
    ll i, k, len, onelen;
    while(scanf("%s%lld", s, &k)!=EOF){
        onelen = 0, len = strlen(s), i = 0;
        while(i < len && s[i] == '1') i++;
        onelen = i;
        if(k <= onelen)
            printf("1\n");
        else
            printf("%c\n", s[onelen]);
    }

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
namespace aizu
{
    class OnlineJudge
    {
        static void Main()
        {
            string input;
            while((input = Console.ReadLine()) != null) {
                int number = -1;
                for(int i=0; i <= 9; ++i) {
                    string temp = input.Replace('X', (char)('0' + i));
                    string[] values = temp.Split("+=".ToCharArray());
                    if(i == 0) {
                        bool continueFlag = false;
                        for(int j=0; j < 3;++j){
                            if(values[j].Length >= 2 && values[j][0] == '0') {
                                continueFlag = true;
                                break;
                            }
                        }
                        if(continueFlag) {
                            continue;
                        }
                    }
                    if(values[2].CompareTo(AddStringNumber(values[0], values[1])) == 0) {
                        number = i;
                        break;
                    }
                }
                Console.WriteLine(number != -1 ? number.ToString() : "NA");
            }
        }
        static string AddStringNumber(string number1, string number2)
        {
            bool carry = false;
            StringBuilder result = new StringBuilder();
            Stack<char>[] number = new[] { new Stack<char>(number1.ToCharArray()), new Stack<char>(number2.ToCharArray()) };
            while(number[0].Count != 0 || number[1].Count != 0) {
                int total = ((number[0].Count > 0 ? number[0].Pop() : '0') + (number[1].Count > 0 ? number[1].Pop() : '0') + (carry ? 1 : 0)) - '0' * 2;
                carry = total / 10 != 0;
                result.Insert(0, (total % 10).ToString());
            }
            if(carry) {
                result.Insert(0, '1');
            }
            return result.ToString();
        }
    }
}

Measured memory_bytes: 6744
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
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; }
const int INF = 1e9;
const ll MOD = 1000000007;
const double pi = 3.141592653589;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {return (a%b) ? gcd(b, a%b) : b;}
ll modPow(ll x, ll n) {
    if(n==0) return 1;
    ll res = modPow(x*x%MOD, n/2);
    if(n&1) res=res*x%MOD;
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<string> v;
    string s,str;
    getline(cin,str);
    stringstream ss{str};
    while(getline(ss, s, ' ')) {
        v.pb(s);
    }
    rep(i,v.size()) {
        rep(j,v[i].size()) {
            if (v[i][j]>='a' && v[i][j]<='z') {
                v[i][j] = v[i][j]-32;
            } else if (v[i][j]>='A' && v[i][j]<='Z') {
                v[i][j] = v[i][j]+32;
            }
        }
    }
    rep(i,v.size()) {
        if (i) {
            cout << " ";
        }
        cout << v[i];
    }
    cout << "\n";
}


Measured memory_bytes: 3232
#include<bits/stdc++.h>
using namespace std;
int main() {
    int N, ans = 0;
    cin >> N;
    int d[200];
    int a[200] = {0};

    for(int i=1; i<= N; i++) {
        cin >> d[i];
    }
    for(int i=1; i<=N; i++) {
        int t = d[i];
        a[t] = 1;
    }
    for(int i = 1; i<=100; i++) {
        ans += a[i];
    }
    cout << ans << endl;
}

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

typedef long long ll;
typedef pair<int, int> ii;

const int MOD = 1e9 + 7;
ll n;

map<ll, ll> dp;
ll f(ll x) {
  if (dp[x]) return dp[x];
  return dp[x] = (f(x/2) + f((x-1)/2) + f((x-2)/2)) % MOD;
}

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

  cin >> n;

  dp[0] = 1;
  dp[1] = 2;
  ll res = f(n);
  cout << res << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <memory>
#include <limits.h>

using namespace std;

void printarray(int n, int a[]){
	for (int i=0; i<n; i++){
		cout << a[i] << " ";
	}
	cout << endl;
}

void merge(int A[], int left, int mid, int right, long long int& cnt){
	//cout << "merge" << endl;
	int n1;
	int n2;
	n1 = mid - left;
	n2 = right - mid;
	int* L = new int[n1+1];
	int* R = new int[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] = INT_MAX;
	R[n2] = INT_MAX;
	//printarray(n1,L);
	//printarray(n2,R);
	int i = 0;
	int j = 0;
	for (int k = left; k<right; k++){
		if (L[i] < R[j]){
			A[k] = L[i++];
		}
		else{
			A[k] = R[j++];
			cnt+=n1-i;
		}
	}
	delete[] L;
	delete[] R;
}

void mergesort(int A[], int left, int right, long long int& cnt){
	int mid;
	if (left+1 < right){
		mid = int((left+right)/2);
		mergesort(A,left,mid,cnt);
		mergesort(A,mid,right,cnt);
		merge(A,left,mid,right,cnt);
	}
}

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

	int* A = new int[n];
	int tmp;
	long long int cnt = 0;
	for (int i=0; i<n; i++){
		cin >> tmp;
		A[i] = tmp;
	}

	mergesort(A, 0, n, cnt);
	delete[] A;

	cout << cnt << endl;

	return 0;
}



Measured memory_bytes: 4332
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

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

  vector<int> s(m);
  vector<char> c(m);
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];

  string ans = "1";
  if (n > 1) {
    for (int i = 1; i < n; i++) ans += "0";
  } else {
    ans = "0";
  }

  for (int i = 0; i < m; i++) ans[s[i] - 1] = c[i];

  bool ok = true;
  for (int i = 0; i < m; i++) ok &= (ans[s[i] - 1] == c[i]);
  if (n > 1 && ans[0] == '0') ok = false;

  if (ok) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
}


Measured memory_bytes: 3564
#include<iostream>
#include<cstring>
using namespace std;
    int judge(string a,string b, int n){
    int flag=1;
    for(int i=0;i<n;i++){
    if(a[i]!=b[i]){
    flag=0;
    break;
        }
     }
    return flag;
    }
    string rotation(string a,int n){
    char temp;
    temp=a[n-1];
    for(int i=n;i>0;i--){
    a[i]=a[i-1];
    }
    a[0]=temp;
    return a;
    }
int main()
{   int flag=0;
    string a,b;
    int s;
    cin>>a>>b;
    s=a.size();
    if(judge(a,b,s)){
        cout<<"Yes";
    }else{
        string temp=a;
    for(int i=0;i<s;i++){
        temp=rotation(temp,s);
        if(judge(temp,b,s)){
            flag=1;
            break;
        }
        }
    if(flag==1){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
/*
  AOJ 2435
  Title:  Zero Division Checker
  @kankichi573
*/
#include <stdio.h>
#include <string.h>
#include <setjmp.h>

jmp_buf jb;
char variable[100][21];
char expression[100][21];

int m,n;
struct uplow {
  unsigned long long usll[4];
}var[100],stack[100];
int sp;

void clear_val(struct uplow *x)
{
  x->usll[0]=x->usll[1]=x->usll[2]=x->usll[3]=0ULL;
}

void set_val(struct uplow *x,unsigned char num)
{
  x->usll[num/64] |= (1ULL<<(num % 64));
}
int is_val(struct uplow x,unsigned char num)
{
  int ret= (x.usll[num/64] & (1ULL<<(num % 64)))?1:0;
  return(ret);
}
void show_val(struct uplow x)
{
  int i;
  for(i=0;i<=255;i++)
    if(is_val(x,(unsigned char)i))
      printf("%d:",i);
  printf("\n");
}
void dump_stack()
{
  int i;
  for(i=0;i<sp;i++)
    show_val(stack[i]);
}
void dump_variable()
{
  int i;
  printf("%d variables\n",n);
  for(i=0;i<n;i++)
    show_val(var[i]);
}

int is_number(char *s)
{
  while(*s)
    {
      if(*s >= '0' && *s <= '9')
	 s++;
      else
	return(0); 
    }
  return(1);
}
int is_variable(char *s)
{
  while(*s)
    {
      if(isalpha(*s))
	 s++;
      else
	return(0); 
    }
  return(1);
}

struct uplow bin_operator(struct uplow arg1,struct uplow arg2,char op)
{
  struct uplow ret;
  int i,j;
  unsigned char res;

  if(op=='/' && is_val(arg2,0)) //div by zero
    longjmp(jb,1);
  clear_val(&ret);
  
  for(i=0;i<256;i++)
    if(is_val(arg1,(unsigned char)i))
      for(j=0;j<256;j++)
	if(is_val(arg2,(unsigned char)j))
	  {
	    if(op=='+')
	      res=i+j;
	    else if(op=='-')
	      res=i-j;
	    else if(op=='*')
	      res=i*j;
	    else if(op=='/')
	      res=i/j;
	    set_val(&ret,res);
	  }
  return(ret);
}

char operator[]="+-*/";

void eval_forth()
{
  int i,j,opn;
  char *el;
  struct uplow work,work1,work2;

  for(i=0;i<m;i++)
    {
      el=&expression[i][0];
      //printf("%d:%s %d\n",i,el,sp);
      if(is_number(el))
	{
	  clear_val(&work);
	  set_val(&work,atoi(el));
	  stack[sp]=work;
	  sp++;
	}
      else if(is_variable(el))
	{
	  for(j=0;j<n;j++)
	    if(0==strcmp(&variable[j][0],el))
	      {
		work = var[j]; 
		stack[sp]=work;
		sp++;
	      }
	}
      else
	{
	  work1=stack[sp-2];
	  work2=stack[sp-1];
  
	  work=bin_operator(work1,work2,*el);
	  sp--;
	  stack[sp-1]=work;
	}
    }
}

int solve()
{
  sp=0;
  if(setjmp( jb ) == 0 ) 
    eval_forth();
  else
    return(0);
    
  return(1);
}
main()
{
  int i,j,ret,a,b;

  memset(var,0,sizeof(long long)*4*100);
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%s %d %d",&variable[i][0],&a,&b);
      for(j=a;j<=b;j++)
	set_val(&var[i],(unsigned char)j);
    }
  //dump_variable();
  scanf("%d",&m);
  for(i=0;i<m;i++)
    scanf("%s",&expression[i][0]);
  
  ret=solve();
  //printf("solve end sp=%d\n",sp);
  //dump_stack();
  printf("%s\n",ret?"correct":"error");
  
  return(0);
}

Measured memory_bytes: 612
#include<iostream>
#include<cstdio>
#include<cmath>
#include<complex>
#include<algorithm>
#include<vector>
#include<queue>
#include<utility>
#include<set>

#define REP(i,n) for(int i= 0;i < n;i++)
#define MK make_pair
	
using namespace std;
int map[100010],sunuke,fennec;


int main()
{
	int n;
	cin >> n;
	
	vector<int> v[100001];
	
	REP(i,n-1)
	{
		int x,y;
		cin >> x >> y;
		v[x].push_back(y),v[y].push_back(x);
	}
	
	/*
	REP(i,n)
	{
		for(int j = 0;j < v[i].size();j++)
			cout << v[i][j] << ' ';
		cout << endl;
	}
	*/
	
	map[1] = 1;map[n] = -1;
	sunuke++;fennec++;
	
	queue<int> q;
	q.push(1);q.push(n);
	
	while(!q.empty())
	{
		int tmp = q.front();q.pop();
		REP(i,v[tmp].size())
		{
			int a = v[tmp][i];
			if(map[a] == 0)
			{
				map[a] = map[tmp];
				if(map[tmp] == 1)fennec++;
				else sunuke++;
				q.push(a);
			//	cout << a << ':' << map[a] << endl;
			}
			
		}

	}
	//cout << sunuke << ' ' << fennec  << endl;
	if(sunuke >= fennec)cout << "Snuke" << endl;
	else cout << "Fennec" << endl;
	
	return 0;
}

Measured memory_bytes: 6400
import sys


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def S(): return sys.stdin.readline().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


x = I()
s = x % 60
hm = x // 60
m = hm % 60
h = hm // 60
print(str(h)+':'+str(m)+':'+str(s))



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

int main() {
  string S,T,U;
  int A,B;
  
  cin >> S >> T;
  cin >> A >> B;
  cin >> U;
  if(S == U){
    A--;
  }
  else {
    B--;
  }
  cout << A <<" "<< B;
}

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

using namespace std;

typedef pair<int,int> pii;

const int N = 1e5 + 100;

vector<pii> adj[N];
int ans[N];
int n;

void dfs(int v, int p) {
    for (auto x : adj[v]) {
	int u = x.first, w = x.second;
	if (u == p) continue;
	if (w % 2)
	    ans[u] = !ans[v];
	else
	    ans[u] = ans[v];
	dfs(u, v);
    }
}

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 1; i < n; i++) {
	int v, u, w;
	cin >> v >> u >> w;
	adj[--v].push_back({--u, w});
	adj[u].push_back({v, w});
    }
    dfs(0, 0);
    for (int i = 0; i < n; i++)
	cout << ans[i] << endl;
}

Measured memory_bytes: 8448
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int n;
    cin>>n;
    auto s=to_string(n);
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='9')
            s[i]='1';
        else if(s[i]=='1')
            s[i]='9';
    }
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256
def main():
	N = int(input())
	S = input()
	brackets = [0, 0]
	for i in range(len(S)):
		if S[i] == ")":
			if brackets[0] > 0:
				brackets[0] -= 1
			else:
				brackets[1] += 1
		elif S[i] == "(":
			brackets[0] += 1
	print(brackets[1] * "(" + S + brackets[0] * ")")

main()

Measured memory_bytes: 8944
from itertools import accumulate

n, W = (int(x) for x in input().split())
WV = [tuple(int(x) for x in input().split()) for _ in range(n)]
weight = [[] for _ in range(4)]  # weight[0] ~ weight[3]
w1 = WV[0][0]
for w, v in WV:
    weight[w - w1].append(v)

for wei in weight:
    wei.sort(reverse=True)

value_acc = [[] for _ in range(4)]
for i in range(4):
    value_acc[i] = list(accumulate(weight[i]))

ans = 0
for i in range(len(weight[0]) + 1):
    for j in range(len(weight[1]) + 1):
        for k in range(len(weight[2]) + 1):
            for l in range(len(weight[3]) + 1):
                tmp = w1 * i + (w1 + 1) * j + (w1 + 2) * k + (w1 + 3) * l
                if tmp <= W:
                    value = 0
                    for x, y in zip([0, 1, 2, 3], [i, j, k, l]):
                        if y - 1 >= 0:
                            value += value_acc[x][y - 1]
                    ans = max(ans, value)

print(ans)


Measured memory_bytes: 74240
#include<bits/stdc++.h>
#define LL long long
#define M 1000005
using namespace std;
const int P=1e9+7;
int main(){
	char str[10];
	scanf("%s",str);
	if(str[0]=='7'||str[1]=='7'||str[2]=='7')puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 3760
n,k = map(int, input().split())

p = 10 ** 9 + 7
N = 10 ** 5 *5  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 3):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

ans = 0
if k < n:
    for i in range(k+1):
        ans += cmb(n,i,p)*cmb(n-1,n-i-1,p)
        ans %= p
else:
    for i in range(n):
        ans += cmb(n,i,p)*cmb(n-1,n-i-1,p)
        ans %= p

print(ans)


Measured memory_bytes: 62676
(let* ((n (read))
    (m (read))
    (k (make-array m))
    (s (make-array '(10 10) :initial-element Nil))
    (p (make-array m))
    (ans 0))

    (dotimes (i m)
        (setf (aref k i) (read))
        (dotimes (j (aref k i))
            (setf (aref s i j) (read))
        )
    )
    (dotimes (i m)
        (setf (aref p i) (read))
    )

    (loop for x below (expt 2 n) do
        (let ((on (make-array 10)))
            (loop for y below n do
                (if (= (logand (ash x (- y)) #b1) 1)
                    (loop for i below m do
                        (loop for j below (aref k i) do
                            (if (= (+ y 1) (aref s i j))
                                (incf (aref on i))
                            )
                        )
                    )
                )
            )
            (let ((ok T))
                (loop for i below m do
                    (if (not (= (rem (aref on i) 2) (aref p i)))
                        (progn
                            (setq ok Nil)
                            (return)
                        )
                    )
                )
                (if (eq ok T) (incf ans))
            )
        )
    )

    (princ ans)
)

Measured memory_bytes: 24600
num, a, b = gets.split.map(&:to_i)

sum = 0
ary = []

(1..num).each.with_index(1) do |n, i|
  while n > 0
    sum += n % 10
    n /= 10
  end

  ary << i if a <= sum && sum <= b
  sum = 0
end

puts ary.inject(:+)

Measured memory_bytes: 1788
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#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 coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes = "Yes", T no = "No") { cout << (val ? yes : no) << endl; }

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

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


#line 2 "abc164_a.cpp"

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

  int s, w;
  cin >> s >> w;
  say(w >= s, "unsafe", "safe");
}


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

int gc(int x, int y){
  int t;
  while(y > 0){
    t = x;
    x = y;
    y = t % y;
  }
  
  return x;
}
  

int main(){
  int K, g;
  int gcd = 0;
  cin >> K;
  for(int a = 1; a <= K; a++){
    for(int b = 1; b <= a; b++){
      for(int c = 1; c <= b; c++){
        
        if(a == b && b == c){
          gcd += a;
        }
        
        else if(a == b || b == c){
          gcd += 3 * gc(a, c);
        }
        
        else{
          g = gc(b, c);
          gcd += 6 * gc(a, g);
        }
      }
    }
  }
  cout << gcd << endl;
}
    

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

using namespace std;

int main()
{
    int n;
    cin>>n;
    int arr1[105], arr2[106];
    for(int i=1 ; i<=n ; i++) cin>>arr1[i]>>arr2[i];
    for(int i=1 ; i<=n-3+1 ; i++){
        if(arr1[i] == arr2[i] and arr1[i+1] == arr2[i+1] and arr1[i+2] == arr2[i+2]){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 3644
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
#define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)


int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    for (auto&&i : p) cin >> i;

    int ans = 0;
    rep(i, n) {
        if (p[i] == i + 1) {
            ans++;
            i++;
        }
    }

    cout << ans << endl;

    return 0;
}

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

const int NIL = -1;
class Node {
public:
	int p, l, r;
	Node(int pp, int ll, int rr) { p = pp; l = ll; r = rr; }
};

vector<Node> T;

void preo( int u )
{
	if( u == NIL ) return;
	cout << " " << u;
	if( T[u].l != NIL ) preo( T[u].l );
	if( T[u].r != NIL ) preo( T[u].r );
}

void ino( int u )
{
	if( u == NIL ) return;
	if( T[u].l != NIL ) ino( T[u].l );
	cout << " " << u;
	if( T[u].r != NIL ) ino( T[u].r );
}

void posto( int u )
{
	if( u == NIL ) return;
	if( T[u].l != NIL ) posto( T[u].l );
	if( T[u].r != NIL ) posto( T[u].r );
	cout << " " << u;
}

int main()
{
	int n;
	cin >> n;
	T = vector<Node>( n, Node( NIL, NIL, NIL ) );
	for( int i = 0; i < n; i++ ) {
		int v, l, r;
		cin >> v >> l >> r;
		T[v].l = l;
		T[v].r = r;
		if( l != NIL ) T[l].p = v;
		if( r != NIL ) T[r].p = v;
	}

	int root;
	for( int i = 0; i < n; i++ ) {
		if( T[i].p == NIL ) root = i;
	}

	cout << "Preorder" << endl;
	preo( root );
	cout << endl;
	cout << "Inorder" << endl;
	ino( root );
	cout << endl;
	cout << "Postorder" << endl;
	posto( root );
	cout << endl;

}



Measured memory_bytes: 3108
import Data.Bool
 
main = do
  getLine
  as <- map read . words <$> getLine
  let o = length [ a | a <- as, odd a]
  let f = length [ a | a <- as, a `mod` 4 == 0 ]
  let t = bool 0 1 $ length as - o - f > 0
  putStr . bool "No" "Yes" $ f + 2 > o + t

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

using namespace std;

int main () {
    int n;
    cin >> n;
    for (int i = 1; i < 10; i++)
    {
       if(n % i == 0 && n/i <= 9){
           cout << "Yes" << endl;
           return 0;
       }
    }
    cout << "No" << endl;
    
}

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

using namespace std;

int main(){
  
  int n,a,b;
  int flag=0;

  while(cin>>n){
  for(int i=n-1;i>=1;i--){
    for(int j=2;j<=sqrt((double)i);j++){
      if(i%j==0){
        flag=1;
        break;
      }
    }
    if(flag==0){
      a=i;
      break;
    }
    else
      flag=0;
  }

  for(int i=n+1;i<60001;i++){
    for(int j=2;j<=sqrt((double)i);j++){
      if(i%j==0){
        flag=1;
        break;
      }
    }
    if(flag==0){
      b=i;
      break;
    }
    else
      flag=0;
  }

  cout<<a<<" "<<b<<endl;
  }
  return 0;
}



Measured memory_bytes: 3104
local mce, mfl, msq, mmi, mma = math.ceil, math.floor, math.sqrt, math.min, math.max
local n = io.read("*n")
local a, t = {}, {}
for i = 1, n do
  a[i] = io.read("*n")
  t[i] = 0
end
for i = n, 1, -1 do
  local dst = a[i]
  local j = 2
  local cur = 0
  while j * i <= n do
    cur = cur + t[j * i]
    j = j + 1
  end
  cur = cur % 2
  t[i] = (a[i] + cur) % 2
end
local m = 0
for i = 1, n do
  if t[i] == 1 then m = m + 1 end
end
print(m)
for i = 1, n do
  if t[i] == 1 then print(i) end
end


Measured memory_bytes: 5376
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Integer> list = new ArrayList<>();

		for ( int i = 1; i <= n; i ++){
			if (i % 3 == 0){
				continue;
			} else if (i % 5 == 0){
				continue;
			} else {
				list.add(i);
			}
		}

		long sum = 0;
		for (int f : list){
			sum += f;
		}

		System.out.println(sum);

	}

}


Measured memory_bytes: 61312
#include<stdio.h>
int main(){
  int unused __attribute__((unused));
  int A, B;

  unused = scanf("%d %d", &A, &B);
  if(A==1) A = 14;
  if(B==1) B = 14;

  if(A>B) printf("Alice");
  else if(A<B) printf("Bob");
  else printf("Draw");

  return 0;
}

Measured memory_bytes: 128
//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>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
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();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 



int main(){
    long long N;
    long long A,B;
    cin >> N >> A >> B;
    long long num=0;
    long long num_A=0,num_B=0;
    long long sum=A+B;
    if(A!=0){
        if(B!=0){
            if(sum<=N){
        num_A=(N/sum)*A;
        num_B=(N/sum)*B;
        num=num_A+num_B;
        if(num+A<=N){
            num_A+=A;
        }
        else{
            num_A+=N-num;
        }
        }
        else{
            if(A<=N){
                num_A=A;
            }
            else{
                num_A=N;
            }
        }
        }
        else{
            num_A=N;
        }
     }    
    cout << num_A;   
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

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

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

ll cnt[200005];

int main() {
    INIT;

    ll N;
    string str;
    cin >> N >> str;

    reps(i, 1, 200005) {
        int pp = __builtin_popcount(i);
        cnt[i] = cnt[i % pp] + 1;
    }

    reverse(ALL(str));

    ll ps = 0;
    rep(i, N) {
        if (str[i] == '1') ps++;
    }

    ll tot1 = 0, p1 = 1;
    ll tot2 = 0, p2 = 1;

    rep(i, N) {
        if (str[i] == '1') {
            tot1 = (tot1 + p1) % (ps + 1);
            if (ps > 1) {
                tot2 = (tot2 + p2) % (ps - 1);
            }
        }

        p1 = (p1 * 2) % (ps + 1);
        if (ps > 1) {
            p2 = (p2 * 2) % (ps - 1);
        }
    }

    vector<ll> ans;
    p1 = 1;
    p2 = 1;

    rep(i, N) {
        if (str[i] == '1') {
            if (ps == 1) {
                ans.pb(0);
            } else {
                ll x = (tot2 - p2 + ps - 1) % (ps - 1);
                ans.pb(cnt[x] + 1);
            }
        } else {
            ll x = (tot1 + p1 + ps + 1) % (ps + 1);
            ans.pb(cnt[x] + 1);
        }

        p1 = (p1 * 2) % (ps + 1);
        if (ps > 1) {
            p2 = (p2 * 2) % (ps - 1);
        }
    }

    reverse(ALL(ans));
    rep(i, N) { cout << ans[i] << endl; }

    return 0;
}

Measured memory_bytes: 7036
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<stdio.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define INF 1e9

int imos[30][100001] = {};
int main()
{
	int n, c;
	cin >> n >> c;
	rep(i, n) {
		int x, y, z;
		cin >> x >> y >> z;
		imos[z - 1][x - 1]++;
		imos[z - 1][y]--;
	}
	rep(i, c) {
		REP(j, 1, 100001) {
			imos[i][j] += imos[i][j - 1];
		}
	}
	int ans = 0;
	rep(i, 100001) {
		int count = 0;
		rep(j, c) {
			if (imos[j][i] != 0)
				count++;
		}
		ans = max(ans, count);
	}
	cout << ans << endl;
	return 0;
}

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

int main () {

    int N;

    scanf("%d", &N);

    set<int> A;

    for (int i = 0; i < N; i++) {
        int a;
        scanf("%d", &a);

        A.insert(a);
    }

    int k = A.size();

    if (k % 2 == 1) printf("%d\n", k);
    else printf("%d\n", k - 1);

    return 0;
}

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

using namespace std;

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

  while(1) {
  s.pop_back();

  int p = s.size() / 2;
  if((s.size() % 2 == 0) && (s.substr(0,p) == s.substr(p,p))) {
    cout << p * 2 << endl;
    return 0;
  }
}
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Vector;

public class Main {
    final  static int max=1000010;
    static class Pair{
        int  f ;
        long s;
        Pair(int a,long b){
            f=a;
            s=b;
        }
    }

    static Vector<Pair> edge[]= new Vector[max * 2];
    static long res[]=new long[max*2];

    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int cases=in.nextInt();
        while(--cases!=0) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();

            if(edge[a]==null)
                edge[a]=new Vector<>();
            edge[a].add(new Pair(b, c));

            if(edge[b]==null)
                edge[b]=new Vector<>();
            edge[b].add(new Pair(a, c));

        }

        int n=in.nextInt(),k=in.nextInt();
        DFS(k,0);
        while (n--!=0){
            int  f=in.nextInt();
            int  t=in.nextInt();

            System.out.println(res[f]+res[t]);
        }

    }

    static boolean visited[]=new boolean[max*2];
    private static void DFS(int k, long e) {
        visited[k]=true;
        for(int i=0;i<edge[k].size();i++)
        {
            if(!visited[edge[k].get(i).f])
            {
               res[edge[k].get(i).f]=e+edge[k].get(i).s;
               DFS(edge[k].get(i).f,e+edge[k].get(i).s);
            }

        }
    }
}


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

int main(){
    int n,m,q;
    cin >>n>>m>>q;
    int a[q],b[q],c[q],d[q];
    rep(i,q){
        cin >>a[i]>>b[i]>>c[i]>>d[i];
        a[i]--;
        b[i]--;
    }
    ll maxv=0;
    vector<int> nums;
    rep(i,m) nums.push_back(0);
    rep(i,n) nums.push_back(1);
    
    do{
        vector<int> A;
        ll z=0,ten=0;
        rep(i,m+n){
            if(nums[i]==0){
                z++;
            }else{
                A.push_back(z+1);
            }
        }
        if(A[n-1]>m) continue;
        rep(i,q){
            if(A[b[i]]-A[a[i]]==c[i])
                ten+=d[i];
        }
        maxv=max(maxv,ten);

    }while(next_permutation(nums.begin(),nums.end()));
    cout << maxv <<endl;
    return 0;
}

Measured memory_bytes: 3636