akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define eps (1e-10)
using namespace std;
class Point
{
	public:
	double x,y;
	Point(double _x=0,double _y=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 a){return Point(a*x,a*y);} 
	Point operator / (double a){return Point(x/a,y/a);}
	double norm(){return x*x+y*y;}
	double ABS(){return sqrt(norm());} //俩点间的距离 
};
struct Segment
{
	Point p1,p2;	
};

double dot(Point a,Point b)//求内积 
{
	return a.x*b.x+a.y*b.y;
}
//外积的值为a与b向量构成的平行四边形面积的值 
double cross(Point a,Point b)//求外积 
{
	return a.x*b.y-a.y*b.x;
} 


//判断是否正交 向量内积：a*b=|a||b|*cos(Y) 当cos为0时正交(90,-90垂直) 
//a*b=a.x*b.x+a.y*b.y;
bool solve1(Point a,Point b)//是否正交 
{
	double f=a.x*b.x+a.y*b.y; 
	if(fabs(f-0.0)<eps) return true;
	else return false;
}
//判断是否平行  向量外积：|a*b|=|a||b|sin(Y) 当sin为0时平行(180,0平行)
//|a*b|=|a|*|b|*sin(Y) 
bool solve2(Point a,Point b)//是否平行 
{
	double f=a.x*b.y-a.y*b.x;
	if(fabs(f-0.0)<eps) return true;
	else return false;
}

/*
求垂足x：对于给定的三点p1,p2,p从点p向通过p1,p2的直线引一条垂线
base=p2-p1;
hypo=p-p1;
 x=s.p1+base*(hypo*base/|base|^2); hypo*base 可以用向量内积求 
*/
Point solve3(Segment s,Point p)//求投影点 
{
	Point base=s.p2-s.p1;
	double r=dot(p-s.p1,base)/base.norm();
	return s.p1+base*r; 
}
/*
求投影点x：对于给定的三点p1,p2,p从点p向通过p1,p2的直线为对称轴与点p
成线对称点为x 
通过求solve3的垂足延长一倍就可以求x 
*/
Point solve4(Segment s,Point p)//求映象 
{
	return p+(solve3(s,p)-p)*2.0;
}

/*
点a与点b之间的距离等于向量a-b或b-a的绝对值。 
*/ 
double getdis(Point a,Point b)//求俩点间的距离                    
{
	return (a-b).ABS();
} 

/*
设直线p1 p2上的向量为a=p2-p1,p与p1构成的向量b=p-p1
则点p与直线p1p2的距离d就等于a,b构成的平行四边形的高
用a与b外积的大小(平行四边形的面积)除以a的大小|a|即可求出高d
d=|a*b|/|a|=|(p2-p1)*(p-p1)|/|p2-p1|; 
*/
//注意：这里Segmet s是不规范的应该是 Line s 才对 
double getdis_Li(Segment s,Point p)//点与直线的距离 
{
	return abs(cross(s.p2-s.p1,p-s.p1)/(s.p2-s.p1).ABS());
}
/*
Point a=p1-p0;
Point b=p2-p0;
1.外积大小across(a,b)为正时,可确定b在a的逆时针方向
	sin(Y)（Y在0-180）所以是正数
2. 外积大小across(a,b)为负时,可确定b在a的顺时针方向
3.（1,2）不符合 表示p2在直线p0p1上(注意是直线),cos(Y)大于90或小于-90
	度时为负，因此a与b的内积dot(a,b)负时，可确定p2位于线段p0p1后方
	即p2->p0->p1
4.不是3时，有俩种p0->p1-p2或者p0->p2->p1如果b的大小大于a的大小，即为
	p0->p1->p2;
5.不符合4，可以确定p2位于线段p0p1上 
*/ 
int ccw(Point p0,Point p1,Point p2)//判断三个点相对位置 
{
	Point a=p1-p0;
	Point b=p2-p0;
	if(cross(a,b)>eps) return 1;//p0,p1,p2成逆时针方向 
	if(cross(a,b)<-eps) return -1;//p0,p1,p2成顺时针方向 
	if(dot(a,b)<-eps) return 2;//p2 p0 p1一次排列在同一直线上 
	if(a.norm()<b.norm()) return -2;// p0 p1 p2一次排列在同一直线上 
	return 0;//p2在线段p0p1上 
	
}
int main()
{
	double x1,y1,x2,y2;
	scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
	Point p1(x1,y1),p2(x2,y2);
	int T;scanf("%d",&T);
	while(T--){
		int x,y;
		scanf("%d %d",&x,&y);
		Point p(x,y);
		if(ccw(p1,p2,p)==1) printf("COUNTER_CLOCKWISE\n");
		else if(ccw(p1,p2,p)==-1) printf("CLOCKWISE\n");
		else if(ccw(p1,p2,p)==2) printf("ONLINE_BACK\n");
		else if(ccw(p1,p2,p)==-2) printf("ONLINE_FRONT\n");
		else printf("ON_SEGMENT\n");
	} 
	
	return 0;
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
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; }

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

const int INF = 1<<30;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> x(n, 0);
    rep(i,n) cin >> x[i];
    int ans = INF;
    rep(i,n){
        if (i + k - 1 == n) break;
        int l = i;
        int r = i+k-1;
        int t1 = abs(x[l]) + abs(x[r] - x[l]);
        int t2 = abs(x[r]) + abs(x[l] - x[r]);
        ans = min(ans, min(t1, t2));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3784
from bisect import bisect_right

def main():
    N = int(input())
    A = list(map(int, input().split()))
    INF = 10 ** 18
    last_max = A[0]
    last_min = A[0]

    money = 1000
    stock = 0
    old_trend = 0
    trend = A[1] - A[0]
    buy_point = []
    bought_point = []

    for i in range(N-1):
        trend = A[i+1] - A[i]
        if trend * old_trend > 0 or trend == 0:
            continue
        else:
            if trend > 0:
                buy_point.append(i)
            if trend < 0:
                bought_point.append(i)
        old_trend = trend

    if len(buy_point) > len(bought_point):
        bought_point.append(N-1)

    for i in range(N):
        if i in buy_point:
            buy = money//A[i]
            stock += buy
            money -= buy*A[i]

            nx_bought_idx = bisect_right(bought_point,i)
            bought_value = A[nx_bought_idx]
            j = i - 1
            while j >= 0 and money >= 100:
                if A[j] < bought_value and money >= A[i]:
                    money -= A[j]
                    stock += 1
                    break
                j -= 1
        
        if i in bought_point:
            bought = stock
            stock = 0
            money += bought * A[i]
    print(money)
    


if __name__ == "__main__":
    main()

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

int main(){
	int N;
	cin >> N;
	int h[N], i, ans=0;
	for(i=0; i<N; i++){
		cin >> h[i];
	}
	h[N] = 0;
	
	int x=0, y=N-1;
	
	do{
		//最小値分下げる。ループの中身。
		int min=100;
		for(i=x; i<=y; i++){
			if(min > h[i])	min = h[i];
		}
		ans += min;
		for(i=x; i<=y; i++){
			h[i] -= min;
		}

      //x,yを決める。
		//xはhが正である最初のindex.
		x = 0;
		if(h[x]==0){
			do{
				x++;
			}while(h[x]==0);
		}
		//yはxから続いてhが正であるものの最後
		y = x;
		if(h[y+1]!=0){
			do{
				y++;
			}while(h[y]!=0);
			y--;
		}
	}while(x<N);
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
using System;

class Program
{
	static void Main()
	{
		string D;
		while ((D = Console.ReadLine()) != "0 0")
		{
			string s = "", t = "";
			string[] sD = D.Split(' ');
			int H = int.Parse(sD[0]), W = int.Parse(sD[1]);
			for (int i = 0; i < W; i++)
			{
				if (i == 0 || i == W - 1)
				{
					t += "#";
				}
				else
				{
					t += ".";
				}
				s += "#";
			}
			for (int i = 0; i < H; i++)
			{
				if (i == 0 || i == H - 1)
				{
					Console.WriteLine(s);
				}
				else
				{
					Console.WriteLine(t);
				}
			}
			Console.WriteLine();
		}
	}
}

Measured memory_bytes: 5384
#include <cstdio>
#include <vector>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
struct state { long long a, b; };
struct comparer {
	bool operator()(const state& s1, const state& s2) const {
		return s1.a < s2.a;
	}
};
int N; long long D, A[33], B[33];
state vl[7777777], vr[7777777]; // meet-in-the middle
int que[14348922]; // searching deque
int main() {
	scanf("%d%lld", &N, &D);
	for (int i = 0; i < N; i++) scanf("%lld%lld", &A[i], &B[i]);

	// Calculate sum with bitmasking
	int sep1 = (N >> 1), sep2 = N - sep1;
	vector<long long> sa1(1 << sep1), sb1(1 << sep1);
	vector<long long> sa2(1 << sep2), sb2(1 << sep2);
	for (int i = 0; i < sep1; i++) {
		int b1 = (1 << i), b2 = (1 << (i + 1));
		for (int j = b1; j < b2; j++) {
			sa1[j] = sa1[j - b1] + A[i];
			sb1[j] = sb1[j - b1] + B[i];
		}
	}
	for (int i = 0; i < sep2; i++) {
		int b1 = (1 << i), b2 = (1 << (i + 1));
		for (int j = b1; j < b2; j++) {
			sa2[j] = sa2[j - b1] + A[i + sep1];
			sb2[j] = sb2[j - b1] + B[i + sep1];
		}
	}

	// Meet-in-the-middle Algorithm
	int cnt1 = 0, cnt3 = 0;
	for (int i = 0; i < 1 << sep1; i++) {
		int r = (1 << sep1) - i - 1, j = r;
		do {
			// i -> remain, j -> anna, k -> bruno
			int k = r - j;
			long long r1 = sa1[k] - sa1[j];
			long long r2 = sb1[k] - sb1[j];
			if (r1 >= 0) vl[cnt1++] = state{ r1, r2 };
			if (r1 > 0) cnt3++;
			j = (j - 1) & r;
		} while (j != r);
	}
	int cnt2 = 0, cnt4 = 0;
	for (int i = 0; i < 1 << sep2; i++) {
		int r = (1 << sep2) - i - 1, j = r;
		do {
			// i -> remain, j -> anna, k -> bruno
			int k = r - j;
			long long r1 = sa2[k] - sa2[j];
			long long r2 = sb2[k] - sb2[j];
			if (r1 >= 0) vr[cnt2++] = state{ r1, r2 };
			if (r1 > 0) cnt4++;
			j = (j - 1) & r;
		} while (j != r);
	}

	// Sorting
	sort(vl, vl + cnt1, comparer()); cnt1 += cnt3;
	sort(vr, vr + cnt2, comparer()); cnt2 += cnt4;

	int cnt5 = cnt1 - cnt3;
	int cnt6 = cnt2 - cnt4;
	vector<state> wl(cnt1), wr(cnt2);
	for (int i = 0; i < cnt3; i++) wl[i] = state{ -vl[cnt5 - i - 1].a, -vl[cnt5 - i - 1].b };
	for (int i = 0; i < cnt4; i++) wr[i] = state{ -vr[cnt6 - i - 1].a, -vr[cnt6 - i - 1].b };
	copy(vl, vl + cnt5, wl.begin() + cnt3);
	copy(vr, vr + cnt6, wr.begin() + cnt4);

	// Searching with deque
	int cl = 0, cr = 0, dl = 0, dr = 0;
	long long ret = 0;
	for (int i = cnt2 - 1; i >= 0; i--) {
		while (cr < cnt1 && wl[cr].a + wr[i].a <= D) {
			while (dr - dl && wl[que[dr - 1]].b <= wl[cr].b) dr--;
			que[dr++] = cr++;
		}
		while (cl < cnt1 && wl[cl].a + wr[i].a < -D) {
			if (dr - dl && que[dl] == cl) dl++;
			cl++;
		}
		if (dr - dl) ret = max(ret, wr[i].b + wl[que[dl]].b);
	}
	printf("%lld\n", ret);
	return 0;
}

Measured memory_bytes: 681924
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
using System.Dynamic;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;

namespace atcorder
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] A = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int[] B = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int[] C = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int ans = 0;
            for (int i = 0; i < N; i++)
            {
                ans += B[A[i] - 1];
                if (i > 0)
                {
                    if (A[i] - 1 == A[i - 1])
                    {
                        ans += C[A[i] - 2];
                    }
                }
            }
            Console.WriteLine(ans);
        }
    } 
}


//文字配列の取得
//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];

//文字列の取得
//string s = Console.ReadLine();

//数字配列の取得
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];

//数字の取得
//int N = int.Parse(Console.ReadLine());

//リスト型(int)の取得
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());

//出力
//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.WriteLine(cnt);



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

# define Rep(i,a,b) for(int i=a;i<=b;i++)
# define _Rep(i,a,b) for(int i=a;i>=b;i--)
# define RepG(i,u) for(int i=head[u];~i;i=e[i].next)

typedef long long ll;

const int N=5e5+5;
const ll mod=1e9+7;

template<typename T> void read(T &x){
   x=0;int f=1;
   char c=getchar();
   for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
   for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+c-'0';
    x*=f;
}

# define int long long

int n,m;
int fac[N],inv[N];
int res;

int Qpow(int base,int ind){
    int res=1;
    while(ind){
        if(ind&1)res=res*base%mod;
        base=base*base%mod;
        ind>>=1;
    }
    return res;
}

int C(int n,int m){
    // if(n==m||!m)return 1;
    return fac[n]*inv[m]%mod*inv[n-m]%mod;
}

signed main()
{
    read(n),read(m);
    fac[0]=inv[0]=1;
    Rep(i,1,m)fac[i]=fac[i-1]*i%mod;
    Rep(i,1,m)inv[i]=Qpow(fac[i],mod-2);
    Rep(i,0,n){
        if(i%2==0)res+=C(n,i)*fac[m-i]%mod*inv[m-n]%mod,res%=mod;
        else res-=C(n,i)*fac[m-i]%mod*inv[m-n]%mod,res=(res+mod)%mod;
        // printf("%lld\n",res);
    }
    printf("%lld\n",res*fac[m]%mod*inv[m-n]%mod);
    return 0;
}

Measured memory_bytes: 11372
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;


vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}




int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll k;
    cin >> k;
    queue<ll> q;
    REP(i, 1, 10) q.push(i);
    ll count = 0;
    while(!q.empty()){
        ll t = q.front();
        q.pop();
        count++;
        if(count == k){
            print(t);
            return 0;
        }
        ll rem = t % 10;
        if(rem - 1 >= 0) q.push(t * 10 + rem - 1);
        q.push(t * 10 + rem);
        if(rem + 1 <= 9) q.push(t * 10 + rem + 1);
    }

}



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

int main()
{
    double t, n, sum=0, result;
    cin >> t;
    while(t--)
    {
        cin >> n;
        sum = sum + (1/n);
    }
    result = 1/sum;
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
Max = sys.maxsize
def l():
    return list(map(int,input().split()))
def m():
    return map(int,input().split())
def onem():
    return int(input())
def s(x):
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa == x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x):
    return " ".join(map(str,x))

n = onem()

a = l()
a.sort()
a = cl.deque(a)
aa = []
co = 0
up = a.pop()
do = a.popleft()

for i in range(len(a)):
    if a[i] >= 0:
        aa.append([do,a[i]])
        do -= a[i]
    else:
        aa.append([up,a[i]])
        up -= a[i]    
aa.append([up,do])
print(up-do)
for i in range(n-1):
    print(jo(aa[i]))



Measured memory_bytes: 22848
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int a,b,c,d,e,f;
    cin>>a>>b>>c>>d>>e>>f;
    
    set<int> water, sugar;
    for(int i=0;i<=30;i++){
        for(int j=0;j<=30;j++){
            if(a*i+b*j<=f){
                water.insert((a*i+b*j)*100);
            }
        }
    }
    
    for(int i=0;i<=3000;i++){
        for(int j=0;j<=3000;j++){
            if(i*c+j*d<=f){
                sugar.insert(i*c+j*d);
            }
        }
    }
    
    vector<int> wtv(water.begin(),water.end());
    vector<int> sgv(sugar.begin(),sugar.end());
    
    
    int x = -1,y=-1;
    for(auto wt: wtv){
        for(auto sg: sgv){
            if(wt+sg>f)continue;
            if(wt/100*e<sg)continue;
            if(x==-1||y*(wt+sg)<=sg*(x+y)){
                x = wt;
                y = sg;
            }
        }
    }
    cout<<x+y<<" "<<y<<endl;
}


Measured memory_bytes: 384
#from collections import deque
#from heapq import heapify, heappop, heappush
#from bisect import insort
#from math import gcd
#from decimal import Decimal
#mod = 1000000007
#mod = 998244353
#N = int(input())
#N, K = map(int, input().split())
#A = list(map(int, input().split()))
#flag = True
#for k in range(N):
#ans = 0
#print(ans)
#print('Yes')
#print('No')
N = int(input())
ans = 0

#N, K = map(int, input().split())
#A = list(map(int, input().split()))
#flag = True
for B in range(1, N+1):
	ans += N//B
	if N%B == 0:
		ans -= 1

#ans = 0
print(ans)
#print('Yes')
#print('No')

Measured memory_bytes: 9028
/*
 * 競技プログラミング用テンプレート
 * by yuma140902
 * 2019/12/08
 * ver 0.1.0
 */
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
const int INF = 900000;
const ll INFL = 9000000;

#define vi vector<int>
#define vii vector<vector<int> >
#define vi_def(n) vector<int>((n))
#define vii_def(n,m) vector<vector<int> >((n), vector<int>((m)))
#define vi_def_dflt(n, def) vector<int>((n), (def))
#define vii_def_dflt(n, m, def) vector<vector<int> >((n), vector<int>((m), (def)))

#define rep(i, n) for(int i=0; i < (n); ++i)
#define per(i, n) for(int i=(n)-1; i >= 0; --i)
#define range(i, begin, end) for(int i=(begin); i < (end); ++i)

int N;
vi A;
int main(){
  scanf("%d", &N);
  A = vi_def(N);
  rep(i, N) scanf("%d", &A[i]);

  int countNegative = 0;
  rep(i, N) if(A[i] < 0) ++countNegative;

  rep(i, N) A[i] = abs(A[i]);

  ll sum = accumulate(A.begin(), A.end(), (ll)0);

  if(countNegative % 2 == 0){
    cout << sum << endl;
  }
  else{
    int min = *min_element(A.begin(), A.end());
    cout << sum-(min*2) << endl;
  }

}


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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1000000000; //
const ll LINF = (ll) 4000000000000000000; //
const ll MOD = (ll) 1000000007; //
const double PI = 3.1415926535898; //
const int limit = 100010;

#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep2(i,n) REP(i,1,n+1)
#define rep3(i,n) REP(i,0,n+1)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define repll(i,n) REPLL(i,0,n)
#define repll2(i,n) REPLL(i,1,n+1)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())

//------------------------------------------------------

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll x[n];
    rep(i, n) cin >> x[i];

    ll sum = 0;
    rep(i, n - 1) sum += min(a * (x[i + 1] - x[i]), b);

    cout << sum << endl;

    return 0;
}

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

bool formula(string &s, int &p)
{
    if (s[p] == 'T') {
	++p;
	return true;
    } else if (s[p] == 'F') {
	++p;
	return false;
    } else if (s[p] == '-') {
	++p;
	return !formula(s, p);
    } else if (s[p] == '(') {
	++p;
	bool lhs = formula(s, p);
	if (s[p] == '*') {
	    ++p;
	    bool rhs = formula(s, p);
	    ++p;
	    return (lhs&&rhs);
	} else if (s[p] == '+') {
	    ++p;
	    bool rhs = formula(s, p);
	    ++p;
	    return (lhs||rhs);
	} else {
	    ++p;
	    ++p;
	    bool rhs = formula(s, p);
	    ++p;
	    if (lhs && !rhs)
		return false;
	    else
		return true;
	}
    }
}

bool equation(string& s, int& p)
{
    bool lhs = formula(s, p);
    ++p;
    bool rhs = formula(s, p);

    //cout << lhs << " " << rhs << endl;
    if (lhs == rhs)
	return true;
    else
	return false;
}

int main()
{
    const string V = "abcdefghijk";

    string s;
    while (cin >> s) {
	if (s == "#")
	    break;

	bool ans = true;
	for (int i = 0; i < (1 <<11); ++i) {
	    string t = s;
	    for (int j = 0; j < t.size(); ++j) {
		if (binary_search(V.begin(), V.end(), t[j])) {
		    if (i & (1 << (t[j]-'a')))
			t[j] = 'T';
		    else
			t[j] = 'F';
		}
	    }

	    int p = 0;
	    if (!equation(t, p))
		ans = false;
	}

	if (ans)
	    cout << "YES" << endl;
	else
	    cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 928
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        var NM = ReadLine().Split().Select(int.Parse).ToArray();
        int N = NM[0];
        int M = NM[1];
        bool[] ac = new bool[N];
        int[] WA = new int[N];
        long wa = 0;
        for (int i = 0; i < M; i++)
        {
            var r = ReadLine().Split();
            int p = int.Parse(r[0])-1;
            var s = r[1];

            if (!ac[p])
            {
                if (s == "WA") WA[p]++;
                else { ac[p] = true;wa += WA[p]; }
            }

        }
        WriteLine($"{ac.Count(_=>_)} {wa}");
    }
}


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

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int MAX_N = 100000, MAX_M = 100000;
int N, M;
int p[MAX_N];
int x[MAX_M], y[MAX_M];

static const int MAX_UF = MAX_N;

template <class T> class UnionFind {
private:
  T par[MAX_UF];
  T rank[MAX_UF];
  
public:
  T find(T x);
  void init(T n);
  void unite(T x, T y);
  bool same (T x, T y);
};

template <class T> void UnionFind<T>::init(T n) {
  for (T i = 0; i < n; ++i) {
    par[i] = i;
    rank[i] = 0;
  }
}

template <class T> T UnionFind<T>::find(T x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}

template <class T> void UnionFind<T>::unite(T x, T y) {
  x = find(x); y = find(y);
  if (x == y) {
    return;
  } else {
    if (rank[x] > rank[y]) {
      par[y] = x;
    } else {
      par[x] = y;
      if (rank[x] == rank[y]) ++rank[y];
    }
  }
}

template <class T> bool UnionFind<T>::same(T x, T y) {
  return find(x) == find(y);
}

int main() {
  cin >> N >> M;
  rep(i,N) cin >> p[i];
  rep(i,M) cin >> x[i] >> y[i];

  UnionFind<int> uf;
  uf.init(N);
  for (int i = 0; i < M; ++i) {
    uf.unite(--x[i], --y[i]);
  }

  int ans = 0;
  for (int i = 0; i < N; ++i) {
    if (uf.same(i, --p[i])) ++ans;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
int main(void){
 
   int N;
   cin >> N;
   int A[2][N];
   
   for(int i = 0; i < N; i++)cin >> A[0][i];
   
   for(int i = 0; i < N; i++)cin >> A[1][i];


   
   int ans = 0;
   int sum = 0;
   
   for(int i = 0; i < N; i++){
       
       sum = 0;
       
       for(int j = 0; j < N; j++){
           
            if(j < i){
                        
                sum += A[0][j];
               
            }else if(j == i){
            
                sum += A[0][j];
                sum += A[1][j];

            }else{
               
                sum += A[1][j];
                
            }
            //cout << sum << endl;
           
           
        }
      //cout <<ans << endl;
        ans = max(sum,ans);
      
   }
   
   cout << ans << endl;
   
   
   
   
    
}

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

int main () {
	string s;
	
	cin>>s;
	int x = s.length();
	
	vector<char>insert;
	
	for(int i=0; i<x; i++) {
		if(s[i] != 'B') {
			insert.push_back(s[i]);
		} else if( !insert.empty()){
			insert.pop_back();
		}
	}
	
	for(int i=0; i<insert.size(); i++) {
		cout<<insert[i];
	}cout<<endl;
	
}

Measured memory_bytes: 3604
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()

	if N <= 2 {
		out(N)
		return
	}

	ans := 0
	cnt := 0
	for i := 1; i < N; i++ {
		ans += i
		cnt++
		// out(i)
		if ans >= N {
			break
		}
	}
	// out(ans, N, cnt)
	// out("----")
	for i := 1; i <= cnt; i++ {
		if N+i == ans {
			continue
		}
		out(i)
	}
}


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

#define M1 1000000007
#define M2 1000000009
#define ll long long 
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define INF 1001001001
#define PI 3.1415926535897932384626
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define f0(i, n) for (int i = 0; i < (int)(n); ++i)
#define f1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define fc0(i,l,r) for(int i = (int)(l); i<(int)(r); ++i)
#define fc1(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i)
#define fr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef pair<int,int> ii; 
 
void init()
{
  #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
      freopen("error.txt", "w", stderr);
    #endif

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
}
 
signed main()
{
    init();

    ll n;
    cin>>n;
    string s="";
    while(n!=0)
    {
      n--;
      s+=(char)(97+n%26);
      n/=26;
    }
    fr0(i,s.size()){cout<<s[i];}

    cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
    return 0;
}

Measured memory_bytes: 3848
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define rep(i,n) for(int i=0;i<n;++i)
#define rep(j,m) for(int j=0;j<m;++j)
#define REP(i,n) for(int i=1;i<=n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define len(s)   ((int)s.size())
#define F first
#define S second
#define pb push_back
#define pf push_front
#define mp make_pair
typedef long long ll;
typedef double db;
typedef vector<ll> ve;
typedef vector< vector <int> >vee;
typedef vector<pair<int,int> >vepa;
typedef set<char>se;
typedef map<ll,ll> mpp;
const ll N=1e5+5;
bool f;
ll n,a[N],b[N],c[N],dp[N][3];
ll solve(ll i=0,ll last=0)
{
  if(i==n)return 0;
  ll &ret=dp[i][last];
  if(~ret)return ret;
  if(last==0)
   return ret=max({solve(i+1,1)+a[i],solve(i+1,2)+b[i],solve(i+1,3)+c[i]});
  else if(last==1)
   return ret=max(solve(i+1,2)+b[i],solve(i+1,3)+c[i]);
  else if(last==2)
   return ret=max(solve(i+1,1)+a[i],solve(i+1,3)+c[i]);
   else if(last==3)
   return ret=max(solve(i+1,2)+b[i],solve(i+1,1)+a[i]);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
   cin>>n;
   memset(dp,-1,sizeof dp);
   rep(i,n)
    cin>>a[i]>>b[i]>>c[i];
   cout<<solve();
go;
}

Measured memory_bytes: 9600
N=int(input())
B=[int(s) for s in input().split()]

A=[int(0) for _ in range(N)]
A[0]=B[0]
A[N-1]=B[N-2]
for i in range(1,N-1):
    A[i]=min(B[i-1],B[i])
print(sum(A))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
int n,k,a[N],at,ans,cs[N];
int main(){
	//freopen("readin.txt","r",stdin);
	scanf("%d%d",&n,&k);
	k--;
	if(k)return cout << (n - 1 + k - 1)/k << endl,0;
	cout << 0 << endl;
}

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

signed main(){
    // cout << fixed << setprecision(10) << flush;

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

    int INF = (1<<30);
    vector<int> dp(n, INF);
    for(int i=0; i<n; i++){
        auto itr = lower_bound(dp.begin(), dp.end(), a[i]);
        int ind = distance(dp.begin(), itr);
        dp[ind] = a[i];
    }

    auto itr_ans = lower_bound(dp.begin(), dp.end(), INF);
    int ans = distance(dp.begin(), itr_ans);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4372
# coding: utf-8
import re
import bisect
from datetime import datetime as dt
import bisect
import fractions

def gcd(a, b):
    return fractions.gcd(a, b)

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

def calc(n, a, b):
    return n//a + n//b - n//lcm(a,b)

if __name__ == '__main__':
    a, b, c, d = map(int, input().split())
    num1 = b - calc(b,c,d)
    num2 = (a-1) - calc(a-1, c,d)
    # ans = calc(b, c, d) - calc(a - 1, c, d)
    # print(b - a + 1 - ans)
    print(num1-num2)


Measured memory_bytes: 5204
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let s = read::<String>().chars().collect::<Vec<_>>();
    let mut ans = 1;
    for i in 1..n {
        if s[i] != s[i - 1] {
            ans += 1;
        }
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int K;
	cin >> K;
	
	queue<ll> que;
	FOR(i, 1, 10) que.push(i);
	
	while (--K) {
		ll cur = que.front(); que.pop();
		int p = cur % 10;
		if (p > 0) que.push(cur * 10 + p - 1);
		que.push(cur * 10 + p);
		if (p < 9) que.push(cur * 10 + p + 1);
	}
	cout << que.front() << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int dp[41][401][401];

int main()
{
	int N, Ma, Mb;
	cin >> N >> Ma >> Mb;

	int a[41], b[41], c[41];
	for (auto i = 1; i <= N; ++i)
	{
		cin >> a[i] >> b[i] >> c[i];
	}

	for (auto i = 0; i <= N; ++i)
	{
		for (auto j = 0; j <= 400; j++)
		{
			for (auto k = 0; k <= 400; ++k)
			{
				dp[i][j][k] = INT_MAX;
			}
		}
	}
	dp[0][0][0] = 0;

	auto result = INT_MAX;
	for (auto i = 1; i <= N; ++i)
	{
		for (auto j = 0; j <= 400; ++j)
		{
			for (auto k = 0; k <= 400; ++k)
			{
				auto temp = INT_MAX;
				if (j >= a[i] && k >= b[i] && dp[i - 1][j - a[i]][k - b[i]] != INT_MAX)
				{
					temp = dp[i - 1][j - a[i]][k - b[i]] + c[i];
				}
				dp[i][j][k] = min(temp, dp[i - 1][j][k]);
			}
		}
	}

	for (auto i = 1; i <= 400; ++i)
	{
		for (auto j = 1; j <= 400; ++j)
		{
			if (i * Mb == j * Ma)
			{
				result = min(result, dp[N][i][j]);
			}
		}
	}

	if (result >= INT_MAX)
	{
		result = -1;
	}

	cout << result << endl;

	return 0;
}

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

long long fun(int n)
{
    if(n==0)
    return 0;
	long long temp=n*(n-1);
	temp/=2;
	return temp;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m;
    cin>>n>>m;
    long long ans=fun(n)+fun(m);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
template <class T>
bool chmax(T &a, const T &b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
	if (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

void solve()
{
	int n;
	ll k;
	cin>>n>>k;

	
	vector<int>a(n);
	
	
	vector<int>trip;
	trip.push_back(1);
	
	rep(i,n){
		cin>>a[i];
	}
	int now=1;
	map<int,int>visited;
	visited[1]=1;
	int repeat=0;
	int bef=0;
	bool dag=false;
	int nth=1;
	while(1){

		now=a[now-1];
		//cout<<now<<" n"<<endl;
		nth++;
		if(visited[now]){
			//cout<<nth<<endl;
			bef=visited[now];
			if(now!=1){
				dag=true;
			}
			repeat=nth-visited[now];
			
			break;
		}else 
		{
			visited[now]=nth;
		}
		trip.push_back(now);	
	}
	//cout<<" bef"<<bef<<endl;
	//cout<<"rep "<<repeat<<endl;
	vector<int>repe;
	rep(i,repeat){
		repe.push_back(trip[i+bef-1]);
		//cout<<repe[i]<<endl;
	}	
	int dest=0;
	if(!dag){
		k%=repeat;
		dest=trip[k];
		//cout<<1<<endl;
	}else{
		if(k>=bef-1){
			k-=bef-1;
			k%=repeat;
			dest=repe[k];
		}else{
			dest=trip[k];
		}
	}
	
	cout<<dest<<endl;
}

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


Measured memory_bytes: 14944
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static readonly int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			//int n = int.Parse(Console.ReadLine());
			//long n = long.Parse(Console.ReadLine());
			//string s = Console.ReadLine();
			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			int n = vs[0];
			int m = vs[1];
			int q = vs[2];

			// 200,000 * 500 = 1*10^8
			int[,] trains = new int[n, n];
			for (int i = 0; i < m; i++) {
				vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
				for (int j = vs[1] - 1; j < n; j++) {
					trains[vs[0] - 1, j]++;
				}
			}
			//for (int i = 0; i < n; i++) {
			//	System.Diagnostics.Debug.Write($"{i + 1,2} : ");
			//	for (int j = 0; j < n; j++) {
			//		System.Diagnostics.Debug.Write($"{trains[i, j],2} ");
			//	}
			//	System.Diagnostics.Debug.WriteLine("");
			//}
			// 100,000 * 500 = 5*10^7
			for (int i = 0; i < q; i++) {
				vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
				int ans = 0;
				//System.Diagnostics.Debug.Write($"{vs[0]}-{vs[1]}:");
				for (int j = vs[0] - 1; j < vs[1]; j++) {
					ans += trains[j, vs[1] - 1];
					//System.Diagnostics.Debug.Write($"{trains[j, vs[1] - 1]} ");
				}
				//System.Diagnostics.Debug.WriteLine("");
				Console.WriteLine(ans);
			}


			Console.Out.Flush();
		}

	}
}


Measured memory_bytes: 18812
N, M  = map(int, input().split())
A = [ input() for i in range(N)]
B = [ input() for i in range(M)]


def serch(x0, y0):
  for i in range(M):
    for j in range(M):
      if x0+i >= N or y0+j >= N:
        return False
      if A[x0+i][y0+j] != B[i][j]:
        return False
  return True

if M > N:
  print('No')
  exit()


for x in range(N):
  for y in range(N):
    if not serch(x,y):
      continue
    else:
      print('Yes')
      exit()
print('No')


Measured memory_bytes: 8976
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    long long int c=0;
    for(int i=0;i<n-1;i++)
    {
        if(a[i+1]<a[i])
        {
            c=c+a[i]-a[i+1];
            a[i+1]=a[i];
        }
    }
    cout<<c;
}

Measured memory_bytes: 4428
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9+7;
struct M {
  int n,m;
  vector<vector<int>> a;
  M(int _n,int _m) : n(_n),m(_m) {
    a.resize(n,vector<int>(m));
  }
  M operator*(const M& b) {
    auto c = M(n,b.m);
    for(int i=0;i<n;i++)
    for(int j=0;j<b.m;j++)
    for(int k=0;k<m;k++) {
      c.a[i][j] += a[i][k]*b.a[k][j];
      c.a[i][j] %= mod;
    }
    return c;
  }
};
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int n,k;
  cin >> n >> k;
  M a(n,n);
  for(int i=0;i<n;i++) {
    for(int j=0;j<n;j++) {
      cin >> a.a[i][j];
    }
  }
  auto res = M(n,n);
  for(int i=0;i<n;i++) res.a[i][i] = 1;
  while(k) {
    if (k%2) {
      res = res * a;
    }
    a = a * a;
    k /= 2;
  }
  auto unitM = M(n,1);
  for(int i=0;i<n;i++) unitM.a[i][0] = 1;
  auto ans = res * unitM;
  int fans = 0;
  for(int i=0;i<n;i++) fans = (fans + ans.a[i][0])%mod;
  cout << fans << '\n';
  return 0;
}

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

int main(){
  int H, W;
  cin >> H >> W;
  string board[H];

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

  // 文字列入力
  for(int i = 0; i < H; i++){
    cin >> board[i];
  }

  // 周囲に地雷があったらその数をカウント
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j ++){
      // そのコマが「#」なら処理しない
      if(board[i][j] == '#') continue;

      int num = 0;
      for(int k = 0; k < 8; k++){
        int ik = i + dy[k];
        int jk = j + dx[k];

        if(ik < 0 || ik >= H) continue;
        if(jk < 0 || jk >= W) continue;
        // 周囲に地雷があったら数をインクリメント
        if(board[ik][jk] == '#') num++;
      }
      // コマの「.」を地雷の数に置き換える
      board[i][j] = char(num + '0');
    }
  }

  // 変換後の文字列出力
  for(int i = 0; i < H; i++){
    cout << board[i] << endl;
  }


}

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

long long int min_cost(int height[], int i, long long int dp[]) {
    if (i == 0) {
        return 0;
    }
    if(i == 1) {
        dp[1] = abs(height[1] - height[0]);
    }
    if (dp[i] != -1) return dp[i];
    return dp[i] = min(min_cost(height, i - 1, dp) + abs(height[i] - height[i - 1]),
                       min_cost(height, i - 2, dp) + abs(height[i] - height[i - 2]));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int height[n];
    for (int i = 0; i < n; ++i) {
        cin >> height[i];
    }
    long long int dp[n];
    for (int i = 0; i < n; ++i) {
        dp[i] = -1;
    }
    cout << min_cost(height, n - 1, dp) << endl;
    return 0;
}

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

#define FOR(i, a, b) for(int(i)=(a);(i)<(b);(i)++)
#define REP(i, n) FOR((i), 0, (n))

#define RFOR(i, b, a) for(int(i)=(b); (i)>=(a); (i)--)
#define RREP(i, n) FOR((i), (n), 0)

#define pb push_back
#define mp make_pair 

using namespace std;

const int INF=INT_MAX/4;
const int MOD=1000000007;
const double EPS=1e-14;

const bool debug_flag=true;

void debug(string str){
	if(debug_flag){
		cout<<str<<endl;
	}
}

void debugs(string str){
	if(debug_flag){
		cout<<str;
	}
}

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout.precision(10);

	string str;
	cin>>str;
	if(str.substr(0, 4)=="YAKI"){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}



	return 0;
}



Measured memory_bytes: 256
def main():
    N, M = (int(i) for i in input().split())
    dic = {}
    for i in range(M):
        s, c = (i for i in input().split())
        if s in dic.keys() and dic[s] != c:
            return print(-1)
        dic[s] = c
    for t in range(1000):
        t = str(t)
        if len(t) != N:
            continue
        for k, v in dic.items():
            if t[int(k)-1] != v:
                break
        else:
            return print(t)
    print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

void Dfs(vector<string> &A,string S,int idx,int k, int N){
    if(idx>=N){
        A.push_back(S);
        return;
    }

    rep(i,0,k){
        S.at(idx)='a'+i;
        Dfs(A,S,idx+1,max(k,i+2),N);
    }
}

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

    vector<string> ans;
    string _ans;
    rep(n,0,N) _ans+='a';

    Dfs(ans,_ans,1,2,N);

    for(auto a:ans) cout<<a<<endl;
}

Measured memory_bytes: 7796
#include<stdio.h>
#include<string.h>
//言語は「C++14(GCC 5.4.1)」
//AtCoder Beginner Contest 154-A
int main(void)
{
	char S[10], T[10], U[10];
	int A, B;
	scanf("%s", S); scanf("%s", T);
	scanf("%d", &A); scanf("%d", &B);
	scanf("%s", U);
	if (strcmp(U, S) == 0)
		A = A - 1;
	else if (strcmp(U, T) == 0)
		B = B - 1;
	printf("%d %d", A, B);
	return 0;
}

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

typedef long long LL;

#define FOR(i, a, b) for (int i = (a), i##_END_ = (b); i <= i##_END_; i++)
#define DNF(i, a, b) for (int i = (a), i##_END_ = (b); i >= i##_END_; i--)

template <typename Tp> void in(Tp &x) {
	char ch = getchar(), f = 1; x = 0;
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') ch = getchar(), f = -1;
	while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	x *= f;
}

template <typename Tp> void out(Tp x) {
	if (x > 9) out(x / 10);
	putchar(x % 10 + '0');
	return;
}

template <typename Tp> Tp Max(const Tp &x, const Tp &y) {return x > y ? x : y;}
template <typename Tp> Tp Min(const Tp &x, const Tp &y) {return x < y ? x : y;}
template <typename Tp> bool chkmax(Tp &x, Tp y) {return x >= y ? 0 : (x=y, 1);}
template <typename Tp> bool chkmin(Tp &x, Tp y) {return x <= y ? 0 : (x=y, 1);}

const int MAXN = 2010;

int n, k, q, B[MAXN], A[MAXN], D[MAXN], C[MAXN], ans = 0x3f3f3f3f;

void solve(int x)
{
	D[0] = 0;
	for (int i = 1, j; i <= n; i = j + 1) {
		j = i; if (A[i] < x) continue;
		while (j < n && A[j + 1] >= x) j++;
		C[0] = 0;
		FOR(l, i, j) C[++C[0]] = A[l];
		if (C[0] < k) continue;
		std::sort(C + 1, C + C[0] + 1);
		FOR(l, 1, C[0] - k + 1) D[++D[0]] = C[l];
	}
	if (D[0] < q) return;
	std::sort(D + 1, D + D[0] + 1);
	chkmin(ans, D[q] - D[1]);
}

int main()
{
	in(n); in(k); in(q);
	FOR(i, 1, n) in(A[i]), B[i] = A[i];

	std::sort(B + 1, B + n + 1);

	FOR(i, 1, n) solve(B[i]);

	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
X, N = map(int, input().split())
p = list(map(int, input().split()))
flag = True
dif = 0
while flag == True:
    flag_m = False
    flag_p = False

    x_m = X - dif
    x_p = X + dif

    for i in range(N):
        if x_m == p[i]:
            flag_m = True
        if x_p == p[i]:
            flag_p = True

    if flag_m == False:
        flag = False
        print(x_m)
    elif flag_p == False:
        flag = False
        print(x_p)

    dif += 1


Measured memory_bytes: 9204
N = gets.to_i
as = gets.split.map(&:to_i)

even = 0
odd = 0
(0...(N/2)).each do |i|
    even += as[2 * i] if as[2 * i] > 0
    odd += as[2 * i + 1] if as[2 * i + 1] > 0
end
even += as[N - 1] if N % 2 == 1 && as[N - 1] > 0

max = as[0]
max_i = 0
N.times do |i|
    if as[i] > max
        max = as[i]
        max_i = i
    end
end

if max <= 0
    print max, "\n"
    print N - 1, "\n"
    until as[0] == max do
        print 1, "\n"
        as.shift
    end
    until as.length == 1 do
        print as.length, "\n"
        as.pop
    end
    exit
end


sum = [even, odd].max

seq = []

if even < odd
    as.shift
    seq.push(1)
end

pointer = 0
while pointer < as.length - 1 do
    if as[pointer] <= 0
        if pointer == 0
            seq.push(1)
            seq.push(1)
        else
           seq.push(pointer + 1) 
        end
        as.delete_at(pointer + 1)
        as.delete_at(pointer)
    else
        pointer += 2
    end
end

until as.length % 2 == 1 && as[-1] > 0 do
    seq.push(as.length)
    as.pop
end

(as.length / 2).times do |i|
    seq.push(2)
end

print sum, "\n", seq.length, "\n"
seq.each do |i|
    print i, "\n"
end

Measured memory_bytes: 3836
package main

import "fmt"

func main() {
	var n, y int
	fmt.Scan(&n, &y)

	for i := 0; i <= n; i++ {
		for j := 0; i+j <= n; j++ {
			k := n - i - j
			if i*10000+j*5000+k*1000 == y {
				fmt.Println(i, j, k)
				return
			}
		}
	}
	fmt.Println(-1, -1, -1)
}


Measured memory_bytes: 512
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]


x,k,d = map(int, input().split())

x = abs(x)

if x - k * d >= 0:
    print(x-k*d)
    exit()

tmp = k - x//d

if (tmp % 2 != 0):
    print(abs(x-x//d*d-d))
else:
    print(abs(x-x//d*d))



Measured memory_bytes: 9168