akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
typedef long long       ll;
#define pb                push_back
#define mp              make_pair
#define sz(a)           a.size()
#define mods(a, m)          ((a % m + m) % m)
#define md(a)               mods(a, MOD)
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define mem(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define f first
#define s second
#define fore(i, b, e)     for (ll i = b; i < e; i++)
#define forr(i, b, e)     for (ll  i = b; i < e; i++)
#define endl '\n'


using namespace std;
//using namespace __gnu_pbds;
typedef long double       ld;

typedef pair<ll, ll>  ii;
typedef pair<ll,ii> iii;
typedef vector<ll>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = ll(1e9 + 7);
const ll MOD = 1e9+7;
const double EPS = 1e-9;
const double PI = acos(-1);
#define tam 3000003
ll pot(ll b,ll e)
{
    b%=MOD;
    ll res=1;
    while(e)
    {
        if (e&1)res*=b,res%=MOD;
        b*=b,b%=MOD;
        e/=2;
    }
    res%=MOD;
    return res;
}
ll fact[tam],invfact[tam];
ll C(ll y,ll x)
{
    if (x<0|| y<0|| x>y)
        return 0;
    return ((fact[y]*invfact[x])%MOD*invfact[y-x])%MOD;         
}
ll get(ll y,ll x)
{
    if (y-x<0)
        cout<<"tue\n";
    //cout<<y<<' '<<x<<endl;
    ll res=0;
    res=pot(2,y+1)-1+MOD;res%=MOD;
    ll yy=y-1;
    ll acont=0;
    while(yy>=0)
    {
        res-=C(yy,x)*(pot(2,acont+1)-1);
        res%=MOD;
        yy--;
        acont++;
    }
    x--,y--;acont=0;
    while(x>=0 && y>=0)
    {
        res-=C(y,x)*(pot(2,acont+1)-1);
        res%=MOD;
        acont++;
        x--,y--;
    }
    res+=MOD;
    res%=MOD;
    return res;
}
int main()
{
    fact[0]=1;
    forr(i,1,tam){
        fact[i]=(fact[i-1]*i)%MOD;
    }
    //cout<<fact[tam-1]<<"wathc\n";
    invfact[0]=1;
    invfact[tam-1]=pot(fact[tam-1],MOD-2);
    for(ll i=tam-2;i>0;i--)
    {
        invfact[i]=invfact[i+1]*(i+1);
        invfact[i]%=MOD;
    }

    std::ios::sync_with_stdio(false); cin.tie(0);
    ll r1,c1,r2,c2;
    cin>>r1>>c1>>r2>>c2;
    ll y0=r1+c1,x0=c1;
    ll yf=r2+c2,xf=c2;
    ll x1,y1,x2,y2;
    //cout<<y0<<" "<<x0<<"  "<<yf<<" "<<xf<<endl;
    y1=yf-(xf-x0);
    x1=x0;
    x2=xf;
    y2=yf-(y1-y0);
    ll tot=0;
    tot+=get(yf,xf);
    //cout<<tot<<endl;
    tot-=get(y1-1,x1-1);
    tot-=get(y2-1,x2);
    //cout<<tot<<endl;
    tot+=get(y0-2,x0-1);
    tot%=MOD;tot+=MOD;tot%=MOD;
    cout<<tot<<endl;

}   
// PLUS ULTRA!


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

int main() {
  ll N;
  cin >> N;
  vector<ll> sum(N);
  for (int i = 0; i < N; i++) {
    ll x;
    cin >> x;
    if (i > 0) sum[i] = sum[i-1] + x;
    else sum[i] = x;
  }
  
  ll m = abs(2*sum[0]-sum[N-1]);
  for (int i = 1; i < N-1; i++) {
    m = min(m,abs(2*sum[i]-sum[N-1]));
  }
  
  cout << m << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    int a,b,c,d;cin>>a>>b>>c>>d;
    if(a+b>c+d){
        cout<<"Left"<<endl;
    }else if(a+b==c+d){
        cout<<"Balanced"<<endl;
    }else{
        cout<<"Right"<<endl;
    }
    
}


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

#define debug(x) cout << (#x) << " is " << x << endl;
#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;


int main()
{
    lli d, t, s;
    cin >> d >> t >> s;
    if(d <= t*s){
		puts("Yes");
	}
	else puts("No\n");
 
    return 0;
}


Measured memory_bytes: 3592
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)





vector<vector<ll>> g;

ll v1;
ll d;

void dfs(ll now, ll par, ll k) {
	if (d < k) {
		d = k;
		v1 = now;
	}
	for (auto &v : g[now]) {
		if (v == par) continue;
		dfs(v, now, k + 1);
	}
}

int main(){
	ll n;
	cin >> n;
	g.resize(n);
	REP(i, n - 1) {
		ll a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(0, -1, 0);
	d = 0;
	dfs(v1, -1, 0);
	if (d % 3 != 1) cout << "First" << endl;
	else cout << "Second" << endl;
}

Measured memory_bytes: 20608
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
using ll=long long;
const ll MOD=1e9+7;
const int INF=1<<30;

int main(){
  int N,M; cin >> N >> M;
  vector<pair<int,int> > v(M);
  rep(i,M){
    cin >> v[i].first >> v[i].second;
  }
  sort(all(v));
  int ans=0;
  int cuta=0,cutb=N+1;
  rep(i,M){
    if (cuta<v[i].first) cuta=v[i].first;
    if (v[i].second<cutb) cutb=v[i].second;
    if (cutb<=v[i].first) {ans++;cuta=v[i].first;cutb=v[i].second;}
  }
  cout << ans+1 << endl;
}

Measured memory_bytes: 1024
from sys import stdin
readline = stdin.readline
def r_map(): return map(int, readline().rstrip().split())

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * (n + 1)
        self.rank = [0] * (n + 1)
        self.max_size = 1

    def root(self, x):
        if(self.parents[x] < 0):
            return x
        else:
            self.parents[x] = self.root(self.parents[x])
            return self.parents[x]

    def unite(self, x, y) -> bool:
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.rank[x] > self.rank[y]:
            self.parents[x] += self.parents[y]
            self.parents[y] = x
        else:
            self.parents[y] += self.parents[x]
            self.parents[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1
        self.max_size = max(self.max_size, self.size(x))
        return True

    def members(self, x):
        root = self.root(x)
        return [i for i in range(self.n) if self.root(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def is_same(self, x, y) -> bool:
        return self.root(x) == self.root(y)

    def size(self, x):
        return -self.parents[self.root(x)]

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}


def main():
    N, M = r_map()
    uf = UnionFind(N)
    for _ in range(M):
        a, b = r_map()
        uf.unite(a, b)
    print(uf.max_size)

if __name__ == "__main__":
    main()


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

string s[120];
string t[120];
vector<int> s_i(120);

int main(void){
  int N,M;

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

  cin >> M;
  for(int i=0; i<M; i++) cin >> t[i];


  int tmp =0;

  for(int i=0; i<N; i++){
    int cnt_s = 0; 
    for(int j=1+i; j<N; j++){
      if(s[i] == s[j]) cnt_s++;
    }
    s_i.at(i) += cnt_s + 1;
  }

  for(int i=0; i<N; i++){
    int cnt_t = 0;
    for(int j=0; j<M; j++){
      if(s[i] == t[j]) cnt_t--;
    }
    s_i.at(i) += cnt_t;
  }

  sort(s_i.begin(),s_i.end(),greater<int>());

  int ans = s_i.at(0);

  if(ans <= 0) cout << 0 << endl;
  else cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let x = read_as_vec::<i64>()[0];
    let mut v: Vec<i64> = vec![0;1001];

    for i in 0..v.len(){
        v[i] = (i as i64-500).pow(5);
    }

    for i in 0..v.len(){
        for j in 0..v.len(){
            if v[i] - v[j] == x{
                println!("{} {}", (i as i64)-500, (j as i64) - 500);
                return;
            }
        }
    }
}


Measured memory_bytes: 2176
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i = 0; i < n; i++) {
			boolean[][] map = new boolean[10][10];
			for(int j = 0; j < 10; j++) {
				for(int k = 0; k < 10; k++) {
					map[j][k] = (sc.nextInt() == 1)?true:false;
				}
			}
			
			IN:for(int j = 0; j < 1 << 10; j++) {
				boolean[][] cpMap = new boolean[10][10];
				boolean[][] faMap = new boolean[10][10];
				for(int k = 0; k < 10; k++) {
					cpMap[k] = Arrays.copyOf(map[k], 10);
				}
				for(int k = 0; k < 10; k++) {
					if((j & 1 << k) != 0) {
						faMap[0][k] = true;
						fa(cpMap,0,k);
					}
				}
				for(int k = 1; k < 10; k++) {
					for(int l = 0; l < 10; l++) {
						if(cpMap[k-1][l]) {
							fa(cpMap,k,l);
							faMap[k][l] = true;
						}
						if(k != 1 && cpMap[k-2][l]) {
							continue IN;
						}
					}
				}
				if(check(cpMap)) {
					show(faMap);
					break;
				}
			}
		}
	}
	public static void show(boolean[][] a) {
		for(int i = 0; i < 10; i++) {
			if(a[i][0]) {
				System.out.print(1);
			}
			else {
				System.out.print(0);
			}
			for(int j = 1; j < 10; j++) {
				if(a[i][j]) {
					System.out.print(" " + 1);
				}
				else {
					System.out.print(" " + 0);
				}
			}
			System.out.println();
		}
	}
	
	public static boolean check(boolean[][] a) {
		for(int i = 0; i < 10; i++) {
			for(int j = 0; j < 10; j++) {
				if(a[i][j]) return false;
			}
		}
		return true;
	}
	
	public static void fa(boolean[][] a, int b, int c) {
		a[b][c] = (a[b][c])?false:true;
		for(int i = 0; i < 4; i++) {
			if(fb(b + vy[i],c + vx[i])) {
				a[b + vy[i]][c + vx[i]] = (a[b + vy[i]][c + vx[i]])?false:true;
			}
		}
	}
	
	public static boolean fb(int b, int c) {
		if(b < 0 || c < 0 || b >= 10 || c >= 10) return false;
		return true;
	}
	
	static int[] vx = new int[] {1,0,-1,0};
	static int[] vy = new int[] {0,1,0,-1};
}

Measured memory_bytes: 34540
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> p(m), y(m);
    vector<vector<pair<int, int>>> v(n);

    rep(i, m) {
        cin >> p[i] >> y[i];
        v[p[i]-1].push_back(make_pair(y[i], i));
    }

    rep(i, n) {
        
        sort(v[i].begin(), v[i].end());

        rep(j, v[i].size()) {
            y[v[i][j].second] = j+1;
        }
    }

    rep(i, m) {
        printf("%06d%06d\n", p[i], y[i]);
    }
    
    return 0;
}

Measured memory_bytes: 7808
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
const ll MAX = 300010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c;
    cin >> a >> b >> c;
    PRINT(min(b/a,c));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

#define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << endl
#define LINE cout << "line : " << __LINE__ << endl
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x) ;
#define LINE 	;
#define dumpV(v);
#define STOP 	;
#endif

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fi<<", "<<a.se<<')';
    return out;
  }
}


//重心分解
const int MAX_NODE = 1e5 + 10;
struct Edge
{
	int to;
	ll cost;
};

vector<Edge> es[MAX_NODE];
vl subTreeSize(MAX_NODE);

ll dfsSubTreeSize(int cur, int par) {
	ll ret = 1LL;
	for(auto& e : es[cur]) {
		int to = e.to;
		if(to == par) continue;
		ret += dfsSubTreeSize(to, cur);
	}
	return subTreeSize[cur] = ret;
}
//secondが重心　第３引数は頂点数　あらかじめdfsSubTreeの必要あり
pll dfsCenter(int cur, int par, int n){
	pll ret = {1LL<<60, -1LL};
	ll m = 0LL;
	for(auto& e : es[cur]) {
		int to = e.to;
		if(to == par) continue;
		ret = min(ret, dfsCenter(to, cur, n));
		m = max(m, subTreeSize[to]);
	}
	return min(ret, {max(m, n-subTreeSize[cur]), cur});
}

ll dfs(int cur, int par, ll depth) {
	ll ret = depth*2;
	for(auto& e: es[cur]) {
		int to = e.to;
		if(to == par) continue;
		ret += dfs(to, cur, depth+e.cost);
	}
	return ret;
}

int main(){
	int n;
	cin >> n;
	rep(i, n-1) {
		int a, b;
		ll c;
		cin >> a >> b >> c;
		a--;
		b--;
		es[a].pb({b, c});
		es[b].pb({a, c});
	}
	dfsSubTreeSize(0, -1);
	int center = dfsCenter(0, -1, n).se;

	subTreeSize.clear();
	subTreeSize.resize(n);
	dfsSubTreeSize(center, -1);

	ll sum = dfs(center, -1, 0);

	rep(i, n) {
		if(i == center) continue;
		if(subTreeSize[i]*2 == n) {
			for(auto& e : es[i]) {
				if(e.to == center) {
					cout << sum - e.cost << endl;
					return 0;
				}
			}
		}
	}
	
	ll m = 1e18;
	for(auto& e: es[center]) m = min(m, e.cost);
	cout << sum - m << endl;

	return 0;
}

Measured memory_bytes: 20608
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

    int N;
    int[] A;

    public void solve() {
        N = nextInt();
        A = new int[N];
        for(int i = 0;i < N;i++){
            A[i] = nextInt();
        }

        int oddCount = 0;
        for(int i = 0;i < N;i++){
            oddCount += A[i] % 2;
        }

        if(oddCount % 2 ==  0) {
            out.println("YES");
        } else {
            out.println("NO");
        }
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[2048];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

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

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

Measured memory_bytes: 37128
from bisect import bisect_left
from bisect import bisect_right


N = int(input())
L = list(map(int, input().split()))
L.sort()

ans = 0
for i in range(N):
    for j in range(i+1, N):
        l = L[j] - L[i]
        r = L[j] + L[i]

        il = bisect_right(L, l, j)
        ir = bisect_left(L, r, j)

        if il == N-1:
            break

        ans += ir - il - 1

print(ans)

Measured memory_bytes: 45864
n = int(input())
tb = 'abcdefghijklmnopqrstuvwxyz'

def output(s, m):
    if len(s) == n:
        print(s)
    else:
        for i in range(m + 1):
            if i == m:
                output(s + tb[i], m + 1)
            else:
                output(s + tb[i], m)
output("", 0)


Measured memory_bytes: 4404
import java.time.DayOfWeek;
import java.time.format.TextStyle;
import java.util.Scanner;
import java.util.Arrays;
import java.util.Locale;

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        String[] dayoftheweek = new String[8];
        String str = scanner.nextLine();
        int result = 7;

        for(int i = 1; i <= 7; i++) {
            dayoftheweek[i] = DayOfWeek.of(i).getDisplayName(TextStyle.SHORT_STANDALONE, Locale.US).toUpperCase();
            if (dayoftheweek[i].equals(str) != dayoftheweek[i].equals("SUN")) {
                result = 7 - i;
                break;
            }
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 28112
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main() {
    string str;
    cin >> str;

    for (int i = 0; i < str.size(); i++) {
        if (str[i] == '1') str[i] = '9';
        else str[i] = '1';
    }

    cout << str << endl;
}


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

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
using P = complex<double>;
using lli = long long int;
using T = lli;
bool cmp_x(const P& p, const P& q)
{
    if (p.real() != q.real())
        return p.real() < q.real();
    return p.imag() < q.imag();
}
T dot(P a, P b)
{
    //内積
    return (conj(a) * b).real();
}
T cross(P a, P b)
{
    //det
    return (conj(a) * b).imag();
}
vector<P> convex_hull(P* ps, int n)
{
    sort(ps, ps + n, cmp_x);
    int k = 0;
    vector<P> qs(n * 2);
    rep(i, n)
    {
        while (k > 1 && cross((qs[k - 1] - qs[k - 2]), (ps[i] - qs[k - 1])) <= 0)
            k--;
        qs[k++] = ps[i];
    }
    for (int i = n - 2, t = k; i >= 0; i--) {
        while (k > t && cross((qs[k - 1] - qs[k - 2]), (ps[i] - qs[k - 1])) <= 0)
            k--;
        qs[k++] = ps[i];
    }
    qs.resize(k - 1);
    return qs;
}
P x[100005];
int main()
{
    int n;
    cin >> n;
    T a, b;

    map<lli,map<lli,int>> idx;
    map<lli,map<lli,int>> prev;


    vector<P> Y;
    rep(i, n)
    {
        cin >> a >> b;
        x[i] = P(a, b);
        Y.push_back(x[i]);
        prev[a][b] = i;
    }
    
    vector<P> con = convex_hull(x, n);
    if(n==2){
        cout << 0.5 << "\n" << 0.5 << endl;
        return 0;
    }
    int cnt = 0;
    for(auto s:con)
    {
        idx[s.imag()][s.real()] = cnt++;
    }
    int k = con.size();
    vector<double> ans ;
    rep(i,n){
        if(idx[Y[i].imag()].find(Y[i].real())==idx[Y[i].imag()].end()){
            ans.push_back(0.0);
            continue;
        }
        int id = idx[Y[i].imag()][Y[i].real()];
        P l = con[(id-1+k)%k];
        P c = Y[i];
        P r = con[(id+1+k)%k];
        using Pd = complex<double>;
        Pd l_c = (l+c);l_c/=2.0;
        Pd r_c = (r+c);r_c/=2.0;
        double rad =    M_PI - abs(arg((r_c - c) / (l_c - c)));
        ans.push_back(rad);
    }
    double total = 0.0;
    rep(i,n)total += ans[i];
    rep(i,n){
        printf("%.10f\n",ans[i]/total);
    }
}


Measured memory_bytes: 512
#include <iostream>
    using namespace std;
     
    int main() {
    	 int h,w,i,j;
        while(1){
			cin>>h>>w;
            if (h==0&&w==0){break;}
            for(i=0;i<h;i++){
                for(j=0;j<w;j++){
                    if(i==0||i==h-1||j==0||j==w-1){
                        cout<<"#";
                    }
                    else{
                        cout<<".";
                    }
                }
                cout<<endl;
            }
            cout<<endl;
        }
}


Measured memory_bytes: 3080
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer;
import java.lang.*; 
import java.util.*;

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

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

		String next() 
		{ 
			while (st == null || !st.hasMoreElements()) 
			{ 
				try
				{ 
					st = new StringTokenizer(br.readLine()); 
				} 
				catch (IOException e) 
				{ 
					e.printStackTrace(); 
				} 
			} 
			return st.nextToken(); 
		} 

		int nextInt() 
		{ 
			return Integer.parseInt(next()); 
		} 

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

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

		String nextLine() 
		{ 
			String str = ""; 
			try
			{ 
				str = br.readLine(); 
			} 
			catch (IOException e) 
			{ 
				e.printStackTrace(); 
			} 
			return str; 
		} 
		
	}
public static void main(String[] args) 
	{ 
		FastReader ob=new FastReader(); 
		int a1 = ob.nextInt(),a3 = ob.nextInt(),a2 = ob.nextInt();
		if(a1+a2+a3>=22){
		    System.out.println("bust");
		    return;
		}
		System.out.println("win");
	}
		
	
} 	

Measured memory_bytes: 23124
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

const int N = 105;

int a[N], b[N];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) b[i] = (int) 2e9;
  for (int i = 0; i + 1 < n; i++) {
    cin >> a[i];
  }
  long long ans = 0;
  for (int i = 0; i + 1 < n; i++) {
    b[i] = min(b[i], a[i]);
    b[i + 1] = min(b[i + 1], a[i]);
    ans += b[i];
  }
  ans += b[n - 1];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int A = scanner.nextInt();
    int B = scanner.nextInt();
    int C = scanner.nextInt();
    int D = scanner.nextInt();
    char[] S = scanner.next().toCharArray();
    if (possible(N, A - 1, B - 1, C - 1, D - 1, S)) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }

  private static boolean possible(int N, int A, int B, int C, int D, char[] S) {
    for (int i = A; i < C; i++) if (S[i] == '#' && S[i + 1] == '#') return false;
    for (int i = B; i < D; i++) if (S[i] == '#' && S[i + 1] == '#') return false;
    if (C < D) return true;
    for (int i = B; i <= D && i < N - 1; i++) if (S[i - 1] == '.' && S[i] == '.' && S[i + 1] == '.') return true;
    return false;
  }
}


Measured memory_bytes: 26416
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S,T;
  cin >> S >> T;
  
  if( S.at(0) == T.at(0) && S.at(1) ==T .at(1) && S.at(2) == T.at(2)){
    cout << 3 << endl;
  }
  else if( S.at(0) != T.at(0) && S.at(1) !=T .at(1) && S.at(2) != T.at(2)){
    cout << 0 << endl;
  }
   else if( S.at(0) != T.at(0) && S.at(1) ==T .at(1) && S.at(2) == T.at(2)){
    cout << 2 << endl;
  }
     else if( S.at(0) == T.at(0) && S.at(1) !=T .at(1) && S.at(2) == T.at(2)){
    cout << 2 << endl;
  }
     else if( S.at(0) == T.at(0) && S.at(1) ==T .at(1) && S.at(2) != T.at(2)){
    cout << 2 << endl;
  }
  else{
    cout << 1 << endl;
  }
}
  
      
    

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

using namespace std;

const int N = 200010;

void QuickSort(char s[][11], int l, int h)
{
    int i = l;
    int j = h;
    char t[11],d[11];
    strcpy(t,s[(l+h)/2]);
        while (i <= j)
        {
            while(strcmp(s[j],t)>0)     
            j--;
            while(strcmp(s[i],t)<0)      
            i++;
            if(i<=j)
            {
                strcpy(d,s[i]);
                strcpy(s[i],s[j]);
                strcpy(s[j],d);
                i++;
                j--;
            }
        }    
        if(l<j) QuickSort(s, l, j);     
        if(i<h) QuickSort(s, i, h);    
    
}
int main()
{
	int i,j,n,a[N]={0},b=0,q=0;
	char s[N][11],t[11];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	scanf("%s",s[i]);
	QuickSort(s,0, n-1);
	
    for(j=0;j<n;j++)
	{
		if(strcmp(s[j],s[j+1])==0)
		{
			a[j-b]++;
			b=a[j-b];
		}
		else
		{
			if(a[j-b]>q)
			q=a[j-b];
			b=0;
		}
	}
	
	for(i=0;i<n;i++)
	{
		if(a[i]==q)
		printf("%s\n",s[i]);
	}

return 0;
}

Measured memory_bytes: 4864
A = [int(input()) for i in range(5)]
B = []
for a in A :
    if a % 10 != 0 :
        B.append(a - a % 10 + 10)
    else :
        B.append(a)
diff = [(b - a) for a, b in zip(A, B)]
print(sum(B)-max(diff))


Measured memory_bytes: 9000
#include<stdio.h>
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<list>
#include<math.h>
using namespace std;


bool checkCycle(vector<int> & S, const int n,const int t)
{
	for (int i = 0; i < n - t; ++i)
	{
		if (S[i] != S[i + t])
		{
			return false;
		}
	}
	return true;
}


int main(){
	std::istream & c_in = cin;

	int n;
	c_in >> n;
	vector<int> S;
	S.resize(n);
	for (int i = 0; i < n; ++i)
	{
		c_in >> S[i];
	}
	int k;
	for (int t = 1; t <= n; ++t)
	{
		if ((n % t) != 0)
		{
			continue;
		}
		if (checkCycle(S, n,t))
		{
			k = n / t;
			break;
		}
	}
	cout << k << endl;
}

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

int main()
{
    int N;
    cin >> N;
    int A[N];
    REP(i, N) cin >> A[i];

    int num = 0;
    ll sum = 0;
    REP(i, N) if (A[i] < 0) ++num;
    REP(i, N) sum += abs(A[i]);

    if (num%2 != 0)
    {
        int minv = INT_MAX;
        REP(i, N) minv = min(minv, abs(A[i]));
        sum -= 2*minv;
    }

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 640
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
map<string,int> data;
map<string,vector<string> >ren;

inline int res(string s){
	if(!ren.count(s))return data[s];
	int sum = 0;
	for(int i =0;i <ren[s].size();i++){
		sum +=res(ren[s][i]);
	}
	data[s]=min(data[s],sum);
	return data[s];
}

int main(){
	int n,m;
	while(scanf("%d",&n),n){
		data.clear();
		ren.clear();
		for(int i =0;i < n;i++){
			string item;
			int cst;
			cin>>item>>cst;
			data[item] =cst;
		}
		cin>>m;
		int k;
		for(int i =0;i <m;i++){
			string renkin;
			cin>>renkin;
			scanf("%d",&k);
			//int sum=0;
			for(int j =0;j <k;j++){
				string tmp;
				cin>>tmp;
				ren[renkin].push_back(tmp);
			}
			//data[renkin]=min(sum,data[renkin]);
		}
		string ans;
		cin>>ans;
		cout <<res(ans)<<endl;
	}
	return 0;
}

Measured memory_bytes: 1284
n, m = gets.split(" ").map(&:to_i)
cards = gets.split(" ").map(&:to_i)
changers = []
m.times do
  changers.push(gets.split(" ").map(&:to_i))
end

cards.sort!

changers.sort! {|a,b| a[1] <=> b[1]}.reverse!

biggest_changers = []

changers.each do |changer|
  changer[0].times do
    biggest_changers.push(changer[1])
    if biggest_changers.length > n
      break
    end
  end
  if biggest_changers.length > n
    break
  end
end

(n - biggest_changers.length).times do
  biggest_changers.push 0
end

cards.each_with_index do |card, index|
  if cards[index] < biggest_changers[index]
    cards[index] = biggest_changers[index]
  else
    break
  end
end

puts cards.inject(:+)

Measured memory_bytes: 19840
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception {
 		//入力された値の取得
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		//計算
		int answer = a + a * a + a * a * a;
		//出力
		System.out.println(answer);
	}
}


Measured memory_bytes: 35788
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  sort(ALL(v));
  int res = 0;
  vector<int> memo(1000005);
  for (int i = 0; i < n; ++i) {
    if(memo[v[i]] != 0){
      memo[v[i]] = 2;
      continue;
    }
    for (int j = 0; j < 1000005; j += v[i]) {
      memo[j]++;
    }
  }

  for (int i = 0; i < n; ++i) {
    if(memo[v[i]] == 1) res++;
  }
  cout << res <<endl;
}


Measured memory_bytes: 7936
#coding : utf-8

import os
import sys

N = int(input())

p = list(map(lambda x: int(x), input().split(" ")))

q = [i for i in range(1, N+1)]

cnt = 0

for i in range(N):
	if p[i] != q[i]:
		cnt += 1
		if cnt > 2:
			break

if cnt > 2:
	print("NO")
else:
	print("YES")



Measured memory_bytes: 3060
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 2000100;



int main(){
        _

        ll n; cin >> n;
        cout<<(n*(n-1))/2<<endl;




return 0;
}



Measured memory_bytes: 3600
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int m = gcd(A,B);
    if(C%m==0){
      System.out.println("YES");
    }else{
      System.out.println("NO");
    }
  }
  
  //最大公約数・最小公倍数（セットで使う）
 static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
 static int lcm (int a, int b) {return a*b/gcd(a,b);}

  
}


Measured memory_bytes: 21972
#include <iostream>
#include <algorithm>
#include <unistd.h>
#include <sstream>
#include <cmath>
#include <climits>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <string.h>
#include <iomanip>
using namespace std;
#define int long long
#define ull unsigned long long
#define F first
#define S second
#define nl "\n"
#define ld long double
#define div 1000000007
#define pi 3.14159265358979323846
#define pb push_back

void solve()
{
    int a,b,c,d;cin>>a>>b>>c>>d;
    int x1=a*c;
    int x2=a*d;
    int x3=b*c;int x4=b*d;
    cout<<max(max(x1,x2),max(x3,x4));
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl

using namespace std;
using ll = long long;


int main() {
  const int MAX = 100100;
  vector<int> cnt(MAX, 0);
  int n; cin >> n;
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
    cnt[a[i]]++;
  }

  sort(all(a));

  ll s = accumulate(all(a), 0ll);

  int q;
  cin >> q;
  vector<pair<int, int>> bc;
  rep(i, q) {
    int b, c;
    cin >> b >> c;
    bc.push_back({b, c});
  }

  rep(i, q) {
    int before = bc[i].first;
    int after = bc[i].second;

    int sa = after - before;

    int c = cnt[before];
    s += (c * sa);
    cout << s << endl;

    cnt[before] = 0;
    cnt[after] += c;
  }
}


Measured memory_bytes: 5100
N,M=map(int,input().split())
S=list(map(int,input().split()))
T=list(map(int,input().split()))
MOD=10**9+7
ans=0
dp=[[0]*(M+1) for _ in range(N+1)]
ans=[[0]*(M+1) for _ in range(N+1)]
for i in range(N):
    for j in range(M):
        if S[i]==T[j]:
            dp[i+1][j+1]=(ans[i][j]+1)%MOD
        else:
            dp[i+1][j+1]=0
        ans[i+1][j+1]=(ans[i][j+1]+ans[i+1][j]-ans[i][j]+dp[i+1][j+1])%MOD
print((ans[N][M]+1)%MOD)

Measured memory_bytes: 104540
#include<bits/stdc++.h>
#include<numeric>
#include<cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#define ll long long int
#define CON 100010
const long long mod=1e9+7;
const int INF=1001001001;
//const int inf=100000;
//const ll ful=1e18;
using namespace std;
//namespace mp = boost::multiprecision;
ll gcd(ll a,ll b)
{
	ll r=a%b;
	if(r==0)
	{
		return b;
	}
	return gcd(b,r);
}
ll lcm(ll num,ll gcd)
{
	return num/gcd;
}
int main() 
{
	ll a,b;
	cin>>a>>b;
	ll com=a*b;
	ll mul=gcd(max(a,b),min(a,b));
	ll ans=lcm(com,mul);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3640
def inputInline():
    N = int(input())
    numbers = list(map(int, input().split(" ")))
    return numbers


def insertionSort(numbers):
    N = len(numbers)
    for i in range(1, N):
        print(" ".join(list(map(str, numbers))))
        j = i - 1
        temp = numbers[i]
        while True:
            if j == -1:
                numbers[0] = temp
                break
            if temp < numbers[j]:
                numbers[j + 1] = numbers[j]
                j -= 1
            else:
                numbers[j + 1] = temp
                break
    return " ".join(list(map(str, numbers)))


print(insertionSort(inputInline()))

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



int main() {
	

	long long n,m,max;
	cin >> n>>m;
	long long count=0;

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

	max = 0;
	for (int i = 0; i < n; i++)
	{
		max += v_a[i];
	}
	
	for (int i = 0; i < n; i++)
	{
		if (4 * m * v_a[i] >= max)
		{

			count += 1;
		}
	}

	if (count >= m)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}




Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class C
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var NK = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var (N, K) = (NK[0], NK[1]);
            var A = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
            for (var i = K; i < N; i++)
            {
                Console.WriteLine(A[i - K] < A[i] ? "Yes" : "No");
            }
        }
    }
}


Measured memory_bytes: 47440
#include <iostream>

using namespace std;

int map[4][4];
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};

void click(int map[4][4], int cx, int cy)
{
	map[cx][cy]++;
	if(map[cx][cy] <= 4) return;
	
	int drop[4][4], ndrop[4][4];
	for(int x = 0; x < 4; x++){
		for(int y = 0; y < 4; y++){
			drop[x][y] = 0;
		}
	}
	drop[cx][cy] = 15;
	map[cx][cy] = 0;
	
	int nx, ny;
	bool flag = true;
	
	while(flag){
		flag = false;
		
		for(int x = 0; x < 4; x++){
			for(int y = 0; y < 4; y++){
				ndrop[x][y] = 0;
			}
		}
		
		for(int x = 0; x < 4; x++){
			for(int y = 0; y < 4; y++){
				for(int i = 0; i < 4; i++){
					if( (drop[x][y] & (1<<i) ) == 0 ) continue;
					nx = x + dx[i], ny = y + dy[i];
					if(nx < 0 || nx >= 4 || ny < 0 || ny >= 4) continue;
					if(map[nx][ny] != 0){
						map[nx][ny]++;
						if(map[nx][ny] >= 5){
							map[nx][ny] = 0;
							ndrop[nx][ny] = 15;
						}
					}else ndrop[nx][ny] |= (1<<i);
				}
			}
		}
		
		for(int x = 0; x < 4; x++){
			for(int y = 0; y < 4; y++){
				drop[x][y] = ndrop[x][y];
				if(drop[x][y]) flag = true;
			}
		}
	}
}

int dfs(int map[4][4], int clk)
{
	bool flag = true;
	for(int x = 0; x < 4; x++){
		for(int y = 0; y < 4; y++){
			if(map[x][y]){
				flag = false;
				goto end;
			}
		}
	}
	end:;
	if(flag) return 0;
			
	if(clk == 0) return 6;
	
	int nmap[4][4];
	int ret = 6;
	for(int x = 0; x < 4; x++){
		for(int y = 0; y < 4; y++){
			for(int i = 0; i < 4; i++){
				for(int j = 0; j < 4; j++){
					nmap[i][j] = map[i][j];
				}
			}
			click(nmap, x, y);
			ret = min(ret, dfs(nmap, clk-1) + 1);
		}
	}
	return ret;
}

int main(void)
{
	for(int y = 0; y < 4; y++){
		for(int x = 0; x < 4; x++){
			cin >> map[x][y];
		}
	}
	
	int ans = dfs(map, 5);
	if(ans > 5) ans = -1;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3120
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.next();
		int N = s.length();
		int count_p = 0, count_g = 0, score = 0;
		for (int i = 0; i < N; i++) {
			char top = s.charAt(i);
			if (count_p < count_g) {
				count_p++;
				if (top == 'g')
					score++;
			} else {
				count_g++;
				if (top == 'p')
					score--;
			}
		}
		System.out.println(score);
	}
}


Measured memory_bytes: 13940
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const double PI=acos(-1);
typedef pair<int,int>P;
const int mod =1e9+7;

int main()
{
    int n,m,x;
    cin>>n>>m>>x;
    vector<int> a(m);
    rep(i,m)cin>>a[i];
    int zero=0;
    int ngoal=0;
    rep(i,m)
    {
        if(a[i]<x)
        {
            zero+=1;
        }
        else if(a[i]>x)
        {
            ngoal+=1;
        }
    }
    cout<<min(zero,ngoal);
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<iomanip>
#include<unordered_map>
using namespace std;
#define l long
#define ll long long
#define ull unsigned long long
int main()
{
int n;
cin>>n;
vector<int>a(n);
for(int i=0;i<n;i++)cin>>a[i];
vector<int>dp(n);
dp[0]=0;
dp[1]=abs(a[1]-a[0]);
for(int i=2;i<n;i++)
{
	
	dp[i]=min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);	
}
//for(int i=0;i<n;i++)cout<<dp[i]<<" ";
cout<<dp[n-1]<<endl;


}

Measured memory_bytes: 1024
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        long ans = 0;
        for (int i = 1; i <= N; i++) {
            if(i%3!=0 && i%5!=0){
                ans += i;
            }
        }

        System.out.println(ans);


    }

}


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

int main() {
  int N;
  cin >> N;
  int A=0;
  vector<int> TJ(N);
  for(int i=0;i<N;i++){
    cin >> TJ.at(i);
  }
  sort(TJ.begin(), TJ.end());
    for(int j=1;j<N;j++){
      if(TJ.at(j-1)==TJ.at(j)) A++;
    }
  if(A==0) cout << "YES"<< endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
using namespace std;
#define int long long
signed main(){
    int N;
    cin >> N;
    map<string, int> s;
    string S[200020];
    for(int i = 0;i < N;i++){
        cin >> S[i];
        s[S[i]]++;
    }
    int max = 0;
     for(auto itr = s.begin(); itr != s.end(); ++itr) {
        if(itr->second > max)max = itr->second;
    }
    for(auto itr = s.begin(); itr != s.end(); ++itr) {
        if(itr->second == max)cout << itr->first << endl;     
    }
}


Measured memory_bytes: 28800
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long
#define pii pair<int,int>

using namespace std;

int main(){

    int A,B,C,D,E,F;cin>>A>>B>>C>>D>>E>>F;

    pii ans={100*A,0};
    for(int i=0;100*i<=F;i+=A){
        for(int j=0;100*i+100*j<=F;j+=B){
            for(int k=0;(100*(i+j)+k<=F)&&((i+j)*E>=k);k+=C){
                for(int l=0;(100*(i+j)+k+l<=F)&&((i+j)*E>=k+l);l+=D){
                    if((100*(i+j)+(k+l))*ans.second < (ans.first+ans.second)*(k+l)){
                        ans.first=100*(i+j);ans.second=k+l;
                    }
                }
            }
        }
    }

    cout<<ans.first+ans.second<<" "<<ans.second<<endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int n; cin >> n;
    vector<int> cnt(n + 1, 0);

    // 調和級数でlogn
    for (int i = 1; i <= n; ++i) {
        int t = i;

        while (t <= n) {
            cnt[t]++;
            t += i;
        }
    }

    ll ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans += (ll)i * (ll)cnt[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 42328
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

	public static void main(String[] args) {

		//?????£?????????
		int numH = 0;
		int numW = 0;

		String cell = "#";
		String con = ".";

		String[] NumWork;

		try {
			//??\????????????
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

			while (true) {
				String line = br.readLine();

				if (line != null) {

					//??°??£?????´??°?????????
					NumWork = line.split(" ", 0);

					//??´??°?????°??????
					ArrayList<Integer> NumList = new ArrayList<Integer>();

					for (int i = 0; i < NumWork.length; i++) {
						NumList.add(Integer.parseInt(NumWork[i]));
					}
					numH = NumList.get(0);
					numW = NumList.get(1);

					// ????????¨(?????????????????????)
					String outputStr = "";

					//??????????????????
					if (numH != 0 || numW != 0) {

						//????????¢?????????

						//????????????
						for (int i = 1; i <= numH; i++) {
							for (int j = 1; j <= numW; j++) {

								// ?\???°??????(#.#.)
								if ((i % 2) == 1){
									//??????????????????
									if((j % 2) == 1){
										outputStr += cell;
									}else{
									outputStr += con;
									}
								//??¶??°??????(.#.#)
								} else {
									//??????????????????
									if((j % 2) == 1){
										outputStr += con;
									}else{
									outputStr += cell;
									}
								}
							}
							//?????£???????????????
							System.out.println(outputStr);
							outputStr = "";
						}
						System.out.println("");

					}else{
						break;
					}
				}else{
					break;
				}

			}
		} catch (IOException e) {
			System.out.println(e);
		}

	}

}

Measured memory_bytes: 53448
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int MOD = 1e9 + 7;
const int64 INF64 = 1LL << 60;

struct Node {
  int x, y;
  int v;
};

const int N = 2e5 + 10;
Node e[N];
vector<ii> a[N];
bool visit[N];
int64 v[N];
int R, C;

void DFS(int k, int64 val, int x, int64 minv[]) {
  visit[x] = true;
  v[x] = val;
  minv[k] = min(minv[k], v[x]);
  for (auto& it : a[x]) {
    int y = it.first, z = it.second;
    if (visit[y]) continue;
    DFS(1 - k, z - val, y, minv);
  }
}

int main() {
  int n;
  scanf("%d%d%d", &R, &C, &n);
  for (int i = 0; i < n; ++i) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    --x; --y;
    a[x].push_back({R + y, z});
    a[R + y].push_back({x, z});
    e[i] = {x, y, z};
  }
  for (int i = 0; i < R + C; ++i) {
    if (visit[i]) continue;
    int64 minv[2] = {INF64, INF64};
    DFS(i < R ? 0 : 1, 0, i, minv);
    if (minv[0] + minv[1] < 0) {
      puts("No");
      return 0;
    }
  }
  for (int i = 0; i < n; ++i) {
    int x = e[i].x, y = e[i].y, z = e[i].v;
    if (v[x] + v[R + y] != z) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 16256