akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

struct edge { int to, cost; };
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VECINT;
typedef vector<ll> VECLL;


int main() {
  int N;cin>>N;
  VECINT AS(3*N);
  priority_queue<int, vector<int>, greater<int>> former_q;
  priority_queue<int, vector<int>> latter_q;
  REP(i,3*N) {
    cin>>AS[i];
    if (i<N) former_q.push(AS[i]);
    else if (i>=2*N) latter_q.push(AS[i]);
  }

  vector<ll> former_dp(N+1);
  vector<ll> latter_dp(N+1);
  priority_queue<int, vector<int>, greater<int>> _former_q_first(former_q);
  priority_queue<int, vector<int>> _latter_q_first(latter_q);
  REP(i,N) {
    former_dp[0] += _former_q_first.top();
    latter_dp[0] += _latter_q_first.top();
    _former_q_first.pop();
    _latter_q_first.pop();
  }

  // 最初と後ろ側でそれぞれ最大最小を取得
  REP(i,N) {
    former_q.push(AS[N+i]);
    former_dp[i+1] = former_dp[i]+AS[N+i]-former_q.top();
    former_q.pop();
    latter_q.push(AS[2*N-i-1]);
    latter_dp[i+1] = latter_dp[i]+AS[2*N-i-1]-latter_q.top();
    latter_q.pop();
  }

  ll ans = LLONG_MIN;
  REP(i,N+1) {
    ans = max(ans, former_dp[i]-latter_dp[N-i]);
  }
  OUT(ans);

  return 0;
}

Measured memory_bytes: 4728
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	int  n;
	cin >> n;
	vector<int> x;
	for (int i=0; i<n; i++) {
		int xi;
		cin >> xi;
		x.push_back(xi);
	}
	sort(x.begin(), x.end());
	
	int minSum = 100*100* n;
	for (int p=x[0]; p<=x[n-1]; p++) {
		int sum = 0;
		for (int i=0; i<n; i++) {
			sum = sum + (x[i] - p) * (x[i] - p);
		}
		if (sum < minSum) minSum = sum;
	}
	
	cout << minSum << endl;
	return 0;
}

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

using  namespace std;

#define FOR(x,y) for(int x = 0; x < y; x++)
#define ll long long
typedef pair<int,int> iPair;


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a,b,c;
    cin >> a >> b >> c;
    if(a==b && a != c) cout << "Yes";
    else if (a==c && a!=b) cout << "Yes";
    else if (b == c && b!=a) cout << "Yes";
    else cout << "No";
    return 0;
}



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

#define MAX_LENGTH 1000
#define CHAR_MAX_LENGTH 10

int main(void)
{
        char line[MAX_LENGTH];
        char tmp;
        char ai[CHAR_MAX_LENGTH];
        int minus = 0;
        int i = 0;
        char *tp;
        int a;
        long sum = 0;
        int min = 1000000;
        int max = -1000000;

        fgets(line, sizeof(line), stdin); //skip line

        while (1) {
                tmp = getchar();
                if (tmp == '-') minus = 1;
                else if ( ( tmp == ' ' ) || ( tmp == '\n' ) ) {
                        ai[i] = '\0';
                        sscanf(ai, "%d", &a);
                        if (minus == 1) {
                                a *= -1;
                                minus = 0;
                        }
                        i = 0;
                        sum += a;
                        if( a < min) min = a;
                        if( a > max) max = a;
                        // do process
                } else {
                        ai[i] = tmp;
                        i++;
                }
                if (tmp == '\n') break;
        }
        printf("%d %d %ld\n", min, max, sum);

        return 0;
}

Measured memory_bytes: 612
n = list(map(int, input()))


ans = 0
ind = len(n) - 1

for i in range(len(n)):
    ans += (10**i * (n[-1] * 2**ind  + sum(n[:-1]) * 2**(ind - 1)))
    n = n[:-1]
    ind = len(n) - 1
print(int(ans))

Measured memory_bytes: 3060
import scipy.sparse as s,numpy as n
f=n.loadtxt(open(0),skiprows=1)
g=s.csgraph.dijkstra(f)
h=n.where(g,g,1)
print(int(sum(t[j]*(t[j]<t+h[j]).all()for i,t in enumerate(h)for j in range(i)))*(f==g).all()or-1)

Measured memory_bytes: 18624
#include<bits/stdc++.h>
using namespace std;
string s;
int ans=0;

int main(){
    cin>>s;
    char now=s[0];
    for (int i=1;i<s.size();i++)
      if (s[i]==now) ans++,now=s[i]=='0'?'1':'0';
      else now=s[i];
    printf("%d",ans);
    return 0;
}

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

typedef long long ll;

using namespace std;

const int N = 2e5 + 100;

 
int main()
{
//	freopen("input.txt", "r", stdin);
	//提交时注释，调试时取消注释！！！ 
	int a, b;
	cin >> a >> b;
	
	int A = a + b,B = a - b, C = a * b;
	int  ans = max(A,B);
	ans = max(ans, C);
	cout << ans;
	
		
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007


int main() {
	int W, a, b;
	cin >> W >> a >> b;
	if (abs(a - b) <= W)print(0);
	else print(min(abs(a + W - b), abs(b + W - a)));






	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MXN = 5e3 + 10;
int n, r, t, a, b, A[MXN];
char ch;
int main()
{
    cin >> a >> b;
    if (b >= a)
    {
        cout << "Impossible" << endl;
        return (0);
    }
    n = a + b;
    for (int i = 1; i < n; i++)
    {
        if (r == -1)
        {
            A[++ r] = i;
            continue;
        }
        cout << "? " << A[r] << " " << i << endl;
        cin >> ch;
        if (ch == 'Y')
            A[++ r] = i;
        else
            r --;
    }
    r = A[r];
    for (int i = 0; i < n; i++)
    {
        cout << "? " << r << " " << i << endl;
        cin >> ch;
        A[i] = (ch == 'Y');
    }
    cout << "! ";
    for (int i = 0; i < n; i++)
        cout << A[i];
    cout << endl;
    return (0);
}


Measured memory_bytes: 724
#include <stdio.h>

int main(void)
{
	int l, m, n, c;
	int trip;
	int i;
	
	while (scanf("%d", &l), l != 0){
		trip = c = 0;
		for (i = 0; i < 12; i++){
			scanf("%d %d", &m, &n);
			trip += m - n;
			if (trip >= l && c == 0){
				c = i + 1;
			}
		}
		if (c == 0){
			printf("NA\n");
		}
		else {
			printf("%d\n", c);
		}
	}
	return (0);
}

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

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define Debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long LL;
typedef long double LD;
typedef unsigned int uint;
typedef pair <int, int> pii;
typedef unsigned long long uLL;

template <typename T> inline void Read(T &x) {
  char c = getchar();
  bool f = false;
  for (x = 0; !isdigit(c); c = getchar()) {
    if (c == '-') {
      f = true;
    }
  }
  for (; isdigit(c); c = getchar()) {
    x = x * 10 + c - '0';
  }
  if (f) {
    x = -x;
  }
}

template <typename T> inline bool CheckMax(T &a, const T &b) {
  return a < b ? a = b, true : false;
}

template <typename T> inline bool CheckMin(T &a, const T &b) {
  return a > b ? a = b, true : false;
}

const int N = 30;

char s[N];
bool v[N];
int n;

int main() {
#ifdef wxh010910
  freopen("d.in", "r", stdin);
#endif
  scanf("%s", s), n = strlen(s);
  for (int i = 0; i < n; ++i) {
    v[s[i] - 'a'] = true;
  }
  if (n != 26) {
    for (int i = 0; i < 26; ++i) {
      if (!v[i]) {
        s[n] = i + 'a', puts(s);
        return 0;
      }
    }
  }
  for (int i = n - 1; ~i; --i) {
    for (int j = s[i] - 'a' + 1; j < 26; ++j) {
      if (!v[j]) {
        s[i] = j + 'a', s[i + 1] = 0, puts(s);
        return 0;
      }
    }
    v[s[i] - 'a'] = false;
  }
  puts("-1");
#ifdef wxh010910
  Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
  return 0;
}


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

const int M=1e5+5;
int ans[M];

int main(){
    string s;
    cin >> s;
    int n=s.size();
    int i=0;
    while(i<n){
        int cntl=0,cntr=0;
        while(i<n&&s[i]=='R') cntr++,i++;
        int lp=i;
        while(i<n&&s[i]=='L') cntl++,i++;
        ans[lp]=(cntl+1)/2+cntr/2;
        ans[lp-1]=cntl/2+(cntr+1)/2;
    }
    rep(i,n) cout<<ans[i]<<" ";
    cout<<endl;
}

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


int main() {
    int n;
    cin>>n;
    vector<int> p(n);
    int count=0;
    for(int i=0;i<n;i++)
    {
        cin>>p[i];
        if(p[i]!=i+1) 
        count++;
    }
    if(count==2 || count==0)
     cout<<"YES"<<endl;
    else
     cout<<"NO"<<endl;
}


Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
int main(){
  string o,e;
  cin >> o >> e;
  for (int i=0;i<e.size();i++){
    cout << o[i] << e[i];
  }
  if(o.size()!=e.size()){
    cout << o[o.size()-1];
  }
  cout << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    boolean[] vis = new boolean[n];
    for(int i=0;i<n;i++){
      vis[i]=true;
    }
    boolean[] vis1 = new boolean[n];
    int[] arr = new int[n];
    for(int i=0;i<n;i++){
      arr[i]=sc.nextInt();
    }
    for(int i=0;i<m;i++){
      int a = sc.nextInt();
      int b = sc.nextInt();
      vis1[a-1]=true;
      vis1[b-1]=true;
      if(arr[a-1]>arr[b-1]){
        vis[b-1]=false;
      }
      if(arr[a-1]==arr[b-1]){
          vis[b-1]=false;
          vis[a-1]=false;
      }
      // else{
      //   vis[b-1]=false;
      // }
      if(arr[b-1]>arr[a-1]){
        vis[a-1]=false;
      }
      // else{
      //   vis[a-1]=false;
      // }
    }
    int count=0;
    for(int i=0;i<n;i++){
      if(vis[i]==true){
        count++;
      }
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 61572
#include<iostream>
#include <vector>
#include <string>
#include <tuple>
#include <cmath>
#include <queue>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <climits>
#include <map>
using namespace std;

#define ll int64_t
const long MOD = 1e9 + 7;


//しゃくとり法(条件を満たす区間をすべて求める方法)
//しゃくとり法では半区間[0,i)　で考えることが多い(ex:[0,2) なら0,1のみ )
int main()
{
  long n;
  cin >> n;
  vector<long> a(n);
  vector<long> b(n);
  vector<long> c(n);

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

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());

  for (int i = 0; i < n; ++i) {
    cerr <<  a[i] << " ";
  }cerr <<endl;
    for (int i = 0; i < n; ++i) {
    cerr <<  b[i] << " ";
  }cerr <<endl;
    for (int i = 0; i < n; ++i) {
    cerr <<  c[i] << " ";
  }cerr <<endl;

  //bjを固定すると上下調べればよい
  //cj固定でもよくね？ →　だめ
  // bjこていのみ！
  long ans = 0;

  for (int i = 0; i < n; ++i) {
    long bs = b[i];
    // cerr << bs <<endl;


    long lb = -1;  //  2 , 4  
    long ub = n;   //  3 , 6  // (-1 +2) /2 = 0
    while (ub - lb > 1) { ////0,1,2,3,4　要素数5のとき  最後 lb=0 ub=1のとき 0 - 1
      long mid = lb + (ub - lb) / 2;
      // cerr << c[mid] <<endl;
      if (bs >= c[mid]) {//昇順ソートしてるから、条件を満たすならlbを増やす //中央がbsより小さいなら
        lb= mid;
      } else {
        ub = mid;
      }
    }
    lb++;
    long cs = c[lb];
    long cnum = n- lb ;

    // cerr <<"c[" << lb <<"]:" << cs <<endl;


    lb = -1;
    ub = n;
    while (ub - lb > 1) { ////0,1,2,3,4　要素数5のとき  最後 lb=0 ub=1のとき 0 - 1
      long mid = lb + (ub - lb) / 2;
      if (bs > a[mid]) {//昇順ソートしてるから、条件を満たすならlbを増やす
        lb = mid;
      } else {
        ub = mid;
      }
    }
    // lb++;
    long as = a[lb];
    long anum = lb + 1 ;

     // cerr <<"a[" << lb <<"]:" << as <<endl;

    ans += cnum * anum;

    cerr << " cs:" << cs << " bs:" << bs << " as:" << as << endl;
    cerr  << " cnum:" << cnum << " anum:" << anum << endl;

  }

// 2*5 10
// 3*5 15
// 5*4 20
// 5*3 15
// 5*3 15
// 6*2 12




  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2560
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN = 100000;
int fa[MAXN + 5], siz[MAXN + 5];
int find(int x) {
	return fa[x] = (fa[x] == x ? x : find(fa[x]));
}
void unite(int x, int y) {
	int fx = find(x), fy = find(y);
	if( fx != fy ) {
		fa[fx] = fy;
		siz[fy] += siz[fx];
	}
}
int P[MAXN + 5], Q[MAXN + 5];
int l[MAXN + 5], r[MAXN + 5];
int stk[MAXN + 5], tp;
int main() {
	int N; scanf("%d", &N);
	for(int i=1;i<=N;i++)
		scanf("%d", &P[i]), Q[P[i]] = i;
	P[0] = P[N + 1] = N + 1;
	stk[tp = 1] = 0;
	for(int i=1;i<=N;i++) {
		while( P[stk[tp]] < P[i] ) tp--;
		l[i] = stk[tp], stk[++tp] = i;
	}
	stk[tp = 1] = N + 1;
	for(int i=N;i>=1;i--) {
		while( P[stk[tp]] < P[i] ) tp--;
		r[i] = stk[tp], stk[++tp] = i;
	}
	long long ans = 0;
	for(int i=1;i<=N;i++) {
		int x = Q[i];
		fa[x] = x, siz[x] = 1;
		if( P[x - 1] < P[x] ) unite(x, x - 1);
		if( P[x + 1] < P[x] ) unite(x, x + 1);
		long long del = 0;
		if( l[x] != 0 )
			del += (r[x] - x)*(siz[find(l[x] - 1)] + 1);
		if( r[x] != N + 1 )
			del += (x - l[x])*(siz[find(r[x] + 1)] + 1);
		ans += 1LL*del*i;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
string t[31],s[31];
int h,w,n,used[40][40];
bool del(){
	r(i,h)r(j,w)used[i][j]=0;
	r(i,h){
		r(j,w-n+1){
			int p=0;
			r(k,n)if(k)if(t[i][j]!=t[i][j+k]||t[i][j+k]=='.')p++;
			if(!p)r(k,n)used[i][j+k]=1;
		}
	}
	r(i,w){
		r(j,h-n+1){
			int p=0;
			r(k,n)if(k)if(t[j][i]!=t[j+k][i]||t[j+k][i]=='.')p++;
			if(!p)r(k,n)used[j+k][i]=1;
		}
	}
	int c=0;
	r(i,h)r(j,w)
	  if(used[i][j])
	  	t[i][j]='.',c++;
	  if(c)return 0;
	  return 1;
}
void fall(){
	r(k,h)
	r(i,h-1)r(j,w)
	  if(t[i+1][j]=='.'&&t[i][j]!='.')
	  	swap(t[i][j],t[i+1][j]);
}
bool check(){
	r(i,h)r(j,w)
	 if(t[i][j]!='.')return 0;
	return 1;
}
int main(){

	cin>>h>>w>>n;

	r(i,h) cin>>s[i];

	r(i,h)r(j,w-1){

	 	r(k,h) t[k]=s[k];

	 	swap(t[i][j],t[i][j+1]);

	 	r(k,w+h){
	 		fall();

	 		if(del())break;;

	 		fall();

	 		if(check())goto L;
	 	}
	 }
	 cout<<"NO"<<endl;
	 if(0)L:cout<<"YES"<<endl;
}

Measured memory_bytes: 3232
#      
import collections, atexit, math, sys, bisect 

sys.setrecursionlimit(1000000)
def getIntList():
    return list(map(int, input().split()))    

try :
    #raise ModuleNotFoundError
    import numpy
    def dprint(*args, **kwargs):
        #print(*args, **kwargs, file=sys.stderr)
        # in python 3.4 **kwargs is invalid???
        print(*args,  file=sys.stderr)
    dprint('debug mode')
except Exception:
    def dprint(*args, **kwargs):
        pass



inId = 0
outId = 0
if inId>0:
    dprint('use input', inId)
    sys.stdin = open('input'+ str(inId) + '.txt', 'r') #标准输出重定向至文件
if outId>0:
    dprint('use output', outId)
    sys.stdout = open('stdout'+ str(outId) + '.txt', 'w') #标准输出重定向至文件
    atexit.register(lambda :sys.stdout.close())     #idle 中不会执行 atexit
    
N, = getIntList()
#print(N)
za  = getIntList()
tot = sum(za)
ti = 0
td = 10000000
for i in range(N ):
    x = za[i]
    t = abs(x*N - tot)
    if t<td:
        td = t
        ti = i
print(ti)







Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
int a[200200]; 
int main() {
  int n;
  cin >> n;
  rep(i,n) cin >> a[i];
  ll all = 0;
  rep(i,n) all = all ^ a[i];
  rep(i,n) {
    ll now = all ^ a[i];
    cout << now << ' ';
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 4416
#include <iostream>
#include<math.h>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;

int main() {

    int n, A, B;
    cin >> n;

    if (n == 1) {
        cout << "Hello World" << endl;
        return 0;
    }

    cin >> A >> B;
    cout << A + B << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
    static final int INF = Integer.MAX_VALUE;

    static class Edge {
        int from, to, cost;

        public Edge(int from, int to, int cost) {
            this.from = from;
            this.to = to;
            this.cost = cost;
        }
    }

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        int P = sc.nextInt();

        List<Edge> edges = new ArrayList<>();
        for (int i = 0; i < M; i++) {
            edges.add(new Edge(sc.nextInt() - 1, sc.nextInt() - 1, -sc.nextInt() + P));
        }

        int[] dist = new int[N];
        Arrays.fill(dist, INF);
        dist[0] = 0;

        boolean possible = true;
        boolean[] reachableFrom = new boolean[N];
        reachableFrom[N - 1] = true;

        for (int i = 0; i < N - 1; i++) {
            for (Edge e : edges) {
                if (reachableFrom[e.to]) reachableFrom[e.from] = true;
                if (dist[e.from] == INF) continue;
                dist[e.to] = Math.min(dist[e.to], dist[e.from] + e.cost);
            }
        }

        for (Edge e : edges) {
            if (!reachableFrom[e.from] || dist[e.from] == INF) continue;
            if (dist[e.to] > dist[e.from] + e.cost) possible = false;
        }

        if (!possible) {
            System.out.println(-1);
        } else {
            System.out.println(Math.max(-dist[N - 1], 0));
        }
    }
}


Measured memory_bytes: 38852
#include<iostream>
#include<cstring>
using namespace std;
string in[101];
int main()
{
	int n;
	cin>>n>>in[1];
	for(int i=2;i<=n;i++)
	{
		cin>>in[i];
		string a=in[i],b=in[i-1];
		if(a[0]!=b[b.size()-1])
		{
			printf("No");
			return 0;
		}
		for(int j=1;j<i;j++)
			if(!in[j].compare(in[i]))
			{
				printf("No");
				return 0;
			}
	}
	printf("Yes");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <queue>

using namespace std;

#define MAX 100

#define WHITE 0
#define GRAY 1
#define BLACK 2

int T;
int N;

int M[MAX][MAX];
int C[MAX],D[MAX];

void bfs(int s)
{
    queue<int> *q = new queue<int>;

    q->push(s);
    D[s] = 0;
    C[s] = GRAY;

    while(!q->empty())
    {
        int u = q->front();
        q->pop();

        for (int v = 0; v < N; v++)
        {
            if (M[u][v] && C[v] == WHITE)
            {
                C[v] = GRAY;
                D[v] = D[u] + 1;
                q->push(v);
            }
        }

        C[u] = BLACK;
    }
}

int main ()
{
    cin >> N;

    for (int i = 0; i < N; i++)
    {
        C[i] = WHITE;
        D[i] = -1;

        for (int j = 0; j < N; j++)
        {
            M[i][j] = 0;
        }
    }

    for (int i = 0; i < N; i++)
    {
        int u, k;
        cin >> u >> k;
        u--;

        for (int j = 0; j < k; j++)
        {
            int v;
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

/*
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            if (j > 0)
                cout << " ";
            cout << M[i][j];
        }
        cout << endl;
    }
*/
    bfs(0);

    for (int i = 0; i < N; i++)
    {
        cout << i+1 << " " << D[i] << endl;
    }

    return 0;
}





Measured memory_bytes: 3136
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF (1LL<<61 + 1<<29)
typedef long long int ll;

int main() {
	int i = 0;
	string s;
	cin >> s;
	for (char c : s)
		i += (c - '-' ? 1 : -1);
	cout << i << std::endl;
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int main() {
	int n = ri();
	if (n == 1) {
		std::cout << "? 1" << std::endl;
		std::string s;
		std::cin >> s;
		if (s == "Red") std::cout << "! RB" << std::endl;
		else std::cout << "! BR" << std::endl;
		return 0;
	}
	std::vector<int> perm(2 * n);
	std::iota(perm.begin(), perm.end(), 0);
	std::mt19937 rnd(time(NULL));
	std::shuffle(perm.begin(), perm.end(), rnd);
	
	int cnt = 0;
	auto Query = [&] (std::vector<int> a) {
		if (++cnt > 210) {
			system("sleep 1.5");
			exit(0);
		}
		for (auto &i : a) i = perm[i];
		std::sort(a.begin(), a.end());
		
		std::set<int> uniq;
		for (auto j : a) if (!uniq.insert(j).second || j < 0 || j >= 2 * n || (int) a.size() != n) {
			system("sleep 0.7");
			exit(0);
		}
		
		std::cout << "?";
		for (auto i : a) std::cout << " " << i + 1;
		std::cout << std::endl;
		fflush(stdout);
		std::string s;
		std::cin >> s;
		if (s == "Red") return true;
		if (s == "Blue") return false;
		while (s != "-1") std::cerr << "x";
		system("sleep 0.2");
		exit(0);
	};
	
	int ind;
	std::map<int, bool> qans;
	{
		std::vector<int> tmp(n);
		std::iota(tmp.begin(), tmp.end(), 0);
		bool first = Query(tmp);
		qans[0] = first;
		std::iota(tmp.begin(), tmp.end(), n);
		qans[n] = Query(tmp);
		int l = 0, r = n;
		while (r - l > 1) {
			int m = l + (r - l) / 2;
			std::vector<int> query(n);
			std::iota(query.begin(), query.end(), m);
			bool cur = Query(query);
			qans[m] = cur;
			if (cur != first) r = m;
			else l = m;
		}
		ind = l;
	}
	
	std::vector<bool> res(2 * n);
	if (qans[ind]) res[ind] = true, res[ind + n] = false;
	else res[ind] = false, res[ind + n] = true;
	std::vector<int> stable;
	for (int i = ind + 1; i < ind + n; i++) stable.push_back(i);
	
	for (int i = 0; i < 2 * n; i++) {
		if (i == ind || i == ind + n) continue;
		if (i < ind || i > ind + n) {
			std::vector<int> query = stable;
			query.push_back(i);
			res[i] = Query(query);
		} else {
			std::vector<int> query;
			for (int j = ind; j <= ind + n; j++) if (j != i) query.push_back(j);
			res[i] = !Query(query);
		}
	}
	std::string ans(2 * n, '0');
	for (int i = 0; i < 2 * n; i++) {
		ans[perm[i]] = res[i] ? 'R' : 'B';
	}
	std::cout << "! " << ans << std::endl;
	
	
	return 0;
}


Measured memory_bytes: 724
#include <stdio.h>

int main(void){
	int a[3]={0};
	int n,i,min=100000000;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(min>a[i])
			min=a[i];
	}
	for(i=1;i<=min;i++){
		if(a[0]%i==0 && a[1]%i==0){
			if(n==2)
				printf("%d\n",i);
			else if(a[2]%i==0)
				printf("%d\n",i);
		}
	}
	return 0;
}

Measured memory_bytes: 596
#include "bits/stdc++.h"
using namespace std;
typedef  long long ll ;
typedef vector<int> ve ;
typedef pair <int , int> pr ;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MAX INT_MAX
#define MIN (-1 * INT_MAX)
#define rep(i,a,b) for(ll i = a ; i< b ; ++i)
#define repp(i,a,b) for(i = a ; i< b ; ++i)
#define reppp(i,a) for( ll i = a ; i >= 0 ; --i)
#define loop(i , arr)  for(auto i : arr)
#define endl '\n'
ve    vec  , vec2  , vec3  , vec4 , v , p;
ll t , n , k , m , sum , cnt;
map<int,vector<int>> graph ;
vector<ve> sv ;
vector<bool>visited ;
priority_queue<ll> pq ;
map< ll , ll> mp ,  mpp ,mpc ;
bool sortBylength(pair <string , int> &a,pair <string , int>  &b)
{
    return a.first.length() > b.first.length() ;

}
ll power(ll x, unsigned long long int y)
{
    if (y == 0)
        return 1;
    else if (y % 2 == 0)
        return power(x, y / 2) * power(x, y / 2);
    else
        return x * power(x, y / 2) * power(x, y / 2);
}
const int mod = 1e9+7 ;
char ch[100001];
const int sss = 1e6+1 ;
const int sss2 = 1e5+2 ;
int arrr[sss2] = {0} ;
vector <int> alls(6) ;
vector<int>pa ;
map<int , int> mps , mps2r ;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
   cin >> n >> k ;
   vec.resize(n) ;
   cnt = 0 ;
   rep(i , 0 , n ) cin >> vec[i] ;
   sort(vec.begin() , vec.end() , greater<int>()) ;
   rep(i , 0 , n){
       if(vec[i] < k ) break;
       cnt++ ;
   }
   cout <<cnt <<endl ;

}

Measured memory_bytes: 3700
n = int(input())
li_h = list(map(int,input().split()))
li_a = [0]*n 
ans = 0
li_count = [True]*100
while True:
    for i in range(n):
        if li_h[i] == 0:
            li_count[i] = False
    temp = li_count[0]
    if temp == True:
        count = 1
    else:
        count = 0
    for i in range(n):
        if temp != li_count[i]:
            temp = li_count[i]
            if temp == True:
                count += 1
    ans += count

    for i in range(n):
        if li_h[i] != 0:
            li_h[i] -= 1
    if li_h == li_a:
        break

print(ans)
   


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

int main(){
    int n,ans=0;
    cin>>n;

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

    for(int i=1;i<n-1;i++){
        if(b[i-1]<=b[i])ans=ans+b[i-1];
        else ans=ans+b[i];
    }

    cout<<ans+b[n-2]+b[0]<<endl;

    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    string s, t;
    cin >> s >> t;

    int n = s.size();

    int b = 0;
    for (int i = 0; i < n; i++) {
        if (s == t) b = 1;
        rotate(s.begin(), s.begin() + 1, s.end());
    }

    cout << (b ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
template<class Type> void line(const Type &a){int cnt=0;for(auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	int n,k,s;
	cin>>n>>k>>s;
	
	vi a(n);
	int p;
	for(p=0;p<k;++p){
		a[p]=s;
	}
	
	if(s==(int)1e9){
		for(p;p<n;++p){
			a[p]=(int)1e9-1;
		}
	}else{
		for(p;p<n;++p){
			a[p]=s+1;
		}
	}
	
	line(a);
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int res[5000];
int arr[5000][15];
vector<int>v[15];
int ar[15];
int totalsub;
void solve(int n,int m)
{
    totalsub=(1<<n)-1;
    for(int i=1;i<=totalsub;i++)
    {
        int temp=i,j=0;
        while(temp>0)
        {
            if(temp&1)
            {
                res[i]+=ar[j];
                for(int k=0;k<m;k++)
                {
                    arr[i][k]+=v[j][k];
                }
            }
            j++;
            temp=temp>>1;
        }
    }
}
int main()
{
    memset(res,0,sizeof(res));
    memset(arr,0,sizeof(arr));
    int n,m,k;cin>>n>>m>>k;

    for(int i=0;i<n;i++)
    {
        cin>>ar[i];
        for(int j=0;j<m;j++)
        {
            int a;cin>>a;
            v[i].push_back(a);
        }
    }
    solve(n,m);
    int ans=INT_MAX;
   for(int i=1;i<=totalsub;i++)
   {
      /* cout<<res[i]<<" ";
       for(int j=0;j<m;j++)
        cout<<arr[i][j]<<" ";
       cout<<endl;*/
       if(ans>res[i])
       {
           int f=0;
           for(int j=0;j<m;j++)
           {
               if(arr[i][j]<k)
               {
                   f=1;break;
               }
           }
           if(f==0)
           ans=res[i];
       }
   }
   if(ans==INT_MAX)
    cout<<-1;
   else
   cout<<ans<<endl;

}


Measured memory_bytes: 3972
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
ll n, a[310000], res;
int main(void){
    // Your code here!
    cin >> n;
    for (ll i = 0; i < n * 3; i++) cin >> a[i];
    sort(a, a + n * 3);
    for (ll i = n; i < n * 3; i += 2) res += a[i];
    cout << res << endl;
}


Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int dp[101][4][4][4] = {0};
    //制約がない3を直前の文字としておく
    dp[0][3][3][3] = 1;
    //len = 0 -> 1文字目を作る
    rep(len, n) rep(c1, 4) rep(c2, 4) rep(c3, 4) {
        if (dp[len][c1][c2][c3] == 0) continue;
        rep(a, 4) {
            if (c2 == 0 && c1 == 1 && a == 2) continue; //ACG
            if (c2 == 1 && c1 == 0 && a == 2) continue; //GAC
            if (c2 == 0 && c1 == 2 && a == 1) continue; //ACG
            if (c3 == 0 && c1 == 1 && a == 2) continue; //A?GC
            if (c3 == 0 && c2 == 1 && a == 2) continue; //AG?C
            dp[len + 1][a][c1][c2] += dp[len][c1][c2][c3];
            dp[len + 1][a][c1][c2] %= inf;
        }
    }
    int ans = 0;
    rep(c1, 4) rep(c2, 4) rep(c3, 4) {
        ans += dp[n][c1][c2][c3];
        ans %= inf;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define FOR(i,m,n) for(i=m;i<n;i++)


int main(void)
{
	int a,b,c,i;
	char d;
	scanf("%d %d %d",&a,&b,&c);
	printf("%d\n",c/a*b);
	return 0;
}

Measured memory_bytes: 128
x = int(input())

if x >= 400 and x < 600:
    print(8)
elif x >= 600 and x < 800:
    print(7)
elif x >= 800 and x < 1000:
    print(6)
elif x >= 1000 and x < 1200:
    print(5)
elif x >= 1200 and x < 1400:
    print(4)
elif x >= 1400 and x < 1600:
    print(3)
elif x >= 1600 and x < 1800:
    print(2)
elif x >= 1800 and x < 2000:
    print(1)

Measured memory_bytes: 9192
#pragma region def
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

using llint = long long;
using vint = vector<int>;
using vvint = vector<vector <int>>;
using pint = pair<int, int>;
const int INF = 1e9;
const long long llINF = 1e18;
#pragma endregion

int main () {
    int n; cin >> n;
    vector<string> s(n), ans;
    map<string, int> mp;
    rep(i, n) {
        cin >> s[i];
        mp[s[i]]++;
    }
    int maxn = 0;
    for (int i = 0; i < n; i++) {
        maxn = max(mp[s[i]], maxn);
    }
//    cout << maxn << endl;
    for (int i = 0; i < n; i++) {
        if (mp[s[i]] == maxn) {
            ans.push_back(s[i]);
        }
    }
    sort(all(ans));
    ans.erase(unique(ans.begin(), ans.end()), ans.end());
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 28404
#include <bits/stdc++.h>
 
using namespace std;
 
long long n, t[5000], x, y, m, ans, f[5000], q[5000];
 
int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	for(int i = 0;i < n;i++)
		cin >> t[i];
	for(int i = 0;i < n;i++)
		cin >> f[i];
	for(int i = 0;i < n-1;i++)
		cin >> q[i];
	ans = f[t[0]-1];
	for(int i = 1;i < n;i++){
		if(t[i]-t[i-1] == 1)ans+=q[t[i-1]-1];
		ans+=f[t[i]-1];
	}
	cout << ans << endl;
}

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

#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;

int main() {
    constexpr int C_MAX = 100000;
    int N, M, R;
    cin >> N >> M >> R;
    vector<int> r(R);
    REP(i, R) {
        cin >> r[i];
        --r[i];
    }
    vector<vector<pii>> g(N);
    REP(i, M) {
        int A, B, C;
        cin >> A >> B >> C;
        --A; --B;
        g[A].push_back(pii(B, C));
        g[B].push_back(pii(A, C));
    }

    const ll INF = (N << R) * C_MAX;
    int result = INF;
    int mask = (1 << R) - 1;
    REP(start, R) {
        vector<int> dp(N << R, INF);
        priority_queue<pli, vector<pli>, greater<pli>> q;
        dp[(r[start] << R) ^ (1 << start)] = 0;
        q.push(pli(0, r[start] << R ^ 1 << start));
        while (!q.empty()) {
            ll d;
            int state;
            tie(d, state) = q.top();
            q.pop();
            if (dp[state] < d) {
                continue;
            }
            int u = state >> R;
            int visited = state & mask;
            for (const pii &edge: g[u]) {
                int v = edge.first;
                int cost = edge.second;
                int k = distance(r.begin(), find(all(r), v));
                if (visited & 1 << k) {
                    continue;
                }
                int visited_next;
                if (k == R) {
                    visited_next = visited;
                } else {
                    visited_next = visited | 1 << k;
                }
                int state_next = v << R ^ visited_next;
                if (dp[state_next] > d + cost) {
                    dp[state_next] = d + cost;
                    q.push(pli(dp[state_next], state_next));
                }
            }
        }
        REP(u, N) {
            result = min(result, dp[u << R ^ mask]);
        }
    }
    cout << result << endl;

    return 0;
}

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

int main() {
    
    unsigned long long int h, w;
    cin >> h >> w;
    unsigned long long int bh = 0;
    unsigned long long int sh = 0;
    if (h == 1 or w == 1) {
        cout << 1 << endl;
        return 0;
    }
    if (h & 1) {
        bh = (h/2) + 1;
        sh = bh-1;
    } else {
        bh = h/2;
        sh = bh;
    }

    unsigned long long int total = 0;
    unsigned long long int half = w/2;
    if (w & 1) {
        total = (half + 1) * bh + (half*sh);
    } else {
        total = half * bh + half * sh;
    }
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 3628
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int[] a = new int[3];
    for(int i = 0; i < 3; i++) {
      a[i] = sc.nextInt();
    }
    Arrays.sort(a);
    int ans = 0;
    if(((a[0] + a[1]) % 2) == 0) {
      ans = ((2 * a[2]) - a[0] - a[1]) / 2;
    } else {
      ans = ((2 * a[2]) - a[0] - a[1] + 3) / 2;
    }
    System.out.println(ans);
  }
}

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

int main() {
  int N;
  cin >> N;
  vector<int> P(N);
  for (int i = 0; i < N; i++) cin >> P.at(i);
  vector<int> Q(N);
  for (int i = 0; i < N; i++) cin >> Q.at(i);
  if (P > Q) swap(P, Q);
  int cnt = 0;
  do {
    if (P == Q) break;
    cnt++;
  } while (next_permutation(P.begin(), P.end()));
  cout << cnt << "\n";
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def is_prime(n: int):
    if n == 1:
        return False
    if n % 2 == 0:
        return n == 2
    d = 3
    while d * d <= n:
        if n % d == 0:
            return False
        d += 2
    return True


def solve(Q: int, l: "List[int]", r: "List[int]"):
    pm = [is_prime(n) for n in range(1, 100001, 2)]
    tm = [
        pm[(n - 1) // 2] and (
            n == 3 or
            ((n + 1) // 2 % 2 == 1 and pm[((n + 1) // 2 - 1) // 2])
        )
        for n in range(1, 100001, 2)
    ]
    acc = [0] * (len(tm) + 1)
    for i in range(len(tm)):
        acc[i + 1] = acc[i] + int(tm[i])
    for li, ri in zip(l, r):
        print(acc[(ri - 1) // 2 + 1] - acc[(li - 1) // 2])


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    Q = int(next(tokens))  # type: int
    l = [int()] * (Q)  # type: "List[int]"
    r = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        l[i] = int(next(tokens))
        r[i] = int(next(tokens))
    solve(Q, l, r)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14048
#include <stdio.h>

int main(void){
        double r, are, circ;
        do{
                scanf("%lf", &r);
        }while(r<=0 || r>=10000);
        are=r*r*3.141592653589;
        circ=2*r*3.141592653589;
        printf("%f %f\n", are, circ);
        return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
const ll INF = 1LL<<60;
typedef pair<ll, ll> P;


int main() {
    cin>>N>>M;
    mat dp(N + 1, vec(N * 3 + 1, 0));
    dp[N][N * 3] = 1;
    ll ans = 0;
    Rrep(i, N + 1){
        //cout<<i<<endl;
        Rrep(j, N * 3 + 1){
            //if(i > j / 2) break;
            if(i == 0 || j == 0){
                (ans += dp[i][j])%=M;
            }else{
                if(j >= 1) (dp[min(i, (j - 1) / 2)][j - 1] += dp[i][j])%=M;
                if(j >= 2) (dp[i - 1][j - 2] += (dp[i][j] * (j - 1))%M)%=M;
                if(j >= 3){
                    (dp[i - 1][j - 3] += (dp[i][j] * ((j - 1) * (j - 2) % M)%M))%=M;
                }
            }
            //cout<<j<<' '<<dp[i][j]<<endl;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 94976
#include<bits/stdc++.h>
using namespace std;
int vis[100005]={0};
int dis[100005];
const int INF=1e9+7;
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=0;i<=n;i++)
        dis[i]=INF;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='1')
            vis[i]=1;
    }
    queue<int> q;
    q.push(0);
    dis[0]=0;
    while(!q.empty())
    {
        int t=q.front();
        q.pop();
        for(int i=min(k,n-t);i>=1;i--)
        {
            if(vis[t+i]==2) break;
            if(!vis[t+i])
            {
                q.push(t+i);
                vis[t+i]=2;
                dis[t+i]=dis[t]+1;
            }
        }
    }
    if(dis[n]==INF)
    {
        cout<<"-1";
        return 0;
    }
    int now=n;
    vector<int> ans;
    for(int i=n;i>0;)
    {
        //cout<<"I"<<i<<'\n';
        int t=0,tem=k;
        for(int j=1;j<=min(i,k);j++)
        {
            if(dis[i-j]==INF) continue;
            tem=j;
            if(dis[i-j]==dis[now]-2)
            {
                //cout<<dis[i-j]<<' '<<i<<' '<<j<<'\n';
                break;
            }
            else t=j;
        }
        ans.push_back(t);
        now=i-t;
        i=i-tem;

    }
    for(int i=dis[n]-1;i>=0;i--)
        cout<<ans[i]<<' ';
}


Measured memory_bytes: 1912
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------


/*------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
------------------------------------------------------------------------------*/











//------------------------------------------------------------------------------
const ll INF = 1LL << 50;
//------------------------------------------------------------------------------

void _main()
{
  int N, M;
  cin >> N >> M;

  const int NMAX = 1000;
  const int MMAX = 2000;
  int a[MMAX], b[MMAX];
  ll c[MMAX];

  rep(i, 0, M)
  {
    cin >> a[i] >> b[i] >> c[i];
    --a[i];
    --b[i];
    c[i] = -c[i];
  }

  ll dist[NMAX];

  rep(i, 0, N) dist[i] = INF;

  dist[0] = 0;

  rep(loop, 0, N - 1)
  {
    rep(i, 0, M)
    {
      if (dist[a[i]] != INF)
      {
        chmin(dist[b[i]], dist[a[i]] + c[i]);
      }
    }
  }

  ll ans = dist[N - 1];

  bool negative[NMAX];

  rep(i, 0, N) negative[i] = false;

  rep(loop, 0, N)
  {
    rep(i, 0, M)
    {
      if (dist[a[i]] != INF)
      {
        if (chmin(dist[b[i]], dist[a[i]] + c[i]))
        {
          negative[b[i]] = true;
        }

        if (negative[a[i]]) negative[b[i]] = true;
      }
    }
  }

  if (negative[N - 1])
  {
    cout << "inf" << endl;
  }
  else
  {
    cout << -ans << endl;
  }
}


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

int main(){
    int n,k;
    cin>>n>>k;
    long int count=0;
    
    for(int i=0;i<100;i++){
        n/=k;
        count+=1;
        if(n==0)break;
    }
    cout<<count<<endl;

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
int main(){
    int n;
    cin >> n;
    int a;
    cin >> a;
    if(n%500<=a){
        cout << "Yes" <<endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _20170409_AOJ
{
    class ALDS1_2A
    {
        static int count = 0;
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] iArr = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            BubbleSort(iArr, n);

            WriteArr(iArr);
            Console.WriteLine(count);

            Console.ReadLine();
        }

        static void BubbleSort(int[] _arr, int _n)
        {
            bool flag = true;
            while (flag)
            {
                flag = false;
                for (int j = _n - 1; j > 0; j--)
                {
                    if (_arr[j] < _arr[j - 1])
                    {
                        int tmp = _arr[j];
                        _arr[j] = _arr[j - 1];
                        _arr[j - 1] = tmp;
                        flag = true;
                        count++;
                    }
                }
            }
        }

        static void WriteArr(int[] _arr)
        {
            int len = _arr.Length;
            if (len > 0)
            {
                Console.Write(_arr[0]);
            }

            if (len > 1)
            {
                for (int i = 1; i < len; i++)
                {
                    Console.Write(string.Format(" {0}", _arr[i]));
                }
            }
            Console.Write("\r\n");
        }
    }
}

Measured memory_bytes: 9524
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] T = new long[N];
        for(int i=0;i<N;i++){
            T[i] = sc.nextLong();
        }
        Arrays.sort(T);
        long ans = T[N-1];
        for(int i=N-2;i>=0;i--){
            ans = scm(ans,T[i]);
        }
        System.out.println(ans);
    }
    static long scm(long A, long B){//A>=B
        if(A%B==0) return A;
        long g = gcd(A,B);
        return A/g*B;
    }
    static long gcd(long C,long D){
        if(C<D){
            long temp = D;
            D = C;
            C = temp;
        }
        if(C%D==0) return D;
        else return gcd(D,C%D);
    }
}


Measured memory_bytes: 21844
n = int(input())
A = list(map(int, input().split()))

cnt = 0
for a in A:
    if a < 0:
        cnt += 1

C = [abs(a) for a in A]
C.sort(reverse=True)
if cnt%2 == 0:
    print(sum(C))
else:
    C[-1] *= (-1)
    print(sum(C))

Measured memory_bytes: 65440
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define vii vector<int,int>
#define Sort(v) sort(v.begin(),v.end())

const int MOD = 1000000007;
const int INF = 1<<30;
using namespace std;


int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(abs(c-a)<=d or (abs(a-b)<=d && abs(b-c) <= d))cout << "Yes" << endl;
    else cout << "No" << endl;
       
    
}







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

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
          var S = cin.Read;
          var ans=1000;
          for(var i=0; i<S.Length-2; i++)
          {
            string numStr = S.Substring(i,3);
            int num = int.Parse(numStr);
            ans = Min(ans, Abs(num-753));              
          }
          WriteLine(ans);          
        }

        static long GcdArray(long[] array)
        {
            var ans = array[0];
            for(var i=1; i<array.Length; i++)
            {
                ans = Gcd(ans, array[i]);
            }
            return ans;
        }

        static long Gcd(long a, long b)
        {
            var v = new[] { a, b };
            while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
            return v[0];
        }

        static long Lcm(long a, long b)
        {
            return a / Gcd(a, b) * b;
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


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

ll dis(ll x1, ll y1, ll x2, ll y2){
    return abs(x1 - x2) + abs(y1 - y2);
}

int main()
{
    ll n;
    cin >> n;
    vector<ll> t(n), x(n), y(n);
    rep(i, n){
        cin >> t[i] >> x[i] >> y[i];
    }

    ll pre_t = 0;
    ll pre_x = 0;
    ll pre_y = 0;
    rep(i, n){
        ll dt = t[i] - pre_t;
        ll d = dis(pre_x, pre_y, x[i], y[i]);
        if (dt < d){
            cout << "No" << endl;
            return 0;
        }
        if ((dt - d) % 2 == 1){
            cout << "No" << endl;
            return 0;
        }
        pre_t = t[i];
        pre_x = x[i];
        pre_y = y[i];
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 5632