akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ROCK ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f first
#define sec second
using namespace std;
using namespace __gnu_pbds;
const long long int linf =(long long)9223372036854775807;
const int dx[8] =  {0,0,1,-1,1,-1,1,-1},dy[9] = {1,-1,0,0,1,-1,-1,1};
typedef long long int ll;

const int N=1e5+5;
ll n,dp[4][N],a,b,c;
vector<pair<int,pair<int,int> > >v;

ll solve(int idx,int lst=0){
    if(idx==n)return 0;
    if(dp[lst][idx]!=-1)return dp[lst][idx];
  
    ll takea=0,takeb=0,takec=0;
    if(lst!=1)takea=solve(idx+1,1)+v[idx].f;
    else takea=max(solve(idx+1,2)+v[idx].sec.f,solve(idx+1,3)+v[idx].sec.sec);
  
    if(lst!=2)takeb=solve(idx+1,2)+v[idx].sec.f;
    else takeb=max(solve(idx+1,1)+v[idx].f,solve(idx+1,3)+v[idx].sec.sec);
  
    if(lst!=3)takec=solve(idx+1,3)+v[idx].sec.sec;
    else takec=max(solve(idx+1,1)+v[idx].f,solve(idx+1,2)+v[idx].sec.f);
  
    ll ans=max(takea,max(takeb,takec));
    return dp[lst][idx]=ans;
}

int main()
{
    ROCK;
    memset(dp,-1,sizeof dp);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a>>b>>c;
        v.push_back({a,{b,c}});
    }cout<<solve(0)<<endl;
    return 0;
}






Measured memory_bytes: 12532
def factrial(n):
  factors = []
  while n%2 == 0:
    factors.append(2)
    n //= 2
    
  for i in range(3, int(n**0.5)+1, 2):
    while n%i == 0:
      factors.append(i)
      n //= i
      
  if n != 1: factors.append(n)
    
  return factors


n = int(input())
mod = 10**9+7

d = {}
for i in range(1,n+1):
  fac = factrial(i)
  for j in fac:
    if j in d: d[j] += 1
    else: d[j] = 1

ans = 1
for k,v in d.items():
  ans *= (v+1)
  ans %= mod
print(ans)

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

#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n - 1; i >=0; i--)

string s;
string t;

bool match(int k) {
    rep(i, t.length()) {
        if(k + i > s.length()) return false;
        if(s[i + k] != t[i] && s[i + k] != '?') return false;
    }
    return true;
}

string fill(int k) {
    string ans = s;
    rep(i, t.length())
        ans[i + k] = t[i];
    rep(i, s.length())
        if(ans[i] == '?') ans[i] = 'a';
    return ans;
}

int main() {
    cin >> s >> t;
    rrep(i, s.length()) {
        if(match(i)) {
            cout << fill(i) << endl;
            return 0;
        }
    }
    cout << "UNRESTORABLE" << endl;
}


Measured memory_bytes: 256
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N = I()

def n_base(n,k):
    if n==0:
        return 0
    else:
        bi=''
        if k<0:
            while n!=0:
                bi+=str(n%abs(k))
                n=-(-n//k)
        else:
            while n!=0:
                bi+=str(n%abs(k))
                n=n//k
        return bi[::-1]

print(n_base(N,-2))

Measured memory_bytes: 38256
a=int(input())
b=int(input())
c=int(input())
x=int(input())
count = 0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if i*500 + j*100 + k*50 == x:
        count += 1
print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
int n;
int getbit(int s,int k)
{
	return (s>>k)&1;
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	vector<vector<ii>> g(n);
	for(int i=0;i<n;i++)
	{
		int Ai;
		cin>>Ai;
		for(int j=0;j<Ai;j++)
		{
			int x,y;
			cin>>x>>y;
			x--;
			g[i].emplace_back(ii(x,y));
		}
	}
	int maxmask=(1<<n),ans=0;
	for(int msk=0;msk<maxmask;msk++)
	{
		int cnt=0;
		bool ok=true;
		for(int i=0;i<n;i++)
			if(getbit(msk,i))
			{
				cnt++;
				for(auto v:g[i]) if((getbit(msk,v.first))^v.second) ok=false;
			}
		if(ok) ans=max(ans,cnt);			
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

class Add_Segment_Tree {
	vector<long long int>v;
	long long int ret;
	int num;
	long long int Update(int place) {
		if (place >= v.size() / 2) {
			return v[place];
		}
		v[place] = Update(place * 2) + Update(place * 2 + 1);
		return v[place];
	}
public:
	Add_Segment_Tree(int n) {
		n++;
		num = 1;
		while (num < n * 2)num *= 2;
		v.resize(num, 0);
	}
	void Add(int place, long long int num, bool update) {
		place += v.size() / 2;
		v[place] += num;
		if (!update)return;
		place /= 2;
		while (place) {
			v[place] = v[place * 2] + v[place * 2 + 1];
			place /= 2;
		}
	}
	void TopDown() {
		Update(1);
	}
	long long int Sum(int a, int b) {
		ret = 0;
		b++;
		for (a += num / 2, b += num / 2; a < b; a >>= 1, b >>= 1) {
			if (a & 1)ret += v[a++];
			if (b & 1)ret += v[--b];
		}
		return ret;
	}
};

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

	cin >> N >> K;
	vector<int>l(K), r(K);
	for (int i = 0; i < K; i++) {
		cin >> l[i] >> r[i];
	}
	Add_Segment_Tree asg(N + 1);
	asg.Add(1, 1, true);
	for (int i = 2; i <= N; i++) {
		long long int sum = 0;
		for (int j = 0; j < K; j++) {
			sum += asg.Sum(max(0, i - r[j]), i - l[j]);
		}
		asg.Add(i, sum%MOD, true);
	}
	cout << asg.Sum(N, N) << endl;
}

Measured memory_bytes: 7428
// practice with kaiboy, coached by rainboy
import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	void main() {
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] dd = new int[8];
		int[] d2c = { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };
		while (m-- > 0) {
			int d = sc.nextInt();
			int c = d2c[d];
			dd[c] = Math.max(dd[c], d);
		}
		int c_ = 2;
		while (dd[c_] == 0)
			c_++;
		int n_ = 0;
		for (int c = c_ + 1; c <= 7; c++)
			n_ += c * (c_ - 1);
		int[] dp = new int[n_ + 1]; Arrays.fill(dp, -1); dp[0] = 0;
		for (int i = 0; i < n_; i++) {
			int k = dp[i];
			if (k != -1)
				for (int c = c_; c <= 7 && i + c <= n_; c++)
					if (dd[c] != 0)
						dp[i + c] = Math.max(dp[i + c], k + 1);
		}
		int[] kk = new int[10];
		int k = (n - n_ + c_ - 1) / c_;
		kk[dd[c_]] += k;
		n -= k * c_;
		while (n > 0) {
			c_ = 0;
			for (int c = 2; c <= 7 && n - c >= 0; c++)
				if (dd[c_] < dd[c] && dp[n] == dp[n - c] + 1)
					c_ = c;
			kk[dd[c_]]++;
			n -= c_;
		}
		for (int d = 9; d >= 1; d--)
			while (kk[d]-- > 0)
				print(d);
		println();
	}
}


Measured memory_bytes: 36020
#include <string.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <istream>
#define INF 2147483647
#define LLINF 9223372036854775807
typedef long long ll;
using namespace std;
map<int,int> mp;
set<int> s;
int a[100010];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		mp[a[i]]++;
		s.insert(a[i]);
	}
	int cnt=0;
	for(set<int>::iterator it=s.begin();it!=s.end();it++){
		if(mp[*it]>=*it){
			cnt+=mp[*it]-*it;
		}
		else cnt+=mp[*it]; 
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 9600
#include <stdio.h>
#include <math.h>



int main (void) {
    int N;
    int i, count=0;
    long long D;
    long long X[200000], Y[200000];
  
    scanf("%d %lld", &N, &D);
    
  for(i=0; i<N; i++) scanf("%lld %lld", &X[i], &Y[i]);
  
  for(i=0; i<N; i++) {
    if(X[i]*X[i]+Y[i]*Y[i]<=D*D) count += 1;
  }
  
  printf("%d\n", count);


       
    return 0;
}







Measured memory_bytes: 4820
def read_ints():
    return [int(c) for c in input().split()]


def count(x):
    ret = 0
    while x % 100 == 0:
        ret += 1
        x //= 100
    return ret


def main():
    d, n = read_ints()
    print(list(x for x in range(1, 2000000) if count(x) == d)[n-1])


if __name__ == '__main__':
    main()

Measured memory_bytes: 102416
#include <iostream>
#include <string>
#include <climits>
using namespace std;
int main(){
    string s,t;
    cin >> s;
    cin >> t;
    int tsize = t.size();
    int ssize = s.size();
    int dif_min = INT_MAX;
    for(int i = 0;i + tsize <= ssize;i++){
        string hoge = s.substr(i,tsize);
        int counter = 0;
        for(int j = 0;j < tsize;j++){
            if(t[j] != hoge[j]){
                counter ++;
            }
        }
        if(dif_min > counter){
            dif_min = counter;
        }
    }
    cout << dif_min;
    return 0;
}


Measured memory_bytes: 3632
#!/usr/bin/env python3
#import math
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

N = int(input())
A = list(map(int, input().split()))

g = A[0]
for i in range(1,N):
    g = lcm(g,A[i])
g -= 1

ans = 0
for a in A:
    ans += g % a
print(ans)


Measured memory_bytes: 5344
#include<iostream>
using namespace std;
int A[100];
int main()
{
    int n;
    cin>>n;
    for (int i = 0; i < n; ++i) {
        cin>>A[i];
        if(i==n-1)
            cout<<A[i]<<endl;
        else
            cout<<A[i]<<" ";
    }
    for (int i = 1; i < n ; ++i) {
        int key=A[i];
        int j=i-1;
        while (j>=0&&key<A[j]){
            A[j+1]=A[j];
            j--;
        }
        A[j+1]=key;
        for (int k = 0; k < n; ++k) {
            if(k==n-1)
                cout<<A[k]<<endl;
            else
                cout<<A[k]<<" ";
        }
    }
}


Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>

using namespace std;

typedef vector<int> vi;
typedef queue<int> qi;

bool tarjan(vi e[], int x, int p[], bool st[], int disc[], int &dn, vi &t) {
    int dmax = -1, dmaxp = -1;
    for (int y : e[x]) {
        if (st[y]) {
            if (disc[y] > dmax) {
                dmax = disc[y];
                dmaxp = y;
            }
        }
    }

    if (dmaxp != -1) {
        do {
            t.push_back(x);
            x = p[x];
        } while (x != dmaxp);
        t.push_back(x);
        return true;
    }

    st[x] = true;
    for (int y : e[x]) {
        if (p[y] == x) {
            bool f = tarjan(e, y, p, st, disc, dn, t);
            if (f) {
                return true;
            }
        }
    }

    st[x] = false;
    return false;
}

int main() {
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    vi e[n];
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        e[a].push_back(b);
    }

    int p[n];
    fill(p, p+n, -2);
    bool st[n];
    memset(st, false, sizeof(st));
    int disc[n];
    fill(disc, disc+n, -1);
    int dn = 0;
    for (int i = 0; i < n; i++) {
        if (p[i] == -2) {
            qi q;
            q.push(i);
            p[i] = -1;
            disc[i] = dn++;
            while (!q.empty()) {
                int x = q.front();
                q.pop();

                for (int y : e[x]) {
                    if (disc[y] == -1) {
                        disc[y] = dn++;
                        p[y] = x;
                        q.push(y);
                    }
                }
            }

            vi t;
            if (tarjan(e, i, p, st, disc, dn, t)) {
                cout << t.size() << endl;
                for (int j = t.size() - 1; j >= 0; j--) {
                    cout << t[j] + 1 << endl;
                }
                return 0;
            }
        }
    }

    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int x, a;
    cin >> x >> a;
    if (x < a) {
        cout << 0 << endl;
    }
    else {
        cout << 10 << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define M 1000000007
#define pie 3.141592653589793238
using namespace std;



signed main(){  
    int n,k; cin >> n >> k;
    int a[n];
    for(int i=0; i<n; i++)
        cin >> a[i];
    sort(a,a+n);
    int s = 0;
    for(int i=0; i<k; i++)
        s += a[i];
    cout << s;
    return 0;
}

Measured memory_bytes: 3632
n = int(input())
A = list(map(int,input().split()))
A.sort()

def gcd(x, y):
	while y:
		x, y = y, x % y
	return x
 
ans = gcd(A[0],A[1])
for i in range(2,n):
  ans = gcd(ans,A[i])
print(ans)  
    

      

Measured memory_bytes: 14252
#include"bits/stdc++.h"

#define rep(i, N) for(int i = 0;i < N;i++)

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;



int main(void) {
	string S; cin >> S;

	rep(i, 3)cout << S[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 3620
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	ll n;
	cin >> n;

	ll mi = n - 1;
	for (ll a = 1; a <= sqrt(n); a++) {
		if (n % a == 0) {
			ll b = n / a;
			chmin(mi, a + b - 2);
		}
	}

	out(mi);

	return 0;
}

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

#define all(v) v.begin(), v.end()

const ll mod=1000000007;

ll countBits(ll in){
  int res=0;
  for(;in>0;in>>=1){
    if((in&0x01)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  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);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}

ll powm(ll a,ll n, ll m){
  ll ret=1;
  while(n>0){
    if(n%2==1){
      ret=(ret*a)%m;
    }
    n>>=1;
    a=(a*a)%m;
  }
  return ret;
}

const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int h,w;cin>>h>>w;
  vector<string> s(h);
  for(int i=0;i<h;i++){
    cin>>s[i];
  }
  vector<vector<int>> l(h,vector<int>(w,0));
  vector<vector<int>> r(h,vector<int>(w,0));
  vector<vector<int>> d(h,vector<int>(w,0));
  vector<vector<int>> u(h,vector<int>(w,0));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j]=='#'){
        l[i][j]=0;
        continue;
      }
      if(j==0){
        l[i][j]=1;
        continue;
      }
      l[i][j]=l[i][j-1]+1;
    }
  }
  for(int i=0;i<h;i++){
    for(int j=w-1;j>=0;j--){
      if(s[i][j]=='#'){
        r[i][j]=0;
        continue;
      }
      if(j==w-1){
        r[i][j]=1;
        continue;
      }
      r[i][j]=r[i][j+1]+1;
    }
  }
  for(int i=h-1;i>=0;i--){
    for(int j=0;j<w;j++){
      if(s[i][j]=='#'){
        d[i][j]=0;
        continue;
      }
      if(i==h-1){
        d[i][j]=1;
        continue;
      }
      d[i][j]=d[i+1][j]+1;
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j]=='#'){
        u[i][j]=0;
        continue;
      }
      if(i==0){
        u[i][j]=1;
        continue;
      }
      u[i][j]=u[i-1][j]+1;
    }
  }
  int ans=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      int val=l[i][j]+r[i][j]+d[i][j]+u[i][j]-3;
      ans=max(ans,val);
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 67200
def main():
    mod = 10**9+7
    n,m=map(int,input().split(' '))
    ans = 1
    if abs(n-m)>1:
        ans = 0
        print(ans)
        exit()
    if n==m:
        ans *= 2
    for i in range(1,n+1):
        ans *= i
        ans %=mod
    for j in range(1,m+1):
        ans *= j
        ans %= mod
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import bisect

n=int(input())
arr=[int(input()) for _ in range(n)]
num=1
ans=[-arr[0]]
for i in range(1,n):
  if -arr[i]>=ans[-1]:
    ans.append(-arr[i])
  else:
    pos=bisect.bisect_right(ans,-arr[i])
    ans[pos]=-arr[i]
print(len(ans))

Measured memory_bytes: 11032
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
#include<set>
#include<map>
using namespace std;
using ll = long long;
ll a,b,n;
ll calc(ll x){
  return floor((a*x)/b)-a*floor(x/b);
}

int main(){
  cin >> a >> b >> n;
  if(n>=b-1){
    cout << calc(b-1);
  }
  else{
  cout << calc(n) << endl;
  }
  //cout << ans;
}

Measured memory_bytes: 3596
#include <stdio.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}

ll n;
ll a[100010];
int main(){
	scanf("%lld",&n);
	rep(i,0,n){
		ll t;
		scanf("%lld",&t);
		a[t]++;
	}
	ll flag=1;
	if(n%2){
		flag&=(a[0]==1);
		rep(i,1,n){
			if(i%2)flag&=!a[i];
			else flag&=(a[i]==2);
		}
	}else{
		rep(i,0,n){
			if(i%2==0)flag&=!a[i];
			else flag&=(a[i]==2);
		}
	}
	printf("%lld",flag*pom(2,n/2,1000000007));
}

Measured memory_bytes: 896
#include <vector>
#include <iostream>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<string> s;
    for (int i = 0; i < N; i++) {
        string str;
        cin >> str;
        s.push_back(str);
    }
    int M;
    cin >> M;
    vector<string> t;
    for (int i = 0; i < M; i++) {
        string str;
        cin >> str;
        t.push_back(str);
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        int cnt = 0;
        string str = s[i];
        for (string a : s) {
            if (a == str) {
                cnt++;
            }
        }
        for (string a : t) {
            if (a == str) {
                cnt--;
            }
        }
        ans = (cnt > ans) ? cnt : ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    String s = sc.next();
    if(s.charAt(s.length()-1)=='s'){
      System.out.println(s+"es");
    }
    else{
      System.out.println(s+"s");
    }
  }
}

Measured memory_bytes: 38456
#include"bits/stdc++.h"
using namespace std;
int main(){
	
	int M, N;
	int Tg[100], Guess[100];
	int Point[100] = {0};

	cin >> N >> M;

	for(int i = 0; i < M; i++)
		cin >> Tg[i];

	for(int i = 0; i < M; i++){
		for(int ii = 0; ii < N; ii++){
			cin >> Guess[ii];
		}

		int Weight = 0;
		for(int ii = 0; ii < N; ii++){
			if(Guess[ii] != Tg[i]) Weight++;
			if(Guess[ii] == Tg[i]) Point[ii] += 1;
		}

		Point[Tg[i] - 1] += Weight;

	}
	
	for(int i = 0; i < N; i++)
		cout << Point[i] << endl;
	

	return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    int n;cin>>n;
    vector<int>a(n),b(n),c(n-1);
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    rep(i,n-1)cin>>c[i];
    int cnt=0;
    ll last=-1;
    rep(i,n){
        if(last==a[i]-1)cnt+=c[last-1];
        last=a[i];
        cnt+=b[a[i]-1];
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long
 
const int N = 100001;
 
int n, m, vis[N];
vector <pair <int, int> > v[N], edges;
vector <int> tour;
 
void dfs(int node, int pnode){
    while(v[node].size()){
        if(vis[v[node].back().second]){
            v[node].pop_back();
            continue;
        }
        vis[v[node].back().second] = 1;
        dfs(v[node].back().first, node);
    }
    tour.push_back(node);
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    srand(time(0));
    cin >> n >> m;
    for(int i = 0 ; i < m ; i++){
        int x, y;
        cin >> x >> y;
        v[x].push_back(make_pair(y, i));
        v[y].push_back(make_pair(x, i));
        edges.push_back(make_pair(x, y));
    }
    for(int itt = 0 ; itt < 60 ; itt++){
        memset(vis, 0, sizeof vis);
        tour.clear();
        random_shuffle(edges.begin(), edges.end());
        for(int i = 1 ; i <= n ; i++){
            v[i].clear();
        }
        for(int i = 0 ; i < m ; i++){
            int x = edges[i].first;
            int y = edges[i].second;
            v[x].push_back(make_pair(y, i));
            v[y].push_back(make_pair(x, i));
        }
        for(int i = 1 ; i <= n ; i++){
            if(v[i].size() % 2) finish("No");
        }
        dfs(1, 0);
        int ok = 1;
        for(int i = 0 ; i < m ; i++){
            if(vis[i] == 0){
                ok = 0;
                break;
            }
        }
        if(ok == 0) continue;
        for(int i = 1 ; i <= n ; i++){
            if(v[i].size() >= 6) finish("Yes");
        }
        int ans = 0;
        vector <int> cnt(n + 1);
        for(int i = 0 ; i < (int)tour.size() ; i++){
            cnt[tour[i]]++;
            if(cnt[tour[i]] == 1) continue;
            ans++;
            int j = i - 1;
            cnt[tour[i]]--;
            while(tour[j] != tour[i]){
                cnt[tour[j]]--;
                j--;
            }
        }
        if(ans >= 3) finish("Yes");
    }
    cout << "No\n";
}


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

int solve(map<int, set<int>>& group, unsigned m) {
    vector<char> vis(m, 0);
    function<int(int)> dfs = [&](int k) {
        if (vis[k]) return 0;
        vis[k] = 1;
        if (!group.count(k)) return 1;
        int cnt = 0;
        for (const int& i : group[k]) cnt += dfs(i);
        return cnt;
    };
    return dfs(0);
}

int main() {
    for (int n; cin >> n, n;) {
        cin.ignore();
        map<string, int> id;
        auto getid = [&](string& s) {
            int t = id.size();
            return id.count(s) ? id[s] : id[s] = t;
        };
        map<int, set<int>> group;
        while (n--) {
            string s; getline(cin, s);
            for (auto& e : s) if(ispunct(e)) e = ' ';
            stringstream ss(s);
            ss >> s;
            int i = getid(s);
            for (; ss >> s; group[i].insert(getid(s)));
        }
        cout << solve(group, id.size()) << endl;
    }
}

Measured memory_bytes: 3340
# ABC080C - Shopping Street
# exhaustive search
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    F = tuple(int(input().replace(" ", ""), 2) for _ in range(N))  # str -> bit -> int
    P = tuple(tuple(map(int, input().split())) for _ in range(N))
    # set of sum of profit in each pattern (2^10)
    ans = {
        sum(p[bin(i & f).count("1")] for f, p in zip(F, P)) for i in range(1, 2 ** 10)
    }
    print(max(ans))


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include "bits/stdc++.h"

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
#define fir first
#define sec second

const int INF = 1e9 + 10;
//const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)
ll MOD = 1e9 + 7;

int n;

struct edge { int to; ll dist; };
vector<edge> G[100010];

int color[100010];

void dfs(int v, int c, ll sum) {
	color[v] = c;

	for (int i = 0; i < G[v].size(); i++) {
		edge e = G[v][i];
		if (color[e.to] != -1) continue;

		if ((ll)(sum + e.dist) % 2 == 0) dfs(e.to, 0, (ll)(sum + e.dist));
		else dfs(e.to, 1, (ll)(sum + e.dist));
	}
	return;
}

void solve() {
	for (int i = 0; i < n; i++) color[i] = -1;

	dfs(0, 0, 0LL);
	for (int i = 0; i < n; i++) {
		cout<< color[i] <<endl;
	}
}

int main(void){
	cin>>n;
	for (int i = 0; i < n - 1; i++) {
		int u, v; ll w; cin>>u>>v>>w;
		u--; v--;
		G[u].push_back((edge){v, w});
		G[v].push_back((edge){u, w});
	}

	solve();
	
	return 0;
}

Measured memory_bytes: 9856
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cassert>
#include <complex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <ctime>
#include <cctype>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <deque>
#include <stack>
#include <memory.h>
using namespace std;
#define ll long long 
int n;
vector<int> g[200005];
int d1[100005],d2[100005];
void dfs(int r,int f,int d,int dist[])
{
    dist[r]=d;
    for(int x:g[r])
    {
        if(x!=f)
            dfs(x,r,d+1,dist);
    }
}
int main()
{
    while(cin>>n)
    {
        for(int i=0;i<n;i++){ 
            g[i].clear();
        }
        int u,v;
        for(int i=0;i<n-1;i++)
        {
            cin>>u>>v;
            u--,v--;
            g[u].push_back(v);
            g[v].push_back(u);
        }
        dfs(0,-1,0,d1);
        dfs(n-1,-1,0,d2);
        int ans=0;
        for(int i=0;i<n;i++)
        {
            if(d1[i]<=d2[i]){
            	ans++;
			}
            else {
            	ans--;
            }
        }
        if(ans>0)
            cout <<"Fennec"<< endl;
        else
            cout<<"Snuke"<<endl;
    }
    return 0;
}

Measured memory_bytes: 15104
N, M, K = gets.split.map(&:to_i)
AS = [0] + gets.split.map(&:to_i)
BS = [0] + gets.split.map(&:to_i)
def preprocess(as)
  ret = []
  n = 0
  as.length.times do |i|
    n += as[i]
    if n > K
      return ret
    end
    ret << n
  end
  ret
end
as = preprocess(AS)
bs = preprocess(BS) + [Float::INFINITY]

a = as.length-1
while as[a] > K
  a -= 1
end

ans = a
b = 0
while a >= 0
  rest = K - as[a]
  while bs[b] <= rest
    b += 1
  end
  b -= 1
  cand = a + b
  #p a: a, b: b, cand: cand, rest: rest
  ans = cand if cand > ans
  a -= 1
end
p ans

Measured memory_bytes: 46772
local mod = 1000000007
local mfl = math.floor

local function bmul(x, y)
  local x0, y0 = x % 31623, y % 31623
  local x1, y1 = mfl(x / 31623), mfl(y / 31623)
  return (x1 * y1 * 14122 + (x1 * y0 + x0 * y1) * 31623 + x0 * y0) % mod
end

local function badd(x, y)
  return (x + y) % mod
end

local function bsub(x, y)
  return x < y and x - y + mod or x - y
end

local function modpow(src, pow)
  local res = 1
  while 0 < pow do
    if pow % 2 == 1 then
      res = bmul(res, src)
      pow = pow - 1
    end
    src = bmul(src, src)
    pow = mfl(pow / 2)
  end
  return res
end

local function modinv(src)
  return modpow(src, mod - 2)
end

local function getComb(n, k)
  local ret = 1
  for i = 1, k do
    ret = bmul(ret, n + 1 - i)
    ret = bmul(ret, modinv(i))
  end
  return ret
end

local n, a, b = io.read("*n", "*n", "*n")
local ret = modpow(2, n)
ret = bsub(ret, 1)
ret = bsub(ret, getComb(n, a))
ret = bsub(ret, getComb(n, b))
print(ret)


Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
long long hoge[6] = {};
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		if (s[0] == 'M') {
			hoge[0]++;
		}
		if (s[0] == 'A') {
			hoge[1]++;
		}
		if (s[0] == 'R') {
			hoge[2]++;
		}
		if (s[0] == 'C') {
			hoge[3]++;
		}
		if (s[0] == 'H') {
			hoge[4]++;
		}
	}
	long long ans = 0;
	for (int i = 0; i < 5; ++i) {
		for (int q = i + 1; q < 5; ++q) {
			for (int j = q + 1; j < 5; ++j) {
				ans += hoge[i] * hoge[q] * hoge[j];
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int count = 0;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		for (int i = n-1; i >= 0; i--) {
			for (int j = n-1; j > 0; j--) {
				int tmp = a[j];
				if (a[j] < a[j-1]) {
					a[j] = a[j-1];
					a[j-1] = tmp;
					count++;
				}
			}
		}
		print(a);
		System.out.println(count);

	}
	static void print(int[] a) {
		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i]);
			if (i != a.length-1) {
				System.out.print(" ");
			}
		}
		System.out.print("\n");
	}

}



Measured memory_bytes: 26296
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

void _149() {
    string s, t;
    cin >> s >> t;
    cout << t + s << endl;
}

void _148() {
    int a, b;
    cin >> a;
    cin >> b;

    int c = 0;
    if ((a != 1) && (b != 1))
        c = 1;
    else if ((a != 2) && (b != 2))
        c = 2;
    else if ((a != 3) && (b != 3))
        c = 3;
    cout << c << endl;
}

void _147() {
    int a, b, c;
    cin >> a >> b >> c;

    if (a + b + c >= 22)
        cout << "bust" << endl;
    else
        cout << "win" << endl;
}

void _146() {
    string s;
    cin >> s;

    vector<string> list = {"SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"};
    for (int i = 0; i < list.size(); ++i) {
        if (s == list[i])
            cout << i + 1 << endl;
    }
}

void _145() {
    int r;
    cin >> r;
    cout << pow(r, 2) << endl;
}

void _144() {
    int a, b;
    cin >> a >> b;

    if ((a >= 1 && a <= 9) && (b >= 1 && b <= 9))
        cout << a * b << endl;
    else
        cout << -1 << endl;
}

void _143() {
    int a, b;
    cin >> a >> b;

    if (b * 2 >= a)
        cout << 0 << endl;
    else
        cout << a - 2 * b << endl;
}

int main()
{
    _143();
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

char CardTypeToName( int type ) {
	switch( type ) {
		case 0: return 'S';
		case 1: return 'H';
		case 2: return 'C';
		case 3: return 'D';
	}
	return ' ';
}

int main() {
	bool a[4][13];
	std::fill( (bool*)a, (bool*)(a+4), false );

	int num;
	cin >> num;
	for( int i=0; i<num; i++ ) {
		char type;
		int rank;
		cin >> type >> rank;
		switch( type ) {
		case 'S': a[0][rank-1] = true;	break;
		case 'H': a[1][rank-1] = true;	break;
		case 'C': a[2][rank-1] = true;	break;
		case 'D': a[3][rank-1] = true;	break;
		}
	}
	for( int i=0; i<4; i++ ) {
		for( int j=0; j<13; j++ ) {
			if( a[i][j] ) { continue; }
			cout << CardTypeToName( i ) << " " << (j+1) << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>

using namespace std;

int func(bool a[101][101], int u, int v, int s, int t)
{
	int c = 0;
	
	for(int i = 0; i < t; i++){
		for(int j = 0; j < s; j++){
			if(a[i+u][j+v]){
				c++;
			}
		}
	}
	
	return c;
}

int main()
{
	int n, h, w, s, t, c;
	bool a[101][101];
	
	while(cin>>n && n){
		cin >> w >> h;
		fill(&a[1][1], &a[h][w], false);
		c = 1;
		for(int i = 0; i < n; i++){
			cin >> t >> s;
			a[s][t] = true;
		}
		cin >> s >> t;
		
		for(int i = 1; i <= h-t+1; i++){
			for(int j = 1; j <= w-s+1; j++){
				c = max(c, func(a, i, j, s, t));
			}
		}
		
		cout << c << endl;
	}
	
	return 0;
}

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

using namespace std;

static const int MAX_N = 100;

int main() {
    int N;
    vector<int> a;
    int t;

    cin >> N;

    for (int i = 0; i < N; i++) {
        cin >> t;
        a.push_back(t);
    }

    sort(a.begin(), a.end(), greater<int>());

    int w = 0;
    int s_a = 0;
    int s_b = 0;
    for (auto s : a) {
        if (w == 0) {
            s_a += s;
            w = 1;
        } else {
            s_b += s;
            w = 0;
        }
    }
    cout << s_a - s_b << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second 
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define rep(i,a,b) for( ll i = a ; i < b ; i+=1 )
#define pp pair<ll,ll> 
#define sz(v) (ll)(v.size())
#define hell (ll)1000000007 
#define slld(x) scanf("%lld",&x)
ll t = 1 ;
void solve()
{
    ll n ;
    cin >> n ; 
    cout << (n*(n-1))/2 ;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //cin >> t ;
    while(t--){
        solve();
    }
    return 0 ;
}


Measured memory_bytes: 256
using System.Text;
using System.Collections.Generic;
using System;

public class hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        var q = int.Parse(Console.ReadLine().Trim());
        var sb = new StringBuilder();
        for (int i = 0; i < q; i++)
        {
            var k = int.Parse(Console.ReadLine().Trim());
            var ans = LowerBound(a, k);
            sb.Append(string.Format("{0}\n", ans));
        }
        Console.Write(sb);
    }
    public static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer)
    {
        int low = start;
        int high = end;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (comparer.Compare(arr[mid], value) < 0)
                low = mid + 1;
            else
                high = mid;
        }
        return low;
    }
    public static int LowerBound<T>(T[] arr, T value) where T : IComparable
    {
        return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default);
    }
}




Measured memory_bytes: 36552
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
2 20
5 9
4 10

output:
9

1 ??? N ??? 100
1 ??? vi ??? 100
1 ??? wi ??? 10,000,000
1 ??? W ??? 1,000,000,000
"""

import sys
from collections import namedtuple

MAX_V = 100


def solve():
    dp = [[float('inf')] * (c_items * MAX_V + 1) for _ in range(c_items + 1)]
    dp[0][0] = 0
    for i, item in enumerate(item_list):
        v, w = item.value, item.weight
        for j in range(c_items * MAX_V + 1):
            if j < v:
                dp[i + 1][j] = dp[i][j]
            else:
                dp[i + 1][j] = min(dp[i][j], dp[i][j - v] + w)

    ans = 0
    for i in range(c_items * MAX_V + 1):
        if dp[c_items][i] <= knapsack_cp:
            ans = i

    return ans


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    c_items, knapsack_cp = map(int, _input[0].split())
    items = map(lambda x: x.split(), _input[1:])

    Item = namedtuple('Item', ('value', 'weight'))
    item_list = [Item(int(v), int(w)) for v, w in items]

    print(solve())

Measured memory_bytes: 19392
s=input()
n=len(s)+1
ans=[0]
p=s[::-1]
cnt=0
for i in range(n-1):
	if s[-i-1]==">":
		cnt+=1
	else:
		cnt=0
	ans.append(cnt)
ansk=[]
for i in range(n):
	ansk.append(ans[-i-1])
import copy
kari=copy.copy(ansk)
cnt=0
for i in range(n-1):
	if kari[i]==kari[i+1]==0:
		cnt+=1
		ansk[i+1]=cnt
	else:
		if kari[i]==0:
			if ansk[i+1]<=ansk[i]:
				ansk[i+1]=ansk[i]+1
		cnt=0
print(sum(ansk))

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

using namespace std;

typedef long long ll;

const int MOD = 1000000007;
const int MAXN = 100003;
const int STATES = 2;

int N;
vector<int> edges[MAXN];
int dp[MAXN][STATES];

int add(int a, int b) {
  return (a + b) % MOD;
}
int mul(int a, int b) {
  return (ll(a) * ll(b)) % MOD;
}
int solve(int u, int parent, bool black) {
  if(parent > 0 && edges[u].size() == 1) return 1;
  if(dp[u][black]) return dp[u][black];

  int ans = 1;
  if(black) {
    for(int v: edges[u]) {
      if(v == parent) continue;

      ans = mul(ans, solve(v, u, 0));
    }
  } else {
    for(int v: edges[u]) {
      if(v == parent) continue;

      ans = mul(ans, add(solve(v, u, 0), solve(v, u, 1)));
    }
  }
  
  return dp[u][black] = ans;
}

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

  cin >> N;
  for(int i = 0; i < N - 1; ++i) {
    int u, v;
    cin >> u >> v;

    edges[u].push_back(v);
    edges[v].push_back(u);
  }

  int ans = add(solve(1, -1, 0), solve(1, -1, 1));
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 16764
import itertools
N=int(input())
S=input()

ans=0

for i in itertools.product(range(0,10),repeat=3):

    isOK=[False]*3
    
    for x in range(len(S)):
        if isOK[0] and isOK[1]:
            if int(S[x])==i[2]:
                ans+=1
                break
        elif isOK[0]:
            if int(S[x])==i[1]:
                isOK[1]=True
        else:
            if int(S[x])==i[0]:
                isOK[0]=True

print(ans)

Measured memory_bytes: 73816
S = input()
N = len(S)
D = []
for i in range(0, N - 2):
    D.append(S[i: i + 3])
E = []
for j in range(N - 2):
    n = abs(753 - int(D[j]))
    E.append(n)
ans = min(E)
print(ans)

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

int main()
{
    int N, a, b, c, d;
    cin >> N;
    a = N % 10;
    b = (N % 100 - N % 10) / 10;
    c = (N % 1000 - N % 100) / 100;
    d = (N - N % 1000) / 1000;

    if((a == b && a == c)||(b == c && b == d)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

int main() {
    int N, M;
    cin >> N >> M;
    pair<int, int> ba[M];
    for (int i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        ba[i] = make_pair(b, a);
    }
    sort(ba, ba + M);

    int x = ba[0].first;
    int cnt = 1;
    for (int i = 1; i < M; i++)
    {
        if(ba[i].second >= x){
            x = ba[i].first;
            cnt++;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
using namespace std;
char s[10005];
int n,cur,ans;
inline int max(int a,int b){
    return a>b?a:b;
}
int main(){
    scanf("%d",&n);
    scanf("%s",s);
    for(int i=0;i<n;i++)
        if(s[i]=='I'){
            cur++;
            ans=max(ans,cur);
        } else cur--;
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <bitset>
using namespace std;
typedef long long int lli;
int main(void)
{
    int N;
    cin >> N;
    vector<int> a;
    int tmp;
    for (int i = 0; i < N; i++)
    {
        cin >> tmp;
        a.push_back(tmp);
    }
    sort(a.begin(), a.end());
    int *x;
    int n = a[N - 1];
    x = new int[100000];
    fill(x, x + (n + 1), 0);
    for (int i = 0; i < N; i++)
    {
        x[a[i]]++;
    }
    int Q;
    int b, c;
    cin >> Q;
    lli *sum;
    sum = new lli[Q];

    /*cin >> b >> c;
    replace(a.begin(), a.end(), b, c);
    sum.push_back(accumulate(a.begin(), a.end(), 0));
    */
    lli tmp1 = 0;
    for (int i = 0; i < N; i++)
    {
        tmp1 += a[i];
    }
    cin >> b >> c;
    sum[0] = tmp1 + x[b] * (c - b);
    x[c] += x[b];
    x[b] = 0;
    for (int i = 1; i < Q; i++)
    {
        cin >> b >> c;
        sum[i] = sum[i - 1] + x[b] * (c - b);
        x[c] += x[b];
        x[b] = 0;
    }
    for (int i = 0; i < Q; i++)
    {
        cout << sum[i] << endl;
    }
}


Measured memory_bytes: 4996
n,k = list(map(int,input().split()))
num_list = list(map(int,input().split()))
next_list = []
mod = ((10**9)+7)
up = 0
exup = 0
ans = 0
for i in range(n):
    for j in num_list:
        if num_list[0] > j:
            up+=1
    next_list.append(num_list.pop(0))
for i in range(n):
    for j in next_list:
        if next_list[-1] > j:
            exup+=1
    del next_list[-1]
ans = up*k*(k+1)//2 + exup*(k-1)*k//2

print(int(ans%mod))

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

int main() {
  int A,B,C,ans=0;
  cin >> A >> B >> C;
  if(A==B) ans=C;
  else if(B==C) ans=A;
  else ans=B;
  cout << ans << endl;
  return 0;
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a + b > c + d) {
  	cout << "Left" << endl;
  } else if (a + b < c + d) {
    cout << "Right" << endl;
  } else {
  	cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();

        long gcd = gcd(a, b);

        int count = 1;

		long d = gcd;
		for (int i = 2; i <= Math.sqrt(gcd); i++) {
			if (d % i == 0) {
				count++;
				while (d % i == 0) {
					d = d / i;
				}
			}
		}

		if (d != 1)
			count++;
		System.out.println(count);
    }

    static long gcd (long a, long b) {
    	long temp;
    	while((temp = a%b)!=0) {
    		a = b;
    		b = temp;
    	}
    	return b;
    }

}


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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << 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; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;

int main(){

  ll n;cin>>n;
  out(setprecision(10)<<pow(n,3));

  return 0;
}



Measured memory_bytes: 3468
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll a,b,c;
  int cnt=0;
  cin>>a>>b>>c;
  for(int i=0;i<100000;i++){
    if(a%2==1||b%2==1||c%2==1){
      cout<<cnt<<endl;
      return(0);
    }
    ll na=b/2+c/2;
    ll nb=a/2+c/2;
    ll nc=a/2+b/2;
    a=na;
    b=nb;
    c=nc;
    cnt++;
  }
  cout<<-1<<endl;
  return(0);
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

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

//container util

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

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

const int N = 1005;
int x[N], y[N];
int u[N], v[N];
char* d = "RUDL";

int main() {
	int n;
	scanf("%d", &n);
	REP(i, n)scanf("%d%d", &x[i], &y[i]);
	int parity = (x[0] ^ y[0]) & 1;
	REP(i, n) {
		if ((x[i] ^ y[i] ^ parity) & 1) {
			printf("-1\n");
			return 0;
		}
		u[i] = x[i] + y[i];
		v[i] = x[i] - y[i];
	}
	VI arms((parity) ? 1 : 2, 1);
	FOR(i, 1, 31)arms.PB(1 << i);
	int m = arms.size();
	printf("%d\n", m);
	REP(i, m)printf("%d ", arms[i]);
	printf("\n");
	REP(i, n) {
		VI dir(m, 0);
		for (int j = m - 1; j >= 0; j--) {
			//u
			if (u[i] < 0) {
				u[i] += arms[j];
				dir[j] |= 2;
			}
			else {
				u[i] -= arms[j];
			}
			//v
			if (v[i] < 0) {
				v[i] += arms[j];
				dir[j] |= 1;
			}
			else {
				v[i] -= arms[j];
			}
		}
		string ret;
		REP(j, m) {
			ret += d[dir[j]];
		}
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 2000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define dum(x) cout<<#x<<'='<<x<<endl
#define dum2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define dum3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl

//ifstream in("Text.txt");cin.rdbuf(in.rdbuf());

unordered_map<int, bool>ump[200020];

int main() {
    int N, M, a, b;
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        cin >> a >> b;
        ump[a][b] = true;
        ump[b][a] = true;
    }
    for (int i = 2; i <= N; i++) {
        if (ump[1][i] == true && ump[i][N] == true) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 40684