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



#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)

using namespace std;

template <class T>
using vec = std::vector<T>;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL<<60;

const double PI = acos(-1.0);

// long long積のオーバーフロー検出
bool detect_mul_overflow(ll a,ll b){
    return a>=LONG_MAX/b;   
}

int lcm(int a,int b){
    //最小公倍数
    return a/__gcd(a,b) * b;
}

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

// int型の2次元配列(3×4要素の)の宣言
// vector<vector<int>> data(3, vector<int>(4));

int n,k,a;


int main()
{
    cin>>n>>k;
    vec<ll> a(n,0);

    rep(i,n){
        cin>>a[i];
    }

    loop(i,k,n){
        if(a[i-k]<a[i]){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }

    return 0;

}




Measured memory_bytes: 4796
#include<iostream>
using namespace std;
int main()
{
  int n, i, j, result=0;
    cin >> n;
  char t, c[n];

  for(i=0; i<n; i++)
    cin >> c[i];
  i=0;
  j=n-1;
  while(i<j)
  {
    while(c[i]!='W' && i<n)
      i++;
    while(c[j]!='R' && j>=0)
      j--;
    if(i < j)
    {
      result++;
      t = c[i];
      c[i] = c[j];
      c[j] = t;
      i++;
      j--;
    }
  }
  cout << result;
  return(0);
}

Measured memory_bytes: 3768
#include<stdio.h>
void swap(int *a,int *b){
	int temp=*a;
	*a=*b;
	*b=temp;
}
int main(){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a>b){
		swap(&a,&b);
	}
	if(a>c){
		swap(&a,&c);
	}
	if(b>c){
		swap(&b,&c);
	}
	printf("%d %d %d\n",a,b,c);
	return 0;
}


Measured memory_bytes: 2684
N,M = map(int,input().split())
H = list(map(int,input().split()))
min = list()

for i in range(M):
    A,B = map(int,input().split())
    if H[A-1] > H[B-1]:
        min.append(B)
    elif H[A-1] < H[B-1]:
        min.append(A)
    else:
        min.append(A)
        min.append(B)

min = set(min)
print(len(H) - len(min))


Measured memory_bytes: 20100
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main(){
    int a,b;cin>>a>>b;
    if(b<a) a--;
    cout<<a<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
using namespace std;
map <string,int> cost;
multimap <string,string>  rule;
set <string> his;
int mk_rule(string a){
  if(his.count(a) == 0){
    his.insert(a);    
    multimap<string,string>::iterator it=rule.find(a);
    while(it != rule.end() && it->first == a) cost[a]= min(cost[a],mk_rule(it->second)),it++;
  }
  return cost[a];
}

int main(){
  int n,m,b;
  cin >> n;
  string a,c,ls[5002];
  for(int i=0;i<n;i++) cin >> ls[i] >> b, cost[ls[i]] = b;
  
  cin >> m;
  for(int i=0;i<m;i++){
    cin >> a >> c;
    rule.insert(pair<string,string>(a,c));
    rule.insert(pair<string,string>(c,a));
  }
  int ans=0;
  for(int i=0;i<n;i++)his.clear(), ans += mk_rule(ls[i]);
  cout << ans <<endl;
  return 0;
}

Measured memory_bytes: 2000
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INF 10000000000
#define mod 1000000007
#define X 1000000
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll usort(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll dsort(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll ssort(const void *a, const void *b){return strcmp((char*)a,(char*)b);}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll z(ll a){return max(a,-a);}
ll gcd(ll a,ll b){if(!b){return a;}else{return gcd(b,a%b);}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll kt(ll a){
  ll sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
ll ks(ll a){
  ll sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
void ppp(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (int i=2;i<X;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
}
ll nCr(int n,int k){
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

int jank(int a){
  char s[4]="spr";
  FOR(3)if(a==s[i])return i;
}

int main(void){
  int n;
  scanf("%d",&n);
  int a;
  FOR(n){
    scanf("%d",&a);
    if(a%2<1&&(a%3)*(a%5)){
      PRS("DENIED");
      return 0;
    }
  }
  PRS("APPROVED");
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
  
#define F first
#define S second 
#define mp make_pair
#define pb push_back
#define pf push_front
#define speed_up ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define debug cerr << "OK\n";
#define ub upper_bound
#define lb lower_bound
#define treap_pair pair<treap*, treap*>
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef set <int> si;
typedef set <ll> sll;
typedef multiset <int> msi;
typedef multiset <ll> msll;
typedef map <int, int> mi;
typedef map <ll, ll> mll;
  
const int N = 1e5 + 2;
const int M = 1e5 + 2;
const int mod = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18 + 100;

  
void data() {
    #ifdef PC
        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #endif	
}

template <typename T>
void scerr(T nums) {
    for (auto it : nums)
        cerr << it << " | ";
    cerr << "\n";
}

ll n, c, w[N], v[N], dp[N], ans = -INF;

int main() {
	data();
	scanf("%lld %lld", &n, &c);
	for (int i = 1; i <= n; ++i)
		scanf("%lld %lld", &w[i], &v[i]);
	for (int i = 0; i < N; ++i)
		dp[i] = -INF;
	dp[0] = 0;
	for (int i = 1; i <= n; ++i) 
		for (int j = c; j >= 0; --j)
			if (j >= w[i]) 
				dp[j] = max(dp[j - w[i]] + v[i], dp[j]);
   	for (int i = c; i >= 0; --i)
   		ans = max(ans, dp[i]);
   	printf("%lld", ans);
}
  
/*
    Timus: 288481RF
    CodeForces: fractal
*/


Measured memory_bytes: 1024
#include <stdio.h>

int main() {
  int a, b;
  scanf("%d %d", &a, &b);
  while(a != 0 || b != 0) {
    if(a < b) {
      printf("%d %d\n", a, b);
    } else {
      printf("%d %d\n", b, a);
    }
    scanf("%d %d", &a, &b);
  }
  return 0;
}

Measured memory_bytes: 2668
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;


signed main() {

    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    int n, a, b;

    cin >> n >> a >> b;

    cout << min(b, a * n) << endl;

    return 0;
}

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

int main()
{
	char ans[1001];
	char read[1001];
	int seak=0;
	scanf("%s",read);
	while(read[seak]!='\0')
	{
		ans[seak]=(read[seak]-'A'+23)%26+'A';
		++seak;
	}
	ans[seak]='\0';
	printf("%s\n",ans);
	return 0;
}

Measured memory_bytes: 948
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
struct node
{
    int s,e;
}list[100005];
bool cmp(node x,node y)
{
    return x.e<y.e;
}
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int x,l;
        for(int i=0;i<n;i++)
        {
            scanf("%d %d",&x,&l);
       		list[i].s=x-l;
       		list[i].e=x+l;
        }
       /* for(int i=0;i<n;i++){
       		cout<<list[i].s<<"*"<<list[i].e<<endl;
        }*/
        sort(list,list+n,cmp);   
        int ans=1,s=list[0].e;   
        for(int i=1;i<n;i++)
        {
            if(list[i].s>=s)   
            {
                ans++;
                s=list[i].e;   
            }
        }
        printf("%d\n",ans);   
    }
    return 0;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	int t;
	cin >> t;
	
	for_(c,0,t) {
		int n, k;
		cin >> n >> k;
		
		int prv, ans = 0;
		cin >> prv;
		
		priority_queue< int > que;
		
		for_(i,1,n) {
			int x;
			cin >> x;
			que.push(x - prv);
			ans += x - prv;
			prv = x;
		}
		
		while (!que.empty() && k > 1) {
			ans -= que.top(); que.pop();
			--k;
		}
		
		cout << ans << endl;
	}
}

Measured memory_bytes: 1864
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int[] x = new int[N];
		int[] y = new int[N];

		for (int i = 0; i < N; i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
		}

		sc.close();

		double[][] d = new double[N][N];
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				double dx = (x[i] - x[j]) * (x[i] - x[j]);
				double dy = (y[i] - y[j]) * (y[i] - y[j]);
				d[i][j] = Math.sqrt(dx + dy);
				d[j][i] = d[i][j];
			}
		}
		List<List<Integer>> p = permutations(IntStream.range(0, N).boxed().collect(Collectors.toList()), N);

		double sum = 0;
		for (List<Integer> l : p) {
			double tmp = 0;
			for (int i = 1; i < l.size(); i++) {
				tmp += d[l.get(i - 1)][l.get(i)];
			}
			sum += tmp;
		}

		out.println(sum / p.size());

	}

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

	private static <T> List<List<T>> permutations(List<T> l, int r) {
		if (r == 0) {
			return new ArrayList<List<T>>() {
				{
					add(new ArrayList<T>());
				}
			};
		}

		List<List<T>> result = new ArrayList<>();

		for (int i = 0; i < l.size(); i++) {
			T a = l.get(i);
			List<T> ll = new ArrayList<>(l);
			ll.remove(i);

			List<List<T>> s = permutations(ll, r - 1);
			for (List<T> ss : s) {
				List<T> z = new ArrayList<>();
				z.add(a);
				z.addAll(ss);
				result.add(z);
			}

		}

		return result;
	}

	private static <T> List<T> remove(List<T> l, T e) {
		List<T> newList = new ArrayList<>(l);
		newList.remove(e);
		return newList;
	}

	private static <T> List<T> cons(T head, List<T> tail) {
		List<T> newList = new ArrayList<>();
		newList.add(head);
		newList.addAll(tail);
		return newList;
	}
}


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

int dist(vector<int> a,vector<int> b){
  int d=0;
  rep(i,a.size()){
    d+=(a[i]-b[i])*(a[i]-b[i]);
  }
  return d;
}
 
int main() {
  int N,D;
  int ans=0;
  cin >> N >> D;
  vector<vector<int>> X(N,vector<int>(D));
  
  rep(i,N){
    rep(j,D){
      cin >> X[i][j];
    }
  }
  
  rep(i,N){
    for(int j=i+1;j<N;++j){
      int d = dist(X[i],X[j]);
      bool flag=false;
      for(int k=0;k<=d;++k){
        if(k*k==d)flag=true;
      }
      if(flag)ans+=1;
    }
  }
  
  cout << ans << endl;
}



Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	long n;
	scanf("%ld", &n);
	long a[n];
	long b[n];
	long i = 1;
	long j = 1;
	while (j <= n)
		b[j++] = 0;
	while (i < n)
	{
		scanf("%ld", &a[i]);
		b[a[i]] += 1;
		i++;
	}
	i = 1;
	while (i <= n)
		printf("%ld\n", b[i++]);
	return 0;
}


Measured memory_bytes: 5276
import string

# 1千兆 + 1
N = int(input())
n_digits = len(str(1000000000000001))
letters = string.ascii_lowercase

x = N - 1
ans = []
# while True:
#     x -= 1
#     mod = x % 26
#     ans = [ mod ] + ans
#     x = x // 26
#     if x <= 0:
#         break

# print(ans)
# print("".join([ letters[v] for v in ans ]))

while True:
    # x -= 1
    mod = x % 26
    div = x // 26
    # x = x // 26
    
    ans.append(mod)
    if div == 0:
        break
    x = div - 1

ans = ans[::-1]
print("".join([ letters[v] for v in ans ]))

Measured memory_bytes: 9972
#include <bits/stdc++.h>
#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define numa(x,a) for(auto x: a)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define pf push_front
#define sec second
#define sz(x) ((int)(x).size())
#define ALL( c ) (c).begin(), (c).end()
#define gcd(a,b) __gcd(a,b)
#define mem(x,n) memset(x,n,sizeof(x))
#define endl "\n"
using namespace std;
template <int POS, class TUPLE> void deploy(std::ostream &os, const TUPLE &tuple){}
template <int POS, class TUPLE, class H, class ...Ts> void deploy(std::ostream &os, const TUPLE &t){ os << (POS == 0 ? "" : ", ") << get<POS>(t); deploy<POS + 1, TUPLE, Ts...>(os, t); }
template <class T,class U> std::ostream& operator<<(std::ostream &os, std::pair<T,U> &p){ os << "(" << p.first <<", " << p.second <<")";return os; }
template <class T> std::ostream& operator<<(std::ostream &os, std::vector<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; }
template <class T> std::ostream& operator<<(std::ostream &os, std::set<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; }
template <class T, class K> std::ostream& operator<<(std::ostream &os, std::map<T, K> &mp){ int remain = mp.size(); os << "{"; for(auto e: mp) os << "(" << e.first << " -> " << e.second << ")" << (--remain == 0 ? "}" : ", "); return os; }
#define DEBUG1(var0) { std::cerr << (#var0) << "=" << (var0) << endl; }
#define DEBUG2(var0, var1) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG1(var1); }
#define DEBUG3(var0, var1, var2) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG2(var1,var2); }
#define DEBUG4(var0, var1, var2, var3) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG3(var1,var2,var3); }
using ll = long long;


int main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int N;
  cin >> N;
  vector <int> nums(N);
  rep(i,N){
    cin >> nums[i];
  }
  int ans = INF;
  for (int x = -100; x <= 100; x++) {
    int cost = 0;
    numa(y,nums){
      cost += (x - y) * (x - y);
    }
    ans = min(ans, cost);
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;
using Data = pair<long long, vector<int> >;

int main() {
  const int N = 3;
  vector<vector<int>> vv(N, vector<int>(N));
  for(int i = 0; i < 3; i++) for(int j = 0; j < 3; j++) cin >> vv[i][j];
  bool ok = true;
  if(vv[0][0] - vv[0][1] != vv[1][0] - vv[1][1]) ok = false;
  if(vv[1][0] - vv[1][1] != vv[2][0] - vv[2][1]) ok = false;
  if(vv[0][1] - vv[0][2] != vv[1][1] - vv[1][2]) ok = false;
  if(vv[1][1] - vv[1][2] != vv[2][1] - vv[2][2]) ok = false;
  if(vv[0][0] - vv[1][0] != vv[0][1] - vv[1][1]) ok = false;
  if(vv[0][1] - vv[1][1] != vv[0][2] - vv[1][2]) ok = false;
  if(vv[1][0] - vv[2][0] != vv[1][1] - vv[2][1]) ok = false;
  if(vv[1][1] - vv[2][1] != vv[1][2] - vv[2][2]) ok = false;
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

void maxheapify(int);

int H[5000000];
int n;

int main(){
  int i;

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%d",&H[i]);
  }

  for(i=n/2;i>=1;i--){
    maxheapify(i);
  }

  for(i=1;i<=n;i++){
    printf(" %d",H[i]);
  }
  printf("\n");

  return 0;
}

void maxheapify(int i){
  int l = 2*i;
  int r = 2*i + 1;
  int largest;
  int temp;

  if(l <= n && H[l] > H[i]){
    largest = l;
  }
  else largest = i;

  if(r <= n && H[r] > H[largest]){
    largest = r;
  }

  if(largest != i){
    temp = H[i];
    H[i] = H[largest];
    H[largest] = temp;
    
    maxheapify(largest);
  }
} 

  



Measured memory_bytes: 3812
N = int(input())

A = input().split(" ")

data = []

for i in range(0, len(A)):
    data.append(0)

# print(data)

# data[0] += 1

# print(data)

for i in A:
    data[int(i) - 1] += 1

# print(data)

for i in data:
    print(i)
print(0)

Measured memory_bytes: 92396
// https://atcoder.jp/contests/dp/tasks/dp_f
#include <bits/stdc++.h>
using namespace std;

string longer(string const& a, string const& b) {
  if (a.length() < b.length())
    return b;
  return a;
}

int main() {
  string a, b;
  cin >> a >> b;
  string t(longer(a,b)),s(a == t ? b:a);
  string lcs[2][t.length() + 1];

  for (int i = 1; i <= s.length() + 1; ++i)
    for (int j = 1; j <= t.length(); ++j) {
      // lcs[i % 2][j] =
      //     (s[i - 1] == t[j - 1])
      //         ? longer(lcs[(i + 1) % 2][j - 1] + s[i - 1],
      //               longer(lcs[i % 2][j - 1], lcs[(i + 1) % 2][j])
      //               )
      //         : longer(lcs[i % 2][j - 1], lcs[(i + 1) % 2][j]);

      lcs[i % 2][j] = longer(lcs[i % 2][j - 1], lcs[(i + 1) % 2][j]);
      if (s[i - 1] == t[j - 1])
        lcs[i % 2][j] = lcs[(i + 1) % 2][j - 1] + s[i - 1];
    }
      
  cout << lcs[1][t.length()] << endl;
}


Measured memory_bytes: 16768
#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;

typedef long long ll;
typedef pair<int, int> P;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, X; cin >> N >> X;
	vector<int> diff(N, 0);
	rep (i, N){
		int x; cin >> x;
		diff[i] = abs(X - x);
	} // end rep

	sort(ALL(diff));
		
	int g = gcd(diff[0],diff[1]);
	
	for (int i = 2; i < N; ++i){
		g = gcd(diff[i], g);
	} // end for

	cout << g << endl;

	return 0;
}

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

struct stu
{
    int x;
    int page;
} s[100000];

bool sp(stu a,stu b)
{
    return a.x<b.x;
}

int main()
{
    int n;
    while(cin>>n)
    {
        int i;
        for(i=0; i<n; i++)
        {
            cin>>s[i].x;
            s[i].page=i;
        }
        sort(s,s+n,sp);
        for(i=0; i<n; i++)
            if(i+1!=n)
                cout<<s[i].page+1<<' ';
            else
                cout<<s[i].page+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 1536
import itertools
import math
N = int(input())
xy = [list(map(int,input().split())) for i in range(N)]
s = list(range(N))
sum = 0
for v in itertools.permutations(s):
    for i in range(N-1):
        distance = math.sqrt((xy[v[i]][0]-xy[v[i+1]][0])**2 + (xy[v[i]][1]-xy[v[i+1]][1])**2)
        sum += distance
print(sum/math.factorial(N))

Measured memory_bytes: 3064
N=gets.to_i
H=gets.split.map(&:to_i)
H[0]-=1 if 1<N && H[0]>=H[1]
(1...N).each do |r|
  l=r-1
  if H[l]<H[r]
    H[r]-=1
  end
end
puts H.each_cons(2).all?{|l,r|l<=r} ? :Yes : :No

Measured memory_bytes: 21664
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) throws Exception{
        // TODO 自動生成されたメソッド・スタブ

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        Set<Integer> a = new HashSet<>();

        for (int i = 0; i < n; i++) {
            a.add(sc.nextInt());

        }
            sc.close();
            if(n == a.size()) {
                System.out.println("YES");
               }
            else {
                System.out.println("NO");
            }


    }

}


Measured memory_bytes: 70132
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T> void puts_all(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void puts_all(const T &value, const Args&... args){std::cout << value << " ";puts_all(args...);}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;


LLI solve(int k, vector<LLI> d, LLI n, LLI x, LLI m){
  LLI ret = 0;

  x %= m;
  for(auto &a : d) a %= m;

  
  LLI last = x;

  REP(i,k){
    last += ((n-2) / k) * d[i];
    if(i <= (n-2) % k) last += d[i];
  }

  //dump(last);

  ret += last / m - x / m;

  REP(i,k){
    if(d[i] == 0){
      ret += (n-2) / k;
      if(i <= (n-2) % k) ret += 1;
    }
  }

  ret = n - 1 - ret;

  return ret;
}


int main(){
  int k, q;

  while(cin >> k >> q){
    vector<LLI> d(k); cin >> d;


    REP(_,q){
      LLI n, x, m; cin >> n >> x >> m;

      auto ans = solve(k, d, n, x, m);
      puts_all(ans);
    }
  }

  return 0;
}


Measured memory_bytes: 384
BLACK = '#'
WHITE = '.'
sizeI, sizeJ = map(int, input().split())
a = [list(input()) for _ in range(sizeI)]

nBlack = 0
curStep = []
for i in range(sizeI):
    for j in range(sizeJ):
        if a[i][j] == BLACK:
            nBlack += 1
            curStep.append((i, j))
need = sizeI * sizeJ
ret = 0
while nBlack != need:
    nextStep = []
    for i, j in curStep:
        for di, dj in ((0, 1), (0, -1), (1, 0), (-1, 0)):
            ni, nj = i + di, j + dj
            if 0 <= ni < sizeI and 0 <= nj < sizeJ and a[ni][nj] == WHITE:
                a[ni][nj] = BLACK
                nBlack += 1
                nextStep.append((ni, nj))
    ret += 1
    curStep = nextStep
print(ret)


Measured memory_bytes: 127916
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//exist x map o setconst ll MOD = 1e9+7;return fac[n]*(finv[k]*finv[n-k] % MOD) % MOD;

struct RollingHash{
    static const long long base1=1007LL,base2=2009LL;
    static const long long MOD1=1000000007LL,MOD2=1000000009LL;
    vector<long long> hash1,hash2,pow1,pow2;
    RollingHash(const string &s /* ここを変える */){
        int sz=(int)s.size();
        hash1.assign(sz+1,0); hash2.assign(sz+1,0);
        pow1.assign(sz+1,1); pow2.assign(sz+1,1);
        for(int i=0;i<sz;i++){
            hash1[i+1]=(hash1[i]*base1+s[i]) % MOD1;
            hash2[i+1]=(hash2[i]*base2+s[i]) % MOD2;
            pow1[i+1]=(pow1[i]*base1) % MOD1;
            pow2[i+1]=(pow2[i]*base2) % MOD2;
        }
    }
    inline pair<long long,long long> query(int l,int r)const{
        if(l<0||r>=hash1.size()||r-l<0) return {0,0};
        long long ret1=hash1[r]-hash1[l]*pow1[r-l]%MOD1;
        ret1=(ret1+MOD1)%MOD1;
        long long ret2=hash2[r]-hash2[l]*pow2[r-l]%MOD2;
        ret2=(ret2+MOD2)%MOD2;
        return {ret1,ret2};
    }
    inline int lcp(const RollingHash &t,int a,int b)const{
        int len=min((int)hash1.size()-a,(int)hash1.size()-b);
        int ok=0,ng=len+1;
        while(ng-ok>1){
            int mid=(ng+ok)>>1;
            if(query(a,a+mid)==t.query(b,b+mid)) ok=mid;
            else ng=mid;
        }
        return ok;
    }
};
signed main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    string s,t;
    cin >> s >> t;
    string add=s;
    int n=(int)add.size();
    int szt=(int)t.size();
    while(s.size()<szt+n){
        s+=add;
    }
    RollingHash rh1(s);
    RollingHash rh2(t);
    vector<int> to(n,-1);
    rep(i,n){
        if(rh1.lcp(rh2,i,0)==szt){
            int j=(i+szt); j%=n;
            to[i]=j;
        }
    }
    vector<ll> d(n,0);
    rep(i,n){
        if(d[i]>0) continue;
        int p=i;
        while(to[p]!=-1){
            int q=to[p];
            chmax(d[q],d[p]+1);
            if(d[q]>=n+1){
                cout << -1 << endl;
                return 0;
            }
            p=q;
        }
    }
    ll ans=0;
    rep(i,n){
        chmax(ans,d[i]);
    }
    cout << ans << endl;
}



Measured memory_bytes: 74308
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif


int main(void) {
    int64_t sum;
    cin >> sum;
    if(sum <= (1e+9)) {
        cout << 0 << " " << 0 << " ";
        cout << sum << " " << 0 << " ";
        cout << sum << " " << 1 << endl;
        return 0;
    }
    int64_t p = sqrt(-100+sum);
    debug("%d\n", p);
    pii p1 = make_pair(0, 0);
    int64_t x = p; int64_t y = p+1;
    int64_t rem = x*y - sum;
    if(rem < 0) {
        rem += y;
        x++;
    }
    pii p2 = make_pair(x, rem);
    pii p3 = make_pair(1, y);

    cout << p1.first << " " << p1.second << " ";
    cout << p2.first << " " << p2.second << " ";
    cout << p3.first << " " << p3.second << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>

int main(){
	int N, T, A, i, minV = (int)(1e9 + 1), maxP = 0, ans;
	scanf("%d%d", &N, &T);
	for(i = 0; i < N; i++){
		scanf("%d", &A);
		if(A < minV){
			minV = A;
		}
		else if(maxP < A - minV){
			maxP = A - minV;
			ans = 1;
		}
		else if(maxP == A - minV){
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
// Marcin Knapik
// before you read it
// make sure it's a good idea
#include<bits/stdc++.h>
using namespace std;

typedef long long         ll;
typedef unsigned long long      ull;
typedef pair< ll, ll >        pll;
typedef pair< int, int  >       ii;
typedef vector< int  >       vi;
typedef vector< ii >        vii;
typedef vector< vi >        vvi;
typedef vector< vector < ii > >   vvii;
typedef vector< ll >        vll;
typedef vector< pll >       vpll;
typedef long double         ld;

#define boost   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define szy     first
#define gi      second
#define sz(a)   (int)(a).size()
#define pb      push_back
#define all(c)    (c).begin(), (c).end()
#define rall(c)   (c).rbegin(), (c).rend()


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

template<class T> inline T fast(T a,T b,T mod) {ll res = 1; while(b){if(b&1) res = (res*a)%mod;a = (a*a)%mod;b >>= 1;}return res;}
template<class T> inline T russian(T a, T b, T mod) {ll res = 0; while(b){if(b&1) res = (res + a)%mod; a = (a+a)%mod; b>>=1;}return res;}
template<class T> inline T sub(T a, T b, T mod) {return ((a - b)+mod)%mod;}
template <class T> istream &operator>>(istream &os, vector<T> &container){for (auto &u : container)os >> u;return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &container){for (auto &u : container)os << u << " ";return os;}
template<typename T> inline T gcd(T a, T b) { while (b)swap(a %= b, b); return a; }

ld e = 2.7182818284590452353602874713526624;
ld PI = acos(-1);
ld eps = 1e-11;

const ll T = 1 << 19;
const ll INF = 1e9 + 7;
const ll BIG_INF = 1e18 + 5;
const long long  N = 44 + 7;
ll n, m, k;
string a, b;

int main(){
	boost;
	cin >> a;
	sort(all(a));

	if(a[0] == a[1] && a[1] != a[2] && a[2] == a[3]){
		cout << "Yes";
	}
	else{
		cout << "No";
	}
}		

Measured memory_bytes: 764
#include <bits/stdc++.h>
#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++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  ll N, K;
  cin >> N >> K;
  ll x[N];
  REP(i, N) { cin >> x[i]; }

  ll ans = INF;

  REP(i, N - K + 1) {
    ll tmp;
    ll l = x[i], r = x[i + K - 1];
    if (0 < l) {
      tmp = r;
    } else if (l < 0 && 0 < r) {
      tmp = r - l + min(abs(l), abs(r));
    } else {
      tmp = abs(l);
    }

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int X,Y,Z,K;cin>>X>>Y>>Z>>K;
    int count=0;
    vector<long> a(X),b(Y),c(Z),AB(X*Y);
    for(int i=0;i<X;i++)cin>>a.at(i);
    for(int i=0;i<Y;i++)cin>>b.at(i);
    for(int i=0;i<Z;i++)cin>>c.at(i);
    
    for(int i=0;i<X;i++){
        for(int j=0;j<Y;j++){
            AB.at(count)=a.at(i)+b.at(j);
            count++;
        }
    }
    sort(AB.begin(),AB.end());
    reverse(AB.begin(),AB.end());
    
    vector<long> ans(K*Z);
    count=0;
    
    for(int i=0;i<min(K,X*Y);i++){
        for(int j=0;j<Z;j++){
            ans.at(count)=AB.at(i)+c.at(j);
            count++;
        }
    }
    sort(ans.begin(),ans.end());
    reverse(ans.begin(),ans.end());
    for(int i=0;i<K;i++)cout<<ans.at(i)<<endl;
}

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

using namespace std;


void solve() {
    int n; cin >> n;
    string s; cin >> s;
    vector<vector<int>> g(n);
    for (int _ = 1; _ < n; _++) {
        int x,y;
        cin >> x >> y;
        x--;y--;
        g[x].emplace_back(y);
        g[y].emplace_back(x);
    }

    vector<int> dp(n), sd(n), sz(n);
    function<void(int,int)> dfs = [&](int u, int p){
        sz[u] = s[u]-'0';
        sd[u] = 0;
        int mx = 0, mi = 0;
        for (int v: g[u])if(v!=p){
            dfs(v, u);
            sz[u] += sz[v];
            sd[u] += (sd[v] += sz[v]);
            dp[v] += sz[v];
            //if (mx < dp[v]) {
            //    mx = dp[v]; mi = sd[v];
            //} else if (mx == dp[v]) {
            //    mi = min(mi, sd[v]);
            //}
            mx = max(mx, dp[v] + sd[v]);
        }
        //if (mx <= sd[u] - mi) dp[u] = sd[u]&1;
        //else dp[u] = mx + mi - sd[u];
        if (mx <= sd[u]) dp[u] = sd[u]&1;
        else dp[u] = mx - sd[u];
    };
    
    int res = 1<<28;
    for (int i = 0; i < n; i++) {
        dfs(i,-1);
        if (dp[i] == 0) {
            res = min(res, sd[i]/2);
        }
    }
    if (res == 1<<28) res = -1;
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    string s;cin >> s;
    ll k;cin >> k;
    ll sz=s.size();
    vvl dp1(sz+1,vl(k+1,0));
    vvl dp0(sz+1,vl(k+1,0));
    dp1[0][0]=1;
    rep(i,sz){
        ll d=s[i]-'0';
        rep(j,k+1){
            if(d==0){
                dp1[i+1][j]+=dp1[i][j];
                dp0[i+1][j]+=dp0[i][j];
                if(j+1<=k)dp0[i+1][j+1]+=9*dp0[i][j];
            }
            else{
                if(j+1<=k)dp1[i+1][j+1]+=dp1[i][j];
                if(j+1<=k)dp0[i+1][j+1]+=(d-1)*dp1[i][j];
                dp0[i+1][j]+=dp1[i][j];
                dp0[i+1][j]+=dp0[i][j];
                if(j+1<=k)dp0[i+1][j+1]+=9*dp0[i][j];
            }
        }
    }
    cout << dp0[sz][k]+dp1[sz][k] <<endl;
}

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

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

int main(){
    string A,B,C;
    int N;
    cin  >> N >> A >> B >> C;
    ll count = 0;
    for(int i=0;i<N;i++){
        if(A[i]!=B[i]&&A[i]!=C[i]&&B[i]!=C[i]){
            count += 2;
        }else if(A[i]==B[i]&&A[i]!=C[i]||A[i]==C[i]&&A[i]!=B[i]||C[i]==B[i]&&A[i]!=B[i]){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)

int main(){

    int A, B, C;
    cin >> A >> B >> C;

    int n = 0;
    if(A == B) n++;
    if(B == C) n++;
    if(C == A) n++;

    if(n == 1) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iterator>
#include <deque>
#include <string>
using namespace std;
const int64_t INF=10000000000000000;
int64_t p;
int64_t powmod(int64_t a,int64_t b){//a^bを求める
	if(b==0){
		return 1;
	}else{
		int64_t temp = powmod(a,b/2);
		temp = temp * temp;
		if(b%2==1){
			temp = temp * a;
		}
		return temp%p;
	}
}
int main(){
	int64_t n;
	cin>>n;
	cin>>p;
	string s;
	cin>>s;
	if(p==2){
		int64_t ans=0;
		for(int64_t i=0;i<n;i++){
			if(s[i]=='0'||s[i]=='2'||s[i]=='4'||s[i]=='6'||s[i]=='8'){
				ans+=(i+1);
			}
		}
		cout<<ans<<endl;
	}else if(p==5){
		int64_t ans=0;
		for(int64_t i=0;i<n;i++){
			if(s[i]=='0'||s[i]=='5'){
				ans+=(i+1);
			}
		}
		cout<<ans<<endl;
	}else{
		map<int64_t,int64_t*> lt;
		for(int64_t i1=0;i1<p;i1++){
			int64_t *temp = new int64_t;
			if(i1==0){
				*temp=1;
			}else{
				*temp = 0;
			}
			lt.insert(make_pair(i1,temp));
		}
		int64_t counter=0;
		reverse(s.begin(),s.end());
		for(int64_t i1=0;i1<n;i1++){
			char digit = s.at(i1);
			if(i1==0){
				counter = digit-'0';
			}else{
				counter = powmod(10,i1)*(digit-'0')+counter;

			}
			counter = (counter%p);
			int64_t *ptr = lt.at(counter);
			*ptr = *ptr+1;
		}
		int64_t ans=0;

		for(int64_t i1=0;i1<p;i1++){
			ans += (*(lt.at(i1))*(*(lt.at(i1))-1))/2;
		}
		cout<<ans<<endl;
	}



}


Measured memory_bytes: 1284
/*B - Echo*/

#include <bits/stdc++.h>

using namespace std;

int main(){

	int tam;
	string cad;
	bool can = true;

	cin >> tam >> cad;

	if(tam % 2 == 1)
		can = false;
	else{

		int j = tam /2;
		for (int i = 0; i < tam / 2; ++i)
		{
			if(cad[i] != cad[j]){
				can = false;
				break;
			}
			j++;
		}

	}

	if(can)
		cout << "Yes";
	else
		cout << "No";
	
	return 0;
}

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

int main(void){
	int w;

	while(1){
		cin>>w;
		if(w == -1){
			break;
		}

		int ans = 1150;
		for(int i=11;i<=20 && i<=w;i++){
			ans += 125;
		}
		for(int i=21;i<=30 && i<=w;i++){
			ans += 140;
		}
		for(int i=31;i<=w;i++){
			ans += 160;
		}

		cout<<4280-ans<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner


object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()

    val m = new Array[Int](n)

    for (i <- 0 until n - 1) {
      val a = sc.nextInt()
      m(a - 1) += 1
    }

    m(n - 1) = 0


    for (i <- 0 until n) {
      println(m(i))
    }
  }
}

Measured memory_bytes: 67028
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
 
 
 
const int INF = 1000000;
 

const int MAX_N = 4010;
const int MAX_M = 4010;



const int MAX_V = 103;


//struct edge{ int to, cost; };
struct edge{ int to, cost; edge(int to, int cost):to(to),cost(cost){}};


int V;
vector<vector<edge> > G;
int d[MAX_V];


void dijkstra(int s){
	//greater<pii>????????????????????¨??§first????°???????????????????????????????????????????
	priority_queue<pii, vector<pii>, greater<pii> > que;
	fill(d, d + V, INF);
	d[s] = 0;
	que.push(pii(0, s));

	while(!que.empty()){
		pii p = que.top();
		que.pop();
		int v = p.second;
		if(d[v] < p.first) continue;
		for(int i = 0; i < G[v].size(); i++){
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost){
				d[e.to] = d[v] + e.cost;
				que.push(pii(d[e.to],e.to));
			}
		}
	}
}

int main(){
	int n, k;
	int t,a,b,c;
	while(cin>>n>>k){
		if(n == 0 && k == 0) break;
		V = n;
		G = vector<vector<edge> > (n + 1);
		for(int i = 0; i < k; i++){
			cin>>t;
			if(t == 0){
				cin>>a>>b;
				dijkstra(a - 1);
				if(d[b - 1] != INF) cout<<d[b - 1]<<endl;
				else cout<<-1<<endl;
			}
			else{
				cin>>a>>b>>c;
				a--; b--;
				G[a].pb(edge(b, c));
				G[b].pb(edge(a, c));
			}
		}
	}
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
const int MAX_V=51;
const int INF=10000000;
int d[MAX_V][MAX_V]; //存在しない場合はINF, d[i][i]=0
int V=51;
int N;
int a[50],b[50];
void warshall_floyd(){
    rep(k,0,V){
        rep(i,0,V){
            rep(j,0,V){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
                //d[i][i]は0にならない
            }
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N;
    rep(i,0,N) cin>>a[i];
    rep(i,0,N) cin>>b[i];
    rep(i,0,N){
        if(a[i]<b[i]||(a[i]>b[i]&&(a[i]+1)/2<=b[i])){
            cout <<-1<<"\n";
            return 0;
        }
    }
    ll ans=0;
    vector<int> v;
    rer(i,51,1){
        rep(j,0,51){
            rep(k,0,51){
                if(j==k) d[j][k]=0;
                else d[j][k]=INF;
            }
        }
        rep(j,1,51){
            rep(k,1,51){
                if(find(v.begin(),v.end(),k)!=v.end()){
                    d[j][j%k]=0;
                }
                else if(k<i){
                    d[j][j%k]=0;
                }
            }
        }
        warshall_floyd();
        ll res=0;
        rep(i,0,N){
            res|=d[a[i]][b[i]];
        }
        if(res!=0){
            v.pb(i);
            ans+=ll(1)<<i;
        }
    }
    cout <<ans<<"\n";
}

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

int main() {
  int max, min, sum, num, judge;
  while (true) {
    sum = 0;
    min = 1000;
    max = 0;
    cin >> num;
    judge = num;
    if (num == 0) break;
    for (int i = 0; i < judge; i++) {
      cin >> num;
      if (max < num) max = num;
      if (min > num) min = num;
      sum += num;
    }
    int result = (sum - max - min) / (judge - 2);
    cout << result << endl;
  }
  return 0;
}



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    ll X;
    cin >> X;
    ll money = 100;
    ll ans = 0;
    while(money < X) {
        ans++;
        money *= 1.01;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3620
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;


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

	cin >> N >> M >> K;
	cout << (N + M - 1) / M * K << endl;
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define MIN(a,b) ((a) <= (b) ? (a) : (b))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort( ALL(v) )

using namespace std;
using ll = long long;
using P = pair<int,int>;

int main()
{


    int s,w; cin>>s>>w;

    if(w>=s)cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
using namespace std;

const int mod = 1e9 + 7, N = 2e5 + 10;
typedef long long ll;
ll n, a, b, fac[N];

ll quick_pow(ll a, ll b) {
    ll ret = 1;
    for (; b; b >>= 1) {
        if (b & 1) ret = ret * a % mod;
        a = a * a % mod;
    } return ret;
}

ll C(ll n, ll m) {
    if(n < m) return 0;
    // c(n,m) = n!/m!/(n-m)!
    ll res = 1;
    rep(i, 1, m) {
        ll a = (n+i-m)%mod;
        ll b = i%mod;
        res = res*(a*quick_pow(b,mod-2)%mod)%mod;
    }
    return res;
}

ll Lucas(ll a, ll b) {
    if (a < mod && b < mod) return C(a, b);
    return Lucas(a / mod, b / mod) * Lucas(a % mod, b % mod);
}

int main() {
    cin >> n >> a >> b;
    ll ans = (quick_pow(2, n) - 1 + mod) % mod;
    ans = (ans - Lucas(n, a) + mod) % mod;
    ans = (ans - Lucas(n, b) + mod) % mod;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define sz(a) int((a).size())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define ld(a) while(a--)
#define tci(v,i) for(auto i=v.begin();i!=v.end();i++)
#define tcf(v,i) for(auto i : v)
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define repd(i,start,lim) for(long long (i)=(start);i>=(lim);i--)
#define present(c,x) (find(all(c),x) != (c).end())
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator
#define INF 		0x3f3f3f3f
#define LLINF       1000111000111000111LL
#define PI 			3.14159265358979323
#define endl '\n'
#ifdef WIN32
#define getchar_unlocked getchar
#endif
#define gc getchar
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define N 1000006
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long int ll;
typedef vector<long long int> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef tuple<int,int,int> iii;
typedef set<int> si;
typedef complex<double> pnt;
typedef vector<pnt> vpnt;
typedef priority_queue<ii,vii,greater<ii> > spq;
const ll MOD=1000000007LL;
template<typename T> T sqr(T x){return x*x;}
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
template<typename T>void read(T &x) { register T c = gc(); x = 0; int t = 0; if (c == '-') t = 1, c = gc(); for (; (c < 48 || c>57); c = gc()); for (; c > 47 && c < 58; c = gc()) { x = (x << 1) + (x << 3) + c - 48; }if (t) x = -x; }
template<typename T> T pow(T x,T y,ll m=MOD){T ans=1;while(y>0){if(y%2==1) ans=(ans*x)%m;y/=2;x=(x*x)%m;}return ans%m;} //using this instead of inbuilt pow due to precision issues in that
template<typename T> ll roundp(T x){ll ans=x;if(x-floor(x)<=0.001) ans=floor(x);else if(ceil(x)-x<=0.001) ans=ceil(x);return ans;}
int main(){
	int n; cin>>n;
	cout<<n*800-(n/15)*200<<endl;
}


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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

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

using Graph = vector<vector<int>>;

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

  Graph G(n);
  REP(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  VI dist(n, -1);
  VI from(n, -1);
  queue<int> q;

  dist[0] = 0;
  q.push(0);
  while(!q.empty()){
    int v = q.front();
    q.pop();
    for(auto nv: G[v]){
      if(dist[nv]==-1){
        dist[nv] = dist[v] + 1;
        from[nv] = v;
        q.push(nv);
      }
    }
  }

  REP(i,n){
    if(dist[i]==-1){
      ANS("No");
      return 0;
    }
  }

  ANS("Yes");

  FOR(i,1,n-1){
    ANS(from[i] + 1);
  }

  return 0;
}


Measured memory_bytes: 10656