akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std ;
#define ulli unsigned long long int 
#define lli long long int
int mod = 1000000007 ;
/*ulli fact(int n){
    ulli ans = 1 ;
    for(int i=1;i<=n;i++){
        ans = (ans * (i%mod))%mod ;
        ans = ans%mod;
        ans = ans%mod ;
    }
    return ans%mod ;
}*/

void solve()
{    
   string s ;
   cin>>s ;
  if(s=="RRS" || s=="SRR"){
      cout<<2 ;
      return ;
  }
  else if(s=="SSS"){
      cout<<0 ;
      return ;
  }
  else if(s=="RRR"){
      cout<<3 ;
      return ;
  }
  cout<<1 ;
    return ;

}
int main()
{   
    cin.tie(0);
	ios_base::sync_with_stdio(false);  
    int t ;
    t = 1 ;
    while(t--)
        solve() ;
    return 0; 
}

Measured memory_bytes: 3648
#include <string>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,h[100005];
ll dp[100005];
/*
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a. != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}
*/
int main(){


	long long N,M;
    std::cin >> N >> M;
  
    vector<pair<long long, long long> > pairs(N);

    // 入力
    for(long long i=0; i<N; i++){
        long long a, b;
        cin >> a >> b;
        pairs[i] = make_pair(a, b);
    }

    // b順にソート
    //sort(ALL(pairs), compare_by_b);
	//sort(pairs.begin(), pairs.end(),greater<pair<int,int> >());
	sort(pairs.begin(), pairs.end());
    /*
    for(int i=0; i<N; i++){
	printf("%d",pairs[i].first);
	printf("%d\n",pairs[i].second);
	}
	*/
    long long sum;
    sum=0;
    long long ans;
    ans=0;
    long long j;
    j=0;
    for(long long i=0; i<N; i++){
		while(j<pairs[i].second){
			if(pairs[i].second+sum<M){
				sum+=pairs[i].second;
				ans+=pairs[i].first*pairs[i].second;
				break;
			}
			else{	
				
				ans+=pairs[i].first;
				sum++;
				j++;
				if(sum==M){
					printf("%lld\n",ans);
					return 0;
				}
				
				//printf("%lld\n",);
				
			}
		}		
		j=0;
		
	}
	
}

Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.nextLine());
		int[][] map = new int[2][n];
		for (int i = 0; i < 2; i++) {
			String[] inputs = sc.nextLine().split(" ");
			for (int j = 0; j < n; j++) {
				map[i][j] = Integer.parseInt(inputs[j]);
			}
		}
		ArrayList<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < n; i++) {
			int count = 0;
			for (int j = 0; j <= i; j++) {
				count += map[0][j];
			}
			for (int k = i; k < n; k++) {
				count += map[1][k];
			}
			list.add(count);
		}

		System.out.println(Collections.max(list));

	}
}


Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define n_l '\n'
#ifndef ONLINE_JUDGE
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; cout << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)),  __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgm(T...); } 
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl
#endif
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef double db;
typedef vector<vi> vvi;
const ll mod=1000000007;
const ll N=200005; //check this
const ll inf = 1e15;
ll powmod(ll a,ll b) {if(b<0)b=mod-1+b;ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll powb(ll a,ll b) {ll res=1;a ; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a;a=a*a;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

ll dp[N];
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif
    ll n,k;cin>>n>>k;
    dp[k]=1;
    for(ll i=k-1;i>=1;i--){
    	dp[i]=powmod(k/i,n);
    	for(ll j=2LL*i;j<=k;j+=i)
    		dp[i]=((dp[i]-dp[j])%mod+mod)%mod;
    }
    ll ans=0;
    for(int i=1;i<=k;i++){
    	(ans+=dp[i]*i*1LL)%=mod;
    }
    cout<<ans;
}


Measured memory_bytes: 4352
X,K,D=map(int, input().split())
X = abs(X)
if X > K*D:
    print(abs(X)-K*D)
else:
    n = X // D
    r = K-n
    m = X - D * n
    if r % 2 == 0:
        print(m)
    else:
        print(D-m)


Measured memory_bytes: 9172
n = int(input())
rev = list(range(int(n**(1/2))+1))
rev = sorted(rev, reverse=True)
factor = 0
for i in rev:
    if n%i==0:
        factor=i
        break

def order(n):
    count = 0
    while n>0:
        n= n//10
        count += 1
    return count 

res = order(n//factor)
print(res)

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

using namespace std;

bool check(vector<int> &a, int mid) {
  int value = a[0];
  for (int i = 2; i < a.size(); i += 2) {
    if (value >= mid) {
      value = max(value + a[i] - a[i - 1], a[i]);
    } else {
      value += a[i] - a[i - 1];
    }
  }
  return value >= mid;
}

int main() {
#ifdef wxh010910
  freopen("input.txt", "r", stdin);
#endif
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  int sum = 0, black = 0, white = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    sum += a[i];
    if (i & 1) {
      white += a[i];
    } else {
      black += a[i];
    }
  }
  if (!(n & 1)) {
    printf("%d %d\n", max(black, white), min(black, white));
  } else {
    int l = 0, r = black, result = 0;
    while (l <= r) {
      int mid = l + r >> 1;
      if (check(a, mid)) {
        result = mid;
        l = mid + 1;
      } else {
        r = mid - 1;
      }
    }
    printf("%d %d\n", white + result, black - result);
  }
  return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
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; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));


signed main() {
	int N, K;
	cin >> N >> K;
	vector<int>A(N);
	rep(i, N)cin >> A[i];
	rep(i, N)A[i]--;
	vector<bool>seen(N, false);
	int now = 0;
	seen[0] = true;
	vector<int>loop;
	loop.push_back(0);
	int num;
	while (1) {
		int next = A[now];
		if (seen[next]) {
			num = next;
			break;
		}
		loop.push_back(next);
		seen[next] = true;
		now = next;
	}
	if (loop.size() == 1) {
		cout << 1;
		return 0;
	}
	vector<int>v;
	rep(i, loop.size()) {
		if (loop[i] == num) {
			while (i < loop.size()) {
				v.push_back(loop[i]);
				i++;
			}
		}
	}
	rep(i, loop.size() - 1) {
		if (loop[i] == num)break;
		if (K == 1) {
			if (i + 1 < loop.size())cout << loop[i + 1] + 1;
			return 0;
		}
		K--;
	}
	int len = v.size();
	cout << endl;
	int ans = K % len;
	cout << v[ans] + 1;
}

Measured memory_bytes: 9232
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    ll a, b, c;
    cin >> a >> b >> c;

    if (c - a - b < 0)
    {
        cout << "No" << endl;
        return 0;
    }

    if (4 * a * b < (c - a - b) * (c - a - b))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int  A,B,K;
    cin>>A>>B>>K;
    for (int i=min(A,B);i>=1;--i){
        if(A%i==0&&B%i==0){
         --K;
        if(K==0){
         cout<<i<<endl;
         return 0;
         }
        }
      }
    assert(false);
    }


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

int main() {
  int n;
  cin >> n;
  vector<tuple<int, int, int>> as;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    as.emplace_back(a + b, a, b);
  }
  sort(as.rbegin(), as.rend());
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      ans += get<1>(as[i]);
    } else {
	  ans -= get<2>(as[i]);
    }
  }
  cout << ans << endl;
}


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

#define ll long long
#define MOD 1000000007
#define MAX 1000000



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

    vector<ll> table(1000001,-1);

    ll a,co;
    for(ll i=0;i<n;i++){
        co=2;
        cin>>a;
        if(table.at(a)==1)continue;
        if(table.at(a)==0){
            table.at(a)=1;
            continue;
        }
        table.at(a)=0;
        while(table.size()>a*co){
            table.at(a*co)=1;
            co++;
        }
    }

    int ans=0;
    for(ll i=1;i<1000001;i++){
        if(table.at(i)==0)ans++;
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 11188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool sieve[(int)1e6+3];
int cnt[(int)1e6+3];
int main(){
	int n;
	cin >> n;
	set<int> ar;
	for(int i=0;i<n;i++){
		int a;
		cin >> a;
		ar.insert(a);
		cnt[a]++;
	}
	int ans = 0;
	for(auto it : ar){
		if(sieve[it]) continue;
		for(int i=it+it;i<(int)1e6+3;i+=it) sieve[i] = 1;
		if(cnt[it] == 1) ans++;
	}
	cout << ans << '\n';
}

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

using namespace std;

typedef long long ll;

int main(){
 ll N; cin >> N;
  vector<ll> A(N); ll cnt = 0;
  for(ll i = 0; i < N; i++){
    cin >> A[i];}
  int flag = 0;
  for(ll i = 0; i < N - 1; i++){
    if( flag == 0){
      if( A[i+1] > A[i]){ flag = 1;}
      else if( A[i+1] < A[i]){ flag = -1;}
    }
    
    else if( flag == 1){
      if( A[i+1] < A[i]){ flag = 0; cnt++;}
    }
    
    else if( flag == -1){
      if( A[i+1] > A[i]){ flag = 0; cnt++;}
    }
  }
  
  cout << cnt + 1 << endl; return 0;}
      
      
      

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

int n, a, b, c;
int l[10];
int ans = 1001001001;

void dfs(int now, int a_num, int a_sum, int b_num, int b_sum, int c_num, int c_sum) {
  if (now == n) {
    if (a_num == 0 || b_num == 0 || c_num == 0) return;

    int sum = 0;
    
    sum += (a_num - 1) * 10 + (b_num - 1) * 10 + (c_num - 1) * 10;
    sum += abs(a - a_sum) + abs(b - b_sum) + abs(c - c_sum);

    ans = min(ans, sum);
    return;
  }

  dfs(now + 1, a_num + 1, a_sum + l[now], b_num, b_sum, c_num, c_sum);
  dfs(now + 1, a_num, a_sum, b_num + 1, b_sum + l[now], c_num, c_sum);
  dfs(now + 1, a_num, a_sum, b_num, b_sum, c_num + 1, c_sum + l[now]);
  dfs(now + 1, a_num, a_sum, b_num, b_sum, c_num, c_sum);

}

int main(void) {
  
  cin >> n >> a >> b >> c;
  rep (i, n) cin >> l[i];

  dfs(0, 0, 0, 0, 0, 0, 0);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
using System;

namespace _0565
{
	class mogmog
	{
		static void Main(string[] args)
		{
			int i, j;
			string[] pasta;
			int[] pfee;
			pasta = new string[3];
			pfee = new int[3];
			string[] drink;
			drink = new string[2];
			int[] dfee;
			dfee = new int[2];
			int mp, md;

			for (i = 0; i < 3; i++)
			{
				pasta[i] = Console.ReadLine();
				pfee[i] = Convert.ToInt32(pasta[i]);
			}
			for (j = 0; j < 2; j++)
			{
				drink[j] = Console.ReadLine();
				dfee[j] = Convert.ToInt32(drink[j]);
			}

			if(pfee[1] > pfee[0] && pfee[2] > pfee[0])
			{
				mp = pfee[0];
			}
			else if(pfee[0] > pfee[1] && pfee[2] > pfee[1])
			{
				mp = pfee[1];
			}
			else mp = pfee[2];
			
			if (dfee[1] > dfee[0])
			{
				md = dfee[0];
			}
			else md = dfee[1];

			int set = mp + md - 50;
			Console.WriteLine(set);
		}
	}
}

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

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> s(M);
    vector<int> c(M);
    vector<int> t(N,-1);
    if(N == 1 && M == 0){
        cout << 0 << endl;
        return 0;
    }
    rep(i,M){
        cin >> s[i] >> c[i];
    }
    rep(i,M){
        if(s[i] == 1 && c[i] == 0){
            if(N>1){
                cout << -1 <<endl;
            }else{
                cout << 0 << endl;
            }
            return 0;
        }
    }
    bool ok=true;
    rep(i,M){
        if(t[s[i]-1] == -1){
            t[s[i]-1] = c[i];
        }else{
            if(t[s[i]-1] != c[i]){
                ok = false;
            }
        }
    }
    if(!ok){
        cout << -1 << endl;
        return 0;
    }
    rep(i,N){
        if(t[i] != -1){
            cout << t[i];
        }else if(i != 0){
            cout << 0;
        }else{
            cout << 1;
        }
    }
    cout << endl;
}


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

int main() {
	
	string s;
	cin >> s;
	vector<int> v(s.size());
	int count_R = 0, count_L = 0, RL;
	
	for(int i=0; i<s.size()-1; i++){
		if(s[i] == 'R'){
			if(s[i+1] == 'R'){
				count_R++;
			}else{
				v.at(i) += count_R/2 + 1;
				v.at(i+1) += (count_R + 1)/2 + 1;
				RL = i;
				count_R = 0;
			}
		}else{
			if(s[i+1] == 'L'){
				count_L++;
			}else{
				v.at(RL) += (count_L + 1)/2;
				v.at(RL+1) += count_L/2;
				count_L = 0;
			}
		}
	}
	if(count_L > 0){
		v.at(RL) += (count_L + 1)/2;
		v.at(RL+1) += count_L/2;
	}
	
	rep(i, s.size()){
		cout << v.at(i) << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int b[4][4],n,a[102];
bool f[4][4];
int main()
{
	int i,j,k;
	for(i=1;i<=3;i++)for(j=1;j<=3;j++)cin>>b[i][j];
	cin>>n;
	for(k=1;k<=n;k++)
	{
		cin>>a[k];
		for(i=1;i<=3;i++)for(j=1;j<=3;j++)if(b[i][j]==a[k])f[i][j]=1;
	}
	if(f[1][1]+f[1][2]+f[1][3]==3)
	{
		cout<<"Yes";
		return 0;
	}
	else if(f[2][1]+f[2][2]+f[2][3]==3)
	{
		cout<<"Yes";
		return 0;
	}
	else if(f[3][1]+f[3][2]+f[3][3]==3)
	{
		cout<<"Yes";
		return 0;
	}
	else if(f[1][1]+f[2][1]+f[3][1]==3)
	{
		cout<<"Yes";
		return 0;
	}
	else if(f[1][2]+f[2][2]+f[3][2]==3)
	{
		cout<<"Yes";
		return 0;
	}
	else if(f[1][3]+f[2][3]+f[3][3]==3)
	{
		cout<<"Yes";
		return 0;
	}
	else if(f[1][1]+f[2][2]+f[3][3]==3)
	{
		cout<<"Yes";
		return 0;
	}
	else if(f[1][3]+f[2][2]+f[3][1]==3)
	{
		cout<<"Yes";
		return 0;
	}
	cout<<"No";
	return 0;
}

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

const int N = 50 + 5;
int n,m;

vector<int> adj[N]; // adjacency list of graph

vector<bool> visited;
vector<int> tin, low;
int timer, cnt;

void dfs(int v, int p = -1) {
    visited[v] = true;
    tin[v] = low[v] = timer++;
    for (int to : adj[v]) {
        if (to == p) continue;
        if (visited[to]) {
            low[v] = min(low[v], tin[to]);
        } else {
            dfs(to, v);
            low[v] = min(low[v], low[to]);
            if (low[to] > tin[v]) cnt++;
        }
    }
}

void find_bridges() {
    timer = 0;
    visited.assign(n, false);
    tin.assign(n, -1);
    low.assign(n, -1);
    for (int i = 0; i < n; ++i) {
        if (!visited[i])
            dfs(i);
    }
}

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n>>m;
    int a,b;
    for (int i = 1; i <= m; i++){
        cin>>a>>b;
        a--, b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    
    
    find_bridges();
    cout<<cnt<<endl;
    
    return 0;
}



Measured memory_bytes: 256
//Multiple Array

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
#define cout15(a) printf("%.15f\n",a)
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<ll,ll> p;
using g = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int n;cin>>n;
    vector<p>q;
    int ans = 0;
    rep(i,0,n){
        int a,b;cin>>a>>b;
        q.pb(mp(a,b));
    }
    reverse(range(q));
    rep(i,0,n){
        if((q[i].first+ans)%q[i].second!=0){
            ans+=q[i].second-((ans+q[i].first)%q[i].second);
        }
    }
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, k;
    cin>>n>>k;
    int sum=0;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    sort(a.begin(), a.end());
    for(int i=0; i<k; i++){
        sum+=a[i];
    }
    cout<<sum<<'\n';
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
ll a[N], s[N];
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i]--;
	}
	if (k == 1)
		return cout << 0, 0;
	ll ans = 0, sum = 0;
	queue<ll> q;
	q.push(0);
	map<ll, ll> mp;
	mp[0] = 1;
	for (int i = 0; i < n; i++) {
		sum += a[i];
		ans += mp[sum % k];
		mp[sum % k]++;
		q.push(sum);
		if (q.size() >= k) {
			mp[q.front() % k]--;
			q.pop();
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

constexpr int inf = 1e9;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H,W;
    cin >> H >> W;
    vec<int> A(H),B(H);
    set<pair<int,int>> s;
    multiset<int> ms;
    for(int i=0;i<H;i++){
        cin >> A[i] >> B[i];
        A[i]--, B[i]--;
    }
    for(int i=0;i<W;i++){
        ms.insert(0);
        s.insert({i,-i});
    }
    for(int k=0;k<H;k++){
        auto it = s.upper_bound({A[k],-inf});
        while(it!=s.end()){
            auto [en,st] = *it;
            if(en>B[k]) break;
            int ne = (B[k]!=W-1? B[k]+1:inf);
            s.insert({ne,st});
            ms.insert(ne+st);
            it = s.erase(it);
            ms.erase(ms.find(en+st));
        }
        if(B[k]!=W-1){
            it = s.upper_bound({B[k]+1,-inf});
            it++;
            while(it!=s.end()){
                auto [en,st] = *it;
                if(en>B[k]+1) break;
                it = s.erase(it);
                ms.erase(ms.find(en+st));
            }
        }
        int res = *ms.begin()+k+1;
        cout << (res>H+W? -1:res) << "\n";
    }
}

Measured memory_bytes: 23484
#include <cstdio>
#include <cmath>
#define LL long long

int main() {
	LL n, p;
	scanf("%lld%lld", &n, &p);
	LL ans = 1;
	LL cnt = 0;
	if (n == 1) {
		printf("%lld", p); return 0;
	}
	
	for (LL i = 2; i * i <= p; i++) {
		if (p % i == 0) {
			int cnt = 0;
			while (p % i == 0) {
				cnt++;
				p /= i;
				if (cnt % n == 0) ans *= i;
			}
		}
		if (p == 1) break;
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define REP1(i,n) for(int i=1; i<=(int)(n); i++)
#define SORT(v) sort(v.begin(), v.end())
#define REVERSE(v)  reverse(v.begin(), v.end())
using namespace std;

int main() {
  int N; cin>>N;
  int ans = 111;
  bool found = false;
  while(!found) {
    if(ans - 111 < N && N <= ans)  found = true;
    else ans += 111;
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n, k;
  cin >> n >> k;
  vector<int> l(n);
  for (int i = 0; i < n; i++)
    cin >> l[i];
  sort(l.begin(), l.end());
  int ans = 0;
  for (int i = n - k; i < n; i++)
    ans += l[i];
  cout << ans << endl;
  return 0;
}


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

using namespace std;
using namespace atcoder;

int main(){
    int N;
    cin>>N;
    dsu d(N+1);
    pair<int,int> p[N];
    pair<int,int> p2[N];
    int iny[N];
    int inx[N+1];
    for(int i=0;i<N;i++){
        int x,y;
        cin>>x>>y;
        pair<int,int> tmpp;
        tmpp.first=x;
        tmpp.second=y;
        p[i]=tmpp;
        iny[i]=y;
        tmpp.first=y;
        tmpp.second=x;
        p2[i]=tmpp;
        inx[x]=y;
    }

    sort(p,p+N);
    sort(p2,p2+N);

    int NM=N;
    for(int i=0;i<N;i++){
        int py=p[i].second;
        for(int j=py+1;j<=NM;j++){
            //cout<<py<<","<<j<<endl;
            d.merge(py,j);
        }
        NM=min(py-1,NM);
    }
    NM=1;
    for(int i=N-1;i>=0;i--){
        int py=p[i].second;
        for(int j=py-1;j>=NM;j--){
           // cout<<py<<"/"<<j<<endl;
            d.merge(py,j);
        }
        NM=max(py+1,NM);
    }

    NM=N;
    for(int i=0;i<N;i++){
        int px=p2[i].second;
        //cout<<px<<endl;
        for(int j=px+1;j<=NM;j++){
            //cout<<p2[i].first<<","<<inx[j]<<endl;
            d.merge(p2[i].first,inx[j]);
        }
        NM=min(px-1,NM);
    }
    NM=1;
    for(int i=N-1;i>=0;i--){
        int px=p2[i].second;
        for(int j=px-1;j>=NM;j--){
            //cout<<p2[i].first<<","<<inx[j]<<endl;
            d.merge(p2[i].first,inx[j]);
        }
        NM=max(px+1,NM);
    }


    int ans[N];
    for(int i=0;i<N;i++){
        ans[i]=d.size(i+1);
    }
    for(int i=0;i<N;i++){
        cout<<ans[iny[i]-1]<<endl;
    }
}


Measured memory_bytes: 9636
// #include<iostream>
// #include<vector>
// #include<algorithm>
// #include<map>
// #include<cstring>
// #include<math.h>
// #include<bitset>
// #include<queue>
// #include<set>
// #include<iomanip>
// #include<math.h>
// #include<assert.h>
// #include<string>
// #include<cstdlib>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr ll INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
}
// ----------------------------------------------------------------------------

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  ll sum=0;
  for(int i=0; i<N; i++){
    cin >> a[i];
    sum += a[i];
  }
  vector<ll> S(N+1,0);
  for(int i=0; i<N; i++){
    S[i+1] = S[i] + a[i];
  }
  ll ans = INF;
  for(int i=1; i<N; i++){
    ll x,y;
    x = S[i];
    y = sum-S[i];
    chmin(ans,abs(x-y));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

int main(){
	int n;
	cin>>n;
	vector<string> s(n);
	rep(i, n) cin>>s[i];
	int cnt = 0;
	bool f = true;
	rep(i, n) {
		if(s[i]=="A") cnt++;
		else cnt--;
		if(cnt < 0) f = false;
	}
	f &= cnt == 0;
	cout<<(f?"YES":"NO")<<endl;
}

Measured memory_bytes: 3168
//
// Copyright 2018 Authors All Rights Reserved.
//
// FileName: E.cpp
// Author: Beiyu Li <sysulby@gmail.com>
// Date: 2018-05-12
//
#include <bits/stdc++.h>

using namespace std;

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

typedef long long LL;
typedef pair<int, int> Pii;

const int inf = 0x3f3f3f3f;
const LL infLL = 0x3f3f3f3f3f3f3f3fLL;

const int maxn = 2000 + 5;

int n;
int p[2][maxn];
int c[3][maxn*2];
int f[maxn][maxn];

void update(int o, int i, int v)
{
  for (; i <= 2 * n; i += (i & -i)) c[o][i] += v;
}

int query(int o, int i)
{
  int ret = 0;
  for (; i; i -= (i & -i)) ret += c[o][i];
  return ret;
}

int main(int argc, char *argv[])
{
  scanf("%d", &n);
  For(i,1,2*n) {
    char buf[2];
    int a;
    scanf("%s%d", buf, &a);
    p[buf[0]=='B'][a] = i;
    update(0, i, 1);
  }
  For(i,0,n) {
    memcpy(c[1], c[0], sizeof(c[0]));
    if (i) update(0, p[0][i], -1);
    memcpy(c[2], c[0], sizeof(c[0]));
    For(j,i==0,n) {
      f[i][j] = inf;
      if (i) {
        if (j) update(1, p[1][j], -1);
        f[i][j] = min(f[i][j], f[i-1][j] + query(1, p[0][i] - 1));
      }
      if (j) {
        f[i][j] = min(f[i][j], f[i][j-1] + query(2, p[1][j] - 1));
        update(2, p[1][j], -1);
      }
    }
  }
  printf("%d\n", f[n][n]);

  return 0;
}

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

int main(){
  int N,M,P;
  while(cin>>N>>M>>P){
    if(N==0&&M==0&&P==0)return 0;
    int X[1000],sum=0;
    rep(i,N){
     cin>>X[i];
     sum+=100*X[i];
    }
    sum=sum-sum*P/100;
    rep(i,N+1){
      if(M==i){
        if(X[i-1]!=0){
         cout<<sum/X[i-1]<<endl;
	}else {
          cout<<0<<endl;          
	}
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3068
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}

typedef long long lint;

using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	lint n,k;
	cin>>n>>k;
	vector<lint>h(n);
	rep(i,n)cin>>h[i];
	sort(all(h));
	lint ans=LLONG_MAX;
	rep(i,n){
		if(n<=i+k-1)continue;
		chmin(ans,h[i+k-1]-h[i]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k  =sc.nextInt();
		int ans= k;
		
		for(int i=1;i<n;i++){
			ans *= k-1;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23252
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var xab = ReadSplitInt();
            if (Abs(xab[0] - xab[1]) > Abs(xab[0] - xab[2]))
                Println("B");
            else
                Println("A");
        }


        static List<long> ReadLines(long n)
        {
            var l = new List<long>();
            for (long i = 0; i < n; i++)
            {
                l.Add(ReadLong());
            }
            return l;
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b);
        static long Lcm(long a, long b) => a / Gcd(a, b) * b;

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}


Measured memory_bytes: 13268
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7; //924844033 1000000000 + 9;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, p, q, last, first, cnt, sum, ans, a[200020], b[220000],pa[220000];
string str, ss;
bool f[220000];
char c[4000][4000];
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Edge { LL to, cost; };
struct edge {
	LL from, to, cost;
};
vector<vector<Edge>>vec,rvec;
vector<edge>ed;
vector<LL>v;
vector<vector<LL>>d;
map<string, LL>ma;
set<LL>st;

void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
LL dfs1(LL cur, LL par){
	LL ret = 1;
	rep(i,vec[cur].size()) {
		Edge e = vec[cur][i];
		if (e.to == par) continue;
		d[cur][i] = dfs1(e.to, cur);
		(ret *= (1 + d[cur][i])) %= m;
	}
	return ret;
}
//根をrとし、その子の一つをc1とすると、r→c1の通り数はdfs1で出ているが
//c1→rの通り数は出ていないため、dfs2のpで伝播させている
//全方位木dp
void dfs2(LL cur, LL pre, LL p) {
	rep(i, vec[cur].size()) if (pre == vec[cur][i].to)d[cur][i] = p;
	vector<LL>L(vec[cur].size()), R(vec[cur].size());
	rep(i, vec[cur].size()) {
		L[i] = (i ? L[i - 1] : 1)* (d[cur][i] + 1) % m;
	}
	for (int i = vec[cur].size()-1; i >= 0; i--) {
		R[i] = (i == vec[cur].size() - 1 ? 1 : R[i + 1])*(d[cur][i] + 1) % m;
		if (vec[cur][i].to != pre) {
			LL ret = (i ? L[i - 1] : 1)*(i == vec[cur].size() - 1 ? 1 : R[i + 1])%m;
			dfs2(vec[cur][i].to, cur, ret);
		}
	}
}

int main() {
	cin >> n >> m;
	vec.resize(n);
	d.resize(n);
	rep(i, n - 1) {
		LL x, y;
		cin >> x >> y;
		x--, y--;
		vec[x].push_back(Edge{ y,1 });
		vec[y].push_back(Edge{ x,1 });
	}
	rep(i, n) d[i].resize(vec[i].size());
	dfs1(0, -1);
	dfs2(0, -1, 0);
	rep(i, n) {
		LL ret = 1;
		rep(j, vec[i].size())(ret *= (d[i][j] + 1)) %= m;
		cout << ret << endl;
	}
	return 0;
}


Measured memory_bytes: 26112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
const ll INFLL=LLONG_MAX;
const int INF=INT_MAX;
const ll MAXLL=0x3f3f3f3f3f3f3f3f;
const int MAX=0x3f3f3f3f;
#define eb emplace_back
#define emp emplace
#define mp(a,b) make_pair(a,b)
template<class T> using min_heap=priority_queue<T,vector<T>,greater<T> >;
template<class T>
void sort(vector<T>& v){
	sort(v.begin(),v.end());
}
template <class T, class U>
void sort(vector<T>& v,U func){
	sort(v.begin(),v.end(),func);
}
template <class T>
int lb_index(vector<T>& v,T k){
	return lower_bound(v.begin(),v.end(),k)-v.begin();
}
template <class T>
int ub_index(vector<T>& v,T k){
	return upper_bound(v.begin(),v.end(),k)-v.begin();
}
struct flow{
	int n,s,t;
	const long long MAXVAL=0x3f3f3f3f3f3f3f3f;
	struct edge{
		int from,to;
		long long cap,cost;
		edge(int u,int v,long long c,long long w):from(u),to(v),cap(c),cost(w){}
		edge(int u,int v,long long c):from(u),to(v),cap(c){
			cost=0;
		}
	};
	vector<edge>e;
	vector<vector<int> >adj;
	vector<long long>dist;
	vector<int>par;
	vector<bool>inq;
	void spfa(){
		fill(dist.begin(),dist.end(),MAXVAL);
		fill(inq.begin(),inq.end(),0);
		fill(par.begin(),par.end(),0);
		queue<int>q;
		dist[s]=0;
		q.emplace(s);
		while(!q.empty()){
			int u=q.front();
			q.pop();
			inq[u]=0;
			for(auto i:adj[u]){
				if(e[i].cap<=0)continue;
				int v=e[i].to;
				long long l=e[i].cost;
				if(dist[u]+l<dist[v]){
					dist[v]=dist[u]+l;
					par[v]=i;
					if(!inq[v])q.emplace(v),inq[v]=1;
				}
			}
		}
	}
	long long augcost(){
		long long curflow=MAXVAL;
		for(int u=t;u!=s;u=e[par[u]].from){
			curflow=min(curflow,e[par[u]].cap);
		}
		for(int u=t;u!=s;u=e[par[u]].from){
			e[par[u]].cap-=curflow;
			e[par[u]^1].cap+=curflow;
		}
		return curflow;
	}
	flow(int n,int s,int t):n(n),s(s),t(t),dist(n),inq(n),par(n),adj(n){}
	void addedge(int u,int v,long long c,long long w){
		adj[u].emplace_back(e.size());
		e.emplace_back(u,v,c,w);
		adj[v].emplace_back(e.size());
		e.emplace_back(v,u,0,-w);
	}
	void addedge(int u,int v,long long c){
		adj[u].emplace_back(e.size());
		e.emplace_back(u,v,c);
		adj[v].emplace_back(e.size());
		e.emplace_back(v,u,0);
	}
	void setflow(long long k){
		int ns=n++;
		adj.resize(n);
		dist.resize(n);
		inq.resize(n);
		par.resize(n);
		addedge(ns,s,k,0);
		s=ns;
	}
	pair<long long,long long> getflow(){
		long long maxflow=0,cost=0;
		for(;;){
			spfa();
			if(dist[t]==MAXVAL)break;
			long long f=augcost();
			maxflow+=f;
			cost+=dist[t]*f;
		}
		return {maxflow,cost};
	}
};
int main(){
	int x,y,e;
	cin>>x>>y>>e;
	flow f(x+y+2,x+y,x+y+1);
	for(int i=0;i<x;i++){
		f.addedge(x+y,i,1);
	}
	for(int i=0;i<y;i++){
		f.addedge(x+i,x+y+1,1);
	}
	while(e--){
		int l,r;
		cin>>l>>r;
		f.addedge(l,x+r,1);
	}
	cout<<f.getflow().fi<<"\n";
}



Measured memory_bytes: 3884
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef pair<int, int> P;

int main(){
  int n, m;
  cin >> n >> m;
  vector<P> sc(m);
  bool flag1 = true, flag2 = false;
  
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    sc.at(i) = make_pair(s, c);
    if (s == 1) {
      flag1 = false;
      if (n != 1 && c == 0) flag2 = true;
    }
  }
  
  if (flag2) {
    cout << -1;
    return 0;
  }
  
  vector<bool> fl(m, true);
  
  for (int i = 0; i < m; i++) {
    P fsc = sc.at(i);
    for (int j = i + 1; j < m; j++) {
      P ssc = sc.at(j);
      if (fsc.first == ssc.first) {
        if (fsc.second != ssc.second) {
          cout << -1;
          return 0;
        } else fl.at(j) = false;
      }
    }
  }
  
  int ans = 0;
  for (int i = 0; i < m; i++) {
    P p = sc.at(i);
    if (fl.at(i)) ans += p.second * pow(10, (n - p.first));
  }
  if (flag1 && n != 1) ans += 1 * pow(10, (n - 1));
  
  cout << ans;
  return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  char S[H][W];
  //入力
  for( int i = 0; i < H; ++i ){
    for( int j = 0; j < W; ++j ){
      cin >> S[i][j];
    }
  }
  
  //出力
  for( int i = 0; i < H; ++i ){
    for( int j = 0; j < W; ++j ){
      int count = 0;
      if( S[i][j] == '#' ){
        cout << '#';
        continue;
      }
      //自マスの左上に爆弾があるか
      if( S[i - 1][j - 1] == '#' ){
        if( i - 1 >= 0 && j - 1 >= 0 ){
          ++count;
        }
      }
      //自マスの上に爆弾があるか
      if( S[i - 1][j] == '#' ){
        if( i - 1 >= 0 ){
          ++count;
        }
      }
      //自マスの右上に爆弾があるか
      if( S[i - 1][j + 1] == '#' ){
        if( i - 1 >= 0 && j + 1 < W ){
          ++count;
        }
      }
      //自マスの左に爆弾があるか
      if( S[i][j - 1] == '#' ){
        if( j - 1 >= 0 ){
          ++count;
        }
      }
      //自マスの右に爆弾があるか
      if( S[i][j + 1] == '#' ){
        if( j + 1 < W ){
          ++count;
        }
      }
      //自マスの左下に爆弾があるか
      if( S[i + 1][j - 1] == '#' ){
        if( i + 1 < H && j - 1 >= 0 ){
          ++count;
        }
      }
      //自マスの下に爆弾があるか
      if( S[i + 1][j] == '#' ){
        if( i + 1 < H ){
          ++count;
        }
      }
      //自マスの右下に爆弾があるか
      if( S[i + 1][j + 1] == '#' ){
        if( i + 1 < H && j + 1 < W ){
          ++count;
        }
      }
      cout << count;
    }
    cout << endl;
  }
}


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

int main() {
  set<int> s;

  int a, b, k;
  cin >> a >> b >> k;
  for (int i = a; i <= min(a + k - 1, b); i++)
    s.insert(i);
  for (int i = b; i >= max(b - k + 1, a); i--)
    s.insert(i);

  for (int h : s)
    cout << h << endl;
}

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

using namespace std;

void c()
{
    int n;
    string s;
    cin >> n;
    cin >> s;
    vector<int> wcount(n, 0);
    vector<int> ecount(n, 0);
    if(s.front() == 'W')
    {
        wcount[0] = 1;
    }else{
        ecount[0] = 1;
    }
    for(int i = 1; i < n; i++)
    {
        if(s[i] == 'W')
        {
            wcount[i] = wcount[i - 1] + 1;
        }else{
            wcount[i] = wcount[i - 1];
        }
        if(s[i] == 'E')
        {
            ecount[i] = ecount[i - 1] + 1;
        }else{
            ecount[i] = ecount[i - 1];
        }
    }
    int max_count = n;
    if(s.front() == 'W')
    {
        max_count = ecount.back();
    }else{
        max_count = wcount.back();
    }
    for(int i = 1; i < n; i++)
    {
        int temp = wcount[i - 1] + (ecount[n - 1] - ecount[i]);
        max_count = min(temp, max_count);
    }
    cout << max_count << endl;
}

int main() {
    int n;
    cin >> n;
    vector<unsigned int> a(n, 0);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    map<int, int> c;
    for(int i = 0; i < n; i++)
    {
        if(a[i] != 0)
        {
            c[i] = i;
        }else{
           int length = 1;
           for(int j = i + 1; j < n; j++)
           {
               if(a[j] == 0)
               {
                   length++;
               }else{
                   break;
               }
           }
           for(int j = i; j < i + length; j++)
           {
               c[j] = i + length - 1;
           }
           i += length - 1;
        }
    }
    long long int result = n;
    for(int i = 0; i < n; i++)
    {
        unsigned int sum = a[i];
        unsigned int xsum = a[i];
        int length = 1;
        for(int j = i + 1; j < n; j++) {
            if(a[j] == 0)
            {
                length += (c[j] - j) + 1;
                j = c[j];
            } else {
                unsigned int temp = sum + a[j];
                unsigned int tempx = xsum ^a[j];
                if (temp == tempx) {
                    sum = temp;
                    xsum = tempx;
                    length++;
                } else {
                    break;
                }
            }
        }
        result += length - 1;
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
//priority_queue<int, vector<int>, greater<int> > pq;
#define _CRT_SECURE_NO_DEPRECATE
const int N = 300030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =  1e9+7;
ll n;
ll dp[N][4],arr[N][4];
int main()
{
    ios::  sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>n;
	rep(i,1,n+1)
	{
		rep(j,1,4)
		{
			cin>>arr[i][j];
			rep(k,1,4)
			{
			 if(j!=k)
			 dp[i][j]=max(dp[i-1][k],dp[i][j]);
			 
			}
			dp[i][j]+=arr[i][j];
		//	cout<<dp[i][j]<<endl;
		}
	}
	cout<<max(dp[n][1],max(dp[n][2],dp[n][3]));
}






Measured memory_bytes: 10496
S = input()[::-1]
N = len(S)

mod = 10**9 + 7

dp = [[0]*13 for i in range(N+1)]
dp[0][0] = 1

for i in range(1, N+1):
    if S[i-1] == "?":
        for j in range(10):
            tmp_mod = (j * pow(10, i-1, 13)) % 13
            for k in range(13):
                dp[i][k] = (dp[i][k] + dp[i-1][k-tmp_mod%13]) % mod

    else:
        tmp_mod = (int(S[i-1]) * pow(10, i-1, 13)) % 13
        for k in range(13):
            dp[i][k] = (dp[i][k] + dp[i-1][k-tmp_mod%13]) % mod

print(dp[N][5])

Measured memory_bytes: 61788
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    int n; cin>>n;
    int v[n]; rep(i,n) cin>>v[i];
    int c[n]; rep(i,n) cin>>c[i];
    int ans=0;
    rep(i,n){
        ans+=max(0,v[i]-c[i]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
X, K, D = map(int, input().split())
X = abs(X)
if X - K * D >= 0:
  print(X - K * D)
else:
  k = X // D
  if (K - k) % 2 == 0:
    print(X - k * D)
  else:
    print(abs(X - (k + 1) * D))


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

const int maxn=2e5+100;
int a[maxn],b[maxn];
int main()
{
    int N;
    while(cin>>N)
    {
        for(int i=0; i<N; i++)
            cin>>a[i],b[i]=a[i];
        sort(a,a+N);
        int t=(N-1)/2;
        for(int i=0; i<N; i++)
        {
            //int pos=lower_bound(a,a+N,a[t])-a;
            //  int x=upper_bound(a,a+N,a[t])-a;
            int pos=t;
            if(b[i]<=a[pos]) pos++;

            //  if(b[i]<=a[x]) pos=x+1;
            //int x=
            cout<<a[pos]<<endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <unordered_map>

using namespace std;

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

	unordered_map<int,int> map;

	for(int i = 1; i < n; ++i){
		int j;
		cin >> j;

		auto m = map.find(j-1);
	
		if(m == map.end())
			map[j-1] = 1;
		else
			map[j-1] += 1; 
	}

	for(int i = 0; i < n; ++i){
		auto m = map.find(i);
	
		if(m == map.end())
			std::cout << 0 << endl;
		else
			std::cout << map[i] << endl; 
	}
}


Measured memory_bytes: 11412
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main(void) {
	long int a;
	int n, even = 0, odd = 0;
	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		scanf("%ld", &a);
		if (a % 2 == 0)even++;
		else odd++;
	}

	if (odd % 2 == 0)printf("YES\n");
	else printf("NO\n");
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
    int H,W;
    while (1){
        cin>>H>>W;
        if (H==0 && W==0) break;
        else{
            for (int a=0;a<W;a++) cout<<"#";
            cout<<endl;
            for (int b=0;b<H-2;b++){
                cout<<"#";
                for (int c=0;c<W-2;c++) cout<<".";
                cout<<"#"<<endl;
            }
            for (int d=0;d<W;d++) cout<<"#";
            cout<<endl;
        }
        cout<<endl;
    }
    
}


Measured memory_bytes: 3004