akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
class Main {
     
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        Dice dice1 = new Dice(stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt());
        Dice dice2 = new Dice(stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt());
        boolean a = solv(dice1, dice2, 0);
        System.out.println((a)?"Yes":"No");
    }
    public static boolean solv(Dice f, Dice dice,int count) {
        if(dice.Top == f.Top && dice.S == f.S && dice.Bottom == f.Bottom && dice.E == f.E && dice.N == f.N && dice.W == f.W) return true;
        if(count == 6) return false;
        Dice tmp = new Dice(dice.Top,dice.S,dice.E,dice.W,dice.N,dice.Bottom);
        tmp.TurnN();
        if(solv(f,tmp,count+1)) {
            return true;
        }
        tmp = new Dice(dice.Top,dice.S,dice.E,dice.W,dice.N,dice.Bottom);
        if(solv(f,tmp,count+1)) {
            return true;
        }
        tmp = new Dice(dice.Top,dice.S,dice.E,dice.W,dice.N,dice.Bottom);
        tmp.TurnE();
        tmp = new Dice(dice.Top,dice.S,dice.E,dice.W,dice.N,dice.Bottom);
        tmp.TurnW();
        if(solv(f,tmp,count+1)) {
            return true;
        }
         
        return false;
    }
     
     
     
}
class Dice {
    int Top; //1
    int Bottom; //6
    int N; //   5
    int S; //   2
    int W; //左 4
    int E; //右 3
    Dice(int a, int b, int c, int d, int e, int f) {
        Top = a;
        S = b;
        E = c;
        W = d;
        N = e;
        Bottom = f;
    }
    public void TurnN() {
        int tmp = Top;
        Top = S;
        S = Bottom;
        Bottom = N;
        N = tmp;
    }
    public void TurnW() {
        int tmp = Top;
        Top = E;
        E = Bottom;
        Bottom = W;
        W = tmp;
    }
    public void TurnE() {
        int tmp = Top;
        Top = W;
        W = Bottom;
        Bottom = E;
        E = tmp;
    }
    public void TurnS() {
        int tmp = Top;
        Top = N;
        N = Bottom;
        Bottom = S;
        S = tmp;
    }
     
}


Measured memory_bytes: 26444
#ifndef DEBUG
#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 999999999999971;
const Int INF = 1LL << 61;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

Int Ceil(Int a, Int b) {
    if (a % b == 0) {
        return a / b;
    } else {
        return Floor(a, b) + 1;
    }
}

Int digits(Int n) {
    return (Int)to_string(n).size();
}

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

    const int a = 50000;
    map<int, int> m;
    for (int i = 1; i <= a; i++) {
        m[i * 1080 / 1000] = i;
    }

    int n;
    cin >> n;

    if (m.count(n) == 1) {
        cout << m[n] << endl;
    } else {
        cout << ":(" << endl;
    }

    return 0;
}


Measured memory_bytes: 5992
#include<cstdio>
const int maxn=110,maxm=30,mod=1000000007;
int h,w,k;
int f[maxn][maxm],pl[maxm],*g;
int main() {
	scanf("%d%d%d",&h,&w,&k);
	g=pl+10;
	g[-1]=1,g[0]=1,g[1]=2;
	for(register int i=2;i<=w;++i)g[i]=(g[i-1]+g[i-2])%mod;
	f[h][1]=1;
	for(register int i=h-1;i>=0;--i)for(register int j=1;j<=w;++j)
	f[i][j]=(1ll*f[i+1][j]*g[j-2]%mod*g[w-j-1]+1ll*f[i+1][j-1]*g[j-3]%mod*g[w-j-1]+1ll*f[i+1][j+1]*g[j-2]%mod*g[w-j-2])%mod;
	printf("%d\n",f[0][k]);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(){
	long long n;
	cin >> n;
	int b;
	
	for(long long i=sqrt(n); i>=1; i--){
		if(n%i==0){
			b= n/i;
			break;
		}
	}
	
	cout << int(log10(b))+1 << endl;
	return 0;
}


Measured memory_bytes: 640
A = int(input())
B = int(input())
C = int(input())
X = int(input())
ans = 0
for a in range(A + 1):
  for b in range(B + 1):
    for c in range(C + 1):
      if 500 * a + 100 * b + 50 * c == X: ans += 1
print(ans)

Measured memory_bytes: 3060
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  vi a(4), b(4);
  while (cin >> a[0] >> a[1] >> a[2] >> a[3] >> b[0] >> b[1] >> b[2] >> b[3]) {
    vi c, d;
    int s = 0;
    rep(i, 4) {
      if (a[i] == b[i]) {
        s++;
      } else {
        c.pb(a[i]), d.pb(b[i]);
      }
    }
    vi interset;
    sort(all(c));
    sort(all(d));
    set_intersection(all(c), all(d), back_inserter(interset));
    cout << s << ' ' << interset.size() << endl;
  }
}

Measured memory_bytes: 3072
#include <iostream>
#include <algorithm>
#include <functional>
#include <stdlib.h>

using namespace std;

int main(int argc, char **argv)
{
	int n, tmp, tmp2;
	char *c;
	
	cin >> n;
	for(int i = 0; i < n; i++){
		c = (char *)calloc(8, sizeof(char));
		cin >> c[0] >> c[1] >> c[2] >> c[3] >> c[4] >> c[5] >> c[6] >> c[7];

		sort(c, c+8);
		tmp = atoi(c);
		sort(c, c+8, greater<char>());		
		tmp2 = atoi(c);
		
		cout << (tmp2-tmp) << endl;
		
		free(c);
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void){
    int a[100], n;

    scanf("%d", &n);
    for (int i=0; i<n; i++){
        scanf("%d", &a[i]);
    }
    for (int i=n-1; i>=0; i--){
        printf("%d", a[i]);
        if (i) printf(" ");
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 1028
N, K = map(int, input().split())
routes = list(map(int, input().split()))

otozureta = set([1])
otozureta_list = [1]

import sys
sys.setrecursionlimit(1000000)

def search(list, next):
    if not otozureta.isdisjoint(set([next])):
        return next
    else:
        otozureta.add(next)
        otozureta_list.append(next)
        return search(list, routes[next - 1])


target = search(routes, routes[0])
target_index = otozureta_list.index(target)

otozureta_list_len = len(otozureta_list)
loop_length = otozureta_list_len - target_index
loop_made_length = target_index
#print(otozureta)

if K < otozureta_list_len:
    print(otozureta_list[K])
else:

    print(otozureta_list[loop_made_length + ((K - loop_made_length) % loop_length)])


Measured memory_bytes: 182572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

ll r[4000],g[4000],b[4000];

int main() {
    ll n,ans = 0,ans2 = 0;
    cin >> n;
    char s[n];
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
        if(s[i] == 'R') r[i] = 1;
        if(s[i] == 'G') g[i] = 1;
        if(s[i] == 'B') b[i] = 1;
    }

    // rgb
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if(2*j-i >= 0 && 2*j-i <= n-1) if(r[i] == 1 && g[j] == 1 && b[2*j-i] == 1) ans++;
        }
    }

    // rbg
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if(2*j-i >= 0 && 2*j-i <= n-1) if(r[i] == 1 && b[j] == 1 && g[2*j-i] == 1) ans++;
        }
    }
    // gbr
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if(2*j-i >= 0 && 2*j-i <= n-1) if(g[i] == 1 && b[j] == 1 && r[2*j-i] == 1) ans++;
        }
    }// grb
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if(2*j-i >= 0 && 2*j-i <= n-1) if(g[i] == 1 && r[j] == 1 && b[2*j-i] == 1) ans++;
        }
    }// bgr
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if(2*j-i >= 0 && 2*j-i <= n-1) if(b[i] == 1 && g[j] == 1 && r[2*j-i] == 1) ans++;
        }
    }// brg
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if(2*j-i >= 0 && 2*j-i <= n-1) if(b[i] == 1 && r[j] == 1 && g[2*j-i] == 1) ans++;
        }
    }
    ans /= 2;

    for (int i = 1; i <= n-1; ++i) {
      r[i] += r[i-1];
      g[i] += g[i-1];
      b[i] += b[i-1];
    }

    ans2 = r[n-1]*g[n-1]*b[n-1];
    ans2 -= ans;
    cout << ans2 << endl;
    return 0;
}

Measured memory_bytes: 3692
#include<stdio.h>

int main()
{
	int x, y;
	scanf("%d%d", &x, &y);

	if (x == 2)
		x = 3;
	else if (x == 4 || x == 6 || x == 9 || x == 11)
		x = 2;
	else
		x = 1;

	if (y == 2)
		y= 3;
	else if (y == 4 || y == 6 || y == 9 || y == 11)
		y = 2;
	else
		y = 1;

	if (x == y)
		printf("Yes\n");
	else
		printf("No\n");

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define make_pair mkp
map<int,int> mp;
int main()
{ 
	ll n;
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int a;
		cin>>a;
		mp[a]++;
	}
	for(int i=1;i<=n;i++)
	{
		cout<<mp[i]<<endl;
	}
	return 0;
} 

Measured memory_bytes: 12976
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    a,b,c = LI()
    print(9*max(a,b,c)+a+b+c)
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

#Solve
if __name__ == "__main__":
    A()


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

int main()
{
	long long N;
	cin>>N;
	long long sum=0;
	for(long long i=1;i<=N;i++){
		if((i%3!=0)&&(i%5!=0)){
			sum+=i;
		}
	}
	cout<<sum<<endl;


	return 0;
}


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

int main() {
    int k, a, b;
    cin >> k >> a >> b;
    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}


Measured memory_bytes: 3624
#include<cstdio>
int a[1<<17|1][11],b[41][1<<17|1],i,j,k,n,p=1e9+7,x,y,z;
int main()
{
    scanf("%d%d%d%d",&n,&x,&y,&z),y+=x,z+=y;
    for(i=1;i<=1<<z;i++)
    for(j=1;j<11;j++)
    {
        for(a[i][j]=1,k=0;k+j<=z;k++)
        if((i>>k&1)&&!(k<x&&k+j>x)&&!(k<y&&k+j>y))a[i][j]|=1<<j+k;
        if(a[i][j]>=1<<z||i==1<<z)a[i][j]=1<<z;
    }
    for(b[0][1]=1,i=0;i<n;i++)
    for(j=1;j<=1<<z;j++)
    for(k=1;k<11;k++)
    b[i+1][a[j][k]]=(b[i+1][a[j][k]]+b[i][j])%p;
    printf("%d",b[n][1<<z]);
    return 0;
}

Measured memory_bytes: 26240
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){

    ll N; cin >> N;
    map<string, vpl> m;
    REP(i, N){
        string s; ll p; cin >> s >> p;
        m[s].pb(PL(p, i));
    }
    FORMAP(it, m){
        vpl v = it->ss;
        sort(v.begin(), v.end(), greater<PL>());
        REP(i, v.size()){
            cout << v[i].ss+1 << endstr;
        }
    }
    return 0;
}


Measured memory_bytes: 256
/*
** 本题使用两个stack，一个用来统计总积水，一个用来统计单独的积水面积。
*/

# include <cstdio>
# include <stack>
# include <vector>
using namespace std;

static const int maxn = 20000 + 10;

char buff[maxn];

int main() {
	// freopen("data.in", "r", stdin);
	// freopen("data.out", "w", stdout);
	while (scanf("%s", buff) != EOF) {
		/*
		** ts用来存储每一个'\'字符的位置，然后当出现'/'字符的时候，通过距离计算积水面积
		** ps用来存储每一个'\'所对应的积水面积，默认是0，当出现'/'后，再把面积加进去
		*/
		stack <int> ts, ps;
		int sum = 0;
		for (int i = 0; buff[i] != '\0'; i++) {
			if (buff[i] == 92) { // 92 是 '\'的 ascii码值
				ts.push(i);
				ps.push(0);
			}
			else if (buff[i] == 47 && !ts.empty()) { // 47 是 '/'的 ascii码值
				int s = i - ts.top(); ts.pop();
				sum += s;
				while (ps.top() != 0) {
					s += ps.top();
					ps.pop();
				}
				ps.pop();
				ps.push(s);
			}
		}
		
		printf("%d\n", sum);
		vector <int> v;
		while (!ps.empty()) {
			if (ps.top() != 0)
				v.push_back(ps.top());
			ps.pop();
		}
		if (v.size() == 0)
			printf("0\n");
		else {
			printf("%d ", v.size());
			for (int i = v.size()-1; i > 0; i--)
				printf("%d ", v[i]);
			printf("%d\n", v[0]);
		}
	}
	return 0;
}


Measured memory_bytes: 2892
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

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

    string s;
    cin >> s;
    int n = sz(s);
    const int INF = INT_MAX / 10;
    vi dp(1 << 26, INF), a(n + 1);
    dp[0] = 0;
    rep(i, n)a[i + 1] = a[i] ^ (1<<(s[i] - 'a'));

    vi pal(26 + 1);
    rep(i, 26)pal[i] = 1 << i;
    int ans = 0;
    rep(i, n) {
        int mi = INF;
        each(p, pal) {
            smin(mi, dp[a[i+1]^p] + 1);
        }
        smin(dp[a[i + 1]], mi);
        ans = mi;
    }
    cout << ans << endl;
}


Measured memory_bytes: 263572
import java.util.*;

public class Main{

	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		ArrayList<Integer> kushi = new ArrayList<Integer>();
		int n = scanner.nextInt();

		for(int i=0 ;i<2*n;i++){
			int l = scanner.nextInt();
			kushi.add(l);
		}

		Collections.sort(kushi);
		int sum=0;
		for(int i=0;i<2*n;i=i+2) sum=sum+kushi.get(i);

		System.out.println(sum); 

	}
}

Measured memory_bytes: 10068
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  string S;
  cin>>S;
  
  
  for(int i=0;i<S.size();i+=2){
    cout<<S[i];
  }
  cout<<endl;
}

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

using namespace std;

int h, w, d;
vector<vector<int>> a;

int main() {
	cin >> h >> w >> d;
	a.resize(h);
	for (int i = 0;i < h;i++) {
		a[i].resize(w);
		for (int j = 0;j < w;j++) {
			cin >> a[i][j];
		}
	}

	vector<int> x, y;
	x.resize(h*w + 1);
	y.resize(h*w + 1);
	for (int i = 0;i < h;i++) {
		for (int j = 0;j < w;j++) {
			x[a[i][j]] = i;
			y[a[i][j]] = j;
		}
	}

	vector<int> sum;
	sum.resize(h*w + 1);
	for (int i = 1;i <= h * w;i++) {
		if (i <= d) {
			sum[i] = 0;
		}
		else {
			sum[i] = sum[i - d] + abs(x[i]-x[i-d])+abs(y[i]-y[i-d]);
		}
	}

	int q;
	cin >> q;
	vector<int> l, r;
	l.resize(q);
	r.resize(q);
	for (int i = 0;i < q;i++) {
		cin >> l[i] >> r[i];		
	}
	for (int i = 0;i < q;i++) {
		cout << sum[r[i]] - sum[l[i]]<<endl;
	}

	return 0;
}


Measured memory_bytes: 3328
h, w = gets.split.map(&:to_i)
fld = Array.new(h){ Array.new(w) }
arr = []
h.times do |i|
   str = gets.chomp
   w.times do |j|
    if str[j] == '.'
      fld[i][j] = -1
      arr << [0, [i, j]]
    else fld[i][j] = str[j].to_i
    end
  end
end
ret = 0
until arr.empty?
  cnt, pos = arr.shift
  y, x = pos
  ret = [ret, cnt].max
  (-1..1).each do |i|
    (-1..1).each do |j|
      p = i+y; q = j+x
      next if i == 0 && j == 0 || p < 0 || p >= h || q < 0 || q >= w || fld[p][q] <= 0
      fld[p][q] -= 1
      arr << [cnt+1, [p, q]] if fld[p][q] == 0
    end
  end
end
p ret

Measured memory_bytes: 19432
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    a = [[int(input()), i] for i in range(n)]
    a.sort()
    
    ans = 0
    for i in range(n):
        if i%2 != a[i][1]%2:
            ans += 1
    
    print(ans//2)


if __name__ == "__main__":
    main()


Measured memory_bytes: 24348
#include<bits/stdc++.h>
#include <string>
#define ll long long int
using namespace std;

const int N=10000005;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        ll n;
        cin>>n;
        ll a[n+1]={0};
        ll ans=0;
        for(ll i=1;i<=n;i++)
        {
            for(ll j=i;j<=n;j+=i)
            {
                a[j]++;
            }
        }
        for(ll i=1;i<=n;i++)
        {
            ans+=i*a[i];
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 81764
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,m,i;
    cin>>n>>m;
    
    int h[n],good[n];
    for(i=0; i<n; i++){
        cin>>h[i];
        good[i]=1;
    }
    
    int a,b,bad;
    for(i=0; i<m; i++){
        cin>>a>>b;
        a--;
        b--;
        if(h[a]<h[b]){
            bad=a;
            good[bad]=0;
        }else if(h[a]>h[b]){
            bad=b;
            good[bad]=0;
        }else{
            good[a]=0;
            good[b]=0;
        }
    }
    
    int cntr=0;
    for(i=0; i<n; i++){
        if(good[i]==1)  cntr++;
    }
    cout<<cntr<<endl;
    
    return 0;
}


Measured memory_bytes: 4416
#!/usr/bin/env python
N, M = map(int, input().split())
P = list(map(int, input().split()))
graph = [[] for _ in range(N+1)]
for _ in range(M):
    x, y = map(int, input().split())
    graph[x].append(y)
    graph[y].append(x)

group = [0]*(N+1)
ans = 0
for i,num in enumerate(P,1):
    ex_space = [i]
    for ex_point in ex_space:
        if group[ex_point]:
            continue
        group[ex_point] = i
        ex_space.extend(graph[ex_point])
    ans += (group[num] == group[i])
 
print(ans)

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

int main() {
	int r;
	
	string s;
	
	cin >> s;
	
	int n = s.length();
	
	if(s[0] != 'A'){
		cout << "WA" << endl;
	}else{
		int cntC = 0;
		int cntU = 0;
		
		for(int i = 0 ; i < n ; i++){
			if(s[i] == 'C'){
				cntC++;
			}
			
			if((s[i] & 32) == 0){
				cntU++;
			}
		}
		
		if(cntC > 1 || cntU > 2){
			cout << "WA" << endl;
		}else{
			cntC = 0;
			
			for(int i = 2 ; i < n - 1 ; i++){
				if(s[i] == 'C'){
					cntC++;
				}	
			}
			
			if(cntC){
				cout << "AC" << endl;
			}else{
				cout << "WA" << endl;
			}
		}
	}
	
	return 0;
}

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

#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(v) int(v.size())
#define pii pair<int, int>
#define mp make_pair
#define f first
#define ll long long
#define ld long double
#define s second
#define vec vector<int>

using namespace std;

const int N = (int) 1e5 + 100;
const int M = (int) 1e5 + 100;
const int K = (int) 200;
const int INF = (int) 1e9 + 7;
const int mod = (int) 998244353;
const ld EPS = (ld) 1e-9;
const ll LINF = (ll) 1e18;

int n;
int a[N], b[N];
bool was[N];
vec v[N];

void dfs(int x, int p = -1) {
	vec c;
	for (auto it : v[x]) {
		if (it == p)
			continue;
		dfs(it, x);
		if (!was[it]) {
			c.pb(it);
		}
	}
	if (sz(c) > 1) {
		cout << "First";
		exit(0);
	}
	if (sz(c) == 1) {
		was[x] = 1;
		was[c[0]] = 1;
	}
}

int main() {
	#ifdef sony
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	srand(time(0));
	cin >> n;
	for (int i = 1; i < n; i++) {
		cin >> a[i] >> b[i];
		v[a[i]].pb(b[i]);
		v[b[i]].pb(a[i]);
	}
	dfs(1);
	cout << (was[1] ? "Second" : "First");
	return 0;		
}

Measured memory_bytes: 6656
n=int(input())
a=list(map(int,input().split()))
ans=0
flug=0 #1:<= 2:>=

for i in range(n-1):
    if flug==0:
        if a[i]<a[i+1]:
            flug=1
        elif a[i]>a[i+1]:
            flug=2
        else:
            pass
    elif flug==1:
        if a[i]<=a[i+1]:
            pass
        else:
            ans+=1
            flug=0
    elif flug==2:
        if a[i]>=a[i+1]:
            pass
        else:
            ans+=1
            flug=0

print(ans+1)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, T; cin >> n >> T;

    int res = inf;
    rep(_, n){
        int c, t; cin >> c >> t;
        if(t <= T){
            chmin(res, c);
        }
    }

    if(res == inf){
        cout << "TLE" << endl;
    }
    else {
        cout << res << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
const ll Mod=1e9+7;
ll modinv(ll a,ll m){
   ll b=m,u=1,v=0;
   while(b){
      ll t=a/b;
      a-=t*b;
      swap(a,b);
      u-=t*v;
      swap(u,v); 
   } 
   u%=m;
   if(u<0)
     u+=m;
   return u;
}
int main() {
  int n,b;
  cin >> n >> b;
  int r=n-b;
  ll m,bs=1,rs=1;
  rep(i,b){
    m=modinv(i+1,Mod);
    rs=rs*(r+1-i)%Mod*m%Mod;
    cout<<rs*bs%Mod<<endl;
    bs=bs*(b-1-i)%Mod*m%Mod;
  }
  return 0;
}


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

// syntax sugar: `for (int i = 0; i < N; ++i)`
#define rep(i, N) for (int i = 0; i < (int)(N); ++i)
#define rep2(i, startValue, N) for (int i = (int)(startValue); i < (int)(N); ++i)
// syntax sugar: `for (int i = 0; i < N; ++i)`
#define REP(type, name, beginValue, endCondValue) \
  for (type name = beginValue; name < endCondValue; ++name)
// syntax sugar: 多次元vector
#define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \
    std::vector<std::vector<std::vector<T>>> name(d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue)));
#define VECTOR_DIM2(T, name, d1, d2, initValue) \
    std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue));
#define VECTOR_DIM1(T, name, d1, initValue) \
    std::vector<T> name(d1, initValue);
#define ll long long
#define ld long double
#define DUMP(v) "," #v ":" << v


// 最大公約数
template <typename T>
T greatestCommonDivisor(T m, T n) {
  return m == 0 ? std::abs(n)
	: n == 0 ? std::abs(m)
	: greatestCommonDivisor(n, m % n);
}

// ABC109 C - Skip
int main(){
  ll n, x; // 1e5, 1e9
  cin >> n >> x;
  vector<ll> xn(n + 1, 0);
  rep(i,n) cin >> xn[i];
  xn[n] = x;

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

  set<ll> diffset;
  {
    ll base = xn[0];
    rep2(i,1,n+1) {
      const auto diff = xn[i] - base;
      //cout << "diff: " << diff << endl;
      diffset.emplace(diff);
      base = xn[i];
    }
  }

  /*
  cout << "diffset:";
  for (const auto& elem : diffset) {
    cout << elem << ",";
  }
  cout << endl;
  */

  // diffsetの最大公約数が答え
  ll ans = -1;
  for (const auto& elem : diffset) {
    if (ans == -1) {
      ans = elem;
    } else {
      //cout << "gcd(" << ans << "," <<  elem << ")" << endl;
      ans = greatestCommonDivisor<ll>(ans, elem);
    }
    //cout << "ans=" << ans << endl;
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
    ll X, Y;
    cin >> X >> Y;
    if (abs(X - Y) <= 1) {
        cout << "Brown" << endl;
    } else {
        cout << "Alice" << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

struct TQueue{
  int x,y,dep;
  struct TQueue* next;
};

void allfree(struct TQueue* q){
  struct TQueue* r[2];
  r[0]=q;
  if(q==0)return;
  r[1]=q->next;
  while(r[1]){
    free(r[0]);
    r[0]=r[1];
    r[1]=r[1]->next;
  }
  free(r[0]);
}

struct TQueue* push(struct TQueue* ed,int y,int x,int d){
  if(ed==0){
    return 0;
  }
  ed->next=(struct TQueue*)malloc(sizeof(struct TQueue));
  ed->next->next=0;
  ed->next->dep=d;
  ed->next->x=x;
  ed->next->y=y;
  return ed->next;
}

struct TQueue* Queue(int y,int x,int d){
  struct TQueue* ret;
  ret=(struct TQueue*)malloc(sizeof(struct TQueue));
  ret->next=0;
  ret->x=x;
  ret->y=y;
  ret->dep=d;
  return ret;
}


struct TQueue* delhead(struct TQueue* st){
  struct TQueue* ret;
  if(!st)return 0;
  ret=st->next;
  free(st);
  return ret;
}




int main(){
  int w,h,n;
  int i,j,k;
  char* s;
  int mp[1000][1000];
  int ts[1002][1002];
  int ret,ls,pt;
  int gy[10],gx[10];
  struct TQueue *st,*ed;
  s=(char*)malloc(sizeof(char)*1001);

  gets(s);
  sscanf(s,"%d %d %d",&h,&w,&n);

  for(i=0;i<h;i++){
    gets(s);
    for(j=0;j<w;j++){
      mp[i][j]=s[j]=='X'?1:0;
      if(s[j]>='1'&&s[j]<='9'){
        gy[s[j]-'0']=i+1;
        gx[s[j]-'0']=j+1;
      }
      if(s[j]=='S'){
        gy[0]=i+1;
        gx[0]=j+1;
      }
    }
  }
  for(i=0;i<h+2;i++){
    ts[i][0]=1;
    ts[i][w+1]=1;
  }
  for(j=0;j<w+2;j++){
    ts[0][j]=1;
    ts[h+1][j]=1;
  }
  ret=0;
  for(k=0;k<n;k++){
    st=Queue(gy[k],gx[k],ret);
    ed=st;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
        ts[i+1][j+1]=mp[i][j];
      }
    }

    while(st){
      if(((st->y+1==gy[k+1]||st->y-1==gy[k+1])&&st->x==gx[k+1])
        ||((st->x+1==gx[k+1]||st->x-1==gx[k+1])&&st->y==gy[k+1])){
        break;
      }
      if(ts[st->y+1][st->x]==0){
        ts[st->y+1][st->x]=1;
        ed=push(ed,st->y+1,st->x,st->dep+1);
      }
      if(!ts[st->y-1][st->x]){
        ts[st->y-1][st->x]=1;
        ed=push(ed,st->y-1,st->x,st->dep+1);   
      }
      if(!ts[st->y][st->x-1]){
        ts[st->y][st->x-1]=1;
        ed=push(ed,st->y,st->x-1,st->dep+1);
      }
      if(!ts[st->y][st->x+1]){
        ts[st->y][st->x+1]=1;
        ed=push(ed,st->y,st->x+1,st->dep+1);
      }
      st=delhead(st);
    }
    if(st){
      ret=st->dep+1;
      allfree(st);
    }else{
      printf("Incorrect Data\n");
      return 0;
    }
  }

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

Measured memory_bytes: 8428
n=int(input())
l=list(map(int,input().split()))

l.sort()

ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        if l[i]!=l[j]:
            for k in range(j+1,n):
                if l[i]+l[j]>l[k] and l[i]!=l[k] and l[j]!=l[k]:
                    ans+=1
print(ans)


Measured memory_bytes: 9192
m,n=map(int,input().split())
dt=[]
for i in range(n):
    p,y = map(int, input().split())
    dt+=[[i,p,y,0]]
dt.sort(key=lambda x:(x[1],x[2]))
pi=1
prep=0
for x in dt:
    if prep==x[1]:
        pi+=1
    else:
        pi=1
    x[3]=pi
    prep=x[1]
dt.sort()
for x in dt:
    print(str(x[1]).zfill(6)+str(x[3]).zfill(6))

Measured memory_bytes: 33704
import sys
input = sys.stdin.readline

n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = [list(map(int,input().split())) for _ in range(m)]

a.sort()

count = 0
now = a[0]
for i in a:
    if i == now:
        count += 1
    else:
        bc.append([count, now])
        now = i
        count = 1

bc.append([count,now])
bc.sort(key = lambda x: x[1], reverse = True)

ans = 0
count = 0

for i in range(10**6):
    b,c = bc[i]
    if count < n:
        if count + b < n:
            ans += b * c
            count += b
        else:
            ans += (n - count) * c
            break
    else:
        break

print(ans)


Measured memory_bytes: 43408
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

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;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int r,g,b; cin >> r >> g >> b;
    int a = r*100 + g*10 + b;
    cerr << a << endl;
    if(a%4==0) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 3556
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>
#include <queue>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

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

    string s;
    cin >> s;

    for (int i = 0; i < (a+b); i++)
    {
        if (i == a)
        {
            if (s[i] != '-')
            {
                cout << "No" << endl;
                return 0;
            }
        }
        else
        {
            if (s[i] == '-')
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  string s; cin >>s; int n=s.size(),x=1,ans=0;
  vector<int>v(n+1,0); vector<int>r(2019,0);
  for(int i=1; i<=n; i++){
    v[i]=(v[i-1]+x*(s[n-i]-'0'))%2019;
    x=(x*10)%2019; r[v[i]]++;
  }
  for(int i=0; i<2019; i++) ans+=r[i]*(r[i]-1)/2;
  cout <<ans+r[0];
return 0;}

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

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

Alice = 0
Bob = 0

for x in range(0, len(a), 2):
    Alice += a[x]

for x in range(1, len(a), 2):
    Bob += a[x]

print(Alice - Bob)

Measured memory_bytes: 9100
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*                                                    
      I ♥ CLARICE STARLING...                                                               
        EXPLAINATION BELOW->
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
const ll INF = (ll)2e18 + 77;
void solve()
{
  ll N,i;cin>>N;
  ll ans=0;
  for(i=1;i<=N;i++)
  {
      ll a=i,d=i,last,n;
      last=(N/i)*i;
      n=(last-a)/d+1;
      //cout<<n<<"\n";
      ans+=(n*(a+last)/2);
  }
  cout<<ans<<"\n";
  
}
int main()
{
   fastio
   //Test_cases
   solve();
  return 0;
}
//map<ll,ll,greater<int>> to sort in descending order ,in iterator declaration no greater<int>
//if you want to apply lowerbound on set use s.lower_bound(key),not the one used for vector
// Syntax to create a min heap for priority queue priority_queue <int, vector<int>, greater<int>>; 
//for modinverse use modularexponention(x,M-2,M);
//for "each" subtraction from ans(ans-k) if(ans<0) do ans+=MOD,ans%=MOD
//vector<vector<int>>dp(201,vector<int>(n+1)); A way to initialize vector of vector
//If wrong on pretest 2 means logically wrong


/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/

/* ll n,m,k,i;cin>>n>>m>>k;
   ll A[n],B[m];
   fo(i,0,n)cin>>A[i];
   fo(j,0,m)cin>>B[i];*/

Measured memory_bytes: 3644
s = str(input())
n = int(input())

stat = 0
front = ""
back = ""

for _ in range(n):
    q = input()

    # 反転の場合
    if q[0] == "1":
        stat = (stat + 1) % 2
        continue

    judge = int(q[2])
    if stat == 1:
        if judge == 1:
            judge = 2
        elif judge == 2:
            judge = 1

    if judge == 1:
        front = q[4] + front 

    if judge == 2:
        back = back + q[4]

s = front + s + back
if stat == 1:
    s = s[::-1]

print(s)


Measured memory_bytes: 4416
/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 
                                                           
*/
/* }}} */

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

// #define int long long

/* cpp template {{{ */

/* short */
#define pb push_back
#define mp make_pair
#define print(x) cout << x << '\n'
#define Fi first
#define Se second

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define DEPS(i, a, n) for (int i = (a); i >= n; i--)
#define DEP(i, n) for (int i = (n); i >= 0; i--)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* const */
const int INF = 999999999;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

/* func */
inline bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}
inline bool inside(int y, int x, int H, int W) {return (y >= 0 && x >= 0 && y < H && x < W);}

/* }}} */

int n;
int ans = INF;
int a[21];

void dfs(int A, int B, int x)
{
  if (x == n){
    ans = min(ans, abs(A - B));
    return;
  }
  
  dfs(A + a[x], B - a[x], x + 1);
  dfs(A, B, x + 1);
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  while (cin >> n, n){
    int sum = 0;
    ans = INF;
    REP(i, n) cin >> a[i], sum += a[i];
    dfs(0, sum, 0);
    print(ans);
  }

  return (0);
}

Measured memory_bytes: 1196
n = gets.to_i
x = n.to_s.split("").last.to_i

if x == 2 || x == 4 || x == 5 || x == 7 || x == 9
  puts 'hon'
elsif x == 0 || x == 1 || x == 6 || x == 8
  puts 'pon'
else puts 'bon'
end

Measured memory_bytes: 14284
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            int l = s.length() - 1;
            int n = s.length() - 2;

            String ans = s.charAt(0) + String.valueOf(n) + s.charAt(l);
            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 23124
n, m = gets.chomp.split(' ').map(&:to_i)
a = Array.new(m)
m.times { |i| a[i] = gets.chomp.split(' ').map { |e| e.to_i - 1 } }

adjs = Array.new(n){ [] }
a.each do |ary|
    s, t = ary
    adjs[s].push(t)
    adjs[t].push(s)
end

visiteds = Array.new(n)
ans = 0
n.times do |i|
    next if visiteds[i]
    stack = [i]
    visiteds[i] = true
    numOfGroupMembers = 1
    until stack.empty? do
        h = stack.pop
        adjs[h].each do |f|
            unless visiteds[f] then
                stack.push(f)
                visiteds[f] = true
                numOfGroupMembers += 1
            end
        end
    end
    ans = [ans, numOfGroupMembers].max
end
puts ans


Measured memory_bytes: 40620
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U& u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U& u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
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 (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vi A(N);
	REP(i, N) {
		cin >> A[i];
	}
	int max = A[0], max2 = -1, max_ind = 0;
	FOR(i, 1, N) {
		if (max < A[i]) {
			max = A[i];
			max_ind = i;
		}
		else if(max2 < A[i]){
			max2 = A[i];
		}
	}
	REP(i, N) {
		if (i == max_ind) {
			cout << max2 << endl;
		}
		else {
			cout << max << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 2432
N,K=map(int,input().split())
S=list(input())

if  S[K-1]=='A':
    S[K-1]='a'
elif S[K-1]=='B':
    S[K-1]='b'
elif S[K-1]=='C':
    S[K-1]='c'

print(''.join(S))


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

int dp[400][400][400];

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

  int K;
  cin >> K;

  for (int i = 0; i < s.size(); ++i) {
    dp[i][i][0] = 1;
  }

  int ans = 1;
  for (int d = 1; d < s.size(); ++d) {
    for (int l = 0; l + d < s.size(); ++l) {
      int r = l + d;
      for (int k = 0; k <= K; ++k) {
        if (s[l] == s[r]) {
          dp[l][r][k] = max(dp[l][r][k], dp[l + 1][r - 1][k] + 2);
        } else {
          if (k) dp[l][r][k] = max(dp[l][r][k], dp[l + 1][r - 1][k - 1] + 2);
        }

        dp[l][r][k] = max({dp[l][r][k], dp[l + 1][r][k], dp[l + 1][r - 1][k], dp[l][r - 1][k]});
        ans = max(ans, dp[l][r][k]);
      }
    }
  }

  cout << ans << endl;
}


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

int main() {
    int n, m, a[100000];
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i] %= m;
    }

    map<int, int> rest_num_table;
    rest_num_table[0]++;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        sum = (sum + a[i]) % m;
        rest_num_table[sum]++;
    }

    long long ans = 0;
    for (auto rest_num_i : rest_num_table) ans += 1ll * rest_num_i.second * (rest_num_i.second - 1) / 2;

    cout << ans << endl;
}

Measured memory_bytes: 3584
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll L,R,d;
int main(){
    cin>>L>>R>>d;
    ll cnt=0;
    for(ll i=L;i<=R;i++){
        if(i%d==0)cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

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

class Main {

    public static void main(String[] args) {
	
	Scanner stdin = new Scanner(System.in);
	final int T = stdin.nextInt();

	for ( int t = 0; t < T; t++ ) {
	    final boolean[] b = new boolean[3];
	    int noOfOut = 0;
	    int score = 0;
	    while ( noOfOut < 3 ) {
		final String s = stdin.next();

		if ( "HIT".equals(s) ){
		    if ( b[2] ) {
			b[2] = false;
			score++;
		    }
		    b[2] = b[1];
		    b[1] = b[0];
		    b[0] = true;
		} else if( "HOMERUN".equals(s) ){
		    score++;
		    if ( b[0] ) score++;
		    if ( b[1] ) score++;
		    if ( b[2] ) score++;
		    Arrays.fill(b, false);
		} else if( "OUT".equals(s) ){
		    noOfOut++;
		}
	    }
	    System.out.println(score);
	}	
    }
    
}

Measured memory_bytes: 17196
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<pair<string,int>> p;
    string s;
    for(int i=0;i<n;i++){
        cin>>s;
        bool flag=true;
        for(int j=0;j<p.size();j++){
            if(s==p[j].first){
                p[j].second++;
                flag=false;
            }
        }
        if(flag){
            p.push_back(make_pair(s,1));
        }
    }
    int m;
    cin>>m;
    string t;
    for(int i=0;i<m;i++){
        cin>>t;
        bool flag=true;
        for(int j=0;j<p.size();j++){
            if(t==p[j].first){
                p[j].second--;
                flag=false;
            }
        }
    }
    int maxv=0;
    for(int i=0;i<p.size();i++){
        maxv=max(maxv,p[i].second);
    }
    cout<<maxv<<'\n';
    return 0;
}

Measured memory_bytes: 3664