akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

public class Main {
	
	static int mod = 1_000_000_007;

	public static void main(String[] args) {
        FastScanner in = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        long a[] = in.readArray(n,1);
        long ans = 0;
        long sum[] = new long[n];
        sum[0] = a[0];
        for(int i=1;i<n;i++) sum[i] = (sum[i-1]+a[i])%mod;
        for(int i=0;i<n-1;i++)
        	ans = (ans+(a[i]*(sum[n-1]-sum[i]+mod))%mod)%mod;
        out.println(ans);
        out.flush();
	}
	
	static class FastScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		
		String next() {
			while(!st.hasMoreTokens())
				try {
					st = new StringTokenizer(br.readLine());
				}catch(IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		int[] readArray(int n) {
			int a[] = new int[n];
			for(int i=0;i<n;i++) a[i] = nextInt();
			return a;
		}
		
		long[] readArray(int n,long x) {
			long a[] = new long[n];
			for(int i=0;i<n;i++) a[i] = nextLong();
			return a;
		}
		
	}
	
	static boolean arrayEquals(char a[], char b[]) {
		int n = a.length;
		boolean verdict = true;
		for(int i=0;i<n;i++) {
			if(a[i]!=b[i]) {
				verdict = false;break;
			}
		}
		return verdict;
	}
	
	static long lcm(long a, long b) {
		return (a*b)/gcd(a,b);
	}
	
	static long gcd(long a, long b) {
		if(b==0) return a;
		else return gcd(b,a%b);
	}
}









Measured memory_bytes: 55932
#include<bits/stdc++.h>
#define ll long long int
#define ff first
#define ss second
#define eps 1e-9

using namespace std;

int main()
{

    ll t,n,m,f,a,b,c,l,r,q,k,x,y,z,ans,mn,mx,sum=0;
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);

    {
        cin>>n;
        
        if(n%1000)
        {
            cout<< 1000 - (n%1000)<<endl;
        }
        else
        {
            cout<<0<<endl;
        }

        

    }

}



Measured memory_bytes: 3620
import numpy as np

import numpy as np

N, C = map(int, input().split(' '))
s = []
t = []
c = []
for i in range(N):
    s_i, t_i, c_i = map(int, input().split(' '))
    s.append(s_i)
    t.append(t_i)
    c.append(c_i - 1)
T = 2*max(t)
# for i in range(N):
#     table[2*s[i]-1: 2*t[i]] += 1
table = np.zeros(T)
for i in range(C):
    table_i = np.zeros(T)
    for j in range(N):
        if c[j] == i:
            table_i[2*s[j]-1: 2*t[j]] = 1
    table += table_i
print(int(np.max(table)))

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

typedef long long ll;

ll knapSack(ll W, ll wt[], ll val[], ll n) 
{ 
   ll i, w; 
   ll K[n+1][W+1]; 
   for (i = 0; i <= n; i++) 
   { 
       for (w = 0; w <= W; w++) 
       { 
           if (i==0 || w==0) 
               K[i][w] = 0; 
           else if (wt[i-1] <= w) 
                 K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]); 
           else
                 K[i][w] = K[i-1][w]; 
       } 
   } 
  
   return K[n][W]; 
}

int main(){
	ll n, wt;	cin >> n >> wt;
  	ll w[n], v[n];
    for(ll i = 0; i < n; ++i){
    	cin >> w[i] >> v[i];
    }
  	cout << knapSack(wt,w,v,n) << endl;
  	return 0;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define loop(k) rep(author_is_masa,k)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/

signed main(){
	string s;
	cin>>s;
	char a=s[0];
	if(s[0]==s[1]) {
		if(s[0]!=s[2]&&s[2]==s[3]) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}else{
		if(s[0]==s[2]&&s[1]==s[3]&&s[0]!=s[1]) cout<<"Yes"<<endl;
		else if(s[0]==s[3]&&s[1]==s[2]&&s[0]!=s[1]) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}


	return 0;
}



Measured memory_bytes: 3596
# coding: utf-8
# submission # - User: herp_sy
# https://atcoder.jp/contests/
#
# lang: Python3 (3.4.3)

import math
import statistics
import numpy as np
import queue

a = [1, 2, 3]
for i in range(2):
  r = int(input())
  a.remove(r)
print(a[0])


Measured memory_bytes: 23580
import java.util.*;
class Main {
    public static void main (String[] args) throws java.lang.Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(), b = sc.nextInt();
        System.out.printf("%d %d %.9f\n", a / b, a % b, 1.0 * a / b);
    }
}


Measured memory_bytes: 26632
N = int(input())
A = list(map(int, input().split()))

a = 0
for i in range(len(A)-1):
  mini = i
  minv = A[i]
  for j in range(i, len(A)):
    if minv > A[j]:
      mini = j
      minv = A[j]
  if i != mini:
    A[i], A[mini] = A[mini], A[i]
    a += 1

print(" ".join(list(map(str, A))))
print(a)


Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi> vii;
typedef priority_queue<int, vi, greater<int> > pqg ; // priority_queue greater
// cout.precision(10); cout<<fixed<<value;


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

  int n;
  cin>>n;
  vi  data(n);
  for(int i=0; i<n; ++i){
    cin>>data[i];
  }
  int ans = 0;
  data.push_back(-1);
  int i = 0;
  while(i<n){
    if( data[i] == data[i+1]){
      int start = 1;
      while( data[i+start] == data[i] ){ start++; }
      i = i+start ;
      ans += (start/2);
    }else{
      i++;
    }
  }
  cout<<ans<<"\n";
  return 0;
}


Measured memory_bytes: 256
<?php
// Your code here!
$input = trim(fgets(STDIN));
$str = "abcdefghijklmnopqrstuvwxyz";

$array_str = array();
$array_str = str_split($str);

foreach($array_str as $key=>$val){
    if($input == $val && $input != 'z'){
        echo $array_str[$key + 1],PHP_EOL;
         //var_dump($key);
    }
}

Measured memory_bytes: 4728
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

int main() {
    int x, y, z, one;
    cin >> x >> y >> z;
    one = y + z;
    x -= z;
    cout << x / one << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define get0(x)     (get<0>(x))
#define get1(x)     (get<1>(x))
#define get2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       9223372036854775807LL
#define LLMIN       -9223372036854775808LL
#define IMAX        2147483647
#define IMIN        -2147483648
typedef long long LL;
using namespace std;

int main(void){
    string s;
    cin>>s;
    int ns=(find(s.begin(),s.end(),'N')!=s.end())+(find(s.begin(),s.end(),'S')!=s.end());
    int we=(find(s.begin(),s.end(),'W')!=s.end())+(find(s.begin(),s.end(),'E')!=s.end());
    if(ns%2==0&&we%2==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

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

using namespace std;

int n, m, a[10];
string ID;
int ans = 0;
int even[] = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9};
vector<int> pos;

void solve(unsigned int idx, int sum)
{
  if(idx == pos.size()){
    if(sum % 10 == 0) ans++;
    return;
  }
  for(int i = 0; i < m; i++){
    int hoge = (pos[idx] % 2 ? even[a[i]] : a[i]);
    solve(idx + 1, sum + hoge);
  }
  return;
}

int main() {
  cin >> n >> ID >> m;
  for(int i = 0; i < m; i++) cin >> a[i];
  reverse(ID.begin(), ID.end());  
  for(int i = 1; i < n; i += 2){
    if(ID[i] == '*') continue;
    ID[i] = even[ID[i]-'0'] + '0';
  }
  int sum = 0;
  for(int i = 0; i < n; i++){    
    if(ID[i] != '*') sum += ID[i] - '0';
    else pos.push_back(i);
  }
  solve(0, sum);
  cout << ans <<endl;
  return 0;
}

Measured memory_bytes: 1356
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
int n,num[105],ma;
int main(){
	int i;n=read();
	for(i=1;i<=n;i++) num[read()]++;
	for(i=1;i<=n;i++) if(num[i]) ma=i;
	if(num[ma]<2){printf("Impossible\n");return 0;}
	for(i=1;i<=(ma-1)>>1;i++) if(num[i]){printf("Impossible\n");return 0;}i--;
	if(~ma&1){++i;if(num[i]!=1){printf("Impossible\n");return 0;}}
	if(ma&1){++i;if(num[i]!=2){printf("Impossible\n");return 0;}}
	for(++i;i<ma;i++) if(num[i]<2){printf("Impossible\n");return 0;}
	printf("Possible\n");return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
const long long INF=1e9+5;
const string alp="abcdefghijklmnopqrstuvwxyg"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYG";
typedef long long ll;

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


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,a[100],i,s=0,c=0;
    double x=0,t;
    cin>>n>>m;
    for(i=0;i<n;i++){
        cin>>a[i];
        s+=a[i];
    }
    x=1.0/(4*m);
    t=(s*x);
    for(i=0;i<n;i++){
        if(a[i]>=t)
            c++;
    }
    if(c<m)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
    return 0;
}

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

typedef long long ll;
const int inf = 1e9;

int main() {
	ll N,M;
	cin>>N>>M;
	vector<ll> a(N),b(N),c(M),d(M),D(N),ans(N);
	rep(i,N)cin>>a[i]>>b[i];
	rep(i,M)cin>>c[i]>>d[i];
	rep(i,N){
		D[i]=inf;
		rep(j,M){
			ll dis = abs(a[i]-c[j])+abs(b[i]-d[j]);
			if(D[i]>dis){
				ans[i]=j+1;
				D[i] = dis;
			}
		}
	}
	rep(i,N)
	cout<<ans[i]<<endl;
}

Measured memory_bytes: 256
def solve():
    N = int(input())
    if N == 0:
        return 0
    ans = ''
    plusvalue = True
    plusbit = True
    if N < 0:
        N = -N
        plusvalue = False
    c = 0
    while N != 0 or c == 1:
        b = (N & 1) + c
        if b < 2:
            c = 0
        else:
            b -= 2
            c = 1
        N >>= 1
        if b == 0:
            ans = '0' + ans
        else:
            if plusvalue:
                ans = '1' + ans
                if not plusbit:
                    c += 1
            else:
                ans = '1' + ans
                if plusbit:
                    c += 1
        plusbit = not plusbit
    return ans

print(solve())


Measured memory_bytes: 3064
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	string st;
	map<string, vector<int>>mp;
	while (getline(cin,st)) {
		string name = st.substr(0, st.find(' '));
		int page = stoi(st.substr(st.find(' ') + 1));
		mp[name].push_back(page);
	}
	for (auto m : mp) {
		cout << m.first << endl;
		sort(m.second.begin(), m.second.end());
		for (int i = 0; i < m.second.size(); ++i) {
			cout << m.second[i];
			if (i == m.second.size() - 1)cout << endl;
			else cout << " ";

		}
	}
	return 0;
}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int INF = 1000000000;
const int MOD = 1000000007;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> d(k);
  vector<vector<int>> a(k, vector<int>());
  rep(i, k){
    cin >> d[i];
    rep(j, d[i]){
      int aa;
      cin >> aa;
      a[i].push_back(aa);
    }
  }

  map<int, int> mp;
  rep(i, k){
    rep(j, d[i]){
      mp[a[i][j]]++;
    }
  }

  cout << n - mp.size() << endl;
  return 0;
}


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

// ====================================================================
#ifdef LOCAL
void __print(int x) {std::cerr << x;} void __print(long x) {std::cerr << x;} void __print(long long x) {std::cerr << x;} void __print(unsigned x) {std::cerr << x;}
void __print(unsigned long x) {std::cerr << x;} void __print(unsigned long long x) {std::cerr << x;} void __print(float x) {std::cerr << x;}
void __print(double x) {std::cerr << x;} void __print(long double x) {std::cerr << x;} void __print(char x) {std::cerr << '\'' << x << '\'';}
void __print(const char *x) {std::cerr << '\"' << x << '\"';} void __print(const std::string &x) {std::cerr << '\"' << x << '\"';} void __print(bool x) {std::cerr << (x ? "true" : "false");}
template<typename T, typename V> void __print(const std::pair<T, V> &x) {std::cerr << '{'; __print(x.first); std::cerr << ", "; __print(x.second); std::cerr << '}';}
template<size_t N> void __print(std::bitset<N> v) {std::cerr << '{'; for (size_t i = 0; i < N; i++) {std::cerr << v[i];} std::cerr << '}';}
template <typename A, typename B, typename C, typename D> void __print(std::tuple<A, B, C, D> p) {std::cerr << '(' << std::to_string(std::get<0>(p)) << ", " << std::to_string(std::get<1>(p)) << ", " << std::to_string(std::get<2>(p)) << ", " << std::to_string(std::get<3>(p)) << ')';}
template <typename A, typename B, typename C> void __print(std::tuple<A, B, C> p) {std::cerr << '(' << std::to_string(std::get<0>(p)) << ", " << std::to_string(std::get<1>(p)) << ", " << std::to_string(std::get<2>(p)) << ')';}
template <typename A, typename B> void __print(std::tuple<A, B> p) {std::cerr << '(' << std::to_string(std::get<0>(p)) << ", " << std::to_string(std::get<1>(p)) << ')';}
template<typename T> void __print(const T &x) {int f = 0; std::cerr << '{'; for (auto &i: x) std::cerr << (f++ ? ", " : ""), __print(i); std::cerr << "}";} void _print() {std::cerr << "]\n";}
template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) std::cerr << ", "; _print(v...);}
#define debug(x...) std::cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...) "?"
#endif
// ====================================================================

signed main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    int n, m;
    std::cin >> n >> m;

    std::vector<int> parent(n + 1);
    std::vector<int> size(n + 1, 1);
    std::iota(parent.begin(), parent.end(), 0);
    
    std::function<int(int)> root = [&](int x) {
        if (parent[x] == x) return x;
        return parent[x] = root(parent[x]);
    };

    std::function<void(int, int)> unite = [&](int u, int v) {
        u = root(u);
        v = root(v);
        if (u == v) return;

        if (size[u] < size[v]) std::swap(u, v);
        parent[v] = u;
        size[u] += size[v];
    };


    // std::vector<std::vector<int>> g(n + 1);

    for (int _ = 0; _ < m; _++) {
        int u, v;
        std::cin >> u >> v;
        unite(u, v); 
        // g[u].emplace_back(v);
        // g[v].emplace_back(u);
    }

    std::cout << *std::max_element(size.begin() + 1, size.end());

    return 0;
}



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

vector<float> kitaiList(200001);
float kitai(int x){
    if(kitaiList[x]!=0){
        return kitaiList[x];
    }else{
        float sum = 0;
        repX(i,x+1,1){
            sum += i;
            //cout << i<<" , "<< x << " a " << (float)i/x << endl;
        }
        sum /= x; 
        kitaiList[x] = sum;
        return sum;
    }
}

int main() {
    int N,K;
    cin >> N >> K;
    vector<int> p(N);
    rep(i,N)cin >> p[i];
    double ans = 0;
    double sum = 0;
    rep(i,N){
        if(i+K<=N){
            if(sum==0){
                rep(j,K){
                    sum += kitai(p[i + j]);
                    //cout << kitai(p[i + j]) << " ";
                }
            }else{
                sum-=kitai(p[i-1]);
                sum+=kitai(p[i+K-1]);
            }
            //cout <<endl;
            //cout << kitai(test) << endl;
            ans = max(ans,sum);
        }
    }
    //cout << kitai(6) << endl;
    cout << fixed << (double) ans << endl;

    return 0;
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const double EPS = 1e-10;

vector<lint> luns(0);

void dfs(string& X) {
    if (X.size() == 11) { return; }

    int prev = X.back() - '0';

    for (int x = 0; x < 10; x++) {
        if (abs(x - prev) > 1) continue;

        X.push_back('0' + x);
        luns.push_back(stoll(X));
        dfs(X);
        X.pop_back();
    }
}

int main() {
    lint K;
    cin >> K;

    string dummy = "";

    for (int x = 1; x < 10; x++) {
        string start = to_string(x);
        luns.push_back(stoll(start));
        dfs(start);
    }
    sort(luns.begin(), luns.end());
    // dump(luns);

    cout << luns[K - 1] << endl;

    return 0;
}

Measured memory_bytes: 11708
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		vector<int>as(N);
		vector<long long int>sums(N + 1);
		for (int i = 0; i < N; ++i)cin >> as[i];
		for (int i = 0; i < N; ++i) {
			sums[i + 1] = sums[i] + as[i];
		}
		long long int ans = -1e8;
		for (int l = 0; l < N; ++l) {
			for (int r = l + 1; r <= N; ++r) {
				ans = max(ans, sums[r] - sums[l]);
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

vector<int> G[1 << 17];
int S, T, N, M;
int d[1 << 17][3];

main()
{
    cin >> N >> M;
    for (int i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
    }
    for (int i = 0; i < N; i++)
        for (int j = 0; j < 3; j++)
            d[i][j] = 2e9 ;
    cin >> S >> T;
    S--, T--;
    queue<pair<int, int>> P;
    P.push({S, 0});
    d[S][0] = 0;
    while (!P.empty())
    {
        int u = P.front().first;
        int c = P.front().second;
        P.pop();
        for (int v : G[u])
        {
            if (d[v][(c + 1) % 3] > d[u][c] + 1)
            {
                d[v][(c + 1) % 3] = d[u][c] + 1;
                P.push({v, (c + 1) % 3});
            }
        }
    }
    cout << (d[T][0] % 3 == 0 ? d[T][0] / 3 : -1) << endl;
}


Measured memory_bytes: 7680
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int A = in.nextInt();
            int B = in.nextInt();
            out.println(Math.min(A * N, B));
        }

    }
}



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

int main() {
	int i, j, k;
	char a[1000], b[1000], *p;
	while(scanf("%s%s",a,b)!=EOF) {
		j = strlen(a);
		k = strlen(b);
		if(j>k) {
			p = a;
			i = j;
			j = k;
			k = i;
		}
		else{
			p = b;
		}
		
		for(i=0;i<j;i++) {
			printf("%c%c",a[i],b[i]);
		}
		if(j != k)printf("%c",p[k-1]);
		printf("\n");
	}
}

Measured memory_bytes: 128
#include<cstdio>
#include<queue>
#include<map>
using namespace std;
typedef pair< int, int > Pi;
int info[100][100];
bool used[100];

int prim(const int& V){
  priority_queue< Pi > que;
  que.push(Pi());
  int ret = 0;
  while(!que.empty()){
    Pi p = que.top(); que.pop();
    if(!~-p.first || used[p.second]++) continue;
    ret -= p.first;
    for(int i = 0; i < V; i++) que.push( Pi( -info[p.second][i], i));
  }
  return ret;
}

int main(){
  int N;
  scanf("%d", &N);
  for(int i = 0; i < N; i++){
    for(int j = 0 ; j < N ; j++){
      scanf("%d", &info[i][j]);
    }
  }
  printf("%d\n", prim(N));
}

Measured memory_bytes: 1184
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

class Mod
{
    static const int MOD = 1000000007;
    long long a;
public:
    Mod(){
        a = 0;
    }
    Mod(long long x){
        a = (x % MOD + MOD) % MOD;
    }
    const Mod operator+(const Mod& x) const{
        return Mod(a + x.a);
    }
    const Mod operator-(const Mod& x) const{
        return Mod(a - x.a);
    }
    const Mod operator*(const Mod& x) const{
        return Mod(a * x.a);
    }
    const Mod operator/(const Mod& x) const{ // フェルマーの小定理、MODが素数である場合のみ有効
        int b = MOD - 2;
        long long c = x.a;
        long long ret = 1;
        while(b > 0){
            if(b & 1){
                ret *= c;
                ret %= MOD;
            }
            c *= c;
            c %= MOD;
            b >>= 1;
        }
        return Mod(a * ret);
    }
    long long getValue(){
        return a;
    }
};

vector<Mod> factorial;

Mod combination(int n, int r)
{
    return factorial[n] / (factorial[r] * factorial[n-r]);
}

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

    factorial.resize(h+w+1);
    factorial[0] = 1;
    for(int i=1; i<=h+w; ++i)
        factorial[i] = factorial[i-1] * i;

    Mod ans = combination(h + w - 2, h - 1);
    for(int i=0; i<min(a, b); ++i){
        int y = h - a + i;
        int x = b - i - 1;
        ans = ans - combination(y + x, y) * combination((h - 1 - y) + (w - 1 - x), h - 1 - y);
    }
    cout << ans.getValue() << endl;

    return 0;
}

Measured memory_bytes: 1792
N, M = map(int, input().split())
def sta(n):
  one = 1
  for i in range(1, n + 1):
    one *= i
  return one

if N >= 3:
  num = sta(N)/(sta(2)*sta(N-2))
if N == 2:
  num = 1
if N <= 1:
  num = 0

if M >= 3:
  mum = sta(M)/(sta(2)*sta(M-2))
if M == 2:
  mum = 1
if M <= 1:
  mum = 0

print(int(num + mum))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int A,B;
	scanf("%d %d",&A,&B);

	printf("%d\n",A*B);

	return 0;
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define REP(w, n) for(int w=0;w<int(n);++w)

int main() {
    int n; cin >> n;
    int a[n]; REP(i, n) {
        int t; cin >> t;
        a[i] = t - 1;
    }
    int b[n]; REP(i, n) cin >> b[i];
    int c[n]; REP(i, n - 1) cin >> c[i];

    int res = 0;
    int pre = -100;
    REP(i, n) {
        res += b[a[i]];
        if (pre + 1 == a[i]) res += c[pre];
        pre = a[i];
    }

    cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#define ll long long
#include<vector>
using namespace std;
int arr[3000][3000];
long long dp[401][401] = {{-1}};

void check(int arr[])
{
    for(int i=0; i<10; ++i)
    {
        arr[i]++;
    }
}


int main()
{
    ll n,k;
    cin>>n>>k;
    unordered_map<ll, ll> m;
    for(int i=1; i<=n; ++i)
    {
        ll temp;
        cin>>temp;
        m[i] = temp;
    }






    if( k > n)
    {
        queue<ll> a;
        unordered_set<ll> s;
        ll current = 1;
        a.push(1);
        s.insert(1);
        while(1)
        {
            current = m[current];
            if(s.find(current) != s.end())
            {
                break;
            }
            a.push(current);
            s.insert(current);
        }

        ll total = 0;
        while(a.front() != current)
        {
            total++;
            a.pop();
        }
        k-=total;
        k%=a.size();
        while(k>-1)
        {
            current = a.front();
            a.pop();
            k--;
        }
        cout<<current;
    }
    else
    {
        ll current = 1;
        while(k--)
        {
            current = m[current];
        }
        cout<<current;
    }
}


Measured memory_bytes: 19884
from statistics import mean, median,variance,stdev
import sys
import math

a = input().split()
#y = input().split()

x = int(a[0])
y = int(a[1])
if (x+y)%3 == 0 or x%3 == 0 or y%3==0:
    print("Possible")
else: print("Impossible")

Measured memory_bytes: 6028
#include<cstdio>
#include<cstring>
using namespace std;
const int N=101,
xx[4]={0,1,0,-1},
yy[4]={1,0,-1,0};
int i,j,k,n,he,ta,a,b,c,flag,las;
int f[N][N][N],q[N*N][2],nex[2],mo[N],pre[N],h[N][N];
int can(int x,int y)
{
	if (x>=0&&x<=100&&y>=0&&y<=100&&!f[i][x][y])
		return 1;
	return 0;
}
int main()
{
	memset(h,0x3f,sizeof(h));
	scanf("%d",&n);
	for (i=1;i<=n;++i)
	{
		scanf("%d%d%d",&a,&b,&c);
		if (!c)
			mo[i]=1;
		else
		{
			pre[i]=las;
			las=i;
		}
		q[1][0]=a,q[1][1]=b;
		h[a][b]=c;
		f[i][a][b]=c+1;
		for (he=ta=1;he<=ta;++he)
		{
			for (j=0;j<4;++j)
			{
				nex[0]=q[he][0]+xx[j];
				nex[1]=q[he][1]+yy[j];
				if (can(nex[0],nex[1]))
				{
					q[++ta][0]=nex[0];
					q[ta][1]=nex[1];
					f[i][nex[0]][nex[1]]=f[i][q[he][0]][q[he][1]]+1;
				}
			}
		}
	}
	for (i=0;i<=100;++i)
		for (j=0;j<=100;++j)
		{
			flag=1;
			for (k=las;pre[k];k=pre[k])
				if (f[k][i][j]!=f[pre[k]][i][j])
				{
					flag=0;
					break;
				}
			if (flag)
				for (k=1;k<=n;++k)
					if (mo[k])
						flag&=f[k][i][j]>=f[las][i][j];
			if (flag&&f[las][i][j]>1&&h[i][j]>0)
			{
				printf("%d %d %d",i,j,f[las][i][j]-1);
				return 0;
			}
		}
	return 0;
}

Measured memory_bytes: 4224
N = int(input())
A = list(map(int, input().split()))

money = 1000;stack=0

for i in range(N-1):
    if A[i]<A[i+1]:
        stack+=money//A[i]
        money %= A[i]
    elif A[i]>A[i+1]:
        money += stack*A[i]
        stack=0

money += stack*A[N-1]
stack=0

print(money)


Measured memory_bytes: 9088
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
//----------------------------------------------------------------

// int MOD = 998244353;
int MOD = 1000000007;
// int m[1001][1001] = {0};
//----------------------------------------------------------------
signed main(){

	ll n,k;
	cin >> n >> k;
	vll p(n);
	rep(i,n)cin >> p[i];
	vll s(n,0);
	rep(i,n-1){
		if(p[i+1]>p[i])s[i+1] = s[i]+1;
		else s[i+1] = 0;
	}
	rep(i,n)cerr << s[i] << " ";cerr << endl;

	set<ll> h;
	rep(i,k)h.insert(p[i]);
	ll pre_maxi = *(h.rbegin());
	ll pre_mini = *(h.begin());
	ll cnt = 0;
	ll sorted_cnt = 0;
	for(int i = 0;i+k-1 < n;i++){
		int st = i;
		int en = i+k-1;
		int sorted = 0;
		if(s[en]-s[st] == k-1)sorted = 1;
		// cerr << sorted << " ";
		if(i == 0){
			if(sorted){
				sorted_cnt++;
			}else{
				cnt++;
			}
		}
		else{
			if(sorted)sorted_cnt++;
			if((p[st-1] == pre_mini && p[en] > pre_maxi)||sorted){
				cerr << i << " ";
			}else{	
				cnt++;
			}
			h.erase(p[st-1]);
			h.insert(p[en]);
			pre_maxi = *(h.rbegin());
			pre_mini = *(h.begin());
		}
	}
	if(sorted_cnt >= 1)cnt++;	
	cout << cnt << endl;


	return 0;
}

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

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://ddcc2017-final.contest.atcoder.jp/tasks/ddcc2017_final_b
// rm -r -f test;oj dl https://agc038.contest.atcoder.jp/tasks/agc038_a

Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int n;
  cin >> n;
  vi a(n);
  REP(i, n) { cin >> a[i]; }

  int ans = 0;
  int cur = 1;
  REP(i, n) {
    if (a[i] == cur) {
      cur++;
    } else {
      ans++;
    }
  }
  if (ans == n) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}


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

void swap_pair(pair<int,int> *p) {
  int tmp;
  tmp = p->first;
  p->first = p->second;
  p->second = tmp;
}

int main() {
  //init
  int N,M;
  cin >> N >> M;
  int H[N];
  vector <pair<int, int>> R;
  for (int i=0; i<N; i++)
    cin >> H[i];

  for (int i=0; i<M; i++) {
    pair <int, int> tmp;
    cin >> tmp.first >> tmp.second;
    R.push_back(tmp);
    swap_pair(&tmp);
    R.push_back(tmp);
  }
  
  //main
  int ans=0;
  bool is_good[N];
  for (int i=0; i<N; i++)
    is_good[i] = true;

  for (auto &p:R) {
    if (H[p.first-1] <= H[p.second-1])
      is_good[p.first-1] = false;
  }

  for (int i=0; i<N; i++)
    if (is_good[i]) ans++;

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



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

int main() {
  int a, b, c, d; cin >> a >> b >> c >> d;
  int answer = 0;
  
  if (a <= c && b > c) answer = min(b - c, d - c);
  if (c <= a && d > a) answer = min(b - a, d - a);
  
  cout << answer << endl;
}

Measured memory_bytes: 256
import sys, re
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from collections import deque, defaultdict, Counter
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop, heapify
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
ab = [LIST() for _ in range(M)]

#隣接行列
graph = [[0]*N for _ in range(N)]

for a, b in ab:
	graph[a-1][b-1] = 1
	graph[b-1][a-1] = 1

ans = 0
for x in permutations(range(1, N)):
	x = list(x)
	x.insert(0, 0)
	#print(x)
	for i in range(N-1):
		if graph[x[i]][x[i+1]] != 1:
			break
	else:
		ans += 1

print(ans)


Measured memory_bytes: 5204
#dekimasen-deshita-
n = int(input())
s = [input(), input()]
mod = 10**9+7
i = 0
ans = 3
pre = 0

while i < n:
    if s[0][i] == s[1][i]:
        typ = 1
        i += 1
    else:
        typ = 2
        i += 2
    if pre == 0 and typ == 2:
        ans *= 2
    elif pre == 1:
        ans = (ans*2)%mod
    elif pre == 2 and typ == 2:
        ans = (ans*3)%mod
    pre = typ
print(ans)

Measured memory_bytes: 3064
#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 << 25;
const int MOD = 1e9+7;
ll lsum[100100],red;
int main() {
  int n;
  cin >> n;
  vector<int> a(3*n);
  rep(i,3*n) cin >> a[i];
  priority_queue<int,vector<int>,greater<int>> R;
  rep(i,n) {
    red += a[i];
    R.push(a[i]);
  }
  lsum[0] = red;
  rep(i,n) {
    R.push(a[n+i]);
    lsum[i+1] = lsum[i] + a[n+i] - R.top();
    R.pop();
  }

  red = 0;
  priority_queue<int> B;
  rep(i,n) {
    red += a[2*n+i];
    B.push(a[2*n+i]);
  }
  ll ans = lsum[n] - red;
  rep(i,n) {
    B.push(a[2*n-i-1]);
    red += a[2*n-i-1] - B.top();
    B.pop();
    ans = max(ans,lsum[n-1-i]-red);
  }
  cout << ans << endl;
}

Measured memory_bytes: 6144
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string A, B;
    cin >> A >> B;
    if (A.size() < B.size()) {
        cout << "LESS" << endl;
        return 0;
    } else if (A.size() > B.size()) {
        cout << "GREATER" << endl;
        return 0;
    } else {
        rep(i, 0, A.size()) {
            if (A[i] < B[i]) {
                cout << "LESS" << endl;
                return 0;
            } else if (A[i] > B[i]) {
                cout << "GREATER" << endl;
                return 0;
            }
        }
        cout << "EQUAL" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	long int A, B, total;
	int count;
	while (scanf("%ld %ld", &A, &B) != EOF)
	{
		total = A + B;
		for (count = 0; total != 0; total /= 10, count++);
		printf("%d\n", count);
	}
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>                                                                          
using namespace std;
int main()
{
  string S;
  cin >> S;
  int t=S.size();
  while(1){
    t-=2;
    string a,b;
    a=S.substr(0,t/2);
    b=S.substr(t/2,t/2);
    if(a==b){
      cout << t << endl;
      break;
    }
  }

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <stdlib.h>
#include <cassert>
#include <time.h>
#include <numeric>
#include <iomanip> 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef vector<int> vi;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define ll long long int
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fill(a,v) memset(a,v,sizeof(a));
#define all(v) v.begin(),v.end()
#define rep(i, a, b) for(int i = a; i < b; i++)
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define trarr(a,n) rep(i,0,n) cerr<<a[i]<<" \n"[i==n-1];
#define trmat(g,n,m) rep(i,0,n)rep(j,0,m) cerr<<g[i][j]<<" \n"[i==m-1];
#define tr(...) cerr<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
template<typename S, typename T> 
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.ff<<", "<<p.ss<<')';return out;}
template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
int l=v.size();for(int i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}
template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

const ld PI = acos(-1);
const ld EPS = 1e-9;
const int inf = 1e9+10;
const ll INF = 1e18+10;
const int P = 1e9+7;
const int N = 2e5+10;

void solve(int _t){
	int n;
	cin >> n;
	map<string,int> m;
	string s;
	m["AC"] = 0;
	m["WA"] = 0;
	m["TLE"] = 0;
	m["RE"] = 0;
	rep(i, 0, n){
		cin >> s;
		m[s]++;
	}
	cout << "AC x "<< m["AC"]<<endl;
	cout << "WA x "<< m["WA"]<<endl;
	cout << "TLE x "<< m["TLE"]<<endl;
	cout << "RE x "<< m["RE"]<<endl;
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t = 1;
	// cin >> t;
	rep(test, 1, t+1){
		solve(test);
	}
	return 0;
}  

Measured memory_bytes: 3660
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <climits>
#include <algorithm>
using namespace std;
typedef pair<double,double> P;
typedef pair<double,int> NODE;
#define X first
#define Y second
#define DST first
#define POS second
double ecd(P A,P B){
	A.X = A.X-B.X;
	A.Y = A.Y-B.Y;
	return sqrt(A.X*A.X+A.Y*A.Y);
}


int main(){
	int n,a,b,m;
	double x,y;
	while(cin >> n && n){
		map<int,P> coord;
		map<int,int> from;
		map<int,vector< pair<int,double> > > info;
		map<int,double> memo,tmp;
		for(int i=0;i<n;i++){
			cin >> a >> x >> y;
			coord[a] = make_pair(x,y);
		}
		
		for(map<int,P>::iterator it1 = coord.begin();it1 != coord.end();it1++){
			for(map<int,P>::iterator it2 = coord.begin();it2 != coord.end();it2++){
				if(!(ecd((*it1).second,(*it2).second) > 50.0)){
					info[(*it1).first].push_back( make_pair((*it2).first,ecd((*it1).second,(*it2).second)));
				}
			}
			tmp[(*it1).first] = (1<<25);
		}

		cin >> m;
		
		for(int i=0;i<m;i++){
			cin >> a >> b;
			vector<int> route;
			priority_queue<NODE,vector<NODE>,greater<NODE> > Q;
			Q.push(make_pair(0,a));
			memo = tmp;
			memo[a]=0;
			from[a]=-1;
			while(Q.size()){
				NODE q = Q.top();Q.pop();
				if(q.POS == b){
					int p = q.POS;
					while(~p){
						route.push_back(p);
						p = from[p];
					}
					break;
				}
				for(int i=0;i<info[q.POS].size();i++){
					if(memo[info[q.POS][i].first] > q.DST + info[q.POS][i].second){
						memo[info[q.POS][i].first] = q.DST + info[q.POS][i].second;
						from[info[q.POS][i].first] = q.POS;
						Q.push(make_pair(memo[info[q.POS][i].first],info[q.POS][i].first));
					}
				}
			}
			if(route.size()){
				reverse(route.begin(),route.end());
				for(int i=0;i<route.size();i++){
					if(i)cout << " ";
					cout << route[i];
				}
			}else{
				cout << "NA";
			}
			cout << endl;
		}
	}
}

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

int main()
{
	int a,b,count=1;
    cin>>a>>b;
    if(b==1)
    {
        cout<<0<<endl;
        return 0;
    }
    int ans=a;
	while(ans<b)
    {
        count++;
        ans+=a-1;
    }
    cout<<count;
}

Measured memory_bytes: 3616
import math, bisect

n, m = map(int, input().split())

s = set()
for x in range(1, math.ceil(math.sqrt(m)) + 1):
    if m % x == 0:
        s.add(x)
        s.add(m // x)

t = list(sorted(s))
i = bisect.bisect_left(t, n)
print(m // t[i])

Measured memory_bytes: 38640
//sが0個以上余っていたらtを消せる
#include <iostream>
#include <string>
using namespace std;

string s;

signed main() {
	cin >> s;
	
	int i;
	int num = 0, ans = 0;
	for (i = 0; i < s.length(); i++) {
		if (s[i] == 'T') {
			if (num > 0) {
				num--;
				ans += 2;
			}
		}
		else {
			num++;
		}
	}
	ans = (int)s.length() - ans;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
nk = gets.split(" ").map(&:to_i)
n = nk[0]
k = nk[1]
num = gets.split(" ").map(&:to_i)

for i in k..(n - 1)
  if (num[i - k] < num[i])
    puts "Yes"
  else
    puts "No"
  end
end


Measured memory_bytes: 33772
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

int main(){
  ll n,a[10010],b[10010],A=0,B=0;
  cin>>n;
  fr(i,n) cin>>a[i];
  fr(i,n) cin>>b[i];
  fr(i,n){
    if(a[i]>b[i]) A+=a[i]-b[i];
    else B+=(b[i]-a[i])/2;
  }
  cout<<(A<=B?"Yes":"No")<<endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int       lint;
typedef vector<int>         vi;
typedef vector<lint>        vl;
typedef pair<int, int>      pii;
typedef vector<pii>         vii;
typedef set<int>            si;
typedef map<string, int>    msi;
 
#define pb(n)           push_back(n)
#define ALL(n)          (n.begin(), n.end())
#define SORT(n)         (n.begin(), n.end(), greater<lint>())       
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define M               10000000
#define MOD             10000007
#define INF             10000000000000000
#define REP(i,a,b)      for(int i = int(a); i <= int(b); i++)
#define REPL(i,a,b)     for(lint i = lint(a); i <= lint(b); i++)
#define fastIO()        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

bool cmp(string a, string b){
    return a + b < b + a;
}
int main()
{
    lint n, l;
    cin>>n>>l;

    vector<string>v(n);

    REP(i, 0, n - 1) cin>>v[i];

    sort(v.begin(), v.end(), cmp);

    REP(i, 0, n - 1) cout<<v[i];
    cout<<endl;

    return 0;
}


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

int main() {
  int a;
  cin >> a;
  vector<int> b(a);
  for(int i = 0;i < a;++i){
    cin >> b.at(i);
  }
  int aa = 0;
  int cc = 222222;
  for(int x : b){
    if(x < cc){
      cc = x;
      aa++;
    }
  }
cout << aa << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  //     <=          <
  //sort(Jnê, Iè);

  int n;


  while(1){
    cin >> n;

    if(n == 0) break;

    int data[1000];

    int sum = 0;

    for(int i = 0; i < n; i++){

      cin >> data[i];
      sum += data[i];

    }
    sort(data, data+n);

    sum -= data[0];
    sum -= data[n-1];

    sum = sum / (n - 2);

    cout << sum << endl;

  }

  return 0;

}
    


    

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

int main() {
  int H, W, ans=0;
  cin >> H >> W;
  vector<vector<char>> Map(H, vector<char>(W));
  vector<vector<int>> BFS(H, vector<int>(W,-1));
  for (int i=0; i<H; i++) {
    for(int j=0; j<W; j++) {
      cin >> Map[i][j];
      if(Map[i][j]=='.') ans++;
    }
  }
  deque<tuple<int, int, int>> dq;
  dq.push_back(make_tuple(0,0,0));
  BFS[0][0]=0;
  int x, y, cnt, cury, curx, dy[4]={0,-1,0,1}, dx[4]={1,0,-1,0};
  bool flg=false;
  while(!dq.empty()) {
    if(flg) break;
    tie(cury,curx,cnt)=dq.front();
    cnt++;
    dq.pop_front();
    for(int i=0; i<4; i++) {
      y = cury+dy[i];
      x = curx+dx[i];
      if(y<0||y>=H||x<0||x>=W) continue;
      else if(Map[y][x]=='#'||BFS[y][x]!=-1) continue;
      else {
        BFS[y][x]=cnt;
        if(y==H-1&&x==W-1) {flg=true; break;}
        dq.push_back(make_tuple(y,x,cnt));
      }
    }
  }
  if(BFS[H-1][W-1]==-1) cout << -1 << "\n";
  else cout << ans-BFS[H-1][W-1]-1 << "\n";
  return 0;
}     

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

int main()
{
	int n,k;
	cin>>n>>k;
	if(n%k==0)
		cout<<0;
	else
		cout<<1;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<ctype.h>
#include<string.h>
int main(){
	char text;
	while(1){
		scanf("%c",&text);
		if(text=='\n')	break;
		if(isalpha(text)){
			if(islower(text))	printf("%c",toupper(text));
			else if(isupper(text))	printf("%c",tolower(text));
		}else	printf("%c",text);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 1756
#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    ll n, p;
    cin >> n >> p;
    if (n == 1)
        cout << p << endl;
    else
    {
        ll ans = 1;
        for (ll i = 2; i * i <= p; i++)
        {
            ll cnt = 0;
            while (p % i == 0)
            {
                cnt++;
                p /= i;
            }
            if (cnt >= n)
            {
                repi(j, cnt / n, 0)
                {
                    ans *= i;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	static int n;
	static int m;
	static String s;
	static String t;
	static int[][] dp;
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int K = stdIn.nextInt();
		for(int ii = 0; ii < K; ii++) {
			String sS = stdIn.next();
			String tS = stdIn.next();
		
			n = sS.length();
			m = tS.length();
			s = sS;
			t = tS;
			dp = new int[n+1][m+1];
		
			for(int i = 0; i < n+1; i++) {
				for(int j = 0; j < m+1; j++) {
					dp[i][j] = -1;
				}
			}
		
			int ans = sorv(0,0);
			System.out.println(ans);
		}
	}
	
	static int sorv(int i, int p) {
		if(dp[i][p] != -1) return dp[i][p];
		if(i == n || p == m) {
			return 0;
		}
		int tmp = t.indexOf(Character.toString(s.charAt(i)), p);
		int c0 = 0;
		int c1 = 0;
		if(tmp >= 0) {
			c0 = sorv(i+1,tmp+1)+1;
			c1 = sorv(i+1,p);
		}
		int c2 = sorv(i+1,p);
		
		int max = c0;
		if(max < c1) max = c1;
		if(max < c2) max = c2;
		
		dp[i][p] = max;
		return max;
		
	}

}

Measured memory_bytes: 189220
#include <iostream>

using namespace std;

int main() {
  double a, b;
  double A[]={35.50,37.50,40.00,43.00,50.00,55.00,70.00};
  double B[]={71,77,83,89,105,116,148};
  string C[]={"AAA","AA","A","B","C","D","E","NA"};
  while(cin >> a >> b) {
    int i;
    for(i=0; i<7; i++) {
      if(a<A[i] && b<B[i]) { break; }
    }
    cout << C[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 1228
S, T = "red", "blue"
A, B = 3, 4
U = "red"

S, T = map(str, input().split())
A, B = map(int, input().split())
U = input()


def calculate(s, t, a, b, u):
    if u == s:
        print("{} {}".format((a - 1), b))
    else:
        print("{} {}".format(a, (b - 1)))


calculate(S, T, A, B, U)


Measured memory_bytes: 8952