akhauriyash/Code-Regression huggingface dataset:
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(){
		
		int[] bcnt = new int[1 << 20];
		for(int i=0;i<(1 << 20);i++){
			for(int j=0;j<20;j++) if((i >> j) % 2 == 1) bcnt[i]++;
		}
		
		int xor = A ^ B;
		if(bcnt[xor] % 2 != 1){
			Console.WriteLine("NO");
			return;
		}
		if(N == 1){
			Console.WriteLine("YES");
			Console.WriteLine("{0} {1}",A,B);
			return;
		}
		
		int[] g0 = CreateCode(N, bcnt[xor]);
		List<int> one = new List<int>();
		List<int> zero = new List<int>();
		for(int i=0;i<N;i++){
			if((xor >> i) % 2 == 0) zero.Add(i);
			if((xor >> i) % 2 == 1) one.Add(i);
		}
		int[] map = new int[N];
		for(int i=0;i<one.Count;i++){
			map[one[i]] = N - 1 - i;
		}
		for(int i=0;i<zero.Count;i++){
			map[zero[i]] = N - 1 - (i + one.Count);
		}
		
		int[] g = new int[1<<N];
		for(int i=0;i<1<<N;i++){
			for(int j=0;j<N;j++){
				int v = (g0[i] >> map[j]) % 2;
				g[i] |= (v << j);
			}
		}
		
		int[] ans = new int[1 << N];
		for(int i=0;i<(1<<N);i++){
			ans[i] = A ^ g[i];
		}
		
		Console.WriteLine("YES");
		Console.WriteLine(String.Join(" ",ans));
		
		
	}
	
	int[] CreateCode(int n, int b){
		int[] a = new int[]{0,1,3,2};
		int[] ax = new int[]{2,3,1,0};
		int[] aa = new int[]{2,0,1,3};
		int[] a2 = new int[]{0,1};
		int[] a2x = new int[]{1,0};
		int[][] dp = new int[n + 1][];
		for(int i=0;i<=n;i++) dp[i] = new int[1 << i];
		
		dp[1][0] = 0;
		dp[1][1] = 1;
		int bb = b / 2;
		int now = 1;
		for(int k=0;k<bb;k++){
			int nt = now + 2;
			for(int j=0;j<dp[now].Length;j++){
				if(j % 2 == 0){
					for(int t=0;t<4;t++){
						dp[nt][j * 4 + t] = (dp[now][j] << 2) + a[t];
					}
				} else if(j == dp[now].Length - 1){
					for(int t=0;t<4;t++){
						dp[nt][j * 4 + t] = (dp[now][j] << 2) + aa[t];
					}
				} else {
					for(int t=0;t<4;t++){
						dp[nt][j * 4 + t] = (dp[now][j] << 2) + ax[t];
					}
				}
			}
			now = nt;
		}
		while(now != n){
			int nt = now + 1;
			for(int j=0;j<dp[now].Length;j++){
				if(j % 2 == 0){
					for(int t=0;t<2;t++){
						dp[nt][j * 2 + t] = (dp[now][j] << 1) + a2[t];
					}
				}else {
					for(int t=0;t<2;t++){
						dp[nt][j * 2 + t] = (dp[now][j] << 1) + a2x[t];
					}
				}
			}
			now = nt;
		}
		
		return dp[n];
	}
	int N,A,B;
	public Sol(){
		var d = ria();
		N = d[0]; A = d[1]; B = d[2];
	}

	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: 26972
import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce

sys.setrecursionlimit(4100000)
INF = 1 << 60
MOD = 10 ** 9 + 7

# ここから書き始める
s = input()
if s[2] == s[3] and s[4] == s[5]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 5988
package main

import (
	"bufio"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

var n int
var G map[int]map[int]int

func initGraph() {
	G = make(map[int]map[int]int, n)
}

func add(from, to, weight int) {
	if _, ok := G[from]; !ok {
		G[from] = make(map[int]int)
	}
	G[from][to] = weight
}

var depth []int

func dfs(v, p, d int) {
	depth[v] = d
	for t, w := range G[v] {
		if t == p {
			continue
		}
		dfs(t, v, d+w)
	}
}

func main() {
	n = readInt()
	initGraph()
	for i := 0; i < n-1; i++ {
		a, b, c := readInt(), readInt(), readInt()
		add(a, b, c)
		add(b, a, c)
	}

	q, k := readInt(), readInt()
	depth = make([]int, n+1)
	dfs(k, -1, 0)
	var wr = bufio.NewWriter(os.Stdout)
	for i := 0; i < q; i++ {
		x, y := readInt(), readInt()
		wr.WriteString(strconv.Itoa(depth[x]+depth[y]) + "\n")
	}
	wr.Flush()
}


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

int main()
{
    string s;
    cin >> s;
    for (int i = 0; i < s.length(); i++)
    {
        if (i % 2 == 0)
        {
            if (s[i] == 'L')
            {
                cout << "No" << endl;
                return 0;
            }
        }
        if (i % 2 != 0)
        {
            if (s[i] == 'R')
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define NIL -1
#define MAX 30
 
using namespace std;
 
struct Node { int parent, left, right; };
 
Node T[MAX];int n;
 
void preParse(int u) {
    if (u == NIL)return;
    cout<<" "<<u;
    preParse(T[u].left);
    preParse(T[u].right);
}
 
void inParse(int u) {
    if (u == NIL)return;
    inParse(T[u].left);
    cout <<" "<<u;
    inParse(T[u].right);
}
 
void postParse(int u) {
    if (u == NIL)return;
    postParse(T[u].left);
    postParse(T[u].right);
    cout <<" "<< u;
}
 
int main() {
    int id, left, right,root;
    cin >> n;
    for (int i = 0;i < n;++i)T[i].parent=T[i].left=T[i].right=NIL;
    for (int i = 0;i < n;++i) {
        cin >> id >> left >> right;
        T[id].left = left;
        T[id].right = right;
        if (left != NIL)T[left].parent = id;
        if (right != NIL)T[right].parent = id;
    }
 
    for (int i = 0;i < n;++i)if (T[i].parent == NIL)root = i;
    cout << "Preorder" << endl;
    preParse(root);
    cout << endl;
    cout << "Inorder" << endl;
    inParse(root);
    cout << endl;
    cout << "Postorder" << endl;
    postParse(root);
    cout << endl;
     
    return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,p;
    cin >> n >> p;

    map<ll,int> mp;
    ll d=2;
    while(d*d<=p) {
        if(p%d) d++;
        else{
            p/=d;
            mp[d]++;
        }
    }
    mp[p]++;

    for(auto itr = mp.begin(); itr !=mp.end(); itr++) cerr << itr->first << " " << itr->second << "\n";

    ll ans=1;
    for(auto itr = mp.begin(); itr !=mp.end(); itr++) {
        ll f=itr->first;
        ll s=itr->second/n;
        if(s) ans*=pow(f,s);
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3980
X, N = map(int, input().split())
p = set(map(int, input().split()))

if N == 0:
    print(X)
else:
    for i in range(100):
        # 左からと右からを交互に計算
        left = X - i
        right = X + i

        if left not in p:
            print(left)
            break
        if right not in p:
            print(right)
            break


Measured memory_bytes: 9176
import java.util.Scanner;

public class Main {
	public static long mod = 1000000000+7;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n];
		long ans = 0;
		long count1 = 0;
		long count0 = 0;
		boolean flag = true;

		for (int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
		}

		for (int i = 0; i < 100; i++) {
			count1 = 0;
			count0 = 0;
			flag = true;
			for (int j = 0; j < n; j++) {
				long b = a[j];
				if(b != 0) flag = false;
				if((b&1) == 1) count1 += 1;
				else count0 += 1;
				a[j] = b>>1;
			}
			if(flag) break;
			ans += ((count0*count1)%mod)*pow(2,i);
			ans = ans%mod;
		}

		System.out.println(ans%mod);
		sc.close();
	}
	public static final long pow(long x, long n) {
	    long sum = 1;
	    while (n > 0) {
	        if ((n & 1) == 1) {
	            sum = sum * x % mod;
	        }
	        x = x*x%mod;
	        n >>= 1;
	    }
	    return sum;
	}
}

Measured memory_bytes: 98980
#include <iostream>
using namespace std;
char a[7500000];
int n,m;

int check(){
	int count=0;
	for(int i=n;i<7500000;i++){
		if(a[i]=='1')continue;
		if(count==m)return i;
		for(int j=i;j<7500000;j+=i){
			a[j]='1';
		}
		count++;
	}
}

int main(){
	while(1){
		cin >>n>>m;
		if(!(n||m))break;
		for(int i=n;i<7500000;i++){
			a[i]='0';	
		}
		cout<<check()<<endl;
	}
}

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

using namespace std;
typedef long long ll;

int main(){
  int N,M,X;
  cin >> N >> M >> X;
  int c[N];
  int a[N][M];
  for(int i=0;i<N;i++){
    cin >> c[i];
    for(int j=0;j<M;j++){
      cin >> a[i][j];
    }
  }
  
  ll ans = 10000000;
  ll now;
  for(int bit=0;bit<(1<<N);++bit){
    now = 0;
    vector<int> ok(M,0);
    bool flag = true;
    for(int i=0;i<N;i++){
      if(bit & (1<<i)){
	now += c[i];
	for(int j=0;j<M;j++){
	  ok[j] += a[i][j];
	}
      }
    }
    for(int j=0;j<M;j++){
      if(ok[j]<X) flag = false;
    }
    if(flag) ans = min(ans,now);
  }
  if(ans==10000000) cout << -1 <<endl;
  else cout << ans << endl;
  
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll A, B;
  cin >> A >> B;
  for (ll i = 1; i <= 3; i++)
  {
    if (A != i && B != i)
      FINALANS(i);
  }
}

Measured memory_bytes: 256
// #include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <bitset>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define trace(x) cerr << #x << ": " << x << " " << endl;
 
typedef int64_t ll;
 
#define endl '\n'
#define int ll
ll mod=1e9+7;
ll mod1=1e9+5;
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power(((((a)%mod)*((a)%mod))%mod),b/2)%mod;
    else return (((a)%mod)*(power(((((a)%mod)*((a)%mod))%mod),b/2)%mod))%mod;
}
inline ll inverse(ll a) {
  a %= mod;
  if (a < 0) a += mod;
  ll b = mod, u = 0, v = 1;
  while (a) {
    ll t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += mod;
  return u;
}
  
  
 //using namespace __gnu_pbds;
 //#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
//find_by_order(k)  returns iterator to kth element starting from 0;
//order_of_key(k) returns count of elements strictly smaller than k;
//erase,insert same as normal set
// mt19937 mrand(chrono::high_resolution_clock::now().time_since_epoch().count()); for randomized solution
const int ce=1e9+7;
ll fast_mod(ll input)
{
    return input < ce ? input : input%ce;
}

int32_t main()
{
    IOS


    int n;
    cin>>n;
    int a[n+1];
    int sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    bitset<4000001> dp;
    dp.set(0);
    for(int i=0;i<n;i++)
        dp|=dp<<a[i];
    int x=sum/2;
    if(sum%2!=0)
        x++;
    for(int i=x;i<=sum;i++)
        if(dp[i])
        {
            cout<<i<<endl;
            return 0;
        }
}       

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
 
const int INF=1001001001;
int N,M,T;
 
int dist[111111];
 
struct UF{
    vint par,sz,pre,ma;
    UF(int n){
        par.resize(n);
        sz.resize(n);
        pre.resize(n);
        ma.resize(n);
        rep(i,n){
            par[i]=i;
            sz[i]=1;
            pre[i]=T;
            if(dist[i]==INF)ma[i]=-INF;
            else ma[i]=0;
        }
    }
    int find(int x){
        return x==par[x]?x:par[x]=find(par[x]);
    }
    void unite(int x,int y,int t){
        x=find(x);y=find(y);
        if(x==y)return;
 
        int a=(pre[x]-t)*sz[x]+ma[x];
        int b=(pre[y]-t)*sz[y]+ma[y];
 
        ma[x]=max(a,b);
        sz[x]+=sz[y];
        par[y]=x;
        pre[x]=t;
    }
 
    int latte(){
        int x=find(0);
        return ma[x]+pre[x]*sz[x];
    }
};
 
vector<pint>G[111111];
 
signed main(){
    scanf("%lld%lld%lld",&N,&M,&T);
 
    vector<tuple<int,int,int>>es;
    rep(i,M){
        int a,b,c;
        scanf("%lld%lld%lld",&a,&b,&c);
        a--;b--;
        G[a].pb({b,c});
        G[b].pb({a,c});
        es.pb(make_tuple(c,a,b));
    }
    sort(all(es));reverse(all(es));
 
 
    fill_n(dist,111111,INF);
    dist[0]=0;
    queue<int>que;
    que.push(0);
    while(que.size()){
        int v=que.front();
        que.pop();
        for(auto &e:G[v]){
            if(dist[e.fi]!=INF||dist[v]>=e.se)continue;
            dist[e.fi]=dist[v]+1;
            que.push(e.fi);
        }
    }
 
 
 
    UF uf(N);
    for(auto &w:es){
        int t,a,b;
        tie(t,a,b)=w;
        uf.unite(a,b,t);
    }
 
    printf("%lld\n",uf.latte());
}

Measured memory_bytes: 24732
N = int(input())
t,a = map(int,input().split())
#print(t,a)
for _ in range(1,N):
    T,A = map(int,input().split())
    d = max(-(-t//T),-(-a//A))
    t,a = T*d,A*d
    #print(t,a,d)
print(t+a)

Measured memory_bytes: 71540
//>>>>>>>>>>>>>>>>>>>>>>>>>>JAI BAJRANG BALI<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<//
#define HARSH_JUDGE
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define db(x)                   cout<<#x<<"="<<x<<'\n'
#define db2(x,y)                 cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define ll long long
#define ld long double
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define setbits(x)      __builtin_popcountll(x)
#define str string
#define bhaag_basanti ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fo(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n;i>=a;i--)
#define cases   long long t;cin>>t;while(t--)
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
#define ff first
#define ss second
#define pb push_back
#define mem(a,x) memset(a,x,sizeof(a))
#define sp(x,y)         fixed<<setprecision(y)<<x
#define nl '\n'
#define sz(x) ((int)(x).size())
const int mod = (int) 1e9 + 7 ;
const int MOD = (int) 998244353 ;
const ll INF = 1e18 ;
const ll N = 1e5 + 5;
#define printall(a) fo(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;



typedef vector<int> vi;
typedef map<ll, ll> mll;
typedef set<int> si;
typedef unordered_set<int> usi;
typedef map<ll, int> mli;
typedef map<char, int> mci;
typedef vector<long long> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpl;
typedef vector<vector<int> > vv;

bool cmp(const pair<ll, ll>& a, const pair<ll, ll>& b)
{

	return a.ss < b.ss;
}

// >>>>>>>>>>>>>>>>>>>>>>>>>>TOR DE DUSHMAN KI NALI<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<//

void solve()
{

	ll n, w;
	cin >> n >> w;
	vll val(n), wt(n);
	ll totval = 0;
	fo(i, 0, n)
	{
		cin >> wt[i] >> val[i];
		totval += val[i];
	}
	vll dp(totval + 1, INF);
	dp[0] = 0;
	fo(i, 0, n)
	{
		for (ll j = totval - val[i]; j >= 0; j--)
		{
			dp[j + val[i]] = min(wt[i] + dp[j], dp[j + val[i]]);
		}
	}

	ll ans = 0;
	fo(i, 0, totval + 1)
	{
		if (dp[i] <= w)
		{
			ans = max(ans, i);
		}
	}
	cout << ans << nl;

	return;
}


int main()
{
	bhaag_basanti
#ifndef HARSH_JUDGE
	freopen("inputf.in", "r", stdin);
	freopen("outputf.in", "w", stdout);
#endif
	ll t = 1;
	// cin >> t;
	// clock_t timest = clock();
	// cerr << "[Executes in " << (double)(clock() - timest) / CLOCKS_PER_SEC << "s]" << endl;
	while (t--)
	{
		solve();

	}
}

Measured memory_bytes: 3984
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i <(n); i++)
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using p = pair<int,int>;

int main(){
  int n,m;
  cin >> n >> m;
  int ans = 0;
  ans += (n*(n-1))/2;
  ans += (m*(m-1))/2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String zero = "0";
        while(true){
            String s = sc.next();
            if(zero.equals(s)){
                break;
            }else{
                int sum = 0;
                for(int i=0; i<s.length(); i++){
                    char c = s.charAt(i);
                    sum += (char)(c-48);
                }
            System.out.println(sum);
                }
        }
    }
}


Measured memory_bytes: 26280
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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

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

int main() {
  int X, A, B;
  cin >> X >> A >> B;
  cout << (X - A) % B << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
keys = []
for i in range(m):
    a, b = map(int, input().split())
    s = 0
    for c in map(int, input().split()):
        c -= 1
        s |= 1 << c
    keys.append((s, a))

INF = 1001001001
dp = [INF] * (1<<n)
dp[0] = 0
for s in range(1<<n):
    for k, v in keys:
        t = s | k
        cost = dp[s] + v
        dp[t] = min(dp[t], cost)

ans = dp[-1]
if ans == INF: ans = -1
print(ans)

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

using lint = long long;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<vector<T>>;
template <typename T> using VVV = vector<vector<vector<T>>>;
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define repu(i, a, b, s) for(int i = int(a); i < int(b); i += int(s))
#define repd(i, a, b, s) for(int i = int(a); i > int(b); i += int(s))
#define endl "\n"
constexpr lint INF = 2e18;
constexpr lint MOD = 1e9 + 7;

void solve() {
    lint a, b;
    cin >> a >> b;
    lint n = b - a - 1;
    lint ans = n * (n + 1) / 2;
    cout << ans - a << endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solve();
}

Measured memory_bytes: 3576
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
h,w = readInts()
block = [input() for _ in range(h)]

allcnt = 0
for i in range(w):
    for j in range(h):
        if block[j][i] == '.':
            allcnt += 1
INF = float('inf')
AR = [[INF] * w for _ in range(h)]
dy = [1,0,0,-1]
dx = [0,-1,1,0]
def bfs():
    d = deque()
    d.append([0,0])
    while d:
        y,x = d.popleft()
        if y == 0 and x == 0:
            AR[y][x] = 0
        for i in range(4):
            ny = y + dy[i]
            nx = x + dx[i]
            if (not 0 <= ny < h) or (not 0 <= nx < w):
                continue
            if AR[ny][nx] == INF and block[ny][nx] != '#':
                AR[ny][nx] = AR[y][x] + 1
                d.append([ny,nx])
bfs()
if AR[h-1][w-1] == INF:
    print(-1)
else:
    print(allcnt - (AR[h-1][w-1]+1)) # start地点の分


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

int main() {
  int H,W;
  cin >> H >> W;
  
  for(int i=0; i < (W+2); i++) {
    cout << "#";
    }
  cout << endl;
  
  for(int i=0; i < H; i++) {
    string ai;
    cin >> ai;
    
    cout << "#" << ai << "#" << endl;
    }
  
  for(int i=0; i < (W+2); i++) {
    cout << "#";
    }
  cout << endl;
  }

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  ll ans1 = 0, sum1 = 0;
  for (int i = 0; i < n; ++i) {
    sum1 += a[i];
    if (i % 2 == 0 && sum1 <= 0) {
      ans1 += 1 - sum1;
      sum1 = 1;
    } else if (i % 2 == 1 && 0 <= sum1) {
      ans1 += 1 + sum1;
      sum1 = -1;
    }
  }
  ll ans2 = 0, sum2 = 0;
  for (int i = 0; i < n; ++i) {
    sum2 += a[i];
    if (i % 2 == 1 && sum2 <= 0) {
      ans2 += 1 - sum2;
      sum2 = 1;
    } else if (i % 2 == 0 && 0 <= sum2) {
      ans2 += 1 + sum2;
      sum2 = -1;
    }
  }
  cout << min(ans1, ans2) << endl;
  return 0;
}

Measured memory_bytes: 640
import java.util.*;

class Main{
    public static final int MOD = (int)1e9+7; 
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int x = sc.nextInt();
      int y = sc.nextInt();
      if((x+y)%3==0 && (double)Math.max(x,y)/(double)Math.min(x,y)<=2){
        int k = (x+y)/3;
        x -= k;
        Mod_nCr mn = new Mod_nCr(MOD, (int)1e6);
        long ans = mn.nCr(k, x);
        System.out.println(ans);
      }else{
        System.out.println(0);
      }
    }
}

class Mod_nCr{
    int mod;
    long[] fact;
    long[] rfact;
     
    public Mod_nCr(int mod, int max){
        this.mod = mod;
        fact = new long[max];
        rfact = new long[max];
         
        fact[0] = 1;
        rfact[0] = 1;
         
        for(int i=1; i<max; i++){
            fact[i] = (fact[i-1]*i)%mod;
            rfact[i] = mod_inverse(fact[i], mod);
        }
    }
     
    //
    private long mod_pow(long x, long p, long m){
        long a = 1;
        while(p>0){
            if(p%2==1){
                a = a*x%m;
            }
            x = x*x%m;
            p /= 2;
        }
        return a;
    }
     
    private long mod_inverse(long a, long m){
        return mod_pow(a, m-2, m);
    }
     
    //
    public long nCr(int n, int r){
        return fact[n]*rfact[r]%mod * rfact[n-r]%mod;
    }
}

Measured memory_bytes: 39508
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <queue>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}
const int INF = 100000000;

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

    for(int i = 0; i < n; i++){
        cout << s[i] << t[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
def resolve():
    N = int(input())

    x_list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

    print(x_list[N-1])



if __name__ == "__main__":
    resolve()

Measured memory_bytes: 3060
#include <iostream>
#include <stdlib.h>
using namespace std;

int compare_int(const void *a, const void *b){
    return *(int*)a - *(int*)b;
}

int main(){
    int N,*a,i,count=1,tmp,dis,sum=0;
    cin >> N;
    a = new int[N];
    for(i=0;i<N;i++){
        cin >> a[i];
    }
    qsort(a,N,sizeof(int),compare_int);
    tmp = a[0];
    for(i=1;i<N;i++){
        if(tmp==a[i]){
            count++;
        }else{
            dis = count - a[i-1];
            if(dis>=0){
                sum += dis;
            }else{
                sum += count;
            }
            tmp = a[i];
            count = 1;
        }
    }
    dis = count - a[N-1];
    if(dis>=0){
        sum += dis;
    }else{
        sum += count;
    }
    cout << sum;
    return 0;
}

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

using namespace std;

void convert_base_n_26(unsigned long long x, vector<int> &res) {
    while (x > 0ULL) {
        res.push_back(x % 26ULL);
        if (x % 26ULL == 0) {
            x -= 26ULL;
        }
        x /= 26ULL;
    }
}


string tab = "zabcdefghijklmnopqrstuvwxy";


int main(void) {
    unsigned long long N;
    cin >> N;
    vector<int> res;
    convert_base_n_26(N, res);

    for (auto it = res.rbegin(); it != res.rend(); ++it) {
        cout << tab[*it];
    }
    cout << endl;
}


Measured memory_bytes: 3640
N,M=map(int,input().split())
op=[list(map(int,input().split())) for _ in range(M)]
susflag=[0]*N
susflag[0]=1
num=[1]*N
fr=0
to=0
#print(susflag,num)
for i in range(M):
    fr=op[i][0]-1
    to=op[i][1]-1
    num[fr]=num[fr]-1
    num[to]=num[to]+1
    if susflag[fr]==1:
        susflag[to]=1
    if num[fr]==0:
        susflag[fr]=0
    #print(susflag,num)
print(sum(susflag))

Measured memory_bytes: 62040
#include <iostream>
#define ll long long
using namespace std;

int main(){
      ll s,ans=0;cin >> s;
      
      while(s != 4 && s != 2 && s != 1){
      if(s%2==0)s/=2;
      else s = (s*3)+1;
      ans++;
      }
      cout << ans+4 << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  for (int i = 0; i < n; i++) {
    cin >> l.at(i);
  }
  int max = *max_element(l.begin(), l.end());
  int sum = accumulate(l.begin(), l.end(), 0);
  if (max < sum - max) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

const long long inf = 1LL << 60;
int N;
long long h[100010];
long long dp[100100];

int main(){
    int N,K; cin >> N >> K;
    for (int i = 0; i < N; i++) cin >> h[i];
    for (int i = 0; i < 100100; i++) dp[i]=inf;

    dp[0]=0;
    for (int i = 0; i < N; i++)
    {
        for (int j = 1; j <= K; j++)
        {
            dp[i+j] = (dp[i+j] < dp[i]+ abs(h[i] - h[i+j]))?
                        dp[i+j] : 
                        dp[i]+ abs(h[i] - h[i+j]);
        }        
    }
    cout << dp[N-1] << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn=200005;
int a[maxn];
int b[maxn];

int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		b[i]=a[i];
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++){
		if(b[i]<=a[n/2]) cout<<a[n/2+1]<<endl;
		else cout<<a[n/2]<<endl;
	}
	
	return 0;
} 

Measured memory_bytes: 3712
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>

#define pb push_back
#define mp make_pair

using namespace std;

template<typename T>inline void upmin(T &x,T y) { y<x?x=y:0; }
template<typename T>inline void upmax(T &x,T y) { x<y?x=y:0; }

typedef unsigned int u32;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod pi=acos(-1);
const int oo=1<<30;
const LL OO=1e18;

const int N=1e5+100,M=4e5+100;
const int mod=1e9+7;

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}

int head[N],nxt[M],to[M],w[M],n;
struct Q{ int k; LL dis; inline bool operator < (const Q &b) const { return dis>b.dis; } };
struct Graph{
	LL dis[N];int f[N];bool out[N];
	inline void shortroad(int k) {
		int i;priority_queue<Q>q;
		for (i=1;i<=n;i++) dis[i]=OO;
		q.push((Q){k,dis[k]=0});f[k]=1;
		while (!q.empty()) {
			k=q.top().k;q.pop();
			if (out[k]) continue;out[k]=true;
			for (i=head[k];i;i=nxt[i])
				if (dis[k]+w[i]<dis[to[i]])
					q.push((Q){to[i],dis[to[i]]=dis[k]+w[i]}),f[to[i]]=f[k];
				else if (dis[k]+w[i]==dis[to[i]])
					(f[to[i]]+=f[k])%=mod;
		}
	}
}G1,G2;
int main()
{
	n=gi();int m=gi(),i,S=gi(),T=gi(),a,b,ans,tot=1,t;
	for (i=1;i<=m;i++) {
		a=gi(),b=gi();
		to[++tot]=b,nxt[tot]=head[a],head[a]=tot;
		to[++tot]=a,nxt[tot]=head[b],head[b]=tot;
		w[tot]=w[tot-1]=gi();
	}
	G1.shortroad(S);
	G2.shortroad(T);
	ans=1LL*G1.f[T]*G2.f[S]%mod;
	for (i=1;i<=n;i++)
		if (G1.dis[i]+G2.dis[i]==G1.dis[T]&&G1.dis[i]==G2.dis[i])
			t=1LL*G1.f[i]*G2.f[i]%mod,ans=(ans-1LL*t*t)%mod;
	for (i=2;i<=tot;i++) {
		a=to[i^1],b=to[i];
		if (G1.dis[a]+G2.dis[b]+w[i]==G1.dis[T]&&G1.dis[a]<G2.dis[a]&&G1.dis[b]>G2.dis[b])
			t=1LL*G1.f[a]*G2.f[b]%mod,ans=(ans-1LL*t*t)%mod;
	}
	cout<<(ans+mod)%mod<<endl;
	return 0;
}


Measured memory_bytes: 11476
x,y=map(int,input().split())
a=list(map(int,input().split()))
dif=1
if x not in a:
  print(x)
else:
  while True:
    if x-dif not in a:
      dif*=-1
      break
    elif x+dif not in a:
      break
    else:
      dif+=1
  print(x+dif)

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 4010;
const LL mod = 998244353;
int N;
bitset<MC> X;
bitset<MC> A[9],B;
int d[9];
int s[9];

int main(){
	cin >> N;
	cin >> X;
	repp(i,0,N) cin >> A[i];
	repp(i,0,N) repp(j,0,MC) if(A[i][j]) d[i] = j;
	if(N>1){
		repp(i,0,N) s[i] = i;
		auto comp = [&](const int p , const int q){return d[p] > d[q];};
		sort(s,s+N,comp);
		while(d[s[1]] >= 0){
			A[s[0]] = (A[s[0]]^(A[s[1]]<<(d[s[0]]-d[s[1]])));
			while(d[s[0]] >= 0 && !A[s[0]][d[s[0]]]) --d[s[0]];
			sort(s,s+N,comp);
		}
		A[0] = A[s[0]];
		d[0] = d[s[0]];
	}
	int z = 0;
	repp(j,0,MC) if(X[j]) z = j;
	LL ans = 0;
	repm(i,z,d[0]-1) ans = (ans * 2 + X[i]) % mod;
	repm(i,z,d[0]-1) if(B[i]^X[i]) B ^= (A[0]<<(i-d[0]));
	++ans;
	repm(i,d[0]-1,-1){
		if(B[i]^X[i]){
			if(B[i]) ans += mod-1;
			break;
		}
	}
	cout << ans % mod << endl;
	return 0;
}


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

#define cp_io ios_base::sync_with_stdio(0);cin.tie(0)
#define ll long long int
#define oo 1000000010
#define MAX 1000000
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define nl "\n"

int main()
{
    cp_io;
    #ifndef ONLINE_JUDGE
    freopen("z_input.txt","rt",stdin);
    freopen("z_output.txt","wt",stdout);
    #endif
    string s;
    cin >> s;
    int n = s.length();

    int sum = 0;
    for(int i=0; i<n; i++)
        sum += s[i]-'0';

    if(sum%9 == 0)
        cout << "Yes";
    else 
        cout << "No";
    return 0;
}

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

using namespace std;
using ll = long long;

int main() {
    int A, B;
    cin >> A >> B;
    int ans = 0;
    while (B-1>0)
    {
        B -= A-1;
        ans++;
    }
    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 3612
#include<cstdio>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    int n;
    while(scanf("%d",&n),n){
        map<string,int>mi;
        for(int i=0;i<n;i++){
            string str;
            int val;
            cin>>str>>val;
            mi[str]=val;
        }
        map<string,vector<string> >es;
        int m;
        scanf("%d",&m);
        for(int i=0;i<m;i++){
            string t;
            int c;
            cin>>t>>c;
            vector<string>V(c);
            for(int i=0;i<c;i++)cin>>V[i];
            es[t]=V;
        }

        for(int i=0;i<n;i++){
            map<string,vector<string> >::iterator it;
            for(it=es.begin();it!=es.end();it++){
                string s=it->first;
                vector<string>V=it->second;
                int sum=0;
                for(int j=0;j<V.size();j++){
                    sum+=mi[V[j]];
                }
                mi[s]=min(mi[s],sum);
            }
        }
        string str;
        cin>>str;
        printf("%d\n",mi[str]);
    }
    return 0;
}

Measured memory_bytes: 1288
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a, b, c, x, y, z;
    scanf("%d %d %d", &a, &b, &c);
    x = max(a, max(b, c));
    y = min(a, min(b, c));
    z = (a + b + c) - (x + y);
    printf("%d\n", x * 10 + y + z);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
int n, A[1010000], B[1010000], cnt;
vector<int>E[26];
char p[1010000], q[1010000];
int main(){
    int i, pv, ck = 0, res = 0;
    scanf("%d",&n);
    scanf("%s",p+1);
    scanf("%s",q+1);
    for(i=1;i<=n;i++){
        E[p[i]-'a'].push_back(i);
        if(p[i]!=q[i])ck = 1;
    }
    if(!ck){
        printf("0\n");
        return 0;
    }
    pv = n;
    for(i=n;i>=1;i--){
        if(q[i]!=q[i-1]){
            pv = min(pv, i);
            int x = q[i]-'a';
            int t = lower_bound(E[x].begin(), E[x].end(), pv + 1) - E[x].begin();
            if(!t){
                printf("-1\n");
                return 0;
            }
            B[++cnt] = i;
            A[cnt] = E[x][t-1];
            pv = E[x][t-1] - 1;
        }
    }
    for(i=1;i<=cnt/2;i++)swap(A[i],A[cnt+1-i]),swap(B[i],B[cnt+1-i]);
    cnt++;
    A[cnt]=B[cnt]=n+1;
    for(i=1;i<=cnt;i++) A[i]-=i, B[i]-=i;
    for(i=1;i<=cnt;i++){
        int t = lower_bound(A+1,A+cnt+1,B[i]) - A;
        res = max(res, t - i);
    }
    printf("%d\n",res+1);
}

Measured memory_bytes: 15180
///In the name of GOD
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
const ll MXN = 1e6 + 10;
ld ans, n, a, b, c;
int main(){
    ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
    cin >> n;
    a = n / (ld)3;
    b = n / (ld)3;
    c = n - a - b;
    ans = a * b * c;
    cout << fixed << setprecision(12);
    cout << ans;
    return 0;
}
/*!
    Be careful who you share your weaknesses with.
    Some people can't wait for the opportunity to use them against you!!
*/
//! N.N


Measured memory_bytes: 256
#include <cmath>
#include <vector>
#include <iomanip>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <limits> 

using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<PII> VP;
typedef vector<ll> VL;
typedef vector<VL> VVL;
string s;
int n;
VVI pal_len;
VVL short_num;

void calc_len() {
	pal_len = VVI(n, VI(n, 1 << 25));
	for (int i = 0; i < n; ++i) {
		pal_len[i][i] = 1;
		if (i+1 < n) pal_len[i][i+1] = (s[i] == s[i+1]) ? 2 : 3;
	}
	for (int dist = 2; dist < n; ++dist) {
	  for (int i = 0, j = dist; j < n; ++i, j++) {
		if (s[i] == s[j]) pal_len[i][j] = 2 + pal_len[i+1][j-1];
		else pal_len[i][j] = 2 + min(pal_len[i+1][j], pal_len[i][j-1]);
	  }
	}
}
void calc_num() {
	short_num = VVL(n, VL(n, 0));
	for (int i = 0; i < n; ++i) {
		short_num[i][i] = 1;
		if (i+1 < n && s[i] == s[i+1]) short_num[i][i+1] = 1;
		if (i+1 < n && s[i] != s[i+1])  short_num[i][i+1] = 2;
	}
	for (int dist = 2; dist < n; ++dist) {
	  for (int i = 0, j = dist; j < n; ++i, j++) {
		if (s[i] == s[j]) short_num[i][j] = short_num[i+1][j-1];
		else if (pal_len[i+1][j] == pal_len[i][j-1]) {
			short_num[i][j] = short_num[i+1][j] + short_num[i][j-1];
			short_num[i][j] = min(short_num[i][j], 1LL << 61);
		} else 
			short_num[i][j] = (pal_len[i+1][j] < pal_len[i][j-1]) ?
					short_num[i+1][j] : short_num[i][j-1];
	  }
	}
}

void solve(int i, int j, ll k, string& sol) {
	if (i == j) { sol = s[i]; return; }
	if (i+1 == j && s[i] == s[j]) { sol = string(2, s[i]); return; }
	if (i+1 == j) {
		vector<string> pos;
		pos.push_back(string(1, s[i]) + string(1, s[j]) + string(1, s[i]));
		pos.push_back(string(1, s[j]) + string(1, s[i]) + string(1, s[j]));
		sort(pos.begin(), pos.end());
		if (k == 1) sol = pos[0];
		else sol = pos[1];
		return;
	}

	if (s[i] == s[j]) {
		solve(i+1, j-1, k, sol);
		if (sol.size() != 0) sol = s[i] + sol + s[j];
		return;
	} 
	if (pal_len[i+1][j] < pal_len[i][j-1] ||
		(pal_len[i+1][j] == pal_len[i][j-1] && s[i] < s[j] && k <= short_num[i+1][j])) {
		solve(i+1, j, k, sol);
		if (sol.size() != 0) sol = s[i] + sol + s[i];
		
		return;
	}
	if (pal_len[i+1][j] > pal_len[i][j-1] ||
		(pal_len[i+1][j] == pal_len[i][j-1] && s[i] > s[j] && k <= short_num[i][j-1])) {
		solve(i, j-1, k, sol);
		if (sol.size() != 0) sol = s[j] + sol + s[j];
		return;
	}
	if (s[i] < s[j]) {
		solve(i, j-1, k-short_num[i+1][j], sol);
		if (sol.size() != 0) sol = s[j] + sol + s[j];
		return;
	}
	solve(i+1, j, k-short_num[i][j-1], sol);
	if (sol.size() != 0) sol = s[i] + sol + s[i];
	return;
}

int main() {
	ios::sync_with_stdio(false);
	ll k;
	while (cin >> s) {
		cin >> k;
		n = s.size();
		calc_len();
		calc_num();
		if (short_num[0][n-1] < k) { cout << "NONE\n"; continue; }
		string sol = "";
		solve(0, n-1, k, sol);
		cout << sol << endl;
	}
}

Measured memory_bytes: 50500
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
using namespace std;

int main(){
    vector<int> d(5);
    int mi=INF;
    int sum=0;
    rep(i,5){
        cin >> d[i];
        if(d[i]%10!=0) mi=min(mi,d[i]%10);
        if(d[i]%10==0) sum+=d[i];
        else sum+=(d[i]-(d[i]%10)+10);
    }
    if(mi==INF) mi=10;
    cout << sum-(10-mi) << endl;
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long int LL;
vector<LL> v1;
LL t[100005];

int BIT[200007];
const int N=100002;

void bit_add(int t,int a,int n){//place,add,n
	for(int i=t+1;i<=n;i+=(i&(-i))){
		BIT[i-1]+=a;
	}
}

void bit_init(int n,int *a){//配列ごと加算
	for(int i=0;i<n;i++){
		bit_add(i,a[i],n);
	}
}

int bit_sum(int t){
	int s=0;
	for(int i=t+1;i!=0;i-=(i&(-i))){
		s+=BIT[i-1];
	}
	return s;
}

int main(){
	LL n;
	int i,j,k;
	int m[3];
	int a,b,c;
	LL s=0;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>t[i];
		v1.push_back(t[i]);
	}
	if(n==1){
		cout<<t[0]<<endl;
		return 0;
	}
	sort(v1.begin(),v1.end());
	m[0]=-1,m[1]=n;
	while(m[1]-m[0]>1){
		m[2]=(m[0]+m[1])/2,a=N,s=0;
		memset(BIT,0,sizeof(BIT));
		for(i=0;i<n;i++){
			bit_add(a,1,N*2);
			if(t[i]>=v1[m[2]])a++;
			else a--;
			s+=bit_sum(a);
		}
		if(s>=n*(n+1)/4)m[0]=m[2];
		else m[1]=m[2];
	}
	if(m[0]==-1)m[0]=0;
	cout<<v1[m[0]]<<endl;
	return 0;
}
		
	


Measured memory_bytes: 2676
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    A, B = map(int, input().split())

    ok = "NG"

    for i in range(A, B+1):
        if i % N == 0:
            ok = "OK"
    
    print(ok)


if __name__ == '__main__':
    main()

Measured memory_bytes: 61708
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

#define Left second
#define Right first
class SEGMENTS{
private:
    
    map<int,int> dat;
    
    bool isInclude(int li, int ri, int L, int R){ return (L<=li && ri<=R); }
    
public:
    
    void erase(int l, int r){
        while(true){
            auto it = dat.upper_bound(l);
            if(it==dat.end() || r<=it->Left)break;
            
            int li = it->Left;
            int ri = it->Right;
            
            if( isInclude(li,ri,l,r) ) dat.erase(it);
            else{
                int tl = li, tr = ri;
                dat.erase(it);
                if( isInclude(l,r,li,ri) ){
                    if(li!=l) dat[l] = li;
                    if(r!=ri) dat[ri] = r;
                }else{
                    if(li<=l&&l<ri) tr = l;
                    if(l<=li&&li<r) tl = r;
                    if(tl!=tr) dat[tr] = tl;
                }
            }
        }
    }
    
    void insert(int l, int r){
        while(true){
            auto it = dat.upper_bound(l);
            if(it==dat.end() || r<it->Left){
                if(dat.count(l)){
                    dat[r] = dat[l];
                    dat.erase(l);
                }
                else dat[r] = l;
                break;
            }
            
            if( isInclude(it->Left,it->Right,l,r) ) dat.erase(it);
            else{
                l = min(l,it->Left);
                r = max(r,it->Right);
            }
        }
    }
    
    int size(){ return dat.size(); }
    
    void output(){ for(auto e:dat)cout<<e.Left<<" "<<e.Right<<endl;cout<<endl; }
};

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    
    SEGMENTS st;
    
    for(int i=0;i<n;){
        if(s[i]=='0')i++;
        else{
            int l=i;
            while(i<n && s[i]=='1') i++;
            st.insert(l,i);
        }
    }
    
    int q;
    cin>>q;
    while(q--){
        int l,r,b;
        cin>>l>>r>>b;
        l--;
        
        if(b==0)    st.erase(l,r);
        else        st.insert(l,r);
        
        cout<<st.size()<<endl;
    }
}

Measured memory_bytes: 4204
#include <stdio.h>
int main(){
    int x,y;
    
    while(1){
        scanf("%d%d",&x,&y);
        if(x==0 && y==0) break;

        if(x<y){
            printf("%d %d\n",x,y);
        }
        else{
            printf("%d %d\n",y,x);
        }
    }
    return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
int main(void){
    int r,c,i,j;
    int sum = 0;
    scanf( "%d %d" , &r , &c );
    int ary[r+1][c+1];
    int total[c+1];
    
    for( i = 0 ; i < r + 1 ; i++ ){
        ary[i][c] = 0;
    }
    for( i = 0 ; i < c + 1 ; i++ ){
        total[i] = 0;
    }
    
    for( i = 0 ; i < r; i++ ){
        for( j = 0 ; j < c; j++ ){
            scanf( "%d" , &ary[i][j] );
            sum += ary[i][j];
            total[j] += ary[i][j];
            printf( "%d " , ary[i][j] );
        }
        printf( "%d\n" , sum );
        sum = 0;
    }
    
    
    for( i = 0 ; i < c ; i++ ){
        printf( "%d " , total[i] );
        total[c] += total[i];
    }
    printf( "%d\n" , total[c] );
    
    
}


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

using LL = long long;
using LD = long double;
 
LL mod = 998244353;

int main()
{
	string s;
	cin >> s;
	LL n = s.size();
	LL q = 1, w = 1;

	string t = "";
	for (LL i = 0; i < n/2; ++i) {
		if (s[i] != s[n-1-i]) {
			q = 0;
		}
		t.push_back(s[i]);
	}


	for (LL i = 0; i < t.size()/2; ++i) {
		if (t[i] != t[t.size()-1-i]) {
			w = 0; break;
		}
	}
	
	if (q&&w) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}


}

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

int main() {
    // input
    int n, m; cin >> n >> m;
    vector<int> a(n);
    REP (i, n) cin >> a[i];

    // solve
    ll ans = 0;
    map<int, int> cnt;
    int acc = 0;
    cnt[acc] += 1;
    REP (i, n) {
        acc = (acc + a[i]) % m;
        ans += cnt[acc];
        cnt[acc] += 1;
    }

    // output
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3584
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <queue>
#include <stack>
#include <tuple>

using namespace std;


typedef long long ll;
const int MAX_V = 210;
const int INT_INF = 1<<30;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
struct edge {
	int cap, cost;
};
int V;

edge G[MAX_V][MAX_V];
int h[MAX_V], dist[MAX_V];
int prevv[MAX_V];
bool used[MAX_V];
void add_edge(int from, int to, int cap, int cost) {
	G[from][to] = (edge){1, cost};
	G[to][from] = (edge){0, -cost};
}

int bit_matching_cost(int l, int r) {
	for (int i = 0; i < l; i++) {
		add_edge(l+r, i, 1, 0);
	}
	for (int i = l; i < l+r; i++) {
		add_edge(i, l+r+1, 1, 0);
	}
	int res = 0;
	fill_n(h, V, 0);
	while (true) {
		fill_n(dist, V, INT_INF);
		dist[l+r] = 0;

        fill_n(used, V, false);
        while (true) {
            int v = -1;
            for (int i = 0; i < V; i++) {
                if (!used[i] && (v == -1 || dist[i] < dist[v])){
                    v = i;
                }
            }
            if (v == -1) break;
            used[v] = true;

			for (int i = 0; i < V; i++) {
				edge &e = G[v][i];
				if (e.cap > 0 && dist[i] > dist[v] + e.cost + h[v] - h[i]) {
					dist[i] = dist[v] + e.cost + h[v] - h[i];
					prevv[i] = v;
				}
			}
        }
		if (dist[l+r+1] == INT_INF) {
			break;
		}
		for (int v = 0; v < V; v++) {
			h[v] += dist[v];
		}
		res += h[l+r+1];
		for (int v = l+r+1; v != l+r; v = prevv[v]) {
			edge &e = G[prevv[v]][v];
			e.cap -= 1;
			G[v][prevv[v]].cap += 1;
		}
	}
	return res;
}
int cost[MAX_V][MAX_V];


const int MAX_N = 105;
int N;
int W[MAX_N][MAX_N], E[MAX_N][MAX_N];
bool F[MAX_N][MAX_N], F2[MAX_N][MAX_N];

int main(int argc, char *argv[]) {
	cin >> N;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			scanf("%d", &(W[i][j]));
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			scanf("%d", &(E[i][j]));
		}
	}
	int min_f = 0, f = 0;
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < N; j++) {
			F[i][j] = (s[j] == 'o');
			if (F[i][j]) {
				min_f = min(min_f, -E[i][j]);
				f += E[i][j];
			}
		}
	}
	min_f *= -1;
	V = (N+1)*2;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (F[i][j]) {
				add_edge(i, N+j, 1, -E[i][j]+min_f);
			} else {
				add_edge(i, N+j, 1, W[i][j]+min_f);
			}
		}
	}
	f += bit_matching_cost(N, N);
	f -= min_f*N;
	int c = 0;
	vector<T> q;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (F[i][j] == G[i][N+j].cap) {
				c++;
				q.push_back(T(i, j, F[i][j]));
			}
		}
	}
	printf("%d\n%d\n", f, c);
	for (T t: q) {
		printf("%d %d %s\n", get<0>(t)+1, get<1>(t)+1, get<2>(t) ? "erase" : "write");
	} 
    return 0;
}

Measured memory_bytes: 1768
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
unsigned euclidean_gcd(unsigned a, unsigned b) {
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}
int main(){
  int n;
  cin >> n;
  int ans=0;
  rep(i,n){
    rep(j,n){
      int gcd=euclidean_gcd(i+1,j+1);
      rep(q,n){
        int a=euclidean_gcd(gcd,q+1);
        ans+=a;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3624