akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 999999
#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<k;i++)
typedef long long ll;
typedef unsigned long long ull;

int main(){
	string str;
	cin >> str;
	int len = str.size();
	int ans = 0;
	rep(i,len/2){
		if(str[i] == '(' && str[len-i-1] != ')')ans++;
		else if(str[i] == ')' && str[len-i-1] != '(')ans++;
		else if(str[i] == 'i' && str[len-i-1] != 'i')ans++;
		else if(str[i] == 'w' && str[len-i-1] != 'w')ans++;
	}
	if(len%2 == 1 && (str[len/2] == '(' || str[len/2] == ')'))ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1180
import java.util.*;

public class Main{
  public static int dp[]=new int[100001];
  public static int go(int a[],int i){
    if(i==a.length-1)
    {
      return 0;
    }
    if(i>a.length-1)
    {
      return 100000;
    }
    if(dp[i]!=-1)
    return dp[i];
    int one=10000,two=10000;
    if(i+1<=a.length-1)
    one=Math.abs(a[i]-a[i+1])+go(a,i+1);
    if(i+2<=a.length-1)
    two=Math.abs(a[i]-a[i+2])+go(a,i+2);
    dp[i]=Math.min(one,two);
    return dp[i];
  }
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in); 
    int n=sc.nextInt();
    int a[]=new int[n];
    for(int i=0;i<n;i++){
    dp[i]=-1;
    a[i]=sc.nextInt();
    }
    dp[n]=-1;
    System.out.print(go(a,0));
  }
}

Measured memory_bytes: 72620
def GCD( a,  b ):
    if b == 0:
        # print("--" * 10)
        return a
    else:
        # print(b)
        return GCD(b, a % b)

import math
N,X = list(map(int,input().split(" ")))
xs = list(map(int,input().split(" ")))
xs = list(map(lambda x:abs(x-X),xs))
gcds = [xs[0]]
for i,x in enumerate(xs[1:]):
    gcds.append(GCD(gcds[i],x))
print(gcds[-1])



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

int main()
{
    double a, t;
    int b;
    cin >> a >> b >> t;
    int cnt = 0;
    double tic = 0.0;
    for (int i = 1; tic + a * i < t + 0.5; i++)
    {
        cnt += b;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import math
while True:
    score = []
    n = int(input())
    if n == 0:
        break
    else:
        for i in range(n):
            score.append(int(input()))
    
    score.remove(min(score))
    score.remove(max(score))
    
    print(math.floor(sum(score)/len(score)))


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

int main()
{
    int N, R;
    cin >> N >> R;
    if (N >= 10)
    {
        cout << R << endl;
    }
    else
    {
        cout << R + 100 * (10 - N) << endl;
    }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	static Long[][] graph;
	static int V;

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] V_E = br.readLine().split(" ");

		V = Integer.parseInt(V_E[0]);

		int E = Integer.parseInt(V_E[1]);

		graph = new Long[V][V];

		for (int i = 0; i < V; i++) {
			for (int j = 0; j < V; j++) {
				if (!(i == j)) {
					graph[i][j] = Long.MAX_VALUE/3;
				}else {
					graph[i][j] =0L;
				}
			}
		}

		for (int i = 0; i < E; i++) {
			String[] edge = br.readLine().split(" ");

			int from = Integer.parseInt(edge[0]);

			int to = Integer.parseInt(edge[1]);

			Long cost = Long.parseLong(edge[2]);

			graph[from][to] = cost;
		}
		washawasha();

		boolean negative = true;

		for (int i = 0; i < V; i++) {
			if (graph[i][i] < 0) {
				System.out.println("NEGATIVE CYCLE");
				negative = false;
				break;
			}
		}

		if (negative) {

			for (int i = 0; i < V; i++) {
				StringBuilder sb = new StringBuilder();
				for (int j = 0; j < V; j++) {
					if (graph[i][j] ==  (Long.MAX_VALUE/3)) {
						sb.append("INF");
						sb.append(" ");
					} else {
						sb.append(graph[i][j]);
						sb.append(" ");
					}
				}
				System.out.print(sb.toString().trim());
				System.out.println("");
			}
		}

	}

	static void washawasha() {
		for (int k = 0; k < V; k++) {
			for (int i = 0; i < V; i++) {
                if (graph[i][k] == Long.MAX_VALUE/3) {
                    continue;
                }
				for (int j = 0; j < V; j++) {
	                  if (graph[k][j] == Long.MAX_VALUE/3) {
	                        continue;
	                    }
					/*System.out.println(graph[i][j]+""+graph[i][k]+""+graph[k][j]);*/
					graph[i][j] = Math.min(graph[i][j], graph[i][k] + graph[k][j]);
				}
			}
		}

	}

}

Measured memory_bytes: 60444
fun main(args: Array<String>) {
    val alphabets = arrayOf('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z')
    val n = readLine()!!.toInt()
    val s = readLine()!!
    var ans = CharArray(s.length)
    for (i in 0 until s.length) {
        val index = alphabets.indexOf(s[i])
        ans[i] = alphabets[(index + n) % 26]
    }
    println(String(ans))
}

Measured memory_bytes: 34076
use strict;
use warnings;
package ZAlgorithm;
sub z_algorithm(@){
	my$n=@_;
	my@z=($n);
	my$i=1;
	my$j=0;
	while($i<$n){
		$j++while$i+$j<$n&&$_[$j]==$_[$i+$j];
		$z[$i]=$j;
		if($j==0){
			$i++;
			next;
		}
		my$k=1;
		while($i+$k<$n&&$k+$z[$k]<$j){
			$z[$i+$k]=$z[$k];
			$k++;
		}
		$i+=$k;
		$j-=$k;
	}
	return@z;
}
package main;
my$N=<>;
my@A=map int,split$",<>;
my@B=map int,split$",<>;
my@T;
for(0..$N-1){
	$T[$_]=$B[$_]^$B[($_+1)%$N];
	$T[$_+$N]=$T[$_+2*$N]=$A[$_]^$A[($_+1)%$N];
}
my@z=ZAlgorithm::z_algorithm(@T);
for(0..$N-1){
	print$_,$",$A[$_]^$B[0],$/if$z[$_+$N]>=$N;
}


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

int main() {
	int n; cin>>n;
	int a,b; a=n%100; b=(n-a)/100;
	if(a<13 && a>0 && b<13 && b>0) cout<<"AMBIGUOUS"<<endl;
	else if(a<13 && a>0) cout<<"YYMM"<<endl;
	else if(b<13 && b>0) cout<<"MMYY"<<endl;
	else cout<<"NA"<<endl;
	return 0;
}

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

  ll N,K;
  cin>>N>>K;
  
  ll base=N%K;
  ll ans = min(base,abs(base-K));
  
  cout<<ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void solve(){
    string S;
    cin >> S;
    int flag = 1;
    for(int i=0; i<S.size(); i++){
        if(S[i] == 'h'){
            if(S[i+1] == 'i' && i+1 != S.size()){
                if(i+2 != S.size()) i = i+1;
                else{
                    cout << "Yes" << endl;
                    exit(0);
                }
            }else{
                cout << "No" << endl;
                exit(0);
            }
        }else{
            cout << "No" << endl;
            exit(0);
        }

    }
    cout << "Yes" << endl;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1e9 + 7

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

    int a,b;

    cin >> a >> b;

    if(b>=a) cout << a;
    else cout << a-1;
}


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 int INF = 1001001001;
int main(){
  int N;
  cin>>N;
  vector<int64_t>a(3*N);
  for(int i=0;i<3*N;i++){
    cin>>a.at(i);
  }

  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
 
  int64_t ans=0;
  int count=1;
  int i=0;
  while(count<=N){
    if(i%2>0){ans+=a.at(i);
     count++;
    }
    i++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 2688
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)

inline int read()
{
	int data = 0, w = 1; char ch = getchar();
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') w = -1, ch = getchar();
	while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
	return data * w;
}

const int N(2e5 + 10);
std::vector<int> G[N]; std::pair<int, int> t[N];
int n, A[2][N], dfn[N], low[N], stk[N], bel[N], id[N], cnt, col, top, cur;
void build(int x = 1, int l = 1, int r = n << 1)
{
	if (l == r) return (void) (id[x] = t[l].second);
	int mid = (l + r) >> 1, ls = x << 1, rs = ls | 1; id[x] = ++cur;
	build(ls, l, mid), build(rs, mid + 1, r);
	G[id[x]].push_back(id[ls]), G[id[x]].push_back(id[rs]);
}

void Link(int ql, int qr, int t, int x = 1, int l = 1, int r = n << 1)
{
	if (ql > qr) return;
	if (ql <= l && r <= qr) return G[t].push_back(id[x]);
	int mid = (l + r) >> 1, ls = x << 1, rs = ls | 1;
	if (ql <= mid) Link(ql, qr, t, ls, l, mid);
	if (mid < qr) Link(ql, qr, t, rs, mid + 1, r);
}

void tarjan(int x)
{
	dfn[x] = low[x] = ++cnt, stk[++top] = x;
	for (auto i : G[x])
		if (!dfn[i]) tarjan(i), low[x] = std::min(low[x], low[i]);
		else if (!bel[i]) low[x] = std::min(low[x], dfn[i]);
	if (dfn[x] == low[x]) { ++col; do { bel[stk[top]] = col; } while (stk[top--] != x); }
}

int check(int mid)
{
	for (int i = 1; i <= cur; i++) G[i].clear();
	memset(dfn, 0, sizeof dfn), memset(low, 0, sizeof low), memset(bel, 0, sizeof bel);
	cnt = top = 0, cur = n << 1; build();
	for (int i = 1; i <= n; i++)
		for (int j = 0; j < 2; j++)
		{
			int l = std::lower_bound(t + 1, t + (n << 1) + 1, std::make_pair(A[j][i] - mid + 1, 0)) - t;
			int r = std::upper_bound(t + 1, t + (n << 1) + 1, std::make_pair(A[j][i] + mid - 1, n << 1 | 1)) - t - 1;
			int _ = std::lower_bound(t + 1, t + (n << 1) + 1, std::make_pair(A[j][i], i + (j ^ 1) * n)) - t;
			Link(l, _ - 1, i + j * n), Link(_ + 1, r, i + j * n);
		}
	for (int i = 1; i <= cur; i++) if (!dfn[i]) tarjan(i);
	for (int i = 1; i <= n; i++) if (bel[i] == bel[i + n]) return 0;
	return 1;
}

int main()
{
	n = read();
	for (int i = 1; i <= n; i++)
		A[0][i] = read(), A[1][i] = read(),
		t[i] = std::make_pair(A[0][i], i + n), t[i + n] = std::make_pair(A[1][i], i);
	std::sort(t + 1, t + (n << 1) + 1); int L = 0, R = 1e9, ans;
	while (L <= R)
	{
		int mid = (L + R) >> 1;
		if (check(mid)) ans = mid, L = mid + 1;
		else R = mid - 1;
	}
	printf("%d\n", ans);
	return 0;
}


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

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define debug(x) cerr << #x << " = " << (x) << endl;
template<typename T>
ostream& operator<<(ostream& o, vector<T>& v) {
    for (auto& x : v) o << x << ' ';
    return o;
}

const int MOD = 1e9 + 7;
int n, m;
string grid[1010];
int memo[1010][1010];
int dx[] = {0, 1};
int dy[] = {1, 0};
void add(int &x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
}  
int dp(int i, int j) {
  int &res = memo[i][j];
  if (res != -1) return res;
  if (grid[i][j] == '#') return res = 0;
  if (i == n-1 && j == m-1) return res = 1;
  res = 0;
  for (int k = 0; k < 2; k++) {
    int x = i + dx[k], y = j + dy[k];
    if (x < 0 || x >= n || y < 0 || y >= m) continue;
    add(res, dp(x, y));
  }
  return res;
}

int main(){
    std::ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> grid[i];
    memset(memo, -1, sizeof memo);
    cout << dp(0, 0) << endl;
}


Measured memory_bytes: 5376
#include <stdio.h>

int main(void){
    char s[3];
  scanf("%s", s);
  
  if ( s[0] = s[1] && s[2] == s[1] && s[0] == s[2] ){
    printf("No\n");
  } else {
    printf("Yes\n");
  }

    return 0;
}

Measured memory_bytes: 128
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a = read::<usize>();
    let b = read::<usize>();

    let mut ans = 0;
    let mut cnt = 0;

    if b == 1 {
        println!("0");
        return;
    } else if b < a {
        println!("1");
        return;
    }

    while cnt + 1 < b {
        cnt += a-1;
        ans += 1;
    }

    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,i;
  cin>>n;
  for(i=9;i>=1;i--)
  {
    if(n%i==0)
    {
      if((n/i)<=9)
      {
        cout<<"Yes";
        return 0;
      }
      else
      {
        cout<<"No";
        return 0;
      }
    }
  }
  cout<<"No";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string wa="UNRESTORABLE",s,t,a;
vector<string>v;
int main()
{
	cin>>s>>t;
	a=s;
	for(int i=0;i+t.size()<=s.size();i++)
	{
		string ss=s.substr(i,t.size());
		int j;
		for(j=0;j<t.size();j++)
		{
			if(s[i+j]==t[j] || s[i+j]=='?')
			{
				continue;
			}
			break;
		}
		if(j!=t.size())
		{
			continue;
		}
		for(j=0;j<t.size();j++)
		{
			s[i+j]=t[j];
		}
		for(j=0;j<s.size();j++)
		{
			if(s[j]=='?')
			{
				s[j]='a';
			}
		}
		v.push_back(s);
		s=a;
	}
	sort(v.begin(),v.end());
	if(v.size()==0)
	{
		cout<<wa<<endl;
	}
	else
	{
		cout<<v[0]<<endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair < int, int > ii;

int main() {

	int a, b, c, d, x;

	scanf("%d %d %d %d %d", &a, &b, &c, &d, &x);

	b = min(b, 2 * a);
	c = min(c, 2 * b);
	d = min(d, 2 * c);

	ll res = (ll) x / 2 * d;
	res += c * (x % 2);

	printf("%lld\n", res);

    return 0;

}


Measured memory_bytes: 256
import math
n, d = map(int, input().split())
v = []
ans = 0
for i in range(n):
  v.append(list(map(int, input().split())))
  
sq_list = [x**2 for x in range(int(40 * d ** 0.5))]

def square(list):
  return [x**2 for x in list]

def calc_distance(l1, l2):
  dif = [l1[i] - l2[i] for i in range(len(l1))]
  d = sum(square(dif))
  return d

for i in range(n - 1):
  for j in range(i + 1, n):
    temp = calc_distance(v[i], v[j])
    if temp in sq_list:
      ans += 1
print(ans)

Measured memory_bytes: 38256
N = int(input().strip())
def hoge(N, r):  # 1-Nのrの倍数の和
  R = N-(N%r)  # N以下の一番大きいrの倍数を知りたい
  n = R//r
  return n*(n+1)//2*r

ans = hoge(N,1) - hoge(N,3) - hoge(N,5) + hoge(N,15)
print(ans)


Measured memory_bytes: 9112
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e5;
const long inf=1e9;
long modpow(long x,long n,long p){
	int i=0;long res=1;
	while(n>=(1<<i)){
		if(n&(1<<i)) (res*=x)%=p;
		i++;
		x=(x*x)%p;
	}return res;
}
int main(){
	long N,P;cin>>N>>P;
	string s;cin>>s;
    if(P==2||P==5){
        long ans=0;
        rep(i,0,N){
            if((s[i]-'0')%P==0) ans += i+1;
        }cout<<ans<<endl;
        return 0;
    }
	long ans = 0;
	long cnt[P]={}; cnt[0]=1;
	long acm = 0,temp;
	for(int i=N-1;i>=0;i--){
        temp = (acm + (s[i]-'0') * modpow(10,N-i-1,P)) % P;
		ans += cnt[temp];
		cnt[temp]++;
        acm = temp;
	}cout<<ans<<endl;
}

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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}

typedef __int128 INT;
INT zero=0;
INT one=1;
int main(){
    int n;
    cin>>n;
    vector<LL> A(n);
    cin>>A;
    INT p=max(0ll,1-A[0]);
    INT ap=max(1ll,A[0]);
    INT m=max(0ll,1+A[0]);
    INT am=min(-1ll,A[0]);    
    FOR(i,1,n){
        INT bp=max(am+A[i],one);
        INT bm=min(ap+A[i],-one);
        INT np=m-am+bp-A[i];
        INT nm=p+ap-bm+A[i];
        p=np;
        m=nm;
        ap=bp;
        am=bm;
    }
    cout<<(LL)min(p,m)<<endl;
    
    
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<map>
using namespace std;main(){int n,c,m;for(;cin>>n,n;){string s,t;map<string,int>M;for(;n;n--)cin>>s>>c,M[s]=c;for(cin>>n;n;M[s]=min(M[s],c),n--)for(c=0,cin>>s>>m;m;m--)cin>>t,c+=M[t];cin>>s,cout<<M[s]<<endl;}}

Measured memory_bytes: 1224
# https://atcoder.jp/contests/abc138/tasks/abc138_d
n, q = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

def dfs(graph, counter, visited, p, x, n):
    stack = [p]
    visited[p] = True
    while stack:
        node = stack.pop()
        # counter[node] += x
        for n in graph[node]:
            if not visited[n]:
                stack.append(n)
                visited[n] = True
                counter[n] += counter[node]

counter = [0] * n
visited = [False] * n
for _ in range(q):
    # まとめて一括で更新することで、dfsの回数を減らす。
    p, x = map(int, input().split())
    p -= 1
    counter[p] += x

for p in range(len(counter)):
    dfs(graph, counter, visited, p, x, n)
print(*counter)

Measured memory_bytes: 105856
import java.io.*;

class Main {
	public static void main(String args[]) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String buf;
		int k[] = new int[5];
		int res[] = new int[5];
		int data[] = new int[3];

		try {
			while (!(buf = br.readLine()).equals("0")) {
				for (int i=0;i<3;i++) {
					data[i] = 0;
				}
				k[0] = Integer.parseInt(buf);
				data[k[0]-1] = 1;
				for (int i=1;i<5;i++) {
					k[i] = Integer.parseInt(br.readLine());
					data[k[i]-1] = 1;
				}
				if (data[0]==1&&data[1]==1&&data[2]==1) {
					for (int i=0;i<5;i++) res[i] = 3;
				} else if (data[0]==1&&data[1]==1) {
					for (int i=0;i<5;i++) {
						if (k[i]==1) res[i] = 1;
						else res[i] = 2;
					}
				} else if (data[0]==1&&data[2]==1) {
					for (int i=0;i<5;i++) {
						if (k[i]==1) res[i] = 2;
						else res[i] = 1;
					}
				} else if (data[1]==1&&data[2]==1) {
					for (int i=0;i<5;i++) {
						if (k[i]==2) res[i] = 1;
						else res[i] = 2;
					}
				} else {
					for (int i=0;i<5;i++) res[i] = 3;
				}
				for (int i=0;i<5;i++) System.out.println(res[i]);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 16972
import sys

input = sys.stdin.readline


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    N, M = [int(x) for x in input().split()]
    XYZ = [[int(x) for x in input().split()] for _ in range(M)]

    u = UnionFind(N)

    for x, y, z in XYZ:
        u.union(x - 1, y - 1)

    print(u.group_count())


if __name__ == '__main__':
    main()


Measured memory_bytes: 25936
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

ll pow5(ll a) {
  return a * a * a * a * a;
}

void solve() {
  ll x;
  scan(x);
  ll min_val = -1000;
  ll max_val = 1000;
  for (ll i = min_val; i < max_val; ++i) {
    for (ll j = i; j < max_val; ++j) {
      if (pow5(j) - pow5(i) == x) {
        printf("%lld %lld\n", j, i);
        return;
      }
    }
  }
  assert (false);
}

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


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

int main(){
    int x, a, b;

    cin >> x >> a >> b;
    if (abs(x - a) < abs(x - b))
        cout << "A" << endl;
    else
        cout << "B" << endl;
      
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





//Dinic O(EV^2)
#define MAX_V 20000
struct edge{ 
	int to, cap, rev;
	edge(int a, int b, int c) :to(a), cap(b), rev(c){}
};

vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];

void add_edge(int from, int to, int cap){
	G[from].push_back(edge(to, cap, G[to].size()));
	G[to].push_back(edge(from, 0, G[from].size() - 1));
}
//sからの最短距離をbfsで計算
void bfs(int s){
	memset(level, -1, sizeof(level));
	queue<int> que;
	level[s] = 0;
	que.push(s);
	while (!que.empty()){
		int v = que.front(); que.pop();
		for (int i = 0; i<G[v].size(); i++){
			edge &e = G[v][i];
			if (e.cap > 0 && level[e.to] < 0){
				level[e.to] = level[v] + 1;
				que.push(e.to);
			}
		}
	}
}
//増加パスをdfsで探す
int dfs(int v, int t, int f){
	if (v == t)return f;
	for (int &i = iter[v]; i<G[v].size(); i++){
		edge &e = G[v][i];
		if (e.cap > 0 && level[v] < level[e.to]){
			int d = dfs(e.to, t, min(f, e.cap));
			if (d>0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s, int t){
	int flow = 0;
	for (;;){
		bfs(s);
		if (level[t]<0)return flow;
		memset(iter, 0, sizeof(iter));
		int f;
		while ((f = dfs(s, t, INF))>0){
			flow += f;
		}
	}
}

int h,w;
char a[100][100];
int n;


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

	cin>>h>>w;
	rep(y, h)rep(x, w)cin >> a[y][x];

	int sy,sx,gy,gx;
	rep(y, h)rep(x, w){
		if (a[y][x] == 'S')sy = y, sx = x;
		else if (a[y][x] == 'T')gy = y, gx = x;
	}
	if (sy==gy || sx==gx){
		cout<<-1<<endl;
		return 0;
	}
	n = h*w;

	rep(y, h)rep(x, w){
		if (a[y][x]=='.')continue;

		int idx = y*w+x;
		add_edge(idx, n + idx, a[y][x]=='S'?INF:1);
		rep(i, h)if (i!=y && a[i][x]!='.')
			add_edge(n + idx, i*w+x, 1);
		rep(i, w)if (i != x && a[y][i] != '.')
			add_edge(n + idx, y*w + i, 1);
	}
	cout << max_flow(sy*w+sx, gy*w+gx)<<endl;





	return 0;
}

Measured memory_bytes: 62592
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

template<class T> inline vector<pair<T, int>> factoring(T n) {
	using p = pair<T, int>;
	using vp = vector<p>;
	vp res;
	T k = n;
	if (n % 2 == 0) {
		res.push_back(p(2, 1));
		n /= 2;
		while (n % 2 == 0) {
			res[0].second++;
			n /= 2;
		}
	}
	for (T i = 3; i <= n && i * i <= k; i += 2) {
		if (n % i == 0) {
			res.push_back(p(i, 1));
			n /= i;
			while (n % i == 0) {
				res.back().second++;
				n /= i;
			}
		}
	}
	if (n != 1) {
		res.push_back(p(n, 1));
	}
	return res;
}

ll func(ll n, ll k) {
	while (n >= k) {
		if (n % k == 0) {
			n /= k;
		} else {
			n %= k;
		}
	}
	return n;
}

template<typename T>
vector<T> divisor(T n) {
	vector<T> res1;
	vector<T> res2;

	for (T i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			res1.push_back(i);
			if (i != n / i) {
				res2.push_back(n / i);
			}

		}
	}
	RREP(i, res2.size()) {
		res1.push_back(res2[i]);
	}
	return res1;
}

int main() {
	IOS;
	ll n;
	cin >> n;
	//ll res = 1;
	set<int> st;
	auto d1 = divisor(n - 1);
	for (auto&& v : d1) {
		if (v > 1) {
			st.insert(v);
		}
	}
	auto d2 = divisor(n);
	for (auto&& v:d2) {
		if (v>1&&func(n, v) == 1) {
			st.insert(v);
		}
	}
	put(st.size());
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
using namespace std;
map <string,int> cost;
multimap <string,string>  rule;
set <string> his,his2;

void update(string a){
  his2.insert(a);
  multimap<string,string>::iterator it=rule.find(a);
  while(it != rule.end() && it->first == a) {
    if(his2.count(it->second)==0&&cost[it->second]>cost[a])cost[it->second]=cost[a], update(it->second);
    it++;
  }
}
int  mk_rule(string a){
  if(his.count(a) == 0){
    his.insert(a);    
    multimap<string,string>::iterator it=rule.find(a);
    while(it != rule.end() && it->first == a) cost[a]= min(cost[a],mk_rule(it->second)),it++;
    his2.clear() , update(a);
  }
  return cost[a];
}

int main(){
  int n,m,b;
  cin >> n;
  string a,c,ls[5002];
  for(int i=0;i<n;i++) {
    cin >> a >> b;
    cost[a] = b , ls[i] = a;
  }
  cin >> m;
  for(int i=0;i<m;i++){
    cin >> a >> c;
    rule.insert(pair<string,string>(a,c));
    rule.insert(pair<string,string>(c,a));
  }
  int ans=0;
  for(int i=0;i<n;i++) ans += mk_rule(ls[i]);
  cout << ans <<endl;
  return 0;
}

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

int main(){
    long long A,B,C,X,Y;
    cin>>A>>B>>C>>X>>Y;

    long long price = X*A + Y*B;
    long long tmp = 0;
    long long tmp2 = max(X,Y)*2;
    for( long long i=1;i<=tmp2;i++){
        if(i<=min(X,Y)){
            tmp = (X-i) *A + (Y-i)*B + C*2*i;
        }
        else if(i<=max(X,Y)){
            if(X<=Y){
                tmp = (Y-i)*B + C*2*i;
            }
            else{
                tmp = (X-i)*A + C*2*i;                
            }
        }
        else{
            tmp = C*2*i;
        }   
        
        // tmp = (X-i) *A;
        // if(tmp<0){
        //     cout<<"A"<< i<<' '<<endl;
        //     break;
        // }
        // tmp = (Y-i)*B;
        // if(tmp<0){
        //     cout<<"B"<< i<<' '<<endl;
        //     break;
        // }
        // tmp = C*2*i;
        // if(tmp<0){
        //     cout<<"C"<< i<<' '<<endl;
        //     break;
        // }
        price = min(price, tmp);
        // cout<<i<<' '<<endl;
        // if(price<0) break;

    }

    cout << price<<endl;


    return 0;
}

Measured memory_bytes: 256
import sys
N = int(input())
slist = [int(input()) for _ in range(N)]
ssum = sum(slist)
if ssum % 10 == 0:
    slist.sort()
    for s in slist:
        if  s % 10 != 0:
            print(ssum - s)
            sys.exit()
    print(0)
else:
    print(ssum)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;

int main(){
    int N, K; cin >> N >> K;
    string S; cin >> S;
    vector<int> V;
    int cnt=1;
    for(int i = 1; i <= N; i++){
        if(i == N) {
            if(S[i-1] == '0') cnt *= -1;
            V.push_back(cnt);
            break;
        }
        if(S[i-1] == S[i]) cnt++;
        else if(S[i-1] != S[i]){
            if(S[i-1] == '0') cnt *= -1;
            V.push_back(cnt);
            cnt=1;
        }
    }
    cnt = 0;
    int r = 0;
    ll ans=0;
    ll MAX=0;

    for(int l = 0; l < V.size(); l++){
        while(cnt <= K && r < V.size()){
            //cout << ans << endl;
            if(V[r] < 0) {
                if(cnt==K) break;
                else {ans+= V[r]*(-1); cnt++;}
            }
            else ans+= V[r];
            r++;
        }
        //cout << l << " " << r <<  " " << ans << endl;
        MAX = max(ans, MAX);
        if(V[l] < 0) {ans+=V[l]; cnt--;}
        else ans-=V[l];
        if(r == V.size()) break;
        
    }
    cout << MAX << endl;
}

Measured memory_bytes: 1020
A=[]
B=[[0,0,0],[0,0,0],[0,0,0]]
bseq=[]
for i in range(3):
    a,b,c=map(int,input().split())
    A.append([a,b,c])
n=int(input())
for i in range(n):
    bseq.append(int(input()))
    
for i in range(n):
    for j in range(3):
        for k in range(3):
            if A[j][k]==bseq[i]:
                B[j][k]=1
bingo=0
if B[0][0]==1 and B[0][1]==1 and B[0][2]==1:
    bingo+=1
if B[1][0]==1 and B[1][1]==1 and B[1][2]==1:
    bingo+=1
if B[2][0]==1 and B[2][1]==1 and B[2][2]==1:
    bingo+=1
if B[0][0]==1 and B[1][0]==1 and B[2][0]==1:
    bingo+=1
if B[0][1]==1 and B[1][1]==1 and B[2][1]==1:
    bingo+=1
if B[0][2]==1 and B[1][2]==1 and B[2][2]==1:
    bingo+=1
if B[0][0]==1 and B[1][1]==1 and B[2][2]==1:
    bingo+=1
if B[2][0]==1 and B[1][1]==1 and B[0][2]==1:
    bingo+=1
if bingo>=1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3188
N, M, X = gets.split.map(&:to_i)
bits = [0, 1].repeated_permutation(N).to_a
note = []
ans = Float::INFINITY
N.times do |i|
	note << gets.split.map(&:to_i)
end

(bits.length).times do |i|
	skill = Array.new(M,0)
	cost = 0
	
	N.times do |j|
		if bits[i][j] == 1
			M.times do |k|
				skill[k] += note[j][k+1]
			end
			cost += note[j][0]
		end
	end
	if skill.all? {|v| v >= X }
		if ans > cost
			ans = cost
		end
	end
end

if ans == Float::INFINITY
	p -1
else
	p ans
end

Measured memory_bytes: 15064
S = input()

S = S[::-1]

check = ["maerd", "remaerd", "esare", "resare"]

ind = 0
f = True

while True:
    if ind == len(S):
        f = True
        break
    if S[ind:ind+5] in check:
        ind += 5
    elif S[ind:ind+6] in check:
        ind += 6
    elif S[ind:ind+7] in check:
        ind += 7
    else:
        f = False
        break

if f:
    print('YES')
else:
    print("NO")

Measured memory_bytes: 9152
#include <iostream>
#include <stdint.h>
#include <utility>
#include <limits.h>
#include <map>
#include <vector>
#include <iomanip>

using namespace std;

using Year = int;
using Line = int;
using PrefId = int;
using CityNumber = int;
using CityId = pair<PrefId,CityNumber>;
using CityMap = map<Year,Line>;
using PrefCityMap = map<PrefId,CityMap*>;
using CityIdMap = map<Line,CityId>;

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

  PrefCityMap pref_city_map; // Npref : MAPcities
  for (int n=1; n<=N; ++n) {
    pref_city_map.emplace(n,new map<int,int>());
  }

  for (int m=0; m<M; ++m) {
    int p, y;
    cin >> p >> y;

    pref_city_map[p]->emplace(y,m);
  }

  vector<CityIdMap*> city_id_maps;
  for (auto& x : pref_city_map) {
    PrefId pref_id = x.first;
    CityMap* city_map = x.second;
    CityIdMap* city_id_map = new CityIdMap;
    CityNumber city_number = 1;
    for (auto& city_info : *city_map) {
      Year year = city_info.first;
      Line line = city_info.second;
      city_id_map->emplace(line,make_pair(pref_id,city_number++));
    }
    city_id_maps.push_back(city_id_map);
  }

  CityIdMap city_id_map;
  for (auto x: city_id_maps)
    city_id_map.insert(x->begin(),x->end());

  for (auto x: city_id_map) {
    cout << setw(6) << setfill('0') << x.second.first;
    cout << setw(6) << setfill('0') << x.second.second << endl;
  }
  
  return 0;
}

Measured memory_bytes: 39412
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d", &tmp);v.push_back(tmp);}}
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

int main(){

  string s, t;
  cin >> s >> t;
  int len = s.length();
  int alpha_s[27] = {}, alpha_t[27] = {};
  REP(i,len){
    alpha_s[s[i]-'a']++;
    alpha_t[t[i]-'a']++;
  }
  REP(i,len){
    if(alpha_s[s[i] - 'a'] != alpha_t[t[i]-'a']){
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
  return 0;
}



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

int main(){
	string s;
	cin>>s;
	int a=0,b=0;
	rep(i,s.size()){
		if(s[i]=='0'+i%2)a++;
		else b++;
	}
	cout << min(a,b)<<endl;
}


Measured memory_bytes: 512
#include<stdio.h>
#define N 100

int main(){
  int n;
  int p[N+1];
  int m[N+1][N+1];
  int i;
  
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&p[i-1]);
    scanf("%d",&p[i]);
  }

  int j,k,l;
  
  for(i=1;i<=n;i++) m[i][i] = 0;
    
    for(l=2;l<=n;l++){
      for(i=1;i<=n-l+1;i++){
	j = i + l -1;
	m[i][j] = 1000000000;
	for(k=i;k<=j-1;k++){
	  m[i][j] = min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
	}
      }
      
    
  }

  printf("%d\n",m[1][n]);

  return 0;
}

int min(a,b){
  int c;
  c = a;
  if(a>b) c = b;
  return c;
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define INF 1000000000000000
#define fi first
#define se second
#define all(v) v.begin(),v.end()
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
struct edge{int to,cost;};
typedef pair<int,int> P;
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
int kaijo(int n){
	int ans=1;
	for(int i=2;i<=n;i++){
		ans*=i;
		ans%=MOD;
	}
	return ans;
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	return modpow(a,b/2)*modpow(a,b/2)%MOD;
}
int comb(int a,int b){
	return kaijo(a)*modpow(kaijo(a-b),MOD-2)%MOD*modpow(kaijo(b),MOD-2)%MOD;
}
signed main(){
	int r,g;
	cin>>r>>g;
	cout<<g*2-r<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)
#define INF 1<<29;


int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    
    vector<int> d(n);
    rep(i,n) d[i] = (a[i]-(i+1));
    sort(d.begin(),d.end());
    int b = d[n/2];
    i64 sum = 0;
    rep(i,n) sum += abs(a[i]-(b+i+1)); 
    
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;

// 最大公約数
ll gcd(ll a, ll b)
{
   if (a%b == 0) {
       return(b);
   } else {
       return(gcd(b, a%b));
   }
}

// 最小公倍数
ll lcm(ll a, ll b){
   return a / gcd(a, b) * b;
}

//素数判定
bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された
    if(n % 2 == 0 || n % 3 == 0) return false;
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // (6の倍数)-1
        if(n % (i+2) == 0) return false; // (6の倍数)+1
    }
    return true;
}

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

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

//配るdp
void solve() {
    ll n; cin >> n;
    ll h[100100];
    Rep(i, 1 ,n) cin >> h[i];

    ll dp[100100];
    Rep(i, 1, 100100) dp[i] = INF;
    dp[1] = 0;
    for (int i = 1; i < n; ++i) {
        chmin(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
        chmin(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
    }
    cout << dp[n] << endl;
}

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

    solve();
    return 0;
}


Measured memory_bytes: 1792
N=int(input())
S=input()
MOD=10**9+7
x=dict()
for s in S:
    x[s]=x.get(s,0)+1
retval=1
for c in x:
    retval*=(x[c]+1)
    retval=retval%MOD
print((retval-1)%MOD)

Measured memory_bytes: 39664
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
	int N,K; cin>>N>>K;
	set<int> D;
	for(int i=0;i<K;i++){
		int tmp; cin>>tmp;
		D.insert(tmp);
	}
	while(true){
		string S=to_string(N);
		bool pro=true;
		for(int i=0;i<S.size();i++){
			if(D.count(S[i]-'0')){
				pro=false;
				break;
			}
		}
		if(pro)break;
		N++;
	}
	cout<<N<<endl;
}

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

int main()
{
  int n;
  double x=1.0;
  int i=0;
  int ans=0;
  scanf("%d",&n);
  
  while(1)
  {
    x=pow(2,i);
    
    if(n<x*2)
    {
      ans=x;
      break;
    }
    
    i++;
  }
  
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>

int main(){

int n;

scanf("%d",&n);
char x;
getchar();
bool ok = false;
for(int i=0;i<n;i++){
scanf("%c ",&x);
if(x=='Y') ok = true;
}

if(ok) printf("Four\n");
else printf("Three\n");

return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<int>
#define vvint vector<vint>
#define P pair<int,int>
#define INT_MAX 2147483647
#define MOD 1000000007
using namespace std;
typedef long long ll;



int main(void) {
	int a, b, k; cin >> k >> a >> b;

	for (int i = a; i <= b; i++) {
		if (i % k == 0) {
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;
	return 0;

}


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

int main () {
  int N, K, ans;
  cin >> N >> K;
  ans = 1;
  
  for (int i = 0; i < N; i++) {
    int A, B;
    A = ans * 2;
    B = ans + K;
    if (A >= B) {
      ans = B;
    }
    else if (A < B) {
      ans = A;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>

int main() {
long long n, m;
scanf("%lld%lld", &n, &m);

if (n == 1 && m == 1) puts("1");
else if (n == 1 || m == 1) printf("%lld\n", n * m - 2);
else printf("%lld\n", (n - 2) * (m - 2));

return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(void)
{
    int m1, m2, m3;
    int t;
    int i;
    
    m1 = 2;
    m2 = 1;
    m3 = 0;
    
    for ( i = 0 ; i < 10; i++) {
        scanf("%d", &t);
        
        if ( t > m1 ) {
            m3 = m2;
            m2 = m1;
            m1 = t;
        } else if( m1 >= t && t > m2) {
            m3 = m2;
            m2 = t;
        } else if( m2 >= t && t > m3) {
            m3 = t;
        } else {
            
        }
    }
    printf("%d\n", m1);
    printf("%d\n", m2);
    printf("%d\n", m3);

    return 0;
}

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

int main(){
  string o, s, ans="";
  cin >> o >> s;

  int size=o.size()+s.size();
  for (int i=0; i<size/2; i++) {
      ans+=o[i];
      ans+=s[i];
  }
  if (size%2!=0) {
    ans+=o[o.size()-1];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m,v0;
int a,b,c;
vector<P> G[501];
ll dp[501][51][2];

struct data{
	int v,f;
	ll c,sp;
	data(){}
	data(int vv,ll ss,ll cc,int ff){
		v=vv;
		sp=ss;
		c=cc;
		f=ff;
	}
	bool operator<(const data &d)const{
		return c>d.c;
	}
};

ll dijkstra(){
	memset(dp,-1,sizeof(dp));
	priority_queue<data> que;
	que.push(data(1,v0,0,0));
	dp[1][v0][0]=0;
	while(que.size()){
		data q=que.top();
		que.pop();
		if(dp[q.v][q.sp][q.f]<q.c)continue;
		if(q.v==n)q.f=1;
		if(q.v==1 && q.f==1)return q.c;
		for(int i=0;i<G[q.v].size();i++){
			int nv=(a*q.sp+b)%c;
			if(dp[G[q.v][i].first][nv][q.f]>q.c+q.sp*G[q.v][i].second){
				dp[G[q.v][i].first][nv][q.f]=q.c+q.sp*G[q.v][i].second;
				que.push(data(G[q.v][i].first,nv,dp[G[q.v][i].first][nv][q.f],q.f));
			}
			if(dp[G[q.v][i].first][nv][q.f]==-1){
				dp[G[q.v][i].first][nv][q.f]=q.c+q.sp*G[q.v][i].second;
				que.push(data(G[q.v][i].first,nv,dp[G[q.v][i].first][nv][q.f],q.f));
			}
		}
	}
	return -1;
}

int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int f,t;
		ll c;
		scanf("%d%d%lld",&f,&t,&c);
		G[f].push_back(P(t,c));
		G[t].push_back(P(f,c));
	}
	scanf("%d",&v0);
	scanf("%d%d%d",&a,&b,&c);
	printf("%lld\n",dijkstra());
	return 0;
}

Measured memory_bytes: 9512
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int N,M,C;
    vector<int> B(100);
    int answer = 0;
    cin >> N >> M >> C;
    for(int i = 0;i < M;i++){
        cin >> B.at(i);
    }
    for(int i = 0;i < N;i++){
        int W = 0;
        vector<int> A(100);
        for(int j = 0;j < M;j++){
            cin >> A.at(j);
            W += B.at(j) * A.at(j);
        }
        if(W + C > 0){
            answer++;
        }
    }
    cout << answer << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#include <utility>
#include <climits>
#include <numeric>
#define ll long long
#define INF INT_MAX 
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << a*b/2 << endl;
}

Measured memory_bytes: 256
N = int(input())
As = list(map(int,input().split()))
sums = 0
moder = 1000000007
s=[0 for i in range(N-1)]
s[-1] = As[-1]
for i in range(N-2):
  s[-(i+2)] = s[-(i+1)]+As[-(i+2)]

for i in range(N-1):
  sums+= (As[i]*s[i])%moder
print(sums%moder)

Measured memory_bytes: 107024
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let input_vec = read_vec::<i64>();
    let n = input_vec[0];
    let l = input_vec[1];

    let sum = n * (n + 1) / 2 + (l - 1) * n;

    if l == 0 || l <0 && 0 <= l + n - 1 {
        println!("{}", sum);
    } else if l < 0 && l + n - 1 < 0 {
        println!("{}",sum - l - n + 1);
    } else {
        println!("{}",sum - l);
    }

    //if l == 0 {
    //    println!("{}", sum);
    //} else if l < 0 {
    //    if 0 <= l + n - 1 {
    //        println!("{}", sum);
    //    } else {
    //        println!("{}",sum - l - n + 1);
    //    }
    //} else {
    //    println!("{}",sum - l);
    //}
    
}


Measured memory_bytes: 4352