akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        int X = ni();
        int N = ni();
        HashSet<Integer> p = new HashSet<>();
        for (int i = 0; i < N; i++) {
            p.add(ni());
        }
        int ans = 0;
        int mindis = Math.abs(X-0);
        for (int i = 1; i <= 101; i++) {
            if(!p.contains(i)){
                if(Math.abs(i-X) < mindis){
                    mindis = Math.abs(i-X);
                    ans = i;
                }
            }
        }
        out.println(ans);
    }

 
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

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

using usize = ::std::size_t;
using u64 = ::std::int_least64_t;
//using u64 = long long;
static constexpr u64 Inf = ::std::numeric_limits<u64>::max() / 2;

u64 modPow(u64 n, u64 k, u64 mod)
{
    if (k == 0) return 1LL % mod;
    u64 r = modPow(n, k >> 1, mod);
    r = r * r % mod;
    if (k & 1) r = r * n % mod;
    return r;
}


int main(int argc, char *argv[])
{
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    u64 n, k;
    cin >> n >> k;
    
    cout << modPow(n, k, 1000000007) << endl;
    
}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL lucas[90];

int main() {
    lucas[0] = 2LL;
    lucas[1] = 1LL;
    for(int i = 2; i <= 86; ++i) lucas[i] = lucas[i - 1] + lucas[i - 2];
    int n;
    scanf("%d", &n);
    printf("%lld\n", lucas[n]);
    return 0;
}


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

using i64 = int64_t;

constexpr i64 MOD = 1e9 + 7;

i64 extgcd(i64 a, i64 b, i64 &x, i64 &y) {
    i64 d = a;
    if (b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else {
        x = 1;
        y = 0;
    }
    return d;
}

i64 multi_inv(i64 a, i64 md) {
    i64 x, y;
    extgcd(md, a, x, y);
    return (y > 0 ? y : md + y);
}

int main(){
    i64 n, m, k;
    cin >> n >> m >> k;
    i64 comb = 1;
    for(i64 i=0;i<k-2;++i){
        comb *= (n*m-2)-i;
        comb %= MOD;
    }
    i64 denominator = 1;
    for(i64 i=k-2;i>0;--i){
        denominator *= i;
        denominator %= MOD;
    }
    comb *= multi_inv(denominator, MOD);
    comb %= MOD;
    i64 xsum = 0;
    for(i64 d=1;d<n;++d){
        xsum += (d*((n-d)*m % MOD) % MOD)*m % MOD;
        xsum %= MOD;
    }

    i64 ysum = 0;
    for(i64 d=1;d<m;++d){
        ysum += (d*((m-d)*n % MOD) % MOD)*n % MOD;
        ysum %= MOD;
    }

    cout << (xsum + ysum % MOD) * comb % MOD << endl;

    return 0;
}


Measured memory_bytes: 256
/*
If you want to shine like a sun, first burn like a sun.
*/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define vpi vector<ppi>
#define vpl vector<ppl>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf 9000000000000000000
#define minf -inf
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
#define MAXN 100005
#define test1(x) cout << #x " = " << x << endl;
#define test2(x,y) cout << #x " = " << x << " " << #y " = " << y << endl;
const ll infinity = 9e18;

/*
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/


int main()
{
    fast

/*
    #ifndef ONLINE_JUDGE
        freopen("input.txt",  "r",  stdin);
        freopen("output.txt", "w", stdout);
    #endif
//*/

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

	t += s;

	cout<<t;
        
        












    return 0;
}

Measured memory_bytes: 256
n = int(input())
dic = {}
for i in range(n):
    s = input()
    try:
        dic[s] += 1
    except:
        dic[s] = 1
high=max(dic.values())
val= sorted(dic.items())
for i in val:
    if(i[1]==high):
        print(i[0])

Measured memory_bytes: 137288
D, G = map(int, input().split())
pc = [list(map(int,input().split())) for _ in range(D)]

# 最大１０種類、各１００問まで
ans = pow(100,10)

# 各配点でbitが立っているかで全探査
for bit in range(1 << D):
    count = 0
    sum = 0
    nokori = set(range(1, D+1))     #解いてない問題の集合

    for i in range(D):
        # i番目のビットが立っていればその配点の問題をすべて解く
        if bit & (1<<i):
            sum += pc[i][0] * (i+1)*100 + pc[i][1]
            count += pc[i][0]
            nokori.discard(i + 1)

    # 目標点に足りなければnokoriで一番配点が大きいものを解く
    if sum < G:
        use = max(nokori)
        # すべて解くパターンと、残りの点数を配点で割った数より１多く解くのの少ない方
        n = min(pc[use-1][0], -(-(G-sum)//(use*100)))
        count += n
        sum += n*use*100

    if sum >= G:
        ans = min(ans, count)

print(ans)

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

const int MOD = 1000000007;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template<class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template<class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

void py(bool isUpper = false) {
  if (isUpper) {
    p("YES");
  } else {
    p("Yes");
  }
}

void pn(bool isUpper = false) {
  if (isUpper) {
    p("NO");
  } else {
    p("No");
  }
}

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

  int x[n + 1];
  for (int i = 1; i <= n; ++i) {
    x[i] = l + i - 1;
  }

  int sum = 0;
  for (int i = 1; i <= n; ++i) {
    sum += x[i];
  }

  vector<pair<int, int>> v;
  for (int i = 1; i <= n; ++i) {
    int after = sum - x[i];
    v.emplace_back(pair<int, int>(abs(sum - after), after));
  }
  p(min(v).second);
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
const int mod = 1e9 + 7;
const int INF = 1e9;
using namespace std;
typedef long long ll;

int main()
{
    int n,x;
    cin >> n >> x;
    int a[n];
    ll ans = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    if(a[0] > x){
        ans += (a[0] - x);
        a[0] = x;
    }
    for(int i = 0; i < n-1; i++){
        if(a[i] + a[i+1] > x){
            ans += ((a[i] + a[i+1]) - x);
            a[i+1] -= ((a[i] + a[i+1]) - x);
        }
    }
    cout << ans;
}

Measured memory_bytes: 640
#include<stdio.h>
int main()
{

int x, y;
scanf("%d %d", &x, &y);

    if(x==2||y==2){
        printf("No\n");
    }
    else if((x==1||x==3||x==5||x==7||x==8||x==10||x==12)&&(y==1||y==3||y==5||y==7||y==8||y==10||y==12))
    {
        printf("Yes\n");
    }
    else if((x==4||x==6||x==9||x==11)&&(y==4||y==6||y==9||y==11))
    {
        printf("Yes");
    }
    else{
        printf("No");
    }

return 0;

}


Measured memory_bytes: 1676
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,M=MI()
    H=LI()
    edge = [[]for _ in range(N)]
    for _ in range(M):
        a,b = MI_()
        edge[a].append(b)
        edge[b].append(a)
    ans = 0
    for i in range(N):
        ok = True
        for to in edge[i]:
            if(H[i]<=H[to]):
                ok = False
        ans += ok
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 98576
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using pll = pair<long long, long long>;
const long long INF = 1<<29;

const int MOD = 1000000007;
long long ruizyou(long long m,long long n){
  if(m == 0)return 0;
  if(m == 1)return 1;
  long long ans = 1;
  long long tmp = m;
  for(int i=0;i<=30;i++){
    if(n & (1<<i)){
      ans *= tmp;
      ans %= MOD;
    }
    tmp *= tmp;
    tmp %= MOD;
  }
  return ans;
}
long long kaizyou(long long x){
  if(x == 0)return 1;
  return x * kaizyou(x-1) % MOD;
}
long long comb(long long x,long long y){
  long long bunsi = kaizyou(x);
  long long bunbo = kaizyou(x-y) * kaizyou(y) % MOD;
  return bunsi * ruizyou((int)bunbo,MOD-2) % MOD;
}
struct unionfind{
  vector<int> par;
  vector<int> hukasa;
  unionfind(int n){
    par = vector<int>(n);
    hukasa = vector<int>(n,0);
    for(int i=0;i<n;i++){
      par.at(i) = i;
    }
  }
  int root(int x){
    if(par.at(x) == x)return x;
    return root(par.at(x));
  }
  void unite(int x,int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry)return;
    if(hukasa.at(rx) >= hukasa.at(ry)){
      par.at(ry) = rx;
      hukasa.at(rx) = max(hukasa.at(ry) + 1,hukasa.at(rx));
    }
    else{
      par.at(rx) = ry;
    }
  }
  bool same(int x,int y){
    return root(x) == root(y);
  }
};
int ctoi(char a){
  return a - '0';
}
long long gcd(long long a,long long b){
  long long c = max(a,b);
  long long d = min(a,b);
  if(d % c == 0)return c;
  return gcd(c,d%c);
}
long long lcm(long long a,long long b){
  return a * b / gcd(a,b);
}
int main(){
  int n,m;
  cin >> n >> m;
  vector<long long> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
    a.at(i) /= 2;
  }
  long long lcm1 = a.at(0);
  for(int i=1;i<n;i++){
    lcm1 = lcm(lcm1,(int)a.at(i));
  }
  bool unko = false;
  for(int i=0;i<n;i++){
    if((lcm1 / a.at(i)) % 2 == 0){
      unko = true;
      break;
    }
  }
  if(unko || m < lcm1)cout << 0 << endl;
  else cout << (m - lcm1) / (2*lcm1) + 1 << endl;
}

Measured memory_bytes: 4064
#include<stdio.h>
int main()
{
	int a,b,c,max,sum=0;
	scanf("%d%d%d",&a,&b,&c);
	max=a;
	if(max<b)max=b;
	if(max<c)max=c;
	sum+=max-a+max-b+max-c;
	if((max-a+max-b+max-c)%2!=0)sum+=4;
	printf("%d",sum/2);
	return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <stack>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const ll MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

const int N = 3005;

string s;
int n;
double p[N];
double dp[N][N];
bool memo[N][N];

double cal(int i, int j) {
  if(memo[i][j]) return dp[i][j];
  else if(i < j) dp[i][j] = 0;
  else if(i==1) {
    dp[1][0] = 1-p[i]; dp[1][1] = p[i];
  } else if(j==0) dp[i][j] = cal(i-1, j) * (1.0-p[i]);
  else dp[i][j] = cal(i-1, j-1) * p[i] + cal(i-1, j) * (1.0-p[i]);
  memo[i][j] = true;
  return dp[i][j];
}

int main () {
  cin >> n;
  rep(i,n) cin >> p[i+1];
  rep(i,N) rep(j,N) dp[i][j] = 0;
  rep(i,n+1) cal(n, i);
  double result = 0.0;
  for (int i = (n+1)/2; i <= N; i++) {
    result += dp[n][i];
  }
  pd(result);br();
}


Measured memory_bytes: 79744
#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(c) begin(c), end(c)
#define range(i,a,b) for(int i = a; i < (int)(b); i++)
#define rep(i,b) range(i,0,b)
#define pb push_back
#define eb emplace_back

using ld = long double;
const ld EPS = 1e-8;
typedef vector<ld> vec;
typedef vector<vec> mat;

vec GaussJordan(mat A) {
    int n = A.size();
    int m = A[0].size();
    for(int i = 0; i < n; i++){
        int pivot = i;
        for(int j = i; j < n; j++) {
            if(abs(A[j][i]) > abs(A[pivot][i])) pivot = j;
        }
        swap(A[i], A[pivot]);
        if(abs(A[i][i]) < EPS) return {};
        for(int j = i + 1; j < m; j++) A[i][j] /= A[i][i];
        for(int j = 0; j < n; j++) {
            if(i != j) {
                for(int k = i + 1; k < m; k++) A[j][k] -= A[j][i] * A[i][k];
            }
        }
    }
    vec x(n);
    for(int i = 0; i < n; i++) x[i] = A[i].back();
    return x;
}

int d;
vec b;

auto y = [](const vec &f, ld x){
    ld res = 0, cur = 1;
    rep(i,d+1){
        res += cur * f[i];
        cur *= x;
    }
    return res;
};

int solve(){
    mat A(d+3, vec(d+2));
    rep(i,d+3){
        ld cur = 1;
        rep(j,d+1){
            A[i][j] = cur;
            cur *= i;
        }
        A[i][d+1] = b[i];
    }
    vector<int> cnt(d+3);
    rep(i,d+3)rep(j,i){
        mat P;
        vector<pair<int,ld>> test;
        rep(k,d+3){
            if(k == i || k == j){
                test.eb(k,b[k]);
            } else {
                P.pb(A[k]);
            }
        }
        vec c = GaussJordan(P);
        rep(k,2){
            int x = test[k].first;
            ld resy = y(c, x);
            ld expy = test[k].second;
            cnt[x] += abs(expy - resy) > 1e-3;
        }
    }
    return max_element(all(cnt)) - cnt.begin();
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    while(cin >> d && d){
        b.resize(d+3);
        rep(i,d+3) cin >> b[i];
        cout << solve() << endl;
    }
}

Measured memory_bytes: 3212
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws java.lang.Exception
	{
		int[][] card = new int[4][13];
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//???????????????????????°???????????????
		int a = Integer.parseInt(br.readLine());
		
		//??????????????????????????§??????????????\?????????
		for(int i = 0; i < a; i++) {
			String str = br.readLine();
			String [] m = str.split(" ");
			int b = Integer.parseInt(m[1]);
			
			if(m[0].equals("S")) {
				card[0][b - 1] = 1;
			}
			if(m[0].equals("H")) {
				card[1][b - 1] = 1;
			}
			if(m[0].equals("C")) {
				card[2][b - 1] = 1;
			}
			if(m[0].equals("D")) {
				card[3][b - 1] = 1;
			}
			
		}
		
		//?????????????????????????????¨?????????
		for(int i = 0; i < card.length; i++) {
			for(int j = 0; j < card[i].length; j++) {
				if(card[i][j] == 0) {
					if(i == 0) {
						System.out.println("S " + (j+1));
					}
					if(i == 1) {
						System.out.println("H " + (j+1));
					}
					if(i == 2) {
						System.out.println("C " + (j+1));
					}
					if(i == 3) {
						System.out.println("D " + (j+1));
					}
				}
			}
		}
	}

}

Measured memory_bytes: 24500
#include<iostream>
#include<string>
using namespace std;
int main(){
	int K;
	string S;
	cin>>K>>S;
	if(S.size()<=K)cout<<S<<endl;
	else{
		 for(int i=0;i<K;i++)cout<<S[i];
		 cout<<"..."<<endl;
		}
}

Measured memory_bytes: 3136
#include <iostream>
#include <string>
using namespace std;
int main() {
    int N, cnt = 0;
    string S, ans;
    cin >> N >> S;
    ans = S;
    for (int i = 0; i < N; i++) {
        if (S[i] == '(') cnt++;
        if (S[i] == ')') {
            if (cnt == 0) ans = '(' + ans;
            else cnt--;
        }
    }
    for (int i = 0; i < cnt; i++) ans += ')';
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <math.h>

using namespace std;

int main()
{
	int a, b, k, t = 0, v;
	cin >> a >> b >> k;
	if (a < b) {
		v = a;
	}
	else {
		v = b;
	}
	for (;; v--) {
		if (a%v == 0 && b%v == 0) {
			t++;
			if (t == k) {
				cout << v << endl;
				break;
			}
		}
		if (v==1)break;
	}
}

Measured memory_bytes: 256
from math import sqrt

n, d = map(int, input().split())
x = []
cnt = 0
for i in range(n):
    tmp = list(map(int, input().split()))
    x.append(tmp)

for i in range(n-1):
    for j in range(i+1, n):
        dist = sqrt(sum([(x1-x2)**2 for (x1, x2) in zip(x[i], x[j])]))
        if dist.is_integer():
            cnt += 1

print(cnt)

Measured memory_bytes: 3064
/**
*    created: 01.07.2020 13:35:08
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#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++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const int mod = 1000000007;
// const int MOD = 998244353;
const long double pi = acos(-1.0);
const int inf = 1LL << 60;

signed main() {

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

    int n;
    cin >> n;
    vector<int> x(n);
    rep(i,n) cin >> x[i];
    vector<int> xc = x;
    sort(all(xc));
    int l = xc[n/2-1];
    int r = xc[n/2];
    if (l == r) {
        rep(i,n) cout << l << endl;
        return 0;
    }
    rep(i,n) {
        if (x[i] <= l) cout << r << endl;
        else cout << l << endl;
    }
    return 0;
}

Measured memory_bytes: 6380
#include<bits/stdc++.h>
using namespace std;
                    
                    
int main(){
    string n;
    cin >> n;
    n = n[n.size() - 1];
    if(n == "2" | n == "4" | n == "5" | n == "7" | n == "9"){
        cout << "hon" << endl;
    }else if(n == "0" | n == "1" | n == "6" | n == "8"){
        cout << "pon" << endl;
    }else{
        cout << "bon" << endl;
    }

    return 0;
            
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;

#define PI 3.14159265358979323846264338327950L

int res = -1;

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

    int N,M;
    cin >> N >> M;
    vector<int> A(M);
    int sum=0;
    for (int i = 0; i < M; i++)
    {
        cin >> A[i];
        sum += A[i];
    }
    if(sum<=N){
        res = N-sum;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3692
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
char s[100010], a[100010];
int t, flag, cnt;
int main() {
	scanf("%s", s);
	int len = strlen(s);
	for(int i = 0; i < len; i++)if(s[i] != 'x')a[t++] = s[i];
	a[t] = '\0';
	for(int i = 0; i < t / 2; i++) {
		if(a[i] != a[t - i - 1])flag = 1;
	}
	if(flag)printf("-1\n");
	else {
		int r = len - 1;
		for(int i = 0; i <= r; i++) {
			if(s[i] == 'x') {
				if(s[r] != 'x')cnt++;
				else r--;
			}
			else {
				while(s[r] == 'x')cnt++, r--;
				r--;
			}
		}
		printf("%d\n", cnt);
	}
	return 0;
}

Measured memory_bytes: 384
r1,c1,r2,c2=map(int,input().split())
mod=10**9+7
def comb(n,k,mod):
  if n<k:
    return 0
  if n-k<k:
    k=n-k
  c=1
  for x in range(n-k+1,n+1):
    c=(c*x)%mod
  d=1
  for x in range(1,k+1):
    d=(d*x)%mod
  c=c*pow(d,mod-2,mod)
  return c%mod
def f(i,j):
  return comb(i+j,i,mod)
ans=f(r2+1,c2+1)-f(r2+1,c1)-f(r1,c2+1)+f(r1,c1)
ans%=mod
print(ans)


Measured memory_bytes: 8984
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

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

    string s;
    cin >> s;

    vector<char> v{'^'};
    for(auto e : s) {
        if(e != v.back())  v.push_back(e);
    }
    cout << v.size() - 1 << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#define rep(i,n) for(int i=0;i<n;++i)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define mod 1000000007
using namespace std;
using ll = long long;
int main() {
	int N, Y;	cin >> N >> Y;
	int x, y, z, num = Y / 1000 - N;
	rep(i, N + 1) {
		x = i;
		if ((num - 9 * x) % 4 == 0) {
			y = (num - 9 * x) / 4;
			if (y < 0) continue;
			z = N - x - y;
			if (z < 0) continue;
			cout << x << " " << y << " " << z << endl;
			return 0;
		}
	}
	cout << "-1 -1 -1" << endl;
}


Measured memory_bytes: 256
//AtCoder Beginner Contest 086
//A - Product

#include <iostream>

using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    if((a%2)*(b%2)!=0){
        cout << "Odd" << endl;
    }else{
        cout << "Even" << endl;    
    }
    return 0;
}


Measured memory_bytes: 256
def solve(a, b, c):
    yummy = 0
    # 解毒剤入り・おいしいで解毒
    detox = min(b, c)
    yummy = 2 * detox
    b -= detox
    c -= detox
    # 解毒剤入り・おいしいで解毒
    detox = min(a, c)
    yummy += detox
    a -= detox
    c -= detox
    # まだおいしいのがあれば食べる
    yummy += b
    # 毒入りは，一回なら食べられる
    if c > 0:
        yummy += 1
    return yummy


def main():
    a, b, c = (int(z) for z in input().split())
    print(solve(a, b, c))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;
int main() {
	int a=0,b=0,c=0,n=1;
	string A,B,C;
	cin>>A>>B>>C;
	while(a-1!=A.size()&&c-1!=C.size()&&b-1!=B.size())
	{
		if(n==1){
			if(a!=A.size())n=A[a]-'a'+1;
			a++;
		}
		if(n==2){
			if(b!=B.size())n=B[b]-'a'+1;
			b++;
		}
		if(n==3){
			if(c!=C.size())n=C[c]-'a'+1;
			c++;
		}
	}
	if(a-1==A.size())cout<<"A";
	if(b-1==B.size())cout<<"B";
	if(c-1==C.size())cout<<"C";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	int N;
	cin>>N;
	vector<int> a(N);
	vector<bool> f(9);
	int any = 0;
	rep(i,N){
		cin>>a[i];
		if(a[i]>=3200)any++;
		else{
			rep(j,8){
				if(j*400<=a[i]&&a[i]<(j+1)*400){
					f[j] = true;
					break;
				}
			}
		}
	}
	int cnt = 0;
	rep(i,8){
		if(f[i])cnt++;
	}
	int ansmin = max(cnt,1);//1は下回らない
	int ansmax = cnt+any;
	cout<<ansmin<<' '<<ansmax<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  int M,D;
  cin >> M >> D;
  int ans = 0;
  for(int i=1;i<=M;i++){
    for(int j=1;j<=D;j++){
      int p = j / 10;
      int q = j % 10;
      if(p > 1 && q > 1 && p * q == i) ans++;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
x = list(map(int, input().split()))
if n >= m:
    print(0)
    exit()
x.sort()
l = []
for i in range(m - 1):
    l.append(x[i + 1] - x[i])
l.sort()
print(sum(l[: m - n]))

Measured memory_bytes: 13968
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
  int n, m, Q;
  cin >> n >> m >> Q;
  vector<vector<int>> sum(n + 1, vector<int>(n + 1));
  rep(i, m) {
    int l, r;
    cin >> l >> r;
    sum[l][r]++;
  }
  for(int i = 1; i <= n; ++i) {
    for(int j = 1; j <= n; ++j) {
      sum[i][j] += sum[i - 1][j];
      sum[i][j] += sum[i][j - 1];
      sum[i][j] -= sum[i - 1][j - 1];
    }
  }

  rep(i, Q) {
    int p, q;
    cin >> p >> q;
    int ans = sum[q][q] - sum[q][p - 1] - sum[p - 1][q] + sum[p - 1][p - 1];
    cout << ans << endl;
  }

}


Measured memory_bytes: 1920
#!/usr/bin/env pypy3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
#  = int(input())
n, m  = map(int, input().split())
#  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

sc = [tuple(map(int, input().split())) for _ in range(m)]

#print(sc)

start = 0 if n == 1 else 10 ** (n-1)
for i in range(start, 10**(n)):
    ans = str(i)

    for s, c in sc:
        #print(s,c,ans)
        if ans[s-1] != str(c):
            break
    else:
        print(ans)
        break
else:
    print(-1)


Measured memory_bytes: 3316
#include <stdio.h>

int main(){
   int x,p[100],i,n,u,d;

   scanf("%d %d",&x,&n);
   for (i=0;i<n;i++) scanf("%d",&p[i]);
   for (i=0;i<n;i++)
      if (p[i]==x) break;
   if (i==n) {
      printf("%d\n",x);
      return 0;
   }
   d=x-1;u=x+1;
   for (;n>0;) {
      for (i=0;i<n;i++)
         if (p[i]==d) break;
      if (i==n) {
         printf("%d\n",d);
         return 0;
      } else {
         p[i]=p[n-1];
         n--;
      }
      d--;
      for (i=0;i<n;i++)
         if (p[i]==u) break;
      if (i==n) {
         printf("%d\n",u);
         return 0;
      } else {
         p[i]=p[n-1];
         n--;
      }
      u++;
   }
   printf("%d\n",d);
   return 0;
}


Measured memory_bytes: 1724
#include <bits/stdc++.h>
using namespace std;
#define N 100005
int n,c,k,a[N];
int main(){
	cin>>n>>c>>k;
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	int ans=0,nc,nk=-1;
	for(int i=0;i<n;i++){
		if(nk<a[i]||!nc){
			ans++;
			nc=c-1;
			nk=a[i]+k;
		}else
			nc--;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int a[100100];
int cost[100100];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	int def = 0;
	for (int i = 1;i <= n;i++) {
		cin >> a[i];
	}

	for (int j = 0;j <= n;j++) {
		def +=abs(a[j+1]-a[j]);
	}

	for (int k = 1;k <= n;k++) {
		cost[k] = def - abs(a[k] - a[k - 1]) - abs(a[k + 1] - a[k]) + abs(a[k + 1] - a[k - 1]);
		cout << cost[k] << "\n";
	}
	return 0;
}

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

int main() {
  int n;
  scanf("%d", &n);
  unordered_map<string, int> vote;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if (!vote.count(s))
      vote.insert({s, 1});
    else
      vote[s]++;
  }

  vector<pair<int, string>> board;
  for (auto p : vote)
    board.push_back({p.second, p.first});
  sort(board.begin(), board.end());
  for (int i = board.size() - 1; i >= -1; i--)
    if (i < 0 || (i >= 0 && board[i].first < board.back().first)) {
      for (int j = i + 1; j < board.size(); j++)
        cout << board[j].second << endl;
      break;
    }

  return 0;
}

Measured memory_bytes: 29380
// This amazing code is by Eric Sunli Chen.
#include<bits/stdc++.h>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

bool P(int x){for(int i=2;i*i<=x;i++)if(x%i==0)return false;return true;}

int p[1111],p1[1111],p2[1111],tot,n;

LL a[555][555];

int main()
{
	for(int i=2;i<=10000&&tot<1002;i++)if(P(i))p[++tot]=i;
	for(int i=1;i<=501;i++)p1[i*2-1]=p[i];
	for(int i=1;i<=501;i++)p2[i*2-1]=p[i+501];
	for(int i=1;i<=501;i++)for(int j=1;j<=501;j++)
	{
		int k1=i+j-1,k2=i-j+501;
		a[i][j]=1;
		if(k1%2==1)a[i][j]*=p1[k1];else a[i][j]*=p1[k1-1]*p1[k1+1];
		if(k2%2==1)a[i][j]*=p2[k2];else a[i][j]*=p2[k2-1]*p2[k2+1];
		if(k1%2==0)a[i][j]++;
	}
	
	get1(n);
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)printf("%lld%c",a[i][j],j==n?'\n':' ');
	return 0;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}

template <class T, class U>
void chmin(T &a, U b) {
  if (b < a) a = b;
}

template <class T>
T Sq(const T &t) {
  return t * t;
}

signed main() {
  int N = read(), count, max = 0;
  string S = readString();
  int isEqual[26] = {0};
  REP(i, N - 1) {
    count = 0;
    for (int j = 0; j <= i; j++) {
      for (int k = i + 1; k < N; k++) {
        if (S[j] == S[k]) isEqual[S[j] - 'a'] = 1;
      }
    }
    REP(j, 26) {
      if (isEqual[j]) count++;
      isEqual[j] = 0;
    }
    chmax(max, count);
  }
  print(max);
}


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

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

	int residence[4][3][10] = { 0 };
	int b, f, r, v;

	for (int i = 0; i < n; i++) {
		std::cin >> b >> f >> r >> v;
		residence[b - 1][f - 1][r - 1] += v;
	}

	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 10; k++) {
				std::cout <<" "<< residence[i][j][k];
			}
			std::cout << std::endl;
		}
		if (i != 3) {
			std::cout << "####################" << std::endl;
		}
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <stdio.h>

using namespace std;

int main() {
 int n,c;
 while(cin >> n) {
	 if (n==0) break;
	 c=0;
	 while(n!=1) { c++; if ((n % 2)==0) n/=2; else n=n*3+1; }
	 cout << c << endl;
 }
return 0;
 }

Measured memory_bytes: 1160
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9) + 7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main() {
	int a, b; cin >> a >> b;
	if (a > 0) {
		cout << "Positive" << endl;
	}
	else if (a <= 0 && 0 <= b) {
		cout << "Zero" << endl;
	}
	else {
		int d = b - a;
		if (d % 2)cout << "Positive" << endl;
		else cout << "Negative" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
r,g,b,n = map(int, input().split())
count = 0
c0,c1,c2 = sorted([r,g,b])
for i in range(1+n//c2):
    rest1 = n - i*c2
    if rest1 < 0:
        break
    for j in range(1+rest1//c1):
        rest = n - i*c2 - j*c1
        if rest <0:
            break
        elif rest%c0 == 0:
            count += 1
print(count)

Measured memory_bytes: 3064
use proconio::input;

fn check(arr : &Vec<(i32, i32)>) -> i32 {
    let mut res = 0;
    for &a in arr {
        res -= a.1;
        if res < 0 { return -1; }
        res += a.0;
    }
    return res;
}

fn main() {
    input! {
        n : usize,
        s : [String; n]
    };
    let mut up = Vec::new();
    let mut down = Vec::new();
    for c in s {
        let mut p = (0, 0);
        for &v in c.as_bytes() {
            if v == b'(' { p.0 += 1 }
            else {
                if p.0 > 0 { p.0 -= 1 }
                else { p.1 += 1 }
            }
        }
        if p.0 >= p.1 {
            up.push(p)
        } else {
            down.push((p.1, p.0))
        }
    }
    up.sort_by_key(|x| x.1);
    down.sort_by_key(|x| x.1);
    let a = check(&up);
    let b = check(&down);
    println!("{}", if a >= 0 && b >= 0 && a == b { "Yes" } else { "No" });
}


Measured memory_bytes: 58484
# E
from collections import deque

n, m = map(int, input().split())
G = dict()
for i in range(1, n+1):
    G[i] = dict()
    
for _ in range(m):
    u, v, s = map(int, input().split())
    G[u][v] = s
    G[v][u] = s

case = 1

done_flg = [0]*(n+1)
res_list = [0]*(n+1)
plmi_flg = [0]*(n+1)

queue = deque([1])
done_flg[1] = 1
plmi_flg[1] = 1

dif_list = []

while len(queue) > 0:
    u = queue.popleft()
    for v in G[u].keys():
        if done_flg[v] == 0:
            done_flg[v] = 1
            res_list[v] = G[u][v] - res_list[u]
            plmi_flg[v] = -plmi_flg[u]
            queue.append(v)
        elif plmi_flg[v] == -plmi_flg[u]:
            if res_list[v] != G[u][v] - res_list[u]:
                case = 9
                break
        else:
            d = G[u][v] - res_list[u] - res_list[v]
            if d % 2 == 1:
                case = 9
                break
            else:
                dif_list.append((d // 2)*plmi_flg[u])
                case = 2
    if case == 9:
        break
            
            
# simple case
if case == 9:
    print(0)
elif case == 2:
    d = dif_list[0]
    check1 = True
    for d_ in dif_list:
        if d_ != d:
            check1 = False
    if check1 == False:
        print(0)
    else:
        for i in range(n+1):
            if plmi_flg[i]==1:
                res_list[i] += d
            elif plmi_flg[i]==-1:
                res_list[i] -= d
        if min(res_list[1:]) > 0:
            print(1)
        else:
            print(0)
elif case == 1:
    res_min_1 = min([res_list[i] for i in range(1, n+1) if plmi_flg[i]==1])
    res_min_2 = min([res_list[i] for i in range(1, n+1) if plmi_flg[i]==-1])
    r = max(0, (res_min_2 - 1) - (-res_min_1 + 1) + 1)
    print(r)



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

using namespace std;
typedef long long LL;

int main(){
  string s, t;
  cin >> s >> t;
  map<char,vector<int>> m;
  rep(i,s.size()){
    char c=s[i];
    m[c].emplace_back(i);
  }
  LL num=-1, pos=0, ans=0;
  LL n=s.size();
  rep(i,t.size()){
    char c=t[i];
    if(!m[c].size()){
      cout << -1 << endl;
      return 0;
    }
    auto itr=upper_bound(m[c].begin(),m[c].end(),num);
    if(itr-m[c].begin()==m[c].size()){
      pos++;
      num=m[c][0];
      ans=m[c][0]+n*pos;
    }
    else{
      num=*itr;
      ans=num+n*pos;
    }
  }
  cout << ans+1 << endl;

  return 0;
}


Measured memory_bytes: 1216
#include<bits/stdc++.h>
#define boost std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

using namespace std;
using LL = long long;

constexpr int MAXN = 2e5 + 5;
constexpr LL M = 1e9 + 7;

template <typename T> inline void read(T &x) {
    int f = 1; x = 0;
    char ch = getchar();
    while (!isdigit(ch)) f = (ch == '-') ? -1 : 1, ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
    x *= f;
}

LL n, k, a[MAXN], res, sum[MAXN], p[MAXN];

void solve1() {
    for (int i = 1; i <= n + 1; i++) a[i] = i - 1;
    sort(a + 1, a + n + 2);
    for (int i = 1; i <= n + 1; i++) sum[i] = sum[i - 1] + a[i];
}

void solve2() {
    reverse(a + 1, a + n + 2);
    for (int i = 1; i <= n + 1; i++) p[i] = p[i - 1] + a[i];
    for (int j = k; j <= n + 1; j++) {
        res += p[j] - sum[j] + 1;
        res %= M;
    }
    cout << res;
}

int main() {
    boost;
    cin >> n >> k;
    solve1(), solve2();
    return 0;
}

Measured memory_bytes: 8276
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;

int main(){
	int N;
	scanf("%d",&N);

	printf("%d\n",(1+N)*N/2);

	return 0;
}


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

#define lli long long int
#define MAX(a,b) (((a)>(b))?(a):(b))
typedef struct s_day
{
	lli a;
	lli b;
	lli c;
	char y;
	char t;
} t_day;

int main(void)
{
	lli n;
	scanf("%lld", &n);
	lli index = 0;
	t_day days[n+1];
	days[0].y = 'd';
	while (index < n)
	{
		scanf("%lld %lld %lld", &(days[index].a), &(days[index].b), &(days[index].c));
		index++;
	}

	index = 1;
	while (index < n)
	{
		days[index].a = days[index].a + MAX(days[index-1].b,days[index-1].c);
		days[index].b = days[index].b + MAX(days[index-1].c,days[index-1].a);
		days[index].c = days[index].c + MAX(days[index-1].a,days[index-1].b);
		index++;
	}
	lli max = MAX(days[n-1].a, days[n-1].b);
	max = MAX(max, days[n-1].c);
	
	printf("%lld", max);

	return (0);
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

    ll n;
    cin >> n;
    map<ll, ll> d_map;
    rep(i, n) {
        ll d;
        cin >> d;
        ++d_map[d];
    }

    ll m;
    cin >> m;
    rep(i, m){
        ll t;
        cin >> t;

        if(d_map[t]) --d_map[t];
        else {
            puts("NO");
            return 0;
        }
    }

    puts("YES");



    return 0;
}

Measured memory_bytes: 12800
fun main() {
    val builder = StringBuilder()

    val s = readInputLine().toCharArray()
    val t = readInputLine().toCharArray()

    var ans = 0

    for (i in s.indices) {
        if (s[i] != t[i]) {
            ans++
        }
    }

    builder.appendln(ans)

    print(builder.toString())
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 43096
N, M=map(int, input().split())

P=list(map(int, input().split()))
XY=[-1 for i in range(N)]


class UnionFind():
  # 作りたい要素数nで初期化
  # 使用するインスタンス変数の初期化
  def __init__(self, n):
    self.n = n
    # root[x]<0ならそのノードが根かつその値が木の要素数
    # rootノードでその木の要素数を記録する
    self.root = [-1]*(n+1)
    # 木をくっつける時にアンバランスにならないように調整する
    self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
  def Find_Root(self, x):
    if(self.root[x] < 0):
      return x
    else:
    # ここで代入しておくことで、後の繰り返しを避ける
      self.root[x] = self.Find_Root(self.root[x])
      return self.root[x]

    # 木の併合、入力は併合したい各ノード
  def Unite(self, x, y):
    # 入力ノードのrootノードを見つける
    x = self.Find_Root(x)
    y = self.Find_Root(y)
    # すでに同じ木に属していた場合
    if (x == y):
      return 
      # 違う木に属していた場合rnkを見てくっつける方を決める
      #rnkが大きい方に結合
    elif (self.rnk[x] > self.rnk[y]):
      self.root[x] += self.root[y]
      self.root[y] = x

    else:
      self.root[y] += self.root[x]
      self.root[x] = y
      # rnkが同じ（深さに差がない場合）は1増やす
      if(self.rnk[x] == self.rnk[y]):
        self.rnk[y] += 1

  # xとyが同じグループに属するか判断
  def isSameGroup(self, x, y):
    return self.Find_Root(x) == self.Find_Root(y)

  # ノードxが属する木のサイズを返す
  def Count(self, x):
    return -self.root[self.Find_Root(x)]

uni=UnionFind(N)

for i in range(M):
  x, y=map(int, input().split())
  XY[x-1]=y-1
  XY[y-1]=x-1
  uni.Unite(x-1, y-1)
  
cnt=0
for i in range(N):
  if not uni.isSameGroup(i,P[i]-1):
    cnt+=1
    
print(N-cnt)

Measured memory_bytes: 14544
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int A, B, C, D,p,k;
cin >> A >> B >> C >> D; /*cinを忘れるとｐもｋも0になる*/
p = A + B;
k = C + D;
if (p > k){
cout << "Left" << endl;
}
else if(p == k){
cout << "Balanced" << endl;
}
else if (p < k){
cout << "Right" << endl;
}
}

Measured memory_bytes: 256
n,q=map(int,input().split())
st=input()
ssum=[0,0]
for i in range(1,n):
    if st[i-1]=="A" and st[i]=='C':
        ssum.append(ssum[-1]+1)
    else:
        ssum.append(ssum[-1])
#print(len(ssum))
for i in range(q):
    a,b=map(int,input().split())
    print(ssum[b]-ssum[a])

Measured memory_bytes: 51236
import java.util.Scanner;
public class Main {
    public static void main (String[] args) {
	Scanner scan = new Scanner(System.in);
	String[] inputs = scan.nextLine().split(" ");
	int[] operands = new int[100];
	int cursol = 0;
	for (int i = 0; i < inputs.length; i++) {
	    int n = -1;
	    if (isOperator(inputs[i])) {
		int op1 = operands[cursol - 2];
		int op2 = operands[cursol - 1];
		if (inputs[i].equals("+")) {
		    n = op1 + op2;
		}
		if (inputs[i].equals("-")) {
		    n = op1 - op2;
		}
		if (inputs[i].equals("*")) {
		    n = op1 * op2;
		}
		cursol -= 2;
	    }
	    else {
		n = Integer.parseInt(inputs[i]);
	    }
	    operands[cursol++] = n;
	}
	System.out.println(operands[0]);
    }
    static boolean isOperator (String a) {
	if (a.equals("+") || a.equals("-") || a.equals("*")) {
	    return true;
	}
	return false;
    }
}

Measured memory_bytes: 26332
#include <bits/stdc++.h>
using namespace std;
#define M 500005
#define bug printf("bug\n")
#define ll long long
int n,k,arr[M],dp[M];
int c(int a,int b)
{
    return abs(arr[a]-arr[b]);
}
int f(int pos)
{
    if(pos>n) return INT_MAX/2;
    if(pos==n) return 0;
    if(dp[pos]!=-1) return dp[pos];
    int res = INT_MAX/2;
    for(int i=1;i<=k;i++)
    {
        if(pos+i<=n) res = min(res,f(pos+i)+c(pos,pos+i));
    }
    return dp[pos] = res;
}
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1; i<=n; i++)
    {
        dp[i] = -1;
        scanf("%d",&arr[i]);
    }
    printf("%d\n",f(1));
    return 0;
}


Measured memory_bytes: 5760