akhauriyash/Code-Regression huggingface dataset:
import sys

H, W = ( int(i) for i in input().split() )
S = [input() for i in range(H)]

cc = 0
for ss in S:
    for st in ss:
        if st == ".":
            cc += 1

for i in range(len(S)):
    S[i] = "#" + S[i] + "#"

temp = ["#" * (W + 2)]
S = temp + S + temp

dd = [[float("inf")] * W for i in range(H)]

def DFS(a, b, d):
    dd[a-1][b-1] = d
    for x, y in [(a+1, b), (a-1, b), (a, b+1), (a, b-1)]:
        if S[x][y] == "#":
            continue
        else:
            if dd[x-1][y-1] > d + 1:
                DFS(x, y, d + 1)

sys.setrecursionlimit(10000)

DFS(1,1,0)
if dd[H-1][W-1] != float("inf"):
    print(cc - dd[H-1][W-1] -1)
else:
    print("-1")

Measured memory_bytes: 72540
#include <stdio.h>
#include <stdlib.h>

#define MAX 100

int h, w;

void swapCol (char grid[][MAX]) {
	for (int col=0; col<h; col++) {
		int num=0;
		for (int row=0; row<w; row++) {
			if (grid[col][row] == '.')
				num ++;
		}
		if (num == w) {
			char tmp[MAX];
			for (int row=0; row<w; row++)
				tmp[row] = grid[col][row];
			for (int cc=col; cc<h-1; cc++) 
				for (int row=0; row<w; row++)
					grid[cc][row] = grid[cc+1][row];
			for (int row=0; row<w; row++)
				grid[h-1][row] = tmp[row];
			h -= 1;
			swapCol (grid);
			break;
		}
	}
	return;
}

void swapRow (char grid[][MAX]) {
	for (int row=0; row<w; row++) {
		int num=0;
		for (int col=0; col<h; col++) {
			if (grid[col][row] == '.')
				num ++;

		}
		if (num == h) {
			char tmp[MAX];
			for (int col=0; col<h; col++)
				tmp[col] = grid[col][row];
			for (int rr=row; rr<w-1; rr++) 
				for (int col=0; col<h; col++)
					grid[col][rr] = grid[col][rr+1];
			for (int col=0; col<h; col++)
				grid[col][w-1] = tmp[col];
			w -= 1;
			swapRow (grid);
			break;
		}
	}
	return;
}




int main () {
	char grid[MAX][MAX];
	int h2, w2;

	scanf ("%d %d", &h, &w);
	h2 = h; w2 = w;

	for (int i=0; i<h; i++)
		scanf ("%s", grid[i]);

	swapCol (grid);
	swapRow (grid);

	
	for (int col=0; col<h; col++)  {
		for (int row=0; row<w; row++)
			putchar (grid[col][row]);
		printf ("\n");
	}
	
	/*
	for (int col=0; col<h2; col++)  {
		for (int row=0; row<w2; row++)
			putchar (grid[col][row]);
		printf ("\n");
	}
	*/

	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ft first
#define sd second
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,k=0;
    cin>>n;
    vector<int> w(n);
    fr(i,n){
        cin>>w[i];
        k+=w[i];
    }
    int ans=k,t=0;
    fr(i,n){
        t+=w[i];
        ans=min(ans,abs(k-2*t));
    }
    cout<<ans<<endl;
}

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

int main() {
    int n;
    cin >> n;
    vector<ll> a(n); 
    rep(i,n) cin >> a[i];
    ll mn = 99999999999;
    int cnt = 0;
    ll ans = 0;
    rep(i,n){
        if(a[i]<0) cnt++;
        mn = min(mn,abs(a[i]));
        ans+=abs(a[i]);
    }
    if(cnt%2) cout << ans-mn*2 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3988
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
  ll A, B, C, K; cin >> A >> B >> C >> K;

  ll ans = 0, rest = K;

  ans += min(A, rest); rest -= min(A, rest);
  rest -= min(B, rest);
  if (rest == 0){
    cout << ans << endl;
    return 0;
  }

  ans -= rest;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;

typedef long long ll;
// const int INF = 1e8;
const ll INF = 1LL << 60;
typedef pair<int, int> P;

int A, B;

int main() {
    cin >> A >> B;

    for (int i = 1; i <= 1000; i++) {
        if ((int)(i * 0.08) == A && (int)(i * 0.1) == B) {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;
}

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

int main() {
  int N,p=0;
  string pwgy;
  cin >> N;
  for (int i = 0; i < N; i++)
  {
    cin >> pwgy;
    if(pwgy == "Y"){
      p++;
    }
  }
  if(p > 0){
    cout << "Four";
  }else{
    cout << "Three";
  }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int N;
    cin>>N;
    int count=0;
    int color=0;
    for(int i=0;i<N;i++){
        int a;
        cin>>a;
        if(i==0){
            color=a;
        }
        else if(i>0){
            if(a==color){
                count+=1;
                color=0;
            }
            else{
                color=a;
            }
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <math.h>
#include <map>
#include <stack>
using namespace std;
static const int INF = 1e9+7;
// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (int i =a; i < b; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define PI 3.14159265359

int main(){
    int n; cin >> n;
    vector<int> d(n);
    rep(i,n) cin >> d[i];
    sort(all(d));
    int cnt = 1;
    rep(i,n-1){
        if(d[i] != d[i+1]) cnt++;
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3576
from math import gcd 
from collections import defaultdict

def to_irreducible(a, b):
    if a == 0:
        return (0, 1)
    GCD = gcd(a, b)
    return (a//GCD, b//GCD)

MOD = 10**9 + 7
N = int(input())
quadrant1 = defaultdict(int)
quadrant2 = defaultdict(int)
zero_cases = 0

for i in range(N):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        zero_cases += 1
    elif a * b >= 0 and b != 0:
        irr = to_irreducible(abs(a), abs(b))
        quadrant1[irr] += 1
    else:
        irr = to_irreducible(abs(b), abs(a))
        quadrant2[irr] += 1
        quadrant1[irr] += 0

ans = 1 
for key, v1 in quadrant1.items():
    v2 = quadrant2[key]
    ans *= (2**v1 + 2**v2 -1)
    ans %= MOD
print((ans+zero_cases-1) % MOD)

Measured memory_bytes: 168232
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll n, m;
  cin >> n >> m;
  vector<ll> a(n);

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

  ll cnt = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] * 4 * m >= total) {
      cnt++;
    }
  }

  string ans = "No";
  if (cnt >= m) {
    ans = "Yes";
  }
  cout << ans << ln;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;

unsigned long long int a = 0, b = 0, c = 1, x = 0, y = 0, z = 0, maxy = 0, mini = 9999, counter = 0;
std::vector<unsigned long long int> vec{}, vecsec{};
unsigned long long int iremono[100000],sheet[100000];
std::vector<std::string>str{};

bool okada = false;
std::string output, output2, input, nyahhoi;
char kakunou[101][101] = {};
int kakunou2[50][50] = {};
int ctoi(const char c) {
	if ('0' <= c && c <= '9') return (c - '0');
	return -1;
}
unsigned long long int LCM(unsigned long long int a, unsigned long long int b) {
	unsigned long long int i, j;
	i = a; j = b;
	while (true) {

		c = i % j;
		i = j;
		if (c != 0) {

			j = c;

		}
		else {
			break;
		}
	}
	return j * (a / j) * (b / j);
}
int main()
{
	cin >> a;
	sheet[a]++;
	while (true) {
		x++;
		if (a % 2 == 0) {
			a /=2;
		}
		else {
			a = a * 3 + 1;
		}
		
		if (sheet[a] == 1) {
			x++;
			break;
		}
		else {

			sheet[a]++;
		}
	}
	cout << x << endl;
	}









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

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

    string S;
    cin >> S;
    bool playable = true;
    for (int i = 0; i < S.length() && playable; i++) {
        if (i % 2 == 0 && S[i] == 'L')
            playable = false;
        else if (i % 2 == 1 && S[i] == 'R')
            playable = false;
    }
    cout << (playable ? "Yes\n" : "No\n");

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(char &c){
  int i;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i, sz=0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
char S[100002];
int N;
int cnt[26];
int main(){
  char res;
  int i;
  N = rd(S);
  for(i=0;i<(N);i++){
    cnt[S[i]-'a']++;
  }
  for(i=0;i<(26);i++){
    if(cnt[i]==0){
      res = 'a' + i;
      break;
    }
  }
  if(i==26){
    wt_L("None");
    wt_L('\n');
  }
  else{
    wt_L(res);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190822-2

// --- original code ---
// char S[100002];
// int N;
// 
// int cnt[26];
// {
//   int i;
//   char res;
//   rd(S@N);
//   rep(i,N) cnt[S[i]-'a']++;
//   rep(i,26) if(cnt[i]==0) res = 'a' + i, break;
//   wt( if[i==26, "None", res] );
// }


Measured memory_bytes: 384
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

fn main() {
    input! {
        x: [i64;5],
    }

    for i in 0..5 {
        if x[i] == 0 {
            println!("{}", i + 1);
            return;
        }
    }
}


Measured memory_bytes: 2136
#include <iostream>
#include <algorithm>
#include <stack>
#include <vector>

constexpr int MAX = 2 * 1e5 + 10, INF = 1e9 + 100;

int a[MAX], dp[MAX], ans[MAX], max;

std::stack<int> stack;

std::vector<int> tree[MAX];
bool used[MAX];

int n;

void dfs(int v)
{

    int next = std::lower_bound(dp, dp + n, a[v]) - dp;

    stack.emplace(dp[next]);

    dp[next] = a[v];

    stack.emplace(max);

    max = std::max(max, next);

    ans[v] = max;

    used[v] = 1;

    for (int ch : tree[v])
    {
        if (!used[ch])
            dfs(ch);
    }

    used[v] = 0;

    max = stack.top();
    stack.pop();
    dp[next] = stack.top();
    stack.pop();
}

int main()
{

    std::cin >> n;

    for (int i = 1; i <= n; ++i)
        std::cin >> a[i];

    for (int i = 0; i < n - 1; ++i)
    {
        int u, v;
        std::cin >> u >> v;
        tree[u].push_back(v);
        tree[v].push_back(u);
    }

    for (int i = 1; i <= n; ++i)
        dp[i] = INF;

    dfs(1);

    for (int i = 1; i <= n; ++i)
        std::cout << ans[i] << std::endl;

    return 0;
}

Measured memory_bytes: 26380
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int A, B;
    cin >> A >> B;
    int K = (A + B) / 2;
    if((A + B) % 2){
        cout << "IMPOSSIBLE" << endl;
    }
    else{
        cout << K << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long 
#define ld long double
long long const inf = 1e18;
int const mxn = 2e4+10;
 
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}
 

 
vector <pair <ll,ll > > s;
long long dp[mxn];
long long ans;
int main(){
	ll h,n;
	cin>>h>>n;
	ll mi = inf;
	for (int i =0;i<n;i++){
		ll a,b;
		cin>>a>>b;
		mi = min(mi,b);
		s.push_back({a,b});
	}
	fill(dp,dp+mxn,inf);
	dp[0]=0;
	dp[1] = mi;
	for (int i = 1;i<=h;i++){
		for (auto j : s){
			long long a = j.F , b = j.S;
			if (i>=a)
				dp[i]=min(dp[i],dp[i-a]+b);
			dp[i] = min(dp[i],(i/a+(i%a>0))*b);
		}
	}


	
	
	cout<<dp[h];

}

Measured memory_bytes: 384
N, M = map(int, input().split())

ac = 0
wa = 0

l = [0] * (N + 1)

for num in range(M):
    p, s =  input().split()
    p = int(p)
    if s == "AC":
        if l[p] <= 0:
            ac += 1
            wa += -l[p]
            l[p] = 1
        
         
    else:
        if l[p] <= 0:
            l[p] -= 1
        
print(*[ac, wa])


Measured memory_bytes: 3828
t, d = map(int, input().split())
ta, tb = map(int, input().split())
da, db = map(int, input().split())
min_score = min([abs(t - (ta * va + tb * vb) / (va + vb)) for va in range(0, d + 1, da) for vb in range(0, d + 1, db) if 1 <= va + vb <= d])
print(min_score)


Measured memory_bytes: 5624
#include <bits/stdc++.h>
using namespace std;
#pragma region Macros
typedef long long ll;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
const long long MOD=1e9+7;
// const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};
#define LOCAL

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    cout << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();++itr){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();++itr){
        os << *itr;
        if (++itr!=s.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}

void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
    cerr << head;
    if (sizeof...(Tail)>0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}

template<class T1,class T2> inline bool chmin(T1 &a,T2 b){
    if (a>b){a=b; return true;} return false;
}
template<class T1,class T2> inline bool chmax(T1 &a,T2 b){
    if (a<b){a=b; return true;} return false;
}
#pragma endregion

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    if (N%1000==0) cout << 0 << '\n';
    else cout << -(N%1000-1000) << '\n';
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main (){
    int a,b; cin>>a>>b;
    if(a==1||b==1){
        if(a==1&&b!=1){
            cout<<"Alice";
        } if(b==1&&a!=1){
        cout<<"Bob";}
        if(a==b){
            cout<<"Draw";
        }
    } else{
        if(a>b){
            cout<<"Alice";
        } if(b>a){
        cout<<"Bob";}
        if(a==b){
            cout<<"Draw";}}}

























Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long int a[200005];
long long int sum[200005];
int main(void)
{
	int n;
  	cin >> n;
  	for(int i=0;i<n;i++)
    {
    	cin >> a[i];
    }
  	sum[n-1] = 0;
  	long long int m = 1e9 + 7;
  	for(int i=1;i<n;i++)
    {
    	sum[n-1-i] = (sum[n-i] + a[n-i])%m;
    }
  	long long int ans = 0;
    for(int i = 0;i<n;i++)
    {
    	ans= ((ans)%m+(a[i]*sum[i])%m)%m;
    }
  	cout << ans << endl;
}


Measured memory_bytes: 6688
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int A = Character.getNumericValue(str.charAt(0));
        int B = Character.getNumericValue(str.charAt(1));
        int C = Character.getNumericValue(str.charAt(2));
        int D = Character.getNumericValue(str.charAt(3));
        
        judge(A,B,C,D);
        
    }
    
    public static void judge(int A,int B,int C,int D){
        if(A+B+C+D==7) System.out.println(A+"+"+B+"+"+C+"+"+D+"=7");
        else if(A+B+C+D==7) System.out.println(A+"+"+B+"+"+C+"+"+D+"=7");
        else if(A+B+C-D==7) System.out.println(A+"+"+B+"+"+C+"-"+D+"=7"); 
        else if(A+B-C+D==7) System.out.println(A+"+"+B+"-"+C+"+"+D+"=7"); 
        else if(A-B+C+D==7) System.out.println(A+"-"+B+"+"+C+"+"+D+"=7"); 
        else if(A+B-C-D==7) System.out.println(A+"+"+B+"-"+C+"-"+D+"=7"); 
        else if(A-B-C+D==7) System.out.println(A+"-"+B+"-"+C+"+"+D+"=7");
        else if(A-B+C-D==7) System.out.println(A+"-"+B+"+"+C+"-"+D+"=7"); 
    }
}

Measured memory_bytes: 39400
#include <iostream>
#include <utility>
#include <queue>
#include <memory>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)

using namespace std;
using ll = long long;
const int mod = 1e9+7;

int main(){
    vector<ll> vec(87,0);
    vec[0] = 2;
    vec[1] = 1;
    int n;
    cin >> n;
    reps(i,2,87){
        vec[i] = vec[i-1] + vec[i-2];
    }

    cout << vec[n] << endl;
    return 0;
}

Measured memory_bytes: 3588
#include <stdio.h>

int main()
{
	int i, N, D[2], flag = 0;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%d %d", &(D[0]), &(D[1]));
		if (D[0] == D[1]) flag++;
		else flag = 0;
		if (flag == 3) break;
	}
	if (i <= N) printf("Yes\n");
	else printf("No\n");
	fflush(stdout);
	return 0;
}

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

typedef long long ll;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    long double a,b,ans;
    cin >> a >> b;
    ans = a*b;
    ll d;
    d = ans;
    cout << d << endl;
}


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

pairs = []
for i in range(N):
    a,b=input().split()
    a=int(a)
    b=int(b)
    pairs.append([a,b])

pair = sorted(pairs, key=lambda x:(x[1]))

impos = False

calc = []
calc.append(pair[0][0])
for i in range(N-1):
    calc.append(calc[i]+pair[i+1][0])

for i in range(N):
    if calc[i]>pair[i][1]:
        impos = True

if impos:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 44448
#include <iostream>
#include <vector>
#define INF 50000000000000
std::vector<int> G[100000];
struct edge{int from,to,cost;};
int V,E,r;
edge es[500000];
long long int d[100000];
void shortest_path(int s);
int main(void){
	std::cin>>V>>E>>r;
	for(int i=0;i<E;i++){
		int from,to,cost;
		std::cin>>from>>to>>cost;
		//G[from].push_back(to);
		//G[t].push_back(s);
		es[i].from=from;
		es[i].to=to;
		es[i].cost=cost;
	}
	shortest_path(r);
	for(int i=0;i<V;i++){
		if(d[i]!=INF){
			std::cout<<d[i]<<std::endl;
		}else {
			std::cout<<"INF"<<std::endl;
		}
	}
	return 0;
}
void shortest_path(int s){
	for(int i=0;i<V;i++){
		d[i]=INF;
	}
	d[r]=0;
	while(1){
		bool flag=true;
		for(int i=0;i<E;i++){
			if(d[es[i].from]!=INF){
				if(d[es[i].to]>d[es[i].from]+es[i].cost){
					d[es[i].to]=d[es[i].from]+es[i].cost;
					flag=false;
				}
			}
		}
		if(flag){
			break;
		}
	}
}

Measured memory_bytes: 11900
#include <iostream>
#include <vector>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <cmath>
#include <cstring>
using namespace std;

#define pi acos(-1)

int to_int(string s){
    int number = 0;
    for(int i=0;i<s.size();i++){
        number *= 10;
        number += s[i] - '0';
    }
    return number;
}

string to_str(int n){
    string s;
    while(n!=0){
        s += n % 10 + 48;
        n /= 10;
    }
    reverse(s.begin(),s.end());
    return s;
}

bool isLeapYear(int year)
{
    if(((year % 4 == 0 ) && (year % 100 != 0)) || (year % 400 == 0))
        return true;
    else
        return false;
}

bool isPrime(int n)
{
    if (n == 2)
        return true;
    if ((n & 1)==0)
        return false;
    for (int i = 3; i*i <= n;i+=2) {
        if (n%i == 0)
            return false;
    }

    return true;
}

bool isPalindrome(string s)
{
    for(int i=0,j=s.size()-1 ; i< s.size()/2 && j >= s.size()/2;i++,j--){
            if(s[i] == s[j])
                continue;
            else{
                return false;
            }
        }
    return true;
}

/*#define row 5001
#define col 10000

int arr[row][col];

void fib()
{
    arr[0][0] = 0;
    arr[1][0] = 1;
    for(int i=2;i<row;i++){
        for(int j=0;j<col;j++){
            if(arr[i-1][j] + arr[i-2][j] == 0)
                continue;
            arr[i][j] += arr[i-1][j] + arr[i-2][j];
            if(arr[i][j] > 9){
                arr[i][j+1] = arr[i][j]/10;
                arr[i][j] %= 10;
            }
        }
    }
}*/

int main()
{
    vector <int> arr(3);

    int even=0,odd=0;

    for(int i=0;i<3;i++){
        int a;
        cin >> a;
        if(a%2 ==0)
            even++;
        else
            odd++;
        arr[i] = a;
    }

    sort(arr.begin(),arr.end());

    if(even == 3 || odd == 3){
        cout << (arr[2]-arr[1])/2 + (arr[2]-arr[0])/2 << endl;
    }

    else if(even == 2)
    {

        if(arr[0]%2 ==0)
            arr[0]++;
        if(arr[1]%2==0)
            arr[1]++;
        if(arr[2]%2==0)
            arr[2]++;

        cout << (arr[2]-arr[1])/2 + (arr[2]-arr[0])/2 + 1 << endl;
    }
    else{
        if(arr[0]%2!=0)
            arr[0]++;
        if(arr[1]%2!=0)
            arr[1]++;
        if(arr[2]%2!=0)
            arr[2]++;
        cout << (arr[2]-arr[1])/2 + (arr[2]-arr[0])/2 + 1<< endl;
    }


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main(void){
  int n, m, c;
  vector<int> b(20);
  int a[20][20];

  cin >> n >> m >> c;

  for(int i = 0; i < m; i ++)
    cin >> b.at(i);
  for(int i = 0; i < n; i ++)
    for(int j = 0; j < m; j ++)
      cin >> a[i][j];

  int count = 0;

  for(int i = 0; i < n; i ++){
    int sum = 0;
    for(int j = 0; j < m; j ++){
      sum += a[i][j] * b.at(j);
    }
    if((sum+c) > 0) count ++;
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    if(b>=a) cout<<a<<endl;
    else cout<<a-1<<endl;
    return 0;
}

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

using namespace std;

ll INF = 100000000000000;
ll dp[105][100005];
int N;
pair<ll,ll> ar[105];

int main(){
    std::ios_base::sync_with_stdio(false); std::cin.tie(0);
    int W;
    cin >> N >> W;
    int total_value = 0;
    ll weight,value;
    for(int i= 0; i < 105; i++ ){
        for(int j=0 ; j < 100005; j++){
            dp[i][j] = INF;
        }
    }
    //cout << dp[1][30];
    for(int i=1; i <= N; i++){
        cin >> weight >> value;
        total_value += value;
        ar[i] = make_pair(weight,value);

    }
    for(int i=1; i <= N; i++){
        weight = ar[i].first; value = ar[i].second;
        for(int j=1; j <= total_value; j++) dp[i][j] = dp[i-1][j]; //copy
        //cout << i << " " << value << " " << dp[i][value] << endl;
        dp[i][value] = min( dp[i][value], weight ); //cout << dp[i][value];
        for(int j=total_value; j >=1; j-- ){
            if( j-value >= 1 && dp[i-1][j-value] != INF ) dp[i][j] = min( dp[i-1][j-value] + weight, dp[i][j] );

        }

    }
    int v = total_value;
    //cout << dp[1][30] << endl;
    while( true ){
        if( dp[N][v] <= W ) {/*cout << v << " " << dp[N][v] << endl;*/ break;}
        --v;
    }
    cout << v;
}


Measured memory_bytes: 82304
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1000010;
const int mod=998244353;
const int inv=499122177;
int n,s,p[N],a[N];
int poww(int x,int y){
	int ans=1;
	while(y){
		if(y&1){
			ans=ans*x%mod;
		}
		x=x*x%mod;
		y>>=1;
	}
	return ans;
}
void fwt(int *a,int n,int x){
	for(int o=1,k=2;k<=n;o<<=1,k<<=1){
		for(int i=0;i<n;i+=k){
			for(int j=0;j<o;j++){
				a[i+j]+=a[i+j+o];
				a[i+j]%=mod;
				a[i+j+o]=a[i+j]+a[i+j+o]*(mod-2)%mod;
				a[i+j+o]%=mod;
				(a[i+j]*=x)%=mod;
				(a[i+j+o]*=x)%=mod;
			}
		}
	}
}
signed main(){
	scanf("%lld",&n);
	for(int i=0;i<(1<<n);i++){
		scanf("%lld",&p[i]);
		(s+=p[i])%=mod;
	}
	s=poww(s,mod-2);
	for(int i=0;i<(1<<n);i++){
		(p[i]*=s)%=mod;
	}
	a[0]=(1<<n)-1;
	for(int i=1;i<(1<<n);i++){
		a[i]=mod-1;
	}
	(p[0]+=mod-1)%=mod;
	fwt(a,1<<n,1);
	fwt(p,1<<n,1);
	for(int i=0;i<(1<<n);i++){
		(a[i]*=poww(p[i],mod-2))%=mod;
	}
	fwt(a,1<<n,inv);
	for(int i=0;i<(1<<n);i++){
		printf("%lld\n",(a[i]-a[0]+mod)%mod);
	}
}

Measured memory_bytes: 7688
# -*- coding: utf-8 -*-
from collections import Counter
from string import ascii_lowercase

N = int(input())
S = []
result = ""
abc = {a: 50 for a in list(ascii_lowercase)}

for n in range(N):
    S.append(Counter(str(input())))

for a in list(ascii_lowercase):
    for n in range(N):
        abc[a] = min(S[n][a], abc[a])

for a in list(ascii_lowercase):
    result += a * abc[a]

print(result)

Measured memory_bytes: 3956
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
typedef long long ll;
using namespace std;

int main(){
  int n;
  int d,x;
  cin >> n;
  cin >> d >> x;
  vector<int> a(n);
  for(int i = 0; i < n; ++i){
    cin >> a[i];
  }
  int cnt = 0;
  for(int i = 0; i < n; ++i){
    int day = 1;
    while(day <= d){
      cnt++;
      day += a[i];
    }
  }
  cout << cnt + x << endl;
}


Measured memory_bytes: 256
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
 
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    int ans = 0;
    vector<int> cnt(3);
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for (int j = 0; j + 1 < s.length(); j++) {
            if (s[j] == 'A' && s[j + 1] == 'B') {
                ans++;
            }
        }
        if (s.back() == 'A' && s[0] == 'B') {
            cnt[2]++;
            continue;
        }
        if (s[0] == 'B') {
            cnt[0]++;
        }
        if (s.back() == 'A') {
            cnt[1]++;
        }
    }
    if (cnt[2]) {
        ans += cnt[2] - 1;
        ans += min(1, cnt[0]) + min(1, cnt[1]);
        cnt[0]--;
        cnt[1]--;
        if (cnt[0] > 0 & cnt[1] > 0) {
            ans += min(cnt[0], cnt[1]);
        }
    } else {
        ans += min(cnt[0], cnt[1]);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 100000000
#define rep(i,a,b) for(int (i)=a;(i)<(int)(b);(i)++)
using ll = long long int;

int main(){
    int S,W;
    cin >> S >> W;
    if(W>=S) cout << "unsafe" << endl;
    else cout << "safe" << endl;

}

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

int main()
{
  int n;
  int x;
  int t;
  cin>>n;
  cin>>x;
  cin>>t;
  
  double y=double(n)/double(x);
  int result=ceil(y)*t;
  cout<<result;
  return 0;
}
   

Measured memory_bytes: 3592
#include<stdio.h>
int main()
{
    int a,b,temp;
    while(scanf("%d %d",&a,&b)!=EOF)
    {
        temp=a-2*b;
        if(temp<=0)
            printf("0\n");
        else
            printf("%d\n",temp);
    }
    return 0;
}


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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int W[2005][2005];
int B[2005][2005];

int main()
{
    ll N, K;
    cin >> N >> K;
    REP(i, 2 * K + 1)
    {
        REP(j, 2 * K + 1)
        {
            B[i][j] = W[i][j] = 0;
        }
    }
    REP(i, N)
    {
        ll x, y;
        char c;
        cin >> x >> y >> c;
        x %= (2 * K);
        y %= (2 * K);
        if (c == 'B')
            B[x + 1][y + 1]++;
        else
            W[x + 1][y + 1]++;
    }

    FOR(i, 2 * K + 1, 1)
    {
        FOR(j, 2 * K + 1, 1)
        {
            B[i][j] += B[i][j - 1];
            W[i][j] += W[i][j - 1];
        }
    }
    FOR(i, 2 * K + 1, 1)
    {
        FOR(j, 2 * K + 1, 1)
        {
            B[j][i] += B[j - 1][i];
            W[j][i] += W[j - 1][i];
        }
    }

    int max = 0;
    REP(i, K)
    {
        REP(j, K)
        {
            //! (0,0)にWの(i,j)を置いた際に叶えられる最大値
            int w = (W[2 * K - i][2 * K] - W[K - i][2 * K]) + (W[2 * K][2 * K - j] - W[2 * K][K - j]) - 2 * (W[2 * K - i][2 * K - j] - W[2 * K - i][K - j] - W[K - i][2 * K - j] + W[K - i][K - j]);
            int b = (B[2 * K - i][2 * K] - B[K - i][2 * K]) + (B[2 * K][2 * K - j] - B[2 * K][K - j]) - 2 * (B[2 * K - i][2 * K - j] - B[2 * K - i][K - j] - B[K - i][2 * K - j] + B[K - i][K - j]);
            //! K-i<=x%2*K<=2*K-1-i && K-j<=y%2*K<=2*K-1-jの部分は黒
            max = std::max(max, W[2 * K][2 * K] - w + b);

            //! (0,0)にBの(i,j)を置いた際に叶えられる最大値
            max = std::max(max, w + B[2 * K][2 * K] - b);
        }
    }
    cout << max << endl;
    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    int ans = 0;
    multiset<int> s(a.begin(), a.end());
    while(!s.empty()) {
        auto it = prev(s.end());
        int a = *it;
        s.erase(it);
        int b = (1LL << (32 - __builtin_clz(a))) - a;
        it = s.find(b);
        if(it != s.end()) {
            ans++;
            s.erase(it);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 13556
#include <bits/stdc++.h>
using namespace std;
int n,dp[2003][2003],a[6003],ans,tg,MX[2003],cur;
vector<int>A,B,C;
void add(int x,int y,int z){A.push_back(x),B.push_back(y),C.push_back(z);}
int main(){
	cin>>n;
	for(int i=1;i<=3*n;i++)cin>>a[i]; 
	memset(dp,-1,sizeof(dp));
	memset(MX,-1,sizeof(MX));
	dp[a[1]][a[2]]=dp[a[2]][a[1]]=MX[a[1]]=MX[a[2]]=cur=0;
	for(int i=3;i<3*n;i+=3){
		if(a[i]==a[i+1]&&a[i]==a[i+2]){tg++;continue;}
		A.clear(),B.clear(),C.clear();
		if(a[i]>a[i+1])swap(a[i],a[i+1]);
		if(a[i+1]>a[i+2])swap(a[i+1],a[i+2]);
		if(a[i]>a[i+1])swap(a[i],a[i+1]);
		if(a[i]==a[i+1])for(int j=1;j<=n;j++)if(dp[j][a[i]]>=0)add(j,a[i+2],dp[j][a[i]]+1);
		if(a[i+1]==a[i+2])for(int j=1;j<=n;j++)if(dp[j][a[i+1]]>=0)add(j,a[i],dp[j][a[i+1]]+1);
		if(dp[a[i]][a[i]]>=0)add(a[i+1],a[i+2],dp[a[i]][a[i]]+1);
		if(dp[a[i+1]][a[i+1]]>=0)add(a[i],a[i+2],dp[a[i+1]][a[i+1]]+1);
		if(dp[a[i+2]][a[i+2]]>=0)add(a[i],a[i+1],dp[a[i+2]][a[i+2]]+1);
		add(a[i],a[i+1],cur),add(a[i+1],a[i+2],cur),add(a[i],a[i+2],cur);
		for(int j=i;j<i+3;j++)for(int k=1;k<=n;k++)if(MX[k]>=0)add(a[j],k,MX[k]);
		for(int j=0;j<(int)A.size();j++)if(dp[A[j]][B[j]]<C[j])
			dp[A[j]][B[j]]=dp[B[j]][A[j]]=C[j],MX[A[j]]=max(MX[A[j]],C[j]),MX[B[j]]=max(MX[B[j]],C[j]),cur=max(cur,C[j]);
	}
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++)if(dp[i][j]>=0)ans=max(ans,dp[i][j]);
		if(dp[i][i]>=0)if(i==a[3*n])ans=max(ans,dp[i][i]+1);
	}
	printf("%d",ans+tg);
}

Measured memory_bytes: 19588
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;


#[fastout]
fn solve() {
    const MOD: usize = 1_000_000_007;
    const INF: usize = std::usize::MAX;
    
    input!{
        n: usize, k: usize,
        x_vec: [isize; n]
    }

    let pos = x_vec.iter().filter(|&x| *x >= 0).map(|x| *x).collect::<Vec<isize>>();
    let neg = x_vec.iter().filter(|&x| *x < 0).map(|x| *x).rev().collect::<Vec<isize>>();

    let mut ans = std::isize::MAX;

    // pos negをどこで区切るか
    for i in 0..=k {
        let pos_cnt = i;
        let neg_cnt = k-i;
        if pos_cnt > pos.len() || neg_cnt > neg.len() { continue; }
        
        let pos_cost = if pos_cnt == 0 { 0 } else { pos[pos_cnt-1] };
        let neg_cost = if neg_cnt == 0 { 0 } else { neg[neg_cnt-1] };
        let cost = std::cmp::min(pos_cost*2 + neg_cost.abs(), neg_cost.abs()*2 + pos_cost);
        ans = std::cmp::min(ans, cost)
    }

    println!("{}", ans);
}

fn main() {
    solve()
}

#[cfg(test)]
mod test {
    use super::solve;
}


Measured memory_bytes: 4740
#include <bits/stdc++.h>
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
ll bpow(ll b, ll p, ll m = 1000000007LL) {
  ll rt = 1;
  for (; p; p >>= 1, b = b * b % m)
    if (p & 1)
      rt = rt * b % m;
  return rt;
}
int mp[1000005];
int main() {
  IOS;
  int k;
  cin >> k;
  ll cur = 0;
  int cnt = 0;
  while (true) {
    cnt++;
    cur = (cur * 10 + 7) % k;
    if (cur == 0) {
      cout << cnt << endl;
      return 0;
    } else if (mp[cur] != 0) {
      cout << -1 << endl;
      return 0;
    }
    mp[cur] = 1;
  }
}


Measured memory_bytes: 7512
N = int(input())
A = [int(i) for i in input().split()]

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

def lcm(a, b):
    return a // gcd(a,b) * b

l = 1
for i in range(N):
    l = lcm(l, A[i])

ans = 0
MOD = int(1e9+7)
for i in range(N):
    ans += l // A[i]

print(ans % MOD)

Measured memory_bytes: 4084
#include<stdio.h>
int main(void) {
	int a, b, c;
	int ten;
	int ans[1000];
	int i, j=0;
	int count=0;

	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);

	if (a < b) {
		ten = a;
	}
	else {
		ten = b;
	}

	for (i = 1; i <= ten; i++) {
		if (a%i == 0 && b%i == 0) {
			ans[j] = i;
			j++;
			count++;
		}
	}

	printf("%d\n",ans[count-(c)]);
	return 0;
}

Measured memory_bytes: 128
class WeightUnionFindTree
  def initialize(n)
    @parent = (0..n).to_a
    @weight = Array.new(n+1, 0)
    @rank = Array.new(n+1, 0)
  end
  
  def find(a)
    return a if @parent[a] == a
    pa = find(@parent[a])
    @weight[a] += @weight[@parent[a]]
    @parent[a] = pa
  end
     
  def unite(a, b, w)
    w += @weight[a]
    w -= @weight[b]
    a = find(a)
    b = find(b)
    return if a == b
    if @rank[a] < @rank[b]
      @parent[a] = b
      @weight[a] = -w
    else
      @parent[b] = a
      @weight[b] = w
      @rank[a] += 1 if @rank[a] == @rank[b]
    end
  end
  
  def same?(a, b)
    find(a) == find(b)
  end
  
  def weight(a)
    find(a)
    @weight[a]
  end
  
  def diff(a, b)
    weight(b) - weight(a)
  end
end

n, m = gets.chomp.split.map(&:to_i)
info = Array.new(m) { gets.chomp.split.map(&:to_i) }

tree = WeightUnionFindTree.new(n)
info.each do |l, r, d|
  if tree.same?(l, r)
    unless tree.diff(l, r) == d
      puts "No"
      exit
    end
  end
  tree.unite(l, r, d)
end
puts "Yes"


Measured memory_bytes: 18556
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr(i,n) for(int i=0;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
ll n,W,w[110],v[110],dp[110][100010];
const ll INF=1e12;

ll vm(ll i,ll t){
  if(t<0) return -INF;
  if(dp[i][t]!=INF) return dp[i][t];
  if(i==0) dp[i][t]=0;
  else dp[i][t]=max(vm(i-1,t),vm(i-1,t-w[i-1])+v[i-1]);
  return dp[i][t];
}

int main(){
  cin>>n>>W;
  fr(i,n+1) fr(t,W+1) dp[i][t]=INF;
  fr(i,n) cin>>w[i]>>v[i];
  cout<<vm(n,W)<<endl;
}

Measured memory_bytes: 80128
/*
Look at the star
Look at the shine for U
*/
#include<bits/stdc++.h>
#define ll long long
#define PII pair<int,int>
#define sl(x) scanf("%lld",&x)
using namespace std;
const int N = 1e6+5;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}
ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}
ll s[N],a[N],b[N];

int main()
{
	ll n,i,j,k;
	sl(n);
	for(i = 1;i <= n;i++)
		sl(s[i]);

	for(i = 1;i <= n;i++)
	{
		if(i&1) a[s[i]]++;
		else b[s[i]]++;
	}
	ll maxa = 0,maxb = 0,ta = 0,tb = 0;
	for(i = 1;i <= 100005;i++)
	{
		if(a[i] > maxa)
		{
			maxa = a[i];
			ta = i;
		}
		if(b[i] > maxb)
		{
			maxb = b[i];
			tb = i;
		}
	}
	if(tb != ta)
	{
		ll ans = n-maxa-maxb;
		printf("%lld\n",ans);
	}
	else
	{
		sort(a,a+100005);
		sort(b,b+100005);
		ll ans = n-max(maxa+b[100003],maxb+a[100003]);
		printf("%lld\n",ans);
	}
}

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

// グローバル変数
string t;
vector<string> v;

// 関数プロトタイプ
void input();
void solve();

int main(void)
{
    input();
    solve();  
}

// 標準入力
void input() {
    cin >> t;
}

void solve() {
    v.resize(t.length());
    for (int i = 0; i < t.length();i++) {
        v[i] = t.substr(i, 1);
    }
    reverse(v.begin(), v.end());
    if(v[0] == "?") {
        v[0] = "D";
    }
    for (int i = 1; i < v.size();i++) {
        if(v[i] == "?") {
            if(v[i-1] == "D") {
                if(i+1 < v.size() && v[i+1] == "P") {
                    v[i] = "D";
                } else {
                    v[i] = "P";
                }
            } else {
                v[i] = "D";
            }
        }
    }
    reverse(v.begin(), v.end());
    for (int i = 0; i < v.size();i++) {
        cout << v[i];
    }
    cout << endl;
}

Measured memory_bytes: 9692
def int_(num_str):
    return int(num_str) - 1

N, M = map(int, input().split())
balls = [1] * N
red = {0}
for i in range(M):
    x, y = map(int_, input().split())
    if x in red:
        if balls[x] == 1:
            red.remove(x)
            red.add(y)
        else:
            red.add(y)
    balls[x] -= 1
    balls[y] += 1
print(len(red))

Measured memory_bytes: 12780
#include <bits/stdc++.h>
#define int long long int
#define INF (int)1e9
#define INFL (int)1e15
#define MAXN (int)1e6
#define err 1e-15
#define sz size
int getInt(char ch) {
    return (int)(ch - '0');
}
int cdiv(int num, int den) {
    return (num%den == 0) ? (num/den) : (num/den)+1;
}
using namespace std;

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

    string s, t;
    cin >> s >> t;

    int cnt = 0;

    for(int i = 0; i < s.length(); i++) {
        if(s[i] == t[i]) cnt++;
    }

    cout << cnt << endl;

    return 0;
}	

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

#define _GLIBCXX_DEBUG

int main() {
  int n, m, ans = 0, c = 0;
  string a;
  typedef pair<string, bool> pair;
  
  cin >> n;
  vector<pair> st(n);
  for(int i = 0; i < n; i++) {
    cin >> st[i].first;
    st[i].second = 1;
  }
  
  cin >> m;
  for(int i = 0; i < m; i++) {
    cin >> a;
    st.push_back(pair(a, 0));
  }
  
  sort(st.begin(), st.end());
  
  for(int i = 0; i < st.size(); i++) {
    if(i == 0 || st[i].first == st[i-1].first) {
      if(st[i].second) c++;
      else c--;
    }
    else {
      ans = max(ans, c);
      if(st[i].second) c = 1;
      else c = -1;
    }
  }
  
  ans = max(ans, c);
  cout << ans << endl;
}

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

int H,W,cnt,t[102][102];
bool vis[102][102];

int dx[2][6]={{-1, 0,0,-1,-1,1},{ 1,1,1,0,-1, 0}}; 
int dy[2][6]={{ 0,-1,1,-1, 1,0},{-1,0,1,1, 0,-1}};

void dfs(int y,int x){
  int nx,ny;
  vis[y][x]=true;
  //t[y][x]=-1;
  for(int i=0;i<6;i++){
    nx=x+dx[y%2][i];
    ny=y+dy[y%2][i];
    if(nx<0||W+1<nx||ny<0||ny>H+1)continue;
    if(vis[ny][nx]) continue;
    if(t[ny][nx]==1){
      cnt++;
    }
    if(t[ny][nx]==0){
      dfs(ny,nx);
    }
  }
}
int main(){
  cin>>W>>H;
  for(int i=0;i<102;i++){
    for(int j=0;j<102;j++){
      t[i][j]=0; vis[i][j]=false;
    }
  }
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      cin>>t[i][j];
    }
  }

  cnt=0;
  dfs(0,0);
  cout<<cnt<<endl;
  
  return 0;
}

Measured memory_bytes: 1456
N,W=map(int,input().split())
dp=[0 for i in range(W+1)]

L=[]
for i in range(N):
    v,w=map(int,input().split())
    for j in range(len(dp)):
        if j+w>W:
            pass
        else:
            if dp[j+w]<dp[j]+v:
                dp[j+w]=dp[j]+v
print(dp[W])


Measured memory_bytes: 5924
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pi=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using vstr=vector<string>;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
void yes(bool c) { if (c)print("Yes"); else print("No"); };

void solve() {
    int N; cin >> N;
    vector<vi> syouziki(N);
    vector<vi> usotuki(N);
    int A,x,y;
    rep(i,N){
        cin >> A;
        rep(j,A){
           cin >> x >> y;
           x--;
           if(y) syouziki[i].pb(x);
           else usotuki[i].pb(x);
        }
        // DEBUG(i);
        // DEBUG_VEC(syouziki[i]);
        // DEBUG_VEC(usotuki[i]);

    }

    ll ans = 0;
    rep(i,pow(2,N)){
        vi persons(N,0);
        rep(j,N){
            if((i>>j)&1){
                persons[j] = 1;
            }
        }
        // DEBUG_VEC(persons);
        bool ok = true;
        rep(j,N){
            // DEBUG_VEC(syouziki[j]);
            // DEBUG_VEC(usotuki[j]);
            if(persons[j]){
                for(auto s:syouziki[j]){
                    if(persons[s]==0){
                        ok = false;
                        break;
                    }
                }
                for(auto s:usotuki[j]){
                    if(persons[s]==1){
                        ok = false;
                        break;
                    }
                }
            }
            if(!ok) break;
        }
        ll tmp_ans = 0;
        if(ok){
            rep(j,N) if(persons[j]) tmp_ans++;
        }
        ans = max(ans, tmp_ans);
    }
    print(ans);
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//V,P(大文字)使用不可

const ll INF=1000000000000000000;

signed main(){
    int n;
    cin>>n;
    V<ll> a(n);
    set<ll> st;
    rep(i,n){
        cin>>a[i];
        st.insert(a[i]);
    }
    if(st.size()==n) cout<<"YES";
    else cout<<"NO";
}

Measured memory_bytes: 11136
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    double n, m, d;
    cin >> n >> m >> d;
    if(d != 0) cout << ((n-d)*2.0/(n*n))*(m-1) << endl;
    else cout << (n/(n*n))*(m-1) << endl;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
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();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
  int n;
  stack<int> s;


  while(cin >> n) {
    if(!n) {
      cout << s.top() << endl;
      s.pop();
    }
    else s.push(n);
  }
}

Measured memory_bytes: 1200