akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int n; cin>>n;
	vi a(n),b(n+1,0);
	a.push_back(0);
	int m=0;
	rep(i,0,n){
		cin>>a[i];
		chmax(m,a[i]);
	}
	int ans=0;
	rep(i,0,m){
		if(a==b)break;
		int cnt=0;
		rep(j,0,n){
			if(a[j]==0)continue;
			if(a[j+1]==0){
				cnt++;
			}
			//if(a[i])a[i]--;
		}
		rep(i,0,n)a[i]=max(a[i]-1,0);
		ans+=cnt;
		//cout<<"  cnt: "<<cnt<<endl;
	//	rep(j,0,n)cout<<a[j]<<" ";
	}
	cout<<ans<<endl;
	
	
	
	return 0;
}

Measured memory_bytes: 3640
import sys
L, R= map(int, input().split())
ans = []
for i in range(L, R):
    for j in range(i+1, R+1):
        if (i*j)%2019 == 0:
            print(0)
            sys.exit()
        else:
            ans.append((i*j)%2019)
print(min(ans))

Measured memory_bytes: 6800
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
ll power(ll x,ll y,ll p){
ll res = 1;x = x % p;
while (y > 0){
if (y & 1){res = (res*x) % p;}
y = y>>1;
x = (x*x) % p;}
return res;}
ll mcd(ll a,ll b){
    if(b>a)swap(a,b);
    if(b==0)return a;
    else return mcd(b,a%b);
}
ll t,n,m,k;
bool esprimo(ll n){
ll s=0;
for(ll i=1;i*i<=n;i++){
    if(n%i==0){s++;}}
if(s>=2){return false;}
return true;
}
int main(){
    //    cout<<fixed<<setprecision(2);
//cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

cin>>n;
cout<<(1000-n%1000)%1000;
}



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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;

ll rec(int i, int avail, int N, vector<ll>& W, vector<ll>& V,
       map<pair<int, ll>, ll>& memo)
{
  if (i >= N) { return 0; }
  if (memo.count(make_pair(i, avail)) != 0) {
    return memo[make_pair(i, avail)];
  }
  ll ret = 0;
  if (W[i] > avail) {
    ret = rec(i + 1, avail, N, W, V, memo);
  }
  else {
    ret = max(rec(i + 1, avail, N, W, V, memo),
              rec(i + 1, avail - W[i], N, W, V, memo) + V[i]);
  }
  return memo[make_pair(i, avail)] = ret;
}

int main()
{
  int N; scanf("%d", &N);
  ll L; scanf("%lld", &L);
  vector<ll> W(N), V(N);
  for (int i = 0; i < N; ++i) {
    scanf("%lld %lld", &W[i], &V[i]);
  }

  map<pair<int, ll>, ll> memo;
  ll ans = rec(0, L, N, W, V, memo);
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin >> H >> W;
  vector<vector<char>> grid(H, vector<char>(W));
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++)
      cin >> grid.at(i).at(j);
  }
  vector<bool> gyo(H,false);
  vector<bool> retu(W, false);
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if (grid.at(i).at(j) == '#'){
        gyo.at(i) = true;
        retu.at(j) = true;
      }
    }
  }
  for(int i=0; i<H; i++){
    if(gyo.at(i)){
      for(int j=0; j<W; j++){
        if(retu.at(j))
          cout << grid.at(i).at(j);
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define mod (ll)(1e9+7)
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<(x)<<endl
#define ps(x) cout<<(x);
#define pfix(d,x) cout << fixed << setprecision(d) << x << endl;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
#define fi first
#define se second
ll a,b,c,d,n,m,x,y,k,h,w,sum,mi,ma,ans,s,t,l,r,res,tmp;
bool flag;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int dx8[8]={1,1,0,-1,-1,-1,0,1},dy8[8]={0,1,1,1,0,-1,-1,-1};
char cha;
string st;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<pair<int,int> > VP;

struct graph{
    int V;
    vector<VP > v;
    graph(int V) : V(V), v(vector<VP >(V)){}
    void add_diedge(int v1, int v2, ll w){
        v[v1].pb({v2, w});
        v[v2].pb({v1, w});
    }
    void add_edge(int v1, int v2, ll w){
        v[v1].pb({v2, w});
    }
    VL dist = vector<ll>(V, -1);
    VI prever = vector<int>(V,-1);
    VL dijkstra(int start){
        priority_queue<P, vector<P>, greater<P> > que;
        que.push(P(0,start));
        while(!que.empty()){
            P pa = que.top();
            //d(pa.fi);d(pa.se);
            que.pop();
            int u = pa.se;
            //d(u);
            //d(dist[u]);
            if(dist[u] >= 0 && dist[u] < pa.fi)continue;
            dist[u]=pa.fi;
            for(P e : v[u]){
                //d("a")
                //d(e.fi);d(e.se);
                if(dist[e.fi] < 0 || dist[e.fi] > dist[u] + e.se){
                    dist[e.fi] = dist[u] + e.se;
                    prever[e.fi] = u;
                    que.push(P(dist[e.fi],e.fi));
                    //d(dist[e.fi]);d(e.fi);
                }
            }
        }
        return dist;
    }
    vector<int> get_path(int t){
        VI path;
        for(; t != -1;t=prever[t])path.pb(t);
        reverse(all(path));
        return path;
    }
    void gprint(){
        rep(i,V){p("");for(P x : v[i]){ps(x.fi);ps(",");ps(x.se);ps(" ");}}
    }
};

int main(){
    cin>>n>>m;
    graph G(n*3+10);
    rep(i,m){
        cin>>a>>b;
        G.add_edge(a*3,b*3+1,1);
        G.add_edge(a*3+1,b*3+2,1);
        G.add_edge(a*3+2,b*3,1);
    }
    //G.gprint();
    cin>>s>>t;
    VL dist = G.dijkstra(s*3);
    //rep(i,n*3+10)p(dist[i]);
    //VI bt = G.get_path(t*3);
    //p("bt");
    //for(int i : bt)p(i);
    p(((dist[t*3]>0)?dist[t*3]/3:-1));
    return 0;
}


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

int main(){
    map<string,int> items;
    string s;
    int n;
    cin >> n;
    for(int i = 0;i < n;i++){
        cin >> s;
        items[s]++;
    }
    cout << items.size() << endl;
}

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

class Program
{
    static void Main(string[] args)
    {
        var A = sc.ReadInt();
        var B = sc.ReadInt();
        var ans = 0;
        for (int i = A; i <= B; i++)
        {
            var s = i.ToString();
            if (s[0] == s[4] && s[1] == s[3]) ans++;
        }
        Console.WriteLine(ans);
    }

    static int MOD = (int)1e9 + 7;
    static int INF = (int)1e7 + 1;
    static long LINF = (long)1e13 + 1;
    static Scanner sc = new Scanner();
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }
    public string ReadStr()
    {
        return this.Next();
    }
    public char ReadChar()
    {
        return this.Next()[0];
    }
    public int ReadInt()
    {
        return int.Parse(this.Next());
    }
    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }
    public long ReadLong()
    {
        return long.Parse(this.Next());
    }
    public double ReadDouble()
    {
        return double.Parse(this.Next());
    }
    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }
    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }
    public double[] ReadDoubleArray(int n)
    {
        var array = new double[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadDouble();
        }
        return array;
    }
    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S,T;
  int ans = 0;
  cin >> S >> T;
  int size = S.size();
  char s,t;
  for(int i = 0; i<size; i++){
    s = S.at(i);
    t = T.at(i);
    if(s != t) ans++;
  }
  cout << ans << endl;
}

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

int main(){
    string s,t;
    cin>>s>>t;
    
    vector<ll> ss(s.length());
    vector<ll> tt(t.length());
    
    for(ll i=0;i<s.length();++i){
        ss[i]=s[i];
    }
    for(ll i=0;i<t.length();++i){
        tt[i]=t[i];
    }
    sort(ss.begin(),ss.end());
    sort(tt.begin(),tt.end(),greater<ll>());
    for(ll i=0;i<min(s.length(),t.length());++i){
        //cout<<ss[i]<<","<<tt[i]<<endl;
        if(ss[i]<tt[i]){
            cout<<"Yes";
            return 0;
        }else if(ss[i]>tt[i]){
            cout<<"No";
            return 0;
        }
    }
    if(s.length()<t.length()){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
}

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

int x,y,a=0,b=0,c=0;

int main(){
	cin >> x >> y;
	
	if(x==1||x==3||x==5||x==7||x==8||x==10||x==12){
		a += 1;
	}else if(x==4||x==6||x==9||x==11){
		b += 1;
	}else{
		c += 1;
	}
	
	if(y==1||y==3||y==5||y==7||y==8||y==10||y==12){
		a += 1;
	}else if(y==4||y==6||y==9||y==11){
		b += 1;
	}else{
		c += 1;
	}
	
	if(a==2||b==2||c==2){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}
			
	

Measured memory_bytes: 256
n=input()
s=input()
s=s.replace(" ",",")
s=str(s).split(",")
l=list(s)
a=0
for i in range(2,int(n)):
  if int(l[i-2])<int(l[i-1]) and int(l[i-1])<int(l[i]):
    a=a+1
  if int(l[i-2])>int(l[i-1]) and int(l[i-1])>int(l[i]):
    a=a+1
print(a)



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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
  cout << a;
  ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
  cout << a << ' ';
  pr(b);
}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

using Graph = vector<vector<int>>;
int N, M;
Graph G;

void solve()
{
  vector<int> dist(N, -1);
  // prev[ v ] が、頂点 v の親 | prev[ v ] := 始点 s から頂点 v への最短路において、v の手前の頂点
  vector<int> prev(N, -1);
  queue<int> que;
  que.push(0);
  dist[0] = 0;
  while (!que.empty())
  {
    int v = que.front();
    que.pop();
    for (auto nv : G[v])
    {
      if (dist[nv] == -1)
      {
        dist[nv] = dist[v] + 1;
        prev[nv] = v;
        que.push(nv);
      }
    }
  }
  cout << "Yes" << endl;
  for (int i = 1; i < N; ++i)
    cout << prev[i] + 1 << endl;
}

int main()
{
  // input 
  cin >> N >> M;
  G.assign(N, vector<int>());
  for (int i = 0; i < M; ++i)
  {
    int a, b;
    cin >> a >> b;
    --a, --b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  // bfs
  solve();
}

Measured memory_bytes: 10676
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N, A):
    A.sort(reverse=True)
    ans = A[0]
    for i in range(2, N):
        ans += A[i // 2]
    print(ans)

if __name__ == '__main__':
    input = sys.stdin.readline
    N = int(input())
    *A, = map(int, input().split())
    main(N, A)


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

long long n, k, vt, x, mx = -1e9, mn = 1e9, vtmx, vtmn;
vector<long long> a;

int main(){
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> x, a.push_back(x);
        if (mx < x) mx = x, vtmx = i;
        if (mn > x) mn = x, vtmn = i;
    } 
    if (mx + mn > 0){
        vt = vtmx;
        cout << 2*n - 1 << endl;
        for (int i = 1; i <= n; i++) {
            cout << vt << " " << i << endl;
        }
        for (int i = 1; i < n; i++) {
            cout << i <<" " << i+1 << endl;
        }
    }
    else{
        vt = vtmn;
        cout << 2*n - 1 << endl;
        for (int i = 1; i <= n; i++){
            cout << vt << " " << i << endl;
        }
        for (int i = n; i > 1; i--){
            cout << i << " " << i-1 << endl;
        }
    }
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
A = sorted(A, reverse = True)
t = 0
y = 0
cnt = 0
for i in range(len(A)-1):
    if A[i] == A[i+1]:
        t = A[i]
        break
    cnt += 1
for j in range(len(A)-1):
    if A[j] == A[j+1] and j >= cnt+2:
        y = A[j]
        break
print(t*y)


Measured memory_bytes: 14244
#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define MOD 1000000007
#define MP make_pair
#define PB push_back
#define SZ(a) ((int)a.size())
typedef long long ll;

int N, K;
char s[100100];

int main () {
        scanf("%s", s);

        N = (int) strlen(s);
        K = N;

        fo(i, 1, N) {
                if (s[i] != s[i-1]) {
                        K = min(K, max(i, N-i));
                }
        }

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

        return 0;
}


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

using namespace std;

int main()
{
    //freopen("input.txt", "r", stdin);

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

    map<string, int> word;
    map<string, int>::iterator it;
    word["AC"] = 0, word["WA"] = 0, word["TLE"] = 0, word["RE"] = 0;
    while (n--)
    {
        char str[10];
        scanf("%s", str);
        word[str]++;
    }
    printf("AC x %d\n", word["AC"]);
    printf("WA x %d\n", word["WA"]);
    printf("TLE x %d\n", word["TLE"]);
    printf("RE x %d\n", word["RE"]);

    return 0;
}

Measured memory_bytes: 3788
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        long a = 2;
        long b = 1;
        long c = 0;
        long result = 1;
        int num = Integer.parseInt(br.readLine().trim());
        for(int i=2; i<=num; i++){
            if(i%3==0){
                a = b+c;
                result = a;
            }else if(i%3==1) {
                b = c+a;
                result = b;
            }else{
                c = a+b;
                result = c;
            }
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 21460
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<unordered_set>
using namespace std;
/*int p = 998244353;*/
int p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<pin,int>
#define V vector
#define Endl endl
#define veb vector<bool>
#define sq(a) (a)*(a)
#define rev(s) reverse(s.begin(),s.end())
#define end_pr(s) cout << s <<endl;return 0
#define itn int
int RE() {
	vel v(3, 2);
	return v.at(4);
}
int ru(int a, int r) {
	if (r == 0) { return 1; }
	int ans = ru(a, r / 2);
	ans *= ans; ans %= p;
	if (r % 2 == 1) { ans *= a; }
	return ans % p;
}
int inv(int a) {
	return ru(a,p - 2);
}
vel dis(int mid1, vvel &way) {
	int n = way.size();
	vel dist(n, -1); dist[mid1] = 0;
	queue<int> q;
	q.push(mid1);
	while (!q.empty()) {
		int st = q.front(); q.pop();
		rep(i, way[st].size()) {
			int to = way[st][i];
			if (dist[to] == -1) {
				dist[to] = dist[st] + 1;
				q.push(to);
			}
		}
	}
	return dist;
}
pin most_far(int now, int n, vvel &way) {
	vel dist1 = dis(now, way);
	pin ans = mkp(-1, 0);
	rep(i, n) {
		if (dist1[i] > ans.first) { ans = mkp(dist1[i], i); }
	}
	return ans;
}

template<typename T>
V<T> uni(V<T> &v) {
	if (v.size() == 0) { return v; }
	sor(v);
	V<T> ans(1, v[0]);
	for (int i = 1; i < v.size(); i++) {
		if (v[i] != v[i - 1]) { ans.push_back(v[i]); }
	}
	v = ans;
	return v;
}
int s_gcd(int a, int b) {
	if (b == 0) { return a; }
	return s_gcd(b, a%b);
}
int gcd(int a, int b) {
	a = abs(a);
	b = abs(b);
	if (a < b) { swap(a, b); }
	return s_gcd(a, b);
}
vel dx{ 1,1,0,0,-1,-1 };
vel dy{ 0,1,1,-1,-1,0 };
signed main() {
	while (true) {
		int h; cin >> h;
		if (h == 0) { break; }
		int ans = 0;
		vvel pla(h, vel(5));
		rep(i, h) {
			rep(j, 5) { cin >> pla[i][j]; }
		}
		rev(pla);
		while (true) {
			int diff = 0;
			rep(i, h) {
				if (pla[i][2] != -1) {
					int count = 1;
					if (pla[i][1] == pla[i][2]) {
						count++;
						if (pla[i][0] == pla[i][2]) { count++; }
					}
					if (pla[i][3] == pla[i][2]) {
						count++;
						if (pla[i][4] == pla[i][2]) { count++; }
					}
					if (count >= 3) {
						diff += pla[i][2] * count;
						if (pla[i][1] == pla[i][2]) {
							pla[i][1] = -1;
							if (pla[i][0] == pla[i][2]) { pla[i][0] = -1;; }
						}
						if (pla[i][3] == pla[i][2]) {
							pla[i][3] = -1;
							if (pla[i][4] == pla[i][2]) { pla[i][4] = -1; }
						}
						pla[i][2] = -1;
					}
				}
			}
			if (diff == 0) { break; }
			rep(i, 5) {
				int back = 0;
				rep(j, h) {
					if (pla[j][i] != -1) {
						pla[back][i] = pla[j][i];
						back++;
					}
				}
				for (int j = back; j < h; j++) { pla[j][i] = -1; }
			}
			ans += diff;
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3120
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

class UnionFind {
public:
    vector<int> par;
    int N;
    UnionFind(int n) {
        par.resize(n, -1);
        N = n;
    }
    int Find(int n) {
        return par[n] < 0 ? n : par[n] = Find(par[n]);
    }
    bool Union(int x, int y) {
        x = Find(x);
        y = Find(y);
        if (x == y) return false;
        if (-par[x] > -par[y]) swap(x, y);
        par[y] += par[x];
        par[x] = y;
        N--;
        return true;
    }
    bool Same(int x, int y) {
        return Find(x) == Find(y);
    }
    int size(int x) {
        return -par[Find(x)];
    }
    int size() {
        return N;
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin, n;
    int sz = 100010;
    vector<vector<int>> cnt(sz);
    REP(i, 0, n) {
        int x, y;
        cin, x, y;
        cnt[x].push_back(y);
    }

    UnionFind uf(sz);
    REP(i, 0, sz) {
        for (int j = 1; j < cnt[i].size(); j++) {
            uf.Union(cnt[i][0], cnt[i][j]);
        }
    }

    ll ans = 0;

    REP (i, 0, sz) {
        if (cnt[i].size()) {
            ans += uf.size(cnt[i][0]) - cnt[i].size();
        }
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 4608
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

A, B, C = MAP()

if C == sorted([A, B, C])[1]:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 5396
H, W = map(int, input().split())

a_list = [list(input()) for i in range(H)]
result = a_list[:]
for i,aa in enumerate(a_list):
    if aa.count('.') == len(aa):
        result[i] = 1
result = [r for r in result if r != 1]

#print(result)
import numpy as np
T_result = np.array(result).T
result2 = T_result.tolist()
for i, aa in enumerate(result2):
    if aa.count('.') == len(aa):
        result2[i] = 1

result2 = [r for r in result2 if r != 1]
for r2 in np.array(result2).T.tolist():
    print(''.join(r2))

Measured memory_bytes: 12492
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repr(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<(int)(n);i++)
#define INF 99999999999999
#define MAX_V 100010
#define MAX_E 2019

    /*Solve*/

int main(){
    ll n,k;
    cin >> n >> k;
    if(k <= n/2 && n%2==0){
        cout << "YES" << endl;
    }else if(k <= n/2+1 && n%2==1){
        cout << "YES" << endl;
    }else cout << "NO" << endl;
}

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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//code here;
	ll i,count=0;
	string s;
	cin>>s;
	for(i=0;i<s.size()/2;i++) {
		if(s[i]!=s[s.size()-1-i]) count++;
	}
	cout<<count<<endl;
	return 0;
}

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


int main(){
	int n,x,a,b,c,cnt=0;
	vector<int> v;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> x;
		v.push_back(x);
	}
	for(int i=2;i<n;i++){
		a=v[i-2],b=v[i-1],c=v[i];
		if( (a>b&&b>c) || (a<b&&b<c) ) cnt++;
	}
	
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        ArrayList<Key> keys = new ArrayList<>();
        for(int i = 0; i < m; i++){
            int a = sc.nextInt();
            int b = sc.nextInt();
            int t = 0;
            for(int j = 0; j < b; j++){
                t += 1 << (sc.nextInt()-1);
            }
            keys.add(new Key(a,b,t));
        }
        int[][] dp = new int[m+1][1 << n];
        for(int i = 0; i <= m; i++){
            Arrays.fill(dp[i],Integer.MAX_VALUE/2);
        }
        dp[0][0] = 0;
        for(int i = 0; i < m; i++){
            Key k = keys.get(i);
            for(int j = 0; j < (1 << n); j++){
                dp[i+1][j] = Math.min(dp[i+1][j],dp[i][j]);
                dp[i+1][j | k.t] = Math.min(dp[i+1][j | k.t], dp[i][j] + k.c);
            }
        }
        System.out.println(dp[m][(1 << n)-1] == Integer.MAX_VALUE/2 ? -1 : dp[m][(1 << n)-1]);
    }
}

class Key{
    int c, o, t;
    public Key(int c, int o, int t){
        this.c = c;
        this.o = o;
        this.t = t;
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

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

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

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

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

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 59572
#include<bits/stdc++.h>
using namespace std;
 
//________________________________________________________________________________________________________
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define in freopen("input.txt","r",stdin)
#define out freopen("output.txt","w",stdout);
#define ll long long 
//________________________________________________________________________________________________________
ll lcm(ll a,ll b) {if(a==0 || b==0){return 0;}else{return (a*b)/__gcd(a,b);}} //
 
 
//--------------------------------------------------------------------------------------------------------
int main()
{
// #ifndef ONLINE_JUDGE
//     in;
//    //out;
// #endif
    //fastread;
    int a,b;
    cin>>a>>b;
    cout<<lcm(a,b)<<endl;
    return 0;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)



int main() {

    string s; cin >> s;

    bool flag = true;
    if(s[0] != s[1] && s[0] != s[2] && s[0] != s[3]) flag = false;
    if(s[1] != s[0] && s[1] != s[2] && s[1] != s[3]) flag = false;
    if(s[2] != s[0] && s[2] != s[1] && s[2] != s[3]) flag = false;
    if(s[3] != s[0] && s[3] != s[1] && s[3] != s[2]) flag = false;

    // 全部同じ文字
    if(s[0] == s[1] && s[0] == s[2] && s[0] == s[3]) flag = false;

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

    return 0;
}


Measured memory_bytes: 256
import sys
from numpy import argmin
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
input = sys.stdin.buffer.readline

V, E = map(int, input().split())

v_from = []
v_to = []
cost = []

for _ in range(E):
    u, v, d = map(int, input().split())
    v_from.append(u)
    v_to.append(v)
    cost.append(d)

graph = csr_matrix((cost, (v_from, v_to)), [V+1, V+1])
dist, predecessors = floyd_warshall(graph, directed=False, return_predecessors=True)
dist[dist == 0] = float('inf')

dist_min = list(map(argmin, dist))

# print(dist_min)


# print(dist, predecessors)
# 発生頻度？無視です……
input()

T_max = int(input())
# order = [[int(input().split()[1]) for _ in range(int(input()))] for _ in range(T_max)]

time = 0
delivering = False
distination = 1
v_next = 1

order = []

def take_order():
    global order
    order.append([int(input().split()[1]) for _ in range(int(input()))])
    # 車に積まれた荷物の情報は捨てる(えー……)
    [input() for _ in range(int(input()))]

# 最初のオーダーだけとっておく
take_order()

def time_next():
    global time, order
    time += 1
    # 時間を進めたらオーダーをとる
    if time < T_max - 1:
        take_order()

def print_flush(value):
    print(value, flush=True)
    # OKを読み飛ばす
    input()
    # 配達完了情報も読み飛ばします……
    [input() for _ in range(int(input()))]

while time < T_max:
    # 配達中なら配達作業
    if delivering:
        # 途中経由地へ進む
        print_flush(v_next)
        # 途中経由地までの残りの距離を減らす
        remaining_next -= 1
        # 到着したら次の途中経由地へ
        if remaining_next == 0:
            next_temp = predecessors[distination, v_next] # predecessors[v_next, distination]
            if next_temp != -9999:
                remaining_next = dist[v_next, next_temp]
                v_next = next_temp
        # 最終目的地までの距離を減らす
        remaining_last -= 1
        # 到着してる(はず)
        if remaining_last == 0:
            # 店に戻り終わった(目的地が店だった)
            if distination == 1:
                delivering = False
            # 店に戻る
            else:
                remaining_last = dist[distination, 1]
                v_next = predecessors[1, distination] # predecessors[distination, 1]
                remaining_next = dist[distination, v_next]
                distination = 1
        time_next()
    # 配達する目的地を決める(一番近いところ)
    else:
        idx = -1
        remaining_last = 0
        dist_temp_min = 10**18
        for i, o in enumerate(order):
            if not o:
                continue
            dst = o[0]
            # 店から配達場所までの時間
            # Waiting time とかいうのがあるのでなんか重みを良い感じにする
            dist_temp = dist[1, dst] + abs(time - i) ** 2
            if dist_temp < dist_temp_min:
                dist_temp_min = dist_temp
                idx = i
        # オーダーが無ければ何もせずに次の時間へ
        if idx == -1:
            print_flush(-1)
            time_next()
            continue
        # 目的地等を設定
        distination = order[idx].pop()
        remaining_last = dist[1, distination]
        v_next = predecessors[distination, 1] # predecessors[1, distination]
        # print(distination, v_next)
        remaining_next = dist[1, v_next]
        delivering = True

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

int main(){
  int N,M;
  cin >> N >> M;
  int MOD=1000000007;
  long long ans=1;
  if (abs(N-M)>1){
    cout << 0 << endl;
  }
  else if (N==M){
    ans=2;
    for (int i=1;i<N+1;i++){
      ans=ans*i%MOD*i%MOD;
    }
    cout << ans << endl;
  }
  else {
    for (int i=1;i<N+1;i++){
      ans=ans*i%MOD;
    }
    for (int i=1;i<M+1;i++){
      ans=ans*i%MOD;
    }
    cout << ans << endl;
  }
}

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

using namespace std;

int main()
{
	int r, g, b;
	cin >> r >> g >> b;
	if ((10 * g + b) % 4 == 0) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K,C;
    cin >> N >> K >> C;
    string S;
    cin >> S;
    vec<int> dpL(N+1,-1e9),dpR(N+1,-1e9);
    dpL[0] = 0;
    for(int i=0;i<N;i++){
        if(S[i]=='x') dpL[i+1] = dpL[i];
        else dpL[i+1] = max(dpL[i],dpL[max(i-C,0)]+1);
    }
    dpR[N] = 0;
    for(int i=N-1;i>=0;i--){
        if(S[i]=='x') dpR[i] = dpR[i+1];
        else dpR[i] = max(dpR[i+1],dpR[min(i+C+1,N)]+1);
    }
    vec<int> ans;
    for(int i=0;i<N;i++){
//        cerr << dpL[i] << " " << dpR[i+1] << "\n";
        if(dpL[i]+dpR[i+1]==K-1) ans.push_back(i);
    }
    for(auto& x:ans) cout << x+1 << "\n";
}

Measured memory_bytes: 4236
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s1, s2; cin >> s1 >> s2;
  if(s1[0] == s2[2] && s1[1] == s2[1] && s1[2] == s2[0]) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

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


int main(){
    int n;
    const int a[7] = {2,4,8,16,32,64,128};
    cin >> n;
    if(n==1){cout<<1<<endl;return 0;}
    for(int i=1;i<n;i++){
        if(n<a[i]){cout<<a[i-1]<<endl;return 0;}
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll MOD = 1e9+7;

int main(){
  int n,t;
  cin>>n>>t;
  int mi=1111;
  for(int i=0;i<n;i++){
	int c,ti;
	cin>>c>>ti;
	if(ti>t)continue;
	mi=min(mi,c);
  }
  if(mi==1111)cout<<"TLE"<<endl;
  else cout<<mi<<endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i++){
    string s = to_string(i);
    if (s.size() % 2 == 1)
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define multi_test true and false
using namespace std;

int dfs(int v, vector<int> &height, vector<bool> &bani, vector<int> tree[])
{
    bani[v] = true;
    int res = 0;
    for (int child : tree[v])
    {
        if (bani[child] == false)
        {
            res += dfs(child, height, bani, tree);
        }
    }
    bool flag = true;
    for (int child : tree[v])
    {
        if (height[v] <= height[child])
        {
            flag = false;
        }
    }
    if (flag)
        res++;
    return res;
}

void solve()
{
    int n, m;
    cin >> n >> m;
    vector<int> height(n);
    for (int &i : height)
        cin >> i;
    vector<int> tree[n];
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    vector<bool> bani(n, false);
    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        if (bani[i] == false)
        {
            cnt += dfs(i, height, bani, tree);
        }
    }
    cout << cnt << endl;
}

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

    int test = 1;
    if (multi_test)
        cin >> test;

    while (test--)
        solve();
    return 0;
}

Measured memory_bytes: 11912
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

long long a[300];

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	long long x = 0;
	for (int i = 2; i < n; i++)
		x ^= a[i];
	long long t = a[0] + a[1] - x;
	if (t & 1) {
		puts("-1");
		return 0;
	}
	t /= 2;
	if (t > a[0]) {
		puts("-1");
		return 0;
	}
	for (int i = 39; i >= 0; i--) {
		if (x & (1LL << i)) {
			if (t & (1LL << i)) {
				puts("-1");
				return 0;
			}
			if (t + (1LL << i) <= a[0]) {
				t += (1LL << i);
			}
		}
	}
	if (t == 0) {
		puts("-1");
		return 0;
	}
	printf("%lld\n", a[0] - t);
	return 0;
}


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

class Main{

	public static void main(String[] args) {




		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		char[] fukuro = new char[N];
		boolean[] judge = new boolean[4];
		int count = 0;

		for(int i = 0;i < N;i++){
			fukuro[i] = scan.next().charAt(0);
		}

		Arrays.fill(judge, false);

		for(int i= 0;i < N;i++){
			if(fukuro[i] == 'P'){
				judge[0] = true;
			}
			if(fukuro[i] == 'W'){
				judge[1] = true;
			}
			if(fukuro[i] == 'G'){
				judge[2] = true;
			}
			if(fukuro[i] == 'Y'){
				judge[3] = true;
			}
		}
		for(int i=0;i < 4;i++){
			if(judge[i]){
				count++;
			}
		}

		if(count==3){
			System.out.println("Three");

		}else{
			System.out.println("Four");
		}


	}






}


Measured memory_bytes: 21972
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
a = li()
q = ii()

s = sum(a)

m = [0] * (10**5 + 1)
for i in range(n):
    m[a[i]] += 1

for i in range(q):
    b,c = mi()

    if m[b] == 0:
        print(s)
    else:
        count = m[b]

        s = s + (c-b)*count
        print(s)

        m[c] += count
        m[b] = 0

        

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

int main(){
    int N, M, count=0;
    cin >> N >> M;
    vector<int> a(M);
    vector<int> b(M);
    for(int i = 0;i < M;i++)
        cin >> a[i] >> b[i];

    for(int i = 1;i < N+1;i++){
        for(int j = 0;j < M;j++){
            if(a[j]==i)
                count++;
            if(b[j]==i)
                count++;
        }
        cout << count << endl;
            count = 0;
    }
}

Measured memory_bytes: 256
def q1():
    S,T = (s for s in input().split())
    A,B = (int(i) for i in input().split())
    U = input()

    if U == S:
        A -= 1
    elif U == T:
        B -= 1
    print('{} {}'.format(A,B))


if __name__ == '__main__':
    q1()

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
using ll = long long;
using namespace std;
int main(){
    ll x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
    ll a=x/d;
    ll ans;
    if(x>=0){
    if(a>k){
        ans=x-k*d;
    }
    else if((k-a)%2==0){
        ans=x-a*d;
    }
    else{
        ans=x-(a+1)*d;
    }
    }
    cout<<abs(ans)<<endl;
}


Measured memory_bytes: 3620
# AGC 028 A
N, M = map(int, input().split())
S = input()
T = input()

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

if S[0] != T[0]:
    print(-1)
    exit(0)
if S == T:
    print(N)
    exit(0)

L = lcm(N,M)
p = L//N
q = L//M
U = ""
k = 0

if gcd(M,N) > 1:
    for k in range(1,L):
        if k%p == 0 and k%q == 0:
            if S[k//p] != T[k//q]:
                print(-1)
                exit(0)
    print(L)
else:
    print(L)


Measured memory_bytes: 41324
import java.io.*;
import java.util.*;
import java.math.*;
import java.util.concurrent.ThreadLocalRandom;
public class Main 
{
	
	static long gcd(long a, long b) 
	{
		if (b == 0)
		{	
			return a;
		}
		
		else
		{
			 return gcd(b, a % b);
		}
	}
	public static void main(String[] args) throws Exception
	{

		
		   PrintWriter out = new PrintWriter(System.out);
		   Scanner in = new Scanner(System.in);
		 // long n , k , q;
		  
		int n;
		n = in.nextInt();
		//b = in.nextInt();
		int t[] = new int[n];
		for(int i = 0; i < n; i++)
		{
			t[i] = in.nextInt();
		}
		int p = in.nextInt();
		int pro[] = new int[p];
		int nw[] = new int[p];
		for(int i = 0 ; i < p; i++)
		{
			pro[i] = in.nextInt();
			pro[i]--;
			nw[i] = in.nextInt();
			int k = t[pro[i]];
			t[pro[i]] = nw[i];
			int sum = 0;
			for(int j = 0; j < n; j++)
			{
				sum += t[j];
			}
			t[pro[i]] = k;
			out.println(sum);
		}
		int sum = 0;
//		for(int i = 0; i < n; i++)
//		{
//			sum += t[i];
//		}
//		out.println(sum);
	   out.close();
	}
}

Measured memory_bytes: 10064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int difference = A - B;
		int remaining = C - difference;
		System.out.println(remaining < 0 ? 0 : remaining);
		sc.close();
	}
}

Measured memory_bytes: 23124
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
    sys.stdin = open('input.txt', 'r')
    sys.stdout = open('output.txt', 'w')
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")
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]

#-------------------------code---------------------------#
#vsInput()

n=Int()
a=array()
a.sort(reverse=True)

series=[a[0]]
have=1
need=n-1

for i in range(1,n):
    if(need>=have+2):
        series.append(a[i]*2)
        have+=2
    elif(need>have):
        have+=1
        series.append(a[i])
    else:
        break

print(sum(series))




Measured memory_bytes: 37580
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j + g] = A[j]
            j -= g
            cnt += 1
        A[j + g] = v


def shellSort(A, n):
    G = [1]
    m = 1
    while True:
        g = 3 * G[-1] + 1
        if g >= n:
            break
        G.append(g)
        m += 1
    G.reverse()
    for i in range(m):
        insertionSort(A, n, G[i])
    print(m)
    print(" ".join(map(str, G)))


n = int(input())
A = []
for i in range(n):
    A.append(int(input()))
cnt = 0
shellSort(A, n)
print(cnt)
for i in range(n):
    print(A[i])


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

typedef long long ll;
typedef pair<ll, ll> P;

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976

int n,m,q;
int a[50],b[50],c[50],d[50];
int ans = 0;
void dfs(string s){ 
    if(s.size() == n){
        if(s[n-1] - '0' < m){
            int tmp = 0;
            rep(i,q){
                if(s[b[i]] - s[a[i]] == c[i]) tmp += d[i];
            }
            ans = max(ans,tmp);
        }
        return ;
    }else{
        int now = s[s.size()-1] - '0';
        for(int i = now; i < 10; i++){
            char c = ('0'+i);
            dfs(s+c);
        }
    }
}

int main()
{
    cin >> n >> m >> q;
    rep(i,q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--; b[i]--;
    }
    dfs("0");
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
  int R;
  cin >> R;

  string contestName[3] = {"ABC", "ARC", "AGC"};
  int index;
  if(R<1200){
    index = 0;
  }else if (R < 2800){
    index = 1;
  }
  else
  {
    index = 2;
  }

  cout << contestName[index];

  return 0;
}


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

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

const long long INF = 1LL << 60;

int main() {
    int n, k;
    long long h[100100];
    long long dp[100100];

    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> h[i];

    for (int i = 0; i < 100100; i++) dp[i] = INF;

    dp[0] = 0;
    for (int i = 1; i < n; i++) {
        for (int j = 1; j <= i; j++) {
            if (j > k) break;
            chmin(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
        }
    }

    cout << dp[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 1792