akhauriyash/Code-Regression huggingface dataset:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<algorithm>

#include<cmath>

#include<set>

#include<vector>

using namespace std;
const int N=2e5+10,inf=1e9;
int n,dp[N][2];
char s[N];
int k;bool is[N];
int main(){
	//freopen("a.in","r",stdin);
	scanf("%d%s",&n,s+1);for(int i=1;i<=n;i++)is[i]=s[i]=='.'?0:1;
	dp[0][0]=0;dp[0][1]=inf;
	for(int i=1;i<=n;i++){
		if(is[i]){
			dp[i][1]=min(dp[i-1][0],dp[i-1][1]);
			dp[i][0]=dp[i-1][0]+1;
		}else{
			dp[i][0]=dp[i-1][0];
			dp[i][1]=min(dp[i-1][0],dp[i-1][1])+1;
		}
	}
	cout<<min(dp[n][0],dp[n][1]);
}

Measured memory_bytes: 2176
from sys import stdin
import sys
import numpy as np
import collections
from functools import cmp_to_key
import heapq
sys.setrecursionlimit(100000)

##  input functions for me
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##

compo = []
cs = []
N = 0
M = 0
A = None
B = None
E = None

def main():
    global compo,cs,N,M,A,B,E
    N, M = rip()
    A = [0] * M
    B = [0] * M
    for i in range(M):
        A[i], B[i] = rip()
        A[i] -= 1
        B[i] -= 1
    
    E = [[] for i in range(N)]
    for i in range(M):
        E[A[i]].append(B[i])
    
    compo = [-1] * N

    def dfs(cmp, route, hs):
        global compo,cs,N,M,A,B,E
        if(len(cs) > 0) : return
        now = route[len(route) - 1]
        for nxt in E[now]:
            if compo[nxt] == -1:
                compo[nxt] = cmp
                route.append(nxt)
                hs.add(nxt)
                dfs(cmp, route, hs)
                hs.remove(nxt)
                route.pop(-1)
            elif compo[nxt] == cmp:
                if nxt in hs:
                    cs = route[route.index(nxt):]
                return
            else:
                return


    cs = []
    c = 0
    for i in range(N):
        if(compo[i] != -1): continue
        c += 1
        a = []
        hs = set()
        a.append(i)
        hs.add(i)
        compo[i] = c
        dfs(c, a, hs)

    if len(cs) == 0:
        print(-1)
        sys.exit(0)
    
    l = cs
    while(True):
        di = dict()
        for i in range(len(l)):
            di[l[i]] = l[(i + 1) % len(l)]
        edx = -1
        for i in range(M):
            if A[i] in di and B[i] in di:
                if di[A[i]] != B[i]:
                    edx = i
                    break
        
        if edx == -1:
            print(len(l))
            print("\n".join([str(n + 1) for n in l]))
            sys.exit(0)
        
        di[A[edx]] = B[edx]
        nl = [A[edx], B[edx]]
        while True:
            nxt = di[nl[-1]]
            if nxt != nl[0]:
                nl.append(nxt)
            else:
                break
        l = nl

if __name__ == "__main__":
    main()


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

struct Card{
	char mark;
	int num;
};

Card Cards1[500000];
Card Cards2[500000];


int partition(int p,int r){
	int x=Cards1[r].num;
	int i=p-1;
	for(int j=p;j<r;j++){
		if(Cards1[j].num<=x){
			i++;
			swap(Cards1[i],Cards1[j]);
		}
	}
	swap(Cards1[i+1],Cards1[r]);
	return i+1;
}

void quickSort(int p, int r){
	if(p<r){
		int q=partition(p,r);
		quickSort(p,q-1);
		quickSort(q+1,r);
	}
}

void merge(int left,int mid,int right){
	int n1=mid-left;
	int n2=right-mid;
	vector<Card> L;
	vector<Card> R;
	int i,j;
	for(i=0;i<n1;i++){
		L.push_back(Cards2[left+i]);
	}
	for(i=0;i<n2;i++){
		R.push_back(Cards2[mid+i]);
	}
	Card s;
	s.num=1<<30;
	L.push_back(s);
	R.push_back(s);
	i=j=0;
	for(int k=left;k<right;k++){
		if(L[i].num<=R[j].num){
			Cards2[k]=L[i++];
		}else{
			Cards2[k]=R[j++];
		}
	}
}

void mergeSort(int left, int right){
	if(left+1<right){
		int mid=left+(right-left)/2;
		mergeSort(left,mid);
		mergeSort(mid,right);
		merge(left,mid,right);
	}
}

bool isStable(int n){
	for(int i=0;i<n;i++){
		Card c1=Cards1[i];
		Card c2=Cards2[i];
		if(c1.mark!=c2.mark||c1.num!=c2.num){
			return false;
		}
	}
	return true;
}

int main(){
	int n,num;
	char mark;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> mark;
		cin >> num;
		Cards1[i].mark=Cards2[i].mark=mark;
		Cards1[i].num=Cards2[i].num=num;
	}
	
	quickSort(0,n-1);
	mergeSort(0,n);
	
	if(isStable(n)){
		cout << "Stable" << endl;
	}else{
		cout << "Not stable" << endl;
	}
	
	for(int i=0;i<n;i++){
		Card c=Cards1[i];
		cout << c.mark << " " << c.num << endl;
	}	
	return 0;
}



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

using namespace std;

typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000 //2e9
#define LLINF 2000000000000000000ll // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define dmp(x) cerr << #x << ": " << x << endl;

template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}

template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T,vector<T>,greater<T>>;
template<class T> vector<T> vect(int len,T elem){ return vector<T>(len,elem); }

template<class T,class U>
ostream& operator << (ostream& os,const pair<T,U>& p){
  os << p.fi << ',' << p.sec; return os;
}
template<class T,class U>
istream& operator >> (istream& is,pair<T,U>& p){
  is >> p.fi >> p.sec; return is;
}
template<class T>
ostream& operator << (ostream &os,const vector<T> &vec){
  for(int i=0;i<vec.size();i++){
    os << vec[i];
    if(i+1<vec.size())os << ' ';
  }
  return os;
}
template<class T>
istream& operator >> (istream &is,vector<T>& vec){
  for(int i=0;i<vec.size();i++)is >> vec[i];
  return is;
}
void fastio(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout<<fixed<<setprecision(20);
}
namespace Util{
  template<class T>
  vector<pair<T,int>> runLength(vector<T> v){
    vector<pair<T,int>> res;
    for(int i=0;i<v.size();i++){
      if(res.empty()||res.back().first!=v[i])res.push_back(make_pair(v[i],1));
      else res.back().second++;
    }
    return res;
  }
  template<class T>
  void compress(vector<T> &v){
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
  }
}

void solve(){
  int n,r;
  cin >> n >> r;
  if(n>=10)cout << r << endl;
  else cout << r+100*(10-n) << endl;
  return ;
}
 
signed main(){
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define rep(i, n)for(int i=0; i<n; i++)

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

  int ab = A+B;
  int bc = B+C;
  int ca = C+A;

  if(ab == C)
    cout << "Yes" << endl;
  else
    if(bc == A)
      cout << "Yes" << endl;
    else
      if(ca == B)
	cout << "Yes" << endl;
      else
	cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<queue>
#include<vector>
#define ll long long
#define pi acos(-1.0)
#define inf 0x3f3f3f3f
using namespace std;
const int maxn = 1e5+5;
int out[maxn];
vector<int>vec[maxn];
queue<int>q1,q2;

int main(){
	int n, m; scanf("%d %d", &n, &m);
	int u, v;
	for(int i = 1; i <= m; i++){
		scanf("%d %d", &u, &v);
		vec[v].push_back(u);
		out[u]++;
	}
	int ans = 0, ok = 0;
	for(int i = 1; i <= n; i++) if(out[i] == 0) q1.push(i);
	while(1){
		ok = 1;
		while(!q1.empty()){
			int now = q1.front(); q1.pop();
			for(int i = 0; i < vec[now].size(); i++){
				int x = vec[now][i];
				out[x]--;
				if(!out[x]) q2.push(x);
			}
			ok = 0;
		}
		if(!ok){
			ans++;
			continue;
		}
		while(!q2.empty()){
			int now = q2.front(); q2.pop();
			for(int i = 0; i < vec[now].size(); i++){
				int x = vec[now][i];
				out[x]--;
				if(!out[x]) q1.push(x);
			}
			ok = 0;
		}
		if(ok) break;
		ans++;
	}
	printf("%d\n",ans-1);
	return 0;
}

Measured memory_bytes: 9556
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <unordered_map>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <stack>
#include <set>
#include <deque>
#pragma GCC optimize(3 , "Ofast" , "inline")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std ;
#define ios ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0)
#define x first
#define y second
#define pb push_back
#define ls rt << 1
#define rs rt << 1 | 1
typedef long long ll ;
const double esp = 1e-6 , pi = acos(-1) ;
typedef pair<int , int> PII ;
const int N = 1e6 + 10 , INF = 0x3f3f3f3f , mod = 1e9 + 7;
int work()
{
    int n ;
    cin >> n ;
    vector<int> v(n + 1) ;
    for(int i = 1; i <= n ;i ++ ) cin >> v[i] ;
    int ans = 0 ;
    for(int i = 1; i <= n ;i ++ ) {
      for(int j = i + 1; j <= n ;j ++ ) {
        for(int k = j + 1; k <= n ;k ++ ) {
          if(v[i] == v[j] || v[i] == v[k] || v[j] == v[k]) continue ;
          if(v[i] + v[j] > v[k] && abs(v[j] - v[i]) < v[k]) ans ++ ;
        }
      }
    }
    cout << ans << endl ;
    return 0 ;
}
int main()
{
  //   freopen("C:UsersspnooyseedDesktopin.txt" , "r" , stdin) ;
  //   freopen("C:UsersspnooyseedDesktopout.txt" , "w" , stdout) ;

  work() ;
  return 0 ;
}
/*
*/


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

int main(){
    ll N,C;
    cin >> N >> C;
    vector<ll> x(N+2,0),v(N+2,0);
    for(int i=1;i<=N;++i)cin >> x[i] >> v[i];
    x[N+1]=C;

    vector<vector<ll> > dp(2, vector<ll>(100010, 0));
    ll cal=0;
    for(int i=1;i<=N;++i){
        cal+=v[i]-(x[i]-x[i-1]);
        dp[0][i]=max(dp[0][i-1],cal);
    }
    cal=0;
    for(int i=N;i>=1;--i){
        cal+=v[i]-(x[i+1]-x[i]);
        dp[1][i]=max(dp[1][i+1],cal);
    }
    ll ans=0;
    for(int i=0;i<=N;++i){
        ll tmp=dp[0][i]+dp[1][i+1];
        ans=max(ans,tmp-x[i]);
        ans=max(ans,tmp-(C-x[i+1]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 4096
// 表計算を行う簡単なプログラムを作成します。
//
// 表の行数rと列数c、r × c の要素を持つ表を読み込んで、各行と列の合計を挿入した新しい表を出力するプログラムを作成して下さい。
//
// Input
// 最初の行にrとcが空白区切りで与えられます。続くr行にそれぞれc個の整数が空白区切りで与えられます。
//
// Output
// (r+1) × (c+1) の新しい表を出力して下さい。各行の隣り合う整数は１つの空白で区切って下さい。各行の最後の列としてその行の合計値を、各列の最後の行としてその列の合計値を、最後の行・列に表全体の合計値を挿入して下さい。
//
// Constraints
// 1 ≤ r, c ≤ 100
// 0 ≤ 要素 ≤ 100

#include <iostream>

using namespace std;

int main(){
  int r,c,i,j,sum=0;
  cin >> r >> c;
  int table[r+1][c+1];
  for(i = 0; i < r; i++){
    for(j = 0 ; j < c; j++){
      cin >> table[i][j];
      sum += table[i][j];
    }
      table[i][j] = sum;
      sum = 0;
  }
  for(j = 0 ; j < c+1; j++){
    for( i = 0; i < r; i++){
      sum += table[i][j];
    }
      table[i][j] = sum;
      sum = 0;
  }

  for( i = 0; i < r+1; i++){
    for( j = 0 ; j < c+1; j++){
      if(j != c)cout << table[i][j] << ' ';
      else cout << table[i][j] << endl;
    }
  }


  return 0;
}



Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define Mod 1000000007
int main()
{
    ll n;
    cin>>n;
    vector<ll> v(n),dp(n);
    for(ll i=0;i<n;i++) cin>>v[i];
    for(ll i=1;i<n;i++)
        dp[i]=min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i]-v[i-2]));
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 4852
#include "bits/stdc++.h"
using namespace std;
int main()
{
	int n;
	scanf("%d", &n);
	vector<vector<int>> a(3, vector<int>(n + 1, 0));
	for(int i = 1; i < 3; ++i)
	{
		for(int j = 1; j <= n; ++j)
		{
			scanf("%d", &a[i][j]);
			a[i][j] += max(a[i - 1][j], a[i][j - 1]);
		}
	}
	printf("%d\n", a[2][n]);
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){

  vector<int>in(5);
  rep(i,5)cin>>in[i];

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

  rep(i,4)cout<<in[4-i]<<" ";
  cout<<in[0]<<endl;

}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(j, m) for (int j = 1; j <= (int)(m); j++)

int seleSort(int a[], int n){
int sw = 0;

rep(i,n){
  int minj = i;
  bool change = 0;
  for(int j = i; j<n; j++){
    if(a[j]<a[minj]){
    minj=j;
    change = 1;
    }
}
if(change){
  swap(a[i],a[minj]);
  sw++;
}
}
return sw;
}

int main(){

int n;
cin >> n;
int a[n];
rep(i,n) cin >> a[i];

int ans = seleSort(a,n);

rep(i,n){
  if(i > 0) cout << " ";
  cout << a[i];
}
cout << endl;
cout << ans << endl;

return 0;

}


Measured memory_bytes: 3080
import sys
def input():
  return sys.stdin.readline().rstrip()
mod = 10**9 + 7
n, m = [int(i) for i in input().split()]
a = [int(input()) for _ in range(m)]
notin = [1] * n
for i in a:
  notin[i] = 0
dp = [0] * n
dp[n - 1] = 1
if n > 1:
	dp[n - 2] = 1 + notin[n - 1]
for i in range(n - 3, -1, -1):
  dp[i] += dp[i + 1] * notin[i + 1] % mod
  dp[i] += dp[i + 2] * notin[i + 2] % mod
  dp[i] %= mod
print(dp[0])

Measured memory_bytes: 9616
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

B = []
for i in range(M-1):
  B.append(abs(A[i+1]-A[i]))
B.sort()
#print(A)
#print(B)   

if N >=M:
  ans = 0
if N == 1:
  ans = sum(B)
else:
  ans = sum(B[:-(N-1)])
print(ans)
           
#dp[i][j]: i個目までにj

Measured memory_bytes: 56744
import fileinput

# DEFINE
ALPHABET= "abcdefghijklmnopqrstuvwxyz"

dict_alphabet = {}

for key in ALPHABET:
    dict_alphabet[key] = 0


# COUNT
for line in fileinput.input():
    for letter in line.lower():
        if letter in dict_alphabet:
            dict_alphabet[letter] += 1


# OUTPUT
for key, value in dict_alphabet.items():

    print(f"{key} : {value}")



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

using namespace std;

int main(){
    int a,b;
    string sentence;
    
    vector<int> char_counter(26,0);
    // C++
    char ch;

    while ( cin >> ch ){
    // ここで ch がアルファベットなら、数える
        if(isupper(ch)) ch = tolower(ch);
        int ascii = ch - 'a';
        if(ascii>=0 && ascii <= 25) char_counter[ascii]++;
    }

    for(int j = 0;j < 26;j++){
        cout << char('a' + j) << " : " << char_counter[j] << "\n";
    }
    return 0;
}



Measured memory_bytes: 3112
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <list>
using namespace std;

typedef long long ll;

#define MOD 1000000007
#define p(x) cout << x << endl;
#define el cout << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

    int n, a;
    cin >> n >> a;

    int num = n % 500;

    if(num <= a){
        p("Yes");
    }else{
        p("No");
    }
}

Measured memory_bytes: 256
n=int(input())
g=[[] for _ in range(n)]
for i in range(n-1):
    u,v,w=map(int,input().split())
    g[u-1].append((v-1,w))
    g[v-1].append((u-1,w))

l=[-1]*n
s=[(1,0)]
while s:
    b,c=s.pop()
    l[b]=c%2
    for x,y in g[b]:
        if l[x]==-1:
            s.append((x,y+c))

for  i in l:
    print(i)

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    int n;
    cin >> n;
    map<string, int> blue;
    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        blue[s]++;
    }
    int m;
    cin >> m;
    for(int i = 0; i < m; i++){
        string s;
        cin >> s;
        if(blue[s] != 0) blue[s]--;
    }
    int ans = 0;
    for(auto v: blue){
        ans = max(ans, v.second);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL<<60;

struct Edge {
    int c;
    int to;
    ll f;
};

struct Node {
    ll d;
    int v;

    bool operator<(const Node& rhs) const {
        return d < rhs.d;
    }
    bool operator>(const Node& rhs) const {
        return d > rhs.d;
    }
};

vector<vector<Edge>> G;

int main() {
    ll N, M;
    cin >> N >> M;
    int p,q,c;
    G.resize(N+M);
    vector<map<int, vector<int>>> same_c(N);
    for ( int i = 0; i < M; i++ ) { 
        cin >> p >> q >> c;
        p--, q--;
        G[p].push_back(Edge{c,N+i,1});
        G[q].push_back(Edge{c,N+i,1});
        same_c[p][c].push_back(N+i);
        same_c[q][c].push_back(N+i);
        G[N+i].push_back(Edge{c,p,1});
        G[N+i].push_back(Edge{c,q,1});
    }

    // for ( int i = 0; i < M; i++ ) {
    //     Edge& e = G[N+i][0];
    //     auto it = same_c[e.to].find(e.c);
    //     if ( it != same_c[e.to].end() ) {
    //         auto v = it->second;
    //         G[N+i].push_back(Edge{e.c,v[0],0});
    //     }
    // }
    for ( int i = 0; i < N; i++ ) {
        for ( auto x : same_c[i] ) {
            auto v = x.second;
            int sz = v.size();
            if (sz <= 1) continue;
            for ( int j = 0; j < sz; j++ ) {
                G[v[j]].push_back(Edge{c,v[(j+1)%sz],0});
            }
        }
    }

    vector<ll> dst(N+M, INF);
    priority_queue<Node, vector<Node>, greater<Node>> que;
    dst[0] = 0;
    que.push(Node{0,0});

    while ( !que.empty() ) {
        Node n = que.top();
        que.pop();
        if ( dst[n.v] < n.d ) continue;
        for ( auto e : G[n.v] ) {
            if ( dst[e.to] > dst[n.v] + e.f ) {
                dst[e.to] = dst[n.v] + e.f;
                que.push(Node{dst[e.to], e.to});
            }
        }
    }

    ll ans = 0;
    if ( dst[N-1] != INF ) ans = dst[N-1] / 2;
    else ans = -1;
    cout << ans << "\n";
    return 0;
}

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

// 辺を表す構造体 (行き先、容量、逆辺)
struct edge {
    int to, cap, rev;
};

void add_edge(int,int,int);
int dfs(int,int,int);
int max_flow(int, int);
void solve();

int INF = pow(10,7);
// 入力
int N;
bool can[100][100]; // can[i][j]:=コンピュータiが仕事jをこなせる

int main(){
    cin >> N;
    int red[100][2];
    int blue[100][2];
    int a,b,c,d;
    for (int i=0;i<N;i++){
        cin >> a >> b;
        red[i][0] = a;
        red[i][1] = b;
    }
    for (int i=0;i<N;i++){
        cin >> c >> d;
        blue[i][0] = c;
        blue[i][1] = d;
    }
    for (int i=0;i<N;i++){
        for (int j=0;j<N;j++){
            if (red[i][0] < blue[j][0] && red[i][1] < blue[j][1]){
                can[i][j] = true;
            }else{
                can[i][j] = false;
            }
        }
    }

    solve();
}


vector<edge> G[300]; // グラフの隣接リスト表現
bool used[300]; // DFSですでに調べたかのフラグ

// fromからtoへ向かう容量capの辺をグラフに追加する 
void add_edge(int from, int to, int cap) {
    G[from].push_back((edge){to, cap, G[to].size()});
    G[to].push_back((edge){from, 0, G[from].size() - 1}); 
}

// 増加パスをDFSで探す
int dfs(int v, int t, int f) {
    if (v == t) return f;
    used[v] = true;
    for (int i = 0; i < G[v].size(); i++) {
        edge &e = G[v][i];
            if (!used[e.to] && e.cap > 0) {
                int d = dfs(e.to, t, min(f, e.cap)); if (d > 0) {
                    e.cap -= d; G[e.to][e.rev].cap += d; return d;
                } 
            }
    }
    return 0;
}

// sからtへの最大流を求める
int max_flow(int s, int t) {
    int flow = 0;
    for (;;) {
        memset(used, 0, sizeof(used));
        int f = dfs(s, t, INF);
        if (f == 0) return flow;
        flow += f;
    } 
}


void solve() {
    // 0~N-1: コンピュータに対応する頂点 // N~N+K-1: 仕事に対応する頂点
    int s = 2*N, t = s + 1;
    // sとコンピュータを結ぶ
    for (int i = 0; i < N; i++) {
        add_edge(s, i, 1);
    }
    // 仕事とtを結ぶ
    for (int i = 0; i < N; i++) {
        add_edge(N + i, t, 1);
    }
    // コンピュータと仕事を結ぶ
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++){
            if (can[i][j]) {
                add_edge(i, N + j, 1);
            }
        }
    }
    printf("%d\n", max_flow(s, t));
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);


int g[15][15];
const int INF = 1001001001;
const int di[] = { -1,0,1,0 };
const int dj[] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int main() {
	int D, G, p[11], c[11];
	cin >> D >> G;
	for (int i = 0; i < D; ++i) {
		cin >> p[i] >> c[i];
	}

	int ans = 1e9;
	for (int mask = 0; mask < (1 << D); ++mask) {
		int s = 0, num = 0, rest_max = -1;
		for (int i = 0; i < D; ++i) {
			if (mask >> i & 1) {
				s += 100 * (i + 1) * p[i] + c[i];
				num += p[i];
			}
			else {
				rest_max = i;
			}
		}
		if (s < G) {
			int s1 = 100 * (rest_max + 1);
			int need = (G - s + s1 - 1) / s1;
			if (need >= p[rest_max]) {
				continue;
			}
			num += need;
		}
		ans = min(ans, num);
	}
	cout << ans << endl;
	return 0;
}


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










const int MAXN = 1010;//点数的最大值
const int MAXM = 120010;//边数的最大值
const int INF = 0x3f3f3f3f;
struct Edge {
  int to,next,cap,flow;
} edge[MAXM]; //注意是 MAXM
int tol;
int head[MAXN];
void init() {
  tol = 2;
  memset(head,-1,sizeof(head));
}
void addedge(int u,int v,int w,int rw = 0) {
  edge[tol].to = v;
  edge[tol].cap = w;
  edge[tol].flow = 0;
  edge[tol].next = head[u];
  head[u] = tol++;
  edge[tol].to = u;
  edge[tol].cap = rw;
  edge[tol].flow = 0;
  edge[tol].next = head[v];
  head[v] = tol++;
}
int Q[MAXN];
int dep[MAXN],cur[MAXN],sta[MAXN];
bool bfs(int s,int t,int n) {
  int front = 0,tail = 0;
  memset(dep,-1,sizeof(dep[0])*(n+1));
  dep[s] = 0;
  Q[tail++] = s;
  while(front < tail) {
    int u = Q[front++];
    for(int i = head[u]; i != -1; i = edge[i].next) {
      int v = edge[i].to;
      if(edge[i].cap > edge[i].flow && dep[v] == -1) {
        dep[v] = dep[u] + 1;
        if(v == t)return true;
        Q[tail++] = v;
      }
    }
  }
  return false;
}
int dinic(int s,int t,int n) {
  int maxflow = 0;
  while(bfs(s,t,n)) {
    for(int i = 0; i < n; i++)cur[i] = head[i];
    int u = s, tail = 0;
    while(cur[s] != -1) {
      if(u == t) {
        int tp = INF;
        for(int i = tail-1; i >= 0; i--)
          tp = min(tp,edge[sta[i]].cap-edge[sta[i]].flow)
               ;
        maxflow += tp;
        for(int i = tail-1; i >= 0; i--) {
          edge[sta[i]].flow += tp;
          edge[sta[i]^1].flow -= tp;
          if(edge[sta[i]].cap-edge[sta[i]].flow == 0)
            tail = i;
        }
        u = edge[sta[tail]^1].to;
      } else if(cur[u] != -1 && edge[cur[u]].cap > edge[cur[u]].flow && dep[u] + 1 == dep[edge[cur[u]].to]) {
        sta[tail++] = cur[u];
        u = edge[cur[u]].to;
      } else {
        while(u != s && cur[u] == -1)
          u = edge[sta[--tail]^1].to;
        cur[u] = edge[cur[u]].next;
      }
    }
  }
  return maxflow;
}




inline int read(){
  int x=0,f=1;
  char ch=getchar();
  while(ch<'0' || ch>'9'){
    if(ch=='-')f=-1;ch=getchar();
  }
  while(ch>='0'&&ch<='9'){
    x=x*10+ch-'0';ch=getchar();
  }
  return x*f;
}



int a[MAXN],b[MAXN],c[MAXN],d[MAXN];
signed main() {
  int n;
  n=read();
  for(int i=1;i<=n;++i) {
    a[i]=read();
    b[i]=read();
  }
  for(int i=1;i<=n;++i) {
    c[i]=read();
    d[i]=read();
  }
  int st=2*n,ed=st+1;
  //init(ed+1);
  init();
  for(int i=1;i<=n;++i) {
    for(int j=1;j<=n;++j) {
      if(a[i]<c[j]&&b[i]<d[j])addedge(i-1,j+n-1,1);
    }
  }
  for(int i=1;i<=n;++i) {
    addedge(st,i-1,1);
  }
  for(int j=1;j<=n;++j) {
    addedge(j+n-1,ed,1);
  }
  int ans=dinic(st,ed,ed+1);
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		int c=scan.nextInt();
		if(b-a==c-b) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
		}
}

Measured memory_bytes: 23252
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

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

    def group_count(self):
        return len(self.roots())


n, m = [int(_) for _ in input().split()]
l = []
for i in range(m):
    x, y, z = [int(_) for _ in input().split()]
    l.append((x, y))

uf = UnionFind(n)
for i in range(len(l)):
    x, y = l[i]
    uf.union(x - 1, y - 1)
ans = uf.group_count()
print(ans)

Measured memory_bytes: 73944
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m; cin >> n >> m;
    if (n >= m){
		cout << 0 << endl;
		return 0;
	}
    vector<ll> x(m);
    rep(i, m) cin >> x[i];
    sort(all(x));
    vector<ll> d(x.size());
    rep(i, x.size() - 1) d.pb(abs(x[i + 1] - x[i]));
    sort(all(d), greater<ll>());
    ll sum = 0;
    rep(i, n - 1) sum += d[i];
    cout << x[x.size() - 1] - x[0] - sum;
    cout << endl;
    return 0;
}



Measured memory_bytes: 2560
// Author: getharshkumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
ll a[N];
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n, x = 1, ans = 0;
    cin >> n;
    for (ll i = 0; i < n; i++)
        cin >> a[i];
    for (ll i = 0; i < 61; i++)
    {
        ll c = 0;
        for (ll j = 0; j < n; j++)
            if (a[j] & (1LL << i))
                c++;
        ans = (ans + ((c * (n - c) % M) * x) % M) % M;
        x = (x * 2) % M;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 4352
#include <stdio.h>

int main()
{
  long n,d;
  scanf("%ld%ld",&n,&d);
  long x[n];
  long y[n];
  int i = 0;
  int cnt = 0;
  while (i < n)
  {
    scanf("%ld%ld",&x[i],&y[i]);
    if (d * d >= (x[i] * x[i]) + (y[i] * y[i]))
      cnt++;
    i++;
  }
  printf("%d",cnt);
}

Measured memory_bytes: 4852
#!/usr/bin/env python
#pyrival orz
import os
import sys
from io import BytesIO, IOBase

"""
    for _ in range(int(input())):
    n,m=map(int,input().split())
    n=int(input())
    a = [int(x) for x in input().split()]
"""

def main():
    n=int(input())
    l,r=[],[]
    for _ in range(n):
        u,v=map(int,input().split())
        l.append(u)
        r.append(v)
    l.sort()
    r.sort()
    u,v=0,0
    if n%2:
        u,v=l[n//2],r[n//2]
    else:
        u,v=l[n//2]+l[n//2-1],r[n//2]+r[n//2-1]
    print(v-u+1)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Measured memory_bytes: 93700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N,M,C;
    cin >> N >> M >> C;
    vector<int> B(M);
    rep(i,M) cin >> B[i];
    int ans = 0;
    rep(i,N){
        int tmp=0;
        rep(j,M){
            int A;
            cin >> A;
            tmp += A*B[j];    
        }
        if(tmp+C>0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
_ = input()
A = list(map(int, input().split()))
B = []

minus = 0

for i in A:
    if i < 0:
        minus += 1
    B.append(abs(i))

if minus % 2 == 0:
    print(sum(B))
else:
    print(sum(B) - min(B) * 2)


Measured memory_bytes: 14332
s=input()
a=s[0]+s[1]
a=int(a)
b=s[2]+s[3]
b=int(b)

answer=0

if a>0 and a<13:
    answer+=2
if b>0 and b<13:
    answer+=1

if answer==0:
    print('NA')
elif answer==1:
    print('YYMM')
elif answer==2:
    print('MMYY')
else:
    print('AMBIGUOUS')

Measured memory_bytes: 3064
# 後ろから見ていく
# N番目の箱の倍数は１つしかないため、確定できる。
# 後ろ半分は倍数の箱を持たない
# 後ろから
# これの繰り返し

n=int(input())
a=list(map(int,input().split()))
h=n//2

b=[-1]*h+a[h:]
for i in range(h,-1,-1):
  # 自分を除く自分の倍数を数える
  jsum=0
  for j in range((i+1)*2-1,len(b),i+1):
    jsum^=b[j]
  b[i]=a[i]^jsum

print(sum(b))
for i in range(n):
  if b[i]:
    print(i+1)

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

int main() {
    string str;
    cin >> str;
    bool ret = true;

    for (char c = 'a'; c <= 'z'; c++){
        int cou = count(str.begin(), str.end(), c);
        if (cou % 2 == 1){
            ret = false;
        }
    }

    if(ret){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

int main(){
    int N;  cin >> N;
    vector<pair<int,int>> ans;
    for(int i=1; i<=N; i++){
        for(int j=i+1; j<=N; j++){
            if(N%2==0 && (i+j)!=N+1){
                ans.push_back({i,j});
            }else if(N%2==1 && (i+j)!=N){
                ans.push_back({i,j});
            }
        }
    }

    cout << ans.size() << endl;
    for(auto p:ans){
        cout << p.first << " " << p.second << endl;
    }
}

Measured memory_bytes: 384
// Template
#include <bits/stdc++.h>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003LL;
template <typename T> inline bool chmin(T& x, const T& y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T& x, const T& y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;

// Fenwick Tree
struct FenwickTree {
    int length;
    vector<ll> node;
    FenwickTree (int N) : length(N), node(length + 1, 0) {}
    void add(int idx, ll val) {
        ++idx;
        while (idx <= length) {
            node[idx] += val;
            idx += (idx & (-idx));
        }
    }
    ll getsum(int idx) {
        ll ans = 0;
        while (idx) {
            ans += node[idx];
            idx -= (idx & (-idx));
        }
        return ans;
    }
};

// Main
int main() {
    int n, q;
    cin >> n >> q;
    FenwickTree fw(n);
    rep(i, n) {
        int a;
        cin >> a;
        fw.add(i, a);
    }
    rep(i, q) {
        int t, x, y;
        cin >> t >> x >> y;
        if (t == 0) fw.add(x, y);
        else cout << fw.getsum(y) - fw.getsum(x) << "\n";
    }
    return 0;
}


Measured memory_bytes: 8256
object Main {
  def main(args: Array[String]): Unit = {
    val scanner = new java.util.Scanner(System.in)

    while(true) {
      val m, f, r = scanner.nextInt

      if(m == -1 && f == -1 && r == -1) System.exit(0)
      if(m == -1 || f == -1 || m + f < 30) {
        println("F")
      } else if(m + f < 50 && r < 50) {
        println("D")
      } else if(m + f < 65) {
        println("C")
      } else if(m + f < 80) {
        println("B")
      } else {
        println("A")
      }
    }
  }
}


Measured memory_bytes: 45080
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(void){

  int n, ans = 0;
  
  cin >> n;
  
  vector<int> l(n);
  
  for(int i = 0;i < n;i++){
    cin >> l[i];
  }
  
  sort(l.begin(), l.end());
  
  int tmp;
  for(int i = 0;i < n-2;i++){
    for(int j = i+1;j < n-1;j++){
      tmp = l[i] + l[j];
      for(int k = j+1;k < n;k++){
        if(tmp > l[k]){
          ans++;
        }else{
          break;
        }
      }
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll a, b, n;
  cin >> a >> b >> n;
  ll t = min(b-1, n);
  cout << a*t/b << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define reg register
typedef long long ll;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
static char buf[100000],*p1=buf,*p2=buf;
inline int read(void){
	reg char ch=getchar();
	reg int res=0;
	while(ch<'0'||'9'<ch)ch=getchar();
	while('0'<=ch&&ch<='9')res=10*res+ch-'0',ch=getchar();
	return res;
}

const int MAXN=2000+5;

int n,m;
int f[MAXN*3][MAXN*4];

inline int add(reg int a,reg int b,reg int mod){
	reg int sum=a+b;
	return sum>=mod?sum-mod:sum;
}

int main(void){
	reg int n=read(),m=read();
	reg int Delta=n+1;
	f[0][Delta]=1;
	f[1][1+Delta]=1;
	f[2][-1+Delta]=1;
	f[2][2+Delta]=1;
	for(reg int i=3;i<=3*n;++i)
		for(reg int j=-n;j<=3*n;++j){
			f[i][j+Delta]=add(f[i][j+Delta],1ll*f[i-3][j+Delta]*(i-2)%m*(i-1)%m,m);
			f[i][j+Delta]=add(f[i][j+Delta],1ll*f[i-2][j+1+Delta]*(i-1)%m,m);
			f[i][j+Delta]=add(f[i][j+Delta],f[i-1][j-1+Delta],m);
		}
	reg int ans=0;
	for(reg int i=0;i<=n;++i)
		ans=add(ans,f[3*n][i*3+Delta],m);
	printf("%d\n",ans);
	return 0;
}

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

int main(int argc, const char * argv[]) {
    int H, W;
    char cells[100][100] = {0};
    
    cin >> H >> W;
    for (int h = 0; h < H; h++) {
        for (int w = 0; w < W; w++) {
            cin >> cells[w][h];
        }
    }
    
    for (int h = 0; h < H; h++) {
        for (int w = 0; w < W; w++) {
            cout << cells[w][h];
        }
        cout << endl;
        for (int w = 0; w < W; w++) {
            cout << cells[w][h];
        }
        cout << endl;
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep2(i,a,n) for(int i = (a);i < (n);i++)
#define rep(i,n) rep2(i,0,n)
#define INF (1LL << 60)
#define itn int

int main(void){
    int n;
    cin >> n;
    itn a[n];
    rep(i,n)cin >> a[i];
    
    ll ans = 1000;
    for(int i = 0;i < n-1;i++){
        if(a[i] < a[i+1]){
            ll katta = ans / a[i];
            ans += katta * (a[i+1] - a[i]);
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

typedef long long ll;

using namespace std;

int main(){
    int in,sum=0;
    
    for(int i=0;i<4;i++){
        scanf("%d",&in);
        sum+=in;
    }
    
    printf("%d\n%d\n",sum/60,sum%60);
    
    
    return 0;
}

Measured memory_bytes: 1188
x, k, d = gets.chomp.split.map(&:to_i)

shou = x.abs.div(d)

if k < shou
  p (x - (x.abs/x)*d*k).abs
  exit
end

hugo = x >= 0 ? 1 : -1
x = x - hugo*d*shou
k -= shou
if k.even?
  p x.abs
else
  p (x - hugo*d).abs
end

Measured memory_bytes: 14328
#include<stdio.h>
#include<string.h>
#include<iostream>
#define ll long long
using namespace std;

int hehe(int n){
    int ans=0;
    while(n)
    {
    ans+=n%10;n/=10;}
    return ans;
}

int main (){
    int m;
    scanf("%d",&m);
    int ans=0x3f3f3f3f;
    for(int i=1;i<m;i++){
        ans=min(hehe(i)+hehe(m-i),ans);
    }
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

struct UnionFind {
    UnionFind() {}
    UnionFind(int n) {
        resize(n);
    }
    
    void resize(int n) {
        par.resize(n, -1);
    }
    
    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    
    bool merge(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return false;
        if (par[rx] > par[ry]) swap(rx, ry);
        par[rx] += par[ry];
        par[ry] = rx;
        return true;
    }
    
    bool is_same(int x, int y) {
        return (root(x) == root(y));
    }
    
    int size(int x) {
        return -par[root(x)];
    }
    
private:
    vector<int> par;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, m, k;
    cin >> n >> m >> k;
    vector<set<ll>> ng(n);
    UnionFind uf(n);
    rep(i, m) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        ng[a].insert(b);
        ng[b].insert(a);
        uf.merge(a, b);
    }
    rep(i, k) {
        ll c, d;
        cin >> c >> d;
        c--; d--;
        ng[c].insert(d);
        ng[d].insert(c);
    }
    rep(i, n) {
        ll ans = uf.size(i);
        for(auto x : ng[i]) {
            if (uf.is_same(i, x)) {
                ans--;
            }
        }
        printf("%lld%s", ans - 1, (i == (n - 1)) ? "\n" : " ");
    }
    return 0;
}


Measured memory_bytes: 24704
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#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 int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout<<(x)<<endl
#define watch2(x,y) cout<<(x)<<" "<<(y)<<endl
#define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld; 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

const int INF = 9e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;

int i,n,p[N],dp[N];

void solve()
{
    cin>>n;
    for(i=1;i<=n;++i)
    {
        cin>>p[i];
        dp[i]=0;
    }
    int ans=0;
    for(i=1;i<=n;++i)
    {
        dp[p[i]]=1;
        dp[p[i]]=max(dp[p[i]],dp[p[i]-1]+1);
        ans=max(ans,dp[p[i]]);
    }
    cout<<n-ans;
}

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

Measured memory_bytes: 3328
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long a = sc.nextLong();
    long b = sc.nextLong();
    long c = a + b;


    long p = n/c;
    long q = n%c;

    if(q>a){
      q = a;
    }

    long ans = a * p + q;

    System.out.println(ans);
  }
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define DAYS 5000000000000000
using namespace std;

int main(void){
    string s;
    long long int k, tmp, cnt = 0;
    cin >> s >> k;
    for (int i=0; i<s.size(); i++){
        if (s[i] == '1') cnt++;
        else{
            for (int j=1; j<=DAYS; j++){
                tmp = pow(s[i] - '0', j);
                if (cnt + tmp >= k){
                    cout << s[i] << endl;
                    return 0;
                }
            }
            cnt += tmp;
        }
        if (cnt >= k){
            cout << s[i] << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 4216
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    string s;
    cin >> s;
    cout << "ABC" << s << endl;
    return 0;
}

Measured memory_bytes: 3648
# coding:utf-8

INF = float('inf')


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


D, G = inpl()
P, C = [], []
for i in range(D):
    p, c = inpl()
    P.append(p)
    C.append(c + 100 * (i + 1) * p)

ans = INF
for i in range(2 ** D):
    point = 0
    cnt = 0
    rest_max = 0
    for shift in range(D):
        if i >> shift & 1:
            cnt += P[shift]
            point += C[shift]
        else:
            rest_max = shift

    if point < G:
        for j in range(P[rest_max]):
            if point >= G:
                break
            cnt += 1
            point += (rest_max + 1) * 100
        else:
            continue

    ans = min(ans, cnt)

print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long i=0;i<n;i++)
typedef vector<long> vec;

double maxd(double a,double b){
if(a>b) return a;
return b;
}

int main(){
  long tri[1009]; long memo=0;
  tri[0]=0;
  rep(i,1000){memo++; tri[i+1]=tri[i]+memo;}//三角数を記録しておく
  
  long n,k;
  cin>>n>>k;
  
  double kt[200010]; long a; double b;
  rep(i,n){ cin>>a; b=a; kt[i]=tri[a]/b; }//期待値の配列、0から入ってる
  
  double s[200010]; s[0]=0;
  rep(i,n){ s[i+1]=s[i]+kt[i]; }//期待値の累積和
  
  double ans=0;
  
  rep(i,n-k+1){ ans=maxd(ans, s[k+i]-s[i] ); }
  
  cout << fixed << setprecision(10);
  cout<<ans;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
typedef pair<string,string> Ps;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	int x,y,sx,sy,cost;
};
int main() {

	ll a;
	cin>>a;

	string s;
	while(a>0){
		char c=a%26+96;
		if(a%26==0){
			s='z'+s;
			a/=26;
			a--;
		}else{
			s=c+s;
			a/=26;
		}
	}
	cout<<s<<endl;

	return 0;
}


Measured memory_bytes: 3612
// BEGINNING WITH THE NAME OF ALMIGHTY GOD ALLAH
// AUTHOR:: MOHAMMAD FAISAL
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
    cin >> a >> b >> c;
  	int res = 100*a + 10*b + c;
    (res%4==0) ? cout<<"YES": cout<<"NO";
    return 0;
}

Measured memory_bytes: 764
import sys
sys.setrecursionlimit(1000000)


def dfs_f(now, kyori):
    kyori_f[now] = kyori
    # 今いる頂点から行ける頂点を順に next に入れてループ
    for next in g[now]:
        # 行ったことがない、白く塗られていない
        if not memo_f[next] and next != n - 1:
            memo_f[next] = True
            dfs_f(next, kyori + 1)


def dfs_s(now, kyori):
    kyori_s[now] = kyori
    # 今いる頂点から行ける頂点を順に next に入れてループ
    for next in g[now]:
        # 行ったことがない、黒く塗られていない
        if not memo_s[next] and next != 0:
            memo_s[next] = True
            dfs_s(next, kyori + 1)


n = int(input())
g = [[] * n for i in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

# フェネック
memo_f = [False for i in range(n)]  # 訪れたことがあるか
kyori_f = [float("inf") for i in range(n)]  # 始点からの距離
memo_f[0] = True
dfs_f(0, 0)

# すぬけ
memo_s = [False for i in range(n)]  # 訪れたことがあるか
kyori_s = [float("inf") for i in range(n)]  # 始点からの距離
memo_s[n - 1] = True
dfs_s(n - 1, 0)

black = 0
white = 0
for i in range(n):
    if kyori_f[i] <= kyori_s[i]:
        black += 1
    else:
        white += 1

if black > white:
    print("Fennec")
else:
    print("Snuke")

Measured memory_bytes: 120516
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if ((abs(a - b) <= d && abs(b - c) <= d) || abs(a - c) <= d ) {
        cout << "Yes";
    } else cout << "No";
}


Measured memory_bytes: 3636