akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(void){
    double w;
    while(scanf("%lf",&w)!=EOF){
        if(w<=48 || w>91){
            if(w<=48){
                printf("light fly\n");
            }else{
                printf("heavy\n");
            }
        }else if(w>48 && w<=57){
            if(w<=51){
                printf("fly\n");
            }else if(w>54){
                printf("feather\n");
            }else{
                printf("bantam\n");
            }
        }else if(w>57 && w<=69){
            if(w<=60){
                printf("light\n");
            }else if(w>64){
                printf("welter\n");
            }else{
                printf("light welter\n");
            }
        }else{
            if(w<=75){
                printf("light middle\n");
            }else if(w>81){
                printf("light heavy\n");
            }else{
                printf("middle\n");
            }
        }
    }
    return 0;
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ld long double
#define dd double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
typedef vector<pll> vplll;
ll mod = 1e9+7;
const ld PI = 2 * acos(0.0);
const vector<ll> dx = {1, -1, 0, 0};
const vector<ll> dy = {0, 0, 1, -1};
#define round(x, y) ((x + y - 1) / y)
#define ce(x, y) ((x + y - 1) / y)
#define amax(x, y) \
    if (y > x)     \
        x = y;
#define amin(x, y) \
    if (y < x)     \
        x = y;
#define lcm(x, y) ((x) * (y) / __gcd(x, y))
#define len(x) (ll) x.length()
#define sq(x) ((x) * (x))
#define cb(x) ((x) * (x) * (x))
int dp[3001][3001];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c,t,n,m,k,q; 
    t = 1;
    // cin>>t;
    while(t--)
    {
    	string s1,s2;
    	cin>>s1>>s2;
    	int l1 = s1.length(), l2 = s2.length();
    	for(int i=0;i<l1;i++)
    	{
    		for(int j=0;j<l2;j++)
    		{
    			dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j]); 
    			if(s1[i]==s2[j])
    			{
    				dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j]+1);
    			}
    		}
    	}
    	string ans;
    	int i=l1-1, j = l2-1;
    	for(int xx = dp[l1][l2];xx>0;)
    	{
    		// for(int j=l2-1;j>=0;j--)
    		// {
    			if(s1[i]==s2[j])
    			{
    				ans.pb(s1[i]);
    				i--, j--, xx--;
    			}
    			else if(xx==dp[i+1][j])
    			{
    				j--;
    			}
    			else
    			{
    				i--;
    			}
    	}
    	reverse(all(ans));
    	cout<<ans<<endl;
    	// cout<<dp[l1][l2]<<endl;
    }
    return 0;
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main() {
  
  string a, b, c;
  cin >> a >> b >> c;
  string abc = "";
  abc = abc + a.at(0) + b.at(0) + c.at(0);
  transform(abc.begin(), abc.end(), abc.begin(), ::toupper);
  cout << abc << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int, int> P;
int main()
{
  int N;
  long K;
  cin >> N >> K;
  vector<P> p(N);
  for (int i = 0; i < N; i++)
  {
    int a, b;
    cin >> a >> b;
    p[i] = make_pair(a, b);
  }
  sort(p.begin(), p.end());
  int ans = 0;
  long len = 0;
  for (int i = 0; i < N; i++)
  {
    len += p[i].second;
    if (K <= len)
    {
      ans = p[i].first;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
"""
参考    yy4さん 2019-11-24 21:24:43
516 ms          PyPy3 (2.4.0)
"""
#def solve():
from collections import deque
import sys

input = sys.stdin.readline

n = int(input())

connection = tuple(set() for _ in range(n))
for idx in range(n - 1):
    a, b = (int(x) - 1 for x in input().split())
    connection[a].add((b, idx))
    connection[b].add((a, idx))

q = deque()
q.append((0, -1, -1))

color_edge = [-1] * n  # color_edge[-1]は使わない
used = [False] * n
used[0] = True
while q:
    v, v_idx, prev_color = q.popleft()
    color_now = 1 if prev_color != 1 else 2
    for u, u_idx in connection[v]:
        if used[u]:
            continue
        used[u] = True
        color_edge[u_idx] = color_now
        q.append((u, u_idx, color_now))
        color_now += 1
        if color_now == prev_color:
            color_now += 1

ret = color_edge[:-1]
#return len(set(ret)), ret

    
#l, ret = solve()
l=len(set(ret))
print(l)
print(*ret, sep='\n')

Measured memory_bytes: 55828
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define all(in) in.begin(), in.end()
#define FIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int, int> PII;

int main(){
    FIO;
    ll n;
    cin >> n;
    if( (n&(n-1)) == 0){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    cout << 1 << " " << 2 << endl;
    cout << 1 << " " << 3 << endl;
    cout << 2 << " " << n+3 << endl;
    cout << 3 << " " << n+2 << endl;
    cout << n+1 << " " << n+2 << endl;
    if(n == 3){
        return 0;
    }
    for(ll i = 4 ; i < n ; i += 2){
        ll x = i, y = i+1;
        cout << 1 << " " << x << endl;
        cout << 1 << " " << y << endl;
        cout << x << " " << n+y << endl;
        cout << y << " " << n+x << endl;
    }
    if(n%2 == 0){
        ll x = 1;
        while((1<<x) <= n){
            x++;
        }
        x = (1 << (x-1));
        ll x1 = 1^x^n;
        cout << x << " " << n << endl;
        cout << x1 <<  " " << n*2 << endl;
    }
    return 0;
}


Measured memory_bytes: 2304
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
#include <map>
using namespace std;

const double PI=acos(-1);

int main(){
    int n;
    cin >> n;
    vector<pair<int, pair<double, double>>> l(n);
    for(int i = 0; i < n; i++){
        double x, y;
        cin >> x >> y;
        l[i].first = i;
        l[i].second.first = x;
        l[i].second.second = y;
    }
    
    double ans = 0;
    do{
        for(int i = 1; i < l.size(); i++){
            double t = sqrt(pow(l[i].second.first - l[i-1].second.first, 2) + pow(l[i].second.second - l[i-1].second.second, 2));
            ans += t;
        }
    }while(next_permutation(l.begin(), l.end()));
    int b = 1;
    for(int i = 1; i <= n; i++) b*= i;
    ans /= b;
    printf("%.6f\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <numeric>
#include <functional>
using namespace std;
using ll = long long int;
ll M = 1000000000+7;
ll RS(ll N, ll P, ll M);

int main(void){
  ll n,a,b;
  cin >> n >> a >> b;
  ll ans;
  ans = RS(2,n,M); // nから任意個選ぶ組み合わせ=2^n (0本の花束はないので、後で1引く)
  
  ll abunbo=1,abunshi=n;
  for (int i = 1; i < a; i++){
    abunshi = abunshi * ((n-i) % M) % M;
    abunbo = abunbo * ((i+1) % M) % M;
  }
  ll acomb = abunshi * RS(abunbo, M-2, M) % M;
  ll bbunbo=1,bbunshi=n;
  for (int i = 1; i < b; i++){
    bbunshi = bbunshi * ((n-i) % M) % M;
    bbunbo = bbunbo * ((i+1) % M) % M;
  }
  ll bcomb = bbunshi * RS(bbunbo, M-2, M) % M;
  
  ans -= (acomb + bcomb + 1) % M;
  if (ans < 0) ans += M;
  cout << ans << endl;
  return 0;
}

ll RS(ll N, ll P, ll M){
  if (P==0) return 1;
  else if (P%2==0){
    ll sq = RS(N,P/2,M);
    return sq*sq%M;
  }
  else{
    return N*RS(N,P-1,M)%M;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  int N;
  cin >> N;
  vector<vector<int>> F(N, vector<int>(10));
  vector<vector<int>> P(N, vector<int>(11));

  rep(i, N) rep(j, 10)
  {
    cin >> F[i][j];
  }
  rep(i, N) rep(j, 11)
  {
    cin >> P[i][j];
  }
  int ans = INT32_MIN;
  rep(i, pow(2, 10))
  {
    if (i == 0)
      continue;
    int n = i;
    vector<int> count(N, 0);
    int time = 0;
    while (n != 0)
    {
      if (n & 1)
      {
        rep(j, N)
        {
          if (F[j][time] == 1)
            count[j]++;
        }
      }
      time++;
      n = n >> 1;
    }
    int profit = 0;
    rep(j, N)
        profit += P[j][count[j]];

    ans = max(ans, profit);
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int mod = 998244353;

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

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

int pw(int a, int b) {
  int res = 1;
  while (b > 0) {
    if (b % 2 == 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b /= 2;
  }
  return res;
}

const int N = 300'009;

int f[N];
int rf[N];

int choose(int n, int k) {
  return mul(f[n], mul(rf[k], rf[n - k]));
}

int main() {
  f[0] = 1;
  rf[0] = 1;
  for (int i = 1; i < N; ++i) {
    f[i] = mul(f[i - 1], i);
    rf[i] = pw(f[i], mod - 2);
  }
  int n, a, b;
  long long k;
  cin >> n >> a >> b >> k;
  int ans = 0;
  for (int i = 0; i <= n; ++i) {
    long long r = k - 1LL * a * i;
    if (r < 0) {
      break;
    }
    if (r % b != 0) {
      continue;
    }
    long long j = r / b;
    if (j > n) {
      continue;
    }
    add(ans, mul(choose(n, i), choose(n, (int)j)));
  }
  cout << ans << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll memo[87];
ll f(ll x){
  if(memo[x]) return memo[x];
  return memo[x] = f(x-1) + f(x-2);
}
int main(){
  int N; cin>>N;
  memo[0] = 2;
  memo[1] = 1;
  cout<<f(N)<<endl;
  return 0;
}


Measured memory_bytes: 384
#include<iostream>

int L,R,d;
int main(){
 	std::cin>>L>>R>>d;
  	int count=0;
  	for(int i=L;i<=R;i++){
    	if(i%d==0)count++;
    }
  	
  std::cout<<count;
  return 0;
  
  
  
}


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

int D,M,d,q;
int c[30];
int s[400][30];
int type[400];
int last[29];
ll satis_level[400];

ll calc_score(int d){
  rep(i,d,D+1) satis_level[i] = 0;
  if(d==1)
    rep(j,1,27) last[j]=0;
  else{
    rep(j,1,27) last[j]=0;
    rep(i,1,d) last[type[i]] = i;
  }
  ll down_satis;
  satis_level[d] = satis_level[d-1];
  rep(i,d,D+1){
    down_satis=0;
    last[type[i]] = i;
    satis_level[i] += s[i][type[i]];
    rep(j,1,27) down_satis += c[j]*(i-last[j]);
    satis_level[i] -= down_satis;
    satis_level[i+1] += satis_level[i];
  }
  return satis_level[D];
}

int main(){
  map<int,int, std::greater<int>> mp;
  satis_level[0]=0;
  cin >> D;
  rep(i,1,27){
    cin >> c[i];
    mp[c[i]]=i;
  }
  rep(i,1,D+1){
    rep(j,1,27){
      cin >> s[i][j];
    }
  }
  
  int j=1;
  for(auto i=mp.begin();j<=D;++i,j++) {
    type[j] = mp[i->first];
  }
  
  ll pre_score,new_score;
  int d,q,pq;
  pre_score = calc_score(1);
  random_device rnd; 
  mt19937 mt(rnd());
  uniform_int_distribution<> rand_d(1,D); 
  uniform_int_distribution<> rand_q(1,26); 
  rep(i,1,200000){
    d = rand_d(mt);
    q = rand_q(mt);
    pq = type[d];
    type[d] = q;
    new_score = calc_score(d);
    if(pre_score > new_score) type[d] = pq;
    else pre_score = new_score;
    //if(pre_score > new_score && i%10000==0) type[d] = q;
  }
  
  rep(i,1,D+1) cout << type[i] << '\n';
  return 0;
}


Measured memory_bytes: 3704
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){

  int n;

  while(cin >> n && n != 0){
  vector<pair<int, int> > v;
    for(int i = 0; i < n; i++){
      int p,d1,d2;
      cin >> p >> d1 >> d2;
      pair<int, int> tmp(d1+d2,p);
      //      cout << tmp.first << " " << tmp.second << endl;
      v.push_back(tmp);
    }
    sort(v.begin(),v.end());
    cout << v[n-1].second << " "<< v[n-1].first << endl;
  } 

  return 0;
}

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

string s,ss,x;
 ll a,b,i,j,l=0,k=0,d,c;
map<ll,ll>m;
vector<ll>v;
cin>>a;

for(i=1;i<a;i++)
{
cin>>b;v.push_back(b);
}
for(i=0;i+1<v.size();i++)
{
l+=min(v[i],v[i+1]);
}
l+=v[a-2];l+=v[0];
if(a==2)
{
cout<<v[0]*2<<endl;return 0;}
cout<<l<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;

int main() {
	ll x, a; cin >> x >> a;
	cout << ((x < a) ? 0 : 10 )<< endl;
	return 0;
}

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

N = int(input())
lst = [None] * N
for i in range(N):
    s, p = input().split()
    lst[i] = [s, int(p)]

idx_list = range(len(lst))
idx_sorted = sorted(idx_list, key=lambda x: (lst[x][0], -lst[x][1]))

for idx in idx_sorted:
    print(idx+1)


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

using namespace std;

long long n, a[5];

int main() {
	scanf("%lld", &n);
	for (int i = 0; i < 5; i++) scanf("%lld", &a[i]);
	
	long long mn = 1e18;
	
	for (int i = 0; i < 5; i++) mn = min(mn, a[i]);
	
	printf("%lld\n", 4LL + (n + mn - 1) / mn);
}


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

using namespace std;

typedef long long ll;

int n,a[100005][2];

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d%d",&a[i][0],&a[i][1]);
    ll ans=0;
    for(int i=n;i>=1;i--){
        ll val=(a[i][1]-((a[i][0]+ans)%a[i][1]))%a[i][1];
//        cout<<val<<'\n';
        ans+=val;
    }
    cout<<ans<<'\n';
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using ld=long double;
using VI=vector<ll>;
using VD=vector<ld>;
using VVI=vector<VI>;
using VC=vector<char>;
using VVC=vector<VC>;
using VS=vector<string>;
using PLL =pair<ll,ll>;
using PLD=pair<ld,ld>;
using VPLL=vector<PLL>;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element((x).begin(),(x).end())
#define MIN(x) *min_element((x).begin(),(x).end())
#define SORTR(x) sort((x).rbegin(),(x).rend())
#define SORT(x) sort((x).begin(),(x).end())
#define SUM(x) accumulate((x).begin(),(x).end(), 0)
#define FILL(x,a) fill(x.begin(),x.end(),a)
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
#define COUT(x) cout<<x<<"\n"

const ll INF = 1e18;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll GCD(VI v){ll a = v[0]; for (ll i = 1; i<SIZE(v); i++) {a = gcd(a, v[i]);} return a;}
ll LCM(VI v){ll a = v[0]; for (ll i = 1; i<SIZE(v); i++) {a = lcm(a, v[i]);} return a;}


void Main()
{
	ll n;
	cin >> n;
	VI t(n+1),v(n+1,0);
	for(ll i=0;i<n;i++) cin >> t[i],t[i]*=2;
	for(ll i=0;i<n;i++) cin >> v[i],v[i]*=2;
	ll to=0;
	ll id=0;
	VI z(8e4+10,0);
	for(ll i=0;i<n;i++) {
		to+=t[i];
		z[id]=min(z[id],v[i]);
		for(id++;id<=to;id++) z[id]=min(z[id-1]+1,v[i]);
		id--;
	}
	ll mv=0;
	double ans=0;
	for(ll i=id-1;i;i--) {
		mv=min(z[i],mv+1);
		ans+=double(mv);
	}
	ans/=4.0;
	cout << ans << "\n";
	return;
}

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


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) b.rbegin(),v.rend()
typedef long long ll;
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i,n){
    cin >> h.at(i);
  }
  int ans = 0;
  int count = 0;
  rep(i,n-1){
    if(h.at(i)>=h.at(i+1)){
      count++;
      ans = max(ans,count);
    }else{
      ans = max(ans,count);
      count = 0;
    }
  }
  cout << ans << endl;
}




Measured memory_bytes: 640
#include <iostream>

using namespace std;

int n , s;

int dfs(int i , int sum , int N){

	if(N == 0 && sum == 0) return 1;//yes
	if(N == 0 || i == 10) return 0;//no

	return dfs(i + 1 , sum , N) + dfs(i + 1 , sum - i , N - 1);
}

int main(){

	while(cin >> n >> s , n){

		cout << dfs(0 , s , n) << endl;
	}
	return 0;
}

Measured memory_bytes: 3052
N = int(input())
A = list(map(int, input().split()))

t = [0] * N
t[0] = sum(A[::2]) - sum(A[1::2])
for i in range(1, N):
    t[i] = 2 * A[i - 1] - t[i - 1]
print(*[str(i) for i in t])


Measured memory_bytes: 20120
#include<bits/stdc++.h>
using namespace std;
int k[2020],f[2000005],a[2000005],g[2000005];
long long sum;
int main() {
	string s;
	cin>>s;
	int n=s.size();
	
	for(int i=0;i<n;i++){
		a[i+1]=s[i]-'0';
	}
	int l=1;
	for(int i=n;i>=1;i--){
		g[i]=l;
		l*=10;
		l%=2019;
	}
	for(int i=n;i>=1;i--){
		f[i]=(f[i+1]+a[i]*g[i])%2019;
		k[f[i]]++;
	}
	sum=k[0];
	sum+=(k[0]*(k[0]-1)/2);
	for(int i=1;i<=2018;i++){
		sum+=(k[i]*(k[i]-1)/2);
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 6092
#include <bits/stdc++.h>
using namespace std;
#define MAX_N 100
#define INF 1<<20
typedef pair<int, int> P;
P r[MAX_N], b[MAX_N];
bool used[2*MAX_N];
int N;
struct edge{int to, cap, rev;};
vector<edge> G[2*MAX_N+2];

void add_edge(int from, int to, int cap){
	G[from].push_back((edge){to, cap, G[to].size()});
	G[to].push_back((edge){from, 0, G[from].size()-1});
}

// 増加パスをdfsで探す
int dfs(int v, int t, int f){
	if(v == t) return f;
	used[v] = true;
	for(int i=0; i<G[v].size(); i++){
		edge &e = G[v][i];
		if(!used[e.to] && e.cap > 0){
			int d = dfs(e.to, t, min(f, e.cap));
			if(d > 0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

// sからtへの最大流を求める
int max_flow(int s, int t){
	int flow = 0;
	for(;;){
		fill(used, used+2*N, 0);
		int f = dfs(s, t, INF);
		if(f == 0) return flow;
		flow += f;
	}
}

int main(void){
	cin >> N;
	int s = 2 * N, t = s + 1;
	for(int i=0; i<N; i++){ cin >> r[i].first >> r[i].second; }
	for(int i=0; i<N; i++){ cin >> b[i].first >> b[i].second; }

	for(int i=0; i<N; i++) add_edge(s, i, 1);
	for(int j=0; j<N; j++) add_edge(j+N, t, 1);
	for(int i=0; i<N; i++){
		for(int j=0; j<N; j++){
			if(r[i].first < b[j].first && r[i].second < b[j].second) add_edge(i, j+N, 1);
		}
	}
	cout << max_flow(s, t) << endl;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
using namespace std;
int main(){
  string a,b;
  int ans=0,c=0,aa;
  cin>>a>>b;
  aa=a.size();
  a+=a;
  for(int i=0;i<aa;i++){
    if(a[i]==b[0]){
      for(int j=0;j<b.size();j++){
	if(a[i+j]==b[j])c++;
      }
      if(c == b.size() && ans == 0){
	cout<<"Yes"<<endl;
	ans++;
      }
    }
    c=0;
  }
  if(ans==0)cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 3192
from sys import stdin
input1 = stdin.readline().rstrip().split()
inputStr = stdin.readline().rstrip()
inputLength = int(input1[0])
changeIdx = int(input1[1]) - 1
    
if inputLength > 50 or changeIdx > inputLength or len(inputStr) != inputLength:
    print("Invalid Input Error")
    
# K番目の文字が大文字なら小文字に、小文字なら大文字に変換する
if inputStr[changeIdx] == 'A' or inputStr[changeIdx] == 'B' or inputStr[changeIdx] == 'C' :
    print(inputStr[0 : changeIdx] + inputStr[changeIdx].lower() + inputStr[changeIdx + 1 : len(inputStr)])
else:
    print(inputStr[0 : changeIdx] + inputStr[changeIdx].upper() + inputStr[changeIdx + 1 : len(inputStr)])

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

using namespace std;

const int N = 8;
int l[N], n, A, B, C;

int solve() {
	int res = 1e9 + 7;
	int cntSs1 = 0, cnts2 = 0, cnts3 = 0;
	for (int S = 0; S < (1 << n); ++S)
		for (int s1 = 1; s1 < (1 << n); ++s1)
			if ((S | s1) == S) {
				cntSs1++;
				for (int s2 = 1; s2 < (1 << n); ++s2)
					if ((s2 & s1) == 0 && (s2 | S) == S) {
						cnts2++;
						int s3 = S & (~(s1 | s2));
						if (s3 == 0) continue;
						cnts3++;
						int mp = 0, a = 0, b = 0, c = 0, cnt = 0, ja = 0, jb = 0, jc = 0;
						for (int i = 0; i < n; ++i) {
							if (s1 & (1 << i)) a += l[i], cnt++, ja++;
							if (s2 & (1 << i)) b += l[i], cnt++, jb++;
							if (s3 & (1 << i)) c += l[i], cnt++, jc++;
						}
						mp = abs(a - A) + abs(b - B) + abs(c - C) + 10 * (ja + jb + jc - 3);
						res = min(res, mp);
					}
			}
	return res;
}

int calc(int i, int a, int b, int c) {
	if (i == n) {
		if (a == 0 || b == 0 || c == 0) return 1e9 + 7;
		return abs(a - A) + abs(b - B) + abs(c -C) - 30;
	}
	int res = 1e9 + 7;
	res = min(res, calc(i + 1, a, b, c));
	res = min(res, 10 + calc(i + 1, a + l[i], b, c));
	res = min(res, 10 + calc(i + 1, a, b + l[i], c));
	res = min(res, 10 + calc(i + 1, a, b, c + l[i]));
	return res;
}

int main() {
	cin >> n >> A >> B >> C;
	for (int i = 0; i < n; ++i)
		cin >> l[i];
	printf("%d", calc(0, 0, 0, 0));
	return 0;
}


Measured memory_bytes: 256
import math
N = int(input())
p = []
d = []

def dfs(route, visited, n):
  total = 0
  if(len(route) == n + 1):
    for i in range(1, N):
      x1, y1 = d[route[i]]
      x2, y2 = d[route[i+1]]
      total += math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
      
    return total

  route.append(0)

  for i in range(n):
    if(visited[i]):
      continue

    route[-1] = i
    v = visited[::]
    v[i] = True
    total += dfs(route[::], v, n)
  
  return total

for i in range(N):
  d.append(list(map(int, input().split())))

a = 1

for i in range(1, N+1):
  a *= i

print(dfs([-1], [False] * N, N) / a)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main(){
    string s;
    ll k;
    cin >> s >> k;

    char ans = '1';

    rep(i, k){
        if(s[i] != '1'){ 
            ans = s[i];
            break;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import sys

n = int(input())
s = input()

l = 0
r = n
while l < n and s[l] == ".":
    l += 1
while r > 0 and s[r-1] == "#":
    r -= 1
if l >= r:
    print(0)
    sys.exit()

A = []
a = 0
b = 0
for i in range(l, r):
    if s[i] == "#":
        if b > 0:
            A.append([a, b])
            a = 1
            b = 0
        else:
            a += 1
    else:
        b += 1
if b > 0:
    A.append([a, b])
# print(A)

DP = [0, 0]
for i in range(len(A)):
    DPN = DP[:]
    DPN[0] = min(DP) + A[i][1]
    DPN[1] = DP[1] + A[i][0]
    DP = DPN[:]
print(min(DP))

Measured memory_bytes: 55244
import java.util.*;
import java.math.*;
     
class Main{
    public static void main(String[] args) {
        
        try(Scanner sc = new Scanner(System.in)){

            int hour1 = Integer.parseInt(sc.next());
            int minute1 = Integer.parseInt(sc.next());
            int hour2 = Integer.parseInt(sc.next());
            int minute2 = Integer.parseInt(sc.next());

            int study = Integer.parseInt(sc.next());

            int difHour = 0;
            int difMinute = 0;

            if(minute2 - minute1 < 0){
                difHour = hour2 - hour1 - 1;
                difMinute = minute2 - minute1 + 60;
            }else{
                difHour = hour2 - hour1;
                difMinute = minute2 - minute1;
            }

            int sumTime = difHour*60 + difMinute;

            System.out.println(sumTime - study);

        }catch(Exception e){
            e.printStackTrace();
        }        
    }
}

Measured memory_bytes: 35608
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  string t = "AKIHABARA";
  int p=0;
  REP(i, 0, t.length()){
    //cerr << p << " "<< i << endl;
    if (p < s.length() && s[p] == t[i]){
      p++;
      continue;
    }
    if (t[i]=='A'){
      continue;
    }
    p = 1000;
    break;
  }
  cout << (p == s.length() ? "YES" : "NO") << "\n";
}


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


int main(){
  ios_base::sync_with_stdio(false);

  int a, b, k;
  vector<int> ans;

  cin >> a >> b >> k;

  for(int i = 1; i <= min(a, b); i++) {
    if(a % i == 0 && b % i == 0) {
      ans.push_back(i);
    }
  }
  
  cout << ans[ans.size()-k] << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
#include <memory>
using namespace std;
typedef long long LL;

int main() {
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];

    sort(a.begin(), a.end());
    
    cout << abs(a[1] - a[2]) + abs(a[0] - a[1]) << endl;



    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int L = 0;
    int R = 0;
    int d = 0; 
    int i = 0;
    scanf("%d", &L);
    scanf("%d", &R);
    scanf("%d", &d);

    while(1){
        if(L > R) break;
        if(L % d == 0) i++;
        L++;
    }
    printf("%d", i);
    return 0;
}

Measured memory_bytes: 1708
#include <bits/stdc++.h>
#define Phuong_ ios_base::sync_with_stdio(0); cin.tie(0);
#define pb push_back
#define mp make_pair

/// easy access -------------
using namespace std;
using ll = long long;
using ld = long double;
typedef pair<int,int> pii;
///-------------------------

int main()
{
    Phuong_; /// <3
    int sum=0;
    int n,m;
    cin >> n >> m;
    while(m--)
    {
        int u;
        cin >> u;
        sum+=u;
    }
    cout << max(n-sum,-1);
    return 0;
}



Measured memory_bytes: 3648
a[200],b[200],c[1000],d[1000],n,m,i,j,k,t;main(){for(;scanf("%d",&n)&&n;){for(i=0;i<n;i++){scanf("%d%d",&a[i],&b[i]);}scanf("%d",&m);for(i=0;i<m;i++){scanf("%d%d",&c[i],&d[i]);}for(i=0;i<m;i++){for(j=1;j<n;j++){for(k=0;k<m;k++){if(a[j]+c[i]-a[0]==c[k]){if(b[j]+d[i]-b[0]==d[k]){t++;}}}}if(t==n-1){printf("%d %d\n",c[i]-a[0],d[i]-b[0]);t=0;break;}t=0;}}return 0;} 

Measured memory_bytes: 608
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<ll,ll> pint;

int n;
const int INF=1000100010;
const int MAX_N=201;
struct edge{
    int to,cap,rev;
    edge(int to,int cap,int rev):
    to(to),cap(cap),rev(rev){}
    };

vector<edge> g[MAX_N];
bool used[MAX_N];
void add_edge(int src,int dst,int cap){
    g[src].pb(edge(dst,cap,g[dst].size()));
    g[dst].pb(edge(src,0,g[src].size()-1));
}
int dfs(int v,int t,int f){
    if(v==t) return f;
    used[v]=true;
    rep(i,g[v].size()){
        edge &e=g[v][i];
        if(!used[e.to]&&e.cap>0){
            int d=dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap-=d;
                g[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}
int max_flow(int s,int t){
    int flow=0;
    while(1){
        memset(used,0,sizeof(used));
        int f=dfs(s,t,INF);
        if(f==0) return flow;
        flow+=f;
    }
}

int sr[2001],ds[2001],d[201][201],c[2001],dd[2001];
int warshall_floyd(){
    rep(k,n)rep(i,n)rep(j,n){
        if(d[i][k]==INF||d[k][j]==INF)continue;
        d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
    }
}
int main(){
    int m,s,t;
    cin>>n>>m>>s>>t;
    --s,--t;
    rep(i,n)rep(j,n) d[i][j]=INF;
    rep(i,n) d[i][i]=0;
    rep(i,m){
        cin>>sr[i]>>ds[i];
        --sr[i],--ds[i];
        cin>>d[sr[i]][ds[i]]>>c[i];
        dd[i]=d[sr[i]][ds[i]];
    }
    warshall_floyd();
    rep(i,m){
        if(d[s][sr[i]]+dd[i]+d[ds[i]][t]==d[s][t]){
            add_edge(sr[i],ds[i],c[i]);
        }
    }
    cout<<max_flow(s,t)<<endl;
    return 0;
}


Measured memory_bytes: 3264
def seiseki(list):
    goukei = list[0]+list[1]
    saishiken = list[2]
    if (list[0]==-1) or (list[1]==-1) or (goukei<30):
        return 'F'
    elif (goukei >= 80):
        return 'A'
    elif (goukei >= 65):
        return 'B'
    elif (goukei >= 50) or (saishiken >= 50):
        return 'C'
    else:
        return 'D'

flag = True
a = []

while flag:
    t = list(map(int, input().split()))
    if (t[0] == -1) and (t[1] == -1) and (t[2] == -1):
        flag = False
        continue
    a.append(t)
for i in a:
    str = seiseki(i)
    print(str)


Measured memory_bytes: 5600
a,b=map(int,input().split())
ans=0
sums=a*(a+1)//2
for i in range(a-b+2):
    c=b+i
    minsum=c*(c-1)//2
    maxsum=sums-(a-c)*(a-c+1)//2
    ans+=maxsum-minsum+1
print(ans%(pow(10,9)+7))

Measured memory_bytes: 9184
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
 
using namespace std;
int MOD = 1000000007;

signed main(){
    int n;
    cin >> n;

    int a[110];
    rep(i,n) cin >> a[i];

    int mini = INF;

    for(int i = -100;i <= 100;i++){
        int ans = 0;
        rep(j,n){
            ans += (a[j]-i)*(a[j]-i);
        }
        mini = min(mini,ans);
    }
    cout << mini << endl;

    
    return 0;   
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://arc059.contest.atcoder.jp/tasks/arc059_a
// rm -r -f test;oj dl http://yahoo-procon2017-qual.contest.atcoder.jp/tasks/yahoo_procon2017_qual_c

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

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int a,b,c;
	cin >> a >> b >> c;
	if(a >= b){
		if(c <= a && c >= b) cout << "Yes\n";
		else cout << "No\n";
	}
	else{
		if(c >= a && c <= b) cout << "Yes\n";
		else cout << "No\n";
	}
	return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        string S = Console.ReadLine();
        string T = Console.ReadLine();
        int count = 0;
        if (S[0] == T[0]) count++;
        if (S[1] == T[1]) count++;
        if (S[2] == T[2]) count++;


        Console.Write(count);

        Console.ReadKey();
    }


    public static int GetInputInt()
    {
        return int.Parse(Console.ReadLine());
    }
    public static int[] GetInputsInt()
    {
        return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    }
    public static List<int> GetInputsIntList()
    {
        return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
    }
    public static List<float> GetInputsFloatList()
    {
        return Console.ReadLine().Split(' ').Select(float.Parse).ToList();
    }

    public static long GetInputLong()
    {
        return long.Parse(Console.ReadLine());
    }
    public static long[] GetInputsLong()
    {
        return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
    }

}


Measured memory_bytes: 11092
import java.util.Scanner;

public class Main{
public static void main(String[] args){
  Scanner sc = new Scanner(System.in);
String S = sc.next();
String T = sc.next();
  String S2=S+S;
if(S2.contains(T)){
  System.out.println("Yes");
}else{
  System.out.println("No");
}
}
}


Measured memory_bytes: 23636
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        String n = scan.nextLine();
        String[] array = n.split("");

        int frag = 0;
        for(String a : array){
            if(a.equals("7")){
                frag = 1;
            }
        }

        if(frag == 1){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

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

int main(){
  int h,w;
  cin >> h >> w;
  vector <string> s(h);
  for(int i=0;i<h;i++){
    cin >> s.at(i);
  }
  
  vector <int> aroundX = {-1, 0, 1, 1, 1, 0,-1,-1};
  vector <int> aroundY = {-1,-1,-1, 0, 1, 1, 1, 0};
  
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s.at(i).at(j)=='#')continue;
      int cnt=0;
      for(int k=0;k<8;k++){
        int x,y;
        x=i+aroundX.at(k);
        y=j+aroundY.at(k);
        if(x<0||x>=h||y<0||y>=w)continue;
        if(s.at(x).at(y)=='#'){
          cnt++;
        }
      }
      s.at(i).at(j)='0'+cnt;
    }
  }
  
  for(int i=0;i<h;i++){
    cout << s.at(i) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
n, k = map(int,input().split())

li = []

for i in range(1, k+1):
  d = int(input())
  a = list(map(int, input().split()))
  li.extend(a)

newli = set(li)

count = 0

for j in range(1, n+1):
  if j in newli:
    count = count
  else:
    count = count + 1

print(count)

Measured memory_bytes: 9244
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <cstdio>
#define INF 1LL<<60
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main(){
  int n;
  cin >> n;
  REP(i, n){
    char x;
    cin >> x;
    if(x == 'Y'){
      cout << "Four" << endl;
      return 0;
    }
  }
  cout << "Three" << endl;
	return 0;
}


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

using namespace std;


int main () {
	int num, act_num;
	cin >> num >> act_num;

	vector<int> length(num);
	for (int i = 0; i < num; i++) {
		cin >> length.at(i);
	}

	sort(length.begin(), length.end(), greater<int>());

	int sum = 0;
	for (int i = 0; i < act_num; i++) {
		sum += length.at(i);
	}

	cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int dep[100010], par[100010], size[100010], bcnt, wcnt;
vector<int> v[100010];

void dfs(int now, int prev) {
	size[now] = 1; par[now] = prev;
	for (int i=0;i<v[now].size();i++) if (v[now][i]!=prev) {
		dep[v[now][i]] = dep[now]+1;
		dfs(v[now][i], now);
		size[now] += size[v[now][i]];
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	int n; cin >> n;
	if (n==2) {
		cout << "Snuke\n";
		return 0;
	}
	for (int i=0;i<n-1;i++) {
		int a, b; cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	dfs(1, -1);
	int p = n, up = (dep[n]-1)/2;
	for (int i=0;i<up;i++) p = par[p];
	wcnt = size[p];
	bcnt = n-wcnt;
	if (bcnt>wcnt) cout << "Fennec\n"; else cout << "Snuke\n";
}

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

int main() {
	int a, b, c=0, n;
	while(++c) {
		cin >> a >> b;
		if(!a&&!b) break;
		if(c>1) cout << endl;
		n = 0;
		for(int i=a; i<=b; ++i) {
			if(!(i%4)&&(!(i%400)||i%100)) {
				cout << i << endl; n++;
			}
		}
		if(!n) cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstdio>
using namespace std;
#define MOD 1000000007
#define MAX 3030
void add(int &x,int y){x+=y;if(x>=MOD)x-=MOD;}
int n,m,ans,f[MAX][MAX][2];
int main()
{
	scanf("%d%d",&n,&m);f[0][0][1]=1;
	for(int i=1;i<=n;++i)f[0][i][0]=1;
	for(int i=1;i<=m;++i)
		for(int j=0;j<=n;++j)
			for(int k=0;k<=1;++k)
			{
				if(j)add(f[i][j][k|(j==1)],f[i-1][j][k]),add(f[i][j-1][k|(j==1)],f[i-1][j][k]);
				if(n-j)add(f[i][j+1][k],f[i-1][j][k]),add(f[i][j][k],f[i-1][j][k]);
			}
	for(int i=0;i<=n;++i)add(ans,f[m][i][1]);
	printf("%d\n",ans);return 0;
}


Measured memory_bytes: 71936
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N,A,B=get_i
puts "#{min(A,B)} #{max(A+B-N,0)}"

Measured memory_bytes: 1788
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  int H, N;
  scanf("%d %d", &N,&H);
  \
  vector<long int> A;
  for (int i=0; i<N; i++){
    int kari;
    scanf("%d", &kari);
    A.push_back(kari);
  }
  
  if(H>= N ){
    printf("0\n");
    return 0;
  }

  sort(A.begin(), A.end());

  long int sum=0;
  for (int i=0; i<N-H ; i++){
    sum += A[i];
  }  
  printf("%ld\n", sum);
return 0;
}

Measured memory_bytes: 2420
n = int(input())
A = list(map(int, input().split()))
if n >= 2:
  for i in range(n, 0, -2):
    print(A[i-1], end=" ")
  for i in range(n % 2, n - 2, 2):
    print(A[i], end=" ")
  print(A[n-2])
if n == 1:
  print(*A)

Measured memory_bytes: 94036
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()

int main() {
  //
  int h, w, d;
  cin >> h >> w >> d;
  map<int, pii> m;
  // vector<vector<int>> a(h, vi(w));
  rep(i, h) {
    rep(j, w) {
      int a;
      cin >> a;
      m[a] = make_pair(i, j);
    }
  }
  vector<ll> move(h * w + 1, 0);
  rep(x, h * w + 1) {
    if (x > d) {
      pii cur = m[x];
      pii prev = m[x - d];
      move[x] = move[x - d] + abs(cur.first - prev.first) +
                abs(cur.second - prev.second);
    }
  }
  int q;
  cin >> q;
  rep(x, q) {
    int l, r;
    cin >> l >> r;
    cout << move[r] - move[l] << endl;
  }
  return 0;
}


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

//関数
//main関数
int main() {
    
    
    //入力
    long N;
    cin>>N;
    vector<long> H(N);
    for(int i=0;i<N;i++){
        cin>>H.at(i);
    }
    //計算
    long ans=1,highest=H.at(0);
    for(int i=1;i<N;i++){
        if(H.at(i)>=highest){
            ans++;
            highest=H.at(i);
        }
    }
    
    //出力
    cout<<ans<<endl;
}





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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  
  if(a+b > c+d)
    cout << "Left" << endl;
  else if(a+b == c+d)
    cout << "Balanced" << endl;
  else
    cout << "Right" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define se second
#define fi first
const int N=400005;
set<pair<int ,int > > S[N];
int tot,n,a[N],l,x,val[N],flag[N],ans,y,z,f[N],g[N],sl[N],ne[N],zz[N],fi[N];
void jb(int x,int y,int z){
	ne[++tot]=fi[x];
	fi[x]=tot;
	zz[tot]=y;
	sl[tot]=z;
}
void down(int x){
	int i=x;
	if (x*2<=l&&val[f[x]]>val[f[x*2]])i=x*2;
	if (x*2<l&&val[f[i]]>val[f[x*2+1]])i=x*2+1;
	if (i!=x){
		swap(f[x],f[i]);
		swap(g[f[x]],g[f[i]]);
		down(i);
	} 
}
void up(int x){
	if (x==1)return;
	if (val[f[x/2]]>val[f[x]]){
		swap(f[x],f[x/2]);
		swap(g[f[x]],g[f[x/2]]);
		up(x/2);
	}
}
signed main(){
	scanf("%lld",&n);
	for (int i=1;i<=n;i++)scanf("%lld",&a[i]);
	for (int i=1;i<n;i++){
		scanf("%lld%lld%lld",&x,&y,&z);
		S[x].insert(mp(z,y));
		S[y].insert(mp(z,x));
	}
	for (int i=1;i<=n;i++)f[i]=g[i]=i,val[i]=a[i]+(*S[i].begin()).fi;
	l=n;
	for (int i=n;i;i--)down(i);
	for (int i=1;i<n;i++){
		int k=f[1];pair<int ,int > p=(*S[k].begin());
		ans+=val[k]+a[p.se];
		S[k].erase(S[k].begin());
		if (!S[k].empty())val[k]=(*S[k].begin()).fi+a[k];
		else val[k]=1e18;
		down(1);
		S[p.se].erase(mp(p.fi,k));
		a[p.se]=min(a[p.se],a[k]+p.fi);
		if (!S[p.se].empty())val[p.se]=(*S[p.se].begin()).fi+a[p.se];
		else val[p.se]=1e18;
		down(g[p.se]);up(g[p.se]);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 59904
#include <iostream>
#include <cmath>
using namespace std;
int main(){
  int X;cin>>X;
  int ans=1; 
    for (int b=2;b<32;++b){
      for (int p=2;p<10;++p){
        int tmp=pow(b,p);
        if (tmp>ans && tmp<=X) ans=tmp;
        //if (ans>X)break;
      }
    }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys

def divisors(n):
  res = []
  for i in range(1, int(n ** 0.5) + 1):
    if n % i: continue
    res.append(i)
    res.append(n // i)
  return res

n = int(sys.stdin.readline().rstrip())

def main():
    res = divisors(n)
    print(res[-1] + res[-2] - 2)

if __name__ ==  '__main__':
    main()

Measured memory_bytes: 3264
using System;
using System.Collections.Generic;

namespace AOJ.Volume0
{
    class Program0013
    {
        static void Main(string[] args)
        {
            string line;
            Queue<string> operatingQueue = new Queue<string>();
            Stack<string> trainStack = new Stack<string>();

            while((line = Console.ReadLine()) != null)
            {
                operatingQueue.Enqueue(line);
            }

            foreach (var op in operatingQueue)
            {
                if (op == "0")
                {
                    Console.WriteLine(trainStack.Pop());
                    int.Parse(op);
                }
                else
                {
                    trainStack.Push(op);
                }
            }
        }
    }
}

Measured memory_bytes: 5680
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  long long length[3] = {0}, cmin;

  cin >> length[0] >> length[1] >> length[2];

  for(int i = 0;i < 3;i++){
    if(length[i] % 2 == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

  cmin = length[0] * length[1];
  cmin = min(cmin, length[1] * length[2]);
  cmin = min(cmin, length[2] * length[0]);

  cout << cmin << endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>

using namespace std;

int main() {

	int n, m, x;

	while(cin >> n >> m) {
		if(n==0&&m==0) {
			break;
		}
		pair<int, int> s[100];
		for(int i=0; i<m; i++) {
			s[i].first=0;
			s[i].second=i+1;
		}
		for(int i=0; i<n; i++) {
			for(int j=0; j<m; j++) {
				cin >> x;
				x && s[j].first++;
			}
		}
		for(int i=0; i<m-1; i++) {
			for(int j=m-1; j>i; j--) {
				if(s[j].first>s[j-1].first) {
					swap(s[j], s[j-1]);
				}
			}
		}

		for(int i=0; i<m; i++) {
			if(i) {
				cout << " ";
			}
			cout << s[i].second;
		}
		cout << endl;
	}

	return 0;

}

Measured memory_bytes: 868
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

vector<long long> list;

void dfs(long long n, long long max)
{
	if (n > max)
	{
		return;
	}

	if (n != 0)
	{
		list.push_back(n);
	}

	dfs(n * 10 + 3, max);
	dfs(n * 10 + 5, max);
	dfs(n * 10 + 7, max);
}

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

	dfs(0, N);

	int count = 0;
	for (auto v : list)
	{
		string s = to_string(v);

		if (s.find('3') != -1
			&& s.find('5') != -1
			&& s.find('7') != -1)
		{
			count++;
		}
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

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

    B -= A;
    A = 0;
    
    REP(k, N) {
        if( k*C - (N-1-k)*D  <= B && B <= k*D - (N-1-k)*C) {
            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    string S[3];
    rep(i,0,3)cin >> S[i];
    int turn = 0;
    while(S[turn].size()){
        int tmp = S[turn][0] - 'a';
        S[turn].erase(S[turn].begin());
        turn = tmp;
    }
    string ans = "ABC";
    cout << ans[turn] << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n;
  bool approved=true;
  cin>>n;
  for(int i=0;i<n;i++){
    int data;
    cin>>data;
    if(data%2==0&&data%3!=0&&data%5!=0){
      approved=false;
    }
  }
  if(approved){
    cout<<"APPROVED"<<endl;
  }else{
    cout<<"DENIED"<<endl;
  }
  return(0);
}



Measured memory_bytes: 256