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

#define endl '\n'
#define sz(x) ((int)(x.size()))

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

	long long n, k;
	cin >> n >> k;
	long long p[n+1], c[n+1];
	for(int i=1; i<=n; i++) cin >> p[i];
	for(int i=1; i<=n; i++) cin >> c[i];
	bool seen[n+1];
	long long ans = -1e18;
	for(int i=1; i<=n; i++) {
		int ptr = i;
		long long tot = 0;
		vector <long long> v;
		memset(seen, 0, sizeof seen);
		while(!seen[ptr]) {
			seen[ptr] = 1;
			tot += c[ptr];
			v.push_back(c[ptr]);
			ptr = p[ptr];
		}
		for(int i=0; i<sz(v); i++) {
			if(i) v[i] += v[i-1];
			if(i+1 <= k) ans = max(ans, v[i]);
			else break;
			if(tot > 0) {
				ans = max(ans, v[i] + (k - i - 1) / sz(v) * tot);
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3844
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
const int MOD = 1331;
using namespace std;
const int N = 2e5 + 10;
int n;
int a[N];
int main(){
	// freopen("in.txt", "r", stdin);
	cin >> n;
	int k;
	cin >> k;
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int i = k; i < n; i++) {
		if (a[i] > a[i - k]) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

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

int main() {
  int R;
  cin >> R;
  if(R < 1200) {
    cout << "ABC" << endl;
  }
  else if(R < 2800) {
    cout << "ARC" << endl;
  }
  else {
    cout << "AGC" << endl;
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

const li mod = 1e9 + 7;

int main() {
    li n, m;
    cin >> n >> m;
    vector<li> rs(n), cs(m);
    for (int i = 0; i < n; ++i) {
        cin >> rs[i];
    }
    for (int i = 0; i < m; ++i) {
        cin >> cs[i];
    }

    sort(rs.begin(), rs.end());
    sort(cs.begin(), cs.end());

    for (int i = 0; i < n - 1; ++i) {
        if (rs[i] == rs[i + 1]) {
            cout << 0 << endl;
            return 0;
        }
    }

    for (int j = 0; j < m - 1; ++j) {
        if (cs[j] == cs[j + 1]) {
            cout << 0 << endl;
            return 0;
        }
    }

    li ans = 1;
    li free = 0;
    li p = n -1, q = m - 1, v = n * m;
    while (v >= 1) {
        const li pd = n - 1 - p;
        const li qd = m - 1 - q;
        if (p >= 0 && rs[p] == v && q >= 0 && cs[q] == v) {

            free += pd + qd;
            v--;
            p--;
            q--;
        } else if (p >= 0 && rs[p] == v) {
            ans *= qd;
            ans %= mod;

            free += qd - 1;
            v--;
            p--;
        } else if (q >= 0 && cs[q] == v) {
            ans *= pd;
            ans %= mod;

            free += pd - 1;
            v--;
            q--;
        } else {
            ans *= free;
            ans %= mod;

            free--;
            v--;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
#include <climits>
#include <chrono>
using namespace std;

#pragma region

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

using ll = long long;
using P = pair<int, int>;

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; }

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter = " ") { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

#pragma endregion


int main() {
    int x;
    cin >> x;
    cout << (30 <= x ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>    //C++の標準ライブラリのヘッダを全て読み込む

#define _GLIBCXX_DEBUG

int main() {
    using std::cout;
    using std::endl;
    using std::cin;
    using std::string;
    using std::vector;

    int h,w;
    cin >> h >> w;
    vector<vector<char>> a(h+2, vector<char>(w+2, '#'));

    for(int i=0; i < h; i++){
        for(int j=0; j < w; j++){
            cin >> a.at(i+1).at(j+1);
        }
    }

    for(int i=0; i < h+2; i++){
        for(int j=0; j < w+2; j++){
            cout << a.at(i).at(j);
        }
        cout << endl;
    }
}

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

int main(){
   
    int n;
    cin>>n;
    int a[n+1];
    memset(a,0,sizeof(a));
    for(int z=1;z<=99;++z){
        for(int y=1;y<=99;++y){
            for(int x=1;x<=99;++x){
                int num = pow(x,2)+pow(y,2)+pow(z,2)+x*y+y*z+x*z;
                if(num<=n){
                    a[num]++;
                    /*set<int> s;
                    s.insert(x);s.insert(y);s.insert(z);
                    if(s.size()==1)a[num]+=1;
                    else if(s.size()==2)a[num]+=3;
                    else a[num]+=6;
                    s.clear();*/
                }
            }
        }
    }
    for(int i=1;i<n+1;++i){
        cout<<a[i]<<endl;
    }
    return 0;
}





Measured memory_bytes: 3596
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n, k; cin >> n >> k;
  vector<double> me(n);
  REP(i, n) {
    int p; cin >> p;
    me[i] = (p + 1) / 2.0;
  }
  double sum = 0, ans = 0;
  REP(i, k - 1) sum += me[i];
  FOR(i, k - 1, n) {
    sum += me[i];
    chmax(ans, sum);
    sum -= me[i - (k - 1)];
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1792
N = int(input())
Points = [list(map(int, input().split())) for i in range(N)]

odd_or_even = set([(x + y) % 2 for x, y in Points])
if len(odd_or_even) == 2:
    print(-1)
    exit()


D = [2 ** i for i in range(39)]
D = D[::-1]
if 0 in odd_or_even:
    D.append(1)

print(len(D))
print(' '.join(map(str, D)))
operation = {'R': (-1, 0), 'L': (1, 0), 'U': (0, -1), 'D': (0, 1)}  # 反対にすることに注意
for x, y in Points:
    nx, ny = x, y
    ans = ''
    for d in D:
        best_score = float('inf')
        best_command = None
        next_x, next_y = None, None

        for command, move in operation.items():
            mx, my = move
            tx, ty = nx + d * mx, ny + d * my
            score = abs(tx) + abs(ty)
            if score < best_score:
                best_score = score
                best_command = command
                next_x, next_y = tx, ty

        ans += best_command
        nx, ny = next_x, next_y

    print(ans)


Measured memory_bytes: 3316
module Main where

import           Data.Char
import           Data.Maybe                     ( fromJust )
import qualified Data.ByteString.Char8         as BS


bytestr2Int = fst . fromJust . BS.readInt
getInt = bytestr2Int <$> BS.getLine
getIntLH = map bytestr2Int . BS.words <$> BS.getLine
getIntLV n = replicate n $ getInt
getInt2D n = replicate n $ getIntLH


main :: IO ()
main = do
    n  <- getInt
    ss <- getLine
    putStrLn $ map (shift n) ss

shift :: Int -> Char -> Char
shift n c = toEnum $ if r < 91 then r else r - 26 where r = (+ n) $ ord c




Measured memory_bytes: 1404
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    string s;
    cin >> s;
    long long int k;
    cin >> k;
    for (int i = 0; i < s.size(); i++) {
        if (k == 1) {
            cout << s[i] << endl;
            return 0;
        }
        if (s[i] == '1') {
            k--;
        } else {
            cout << s[i] << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3584
#include <iostream>
#include <string>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define endl '\n'
const int INF = (1 << 30);
using namespace std;
typedef long long int ll;

void solve(){
    char s[20], ss[]="CODEFESTIVAL2016";
    cin >> s;
    int ans = 0;
    for(int i=0; i<16; i++){
        ans += (s[i] != ss[i]);
    }
    cout << ans << endl;
}

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

    solve();
}


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

using namespace std;

int main() {
    string s;
    cin >> s;
    int r = 0;
    for(int i=0, j=s.length()-1; i<j; i++, j--) {
        if(s[i]!=s[j]) r++;
    }
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 256
import math
A,B,H,M=map(int, input().split())

x_shorthand=A*math.cos(math.pi*(H+M/60)/6)
y_shorthand=A*math.sin(math.pi*(H+M/60)/6)

x_longhand=B*math.cos(math.pi*(H*60+M)/30)
y_longhand=B*math.sin(math.pi*(H*60+M)/30)

print(math.sqrt((x_shorthand-x_longhand)**2+(y_shorthand-y_longhand)**2))

Measured memory_bytes: 9516
#include <iostream>
#include <vector>

template<typename T>
void print_ary(std::vector<T> ary, char delim = '\n') {
    for(int i = 0; i < ary.size()-1; i++) {
        std::cout << ary[i] << delim;
    }
    std::cout << ary[ary.size()-1];
}


template<typename T>
void insertion_sort(std::vector<T>&& ary) {
    for (int i = 1; i < ary.size(); i++) {
        int target = ary[i];
        int j = i - 1;
        while(j >= 0 &&  ary[j] > target) {
            ary[j+1] = ary[j];
            j--;
        }
        ary[j+1] = target;
        print_ary(ary, ' ');
        std::cout << std::endl;
    }
}

template<typename T>
void bubble_sort(std::vector<T> && ary) {
    int n = ary.size();
    bool flag = true;
    int counter = 0;
    while (flag) {
        flag = false;
        for (int j = n - 1; j > 0; j--) {
            if (ary[j] < ary[j - 1]) {
                std::swap(ary[j], ary[j - 1]);
                flag = true;
                counter++;
            }
        }
    }
    print_ary(ary, ' ');
    std::cout << std::endl << counter << std::endl;;
}

template<typename T>
void selection_sort(std::vector<T>&& ary){
    int counter = 0;
    for (int i = 0; i < ary.size(); i++) {
        int min_index = i;
        for(int j = i + 1; j < ary.size(); j++) {
            if (ary[min_index] > ary[j]) {
                min_index = j;
            }
        }
        if(i != min_index) {
            std::swap(ary[i], ary[min_index]);
            counter++;
        }
    }
    print_ary(ary, ' ');
    std::cout << std::endl << counter << std::endl;;
}

int main(int argc, char const* argv[])
{
    int n;
    std::cin >> n;
    std::vector<int> ary(n);
    for (auto &i: ary) {
        std::cin >> i;
    }
    selection_sort(std::move(ary));
    return 0;
}

Measured memory_bytes: 3136
import java.util.*;
import java.io.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		
		if(str.length() < 4)
			System.out.println("No");
		else if(str.substring(0,4).equals("YAKI"))
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

Measured memory_bytes: 23508
#include<stdio.h>
 
int main(void){
int a, b, c,n, i;
scanf("%d", &n);
for(i=0;i<n;i++){
scanf("%d %d %d", &a, &b, &c);
int ok = 0;
if (a*a + b*b == c*c) ok = 1;
if (b*b + c*c == a*a) ok = 1;
if (c*c + a*a == b*b) ok = 1;

printf("%s\n", (ok?"YES":"NO"));
}
return 0;
}
 

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++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;

    }
}

LL comb(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;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int n;
    cin >> n;
    LL c = 0;
    while( n-- ) {
        int a;
        cin >> a;
        while( a % 2 == 0 ) {
            ++c;
            a >>= 1;

        }

    }
    cout << c << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll N = 1e9+7;
const int n_max = 1e5+10;

int main(){
    ll a,b; cin >> a >> b;
    ld ald = a, bld = b;
    ld ans = (ald + bld) / 2;
    if(ceil(ans) == floor(ans)){
        cout << int(ans) << endl;
    }
    else cout << "IMPOSSIBLE" << endl;
    return 0;
}

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

const int mod = 1000000007;

int dp[625];
int nex[625];

bool check(int p) {
	string s;
	string w = "WATGC";
	rep(i, 5) {
		s.push_back(w[p % 5]);
		p /= 5;
	}
	if(s.find("AGC") != string::npos) {
		return false;
	}
	rep(i, 4) {
		swap(s[i], s[i + 1]);
		if(s.find("AGC") != string::npos) {
			return false;
		}
		swap(s[i], s[i + 1]);
	}
	return true;
}

bool ch[3125];

signed main() {
	int n;
	cin >> n;
	rep(i, 3125) {
		ch[i] = check(i);
	}
	rep(i, 625) {
		dp[i] = 0;
	}
	dp[0] = 1;
	rep(i, n) {
		rep(j, 625) {
			nex[j] = 0;
		}
		rep(j, 625) {
			rep(k, 4) {
				if(ch[(k + 1) * 625 + j]) {
					nex[(k + 1) * 125 + j / 5] += dp[j];
				}
			}
		}
		rep(j, 625) {
			dp[j] = nex[j] % mod;
		}
	}
	int ans = 0;
	rep(i, 625) {
		ans += dp[i];
	}
	cout << ans % mod << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
 
 
int main(){
   int k,x;
   scanf("%d %d", &k,&x);
   k = 500*k;
   if(k>=x){
     printf("Yes");
   }else{
     printf("No");
   }
	return 0;
 
}

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

int a[100005], pn[100005];

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

    int ac = 0, pena = 0;
    rep(i, m) {
        int p;
        cin >> p;
        p--;
        string s;
        cin >> s;

        if (s == "WA" && a[p] == 0) pn[p]++;
        if (s == "AC" && a[p] == 0) {
            ac++;
            a[p] = 1;
            pena += pn[p];
        }
    }

    cout << ac << ' ' << pena << endl;
    return 0;
}


Measured memory_bytes: 4328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX=1e5+10;
ll l[200];
int solve(){
    ll x,k,d,m;
    cin>>x>>k>>d;
    if (x==0){
        if (k%2==0)return cout<<0<<endl,0;
        else return cout<<d<<endl,0;
    }
    if (x<0)x=-x;
    ll n=x/d;
    if(x<d){
        if (k%2==0)return cout<<x<<endl,0;
        else return cout<<d-x<<endl,0;
    }
    if (n<k){
        if (n>0) m=x%d;
        if((k-n)%2==0)cout<<m<<endl;
        else cout<<d-m<<endl;
        return 0;
    } else{
        m=x-k*d;
        cout<<m<<endl;
        return 0;
    }
}
int main(){
    int _=1;
    while(_--){
        solve();
    }
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define mkp make_pair
#define nl cout<<endl
#define MOD 1000000007
#define loop(i,start,end) for(ull i=start;i<end;i++)
#define N 100001
#define all(v) v.begin(),v.end()
#define oa(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";nl
#define ov(a) for(int i=0;i<a.size();i++)cout<<a[i]<<" ";nl
int main() 
{
    fastio();

  ll n,k;cin>>n;
  ll a[n][3];
  loop(i,0,n)cin>>a[i][0]>>a[i][1]>>a[i][2];
  for(int i = 1;i<n;i++)
  {
    a[i][0] += max(a[i-1][1],a[i-1][2]);
    a[i][1] += max(a[i-1][0],a[i-1][2]);
    a[i][2] += max(a[i-1][1],a[i-1][0]);
  }
  cout<<max(a[n-1][0],max(a[n-1][1],a[n-1][2]));


  return 0;
}

Measured memory_bytes: 2560
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn calc(
    target: usize,
    depth: usize,
    nexts: &Vec<Vec<usize>>,
    memo: &mut Vec<Vec<Option<f64>>>,
) -> f64 {
    let n = nexts.len();
    let target = if target < depth { 0 } else { target };
    if depth == n - 1 {
        return 0.0;
    }
    if let Some(v) = memo[target][depth] {
        return v;
    }
    let mut nrets = vec![];
    let mut sum = 0.0;
    for &t in nexts[depth].iter() {
        let v = 1.0 + calc(target, t, nexts, memo);
        sum += v;
        nrets.push(v);
    }
    let mut ret = sum / nexts[depth].len() as f64;
    if target == depth && nexts[depth].len() != 1 {
        nrets.sort_by(|lhs, rhs| lhs.partial_cmp(rhs).unwrap());
        sum -= nrets.last().unwrap();
        ret = sum / (nexts[depth].len() - 1) as f64;
    }
    memo[target][depth] = Some(ret);
    return ret;
}

fn main() {
    let n = read::<usize>();
    let m = read::<usize>();
    let mut nexts = vec![vec![]; n];
    for _i in 0..m {
        let s = read::<usize>() - 1;
        let t = read::<usize>() - 1;
        nexts[s].push(t);
    }
    let mut memo = vec![vec![None; n]; n];
    let mut ans = 1e+10;
    for i in 0..n {
        let nans = calc(i, 0, &nexts, &mut memo);
        if nans < ans {
            ans = nans;
        }
    }
    println!("{:.8}", ans)
}


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

#define ris   return *this
#define tmplt template<class T
#define dbgo  debug& operator<<
tmplt > struct rge { T b, e; };
tmplt > rge<T> range(T i, T j) { return rge<T>{i, j}; }
struct debug {
#ifdef LOCAL
~debug(){cerr<<endl;}
tmplt > dbgo(T x){cerr<<boolalpha<<x;ris;}
tmplt, class C > dbgo(pair<T, C> x){ris<<"("<<x.first<<", "<<x.second<<")";}
tmplt > dbgo(rge<T> x){*this<<"[";for(auto it=x.b;it!=x.e;it++){*this<<", "+2*(it==x.b)<<*it;}ris<<"]";}
tmplt > dbgo(vector<T> x){ris<<range(x.begin(),x.end());}
#else
tmplt > dbgo(const T&){ris;}
#endif
};
#define nav(...) << "[ " << #__VA_ARGS__ ": " << (__VA_ARGS__) << " ] "
using ll = long long;

#define forn(i, n) for(int i = 0; i < int(n); i++)
#define ford(i, n) for(int i = n-1; i >= 0; i--) 

template<typename T> 
void min_self(T& a, T b) { 
    a = min(a, b); 
}
template<typename T>
void max_self(T& a, T b) { 
    a = max(a, b); 
}

int calc(vector<int> a, vector<int> b, int bit) {
    int n = a.size();
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    debug() nav(a);
    debug() nav(b);
    ll ans = 0;
    int target = 1<<bit;
    for(int i = 0; i < n; i++) {
        int r = lower_bound(b.begin(), b.end(), 2*target - a[i]) - b.begin();
        r--;
        int l = lower_bound(b.begin(), b.end(), target - a[i]) - b.begin();
        //$ debug() nav(l) nav(r);
        ans += r - l + 1;
        l = lower_bound(b.begin(), b.end(), 3*target - a[i]) - b.begin();
        ans += n - l;
    }
    
    return ans & 1;
}

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

    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for(int i = 0; i < n; i++) {
        cin >> b[i];
    }
    int ans = 0;
    for(int bit = 0; bit < 30; bit++) {
        vector<int> na(n), nb(n);
        for(int i = 0; i < n; i++) {
            na[i] = a[i] % (1<<(bit+1));
            nb[i] = b[i] % (1<<(bit+1));
        }
        debug() nav(bit) nav(calc(na, nb, bit));
        ans |= calc(na, nb, bit)<<bit;
    }
    
    cout << ans << endl;
}













// Don't worry, you're getting better

// Read statement carefully
// Solve on paper first!
// Make your infinity big enough
// Overflows (long long)

// Author: blondie


Measured memory_bytes: 6968
n, m = gets.strip.split.map(&:to_i)

ans = Array.new(m + 1){0}

n.times do 
  _k, *like = gets.strip.split.map(&:to_i)
  like.each { |i| ans[i] = ans[i] + 1 }
end

puts ans.count { |x| x == n }


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

int main() {
  int a, b;
  cin >> a >> b;
  if (a == 1) a += 13;
  if (b == 1) b += 13;
  if (a > b) cout << "Alice" << endl;
  else if (a < b) cout << "Bob" << endl;
  else cout << "Draw" << endl;

  return 0;
}


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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) {
        ll d = euclid(b, a % b, y, x);
        return y -= a / b * x, d;
    }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1)
            ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1);
        return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e)
            return Mod(1);
        Mod r = *this ^ (e / 2);
        r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);

    while (true) {
        int T, P, R; cin >> T >> P >> R;
        if (!T) break;

        map<int, map<int, int>> penq;
        map<int, int> ttlpen;
        map<int, int> solved;

        rep(i, 0, R) {
            int t, p, time; string msg;
            cin >> t >> p >> time >> msg;
            if (msg == "CORRECT") {
                ttlpen[t] += penq[t][p] * 1200 + time;
                solved[t]++;
            } else {
                penq[t][p]++;
            }
        }

        vector<pair<pii, int>> ranks;
        rep(i, 1, T + 1) {
            ranks.push_back({{-solved[i], ttlpen[i]}, i});
        }
        sort(all(ranks));
        for (auto p : ranks) {
            cout << p.second << " " << -p.first.first << " " << p.first.second << endl;
        }
    }
}


Measured memory_bytes: 3296
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s="ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
	int n;
	cin>>n;
	string t;
	cin>>t;
	for(int i=0;i<t.size();i++)
	{
		t[i]=s[t[i]-'A'+n];
	}
	cout<<t;
	return 0;
}

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

int main() {
  long long int n,k;
  cin >> n >> k;
  
  long long int ans = 0;
  ans += (n/k) * (n/k) * (n/k);
  
  if (k <= (2 * n) && k % 2 == 0)
    ans += ((n - k/2)/k + 1) * ((n - k/2)/k + 1) * ((n - k/2)/k + 1);
  
  cout << ans << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val (a, b) = readLine()!!.split(' ').map(String::toLong)
    val pList = readLine()!!.split(' ').map(String::toLong)
    val one = pList.filter { it <= a }
    val two = pList.filter { a + 1 <= it && it <= b }
    val three = pList.filter { b + 1 <= it }
    println(Math.min(one.size, Math.min(two.size, three.size)))
}


Measured memory_bytes: 38236
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
void Calc(){
	long K = rei();
	long A = rei();
	long B = rei();
	long C = 1;
	if(C+K >= A){
		K -= A-C;
		C = A;
	}
	else{
		C += K;
		cout << C << endl;
		return;
	}
	if(B-A > 2){
		C += K/2*(B-A) + K % 2;
	}
	else{
		C += K;
	}
	cout << C << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

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

using namespace std;

const int mod = 1e9 + 7;

using int64 = long long;
const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

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

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int N, K;
  cin >> N >> K;
  int ret = 0;
  while(N--) {
    int x;
    cin >> x;
    ret += x >= K;
  }
  cout << ret << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<deque>
#include<queue>

using std::cout;
using std::cin;
using std::setw;
using std::setfill;
using std::string;
using std::pair;
using std::make_pair;
using std::vector;
using std::queue;
using std::deque;
using std::priority_queue;
using std::next_permutation;
//using std::iota;
using std::sort;
using std::greater;
using std::max;
using std::min;

using lli = long long int;
using ulli = unsigned long long int;

#define INF 999999999;

#define EVEL 1

#ifndef EVEL
#define dbug(X) std::cout << #X << ":" <<X<<" " ;
#define dbugf(s) std::cout << s << " ";
#define dbugln std::cout<<"\n";
#else
#define dbug(X) {}
#define dbugf(s) {}
#define dbugln {}
#endif

char rt[27];
char b;

int main(){
	cin.tie(0);
	std::ios::sync_with_stdio(false);
    rt['A'-'A'] = 'T';
	rt['T'-'A'] = 'A';
    rt['G'-'A'] = 'C';
    rt['C'-'A'] = 'G';

    cin >> b;
    cout << rt[b-'A'] << "\n";
	return 0;
}


Measured memory_bytes: 256
import sys

inf = 10**3

def solve():
    n = int(input())
    alps = [inf] * 26

    for i in range(n):
        s = input()

        tmp = [0] * 26

        for ch in s:
            tmp[ord(ch) - ord('a')] += 1

        for i in range(26):
            alps[i] = min(alps[i], tmp[i])

    ans = ''

    for i in range(26):
        ans += chr(i + ord('a')) * alps[i]

    print(ans)

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

if __name__ == '__main__':
    solve()

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = ll(1e18) + 1;

int main(void)
{
    string s, t;

    cin >> s >> t;

    cout << t + s << endl;
}

Measured memory_bytes: 256
from collections import deque
h,w=map(int,input().split())

maze=[]
INF=10**6
dx=[1,0,-1,0]
dy=[0,1,0,-1]

#マップ入力
for i in range(h):
    row=list(input())
    maze.append(row)


ans=0
for i in range(h):
    for j in range(w):
        queue=deque()
        d=[]
        used=[]
        for p in range(h):
            used.append([False for k in range(w)])
            d.append([INF for k in range(w)])
            
        if maze[i][j]==".":
            d[i][j]=0
            used[i][j]=True
            queue.append([i,j])

            while len(queue)>0:
                y,x=queue.popleft()
                for k in range(4):
                    nx=x+dx[k]
                    ny=y+dy[k]
                    if 0<=ny<h and 0<=nx<w:
                        if d[ny][nx]>d[y][x]+1 and maze[ny][nx]=="." and 0==used[ny][nx]:
                            d[ny][nx]=d[y][x]+1
                            ans=max(ans,d[ny][nx])
                            queue.append([ny,nx])
                            used[ny][nx]=True
print(ans)   

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for(auto&& i : a){
        cin >> i;
    }
    priority_queue<int> b(begin(a), end(a));
    for(int i = 0; i < m; i++){
        b.push(b.top() / 2);
        b.pop();
    }
    long long ans = 0;
    for(int i = 0; i < n; i++){
        ans += b.top();
        b.pop();
    }
    cout << ans << "\n";
}

Measured memory_bytes: 1408
S=list(str(input()))
if 1<=int(S[0]+S[1])<=12 and 1<=int(S[2]+S[3])<=12:
    print('AMBIGUOUS')
elif 1<=int(S[0]+S[1])<=12 and (1>int(S[2]+S[3]) or 12<int(S[2]+S[3])):
    print('MMYY')
elif 1<=int(S[2]+S[3])<=12 and (1>int(S[0]+S[1]) or 12<int(S[0]+S[1])):
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int n = sc.nextInt();
		int[] values = new int[w];
		for(int i = 0; i<n; i++){
			values[i] = i + 1;
		}
		for(int i = 0; i<n; i++){
			String str = sc.next();
			String[] ab = str.split(",");
			int a = Integer.parseInt(ab[0]) - 1;
			int b = Integer.parseInt(ab[1]) - 1;

			int tmp;
			tmp = values[a];
			values[a] = values[b];
			values[b] = tmp;
		}

		for(int i = 0; i<n; i++){
			System.out.println(values[i]);
		}
	}
}

Measured memory_bytes: 26252
import sys
a,b,c=map(int,input().split())
ans=0
if a%2==1 or b%2==1 or c%2==1:
    print(0)
    sys.exit()
if a%2==0 and a==b==c:
    print(-1)
    sys.exit()
while a%2==0 and b%2==0 and c%2==0:
    ta=a/2
    tb=b/2
    tc=c/2
    a=tb+tc
    b=ta+tc
    c=ta+tb
    ans+=1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

int f(int x){
    if(x%2 == 0){
        return x/2;
    }else{
        return 3*x + 1;
    }
}

int main(){
    int s;
    cin >> s;
    int tmp;
    int count = 1;
    
    if(s == 8){
        cout << 5 << endl;
        return 0;
    }else if(s == 4){
        cout << 4 << endl;
        return 0;
    }else if(s == 2){
        cout << 4 << endl;
        return 0;
    }else if(s == 1){
        cout << 4 << endl;
        return 0;
    }
    
    tmp = f(s);
    count++;
    
    while(tmp != 8){
        tmp = f(tmp);
        count++;
    }
    cout << count + 4 << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <unordered_map>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;
 
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define y1 abcde
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
#define int long long

const int inf = 2e9;
const int N = 2e5 + 15;
int n, a[N], ans, x[2];
bool used[N];
vector <int> cur;

main() {
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        cur.pb(a[i]);
    }
    sort(cur.begin(), cur.end());
    for(int i = 1; i <= n; ++i)
        a[i] = lower_bound(cur.begin(), cur.end(), a[i]) - cur.begin() + 1;
    for(int i = 1; i <= n; ++i) {
        if(a[i] % 2 != i % 2)
            ++x[a[i] & 1];
    }
    cout << max(x[0], x[1]) << endl;
    return 0;
}

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

int main() {
  int N,count = 0;
  cin >> N;
  vector<int> V(N);
  for ( int i = 0 ; i < N ; i++ )
    cin >> V.at(i);
  for ( int j = 0 ; j < N ; j++ ) {
    int A = 0;
    for ( int k = 0 ; k < j ; k++ ) {
      if ( V.at(j) == V.at(k) )
        A++;
    }
    if ( A == 0 )
      count++;
  }
  cout << count << endl; 
  
}

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

int main() {
  int n;
  cin >> n;
  vector<int> r(n);
  for (int i = 0; i < n; i++) {
    cin >> r.at(i);
  }

  int min_r, max_d;
  max_d = r.at(1) - r.at(0);
  min_r = r.at(0);
  for (int i = 1; i < n; i++) {
    max_d = max(max_d, r.at(i) - min_r);
    min_r = min(min_r, r.at(i));
  }

  cout << max_d << endl;
  
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using pii = pair<int,int>;
#define ALL(x) (x).begin(),(x).end()

int main(){
	ll K;
	cin >> K;
	queue<string> q;
	string ar[10] = {"1","2","3","4","5","6","7","8","9"};
	for(ll i=1;i<=9;i++) q.push(ar[i-1]);
	int cnt = 0;
	while(!q.empty()) {
		string bef = q.front();
		cnt++;
		if(cnt == K) {
			cout << bef << endl;
			return 0;
		}
		char tmp = bef[bef.size()-1];
		q.pop();
		if((char)(tmp-1) >= '0') q.push(bef+(char)(tmp-1));
		q.push(bef+tmp);
		if((char)(tmp+1) <= '9') q.push(bef+(char)(tmp+1));
	}
}

Measured memory_bytes: 13824
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007LL

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

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

	ll n;cin >> n;
	vector<ll> ans(100000);
	for(ll i = 1;i <= 100;i++){
		for(ll j = 1;j <= 100;j++){
			for(ll k = 1;k <= 100;k++){
				ll now = i * i + j * j + k * k + i * j + j * k + i * k;
				ans[now]++;
			}
		}
	}

	REP(i, n){
		cout << ans[i+1] << endl;
	}

	return 0;
}


Measured memory_bytes: 3972
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N; cin >> N;
    string s; cin >> s;
    vector<int> S(N);
    for (int i = 0; i < N; ++i)
    {
        S[i] = s[i] == 'o' ? 1 : -1;
    }
    // Ai は i 番目の動物が羊のとき +1, 狼のとき -1 をとるとし，
    // Si は si = o のとき +1, si = x のとき -1 をとるとすると
    // A{i-1} * A{i+1} = Ai * Si が成立する
    // A0, A1 を決めれば残りは順に計算できる -> 矛盾がでなければOK
    vector<int> ansAs;
    bool hasFound = false;
    for (const int A0 : {1, -1})
    {
        for (const int A1 : {1, -1})
        {
            vector<int> tmpAs(N);
            tmpAs[0] = A0, tmpAs[1] = A1;
            for (int i = 0; i < N; ++i)
            {
                tmpAs[(i + 2) % N] = tmpAs[(i + 1) % N] * S[(i + 1) % N] / tmpAs[i];
            }
            if (tmpAs[0] == A0 && tmpAs[1] == A1)
            {
                hasFound = true;
                ansAs = tmpAs;
                break;
            }
        }
        if (hasFound) break;
    }
    if (hasFound)
    {
        for (const int Ai : ansAs)
        {
            cout << (Ai == 1 ? 'S' : 'W');
        }
        cout << endl;
    }
    else
    {
        cout << -1 << endl;
    }
}


Measured memory_bytes: 1784
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    int sugerWater = 0;
    int suger = 0;
    float maxConcentration = 0.0;
    for (int a = 0; a <= 30; a++) {
        for (int b = 0; b <= 15; b++) {
            for (int c = 0; c <= 3000; c++) {
                for (int d = 0; d <= 1500; d++) {
                    int x = a * 100 * A + b * 100 * B;
                    int y = c * C + d * D;
                    if (x + y > 0 && x + y <= F && 100 * y <= x * E) {
                        float concentration = 100.0 * y / (x + y);
                        if(maxConcentration <= concentration) {
                            maxConcentration = concentration;
                            sugerWater = x + y;
                            suger = y;
                        }
                    } else {
                        break;
                    }
                }
            }
        }
    }
    cout << sugerWater << ' ' << suger << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define all(uiet) uiet.begin(),uiet.end()
#define read(UIET) for(int i = 0; i < n; ++i) cin >> UIET[i]
#define out(UIET) for(int i = 0; i < n; ++i) cout << UIET[i]
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"
#define mod 1000000007
const int INF=(1LL<<60)-1;
int32_t main(){
    SPEED;
    string s;
    cin >> s;
    int a = 0, z = 0;
    for(int i = 0; i < len(s); ++i){
        if(s[i] == 'A' && a == 0) a = i + 1;
        if(s[i] == 'Z') z = i + 1; 
    }
    cout << z - a + 1 ;
}

Measured memory_bytes: 3776
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <string>
#include <math.h>
#include <time.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
int main() {
	int a, b, c, x, y, z;
	cin >> a >> b >> c >> x >> y;
	bool isX = false;
	if (x < y)
		z = x;
	else {
		z = y;
		isX = true;
	}
	int ans = min(2 * c*z, z*a + z*b);
	if (isX)
		ans += min(2 * (x - z)*c, (x - z)*a);
	else
		ans += min(2 * (y - z)*c, (y - z)*b);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
//フェニック木　Binary Indexed Tree;
#include <iostream>
#include <atcoder/fenwicktree>
using namespace std;
using namespace atcoder;

int main(){
    int N, Q;
    cin >> N >> Q;
    fenwick_tree<long long> fw(N);
    for(int i = 0; i < N; i++){
        long long a;
        cin >> a;
        fw.add(i, a);
    }
    for(int i = 0; i < Q; i++){
        bool b; long long u; long long v;
        cin >> b >> u >> v;
        if(b){
            cout << fw.sum(u, v) << endl;
        }
        else{
            fw.add(u, v);
        }
    }
    return 0;
}

Measured memory_bytes: 8200
N = int(input())
A = [0] + list(map(int, input().split()))
 
B = [0] * (N + 1)
for i in reversed(range(1, N + 1)):
    ball = 0
    base = i + 1
 
    for j in range(i, N + 1, i):
        ball += B[j]
 
    if ball % 2 != A[i]:
        B[i] = 1
 
print(sum(B))
print(*[i for i, b in enumerate(B) if b == 1], sep=' ')

Measured memory_bytes: 17680
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function root(uf::Array{Int,1},x);s=x;while uf[s]>0;s=uf[s];end;s;end
same(uf::Array{Int,1},x,y)=root(uf,x)==root(uf,y)?true:false;
function unite(uf::Array{Int,1},x,y);l=root(uf,x);r=root(uf,y);if l!=r;if uf[l]<uf[r];uf[l]+=uf[r];uf[r]=l;else;uf[r]+=uf[l];uf[l]=r;end;end;end

function main()
	n,m = readline() |> split |> parseMap
	d = zeros(Int,n)
	e = Tuple{Int,Int}[(0,0) for i in 1:m]
	for i in 1:m
		a,b = readline() |> split |> parseMap
		d[a] += 1
		d[b] += 1
		e[i] = (a,b)
	end
	fo = 0
	fn = 0
	for i in 1:n
		if d[i]==1
			fo += 1
		elseif d[i]==n-1
			fn += 1
		end
	end
	if fo==n-1&&fn==1&&m+1==n
		println(0)
	else
		uf = -ones(Int,2*n)
		for i in 1:m
			unite(uf,e[i][1],e[i][2]+n)
			unite(uf,e[i][1]+n,e[i][2])
		end
		f = 0
		for i in 1:n
			if same(uf,i,n+i)
				f = 1
				break
			end
		end
		if f==1
			println(div(n*(n-1),2)-m)
		else
			g = [Int[] for i in 1:n]
			for i in 1:m
				push!(g[e[i][1]],e[i][2])
				push!(g[e[i][2]],e[i][1])
			end
			ab = zeros(Int,n)
			ab[1] = 1
			stack = Int[1]
			while !isempty(stack)
				now = pop!(stack)
				for i in g[now]
					if ab[i]==0
						push!(stack,i)
						ab[i]=ab[now]*(-1)
					end
				end
			end
			f = 0
			for i in 1:n
				if ab[i]==1
					f += 1
				end
			end
			println(f*(n-f)-m)
		end
	end
end

main()

Measured memory_bytes: 171548
// B - Iron Bar Cutting
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	vector<long long> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	long long total = accumulate(a.begin(), a.end(), 0LL);
	long long ans = total, x = 0, y = total;
	for (int i = 0; i < n; i++) {
		x += a[i], y -= a[i];
		ans = min(ans, abs(y - x));
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <math.h> 
using namespace std;

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int out(int x) {
    int a[100010];
    for (int i = 1; i <= 100003; i++) {
        a[i] = i;
    }
    int init = x;
    if (x % 2 == 0) init = x + 1;
    int ans = 0;
    for (int i = init; i <= 100003; i += 2) {
        if (IsPrime(a[i])) {
          ans = a[i] ;
          break;
        }
    }
    return ans;
}


int main() {
    int x, ans;
    cin >> x;
    if (IsPrime(x)) ans = x;
		else ans = out(x); 
	cout << ans << endl;
}

Measured memory_bytes: 640
//Code is like humor. When you have to explain it, it’s bad.
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#include <bits/stdc++.h>
#define MOD 1000000007
#define MOD1 998244353
#define endl "\n"
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define mkp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define int ll
using namespace std;
typedef long long ll;
typedef pair<int,int> pairs;
typedef map<int,int> maps;
typedef vector <int> VI;
typedef std::multimap<int, pair<int,int>>::iterator MMIPIterator;
typedef std::map<int, int>::iterator MIIIterator;
double pi = 2 * acos(0.0);


int32_t main()  {
    fastio;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    #endif
    
    int s,w;
    cin>>s>>w;
    if(w>=s) cout << "unsafe\n";
    else cout << "safe\n";
    
    return 0;
    
}



Measured memory_bytes: 3652