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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin >> n >> m;
    int d=1;
    int ans=1;

    if(n==1){
        cout << m << "\n";
        return 0;
    }

    while(d<=m){
        if(m%d==0){
            if(m/d>=n) ans=d;
            else break;
        }
        if(m<n*d) break;
        d++;
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>
#include <random>
#include <map>
#include <iomanip>
#include <sstream>

//AtCoderC++.cpp

using namespace std;


#define rep(i,from,to) for(int i=from;i<to;i++)
#define ints(name,n) vector<int> name;name.resize(n)

template<typename T> void Show(const vector<vector<T>>& v, string delimiter = " ") {
	for (int i = 0; i < v.size(); i++) {
		for (int j = 0; j < v[i].size(); j++) {
			cout << v[i][j];
			if (j != v[i].size() - 1) {
				cout << delimiter;
			} else {
				cout << endl;
			}
		}
	}
}
template<typename T> void Show(const vector<T>& v, string delimiter = " ") {
	for (int i = 0; i < v.size(); i++) {
		cout << v[i];
		if (i != v.size() - 1) {
			cout << delimiter;
		} else {
			cout << endl;
		}
	}
}
template<typename T> vector<T> getUniform(T value, int n) {
	vector<vector<T>> ts;
	ts.resize(n);
	for (int i = 0; i < n; i++) {
		ts[i] = value;
	}
	return ts;
}
template<typename T> vector<vector<T>> getUniform(T value, int row, int col) {
	vector<vector<T>> ts;
	ts.resize(row);
	for (int i = 0; i < row; i++) {
		ts[i].resize(col);
		for (int j = 0; j < col; j++) {
			ts[i][j] = value;
		}
	}
	return ts;
}
bool All(vector<vector<bool>> ts) {
	int h = ts.size();
	int w = ts[0].size();
	rep(i, 0, h) {
		rep(j, 0, w) {
			if (!ts[i][j])return false;
		}
	}
	return true;
}

int main() {
	int n, k;
	cin >> n >> k;
	char c;
	for (size_t i = 0; i < n; i++) {
		cin >> c;
		if (i == k - 1)c = tolower(c);
		cout << c;
	}
}


Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int[] factors(int n) {
    assert(n > 1);

    int[] ps;
    while (n % 2 == 0) {
        ps ~= 2;
        n /= 2;
    }

    for (int i = 3; i * i <= n; i += 2) {
        while (n % i == 0) {
            ps ~= i;
            n /= i;
        }
    }

    if (n > 1) ps ~= n;
    return ps;
}

long calc(int n) {
    const mod = cast(int)1e9 + 7;

    long[int] d;
    for (int i = 2; i <= n; i++) {
        foreach (x; factors(i)) {
            d[x]++;
        }
    }

    long ans = 1;
    foreach (k, v; d) {
        ans = (ans * (v + 1)) % mod;
    }
    return ans;
}

void main() {
    int n = readint;
    writeln(calc(n));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{
    IOS;
    int n,c=0;
    cin>>n;
    int a[n];
    for(int i=1;i<=n;i++)
    {   
        cin>>a[i];
        if(i%2!=0 && a[i]%2!=0){c++;}
    }
    cout<<c;
   return 0;
 }



Measured memory_bytes: 3568
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;

int main(int argc, const char * argv[]) {
  int n;
  cin >> n;
  vector<ll> a(n, 0);
  vector<int> a_vec(n, 0);
  rep(i, n){
    int tmp;
    cin >> tmp;
    tmp--;
    a_vec[i] = tmp;
    a[tmp]++;
  }
  long long ans = 0;
  rep(i, n){
    if(a[i] > 1){
      ans += a[i] * (a[i] - 1) / 2;
    } 
  }

  rep(i, n){
    // cout << a[a_vec[i]] << endl;
    // cout << "test" << endl;
    if(a[a_vec[i]] > 1){
      cout << ans - (a[a_vec[i]] - 1) << endl;
    }else{
      cout << ans << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 4992
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;


void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,a;
    cin >> n >>a;
    cout << n*n - a;

    return 0;
}

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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define LINF 1e18
#define Puts(b) cout<<(b? "Yes":"No")<<endl
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef long long i64;

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

  string s, t;
  cin >> s >> t;

  bool ok = true;
  map<char, char> mps, mpt;
  rep(i, 0, s.size()) {
    char S = s[i], T = t[i];
    if(mps.count(S) && mps[S] != T) ok = false;
    if(mpt.count(T) && mpt[T] != S) ok = false;
    mps[S] = T;
    mpt[T] = S;
  }
  Puts(ok);
}


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

int main() {
	long long int N, M,ans=0;
	cin >> N >> M;
	vector<pair<long long int, long long int>>v(N);
	for (auto& i : v)cin >> i.first >> i.second;
	sort(v.begin(), v.end());
	for (int i = 0; i < N; i++) {
		while (M != 0 && v[i].second != 0) {
			M--;
			v[i].second--;
			ans += v[i].first;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(){
  int x,i,flag;
  scanf("%d", &x);
  i=x;
  for(i;i<x*2;i++){
    flag=0;
    for(int j=2;j<i;++j){
      if(i%j==0){
        flag=1;
      }
    }
    if(flag==0){
      printf("%d\n", i);
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>

int main(int argc, char **argv){

    int N, A;

    std::cin >> N;
    std::cin >> A;

    int rest = N % 500;

    if(rest <= A){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }

    
}


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

#define MAXN 4001

typedef unsigned long long ll;
typedef ll Hash;

const ll primes[] = {(ll) 1e18+7, 1000*1000*1000 + 9};
ll power[2][26];

ll mpow(ll a, int n, ll mod) {
	if(n == 0) return 1;
	ll x = mpow(a, n/2, mod);
	x *= x; x %= mod;
	if(n % 2 == 1) x *= a;
	return x % mod;
}

void inc(Hash& h, int pos) {
	h += power[0][pos];
	if(h >= primes[0]) h -= primes[0];
	//$ h.first %= primes[0];
	//$ h.second += power[1][pos];
	//$ if(h.second >= primes[1]) h.second -= primes[1];
	//$ h.second %= primes[1];
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	for(int i = 0; i < 2; i++)
		for(int j = 0; j < 26; j++) 
			power[i][j] = mpow(MAXN, j, primes[i]);
	
	string s, t;
	cin >> s >> t;
	int n = s.length(), m = t.length();
	if(n > m) swap(s, t), swap(n, m);
	unordered_map<Hash, int> sub;
	
	for(int L = 0; L < n; L++) {
		Hash h = 0;
		for(int R = L; R < min(L + 100, n); R++) {
			inc(h, s[R] - 'a');
			sub[h] = R - L + 1;
		}
	}
	
	int ans = 0;
	for(int L = 0; L < m; L++) {
		Hash h = 0;
		for(int R = L; R < min(L + 100, m); R++) {
			inc(h, t[R] - 'a');
			if(sub.count(h)) {
				ans = max(ans,  R - L + 1);
			}
		}
	}
	
	cout << ans << endl;
}



Measured memory_bytes: 18500
// =====================================================================================
// 
//       Filename:  D.cpp
//        Created:  2017년 06월 10일 21시 08분 24초
//       Compiler:  g++ -O2 -std=c++14
//         Author:  baactree ,  bsj0206@naver.com
//        Company:  Chonnam National University
// 
// =====================================================================================

#include <bits/stdc++.h>
using namespace std;
int n;
string s;
string le, ri;
int main(){
	cin>>n>>s;
	le=ri="";
	int cnt=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='(')
			cnt++;
		else{
			if(cnt>0){
				cnt--;
			}
			else
				le+="(";
		}
	}
	for(int i=0;i<cnt;i++)
		ri+=")";
	cout<<le+s+ri<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define ms_valtype int

#pragma GCC optimize("O3")
#pragma GCC target("avx")

//比較関数
int compare_ms(ms_valtype a, ms_valtype b){
	return a - b;
}

//昇順
void sort_sub(ms_valtype *origin, int left, int right, ms_valtype *tmp){
	if(right - left > 1){
		int i, j, k, half = (left + right) / 2;
		sort_sub(origin, left, half, tmp);
		sort_sub(origin, half, right, tmp);
		for(i = left; i < right; i++){
			tmp[i] = origin[i];
		}
		for(i = left, j = left, k = half; i < right; i++){
			if(k == right){
				origin[i] = tmp[j];
				j++;
			}
			else if(compare_ms(tmp[j], tmp[k]) <= 0 && j < half){
				origin[i] = tmp[j];
				j++;
			}
			else{
				origin[i] = tmp[k];
				k++;
			}
		}
	}
}

void sort(ms_valtype *origin, int N){
	ms_valtype *tmp = (ms_valtype *)malloc(sizeof(ms_valtype) * N);
	sort_sub(origin, 0, N, tmp);
	free(tmp);
}

int bound(int k, int N, int *b){
	int l = -1, h, r = N;
	while(r - l > 1){
		h = (l + r) / 2;
		if(b[h] < k){
			l = h;
		}
		else{
			r = h;
		}
	}
	return r;
}

int main(){
	int N, i, j, ans = 0, xor, dig, cov;
	scanf("%d", &N);
	int *a = (int *)malloc(sizeof(int) * N);
	int *b = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%d", &a[i]);
	}
	for(i = 0; i < N; i++){
		scanf("%d", &b[i]);
	}
	for(i = 28; i >= 0; i--){
		dig = 1 << i, cov = (dig << 1) - 1;
		xor = N & 1;
//		printf("i = %d\n", i);
		for(j = 0; j < N; j++){
			a[j] &= cov;
			b[j] &= cov;
		}
		sort(b, N);
/*		for(j = 0; j < N; j++){
			printf("b[%d] = %d\n", j, b[j]);
		}
*/		for(j = 0; j < N; j++){
			xor ^= bound(1 * dig - a[j], N, b) & 1;
			xor ^= bound(2 * dig - a[j], N, b) & 1;
			xor ^= bound(3 * dig - a[j], N, b) & 1;
		}
//		printf("xor = %d\n", xor);
		ans |= (xor << i);
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2560
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        long mod = (long)Math.pow(10,9)+7;
        FastScanner sc = new FastScanner(System.in);
        long n = sc.nextLong();
        long k = sc.nextLong();
        long ans = 0;
        if(k == 0){
            for(long i = k+1; i <= n; i++){
                long tmp = n/i*(i-k);
                if(n % i >= k){
                    tmp += (n%i)-k;
                }
                //System.out.println(tmp);
                ans += tmp;
            }
            System.out.println(ans);
        }else{
            for(long i = k+1; i <= n; i++){
                long tmp = n/i*(i-k);
                if(n % i >= k){
                    tmp += (n%i)-k+1;
                }
                //System.out.println(tmp);
                ans += tmp;
            }
            System.out.println(ans);
        }
    }
}


class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


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

using namespace std ;

#define sz(v) (int)v.size()
#define ll long long
#define all(v)  v.begin() , v.end()
#define rall(v)  v.rbegin() , v.rend()
#define pf push_front
#define pb push_back
#define fast FastInputOutput() ;
#define Clear( container , value ) memset( container , value , sizeof container )
#define PI acos( -1.0 )
#define forn( t , v , be , n ) for( t v = be ; v < n ; v++ )
#define fore( x , j ) for( auto x : j )
#define se second
#define fr first
//#define c_b fflush(stdin);

const ll Long_max = numeric_limits < ll > :: max() ;
const int Int_max = numeric_limits < int > :: max() ;

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

void File_input( string pathIn ) {
    freopen( pathIn.c_str(), "r", stdin ) ;
}

void File_output( string pathOut ) {
    freopen( pathOut.c_str(), "w", stdout ) ;
}

int msg() {
    srand( time( 0 ) ) ;
    vector < string > st = {
        "Wish everyone high ratings!",
        "Good luck!",
        "Have fun!",
        "Please, read all the problems!",
        "Go Go fight!"
    } ;
    cerr << st[ rand() % sz( st ) ] ;
    return 0 ;
}

void FastInputOutput() {
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}

int main() {

   int x , a ;
   cin >> x >> a ;
   cout << ( ( x < a ) ? 0 : 10 ) ;

   return 0 ;
}



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

int main(){
  string s; cin >> s;
  int n = (int)s.size();
  int cnt = 0;
  for(int i = 0; i < n; i++) cnt += (s[i] == 'o');
  cout << 700 + cnt * 100 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
#define _rep(n, a, b) for (ll n = (a); n <= (b); ++n)
#define _rev(n, a, b) for (ll n = (a); n >= (b); --n)
#define _for(n, a, b) for (ll n = (a); n < (b); ++n)
#define _rof(n, a, b) for (ll n = (a); n > (b); --n)
#define oo 0x3f3f3f3f3f3fll
#define ll long long
#define db double
#define eps 1e-8
#define bin(x) cout << bitset<10>(x) << endl;
#define what_is(x) cerr << #x << " is " << x << endl
#define met(a, b) memset(a, b, sizeof(a))
#define all(x) x.begin(), x.end()
#define pii pair<ll, ll>
#define pdd pair<db, db>
#define pi acos(-1.0)
#define lowbit(x) x &(-x)
const ll maxn = 1e5 + 10;
const ll mod = 1e9;

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	string f, b;
	int q;
	bool right = 1;
	cin >> q;
	_rep(i, 1, q){
		int op;
		cin >> op;
		if(op == 1){
			right = !right;
		}else {
			int o;
			cin >> o;
			if(!right) o = 3-o;
			char c;
			cin >> c;
			if(o == 1){
				f = c + f;
			}else b = b + c;
		}
	}
	s = f + s + b;
	if(!right){
		reverse(all(s));
	}
	cout << s << endl;
}


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

const int MAXN = 1e6+5;

ll s[505];
ll a[505][505], t = 1000000000000000, n;
map<ll, ll> m;

ll gcd(ll a, ll b) {
	if (b == 0)
		return a;
	return gcd(b, a%b);
}

bool isp(int x) {
	for (int i = 2; i < x; ++i)
		if (x%i == 0)
			return 0;
	return 1;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	int ct = 0;
	for (int i = 500; i <= 5000; ++i) {
		if (isp(i)) {
			s[ct] = i;
			ct++;
		}
		if (ct == 250)
			break;
	}

	for (int i = 0; i < 500; ++i)
		for (int k = i%2; k < 500; k += 2) {
			a[i][k] = (i+1)*s[k/2];
		}

	for (int i = 0; i < 500; ++i)
		for (int j = 0; j < 500; ++j) {
			if (a[i][j] > 0)
				continue;
			ll x = 1, g;
			if (i != 0) {
				g = gcd(x, a[i-1][j]);
				x = x/g*a[i-1][j];
			} if (i != 499) {
				g = gcd(x, a[i+1][j]);
				x = x/g*a[i+1][j];
			} if (j != 0) {
				g = gcd(x, a[i][j-1]);
				x = x/g*a[i][j-1];
			} if (j != 499) {
				g = gcd(x, a[i][j+1]);
				x = x/g*a[i][j+1];
			}
			// assert(x <= 1LL*10*10*10*1000000*1000000);
			ll y = t/x;
			ll h = y*x+1;
			while (m[h] == 1)
				h -= x;
			m[h] = 1;
			a[i][j] = h;
		}

	cin >> n;

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j)
			cout << a[i][j] << ' ';
		cout << endl;
	}

	m.clear();
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j) {
			if (m[a[i][j]] == 1) {
				cout << a[i][j] << endl;
				cout << i << ' ' << j << " BAD" << endl;
				return 0;
			}
			m[a[i][j]] = 1;
		}

	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n-1; ++j) {
			ll e = a[i][j], f = a[i][j+1];
			ll m1 = max(e, f);
			ll m2 = min(e, f);
			if (m1%m2 != 1)
				cout << i << ' ' << j << ' ' << a[i][j] << ' ' << a[i][j+1] << endl;
			assert(m1%m2 == 1);
		}

	for (int i = 0; i < n-1; ++i)
		for (int j = 0; j < n; ++j) {
			ll e = a[i][j], f = a[i+1][j];
			ll m1 = max(e, f);
			ll m2 = min(e, f);
			if (m1%m2 != 1)
				cout << i << ' ' << j << ' ' << a[i][j] << ' ' << a[i+1][j] << endl;
			assert(m1%m2 == 1);
		}
}

Measured memory_bytes: 20608
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iostream>
#define maxn 200009
using namespace std;
int n, K;
long long a[maxn];
map<long long, int>mp;
long long X[maxn * 4];
int tot = 0;
map<long long, int>f;
long long b[maxn * 4];
long long getsum(int x){
	long long sum = 0;
	while(x > 0){
		sum += b[x];
		x -= x & -x;
	}
	return sum;
}

void update(int x){
	while(x < 4 * maxn){
		b[x]++;
		x += x & -x;
	}	
}

int main(){
	cin >> n >> K;
	for(int i = 1; i <= n; i++){
		scanf("%lld", &a[i]);
		a[i] -= K;
	}
	long long ans = 0;
	X[tot++] = 0;
	long long sum = 0;
	for(int i = 1; i <= n; i++){
		sum += a[i];
		X[tot++] = sum;
		X[tot++] = -sum;
	}
	
	sort(X, X + tot);
	tot = unique(X , X + tot) - X;
	
	for(int i = 0; i < tot; i++){
		f[X[i]] = i + 1;
	}
	
	update(f[0]);
	sum  = 0;
	for(int i =1; i <= n; i++){
		sum += a[i];
		ans += getsum(f[sum]);
		update(f[sum]);
	}
	cout << ans << endl;
	return 0;
	
}

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

typedef long long ll;

vector<int> g[2020];
int dist[2020],ans[2020];

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

    int n,x,y;
    cin >> n >> x >> y;
    for(int i=0;i<n-1;i++){
        g[i].push_back(i+1);
        g[i+1].push_back(i);
    }
    g[x-1].push_back(y-1);
    g[y-1].push_back(x-1);
    queue<int> q;
    for(int i=0;i<n;i++){
        memset(dist,-1,sizeof(dist));
        q.push(i);
        dist[i] = 0;
        while(!q.empty()){
            int v = q.front();
            q.pop();
            for(int nv : g[v]){
                if(dist[nv]!=-1) continue;
                dist[nv] = dist[v] + 1;
                ans[dist[nv]]++;
                q.push(nv);
            }
        }
    }
    for(int i=1;i<=n-1;i++) cout << ans[i]/2 << endl;
    return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/
vi mv_i = {1, -1, 0, 0};
vi mv_j = {0, 0, 1, -1};

/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    i32 n; cin >> n;
    vec<PII> p;
    rep(i, n*n) {
        i32 tmp, h, w;
        cin >> tmp;
        --tmp;
        h = tmp/n, w = tmp%n;
        p.emplace_back(h, w);
    }

    vii grid(n, vi(n, 1));
    vii mini_dist(n, vi(n, inf));
    queue<PII> que;
    vii dist(n, vi(n));
    rep(i,n)rep(j,n) dist[i][j] = min<i32>({i, n-i-1, j, n-j-1});

    i32 cnt = 0;

    for(i32 i = 0; i < n*n; ++i) {
        i32 si = p[i].first, sj = p[i].second;
        cnt += dist[si][sj];
        grid[si][sj] = 0;
        que.emplace(si, sj);

        i32 ui, uj, ni, nj;
        i32 minimum = inf;
        while(que.size()) {
            tie(ui,uj) = que.front(); que.pop();
            rep(_,4) {
                ni = ui+mv_i[_], nj = uj+mv_j[_];
                if(!(0<=ni && ni<n && 0<=nj && nj<n)) continue;
                if(dist[ni][nj] > dist[ui][uj] + grid[ui][uj]) {
                    dist[ni][nj] = dist[ui][uj] + grid[ui][uj];
                    que.emplace(ni, nj);
                }
            }
        }
//        debug(cnt);
//        // debug
//        rep(i,n) rep(j,n) cout << grid[i][j] << (j==n-1 ? '\n' : ' ');
//        cout << '\n';
//        rep(i,n) rep(j,n) cout << dist[i][j] << (j==n-1 ? "\n" : "  ");
//        cout << '\n';
    }

    cout << cnt << '\n';
//    debug(debug_cnt);


    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    long long k;
    cin >> n >> m >> k;
    long long asum = 0;
    vector<long long> a;
    vector<long long> b;
    long long book;
    for (int i = 0; i < n; i++) { 
        cin >> book;
        asum += book;
        a.push_back(asum);
    }
    long long bsum = 0;
    for (int i = 0; i < m; i++) {
        cin >> book;
        bsum += book;
        b.push_back(bsum);
    }
    int j = m - 1;
    while (j >= 0 && b[j] > k) {
        j--;
    }
    int sol = j + 1; 
    for (int i = 0; i < n; i++) {
        while (j >= 0 && a[i] + b[j] > k) {
            j--;
        }
        if (i + j + 2 > sol && a[i] <= k){
            sol = i + j + 2;
        }
    }
    cout << sol;
}


Measured memory_bytes: 7900
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main(void){
	char s[200005],t[200005];
	scanf("%s",s);
	scanf("%s",t);
	int i,j,flag=0;
	int len=strlen(s);
	char R[26],Rd[26];
	rep(i,26){
		R[i]=-1;
		Rd[i]=-1;
	}
	for(i=0;i<len;i++){
		flag=0;
		if(R[s[i]-97]>=0){
			if(R[s[i]-97]!=t[i]){
				printf("No\n");
				return 0;
			}
		} 
		if(Rd[t[i]-97]>=0){
			if(Rd[t[i]-97]!=s[i]){
				printf("No\n");
				return 0;
			}
		}
		if(R[s[i]-97]<0) R[s[i]-97]=t[i];
		if(Rd[t[i]-97]<0) Rd[t[i]-97]=s[i];
	}


	printf("Yes\n");
	return 0;
}

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

using namespace std;

int solve(const std::vector<int>& as) {
  int ret = 0;
  for (auto itr = as.begin(); itr != as.end();
       itr = std::upper_bound(itr, as.end(), *itr)) {
    auto const nextItr = std::upper_bound(itr, as.end(), (*itr) + 2);
    ret = std::max(static_cast<int>(nextItr - itr), ret);
  }
  return ret;
}

int main() {
  int n;
  std::cin >> n;
  std::vector<int> as(n);
  for (auto& a : as) {
    std::cin >> a;
  }
  std::sort(as.begin(), as.end());
  std::cout << solve(as) << std::endl;
  return 0;
}

Measured memory_bytes: 640
//D問題を尺取り法で実装する

#include <iostream>
#include <vector>
//#include<bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;

int main(){
  int N,K,ans;
  string S;//1011100001010101など
  cin >> N >> K >> S;
  vector<int> Nums;
  int cnt = 0,number = 1;//numberは着目する符号
  for (int n = 0; n < N; n++){
    if(S[n] ==  '0' + number){
      cnt++;
    }else{
      Nums.push_back(cnt);
      number ^= 1;
      cnt = 1;
    }
  }
  if(cnt != 0)Nums.push_back(cnt);
  if(number == 0)Nums.push_back(0);

  int maxSum = -1,sum = 0;
  int left = 0,right = 0;
  for (int i = 0; i < Nums.size(); i += 2){
    int nextLeft = i;
    int nextRight = min(i + 2 * K + 1,(int)Nums.size());
    while(nextLeft>left){
      sum -= Nums[left];
      left++;
    }
    while(nextRight>right){
      sum += Nums[right];
      right++;
    }
    //cout << sum << endl;
    maxSum = max(sum,maxSum);
  } 

  //for (int i = 0; i < Nums.size();i++)
    //cout << Nums[i] << endl; 
  cout << maxSum << endl;
}

Measured memory_bytes: 1020
#include <iostream>
#include <cmath>
#include<algorithm> 
#include<functional>

using namespace std;

int n;
int a[200010];
long b[200010];

long calc(int b) {
	long ans = 0;
	for (int i = 0; i < n; i++) {
		ans += abs(a[i] - (b + i + 1));
	}
	return ans;
}
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		b[i] = a[i] - (i + 1);
	}

	sort(b, b + n, greater<>());

	int median = b[n / 2];
	long answer[3] = { calc(median + 1) , calc(median), calc(median - 1) };

	cout << min(min(answer[0], answer[1]),answer[2]) << endl;

	return 0;
}

Measured memory_bytes: 2560
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
using namespace __gnu_pbds;
using namespace std;

#define double      	long double
#define int         	long long
#define pb          	push_back
#define pii         	pair<int,int>
#define vi          	vector<int>
#define vii         	vector<pii>
#define mi          	map<int,int>
#define mii         	map<pii,int>
#define all(a)      	(a).begin(),(a).end()
#define sz(x)       	(int)x.size()
#define endl        	"\n"
#define repp(i,a,b) 	for(int i=a;i<b;i++)
#define rep(i,a,b) 		for(int i=a;i<=b;i++)
#define brep(i,a,b)     for(int i=a;i>=b;i--)
#define deb1(x)      	cout << #x << "=" << x << endl
#define deb2(x, y)  	cout << #x << "=" << x << "," << #y << "=" << y << endl
#define deb3(x, y, z)  	cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define trace(v) 		for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;
#define tracearr(a,l,r) for(int iii=l;iii<=r;iii++)cout << a[iii] << " ";cout << endl;
#define PI          	3.1415926535897932384626
#define F 				first
#define S 				second
#define clr(x,y) 		memset(x, y, sizeof(x))
#define IOS         	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
// *s.find_by_order(1) - gives the 2nd samllest element in set
// s.order_of_key(x)   - gives the number of elements in the set which are strictly smaller than x


const int N=1e5 + 5;
const int MOD=1e9 + 7;

int32_t main()
{
	//IOS;
	int T=1;
	//cin >> T;
	// int numOfSetBits = __builtin_popcountll(n);
	std::cout << std::fixed << std::setprecision(12);
	while(T--)
	{
		int n;
		cin >> n;
		vector<int> v(n);
		rep(i,0,n-1)
			cin >> v[i];
		sort(all(v));
		reverse(all(v));
		int ans = 0;
		ans += v[0];
		int i = 1;
		int l = n-1;
		l--;
		while(1)
		{
			if(l<=0)
				break;
			if(l>=2)
			{
				ans += v[i]*2;
				l -= 2;
			}
			else
			{
				ans += v[i];
				l -= 1;
			}
			i++;
			
		}
		cout << ans << endl;
	}
}



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

int main() {
  int n,m,t,c;
  while(cin>>n>>m, n|m) {
    c = 0;
    if(m>n) swap(n,m);

    while(m>0) {
      n %= m;
      swap(n,m);
      c++;
    }
    cout<<n<<" "<<c<<endl;
  }
}

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

int main() {
  int n, a, b;
  
  cin >> n >> a >> b;
   
  int planA = n * a;

  if (planA == b) {
    cout << planA << endl;
  } else if (planA < b) {
    cout << planA << endl;
  } else {
    cout << b << endl;
  }
  
}

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

using namespace std;

#define ll long long

int n;

bool isPrime(int n) {
  for (int i = 2; i <= sqrt(n); i++) {
    if (n%i==0) {
      return false;
    }
  }
  return true;
} 

bool factorable(int n) {
  for (int i = 1; i <= 9; i++) {
    if (n%i == 0) {
      if (n/i <= 9) {
        return true;
      } 
    }
  }
  return false;
}

void solve() {
  cin >> n;
  if (n <= 81) {
    if (n < 9) {
      cout << "Yes\n";
      return;
    }
    if (isPrime(n)) {
      cout << "No\n";
      return;
    }
    if (!factorable(n)) {
      cout << "No\n";
      return;
    }
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}


Measured memory_bytes: 256
import sys

N, Y = map(int, input().split())
max1000 = int(Y/1000)
c1000 = [i for i in range(max1000, -1, -5) if i <= N]
for z in c1000:
    max5000 = int((max1000-z) / 5)
    for y in range(0, max5000+1):
        x = N - y - z
        if x*10000 + y*5000 + z*1000 == Y:
            print(str(x) + ' ' + str(y) + ' ' + str(z))
            sys.exit()
print("-1 -1 -1")

Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
	int i,j,w,h;
	
	while(1){
		scanf("%d %d",&h,&w);
		if(h==0&&w==0) break;
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  int H[N];
  for(int i=0;i<N;i++){
   cin >> H[i];
  }
  int count=0;
  int max=0;
  for(int i=0;i<N-1;i++){
   if(H[i]>=H[i+1]){
    count++; 
   }
   else{
    count=0; 
   }
   if(count>max){
    max=count; 
   }
  }

  cout << max << endl;
  
  return 0;
} 


Measured memory_bytes: 640
#include<bits/stdc++.h>
        #define ll long long
        #define rep(i,a,b) for(i=a;i<b;i++)
        #define pb push_back
        #define all(v) v.begin(),v.end()
        #define F first
        #define S second
        #define vi vector < int >
        #define vii vector < long long int >
        #define CLR(a) memset((a),0,sizeof(a))
        #define mp make_pair
        #define hell 1000000007
        using namespace std;


        void solve()
        {
            ll i,j=0,r=200,p,q,k=0,ans=0,d,y=0,h,flag=0,n,m=0,a=hell,b=hell,id,c,h1,h2,a1,b1;
            cin>>n;
            vector < ll > v(n),as(n);
            rep(i,0,n) cin>>v[i],as[i]=v[i];
            sort(all(v));
            if(v[0]==v[n-1])
            {
                rep(i,0,n)
                   {
                       cout<<v[0]<<endl;
                   }
                   return;
            }
            rep(i,0,n)
             {
                 if(as[i]!=v[n-1]) cout<<v[n-1]<<endl;
                 else if(as[i]==v[n-1]) cout<<v[n-2]<<endl;
                 else cout<<v[n-1]<<endl;
             }





        }


        signed main()
        {
            ios::sync_with_stdio(false);
            cin.tie(0);
            cout.tie(0);
            int t=1;
            //cin>>t;
            while(t--)
            solve();
        }

           /*

      void bfs( int i , int j)
           {
               vis[i][j]= true;
             queue < int > que;
             que.push(k);
             while(!que.empty())
             {
                int x= que.front();
                que.pop();
                 for ( int i=1;i<=n;i++)
                 {
                     if((!g[1][n] and g[x][i] ) or (g[1][n] and ! g[x][i]))
                     {
                       if(!vis[i])
                       {
                           que.push(i);
                           level[i]=level[x]+1;
                           vis[i]= true;
                       }
                     }
                 }
             }
           }

          ll int por(ll int a,ll int b)
             {
                ll int k=1;
                while(b>0)
                {
                    if(b%2) k=k*a,k%=hell;
                    b/=2;
                    a*=a; a%=hell;
                }
                return k;
             } */


Measured memory_bytes: 4736
import itertools

N=int(input())
P=list(map(int,input().split()))
Q=list(map(int,input().split()))
R=[]

for i in range(N):
    num = i+1
    R.append(num)

L=list(itertools.permutations(R))
S=[]
for i in range(len(L)):
    S.append(0)
    for j in range(N):
        S[i]+=L[i][j]*(10**(N-1-j))

S.sort()

p=0
q=0
for i in range(N):
        p+=P[i]*(10**(N-1-i))
        q+=Q[i]*(10**(N-1-i))
tmp1=0
tmp2=0
for i in range(len(S)):
    if S[i]==p:
        tmp1=i
    
    if S[i]==q:
        tmp2=i

print(abs(tmp1-tmp2))



Measured memory_bytes: 9664
use std::io::{stdin, Read};
use std::str::FromStr;

// https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn main() {
    let n = read::<usize>();
    let mut k = read::<usize>();
    let mut neg = vec![];
    let mut pos = vec![0];

    for _ in 0..n {
        let x = read::<i32>();
        if x < 0 {
            neg.push(x)
        } else if x > 0 {
            pos.push(x)
        } else {
            k -= 1
        }
    }
    neg.push(0);
    let n_len = neg.len();

    let mut ans = i32::max_value();
    use std::cmp::min;
    let end = min(pos.len(), k + 1);
    for i in 0..end {
        if n_len > (k - i) {
            let right = pos[i];
            let left = neg[n_len - (k - i) - 1].abs();
            ans = min(ans, min(left * 2 + right, right * 2 + left))
        }
    }
    println!("{}", ans)
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main()
{
   vector<int>vv[100];
   int n,m;
   cin>>n>>m;
   int i,j,k,l,x,y;
  for(i=0;i<m;i++)
  {
      cin>>x>>y;
      vv[x].push_back(y);
      vv[y].push_back(x);
  }
  for(i=1;i<=n;i++)
  {
      cout<<vv[i].size()<<endl;
  }
 return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;
const ll MOD = 1000000007;

char S[200000];
int t[200000];

int main(){
    int N;
    cin >> N;
    t[0] = 1;
    for(int i = 0; i < 2*N; i++){
        cin >> S[i];
        if(i >= 1){
            if(S[i] == S[i-1]) t[i] = -t[i-1];
            else t[i] = t[i-1];
        }
    }
    if(S[0] == 'W' || S[2*N-1] == 'W') {
        cout << 0 << endl;
        return 0;
    }
    ll cnt = 0;
    ll ans = 1;
    for(ll i = 1; i <= N; i++){
        ans *= i;
        ans %= MOD;
    }
    for(int i = 0; i < 2*N; i++){
        if(t[i] == -1){
            ans *= cnt;
            ans %= MOD;
        }
        cnt += t[i];
    }
    if(cnt != 0){
        cout << 0 << endl;
    }else{
        cout << ans << endl;
    }
}

Measured memory_bytes: 1280
#include <iostream>
#include<bits/stdc++.h>
#define rep(k,i,n) for(int i=k;i<n;++i)
using namespace std;
int main(void){
    // Your code here!
    long long N;
    cin>>N;
    long long x;
    rep(1,i,sqrt(N)+1){
        if(N%i==0)x=i;
    }
    cout<<x+N/x-2<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int N,x;
  cin >> N >> x;

  vector<long>candy(N,0);
  for(int i=0;i<N;i++){
    cin >> candy[i];
  }

  long ans = 0;
  if(candy[0] > x){
    ans += candy[0] - x;
    candy[0] = x;
  }

  for(int i=0;i<N - 1;i++){
    if(candy[i] + candy[i + 1] > x){
      ans += candy[i] + candy[i + 1] - x;
      candy[i + 1] = x - candy[i];
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <string>
#include <map>

using namespace std;

int a[300005];

int main()
{
    int N, x;

    cin >> N >> x;

    if(x == 1 || x == 2*N - 1)
    {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    for (int i = 0; i < 2 * N - 1;i++)
    {
        a[i] = i + 1;
    }

    swap(a[x - 1], a[N - 1]);
    swap(a[0], a[N - 2]);
    swap(a[2 * N - 2], a[N]);

    for (int i = 0; i < 2 * N - 1; i++)
    {
        cout << a[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 2304
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;


void dump(int* a,int N)
{
    cout << a[0];
    for( int i=1; i<N; i++ ){
        cout << " " << a[i];
    }
    cout << endl;
}

int sort(int* a,int N)
{
    dump(a, N);
    for( int i=1; i<N; i++ ){
        int k = a[i];
        int j;
        for( j=i-1;j>=0 && a[j] > k ;j--){
            a[j+1] = a[j];
        }
        a[j+1] = k;
        dump(a, N);
    }
}

int main()
{
    int N;
    int a[100];
    scanf("%d", &N);
    for (int i = 0; i < N; ++i) {
        scanf("%d", &a[i]);
    }

    sort(a,N);
    return 0;
}

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

using namespace std;

int main() {

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

	int counter = 0;
	for (int i = a; i <= b; i++) {
		if (c%i == 0) { counter++; }
	}

	cout << counter << endl;

}


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

int N;
int flag[101];

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

  cin >> N;
  for (int i = 0; i < N; i++) {
    int d;
    cin >> d;
    flag[d] = 1;
  }
  int sum = 0;
  for (int i = 0; i < 101; i++) {
    sum += flag[i];
  }
  cout << sum << endl;
  return 0;
}

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

class Era{
    public:
    vector<int>prime;
    vector<int>imos;
    Era(int num = 0){
        if(num < 2)return;
        prime = vector<int>(num + 1, 1);
        prime[0] = 0;
        prime[1] = 0;
        for(int i = 2; i * i <= num; i++){
            if(prime[i] == 0)continue;
            for(int j = i + i; j <= num; j += i){
                prime[j] = 0;
            }
        }
        imos = vector<int>(num + 1, 0);
        for(int i = 1; i <= num; i++){
            imos[i] = imos[i - 1] + prime[i];
        }
    }
};

int main(){

    Era era(1000000);
    for(int x; cin >> x;)cout << era.imos[x] << endl;
    
    return 0;
}



Measured memory_bytes: 10532
#include<iostream>
#include<cstring>
char a[10086];
bool c, f;
using namespace std;
int main() {
    cin>>a;
    for(int i=0; i<strlen(a); i++) {
        if(a[i]=='C') c=true;
        if(a[i]=='F'&&c==true) f=true;
    }
    if(f==true) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

#define ll long long

using namespace std;

const int MAXN = 100010;
const int MAXM = 100010;
const int MAXINT = 2147483647;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;

string s;

int main() {   
	cin >> s;
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == '?' ) cout << 'D';
		else cout << s[i]; 
	}
	puts("");
    return 0;
}

Measured memory_bytes: 3760
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;
import java.util.Stack;
public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        while(true){
            String S = sc.nextLine();
            if(S.equals(".")) break;
            Deque<String> kakko = new ArrayDeque<>();
            int f = 1;
            for(int i = 0; i < S.length(); i++){
                char x = S.charAt(i);
                if(x == '(') kakko.push("(");
                if(x == '[') kakko.push("[");
                if(x == ')'){
                    if(kakko.isEmpty()||kakko.pop() != "("){
                        f = 0;
                        break;
                    }
                }
                if(x == ']'){
                    if(kakko.isEmpty()||kakko.pop() != "["){
                        f = 0;
                        break;
                    }
                }
            }
            if(f == 1&&kakko.isEmpty()) System.out.println("yes");
            else System.out.println("no");
            
        }
        sc.close();
        
    }
}



Measured memory_bytes: 45624
#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 <iomanip>       // fixed, setprecision
using namespace std;

int main()
{
  long long N, a;
  cin >> N;
  set<long long> e;
  for (int i = 0; i < N; i++)
  {
    cin >> a;
    if (e.find(a) != e.end())
    {
      cout << "NO" << endl;
      return 0;
    }
    else
    {
      e.insert(a);
    }
  }
  cout << "YES" << endl;
}


Measured memory_bytes: 12252
#include<bits/stdc++.h>
#include<sstream>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define loop(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revloop(i,a,b) for(i=(int)a;i>=(int)b;i--)
#define stloop(it,v) for(it=v.begin();it!=v.end();++it)
#define ii pair<int,int>
#define MP make_pair
#define pb push_back
#define ll long long int
#define PI acos(-1.0)
#define f first
#define se second
#define rs resize
ll n,k,c;
vector<ll> a;
bool can(ll no)
{
    ll i=0,j,Lm;
    while(no>0 && i<n)
    {
      Lm=a[i]+k;
      for(j=i+1;j<i+c && j<n;j++)
      { if(a[j]>Lm)
         break;
      }
      i=j;
      no--;
    }
    if(no>0 && i>n)
      return true;
    if(no<=0 && i<n)
      return false;
    return true;
}
int main()
{  std::ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   ll lo,hg,mid,i,ans;
   cin>>n>>c>>k;
   a.rs(n);
   loop(i,0,n)
    cin>>a[i];
   sort(all(a));
   lo=1;
   hg=n;
   while(lo<=hg)
   {
     mid=(lo+hg)/2;
     if(can(mid))
     { ans=mid;
       hg=mid-1;
     }
     else
       lo=mid+1;
   }
   cout<<ans;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h> 
using namespace std;
int main() {
  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  if(a==0){
    cout<<1<<endl;
  }
  else if(b==0){
    cout<<2<<endl;
  }
  else if(c==0){
    cout<<3<<endl;
  }
  else if(d==0){
    cout<<4<<endl;
  }
  else if(e==0){
    cout<<5<<endl;
  }
}

Measured memory_bytes: 3596
<?php
fscanf(STDIN, "%d %d", $n, $m);
$ok=0;$ng=0;$list=[];
for($i=0;$i<$m;++$i){
  fscanf(STDIN, "%d %s", $p, $s);
  if (isset($list[$p]) && $list[$p] == -1) continue;
  if ($s == 'AC') {
    $ok++;
    if (isset($list[$p])) $ng += $list[$p];
    $list[$p] = -1;
  } else {
    if (!isset($list[$p])) $list[$p] = 0;
    $list[$p]++;
  }
}
echo $ok." ".$ng;

Measured memory_bytes: 18036
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
vector<int>vec[100010];
int a[100010];
int n;
int len;
int x,y;
int size[100010];
int siz[100010];
int xx[100010];
bool flag=1;
void output(bool b){
	if(b)cout<<"Fennec";
	else cout<<"Snuke";
	exit(0);
}
void work(){
//	cout<<"hello\n";
	int pos=len-1;
	int lps=0;
	while(pos>=0){
		siz[xx[pos]]=size[xx[pos]]-lps;
		lps=size[xx[pos]];
		pos--;
	}
	ll sum1=siz[1],sum2=siz[n];
	if(len==2){
		output(sum1>sum2);
	}
	int pos1=0,pos2=len-1;
	int cnt=0;
	while(pos1+1<pos2){
//		cout<<sum1<<' '<<sum2<<' '<<cnt<<'\n';
		cnt++;
		if(cnt&1){
			pos1++;
			sum1+=siz[xx[pos1]];
		}
		else {
			pos2--;
			sum2+=siz[xx[pos2]];
		}
	}
//	cout<<sum1<<' '<<sum2<<' '<<cnt<<'\n';
	if(sum1==sum2){
		if(cnt&1)cout<<"Fennec";
		else cout<<"Snuke";
		exit(0);
	}
	output(sum1>sum2);
}
void dfs(int idx,int par,int step){
//	cout<<idx<<'\n';
	size[idx]=1;
	a[step]=idx;
	if(idx==n&&flag){
		for(int i=0;i<step+1;i++){
			xx[i]=a[i];
		}
		flag=0;
		len=step+1;
	}
	for(int i=0;i<vec[idx].size();i++){
		if(vec[idx][i]!=par)dfs(vec[idx][i],idx,step+1),size[idx]+=size[vec[idx][i]];
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n;
	for(int i=1;i<n;i++){
		cin>>x>>y;
		vec[x].pb(y);
		vec[y].pb(x);
	}
//	for(int i=1;i<=n;i++)cout<<i<<':'<<vec[i].size()<<'\n';
	dfs(1,-1,0);
	work();
	return 0;
}

Measured memory_bytes: 13184
// Problem : C - Sum of product of pairs
// Contest : AtCoder - AtCoder Beginner Contest 177
// URL : https://atcoder.jp/contests/abc177/tasks/abc177_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*ヽ｀、ヽ｀｀、ヽ｀ヽ｀、、ヽ ｀ヽ 、ヽ｀🌙｀ヽヽ｀ヽ、ヽ｀
ヽ｀、ヽ｀｀、ヽ 、｀｀、 ｀、ヽ｀ 、｀ ヽ｀ヽ、ヽ ｀、ヽ｀｀、
ヽ、｀｀、｀、ヽ｀｀、 、ヽヽ｀、｀、、ヽヽ、｀｀、 、 ヽ｀、
ヽ｀｀、 ヽ｀ヽ｀、、ヽ ｀ヽ 、 🚶ヽ｀｀｀｀ヽヽヽ｀、、ヽ｀、、ヽ*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long   ll;
typedef long double ld;
typedef complex< ld > cd;
 
typedef pair<int, int> pi;
typedef pair<ll, ll>   pl;
typedef pair<ld, ld>   pd;
 
typedef vector< int > vi;
typedef vector< ld >  vd;
typedef vector< ll >  vl;
typedef vector< pi >  vpi;
typedef vector< pl >  vpl;
typedef vector< cd >  vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a)    for (int i=0; i<(a); i++)
#define rep1(i, a, b) for (int i = (b)-1; i >= a; i--)
#define rep(i, a)     for (int i = (a)-1; i >= 0; i--)
#define trav(a, x)    for (auto& a : x)
#define uid(a, b)     uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f  first
#define s  second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	int n;
	cin>>n;
	vl a(n);
	loop(i,n)
		cin>>a[i];
	ll pref[n]={0};
	pref[0]=a[0];
	l00p(i,1,n)
	{
		pref[i]=pref[i-1]+a[i];
	}
	ll ans=0;
	loop(i,n-1)
	{
		ans+=(a[i])*((pref[n-1]-pref[i])%MOD);
		ans%=MOD;
	}
	cout<<ans%MOD;
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 6396