akhauriyash/Code-Regression huggingface dataset:
sa = list(input())
sb = list(input())
sc = list(input())

now = "a"
check = True
while check:
    if now == "a":
        if len(sa) == 0:
            print("A")
            check = False
        else:
            nex = sa[0]
            sa.pop(0)
    elif now == "b":
        if len(sb) == 0:
            print("B")
            check = False
        else:
            nex = sb[0]
            sb.pop(0)
    elif now == "c":
        if len(sc) == 0:
            print("C")
            check = False
        else:
            nex = sc[0]
            sc.pop(0)
    now = nex

Measured memory_bytes: 3064
n, m = map(int, input().split())
scores = []
for _ in range(m):
    num, r = input().split()
    scores.append([num, r])

answers = [0] * (n + 1)
penalties = [0] * (n + 1)
ac = set()
for num, r in scores:
    n = int(num)
    if r == 'AC':
        answers[n] = 1
        ac.add(n)
    elif r == 'WA' and answers[n] == 0:
        penalties[n] += 1

ans = sum(answers)
p = 0
for a in ac:
    p += penalties[a]

print(ans, p)

Measured memory_bytes: 34836
#include<bits/stdc++.h>
#include<string>
#include <iostream>
using namespace std;
int main()
{
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	int score=0;
	int p=min(a,k);
	k-=p;
	score+=p;
	if(k>0)
	{
		k-=min(k,b);

	}
	if(k>0)
	{
	    int z=min(k,c);
		k-=z;
		score-=z;

	}
	cout<<score<<endl;
	return 0;


}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[3001][3001];
char a[3001][3001]; string s1,s2;
void print(int i,int j)
{
    if(i<=0||j<=0)
    return;
    if(a[i][j]=='/')
    {
        print(i-1,j-1);cout<<s2[j-1];
    } 
    else if(a[i][j]=='-')
    print(i,j-1);
    else if(a[i][j]=='|')
    print(i-1,j);
}
int main()
{
   
    cin>>s1>>s2;
    int l=s1.size(),r=s2.size();
    for(int i=0;i<=l;i++)
    dp[i][0]=0;
    for(int i=0;i<=r;i++)
    dp[0][i]=0;
    for(int i=1;i<=l;i++)
    {
        for(int j=1;j<=r;j++)
        {
            if(s1[i-1]==s2[j-1])
            {
                a[i][j]='/';
                dp[i][j]=1+dp[i-1][j-1];
            }
            else 
            {
                if(dp[i][j-1]>=dp[i-1][j])
                {
                    dp[i][j]=dp[i][j-1];
                    a[i][j]='-';    
                }
                else
                {
                    dp[i][j]=dp[i-1][j];
                    a[i][j]='|';    
                }
            }
        }
    }
    print(l,r);
    cout<<endl;
}

Measured memory_bytes: 79488
/*
	@author: cheerioskun
*/
#pragma GCC target("popcnt")
#include "bits/stdc++.h"
#define f first
#define sc second
#define pb push_back
#define MOD 1000000007L
#define inf 0x3f3f3f3f
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long int ll;
typedef std::vector<int> vi;
typedef std::pair<int, int> pii;
using namespace std;

ll w[102], v[102];

int main(){
	fast_io
	int N, W;
	cin>>N>>W;
	for(int i = 0;i < N; ++i){
		cin>>w[i]>>v[i];
	}
	ll** dp = new ll*[N + 1];
	for(int i = 0;i <= N; ++i){
		dp[i] = new ll[W + 1]();
	}
	for(int i = 0;i <= W; ++i){
		dp[0][i] = 0;
	}
	for(int i = 0;i <= N; ++i){
		dp[i][0] = 0;
	}
	for(int i = 0;i < N; ++i){
		for(int j = 0;j <= W; ++j){
			if(j + w[i] <= W){
				dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
			}
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
		}
	}
	ll ans = -inf;
	for(int j = 0;j <= W; ++j){
		ans = max(ans, dp[N][j]);
	}
	cout<<ans<<endl;
	#ifndef ONLINE_JUDGE
    	cout<<"Time Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}



Measured memory_bytes: 82732
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 1000000007;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;


	void doIt() {
		int n = sc.nextInt();
		int d[] = new int[n];
		int sum = 0;
		for(int i = 0; i < n; i++) {
			d[i] = sc.nextInt();
			sum += d[i];
		}
		int ans = 0;
		for(int i = 0; i < n; i++){
			sum -= d[i];
			ans += d[i] * sum;
		}
		System.out.println(ans);
	}
		
	
	

	public static void main(String[] args) {
		new Main().doIt();
	}
}


Measured memory_bytes: 21968
#include<cstdio>
long long f(long long x,long long y){
	if(x==-1) return 0;
	else return x / y + 1;
}
int main(){
	long long a,b,x;
	scanf("%lld %lld %lld",&a,&b,&x);
	printf("%lld\n",f(b,x)-f(a-1,x));
}


Measured memory_bytes: 256
M,K=map(int,input().split())
        
ans=[]
for i in range(pow(2,M)):
    if i!=K:
        ans.append(str(i))
ans1=ans+[str(K)]+ans[::-1]+[str(K)]
if K==0:
    ans1=[]
    for i in range(pow(2,M)):
        ans1+=[str(i)]*2
if K>=pow(2,M):
    print(-1)
elif K==M==1:
    print(-1)
else:
    print(' '.join(ans1))

Measured memory_bytes: 25352
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {

    static final int MOD = 1000000007;
    static final int INF = 1 << 30;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long ans = 0;
        long A = sc.nextLong()-1;
        long B = sc.nextLong();
        long X = sc.nextLong();
        if(A==-1){
            ans = B/X + 1;
        }else{
            ans = B/X-A/X;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23636
#include<iostream>
#include<unordered_map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
#define pb push_back
const ll mod = 1000000007;

void sayNo() {
	cout << "No" << endl;
}

void sayYes() {
	cout << "Yes" << endl;
}

int main() {
	 int N;
	 cin >> N;
	 vector<int> A;

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

	 int count = 1;
	 deque<int> nums(1, A[0]);

	 for (int i = 1; i < N; i++) {
		 if (nums[0] >= A[i]) {
			 nums.push_front(A[i]);
			 count++;
			 continue;
		 }
		 auto itr = lower_bound(nums.begin(), nums.end(), A[i]);
		 int id = distance(nums.begin(), itr);
		 nums[id - 1] = A[i];
	 }
	 cout << count << endl;

	 return 0;
}

Measured memory_bytes: 1016
while True:
    n, k = map(int, input().split())
    if not n:
        break
    cards = [int(input()) for _ in range(k)]
    cards.sort(reverse=True)
    white = False
    if not cards[-1]:
        white = True
        cards.pop()
    if not cards:
        print(1)
        continue
    prev, cnt, precnt = cards.pop(), 1, 0
    ans = 1
    while cards:
        cur = cards.pop()
        diff = cur - prev
        if diff == 1:
            cnt += 1
        else:
            ans = max(ans, precnt + cnt)
            precnt = (cnt + 1) if white and diff == 2 else 0
            cnt = 1
        prev = cur
    ans = max(ans, precnt + cnt)

    print(ans)

Measured memory_bytes: 11128
import sys
def input():
    return sys.stdin.readline()[:-1]
N,K=map(int,input().split())
s=[tuple(map(int,input().split())) for i in range(N)]
lx,ly=[],[]
for i in s:
    lx.append(i[0])
    ly.append(i[1])
lx.sort()
ly.sort()
a=10**20
t=N-K
for i in range(N-1):
    for j in range(i+1,N):
        for k in range(N-1):
            for m in range(k+1,N):
                S=(lx[j]-lx[i])*(ly[m]-ly[k])
                if S>=a:
                    continue
                c=0
                for n in s:
                    if lx[i]<=n[0]<=lx[j] and ly[k]<=n[1]<=ly[m]:
                        continue
                    c+=1
                    if c>t:
                        break
                else:
                    a=S
print(a)

Measured memory_bytes: 49372
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] c = new int[n - 1];
		int[] s = new int[n - 1];
		int[] f = new int[n - 1];
		for(int i = 0 ; i < n - 1 ; i++) {
			c[i] = sc.nextInt();
			s[i] = sc.nextInt();
			f[i] = sc.nextInt();
		}
		for(int i = 0 ; i < n - 1 ; i++) {
			int t = s[i] + c[i];
			for(int j = i + 1 ; j < n - 1 ; j++) {
				if(t < s[j]) t = s[j];
				else if(t % f[j] != 0) t += f[j] - t % f[j];
				t += c[j];
			}
			System.out.println(t);
		}
		System.out.println(0);
	}
}


Measured memory_bytes: 26456
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    m=min(A); M=max(A)
    mi=A.index(m)+1; Mi=A.index(M)+1
    print(2*n-2)
    # 全て非負にする
    if(-m<=M):
        for i in range(1,n+1):
            if(i==Mi): continue
            print(Mi,i)
        for i in range(1,n):
            print(i,i+1)
    # 全て非正にする
    else:
        for i in range(1,n+1):
            if(i==mi): continue
            print(mi,i)
        for i in range(n,1,-1):
            print(i,i-1)
resolve()

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

int main() {
  int m1,d1,m2,d2;
  cin >> m1 >> d1 >> m2 >> d2;
  if(m1 == m2){
    cout << 0 << endl;
  }
  else{
    cout << 1 << endl;
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <vector>
using namespace std;

int solution(const vector<int> &p, const vector<int> &c, const int g) {
    //TODO: check if p and c are valid
    int n = p.size();
    int foo = accumulate(p.begin(), p.end(), 0);
    int tail = 1 << n;
    for (int k = 0; k < tail; ++k) {
        int cost = 0;
        int need = g;
        for (int i = 0; i < n; ++i) {
            if ((k >> i) & 1) {
                cost += p[i];
                need -= p[i] * (i + 1) + c[i];
            }
        }
        for (int i = n - 1; i >= 0; --i) {
            if (need <= 0) break;
            if (((k >> i) & 1) == 0) {
                int num = min((need + i) / (i + 1), p[i] - 1);
                cost += num;
                need -= num * (i + 1);
            }
        }
        if (need <= 0)
            foo = min(cost, foo);
    }
    return foo;
}

int main() {
    int n, g;
    scanf("%d%d", &n, &g);
    g /= 100;
    vector<int> p(n, 0);
    vector<int> c(n, 0);
    for (int i = 0; i < n; ++i) {
        scanf("%d%d", &p[i], &c[i]);
        c[i] /= 100;
    }
    printf("%d\n", solution(p, c, g));
    return 0;
}

Measured memory_bytes: 888
import java.util.*;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int a = scan.nextInt();
		int b = scan.nextInt();
		int h = scan.nextInt();
		int m = scan.nextInt();
		double kaku = 0;
		
		double h_kaku = h*30;
		if(m!=0) {
			h_kaku += m*0.5;
		}
		double m_kaku = m*6;
		
		kaku = Math.min(h_kaku-m_kaku, 360-(h_kaku-m_kaku));
		double ans = 0;
		
		
		if(kaku!=90) {
			ans = Math.pow(a, 2)+Math.pow(b, 2)-2*a*b*Math.cos(kaku*(Math.PI/180));
		}else {
			ans = Math.pow(a, 2)+Math.pow(b, 2)-2*a*b*0;
		}
		
		System.out.println(Math.sqrt(ans));
		
		
		
		
	}	
	
	
	//�ŏ�����
	/*
	static int gcd (int a, int b) {
		int temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return b;
	}
	*/
	
	//����ւ�
	/*
	static int swap (int a, int b) {
		int swap_arr[] = new int[2];
		
		swap[0] = b;
		swap[1] = a;
		
		return swap_arr;
	}
	*/
	
}



Measured memory_bytes: 35972
#!/usr/bin/env python3

def main():
    n = input()
    l = len(n)
    k = int(input())
    dp0 = [0 for j in range(4)]
    dp1 = [0 for j in range(4)]
    dp1[0] = 1
    for i in range(l):
        d = int(n[i])
        if d == 0:
            for j in [3, 2, 1]:
                dp0[j] += dp0[j - 1] * 9
        else:
            for j in [3, 2, 1]:
                dp0[j] += dp0[j - 1] * 9
                dp0[j] += dp1[j - 1] * max(0, d - 1)
                dp0[j] += dp1[j]
            dp0[0] += dp1[0]
            dp1 = [0] + dp1[0:3]
    print(dp0[k] + dp1[k])

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
      const int mx=100000;
    pair<long long,long long>ps[mx];
    long long n,a,b,i=0,cnt=0,k,t=-1000000000;
    cin>>n;
    k=n;
    for(i=0;i<n;i++)
    {
        cin>>a>>b;
        ps[i]=make_pair(a+b,a-b);
    }
    sort(ps,ps+n);
    for(i=0;i<n;i++)
    {
          if(t<=ps[i].second)
          {
                cnt++;
                t=ps[i].first;
          }
    }
    cout<<cnt<<endl;

}


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

int main(){
  string A,B,C;
  cin >> A >> B >> C;
  char next='a';
  int next_A=0,next_B=0,next_C=0;
  while(true){
    if(next=='a'){
      if(next_A==A.size()){
        cout << "A" << endl;
        break;
      }
      else{
        next=A.at(next_A);
        next_A++;
      }
    }
    if(next=='b'){
      if(next_B==B.size()){
        cout << "B" << endl;
        break;
      }
      else{
        next=B.at(next_B);
        next_B++;
      }
    }
    if(next=='c'){
      if(next_C==C.size()){
        cout << "C" << endl;
        break;
      }
      else{
        next=C.at(next_C);
        next_C++;
      }
    }
  }
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  long long n;                                                                 cin >> n;
  long long i;                                                                 long long cnt = 0;                                                           vector<long long> a(n);                                                      long long max = 0;
  for(i=0;i<n;i++) cin >> a[i];
  for(i=0;i<n;i++){
    if(max<=a[i]) max = a[i];
    else cnt += max-a[i];
  }
  cout << cnt << "\n";
  return 0;
}

Measured memory_bytes: 4844
/*
 * じょえチャンネル
 * 高評価・チャンネル登録よろしくおねがいします！
 * https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
 */
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define inf (int)(3e18)
#define P pair<int,int>
#define mod (int)(1e9+7)
template<class T> inline void chmin(T &a, T b) {
	a = min(a, b);
}
template<class T> inline void chmax(T &a, T b) {
	a = max(a, b);
}

int A,B,M;
int a[100005],b[100005];
signed main(){
	cin>>A>>B>>M;
	rep(i,A)cin>>a[i];
	rep(i,B)cin>>b[i];
	int ans=inf;
	rep(i,M){
		int x,y,c;cin>>x>>y>>c;x--;y--;
		chmin(ans,a[x]+b[y]-c);
	}
	sort(a,a+A);
	sort(b,b+B);
	chmin(ans,a[0]+b[0]);
	cout<<ans<<endl;
}


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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int len = sc.nextInt();
		String dummy = sc.nextLine();

	    String[] array = new String[num];
	    for(int i = 0; i<num; i++){
	        array[i] = sc.nextLine();
	    }

	    Arrays.sort(array);
	    for(int i = 0; i<array.length; i++){
			System.out.print(array[i]);
	    }
	}
}


Measured memory_bytes: 23380
#include<cstdio>
#include<cstring>

#define MAXN 100000
char str[MAXN+5];

int main(){
    scanf("%s",str+1);
    int N=strlen(str+1),Ans=0,r=0,p=0;
    for(int i=1;i<=N;i++){
        if(str[i]=='g'){
            if(p<r) Ans++,p++;
            else r++;
        }
        else{
            if(p<r) p++;
            else Ans--,r++;
        }
    }
    printf("%d",Ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.1415926;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
using namespace std;
vector<ll> v;
vector<string> vs;
vector<pair<ll, ll>> vp;
vector<vector<ll>> vv(110, vector<ll>(50, 0));
vector<tuple<ll, ll, ll>> vt;
map<ll, ll> mp;

typedef int Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}

int main()
{
	ll a, b, c;
	cin >> a >> b >> c;
	cout << ((10 * b + c) % 4 ? "NO" : "YES") << endl;
}

Measured memory_bytes: 256
def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline
    
    N, M = map(int, input().split())
    C = []
    D = UnionFind(N)
    E = [0]
    ans = []
    
    for i in range(M):
        A,B = map(int, input().split())
        C.append([A,B])
    C = C[::-1]
    for i in range(M):
        A,B = C[i]
        p = D.union(A,B)
        E.append(E[i]+p)
    benri = int(N*(N-1)/2)
    for i in range(M):
        ans.append(benri - E[i])
    ans = ans[::-1]
    for i in range(M):
        print(ans[i])

class UnionFind:
    def __init__(self, n):
        self.par = [-1 for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if not x==y:
            if self.rank[x] < self.rank[y]:
                tmp = self.par[y]
                tmp2 = self.par[x]
                self.par[y] += self.par[x]
                self.par[x] = y
                return int(self.par[y]*(self.par[y]+1)/2 - tmp*(tmp+1)/2 - tmp2*(tmp2+1)/2)
            else:
                tmp = self.par[x]
                tmp2 = self.par[y]
                self.par[x] += self.par[y]
                self.par[y] = x
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1
                return int(self.par[x]*(self.par[x]+1)/2 - tmp*(tmp+1)/2 - tmp2*(tmp2+1)/2)
        else:
            return 0
        

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)  

main()

Measured memory_bytes: 106672
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#include <bitset>
#include <iomanip>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  //cout<<fixed<<setprecision(10);
  ll n,h,ans=0;
  cin>>h>>n;
  vector<ll>v(n,0);
  ll sum=0;
  for(ll i=0;i<n;i++){
    cin>>v[i];
    sum+=v[i];
  }
  if(sum>=h)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 1024
class CellularPhone
{
	//tips C#???????????????????????????????????????????????????
	class Button {
		protected string m_code;
		public Button(){m_code = " ";}
		
		public char push(int i) { //i = ??????????????£?¶????????????????????????°
			int input = (i - 1) % m_code.Length;
			return m_code[input];
		}
	}
	class Button_1 : Button{ public Button_1() {m_code = ".,!? ";}};
	class Button_2 : Button{ public Button_2() {m_code = "abc"  ;}};
	class Button_3 : Button{ public Button_3() {m_code = "def"  ;}};
	class Button_4 : Button{ public Button_4() {m_code = "ghi"  ;}};
	class Button_5 : Button{ public Button_5() {m_code = "jkl"  ;}};
	class Button_6 : Button{ public Button_6() {m_code = "mno"  ;}};
	class Button_7 : Button{ public Button_7() {m_code = "pqrs" ;}};
	class Button_8 : Button{ public Button_8() {m_code = "tuv"  ;}};
	class Button_9 : Button{ public Button_9() {m_code = "wxyz" ;}};
	
	private Button[] m_button;
	
	private int m_inputNum;
	private int m_inputCount;
	private string m_translatedStr;
	
	private void flushInputStr()
	{
		if (0 != m_inputCount) m_translatedStr += m_button[m_inputNum].push(m_inputCount);
		m_inputCount = 0;
	}
	
	public CellularPhone() {
		m_inputNum = 0;
		m_inputCount = 0;
		m_translatedStr = "";

		m_button = new Button[10];
		m_button[0] = new Button();   m_button[1] = new Button_1(); 
		m_button[2] = new Button_2(); m_button[3] = new Button_3();
		m_button[4] = new Button_4(); m_button[5] = new Button_5();
		m_button[6] = new Button_6(); m_button[7] = new Button_7();
		m_button[8] = new Button_8(); m_button[9] = new Button_9();
	}
	public void put(int i) {
		if ((i == 0) || (m_inputNum != i)) {// 0??????????????\?????¨??°??????????????\???????????????
			flushInputStr();
		}
		if (i != 0) {
			m_inputNum = i;
			++m_inputCount;
		}
	}
	
	public string echoStr() 
	{
		System.Console.WriteLine(m_translatedStr);
		return m_translatedStr;
	}
	public void clearStr() { m_translatedStr = "";}
};

class KeitaiMessage
{
	public static void Main()
	{
		CellularPhone myPhone = new CellularPhone();
		int inputCount = int.Parse(System.Console.ReadLine());
		
		for (int i = 0; i < inputCount; ++i) {
			string inputStr = System.Console.ReadLine();
			for (int index = 0; index < inputStr.Length; ++index) {
				myPhone.put(inputStr[index] - '0'); // ??°????????????
			}
			myPhone.echoStr();
			myPhone.clearStr();
		}
	}
};

	
	

Measured memory_bytes: 8972
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI acos(-1.0)
#define test() int t; cin>>t; while(t--)
#define ll long long int

int main()
{
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	//test() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll ans = 0;
	for (int i = 1; i < n; i++) {
		if (a[i] < a[i - 1]) {
			ans += a[i - 1] - a[i];
			a[i] = a[i - 1];
		}
	}
	cout << ans << endl;
	//}
	return 0;
}


Measured memory_bytes: 3996
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int A, B, C; cin >> A >> B >> C;
  int v = max({A, B, C});
  int count = 3 * v - (A + B + C);
  if (count % 2 == 0) cout << count/2 << endl;
  else                cout << (count/2) + 2 << endl;
}


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

using lint = long long;
const int inf = 1001001001;

lint Combination(lint n, lint k) {
    lint res = 1;
    for (lint i = 1; i <= k; ++i) {
        res *= n--;
        res /= i;
    }
    return res;
}

int main() {
  int n, a, b;
  cin >> n >> a >> b;

  vector<lint> v(n);
  for (auto &u : v) cin >> u;

  sort(v.rbegin(), v.rend());

  double ave = 0;
  for (int i = 0; i < a; ++i) {
    ave += v[i];
  }
  ave /= a;

  int u = -1;
  while (v[u] != v[a - 1]) u++;
  int d = u;
  while (v[d] == v[a - 1]) d++;
  d -= u;

  int l = a - u, r = (u != 0 ? a : b) - u;
  lint ans = 0;
  for (int i = l; i <= r; ++i) {
    ans += Combination(d, i);
  }

  cout.precision(8);
  cout << fixed << ave << endl;
  cout << ans << endl;
}


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


Measured memory_bytes: 1700
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;


int main() {
    int i, j, num, start, end, c;
    double a, b, rad, x[100], y[100], ab[100], mean, dev, d_1=0.0, d_2=0.0, d_3=0.0, d_inf=0.0;

    cin >> num;
    for(i=0;i<num;i++){
        cin >> x[i];
    }
    for(i=0;i<num;i++){
        cin >> y[i];
    }
    for(i=0;i<num;i++){
        ab[i] = abs(x[i] - y[i]);
    }
    for(i=0;i<num;i++){
        d_1 = d_1 + ab[i];
        d_2 = d_2 + ab[i]*ab[i];
        d_3 = d_3 + ab[i]*ab[i]*ab[i];
        if(d_inf < ab[i]){
            d_inf = ab[i];
        }
    }

    cout << fixed <<setprecision(10) << d_1 << endl;
    cout << fixed <<setprecision(10) << sqrt(d_2) << endl;
    cout << fixed <<setprecision(10) << pow(d_3, 1.0/3.0) << endl;
    cout << fixed <<setprecision(10) << d_inf << endl;
    return 0;
}



Measured memory_bytes: 3468
#include <bits/stdc++.h>
#include <string.h>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15

int main(){

 int r,c,n;

 cin>>r>>c>>n;

 int maxi,mini;
 if(r>c){ maxi = r; mini = c;}
 else if(c>r) {maxi = c; mini = r;}

 int cnt=0,ans=0;

 while(cnt<n){
   cnt += maxi;
   ans++;
 }

  cout<<ans<<endl;

return 0;
 }


Measured memory_bytes: 3596
#include <stdio.h>

int main()
{
  double a, b, c, d, e, f;
  double x, y;

  while(scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) != EOF){
    x = (e*c-b*f) / (e*a-b*d);
    y = (c*d-a*f) / (b*d-e*a);

    if(x == -0.0) x = 0;
    if(y == -0.0) y = 0;

    printf("%.3f %.3f\n",x,y);
  }

  return 0;
}

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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#ifdef LOCAL
#define dmp(x) cerr << __LINE__ << " " << #x << " " << x << endl
#else
#define dmp(x) void(0)
#endif

template <class t, class u>
void chmax(t &a, u b)
{
  if (a < b)
    a = b;
}
template <class t, class u>
void chmin(t &a, u b)
{
  if (b < a)
    a = b;
}
const int mod = 1000000007;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};
struct combination
{
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1)
  {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i)
      fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i)
      ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k)
  {
    if (k < 0 || k > n)
      return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

template <class t>
using vc = vector<t>;
template <class t>
using vvc = vc<vc<t>>;

using vi = vc<int>;
int gcd(int a, int b)
{
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int lcm(int a, int b)
{
  return (a * b) / gcd(a, b);
}
int fact(int n)
{
  if (n == 0)
    return 1;
  return n * fact(n - 1);
}

int main()
{
  char a, b;
  cin >> a >> b;
  if(a=='H'){
  if(b=='H'){
  	cout << 'H' <<endl;
  }else{
  	cout <<'D'<<endl;
  }
  }else{
  	if(b=='H'){
    	cout <<'D'<<endl;
    }else{
    cout <<'H'<<endl;
    }
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=1000000007;

ll N,M;

int main(){
    cin>>N>>M;

    ll ans=0;
    if(N==1 || M==1){
        if(N==1 && M==1) ans=1;
        else ans=max(N,M)-2;
    }else{
        ans=(N-2)*(M-2);
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3608
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
#include<queue>
#include<utility>
#include<tuple>
#include<set>
using namespace std;

int main(void)
{
	int X, Y, Z, K;
	cin >> X >> Y >> Z >> K;

	vector<long long> A(X), B(Y), C(Z);
	for (int i = 0; i < X; i++)
		cin >> A[i];
	for (int i = 0; i < Y; i++)
		cin >> B[i];
	for (int i = 0; i < Z; i++)
		cin >> C[i];

	const long long minf = -1E9;
	A.push_back(minf);
	B.push_back(minf);
	C.push_back(minf);

	sort(A.rbegin(), A.rend());
	sort(B.rbegin(), B.rend());
	sort(C.rbegin(), C.rend());

	set<int> dic;
	priority_queue < pair<long long, tuple<int, int, int>>> task;
	dic.insert(0);
	task.push(make_pair(A[0] + B[0] + C[0], make_tuple(0, 0, 0)));

	vector<long long> abc;
	while (abc.size() < K) {
		auto p = task.top();
		task.pop();

		abc.push_back(p.first);

		for (int j = 0; j < 3; j++) {
			int a, b, c;
			tie(a, b, c) = p.second;

			if (j == 0)
				a++;
			else if (j == 1)
				b++;
			else
				c++;

			int hash = (a << 20) + (b << 10) + c;
			if (dic.count(hash) == 1)
				continue;

			dic.insert(hash);
			task.push(make_pair(A[a] + B[b] + C[c], make_tuple(a, b, c)));
		}
	}
	
	sort(abc.rbegin(), abc.rend());

	for (int i = 0; i < K; i++) {
		cout << abc[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 896
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <string.h>
#include <vector>
#include <unordered_map>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i > 0; i--)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

typedef int64_t int64;
typedef int64_t ll;

const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };

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

using namespace std;


class D {
	int n, m;
	const int MOD{ 1000000007 };
	vector<int> primes;
	vector<pair<int, int>> result;

public:
	D()
	{
		cin >> n >> m;
	}

	ll modinv(ll a, ll b) {
		if (!b)
			return 1;

		if (b & 1)
			return a * modinv(a, b - 1) % MOD;
		else
		{
			ll half = modinv(a, b / 2);
			return half * half % MOD;
		}
		
	}

	ll comb(int a, int b)
	{
		if (b > a - b)
			return comb(a, a - b);

		ll denominator{ 1 };
		ll numerator{ 1 };

		REP(i, b)
		{
			denominator *= (b - i);
			denominator %= MOD;
			numerator *= (a - i);
			numerator %= MOD;
		}

		return numerator * modinv(denominator, MOD - 2) % MOD;
	}

	void solve()
	{

		int tmp{ m };
		ll ans{ 1 };

		int div{ 2 };
		int cnt{ 0 };

		while (!(tmp & 1))
		{
			cnt++;
			tmp >>= 1;
		}
		if (cnt)
			ans = comb(n + cnt - 1, cnt) % MOD;

		for (div = 3; div <= tmp; div += 2)
		{
			cnt = 0;

			while (!(tmp % div))
			{
				cnt++;
				tmp /= div;
			}

			if (cnt)
			{
				ans *= comb(n + cnt - 1, cnt);
				ans %= MOD;
			}
		}

		cout << ans << endl;

	}
};


int main()
{
	D solution;
	solution.solve();

	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

vector<int> Zalgorithm(string S) {
    vector<int> A(S.size());
    A[0] = S.size();
    int i = 1, j = 0;
    while (i < S.size()) {
        while (i+j < S.size() && S[j] == S[i+j]) ++j;
        A[i] = j;
        if (j == 0) { ++i; continue;}
        int k = 1;
        while (i+k < S.size() && k+A[k] < j) A[i+k] = A[k], ++k;
        i += k; j -= k;
    }
    return A;
}

int main() {
    int N, ans = 0;
    string S;
    cin >> N >> S;
    rep(i, N - 1) {
        auto A = Zalgorithm(S.substr(i, N - i));
        for (int j = 1; j < N - i; j++) {
            ans= max(ans, min(A[j], j));
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 typedef long long ll;
 
int main() {
int n,t;
cin>>n>>t;
int m[333333];
for(int i=0;i<n;i++)cin>>m[i];
int ans=0;
for(int i=0;i<n-1;i++){
if(m[i+1]-m[i]<t)ans+=m[i+1]-m[i];
else ans+=t;
}
ans+=t;
cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<iostream>
int A,B;
int main(void)
{
using namespace std;
int n,C,D;
while(1)
{
cin>>n;
if(!n)break;
A=0;
B=0;
for(;n>0;n--){
cin>>C;
cin>>D;
if(C>D){
A+=(C+D);
}else if(C<D){
B+=(C+D);
}else{
A+=C;
B+=D;
}
}
cout<<A<<" "<<B<<endl;
}
return 0;
}

Measured memory_bytes: 1160
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
	string a;
	cin >> a;
	if (a == "A") cout << "T" << endl;
	else if (a == "T") cout << "A" << endl;
	else if (a == "C") cout << "G" << endl;
	else if (a == "G") cout << "C" <<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define range(i, a, b) for(auto i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const long double EPS = 1e-8;
using vi = vector <int>;
using vvi = vector <vi>;

signed main() {
	int n;
	cin >> n;
	string s[2];
	cin >> s[0] >> s[1];
	int ans = 1;
	rep (i, s[0].size()) {
		if (s[0][i] == s[1][i]) {
			ans = (ans * (!i ? 3 : s[0][i - 1] == s[1][i - 1] ? 2 : 1)) % MOD;
		} else {
			ans = (ans * (!i ? 6 : s[0][i - 1] == s[1][i - 1] ? 2 : 3)) % MOD;
			i++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int N ,X ,j ;
  cin >> N ;
  X = 1;
  vector<int> vec(N) ;
    for (int i=0; i<N ; i++)
     cin >> vec.at(i) ;
  sort(vec.begin(),vec.end()) ;
    while (j<N-1){
      if(!(vec.at(j) == vec.at(j+1)))
        X+=1 ;
      j+=1;
    }
    cout << X <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 100005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 1e9 + 7;
ll pre[maxn];
ll inv[maxn];
ll prei[maxn];
void build(int n){
    pre[1] = pre[0] = 1, inv[1] = inv[0] = 1, prei[1] = prei[0] = 1;
    for(int i = 2 ; i <= n ; i++){
        pre[i] = pre[i-1] * i % mod;
        inv[i] = (mod - mod / i * inv[mod % i] % mod) % mod;
        prei[i] = prei[i-1] * inv[i] % mod;
    }
}
ll C(int n, int k){
    if (k == 0) {
        return 0;
    }
   return pre[n] * prei[k] % mod * prei[n-k] % mod;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    map<int,int>mp;
    int n;
    cin >> n;
    int F,S;
    f1(n + 1) {
        int x;
        cin >> x;
        if (mp[x]) {
            F = mp[x];
            S = i;
        }
        mp[x] = i;
    }
    build(n+2);
    cout << n << endl;
    ll rem = F - 1 + n + 1 - S;
    fr(i,2,n + 2) {
        ll ans = C(n + 1, i);
        if (rem >= i - 1) {
            ans -= C(rem, i - 1);
        }
        if (ans < 0) {
            ans %= mod;
            ans += mod;
        }
        cout << ans << '\n';
    }
}


Measured memory_bytes: 8320
n = gets.strip.to_i
a = gets.strip.split.map(&:to_i).sort.reverse
b = gets.strip.split.map(&:to_i).sort
c = gets.strip.split.map(&:to_i).sort

#p a
#p b
#p c

result = 0
b.each do |current_b|
  a_count = a.length - (a.bsearch_index {|e| e < current_b} || a.length)

  c_count = c.length - (c.bsearch_index {|e| e > current_b} || c.length)

#p [current_b, a_count, c_count]
  result += a_count * c_count
end

p result



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

using namespace std;
using ll = long long;
using ull = unsigned long long;

typedef pair<int, int>pi;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
typedef pair<P, P> PPP;

const ll MOD = 1e9 + 7;
const ll INF = 5e18;
const double DINF = 5e14;
const double eps = 1e-10;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };

#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

struct RMinQ {
private:
	int n;
	vector<ll>node;
public:
	RMinQ(vector<ll>v) {
		int sz = v.size();
		n = 1;
		while (n < sz)n *= 2;
		node.resize(2 * n - 1, INF);
		for (int i = 0;i < sz;i++)node[i + n - 1] = v[i];
		for (int i = n - 2;i >= 0;i--)node[i] = min(node[2 * i + 1], node[2 * i + 2]);
	}
	ll getmin(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0)r = n;
		if (r <= a || b <= l)return INF;
		if (a <= l && r <= b)return node[k];
		ll vl = getmin(a, b, 2 * k + 1, l, (l + r)/ 2);
		ll vr = getmin(a, b, 2 * k + 2, (l + r) / 2, r);
		return min(vl, vr);
	}
};

struct RMaxQ {
private:
	int n;
	vector<ll>Node;
public:
	RMaxQ(vector<ll>v) {
		int sz = v.size();
		n = 1;
		while (n < sz)n *= 2;
		Node.resize(2 * n - 1, -1);
		for (int i = 0;i < sz;i++)Node[i + n - 1] = v[i];
		for (int i = n - 2;i >= 0;i--)Node[i] = max(Node[2 * i + 1], Node[2 * i + 2]);
	}
	ll getmax(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0)r = n;
		if (r <= a || b <= l)return -1;
		if (a <= l && r <= b)return Node[k];
		ll vl = getmax(a, b, 2 * k + 1, l, (l + r) / 2);
		ll vr = getmax(a, b, 2 * k + 2, (l + r) / 2, r);
		return max(vl, vr);
	}
};

ll N, d, x, y, s, ans;
vector<PP>v;
vector<ll>vv, xx, yy;

int main() {
	cin >> N >> d;
	for (int i = 0;i < N;i++) {
		cin >> x >> y >> s;
		v.eb(PP(s, P(x, y)));
	}
	sort(ALL(v));
	xx.resize(N), yy.resize(N), vv.resize(N);
	for (int i = 0;i < N;i++) {
		vv[i] = v[i].fr;
		xx[i] = v[i].sc.fr;
		yy[i] = v[i].sc.sc;
	}
	RMinQ xmn(xx), ymn(yy);
	RMaxQ xmx(xx), ymx(yy);
	for (int i = 0;i < N;i++) {
		int it = upper_bound(ALL(vv), vv[i] + d) - vv.begin();
		ans = max(ans, (xmx.getmax(i, it) - xmn.getmin(i, it))*(ymx.getmax(i, it) - ymn.getmin(i, it)));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 30260
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define int long long
#define se second
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t,mpp[li];
int cev;
string s;
vector<int> v;

main(void){
	scanf("%lld",&n);
	FOR{
		scanf("%lld",&a[i]);
		mpp[a[i]]++;
		cev+=a[i];
	}
	scanf("%lld",&t);
	while(t--){
		int x,y;
		scanf("%lld %lld",&x,&y);
		cev-=mpp[x]*x;
		cev+=mpp[x]*y;
		mpp[y]+=mpp[x];
		mpp[x]=0;
		printf("%lld\n",cev);
	}
	return 0;
}



Measured memory_bytes: 5344
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string n;
	
	cin >> n;
	
	for (int i = 'a'; i <= 'z'; i++) {
		if (n.find(i) == string::npos) {
			cout << (char)i << endl;
			return 0;
		}
	}

	cout << "None" << endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define pi 3.14
using namespace std;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef pair<long long,int> pli;
typedef pair<int,long long> pil;
const int INF=1000000007;
const int MOD=1000000007;
const int nmax=101234;

int n,tot,res[nmax];
pii G[nmax];
vector<pii> v2[nmax];

void dfs(int s,int f,int c){
    tot=max(tot,(int)v2[s].size());
    for(int flg=1,i=0;i<v2[s].size();++i){
        int u=v2[s][i].first;
        int pos=v2[s][i].second;
        if(u!=f){
            if(flg==c)++flg;
            res[pos]=flg;
            dfs(u,s,flg);
            ++flg;
        }
    }
}

int main()
{
    scanf("%d",&n);
    for(int u,v,i=1;i<n;++i){
        scanf("%d%d",&u,&v);
        G[i]={u,v};
        v2[u].pb({v,i});
        v2[v].pb({u,i});
    }
    dfs(1,0,0);
    printf("%d\n",tot);
    for(int i=1;i<n;++i)
        printf("%d\n",res[i]);
    return 0;
}


Measured memory_bytes: 9856
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

k,n = inpl()
a = inpl()
b = []
for i in range(1,n):
    b.append(abs(a[i] - a[i-1]))
b.append(k-a[-1] + a[0])
b.sort()
print(sum(b) - b[-1])


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int k;
	ll a, b;
	cin>>k>>a>>b;
	if(b-a<=1 || k<a-1){
		cout<<k+1<<'\n';
		return 0;
	}
	ll ans=0;
	if(a&1){
		if(k&1){
			ans=a+(b-a)*(k-1-(a-1))/2+1;
		}
		else{
			ans=a+(b-a)*(k-(a-1))/2;
		}
	}
	else{
		if(k&1){
			ans=a+(b-a)*(k-(a-1))/2;
		}
		else{
			ans=a+(b-a)*(k-1-(a-1))/2+1;
		}
	}
	cout<<ans<<'\n';
	return 0;
}


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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL MOD = 1e9+7;

int main() {
    int L, R, d;
    cin >> L >> R >> d;
    int x = 0;
    FOR(i, L, R + 1) {
        x += i%d == 0 ? 1 : 0;
    }
    cout << x << endl;
    return 0;
}


Measured memory_bytes: 3628
import java.util.Scanner;

public class Main { 
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int[][] c = new int[3][3];
    int max =0;
    for (int i =0; i<3; i++) {
      for (int j =0; j<3; j++) {
        c[i][j] = sc.nextInt();
        max = Math.max(c[i][j],max);
      }
    }
    for (int i =0; i<=max; i++) {
      for (int j =0; j<=max; j++) {
        for (int k =0; k<=max; k++) {
          if (c[1][0] - c[0][0] == j - i && c[1][0] - c[2][0] == j - k) {
            if (c[1][1] - c[0][1] == j - i && c[1][1] - c[2][1] == j - k) {
              if (c[1][2] - c[0][2] == j - i && c[1][2] - c[2][2] == j - k) {
                System.out.println("Yes");
                return;
              }
            }
          }
        }
      }
    }     
    System.out.println("No");  
  }
}    

Measured memory_bytes: 22100
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
typedef long long ll;

int main(){
    string s;
    cin >> s;
    s[3]='8';
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

int main(void){
    int N;
    std::cin >> N;
    std::string str;
    std::cin >> str;
    if((N & 1) == 0){
        int half_length = N/2;
        for(int i = 0; i < half_length; ++i){
            if(str[i] != str[i+half_length]){
                std::cout << "No";
                return 0;
            }
        }
        std::cout << "Yes";
        return 0;
    }
    std::cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef		 long long int     ll;
typedef		vector<ll>      vll;
#define     fi              first
#define     se              second
#define		pb              push_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		ss              ' '
#define     pii             pair<ll,ll>
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
const double eps = 1e-8;




int main()
{
//    ios::sync_with_stdio(0);
//    cin.tie(0)
   ll ar[6];
   ll ans;
   for(ll i=1;i<=5;i++)
   {
       cin>>ar[i];
       if(ar[i]==0) ans=i;
   }
   cout<<ans<<nn;



}


/* Final check before submit :

1. array size or integer overflow.

2. Think twice,code once.check all possible counter test case.

3. Be careful about corner case! n=1?k=1? something about 0?

4. avoid stupid mistake!complexity(t/m)?precision error?submit same code twice?

5. if got WA than remember that you are missing something common.
   *** Be confident!!! who knows? may be your one step back to AC ***

*/



Measured memory_bytes: 3608
#include <cstdio>
#include <iostream>

using namespace std;

int all,ans;

void m(int d){
    ans += all / d;
    all = all % d;
}

int solve(int a){
    all = 1000 - a;
    ans = 0;
    m(500);
    m(100);
    m(50);
    m(10);
    m(5);
    m(1);
    return ans;
}

int main(){
    int a;
    while(true){
        cin >> a;
        if(!a){break;}
        cout << solve(a) << endl;
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> > 
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;
int main()
{
	boost;
	string s;
	cin >> s;
	int sum = 0;
	for(char c : s)
	sum = (sum + (c - '0')) % 9;
	cout << (sum == 0 ? "Yes" : "No");
}

Measured memory_bytes: 3712