akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main(){
        long long x;
        cin >> x;
        long long hp = 0;
        hp += x/500 * 1000;
        int resto = x % 500;
        if(resto){
                hp += resto/5 * 5;
        }
        cout << hp << '\n';
}

Measured memory_bytes: 256
import collections

n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]
money = []
for plus in collections.Counter(s).most_common():
    if plus[0] in t:
        money.append(plus[1] - collections.Counter(t).get(plus[0]))
    else:
        money.append(plus[1])
if max(money) < 0:
    print(0)
else:
    print(max(money))

Measured memory_bytes: 9352
N = int(input())
stone = list(map(str,input()))
ind = [""]*2
ind[0] = list()
ind[1] = list()
R = 0
W = 0
for i in range(N):
    if(stone[i]=="W"):
        ind[0].append(i)
        W += 1
    else:
        ind[1].append(i)
        R += 1
newR = 0
for i in range(R):
    if(i != ind[1][i]):
        break
    newR+= 1


newind =list(reversed(ind[1]))
ans2 = 0

# print(W,R,newR)
# print(ind[1],newind)
if(newR != R):
    ans1 = min(W,R-newR)
else:
    ans1 = min(W,R)
if(ans1 != 0):
    for i in range(N//2):
        if(ind[0][i]>newind[i]):
            break
        ans2+=1
        # print(ans)
print(min(ans1,ans2))


Measured memory_bytes: 20324
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

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

	int n;
	cin >> n;
	vector<int> x(n);
	vector<int> y(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i == j) continue;
			int dx = x[i] - x[j];
			int dy = y[i] - y[j];
			int save = 0;
			for (int f = 0; f < n; f++) {
				int nx = x[f] + dx;
				int ny = y[f] + dy;
				int any = 0;
				for (int s = 0; s < n; s++) {
					if (nx == x[s] && ny == y[s]) {
						any = 1;
					}
				}
				save += any;
			}
			ans = max(ans, save);
		}
	}
	cout << n - ans << '\n';
}

Measured memory_bytes: 3156
X , Y , Z , K = map(int ,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ab_value = []
value = []
flag = False

for a in A:
    for b in B:
        ab_value.append(a + b)

ab_value.sort(reverse = True)
ab_value = ab_value[:K + 1]
C.sort(reverse = True)
i = 0
for k in ab_value:
    for c in C:
        value.append(c + k)
value.sort(reverse= True)
for i in range(K):
    print(value[i])

Measured memory_bytes: 151384
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int N,D;
    double wa=0;
    int count=0;
    float sqrtwa;
    cin >> N >> D ;
    vector<int> X(N*D);
    for (int i = 0; i < N*D ; i++) {
        std::cin >> X.at(i);
    }
    for (int m = 0; m < N-1; m++)
    {
        for (int n = m+1; n < N; n++)
        {
            for (int j = 0; j < D; j++)
            {
                int po =X[m*D+j];
                int pi =X[n*D+j];
                wa = wa+double(abs(po-pi)*abs(po-pi));
            }
            sqrtwa=sqrt(wa);
            if (sqrtwa == int(sqrtwa))
            {
                count++;
            }
            wa=0;       
        }
    }
    cout << count;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const ll inf = 1e16;
const ll mod=1000000007;
typedef pair<ll,ll> pi;

void solve()
{
 ll n;
 string s;
 cin>>n>>s;
 ll ans=0;
 ll c=0;
 for(ll i=n-1;i>=0;i--)
 {
     if(s[i]=='R') c++;
 }
 for(ll i=0;i<n;i++)
 {
     if(s[i]=='R')
     {
         if(i>=c) ans++;
     }
 }
cout<<ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    t=1;
    for(ll i=1;i<=t;i++)
    {
        solve();
        cout<<endl;

    }
    return 0;
}

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

struct Dice {
  int f[6];

  void roll(char ch) {
    if (ch == 'N') {
      int t = f[0];
      f[0] = f[1];
      f[1] = f[5];
      f[5] = f[4];
      f[4] = t;
    } else if (ch == 'E') {
      int t = f[0];
      f[0] = f[3];
      f[3] = f[5];
      f[5] = f[2];
      f[2] = t;
    } else if (ch == 'W') {
      int t = f[0];
      f[0] = f[2];
      f[2] = f[5];
      f[5] = f[3];
      f[3] = t;
    } else if (ch == 'S') {
      int t = f[0];
      f[0] = f[4];
      f[4] = f[5];
      f[5] = f[1];
      f[1] = t;
    }
  }

  int top() {
    return f[0];
  }
};

int main() {
  Dice d;

  for (int i = 0; i < 6; i++) cin >> d.f[i];

  string str;
  cin >> str;

  for (int i = 0; i < str.size(); i++) {
    char ch = str[i];
    d.roll(ch);
 }

  cout << d.top() << endl;
  return 0;
}



Measured memory_bytes: 3200
n=int(input())

result=[0]

for i in range(n):
    a,b=map(int,input().split())
    if(a!=b):
        result.append(0)
    else:
        result.append(result[-1]+1)

for i in range(1,n+1):
    if(result[i]==3):
        print("Yes")
        break
    if(i==n):
        print("No")

Measured memory_bytes: 62584
// In the name of God

#include <bits/stdc++.h>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> v(n);
	for(int i=0;i<n;i++) {
		cin >> v[i];
	}
	vector<int> ans;
	for(int i=0;i<n;i++) {
		if(ans.size() < v[i]-1) {
			cout << -1;
			exit(0);
		}
		ans.insert(ans.begin()+v[i]-1, v[i]);
	}
	for(int i=0;i<n;i++) cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;

public class Main{

    public static void main(String[] args){
        //START

        Scanner sc=new Scanner(System.in);
        int H1=sc.nextInt();
        int M1=sc.nextInt();
        int H2=sc.nextInt();
        int M2=sc.nextInt();
        int K=sc.nextInt();

        int h=(H2-H1)*60;
        int m=(M2-M1);

        int sum=h+m-K;

        System.out.println(sum);

        //END
    }
}



Measured memory_bytes: 35800
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){


}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
    z->parent = y;

    if(y == NIL) root = z;
    else if(z->key < y->key) y->left = z;
    else y->right = z;

}

void inorder(Node u){
  if(u->left != NIL) inorder(u->left);
  printf(" %d",u->key);
  if(u->right != NIL) inorder(u->right);
}
void preorder(Node u){
  printf(" %d",u->key);
  if(u->left != NIL) preorder(u->left);
  if(u->right != NIL) preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 25148
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.141592653589793238;

int main() {
  double a, b, x, ans;
  cin >> a >> b >> x;
  x /= a;
  if (a * b / 2 < x)  // 水多めパターン
    ans = atan(((a * b - x) * 2 / a) / a);
  else  // 少なめ
    ans = atan(b / (x * 2 / b));
  cout << fixed << setprecision(10) << ans * 180 / PI << endl;
}


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

int H,W;
char S[310][310],T[710][710];
int R[710][710] = {{0}},C[710][710] = {{0}};

int main(){
	cin >> H >> W;
	for(int i=0;i<=709;i++){
		for(int j=1;j<=709;j++){
			T[i][j] = '.';
		}
	}
	for(int i=1;i<=H;i++){//適当に回転
		for(int j=1;j<=W;j++){
			cin >> S[i][j];
			T[i-j+350][i+j] = S[i][j];
		}
	}
	for(int i=1;i<=700;i++){
		for(int j=1;j<=700;j++){
			if(T[i][j]=='#'){
				C[i][j]++; R[i][j]++;
			}
		}
	}
	for(int i=1;i<=700;i++){//横の累積和
		for(int j=1;j<=700;j++){
			C[i][j] += C[i][j-1];
		}
	}
	for(int i=1;i<=700;i++){//縦の累積和
		for(int j=1;j<=700;j++){
			R[i][j] += R[i-1][j];
		}
	}
	int ans = 0;
	for(int i=1;i<=700;i++){//横の#のペアの計算
		for(int j=1;j<700;j++){
			if(T[i][j]=='.') continue;
			for(int k=j+1;k<=700;k++){
				if(T[i][k]=='#'){
					int d = k-j;
					if(i-d>=0) ans += C[i-d][k-1]-C[i-d][j-1];
					if(i+d<=700) ans += C[i+d][k]-C[i+d][j];
				}
			}
		}
	}
	for(int j=1;j<=700;j++){//縦の#のペアの計算
		for(int i=1;i<700;i++){
			if(T[i][j]=='.') continue;
			for(int k=i+1;k<=700;k++){
				if(T[k][j]=='#'){
					int d = k-i;
					if(j-d>=0) ans += R[k][j-d]-R[i][j-d];
					if(j+d<=700) ans += R[k-1][j+d]-R[i-1][j+d];
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 4864
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=200000+10;
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
int a[maxn];
int cnt[maxn];
int f[maxn];
int ans;
int main(){
	int n=read(),m=read();
	for(int i=1;i<=n;i++)
		a[i]=read(),cnt[a[i]]++;
	for(int i=1;i<=n;i++)
		for(int j=0;j<cnt[i];j++)
			 f[max(i-j,1)]++;
	for(int i=1;i<=n;i++)
		if(!f[i])
			ans++;
	while(m--){
		int x=read(),y=read();
		int u=a[x];
		a[x]=y;
		x=u;
		f[max(x-cnt[x]+1,1)]--;
		if(f[max(x-cnt[x]+1,1)]==0) ans++;
		cnt[x]--;
		f[max(y-cnt[y],1)]++;
		if(f[max(y-cnt[y],1)]==1) ans--;
		cnt[y]++;
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 3712
#ALDS_1_1_D Maximum Profit

N=int(input())
A=[]
for i in range(N):
    A.append(int(input())) 
MIN= A[0]
MAX= A[1]-A[0]
for i in range(1,N):
    MAX=max(MAX,A[i]-MIN)
    MIN=min(MIN,A[i])
print(MAX)


Measured memory_bytes: 13592
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
        double [] in = new double [a];
        double ans = 0;
        for(int i=0;i<a;i++){in[i]=sc.nextDouble();}
		for(int i=0;i<a;i++){ans+=1/in[i];}
        ans = 1/ans;
		System.out.println(ans);
	}
}


Measured memory_bytes: 23252
#include <stdio.h>

int main()
{
    int h, w, n, j, hasil=0;
    scanf("%d%d%d", &h,&w,&n);
    if(h>w){
        j=h;
    }else{
        j=w;
    }
    for(int i=0;i<n;i=i+j){
        hasil++;
    }
    printf("%d\n", hasil);
    return 0;
}

Measured memory_bytes: 1708
A = list(map(int, input().split()))
S = A[1]
S += (A[0] // 2) * 2 + (A[3] // 2) * 2 + (A[4] // 2) * 2
if A[3] % 2 == 1 and A[4] % 2 == 1 and A[0] % 2 == 1:
  S += 3
elif A[3] % 2 == 1 and A[4] % 2 == 1 and A[0] % 2 == 0 and A[0] != 0:
  S += 1
elif A[3] % 2 == 0 and A[4] % 2 == 1 and A[0] % 2 == 1 and A[3] != 0:
  S += 1
elif A[3] % 2 == 1 and A[4] % 2 == 0 and A[0] % 2 == 1 and A[4] != 0:
  S += 1
print(S)


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

using namespace std;
typedef long long ll;
const int MAXN = 100100;

int N;
ll M, V, P;
ll arr[MAXN];
ll ps[MAXN];

int main()
{
    ios_base::sync_with_stdio(0);
    
    cin >> N >> M >> V >> P;
    for (int i = 0; i < N; i++)
        cin >> arr[i];
    sort (arr, arr + N);
    reverse (arr, arr + N);

    ps[0] = 0;
    for (int i = 0; i < N; i++)
        ps[i+1] = ps[i] + arr[i];

    int ans = 0;
    int cstart = P - 1;
    for (int i = 0; i < N; i++)
    {
        int nget = (N - i) + (P - 1);
        if (nget >= V)
        {
            if (arr[i] + M >= arr[P-1])
                ans++;
        }
        else
        {
            while (cstart < i && arr[cstart] > arr[i] + M)
                cstart++;

            ll cadd = (i - cstart) * ((ll) arr[i] + M) - (ps[i] - ps[cstart]);
            if (arr[i] + M >= arr[P-1] && cadd >= (V - nget) * M)
                ans++;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 1792
N = int(input())
print(0, flush=True)
s0 = input()
if s0 == 'Vacant':
    exit()
l = 0
r = N-1

while r - l > 1:
    m = (l+r) // 2  # 中央値のクエリを送る
    print(m, flush=True)
    s = input()
    if s == 'Vacant':
        exit()
    if m % 2 == 1:  # r-lが奇数であることと同義
        if s != s0:  # 異性ならば
            l = m  # 前半部分に空席はないから下限をあげる
        else:  # 同性ならば
            r = m  # 前半部分に空席があるので上限を下げる
    else:  # r-lが偶数であることと同義
        if s != s0:  # 異性ならば
            r = m  #
        else:  # 同性ならば
            l = m
print(r, flush=True)
sr = input()


Measured memory_bytes: 3660
from collections import deque

h,w=map(int,input().split())

maze=[list(input()) for i in range(h)]


dx=[1,-1,0,0]
dy=[0,0,1,-1]

Q=deque()

for i in range(h):
  for j in range(w):
    if maze[i][j]=='#':
      Q.append((i,j,0))


while Q:
  x,y,z=Q.popleft()
  for i in range(4):
    nx=x+dx[i]
    ny=y+dy[i]

    if 0<=nx<h and 0<=ny<w and maze[nx][ny]=='.':
      Q.append((nx,ny,z+1))
      maze[nx][ny]='#'


print(z)


Measured memory_bytes: 215312
import java.util.Scanner;

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

		String s = sc.next();
		char[] c = s.toCharArray();
		String ans = "Good";

		for (int i = 0; i < 3; i++) {
			if (c[i] == c[i + 1])
				ans = "Bad";
		}
		System.out.println(ans);

	}

}


Measured memory_bytes: 23892
#include <iostream>
 
using namespace std;
 
int main(){
  int W, H, x, y, r;
 
  cin >> W >> H >> x >> y >> r;
  if(x-r < 0 || x+r > W || y-r < 0 || y+r > H){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
 
  return 0;
}

Measured memory_bytes: 3100
#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>;

int main(){
    int N, K; cin >> N >> K;
    queue<int> Q;
    rep(i, K){
        int a; cin >> a;
        Q.push(a);
    }
    rep(i, N-K){
        int a; cin >> a;
        Q.push(a);
        if(Q.front() < Q.back()) cout << "Yes" << endl;
        else cout << "No" << endl;
        Q.pop();
    }
}


Measured memory_bytes: 4316
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

set<vector<int> > sv;
// vv[k] := 3個以上の合計が10になる饅頭の組合せ
vector<vector<int> > vv;
// v_sum[k] := vv[k]の合計
int v_sum[40] = {0};
// memo[k] := k 番目の組合せで饅頭が作れない
bool memo[40];

// v := 饅頭の集合, sum := v[0] + v[1] + ... + v[v.size()-1] (合計)
void f(vector<int> v, int sum = 0){
	if( sum == 10 ){
		if( 3 <= v.size() ){ 
			sort(v.begin(), v.end());
			sv.insert(v);
		}
	}else if( sum < 10 ){
		for(int i = 9; i >= 1 ; i-- ){
			v.push_back(i);
			f(v, sum + i);
			v.pop_back();
		}
	}
}

// 3個以上で10になる饅頭の組合せを事前に列挙しておく
void init(){
	vector<int> v;
	f(v);
	for(set<vector<int> >::iterator it = sv.begin() ; it != sv.end() ; ++it ){
		vv.push_back(*it);
	}
	for(int i = 0 ; i < vv.size() ; i++ ){
		int sum = 0;
		for(int j = 0 ; j < vv[i].size() ; j++ ){
			sum += vv[i][j];
		}
		v_sum[i] = sum;
	}
}

// v[k](k番目の合計が10になる組合せ)が使えるかどうかを返す
bool check(int k, vector<int> s){
	for(int i = 0 ; i < vv[k].size() ; i++ ){
		int e = vv[k][i];
		if( s[e] == 0 ){
			return false;
		}else{
			s[e]--;
		}
	}
	return true;
}

// v[k](k番目の合計が10になる組合せ)を使う
void used(int k, vector<int> &s){
	for(int i = 0 ; i < vv[k].size() ; i++ ){
		int e = vv[k][i];
		if( s[e] ) s[e]--;
	}
}

int foo;

set<vector<int> > mm;

// DFS
void dfs(int &res, int cnt, int sum, vector<int> &s){
	// 解の更新
	res = max(res, cnt);
	
	if( mm.count(s) ) return;
	
	if( foo < 100000 ){
		mm.insert(s);
	}
	
	foo++;
	//if( 7500000 < foo ) return;
	
	if( sum < 10 ) return;
	// もう解が更新できない時点で探索打ち切る
	if( cnt + sum / 10 <= res ) return;
	
	for(int i = 0 ; i < vv.size() ; i++ ){
		if( memo[i] ) continue;
		
		if( check(i, s) ){
			vector<int> s_ = s;
			used(i, s_);
			dfs(res, cnt + 1, sum - v_sum[i], s_);
		}
	}
}

int solve(vector<int> &s){
	foo = 0;
	int sum = 0, res = 0;
	for(int i = 0 ; i < vv.size() ; i++ ){
		if( !check(i, s) ){
			memo[i] = true;
		}
	}
	
	mm.clear();
	for(int i = 1 ; i <= 9 ; i++ ) sum += i * s[i];
	dfs(res, 0, sum, s);
	return res;
}

int main(){
	// 3個以上で10になる饅頭の組合せを事前に列挙しておく
	init();
	
	int n;
	while( cin >> n, n ){
		
		// s[k] := 重さkの饅頭の個数
		vector<int> s(12, 0);
		fill(memo, memo + 40, false);
		
		for(int i=0 ; i < n ; i++ ){
			int e;
			cin >> e;
			s[e]++;
		}
		
		int ans = 0;
		// 2個で10になる組合せは貪欲に使う
		for(int i = 1 ; i <= 4 ; i++ ){
			int j = 10 - i;
			int k = min(s[i], s[j]);
			s[i] -= k;
			s[j] -= k;
			ans += k;
		}
		ans += s[5]/2;
		s[5] %= 2;
		// 3個以上で10になる組合せを探索する
		ans += solve(s);
		// 出力
		cout << ans << endl;
	}	
}

Measured memory_bytes: 1456
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
//#include <bits/stdc++.h>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;

string yn(bool x){
    return x ? "Yes" : "No";
}
int main(){
    int a,b,k; cin >> a >> b >> k;
    set<int> x;
    
    for(int i =a ; i<a+k and i<=b ; i++){
        x.insert(i);
    }
    for(int i=(b-k+1>=a ? b-k+1 : a) ; i<=b ; i++){
        x.insert(i);
    }
    
    for(auto itr = x.begin() ; itr !=x.end() ; itr++){
        cout << *itr << endl;
    }
    
}






Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int N = 1e5 + 10;
int f[N], d[N];

ii find(int x) {
  if (f[x] == f[f[x]]) {
    return {f[x], d[x]};
  }
  ii ret = find(f[x]);
  f[x] = ret.first;
  d[x] += ret.second;
  return {f[x], d[x]};
}

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) f[i] = i;
  bool found = false;
  while (m--) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    --x; --y;
    ii tx = find(x), ty = find(y);
    int rx = tx.first, ry = ty.first;
    int dx = tx.second, dy = ty.second;
    if (rx != ry) {
      f[ry] = rx;
      d[ry] = dx - dy + z;
    } else {
      if (dx + z != dy) found = true;
    }
  }
  puts(found ? "No" : "Yes");
  return 0;
}


Measured memory_bytes: 1024
H,W,N=map(int,raw_input().split())
XY=[]
for i in range(N):
    XY.append(map(int,raw_input().split()))

XY.sort()

conditions=[2,1]
for xy in XY:
    if xy[0]>conditions[0]:
        conditions=[xy[0],conditions[1]+xy[0]-conditions[0]]
    if conditions[1]>=xy[1]:
        print xy[0]-1
        break
    if xy[1]==conditions[1]+1:
        conditions=[conditions[0],conditions[1]-1]
else:
    print H

Measured memory_bytes: 41192
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#define INT_MAX 999999999
#define ll long long int
#define mod 1000000007
using namespace std;
int main()
{
    ll n;
    cin>>n;
    vector<ll> a(n);
    ll s =0;
    for(ll i = 0; i< n; i++)
       {
            cin>>a[i];
            s+=a[i];
       } 
    ll dp[n][n];
    for(ll i =0; i< n; i++)
    {
        dp[i][i] = a[i];
    }
    for(ll L = 2; L<=n; L++)
    {
        for(ll i = 0; i< n-L+1; i++)
        {
            ll j = i+L-1;
            ll x = (i+2) <= j ? dp[i+2][j] : 0;
            ll y = (i+1) <= (j-1) ?  dp[i+1][j-1] : 0;
            ll z = i <= (j-2) ? dp[i][j-2] : 0;

            dp[i][j] = max(a[i] + min(x, y), a[j] + min(y, z));
        }
    }
    ll yy = s - dp[0][n-1];
    cout<<dp[0][n-1] - yy<<endl;

}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	EACH(x,vec) is >> x;
	return is;
}
/*
template<class... T>
ostream& operator<<(ostream& os, tuple<T...>& t) {
	for (size_t i = 0; i < tuple_size< tuple<T...> >::value; ++i) {
		if (i) os << " ";
		os << get<0>(t);
	}
	return os;
}
*/
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
	REP(i,vec.size()) {
		if (i) os << " ";
		os << vec[i];
	}
	return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
	REP(i,vec.size()) {
		if (i) os << endl;
		os << vec[i];
	}
	return os;
}

template <typename T>
class SegmentTree {
  using func_t = function<T(T, T)>;
  const int n;
  const T id;
  func_t merge;
  vector<T> data;
  T sub(int l, int r, int node, int lb, int ub) {
    if (ub <= l || r <= lb) return id;
    if (l <= lb && ub <= r) return data[node];
    T vl = sub(l, r, node * 2 + 0, lb, (lb + ub) / 2);
    T vr = sub(l, r, node * 2 + 1, (lb + ub) / 2, ub);
    return merge(vl, vr);
  }
  int size(int n) {
      int res;
      for (res = 1; res < n; res <<= 1);
      return res;
  }
public:
  SegmentTree(int n, T id, func_t merge) :
    n(size(n)), id(id), merge(merge), data(size(n) * 2, id) {}
  void update(int p, T val) {
    assert (0 <= p && p < n);
    p += n;
    data[p] = val;
    while (p /= 2) {
      int l = p * 2, r = p * 2 + 1;
      data[p] = merge(data[l], data[r]);
    }
  }
  T find(int l, int r) {
    return sub(l, r, 1, 0, n);
  }
};

int main() {
  int n, q, com, x, y;
  cin >> n >> q;
  SegmentTree<int> seg(n, 0x7FFFFFFF, [](int a, int b){return min(a, b);});
  while (q--) {
    cin >> com >> x >> y;
    if (com) cout << seg.find(x, y+1) << endl;
    else seg.update(x, y);
  }
  return 0;
}

Measured memory_bytes: 3896
H,W = map(int,input().split())

A = [[c=='#' for c in input()] for _ in range(H)]

dp = [[False]*W for _ in range(H)]

dp[0][0] = True
def solve():

    s = sum(sum(l) for l in A)
    if s != H+W-1:
        return False

    for d in range(1,H+W):
        if d < W:
            dp[0][d] = dp[0][d-1] and A[0][d]
        if d < H:
            dp[d][0] = dp[d-1][0] and A[d][0]
        for i in range(1,d):
            j = d-i
            if i >= H or j >= W:
                continue
            dp[i][j] = A[i][j] and (dp[i-1][j] or dp[i][j-1])

    return dp[-1][-1]

print('Possible' if solve() else 'Impossible')

Measured memory_bytes: 61932
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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

const int INF = 1e7;
const int num_max = 401;
int dp[41][401][401];
int a[41], b[41], c[41];
int
main(void){  
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int n, ma, mb;
  cin >> n >> ma >> mb;
  REP(i, n) cin >> a[i] >> b[i] >> c[i];

  //n+1番目までちゃんと初期化する
  REP(i, n+1) REP(j, num_max) REP(k, num_max) dp[i][j][k] = INF;

  dp[0][0][0] = 0;
  REP(i, n){
    REP(j, num_max){
      REP(k, num_max){
	if(dp[i][j][k] == INF) continue; 
	chmin(dp[i+1][j][k], dp[i][j][k]);
	chmin(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k]+c[i]);	
      }
    }
  }

  ll ans = INF;
  //1番目からやる
  FOR(j,1,num_max) FOR(k,1,num_max) if(j*mb==k*ma) ans = min((int)ans, dp[n][j][k]);

  if(ans == INF) ans = -1;
  cout << ans << endl;
  
  return 0;
}

/*
デバッグポイント
- 初期化が全部できてるかチェック
- ループの境界条件チェック
- 漸化式チェック
- 最後の結果集計部分チェック
 */


Measured memory_bytes: 25984
n,m=gets.split.map &:to_i
a=[]
b=[]
ar=[]
n.times do
  r = Array.new(m)
  g = gets.split.map{|e|e.to_i-1}
  g.length.times do |i|
    r[g[i]]=i
  end
  a<< r
  b<< g
  ar << g[0]
end
br=[true]*m
cr=[0]*n
max = 0
maxx = 10**9
if m==1
  maxx=n
else
(m-1).times do |i|
  h = Hash.new(0)
  ar.each do |e|
    h[e]+=1
  end
  max = -1
  maxe = nil
  h.each do |e,v|
    if v>max
      max = [max,v].max
      maxe = e
    end
  end
  br[maxe]=false
  ar.length.times do |ii|
    if ar[ii] == maxe
      while true do
        cr[ii]+=1
        if br[b[ii][cr[ii]]]
          ar[ii]=b[ii][cr[ii]]
          break
        end
      end
    end
  end
  maxx = [maxx,max].min
end
end
p maxx
  
  

Measured memory_bytes: 6140
N=int(input())
s=[]
for k in range(N):
    s.append([None]*10)
    l=input()
    for j in range(10):
        s[k][j]=l[j]
    s[k].sort()
s.sort()
a=0
r=0
for i in range(N-1):
    if s[i]==s[i+1]:
        r+=1
    elif r!=0:
        a+=r*(r+1)//2
        r=0
a+=r*(r+1)//2
print(a)

Measured memory_bytes: 100184
#include<iostream>
using namespace std;
int main(){
	int n,i,j,i2;
	cin>>n;
	if(n<4)
		cout<<1;
	for(i=n;i>=1;i--){
		for(j=2;j<i;j++){        //因数查找 
			i2=i;
			while(i2%j==0){    
				i2/=j; 
				if(i2==1){
					cout<<i;
					return 0;
				}
			}
		}
	}
	return 0;
} 

Measured memory_bytes: 256
import Control.Monad.ST
import Data.Char
 
 
readInt :: IO Int
readInt = read <$> getLine :: IO Int
 
readIntSplit :: IO [Int]
readIntSplit = map read . words <$> getLine :: IO [Int]
 
readStr :: IO String
readStr = getLine
 
readStrSplit :: IO [String]
readStrSplit = map read . words <$> getLine

solve :: String -> String
solve "ABC" = "ARC"
solve "ARC" = "ABC"

main = do
  s <- readStr
  putStrLn $ solve s

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

int main() {
   while (1) {
      string s;
      getline(cin, s);
      if (s==".") break;

      stack<char> stk;
      int cnt = 0;
      bool ok = false;
      int n = s.size();
      for (int i = 0; i < n; i++) {
         if (s[i] == '(') stk.push(s[i]);
         if (s[i] == '[') stk.push(s[i]);
         if (s[i] == ')') {
            if (stk.empty() || stk.top() != '(') {
               ok = true;
               break;
            } else {
               stk.pop();
            }
         }
         if (s[i] == ']') {
            if (stk.empty() || stk.top() != '[') {
               ok = true;
               break;
            } else {
               stk.pop();
            }
         }
      }
      if (stk.empty() && !ok) {
         puts("yes");
      } else {
         puts("no");
      }
   }
}


Measured memory_bytes: 3176
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import comb

# 再帰がやばいとき
# import sys
# sys.setrecursionlimit(10**9)

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

# field[H][W]
def create_grid(H, W, value = 0):
    return [[ value for _ in range(W)] for _ in range(H)]

########
    
def main():
    N, K = l_inpl()

    if K == 0:
        print(N*N)
        return

    ans = 0
    for b in range(1, N+1):
        if b < K:
            continue
        p = N//b
        r = N%b
        ans += max(b-K, 0) * p + max(r-K+1, 0)
    print(ans)
if __name__ == "__main__":
    main()


Measured memory_bytes: 39280
# temp
n,w = map(int,input().split())
wv = [tuple(map(int,input().split())) for i in range(n)]

dp = [0] + [float("inf")]*(10**5)
for i in range(n):
    for j in range(10**5,wv[i][1]-1,-1):
        dp[j] = min(dp[j],dp[j-wv[i][1]]+wv[i][0])

res = 0
for v,e in enumerate(dp):
    if e <= w:
        res = v
print(res)

Measured memory_bytes: 93244
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int>d(n);  
  
  for(int i = 0; i < n; i++) cin >> d[i];
  /*
  int l, i = 0;
  while(cin>>l){
   	d[i]=l;
    i++;
  }
  */
  
  sort(d.begin(), d.end());
  int answer = d[d.size()/2] - d[d.size()/2 - 1];
  
   cout << answer << endl;

	return 0; 
}

 /*
 //長さがわからないとき
  while(cin>>l){
   	d[i]=l;
    i++;
  }
  
*/

Measured memory_bytes: 640
#include<stdio.h>
int main(void){
	int a,b,c,d,p,ans;
	scanf("%d %d %d %d %d",&a,&b,&c,&d,&p);
	ans=b;
	if(c<=p){
		ans+=d*(p-c);
	}
	if(a*p>ans){
		printf("%d\n",ans);
	}
	else {
		printf("%d\n",a*p);
	}
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int n;
    string s;
    cin >> n >> s;
    if (n % 2 == 1) {
        cout << "No" << endl;
    } else {
        int half = n/2;
        if (s.substr(0, half) == s.substr(half, half))
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> primeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	ll n, ans, s;
	in(n);


	ans = n / 1.08;

	while ((ll)(ans * 1.08) <= n) {
		if ((ll)(ans * 1.08) == n) {
			outn(ans);
			return 0;
		}
		ans++;
	}

	outn(":(");

	return 0;


}


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

int main() {
    int n, q; cin >> n >> q;
    string s; cin >> s;
    vector<int> l(q), r(q);
    rep(i, q) {
        cin >> l[i] >> r[i];
        l[i]--;
        r[i]--;
    }
    vector<int> cnt(n);
    for (int i = 1; i < s.size(); i++) {
        if (s[i] == 'C' && s[i-1] == 'A') {
            cnt[i] = cnt[i-1] + 1;
        }
        else {
            cnt[i] = cnt[i-1];
        }
    }
    rep(i, q) {
        cout << cnt[r[i]] - cnt[max(l[i], 0)] << endl;
    }
}


Measured memory_bytes: 4492
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long a,b,c,d,ans1,ans2,ans3,ans4;
  cin >> a >> b >> c >> d;
  ans1 = a*c;
  ans2 = b*d;
  ans3 = a*d;
  ans4 = b*c;
  cout << max(max(ans1,ans2),max(ans3,ans4)) << endl; 
  return 0;
} 

Measured memory_bytes: 3632
import math
import bisect
#[int(x) for x in input().split()]
#map(int,input().split())
#for _ in range(int(input())):
a,b=input().split()
a=int(a)
b=list(b.split("."))
b=''.join(b)
b=int(b)

print(a*b//100)

Measured memory_bytes: 61964
#include<stdio.h>
int main(){
    int p,q,r;
    scanf("%d %d %d", &p, &q, &r);
    
    if(p+q<=p+r && p+q <=q+r){
        printf("%d\n",p+q);
    }else if(p+r<=p+q && p+r<=q+r){
        printf("%d\n",p+r);
    }else if(q+r<=p+q && q+r<=p+r){
        printf("%d\n",q+r);
    }

    return 0;
}

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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amin(T& a,T2 b){ if(a > b) a = b;}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	string s;
	cin >>n >>s;
	VI sd(2*n);
	rep(i, 2*n) sd[i] = s[i%n]=='o'? 0: 1;
	rep(i, 4){
		VI ck(2*n+2, -1);
		ck[0] = i&1; ck[1] = (i>>1) &1;
		rep2(i, 1, 2*n){
			if(ck[i] == sd[i] ) ck[i+1]=ck[i-1];
			else ck[i+1] = ck[i-1] ^ 1;
		}

		bool ok=true;
		rep(i, n) if(ck[i] != ck[i+n]) ok=false;
		//for(auto x :ck) cerr<<x<<" "; dbg("::", ok);
		if(ok){
			rep(i, n) cout <<(ck[i]==0? 'S':'W');
			cout <<"\n";
			return 0;
		}
	}
	puts("-1");
	return 0;
}


Measured memory_bytes: 2000
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
int n;
vector<P> g[100005];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  REP(i, n - 1) {
    int u, v, w;
    cin >> u >> v >> w;
    u--; v--;
    g[u].push_back(P(v, w));
    g[v].push_back(P(u, w));
  }

  vector<int> ans(n);
  ans[0] = 0;

  queue<tuple<int, int, int>> que;
  que.push({0, -1, 0});

  while(!que.empty()) {
    int now, from, color;
    tie(now, from, color) = que.front(); que.pop();
    for(P u : g[now]) {
      if(u.first == from) continue;
      int n_color = (color + u.second) % 2;
      ans[u.first] = n_color;
      que.push({u.first, now, n_color});
    }
  }

  REP(i, n) cout << ans[i] << endl;
}


Measured memory_bytes: 9576
/********************************************************
  **░██████╗██╗░░░░░░█████╗░██╗░░░██╗██╗░█████╗░░██████╗░**
  **██╔════╝██║░░░░░██╔══██╗██║░░░██║██║██╔══██╗██╔════╝░**
  **╚█████╗░██║░░░░░███████║╚██╗░██╔╝██║██║░░╚═╝██║░░██╗░**
  **░╚═══██╗██║░░░░░██╔══██║░╚████╔╝░██║██║░░██╗██║░░╚██╗**
  **██████╔╝███████╗██║░░██║░░╚██╔╝░░██║╚█████╔╝╚██████╔╝**
  **╚═════╝░╚══════╝╚═╝░░╚═╝░░░╚═╝░░░╚═╝░╚════╝░░╚═════╝░**
  *********************************************************/

#include <bits/stdc++.h>
using namespace std;


#define ll                          long long
#define ld                          long double

#define forn(i,n)                   for(int i=0;i<n;++i)
#define all(v)                      v.begin(), v.end()
#define rall(v)                     v.rbegin(),v.rend();
#define isSubstring(s1,s2)          s1.find(s2) != std::string::npos
	
#define pb                          push_back
#define pf                          push_front
#define mp                          make_pair
#define fr                          first
#define sc                          second

#define vpi                         <vector<pair<int,int>>
#define vi                          vector<int>
#define sz(a)                       (int)a.size()

#define   endl                       "\n"
#define     nl                       cout<<"\n";
#define fastio                       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define MN                           INT_MIN
#define MX                           INT_MAX

bool isPrime(ll n){if(n<2)return false;for(ll x = 2;x*x <=n;x++){if(n%x == 0)return false;}return true;}
bool isPerfectSquare(long double x){long double sr=sqrt(x);return((sr-floor(sr))==0);}
int gcd(int a, int b){if(a==0)return b;if(b==0) return a;if(a==b)return a;if(a>b)return gcd(a-b,b);return gcd(a,b-a);} 


int32_t main()
{
	string s,t;
	int cnt= 0 ;
	cin >> s >> t;
	for(int i =0 ;i<sz(s);i++)
	{
		if(s[i] == t[i])cnt++;
	}
	cout <<cnt<<endl;
}

Measured memory_bytes: 3584
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int w[123];

int main(void){
	int n,i,ans,s=0,t=0;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> w[i];
		s += w[i];
	}
	ans = s;
	for(i=0; i<n; ++i){
		t += w[i];
		ans = min(ans,abs(s-t*2));
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;


bool isPrime(int x){
    if(x == 2){
        return true;
    }
    if(x == 1 || x % 2 == 0){
        return false;
    }

    for(int i = 3;i < sqrt(x) + 1;i++){
        if(x % i == 0){
            return false;
        }
    }
    return true;

}

int main(){
    int N;
    cin >> N;
    int prime = 0;
    for(int i = 0;i < N;i++){
        int x;
        cin >> x;
        if(isPrime(x)){
            prime++;
        }
    }
    cout << prime << endl;
}



Measured memory_bytes: 3076
#https://atcoder.jp/contests/yahoo-procon2019-qual/tasks/yahoo_procon2019_qual_d
#2019-02-10

#DP

L = int(input())
A = [int(input()) for i in range(L)]

DP = [0 for i in range(5)]

def cost(s, a):
    if s == 0 or s == 4:
        return a
    elif s == 1 or s == 3:
        if a > 0:
            return a%2
        else:
            return 2
    else:
        return (a+1)%2

for i in range(L):
    n = [min(DP[:i+1]) for i in range(5)]
    a = A[i]
    DP[0] = n[0] + cost(0, a)
    DP[1] = n[1] + cost(1, a)
    DP[2] = n[2] + cost(2, a)
    DP[3] = n[3] + cost(3, a)
    DP[4] = n[4] + cost(4, a)



print(min(DP))

Measured memory_bytes: 11040
sx, sy, tx, ty = map(int, input().split())
dire = ["", "U", "L", "R", "D"]
dire_f = []
dire_s = [2]
a = []
b = []
c = []
d = []
for i in range(abs(ty-sy)):
    dire_f.append((ty-sy)//abs(ty-sy))
for i in range(abs(sx-tx)):
    dire_f.append(((sx-tx)//abs(sx-tx))*2)
for i in range(abs(ty-sy)+1):
    dire_s.append((ty-sy)//abs(ty-sy))
for i in range(abs(sx-tx)+1):
    dire_s.append(((sx-tx)//abs(sx-tx))*2)
dire_s.append(-1)
for i in range(len(dire_f)):
    a.append(dire[dire_f[i]])
    b.append(dire[dire_f[i]*(-1)])
for i in range(len(dire_s)):
    c.append(dire[dire_s[i]])
    d.append(dire[dire_s[i]*(-1)])
print("".join(a+b+c+d))


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

#define ll long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;

ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
int main() {
    //COMint();
    ll N=in();
    ll T=in();
    ll t[N];
    ll ans;ans=0;
    REP(i,N){
        cin>>t[i];
    }
    ll endyu;endyu=T;
    for(int i=1;i<N;i++){
        if(t[i]>t[i-1]+T){
            ans+=T;
        }else{
            ans+=t[i]-t[i-1];
        }
    }
    ans+=T;
    print(ans);
}

Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 12 09:35:02 2018
ABC105D
@author: maezawa
"""
import collections
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = [0]
b0 = 0
for i in a:
    b0 += i
    b.append(b0)
    
bmodm = list(map(lambda x: x%m, b))
c = collections.Counter(bmodm)
#print(b)
#print(bmodm)
#print(c)

cnt = 0
for nm in c.values():
    cnt += nm*(nm-1)//2
print(cnt)

Measured memory_bytes: 18852
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18

ll mod = 1e9+7;
  
int main() {
	// 入力
	ll N;cin>>N;
    ll A[N];REP(i,N){
        cin>>A[i];A[i]--;
    }
    ll B[N];REP(i,N){
        cin>>B[i];
    }
    ll C[N-1];REP(i,N-1){
        cin>>C[i];
    }

	// 解法
    ll ans = 0;
    REP(i,N){
        ans += B[A[i]];
        if (i!=0 & A[i-1]+1==A[i]){
            ans += C[A[i-1]];
        }
    }
    
	//出力
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
#include <cctype>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<long long>
#define vvl vector<vector<long long>>

using namespace std;

typedef long long ll;

int main()
{
  int n;
  cin >> n;
  vector<string> w(n);
  REP(i, n)
  {
    cin >> w[i];
  }
  REP(i, n)
  {
    if (i != 0)
    {
      if (w[i].front() != w[i - 1].back())
      {
        cout << "No" << endl;
        return 0;
      }
    }
    REP(h, n)
    {
      if (i != h && w[i] == w[h])
      {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

int main(){
  int a,b;
  vector<int> c(3);
  cin >> a >> b;
  c.at(0) = a-b;
  c.at(1) = a+b;
  c.at(2) = a*b;
  sort(c.begin(),c.end());
  cout << c.at(2);
}
  

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

int main() {
 long int A,B,C,D;
  cin >> A >> B >> C >>D; 
 long int LCM;
 long int r;
 long int x = min(C,D);
 long int y = max(C,D);
  
  do{
    r = y % x;
    y = x;
    x = r;
  }
  while(r!=0);
  
  LCM = C* D/y;
     
  cout << B-(A-1)-B/C - B/D + B/LCM +(A-1)/C +(A-1)/D -(A-1)/LCM <<endl;
  
  return 0;
}
  

Measured memory_bytes: 256
h, w = map(int, input().split())
mp = [list(map(int, input().split())) for _ in range(h)]
ans = 10 ** 20
for i in range(h):
  for j in range(w):
    s = 0
    for y in range(h):
      for x in range(w):
        s += min(abs(y - i), abs(x - j)) * mp[y][x]
    ans = min(ans, s)
print(ans)


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

int main() {
  string S, T;
  cin >> S >> T;

  vector<int> first(26, -1);
  vector<int> second(26, -1);
  rep(i, S.size()) {
    int x = S[i] - 'a';
    int y = T[i] - 'a';
    if (first[x] != -1 || second[y] != -1) {
      if (first[x] != y || second[y] != x) {
        cout << "No" << endl;
        return 0;
      }
    }
    else {
      first[x] = y;
      second[y] = x;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 776