akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int mod = 1e9 + 7;
const int inf = 2e18;

signed main() {
    vector<string> A(2);
    cin >> A;
    vector<int> B(2);
    cin >> B;
    string S;
    cin >> S;
    for (int i = 0; i < 2; i++) {
        if (S == A[i]) --B[i];
    }
    cout << B[0] << " " << B[1] << endl;
}



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

main() {
    int N; cin >> N; int sum=0;
    int T[N]; rep(i,N){cin >> T[i]; sum+=T[i];}
    int M; cin >> M;
    rep(i,M){
        int P,X; cin >> P >> X;
        cout << X-T[P-1]+sum << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define rep(i, f, n) for (int i = (f); i < (int)(n); i++)
#define repe(i, f, n) for (int i = (f); i <= (int)(n); i++)
using namespace std;
using ll = long long;
using pint = pair<int, int>;

int main() {
  string S;
  cin >> S;
  string pat = "ACGT";
  int ans = 0, tot = 0;
  rep(i, 0, S.size()) {
    if (pat.find(S[i]) != pat.npos)
      tot++;
    else
      tot = 0;
    ans = max(ans, tot);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3596
def main(a, b, c, x):

    def gen(coin, n_of_coins, x_parts):
        for x_part in x_parts:
            for i in range(n_of_coins + 1):
                new_x_part = x_part + coin * i
                if new_x_part <= x:
                    yield new_x_part

    x_maybe_iter = gen(50, c, gen(100, b, gen(500, a, [0])))
    patterns = sum(x_maybe == x for x_maybe in x_maybe_iter)
    return patterns


if __name__ == '__main__':
    a, b, c, x = [int(input()) for _ in range(4)]
    print(main(a, b, c, x))


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static Scanner scanner = new Scanner(System.in);

	public static void main(String[] args) {

		StringBuilder text = new StringBuilder(input());
		text.reverse();
		System.out.println(text);

		close();

	}

	public static String input() {

		return scanner.nextLine();

	}

	public static void close() {

		if (scanner != null) {

			scanner.close();

		}
	}
}

Measured memory_bytes: 26148
#include <bits/stdc++.h>
#define rep(i,l,r) for (int i=l,i##end=r;i<=i##end;++i)
#define per(i,r,l) for (int i=r,i##end=l;i>=i##end;--i)
#define sit set<int>::iterator
#define ll long long
using namespace std;
const int N=1e3+3,INF=1e9;
int a[N][N],f[N][N];
char s[N];
int main(){
    int n,m; cin>>n>>m;
    rep(i,1,n){
        scanf("%s",s);
        rep(j,1,m) a[i][j]=s[j-1]=='#';
    }
    rep(i,1,n)
        rep(j,1,m)
            if (i==1&&j==1) f[i][j]=a[i][j];
            else{
                f[i][j]=INF;
                if (i>1) f[i][j]=min(f[i][j],f[i-1][j]+(!a[i-1][j]&&a[i][j]));
                if (j>1) f[i][j]=min(f[i][j],f[i][j-1]+(!a[i][j-1]&&a[i][j]));
            }
    cout<<f[n][m]<<endl;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL //デバッグ出力系
#define dout cout
#define debug() if(true)
#else
#define dout if(false) cout
#define debug() if(false)
#endif//
#define next asdnext
#define prev asdprev
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define vrep(i, v) for(auto &i : v)
#define all(x) (x).begin(),(x).end()
#define vout(v) for(auto &i:v){cout<<i<<" ";}cout<<"\n"; //配列出力
#define vin(v) for(auto &i:v)cin>>i; //配列入力
#define vec(v,n) vector<int> v(n,0);
typedef long long ll;
typedef unsigned long long ull;

void Main() {
	int N, X;
	cin >> N >> X;
	vec(L, N);

	vin(L);

	int i;
	int sum=0;
	for (i = 0; i < N; i++) {
		sum += L[i];
		if (sum > X) {
			cout << i + 1 << endl;
			return;
		}
	}
	cout << N + 1<<endl;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 256
N = gets.to_i
A = gets.split(' ').map(&:to_i)
B = gets.split(' ').map(&:to_i)
C = gets.split(' ').map(&:to_i)

A.unshift(0)
B.unshift(0)
C.unshift(0)
ans = 0
1.upto(N) do |i|
	ans += B[A[i]]
	if i >= 2 && A[i] == A[i-1] + 1
		ans += C[A[i-1]]
	end
end
puts ans

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    int all = 1; int sub = 1;
    for (int i = 0; i < n; i++) {
        all *= 3; sub *= 2 - (a[i] % 2);
    }
    cout << all - sub << "\n";
    return 0;
}

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

typedef long long ll;
ll M = 1e9 + 7;
ll n, d[105][500];
ll f(ll p, ll q) {
	ll i, z, s = 0;
	if (d[p][q] != -1) return d[p][q];
	if (p == n) return 1;
	for (i = 1; i <= 4; i++) {
		z = (q % 100) * 10 + i;
		if (z == 123 || z == 132 || z == 213) continue;
		if ((q / 100) == 1 && (q % 10) == 2 && i == 3) continue;
		if ((q / 10) == 12 && i == 3) continue;
		s = (s + f(p + 1, z)) % M;
	}
	return d[p][q] = s;
}
int main()
{
	cin >> n;
	memset(d, -1, sizeof(d));
	cout << f(0, 0);
    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <queue>
#include <cmath>
using namespace std;

struct data{
	int v,bit,c;
	data(int vv=0,int bb=0,int cc=0){
		v=vv;
		bit=bb;
		c=cc;
	}
	bool operator<(const data &d1)const{
		return d1.c<c;
	}
};

int n,m,l,s,t;
int dist[301][301];
int dp[18][1<<16];
int siro[301];
int cost[18];

void dijk(){
	for(int i=0;i<=l;i++){
		for(int j=0;j<(1<<l);j++){
			dp[i][j]=t+1;
		}
	}
	priority_queue<data> que;
	que.push(data(l,0,0));
	dp[l][0]=0;
	while(que.size()){
		data q=que.top();
		que.pop();
		if(dp[q.v][q.bit]<q.c)continue;
		if(q.v!=l && !(q.bit>>q.v & 1)){
			if(dp[q.v][q.bit|(1<<q.v)]>dp[q.v][q.bit]+cost[q.v]){
				dp[q.v][q.bit|(1<<q.v)]=dp[q.v][q.bit]+cost[q.v];
				que.push(data(q.v,q.bit|(1<<q.v),dp[q.v][q.bit|(1<<q.v)]));
			}
		}
		for(int i=0;i<=l;i++){
			if(dp[i][q.bit]>dp[q.v][q.bit]+dist[siro[q.v]][siro[i]]){
				dp[i][q.bit]=dp[q.v][q.bit]+dist[siro[q.v]][siro[i]];
				que.push(data(i,q.bit,dp[i][q.bit]));
			}
		}
	}
}

int main(void){
	while(1){
		scanf("%d %d %d %d %d",&n,&m,&l,&s,&t);
		if(n+m+l+s+t==0)break;
		s--;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				dist[i][j]=t+1;
			}
			dist[i][i]=0;
		}
		for(int i=0;i<m;i++){
			int a,b,c;
			scanf("%d %d %d",&a,&b,&c);
			a--;
			b--;
			dist[a][b]=c;
			dist[b][a]=c;
		}
		memset(siro,-1,sizeof(siro));
		for(int i=0;i<l;i++){
			int v;
			scanf("%d %d",&v,&cost[i]);
			v--;
			siro[i]=v;
		}
		siro[l]=s;
		for(int k=0;k<n;k++){
			for(int i=0;i<n;i++){
				for(int j=0;j<n;j++){
					dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
				}
			}
		}
		dijk();
		int res=0;
		for(int bit=0;bit<(1<<l);bit++){
			if(dp[l][bit]<=t){
				res=max(res,__builtin_popcount(bit));
			}
		}
		printf("%d\n",res);
	}
	return 0;
}

Measured memory_bytes: 25792
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    int N,K;cin>>N>>K;
    int ans=0;
    while(1){
        N/=K;
        ans++;
        if(N!=0)continue;
        else break;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3596
data = list(map(int,input().split()))
n = data[0]
a = data[1]
b = data[2]
ans = 0
a1 = 0
a2 = 0
a3 = 0
a4 = 0
a5 = 0

for i in range(n+1):
  base = str(i)
  if i >= 10000:
    a1 = base[0]
    a2 = base[1]
    a3 = base[2]
    a4 = base[3]
    a5 = base[4]
  elif i >= 1000:
    a1 = base[0]
    a2 = base[1]
    a3 = base[2]
    a4 = base[3]
  elif i >= 100:
    a1 = base[0]
    a2 = base[1]
    a3 = base[2]
  elif i >= 10:
    a1 = base[0]
    a2 = base[1]
  elif i >= 0:
    a1 = base[0]
  
  
  total = int(a1)+int(a2)+int(a3)+int(a4)+int(a5)
  if a <= total <= b:
    ans = ans + i

print(ans)

Measured memory_bytes: 3188
def main():
    n = int(input())

    a = list(map(int, input().split()))

    if 0 in a:
        print(0)
        return

    ans = 1
    for tmp in a:
        ans *= tmp
        if (ans > 1e18) :
            print(-1)
            return

    print(ans)

main()


Measured memory_bytes: 21596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep3(i, s, n) for (int i = (s); i <= (int)(n); i++)
int b[1000010];
int d[1000010];

int main() {
	int n,a;
	int p,ans;

	cin >> n ;

	ans=1;
	rep(i,1000010) b[i]=0;
	rep(i,1000010) d[i]=0;
	rep3(i,2,1010){
		rep3(j,i,1000010/i){
			if (d[j*i]==0) d[j*i]=i;
		}
	}
	rep(k,n) {
		cin >> a ;
		p=0;
		while (d[a]>0) {
			if(d[a]>p) {
				p=d[a];
				b[p]++;
				if(b[p]>ans) ans=b[p];
			}
			a/=p;
		}
		if (a<2) continue;
		if (a<=p) continue;
		b[a]++;
		if(b[a]>ans) ans=b[a];
	}
	if (ans==n) {
		cout << "not coprime" << endl;
		return 0;
	}else if (ans>1){
		cout << "setwise coprime" << endl;
		return 0;
	}else{
		cout << "pairwise coprime" << endl;
		return 0;
	}
}

Measured memory_bytes: 11456
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s; cin>>s;
    int len=s.size();
    if(s[0]==s[s.size()-1]) len--;
    if(len%2==0)
        cout<<"Second"<<endl;
    else
        cout<<"First"<<endl;
    return 0;
}



Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main(){
  long long int K, A, B, sum=0;
  cin >> K >> A >> B;
  if(B - A <= 1) sum = 1 + K;
  else{
    if(K < A+1) sum = 1 + K;
    else{
      K -= (A+1);
      sum += B;
      if(K != 0){
        if(K % 2 == 1) sum++;
        sum += (B-A)*(K/2);
      }
    }
  }
  cout << sum << "\n";
  return 0;
}


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

int main(){
  ll n;
  cin >> n;
  
  vector<ll> a(n), b(n), c(n);
  cin >> a[0] >> b[0] >> c[0];
  
  ll x,y,z;
  
  for(ll i=1; i<n; i++){
    cin >> x >> y >> z;
    a[i] += x + max(b[i-1],c[i-1]);
    b[i] += y + max(c[i-1],a[i-1]);
    c[i] += z + max(a[i-1],b[i-1]);
  }
  
  cout << max(a[n-1],max(b[n-1], c[n-1])) << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
#define reps(i, n) for(int i = 1; i <= n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;


int main()
{
	char a[22];
	rep(i, 19) cin >> a[i];
	a[5]=' ';
	a[13]=' ';
	rep(i, 19) cout << a[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = n / 1000;
        int b = -(a * 10 - n / 100);
        int c =  n / 10-a * 100 - b * 10;
        int d = n % 10;

        if (a == b || b == c || c == d) {
            System.out.println("Bad");
        } else {
            System.out.println("Good");
        }
    }
}



Measured memory_bytes: 21332
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a_i = new int[n+1];
        for (int i = 1; i <= n; i++) {
            a_i[i] = sc.nextInt();
        }
        int[] data = new int[n+1];
        int count = 0;
        for (int i = n; i >= 1; i--) {
            int sum = 0;
            for (int j = 2 * i; j <= n; j += i) {
                sum += data[j];
            }
            if (a_i[i] == 0) {
                if(sum % 2 == 0) {
                    data[i] = 0;
                } else {
                    data[i] = 1;
                    count++;
                }
            } else {
                if(sum % 2 == 0) {
                    data[i] = 1;
                    count++;
                } else {
                    data[i] = 0;
                }
            }
        }
        System.out.println(count);
        for(int i = 1; i <= n; i++) {
            if(data[i]==1) {
                System.out.print(i+" ");
            }
        }
        System.out.println();
    }
}

Measured memory_bytes: 76204
#include <bits/stdc++.h>
#include<math.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long
#define INF 2000000000
#define Min(a,b) (a<b?a:b)
#define Max(a,b) (a>b?a:b)
#define PI 3.1415926535897932
using namespace std;






int main()
{
int n;
cin>>n;
int a[n][3];
for(int i=0; i<n; i++){
	cin>>a[i][0]>>a[i][1]>>a[i][2];
}
int dp[n][3];
dp[0][0]=a[0][0]; dp[0][1]=a[0][1]; dp[0][2]=a[0][2];
for(int i=1; i<n; i++){
	for(int j=0; j<3;j++){
		if(j==0)
			dp[i][0]=a[i][0]+max(dp[i-1][1], dp[i-1][2]);
		else if(j==1)
			dp[i][1]=a[i][1]+max(dp[i-1][0], dp[i-1][2]);
		else if(j==2)
			dp[i][2]=a[i][2]+max(dp[i-1][0], dp[i-1][1]);
	}
}
cout<<max(max(dp[n-1][1], dp[n-1][2]), dp[n-1][0]);
















return 0;

}



Measured memory_bytes: 2560
import java.io.IOException;
import java.util.Scanner;

public class Main {

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

		double a = scan.nextDouble();

		double radi = a * a * 3.141592653589;
		double circ = 2 * a * 3.141592653589;

		String radi2 = String.format("%.6f", radi);
		String circ2 = String.format("%.6f", circ);

		System.out.println(radi2 + " " + circ2);
	}
}



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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep (i, n) cin >> a[i];

  vector<int> l(n), r(n);
  rep (i, n) {
    if (i == 0) {
      l[0] = a[0];
      r[n - 1] = a[n - 1];
    } else {
      l[i] = gcd(l[i - 1], a[i]);
      r[n - 1 - i] = gcd(r[n - i], a[n - 1 - i]);
    }
  }

  int ans = 0;
  rep (i, n) {
    if (i == 0) ans = max(ans, r[i + 1]);
    else if (i == n - 1) ans = max(ans, l[i - 1]);
    else ans = max(ans, gcd(l[i - 1], r[i + 1]));
  }

  cout << ans << endl;
}


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

int main(){
  int n,m=0,b,ans=0;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> b;
    ans+=max(b-m,0);
    m=b;
  }
  cout << ans << endl;
  return 0;
}

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

#define For(i, j, k) for (int i = j; i <= k; i++)

using namespace std;

int n;

int calc(int x) {
	int ret = 0;
	while (x) ret += x % 10, x /= 10;
	return ret;
}

int main() {

	scanf("%d", &n);

	int ans = 1e9;
	For(i, 1, n - 1) ans = min(ans, calc(i) + calc(n - i));
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 256
MODE = "stdio"
require 'matrix'
line = Array.new

if(defined? MODE)
  line = STDIN.read.split("\n")
else
  tmp = '3
  cat dog
  fish fish
  lion tiger'.split("\n")
  tmp.each{|s|
    line << s.strip
  }
end
n=line[0].to_i

t_p,h_p=[0,0]
(1..n).each do |m|
  t,h = line[m].split(" ")
  if t<h
    h_p += 3
  elsif h<t
    t_p += 3
  else
    t_p += 1
    h_p += 1
  end
end

puts "#{t_p} #{h_p}"

Measured memory_bytes: 9192
#include <stdio.h>

int main() {
    int n, a, b;
    char input[256];

    scanf("%d", &n);
    scanf("%d", &a);
    scanf("%d", &b);
    
    int r = n * a;
    if(r <= b) {
        printf("%d\n", r);
    } else {
        printf("%d", b);
    }
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

long getLongTime(int* t) {
	long longt = 0;
	longt += 60 * 60 * t[0];
	longt += 60 * t[1];
	longt += t[2];
	
	return longt;
}

void getFormattedTime(long longt, int* t) {
	t[0] = longt / (60 * 60);
	longt -= t[0] * (60 * 60);
	t[1] = longt / 60;
	longt -= t[1] * 60;
	t[2] = longt;
}

int main(void){
    int times[3][2][3];
	long longTime[3][3];
	int workTime[3][3];

	for (int i = 0; i < 3; i++) {
		cin >> times[i][0][0] >> times[i][0][1] >> times[i][0][2] >> times[i][1][0] >> times[i][1][1] >> times[i][1][2];
		longTime[i][0] = getLongTime(times[i][0]);
		longTime[i][1] = getLongTime(times[i][1]);
		longTime[i][2] = longTime[i][1] - longTime[i][0];

		getFormattedTime(longTime[i][2], workTime[i]);
	}

	for (int i = 0; i < 3; i++) {
		cout << workTime[i][0] << " " << workTime[i][1] << " " << workTime[i][2] << endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>
using namespace std;
#define MAX_N 50010
const int INF = 1e9;

int main() {
    int n, m; cin >> n >> m;
    int c[m];
    for (int i = 0; i < m; i++) cin >> c[i];
    int dp[MAX_N];
    for (int i = 0; i < MAX_N; i++) dp[i] = INF;
    dp[0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < m; j++) {
            if (i >= c[j]) {
                dp[i] = min(dp[i], dp[i - c[j]] + 1);
            }
        }
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 3316
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int i,n,a[100];
    scanf("%d",&n);
    for(i=0; i<n; i++){
        scanf("%d", &a[i]);
    }
    for(i=n-1; i>=0; i--){
        printf("%d", a[i]);
        if(i!=0){
            printf(" ");
        }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2056
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
typedef long long ll;
using namespace std;


int N, d[50], res;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> d[i];
	}
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			res += d[i] * d[j];
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#coding=UTF-8

mozir=input()
hyo=mozir.split(' ')
Boxes=int(hyo[0])
Opes=int(hyo[1])

Red={0}
Balls=[1]*Boxes

for idx in range(0,Opes,1):
    mozir=input()
    hyo=mozir.split(' ')
    Sousa=((int(hyo[0])-1,int(hyo[1])-1))

    if Balls[Sousa[0]]==1:
        if Sousa[0] in Red:
            Red.remove(Sousa[0])
            Red.update({Sousa[1]})
        else:
            pass

    else:
        if Sousa[0] in Red:
            Red.update({Sousa[1]})
        else:
            pass
        
    Balls[Sousa[0]]-=1
    Balls[Sousa[1]]+=1
    #print(Red)

print(len(Red))


Measured memory_bytes: 12772
#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
#define debug(x) cerr << #x << " : " << x << endl

namespace atcoder {
	void judge_outer(bool judge_exp, string ok = "Yes", string ng = "No") {
		if (judge_exp) {
			cout << ok << endl;
		}
		else {
			cout << ng << endl;
		}
	}

	template<typename T>
	T ncr(T left, T right) {
		right = min(left - right, right);
		T ans = 1;
		for (T i = 1; i <= right; i++) {
			ans = ans * (left - right + i) / i;
		}
		return ans;
	}

	const int LIMIT = 1000000007;
	const int tenfive = 100000;
}

using namespace atcoder;

int main() {
	int a, b;
	cin >> a >> b;
	int add = a + b;
	int sub = a - b;
	int mul = a * b;
	int ans = max(add, sub);
	ans = max(ans, mul);
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int main(){
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    
    sort(a.begin(),a.end());
    ll cnt = 1,ans = 0;
    rep(i,n){
        if(a[i] == a[i+1]){
            cnt++;
        }else{
            if(a[i] > cnt) ans += cnt;
            else ans += cnt - a[i];
            cnt = 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    x, y, h = [], [], []
    for _ in range(n):
        a,b,c = map(int, input().split())
        x.append(a)
        y.append(b)
        h.append(c)
    a = max(h)

    for cx in range(101):
        for cy in range(101):
            for higth in range(a, a+300):
                for i in range(n):
                    if h[i] > 0:
                        if h[i] != (higth-abs(x[i]-cx)-abs(y[i]-cy)):
                            break
                    else:
                        if 0 < (higth-abs(x[i]-cx)-abs(y[i]-cy)):
                            break
                else:
                    print(cx, cy, higth)
                    exit()

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
WHITE = 0
GRAY = 1
BLACK = 2

n = int(raw_input())
M = [ [-1] * n for _ in xrange(n)]
color = [WHITE] * n
d = [float('inf')] * n

for i in xrange(n):
    a = map(int, raw_input().split())
    for j in xrange(a[1]):
        M[a[0]][a[2*(j+1)]] = a[2*(j+1)+1]

def dijkstra():
    d[0] = 0

    while True:
        mincost = float('inf')
        for i in xrange(n):
            if color[i] != BLACK and d[i] < mincost:
                mincost = d[i]
                u = i

        if mincost == float('inf'):
            break

        color[u] = BLACK

        for v in xrange(n):
            if color[v] != BLACK and M[u][v] >= 0:
                if d[u] + M[u][v] < d[v]:
                    d[v] = d[u] + M[u][v]
                    color[v] = GRAY

    for i in xrange(n):
        print "{} {}".format(i, d[i])

    return 0

def main():
    dijkstra()
    return 0

main()

Measured memory_bytes: 6524
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

// below
typedef long long unsigned int ul;
typedef __int128_t lll;
class rolling_hash {
private:
    vector<lll> hash, power;
    lll base = 1e9+7;
    string s;
    const lll mod = (1ull << 61)-1;
    const lll positiviser = mod*10;
public:
    rolling_hash(const string &s);
    lll mul(lll a, lll b);
    lll get(int l, int r);
    ul change(int i, char chg);
    ~rolling_hash();
};

lll rolling_hash::mul(lll a, lll b) {
    lll t = a*b;
    t = (t>>61) + (t & mod);
    if (t >= mod) return t-mod;
    return t;
};


// 半開区間: [l, r)
lll rolling_hash::get(int l, int r) {
    lll ret = hash[r]+positiviser - mul(power[r-l],hash[l]);
    ret = (ret >> 61) + (ret&mod);
    return ret;
};

// 
ul rolling_hash::change(int idx, char chg) {
    int sz = s.length();
    char cur = s[idx];
    int diff = chg-cur;
    lll al_hash = hash[sz];
    if (diff >= 0) {
        ul d = (ul)diff;
        al_hash = al_hash+(power[sz-idx-1]*d);
    }
    else {
        ul d = (ul)abs(diff);
        al_hash = al_hash-(power[sz-idx-1]*d);
    }
    return al_hash%mod;
};

rolling_hash::rolling_hash(const string &s) {
    int n = (int)s.size();
    this->s = s;
    hash.assign(n+1,0);
    power.assign(n+1,1);
    for (int i = 0; i < n; ++i) {
        hash[i+1] = mul(hash[i],base)+s[i];
        power[i+1] = mul(power[i],base);
        if (hash[i+1] >= mod) hash[i+1] -= mod;
        if (power[i+1] >= mod) hash[i+1] -= mod;
    }
};


rolling_hash::~rolling_hash() {};
// above

int main(int argc, char const *argv[]) {
    string s,t; cin>>s>>t;
    int n = s.length(); int m = t.length();

    rolling_hash rs(s), rt(t);
    ll hst = rt.get(0,m);

    rep(i,n-m+1) {
        ll hss = rs.get(i, i+m);
        if (hss == hst) {
            cout << i << '\n';
        }
    }
    return 0;
}


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


#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define f_cin(X) scanf("%f",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)

#define  i_cout(X) printf("%d\n",X)
#define  f_cout(X) printf("%g\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  ll_cout(X) printf("%lld\n",X)

typedef long long  ll;
#define rept(x, s, n) for (int x = s; x < n; x++)

#define Yes_RTN s_cout("Yes");return 0
#define No_RTN  s_cout("No");return 0
#define YES_RTN s_cout("YES");return 0
#define NO_RTN  s_cout("NO");return 0


int i_cins(int n, int* A);
int l_cins2(int n, long* A,long* B);
int s_dsort(const void* a, const void* b);
int s_asort(const void* a, const void* b);

int  _gcd(int a, int b);

int s_asorts(const void* a, const void* b);


int main(void) {
	int  A, B, K, i=0,max,cnt=0;
	i_cin3(A,B,K);
	max = _gcd(A, B);

	for(i=max;;i--) {
		if (max % i)continue;
	    cnt++;
	    if (cnt == K)break;
	}
	i_cout(i);
	return 0;
}
	
//昇順
int s_asorts(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}	
int s_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int s_asort(const void* a, const void* b) {
	return(*(int*)a -*(int*)b);
}
int l_cins2(int n, long* a, long* b) {
	int i;
	rept(i, 0, n) {
		l_cin2(*(a + i), *(b + i));
	}
	return 0;
}
int i_cins(int n, int* a) {
	int i;
	for (i = 0; i < n; i++) {
		i_cin(*(a + i));
	}

	return 0;
}
int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}


Measured memory_bytes: 128
def solve(c, a):
    dp = [float('inf')]*(2*10**5)
    dp[0] = 0
    for w, v in a:
        for i in range(len(dp)-1, -1, -1):
            if dp[i] != float('inf'):
                dp[i+v] = min(dp[i+v], dp[i] + w)
    return next(i for i in range(len(dp)-1, -1, -1) if dp[i] <= c)
  
n, k = map(int, input().split())
a = []
for _ in range(n):
    a.append(list(map(int, input().split())))
print(solve(k, a))

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

#define debug(a) cout << #a << " " << a << endl;
#define _debug(a, i) cout << #a << "[" << i << "]" << " = " << a[i] << endl;
#define fastio ios_base::sync_with_stdio(false); \
			cin.tie(0);							     \
			cout.tie(0);
#define sz(arr) ll(arr.size())

using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18 + 9;
const double PI = 4.0 * atan(1.0);

ll powmod(ll a, ll b, const ll MOD) { 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 gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll modInverse(ll n, const ll p) { return powmod(n, p - 2, p); }
ll div_floor(ll a, ll b) { return a / b - (((a ^ b) < 0) and a % b); }
ll div_ceil(ll a, ll b) { return a / b + (((a ^ b) >= 0) and a % b); }
ll kCn(ll k, ll n, ll f[]) { return (f[n] * modInverse((f[n - k] * f[k]) % MOD, MOD)) % MOD; }


int main() {
	//#ifndef ONLINE_JUDGE
	//	(void)freopen("input.txt", "r", stdin);
	//	(void)freopen("output.txt", "w", stdout);
	//#endif // !ONLINE_JUDGE
	fastio;

	int n, k;
	cin >> n >> k;
	vector<int> cnt(n);
	while(k--) {
		int d;
		cin >> d;
		int x;
		for (int i = 0; i < d; ++i) {
			cin >> x;
			--x;
			++cnt[x];
		}

	}
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		if (cnt[i] == 0)
			++ans;
	}
	cout << ans;
	return 0;
}


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

int main(void) {
    string str;
    cin >> str;
    int i = 0;
    while (i != (int)str.size()) {
        if (str[i] == 'B') {
            str.erase(str.begin()+i);
            if (i != 0) 
                str.erase(str.begin()+i-1);
            i = 0;
            continue;
        }
        else i++;
    }
    cout << str << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
 
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
 
const ll oo = 1e18 + 7;
const ll mod = 1e9 + 7, maxn = (1e5) + 10;  
const long double PI = acos(-1);
int parent[maxn];

int find_parent(int x) {
    if (x == parent[x]) return x;
    return parent[x] = find_parent(parent[x]);
}

void union_set(int x, int y){
    x = find_parent(x);
    y = find_parent(y);

    if (x == y) return;

    parent[y] = x;
}

void init(){
    for (int i=0; i<maxn; i++) parent[i] = i;
}
int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    init();

    for (int i=0; i<m; i++){
        int x, y, z;
        cin >> x >> y >> z;
        union_set(x, y);
    }

    set<int> ans;

    for (int i=1; i<=n; i++){
        ans.insert(find_parent(i));
    }

    cout << ans.size() << endl;
    return 0;
}

Measured memory_bytes: 8640
#include <stdio.h>
int main(void){
    int a, b, c;
    int i = 0;
    
    scanf("%d %d %d", &a, &b, &c);
    
    for (int x = a; x <= b; x++)
        if(c%x==0) {
            i += 1;
        }
        
    printf("%d\n", i);
    
    return 0;
    
}


Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MAX=1e5+5;
ll mod=1e9+7;
#define pb push_back
#define se second
#define fi first
#define maxe max_element
#define mine min_element
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define boost  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
vector<int> graph[205];
int color[205];
int nCk[100][100];
bool bipartite_jugding(int v, int c){
    color[v] = c;
    for(int i = 0; i < graph[v].size(); ++i){
        if(color[graph[v][i]] == c) return false;
        if(color[graph[v][i]] == 0 && !bipartite_jugding(graph[v][i], -c)){
            return false;
        }
    }
    return true;
}

 void combi() {
	for (int i = 0; i <= 99; ++i) nCk[i][0] = 1;
	for (int i = 1; i <= 99; ++i) for (int j = 1; j <= i; ++j) {
		nCk[i][j] = (nCk[i-1][j] + nCk[i-1][j-1]) % mod;
	}
}

long long expo(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*expo((x*x)%M,(n-1)/2,M))%M;

}

void solve(){
  int n;
  cin>>n;
  vector<int> p(n),q(n),wo(n);
  for(int i=0;i<n;i++)cin>>p[i];
  for(int i=0;i<n;i++)cin>>q[i];
  for(int i=0;i<n;i++)wo[i]=i+1;
  //set<vector<int>> st;
  int k=0;int l,r;
  do {
        k++;int i;
         for( i=0;i<n;i++)if(p[i]!=wo[i])break;
         if(i==n)l=k;
  for(i=0;i<n;i++)if(q[i]!=wo[i])break;
         if(i==n)r=k;
    } while (next_permutation(wo.begin(), wo.end()));
  cout<<abs(r-l)<<endl;
}

int main(){
boost;
  solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <iomanip>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <unordered_map>
//pragma GCC optimize("Ofast")
//pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native" )
#include <queue>
#define endl "\n";
#define int long long
#define debug(x) cout << #x << " is " << x << endl;
using namespace std;

void solve() {
	int n, m = 0, ans = 0; cin >> n;
	vector <int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		m = max(m, a[i]);
	}
	vector <bool> re(m + 1);
	sort(a.begin(), a.begin() + n);
	for (int i = 0; i < n; ++i) {
		if (!re[a[i]]) {
			if (i == n - 1 or a[i] != a[i + 1]) ++ans;
			//debug(a[i]);
			re[a[i]] = true;
			for (int j = a[i] + a[i]; j <= m; j += a[i]) {
				re[j] = true;
			}
		}

	}
	cout << ans << endl;
}
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(15);
	int t;
	t = 1;
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 5060
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
nb = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    a = na()

    min_n = min(a)
    max_n = max(a)
    minflg = True
    maxflg = True

    d = []
    for ai in a:
        if ai == min_n and minflg:
            minflg = False
            continue
        if ai == max_n and maxflg:
            maxflg = False
            continue
        d.append(ai)

    ans = []
    for ai in d:
        if ai < 0:
            ans.append([max_n, ai])
            max_n -= ai
        else:
            ans.append(([min_n, ai]))
            min_n -= ai
    ans.append([max_n, min_n])

    print(max_n - min_n)

    for a, b in ans:
        print(a, b)


if __name__ == '__main__':
    main()


Measured memory_bytes: 27824
N,K=map(int,input().split())
V=list(map(int,input().split()))
V_=list(reversed(V))
ans=0
for k in range(1,K+1):
    k_=min(k,N)
    for kk in range(k_+1):
        sum=0
        l=[]
        for i in range(kk):
            sum+=V[i]
            l.append(V[i])
        for i in range(k_-kk):
            sum+=V_[i]
            l.append(V_[i])
        l.sort()
        for j in range(min(k_,K-k_)):
            if l[j]>=0:
                break
            sum-=l[j]
        ans=max(ans,sum)
print(ans)


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

int main() {
  int n;
  cin >> n;
  vector<ll> list(n);
  int cnt = 0;
  ll minv = LLONG_MAX;
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> list[i];
    if (list[i] < 0) {
      cnt++;
      list[i] *= -1;
    }
    minv = min(minv, list[i]);
    sum += list[i];
  }
  if (cnt % 2) {
    sum -= minv * 2;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 1024
fun main(args: Array<String>) {

    val N = readLine()!!.toInt()

    var h = readLine()!!.split(" ").map{it.toInt()}
    var dp =  IntArray(N){0}


    dp[1] = Math.abs(h[1] - h[0])
    for(i in 2 until N){
        dp[i] = Math.min(dp[i-2] + Math.abs(h[i] - h[i-2]), dp[i-1] + Math.abs(h[i] - h[i-1]))
    }
    println(dp[N-1]);



}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

const int MAX = 100010;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

void com_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll com(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main(){
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    com_init();

    ll res = 0;
    for (int i = 0; i <= n - k; ++i) {
        res += (a[n - 1 - i] -  a[i]) * com(n - i - 1, k - 1);
        res %= MOD;
    }
    if(res < 0) res += MOD;
    cout << res << endl;
}

Measured memory_bytes: 3584
#include<stdio.h>

int main(){
  int n; scanf("%d",&n);
  int c=0,s=0,a[n];
  for(int i=0; i<n; i++){
    scanf("%d",&a[i]);
  }
  for(int i=0; i<n-1; i++){
    //printf("a[%d]= %d %d\n",i ,a[i],c);
    if(a[i]>=a[i+1]){
      c++;
    }
    else{
      if(c>s) s=c;
      c=0;
    }
  }
  if(c>s) s=c;
  printf("%d\n",s);
  return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
int main ()
{
    int a, b, c, x, i, j, k, cnt=0;
    scanf("%d%d%d%d", &a, &b, &c, &x);
    for (i=0; i <= a && 500*i<=x; i++)
    {
        for (j=0; j <= b && 100*j+500*i<=x; j++)
        {
            for (k=0; k <= c && 50*k+100*j+500*i<=x; k++)
            {
                if (500*i+100*j+50*k==x)
                {
                    cnt++;
                }
            }
        }
    }
    printf("%d", cnt);
    return 0;
}

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

typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i=0;i<N;i++) cin >> A[i];
    vector<ll> sum(N+1);
    for (int i=0;i<N;i++) sum[i+1] = sum[i] + A[i];
    map<ll,ll> mp;
    ll ans = 0;
    mp[0]++;
    for (int i=1;i<=N;i++){
        ans += mp[sum[i]];
        mp[sum[i]]++;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 15872
#include<cstdio>
#include<iostream>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<list>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<iomanip>
#include<fstream>
#include<ctime>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int N = 55;

LL res;
bool vis[N];
int tab[N], bat[N], lim, i, j, go[N][N], n;
set<int> s;

void dfs(int w) {
	vis[w] = true;
	for (int i=1;i<=lim;i++) if (!vis[go[w][i]]) dfs(go[w][i]);
	for (set<int>::iterator it = s.begin();it!=s.end();it++) if (!vis[go[w][*it]]) dfs(go[w][*it]);
}

bool can() {
	int i, j;
	for (i=0;i<n;i++) {
		for (j=0;j<=50;j++) vis[j] = false;
		dfs(tab[i]);
		if (!vis[bat[i]]) return false;
	}
	//printf("%d\n", lim);
	return true;
}

int main() {
scanf("%d", &n);
for (i=0;i<n;i++) scanf("%d", &tab[i]);
for (i=0;i<n;i++) scanf("%d", &bat[i]);
for (i=0;i<=50;i++) for (j=1;j<=50;j++) go[i][j] = i % j;
s.clear();
lim = 50;
if (!can()) {
	printf("-1\n");
	return 0;
}
for (i=50;i>=1;i--) {
	lim = i - 1;
	if (!can()) {
		//printf("%d\n", i);
		s.insert(i);
		res += (1LL << i);
	}
} 
printf("%lld\n", res); 
return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;

int main() {

    string s;
    cin >> s;
    
    if(s[0] == '9' || s[1] == '9') cout << "Yes" << endl;
    else cout << "No" << endl;
        

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
    #include<vector>
    using namespace std;
    int main()
    {
      int n;
      vector<long long>freq(27);
      scanf("%d",&n);
      char c1=getchar();
      for(int i=0;i<n;i++)
      {
        char c=getchar();
        freq[c-'a']++;
      }
      long long res=1;
      for(int i=0;i<26;i++)
      {
        res=(res*(freq[i]+1))%1000000007;
      }
      res-=1;
      if(res==-1)res=1000000006;
      printf("%lld\n",res);
      return 0;
    }

Measured memory_bytes: 256
//package solution;

import java.io.*;
import java.util.*;
import java.math.*;
import java.awt.Point;
import java.text.*;

public final class Main {
    BufferedReader br;
    StringTokenizer stk;

    public static void main(String[] args) throws Exception {
        new Main().run();
    }
    
    {
        stk = null;
        br = new BufferedReader(new InputStreamReader(System.in));
    }
    
    void run() throws Exception {
        int n = ni();
        HashMap<Integer, Integer> map = new HashMap<>();
        int[] a = new int[n];
        for(int i=0; i<n; i++) {
            a[i] = ni();
            if(!map.containsKey(a[i])) map.put(a[i], 0);
            map.put(a[i], map.get(a[i]) + 1);
        }
        
        long totalPairs = 0;
        for(int key : map.keySet()) {
            long frq = map.get(key);
            totalPairs += (frq * (frq - 1)) >> 1;
        }
        
        for(int i=0; i<n; i++) {
            long rem = map.get(a[i]) - 1;
            pl(totalPairs - rem);
        }
    }
    
    //Reader & Writer
    String nextToken() throws Exception {
        if (stk == null || !stk.hasMoreTokens()) {
            stk = new StringTokenizer(br.readLine(), " ");
        }
        return stk.nextToken();
    }

    String nt() throws Exception {
        return nextToken();
    }

    String ns() throws Exception {
        return br.readLine();
    }

    int ni() throws Exception {
        return Integer.parseInt(nextToken());
    }

    long nl() throws Exception {
        return Long.parseLong(nextToken());
    }

    double nd() throws Exception {
        return Double.parseDouble(nextToken());
    }

    void p(Object o) {
        System.out.print(o);
    }

    void pl(Object o) {
        System.out.println(o);
    }
    
    void selector() {
        Random rd = new Random();
        String[] s = new String[] {"Strings", "Sorting", "Search"
                , "Graph theory", "Greedy", "Dynamic programming"
                , "Constructive algos", "Bit manipulation", "Recursion"};
        pl(s[rd.nextInt(s.length)] + " " + (rd.nextInt(5)+1));
    }
}

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

int n, cntans, ans=1;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;

    for(int i=1; i<=n; i++) {
        int cur=i, cnt=0;
        while(cur%2==0) {
            cur/=2;
            cnt++;
        }
        if(cnt>cntans) {
            cntans = cnt;
            ans = i;
        }
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
import numpy as np
from collections import Counter
N=int(input())
Alist=list(map(int,input().split()))
Q=int(input())
bc=[]
for _ in range(Q):
    bc.append(list(map(int,input().split())))
count=Counter(Alist)
result=0
for key,value in count.items():
    result+=key*value
for i in range(Q):
    if bc[i][0] in count.keys():
        result+=(bc[i][1]-bc[i][0])*count[bc[i][0]]
        count[bc[i][1]]+=count[bc[i][0]]
        count[bc[i][0]]=0
    print(result)

Measured memory_bytes: 53972
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 998244353;
 
// 32 mil = ~1 sec 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;

int main ()
{
  prep();
  long long n;
  cin >> n;
  long long arr[n];
  long long sum = 0;
  long long orig = n*(n+1)/2;
  for (int i=0; i<n; i++){
      cin >> arr[i];
      sum += arr[i];
  }
  if (sum%orig != 0){
      cout << "NO";
      return 0;
  }
  long long times = sum/orig;
  for (int i=0; i<n; i++){
      if (arr[i] < times || arr[i] > times*n){
          cout << "NO";
          return 0;
      }
  }
  long long diffs[n];
  long long diffsum = 0;
  for (int i=1; i<n; i++){
      diffs[i-1] = arr[i]-arr[i-1];
      diffsum += diffs[i-1];
  }
  diffs[n-1] = arr[0]-arr[n-1];
  diffsum += diffs[n-1];
  if (diffsum != 0){
      cout << "NO";
      return 0;
  }
  // x+y = times
  // x = times-y
  // x-(n-1)y = diff
  // -n*y = diff-times
  // y = (diff-times)/(-n)
  // all y's should add to times
  int ytimes = 0;
  for (int i=0; i<n; i++){
      long long diff = diffs[i];
      long long y = diff-times;
      if (y%n != 0){
          cout << "NO";
          return 0;
      }
      ytimes += y/(-n);
  }
  if (ytimes != times){
      cout << "NO";
  }else{
      cout << "YES";
  }
  return 0; 
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 2e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

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

    int dp[n][3] = {};
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    rep(i, 1, n) {
        dp[i][0] = a[i] + max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][1] = b[i] + max(dp[i - 1][2], dp[i - 1][0]);
        dp[i][2] = c[i] + max(dp[i - 1][0], dp[i - 1][1]);
    }

    cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}) << endl;
    return 0;
}


Measured memory_bytes: 2560
import java.util.*;
public class Main{
	public static void main(String sp[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> al = new ArrayList<>();
		for(int i=0;i<n;i++)
			al.add(sc.nextInt());
		
		for(int i=n-1;i>=1;i--){
			if(al.get(i-1)>al.get(i)){
				al.set(i-1,al.get(i-1)-1);
			}
		}
		boolean b=true;
		for(int i=0;i<n-1;i++){
			if(al.get(i+1)<al.get(i)){
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}
}

Measured memory_bytes: 61368
N=int(input())
L=list(map(int,input().split()))
L=[i//400 for i in L]
a=[i for i in L if i<8]
b=[i for i in L if i>7]
a=len(set(a))
b=len(b)
if a==0:
  mi=1
  ma=b
else:
  mi=a
  ma=mi+b
print(mi,ma)

Measured memory_bytes: 9008