akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

int main() {
    int n;
    long long x;
    cin >> n;
    vector<long long> a(n);
    vector<long long> b(n);
    for (int i = 0; i < n; i++){
        cin >> x;
        a[i] = x;
        b[i] = x;
    }
    sort(a.begin(), a.end());
    for (int j = 0; j < n; j++){
        if (b[j] <= a[a.size() / 2 - 1]){
            cout << a[a.size() / 2] << endl;
        }else{
            cout << a[a.size() / 2 - 1] << endl;
        }
    }
}

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

using namespace std;

#define nl '\n'

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

  if (N * A < B) {
    cout << N * A << nl;
  } else {
    cout << B << nl;
  }
  return 0;
}

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

typedef long long ll;

const int V = 100001;
//cost, node
vector<vector<pair<int, int>>> edges(V);
ll INF = 1e16;
vector<ll> minCost(V, INF);
vector<bool> nodeIsFixed(V, false);

int main()
{
    int N;
    cin >> N;
    for(int i = 0; i < N - 1; i++)
    {
        int u, v, w;
        cin >> u >> v >> w;
        edges.at(u).push_back(make_pair(w, v));
        edges.at(v).push_back(make_pair(w, u));
    }
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> q;
    q.push(make_pair(0, 1));
    while(!q.empty())
    {
        ll cost;
        int currentNode;
        tie(cost, currentNode) = q.top();
        q.pop();
        if(nodeIsFixed.at(currentNode)){
            continue;
        }
        nodeIsFixed.at(currentNode) = true;
        minCost.at(currentNode) = cost;
        for(pair<int, int> edge : edges.at(currentNode)) {
            if (minCost.at(edge.second) <= cost + edge.first){
                continue;
            }
            q.push(make_pair(cost + edge.first, edge.second));
        }
    }
    for(int i = 1; i <= N; i++)
    {
        cout << minCost.at(i) % 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 7296
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin>>N;
    cout<<"ABC"<<N<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ms(a, n) memset(a, n, sizeof(a))
#define Size(Array) sizeof(Array)/sizeof(Array[0])
#define pb push_back
#define ed endl
#define en cout << endl
#define it(A) A.begin(), A.end()
#define mod (ll)(1e9 + 7)
#define f(i, a, b) for(ll i = a; i < b; i++)
#define cin(a, n) for(ll i = 0; i < n; i++) cin >> a[i]
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define MAX 200005


using namespace std;


void solve()
{
    ll k, a, b;
    cin >> k >> a >> b;

    if(a%k==0 or b%k==0)
    {
        cout << "OK" << endl;
        return;
    }

    ll x = a/k;
    if( (x+1)*k  <= b) cout << "OK" << endl;
    else cout << "NG" << endl;

    return;
}

int main()
{
    FAST;

    ll t = 1;
    while(t--)
        solve();


    return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vii> vvii;

#define fastIO ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define forw(i,l,r) for( auto i = (l) ; i < (r) ; i++ )
#define forb(i,r,l) for( auto i = (r) ; i >= (l) ; i-- )
#define log2i(x) 32 - __builtin_clz((x)) - 1
#define log2ll(x) 64 - __builtin_clzll((x)) - 1
#define Pi acos(-1.0)
#define sz(x) (int)x.size()
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

const int N = 2e5+7;
const ll M = 1e9+7;
int n,m,a,b;
ll ans;
ll f[N], invf[N];

ll fexp(ll x, ll y) {
    ll res=1;
    while(y) {
        if(y&1) res=(res*x)%M;
        x=(x*x)%M;
        y>>=1;
    }
    return res%M;
}

void init() {
    f[0]=invf[0]=1;
    forw(i,1,N) {
        f[i]=(f[i-1]*i)%M;
        invf[i]=(invf[i-1]*fexp(i,M-2))%M;
    }
}

ll C(int n, int k) {return (f[n]*invf[k]%M*invf[n-k])%M;}

int main() {
#ifndef ONLINE_JUDGE
    //freopen("test.inp","r",stdin);
    //freopen("test.out","w",stdout);
#endif
    fastIO;
    init();
    cin >> n >> m >> a >> b;
    forw(i,b,m) ans=(ans+C(n-a-1+i,i)%M*C(a-1+m-i-1,a-1)%M)%M;
    cout << ans;
    return 0;
}


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

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] arr = new int[n];
        String[] line = br.readLine().split(" ", n);
        for (int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(line[i]);
        }
        Arrays.sort(arr);
        for (int i = 1; i < n; i++) {
            if (arr[i] == arr[i - 1]) {
                System.out.println("NO");
                return;
            }
        }
        System.out.println("YES");
    }
}


Measured memory_bytes: 46292
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ojtEx
{
    class Program
    {
        static void Main(string[] args)
        {
            //int X = int.Parse(Console.ReadLine());
            //int a = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();

            //string[] xa = Console.ReadLine().Split(' ');
            //int x = int.Parse(xa[0]);
            //int a = int.Parse(xa[1]);


            //int ans = Solve(x, a);

            int x, y, z, w;
            x = int.Parse(s[0].ToString());
            y = int.Parse(s[1].ToString());
            z = int.Parse(s[2].ToString());
            w = int.Parse(s[3].ToString());


            string ans = S(x, y, z, w);

            Console.WriteLine(ans);
        }

        public static int Solve(int X, int A)
        {
            if (X < A)
            {
                return 0;
            }
            if (A <= X)
            {
                return 10;
            }

            return 0;
        }

        public static string S(int x, int y,int z,int w)
        {
            if(x!=y && y!=z && z!=w)
                {
                return "Good";
                }
            else
            {
                return "Bad";
            }
        }

    }
}


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

int main(){
  int e;
  while(cin >> e,e){
    int ans = e;
    for(int z=0;z*z*z<=e;z++){
      for(int y=0;y*y+z*z*z<=e;y++){
	ans = min(ans,e-z*z*z-y*y+y+z);
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define SFOR(i,a,b) for(int i=a;i<b;i++)
#define elif(a) else if(a)
#define INF INT_MAX
#define F first
#define S second
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,k;
  string s;
  cin>>n>>k;
  cin>>s;
  FOR(i,n){
    if(i==k-1){
      printf("%c",s[i]+'a'-'A');
    }else{
      printf("%c",s[i]);
    }
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n;
  scanf("%d",&n);
  int a,b=1,c=0;
  for(int i=0;i<n;i++){
    scanf("%d",&a);
    if(a==b)b++;
    else c++;
  }
  if(b==1){puts("-1");return 0;}
  printf("%d\n",c);
}

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

int main()
{
	std::vector<int> list_a{};
	std::vector<int> list_b{};
	std::array<bool, 10> a;
	
	int a1, a2, a3, a4;
	int b1, b2, b3, b4;
	int hit = 0, brow = 0;
	while (std::cin >> a1 >> a2 >> a3 >> a4 >> b1 >> b2 >> b3 >> b4)
	{
		hit = 0;
		brow = 0;
		for (auto& val : a)
		{
			val = false;
		}
		list_a.clear();
		list_b.clear();

		a[a1 - 1] = true;
		a[a2 - 1] = true;
		a[a3 - 1] = true;
		a[a4 - 1] = true;

		list_a.push_back(a1);
		list_a.push_back(a2);
		list_a.push_back(a3);
		list_a.push_back(a4);

		list_b.push_back(b1);
		list_b.push_back(b2);
		list_b.push_back(b3);
		list_b.push_back(b4);

		for (int i = 0; i < list_a.size(); ++i )
		{
			if (list_a[i] == list_b[i])
			{
				hit++;
			}
			else
			{
				if ( a[ list_b[i] - 1 ] )
				{
					brow++;
				}
			}
		}
		std::cout << hit << " " << brow << std::endl;
	}

	return 0;
}

Measured memory_bytes: 3064
N = list(input())

sum = 0

while N != []:
    if N[-1] != '9' and len(N) != 1:
        sum += 9
        del N[-1]
        if N[-1] == '0':
            N = list(str(int(''.join(N)) - 1))
        else:
            N[-1] = str(int(N[-1]) - 1)
    elif len(N) == 1:
        sum += int(N[0])
        del N[0]
    else:
        sum += 9
        del N[-1]

print(sum)

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

using namespace std;

int main()
{
    int i,j,k,n,m,x,y=0,z,a,b;
    cin>>a>>b;
    m=b+b;
    if(m>=a)
    {
        cout<<0<<endl;
    }
    else
    {
        cout<<a-m<<endl;
    }
}


Measured memory_bytes: 256
ans = 0
for i in range(10000):
  n,x = map(int,input().split())
  if n == 0 and x == 0:
    break
  else:
    for i in range(1,n+1):
      for j in range(i+1,n+1):
        for _ in range(j+1,n+1):
          if i+j+_ == x:
            ans += 1
    print(ans)
    ans = 0


Measured memory_bytes: 5592
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <tuple>
#include <cstring>
#include <map>
#include <iomanip>
#include <ctime>
#include <complex>
#include <cassert>
#include <climits>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define len(X) (X).size()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tiii tuple<int, int, int>
#define Tlll tuple<ll, ll, ll>

int main() {
    string s, a, b;
    cin >> s;
    int q;
    cin >> q;
    bool rev = 0;
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            rev = rev ^ 1;
        }
        else {
            int f;  char c;
            cin >> f >> c;
            if ((f + rev) % 2) {
                a += c;
            }
            else b += c;
        }
    }
    if (rev) {
        reverse(all(b));
        reverse(all(s));
        cout << b << s << a << endl;
    }
    else {
        reverse(all(a));
        cout << a << s << b << endl;
    }
}

Measured memory_bytes: 1088
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	string s; cin >> s;
	string ans;
	for (auto i : s)
	{
		if (i == 'B')
		{
			if (ans.empty()) continue;
			else ans.pop_back();
		}
		else ans += i;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <string>
#include <utility>
using namespace std;

int n,m;
pair<int,int> d[10010];

int main(){
	while (1){
		cin >> n >> m;
		if (n == 0) break;
		for (int i = 0; i < n; i++){
			cin >> d[i].second >> d[i].first;
		}
		int exp = 0;
		int dist = 0;
		for (int i = 0; i < n; i++){
			exp += d[i].second * d[i].first;
			dist += d[i].second;
		}
		if (m >= dist) cout << 0 << endl;
		else{
			sort(d, d + n);
			reverse(d, d + n);
			int i = 0;
			while (m > 0){
				if (d[i].second == 0)i++;
				exp -= d[i].first;
				d[i].second -= 1;
				m -= 1;
			}
			cout << exp << endl;
		}
	}
	return 0;
}

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

/*
O(N)で解けそうなのはすぐわかる。
偶数/奇数番目を正/負にするか比べるように実装すると間違いにくい。
*/

long first_plus(vector<int> A) {
    long res = 0;
    long sum = 0;
    for (int i = 0; i < A.size(); i++)
    {
        sum += A[i];
        if (i % 2 == 0)
        {
            while (sum <=0) {
                sum++;
                res++;
            }
        }
        else
        {
            while (sum >=0) {
                sum--;
                res++;
            }
        }
        
    }
    return res;
}

long first_minus(vector<int> A) {
    long res = 0;
    long sum = 0;
    for (int i = 0; i < A.size(); i++)
    {
        sum += A[i];
        if (i % 2 == 0)
        {
            while (sum >= 0) {
                sum--;
                res++;
            }
        }
        else
        {
            while (sum <= 0) {
                sum++;
                res++;
            }
        }
        
    }
    return res;
}

int main() {
    int N;
    cin >> N;

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

    long res1 = first_plus(A);
    long res2 = first_minus(A);
    cout << min(res1, res2) << endl;
}

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

vector<vector<int>> ki;
vector<int> cost;

void sum(int f, int p){
    for(int a:ki[p]){
        if (a != f){
            cost[a] += cost[p];
            sum(p, a);
        }
    }
}

int main(){
    int N, Q;
    cin >> N >> Q;
    ki.resize(N+1);
    cost.resize(N+1, 0);
    for(int i=0; i < N-1; i++){
        int a, b;
        cin >> a >> b;
        ki[a].push_back(b);
        ki[b].push_back(a);
    }
    for(int i=0; i < Q; i++){
        int a, b;
        cin >> a >> b;
        cost[a] += b;
    }
    sum(1, 1);
    for(int i=1; i<N+1; i++){
        cout << cost[i] << " ";
    }
}


Measured memory_bytes: 23424
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#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 all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 105000000000

const int maxn = 1e5 + 10;

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

	int a;
	int count = 0, free = 0;
	int idx[100] = { 0 };
	rep(i, n)
	{
		cin >> a;
		if (a >= 3200) free++;
		else if (idx[a / 400] == 0) count++, idx[a / 400] = 1;
	}

	if (count == 0)count = 1, free--;

	cout << count <<" "<< count + free << endl;

	return 0;
	
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline

def main():
    ans = 0
    n = int(input())
    o = list(map(int, input().split()))
    l = [0]*n
    for i in range(n):
        l[o[i]-1] = i+1
    for i in range(len(l)):
        if  i != len(l)-1:
            print("{} ".format(l[i]), end='')
        else:
            print(l[i])

if __name__ == '__main__':
    main()

Measured memory_bytes: 13304
#include <iostream>
#include <string>

using namespace std;

int top, s[1000];

void push(int x) { s[++top] = x; }

int pop() {
  top--;
  return s[top + 1];
}
int main() {
  top = 0;
  string c;
  while (cin >> c) {
    if (c[0] == '+') {
      int k = pop();
      int k2 = pop();
      push(k2 + k);
    } else if (c[0] == '-') {
      int k = pop();
      int k2 = pop();
      push(k2 - k);
    } else if (c[0] == '*') {
      int k = pop();
      int k2 = pop();
      push(k2 * k);
    } else {
      push(stoi(c));
    }
  }
  cout << pop() << endl;
  return 0;
}


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


int main(){
	int N,M;
	cin >> N >> M;
	vector<int> H(N);
	rep(i,N)cin >> H[i];
	vector<int> C(N);
	rep(i,M){
		int a,b; cin >> a >> b; a--; b--;
		if(H[a]>H[b])C[b]=-1;
		if(H[b]>H[a])C[a]=-1;
		if(H[a] == H[b]){C[a]=-1; C[b]=-1; }
	}

	int ans = count(C.begin(),C.end(),0);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4000
N,M = map(int,input().split())
A = sorted(list(map(int,input().split())))
Ap = {}
for _ in range(M):
  B,C = map(int,input().split())
  if C in Ap.keys():
    Ap[C] = Ap[C]+B
  else:
    Ap[C] = B
Clist = sorted(Ap.keys())
nc = len(Clist)
i,j,k = 0,0,0
count = 0
a = A[N-1]
while i+j < N:
  if k<nc:
    c = Clist[nc-k-1]
    b = Ap[c]
  else:b,c = 0,0
  if a>=c:
    count += a
    i += 1
    a = A[N-i-1]
  elif c>a:
    count += b*c if i+j+b<N else c*(N-i-j)
    j += b
    k += 1
print(count)

Measured memory_bytes: 23464
def fail!
    puts 'No'
    exit
end

N = gets.to_i
ps = [0] + N.times.map{gets.to_i}
INF = 10**9

same = (0..N).map{|i| ps[i] == i}

blocks = []
pool = []
(1..N).each do |i|
    if same[i]
        if same[i-1] && pool.length > 0
            blocks.push(pool)
            pool = []
        end
    else
        if i > 1 && !same[i-1]
            unless i >= 4 && same[i-2] && !same[i-3]
                fail!
            end
            if pool.length > 0
                blocks.push(pool)
                pool = []
            end
        end
        pool.push(i)
    end
end
blocks.push(pool) if pool.length > 0

blocks.each do |bl|
    mini, maxi = bl.minmax
    minp, maxp = bl.map{|i| ps[i]}.minmax
    fail! unless mini == minp && maxi == maxp

    l, r = 0, 0
    bl.each do |i|
        if ps[i] < i
            fail! if l > ps[i]
            l = ps[i]
        else
            fail! if r > ps[i]
            r = ps[i]
        end
    end
end
puts 'Yes'

Measured memory_bytes: 13908
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf=1e15;
const int maxn=105;
int n,m,s,t,G[105][105],cost[105][105],pre[maxn];
ll d[maxn];
bool inq[maxn];
void read(int& ret)
{
	ret=0;
	char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') ret=(ret<<3)+(ret<<1)+ch-'0',ch=getchar();
}
void build()
{
	for(int i=1;i<=n;i++) G[s][i]=m;
	for(int i=n+1;i<t;i++) G[i][t]=m;
	for(int i=1,x;i<=n;i++){
		for(int j=n+1;j<t;j++){
			read(x);
			G[i][j]=1,cost[i][j]=-x,cost[j][i]=x;
		}
	}
}
bool SPFA()
{
	queue<int> q;
	for(int i=0;i<=t;i++) d[i]=inf;
	q.push(s),d[s]=0;
	while(!q.empty()){
		int u=q.front();
		q.pop(),inq[u]=false;
		for(int i=0;i<=t;i++){
			if(G[u][i]>0&&d[i]>d[u]+cost[u][i]){
				d[i]=d[u]+cost[u][i];
				pre[i]=u;
				if(!inq[i]){
					inq[i]=true;
					q.push(i);
				}
			}
		}
	}
	return d[t]<0;
}
int main()
{
	read(n),read(m);
	s=0,t=2*n+1;
	build();
	ll ans=0;
	while(SPFA()){
		ans-=d[t];
		for(int i=t;i!=s;i=pre[i]){
			G[pre[i]][i]--;
			G[i][pre[i]]++;
		}
	}
	printf("%lld\n",ans);
	for(int i=1;i<=n;i++){
		for(int j=n+1;j<t;j++){
			if(G[i][j]!=1) printf("X");
			else printf(".");
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

ll N, M, A, B;
vector<ll> E[100000];
bool visited[100000];

bool check(ll v) {
  bool ret = true;
  for(ll u : E[v]) ret = ret & visited[u];
  return ret;
}

int main(void) {
  cin >> N >> M;
  REP(i, 0, M) {
    cin >> A >> B; A--; B--;
    E[A].push_back(B);
    E[B].push_back(A);
  }

  REP(i, 0, N) visited[i] = false;

  deque<ll> deq;
  deq.push_front(0);
  deq.push_back(E[0][0]);
  visited[0] = visited[E[0][0]] = true;

  while(1) {
    bool front_ok = check(deq.front()), back_ok = check(deq.back());
    if(front_ok && back_ok) break;
    if(!front_ok) {
      for(ll u : E[deq.front()]) if(!visited[u]) {
        deq.push_front(u);
        visited[u] = true;
        break;
      }
    }
    if(!back_ok) {
      for(ll u : E[deq.back()]) if(!visited[u]) {
        deq.push_back(u);
        visited[u] = true;
        break;
      }
    }
  }

  cout << deq.size() << endl;
  REP(i, 0, deq.size()) cout << deq[i] + 1 << (i + 1 != deq.size() ? " " : "\n");
}


Measured memory_bytes: 7168
using System;
class Program{
 static void Main(){
while(true){
  string[] s = Console.ReadLine().Split(' ');
  int a = int.Parse(s[0]);
  string op = s[1];
  int b = int.Parse(s[2]);
  if(op == "+"){
   Console.WriteLine(a + b);
  }
  if(op == "-"){
   Console.WriteLine(a - b);
  }
  if(op == "*"){
   Console.WriteLine(a * b);
  }
  if(op == "/"){
   Console.WriteLine(a / b);
  }
  if(op == "?"){
   return;
  }
}
}
}

Measured memory_bytes: 9144
def f n
  ret = 0
  while n > 0
    ret += n % 10
    n /= 10
  end
  ret
end

def g n
  n.to_f / f(n)
end

K = gets.to_i
ret = []
data = 1
15.times { (2..200).to_a.each {|i| ret.push(data * i - 1)}; data *= 10 }
ret.uniq!
ret.sort
ans = ret.select.with_index {|num,i| flg = true; ret[i..((i+10) < ret.size ? (i+10) : -1)].each {|num2| flg = false if g(num) > g(num2) } ; flg }
puts ans[0...K]

Measured memory_bytes: 2044
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
//ll dx[4] = {1, 0, -1, 0};
//ll dy[4] = {0, 1, 0, -1};

vector<ll> g[114514];
vector<ll> h[114514];
bool used[114514] = {};
ll d[114514];
void dfs(int from, int now, int cnt) {
	if (cnt == 0) {
		if (from != now) h[from].push_back(now);

		return;
	}
	for (int i = 0; i < g[now].size(); i++) {
		dfs(from, g[now][i], cnt - 1);
	}
	return;
}

int main() {
	IOS();
	ll n;
	cin >> n;
	vector<ll> p(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	ll ans = 0;
	for (int i = 1; i < n - 1; i++) {
		if (p[i - 1] > p[i] && p[i + 1] < p[i]) ans++;
		if (p[i - 1] < p[i] && p[i + 1] > p[i]) ans++;
	}
	dump(ans);
	return 0;
}


Measured memory_bytes: 5632
#include<iostream>
using namespace std;
int main()
{
  int x, i, j;
  cin >> x;
  int ans = 1;
  int a;
    // 整数の入力
 for (i = 2; i < x; i++){
   a = i;
   for (j = 2; j < 10; j++){
     a *= i;
      if (a > x) break;
     if (a > ans) ans = a;
    
   }
 }
  cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define REP(i,x,n) for(int i = (x); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);

int main(void)
{
    ll n, four=0, two=0;
    cin >> n;
    rep(i,n){
        ll a;
        cin >> a;
        if(a%4 == 0) four++;
        else if(a%2 == 0) two++;
    }
    if(four*2+max(0LL, two-1) >= n-1) puts("Yes"); 
    else puts("No");
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int ll
#define pii pair <int,int>
#define pipii pair <int,pair <int,int>>
#define mp make_pair
#define sz(var) (int)var.size()
const int maxinput=100005;
const int inf=1e15+7;
#define vi vector <int>
signed main() 
{
    FAST
    int n,w;cin>>n>>w;
    int a[n+1][2]; //weight,val, 1 based indexing
    for(int i=1;i<=n;i++)
        cin>>a[i][0]>>a[i][1];
    //dp[i][j] is minimum weight required to gain j profit when we have only seen first i elements
    //dp[i][j] = min(dp[i-1][j], dp[i-1][j-val[i]]+wt[i])
    //base case: dp[0][j] is 0 as if no elment are their then then min weight to gain j profit is infinity
    //dp[i][0] is 0 as for 0 profit min weight required is 0
    int maxv=1e5+5;
    int dp[2][maxv+5];
    for(int j=0;j<=maxv;j++)
        dp[0][j]=inf;

    dp[0][0]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=maxv;j++)
        {
            if(a[i][1]<=j)
                dp[1][j]=min(dp[0][j],dp[0][j-a[i][1]]+a[i][0]);
            else
                dp[1][j]=dp[0][j];
        }
        for(int j=0;j<=maxv;j++)
            dp[0][j]=dp[1][j];
    }
    int ans=0;
    for(int j=0;j<=maxv;j++)
        if(dp[0][j]<=w)
            ans=j;
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#define r(i,n) for(int i=0; i<n; i++)
typedef long long ll;
using namespace std;

int main(void){
  ll a;
  cin >> a;
  ll ans = a/11*2;
  if(a%11!=0 && a%11<=6){
    ans++;
  }
  if(a%11>6){
    ans+=2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long int
#define fast       ios_base::sync_with_stdio(false); cin.tie(NULL);
 
int main() {
    fast
    ll n;
    cin>>n;
    map <string ,int> A;
    string str;
    for(ll i=0;i<n;i++){
        cin>>str;
        A[str]++;
    }
    ll x = A.size();
    cout<<x<<"\n";
}

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


int main(){
    string S,T;
    int a, b;
    string U;
    cin>>S>>T;
    cin>>a>>b;
    cin>>U;
    if(U==S)cout<<a-1<<" "<<b<<endl;
    else cout<<a<<" "<<b-1<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

K = int(readline())

from collections import deque
q = deque([i for i in range(1,10)])

cnt = 0
while q:
  n = q.popleft()
  cnt += 1
  if cnt == K:
    print(n)
    break
  right = n % 10
  for c in range(max(right - 1, 0),min(right + 2,10)):
    q.append(n * 10 + c)
    


Measured memory_bytes: 19628
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    int n, a, b; cin >> n >> a >> b;
    if(a*n > b){
        pr(b);
    }else{
        pr(a*n);
    }
    return 0;}

Measured memory_bytes: 3620
from copy import deepcopy

D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(D)]

def func(ans_lst):
    last = {}
    for i in range(1,27):
        last[i] = 0
    for i in range(5):
        last[ans_lst[i]] = i+1

    total_sat = 0
    for d in range(6,D+1):
        ans = [1,-float('inf')]
        for i in range(1,27):
            satisfaction = 0
            satisfaction += s[d-1][i-1]
            for j in range(1,27):
                if i != j:
                    satisfaction -= c[j-1]*(d-last[j])
            if ans[1] <= satisfaction:
                ans = [i,satisfaction]
        last[ans[0]] = d
        ans_lst.append(ans[0])
        total_sat += ans[1]
    return [total_sat,ans_lst]

def rec(d,ans_lst):
    if d == 6:
        return func(ans_lst)
    ans_lst1 = deepcopy(ans_lst)
    ans_lst2 = deepcopy(ans_lst)

    a,b,*gomi = sorted(s[d-1],reverse=True)
    ans_lst1.append(s[d-1].index(a)+1)
    ans_lst2.append(s[d-1].index(b)+1)
    ret = [rec(d+1,ans_lst1),rec(d+1,ans_lst2)]
    ret.sort(reverse=True)
    return ret[0]

out = rec(1,[])
for i in range(365):
    print(out[1][i])

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

int health, n, dmg[1005], cost[1005];
int dp[10005][1005];

int solve(int health, int pos){
  if(health <= 0) return 0;
  if(pos >= n) return 1e9;

  int &res = dp[health][pos];
  if(res != -1) return res;
  res = INT_MAX;
  res = min(res, solve(health, pos+1));
  res = min(res, solve(health-dmg[pos], pos) + cost[pos]);
  return res;
}

int main(){

  ios_base :: sync_with_stdio(false);

  cin >> health >> n;
  for(int i=0; i<n; i++) cin >> dmg[i] >> cost[i];
  memset(dp, -1, sizeof(dp));

  cout << solve(health, 0) << endl;
  return 0;
}

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

int main(){
while(true){
 int n;
 int m=10000000;
 cin>>n;

 if(n==0)break;

 int s[n];
 for(int i=0;i<n;i++){
	cin>>s[i];
 }

 sort(s,s+n);

 for(int i=0;i<n-1;i++){
	if(s[i+1]-s[i]<m){
		m=s[i+1]-s[i];
	}
 }
 cout<<m<<endl;
}
 return 0;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}

ll n,k;
vector<ll> pos,neg;
ull mincou = 0;
ull plucou = 0;
ull zerocou = 0;

//bool solve(ll k){
//  ll sum = 0;
//  if(k > 0){
//    sum += mincou + zerocou;
//    rep(i,pos.size()){
//      t1 = k / pos[i];
//      sum += upper_bound(all(pos),t1) - pos.begin();
//    }
//    rep(i,neg.size()){
//      t1 = k / pos[i];
//      sum +=
//    }
//  }else if(k == 0){
//    return mincou < k && k <= mincou + zerocou;
//  }
//  return sum >= k;
//}
//
//ll calc(ll k){
//
//}
//

int main(){
  cin >> n >> k;
  ll n_pos,n_zero,n_neg;
  rep(i,n){
    cin >> t1;
    if(t1 > 0){
      pos.push_back(t1);
    }else if(t1 == 0){

    }else{
      neg.push_back(t1);
    }
  }
  sort(all(pos));
  sort(all(neg));
  mincou = pos.size() * neg.size();
  plucou = pos.size() * (pos.size() - 1) / 2 + neg.size() * (neg.size() - 1) / 2;
  zerocou = n * (n - 1) / 2 - mincou - plucou;

  ll f0 = mincou;
  ll f1 = mincou + zerocou;
  ll ans = 0;
  n_pos = pos.size();
  n_neg = neg.size();
  if(k <= f0){
    ll ok = 0;
    ll ng = -1e18-1;
    while(abs(ok-ng) > 1){
      ll mid = (ok + ng) / 2;
      ll sum = 0;
      ll j = n_pos - 1;
      rep_rev(i,n_neg){
        while (j >= 0 && neg[i] * pos[j] <= mid) j--;
        sum += n_pos - 1 - j;
      }
      if(sum >= k){
        ok = mid;
      }else{
        ng = mid;
      }
    }
    ans = ok;
  }else if(k <= f1){
    ans = 0;
  }else{
    ll ok = 1e18+1;
    ll ng = 0;
    while(abs(ok-ng) > 1){
      ll mid = (ok + ng) / 2;
      ll sum = f1;
      int j = n_neg - 1;
      for (int i = 0; i < n_neg - 1; i++) {
        while (j >= 0 && neg[i] * neg[j] <= mid) j--;
        sum += min(n_neg - j - 1, n_neg - i - 1);
      }

      j = 0;
      for (int i = n_pos - 1; i >= 1; i--) {
        while (j < n_pos && pos[i] * pos[j] <= mid) j++;
        sum += min(i, j);
      }
      if (sum >= k){
        ok = mid;
      }else {
        ng = mid;
      }
    }
    ans = ok;
  }
  cout << ans << endl;
}



Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
int a[10],p[10],q[10];
int main()
{
	int n,x,y,cn=0;
	cin>>n;
	for(int i=0;i<n;i++) cin>>p[i];
	for(int i=0;i<n;i++) cin>>q[i];
	for(int i=0;i<n;i++) a[i]=i+1;
	do{
		bool ch=true;
		for(int i=0;i<n;i++){
			if(a[i]!=p[i]) ch=false;
		}
		if(ch){
			x=cn;
			break;
		}
		cn++;
	}while(next_permutation(a,a+n));
	
	cn=0;
	for(int i=0;i<n;i++) a[i]=i+1;
	do{
		bool ch=true;
		for(int i=0;i<n;i++){
			if(a[i]!=q[i]) ch=false;
		}
		if(ch){
			y=cn;
			break;
		}
		cn++;
	}while(next_permutation(a,a+n));
	cout<<abs(x-y);
	return 0;
}

Measured memory_bytes: 256
import sys

def to_f(e):
  return float(e)

while True:
  line = sys.stdin.readline()
  if not line: break
  a,b,c,d,e,f = map(to_f, line.rstrip().split(" "))
  x = (c*e-b*f)/(a*e-d*b)
  y = (c*d-a*f)/(b*d-a*e)
  if x == 0:
    x = 0

  if y == 0:
    y = 0

  sys.stdout.write("{0:.3f}".format(x))
  sys.stdout.write(" ")
  print "{0:.3f}".format(y)

Measured memory_bytes: 6320
# import math
import fractions
n, start = list(map(int, input().split()))
x = list(map(int, input().split()))

ans = abs(start - x[0])
for i in range(1, n):
	dist = abs(start - x[i])
	# ans = math.gcd(ans, dist)
	# Python 3.5以上では正解になるはずだが、AtCoderでは3.4.3なのでmath.gcdが使えず、ランタイムエラーになる
	# 3.4以前ではfractions.gcdを使う必要がある。fractions.gcdは3.5以降では非推奨である
	ans = fractions.gcd(ans, dist)
print(ans)


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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;  cin >> n;
    ll ans = 0;
    vector<int> a(n + 1), b(n);
    rep(i, n + 1) {
      cin >> a[i];
    }
    rep(i, n) {
      cin >> b[i];
    }

    rep(i, n) {
      if (b[i] >= a[i]) {
        b[i] -= a[i];
        ans += a[i];
        a[i] = 0;
        if (b[i] >= a[i + 1]) {
          ans += a[i + 1];
          a[i + 1] = 0;
        } else {
          a[i + 1] -= b[i];
          ans += b[i];
        }
      } else {
        ans += b[i];
      }
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
#define llint long long

using namespace std;

llint n;
string s;
set<string> S;

int main(void)
{
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> s;
		S.clear();
		for(int j = 1; j < s.size(); j++){
			string t = s.substr(0, j), u = s.substr(j);
			string revt = t, revu = u;
			reverse(revt.begin(), revt.end());
			reverse(revu.begin(), revu.end());
			
			S.insert(t+u);
			S.insert(revt+u);
			S.insert(t+revu);
			S.insert(revt+revu);
			
			S.insert(u+t);
			S.insert(revu+t);
			S.insert(u+revt);
			S.insert(revu+revt);
		}
		cout << S.size() << endl;
	}
}


Measured memory_bytes: 3164
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;


public class Main {
	
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
	

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
    public static long mod = (long) (1e9+7);
    public final static int MAX = (int) 90000000;
  // static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
	   
	 FastReader sc = new FastReader();
		
	int h = sc.nextInt();
	int w = sc.nextInt();
	List<Pair> temp = new ArrayList<>();
	boolean[][] tab = new boolean[h][w];
	
	for(int i=0;i<h;++i) {
		String s = sc.next();
		for(int j=0;j<w;++j) {
			if(s.charAt(j) == '#') {
				tab[i][j] = true;
				temp.add(new Pair(i,j));
			}
		}
	}
	int[] dx = {0,0,-1,1};
	int[] dy = {-1,1,0,0};
		
	int black = temp.size();
	int ans = 0;
	while(black != h*w) {
		List<Pair> last = new ArrayList<>();
		for(Pair p : temp) {
			for(int i=0;i<dx.length;++i) {
				Pair pr = new Pair(p.x+dx[i],p.y+dy[i]);
				if(inGrid(pr.x,pr.y,h,w) && !tab[pr.x][pr.y]) {
					last.add(pr);
					tab[pr.x][pr.y] = true;
				}
			}
		}
		
		temp = last;
		black+=temp.size();
		++ans;
	}
	out.println(ans);
	
 	out.close();
	}
	
	 private static boolean inGrid(int x, int y, int h, int w) {
		 if(x>=0 && y>=0 && x<h && y<w)
			 return true;
	    
	return false;
}

	static class Pair{
	    	int x;
	    	int y;
	    	Pair(int x,int y){
	    		this.x=x;
	    		this.y=y;
	    	}
	    	@Override
	        public int hashCode() {
	            final int prime = 31;
	           int  result = prime * x + y; 
	            return result;
	        }
	    	
	    	 @Override
	    	    public boolean equals(Object obj) {
	    	        if (this == obj)
	    	            return true;
	    	        if (obj == null)
	    	            return false;
	    	        if (getClass() != obj.getClass())
	    	            return false;
	    	        Pair other = (Pair) obj;
	    	        if (x != other.x && y != other.y)
	    	            return false;
	    	        return true;
	    	    }
	    	 @Override
	    	 public String toString() {
	    		 return "{"+String.valueOf(x)+","+String.valueOf(y)+"}";
	    	 }
	    	
	    }
}

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

int main() {
    int n;
    cin >> n;
    vector<int> t(n+1);
    vector<int> x(n+1);
    vector<int> y(n+1);
    t[0] = 0; x[0] = 0; y[0] = 0;
    for(int i = 0; i < n; i++) {
        cin >> t[i] >> x[i] >> y[i];
    }

    int fx = 0;
    int fy = 0;
    for(int i = 1; i < n+1; i++) {
        int xl = abs(x[i]-x[i-1]);
        int yl = abs(y[i]-y[i-1]);
        int td = abs(t[i]-t[i-1]);
        //cout << xl << " " << yl << " " << td << endl;
        //cout << (xl+yl)%2 << " " << (t[i]-t[i-1])%2 << endl;
        if(xl+yl <= td && ((xl+yl)%2 == (td)%2)) {
            //cout << i << endl;
        }
        else {
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1408
N = int(input())
A = list(map(int,input().split()))
from collections import defaultdict
d = defaultdict(int)
for a in A:
  d[a] += 1

keisan = dict()

for key,value in d.items():
  keisan[key] = (value * (value-1)) // 2
res = sum(keisan.values())
# print(d,keisan)
for a in A:
  # 合計から必要なくなった部分を除去する
  val = d[a]
  
  print(res - ((val*(val-1))//2) +(((val-1)*(val-2))//2)  )


Measured memory_bytes: 96588
"""
a = int(x*0.08)
a <= x*0.08 < a+1
a/0.08 <= x < (a+1)/0.08

b = int(x*0.1)
b <= x*0.1 < b+1
b/0.1 <= x < (b+1)/0.1
"""

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
a,b = [int(i) for i in readline().split()]

for i in range(10000):
    if i * 8 // 100 == a and i * 10 // 100 == b:
        print(i)
        break
else:
    print(-1)


Measured memory_bytes: 3060
import java.util.*;
public class Main {
	
	public static int gcd(int a, int b) {
		return b == 0 ? a: gcd(b, a % b);
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int ans = 0;
		for(int i = 1; i <= K; i++) {
			for(int j = 1; j <= K; j++) {
				int x = gcd(i, j);
				for(int k = 1; k <= K; k++) {
					ans += gcd(x, k);
				}
			}
		}
		System.out.println(ans);
	}

}

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

namespace Saikoro
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] men = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var saikoro=new Saikoro(men);
            foreach(char c in Console.ReadLine())
            {
                saikoro.Move(c);
            }
            
            saikoro.showTop();
        }
    }
    class Saikoro
    {
        public int[] men { get; set; }

        public Saikoro(int[] men)
        {
            this.men = men;
        }
        public void  showTop()
        {
            Console.WriteLine(men[0]);
        }

        public void Move(char c)
        {
            switch (c)
            {
                case 'N':
                    N();
                    break;
                case 'S':
                    S();
                    break;
                case 'E':
                    E();
                    break;
                case 'W':
                    W();
                    break;
                default:
                    break;
            }
        }
        public void N()
        {
            var temp = (int[])men.Clone();
            men[0] = temp[1];
            men[1] = temp[5];
            men[5] = temp[4];
            men[4] = temp[0];
        }
        public void W()
        {
            var temp =(int[]) men.Clone();
            men[0] = temp[2];
            men[2] = temp[5];
            men[5] = temp[3];
            men[3] = temp[0];
        }
        public void E()
        {
            var temp = (int[])men.Clone();
            men[2] = temp[0];
            men[5] = temp[2];
            men[3] = temp[5];
            men[0] = temp[3];
        }
        public void S()
        {
            var temp = (int[])men.Clone();
            men[0] = temp[4];
            men[4] = temp[5];
            men[5] = temp[1];
            men[1] = temp[0];

        }
    }
}



Measured memory_bytes: 18440
N = int(input())

mymax1 = -99
mymax2 = -9
mycnt = -1


for i in range(N):
  mynum = int(input())
  if mynum > mymax1:
    mymax1 = mynum
    mycnt = i
  else:
    if mynum > mymax2:
      mymax2 = mynum
for i in range(N):
  if i == mycnt:
    print(mymax2)
  else:
    print(mymax1)

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

//template
#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 ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
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; }
//template end



int main(){
   int n; scanf("%d",&n);
   vector<int> a(n); rep(i,0,n)scanf("%d",&a[i]);
   int d=*max_element(ALL(a));
   int cnt[110]={}; rep(i,0,n)cnt[a[i]]++;
   rep(i,0,d+1){
      int idx=max(i,d-i);
      if(!cnt[idx]){printf("Impossible\n"); return 0;}
      cnt[idx]--;
   } d=(d+1)/2;
   rep(i,0,d+1)if(cnt[i]){printf("Impossible\n"); return 0;}
   printf("Possible\n");
   return 0;
}

Measured memory_bytes: 256
import math
def main():
    while True:
        _factorial = int(input())
        if _factorial == 0:
            break
        _factorial = math.factorial(_factorial)
        count = 0
        for value in (str(_factorial))[::-1]:
            if value == '0':
                count += 1
            else:
                break
        print(count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5800
// C - 2D Plane 2N Points

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

pair<int, int> red[100];
pair<int, int> blue[100];
bool used_red[100];

int main() {
	int N;
	cin >> N;

	for (int i=0; i<N; i++) {
		int a, b;
		cin >> a >> b;
		red[i] = make_pair(a, b);
	}

	for (int i=0; i<N; i++) {
		int c, d;
		cin >> c >> d;
		blue[i] = make_pair(c, d);
	}

	sort(blue, blue+N);

	int ans = 0;

	for (int i=0; i<N; i++) {
		int bx = blue[i].first;
		int by = blue[i].second;

		int max_ry = -1;
		int max_red_idx = -1;
		for (int j=0; j<N; j++) {
			int rx = red[j].first;
			int ry = red[j].second;

			if (rx < bx && ry < by && ry > max_ry && used_red[j] == false) {
				max_red_idx = j;
				max_ry = ry;
			}
		}

		if (max_red_idx != -1) {
			ans++;
			used_red[max_red_idx] = true;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3604
import numpy as np

n = int(input())

left = np.zeros(n)
right = np.zeros(n)
for i in range(n):
    x, l = map(int, input().split())
    left[i] = int(x-l)
    right[i] = int(x+l)

sort_ind = np.argsort(right)
left = left[sort_ind]
right = right[sort_ind]

ans = 0
right_now = -1 * 10**10
for i in range(n):
    if(left[i] >= right_now):
        ans += 1
        right_now = right[i]

print(ans)

Measured memory_bytes: 24732
import java.util.Scanner;

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

        int n = sc.nextInt();
        int ret = 999999;
        for(int i = 0; i <= n ; i++ ){
            int c = 0;
            int a = i;
            while(a > 0){
                c += a % 9;
                a = a / 9;
            }
            a = n - i;
            while(a > 0){
                c += a % 6;
                a = a / 6;
            }
            if(ret > c){
                ret = c;
            }
        }
        System.out.println(ret);

    }
}

Measured memory_bytes: 21972