akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int[] list = new int[n];

        for (int i = 0; i < n; i++) {
            list[i] = sc.nextInt();
        }

        Arrays.sort(list);

        System.out.println(list[n / 2] - list[n / 2 - 1]);
    }
}


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

int main() {
  int k,n;
  string s;
  cin >> k >> s;
  n = s.size();
  if(n <= k) cout << s << endl;
  else cout << s.substr(0,k) << "..." << endl;
}

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

#define coutv(v) for (int i = 0; i < (v).size(); ++i) cout << v[i] << ' '; cout << endl;
#define coutvv(v) for (int i = 0; i < (v).size(); ++i) {for (int j = 0; j < (v[i]).size(); ++j) cout << v[i][j] << ' '; cout << endl;}
#define debugv(v) {for (int i = 0; i < (v).size(); ++i) cerr << v[i] << ' '; cerr << endl;}
#define debugvv(v) {for (int i = 0; i < (v).size(); ++i) {for (int j = 0; j < (v[i]).size(); ++j) cerr << v[i][j] << ' '; cerr << endl;}}
#define stringtovector(s, v) {for (int i = 0; i < (s).size(); ++i) v.push_back(s[i]);};
#define TC int TESTCASE; cin >> TESTCASE; while (TESTCASE--)
typedef long long ll;
const int mod = 1000000007;


vector<vector<int>> g;
vector<pair<long double, int>>used;
int n;

void dfs(int x, int d) {
    used[x].first = 1;
    used[x].second = 1;
    for (auto y : g[x]) {
        if (y != 0) {
            if (!used[y].first) {
                used[y].first = d + 1;
                used[y].second += 1;
                dfs(y, d + 1);
            } else {
                int len = g[y].size();
                used[y].second += 1;
                used[y].first = (used[y].first + d + 1) / (used[y].second);
            }
        }
    }
}



int main() {
    int d, t, s;
    cin >> d >> t >> s;
    if (s * t >= d) {
        cout << "Yes";
    } else {
        cout << "No";
    }
}





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

int main(){
	int a,b,c; cin >> a >> b >> c;
	int count=0;
	int l[3]={a,b,c};
	for(int i=0;i<3;i++){
		for(int j=i+1;j<3;j++){
			if(l[i]==l[j]){
				l[j]=0;
			}
		}
	}
	for(int i=0;i<3;i++){
		if(l[i]!=0){
			count++;
		}
	}
	cout << count;
} 

Measured memory_bytes: 256
//Moh_K_Imar .......
//29/08/2020  ... 5,30.
//Ya Rab....
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
int main(){
    ld a,b,c;
    cin>>a>>b>>c;
    cout<<(0.5*b)*a<<endl;

    return 0;
}



Measured memory_bytes: 3756
#include <set>  
#include <map>  
#include <math.h>  
#include <vector>  
#include <stdio.h>  
#include <string.h>  
#include <iostream>  
#include <algorithm>  
const double eps = 1e-8;  
using namespace std;  
   
set<int> x;  
set<int> y;  
set<int>::iterator it;  
   
void doit(int a,int now)  
{  
    if(now==0) return;  
    if(a==1){  
        set<int> y_;  
        y_.clear();  
        for(it = y.begin();it!=y.end();it++){  
            y_.insert(*it-now);  
            y_.insert(*it+now);  
        }  
        y.clear();  
        for(it = y_.begin();it!=y_.end();it++){  
            y.insert(*it);  
            y.insert(*it);  
        }  
    }else{  
        set<int> x_;  
        x_.clear();  
        for(it = x.begin();it!=x.end();it++){  
            x_.insert(*it-now);  
            x_.insert(*it+now);  
        }  
        x.clear();  
        for(it = x_.begin();it!=x_.end();it++){  
            x.insert(*it);  
            x.insert(*it);  
        }  
    }  
}  
   
int main()  
{  
    string s;  
    cin>>s;  
    int xx,yy;  
    scanf("%d%d",&xx,&yy);  
    int now=0;  
    int i;  
    for(i=0;i<s.length();i++){  
        if(s[i]=='F'){  
            now++;  
        }else{  
            break;  
        }  
    }  
    x.insert(now+10000);  
    y.insert(10000);  
    int a=1;  
    now=0;  
    for(i++;i<s.length();i++){  
        if(s[i]=='F'){  
            now++;  
        }else{  
            doit(a,now);  
            a^=1;  
            now=0;  
        }  
    }  
    doit(a,now);  
    if(x.find(xx+10000)!=x.end()&&y.find(yy+10000)!=y.end()){  
        printf("Yes\n");  
    }else  
        printf("No\n");  
   
   
}  

Measured memory_bytes: 768
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
vector<ll> pw2(51,1);vector<ll> pw10(19,1);


int main(){
    {rep1(i,50) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N,K; cin>>N>>K;
    ll ans=0;
    vector<ll> A(N+1,0);
    rep1(i,N) cin>>A[i];
    
    vector<ll> visited(N+1,INF);
    ll now=1;
    ll rotate,times;
    visited[now]=0;
    rep1(i,N){
        now=A[now];
        if(i==K){
            cout<<now<<endl;
            return 0;
        }
        
        if(visited[now]==INF) visited[now]=i;
        else{
            rotate=now;
            times=i;
            break;
        }
    }
    //visited[rotate]~times回でrotateに戻る
    ll L=times-visited[rotate];
    rep1(i,(K-visited[rotate])%L){
        now=A[now];
    }
    cout<<now<<endl;
}



Measured memory_bytes: 6428
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> A(n);
  bool allEven = true;
  rep(i, n) {
    cin >> A[i];
    if(A[i]%2) allEven = false;
  }
  cout << (allEven ? "second" : "first") << endk;
  return 0;
}


Measured memory_bytes: 3972
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define all(v) (v).begin(),v.end()
#define fi first
#define se second
vector<vector<int>> graph;
  int n,m;
bool used[200000];
int dp[200000];
int tp_sort(int v){
    if(!used[v])  return dp[v];
    used[v]=false;
    for(auto to:graph[v]){
            int res=tp_sort(to);
            dp[v]=max(dp[v],res+1);
    }
    return dp[v];
}

int main(){
    int n,m;
    cin>>n>>m;
    graph.resize(n);
    fill(used,used+n,true);
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        graph[--a].push_back(--b);
    }
    int ans=0;
    for(int i=0;i<n;i++){
      int res=tp_sort(i);
     ans=max(ans,res);
    }
    cout<<ans<<endl;
}





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

using namespace std;

int main(void) {
	int k, x;
	scanf("%d%d", &k, &x);
	for (int i = max(x - k + 1, -1000000); i <= min(x + k - 1, 1000000); ++i)
		printf("%d ", i);
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long lint;
typedef unsigned long long ulint;


//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
//template <typename T> void print(T* v, int N) { if (N == 0) cout << "{ }"; cout << "{" << v[0]; for (int p = 1; p < N; p++) cout << ", " << v[p]; cout << "}"; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
	


int main() {
	set<int> st;
	for (int i = 0; i < 3; i++) {
		int x; cin >> x;
		st.insert(x);
	}
	cout << st.size() << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;


int main(){
  int n,C;
  cin >> n >> C;
  vector<vector<P>> d(32);
  rep(i,n){
    int s,t,c; cin >> s >> t >> c;
    d[c].push_back({s,t});
  }
  rep(i,32){
    sort(d[i].begin(),d[i].end());
  }
  vector<vector<int>> ch(32, vector<int>(mx,0));
  rep(i,32){
    int m = d[i].size();
    rep(j,m){
      if(j>0 && d[i][j-1].S==d[i][j].F){
        ch[i][d[i][j-1].S*2] = 0;
      } else {
        ch[i][d[i][j].F*2-1] = 1;
      }
      ch[i][d[i][j].S*2] = -1;
    }
  }
  rep(i,32){
    rep(j,mx-1){
      ch[i][j+1] += ch[i][j];
    }
  }

  int ans = 0;
  rep(j,mx){
    int cnt = 0;
    rep(i,32){
      if(ch[i][j]) cnt++;
    }
    ans = max(ans,cnt);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 27392
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }

        public static bool  prime(long x)
        {
            if (x < 2) return false;
            else if (x == 2) return true;
            else if (x % 2 == 0) return false;
            double sqrt = Math.Sqrt(x);
            for (int i = 3; i <= sqrt; i+=2)
            {
                if (x % i == 0) return false;
            }
            return true;
        }




        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);


            var x = Read();


            long ans = 0;
            for (long i = x; ; i++)
            {
                if (prime(i))
                {
                    ans = i;
                    break;
                }
            }
            Console.WriteLine(ans);
              
            
           
           
            



            Console.Out.Flush();
        }
    }
}




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

int main(void) {
  long long N;
  cin >> N;
  vector<long long> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    a[i]--;
  }
  long long current = 0;
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    if (a[i] == current) {
      current++;
    } else {
      ans++;
    }
  }
  cout << (current == 0 ? -1 : ans) << endl;
  return 0;
}

Measured memory_bytes: 1792
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n;
  int mx=0;
  string s;
  cin >> n ;
  map<string,int>m;
  for(int i=0;i<n;i++){
    cin >> s;
    sort(s.begin(),s.end());
    m[s]++;
  }
  int64_t sum=0;
  for(auto p:m){
    if(p.second >= 2){
      sum += (int64_t)(p.second-1)*p.second*0.5;
    }
  }
  cout << sum << endl;
}

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

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

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

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++)
        cin >> a[i];

    int res = lcm(a[0], a[1]);
    for (int i = 2; i < N; i++)
        res = lcm(res, a[i]);

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n,m,a,b;
  cin>>n>>m;
  cin>>a;
  a=abs(m-a);
  r(i,n-1){
    cin>>b;
    b=abs(m-b);
    a=__gcd(a,b);
  }
  cout<<a<<endl;
}


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

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

typedef long long ll;
#define INF (1ll << 60)

ll divide2(ll h, ll w, ll s) {
  // s: すでに分け終えた面積
  // h x wを面積aとbに分けて、そのときの、s,a,bの絶対差の最大値を返す
  ll max_s1 = -1;
  ll a1 = h/2 * w;
  ll b1 = (h - h/2) * w;
  max_s1 = max(max_s1, abs(s - a1));
  max_s1 = max(max_s1, abs(s - b1));
  max_s1 = max(max_s1, abs(a1 - b1));
  ll max_s2 = -1;
  ll a2 = w/2 * h;
  ll b2 = (w - w/2) * h;
  max_s2 = max(max_s2, abs(s - a2));
  max_s2 = max(max_s2, abs(s - b2));
  max_s2 = max(max_s2, abs(a2 - b2));
  return min(max_s1, max_s2);
}

ll solve(ll h, ll w) {
  ll min_s = INF;
  rep(i,h)
    min_s = min(min_s, divide2(h - i, w, i * w));
  rep(i,w)
    min_s = min(min_s, divide2(w - i, h, i * h));
  return min_s;
}

int main() {
  int h, w;
  cin >> h >> w;
  cout << solve(h, w) << endl;
}


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

int n;
string s, ts;

int main()
{
	cin >> n; //要らないので汎用int型変数として使います(ほんとはあんまよくない)
	cin >> s;
	ts = s;
	while ((n = ts.find("()")) != string::npos)
	{
		ts.erase(n, 2);
	}
	while (!ts.empty())
	{
		if (ts[0] == '(')
		{
			s = s + ')';
		}
		else
		{
			s = '(' + s;
		}
		ts.erase(0, 1);
	}
	cout << s;
}

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

int main() {

	using namespace std;

	string S;
	cin >> S;

	if (S[S.length() - 1] == 's') {
		cout << S << "es" << endl;
	}
	else {
		cout << S << "s" << endl;
	}

	return 0;

}

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);

int main() {
	cin.sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<pair<int, int>>C(M);
	map<int,pair<int, int>>mp;
	rep(i, M) {
		cin >> C[i].second >> C[i].first;
		mp[i] = C[i];
	}
	sort(C.begin(), C.end());
	map<pair<int, int>, int>mp2;
	vector<int>P(N);
	rep(i, M) {
		mp2[C[i]] = ++P[C[i].second - 1];
	}
	rep(i, M) {
		int p = mp[i].second;
		int num = mp2[mp[i]];
		cout << setfill('0') << right << setw(6) << p << setfill('0') << right << setw(6) << num << endl;
	}

	return 0;

}

Measured memory_bytes: 15232
# Aizu Problem NTL_1_C: Least Common Multiple
#
import itertools
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input2.txt", "rt")


def get_factors(n):
    f = 2
    increments = itertools.chain([1,2,2], itertools.cycle([4,2,4,2,4,6,2,6]))
    for incr in increments:
        if f*f > n:
            break
        while n % f == 0:
            yield f
            n //= f
        f += incr
    if n > 1:
        yield n

N = int(input())
max_powers = {}
for n in [int(_) for _ in input().split()]:
    powers = {}
    for f in get_factors(n):
        powers[f] = powers.get(f, 0) + 1
    for p in powers:
        max_powers[p] = max(powers[p], max_powers.get(p, 0))
lcm = 1
for p in max_powers:
    lcm *= p**max_powers[p]

print(lcm)

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

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i,n) cin >> p[i];
  int curMin = 1e8;
  int ans = 0;
  rep(i,n) {
    curMin = min(curMin, p[i]);
    if (curMin == p[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll dis[110][110];
ll a[1010], b[1010], c[1010];
int main() {
	ll n, m, inf = 1e15;
	for (int i = 0; i<110; i++)for (int j = i + 1; j < 110; j++)dis[i][j] = dis[j][i] = inf;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--, b[i]--;
		dis[a[i]][b[i]] = dis[b[i]][a[i]] = c[i];
	}
	for (int k = 0; k<n; k++)for (int i = 0; i<n; i++)for (int j = 0; j<n; j++)dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
	ll ans = m;
	for (int i = 0; i<m; i++)for (int j = 0; j<n; j++) {
		if (dis[j][a[i]] + c[i] == dis[j][b[i]]) {
			ans--;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
/*
 * kuki.cpp
 *
 *  Created on: 2018/04/19
 *      Author: J01003
 */
#include<iostream>
using namespace std;

int main(){

	int a,b;

	cin>>a>>b;

	cout<<a*b<<" "<<a+b+a+b<<endl;

	return 0;
}



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

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;

int main( void )
{
	int n;
	while ( cin >> n, n ) {
		int w, h;
		cin >> w >> h;
		
		VVI field( h + 1, VI( w + 1, 0 ) );
		
		for ( int i = 0; i < n; ++i ) {
			int x, y;
			cin >> x >> y;
			field[y][x] = 1;
		}
		
		for ( int y = 0; y <= h; ++y ) {
			for ( int x = 1; x <= w; ++x ) {
				field[y][x] += field[y][x - 1];
			}
		}
		for ( int y = 1; y <= h; ++y  ) {
			for ( int x = 0; x <= w; ++x ) {
				field[y][x] += field[y - 1][x];
			}
		}
		
		int s, t, ans = 0;
		cin >> s >> t;
		
		for ( int y = 1; y + t - 1 <= h; ++y ) {
			for ( int x = 1; x + s - 1 <= w; ++x ) {
				ans = max( ans, field[y + t - 1][x + s - 1] - field[y + t - 1][x - 1] - field[y - 1][x + s - 1] + field[y - 1][x - 1] );
			}
		}
		
		cout << ans << endl;
	}
	return 0;
}

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

int main(void){
	int r, c;
	int **table;

	cin >> r >> c;

	table = new int*[r+1];
	for (int i = 0; i < r+1; i++){
		table[i] = new int[c+1];
	}

	for (int i = 0; i < r; i++){
		for (int j = 0; j < c; j++){
			cin >> table[i][j];
		}
	}

	for (int i = 0; i < r; i++){
		table[i][c] = 0;
		for (int j = 0; j < c; j++){
			cout << table[i][j] << " ";
			table[i][c] += table[i][j];
		}
		cout << table[i][c] << "\n";
	}
	table[r][c] = 0;
	for (int j = 0; j < c; j++){
		table[r][j] = 0;
		for (int i = 0; i < r; i++){
			table[r][j] += table[i][j];
		}
		cout << table[r][j] << " ";
		table[r][c] += table[r][j];
	}
	cout << table[r][c] << "\n";

	delete[] table[0];
	delete[] table;

	return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PI                acos(-1)
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define forr(i, b, e)     for(ll i = b; i < e; i++)
#define forite(i, b, e)    for(auto i = b; i!=e; i++)
#define forg(i, b, e, m)  for(ll i = b; i < e; i+=m)

#define F first
#define S second

using namespace std;
using namespace __gnu_pbds;

typedef long long       ll;
typedef pair<int, int>  ii;
typedef vector<ll>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int INF = ll(1e9+7);
#define tam 320000
#define tamlog 61
#define ptr nodo*

typedef pair<ii,ll> iii;

int main()
{
    ll n,m;
    cin>>n>>m;
    ll cant=min(m/2,n);
    m-=cant*2;
    cout<<cant+m/4<<endl;
}
// PLUS ULTRA!

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

template <typename T> void output(T, int);
int gcd(int a, int b);

int main() {
    // source
    int n;
    cin >> n;
    cout << n*(n+1)/2 << endl;
    return 0;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<vector>
using namespace std;
struct node
{
	long long x,y;
}a[1000005],b[1000005];
char s[1000005];
map<pair<long long,long long>,long long>Map;
int n,m;
long long ans;
signed main()
{
	scanf("%d",&n);
	scanf("%s",s);
	m=1ll<<n;
	for (int l=0;l<m;l++)
	{
		for (int i=0;i<n;i++)
			if (l>>i&1)	a[l].x=a[l].x*27+s[i]-96;
			else a[l].y=a[l].y*27+s[i]-96;
		for (int i=n-1;i>=0;i--)
			if (l>>i&1) b[l].x=b[l].x*27+s[i+n]-96;
			else b[l].y=b[l].y*27+s[i+n]-96;
	}
	for (int i=0;i<m;i++)
		Map[make_pair(a[i].x,a[i].y)]++;
	for (int i=0;i<m;i++)
		ans+=Map[make_pair(b[i].x,b[i].y)];
	printf("%lld\n",ans);
}


Measured memory_bytes: 44288
#include<stdio.h>
#include<math.h>
int main(){
  int a,b,c,d,s,g;
  scanf("%d%d%d%d",&a, &b, &c, &d);
  if(d<a || b<c){
    printf("0\n");
  }
  else{
    if(a>c){
      s=a;
    }
    else{
      s=c;
    }
    if(b>d){
      g=d;
    }
    else{
      g=b;
    }
    printf("%d\n",g-s);
  }
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    ll R, C, K;
    cin >> R >> C >> K;
    vector<vector<ll>> grid(R, vector<ll>(C, 0));
    ll r, c, v;
    while(K--) {
        cin >> r >> c >> v;
        grid[r-1][c-1] += v;
    }
    vector<vector<vector<ll>>> dp(R, vector<vector<ll>>(C, vector<ll>(4, 0)));
    
    dp[0][0][0] = 0;
    dp[0][0][1] = grid[0][0];
    for(int i = 0; i < R; i++) {
        for(int j = 0; j < C; j++) {
            for(int k = 3; k >= 0; k--) {                
                if (j-1 >= 0) {
                    dp[i][j][k] = max({dp[i][j][k], dp[i][j-1][k]});
                    if (k-1 >= 0)
                        dp[i][j][k] = max({dp[i][j][k], dp[i][j-1][k-1]+grid[i][j]});
                }                
            }
            if (i-1 >= 0) {
                for(int k = 3; k >= 0; k--) {
                    dp[i][j][0] = max({dp[i][j][0], dp[i-1][j][k]});
                    dp[i][j][1] = max({dp[i][j][1], dp[i-1][j][k]+grid[i][j]});
                }
            }   
        }
    }
    ll ans = 0;
    for(int k = 0; k <= 3; k++) {
        ans = max(ans, dp[R-1][C-1][k]);
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 705996
#pragma GCC optimize("Ofast")
  
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <tuple>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <cassert>
#include <numeric>
#include <cmath>
#include <bitset>
#include <random>
#include <regex>

using namespace std;
  
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(14)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
constexpr int dy[] = {0,1,0,-1,1,-1,-1,1};
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class A, class B> inline A updiv(const A a,const B b){ return (a + b - 1) / b; }
template <class A, class B> inline A gcd(const A a,const B b){ return b ? gcd(b,a % b) : a; }
template <class A, class B> inline A lcm(const A a,const B b){ return a / gcd(a,b) * b; }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A,class B> using umap = unordered_map<A,B>;


signed main(void){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int h,w;
    cin >> h >> w;

    vector<string> mat(h);

    rep(i,h){
        cin >> mat[i];
    }

    auto inside = [&](int y, int x){
        return (y < h && x < w && y >= 0 && x >= 0);
    };

    queue<tuple<int,int,bool> > que;
    vector<vector<int> > cnt(h,vector<int>(w,INF));

    que.emplace(0,0,mat[0][0] == '#');
    cnt[0][0] = (mat[0][0] == '#');
    while(!que.empty()){
        int y,x;
        bool brack;
        tie(y,x,brack) = que.front();
        que.pop();
        rep(i,2){
            int ny = y + dy[i];
            int nx = x + dx[i];
            if(inside(ny,nx)){
                int add = (!brack && mat[ny][nx] == '#');
                if(chmin(cnt[ny][nx],cnt[y][x] + add)){
                    que.emplace(ny,nx,mat[ny][nx] == '#');
                }
            }
        }
    }

    cout << cnt[h-1][w-1] << '\n';

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define max 100005
using ll =long long;
using namespace std;

int main(){
    int s,w;
    cin>>s>>w;
    if(s<=w){
        cout<<"unsafe"<<endl;
    }else{
        cout<<"safe"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long a,b,v,w,t;
    cin>>a>>v>>b>>w>>t;
    long long dist=abs(a-b), sp=v-w;
    if(sp*t>=dist){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <set>
#include <tuple>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[])
{
	int N, Q;
	tuple<int, int, int> stx[200001];
	set<pair<int, int> > st;

	cin >> N >> Q;

	for (int i = 0; i < N; i++) {
		int S, T, X;
		cin >> S >> T >> X;
		stx[i] = make_tuple(X, S - X, T - X);
	}
	sort(stx, stx + N);

	for (int i = 0; i < Q; i++) {
		int D;
		cin >> D;
		st.insert(make_pair(D, i));
	}

	int ans[200001] = {0};
	for (int i = 0; i < Q; i++) {
		ans[i] = -1;
	}
	for (int i = 0; i < N; i++) {
		int S, T, X;
		tie(X, S, T) = stx[i];

		auto itr = st.lower_bound(make_pair(S, -1));
		while (itr != st.end()) {
			if (itr->first >= T) {
				break;
			}
			ans[itr->second] = X;
			st.erase(itr++);
		}
	}

	for (int i = 0; i < Q; i++) {
		cout << ans[i] << "\n";
	}

	return 0;
}


Measured memory_bytes: 14336
#include <iostream>

using namespace std;

int main()
{
    int n,cn;
    cin>>n;
    cn=n;
    int v[3];
    v[2]=n%10;
    n/=10;
    v[1]=n%10;
    n/=10;
    v[0]=n%10;
    int x=v[0]*100+v[1]*10+v[2];
    int x2=v[0]*100+v[0]*10+v[0];
    if(x>x2){
        cout<<x2+111;
    }
    else{
        cout<<x2;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

string s;
int k;

int main(){
	cin>>s>>k;
	int n=s.size();
	vs a;
	for(int i=0;i<n;i++) for(int j=1;j<=5;j++) if(i+j<=n) a.push_back(s.substr(i,j));
	sort(a.begin(),a.end());
	a.erase(unique(a.begin(),a.end()),a.end());
	cout<<a[k-1]<<endl;
}

Measured memory_bytes: 1660
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	unsigned int n;
	cin >> n;
	unsigned int sum = 0, m = n;
	while(m != 0){
		unsigned int tmp = m % 10;
		sum += tmp;
		m -= tmp;
		m /= 10;
	}
	if(n % sum == 0) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define sum(x) accumulate(all(x),0)
#define pc(x) __builtin_popcount(x)
#define gll greater<ll>()

void solve(){
 ll n,k;
  cin >> n >> k;
  vll a(n);
  rep(i,0,n) cin >> a[i];
  
  rep(i,k,n){
    if(a[i-k]<a[i]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  
  
  
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}

Measured memory_bytes: 4772
#include<cstdio>
#define abs(a) ((a)>=0?(a):(-(a)))
#define min(a,b) ((a)<(b)?(a):(b)) 
#define maxn 100050
using namespace std;
int dp[maxn],a[maxn];
int main(){
	int n,k=2;
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	scanf("%d",&a[i]),dp[i]=1e9;
	dp[1]=0;
	for (int i=2;i<=n;i++){
		for (int j=1;j<=k;j++)
		if (i-j>0) dp[i]=min(dp[i],dp[i-j]+abs(a[i-j]-a[i]));
	}
	printf("%d\n",dp[n]);
	return 0;
}

Measured memory_bytes: 896
n=int(input())
s=[list(map(int,input().split()))for i in range(3)]
s[0].sort()
s[1].sort()
s[2].sort()
c,d,e=0,0,0
for i in range(n):
    while d<n and s[0][d]<s[1][i]:
        d+=1
    while e<n and s[2][e]<=s[1][i]:
        e+=1
    c+=d*(n-e)
print(c)

Measured memory_bytes: 23328
class HeapNode():
    def __init__(self):
        self.id = None
        self.key = None
        self.left = None
        self.right = None
        self.parent = None
    
    def show(self):
        print("node {0}: key = {1}, ".format(self.id,self.key), end="")
        if self.parent:
            print("parent key = {}, ".format(self.parent.key), end="")
        if self.left:
            print("left key = {}, ".format(self.left.key), end="")
        if self.right:
            print("right key = {}, ".format(self.right.key), end="")
        print("")

class HeapTree():
    def __init__(self, n):
        self.root = None
        self.n = n + 1
        self.T = [None] * (2 * n + 2)

    def insert(self, x):
        for i in range(len(x)):
            Node = HeapNode()
            if self.root is None:
                self.root = Node
            Node.id = i + 1
            Node.key = x[i]
            self.T[i+1] = Node
            
    def setPLR(self):
        for i in range(1, self.n):
            Node = self.T[i]
            Node.left = self.T[i * 2]
            Node.right = self.T[i * 2 + 1]
            Node.parent = self.T[i // 2]

    def TreePrint(self):
        for i in self.T[1 : self.n]:
            i.show()

n = int(input())
L = list(map(int, input().split()))
Tree = HeapTree(n)
Tree.insert(L)
Tree.setPLR()
Tree.TreePrint()

Measured memory_bytes: 7784
#include <bits/stdc++.h>
#define x first
#define v second
#define l second
#define r first
using namespace std;
typedef pair<int,int> ii;
const long long mod = 1000000007;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n; cin >> n;
	ii arr[n];
	ii ranges[n];
	
	vector<int> dis;
	for(int i = 0;i < n;i++){
		cin >> arr[i].x >> arr[i].v;
		dis.push_back(arr[i].v);
	}
	sort(arr, arr + n, [&](ii a, ii b){ return a.x < b.x; });
	sort(dis.begin(),dis.end()); ///discritize velocity
	for(int i = 0;i < n;i++) arr[i].v = lower_bound(dis.begin(),dis.end(),arr[i].v) - dis.begin();
	
	///finding the ranges
	int minV = mod, maxV = 0;
	for(int i = 0;i < n;i++){
		maxV = max(maxV, arr[i].v);
		ranges[i].r = maxV;
		dis.push_back(arr[i].v);
	}
	for(int i = n-1;i >= 0;i--){
		minV = min(minV, arr[i].v);
		ranges[i].l = minV;
	}
	
	sort(ranges, ranges + n); ///increasing r, then l
	
	long long ans = (ranges[0].r == maxV);
	long long dp[n]; dp[0] = 1;
	for(int i = 1;i < n;i++){
		int pos = lower_bound(ranges, ranges + i, ii(ranges[i].l - 1, -1)) - ranges; ///find which ranges can be extended from
		dp[i] = dp[i-1];
		if(pos != 0) dp[i] -= dp[pos-1];
		if(ranges[i].l == minV) dp[i]++; ///can start taking from here
		
		dp[i] %= mod;
		if(dp[i] < 0) dp[i] += mod;
		
		if(ranges[i].r == maxV){ ///this range covers till the end
			ans += dp[i];
			if(ans >= mod) ans -= mod;
		}
		
		dp[i] += dp[i-1]; ///update dp like a prefix sum
		if(dp[i] >= mod) dp[i] -= mod;
		
	}
	cout << ans;
}

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

int main() {
  int n, a = 100000;
  scanf("%d", &n);
  while (n--) {
    a += a * 5 / 100;
    a = (int)ceil(a / 1000.0) * 1000;
  }
  printf("%d\n", a);
}


Measured memory_bytes: 2680
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		long N = sc.nextLong();
		long K = sc.nextLong();
		
		long min = N;
		if (N >= K) {
			min = N % K;
		}
		
		if (min > K / 2.0) {
			min = Math.abs(min - K);
		}
		
		System.out.println(min);
		
	}
}

Measured memory_bytes: 23124
#include<iostream>
char judge(int m,int r,int f){
    char grade;
    int sum=m+r;
    if(m==-1 || r==-1) grade='F';
    else if(sum>=80) grade='A';
    else if(sum>=65) grade='B';
    else if(sum>=50) grade='C';
    else if(sum>=30){
        grade='D';
        if(f>=50) grade='C';
    }
    else grade='F';
    return grade;
}
int main(void){
    int m,r,f;
    while(1){
        std::cin>>m>>r>>f;
        if(m==-1&&r==-1&&f==-1) break;
        std::cout<<judge(m,r,f)<<std::endl;
    }
    return 0;
}

Measured memory_bytes: 3088
/*  -*- coding: utf-8 -*-
 *
 * 1588.cc: Potatoes
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 15;
const int MAX_M = 10000;
const int MAX_K = 3;

/* typedef */

typedef vector<int> vi;
typedef pair<int,int> pii;

/* global variables */

pii ps[MAX_N];

/* subroutines */

void comb(int u, int k, int n, int bits, vi &cs) {
  if (k <= 0) {
    cs.push_back(bits);
    return;
  }
  if (u >= n) return;

  for (int i = u, bi = 1 << i; i < n; i++, bi <<= 1)
    comb(i + 1, k - 1, n, bits | bi, cs);
}

inline void setmax(int &a, int b) { if (a < b) a = b; }

/* main */

int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);

  for (int i = 0; i < n; i++) scanf("%d", &ps[i].first);
  for (int i = 0; i < n; i++) scanf("%d", &ps[i].second);
  sort(ps, ps + n);

  vi cs;
  comb(0, k, n, 0, cs);
  //printf("%lu\n", cs.size());

  int maxsum = 0;
  for (vi::iterator vit = cs.begin(); vit != cs.end(); vit++) {
    int &bits = *vit;
    int sum = 0, r = m;
    for (int i = n - 1, bi = 1 << i; i >= 0; i--, bi >>= 1)
      if (bits & bi) {
	int c = min(r, ps[i].second);
	sum += c * ps[i].first;
	r -= c;
      }

    setmax(maxsum, sum + r);
  }

  printf("%d\n", maxsum);
  return 0;
}



Measured memory_bytes: 3284
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>
#include <bitset>

//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//std::cout << std::fixed << std::setprecision(10)
//std::ios::sync_with_stdio(false);
constexpr long long MOD = 1000000007;

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

int main()
{
  long long A, B, N;
  std::cin >> A >> B >> N;
  long long r = N < B ? N : B - 1;
  std::cout << (A * r) / B << std::endl;
  return 0;
}



Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;i++)
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;
typedef vector<P> vip;

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

int main(){
//option:-std=c++0x
    solve();
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		String na = String.valueOf(n);
		if((char)na.charAt(na.length()-1) == '2' ||(char)na.charAt(na.length()-1) == '4' ||(char)na.charAt(na.length()-1) == '5' ||(char)na.charAt(na.length()-1) == '7' ||(char)na.charAt(na.length()-1) == '9') {
			System.out.println("hon");
		}else if((char)na.charAt(na.length()-1) == '3' ) {
			System.out.println("bon");
		}else {
			System.out.println("pon");
		}
	}
	
}


Measured memory_bytes: 26996
#include <bits/stdc++.h>
#include <cmath>    // abs() for float, and fabs()
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main(){
    ll x;
    ll k;
    ll d;
    ll a = 0;
    ll b = 0;
    ll aa = 0;
    ll bb = 0;
    ll ans = 0;
    cin >> x >> k >> d;
    if (x < 0){
        x = abs(x);
    }
    a = x / d;
    b = x % d;
    if (a > k){
        ans = x - d * k;
    }
    if (a == k){
        ans = b;
    }
    if (a < k){
        aa = x - d * a;
        bb = k - a;
        if (bb % 2 == 0){
            ans = aa;
        }else{
            ans = aa - d;
        }
    }
    if (ans < 0){
        ans = abs(ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main(){
    string s,p;
    cin>>s>>p;
    s=s+s;
    int i;
    for(i=0; i<s.length()/2; i++){
        string str;
        for(int j=i; j<i+p.length(); j++){
            str+=s[j];
        }
        if(str==p){
        //if(s.substr(i, p.length())==p){
            cout<<"Yes\n";
            break;
        }
    }
    if(i==s.length()/2) cout<<"No\n";
    return 0;
}


Measured memory_bytes: 3204
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
#include<bitset>

#define rep(i, n) for(int i = 0;i < (n);i++)
#define rrep(i, n) for(int i = (n);i >= 0;i--)
#define FOR(i, m, n) for(int i = (m);i < (n);i++)

using namespace std;
using ll = long long;

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

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


//////////////////////////////////////////////////


int main() {
    int n, q; cin >> n >> q;
    vector<vector<int>> g(n);
    for (int i = 0; i < n-1; i++)
    {
        int a, b; cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<ll> cnt(n);
    for (int i = 0; i < q; i++)
    {
        int p, x; cin >> p >> x;
        p--;
        cnt[p] += x;
    }

    auto rec = [&](auto &&rec, int now, int before) -> void {
        if (now != 0) cnt[now] += cnt[before];
        for (int i = 0; i < g[now].size(); i++)
        {
            if (before == g[now][i]) continue;
            rec(rec, g[now][i], now);
        }
    };

    rec(rec, 0, -1);
    
    for (int i = 0; i < n; i++)
    {
        printf("%lld%c", cnt[i], (i==(n-1) ? '\n' : ' '));
    }
    
    
    return 0;
}


Measured memory_bytes: 21120
h, w = map(int, input().split())
a = [input() for i in range(h)]

row = [False] * h
col = [False] * w
for i in range(h):
	for j in range(w):
		if a[i][j] == '#':
			row[i] = True
			col[j] = True

for i in range(h):
	if row[i]:
		for j in range(w):
			if col[j]:
				print(a[i][j], end = '')
		print()

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

class Dice
{
private:
  int surf[6];
public:
  void set_surf(int* input);
  void roll(char orient);
  void disp_top();
};

void Dice::set_surf(int* input)
{
  memcpy(surf, input, 6*sizeof(int));
}

void Dice::roll(char orient){
  int temp[6];
  
  switch(orient){
  case 'S':
    temp[0]=surf[4];
    temp[1]=surf[0];
    temp[2]=surf[2];
    temp[3]=surf[3];
    temp[4]=surf[5];
    temp[5]=surf[1];
    break;
  case 'N':
    temp[0]=surf[1];
    temp[1]=surf[5];
    temp[2]=surf[2];
    temp[3]=surf[3];
    temp[4]=surf[0];
    temp[5]=surf[4];
    break;
  case 'W':
    temp[0]=surf[2];
    temp[1]=surf[1];
    temp[2]=surf[5];
    temp[3]=surf[0];
    temp[4]=surf[4];
    temp[5]=surf[3];
    break;
  case 'E':
    temp[0]=surf[3];
    temp[1]=surf[1];
    temp[2]=surf[0];
    temp[3]=surf[5];
    temp[4]=surf[4];
    temp[5]=surf[2];
    break;
  }

  memcpy(surf, temp, 6*sizeof(int));
  
}

void Dice::disp_top(){
  cout << surf[0] << endl;
}

int main()
{
  int input[6];
  Dice dice;
  string order;
  
  for(int i=0; i<6; i++){
    cin >> input[i];
  }
  dice.set_surf(input);
  
  cin >> order;

  for(int i=0; i<order.size(); i++){
    dice.roll(order[i]);
  }

  dice.disp_top();
  
  return(0);
}

Measured memory_bytes: 1208
def main():
	N = int(input())
	A = [0]*N
	for i in range(N):
		A[i] = int(input())
	a = list(A)
	a.sort(reverse=True)
	for i in range(N):
		if a[0] == A[i]:
			print(a[1])
		else:
			print(a[0])


if __name__ == '__main__':
	main()

Measured memory_bytes: 14156
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|i| i.parse().ok().unwrap())
        .collect()
}

fn main() {
    let n: usize = read();
    let ps: Vec<usize> = read_vec();

    let mut min: usize = n;
    let mut count: usize = 0;

    for p in ps.iter() {
        if min >= *p {
            count += 1;
            min = *p;
        }
    }
    println!("{}", count);

}

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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(ll i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

const ll inf = 1ll<<62;
const ll mod = 1e9+7;

int main(){
#define int ll
  string s; cin >> s;
  map<char,int> mp;
  rep(i,sz(s)) mp[s[i]]++;
  int a = 0;
  for(auto x : mp) a += x.snd * (x.snd - 1) / 2;
  cout << sz(s) * (sz(s) - 1) / 2 - a + 1<< endl;;  
}

Measured memory_bytes: 640
blue_num = gets.chomp.to_i
blue_cards = []
blue_num.times do |i|
  blue_cards << gets.chomp.to_s
end
red_num = gets.chomp.to_i
red_cards = []
red_num.times do |i|
  red_cards << gets.chomp.to_s
end
yen = []
blue_cards.each_with_index do |blue_card,i|
   add_count = blue_cards.select {|t| t == blue_card}.length
   remove_count = red_cards.select {|t| t == blue_card}.length
   yen << add_count - remove_count
end
yen.sort!{|a, b| b <=> a }
if yen.first < 0
  puts 0
else
  puts yen.first
end


Measured memory_bytes: 1916
def inN():
    return int(input())
def inL():
    return list(map(int,input().split()))
n = inN()
a = inL()
if 0 in a:
    print(0)
    exit()

sum = 1
t = pow(10,18)
for i in range(n):
    sum *= a[i]
    if sum > t:
        print(-1)
        exit()
print(sum)

Measured memory_bytes: 84628
N = int(input())
W = list(map(int, input().split()))

total = sum(W)
half = total / 2
#print(total, half)

cusum = [0]
for w in W:
  tmp = cusum[-1] + w
  cusum.append(tmp)
#print(cusum)

for i in range(N+1):
  if cusum[i] >= half:
    diff1 = abs(total - 2 * cusum[i])
    diff2 = abs(total - 2 * cusum[i-1])
    #print(i, diff1, diff2)
    ans = min(diff1, diff2)
    break

print(ans)

Measured memory_bytes: 3064
import sys
from collections import Counter
input = sys.stdin.buffer.readline

N = int(input())
a = list(map(int, input().split()))

c = Counter(a)
if len(c.most_common()) > 2:
    print('No')
elif len(c.most_common()) == 1:
    if c.most_common()[0][0] == N-1:
        print('Yes')
    else:
        if c.most_common()[0][0] * 2 <= N:
            print('Yes')
        else:
            print('No')
else:
    x, nx = c.most_common()[0]
    y, ny = c.most_common()[1]
    if x > y:
        x, y = y, x
        nx, ny = ny, nx
    if y - x != 1:
        print('No')
    else:
        if 1 <= y - nx <= ny//2:
            print('Yes')
        else:
            print('No')


Measured memory_bytes: 58780