akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

#整数値龍力　複数の入力
def input_multiple_number():
    return map(int, input().split())

S = input()
a = [0]


sumS = 0
i = 0
base = 0
while i < len(S):
	j = 0
	
	while (i+j) < len(S) and S[i+j] != "<":
		j += 1
	if base > j:
		sumS += (base*1-j)

	sumS += sum(range(j+1))
	base = 0
	

	i += j

	j = 0
	while (i+j) < len(S) and S[i+j] != ">":
		j += 1

	sumS += sum(range(base,base+j))
	base += j

	i += j

sumS += base


print(sumS)



Measured memory_bytes: 4212
K = int(input())

data=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(data[K-1])

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, w;
  cin >> n >> w;
  int wi[n];
  int vi[n];
  int ac = 0;
  for(int i = 0; i<n;i++){
    cin >> wi[i] >> vi[i];
    ac+= vi[i];
  }
  long long dp[2][ac+1];
  for(int j = 0; j<=ac;j++){
    dp[0][j] = 1000000000000;
  }
  dp[0][0]  = 0;
  bool f = 1;
  for(int i = 1; i<=n;i++){
    for(int j = 0; j<=ac;j++){
      if(j>=vi[i-1]){
	dp[f][j] = min(dp[!f][j],dp[!f][j-vi[i-1]]+wi[i-1]);
      }else{
	dp[f][j] = dp[!f][j];
      }
    }
    f = !f;
  }
  int ans = 0;
  for(int i = 0; i<=ac;i++){
    if(dp[!f][i]<=w){
      ans = max(ans,i);
    }
  }
  cout << ans <<'\n';
  return 0;
}


Measured memory_bytes: 5192
def main():
    n, d = map(int, input().split())
    xs = [[int(a) for a in input().split()] for _ in range(n)]

    cnt = 0
    for i, x in enumerate(xs):
        for j, y in enumerate(xs):
            if i >= j:
                continue
            d = sum([(xi - yi)**2 for xi, yi in zip(x, y)])
            d2 = int(d ** 0.5) - 1
            if d2 ** 2 == d or (d2 + 1) ** 2 == d or (d2 + 2) ** 2 == d:
                cnt += 1
    print(cnt)


main()


Measured memory_bytes: 3188
import sys
r={'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000}
for e in sys.stdin:
 n=[r[c]for c in e[:-1]]
 print(sum(n[i]*[1,-1][i+1<len(n)and n[i]<n[i+1]]for i in range(len(n))))


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

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

int a[100005];
int b[100005];
int c[100005];

int main(void){
    int n;
    int i;
    unsigned long long answer = 0;
    int ai, ci;
    
    scanf("%d", &n);
    for (i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    for (i = 0; i < n; i++){
        scanf("%d", &b[i]);
    }
    for (i = 0; i < n; i++){
        scanf("%d", &c[i]);
    }

    qsort(a, n, sizeof(int), ascending_compare);
    qsort(b, n, sizeof(int), ascending_compare);
    qsort(c, n, sizeof(int), ascending_compare);

    
    for (i = 0; i < n; i++){
        ai = lower_bound(a, n, b[i]);
        ci = lower_bound(c, n, b[i]+1);
            answer += (unsigned long long)(ai)*(n-ci);
        }

    printf("%lld\n", answer);
    return 0;
}


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

int main(void) {
	int W, H, x, y;
	cin >> W >> H >> x >> y;

	double a = (double)W * H / 2.0;
	int t = 0;
	if ((2 * x == W) && (2 * y == H))
		t = 1;

	cout << fixed << setprecision(12) << a << ' ' << t << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>
#include <iomanip>
#include <functional>
#include <array>
#include <memory>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#undef NDEBUG
#include <assert.h>

using namespace std;
typedef long long ll;

int gcd(int a, int b) {
	return b ? gcd(b, a%b) : a;
}

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

	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	cout << (k <= *max_element(a.begin(), a.end()) &&
		k % accumulate(a.begin(), a.end(), 0, [](const int acc, const int x) {
		return gcd(acc, x);
		}) == 0 ? "POSSIBLE" : "IMPOSSIBLE") << endl;
	return 0;
}

Measured memory_bytes: 640
package main

import (
	"fmt"
	"math"
)

func gcd(a, b int) int {
	for a%b != 0 {
		a, b = b, a%b
	}
	return b
}

func main() {
	var n, x, r, t int
	fmt.Scan(&n, &x)

	for i := 0; i < n; i++ {
		fmt.Scan(&t)
		t = int(math.Abs(float64(t - x)))
		if i == 0 {
			r = t
			continue
		}
		if g := gcd(t, r); r > g {
			r = g
		}
	}

	fmt.Println(r)
}

Measured memory_bytes: 5504
#include<cstdio>
#include<string>
#include<cstring>
#include<utility>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<vector>
#include<iostream>
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
using namespace std;
int main()
{
	int i,j,k,n,m=0,x,y=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&x);
		y=max(y,x);
		m+=x;
	}
	m-=y/2;
	printf("%d",m);
	return 0;
}

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

const int MAXN = 1e6 + 5;
const int MOD = 1e9 + 7;

int n, a[MAXN], cnt[MAXN], gcdd;
vector<int> v[MAXN];

template <class T>
void read(T& x, T f = 1, char ch = getchar()) {
    x = 0;
    while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar();
    while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar();
    x *= f;
}

bool isprime(int x) {
    for (int i = 2; i <= sqrt(x); i++)
        if (x % i == 0) return false;
    return true;
}

void init() {
    for (int i = 2; i <= 1000000; i++) {
        if (isprime(i)) {
            for (int k = 1; k * i <= 1000000; k++) v[k * i].push_back(i);
        }
    }
}

int main() {
    init();
    read(n);
    for (int i = 1; i <= n; i++) read(a[i]);
    gcdd = a[1];
    for (int i = 2; i <= n; i++) gcdd = __gcd(a[i], gcdd);
    bool tag = 1;
    for (int i = n; i >= 1; i--) {
        for (int j = 0; j < v[a[i]].size(); j++)
            if (cnt[v[a[i]][j]]) {
                tag = 0;
                break;
            }
        for (int j = 0; j < v[a[i]].size(); j++) cnt[v[a[i]][j]]++;
    }
    if (tag)
        cout << "pairwise coprime";
    else {
        if (gcdd == 1)
            cout << "setwise coprime";
        else
            cout << "not coprime";
    }
    return 0;
}


Measured memory_bytes: 66684
k=int(input())
 
def gcd(l,m,n):
  f=min(l,m,n)
  while l%f!=0 or m%f!=0 or n%f!=0:
    f=f-1
  return f
 
sum=0
for l in range(1,k+1):
  for m in range(l,k+1):
    for n in range(m,k+1):
      if l==m==n:
        sum=sum+gcd(l,m,n)
      elif l==m or m==n:
        sum=sum+gcd(l,m,n)*3
      else:
        sum=sum+gcd(l,m,n)*6
 
print(sum)

Measured memory_bytes: 68556
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
  int H,W;
  cin >> H >> W;

  int A[H][W];

  for (int i=0; i<H; ++i) {
    for (int j=0; j<W; ++j) {
      cin >> A[i][j];
    }
  }

  /*
  1行目から順に次の操作をする．
  1列目から順に要素をみて，奇数ならば真下(真下に行がある場合)，または一つ右（ない場合）にコインを移動する．
  A[i][j]における操作の結果はA[i][j]--;, A[i+1][j]++;である．（真下に移動する場合）
  ただし，操作後の行列は回答に求められないので，A[i][j]--;の操作は省略している．
  右下の要素（すなわちA[H][W]）についてはそれ以上移動できないので，何もしない．
  最終的には右下の要素を除く全ての要素について，それが偶数であることが保証される．

  実際に操作した回数と，操作時の移動下と移動先を記録すればよい．
  */
  vector< vector<int> > ops(H*W);
  int N = 0;
  for (int i=0; i<H; ++i) {
    for (int j=0; j<W; ++j) {
      if (A[i][j] % 2 == 0) continue;
      else {
        if (i<H-1) {
          A[i+1][j]++;
          ops[N] = {i, j, i+1, j};
          N++;
        } else {
          if (j < W-1) {
            A[i][j+1]++;
            ops[N] = {i, j, i, j+1};
            N++;
          } else {
            continue;
            }
          }
        }
      }
    }

  cout << N << endl;
  for (int i=0; i<N; ++i) {
    for (int j=0; j<4; ++j) {
      cout << ops[i][j] + 1;
      if (j<3) cout << " ";
    }
    cout << endl;
  }
  return(0);
}


Measured memory_bytes: 13312
#include <bits/stdc++.h>
using namespace std;
int main(){
 double a;
 string b;
 double total = 0;
 int N;
 cin >> N;
  for(int i=0;i<N;i++){
    cin >> a >> b;
    if(b == "JPY") total+=a;
    else total+=380000*a;
  }
  cout << total << endl;
}    

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

const long long int INF=99999999999999,inf=199999;
const long long int mod=1000000007;



long long int n,m,k,a[200005],b,c,d,count=0,res=0,tmp;
int main() {
    int count=0;
    string str;
    map<long long int,long long int>mp;
	cout << fixed << setprecision(10);
    cin>>n>>m;
    if(abs(n-m)%2==0){
        cout<<abs(n-m)/2+min(n,m)<<endl;
    }else{
        cout<<"IMPOSSIBLE"<<endl;
    }
    
} 


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

int a, b, c, d;

int main() {
	ios::sync_with_stdio(0);
	cin >> a >> b >> c >> d;

	while(1) {
		c -= b;
		if(c <= 0) {
			cout << "Yes" << endl;
			return 0;
		}

		a -= d;
		if(a <= 0) {
			cout << "No" << endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 3612
import java.util.*;

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

        int N = sc.nextInt();
        int[] B = new int[N-1];
        int[] A = new int[N];
        int ans = 0;

        for(int i=0; i<N-1; i++){
            B[i] = sc.nextInt();
        }
        A[0] = B[0];
        for(int i=1; i<N-1; i++){
            if(B[i]<=B[i-1]){
                A[i] = B[i];
            }
            else if(B[i]>B[i-1]){
                A[i] = B[i-1];
            }
        }
        A[N-1] = B[N-2];
        for(int i=0; i<N; i++){
            ans += A[i];
        }
        System.out.println(ans);
    }
}

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

#define int long long
#define endl "\n"

signed main ()
{

//#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int k;
	cin >> k;
	
	if (k%2 == 0 or k%5 == 0){
		cout << -1 << endl;
		return 0;
	}
	int length = 1;
	int remainder = 7%k;
	int temp = 1;
	
	while (remainder != 0){
		temp = (temp*10)%k;
		length++;
		remainder = (remainder + (7*temp)%k)%k;
	}
	
	cout << length << endl;
		
	return 0;

}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;
string s,t;

int main(){
	cin>>n>>s>>t;
	s='#'+s;t='#'+t;
	vi a,b;
	a.push_back(n+1);
	b.push_back(n+1);
	queue<char> q;
	for(int i=n;i>0;i--){
		if(t[i]!=t[i-1]){
			q.push(t[i]);
			b.push_back(i);
		}
		if(q.size()&&q.front()==s[i]){
			q.pop();
			a.push_back(i);
		}
	}
	if(!q.empty()){
		cout<<-1<<endl;
		return 0;
	}
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	int N=a.size(),I=0,res=0,M=0;
	string s_=s;
	for(int i=1;i<=n;i++){
		if(I<N&&a[I]==i) I++;
		else s_[i]=s_[i-1];
	}
	if(s!=s_) s=s_,res++;
	for(int i=1;i<N-1;i++){
		int l=-1,r=N-i-1;
		while(r-l>1){
			int m=(l+r)/2;
			if(b[i]<=a[i+m]-m) r=m;
			else l=m;
		}
		M=max(M,r);
	}
	cout<<res+M<<endl;
}

Measured memory_bytes: 13780
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a + 3);
    cout << a[2] - a[0] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
int64_t MOD=1000000007;

int main() {
  int N;
  cin>>N;
  vector<int64_t> A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
    A.at(i)-=(i+1);
  }
  sort(A.begin(),A.end());
  int64_t k=A.at(N/2);
  int64_t ans=0;
  for(int i=0;i<N;i++){
    ans+=abs(k-A.at(i));
  }
  cout<<ans;
}


Measured memory_bytes: 1792
fun main() {
    val (n, m, x) = next3Int()
    val dummy = intArrayOf(0)
    val books = Array(n) { dummy }
    repeat(n) { i ->
        books[i] = nextIntArray(m + 1)
    }
    var min = -1
    for (buy in 1..0b111111111111) {
        val r = IntArray(m)
        var p = 0
        for (i in 0 until n) {
            if ((buy shr i) % 2 != 0) {
                p += books[i][0]
                for (j in 0 until m) {
                    r[j] += books[i][j + 1]
                }
            }
        }
        if (r.all { it >= x }) {
            if (min < 0) {
                min = p
            } else {
                min = kotlin.math.min(min, p)
            }
        }
    }
    println(min)
}

val sc = java.util.Scanner(System.`in`)
fun next(): String = sc.next()
fun nextInt() = sc.nextInt()
fun next2Int() = Pair(nextInt(), nextInt())
fun next3Int() = Triple(nextInt(), nextInt(), nextInt())
fun nextIntArray(size: Int) = IntArray(size) { nextInt() }
fun nextLong() = sc.nextLong()
fun nextLine(): String = sc.nextLine()
fun nextList() = nextLine().split(" ")
fun printYesNo(isYes: Boolean) = println(if (isYes) "Yes" else "No")
fun printString(action: StringBuilder.() -> Unit) = println(buildString(action))

Measured memory_bytes: 38328
import heapq

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

for i in range(N):
    A[i] *= -1
heapq.heapify(A)


for i in range(M):
    b = heapq.heappop(A) * (-1)
    heapq.heappush(A, (b // 2) * (-1))
    

print(sum(A) * -1)

Measured memory_bytes: 14180
N=int(input())
schedule=[list(map(int,input().split())) for _ in range(N)]
#print(schedule)
flag=1
point=[0,0,0]   #[time,x,y]
cur=[0,0,0]
for i in range(N):
    #print(point,schedule[i])
    needtime=schedule[i][0]-point[0]
    basetime=abs(point[1]-schedule[i][1])+abs(point[2]-schedule[i][2])
    if (needtime>=basetime)and(needtime%2==basetime%2):
        point=schedule[i]
    else:
        flag=0
        break
if flag==1:
    print("Yes")
else:
    print("No")

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

typedef long long ll;

const int maxn = 1e5 + 1e2;
int bipart[maxn];
int color[maxn];
std::vector<int> adj[maxn];

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

	int v, e;
	std::cin >> v >> e;

	for(int i = 0; i < e; i++){
		int f, s;
		std::cin >> f >> s;
		f--, s--;

		adj[f].push_back(s);
		adj[s].push_back(f);
	}

	memset(bipart, -1, sizeof(bipart));
	memset(color, -1, sizeof(color));

	ll single = 0;
	ll nonbipartite = 0;
	ll bipartite = 0;

	for(int i = 0; i < v; i++){
		if(bipart[i] == -1){
			std::queue<int> q;

			bipart[i] = 1;
			int size = 0;
			q.push(i);
			color[i] = 0;

			while(!q.empty()){
				int fr = q.front();
				size++;
				q.pop();

				for(int next : adj[fr]){
					if(color[next] == -1){
						bipart[next] = 0;
						color[next] = !color[fr];
						q.push(next);
					} else if(color[next] == color[fr]){
						bipart[i] = 0;
					}
				}
			}

			if(size == 1){
				single++;
			} else if(bipart[i]){
				bipartite++;
			} else {
				nonbipartite++;
			}
		}
	}

	ll sum = 0;
	sum += (ll) 2 * v * single;
	sum -= single * single;

	sum += 2 * bipartite * bipartite;
	sum += 2 * bipartite * nonbipartite;
	sum += nonbipartite * nonbipartite;

	std::cout << sum << '\n';
}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N; i++)
#define INF 1 << 28
typedef pair<int,int> Pi;
#define F first
#define S second
#define pb push_back

inline void chmax(int &a, int b) { a = max(a,b); }
inline void chmin(int &a, int b) { a = min(a,b); }

int main()
{
  int N, M;
  while(cin >> N, N) {
    string s;
    cin >> M >> s;
    int cnt = -1, sum = 0;
    char save = 'N';
    Rep(i,s.size()) {
      if(save != s[i] && ~cnt) {
	cnt++;
      } else {
	sum += max(0,((cnt - 1) / 2) - (N - 1));
	cnt = -1;
      }
      save = s[i];
      if(s[i] == 'I') {
	chmax(cnt,1);
      }
    }
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 3752
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<string.h>
#include<set>
#include<functional>
using namespace std;

#define INF 1<<21
#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
	int dx, dy;
	int x = 0, y = 0;
	int dis = 0;
	int ansx, ansy;
	while (1) {
	  cin >> dx >> dy;
	  if (dx == 0 && dy == 0)break;
	  x += dx; y += dy;
	  if (dis == x*x + y*y && x > ansx) {
		ansx = x;
		ansy = y;
	  }
	  else if (dis < x*x + y*y) {
		dis = x*x + y*y;
		ansx = x;
		ansy = y;
	  }
	}
	cout << ansx << " " << ansy << endl;
  }
  return 0;
}

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

int main(){
  char b;
  cin >> b;
  if(b == 'A'){
    cout << 'T'<<endl;
  }
  else if (b == 'T') {
    cout << 'A' << endl;
  }
  else if (b == 'C') {
    cout << 'G' << endl;
  }
  else {
  cout << 'C' << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  int left,right;
  cin >> A >> B >> C >> D;
  left = A+B;
  right = C+D;
  if(left>right) cout << "Left" << endl;
  else if(left==right) cout << "Balanced" << endl;
  else cout << "Right" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	char egg;
	char cha;
	char negi;
	scanf("%c", &egg);
	scanf("%c", &cha);
	scanf("%c", &negi);

	int i = 0;
	if(egg == 'o'){
		i++;
	}
	if(cha == 'o'){
		i++;
	}
	if(negi == 'o'){
		i++;
	}
	
	switch(i){
		case 0:
			printf("%d\n", 700);
			break;
		case 1:
			printf("%d\n", 800);
			break;
		case 2:
			printf("%d\n", 900);
			break;
		case 3:
			printf("%d\n", 1000);
			break;
	}
}

Measured memory_bytes: 128
hon_list = [2, 4, 5, 7, 9]
pon_list = [0, 1, 6, 8]
bon_list = [3]
N = int(input())
r = N % 10
if r in hon_list:
    print("hon")
if r in pon_list:
    print("pon")
if r in bon_list:
    print("bon")

Measured memory_bytes: 9204
o = input()
e = input()

olen = len(o)
elen = len(e)

res = ""

if olen == elen:
    for i in range(olen):
        res += o[i]
        res += e[i]
    print(res)

else:
    for i in range(elen):
        res += o[i]
        res += e[i]
    res += o[elen]
    print(res)

Measured memory_bytes: 3060
#include <iostream>
#include <queue>
#include <vector>

const int Max = 100;
int map[Max + 1][Max + 1];

typedef struct{
	bool startflag;
	int distance;
}State;

int main()
{
	int n, k, l, temp;
	std::queue<int> q;
	std::vector<State> state;

	for (int i = 1; i < Max + 1; i++){
		for (int j = 1; j < Max + 1; j++){
			map[i][j] = 0;
		}
	}

	std::cin >> n;
	for (int i = 1; i <= n; i++){
		std::cin >> k >> l;
		for (int j = 1; j <= l; j++){
			std::cin >> temp;
			map[k][temp] = 1;
		}
	}

	State s = { false, 0 };
	for (int i = 0; i <= n; i++){
		state.push_back(s);
	}

	int d = 0;
	while (1){
		if (q.empty() == true){
			bool f = false;
			for (int i = 1; i <= n; i++){
				if (state[i].startflag == false){
					if (i != 1){
						state[i].startflag = true;
						state[i].distance = -1;
						continue;
					}
					q.push(i);
					state[i].startflag = true;
					d = 0;
					state[i].distance = d;
					d++;
					f = true;
					break;
				}
			}
			if (f == false){
				break;
			}
		}
		int size = q.size();
		for (int j = 0; j < size; j++){
			for (int i = 1; i <= n; i++){
				if (map[q.front()][i] == 1 && state[i].startflag == false){
					q.push(i);
					state[i].startflag = true;
					state[i].distance = d;
				}
			}
			q.pop();
		}
		d++;
	}

	for (int i = 1; i <= n; i++){
		std::cout << i << " " << state[i].distance << std::endl;
	}

	return 0;
}

Measured memory_bytes: 3212
H, W = map(int, input().split())
S = []
for h in range(H):
    S.append(list(input().strip()))


for h in range(H):
    for w in range(W):
        x, y = w, h
        if S[y][x] == ".":
            c = 0
            for i in range(max(x-1, 0), min(x+2, W)):
                for j in range(max(y-1, 0), min(y+2, H)):
                    if S[j][i] == "#":
                        c += 1
            S[y][x] = str(c)

for h in range(H):
    print("".join(S[h]))


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef vector<pll> vll;
typedef vector<vl> vvl;

#define fori(i, n) for (int i = 0; i < n; i++)
#define ford(i, n) for (int i = n - 1; i >= 0; i--)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define repd(i, a, b) for (int i = a; i >= b; i--)
#define trav(x, a) for (auto &x : a)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define endl '\n'
#define sz(a) (int)(a).size()
#define fi first
#define se second

clock_t time_p = clock();
void time_taken()
{
    time_p = clock() - time_p;
    cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}

const ll mod = 1e9 + 7;
const ll INF = 1e18;

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(nullptr);

    int64_t n, p;
    cin >> n >> p;
    int64_t ans = 1;
    for (int64_t i = 2; i * i <= p; i++)
    {
        if (p % i)
            continue;
        int cnt = 0;
        while (p % i == 0)
        {
            p /= i;
            cnt++;
        }
        ans *= powl(i, cnt / n);
    }
    if(p > 1){
        ans *= powl(p, 1 / n);
    }
    cout << ans << endl;

    time_taken();   
    return 0;
}

Measured memory_bytes: 3856
#include<stdio.h>
int main()
{
    int N,M,i,A[10000],sum=0;
    scanf("%d%d",&N,&M);
    for(i=0;i<M;i++)
    {
        scanf("%d",&A[i]);
        sum=sum+A[i];
    }
    if(sum>N)
    {
        printf("-1\n");

    }
    else
    {
        printf("%d\n",N-sum);
    }
    return 0;

    }


Measured memory_bytes: 1728
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int min = 1000000, max = -1000000;
		long sum = 0;
		
		for (int i=0; i<n; i++) {
			int num = sc.nextInt();
			if (num < min) min = num;
			if (num > max) max = num;
			sum += num;
		}
		
		System.out.printf("%d %d %d\n",min, max, sum);
	}
}



Measured memory_bytes: 41912
# 解説の写経

def solve_panasonic2020_e():
    def unmatched(c1: str, c2: str) -> bool:
        """c1,c2がマッチしない"""
        return not (c1 == '?' or c2 == '?' or c1 == c2)

    A = input()
    B = input()
    C = input()

    MX = max(map(len, [A, B, C]))

    # 相対位置ごとの文字列マッチングの可否を調べる
    # ab/ac/bc[index差]:=その相対位置でマッチしないときTrue
    # [-MX,MX]
    # + : 左文字より右文字が右にある, a->b
    # - : 右文字より左文字が右にある, b->a
    ab = [False] * (MX * 4 + 1)
    ac = [False] * (MX * 4 + 1)
    bc = [False] * (MX * 4 + 1)

    for i, a in enumerate(A):
        for j, b in enumerate(B):
            ab[i - j] |= unmatched(a, b)

    for i, a in enumerate(A):
        for j, c in enumerate(C):
            ac[i - j] |= unmatched(a, c)

    for i, b in enumerate(B):
        for j, c in enumerate(C):
            bc[i - j] |= unmatched(b, c)

    # Aに対するB,Cの相対位置MX**2で全探索
    ans = sum(map(len, [A, B, C]))
    for i in range(-MX * 2, MX * 2 + 1):  # ACBのようにAB間にMX分空くこともあって、幅2MX
        if ab[i]: continue
        for j in range(-MX * 2, MX * 2 + 1):  # ABCのようにAC間にMX分空くこともあって、幅2MX
            if ac[j]: continue
            if bc[j - i]: continue
            # 添え字で混乱するが
            # ab[i-j]で
            # 添え字i-jは(bの開始)-(aの開始)を意味したことから
            # (i-j>0でa->bの配置から)
            # 今回i,jは(aの開始)を基準にした(b,cの開始位置)で
            # bcの添え字は(cの開始)-(bの開始)なのでj-i

            # [L,R)
            L = min(0, i, j)
            R = max(len(A), i + len(B), j + len(C))
            ans = min(ans, R - L)

    print(ans)
    return


if __name__ == '__main__':
    solve_panasonic2020_e()

# N**3は通らない
# N**2の方針=2本の文字列の捜査


Measured memory_bytes: 63580
#include <cstdio>

int check[30];

int main() {
  for (int bit = 29; bit >= 0; bit--) {
    check[bit] = 0;
  }

  int n;
  scanf("%d", &n);
  int xor_sum = 0;
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    xor_sum ^= a;
    a = a ^ (a - 1);
    for (int bit = 29; bit >= 0; bit--) {
      int x = (1 << (bit + 1)) - 1;
      if (a == x) {
        check[bit] = 1;
      }
    }
  }

  int ans = 0;
  for (int bit = 29; bit >= 0; bit--) {
    if (((1 << bit) & xor_sum) == 0) {
      continue;
    }
    int x = (1 << (bit + 1)) - 1;

    if (check[bit] > 0) {
      xor_sum ^= x;
      ans += 1;
    }
  }

  if (xor_sum != 0) {
    printf("-1\n");
  } else {
    printf("%d\n", ans);
  }
}

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

#define int long long
#define ll long long
#define f1(i,a,b) for(int i=a;i<b;i++)
#define f2(i,a,b) for(int i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;
ll temp;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    // #ifndef ONLINE_JUDGE
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/in.txt","r",stdin);
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/out.txt","w",stdout);
    // #endif

    string s,t;
    cin>>s>>t;
    int a,b;
    cin>>a>>b;
    string y;
    cin>>y;
    if(y==s)
    	a--;
    else
    	b--;

    cout<<a<<gp<<b<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mp(x,y)     make_pair(x,y) 
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,a,n)   for(ll i=a;i<n;i++)
#define frr(i,a,n)  for(ll i=n-1;i>=a;i--)


const ll N   =  500005;
const ll mod = 1e9 + 7;

using namespace std;


void solve()
{
 string s;
  ll n,m,k,x=0,y=0,c=0,q,ans=0;
  cin>>s;
 
  for (ll i = 0; i < s.size()-1; ++i)
  {
    if(s[i]==s[i+1])
    {
      c("Bad");
      return;
    }
  }
  c("Good");
  
//  cout<<c<<" ";
}

signed main(){
  
  
      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      ll T=1;
      //cin>>T;
      while(T--)
      {
      solve();
      }
      return 0;
    }


Measured memory_bytes: 764
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
typedef long long ll;

using namespace std;

int main() {
	int k5 = 0, k7 = 0;
	rep(_, 3) {
		int a; cin >> a;
		if (a == 5) k5 += 1;
		if (a == 7) k7 += 1;
	}
	if (k7 = 1 && k5==2) cout << "YES" << endl;
	else cout << "NO" << endl;
}

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

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

    ll N, K;
    cin >> N >> K;

    if (N % K == 0) {
        cout << 0 << "\n";
        return 0;
    }

    ll ans = N;
    while (N / K > 0) {
        N = N % K;
        ans = N;
    }

    ll tmp = abs(N - K);
    if (N < tmp) cout << N << "\n";
    else cout << tmp << "\n";
    return 0;
}

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

using namespace std;

int n,m;
int x_1[123],y_1[123];
int x_2[123],z_2[123];

double f(int dx){
  vector<double> y;
  for(int i=0;i<m;i++){
    if(x_1[i]*2==dx){
      y.push_back(y_1[i]);
    }else if((x_1[i]*2-dx)*(x_1[(i+1)%m]*2-dx)<0){
      y.push_back(y_1[i]+(y_1[(i+1)%m]-y_1[i])*(dx/2.-x_1[i])/(x_1[(i+1)%m]-x_1[i]));
    }
  }
  if(y.empty())return 0;
  sort(begin(y),end(y));
  vector<double> z;
  for(int i=0;i<n;i++){
    if(x_2[i]*2==dx){
      z.push_back(z_2[i]);
    }else if((x_2[i]*2-dx)*(x_2[(i+1)%n]*2-dx)<0){
      z.push_back(z_2[i]+(z_2[(i+1)%n]-z_2[i])*(dx/2.-x_2[i])/(x_2[(i+1)%n]-x_2[i]));
    }
  }
  if(z.empty())return 0;
  sort(begin(z),end(z));
  return (y.back()-y[0])*(z.back()-z[0]);
}

int main(){
  while(cin>>m>>n,m|n){
    vector<int> v;
    for(int i=0;i<m;i++){
      cin>>x_1[i]>>y_1[i];
      v.push_back(x_1[i]);
    }
    for(int i=0;i<n;i++){
      cin>>x_2[i]>>z_2[i];
      v.push_back(x_2[i]);
    }
    sort(begin(v),end(v));
    double ans=0;
    for(int i=0;i<v.size()-1;i++){
      if(v[i]<*min_element(x_1,x_1+m)||v[i]<*min_element(x_2,x_2+n))continue;
      if(v[i+1]>*max_element(x_1,x_1+m)||v[i+1]>*max_element(x_2,x_2+n))continue;
      ans+=(v[i+1]-v[i])/6.*(f(v[i]*2)+4*f(v[i]+v[i+1])+f(v[i+1]*2));
    }
    cout<<fixed<<ans<<endl;
  }
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=(2e5)+10;
int n;
ll s[maxn],a[maxn],s1,s2,s3,s4,ans=1e18;
int find(int l,int r,ll x) {
	while (l<r) {
		int mid=(l+r+1)/2;
		if (s[mid]<=x) l=mid;
		else r=mid-1;
	}
	return l;
}
int main() {
	//freopen("1.txt","r",stdin);
	scanf("%d",&n);
	for (int i=1;i<=n;i++) {
		scanf("%lld",&a[i]);
		s[i]=s[i-1]+a[i];
	}
	for (int i=2;i<n-1;i++) {
		s1=find(0,i,s[i]/2),s2=s1+1;
		s3=find(i+1,n,s[i]+(s[n]-s[i])/2),s4=s3+1;
		int s5,s6;
		if (abs(s[i]-s[s1]-s[s1])<abs(s[i]-s[s2]-s[s2])) s5=s1; else s5=s2;
		if (abs(s[n]-s[s3]-s[s3]+s[i])<abs(s[n]-s[s4]-s[s4]+s[i])) s6=s3; else s6=s4;
		ans=min(max(max(s[s5],s[i]-s[s5]),max(s[s6]-s[i],s[n]-s[s6]))
		-min(min(s[s5],s[i]-s[s5]),min(s[s6]-s[i],s[n]-s[s6])),ans);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main(){
  int L;
  cin >> L;
  int N = 20;
  vector<tuple<int, int, int>> E;
  for (int i = 0; i < N - 1; i++){
    E.push_back(make_tuple(i, i + 1, 0));
  }
  for (int i = 0; i < N - 1; i++){
    if (L >= 1 << (i + 1)){
      E.push_back(make_tuple(i, i + 1, 1 << i));
    }
  }
  int cnt = 0;
  int tmp = 1;
  while (tmp * 2 < L){
    tmp *= 2;
    cnt++;
  }
  for (int i = 0; i < cnt; i++){
    if (L >> i & 1){
      L -= (1 << i);
      E.push_back(make_tuple(i, N - 1, L));
    }
  }
  int M = E.size();
  cout << N << ' ' << M << endl;
  for (int i = 0; i < M; i++){
    int v = get<0>(E[i]);
    int w = get<1>(E[i]);
    int d = get<2>(E[i]);
    cout << v + 1 << ' ' << w + 1 << ' ' << d << endl;
  }
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main ()
{
    string s,t;
    cin>>s>>t;
    int i,r=s.length(),k=t.length(),m=0;
    for(i=0;i<r;i++)
    {
        if(s[i]!=t[i]){
            printf("No\n");
            m=1;
            break;
        }
    }
      if(m==0)
        if((k-r)==1)
        printf("Yes\n");
           else printf("No\n");
}




Measured memory_bytes: 3520
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <cstdio>
using namespace std;

ll floor_sum(ll n,ll m,ll a,ll b){
  ll ans=0;
  if(a>=m){
    ans+=(n-1)*n*(a/m)/2;
    a%=m;
  }
  if(b>=m){
    ans+=n*(b/m);
    b%=m;
  }

  ll y_max=(a*n+b)/m;
  if(y_max==0) return ans;
  ans+=floor_sum(y_max,a,m,a*n-y_max*m+b);
  return ans;
}

int main(){
  int t;
  scanf("%d",&t);
  
  while(t--){
    int n,m,a,b;
    scanf("%d%d%d%d",&n,&m,&a,&b);
    printf("%lld\n",floor_sum(n,m,a,b));
  }
  
  return 0;
}

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

int main() {
  int ans=0;
  vector<vector<int>>A(3,vector<int>(3));
  int N;
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin>>A[i][j];
    }
  }
  cin>>N;
  rep(i,N){
    int x;
    cin>>x;
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
        if(x==A[j][k]){
          A[j][k]=0;
        }
      }
    }
  }
  for(int i=0;i<3;i++){
    int x=0;
    for(int j=0;j<3;j++){
      x=x+A[i][j];
    }
    if(x==0){
      ans++;
    }
  }
  for(int i=0;i<3;i++){
    int x=0;
    for(int j=0;j<3;j++){
      x=x+A[j][i];
    }
    if(x==0){
      ans++;
    }
  }
  int x=0;
  for(int i=0;i<3;i++){
    x+=A[i][i];
  }
    if(x==0) { 
      ans++;
    }
  x=0;
  for(int i=0;i<3;i++){
    x+=A[i][2-i]; 
  }
    if(x==0){
      ans++;
    }
  if(ans==0) cout<<"No";
  else cout<<"Yes";
}


Measured memory_bytes: 256
object Main extends App {
	private def direct(a: Int, n: Int): Long = {
		//val pow = Math.pow(2, n).toLong
		val pow = 1L << n
		pow + a * (pow - 1)
	}

	//@scala.annotation.tailrec
	private def func(n: Int, x: Long): Long = {
		//println("func", n, x)
		if (n == 0 && x > 0) return 1L
		if (x <= 1) return 0L
		//if (n == 0 && x == 0) return 0L

		val lenOfN1 = direct(3, n - 1)
		val numOfN1 = direct(1, n - 1)

		if (x <= lenOfN1 + 1) {
			func(n - 1, x - 1)
		} else {
			numOfN1 + 1 + func(n - 1, x - 2 - lenOfN1)
		}
	}

	private def solve(in: Seq[Long]): Long = func(in(0).toInt, in(1))

	assert(solve(Seq(0, 0)) == 0)
	assert(solve(Seq(0, 1)) == 1)
	assert(solve(Seq(1, 1)) == 0)
	assert(solve(Seq(3, 14)) == 7)
	assert(solve(Seq(3, 15)) == 8)
	assert(solve(Seq(3, 28)) == 15)
	assert(solve(Seq(3, 29)) == 15)
	assert(solve(Seq(50, 4321098765432109L)) == 2160549382716056L)
	println(solve(io.Source.stdin.getLines.toIndexedSeq.head.split(' ').map(_.toLong)))
}


Measured memory_bytes: 27208
#include<stdio.h>
#define MAX 100005
#define NIL -1
struct Node{
    int parent;
    int left;
    int right;
};
struct Node T[MAX];

int n,D[MAX];
int setDepth(int u,int p){
    D[u] = p;
    if (T[u].right != NIL){
        setDepth(T[u].right,p);
    }
    if(T[u].left != NIL){
        setDepth(T[u].left,p + 1);
    }
}
void printChildren(int u){
    int c;
    c = T[u].left;
    printf("node %d: parent = %d, depth = %d, ",u,T[u].parent,D[u]);
    if(D[u] == 0){
    printf("root, [");
    }
    else if(c != NIL){
        printf("internal node, [");
    }
    else if(c == NIL){
        printf("leaf, [");
    }
    while(c != NIL){
        printf("%d",c);
        if(T[c].right != -1){
            printf(", ");
        }
        c = T[c].right;
    }
    printf("]\n");
}

int main(){
    int i,v,d,j,c,l,r,u;
    scanf("%d",&n);
    for(i = 0;i < n;i++){
        T[i].parent = NIL;
        T[i].left = NIL;
        T[i].right = NIL;
    }
    for(i = 0;i < n;i++){
        scanf("%d %d",&v,&d);
        for(j = 0;j < d;j++){
            scanf("%d",&c);
            if(j == 0) T[v].left = c;
            else T[l].right = c;
            l = c;
            T[c].parent = v;
            }
    }


for(i = 0;i < n;i++){
    if(T[i].parent == NIL) r = i;
}

setDepth(r,0);

for(u = 0;u < n;u++){
printChildren(u);
}
return 0;
}




Measured memory_bytes: 6452
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<template<class...> class ContT, class ValueT, size_t Dim>
struct vec_type
{
    using type = ContT<typename vec_type<ContT, ValueT, Dim-1>::type>;
};

template<template<class...> class ContT, class ValueT>
struct vec_type<ContT, ValueT, 0>
{
    using type = ValueT;
};

template<class ValueT, size_t Dim = 1>
using vec_t = typename vec_type<std::vector, ValueT, Dim>::type;


template<class ValueT, size_t Dim, class = typename std::enable_if<Dim == 0>::type>
auto make_vec(ValueT value = ValueT()) -> ValueT
{
    return value;
}

template<class ValueT, size_t Dim, class... Rest>
auto make_vec(size_t size0, Rest... rest)
{
    auto vec = make_vec<ValueT, Dim-1>(rest...);
    return std::vector(size0, vec);
}

int diffabs(int l, int r)
{
    if (l < r) return r-l;
    else return l-r;    
}


///////////////////////////////////////////////////

bool comp_first_second(pair<int,int> l, pair<int,int> r)
{
    if (l.first < r.first) return true;
    else if (l.first > r.first) return false;
    else if (l.second < r.second) return true;
    else return false;
}

bool comp_second_first(pair<int,int> l, pair<int,int> r)
{
    if (l.second > r.second) return true;
    else if (l.second < r.second) return false;
    else if (l.first > r.first) return true;
    else return false;
}

int main()
{
    int N;
    cin >> N;
    vi A(N), B(N);
    vector<pair<int,int>> pr(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i] >> B[i];
        pr.emplace_back(A[i], B[i]);
    }

    sort(begin(A), end(A), less<int>());
    sort(begin(B), end(B), greater<int>());

    ll ans;
    if (N % 2 == 0)
    {
        int hN = N / 2;
        
        ll kagen0 = A[hN-1];
        ll kagen1 = A[hN];
        ll jogen0 = B[hN-1];
        ll jogen1 = B[hN];

        ll range = (jogen0 + jogen1) - (kagen0 + kagen1) + 1;
        ans = range;        
    }
    else
    {
        int hN = N / 2;
        
        int range = B[hN] - A[hN] + 1;
        ans = range;
    }
    cout << ans << endl;
}

Measured memory_bytes: 7956
n=int(input())
s=input()
m=list(s.split())
a=0
b=0
for i in range(0,n):
  a=a+int(m[i])
  b=b+(int(m[i])*int(m[i]))
l= ((a**2)-b)//2
l=l%1000000007
print(l)

Measured memory_bytes: 95148
#https://at274.hatenablog.com/entry/2018/02/02/173000
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            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 self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

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

n,m=map(int, input().split())
uf=UnionFind(n)
for _ in range(m):
    ai,bi=map(int, input().split())
    uf.union(ai,bi)

cnt=[0]*(n+1)

for i in range(n+1):
    cnt[uf.find(i)]+=1
print(max(cnt))

Measured memory_bytes: 99520
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
    string s,l;
    int n = 0;
    cin >> s;
    cin >>l;
    for(int i=0;i < s.length();i++){
        if(s[i] != l[i]) n++;
    }
    cout << n;
}

Measured memory_bytes: 3916
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        ArrayList<Long> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(sc.nextLong());
        }
        System.out.println(list.stream().sorted(Comparator.reverseOrder()).skip(k).mapToLong(l -> l).sum());
    }
}

Measured memory_bytes: 67200
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();
		
		if(a>0){
			System.out.println("Positive");
		}else{
			if(b>=0){
				System.out.println("Zero");
			}else{
				if((b-a) % 2 == 0){
					System.out.println("Negative");
				}else{
					System.out.println("Positive");
				}
			}
		}
		
	}

}


Measured memory_bytes: 9796
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

const ll INF = 1e9;

int main() {
	#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
	#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);

	ll n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	ll diff = abs(b - a);
	n -= 1;
	REP(i, n) {
		ll lb = -d * i, ub = -c * i;
		if (lb + c * (n - i) <= diff && diff <= ub + d * (n - i)) {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 256
def resolve():
    H,_ = map(int,input().split())
    DP = [[2 ** 63 - 1 for _ in range(10)] for _ in range(10)]
    for i in range(10):
        DP[i] = list(map(int,input().split()))

    for k in range(10):
        for i in range(10):
            for j in range(10):
                DP[i][j] = min(DP[i][j],DP[i][k]+DP[k][j])

    import collections
    import itertools
    A = [list(map(int,input().split())) for _ in range(H)]
    c = collections.Counter(itertools.chain.from_iterable(A))
    ans = 0
    for i in range(10):
        ans += c[i] * DP[i][1] 
    print(ans)
resolve()

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

int main() {
  int N, M, C[50];
  cin >> N >> M;
  for (int i = 0; i < N; i++) C[i] = 0;
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    C[a - 1]++;
    C[b - 1]++;
  }
  for (int i = 0; i < N; i++) cout << C[i] << endl;
}

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

int main(){
  map<string,int> m;
  m["MON"]=1;
  m["TUE"]=2;
  m["WED"]=3;
  m["THU"]=4;
  m["FRI"]=5;
  m["SAT"]=6;
  m["SUN"]=0;
  string S;
  cin >> S;
  cout << 7-m[S];
}

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

int main()
{
  int A,B,T ;
  cin>>A>>B>>T ;
  int count=0 ;
  
  for(int i=0;i+A<T+0.5;i+=A){
    count +=B ;
  }
  
  cout<<count<<endl ;
  
  return 0 ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair <int, int>;
const double PI = acos(-1);

int main() {
int A, B;
cin >> A >> B;
if(A%2 == B%2) cout << (A+B)/2 << endl;
else cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 256
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
e = []
o = []
for i in range(n):
    if i % 2 == 0:
        e.append(v[i])
    else:
        o.append(v[i])
e_counter = Counter(e)
o_counter = Counter(o)
e_most = e_counter.most_common()
o_most = o_counter.most_common()
E1 = e_most[0][0]
E2 = E1
if len(e_most) > 1:
    E2 = e_most[1][0]
O1 = o_most[0][0]
O2 = O1
if len(o_most) > 1:
    O2 = o_most[1][0]
e_cnt = n // 2 - e.count(E1)
o_cnt = n // 2 - o.count(O1)
if e_cnt == 0 and o_cnt == 0:
    if e[0] == o[0]:
        print(n // 2)
    else:
        print(0)
else:
    if E1 != O1:
        print(e_cnt + o_cnt)
    else:
        if E1 == O2:
            e_cnt = n // 2 - e.count(E2)
            print(e_cnt + o_cnt)
        elif E2 == O1:
            o_cnt = n // 2 - o.count(O2)
            print(e_cnt + o_cnt)
        else:
            cnt1 = n // 2 - e.count(E2) + o_cnt
            cnt2 = e_cnt + n // 2 - o.count(O2)
            print(min(cnt1, cnt2))


Measured memory_bytes: 23776
N=int(raw_input())
array=map(int, raw_input().split())

max_abs=0

for i in range(N):
    a1 = array[i]
    for j in range(i+1,N):
        a2 = array[j]
        tmp_abs = abs(a1-a2)
#        print i,j,a1,a2,tmp_abs
        if tmp_abs > max_abs:
            max_abs = tmp_abs

print max_abs


Measured memory_bytes: 2568
#include<iostream>
#include<vector>
#include<string>
typedef long long ll;
using namespace std;
ll mod = 1000000007;
ll expr(string &s,int a,int b);
ll term(string &s,int a,int b);
ll number(string &s,int a,int b);


ll expr(string &s,int a,int b){
    int tmp = -1;
    int dep = 0;
    for(int i=b;i>=a;i--){
        if(s[i]=='<'){
            dep++;
        }
        if(s[i]=='>'){
            dep--;
        }
        if(s[i]=='p'&&dep==0){
            tmp =i;
            break;
        }
    }
    if(tmp==-1){
        return term(s,a,b);
    }else{
        ll x = expr(s,a,tmp-1);
        ll y = expr(s,tmp+1,b);
        if(y>=30)x=0;
        else for(ll i=0;i<y;i++){
            x /=2;
        }
        return x;
    }
}

ll term(string &s,int a,int b){
    if(s[a]=='S'){
        ll x = expr(s,a+2,b-1);
        return x*x%mod;
    }else{
        return number(s,a,b);
    }
}


ll number(string &s,int a,int b){
    ll ans = 0;
    for(int i=a;i<=b;i++){
        ans *=(ll)10;
        ans += (ll)(s[i]-'0');
    }
    return ans;
}


int main(){
    while(1){
        string s1,s;
        getline(cin,s1);
        if(s1[0]=='#')break;
        for(int i=0;i<s1.size();i++){
            if(s1[i]!=' '){
                s.push_back(s1[i]);
            }
        }
        vector<bool> p((int)s.size());
        for(int i=0;i<s.size();i++){
            if(s[i]!='<'&&s[i]!='>'){
                if(i==0)continue;
                if(s[i-1]=='>'){
                    p[i-1]=1;
                    p[i-2]= 1;
                }
            }
        }
        string ss;
        int tmp = 0;
        while(tmp<(int)s.size()){
            if(p[tmp]){
                ss.push_back('p');
                tmp+=2;
            }else{
                ss.push_back(s[tmp]);
                tmp++;
            }
        }
        cout << expr(ss,0,(int)ss.size()-1) << endl; 
    }
    return 0;
}


Measured memory_bytes: 5540