akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0))
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0))
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a))
#define Reverse(a) reverse(All(a))
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define Lower(a,t) lower_bound(All(a),t)
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int gcd(int u, int v) {
  int r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}

signed main(){
    int a,b,c;
    cin >> a >> b >> c;
    int n = gcd(a,b);
    if(c%n==0){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    

    return 0;
}



void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define int long long int
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define err(A) cout << #A << " = " << (A) << endl
using namespace std;

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

ll h[N];

ll dp[N];

int32_t main(){
    ll n;
    cin >> n;
    for (int i=0;i<n;i++){
        cin >> h[i];
    }
    dp[n-1]=abs(h[n-1]-h[n-2]);
    for (int i=n-2;i>0;i--){
        dp[i]=min(dp[i+1]+abs(h[i-1]-h[i]),dp[i+2]+abs(h[i-1]-h[i+1]));

    }
    cout << dp[1];
}


Measured memory_bytes: 1792
from collections import deque
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))

A = deque(sorted(a,reverse=True))
B = deque([])

for _ in range(m):
    #if _ % (m//10) == 0: print(A, B)
    if A:
        if B:
            if (A[0] > B[0]):
                B.append(A.popleft()//2)
                continue
        else:
            B.append(A.popleft()//2)
            continue
    b = B.popleft()
    B.append(b//2)

print(sum(A)+sum(B))


Measured memory_bytes: 93120
#include <cmath>
#include <iostream>

using namespace std;

#define EPS 1e-10
#define equals(a, b) (fabs((a) - (b)) < EPS)

class Point {
public:
  double x, y;
  Point() {};
  Point(double x, double y): x(x), y(y) {}

  Point operator + (const Point &p) { return Point(x + p.x, y + p.y); }
  Point operator - (const Point &p) { return Point(x - p.x, y - p.y); }
  Point operator * (double d) { return Point(d * x, d * y); }
  Point operator / (double d) { return Point(d / x, d / y); }

  bool operator < (const Point &p) const {
    return (x == p.x ? y < p.y : x < p.x);
  }

  bool operator == (const Point &p) const {
    return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
  }

  friend ostream& operator << (ostream &os, Point &p) {
    return os << "Point(" << p.x << ", " << p.y << ")";
  }
};

typedef Point Vector;

struct Segment {
  Point p1, p2;  
};

double cross (Point p1, Point p2) {
  return p1.x * p2.y - p1.y * p2.x;
}

double dot(Vector v1, Vector v2) {
  return v1.x * v2.x + v1.y * v2.y;
}

bool isOrthogonal(Segment s1, Segment s2) {
  return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}

bool isParallel(Segment s1, Segment s2) {
  return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}

int main() {
  int n; cin >> n;
  while (n--) {
    Segment s1, s2;
    int x, y;

    cin >> x >> y;
    s1.p1 = Point(x, y);
    cin >> x >> y;
    s1.p2 = Point(x, y);

    cin >> x >> y;
    s2.p1 = Point(x, y);
    cin >> x >> y;
    s2.p2 = Point(x, y);

    if (isParallel(s1, s2)) cout << 2;
    else if (isOrthogonal(s1, s2)) cout << 1;
    else cout << 0;
    cout << endl;
  }
}

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

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define PI (acos(-1))

int n,k,Sum[100010]={};//s[i] = i番目までみたときの直立グループの数
string s;
int isOK(int x){//連続x人並ばせられるかどうか

  //n-x通りのsubstrを調べ、直立グループの数がk以下なものがあればok
  rep(i,n-x+1){
    int gro;
    if(i==0){
      gro = Sum[x-1];
    }else{
      if(s[i-1] == '0' && s[i] == '0'){
        gro = Sum[i+x-1]-Sum[i-1]+1;
      }else{
        gro = Sum[i+x-1]-Sum[i-1];
      }
    }

    if(gro <= k)return true;
  }
  return false;
}

int main(){
  cin >> n >> k >> s;

  if(s[0] == '0')Sum[0] = 1;

  reps(i,1,n){
    if(s[i-1] == '1' && s[i] == '0')Sum[i] = Sum[i-1]+1;
    else Sum[i] = Sum[i-1];
  }

  /*rep(i,n){
    cout << Sum[i] <<" ";
  }
  cout << endl;*/

  ll ok = 0, ng = INF;
  while(abs(ok-ng)>1){
    ll mid = (ok+ng)/2;
    if(isOK(mid)){
      ok = mid;
    }else{
      ng = mid;
    }
  }

  cout << ok << endl;
}

Measured memory_bytes: 896
use std::io::*;
use std::str::FromStr;

type NodeId = usize;

struct Node {
    parent: Option<NodeId>,
    left_child: Option<NodeId>,
    right_brother: Option<NodeId>,
    depth: u32,
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn rec(node_id: NodeId, depth: u32, nodes: &mut Vec<Node>) {
    nodes[node_id].depth = depth;
    if nodes[node_id].right_brother != None {
        rec(nodes[node_id].right_brother.unwrap(), depth, nodes)
    }
    if nodes[node_id].left_child != None {
        rec(nodes[node_id].left_child.unwrap(), depth + 1, nodes)
    }
}

fn main() {
    let n: usize = read();
    let mut nodes: Vec<Node> = (0..n)
        .map(|_| Node {
            parent: None,
            left_child: None,
            right_brother: None,
            depth: 0,
        })
        .collect();

    let mut root_node_id: NodeId = 0;

    for _ in 0..n {
        let node_id: NodeId = read();
        let k: usize = read();
        let mut left_brother_id: Option<NodeId> = None;
        for index in 0..k {
            let child_node_id: NodeId = read();
            if index == 0 {
                nodes[node_id].left_child = Some(child_node_id);
            } else {
                nodes[left_brother_id.unwrap()].right_brother = Some(child_node_id);
            }
            left_brother_id = Some(child_node_id);
            nodes[child_node_id].parent = Some(node_id);
        }
    }

    for index in 0..n {
        if nodes[index].parent == None {
            root_node_id = index;
        }
    }

    rec(root_node_id, 0, &mut nodes);

    for (index, node) in nodes.iter().enumerate() {
        print!("node {}: ", index);
        if node.parent == None {
            print!("parent = -1, ");
        } else {
            print!("parent = {}, ", node.parent.unwrap());
        }
        print!("depth = {}, ", node.depth);

        if node.parent == None {
            print!("root, ");
        } else if node.left_child == None {
            print!("leaf, ");
        } else {
            print!("internal node, ");
        }

        print!("[");
        if node.left_child != None {
            let mut count = 0;
            let mut right_brother_id: Option<NodeId> = node.left_child;
            while right_brother_id != None {
                let right_brother: &Node = &nodes[right_brother_id.unwrap()];
                if count != 0 {
                    print!(", ")
                }
                print!("{}", right_brother_id.unwrap());
                count += 1;
                right_brother_id = right_brother.right_brother
            }
        }
        println!("]");
    }
}



Measured memory_bytes: 15856
import numpy as np
def main():
    n = int(input())
    s = list(input())
    for i in range(n):
        s[i] = ord(s[i]) - ord("a")
    s = np.array(s)
    dp = np.zeros((n+1, n+1), dtype=np.int64)
    tmp = np.arange(0, n+1)
    t = np.zeros((n+1, n+1))
    for i in range(n+1):
        t[i] += tmp
        tmp -= 1
#    for i in range(n+1):
#        print(t[i])
    for i in range(n):
        c = s[i]
        equal = (c == s)
#        print(equal)
        dp[i+1][1:] += equal
        dp[i+1][1:] += equal * dp[i][:-1]
#    for i in range(n+1):
#        print(dp[i])
    dp = np.minimum(dp, t)
#    for i in range(n+1):
#        print(dp[i])
    ans = 0
    for i in range(1, n):
        tmp = dp[i][i+1:]
        tmp = tmp[ans<tmp]
        if 0 < len(tmp):
            ans = max(ans, max(tmp))
    print(int(ans))

if __name__ == "__main__":
    main()


Measured memory_bytes: 598688
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
//cout<<setprecision(20)
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int LBI(vector<llint>&ar,llint in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
int UBI(vector<llint>&ar,llint in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int i,n;cin>>n;
	vector<llint>a(n+1);
	for(i=1;i<=n;i++){
		llint aa;cin>>aa;
		a[i]=a[i-1]+aa;
	}
	SO(a);
	llint ans=0;
	for(i=0;i<=n;i++){
		ans+=UBI(a,a[i])-LBI(a,a[i]);
	}
	ans-=n+1;
	ans/=2;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1920
//@source: 
//@create: 18:56:59 Saturday 15/08/2020
//@author: nghethuat102
#include <bits/stdc++.h>
using namespace std;

#define len(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define discrete(x) sort(all(x)), x.erase(unique(all(x)), x.end())

void solve() {
    string s;
    cin >> s;
    if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R') {
        cout << "3\n";
        return;
    }
    if (s[0] == 'R' && s[1] == 'R') {
        cout << "2\n";
        return;
    }
    if (s[1] == 'R' && s[2] == 'R') {
        cout << "2\n";
        return;
    }
    if (s[0] == 'R' || s[1] == 'R' || s[2] == 'R') {
        cout << "1\n";
        return;
    }
    cout << "0\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    for (int it = 1; it <= t; ++it) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

ll calc(vector<int>& v){
    sort(v.begin(),v.end());
    ll ret=0;
    for(auto e : v){
        ret=10*ret+e;
    }
    return ret;
}
vector<int> ltov(ll x,int n){
    vector<int> ret(n);
    rep(i,n){
        ret[n-i-1]=x%10;
        x/=10;
    }
    return ret;
}

void solve(int n){
    string s,t;
    cin>>s>>t;
    vector<int> a(n+1);
    rep(i,n){
        a[i]=t[i]-s[i];
        if(a[i]<0)a[i]+=10;
    }
    rep(i,n){
        a[n-i]-=a[n-i-1];
        if(a[n-i]<0)a[n-i]+=10;
    }
    sort(a.begin(),a.end());
    ll g=calc(a);
    if(g==0){
        cout<<0<<endl;
        return;
    }
    map<ll,int> dist;
    queue<ll> q;
    q.push(0);
    dist[0]=0;
    while(q.size()){
        ll p=q.front();q.pop();
        auto vv=ltov(p,n+1);
        int d=dist[p];
        rep(i,n+1)rep(j,n+1)REP(k,1,10){
            if(i==j)continue;
            auto v=vv;
            v[i]+=k;if(v[i]>=10)v[i]-=10;
            v[j]-=k;if(v[j]<0)v[j]+=10;
            auto nxt=calc(v);
            if(!dist.count(nxt)){
                dist[nxt]=d+1;
                if(nxt==g){
                    cout<<d+1<<endl;
                    return;
                }
                q.push(nxt);
            }
        }
    }
    cout<<dist[g]<<endl;
}

int main(){
    int n;
    while(cin>>n,n!=0)solve(n);    
    return 0;
}


Measured memory_bytes: 4200
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<utility>
#define mod 1000000007
#define pb push_back
using namespace std;
long long ggcd(long long x,long long y){
	if(x==0 | y==0)return 0;
	while(x>0 && y>0){
		if(x>y) x=x%y;
		else y=y%x;
	}
	return x+y;
}
int main(){
	long long a,b,c,d,t;
	long long aa[1100],bb[1100],cc[1100],dd[1100];
	cin>>t;
	for(int i=0;i<t;i++){
		cin>>aa[i]>>bb[i]>>cc[i]>>dd[i];
	}
	for(int i=0;i<t;i++){
		a=aa[i];b=bb[i];c=cc[i];d=dd[i];
		if(a<b){cout<<"No"<<endl; goto end;}
		
		if(b>d){
			cout<<"No"<<endl;
			goto end;
		}
		else{
			if(a%b>c){
				cout<<"No"<<endl;
				goto end;
			}
			else{
				if(c+1>=b){
					cout<<"Yes"<<endl;
				}
				else{
					long long le = c+1-a%b;
					long long ri = b-1-a%b;
					long long st = ggcd(b, d%b);
					if(st==0){cout<<"Yes"<<endl;}
					else if( (ri/st)*st>=le ){cout<<"No"<<endl;}
					else{cout<<"Yes"<<endl;}
				}
				goto end;
			}
		}
		end:a=a+0;
	}		
	return 0;
}

Measured memory_bytes: 256
H,W=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))

grid=[]
for i,ai in enumerate(a):
    grid.extend([i+1]*ai)

ans=[]
for i in range(H):
    l=W*i
    r=l+W
    tmp=grid[l:r]
    if i%2==0:
        ans.append(tmp)
    else:
        ans.append(tmp[::-1])

for i in ans:
    print(*i, sep=" ")

Measured memory_bytes: 3956
#include <cstdio>

typedef long long LL;
const int MN = 100005, MQ = 100005;

int N, Q; LL M;
int pa[MN]; int fp(int x) { return pa[x] ? pa[x] = fp(pa[x]) : x; }
int qu[MQ], qv[MQ], K;
int E;

int main() {
	scanf("%d%lld%d", &N, &M, &Q);
	for (int i = 1; i <= Q; ++i) {
		int x, y, z;
		scanf("%d%d%d", &x, &y, &z);
		++x, ++y;
		if (z == 0) { if ((x = fp(x)) != (y = fp(y))) pa[y] = x, ++E; }
		else qu[++K] = x, qv[K] = y;
	}
	if (K && M == N - 1) return puts("No"), 0;
	for (int i = 1; i <= K; ++i)
		if ((qu[i] = fp(qu[i])) == (qv[i] = fp(qv[i])))
			return puts("No"), 0;
	int C = N - E;
	if (C == 2) return puts("No"), 0;
	if (M > E + (LL)C * (C - 1) / 2) return puts("No"), 0;
	return puts("Yes"), 0;
	return 0;
}

Measured memory_bytes: 896
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
n,x=mii()
a,p=[1],[1]
for i in range(n):
    a.append(a[i]*2 +3)
    p.append(p[i]*2 +1)

def dfs(n,x):
    if n==0:
        return 0 if x<=0 else 1
    elif x<= 1 + a[n-1]:
        return dfs(n-1,x-1)
    elif x==a[n-1]+2:
        return p[n-1]+1
    else:
        return p[n-1]+1+dfs(n-1,x-2-a[n-1])
print(dfs(n,x))

Measured memory_bytes: 63724
def a_atcoder_contest_scheduling(CONTEST=26):
    D = int(input())
    Satisfaction_decreasing = [int(i) for i in input().split()]
    Satisfaction_difference = [[int(i) for i in input().split()] for j in range(D)]

    # とりあえず満足度の減少があまり大きくならないようにする
    ans = [(i % CONTEST) + 1 for i in range(D)]
    return '\n'.join(map(str, ans))

print(a_atcoder_contest_scheduling())

Measured memory_bytes: 9392
#include <bits/stdc++.h>
using namespace std;int main() {
  long int N, cnt, cnt2;
  cin >> N;
  if(N % 2 == 1){
    cout << 0 << endl;
  }
  else{
    cnt = N /= 10;
    cnt2 = N;
    while(cnt != 0){
      cnt /= 5;
      cnt2 += cnt;
    }
    cout << cnt2 << endl;
  }
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
S = list(input().rstrip())
N = len(S)
cnt = 0
for i in S:
    cnt += i.isupper()
if cnt != 2:
    print("WA")
    sys.exit()
if S[0] != "A":
    print("WA")
    sys.exit()
if "C" not in S[2:N-1]:
    print("WA")
    sys.exit()
print("AC") 


Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll N , M , X; cin >> N >> M >> X;
  vector<ll> c(N);
  vector<vector<ll> > a(N, vector<ll> (M, 0));

  rep(i,N){
    cin >> c[i];
    rep(j,M) cin >> a[i][j];
  }


  ll ans = INF;
  rep(i , (1 << N)){
    vector<ll> score(M);
    ll tmp = 0;
    rep(j, N){
      // j buy
      if( (i >> j) % 2 == 1 ){
        tmp += c[j];
        rep(k, M){
          score[k] += a[j][k];
        }
      }
    }
    bool check = true;
    rep(l,M){
      if(score[l] < X) check = false;
    }

    if(check){
      ans = min(ans , tmp);
    }
  }

  if(ans == INF) cout << -1 << endl;
  else cout << ans << endl;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
typedef long double ld;
typedef long long ll;
 
using namespace std;
 
#define MAXN (1 << 12)
 
int n, t;
vector<pair<int, int> > v;
int mem[MAXN][MAXN];
 
int solve(int k, int pos) {
	if ((k >= t) || (pos >= n)) {
		return 0;
	}
	int & ret = mem[k][pos];
	if (ret >= 0) {
		return ret;
	}
	int cur1 = v[pos].second + solve(k + v[pos].first, pos + 1);
	int cur2 = solve(k, pos + 1);
	ret = max(cur1, cur2);
	return ret;
}
 
int main() {
	memset(mem, -1, sizeof(mem));
	cin >> n >> t;
	for (int i = 0; i < n; i++) {
		int t1, t2;
		cin >> t1 >> t2;
		v.push_back(make_pair(t1, t2));
	}
	sort(v.begin(), v.end());
	cout << solve(0, 0) << endl;
	return 0;
}

Measured memory_bytes: 69348
#include<iostream>
using namespace std;   
int a,b,c,x,n;
    int main()
    {
        while(scanf("%d",&n)!=EOF)
        {
            a=b=c=0;
            for(int i=0;i<n;i++)
            {
                scanf("%d",&x);
                if(!(x%4)) a++;
                else if(x&1) b++;
                else c++;
            }
            if(!c) b--;
            puts(a>=b?"Yes":"No");
        }
        return 0;
    }

Measured memory_bytes: 256
from collections import deque
import sys
input = sys.stdin.readline

N = int(input())
A = []
for _ in range(N):
    # 選手番号を0-indexにする
    line = list(map(lambda x: int(x) - 1, input().split()))
    A.append(line)

# cnt[i] = 選手iが現在までに何試合したか
cnt = [0] * N
# recent[i] = 選手iが最後に試合をした日
recent = [0] * N

# Qの初期値 = [0, 1, ..., N-1]
Q = deque(range(N))

while Q:
    # ある選手(p1)について
    p1 = Q.popleft()
    # p1がまだ全試合(N-1試合)を終えていない場合
    # p2 = p1が次に当たるべき選手
    if cnt[p1] < N - 1:
        p2 = A[p1][cnt[p1]]
        # p2もまだ全試合を終えていない場合
        if cnt[p2] < N - 1:
            # p2が次に当たるべき選手がp1の場合 -> (p1,p2)の試合を行うことが可能
            if A[p2][cnt[p2]] == p1:
                # day = (p1,p2)の試合を行う日
                day = max(recent[p1], recent[p2]) + 1
                recent[p1] = day
                recent[p2] = day
                cnt[p1] += 1
                cnt[p2] += 1
                Q.append(p1)
                Q.append(p2)

if min(cnt) != N - 1:
    print(-1)
else:
    print(max(recent))


Measured memory_bytes: 41384
/*
    @uthor: Amit Kumar
    user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus;
*/
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//#define ln mp::cpp_int;
#define ll    long long
#define ld    long double
#define ull   unsigned long long
#define endl "\n"
ll google_itr = 1;
#define google(x) cout<<"Case #"<<x<<":"
#define pi 3.14159265358979323846264338327950L

const ll mod = 1e9+7;
const ll inf = 1e18;

ll popcount(ll num){
    num = num - ((num >> 1) & 0x55555555);
    num = (num & 0x33333333) + ((num >> 2) & 0x33333333);
    return ((num + (num >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}

vector<pair<ll,ll>> factor_arr;

void myfactor(ll num){ 
    ll count = 0;   
    while (!(num % 2)) { 
        num >>= 1; count++; 
    }  
    if (count) factor_arr.push_back({2,count}); 
    for (auto i = 3; i <= sqrt(num); i += 2) { 
        count = 0; 
        while (num % i == 0) { 
            count++; 
            num /= i; 
        } 
        if (count) factor_arr.push_back({i,count}); 
    } 
    if (num > 2) factor_arr.push_back({num,1});
}
queue<ll> lul;
vector<ll> ans;

void prepro(){
    ll times = 100001;
    for(auto i=1; i<=9; i++) lul.push(i), ans.push_back(i);
    while(times--){
        ll fr = lul.front();
        lul.pop();
        if(fr%10 != 0) ans.push_back((10*fr) + (fr%10) - 1), lul.push((10*fr) + (fr%10) - 1);
        ans.push_back((10*fr) + (fr%10)),lul.push((10*fr) + (fr%10));
        if(fr%10 != 9) ans.push_back((10*fr) + (fr%10) + 1), lul.push((10*fr) + (fr%10) + 1);  
    }
}
void virus(){
        ll pos;
        cin>>pos;
        cout<<ans[pos-1];
}


int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
  /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/

    ll t=1;
    //cin>>t;
    while(t--){
           auto start = high_resolution_clock::now();
           prepro();
           virus();
           auto stop = high_resolution_clock::now();
           auto duration = duration_cast<seconds>(stop - start);
         //cout << "Time: "<<duration.count()<<endl;
        //your code goes here
    }
    return 0;
}

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

int main(){

  long long N, M;
  cin >> N >> M;

  if(2*N > M){
    cout << M/2 << endl;
  }else{
    cout << N + (M - 2*N)/4 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner io = new Scanner(System.in);
		int x = io.nextInt();
		int y = io.nextInt();
		switch(x){
		
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			x = -1;
			break;
		case 4:
		case 6:
		case 9:
		case 11:
			x = -2;
			break;
		case 2:
			x = -3;
			break;
		}
		
		switch(y){
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			y = -1;
			break;
		case 4:
		case 6:
		case 9:
		case 11:
			y = -2;
			break;
		case 2:
			y = -3;
			break;
		}
		
		System.out.println((x==y)?"Yes":"No");
	}
}


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

import static java.lang.Integer.*;
import static java.lang.Long.parseLong;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter prnt = new PrintWriter(System.out);
        StringTokenizer st;
        int N = parseInt(read.readLine());
        long[] arr = new long[N];
        st = new StringTokenizer(read.readLine());
        for (int i = 0; i < N; i++) {
            arr[i] = parseLong(st.nextToken());
        }
        prnt.println(getSum(arr, N));
        prnt.close();
    }

    static long getSum(long[] arr, int N) {
        long mod = (long) (1e9 + 7);
        long Sum = 0;
        long[] preixSum = new long[N];
        preixSum[0] = arr[0];
        for (int i = 1; i < N; i++) {
            preixSum[i] += (preixSum[i - 1] + arr[i]);
        }
        for (int i = 0; i < (N - 1); i++) {
            Sum += ((arr[i] % mod) * ((preixSum[N - 1] - preixSum[i]) % mod)) % mod;
            Sum %= mod;
        }
        return Sum;
    }
}

Measured memory_bytes: 56020
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());
#define pb push_back

ll k,r,l;
ld p,e,t;

ld segtree(ld _l, ld _r,ll _c) {
	if(_l>=t-e-EPS&&_r<=t+e+EPS) {
		return 1;
	}
	if(_l>t+e-EPS||_r<t-e+EPS) {
		return 0;
	}
	ld _m=(_l+_r)/2;
	if(_c==k) {
		if(abs(_m-t)<e+EPS) return 1;
		else return 0;
	}
	if(_m>=t-EPS) {
		return (1-p)*segtree(_l,_m,_c+1)+p*segtree(_m,_r,_c+1);
	} else {
		return p*segtree(_l,_m,_c+1)+(1-p)*segtree(_m,_r,_c+1);
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin>>k>>r>>l>>p>>e>>t;
	cout<<fixed<<setprecision(100)<<segtree(r,l,0)<<endl;
}




Measured memory_bytes: 3284
#include <iostream>
using namespace std;
int n,cnt,ans;
int main(void){
    cin>>n;
    for(int i=105;i<=n;i++){
        cnt=0;
        for(int j=1;j<=i;j++){
            if(i%j==0)cnt++;
        }
        if(cnt==8&&i%2==1)ans++;
    }
    cout<<ans<<endl;
}


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

class dice{
	public:
	int d[6];

	void rolls(string str){
		for(int i = 0; str[i] != '\0'; i++)
			roll(str[i]);
	}
	void roll(char in){//4 2 1 6 5 3
		int direc[4][6]={
			{1,5,2,3,0,4},//n
			{3,1,0,5,4,2},//e
			{4,0,2,3,5,1},//s
			{2,1,5,0,4,3}//w
		};
		int news;
		int temp_d[6];
		if(in =='N')news = 0;
		if(in =='E')news = 1;
		if(in =='S')news = 2;
		if(in =='W')news = 3;
		for(int i = 0;i < 6;i++)
			temp_d[i] = d[direc[news][i]];
		for(int i = 0;i < 6;i++)
			d[i] = temp_d[i];
	}
	void print(void){
		for(int i = 0;i < 6; i++){
			cout << d[i];
			if(i==6-1)cout << endl;
			else cout << " ";
		}
	}
};

int checkdice(dice d1, dice d2){
	int i;
	for(i = 0;i < 6;i++)
		if(d1.d[i] != d2.d[i])
			break;
	if(i==6)return 1;
	return 0;
}

int main(){
	dice d1,d2;
	int r = 0;

	for(int i = 0;i < 6; i++)
		cin >> d1.d[i];
	for(int i = 0;i < 6; i++)
		cin >> d2.d[i];

	for(int i = 0;i < 4;i++){
		r+=checkdice(d1,d2);
		d2.rolls("SEN");
	}

	d2.roll('N');
	for(int i = 0;i < 4;i++){
		r+=checkdice(d1,d2);
		d2.rolls("SEN");
	}
	d2.roll('S');

	d2.roll('W');
	for(int i = 0;i < 4;i++){
		r+=checkdice(d1,d2);
		d2.rolls("SEN");
	}
	d2.roll('E');

	d2.roll('E');
	for(int i = 0;i < 4;i++){
		r+=checkdice(d1,d2);
		d2.rolls("SEN");
	}
	d2.roll('W');

	d2.roll('S');
	for(int i = 0;i < 4;i++){
		r+=checkdice(d1,d2);
		d2.rolls("SEN");
	}
	d2.roll('N');

	d2.rolls("SS");
	for(int i = 0;i < 4;i++){
		r+=checkdice(d1,d2);
		d2.rolls("SEN");
	}
	
	if(r>0)cout << "Yes" << endl;
	else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 1204
#include <cstdio>
#include <stack>
#include <algorithm>
using namespace std;
 
int n;
 
int main(void){
    stack<int> s;
    char c;
    while(scanf("%c",&c)!=EOF){
        if(c=='+'){
            int a=s.top();
            s.pop();
            int b=s.top();
            s.pop();
            s.push(a+b);
        }
        if(c=='-'){
            int a=s.top();
            s.pop();
            int b=s.top();
            s.pop();
            s.push(b-a);
        }
        if(c=='*'){
            int a=s.top();
            s.pop();
            int b=s.top();
            s.pop();
            s.push(a*b);
        }
        if(c>='0' && c<='9'){
            int d=c-'0';
            while(1){
                scanf("%c",&c);
                if(c>='0' && c<='9')d=d*10+(c-'0');
                else break;
            }
            s.push(d);
        }else scanf("%*c");
    }
    printf("%d\n",s.top());
    return 0;
}


Measured memory_bytes: 2756
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <tuple>
#include <bitset>
#include <random>
#define REP(i,n) for(int i=0;i<n;i++)
#define INF 1000000007
using namespace std;
using pii=pair<int,int>;
using LL=int64_t;


vector<int> Dijkstra(vector<vector<pii>> adj_list,int start){/*adj_listはs番目に「「tとsからtへの距離dのpair」を並べたベクトル」が入っているベクトル */
  int n=adj_list.size();
  /*初期化*/
  vector<int> distance(n,INF);
  vector<int> pre(n);/*最短経路におけるひとつ前の頂点*/
  distance.at(start)=0;
  priority_queue<pii,vector<pii>,greater<pii>> unsettled;/*未確定の頂点*/
  REP(u,n){
    unsettled.push(make_pair(distance.at(u),u));
  }

  /*本計算*/
  while(!unsettled.empty()){
    int u;
    tie(ignore,u)=unsettled.top();
    unsettled.pop();/*uを確定*/
    /*uから伸びている辺の先へ書き込み*/

    for(auto vpair : adj_list.at(u)){
      int weight_u_to_v,v;
      tie(v,weight_u_to_v)=vpair;
      int alt=distance.at(u)+weight_u_to_v;
      /*更新*/
      if(distance.at(v)>alt){
        distance.at(v)=alt;
        pre.at(v)=u;
        unsettled.push(make_pair(alt,v));

      }
    }

  }
  return pre;

}



int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<pii>> adj_list(n);
    REP(i,m){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        adj_list.at(a).push_back(make_pair(b,1));
        adj_list.at(b).push_back(make_pair(a,1));

    }

    vector<int> pre=Dijkstra(adj_list,0);
    cout<<"Yes"<<endl;
    for(int i=1;i<n;i++){
        cout<<pre.at(i)+1<<endl;
    }


    return 0;
}

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

C0 = 0
C1 = 0
C2 = 0
C3 = 0

for i in range(0,N):
  S = str(input())
  if S == 'AC':
    C0 += 1
  elif S == 'WA':
    C1 += 1
  elif S == 'TLE':
    C2 += 1
  elif S == 'RE':
    C3 += 1
    
print('AC x',C0)
print('WA x',C1)
print('TLE x',C2)
print('RE x',C3)


  

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

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

    float d,t,s;
    cin>>d>>t>>s;
    if(d/t > s)
    {
        cout<<"No\n";
    }
    else
    {
        cout<<"Yes\n";
    }
    


    return 0;
}



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

// iterator
#define REP(i,from, to) for(lli i=from;i<to;i++)
#define REPE(i,from, to) for(lli i=from;i<=to;i++)
#define REP_R(i,from, to) for(lli i=from;i>to;i--)
#define REPE_R(i,from, to) for(lli i=from;i>=to;i--)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;



lli n;
double E[301][301][301];

double rec(lli n_1, lli n_2, lli n_3) {
    if (n_1 == 0 && n_2 == 0 && n_3 == 0)
        return 0;
    if (E[n_1][n_2][n_3] != 0)
        return E[n_1][n_2][n_3];
    double e1, e2, e3;
    e1 = e2 = e3 = 0;
    if (n_1 > 0)
        e1 = rec(n_1-1, n_2, n_3) * n_1/(n_1+n_2+n_3);
    if (n_2 > 0)
        e2 = rec(n_1+1, n_2-1, n_3) * n_2/(n_1+n_2+n_3);
    if (n_3 > 0)
        e3 = rec(n_1, n_2+1, n_3-1) * n_3/(n_1+n_2+n_3);

    E[n_1][n_2][n_3] = e1+e2+e3+(n/(double)(n_1+n_2+n_3));
    //cout3(n_1,n_2,n_3);
    //cout1(E[n_1][n_2][n_3]);
    return E[n_1][n_2][n_3];
}

int main() {
    cin1(n);
    lli n_1, n_2, n_3;
    n_1 = n_2 = n_3 = 0;
    REP(i,0,n) {
        lli a;
        cin >> a;
        if (a == 1)
            n_1++;
        else if (a==2)
            n_2++;
        else
            n_3++;
    }

    cout <<std::setprecision(10)<< rec(n_1, n_2, n_3) << endl;
}


Measured memory_bytes: 213248
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctype.h>
using namespace std;
#define dump(a) cout << (a) << '\n';
typedef long long Int;
Int mod = 1e9+7;
Int MOD = 998244353;

int main() {
    ios::sync_with_stdio(false);
     Int n, m;
    cin >> n >> m;
  
    bool x = false;
    vector<Int> a(n), b(m);
    for (Int i = 0; i < n; i++) cin >> a[i];
    for (Int i = 0; i < m; i++) cin >> b[i];
    sort(a.begin(), a.end(), greater<Int>());
    sort(b.begin(), b.end(), greater<Int>());
    /* for (Int i = 0; i < n; i++) {
        if (a[i] < n * m - i) x = true;
    }
    for (Int i = 0; i < m; i++) {
        if (b[i] < n * m - i) x = true;
    } */
    for (Int i = 0; i < n-1; i++) {
        if (a[i] == a[i+1]) x = true;
    }
    for (Int i = 0; i < m-1; i++) {
        if (b[i] == b[i+1]) x = true;
    }
    if (x) {
        dump(0);
        return 0;
    } 
    vector<bool> used(n * m + 1, false);
    map<Int, Int> mp;
    for (Int i = 0; i < n; i++) mp[a[i]]++;
    for (Int j = 0; j < m; j++) mp[b[j]]++;
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        if (itr->second == 2) used[itr->first] = true;
    }
    Int i, j;
    i = j = 0;
    Int res = 1;
    for (Int k = n * m; k > 0; k--) {
        if (used[k]) continue;
        while (i < n-1 && a[i+1] >= k) i++;
        while (j < m-1 && b[j+1] >= k) j++;
        if (a[i] < k || b[j] < k) {
            dump(0);
            return 0;
        }
        Int tmp = (i + 1) * (j + 1) - (n * m - k);
        if (a[i] == k) tmp = (j + 1);
        else if (b[j] == k) tmp = (i + 1);
        //cout << k << " " << tmp << '\n';
        res *= tmp;
        res %= mod;
    }
    dump(res);
    return 0;  
}

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

string s;
int main(){
    cin>>s;
    if (s.size()&1){
        cout<<"No";
        return 0;
    }
    int cnt=0;
    for (auto c:s){
        if (c!=(cnt?'i':'h')){
            cout<<"No";
            return 0;
        }
        cnt^=1;
    }
    cout<<"Yes";
    return 0;
}

Measured memory_bytes: 256
a,b,c,d = [x for x in input()]
op = ["+","-"]
for op1 in op:
    for op2 in op:
        for op3 in op:
            if eval(a + op1 + b + op2 + c + op3 + d) == 7:
                print(a + op1 + b + op2 + c + op3 + d + "=7")
                exit()

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main{
    public static void main(String[] args) throws IOException{
        int n,in,min,max,i;
 
        long sum = 0;
  
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  
        n = Integer.parseInt(br.readLine());
 
        min = Integer.MAX_VALUE;
        max = Integer.MIN_VALUE;
  
        String[] readLineArray = br.readLine().split(" ");
  
        for (i = 0; i < n; i++){
            in = Integer.parseInt(readLineArray[i]);
            if(in < min) min = in;
            if(in > max) max = in;
            sum += in;
        }
 
        System.out.println(min+" "+max+" "+sum);
    }
}

Measured memory_bytes: 25504
#include <iostream>

using namespace std;

int main(){
    int a;
    int b;
    cin >> a;
    cin >> b;
    if(a == 1 && b == 2){
        cout << 3 << endl;
    }
    else if(a == 1 && b == 3){
        cout << 2 << endl;
    }
    else if(a == 2 && b == 1){
        cout << 3 << endl;
    }
    else if(a == 2 && b == 3){
        cout << 1 << endl;
    }
    else if(a == 3 && b == 1){
        cout << 2 << endl;
    }
    else if(a == 3 && b == 2){
        cout << 1 << endl;
    }
}

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

int main(){
  int n,k;cin>>n>>k;
  int a[n];
  for(int i=0;i<n;++i) {
    cin>>a[i];
  }
  sort(a, a+n);
  int ans=0;
  for(int j=0;j<k;++j) {
    ans+=a[j];
  }
  cout<<ans;
}

Measured memory_bytes: 3640
def main():
    import sys
    input = sys.stdin.readline
    
    from collections import defaultdict
    import itertools
    import copy
    
    N,M = map(int,input().split())
    dp = [[float("inf")]*(2**N) for i in range(M+1)]
    dp[0][0] = 0
    
    for i in range(1,M+1):
        #print(dp[M][(True,)*N])
        a,b = map(int,input().split())
        c = list(map(int,input().split()))
        tmp = 0
        for k in c:
            tmp += 2**(k-1)
        for j in range(2**N):
            now = j | tmp
            dp[i][j] = min(dp[i][j],dp[i-1][j])
            dp[i][now] = min(dp[i][now],dp[i-1][now], dp[i-1][j]+a)
            #print(dp[i][now],dp[i-1][now], dp[i-1][j]+a)
    
    if dp[M][2**N-1] == float("inf"):
        print(-1)
    else:
        print(dp[M][2**N-1])
            
    
    
main()

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

int main()
{
    int n, k;
    int i, j, ans = 0;
    
    cin >> n >> k;
    
    int a[n];
    
    for(i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    sort(a, a+n);
    
    for(j = 1; j <= k; j++) {
        ans = ans + a[n-j];
    }
    
    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 256
lines=readlines(open("/dev/fd/0"))
input()=shift!(lines)
int(s::String)=parse(Int,s)
int(s::SubString{String})=parse(Int,s)
int(s::Array{SubString{String},1})=map(int,s)
function main()
    INF=2^60
    a,b,q=input()|>split|>int
    s=[-INF]
    append!(s,[int(input())for i in 1:a])
    push!(s,INF)
    t=[-INF]
    append!(t,[int(input())for i in 1:b])
    push!(t,INF)
    for x in[int(input())for i in 1:q]
        m=INF
        i=searchsortedlast(s,x)
        j=searchsortedlast(t,x)
        for v in view(s,i:i+1)
            for w in view(t,j:j+1)
                m=min(m,abs(x-v)+abs(v-w),abs(x-w)+abs(w-v))
            end
        end
        println(m)
    end
end
main()

Measured memory_bytes: 173352
import sys
input = sys.stdin.readline
from collections import Counter

N = int(input())
A = []
for _ in range(N):
    a = sorted(list(input()))
    A.append(''.join(a))

B = Counter(A)

ans = 0
for k,v in B.items():
    ans += v*(v-1)//2
print(ans)

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

int main() {
    long long D, N;
    cin >> D >> N;
    int ans = pow(100, D) * N;

    if (N == 100 && D == 0) {
        ans++;
    } else if (N == 100 && D > 0) {
        ans += pow(100, D);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	char s[11];
	int f=0;

	scanf("%s",s);

	if(s[0]!='A'){
		printf("WA\n");
		return 0;
	}
	for(int i=1;i<strlen(s);i++){
		if(i>=2&&i<=strlen(s)-2&&s[i]=='C')
			f++;
		else if(s[i]<'a'||s[i]>'z'){
			printf("WA\n");
			return 0;
		}
	}
	if(f==1)
		printf("AC\n");
	else
		printf("WA\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

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

const int INF = 1e9;

int main() {
    int n;
    cin >> n;
    int h[n], dp[n];
    for (int i = 0; i < n; i++) cin >> h[i];
    for (int i = 0; i < n; i++) dp[i] = INF;
    dp[0] = 0, dp[1] = abs(h[1] - h[0]);
    for (int i = 2; i < n; i++) {
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
    }
    cout << dp[n-1] << endl;
}

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

int main(){
  string S,T;
  cin >> S >> T;
  int ans = 0;
  for(int i=0;i<S.size();i++){
    if(S.at(i)!=T.at(i) ) ans ++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3924
n = int(input())
a = sorted(list(map(int,input().split())))
ans_bigger = max(a)
ans_half = ans_bigger / 2
dif = float("inf")
for i in range(n-1):
  x = abs(a[i]-ans_half)
  if dif > x:
    dif = x
    ans_smaller = a[i]
print(ans_bigger,ans_smaller)


Measured memory_bytes: 62704
#include<iostream>
#include<string>
using namespace std;
#define isnum(x) ((x)>='0'&&(x)<='9')
int main(void)
{
  int a,b,i;cin >> a >> b;
  string s; cin >> s;
  bool ok=true;
  for(i=0;i<a;i++) {
    if(!isnum(s[i])) {
      ok=false;
    }
  }
  if(s[a]!='-') ok=false;
  for(i=a+1;i<a+b+1;i++) {
    if(!isnum(s[i])) {
      ok=false;
    }
  }
  cout << ((ok?"Yes":"No")) << endl;
    
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;



int main(){
    ll x,y;
    cin >> x >> y;
    if(abs(x-y)<=1){
        cout << "Brown" << endl;
    }
    else{
        cout << "Alice" << endl;
    }

    return 0;
}


Measured memory_bytes: 3564
#include <iostream>

int main()
{
    int a, b;
    std::cin >> a;
    std::cin >> b;
    int c;

    if (a < b) {
        c = a;
        a = b;
        b = c;
    }

    while (1) {
        int d = a % b;
        if (d == 0) {
            std::cout << b << std::endl;
            break;
        }
        a = b;
        b = d;
    }
}



Measured memory_bytes: 3100
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <iostream>
#include <list>
#include <functional>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
typedef long long ll;
const ll mll = 9223372036854775807;
const int mint = (2 << 31) - 1;
using namespace std;

int main()
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	vector<int> v;
	v.push_back(a);
	v.push_back(b);
	v.push_back(c);
	sort(v.begin(), v.end());
	printf("%d", v[1] - v[0] + v[2] - v[1]);
}

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

using namespace std;
const int N=105,NN=N<<1,M=N*N;
const LL inf=1ll<<55;
LL rd()
{
    LL x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}
    return x*w;
}
struct node
{
	LL x,y;
	node(LL nx=0,LL ny=0){x=nx,y=ny;}
	bool operator < (const node &bb) const {return x!=bb.x?x<bb.x:y<bb.y;}
	node operator + (const node &bb) const {return (node){x+bb.x,y+bb.y};}
}w[M],di[NN];
int to[M],nt[M],c[M],hd[NN],tot=1,ps,pt,fw[NN],pr[NN],v[NN];
LL s1,s2,ans;
void adde(int x,int y,int z,LL z1,LL z2)
{
	++tot,to[tot]=y,nt[tot]=hd[x],c[tot]=z,w[tot]=(node){+z1,+z2},hd[x]=tot;
	++tot,to[tot]=x,nt[tot]=hd[y],c[tot]=0,w[tot]=(node){-z1,-z2},hd[y]=tot;
	s1-=z*z1;
}
void csfl()
{
	queue<int> q;
	while(1)
	{
		for(int i=1;i<=pt;++i) di[i]=(node){-inf,-inf};
		di[ps]=(node){0,0},fw[ps]=1<<30,v[ps]=1,q.push(ps);
		fw[pt]=0;
		while(!q.empty())
		{
			int x=q.front();
			q.pop();
			for(int i=hd[x];i;i=nt[i])
			{
				int y=to[i];
				if(c[i]>0&&di[y]<di[x]+w[i])
				{
					di[y]=di[x]+w[i];
					pr[y]=i,fw[y]=min(fw[x],c[i]);
					if(!v[y]) v[y]=1,q.push(y);
				}
			}
			v[x]=0;
		}
		if(!fw[pt]) return;
		s1+=di[pt].x*fw[pt],s2+=di[pt].y*fw[pt];
		int x=pt;
		while(x!=ps)
		{
			int i=pr[x];
			c[i]-=fw[pt],c[i^1]+=fw[pt];
			x=to[i^1];
		}
	}
}
int n,m,t=100;
char cc[2];
LL a[N][3],b[N<<2][3],px[N][2],py[N][2];
map<char,int> id;

int main()
{
	id['L']=0,id['R']=1,id['D']=2,id['U']=3;
	n=rd();
	for(int i=1;i<=n;++i)
		for(int j=0;j<=2;++j)
			a[i][j]=rd();
	m=rd();
	for(int i=1;i<=m;++i)
	{
		scanf("%s",cc),b[i][0]=id[cc[0]];
		b[i][1]=rd(),b[i][2]=rd();
	}
	ps=0,pt=203;
	int yyb=201,zsy=202;
	for(int h=1;h<=n;++h)
	{
		memset(hd,0,sizeof(int)*(pt+1)),tot=1,s1=s2=0;
		for(int i=1;i<=t;++i) px[i][0]=0,px[i][1]=1<<30;
		for(int i=1;i<=t;++i) py[i][0]=0,py[i][1]=1<<30;
		for(int i=1;i<=m;++i)
		{
			if(b[i][0]==0) px[b[i][1]][1]=min(px[b[i][1]][1],b[i][2]);
			if(b[i][0]==1) px[b[i][1]-1][0]=max(px[b[i][1]-1][0],h-b[i][2]);
			if(b[i][0]==2) py[b[i][1]][1]=min(py[b[i][1]][1],b[i][2]);
			if(b[i][0]==3) py[b[i][1]-1][0]=max(py[b[i][1]-1][0],h-b[i][2]);
		}
		adde(ps,yyb,h,1,0);
		bool o=1;
		int np=yyb;
		for(int i=t;i;--i)
		{
			if(px[i][0]>px[i][1]){o=0;break;}
			adde(np,i,px[i][0],1,0),adde(np,i,px[i][1]-px[i][0],0,0);
			np=i;
		}
		np=zsy;
		for(int i=t;i;--i)
		{
			if(py[i][0]>py[i][1]){o=0;break;}
			adde(i+t,np,py[i][0],1,0),adde(i+t,np,py[i][1]-py[i][0],0,0);
			np=i+t;
		}
		adde(zsy,pt,h,1,0);
		if(!o) continue;
		for(int i=1;i<=n;++i) adde(a[i][0],a[i][1]+t,1,0,a[i][2]);
		csfl();
		if(s1>=0) ans=max(ans,s2);
	}
	printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long

const int N = 100010;

int a, b, n;
int num[N];

bool check(int mid){
	ll cnt = 0, y = a - b;
	for (int i = 0; i < n; ++ i){
		ll x = num[i] - 1ll * b * mid;
		cnt += x >= 0 ? (x + y - 1) / y : 0;
	}
	return cnt <= mid;
}

int main(){
	scanf("%d%d%d", &n, &a, &b);
	for (int i = 0; i < n; ++ i){
		scanf("%d", &num[i]);
	}
	int left = 0, right = 1e9;
	while (left < right){
		int mid = left + right >> 1;
		if (check(mid)){
			right = mid;
		}
		else{
			left = mid + 1;
		}
	}
	return printf("%d\n", left), 0;
}

Measured memory_bytes: 640