akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define DEBUG
#ifdef DEBUG
#define debug_printf printf
#else
#define debug_printf 1 ? 0 : printf
#endif

typedef long long int ll;
typedef vector<ll> Vl;
typedef vector<int> Vi;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pl;

#define FST first
#define SND second

const int MAX_N = 100000;                  // 10^5
// const int MAX_N = 100000;                  // 10^5
// const int MAX_N = 1000000000;              // 10^9
// const ll  MAX_N = 1000000000000000000;     // 10^18
// const int BASE  = 1000000000 + 7;          // 10^9 + 7
// const int INFI  = 1000000000 + 7;          // 10^9 + 7
// const ll INFL  = 1000000000000000000 + 7; // 10^18 + 7

int N;
bool CLR[MAX_N];
vector<int> G[MAX_N];

Vi find_path(int s, int t) {
  int prev[MAX_N];
  memset(prev, -1, sizeof(prev));

  queue<int> q;
  q.push(s);
  prev[s] = s;
  while (!q.empty()) {
    int u = q.front(); q.pop();
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i];
      if (prev[v] < 0) {
        prev[v] = u;
        q.push(v);
        if (v == t) break;
      }
    }
  }

  Vi path;
  int u = t;
  path.push_back(u);
  while (u != s) {
    u = prev[u];
    path.push_back(u);
  }

  return path;
}

void solve() {
  Vi path = find_path(0, N - 1);

  memset(CLR, false, sizeof(CLR));
  int len = path.size();
  for (int i = 0; i < len / 2; i++) {
    CLR[path[i]] = true;
  }

  stack<int> stk;
  stk.push(0);
  CLR[0] = true;
  int cnt = 1;
  while(!stk.empty()) {
    int u = stk.top(); stk.pop();
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i];
      if (!CLR[v]) {
        CLR[v] = true;
        cnt++;
        stk.push(v);
      }
    }
  }

  if (cnt <= N / 2) {
    cout << "Snuke" << endl;
  } else {
    cout << "Fennec" << endl;
  }
}

int main() {
  cin >> N;
  for (int i = 0; i < N - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }

  solve();

  return 0;
}


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

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

  int ans = 0;
  for (int i = 0; i < n; i++) ans += cnt[i] == m;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <map>
using namespace std;

int main(){
    map<char, int> mp;
    string s;
    cin >> s;
    for(int i=0; i<(int)s.length(); i++){
        mp[s[i]] ++;
    }
    for(auto& cm:mp){
        if(cm.second % 2 == 1){
            cout << "No" << "\n";
            return 0;
        }
    }
    cout << "Yes" << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//freopen("transmitters.in","r",stdin);
using namespace std;

void fast(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
/*long long mn=1e9;
void lucky (long long a, long long c,int b)
{
    if(a > 1e11)
    return ;
    if(a>=b&&c==0)
    mn=min(mn,a);
    
    lucky (a*10+7,c-1,b);
    lucky (a*10+4,c+1,b);
    
}*/
long long toint(string s){
	long long a = 0, c = 1;;
	for (int i = 0; i<s.size(); i++){
		a += (s[s.size() - i - 1] - '0')*c;
		// cout<<a<<endl;
		c *= 10;
	}
	return a;
}
int prime(int x)
{
int c=0;
 if(x==1)
 {
    return 0;
    
 }
 else
 {
  for(int j=2; j*j<=x;j++ ) 
  {
   if(x%j==0) 
   {
    c++;
     } 
   }

     if(c==0) 
      return 1;
    
    return 0;
     }
}
int arr[100000];
int main()
{

  fast();

   long long n,m,c=0,x=0,y=0,t,h,z;
   string s;
   cin>>n;
   for(int i=0;i<n;i++)
   cin>>arr[i];
   sort(arr,arr+n);
   for(int i=0;i<n-1;i++)
   c+=arr[i];
   c+=(arr[n-1]/2);
   cout<<c<<endl;
//	system("pause");
	//cout << "-1" << endl;
	//  transform(x.begin(), x.end(), x.begin(), ::tolower); 

	return 0;
}
	

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

// Loops
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)

#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(xi, x) for (auto &&xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)

// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi = vec<ll>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<ll, ll>;

// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define mp make_pair

// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase(unique(all(v)), v.end())
#define perm(c)                                                                \
  sort(all(c));                                                                \
  for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))

template <class T> pair<T, size_t> max(vector<T> &x) {
  auto it = max_element(all(x));
  return mp(*it, it - x.begin());
}
template <class T> pair<T, size_t> min(vector<T> &x) {
  auto it = min_element(all(x));
  return mp(*it, it - x.begin());
}

template <class T> inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}

// Utilities
// Grid world utilities
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
#define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H)

// Debug
#ifdef LOCAL
#include "dump.hpp"
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define dump(...)
#define debug(x)
#endif

// Paste snippets here!!

//

void solve(long long A, long long B) {
  rep(X,1,1300){
    if(108*X/100-X==A && 110*X/100-X==B){
      cout << X << endl;
      return;
    }
  }
  cout << -1 << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); // Magic for faster cin
  cout.precision(12);
  long long A;
  std::cin >> A;
  long long B;
  std::cin >> B;
  solve(A, B);
  return 0;
}


Measured memory_bytes: 3664
#define _ 2<<17
A[_];long P[_],M=1e9+7,F[_],I[_]={1},X;i,j,k,t;c(a,b)int*a,*b;{t=*a-*b?:a[1]-b[1];}p(a,b){return b?p(a%M*a%M,b/2)*(b%2?a:1L)%M:1;}f(a,b){return F[a+b]*I[a]%M*I[b]%M;}main(s){for(;++X<_;)I[X]=p(s=F[X]=X*s%M,M-2);for(;~scanf("%d",A+i);)i++-1||gets(P);for(qsort(A,i/=2,8,c);j<i;P[j++]=X)for(X=f(s=A[k=j*2]-=1,t=A[j*2+1]-=1);k;X=t<A[k+1]?X:(X-f(s-A[k],t-A[k+1])*P[k/2]%M+M)%M)k-=2;printf("%d",X);}

Measured memory_bytes: 6396
#ABC 118, C - Monsters battle Royale
n = int(input())
A = sorted([int(el) for el in input().split(' ')])

def attack(B):
    for i in range(1, len(B)):
        B[i] = B[i] % B[0]
    return sorted(B)

while len(A) > 1:
    A = attack(A)
    A = [a for a in A if a > 0]
print(A[0])














Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int a, b;
	cin >> a >> b;
	
	int c = max(a, b);
	int d = min(a, b);
	ll ans = 0;
	for (int i = 0; i < c; i++)
	{
		ans += d * pow(10, i);
	}
	cout << ans;
	return 0;
	 
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>

using namespace std;

void check_str(string& S)
{
    for (int i = 0; i < S.size() - 1; i++) {
        if ( S[i] == S[i + 1] ) {
            cout << "Bad" << endl;
            return;
        }
    }
    cout << "Good" << endl;
}

int main()
{
    string S;

    cin >> S;

    check_str(S);

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    
    if(A==B){
      System.out.println("Draw");
    }else if(A==1 && B!=1){
      System.out.println("Alice");
    }else if(A!=1 && B==1){
      System.out.println("Bob");
    }else if(A>B && B!=1){
      System.out.println("Alice");
    }else if(A<B && A!=1){
      System.out.println("Bob");
    }
  }
}
    
    

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

using namespace std;

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

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]) {
  int n,k;
  int x=0,ans=0;
  cin>>n>>k;
  for(int i=0;i<n;i++){
    cin>>x;
    if(x>k-x){
      ans+=k-x;
    }else{
      ans+=x;
    }
  }
  cout<<2*ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
    long q, h, s, d;
    scan(q, h, s, d);
    // writeln(q, ' ', h, ' ', s, ' ', d);
    auto n = lread();
    // writeln(n, "L買いたい");
    long x = 4 * q; //0.25で作った1
    long y = 2 * h; //0.5で作った1
    // writeln("1: ", s);
    // writeln("0.25で作った1: ", x);
    // writeln("0.5で作った1: ", y);
    // writeln("2: ", d);
    // writeln("0.25で作った2: ", x * 2);
    // writeln("0.5で作った2: ", y * 2);
    long min_1 = min(s, x, y);
    long min_2 = min(d, x * 2, y * 2, min_1 * 2);
    // writeln(min_1);
    // writeln(min_2);
    if (n == 1)
    {
        writeln(min_1);
        return;
    }
    if (n % 2 != 0)
    {
        writeln(min((n / 2) * min_2 + min_1, min_1 * n));
        return;
    }
    else
    {
        writeln(min(min_1 * n, min_2 * (n / 2)));
        return;
    }

}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}

void arywrite(T)(T a)
{
    a.map!text.join(' ').writeln;
}


Measured memory_bytes: 3664
H, W = map(int, input().split())
N = int(input())
A = [int(x) for x in input().split()]
C = []
for i in range(N):
  C += [str(i + 1)] * A[i]
for j in range(H):
  out = C[:W]
  if j % 2:
    out.reverse()
  print(' '.join(out))
  C = C[W:]

Measured memory_bytes: 3828
import java.util.*;
public class Main {
    
    public static boolean dfs(int i, int[] nums, List<Integer> left, List<Integer> right)
    {
        // System.out.println(i);
        if(i==11)
        {
            // System.out.println(i);
            for(int j=2;j<left.size(); j++)
            {
                if(left.get(j-1) > left.get(j))
                    return false;
            }
            for(int j=2;j<right.size(); j++)
            {
                if(right.get(j-1) > right.get(j))
                    return false;
            }
            return true;
        }
        // System.out.println(left.toString()+" "+right.toString());
        if(nums[i-1] < left.get(left.size()-1) && nums[i-1] < right.get(right.size()-1))
            return false;
        boolean left_flag = false;
        if(nums[i-1] > left.get(left.size()-1))
        {
            left.add(nums[i-1]);
            left_flag= dfs(i+1, nums, left, right);
            if(left_flag)
                return true;
            left.remove(left.size()-1);
        }
    
        boolean right_flag = false;
        if(nums[i-1] > right.get(right.size()-1))
        {
            right.add(nums[i-1]);
            right_flag =  dfs(i+1, nums, left, right);
            if(right_flag)
                return true;
            right.remove(right.size()-1);
        }
        return false;
    }
    
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] nums = new int[10];
        for(int i=0;i<N;i++)
        {
            for(int j=0;j<10;j++)
            {
                nums[j] = sc.nextInt();
            }
            
            List<Integer> left = new ArrayList<Integer>();
            List<Integer> right = new ArrayList<Integer>();
            left.add(0);
            right.add(0);
            boolean flag = dfs(1, nums, left, right);
            if(flag)
            {
                System.out.println("YES");
            }
            else
            {
                System.out.println("NO");
            }
        }
    }
}



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

int N,K;
char S[200020] = {0};
bool ans[400010] = {0};
int fi,se;
bool F = false;

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

    if(K > 2 * N)
    {
        if(N % 2)
        {
            if(K % 2)printf("A");
            else printf("B");
        }
        for(int i = 0; i < N / 2; i++)printf("BA");printf("\n");
    }

    else
    {
        fi = 0,se = N - 1;

        for(int i = 0; i < N; i++)if(S[i] == 'B')ans[i] = true;

        for(int i = 0; i < K; i++)
        {
            if(ans[fi] ^ F)
            {
                fi++;se++;
                F ^=1;
                ans[se] = F;
            }
            else ans[fi] ^= 1;
        }

        for(int i = fi; i <= se; i++)
        {
            if(F ^ ans[i])printf("B");
            else printf("A");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  string s,t;
  cin >> s >> t;
  ll n=0;
  for(int i=0;i<s.size();i++)if(s[i]!=t[i])n++;

  cout << n << endl;

}

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

#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl


vector<long long> a, b, c;

long long memo[1010][1 << 13];
long long dfs(int i, int rem) {
    if (rem == 0) return 0;
    if (i == a.size()) {
        if (rem) return 1LL << 32;
        return 0;
    }
    if (memo[i][rem] != -1) return memo[i][rem];
    return memo[i][rem] = min(dfs(i + 1, rem), dfs(i + 1, rem & ~c[i]) + a[i]);
}

int main() {
    memset(memo, -1, sizeof(memo));
    int N, M;
    cin >> N >> M;
    a.resize(M);
    b.resize(M);
    c.resize(M);
    rep (i, M) {
        cin >> a[i] >> b[i];
        c[i] = 0;
        rep (j, b[i]) {
            int t;
            cin >> t;
            t--;
            c[i] |= (1 << t);
        }
    }
    auto ans = dfs(0, (1 << N) - 1);
    if ((1LL << 32) <= ans ) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}


Measured memory_bytes: 68296
h,w=map(int,input().split())
l=[]
d=[-1,0,1]
for i in range(h):
    a=list(input())
    l.append(a)
for i in range(h):
    for j in range(w):
        cnt=0
        for x in d:
            for y in d:
                if 0<=i+x<h and 0<=j+y<w:
                    if l[i+x][j+y]=="#":
                        cnt+=1
        if l[i][j]==".": l[i][j]=cnt
for i in l:
    print("".join(map(str,i)))

Measured memory_bytes: 3064
N = int(input())
plan = []
for i in range(N):
    A = input().split()
    plan.append(A)

judge = 0
now = [0, 0, 0]

for i in range(N):
    t = int(plan[i][0])
    x = int(plan[i][1])
    y = int(plan[i][2])
    
    dis = abs(x - now[1]) + abs(y - now[2])
    t_ = t - now[0]
    
    if t_ < dis:
        judge = 1
        break
    else:
        t_ = t_ - dis
        
        if t_ % 2 != 0:
            judge = 1
            break
    
    now = [t, x, y]

if judge == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 32168
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using ll = long long;
using namespace std;

int main() {
    ll A, B, C;
    cin >> A >> B >> C;

    puts(A+B >=C ? "Yes" : "No");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
string s,t,u;
int a,b;
int main(){
    cin>>s>>t;
    cin>>a>>b;
    cin>>u;
    if(s==u)cout<<a-1<<" "<<b;
    else cout<<a<<" "<<b-1;


	return 0;
}


Measured memory_bytes: 256
<?php
/**
 * ABC133
 * A - T or T
 */

// $s = trim(fgets(STDIN));
// fscanf(STDIN, "%d %d", $a, $b);
// $n = array_map('intval', explode(' ', trim(fgets(STDIN))));

fscanf(STDIN, "%d", $K);
$S = trim(fgets(STDIN));

if (strlen($S) <= $K) {
    echo $S, "\n";
} else {
    echo substr($S, 0, $K);
    echo "...\n";
}


Measured memory_bytes: 16220
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

int main(){
  int n;
  cin>>n;
  vector<long> v(n);
  rep(i,n) cin>>v[i];
  long tot = accumulate(all(v), 0L);

  long ans = tot;
  long cur = 0;
  rep(i,n){
    cur += v[i];
    ans = min(ans, abs(tot - cur*2));
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int n, m;
    vector<int> rest(2);
    cin >> n >> rest[0] >> rest[1] >> m;

    if(n == 1){
        int a, b;
        cin >> a >> b;
        for(int i=0; i<m; ++i){
            int x;
            cin >> x;
            if(x == a)
                -- rest[0];
            if(x == b)
                -- rest[1];

            if(rest[0] <= 0 || rest[1] <= 0){
                if(rest[0] <= 0 && rest[1] <= 0)
                    cout << "DRAW" << endl;
                else if(rest[0] <= 0)
                    cout << "USAGI" << endl;
                else
                    cout << "NEKO" << endl;
                return 0;
            }
        }

        cout << "DRAW" << endl;
        return 0;
    }

    vector<vector<pair<int, int> > > p(2, vector<pair<int, int> >(1000001, make_pair(-1, -1)));
    for(int i=0; i<2; ++i){
        for(int j=0; j<n; ++j){
            for(int k=0; k<n; ++k){
                int a;
                cin >> a;
                p[i][a] = make_pair(j, k);
            }
        }
    }

    vector<vector<int> > yNum(2, vector<int>(n, 0)), xNum(2, vector<int>(n, 0)), diagonalNum(2, vector<int>(2, 0));
    for(int i=0; i<m; ++i){
        int a;
        cin >> a;

        for(int i=0; i<2; ++i){
            if(p[i][a].first != -1){
                int y = p[i][a].first;
                int x = p[i][a].second;
                if(++ yNum[i][y] == n)
                    -- rest[i];
                if(++ xNum[i][x] == n)
                    -- rest[i];
                if(y == x && ++ diagonalNum[i][0] == n)
                    -- rest[i];
                if(y + x == n-1 && ++ diagonalNum[i][1] == n)
                    -- rest[i];
            }
        }

        if(rest[0] <= 0 || rest[1] <= 0){
            if(rest[0] <= 0 && rest[1] <= 0)
                cout << "DRAW" << endl;
            else if(rest[0] <= 0)
                cout << "USAGI" << endl;
            else
                cout << "NEKO" << endl;
            return 0;
        }
    }

    cout << "DRAW" << endl;
    return 0;
}

Measured memory_bytes: 16000
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;

#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

#define ALL(obj) (obj).begin(),(obj).end()

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision; // cpp_int

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define L list<int>

#define pb(a) push_back(a)
#define mp make_pair


int main(){
  vector<V> v(3,V(3));REP(i,3)REP(j,3)cin>>v[i][j];

  bool flag=false;
  REP(a0,v[0][0]+1){//v[0][0]がiと仮定する
    int b0 = v[0][0]-a0;
    int b1 = v[0][1]-a0;
    int b2 = v[0][2]-a0;
    int a1 = v[1][0]-b0;
    int a2 = v[2][0]-b0;
    if(a0+b0==v[0][0]&&a0+b1==v[0][1]&&a0+b2==v[0][2]&&a1+b0==v[1][0]&&a1+b1==v[1][1]&&a1+b2==v[1][2]&&a2+b0==v[2][0]&&a2+b1==v[2][1]&&a2+b2==v[2][2]){flag=true;break;}
  }
  Yes(flag);
  return 0;
}



Measured memory_bytes: 256
N,M = [int(s) for s in input().split()]
data = [[0 for i in range(4)] for j in range(M)]

for i in range(M):
    l = [int(s) for s in input().split()]
    data[i][0],data[i][1] = l[0],l[1]
    data[i][2] = i+1
data.sort()

seq = 1
for i in range(M):
    if i == 0:
        data[0][3] =str(data[0][0]).zfill(6) + "000001"
        seq += 1
    elif data[i][0] == data[i-1][0]:
        data[i][3] = str(data[i][0]).zfill(6) + str(seq).zfill(6)
        seq += 1
    else:
        seq = 1
        data[i][3] = str(data[i][0]).zfill(6) + "000001"
        seq += 1

data.sort(key = lambda x:x[2])
for i in range(M):
    print(data[i][3])
        

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

int main(){
    int N,K,Q;cin>>N>>K>>Q;
    vector<int> a(N);
    for(int i=0;i<Q;i++){
        int p;cin>>p;
        a.at(p-1)++;
    }
    for(int i=0;i<N;i++){
        if(a.at(i)>Q-K)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
using ll = long long;
using ull = unsigned long long;
constexpr int MOD = 1000000007;

int mod(ll x){
    return x > 0 ? x % MOD : (x+MOD) % MOD;
}

int modm(ll x,ll m){
    return x * m % MOD;
}

int modpow(ll x, ll p) {
    int ret = 1;
    while(p > 0) {
        if (p & 1) ret = modm(ret,x);
        x = modm(x,x);
        p >>= 1;
    }
    return ret;
}

// x * modinv(d)
int modd(ll x,ll d) {
    return modm(x,modpow(d,MOD-2));
}

int main(void)
{
    IOS
    constexpr int N = 1e5;
    constexpr int M = 13;
    
    string s; cin >> s;
    ll dp[N+10][M];
    memset(dp,0,sizeof dp);
    dp[0][0] = 1;

    int l = s.size();
    REP(i,l) {
        REP(j,M) {
            REP(k,10) {
                if (s[i] - '0' == k || s[i] == '?') {
                    dp[i+1][(j*10 +k) % M] = mod(0LL + dp[i+1][(j*10 +k) % M] + dp[i][j]);
                }
            }
        }
    }

    cout << dp[l][5] << endl;

    return 0;
}

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

using namespace std;

int solve_brute(const vector<vector<int>> &pts, int last, int n) {
	if (n < 0)
		return 0;

	int max_n = 0;
	for (size_t i = 0; i < pts.size(); ++i) {
		if (last != (int)i) {
			max_n = max(max_n,
				    solve_brute(pts, i, n - 1) + pts[n][i]);
		}
	}

	return max_n;
}

int solve_tab(const vector<vector<int>> &pts, int n) {
	// dp[d][a] represents the maximum score stopping at day d
	// with the last used action a
	vector<vector<int>> dp(n, vector<int>(3));
	dp[0][0] = pts[0][0];
	dp[0][1] = pts[0][1];
	dp[0][2] = pts[0][2];

	for (int i = 1; i < n; ++i) {
		int m0 = dp[i - 1][0];
		int m1 = dp[i - 1][1];
		int m2 = dp[i - 1][2];

		// I'm using action 0 so I have to use the previous
		// days that used actions 1 or 2 last
		dp[i][0] = max(m1 + pts[i][0], m2 + pts[i][0]);

		dp[i][1] = max(m0 + pts[i][1], m2 + pts[i][1]);
		dp[i][2] = max(m0 + pts[i][2], m1 + pts[i][2]);
	}

	return max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]});
}

int main() {

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

	int n;
	cin >> n;
	vector<vector<int>> pts(n, vector<int>(3));
	for (int i = 0; i < n; ++i) {
		cin >> pts[i][0] >> pts[i][1] >> pts[i][2];
	}

	cout << solve_tab(pts, n) << '\n';

	return 0;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 100100100100;


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}


int main(){
    int N;
    cin >> N;
    vector<ll> ans;
    ans.push_back(2);
    ans.push_back(1);
    int index = 2;
    while(1){
        if(ans.size() > N){
            cout << ans[N] << endl;
            return 0;
        }
        ll num = ans[index - 1] + ans[index - 2];
        ans.push_back(num);
        index++;
    }
    
}

Measured memory_bytes: 256
n = int(input())
s = input()

#ox
ans = "-1"

for animals in ["SS","SW","WS","WW"]:
    for say in s:
        if (animals[-1] == "S" and say == "o" ) or (animals[-1] == "W" and say == "x"):
            animals += animals[-2]
        elif (animals[-1] == "S" and say == "x"):
            if animals[-2] == "S":
                animals += "W"
            else:
                animals += "S"
        elif (animals[-1] == "W" and say == "o"):
            if animals[-2] == "S":
                animals += "W"
            else:
                animals += "S"
    if animals[:2] == animals[-2:]:
        ans  =animals[1:-1]
print(ans)


Measured memory_bytes: 3444
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdio.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
int main()
{
  int n,i,x[8],y[8],g=0;
  double sum,total=0;
  cin>>n;
  vector<int> c(n);
  rep(i,n){
    cin>>x[i]>>y[i];
    c[i]=i;
  }
  do{
    sum=0;
    rep(i,n-1){
      sum+=fabs(sqrt(pow(x[c[i]]-x[c[i+1]],2)+pow(y[c[i]]-y[c[i+1]],2)));
    }
    total+=sum;
    g++;
  }while(next_permutation(c.begin(),c.end()));
 
  printf("%f\n",total/g);
  return 0;
}

Measured memory_bytes: 256
X, K, D = map(int, input().split())
ans = 0

if X > 0:
    tmp = abs(X) // D
    if tmp  >= K:
        ans = X-D*K
        
    elif tmp < K:
        nK = K - tmp
        X1 = X- D*tmp
        X2 = X1 - D
        if nK %2 == 0:
            ans = X1
        else :
            ans = X2
        
elif X < 0:
    tmp = abs(X) // D
    if tmp  >= K:
        ans = X + D*K
    elif tmp < K:
        nK = K - tmp
        X1 = X + D*tmp
        X2 = X1 + D
        if nK %2 == 0:
            ans = X1
        else :
            ans = X2
else:
    if K %2 == 0:
        ans = 0
    else :
        ans = D
print(abs(ans))

Measured memory_bytes: 61780
#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<math.h>
#include<iomanip>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define MOD 1000000007

int main() {
	vt n, cnt = 0, ans = 0;
	cin >> n;
	vector<vt> h(n);
	rep(i, n) cin >> h.at(i);
	h.push_back(1000000001);
	rep(i, n){
		if (h.at(i) >= h.at(i + 1)) {
			cnt++;
		}
		else {
			if (ans < cnt) ans = cnt;
			cnt = 0;
		}
	}
	cout << ans;
	return 0;
}

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

int main(){
  int64_t K;
  cin >> K;
  vector<vector<string> > dp(12);
  if(K<10){
    cout << K << endl;
    return 0;
  }
  for(int i=0;i<10;i++){
    dp.at(1).push_back(to_string(i));
  }
  int64_t count=9;
  for(int64_t i=2;;i++){
    for(int j=0;j<10;j++){
      for(auto s:dp.at(i-1)){
        if(abs((s.at(0)-'0')-j)<=1){
          if(j!=0){
            count++;
          }
          dp.at(i).push_back(to_string(j)+s);
          if(count==K){
            cout << j << s << endl;
            return 0;
          }
        }
      }
    }
  }
  return 0;
}


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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
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 (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int x;
int res;
rep(i,5){
    cin>>x;
    if(x==0){
        res=i+1;
    }
}
cout<<res<<endl;
return 0;
}

Measured memory_bytes: 3636
def main():
    args = input().rstrip()
    S = args
    T = input().rstrip()
    
    flag = True
    for i in range(len(S)):
        if(S[i] != T[i]):
            flag = False
            break
    
    if(flag == True):
        print('Yes')
    else:
        print('No')
    
    
if __name__ == "__main__":
    main()

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

int64_t luca(int i){
  int64_t prev1 = 2;
  int64_t prev2 = 1;
  for(int j = 2; j<=i; j++){
  	int64_t next = prev2 + prev1;
    prev1 = prev2;
    prev2 = next;
  }
  return prev2;
}

int main(){
  int64_t N;
  cin >> N;
  
  cout << luca(N) << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
vector<int> arrmv;
/* Iterative Function to calculate (x^y)%p in O(log y) */
const int MODN=998244353;
int quick_power(int x, unsigned int y, int p) 
{ 
    int res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or  
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p;   
    } 
    return res; 
} 

int32_t main(){
	int n;cin>>n;
	arrmv.resize(n);
	for(int i=0;i<n;i++){
		cin>>arrmv[i];
	}
	if(arrmv[0]!=0){
		cout<<0<<endl;
		return 0;
	}
	sort(arrmv.begin(),arrmv.end(),less<int>());
	int i,j;
	vector<int> mv;
	for( i=j=0;i<n;i=j){
		j=i;
		while(j<n && arrmv[j]==arrmv[i])j++;
		if(j==n)break;
		if(arrmv[j]>arrmv[i]+1){
			cout<<0<<endl;
			return 0;
		}
		if(i==0){
			if(j-i>1){
				cout<<0<<endl;
				return 0;
			}
			continue;
		}
		mv.push_back(j-i);
		
	}
	mv.push_back(j-i);
	int ans=1;
	for(int i=1;i<(int)mv.size();i++){
		ans*=quick_power(mv[i-1],mv[i],MODN);
		ans%=MODN;
	}
	cout<<ans<<endl;
	return 0;
}

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

#define LIM 100000
#define SENTINEL 1000000000

struct Card {
  char s[2];
  int v;
};

int partition(Card A[], int left, int right) {
  int m = right - 1;
  int j = left;
  for ( int i = left; i < m; i++ ) {
    if ( A[i].v <= A[m].v ) {
      Card t = A[j]; A[j] = A[i]; A[i] = t;
      j++;
    }
  }
  Card t = A[j]; A[j] = A[m]; A[m] = t;
  return j++;
}

void quickSort(Card A[], int left, int right) {
  int m = partition(A, left, right);
  if ( left < m ) {
    quickSort(A, left, m);
    quickSort(A, m, right);
  }
}

void merge(Card A[], int left, int middle, int right) {
  int l = middle - left;
  int r = right - middle;
  Card L[l], R[r];
  for ( int i = 0; i < l; i++ ) L[i] = A[left + i];
  for ( int i = 0; i < r; i++ ) R[i] = A[middle + i];
  L[l].v = R[r].v = SENTINEL;
  l = r = 0;

  for ( int i = left; i < right; i++ ) {
    if (L[l].v <= R[r].v) A[i] = L[l++];
    else A[i] = R[r++];
  }
}

void mergeSort(Card A[], int left, int right) {
  if ( left + 1 < right ) {
    int m = (left + right) / 2;
    mergeSort(A, left, m);
    mergeSort(A, m, right);
    merge(A, left, m, right);
  }
}

int main() {
  Card A[LIM], B[LIM];
  int n;

  scanf("%d", &n);
  for ( int i = 0; i < n; i++ ) {
    scanf("%s %d", A[i].s, &A[i].v);
    B[i] = A[i];
  }
  
  quickSort(A, 0, n);
  mergeSort(B, 0, n);

  int j = 0;
  while ( strcmp(A[j].s, B[j].s) == 0 && j < n ) j++;

  if ( j == n ) printf("Stable\n");
  else printf("Not stable\n");

  for ( int i = 0; i < n; i++ ) {
    printf("%s %d\n", A[i].s, A[i].v);
  }

  return 0;
}


Measured memory_bytes: 4940
#include <iostream>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <typeinfo>
#include <queue>
#include <math.h>
using namespace std;


int main(){
	int n, t,ans=0,m;
	cin>>n>>t;
	int a[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}

	int b[n]={};
	m=a[0];
	for (int i = 1; i < n; ++i)
	{
		m=min(a[i-1],m);
		b[i]=a[i]-m;
	}

	int y=0;
	for (int i = 0; i < n; ++i)
	{
		y=max(y,b[i]);
	}

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

	cout<<ans<<endl;







return 0;
}



Measured memory_bytes: 1024
#define REP(i, n) for (int i = 0; (i) < (n); ++i)

#include <iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    double a[n];
    string u[n];
    REP(i, n)
    {
        cin >> a[i] >> u[i];
    }
    double ans = 0.0;
    REP(i, n)
    {
        if (u[i] == "JPY")
        {
            ans += a[i];
        }
        else
        {
            ans += a[i] * 380000.0;
        }
    }
    cout << ans<< endl;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

n,m = LI()

print((n-1)*(m-1))

Measured memory_bytes: 61900
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	p := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&p[i])
	}
	sort.Ints(p)
	var ans int
	for i := 0; i < k; i++ {
		ans += p[i]
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1888
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ull unsigned long long
#define mp make_pair
#define F first
#define S second
//#define mod 1000000007

ll  mod = 1000000007;
int main()
{
    ll n;
    cin >> n;

    ll ans = 1;
    ll ans1 = 1;
    ll ans2 = 1;

    for(int i=0;i<n;i++)
    {
        ans *= 10;
        ans1 *= 9;
        ans2 *= 8;
        
        ans1 %= mod;
        ans %= mod;
        ans2 %= mod;
    }

    
    cout << ((ans%mod + (-2*ans1+2*mod)%mod)%mod + ans2%mod )%mod << endl; 


}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}
const int INF = 1e18;

bool isOk(int n, vi &B, int index, int mx) {
    return n+B[index] <= mx;
}

signed main() {
    int N, M, K;
    cin >> N >> M >> K;

    vi Asum(N+1, 0), Bsum(M+1, 0);
    rep(i, N) {
        int a;
        cin >> a;
        Asum[i+1] = Asum[i] + a; 
    }
    rep(i, M) {
        int b;
        cin >> b;
        Bsum[i+1] = Bsum[i] + b;
    }

    int res = 0;
    rep(i, N+1) {
        if(Asum[i]>K) break;
        int l=0, r=M+1, mid;
        while(abs(l-r)>1) {
            mid = (l+r)/2;
            if(isOk(Asum[i], Bsum, mid, K)) l = mid;
            else r = mid;
        }
        res = max(res, i+l);
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 6424
#include <bits/stdc++.h>
#define ll long long int
#define N 1000
#define f(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define po pop_back
#define pb push_back
#define lb lower_bound
#define fi first
#define se second
#define debug(x) cout << #x << " = " << x << endl
#define ub upper_bound
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define all(x) x.begin(), x.end()
#define PI 3.14159265
#define cot cout.tie(0)
using namespace std;
/**
        * @author :: Sawlani
        *
        */

string calnext(string s)
{
    bool flag= true;

    for(auto i:s)
    {
        if(i!='9')
        flag = false;

    }

    if(flag)
    {
        int n=s.length();
        s="";
        s+="1";
        f(i,1,n)
        s+="0";
         return s;
    }
     
     
      rf(i,s.length()-1,0)
      {
            if((s[i]>s[i-1])||(s[i]=='9'))
            {
                continue;
            }
            else 
            {
               int p=s[i]-'0';
               p++;
               s[i]=(char)(p+48);
               p=s[i]-'0';
               f(j,i+1,s.length()-1)
               {
                     if(j==(i+1))
                     {
                         p--;
                        s[j]=(char)(p+48);
                     }
                   else
                   {
                        p--;
                      s[j]=p<=0?'0':(char)(p+48);
                   }
                    
               }
               return s;
            }
      }

      int p=s[0]-'0';
      p++;
      
      
      s[0]=(char)(p+48);
       p--;
      s[1]=p<=0?'0':(char)(p+48);
             

       f(i,2,s.length()-1)
       {
          p--;
          s[i]=p<=0?'0':(char)(p+48);
       }
       return s;
}       

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

     if(n<=10)
     {
         cout <<  n << endl;
         return 0;
     }
     
     n-=10;

     
    string ans="10";
      
     while(n!=0)
     {
         n--;

         ans=calnext(ans);

      
     }

     cout << ans;
}

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

int main() {
  //  freopen("in.txt", "r", stdin);
  //  freopen("out.txt", "w", stdout);
  int t;
  cin >> t;
  while(t--){
    int a, b;
    cin >> a >> b;
    if(a > b)swap(a, b);
    ll rnk = 1LL * a * b;
    ll lo = 0, hi = rnk - 1;
    while(lo < hi){
      ll mid = (lo + hi + 1) / 2;
      ll m = mid / 2;
      ll F = mid + (mid >= a ? 1 : 0);
      ll S = mid + (mid >= b ? 1 : 0);
      bool g = 1;
      for(ll x = max(1LL, m - 50);x <= min(m + 50, mid);x++){
        ll L = x;
        ll R = mid - x + 1;
        if(L >= a)
          L++;
        if(R >= b)
          R++;
        if((rnk + R - 1) / R <= L || rnk <= L * R){
          g = 0;
          break;
        }

      }
      if(g)
        lo = mid;
      else
        hi = mid - 1;
    }
    cout << lo << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#define TEMPLATE_USED
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
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;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

void solve();

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

void solve(){
    ll n,k;cin>>n>>k;
    vl a(n);rep(i,n)cin>>a[i];

    cout<<(n-1+k-2)/(k-1)<<endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>

int n;
long long a[200000];
long long k;

int cmpfunc( const void *a, const void *b )
{
    long long r = *((long long *) a) - *((long long *) b);

    if( r < 0LL) return( -1 );
    else if( r == 0LL ) return( 0 );
    else return( 1 );
}

long long count( long long x )
{
    int i;
    long long tot = 0;

    for( i=0; i<n; i++ ) {
        if( a[i] < 0 ) {
            int l = -1;
            int r = n;
            while( l+1 < r ) {
                int c = (l+r) /2;
                if( a[c] * a[i] < x ) r=c;
                else                  l=c;
            }
            tot += n-r;
        } else {
            int l = -1;
            int r = n;
            while( l+1 < r ) {
                int c = (l+r) /2;
                if( a[c] * a[i] < x ) l=c;
                else                  r=c;
            }
            tot += r;
        }

        if( a[i] * a[i] < x ) tot--;
    }

    tot /= 2;

//printf( "k=%lld   x=%lld   tot=%lld\n", k, x, tot );

    return( tot );
}

int main( int argc, char *argv[] )
{
    int i;
    long long l = -((long long)1.0e18)-1;
    long long r =  ((long long)1.0e18)+1;

    if( scanf( "%d", &n ) != 1 ) {
        printf( "N read error!\n" );
        exit( -1 );
    }

    if( scanf( "%lld", &k ) != 1 ) {
        printf( "K read error!\n" );
        exit( -1 );
    }

    for( i=0; i<n; i++ ) {
        if( scanf( "%lld", &a[i] ) != 1 ) {
            printf( "A[%d] read error!\n", i );
            exit( -1 );
        }
    }

    qsort( a, n, sizeof(long long), cmpfunc );

    while( l+1 < r ) {

        long long x = (l + r) /2;

        if( count( x ) < k ) l = x;
        else                 r = x;
    }

    printf( "%lld\n", l );
}


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

long long xorsum(long long x){
    if(x%4 == 3){return 0;}
    if(x%4 == 1){return 1;}
    if(x%4 == 2){return x+1;}
    if(x%4 == 0){return x;}
}

int main (){
    long long A,B;
    cin >> A >> B;
    cout << (xorsum(A-1) ^ xorsum(B)) << endl;
    //関数の積　（）で囲うこと
}

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

int main(){
    int n, l, ab = 500, res = 0;
    vector<int> v;
    cin >> n >> l;

    for(int i = 1; i <= n; i++){
        v.push_back(l + i - 1);
        if(abs(l + i - 1) < abs(ab)){
            ab =l + i - 1;
        }
    }
    //sort(v.begin(),v.end());
    res = accumulate(v.begin(),v.end(),0) - ab;
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll M = 1e9 + 7;
const int iinf = 1 << 29;
const long long llinf = 1ll << 60;
const double PI = 3.14159265;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll mrand(ll B) {
  return (ull)rng() % B;
}

void work() {
    int n; cin>>n;
    vector<int> v(n);
    vector<int> ans(n, 0);
    for (auto& e : v) cin>>e;
    for (int b = 0; b < 31; ++b) {
        int n0 = 0, n1 = 0;
        for (auto e : v) {
            if ((1<<b)&e)
                ++n1;
            else
                ++n0;
        }
        if (n0 % 2 == 0) {
            for (int i = 0; i < n; ++i) {
                if (v[i]&(1<<b)) {
                    ans[i] |= (1<<b);
                }
            }
        } else {
            for (int i = 0; i < n; ++i) {
                if ((v[i]&(1<<b)) == 0) {
                    ans[i] |= (1<<b);
                }
            }
        }
    }
    for (auto e : ans) cout << e << " ";
    cout << "\n";
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    //int nt; cin>>nt; while (nt--) work();
    work();
    return 0;
}


Measured memory_bytes: 4712
/****************************************************************
*	Author: huhao
*	Email: 826538400@qq.com
*	Create time: 2020-03-15 15:38:40
****************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define fr(i,a,b) for(int i=(a),end_##i=(b);i<=end_##i;i++)
#define fd(i,a,b) for(int i=(a),end_##i=(b);i>=end_##i;i--)
int read()
{
	int r=0,t=1,c=getchar();
	while(c<'0'||c>'9')
	{
		t=c=='-'?-1:1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		r=(r<<3)+(r<<1)+(c^48);
		c=getchar();
	}
	return r*t;
}
const int N=100010,mod=1000000007;
char c[N];
int s,f[N],n,a[N],b[N];
int main()
{
	scanf("%s",c+1); n=strlen(c+1); f[n+1]=1;
	fr(i,1,n)
	{
		if(i==n){ printf("1\n"); return 0; }
		if(c[i]==c[i+1]) break;
	}
	fd(i,n,1)
	{
		a[i]=c[i]=='a'?i+1:c[i+1]=='b'?i+2:a[i+2];
		b[i]=c[i]=='b'?i+1:c[i+1]=='a'?i+2:b[i+2];
		s=(s+(c[i]=='a'?1:2))%3;
		f[i]=(f[a[i]]+f[b[i]]+(s==0))%mod;
//		printf("%d %d %d %d\n",i,a[i],b[i],f[i]);
	}
	printf("%d\n",(f[1]-(s==0)+mod)%mod);
	return 0;
}

Measured memory_bytes: 1408