akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main()
{
    int a,b,c=0;
    char op;
    cin >> a >> op >> b;
    if(op == '+'){
        c= a + b;
    }
    else if(op == '-'){
        c = a - b;
    }
    cout << c << endl;
    return 0;
}

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

vector<int> g[2][200010];
int a[2][200010], visited[2][200010];

void dfs(int i, int v, int k)
{
    a[i][v]=k;
    visited[i][v]=1;
    for(int u: g[i][v]) if (!visited[i][u]) dfs(i, u, k);
}

int main()
{
    int N, K, L; cin>>N>>K>>L;
    while (K--) {
        int p, q; cin>>p>>q;
        --p, --q;
        g[0][p].push_back(q);
        g[0][q].push_back(p);
    }
    while (L--) {
        int p, q; cin>>p>>q;
        --p, --q;
        g[1][p].push_back(q);
        g[1][q].push_back(p);
    }
    int k=0;
    for(int i=0; i<N; ++i) {
        if (!a[0][i]) dfs(0, i, ++k);
        if (!a[1][i]) dfs(1, i, ++k);
    }
    map<pair<int, int>, int> x;
    for(int i=0; i<N; ++i) x[make_pair(a[0][i], a[1][i])]++;

    for(int i=0; i<N; ++i) cout<<x[make_pair(a[0][i], a[1][i])]<<' ';
    cout<<endl;
}


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

int main() {
	int N;
	string S;
	cin >> N >> S;
	int x = 0, max = 0;
	for (int i = 0;i < N;i ++) {
		if (S[i] == 'I') x ++;
		else x --;
		if (x > max) max = x;
	}
	cout << max;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

問題文通りにxを操作しながら、常に最大値を覚えれば良い
*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define deb(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;

typedef long long int ll;
typedef string str;

ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;     
  
    x = x % p;   
    while (y) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;  
        x = (x*x) % p; 
    } 
    return res; 
} 
 
ll nCrModP(ll n, ll r, ll p) 
{ 
    if (!r) 
      return 1; 
  
	ll fac[n+1]; 
   	fac[0] = 1; 
    for (ll i=1 ; i<=n; i++) 
        fac[i] = fac[i-1]*i%p; 
  
    return (fac[n]* power(fac[r], p-2,p) % p * power(fac[n-r], p-2,p) % p) % p; 
}

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

void fast(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main ()
{
	ll t,n,m,k,i,j,z;
	str s;
	cin >> n >> k;
	ll h[55][n+3];
	for(i=0;i<55;i++)
	{
		for(j=0;j<n+2;j++)
		{
			h[i][j]=0;
		}
	}
	ll cnt=0;
	for(i=1;i<=n;i++)
	{
		cin >> h[0][i];
	}
 	i=1;
	while(i<55 && cnt<n)
	{
		cnt=0;
		for(j=1;j<=n;j++)
		{
			z=h[i-1][j];
			t=max(0*z,j-z);

			// deb(t,z,j);
			h[i][t]+=1;
			h[i][j]-=1;
			h[i][j+1]+=1;
			t=min(j+z+1,n+1);
			h[i][t]-=1;
		}
		for(j=1;j<=n;j++)
		{
			h[i][j]+=h[i][j-1];
		}
		for(j=1;j<=n;j++)
		{
			h[i][j]+=1;
			if(h[i][j]==n)
				cnt++;
		}
		i++;
	}
	if(k>=i)
	{
		k=i-1;
	}
	for(i=1;i<=n;i++)
	{
		cout << h[k][i] << " ";
	}
	cout << "\n";
}

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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    string s;
    cin >> s;
    Int n = s.size();
    vector<pair<char, Int>> v;
    char a = s[0];
    Int cnt = 1;
    for (Int i = 1; i < n; i++) {
        if (a == s[i]) {
            cnt++;
        } else {
            v.emplace_back(a, cnt);
            cnt = 1;
            a = s[i];
        }
    }
    if (cnt > 0) {
        v.emplace_back(a, cnt);
    }
    // for (Int i = 0; i < (Int)v.size(); i++) {
    //     cout << v[i].fi << " " << v[i].se << endl;
    // }
    // return 0;
    vector<Int> res(v.size());
    for (Int i = 0; i < (Int)v.size(); i+=2) {
        res[i] = (v[i].se + 1) / 2 + v[i + 1].se / 2;
        res[i + 1] = v[i].se / 2 + (v[i + 1].se + 1) / 2;
    }
    cnt = 0;
    for (Int i = 0; i < n; i++) {
        if (i + 1 < n and s[i] == 'R' and s[i + 1] == 'L') {
            cout << res[cnt] << " " << res[cnt + 1] << " ";
            cnt += 2;
            i++;
        } else {
            cout << "0 ";
        }
    }
    cout << endl;
    return 0;
}

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

int main(){
  int X,k=1;
  cin>>X;
  for(int i=2;i<=X/i;i++){
    int j=i*i;
    for(;j<=X;j*=i){}
    k=max(k,j/i);
  }
  cout<<k<<endl;
}

Measured memory_bytes: 256
from collections import defaultdict

n =int(input())

d = defaultdict(int)

for _ in range(n):
    s = input()
    d[s] += 1

result = sorted(d.items(), key=lambda x: -x[1])

max_val = 0
maxes = []
for r in result:
    if max_val > r[1]:
        break
    else:
        max_val = r[1]
        maxes.append(r[0])

print("\n".join(sorted(maxes)))


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

template<typename T>
T Input()
{
	T value;
	std::cin >> value;
	return value;
}

int main()
{
	std::vector<bool> isPrime(100000001);
	for (auto i = 0; i < 100000000; ++i)
		isPrime[i] = false;

	for (auto i = 3; i <= 100000000; i += 2)
		isPrime[i] = true;

	isPrime[2] = true;

	for (auto i = 3; i*i <= 100000000; i += 2)
		if (isPrime[i] == true)
			for (auto j = i*i; j <= 100000000; j += i)
				isPrime[j] = false;

	int num, count = 0;
	std::vector<int> arr;

	std::cin >> num;

	for (auto i = 0; i < num; ++i)
		arr.push_back(Input<int>());

	for (auto elem : arr)
		if (isPrime[elem])
			++count;

	std::cout << count << "\n";

	return 0;
}

Measured memory_bytes: 13332
import java.util.Scanner;

public class Main{
	public static void main(String[]args){
		Scanner scan = new Scanner(System.in);
		String S = scan.next();
		int time_sec = new Integer(S);
		
		int time_min = time_sec/60;
		int s =time_sec%60;
		
		int h =time_min/60;
		int m =time_min%60;
		
		System.out.println(h + ":" + m + ":" + s);
	}
}

Measured memory_bytes: 17120
import kotlin.math.ceil

fun main() = Thread(null, ::abc173d, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()

@OptIn(ExperimentalStdlibApi::class)
fun abc173d() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map { it.toLong() }

    if (n == 2) return println(aList.max()!!)

    val half = ceil(n.toDouble() / 2).toInt()
    val remHalf = n - half

    val sortedHalf = aList.sortedDescending().take(half)

    val answer = sortedHalf.dropLast(1).sum() +
            sortedHalf.drop(1).take(remHalf - 1).sum() + sortedHalf.last()

    println(answer)
}


Measured memory_bytes: 72368
///A drunk man will find his way home, but a drunk bird may get lost forever...
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef pair <int, int> pii;
#define pb push_back
#define f first
#define s second
#define sz(x) (int)x.size()
const int mx = 2000 * 100 + 5;
int a[mx];
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
 	cout.tie(0);
	int n;
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> a[i];
	if(a[0]){
		cout << -1 << endl;
		return 0;
	}
	int ans = 0;
	for(int i = n - 1; i >= 0; i--){
		if(a[i] + 1 < a[i + 1]){
			cout << -1 << endl;
			return 0;
		}
		if(a[i] + 1 == a[i + 1])
			ans++;
		else
			ans += a[i + 1];
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1e18;

int main() {
  ll n;
  cin>>n;
  ll dp[n+1][3];
  rep(i,n+1)rep(j,3)dp[i][j]=0;
  rep(i,n){
    ll a1,b1,c1;
    cin>>a1>>b1>>c1;
      dp[i+1][0]=max(dp[i+1][0],dp[i][1]+a1);
      dp[i+1][0]=max(dp[i+1][0],dp[i][2]+a1);

      dp[i+1][1]=max(dp[i+1][1],dp[i][0]+b1);
      dp[i+1][1]=max(dp[i+1][1],dp[i][2]+b1);

      dp[i+1][2]=max(dp[i+1][2],dp[i][1]+c1);
      dp[i+1][2]=max(dp[i+1][2],dp[i][0]+c1);
  }
  ll ans=0;
  rep(i,3){
    ans=max(ans,dp[n][i]);
  }
  cout<<ans;
}


Measured memory_bytes: 5948
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <list>
#include <cmath>
using namespace std;
#define rep(i,m,n) for (int i = (int) (m); i < (int) (n); i++)
#define rep1(i,m,n) for (int i = (int) (m); i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
int main(void){
    int N;
    cin>>N;
    if(N%2==0)cout<<N/2<<endl;
    else cout<<N/2+1<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll po[222222];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  vi A(n);
  for(int i=0;i<n;i++){
    cin>>A[i];
    po[A[i]]=i+1;
  }
  set<ll>se;
  se.insert(po[n]);
  se.insert(0);
  se.insert(n+1);
  // for(auto a:se)cout<<a <<" ";
  //cout<<endl;
  ll ans=0;
  for(ll i=n-1;i>=1;i--){
    auto lb = se.lower_bound(po[i]);
    ll num=*lb;
    --lb;
    ll num2=*lb;
    if(num==n+1){
      --lb;
      ll num3=*lb;
      ans+=(num-po[i])*(num2-num3)*i;
    }else if(num2==0){
      //auto lb3=lower_bound(ALL(se),num+1);
      ++lb;
      ++lb;
      ll num3=*lb;
      ans+=po[i]*(num3-num)*i;
    }else{
      --lb;
      ll num4=*lb;
      ++lb;++lb;++lb;
      //auto lb3=lower_bound(ALL(se),num+1);
      ll num3=*lb;
      ans+=(po[i]-num2)*(num3-num)*i;
   
      ans+=(num-po[i])*(num2-num4)*i;
    }
    se.insert(po[i]);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 6528
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
#define PI 3.14159265358979323846264338327950L;
const int INF2 = 1001001001;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;


int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};

const int MAX_N = 110000;

int memo[MAX_N];

int rec(int n) {
	if (n == 0)return 0;
	if (memo[n] != -1)return memo[n];

	int res = n;

	for (int pow6 = 1; pow6 <= n; pow6 *= 6)res = min(res, rec(n - pow6) + 1);

	for (int pow9 = 1; pow9 <= n; pow9 *= 9)res = min(res, rec(n - pow9) + 1);

	return memo[n] = res;
}

int calc(int x) {
	int ret = 0;
	while (x % 2 == 0) {
		x /= 2;
		ret++;
	}

	return ret;
}

int a[12][12];
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);


	int s;
	cin >> s;
	vector<int> data(s);
	rep(i, 0, s) {
		cin >> data[i];

	}
	/*int min = 1;
	rep(i, 0, s) {

		min = lcm(min, data[i]);
	}

	min -= 1;*/

	int ans = 0;

	rep(i, 0, s) {

		ans += data[i] - 1;;
	}

	cout << ans << endl;


}
	

Measured memory_bytes: 256
#include <stdio.h>
#define N 100

int main(void)
{
  char s[N];
  int i, j;

  scanf("%s",s);

  for(i=0; s[i]!='\0';i++);

  for(j=0; j<i;j++)
    s[j] = 'x';

  printf("%s\n", s);

  return 0;
}
    


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef vector<int> vi;
const int inf = 1e9+7;
const int INF = 1e18+7;
int mod = 1e9+7;

int c[2][11], n, k;
void init(int f){
	int s = 0, cnt = 0, nn = n;
	if(f == 1)nn = 7;
	rep(i,nn-2){
		//printf("%lld ", s);
		if(c[f][s])break;
		c[f][s]++;cnt++;
		if(f == 0)s = (s+3*3*7)%11;
		if(f == 1)s = (s+3*3)%11;
	}
	int m = (nn-2)%cnt;
	//printf("%lld\n", cnt);
	rep(i,11)c[f][i] *= (nn-2)/cnt;
	
	s = 0;
	rep(i,m){
		c[f][s]++;
		if(f == 0)s = (s+3*3*7)%11;
		if(f == 1)s = (s+3*3)%11;
	}
	return;
}

signed main(){
	scanf("%lld%lld", &n, &k);
	rep(i,2)init(i);
	int ans = 0;
	rep(i,11)rep(j,11){
		int tmp = c[0][i]*c[1][j];
		//if((i+j+4)%11 == k)printf("%lld\n", tmp);
		if((i+j+4)%11 == k)ans += tmp;
	}
	/*rep(i,2){
		rep(j,11)printf("%lld ", c[i][j]);
		printf("\n");
	}*/
	printf("%lld\n", ans);
	return 0;
}




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

double p[maxn], dp[maxn][maxn] = {};
int n;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> p[i];
    dp[0][0] = 1.00;
    for(int i = 1; i <= n; i++) {
        for(int j = 0; j <= i; j++) {
            dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1.00 - p[i]);
        }
    }
    double ans = 0.00;
    for(int i = n; i > (n / 2); i--) ans += dp[n][i];
    cout << setprecision(10) << ans << '\n';
    return 0;
}


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

int main() {
	int W,H,N;
	int x[110],y[110],e[110];
	cin >> W>> H>> N;
	int num[110][110];
	for(int i=0;i<N;i++) cin >> x[i] >> y[i] >> e[i];
	int a=0,b=W,c=0,d=H;
	for(int i=0;i<N;i++){
		if(e[i]==1)a=max(a,x[i]);
		if(e[i]==2)b=min(b,x[i]);
		if(e[i]==3)c=max(c,y[i]);
		if(e[i]==4)d=min(d,y[i]);
	}
	cout <<max(0,b-a)*max(0,d-c)<<endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

  int n;
  cin >> n;

  for (int i = 0; i <= 50000; ++i) {
    int x = i * 1.08;
    if (x == n) {
      cout << i << '\n';
      return 0;
    }
  }

  puts(":(");

  return (0);
}


Measured memory_bytes: 3620
/*input
5 2
..
#.
..
.#
..
*/
#include<bits/stdc++.h>
using namespace std;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int fast_ex(int a,int n,int m){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= fast_ex(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

int n,m;
const int N = 1001;
int dp[N][N];
int ok[N][N];

void solve(){
	 cin >> n >> m;
	 REP(i,n+1){
	 	REP(j,m+1)dp[i][j] = 0;
	 }
	 RE(i,n){
	 	RE(j,m){
	 		char o;cin >> o;
	 		ok[i][j] = (o == '.');
	 	}
	 }
	 dp[1][1] = 1;
	 RE(i,n){
	 	RE(j,m){
	 		if(ok[i][j]){
	 			if(i == 1 && j == 1)continue;
	 			dp[i][j] = dp[i-1][j] + dp[i][j-1];
	 			dp[i][j] %= MOD;
	 		}
	 	}
	 }
	 cout << dp[n][m];
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;//cin >> t;
  WL(t)solve();
  return 0;
}

Measured memory_bytes: 15872
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), k = in.nextInt(), c = in.nextInt(), pre[] = new int[k + 1], suf[] = new int[k + 1];
        String s = in.next();
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        for (int i = 1; i <= k; i++) {
            int j = 0;
            if (i != 1)
                j = pre[i - 1] + c;
            for (; j < n; j++) {
                if (s.charAt(j) == 'o') {
                    pre[i] = j + 1;
                    break;
                }
            }
        }
        for (int i = k; i > 0; i--) {
            int j = n - 1;
            if (i != k)
                j = suf[i + 1] - 1 - c - 1;
            for (; j >= 0; j--) {
                if (s.charAt(j) == 'o') {
                    suf[i] = j + 1;
                    break;
                }
            }
        }
        for (int i = 1; i <= k; i++) {
            if (pre[i] == suf[i] && pre[i] != 0)
                out.println(pre[i]);
        }
        out.flush();
    }

}


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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,x,t;
  	cin >> n >> x >>t;
  	if (n%x==0) cout << (n/x)*t;
  else{ cout << (n/x+1)*t;
  }
  return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+7;
const int mod =2019;
char a[maxn];
int b[maxn],c[2020];
int  Pow(int a,int b)
{
	 int res=1;
	 while(b){
	  if(b&1)  res=res*a%mod;
	  a=a*a%mod;
	  b>>=1;
	 }
	 return res%mod;
}
int main()
{
	scanf("%s",a+1);
	int n=strlen(a+1);
	for(int i=1;i<=n;i++)
	{
	b[i]=(mod+b[i-1]+(a[i]-'0')*Pow(10,(n-i))%mod)%mod;
	c[b[i]]++;
	} 
   long long sum=0;
   for(int i=0;i<2019;i++)
   	sum+=1ll*c[i]*(c[i]-1)/2;
   if(c[0]) cout<<sum+c[0]<<endl;
   else cout<<sum<<endl;	
	
}

Measured memory_bytes: 4644
#include<iostream>

using namespace std;

typedef struct{
  int win;
  int lose;
  char name;
}Info;

int main(){

  int n;
  while(cin >> n && n){
    Info data[n];
    for(int i = 0; i < n; i++) data[i].lose = data[i].win = 0;

    for(int i = 0; i < n; i++){
      cin >> data[i].name;
      for(int j = 0; j < n-1; j++){
	int num;
	cin >> num;
	if(num == 0) data[i].win++;
	if(num == 1) data[i].lose++;
      }
    }
    
    for(int i = 0; i < n; i++)
      for(int j = 0; j < n-i-1; j++){
	if(data[j].win == data[j+1].win && data[j].lose > data[j+1].lose) swap(data[j],data[j+1]);
	if(data[j].win < data[j+1].win) swap(data[j],data[j+1]);
      }
    for(int i = 0; i < n; i++) cout << data[i].name << endl;
  }
  return 0;
}

Measured memory_bytes: 0
n = int(input())
A = []
ans = 0
for i in range(n):
    x =int(input())
    lists = [list(map(int,input().split())) for j in range(x)]
    A.append(lists)

for i in range(2**n):
    honesty = [0]*n
    for j in range(n):
        if (i>>j) & 1:
            honesty[j] = 1
    true = 1
    for j in range(n):
        if honesty[j] == 1:
            for k in range(len(A[j])):
                x,y = A[j][k]
                if not honesty[x-1] == y:
                    true = 0
                    break
    if true == 1:
        ans = max(ans,sum(honesty))
print(ans)

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

using namespace std;

using ll = long long;

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

    ll a, b, c, k;

    cin >> a >> b >> c >> k;
    if (b <= a && c <= a)
        cout << b + c + pow(2, k) * a << endl;
    else if (c <= b)
        cout << c + a + pow(2, k) * b << endl;
    else
        cout << a + b + pow(2, k) * c << endl;

    return 0;
}


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

struct s {
	char a[6];
	s() {
		for(int i = 0; i < 6; i++)
			a[i] = 0;
	}
	bool operator==(const s & obj) const {
		bool res = true;
		for(int i = 0; i < 6; i++) {
			res &= a[i] == obj.a[i];
		}
		return res;
	}
	bool operator<(const s & obj) const {
		for(int i = 0; i < 6; i++) {
			if(a[i] < obj.a[i])
				return true;
			else if(a[i] > obj.a[i])
				return false;
		}
		return false;
	}
};

int main() {
	int n;
	while(cin >> n, n) {
		vector
 v;
		vector<int> in;
		int sum = 0;
		for(int i = 0; i < n; i++) {
			int tmp;
			cin >> tmp;
			in.push_back(tmp);
			sum += tmp;
		}
		sort(in.rbegin(), in.rend());
		v.push_back(s());
		int res = 0;
		for(int k = 0; k < in.size(); k++) {
			int m;
			vector
 nex;
			m = in[k];
			for(int i = 0; i < v.size(); i++) {
				res = max(res, (int)v[i].a[5]);
				if(res - v[i].a[5] > sum / 10)
					continue;
				for(int j = 0; j + m <= 10; j++) {
					s p = v[i];
					if(j == 0)
						;
					else if(j <= 5) {
						if(p.a[j-1] <= 0)
							continue;
						p.a[j-1]--;
					}
					else {
						if(p.a[10-j-1] >= 0)
							continue;
						p.a[10-j-1]++;
					}

					if(j+m <= 5) {
						p.a[j+m-1]++;
					}
					else if(j+m < 10) {
						p.a[10-(j+m)-1]--;
					}
					else {
						p.a[5]++;
					}
//					cout << j + m << endl;
					nex.push_back(p);
				}
			}
			sort(nex.begin(), nex.end());
			nex.erase(unique(nex.begin(), nex.end()), nex.end());
			v = nex;
			sum -= in[k];
		}
		for(int i = 0; i < v.size(); i++) {
			res = max(res, (int)v[i].a[5]);
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 4304
using System;
using System.Collections.Generic;
class Program{
	static List<long[]>[] li;
	static long[] h;
	static void Main(){
		int n=int.Parse(Console.ReadLine());
		h=new long[n+1];
		li=new List<long[]>[n+1];
		for(int i=1;i<=n;i++){
			li[i]=new List<long[]>();
			h[i]=-1;
		}
		for(int i=0;i<n-1;i++){
			long[] q=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
			li[q[0]].Add(new long[]{q[1],q[2]});
			li[q[1]].Add(new long[]{q[0],q[2]});
		}
		long[] s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
		fu(s[1],0);
		for(int i=0;i<s[0];i++){
			long[] q=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
			Console.WriteLine("{0}",h[q[0]]+h[q[1]]);
		}
	}
	static void fu(long n,long k){
		h[n]=k;
		for(int i=0;i<li[n].Count;i++){
			if(h[li[n][i][0]]==-1){
				fu(li[n][i][0],k+li[n][i][1]);
			}
		}
	}
}

Measured memory_bytes: 46348
/*
gcc compile command
gcc a.c -o a
*/

/* Includes */
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

/* Defines */
#define MAX_MOJISU (101)

/* Prototypes */
int func_judge(void);
int func_calc_rank(char val1);

/* Valuables */
int num_card;

char moji_taro[MAX_MOJISU];
char moji_hanako[MAX_MOJISU];
char dictionary[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

int result;

int point_taro;
int point_hanako;

/* Main */
int main ()
{  
    /* カードの枚数取得 */
    scanf("%d", &num_card);

    for (int i = 0; i < num_card; i++) {

        /* i回目のカード取得 */
        scanf("%s %s", moji_taro, moji_hanako);

        /* 勝敗の判断 */
        /* 1; Taro Win, 0; Draw, -1; Hanako Win */
        result = func_judge();

        /* ポイントの加算 */
        if (result == 1) {
            point_taro += 3;
        }
        else if (result == -1) {
            point_hanako += 3;
        }
        else if (result == 0) {
            point_taro ++;
            point_hanako ++;
        }
        else {
            /* NOP */
        }
	}

    /* 結果出力 */
    printf("%d %d\n", point_taro, point_hanako);
}

/* Sub */
/*
    param[in]       void
    param[out]      f_result        (1; Taro Win, 0; Draw, -1; Hanako Win) 
*/
int func_judge(void)
{
    int f_result;
    int f_hikaku_kaisu;

    int f_mojisu_taro;
    int f_mojisu_hanako;
    int f_moji_rank_taro;
    int f_moji_rank_hanako;

    /* 文字数取得 */
    f_mojisu_taro = strlen(moji_taro);
    f_mojisu_hanako = strlen(moji_hanako);

    /* 比較回数検討 */
    if (f_mojisu_taro <= f_mojisu_hanako) {
        f_hikaku_kaisu = f_mojisu_taro;
    }
    else {
        f_hikaku_kaisu = f_mojisu_hanako;
    }

    /* 比較検討1 */
    for (int i = 0; i < f_hikaku_kaisu; i++) {
        f_moji_rank_taro = func_calc_rank(moji_taro[i]);
        f_moji_rank_hanako = func_calc_rank(moji_hanako[i]);

        if (f_moji_rank_taro > f_moji_rank_hanako) {
            return (1);
        }
        else if (f_moji_rank_taro < f_moji_rank_hanako) {
            return (-1);
        }
        else {
            /* NOP */
        }
    }

    /* 比較検討2 */
    if (f_mojisu_taro > f_mojisu_hanako) {
        f_result = 1;
    }
    else if (f_mojisu_taro < f_mojisu_hanako) {
        f_result = -1;
    }
    else {
        f_result = 0;
    }

    return f_result;
}

/*
    param[in]       moji
    param[out]      f_moji_rank
*/
int func_calc_rank(char moji)
{
    int f_moji_rank;

    for (int i = 0; i < 26; i++) {
        if (moji == dictionary[i]) {
            f_moji_rank = i;
            break;  
        }
        else {
            /* NOP */
        }
    }

    return f_moji_rank;
}


Measured memory_bytes: 2096
/**
*    author:  souzai32
*    created: 07.08.2020 23:51:01
**/

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

int main() {

    int n,m;
    cin >> n >> m;
    vector<bool> p(n);
    vector<int> ball(n,1);
    p.at(0)=true;
    int x,y;
    rep(i,m){
        cin >> x >> y;
        x--;
        y--;
        if(p.at(x)) p.at(y)=true;
        ball.at(x)--;
        ball.at(y)++;
        if(ball.at(x)==0) p.at(x)=false;
    }

    int count=0;
    rep(i,n) if(p.at(i)) count++;

    cout << count << endl;

    return 0;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll N,ans;
int main(){
    
    scanf("%lld",&N);
    for (ll i = 1; i < N; i++)
    {
        ans += i;
    }
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 256
#region using
using System;
using System.Collections.Generic;
using System.Linq;
using IEnumerable = System.Collections.IEnumerable;
using IEnumerator = System.Collections.IEnumerator;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;
using TextReader = System.IO.TextReader;
using System.Text;
#endregion

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            return Math.Abs(consoleReader.Long - consoleReader.Long) > 1 ? "Alice" : "Brown";
        }


        #region いつもの
#pragma warning disable
        private ConsoleReader consoleReader;
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program(new ConsoleReader(Console.In)).Calc()); static string AllLines<T>(IEnumerable<T> source) => string.Join("\n", source);
    }
    static class Ext
    {
        public static Dictionary<TKey, int> GroupCount<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) => source.GroupBy(keySelector).ToDictionary(g => g.Key, g => g.Count());
        public static Dictionary<TKey, int> GroupCount<TKey>(this IEnumerable<TKey> source) => source.GroupCount(i => i);
    }
    public class ConsoleReader { private string[] ReadLineSplit() => textReader.ReadLine().Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries); private string[] line = Array.Empty<string>(); private int linePosition; private TextReader textReader; public ConsoleReader(TextReader tr) { textReader = tr; } public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public string String { get { if (linePosition >= line.Length) { linePosition = 0; line = ReadLineSplit(); } return line[linePosition++]; } } public class SplitLine { private string[] splited; public SplitLine(ConsoleReader cr) { splited = cr.ReadLineSplit(); cr.line = Array.Empty<string>(); } public int[] Int => String.Select(x => int.Parse(x)).ToArray(); public int[] Int0 => String.Select(x => int.Parse(x) - 1).ToArray(); public long[] Long => String.Select(x => long.Parse(x)).ToArray(); public double[] Double => String.Select(x => double.Parse(x)).ToArray(); public string[] String => splited; } public SplitLine Split => new SplitLine(this); public class RepeatReader : IEnumerable<ConsoleReader> { ConsoleReader cr; int count; public RepeatReader(ConsoleReader cr, int count) { this.cr = cr; this.count = count; } public IEnumerator<ConsoleReader> GetEnumerator() => Enumerable.Repeat(cr, count).GetEnumerator(); System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator(); public IEnumerable<string> String => this.Select(cr => cr.String); public IEnumerable<int> Int => this.Select(cr => cr.Int); public IEnumerable<int> Int0 => this.Select(cr => cr.Int - 1); public IEnumerable<long> Long => this.Select(cr => cr.Long); public IEnumerable<double> Double => this.Select(cr => cr.Double); } public RepeatReader Repeat(int count) => new RepeatReader(this, count); }
    #endregion
}


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

int main()
{
	int x, a, b;
	cin >> x >> a >> b;
	if (b - a <= 0) {
		cout << "delicious" << endl;
	}
	else if (b - a < x+1) {
		cout << "safe" << endl;
	}
	else {
		cout << "dangerous" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define PI 3.141592653

void solve() 
{
    char s[200];
    int n,k;
    scanf("%d",&k);
    scanf("%s",&s);
    if(strlen(s)<=k){
        printf("%s",s);
    }
    else{
        s[k]='.';s[k+1]='.';s[k+2]='.';s[k+3]='\0';
        printf("%s\n",s);
    }
    
    
}  
int main(){
    int t;
    // scanf("%d",&t);
    // while(t--){
        solve();
    // }
    return 0;
}

Measured memory_bytes: 1736
typedef struct {
    char name[100];
    int t;
} data;
   
data array[100001];
int head=0,tail=0;


int main(void){
	int N,q,i,sum=0,cnt=0;
	scanf("%d %d",&N,&q);
	for(i=0;i<N;i++){
		scanf("%s %d",array[i].name,&array[i].t);
	}
	while(cnt!=N){
		if(q<array[head].t){
			array[head].t=array[head].t-q;
			sum+=q;
			array[tail]=array[head];
			if(tail==N-1) tail=0;
			else tail++;
		}
		else if(array[head].t!=0){
			sum+=array[head].t;
			array[head].t=0;
			printf("%s %d\n",array[head].name,sum);
			cnt++;
		}
		if(head==N-1) head=0;
		else	head++;
	}
    return 0;
}



Measured memory_bytes: 6848
#include<cstdio>
#include<algorithm>
using namespace std;
long long a[200005];
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    long long ans=0;
    sort(a,a+n);
    for(int i=n-1-k;i>=0;i--)
    {
        ans+=a[i];
    }
    printf("%lld",ans);
}


Measured memory_bytes: 1664
#include <cstdio>

const int maxn = 2010, mod = 924844033;

int n, m, K, ans, fac[maxn];
bool f[maxn << 1];
int dp[maxn << 1][maxn][2];

int main() {
	scanf("%d%d", &n, &K);
	fac[0] = 1;
	for (int i = 1; i <= n; ++i) {
		fac[i] = 1ll * fac[i - 1] * i % mod;
	}
	for (int i = 1; i <= K; ++i) {
		f[++m] = 1;
		for (int x = i + K; x <= n; x += K) {
			++m;
		}
		f[++m] = 1;
		for (int x = i + K; x <= n; x += K) {
			++m;
		}
	}
	dp[0][0][0] = 1;
	for (int i = 1; i <= m; ++i) {
		if(f[i]) {
			for (int j = 0; j <= n; ++j) {
				dp[i][j][0] = (dp[i - 1][j][0] + dp[i - 1][j][1]) % mod;
				dp[i][j][1] = 0;
			}
		}
		else {
			for (int j = 1; j <= n; ++j) {
				dp[i][j][1] = dp[i - 1][j - 1][0];
			}
			for (int j = 0; j <= n; ++j) {
				dp[i][j][0] = (dp[i - 1][j][0] + dp[i - 1][j][1]) % mod;
			}
		}
	}
	for (int i = 0; i <= n; ++i) {
		int x = 1ll * fac[n - i] * (dp[m][i][0] + dp[m][i][1]) % mod;
		if(i & 1) {
			(ans += mod - x) %= mod;
		}
		else {
			(ans += x) %= mod;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 62976
// -----------------------------------
// Author     : MatsuTaku
// Country    : Japan
// Created    : 05/03/20 20:34:41
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  vector<ll> pf(1001);
  for (ll n = -500; n <= 500; n++) {
    pf[n+500] = n*n*n*n*n;
  }
  ll x; cin>>x;
  auto solve = [&]() {
    for (int i = -500; i <= 500; i++) {
      for (int j = -500; j <= 500; j++) {
        if (pf[i+500]-pf[j+500] == x) {
          return make_pair(i,j);
        }
      }
    }
  };
  auto [a,b] = solve();
  cout << a << " " << b << endl;

  return 0;
}


Measured memory_bytes: 3660
/*入力として与えられた整数の集合に含まれる素数の個数の求めるプログラム*/
#include <stdio.h>
#include <math.h>

int isPrime(int);

int main()
{
  int num, n, i, count_pn = 0;

  scanf("%d", &n);
  
  for( i = 0; i<n; i++ )
    {
      scanf("%d", &num);
      count_pn += isPrime(num);
    }

  printf("%d\n", count_pn);

  return 0;
}

/*引数xが素数かどうか判定するプログラム
  戻り値 TRUE 1  FALSE 0*/
int isPrime(int x)
{
  int i;
  double route_x = sqrt(x);
  
  if( x<= 1 )
    return 0;

  for( i = 2; i<=route_x; i++ )
    {
      if( x%i == 0 )
	return 0;
    }
  return 1;
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int  a[N],flag[N];
int main()
{
	cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
	for(int i=0;i<9;i++)cin>>a[i];
	int n;
	cin>>n;
	int x;
	for(int i=0;i<n;i++)
	{
		cin>>x;
		for(int j=0;j<9;j++)
			if(a[j]==x)flag[j]=1;
	}
	if(flag[0]==1&&flag[1]==1&&flag[2]==1){cout<<"Yes";return 0;}
	if(flag[3]==1&&flag[4]==1&&flag[5]==1){cout<<"Yes";return 0;}
	if(flag[6]==1&&flag[7]==1&&flag[8]==1){cout<<"Yes";return 0;}
	if(flag[0]==1&&flag[3]==1&&flag[6]==1){cout<<"Yes";return 0;}
	if(flag[1]==1&&flag[4]==1&&flag[7]==1){cout<<"Yes";return 0;}
	if(flag[2]==1&&flag[5]==1&&flag[8]==1){cout<<"Yes";return 0;}
	if(flag[0]==1&&flag[4]==1&&flag[8]==1){cout<<"Yes";return 0;}
	if(flag[2]==1&&flag[4]==1&&flag[6]==1){cout<<"Yes";return 0;}
	cout<<"No";
		return 0;
}


Measured memory_bytes: 256
#include<cstdio>                                                                                   
#include<cstring>                                                                                  
#include<algorithm>                                                                                
#include<vector>                                                                                   
using namespace std;                                                                               

int n;                                                                                             
vector<int> G[100];                                                                              
bool D[100];                                                                                       
int r,k;

void solve(int m)
{
    D[m]=1;
    r=max(r,++k);
    for(vector<int>::iterator it=G[m].begin();it!=G[m].end();it++){                              
        if(!D[*it]){                                                                               
            solve(*it);                                                                 
        }                                                                                          
    }                                                                                              
    --k;
    D[m]=0;
}                                                                                                  

int main()
{
    for(int i=0;i<100;i++)G[i].reserve(100);
    while(scanf("%d",&n),n){
        r=0;
        for(int i=0;i<100;i++)G[i].clear();
        while(n--){
            int a,b;
            scanf("%d%d",&a,&b);
            G[a-1].push_back(b-1);
            G[b-1].push_back(a-1);
        }
        for(int i=0;i<100;i++){
            solve(i);
        } 
        printf("%d\n",r);
    }
}

Measured memory_bytes: 848
// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬████╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<vector<P> > Graph;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  int n;
  while(cin >> n, n){
    vector<int> a(n);
    REP(i,n) cin >> a[i];

    sort(a.begin(),a.end());
    cout << (accumulate(a.begin(),a.end(),0LL) - a[0] - a[n-1])/(n-2) << endl;
  }

  return 0;
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;
int N, M;
vector<vector<bool>> bridge(51, vector<bool>(51, false));
vector<bool> visited(N, false);

void can_visit(int k, vector<bool> &V);

int main(){
  
  cin >> N >> M;
  
  //辺のグラフを作る 
  rep(i, M){
    int a, b;
    cin >> a >> b;
    bridge[a][b] = true;
    bridge[b][a] = true;
  }
  
  //橋かどうか判断する
  int counter = 0;
  for(int i = 1; i <= N; i++){
    for(int j = i+1; j <= N; j++){
      //ijが辺のとき
      if(bridge[i][j]){
        bridge[i][j] = false;//一旦取り除く
        bridge[j][i] = false;
        
        vector<bool> visited(N, false);
        
        //再起関数を実装する
        can_visit(1, visited);
        bool x = true;
        for(int k = 0; k < N; k++){
          //cout << visited[k];
          if(!visited[k]){
            x = false;
          }
        }
        
        if(x){
          counter++;
        }
        
        bridge[i][j] = true;//もとに戻す
        bridge[j][i] = true;
      }
      
      //ijが辺じゃないとき
      else{
        continue;
      }
      
      //cout << endl;
    }
  }
  cout << M-counter << endl;
}
 //kから行けるすべてのマスをtrueにする
void can_visit(int k, vector<bool> &V){
 
  if(V[k-1]) return;
  // cout << k;
  V[k-1] = true;

  
  for(int l= 1; l<=N; l++){
    if(bridge[k][l]){
       can_visit(l, V);
    }
  }
  
 return;
}



      
    



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[2002][2002];
int b[2002][2002];
char s[4];

inline int f(int (*d)[2002], int sx, int sy, int ex, int ey){
	return d[ex][ey]-d[ex][sy]-d[sx][ey]+d[sx][sy];
}

int main(){
	int i,j,n,m,t,r=0;
	scanf("%d%d",&n,&m);
	while(n--){
		scanf("%d%d%s",&i,&j,&s);
		if(s[0]=='W') a[i%(m+m)+1][j%(m+m)+1]++;
		else b[i%(m+m)+1][j%(m+m)+1]++;
	}
	for(i=1;i<=m+m;i++) for(j=1;j<=m+m;j++){
		a[i][j]+=a[i-1][j]+a[i][j-1]-a[i-1][j-1];
		b[i][j]+=b[i-1][j]+b[i][j-1]-b[i-1][j-1];
	}
	for(i=1;i<=m;i++) for(j=1;j<=m;j++){
		t=f(a,0,0,i,j)+f(b,i,0,i+m,j)+f(a,i+m,0,m+m,j)+f(b,0,j,i,j+m)+f(a,i,j,i+m,j+m)+f(b,i+m,j,m+m,j+m)+f(a,0,j+m,i,m+m)+f(b,i,j+m,i+m,m+m)+f(a,i+m,j+m,m+m,m+m);
		if(t>r) r=t;
		t=f(b,0,0,i,j)+f(a,i,0,i+m,j)+f(b,i+m,0,m+m,j)+f(a,0,j,i,j+m)+f(b,i,j,i+m,j+m)+f(a,i+m,j,m+m,j+m)+f(b,0,j+m,i,m+m)+f(a,i,j+m,i+m,m+m)+f(b,i+m,j+m,m+m,m+m);
		if(t>r) r=t;
	}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 31488
n,m=map(int,input().split())
L=[list(map(int,input().split())) for _ in range(m)]
 
lm=0
rm=float('inf')
for i in range(m):
      lm=max(L[i][0],lm)
      rm=min(L[i][1],rm)
print(max(0,rm-lm+1))

Measured memory_bytes: 27332
#import pysnooper
import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy
setrecursionlimit(10**6)
input=stdin.readline

n=int(input().rstrip())
a=sorted([list(map(int,input().rstrip().split())) for _ in range(n)],key=lambda x:-x[2])
c=a[1:]
x,y,h=a[0]
for cx in range(101):
    for cy in range(101):
        H=h+abs(x-cx)+abs(y-cy)
        for i in c:
            nh=max(0,H-abs(i[0]-cx)-abs(i[1]-cy))
            if nh!=i[2]:
                break
        else:
            print(cx,cy,H)
            exit()

Measured memory_bytes: 3836
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 22 20:52:29 2020

@author: H_Hoshigi
"""

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

P = sum(X_list) // N

cost_list_1 = [(Xi-P)**2 for Xi in X_list]
cost_list_2 = [(Xi-(P+1))**2 for Xi in X_list]

print(min(sum(cost_list_1),sum(cost_list_2)))


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

using namespace std;

int main()
{
    long long a,b,c;
    cin >> a >> b;
    c=a*b;
    if(a==b)
    {
        cout << 0 << endl;
    }
    else if(a==0)
    {
        if(b<0)
        {
            cout << -1*b+1 << endl;
        }
        else
        {
            cout << b << endl;
        }
    }
    else if(b==0)
    {
        if(a>0)
        {
            cout << a+1 << endl;
        }
        else
        {
            cout << -1*a << endl;
        }
    }
    else if(b>a && c>0)
    {
        cout << b-a << endl;
    }
    else if(a>b && c>0)
    {
        cout << a-b+2 << endl;
    }
    else if(c<0)
    {
        cout << abs(abs(a)-abs(b))+1 << endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int n; cin >> n;
	priority_queue<int> que;
	for (int i=0; i<n; i++) {
		int a; cin >> a;
		que.push(a);
	}
	int a = 0;
	int b = 0;
	for (int i=0; i<n; i++) {
		int now = que.top();
		que.pop();
		if (i%2==0) a += now;
		else b += now;
	}
	cout << a - b << endl;
	return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

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

int main(){
  string s; cin >> s;
  int d; cin >> d;
  for(int i = 0; i < (int)s.size(); i+=d)cout << s[i];
  cout << endl;
}



Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    private final static String NEG = "NO\n";

    private final static String AFF = "YES\n";

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(
                new InputStreamReader(System.in), 1024);
        int number = Integer.parseInt(br.readLine());
        int sides[] = new int[3];
        StringTokenizer tknz;
        StringBuilder builder = new StringBuilder();

        for (; 0 < number; number--) {
            tknz = new StringTokenizer(br.readLine());
            for (int i = 0; i < 3; i++) {
                sides[i] = Integer.parseInt(tknz.nextToken());
            }
            Arrays.sort(sides);
            if (sides[1] % 2 != 0) {
                builder.append(NEG);
            } else if (sides[0] * sides[1] * sides[2] % 60 != 0) {
                builder.append(NEG);
            } else if (Math.pow(sides[0], 2) + Math.pow(sides[1], 2) != Math
                    .pow(sides[2], 2)) {
                builder.append(NEG);
            } else {
                builder.append(AFF);
            }
        }
        System.out.print(builder);
    }
}

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



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

Measured memory_bytes: 3632