akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int N=3e3+5,mo=998244353;
int n,x,f[N][N*2],C[N][N],i,j,ans=1;
inline void add(int&x,const int&y){x+=y;x>=mo?x-=mo:0;}
int main(){
	scanf("%d%d",&n,&x);
	for(i=**C=1;i<=n;++i)for(j=*C[i]=1;j<=n;++j)C[i][j]=(C[i-1][j-1]+C[i-1][j])%mo;
	for(i=0,f[0][0]=1;i<n;++i)for(j=0;j<=i*2;++j)add(f[i+1][j+2],f[i][j]),add(f[i+1][j+1],f[i][j]);
	for(i=1;i<=n;++i){
		int s=0;
		for(j=0;j<x;++j)add(s,f[i][j]);
			for(j=x+1;j<=i*2;j+=2)if(j>=i){
				int p=i-(j-x+1),q=x-1-(j-x+1);
				if(j>=x*2){if(j==i*2)add(s,x&1);}
					else if(p>=0 && q>=0)add(s,f[p][q]);
			}
		ans=(ans+1ll*C[n][i]*s)%mo;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 105984
#include<stdio.h>

int main(void){
	int t,n,jikan,mjikan,lop,souwa=0;

	scanf("%d",&n);
	scanf("%d",&t);

	scanf("%d",&mjikan);

	for(lop=0;lop<n-1;lop++){
		scanf("%d",&jikan);
		
		if(jikan-mjikan>=t){
			souwa+=t;
		}else{
			souwa+=jikan-mjikan;
		}	
		mjikan=jikan;
	}

	souwa+=t;
	printf("%d\n",souwa);
	

	return 0;

}

Measured memory_bytes: 128
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author rahdirigs
 */

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

template <typename T> void s_min(T& a, T b) {
	if (a > b) {
		a = b;
	}
}

const ll INF = 0x3f3f3f3f;

class TaskE {
public:
	void solve(std::istream& in, std::ostream& out) {
		int N, W;
		in >> N >> W;
		vector<int> v(N + 1), w(N + 1);
		for (int i = 1; i <= N; i++) in >> w[i] >> v[i];
		const int V = 1000 * N;
		vector<vector<ll>> dp(N + 1, vector<ll> (V + 1, INF));
		dp[1][0] = 0;
		dp[1][v[1]] = w[1];
		for (int i = 2; i <= N; i++) {
			for (int j = 0; j <= V; j++) {
				dp[i][j] = dp[i - 1][j];
				if (j < v[i]) continue;
				s_min(dp[i][j], w[i] + dp[i - 1][j - v[i]]);
			}
		}
		int ans = 0;
		for (int i = 0; i <= V; i++) {
			if (dp[N][i] <= W) ans = i;
		}
		out << ans;
	}
};


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	TaskE solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int l = 0, r = n - 1, ans = 0;;

  while (l < r) {
    if (s[l] == 'W' && s[r] == 'R') {
      ans++;
      l++; r--;
    } else {
      if (s[l] == 'R') l++;
      if (s[r] == 'W') r--;
    }
  }

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


Measured memory_bytes: 3744
#include<iostream>
#include<math.h>
using namespace std;

int main(){
int x;
int y;
cin>>x>>y;
double a, b;
a = (-y + 4 * x)/2;
b = (y - 2 * x)/2;



      if(y % 2 == 0 && a >= 0 && b >= 0)cout<<"Yes";
      else cout<<"No";


}


Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main(){
    int x,a,i,j,b;
    string s;
    cin >> s;
    x=0;
    b=0;
    a=s.length();
    if(s[0]!='A')
        x=1;
    if(s[0]=='C'||s[1]=='C'||s[a-1]=='C')
        x=1;
    for(j=2;j<a-1;j++){
        if(s[j]=='C'){
            b++;
        }
    }
    if(b>1||b==0)
        x=1;
    for(i=1;i<a;i++){
        if(s[i]=='C')
            continue;
        if(s[i]<'a'||s[i]>'z')
            x=1;
    }

    if(x==1)
        cout << "WA" << endl;
    else
        cout << "AC" << endl;
    return 0;
}

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

int main()
{
    ll K; cin >> K;
    if (K % 2 == 0) {
        cout << K / 2 * K / 2 << endl;
    }
    else {
        ll tmp = (K - 1) / 2;
        cout << (tmp+1) * tmp << endl;
    }



}


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

int main(void)
{
    int b;
    cin >> b;
    vector<long long> L(b);
    for (int i = 0;i < b;i++) cin >> L[i];
    int ans = 0;
    
    for (int i = 0;i < b;i++)
    {
        for (int j = i+1;j < b;j++)
        {
            for (int k = j+1;k < b;k++)
            {
                if (L[i] == L[j] || L[j] == L[k] || L[i] == L[k]) continue;
                long long _max = max({L[i], L[j], L[k]});
                long long _min = min({L[i], L[j], L[k]});
                long long mid = L[i] + L[j] + L[k] - _max - _min; 
                if (_max >= _min + mid) continue;
                ans++;
            }
        }
    }

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


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

ll mpow(ll x, ll n){ //x^n(mod mo) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % mo;
        x = x*x % mo;
        n = n >> 1;
    }
    return ans;
}
 
const int mod = 1000000007;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
 
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};
 
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(200010);

int main(){
    ll N,K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i,N){
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    mint ans = 0;
    REP(i,K-1,N){
        ans += mint(A[i])*comb(int(i),int(K-1));
        //cout << comb(int(i),int(K-1)) << endl;
    }
    sort(A.begin(), A.end(), greater<ll>());
    REP(i,K-1,N){
        ans -= mint(A[i])*comb(int(i),int(K-1));
    }
    cout << ans << endl;
}



Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
  int n;
  long long s = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    s += a[i];
  }
  a[n] = a[0];
  long long each = 1LL * n * (n + 1) / 2;
  if (s % each != 0) {
    printf("NO\n");
    return 0;
  }
  long long rounds = s / each;
  long long cnt = 0;
  for (int i = 1; i <= n; i++) {
    long long expect = a[i - 1] + rounds;
    long long diff = expect - a[i];
    if (diff % n != 0) {
      printf("NO\n");
      return 0;
    }
    diff /= n;
    if (diff < 0 || diff > rounds) {
      printf("NO\n");
      return 0;
    }
    cnt += diff;
  }
  if (cnt == rounds) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }
  return 0;
}


Measured memory_bytes: 640
from operator import itemgetter

N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]

XY.sort(key=itemgetter(1))
XY.sort(key=itemgetter(0))

ans = N
for i in range(N-1):
    for j in range(i+1, N):
        p = XY[j][0] - XY[i][0]
        q = XY[j][1] - XY[i][1]
        cost1 = N
        cost2 = N
        for x, y in XY:
            if [x+p, y+q] in XY:
                cost1 -= 1
            if [x-p, y-q] in XY:
                cost2 -= 1
        ans = min([ans, cost1, cost2])
print(ans)

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

using namespace std;

void insertionsort(vector<int> &a, int n,int g, int &cnt){
	int v;
	for (int i = g; i < n; i++) {
		v = a[i];
		int j = i - g;
		while (j >= 0 && a[j] > v) {
			a[j + g] = a[j];
			j = j - g;
			cnt++;
		}
		a[j + g] = v;
	}
}

void shellsort(vector<int> &a, int n) {
	int cnt = 0;
	int m = 1;
	vector<int> g;

	int pitch;
	pitch = int(n*(pow(3, -m))) + 1;
	g.push_back(pitch);
	while (pitch != 1) {
		m++;
		pitch = int(n*(pow(3, -m)))+1;
		g.push_back(pitch);
	}
	for (int i = 0; i < m; i++) {
		insertionsort(a, n, g[i],cnt);
	}
	cout << m << endl;
	cout << g[0];
	for (int i = 1; i < m; i++) {
		cout << " " << g[i];
	}
	cout << endl;
	cout << cnt << endl;
	for (int i = 0; i < n; i++) {
		cout << a[i] << endl;
	}
}

int main() {

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

	shellsort(a, n);

}


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

int num[100000];
int main(){
    int n, k;
    int a;
    int i;
    long long int now;
    long long int max;
    cin >> n >> k;
    while(n || k){
        for(i=0;i<n-k;i++){
            num[i] = 0;
        }
        now = 0;
        max = 0;
        for(i=0;i<k;i++){
            cin >> a;
            num[i] -= a;
            now += a;
        }
        for(;i<n-k;i++){
            cin >> a;
            num[i] -= a;
            num[i-k] += a;
        }
        for(;i<n;i++){
            cin >> a;
            num[i-k] += a;
        }
        for(i=0;i<n-k+1;i++){
            if(max < now){
                max = now;
            }
            now += num[i];
        }
        cout << max << endl;
        cin >> n >> k;
    }
}

Measured memory_bytes: 1068
# 058_a
a, b, c = map(int, input().split())
if (1 <= a & a <= 100) & (1 <= b & b <= 100) & (1 <= c & c <= 100):
    d_ab = b - a
    d_bc = c - b
    if d_ab == d_bc:
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 9144
///******* In the name of Allah *******///

#include <bits/stdc++.h>
using namespace std;

int main()
{
    long int a,b,c,d,e,f,g,t,i,j,k,l1,l2,m,n,r,sum,ans_1,ans_2,ans_3,cnt,Max,Min,flag,swi1,swi2;
    double aa,bb,cc,dd,ee;
    char aaa[1013][1013],bbb[1013],ccc[1013];
    cin>>n>>m;
    if(n==m)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    char s[3];
    int i,len,d=0,sum;
    gets(s);
    len=strlen(s);
    for(i=0;i<len;i++){
        if(s[i]=='o'){
        d=d+1;
        }
    }
    sum=700+(d*100);
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
        public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);
                int A = sc.nextInt();
                int B = sc.nextInt();
                sc.close();
                int r = (B - 1) / (A - 1);
                int d = (B - 1) % (A - 1) > 0 ? 1 : 0;
                System.out.println(r + d) ;
        }
}


Measured memory_bytes: 23124
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int c1 = sc.nextInt();
		int c2 = sc.nextInt();
		int c3 = sc.nextInt();

		int total = c1+c2+c3;
		if( c1 == (c2 + c3)){
			System.out.println("Yes");
		}else if( c2 == (c1 + c3)){
			System.out.println("Yes");
		}else if (c3 == (c1+c2)){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}

		sc.close();
	}

}


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

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

int n,m;
int a[125];

int main(){
  scanf("%d%d", &n, &m);
  REP(i,n)scanf("%d", a+i);
  sort(a,a+n,greater<int>());
  int total = accumulate(a, a+n, 0);
  if(a[m-1] * 4 * m >= total){
    puts("Yes");
  }else{
    puts("No");
  }
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

lastx = sum(
    a * (1 if i % 2 == 0 else -1)
    for i, a in enumerate(A)
) // 2
print(lastx * 2, end="")

for a in A[:-1]:
    lastx = a - lastx
    print(" " + str(lastx * 2), end="")


Measured memory_bytes: 14028
N = int(input())
H = [int(x) for x in input().split()]

dp = [float('inf')] * N
dp[0] = 0
dp[1] = abs(H[1]-H[0])

for i in range(2,N):
    d1 = dp[i-1] + abs(H[i] - H[i-1])
    d2 = dp[i-2] + abs(H[i] - H[i-2])
    dp[i] = min(d1,d2)
        
print(dp[N-1])

Measured memory_bytes: 13928
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
signed main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    
    int idx = 1;
    rep(i, n) {
        idx = a[idx - 1];
        if (idx == 2) {
            put(i + 1);
            return 0;
        }
    }

    put(-1)
    return 0;
}

Measured memory_bytes: 3736
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::cmp::{min, max};

struct Scanner<R: Read> {
    reader: R,
    buffer: String,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader, buffer: String::new() }
    }

    // fn line(&mut self) -> String {
    //     self.buffer = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
    //         .skip_while(|&c| c == '\n' || c == '\r')
    //         .take_while(|&c| !(c == '\n' || c == '\r'))
    //         .collect::<String>();
    //     self.buffer.clone()
    // }

    fn read_buffer(&mut self) {
        self.buffer = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        self.read_buffer();
        if self.buffer.is_empty() {
            None
        } else {
            self.buffer.parse::<T>().ok()
        }
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            // writeln!(std::io::stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }

    fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.read()).collect()
    }

    fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }
}

trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item=U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(104_857_600)
        .spawn(solve)
        .unwrap()
        .join()
        .unwrap();
}

fn solve() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    loop {
        let n = sc.read();
        let mut a: Vec<u32> = sc.vec(n);
        a.sort();
        a.dedup();
        let m = sc.read();
        let mut b: Vec<u32> = sc.vec(m);
        b.sort();

        let mut cnt = 0;
        let mut it = a.iter().peekable();
        for &x in b.iter() {
            // println!("{:?}", it);
            while let Some(&y) = it.peek() {
                if y < &x {
                    it.next();
                } else {
                    break;
                }
            }
            while let Some(&y) = it.peek() {
                if y == &x {
                    cnt += 1;
                    it.next();
                } else {
                    break;
                }
            }
        }
        println!("{}", cnt);
    }
}



Measured memory_bytes: 9164
#include <stdio.h>
 
int main()
{
  int n,m,i,j,count=0;
  scanf("%d",&n);
  int a[n];
  for(i=0; i<n; i++) scanf("%d",&a[i]);
  scanf("%d",&m);
  for(i=0; i<m; i++) {
    int x;
    scanf("%d",&x);
    for(j=0; j<n; j++) {
      if(a[j]==x) {
    count++;
    break;
      }
    }
  }
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 1988
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline--------------------------------------------
    n = int(input())
    a = list(map(int,input().split()))
    tmp = 0
    ans = 0
    r = 0
    for l in range(n):
        while r < n and tmp ^ a[r] == tmp + a[r]:
            tmp += a[r]
            r += 1
        ans += r-l
        if l == r:
            r += 1
        else:
            tmp -= a[l]
    print(ans)
if __name__ == "__main__":
    main() #endline===============================================
    

Measured memory_bytes: 27144
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

ll gcd(ll a, ll b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

vector<ll> enum_div(ll n){//nの約数を列挙
  vector<ll> ret;
  for(ll i=1 ; i*i<=n ; ++i){
    if(n%i == 0){
      ret.push_back(i);
      if(i!=1 && i*i!=n){
        ret.push_back(n/i);
      }
    }
  }
  sort(ret.begin(),ret.end());
  return ret;
}

bool is_prime(ll num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

const int INF = 1<<30;
int main(){
  int n,m; cin >> n >> m;
  vector<pair<int,int>> key;
  rep(i,m){
    int a, b;
    cin >> a >> b;
    int s = 0;
    rep(j,b){
      int c;
      cin >> c;
      c--;
      s |= 1<<c;
    }
    key.emplace_back(s,a);
  }
  
  vector<int> dp(1<<n,INF);
  dp[0] = 0;
  rep(s,1<<n){
    rep(i,m){
      int t = s | key[i].first;
      int cost = dp[s] + key[i].second;
      dp[t] = min(dp[t],cost);
    }
  }
  int ans = dp.back();
  if (ans == INF) ans = -1;
  cout << ans << endl;
  return 0;
}

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

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

typedef long long ll;

struct hoge{
    int s, n;
    string name;
    hoge(int s, int n, string name) : s(s), n(n), name(name) { }
};
bool operator < (const hoge &a, const hoge &b){
    return a.s != b.s ? a.s > b.s : a.n < b.n;
}

int main(void){
    int count=0;
    while(true){
        int n;
        cin >> n;
        if(count !=0 && n!=0) cout << "\n";
        count++;
        if(n==0) break;
        vector<hoge> v;
        string name;
        int win;
        
        for(int i=0; i<n; i++){
            cin >> name;
            ll w, l, d;
            cin >> w >> l >> d;
            win=3*w+d;
            v.push_back(hoge(win, i, name));
        }
        sort(v.begin(), v.end());
        for(int i=0; i<n; i++){
            cout << v[i].name << "," << v[i].s << "\n";
        }
        
    }
     
     
    return 0;
}


Measured memory_bytes: 3180
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define _size(X) (int)((X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 100000;
int N;
vector<int> A;
vector<int> bet1;
vector<int> bet2;

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

  cin >> N;
  A.push_back(0);
  rep(i, N) {
      int t;
      cin >> t;
      A.push_back(t);
  }
  A.push_back(0);

  for (int i = 0; i < A.size(); ++i) {
      if (i+1 != A.size()) {
          bet1.push_back(abs(A[i+1]-A[i]));
      }
      if (i+2 != A.size()) {
          bet2.push_back(abs(A[i+2]-A[i]));
      }
  }

  ll sum = 0;
  for (int i = 0; i < bet1.size(); ++i) {
      sum += bet1[i];
  }

  for (int i = 1; i < A.size()-1; ++i) {
      ll ans = sum;
      ans -= bet1[i-1];
      ans -= bet1[i];
      ans += bet2[i-1];
      cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 2936
#include<iostream>
#include<string>
#define value( x ) cout<< "value of "<< #x << " is "<< x<<endl;
long long max( long long x, long long y) {if(x>y) return x;else return y;}
using namespace std;
int main()
{

	int temp='a';
    	char c[100];
    	for(int i=0;i<26;i++) c[i]=temp+i;
    	string s;
    	cin>>s;
    	int counting=0;
    	int temp2;
    	for(int i=0;i<s.length();i++) {
    			temp2=s[i];
    			temp2-=temp;
    			c[temp2]='0';
    	}
    	for(int i=0;i<26;i++)
    	{
    		if(c[i]!='0'){ cout<<c[i];break;}
    		else counting++;
    	}
    	if(counting==26)cout<<"None";
return 0;
}


Measured memory_bytes: 512
//Dragon_warrior7(IITK)
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define umap unordered_map
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define pll pair<ll, ll> 
#define ull unsigned ll
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
#define deb(x) cout<<#x<<' '<<'='<<' '<<x<<'\n'
//typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}
// const int mod=1e9+7;
// ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// ll modInverse(ll a){return power(a,mod-2);}
ll n,m,a,b,c,k,temp,x,y;
void solveforthiscase(const int & test)
{//deb(test);
cin>>n;
ll ans=0;
cin>>k;
for(int b=k+1;b<=n;b++)
{
    ans+=(b-k)*(n/b);
    int l=n%b;
    //deb(l);
    if(k==0)
    ans+=max(0ll,l-k);
    else
    ans+=max(0ll,l-k+1);
    //deb(ans);
}
cout<<ans;
return ;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
// 	cin>>test;
    for(int i=1;i<=test;i++)
    {
        solveforthiscase(i);
    }
}

Measured memory_bytes: 256
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin >> n;
	println(n*n*n);
}


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

bool valid(char s) {
  return  (s == 'A' || s == 'C' || s == 'G' || s == 'T');
};

int main() {
  string S;
  cin >> S;
  int n = S.size();
  vector<int> ans(n, 0);

  for (int i = 0; i < n; i++) {
    if (valid(S[i])) {
      for (int j = i; j < n; j++) {
        if (valid(S[j])) ans[i]++;
        else break;
      }
    }
  }

  sort(ans.begin(), ans.end());
  reverse(ans.begin(), ans.end());
  cout << ans[0] << endl;
};


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <iomanip>
using namespace std;
#define rep(i, N) for (ll i = 0; i < (N); i++)
typedef long long ll;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll count = s.size();
    rep(i, count)
    {
        cout << "x";
    }
    cout << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static boolean pal(int a) {
		int[] A = new int[5];
		for(int i =0; i < 5; i ++) {
			A[i] = a%10;
			a /= 10;
		}
		if(A[0] == A[4] && A[1] == A[3]) {
			return true;
		}
		else {
			return false;
		}
	}

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int A = stdIn.nextInt();
		int B = stdIn.nextInt();
		int count = 0;
		
		for(int i = A; i <= B; i++) {
			if(pal(i)) {
				count++;
			}
		}
		System.out.println(count);

	}

}

Measured memory_bytes: 25684
import java.util.Scanner;
import java.util.Arrays;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int d = sc.nextInt();
    int t = sc.nextInt();
    int s = sc.nextInt();
    String ans;
    ans = (s * t >= d) ? "Yes" : "No";
    System.out.println(ans);
    sc.close();
  }
}


Measured memory_bytes: 35744
#include<stdio.h>
#include<string.h>
int main(void)
{
	int degy[4]={1,0,-1,0},degx[4]={0,1,0,-1};
	int i,j,m,n,x,y,deg;
	char s[5][9]={"FORWARD","BACKWARD","RIGHT","LEFT","STOP"};
	int suu;
	char buf[20];
	
	while(1)	{
		scanf("%d %d",&m,&n);
		if(m==0 && n==0)	break;
		x=1;	y=1;	deg=0;
		while(1)	{
			scanf("%s",buf);
			if(strcmp(buf,s[0])==0)	{
				scanf("%d",&suu);
				x=x+degx[deg]*suu;
				if(x>m)	x=m;
				if(x<1)	x=1;
				y=y+degy[deg]*suu;
				if(y>n)	y=n;
				if(y<1)	y=1;
			}
			else if(strcmp(buf,s[1])==0)	{
				scanf("%d",&suu);
				x=x-degx[deg]*suu;
				if(x>m)	x=m;
				if(x<1)	x=1;
				y=y-degy[deg]*suu;
				if(y>n)	y=n;
				if(y<1)	y=1;
			}
			else if(strcmp(buf,s[2])==0)	{
				deg=(deg+1)%4;
			}
			else if(strcmp(buf,s[3])==0)	{
				deg=(deg+3)%4;
			}			
			else if(strcmp(buf,s[4])==0) {
				break;
			}
		}
		printf("%d %d\n",x,y);
	}
	return 0;
}


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

#define LL long long
int arr[100009];

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	sort(arr,arr+n);
	int r=0,u=1;
	for(int i=1;i<n;i++){
		if(arr[i]==arr[i-1]){
			r++;
		}else{
			u++;
		}
	}
	int ans;
	if((u==1)&&(r>=2)){
		ans=u;
	}else if((u>1)&&(r>=1)){
		if(r%2==0){
			ans=u;
		}else{
			ans=u-1;
		}
	}else if((u>2)&&(r==0)){
		ans=u;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
n,k=map(int,input().split())
A=list(map(int,input().split()))
dp=[0]*(2*k)
for i in range(k+1):
  a=0
  for j in range(n):
    if dp[i-A[j]]==1:
      a=1
  if a==0:
    dp[i]=1
if dp[k]==0:
  print("First")
else:
  print("Second")

Measured memory_bytes: 43244
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)



int main(){

  ll dp[2501][51];
  ll ndp[2501][51];
  rep(i,2501){
    rep(j,51){
      dp[i][j]=0;
    }
  }
  dp[0][0]=1;
  ll n,a;
  cin >> n >> a;
  ll x[n];
  rep(i,n) cin >> x[i];
  ll cnum=1;
  rep(i,n){
    rep(j,2501){
      rep(k,51){
	if(j-x[i]>=0 && k>0){
	  ndp[j][k] = (dp[j-x[i]][k-1] + dp[j][k]);
	}
	else ndp[j][k] = dp[j][k];
      }
    }
    swap(ndp,dp);
  }
  ll ans=0;
  rep(i,2501) rep1(j,50){
    if(j*a==i && dp[i][j]>0){
      ans+=dp[i][j];
    }
  }
  cout << ans << endl;
  return 0;

}


Measured memory_bytes: 2176
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

#define MAX 200010
#define INF (int)(1e9 + 10)

vector<int> G[MAX];
int a[MAX] = {0};
int d[MAX];

void dfs(int i, int par, vector<int> &lis) {
    bool push = false;
    auto pp_update = partition_point(lis.begin(), lis.end(), [&](int x) {
        return x < a[i];
    });
    int org = *pp_update;
    *pp_update = a[i];
    auto pp_end = partition_point(lis.begin(), lis.end(), [&](int x) {
        return x < INF;
    });
    d[i] = pp_end - lis.begin() - 1;
    for (auto &g:G[i]) {
        if (g == par) continue;
        dfs(g, i, lis);
    }
    *pp_update = org;
}

int main() {
    int n;
    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> a[i];
    }
    for (int i=0, ui, vi; i<n-1; i++) {
        cin >> ui >> vi;
        ui--; vi--;
        G[ui].push_back(vi);
        G[vi].push_back(ui);
    }
    vector<int> lis(n+1, INF);
    lis[0] = -INF;
    dfs(0, -1, lis);
    for (int i=0; i<n; i++) {
        cout << d[i] << '\n';
    }
    return 0;
}

Measured memory_bytes: 30748
#include<bits//stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n;i++)
int main() {
	deque<char> dq;string S;
	cin >> S; char c;bool r = 0;
	rep(i,S.size()) dq.push_back(S[i]);
	int q, t, f;cin >> q;
	rep(i, q) {
		cin >> t;
		if (t == 1) r ^= 1; // ^ = xor
		else {
			cin >> f >> c;f--;
			if (f ^ r) dq.push_back(c);
			else dq.push_front(c);
		}
	}
	if(r)reverse(dq.begin(), dq.end());
	rep(i, dq.size()) cout << dq[i];
}

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

bool isNotDivisor[1000010], isVisited[1000010] = {0};

void sieveDivisor(int arr[], int max, int n)
{
	for(int i = 0; i <= max; i++) isNotDivisor[i] = true;
	for(int i = 0; i < n; i++)
	{
		if(isNotDivisor[arr[i]] && !isVisited[arr[i]])
		{
			isVisited[arr[i]] = 1;
			for(int j = arr[i] * 2; j <= max; j+=arr[i])
				isNotDivisor[j] = false;
		}
		else isNotDivisor[arr[i]] = false;
	}
}

int main()
{
	int n, cnt = 0;
	scanf("%d", &n);
	int arr[n];
	for(int i = 0; i < n; i++) scanf("%d", &arr[i]);
	sort(arr, arr + n);
	int max = arr[n-1];
	sieveDivisor(arr, max, n);
	for(int i = 0; i < n; i++)
		if(isNotDivisor[arr[i]])
			cnt++;
	printf("%d", cnt);
	return 0;
}


Measured memory_bytes: 6548
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string str;
    int num;
    while(1){
        cin >> str;
        if(str == "0") break;
        num=0;
        for(int i=0; i<str.size(); i++){
            char c=str[i];
            num += c-'0';
        }
        cout << num << endl;
    }
    return 0;
}



Measured memory_bytes: 3152
//@author Khaled Alam(Ninjo) ~ KhaledAlam.net
#include <bits/stdc++.h>
using namespace std;
// Template(v0.0.1)  |  Github.com/khaledalam/templates/tree/master/cpp
typedef long long ll;
typedef vector<int> vi;
typedef stringstream ss;
typedef pair<int, int> pii;
//#########################
#define endl         '\n'
#define fi           first
#define se           second
#define pb           push_back
#define mp           make_pair
#define out(x)       return cout<<x,0
#define all(x)       x.begin(),x.end()
#define sz(x)        ((int)(x.size()))
#define clr(x)       memset(x,0,sizeof x)
#define rep(i,n)     for(int i=0;i<n;i++)
#define ifile(x)     freopen(#x,"r",stdin)
#define ofile(x)     freopen(#x,"w",stdout)
#define pin0(x)      size_t x = time(NULL)
#define pin1(x)      fprintf(stderr,"time: %.2fs\n",(float)time(NULL)-x)
#define foreach(i,t) for(__typeof(t.begin()) i=t.begin();i!=t.end();i++)
#define ios          ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define val(x)       cerr<<"[l#: "<<__LINE__<<"] "<< " "<<#x<<" = "<<x<<'\n'
//##########################################################################

map<int, bool> vis;
ll res = 0;
int main()
{
//	ios;
//	ifile(input.txt); //ofile(output.txt);

//	cout << __gcd(0, 5);
//	return 0;
	int n;
	cin >> n;

	rep(i,n)
	{
		int a;
		cin >> a;
		if (vis[a])
		{
			vis[a] = false;
			res--;
		}
		else
		{
			vis[a] = true;
			res++;
		}
	}
	cout << res;
}



Measured memory_bytes: 4864
/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */
 
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x)     x.begin(),x.end()
#define tc   int tt; scf(tt); while(tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll M =1e9+7;
const int N = 1e6+7;


ll ME(ll x,ll n)
{
    ll res=1;
    
    while(n)
    {
        if(n&1)
        res=(res*x)%M;
        
        n/=2;
        
        x=(x*x)%M;
    }
    
    return res;

    
}



void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

    
int main()
{

    int n,ctr=0;
    scf(n);
    
    int a[n];
    
    rep(i,0,n)
    scf(a[i]);
    
    for (int i = 0; i < n; i++)
    { 
        for (int j = i + 1; j < n; j++)
        { 
  
            for (int k = j + 1; k < n; k++) 
            {
  
               if( a[i] + a[j] > a[k] 
                    && a[i] + a[k] > a[j] 
                    && a[k] + a[j] > a[i]&&a[i]!=a[k]&&a[k]!=a[j]&&a[i]!=a[j]) 
                    ctr++; 
            } 
    } 
 
} 
    
    
 
        
    
    
    prin(ctr);
    
    


    
    
          
    
}

Measured memory_bytes: 3820
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<=(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換　
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return Euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int digit_sum(int n) {
  int sum=n%10;
  while(n!=0) {
    n/=10;
    sum+=n%10;
  }
  return sum;
}

vpll PrimeFactorization(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}

int main() {
  int n, k;
  cin >> n >> k;
  vi l(n);
  REP(i,n) cin >> l[i];
  sort(ALL(l),greater<int>());
  int ans=0;
  REP(i,k) {
    ans+=l[i];
  }
  cout << ans << endl;
  return 0;
}


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

const int MAXN = 100000 + 5;

int N, M;
vector<int> Adj[MAXN];
int fa[MAXN], col[MAXN], dep[MAXN];

bool hasCircle;
int circA, circB;

inline void addEdge(int u, int v)
{
	Adj[u].push_back(v);
	Adj[v].push_back(u);
}

void DFS(int cur)
{
	dep[cur] = dep[fa[cur]] + 1;
	col[cur] = (dep[cur] & 1 ? 1 : -1);

	for (int to : Adj[cur])
	{
		if (to == fa[cur])
			continue;
		if (dep[to])
		{
			if (!hasCircle)
				circA = cur, circB = to, hasCircle = true;
		}
		else
			fa[to] = cur, DFS(to), col[cur] += col[to];
	}
}

int solveAcyclic()
{
	if (col[1])
		return -1;

	int ret = 0;
	for (int i = 1; i <= N; i++)
		ret += abs(col[i]);
	return ret;
}

int solveOddCircle()
{
	if (col[1] & 1)
		return -1;

	int delta = -col[1] / 2, ret = abs(delta), cur;
	cur = circA;
	while (cur)
		col[cur] += delta, cur = fa[cur];
	cur = circB;
	while (cur)
		col[cur] += delta, cur = fa[cur];

	for (int i = 1; i <= N; i++)
		ret += abs(col[i]);
	return ret;
}

int solveEvenCircle()
{
	if (col[1])
		return -1;

	int circle[MAXN] =
	{ 0 }, top = 0;
	for (int cur = circA; cur != circB; cur = fa[cur])
		circle[++top] = col[cur], dep[cur] = 0;

	int mid = (top + 1) >> 1, delta, ret;
	nth_element(&circle[1], &circle[mid], &circle[top + 1]);

	delta = (circle[mid]);
	ret = abs(delta);

	for (int i = 1; i <= N; i++)
		if (dep[i])
			ret += abs(col[i]);
	for (int i = 1; i <= top; i++)
		ret += abs(circle[i] - delta);
	return ret;
}

int main()
{
	//printf("%d %d\n", 1 & 1, -1 & 1);
	fflush(stdout);

	scanf("%d%d", &N, &M);
	for (int i = 1; i <= M; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		addEdge(u, v);
	}

	DFS(1);

	if (!hasCircle)
		printf("%d\n", solveAcyclic());
	else
	{
		if ((dep[circA] - dep[circB] + 1) & 1)
			printf("%d\n", solveOddCircle());
		else
			printf("%d\n", solveEvenCircle());
	}

	return 0;
}


Measured memory_bytes: 11520
use std::cmp;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
    	a:isize,
        b:isize,
        c:isize
    }
       
    println!("{}", cmp::max(c-a+b, 0));
}

Measured memory_bytes: 4352
import sys

n = int(input())
minv = int(input())
v = int(input())
maxv = v-minv
if v < minv: minv = v

for r in map(int,sys.stdin.readlines()):
  m = r-minv
  if maxv < m < 0:
    maxv = m
    minv = r
  elif maxv < m:
    maxv = m
  elif m < 0:
    minv = r

print(maxv)

Measured memory_bytes: 21912
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
for i in range(N):
	a.append(a[i] + A[i])
for i in range(M):
	b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
	if a[i] > K:
		break
	while b[j] > K - a[i]:
		j -= 1
	ans = max(ans, i + j)
print(ans)

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

int main(){
  int A[3][3];
  rep(i,0,3)rep(j,0,3) cin >> A[i][j];
  int n;
  cin >> n;
  int b[n];
  rep(i,0,n) cin >> b[i];

  rep(i,0,n){
    rep(j,0,3)rep(k,0,3){
      if(b[i]==A[j][k]) A[j][k] = 0;
    }
  }

  int flag = 0;

  rep(i,0,3){
    if(A[0][i]==A[1][i] && A[1][i]==A[2][i] && A[0][i]==0) flag = 1;
    if(A[i][0]==A[i][1] && A[i][1]==A[i][2] && A[i][0]==0) flag = 1;
  }
  if(A[0][0]==A[1][1] && A[1][1]==A[2][2] && A[0][0]==0) flag = 1;
  if(A[2][0]==A[1][1] && A[1][1]==A[0][2] && A[1][1]==0) flag = 1;

  cout << (flag==1 ? "Yes" : "No") << endl;


  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long w;
int n;
long arr[101][2];

long mx=1000000001;
int main() {
	// your code goes here
	cin>>n>>w;
	long v=0;
	for(int i=1;i<=n;++i)
	    {cin>>arr[i][0]>>arr[i][1];v+=arr[i][1];}
	long dp[v+1];
	dp[0]=0;
    for(int i =1;i<=v;++i) dp[i]=mx;
	
	for(int i =1;i<=n;++i)  
	    for(int j=v;j>=arr[i][1];--j)
	        dp[j]= min(dp[j],dp[j-arr[i][1]]+arr[i][0]);
	    
	 


	for(int i=v;i>=1;--i)
	    {
	        if(dp[i]<=w) {cout<<i; return 0;}
	    }
	 
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(){
    int n, dr;
    scanf("%d %d", &n, &dr);

    int ir, k = n;

    if (n >= 10){
        ir = dr;
    } else {
       k = n;
       ir = (dr + 100*(10-k));
    }
 printf("%d", ir);
 return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[4]={0,1,0,-1},mdy[4]={-1,0,1,0};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll n;
ll a[300100];
priority_queue<ll,vector<ll>,greater<ll>> former;
priority_queue<ll> latter;
ll sum_f[100100]={};
ll sum_l[100100]={};
ll ans=-INFl;
int main(){
	cin>>n;
	REP(i,3*n)cin>>a[i];
	REP(i,n){
		former.push(a[i]);
		sum_f[0]+=a[i];
	}
	for(int i=2*n;i<3*n;i++){
		sum_l[0]+=a[i];
		latter.push(a[i]);
	}
	for(int i=n;i<2*n;i++){
		former.push(a[i]);
		sum_f[i-n+1]=sum_f[i-n]+a[i]-former.top();
		former.pop();
	}
	for(int i=2*n-1;i>=n;i--){
		latter.push(a[i]);
		sum_l[2*n-i]=sum_l[2*n-i-1]+a[i]-latter.top();
		latter.pop();
	}
	for(int i=0;i<=n;i++){
		ans=max(ans,(sum_f[i]-sum_l[n-i]));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5876
#include<iostream>
int main(){
  int a,b;
  std::cin >> a >> b;
  if(a < b) std::cout << "a < b" << std::endl;
  else if(a > b) std::cout << "a > b" << std::endl;
  else std::cout << "a == b" << std::endl;
  return 0;
}

Measured memory_bytes: 3088
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;

int main()
{
	int n, a[200000], b[200000], ar[200000][29], br[29][200000], c[29], x[29], ans=0, a1[29], b1[29];

	c[0]=1;
	x[0]=0, a1[0]=0, b1[0]=0;
	for(int i=0; i<28; i++){
		c[i+1]=c[i]*2;
		x[i+1]=0, a1[i+1]=0, b1[i+1]=0;
	}

	scanf("%d", &n);
	for(int i=0; i<n; i++){
		scanf("%d", &a[i]);
		for(int j=0; j<29; j++){
			ar[i][j]=a[i]%c[j];
			if(a[i]/c[j]%2==1){
				a1[j]++;
			}
		}
	}
	for(int i=0; i<n; i++){
		scanf("%d", &b[i]);
		for(int j=0; j<29; j++){
			br[j][i]=b[i]%c[j];
			if(b[i]/c[j]%2==1){
				b1[j]++;
			}
		}
	}

	for(int s=1;s<29;s++){
		sort(br[s], br[s]+n);
		for(int i=0; i<n; i++){
			if(br[s][n-1]<c[s]-ar[i][s]){
				continue;
			}else{
			int j1=0, j2=n-1;
			while(j1!=j2){
				int jmid=(j1+j2)/2;
				if(br[s][jmid]<c[s]-ar[i][s]){
					j1=jmid+1;
				}else{
					j2=jmid;
				}
			}
			x[s]=(x[s]+n-j1)%2;
			}
		}
	}

	for(int s=0; s<29; s++){
		x[s]=(x[s]+n%2*(a1[s]+b1[s])%2)%2;
		ans=ans+x[s]*c[s];
	}

	printf("%d\n", ans);

	return 0;

}

Measured memory_bytes: 46976
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;
int inf = 1000000000;

int main(void) {

  int n;
  cin >> n;
  cout << n * 32 << endl;

  return 0;
}

// EOF

Measured memory_bytes: 3128
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <list>
#include <set>
#include <utility> // pair
#include <map>
#include <iostream>
#include <sstream>
#include <algorithm> // sort
#include <string>
#include <stack>
#include <queue>
#include <fstream>
#include <bitset>
#define PI acos(-1)
typedef long long ll;
const long long mod = 1e9 + 7;
const long long maxn = 1e5 + 5; 
using namespace std;

int a[30] = {0};
int b[30] = {0};
int main() 
{ 
	int a, b, c, d;
	scanf("%d %d %d %d", &a, &b, &c, &d);
	if (b >= c)
		printf("Yes\n");
	else if (d >= a)
		printf("No\n");
	else
	{
		while (a != 0 && c != 0)
		{
			c -= b;
			if (c <= 0)
			{
				printf("Yes\n");
				break;
			}
			a -= d;
			if (a <= 0)
			{
				printf("No\n");
				break;
			}
		}
		
	}
	
	return 0;
}

Measured memory_bytes: 3760