akhauriyash/Code-Regression huggingface dataset:
#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 ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int mod = (int)1e9 + 7;
const int MX = (int)1e5 + 10;

void add_self(int &x, int y){x += y; if(x >= mod) x -= mod;}
void sub_self(int &x, int y){x -= y; if(x < 0) x += mod;}
void mul(int &x, int y){x = x * 1LL * y % mod;}

int n;
vector<string> s;

int dp[MX][5][5][5];

int solve(int idx, int a, int b, int c){
	if(a < 0 || b < 0 || c < 0 || a > 4 || b > 4 || c > 4) return 0;
	if(idx == n){
		return a >= 0 && b >= 0 && c >= 0;
	}

	auto &ret = dp[idx][a][b][c];
	if(ret != -1) return ret;

	ret = 0;

	if(s[idx] == "AB"){
		ret |= solve(idx + 1, a - 1, b + 1, c);
		ret |= solve(idx + 1, a + 1, b - 1, c);
	}
	else if(s[idx] == "AC"){
		ret |= solve(idx + 1, a - 1, b, c + 1);
		ret |= solve(idx + 1, a + 1, b, c - 1);
	}
	else{
		ret |= solve(idx + 1, a, b - 1, c + 1);
		ret |= solve(idx + 1, a, b + 1, c - 1);
	}

	return ret;
}


void build(int idx, int a, int b, int c){

	if(idx == n) return;
	
	if(s[idx] == "AB"){
		if(solve(idx + 1, a - 1, b + 1, c)){
			cout << "B\n", build(idx + 1, a - 1, b + 1, c);
		}
		else{
			cout << "A\n", build(idx + 1, a + 1, b - 1, c);
		}
	}
	else if(s[idx] == "AC"){
		if(solve(idx + 1, a - 1, b, c + 1)){
			cout << "C\n", build(idx + 1, a - 1, b, c + 1);
		}
		else{
			cout << "A\n", build(idx + 1, a + 1, b, c - 1);
		}
	}
	else{
		if(solve(idx + 1, a, b + 1, c - 1)){
			cout << "B\n", build(idx + 1, a, b + 1, c - 1);
		}
		else{
			cout << "C\n", build(idx + 1, a, b - 1, c + 1);
		}
	}
}

int main(){

	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(0);

	int a, b, c;
	cin >> n >> a >> b >> c;

	s.resize(n);
	for(auto &x : s) cin >> x;

	memset(dp, 0xff, sizeof dp);

	a = min(a, 3);
	b = min(b, 3);
	c = min(c, 3);

	if(solve(0, a, b, c) == 1){
		cout << "Yes\n";
		build(0, a, b, c);
	}
	else{
		cout << "No\n";
	}

	return 0;
}

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


int main()
{
	int n;
	int ans = 0;
	int v[50];
	int c[50];

	cin >> n;

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


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

	for (int i = 0; i < n; i++) {
		if (v[i] - c[i] > 0) {
			ans += v[i] - c[i];
		}
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 256
N=int(input())
A,B,C=[list(map(int,input().split())) for _ in range(3)]
A=[x-1 for x in A]
ans=sum(B)
p=A[0]

for i in A[1::]:
    if i==p+1:
        ans+=C[p]
    p=i
print(ans)


Measured memory_bytes: 3060
pub struct Scanner {
    line: Vec<String>,
    idx: usize,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        return Scanner {
            line: vec![],
            idx: 0,
        };
    }
    fn next<T: std::str::FromStr>(&mut self) -> T {
        if self.idx == self.line.len() {
            let mut buffer = String::new();
            std::io::stdin().read_line(&mut buffer).ok();
            let a: Vec<&str> = buffer.trim().split(' ').collect();
            self.line = a.iter().map(|&s| String::from(s)).collect();
            self.idx = 0;
        }
        let ret: T = self.line[self.idx].parse::<T>().ok().expect("Parse error.");
        self.idx += 1;
        ret
    }
    fn next_string(&mut self) -> Vec<char> {
        let s: String = self.next();
        return s.chars().collect::<Vec<char>>();
    }
    fn next_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        let mut v: Vec<T> = Vec::with_capacity(n);
        for _i in 0..n {
            v.push(self.next());
        }
        v
    }
}

fn main(){
    let mut scan = Scanner::new();
    let r:f64 = scan.next();
    println!("{}", 2.0 * r * std::f64::consts::PI);
}


Measured memory_bytes: 2212
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define ll long long

int main() {
	int n;
	cin >> n;
	int arr[n];
	unordered_map<int, int> mp;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
		mp[arr[i]]++;
	}
	ll ans = 0;
	for (auto i : mp) {
		if (i.first < i.second) ans += i.second - i.first;
		else if(i.first > i.second)
		ans += i.second;
	}
	cout << ans <<endl;
}


Measured memory_bytes: 7468
#B問題
w = input()
ww = sorted(w)
flag = True
if len(w) % 2 != 0:
    flag = False
else:
    ww = sorted(w)
    for i in range(0, len(ww), 2):
        if ww[i] != ww[i+1]:
            flag = False
        
if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
from itertools import groupby

class UnionFindVerSize():
    def __init__(self, N):
        global S,H,W
        """ N個のノードのUnion-Find木を作成する """
        # 親の番号を格納する。自分が親だった場合は、自分の番号になり、それがそのグループの番号になる
        self._parent = [n for n in range(0, N)]
        # グループのサイズ（個数）
        self._size = [1] * N

        self._black=[0]*N
        self._white=[0]*N

        for i in range(0,H*W):
            h=i//W
            w=i%W
            if S[h][w]=='#':
                self._black[i]=1
                self._white[i]=0
            else:
                self._black[i]=0
                self._white[i]=1

    def find_root(self, x):
        """ xの木の根(xがどのグループか)を求める """
        if self._parent[x] == x: return x
        self._parent[x] = self.find_root(self._parent[x]) # 縮約
        return self._parent[x]

    def unite(self, x, y):
        """ xとyの属するグループを併合する """
        gx = self.find_root(x)
        gy = self.find_root(y)
        if gx == gy: return

        # 小さい方を大きい方に併合させる（木の偏りが減るので）
        if self._size[gx] < self._size[gy]:
            self._parent[gx] = gy
            self._black[gy]+=self._black[gx]
            self._white[gy]+=self._white[gx]
            self._size[gy] += self._size[gx]
        else:
            self._parent[gy] = gx
            self._black[gx]+=self._black[gy]
            self._white[gx]+=self._white[gy]
            self._size[gx] += self._size[gy]

    def get_size(self, x):
        """ xが属するグループのサイズ（個数）を返す """
        return self._size[self.find_root(x)]

    def is_same_group(self, x, y):
        """ xとyが同じ集合に属するか否か """
        return self.find_root(x) == self.find_root(y)

    def calc_group_num(self):
        """ グループ数を計算して返す """
        N = len(self._parent)
        ans = 0
        for i in range(N):
            if self.find_root(i) == i:
                ans += 1
        return ans

    def calc_black(self,x):
        return self._black[self.find_root(x)]

    def calc_white(self,x):
        return self._white[self.find_root(x)]


H,W=map(int,input().split())
S=[]
for i in range(0,H):
    s=input()
    S.append(s)

uf=UnionFindVerSize(H*W)
for i in range(0,H*W):
    h=i//W
    w=i%W
    if W-1>=w+1:
        if S[h][w]!=S[h][w+1]:
            uf.unite(i,i+1)
    if H-1>=h+1:
        if S[h][w]!=S[h+1][w]:
            uf.unite(i,i+W)

root=[uf.find_root(i) for i in range(0,H*W)]
root.sort()

ans=0
root=groupby(root)
for key,group in root:
    black=uf.calc_black(key)
    white=uf.calc_white(key)
    ans+=black*white

print(ans)


Measured memory_bytes: 75528
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,W;
	cin>>n>>W;
	long long int w[n], v[n];
	for(int i = 0; i < n; i++)
		cin>>w[i]>>v[i];
	long long int dp[n+1][W+1];
	for(int i = 0; i <= n; i++)
		dp[i][0] = 0;
	for(int i = 0; i <= W; i++)
		dp[0][i] = 0;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= W; j++)
		{
			if(j < w[i-1])
				dp[i][j] = dp[i-1][j];
			else
				dp[i][j] = max(dp[i-1][j], v[i-1] + dp[i-1][j-w[i-1]]);
		}

	cout<<dp[n][W];
	return 0;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin >>a>>b;
  if(a==1||b==1){
    if(a==2||b==2){
      cout<<3<<endl;
    }
    else{
      cout<<2<<endl;
    }
  }
  else{cout<<1<<endl;}
}

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

using namespace std;

int main(){
    int N,M; cin>>N>>M;
    int ans=0;
    vector<int> K(N+1);
    vector<vector<int>> A(N+1,vector<int>(M+1));
    vector<int> F(M+1,0);//好きな人数

    for(int i=1;i<=N;i++){
        cin>>K[i];
        for(int j=1;j<=K[i];j++){
            cin>>A.at(i).at(j);
        }
    }
    for(int i=1;i<=N;i++){
        for(int j=1;j<=K[i];j++){
            int tmp=A.at(i).at(j);
            F[tmp]++;
        }
    }
    for(int i=1;i<=M;i++){
        if(F[i]==N) ans++;
    }

    printf("%d",ans);


    return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    long long h;
    cin >> n >> h;
    vector<long long> b(n);
    long long a = 0;
    for(int i = 0; i < n; i++){
        long long x;
        cin >> x >> b[i];
        a = max(a, x);
    }
    sort(b.rbegin(), b.rend());
    long long cur = 0, ans = 0;
    for(int i = 0; i < n; i++){
        if(a >= b[i]) break;
        cur += b[i];
        ans++;
        if(cur >= h) break;
    }
    if(cur < h) ans += (h - cur + a - 1) / a;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;
using pii = pair<Int,Int>;
using mapis = unordered_map<Int,string>;
using mapii = unordered_map<Int,Int>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

Int LCM(Int a, Int b){
    return a*b/GCD(a,b);
}


int main() {
    Int r;

    cin >>r;



    cout << 3*r*r << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using ll=long long;
using namespace std;

int main(){
    ll mod=1e9+7;
    int N;
    cin>>N;
    vector<ll> A(N);
    ll sum=0;
    for(int i=0;i<N;i++){
        cin>>A[i];
        sum+=A[i];
        sum%=mod;
    }
    ll ans=0;
    for(int i=0;i<N;i++){
        sum-=A[i];
        sum+=mod;
        sum%=mod;
        ans+=A[i]*sum;
        ans%=mod;
    }

    cout<<ans<<endl;

    return 0;
}

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

using namespace std;

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

    if(S.at(K-1)=='A')
    {
        S.at(K-1) = 'a';
    }
    if(S.at(K-1)=='B')
    {
        S.at(K-1) = 'b';
    }
    if(S.at(K-1)=='C')
    {
        S.at(K-1) = 'c';
    }

    cout << S << endl;

    return 0;
}

Measured memory_bytes: 256
/* Beginning */

#include <iostream>
using namespace std;

int main(){
	int n;
	int cnt[4] = { 0, 0, 0, 0};

	for(int i = 0; i < 4; i++){
		cin >> n;
		if(n == 1){
			cnt[0] = 1;
		}else if(n == 9){
			cnt[1] = 1;		
		}else if(n == 7){
			cnt[2] = 1;		
		}else if(n == 4){
			cnt[3] = 1;		
		}
	}

	if((cnt[0] + cnt[1] + cnt[2] + cnt[3])%4 == 0) cout << "YES" << endl;
	else cout << "NO" << endl;

}

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

template <class T>
inline void read(T &x) {
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar()) f ^= c == '-';
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    T y = 1;
	int len = 1;
    for (; y <= x / 10; y *= 10) ++len;
    for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}

const int MAXN = 2e5, MAXM = 4e5;
int n, q, tot, head[MAXN + 5], f[MAXN + 5];
struct Edge {
	int next, to;
} e[MAXM + 5];

inline void addEdge(int u, int v) {
	e[++tot] = (Edge) { head[u], v };
	head[u] = tot;
}

void dfs(int u, int fa) {
	for (int v, i = head[u]; v = e[i].to, i; i = e[i].next) {
		if (v == fa) continue;
		f[v] += f[u];
		dfs(v, u);
	}
}

int main() {
	read(n), read(q);
	for (int u, v, i = 1; i < n; ++i) {
		read(u), read(v);
		addEdge(u, v), addEdge(v, u);
	}
	for (int x, p, i = 1; i <= q; ++i) {
		read(x), read(p);
		f[x] += p;
	}
	dfs(1, 0);
	for (int i = 1; i <= n; ++i) {
		write(f[i]);
		putchar(' ');
	}
	putchar('\n');
	return 0;
}

Measured memory_bytes: 16512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define EPS (1e-10)

void add_mod(ll &a, ll b){
	a += b;
	a %= MOD;
}

void mul_mod(ll &a, ll b){
	a *= b;
	a %= MOD;
}

vector<int> v[123456];

int main(void){
	int n,m,a,b,r,i,j,ans=0;
	cin >> n >> m;
	for(i=0; i<m; ++i){
		cin >> a >> b; --a; --b;
		v[a].push_back(b);
	}
	r = n;
	for(i=0; i<(n-1); ++i){
		for(j=(v[i].l_ength()-1); j>=0; --j){
			r = min(r,v[i][j]);
		}
		if(r-i==1){
			++ans;
			r = n;
		}
	}
	cout << ans << endl;
	return 0;
}


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

int max(int a,int b){
  if(a>b) return a;
  else return b;
}
int absolute(int a,int b){
  if(a-b<0) return -(a-b);
  else return a-b;
}
int main(){
  int x,a,b;
  cin >> x >> a >> b;
  
  if(absolute(x,a)<absolute(x,b)) cout << 'A' << endl;
  else cout << 'B' << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <limits>

#define rep(i,s,N) for(int i=s;i<N;i++)
using namespace std;
typedef long long int lli;

int cal(lli x) {
	int s = 0;
	while (x > 0) {
		s += x % 10;
		x /= 10;
	}
	return s;
}

int main(void)
{
	lli N; cin >> N;
	int S = cal(N);
	cout << (N%S==0 ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
T = list(map(int,input().split()))
M = int(input())
x = []
y = []
for i in range(M):
    x1,y1 = list(map(int,input().split()))
    x.append(x1)
    y.append(y1)
S = sum(T)
def gori(i):
    v = S - int(T[x[i]-1]) + int(y[i])
    return v
for ans in map(gori, range(M)):
    print(ans)
# print(N)
# print(T)
# print(M)
# print(x)
# print(y)
# print(S)






Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long n,m;
    cin >> n >> m;
    cout << (n-1)*(m-1) << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 3564
n,m = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
sx = 0
sy = 0
for i in range(1,n+1):
    sx += (x[i - 1]*(i - 1)) - (x[i - 1] * (n - i))
for s in range(1,m+1):
    sy += (y[s - 1]*(s - 1)) - (y[s - 1] * (m - s))
print(abs(sx * sy)%1000000007)

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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  ll k;
  cin >> s >> k;
  for (int i = 0; i < k; i++) {
    if (s[i] != '1') {
      cout << s[i] << '\n';
      return 0;
    }
  }
  cout << 1 << '\n';
  return 0;
}


Measured memory_bytes: 256
using System;

namespace abc079_b
{
    class Program
    {
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            long[] ret = new long[n + 1];
            ret[0] = 2; ret[1] = 1;
            for (long i = 2; i <= n; i++)
            {
                ret[i] = ret[i - 1] + ret[i - 2];
            }
            Console.WriteLine(ret[n]);
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second < secondElof.second;
}
ll nod(ll F) { return log10(F) + 1; }
//**定義場所**//
//gcd, isPrime, eratos, modinv, bitSearch, dfs, bfs, dijkstra, UnionFind, COM//
ll i, j, k, l, m, n; ll N, M, K, H, W, L; string S;
ll MOD = 1000000007; ll ans = 0; ll INF = 9999999999999;
vl flag, color; vll path;
//***********//

int main() {
	cin >> H >> W >> N;
	ll M = max(H, W);
	cout << (N - 1) / M + 1;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.StringTokenizer;


public class Main {
    static final int INF = (int) 1e9;

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        int[] a = sc.nextIntArray(n);
        int l = -INF;
        int r = INF;
        long ans = Long.MAX_VALUE;
        while (l <= r) {
            int mid1 = l + (r - l) / 3;
            int mid2 = r - (r - l) / 3;
            long one = calc(a, mid1);
            long two = calc(a, mid2);
            if (one < two) r = mid2 - 1;
            else l = mid1 + 1;
            ans = Math.min(ans, Math.min(one, two));
        }
        out.println(ans);
        out.flush();
        out.close();
    }

    static long calc(int[] a, int b) {
        long ans = 0;
        for (int i = 0; i < a.length; i++) {
            ans += Math.abs(a[i] - (b + i));
        }
        return ans;
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream system) {
            br = new BufferedReader(new InputStreamReader(system));
        }

        public Scanner(String file) throws Exception {
            br = new BufferedReader(new FileReader(file));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

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

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

        public char nextChar() throws IOException {
            return next().charAt(0);
        }

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

        public boolean ready() throws IOException {
            return br.ready();
        }

        public void waitForInput() throws InterruptedException {
            Thread.sleep(3000);
        }

        public int[] nextIntArray(int n) throws IOException {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public Integer[] nextIntegerArray(int n) throws IOException {
            Integer[] a = new Integer[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public double[] nextDoubleArray(int n) throws IOException {
            double[] ans = new double[n];
            for (int i = 0; i < n; i++)
                ans[i] = nextDouble();
            return ans;
        }

    }
}


Measured memory_bytes: 47612
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;
using vll = vector<long long>;
using vvll = vector<vll>;
const double EPS = 1e-9;
const long long MOD=1e9+7;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define SZ(x) ((int)(x).size())
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
  ll n,k; cin>>n>>k;
  vll a(n); rep(i,n) cin>>a[i];
  vll dp(k+1);
  REP(i,0,k+1){
    REP(j,0,n){
      if(i<a[j]) continue;
      if(dp[i-a[j]]==0) dp[i]=1;
    }
  }
  if(dp[k]) cout<<"First"<<endl;
  else cout<<"Second"<<endl;
}

Measured memory_bytes: 4024
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - String Transformation

            //変換前と変換後の文字列を配列に
            var s = Console.ReadLine().ToCharArray();
            var t = Console.ReadLine().ToCharArray();

            //変換前の文字列を、1文字ずつ変換後に一致させていく
            for(int i = 0; i < s.Length; i++)
            {
                char before = s[i];
                char after = t[i];

                if (before != after)
                {
                    //今の文字よりも前に変換対象があれば、その時点でNG
                    //(すでにTと一致させているのに、再度変換することになるので)
                    for(int j = 0; j < i; j++)
                    {
                        if (s[j] == before | s[j] == after)
                        {
                            Console.WriteLine("No");
                            return;
                        }
                    }

                    //今の文字より後だけ変換
                    for (int j = i; j < s.Length; j++)
                    {
                        if (s[j] == before)
                        {
                            s[j] = after;
                        }
                        else if (s[j] == after)
                        {
                            s[j] = before;
                        }
                    }
                }
            }

            //最後まで変換できれば、SとTは一致しているはず
            Console.WriteLine("Yes");            
        }
    }
}

Measured memory_bytes: 13280
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>
#include <cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;

inline bool check(ll x, ll y, ll xMax, ll yMax) { return x >= 0 && y >= 0 && xMax > x && yMax > y; }
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string tostring(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }
template<class T> inline T mypow(T x, ll n) { T res = 1; while (n > 0) { if (n & 1)res = res * x;	x = x * x;	n >>= 1; }return res; }
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

#define For(i,a,b)	for(ll (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define rFor(i,a,b)	for(ll (i) = (a-1);i >= (b);(i)--)
#define rrep(i,n)	rFor(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define tostr(a)	tostring(a)
#define dump(val) 	cerr << #val " = " << val << endl;
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

const ll dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = 1e17 + 9;

#define int ll
#define double ld

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

	string s;
	cin >> s;

	int n = s.size();
	rep(i, n) {
		if (i + 1 < n && s[i] == s[i + 1]) {
			cout << i + 1 << " " << i + 2 << endl;
			return 0;
		}
		if (i + 2 < n && s[i] == s[i + 2]) {
			cout << i + 1 << " " << i + 3 << endl;
			return 0;
		}
	}
	cout << -1 << " " << -1 << endl;

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define mt make_tuple
#define show(x) cout<<x<<'\n'
#define showh(x) cout<<x<<' '
#define go(i,a,n) for(ll i=a;i<n;i++)
#define gor(i,a,n) for(ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define mod 1000000007
bool prime[100001];
bool ispoweroftwo(ll x)
{
    return x && !(x & (x-1));
}
ll xorcal(ll n)
{
    if(n%4==0)
        return n;
    if(n%4==1)
        return 1;
    if(n%4==2)
        return n+1;
    if(n%4==3)
        return 0;
}
void sieve(ll n)
{
    memset(prime,true,sizeof(prime));
    prime[0]=false;
    prime[1]=false;
    for(ll i=2;i*i<=n;i++)
    {
        if(prime[i]==true)
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                prime[j]=false;
            }
        }
    }
    show(prime[89]);
}
bool isprime(ll n)
{
    if (n<=1) return false;
    if (n<=3) return true;

    if(n%2==0 or n%3==0) return false;

    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0 or n%(i+2)==0) return false;
    }
    return true;
}

ll modinverse(ll a,ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m; a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
       x += m0;

    return x;
}

ll gcd(ll a,ll b)
{
    if(a==0)
    {
        return b;
    }
    return(b%a,a);
}

ll power(ll A, ll B)
{
    if (A == 0)
        return 0;
    if (B == 0)
        return 1;

    ll y;
    if (B % 2 == 0) {
        y = power(A, B / 2);
        y = (y * y) % mod;
    }

    else {
        y = A % mod;
        y = (y * power(A, B - 1) % mod) % mod;
    }

    return (ll)((y + mod) % mod);
}
ll ncr(ll n,ll r)
{
    if(r==0 or n==r)
    {
        return 1;
    }
    return (ncr(n-1,r-1)%mod + (ncr(n-1,r))%mod)%mod;
}

int main()
{
    ios_base::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    ll m=n-k;
    ll l[2001][2001]={0};
    l[0][0]=1;
    go(i,1,2001)
    {
        l[i][0]=1;
        go(j,1,i+1)
        {
            l[i][j]= ((l[i-1][j] % mod) + (l[i-1][j-1] % mod)) % mod;
        }
    }
    go(i,1,k+1)
    {
        show( ((l[k-1][i-1] % mod) * (l[m+1][i] % mod)) % mod );
    }
    return 0;
}


Measured memory_bytes: 31616
#include <iostream>
using namespace std;
#define m 1000000007

int main() {
	
	int h,w;
	cin>>h>>w;
	char arr[h][w];
	int c[h][w]={0};
	for(int i=0;i<h;i++){
	    for(int j=0;j<w;j++){
	        cin>>arr[i][j];
	    }
	}
	for(int j=0;j<w;j++){
	    if(arr[0][j]=='#')
	        break;
	    c[0][j]=1;
	}
	for(int i=0;i<h;i++){
    	if(arr[i][0]=='#')
	        break;
	    c[i][0]=1;
	}
	for(int i=1;i<h;i++){
	    for(int j=1;j<w;j++){
	        if(arr[i][j]=='#')
	            continue;
	        if(arr[i-1][j]=='#')
	            c[i][j]=c[i][j-1]%m;
	        else if(arr[i][j-1]=='#')
	            c[i][j]=c[i-1][j]%m;
	        else
	            c[i][j]=(c[i-1][j]+c[i][j-1])%m;
	    }
	}
	cout<<c[h-1][w-1]<<endl;
}

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

using namespace std;
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 29)

using Pi = pair<int, int>;

string to_string(string s) {
  return s;
}

template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

template <class S>
string to_string(unordered_set<S> s) {
  string ret = "{";
  for (S x : s)
    ret += to_string(x) + ",";
  return ret + "}";
}

template <class S, class T>
string to_string(map<S, T> m) {
  string ret = "{";
  for (pair<S, T> x : m)
    ret += to_string(x) + ",";
  return ret + "}";
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < (int)v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

int V, E, T;
vector<vector<Pi>> G;
vector<vector<int>> orders;
using Ppi = pair<int, pair<int, int>>;

vector<Ppi> get_path(int s, int g) {
  vector<int> d(V, INF), prev(V, -1);
  vector<bool> used(V);
  priority_queue<Ppi, vector<Ppi>, greater<Ppi>> q;
  q.push(Ppi(0, Pi(-1, s)));
  while (!q.empty()) {
    Ppi t = q.top();
    q.pop();
    int l = t.first;
    int from = t.second.first;
    int v = t.second.second;
    if (used[v])
      continue;
    used[v] = 1;
    d[v] = l;
    prev[v] = from;
    if (g == v)
      break;
    for (Pi e : G[v]) {
      if (d[e.second] > l + e.first) {
        q.push(Ppi(l + e.first, Pi(v, e.second)));
      }
    }
  }
  vector<Ppi> ret;
  int now = g;
  while (now != s) {
    ret.push_back(Ppi(d[now] - d[prev[now]], Pi(prev[now], now)));
    now = prev[now];
  }
  return ret;
}

int main() {
  cin >> V >> E;
  G.resize(V);
  FOR(i, E) {
    int u, v, d;
    cin >> u >> v >> d;
    G[u - 1].emplace_back(d, v - 1);
    G[v - 1].emplace_back(d, u - 1);
  }
  cin >> T;
  orders.resize(T);
  int now = 0;
  vector<int> actions(T * 4, -1);
  FOR(i, T) {
    int Nnew;
    cin >> Nnew;
    FOR(j, Nnew) {
      int new_id, dst;
      cin >> new_id >> dst;
      orders[i].push_back(dst - 1);
      if (now <= i) {
        vector<Ppi> ret = get_path(0, dst - 1);
        now = i;
        for (int a = ret.size() - 1; a >= 0; --a) {
          FOR(b, ret[a].first) { actions[now++] = ret[a].second.second + 1; }
        }
        for (int a = 0; a < ret.size(); ++a) {
          FOR(b, ret[a].first) { actions[now++] = ret[a].second.first + 1; }
        }
      }
    }
  }
  FOR(i, T) { cout << actions[i] << endl; }
  return 0;
}

Measured memory_bytes: 896
#include <stdio.h>
#include <string.h>

int main(void) {
	char str[20],def;
	int i,j,z;

	scanf("%s", str);
	z = strlen(str);
	j = z;

	for (i = 0; i<z / 2; i++,j--){
		def = str[i];
		str[i] = str[j-1];
		str[j-1] = def;
	}

	printf("%s\n", str);

	return 0;
}

Measured memory_bytes: 524
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    H, W, m = map(int, input().split())
    H_list = [0] * H
    W_list = [0] * W
    bomb = []
    for _ in range(m):
        h_, w_ = map(lambda x: int(x) - 1, input().split())
        H_list[h_] += 1
        W_list[w_] += 1
        bomb.append([h_, w_])

    ma = max(H_list) + max(W_list)
    cnt_H = Counter(H_list)
    cnt_W = Counter(W_list)
    cnt = 0
    for k, v in cnt_H.items():
        if cnt_W.get(ma - k) is not None:
            cnt += v * cnt_W[ma - k]

    for h, w in bomb:
        total = H_list[h] + W_list[w]
        if total == ma:
            cnt -= 1
    if cnt:
        print(ma)
    else:
        print(ma - 1)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 59204
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define pb push_back
#define fst first
#define snd second

typedef long long ll;
typedef pair<int,int> pii;
template<typename T> using min_queue=priority_queue<T,vector<T>,greater<T>>;

const ll MOD=1e9+7;

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

    int X;cin>>X;
    int d = gcd(X,180);
    int res = 180/d;
    if ((X/d)%2 == 1) res *= 2;
    cout << res << '\n';
    return 0;
}


Measured memory_bytes: 3592
def main():
    N = int(input())
    F = [0 for _ in range(N)]
    for i in range(N):
        F[i] = list(map(int, input().split()))
    P = [0 for _ in range(N)]
    for i in range(N):
        P[i] = list(map(int, input().split()))

    cost = []
    for i in range(1,2**10):
        cost_i = 0
        k = i
        now = ""
        for _ in range(10):
            now += str(k%2)
            k = k//2
        for n in range(N):
            ci = 0
            for j in range(10):
                if int(now[j])==F[n][j]==1:
                    ci += 1
            cost_i += P[n][ci]
        cost.append(cost_i)

    return max(cost)

if __name__ == '__main__':
    print(main())



Measured memory_bytes: 3064
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n,x,t] <- getIntList
    let ans = t * ((n-1) `div` x + 1)
    print ans


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

int main() {
  int A,B,K;
  cin >> A >> B >> K;
  int i=0;
  int j=A+1;
  while(i!=K){
    j--;
    if(A%j==0&&B%j==0){
      i++;
    }
  }
  cout << j << endl;
}


Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, s, n) for(int i = s; i < n; i++)
using namespace std;
using P = pair<int, int>;

int main(){
  int n, k;
  cin >> n >> k;
  int m = min(n, k);
  deque<int> deq;
  rep(i, n){
    int v;
    cin >> v;
    deq.push_back(v);
  }
  int ans = 0;
  rep(i, m+1)rep(j, i+1){
    deque<int> dq(deq);
    priority_queue<int, vector<int>, greater<int>> que;
    rep(a, j){
      int x = dq.front();
      dq.pop_front();
      que.push(x);
    }
    rep(b, i-j){
      int x = dq.back();
      dq.pop_back();
      que.push(x);
    }
    rep(c, k-i){
      if (que.empty()) break;
      if (que.top() < 0) que.pop();
    }
    int sum = 0;
    while(!que.empty()){
      sum += que.top();
      que.pop();
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3544
#include<bits/stdc++.h>
#define INF (1e9)
#define N 5005
using namespace std;
typedef pair<int,int> P;
int n,k,C[N][N];
vector<int> G[N];
P cr[N];

void bnf(int s){
  queue<P> q;
  int d[N];
  for(int i=0;i<N;i++)d[i]=INF;
  d[s]=0;
  q.push(P(s,0));
  while(!q.empty()){
    P t=q.front(); q.pop();
    int node=t.first;
    int cost=t.second;
    for(int i=0;i<G[node].size();i++){
      int nnode=G[node][i];
      if(d[nnode]==INF){
	d[nnode]=cost+1;
	q.push(P(nnode,d[nnode]));
      }
    }
  }
  for(int i=0;i<n;i++)
    if(i!=s&&d[i]<=cr[s].second)
      C[s][i]=cr[s].first;
}

int dijkstra(){
  priority_queue<P,vector<P>,greater<P> > q;
  int d[N];
  for(int i=0;i<N;i++)d[i]=INF;
  d[0]=0;
  q.push(P(0,0));
  while(!q.empty()){
    P t=q.top(); q.pop();
    int cost=t.first;
    int node=t.second;
    if(d[node]<cost)continue;
    for(int i=0;i<n;i++){
      int nnode=i;
      int ncost=cost+C[node][nnode];
      if(node==i)continue;
      if(d[nnode]>ncost){
	d[nnode]=ncost;
	q.push(P(d[nnode],nnode));
      }
    }
  }
  return d[n-1];
}

int main(){
  cin>>n>>k;
  for(int i=0;i<n;i++)
    cin>>cr[i].first>>cr[i].second;
  int a,b;
  for(int i=0;i<k;i++){
    cin>>a>>b;
    a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)C[i][j]=INF;
  for(int i=0;i<n;i++)bnf(i);
  cout<<dijkstra()<<endl;
  return 0;
}

Measured memory_bytes: 101348
<?php

main();

function main() {
	while(true) {
		$input = getInput();
		if (empty($input)) {
			break;
		}
		list($x, $y) = solveArray($input);
		printSolution($x, $y);
	}
}

function printSolution($x, $y) {
	$x = round($x, 3);
	$y = round($y, 3);
	printf("%.3f %.3f\n", $x, $y);
}

function getInput() {
	$line = trim(fgets(STDIN));
	if (empty($line)) {
		return array();
	}
	return explode(' ', $line);
}

function solveArray(array $data) {
	if (count($data) != 6) {
		return null;
	}
	return solve($data[0], $data[1], $data[2], $data[3], $data[4], $data[5]);
}

function solve($a, $b, $c, $d, $e, $f) {
	$x = det2($c, $b, $f, $e) / det2($a, $b, $d, $e);
	$y = det2($a, $c, $d, $f) / det2($a, $b, $d, $e);
	return array($x, $y);
}

function det2($a, $b, $c, $d) {
	return $a * $d - $b * $c;
}

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

int main(){
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;

  int sum = a * x + b * y;
  for(int i = 0; i <= max(x, y); i++){
    int res = (a * x + b * y) - (a * min(i, x) + b * min(i, y)) + (2 * i * c);
    if(res < sum){sum = res;}
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
void trace(int A[], int N)
{
	for (int i = 0; i < N; i++)
	{
		if (i > 0)
			cout << " ";
		cout << A[i];
	}
	cout << "\n";
}
void insertionSort(int A[], int N)
{
	for (int i = 1; i < N; i++)
	{
		int v = A[i];
		int j = i - 1;
		while (j >= 0 && A[j] > v)
		{
			A[j + 1] = A[j];
			j--;
		}
		A[j+1] = v;
		trace(A, N);
	}
	
}
int main()
{
	int N,i;
	int A[100];
	cin >> N;
	for (i = 0; i < N; i++)
	{
		cin >> A[i];
	}
	trace(A, N);
	insertionSort(A, N);
	return 0;

}


Measured memory_bytes: 3132
N = int(input())
L = list(map(int, input().split()))
ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            x, y, z = L[i], L[j], L[k]
            if x != y and x != z and y != z:
                if max(x, y, z) < x + y + z - max(x, y, z):
                    ans += 1
print(ans)

Measured memory_bytes: 68312
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep2(i,start,end) for(ll i = start; i < end; ++i)
#define dwn(i,n) for(int i = n; i >= 0; --i)
#define dwn2(i,start,end) for(ll i = start; i >= end; --i)
#define pll pair<ll,ll>
#define mk(x,y) make_pair(x,y)
#define pdl pair<double, ll>
const ll N = 4e5 + 200;
const ll INF = 0x3f3f3f;
const ll mode = 1e9 + 7;


int main(){
	ll a,b;
	cin>>a>>b;
	ll sum = 0;
	for(int i = 0; i <= 20; i++){
		int tmp = i*a-i+1;
		if(tmp >= b){
			sum = i;
			break;
		}
	}
	cout<<sum<<endl;

	return 0;
}








Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10; 
int f[N];
int get(int x){
	if(f[x]!=x)f[x]=get(f[x]);
	return f[x];
} 
int main(){
	int n,m,x,y,ans=0;
	cin>>n>>m;
	for(int i=1;i<=n;i++)f[i]=i;
	for(int i=1;i<=m;i++){
		cin>>x>>y;
		int f1=get(x),f2=get(y);
		if(f1!=f2){
			ans++,f[f1]=f2;
		}
	}
	printf("%d\n",n-1-ans);
}

Measured memory_bytes: 4108
#include <iostream>
#include <map>

int main() {
    unsigned int N, W; std::cin >> N >> W;
    std::map<unsigned int /* w */, unsigned int /* v */> m;
    m.insert(std::make_pair(0, 0));
    for (unsigned int i = 0; i < N; i++) {
        unsigned int w, v; std::cin >> w >> v;
        decltype(m) mm(m);
        for (const auto& l: mm) {
            auto nw = l.first + w;
            if (nw > W) {
                continue;
            }
            auto nv = l.second + v;
            const auto f = m.find(nw);
            if (f == m.end() || nv > f->second) {
                m[nw] = nv;
            }
        }
    }

    unsigned int mm = 0;
    for (const auto& l: m) {
        mm = std::max(mm, l.second);
    }

    std::cout << mm << std::endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
using namespace std;
int main(void)
{ 
long long int n,m,a,mod;
  mod=1000000000+7;
  int i;
  cin>>n>>m;
  a=1;
  if(n-m>1||n-m<-1){cout<<0;return 0;}
  for(i=1;i<=n;i++){a=a*i;a=a%mod;}
  for(i=1;i<=m;i++){a=a*i;a=a%mod;}
  if(n==m)a=2*a;
  a=a%mod;
  cout<<a;
  
}

Measured memory_bytes: 3596
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <tuple>

using namespace std;

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

    tuple<int, int, int> data[M];
    // (Y_i, P_i, i)の配列

    for (int i = 0; i < M; ++i) {
        int p, y;
        cin >> p >> y;
        data[i] = make_tuple(y, p, i);
    }

    // tupleをソートするときは第一要素がkeyとなる
    // つまりY_iによって昇順にソートされる
    sort(data, data + M);

    int cnt[N + 1];
    fill(cnt, cnt + N + 1, 0);
    // 各県に今属している市の数

    pair<int, int> id[M];
    // 各市の(属する県、県の中で誕生した順番)

    for (int i = 0; i < M; ++i) {
        int y, p, idx;
        tie(y, p, idx) = data[i];
        ++cnt[p];
        id[idx] = make_pair(p, cnt[p]);
    }

    for (int i = 0; i < M; ++i) {
        // setwで文字数、setfillで埋める文字を指定
        // iomanipをincludeする必要があるので注意
        cout << setw(6) << setfill('0') << id[i].first;
        cout << setw(6) << setfill('0') << id[i].second << endl;
    }
    return 0;
}

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

using namespace std;

#define int long long

const int mod = 1e9 + 7;

typedef pair<int, int> ii;
map<ii, int> mp;

int n;
ii a[200001];
int pow_2[200001];

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	pow_2[0] = 1;
	for (int i = 1; i <= 200000; i++)
		pow_2[i] = pow_2[i - 1] * 2 % mod;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i].first >> a[i].second;
		if (!a[i].first && !a[i].second)
			ans++;
		else if (!a[i].first)
			mp[ii(0, 1)]++;
		else if (!a[i].second)
			mp[ii(1, 0)]++;
		else
		{
			int g = __gcd(a[i].first, a[i].second);
			int x, y;
			x = a[i].first / g, y = a[i].second / g;
			if (y < 0)
			{
				x *= -1;
				y *= -1;
			}
			mp[ii(x, y)]++;
		}		
	}
	int cur = (pow_2[mp[ii(1, 0)]] + pow_2[mp[ii(0, 1)]] - 1)%mod;
	for (int i = 1; i <= n; i++)
		if (a[i].first && a[i].second)
		{
			int g = __gcd(a[i].first, a[i].second);
			int x, y;
			x = a[i].first / g, y = a[i].second / g;
			if (y < 0)
			{
				x *= -1;
				y *= -1;
			}
			int tmp = pow_2[mp[ii(x, y)]];
			mp[ii(x, y)] = 0;
			x = -a[i].second / g, y = a[i].first / g;
			if (y < 0)
			{
				x *= -1;
				y *= -1;
			}
			(tmp += pow_2[mp[ii(x, y)]]) %= mod;
			mp[ii(x, y)] = 0;
			tmp = (tmp - 1 + mod)%mod;
			(cur *= tmp) %= mod;
		}
	cout << ((ans + cur)%mod - 1 + mod)%mod;	
}

Measured memory_bytes: 33304
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

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

def print_l(l):
    print(' '.join(map(str, l)))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

s = s_in()

if s == 'BBB' or s == 'AAA':
    print("No")
else:
    print("Yes")


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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    ll N;
    ll mini = LONG_LONG_MAX;
    vector<ll> L;
    cin >> N;
    L.resize(N);
    cin >> L[0];
    for(ll i = 1;i < N;i++) {
        ll temp;
        cin >> temp;
        L[i] = L[i - 1] + temp;
    }
    for(ll i = 0;i < N - 1;i++) {
        ll temp = abs(L.back() - 2 * L[i]);
        mini = min(mini, temp);
    }
    cout << mini << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <iostream>
#include <climits>
#include <map>
#include <cmath>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <vector>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <utility>
#include <queue>
 
using namespace std;

#define ll long long
#define ulli  unsigned ll int
#define sl(n) scanf("%lld", &n)
#define sl2(a,b) scanf("%lld%lld", &a,&b)
#define sl3(a,b,c) scanf("%lld%lld%lld", &a,&b,&c)
#define VI  vector<int>
#define Vll  vector<ll>
#define all(v)  v.begin(),v.end()
#define ub(v,x)  upper_bound(all(v),x)

int st(int x,int pos){  return x= x |(1<<pos);}
int  Reset(int x,int pos ){ return x= x &~(1<<pos);}

#define  si(n) scanf("%d", &n)
#define  si2(a,b) scanf("%d%d", &a,&b)
#define  si3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define  sf(n) scanf("%lf", &n)
#define  pii pair <int, int>
#define  pll pair <ll, ll>
#define  plp pair <int, pll >
#define  pb push_back
#define  mkpr  make_pair
#define  ff   first
#define  ss  second
#define  srt(V)  sort(V.begin(),V.end());
#define  rsrt(V)  sort(V.rbegin(),V.rend());
#define  nl printf("\n");   
#define  PI  2*acos(0.0);
#define  INFP ((ll)1<<62)
#define  INFN (0-(ll)1<<62)
#define  loop(a,b)  for(int g=a;g<=b;g++)
#define  for1(n)  for(int i=0;i<n;i++)
#define  for2(n)  for(int j=0;j<n;j++)
#define  for3(n)  for(int k=0;k<n;k++)
#define  for4(n)  for(int l=0;l<n;l++)
#define  fr(i,a,b) for(int i=a;i<=b;i++)
#define  bug1(a)  cout<<a<<endl;
#define  bug2(a,b)  cout<<a<<" "<<b<<endl;
#define  bug3(a,b,c)  cout<<a<<" "<<b<<" "<<c<<endl;
#define  bug4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;

#define  tst(n)  for(int cs=1;cs<=n;cs++)
#define  spc <<" "<<
#define  pys puts("YES");
#define  pno  puts("NO");
#define  bug puts("bug");
#define  pmn puts("-1");
#define  zero puts("0");
#define  limit 200006
#define  md 1000000007
#define  sq(n)  n*n





typedef pair<ll,ll> iPair;

ll A[limit],frq[limit],keep[limit];
int main()
{
 
             /*  
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);*/

        memset(frq,0,sizeof frq);
        ll n;

        cin>>n;

        fr(i,1,n)
        {

          ll a;

          sl(a);
          A[i]=a;
          frq[a]++;
        }


        ll ans=0;

        fr(i,1,n)
        {

          keep[i]=frq[A[i]]-1;
          ans+=keep[i];

        }

        fr(i,1,n)
        {

          cout<<ans/2-keep[i]<<endl;
        }

       
     




       // cout<<ans<<endl;
    

 

        /**
       *    @author     : Ikbal Hossain
       *    @University  : RUET CSE 15
       *    @CodeForces : iAmrifat
       *    @UVA        : rifat_ikbal
       *    @facebook   : https://www.facebook.com/ikbal.rifat.5
       */
 
      /* ll dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; */ // 4 Direction
      /* ll dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1}; */ // 8 Direction
      /* ll dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; */ // Knight Direction
      /* ll dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; */ // Hexagonal Direction
 
}
 
 
 


Measured memory_bytes: 8320