akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define mp make_pair
 
typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;
 
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<string, string> ss;
typedef pair<int, ss> iss;
 
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<ld> vld;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pair<int, pii>> vpiii;
 
typedef map<string, string> mss;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<int, ll> mill;
typedef map<int, vpii> mivpii;

const int MAXN = 1e4;
const int MAXD = 100;
const int TIGHT = 2;
const int UNSET = -1;
const int MOD = 1e9 + 7;

int dp[MAXN + 1][MAXD + 1][TIGHT];
int d[MAXN + 1];

string K;
int D, N;

void fast_io() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

int solve(int pos, int mod, bool r) {
	if(pos == N) return (mod == 0);
	if(dp[pos][mod][r] != UNSET) return dp[pos][mod][r];

	int lim = (r ? d[pos] : 9);
	int sum = 0;
	
	for(int i = 0; i <= lim; i++) {
		bool nr = (i == d[pos]) ? r : 0;
		sum += solve(pos + 1, (mod + i) % D, nr);
		if(sum >= MOD) sum -= MOD;
	}
	
	return dp[pos][mod][r] = sum;
}

int main() {
	fast_io();
//	freopen("input/dp_s.txt", "r", stdin);

	memset(dp, UNSET, sizeof(dp));
	cin >> K >> D;
	
	N = K.length();
	for(int i = 0; i < N; i++) 
		d[i] = K[i] - '0';
		
	int ans = (solve(0, 0, 1) - 1) % MOD;
	if(ans < 0) ans += MOD;
	cout << ans << '\n';
	
	return 0;
}

Measured memory_bytes: 9088
x,y,h,w,T;main(n){for(;scanf("%d",&n)*n;T=!printf("%d\n",T))for(;n--;T+=x>8?0:x*200)scanf("%d%d%d%d",&x,&y,&h,&w),x=fmax((x+y+h+19)/20,w<3?3:(w+19)/5);}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

    int ans = K * pow(K - 1, N - 1);

    cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n,i,j,a[1010][1010],t=-1,k[1010]={};
  bool d[1010],pos=true;
  scanf("%d",&n);
  for (i=1;i<=n;i++) for (j=0;j<n-1;j++) scanf("%d",&a[i][j]);
  while (pos){
    t++;
    pos=false;
    for (i=1;i<=n;i++) d[i]=false;
    for (i=1;i<=n;i++) if (k[i]!=n-1){
      j=a[i][k[i]];
      if (!d[i] && !d[j] && a[j][k[j]]==i){
        pos=true;
        k[i]++;
        k[j]++;
        d[i]=true;
        d[j]=true;
      }
    }
  }
  for (i=1;i<=n;i++) if (k[i]!=n-1) break;
  if (i==n+1) printf("%d\n",t);
  else puts("-1");
  return 0;
}


Measured memory_bytes: 4224
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  int i;
  string s;
  cin >> s;
  int n=s.length();
  int fans=0,sans=0;
  for(i=0;i<n;i++){
    if(i%2==0){
      if(s.at(i)=='1'){
        fans+=1;
      }
    }else{
      if(s.at(i)=='0'){
        fans+=1;
      }
    }
  }
  for(i=0;i<n;i++){
    if(i%2==0){
      if(s.at(i)=='0'){
        sans+=1;
      }
    }else{
      if(s.at(i)=='1'){
        sans+=1;
      }
    }
  }
  cout << min(fans,sans) << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
 
using namespace std;
typedef long long int lli;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef pair <lli,lli> pii;
#define ff first
#define ss second
#define MOD 1000000007
#define pb push_back
 
 
int main(){
	fast;
	int n, m;
	cin>>n>>m;
	string s;
	string ans;
	unordered_map<int,char> mp;
	for(int i=0; i<n; i++) s+="0";
	while(m--){
	    int i;
	    char c;
	    cin>>i>>c;
	    if((mp.find(i) == mp.end()) || (mp[i]==c)){  mp[i]=c; s[i-1]=c;}
	    else{ans="-1"; break;}
	    
	}
	if(s[0]=='0' && n!=1){
	    if(mp[1]=='0'){ ans="-1"; }
	    else{ s[0]='1';}
	}
	if(ans != "-1") ans=s;
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 512
# -*- coding: utf-8 -*-
import bisect
import sys

sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
INF = 2**62-1


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


ans = [-1] * (2*10**5+1)


@mt
def slv(N, A, UV):
    A.insert(0, -1)
    g = [list() for _ in range(0, N+1)]
    for u, v in UV:
        g[u].append(v)
        g[v].append(u)

    def dfs(u, p, dp):
        global ans

        for v in g[u]:
            if v == p:
                continue

            i = bisect.bisect_left(dp, A[v])
            b = dp[i]
            dp[i] = A[v]
            ans[v] = bisect.bisect_left(dp, INF)
            dfs(v, u, dp)
            dp[i] = b
    dp = [INF] * (N+1)
    dp[0] = A[1]
    dfs(1, 0, dp)

    ans[1] = 1
    for i in range(1, N+1):
        print(ans[i])


def main():
    N = read_int()
    A = read_int_n()
    UV = [read_int_n() for _ in range(N-1)]
    slv(N, A, UV)


if __name__ == '__main__':
    main()


Measured memory_bytes: 307132
n = gets.chomp.to_i
score = []
n.times do
  score << gets.chomp.to_i
end

sum = score.inject(&:+)
valid = score.select{|s| s % 10 != 0}
puts valid.empty? ? "0" : (sum % 10 == 0) ? sum - valid.min : sum


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

using namespace std;

#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
#define INF (int)1e9
typedef long long int int64;

void print() {
    cout << endl;
}

void print(string s, bool endline = true) {
    cout << s;
    if (endline) print();
}

void print(int s, bool endline = true) {
    cout << s;
    if (endline) print();
}

template <typename T, typename T2>
void print(pair<T, T2>& p, bool endline = true) {
    print("(", false);
    print(p.first, false);
    print(", ", false);
    print(p.second, false);
    print(")", false);

    if (endline) print();
}

template <typename T, typename T2>
void print(map<T, T2>& m, bool endline = true) {
    print("{");
    for (auto& p : m) {
        print("  ", false);
        print(p);
    }
    print("}");

    if (endline) {}
}

template<typename T>
void print(vector<T>& v, bool endline = true) {
    print("[", false);
    for (size_t i = 0; i < v.size(); ++i) {
        print(v[i], false);
        if(i != v.size() - 1) print(",", false);
    }
    print("]", false);

    if(endline) print();
}

template <typename T>
vector<T> operator+(const vector<T> &a, const vector<T> &b)
{
    vector<T> ret;
    ret.reserve( a.size() + b.size() );                // preallocate memory
    ret.insert( ret.end(), a.begin(), a.end() );        // add A;
    ret.insert( ret.end(), b.begin(), b.end() );        // add B;

    return ret;
}

template <typename T>
vector<T> &operator+=(vector<T> &a, const vector<T> &b)
{
    a.reserve( a.size() + b.size() );                // preallocate memory without erase original data
    a.insert( a.end(), b.begin(), b.end() );         // add B;
    return a;
}

int main() {
    // g++ -Wall -Wextra -O2 -std=c++17 helloworld.cpp
    int n;
    cin >> n;
    unordered_map<int, vector<int>> tree;
    unordered_map<int, int> color;

    int k = 1;
    vector<int> ret;

    while(n -- > 1) {
        int a, b;

        cin >> a >> b;

        tree[a].push_back(b);
        tree[b].push_back(a);
        ret.push_back(b);
    }

    for(auto& p : tree) {
        k = max((int) p.second.size(), k);
    }

    vector<int> children {1};
    color[1] = 0;

    while(!children.empty()) {
        vector<int> new_children;
        for(auto parent : children) {
            int i = 1;

            for (auto child : tree[parent]) {
                if (child > parent) {
                    if (i == color[parent]) i++;

                    color[child] = i;
                    i++;
                    new_children.push_back(child);
                }
            }
        }

        children = new_children;
    }

    print(k);
    for(auto c : ret) print(color[c]);

    return 0;
}

Measured memory_bytes: 13852
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 9999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> H >> W;
  DV(G,int,H,W,0);
  rep(i,0,H)rep(j,0,W)cin >> G[i][j];
  queue<pair<pint,pint>>que;
  rep(i,0,H){
    if(i&1){
      rrep(j,W,0){
        if(i==H-1&&j==0)continue;
        if(G[i][j]%2){
          if(j!=0){
            que.push(make_pair(pint(i,j),pint(i,j-1)));
            G[i][j-1]++;
          }
          else{
            que.push(make_pair(pint(i,j),pint(i+1,0)));
            G[i+1][0]++;
          }
        }
      }
    }
    else{
      rep(j,0,W){
        if(i==H-1&&j==W-1)continue;
        if(G[i][j]%2){
          if(j!=W-1){
            que.push(make_pair(pint(i,j),pint(i,j+1)));
            G[i][j+1]++;
          }
          else{
            que.push(make_pair(pint(i,j),pint(i+1,W-1)));
            G[i+1][W-1]++;
          }
        }
      }
    }
  }
  Out(que.size());
  while(!que.empty()){
    auto v=que.front();que.pop();
    cout << v.first.first+1 << " " << v.first.second+1 << " " << v.second.first+1 << " " << v.second.second+1 << endl;
  }
}

Measured memory_bytes: 7168
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#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 revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int N; cin >> N;
    vector<int> H;
    rep (i, 0, N) {
        int h; cin >> h;
        H.push_back(h);
    }

    reverse(H.begin(), H.end());

    rep (i, 1, H.size()) {
        if (H[i-1] >= H[i]) continue;
        else if (H[i-1] == H[i]-1) H[i] -= 1;
        else {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 892
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
void pl(vector<int> &s){
	s[0]++;
	rep(i,s.size()-1){
		if(s[i]==2){
			s[i+1]++;
			s[i]=0;
		}
	}
	return;
}

int main(){
	int n,m;
	cin>>n>>m;
	vector<int>k(m);
	vector<vector<int> >s(m);
	vector<int>p(m);
	rep(i,m){
		cin>>k[i];
		vector<int>tmp(k[i]);
		rep(j,k[i]) cin>>tmp[j];
		s[i]=tmp;
	}
	rep(i,m) cin>>p[i];
	vector<int> state(n,0);
	int cnt=0;
	int sum;
	int flg;
	/*
	rep(i,m){
		rep(j,k[i]){
			cout<<s[i][j]<<",";
		}
		cout<<endl;
	}
	*/
	while (state[n-1]<2){
			flg=0;
		rep(i,m){
			sum=0;
			rep(j,k[i]){
				sum+=state[s[i][j]-1];
			}
			if(sum%2!=p[i])flg=1; 
		}
		if(flg==0) cnt++;
		/*
		rep(i,m)cout<<state[i];
		cout<<endl;
		*/
		pl(state);
	}
	cout<<cnt<<endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#define M 101

using namespace std;

int main(){
	string ts;
	cin >> ts;
	int acount=0;
	int bcount = 0;
	for (int i = 0; i<ts.length(); i++){
		if (ts[i] == 'A'){
			acount++; 
		} else {
			bcount++;
		}
	}
	if (bcount != 3 && acount != 3){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}
			
		


Measured memory_bytes: 256
n = int(input())
p = list(map(int,input().split()))
ans=0
m=[]
m.append(p[0])
for i in range(1,n):
    m.append(min(p[i],m[i-1]))

for i , j in zip(p,m):
    if i <= j:
        ans+=1
print(ans)


Measured memory_bytes: 86864
#include <iostream>
using namespace std;
int main(){
	int r, c;
	cin >> r >> c;
	int arr[r + 1][c + 1];
	for (int j = 0; j <= c ; j++) arr[r][j] = 0;

	for (int i = 0; i < r ; i++){
        arr[i][c] = 0;
		for (int j = 0; j < c ; j++){
            cin >> arr[i][j];
            arr[i][c] += arr[i][j];
            arr[r][j] += arr[i][j];
    	}
    	arr[r][c] += arr[i][c];
	}
    
	for (int i = 0; i <= r ; i++){
		for (int j = 0; j <= c ; j++){
            cout << arr[i][j];
            if(j != c) cout << " ";
            else cout << endl;
    	}
	}

	return 0;
}



Measured memory_bytes: 3112
# -*- coding: utf-8 -*-
def PalindromeCheck(str_s):
    result = "Yes"
    for i in range((len(str_s) // 2)):
        #print(str_s[i])
        if str_s[i] != str_s[len(str_s) -1 - i]:
            result = "No"
            break
    return result

def StrongCheck(str_s):
    result = "Yes"
    if PalindromeCheck(str_s) == "No":
        result = "No"
    if PalindromeCheck(str_s[0:(len(str_s) -1) // 2]) == "No":
        result = "No"
    if PalindromeCheck(str_s[(len(str_s) + 3) // 2:len(str_s) - 1]) == "No":
        result = "No"
    return result


str_s = input()
print(StrongCheck(str_s))

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll x,y;
  cin >> x >> y;
  ll ans;
  if(x<y){
    if(x<0){
      ans = min(abs(y+x)+1,y-x);
    }else{
      ans = y - x;
    }
  }else{
    if(x<0){
      ans = abs(x-y) + 2;
    }else if (x==0){
      ans = abs(x-y) + 1;
    }else{
      if(y>0){
        ans = abs(x-y) + 2;
      }else{
        ans = abs(-x-y) + 1;
      }
    }
  }
  cout << ans<< endl;
  return 0;
}


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

int main()
{
    string s;
    cin >> s;
    
    set<char> a;
    for(int i = 0; i < s.size(); ++i)
    {
        a.insert(s[i]);
    }
    
    if(a.size() == s.size())
    {
        cout << "yes" << endl;
    }
    else
    {
        cout << "no" << endl;
    }
    
    return 0;
}




Measured memory_bytes: 256
def codefestival_2016_final_a
    h,w = gets.chomp.split(/\s/).map{|x| x.to_i}

    c = -1
    r = -1
    for i in 1..h
        gets.chomp.split(/\s/).each_with_index do |x,idx|
            if x == 'snuke'
                c = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'[idx]
                r = i
            end
        end
    end

    print "#{c}#{r}\n"
end

codefestival_2016_final_a

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

public class Main {
    static MyReader in = new MyReader();
    static PrintWriter out = new PrintWriter(System.out);

    static int K = 33;
    static int L = K * 2;
    static char[][] s = new char[L][L];

    public static void main(String[] args) {
        int A = in.i();
        int B = in.i();

        init(0, '#');
        init(K, '.');

        color(A, 0, '.');
        color(B, K + 1, '#');

        print();
    }

    static void init(int i0, char c) {
        for (int i = i0, i1 = i0 + K; i < i1; i++) {
            Arrays.fill(s[i], c);
        }
    }

    static void color(int i1, int j0, char c) {
        for (int i = 1, j = j0, k = 0; i < i1; i++, k += 4) {
            if (L <= k) {
                k = (++j & 1) << 1;
            }
            s[j][k] = c;
        }
    }

    static void print() {
        out.print(L);
        out.print(' ');
        out.println(L);
        for (int i = 0; i < L; i++) {
            out.println(s[i]);
        }
        out.flush();
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    int i() {
        int k = next() - '0';
        boolean minus = k == -3;
        int n = minus ? 0 : k;
        while (0 <= (k = next() - '0') && k <= 9) n = 10 * n + k;
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        int k = next() - '0';
        boolean minus = k == -3;
        long n = minus ? 0 : k;
        while (0 <= (k = next() - '0') && k <= 9) n = 10 * n + k;
        return minus ? -n : n;
    }

    char[] s(final int N) {
        char[] s = new char[N];
        for (int i = 0; i < N; i++) {
            s[i] = next();
        }
        next();
        return s;
    }

    public int read(char[] cbuf) {
        int i;
        char c;
        for (i = 0; (c = next()) != ' ' && c != '\n'; i++) cbuf[i] = c;
        return i;
    }

    public String readLine() {
        try {
            return super.readLine();
        } catch (IOException e) {
            return null;
        }
    }
}


Measured memory_bytes: 32628
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

/**
 * Planetary Exploration
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		int M, N, K;
		line = br.readLine();
		M = parseInt(line.substring(0, line.indexOf(' ')));
		N = parseInt(line.substring(line.indexOf(' ') + 1));
		K = parseInt(br.readLine());

		//
		int[][] J = new int[M + 1][N + 1];
		int[][] O = new int[M + 1][N + 1];
		int[][] I = new int[M + 1][N + 1];

		for (int i = 0; i < M; i++) {
			line = br.readLine();
			for (int j = 0; j < N; j++) {
				switch (line.charAt(j)) {
					case 'J':
						J[i + 1][j + 1] = 1;
						break;
					case 'O':
						O[i + 1][j + 1] = 1;
						break;
					case 'I':
						I[i + 1][j + 1] = 1;
						break;
				}
			}
		}

		//sum up
		for (int i = 1; i <= M; i++) {
			for (int j = 1; j <= N; j++) {
				J[i][j] += J[i][j - 1];
				O[i][j] += O[i][j - 1];
				I[i][j] += I[i][j - 1];
			}
		}

		for (int j = 1; j <= N; j++) {
			for (int i = 1; i <= M; i++) {
				J[i][j] += J[i - 1][j];
				O[i][j] += O[i - 1][j];
				I[i][j] += I[i - 1][j];
			}
		}

		//solve
		StringBuilder sb = new StringBuilder();

		for (int k = 0; k < K; k++) {
			StringTokenizer st = new StringTokenizer(br.readLine());

			int a, b, c, d;
			a = parseInt(st.nextToken());
			b = parseInt(st.nextToken());
			c = parseInt(st.nextToken());
			d = parseInt(st.nextToken());

			int j, o, i;
			j = J[c][d] - J[a - 1][d] - J[c][b - 1] + J[a - 1][b - 1];
			o = O[c][d] - O[a - 1][d] - O[c][b - 1] + O[a - 1][b - 1];
			i = I[c][d] - I[a - 1][d] - I[c][b - 1] + I[a - 1][b - 1];

			sb.append(j).append(' ');
			sb.append(o).append(' ');
			sb.append(i).append('\n');
		}

		System.out.print(sb.toString());
	}
}

Measured memory_bytes: 80548
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().run();
	}
	
	private void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		while (n-- > 0) {
			double x1 = scan.nextDouble();
			double y1 = scan.nextDouble();
			double x2 = scan.nextDouble();
			double y2 = scan.nextDouble();
			double x3 = scan.nextDouble();
			double y3 = scan.nextDouble();
			double x4 = scan.nextDouble();
			double y4 = scan.nextDouble();
			
			double x12 = x2 - x1;
			double y12 = y2 - y1;
			double x34 = x4 - x3;
			double y34 = y4 - y3;
			
			if (y12 * x34 == x12 * y34) {
				System.out.println("YES");
			}else {
				System.out.println("NO");
			}
		}
	}
	
	private void debug() {
		System.out.println();
	}

}

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

int main() {
  string s;
  cin >> s;
  int ans=0;
  for(int i=1; i<s.size(); i++) {
    if(s[i-1]!=s[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#define k first
#define v second
using namespace std;

const int N = 200005;
int n, T;

long long score(vector<pair<int, int>> &x)
{	if(x.empty()) return 0;
	long long res = 0;
	sort(x.begin(), x.end());
	priority_queue<int> q;
	int idx = x.size() - 1;
	for(int i = x[idx].k; i; --i)
	{
		while(idx >= 0 && x[idx].k == i) q.push(x[idx--].v);
		if(!q.empty())
		{
			res += q.top();
			q.pop();
		}
	}
	return res;
}

int main(){
	cin >> T;
	while(T--)
	{
		cin >> n;
		long long ans = 0;
		vector<pair<int, int>> L, R;
		for(int i = 0, k, l, r; i < n; ++i)
		{
			scanf("%d %d %d", &k, &l, &r);
			if(l <= r) {
				ans += l;
				R.push_back({n-k, r-l});
			}
			else
			{
				ans += r;
				L.push_back({k, l-r});
			}
		}
		ans += score(L);
		ans += score(R);
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 5228
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#include <cmath>
#include <string>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
//================================================

int a = 0, b = 0, c, d, n, k = 0;
string s, t;



int main()
{
	vector<int>n(4);
	cin >> n[0] >> n[1] >> n[2] >> n[3];
	sort(all(n));
	if (n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;


	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d;
int main()
{
	cin>>a>>b>>c>>d;
	if (a+b>c+d) cout<<"Left"<<endl;
	if (a+b==c+d) cout<<"Balanced"<<endl;
	if (a+b<c+d) cout<<"Right"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define M 101

int Ad[M][M];
int d[M];
int f[M];
char color[M];
int t;
void visit(int);

int main(){

  int n,i,j,m,u,k;

  scanf("%d",&n);

  for(i=1;i<M;i++){
    for(j=1;j<M;j++){
      Ad[i][j]=0;
    }
  }

  for(i=1;i<=n;i++){
    scanf("%d%d",&u,&k);
    color[i]='W';
    if(k!=0){for(m=1;m<=k;m++){
      scanf("%d",&Ad[u][m]);
      }
    }
  }
    t = 0;

  for(i=1;i<=n;i++){
    if(color[i]=='W') visit(i);
  }
  
  for(i=1;i<=n;i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }
 
  return 0;
}

void visit(int u){
  int i=1;

  color[u]='G';
  
  d[u]=++t;

  while(Ad[u][i]!=0){
    if(color[Ad[u][i]]=='W') { visit(Ad[u][i]);}
    i++;
  }
  color[u]='B';
  
  f[u] = ++t;
  
}

Measured memory_bytes: 640
import java.io.OutputStreamWriter;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author ilyakor
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
        long n = in.nextLong();
        long x = in.nextLong();
        long res = n;
        long a = x, b = n - x;
        while (a > 0 && b > 0) {
            long r = a / b;
            res += 2L * r * b;
            if (a - r * b == 0) res -= b;
            a -= r * b;
            long t = a;
            a = b;
            b = t;
        }
        out.printLine(res);
    }
}

class InputReader {
    private InputStream stream;
    private byte[] buffer = new byte[10000];
    private int cur;
    private int count;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public static boolean isSpace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public int read() {
        if (count == -1) {
            throw new InputMismatchException();
        }
        try {
            if (cur >= count) {
                cur = 0;
                count = stream.read(buffer);
                if (count <= 0)
                    return -1;
            }
        } catch (IOException e) {
            throw new InputMismatchException();
        }
        return buffer[cur++];
    }

    public int readSkipSpace() {
        int c;
        do {
            c = read();
        } while (isSpace(c));
        return c;
    }

    public long nextLong() {
        long sgn = 1;
        int c = readSkipSpace();
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            if (c < '0' || c > '9') {
                throw new InputMismatchException();
            }
            res = res * 10L + (long)(c - '0');
            c = read();
        } while (!isSpace(c));
        res *= sgn;
        return res;
    }

}

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public void print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0) {
                writer.print(' ');
            }
            writer.print(objects[i]);
        }
    }

    public void printLine(Object... objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }

}



Measured memory_bytes: 8148
N = int(input())
B = list(map(int, input().split()))

A = [0] * N
A[N - 1] = B[-1]

for i in reversed(range(1, N - 1)):
    A[i] = min(B[i], B[i - 1])
A[0] = B[0]
print(sum(A))

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
int main()
{
	long long a = 0, b = 0, c = 0, rate[100] = {}, last = 0, k = 0, ansa = 0, ansb = 0, x = 0, y = 0;
	
	int onex = 0, tenx = 0, hunx = 0, thoux = 0,manx=0;
		int one = 0, ten = 0, hun = 0, thou = 0,man=0;
	std::cin >>a;
	
	bool okada = true;
	for (int i = 1; i <= a-1; i++) {
		x = i;
		y = a - x;
		    onex = x%10;
			tenx = x%100/10;
			hunx = x%1000/100;
			thoux = x%10000/1000;
			manx = x % 100000 / 10000;
			one = y % 10;
			ten = y % 100 / 10;
			hun = y % 1000 / 100;
			thou =y % 10000 / 1000;
			man = y % 100000 / 10000;
			ansa = one + ten + hun + thou +man + onex + tenx + hunx + thoux +manx;
		
			if (i == 1) {
				last =ansa;
			
			}
			else if ( last > ansa) {
				last = ansa;
	
			}
	
	}

	std::cout << last << std::endl;
}







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

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

int main(){
    int N;
    cin >> N;
    int a[N],b[N],c[N];
    for(int i=0;i<N;i++){
        cin >>a[i]>>b[i]>>c[i];
    }
    int dp[N][3];
    for(int i=0;i<N;i++){
        for(int j=0;j<3;j++){
            dp[i][j]=0;
        }
    }
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    for(int i=1;i<N;i++){
        //aを選択
        if(chmax(dp[i-1][1]+a[i],dp[i-1][2]+a[i])){//直前BorCで比較
            dp[i][0]=dp[i-1][1]+a[i];
        }else{
            dp[i][0]=dp[i-1][2]+a[i];
        }
        //b
        if(chmax(dp[i-1][0]+a[i],dp[i-1][2]+a[i])){
            dp[i][1]=dp[i-1][0]+b[i];
        }else{
            dp[i][1]=dp[i-1][2]+b[i];
        }
        //c
        if(chmax(dp[i-1][0]+a[i],dp[i-1][1]+a[i])){
            dp[i][2]=dp[i-1][0]+c[i];
        }else{
            dp[i][2]=dp[i-1][1]+c[i];
        }
    }
    int Max=0;
    for(int i=0;i<3;i++){
        if(chmax(dp[N-1][i],Max)){
            Max=dp[N-1][i];
        }
    }

    cout << Max<<endl;

    return 0;
}

Measured memory_bytes: 2560
import sys
input = sys.stdin.buffer.readline
N,W = map(int, input().split())
v_max = (10**3)*N
inf = float('inf')
dp = [inf for _ in range(v_max+1)]
dp[0] = 0
for _ in range(N):
	w,v = map(int, input().split())
	for j in range(v_max,v-1,-1):
		b = w + dp[j-v]		
		if b<dp[j]:
			dp[j] = b

ans = None
for i in range(v_max+1):
	z = dp[i]
	if z<=W:
		ans = i

print(ans)



Measured memory_bytes: 11836
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>; // intの2次元の型に vvi という別名をつける
const ll llMAX=9223372036854775807LL; 
const ll llMIN=-9223372036854775808LL;

void myprint1D(vi &data)
{
  REP(i,data.size())
    cout<<data[i]<<" ";
  cout<<endl;
}

//配列を[y][x]で表示
void myprint2D_T(vvi &data)
{
  REP(i,data.size())
    myprint1D(data[i]);
}

//配列を[x][y]で表示
void myprint2D(vvi &data)
{
  ll l1=data.size();
  ll l2=data[0].size();
  REP(j,l2){
    REP(i,l1)
      cout<<data[i][j]<<" ";
    cout<<endl;
  }
}

//print(a,b...)って使い方
void print1(ll a){cout<<a<<endl;}
void print2(ll a,ll b){cout<<a<<" "<<b<<endl;}
void print3(ll a,ll b,ll c){cout<<a<<" "<<b<<" "<<c<<endl;}
void print4(ll a,ll b,ll c,ll d){cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;}
void print5(ll a,ll b,ll c,ll d,ll e){cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl;}


ll n,k,x,y;


//moddivとnCk
//c剰余下でaをbで割った値
ll moddiv(ll a,ll b,ll c){
	ll x0=c,x1=b,x2,n0=0LL,n1=1LL,n2,t=a%b,m,ans;
	if (t==0LL) return a/b;
		for(int i=0;i<900;i++){
      m=x0/x1;
      x2=x0-x1*m;
      n2=(n0-m*n1)%c;
      if (x2==1LL){
        ans=(n2+c)%c;
        break;
      }
      x0=x1;x1=x2;
      n0=n1;n1=n2;
    }
	return (a+((t*ans)%c)*b-t)/b;
}
//剰余の割ざん

//aのn乗 mod c
ll expmod(ll a,ll n,ll c){
  ll ans=1LL,aa=a,beki=n;
  for(int i=0;i<64;i++){
    if (beki%2==1LL) ans=ans*aa%c;
    aa=aa*aa%c;
    beki/=2LL;
    if (beki==0LL)break;
  }
  return ans;
}

//nCk
vi mulmod(500001);//0!,1!,2!,3!,4!,,,,
void first_nCk(){
  mulmod[0]=1LL;
  for(ll i=1;i<500001;i++){
    mulmod[i]=mulmod[i-1]*i%MOD;
  }
}
ll nCk(ll nn,ll kk){
  return moddiv(mulmod[nn],mulmod[kk]*mulmod[nn-kk]%MOD,MOD);
}

ll modinv(ll a,ll b){
  return moddiv(1,a,b);
}

ll garner(ll a,ll b,ll ar,ll br){
  return ar+(br-ar+b)%b*modinv(a,b)%b*a;
}
ll garner2(ll a,ll b,ll ar,ll br){
  ll ret=(ar+(br-ar)*moddiv(1,a,b)%b*a)%(a*b);
  return ret;
}

ll gcd(ll a,ll b){
  ll r = a % b;
  while(r!=0LL){
    a = b;
    b = r;
    r = a % b;
  }
return b;
}





int main(){
  ll ans=0;
  cin >> n;

  if (n==1){
    cout<<1<<endl;
    return 0;
  }
  if (n%2==0){
    ans=2*n-1;
  }else{
    ans=n-1;
  }

  n*=2;
  for(ll i=2;i<=n+2;i++){
    if (i*i>n)break;
    if (n%i==0){
      ll val0=i;
      ll val1=n/i;
      if (gcd(val0,val1)==1){
        ll ans0=garner2(val0,val1,1,0)-1+val0*val1;
        ll ans1=garner2(val0,val1,0,1)-1+val0*val1;
        ans0%=val0*val1;
        ans1%=val0*val1;
        if (ans0>1)
          ans=min(ans,ans0);
        if (ans1>1)
          ans=min(ans,ans1);
      }
    }
  }


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

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

int main(){
    int N;
    cin >> N;
    int count = 1;
    //count-1...残るレンガの数
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        if(a == count){
            count++;
        }
    }
    if(count-1 == 0) cout << -1 << endl;
    else cout << N - count + 1 << endl;
    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

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

    while (true) {
      int n = scanner.nextInt();
      if (n == 0) break;
      double m = 0.0, d = 0.0;

      for (int i = 0; i < n; ++i) {
        score[i] = scanner.nextInt();
        m += score[i];
      }

      m /= n;

      for (int i = 0; i < n; ++i) {
        d += Math.pow(((double)score[i] - m), 2);
      }

      d /= n;

      System.out.println(Math.sqrt(d));
    }
  }
}


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

#define MAXN 1000010
#define mod 1000000007

int n,f[MAXN],add;

int main()
{
    cin>>n;
    f[n]=n;
    f[n-1]=(long long)n*n%mod;
    for(int i=n-2;i>=1;--i)
    {
        add=(add+f[i+3])%mod;
        f[i]=f[i+1];
        f[i]=(f[i]+(long long)(n-1)*(n-1)%mod)%mod;
        f[i]=(f[i]+add)%mod;
        f[i]=(f[i]+i+1)%mod;
    }
    cout<<f[1]<<endl;
    return 0;
}

Measured memory_bytes: 4096
#include<iostream>
using namespace std;
 
int main(){
  int n, taro=0, hanako=0;
  string t, h;
 
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>t>>h;
    if(t>h) taro+=3;
    else if(t<h) hanako+=3;
    else{
      taro++;
      hanako++;
    }
  }
 
  cout<<taro<<" "<<hanako<<endl;
 
  return 0;
}


Measured memory_bytes: 3140
#include<bits/stdc++.h>
using namespace std;
long long   a[100005];
long long int mod=1000000007;
long long int j=mod-2;
long long int modpow (long long int a) {
	long long int res = 1;
	j=mod-2;
	while (j > 0)
		if (j & 1) {
			res = (res * a) % mod;
			--j;
		}
		else {
			a = (a * a) % mod;
			j >>= 1;
		}
	return res %mod;
}
int main()
{
   long long n,x;
   cin>>n>>x;
   for(long i=1;i<=n;i++)cin>>a[i];
   long long ans=0;
   for(long i=2;i<=n;i++)
   {
       long long p=a[i]+a[i-1];
       if(p>x)
       {
           long long d=p-x;
           a[i]=max(0LL,a[i]-d);
           ans+=d;
       }
   }
   cout<<ans<<endl;

}


Measured memory_bytes: 1024
//g++ main.cpp -I /usr/local/include/ac-library
#include<cmath>
//#include <atcoder/all>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
//using namespace atcoder;
stack<int> st;
queue<int> qu;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
#define ALL(a) a.begin(), a.end()
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define pb push_back
#define sz(x) (int)(x).size()
#define mod 1000000007
//#define mint=modint1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    int k;
    cin >> k;
    string s;
    rep(i,k){
        s+="ACL";
    }
    cout<<s<<endl;
    return 0;
}

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

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

  ll sum = 0;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
    sum += a.at(i);
  }

  int ans = 0;
  if (x == sum) {
    ans = N;
  } else if (x > sum) {
    ans = N - 1;
  } else { // x < sum
    sort(a.begin(), a.end());
    for (int i = 0; i < N; i++) {
      int num = a.at(i);
      if (x < num) {
        break;
      }
      x -= num;
      ans++;
    }
  }

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

Measured memory_bytes: 256
import std.stdio;
import std.string;
import std.algorithm;

string[] s;
int[500][500] memo;
int h, w, ans;

void main(){
	while (readf("%d %d\n", &h, &w), h != 0 || w != 0) {
		s = [];
		for (int i = 0; i < h; i++) {
			s ~= chomp(readln());
		}
		for (int y = 0; y < h; y++) {
			for (int x = w-1; x >= 0; x--) {
				memo[y][x] = calcWidth(x, y);
			}
		}
		ans = 0;
		for (int y = 0; y < h; y++) {
			for (int x = 0; x < w; x++) {
				ans = max(ans, solve(x, y));
			}
		}
		writeln(ans);
	}
}

int calcWidth(int x, int y){
	int result = 1;
	if(s[y][x] == '*') return 0;
	if(x+1 < w) result += memo[y][x+1]; 
	return result;
}

int solve(int x, int y){
	int result = 0;
	int minWidth = 9999;
	for (int i = y; i < h; i++) {
		minWidth = min(minWidth, memo[i][x]);
		result = max(result, minWidth * (i-y+1));
	}
	return result;
}

Measured memory_bytes: 2516
#include <iostream>
using namespace std;
int main(){
  string s;
  int res = 0;
  cin >> s;
  for(char x : s){
    if(x == 'R') ++res;
  }
  if(res == 2 && s[1] == 'S') res --;
  cout << res << endl;
  return 0;
}


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

typedef long long  LL;
typedef pair <LL,LL>  PLL;
const int N=132000;
const LL oo=1LL<<60;
int n,f[N],a[N],ls[N],rs[N],siz[N],tot[N],TOT,ans;
LL dep[N],L,R,k;
PLL temp[N];
vector <PLL> V[N];

void dfs(int x)
{
	dep[x]=dep[f[x]]+a[x];
	if (ls[x])
		{
			dfs(ls[x]),dfs(rs[x]),siz[x]+=siz[ls[x]]+siz[rs[x]];
			V[x].resize(min(siz[ls[x]],siz[rs[x]])*2);
		}else  siz[x]=1,V[x].resize(1);
}

void clear(){TOT=-1;}
void push(LL a,LL b){temp[++TOT]=make_pair(a,b);}
void move(int x){tot[x]=TOT;  for (int i=0; i<=TOT; i++)  V[x][i]=temp[i];}

void calc(int x)
{
	if (!ans)  return;
	if (!ls[x])  {clear(),push(dep[x],dep[x]),move(x);  return;}
	int Ls=ls[x],Rs=rs[x];
	calc(Ls),calc(Rs);
	if (!ans)  return;
	if (tot[Ls]>tot[Rs])  swap(Ls,Rs);
	clear();
	for (int i=0,j=tot[Rs]; i<=tot[Ls]&&j>=0; i++)
		{
			while ((j>=0)&&(V[Rs][j].first+V[Ls][i].first>k+2*dep[x]))  j--;
			if ((i==0)&&(j<0))  {ans=0;  return;}
			if (j>=0)
				{
					push(V[Ls][i].second,V[Rs][j].second);
					push(V[Rs][j].second,V[Ls][i].second);
				}
		}
	sort(temp,temp+TOT+1);
	LL t=oo;
	for (int i=0; i<=TOT; i++)
		if (temp[i].second>=t)  temp[i].first=oo;
		else  t=temp[i].second;
	sort(temp,temp+TOT+1);
	while (temp[TOT].first==oo)  TOT--;
	move(x);
}

void work()
{
	scanf("%d",&n);
	for (int i=2; i<=n; i++)
		{
			scanf("%d %d",&f[i],&a[i]),R+=a[i];
			if (ls[f[i]])  rs[f[i]]=i;  else  ls[f[i]]=i;
		}
	dfs(1);
	while (R-L>1)  k=(L+R)>>1,ans=1,calc(1),ans?R=k:L=k;
	cout<<R;
}

int main()
{
	work();
	return 0;
}


Measured memory_bytes: 29056
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#define REP(x,y) for(int i=x;i<=y;i++)
using namespace std;

struct point {
	double x; double y;
};
double INF = 100000000000000000;
int const MAX = 1005;
point a[MAX];
double radius[MAX];
double g[MAX][MAX];
int color[MAX];
double dist[MAX];

int main() {
	cin >> a[0].x >> a[0].y >> a[1].x >> a[1].y;
	radius[1] = radius[0] = 0;
	int n;
	cin >> n;
	REP(2, n + 1) {
		cin >> a[i].x >> a[i].y;
		cin >> radius[i];
	}
	REP(0, n + 1) {
		for (int j = 0; j <= i; j++) {
			double dist_x, dist_y;
			dist_x = a[i].x - a[j].x;
			dist_y = a[i].y - a[j].y;
			g[i][j] = g[j][i] = max(double(0),sqrt(dist_x*dist_x + dist_y * dist_y)-radius[i]-radius[j]);
		}
	}
	int now = 0;
	REP(0, n + 1) color[i] = 0;
	REP(0, n + 1) dist[i] = INF;
	color[0] = 1;
	dist[0] = 0;
	while (now != 1) {
		int nearest = 1;
		double nearest_dist = INF;
		REP(1, n + 1) {
			if (color[i] == 0) {
				dist[i] = min(dist[i], g[i][now]+dist[now]);
				if (nearest_dist >= dist[i]) {
					nearest_dist = dist[i];
					nearest = i;
				}
			}
		}
		now = nearest;
		color[now] = 1;
	}
	cout.precision(20);
	cout << dist[1] << endl;
}

Measured memory_bytes: 8192
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll x[10], y[10];
    rep(i,0,N) cin >> x[i] >> y[i];
    double ans = 0.0;
    vector<ll> v(N);
    iota(v.begin(), v.end(), 0);
    do{
        double res = 0.0;
        rep(i,0,N-1){
            res += sqrt((x[v[i]] - x[v[i+1]]) * (x[v[i]] - x[v[i+1]]) + (y[v[i]] - y[v[i+1]]) * (y[v[i]] - y[v[i+1]]));
        }
        ans += res;
    }while(next_permutation(v.begin(), v.end()));
    ll n = 1;
    rep(i,1,N+1) n *= i;
    ans /= (double) n;
    cout << setprecision(12) << ans << endl;

    

}

Measured memory_bytes: 256
from itertools import permutations
n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
l=[i for i in range(1,n+1)]
L=list(map(list,permutations(l)))
vp=L.index(p)
vq=L.index(q)
print(abs(vp-vq))

Measured memory_bytes: 10356
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstdlib>

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

using namespace std;

typedef long long int ll;

const ll INF=(ll)1e18;

int main(){
  int N;

  cin >> N;

  vector<ll> a;

  REP(i,N){
    ll aa;
    cin >> aa;
    a.push_back(aa);
  }

  vector<ll> c;

  int ans = 0;
  for(int i = N-1; i >= 0; i--){
    ll t = a[i];

    vector<ll>::iterator iter = upper_bound(c.begin(),c.end(), t);
    if(iter == c.end()){
      ans++;
      c.push_back(t);
    }else{
      *iter = t;
    }

    // REP(j,c.size()){
    //   cout << c[j] << " ";
    // }
    // cout << endl;
  }
  cout << ans << endl;
}

Measured memory_bytes: 2548
n, m = map(int, input().split())
item = input().split()
item = [int(x) for x in item]

item.sort(reverse=True)

s = sum(item)
res = 0
for i in range(n):
  if item[i] >= s / (4*m):
    res += 1
    if res >= m:
      print('Yes')
      break
  else:
    print('No')
    break


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
typedef long long ll;
typedef long double ld;


#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
ll S[1000] = { 0 };
ll N,M,Q;


int main() {
	multimap<string, ll>A;
	cin >> Q;
	rep(i, Q) {
		ll a;
		cin >> a ;
		if (a==0) {
			string key;
			ll x;
			cin >> key >> x;
			A.insert(make_pair(key, x));
		}
		else if(a==1){
			string key;
			cin >> key;
			multimap<string, ll>::iterator j = A.find(key);
			while(j!=A.end()) {
				string tmp = j->first;
				cout << j->second << endl;
				j++;
				if (j==A.end()||tmp != j->first)break;
			}
		}
		else if(a==2){
			string key;
			cin >> key;
			A.erase(key);
		}
		else {
			string key1,key2;
			cin >> key1>>key2;
			for (multimap<string, ll>::iterator j = A.lower_bound(key1); j != A.upper_bound(key2);++j) {
				cout <<j->first<<" "<< j->second << endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 24928
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	S := sc.nextStr()
	if S == "Sunny" {
		fmt.Println("Cloudy")
	} else if S == "Cloudy" {
		fmt.Println("Rainy")
	} else {
		fmt.Println("Sunny")
	}
}


Measured memory_bytes: 640
w = gets.chomp.to_i
n = gets.chomp.to_i
lots = (1..w).to_a

n.times do
  a, b = gets.chomp.split(',').map(&:to_i)
  lots[a - 1], lots[b - 1] = lots[b - 1], lots[a - 1]
end

puts lots

Measured memory_bytes: 8504
#include <iostream>
#include <string>
using namespace std;
char s[124];

int main()
{
    string line;
    cin >> line;
    for(int i = 0; i < line.length();i++)
    {
        s[line.at(i)]++;
    }
    for(int i = 96; i<= 123; i++)
    {
        if(s[i] % 2 != 0)
        {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <stack>

#define rep(i,x) for(int i=0;i<x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rep_to(a,i,x) for(int i=a;i<x;i++)

using namespace std;

int main()
{
	int N,M;
	FILE *fp;
	fp=fopen("ans.txt","w");

	while(cin >> N && N)
	{
		int robot_x=10,robot_y=10;
		int item_x[100000]={};
		int item_y[100000]={};
		int flag[100][100]={};
		int count=0;

		rep(i,N)cin >> item_x[i] >> item_y[i];
		
		cin >> M;
		rep(i,M)
		{
			char muki[10]={};
			int L=0;

			cin >> muki >> L;
			
			rep(j,L)
			{
				if(muki[0]=='N')robot_y++;
				else if(muki[0]=='E')robot_x++;
				else if(muki[0]=='S')robot_y--;
				else if(muki[0]=='W')robot_x--;

				rep(k,N)
				{
					if(robot_x == item_x[k] && robot_y == item_y[k] && flag[robot_x][robot_y] == 0)
					{
						count++;
						flag[robot_x][robot_y]=1;
					}
				}
			}
		} 
		if(N<=count)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	fclose(fp);
	return 0;
}

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

int gcd(int x, int y) {
	if (x % y == 0) {
		return y;
	} else {
		return gcd(y, x%y);
	}
}

int main() {
	int x = 0;
	int y = 0;
	cin>>x>>y;
	if (x > y) {
		cout<<gcd(x, y)<<endl;
	} else {
		cout<<gcd(y, x)<<endl;
	}
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define int ll
//const ll mod = 1000000007;

int n,m,k,a[30][31];
int temp,ans;
signed main() {
    cin >> n >> m;
    for (int i=0;i<n;i++) {
        cin >> k;
        for (int j=0;j<k;j++) {
            cin >> temp; temp--;
            a[i][temp] = 1;
        }
    }
    for (int i=0;i<m;i++) {
        for (int j=0;j<n;j++) {
            a[0][i] &= a[j][i];
        }
    }
    for (int i=0;i<m;i++) {
        ans += a[0][i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;
class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int x = sc.nextInt(), y = sc.nextInt();
			if(x == 0 && y == 0) {
				break;
			}
			if(x > y) {
				int t = x;
				x = y;
				y = t;
			}
			System.out.println(x + " " + y);
		}
	}
}


Measured memory_bytes: 35480