akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define dump(x) cout << (x) << endl

int main() {
  int x[200] = {};
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  for (int i = a; i < b; i++) {
    x[i] += 1;
  }
  for (int i = c; i < d; i++) {
    x[i] += 1;
  }
  int cnt = 0;
  for (int i = 0; i < 200; i++) {
    if (x[i] == 2) {
      cnt++;
    }
  }
  dump(cnt);
  return 0;
}


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

int main() {
    int N;
    string X;
    cin >> N >> X;

    int PopCount(0);
    for (int i = 0; i < N; ++i) {
        if (X[i] == '1') ++PopCount;
    }

    vector<int> pMod(N, 1), nMod(N, 1);
    for (int i = N - 2; i >= 0; --i) {
        pMod[i] = (pMod[i + 1] << 1) % (PopCount + 1);
        if (PopCount - 1 > 0) nMod[i] = (nMod[i + 1] << 1) % (PopCount - 1);
    }

    // Xp := X % (PopCount + 1)
    // Xn := X % (PopCount - 1)

    int Xp(0), Xn(0);
    for (int i = 0; i < N; ++i) {
        if (X[i] == '1') {
            (Xp += pMod[i]) %= (PopCount + 1);
            if (PopCount - 1 > 0) (Xn += nMod[i]) %= (PopCount - 1);
        }
    }

    for (int i = 0; i < N; ++i) {
        int ans = 1;
        if (X[i] == '1') {
            if (PopCount - 1 <= 0) {
                cout << 0 << endl;
                continue;
            }
            int res = (Xn - nMod[i] + (PopCount - 1)) % (PopCount - 1);
            // シミュレーション
            while (res != 0) {
                res = res % __builtin_popcount((unsigned int)res);
                ++ans;
            }
        } else {
            int res = (Xp + pMod[i] + (PopCount + 1)) % (PopCount + 1);
            while (res != 0) {
                res = res % __builtin_popcount((unsigned int)res);
                ++ans;
            }
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 5228
import java.util.*

fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val aList = readLine()?.split(" ")?.map { it.toLong() } ?: return

    var appendFirst = (n % 2 ) != 0  // true: first, false: last
    val sortedList = LinkedList<Long>()

    for (a in aList) {
        if (appendFirst) {
            sortedList.addFirst(a)
        } else {
            sortedList.addLast(a)
        }
        appendFirst = appendFirst.not()
    }

    println(sortedList.joinToString(separator = " "))
}

Measured memory_bytes: 108788
#include<iostream>

using namespace std;

int main()
{
	for(int n;cin>>n,n;){
		int a[100];
		for(int i=0;i<n;i++)	cin>>a[i];

		int cnt=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<n-i-1;j++)
				if(a[j]>a[j+1])	swap(a[j],a[j+1]),cnt++;
		}
		cout<<cnt<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a) ? "Yes" : "No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
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;
}
const long long INFLL = 1LL << 62;
const int INF = 1 << 30;
const double PI = acos(-1);
int main()
{
    int n;
    int ans1 = 0;
    int ans2 = 0;
    cin >> n;
    map<int, int> co;
    co[8]=0;
    int bef;
    rep(i, n)
    {
        cin >> bef;
        if (bef >= 3200)
        {
            co[8] += 0;
            co[8]++;
        }
        else
        {
            co[bef / 400] += 0;
            co[bef / 400]++;
        }
    }
    ans1 = co.size()-1;
    ans2 = ans1 + co[8];
    if(ans1==0){
        ans1=1;
    }
    cout << ans1 << " " << ans2 << endl;
}


Measured memory_bytes: 256
#include<iostream>

long long n,k,MOD=1000000007;

unsigned long long res1,res2;

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

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

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

int main(){

    COMinit();

    std::cin>>n>>k;

    std::cout<<n-k+1<<std::endl;

    for(int i=2;i<=k;i++){
        res1=1;
        res2=1;
        if(i-1<=n-k){
            res1=COM(k-1, i-1);
            res2=COM(n-k+1,i);
            std::cout<<(res1*res2)%MOD<<std::endl;
        }
        else
        std::cout<<0<<std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 12160
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n;
  cin >> n;
  vector<vector<int>> dp(3,vector<int>(n+1));
  rep1(i,n){
    int tmp;
    cin >> tmp;
    dp[1][i] = dp[1][i-1] + tmp;
  }
  rep1(i,n){
    int tmp;
    cin >> tmp;
    dp[2][i] = tmp + max(dp[1][i],dp[2][i-1]); 
  }
  cout << dp[2][n] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)

int main() {
    string s;
    cin >> s;
    int p = (s[0]-'0')*10+s[1]-'0';
    int q = (s[2]-'0')*10+s[3]-'0';
    int flag = 0;
    
    if(p >= 1 && p <= 12) {
        flag = 2;
    }
    else if(q >= 1 && q <= 12) {
        flag = 3;
    }
    if((q >= 1 && q <= 12) && (p >= 1 && p <= 12)) {
        flag = 1;
    }
    
    if(flag == 0) {
        cout << "NA" << endl;
    }
    else if(flag == 1) {
        cout << "AMBIGUOUS" << endl;
    }
    else if(flag == 2) {
        cout << "MMYY" << endl;
    }
    else {
        cout << "YYMM" << endl;
    }

  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[200010],n,i;
int main()
{
	cin>>n;
	for(i=1;i<=n;i++)
	cin>>a[i];
	sort(a+1,a+n+1);
	for(i=1;i<n;i++)
	if(a[i]==a[i+1])
	{
		cout<<"NO"<<endl;
		return 0;
	}
	cout<<"YES"<<endl;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long int lli;
typedef long long ll;

int main(){
    int n,m,X,Y; cin >> n >> m >> X >> Y;
    vector<int> x(n), y(m); 
    rep(i,n) cin >> x[i];
    rep(i,m) cin >> y[i];

    vector<string> out = {"No War","War"};
    int ans = 1;

    repm(z,X+1,Y+1){
        bool suc = true;
        rep(i,n) if(!(x[i] < z)) suc = false;
        rep(i,m) if(!(y[i] >= z)) suc = false;
        if(suc){
            ans = 0;
            break;
        }
    }

    cout << out[ans] << endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
C = [tuple(map(int, input().split())) for _ in range(M)]
ans = 10 ** (N - 1) if N != 1 else 0
while ans < 10 ** N:
    for s, c in C:
        if str(ans)[s - 1] == str(c):
            continue
        else:
            break
    else:
        print(ans)
        break
    ans += 1
else:
    print(-1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;
    int N = S.size();
    int ans = 999;
    for(int i=0; i<=N-3; i++){
        int a100 = (S[i]-'0')*100;
        int b10 = (S[i+1]-'0')*10;
        int c = S[i+2]-'0';
        int num = a100 + b10 + c;
        ans = min(ans,abs(num-753));
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import static java.lang.Math.*;

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

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int N = scanner.nextInt();
        String s = scanner.next();
        int a = 0;
        int prev = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '(') {
                a++;
            }
            if (s.charAt(i) == ')') {
                a--;
                if (a < 0) {
                    a++;
                    prev++;
                }
            }
        }
        for (int i = 0; i < prev; i++) {
            s = "("+s;
        }
        for (int i = 0; i < a; i++) {
            s = s+")";
        }
        System.out.println(s);
    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";

        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {
                    line = br.readLine();
                }
                s = line.split(reg, 0);
                i = 0;
                return s[i++];
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        public int nextInt() {
            try {
                return Integer.parseInt(next());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return -1;
        }

        public double nextDouble() {
            try {
                return Double.parseDouble(next());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return -1;
        }

        public long nextLong()  {
            try {
                return Long.parseLong(next());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return -1;
        }
    }
}


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

int main(){
  string s1,s2,s3;
  cin>>s1>>s2>>s3;
  char x = s1[0]-0x20;
  char y = s2[0]-0x20;
  char z = s3[0]-0x20;
  string s = {x,y,z};
  cout<<s<<endl;
  return 0;
}


Measured memory_bytes: 256
//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 <fstream>
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;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
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)

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

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
#define INF 1000000


int dp[102];
int main(){
	int N;
	int g[]={2,3,5,10,12,15};
	int v[]={380,550,850,1520,1870,2244};
	VI res;
	REP(i,102)dp[i]=INF;
	dp[0]=0;
	REP(i,49){
		REP(j,6)dp[i+g[j]]=min(dp[i]+v[j],dp[i+g[j]]);
	}
	while(cin>>N&&N!=0){
		res.PB(dp[N/100]);
	}
	REP(i,SZ(res))cout<<res[i]<<endl;
	return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a + b > c + d) cout << "Left";
    else if (a + b < c + d) cout << "Right";
    else cout << "Balanced";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

static const long long mod = 1000000007;
struct mint {
  long long x;
  mint(ll x = 0):x(x%mod) {}
  mint& operator+=(const mint a) {
    (x += a.x) %= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    (x += mod-a.x) %= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint ret(*this);
    return ret += a;
  }
  mint operator-(const mint a) const {
    mint ret(*this);
    return ret -= a;
  }
  mint operator*(const mint a) const {
    mint ret(*this);
    return ret *= a;
  }
  mint pow(ll t) const {
    if(t==0) return mint(1);
    mint a = pow(t>>1);
    a *= a;
    if(t&1) a *= *this;
    return a;
  }
  
  //for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint ret(*this);
    return ret /= a;
  }
};
ostream &operator<<(ostream& os, const mint& x) {
  os << x.x;
  return os;
}
class modutils {
  vector<mint> fact, invfact;
public:
  modutils(int n = 2000005):fact(n+1),invfact(n+1) {
    fact[0] = 1;
    for(int i=1; i<=n; i++) fact[i] = fact[i-1] * i;
    invfact[n] = fact[n].inv();
    for(int i=n; i>=1; i--) invfact[i-1] = invfact[i] * i;
  }
  mint pow(mint x, ll n) {
    return x.pow(n);
  }
  mint comb(ll n, ll k) {
    if(n<0 || k<0 || n<k) return 0;
    return fact[n] * invfact[k] * invfact[n-k];
  }
  mint perm(ll n, ll k) {
    if(n<0 || k<0 || n<k) return 0;
    return fact[n] * invfact[n-k];
  }
  mint fac(ll n) {
    return fact[n];
  }
};
modutils mutil;


int main(){
  ll K;
  string S;
  cin >> K;
  cin >> S;

  ll N = S.size();

  mint ret(0);
  for(ll x=0; x<=K; x++){
    mint tmp(1);
    tmp *= mutil.comb(N-1+K-x, K-x);
    tmp *= mutil.pow(25, K-x);
    tmp *= mutil.pow(26, x);
    ret += tmp;
  }
  
  cout << ret << endl;
  
  
  return 0;
}



Measured memory_bytes: 36592
#include<iostream>
using namespace std;
int main()
{
   int n,x,t;
   cin>>n>>x>>t;
   int ans;
   if(n%x==0)
   {
       ans=n/x;
       cout<<ans*t<<endl;
   }
   else
   {
       ans=n/x;
       cout<<(ans+1)*t<<endl;
   }
    return 0;
}


Measured memory_bytes: 3164
// Gear4        
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define FOR0(i,n) for(int i=0, _##i=(n); i<_##i; ++i)
#define FOR(i,l,r) for(int i=(l), _##i=(r); i<_##i; ++i)
#define FORD(i,l,r) for(int i=(r), _##i=(l); --i>=_##i; )
#define SZ(a) ((int)((a).size()))
#define printCase() "Case #" << caseNum << ": "
#define pb push_back
#define mp make_pair
#define SYNC std::ios::sync_with_stdio(false);  cin.tie(NULL);
#define ff first
#define ss second
template<typename T> using V = vector<T>;
template<typename T, typename U> using P = pair<T,U>;
using ld = long double;
using ll = long long;
#define endl '\n'
const int inf = 1e9, mod = 1e9 + 7;
const ll INF = 9e18;
const ld EPS = 1e-9, PI = acosl(-1.0);
const int N = 2e5 + 5;
string s, sl, sr; int n, cnt[26], cur[26], loc[N], a[N], ft[N];
ll ans = 0;
int query(int i) {
    int ret = 0;
    for(; i; i-=i&-i) ret += ft[i];
    return ret;
}
void upd(int i) {
    for(; i <= n; i += i&-i) ft[i]++;
}
int main() {
    SYNC
    cin >> s; n = s.length();
    for (char c : s) {
        cnt[c-'a']++;
    }
    int oe[2] = {};
    FOR0(i, 26) oe[cnt[i]&1]++;
    if(oe[1] > 1) {
        cout << -1;
        return 0;
    }
    FOR0(i, n) {
        int c = s[i] - 'a';
        if(++cur[c] > cnt[c] / 2)
            loc[i] = 1;
    }
    int tmp = 0;
    FOR0(i, n) {
        if(!loc[i]) tmp++;
        if(loc[i]) ans += n/2 - tmp;
    }
    cerr << ans << endl;
    FOR0(i, n) {
        if(loc[i]) sr.pb(s[i]);
        else sl.pb(s[i]);
    }
    if(n&1) {
        FOR0(i, (int)sr.length()) {
            if(cnt[sr[i] - 'a'] & 1) {
                ans += i;
                sr.erase(i, 1);
                break;
            }
        }
    }
    reverse(sr.begin(), sr.end());
    V<V<int>> pos(26);
    FORD(i, 0, sr.length()) {
        pos[sr[i] - 'a'].pb(i+1);
    }
    FOR0(i, sl.length()) {
        int c = sl[i] - 'a';
        a[i] = pos[c].back();
        pos[c].pop_back();
    }
    n = sl.length();
    FOR0(i, n) {
        ans += i-query(a[i]);
        upd(a[i]);
    }
    cout << ans;
}

Measured memory_bytes: 2708
using System;
using System.Linq;
using System.Collections.Generic;

class MyClass
{
    public static bool CheckA(string str)
    {
        if (!str.StartsWith(">\'"))
        {
            return false;
        }
        var bodylen1 = 0;
        var bodylen2 = 0;
        var i = 2;

        try
        {
            while (str[i] == '=')
            {
                bodylen1++;
                i++;
            }
            if (bodylen1 == 0 || str[i] != '#')
            {
                return false;
            }
            i++;
            while (str[i] == '=')
            {
                bodylen2++;
                i++;
            }
            return bodylen1 == bodylen2 && str[i] == '~' && i == str.Length - 1;
        }
        catch { return false; }
    }

    public static bool CheckB(string str)
    {
        if (!str.StartsWith(@">^") || !str.EndsWith("~~"))
        {
            return false;
        }
        var bodylen = 0;
        var i = 2;

        try
        {
            while (str[i] == 'Q' && str[i + 1] == '=')
            {
                bodylen++;
                i += 2;
            }
            return bodylen >= 1 && i == str.Length - 2;
        }
        catch { return false; }
    }

    public static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        for (int i = 0; i < n; i++)
        {
            var str = Console.ReadLine();
            Console.WriteLine(CheckA(str) ? "A" : CheckB(str) ? "B" : "NA");
        }
    }
}


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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;

    int cnt = 0;
    while (a != b || a != c) {
        cnt++;
        if (a == b && c < a) c += 2;
        else if (a == c && b < a) b += 2;
        else if (b == c && a < b) a += 2;

        else if (a > b && a > c) b++, c++;
        else if (b > a && b > c) a++, c++;
        else if (c > b && c > a) a++, b++;
    }

    cout << cnt << "\n";
}


Measured memory_bytes: 256
def main():
    MOD = 10 ** 9 + 7

    N, M = map(int, input().split())
    if abs(N - M) > 1:
        print(0)
        return

    ans = 1
    for i in range(1, N + 1):
        ans = (ans * i) % MOD

    for i in range(1, M + 1):
        ans = (ans * i) % MOD

    if N == M:
        ans = (ans * 2) % MOD

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#define LL long long

#include<iostream>
#include<algorithm>
using namespace std;

int main(){
	string s;
	cin>>s;
	LL num=0;
	for(int i=0;i<s.size();i++){
		if(count(s.begin(),s.end(),s[i]) != 1){
			num++;
			break;
		}
	}
	if(num==0){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
	return 0;
}


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

int main(){
  int a,b,c,d,i,j,n;
  char t1[26],t2[26];

  scanf("%d\n",&n);
  for(i=0;i<n;i++){
    for(j=0;j<26;j++){ t1[j]=0; t2[j]=0;}
    a=t1[0]=getchar();
    while((b=getchar())!='\n'){
      c=getchar(); d=getchar();
      if(c=='>' && strchr(t1,d)==NULL){
        t2[0]=d;
        t2[1]=0;
        strcat(t1,t2);
      }
      if(b=='<' && t1[0]==a){
        strcpy(t2,t1);
        t1[0]=d;
        t1[1]=0;
        strcat(t1,t2);
      }
      a=d;
    }
    printf("%s\n",t1);
  }
  return 0;
}

Measured memory_bytes: 600
#include<stdio.h>
 
int main(){
  int x1,x2,x3,x4,x5;
  while(scanf("%d %d %d %d %d",&x1,&x2,&x3,&x4,&x5)==0);
  
  if(x1==0)
    printf("1\n");
  else if(x2==0)
    printf("2\n");
    else if(x3==0)
    printf("3\n");
    else if(x4==0)
    printf("4\n");
    else if(x5==0)
    printf("5\n");
  
 return 0; 
}

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

int main(){
    int D, G, p[11], c[11];
    cin >> D >> G;
    for(int i = 0; i < D; ++i){
        cin >> p[i] >> c[i];
    }

    int ans = 1e9;
    for(int mask = 0; mask < (1 << D); ++mask){
        int s = 0, num = 0, rest_max = -1;
        for(int i = 0; i < D; ++i){
            if(mask >> i & 1){
                s += 100 * (i+1) * p[i] + c[i];
                num += p[i];
            }else{
                rest_max = i;
            }
        }
        if(s < G){
            int s1 = 100 * (rest_max + 1);
            int need = (G - s + s1 - 1) / s1;
            if(need >= p[rest_max]){
                continue;
            }
            num += need;
        }
        ans = min(ans, num);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int in(){ int x; scanf("%d", &x); return x; }
int main(){
	int a = in(), b = in(), c = in();
	int cnt = 0;
	for(int x = a; x <= b; x++) if(c % x == 0) cnt++;
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 1028
// 6/20
// AGC045 リアルタイム参加
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

int main() {
    int X;
    cin >> X;
    cout << 360 / gcd(X, 360) << endl;
}

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

#include <boost/algorithm/string/classification.hpp>  // is_any_of
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/math/tools/minima.hpp>
#include <boost/multi_array.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>

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

namespace adaptor = boost::adaptors;
using namespace std;
using boost::irange;
using boost::algorithm::join;
using boost::algorithm::replace_all;
using boost::algorithm::split;
using boost::math::tools::brent_find_minima;
using boost::multiprecision::cpp_int;
using ll = long long;
using P = pair<int, int>;

// TOP
void Main()
{
	int n, k;
	cin >> n >> k;

	int count;
	count = 0;
	while (n)
	{
		n /= k;
		count++;
	}
	cout << count << endl;
}
// END

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 256
#include <cmath>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;
using vi = vector<int>;

int h1;
int s1;
int h2;
int s2;

void input() {
  cin >> h1 >> s1 >> h2 >> s2;
}

void solve() {
  bool turn = true;

  while (h1 > 0 && h2 > 0) {
    if (turn) {
      h2 -= s1;
    } else {
      h1 -= s2;
    }

    turn = !turn;
  }

  string ans = "Yes";

  if (h1 <= 0)
    ans = "No";

  cout << ans << '\n';
}

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

  cout.precision(16);
  cout << fixed;

  int _times = 1;

#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);

  _times = 2;
#endif

  // cin >> _times;

  while (_times--) {
    input();
    solve();
  }
}


Measured memory_bytes: 3604
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
    public static void main (String[] args) throws IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	int n = Integer.parseInt(br.readLine());
	Card[] cards = new Card[n];
	String[] input;
	for (int i = 0; i < n; i++) {
	    input = br.readLine().split(" ");
	    cards[i] = new Card(input[0], Integer.parseInt(input[1]), i);
	}

	quicksort(cards, 0, n-1);

	String message = "Stable";
	for (int i = 0; i < n - 1; i++) {
	    if (cards[i].num == cards[i+1].num && cards[i].index > cards[i+1].index ) {
		message = "Not stable";
	    }
	}
	StringBuilder sb = new StringBuilder();
	sb.append(message + "\n");
	for (int i = 0; i < n; i++) {
	    sb.append(cards[i].suit + " " + cards[i].num + "\n");
	}
	System.out.print(sb);
    }
    static void quicksort (Card[]a, int p, int r) {
	if (p < r) {
	    int q = partition(a, p, r);
	    quicksort(a, p, q - 1);
	    quicksort(a, q + 1, r);
	}
    }
    static int partition (Card[] a, int p, int r) {
	int x = a[r].num;
	int i = p - 1;
	Card tmp;
	for (int j = p; j < r; j++) {
	    if (a[j].num <= x) {
		i = i + 1;
		tmp = a[j];
		a[j] = a[i];
		a[i] = tmp;
	    }
	}
	tmp = a[i+1];
	a[i+1] = a[r];
	a[r] = tmp;
	return i+1;
    }
}
class Card {
    String suit;
    int num;
    int index;
    Card (String suit, int num, int index) {
	this.suit = suit;
	this.num = num;
	this.index = index;
    }
}

Measured memory_bytes: 70284
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <ctype.h>
#include <stdlib.h>
#include <map>
using namespace std;

int main() {
	int A, B, C;
	cin >> A >> B >> C;

	bool flag = false;

	if (A == B && B != C) {
		flag = true;
	}
	if (A == C && B != C) {
		flag = true;
	}
	if (B == C && C != A) {
		flag = true;
	}

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


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

int main(){
    string s;
    cin >> s;
    bool hitachi = true;
    int n = s.size();
    if (n%2 == 1) hitachi = false;
    if(hitachi){
        for(int i =0; i < n/2; i++){
            if(s.at(2*i) != 'h'|| s.at(2*i+1) !='i'){
                hitachi = false;
                break;
            }
        }
    }
    if(hitachi) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import java.util.TreeMap;
import java.util.TreeSet;

import static java.util.Comparator.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        Solver solver = new Solver(System.in, out);
        solver.solve();
        out.close();
    }
}
class Solver {
	Scanner sc;
	PrintWriter out;
    public Solver(InputStream in, PrintWriter out) {
    	sc = new Scanner(in);
    	this.out = out;
    }
    // ==================================================================
    int N, M;
    int[][] A;
    boolean[] used;
    int calc(int now, int cnt) {
//    	out.println("開始　　now = " + now + "  cnt = " + cnt);
    	if(cnt >= N-1) {
//        	out.println("見つかった！　　now = " + now + "  cnt = " + cnt);
    		return 1;
    	}
    	int ans = 0;
    	for (int i = 0; i < N; i++) {
			if(A[now][i] == 1 && !used[i]) {
				used[i] = true;
				ans += calc(i, cnt+1);
				used[i] = false;
			}
		}
//    	out.println("戻り　　 now = " + now + "  cnt = " + cnt + "  --> ans = " + ans);
    	return ans;
    }
    public void solve() {
    	N = ni();
    	M = ni();
    	A = new int[N][N];
    	used = new boolean[N];
    	int x, y;
    	for (int i = 0; i < M; i++) {
			x = ni() - 1;
			y = ni() - 1;
			A[x][y] = 1;
			A[y][x] = 1;
		}
    	used[0] = true;
    	out.println(calc(0, 0));
    }
    // ------------------------------------------
    // 入力
    // ------------------------------------------
    public int ni() {
    	return sc.nextInt();
    }
    public long nl() {
    	return sc.nextLong();
    }
    public String ns() {
    	return sc.next();
    }
    public char[] nc() {
    	return sc.next().toCharArray();
    }
    public int[] ndi(int N) {
    	int[] ans = new int[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = ni();
		}
    	return ans;
    }
    public long[] ndl(int N) {
    	long[] ans = new long[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = nl();
		}
    	return ans;
    }
    public String[] nds(int N) {
    	String[] ans = new String[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = ns();
		}
    	return ans;
    }
    public char[][] ndc(int N) {
    	char[][] ans = new char[N][];
    	for (int i = 0; i < N; i++) {
			ans[i] = nc();
		}
    	return ans;
    }
    public int[][] ndii(int N, int S) {
    	int[][] ans = new int[N][S];
    	for (int i = 0; i < N; i++) {
			for (int j = 0; j < S; j++) {
				ans[i][j] = ni();
			}
		}
    	return ans;
    }
}


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

template <typename T>
using lim = numeric_limits<T>;

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

	int n; cin >> n;

	ll ans = 0;
	for(int i = 1; i <= n; i++){
		if (i%3 == 0 or i%5 == 0) continue;
		ans += i;
	}

	cout << ans << "\n";
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#pragma warning( disable:4996 )
using namespace std;

#define SWAP(a,b) (a += b,b = a - b,a -= b)
#define MIN(a, b) ((a) < (b) ? (a) : (b))


int main(void) {
	char s[5];
	scanf("%s", s);
	if ((s[0] == s[1] && s[2] == s[3]) ||
		(s[0] == s[2] && s[1] == s[3]) ||
		(s[0] == s[3] && s[1] == s[2])) {
		if (s[0] == s[1] && s[0] == s[2] && s[0] == s[3]) {
			printf("No\n");
		}
		else {
			printf("Yes\n");
		}
		
	}
	else {
		printf("No\n");
	}
	return 0;
}

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

int main() {
  char c;
  for (;;) {
    scanf("%c", &c);
    if (c == 'A') printf("T");
    else if (c == 'T') printf("A");
    else if (c == 'C') printf("G");
    else if (c == 'G') printf("C");
    else
      break;
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 256
import sys


def input():
    return sys.stdin.readline().strip()
# sys.setrecursionlimit(100000)


def main():
    n = int(input().strip())
    B = [int(i) for i in input().strip().split()]
    ans = []
    ptr = len(B)
    while ptr > 0:
        if B[ptr - 1] == ptr:
            ans.append(B.pop(ptr - 1))
            ptr = len(B)
        else:
            ptr -= 1
    if len(ans) == n:
        for i in ans[::-1]:
            print(i)
    else:
        print(-1)

    return


if __name__ == "__main__":
    main()


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

int main() {
    int a, b, m;
    cin >> a >> b >> m;
    vector<int> va(a), vb(b);
    for (int i = 0; i < a; i++) cin >> va[i];
    for (int i = 0; i < b; i++) cin >> vb[i];
    int ans = 1e9;
    for (int i = 0; i < m; i++) {
        int x, y, c;
        cin >> x >> y >> c;
        int cur = va[x - 1] + vb[y - 1] - c;
        ans = min(ans, cur);
    }
    sort(va.begin(), va.end());
    sort(vb.begin(), vb.end());
    cout << min(ans, va[0] + vb[0]) << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b;
    cin>>a>>b;
    puta(lcm(a,b));
    return 0;
}

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

using namespace std;

int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++) cin>>arr[i];
    sort(arr,arr+n);
    int sum=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<i;j++)
        {
            for(int k=0;k<j;k++)
            {
                if(arr[i]!=arr[j] && arr[j]!=arr[k] && arr[k]!=arr[i])
                {
                    if(arr[j]+arr[k]>arr[i]) sum++;
                }
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()

const int INF = 100000002;

int main(){
	ll n, a, b; cin >> n >> a >> b;
	ll c = a+b;
	ll ans = n / c * a + min(n % c, a);
	cout << ans << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  
  for (int i = 0; i < N; i++) cin >> vec.at(i);
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  int Alice = 0;
  int Bob = 0;
  
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
       Alice += vec.at(i);
    } else {
       Bob += vec.at(i); 
    }
  }
  
  cout << Alice - Bob << endl;
  
}

Measured memory_bytes: 256
def main():
    S = list(map(int, input().split("/")))
    result = ""
    if S[0] < 2019:
        result = "Heisei"
    elif S[0] == 2019 and S[1] <= 4 and S[2] <= 30:
        result = "Heisei"
    else:
        result = "TBD"

    print(result)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
struct _{
    int a, c;
};
int n, k, e, r;
char c, t;
string s;
vector<_> v; 
int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n>>k>>s;
    for(int i = 0;i < n; i++){
        c = s[i];
        if (s[i] == 'L' && i-1 >= 0 && s[i-1] == 'L')r++;
        if (s[i] == 'R' && i+1 <n && s[i+1]=='R')r++;
        if (t&&c^t){
            if (t == 'L')v.push_back({0, e});
            else v.push_back({1, e});
            e = 0;
        }
        t = c;
        e++;
    }
    if (t == 'L')v.push_back({0, e});
    else v.push_back({1, e});
    e = v.size();
    while(e > 2 && k--){
        r += 2;
        e-=2;
    }
    if (k && e == 2){
        r += 1;
        k--;
    }
    cout << r;
}

Measured memory_bytes: 1480
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

const int MAX_N = 110;
ll dp[MAX_N][4*4*4];

int main(){
    string s = "AGCT";
    auto calcId = [](int x, int y, int z) {
        return x * 16 + y * 4 + z;
    };

    vector<vector<int>> allStats;
    {
        auto check = [](vector<int> stats) {
            rep(i, 2) {
                bool f = true;
                rep(j, 3) f &= stats[i+j] == j;
                if(f) return false;
            }
            rep(k, 3) {
                swap(stats[k], stats[k+1]);
                rep(i, 2) {
                    bool f = true;
                    rep(j, 3) f &= stats[i+j] == j;
                    if(f) {
                        swap(stats[k], stats[k+1]);
                        if(f) return false;
                    }
                }
                swap(stats[k], stats[k+1]);
            }
            return true;
        };
        rep(i, 4) rep(j, 4) rep(k, 4) rep(l, 4) {
            vector<int> stats{i, j, k, l};
            if(check(stats)) allStats.push_back(stats);
        }
    }
    // for(auto&& s: allStats) {
    //     for(auto&& x: s) cout << " " << x;
    //         cout << endl;
    // }
    {
        set<vector<int>> st;
        for(auto&& s : allStats) {
            vector<int> tmp(s.begin(), s.begin()+3);
            if(st.count(tmp)) continue;
            dp[3][calcId(tmp[0], tmp[1], tmp[2])] = 1LL;
            st.insert(tmp);
        }
    }
    int N;
    cin >> N;
    REP(i, 3, N) for(auto&& s : allStats) {
        int cur = calcId(s[0], s[1], s[2]);
        int nxt = calcId(s[1], s[2], s[3]);
        (dp[i+1][nxt] += dp[i][cur]) %= MOD;
    }
    ll ans = 0LL;
    rep(i, 4*4*4) (ans += dp[N][i]) %= MOD;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int A,B,C,D;
	cin >> A >> B >> C >> D;
	while(1){
		C -= B;
		if(C <= 0){
			cout << "Yes" << endl;
			break;
		}
		A -= D;
		if(A <= 0){
			cout << "No" << endl;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 3600
s=input()
n=len(s)
b_start = 0
w_start = 0
for i in range(n):
    if(i%2==0):
        b_start += (s[i]=='1')
        w_start += (s[i]=='0')
    else:
        b_start += (s[i]=='0')
        w_start += (s[i]=='1')

print(min(b_start,w_start))

Measured memory_bytes: 67280
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace debug
{
    class main
    {
        static void Main(string[] args)
        {
            //問題クラスを展開
            ProgramA a = new ProgramA();
            a.main();//実行する

        }

    }

    class ProgramA
    {
        public void main()
        {

            string[] s = Console.ReadLine().Split(' ');

            Console.WriteLine((int.Parse(s[0]) - 1) * (int.Parse(s[1]) - 1));


        }
    }

}






Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define MOD 10000007
 
int main()
{
     ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
     ll n,q,x,y;
     cin>>n>>q;
     vector<vector<ll>> v(n+1);
     for(ll i=0;i<n-1;i++)  {  cin>>x>>y;   v[x].pb(y);  v[y].pb(x);}
     ll ans[n+1]={0};
     while(q--)
     {
          cin >> x >>y;
          ans[x] += y;
     }
     bool visited[n+1]={0};
     stack<pair<ll,ll>> s;
     s.push(mp(1,-1));
     while(!s.empty())
     {
          pair<ll,ll> p = s.top();
          s.pop();
          ll t1 = p.ff;
          ll t2 = p.ss;
          visited[t1] = 1;
          for(auto X:v[t1])
          {
               if(visited[X]==0)
               {
                    ans[X] += ans[t1];
                    s.push(mp(X,t1));
               }
          }
     }
     for(ll i=1;i<=n;i++)   cout<<ans[i]<<" ";
}
 

Measured memory_bytes: 19696
main = do
  s <- getContents
  let ln = lines $ s
  let n = length . filter id . map isPalin $ ln
  putStrLn . show $ n

isPalin::[Char] -> Bool
isPalin [] = True
isPalin [a] = True
isPalin (x:xs)
  | x == (last xs) = isPalin (init xs)
  | otherwise = False

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

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

    int n;
    cin >> n;
    vector<int> s(1 << n), t(1, 1);
    rep(i, 0, 1 << n) cin >> s[i];
    sort(s.begin(), s.end(), greater<int>());
    rep(i, 1, 1 << n) {
        if (s[i] == s[i - 1])
            t.back()++;
        else
            t.emplace_back(1);
    }
    if (t[0] != 1) {
        cout << "No" << endl;
        return 0;
    }

    /*vector<int> par((1 << n) + 1), tree((1 << n) + 1);
    tree[1] = s[0];
    int l = 1;
    rep(i, 2, (1 << n) + 1) {
        while (l * 2 < i)
            l <<= 1;
        par[i] = i - l;
    }*/
    vector<int> deg(n + 1, 1);
    deg[0] = 0;

    rep(i, 1, t.size()) {
        if (accumulate(deg.begin(), deg.end(), 0) < t[i]) {
            cout << "No" << endl;
            return 0;
        }

        vector<int> add(n + 1);
        int l = 1;
        while (t[i]) {
            if (t[i] > deg[l]) {
                add[l] = deg[l];
                t[i] -= deg[l];
                deg[l] = 0;
                l++;
            } else {
                add[l] = t[i];
                deg[l] -= t[i];
                t[i] = 0;
            }
        }
        for (l = n - 1; l > 0; l--) {
            rep(j, l + 1, n + 1) {
                deg[j] += add[l];
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 2424
#include <iostream>
    using namespace std;
     
    int main(){
        //recieve inputs
        int N, X, T;
        cin >> N >> X >> T;
     
        //find the number of times to use the machine
        int times = (N + X - 1) / X;
     
        //find the answer
        int ans = times * T;
     
        //output the answer
        cout << ans << endl;
    }

Measured memory_bytes: 3600
// #define _GLIBCXX_DEBUG

#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <string>
#include <vector>
#include <chrono>
#include <cmath>

#define int long long

using namespace std;


const int INF = 1e15;


signed main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[i]--;
  }

  vector<int> prev(N, -1);

  int current = 0;

  for (int t = 0; t < K;) {
    if (t == K) {
      break;
    }

    if (prev[current] != -1) {
      int distance = t - prev[current];
      prev[current] = t;

      if (t + distance <= K - t) {
        t = K - (K - t) % distance;
        continue;
      }
    }

    prev[current] = t;
    current = A[current];
    t++;
  }

  cout << current + 1 << endl;


  return 0;
}


Measured memory_bytes: 6428
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
template<typename T> ll min(ll a, const T&& b) { return a < b ? a : b; }
template<typename T> ll min(const T&& a, ll b) { return a < b ? a : b; }
template<typename T> ll max(ll a, const T&& b) { return a > b ? a : b; }
template<typename T> ll max(const T&& a, ll b) { return a > b ? a : b; }
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

void solve() {
  ll n; cin >> n;
  string s; cin >> s;
  vector<ll> R(n+1, 0);
  rrep(i, n) R[i] = R[i+1] + (s[i] == '.');
  vector<ll> L(n+1, 0);
  rep(i, n) L[i+1] = L[i] + (s[i] == '#');
  ll ans = linf;
  rep(i, n+1) {
    chmin(ans, L[i] + R[i]);
  }
  cout << ans << endl;
}


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

public class Main {
	static int n;

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int m = Integer.parseInt(str[1]);

		int set[] = new int[n];

		int wa = 0;
		int ac = 0;

		for (int i = 0; i < m; i++) {
			str = br.readLine().split(" ");
			int p = Integer.parseInt(str[0]) - 1;
			String s = str[1];

			if (s.equals("WA") && set[p] != -1) {
				set[p]++;
			} else if (set[p] != -1) {
				wa += set[p];
				ac++;
				set[p] = -1;
			}
		}
		System.out.println(ac + " " + wa);
	}
}

Measured memory_bytes: 48144