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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << ": " << x << '\n'

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

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

  ll n;
  cin >> n;

  ll res = 0;
  bool flag = 0;
  rep(i, inf + 1) {
    if (n < i * i) {
      break;
    } else if (n == i * i) {
      flag = 1;
    }
    res = i * i;
  }

  cout << (flag ? n : res) << endl;

  return 0;
}

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

int main(){
	string s;
	cin >>s;
	int a,b;
	a=0;
	b=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='g')a+=1;
		else b +=1;
	}
	cout << (a-b)/2 << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

const ll MOD = 1000000007;

ll powmod(ll x, ll n){
    ll ret=1;
    while(n>0){
        if(n&1){
            ret*=x;
            ret%=MOD;
            n-=1;
        }
        else{
            x*=x;
            x%=MOD;
            n>>=1;
        }
    }
    return ret;
}

signed main(){
    int n; cin >> n;
    ll num0[60],num1[60];
    rep(i,60) num0[i]=num1[i]=0;
    rep(i,n){
        ll a; cin >> a;
        for(ll j=0;j<60;j++){
            if(a&(1ull<<j)) num1[j]++;
            else num0[j]++;
        }
    }
    //rep(i,10) cout<< num0[i]<<" "<<num1[i]<<endl;
    ll ans=0;
    rep(i,60){
        ll x=num0[i]*num1[i];
        x%=MOD;
        ans+=(powmod(2,i)*x)%MOD;
        ans%=MOD;
    }
    cout << ans%MOD << endl;
}


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

using namespace std;

using ll = long long;

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

#define INF 1e9

int main(void)
{
    ll n, a, b, x[100005], i, sum = 0, t;

    cin >> n >> a >> b;
    for(i = 0; i < n; i++){
        cin >> x[i];
    }

    t = x[0];
    for(i = 1; i < n; i++){
        sum += min((x[i] - t) * a, b);
        t = x[i];
    }

    cout << sum << endl;
}


Measured memory_bytes: 1024
def dfs(s):
    global cnt
    if s != "":
        if int(s) > n:
            return
    if len(set(s)) == 3:
        cnt += 1
    dfs(s + "3")
    dfs(s + "5")
    dfs(s + "7")


n = int(input())
cnt = 0
dfs("")
print(cnt)

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

int main() {
    string S, T;
    cin >> S >> T;
    for(int i = 0; i < S.size(); i++) {
        if (S == T) {
            cout << "Yes" << endl;
            return 0;
        }
        S = S.back() + S.substr(0, S.size() - 1);
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

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

int main(void) {
  int d, n;
  cin >> d >> n;
  if (n == 100) {
    if (d == 0) {
      n = 101;
    }
    else if (d == 1) {
      n = 10100;
    }
    else if (d == 2) {
      n = 1010000;
    }
  }
  else {
    if (d == 1) {
      n *= 100;
    }
    else if (d == 2) {
      n *= 10000;
    }
  }
  cout << n << endl;
}


Measured memory_bytes: 256
#初期値の準備
fidge_number = 4
floor_number = 3
room_number = 10
residents_data = list()

#リストの初期化
for x in range(fidge_number):
    residents_data_temp = list()
    for y in range(floor_number):
        residents_data_temp.append([0]*10)
    residents_data.append(residents_data_temp)

#インプットdataの反映
data_number = int(input())
for i in range(data_number):
    #入力データの格納
    input_data = list(map(int, input().split()))
    fidge_input = input_data[0]
    floor_input = input_data[1]
    room_input = input_data[2]
    number_input = input_data[3]
    
    #入力データのエラーチェック
    if 0 <= fidge_input <= fidge_number and 0<= floor_input <= floor_number and 0<= room_input <= room_number:
        if residents_data[fidge_input-1][floor_input-1][room_input-1] + number_input >= 0:

    #入力データの反映
            residents_data[fidge_input-1][floor_input-1][room_input-1] += number_input

#結果の表示
for x in range(fidge_number):
    for y in range(floor_number):
        print(" " + " ".join(map(str,residents_data[x][y])))
    if x != fidge_number-1:
        print("####################")



Measured memory_bytes: 5608
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;

char grid[1002][1002];

int paths(int n,int m){
    int dp[1002][1002];
    memset(dp,-1,sizeof(dp));
    int counter = 1;
    for(int i=0;i<m;i++){
        if(grid[0][i]=='#'){
            dp[0][i] = 0;
            counter = 0;
        }
        if(grid[0][i]=='.' && counter==1){
            dp[0][i] = 1;
        }
        if(counter==0){
            dp[0][i] = 0;
        }
    }
    counter = 1;
    for(int i=0;i<n;i++){
        if(grid[i][0]=='#'){
            dp[i][0] = 0;
            counter = 0;
        }
        if(grid[i][0]=='.' && counter==1){
            dp[i][0] = 1;
        }
        if(counter==0){
            dp[i][0] = 0;
        }
    }

    for(int i=1;i<n;i++){
        for(int j=1;j<m;j++){
            if(grid[i][j]=='.'){
                dp[i][j] = (dp[i-1][j]%mod + dp[i][j-1]%mod)%mod;
            }
            else{
                dp[i][j] = 0;
            }
        }
    }

    return dp[n-1][m-1];
}

int main(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>grid[i][j];
        }
    }
    cout<<paths(n,m);
    return 0;
}

Measured memory_bytes: 5120
import sys
import math
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    S = inputs[0]
    count_0 = 0
    count_1 = 0

    for s in S:
        if s == "0":
            count_0 += 1
        else:
            count_1 += 1

    return len(S) - abs(count_0 - count_1)


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)


Measured memory_bytes: 3568
#include<bits/stdc++.h>
#define int long long int
using namespace std;
int n,dp[3001][3001],a[3001];
int rec(int l,int r){
	if(l>r)swap(l,r);
	if(dp[l][r]!=0)return dp[l][r];
	return dp[l][r]=max(a[l]-rec(l+1,r),a[r]-rec(l,r-1));
}
main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		dp[i][i]=a[i];
	}
	cout<<rec(1,n);
}

Measured memory_bytes: 70144
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Map<Integer, Integer> d = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int num = Integer.parseInt(sc.next());
            if (d.containsKey(num)) {
                d.put(num, d.get(num) + 1);
            } else {
                d.put(num, 1);
            }
        }
        int m = Integer.parseInt(sc.next());
        Map<Integer, Integer> t = new HashMap<>();
        for (int i = 0; i < m; i++) {
            int num = Integer.parseInt(sc.next());
            if (t.containsKey(num)) {
                t.put(num, t.get(num) + 1);
            } else {
                t.put(num, 1);
            }
        }
        sc.close();

        // 主処理
        boolean judge = true;
        for (int key : t.keySet()) {
            if (!(d.containsKey(key) && t.get(key) <= d.get(key))) {
                judge = false;
                break;
            }
        }

        String result = judge ? "YES" : "NO";

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 113824
#include <bits/stdc++.h>
using namespace std;
signed main(){
  int a[3],ans=0;
  cin>>a[0]>>a[1]>>a[2];
  sort(a,a+3);
  cout<<(a[2]-a[1])+(a[1]-a[0])<<endl;
  return(0);
}


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

int main() {
  unsigned long long n,a,b,ans,x,y;

  cin >> n >> a >> b;


  x=n/(a+b);
  x*=a;
  y=n%(a+b);
  
  if(y>a) {
    y=a;
  }

  ans=x+y;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define db(x) cout<<#x<<"="<<x<<endl
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //y1 j0 j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
#define EPS 1e(-9);
using namespace std;
typedef long long ll;

vector<int> divisors(int n) {
  vector<int> res;
  for(int i = 1; i*i <= n; ++i) {
    if(n % i != 0) continue;
    res.push_back(i);
    if(n/i == i) continue; // 上の行で追加済み。
    res.push_back(n/i);
  }
  sort(ALL(res),greater<int>());
  return res;
}


void Main(){

    int N,M; cin>>N>>M;

    vector<int> div=divisors(M);
    for(auto x: div){
        if(M/x>=N){
            cout<< x <<"\n"; return;
        }
    }
}

//-----------------------------------
int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------


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

int main() {
  int a,b; 
  cin >>a>>b;
  string moji_a=to_string(a);
  string moji_b=to_string(b);
  int keta_b=moji_b.size();
  int tasu=a*pow(10,keta_b)+b;
  int heihou=sqrt(tasu);
  if(heihou*heihou==tasu){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int n; cin >> n;
    vector<int> k(n), l(n), r(n);
    int ans = 0;
    rep(i, n) {
        cin >> k[i] >> l[i] >> r[i];
        ans += min(l[i], r[i]);
    }
    vector<int> ids(n);
    iota(all(ids), 0);
    sort(all(ids), [&](int i, int j){ return k[i] < k[j];});
    priority_queue<int, vector<int>, greater<int>> pque;
    per(i, n) {
        int j = ids[i];
        if(l[j] < r[j]) {
            int x = r[j] - l[j];
            if(n - k[j] > (int)pque.size()) {
                pque.push(x);
            } else {
                if(pque.empty()) continue;
                int y = pque.top();
                if(y < x) {
                    pque.pop();
                    pque.push(x);
                }
            }
        }
    }
    while(pque.size()) {
        ans += pque.top(); pque.pop();
    }
    priority_queue<int, vector<int>, greater<int>> pque1;
    rep(i, n) {
        int j = ids[i];
        if(l[j] > r[j]) {
            int x = l[j] - r[j];
            if(k[j] > (int)pque1.size()) {
                pque1.push(x);
            } else {
                if(pque1.empty()) continue;
                int y = pque1.top();
                if(y < x) {
                    pque1.pop();
                    pque1.push(x);
                }
            }
        }
    }
    while(pque1.size()) {
        ans += pque1.top(); pque1.pop();
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	int t; cin >> t; rep(i, t)solve();
	//solve();
    return 0;
}

Measured memory_bytes: 11756
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define pii pair<long long,long long>
#define endl '\n'
#define N 100001
int mod=1000000007;
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int modexp(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        
        return modexp((x*x)%M,n/2,M);
    else                             
        return (x*modexp((x*x)%M,(n-1)/2,M))%M;
}
void solve()
{
    int n,k; cin>>n>>k;
    n++;
    int ans=0;
    for(int i=k;i<=n;i++)
    {
        int l = ((i*(i-1))/2)%mod;
        int r = ((n*(n-1))/2) - (((n-i)*(n-1-i))/2);
        r=r%mod;
        ans=(ans+r-l+1+mod)%mod;
    }
    cout<<ans;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test; test=1;
    while(test--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3664
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;

int main() {
    int n;
    string s, t;
    cin >> n >> s >> t;
    for(size_t i = 0; i < n; i++) {
        cout << s[i] << t[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
import scala.math.ceil

object Main {
  val sc = new java.util.Scanner(System.in)

  def sin(n: Int): Seq[Int] = Seq.fill(n)(sc.nextInt())

  def iin(): Int = sc.nextLine().toInt

  def main(args: Array[String]): Unit = {
    val n = iin()
    val s = Seq.fill(3)(sc.nextLine())

    var cnt = 0;
    for(i <- 0 until n){
      val size = Set(s(0)(i), s(1)(i), s(2)(i)).size
      cnt += size - 1
    }
    println(cnt)
  }
}

Measured memory_bytes: 25644
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n;
    cin >> n;
    vec a(n);
    rep(i, n) cin >> a[i];

    sort(all(a));

    unordered_map<int, int> mp;

    rep(i, n) {
        mp[a[i]]++;
    }

    int c = 0;
    int res = 0;

    for (auto&& p : mp) {
        res++;
        if (p.second > 1 && p.second % 2 == 0) {
            c++;
        }
    }

    if (c % 2) res--;
    cout << res << endl;
    return 0;
}

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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int>vec(M,0);
  for(int i=0; i<N; i++){
    int K;
    cin >> K;
    for(int i=0; i<K; i++){
      int A;
      cin >> A;
      vec[A-1] += 1;
    }
  }
  int ans;
  for(int i=0; i<M; i++){
    if(vec[i] == N){
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3604
s = str(input())
a = int(s[0])*10 + int(s[1])
b = int(s[2])*10 + int(s[3])
if 1 <= a <= 12 and 1 <= b <= 12:
    print("AMBIGUOUS")
elif 1 <= a <= 12:
    print("MMYY")
elif 1 <= b <= 12:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

// <expr>   ::= <term> [ ('+'|'-') <term> ]*
// <term>   ::= <factor> [ ('*'|'/') <factor> ]*
// <factor> ::= <number> | '(' <expr> ')'
// <number> :== ???????????°

ll expr(int& pos);
ll mid(int& pos);
ll term(int& pos);
ll factor(int& pos);
ll number(int& pos);

string s;
map<char,int> mp;

void comp(ll& a1,ll a2,char c){
    if(c == '+'){
        a1 += a2;
    }else if(c == '-'){
        a1 -= a2;
    }else{
        a1 *= a2;
    }
}

ll expr(int& pos){
    ll res = mid(pos);
    while(mp[s[pos]] == 1){
        char c = s[pos];
        comp(res,mid(++pos),c);
    }
    return res;
}

ll mid(int& pos){
    ll res = term(pos);
    while(mp[s[pos]] == 2){
        char c = s[pos];
        comp(res,term(++pos),c);
    }
    return res;
}

ll term(int& pos){
    ll res = factor(pos);
    while(mp[s[pos]] == 3){
        char c = s[pos];
        comp(res,factor(++pos),c);
    }
    return res;
}

ll factor(int& pos){
    if(isdigit(s[pos])) return number(pos);
    pos++;  //'('?????¨??°???
    ll res = expr(pos);
    pos++;  //')'?????¨??°???
    return res;
}

ll number(int& pos){
    string res;
    while(isdigit(s[pos])){
        res.pb(s[pos++]);
    }
    return stoi(res);
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s;
    vi v(3);
    string hoge = "+-*";
    iota(all(v),0);
    ll mx = numeric_limits<ll>::min();
    int pos = 0;
    rep(i,3){
        rep(j,3){
            rep(k,3){
                mp['+'] = i+1,mp['-'] = j+1,mp['*'] = k+1;
                pos = 0;
                cmx(mx,expr(pos));
            }
        }
    }
    cout << mx << "\n";
    return 0;
}

Measured memory_bytes: 3196
#include<stdio.h>

int main(){
	int a,b,x,y,kurang;
	scanf("%d %d %d %d %d", &a,&b,&x,&y,&kurang);
	int temp=((x*60)+y)-((a*60)+b);
	printf("%d\n", temp-kurang);
	return 0;
}

Measured memory_bytes: 1704
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n,m;
    while(cin>>n>>m,n+m){
        map<string,pii>mp;
        rep(i,n){
            string hoge;
            cin>>hoge;
            int a,b; cin>>a>>b;
            mp[hoge]=pii(b-a+1,b);
        }
        rep(_,m){
            int tiya;cin>>tiya;
            bool flag=true;
            for(map<string,pii>::iterator itr=mp.begin();itr!=mp.end();itr++){
                if(itr->second.first<=tiya&&tiya<=itr->second.second){
                    flag=false;
                    cout<<(itr->first)<<" "<<tiya-itr->second.first+1<<endl;
                    break;
                }
            }
            if(flag)cout<<"Unknown"<<endl;
        }
    }
}

Measured memory_bytes: 3264
def geti; gets.to_i end
def getis; gets.split.map &:to_i end
def getin n;  n.times.map{geti}  end
def getisn n; n.times.map{getis} end
YES = "YES"; NO = "NO"; Yes = "Yes"; No = "No";

h,w = getis
ans = 1e99
2.times do
  w.times do |i|
    a = h * i
    [(h / 2) * (w - i), h * i].map do |b|
      x = [a, b, h * w - a - b]
      ans = [ans, x.max - x.min].min
    end
  end
  h,w = w,h
end
p ans

__END__

n = geti
puts n % n.to_s.chars.map(&:to_i).reduce(:+) == 0 ? Yes : No

n,a,b = getis
p [n*a,b].min

a,b,c = getis
p [a,b,c].any?(&:even?) ? 0 : [a*b,b*c,c*a].min

a,b=getis
puts a > 0 ? 'Positive' : b >= 0 ? 'Zero' : (b - a) % 2 == 1 ? 'Positive' : 'Negative'


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int n; cin >> n;
    int ans = 0;
    for(int i=3; i<=n; i+=2){
        int yaku = 0;
        for(int j=1; j<=i; j+=2){
            if(i%j == 0){
                yaku++;
            }
        }
        if(yaku == 8) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3464
Printf.printf "%s\n"
    (Scanf.sscanf (read_line()) 
                 "%s"  
                 (function 
                     |"a" -> "vowel"
                     |"i" -> "vowel"
                     |"u" -> "vowel"
                     |"e" -> "vowel"
                     |"o" -> "vowel" 
                     |_ -> "consonant"))


Measured memory_bytes: 384
#include <stdio.h>

int main()
{
int x = 0;
char a[5];


	scanf("%s", a);

	for(int i = 0; i < 4; i++)
	{
		if (a[i] == '+')
		{
			x++;
		}
		else if (a[i] == '-')
		{
			x--;
		}
	}
	printf("%d\n", x);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define N 1000005
using namespace std;

typedef long long ll;

int n, ans1, ans2;
char s[N];

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%s",s + 1);
	n = strlen(s + 1);
	for(int i = 1; i <= n; i++){
		ans1 += ((s[i] - '0') != i%2);
		ans2 += ((s[i] - '0') == i%2);
	}
	printf("%d\n", min(ans1, ans2));
	return 0;
}

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

int main(void){
    int r, D, x0;
    cin >> r >> D >> x0;
    for (int i = 1; i <=10; i++){
        x0 = x0 * r - D;
        cout << x0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>

#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)>(b))?(b):(a))
#define abs(a)   (((a)<(0))?(-(a)):(a))

typedef long long ll;
typedef unsigned long long ull;

int main(void)
{
	int a, p;
	scanf("%d%d", &a, &p);
	printf("%d", (a * 3 + p) / 2);
}


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

using namespace std;

int main(){
  string n;
  cin>>n;
  int ans=0;
  for(int i=0;i<n.size();++i){
    ans+=(n[i]-'0');
  }
  cout<<((ans%9==0)?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 3732
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) throws IOException{
		
		BufferedReader br =
				new BufferedReader(new InputStreamReader(System.in));
		
		String op;
		String[] ArrayX = new String[3];
		int[] ArrayA = new int[2];
		int resultNum = 0;
		String resultLine = "";

        boolean check = true;
        while(check){
            String line = br.readLine();
            ArrayX = line.split(" ");
            op = ArrayX[1];
            ArrayA[0] = Integer.parseInt(ArrayX[0]);
            ArrayA[1] = Integer.parseInt(ArrayX[2]);
            
            if(op.equals("+")) {
            	resultNum = ArrayA[0] + ArrayA[1];
            	resultLine = resultLine + resultNum + ("\n");
            }
            else if(op.equals("-")) {
            	resultNum = ArrayA[0] - ArrayA[1];
            	resultLine = resultLine + resultNum+ ("\n");
            }
            else if(op.equals("*")) {
            	resultNum = ArrayA[0] * ArrayA[1];
            	resultLine = resultLine + resultNum+ ("\n");
            }
            else if(op.equals("/")) {
            	resultNum = (ArrayA[0] / ArrayA[1]);
            	resultLine = resultLine + resultNum+ ("\n");
            }
            
            else if(op.equals("?") ){
            	check = false;
            }
        }
        System.out.print(resultLine);
	}
}

Measured memory_bytes: 24380
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int n;
string s[60];
int cnt[60][26];

void solve() {
  for (int i=0;i<n;i++) {
    for (int j=0;j<s[i].size();j++) {
      cnt[i][s[i][j] - 'a']++;
    }
  }
  for (int i=0;i<26;i++) {
    int minCnt = 60;
    for (int j=0;j<n;j++) {
      minCnt = min(minCnt, cnt[j][i]);
    }
    for (int j=0;j<minCnt;j++) {
      cout << (char)('a' + i);
    }
  }
  cout << endl;
}

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


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


long long int N, K;
std::vector<long long int> C, P;

long long int calc_max(std::vector<long long int> loop_vec) {
    long long int sum = 0;
    for (int j = 0; j < loop_vec.size(); j++) {
        sum += loop_vec[j];
    }
    long long int n_loop = loop_vec.size();
    long long int loop = std::max(0ll, (K - n_loop) / n_loop);
    int count = K - loop * n_loop;
    long long int max = loop_vec[0];
    int n_max = 1;
    for (int i = 0; i < n_loop; i++) {
        long long int s = 0;
        for (int j = 0; j < count; j++) {
            s += loop_vec[(i + j) % n_loop];
            if (s > max) {
                max = s;
                n_max = j + 1;
            }
        }
    }
    if (sum > 0) {
        max += sum * loop;
    }
    return max;
}


int main() {
    std::cin >> N >> K;

    C = std::vector<long long int>(N);
    P = std::vector<long long int>(N);
    for (int i = 0; i < N; i++) {
        std::cin >> C[i];
        C[i]--;
    }

    for (int i = 0; i < N; i++) {
        std::cin >> P[i];
    }

    long long int max = -200000000000;
    std::vector<int> flag(N, -1);
    for (int i = 0; i < N; i++) {
        if (flag[i] != -1) {
            continue;
        }
        std::vector<long long int> loop {P[i]};
        flag[i] = 1;
        int next = i;
        while (C[next] != i) {
            next = C[next];
            loop.emplace_back(P[next]);
            flag[next] = 1;
        }
        max = std::max(max, calc_max(loop));
    }
    std::cout << max << std::endl;
}


Measured memory_bytes: 3836
#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() {
    ll X; cin >> X;
    ll tmp = 100;
    ll ans = 0;
    while (tmp < X) {
        tmp += (tmp * 0.01) / 1;
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
n=int(input())
sl=[input() for _ in range(n)]
t=[0]*5
a=[0,0,0,0,0,0,1,1,1,2]
b=[1,1,1,2,2,3,2,2,3,3]
c=[2,3,4,3,4,4,3,4,4,4]
for s in sl:
    if s[0]=='M':
        t[0]+=1
    elif s[0]=='A':
        t[1]+=1
    elif s[0]=='R':
        t[2]+=1
    elif s[0]=='C':
        t[3]+=1
    elif s[0]=='H':
        t[4]+=1
ans=0
for i in range(10):
    ans+=t[a[i]]*t[b[i]]*t[c[i]]
print(ans)

Measured memory_bytes: 9772
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>

using namespace std;

int main() {
	int A, B, C, X, Y;
	long long ans = 0;

	cin >> A >> B >> C >> X >> Y;

	if (A + B > C * 2) {
		int Z = min(X, Y);
		X -= Z;
		Y -= Z;
		ans += Z * C * 2;
	}

	if (A > C * 2)ans += X * C * 2;
	else ans += X * A;

	if (B > C * 2)ans += Y * C * 2;
	else ans += Y * B;

	cout << ans << endl;

	
	return 0;
}

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

int main(){
  int n ; cin >> n ;
  bool check = true ;
  long int a,b ;
  cin >> a ;
  a-- ;
  for(int i=0;i<n-1;i++){
    cin >> b ;
    if(a<b) b-- ;
    else if(a>b){
      check = false ;
      break ;
    }
    a = b ;
  }
  if(check){
    cout << "Yes" << endl ;
  }else{
    cout << "No" << endl ;
  }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        var ab = Console.ReadLine().Split();
        var a = int.Parse(ab[0]);
        var b = int.Parse(ab[1]);
        Console.WriteLine(Math.Max(Math.Max(
            a + b,
            a - b),
            a * b));
    }
}


Measured memory_bytes: 11092
#include <algorithm>
#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;
typedef long long ll;
typedef pair<int, int> pii;
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;
ll INF = 1e18;
#define def 0

ll gcd(ll a, ll b) { return a ? gcd(b % a, a) : b; }

bool ok(string s, char ch) {
  rep(i, s.size()) {
    if (s[i] != ch) return false;
  }
  return true;
}

int main() {
  //
  string s;
  cin >> s;
  vi chcnt(26, 0);
  rep(x, 26) {
    string prev = s;
    char ch = x + 'a';
    while (!(ok(prev, ch))) {
      string tmp;
      rep(i, prev.size() - 1) {
        if (prev[i] == ch || prev[i + 1] == ch) {
          tmp += string(1, ch);
        } else {
          tmp += string(1, prev[i]);
        }
      }
      prev = tmp;
      chcnt[x]++;
    }
  }
  int ans = s.size() + 1;
  rep(x, 26) { ans = min(ans, chcnt[x]); }
  cout << ans << endl;
  return 0;
}


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

int main(){
    double N,K;
    cin >> N >> K;
    double ans = 0;
    for (double i = 1; i < N + 1; i++){
        int j = 0;
        int endf = 0;
        while (endf == 0){
            if (i * pow(2,j) > K - 1)  endf = 1;
            else j += 1;
        };
        double X = 1 / N;
        double Y = pow(2,j);
        ans += X / Y;
    }
    cout << setprecision(12) << ans << endl;
}

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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(long long i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const double EPS = 1e-9;
const ll powll = 1LL<<1;

/*
while(!frag && cin >> a >>b, a|b)
*/

int main(void){
    int a,b,c,k; cin >> a >>b >> c >> k;
    while(a >= b){
        k--;
        b *= 2;
    }
    while(b >= c){
        k--;
        c *= 2;
    }

    if(k >= 0){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }
}

Measured memory_bytes: 3584
package main

import (
  "fmt"
)

func main() {
  var X, Y int
  fmt.Scan(&X,&Y)

  result := 1
  a := X
  for {
    if a*2 <= Y{
      result +=1
      a = a*2
    }else{
      break
    }
  }
    fmt.Println(result)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int N=505;
char ch[N][N];
int n,m;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%s",ch[i]+1);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(ch[i][j]=='#'||i==1||(i!=n&&j%2==0))putchar('#');
			else putchar('.');
		}
		puts("");
	}
	puts("");
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(ch[i][j]=='#'||i==n||(i!=1&&j%2==1))putchar('#');
			else putchar('.');
		}
		puts("");
	}
}

Measured memory_bytes: 1024
import copy
import random
import math
d = int(input())
c = list(map(int,input().split()))
s = []
t = [0 for _ in range(d)]
for i in range(d):
  si = list(map(int,input().split()))
  s.append(si)
lastd = [-1 for _ in range(26)]
for i in range(d):
  mx = 0
  mj = 0
  for j in range(26):
    if s[i][j] + (i-lastd[j])*c[j] > mx:
      mx = s[i][j] + (i-lastd[j])*c[j]
      mj = j
  lastd[mj] = i
  t[i] = mj
lastd = [-1 for _ in range(26)]
ans = 0
for i in range(d):
  di = t[i]
  lastd[di-1] = i
  ans += s[i][di-1]
  for j in range(26):
    ans -= (i-lastd[j])*c[j]
mxans = ans
mxt = copy.deepcopy(t)
for time in range(100000):
  da = random.randint(0, d-1)
  qb = t[da]
  if random.random() < 0.7:
    bord = c[qb]*(0.7)
    qac = []
    cap = qac.append
    for i in range(0,qb):
      if s[da][i] > bord:
        cap(i)
      continue
    for i in range(qb+1,26):
      if s[da][i] > bord:
        cap(i)
      continue
    if len(qac) == 0:
      continue
    qa = random.choice(qac)
  else:
    bord = c[qb]//2
    qac = []
    cap = qac.append 
    for i in range(0,qb):
      if c[i] > bord:
        cap(i)
    for i in range(qb+1,26):
      if c[i] > bord:
        cap(i)
    if len(qac) == 0:
      continue
    qa = random.choice(qac) 
  #print(da,qb,qa,t)
  qb1 = -1
  qa1 = -1
  for i in range(da-1,-1,-1):
    if t[i] == qb:
      qb1 = i
      break
  for i in range(da-1,-1,-1):
    if t[i] == qa:
      qa1 = i
      break
  qb2 = d
  qa2 = d
  for i in range(da+1,d):
    if t[i] == qb:
      qb2 = i
      break
  for i in range(da+1,d):
    if t[i] == qa:
      qa2 = i
      break
  delta = -s[da][qb]+s[da][qa]-c[qb]*(qb2-da)*(da-qb1)+c[qa]*(qa2-da)*(da-qa1)
  if delta > 0:
    t[da] = qa
    ans += delta
    if ans > mxans:
      mxans = ans
      mxt = copy.deepcopy(t)
  else:
    if random.random() < math.exp((delta*time)/100000):
      t[da] = qa
  #print(mxans)
for ansd in mxt:
  print(ansd+1)

Measured memory_bytes: 82516
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
    int N,A,B,C,D,a,c;
    cin>>N>>A>>B>>C>>D;
    a=ceil((double)N/A)*B;
    c=ceil((double)N/C)*D;
    cout<<min(a,c)<<endl;
    return 0;
}



Measured memory_bytes: 3112
N = int(input())
a = [int(i) for i in input().split()]
sunuke = a[0]
arai = sum(a[1:])
if N == 2:
    print(abs(a[0] - a[1]))
else:
    ans = float('inf')
    for i in range(1, N-1):
        sunuke += a[i]
        arai -= a[i]
        ans = min(ans, abs(sunuke - arai))

    print(ans)

Measured memory_bytes: 31348
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

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


	string S, T;
	cin >> S >> T;
	int N = S.size();
	int M = T.size();

	int dp[5001][5001] = {};
	rep(i, N) {
		rep(j, M) {
			if (S[i] == T[j]) dp[i + 1][j + 1] = dp[i][j] + 1;
			else dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
		}
	}
	vector<char> V;
	int i = N, j = M;
	while(V.size() < dp[N][M]) {
		while (i > 0 && dp[i - 1][j] == dp[i][j]) i--;
		while (j > 0 && dp[i][j - 1] == dp[i][j]) j--;
		V.pb(S[i - 1]);
		i--;
		j--;
	}
	rep(i, V.size()) {
		cout << V[V.size() - i - 1];
	}
	cout << endl;

	Would you please return 0;
}

Measured memory_bytes: 97920
// AOJ 2352 Divisor
// 2018.4.10 bal4u

#include <stdio.h>
#include <string.h>

#define MAX 202
int   hi[MAX],  to[MAX][MAX];
char seen[MAX];
int  match[MAX];

int bpm(int u);
int bipartiteMatching(int m, int n)
{
    int u, max;

    memset(match, -1, (m+n)*sizeof(int));
    max = 0;
    for (u = 0; u < m; u++) {
        memset(seen, 0, m+n);
        if (bpm(u)) max++;
    }
    return max;
}

int bpm(int u)
{
    int i, v;

    for (i = 0; i < hi[u]; i++) {
        v = to[u][i];
        if (seen[v]) continue;
        seen[v] = 1;
        if (match[v] < 0 || bpm(match[v])) {
            match[u] = v, match[v] = u;
            return 1;
        }
    }
    return 0;
}

//#define getchar_unlocked()  getchar()
int in()
{
    int n = 0, c = getchar_unlocked();
    do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
    return n;
}

int  x[102]; int N;
char f[102]; int sz;
int  a[102];

int calc(int n, int *a)
{
    int i, j;

    memset(hi, 0, (sizeof(int)*n)<<1);
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) if (j != i) {
            if (a[i] % a[j] == 0) to[i][hi[i]++] = n+j;
        }
    }
    return n-bipartiteMatching(n, n);
}

int main()
{
    int i, j, k, ans;

    N = in();
    for (i = 0; i < N; i++) x[i] = in();

    // 課題文の条件を満たす集合Sの大きさを確定させる
    ans = calc(N, x);

    if (ans == 1) { puts("1"); return 0; }      // Sの大きさは1の場合、無条件にx[0]が答え

    memset(f, 1, N);    // f[i]=1：答えかその候補者、0：除外すべきx[i]

    sz = 0;             // 先頭x1から一つずつ確定していく。確定したx[i]の個数はsz
    for (i = 0; i < N; i++) {

        // x[i] を答えの集合Sに入れることができるか
        for (j = 0; j < i; j++) if (f[j]) {
            if (!(x[i] % x[j]) || !(x[j] % x[i])) break;
        }
        if (j < i) { f[i] = 0; continue; }      // 確定した集合Sの他メンバーと衝突するので不適合

        // x[i] を集合Sのメンバーにする
        k = 0; for (j = i+1; j < N; j++) if (f[j]) {
            if (x[i] % x[j] && x[j] % x[i]) {   // 残りのx[j]からx[i]と衝突しないものを選ぶ
                a[k++] = x[j];
            } else f[j] = 2;
        }
        
                                                // calc(k, a) は残りのx[j]で作れる集合の大きさ
        if (calc(k, a) + sz + 1 == ans) {       // 確定した集合Sの大きさ（=ans）と同じ
            // 結論として、x[i]を集合Sに入れるべきだ
            if (++sz == ans) break;
            for (j = i+1; j < N; j++) if (f[j] == 2) f[j] = 0;
        } else {
            // 結論として、x[i] は不適切で除外すべきだ
            f[i] = 0;
            for (j = i+1; j < N; j++) if (f[j] == 2) f[j] = 1;
        }
    }
    memset(f+i+1, 0, N-(i+1));                  // 残りのx[i]をすべて除外

    // 確定したx[i]を出力して終了
    k = 0; for (i = 0; i < N; i++) if (f[i]) {
        if (k) putchar(' '); else k = 1;
        printf("%d", i+1);
    }
    putchar('\n');
    return 0;
}



Measured memory_bytes: 2100
#include<cstdio>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>
#include<cctype>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stack>
#include<ctime>
#define mst(a,b) memset(a,b,sizeof(a))
#define foreasy(i,a,b) for(i=a;i<b;i++)
#define IN 1
#define OUT 0
//#define LOCAL
const double PI = acos(-1.0);
const int maxn=500000+5;

char s[10];
using namespace std;

bool cmp(int a, int b)
{
    return a>b;
}

int solve(int n)
{
    if(n<=0) return 1;
    else  return n*solve(n-1);
}
#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())

int main()
{
#ifdef LOCAL
    freopen("test.txt", "r", stdin);
#endif // LOCAL
    scanf("%s",s);
    int add = 0;
    for(int i = 0; i<3;i++)
    {
        add+=s[i]-'0';
    }
    printf("%d\n",add);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<algorithm>
using namespace std; int DIGITS = 0; int CLOCKWISE = -1;
struct Point { long double px, py; }; struct Polygon { vector<Point>p; };
Point Minus(Point a, Point b) { Point G; G.px = a.px - b.px; G.py = a.py - b.py; return G; }
long double dot(const Point& a, const Point& b) { return a.px * b.px + a.py * b.py; }
long double crs(const Point& a, const Point& b) { return a.px * b.py - a.py * b.px; }
bool operator<(const Point& a, const Point& b) { return a.py * 1e10 + a.px < b.py * 1e10 + b.px; }
long double norm(Point a) { return a.px*a.px + a.py*a.py; }
int ccw(Point p0, Point p1, Point p2) {
	Point a = Minus(p1, p0), b = Minus(p2, p0);
	if (crs(a, b) > 1e-10) return 1;
	if (crs(a, b) < -1e-10) return -1;
	if (fabs(crs(a, b)) < 1e-10) return -1;
	if (dot(a, b) < -1e-10) return 2;
	if (norm(a) < norm(b)) return -2;
	return 0;
}
vector<Point> solve(Polygon X) {
	vector<Point>P = X.p, u, l;
	int M = P.size();
	if (M < 3) { return P; }
	sort(P.begin(), P.end());
	u.push_back(P[0]); u.push_back(P[1]);
	l.push_back(P[P.size() - 1]); l.push_back(P[P.size() - 2]);
	for (int i = 2; i < P.size(); i++) {
		for (int j = u.size(); j >= 2; j--) {
			if (ccw(u[j - 2], u[j - 1], P[i]) == CLOCKWISE) {
				break;
			}
			u.pop_back();
		}
		u.push_back(P[i]);
	}
	for (int i = P.size() - 3; i >= 0; i--) {
		for (int j = l.size(); j >= 2; j--) {
			if (ccw(l[j - 2], l[j - 1], P[i]) == CLOCKWISE) {
				break;
			}
			l.pop_back();
		}
		l.push_back(P[i]);
	}
	reverse(l.begin(), l.end());
	for (int i = u.size() - 2; i >= 1; i--) { l.push_back(u[i]); }
	return l;
}
int main() {
	int N; cin >> N; Point A; Polygon C; vector<Point>D;
	for (int i = 0; i < N; i++) {
		cin >> A.px >> A.py; D.push_back(A);
	}
	C.p = D; vector<Point>E = solve(C);
	cout << E.size() << endl;
	for (int i = 0; i < E.size(); i++) {
		cout << fixed << setprecision(DIGITS) << E[i].px << ' ' << fixed << setprecision(DIGITS) << E[i].py << endl;
	}
	return 0;
}

Measured memory_bytes: 22064
#https://atcoder.jp/contests/abc136/tasks/abc136_c

n = int(input())
h = [int(i) for i in input().split()]

flag = 'Yes'
for i in reversed(range(n - 1)):
    if h[i+1] - h[i] < 0 and h[i+1] - h[i] >= -1:
        h[i] -= 1
    elif h[i+1] - h[i] <= -2:
        flag = 'No'
        break
print(flag)

Measured memory_bytes: 14252
i = 0
while i < 20:
    n = int(input())
    if n == 0:
        break
    
    j = 0
    sum = 1
    while j < n:
        j = j + 1
        sum = sum*j
    #print(sum)
        
    Sum = 0
    for k in range(100000):
        if sum%10 != 0:
            break
        
        Sum = Sum + 1
        sum = sum//10
    print(Sum)


Measured memory_bytes: 5628
S = input()
T = input()

STRMAX = "z" * 50
ans = STRMAX
for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        if S[i+j] == T[j] or S[i+j] == '?':
            if j == len(T)-1:
                work = S[:i] + T + S[i+j+1:]
                work = work.replace('?','a')
                if work < ans:
                    ans = work
        else:
            break

if ans == STRMAX:
    print("UNRESTORABLE")
else:
    print(ans)

Measured memory_bytes: 3064
#include<cstdio>

int main(){
    unsigned N, tmp, answer = 0;
    scanf("%u", &N);
    for (unsigned i = 0; i < N; i++){
        scanf("%u", &tmp);
        if(!(i&1) && (tmp&1)) answer++;
    }
    printf("%u\n", answer);
	return 0;
}

Measured memory_bytes: 1696
N = int(input())
S = []
S = list(map(int, input().split()))
f = 0
t = 0
while  t == 0:
    for i in range(len(S)):
        t = S[i]%2
        if t == 1:
            break
        else:
            S[i] = int(S[i]/2)
    if t ==1:
        break
    f = f + 1
print(f)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
// Big two primes
#define X 1001100011100001111ll
#define ll long long
#define all(a) a.begin(),a.end()
#define sortall(a) sort(all(a))
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define nloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define arrip(n)  int a[n]; fo(i, n) cin >> a[i];
#define arrop(n)  fo(i,n) cout<<a[i]<<" ";
#define pb push_back
#define mp make_pair
#define itr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626

#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define inf (int)(1e18)
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int>
#define fi first
#define se second
#define endl "\n"
#define pi pair<int, int>
#define vpi vector<pi>
#define sz(s) s.size()
#define bits(n) __builtin_popcount(n)//Count set bits

const int MAXN = (int)((1e5) + 100);
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
int max(int a, int b) {if (a > b) return a; else return b;}
int min(int a, int b) {if (a < b) return a; else return b;}





int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("codeci.txt", "r", stdin);
	freopen("codeco.txt", "w", stdout);
#endif
	fio;

	int n, a, b;
	cin >> n >> a >> b;

	int res = 0;
	if (a > 0)
	{
		res = n / (a + b) * a;
		n = n - n / (a + b) * (a + b);
		res += min(n, a);
	}
	cout << res << endl;
}

Measured memory_bytes: 3628