akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M,x;
  cin>>N>>M;
  int a[N],b[N],c[M],d[M],Z[N];
  for(int i=0;i<N;i++) cin>>a[i]>>b[i];
  for(int i=0;i<M;i++) cin>>c[i]>>d[i];
  for(int i=0;i<N;i++){
    x=abs(a[i]-c[M-1])+abs(b[i]-d[M-1]);
    Z[i]=M;
    for(int j=M-1;j>=0;j--){
      int L=abs(a[i]-c[j])+abs(b[i]-d[j]);
      if(x>=L){
        x=L;
        Z[i]=j+1;
      }
    }
  }
  for(int i=0;i<N;i++) cout<<Z[i]<<endl;
}

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

int main() {
  int N,M;
  cin>>N>>M;
  vector<pair<int,int>> key;
  rep(i,M){
    int a,b;
    cin>>a>>b;
    int s=0;
    rep(j,b) {
      int c;
      cin>>c;
      c--;
      s |= 1<<c;
    }
    key.emplace_back(s,a);//push_back（要素の追加）の上位互換
  }
  //bit演算子でｃを管理
  vector<int> dp(1<<N,INF);//2の12乗は4096. dp=コストの最小値。
  dp[0]=0;
  rep(s,1<<N){
    rep(i,M){
      int t =  s | key[i].first;
      int cost = dp[s]+key[i].second;
      dp[t] = min(dp[t],cost);
    }
  }
  int ans = dp.back();
  if(ans==INF) ans = -1;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
vector<int64_t>A(N);
  for(int i=0;i<N;i++)
    cin>>A.at(i);
  vector<int64_t>B(N);
  for(int i=0;i<N;i++)
    cin>>B.at(i);
  vector<int64_t>C(N);
  for(int i=0;i<N;i++){
  C.at(i)=A.at(i)-B.at(i);
  }vector<int64_t>P={};
  vector<int64_t>M={};
  for(int i=0;i<N;i++){
  if(0<=C.at(i))
    P.push_back(C.at(i));
    else
      M.push_back(C.at(i));
  }sort(P.begin(),P.end());
  reverse(P.begin(),P.end());
  int64_t p=P.size();
  int64_t m=M.size();
  int64_t sum1=0;
  int64_t sum2=0;
  for(int i=0;i<p;i++)
    sum1+=P.at(i);
  for(int i=0;i<m;i++)
    sum2+=M.at(i);
  if(sum1+sum2<0)
    cout<<-1<<endl;
  else{
  int ans=m;
    int64_t sum3=0;
    for(int i=0;i<p+1;i++){
      if(-sum2<=sum3){
      ans+=i; break;
      }sum3+=P.at(i);
    }cout<<ans<<endl;
  }
  return 0;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if ((a == 5 && b == 5 && c == 7) || (a == 5 && b == 7 && c == 5) ||
      (a == 7 && b == 5 && c == 5)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

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

int main(){
	
	int w, h, x, y;
	double s;
	
	scanf("%d %d %d %d", &w, &h, &x, &y);
	
	s = w * (double)h / 2.0;
	
	printf("%.11lf ", s);
	
	if(w / 2.0 == (double)x && h / 2.0 == (double)y)
		printf("1");
	else
		printf("0");
	
	return 0;
}

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

int main(){
	int a,b,c,k,x[1000][4],p[500];
	while(true){
		for(int i=0;i<500;i++){
			p[i]=2;
		}
		cin>>a>>b>>c;
		if((a==0 && b==0) && c==0){
			break;
		}
		cin>>k;
		for(int i=0;i<k;i++){
			cin>>x[i][0]>>x[i][1]>>x[i][2]>>x[i][3];
			if(x[i][3]==1){
				p[x[i][0]]=1;
				p[x[i][1]]=1;
				p[x[i][2]]=1;
			}
		}
		for(int j=0;j<100;j++){
			for(int i=0;i<k;i++){
				if((p[x[i][0]]==1 && p[x[i][1]]==1)&& x[i][3]==0){
					p[x[i][2]]=0;
				}
				if((p[x[i][0]]==1 && p[x[i][2]]==1)&& x[i][3]==0){
					p[x[i][1]]=0;
				}
				if((p[x[i][1]]==1 && p[x[i][2]]==1)&& x[i][3]==0){
					p[x[i][0]]=0;
				}
			}
		}
		for(int i=1;i<=a+b+c;i++){
			cout<<p[i]<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1176
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	char c;
	cin >> c;
	cout << (char)(c + 1) << endl;
}

Measured memory_bytes: 256
import math
n,d=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
c=0
for i in range(n):
    x=l[i][0]
    y=l[i][1]
    k=math.sqrt(x**2+y**2)
    if k<=d:c+=1
print(c)

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

using namespace std;

int main(){
  
  int N, M;
  
  cin >> N >> M;
  
  int S[N];
  bool S_f[N];
  
  for(int i = 0; i < N; i++)
    S[i] = 0;
  if(N > 1)
  	S[0] = 1;
  
  for(int i = 0; i < N; i++)
    S_f[i] = true;
    
  for(int i = 0; i < M; i++){
  	int s, c;
    cin >> s >> c;
    if(S_f[s-1] || c==S[s-1]){
      S[s-1] = c;
      S_f[s-1] = false;
    }
    else{
      cout << "-1" << endl;
      return 0;
    }
  }
  
  if(N > 1 && S[0] == 0){
    cout << "-1" << endl;
    return 0;
  }
  
  int tmp = 0;
  
  for(int i = 0; i < N; i++){
  	tmp += S[i]*pow(10,N-i-1); 
  }
  cout << tmp << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import Counter
from math import factorial
n = int(input())
s = [''.join(sorted(list(input()))) for _ in range(n)]

def combination(i):
    return factorial(i) // (factorial(i-2) * factorial(2))

cnt = Counter(s)
ans = 0
for i in cnt.values():
    if i == 1:
        pass
    else:
        ans += combination(i)
print(ans)

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

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

ll dp[110][101000]; // num,value

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

	int N=in(),W=in();
	vector<ll> w(N),v(N);
	REP(i,N){
		w[i]=in();
		v[i]=in();
	}
	for(auto& x:dp){
		for(auto& y:x) y = 1LL<<60;
	}
	dp[0][0]=0;
	
	int max_value = 101000;
	for(int num=0;num<N;num++){
		for(int value=0;value<max_value;value++){
			if(value-v[num]>=0) chmin(dp[num+1][value],dp[num][value-v[num]]+w[num]);
			chmin(dp[num+1][value],dp[num][value]);
		}
	}
	
	int res=0;
	for(int i=0;i<max_value;i++){
		if(dp[N][i]<=W) res = max(res,i);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 87168
#include <bits/stdc++.h>
using namespace std;
int paper[10][10];
const int dx[] = { 0, 0, -1, 1, -1, -1,  1, 1,  0, 0, -2, 2};
const int dy[] = {-1, 1,  0, 0, -1,  1, -1, 1, -2, 2,  0, 0};

int main() {
  int x, y, s;
  char c;
  while (cin >> x >> c >> y >> c >> s) {
    paper[y][x]++;
    for (int i = 0; i < s * 4; i++) {
      int px = x + dx[i];
      int py = y + dy[i];
      if (px >= 0 && px < 10 && py >= 0 && py < 10){
        paper[py][px]++;
      }
    }
  }
  int num_of_cells = 0, max_density = 0;
  for (int i = 0; i < 10; i++)
  {
    for (int j = 0; j < 10; j++)
    {
      if (paper[j][i] == 0) num_of_cells++;
      max_density = max(paper[j][i], max_density);
    }
  }
  cout << num_of_cells << "\n" << max_density << "\n";
}



Measured memory_bytes: 3084
import Data.Array.IO
import Control.Applicative
import Data.List
import Control.Monad

main = do
    n <- read <$> getLine
    xs <- map (map read.words) <$> getLineN n :: IO [[Int]]
    putStrLn.(\v -> if v then "Yes" else "No").forth $ foldl f (0,0,0,True) xs

forth (_,_,_,v) = v


f (t1,x1,y1,flag) [t2,x2,y2] = if judge then (t2,x2,y2,flag && True) else (x2,y2,t2,False) where
    distance = abs(x1-x2) + abs(y1-y2)
    judge = t2-t1 >= distance && (t2-t1) `mod` 2 == distance `mod` 2 
    
getLineN :: Int -> IO [String]
getLineN n = replicateM n getLine

Measured memory_bytes: 73084
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main( ) {
    //freopen("A.01.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    int minusac=a-c;
    int minusab=a-b;
    int minusbc=b-c;
    (abs(minusac)<=d or abs(minusbc)<=d and abs(minusab<d))?printf("%s","Yes"):printf("%s","No");
    return 0;
}

Measured memory_bytes: 3812
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;

int main() {
    ll N, M;
    cin >> N >> M;
    vector<pair<ll, ll>> vp(N);
    ll a, b;
    for(ll i=0; i<N; i++){
        cin >> a >> b;
        vp.at(i) = make_pair(a, b);
    }

    sort(vp.begin(), vp.end());

    ll sum = 0;
    ll kosu = 0;
    for(auto c : vp){
        if(kosu + c.second <= M){
            kosu += c.second;
            sum += c.first * c.second;
        }
        else{
            sum += (M-(kosu))*c.first;
            break;
        }
    }
    cout << sum << endl;
}


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

int main()
{
  long long c, a = 0;
  string n;
  cin >> n;
  
  for (long long i = 0; i < n.size() ; i++){
    c = n[i] - 48;
    a += c;
  }
  if(a % 9 == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
 
  return 0;
} 

Measured memory_bytes: 3744
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

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

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

int gcd(int a, int b){
	if (b == 0)return a;
	return gcd(b, a % b);
}

//-----------------------ここから-----------


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

	if(n % 500 > a){
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
using namespace std;

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

#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
#define PI acos(-1)
#define rad(t) double(t)*PI/180.0

// ???
class Point {
public:
	double x, y;

	Point(double x = 0.0, double y = 0.0) : x(x), y(y) {}

	Point operator + (Point p) {
		return Point(x + p.x, y + p.y);
	}
	Point operator - (Point p) {
		return Point(x - p.x, y - p.y);
	}
	Point operator * (double c) {
		return Point(c * x, c * y);
	}
	Point operator / (double c) {
		return Point(x / c, y / c);
	}
	bool operator < (const Point &p) const {
		return (x != p.x ? x < p.x : y < p.y);
	}
	bool operator == (const Point &p) const {
		return (fabs(x - p.x) < EPS && fabs(y - p.y) < EPS);
	}
	bool operator != (const Point &p) const {
		return (fabs(x - p.x) > EPS || fabs(y - p.y) > EPS);
	}

	// ?????????
	double norm() {
		return (x * x + y * y);
	}
	// ??§??????
	double abs() {
		return sqrt(norm());
	}
};

// ????????????
typedef Point Vector;

// ??????
double dot(Vector a, Vector b) {
	return (a.x * b.x + a.y * b.y);
}

// ??????
double cross(Vector a, Vector b) {
	return (a.x * b.y - a.y * b.x);
}

// ?????????
double norm(Vector a) {
	return (a.x * a.x + a.y * a.y);
}

// ??§??????
double abs(Vector a) {
	return sqrt(norm(a));
}

// ??????
class Segment {
public:
	Point p1, p2;

	Segment(Point p1 = Point(), Point p2 = Point()) : p1(p1), p2(p2) {}
};

// ??????(Parallel)????????????
bool isParal(Vector a, Vector b) {
	return equals(cross(a, b), 0.0);
}

bool isParal(Point a1, Point a2, Point b1, Point b2) {
	return isParal(a1 - a2, b1 - b2);
}

// ?????????????????????????????????!!
bool isParal(Segment s1, Segment s2) {
	return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}

// ?????¨???????????¢
double distP(Point a, Point b) {
	return (a - b).abs();
}

int n;
vector<Point> v;

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> n;
	v.resize(n);
	for (int i = 0; i < n; ++i) {
		cin >> v[i].x >> v[i].y;
	}
	if (n % 2) {
		cout << "NA" << endl;
		return 0;
	}

	for (int i = 0; i < n / 2; ++i) {
		Segment s(v[i], v[i+1]), t(v[(n/2+i)%n], v[(n/2+i+1)%n]);
		
		// ????????´????????¨????????§???????????????????????°????????°???????§°
		if (!isParal(s, t) || (s.p2 - s.p1).norm() != (t.p2 - t.p1).norm()) {
			cout << "NA" << endl;
			return 0;
		}
	}
	
	// ????§°???????????????????±???????
	Point ans((v[0].x + v[n/2].x)/2, (v[0].y + v[n/2].y)/2);
	
	cout << fixed;
	cout.precision(10);
	cout << ans.x << " " << ans.y << endl;
	
	return 0;
}

Measured memory_bytes: 3296
#include <bits/stdc++.h> 
using namespace std; 
  
// Function to count all possible 
// triangles with arr[] elements 
int findNumberOfTriangles(int arr[], int n) 
{ 
    // Count of triangles 
    int count = 0; 
  
    // The three loops select three 
    // different values from array 
    for (int i = 0; i < n; i++) { 
        for (int j = i + 1; j < n; j++) { 
  
            // The innermost loop checks for 
            // the triangle property 
            for (int k = j + 1; k < n; k++) 
  
                // Sum of two sides is greater 
                // than the third 
              if(arr[i]!=arr[j]&&arr[i]!=arr[k]&&arr[j]!=arr[k]){
                if ( 
                    arr[i] + arr[j] > arr[k] 
                    && arr[i] + arr[k] > arr[j] 
                    && arr[k] + arr[j] > arr[i]) 
                    count++; 
              }
        }
    } 
    return count; 
} 
  
// Driver code 
int main() 
{ 
   int n;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];
  }
  cout<< findNumberOfTriangles(arr, n); 
  
    return 0; 
} 

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

bool equal(vector<string>a, vector<string>b) {
	if (a.size() != b.size())return false;
	for (int i = 0; i < a.size(); i++) {
		if (a[i].length() != b[i].length())return false;
		for (int j = 0; j < a[i].length(); j++) {
			if (a[i][j] != b[i][j])return false;
		}
	}
	return true;
}

int main() {
	int n, m;
	cin >> n >> m;
	vector<string>a(n), b(m);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < n - m + 1; i++) {
		for (int j = 0; j < n - m + 1; j++) {
			vector<string>p(m);
			for (int k = 0; k < m; k++) {
				p[k] = a[i + k].substr(j, m);
			}
			if (equal(p, b)) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}

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

int main(void)
{
	char s[30];
	int i,j,len;
	char result[]="yes";
	
	scanf("%s",s);
	
	len = strlen(s);
	
	for(i=0; i<len; i++){
		for(j=i+1; j<len; j++){
			if(s[i] == s[j]) strcpy(result,"no");
		}
	}
	
	printf("%s\n",result);
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    int n;
    string s;
    long r = 0;
    long g = 0;
    long b = 0;
    cin >> n;

    for (int i = 0; i < n; i++) {
        char c;
        cin >> c;
        s.push_back(c);
        if (c == 'R') {
            r += 1;
        } else if (c == 'G') {
            g += 1;
        } else {
            b += 1;
        }
    }

    long ans = r * g * b;

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int k = j + j - i;
            if (!(k < (int)s.length())) continue;
            if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) ans -= 1;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3632
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        w1: i64, w2: i64, s1: i64, s2: i64, e: i64, lim: i64,
    }

    let mut ans = (100*w1, 0); // (water + sugar, sugar)
    for i1 in 0..=lim / (100*w1) {
        let water1 = 100 * w1 *i1;
        for i2 in 0..=(lim - water1) / (100*w2) {
            let water2 = 100 * w2 * i2;
            let water = water1 + water2;
            for j1 in 0..=(lim - water) / s1 {
                let sugar1 = s1 * j1;
                for j2 in 0..=(lim - water - sugar1) / s2 {
                    let sugar2 = s2 * j2;
                    let sugar = sugar1 + sugar2;
                    let total = water + sugar;

                    if e * (water/100) < sugar {
                        continue;
                    }
                    
                    if total * ans.1 < ans.0 * sugar {
                        ans = (total, sugar);
                    }
                }
            }
        }
    }
    println!("{} {}", ans.0, ans.1);
}


Measured memory_bytes: 2152
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

//The Number of the Real Roots of a Cubic Equation
public class Main{

	int a, b, c, d;
	double EPS = 1e-8;
	List<Double> ans;
	
	double f(double x){
		return a*x*x*x + b*x*x + c*x + d;
	}
	double df(double x){
		return 3*a*x*x + 2*b*x + c;
	}
	void bs(double L, double R, boolean up){
		if(f(L)==0){
			ans.add(L); return;
		}
		if(f(R)==0){
			ans.add(R); return;
		}
		if(L <= 0 && 0 <= R && f(0)==0)return;
		if(up && (0 < f(L) || f(R) < 0))return;
		if(!up && (f(L) < 0 || 0 < f(R)))return;
		while(R-L > 1e-12){
			double M = (L+R)/2;
			if(0 < f(M)){
				if(up)R=M;
				else L=M;
			}
			else if(f(M) < 0){
				if(up)L=M;
				else R=M;
			}
			else{
				ans.add(M); return;
			}
		}
		if(Math.abs(f(L)) < EPS)ans.add(L);
	}

	void run(){
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		int INF = 1000000;
		while(T--!=0){
			a = sc.nextInt(); b = sc.nextInt(); c = sc.nextInt(); d = sc.nextInt();
			int D = b*b-3*a*c, rm = 0, rp = 0;
			ans = new ArrayList<Double>();
			if(0 <= D){
				double x0 = (-b-Math.sqrt(D))/3/a, x1 = (-b+Math.sqrt(D))/3/a;
				if(x1 < x0){
					double tmp = x1;
					x1 = x0;
					x0 = tmp;
				}
				bs(-INF, x0, 0 < df((x0-INF)/2));
				bs(x0, x1, 0 < df((x0+x1)/2));
				bs(x1, INF, 0 < df((x1+INF)/2));
			}
			else{
				bs(-INF, INF, 0 < df(0));
			}
			for(double d:ans){
				if(Math.abs(d) <= 0)continue;
				if(0 < d)rp++;
				else rm++;
			}
			System.out.println(rp+" "+rm);
		}
	}

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

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

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

    int ma = max(X,Y);
    int mi = min(X,Y);

    int a1 = ma*C*2;
    int a2 = mi*C*2 + abs(mi - X)*A + abs(mi - Y)*B;
    int a3 = A*X + B*Y;

    int ans = 1 << 30;
    ans = min(ans,a1);
    ans = min(ans,a2);
    ans = min(ans,a3);

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
//#define S second
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
template <class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
signed main() {
    long double pi = 3.14159265358979323846;
    cout << fixed << setprecision(10);
    long double R;
    cin >> R;
    cout << 2 * pi * R << endl;
}


Measured memory_bytes: 3780
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=2e5+5;
struct eg{int v,nx;}e[N<<1];int head[N],tot;
inline void add(R int u,R int v){e[++tot]={v,head[u]},head[u]=tot;}
int dep[N],vis[N],fa[N],n;
void dfs(int u,int fa){
	go(u)if(v!=fa)dfs(v,u);
	if(!vis[u]&&vis[fa]){puts("First");exit(0);}
	if(!vis[u])vis[u]=vis[fa]=1;
}
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d",&n);
	for(R int i=1,u,v;i<n;++i)scanf("%d%d",&u,&v),add(u,v),add(v,u);
	vis[0]=1;dfs(1,0);
	puts("Second");
	return 0;
}

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

#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define ll long long
template<typename T, typename U> 
static inline void amin(T &x, U y){
	if(x>y)
		x = y;
}
template<typename T, typename U> 
static inline void amax(T &x, U y){
	if(x<y)
		x = y;
}
#define rep(i,n) for(int i = 0; i < n; ++i)
#define REP(i,k,n) for(int i = k; i <= n; ++i)
#define REPR(i,k,n) for(int i = k; i >= n; --i)

int inf = 2e9;
ll INF = 2e18;
const int mod = 1e9+7;
const int N = 303;

double dp[N][N][N];

double solve(int a,int b,int c,int n){
    if(a==0 && b==0 && c==0){
        return 0;
    }
    if(dp[a][b][c] != 0){
        return dp[a][b][c];
    }
    double moves = (double)n/(a+b+c);
    if(a!=0){
        moves += solve(a-1,b,c,n)*((double)a/(a+b+c));
    }
    if(b!=0){
        moves += solve(a+1,b-1,c,n)*((double)b/(a+b+c));
    }
    if(c!=0){
        moves += solve(a,b+1,c-1,n)*((double)c/(a+b+c));
    }
    return dp[a][b][c] = moves;
}

int main(){
	int n;
    cin >> n;
    int x,cnt[4];
    cnt[0] = cnt[1] = cnt[2] = cnt[3] = 0;
    rep(i,n){
        cin >> x;
        cnt[x]++;
    }
    cout<<fixed<<setprecision(10)<<solve(cnt[1],cnt[2],cnt[3],n);
	return 0;
}

Measured memory_bytes: 217344
import numpy as np
input1 = list(map(int,input().split()))
input2 = input()

N = input1[0]
S = input2

if N%2 == 1:
  print('No')
  exit()

if S[:int(N/2)] == S[int(N/2):]:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 21232
#include <stdio.h>
#include <string.h>

int main(void)
{
	int n, k;
	char s[256];
	scanf("%d", &n);
	scanf("%s", s);
	scanf("%d", &k);
	k--;
	for (int i = 0; i < n; i++) {
		if (s[i] != s[k]) {
			printf("*");
		} else {
			printf("%c", s[i]);
		}
	}

	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int f[44];
int makefibonacci(void){
  int i;
  f[0] = 1;
  f[1] = 1;
  for(i = 2; i < 45; i++){
    f[i] = f[i-1] + f[i-2];
  }
}

int main(){
  int n;
  makefibonacci();
  scanf("%d", &n);

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

  return 0;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
int main(){
  double n;	cin >> n;
  vector<double>	a(n);
  for(int i=0;i<n;i++)	cin >> a[i];
  
  double ans=0;
  for(int i=0;i<n;i++){
    ans+=1/a[i];
  }
  printf("%.10f",1/ans);
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int n;
    cin >> n;
    vector<int> b(n-1);
    for (int i = 0; i < n - 1; ++i) {
        cin >> b[i];
    }

    int res = b[0];
    for (int i = 1; i < n-1; ++i) {
        res += min(b[i], b[i-1]);
    }
    res += b[n-2];
    cout << res << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace  std;
int main()
{
  int i,k,n,m;
  string s;
  cin >> n >> s;
  vector<int> white(n+1);
  vector<int> black(n+1);
  white.at(0)=0;
  black.at(0)=0;
  for(i=0;i<n;i++)
  {
    if(s.at(i)=='#')
    { white.at(i+1)=white.at(i)+1;
    }
    else
    {
      white.at(i+1)=white.at(i);
    }
  }
 for(i=0;i<n;i++)
  {
    if(s.at(n-1-i)=='.')
    {  black.at(i+1)=black.at(i)+1;
    }
   else
    {
      black.at(i+1)=black.at(i);
    }
  } 
  m=1000000;
  for(i=0;i<n+1;i++)
  {
    if(m>=white.at(i)+black.at(n-i))
      m=white.at(i)+black.at(n-i);
  //  cout << m << endl;
  }
  cout << m << endl;
}


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

int main(){
    
    
    while(true){
        int a,b;
        char c;
        cin>>a>>c>>b;
        if(c=='?')break;
        if(c=='+')cout<<a+b<<endl;
        if(c=='*')cout<<a*b<<endl;
        if(c=='/')cout<<a/b<<endl;
        if(c=='-')cout<<a-b<<endl;
        
    }
    
    
}



Measured memory_bytes: 3032
package main

import (
	"sort"
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	r := make(robots, n)

	for i := 0; i < n; i++ {
		x := scanInt()
		l := scanInt()
		r[i] = robot{x-l,x+l}
	}

	sort.Sort(r)

	cnt := 0
	anc := -int(1<<31-1)
	for i := 0; i < n; i++ {
		if anc <= r[i].a {
			anc = r[i].b
			cnt++
		}
		// fmt.Fprintln(wr, anc)
	}

	fmt.Fprintln(wr, cnt)
	// fmt.Fprintln(wr, r)

}

type robot struct {
	a,b int
}

type robots []robot

func (a robots) Len() int           { return len(a) }
func (a robots) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a robots) Less(i, j int) bool {
	if a[i].b==a[j].b {
		return a[i].a<a[j].a
	}
	return a[i].b < a[j].b
}


Measured memory_bytes: 4608
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep2l(i, s, n) for (ll i = (ll)(s); i < (ll)n; i++)

int main() {
    int n;
    cin >> n;
    vector<int> ans(26, 0);
    int count = 1;
    while (count <= n) {
        string S;
        cin >> S;
        if (count == 1) {
            rep(i, S.size()) {
                ans[(int)(S[i]-'a')]++;
            }
            count++;
            continue;
        }
        vector<int> res(26, 0);
        rep(i, S.size()) {
            res[(int)(S[i]-'a')]++;
        }
        rep(i, 26) {
            ans[i] = min(ans[i], res[i]);
        }
        count++;
    }
    string answer;
    rep(i, 26) {
        rep(j, ans[i]) {
            answer += (char)('a' + i);
        }
    }
    cout << answer << endl;
}


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

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

int main() {
    lint n;
    cin >> n;
    vector<lint> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    lint ans = LLONG_MAX;
    for (int p = 1; p <= 100; p++) {
        lint cand = 0;
        for (int i = 0; i < n; i++) {
            cand += (x[i] - p) * (x[i] - p);
        }
        chmin(ans, cand);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cassert>
#include <algorithm>    
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <bitset>
#define pb push_back
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define int long long


using namespace std;
typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef tuple<int, int, int> tiii;
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const long long INF = 1e18;
const int M = 1e9 + 7;





signed main()
{
#ifndef ONLINE_JUDGE
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif
	int l, r;
	cin >> l >> r;
	int res = inf;
	for(int i = l; i <= min(r, l + 2019); ++i){
		for(int j = i + 1; j <= min(r, l + 2019); ++j){
			res = min(res, i * j % 2019);
		}
	}	
	cout << res << endl;



    
	return 0;
}

Measured memory_bytes: 256
#[doc = " https://github.com/hatoo/competitive-rust-snippets"]
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
mod util {
    use std::fmt::Debug;
    use std::io::{stdin, stdout, BufWriter, StdoutLock};
    use std::str::FromStr;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn chars() -> Vec<char> {
        line().chars().collect()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
    #[allow(dead_code)]
    pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
        let out = stdout();
        let writer = BufWriter::new(out.lock());
        f(writer)
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ;; ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( $ t : ty ;; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ;; ) ) . collect ::< Vec < _ >> ( ) } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}
fn solve() {
    let s = util::chars();

    if s.len() < 4 {
        println!("WA");
        return;
    }

    if s[0] == 'A'
        && s[2..s.len() - 1].iter().filter(|&&c| c == 'C').count() == 1
        && s.iter().filter(|c| c.is_uppercase()).count() == 2
    {
        println!("AC");
    } else {
        println!("WA");
    }
}


Measured memory_bytes: 8572
import java.util.Scanner;

class B {
    public static void main(String... args) {
        final Scanner sc = new Scanner(System.in);
        final char[] S = sc.next().toCharArray();
        final int w = sc.nextInt();
        final StringBuilder sb = new StringBuilder();
        for(int i = 0; i < S.length; i += w)
            sb.append(S[i]);
        System.out.println(sb);
    }
}
public class Main {
    public static void main(String...args) {
        B.main();
    }
}


Measured memory_bytes: 21844
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    x, t = map(int, input().split())
    print(max(0, x - t))


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9108
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

class Pascal{
	vector<vector<int>>C;
public:
	Pascal(){}
	Pascal(int n){
		n=n*2+10;
		C=vector<vector<int>>(n,vector<int>(n));
		for(int i=0;i<n;i++){
			for(int j=0;j<=i;j++){
				if(j==0||j==i)C[i][j]=1;
				else C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD;
			}
		}
	}
	int nCr(int n,int r){
		return C[n][r];
	}
	int nrC(int n,int r){
		return C[n+r][n];
	}
};
int main(){
	int n,K;cin>>n>>K;
	cout<<n-K+1<<endl;
}

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

int main(){
	int k,s,ans = 0;
	cin >> k >> s;
	
	for(int i = 0;i<=k;i++){
		for(int j = 0;j<=k;j++){
			if(s-i-j<=k&&s-i-j>=0) ans++;
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
kaidan = [0] * (N + 1)
for i in range(M):
    tmp = int(input())
    kaidan[tmp] = -1
kaidan[0] = 1
for i in range(1,N + 1):
    if i == 1:
        if kaidan[i] != -1:
            kaidan[i] = 1
        else:
            kaidan[i] = 0
    else:
        if kaidan[i] != -1:
            kaidan[i] = kaidan[i -1] + kaidan[i - 2]
        else:
            kaidan[i] = 0
print(kaidan[N] % (10 ** 9 + 7))

Measured memory_bytes: 460020
x  = int(input())
def p(x):
    i = 2
    if x <= 1:
        return False
    while i*i <= x:
        if x%i == 0:
            return False
        i += 1
    return True
while True:
    if p(x) == True:
        print(x)
        break
    x += 1

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

#define PB push_back
#define MP make_pair
#define LL long long
#define LLU usinged long long
#define SZ(a) ((int)a.size())


using namespace std;

int main() {
	
	int N,K;
	scanf("%d %d", &N, &K);
	
	int ans = 0;
	for(int i = 0; i < N; i++) {
		int a;
		scanf("%d", &a);
		if(a >= K) ans++;
	}
	
	printf("%d\n", ans);
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
       int n;
       scanf("%d",&n);
       int ft=0,fx=0,fy=0,flag=0;
       for(int i=0;i<n;i++){
              int t, x, y;
              scanf("%d%d%d",&t,&x,&y);
              int cost=t-ft;
              int need=cost-abs(fx-x)-abs(fy-y);
              if(need<0||need%2!=0){
                     flag=1;
                     break;
              }
              ft=t;
              fx=x;
              fy=y;
       }
       if(flag){
              printf("No");
       }
       else printf("Yes");
       return 0;
}



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

int main () {
	char S[15];
	char T[15];
	int A, B;
	char U[15];
	
	scanf("%s %s", &S, &T);
	scanf ("%d %d", &A, &B);
	scanf ("%s", &U);
	

	if (strcmp(U,S)==0) {
		printf("%d %d\n", A-1, B);
	}
	if (strcmp(U,T)==0) {
		printf("%d %d\n", A, B-1);
	}
	
	return 0;
}

Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using ld=long double;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
const int inf=1e9+7;
const ll INF=9e18;
const long double PI = acos(-1.0);
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int F=1000;
bool ex[F][F];

int main(){//cout<<fixed<<setprecision(20);
  ll n,p,q;
  cin>>n>>p>>q;
  vll a(n),b(n),c(n);
  rep(i,0,n)cin>>a[i]>>b[i]>>c[i];
  ll l=(n+1)/2,r;
  r=n-l;
  map<P,ll> lmap,rmap;
  rep(bit,0,(1<<l)){
    ll cnta=0,cntb=0,cntc=0;
   rep(i,0,l){
    if(bit & (1<<i)){
      cnta+=a[i];
      cntb+=b[i];
      cntc+=c[i];
    }
   }
    if(lmap[mp(cnta,cntb)]==0)
    lmap[mp(cnta,cntb)]=cntc;
    else{
      chmin(lmap[mp(cnta,cntb)],cntc);
    }
  }
  rep(bit,0,(1<<r)){
    ll cnta=0,cntb=0,cntc=0;
   rep(i,0,r){
    if(bit & (1<<i)){
      cnta+=a[l+i];
      cntb+=b[l+i];
      cntc+=c[l+i];
    }
   }
    ex[cnta][cntb]=true;
    if(rmap[mp(cnta,cntb)]==0)
    rmap[mp(cnta,cntb)]=cntc;
    else{
      chmin(rmap[mp(cnta,cntb)],cntc);
    }
  }
  
  ll ans=INF;
  for(auto v:lmap){
    ll A=v.first.first;
    ll B=v.first.second;
    rep(i,0,F){
      ll C=i;
      if((q*A+q*C-B*p)%p==0){
      ll D=(q*A+q*C-B*p)/p;
        if(D>=F||D<0)continue;
        if(ex[C][D]){
          if(A+C==0||B+D==0)continue;
         chmin(ans,v.second+rmap[mp(C,D)]); 
        }
      }
    }
  }
  if(ans==INF)ans=-1;
  cout<<ans<<endl;
}




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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	int n;
	cin >> n;
	long long ans = (1ll*n*(n + 1))/2;
	for (int i = 2; i <= n; i++) {
		for (int j = i; j <= n; j += i) ans += j;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3540
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();
	
	ll N, K; cin >> N >> K;
	if (abs(N - K) > N) {
		cout << N << "\n";
	}
	else {
		N = abs(N - (N + K - 1) / K * K);
		cout << N << "\n";
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=100005,M=1e9+7; 
int n,a[N],pre[N],deg[N],cnt[N],f[N],ans=1,vis[N];
signed main(){
	scanf("%lld",&n);
	for (int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		deg[a[i]]++;
	}
	for (int i=1;i<=n;i++){
		if (deg[i]>2){
			printf("0\n");
			return 0;
		}
		if (deg[i]<2||vis[i])continue;
		int p=i;
		while (p!=i||!vis[p]){
			if (vis[p]){
				printf("0\n");
				return 0;
			}
			vis[p]=1;
			pre[a[p]]=p;
			p=a[p];
		}
	}
	for (int i=1;i<=n;i++)
		if (!deg[i]){
			int p=i,l1=0,l2=0;
			while (!vis[p])vis[p]=1,p=a[p],l1++;
			do {
				l2++;
				p=pre[p];
			}while(deg[p]!=2);
			if (l1<l2)ans=ans*2%M;
			else if (l1>l2){
				printf("0\n");
				return 0;
			}
		}
	for (int i=1;i<=n;i++)
		if (!vis[i]){
			int p=i,l=0;
			do {
				l++;
				p=a[p];
				vis[p]=1;
			}
			while(p!=i);
			cnt[l]++;
		}
	for (int i=1;i<=n;i++){
		int mul=1;
		if (i!=1&&(i&1))mul++;
		f[0]=1;f[1]=mul;
		for (int j=2;j<=cnt[i];j++)
			f[j]=(f[j-2]*(j-1)%M*i+f[j-1]*mul)%M;
		ans=ans*f[cnt[i]]%M;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 4480
N = int(input())
b = list(map(int,input().split()))

def pos(b):
    n = len(b)
    res = False
    for i in range(1,n+1):
        if b[-i] == n+1-i:
            b.pop(-i)
            return True,n+1-i,b
    return False,0,b 

ans = []
for i in range(N):
    possible,j,b = pos(b)
    if not possible:
        print(-1)
        break
    ans.append(j)
if possible:
    for i in range(N-1,-1,-1):
        print(ans[i])
        


Measured memory_bytes: 3064
#include<iostream>
#include<string>
using namespace std;
int main(){
	int N;
	long  double ans = 0;
	long double x[11];
	string  A = "BTC";
	string u;

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> x[i];
		cin >> u;
		if ( u== "BTC") {
			x[i] *= 380000.0;
		}
		ans += x[i];
	}

	cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 100100100100100100
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,a,n) for(int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> PLL;

vector<ll> divisor(ll n) 
{
    vector<ll> d;
    for(ll i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            d.push_back(i);
            if(i * i != n) d.push_back(n / i);
        }
    }
    return d;
}

vector<ll> solve(ll n, vector<ll> v)
{
    vector<ll> d; 

    for(ll i = 0; i < v.size(); i++) {
        if(n % v[i] == 0) {
            d.push_back(v[i]);
        }
    }
    return d;
}


int main() 
{
    ll a, b, k;
    cin >> a >> b >> k;
    int cnt = k;

    for(ll i = max(a,b); i > 0; i--) {

        if((a % i == 0) && (b % i == 0)) {
            cnt--;
        }
        if(cnt == 0) { cout << i << endl; return 0; }
    }

    return 0;
}



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

int main(){
	long double w, h, x, y; 
	cin >> w >> h >> x >> y; 
	long double s = w*h/2;
	
	cout << s; 
	if(x == w/2 && y == h/2){
		cout << " 1" << endl;
	}else{
		cout << " 0" << endl;
	}
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 998244353; constexpr int MAX = 2000020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;


int A[10];
void solve() {
	REP(i, 7)cin >> A[i];
	ll ans = 0;
	ans += A[1];
	int odd = 0;
	odd += A[0] % 2;
	odd += A[3] % 2;
	odd += A[4] % 2;
	if (odd >= 2 && A[0] && A[3] && A[4]) {
		ans += 3;
		A[0]--;
		A[3]--;
		A[4]--;
	}
	ans += A[0] / 2 * 2;
	ans += A[3] / 2 * 2;
	ans += A[4] / 2 * 2;

	print(ans);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}



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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

const int N = 200009;
int n;
vector<int> graph[N];
int col[N], ct[2], ans[N];

void dfs(int cur, int par = 0, int height = 0) {
    col[cur] = height%2;
    ct[col[cur]]++;
    for(int child : graph[cur]) {
        if(child != par) {
            dfs(child, cur, height+1);
        }
    }
}

int ones, twos, threes;
void print(int num) {
    if(num == 1) {
        cout << ones*3 + num << ' ';
        ones++;
    } else if(num == 2) {
        cout << twos*3 + num << ' ';
        twos++;
    } else {
        cout << threes*3 + num << ' ';
        threes++;
    }
}

int32_t main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    for(int i = 0; i < n-1; ++i) {
        int a, b; cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    dfs(1);

    if(ct[0] > ct[1]) {
        swap(ct[0], ct[1]);
        for(int i = 1; i <= n; ++i) {
            col[i] ^= 1;
        }
    }

    int need1 = n/3, need2 = n/3;
    if(n%3 != 0) need1++;
    if(n%3 == 2) need2++;

    if(ct[0] < need1) {
        for(int i = 1; i <= n; ++i) {
            if(col[i] == 0) {
                print(3);
            } else if(ones < need1) {
                print(1);
            } else if(twos < need2) {
                print(2);
            } else {
                print(3);
            }
        }
    } else {
        for(int i = 1; i <= n; ++i) {
            if(col[i] == 0 && ones < need1) {
                print(1);
            } else if(col[i] == 1 && twos < need2) {
                print(2);
            } else {
                print(3);
            }
        }
    }
    cout << '\n';
    
    return 0;
}


Measured memory_bytes: 19456