akhauriyash/Code-Regression huggingface dataset:
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
  int D, G;
  cin >> D >> G;
  vector<int> P(D), B(D);
  for (int i = 0; i < D; i++) {
    cin >> P[i] >> B[i];
  }

  int ans = INF;
  for(int i = 0; i < 1 << D; i++) {
    int sum = 0, sum_p = 0;
    priority_queue<int> Q;
    for(int j = 0; j < D; j++) {
      if (i >> j & 1) {
        sum += P[j] * (j + 1) * 100 + B[j];
        sum_p += P[j];
      } else {
        for(int k = 0; k < P[j]; k++) {
          Q.push((j + 1) * 100);
        }
      }
    }
    while(sum < G && !Q.empty()) {
      int p = Q.top(); Q.pop();
      sum += p;
      sum_p++;
    }

    ans = min(ans, sum_p);
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;


void dfs(vector<vector<long>> &G, int prev) {
}

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

    vector<vector<pair<long,long>>> G(n);
    for(int i=0; i<n; i++) {
        long a;
        cin >> a;
        for(int j=0; j<a; j++) {
            long x,y;
            cin >> x >> y;
            x--;
            G[i].push_back(make_pair(x, y));
        }
    }

    long r = 0;
    for(int c=0; c<1<<n; c++) {
        long t = __builtin_popcount(c);
        for(int i=0; i<n; i++) {
            if((c >> i)&1) {
                for(auto v: G[i]) {
                    if(((c >> v.first)&1) != v.second)
                        goto bad;
                }
            }
        }
        r = max(r, t);
bad:
        ;
    }
    cout << r << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main () {
    int cnt=0;
    string N;
    cin >> N;
    if (N[0]=='A')
        cnt++;
    for (int i=1;i<N.size();i++){
        if (i!=1 && i!=N.size()-1 && N[i]=='C')
            cnt+=2;
        else if (N[i]-96<0)
            cnt+=100;
    }
    cnt==3 ? cout << "AC" : cout << "WA";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
const int MOD = 1000000000 + 7;
const int NMAX = 100000;

int main()
{
    int N, M;
    pair<int, bool> dp[NMAX + 10];
    for(int i = 0; i <=NMAX; ++i) {
        dp[i].first = 0; dp[i].second = true;
    }
    cin >> N >> M;
    for(int i = 0; i < M; ++i) {
        int atmp; cin >> atmp;
        dp[atmp].second = false;
    }
    dp[0].first = 1;
    for(int i = 1; i <= NMAX; ++i) {
        if(dp[i].second) {
            if(i >= 2) {
                dp[i].first = ( ((dp[i-1].second)? dp[i-1].first : 0) 
                + ((dp[i-2].second)? dp[i-2].first : 0) ) % MOD;
            }
            else {
                dp[i].first = dp[i-1].first % MOD;
            }
        }
    }
    cout << dp[N].first << endl;
    return 0;
}

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

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

    if (A >= B){
        cout << "delicious" << endl;
    }
    else if(B - A > X){
        cout << "dangerous" << endl;
    }
    else{
        cout << "safe" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  string a, b, c, d;
  
 
  a = s.at(0);
  //cout << a << endl;
  b = s.at(1);
  //cout << b << endl;
  c = s.at(2);
  //cout << c << endl;
  d = s.at(3);
  //cout << d << endl;
  
  if (a == b || b == c || c ==d) {
    cout << "Bad" << endl;
  }
  else {
   cout << "Good" << endl; 
  }
  
}

Measured memory_bytes: 256
a = (int)(input())

flag = [False] * (a * 2 + 1)
sosu = []

# 最初に素数を消す
for i in range(2, len(flag)):
    if i * i < a * 2:
        flag[i] = True
        sosu.append(i)
#print("flag = {}".format(flag))

# ふるいにかける
for i in sosu:
    for j in range(i, len(flag), i):
        flag[j] = True
#print("flag = {}".format(flag))

# 答えは？
ret = 2
for i in range(a, len(flag)):
    if flag[i] == False:
        ret = i
        break 

print("{}".format(ret))

Measured memory_bytes: 10264
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int N;
    cin >> N;
    if(N%1000 ==0 ){
        cout << 0 << endl;
    } else {
        cout << 1000 -N%1000 << endl;
    }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define Little 1
const long long INF = 1LL<<60;
#define pairint pair<int,int>
signed main(){
  int x=0,y=0,z=0,w=0,n=0,m=0,o=0;
  std::cin >> x >> y;
  std::vector<int> v(y);
  rep(i,y){
    std::cin >> z;
    x-=z;
  }
  if(x>=0)std::cout << x << '\n';
  else std::cout << -1 << '\n';  
}


Measured memory_bytes: 3700
import java.util.Scanner;

public class Main {
	/**
	 * Contest with Drinks Easy
	 * @param 1 ≦ N ≦ 100
	 * @param 1 ≦ Ti ≦ 10^5
	 * @param 1 ≦ M ≦ 100
	 * @param 1 ≦ Pi ≦ N
	 * @param 1 ≦ Xi ≦ 10^5
	 */
	public static void main(String... args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int t[] = new int[n];
			int base = 0;
			for (int i = 0; i < n; i++) {
				t[i] = sc.nextInt();
				base += t[i];
			}
			int m = sc.nextInt();
			int p[] = new int[m];
			int x[] = new int[m];
			for (int i = 0; i < m; i++) {
				p[i] = sc.nextInt();
				x[i] = sc.nextInt();
			}
			for (int i = 0; i < m; i++) {
				System.out.println(base - t[p[i] - 1] + x[i]);
			}
		}
	}
}

Measured memory_bytes: 21844
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int C = sc.nextInt();
		int time[][] = new int[N][3];
		Boolean flag[] = new Boolean[N];
		Arrays.fill(flag, false);
		
		for(int i = 0; i < N; i++) {
			time[i][0] = sc.nextInt();
			time[i][1] = sc.nextInt();
			time[i][2] = sc.nextInt();
		}
		
		Arrays.sort(time, Comparator.comparingInt(o -> o[0]));
		
		int ans = 0;
		while(Arrays.asList(flag).contains(false)) {
			ans++;
			int t = 0;
			int c = -1;
			for(int i = 0; i < N; i++) {
				if(flag[i]) continue;
				if(time[i][2] == c || c == -1) {
					if(t <= time[i][0]) {
						flag[i] = true;
						t = time[i][1];
						c = time[i][2];
					}
				} else {
					if(t < time[i][0]) {
						flag[i] = true;
						t = time[i][1];
						c = time[i][2];
					}
				}
			}
		}
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 97692
#include<iostream>
#include<vector>
#include<cstdlib>
#include <cmath>
#define INF 100000000
template<class T> inline bool chmax(T& a, T b)
{ if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b)
{ if (a > b) { a = b; return 1; } return 0; }

using namespace std;

int main(){
  int i,j,k,n,d,x=100000;
  string a; cin >>a;
  bool flag = true, flag2=false;

  if(a[0]!='A')flag=false;

  for(i=2;i<a.size()-1;i++){
    if(flag2==true && a[i]=='C')flag=false;
    if(flag2==false && a[i]=='C'){
      flag2=true;
      x=i;
    }
  }
  if(flag2==false)flag=false;

  for(j=0;j<a.size();j++){
    if(j==0 || x==j)continue;
    if((a[j]>= 'A') && (a[j]<='Z'))flag=false;
  }

  if(flag)cout << "AC"<<endl;
  else cout <<"WA"<<endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void dfs(int now,long long sum);
typedef pair<int,int>P;
int n;
vector<P>node[100009];
long long d[100009];

int main(){
  memset(d,-1,sizeof(d));
  int q,k;
  cin>>n;
  for(int i=0;i<n-1;i++){
    int a,b,c;
    cin>>a>>b>>c;
    node[a].push_back(P(b,c));
    node[b].push_back(P(a,c));
  }
  cin>>q>>k;
  dfs(k,0);
  for(int i=0;i<q;i++){
    int x,y;
    cin>>x>>y;
    cout<<d[x]+d[y]<<endl;
  }
  return(0);
}

void dfs(int now,long long sum){
  d[now]=sum;
  for(int i=0;i<node[now].size();i++){
    int next=node[now][i].first;
    int cost=node[now][i].second;
    if(d[next]==-1)dfs(next,sum+cost);
  }
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repm(i, m, n) for (int i = m; i < (n); i++)
#define eps (1e-7)
#define inf (1e9)
#define pi (acos(-1))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

    int n;
    cin >> n;
    vi p(n);
    rep(i, n) cin >> p[i];

    int count = 0;
    int m = n;
    rep(i, n)
    {
        if (p[i] <= m)
        {
            m = p[i];
            count++;
        }
    }

    cout << count << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int a, b;
	cin >> a >> b;
	cout << a * b << endl;
	return 0;
}

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

int main() {
	
	int n,q;
	cin >> n;
	vector<int> a(n);
	for(auto &i:a) cin >> i;
	cin >> q;
	int cnt{};
	for(int i=0; i<q; i++){
		int c;
		cin >> c; 
		auto it1 = lower_bound(a.begin(),a.end(),c);
		auto it2 = upper_bound(a.begin(),a.end(),c);
		if(it1 != it2) cnt++;
	}
	cout << cnt << endl;
	
}


Measured memory_bytes: 3128
#line 2 "/Users/kaage/Desktop/ProgrammingWorkspace/library/other/template.hpp"
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(lint)(n);i++)
#define REP(i,n) for(int i=1;i<=(lint)(n);i++)
#define all(V) V.begin(),V.end()
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<int, int> P;
typedef std::pair<lint, lint> LP;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = DBL_EPSILON;
constexpr double PI=3.141592653589793238462643383279;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
template<typename T>
T mypow(T a, unsigned int b) {
	if (!b)return T(1);
	if (b & 1)return mypow(a, b - 1) * a;
	T memo = mypow(a, b >> 1);
	return memo * memo;
}
lint modpow(lint a, lint b, lint m) {
	if (!b)return 1;
	if (b & 1)return modpow(a, b - 1, m) * a % m;
	lint memo = modpow(a, b >> 1, m);
	return memo * memo % m;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, vec.size() - 1)std::cout << vec[i] << " ";
	std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
#line 2 "main.cpp"
int n,a[85];
LP dp[85][2];
int main(){
	std::cin>>n;
	rep(i,n)std::cin>>a[i];
	lint m=1000,s=0;
	rep(i,n){
		if(a[i]<a[i+1]){
			s+=m/a[i];
			m%=a[i];
		}
		else{
			m+=s*a[i];
			s=0;
		}
	}
	m+=s*a[n-1];
	std::cout<<m<<std::endl;
	return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>
#include <string.h>
#define MAX 201
int main(void)
{
    char n[MAX], nn[MAX]; 
    int m, h, i, j;
    int len;
    while(scanf("%s", n), n[0] != '-'){
        len = strlen(n);
        scanf("%d", &m);
        for(i=0; i<m; i++){
            scanf("%d", &h);
            for(j=0; j<len-h; j++){
                nn[j] = n[h+j];
            }
            for(j=len-h; j<len; j++){
                nn[j] = n[j-(len-h)];
            }
            for(j=0; j<len; j++){
                n[j] = nn[j];
            }
        }
        printf("%s\n", n);
    }
    return 0;
}

Measured memory_bytes: 584
x=[]
y=[]
z=[]
for j in range (3):
  x1,y1,z1=[int(i) for i in input().split()]
  x.append(x1)
  y.append(y1)
  z.append(z1)

for p in range (2):
  if x[p]-x[p+1]!=y[p]-y[p+1] or y[p]-y[p+1]!=z[p]-z[p+1]:
    print("No")
    break
    
  if x[0]-y[0]!=x[1]-y[1] or x[1]-y[1]!=x[2]-y[2]:
    print("No")
    break
    
  if z[0]-y[0]!=z[1]-y[1] or z[1]-y[1]!=z[2]-y[2]:
    print("No")
    break
    
  if p==1:
    print("Yes")

Measured memory_bytes: 3064
# AtCoder Regular Contest 059
# C - いっしょ
# https://atcoder.jp/contests/arc059/tasks/arc059_a
N = int(input())
*A, = map(int, input().split())

mincost = 10**10
for i in range(-100, 101):
    cost = 0
    for a in A:
        cost += (a-i)*(a-i)

    if cost < mincost:
        mincost = cost

print(mincost)


Measured memory_bytes: 39024
import java.util.*;
import java.io.*;
public class Main{
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		long a = Long.parseLong(sc.next()) - 1;
		long b = Long.parseLong(sc.next());
		sc.close();
		long zero = (a + 1) / 2 + (b + 1) / 2;
		zero %= 2;
		if(a % 2 == 0) zero ^= a;
		if(b % 2 == 0) zero ^= b;
		ou.print(zero + "\n");
		ou.flush();
    }
}

Measured memory_bytes: 38740
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
int n;
pii a[200010];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n;
  	for(int i=0;i<n;i++)cin>>a[i].second>>a[i].first;
  	sort(a,a+n);
 	int now=0;
  	for(int i=0;i<n;i++){
   		now=now+a[i].second;
    	if(now>a[i].first){
      		cout<<"No";
      		return 0;
    	}
	}
	cout<<"Yes";
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define per(i,n) for (int i=n-1; i>=0; --i)
#define all(a) a.begin(), a.end()
using namespace std;
using namespace atcoder;
using ll = long long;
using P  = pair<int,int>;
using vi = vector<int>;
using vv = vector<vi>;

int main(){
    int n, m;
	cin >> n >> m;
	dsu d(n);
	rep(i,m){
      int a,b;
      cin >> a >> b;
      a--; b--;
      d.merge(a,b);
    }
	vv g = d.groups();
	cout << (int)g.size() -1 << endl;
	return 0;
}


Measured memory_bytes: 8948
using System;
using System.Linq;
using System.Collections.Generic;

public class Program
{
	public static void Main()
	{
		var inputNum = _GetIntReadLine();
		var sum = Enumerable.Range(1 , inputNum).Select(iIndex =>
		{
			decimal num = 0;
			if((iIndex % 3) != 0 && (iIndex % 5) != 0)
			{
				num = iIndex;
			}
			return num;
		})
		.Sum();
		Console.WriteLine(sum);
	}

	private static string		_GetReadLine()		  { return Console.ReadLine(); }
	private static int			_GetIntReadLine()	  { return int.Parse(_GetReadLine()); }
	private static List<string> _GetListReadLine()	  { return _GetReadLine().Split(' ').ToList(); }
	private static List<int>	_GetIntListReadLine() { return _GetListReadLine().Select(iText => int.Parse(iText)).ToList(); }
}

Measured memory_bytes: 28404
#include <stdio.h>

int main(void)
{
    long long n,m;
    scanf("%lld%lld", &n, &m);

    if (3 <= n && 3 <= m)
        printf("%lld\n", (n - 2) * (m - 2));
    else if (n == 2 || m == 2)
        printf("0\n");
    else if (n == 1) {
        switch (m) {
            case 1 : printf("1\n"); break;
            case 2 : printf("0\n"); break;
            case 3 : printf("1\n"); break;
            default : printf("%lld\n", m - 2); break;
        }
    }
    else {
        switch (n) {
            case 1 : printf("1\n"); break;
            case 2 : printf("0\n"); break;
            case 3 : printf("1\n"); break;
            default : printf("%lld\n", n - 2); break;
        }
    }

    return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(){

    int a, b, c;
    cin >> a >> b >> c;

    if(a>b) cout << "a > b" << endl;
    else if (a<b) cout << "a < b" << endl;
    else cout << "a == b" << endl; 

    return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7

using ar3 = array<int, 3>; // to-pos, length(money), threaten

int solve(const vector<vector<ar3>> edges, const int initMoney) {
	// init
	const int N = edges.size();
	vector<vector<int>> dp(N, vector<int>(initMoney + 1, INF));
	priority_queue<pii> pq;
	dp[0][initMoney] = 0;
	pq.push({ initMoney,0 });

	// calc
	while (!pq.empty()) {
		auto now = pq.top(); pq.pop();
		int money = now.first;
		int pos = now.second;
		int score = dp[pos][money];
		for (auto edge : edges[pos]) {
			int next = edge[0];
			int cost = edge[1];
			int enemy = edge[2];

			// dangerous
			int nscore = score + enemy;
			if (dp[next][money] > nscore) {
				dp[next][money] = nscore;
				pq.push({ money,next });
			}

			// safe
			int nmoney = money - cost;
			if (nmoney < 0)continue;
			if (dp[next][nmoney] > score) {
				dp[next][nmoney] = score;
				pq.push({ nmoney,next });
			}
		}
	}

	return *min_element(dp.back().begin(), dp.back().end());
}

int main()
{
	while (true) {
		int N, M, L;
		cin >> N >> M >> L;
		if (N == 0)break;

		vector<vector<ar3>> info(N);
		REP(i, M) {
			int a, b, c, d;
			cin >> a >> b >> c >> d;
			a--; b--;
			info[a].push_back({ b,c,d });
			info[b].push_back({ a,c,d });
		}

		cout << solve(info, L) << endl;
	}
	return 0;
}



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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int ans = INF;
int N, K;
vector<int> D;
vector<bool> flag(10, true);
void dfs(int pay){
  if(pay >= N){
    ans = min(pay, ans);
    return;
  }
  REP(i, 10){
    if(flag[i]){
      dfs(pay*10+i);
    }
  }
}

int main(){
  cin >> N >> K;
  D.resize(K);
  REP(i, K){
    cin >> D[i];
    flag[D[i]] = false;
  }
  FOR(i, 1, 10){
    if(flag[i]){
      dfs(i);
    }
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <list>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define sz(x) int(x.size())

typedef long long ll;

using namespace std;

/*******-c++14 don't include-*******/
template<typename T>
T gcd(T a, T b){if( b == 0)return a; return gcd(b, a%b); }
template<typename T>
T lcm(T a, T b){return a*b/gcd(a,b); }
void printArr(int *a, int len){for(int i=0; i<len; i++){if(i)cout << " ";cout << a[i];}cout << endl;}
/*******---------------------*******/

static const int INTINF = (2147483647);
static const ll LLINF = (1ll<<32);
static const int MAX = 100001;

int arr[MAX];

int main(int argc, const char * argv[]) {
    // input from txt
    
    /////////
    //write//
    /////////
    
    int n;
    cin >> n;
    rep(i, n){
        cin >> arr[i];
    }
    
    ll res;
    rep(i, n-1){
        rep2(j, i+1, n){
            res += arr[i] * arr[j];
        }
    }
    
    cout << res << endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	string s; cin>>s;
	int n=s.size();
	rep(i,0,n){
		if(s[i]=='?'){
			if(s[i+1]=='D' && i<n-1 && i!=0 && s[i-1]!='P') s[i]='P';
			else if(i!=0 && i<n-1 && s[i-1]=='D' && s[i+1]=='?'){
				s[i]='P';
				s[i+1]='D';
			}
			else if(i==0 && n!=1){
				if(s[1]=='D' || s[1]=='?') s[0]='P';
				else s[0]='D';
			}
			else s[i]='D';
		}
	}
	cout<<s;
	return 0;
}


Measured memory_bytes: 3764
rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())

from collections import deque

A = deque(rr())
flipped = 0

Q = rri()
for _ in xrange(Q):
    query = rr().split()
    if query[0] == '1':
        flipped ^= 1
    else:
        f, c = query[1:]
        f = int(f)
        if f == 1:
            if flipped == 0:
                A.appendleft(c)
            else:
                A.append(c)
        else:
            if flipped == 0:
                A.append(c)
            else:
                A.appendleft(c)
    #print A, flipped

if flipped == 0:
    print "".join(A)
else:
    print "".join(reversed(A))


Measured memory_bytes: 54940
#include <bits/stdc++.h>
using namespace std;
#define Rep(i, n) for(int i = 0; i < (int)(n); i++)
#define vecin1(n) vector<int> vec1(n); Rep(i,n) cin >> vec1.at(i)
#define vecin2(n) vector<int> vec2(n); Rep(i,n) cin >> vec2.at(i)
int main() {
int n,ans = 0;
cin >> n;

vecin1(n);
vecin2(n);

Rep(i,n)
{
  if(vec1.at(i)-vec2.at(i)>0)
  ans += vec1.at(i)-vec2.at(i);
}
  cout << ans << endl;
}

Measured memory_bytes: 256
n,a,b = map(int,input().split())
count = 0
for i in range(n+1):
    judge = i%10 + (i%100 - i%10)//10 + (i%1000 - i%100)//100 + (i%10000 - i%1000)//1000 + (i%100000 - i%10000)//10000
    if judge >= a and judge <= b:
        count += i
print(count)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
   
int main(){
    u_int a;    // width
    u_int b;    // height
    while(std::cin >> a >> b){
        if(a == 0 && b == 0){
            break;
        }
          
        // initialization
        std::vector<std::vector<u_int>> path(a+1, std::vector<u_int>(b+1, 1));
          
        // construction
        u_int n;
        std::cin >> n;
        for(u_int i = 0; i < n; ++i){
            u_int x, y;
            std::cin >> x >> y;
            path[x][y] = 0;
        }
          
        // out path
        for(u_int i = 0; i < a+1; ++i) path[i][0] = 0;
        for(u_int i = 0; i < b+1; ++i) path[0][i] = 0;
          
        // calc the number of path
        for(u_int x = 1; x <= a; ++x){
            for(u_int y = 1; y <= b; ++y){
                if(path[x][y] != 0 && !(x == 1 && y == 1)){
                    path[x][y] = path[x-1][y] + path[x][y-1];
                }
            }
        }
          
        std::cout << path[a][b] << std::endl;
           
    }
    return 0;
}

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

int main(void){
    int a, b;
    
    cin >> a >> b;
    
    if(a <= 8 && b <= 8){
        cout << "Yay!\n";
    }
    
    else{
        cout << ":(\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

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

func main() {
	var K int
	fmt.Scan(&K)
	sum := 0
	for i := 1; i <= K; i++ {
		for j := 1; j <= K; j++ {
			for l := 1; l <= K; l++ {
				sum += gcd(gcd(i, j), l)
			}
		}
	}
	fmt.Println(sum)
}

Measured memory_bytes: 1776
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
const int N = 1000, INF = 1 << 30;
vector<int> g[N];
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
  }
  int siz = 1 << 30;
  vector<int> ans;
  for (int st = 0; st < n; st++) {
    queue<int> que;
    que.push(st);
    vector<int> dist(n, INF), prv(n, -1);
    dist[st] = 0;
    while (que.size()) {
      int cur = que.front();
      que.pop();
      for (int nxt : g[cur]) {
        if (nxt == st) {
          if (siz < dist[cur]) continue;
          siz = dist[cur];
          int j = cur;
          ans.clear();
          ans.push_back(st);
          while (prv[j] != -1) {
            ans.push_back(j);
            j = prv[j];
          }
        } else if (dist[nxt] < INF) {
          continue;
        } else {
          que.push(nxt);
          dist[nxt] = dist[cur] + 1;
          prv[nxt] = cur;
        }
      }
    }
  }
  if (!ans.empty()) {
    cout << ans.size() << '\n';
    for (int i : ans) {
      cout << i + 1 << '\n';
    } 
  } else {
    cout << -1 << '\n';
  }
  return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main()
{
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if(x>0&&y>0&&r>0){
    if((x+r)<=W && y<H)
        printf("Yes\n");
    else
        printf("No\n");
    }
    else
        printf("No\n");
    return 0;
}



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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

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

int main()
{   
    int n, x, y;
    cin >> n >> x >> y;
    --x, --y;
    vvi g(n);
    rep(i, n-1) {
        g[i].push_back(i+1);
        g[i+1].push_back(i);
    }
    g[x].push_back(y); g[y].push_back(x);

    vvi dist(n, vi(n, 114514));
    rep(i, n) {
        queue<P> q;
        q.push({i, 0});
        while(!q.empty()) {
            auto x = q.front(); q.pop();
            int p = x.first, s = x.second;

            for(int j : g[p]) {
                if(dist[i][j] != 114514) continue;
                q.push({j, s+1});
                dist[i][j] = s+1;
            }
        }
    }

    map<int, int> m;
    rep(i, n) for(int j = i+1; j < n; j++) m[dist[i][j]]++;
    for(int i = 1; i <= n-1; i++) cout << m[i] << endl;
        
    return 0;
}


Measured memory_bytes: 19496
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i*i <= n; ++i) {
    if (n%i != 0) continue;
    res.emplace_back(i);
    if (i*i != n) res.emplace_back(n/i); //注意
  }
  return res;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  ll n;
  cin >> n;
  int ans = 0;
  auto d1 = divisor(n);
  for (auto x : d1) {
    if (x == 1) continue;
    ll temp = n/x;
    while(true) {
      if (temp % x == 0) temp/=x;
      else break;
    }
    debug(x, temp);
    if (temp % x == 1) ans++;
  }
  auto d2 = divisor(n-1);
  ans += d2.size() - 1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3688
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define N '0'
#define X '1'
#define S '2'
#define G '3'
#define D '4'

const int INF = (int)1e9;

const int MAX_W = 22;
const int MAX_H = 22;

char field[MAX_H][MAX_W];
int w, h, res;

void dfs(int x, int y, int step){
	if (step >= 10) return;
	if (res < step) return;

	/*
	REP(yy, h + 2){
		REP(xx, w + 2){
			if(x == xx && y == yy)
				LOG("* ");
			else
				LOG("%c ", field[yy][xx]);
		}
		LOG("\n");
	}
	LOG("---------------\n");
*/

	REP(i, 4){
		int sx = x;
		int sy = y;
		while(field[sy][sx] == N){
			sx+=dx[i];
			sy+=dy[i];
		}
		if(field[sy][sx] == D) continue;
		if(field[sy][sx] == G){
			res = min(res, step + 1);
			continue;
		}
		if(field[sy][sx] == X){
			if(sx - dx[i] == x && sy - dy[i] == y) continue;
			field[sy][sx] = N;
			dfs(sx - dx[i], sy - dy[i], step + 1);
			field[sy][sx] = X;
		}
	}
}

int main() {
//	int w, h;
	while(cin >> w >> h, w | h){
		fill_n((char *)field, MAX_H * MAX_W, D);
		res = INF;

		int sx, sy;
		REP(y, h){
			REP(x, w){
				char c;
				cin >> c;
				if(c == S){
					sx = x + 1;
					sy = y + 1;
					c = N;
				}

				field[y + 1][x + 1] = c;
			}
		}

		dfs(sx, sy, 0);
		cout << (res == INF ? -1 : res) << endl;
	}
}

Measured memory_bytes: 1160
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <fstream>
using namespace std;
int main(){
	long long a,b,n;
	cin>>a>>b>>n;
	if(b>n){
		long long x=a*n/b;
		long long y=a*(n/b);
		cout<<x-y<<endl;
	}else{
		long long m=n/b*b;
		long long x=a*(m-1)/b;
		long long y=a*((m-1)/b);
		long long xx=a*(n-1)/b;
		long long yy=a*((n-1)/b);
		cout<<max(x-y,xx-yy)<<endl;
	}
	return 0;
}

Measured memory_bytes: 3624
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        mut x: i64,
        mut k: i64,
        d: i64,
    }

    if x < 0 {
        x *= -1;
    }

    let simple_move_cnt = x / d;
    if simple_move_cnt >= k {
        println!("{}", x - k * d);
        return;
    }

    x -= simple_move_cnt * d;
    k -= simple_move_cnt;
    if k % 2 == 0 {
        println!("{}", x.abs());
    } else {
        println!("{}", (x - d).abs().min((x + d).abs()));
    }
}


Measured memory_bytes: 2160
import math

N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

data = [A,B,C,D,E]
data.sort()

time = math.ceil(N/data[0])+4
if data[0] >= N:
    time = 5

print(time)

Measured memory_bytes: 38640
#include<iostream>
#include<string>
using namespace std;
int main()
{
  int a=0,b=0,c=0,d=0;
  string s;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='N'){
      a=1;
    }
    if(s[i]=='W'){
      b=1;
    }
    if(s[i]=='S'){
      c=1;
    }
    if(s[i]=='E'){
      d=1;
    }
  }
  if(a==0&&a<c){
    cout<<"No"<<endl;
  }
  else if(c==0&&c<a){
      cout<<"No"<<endl;
  }
  else if(b==0&&b<d){
    cout<<"No"<<endl;
  }
  else if(d==0&&d<b){
      cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 3
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	mm := map[string]int{}
	for i := 0; i < n; i++ {
		s := getNextString(scanner)
		mm[s] = mm[s] + 1
	}
	pp := make(pairs, 0)
	for s, c := range mm {
		pp = append(pp, pair{
			s: s,
			c: c,
		})
	}
	sort.Sort(pp)
	ss := make([]string, 0)
	for i := 0; i < len(mm) && pp[i].c == pp[0].c; i++ {
		ss = append(ss, pp[i].s)
	}
	sort.Strings(ss)
	for _, s := range ss {
		fmt.Fprintln(writer, s)
	}
}

type pair struct {
	s string
	c int
}

type pairs []pair

func (a pairs) Len() int           { return len(a) }
func (a pairs) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a pairs) Less(i, j int) bool { return a[i].c > a[j].c }


Measured memory_bytes: 40064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
vector<string> split(string s, char p){vector<string>v;stringstream m(s);string b;while(getline(m,b,p))v.push_back(b);return v;}
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; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

int main(){
    ll X, Y, Z;
    cin >> X >> Y >> Z;
    cout << (X-Z)/(Y+Z) << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>





using namespace std;




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

	vector<vector<int>> tree(n);
	vector<pair<int, int>> vp;

	//cout << a << b << x << endl;
	int a, b;
	for (int i = 0; i < n - 1; i++) {
		cin >> a >> b;
		a--;
		b--;
		tree[a].emplace_back(b);
		tree[b].emplace_back(a);
		vp.emplace_back(a, b);
	}

	/*
	for (int i = 0; i < n-1; i++) {
		cout << vp[i].first << " " << vp[i].second << endl;
	}
	*/
	/*
	for (int i = 0; i < n; i++) {
		printf("%d;",i);
		for (int j = 0; j < tree[i].size(); j++) {
			printf("%d ", tree[i][j]);
		}
		printf("\n");
	}
	printf("\n");
	*/

	int max_color_num = 0;
	map<pair<int, int>, int> I;
	vector<int> cs(n, 0);

	vector<bool> used(n, 0);
	queue<int> que;
	used[0] = true;
	que.emplace(0);
	while (!que.empty()) {
		int v = que.front();
		que.pop();
		if (max_color_num < (int)tree[v].size()) {
			max_color_num = tree[v].size();
		}
		int cur = 1;
		for (int u : tree[v]) {
			if (used[u]) {
				continue;
			}
			if (cur == cs[v]) {
				cur++;
			}

			cs[u] = cur;
			I[make_pair(u, v)] = cur;
			I[make_pair(v, u)] = cur;
			cur++;
			used[u] = true;
			que.emplace(u);
		}
	}

	cout << max_color_num << endl;
	for (auto p : vp) cout << I[p] << endl;
	return 0;
}

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved
int main(){
    int n,k;
    cin>>n>>k;
    long long x[n];
    rep(i,n){
        cin>>x[i];
    }
    if(x[0]>=0){
        cout<<x[k-1]<<endl;
        return 0;
    }
    else if(x[n-1]<0){
        cout<<-x[n-1-(k-1)]<<endl;
        return 0;
    }
    else{
        long long ans=INF;
        for(int i=0;i+k-1<n;i++){
        ans=min(ans,abs(x[i])+abs(x[i+k-1]-x[i]));
        ans=min(ans,abs(x[i+k-1])+abs(x[i+k-1]-x[i]));
        }
        /*
        if(center+k<n)
        ans=min(ans,abs(x[center+k]));
        if(center-(k-1)>=0)
        ans=min(ans,abs(x[center-(k-1)]));

        for(int i=0;i<=center;i++){
            long long total=abs(x[center-i])*2;
            if(center+k-1<=n){
            total+=x[center+(k-1-i)];
            ans=min(ans,total);
            }
        }
        for(int i=0;center+i<n;i++){
            long long total=abs(x[center+i])*2;
            if(center-(k-1-i)>=0){
            total+=abs(x[center-(k-1-i)]);
            ans=min(ans,total);
            }
        }
        */

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

}
/*


*/


Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <numeric>
#include <algorithm>
using namespace std;
int main(){
    long long n,m,cnt=0;
    cin>>n>>m;
    long long a[n][m],b[m];
    for(int i=0;i<n;++i){
        for(int j=0;j<m;++j){
            cin>>a[i][j];
        }
    }
    for(int i=0;i<m;++i){
        cin>>b[i];
    }
    for(int i=0;i<n;++i){
        for(int j=0;j<m;++j){
            cnt+=a[i][j]*b[j];
        }
        cout<<cnt<<endl;
        cnt=0;
    }
    return 0;
}



Measured memory_bytes: 3180
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1<<30;
int n,m,out;
vvi in;
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
void dfs(int a,int b,int c){
	out=max(out,c+1);
	rep(i,4){
		int nx=a+dx[i];
		int ny=b+dy[i];
		if(nx<0||ny<0||nx>=n||ny>=m)continue;
		if(in[nx][ny]==1){
			in[nx][ny]=2;
			dfs(nx,ny,c+1);
			in[nx][ny]=1;
		}
	}
}
int main(){
	while(cin>>m>>n,n+m){
		in=vvi(n,vi(m));
		rep(i,n)rep(j,m)cin>>in[i][j];
		out=0;
		rep(i,n)rep(j,m)if(in[i][j]==1){
			in[i][j]=2;
			dfs(i,j,0);
			in[i][j]=1;
		}
		cout<<out<<endl;
	}
}

Measured memory_bytes: 1292
class BlackjackDealer
  def initialize(hand:, deck:)
    @hand = hand
    @deck = deck
    @score = 0
    @aces = 0
  end

  def get_score
    @hand.each do |card|
      @score += calc_card_value(card: card)
      @aces += 1 if card == 'A'
      adjust_score
    end

    return 'blackjack' if @score == 21

    while keep_drawing? && @deck.any?
      card = @deck.shift
      @score += calc_card_value(card: card)
      @aces += 1 if card == 'A'
      adjust_score
    end

    return 'bust' if @score > 21
    @score
  end

  private

  def keep_drawing?
    @score <= 16 || (@score == 17 && @aces >= 1)
  end

  def adjust_score
    while @score > 21 && @aces > 0
      @score -= 10
      @aces -= 1
    end
  end

  def calc_card_value(card:)
    cards_values = {'A' => 11, 'T' => 10, 'J' => 10, 'Q' => 10, 'K' => 10}
    cards_values.fetch(card) {card.to_i}
  end
end

rounds = gets.to_i

rounds.times do
  hand = gets.split
  deck = gets.split
  dealer = BlackjackDealer.new(hand: hand, deck: deck)
  puts dealer.get_score
end

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

using namespace std;

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

    int a;
    bool flag = true;
    set<int> s;
    for (int  i = 0; i < n; i++) {
        cin >> a;
        if (s.count(a)) {
            flag = false;
            break;
        }
        else {
            s.insert(a);
        }
    }

    if (flag) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 9600
function Main(input){
    input= input.split(" ");
    input= input.map(Number);
    children = 2;
    
    var sub = function(arry,num){
        var sum = 0;
        arry.forEach(element => {
            sum += element;
        });
        
        if (arry.indexOf(sum/num) !== -1){
            return true;
        }else{
            return false;
        }
        //return arry.includes(sum/num);
    }
    
    if(sub(input,children)){
        console.log('Yes');
    }else{
        console.log('No');
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8")); 

Measured memory_bytes: 20936
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <fstream>
using namespace std;

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

int a[110];
int num[110];

int main() {

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

    int r = 0;
    for (int i = 0; i < N; i++) {
        if (a[i] <= 399)num[0]++;
        else if (a[i] <= 799)num[1]++;
        else if (a[i] <= 1199)num[2]++;
        else if (a[i] <= 1599)num[3]++;
        else if (a[i] <= 1999)num[4]++;
        else if (a[i] <= 2399)num[5]++;
        else if (a[i] <= 2799)num[6]++;
        else if (a[i] <= 3199)num[7]++;
        else r++;
    }
    int cou = 0;
    for (int i = 0; i < 8; i++) {
        if (num[i] > 0)cou++;
    }

    if (cou == 0) {
        cout << 1 << ' ' << r << endl;
    }//OK
    else {
        cout << cou << ' ' <<  r + cou << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
		
		int mod = (int)1e9+7; 
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[N];
		for(int i=0;i<N;i++)A[i]=sc.nextInt();
		sc.close();
		
		int memo[] = new int[N];
		long ans = 1;
		for(int i=0;i<N;i++) {
			if(A[i]==0) {
				ans *= (3 - memo[A[i]]);
			}else {
				ans *= (memo[A[i]-1]-memo[A[i]]);
			}
			ans %= mod;
			memo[A[i]]++;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 53344
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int main() {
	int k;
	scanf("%d", &k);
	vector<bool> used(k);
	int v = 0;
	for (int i = 1;; ++i) {
		v = (v * 10 + 7) % k;
		if (!v) {
			printf("%d\n", i);
			return 0;
		}
		if (used[v]) break;
		used[v] = true;
	}
	printf("-1\n");
}


Measured memory_bytes: 3848