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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

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;

int main(){
  int x,y;cin>>x>>y;
  if(y%2==1){cout<<"No"<<endl;return 0;}
  y/=2;
  if(x<=y&&y<=(2*x))cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PP;
const int mod = 1000000007;

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

    int N;
    while (1)
    {
        cin >> N;
        if (N == 0)
            break;
        vector<int> a(N);
        rep(i, N)
        {
            string s;
            cin >> s;
            a[i] = s.size();
        }
        int tanku[] = {5, 7, 5, 7, 7};
        int ans = 0;
        rep(i, N)
        {
            int now = 0, pos = 0;
            Rep(j, i, N)
            {
                int nxt = a[j];
                if (now + nxt == tanku[pos])
                {
                    pos++, now = 0;
                    if (pos == 5 && ans == 0)
                    {
                        ans = i + 1;
                        break;
                    }
                }
                else if (now + nxt > tanku[pos])
                    break;
                else
                    now += nxt;
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3192
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c;
    cin >> a >> b >> c;
    cout << a*b/2;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <random>
#include <chrono>

using namespace std;

using ll = long long;
using ull = unsigned long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) { if (flg) { cout << hoge << endl; exit(0); } }
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) { o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o; }
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; }
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; }
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) { o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o; }
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) { o << "{" << obj.first << ", " << obj.second << "}"; return o; }
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; }
void print(void) { cout << endl; }
template <class Head> void print(Head&& head) { cout << head; print(); }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head << " "; print(forward<Tail>(tail)...); }
template <class T> void chmax(T& a, const T b) { a = max<T>(a, b); }
template <class T> void chmin(T& a, const T b) { a = min<T>(a, b); }
void YN(bool flg) { cout << ((flg) ? "YES" : "NO") << endl; }
void Yn(bool flg) { cout << ((flg) ? "Yes" : "No") << endl; }
void yn(bool flg) { cout << ((flg) ? "yes" : "no") << endl; }

int main() {
	int a, b, c, d; cin >> a >> b >> c >> d;
	a += b;
	a += c;
	a += d;
	cout << a / 60 << endl;
	cout << a % 60 << endl;
	return 0;
}



Measured memory_bytes: 3088
#include<cstdio>
using namespace std;

long long a,b,c,x,y;

long long max_ll(long long arg1,long long arg2)
{
	return arg1>arg2 ? arg1 : arg2;
}

long long min_ll(long long arg1,long long arg2)
{
	return arg1<arg2 ? arg1 : arg2;
}

long long f(long long cc)
{
	return 2*a*x+2*b*y+(2*c-a-b)*cc;
}

int main()
{
	scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&x,&y);
	printf("%lld\n",min_ll(min_ll(f(0),f(min_ll(2*x,2*y)))/2ll,2*c*max_ll(x,y)));
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define P pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007;
//最大公約数
int gcd(int s,int b){
    if(b==0)return s;
    return gcd(b,s%b);
}
signed main(){
    char s[4];
    cin>>s[0]>>s[1]>>s[2]>>s[3];
    sort(s,s+4);
    if(s[0]==s[1]&&s[2]==s[3]&&s[1]!=s[2]){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}


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

int main(){
    double a,b,c,C,S,L,h,pi;
    cin >> a >> b >> C;
    pi = acos(-1);
    S = 0.5*a*b*sin(C*pi/180);
    c = sqrt(pow(a,2) + pow(b,2) - 2*a*b*cos(C*pi/180));
    L = a + b + c;
    h = 2*S/a;
    
    cout << fixed << setprecision(15) << S << "\n" << L << "\n" << h << "\n";
    return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	vector<int> v(n);
	map<int,int> m;
	long long int sum=0;
	for(int i=0;i<n;i++){
		cin>>v[i];
		m[v[i]]++;
	}
	map<int,int>::iterator it;
	for(it=m.begin();it!=m.end();it++)
	{
		long long int  x=it->second;
		sum+=x*(x-1)/2;
	}
	for(int i=0;i<n;i++)
	{
		int w=m[v[i]];
		cout<<sum-w+1<<"\n";
	}
	return 0;
}


Measured memory_bytes: 8320
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> val(n);
  vector<int> diff(n);
  for (int i=0; i<n; i++){
    cin >> val.at(i);
  }
  for (int i=0;i < n; i++){
    int c;
    cin >> c;
    diff.at(i)=val.at(i)-c;
  }
  int sum=0;
  int ans=0;
  for (int j=0; j < (1 << n); j++){
    for (int k=0; k < n; k++){
      if (j & (1 << k)) sum+=diff.at(k);
    }
    if (ans < sum) ans=sum;
    sum=0;
  }
  cout << ans << endl;
  return 0;
}
    
  

Measured memory_bytes: 256
#include <iostream>
#include<math.h>
#include<iomanip>
 
using namespace std;
 
int main(){
    long n,k;cin>>n>>k;
    long num,l,val;
    int count=0;
    
    
    double ans=0.0,k1;
    for(long i=1;i<=n;i++)
    {
       count=0; 
    val=i;
    
    while(val<k)
    {
        
        val*=2;
        count++;
    }
    
    k1=n*(pow(2,count));
   
    
    
    ans+=(1/k1);
    }
    cout<<setprecision(12)<<(ans);
    
    

}

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

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

    string ans = "No";
    if(a == b and b != c){
        ans = "Yes";
    }
    if(b == c and c != a){
        ans = "Yes";
    }
    if(c == a and a != b){
        ans = "Yes";
    }


    cout << ans << endl;
}

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

using namespace std;

using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORE(i, a, b) for (int i = (a); i <= (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define all(v) (v).begin(), (v).end()
#define sp cout << fixed << setprecision(10)
typedef pair<int, int> P;
const int inf = (int)1e9;
const int mod = (int)1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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

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

    int sum = 0;
    if (a > b) {
        sum += a;
        a--;
    } else {
        sum += b;
        b--;
    }
    cout << sum + max(a, b) << endl;

    return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define ff first
#define ss second
#define rep(i,n,z) for(int i=z;i<n;i++)
#define rrep(i,z) for(int i=z;i>=0;i--)
#define fillv(a,k) memset(a,k,sizeof(a))

#define leadzero(a) __builtin_clz(a) //count leading zeros
#define trailzero(a) __builtin_ctz(a) //count trailing zeros
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln cout<<"\n"
#define sp cout<<" "

#define all(c) c.begin(),c.end()

typedef long long int ll;
typedef pair<ll,ll> p64;
typedef vector<ll> v64;
typedef vector<p64> vp64;
typedef vector<v64> vv64;
typedef map<ll,ll> m64;


typedef long double ld;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<string> vs;
typedef vector<int> v32;
typedef vector<v32> vv32;
typedef vector<p32> vp32;
typedef vector<vp32> vvp32;

const int LIM = 1e5+5, MOD = 1e9+7;

#define sumv(v) accumulate(all(v),ll(0))
#define productv(v) accumulate(all(v), ll(1), multiplies< ll >())

int main()
{
	fastio;
	string s, t;
	cin>>s>>t;
	s=" "+s;
	t=" "+t;
	ll sn = s.length();
	ll tn = t.length();
	ll dp[sn][tn];
	char d[sn][tn];	
	for(ll i =0;i<sn;i++)
		for(ll j=0;j<tn;j++) dp[i][j]=0;

	for(ll i=1;i<sn;i++)
	{
		for(ll j=1;j<tn;j++)
		{
			if(s[i]==t[j])
			{
				dp[i][j] = dp[i-1][j-1]+1;
				d[i][j] = 'd';
			}
			else
			{
				if(dp[i-1][j]>=dp[i][j-1])
				{
					dp[i][j] = dp[i-1][j];
					d[i][j] = 'u';
				}
				else
				{
					dp[i][j]=dp[i][j-1];
					d[i][j]='l';
				}
			}
			// cout<<d[i][j]<<dp[i][j]<<" ";
		}
		// ln;
	}

	ll i=sn-1;
	ll j=tn-1;
	string ans="";
	while(i>0&&j>0)
	{
		// cout<<i<<" "<<j<<" "<<d[i][j]<<endl;
		if(d[i][j]=='d') 
			{
				ans = s[i]+ans;
				i--;
				j--;
			}
		else if(d[i][j]=='u') i--;
		else j--;

	}
	cout<<ans<<endl;
}

Measured memory_bytes: 79488
#include <bits/stdc++.h>
using namespace std;
inline bool chmax (int& a, int b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
void dfs (
  int crr
, int prt
, int d
, vector<int>& dpt
, vector<vector<int>>& grh
) {
  dpt[crr] = d;
  for (int nxt : grh[crr]) if (nxt != prt) {
    dfs(nxt, crr, d + 1, dpt, grh);
  }
}
int main() {
  int n;
  cin >> n;
  vector<vector<int>> grh(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    grh[--a].push_back(--b);
    grh[b].push_back(a);
  }
  vector<int> dpt(n);
  dfs(0, 0, 0, dpt, grh);
  int mdt = 0;
  int rt = -1;
  for (int i = 0; i < n; i++) {
    if (chmax(mdt, dpt[i])) rt = i;
  }
  dfs(rt, rt, 0, dpt, grh);
  int mxv = 0;
  for (int i = 0; i < n; i++) {
    chmax(mxv, dpt[i]);
  }
  cout << (mxv % 3 == 1 ? "Second" : "First") << endl;
  return 0;
}

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

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

using namespace std;

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

vector<pair<char, int>> runLengthEncoding(string s) {
  vector<pair<char, int>> res;
  char cur = s.at(0);
  int cnt = 1;
  for (int i = 1; i < s.size(); i++) {
    if (cur == s.at(i)) {
      cnt++;
    } else {
      res.emplace_back(cur, cnt);
      cnt = 1;
      cur = s.at(i);
    }
    if (i == s.size() - 1) {
      res.emplace_back(cur, cnt);
    }
  }
  return res;
}

int main() {
  string s;
  cin >> s;
  auto lr = runLengthEncoding(s);
//  // デバッグ出力
//  rep(i, lr.size()) {
//    cout << "<";
//    cout << lr.at(i).first << ", " << lr.at(i).second;
//    cout << ">" << endl;
//  }
  rep(i, lr.size() / 2) {
    pair<char, int> r = lr.at(i * 2);
    pair<char, int> l = lr.at(i * 2 + 1);
    int ll = ceil((double) r.second / 2) + floor((double) l.second / 2);
    int rr = ceil((double) l.second / 2) + floor((double) r.second / 2);
    rep(j, r.second - 1) {
      cout << 0 << " ";
    }
    cout << ll << " ";
    cout << rr << " ";
    rep(j, l.second - 1) {
      cout << 0 << " ";
    }
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 1656
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <stdio.h>
#include <math.h>
#include <cstdlib>
#include <iostream>
#include <cstdlib>
using namespace std;
using ll = long long;
const int INF = 1e9 + 5;

void print_vector(vector<vector<ll> >v){
    for(ll i=0;i<v.size();i++){
        for(ll j=0;j< v[i].size();j++){
            cout<<v[i][j]<<" ";
        }cout<<"\n";
    }
}

int main(){
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='7'){
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";

    return 0;
}


Measured memory_bytes: 3632
N = int(input())
a = [str(input()) for i in range(N)]
cnt = 0
tBeA = 0
tBeNA = 0
tNBeA = 0
for i in range(N):
    flag = False
    if a[i][0] == "B":
        if a[i][-1] == "A":
            tBeA += 1
        else:
            tBeNA += 1
    else:
        if a[i][-1] == "A":
            tNBeA += 1

    for j in range(len(a[i])):
        # print(a[i][j])
        if a[i][j] == "B" and flag:
            cnt += 1
        flag = False

        if a[i][j] == "A":
            flag = True

print(
    cnt + min(tBeNA, tNBeA) if tBeA == 0 else cnt + min(tBeNA, tNBeA) + tBeA if tNBeA + tBeNA > 0 else cnt + min(tBeNA,
                                                                                                                 tNBeA) + tBeA - 1)


Measured memory_bytes: 3700
n = int(input())
a = list(map(int, input().split()))

ans = []
for i in range(n):
    c = 0
    while True:
        if a[i]%2 == 0:
            a[i] = a[i]/2
            c += 1
        else:
            ans.append(c)
            break
print(min(ans))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, T;
  cin >> N >> T;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  
  int64_t ans = 0;
  for(int i=0; i<N-1; i++){
    if(vec.at(i+1) - vec.at(i) <= T){
      ans += vec.at(i+1) - vec.at(i);
    }
    else{
      ans += T;
    }
  }
  ans += T;
  cout << ans << endl;
}

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

int main(){
    int A1,A2,A3;
    cin>>A1>>A2>>A3;
    if(22<=A1+A2+A3)cout<<"bust"<<endl;
    else cout<<"win"<<endl;
}

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

int main() {
  int n, l;
  cin >> n >> l;
  vector<string> iroha(n);
  for(int i = 0; i < n; i++){
    cin >> iroha.at(i);
  }
  
  sort(iroha.begin(), iroha.end());
  string ans = iroha.at(0);
  
  for(int i = 1; i < n; i++){
    ans += iroha.at(i);
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <numeric>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second

#define INF 2147483600
#define long long long

int solve(long x, long y){
  if(y==0) {
    if(x>0) return x+1;
    else return -x;
  }
  if(x==0){
    if(y>=0) return y;
    else return -y+1;
  }
  if(x*y >= 0){
    if(y>=x) return y-x;
    else return x-y + 2;
  } else {
    return min(solve(-x,y), solve(x,-y))+1;
  }
}

int main(){
  int x,y;
  cin>>x>>y;

  cout << solve(x,y) << endl;

  return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc164/tasks/abc164_d

import sys
input = sys.stdin.readline


S = input().rstrip()

res = 0

x = 0
p = 1
L = len(S)
MOD = 2019
reminder = [0]*2019
reminder[0] = 1
for s in reversed(S):
    """ 累積和 """
    x = (int(s)*p + x)%MOD
    p = p*10%MOD
    res += reminder[x]
    reminder[x] += 1

print(res)

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

const int MAX_V = 50;
const int MAX_S = MAX_V*50+5;
const ll INF = 1e18;

struct Edge {
  int to, a, b;
  Edge(int to, int a, int b):to(to),a(a),b(b) {}
};

struct Data {
  int v, s;
  ll x;
  Data(int v, int s, ll x):v(v),s(s),x(x) {}
  bool operator<(const Data& a) const {
    return x > a.x;
  }
};

vector<Edge> g[MAX_V];
ll dist[MAX_V][MAX_S+5];

int main() {
  int n, m, s;
  cin >> n >> m >> s;
  rep(i,m) {
    int u,v,a,b;
    cin >> u >> v >> a >> b;
    --u; --v;
    g[u].emplace_back(v,a,b);
    g[v].emplace_back(u,a,b);
  }
  rep(i,n)rep(j,MAX_S+5) dist[i][j] = INF;
  s = min(s, MAX_S);
  priority_queue<Data> q;
  auto push = [&](int v, int s, ll x) {
    if (s < 0) return;
    if (dist[v][s] <= x) return;
    dist[v][s] = x;
    q.emplace(v,s,x);
  };
  vector<int> c(n), d(n);
  rep(i,n) cin >> c[i] >> d[i];
  push(0,s,0);
  while (!q.empty()) {
    Data hoge = q.top(); q.pop();
    int v = hoge.v, s = hoge.s;
    ll x = hoge.x;
    //if (dist[v][s] != x) continue;
    {
      int ns = min(s+c[v], MAX_S);
      push(v,ns,x+d[v]);
    }
    for (Edge e : g[v]) {
      push(e.to, s-e.a, x+e.b);
    }
  }
  for (int i = 1; i < n; ++i) {
    ll ans = INF;
    rep(j,MAX_S+5) {
      ans = min(ans, dist[i][j]);
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 6224
module Main where

import Data.Functor

main :: IO ()
main =  do
  { str <- getLine
  ; [q] <- getInts
  ; loop q str
  }

loop :: Int -> String -> IO ()
loop 0 _ = done
loop m s = do
  { cmd <- getWords
  ; case cmd of
      ["print",a,b]     -> prn (read a) (read b) s >>  loop (m-1) s
      ["reverse",a,b]   -> rev (read a) (read b) s >>= loop (m-1)
      ["replace",a,b,p] -> rep (read a) (read b) p s >>= loop (m-1)
  }

prn :: Int -> Int -> String -> IO ()
prn a b s = case splitAt a s of
  (_,ys) -> putStrLn (take (b-a+1) ys)

rev :: Int -> Int -> String -> IO String
rev a b s = case splitAt a s of
  (xs,ys) -> case splitAt (b-a+1) ys of
    (zs,ws)  -> return (xs ++ reverse zs ++ ws)

rep :: Int -> Int -> String -> String -> IO String
rep a b t s = case splitAt a s of
  (xs,_) -> case splitAt (b+1) s of
    (_,ys) -> return (xs ++ t ++ ys)

done :: IO ()
done = return ()

getInts :: IO [Int]
getInts = map read . words <$> getLine

getWords :: IO [String]
getWords = words <$> getLine

Measured memory_bytes: 5080
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,c=0;
cin>>n>>m;
double a[n],sum=0;
for(int i=0;i<n;i++)
{cin>>a[i];
sum+=a[i];
}
for(int i=0;i<n;i++)
{
    if(a[i]>=(sum/(4*m)))
    {
        c++;
        if(c>=m)
        {

            cout<<"Yes";
            return 0;
        }

    }



}

cout<<"No";
  }



Measured memory_bytes: 256
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>
#include<map>
#include<set>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;

ll MOD = 1000000007;




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

	std::map<double,int> mp;

	for (int i = 0; i < N; ++i)
	{
		int A; cin >> A;
		mp[A]++;
	}

	for (int i = 0; i < M; ++i)
	{
		double A = mp.rbegin()->first;
		mp[A]--;
		mp[A / 2]++;
		if (mp[A] == 0)
		{
			mp.erase(A);
		}
	}

	ll ans = 0;
	for (auto & itr : mp)
	{
		ans += ((ll)itr.first)*itr.second;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 6528
/*input

*/
#include <iostream>
#include <fstream>
#include <bitset>
#include <vector>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <utility>
#include <ctime>
#include <algorithm>
#include <iomanip>
#include <assert.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define endl '\n'
#define mp make_pair
#define pb push_back
#define MOD 1000000007ULL
#define MOD2 1000000009ULL
#define INF 1000000000ULL
#define F first
#define S second
#define eps 1e-9
#define PI 3.14159265358979
#define gcd __gcd
#define sd(x) scanf("%d", &(x))
#define slld(x) scanf("%lld", &(x))
#define ss(x) scanf("%s", x)
#define sc(x) scanf(" %c", &x)
#define pd(x) printf("%d\n", (x))
#define plld(x) printf("%lld\n", (x));
#define gc getchar

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<int, int> vii;
typedef vector<ll, ll> vll;

void scanint(int &x)
{
    register int c = gc();
    bool flag = false;
    x = 0;
    for(;((c<48 && c!=45) || c>57);c = gc());
    if(c==45)
    {
		flag = true;
		c = gc();
    }
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(flag)
    	x = x - (x<<1);
    return;
}

void scanll(ll &x)
{
	register long long c;
	bool flag = false;
	x = 0;
	for(;((c<48 && c!=45) || c>57);c = gc());
	if(c==45)
	{
		flag = true;
		c = gc();
	}
	for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
	if(flag)
    	x = x - (x<<1);
	return;
}

void solve(int l, string sl, int r, string sr)
{
	int mid = (l+r)>>1;
	string s;
	cout << mid << "\n";
	fflush(stdout);
	cin >> s;

	if(s == "Vacant")
	{
		return;
	}

	if(sl == s && (mid-l)%2 == 0)
		solve(mid, s, r, sr);
	else if(sl == s && (mid-l)%2 == 1)
		solve(l, sl, mid, s);
	else if(sl != s && (mid-l)%2 == 1)
		solve(mid, s, r, sr);
	else if(sl != s && (mid-l)%2 == 0)
		solve(l, sl, mid, s);

	return;
}

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

	// clock_t clk;
	// clk = clock();
	// freopen("in.in", "r", stdin);
	// freopen("out.out", "w", stdout);
	
	int n;
	cin >> n;
	int l = 0, r = n/2;
	string sl, sr;
	cout << l << "\n";
	fflush(stdout);
	cin >> sl;

	if(sl == "Vacant")
		return 0;

	cout << r << "\n";
	fflush(stdout);
	cin >> sr;

	if(sr == "Vacant")
		return 0;

	if(sl == sr && (r-l)%2 == 0)
		solve(r, sr, n, sl);
	else if(sl == sr && (r-l)%2 == 1)
		solve(l, sl, r, sr);
	else if(sl != sr && (r-l)%2 == 1)
		solve(r, sr, n, sl);
	else if(sl != sr && (r-l)%2 == 0)
		solve(l, sl, r, sr);

	// clk = clock() - clk;
	// cout << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	// printf("Time: %lf", ((double)clk)/CLOCKS_PER_SEC);
	return 0;
}

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

int n,ans,now;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n,n){
        ans=0,now=0;
        for (int i=0;i<n;++i){
            string next; cin >> next;
            if (next[0]=='l') now^=1;
            if (next[0]=='r') now^=2;
            if (now==3) ++ans,now=0;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3136
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <stack>
#include <queue>
#include <cmath>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define llrep(i,j,k) for(long long int i=j;i<(long long int)k;i++)
#define sort(x) sort(x.begin(),x.end()); 
#define vi vector<int>
#define vvi vector<vector<int>> 
#define lli long long int

const int INF = 100000000;

using namespace std;

void p(int x) {
	cout << x << endl;
}

void pp(string s) {
	cout << s << endl;
}



int main() {
	int w, h,k;
	cin >> w >> h >> k;

	vvi v(w, vi(h,1));

	rep(i, 0, k) {
		int x, y, a;
		cin >> x >> y >> a;
		if (a == 1) {
			rep(j, 0, x) {
				rep(k, 0, h) v[j][k] = 0;
			}
		}
		else if (a == 2) {
			rep(j, x, w) {
				rep(k, 0, h) v[j][k] = 0;
			}
		}
		else if (a == 3) {
			rep(j, 0, w) {
				rep(k, 0, y) v[j][k] = 0;
			}
		}
		else if (a == 4) {
			rep(j, 0, w) {
				rep(k, y, h) v[j][k] = 0;
			}
		}

		
	}

	int count = 0;
	rep(i, 0, w) {
		rep(j, 0, h) {
			if (v[i][j] == 1) count++;
		}
	}
	p(count);

	





	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int INF=-1e9;
vector<vector<int>>adj(100010,vector<int>{});
vector<bool>vis(100010,false);
vector<int>indegree(100010,1);
vector<int>dis(100010,INF);
void dfs(int a){
vis[a]=true;
for(auto x:adj[a]){
dis[x]=max(dis[a]+1,dis[x]);
indegree[x]--;
if(!vis[x] && indegree[x]==0)
dfs(x);
}

}
int main(){
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;

    for(int i=0;i<m;i++){
int a,b;
cin>>a>>b;
a-=1;
b-=1;
adj[a].push_back(b);
indegree[b]+=1;
    }
dis[n]=0;
for(int i=0;i<n;i++){
adj[n].push_back(i);
}

indegree[n]=0;
dfs(n);

for(int i=0;i<n;i++){
if(vis[i])
continue;
dfs(i);}
int ans=-1e9;
for(int i=0;i<=n;i++){
ans=max(ans,dis[i]);
}
cout<<(ans-1);
    return 0;}


Measured memory_bytes: 11836
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::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...);
}
#else
#define trace(...)
#endif

#define lsc(x)      scanf("%lld",&x)
#define sc(x)       scanf("%d",&x)
#define lpr(x)      printf("%lld ",(long long)x)
#define pr(x)       printf("%d ",x)
#define n_l         printf("\n")
#define VI          vector<int>
#define VII         vector<long long int>
#define m_p         make_pair
#define pb          push_back
#define fi           first
#define se           second
#define mset(x,y)   memset(x,y,sizeof(x))
#define sz(v)       (int)v.size()
#define all(v)      v.begin(), v.end()
#define fr(i, a, n) for(int i=a;i<=n;i++)
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
const int N=(int)1e6+5;
const int mod = 1000000007;
typedef long long ll;
// order_of_key (val): returns the no. of values strictly less than val
// find_by_order (k): returns the kth largest element iterator.(0-based)
// vector<int>::iterator itr=lower_bound(v.begin(),v.end(),x);
// s.substr(pos[0-indexed], len(default=till end))
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

ll fmod(ll x){if (x<mod) return x;return x%mod;}
ll mul(ll a, ll b, ll c){
	ll ret=0;while(b){if (b%2) ret=(ret+a)%c;a=(a*2)%c;b>>=1;}
    return ret;
}
int modpow(ll a, ll b){
    ll ret=1;while(b){if (b%2) ret=(ret*a)%mod;a=(a*a)%mod;b>>=1;}
    return (int)ret;
}
inline int inv(int x){ return modpow(x, mod-2);}
int isprime[N];
void calc_prime(){
	isprime[1]=1;for(ll i=2;i<N;i++) if (!isprime[i]) for(ll j=i*i;j<N;j+=i) isprime[j]=1;
}
int main(){
    int x;sc(x);
    int n;sc(n);
    set<int> s;
    fr(i, -100, 200) s.insert(i);
    fr(i, 1, n){
        int p;sc(p);
        if (s.find(p)!=s.end()){
            s.erase(p);
        }
    }
    int ans = 0;
    int diff = mod;
    for(auto u: s){
        int tmp = abs(u-x);
        if (tmp < diff){
            diff = tmp;
            ans = u;
        }
    }
    pr(ans);n_l;
    return 0;
}



Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
 
int solve(vector<int> v, vector<int> P)
{
    int ret = 0;
    while (v != P)
    {
        next_permutation(v.begin(), v.end());
        ret++;
    }
    return ret;
}
 
int main()
{
    int N;
    cin >> N;
    vector<int> P(N), Q(N);
    for (int i = 0; i < N; i++) cin >> P[i];
    for (int i = 0; i < N; i++) cin >> Q[i];
    vector<int> v(N);
    for (int i = 0; i < N; i++) v[i] = i + 1;
    cout << abs(solve(v, P) - solve(v, Q)) << endl;
}

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

int main() {
  long long a,b,c,d;
  cin >> a>>b>>c>>d;
  long long A=a*c;
  long long B=a*d;
  long long C=b*d;
  long long D=b*c;
  long long ANS=max(A,B);
  long long ans=max(C,D);
  cout<<max(ANS,ans)<<endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  vector<int> s = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;
  cin >> K;
  
  cout << s.at(K-1) << endl;
}


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

int main(){
    int X;
    cin >> X;
    int high = ceil(sqrt(X));

    int max_val = 0;
    for(int i=high; i>0; i--){
        if(i==1){
            max_val = (max_val < 1)? 1:max_val;
        }
        int max_p = (int)round(log(X)/log(i));
        for(int j=max_p; j>=2; j--){
            int val = (int)round(pow(i, j));
            if(val <= X && max_val < val){
                max_val = val;
            }
        }
    }
    cout << max_val << endl;
    return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
#define pb push_back
vector<pair<ll,ll>>check_list,ncheck_list;
ll sx,sy,gx,gy,h,w;
string s[(ll)1e3+5];
vector<vector<ll>>d((ll)1e3+5,vector<ll>(1e3+5,-1));
ll dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
void dfs(ll x,ll y,ll cnt){
    if(y<0||x<0||x>=h||y>=w)return;
    if(s[x][y]=='#')return;
    if(d[x][y]!=-1)return;
    d[x][y]=cnt;
    check_list.pb({x,y});
    rep(0,i,4){
        ll nx=x+dx[i],ny=y+dy[i];
        dfs(nx,ny,cnt);
    }
}
void dfs2(ll x,ll y,ll cnt){
    rep(-2,i,3){
        rep(-2,j,3){
            ll nx=x+i,ny=y+j;
            dfs(nx,ny,cnt);
        }
    }
}
int main(void){
    cin>>h>>w;
    cin>>sx>>sy;
    --sx,--sy;
    cin>>gx>>gy;
    --gx,--gy;
    rep(0,i,h)cin>>s[i];
    ll cnt=0;
    dfs(sx,sy,cnt);
    while(check_list.size()){
        cnt++;
        ncheck_list.clear();
        for(auto p:check_list){
            ncheck_list.pb(p);
        }
        check_list.clear();
        for(auto p:ncheck_list){
            ll x=p.first,y=p.second;
            dfs2(x,y,cnt);
        }
    }
    cout<<d[gx][gy];
}


Measured memory_bytes: 13504
# coding: utf-8
# Your code here!
#パクリゆるして
#グラフのようななにか

import sys
input=sys.stdin.readline
sys.setrecursionlimit(1000000)

from collections import deque


N,Q=map(int,input().split())

tree=[[]*(N+1) for i in range(N+1)]
point=[0]*(N+1)

for _ in range(N-1):
    a,b=map(int,input().split())
    tree[a].append(b)
    tree[b].append(a)
    
for _ in range(Q):
    p,x=map(int,input().split())
    point[p]+=x
#print(point)

d=deque([[1,0]])

while d:
    node,parent=d.popleft()
    point[node]+=point[parent]
    lis=tree[node]
    for child in lis:
        if child==parent:
            continue
        d.append([child,node])
    #print(d)

print(*point[1:])


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

int main() {
    long long inf  = 1e9+7;
  int N;
  cin >> N;
  vector<long long int> A(N);
  long long int sumA = 0;
  for (int i=0; i < N; i++) {
    cin >> A[i];
    A[i] = A[i] % inf;
    sumA = sumA + A[i];
    sumA = sumA % inf;
  }
  long long int sumanijo = 0;
  sumanijo = sumA * sumA % inf;
  long long int nijosum = 0;
  for (int i=0; i < N; i++) {
    nijosum = nijosum + A[i] * A[i] % inf;
    nijosum = nijosum % inf;
  }
  long long int sum = 0;
  long long int sa = 0;
  sa = sumanijo - nijosum;
  while (true){
    if(sa < 0) {
      sa = sa + inf;
    } else {
      break;
    }
  }
  sum = sa % inf;
  if (sum % 2 == 1){
    sum = (sum + inf)/2;
  } else{
    sum = sum/2;
  }
  cout << sum << endl;
}

Measured memory_bytes: 4816
# 各竹に対して使わない,A,B,Cに使う(0123)を割り当てて,合成してから延長短縮する
N,A,B,C=map(int,input().split())
L=[int(input()) for i in range(N)]

def bf(m):
    ret=[]
    while m!=0:
        ret.append(m%4)
        m=m//4
    return ret+[0]*(N-len(ret))

ans=10000
comp=[A,B,C]
for i in range(4**N): # 4進数で列挙
    ch=[0,0,0] # 2本以上あるかchecker
    tmp=[0,0,0] # 合成MPの保存場所
    tgt=[A,B,C] # 合成して作った竹との差を保存
    for j,l in zip(bf(i),L): # はじめに全て合成する
        if j==0: # 0なら使わない
            continue
        else:
            tgt[j-1]-=l # 目標値から引く
            if ch[j-1]: # 2本以上なら
                tmp[j-1]+=10 # 合成MP
            else:
                ch[j-1]+=1 # 初めて
    flag=True # 竹が作れない場合も含まれていて、そのための旗
    for l,com in zip(tgt,comp):
        if l==com: # 変わってない -> 何もひかれてないので竹は作れない
            flag=False
            break
    if flag:
        ans=min(ans,sum(abs(x) for x in tgt)+sum(tmp)) # xが目標値より大きいこともありうる
print(ans)

Measured memory_bytes: 3064
//What is love?

#include <iostream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

#define FOR(i,n,m) for(int i=n; i<m; i++)
#define ROF(i,n,m) for(int i=n; i>m; i--)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define ri(a) scanf("%d",&a)
#define rii(a,b) scanf("%d %d",&a,&b)
#define riii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define lri(a) scanf("%lld",&a)
#define lrii(a,b) scanf("%lld %lld",&a,&b)
#define ms(obj,val) memset(obj,val,sizeof(obj))
#define debug true
#define dprintf debug && printf

const int INF = 0x3f3f3f3f;
const ll INFLL = 1e18;
const int MOD = 1e9+7;
const int MAXN = 2e5+5;

//Baby don't hurt me

ll gcd(ll a, ll b){
    while(b) b^=a^=b^=a%=b;
    return a;
}

ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}

int n, m;
char s[MAXN], t[MAXN];


//Don't hurt me

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

    rii(n,m);
    scanf("%s",s); scanf("%s",t);
    ll ans = lcm(n,m);
    int i = 0, j = 0;
    ll x = ans/m, y = ans/n;
    while(i < n && j < m){
        if(s[i] != t[j]) {printf("-1\n"); return 0;}
        i += x;
        j += y;
    }
    printf("%lld\n",ans);

    return 0;
}
//No more


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

struct guide {
    int id;
    string name;
    int point;
};

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

    int N, X;
    cin >> N >> X;

    int count = 1;
    int D = 0;
    for (int i = 0; i < N; ++i) {
        int L;
        cin >> L;
        D += L;
        if (D > X) {
            break;
        }
        count++; 
    }

    cout << count  << '\n';

    return 0;
}


Measured memory_bytes: 256
a,x,nn,b,c,nnn,nnnn=map(int,input().split())
ans=x+a//2*2+b//2*2+c//2*2
if a*b*c:
  j=a%2+b%2+c%2
  if j==2:
    ans+=1
  if j==3:
    ans+=3
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	string s,t;
	cin>>s>>t;
	
	s.push_back(t[t.size()-1]);
	
	cout<<(s==t?"Yes":"No")<<endl;
}

Measured memory_bytes: 3620
io = STDIN
n,k=io.gets.split.map(&:to_i)
R,S,P=io.gets.split.map(&:to_i)
t=io.gets.chomp.split(//)
score={
  "r"=>R,
  "s"=>S,
  "p"=>P,
  "e"=>0
}
w={
  "r"=>"p",
  "s"=>"r",
  "p"=>"s",
}
win=t.map{|ch|w[ch]}
(k...n).each do |i|
  win[i]='e' if win[i-k]==win[i]
end
puts win.map{|ch|score[ch]}.inject(:+)


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

int main(){
  ll n;
  cin>>n;
  vector<string> v(n);
  rep(i,n){
    cin>>v.at(i);
  }
  rep(i,n){
    sort(v.at(i).begin(),v.at(i).end());
  }
  sort(v.begin(),v.end());
  v.push_back("a");
  ll sum=1,i=0,ans=0;
  while (i<n){
    if (v.at(i) == v.at(i+1)){
      sum++;
      i++;
    }
    else{
      ans += sum*(sum-1)/2;
      sum=1;
      i++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 8064
// こんな難しい書き方しなくても、文字列参照の添字の工夫で溶けた。

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

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

	if(N == 1) {
		cout << "Hello World" << endl;
	} else {
		int A, B;
		cin >> A >> B;
		cout << A + B << endl;
	}
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
li = [0, 0, 0, 0, 0, 0, 0, 0, 0]
for i in range(n):
    if 1 <= a[i] <= 399:
        li[0] += 1
    elif 400 <= a[i] <= 799:
        li[1] += 1
    elif 800 <= a[i] <= 1199:
        li[2] += 1
    elif 1200 <= a[i] <= 1599:
        li[3] += 1
    elif 1600 <= a[i] <= 1999:
        li[4] += 1
    elif 2000 <= a[i] <= 2399:
        li[5] += 1
    elif 2400 <= a[i] <= 2799:
        li[6] += 1
    elif 2800 <= a[i] <= 3199:
        li[7] += 1
    else:
        li[8] += 1
if li[8] == 0:
    print(str(9 - li.count(0)) + " " + str(9 - li.count(0)))
elif 8 - li.count(0) == 0:
    print(str(9 - li.count(0))+" "+str(8 - li.count(0)+li[8]))
else:
    print(str(8 - li.count(0))+" "+str(8 - li.count(0)+li[8]))

Measured memory_bytes: 3064
import math


def main():
    N, K = map(int, input().split())
    print((max(0, N - K + 1) + sum((
        max(0, N - (math.ceil(K * (1 / 2) ** i)) + 1)
        - max(0, N - (math.ceil(K * (1 / 2) ** (i - 1))) + 1)) * (1 / 2) ** i
        for i in range(1, int(math.log2(K)) + 1 + 1))) / N)
    return


main()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define R register
#define mp make_pair
#define ll long long
#define pii pair<int, int>
using namespace std;
const int N = 110000, M = N << 2, inf = 1e9;

int n, m, d[N], nxt[M], to[M], noedg = 1, hd[N], val[M], tag[N];
priority_queue<pii> que;
char s[N];

struct DSU {
//
int fa[M];

inline void init() {
    for (R int i = 1; i <= n * 2; ++i) fa[i] = i;
    return;
}

int find(int x) {
    return fa[x] == x ? x : fa[x] = find(fa[x]);
}

inline void unite(int x, int y) {
    fa[find(x)] = find(y);
    return;
}
//
} dsu;

inline void addEdg(int x, int y) {
    nxt[++noedg] = hd[x], hd[x] = noedg, to[noedg] = y;
    nxt[++noedg] = hd[y], hd[y] = noedg, to[noedg] = x;
    return;
}

template <class T>
inline void read(T &x) {
    x = 0;
    char ch = getchar(), w = 0;
    while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    x = w ? -x : x;
    return;
}

inline char rev(char ch) {
    return ch == 'B' ? 'W' : 'B';
}

int main() {
    int x, y;
    read(n), read(m);
    for (R int i = 1; i <= n; ++i) read(d[i]), que.push(mp(d[i], i));
    for (R int i = 1; i <= m; ++i) read(x), read(y), addEdg(x, y);
    dsu.init();
    while (que.size()) {
        int now = que.top().second, pos = now; 
        que.pop();
        if (tag[now]) {
            for (R int i = hd[now]; i; i = nxt[i])
                if (!val[i >> 1]) val[i >> 1] = inf;
            continue;
        }
        for (R int i = hd[now], v; i; i = nxt[i])
            v = to[i], pos = d[v] <= d[pos] ? v : pos;
        if (pos == now) return printf("-1\n"), 0;
        if (d[pos] < d[now]) {
            dsu.unite(pos, now), dsu.unite(pos + n, now + n);
            for (R int i = hd[now], v; i; i = nxt[i]) {
                if ((v = to[i]) == pos)
                    val[i >> 1] = d[now] - d[v];
                else if (!val[i >> 1])
                    val[i >> 1] = inf;
            }
        }
        else {
            dsu.unite(pos + n, now), dsu.unite(pos, now + n);
            tag[pos] = 1;
            for (R int i = hd[now], v; i; i = nxt[i]) {
                if ((v = to[i]) == pos)
                    val[i >> 1] = d[now];
                else if (!val[i >> 1])
                    val[i >> 1] = inf;
            }
        }
    }
    for (R int i = 1; i <= n; ++i) {
        if (s[i]) continue;
        int k = dsu.find(i);
        if (k > n) {
            if (!s[k - n]) s[k - n] = 'W';
            s[i] = rev(s[k - n]);
        }
        else {
            if (!s[k]) s[k] = 'W';
            s[i] = s[k];
        }
    }
    printf("%s\n", s + 1);
    for (R int i = 1; i <= m; ++i) printf("%d\n", val[i]);
    return 0;
}

Measured memory_bytes: 10612
import math

def isPrime(n):
    if n == 2 or n == 3:
        return True
    if n%2 == 0:
        return False
    for i in range(3, int(math.sqrt(n))+1, 2):
        if n%i == 0:
            return False
    return True

X = int(input())
while True:
    if isPrime(X):
        print(X)
        break
    else:
        X += 1

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define  rep(i,a,b) for(i=a;i<b;i++)
#define endl "\n"
#define ll long long int
#define ld long double
using namespace std;
int main()
{
IOS;
ll n,i;
cin>>n;
ld a[n],sum=0;;
rep(i,0,n)
cin>>a[i];
rep(i,0,n)
    sum=sum+1/a[i];
    cout<<setprecision(15)<<fixed<<1/sum;
return 0;
}



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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintStream out = new PrintStream(System.out);

        int N, K, ans;

        N = sc.nextInt();
        K = sc.nextInt();

        ans = K;
        for(int i = 1; i < N; i++) {
            ans *= K-1;
        }

        out.println(ans);
        sc.close();
    }
}

Measured memory_bytes: 21844
#include<stdio.h>
#include<string.h>
int min(int a, int b)
{
    if (a < b)
        return a;
    else
        return b;
}
int main()
{
    int n;
    scanf("%d", &n);
    int i, j;
    char s[55][55];
    for (i = 0; i < n; i++)
        scanf("%s", s[i]);
    int c[30];
    for (i = 0; i < 30; i++)
        c[i] = 100;
    int p[30];
    for (i = 0; i < n; i++)
    {
        for (j = 0; j < 30; j++)
            p[j] = 0;
        for (j = 0; j < strlen(s[i]); j++)
            p[(int)(s[i][j] - 'a')]++;
        for (j = 0; j < 30; j++)
            c[j] = min(c[j], p[j]);
    }
    for (i = 0; i < 30; i++)
        if (c[i] > 0)
            for (j = 0; j < c[i]; j++)
                printf("%c", 'a' + i);
    printf("\n");
    return 0;
}

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

int main(){
    int n;
    while(cin>>n){
        int i,y,z=0,k=1;
        for(i=1; i<=n; ++i){
            int a,b,c,x=0;
            a=i;

            while(b!=0){
                b=a/2;

                if(a%2==0){
                    ++x;
                }

                a=b;
            }
            if(x>z){
                k=i;
                z=x;
            }
            b=1;
        }
        printf("%d\n",k);
    }
return 0;
}





Measured memory_bytes: 384
#include <iostream>
#include <bitset>
#include <string>
#include <vector>
using namespace std;

int main() {
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    
    if( ((a == b) && !(a==c)) || ((a == c) && !(b==c)) || ((c == b) && !(a==c))){
    printf("Yes");
    }
    else{
    printf("No");
    }
    
}

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

int n;

int main() {
	scanf("%d", &n);
	if (n & 1) {
		if (n == 3) {
			printf("%d\n", 2);
			printf("%d %d\n", 1, 3);
			printf("%d %d\n", 2, 3);
		} else {
			printf("%d\n", 2 * (n - 1));
			printf("%d %d\n", n, 1);
			printf("%d %d\n", n, n - 1);
			for (int i = 1; i <= (n - 1) / 2 - 1; ++i) {
				printf("%d %d\n", i, i + 1);
				printf("%d %d\n", i, n - 1 - i);
				printf("%d %d\n", n - i, i + 1);
				printf("%d %d\n", n - i, n - 1 - i);
			}
			printf("%d %d\n", n, (n - 1) / 2);
			printf("%d %d\n", n, n - ((n - 1) / 2));
		}
	} else {
		if (n == 4) {
			printf("%d\n", 4);
			printf("%d %d\n", 1, 2);
			printf("%d %d\n", 1, 3);
			printf("%d %d\n", 4, 2);
			printf("%d %d\n", 4, 3);
		} else {
			printf("%d\n", 2 * n);
			for (int i = 1; i <= n / 2 - 1; ++i) {
				printf("%d %d\n", i, i + 1);
				printf("%d %d\n", i, n - i);
				printf("%d %d\n", n - i + 1, i + 1);
				printf("%d %d\n", n - i + 1, n - i);
			}
			printf("%d %d\n", n / 2, 1);
			printf("%d %d\n", n / 2, n);
			printf("%d %d\n", n - (n / 2 - 1), 1);
			printf("%d %d\n", n - (n / 2 - 1), n);
		}
	}
	return 0;
}	

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = (ll)1e9 + 7;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n, w; cin >> n >> w;
  vll wv(n), vv(n);
  REP(i, n) cin >> wv.at(i) >> vv.at(i);
  vvll dp(n+1, vll(w+1, 0));
  REP(i, n) {
    REP(j, w+1) {
      if (j >= wv.at(i)) chmax(dp.at(i+1).at(j), dp.at(i).at(j-wv.at(i)) + vv.at(i));
      chmax(dp.at(i+1).at(j), dp.at(i).at(j));
    }
  }
  cout << dp.at(n).at(w) << endl;
  return 0;
}


Measured memory_bytes: 80256
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return input()
path=[]
c=[0,0,0,0]
used=[False for i in range(4)]
for i in range(3):
    a,b=IL()
    c[a-1]+=1
    c[b-1]+=1
    path.append([a-1,b-1])
c.sort()
if c==[1,1,2,2]:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064