akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
//========================================================================



int main() {
	
	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	//==================================
	

	int N;
	cin >> N;
	vint A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

	int maxK = 0;
	int maxId = 0;

	for (int i = 0; i < N; i++) {


		if (A[i] == maxK + 1) {
			maxK++;
		}


	}

	if (maxK == 0) {
		cout << -1;
		return 0;
	}

	cout << N - maxK;

}



Measured memory_bytes: 1024
s = list(input())
t = list(input())
length = len(s)
ans = 'No'
for i in range(length):
    k0 = s[0]
    for j in range(length-1):
        k1 = s[j+1]
        s[j+1] = k0
        k0 = k1       
    s[0] = k0
    #print(s)
    if s == t:
        ans = 'Yes'
print(ans)


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

int main(){
    string s;
    cin >> s;
    for(int i = 1;;i+2){
        s = s.substr(0, s.size() - i * 2);
        string a = s.substr(0, s.size() / 2);
        string b = s.substr(s.size() / 2, s.size() / 2);
        if(a == b){
            cout << s.size() << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
n,k = map(int,input().split())
L = list(map(int,input().split()))
inf = float("inf")
dp = [inf]*(n)
dp[0] = 0

for i in range(1,n):
    for j in range(1,k+1):
        if i - j >=0:
            dp[i] = min(dp[i],dp[i-j] + abs(L[i] - L[i-j]))
#print(dp)            
print(dp[n-1])

Measured memory_bytes: 55392
while gets
  s=$_.upcase.gsub(/[^A-Z]/,"")

  odd=(1..s.size-2).map{|i|
    j=1
    j+=1 while ( (i-j)>=0 && (i+j)<s.size && s[i-j]==s[i+j] )
    j-=1
    j==0?nil:s[i..i+j]
  }.uniq.compact.sort_by(&:size).inject([]){|s,r|
    s-(2..r.size-1).map{|i|r[0,i]}+[r]
  }.map{|s|s[1..-1].reverse+s}

  even=(0..s.size-2).map{|i|
    j=0
    j+=1 while ( (i-j)>=0 && (i+j+1)<s.size && s[i-j]==s[i+j+1] )
    j-=1
    j<=0?nil:s[i+1..i+j+1]
  }.uniq.compact.sort_by(&:size).inject([]){|s,r|
    s-(2..r.size-1).map{|i|r[0,i]}+[r]
  }.map{|s|s.reverse+s}

  puts (odd+even).join(" ")
end

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

const ll N = 2010;

bool match(char c, char d) {
	return c == '?' || d == '?' || c == d;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	vector<string> a(3);
	FOR(i,0,3) cin >> a[i];

	vector<vvl> ok(3, vvl(3));

	FOR(i,0,3) FOR(j,0,3) if (i != j) {
		ok[i][j].resize(sz(a[i])+1, true);
		FOR(k,0,sz(a[i])+1) FOR(t,0,sz(a[j])) {
			if (k+t >= sz(a[i])) break;
			if (!match(a[i][k+t], a[j][t])) {
				ok[i][j][k] = false;
				break;
			}
		}
	}
	
	auto check = [&](ll i, ll j, ll k) {
		if (k >= sz(ok[i][j])) return true;
		return !!ok[i][j][k];
	};

	vl p = {0,1,2};
	ll res = oo;
	do {
		ll i = p[0], j = p[1], k = p[2];
		FOR(s,0,N) FOR(t,0,N) {
			if (!check(i, j, s)) continue;
			if (!check(j, k, t)) continue;
			if (!check(i, k, s+t)) continue;
			ll cur = 0;
			cur = max(cur, sz(a[i]));
			cur = max(cur, sz(a[j]) + s);
			cur = max(cur, sz(a[k]) + s + t);
			res = min(res, cur);
		}
	} while (next_permutation(all(p)));

	cout << res << endl;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const double PI  =3.141592653589793238463;
long long mod = 1000000007;
vector<int>adj[100005];
bool visited[100005]={false};
int path[100005]={0};
int main()
{

   ios::sync_with_stdio(false);
	cin.tie(0);
	ll t;
	t=1;
	while(t--)
    {
          int n,m;
          cin>>n>>m;
          for(int i=0;i<m;i++) {
              int a,b; cin>>a>>b;
              adj[a].push_back(b);
              adj[b].push_back(a);
          }
          queue<int>q;
          q.push(1);
          visited[1]=true;
          while(!q.empty()) {
              int b = q.front(); 
              q.pop();
              for(int i:adj[b]) {
                  if(!visited[i]) {
                      visited[i]=true;
                      path[i]=b;
                      q.push(i);
                  }
              }
          }
        bool f =true;
        for(int i=1;i<=n;i++) if(!visited[i]) {f=false; break;}
        if(!f) cout<<"No"<<"\n";
        else {
            cout<<"Yes"<<endl;
            for(int i=2;i<=n;i++) cout<<path[i]<<endl;
        }

    
    }
}









Measured memory_bytes: 10552
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>

using namespace std;
using ull = unsigned long long;
using ll = long long;
using lli = long long int;
using ld = long double;
using pa = pair<int,int>;
#define SORT(v, n) sort(v, v+n);
#define ALL(v) v.begin(),v.end()
#define VSORT(v) sort(ALL(v))
#define GRESORT(v) sort(ALL(v),greater<ll>())
#define REVERSE(v) reverse(ALL(v))
#define overlap(v) v.erase(unique(ALL(v)),v.end())
#define debug(x) cout << #x << ": " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i = (b-1); i >= a; i--)
#define rrep(i,n) RFOR(i,0,n)
#define INF 999999999
#define mins(a,b) a = min(a,b)
#define maxs(a,b) a = max(a,b)

//4近傍
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

//8近傍
//int dy[]={0,0,1,-1,1,1,-1,-1};
//int dx[]={1,-1,0,0,1,-1,1,-1};

ll mod = 1000000007;

ll gcd(ll n, ll x){
    if(n == 0) return x;
    return gcd(x%n,n);
}

void solve(){
    ll n,x; cin >> n >> x;
    cout << 3 * (n - gcd(n,x)) << endl;
}

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

    solve();

    return 0;
}

Measured memory_bytes: 256
enum class Card{
    Taro, Hanako, Used
}
fun main(args:Array<String>):Unit{
    var n = readLine()!!.toInt()
    while(n != 0){
        val cards = Array(n * 2){Card.Hanako}
        repeat(n){
            cards[readLine()!!.toInt() - 1] = Card.Taro
        }
        var restTaro = n
        var restHanako = n
        var isTarosTurn = true
        while (restTaro != 0 && restHanako != 0){
            cards.forEachIndexed{index, card ->
                when{
                    isTarosTurn && card == Card.Taro && restHanako != 0 -> {
                        isTarosTurn = false
                        restTaro--
                        cards[index] = Card.Used
                    }
                    !isTarosTurn && card == Card.Hanako && restTaro != 0 -> {
                        isTarosTurn = true
                        restHanako--
                        cards[index] = Card.Used
                    }
                }
            }
            isTarosTurn = !isTarosTurn
        }
        println(cards.count{it == Card.Hanako})
        println(cards.count{it == Card.Taro})
        n = readLine()!!.toInt()
    }
}


Measured memory_bytes: 24668
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <iomanip>       // fixed, setprecision
using namespace std;

int main()
{
  uint64_t r, D, x;
  cin >> r >> D >> x;
  for (int i = 0; i < 10; i++)
  {
    x = x * r - D;
    cout << x << endl;
  }
}


Measured memory_bytes: 3108
#include <iostream>


using namespace std;

int main()
{
	char A[3][3];

	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> A[i][j];
		}
	}

	cout << A[0][0] << A[1][1] << A[2][2] << endl;
	
		
	
}




Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	string s;
	cin >> s;
	if (s.size() % 2 == 0){
		printf("No\n");
		return 0;
	}
	string t = s;
	reverse(t.begin(), t.end());
	if (s != t){
		printf("No\n");
		return 0;
	}
	string x = "";
	for (int i = 0; i < s.size() / 2; i++) x.push_back(s[i]);
	string y = x;
	reverse(y.begin(), y.end());
	if (x != y){
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
}

Measured memory_bytes: 256
#include <stdio.h>
int min(int a,int b){
    if(a<b)return a;
    return b;
}
int main(){
    int n,a,b,temp;
    while(1){
        scanf("%d",&n);
        if(n==0)return 0;
        a=b=0;
        for(int i=2;i<=n;i++){
            temp=i;
            while(temp%2==0){
                temp/=2;
                a++;
            }
            while(temp%5==0){
                temp/=5;
                b++;
            }
        }
        printf("%d\n",min(a,b));
    }
}

Measured memory_bytes: 2576
#include <iostream>

using namespace std;

const int MAX_P = 1000010;
bool prime[MAX_P + 1];

void init_prime()
{
    for (int i = 0; i < MAX_P; i++)
        prime[i] = true;
    prime[0] = prime[1] = false;

    for (int i = 2; i * i < MAX_P; i++) 
        if (prime[i])
            for (int j = 2 * i; j < MAX_P; j += i)
                prime[j] = false;
}

int main()
{
    int a, d, n;

    init_prime();

    while (cin >> a >> d >> n, a || d || n) {
        int ans = 0;

        while (true) {
            if (prime[a])
                ans++;
            if (ans == n)
                break;
            a += d;
        }
        cout << a << endl;
    }

    return 0;
}

Measured memory_bytes: 2136
a,b,c,x,y=map(int,input().split())

ans=10**9
for i in range(0,max(x,y)*2+2,2):
  tx=max(x-i//2,0)
  ty=max(y-i//2,0)
  t_ans=tx*a+ty*b+i*c
  ans=min(ans,t_ans)
print(ans)

Measured memory_bytes: 3064
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
public class Main {
	public static void main(String[] args)throws Exception{
		PrintWriter out = new PrintWriter(System.out);
		int N=nextInt();
		int D=nextInt();
		int ans=0;
		for(int i=0;i<N;i++){
			double x=nextInt();
			double y=nextInt();
			if(Math.sqrt((x*x)+(y*y))<=D)
				ans++;
		}
		System.out.println(ans);
	}
	static boolean isOK(int index,int key,int[]a){
		if (a[index]>=key) return true;
	    else return false;
	}
	static int binary_search(int key,int[] a) {
	    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	    int ok = (int)a.length; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	    while (Math.abs(ok - ng) > 1) {
	        int mid = (ok + ng) / 2;
	        if (isOK(mid,key,a)) ok = mid;
	        else ng = mid;
	    }
	    return ok;
	}
	//FastScanner
	static InputStream in = System.in;
	static  byte[] buffer = new byte[1024];
	static int length = 0, p = 0;
	public static boolean hasNextByte () {
		if (p < length) return true;
		else {
			p = 0;
			try {length = in.read(buffer);}
			catch (Exception e) {e.printStackTrace();}
			if (length == 0) return false;
		}
		return true;
	}
	public static int readByte () {
		if (hasNextByte() == true) return buffer[p++];
		return -1;
	}
	public static boolean isPrintable (int n) {return 33<=n&&n<=126;}
	public static void skip () {
		while (hasNextByte() && !isPrintable(buffer[p])) p++;
	}
	public static boolean hasNext () {skip(); return hasNextByte();}
	public static String next () {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int temp = readByte();
		while (isPrintable(temp)) {
			sb.appendCodePoint(temp);
			temp = readByte();
		}
		return sb.toString();
	}
	public static int nextInt () {return Math.toIntExact(nextLong());}
	public static int[] nextInts (int n) {
		int[] ar = new int[n];
		for (int i=0; i<n; i++) ar[i] = nextInt();
		return ar;
	}
	public static long nextLong () {
		if (!hasNext()) throw new NoSuchElementException();
		boolean minus = false;
		int temp = readByte();
		if (temp == '-') {
			minus = true;
			temp = readByte();
		}
		if (temp<'0' || '9'<temp) throw new NumberFormatException();
		long n = 0;
		while (isPrintable(temp)) {
			if ('0'<=temp && temp<='9') {
				n *= 10;
				n += temp - '0';
			}
			temp = readByte();
		}
		return minus? -n : n;
	}
}



Measured memory_bytes: 36684
n = int(input())
a = list(map(int,input().split()))
a.insert(0,0)
b = []
if n%2==0:
	i=n
	while i>=2:
		b.append(a[i])
		i += -2
	k=1
	while k<=n-1:
		b.append(a[k])
		k += 2
else:
	i=n
	while i>=1:
		b.append(a[i])
		i += -2
	k=2
	while k<=n-1:
		b.append(a[k])
		k+=2
for i in range(n-1):
	print(b[i],end=' ')
print(b[n-1])

Measured memory_bytes: 26180
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>
#include<bitset>
#include<stack>
#include<fstream>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> lltpl;
typedef tuple<int, int, int> tpl;

int dy8[8] = { 2,2,-2,-2,1,1,-1,-1 };
int dx8[8] = { 1,-1,1,-1,2,-2,2,-2 };
int dx4[4] = { 1,0,0,-1 };
int dy4[4] = { 0,1,-1,0 };


/******************************************************************************************/

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}

// vector
template <typename T>
istream& operator>>(istream & is, vector<T> & vec) { for (T& x : vec) is >> x; return is; }
// pair
template <typename T, typename U>ostream& operator<<(ostream & os, pair<T, U> & pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; }
// vector
template <typename T>ostream& operator<<(ostream & os, const vector<T> & vec) { os << "{";	for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : ", "); }os << "}"; return os; }
// map
template <typename T, typename U>ostream& operator<<(ostream & os, map<T, U> & map_var) { os << "{";	repi(itr, map_var) { os << *itr; itr++; if (itr != map_var.end()) os << ", "; itr--; }os << "}"; return os; }
// set
template <typename T>ostream& operator<<(ostream & os, set<T> & set_var) { os << "{"; repi(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) os << ", "; itr--; }os << "}"; return os; }



const int IINF = 1e9 + 7;
const ll LINF = 1e18 + 7;
constexpr ll MOD = 1e9 + 7;

//ここから書くこと






int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	string s;
	cin >> s;

	if (s.substr(0, n / 2) == s.substr(n/2)) {
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	
	
	return 0;
}


Measured memory_bytes: 256
import fractions
import sys
from sys import stdin

n, m = map(int, stdin.readline().rstrip().split())
s = stdin.readline().rstrip()
t = stdin.readline().rstrip()


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


g = fractions.gcd(n, m)
for i in range(g):
    if s[n // g * i] != t[m // g * i]:
        print(-1)
        sys.exit()
print(lcm(n, m))

Measured memory_bytes: 5340
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll ar[100];

int main()
{

    ll d1,d2,i,t,mn,sum=0;

    cin>>t;
    for(i=0;i<5;i++)
    {
        cin>>ar[i];

    }

    sort(ar,ar+5);

    mn=ar[0];

    if(t<=mn)cout<<5<<endl;
    else
    {
        d1=(t-mn)%mn;
        d2=(t-mn)/mn;
        if(d1!=0)sum=1;
        sum=sum+d2+5;

        cout<<sum<<endl;
    }





    return 0;
}


Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using p32=pair<int,int>;
using i64=int64_t;
using p64=pair<i64, i64>;

const int mod=1e9+7;

main()
{
    int n; cin>>n;
    int az=0,bz=0;
    int abz=0;
    map<p64, i64> pcnt,ncnt;
    for(int i=0; i<n; ++i)
    {
        i64 a,b; cin>>a>>b;
        if(!a)
        {
            if(!b)
            {
                ++abz;
            }
            else ++az;
        }
        else if(!b)
        {
            ++bz;
        }
        else
        {
            i64 g=gcd(a,b);
            a/=g,b/=g;
            if(a<0) a=-a,b=-b;
            if(b>0) pcnt[{a,b}]++;
            else ncnt[{a,b}]++;
        }
    }
    i64 pw2[1<<18]={1};
    for(int i=0; i<n; ++i)
    {
        pw2[i+1]=pw2[i]*2%mod;
    }
    i64 ans=pw2[az]+pw2[bz]-1;
    ans%=mod;
    for(auto [p,c]:pcnt)
    {
        p64 q={p.second,-p.first};
        ans=ans*(pw2[ncnt[q]]+pw2[c]-1)%mod;
        ncnt.erase(q);
    }
    for(auto [p,c]:ncnt)
    {
        ans=ans*pw2[c]%mod;
    }
    (ans+=abz-1+mod)%=mod;
    cout << ans << "\n";
}


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

using ll = long long;
#define int long long
using P = pair<int, int>;

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
template<typename T = int>
T in() {T a; cin >> a; return a;}
/***** MAIN *****/
signed main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  if(a >= k) {
    cout << k << endl;
  } else if(a + b >= k) {
    cout << a << endl;
  } else {
    cout << a - (k-a-b) << endl;
  }
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 3512
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int[] nums = new int[n];

		for(int i=0; i<n; i++){
			nums[i] = scan.nextInt();
		}
		scan.close();

		long max = nums[0];
		long min = nums[0];
		long sum = 0;

		for(int s=0; s<nums.length; s++){
			sum += nums[s];
			if(max < nums[s]){
				max = nums[s];
			}
			if(min > nums[s]){
				min = nums[s];
			}
		}

		System.out.println(min + " " + max + " " + sum);
	}

}

Measured memory_bytes: 31788
nyuryoku=input()
nyuryoku_spl=nyuryoku.split("/")
nyuryoku_num=nyuryoku_spl[0]+nyuryoku_spl[1]+nyuryoku_spl[2]
nyuryoku_num=int(nyuryoku_num)
nyuryoku_num

if nyuryoku_num<=20190430:
    print("Heisei")
else:
    print("TBD")

Measured memory_bytes: 2940
#include <stdio.h>
#define MAX_INDEX 1000


void print_a(int a[], int n) {
	int i;
	for (i = 0; i < n - 1; i++) {
		printf("%d ", a[i]);
	}
	printf("%d\n", a[n - 1]);
}

void insertionSort(int a[],int  n) {
	int i, j, temp;
	for (i = 1; i < n; i++) {
		temp = a[i];
		j = i - 1;
		while (j >= 0 && a[j] > temp) {
			a[j+1] = a[j];
			j--;
		}
		a[j+1] = temp;
		print_a(a, n);
	}
}


int main() {
	int a[MAX_INDEX], n;
	scanf("%d", &n);
	int i = 0;
	int ch;
	for (i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	print_a(a, n);
	insertionSort(a, n);

}


Measured memory_bytes: 2060
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
int N;
ll A[200000];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N;
    double cur = 1.0;
    ll ans = 1;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        if(A[i] == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    for(int i = 0; i < N; i++){
        cur *= (double)A[i];
        if(cur > 2e18){
            cout << -1 << endl;
            return 0;
        }
        ans *= A[i];
    }
    if(ans > (ll)1e18){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 4e5 + 5;

int n,prefixE[maxn],prefixW[maxn];
string s;


int W_left(int x) {
  if (x==0) return 0;
  return prefixW[x-1];
}

int E_right(int x) {
  int ans = prefixE[n-1];
  ans -= prefixE[x];
  return ans;
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cin>>n>>s;
  for (int i=0; i<n; i++) {
    if (i) {
      prefixE[i]+=prefixE[i-1];

      prefixW[i]+=prefixW[i-1];

    }
    if (s[i]=='E') prefixE[i]++;
    if (s[i]=='W') prefixW[i]++;
  }
  int best = maxn;

  // for (int i=0; i<n; i++) {
  //   cout<<prefixE[i];
  // }
  // cout<<endl;
  // for (int i=0; i<n; i++) {
  //   cout<<prefixW[i];
  // }
  // cout<<endl;

  for (int i=0; i<n; i++) {
    best = min(best, W_left(i)+E_right(i));
  }


  cout<<best<<endl;
  return 0;
}


Measured memory_bytes: 3092
import java.util.Scanner;

public class Main{

	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		String S = scan.next();
		String result = "No";
		if(String.valueOf(S.charAt(2)).equals(String.valueOf(S.charAt(3)))
				&&(String.valueOf(S.charAt(4)).equals(String.valueOf(S.charAt(5))))){
			result = "Yes";
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 21844
import java.util.*;
public class Main{
    public static void main(String[] args)
    {
        
        Scanner sc = new Scanner(System.in);
        while(true)
        {
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H == 0 && W == 0)
            {
                break;
            }
            for(int j=0;j<H;j++)
            {
                for(int i = 0; i < W ;i++)System.out.print("#");
                System.out.println();
            }
            System.out.println();
        }
        sc.close();
    }
}


Measured memory_bytes: 33540
#pragma gcc optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i=(ll)(r);i<(ll)(n);++i)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define pb(n) push_back(n)
#define endl '\n'
#define P(x) cout << #x << " = " << (x) << endl
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c
#define VIN(V) for(int ii = 0; ii < (V).size(); ii++) {cin >> (V).at(ii);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(ii,(V).size()){cout << (V)[ii] << " ";} cout<<endl;
#define VOUT2(V) REP(jj,(V).size()){VOUT(V[jj])}
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<vi > vvi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
ll n, m, k, ans, sum, cnt = 0; string s; char c;

int main(){
  cin.tie(0);ios::sync_with_stdio(false);
  ll h,w;
  IN2(h,w);
  vs grid(h);
  FOR(i,0,h) cin >> grid[i];

  vvi yokogrid(h,vi(w,0));
  FOR(i,0,h) {
    cnt = 0;
    FOR(j,0,w) {
      if (grid[i][j] == '#') {
        FOR(k,0,cnt) yokogrid[i][j-k-1] = cnt;
        cnt = 0;
      } else if (j==w-1) {
        cnt++;
        FOR(k,0,cnt) yokogrid[i][j-k] = cnt;
      } else {
        cnt++;
      }
    }
  }
  vvi tategrid(h,vi(w,0));
  FOR(j,0,w) {
    cnt = 0;
    FOR(i,0,h) {
      if (grid[i][j] == '#') {
        FOR(k,0,cnt) tategrid[i-k-1][j] = cnt;
        cnt = 0;
      } else if (i==h-1) {
        cnt++;
        FOR(k,0,cnt) tategrid[i-k][j] = cnt;
      } else {
        cnt++;
      }
    }
  }

  // VOUT2(yokogrid);
  // VOUT2(grid);
  // VOUT2(tategrid);
  FOR(i,0,h) {
    FOR(j,0,w) {
      chmax(ans, yokogrid[i][j] + tategrid[i][j]);
    }
  }
  OUT(ans - 1);
}


Measured memory_bytes: 67200
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int main(){

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

	printf("%d\n",N/3);

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define ESP (1e-13)
using namespace std;

//??§?¨????????§???????
typedef struct Point {
	double x; 
	double y;

	Point() { }

	Point(double x, double y) :x(x), y(y) { }

	Point operator+(const Point& p) {
		return Point(x + p.x, y + p.y);
	}

	Point operator-(const Point& p) {
		return Point(x - p.x, y - p.y);
	}

	Point operator*(const double& a) {
		return Point(x*a, y*a);
	}

	Point operator=(const Point& p1) {
		return Point(p1.x,p1.y);
	}

};

//??´??§?????????????§???????
typedef Point Vector;

//??´???????§???????
 struct Line {
	Point p1, p2;
	Line() {}
	Line(const Point& a,const Point& b) : p1(a),p2(b) { }
};

 //??????????§???????
 typedef Line Segment;

//2??????????????¢????±?????????¢??°
double abs(Point p1, Point p2) {
	double norm = (p1.x - p2.x)*(p1.x - p2.x) + (p1.y - p2.y)*(p1.y - p2.y);
	return sqrt(norm);
}

//????????¢??°
double product(Vector v1, Vector v2) {
	return v1.x*v2.x + v1.y*v2.y;
}

//????????¢??°
double cross(Vector p1, Vector p2) {
	return p1.x*p2.y - p1.y*p2.x;
}

//3??????????????¢???????±?????????¢??°
int ccw(Point p0, Point p1, Point p2) {
	Vector v0 = p1 - p0;
	Vector v1 = p2 - p0;
	if (cross(v0, v1) > ESP) return 1;   //p0,p1,p2??????????¨???????
	if (cross(v0, v1) < -ESP) return -1;   //p0,p1,p2???????¨???????
	if (product(v0, v1) < -ESP) return 2;  //p2,p0,p1????????§????????´??????
	if (abs(p0, p1) < abs(p0, p2)) return -2;  //p0,p1,p2????????§????????´??????
	return 0;   //p2?????????(p0,p1)???
}


bool intersect(Point p0, Point p1, Point p2, Point p3) {
	return (ccw(p0, p1, p2)*ccw(p0, p1, p3) <= 0&&ccw(p2,p3,p0)*ccw(p2,p3,p1)<=0);
	//?????????????????????????????¶
}

//????????????????????£??????????????????????????¢??°
bool intersect(Segment s1, Segment s2) {
	return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}

//??´?????¨???????????¢????±?????????¢??°
double DistanceLP(Line l, Point p) {
	return abs(cross(l.p2 - l.p1, p - l.p1)/abs(l.p1,l.p2));
}

//????????¨???????????¢????±?????????¢??°
double DistanceSP(Segment s, Point p) {
	if (product(s.p2 - s.p1, p - s.p1) < -ESP) return abs(p, s.p1);
	if (product(s.p1 - s.p2, p - s.p2) < -ESP) return abs(p, s.p2);
	return DistanceLP(s, p);
}

//2??????????????¢????±?????????¢??°
double DistanceSS(Segment s1, Segment s2) {
	if (intersect(s1, s2)) return 0.0;
	return min(min(DistanceSP(s1, s2.p1), DistanceSP(s1,s2.p2)), min(DistanceSP(s2, s1.p1), DistanceSP(s2, s1.p2)));
}

//?????´???????\???¢????±?????????¢??°
Point CrossPoint(Line s1,Line s2) {
	double d1=DistanceLP(s2, s1.p1);
	double d2 = DistanceLP(s2, s1.p2);
	double t = d1 / (d1 + d2);
	return s1.p1 + (s1.p2 - s1.p1)*t;
}

int main() {
	Line s0,s1;
	int q; 
	cin >> q;
	for (int i = 0;i < q;i++) {
		cin >> s0.p1.x; cin >> s0.p1.y;
		cin >> s0.p2.x; cin >> s0.p2.y;
		cin >> s1.p1.x; cin >> s1.p1.y;
		cin >> s1.p2.x; cin >> s1.p2.y;
		cout <<setprecision(12)<<CrossPoint(s0,s1).x<<" "<<setprecision(12)<<CrossPoint(s0,s1).y<<endl;
	}
}

Measured memory_bytes: 3256
H, W, K = map(int, input().split())

A = []
for _ in range(H):
    A.append(input())

hrange = list(range(H))
wrange = list(range(W))

def check(hvs, wvs):
    c = 0
    for i in range(H):
        if i in hvs:
            continue
        for j in range(W):
            if j in wvs:
                continue
            if A[i][j] == "#":
                c += 1
    return c

res = 0
from itertools import combinations
for h in range(H):
    for w in range(W):
        for hv in combinations(hrange, h):
            for wv in combinations(wrange, w):
                if check(hv, wv) == K:
                    res += 1
print(res)


Measured memory_bytes: 9212
_ = int(input())
a = list(map(int, input().split()))

for i, v in enumerate(a):

    j = i - 1 

    while j >= 0 and a[j] > v:
        a[j+1] = a[j]
        j -= 1

    a[j+1] = v
    print(" ".join(map(str, a)))


Measured memory_bytes: 5596
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define inf 100000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define vll vector<lli>
#define eps 0.000001
#define endl '\n'
#define mo 998244353
 
using namespace std ;
 
#define MAXN 300005

typedef tree<lli,null_type,less<lli>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

int main()
{
//////////
///////////////////////////////////////////

    string s;
    cin>>s;

    lli x=0,y=0;

    for(lli i=0;i<2;i++)
    {
        x*=10;
        x += (s[i]-'0');
    }

    for(lli i=2;i<4;i++)
    {
        y*=10;
        y += (s[i]-'0');
    }

  //  cout<<x<<" "<<y<<endl;

    if(x<=12 && x>=1)
    {
        if(y<=12 && y>=1)
            cout<<"AMBIGUOUS"<<endl;

        else
            cout<<"MMYY"<<endl;
    }

    else
    {
        if(y<=12 && y>=1)
            cout<<"YYMM"<<endl;

        else
            cout<<"NA"<<endl;
    }


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string a, b;
int dp[3005][3005];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie();
    cout.tie();
    cin >> a >> b;
    int aa=a.length();
    int bb=b.length();
    for(int i=1;i<=aa;i++){
        for(int j=1;j<=bb;j++){
            if(i==0 || j==0){
                dp[i][j]=0;
            }
            else if(a[i-1]==b[j-1]){
                dp[i][j]=1+dp[i-1][j-1];
            }
            else{
                dp[i][j]=max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
    deque<char>lcs;
    int x=aa, y=bb;
    while(x>0 and y>0){
        if(a[x-1]==b[y-1]){
            lcs.push_front(a[x-1]);
            x--;
            y--;
        }
        else if(dp[x-1][y]>dp[x][y-1]){
            x--;
        }
        else{
            y--;
        }
    }
    for(int i=0;i<lcs.size();i++){
        cout << lcs[i];
        if(i==lcs.size()-1){
            cout << endl;
        }
    }
}

Measured memory_bytes: 35456
#include<stdio.h>

int main(){
	int t;
	int w[30];
	int n;
	int a,b;
	int i;
	int temp;
	scanf("%d",&t);
	scanf("%d",&n);
	for(i=0;i<t;i++){
		w[i] = i;
	}
	for(i=0;i<n;i++){
		scanf("%d,%d",&a,&b);
		temp = w[a-1];
		w[a-1] = w[b-1];
		w[b-1] = temp;
	}
	for(i=0;i<t;i++){
		printf("%d\n",w[i]+1);
	}
	return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <cstdio>

using namespace std ;

typedef long long LL ;
const int N=1e6+10 ;
const LL P=1e9+7 ;

LL fac[N] , inv[N] ;
inline LL qpow ( LL a , LL b , LL p )
{
	LL res ;
	for ( res=1 ; b ; a=a*a%p,b>>=1 )
		if ( b&1 ) res=res*a%p;
	return res ;
}
inline void init ( int n )
{
	int i ;
	fac[0]=1;
	for ( i=1 ; i<=n ; i++ ) fac[i]=fac[i-1]*i%P;
	inv[n]=qpow(fac[n],P-2,P);
	for ( i=n ; i>=1 ; i-- ) inv[i-1]=inv[i]*i%P;
}

int X , Y ;
int main ()
{
	int i ;
	scanf("%d%d",&X,&Y),init(max(X,Y));
	LL res=0 ;
	for ( i=0 ; i<=X && 2*i<=Y ; i++ )
	{
		int x=X-i , y=Y-2*i ;
		if ( x==y*2 )
			(res+=fac[i+y]*inv[i]%P*inv[y])%=P;
	}
	printf("%lld\n",res);
	return 0 ;
}


Measured memory_bytes: 15744
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for(int i = 1, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

using namespace std;

int main() {
  int N, H;
  cin >> N >> H;
  auto a = vector<int>(N);
  auto b = vector<int>(N);
  REP(i, N) cin >> a[i] >> b[i];

  int max_a = *max_element(ALL(a));
  sort(ALL(b), greater<int>());
  int cnt = 0;
  REP(i, N) {
    if(b[i] < max_a) break;
    H -= b[i];
    cnt++;
    if(H <= 0) break;
  }

  if(H > 0) {
    if(H % max_a == 0) {
      cnt += H / max_a;
    } else {
      cnt += H / max_a + 1;
    }
  }

  cout << cnt << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
using namespace std;
const int N=1e6;
int n,m,head[N+10],tot=0,f[N+10][2];
char s[N+10];
bool ok[N+10];
queue <int> q;
struct data {
    int next,num;
}edge[N+10];
void Add(int u,int v) {
    edge[++tot].next=head[u];
    edge[tot].num=v;
    head[u]=tot;
}
void Solve() {
    for (int i=1;i<=n;i++) {
        for (int j=head[i];j!=-1;j=edge[j].next) {
            int kx=edge[j].num;
            f[i][s[kx]-'A']++;
        }
    }
    for (int i=1;i<=n;i++)
        if (f[i][0]==0||f[i][1]==0) q.push(i);
        else ok[i]=1;
    while (!q.empty()) {
        int k=q.front();
        q.pop();
        for (int i=head[k];i!=-1;i=edge[i].next) {
            int kx=edge[i].num;
            if (!ok[kx]) continue;
            f[kx][s[k]-'A']--;
            if (!f[kx][s[k]-'A']) {
                ok[kx]=0;
                q.push(kx);
            }
        }
    }
    bool ans=0;
    for (int i=1;i<=n;i++) ans|=ok[i];
    if (ans) printf("Yes\n");
    else printf("No\n");
}
int main() {
    memset(head,-1,sizeof(head));
    scanf("%d%d",&n,&m);
    scanf("%s",s+1);
    for (int i=1;i<=m;i++) {
        int u,v;
        scanf("%d%d",&u,&v);
        Add(u,v);
        Add(v,u);
    }
    Solve();
    return 0;
}


Measured memory_bytes: 16000
#include <iostream>
using namespace std;
int main(void){
   int x,y,a;
  
   while (true) {
        cin>>x>>y;
        if(x==0 && y==0){
            break;
        }
    if(y<x){
    a=y;
    y=x;
    x=a;
    }
    cout<<x<<" "<<y<<endl;
   }
}


Measured memory_bytes: 3072
#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()
{
	int n, k;
	cin >> n >> k;
	vector<int> p(n);
	for(int i = 0; i < n; ++i)
	{
		cin >> p[i];
	}
	sort(p.begin(), p.end());

	int ans = 0;
	for(int i = 0; i < k; ++i)
	{
		ans += p[i];
	}
	cout << ans;
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
int main(void) {
int a, i, j, x;
int b[10000];
scanf("%d", &a);
for (i = 0;i < a;i++) {
scanf("%d", &b[i]);
} 
for (j = 0;j < 10000;j++) {
for (i = 0;i < a;i++) {
if (b[i] % 2 == 0) {
b[i] = b[i] / 2;
} else {
break;
} 
} if (b[i] % 2 == 1) {
break;
}
} printf("%d\n", j);
return 0;
}

Measured memory_bytes: 128
#include <iomanip>
#include <iostream>

using namespace std;

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

    double sum = 0;
    for (int i = 1; i <= n; i++) {
        int toss = 0;
        for (int j = i; j < k; j *= 2) {
            toss++;
        }
        sum += 1.0 / ((1 << toss) * n);
    }

    cout << setprecision(12) << fixed << sum << endl;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  if(a < 0 && b < 0) {
    if((b - a) % 2 == 0) cout << "Negative" << endl;
    else cout << "Positive" << endl;
  } else if(a < 0 && b >= 0) {
    cout << "Zero" << endl;
  } else {
    cout << "Positive" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> p;

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <stack>
using namespace std;
using Graph = vector<vector<int>>;

// 探索
vector<bool> seen, finished;

// サイクル復元のための情報
int pos = -1; // サイクル中に含まれる頂点 pos
stack<int> hist; // 訪問履歴

void dfs(const Graph &G, int v, int p) {
  seen[v] = true;
  hist.push(v);
  for (auto nv : G[v]) {
    if (nv == p) continue; // 逆流はNG

    // 完全終了した頂点はスルー
    if (finished[nv]) continue;

    // サイクルを検出
    if (seen[nv] && !finished[nv]) {
      pos = nv;
      return;
    }

    // 再帰的に探索
    dfs(G, nv, v);

    // サイクル検出したらすぐに抜ける
    if (pos != -1) return;
  }
  hist.pop();
  finished[v] = true;
}

int main() {
  // 頂点数 (サイクルを一つ含むグラフなので辺数は N で確定)
  int N; cin >> N;

  // グラフ入力受取
  Graph G(N);
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  // 探索
  seen.assign(N, false);
  finished.assign(N, false);
  dfs(G, 0, -1);

  // サイクルを復元
  set<int> cycle;
  while (!hist.empty()) {
    int t = hist.top();
    cycle.insert(t);
    hist.pop();
    if (t == pos) break;
  }

  // クエリに答える
  int Q; cin >> Q;
  vector<pair<int, int>> queries(Q);
  for (auto& query : queries) {
    int a, b; cin >> a >> b;
    a--; b--;
    query = make_pair(a, b);
  }
  for (auto query : queries) {
    if (cycle.count(query.first) && cycle.count(query.second))
      cout << 2 << endl;
    else
      cout << 1 << endl;
  }
}


Measured memory_bytes: 19868
N, M = map(int, input().split(" "))
s_table = []
for m in range(M):
    line = list(map(int, input().split(" ")))
    s_table.append(line[1:])

p_list = list(map(int, input().split(" ")))
patterns = 0
for state in range(2 ** N):
    s_bits = [bool(state & (2 ** i)) for i in range(N)]
    ramps = 0
    for p, switches in zip(p_list, s_table):
        n = 0
        for s in switches:
            n += s_bits[s - 1]
        if n % 2 == p:
            ramps += 1

    if ramps == M:
        patterns += 1

print(patterns)


Measured memory_bytes: 3064
from collections import defaultdict, deque

INF = 10**12
N, M = map(int, input().split())
E = defaultdict(list)
for _ in range(M):
    a, b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)
dist = [INF]*N
q = deque([(0, 0)])
while q:
    v, d = q.popleft()
    dist[v] = d
    for u in E[v]:
        if dist[u] == INF:
            q.append((u, d+1))
print('POSSIBLE' if dist[N-1] == 2 else 'IMPOSSIBLE')

Measured memory_bytes: 63888
N = int(input())
lst = [input() for P in range(N)]
for i in range(len(lst)-1):
    if lst[i][-1] != lst[i+1][0]:
        print("No")
        exit()
st = set(lst)
if len(st) != len(lst):
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        double r,a,b;
        r = sc.nextDouble();
        a = (r * r * Math.PI);
        b = (2 * r * Math.PI);
        System.out.printf("%.6f %.6f", a, b);
    }
}


Measured memory_bytes: 28464
import sys
input = sys.stdin.readline
n = int(input())
a = [int(input()) for i in range(n)]
a.sort()
b = []
c = []
for i in range(n):
  if i%2:
    b.append(a[i//2])
    c.append(a[i//2+(n+1)//2])
  else:
    b.append(a[i//2+n//2])
    c.append(a[i//2])
if n>=3 and n%2:
  b[-1],b[2] = b[2],b[-1]
  c[0],c[-3] = c[-3],c[0]
ansb = 0
ansc = 0
for i in range(n-1):
  ansb += abs(b[i+1]-b[i])
  ansc += abs(c[i+1]-c[i])
print(max(ansb,ansc))

Measured memory_bytes: 9556
table = [4,1,4,1,2,1,2,1]

def round():
    item = table.pop(0)
    table.append(item)
    
def getRideNum(participants):
    rideNum = 0
    for i in range(0,8):
        n = table[i] - participants[i]
        if n >= 0:
            n = participants[i]
        else:
            n = table[i]
        rideNum += n
    return rideNum
    
def tableToNum(t):
    num = 0
    for i in range(7,-1,-1):
        n = t[i] * pow(10,7 - i)
        num += n
    return num

while(1):
    try:
        participants = list(int(x) for x in input().split())
        maxRideNum = 0
        maxTable = []

        for i in range(0,8):
            rideNum = getRideNum(participants)
            if rideNum > maxRideNum:
                maxRideNum = rideNum
                maxTable = table.copy()
                
            elif rideNum == maxRideNum:
                if tableToNum(table) < tableToNum(maxTable):
                    maxTable = table.copy()
            round()

        for i in range(0,len(maxTable)):
            if i != 0:
                print(" ",end="")
            print(maxTable[i],end="")
        print()
        
    except EOFError:
        break


Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define dd double
#define pb push_back
#define ff first
#define ss second
#define Mp make_pair
const ll Mod=1000000007;
const ll INF=999999999999999999;
const ll NN=(ll)(1e6+5);
ll min(ll x,ll y){if(x<y) return x;return y;}
ll max(ll x,ll y){if(x>y) return x;return y;}
ll power(ll x,unsigned ll y) 
{ 
    if (y==0) 
        return 1; 
    else if (y%2==0) 
        return power(x,y/2)*power(x,y/2); 
    else
        return x*power(x,y/2)*power(x,y/2); 
}
ll hcf(ll a,ll b) 
{ 
    if(b==0) 
        return a; 
    return hcf(b,a%b);  
}
int main()
{
   fio;
   /*#ifndef ONLINE_JUDGE 
    	freopen("input.txt", "r", stdin); 
    	freopen("output.txt", "w", stdout); 
    	freopen("error.txt", "w", stderr); 
   #endif*/
   ll TT=1;
   //cin>>TT;
   while(TT--)
   {
     ll n,x,t;
     cin>>n>>x>>t;
     cout<<((n/x)+(n%x?1:0))*t;
   }
}

Measured memory_bytes: 3644
#include<stdio.h>
#include<iostream>
#include<queue>
#include<cstdio>
using namespace std;

int main(){
	int n,m;
	while(scanf("%d %d",&n,&m),n!=0){
		queue<int> chair;
		for(int i=0;i<n;i++){
			chair.push(i);
		}
		int ans=0;
		while(chair.empty()!=true){
			for(int j=m-1;j--;){
				int n;
				n=chair.front();chair.pop();
				chair.push(n);
			}
			ans=chair.front();chair.pop();
		}
		
		cout<<ans+1<<endl;
	}
	
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
int mod = 1000000007;
const int N = 1e5 + 5;
int ans[N];
int h[N];
char grid[1009][1009];
int ans2[1009][1009];
int hap[N][3];
int ans3[N][3];
int main(){
//    int n,k;
//    cin>>n>>k;
//    for(int i = 0 ; i < n ; i++)cin>>h[i];
//    ans[0]=0;
//
//    for(int i = 1; i < n ; i++){
//        ans[i] = 1e9;
//        for(int j = i-1;j>=max(i-k,0);j--){
//            ans[i] = min(ans[i],abs(h[i]-h[j])+ans[j]);
//        }
//    }
//    cout<<ans[n-1];
//    int n;
//    cin>>n;
//    for(int i = 0 ; i < n ; i++)cin>>h[i];
//
//    for(int i = 0 ; i < n ; i++){
//        ans[i] = 1;
//        for(int j = 0 ; j < i ; j++){
//            if(h[i]>h[j])ans[i] = max(ans[j]+1,ans[i]);
//        }
//    }
//    int mx = 0;
//    for(int i = 0 ; i < n ; i++)if(ans[i]>mx)mx=ans[i];
//    cout<<mx;
//    int h,w;
//    cin>>h>>w;
//    for(int i = 0 ; i < h ; i++){
//        for(int j = 0 ; j < w ; j++)cin>>grid[i][j];
//    }
//    ans2[0][0]=1;
//    for(int i = 0 ; i < h ; i++){
//        for(int j = 0 ; j < w ; j++){
//
//            if(grid[i][j]=='#'){
//                ans2[i][j]=0;
//                continue;
//            }
//            if(j)ans2[i][j] =  ((ans2[i][j]%mod) + (ans2[i][j-1]%mod))%mod;
//            if(i)ans2[i][j] =  ((ans2[i][j]%mod) + (ans2[i-1][j]%mod))%mod;
//        }
//    }
//    cout<<ans2[h-1][w-1];
    int n;
    cin>>n;
    for(int i = 0 ; i < n ; i++){
        for(int j = 0 ; j < 3 ; j++)cin>>hap[i][j];
    }
    ans3[0][0] = hap[0][0]; ans3[0][1] = hap[0][1]; ans3[0][2] = hap[0][2];
    for(int i = 1 ; i < n ; i++){
        ans3[i][0] = max(ans3[i-1][1],ans3[i-1][2])+hap[i][0];
        ans3[i][1] = max(ans3[i-1][0],ans3[i-1][2])+hap[i][1];
        ans3[i][2] = max(ans3[i-1][0],ans3[i-1][1])+hap[i][2];
    }
    cout<<max(ans3[n-1][0],max(ans3[n-1][1],ans3[n-1][2]));
}

Measured memory_bytes: 4352
#include <cstdio>
#include <algorithm>
#include <cstring>
typedef long long ll;

using namespace std;
ll n, x, t;

int main() {
    scanf("%lld%lld%lld", &n, &x, &t);
    ll num = (n + (x - 1)) / x;
    printf("%lld\n", num * t);
    return 0;
}

Measured memory_bytes: 1736