akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>


void Partition(int *,int,int);

main() {

  int i,x;
  scanf("%d",&x);

  int *A;
  A = malloc(sizeof(int)*x);
  for(i=0;i<x;i++){
    scanf("%d",&A[i]);
  }
  Partition(A,0,x-1);

  return 0;
}

void Partition(int *A,int p,int r){
  int i,j,x,y;
  x = A[r];
  i = p ;
  for(j=p;j<=r-1;j++){
    if(A[j] <= x){    
      y = A[i];
      A[i] = A[j];
      A[j] = y;
      i = i+1;
    }
  }
  
  y = A[i];
  A[i] =A[r];
  A[r] = y;
  
  
  for(j=0;j<=r;j++){
    if(j == i){
       printf("[%d]",A[j]);
    }
    else printf("%d",A[j]);
    if(j<r) printf(" ");
  }
    printf("\n");
  
}

Measured memory_bytes: 996
#include<stdio.h>

int main(){
    int m,f,r;
    while(scanf("%d %d %d",&m,&f,&r) && ((m != -1 || f != -1|| r != -1))){
        if(m == -1 || f == -1){
            printf("F\n");
        } else if( m+f >= 80){
            printf("A\n");
        } else if(m+f >= 65 && m+f < 80 ){
            printf("B\n");
        } else if(m+f >= 50 && m+f < 65){
            printf("C\n");
        } else if(m+f >= 30 && m+f < 50){
            if(r >= 50){
                printf("C\n");
            } else {
                printf("D\n");
            }
        } else if(m+f < 30){
            printf("F\n");
        }
    }
    return 0;
}


Measured memory_bytes: 2552
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  int n,a;
  cin >> n >> a;
  cout << n*n - a << endl;
  return 0;
}


Measured memory_bytes: 256
s = input()
K = int(input())
l = min(len(s),K)
lis = []
for i in range(1,l+1):
  for j in range(len(s)-i+1):
    lis.append(s[j:j+i])
lis = list(set(lis))
lis.sort()
print(lis[K-1])

Measured memory_bytes: 40176
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

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

    ll s = 0;
    Rep (i, 3) {
        ll a;
        cin >> a;
        s += a;
    }

    if (s >= 22) cout << "bust\n";
    else cout << "win\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define F(i,n) for(long long int i=0;i<n;i++)
#define REF(i,a,b) for(int i=a;i<=b;i++)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ln "\n"
#define m 1000000007
#define fastio ios::sync_with_stdio(0);cin.tie(0);
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")


int main() {
    fastio;
    fast;
    ll n;
    cin>>n;
    vector<ll> v(n);
    F(i,n)
    {
        cin>>v[i];
    }
    ll cnt=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            for(int k=j+1;k<n;k++)
            {
                if((v[i]!=v[j] && v[j]!=v[k] && v[k]!=v[i]) && (v[i]+v[j]>v[k] && v[k]+v[j]>v[i] && v[k]+v[i]>v[j]))
                {
                    cnt++;
                }
            }
        }
    }
    cout<<cnt<<ln;
    return 0;
}


Measured memory_bytes: 3628
N = int(input())
a = list(map(int, input().split()))
box = [0]*N
hantei = True
ans = 0
while hantei == True:
    for i in range(N):
        if a[i] % 2 == 0:
            a[i] = a[i]//2
        else:
            hantei = False
            break
    ans += 1
print(ans-1)

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

using namespace std;

#define rep(i, a, b) for (int i = (a), i##_end_ = (b); i <= i##_end_; ++i)
#define drep(i, a, b) for (int i = (a), i##_end_ = (b); i >= i##_end_; --i)
#define clar(a, b) memset((a), (b), sizeof(a))
#define debug(...) fprintf(stderr, __VA_ARGS__)
template <typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
typedef long long LL;
typedef long double LD;
void procStatus() {
	ifstream t("proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}
LL read() {
	LL x = 0, flag = 1;
	char ch = getchar();
	for (;!isdigit(ch); ch = getchar()) if (ch == '-') flag *= -1;
	for (;isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
	return x * flag;
}
void write(LL x) {
	if (x < 0) putchar('-'), x = -x;
	if (x >= 10) write(x / 10);
	putchar(x % 10 + '0');
}

const int Maxn = 1009, Mod = 1e9 + 7;
int mplus(int x, const int &y) {
	x += y;
	if (x >= Mod) x -= Mod;
	return x;
}	
int n, k, g[Maxn];
int dp[Maxn][Maxn];
vector <int> G[Maxn];

void Init() {
	n = read() * 2, k = read();
	rep (i, 1, n) {
		if (i & 1) continue;
		g[i] = 1;
		for (int j = 1; j <= i; j += 2) g[i] = g[i] * 1ll * j % Mod;
	}
	rep (i, 1, k) {
		int u = read(), v = read();
		G[u].push_back(v), G[v].push_back(u); 
	}
}

int cnt[Maxn], cnt1[Maxn];
void Solve() {
	int ans = 0;

	g[0] = 1;
	rep (i, 1, n) {
		cnt[i] = cnt[i - 1] + (G[i].size() != 0);
		cnt1[i] = cnt1[i - 1] + (G[i].size() == 0);
	}

	rep (i, 1, n) 
		rep (j, i, n) {
			if ((j - i + 1) & 1) continue;
			bool outer = false;
			rep (l, i, j) {
				rep (p, 0, G[l].size() - 1) 
					if (G[l][p] < i || G[l][p] > j) {
						outer = true;
						break;
					}
				if (outer) break;
			}
			if (outer) continue;
			dp[i][j] = g[cnt1[j] - cnt1[i - 1]];
			rep (l, i, j - 1) 
				dp[i][j] = mplus(dp[i][j], Mod - 1ll * dp[i][l] * g[cnt1[j] - cnt1[l]] % Mod);
			ans = mplus(ans, dp[i][j] * 1ll * g[cnt1[i - 1] + cnt1[n] - cnt1[j]] % Mod);
		}
	cout << ans << endl;
}

int main() {
//	freopen("bosky.in", "r", stdin);
//	freopen("bosky.out", "w", stdout);

	Init();
	Solve();	

#ifdef Qrsikno
	procStatus();
	debug("\nRunning time: %.3lf(s)\n", clock() * 1.0 / CLOCKS_PER_SEC);
#endif
	return 0;
}


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

// clang-format off
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define endl '\n'
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { 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> ostream &operator<<(ostream &os, 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> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

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); }
// clang-format on

void solver() {
    int n = input();
    set< string > used;
    
    string pre = input< string >();
    used.insert(pre);
    range(i, 0, n - 1) {
        string w = input< string >();

        if (used.count(w) || pre.back() != w.front()) {
            cout << "No" << endl;
            return;
        }
        
        used.insert(w);
        pre = w;
    }
    
    cout << "Yes" << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


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

#define int long long
#define INF 9223372036854775807
#define M_PI 3.14159265358979323846
#define double long double

int mod = 1e9+7;

int fastPow(int b, int e){int r = 1;while(e){if(e%2 == 1){r*=b;r%=mod;}b*=b;b%=mod;e/=2;}return r;}
int pgcd(int a, int b){ if(a%b == 0) return b; else return pgcd(b, a%b);}
int sign(int a){if(a < 0){ return -1;}if(a == 0) {return 0;}if(a > 0) {return 1;}}
bool isPrime(int a){if(a == 1) {return false;}int f = sqrt(a);for(int i = 2; i<=f; i++){if(a%i == 0){return false;}}return true;}
int toInt(string s){int tot = 0;for(int i = s.size()-1; i >= 0; i--){tot+=((s[i]-'0')%mod)*fastPow(10,i);tot%=mod;}return tot;}
string toString(int a){string s = "";while(a){s = (char)('0'+a%10) + s;a/=10;}return s;}

int memo[1009][1009];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    char tab[n+1][m+1];
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> tab[i][j];
        }
    }
    memo[1][1] = 1;
    for(int i = 1; i <=n; i++){
        for(int j = 1; j <= m; j++){
            if(tab[i][j] != '.') continue;
            else memo[i][j] += memo[i-1][j]+memo[i][j-1];
            memo[i][j]%=mod;
        }
    }
    cout << memo[n][m] << endl;
}


Measured memory_bytes: 9088
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <bitset>
#include <functional>
using namespace std;
const constexpr int INF = 1e9;
typedef std::pair<std::string,double> P;

int L, N, sum; 
string s;
vector<int> v;
int dist[1000];
bool dp[11000];
void solve(){
    if(N<1200) cout << "ABC" << endl;
    else if(N<2800) cout << "ARC" << endl;
    else cout << "AGC" << endl;
}
int main() {
    cin >> N;
    solve();
	return 0;
}

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        double r=sc.nextDouble();
        double a=r*2*Math.PI;
        double b=r*r*Math.PI;
        System.out.printf("%10f %10f",b,a);
    }
}


Measured memory_bytes: 28224
s = input()
f,b = int(s[:2]),int(s[2:])
if 1 <= f <= 12:
  if 1 <= b <= 12:
    print("AMBIGUOUS")
  else:
    print("MMYY")
else:
  if 1 <= b <= 12:
    print("YYMM")
  else:
    print("NA")

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

using namespace std;

int main(){
    int a =0,x=0;
    string s,t;
    cin >> s>>t;

    for(int i=0; i <3;i++){
        if(s[x]==t[x]){
            a++;
        }
        x++;
    }
cout << a << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
using namespace std;


// PROOF?
vector<vector<pair<int,int>>> adj;
vector<int> vis;
vector<int> col;
void dfs(int u,int c=0){
    if(vis[u])return;
    vis[u]=1;
    col[u]=c;
    for(auto e:adj[u]){
        int v=e.first;
        int w=e.second;
        dfs(v,c^w);
    }
}
int main() {
    int n;
    cin>>n;
    adj.resize(n+3);
    vis.resize(n+3);
    col.resize(n+3);
    for(int i=0;i<n-1;++i){
        int u,v,w;
        cin>>u>>v>>w;
        adj[u].push_back({v,w%2});
        adj[v].push_back({u,w%2});
    }
    dfs(1);
    for(int i=1;i<=n;++i)cout<<col[i]<<endl;
    return 0;
}


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

int main (void){
    long long int n, p, ans;
    ans = 1;
    cin >> n >> p;
    if (n == 1){
        cout << p << endl;
        return 0;
    }

    for (long long int i = 2; i*i <= p; i++){
        int cnt = 0;
        while (p % i == 0){
            cnt++;
            p /= i;
            if (cnt == n){
                ans *= i;
                cnt = 0;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

N = int(input())
d = {}
for i in range(N):
    S = input()
    if S in d:
        cnt = d[S]
        cnt += 1
        d.update({S: cnt})
    else:
        d.update({S: 1})
list = sorted(d.items(), key=lambda x:(-x[1], x[0]))
max = list[0][1]
for v in list:
    if max == v[1]:
        print(v[0])
    else:
        break

Measured memory_bytes: 59228
//#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
//#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
//#pragma GCC target("avx2")  //Enable AVX
#include<bits/stdc++.h>
using namespace std;

#define all(a) begin(a),end(a)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int mod=1e9+7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int mul(int a,int b){
  return ((a)*1ll*(b))%mod;
}

void add(int &a,int b){
  a+=b;
  if(a>=mod)a-=mod;
}

int sub(int a,int b){
  a-=b;
  if(a<0){
    a+=mod;
  }
  return a;
}

int powz(int a,int b){
  int res=1;
  while(b){
    if(b&1){
      res=mul(res,a);
    }
    b/=2;
    a=mul(a,a);
  }
  return res;
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
  input>>x.F>>x.S;
  return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
  for(auto& i:x)
    input>>i;
  return input;
}

template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
  for(auto& i:x)
    output<<i<<' ';
  return output;
}

template<typename T>
vector<pair<T,int>> getvec(int n){
  vector<pair<T,int>>a(n);
  for(int i=0;i<a.size();i++){
    cin>>a[i].F;
    a[i].S=i;
  }
  return a;
}

const int N=200005;

void solve(){
  string s;
  cin>>s;
  if(s=="ABC"){
    cout<<"ARC";
  }
  else{
    cout<<"ABC";
  }
  
}

signed main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc=1;
  //cin>>tc;
  for(int _=0;_<tc;_++){
    // cout<<"Case #"<<_+1<<": ";
    solve();
    if(_!=tc-1){
      cout<<'\n';
    }
  }
}



Measured memory_bytes: 3624
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b) { return *(int *)a - *(int *)b; }                            /* 1,2,3,4.. */
int des(const void *a, const void *b) { return *(int *)b - *(int *)a; }                            /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { return *(char *)a - *(char *)b; }                     /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) { return strcmp(*(const char **)a, *(const char **)b); } /* aaa,aab.. */
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
#define rep(i, n) for (int i = 0; i < n; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void)
{
  int a, b, t;
  scanf("%d %d %d", &a, &b, &t);

  int sets = t / a;
  int sheets = sets * b;
  printf("%d\n", sheets);
  return 0;
}


Measured memory_bytes: 128
"""
各数字が何回たされて、何回引かれるかを考えればよい。
各数は自分以下の数の個数をMとすると、cmb(M,K-1)回足される。

各数は自分以上の数の個数をMとすると、cmb(M,K-1)回引かれる。
"""
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

N,K = map(int,input().split())
A = list(map(int,input().split()))

A.sort()

ans = 0
for i in range(N):
    a = A[i]
    ans += a * cmb(i,K-1,p)
    ans %= p

A = A[::-1]
for i in range(N):
    a = A[i]
    ans -= a * cmb(i,K-1,p)
    ans %= p

print(ans)


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

class Program {
    static void Main (string[] args) {
        var tempstr = Console.ReadLine ().Split (' ');
        long a = long.Parse (tempstr[0]);
        long b = long.Parse (tempstr[1]);
        long c = long.Parse (tempstr[2]);
        long d = long.Parse (tempstr[3]);

        long x1 = a * c;
        long x2 = a * d;
        long x3 = b * c;
        long x4 = b * d;

        long max = Math.Max (Math.Max (x1, x2), Math.Max (x3, x4));
        Console.WriteLine (max);

    }

}

//dotnet run --project test

Measured memory_bytes: 27532
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const Arr = (input.trim()).split("\n");
const N1 = Number(Arr[0]);
const arr1 = Arr[1].split(" ").map(Number);
// const N2 = Number(Arr[2]);
const arr2 = Arr[3].split(" ").map(Number);

const binarySearch = (function(arr, N) {
  return (key) => {   
    let mid;
    let left = 0;
    let right = N;
    if (key < arr[0] || arr[N-1] < key) return 0;
    while (left < right) {
      mid = Math.floor((left + right) / 2);
      if (key < arr[mid]) right = mid;
      else if (key > arr[mid]) left = mid + 1;
      else return 1;
    }
    return 0;
  }
})(arr1, N1);

const summing = (a, b) => a + b;
console.log(arr2.map(binarySearch).reduce((a, b) => a + b, 0));


Measured memory_bytes: 34952
#include <bits/stdc++.h>
#define rep(i,a,b) for(auto i=(a);i<(b);i++)
#define per(i,a,b) for(auto i=(a);i>=(b);i--)
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define int_inf 0x3f3f3f3f
#define int_max 2147483647
#define ll_max 9223372036854775807
#define ull_max 18446744073709551615
#define ll_inf 0x7f7f7f7f7f7f7f7f
#define lowbit(x) (x)&(-x)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define eps 1e-8
#define all(v) (v.begin(),v.end())
#define db double
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const double pi=acos(-1.0);
const double inf = 1e100;
template<class T>
inline T read()
{
	T x=0,f=1;char s=getchar();
	while(s<'0'||s>'9') {if(s=='-')f=-1;s=getchar();};
	while(s>='0'&&s<='9'){x=(x<<3)+(x<<1)+s-48;s=getchar();};
	return x*f;
}
template<typename T>
inline void wri(T x)
{
	if(x<0){x=-x;putchar('-');};
	if(x/10) wri(x/10);
	putchar(x%10+48);
}
template<typename T>
inline void print(T x,char s)
{
	wri(x);
	putchar(s);
}
template<typename T>
T gcd(T a,T b)
{
	return b==0?a:gcd(b,a%b);
}
//关闭流同步就不能手写读入优化啦
string s; 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>s;
    if(s[0]>='a'){
    	cout<<'a';
	}
	else 
	cout<<'A';
	return 0;
}



Measured memory_bytes: 3648
// C - Sugar Water
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define irp(i,s,e) for(int i=(s);i>(e);--i)

void solve(int w1,int w2, int s1, int s2, int solute, int volume){
	int WS = w1*100, S = 0;
	int wend = volume/100;
	double maxper = 0.0;
	rp(iw, 1, wend+1) rp(jw, 0, wend+1){
		int w = w1*iw + w2*jw;
		if(w > wend) break;
		int send = volume - w*100;
		irp(is, send, -1) irp(js, send, -1){
			int s = s1*is + s2*js;
			if(s > send || s > solute*w) continue;
			int ws = w * 100 + s;
			if(ws > volume) continue;
			double per = 100.0*s/ws;
			if(maxper >= per) continue;
			maxper = per;
			WS = ws;
			S = s;
			break;
		}
	}
	printf("%d %d\n",WS,S);
}

int main(){
	int a,b,c,d,e,f;
	cin>>a>>b>>c>>d>>e>>f;
	solve(a,b,c,d,e,f);
}

Measured memory_bytes: 256
/// e.cpp

# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
const pair < int , int > DD[] = {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < __typeof(v.x) > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vl vector < ll >
# define pll pair < ll , ll >
# define pii pair < int , int >
# define mp make_pair
# define db long double
# define fail puts("-1")
# define yes puts("YES")
# define no puts("NO")
# define PP puts("Possible")
# define II puts("Impossible")
# define vii vector < pii >
# define vll vector < pll >
# define pb push_back
# define pdd pair < db , db >
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    static int a[1 << 20];
    static int b[1 << 20];
    static vi g[1 << 20];
    int n,m;
    fi>>n>>m;
    for (int i = 1;i <= m;++i)
        fi>>a[i]>>b[i],g[a[i]].pb(i),g[b[i]].pb(i);
    static int D[1 << 10][1 << 10];
    memset(D,-1,sizeof(D));
    static int ok[1 << 20];
    for (int i = 1;i <= n;++i)
        ok[i] = 1;
    auto go = [&](int vertex)
    {
        queue < int > Q;
        Q.push(vertex);
        D[vertex][vertex] = m + 1;
        while (!Q.empty())
        {
            int node = Q.front();
            Q.pop();
            for (auto it : g[node])
            if (it < D[vertex][node])
            {
                int nxt = a[it] + b[it] - node;
                if (D[vertex][nxt] != -1)
                {
                    ok[vertex] = 0;
                    return;
                }
                D[vertex][nxt] = it;
                Q.push(nxt);
            }
        }
    };
    for (int i = 1;i <= n;++i)
        go(i);
    int ans = 0;
    for (int i = 1;i <= n;++i)
        for (int j = i + 1;j <= n;++j)
        if (ok[i] && ok[j] && D[i][j] == -1 && D[j][i] == -1)
        {
            int ok = 0;
            for (int k = 1;k <= n;++k)
                ok |= D[i][k] != -1 && D[j][k] != -1 && D[i][k] != D[j][k];
            ans += 1 - ok;
        }
    fo << ans << '\n';
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


Measured memory_bytes: 34304
#include<cstdio>
#include<cstring>
#include<vector>
#define For(i,A,B) for(i=(A);i<=(B);++i)
#define pb push_back
using namespace std;
typedef long long ll;
const int N=300050;
const int M=100050;
int c[N],w[N],n;
ll f[10][M],s[M];
vector<int> q[N],id[N],t;
inline void chkmax(ll &a,ll b){if(a<b)a=b;}
void dfs(int u,short d){
	int i,l=q[u].size()-1;
	if(u<512){
		For(i,1,100000){
			f[d][i]=f[d-1][i];
			if(i>=w[u])chkmax(f[d][i],f[d-1][i-w[u]]+c[u]);
		}
		For(i,0,l)s[id[u][i]]=f[d][q[u][i]];
	}else{
		int S;
		short j,len;
		ll ans,sc,sw;
		t.clear();
		for(i=u;i>511;i>>=1)t.pb(i);
		len=t.size();
		For(i,0,l){
			ans=0ll;
			For(S,0,(1<<len)-1){
				sc=sw=0ll;
				For(j,0,len-1)if((S>>j)&1){sc+=c[t[j]];sw+=w[t[j]];}
				if(sw<=q[u][i])chkmax(ans,f[9][q[u][i]-sw]+sc);
			}
			s[id[u][i]]=ans;
		}
	}
	if(u*2<=n){
		dfs(u*2,d+1);
		if(u*2<n)dfs(u*2|1,d+1);
	}
}
int main(){
	int m,i,u,l;
	scanf("%d",&n);
	For(i,1,n)scanf("%d%d",c+i,w+i);
	scanf("%d",&m);
	For(i,1,m){
		scanf("%d%d",&u,&l);
		q[u].pb(l);id[u].pb(i);
	}
	dfs(1,1);
	For(i,1,m)printf("%lld\n",s[i]);
	return 0;
}

Measured memory_bytes: 33344
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N, M = in.next().toInt
  val graph = Array.fill[List[Int]](N+1)(Nil)
  for (_ <- 1 to M) {
    val u, v = in.next().toInt
    graph(u) = v :: graph(u)
  }
  val S, T = in.next().toInt

  //
  val q = new Queue[(Int, Int)]() // (moveNum, node)
  val dp = Array.ofDim[Boolean](N+1, 4)

  q.enqueue((0, S))
  dp(S)(3) = true

  var ans = -1
  breakable {
    while (!q.isEmpty) {
      val (cost, now) = q.dequeue

      if (now == T) {
        ans = cost
        break
      }

      var set = Set[Int]()
      set += now

      for (i <- 0 to 3) {
        val nextSet = Set[Int]()
        for (e <- set) {
          if (i == 3) {
            if (!dp(e)(i)) {
              q.enqueue((cost+1, e))
            }
          }
          else {
            if (!dp(e)(i)) {
              dp(e)(i) = true
              for (e2 <- graph(e))
                nextSet += e2
            }
          }
        }

        set = nextSet
      }
    }
  }

  println(ans)

}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.deep))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


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

int n, m, k, x, y;
string s;

int main(void)
{
    cin >> n;
    vector<long long> l(n);
    for (int i = 0; i < n; i++) cin >> l[i];
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            for (int k = j + 1; k < n; k++)
            {
                if (l[i] != l[j] && l[j] != l[k] && l[k] != l[i])
                {
                    if (l[i] + l[j] > l[k] && l[k] + l[j] > l[i] && l[i] + l[k] > l[j]) ans++;
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define inf 10000000000

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

    ll a, b, c;
    cin >> a >> b >> c;
    if(a == b){
        cout << c << endl;
    }else if(b == c){
        cout << a << endl;
    }else{
        cout << b << endl;
    }
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"io"
	"os"
)

func primeFactors(n uint64) (pfs map[uint64]uint64) {
	pfs = make(map[uint64]uint64)
	for n%2 == 0 {
		pfs[2]++
		n = n / 2
	}

	var i uint64
	for i = 3; i*i <= n; i = i + 2 {
		for n%i == 0 {
			pfs[i]++
			n = n / i
		}
	}

	if n > 2 {
		pfs[n]++
	}
	return
}

func pow(x uint64, y uint64) uint64 {
	//_, _ = fmt.Printf("pow: %v, %v\n", x,y)
	z := x
	if y == 0 {
		return 1
	}
	var i uint64
	for i =1;i<y;i++ {
		z = z * x
	}
	return z
}

func incIdx(idx *[]uint64, max *[]uint64) bool {
	for i:=0;i<len(*idx);i++ {
		if (*idx)[i] < (*max)[i] {
			(*idx)[i]++
			return true
		} else {
			(*idx)[i] = 0
		}
	}
	return false
}

func answer(reader io.Reader, writer io.Writer) {
	var n uint64
	_, _ = fmt.Fscan(reader, &n)
	var sum uint64
	pfs := primeFactors(n)
	//_, _ = fmt.Printf("%v, %v\n", pfs, len(pfs))
	numPf := len(pfs)
	idx := make([]uint64, len(pfs))
	max := make([]uint64, len(pfs))
	listPf := make([]uint64, len(pfs))
	c := 0
	for k, v := range pfs {
		listPf[c] = k
		max[c] = v
		c++
	}

	for {
		var pf uint64
		pf = 1
		for i:=0;i<numPf;i++{
			pf = pf * pow(listPf[i],idx[i])
		}
		//_, _ = fmt.Printf("pf: %v\n", pf)
		if pf > 2 {
			if n / pf < pf && n/(pf-1) == n%(pf-1) {
				sum += pf - 1
				//_, _ = fmt.Printf("m: %v, %v, %v\n", pf-1, n/(pf-1), n%(pf-1))
			}
		}
		if !incIdx(&idx, &max) {
			break
		}
	}
	//_, _ = fmt.Printf("%v\n", sum)
	_, _ = fmt.Fprintf(writer, "%v", sum)
}

func main() {
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

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


int main() {
	int n;
	cin >> n;
	double res = 0.0;
	rep(i, n) {
		double x;
		string u;
		cin >> x;
		cin >> u;
		if (u=="JPY") res += x;
		else res += 380000.0 * x;
	}
	cout << fixed << setprecision(5);
	cout << res << endl;
}

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

typedef long long ll;
int n,d[101];
ll dp[101][21];

int main(){
  cin >> n;
  for(int i = 0;i < n;i++) cin >> d[i];
  
  memset(dp,0,sizeof(dp)); dp[0][d[0]] = 1;
  for(int i = 1;i < n - 1;i++){
    for(int j = 0;j <= 20;j++){
      if(j + d[i] <= 20) dp[i][j + d[i]] += dp[i - 1][j];
      if(j - d[i] >= 0) dp[i][j - d[i]] += dp[i - 1][j];
    }
  }
  
  cout << dp[n-2][d[n-1]] << endl;
}

Measured memory_bytes: 1184
#include <iostream>
using namespace std;
int main()
{
 int a, b, c, d;
    std::cin >> a >> b >> c;
 
    if (a >= b) {
        d = a;
        a = b;
        b = d;
    }
 
    if (b >= c) {
        d = b;
        b = c;
        c = d;
    }
 
    if (a >= b) {
        d = a;
        a = b;
        b = d;
    }
 
    std::cout << a << " " << b << " " << c << std::endl;
    return 0;
}


Measured memory_bytes: 3068
N, M, C = gets.split.map(&:to_i)
B = Array.new(gets.split.map(&:to_i))
ans = 0
N.times do
  A = Array.new(gets.split.map(&:to_i))
  result = 0
  M.times do |i|
    result += A[i] * B[i]
  end
  ans += 1 if result + C > 0
end
puts ans


Measured memory_bytes: 1788
#include <stdio.h>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;


char S[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
                 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'};
int f(int n,int k)
{
    int kk=abs(k);
    return (n%k+kk)%kk;

}


int main()
{
    int n,k;
    string ans;
    while(cin>>n){
        k=-2;
        ans="";
        if(n==0){
            printf("0\n");
            continue;
        }
        while(n){
            int x=f(n,k);//n-x可以被k整除，且x最小
            ans+=S[x];
            n=(n-x)/k;
        }
        reverse(ans.begin(),ans.end());
        cout<<ans<<endl;
    }


}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

template <typename T, typename U>
vector<U> make_vector(T&& n, U&& val) {
  return vector<U>(forward<T>(n), forward<U>(val));
}
template <typename T, typename... Args>
decltype(auto) make_vector(T&& n, Args&&... args) {
  return vector<decltype(make_vector(forward<Args>(args)...))>(forward<T>(n), make_vector(forward<Args>(args)...));
}

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

void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  rep(i, n) s[i] -= '0';
  int cnt = 0;
  rep(i, n) cnt += s[i];
  if (cnt == 0) {
    rep(i, n) {
      cout << 1 << '\n';
    }
    return;
  }
  vi32 m(2);
  m[0] = cnt + 1;
  m[1] = cnt - 1;
  vector<vi32> mods(2, vi32(n + 1));
  rep(mi, 2) {
    int mod = m[mi];
    if (mod == 0) continue;
    int acc = 1;
    rrep(i, n) {
      int k = s[i];
      mods[mi][i] = (mods[mi][i + 1] + k * acc) % mod;
      acc = acc * 2 % mod;
    }
  }
  vi32 ans(n);
  int acc = 1;
  rrep(i, n) {
    int k = s[i];
    int mod = m[k];
    if (mod != 0) {
      int a = (mods[k][0] - mods[k][i] + mod) % mod;
      int b = (mods[k][i + 1] - mods[k][n] + mod) % mod;
      int x = (a + b + (1 - k) * acc) % mod;
      int y = __builtin_popcount(x);
      int c = 1;
      while (y) {
        c += 1;
        x %= y;
        y = __builtin_popcount(x);
      }
      ans[i] = c;
    }
    acc = acc * 2 % m[0];
  }
  rep(i, n) {
    cout << ans[i] << '\n';
  }
}


Measured memory_bytes: 5980
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

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

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.

	int N;
	int ans = 0;
	cin >> N;

	FOR(i, 0, 100) {
		if (pow(2, i) <= N)
			ans = pow(2, i);
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 384
M=10**9+7
q=->a,b{b<1?1:a**b[0]*q[a*a%M,b/2]}
f=->r,c{s=t=1
c.times{|i|t=t*-~i%M
s=s*(r+c-i)%M}
s*q[t,M-2]}
eval"A,B,C,D="+`tr \\  ,`
p (f[A,B]-f[C+=1,B]-f[A,D+=1]+f[C,D])%M

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

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

    int n = N;
    int sumN = 0;

    while (n > 0) {
        sumN += (n % 10);
        n /= 10;
    }

    if (N % sumN == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
def is_even(s):
    if len(s) % 2 == 1:
        return False
    mid = len(s) // 2
    if s[:mid] == s[mid:]:
        return True
    return False

def main():
    S = input().strip()
    S = S[:len(S)-2]
    while len(S) > 2:
        if is_even(S):
            break
        else:
            S = S[:len(S)-2]
    print(len(S))

if __name__ == "__main__":
    main()

Measured memory_bytes: 61784
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        a: i32,
        b: i32,
    }

    let ans = if a * b % 2 == 0 { "No" } else { "Yes" };

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
const int INF = 1e18;
signed main(){
	int n,k;cin >> n >> k;
	int ret = -INF;
	vector<int> p(n),c(n);
	rep(i,n){
		cin >> p[i];
		p[i]--;
	}
	rep(i,n)cin >> c[i];
	vector<vector<int>> travel(n,vector<int> ());
	rep(i,n){
		travel[i].push_back(i);
		while(1){
			int tmp = p[travel[i].back()];
			if(tmp == travel[i][0])break;
			travel[i].push_back(tmp);
		}
		int tmp = 0;
		rep(j,(int)travel[i].size())tmp+= c[travel[i][j]];
		if(k >= (int)travel[i].size()){
			int use = k/(int)travel[i].size();
			int rest = (k%(int)travel[i].size());
			tmp *= (use-1);
			rep(j,(int)travel[i].size()){
				tmp += c[travel[i][j]];
				ret = max(ret,tmp);
			}
			rep(j,rest){
				tmp += c[travel[i][j]];
				ret = max(ret,tmp);
			}
			ret = max(ret,tmp);
		}

		int score = 0;
		bool changed = false;
		rep(j,min((int)travel[i].size(),k)){
			score += c[travel[i][j]];
			changed = true;
			if(changed)ret = max(ret,score);
		}
		if(changed)ret = max(ret,score);
		
	}
	cout << ret << endl;


	
	
	return 0;
}

Measured memory_bytes: 218612
package main

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

var stdin = bufio.NewScanner(os.Stdin)

func main() {
	stdin.Split(bufio.ScanWords)
	var H, W int64
	var a int64
	H = nextInt64()
	W = nextInt64()

	if 2 <= H && 2 <= W {
		if H%2 == 0 && W%2 == 0 {
			a = H * W / 2
		} else if H%2 == 1 && W%2 == 1 {
			a = (H-1)*(W-1)/2 + (W-1)/2 + (H-1)/2 + 1
		} else if H%2 == 1 {
			a = (H-1)*W/2 + W/2
		} else if W%2 == 1 {
			a = H*(W-1)/2 + H/2
		}
	} else if H == 1 || W == 1 {
		a = 1
	}
	fmt.Println(a)
}

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

func nextInt64() int64 {
	stdin.Scan()
	i, err := strconv.ParseInt(stdin.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func nextStr() string {
	stdin.Scan()
	i := stdin.Text()
	// if err != nil {
	// 	panic(err)
	// }
	return i
}


Measured memory_bytes: 640
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<long long> D(N);
	vector<int> p(N);
	for (int i = 0; i < N; ++i) {
		cin >> D[i];
		p[i] = i;
	}
	sort(p.begin(), p.end(), [&](int i, int j) { return D[i] > D[j]; });
	vector<long long> ds = D;
	for (int i = 0; i < N; ++i) ds[i] *= -1;
	sort(ds.begin(), ds.end());
	vector<int> cnt(N, 1);
	bool ok = true;
	vector<pair<int, int> > edges;
	for (int i = 0; i < N - 1; ++i) {
		long long tar = -ds[i] - (N - 2 * cnt[p[i]]);
		int u = lower_bound(ds.begin(), ds.end(), -tar) - ds.begin();
		if (u == N || -ds[u] != tar) {
			ok = false;
			break;
		}
		cnt[p[u]] += cnt[p[i]];
		edges.push_back(make_pair(p[u], p[i]));
	}
	long long sum = 0;
	for (int i = 0; i < N; ++i) {
		if (i != p[N - 1]) {
			sum += cnt[i];
		}
	}
	if (sum != -ds[N - 1]) ok = false;
	if (!ok) {
		cout << -1 << endl;
	}
	else {
		for (pair<int, int> i : edges) {
			cout << i.first + 1 << ' ' << i.second + 1 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 4596
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cstdlib>
#include <utility>
#include <cmath>
#include <queue>
#include <stack>
#include <cstring>

using namespace std;

#define ll long long

#ifndef ONLINE_JUDGE
#define debug(format, ...) fprintf(stderr, \
    "%s:%d: " format "\n", __func__, __LINE__,##__VA_ARGS__)
#else
#define debug(format, ...)
#define NDEBUG
#endif

char s[100005];
int acnt, bcnt, ccnt;

int n;

bool check(const char* S)
{
    int n_acnt = 0, n_bcnt = 0, n_ccnt = 0;
    for (int i = 1; i <= n; i++) {
        char chr = S[(i - 1) % 3];
        if (chr == 'a') n_acnt++;
        if (chr == 'b') n_bcnt++;
        if (chr == 'c') n_ccnt++;
    }
    return n_acnt == acnt && n_bcnt == bcnt && n_ccnt == ccnt;
}

int main()
{
    scanf("%s", s + 1);
    n = strlen(s + 1);
    for (int i = 1; i <= n; i++) {
        if (s[i] == 'a') acnt++;
        else if (s[i] == 'b') bcnt++;
        else ccnt++;
    }
    if (check("abc") || check("acb") || check("bac") || check("bca")
        || check("cab") || check("cba")) {
            printf("YES");
        } else {
            printf("NO");
        }
    return 0;
}


Measured memory_bytes: 3236
class UnionFind:
    def __init__(self, N: int):
        self.parents = [-1] * N
        self.ranks = [-1] * N
        for i in range(N):
            self.ranks[i] = 0

    def find_root(self, x):
        if self.parents[x] < 0:
            return x
        else:
            # find the root of x and make a shortcut pass
            self.parents[x] = self.find_root(self.parents[x])
            return self.parents[x]

    def unite(self, x, y):
        x = self.find_root(x)
        size_x = -self.parents[x]
        y = self.find_root(y)
        size_y = -self.parents[y]
        if self.ranks[x] < self.ranks[y]:
            self.parents[x] = y  # merge the tree under x to y
            self.parents[y] = -(size_x + size_y)
        else:
            self.parents[y] = x  # merge the tree under y to x
            self.parents[x] = -(size_x + size_y)
            # Rank of x increments (Note that the rank of the root doesn't change otherwise)
            if self.ranks[x] == self.ranks[y]:
                self.ranks[x] += 1

    def same(self, x, y):
        return self.find_root(x) == self.find_root(y)

    def size(self, x):
        x = self.find_root(x)
        return -self.parents[x]


def get_input():
    N, M = (int(x) for x in input().split())
    rels = []
    for m in range(M):
        r = [int(x) - 1 for x in input().split()]  # adjust to 0-origin
        rels.append(r)
    return N, M, rels


N, M, rels = get_input()

# Map friends on a union-find tree
tree = UnionFind(N)
for r in rels:
    x = r[0]
    y = r[1]
    if not tree.same(x, y):
        tree.unite(x, y)
# print(tree.parents)

# Max number of groups is the size of the largest group
max_size = 0
for i in range(N):
    s = tree.size(i)
    if max_size < s:
        max_size = s
print(max_size)


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

using namespace std;

typedef unsigned long long ull;
typedef pair<int, int> P;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w, n;
    cin >> h >> w >> n;
    map<P, int> memo;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        for (int j = -2; j <= 0; j++) {
            for (int k = -2; k <= 0; k++) {
                int x = a + j;
                int y = b + k;
                if (x <= 0 || x > h - 2 || y <= 0 || y > w - 2) continue;
                P key = P(x, y);
                if (memo.find(key) == memo.end()) memo[key] = 1;
                else memo[key]++;
            }
        }
    }
    int ans[10] = {};
    for (auto i = memo.begin(), e = memo.end(); i != e; ++i) {
        ans[i->second]++;
    }
    ull sum = (ull)(h - 2) * (w - 2);
    for (int i = 1; i < 10; i++) sum -= ans[i];
    cout << sum << "\n";
    for (int i = 1; i < 10; i++) cout << ans[i] << "\n";
    return 0;
}

Measured memory_bytes: 56576