akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> veci;
typedef vector<ll> vecll;
typedef vector<string> vecs;
template<class T,class U> using Hash=unordered_map<T,U>;
 
#define REP(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define RREP(i, a, n) for(ll i = n-1; i >= (ll)(a); i--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, 0, n)
#define MD 1000000007
#define _SPLIT " "
 
template<class T> T read(){T a;cin >> a;return a;}
template<class T> void read(T& a){cin >> a;}
template<class T,class ...Args> void read(T& a, Args&... args){cin >> a; read(args...);} 
template<class T> void rarr(T a, int n){for(int i = 0; i < n; i++) {cin >> a[i];}}
template<class T> void write(T a){cout << setprecision(24) << a << endl;}
template<class T,class ...Args> void write(T a, Args... args){cout << setprecision(24) << a << _SPLIT; write(args...);}
template<class T> void warr(vector<T> a, const char* c = " "){cout << a[0];for(int i = 1; i < (int)a.size(); i++)cout << c << a[i];cout << endl;;}
template<class T> void warr(T a, int n, const char* c = " "){cout << a[0];for(int i = 1; i < n; i++)cout << c << a[i];cout << endl;}
template<class T> void warr(T begin, T end, const char* c = " "){cout << *begin;for(auto i = begin+1; i != end; i++)cout << c << *i;cout << endl;}
void split(string s, string delim, veci& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(atoi(s.substr(pos).data()));break;}else {result.push_back(atoi(s.substr(pos, p - pos).data()));}pos = p + delim.size();}}
void split(string s, string delim, vecs& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(s.substr(pos));break;}else {result.push_back(s.substr(pos, p - pos));}pos = p + delim.size();}}
ll gcd(ll a, ll b){while(true){ll k = a % b;if(k == 0)return b;a = b;b = k;}}
ll comb(ll n, ll m){ll p=1;m=min(m,n-m);for(ll i=1;i<=m;i++){p*=n-i+1;p/=i;}return p;}

int main(void)
{
    int a[3];
    rep(i,3)read(a[i]);
    rep(i,3){
        int s=0;
        rep(j,3)if(i!=j)s+=a[j];
        if(s==a[i])write("Yes"),exit(0);
    }
    write("No");
    return 0;
}

Measured memory_bytes: 256
io = STDIN
n,m=io.gets.split.map(&:to_i)
a=io.gets.split.map(&:to_i).sort
bc=m.times.map{io.gets.split.map(&:to_i)}.sort_by{|b,c|-c}
i=0
add=0
bc.each do |b,c|
  next if a[i]>=c
  b.times do
    break if a[i]>=c
    add+=c-a[i]
    i+=1
    break if i>=n
  end
  break if i>=n
end
puts a.inject(:+)+add


Measured memory_bytes: 21252
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
multiset<int> ps;
int n,a[SZ];
ll pf[SZ],sf[SZ];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n+n+n;i++)
		scanf("%d",a+i);
	ll sum=0;
	for(int i=1;i<=n+n+n;i++)
	{
		sum+=a[i]; ps.insert(a[i]);
		if(ps.size()>n)
		{
			sum-=*ps.begin();
			ps.erase(ps.begin());
		}
		if(ps.size()==n) pf[i]=sum;
		else pf[i]=-1e18;
	}
	ps.clear(); sum=0;
	for(int i=n+n+n;i>=1;--i)
	{
		sum+=-a[i]; ps.insert(-a[i]);
		if(ps.size()>n)
		{
			sum-=*ps.begin();
			ps.erase(ps.begin());
		}
		if(ps.size()==n) sf[i]=sum;
		else sf[i]=-1e18;
	}
	ll ans=-1e18;
	for(int i=1;i<n+n+n;i++)
		ans=max(ans,pf[i]+sf[i+1]);
	printf("%lld\n",ans);
}


Measured memory_bytes: 15104
// AOJ 2022 Princess, a Cryptanalyst
// 2018.3.16 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int N;
char word[10][12]; int sz[12];

// 単語間の一致関係
// [a][b]=k 単語bの先頭k文字が単語aの末尾と一致
char in[10][10];

char ans[110]; int len;
char cand[110];
char f[10];

int naiveMatch(char *text, int len, char *pattern, int patlen)
{
	char c;
	char *tp, *pp;
	char *textEnd, *patEnd;

	if (len < patlen) return 0;

	textEnd = text + len - patlen + 1;
	patEnd = pattern + patlen;

	c = *pattern++;
	while (text != textEnd) {
		if (*text++ == c) {
			tp = text;
			pp = pattern;
			do if (pp == patEnd) return 1;
			while (*tp++ == *pp++);
		}
	}
	return 0;
}

void calc()
{
	int i, j, k;
	char *p;

	memset(in, 0, sizeof(in));
	for (i = 0; i < N; i++) {
		for (j = 0; j < N; j++) if (i != j) {
			for (k = sz[i] - 1, p = word[i] + 1; k; k--, p++) {
				if (!memcmp(p, word[j], k)) {
					in[i][j] = k;
					break;
				}
			}
		}
	}
}

void rec(int n, int pre, int w)
{
	int i, t;

	if (n == N) {
		if (w < len || (w == len && memcmp(ans, cand, w) > 0)) {
			memcpy(ans, cand, w), len = w, ans[w] = 0;
		}
		return;
	}
	for (i = 0; i < N; i++) if (!f[i]) {
		t = sz[i] - in[pre][i];
		if (t < len) {
			f[i] = 1;
			memcpy(cand + w, word[i] + in[pre][i], t);
			rec(n + 1, i, w + t);
			f[i] = 0;
		}
	}
}

int main()
{
	int i, j;

	while (scanf("%d", &N) && N) {
		for (i = 0; i < N; i++) {
			scanf("%s", word[i]);
			sz[i] = strlen(word[i]);
		}

		// 完全一致する単語の排除
		memset(f, 0, sizeof(f));
		for (i = 0; i < N; i++) {
			if (f[i]) continue;
			for (j = i + 1; j < N; j++) if (!f[j]) {
				if (naiveMatch(word[i], sz[i], word[j], sz[j])) f[j] = 1;
				else if (naiveMatch(word[j], sz[j], word[i], sz[i])) {
					f[i] = 1;
					break;
				}
			}
		}
		i = 0; for (j = 0; j < N; j++) if (!f[j]) {
			if (j != i) strcpy(word[i], word[j]), sz[i] = sz[j];
			i++;
		}
		N = i;

		calc();

		len = 10000;
		memset(f, 0, sizeof(f));
		for (i = 0; i < N; i++) {
			f[i] = 1;
			memcpy(cand, word[i], sz[i]);
			rec(1, i, sz[i]);
			f[i] = 0;
		}
		puts(ans);
	}
	return 0;
}


Measured memory_bytes: 2044
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
lint x[100100],v[100100],s[100100];
lint dp[2][100100];//片道
lint d2[2][100100];//往復
int main()
{
	int n;lint c;
	cin>>n>>c;
	rep(i,n) cin>>x[i]>>v[i];
	s[0]=0;rep(i,n) s[i+1]=s[i]+v[i];
	dp[0][0]=d2[0][0]=0;
	rep(i,n){
		dp[0][i+1]=max(dp[0][i],s[i+1]-x[i]);
		d2[0][i+1]=max(d2[0][i],s[i+1]-x[i]*2);
	}
	dp[1][n]=d2[1][n]=0;
	for(int i=n-1;i>=0;i--){
		dp[1][i]=max(dp[1][i+1],(s[n]-s[i])-(c-x[i]));
		d2[1][i]=max(d2[1][i+1],(s[n]-s[i])-(c-x[i])*2);
	}
	lint out=0;
	rep(i,n+1) out=max(max(dp[0][i]+d2[1][i],dp[1][i]+d2[0][i]),out);
	cout<<out<<endl;
}


Measured memory_bytes: 5760
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		while (true) {
			int m = scn.nextInt();
			int f = scn.nextInt();
			int r = scn.nextInt();
			if (m == -1 && f == -1 && r == -1) {
				break;
			}
			if (m == -1 || f == -1) {
				System.out.println("F");
			} else if (m + f >= 80) {
				System.out.println("A");
			} else if (m + f >= 65 && m + f < 80) {
				System.out.println("B");
			} else if (m + f >= 50 && m + f < 65) {
				System.out.println("C");
			} else if (m + f >= 30 && m + f < 50) {
				if (r >= 50) {
					System.out.println("C");
				} else {
					System.out.println("D");
				}
			} else if (m + f < 30) {
				System.out.println("F");
			}
		}
	}
}



Measured memory_bytes: 26184
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 2e5 + 7;
const int INF = 1e9;
int a[MAXN];
#define lson (rt << 1)
#define rson (rt << 1 | 1)
struct node{int val, pos;} T[MAXN << 2][2];
bool lazy[MAXN << 2];
node merge(node &Tl, node &Tr)
{
    if (Tl.val < Tr.val) return Tl;
    else return Tr;
}
void pushup(int rt) 
{
    for (int i = 0; i < 2; i++) T[rt][i] = merge(T[lson][i], T[rson][i]);
}
void build(int rt, int l, int r)
{
    if (l == r) 
    {
        T[rt][(l % 2)] = {a[l], l};
        T[rt][(l % 2) ^ 1] = {INF, l};
        return;
    }
    int mid = (l + r) >> 1;
    build(lson, l, mid);
    build(rson, mid + 1, r);
    pushup(rt);
}
void update(int rt) {swap(T[rt][0], T[rt][1]); lazy[rt] ^= 1;}
void pushdown(int rt)
{
    if (!lazy[rt]) return;
    update(lson); update(rson);
    lazy[rt] = 0;
}
void modify(int rt, int l, int r, int L, int R)
{
    if (L <= l && r <= R) {update(rt); return;}
    int mid = (l + r) >> 1;
    pushdown(rt);
    if (L <= mid) modify(lson, l, mid, L, R);
    if (mid <  R) modify(rson, mid + 1, r, L, R);
    pushup(rt);
}
node query(int rt, int l, int r, int L, int R, int c)
{
    if (L <= l && r <= R) return T[rt][c];
    int mid = (l + r) >> 1; 
    pushdown(rt);
    node Tl = {INF, -1};
    node Tr = Tl;
    if (L <= mid) Tl = query(lson, l, mid, L, R, c);
    if (mid <  R) Tr = query(rson, mid + 1, r, L, R, c);
    return merge(Tl, Tr);
} 
void modi_pos(int rt, int l, int r, int pos)
{
    if (l == r) { T[rt][0].val = T[rt][1].val = INF; return;}
    int mid = (l + r) >> 1;
    pushdown(rt);
    if (pos <= mid) modi_pos(lson, l, mid, pos);
    else modi_pos(rson, mid + 1, r, pos);
    pushup(rt);
}
int main()
{
    int n; scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    build(1, 1, n);
    set<int>pt; pt.insert(n + 1);
    for (int _ = 1; _ <= n; _ += 2)
    {
        node p1 = T[1][1];
        int pos = *pt.lower_bound(p1.pos) - 1;
        node p2 = query(1, 1, n, p1.pos + 1, pos, 0);
        printf("%d %d ", p1.val, p2.val);
        modi_pos(1, 1, n, p1.pos); pt.insert(p1.pos);
        modi_pos(1, 1, n, p2.pos); pt.insert(p2.pos);
        if (p1.pos + 1 <= p2.pos - 1) modify(1, 1, n, p1.pos + 1, p2.pos - 1);
    }
    return 0;   
}

Measured memory_bytes: 21760
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
  string s1,s2,s3;
  cin >> s1 >> s2 >> s3;
  
  printf("%c%c%c\n",s1[0]-32,s2[0]-32,s3[0]-32);

  return 0;
}


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

#define ll long long
using namespace std;

const int N = 1e5 + 5, M = 1e9 + 7;
int n, u, v;
vector<int> adj[N];
bool vis[N];
ll dpblack[N], dpwhite[N];

// dpwhite = prod(dpblack)
// dpblack = dpwhite + prod(dpwhite)

void dfs(int x) {
    vis[x] = true;
    dpwhite[x] = dpblack[x] = 1;
    for(int y : adj[x]) {
        if(!vis[y]) {
            dfs(y);
            dpwhite[x] = (dpwhite[x] * dpblack[y]) % M;
            dpblack[x] = (dpblack[x] * dpwhite[y]) % M;
        }
    }
    dpblack[x] = (dpblack[x] + dpwhite[x]) % M;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for(int i = 0; i < n - 1; i++) {
        cin >> u >> v;
        u--; v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(0);
    cout << dpblack[0] << endl;
}

Measured memory_bytes: 11520
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
using namespace std;
string a,b,c="";
signed main(){
	cin>>a>>b;
	for(int i=0;i<a.size()+b.size();i++){
		if(i%2==0){
			c=c+a[i/2];
		}else{
			c=c+b[i/2];
		}
	}
	cout<<c;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    char[] c = sc.next().toCharArray();
    int number1 = Character.getNumericValue(c[0]) * 10 + Character.getNumericValue(c[1]);
    int number2 = Character.getNumericValue(c[2]) * 10 + Character.getNumericValue(c[3]);

    //System.out.println(number1);
    //System.out.println(number2);

    int count1 = 0;
    int count2 = 0;

    if(number1<=12 && number1>0){
      count1 += 1;
    }
    if(number2<=12 && number2>0){
      count2 += 1;
    }
    if(count1==1 && count2==1){
      System.out.println("AMBIGUOUS");
    }
    if(count1==0 && count2==1){
      //System.out.println(c);
      System.out.println("YYMM");
    }
    if(count1==1 && count2==0){
      //System.out.println(c[2]+""+c[3]+""+c[0]+""+c[1]);
      System.out.println("MMYY");
    }
    if(count1==0 && count2==0){
      System.out.println("NA");
    }


  }
}

Measured memory_bytes: 21716
import java.util.*;

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

		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		ArrayList<Integer> xArrayList = new ArrayList<>();

		for (int i=0; i<n; i++){
			xArrayList.add(Integer.parseInt(sc.next()));
		}
		Collections.sort(xArrayList);

		int ans = Integer.MAX_VALUE;
		for (int i=0; i<n-k+1; i++){
			ans = Math.min(ans, Math.min(Math.abs(xArrayList.get(i)) + Math.abs(xArrayList.get(i+k-1) - xArrayList.get(i)), Math.abs(xArrayList.get(i+k-1)) + Math.abs(xArrayList.get(i) - xArrayList.get(i+k-1))));
		}

		System.out.println(ans);
	}
}

Measured memory_bytes: 48984
/* * * * * * * * * * * **
*                      *
*	   saurabh8522	   *
*	  I will handle	   *
*		   IT.		   *
*                      *
* * * * * * * * * * * **/
#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ld long double
#define zero(a) memset((a),0,sizeof((a)))
#define one(a) memset((a),1,sizeof((a)))
#define minus(a) memset((a),-1,sizeof((a)))
#define all(g) g.begin(),g.end()
#define ppb pop_back
using namespace std;
typedef long long int ll;
#define MOD 1000000007
ll extgcd(ll a,ll b,ll& x,ll& y){if(b==0){x=1;y=0;return a;}else{int g=extgcd(b,a%b,y,x);y-=a/b*x;return g;}}
ll modpow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll numdigit(ll n){return floor(log10(n)) + 1;}
bool isPowerTwo (ll x) { return x && (!(x&(x-1))); } 
// ll dp[3001][3001];
// ll find(string s,string t,ll i,ll j){
// 	if(i>=s.size()||j>=t.size()) return 0;
// 	ll &ans=dp[i][j];
// 	if(ans!=-1) return ans;
// 	if(s[i]==t[j]){
// 		ans=1+find(s,t,i+1,j+1);
// 	}
// 	else ans=max(ans,max(find(s,t,i,j+1),find(s,t,i+1,j)));
// 	return ans;
// }
int  main(){
	FastRead;
	ll t=1;
	// cin>>t;
	while(t--){
		string s,u;
		cin>>s>>u;
		// cout<<s<<" "<<u<<endl;
		int n=s.size(),m=u.size();
		// cout<<n<<" "<<m<<endl;
		ll dp[n][m];
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				dp[i][j]=0;
			}
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				if(s[i]==u[j]){
					dp[i][j]=(i==0||j==0)?1:dp[i-1][j-1]+1;
				}
				else{
					dp[i][j]=max((i==0)?0:dp[i-1][j],(j==0)?0:dp[i][j-1]);
				}
				// cout<<i<<" "<<j<<endl;
			}
		}
		string ans="";
		int i=n-1,j=m-1;
		// cout<<dp[n-1][m-1]<<endl;
		while(i>=0&&j>=0){
			if(s[i]==u[j]){
				ans+=s[i];
				i--;j--;
				continue;
			}
			if(dp[i][j]==dp[i-1][j]&&i>0){
				i--;
			}
			else{
				j--;
			}
		}
		reverse(ans.begin(),ans.end());
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 70656
//http://drken1215.hatenablog.com/entry/2018/07/18/214400
//を参考
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
const int MAXN=30;
const int INF=1e9;
double dp[MAXN+5][MAXN+5][MAXN+5];// 現在地点,直前の地点,今の速度
int n,m;
double ans=INF;
template<typename A,size_t N,typename T>
void Fill(A (&array)[N],const T &val)
{
  std::fill( (T*)array,(T*)(array+N),val );
}

struct State
{
  double cost;
  int now,prev,speed;
  State(double c,int n,int p,int s):cost(c),now(n),prev(p),speed(s){}//コスト,現在地,直前の地点,今の速度

  bool operator < (State s)const 
  {
    return s.cost<cost;
  }
};

struct Edge
{
  int to,dist,limit;
  Edge(int t,int d,int l):to(t),dist(d),limit(l){}
};

vector<Edge> Graph[MAXN+5];

int main(void)
{
  while(cin >> n >> m && n)
    {
      int s,t;
      cin >> s >> t;
      for (int i = 0; i <= MAXN; ++i)
	{
	  for (int j = 0; j <= MAXN; ++j)
	    {
	      for (int k = 0; k <= MAXN; ++k)
		{
		  dp[i][j][k]=INF;
		}
	    }
	}
      for(int i=0;i<MAXN+5;i++)
	{
	  Graph[i].clear();
	}
      for (int i = 0; i < m; ++i)
	{
	  int x,y,d,c;
	  cin >> x >> y >> d >> c;
	  Graph[x].push_back(Edge(y,d,c));
	  Graph[y].push_back(Edge(x,d,c));
	}
      ans=INF;
      priority_queue<State> que;//上のStateと持つ状態は同じ
      que.push(State(0.0,s,0,1));
      dp[s][0][1]=0.0;
      while(!que.empty())
	{
	  auto state=que.top();que.pop();
	  int nowpoint=state.now;
	  int prevpoint=state.prev;
	  int nowspeed=state.speed;
	  double nowcost=state.cost;
	  for (int i = 0; i < int(Graph[nowpoint].size()); ++i)
	    {
	      for(int j=-1;j<=1;j++)
		{
		  if(prevpoint==0)
		    {
		      if(j==-1 || j==1) continue;
		    }
		  int nextspeed=nowspeed+j;
		  int nextpoint=Graph[nowpoint][i].to;
		  int nextlimit=Graph[nowpoint][i].limit;
		  double gocost=(double)Graph[nowpoint][i].dist/(double)nextspeed;
		  if(nextpoint==prevpoint) continue;
		  if(nextspeed>nextlimit) continue;
		  if(dp[nextpoint][nowpoint][nextspeed]>nowcost+gocost)
		    {
		      dp[nextpoint][nowpoint][nextspeed]=nowcost+gocost;
		      que.push(State(dp[nextpoint][nowpoint][nextspeed],nextpoint,nowpoint,nextspeed));
		    }
		}
	    }
	}
      for (int i = 1; i <= n; ++i)
	{
	  if(dp[t][i][1]<ans) ans=dp[t][i][1];
	}
      if(ans==INF) cout << "unreachable" << endl;
      else cout << fixed << setprecision(12) << ans << endl;
    }
  return 0;
 
}



Measured memory_bytes: 3852
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>

typedef long long int ll;

using namespace std;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int count=0;
    for (int i=a;i<=b;++i){
        if(c%i==0){
            ++count;
        }
    }
    cout << count << endl;
    return 0;
}



Measured memory_bytes: 3100
//om nama sivaya
#include<bits/stdc++.h>
#define M 1000000007
#define ll long long
using namespace std;
void solve(){
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    //c>b>a
    while(b<=a){
        b*=2;
        k--;
    }
    while(c<=b){
        c*=2;
        k--;
    }
    if(k>=0)
    cout<<"Yes";
    else
    cout<<"No";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44


/*const int MOD = (int) 1e9 + 7;

inline void mod(int &x) {
    if(x >= MOD)
        x -= MOD;
}

inline void add(int &x, int y) {
    x += y;
    mod(x);
}

inline void mul(int &x, int y) {
    x = (1LL * x * y) % MOD;
}*/

using namespace std;

const int MAXN = 17;

ll arr[MAXN + 1];

inline ll solve(int l, int r, ll a, ll b) {
    if(r - l <= 1) {
        return 0;
    }

    ll ans = 1e18;
    for(int i = l + 1; i < r; i++) {
        ans = min(ans, solve(l, i, a, a + b) + solve(i, r, a + b, b) + 1LL * (a + b) * arr[i]);
    }
    return ans;
}

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, n;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    cin >> n;

    for(i = 1; i <= n; i++) {
        cin >> arr[i];
    }

    cout << solve(1, n, 1, 1) + arr[1] + arr[n];

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n,k,ans=0,cnt=0;
  cin>>n>>k;
  vector<int>vec(n);
  rep(i,n){
    int a;
    cin>>a;
    if (vec.at(a-1)==0) {
      cnt+=1;
    }
    vec.at(a-1)+=1;
  }
  sort(vec.begin(),vec.end());
  if (cnt<=k) {
    cout<<0<<endl;
  }
  else{
    cnt=cnt-k;
    rep(j,n){
      if (cnt==0) {
        break;
      }
      else if (vec.at(j)!=0) {
        ans+=vec.at(j);
        cnt-=1;
      }
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    string s;
    cin >> s;
    int n = s.size();
    int diff = 753;
    REP(i,0,n-2) {
        string x = s.substr(i,3);
        diff = min(diff, abs(753 - stoi(x)));
    }
    cout << diff << endl;
}

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

Measured memory_bytes: 256
from itertools import permutations
n, m, r = map(int, input().split())
R = list(map(lambda x: int(x)-1, input().split()))
INF = 10**18
dist = [[INF]*n for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    dist[a-1][b-1] = c
    dist[b-1][a-1] = c

for k in range(n):
    for i in range(n):
        for j in range(n):
            dist[i][j] = min(dist[i][k]+dist[k][j], dist[i][j])

ans = INF
for subset in permutations(R):
    d = 0
    for v, v2 in zip(subset, subset[1:]):
        d += dist[v][v2]
    if d < ans:
        ans = d
print(ans)


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

int main() {
	
	int n, k; cin >> n >> k;
	const int p = 10;
	vector<bool> canUse(p, true);
	for (int i = 0; i < k; i++) {
		int d; cin >> d;
		canUse[d] = false;
	}
	int ans;
	int now = n;
	while (true) {
		string now_s = to_string(now);
		bool ok = true;
		for (int i = 0; i < now_s.size(); i++) {
			for (int j = 0; j < p; j++) {
				if (!canUse[(int)(now_s[i] - '0')]) {
					ok = false;
					break;
				}
			}
		}
		if (ok) {
			ans = now;
			break;
		}
		now++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3696
/*Lucky_Glass*/
#include<cstdio>
#include<iostream>
#include<cmath>
#include<queue>
using namespace std;
int main()
{
	int n,dx=0,dy=0,dt=0;
	scanf("%d",&n);
	bool T=true;
	for(int i=0;i<n;i++)
	{
		int t,x,y;
		scanf("%d%d%d",&t,&x,&y);
		if(abs(x-dx)+abs(y-dy)+dt<=t)
			if((t-abs(x-dx)+abs(y-dy)-dt)%2)
				T=false;
			else
				dx=x,dy=y,dt=t;
		else
			T=false;
	}
	if(T) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
b1,b2,b3= map(int, input().split())
if (b1==1 and b2==0 and b3==0):
    print("Close")
elif (b1==0 and b2==1 and b3==0):
    print("Close")
elif (b1==1 and b2==1 and b3==0):
    print("Open")
elif (b1==0 and b2==0 and b3==1):
    print("Open")
else:
    print("Close")
    


Measured memory_bytes: 5592
#include <algorithm>
#include <bitset>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
#define cerr                                                                   \
  if (true)                                                                    \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;
typedef pair<int, int> pp;       // int aa = pp.first;
typedef tuple<int, int, int> tp; // int aa = get<0>(tp);

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

class BIT {
public:
  vector<int> bit;
  int M;

  BIT(int M) : bit(vector<int>(M + 1, 0)), M(M) {}

  int get(int i) const {
    if (!i)
      return 0;
    return bit[i] + get(i - (i & -i));
  }

  void add(int i, int x) {
    if (i > M)
      return;
    bit[i] += x;
    add(i + (i & -i), x);
  }
};

BIT bit(100010);
void solve(long long N, long long M, vector<long long> &l,
           vector<long long> &r) {

  vector<tp> vtp;
  REP(i, N) { vtp.push_back(tp(r[i] - l[i] + 1, l[i], r[i])); }
  sort(ALL(vtp));

  int pc = 0;
  FOR(m, 1, M + 1) {
    int ans = 0;

    while (pc < N && get<0>(vtp[pc]) < m) {
      bit.add(get<1>(vtp[pc]), 1);
      bit.add(get<2>(vtp[pc]) + 1, -1);
      pc++;
    }

    ans += N - pc;

    for (int v = m; v <= M; v += m) {
      ans += bit.get(v);
    }

    cout << ans << endl;
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N;
  long long M;
  cin >> N;
  vector<long long> r(N - 1 + 1);
  vector<long long> l(N - 1 + 1);
  cin >> M;
  for (int i = 0; i <= N - 1; i++) {
    cin >> l[i];
    cin >> r[i];
  }
  solve(N, M, l, r);
  return 0;
}


Measured memory_bytes: 11632
#include <cstdio>
using namespace std;
static_assert(sizeof(long) >= 8, "long too short");
int main() {
    long x, y;
    scanf("%ld %ld", &x, &y);
    int ans = 1;
    while (x * 2 <= y) {
        x *= 2;
        ans++;
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 128
def cal_expo(m, n, MOD):
    if m == 1:
        return 1
    ans = 1
    while n != 1:
        if n % 2 != 0:
            ans = (ans * m) % MOD
        n //= 2
        m = (m ** 2) % MOD
    ans = (ans * m) % MOD
    return ans


def main():
    m, n = map(int, input().split())
    MOD = 10 ** 9 + 7
    ans = cal_expo(m, n, MOD)
    print(ans)


if __name__ == '__main__':
    main()



Measured memory_bytes: 5600
#include <iostream>

#define N 12

std::string island[N];

void dfs( int i, int j ) {
    int dx[] = { -1,  0,  1,  0 };
    int dy[] = {  0, -1,  0,  1 };
    island[i][j] = '0';
    for (int k=0; k<4; ++k) {
        int x = i+dx[k], y = j+dy[k];
        if ( 0<=x && x<N && 0<=y && y<N && island[x][y] == '1' ) {
            dfs( x, y );
        }
    }
}

void solve() {
    unsigned int num = 0;
    for (int i=0; i<N; ++i) {
        for (int j=0; j<N; ++j) {
            if ( island[i][j] == '1' ) {
                ++num;
                dfs( i, j );
            }
        }
    }
    std::cout << num << std::endl;
}

int main() {
    while ( std::cin >> island[0] ) {
        for (int i=1; i<N; ++i) {
            std::cin >> island[i];
        }
        solve();
    }
    return 0;
}



Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(ll i = (ll)(k); i < (ll)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll, ll> pii;
const ll MOD = 1000000007;
const ll INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/
const ll mod = 1000000007;

struct Mod {
	ll n;
	Mod() : n(0) { ; }
	Mod(ll m) : n(m) {
		if (n >= mod) n %= mod;
		else if (n < 0) n = (n % mod + mod) % mod;
	}
	operator ll() { return n; }
};

bool operator==(Mod a, Mod b) { return a.n == b.n; }
Mod operator+=(Mod &a, Mod b) { a.n += b.n; if (a.n >= mod) a.n -= mod; return a; }
Mod operator-=(Mod &a, Mod b) { a.n -= b.n; if (a.n < 0) a.n += mod; return a; }
Mod operator*=(Mod &a, Mod b) { a.n = ((long long)a.n * b.n) % mod; return a; }
Mod operator+(Mod a, Mod b) { return a += b; }
Mod operator-(Mod a, Mod b) { return a -= b; }
Mod operator*(Mod a, Mod b) { return a *= b; }
Mod operator^(Mod a, ll n) {
	if (n == 0) return Mod(1);
	Mod res = (a * a) ^ (n / 2);
	if (n % 2) res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
Mod operator/(Mod a, Mod b) { return a * Mod(inv(b, mod)); }

#define MAX_N 1024000

Mod fact[MAX_N], factinv[MAX_N];
void init() {
	fact[0] = Mod(1); factinv[0] = 1;
	REP(i, MAX_N - 1) {
		fact[i + 1] = fact[i] * Mod(i + 1);
		factinv[i + 1] = factinv[i] / Mod(i + 1);
	}
}
Mod comb(ll a, ll b) {
	return fact[a] * factinv[b] * factinv[a - b];
}

int main()
{
	cin.sync_with_stdio(false);
	init();
	ll h, w, a, b; cin >> h >> w >> a >> b;
	Mod sum = comb(h+w-2, h-1);
	if (a < b)
	{
		REP(i, a)
		{
			ll sta = h - 1 + (b - a), stb = w - 1 - (b - a);
			Mod ta = comb(sta, b-a+i), tb = comb(stb, i);
			Mod tmp = ta*tb;
			sum -= tmp;
		}
	}
	else
	{
		REP(i, b)
		{
			ll sta = h - (a-b) - 1, stb = h + w - 2 - sta;
			Mod ta = comb(sta, i), tb = comb(stb, a-b+i);
			Mod tmp = ta*tb;
			sum -= tmp;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 16256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		String S = scan.next();

		int max = 0;
		for (int i = 1; i < N; i++) {
			String sub1 = S.substring(0, i + 1);
			String sub2 = S.substring(i + 1);
			//System.out.println(sub1 + " " + sub2);
			int[] sub1_char = new int[26];
			int[] sub2_char = new int[26];
			for (char c : sub1.toCharArray()) {
				sub1_char[c - 'a']++;
			}
			for (char c : sub2.toCharArray()) {
				sub2_char[c - 'a']++;
			}
			int count = 0;
			for (int j = 0; j < 26; j++) {
				if (sub1_char[j] > 0 && sub2_char[j] > 0) {
					count++;
				}
			}
			if (count > max) {
				max = count;
			}

		}
		System.out.println(max);
	}

}

Measured memory_bytes: 21844
import java.util.Arrays;
import java.util.Scanner;

public class Main{

	void run(){
		Scanner in = new Scanner(System.in);
		for(;;){
			int N = in.nextInt();
			if(N==0) return ;
			int[] noEquip = new int[N];
			int[][] matrix = new int[N][N];
			for(int i=0; i<N; i++){
				noEquip[i] = in.nextInt();
				for(int j=0; j<N; j++){
					matrix[i][j] = in.nextInt();
				}
			}
			System.out.println(solve(noEquip, matrix));
		}
	}

	int solve(int[] noEquip, int[][] matrix){
		int N = noEquip.length;
		int[] dp = new int[1<<N];
		Arrays.fill(dp, Integer.MAX_VALUE);
		
		dp[0] = 0;
		for(int bit=0; bit<(1<<N); bit++){
			for(int i=0; i<N; i++)if(((bit>>i)&1)==0){
				int min = noEquip[i];
				for(int j=0; j<N; j++)if(((bit>>j)&1)>0){
					min = Math.min(min, matrix[i][j]);
				}
				dp[bit|(1<<i)] = Math.min(dp[bit|(1<<i)], dp[bit] + min);
			}
		}
		
		return dp[(1<<N)-1];
	}

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

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 


int table[9];
int bamboo[9];
int n, a, b, c;
int ans =INF;

void dfs(int len=0) {
  if (len == n) {
    int sumA=0, sumB=0, sumC=0;
    int now = 0;
    for (int i=0; i<n;i++) {
      int num = table[i];
      if (num==3) {
        if (sumC) now+=10;
        sumC += bamboo[i];
      }
      if (num==2) {
        if (sumB) now+=10;
        sumB += bamboo[i];
      }
      if (num==1) {
        if (sumA) now += 10;
        sumA += bamboo[i];
      }
    }
    if (sumA==0 || sumB==0 || sumC==0) return;
    now += abs(sumC-c);
    now += abs(sumB-b);
    now += abs(sumA-a);
    chmin(ans, now);
    return ;
  }
  for (int i=1; i<5;i++) {
    table[len] = i;
    dfs(len+1);
  }
}

int main() {
  cin >> n >> a >> b >> c;
  rep(i,n) cin >> bamboo[i];
  dfs();
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

#define ll long long

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

	if (a == b) {
		cout << a * 2 << endl;
		return 0;
	}

	if (a > b) {
		cout << a + (a - 1) << endl;
	}
	else {
		cout << b + (b - 1) << endl;
	
	}


}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string.h>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector> 

using namespace std;

int main() {
	int n, x, y;
	cin >> n;
	x = 800 * n;
	y = 200 * (n / 15);
	cout << x - y << endl;
	return 0;
}

Measured memory_bytes: 256
from random import random

K = 26
d = int(input())

c = list(map(int, input().split()))

s = []
for i in range(d):
    q = list(map(int, input().split()))
    s.append(q)

ans = []
last = [-1 for i in range(K)]
for i in range(d):
    x = []
    for j in range(K):
        x.append(pow(s[i][j] * s[i][j] * s[i][j] * c[j] * (i - last[j]) * c[j] * (i - last[j]), 2))

    sum = 0
    for j in range(K):
        sum += x[j]

    for j in range(K):
        x[j] /= sum

    prob = random()
    cur = 0
    for j in range(K):
        if cur + x[j] <= prob:
            cur += x[j]
            continue
        ans.append(j)
        last[j] = i
        break


def get_result():
    res = 0
    last = [-1 for i in range(K)]
    for i in range(d):
        res += s[i][ans[i]]
        last[ans[i]] = i
        for j in range(K):
            res -= c[j] * (i - last[j])
    return res


# print(get_result())
for u in ans:
    print(u + 1)


Measured memory_bytes: 9656
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) begin(a),end(a)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}
int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}




char field[110][110];
int H,W;

int main(){

  int H,W;
  vector<bool> h(H,false);
  vector<bool> w(W,false);    
  cin >> H >> W;
  rep(i,H){
    rep(j,W){
      cin >> field[i][j];
      if(field[i][j] == '#'){
	h[i] = true;
	w[j] = true;
      }
    }
  }
  rep(i,H){
    if(h[i]){
      rep(j,W){
	if(w[j]){
	  cout << field[i][j];
	}
      }
      cout << endl;
    }
  }
  
}


Measured memory_bytes: 256
#最初に置いておくもの
import sys
sys.setrecursionlimit(500000) 
input=sys.stdin.readline

N=int(input())
A = [list(map(int, input().split())) for _ in range(N)]

inf=float('inf')
dp=[[0]*3 for j in range(N+1)]

def chmax(a,b):
    return max(a,b)

for n in range(N):
    for i in range(3):
        for m in range(3):
                if (i == m):
                    continue
                dp[n+1][m]=chmax(dp[n+1][m], dp[n][i] + A[n][m])


re=max(dp[N][0],dp[N][1],dp[N][2])
print(re)

Measured memory_bytes: 69596
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  string S;
  cin>>S;
  int ans = 0;
  int tmp;
  for(int i=0;i<N;++i) {
    tmp = 0;
    for(int j=0;i+j<N;++j) {
      if(S[i+j]==S[j]) tmp++;
      else {
        ans = max(ans, min(tmp, i));
        tmp = 0;
      }
      ans = max(ans, min(tmp, i));
    }
  }
  cout<<ans<<endl;
}



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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int n; cin>>n;
	bool A[200][200];
	rep(u,n){
		string s; cin>>s;
		rep(v,n) A[u][v]=(s[v]=='1');
	}

	int ans=0;
	rep(r,n){
		int d[200];
		rep(u,n) d[u]=-1;
		d[r]=0;
		queue<int> Q;
		Q.push(r);
		while(!Q.empty()){
			int u=Q.front(); Q.pop();
			rep(v,n) if(A[u][v] && d[v]==-1) {
				d[v]=d[u]+1;
				Q.push(v);
			}
		}

		rep(u,n) rep(v,n) if(A[u][v] && abs(d[u]-d[v])!=1) { cout<<-1<<endl; return 0; }
		ans=max(ans,*max_element(d,d+n)+1);
	}
	cout<<ans<<endl;

	return 0;
}


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

using namespace std;

int main() {
  string s;
  cin >> s;
  int n = s.length();
  
  int sum = 0;
  
  for (int i=0; i < n; i++) {
    sum += s[i] - '0';
  }

  if (stoi(s) % sum == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define MAX 1000

struct data{
  int id,ax,ay,bx,by;
  string str;
  vector<int> g;
};

int n,p;
string s;

vector<data> G;

int getNum(){
  int res=0;
  while('0'<=s[p]&&s[p]<='9'){
    res*=10;
    res+=(s[p]-'0');
    p++;
  }
  return res;
}

void rec(){
  data d;
  d.str="";
  d.g.clear();
  p++;
  for(;s[p]!='>';p++)d.str.push_back(s[p]);
  p++;
  d.ax=getNum();
  p++;
  d.ay=getNum();
  p++;
  d.bx=getNum();
  p++;
  d.by=getNum();
  //cout<<d.ax<<" "<<d.ay<<" "<<d.bx<<" "<<d.by<<endl;
  while(1){
    if(s[p+1]=='/')break;
    rec();
    d.g.push_back((int)G.size()-1);
  }
  while(s[p]!='>')p++;
  p++;
  G.push_back(d);
}

bool check(int a,int x,int y){
  return (G[a].ax<=x&&x<=G[a].bx&&G[a].ay<=y&&y<=G[a].by);
}

int solve(int a,int x,int y){
  for(int i=0;i<(int)G[a].g.size();i++){
    int w=G[a].g[i];
    if(check(w,x,y))return solve(w,x,y);
  }
  return a;
}

int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    cin>>s;
    p=0;
    rec();
    for(int i=0;i<n;i++){
      int x,y;
      cin>>x>>y;
      if(!check(G.size()-1,x,y))cout<<"OUT OF MAIN PANEL 1"<<endl;
      else{
	int ans=solve(G.size()-1,x,y);
	cout<<G[ans].str<<" "<<G[ans].g.size()<<endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1248
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
typedef pair<int,int> P;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
void YN(bool flg){cout<<(flg?"YES":"NO")<<endl;}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<endl;}
void yn(bool flg){cout<<(flg?"yes":"no")<<endl;}
signed main(){
	int n,z,w;
	cin>>n>>z>>w;
	vector<int> a(n);
	rep(i,n) cin>>a[i];
	if(n==1) cout<<llabs(w-a[0])<<endl;
	else cout<<max(llabs(w-a[n-1]),llabs(a[n-1]-a[n-2]))<<endl;
}


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

const int maxn = 1e5 + 10;
const int maxp = 61;
const long long mod = 1e9 + 7;

int n, m;
int p[maxn];
vector<int> g[maxn];
int comp=0;
vector<int> c[maxn];
int u[maxn];

int t[maxn];

void dfs(int v)
{
    u[v] = 1;
    for (int to : g[v])
    {
        if (!u[to])
            dfs(to);
    }
    c[comp].push_back(v);
}

main()
{
	ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
        cin >> p[i], p[i]--;
    for (int i = 0; i < m; ++i)
    {
        int x, y;
        cin >> x >> y;
        x--;y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    for (int i = 0; i < n; ++i)
    {
        if (!u[i])
            dfs(i), comp++;
    }

    int res = 0;

    for (int i = 0; i < comp; ++i)
    {
        for (int el : c[i])
            t[el]++;
        for (int el : c[i])
            res += t[p[el]];
        for (int el : c[i])
            t[el]--;
    }
    cout << res << "\n";
}


Measured memory_bytes: 14324
#include<cstdio>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<cmath>
#include<set>
#include<map>
#include<queue>
using namespace std;
#define MAXN 2000000
#define INF 0x7FFFFFFF
int main() {
	int a[4];
	scanf("%d%d%d",&a[1],&a[2],&a[3]);
	int x;
	scanf("%d",&x);
	if(500*a[1]+100*a[2]+50*a[3]<x) {
		printf("0\n");
		return 0;
	}
	int ans=0;
	for(int i=0;i<=a[1];i++)
		for(int j=0;j<=a[2];j++)
			for(int k=0;k<=a[3];k++)
				if(500*i+100*j+k*50==x)
					ans++;
	printf("%d\n",ans);
}


Measured memory_bytes: 256
N, K = map(int, input().split())

ans = []

if N == 2 and K > 0:
    ans = []
elif (1+N-2)*(N-2)//2 < K:
    ans = []
else:
    for i in range(2, N+1):
        ans.append([1, i])
    cnt = (1+N-2)*(N-2)//2

    for u in range(2, N):
        if cnt == K:
            break
        for v in range(u+1, N+1):
            if cnt == K:
                break
            ans.append([u, v])
            cnt -= 1

if ans:
    print(len(ans))
    for u, v in ans:
        print(u, v)
else:
    print(-1)


Measured memory_bytes: 44272
#include<iostream>
#include<math.h>
using namespace std;

int main(){
    long long n;
    cin>>n;

    long long  sum=1000000000000;
    for(int i=1; i<=sqrt(n); i++){
        if(n%i==0){
            if(sum > i+(n/i)-2){
             //   cout<<i<<" "<<n/i<<endl;
                sum = i+(n/i)-2;
            }
        }
    }
    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>

const ll mod = 1000000007;

int main() {
	ll n;
	cin >> n;
	vector<ll>a(n);
    rep(i, n)cin >> a[i];
	ll ans(0);
    rep(i, 60){
        ll  cnt(0);
        rep(j, n) {
            if (a[j] >> i & 1) {
                cnt++;
            }
        }
        ll t=pow(2,i);
        t %= mod;
        ans += (((n - cnt) *cnt) % mod)*t;
        ans %= mod;
    }
    
    cout << ans;

}

Measured memory_bytes: 5592
#!/usr/bin/env python
# -*- coding: utf-8 -*-

S = input().strip()
res = 7
num = list()
for i in range(len(S)):
    num.append(int(S[i]))

for b in range(2**(3)):
    b_str = format(b, 'b').zfill(len(S)-1)
    sum = num[0]
    for i in range(len(num) - 1):
        if b_str[i] == '0':
            sum -= num[i+1]
        else:
            sum += num[i+1]
    if sum == res:
        break

plus_or_minus = list()
for i in range(3):
    if b_str[i] == '0':
        plus_or_minus.append('-')
    else:
        plus_or_minus.append('+')
print('{}{}{}{}{}{}{}=7'.format(num[0], plus_or_minus[0], num[1], plus_or_minus[1], num[2], plus_or_minus[2], num[3]))


Measured memory_bytes: 9108
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <unistd.h>
using namespace std; 
using namespace std::chrono; 
using namespace __gnu_pbds;
#define ll long long int 
//mp.reserve(1024);
//mp.max_load_factor(0.25);
typedef tree<int, null_type, less<int>, rb_tree_tag,  
                 tree_order_statistics_node_update>  
          ordered_set;  
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
            x += 0x9e3779b97f4a7c15;
            x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
            x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
            return x ^ (x >> 31);
        }

        size_t operator()(uint64_t x) const {
            static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
            return splitmix64(x + FIXED_RANDOM);
        }
};
 
void addEdge(vector<ll> adj[], ll u, ll v) 
{ 
   adj[u].push_back(v); 
   adj[v].push_back(u); 
} 
vector<ll> z_function(string s) {
    ll n = s.length();
    vector<ll> z(n);
    for (ll i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    return z;
}
int main() 
{ 
 	ios_base::sync_with_stdio(false);
   	cin.tie(NULL);
   	cout.tie(NULL);
    //freopen("input.txt", "r", stdin); 
    //freopen("output1.txt", "w", stdout); 
	ll n;
    cin>>n;
    vector<ll>v;
    for(ll i=0,temp;i<n;i++){
        cin>>temp;
        v.push_back(temp);
    }
    v.push_back(INT_MAX);
    v.push_back(INT_MAX);
    ll dp[n+2];
    for(ll i=0;i<n+2;i++)
        dp[i]=INT_MAX;
    dp[0]=0;
    
    for(ll i=0;i<n;i++){
      //  cout<<dp[i]<<endl;
        dp[i+1]=min(dp[i+1],dp[i]+abs(v[i]-v[i+1]));
        dp[i+2]=min(dp[i+2],dp[i]+abs(v[i]-v[i+2]));
    }
    cout<<dp[n-1]<<endl;
    return 0; 
} 


Measured memory_bytes: 1908