akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <stdio.h>
using namespace std;

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

vector<bool> eratosthenes(int n) {
	vector<bool> prime(n + 1);
	for (int i = 2; i <= n; i++) {
		prime[i] = true; // 初期化
	}
	prime[0] = prime[1] = false;
	for (int i = 2; i*i <= n;i++) {
		if (prime[i]) {
			for (int j = i * 2; j <= n; j += i) {
				prime[j] = false;
			}
		}
	}
	return prime;
}
int n, m,p[29], ans = 0,a[29], b[29];
const int nmax = 8;
bool graph[nmax][nmax];
/**
 * pos個は決定済み
 * mask 残に置く数の集合を表すビット配列
 */
void dfs(int pos, int mask) {
//	cout << "pos=" << pos << ",mask=" << mask << endl;
	if (pos == n) { // posが最後までいった
//		cout << p[0] << p[1] << p[2] << endl;
		ans++;
		return;
	}
	REP(i, n) {
		if (mask  & (1 << i)) { // 残の中にiが残っている場合
//			cout << "mask=" << mask << ",1<<" << i << "="  << (1 << i) << "=true" << endl;
			p[pos] = i; // 配列のPOS位置を0～nまでループ
			if (p[0] != 0)continue;
			if (pos > 0 && graph[p[pos - 1]][p[pos]] == false) {
				//				cout << "pos=" << pos << "," << p[0] << p[1] << p[2] << ",graph[" << p[pos - 1] << "][" << p[pos] << "]=false" << endl;
				continue;
			}
			dfs(pos + 1, (mask ^ (1 << i))); // 配列のPOS位置を進める,排他的論理和でフラグを下ろす
		}
		else {
//			cout << "mask=" << mask << ",1<<" << i << "=" << (1 << i) << "=false" << endl;
		}
	}
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	scanf("%d %d", &n ,&m);

	REP(i, m) {
		scanf("%d %d",&a[i], &b[i]);
		p[i] = i;
		graph[a[i] - 1][b[i] - 1] = graph[b[i] - 1][a[i] - 1] = true;
	}

	dfs(0, (1 << n) - 1);
	cout << ans << endl;
	return 0;
}
/**
 * v 現在の頂点
 */
int dfs(int v, int n, bool visited[]) {
	bool all_visited = true; // 全頂点を訪問済
	REP(i, n) {
		if(!visited[i])all_visited = false;
	}
	if (all_visited)return 1; //答を1増やす
	int ret = 0;
	REP(i, n) { //頂点i:頂点vに隣接、且つ、未訪問
		if (!graph[v][i])continue;
		if(visited[i])continue;

		visited[i] = true;
		ret += dfs(i, n, visited);
		visited[i] = false;
	}
	return ret;
}
/*int main() {
	scanf("%d %d", &n, &m);

	REP(i,m) {
		scanf("%d %d", &a[i], &b[i]);
		p[i] = i;
		graph[a[i] - 1][b[i] - 1] = graph[b[i] - 1][a[i] - 1] = true;
	}
	
	bool visited[nmax];
	REP(i, n)visited[i] = false;
	
	visited[0] = true;
	ans = dfs(0, n, visited);
	cout << ans << endl;
	return 0;

}
*/

Measured memory_bytes: 384
# -*- coding: utf-8 -*-
import math
import itertools

n = int(input())
x = [0]*n
y = [0]*n
d = [[0 for i in range(n)] for i in range(n)]
di = [0]*n
for i in range(n):
    x[i], y[i] = map(int, input().split())
    di[i] = i

for i in range(n):
    for j in range(n):
        d[i][j] = math.sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)

p_list = list(itertools.permutations(di, n))
total_dist = 0
total_count = 0

for c in p_list:
    dist = 0
    src = c[0]
    for ci in range(1, n):
        dst = c[ci]
        dist += d[src][dst]
        if(ci != n-1):
            src = dst
    total_dist += dist
    total_count += 1

print(total_dist/total_count)

Measured memory_bytes: 46956
#include<bits/stdc++.h>
using namespace std;
struct node
{
	int l,r;
}Node[100000+100];
bool cmp(struct node a,struct node b)
{
	return a.r<b.r;
}
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++)
		scanf("%d %d",&Node[i].l,&Node[i].r);
	sort(Node,Node+m,cmp);
	int now=-1;
	int sum=0;
	for(int i=0;i<m;i++)
	{
		if(Node[i].l<now)
			continue;
		else
		{
			sum++;
			now=Node[i].r;
		}
	}
	printf("%d\n",sum);
	return 0;
}

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

using namespace std;

int main()
{
	string S, T;
	cin >> S >> T;

	int ans = 0;
	for (size_t i = 0; i < S.size(); i++) {
		if (S[i] != T[i]) {
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3828
using System;
class Program1{
    static void Main(string[]args){
        string[]t=Console.ReadLine().Split(' ');
        int A=int.Parse(t[0]);
        int B=int.Parse(t[1]);
        if(A+B>A-B && A+B>A*B){
            Console.WriteLine(A+B);
        }else if(A*B>A+B&&A*B>A-B){
            Console.WriteLine(A*B);
        }else{
            Console.WriteLine(A-B);
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

// Return # of pairs (i,j) s.t. A[i] * A[j] < x
ll CountPairs(const vector<ll> &A, ll x) {
  ll count = 0;
  ll N = A.size();

  for (int i = 0; i < N - 1; ++i) {
    if (A[i] >= 0) {
      int p = i + 1;
      int q = N;
      if (A[i] * A[p] >= x) continue;
      while (p + 1 < q) {
    	int mid = (p + q) / 2;
    	if (A[i] * A[mid] < x) {
    	  p = mid;
    	} else {
    	  q = mid;
    	}
      }
      count += q - (i + 1);
    } else {
      int p = N - 1;
      int q = i;
      if (A[i] * A[p] >= x) continue;
      while (q < p - 1) {
	int mid = (p + q) / 2;
	if (A[i] * A[mid] < x) {
	  p = mid;
	} else {
	  q = mid;
	}
      }
      count += (N - 1) - q;
    }
  }

  // int expected_count = 0;
  // for (int i = 0; i < N - 1; ++i) {
  //   for (int j = i + 1; j < N; ++j) {
  //     if (A[i] * A[j] < x) ++expected_count;
  //   }
  // }

  // if (count != expected_count) {
  //   cerr << "x = " << x << endl;
  //   cerr << "count = " << count << endl;
  //   cerr << "expected_count = " << expected_count << endl;
  //   exit(1);
  // }
  
  return count;
}

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());

  ll p = -1e18;
  ll q = 1e18 + 1;
  while (p + 1 < q) {
    ll mid = (p + q) / 2;
    if (CountPairs(A, mid) < K) {
      p = mid;
    } else {
      q = mid;
    }
  }

  cout << p << endl;
  
  return 0;
}


Measured memory_bytes: 1792
using System;
using System.Linq;

namespace kozaiyApp
{
    public class B
    {
        static void Main()
        {
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int K = int.Parse(input[1]);

            int[] sunuke = Enumerable.Repeat<int>(0, N).ToArray();  // 0はもらってない、1はもらってる

            // おかしぶん繰り返す
            for (int i = 0; i < K; i++)
            {
                int d = int.Parse(Console.ReadLine());
                string[] inputA = Console.ReadLine().Split(' ');
                for (int j = 0; j < d; j++)
                {
                    int a = int.Parse(inputA[j]) - 1;
                    sunuke[a] = 1;
                }
            }

            int ans = 0;
            // sunukeで0の数を数える
            for (int i = 0; i < N; i++)
            {
                if (sunuke[i] == 0)
                {
                    ans += 1;
                }
            }

            Console.WriteLine(ans);
        }
    }
}


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

typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/
const int MX = 210000;

int n;
int cc[MX];

int main() {
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		++x;
		++cc[x];
		++cc[x - 1];
		++cc[x + 1];
	}
	int mx = 0;
	for (int i = 0; i < MX; ++i)
		mx = max(mx, cc[i]);
	cout << mx << "\n";
	return 0;
}




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

int main(){
    string X,Y;
    cin>>X>>Y;
    // 'A'=10;
    // 'B'=11;
    // 'C'=12;
    // 'D'=13;
    // 'E'=14;
    // 'F'=15;
    if(X<Y){
        cout<<"<"<<endl;
    }else if(X>Y){
        cout<<">"<<endl;
    }else{
        cout<<"="<<endl;
    }
}

Measured memory_bytes: 3620
n, l = gets.split.map(&:to_i)
s = l
e = n + l - 1

if s <= 0 && e >= 0
  puts [*s..e].inject(:+)
elsif e < 0
  puts [*s..(e-1)].inject(:+)
else
  puts [*(s+1)..e].inject(:+)
end

Measured memory_bytes: 1788
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <stack>
#include <cassert>
#include <map>
#include <numeric>
#include <cstring>
#include <set>
#include <ctime>
#include <queue>
#include <cmath>
#include <iomanip>
#include <iterator>

using namespace std;

clock_t timeStart, timeFinish;

void timeBegin() {
    timeStart = clock();
}

void timeEnd() {
    timeFinish = clock();
}

void timeDuration() {
    double time_taken = double(timeFinish - timeStart) / double(CLOCKS_PER_SEC);
    cout << "Time taken by program is : " << fixed << time_taken << setprecision(5);
    cout << " sec " << endl;
}

class InputReader {
public:
    InputReader() {
        input_file = stdin;
        cursor = 0;
        fread(buffer, SIZE, 1, input_file);
    }
    InputReader(const char *file_name) {
        input_file = fopen(file_name, "r");
        cursor = 0;
        fread(buffer, SIZE, 1, input_file);
    }
    inline InputReader &operator >>(int &n) {
        while((buffer[cursor] < '0' || buffer[cursor] > '9') && buffer[cursor] != '-') {
            advance();
        }
        int sign = 1;
        if (buffer[cursor] == '-') {
            sign = -1;
            advance();
        }
        n = 0;
        while('0' <= buffer[cursor] && buffer[cursor] <= '9') {
            n = n * 10 + buffer[cursor] - '0';
            advance();
        }
        n *= sign;
        return *this;
    }
private:
    FILE *input_file;
    static const int SIZE = 1 << 17;
    int cursor;
    char buffer[SIZE];
    inline void advance() {
        ++ cursor;
        if(cursor == SIZE) {
            cursor = 0;
            fread(buffer, SIZE, 1, input_file);
        }
    }
};

const int MAXN = 200000;

int main() {
    timeBegin();
    //ifstream cin("input.in");
    //ofstream cout("papagali.out");
    string s;
    cin >> s;
    string t;
    for (auto ch : s)
        if (ch == '?')
            t.push_back('D');
        else
            t.push_back(ch);
    cout << t << "\n";
    //timeDuration();
    return 0;
}

Measured memory_bytes: 3988
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long nn = 0;
		for(int i=0;i<N-1;i++){
			nn += ((((X[i+1] - X[i]) * (N-1 - i)) % mod) * (i + 1)) % mod;
			if(nn >= mod) nn %= mod;
		}
		long mm = 0;
		for(int i=0;i<M-1;i++){
			mm += ((((Y[i+1] - Y[i]) * (M-1 - i)) % mod) * (i + 1)) % mod;
			if(mm >= mod) mm %= mod;
		}
		
		long ret = nn * mm % mod;
		Console.WriteLine(ret);
	}
	const long mod = (long)1e9 + 7;
	int N,M;
	long[] X;
	long[] Y;
	public Sol(){
		var d = ria();
		N = d[0]; M = d[1];
		X = rla();
		Y = rla();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

int main() {
  string S;
  cin >> S;
  int ans = 0;
  for (int i = 0; i < 3; ++i) {
    if (S.at(i) == '1') {
      ++ans;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

ll p_p=0;
ll r_p=0;
ll s_p=0;

int main(void){
    ll n,k;
    ll r,s,p;
    string t;
    cin>>n>>k;
    cin>>r>>s>>p;
    cin>>t;
    ll ans=0;
    ll t_len=t.length();
    for(ll i=0;i<k;i++){
        string u="";
        for(ll j=i;j<t_len;j+=k){
            u+=t[j];
        }
        ll u_len=u.length();
        ll num=0;
        for(ll j=0;j<u_len;){
            ll index=j;
            num=0;
            while(true){
                if(j==u_len)break;
                if(u[index]==u[j])j++;
                else{
                    break;
                }
            }
            ll c=(j-index+1)/2;
            if(u[index]=='p'){
                num+=s*c;
            }
            if(u[index]=='s'){
                num+=r*c;
            }
            if(u[index]=='r'){
                num+=p*c;
            }
            ans+=num;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
A, B, C, D = map(int, list(input()))

sym = ["+", "-"]

for op1 in range(2):
    for op2 in range(2):
        for op3 in range(2):
            S = A + B * (-1) ** op1 + C * (-1) ** op2 + D * (-1) ** op3
            if S == 7:
                print("".join(map(str, [A, sym[op1], B, sym[op2], C, sym[op3], D, "=", 7])))
                exit()


Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
int ss(int x)
{
    int n,t=0;
    if(x%3==0)
    t=1;
    do
    {
        if(x%10==3)
        {
            t=1;
            break;
        }
        x/=10;    
    }
    while(x);
    return t;
}
int main()
{
    int x,n;
    scanf("%d",&n);
    int t;
    for(x=3;x<=n;x++)
    {
        t=ss(x);
        if(t==1)
        printf(" %d",x);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int inf = 1001001001;
 
int main(){
    ll n;
    ll ans=1LL,cnt=0LL;
    cin >> n;
    vector<ll> data(n);
    rep(i,n){
        cin >> data.at(i);
        if(data.at(i)==0LL){
            cout << 0 << endl;
            return 0;
        }

    }
    rep(i,n){
        if(ans>1000000000000000000LL/data.at(i)){
            cout << -1 << endl;
            return 0;
        }
        ans*=data.at(i);

    }
    if(ans>1000000000000000000LL || ans<0LL){
            cout << -1 << endl;
            return 0;
        }
    
    cout << ans << endl;

}

Measured memory_bytes: 4048
#include <iostream>
using namespace std;
int main(void)
{
	int a,b,c=0,d,e;
	for (a=0;a<5;a++)
	{
		cin>>b;
		if (b<40)
		{
			b=40;
		}
		c=c+b;
	}
	c=c/5;
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 3080
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(void){
	int n,x[100],y[100];
	double p1=0,p2=0,p3=0,p=0;
	scanf("%d",&n);
	for(int a=0;a<n;a++)scanf("%d",&x[a]);
	for(int a=0;a<n;a++)scanf("%d",&y[a]);
	for(int a=0;a<n;a++){
		p1+=abs(x[a]-y[a]);
		p2+=pow(abs(x[a]-y[a]),2);
		p3+=pow(abs(x[a]-y[a]),3);
		if(p<abs(x[a]-y[a]))p=abs(x[a]-y[a]);
	}
	p2=sqrt(p2);
	p3=pow(p3,1.0/3.0);
	printf("%f\n%f\n%f\n%f\n", p1, p2, p3,p);
return 0;
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int a[N],p[N],n;
int check(int mid)
{
	for(int i=1;i<=2*n-1;i++)
		p[i]=(a[i]>=mid);
	for(int i=n;i>=2;i--)
	{
		if(p[i]==p[i-1])
			return p[i];
		int j=2*n-i;
		if(p[j]==p[j+1])
			return p[j];
	}
	return p[1];
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=2*n-1;i++)
		scanf("%d",&a[i]);
	int l=1,r=2*n-1;
	while(l<r)
	{
		int mid=l+r+1>>1;
		if(check(mid))
			l=mid;
		else
			r=mid-1;
	}
	printf("%d\n",l);
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define mod 1000000007

const int sz=1e5+5;
ll inf=1e15;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        ll x,k,d;
        cin>>x>>k>>d;   
        x=abs(x);
        ll mv=x/d;
        ll rem=(x-(mv*d));
        if(k<=mv)
        {
            cout<<(x-(k*d));
        }
        else 
        {
            k=(k-mv);
            x=rem;
            if(k&1)
            {
                cout<<(d-rem);
            }
            else
                cout<<rem;
        }
        // cout<<ans;
    }

    return 0;
}

Measured memory_bytes: 3648
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/15/ALDS1_15_A


n = int(input())

cnt = 0
coin = (25, 10, 5, 1)
for c in coin:
    cnt += n // c
    n -= c * (n // c)

print(cnt)



Measured memory_bytes: 5592
n,k = map(int,input().split())
a = list(map(int,input().split()))
a = [a[i]-k for i in range(n)]
DP = [[0 for i in range(5100)] for j in range(52)]
for i in range(52):
    DP[i][2530] = 1
for i in range(1,n+1):
    for j in range(5050):
        DP[i][j] = DP[i-1][j] + DP[i-1][j-a[i-1]]
print(DP[n][2530]-1)

Measured memory_bytes: 5748
a=[]
b=[]
max=0
100.times{|i|
  a[i]=0
}
while n=gets
  n=n.to_i
  a[n-1]+=1
  max=a[n-1] if a[n-1]>max
end
100.times{|j|
  if a[j]==max
    p j+1
  end
}


Measured memory_bytes: 6836
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    string S, T; cin >> S >> T;
    int ans = 0;
    F0R(i, sz(S)) if (S[i] != T[i]) ans++;
    cout << ans << nl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 3772
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <functional>
#include <sstream>
#include <complex>
#include <climits>
using namespace std;

#define REP(i,a,n) for(int i=(a);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define EPS 1e-8

int main(){
	int m,d;
	const int day[] = {31,29,31,30,31,30,31,31,30,31,30,31};
	const char *youbi[] = {
		"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"
	};
	while(scanf("%d",&m),m){
		scanf("%d",&d);
		int sum = 0;
		rep(i,m-1)sum+=day[i];
		sum += d;
		puts(youbi[(sum+2)%7]);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
	int input;
	int code = 0;
	
	while (scanf("%*[^0-9]%d", &input) != EOF){
		code += input;
	}
	
	printf("%d\n", code);
	return (0);
}

Measured memory_bytes: 1140
#define Link "https://arc074.contest.atcoder.jp/tasks/arc074_d?fbclid=IwAR1u2WnBRSm0lLs0cqi_vsg5Ne3D8MWtHeTec3YuJGfEQHdq9CtY2QFdpYQ"

#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>

#define TASK "atcoder_arc074F"

using namespace std;

const int maxn = 2e2 + 1;
int h,w,S,T,cnt,_u[maxn*maxn],_v[maxn*maxn],cf[maxn*maxn*2],d[maxn*maxn];
char a[maxn][maxn];
vector <int> e[maxn*maxn];
vector <int> :: iterator key[maxn*maxn];
queue <int> qu;

void Connect(int u, int v, int d)
{
    ++cnt;
    _u[cnt] = u;
    _v[cnt] = v;
    cf[cnt*2] = d;
    cf[cnt*2+1] = d;
    e[u].push_back(cnt*2);
    e[v].push_back(cnt*2+1);
}

void Enter()
{
    cin >> h >> w;
    for (int i=1;i<=h;++i)
        for (int j=1;j<=w;++j) {
            cin >> a[i][j];
            if (a[i][j] == 'S') {
                Connect(0,i,1e9);
                Connect(i,j+h,1e9);
            }
            if (a[i][j] == 'T') {
                Connect(w+h+1,i,1e9);
                Connect(j+h,w+h+1,1e9);
            }
            if (a[i][j] != '.')
                Connect(i,j+h,1);
        }
}

void Init()
{

}

bool BFS()
{
    fill(d,d+h+w+10+1,-1);
    d[S] = 0;
    qu.push(S);
    while (!qu.empty()) {
        int u = qu.front();
        qu.pop();
        key[u] = e[u].begin();
        for (int i : e[u]) {
            int v = _u[i/2] + _v[i/2] - u;
            if (d[v] == -1 && cf[i] != 0) {
                d[v] = d[u] + 1;
                qu.push(v);
            }
        }
    }
    return d[T] != -1;
}

int DFS(int u, int val)
{
    if (u == T || val == 0)
        return val;
    int X = 0;
    for (;key[u]!=e[u].end();++key[u]) {
        int i = *key[u];
        int v = _u[i/2]  + _v[i/2] - u;
        if (d[v] == d[u] + 1) {
            int k = DFS(v,min(val,cf[i]));
            X += k;
            cf[i] -= k;
            cf[i^1] += k;
            val -= k;
        }
        if (val == 0)
            break;
    }
    return X;
}

void Solve()
{
    S = 0;
    T = h + w + 1;
    int res = 0;
    while (BFS())
        res += DFS(S,1e9);
    if (res == 1e9)
        cout << -1;
    else
        cout << res;
}

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

#ifdef LHL
    freopen(".INP","r",stdin);
    freopen(".OUT","w",stdout);
#else
//    freopen(TASK".INP","r",stdin);
//    freopen(TASK".OUT","w",stdout);
#endif // LHL

    Enter();
    Init();
    Solve();
}


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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()

int main(){
    cout << setprecision(20);

    ll N;
    cin >> N;

    vll a(N, 0);
    rep(i, N) cin >> a[i];

    vvll dp(N, vll(3, 0));
    irep(i, N){
        dp[i][0] = a[i] + ((i+2)<N? dp[i+2][0] : 0);
        if(i+1<N) dp[i][1] = a[i] + ((i+3)<N? max(dp[i+3][0], dp[i+2][1]) : (i+2)<N? dp[i+2][1] : 0);
        if(i+2<N) dp[i][2] = a[i] + ((i+4)<N? max(dp[i+4][0], max(dp[i+3][1], dp[i+2][2])) : (i+3)<N? max(dp[i+3][1], dp[i+2][2]) : (i+2)<N? dp[i+2][2] : 0);
    }
    ll total = N%2==0? max(dp[0][1], dp[1][0]) : max(dp[0][2], max(dp[1][1], dp[2][0]));
    cout << total << endl;
}


Measured memory_bytes: 15632
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long K,A,B;
	long long bis=1;
	long long yen=0;
	long long i;
	scanf("%lld %lld %lld",&K,&A,&B);
	for(i=0;i<K;i++){
		if(yen){yen--; bis+=B;}
		else if(bis>=A&&K-1!=i&&B-A>1) {bis-=A; yen++;}
		else bis++;
	}
	printf("%lld\n",bis);
}


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

int main () {
  int a, tmp=0, ans = 10000000;
  cin >> a;
  vector<int> line(a);
  for(int i = 0; i < a; i++){
    cin >> line[i];
  }
  sort(line.begin(), line.end());
  for(int i = line[0]; i <= line[a-1]; i++){
    tmp = 0;
    for(int j = 0; j < a; j++){
      tmp += (line[j]-i)*(line[j]-i) ;
    }
    ans = min(tmp, ans);
  }
  cout << ans << endl ;
}

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

ll fastpower (ll b , ll p){
    ll k= p%2 ? b : 1 ;
    return p==0 ? 1 : k*(fastpower(b*b,p/2));
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	long long int n, m, k;
	scanf("%lld %lld %lld", &n, &m, &k);
	long long int i, j;
	long long int a[200005], b[200005];
	for (i = 0; i < n; i++)
		scanf("%lld", &a[i + 1]);
	for (i = 0; i < m; i++)
		scanf("%lld", &b[i + 1]);
	a[0] = b[0] = 0;
	for (i = 0; i < n; i++)
		a[i + 1] += a[i];
	for (i = 0; i < m; i++)
		b[i + 1] += b[i];
	long long int ans = 0;
	j = m;
	for (i = 0; i <= n; i++)
	{
		while (j >= 0 && a[i] + b[j] > k)
			j--;
		if (j >= 0)
			if (ans < i + j)
				ans = i + j;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 6936
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }


int main() {
    int n; cin >> n;
    vector<int> d(n);
    rep(i, n) cin >> d[i];

    sort(d.begin(), d.end());
    int top = d[0];
    int ans = 1;
    for(int i=1; i < n; i++) {
        if(top < d[i]) {
            ans++;
        }
        top = d[i];
    }

    cout << ans << endl;


}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using static System.Console;
using static System.Math;
class Simple
{
    int N;
    int[] a;
    void Solve() {
        //input
        N = io.Int;
        a = new int[N];
        for (int i = 0; i < N; ++i)
            a[i] = io.Int;
        //cal
        var mulOf4Num = a.Count(a => a % 4 == 0);
        var mulOf2Num = a.Count(a => a % 2 == 0);
        var onlyMulOf2Num = mulOf2Num - mulOf4Num;
        var ans = mulOf4Num * 2 + 1 >= N || mulOf4Num * 2 + onlyMulOf2Num >= N;
        //ret
        WriteLine(ans ? "Yes" : "No");
    }
    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) => new Simple().Stream();
    private void Stream() {
        //var exStdIn = new System.IO.StreamReader("stdin.txt");
        //SetIn(exStdIn);
        Solve();
        io.Flush();
    }
}
class SimpleIO
{
    string[] _nextBuffer;
    int _bufferCnt;
    char[] cs = new char[] { ' ', '"', ',' };
    StreamWriter sw = new StreamWriter(OpenStandardOutput()) {
        AutoFlush = false
    };
    public SimpleIO() {
        _nextBuffer = new string[0];
        _bufferCnt = 0;
        SetOut(sw);
    }
    string Next() {
        if (_bufferCnt < _nextBuffer.Length)
            return _nextBuffer[_bufferCnt++];
        var st = ReadLine();
        while (st == "")
            st = ReadLine();
        if (st != null)
            _nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        else
            st = "";
        _bufferCnt = 0;
        return _nextBuffer[_bufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void Flush() => Out.Flush();
}


Measured memory_bytes: 18528
#template
from sys import setrecursionlimit
setrecursionlimit(10**6)
from collections import Counter
def inputlist(): return [int(j) for j in input().split()]
#template
N,H,W = inputlist()
count = 0
for i in range(N):
    A,B = inputlist()
    if A >= H and B >= W:
        count+=1
print(count)

Measured memory_bytes: 3316
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;

namespace B
{
    class Solver
    {
        public bool Solve()
        {
            string s = Console.ReadLine();
            string t = Console.ReadLine();
            for (int i = 0; i < s.Length; i++)
            {
                string tmp = s.Substring(i) + s.Substring(0, i);
                if (tmp == t) return true;
            }
            return false;
        }

    }

    class M
    {
        public static void Main(string[] args)
        {
            if (new Solver().Solve()) { Console.WriteLine("Yes"); }
            else { Console.WriteLine("No"); }
        }

    }
};


Measured memory_bytes: 13140
#include <stdio.h>

int main()
{
	int x, y;
	int sum;
	int flag = 0;

	scanf("%d %d", &x, &y);

	for (int i = 0; i <= x; i++) {
		sum = i * 4 + (x - i) * 2;
		if (sum == y)
			flag = 1;
	}

	if (flag == 1)
		printf("Yes\n");
	else
		printf("No\n");

	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <bitset>
#include <string>

int main(void) {
    u_int n;
    std::string event;

    std::cin >> n;
    for (u_int i = 0; i < n; ++i) {
        // 各ビットがそれぞれの塁のランナーの有無を表現する
        std::bitset<4> runner;
        u_int out = 0, score = 0;

        do {
            std::cin >> event;
            if ("HIT" == event) {
                runner <<= 1;   // ランナーを1つずつ進める
                runner.set(0);  // 一塁にランナーを置く
                // ホームインしたかどうか
                if (runner.test(3)) {
                    ++score;
                    runner.reset(3);
                }
            } else if ("HOMERUN" == event) {
                score += runner.count() + 1;
                runner.reset(); // ランナーをリセット
            } else if ("OUT" == event) {
                ++out;
            }
        } while (out != 3);

        std::cout << score << std::endl;
    }

    return 0;
}

Measured memory_bytes: 1208
memo = {"S"=>[],"H"=>[],"C"=>[],"D"=>[]}
gets.chomp.to_i.times do
  k, n = gets.chomp.split
  memo[k] << n
end

all = (1..13).map(&:to_s)
memo.each{|k, ns| all.each{|n| puts "#{k} #{n}" if !ns.include?(n)}}


Measured memory_bytes: 6864
#include <bits/stdc++.h>
using namespace std;
const int MAX = 510000;
const int MOD = 1000000007;

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

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
    COMinit();
	int s,i=1;
    cin>>s;
    long long ans=0;
    while(true){
    	if(i*3>s) break;
        long long k=COM(s-i*3+i-1,i-1);
        ans=(ans+k)%MOD;
        i++;
    }
  cout<<ans%MOD;
}


Measured memory_bytes: 15536
/*
[abc121] D - XOR World
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

ll A, B;

ll f(ll x) { return ((x + 1) / 2 % 2) ^ ((x & 1) ? 0 : x); }

ll solve() { return f(A - 1) ^ f(B); }

int main() {
    cin >> A >> B;

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 256
var sx,sy,tx,ty,i:Integer;
begin
	read(sx,sy,tx,ty);
	tx:=tx-sx;
	ty:=ty-sy;
	for i:=1 to ty do write('U');
	for i:=1 to tx do write('R');
	for i:=1 to ty do write('D');
	for i:=1 to tx do write('L');
	write('L');
	for i:=1 to ty do write('U');
	write('UR');
	for i:=1 to tx do write('R');
	write('DR');
	for i:=1 to ty do write('D');
	write('DL');
	for i:=1 to tx do write('L');
	write('U');
end.


Measured memory_bytes: 128
import math

def is_prime(num):
    if num == 2:
        return True
    if num <= 1 or num % 2 == 0:
        return False
    r = math.floor(math.sqrt(num)) + 1
    for i in range(3, r, 2):
        if num % i == 0:
            return False
    return True

n = int(input())
prime_count = 0
for _ in range(n):
    if is_prime(int(input())):
        prime_count += 1

print(prime_count)



Measured memory_bytes: 5676
n, m = gets.split.map(&:to_i)
arr = []
loop do
  l = gets.split.map(&:to_i)
  l[0] != 0 ? arr << l : break
end
gets.to_i.times do |i|
  b = gets.split.map(&:to_i)
  c = [0]*n
  arr.each do |s, t, e|
    c[s-1] += b[t-1]*e
  end
  puts c.join(" ")
end

Measured memory_bytes: 13048
/*??????????????????*/
#include<stdio.h>
int main()
{
    int n,i,k[10001],c1,c2;
    scanf("%d",&n);
    while(n!=0){
        c1=0;
        c2=0;
        for(i=0;i<n;i++){
            scanf("%d",&k[i]);
            if(k[i]==0){
                c2++;
            }
            else if(k[i]==1){
                c1++;
                c2++;
            }
            else if(k[i]>=2){
                c1++;
            }
        }
        if(c2==n){
            printf("NA\n");
        }
        else {
            printf("%d\n",c1+1);
        }
        scanf("%d",&n);
    }
    return 0;
}

Measured memory_bytes: 648
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;
double dp[305][305][305] = {};
const double eps = 1e-12;
int n;

double dfs(int a, int b, int c){
    if(a == 0 && b == 0 && c == 0){
        return 0.0f;
    }
    if(dp[a][b][c] >= eps){
        return dp[a][b][c];
    }
    double val = 0;
    double add = (double)n / (a + b + c);
    if(a != 0){
        val += (dfs(a-1, b, c) +  add) * ((double)a / (a + b + c));
    }
    if(b != 0){
        val += (dfs(a+1, b-1, c) +  add) * ((double)b / (a + b + c));
    }
    if(c != 0){
        val += (dfs(a, b+1, c-1) +  add) * ((double)c / (a + b + c));
    }
    dp[a][b][c] = val;
    return val;
}

int main(){
    cin >> n;
    int a_num[3] = {0};
    int val;
    for(int i=0; i<n; i++){
        cin >> val; val--;
        a_num[val]++;
    }
    cout << setprecision(12);
    cout << dfs(a_num[0], a_num[1], a_num[2]) << "\n";
    return 0;
}

Measured memory_bytes: 219392
while 1:
    a, b, c = raw_input().split()
    if b == "?":
        break
    a = int(a)
    c = int(c)
    if b == "+":
        print a+c
    elif b == "-":
        print a-c
    elif b == "*":
        print a*c
    elif b == "/":
        print a//c


Measured memory_bytes: 4632
let to_num s =
  let sym_to_num = function
    | 'A' -> 1
    | 'C' -> 2
    | 'G' -> 3
    | 'T' -> 4
    | _ -> exit 1
  in
  let n = String.length s in
  let rec doit i acc =
    if i = n then acc
    else doit (i + 1) (4*acc + sym_to_num s.[i])
  in
  doit 0 0

let () =
  let tbl = Array.make (22369620 + 1) false in
  let n = read_int () in
  let rec doit i =
    if i < n then begin
      match Scanf.scanf "%s %s\n" (fun x y -> x, y) with
      | ("insert", x) -> (tbl.(to_num x) <- true; doit (i + 1))
      | ("find", x) -> (print_endline (if tbl.(to_num x) then "yes" else "no"); doit (i + 1))
      | _ -> exit 1
    end
  in
  doit 0

Measured memory_bytes: 181308
#include <bits/stdc++.h>
#include <string_view>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define AB_BHI_NI_DEGI                \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define int long long
#define pb push_back
#define N 100009
#define inf 1e18
const double PI = 3.141592653589793238462643383279;
int mod = 1e9 + 7;
//int mod = 998244353;
#define P pair<int, int>
#define F first
#define S second
#define ll long long
#define all(v) v.begin(), v.end()
#define vi vector<int>
#define ld long double

#define ordered_set tree<P, null_type, less<P>, rb_tree_tag, tree_order_statistics_node_update>

int n, k;
int a[100];

void solve()
{
    k = 1000;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    int ans = 1000;
    int prev = a[0];
    int stock = 0;
    int amount = 1000;
    for (int i = 1; i < n; i++)
    {
        if (prev < a[i])
        {
            stock = amount / prev;
            amount = amount % prev;
            amount += a[i] * stock;
            ans = max(ans, amount);
            prev = a[i];
        }
        else
            prev = min(prev, a[i]);
    }
    cout << ans << "\n";
}
int32_t main()
{
    AB_BHI_NI_DEGI
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //cout.precision(20);
    //cout << fixed;
    int T = 1;
    //cin >> T;
    int cnt = 1;
    while (T--)
    {
        //cout << "Case #" << cnt++ << ":\n";
        solve();
    }
    return 0;
}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){

			String S = scan.next();
			char[]s = S.toCharArray();

			if(s[s.length-1]=='s') {
				System.out.println(S+"es");
			}else {
				System.out.println(S+"s");
			}
		}


	}


}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using llong = long long int;

const static int MAX = 999999;
const static int MOD = 1000000007;
const static int IINF = INT_MAX;
const static llong LINF = LLONG_MAX;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

template<typename T> T my_gcd(T a, T b) {
    return (a ? my_gcd(b % a, a) : b);
}
template<typename T> T my_lcm(T a, T b){
    return a * b / my_gcd(a, b);    
}

bool check(vector<int> A, vector<int> B) {
    rep(i, (int)A.size()) {
        if (A[i] != B[i]) return 0;
    }

    return 1;
}

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> P(n), Q(n);
    rep(i, n) cin >> P[i];
    rep(i, n) cin >> Q[i];

    vector<int> S(n);
    rep(i, n) S[i] = i + 1;

    int a, b, cnt = 1;
    do {
        if (check(P, S)) a = cnt;
        if (check(Q, S)) b = cnt;
        ++cnt;
    } while (next_permutation(all(S)));

    cout << abs(a - b) << endl;
    
    return 0;
}

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

bool check(char a0, char a1, char op, char a2){
	bool same = (op == 'o') == (a1 == 'S');
	return same == (a0 == a2);
}

int main(){
	int n;
	string s;
	cin >> n >> s;
	string tmp(n, ' ');
	for(int p = 0; p < 4; p++){
		tmp[0] = (p & 1) ? 'S' : 'W';
		tmp[1] = (p & 2) ? 'S' : 'W';
		for(int i = 2; i < n; i++){
			bool prev = tmp[i - 1] == 'S';
			bool same = (s[i - 1] == 'o') == prev;
			tmp[i] = (same ? tmp[i - 2] : (tmp[i - 2] == 'S' ? 'W' : 'S'));
		}
		if(check(tmp[n - 2], tmp[n - 1], s[n - 1], tmp[0]) && check(tmp[n - 1], tmp[0], s[0], tmp[1])){
			cout << tmp << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}

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

int main()
{
    int n; scanf("%d", &n);
    int ar[n+5] = {};
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &ar[i]);
    }
    int CountGood = 0;
    for(int i = 1; i <= n; i++)
    {
        if(ar[i] != i)
        {
            CountGood++;
        }
    }
    if(CountGood <= 2)
    {
        printf("YES\n");
    }
    else
    {
        printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

struct UnionFind {
    vector<int> par;
    vector<int> rank;
    
    UnionFind(int n = 1) {
        init(n);
    }
    
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }
    
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    int n;
    cin>>n;
    vvl as(n, vl(n));
    cin>>as;
    vvl ws(n, vl(n));
    rep(i, n) rep(j, n) ws[i][j] = as[i][j];

    rep(i, n) {
        priority_queue<LP, vector<LP>, greater<LP>> q;
        vl dist(n);
        vector<bool> visited(n);
        q.push(LP(0, i));
        while (!q.empty()) {
            LP p = q.top(); q.pop();
            ll w = p.fi;
            ll v = p.se;
            if (visited[v]) {
                if (w == as[i][v]) {
                    ws[i][v] = 0;
                    ws[v][i] = 0;
                }
                continue;
            }
            visited[v] = true;
            if (as[i][v] != w) {
                cout<<-1<<endl;
                return 0;
            }
            rep(j, n) {
                if (ws[v][j] == 0) continue;
                q.push(LP(ws[v][j] + w, j));
            }
        }
    }
    ll ans = 0;
    rep(i, n) rep(j, n) ans += ws[i][j];
    cout<<ans / 2<<endl;
}

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

int main(){
    int x, a, b;    cin>>x>>a>>b;
    int min_a,min_b;
    
    if(x-a<0)
        min_a=a-x;
    else
        min_a=x-a;
    
    if(x-b<0)
        min_b=b-x;
    else
        min_b=x-b;
    
    cout<<(min_a<min_b?'A':'B')<<endl;
    
}

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

int main() {
	int n;cin >> n;
	vector <int> v(3*n);
	rep(i,3*n) cin >> v[i];
	sort(v.begin(), v.end());
	int64_t ans=0;
	rep(i,n){
		ans+=v[3*n-2*(i+1)];
	}
	cout << ans << endl;
}


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

/* macros */
#define int long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vt vector
#define pb push_back
#define fi first
#define se second
#define pi pair<int,int>
#define tc int t;cin>>t;while (t--){solve();}
#define notc solve();
#define newline cout << "\n";
#define mod 1000000007
#define ret return 0;
#define sz(x) (int)x.size();
#define rep(i,a,b) for(int i=a;i<b;i++)
#define srt(x) sort(x.begin(), x.end())

int n;
vi a,b,c;

int dp[100005][4];
       
int go(int pos, int last){
    if (pos == n){
        return 0;
    }
    if (dp[pos][last] != -1){
        return dp[pos][last];
    }
    int ans = INT_MIN;
    if (last != 1){
        ans = max(ans, go(pos+1,1) + a[pos]);
    }
    if (last != 2){
        ans = max(ans, go(pos+1,2) + b[pos]);
    }
    if (last != 3){
        ans = max(ans, go(pos+1,3) + c[pos]);
    }
    return dp[pos][last] = ans;
}

void solve(){
    cin>>n;
    a.resize(n);
    b.resize(n);
    c.resize(n);
    for (int i=0;i<n;i++){
        for (int j=0;j<=2;j++){
            if (j == 0){
                cin>>a[i];
            }else if (j == 1){
                cin>>b[i];
            }else{
                cin>>c[i];
            }
        }
    }
    memset(dp, -1, sizeof dp);
    int ans = go(0,0);
    cout << ans << "\n";
}

int32_t main(){
    fastio
    notc
    ret
}


Measured memory_bytes: 13344
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#include <stack>
#include <functional>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = (int)(a);(i) > (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, n) &((x)[0]), &((x)[n])
#define BRK(x) { (x); break; }
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using namespace std;


int N;
int Y;


void solve(){
	int x = -1, y = -1, z = -1;
	repe(i, 0, N){
		repe(j, 0, N-i){
			int k = N-i-j;
			if(10000*i+5000*j+1000*k == Y) BRK((x=i, y=j, z=k));
		}
	}
	cout << x << ' ' << y << ' ' << z << endl;
}


signed main(){
	cin >> N >> Y;

	solve();

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;

string s1, s2;

int main() {
  while (1) {
    cin >> s1;
    if (s1[0] == '.') break;
    cin >> s2;
    vector<string> d1, d2;
    if (s1 == s2) {
      cout << "IDENTICAL" << endl;
      continue;
    }
    string temp = "";
    for (ll i = 0; i < s1.size(); i++) {
      if (s1[i] == '"') d1.push_back(temp), temp = "";
      else temp += s1[i];
    }
    d1.push_back(temp);
    temp = "";
    for (ll i = 0; i < s2.size(); i++) {
      if (s2[i] == '"') d2.push_back(temp), temp = "";
      else temp += s2[i];
    }
    d2.push_back(temp);
    if (d1.size() != d2.size()) {
      cout << "DIFFERENT" << endl;
      continue;
    }
    ll counter = 0;
    for (ll i = 0; i < d1.size(); i++) if (d1[i] != d2[i]) {
      if (i % 2 == 0) counter += 2;
      else counter++;
    }
    if (counter == 1) cout << "CLOSE" << endl;
    else cout << "DIFFERENT" << endl;
  }
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
//////////////////////////////////

int main() {
  int n; cin >> n;
  vector<pair<int, int>> p(n);
  int x, l;
  for(int i=0; i<n; i++) {
    cin >> x >> l;
    p[i].first = x + l;
    p[i].second = x - l;
  }
  sort(all(p));
  int ans = 1;
  int pos = p[0].first;
  for(int i=1; i<n; i++) {
    if (pos <= p[i].second) {
      ans++;
      pos = p[i].first;
    }
  }
  cout << ans << endl;

  return 0;
}

// EOF

Measured memory_bytes: 1024
#include <cmath>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <queue>
//~ #include <cstring>

using namespace std;

#define forsn(i,s,n) for (int i = (s);i < (int)(n);i++)
#define forn(i,n) forsn(i,0,n)
#define dforsn(i,s,n) for (int i = (n-1);i >= (int)(s);i--)
#define dforn(i,n) dforsn(i,0,n)
#define all(v) (v).begin(), (v).end()
#define F first
#define S second

typedef long long int tint;

int a[100000];

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

	int k; cin >> k;
	forn(i,k) cin >> a[i];
	
	bool broken = false;
	tint l = 2, r = 3;
	dforn(i,k) {
		if (l % a[i]) l = l + a[i] - (l % a[i]);
		if (r % a[i]) r = r + a[i] - (r % a[i]);

		if (l >= r) broken = true;
	}
	
	if (broken) cout << -1 << endl;
	else cout << l << ' ' << r - 1 << endl;
}


Measured memory_bytes: 640
from operator import itemgetter
N = int(input())
SP = []
for i in range(N):
    S, P = input().split()
    P = int(P)
    SP.append((i+1, S, P))
SP = sorted(sorted(SP, key=itemgetter(2), reverse=True), key=itemgetter(1))
for i in SP:
    print(i[0])

Measured memory_bytes: 3060