akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
typedef pair<pi, int> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (int) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss

string n;
int sum;

int main() {
	fastio; cin >> n;
	FOR(i, 0, n.length()-1) {
		sum += n[i] - '0';
	}
	cout << (sum % 9 ? "No" : "Yes");
}


Measured memory_bytes: 3744
#!/usr/bin/env python3
import collections
import copy

def count_black(row):
    ret = 0
    for r in row:
        ret += collections.Counter(list(r))['#']
    return ret

def flip(row, w, h):
    if w>-1:
        for i in range(len(row)):
            row[i][w] = 'R'
    if h>-1:
        row[h]=['R' for _ in range(len(row[h]))]

    return row


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    H, W, K = list(map(int, input().split()))
    
    row = []
    for i in range(H):
        row.append(list(input()))

    ans = 0
    for i in range(2**(H+W)):
        rr = copy.deepcopy(row)
        for j in range(H+W):
            if ((i >> j) & 1):
                if j<H: 
                    rr = flip(rr, -1, j)
                else:
                    rr = flip(rr, j-H, -1)
        if count_black(rr) == K:
            ans += 1

    print(ans)



if __name__ == '__main__':
    main()


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

void solve()
{
	ll n, k;
	cin >> n >> k;

	// (n+1)Ck + nC(k+1) + ... + (n+1)C(n+1)
	//=(n+1)C(n-k+1) + nC(n-k) + ... + (n+1)C(0)

	ll ans = 0;
	for(ll i = k; i <= n + 1; ++i)
	{
		ans = (ans + (long long)((n+1) * i) % MOD - (long long)(i * i) % MOD + 1) % MOD;
	}

	cout << ((ans + MOD) % MOD) << endl;
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 1; i <= (n); ++i)
using ll = long long;
using P = pair<int, int>;

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  bool ans = false;
  rep (i, b){
    if ((a * i) % b == c) ans = true;
  }
  if (ans) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

ll gcd(ll a, ll b) {
  ll v0=a, v1=b, v2=v0%v1;
  while(v2>0) {
    v0 = v1;
    v1 = v2;
    v2 = v0%v1;
  }
  return v1;
}

int main() {
  int N;
  cin>>N;
  ll A[N];
  for(int i=0;i<N;++i) cin>>A[i];
  ll gcds1[N], gcds2[N];
  gcds1[0] = A[0];
  for(int i=1;i<N;++i) {
    gcds1[i] = gcd(gcds1[i-1], A[i]);
  }
  gcds2[N-1] = A[N-1];
  for(int i=N-2;i>=0;--i) {
    gcds2[i] = gcd(gcds2[i+1], A[i]);
  }
  ll ans = 1;
  /**
  for(int i=0;i<N;++i) cout<<gcds1[i]<<" ";
  cout<<endl;
  for(int i=0;i<N;++i) cout<<gcds2[i]<<" ";
  cout<<endl;
  **/
  for(int i=0;i<N;++i) {
    if(i==0) ans = max(ans, gcds2[1]);
    else if(i==N-1) ans = max(ans, gcds1[N-2]);
    else ans = max(ans, gcd(gcds1[i-1], gcds2[i+1]));
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 5948
#include<iostream>
#include<vector>
using namespace std;
#define ll long long int
int main(){
    ll n, m, k, temp;;
    cin>>n>>m>>k;
    vector<ll> a(n+1), b(m+1);
    a[0]=0, b[0]=0;
    for(int i=1;i<=n;i++){
        cin>>temp;
        a[i]=a[i-1]+temp;
    }
    for(int i=1;i<=m;i++){
        cin>>temp;
        b[i]=b[i-1]+temp;
    }
    ll ans=-1, j=m;
    for(ll i=0;i<=n;i++){
        if(a[i]>k) break;
        while(b[j]>k-a[i]){
            j--;
        }
        ans=max(ans, i+j);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5952
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <stack>
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define elif else if
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define append push_back
#define pb push_back
#define str to_string
#define gcd __gcd
#define optimise cout.tie(0);cin.tie(0);ios_base::sync_with_stdio(0);
#define all(x) x.begin(),x.end()
using namespace std;
const ll MOD = 998244353;
void solve()
{
    ll n;cin>>n;
    ull ans=0;
    for(ll i=2;i<=n;i++)
        for(ll j=i<<1;j<=n;j+=i)ans+=j;
    cout<<ans+n*(n+1)-1;
}
int main()
{
    optimise
    ll t=1;
    while(t--)solve();
}

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

int main(void){
		int b,f,r,v,n;
		int a[4][3][10];

		//配列初期化
		for(int i = 0;i < 4;i++){
				for(int j = 0; j < 3;j++){
						for(int k = 0;k < 10;k++){
								a[i][j][k] = 0;
						}
				}
		}

		cin >> n;
		for(int i = 0;i < n;i++){
				cin >> b >> f >> r >> v;
				a[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++){
							cout << " " << a[i][j][k];
						}
						cout << endl;
				}
				if(i !=3){
						cout << "####################" <<endl;
				}
		}
		return 0;
}

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

int main(void){
    int n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n){
        cin>>a[i];
    }
    int l = 0;
    ll bit = 0;
    ll res = 0;
    rep(r,n){
        while(bit+a[r] != (bit^a[r])){
            bit -= a[l];
            l++;
        }
        bit += a[r];
        res += r-l+1;
    }
    cout<<res<<endl;
    return 0;
}


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

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 27
#endif

#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(v) (int)(v.size())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ar array
#define lb lower_bound
#define ub upper_bound
#define forn(i, n) for(int i = 0; i < n ; ++i)
#define for1(i, n) for(int i = 1; i <=n ; ++i)
#define ford(i, n) for(int i = n-1; i>= 0;--i)
#define UNQ(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define mem(X,val) memset(X, val, sizeof((X)))

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>>  vvi ;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpi ;

const db PI = acos(-1);
const ll mod = 1e9+7;
template <typename A, typename B>istream& operator>>(istream& input,pair<A,B>& x) {input>>x.F>>x.S;return input;}
template <typename A>istream& operator>>(istream& input,vector<A>& x) {for(auto& i:x)input>>i;return input;}
template<typename A>ostream& operator<<(ostream& output,vector<A>& x) {for(auto& i:x)output<<i<<' ';return output;}
template<class T> void _R(T &x) { cin >> x; } void R() {}template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...);}
template <class T>void smax(T& x,T y){ if(x<y)x=y;}
template <class T>void smin(T& x,T y){ if(x>y)x=y;}
template<typename T1, typename T2> T1 powz(T1 A, T2 B);
/***************************************************main code**************************************************************/
const int MXN=1e6+5;
const ll INF = 9e18+200;
const int inf = 1e9+100;
const int mxn = 1e5+20;

vector<int> adj[mxn];
int dist[mxn];
bool visited[mxn];
bool active[mxn];
vector<int> order;
void dfs(int u){
	visited[u] = true;
	active[u] = true;
	for(int v: adj[u])
			if(!visited[v])
				dfs(v);
	active[u] = false;
	order.pb(u);
}
void test_case()
{	
	int n,m; cin >> n >> m;
	forn(i, n)adj[i].clear(),dist[i] = 0,visited[i]=false,active[i]=false;
	order.clear();
	forn(j, m){
		 int x,y; cin >> x>> y;
	 	--x,--y;
	 	adj[x].pb(y);
	}
	forn(i, n)
		if(!visited[i])
				dfs(i);
	reverse(all(order));
	debug(order);
	for(int u : order){
		for(int v : adj[u])
			  smax(dist[v],dist[u]+1);
	}
	int lpa=0;
	forn(i,n)
		smax(lpa,dist[i]);
	cout << lpa;	
}
/*************----------------------------******************/
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
#ifdef VIJY_DEFINE
    freopen("input.txt","r",stdin);
#endif
//  freopen("output.txt","w",stdout);
    int Tests = 1;
//  cin >> Tests;
    
    for(int tc = 1; tc <= Tests; ++tc){
        //cout <<"Case #"<<tc<<": ";
        test_case();
        cout<<'\n';
    }
#ifdef VIJY_DEFINE
    cerr << "Time elapsed: "<< 1.0*clock() / CLOCKS_PER_SEC <<"s.\n";
#endif   
}
template<typename T1, typename T2>
T1 powz(T1 X,T2 B)
{
    ll A = X;
    ll res=1;
        A%=mod; 
        assert(B>=0); 
    for( ; B ; B>>=1){
        if(B&1)res=res*A%mod;
        A= A*A%mod;
    }
    return res;
}


Measured memory_bytes: 12652
n,a,b=map(int,input().split())
mod=10**9+7
s=1
for i in range(a):
  s=s*(n-i)%mod
  s=s*pow((i+1),mod-2,mod)%mod
t=1
for i in range(b):
  t=t*(n-i)%mod
  t=t*pow((i+1),mod-2,mod)%mod
print((2**n-1-s-t)%mod)

Measured memory_bytes: 281420
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int min = 0;
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            int j = sc.nextInt();//当前数
            if (i == 0) {
                min = j;
            }else{
                max=Math.max(max,j-min);
                min=Math.min(min,j);
            }
        }
        System.out.println(max);
    }}


Measured memory_bytes: 98752
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue}

object Main extends App {

  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val T1, T2 = in.next().toLong
  val A1, A2 = in.next().toLong
  val B1, B2 = in.next().toLong


  //
  val a1 = A1 * T1
  val a2 = A2 * T2

  val b1 = B1 * T1
  val b2 = B2 * T2

  val asum = a1 + a2
  val bsum = b1 + b2
  
  val hoge = (a1 > b1)
  val fuga = (a2 > b2)

  if (asum == bsum) {
    println("infinity")
  }
  else if (hoge == fuga) {
    println(0)
  }
  else {

    val c1 = (a1 - b1).abs
    val c2 = (a2 - b2).abs

    val c3 = (c1 - c2).abs

    if (c1 > c2) {
      println(0)
    }
    else {
      var ans = (c1 / c3) * 2

      if (c1 % c3 != 0)
        ans += 1

      println(ans)
    }
  }
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.deep))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}



Measured memory_bytes: 25552
#include<stdio.h>


int main(){
int n;
int a,b,c,d;
int count=0;

while(scanf("%d",&n)!=EOF){
count=0;
for(a=0;a<10;a++){
 for(b=0;b<10;b++){
  for(c=0;c<10;c++){
   for(d=0;d<10;d++){if(a+b+c+d==n)count++;}}}}

printf("%d\n",count);
}
return 0;
}

Measured memory_bytes: 1684
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                           \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
  cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

namespace number_theory {
vector<int> primes;
void init(int n) {
  primes.push_back(2);
  bool is_prime[n + 1];
  fill(is_prime, is_prime + n + 1, true);
  for (long long p = 3; p <= n; p += 2)
    if (is_prime[p]) {
      primes.push_back(p);
      for (long long i = p * p; i <= n; i += p) is_prime[i] = false;
    }
}
// f -> g s.t. g(n) = sum_{m|n} f(m)
template <typename T>
void divisor_zeta(vector<T> &f) {
  int n = f.size();
  for (int p : primes) {
    if (p > n) break;
    for (int i = 1; p * i < n; i++) f[p * i] += f[i];
  }
}
// f -> h s.t. f(n) = sum_{m|n} h(m)
template <typename T>
void divisor_mobius(vector<T> &f) {
  int n = f.size();
  for (int p : primes) {
    if (p > n) break;
    for (int i = (n - 1) / p; i > 0; i--) f[p * i] -= f[i];
  }
}
// get table of Mobius function
template <typename T = int>
vector<T> get_mu(int n) {
  vector<T> f(n + 1, T(0));
  f[1] = T(1);
  divisor_mobius(f);
  return f;
}
// get table of Euler's totient function
template <typename T = int>
vector<T> get_phi(int n) {
  vector<T> f(n + 1);
  iota(f.begin(), f.end(), 0);
  divisor_mobius(f);
  return f;
}
// get table of number-of-divisors function
template <typename T = int>
vector<T> get_d(int n) {
  vector<T> f(n + 1, 1);
  divisor_zeta(f);
  return f;
}
// get table of sum-of-divisors function
template <typename T = int>
vector<T> get_sigma(int n) {
  vector<T> f(n + 1);
  iota(f.begin(), f.end(), 0);
  divisor_zeta(f);
  return f;
}
template <typename T>
static vector<T> lcm_convolution(vector<T> a, vector<T> b) {
  int n = max(a.size(), b.size());
  a.resize(n);
  b.resize(n);
  divisor_zeta(a);
  divisor_zeta(b);
  for (int i = 0; i < n; i++) a[i] *= b[i];
  divisor_mobius(a);
  return a;
}
// f -> g s.t. g(n) = sum_{n|m} f(m)
template <typename T>
static void multiple_zeta(vector<T> &f) {
  int n = f.size();
  for (int p : primes) {
    if (p > n) break;
    for (int i = (n - 1) / p; i > 0; i--) f[i] += f[p * i];
  }
}
// f -> h s.t. f(n) = sum_{n|m} h(m)
template <typename T>
static void multiple_mobius(vector<T> &f) {
  int n = f.size();
  for (int p : primes) {
    if (p > n) break;
    for (int i = 1; p * i < n; i++) f[i] -= f[p * i];
  }
}
template <typename T>
static vector<T> gcd_convolution(vector<T> a, vector<T> b) {
  int n = max(a.size(), b.size());
  a.resize(n);
  b.resize(n);
  multiple_zeta(a);
  multiple_zeta(b);
  for (int i = 0; i < n; i++) a[i] *= b[i];
  multiple_mobius(a);
  return a;
}
}  // namespace number_theory

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  using namespace number_theory;
  int N;
  cin >> N;
  init(N);
  auto f = get_d<int>(N);
  long long ans = 0;
  for (long long i = 1; i <= N; i++) {
    ans += f[i] * i;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 54900
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static void Swap<T>(ref T a, ref T b)
    {
	var t = a;
	a = b;
	b = t;
    }

    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class UnionFind
{
    private int[] d;

    public UnionFind(int n)
    {
	d = new int[n];
	for (int i = 0; i < n; i++){ d[i] = -1; }
    }

    public int Find(int x)
    {
	if (d[x] < 0){ return x; }
	return d[x] = Find(d[x]);
    }

    public void Unite(int x, int y)
    {
	x = Find(x); y = Find(y);
	if (x == y){ return; }
	if (d[x] > d[y]){ Swap(ref x, ref y); }
	d[x] += d[y];
	d[y] = x;
    }

    public bool Same(int x, int y){ return Find(x) == Find(y); }
    public int Size(int x){ return -d[Find(x)]; }
}

class Program
{
    public static void Main()
    {
	var tmp = ReadIntArray();
	int n = tmp[0], k = tmp[1], l = tmp[2];

	UnionFind uf1 = new UnionFind(n+1);
	
	for (int i = 0; i < k; i++)
	{
	    tmp = ReadIntArray();
	    int p = tmp[0], q=tmp[1];
	    uf1.Unite(p, q);
	}

	UnionFind uf2 = new UnionFind(n+1);

	for (int i = 0; i < l; i++)
	{
	    tmp = ReadIntArray();
	    int r = tmp[0], s = tmp[1];
	    uf2.Unite(r,s);
	}

	var dic = new Dictionary<Tuple<int,int>,int>();
	
	for (int i = 1; i <= n; i++)
	{
	    var pair = Tuple.Create(uf1.Find(i), uf2.Find(i));
	    if (dic.ContainsKey(pair)){ dic[pair]++; }
	    else { dic.Add(pair, 1); }
	}

	for (int i = 1; i <= n; i++)
	{
	    var pair = Tuple.Create(uf1.Find(i), uf2.Find(i));
	    Write(dic[pair]);
	    if (i!=n){ Write(" "); }
	}
	WriteLine("");
    }
}


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

using namespace std;

int main()
{
    //system("chcp 65001");

    int A,B,N;
    cin >> N;

    if(N == 1)
    {
        cout << "Hello World";
        goto end;
    }
    cin >> A >> B;
    if(N == 2)
    {
        cout << A + B;
    }
    end:
    //cout << N;

    return 0;
}

Measured memory_bytes: 256
//Radhe Radhe
#include<bits/stdc++.h>
#define godspeed  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define rep1(i,a,b)    for(ll i=a; i<=b; i++)
#define repVect(i,n)    for(ll i=0; i<sum.size(); i++)
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
#define yes cout<<"YES"<<'\n'
#define no cout<<"NO"<<'\n'
using namespace std;

int main()
{
    godspeed
    ll  i,j,k,l,a,v,b,w,t;
    string s;
    cin>>a>>v>>b>>w>>t;
    b=abs(b-a)+(w*t);
    a=v*t;
    (a>=b)?yes:no;




    return 0;
}





Measured memory_bytes: 3592
#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 <cmath>         // sqrt
#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 <bits/stdc++.h> // isupper, islower, isdigit, toupper, tolower
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, n) for (int i = (a); i < (n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pl;
typedef pair<int, int> P;
typedef tuple<ll, ll, string> Tlls;

// Greatest Common Divisor (最大公約数)
ll gcd(ll a, ll b)
{
  // Eucledean algorithm
  while (a)
  {
    if (a < b)
    {
      std::swap(a, b);
    }
    a %= b;
  }
  return b;
}

// Least Common Multiple 最小公倍数
ll lcm(ll a, ll b)
{
  return a / gcd(a, b) * b;
}

// key: value of prime factor素因数分解
// value: number of prime factor
map<ll, ll> prime_factorization(ll n)
{
  map<ll, ll> prime_factors;
  for (ll i = 2; i * i <= n; i++)
  {
    while (n % i == 0)
    {
      prime_factors[i]++;
      n /= i;
    }
  }
  if (n != 1)
    prime_factors[n] = 1;
  return prime_factors;
}

// 約数リスト約数の列挙
vector<ll> get_divisors(const ll n)
{
  vector<ll> divs;
  for (ll i = 1; i < (ll)sqrt((ld)n) + 1; i++)
  {
    if (n % i == 0)
    {
      divs.push_back(i);
      if (i != n / i)
      {
        divs.push_back(n / i);
      }
    }
  }

  // 必要に応じてソート
  // sort(divs.begin(), divs.end());

  return divs;
}

int main()
{
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  rep(i, N)
  {
    cin >> A.at(i);
  }
  vector<ll> S;
  vector<ll> ORD(N + 1, -1);
  ll C = 1;
  ll L = 0;

  {
    ll v = 1;
    while (ORD.at(v) == -1)
    {
      ORD.at(v) = S.size();
      S.push_back(v);
      v = A.at(v - 1);
    }
    C = S.size() - ORD.at(v);
    L = ORD.at(v);
  }

  if (K < L)
  {
    cout << S.at(K) << endl;
  }
  else
  {
    K -= L;
    K %= C;
    cout << S.at(L + K) << endl;
  }
  return 0;
}


Measured memory_bytes: 8440
#include<stdio.h>

int main(void)
{
	unsigned long long n, m, s;
	
	scanf("%llu%llu", &n, &m);
	if (m <= 2 * n)
	    s = m / 2;
	else
	    s = n + (m - 2 * n) / 4;
	printf("%llu\n", s);
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef long long ll;
const int MAX_N = 100000000;

int prime[MAX_N];        
bool is_prime[MAX_N + 1];  

int sieve(int n){
    int p = 0;
    rep(i, n+1) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for(int i=2; i<=n; i++){
        if(is_prime[i]){
            prime[p++] = i;
            for(int j=2*i; j<=n; j+=i) is_prime[j] = false;
        }
    }
    return p;
}


int main() {
  int Q;
  cin >> Q;
  int l[Q],r[Q];
  rep(i,Q) cin>>l[i]>>r[i];
  sieve(100001);
  int ans[100001]={0};
  rep(i,100001){
      if(i) ans[i]+=ans[i-1];
      if(is_prime[i]==true&&is_prime[(i+1)/2]==true) ans[i]++;
  }
  rep(i,Q){
    cout<<ans[r[i]]-ans[l[i]-1]<<endl;
  }
}


Measured memory_bytes: 3968
#include <iostream>
#include <algorithm>
#include <vector>
#include <bitset>
#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;
int main()
{
  int l;
  cin >> l;
  int s;
  rep(i,20){
    if((l>>i)&1){
      s = i+1;
    }
  }
  vector<pair<pair<int,int>,int>> res;
  rep1(i,s-1){
    res.push_back({{i,i+1},0});
    res.push_back({{i,i+1},(int)(1<<(i-1))}); 
  }
  int d = (1<<(s-1));
  rep(i,s-1){
    if((l>>i)&1){
      res.push_back({{i+1,s},d});
      d += (1<<i);
    }
  }
  
  cout << s << " " << (int)res.size() << "\n";
  rep(i,res.size()){
    cout << res[i].first.first << " " << res[i].first.second << " " << res[i].second << "\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vector<int> abox,bbox,cbox;
    for(int i=0;i<a;i++){
        int temp;
        cin>>temp;
        abox.push_back(temp);
    }
    for(int i=0;i<b;i++){
        int temp;
        cin>>temp;
        bbox.push_back(temp);
    }
    for(int i=0;i<c;i++){
        int temp;
        cin>>temp;
        cbox.push_back(temp);
    }
    sort(abox.begin(),abox.end());  
    sort(bbox.begin(),bbox.end());  
    sort(cbox.begin(),cbox.end());
    
    vector<int> total_eaten;
    for(int i=0;i<x;i++){
        total_eaten.push_back(abox.back());
        abox.pop_back();
    }
    for(int i=0;i<y;i++){
        total_eaten.push_back(bbox.back());
        bbox.pop_back();
    }
    for(int i=0;i<c;i++){
        total_eaten.push_back(cbox.back());
        cbox.pop_back();
    }
    sort(total_eaten.begin(),total_eaten.end());
    reverse(total_eaten.begin(),total_eaten.end());
    ll sum=0;
    for(int i=0;i<x+y;i++){
        sum+=total_eaten[i];
    }
    
    cout<<sum<<endl;

}

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

using namespace std;


#define ll              long long
#define pb              push_back
#define nn           cout << "\n";


ll dp[100000],ht[100000];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t,a,b,i,j,c,d,e,f,n,k,m,w;

    memset(dp,0,sizeof(dp));

    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a;
        ht[i]=a;

    }

    dp[n]=0;dp[n+1]=10000000;ht[n+1]=10000000;
    for(i=n-1;i>=1;i--)
    {
        
        dp[i]=min((dp[i+1]+abs(ht[i]-ht[i+1])),(dp[i+2]+abs(ht[i]-ht[i+2])));
    }

    cout<<dp[1];
    return 0;
}


Measured memory_bytes: 5180
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s,a;
	cin>>s;
	int i,j=0,k=0,p=0;
	a={"keyence"};
	for (i=0;i<7;i++,p++)
	{
		if (s[i]!=a[p])
		{
			j=1;
			break;
		}
	}
	p=0;
	for (i=s.length()-7;i<s.length();i++,p++)
	{
		if (s[i]!=a[p])
		{
			k=1;
			break;
		}
	}
	if (!j||!k)
	cout<<"YES"<<endl;
	else
	{
		j=0;
		for (i=0;i<7;i++,j++)
		{
			if (s[i]==a[j])
			continue;
			else
			{
				k=i;
				break;
			}
		}
		for (i=s.length()-(7-k);i<s.length();i++,j++)
		{
			p=1;
			if(a[j]!=s[i])
			{
				p=0;
				break;
			}
		 }
		 if (p==1)
		 cout<<"YES"<<endl;
		 else
		 cout<<"NO"<<endl; 
	}
}

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

using namespace std;
using ll  = long long;
using ii  = pair < int , int >;
using i3  = pair < int , ii >;
using vi  = vector < int >;
using vii = vector < ii >;
using vi3 = vector < i3 >;

const int N = 110 , M = 1e5 + 5;
const ll INF = 1e12;
const double eps = 1e-9 , PI = acos(-1);

int n , W;
int w[N];
ll  v[N];
ll mem[N][M];

ll dp(int i , int sum){
    if(sum > W)return -INF;
    if(i == n )return 0;

    ll &ret = mem[i][sum];
    if(ret != -1)return ret;

    return ret = max(dp(i+1 , sum) , v[i] + dp(i+1 , sum + w[i]));
}

void solve(){
    scanf("%d %d" , &n , &W);
    for(int i = 0 ; i < n ; i ++){
        scanf("%d %lld" , &w[i] , &v[i]);
    }

    memset(mem , -1 , sizeof mem);
    printf("%lld\n" , dp(0 , 0));
}

main(){
    int t = 1;
    //scanf("%d" , &t);

    while( t -- ){
            solve();
    }

    return 0;
}






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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

LL n, x;

int main() {
    cin >> n;
    LL sum = 0;
    x = 0;
    LL mul = 1;
    while (true) {
        if (x + 9 * mul <= n) {
            x += 9 * mul;
            sum += 9;
            mul *= 10;
            continue;
        }
        while (x + mul <= n) {
            x += mul;
            sum += 1;
        }
        break;
    }
    cout << sum << endl;
    return 0;
}


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

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

ii arr[200010];
ii interval[200010];
int mini[200010];
int maxi[200010];
int presum[200010];

int mod=1000000007;

int main() {
    //freopen("hi.txt","r",stdin);
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d%d",&arr[i].second,&arr[i].first);
    }
    sort(arr,arr+n);
    mini[n-1]=arr[n-1].second;
    maxi[0]=arr[0].second;
    for(int i=n-2;i>=0;i--){
        mini[i]=min(arr[i].second,mini[i+1]);
    }
    for(int i=1;i<n;i++){
        maxi[i]=max(arr[i].second,maxi[i-1]);
    }
    //for(int i=0;i<n;i++)printf("%d ",arr[i].second);printf("\n");
    for(int i=0;i<n;i++){
        interval[i].second=upper_bound(mini,mini+n,arr[i].second)-mini-1;
        interval[i].first=lower_bound(maxi,maxi+n,arr[i].second)-maxi;
    }
    sort(interval,interval+n);
    interval[n]=ii(n,n);
    int pos=-1;
    presum[0]=1;
    for(int i=1;i<=n;i++){
        while(interval[i].first!=0 && (pos==-1 || interval[pos].second<interval[i].first-1)){
            pos++;
        }
        if(pos==-1){
            presum[i]=presum[i-1]+1;
        }
        else{
            if(pos!=0)
                presum[i]=presum[i-1]-presum[pos-1];
            else
                presum[i]=presum[i-1];
        }
        presum[i]%=mod;
        presum[i]+=presum[i-1];
        presum[i]%=mod;
    }
    printf("%d",((presum[n]-presum[n-1])%mod+mod)%mod);
}


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

class DisjointSet{
    public:
        vector<int> rank, p;

        DisjointSet(){}
        DisjointSet(int size){
            rank.resize(size, 0);
            p.resize(size, 0);
            for(int i = 0; i < size; i++) makeSet(i);
        }

        void makeSet(int x){
            p[x] = x;
            rank[x] = 0;
        }//グループを作る

        bool same(int x, int y){
            return findSet(x) == findSet(y); //x,yが同じグループに属しているか判定
        }

        void unite(int x, int y){
            link(findSet(x), findSet(y));
        }//xとyの属するsetを結合する

        void link(int x, int y){
            if(rank[x] > rank[y]){
                p[y] = x;
            }else{
                p[x] = y;
                if( rank[x] == rank[y]){
                    rank[y]++;
                }
            }
        }//rankが大きい方の下にrankが小さいものをくっつける

        int findSet(int x){
            if(x != p[x]){
                p[x] = findSet(p[x]);
            }
            return p[x];
        }//再帰的にxの親を見つけている
};

int main(){
    int n, m, t, x, y;
    cin >> n >> m;
    vector<int> p;
    DisjointSet ds = DisjointSet(n);
    for(int i = 0; i < n; i++){
        cin >> t;
        p.push_back(t-1);
    }
    for(int i = 0; i < m; i++){
        cin >> x >> y;
        if(ds.same(x-1,y-1) != true){
            ds.unite(x-1,y-1);
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(ds.same(p[i], i) == true){
            ans++;
        }
    }

    cout << ans << endl;

}

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

left = 0
right = 0
out = ""
for i in range(len(s)):
    if s[i] == "(":
        left += 1
        out += "("
    else:
        right += 1
        out += ")"
        if right > left:
            out = "(" + out
            left += 1
while left != right:
    if right > left:
        left += 1
        out = "(" + out
    else:
        right += 1
        out += ")"
print(out)

Measured memory_bytes: 3064
// From youtube - atcoder abc142 f
// https://www.youtube.com/watch?v=l4pTJy13sbM

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

ll powmod(ll x, ll n) { // like pow(x, n)
  ll r = 1;
  while (n) {
    if (n & 1) {
      r = r * x % MOD;
    }
    x = x * x % MOD;
    n >>= 1;
  }
  return r;
}

vector< vector<int> > graph;
vector<int> state;
vector<int> vs;

bool dfs(int v) {
  if (state[v] == 1) { // intermediate
    vs.erase(vs.begin(), find(all(vs), v)); // remove all elements before v.
    return true;
  }
  if (state[v] == -1) { // Already visited
    return false;
  }
  // state[v] == 0
  vs.push_back(v);
  state[v] = 1;
  for (int u : graph[v]) {
    if (dfs(u)) { return true; }
  }
  state[v] = -1;
  vs.pop_back();
  return false;
}

int N, M;

void solve() {
  vector<int> nxt(N), visited(N), erased(N, 1);
  rep(i, vs.size()) {
    int v = vs[i];
    int u = vs[(i+1)%vs.size()];
    nxt[v] = u;
    erased[v] = 0;
  }
  int v = vs[0];
  while (!visited[v]) {
    for (int u : graph[v]) {
      if (erased[u]) { continue; }
      int nv = v;
      while (nxt[nv] != u) {
        nv = nxt[nv];
        erased[nv] = 1;
      }
      nxt[v] = u;
    }
    visited[v] = 1;
    v = nxt[v];
  }

  vector<int> ans;
  int sv = v;
  while (true) {
    ans.push_back(v);
    v = nxt[v];
    if (v == sv) { break; }
  }
  cout << ans.size() << endl;
  for (auto v : ans) {
    cout << v + 1 << endl;
  }
}

int main(int argc, char** argv) {
  cin >> N >> M;
  graph.resize(N);
  rep(i, M) {
    int A, B;
    cin >> A >> B;
    --A; --B; // 0-indexed
    graph[A].push_back(B);
  }

  state.resize(N);
  rep(i, N) {
    if (!state[i]) {
      if (dfs(i)) {
        // for (int v : vs) { cout << v << endl; }
        solve();
        return 0;
      }
    }
  }

  cout << -1 << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    double n; cin >> n;
    double before = ceil(n * 100.00 / 108.00);

    if (floor(before * 1.08) == n) {
        cout << before << endl;
    } else {
        cout << ":(" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
class Main {
	public static void main (String[] args) throws java.lang.Exception {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt();
		System.out.println((a * b) + " " + (a * 2 + b * 2));
	}
}

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

using namespace std;

int main()
{
   int n,d,x,a[101],i,j,sum=0;
   cin>>n>>d>>x;
   for(i=0;i<n;i++){
    cin>>a[i];
   }
   for(i=0;i<n;i++){
    for(j=1;j<=d;j++){
        if((j*a[i]+1)<=d) sum+=1;
        else break;
    }
   }
   cout<<n+sum+x;
    return 0;
}


Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
const i64 MOD = 1e9+7;
const i64 INF = 1e18+7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}

template <i64 mod = MOD>
struct ModInt{
    i64 p;

    ModInt() : p(0){}
    ModInt(i64 x){p = x >= 0 ? x % mod : x + (-x + mod - 1) / mod * mod;}

    ModInt& operator+=(const ModInt& y){p = p + *y - ((p + *y) >= mod ? mod : 0); return *this;}
    ModInt& operator-=(const ModInt& y){p = p - *y + (p - *y < 0 ? mod : 0); return *this;}
    ModInt& operator*=(const ModInt& y){p = (p * *y) % mod; return *this;}
    ModInt& operator%=(const ModInt& y){if(y)p %= *y; return *this;}

    ModInt operator+(const ModInt& y) const{ModInt x = *this; return x += y;}
    ModInt operator-(const ModInt& y) const{ModInt x = *this; return x -= y;}
    ModInt operator*(const ModInt& y) const{ModInt x = *this; return x *= y;}
    ModInt operator%(const ModInt& y) const{ModInt x = *this; return x %= y;}

    friend ostream& operator<<(ostream& stream, const ModInt<mod>& x){
        stream << *x;
        return stream;
    }

    friend ostream& operator>>(ostream& stream, const ModInt<mod>& x){
        stream >> *x;
        return stream;
    }

    ModInt& operator++(){p = (p + 1) % mod; return *this;}
    ModInt& operator--(){p = (p - 1 + mod) % mod; return *this;}

    bool operator==(const ModInt& y) const{return p == *y;}
    bool operator!=(const ModInt& y) const{return p != *y;}

    const i64& operator*() const{return p;}
    i64& operator*(){return p;}

};

using mint = ModInt<1000000>;


signed main(){
    int n;
    cin >> n;
    vector<int> a(n - 1), b(n - 1);
    vector<vector<int>> path_list(n);
    vector<int> lose(n, false);
    for(int i = 0; i < n - 1; ++i){
        cin >> a[i] >> b[i];
        --a[i], --b[i];
        lose[b[i]] = true;
        path_list[a[i]].emplace_back(b[i]);
    }
    int par = -1;
    for(int i = 0; i < n; ++i){
        if(!lose[i])
            par = i;
    }

    vector<vector<mint>> ncr(n + 1);
    ncr[0].resize(1);
    ncr[0][0] = 1;
    for(int i = 0; i < n; ++i){
        ncr[i + 1].resize(i + 2);
        for(int j = 0; j <= i; ++j){
            ncr[i + 1][j] += ncr[i][j];
            ncr[i + 1][j + 1] += ncr[i][j];
        }
    }

    function<pair<mint,int>(int)> f = [&](int x){
        mint ans = 1;
        vector<pair<mint,int>> res;
        for(auto& p : path_list[x])
            res.emplace_back(f(p));
        int sum = 0;
        for(auto& p : res){
            ans *= p.first;
            sum += p.second;
        }
        int sum_tmp = sum + 1;
        for(auto& p : res){
            ans *= ncr[sum][p.second];
            sum -= p.second;
        }
        return make_pair(ans, sum_tmp);
    };
    cout << f(par).first << endl;
}



Measured memory_bytes: 6992
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lf else if

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=15;
const int p=1e9+7;

int Pow(int a,int b){
	int res=1;
	for (;b;b>>=1,a=1ll*a*a%p) if (b&1) res=1ll*res*a%p;
	return res;
}

int g[N][1<<N],w[N][1<<N],f[1<<N],chk[1<<N];
int A[N][N];
int n,m,x,y;

int main(){
	n=IN();m=IN();
	For(i,0,m){
		x=IN()-1,y=IN()-1;
		A[x][y]=1;
	}
	For(i,0,n) For(t,0,1<<n)
		if (!(t>>i&1)){
			int c=0;
			For(j,0,n) if ((t>>j&1)&&A[i][j]) c++;
			g[i][t]=(1<<c)-1;
			w[i][t]=1<<c;
		}
	For(t,1,1<<n) chk[t]=((t&1)==(t>>1&1));
	For(s,1,1<<n) if (chk[s]){
		f[s]=1;
		for (int u=(s-1)&s;u;u=(u-1)&s)
			if (chk[u]&&chk[s^u]){
				int tmp=1;
				For(i,0,n)
					if (u>>i&1){
						tmp=1ll*tmp*g[i][s^u]%p;
					} lf (s>>i&1){
						tmp=1ll*tmp*w[i][u]%p;
					}
				f[s]=(f[s]+1ll*tmp*f[u])%p;
			}
	}
	printf("%d\n",(Pow(2,m)-f[(1<<n)-1]+p)%p);
}

Measured memory_bytes: 4224
(let ((n (read))
      (k (read))
      (count 1)
      (temp 0)
      (ans 0))
  (loop for i from (1+ k) upto n
        do (setf ans (+ ans (* (floor (/ n i)) count)))
           ;; (format t "~A:~A  " i (* (floor (/ n i)) count))
           (setf temp (- (+ (mod n i) count (if (= k 0) 0 1)) i))
           (if (and (> temp 0) (not (= 0 (mod n i)))) (setf ans (+ ans temp)))
           ;; (format t "~A::~A  ~A~%" i temp (mod n i))
           (setf count (1+ count)))
  (format t "~A~%" ans))

Measured memory_bytes: 22248
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

m,n = mi()

mod = 1000000007

def modpow(m,n,mod=1000000007):
    res = 1
    while n>0:
        if n&1: res = res * m % mod
        m = m * m % mod
        n >>= 1
    return res

ans = modpow(m,n)

print(ans)


Measured memory_bytes: 5600
n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

map = Hash.new(0)
a.each do |x|
  map[x] += 1
end

_k = map.keys.size
c = map.sort {|a, b| a[1] <=> b[1] }
ans = 0
while _k > k do 
  ans += c.shift[1]
  _k -= 1
end

puts ans


Measured memory_bytes: 40932
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
typedef long long ll;
typedef long double ld;
#define trace(x)  cerr << #x << ": " << x << endl;
const ll N=5*1e5+5;ll mod=998244353;
vector<ll> last(N,-1);
void update(ll i,ll val, ll bit[],ll n)
{
	for(;i<=n;i+=i&-i)
		bit[i]+=val;
}
int sum(ll i,ll bit[], ll n)
{
	ll s=0;
	for(;i>0;i-=i&-i)
	{
		s+=bit[i];
	}
	return s;
}
void solve(ll a[],ll n,vector<pair<pair<ll,ll>,ll>>query,ll q)
{
	ll bit[n+1];
	memset(bit,0,sizeof(bit));
	vector<ll> ans(q);ll cur=0;
	for(ll i=0;i<n;i++)
	{
		if(last[a[i]]!=-1)
		{
			update(last[a[i]]+1,-1,bit,n);
		}
		last[a[i]]=i;
		update(i+1,1,bit,n);
		while(cur<q && query[cur].first.first==i)
		{
			ans[query[cur].second]=sum(query[cur].first.first+1,bit,n)-sum(query[cur].first.second,bit,n);
			cur++;
		}
	}
	for(ll i=0;i<q;i++)cout<<ans[i]<<"\n";
}
int main()
{
	ll n;cin>>n;ll q;cin>>q;
	ll a[n];
	for(ll i=0;i<n;i++)cin>>a[i];
	vector<pair<pair<ll,ll>,ll>>query(q);
	for(ll i=0;i<q;i++)
	{
		ll l,r;cin>>l>>r;l--;r--;
		query[i].first.first=r;query[i].first.second=l;query[i].second=i;
	}
	sort(query.begin(),query.end());
	solve(a,n,query,q);

}

Measured memory_bytes: 42812
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();

        for(int i = 0; i < m; i++){
            n -= sc.nextInt();
        }

        System.out.println(n >= 0 ? n : -1);
    }
}


Measured memory_bytes: 46232
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

#ifdef WIN32
	#define LL "%I64d"
#else
	#define LL "%lld"
#endif

#ifdef CT
	#define debug(...) printf(__VA_ARGS__)
	#define setfile() 
#else
	#define debug(...)
	#define filename ""
	#define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout)
#endif

#define R register
#define getc() (_S == _T && (_T = (_S = _B) + fread(_B, 1, 1 << 15, stdin), _S == _T) ? EOF : *_S++)
#define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
#define cabs(_x) ((_x) < 0 ? (- (_x)) : (_x))
char _B[1 << 15], *_S = _B, *_T = _B;
inline int F()
{
	R char ch; R int cnt = 0; R bool minus = 0;
	while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
	ch == '-' ? minus = 1 : cnt = ch - '0';
	while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
	return minus ? -cnt : cnt;
}
const char s[] = "CODEFESTIVAL2016";
char ss[16];
int main()
{
//	setfile();
	scanf("%s", ss);
	R int ans = 0;
	for (R int i = 0; i < 16; ++i) ans += s[i] != ss[i];
	printf("%d\n", ans );
	return 0;
}


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

using namespace std;
int main()
{
    int r,g,b,n;
    cin>>r>>g>>b>>n;
    long long ans=0;
    for(int i=0;i<=n/r;i++){
        int temp=n-i*r;
        for(int j=0;j<=temp/g;j++){
            int temp2=temp-j*g;
            if(temp2%b==0){
                ans++;
                //cout<<i<<" "<<j<<endl;
            }
        }
    }
    cout<<ans;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
    char a[5];
    scanf("%s", a);
    cout << (a[0] == a[1] || a[1] == a[2] || a[2] == a[3] ? "Bad" : "Good") << endl;
}

Measured memory_bytes: 256
import math as mt
n=int(input())
x=7%n
ten=1
for i in range(n):
  if x%n==0:
    print(i+1)
    break
  ten=((ten%n)*(10%n))%n
  x+=((ten%n)*(7%n))%n
else:
  if n==1:
    print(1)
  else:
    print(-1)

Measured memory_bytes: 63760
#include<stdio.h>
#include<math.h>
int main()
{
	int s,j;
	int i[101];
	i[0]=1;
	while(scanf("%d",&s)!=EOF)
	{
		int c=0;
		for(j=1;j<=s;j++)
		{
			i[j]=pow(2,j);
			if(i[j]>s)
			{
				c=i[j-1];
				break;
			}
		}
		printf("%d\n",c);
	}
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);


int main(void)
{
    ll n,k;
    cin>>n>>k;
    cout<<n-k+1<<endl;
    return 0;
}

Measured memory_bytes: 3608
# coding: utf-8
N, D = map(int, input().split())
ans = 0
X = []
for i in range(N):
    x = list(map(int, input().split()))
    X.append(x[:])
for i in range(N - 1):
    for j in range(i+1, N):
        tmp = 0
        for k in range(D):
            tmp += (X[i][k] - X[j][k]) ** 2
        if int(tmp ** 0.5) == tmp ** 0.5:
            ans += 1
print(ans)

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a.at(i);
  sort(a.begin(), a.end());
  
  cout << a.at(n-1) -a.at(0) << endl;
}

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

int main(){
  int n;
  while(cin >> n, n){
    vector<double> s(n);
    for(int i=0; i<n; i++)
      cin >> s[i];

    double sum = accumulate(s.begin(), s.end(), 0);
    double sigma2 = 0;
    for(int i=0; i<n; i++)
      sigma2 += (sum - n*s[i]) * (sum - n*s[i]);
    sigma2 /= n*n*n;
    
    printf("%0.8f\n", sqrt(sigma2));
  }

  return 0;
}

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

const long long MOD = 1e9 + 7;

int main()
{
    vector<int> able(1001, 1);
    vector<int> P;
    for(int x = 2; x < 1001; ++x) {
        if(able[x]) {
            P.push_back(x);
            for(int k = 2; k * x < 1001; ++k) {
                able[k * x] = 0;
            }
        }
    }
    int N;
    cin >> N;
    map<int, long long> D;
    for(int x = 2; x < N + 1; ++x) {
        int r = x;
        int i = 0;
        while(r != 1) {
            if(r % P[i] == 0) {
                r /= P[i];
                ++D[P[i]];
            }else {
                ++i;
            }
        }
    }
    long long ans = 1;
    for(auto x: D) {
        ans = ans * (x.second + 1) % MOD;
    }
    cout << ans << endl;
}

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

int main(){
    stack<int> S;
    int a,b;
    string s;

    while(cin >> s){
        if(s.at(0)=='+'){
            a=S.top();
            S.pop();
            b=S.top();
            S.pop();
            S.push(a+b);
        }
        else if(s.at(0)=='-'){
            b=S.top();
            S.pop();
            a=S.top();
            S.pop();
            S.push(a-b);
        }
        else if(s.at(0)=='*'){
            a=S.top();
            S.pop();
            b=S.top();
            S.pop();
            S.push(a*b);
        }
        else{
            S.push(stoi(s));
        }
    }
    cout << S.top() << endl;
}


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

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

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

ll n;
ll a,b;

int main(){
    cin >> n >> a >> b;
    cout << min(n*a,b) << endl;
}

Measured memory_bytes: 256