akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int n,m,q; cin>>n>>m>>q;
    vector<vector<int>> rail(n,vector<int>(n,0));
    rep(i,m){
        int l,r; cin>>l>>r;
        rail[l-1][r-1]++;
    }
    if(n>1){
        rep(i,n-1) rail[i][i+1]+=rail[i][i]+rail[i+1][i+1];
    }
    for(int i=2;i<n;i++){
        rep(j,n-i){
            rail[j][j+i]+=rail[j][j+i-1]+rail[j+1][j+i]-rail[j+1][j+i-1];
        }
    }
    rep(i,q){
        int a,b; cin>>a>>b;
        cout<<rail[a-1][b-1]<<endl;
    }
}

Measured memory_bytes: 1920
# frozen_string_literal: true

m, d = gets.split.map(&:to_i)
cnt = 0

(1..m).each do |i|
  (1..d).each do |j|
    d1 = j / 10
    d2 = j % 10
    cnt += 1 if d1 * d2 == i && d1 >= 2 && d2 >= 2
  end
end

puts cnt

Measured memory_bytes: 1788
#include<bits/stdc++.h>
//typedef long long int ll;
using namespace std;
using ll = long long;
using ld = long double;
using Vc = vector <char>;
using Vs = vector <string>;
using Vll = vector <ll>;
using Vi = vector <int>;
using Sll = set <ll>;
using Ss = set <string>;
using Sc = set <char>;
using Si = set <int>;
using MiVi = map<int,Vi>;
using MllVll = map<ll,Vll>;
using Mllll = map<ll,ll>;
using Mii = map<int,int>;
using MllSll = map<ll,Sll>;
using Mlls = map<ll,string>;
using Pllll = pair<ll,ll>;
using Pii = pair<int,int>;


#define nl cout<<endl
#define ns cout<<" "
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
#define forAuto(i,x) for(auto i: x)
#define forRange(i,l,h) for(int i=l;i<h;i++)
#define all(x) x.begin(),x.end()
#define append push_back


void vsInput()
{
    #ifndef ONLINE_JUDGE
         freopen("input.txt","r",stdin);
         freopen("output.txt","w",stdout);
    #endif // ONLINE_JUDGE
}
template<class T1>
ll sum(T1 a){ll ans=0;forAuto(i,a)ans+=i;return ans;}

template<class T>
void printC(T a){forAuto(i,a)cout<<i<<" ";cout<<endl;}

template<class T1,class T2>
void printP(pair<T1,T2> i){cout<<"{"<<i.first<<",";cout<<i.second<<"} ";}

template<class T1,class T2>
void printG(map<T1,T2> a){forAuto(i,a){cout<<i.first<<" -> ";printC(i.second);}}

template<class T1,class T2>
void printWG(map<T1,T2> a){forAuto(i,a){cout<<i.first<<" -> ";forAuto(j,i.second)printP(j);nl;}}

void value() {}
template <class T1, class... T2>
void value(T1& var1, T2&... var2) { cin>>var1; value(var2...); }

void print() {}
template <class T1, class... T2>
constexpr void print(const T1& var1, const T2& ... var2) { cout<<var1;ns; print(var2...); }


template<class T1,class T2>
void printM(map<T1,T2> a){forAuto(i,a){cout<<i.first<<" -> ";cout<<i.second; nl;}}


#define CPN 700007
#define M 1000000007
//const int inf=1e18+5;


//----------------------------CODE----------------------------//
int dp[100002];
//int mn=1000000;
int frog(int a[],int n,int i,int k)
{
    int mn=INT_MAX,x;
    if(i==n-1)
        return 0;
    if(dp[i] != -1)
        return dp[i];
    for(int j=i+1;j<i+k+1;j++)
    {
        if(j<n)
        {
            x=abs(a[j]-a[i])+frog(a,n,j,k);
            mn=min(mn,x);
            
        }

    
    }
    return dp[i]=mn;
}


int main()
{
    memset(dp,-1,sizeof(dp));
    fast;
    //vsInput();
    int n,res,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    res=frog(a,n,0,k);

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


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

int main() {
  int a[3];
  for (auto &aa:a) {
    cin >> aa;
  }
  sort(a, a + 3);
  reverse(a, a + 3);
  cout << a[0] * 10 + a[1] + a[2] << endl;
  return 0;
}

Measured memory_bytes: 256
//aの各要素を{選ぶ, 選ばない}で, 数列bを作ってみる。 -> aは相異なるのでbは相異なる。
//-> bの順番(r!通り)によらず, _xor(b)は同じ値. (つまり, 各長さrについて, この作り方でhoge[r]通り作れたとすれば…
//答えはΣhoge[r] * r!になる。(選ぶ, 選ばない～でbを作る場合に必要な情報は [どこまで決めたか?, bの長さ, そこまでの_xor]の3つ。これでDPすればよい）
//余りとり忘れてた。つらい。

#include <iostream>
#define int long long
using namespace std;

int mod = 1000000007;
int n, k;
int a[100];
int fact[101];
int dp[101][101][256];	//dp[id][len][_xor] = count

signed main() {
	int id, len, _xor;
	
	cin >> n >> k;
	for (id = 0; id < n; id++) cin >> a[id];
	fact[0] = 1; for (len = 1; len <= n; len++) { fact[len] = (fact[len - 1] * len) % mod; }
	
	dp[0][0][0] = 1;
	for (id = 0; id < n; id++) {
		for (len = 0; len <= id; len++) {
			for (_xor = 0; _xor < 256; _xor++) {
				//使う
				dp[id + 1][len + 1][_xor ^ a[id]] += dp[id][len][_xor];
				dp[id + 1][len + 1][_xor ^ a[id]] %= mod;
				//使わない
				dp[id + 1][len][_xor] += dp[id][len][_xor];
				dp[id + 1][len][_xor] %= mod;
			}
		}
	}
	
	int ans = 0;
	for (len = 1; len <= n; len++) {
		ans += dp[n][len][k] * fact[len];
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10880
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		Set<Card> exists = new HashSet<Card>();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] tmp;
		String suite;
		int rank;
		for(int i = 0;i < n;i++){
			tmp = br.readLine().split(" ");
			suite = tmp[0];
			rank = Integer.parseInt(tmp[1]);
			exists.add(new Card(suite, rank));
		}
		
		String[] suiteTable = {"S", "H", "C", "D"};
		for(int i = 0;i < suiteTable.length;i++){
			for(int j = 1;j <= 13;j++){
				if(!exists.contains(new Card(suiteTable[i], j))){
					StringBuilder sb = new StringBuilder();
					sb.append(suiteTable[i]);
					sb.append(" ");
					sb.append(j);
					System.out.println(sb.toString());
					sb = null;
				}
			}
		}
	}

}

class Card {
	private String suite;
	private int rank;
	
	Card(){
		
	}
	
	Card(String suite, int rank){
		setSuite(suite);
		setRank(rank);
	}

	public String getSuite() {
		return suite;
	}

	public void setSuite(String suite) {
		this.suite = suite;
	}

	public int getRank() {
		return rank;
	}

	public void setRank(int rank) {
		this.rank = rank;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + rank;
		result = prime * result + ((suite == null) ? 0 : suite.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Card other = (Card) obj;
		if (rank != other.rank)
			return false;
		if (suite == null) {
			if (other.suite != null)
				return false;
		} else if (!suite.equals(other.suite))
			return false;
		return true;
	}

}

Measured memory_bytes: 17012
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end
def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n=gi
a=gsmi

putsend 1 if n==1

# bitが重ならなければいい
# 1が立ってる場所の配列
ar=[]
n.times do |i|
  l=a[i].bit_length
  ar2=[]
  l.times do |j|
    ar2<<j if a[i][j]==1
  end
  ar<<ar2
end

#puts ar.to_s

# 尺取り法で重なるパターンを数える
cnt=0
l=0
r=1
prev=ar[0]
while r<n do
  #puts "#{l},#{r}"
  if (prev & ar[r]).empty?
    prev = prev + ar[r]
    r+=1
  else
    prev = prev - ar[l]
    l+=1
    cnt+= n-1 -r + 1
    if l==r
      r+=1
      prev = prev + ar[l]
    end
  end
  #puts cnt
end

puts C(n,2)-cnt+n

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

int main(){
	int H,W;
	cin >> H >> W;
	string S[H];
	for(int i=0;i<H;i++){
		cin >> S[i];
	}
	int x[8]={0,1,0,-1,1,1,-1,-1};
	int y[8]={1,0,-1,0,1,-1,1,-1};
	
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(S[i].at(j)=='.'){
				int count=0;
				for(int k=0;k<8;k++){
					if(i+x[k]<0||H-1<i+x[k]||j+y[k]<0||W-1<j+y[k]) continue;
					if(S[i+x[k]].at(j+y[k])=='#') count++;
				}
				S[i].at(j)=char(count+'0');
			}
		}
	}
	
	for(int i=0;i<H;i++){
		cout << S[i] << endl;
	}
}

Measured memory_bytes: 256
// 解説前
#include <iostream>
#include <vector>

// ある頂点に対して行われる操作はそれ自身とその親に対するもののみである。
// => 深さ優先探索を用いて、頂点のカウンターの値を親から順に累積的に計算すれば良い。
int solve_D() {
  size_t N;  // 頂点の数
  size_t Q;  // 操作の回数
  std::cin >> N >> Q;

  // 辺で接続する頂点のリストを作る
  std::vector<std::vector<size_t>> tree(N);
  for (size_t i = 0; i < N - 1; ++i) {
    size_t a, b;
    std::cin >> a >> b;

    // 親子関係が降順である場合にも対応するため、a->bとb->aの両方を登録しておく。
    // 親子関係が逆順であった方は探索アルゴリズムの都合により無視されるので、
    // 結果としては余分な計算が増えるだけになる。
    tree[a - 1].push_back(b - 1);
    tree[b - 1].push_back(a - 1);
  }

  // カウンターに足す点数のリストを作る
  std::vector<uint64_t> scores(N);
  for (size_t i = 0; i < Q; ++i) {
    size_t p;
    uint64_t x;
    std::cin >> p >> x;
    scores[p - 1] += x;  // 同じ頂点に対する操作を合算しておく
  }

  // 頂点のカウンターの値を深さ優先で累積的に計算する
  std::vector<size_t> stack;
  stack.reserve(N);
  std::vector<bool> visited(N);
  std::vector<uint64_t> total_scores(N);

  stack.push_back(0);
  visited[0] = true;
  total_scores[0] = scores[0];

  while (true) {
    const auto v = stack.back();

    // 未訪問の子供に訪問する
    auto& children = tree[v];
    bool all_visited = true;
    while (!children.empty()) {
      const auto child = children.back();

      // 訪問済みの子供を再度チェックしないようにリストから除外する
      children.pop_back();

      // 子供が訪問済みでない場合
      if (!visited[child]) {
        // その子供にも訪問するためにスタックに積む
        stack.push_back(child);
        visited[child] = true;

        // その頂点のカウンターの値を親のカウンターの値を活用して計算する
        total_scores[child] = total_scores[v] + scores[child];

        all_visited = false;
        break;
      }
    }

    // すべての子供が訪問済みである場合
    if (all_visited) {
      // ひとつ前に戻る
      stack.pop_back();

      // すべてに訪問すれば終了
      if (stack.empty()) break;
    }
  }

  // 結果発表
  for (const auto score : total_scores) {
    std::cout << score << ' ';
  }

  return 0;
}

int main() {
  return solve_D();
}


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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

int main()
{
    int a,b,c,d,p;
    cin >>a >>b >>c >>d >>p;

    int x=a*p;
    int y=b;
    if(c<p) y+=d*(p-c);

    cout << min(x,y) << endl;
    
    return 0;
}

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

 
int main() {
  int N;
  cin >> N;
  vector<vector<double>> D(N,vector<double>(2));
  for (int i = 0; i < N; i++) cin >> D.at(i).at(0) >> D.at(i).at(1);
  
  vector<int> num(N,0);
  for (int i = 0; i < N; i++) num.at(i) = i;

  int c = 0;
  double res = 0; 
  do {

    for (int i = 1; i < N; i++) {
      double x = abs(D.at(num.at(i-1)).at(0) - D.at(num.at(i)).at(0));
      double y = abs(D.at(num.at(i-1)).at(1) - D.at(num.at(i)).at(1));
      res += sqrt(x*x + y*y);
    }
    c++;

  } while (next_permutation(num.begin(), num.end()));

  cout << fixed << setprecision(15) << res / c << endl;
  
  return 0;
}


Measured memory_bytes: 256
object Main extends App {
	
	override def main(args:Array[String]) = {
		val sc = new java.util.Scanner(System.in)
		
		Iterator.continually(new Scores(sc.nextInt,sc.nextInt,sc.nextInt)).
		takeWhile(_.isContinue).foreach{s => println(s.getGrade)}
	}
	
	case class Scores(val m:Int, val f:Int, val r:Int){
		val isContinue = !( m == -1 && f == -1 && r == -1 )

		val getGrade = (m,f,r) match{
			// ??????????¨??????????????¨????????????????????¬????????????´???????????? F???
			case (-1 , _ , _) | (_ , -1 , _ ) 
				=> "F"
			// ??????????¨???¨??????????¨????????¨??????°??? 80 ??\???????????°????????? A ???
			case (mm,ff,_) if mm + ff >= 80
				=> "A"
			// ??????????¨???¨??????????¨????????¨??????°??? 65 ??\??? 80 ??????????????°????????? B???
			case (mm,ff,_) if mm + ff >= 65
				=> "B"
			// ??????????¨???¨??????????¨????????¨??????°??? 50 ??\??? 65 ??????????????°????????? C???
			case (mm,ff,_) if mm + ff >= 50
				=> "C"
			// ??????????¨???¨??????????¨????????¨??????°??? 30 ??\??? 50 ??????????????°????????? D??? ???????????????????¨?????????°??? 50 ??\???????????°????????? C???
			case (mm,ff,rr) if mm + ff >= 30 && rr >= 50
				=> "C"
			case (mm,ff,_) if mm + ff >= 30
				=> "D"
			// ??????????¨???¨??????????¨????????¨??????°??? 30 ??????????????°????????? F
			case _
				=> "F"
		} 
	}
}

Measured memory_bytes: 45048
n, k = map(int, input().split())
a = list(map(int, input().split()))

ruiseki = [0] * (n + 1)
for i in range(n):
    ruiseki[i+1] = ruiseki[i] + a[i]

li = []
for i in range(n):
    for j in range(i, n):
        tmp = format(ruiseki[j + 1] - ruiseki[i], '040b')
        li.append(tmp)

for i in range(40):
    cnt = 0
    new_li = []
    for j in range(len(li)):
        if li[j][i] == "1":
            new_li.append(li[j])
            cnt += 1
    if cnt >= k:
        li = new_li[0:]

ans = 2**41 -1
for i in range(k):
    ans = ans & int(li[i], 2)
print(ans)

Measured memory_bytes: 56504
#include <stdio.h>
#include <stdlib.h>
#define int long long
#define p (int)(1e9 + 7)

typedef struct {
	int r;
	int c;
}pos;

int MOD(int a){
	a %= p;
	return a >= 0 ? a : a + p;
}

signed compair(const void *_a, const void *_b){
	pos a = *(pos *)_a, b = *(pos *)_b;
	int sub;
	if(a.r != b.r){
		sub = a.r - b.r;
	}
	else{
		sub = a.c - b.c;
	}
	if(sub < 0){
		return -1;
	}
	else if(sub == 0){
		return 0;
	}
	else{
		return 1;
	}
}

int *fact, *fact_inv;

int comb(int k, int l){
	if(k < 0 || l < 0){
		return 0;
	}
	else{
		return MOD(fact[k + l] * MOD(fact_inv[k] * fact_inv[l]));
	}
}

signed main(){
	int H, W, N, i, j;
	scanf("%lld%lld%lld", &H, &W, &N);
	pos *ps = (pos *)malloc(sizeof(pos) * (N + 1));
	for(i = 0; i < N; i++){
		scanf("%lld%lld", &ps[i].r, &ps[i].c);
	}
	ps[N] = (pos){H, W};
	qsort(ps, N + 1, sizeof(pos), compair);

	fact = (int *)malloc(sizeof(int) * (H + W + 1));
	fact[0] = 1;
	for(i = 1; i <= H + W; i++){
		fact[i] = MOD(fact[i - 1] * i);
	}
	fact_inv = (int *)malloc(sizeof(int) * (H + W + 1));
	fact_inv[0] = 1;
	fact_inv[1] = 1;
	for(i = 2; i <= H + W; i++){
		fact_inv[i] = MOD(-(p / i) * fact_inv[p % i]);
	}
	for(i = 1; i <= H + W; i++){
		fact_inv[i] = MOD(fact_inv[i - 1] * fact_inv[i]);
	}

	int *dp = (int *)malloc(sizeof(int) * (N + 1));
	for(i = 0; i <= N; i++){
		dp[i] = comb(ps[i].r - 1, ps[i].c - 1);
		for(j = 0; j < i; j++){
			if(ps[j].r <= ps[i].r && ps[j].c <= ps[i].c){
				dp[i] = MOD(dp[i] - dp[j] * comb(ps[i].r - ps[j].r, ps[i].c - ps[j].c));
			}
		}
	}
	printf("%lld\n", dp[N]);
	return 0;
}

Measured memory_bytes: 3452
import scala.io.StdIn._

object Main extends App {

  val Array(n,m) = readLine().split(" ").map(_.toInt)

  val mod = (1e9 + 7).toInt
  def solve() = {
    val diff = (n-m).abs
    val ans = if(diff > 1) 0L
    else if(diff > 0) {
      val larger = Math.max(n,m)
      val fact = factorial(larger-1)
      larger * fact % mod * fact
    } else {
      val fact = factorial(n)
      2 * fact % mod * fact
    }
    ans % mod
  }

  def factorial(num: Long): Long = {
    var i = 1
    var ans = 1L
    while(i <= num) {
      ans *= i
      ans %= mod
      i += 1
    }
    ans
  }

  println(solve())

}



Measured memory_bytes: 54684
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int N;
int main() {
	cin>>N;

	cout<<48-N<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
 
      // スペース区切りの整数の入力
      int ab = sc.nextInt();
      int bc = sc.nextInt();

      //三角形の面積計算
      int area = ab * bc / 2;
      
      //面積を出力
      System.out.println(area);
	}
}

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

int main() {
  string s;
  cin >> s;
  int i = s.size() - 1;
  if(s.at(i) == 's'){
    s += "es";
  }else{
    s += "s";
  }



  cout << s << endl;
}


Measured memory_bytes: 3628
using System;
using System.Linq;
using System.Collections.Generic;

namespace solve
{
    class Program
    {

        static void Main(string[] args)
        {
            while (true)
            {
                string s = Console.ReadLine();
                if (s == null) break;
                int n = int.Parse(s);
                int ans = 0;
                for (int a = 0; a <= 9; a++)
                {
                    for (int b = 0; b <= 9; b++)
                    {
                        for (int c = 0; c <= 9; c++)
                        {
                            for (int d = 0; d <= 9; d++)
                            {
                                if (a + b + c + d == n) ans++;
                            }
                        }
                    }
                }

                Console.WriteLine(ans);
            }

        }
    }
}



Measured memory_bytes: 19980
n = int(input())
a = list(map(int,input().split()))

abs_a = [abs(i) for i in a]
hu = [i for i in a if i < 0]
hunokazu = len(hu)
zero = 0 in a

if hunokazu%2 == 0 or zero == True:
    print(sum(abs_a))
else:
    abs_a_min = min(abs_a)
    print(sum(abs_a)-abs_a_min*2)


Measured memory_bytes: 15020
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <cstdio>
#include <cstdlib>

typedef long long int lld;
typedef unsigned long long int ulld;
const int mod = 1000000007;

using namespace std;

int main (void) {
	ios::sync_with_stdio (false);
	string s;
	cin >> s;
	if (s.find ("AC") != string::npos) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int main()
{
    she_told_me_dont_worry
    int n, a, b;
    cin>>n>>a>>b;
    int cst1 = n*a, cst2 = b; 
    cout<<MIN2(cst2, cst1);
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const inf = 1000000000

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	n, m := readInt(), readInt()
	dp := make([]int, 1<<uint(n))
	for i := 1; i < len(dp); i++ {
		dp[i] = inf
	}

	for i := 0; i < m; i++ {
		a, b := readInt(), readInt()
		c := 0
		for j := 0; j < b; j++ {
			c += 1 << uint(readInt()-1)
		}
		for j := 0; j < len(dp)-1; j++ {
			dp[j|c] = min(dp[j|c], dp[j]+a)
		}
	}
	if v := dp[len(dp)-1]; v == inf {
		fmt.Println(-1)
	} else {
		fmt.Println(v)
	}
}


Measured memory_bytes: 640
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        try (CustomReader in = new CustomReader()) {
            new Main().execute(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void execute(CustomReader in) throws IOException {
        int[] rgbn = in.readLineAsIntArray();
        int R = rgbn[0];
        int G = rgbn[1];
        int B = rgbn[2];
        int N = rgbn[3];

        int cnt = 0;
        for (int r = 0; r <= (N / R); r++) {
            for (int g = 0; g <= (N / G); g++) {
                int numB = N - (R * r) - (G * g);
                if (numB >= 0 && numB % B == 0) {
                    cnt++;
                }
            }
        }
        System.out.println(cnt);
    }

    static class CustomReader extends BufferedReader {

        public CustomReader() throws IOException {
            super(new InputStreamReader(System.in));
        }

        public int[] readLineAsIntArray() throws IOException {
            String[] strArray = this.readLine().split(" ");
            int[] intArray = new int[strArray.length];
            for (int i = 0, n = strArray.length; i < n; i++) {
                intArray[i] = Integer.parseInt(strArray[i]);
            }
            return intArray;
        }

        public int[][] readAsIntMatrix(int rows, int columns) throws IOException {
            int[][] matrix = new int[rows][columns];
            for (int i = 0; i < rows; i++) {
                String[] r = this.readLine().split(" ");
                for (int j = 0; j < columns; j++) {
                    matrix[i][j] = Integer.parseInt(r[j]);
                }
            }
            return matrix;
        }

    }
}

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

using namespace std;

template <class T> void mini(T &l, T r) {l = min(l, r);}
template <class T> void maxi(T &l, T r) {l = max(l, r);}

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(bool a) {
  return a ? "T" : "F";
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ll = long long;
using ld = long double;

const int N = 1e5 + 10, M = 2e5 + 10, B = 1e9 + 7;
const ll inf = (ll)1e18 + 10;

int n, m;
vector < pair <int, int> > e[N];
int U[M], V[M], D[M];
bool vis[N];
ll dis[2][N], ways[2][N];
int S, T;

void add(ll &x, ll y) {
  x = (x + y) % B;
  if (x < 0) x += B;
}

void dij(int s, ll dis[], ll ways[]) {
  priority_queue < pair <ll, int> > pq;
  fill_n(vis + 1, n, 0);
  fill_n(dis + 1, n, inf);
  fill_n(ways + 1, n, 0);
  dis[s] = 0;
  ways[s] = 1;
  pq.emplace(0, s);
  while (!pq.empty()) {
    auto t = pq.top();
    int u = t.second;
    pq.pop();
    if (vis[u]) continue;
    vis[u] = 1;
    for (auto ed : e[u]) {
      ll w = ed.second;
      int v = ed.first;
      if (dis[v] == dis[u] + w) {
        add(ways[v], ways[u]);
      } else if (dis[v] > dis[u] + w) {
        ways[v] = ways[u];
        dis[v] = dis[u] + w;
        pq.emplace(-dis[v], v);
      }
    }
  }
}

ll mul(ll x, ll y) {
  x = x * y % B;
  if (x < 0) x += B;
  return x;
}

void run() {
  cin >> n >> m;
  cin >> S >> T;
  for (int i = 1; i <= m; ++i) {
    int u, v, d;
    cin >> u >> v >> d;
    U[i] = u, V[i] = v, D[i] = d;
    e[u].emplace_back(v, d);
    e[v].emplace_back(u, d);
  }
  dij(S, dis[0], ways[0]);
  dij(T, dis[1], ways[1]);
  ll dd = dis[0][T];
  //pair <int, int> fenshu(dd, 2);
  ll ans = mul(ways[0][T], ways[1][S]);
  debug(ans);
  ll sub = 0;
  debug(dd);

  debug(e[2]);
  debug(e[3]);
  for (int j = 1; j <= n; ++j) {
    if (dis[0][j] * 2 == dd && dis[1][j] * 2 == dd) {
      ll tmp = mul(ways[0][j], ways[1][j]);
      add(sub, mul(tmp, tmp));
      debug(sub);
    debug(j);
    }
  }
  for (int i = 1; i <= m; ++i) {
    int u = U[i], v = V[i];
    if (dis[0][u] > dis[0][v]) swap(u, v);
    if (dis[0][u] * 2 < dd && dis[0][v] * 2 > dd && dis[0][u] + D[i] == dis[0][v] && dis[0][u] + dis[1][u] == dd && dis[0][v] + dis[1][v] == dd) {
      ll tmp = mul(ways[0][u], ways[1][v]);
      add(sub, mul(tmp, tmp));
      debug(sub, dis[0][v], dis[0][u], u, v);
    }
  }
  add(ans, -sub);
  cout << ans << endl;
}

int main() {
  run();
  return 0;
}


Measured memory_bytes: 17492
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int l = sc.nextInt();
		int r = sc.nextInt();
		if (r - l + 1 >= 2019 || r % 2019 < l % 2019) {
		    System.out.println(0);
		    return;
		}
		int min = Integer.MAX_VALUE;
		for (int i = l; i < r; i++) {
		    for (int j = i + 1; j <= r; j++) {
		        min = Math.min(min, (i % 2019) * (j % 2019) % 2019);
		    }
		}
		System.out.println(min);
   }
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


using namespace std;

int main(){
    ll dist[333][333];

    int n;
    cin >> n;
    vector<vector<ll>> e(n, vector<ll> (n));
    vector<pair<ll, pair<ll, ll>>> edge;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> e[i][j];

        }
    }

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < i; j++) {
            int good = 1;
            for (int x = 0; x < n; x++) {
                if (i == j || i == x || j == x) continue;
                if (e[x][j] + e[x][i] < e[i][j]) {
                    cout << "-1\n";
                    return 0;
                }
                if (e[x][j] + e[x][i] == e[i][j]) good = 0;
            }
            ans += e[i][j] * good;
        }
    }

    cout << ans << endl;



}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  cin >> N;
  int ans=0;
  int p[100010];
  for(int i=1;i<=N;i++){
    cin >> p[i];
  }
  for(int i=1;i<=N;i++){
    if(i==p[i]){
      if(i==N){
        ans++;
      }else{
        swap(p[i],p[i+1]);
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int

using namespace __gnu_pbds;

typedef tree<pair<ll,pair<ll,ll> >, null_type, less<pair<ll,pair<ll,ll> > >, rb_tree_tag, tree_order_statistics_node_update>ordered_set;


#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
#define mod 1000000007
/* Precode Start Here *\


power of 2 less than or equal to N

ll largest_power(ll N)
{
    //changing all right side bits to 1.
    N = N (N>>1);
    N = N| (N>>2);
    N = N| (N>>4);
    N = N| (N>>8);


//as now the number is 2 * x-1, where x is required answer, so adding 1 and dividing it by
 2.
            return (N+1)>>1;

}


     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}




/* Precode Ends */
ll A[5000001],B[5000001],vis[4];
vector<ll>v;
map<ll,ll>myMap;
set<ll>mySet;
vector<pair<ll,ll> >vp;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);


 ll a,b;
 cin>>a>>b;

 vis[a]=1;
 vis[b]=1;
 for(int i=1;i<=3;i++)
 {
     if(vis[i]==0)
     {
         cout<<i<<endl;
         return 0;
     }
 }
return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a[100009];
int main()
{
    ll n;
    cin>>n;
    for(ll i=1; i<=n; i++)
    {
        cin>>a[i];
    }
    sort(a+1,a+1+n);
    ll le=0;
    ll wi=0;
    ll s=0;
    int i=n-1;
   while(i>=1&&s<=1)
   {
       if(a[i]==a[i+1])
       {
           if(s==0)
           {
               le=a[i];
               s++;
               i-=2;
           }
           else if(s==1)
           {
               wi=a[i];
               s++;
           }

       }
       else
       {
          i--;
       }

   }
  if(s==2)
  {
      cout<<wi*le<<endl;
  }
  else
  {
      cout<<0<<endl;
  }
}


Measured memory_bytes: 1024
#include <iostream>
    using namespace std;
    int main(void){
        
    
    
     int n;
     cin >> n;
     
     int a;
     a=n%1000;
    
    if(a!=0){
     int b;
     b=1000-a;
     cout << b;
    }else if(a==0){
        cout << 0;
    }
        
    
    }

Measured memory_bytes: 3164
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<map>
using namespace std;
const int N=1e5+5;
int a[N],b[N],n,X,Y,cnt,tot,head[N],ans;
bool vis[N];
map<int,int>id;
vector<int>va,vb;
struct edge{
	int to,nxt;
}e[N];
inline int get(int x){return id.count(x)?id[x]:id[x]=++tot;}
void dfs(int u){
	vis[u]=1;for(int i=head[u];i;i=e[i].nxt)if(!vis[e[i].to])dfs(e[i].to);
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=0;i<n;++i)cin>>a[i],X^=a[i],va.push_back(a[i]);
	for(int i=0;i<n;++i)cin>>b[i],Y^=b[i],vb.push_back(b[i]);
	va.push_back(X),vb.push_back(Y);
	sort(va.begin(),va.end()),sort(vb.begin(),vb.end());
	if(va!=vb){cout<<"-1\n";return 0;}
	for(int i=0;i<n;++i)
	if(a[i]!=b[i]){
		int A=get(a[i]),B=get(b[i]);
		e[++cnt]=(edge){B,head[A]},head[A]=cnt;
		++ans;
	}
	if(!id.count(X))++ans;else
	if(X!=Y){
		int A=get(X),B=get(Y);
		e[++cnt]=(edge){B,head[A]},head[A]=cnt;
	}
	for(int i=1;i<=tot;++i)if(!vis[i])++ans,dfs(i);
	cout<<ans-1<<'\n';
	return 0;
}

Measured memory_bytes: 9336
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
typedef long long ll;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define forn(i,a,b) for(int i=a;i<(int)b;i++)
int main()
{
    int n,k,s;
    cin>>n>>k>>s;
    if(k==n)
    {
        for(int i=0;i<n;i++)
        cout<<s<<" ";
        return 0;
    }
    if(s==1)
    {
        for(int i=0;i<k;i++)
        cout<<"1 ";
        for(int i=0;i<n-k;i++)
        cout<<"5 ";
        return 0;
    }
    if(s==2)
    {
        for(int i=0;i<k;i++)
        cout<<"2 ";
        for(int i=0;i<n-k;i++)
        cout<<"3 ";
        return 0;
    }
    for(int i=0;i<k;i++)
    cout<<s<<" ";
    for(int i=0;i<n-k;i++)
    cout<<s-1<<" ";
    return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>

#define rep(i, n) for (int i = 0; i < n; i++) 
#define rrep(i, n) for(int i = n-1; i>=0; i--)
#define range(i, n, m) for (int i = n; i < m; i++) 
#define rrange(i, n, m) for (int i = n - 1; i => m; i--) 

typedef long long int ll;
typedef unsigned long long int ull;


using namespace std;

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

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

	ll N, K;
	cin >> N >> K;

	vector<ll> h(N, 0);
	
	rep(i,N){
		cin >> h[i];
	}

	sort(h.begin(), h.end());

	ll min = h[N - 1] - h[0];

	rep(i, N - K + 1) {
		if (min > (h[i + K - 1] - h[i])) {
			min = h[i + K - 1] - h[i];
		}

	}

	cout << dec << min;

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define N_PRIME 1000000007
#define ll int64_t

int w,h;
bool is_land[64][64];

void show(){
    for(int y = 1 ; y <= h ; y++ ){
        for(int x = 1; x <= w ;x++){
            cout << is_land[x][y] ?'1':'0';
        }
        cout << endl;
    }
}

bool fill(int x,int y){
    if( is_land[x][y] == false )
        return false;
    
    is_land[x][y] = false;
    for(int dx = -1 ; dx <= 1 ; dx++){
        for(int dy = -1 ; dy <= 1 ; dy++ ){ 
            fill(x+dx,y+dy);
        }
    }
    
    return true;
}

void subroutine(){
    
    for(int i = 0 ; i < 64 * 64 ; i++ )
        is_land[i/64][i%64] = false;
    
    cin >> w >> h;
    if( w == 0 && h == 0 )exit(0);
    
    for(int y = 0 ; y < h ; y++ ){
        for(int x = 0 ;x < w ; x++ ){
            int temp;
            cin >> temp;
            is_land[x+1][y+1] = temp == 1;
        }
    }
    int count = 0 ;
    
    for(int y = 1 ; y <= h ; y++ ){
        for(int x = 1 ;x <= w ; x++ ){
            if(  fill(x,y) )
                count++;
            //show();
        }
    }
    
    cout << count << endl;
}

int main(void){
    while(true)subroutine();
    return 0;
}

Measured memory_bytes: 3200
#include <cstdio>
#include <cmath>

using namespace std;

int main(void){
  int N;
  int *X;
  int *Y;

  scanf("%d", &N);
  X = new int[N];
  Y = new int[N];

  for(int i = 0; i < N; i++)
    scanf("%d", X+i);
  for(int i = 0; i < N; i++)
    scanf("%d", Y+i);

  int max = -2147483648;

  for (int i = 0; i < int(pow(2.0, N)); i++) {
    int val = 0;
    for (int j = 0; j < N; j++)
      if ((i >> j) & 0x01 == 1)
        val += X[j] - Y[j];
    if (val > max)
      max = val;
  }
  printf("%d", max);
  delete X;
  delete Y;

  return 0;
}

Measured memory_bytes: 256
import sys, io, os, re
import bisect
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor
from copy import copy, deepcopy
from collections import deque
from fractions import gcd
from functools import reduce
from itertools import groupby

n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

def array1(n): return [0] * n
def array2(n, m): return [[0] * m for x in range(n)]
def array3(n, m, l): return [[[0] * l for y in xrange(m)] for x in xrange(n)]

X, Y = nn()

for i in range(X+1):
    if (i * 2 +  (X - i) * 4) == Y:
        print("Yes")
        exit(0)
else:
    print("No")

Measured memory_bytes: 72796
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;
struct node{
	int i;
	int sum;
};

node A[100010];
bool cmp(node a,node b){
	return a.sum<b.sum;
}

int main(){
	int n;cin>>n;
    for(int i=1;i<=n;i++)cin>>A[i].sum,A[i].i=i;
    sort(A+1,A+n+1,cmp);
    for(int i=1;i<=n;i++)cout<<A[i].i<<" ";
	
	
	
	
	return 0;
} 

Measured memory_bytes: 1664
from collections import defaultdict

sh = int(input())
b = input()

id = [int(n) for n in b.split(" ")]
D = defaultdict(int)
for i in id:
    if i not in D:
        D[i] = 1
    else:
        D[i] += 1
#print(D)

for i in range(1,sh+1):
    if i in D:
        print(D[i])
    else:
        print(0)


Measured memory_bytes: 36736
import java.util.Scanner;

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

		long N = scan.nextLong();
		long max = scan.nextLong();
		long ans = 0;
		for(int i=0;i<N-1;i++){
			long c = scan.nextLong();
			ans+=Math.max(0,max-c);
			max=Math.max(c,max);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 48500
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long K = sc.nextLong();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt() - 1;
		}
		Map<Integer, Integer> map = new HashMap<Integer, Integer>();
		int s = 0;
		while (!map.containsKey(s)) {
			map.put(s, A[s]);
			s = A[s];
		}
		int c = 0;
		int p = 0;
		while (p != s) {
			 p = map.get(p);
			 c++;
		}
		if (K >= c) {
			long count = (K - c) % (map.size() - c);
			int ans = s;
			while (count > 0) {
				ans = map.get(ans);
				count--;
			}
			System.out.println(ans + 1);
		} else {
			long count = K;
			int ans = 0;
			while (count > 0) {
				ans = map.get(ans);
				count--;
			}
			System.out.println(ans + 1);
		}
	}

}

Measured memory_bytes: 67832
#include<bits/stdc++.h>
#define N ()
#define ll long long
#define debug(x) cerr<<#x<<" : "<<x<<endl
#define CM cerr<<(&MOP2-&MOP1)/1024.0/1024.0<<endl
using namespace std;
template <class T> inline T Min(T x, T y){
    return x<y?x:y;
}
template <class T> inline T Max(T x, T y){
    return x>y?x:y;
}
bool MOP1;
int a,b;
bool MOP2;
int main(){
	scanf("%d%d",&a,&b);
	printf("%d\n",(a+b-3)/(a-1));
	return 0;
}






Measured memory_bytes: 256
using System;

namespace ABC086_B_1_21
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			string[] input = Console.ReadLine().Split(' ');
			int number = int.Parse(input[0] + input[1]);

			double sqrtNumber = Math.Sqrt(number);

			if (sqrtNumber % 1 == 0)
			{
				Console.WriteLine("Yes");
			}
			else
			{
				Console.WriteLine("No");
			}
		}
	}
}

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

using namespace std;

int s[1000001];
vector<int> a;

int main() {
    int n, x;
    cin >> n;
    int MAX = 0;
    for(int i = 0; i < n; ++i) {
        cin >> x;
        MAX = max(MAX, x);
        ++s[x];
        a.push_back(x);
    }
    sort(a.begin(), a.end());
    int ans = 0;
    for(int i = 0; i < n; ++i) {
        if(s[a[i]] == 0) continue;
        if(s[a[i]] == 1) ++ans;
        int cur = a[i];
        for(int j = cur; j <= MAX; j += cur) {
            s[j] = 0;
        }
    }
    cout << ans << '\n';
    return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n-1; i >= 0; i--)
#define FOR(i, n, m) for(int i = n; i < (int)(m); i++)
#define PRINT(x) cout << x << endl
#define ALL(v) v.begin(), v.end()
#define INF (ll)1e18

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

ll MOD = 1000000007;

int main()
{
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];
    if (N <= K-1) {
        PRINT(abs(A[N-1] - A[0]));
        return 0;
    }
    vector<ll> dp(N, INF);
    dp[0] = 0;
    FOR(i, 1, K) {
        REP(j, i) {
            dp[i] = min(dp[i], dp[i-(j+1)] + abs(A[i] - A[i-(j+1)]));
        }
    }
    FOR(i, K, N) {
        REP(j, K) {
            dp[i] = min(dp[i], dp[i-(j+1)] + abs(A[i] - A[i-(j+1)]));
        }
    }
    PRINT(dp.back());
    return 0;
}


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

using namespace std;

int power(int a, int b)
{
    int ans = 1;
    for(int i = 0; i < b; i++){
        ans *= a;
    }

    return ans;
}
int main(void)
{
    int x;
    cin >> x;
    int max = 1;
    for(int i = 2; i <= sqrt(x); i++){
        for(int j = 2; power(i, j) <= x; j++){
            if(power(i, j) >= max){
                max = power(i, j);
            }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define debug(x) cerr << #x << " = " << x << '\n';
#define BP() cerr << "OK!\n";
#define PR(A, n) cerr << #A << " = "; for (int _=1; _<=n; ++_) cerr << A[_] << ' '; cerr << '\n';
#define PR0(A, n) cerr << #A << " = "; for (int _=0; _<n; ++_) cerr << A[_] << ' '; cerr << '\n';
#define FILE_NAME "data"

const int MAX_N = 2002;
const int INF = 1e9;

int n, k, q, a[MAX_N], b[MAX_N];

void enter() {
	cin >> n >> k >> q;
	for (int i=1; i<=n; ++i)
		cin >> a[i];
}

int calc_number_of_valid_seg(int min_val, int max_val) {
	int res = 0;
	for (int i=1; i<=n; ++i) {
		if (b[i]==0)
			continue;
		int j = i, cnt = a[i]<=max_val;
		while (j+1<=n && b[j+1]) {
			++j;
			cnt += (a[j]<=max_val);
		}
		/*debug(j-i+1-k+1);
		if (cnt>j-i+1-k+1)
			ok = true;*/
		res += max(0, min(cnt, j-i+1-k+1));
		i = j;
	}
	return res;
}

int fix_min(int min_val) {
	for (int i=1; i<=n; ++i) {
		if (a[i]>=min_val)
			b[i] = 1;
		else
			b[i] = 0;
	}
	//debug(calc_number_of_valid_seg(1, 1));
	int l = min_val, r = INF, mid = (l + r) / 2;
	while (l!=mid && mid!=r) {
		if (calc_number_of_valid_seg(min_val, mid)>=q)
			r = mid;
		else
			l = mid;
		mid = (l + r) / 2;
	}
	for (int i=l; i<=r; ++i)
		if (calc_number_of_valid_seg(min_val, i)>=q)
			return i;
	return -1;
}

int main() {
	//freopen(FILE_NAME".inp", "r", stdin);
	//freopen(FILE_NAME".out", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	enter();
	int res = INF;
	//debug(fix_min(1));
	for (int i=1; i<=n; ++i) {
		int tmp = fix_min(a[i]);
		if (tmp!=-1)
			res = min(res, fix_min(a[i]) - a[i]);
	}
	cout << res;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let a: Vec<i64> = (0..n).map(|_| read::<i64>()).collect();
    let b: Vec<i64> = (0..n).map(|_| read::<i64>()).collect();

    let suma: i64 = a.iter().sum();
    let sumb: i64 = b.iter().sum();
    if suma < sumb {
        println!("-1");
        return;
    }

    let mut d: Vec<i64> = vec![0; n];
    let mut ans = 0;
    let mut hu: i64 = 0;
    for i in 0..n {
        d[i] = a[i] - b[i];
        if d[i] < 0 {
            hu += b[i] - a[i];
            ans += 1;
        }
    }
    d.sort();
    if ans == 0 {
        println!("0");
        return;
    }
    for i in 0..n {
        if hu > 0 {
            hu -= d[n - i - 1];
        }
        if hu <= 0 {
            ans += i + 1;
            break;
        }
    }
    println!("{}", ans);
}

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


Measured memory_bytes: 6396
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int Z = sc.nextInt();
		int temp = X;
		X = Y;
		Y = temp;
		temp = X;
		X = Z;
		Z = temp;
		System.out.println(X+" "+Y+" "+Z);
	}

}


Measured memory_bytes: 20308
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  for_each(begin(A), end(A), [](auto& x) { cin >> x; });

  ll sum = accumulate(cbegin(A), cend(A), 0LL);

  ll sa = 202020202020;
  ll sum_count = 0;
  for (ll i = 0; i < N; i++) {
    sum_count += A[i];
    ll rest = sum - sum_count;
    sa = min(sa, abs(sum_count - rest));
  }

  cout << sa << endl;
  return 0;
}


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

int main(){
    string s;
    int k;
    cin>>s;
    cin>>k;
    for (int i = 0; i < k; ++i) {
        if(s.at(i)!='1'){
            cout<<s.at(i)<<endl;
            break;
        }else{
            if(i==k-1){
                cout<<1<<endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()
#define allg(v) v.begin(), v.end(), greater<int>()

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s, x, y;
  int n, ans = 0;
  cin >> n >> s;
  
  rep(i, 1, n) {
    x = s.substr(0, i);
    y = s.substr(i, n-i);
    
    int cnt = 0;
    rep(k, 0, 26) {
      bool xx = false;
      bool yy = false;
      rep(j, 0, i) if(x[j] == k+'a') xx = true;
      rep(j, 0, n-i) if(y[j] == k+'a') yy = true;
      if(xx and yy) cnt++;
    }
    ans = max(ans, cnt);
  }      
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll int
#define N 100005
#define rep(i,j,k) for (ll i=j;i<=k;++i)
#define per(i,j,k) for (ll i=j;i>=k;--i)
using namespace std;
inline ll read(){
	char ch=getchar(); ll x=0,f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
	return x*f;
}
ll n,m,ans,flag[N],num[N];
int main(){
	n=read(); m=read();
	flag[1]=1;
	rep(i,1,n) num[i]=1;
	rep(i,1,m){
		ll x=read(),y=read();
		--num[x]; ++num[y];
		if (flag[x]) ++flag[y];
		if (!num[x]) flag[x]=0;
	}
	rep(i,1,n) if (flag[i]) ++ans;
	printf("%d",ans);
}

Measured memory_bytes: 896