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

	int main() {
	#ifdef LOCAL_DEFINE
		// freopen("data.in", "rt", stdin);
		// freopen("data.out", "w", stdout);
		auto _start = chrono::high_resolution_clock::now();
	#endif

		ios::sync_with_stdio(false);
		cin.tie(0);
		cout << fixed << setprecision(15);
		int n, m;
		cin >> n >> m;
		vector<string> grid(n);
		for(int i = 0; i < n; i++) {
			cin >> grid[i];
		}
		const int md = 1e9 + 7;
		auto add = [&](int &a, int b) {
			a += b;
			if(a >= md) a -= md;
		};
		vector<vector<int>> dp(n + 1, vector<int>(m + 1));
		dp[0][0] = 1;
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				if(i + 1 < n && grid[i + 1][j] != '#') {
					add(dp[i + 1][j], dp[i][j]);
				}
				if(j + 1 < m && grid[i][j + 1] != '#') {
					add(dp[i][j + 1], dp[i][j]);
				}
			}
		}
		cout << dp[n - 1][m - 1] << '\n';

	#ifdef LOCAL_DEFINE
		auto _end = chrono::high_resolution_clock::now();
		cerr << "elapsed time: " << chrono::duration<double, milli>(_end - _start).count() << " ms\n";
	#endif
		return 0;
	}

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

#define MAXN 100010

struct node
{
	int a,b;
	bool operator<(node n)const
	{
		return b==n.b?a<n.a:b>n.b;
	}
}a[MAXN];

int n,m,ans;
set<int> ep;

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)
	{
		scanf("%d%d",&a[i].a,&a[i].b);
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=m;++i)
	{
		ep.insert(i);
	}
	for(int i=1;i<=n;++i)
	{
		int p=m-a[i].a+1;
		auto res=ep.lower_bound(p+1);
		if(res==ep.begin())continue;
		else ans+=a[i].b,ep.erase(--res);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 5888
#include <cstdio>

int sx, sy, tx, ty;

int main(){
	scanf("%d %d %d %d", &sx, &sy, &tx, &ty);
	tx -= sx;
	ty -= sy;
	for(int i=0; i<ty; ++i) printf("U");
	for(int i=0; i<tx; ++i) printf("R");
	for(int i=0; i<ty; ++i) printf("D");
	for(int i=0; i<tx+1; ++i) printf("L");
	for(int i=0; i<ty+1; ++i) printf("U");
	for(int i=0; i<tx+1; ++i) printf("R");
	printf("DR");
	for(int i=0; i<ty+1; ++i) printf("D");
	for(int i=0; i<tx+1; ++i) printf("L");
	printf("U\n");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
long N;
#define MOD 1000000007

long long mod(long long x)
{
    if(x < 0)
    {
        x = x % 1000000007 + 1000000007;
    }
    return x % 1000000007;
}

long long modpow(long long a, long long n, long long mod = MOD) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod = MOD) {
    return modpow(a, mod - 2, mod);
}
/*
long com(long n,long x)
{
    if(n-1 == x || x == 1)
    {
        return n;
    }
    else if(n == x || x == 0)
    {
        return 1;
    }
    else
    {
        return mod(com(n-1,x-1) + com(n-1,x));
    }
}

void comb(vector<vector <long long int> > &v){
    for(int i = 0;i <v.size(); i++){
        v[i][0]=1;
        v[i][i]=1;
    }
    for(int k = 1;k <v.size();k++){
        for(int j = 1;j<k;j++){
            v[k][j]=mod(v[k-1][j-1]+v[k-1][j]);
        }
    }
}
 */
/*
long mod2(long x, long x2,long &y)
{
    y = y * x2 + x*x2 / 1000000007;
    return x * x2 % 1000000007;
}

long mod3(long x, long &y)
{
    y = x / 1000000007;
    return x % 1000000007;
}

void combi(vector<long> &x,int i)
{
    long lm = x.size();
    for(long t = 0;t<lm;t++)
    {
        x[t] *= (N-i);
    }
    for(long t = lm-1;t>0;t--)
    {
        x[t-1] += (x[t]%(i+1)) * MOD;
        x[t] /= (i+1);
    }
    x[0] /= (i+1);
    for(int t = 0;t<lm;t++)
    {
        if(x[t] > MOD)
        {
            if(t == lm-1)
            {
                x.push_back(x[t]/MOD);
                x[t] %= MOD;
            }
            else
            {
                x[t+1] += x[t]/MOD;
                x[t] %= MOD;
            }
        }
    }
}
*/
 
long ppp(long x,long y)
{
    if(y == 1)
    {
        return x;
    }
    else
    {
        return mod(ppp(mod(x * x),y/2 + y%2));
    }
    
}


int main()
{
    
    int a,b;
    cin >> N;
    cin >> a >> b;
    
    long long ans = modpow(2,N);
    
    
    long long ansA = 1;
    
    
    for(int i = 0;i<a;i++)
    {
        ansA = mod(mod(ansA * (N-i)) * modinv(i+1));
        
    }
    long long ansB = ansA;
    for(int i = a;i<b;i++)
    {
        ansB = mod(mod(ansB * (N-i)) * modinv(i+1));
    }
    
    
    ans = mod(ans - 1 - ansA - ansB);
    
    cout << ans << endl;
    return 0;
    
    /*
    long ansA = 1;
    long tem = 0;
    vector<long> ans2;
    ans2.push_back(1);
    for(int i = 0;i<a;i++)
    {
        combi(ans2,i);
     
        ansA = mod2(ansA,N-i,tem);
        long ttt = tem;
        ansA = mod3((100000007/(i+1)) * ttt + ((100000007%(i+1))+ansA) / (i+1),tem);
     
    }
    long ansB = ansA;
    vector<long> ans3;
    ans3 = ans2;
    for(int i = a;i<b;i++)
    {
        combi(ans3,i);
    }
    
    ans = mod(ans - 1 - ans2[0] - ans3[0]);
    */
    
    
}


 

Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>
#include <random>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
int main(void){
    string s;
    cin >> s;
    if(s.back() == 's'){
        cout << s << "es" << endl;
    } else {
        cout << s << 's' << endl;
    }
}



Measured memory_bytes: 3628
# -*- coding: utf-8 -*-
def power(val, n, mod):
    ret = 1
    while n:
        if n & 1:
            ret = (ret * val) % mod
        val = (val * val) % mod
        n = n >> 1
    return ret


def cmb(n, r, mod):
    if n - r < r:
        r = n - r
    if r == 0:
        return 1
    if r == 1:
        return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
            result = result % mod

    return result % mod


n, a, b = map(int, input().split())

pow_val = power(2, n, 1000000007)
ans = pow_val - 1 - cmb(n, a, 1000000007) - cmb(n, b, 1000000007)

if ans >= 0:
    print(ans)
else:
    if ans + 1000000007 >= 0:
        print(ans + 1000000007)
    else:
        print(ans + (1000000007 * 2))


Measured memory_bytes: 108236
def comb(n,m):
    global kaijo,p
    bunbo=(kaijo[m]*kaijo[n-m])%p
    bunbo=pow(bunbo,p-2,p)
    return kaijo[n]*bunbo%p


p=10**9+7
kaijo=[1]
for i in range(2010):
    kaijo.append(kaijo[-1]*(i+1)%p)
#print(kaijo)

s=int(input())
ans=0


for i in range(s//3):
    nokori=s-3*(i+1)
    ans+=comb(nokori+i,i)
    ans%=p

print(ans)

Measured memory_bytes: 63908
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] line = br.readLine().split(" ");
        final int n = Integer.parseInt(line[0]);
        final int m = Integer.parseInt(line[1]);
        final int l = Integer.parseInt(line[2]);
        long[][] A = new long[n][m];
        long[][] B = new long[m][l];
        long[][] C = new long[n][l];
        
        for (int i=0; i<n; i++){
            String[] tmp= br.readLine().split(" ");
            for (int j=0; j<m; j++){
                long num = Long.parseLong(tmp[j]);
                A[i][j] = num;
            }
        }
        for (int i=0; i<m; i++){
            String[] tmp= br.readLine().split(" ");
            for (int j=0; j<l; j++){
                long num = Long.parseLong(tmp[j]);
                B[i][j] = num;
            }
        }
        for (int i=0; i<n; i++){
            for (int j=0; j<m; j++){
                for (int k=0; k<l; k++){
                    C[i][k] += A[i][j]*B[j][k]; 
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i=0; i<n; i++){
            for (int j=0; j<l-1; j++){
                sb.append(C[i][j]);
                sb.append(" ");
            }
            sb.append(C[i][l-1]);
            sb.append("\n");
        }
        System.out.print(sb.toString());
    }
}

Measured memory_bytes: 27044
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n,k;
    cin >>n ;
    char s[10];
    char c;
    cin >> s ;
    cin >> k;
    c=s[k-1];
    for(int i=0;i<n;i++){
        if(c!=s[i]){
            cout << "*";
        }
        else {
            cout << s[k-1];
        }
    }
    
}


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

string s;

int main(){
  cin >> s;
  int n = s.size();
  long long int a[300000];
  long long int sum = 0;
  rep(i, n){
    char c = s.at(i);
    if(c == 'B'){
      sum++;
      a[i] = 0;
    }else{
      a[i] = sum;
    }
    cerr << a[i] << " ";
  }
  long long int ans = 0;
  rep(i, n){
    ans += a[i];
  }
  cout << ans << endl;
  return 0;
}


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

/// Constant:
#define         eps         10e-9
#define         pi          2*acos(0)
#define         P1          1e9+7
#define         P2          1e9+9

#define         lli         long long int
#define         PB          push_back
#define         pb          pop_back
#define         mk          make_pair
#define         I           insert
/// Loop:
#define         f1(a,b)     for (int i=a; i<=b; i++)
#define         f2(a,b)     for (int j=a; j<=b; j++)
#define         f-1(a,b)     for (int i=b; i>=a; i--)
#define         f-2(a,b)     for (int j=b; j>=a; j--)
///Print:
#define         pY          cout<<"YES"<<endl;
#define         pN          cout<<"NO"<<endl;
#define         py          cout<<"Yes"<<endl;
#define         pn          cout<<"No"<<endl;

using namespace std;
///ISNNJB

/// Functions:
//lli bigmod(lli b, lli p, lli m){if(p==0)return 1;if(p%2!=0) return b%m*fun(b,p-1,m)%m;if(p%2==0){ lli res=fun(b,p/2,m);return (res%m*res%m)%m;}}
//lli mod_inverse(lli a, lli mod) { return bigmod(a,mod-2,mod); }
//lli LCM(lli a, lli b){ return a*b/ __gcd(a,b);}

///Global Variable:
int ara[400005],brr[400004];

/**int fx[]={+1,-1,+0,+0};
int fy[]={+0,+0,+1,-1};
int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};*/

int main() {

    /**freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    lli a,b,c,d,t,n,m,x,y,q,ctn=0,l1,l2,total=0;

    cin>>n;
    for (int aa=1; aa<=n; aa++) {
        for (int i=1; i<=100; i++) {
            for (int j=1; j<=100; j++) {
                for (int k=1; k<=100; k++) {
                    if((i*i+j*j+k*k+i*j+j*k+k*i)==aa)
                        ctn++;
                    else if((i*i+j*j+k*k+i*j+j*k+k*i)>aa)
                        break;
                }
            }
        }
        cout<<ctn<<endl;
        ctn=0;
    }

    return 0;
}




Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
int main() {
    long test=1;
    // cin>>test;
    while(test--)
    {
	long long n,m,i,j,a,b,c,d,ans=0;
    cin>>n>>m;
    char ch[n+2][m+2];
    for(i=1;i<=n;i++)
    for(j=1;j<=m;j++)
        cin>>ch[i][j];
    for(i=0;i<=n+1;i++)
    {
        for(j=0;j<=m+1;j++)
        {
            if(i==0 || i==n+1 || j==0 || j==m+1)
            cout<<"#";
            else cout<<ch[i][j];
        }
        cout<<endl;
    }
    }
}

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

using namespace std;

// xのn乗のmodでのmodを返す

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    int N,K;
    long long int ans=0;
    cin >> N >> K;
    vector<long long int> A(N);
    COMinit();
    for(int i=0;i<N;i++){
        cin >> A[i];
    }

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

    for(int i=0;i<N;i++){
        ans -= A[i]*COM(N-i-1,K-1);
        ans += A[i]*COM(i,K-1);
        ans %= 1000000007;
    }

    cout << ans%1000000007 << endl;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> Grid;
  int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
  int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
  for (int i = 0; i < H; i++) {
    string tmp;
    cin >> tmp;
    Grid.emplace_back(tmp);
  }

  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (Grid[i][j] == '#') continue;
      int num = 0;
      for(int d = 0; d < 8; d++) {
        int ni = i + dy[d];
        int nj = j + dx[d];
        if(ni < 0 or H <= ni) continue;
        if(nj < 0 or W <= nj) continue;
        if (Grid[ni][nj] == '#') num++;
      }
      Grid[i][j] = char(num + '0');
    }
  }

  //printGrid
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
        cout << Grid[i][j];
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 256
from math import gcd

n=int(input())
mod=10**9+7

d=dict()
zeros=0
for _ in range(n):
  a,b=map(int,input().split())
  if not any((a,b)):
    zeros+=1
    continue
  if all((a,b)):
    g=gcd(a,b)*(a//abs(a))
  elif a:
    g = a
  else:
    g = b
  p=a//g,b//g
  d[p]=d.get(p,0)+1

ans=1
done=set()
for (a,b),v in d.items():
  if (-b,a) in done or (b,-a) in done:
    continue
  done.add((a,b))
  w=d.get((-b,a),0)+d.get((b,-a),0)
  ans *=(pow(2,v)+pow(2,w)-1)
  ans %= mod
print((ans+zeros-1)%mod)



Measured memory_bytes: 71904
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
long long  mod = 1000000007;
int main()
{
	int R, G, B, N;
	cin >> R >> G >> B >> N;
	int count = 0;
	for (int i = 0; i <= N / R; i++) {
		for (int j = 0; j <= (N - R * i) / G; j++) {
			if ((N - R * i - G * j) % B == 0) {
				count++;
			}
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
p = list(map(int, input().split()))


s = sum(p[0:K])
s_max = s

for i in range(N-K):
    s = s -p[i] + p[i+K]

    if s_max < s:
        s_max = s

print((s_max+K)/2)

Measured memory_bytes: 25060
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const long long INFL = 2e18;
const int MOD = 1000000007;
int main(){
	int n;
	cin >> n;
	vector<int> d1(n);
	vector<int> d2(n);

	for(int i = 0;i < n;i++)cin >> d1[i] >> d2[i];

	bool flag = false;
	for(int i = 0;i < n - 2;i++){
		if(d1[i] == d2[i] && d1[i+1] == d2[i+1] && d1[i+2] == d2[i+2]){
			flag = true;
		}
	}

	if(flag)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int a, b, ans = 0;
    cin >> a >> b;
    ans = max({a + b, a - b, a * b});
    cout << ans << endl;
    return 0;
}


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

using namespace std;
using ll = long long;
#define rep(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define REP(i, n) for(ll i = n-1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << " = " << x << endl
#define mp make_pair
#define pb push_back

const long long MOD = 1000000007;
const long long INF = 1LL<<60;


int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    cout << fixed << setprecision(12);

    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import sys

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
 
def gcd_list(li):
	if len(li) > 2:
		x = gcd(li[-1], li[-2])
		li = li[:-2] + [x]
		return gcd_list(li)
	else:
		return gcd(li[0], li[1])


def main():
    a = int(input())
    lists = list(map(int, input().split()))
    score = []

    if len(lists)==1:
        print(lists[0])
        sys.exit()

    bai = gcd_list(lists)

    for i in lists :
        num = bai / i
        score.append(num)

    bunbo = sum(score)

    ans = bai /bunbo
    print(ans)


if __name__ == '__main__' :
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <utility>

using namespace std;

#define REP(i,n) for(int (i)=(0);(i)<(n);++i)
#define ll long long

int main(){
    int n,k;
    string s;
    cin >> n >> k >> s;

    s[k-1]+=32;

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        String s = sc.next();
        char[] cL = new char[n];
        for (int i = 0;i<n; i++) {
            char c = s.charAt(i);
            if (i+1 == k) {
                if (c == 'A') cL[i] = 'a';
                if (c == 'B') cL[i] = 'b';
                if (c == 'C') cL[i] = 'c';
            } else {
                cL[i] = c;
            }
        }
        for (char c : cL) {
            System.out.print(c);
        }
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
using namespace std;
int main() {
    fast();
    // ll t;
    // cin>>t;
    // while(t--)			
    // {
        
    // }
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    ll ans=0,mx=a[0];
    for(int i=1;i<n;i++)
    {
        mx=max(mx,a[i]);
        ans+=abs(mx-a[i]);
    }
    cout<<ans;
}

Measured memory_bytes: 5196
// Problem : A - ∴ (Therefore)
// Contest : AtCoder - AtCoder Beginner Contest 168
// URL : https://atcoder.jp/contests/abc168/tasks/abc168_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//mst,pq,mp,st,q
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;

signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int n;
		cin>>n;
		n = n%10;
		if(n==2||n==4||n==5||n==7||n==9)
		{
			cout<<"hon";
		}
		else if(n==3)
		{
			cout<<"bon";
		}
		else
		{
			cout<<"pon";
		}    	
    }
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cstdio>

#define repi(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,a) repi(i,0,a)

using namespace std;

typedef long long ll;

int H, W;
ll L;
int dx[] = {-1,0,1,0};
int dy[] = {0,-1,0,1};
bool inrange(int x, int y){ return x >= 0 && x < W && y >= 0 && y < H;}

int main(){
    while(cin >> H >> W >> L, H || W || L){
        vector<string> maze(H);
        rep(i,H) cin >> maze[i];
        int x, y, dir;
        rep(i,H)rep(j,W){
            if(maze[i][j] == 'W'){ dir = 0; x = j; y = i; break;}
            else if(maze[i][j] == 'N'){ dir = 1; x = j; y = i; break;}
            else if(maze[i][j] == 'E'){ dir = 2; x = j; y = i; break;}
            else if(maze[i][j] == 'S'){ dir = 3; x = j; y = i; break;}
        }
        int field[128][128][4];
        memset(field,-1,sizeof(field));
        field[y][x][dir] = 0;
        ll turn = 1;
        bool rooped = false;
        while(turn <= L){
            int nx, ny, ndir;
            rep(i,4){
                ndir = (dir+i)%4;
                nx = x + dx[ndir];
                ny = y + dy[ndir];
                if(inrange(nx, ny) && maze[ny][nx] != '#'){
                    x = nx; y = ny; dir = ndir;
                    break;
                }
            }
            if(!rooped && field[y][x][dir] >= 0){
                rooped = true;
                ll roop = turn - field[y][x][dir];
                turn += (L - turn) / roop * roop;
                turn++;
            }
            else{
                field[y][x][dir] = turn;
                turn++;
            }
        }
        cout << y+1 << ' ' << x+1 << ' ';
        cout << (dir==0? 'W': dir==1? 'N': dir==2? 'E': 'S') << endl;
    }
    return 0;
}

Measured memory_bytes: 1512
#include <iostream>
using namespace std;
int main()
{
	for (int i = 1; i <= 9; i++)
	{
		for (int j = 1; j <= 9; j++)
		{
			cout << i << "x" << j << "=" << i * j<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3052
import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    N = NI()
    A = NLI()
    now = 0
    ans = 0
    for a in A:
        if now <= a:
            now = a
        else:
            ans += now - a
    print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 33696
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main(){
  int N, Q;
  while(cin >> N >> Q, N){
    map<int, string> M;
    map<string, int> E;
    string eraname;
    int eb, w;
    for(int i = 0; i < N; ++i){
      cin >> eraname >> eb >> w;
      M[w-eb] = eraname;
      E[eraname] = w;
    }
    for(int i = 0; i < Q; ++i){
      cin >> w;
      int t = 0;
      eraname = "Unknown";
      for(map<int, string>::iterator iter = M.begin(); iter != M.end(); ++iter){
    if(iter->first < w && w <= E[iter->second]){
      eraname = iter->second;
      t = w - iter->first;
    }else if(iter->first >= w) break;
      }
      cout << eraname;
      if(t) cout << " " << t;
      cout << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3388
f=!1;while(n=gets.to_i)>0;f&&puts;f=i=0;puts (1..n).map{t,a,b,c=gets.split;[t,a.to_i*3+c.to_i]}.sort_by{|v|[-v[1],i+=1]}.map{|x|x.join","}.join"\n";end

Measured memory_bytes: 6120
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define IP pair<int,int>
#define enld endl

int main() {
	lint N, K;
	cin >> N >> K;
	vector<lint>A(N);
	rep(i, N) {
		cin >> A[i];
	}
	lint now = 0;
	lint cnt = 0;
	lint first = 0;
	lint end = 0;
	set<lint>S;
	lint a = 0;
	while (1) {
		S.insert(now);
		now = A[now] - 1;
		cnt++;
		if (S.count(now)) {
			end = cnt;
			a = now;
			break;
		}
	}
	//cout << '!' << enld;
	now = 0;
	cnt = 0;
	while (1) {
		if (now == a) {
			first = cnt + 1;
			break;
		}
		now = A[now] - 1;
		cnt++;

	}
	if (K > 1000000) {
		K = (K - (first - 1)) % (end - first + 1) + (first - 1);
	}
	//cout << first << ' ' << end << endl;
	//cout << K << endl;
	now = 0;
	rep(i, K) {
		now = A[now] - 1;
	}
	cout << now + 1 << enld;
}

Measured memory_bytes: 13996
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fs ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll c=0;
vector<ll>a[100001];
ll dp[100001];
ll rec(ll i){
	//cout<<"inside "<<i<<endl;
	if(a[i].size()==0){
		//cout<<"i "<<i<<endl;
		dp[i]=0;
		return 0;
	}
	for(ll j=0;j<a[i].size();j++){
		 //cout<<"dp[a[i][j]] "<<dp[a[i][j]]<<endl;
		if(dp[a[i][j]]==-1)
		   dp[i]=max(dp[i],rec(a[i][j])+1);
		else
		   dp[i]=max(dp[i],dp[a[i][j]]+1);
	}
	//cout<<"returning from i "<<i<<" dp value "<<dp[i]<<endl;
	return dp[i];
 }

int main(){
	ll n,m,x,y,maxi=0;
	cin>>n>>m;
	for(ll i=0;i<m;i++){
		 cin>>x>>y;
		 a[x].pb(y);
	}
	for(ll i=1;i<=n;i++)
	   dp[i]=-1;
	for(ll i=1;i<=n;i++){
		rec(i);
	}
	for(ll i=1;i<=n;i++){
	   //cout<<dp[i]<<endl;
	   maxi=max(maxi,dp[i]);
   }
	cout<<maxi;
}

Measured memory_bytes: 8576
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
static int n = int.Parse(Console.ReadLine());
static long mod = 1000000007;
static List<int>[] nextList = new List<int>[n];//隣接リスト（リストの入った配列）
static long[,] dp = new long[n,2];

	static void Main()
	{
    for(int i = 0; i < n; i++)
    {
      nextList[i] = new List<int>();//リストの宣言
      dp[i,0] = -1;
      dp[i,1] = -1;
    }
    for(int i = 0; i < n-1; i++)
    {
      int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
      nextList[nums[0]-1].Add(nums[1]-1);//隣接リストへ追加。
      nextList[nums[1]-1].Add(nums[0]-1);
    }
    
		Console.WriteLine((DP(0,0)+DP(0,1))%mod);
	}

  static long DP(int vertexNum, int colorNum)
  {
    if(dp[vertexNum,colorNum] != -1) return dp[vertexNum,colorNum];
    
    dp[vertexNum,colorNum] = 1;
    
    if(colorNum == 0)
    {
      for(int i = 0; i < nextList[vertexNum].Count; i++)
      {
        int partnerNum = nextList[vertexNum][i];
        nextList[partnerNum].Remove(vertexNum);//木の逆走を防ぐ
        dp[vertexNum,colorNum] *= (DP(partnerNum,0) + DP(partnerNum,1))%mod;
        dp[vertexNum,colorNum] %= mod;
      }
      //Console.WriteLine(vertexNum+" "+colorNum+" "+dp[vertexNum,colorNum]);
      return dp[vertexNum,colorNum];
    }else
    {
      for(int i = 0; i < nextList[vertexNum].Count; i++)
      {
        int partnerNum = nextList[vertexNum][i];
        nextList[partnerNum].Remove(vertexNum);
        dp[vertexNum,colorNum] *= DP(partnerNum,0);
        dp[vertexNum,colorNum] %= mod;
      }
      //Console.WriteLine(vertexNum+" "+colorNum+" "+dp[vertexNum,colorNum]);
      return dp[vertexNum,colorNum];
    }

    return 0;
  }
}

Measured memory_bytes: 36232
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

// dp[i][j][k]:=r/g/bの最右座標がi/j/kなる場合の数
int dp[310][310][310];
vector<pair<int,int>> v[310];
int main(){
    int n,m; cin>>n>>m;
    rep(i,m){
        int l,r,x; cin>>l>>r>>x;
        v[r].push_back({l,x});
    }
    dp[0][0][0]=1;
    int ans=0;
    for(int r=0;r<=n;r++){
        for(int g=0;g<=n;g++){
            for(int b=0;b<=n;b++){
                int k=max({r,g,b});
                for(auto i:v[k]){
                    int l=i.first,x=i.second;
                    int color=0;
                    if(l<=r) color++;
                    if(l<=g) color++;
                    if(l<=b) color++;
                    if(x==color){
                        // printf("{%d,%d,%d}=%d\n",r,g,b,dp[r][g][b]);
                    }else{
                        dp[r][g][b]=0;
                    }
                }
                if(k==n) (ans+=dp[r][g][b])%=MOD;
                (dp[k+1][g][b]+=dp[r][g][b])%=MOD;
                (dp[r][k+1][b]+=dp[r][g][b])%=MOD;
                (dp[r][g][k+1]+=dp[r][g][b])%=MOD;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 114944
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int n = sc.nextInt();
		int m = sc.nextInt();
		tunnel(n, m);
		sc.close();
	}

	private static void tunnel(int n, int m) {
		int c = m;
		int in = 0;
		int out = 0;
		int max = m;

		for (int i = 0; i < n; i++) {
			in = sc.nextInt();

			out = sc.nextInt();

			c += in - out;

			max = Math.max(max, c);


				if (c < 0) {
					max = 0;
					break;
				}

		}

		System.out.println(max);
	}

}



Measured memory_bytes: 46020
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main(void)
{
	int n, s;
	double sum, ssum, mean_s, mean_ss;

	while(1)
	{
		cin >> n;
		if(n == 0) break;

		sum = ssum = 0;

		for(int i = 0; i < n; i++)
		{
			cin >> s;
			sum += s;
			ssum += s*s;
		}

		mean_s = sum / n;
		mean_ss = ssum / n;

		printf("%.8f\n", sqrt(mean_ss - mean_s * mean_s));
	}

	return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N;
  cin>>N;
  
  vector<vector<int>> vec(N,vector<int> (2));
  for(int i=0;i<N;i++){
    cin>>vec[i][0]>>vec[i][1];
  }
  
  
  int sum=0;
  
  for(int i=0;i<N;i++){
    sum+=vec[i][1]-vec[i][0]+1;
  }
  
  
  cout<<sum<<endl;
}

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

void ID(string a, int n) {
	int ans = 0;
	int par = 0;
	for (int i = 0; i < n; i++) {
		if (a.substr(i,1) == "I") par += 1;
		else par -= 1;

		if (ans < par) ans = par;
	}
	cout << ans << endl;
}
int main() {
	int n; string a;
	cin >> n;
	cin >> a;
	ID(a, n);
}

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

#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>

using namespace std;


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

/*int power(int a,int n)
{
    if(n == 1)return a%mod;
    if(n == 0)return 1;
    if(n&1)return ((a%mod)*(power((a*a)%mod,n>>1))%mod)%mod;
    return power((a*a)%mod,n>>1)%mod;
}
*/
const int md = 998244353;


signed main()
{
    showoff;
    int n,k;
    cin >> n >> k;
    int mi[n+5],h[n+5];
    FOR(i,1,n+1){
    cin >> h[i];
    mi[i] = (int) 1e18;
    }
    mi[1] = 0;
    FOR(i,2,n+1){
    FOR(j,1,k+1){
    if(i-j >= 1)mi[i] = min(mi[i],mi[i-j]+abs(h[i]-h[i-j]));
    }
    }
    cout << mi[n] << "\n";
    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
int main(void)
{
	int x,y;
	while(1){
		scanf("%d %d",&x,&y);
		if(x==0&&y==0){
			break;
		}
		if(x>y){
			printf("%d %d\n",y,x);
		}
		else{
		printf("%d %d\n",x,y);
		}
	}
	return 0;
}



Measured memory_bytes: 2044
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>
#include <climits>
#include <map>
#include <numeric>
#include <functional>
#include <utility>

using namespace std;

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

int main(void) {
  int a, b;
  cin >> a >> b;
  int ans = 0;
  for (int i = 0; i < 2; i++) {
    if (a >= b) {
      ans += a;
      --a;
    }
    else {
      ans += b;
      --b;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

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

    char mat[505][505]{};

    var(int, A, B);
    const int H = 100;
    const int W = 100;
    rep(i, 0, H) rep(j, 0, W) { mat[i][j] = (i < 50) ? '#' : '.'; }

    --A, --B;
    rep(i, 0, H) {
        if (A <= 0) break;
        if (i & 1) continue;
        rep(j, 0, W) {
            if (A <= 0) break;
            if (j & 1) continue;
            mat[i][j] = '.';
            --A;
        }
    }

    repr(i, H - 1, 0) {
        if (B <= 0) break;
        if (!(i & 1)) continue;
        rep(j, 0, W) {
            if (B <= 0) break;
            if (j & 1) continue;
            mat[i][j] = '#';
            --B;
        }
    }

    print(H, W);
    rep(i, 0, H) { print(mat[i]); }

    return 0;
}


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

int main()
{
    int N;
    cin >> N;
    vector<string> S(N);
    bool a = false;

    for (int i = 0; i < N; i++)
    {
        cin >> S.at(i);
    }
    for (int i = 0; i < N; i++)
    {
        if (S.at(i) == "Y")
        {
            a = true;
            break;
        } 
    }
    if (a == true) {
        cout << "Four" << endl;
    } else {
        cout << "Three" << endl;
    }
    
    
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Iterator;

// aoj DSL_1_A
public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Printer pr = new Printer(System.out);

		int n = sc.nextInt();
		int q = sc.nextInt();

		UnionFind uf = new UnionFind(n);

		for (int i = 0; i < q; i++) {
			int com = sc.nextInt();
			int x = sc.nextInt();
			int y = sc.nextInt();
			
			if (com == 0) {
				uf.union(x, y);
			} else {
				if (uf.same(x, y)) {
					pr.println(1);
				} else {
					pr.println(0);
				}
			}
		}

		pr.close();
		sc.close();
	}
	
	@SuppressWarnings("unused")
	private static class UnionFind {
		int[] parent;
		int[] rank;

		UnionFind(int n) {
			parent = new int[n];
			rank = new int[n];
			for (int i = 0; i < n; i++) {
				parent[i] = i;
				rank[i] = 0;
			}
		}
		
		int find(int x) {
			if (parent[x] == x) {
				return x;
			} else {
				return parent[x] = find(parent[x]);
			}
		}
		
		boolean same(int x, int y) {
			return find(x) == find(y);
		}
		
		void union(int x, int y) {
			x = find(x);
			y = find(y);
			if (x != y) {
				if (rank[x] > rank[y]) {
					parent[y] = x;
				} else {
					parent[x] = y;
					if (rank[x] == rank[y]) {
						rank[y]++;
					}
				}
			}

			return;
		}

		// ??°?????????????????°
		int count() {
			int ret = 0;
			for (int i = 0; i < parent.length; i++) {
				if (find(i) == i) {
					ret++;
				}
			}
			
			return ret;
		}
	}

	@SuppressWarnings("unused")
	private static class Scanner {
		BufferedReader br;
		Iterator<String> it;
		
		Scanner (InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}
		
		String next() throws RuntimeException  {
			try {
				if (it == null || !it.hasNext()) {
					it = Arrays.asList(br.readLine().split(" ")).iterator();
				}
				return it.next();
			} catch (IOException e) {
				throw new IllegalStateException();
			}
		}
		
		int nextInt() throws RuntimeException {
			return Integer.parseInt(next());
		}

		long nextLong() throws RuntimeException {
			return Long.parseLong(next());
		}

		float nextFloat() throws RuntimeException {
			return Float.parseFloat(next());
		}

		double nextDouble() throws RuntimeException {
			return Double.parseDouble(next());
		}

		void close() {
			try {
				br.close();
			} catch (IOException e) {
//				throw new IllegalStateException();
			}
		}
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}

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

using ll = long long;
const ll inf = (ll) 1e18;
const ll mod = (ll) 1e9+7;

ll sum(int n)
{
	ll k = n;
	return (k*(k+1))/2;
}

int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	ll ans = 0;
	for(int i = k; i <= n+1; i++) {
		ans += sum(n) - sum(n-i) - sum(i-1)+1;
		ans %= mod;
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 3780
N = int(input())
P = [int(input()) for _ in range(N)]

check = [0] * N

for i in P:
    if check[i-1] == 0:
        if (i-2 >= 0 and check[i-2] == 0) or i == 1:
            check[i-1] = 1
        else:
            check[i-1] = 2
count = 0
ans = 0
for i in range(N):
    if check[i] == 2:
        count += 1
    else:
        ans = max(ans, count)
        count = 1
ans = max(ans, count)

print(N-ans)


Measured memory_bytes: 12624
#include<stdio.h>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{int n,i,j;
long long min,ans;
int a[101];
scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
sort(a+1,a+n+1);
  min=0;
for(i=a[1];i<=a[n];i++)
  { ans=0;
   for(j=1;j<=n;j++)
      ans+=(a[j]-i)*(a[j]-i);
    if(min==0) 
      min=ans;
     if(ans<min) 
    	min=ans;
  }
printf("%lld\n",min);
 } 

Measured memory_bytes: 256
#S, T = map(int, input().split())
S = input()
T = input()

myans = float('INF')
for s in range(len(S) - len(T)+1 ):
    mycnt = 0
    for t in range(len(T)):
        #print(S[s+t], T[t])
        if S[s+t] != T[t]:
            mycnt += 1
    if mycnt < myans:
        myans = mycnt
print(myans)

Measured memory_bytes: 9048
# -*- coding: utf-8 -*-
"""
B - Stone Monument
https://abc099.contest.atcoder.jp/tasks/abc099_b

"""
import sys
from sys import stdin
input = stdin.readline



def solve(a, b):
    diff = b - a
    return (1 + diff) * diff // 2 - b


def main(args):
    a, b = map(int, input().split())
    ans = solve(a, b)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3060
x,k,d=map(int, input().split())
if abs(k*d)>abs(x):
    if k%2==0:
        a=x%(2*d)
        print(min(abs(a),abs(a-2*d)))
    else:
        a=x%(2*d)
        print(min(abs(a-d),abs(a+d)))
else:
    print(abs(x)-abs(k*d))

Measured memory_bytes: 9200
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static class Task {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int num = n % 10;
            if (num == 2 || num == 4 || num == 5 || num == 7 || num == 9) {
                out.println("hon");
            } else if (num == 0 || num == 1 || num == 6 || num == 8) {
                out.println("pon");
            } else {
                out.println("bon");
            }
        }
    }

    private static void sort(double[] arr) {
        Double[] objArr = Arrays.stream(arr).boxed().toArray(Double[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(int[] arr) {
        Integer[] objArr = Arrays.stream(arr).boxed().toArray(Integer[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(long[] arr) {
        Long[] objArr = Arrays.stream(arr).boxed().toArray(Long[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task task = new Task();
        task.solve(1, in, out);
        out.close();
    }

    public static void main(String[] args) {
        new Thread(null, () -> solve(), "1", 1 << 26).start();
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

    }

}

Measured memory_bytes: 33900
import numpy as np

H, W = map(int, input().split())
S = np.array([list(input()) for _ in range(H)]) == '.'

D = np.zeros((H, W), dtype=int)
U = np.zeros((H, W), dtype=int)
L = np.zeros((H, W), dtype=int)
R = np.zeros((H, W), dtype=int)

for h in range(H):
    U[h] = (U[h - 1] + 1) * S[h]
    D[-h - 1] = (D[-h] + 1) * S[-h - 1]
for w in range(W):
    L[:, w] = (L[:, w - 1] + 1) * S[:, w]
    R[:, -w - 1] = (R[:, -w] + 1) * S[:, -w - 1]
print(np.max(U + D + L + R) - 3)

Measured memory_bytes: 219796
#include<bits/stdc++.h>
using namespace std;
/**
******************* Author:Bisnu sarkar ****************************
**/
/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/
#define fRead(x)       freopen(x,"r",stdin)
#define fWrite(x)      freopen (x,"w",stdout)
#define ull            unsigned long long
#define ll             long long
#define pii            pair<int,int>
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';
#define sz(s)          (int)s.size()
#define all(s)         s.begin(),s.end()
#define IO             ios_base::sync_with_stdio(false),cin.tie(NULL);  
#define what_is(x)     cerr << #x << " is " << x << endl;
///*....Debugger....*///
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ", ";
  err(++it, args...);
}
///*....Input....*///
template <typename T> inline void Int(T &n) {
  n = 0; int f = 1; register int ch = getchar();
  for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
  n = n * f;
}
 
template <typename T, typename TT> inline void Int(T &n, TT &m) { Int(n); Int(m); }
template <typename T, typename TT, typename TTT> inline void Int(T &n, TT &m, TTT &l) { Int(n, m); Int(l);}
double ind(){double x; scanf("%lf",&x);return x;}

///*....Bitmask....*///
int set_1(int n,int pos){return n = (n | (1<<pos));}
int reset_0(int n,int pos){return n= n & ~(1<<pos);}
bool check_bit(int n,int pos){return n = n & (1<<pos);}

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

///*....Constraints....*///
const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi=2* acos(0.0);
const double eps=1e-9;


int main()
{
    int t=1,te=0;
    //Int(t);
    while(t--){
        int a;
        Int(a);

        printf("%d\n", a+ a*a + a*a*a );

        //printf("Case %d: ",++te);
    }
    return 0;
}






Measured memory_bytes: 3664
package main

import "fmt"

func main() {
	var s, t []byte
	fmt.Scanf(`%s
%s
`, &s, &t)
	for range s {
		for i := range s[1:] {
			if s[i+1] < s[i] {
				s[i+1], s[i] = s[i], s[i+1]
			}
		}
	}
	for range t {
		for i := range t[1:] {
			if t[i+1] > t[i] {
				t[i+1], t[i] = t[i], t[i+1]
			}
		}
	}
	if Lt(s, t) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func Lt(a, b []byte) bool {
	la, lb := len(a), len(b)
	l := min(la, lb)
	for i := 0; i < l; i++ {
		if a[i] < b[i] {
			return true
		} else if a[i] > b[i] {
			return false
		}
	}
	if la < lb {
		return true
	}
	return false
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,n,m) for(int i=n;i<=m;i++)
#define read(n) cin>>n;
#define write(n) cout<<n;
using namespace std;
int n;
string s;
bool ok(string t)
{
	string r=t;
	reverse(t.begin(),t.end());
	return r==t;
}
int main()
{
	read(s);
	n=s.size();
	if(ok(s)&&ok(s.substr(0,n/2))&&ok(s.substr(n/2+1,n/2)))
		puts("Yes");
	else
		puts("No");
	return 0;
}

Measured memory_bytes: 256