akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    int a;
    cin >> a;
    int b;
    cin >> b;
    int n;
    cin >> n;
    int c;
    if(a > b){
        c = a;
    }
    else {
        c = b;
    }int i = 1;
    while(true){
        if(i * c >= n)break;
        i++;
    }
    cout << i << endl;
    return 0;
}

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

int main()
{
	int N;
	std::string S;
	std::cin >> N >> S;
	int pos[2]{};
	for (auto& e: S)
	{
		if ('A' <= e && e <= 'M') pos[1]++;
		else if ('N' <= e && e <= 'Z') pos[1]--;
		else if ('a' <= e && e <= 'm') pos[0]++;
		else pos[0]--;
	}
	char dir[2]{'a', 'A'};
	if (pos[0] < 0) dir[0] += 13;
	if (pos[1] < 0) dir[1] += 13;
	printf("%d\n", std::abs(pos[0]) + std::abs(pos[1]));
	pos[0] = std::abs(pos[0]);
	pos[1] = std::abs(pos[1]);
	for (int i{}; i < pos[0]; i++) putchar(dir[0]);
	for (int i{}; i < pos[1]; i++) putchar(dir[1]);
	putchar('\n');

	return 0;
}


Measured memory_bytes: 3464
#include<stdio.h>
#include<stdlib.h>
int asc(const void *a,const void *b){
    int x=*((int*)a),y=*((int*)b);
    if(x<y)return -1;
    else if(x==y)return 0;
    else return 1;
}
int main(){
    int a[3];for(int i=0;i<3;i++)scanf("%d",&a[i]);
    qsort(a,3,sizeof(int),asc);
    
    int sum=0;
    for(int i=0;i<2;i++){
        sum+=a[i+1]-a[i];
    }
    printf("%d\n",sum);
    return 0;
}

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

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main(){
  ll n ;
  cin >> n ;
  vector<int> A(100000,0)  ;
  A[0] = 0 ;
  int count = 0 ;
  rep(i,100){
    count += i ;
    A[count] = i ;
  }
  rep(i,100000) A[i+1] = max(A[i+1],A[i]) ;
  auto mp = prime_factor(n) ;
  ll ans = 0 ;
  for(auto p : mp ){
    ans += A[p.second] ;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3788
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <time.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

int main() {
	ll N, W, w, v, miw;
	vector<ll> V[4];
	cin >> N >> W;
	ll i, j, k, l;
	V[0].push_back(0ll);
	V[1].push_back(0ll);
	V[2].push_back(0ll);
	V[3].push_back(0ll);
	for (i = 0; i < N; i++) {
		cin >> w >> v;
		if (!i)miw = w;
		V[w - miw].push_back(v);
	}
	for (i = 0; i < 4; i++) {
		sort(V[i].begin()+1, V[i].end(), greater<ll>());
		for (j = 1; j < V[i].size(); j++) {
			V[i][j] += V[i][j - 1];
		}
	}
	ll ans = 0;
	for (i = 0; i < V[0].size(); i++) {
		for (j = 0; j < V[1].size(); j++) {
			for (k = 0; k < V[2].size(); k++) {
				for (l = 0; l < V[3].size(); l++) {
					if (miw*(i + j + k + l ) + j + 2 * k + 3 * l > W)continue;
					ans = max(ans, V[0][i] + V[1][j] + V[2][k] + V[3][l]);
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
main = do
  s <- getLine
  t <- getLine
  print $ solve s t

d x y = length . filter f $ zip x y
  where
    f (a, b) = a /= b

solve s@(_:ss) t | length s == length t = d s t
                 | otherwise = min ans $ solve ss t
  where
    ans = d t $ take (length t) s

Measured memory_bytes: 4820
N, M = map(int, input().split())
A = list(map(int, input().split()))
p = [[A[i], 1] for i in range(N)]   # Aのカードは各1枚ずつ

for i in range(M):
    B, C = map(int, input().split())
    p.append([C, B])    # CのカードをB枚追加

p.sort()
p.reverse()

ans = 0
cnt = N
for v, n in p:
    num = min(cnt, n)    # 残り枚数とvのカード枚数の少ない方を採用
    ans += v * num
    cnt -= num
    if cnt == 0:
        break

print(ans)


Measured memory_bytes: 34640
#include <bits/stdc++.h>
#define quick ios::sync_with_stdio(false);cin.tie(nullptr);
#define endl '\n';
using namespace std;
int main() {
  quick;
  int l;string st;
  cin >> l >> st;
  int r = 0;
  int w = 0;
  int sw = 0;
  for (int i = 0; i < l; ++i) {
    if (st[i] == 'W') { ++w;
    } else {
      ++r;}
  }
  int res = min(r, w);
  for (int i = 0; i < r; ++i) {
    if (st[i] == 'W') {
      ++sw;}
  }
  res = min(res, sw);

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 3728
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

int N;
int x[24], y[24], r[24], c[24];
int on[24];

#define SQ(x) ((x)*(x))
inline bool isIntersect(int i, int j) {
  return SQ(x[j]-x[i]) + SQ(y[j]-y[i]) < SQ(r[j]+r[i]);
}

inline bool isValid(int i, int S) {
  for(int j=0; j<i; j++) {
    if((on[i]>>j & 1) && !(S>>j & 1)) return false;
  }
  return true;
}

char memo[1<<24];
char dfs(int S, const int sum) {
  char& ret = memo[S];
  if(ret != -1) return ret;
  ret = sum;
  for(int i=0; i<N; i++) {
    if(S>>i & 1) continue;
    if(!isValid(i, S)) continue;
    for(int j=0; j<N; j++) {
      if(i == j) continue;
      if(c[i]!=c[j]) continue;
      if(S>>j & 1) continue;
      if(!isValid(j, S)) continue;
      ret = max(ret, dfs(S+(1<<i)+(1<<j), sum+2));
    }
  }
  
  return ret;
}

int main() {
  
  while(cin >> N && N) {
    for(int i=0; i<N; i++) {
      cin >> x[i] >> y[i] >> r[i] >> c[i];
      on[i] = 0;
      for(int j=0; j<i; j++) {
        if(isIntersect(i, j)) on[i] += 1<<j;
      }
    }
    memset(memo, -1, sizeof memo);
    cout << (int)dfs(0, 0) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 17552
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	char a,b,c,d;
	scanf("%c%c%c%c",&a,&b,&c,&d);
	int aa=a-'0',bb=b-'0',cc=c-'0',dd=d-'0';
	
	if(aa+bb+cc+dd==7) printf("%c+%c+%c+%c=7\n",a,b,c,d);
	else if(aa+bb+cc-dd==7) printf("%c+%c+%c-%c=7\n",a,b,c,d);
	else if(aa+bb-cc+dd==7) printf("%c+%c-%c+%c=7\n",a,b,c,d);
	else if(aa+bb-cc-dd==7) printf("%c+%c-%c-%c=7\n",a,b,c,d);
	else if(aa-bb+cc+dd==7) printf("%c-%c+%c+%c=7\n",a,b,c,d);
	else if(aa-bb+cc-dd==7) printf("%c-%c+%c-%c=7\n",a,b,c,d);
	else if(aa-bb-cc+dd==7) printf("%c-%c-%c+%c=7\n",a,b,c,d);
	else if(aa-bb-cc-dd==7) printf("%c-%c-%c-%c=7\n",a,b,c,d);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {
  int N, M, X;
  cin >> N >> M >> X;

  int count_left = 0;
  int count_right = 0;
  for (int i = 0; i < M; ++i) {
    int tmp;
    cin >> tmp;
    if (tmp > X) {
      ++count_right;
    } else {
      ++count_left;
    }
  }

  cout << min(count_right, count_left) << endl;

  return 0;
}

Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t H, W;
  cin >> H >> W;
  vector<vector<bool>> A(H, vector<bool>(W, false));
  for (int64_t r = 0; r < H; ++r) {
    string s;
    cin >> s;
    for (int64_t c = 0; c < W; ++c) {
      const char ch = s.c_str()[c];
      A[r][c] = (ch == '.');
    }
  }
  using DistancePosition = std::pair<int64_t, Pair>;
  vector<vector<int64_t>> distances(H, vector<int64_t>(W, INT64_MAX));
  priority_queue<Pair, vector<DistancePosition>, std::greater<DistancePosition>> q;
  const int64_t initial_distance = (A[H - 1][W - 1]) ? 0 : 1;
  q.push(DistancePosition(initial_distance, Pair(H - 1, W - 1)));
  while (q.size() > 0U) {
    const DistancePosition dp = q.top();
    q.pop();
    const int64_t c_distance = dp.first;
    const Pair c_position = dp.second;
    if (c_position.first == 0 && c_position.second == 0) {
      cout << c_distance << endl;
      break;
    }

    if (c_distance < distances[c_position.first][c_position.second]) {
      distances[c_position.first][c_position.second] = c_distance;

      vector<Pair> nexts;
      if (c_position.first - 1 >= 0) {
        nexts.push_back(Pair(c_position.first - 1, c_position.second));
      }
      if (c_position.second - 1 >= 0) {
        nexts.push_back(Pair(c_position.first, c_position.second - 1));
      }
      for (const auto next : nexts) {
        int64_t next_distance = c_distance;
        if (A[next.first][next.second] == false && A[c_position.first][c_position.second] == true) {
          ++next_distance;
        }
        q.push(DistancePosition(next_distance, next));
      }
    }
  }

  return 0;
}


Measured memory_bytes: 384
import java.util.*;

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

        long val = 100;
        long years = 0;
        while (val < X) {
            val = val + (val / 100);
            years++;
        }
        System.out.println(years);
    }
}


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

const int MXN = 100005;
vector<int> sub[MXN];
int depth[MXN];

int dep(int node) {
	
	if (depth[node] != -1) return depth[node];
	int mx = 0;
	for (int i=0; i<sub[node].size(); i++) {
		mx = max(mx, dep(sub[node][i]));
	}
	return depth[node] = mx + 1;
}

int main() {
	
	int n, m;
	cin >> n >> m;
	for (int i=0; i<m; i++) {
		int a, b;
		cin >> a >> b;
		sub[a].push_back(b);
	}
	for (int i=0; i<MXN; i++) depth[i] = -1;
	
	int mx = 0;
	for (int i=1; i<=n; i++) {
		mx = max(mx, dep(i));
	}
	cout << mx - 1 << endl;
	
}


Measured memory_bytes: 8192
import java.util.Scanner;
public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		new AOJ0578().doIt();
	}
	
	class AOJ0578{
		String board;
		void doIt(){
			int n = in.nextInt();
			board = in.next();
			int cnt = 0;
			for(int i=0;i<n;i++){
				if(result(in.next()))cnt++;
//				System.out.println(cnt);
			}
			System.out.println(cnt);
		}
		
		boolean result(String text){
//			System.out.println(text);
			for(int i=1;i<text.length();i++){//抜く数
				for(int s=0;s<text.length();s++){//start position
					StringBuffer sb = new StringBuffer();
					for(int k=s;k<text.length();k+=i){
						sb.append(text.charAt(k));
						if(sb.toString().equals(board))return true;
					}
					if(sb.toString().equals(board))return true;
				}
			}
			return false;
		}
		
	}
		
}

Measured memory_bytes: 89896
n_char::Char -> Int -> String
n_char c 0=[]
n_char c n=c:(n_char c (n-1))

type Coord = (Int,Int)

forth_1:: Coord -> Coord -> String
forth_1 (s_x,s_y) (t_x,t_y) = (n_char 'U' (t_y-s_y))++(n_char 'R' (t_x-s_x))

back_1:: Coord -> Coord -> String
back_1 (s_x,s_y) (t_x,t_y) = (n_char 'D' (t_y-s_y))++(n_char 'L' (t_x-s_x))

forth_2:: Coord -> Coord -> String
forth_2 (s_x,s_y) (t_x,t_y) = "L"++(n_char 'U' ((t_y-s_y)+1))++(n_char 'R' ((t_x-s_x)+1))++"D"

back_2:: Coord -> Coord -> String
back_2 (s_x,s_y) (t_x,t_y) = "R"++(n_char 'D' ((t_y-s_y)+1))++(n_char 'L' ((t_x-s_x)+1))++"U"

solver::Coord->Coord->String
solver s t = (forth_1 s t)++(back_1 s t)++(forth_2 s t)++ (back_2 s t)

main::IO()
main = do
  d<-getLine
  let s_x:s_y:t_x:t_y:[]= map read (words d) ::[Int]
  putStr (solver (s_x,s_y) (t_x,t_y))
  putStr "\n"

Measured memory_bytes: 1148
#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 A, B, m;
  cin >> A >> B >> m;
  vector<int> a(A), b(B);
  rep(i, A) cin >> a[i];
  rep(i, B) cin >> b[i];
  int cost = INF;
  rep(i, m) {
    int x, y, c;
    cin >> x >> y >> c;
    x--, y--;
    cost = min(cost, a[x] + b[y] - c);
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  cost = min(cost, a[0] + b[0]);
  cout << cost << endl;
  return 0;
}


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

int main(){
    string s;
    cin>>s;
    int c=0;
    for(int i=0;i<s.size();i++){
	if(s[i]=='o')
	    ++c;
    }
    int rem = 15-s.size();
    int req = 8-c;

    if(req>rem)
	cout<<"NO"<<endl;
    else
	cout<<"YES"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i = 0; i < n; i++)
#define rep2(i,start,end) for(ll i = start; i < end; i++)
#define dwn(i,n) for(int i = n; i >= 0; i--)
#define dwn2(i,start,end) for(ll i = start; i >= end; i--)
#define pll pair<ll,ll>
#define mk(x,y) make_pair(x,y)
#define pdl pair<double, ll>
const ll N = 4e5 + 200;
const ll INF = 0x3f3f3f;
const ll Mode = 1e9 + 7;


int main(){
	ll n;
	cin>>n;
	priority_queue<double, vector<double>, greater<double>> p;
	rep(i,n){
		ll x;
		cin>>x;
		p.push(x);
	}
	while(p.size() > 1){
		double x,y;
		x = p.top();
		p.pop();
		y = p.top();
		p.pop();
		p.push((x+y)/2.0);
	}
	cout<<p.top()<<endl;
	return 0;
}








Measured memory_bytes: 256
n = int(input())
h = list(map(int,input().split()))
max = max(h)
count = 0
for i in range(1,max+1):
    tmp_count = 0
    check = 0
    for j in h:
        if j >= i:
            if check == 0:
                tmp_count += 1
                check = 1
        else:
            check = 0
    count += tmp_count
print(count)

Measured memory_bytes: 38896
#include <bits/stdc++.h>
#define int long long
#define range(i,x,y) i=(x);i<(y);i++
#define all(x) begin(x),end(x)
#define lim(x,r,l) (r<=x&&x<l)
typedef long long ll;
typedef long double ld;
using namespace std;

signed main(){
  int n;
  while(cin >> n, n != 0){
    vector<vector<int>> p(n);
    for(int range(i,0,n)){
      int m;
      cin >> m;
      p[i] = vector<int>(m);
      for(int range(j,0,m)){
        cin >> p[i][j];
      }
      sort(all(p[i]));
    }
    int k;
    cin >> k;
    vector<int> l(k);
    for(int range(j, 0, k)){
      cin >> l[j];
    }
    sort(all(l));
    int id = -2;

    for(int range(i,0,n)){

      if(includes(all(p[i]), all(l))){
        if(id==-2){
          id = i;
        }else{
          id = -3;
        }
      }
    }
    cout << max(-1ll, id+1) << endl;
  }
}

Measured memory_bytes: 3176
N, M = gets.split.map(&:to_i)
L = N.times.map{0}
R = N.times.map{0}
M.times do
  l, r = gets.split.map {|c| c.to_i - 1}
  L[l] += 1
  R[r] += 1
end

ans = 0
gates = 0
N.times do |i|
  gates += L[i]
  ans += 1 if gates == M
  gates -= R[i]
end

puts ans

Measured memory_bytes: 3836
read*,i,j,k
if(j<i)then
n=i;i=j;j=n
endif
if(k<j)then
n=j;j=k;k=n
endif
if(j<i)then
n=i;i=j;j=n
endif
n=(k-i)/2+(k-j)/2;k=i+j+n+n-k-k
if(k==-1)then
n=n+2
else if(k==-2)then
n=n+1
endif
print"(i0)",n
end

Measured memory_bytes: 256
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))

ans = -1
sna = 1145141919810931893
for i, j in enumerate(h):
    temp = t - j * 0.006
    if abs(temp-a) < sna:
        sna = abs(temp-a)
        ans = i
print(ans + 1)

Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
    char W[11], T[1100];
    int i, count=0;
    scanf("%s", &W);
    while(scanf("%s", &T)) {
        if (strcmp(T,"END_OF_TEXT") == 0)  break;
        for(i=0; i < strlen(T); i++) T[i] = tolower(T[i]);
        if(strcmp(W,T) == 0) count++;
    }
    printf("%d\n", count);
    return 0;
}


Measured memory_bytes: 2088
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    string s[2];
    cin >> s[0];
    s[1] = s[0];
    int n = s[0].length();
    reverse(s[1].begin(), s[1].end());
    if (s[0] != s[1])
    {
        Yes(0);
        return 0;
    }
    string t[2], u[2];
    for (int i = 0; i < (n - 1) / 2; i++)
    {
        t[0] += s[0][i];
    }
    t[1] = t[0];
    reverse(t[1].begin(), t[1].end());
    if (t[0] != t[1])
    {
        Yes(0);
        return 0;
    }
    for (int i = (n + 3) / 2 - 1; i < n; i++)
    {
        u[0] += s[0][i];
    }
    u[1] = u[0];
    reverse(u[1].begin(), u[1].end());
    if (u[0] != u[1])
    {
        Yes(0);
        return 0;
    }
    Yes(1);
}

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

using namespace std;

int main(void)
{
    int n;
    int r[200000];
    int maxv = -1000000001;

    cin >> n;

    for(int i=0; i < n; i++)
    {
        cin >> r[i];
    }

    int minv = r[0];
    for(int i=1; i < n; i++)
    {
        maxv = max(maxv, r[i]-minv);
        minv = min(minv, r[i]);
    }

    cout << maxv << endl;

    return 0;
}

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

int main(){
  int N; cin >> N;
  string s;
  int count[5]={};
  for(int i=0; i<N; i++){
    cin >> s;
    switch(s[0]){
      case 'M': count[0]++; break;
      case 'A': count[1]++; break;
      case 'R': count[2]++; break;
      case 'C': count[3]++; break;
      case 'H': count[4]++; break;
    }
  }
  int pos=0,j=0;
  long long count2[5]={};
  for(int i=0; i<5; i++){
    if(count[i]>0){
      pos++;
      count2[j]=count[i];
      j++;
    }
  }
  if(count2[2]==0){
    cout << 0 << endl;
  }else if(count2[3]==0){
    cout << count2[0]*count2[1]*count2[2] << endl;
  }else if(count2[4]==0){
    cout << count2[0]*count2[1]*count2[2]+count2[0]*count2[1]*count2[3]+
      count2[0]*count2[2]*count2[3]+count2[1]*count2[2]*count2[3] << endl;
  }else{
    cout << count2[0]*count2[1]*count2[2]+count2[0]*count2[1]*count2[3]+
      count2[0]*count2[1]*count2[4]+count2[0]*count2[2]*count2[3]+
      count2[0]*count2[2]*count2[4]+count2[0]*count2[3]*count2[4]+
      count2[1]*count2[2]*count2[3]+count2[1]*count2[2]*count2[4]+
      count2[1]*count2[3]*count2[4]+count2[2]*count2[3]*count2[4] << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1e9;
const int64_t inf64=4e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}
 
using i64=int64_t;
 
void solve(){
    int N,K;
    cin >> N >> K;
 
    vector<int> x(N),y(N),xs(N),ys(N);
    rep(i,0,N){
        cin >> x[i] >> y[i];
        xs[i]=x[i];
		ys[i]=y[i];
    }
 
    sort(begin(xs),end(xs));
    sort(begin(ys),end(ys));
 
    i64 ans=inf64;
    rep(i,0,xs.size()) rep(j,i+1,xs.size()) rep(k,0,ys.size()) rep(l,k+1,ys.size()){
        int x1=xs[i],y1=ys[k],x2=xs[j],y2=ys[l];
        i64 s=i64(x2-x1)*i64(y2-y1);
        if(s>=ans) continue;
        
        int cnt=0;
        rep(i,0,N) if(x1<=x[i] and x[i]<=x2 and y1<=y[i] and y[i]<=y2) ++cnt;
        
        if(cnt>=K) ans=s;
    }
 
    cout << ans << endl;
}
 
int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 256
// "include" {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <tuple>
// }}}
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int> 
#define int long long
#define setout(n,x) setw(n) << setfill(x)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b;
	cin >> a >> b;
	if(b % a == 0) cout << a + b << '\n';
	else cout <<b - a << '\n';
	return 0;
}


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

#define pp push_back
#define pf push_front
#define mp make_pair
#define fs first
#define sc second
#define sf scanf

using namespace std;

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

const int N = (int) 123;
const int INF = (int) 1e9 + 7;

bool p[N];

int main(int argc, char *argv[])
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);

	int x, n;
	sf("%d %d", &x, &n);
	for (int i = 0; i < n; ++i) {
		int x;
		sf("%d", &x);
		p[x] = true;
	}
	int mn = INF;
	int ans = -1;
	for (int i = 0; i <= 101; ++i) {
		if (p[i]) continue;
		if (mn > abs(x - i)) {
			mn = abs(x - i);
			ans = i;
		}
	}

	for (int i = 0; i <= 101; ++i) {
		if (mn > abs(-i - x)) {
			mn = abs(-i - x);
			ans = -i;
		}
	}

	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 3828
N = int(input())
res = 0
def is753(N):
    n7,n5,n3 = 0,0,0
    while N > 0:
      if N % 10 == 7:
          n7 = 1
      elif N%10 == 5:
          n5 = 1
      else:
          n3 = 1
      N = N // 10
    return n5 & n3 & n7

def solve(D):
	if D > N:
		return 0
	else:
		d = 0
		if is753(D):
			d = 1
		return solve(D*10+3) +  solve(D*10+5) + solve(D*10+7) + d
print(solve(0))

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const int MAX = 128;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const int MOD = 1000000007;

int v[MAX];

void solve(void){
    while (1) {
        int n, r;
        scanf("%d %d\n", &n, &r);
        if (n == 0 && r == 0) break;
        rep(n, i) v[i] = n-i;
        rep(r, meaningless_) {
            int vv[n];
            rep(n, i) vv[i] = v[i];
            int p, c;
            scanf("%d %d\n", &p, &c);
            rep(c, j) {
                v[j] = vv[p-1+j];
            }
            rep(p-1, j) {
                v[c+j] = vv[j];
            }
        }
        printf("%d\n", v[0]);
    }
}

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



Measured memory_bytes: 3184
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000000)
from collections import defaultdict
mod = 10**9+7

N = int(input())
S = [int(x) for x in input()[:-1]]
left = defaultdict(lambda : [10**9]*10)
right = defaultdict(lambda : [-10**9]*10)
cnt = [0]*10
flg = [0]*10
for i, x in enumerate(S):
    if flg[x] == 0:
        flg[x] = 1
        left[x] = cnt[:]
    right[x] = cnt[:]
    cnt[x] += 1
ans = 0
for i in range(1000):
    a, b, c = i%1000//100, i%100//10, i%10
    if a == b:
        if right[c][b]-left[a][b] > 1:
            ans += 1
    elif right[c][b]-left[a][b] > 0:
        ans += 1
print(ans)


Measured memory_bytes: 3804
# -*- coding: utf-8 -*-

N,M = list(map(int, input().rstrip().split()))
ab_list = [list(map(int, input().rstrip().split())) for i in range(N)]
cd_list = [list(map(int, input().rstrip().split())) for i in range(M)]
#-----

for a,b in ab_list:
    dist = (10**8)*2*2 + 1
    
    for i,[c,d] in enumerate(cd_list):
        temp_dist = abs(a-c) + abs(b-d)
        
        if dist > temp_dist:
            dist = temp_dist
            check = i

    print(check+1)


Measured memory_bytes: 3060
# def gcd(a, b):
# 	while b:
# 		a, b = b, a % b
# 	return a

# def lcm(a, b):
# 	return a * b // gcd (a, b)

# def f(m, input):
#   r = 0
#   for i in input:
#     r += m % i
#   return r

N = map(int, input())
a_n = list(map(int, input().split(" ")))
# a_n = sorted(a_n)

max = 0
for x in a_n:
  max += x
 
# result = []
# for m in range(max):
  # out = f(m, a_n)
  # result.append(out)
# re = sorted(result)
#print(re[-1])
#print(max) #994 518 941 851 647 2 581 -> 4534
print(max - len(a_n))

Measured memory_bytes: 3316
using namespace std;



#include <iostream>
#include <vector>

typedef pair<int, int> P;
int main() {
  int N; cin >> N;
  bool al_pair[N];
  memset(al_pair, 0, sizeof(al_pair));
  
  vector<P> blue(N), red(N);
  
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    red[i] = P(y, x);
  }
  
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    blue[i] = P(x, y);
  }
  
  sort(blue.begin(), blue.end());
  sort(red.rbegin(), red.rend());
  
  int ans = 0;
  
  for (int b = 0; b < N; b++) {
    for (int r = 0; r < N; r++) {
      if (!al_pair[r] && blue[b].first > red[r].second && blue[b].second > red[r].first) {
        ans++;
        al_pair[r] = true;
        break;
      }
    }
  }
  
  
  cout << ans << endl;
  return 0;
}

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


int main() {
    string S; cin >> S;
    int half_len = S.size() / 2;
    int ans = 0;
    for (int i = 0; i < half_len; i++) {
        if (S[i] != S[S.size() - i - 1]) ans++;
    }

    cout << ans << endl;
    return 0;
}

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int K, N;
  cin >> K >> N;
  vector<int> A(N);
  REP(i, N) { cin >> A.at(i); }

  vector<int> dist(N + 1, 0);
  REPI(i, 1, N) { dist.at(i) = dist.at(i - 1) + (A.at(i) - A.at(i - 1)); };
  int longest_path = dist.at(N - 1);
  int ans = longest_path;
  int f_and_l = K - longest_path;

  REPI(i, 1, N - 1) {
    ans = min(ans, longest_path + f_and_l - (A.at(i) - A.at(i - 1)));
    ans = min(ans, longest_path + f_and_l - (A.at(i + 1) - A.at(i)));
  }
  ans = min(ans, longest_path + f_and_l - (A.at(1) - A.at(0)));
  ans = min(ans, longest_path + f_and_l - (A.at(N - 1) - A.at(N - 2)));

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
# D - Saving Snuuk
from heapq import heappop, heappush
INF = float('inf')
def dijkstra(s,n,g): # sからの最短距離 頂点数n g[v]=[(u1,w1),(u2,w2)....]:vからuへの有向辺があり、重みw
  que = []
  d = [INF for _ in range(n)]
  d[s] = 0
  heappush(que,(0,s))
  while len(que) > 0:
    p = heappop(que)
    v = p[1]
    if d[v] < p[0]:
      continue
    for u,w in g[v]:
      if d[u] > d[v]+w:
        d[u] = d[v]+w
        heappush(que,(d[u],u))
  return d

n,m,s,t = map(int,input().split())
s -= 1
t -= 1
ge = [[] for _ in range(n)]
gs = [[] for _ in range(n)]
for i in range(m):
  u,v,a,b = map(int,input().split())
  u -= 1
  v -= 1
  ge[u].append((v,a))
  ge[v].append((u,a))
  gs[u].append((v,b))
  gs[v].append((u,b))

de = dijkstra(s,n,ge)
ds = dijkstra(t,n,gs)
c = []
for i in range(n):
  c.append((de[i]+ds[i],i))
c.sort()
j = 0
for i in range(n):
  while(c[j][1] < i):
    j += 1
  print(10**15-c[j][0])


Measured memory_bytes: 131252
def main():
    import sys
    readline = sys.stdin.buffer.readline

    from collections import deque

    n = int(readline())
    ab = [list(map(int, readline().split())) for _ in range(n-1)]

    l = [[] for _ in range(n+1)]
    for a, b in ab:
        l[a].append(b)
        l[b].append(a)

    parents = [-1] * (n+1)
    order = []
    q = deque()
    q.append(1)
    while q:
        c = q.pop()
        order.append(c)
        for i in l[c]:
            if i == parents[c]:
                continue
            parents[i] = c
            q.append(i)
    
    color = [-1] * (n+1)
    for i in order:
        ng = color[i]
        c = 1
        for j in l[i]:
            if j == parents[i]:
                continue
            if c == ng:
                c += 1
            color[j] = c
            c += 1
    
    ans = []
    for a, b in ab:
        if a == parents[b]:
            ans.append(color[b])
        else:
            ans.append(color[a])

    print(max(ans))
    print('\n'.join(list(map(str, ans))))

if __name__ == '__main__':
    main()

Measured memory_bytes: 48380
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  string S; cin>>S;
  int N=S.size();
  string T;
  rep(i,0,N){
    if(S[i]!='x') T+=S[i];
  }
  int ans=0;
  int M=T.size();
  rep(i,0,M){
    if(T[i]!=T[M-i-1]){
      ans=-1;
      break;
    }
  }
  if(ans==0){
    int count=0;
    vi C;
    rep(i,0,N){
      if(S[i]=='x') count++;
      else{
        C.pb(count);
        count=0;
      }
    }
    C.pb(count);
    int P=C.size();
    rep(i,0,P){
      ans+=abs(C[i]-C[P-i-1]);
    }
    ans/=2;
  }
  cout<<ans<<endl;
  }


Measured memory_bytes: 1724
#include <cstdio>
#include <algorithm>
#define LL long long
#define INF 1e15
#define M 3000
using namespace std;
int n,m,s,head[55],tot,c[55],d[55];
LL dp[55][3010];
struct node{
	int to,next,a,b;
}e[105*2];
void add_edge(int u,int v,int a,int b){
	tot++,e[tot].to=v,e[tot].a=a,e[tot].b=b,e[tot].next=head[u],head[u]=tot;
}
int main(){
	int i,j,u,v,a,b,flag;
	scanf("%d%d%d",&n,&m,&s);
	for(i=1;i<=m;i++){
		scanf("%d%d%d%d",&u,&v,&a,&b);
		add_edge(u,v,a,b),add_edge(v,u,a,b);
	}
	for(i=1;i<=n;i++)scanf("%d%d",&c[i],&d[i]);
	for(i=1;i<=n;i++)
		for(j=0;j<=M;j++)dp[i][j]=INF;//注意j从0开始
	s=min(M,s);
	dp[1][s]=0;
	while(1){
		flag=0;
		for(u=1;u<=n;u++){
			for(j=M-1;j>=0;j--)dp[u][j]=min(dp[u][j],dp[u][j+1]);//清空手上的钱，但不消耗时间
			for(j=0;j<=M;j++){
				if(j>=c[u])dp[u][j]=min(dp[u][j],dp[u][j-c[u]]+d[u]);//01背包
				for(b=head[u];b;b=e[b].next){
					v=e[b].to;
					if(j>=e[b].a&&dp[v][j-e[b].a]>dp[u][j]+e[b].b){
						flag=1;
						dp[v][j-e[b].a]=dp[u][j]+e[b].b;
					}
				}
			}
		}
		if(!flag)break;
	}
	for(i=2;i<=n;i++)printf("%lld\n",dp[i][0]);
	return 0;
}

Measured memory_bytes: 2920
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f40;
const long long mod=1e9+7;
const long double PI = acos(0);
template <class T>void UNIQUE(vector<T> &x){
	sort(all(x));
	x.erase(unique(all(x)), x.end());
}

// }}} End Header
int main() {
	ll n, white = 0, right = 0;
	ll w = 0, r = 0, ans;
	string s;
	cin >> n >> s;

	rep(i,n){
		if(s[i] == 'R') right++;
		else white++;
	}
	ans = min(white, right);
	r = right;

	rep(i,n-1){
		if(s[i] == 'W') w++;
		else r--;
		ll subans = max(w, r);
		ans = min(subans, ans);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>   //PBDS
#include <ext/pb_ds/tree_policy.hpp>       //PBDS
#define int long long int
#define vi vector<int>
#define vii vector<pair<int,int>>
#define pi pair<int,int>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pf push_front
#define F first
#define S second
#define mi map<int,int>
#define PI   3.141592653589
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define f(n) for(int i=0;i<n;i++)
#define rf(n) for(int i=n-1;i>=0;i--)
#define check(x)   cerr<<#x<<" : "<<x<<endl;
#define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
#define fbo find_by_order                    //return iterator PBDS
#define ook order_of_key                     //return number :)) PBDS
#define baar exit(0)
using namespace __gnu_pbds;
using namespace std;
signed main()
{
	int n,m;
	cin>>n>>m;
	int ans=0;
	if(n>=1)
	{
		ans+=(n*(n-1))/2;
	}
	if(m>=1)
	{
		
		ans+=(m*(m-1))/2;
	}
	cout<<ans;
	return 0;
}

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

//region Template
#include "ext/pb_ds/assoc_container.hpp"

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const int MOD2 = 998244353;
const int MOD = 1000000007;
using namespace std;
#define finish(x) cout << x; exit(0);
#define fastIO cin.tie(0); cin.sync_with_stdio(false);
#define fi first
#define se second
void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }

//const string USCAO_TAG = "mountains";
void usaco(const string& USACO_TAG) { setIn(USACO_TAG + ".in"); setOut(USACO_TAG + ".out"); }
#define is_empty(...) ( sizeof( (char[]){#__VA_ARGS__} ) == 1 )

void print() {}
template<typename T, typename... Args>
void print(T firstArg, Args... args) {
	#ifdef LOCAL
	cout << firstArg << endl;
	print(args...);
	#endif
}

//endregion

/* Notes:
 * Fry my kartoshka
 */

const int MAXN = 1e5 + 5;
const int INF = 2e9;

bool vis[MAXN][2];
ll dp[MAXN][2];

vector<vector<int>> adj;
int n;

int dfs(int node, int p, bool col){
	if(vis[node][col]) return dp[node][col];

	vis[node][col] = 1;
	for(auto x : adj[node]){
		if(x == p){
			continue;
		}
		if(col == 1) {

			dp[node][col] *= dfs(x, node, 0) + dfs(x, node, 1);
			dp[node][col] %= MOD;
		}
		else{
			dp[node][col] *= dfs(x, node, 1);
			dp[node][col] %= MOD;
		}
	}

	return dp[node][col];
}
int main(){
	//usaco("milkvisits");

#ifdef LOCAL
	setIn("in.txt");
	setOut("out.txt");
#endif

	fastIO;
	cin >> n;
	adj.assign(n + 1, vector<int>());

	for(int i = 0; i <= n; i++){
		dp[i][0] = dp[i][1] = 1;
	}
	for(int i = 0; i < n - 1; i++){
		int u, v;
		cin >> u >> v;

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

	ll ans = dfs(1, 1, 0);

	cout << (ans + dfs(1,1, 1)) % MOD;
}


Measured memory_bytes: 15872
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define F first
#define S second
#define int long long
#define lint long long
#define ld long double
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define SET(x, val) memset(x, val, sizeof(x))
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 2e5 + 5, MOD1 = 1e9 + 7, MOD2 = 998244353;
const lint INF = 1e18;

#define PI 3.1415926535
int a, b, h, m;
signed main()
{
    cout << setprecision(25);
    cin >> a >> b >> h >> m;
    ld ah = (60*h + m)/2.00;
    //cout << ah << endl;
    ah = (ah*PI)/180.00;
    ld am = 6*m;
    am=(am*PI)/180.00;
    ld hx = a*sin(ah), hy = a*cos(ah);
    ld mx = b*sin(am), my = b*cos(am);
    //cout << hx << " " << hy << " - " << mx << " " << my << endl;
    ld ans = (hx-mx)*(hx-mx);
    ans += (hy - my)*(hy-my);
    ans = sqrt(ans);
    cout << ans;
}

Measured memory_bytes: 4164
using System;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
class P
{
    static void Main()
    {
        int[] abc = Console.ReadLine().Split().Select(int.Parse).ToArray();
        for (int i = 1; i <= 1000; i++)
        {
            if((abc[0] * i) % abc[1] == abc[2])goto end;
        }
        Console.WriteLine("NO");
        return;
        end:;
        Console.WriteLine("YES");
    }
}


Measured memory_bytes: 13396
fn get_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().to_string()
}

fn reads<T>() -> Vec<T>
    where
        T: std::str::FromStr,
        <T as std::str::FromStr>::Err: std::fmt::Debug {
    get_line().split(' ').map(|x| x.parse().unwrap()).collect()
}

use std::collections::BinaryHeap;
use std::cmp::Ordering;

#[derive(Clone, Copy, Eq, PartialEq)]
struct E {
    i: usize,
    j: usize,
    d: i64,
}

impl Ord for E {
    fn cmp(&self, other: &Self) -> Ordering {
        let mut res = other.d.cmp(&self.d);
        if res == Ordering::Equal {
            res = self.i.cmp(&other.i);
            if res == Ordering::Equal {
                res = self.j.cmp(&other.j);
            }
        }

        res
    }
}

impl PartialOrd for E {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}

fn main() {
    let hw = reads();
    let mut ts = vec![];
    ts.push(vec![false; hw[1] + 2]);
    let mut res = 0i64;

    for _ in 0..hw[0] {
        let mut xs = vec![];
        xs.push(false);
        for x in get_line().chars().map(|x| x == '.') {
            if x {
                res += 1;
            }
            xs.push(x);
        }
        xs.push(false);

        ts.push(xs);
    }
    ts.push(vec![false; hw[1] + 2]);

    let mut f = false;
    let mut q = BinaryHeap::new();
    
    q.push(E {
        i: 1,
        j: 1,
        d: 0,
    });

    while let Some(e) = q.pop() {
        if e.i == hw[0] && e.j == hw[1] {
            res -= e.d;
            res -= 1;
            f = true;
            break;
        }
        if !ts[e.i][e.j] {
            continue;
        }
        ts[e.i][e.j] = false;
        
        q.push(E {
            i: e.i + 1,
            j: e.j,
            d: e.d + 1,
        });
        q.push(E {
            i: e.i - 1,
            j: e.j,
            d: e.d + 1,
        });
        q.push(E {
            i: e.i,
            j: e.j + 1,
            d: e.d + 1,
        });
        q.push(E {
            i: e.i,
            j: e.j - 1,
            d: e.d + 1,
        });
    }

    if !f {
        res = -1;
    }
    

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


Measured memory_bytes: 4352
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;

	writeln(N > 999 ? "ABD" : "ABC");
	stdout.flush();
	debug readln();
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>

bool checkPrimenumber(int input){

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

int main(){

    //size of list
    int n;
    std::cin >> n;

    //number of prime number
    int count = 0;

    //input number
    int input;

    //count prime number
    for(int i = 0 ; i < n; i++)
    {
        std::cin >> input;
        if(checkPrimenumber(input))
            //count the number of primenumber
            count++;
    }

    //showing the output
    std::cout << count << std::endl;

    return 0;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
// aya_seは起床のプロ
using namespace std;

//@ebi's definition

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n - 1)); i >= (int)(a); i--)
#define all(v) (v).begin(), (v).end()

using ll = long long;

struct Edge
{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w) {}
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<ll>>;

// xxpoxx's definition
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define RES(a, n) (a).resize(n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = 1L << 60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/

// aya_se's definition
vl fac, finv, inv;
void COMinit(ll N)
{
    fac.resize(N);
    finv.resize(N);
    inv.resize(N);
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < N; 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(ll n, ll k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll modinv(ll a, ll m)
{
    ll b = m, u = 1, v = 0;
    while (b)
    {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

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

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

int main()
{
    cout << std::fixed << std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N,M;
    cin >>N>>M;
    if(N==1) cout << (M+1)%MOD<<endl;
    else{
        ll ans=(M+1)%MOD;
        if((N-1)>M){
            cout << ans<<endl;
        }else{
            ll X=(M/(N-1))%MOD;
            ll pre1=((M+1)%MOD*X)%MOD;
            ll pre2=((N-1)%MOD);
            ll pre3=((X*(X+1))%MOD*modinv(2,MOD))%MOD;
            ll pre=((pre1-(pre2*pre3)%MOD)%MOD+MOD)%MOD;
            (ans+=pre*2)%MOD;
            cout << ans%MOD << endl;
        }
    }
}



Measured memory_bytes: 3228
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<ll, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
ll a[200010];

// Range Mininum Query
template<typename T>
class SegmentTree {
private:
    int n;
    T dat[2000100];
public:
    SegmentTree(int n_) {
	n = 1;
	while (n < n_) n *= 2;
	for (int i = 0; i < 2*n-1; i++) dat[i] = inf;
    }

    void update(int k, T a) {
	k += n - 1;
	dat[k] = a;
	while (k > 0) {
	    k = (k - 1) / 2;
	    dat[k] = min(dat[k*2+1], dat[k*2+2]);
	}
    }
    
    // call query(a, b)
    // return min value for [a, b)
    T query(int a, int b) { return query(a, b, 0, 0, n); }
    T query(int a, int b, int k, int l, int r) {
	if (r <= a || b <= l) return inf;

	if (a <= l && r <= b) return dat[k];
	else {
	    T vl = query(a, b, k*2+1, l, (l+r)/2);
	    T vr = query(a, b, k*2+2, (l+r)/2, r);
	    return min(vl, vr);
	}
    }
};

int idx[200010];
SegmentTree<ll> st(200010);

ll calc(int l, int r) {
    if (l >= r) return 0;
    ll v = st.query(l, r);
    int i = idx[v];
    return (v+1) * (i - l + 1) * (r - i) + calc(l, i) + calc(i+1, r);
}

ll solve() {
    for (int i = 0; i < n; i++) {
        idx[a[i]] = i;
        st.update(i, a[i]);
    }
    return calc(0, n);
}

void input() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 94208
a = int(raw_input())
b = int(raw_input())
c = int(raw_input())
x = int(raw_input())

ans = 0
for i in range(a + 1):
  for j in range(b + 1):
    for k in range(c + 1):
      sum = 500 * i + 100 * j + 50 * k
      if sum == x:
        ans +=1
        
print ans

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

int main()
{
    // get two strings separated with half-width break
    string S, T;
    cin >> S >> T;
    // get two integers separated with half-width break
    int b,c;
    cin >> b >> c;
    // get a string
    string picked;
    cin >> picked;
  	if (S == picked) {
      b--;
    } else if (T == picked) {
      c--;
    }
    // output
    cout << b << " " << c << endl;
    return 0;
}


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

using namespace std;

int main()
{
    long long int n , k , i , l , r , md=1000000007, ans=0;
    cin>>n>>k;
    if(k>n)
    {
        cout<<"1"<<endl;
        return 0;
    }
    long long int a[n+1];
    a[0]=0;
    for( i = 1 ; i < n+1 ; i++)
    {
        a[i]=a[i-1]+i;
    }
    while(k<=n)
    {
        l=a[k-1];
        r=a[n]-a[n-k];  
        ans=ans%md +(r-l+1)%md;
        k++;
    }
        cout<<ans+1<<endl;

}


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

using i64 = int64_t;

int main(){
    int w, h, n;
    cin >> w >> h >> n;
    vector<pair<int, int>> spots;
    for(int i=0;i<n;++i){
        int x, y;
        cin >> x >> y;
        spots.emplace_back(x, y);
    }

    int ans = 0, cx = spots[0].first, cy = spots[0].second;
    for(auto e: spots){
        int cost = 0;
        if(e.first >= cx && e.second >= cy || e.first <= cx && e.second <= cy){
            cost += max(abs(e.first-cx), abs(e.second-cy));
        }else if(e.first > cx && e.second < cy || e.first < cx && e.second > cy){
            cost += abs(e.first-cx) + abs(e.second-cy);
        }
        cx = e.first;
        cy = e.second;
        ans += cost;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3072