akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <string>
#include<algorithm>
using namespace std;
 

int main(){
    long long N;
    cin >> N;
    if(N%10==9 || (N/10)==9){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N = gets.to_i
a = gets.split.map(&:to_i)
ans = 1
zero = false
over = false
N.times do |i|
    zero = true if a[i] == 0
    ans *= a[i];
    if(1000000000000000000 < ans)
        over = true
        ans = 0
    end
end
if zero
    puts 0
elsif over
    puts -1
else
    puts ans
end

Measured memory_bytes: 21704
day=input().split()
x=int(day[0])
y=int(day[1])

a=1 #月
b=22 #日
c=0
d=0
ans=0

for i in range(x):
	while b<=y :
		c=int(b/10)
		d=b%10
		if a==c*d:
			ans+=1
		b+=1
		if b%10==0:
			b+=2
	a+=1
	b=22
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

using namespace std;
int a, b;

int main() {
	cin >> a >> b;
	if (a <= 9 && b <= 9) {
		cout << a*b<<endl;
		return 0;
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 45

int count = 0;
int fib[N];

void Fib(int n){
  if(count == 0 || count == 1) fib[count] = 1;
  else   fib[count] = fib[count-1] + fib[count-2];

  if(count == n){
    printf("%d\n", fib[count]);
    return;
  }
  
  count++;

  Fib(n);
}

int main(){
  int n;

  scanf("%d", &n);

  Fib(n);

  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	register int f=1,k=0;register char c=getchar();
	while (c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
	while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();
	return k*f;
}
const int maxn=2e5+100;
struct mc{int val,pos;}store[maxn];
int a[maxn],f[maxn],mx,p,value;
bool vis[maxn];
inline bool cmp(const mc&a,const mc&b){return a.val<b.val;}
int main()
{
	int n=read(),pre=0,rear=0,ans=0;
	for (register int i=1,tmp;i<=n;i++)tmp=read(),f[tmp]=f[tmp-1]+1,f[tmp]>mx&&(mx=f[tmp]);
	cout << n-mx<<endl;
//	for (register int i=1;i<=n;i++)cout <<a[i]<<" ";puts("");
//	for (register int i=1;i<=n;i++)cout << a[i]-i<<" ";puts("");
//	for (register int i=1;i<=n;i++)cout << i%10 <<" ";
	/*
	for (register int i=1;i<=n;i++)
	store[i].pos=i,a[i]=store[i].val=read(),
	a[i]==a[i-1]+1?(f[i]=f[i-1]+1):(f[i]=1),f[i]>mx&&(mx=f[i],p=i,value=a[i]);
	for (register int i=p-mx+1;i<=p;i++)vis[i]=1;
	sort(store+1,store+1+n,cmp);
	for (register int i=1;i<p-mx+1;i++)
	if (a[i]>value[i])
	printf("%d\n",pre+rear);*/
}

Measured memory_bytes: 1024
n = int(input())
dp = [float("Inf") for _ in range(n)]
ary = list(map(int,input().split()))
dp[0] = 0
for i in range(n-1):
    dp[i+1] = min(dp[i+1],abs(ary[i]-ary[i+1])+dp[i])
    if  i +2 <= n-1:
        dp[i+2] = min(dp[i+2],abs(ary[i]-ary[i+2])+dp[i])
print(dp[n-1])

Measured memory_bytes: 17460
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const ll LIM = 1e9+4;
ll find(ll X){
    ll l=0, r=LIM;
    while(r-l>1){
        ll m =(l+r)/2;
        if(m*m < X) l=m;
        else r=m;
    }
    return l;
}

ll solve(){
    ll a,b;
    cin >>a >>b;
    if(a>b) swap(a,b);

    ll x = find(a*b);

    ll ans = x;
    if(a<=x) --ans;

    ll y = (a*b-1)/(x+1);
    ans += y;
    if(b<=y) --ans;

    // dbg(x);
    // dbg(y);
    return ans;
}

int main(){
    int Q;
    cin >>Q;
    rep(i,Q) cout << solve() << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    int N; cin >> N;

    int ans = 0, dp[N + 1] = {};
    REP(i, 0, N) {
        int p; cin >> p;
        dp[p] = dp[p - 1] + 1;
        ans = max(ans, dp[p]);
    }

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

Measured memory_bytes: 1152
h,w=gets.split.map(&:to_i)
c=[]
10.times do
  c << gets.split.map(&:to_i)
end
10.times do |k|
  10.times do |i|
    10.times do |j|
      c[i][j]=c[i][k]+c[k][j] if c[i][j]>c[i][k]+c[k][j]
    end
  end
end
l=[0]*11
h.times do
  a=gets.split.map(&:to_i)
  a.each do |aa|
    l[aa]+=1
  end
end
ans=0
10.times do |i|
  ans+=l[i]*c[i][1]
end
puts ans

Measured memory_bytes: 14312
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
//added two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set] 
//(2)set.order_of_key(k)[count of elements strictly less than k]
typedef vector< int > vi;
typedef vector< ll > lvi;
typedef vector< vi > vvi;
typedef vector< lvi > lvvi;
typedef pair< int,int > ii;
typedef pair< ll,ll > lii;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)//remember i is an iterator
#define present(c,x) ((c).find(x) != (c).end())//for sets,maps,multimaps
#define cpresent(c,x) (find(all(c),x) != (c).end())//for vectors
#define tc(t) int (t); cin>>(t);while((t)--)
#define ff first
#define ss second
#define mp make_pair
#define ld long double
#define ull unsigned long long int
#define mod 1000000007
int mark[200000]={0}; // 1 is important
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
	ll r,c,n;
	cin>>r>>c>>n;
	set<int> st[4];
	map<ii,int> id;
	for (int i = 1; i <= n; ++i)
	{
		int x,y,ct=0;
		cin>>x>>y;
		id[{x,y}]=i;
		if(y==0) st[0].insert(x);
		if(x==r) st[1].insert(y);
		if(y==c) st[2].insert(-1*x);
		if(x==0) st[3].insert(-1*y);
		if(x==0 || y==0 || x==r || y==c) ct++;
		cin>>x>>y;
		id[{x,y}]=i;
		if(y==0) st[0].insert(x);
		if(x==r) st[1].insert(y);
		if(y==c) st[2].insert(-1*x);
		if(x==0) st[3].insert(-1*y);
		if(x==0 || y==0 || x==r || y==c) ct++;
		if(ct==2) mark[i]=1;
	}
	stack<int> sta;
	tr(st[0],it)
	{
		if(*it==r) continue;
		int tmp=id[{*it,0}];
		if(mark[tmp])
		{
			if(!sta.empty())
			{
				if(sta.top()==tmp)
				sta.pop();
				else sta.push(tmp);
			}
			else sta.push(tmp);
		}
	}
	tr(st[1],it)
	{
		if(*it==c) continue;
		int tmp=id[{r,*it}];
		if(mark[tmp])
		{
			if(!sta.empty())
			{
				if(sta.top()==tmp)
				sta.pop();
				else sta.push(tmp);
			}
			else sta.push(tmp);
		}
	}
	tr(st[2],it)
	{
		if((-1*(*it))==0) continue;
		int tmp=id[{-1*(*it),c}];
		if(mark[tmp])
		{
			if(!sta.empty())
			{
				if(sta.top()==tmp)
				sta.pop();
				else sta.push(tmp);
			}
			else sta.push(tmp);
		}
	}
	tr(st[3],it)
	{
		if((-1*(*it))==0) continue;
		int tmp=id[{0,-1*(*it)}];
		if(mark[tmp])
		{
			if(!sta.empty())
			{
				if(sta.top()==tmp)
				sta.pop();
				else sta.push(tmp);
			}
			else sta.push(tmp);
		}
	}
	if(sta.empty()) cout<<"YES\n";
	else cout<<"NO\n";
	return 0;
}

Measured memory_bytes: 22912
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

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

		// 整数の入力
		int n = sc.nextInt();
		int k = sc.nextInt();
		int cnt = 0;
		boolean isExists = false;

		ArrayList<Integer> arrN = new ArrayList<Integer>();

		for (int i = 1; i < n + 1; i++) {
			arrN.add(i);
		}

		Collections.sort(arrN);

		for (int i = 0; i < arrN.size(); i = i + 2) {
			cnt++;

			if (cnt == k) {
				isExists = true;
			}
		}

		if (isExists) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

		sc.close();
	}
}


Measured memory_bytes: 21844
#include "bits/stdc++.h"

using namespace std;


#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define int long long

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

template <typename T>

void print(T x)
{
	std::cout << x <<" " ;
}


signed main(void) {
	int N;
	cin >> N  ;
  
	vector<int> A, X;
	A.resize(N);
	X.resize(N);
  
	rep(i, N) {
		cin >> A[i];
	}
  
	int sum = 0;
  
	rep(i, N) {
		if (i % 2 == 0) {
			sum += A[i];
		}
		else {
			sum -= A[i];
		}
	}
	X[0] = sum ;
	rep1(i, N) {
		X[i] = 2*A[i - 1] - X[i - 1];
	}
	rep(i, N) {
		print(X[i]);
	}
}

Measured memory_bytes: 2816
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;

int main()
{
	long long int A, B,N,i,j,k,l,m;
	cin >> N;
	if (N < 105)
		cout << 0 << endl;
	else if(N<135)
		cout << 1 << endl;
	else if(N<165)
		cout << 2 << endl;
	else if(N<189)
	cout << 3 << endl;
	else if(N<195)
		cout << 4 << endl;
	else
		cout << 5 << endl;
    return 0;
}



Measured memory_bytes: 256
def main():
    S = input()

    dict = {
        'SUN': 7,
        'MON': 6,
        'TUE': 5,
        'WED': 4,
        'THU': 3,
        'FRI': 2,
        'SAT': 1,
    }
    print(dict[S])

if __name__ == '__main__':
    main()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++) //(i, 0, n)でi=0~n-1までn回
#define REPn(i, a, n) for(int i=a; i<=n; i++) //(i, 1, n)でi=1~nまでn回
#define sortv(v) sort(v.begin(), v.end());
#define sortg(v) sort(v.begin(), v.end(), greater<>());
#define rev(v) reverse(v.begin(), v.end()); //逆順に並べ替え

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

Measured memory_bytes: 256
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v), std::end(v)
#define REP(i, k) for (std::decay_t<decltype(k)> i = 0; i < k; i++)
#define LOOP(k) REP (ngtkana_is_a_genius, k)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T, class U> using pair = std::pair<U, T>;
template <class T> using diag_pair = std::pair<T, T>;
template <class... Args> using tuple = std::tuple<Args...>;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/
template <class F>
class fixed_point {
    F f;
    public:
    fixed_point(F&& f_) : f(f_) {}
    template <class... Args> auto operator() (Args... args) { return f(f, args...); }
};
template <class F> auto make_fixed_point(F&& f) { return fixed_point<F>(std::forward<F&&>(f)); }
int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    u32 n; std::cin >> n;
    vec<vec<u32>> g(n);
    LOOP (n-1) {
        u32 u, v; std::cin >> u >> v, u--, v--;
        g.at(u).push_back(v);
        g.at(v).push_back(u);
    }

    vec<u32> dp(n);
    make_fixed_point([&](auto&& dfs, u32 x, u32 p) -> void {
        auto&& v = g.at(x);
        for (u32 y: v) if (y!=p) {
            dfs(dfs, y, x);
            dp.at(x) ^= dp.at(y);
        }
        dp.at(x)++;
    })(0, 0);
    std::cout << (dp.at(0)!=1 ? "Alice" : "Bob") << '\n';
}


Measured memory_bytes: 18520
#include <iostream>
#include <vector>

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

    std::vector<int> W(N);
    for (int i = 0; i < N; i++)
        std::cin >> W[i];
    for (int i = 1; i < N; i++)
        W[i] += W[i - 1];

    int ans = 1 << 30;
    for (int i = 0; i < N - 1; i++) {
        int S1 = W[i];
        int S2 = W.back() - W[i];
        ans = std::min(ans, std::abs(S1 - S2));
    }
    std::cout << ans << "\n";
}

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

int main(){
   int A, B, C, D, ans;
   cin >> A >> B >> C >> D;
  if (A <= B) { ans = A; }
  else { ans = B; }
  if (C <= D) { ans = ans + C; }
  else { ans = ans + D; }
  cout << ans;
}
  


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

int main() {
    int N, C;
    cin >> N >> C;

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

    int c[N][N];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> c[i][j];
            c[i][j]--;
        }
    }

    int cost[3][C];
    fill(cost[0], cost[3], 0);
    for (int k = 0; k < C; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                cost[(i + j) % 3][k] += D[c[i][j]][k];
            }
        }
    }

    int ans = 1e9;
    for (int i = 0; i < C; i++) {
        for (int j = 0; j < C; j++) {
            for (int k = 0; k < C; k++) {
                if (i != j && j != k && k != i) {
                    int sum = cost[0][i] + cost[1][j] + cost[2][k];
                    ans = min(ans, sum);
                }
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1280
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const N = input[0][0];

  return `ABC${N.padStart(3, "0")}`;
};

console.log(main(read()));


Measured memory_bytes: 29660
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
#define ll long long
int n;
ll store[200010],ans=0;

signed main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>store[i];
	sort(store,store+n);
	for(int i=0;i<n/2;i++)swap(store[i],store[n-1-i]);
	n-=2;
	ans+=store[0];
	int cur=1;
	while(n>0){
		if(n==1){ans+=store[cur];break;
		}
		ans+=store[cur]*2;
		n-=2;
		cur++;
	}
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 5184
# ABC142E - Get Everything
def main():
    N, M = map(int, input().split())
    p, INF = 1 << N, 1 << 60
    # bitDP of minimum cost to buy the subset of items represented by a binary
    dp = [INF] * p
    dp[0] = 0
    for _ in range(M):
        a, _ = map(int, input().split())
        x = sum(1 << (i - 1) for i in map(int, input().split()))
        for y in range(p):
            dp[x | y] = min(dp[x | y], dp[y] + a)
    ans = dp[-1] if dp[-1] != INF else -1
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	static void solve(){//Here is the main function
		ArrayList<String> s = nextCharArray();
		if(s.get(s.size() - 1).equals("s")){
			s.add("e");
		}
		s.add("s");
		myout(myconv(s, 0));
	}
	//Method addition frame start



	//Method addition frame end

	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	@SuppressWarnings("unchecked")
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
}


Measured memory_bytes: 33360
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <queue>
#define rep0(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i) 
const long long INF = 1000000007;
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	/*
	/
	/
	/
	*/
	int a, b, c;
	cin >> a >> b >> c;
	if (a <= c && c <= b)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;

}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template<typename T> void print(const T & v);


int main() {
    int N;
    cin >> N;
    vector<int> a(N + 1, 0);
    rep(i, N) cin >> a[i + 1];
    vector<int> b = a;
    for(int i = N / 2; i > 0; i--){
        int cnt = 0;
        for(int j = i; j <= N; j += i){
            if(b[j] == 1){
                cnt++;
            }
        }
        if(cnt % 2 == a[i]){
            b[i] = a[i];
        }else{
            b[i] = (a[i] + 1) % 2;
        }
    }
    int m = 0;
    vector<int> ans;
    for(int i = 1; i <= N; i++){
        if(b[i]){
            ans.emplace_back(i);
            m++;
        }
    }
    cout << m << endl;
    print(ans);
    return 0;

}


// Use For Debug
template <typename T>
void print(T const & v){
    for(int i = 0; i < v.size(); i++){
        if(i) cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 3192
import numpy as np
n,m=list(map(int,input().split()))
a=np.array(list(map(int,input().split())))
b=np.zeros(n)

mod = 2*n

tmp = 0
for i in range(mod):
  if b[tmp] == 2:
    break
  b[tmp] += 1
  tmp = a[tmp] -1
  
s = len(a[b==1])
t = len(a[b==2])

if m > s:
  m = (m-s)%t + s
tmp = 0
for i in range(m):
  tmp = a[tmp] -1
  
print(tmp+1)
  

Measured memory_bytes: 51036
#include <iostream>
#include <vector>

int main(){
    long a, b;
    std::cin >> a >> b;

    int diff = b - a;
    int val = 0;
    for(long i = 1; i <= diff; ++i){
        val += i;
    }

    std::cout << val - b << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,a,b;cin>>n>>a>>b;
  cout<<min(a*n,b)<<endl;

  return 0;

}


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

int main(void)
{
    string s,t;
    cin >> s >> t;
    bool f = true;
    for (int i = 0;i < s.size();i++)
    {
        if (s[i] != t[i]) f = false;
    }

    cout << (f? "Yes":"No") << endl;
    
    return 0;
}


Measured memory_bytes: 3640
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <ratio>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;
template<class T> using v = vector<T>;
template<class T, class U> using p = pair<T, U>;

#define REP(i, n) for(int i = 0; i < n; ++i)

template<class T> T read() { T x{}; cin >> x; return x; }
template<class T> v<T> read(int N){ v<T> x(N); REP(i, N) cin >> x[i]; return x; }

template<class T>
void write(const T &x){ cout << x << endl; }
void write(double x){ printf("%.15f\n", x); }

const ull MOD = 1000'000'007;


int main(){
    ll N, X, D;
    cin >> N >> X >> D;

    if(D == 0){
        if(X == 0){ write(1);}
        else{ write(N + 1); }
    } else {
        if(D < 0){ X = -X; D = -D; }
        map<ll, set<p<ll, ll>>> range;
        for(ll k = 0; k <= N; ++k){
            ll offset = (k * X);
            ll s = k * (k - 1) / 2;
            ll e = (N - 1 + N - k) * k / 2 + 1;
            ll key = (offset % D + D) % D;
            range[key].insert({offset + D * s, offset + D * e});
            //cout << key << ", "<<  s << ", " << e << endl;
        }

        ll ans = 0;
        for(auto & r : range){
            ll last_s = r.second.begin()->first;
            for(auto & seg : r.second){
                last_s = max(last_s, seg.first); 
                ans += max(0LL, (seg.second - last_s) / D);
                last_s = max(last_s, seg.second);
            }
        }
        write(ans);
    }
}



Measured memory_bytes: 31488
#include <bits/stdc++.h>
using namespace std;
int read();

int n, x[2003], y[2003], cnt;
long long len[102];

void solve(long long x, long long y) {
    for (int i = 1; i <= cnt; ++i)
        (abs(x) > abs(y)) ? ((x < 0) ? (x += len[i], putchar('L'))
                                     : (x -= len[i], putchar('R')))
                          : ((y < 0) ? (y += len[i], putchar('D'))
                                     : (y -= len[i], putchar('U')));
    puts("");
}

int main() {
    n = read();
    for (int i = 1; i <= n; ++i) {
        x[i] = read(), y[i] = read();
        if ((x[i] + y[i] & 1) != (x[1] + y[1] & 1)) return puts("-1"), 0;
    }

    for (int i = 35; i >= 0; --i) len[++cnt] = 1ll << i;
    if (!(x[1] + y[1] & 1)) len[++cnt] = 1;
    printf("%d\n", cnt);
    for (int i = 1; i <= cnt; ++i) printf("%lld ", len[i]);
    puts("");
    for (int i = 1; i <= n; ++i) solve(x[i], y[i]);
    return 0;
}
const int _SIZE = 1 << 22;
char ibuf[_SIZE], *iS = ibuf, *iT = ibuf;
#define gc                                                         \
    (iS == iT ? iT = ((iS = ibuf) + fread(ibuf, 1, _SIZE, stdin)), \
     (iS == iT ? EOF : *iS++) : *iS++)
int read() {
    int x = 0, f = 1;
    char c = gc;
    while (!isdigit(c)) f = (c == '-') ? -1 : f, c = gc;
    while (isdigit(c)) x = x * 10 + c - '0', c = gc;
    return x * f;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/diverta2019/tasks/diverta2019_c

n = gets.to_i
res = 0

def is_left(word)
  word[0] != 'B' && word[-1] == 'A'
end

def is_mid(word)
  word[0] == 'B' && word[-1] == 'A'
end

def is_right(word)
  word[0] == 'B' && word[-1] != 'A'
end


lefts = []
rights = []
mids = []
words = []

n.times do
  word = gets.chomp
  res += word.scan('AB').size
  if is_left(word)
    lefts << word
  elsif is_mid(word)
    mids << word
  elsif is_right(word)
    rights << word
  end
  words << word
end

minsize = [lefts.size, rights.size].min

if mids.size == 0
  res += minsize
elsif lefts.size + rights.size == 0
  res += mids.size - 1
else
  res += [lefts.size, rights.size].min + mids.size
end

puts res

Measured memory_bytes: 3068
#include<bits/stdc++.h>
#define ll long long
#define MOD 1000000007
const int N = 3000;
using namespace std;
ll factorialNumInverse[N + 1]; 

// array to precompute inverse of 1! to N! 
ll naturalNumInverse[N + 1]; 

// array to store factorial of first N numbers 
ll fact[N + 1]; 
void InverseofNumber(ll p) 
{ 
	naturalNumInverse[0] = naturalNumInverse[1] = 1; 
	for (int i = 2; i <= N; i++) 
		naturalNumInverse[i] = naturalNumInverse[p % i] * (p - p / i) % p; 
} 
// Function to precompute inverse of factorials 
void InverseofFactorial(ll p) 
{ 
	factorialNumInverse[0] = factorialNumInverse[1] = 1; 

	// precompute inverse of natural numbers 
	for (int i = 2; i <= N; i++) 
		factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p; 
} 

// Function to calculate factorial of 1 to N 
void factorial(ll p) 
{ 
	fact[0] = 1; 

	// precompute factorials 
	for (int i = 1; i <= N; i++) { 
		fact[i] = (fact[i - 1] * i) % p; 
	} 
} 

// Function to return nCr % p in O(1) time 
ll Binomial(ll N, ll R, ll p) 
{ 
	// n C r = n!*inverse(r!)*inverse((n-r)!) 
	ll ans = ((fact[N] * factorialNumInverse[R]) 
			% p * factorialNumInverse[N - R]) 
			% p; 
	return ans; 
} 

int main()
{
  ll n;
  cin>>n;
  ll p = MOD;
  InverseofNumber(p); 
  InverseofFactorial(p); 
  factorial(p); 
  ll ans = 0;
  if(n <= 2)
  {
    cout<<0<<"\n";
  }
  else
  {
    for(ll i = 1;i <= n/3;i++)
    {
      ll d = n - 3*i;
      ans = (ans + Binomial(d+i-1,i-1,MOD))%MOD;
    }
    cout<<ans<<"\n";
  }
}
  

Measured memory_bytes: 3680
H,W = [int(x) for x in input().split()]
ans = []
for i in range(H):
  cnt= 0
  S = list(input())
  for j in range(W):
    if S[j]==".":
      cnt +=1
  if cnt!=W:
    ans.append(S)
ans1 = []
for j in range(len(ans[0])):
  cnt = 0
  for i in range(len(ans)):
    if ans[i][j]==".":
      cnt+=1
  if cnt ==len(ans):
    ans1.append(j)
for i in range(len(ans)):
  for j in ans1:
    ans[i][j]=0
for i in range(len(ans)):
  for j in range(len(ans[0])):
    if ans[i][j] !=0:
    	print(ans[i][j],end="")
  print()

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

#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)
 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    ll N;
    cin >> N;
    vector<vector<ll>> A(N,vector<ll>(2));

    rep(i,N) {
        ll x,y;
        cin >> x >> y;
        A[i][0] = x;
        A[i][1] = y;
    }

    set<P> S;
    rep(i,N) {
        rep(j,N) {
            if (i==j) continue;
            int p = A[j][0]-A[i][0];
            int q = A[j][1]-A[i][1];
            P tmp = make_pair(p,q);
            S.insert(tmp);
            tmp = make_pair(-p,-q);
            S.insert(tmp);
        }
    }
    int ans = 0;
    for (auto s:S){
        int p = s.first;
        int q = s.second;
        int tmp = 0;
        rep(i,N) {
            rep(j,N) {
                if (i==j) continue;
                if (A[i][0]-A[j][0]==p && A[i][1]-A[j][1]==q) {
                    tmp++;
                }

            }
        }
        ans = max(ans,tmp);
    }
    ans = N-ans;
    cout << ans << endl;

}

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


//最大公約数
ll gcd(ll a, ll b) {
	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

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



// ABC131C - Anti-Division
// https://atcoder.jp/contests/abc131/tasks/abc131_c
void ABC131C() {
	ll A, B, C, D;
	cin >> A >> B >> C >> D;

	ll num = B - A + 1; //A～Bの数値の個数
	ll c = B / C - (A - 1) / C; //[0～BまでのCで割り切れる数値の個数] - [0～A-1までのCで割り切れる数値の個数]
	ll d = B / D - (A - 1) / D; //[0～BまでのDで割り切れる数値の個数] - [0～A-1までのDで割り切れる数値の個数]

	ll lcm_cd = lcm(C,D); //CとDの最小公倍数 : CD
	ll cd = B / lcm_cd - (A - 1) / lcm_cd; //[0～BまでのCDで割り切れる数値の個数] - [0～A-1までのCDで割り切れる数値の個数]

	//cout << "num     : " << num << endl;
	//cout << "c       : " << c   << endl;
	//cout << "d       : " << d   << endl;
	//cout << "lcm_cd  : " << lcm_cd << endl;
	//cout << "cd      : " << cd  << endl;

	ll ans = num - c - d + cd;
	cout << ans << endl;
}

int main() {
	ABC131C();

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
using namespace std;
using ll = long long;
#define in(v) v; cin >> v;
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)

int main() {
  int in(N); int in(M);

  vector<ll> sum(N+1, 0);
  map<ll, int> m;
  ++m[0];
  rep(i, N) {
    ll in(a);
    sum[i+1] = sum[i] + a;
    sum[i+1] %= M;
    ++m[sum[i+1]];
  }
  ll ans = 0;
  rep(i, N)
    ans += --m[sum[i+1]];
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4992
// g++ -std=gnu++1y -O2 main.cpp

#include <cassert>
#include <cstdio>
#include <vector>
#include <set>

#include <map>
#include <unordered_map>
#include <string>
#include <utility>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <climits>

using namespace std;

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

const int INF = 1e9;
const long long LINF = 1e18;

int main() {
	int N;
	cin >> N;

	long long sum = 0;
	for (int i = 1; i <= N; i++)
	{
		if ((i % 3) == 0 && (i % 5) == 0) {
			continue;
		}
		else if ((i % 3) == 0) {
			continue;
		}
		else if ((i % 5) == 0) {
			continue;
		}
		else {
			sum += i;
		}
	}

	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<stdlib.h>
 
int main(){
  int d[100], N, a, i, j, num;
  scanf("%d", &N);
  for(i=0; i<N; i++){
    scanf(" %d", &a);
    d[i]=a;
    if(i==0)
      num=1;
    else
      for(j=0; j<i; j++){
//        if(i==0){num=1; break;}
        if(d[j]==d[i])break;
        if(j==i-1)num++;
      }
  }
  printf("%d\n", num);
}

Measured memory_bytes: 128
#include<iostream>
#include<queue>
using namespace std;
typedef pair<int, int> P;
const int MAX_N = 1000;
const int MAX_M = 1000;
const int MAX_T = 9;
const int INF = 100000000;
int n, m, t;
int sx, sy;
int ans = 0;
char field[MAX_N][MAX_M];
int d[MAX_N][MAX_M];
P factory[MAX_T];
int dx[4] = {0, -1, 0, 1}, dy[4] = {-1, 0, 1, 0};

//从当前起点&#24320;始，&#23547;找第num个&#22902;酪 
int bfs(int x, int y, int num){
	int gx = factory[num].first;
	int gy = factory[num].second;
	queue<P> que;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			d[i][j] = INF;
		}
	}
	d[x][y] = 0;
	que.push(P(x,y));
	
	while(que.size()){
		P p = que.front();
		que.pop();
		int x = p.first;
		int y = p.second;
		if(x == gx && y == gy){
			break;
		}
		for(int i = 0; i < 4; i++){
			int nx = x + dx[i], ny = y + dy[i];
			if(nx >= 0 && nx < n && ny >= 0 && ny < m && field[nx][ny] != 'X' && d[nx][ny] == INF){
				d[nx][ny] = d[x][y] + 1;
				que.push(P(nx, ny));
			}
		}
	}
	
	return d[gx][gy];
}

void solve(){
	cin >> n >> m >> t;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			cin >> field[i][j];
			if(field[i][j] == 'S'){
				factory[0] = P(i, j);
			}
			if(field[i][j] >= '1' && field[i][j] <= '9'){
				int index = field[i][j] - '0';
				factory[index] = P(i, j);
			}
		}
	}

	int ans = 0;
	
	for(int i = 0; i < t; i++){
		int x = factory[i].first;
		int y = factory[i].second;
		ans += bfs(x, y, i + 1);
	}
	cout << ans << "\n";
}

int main(){
	solve();
}

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

#define ll long long 
#define sz(x) (int)x.size()

using namespace std;

int main(){
	int n,m,x;
	cin>>n>>m>>x;
	vector<int>c(n);
	vector<vector<int>>v;
	for(int i=0;i<n;i++){
		cin>>c[i];
		vector<int>a(m);
		for(int j=0;j<m;j++)cin>>a[j];
		v.push_back(a);
	}
	int ans=1e9;
	for(int mask=1;mask<(1<<n);mask++){
		int cur=0;
		vector<int>b(m,0);
		for(int i=0;i<n;i++){
			if(!(mask&(1<<i)))continue;
			cur+=c[i];
			for(int j=0;j<m;j++){
				b[j]+=v[i][j];
			}
		}
		bool ok=1;
		for(int i=0;i<m;i++){
			if(b[i]<x)ok=0;
		}
		if(ok)ans=min(ans,cur);
	}
	cout<<(ans==1e9?-1:ans);
}


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

int main() {
  bool flag = true;
  int64_t n, a, b, time; cin >> n;
  vector<pair<int64_t, int64_t>> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    vec.at(i) = make_pair(b,a);
  }
  sort(vec.begin(), vec.end());
  for (int i = 0; i < n; i++) {
    time += vec.at(i).second;
    if (time > vec.at(i).first) {
      flag = false;
    }
  }
  if (flag) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}



Measured memory_bytes: 3328
import java.util.Scanner;

class Main {
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);

    int A = sc.nextInt();
    int B = sc.nextInt();

      if (A + B >= 24 ) {
        System.out.println(A + B - 24);
      }
      else {
        System.out.println(A + B);
      }

  }
}


Measured memory_bytes: 21844
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int count = 0;
        for (int i = 1; Math.pow(i + a, n) <= m; i++) {
            int x = (int)(Math.pow(i + a, n));
            int y = getCount(x);
            if (y == i) {
                count++;
            }
        }
        System.out.println(count);
    }
    
    static int getCount(int x) {
        int count = 0;
        while (x > 0) {
            count += x % 10;
            x /= 10;
        }
        return count;
    }
}



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

int main(){
    int n, A[1000];
    cin >> n;
    for ( int i = 0; i < n; i++ ) cin >> A[i];
    
    for ( int i = 0; i < n; i++ ){
        int v = A[i];
        int j = i - 1;
        while ( j >= 0 && A[j] > v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        for ( int l = 0; l < n; l++) {
            if (l) cout << " ";
            cout << A[l];
        }
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3080
N=int(input())
bin_a="".join(["{:060b}".format(a) for a in map(int, input().split())])
mod=10**9+7
xor=0
for d in range(60):
  ones=bin_a[59-d::60].count('1')
  xor+=2**d*ones*(N-ones)    
print(xor%mod)

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  map<ll, ll> mp;
  ll n,k;cin>>n>>k;
  while(n--){
    ll a,b;
    cin>>a>>b;
    mp[a]+=b;
  }
  ll sum=0;
  for (auto& kv : mp) {
    sum+=kv.second;
    if(k<=sum){
      cout<<kv.first<<endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
int num,n,s,ans;
int solve(int a,int dp,int sum);

int main(){
    while(1){
    cin >> n >> s;
    if(n==0&&s==0)break;
    cout << solve(0,0,0) << endl;
    }
return 0;
}

int solve(int c,int dp,int sum){
    if(dp==10){
        if(sum==s&&c==n)return 1;
        return 0;
    }
    return solve(c,dp+1,sum)+solve(c+1,dp+1,sum+dp);
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdlib>

using namespace std;

int search(int *A, int N, int key) {
    A[N] = key;
    for (int i = 0; i < N; i++) {
        if (A[i] == key) {
            return 1;
        } 
    }
    return 0;
}

int main() {
    int q, N, key;
    int sum = 0;

    cin >> N;
    int *A = (int *)malloc(sizeof(int) * (N + 1));
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> key;
        if (search(A, N, key)) {
            sum++;
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3080
#include <cstdio>
#include <algorithm>
static const int MAXN = 102;

int n, a[MAXN];

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

    int ans = 0x7fffffff, cur;
    for (int i = -100; i <= 100; ++i) {
        cur = 0;
        for (int j = 0; j < n; ++j) cur += (a[j] - i) * (a[j] - i);
        ans = std::min(ans, cur);
    }
    printf("%d\n", ans);

    return 0;
}


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

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Mll = M<ll, ll>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin(),ie=(c).rend();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

struct UFTree {
    static const int MAX_N = 1e6;
    int p[MAX_N], r[MAX_N], s[MAX_N];

    UFTree(int n): p(), r(), s() {
        for(int i = 0; i < n; ++i) {
            p[i] = i;
            r[i] = 0;
            s[i] = 1;
        }
    }

    int root(int x) {
        return p[x] == x ? x : (p[x] = root(p[x]));
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if(x == y) return;

        if(r[x] < r[y]) {
            p[x] = y;
            s[y] = s[x] + s[y];
        } else {
            p[y] = x;
            s[x] = s[x] + s[y];
            if(r[x] == r[y]) r[x]++;
        }
    }

    int size(int x) {
        return s[root(x)];
    }
};

int n;

int main() {
    cin >> n;
    VVi adj(n);
    REP(i, n-1) {
        int a, b; cin >> a >> b;
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    Vi parent(n, -1);
    queue<int> q;
    q.push(0);
    parent[0] = 0;
    while (!q.empty()) {
        int node = q.front();
        q.pop();
        for (auto x: adj[node]) {
            if (parent[x] != -1) continue;
            parent[x] = node;
            q.push(x);
        }
        if (parent[n-1] != -1) break;
    }

    Vi path = {n-1};
    while (path.back() != 0) {
        path.push_back(parent[path.back()]);
    }
    int confnode = path[path.size()/2-1];

    UFTree t = UFTree(n);
    q = queue<int>();
    q.push(0);
    while (!q.empty()) {
        int node = q.front();
        q.pop();
        for (auto x: adj[node]) {
            if (t.same(0, x) || x == confnode) continue;
            t.unite(0, x);
            q.push(x);
        }
    }

    int s = t.size(0);
    if (s > n-s) {
        cout << "Fennec" << '\n';
    } else {
        cout << "Snuke" << '\n';
    }

    return 0;
}


Measured memory_bytes: 18296
#include <stdio.h>
#include <math.h>

int main () {
    double ans=0;
    double x1,y1,x2,y2;
    scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
    ans=sqrt(pow(x1-x2,2)+pow(y1-y2,2));
    printf("%.8lf",ans);
}


Measured memory_bytes: 2112
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

#define REP(i, n) for(int i=0; i<n; i++)

int n;
vector<int> s;
int c = 0;

int main(){
    cin >> n;
    REP(i, n){
        int si;
        cin >> si;
        s.push_back(si);
        c += si;
    }

    sort(s.begin(), s.end());
    
    int output = 0;
    if(c%10!=0){
        cout << c << endl;
    } else {
        REP(i, n){
            if((c-s[i])%10 != 0){
                output = c - s[i];
                break;
            }
        }
        cout << output << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int n=10000,a,b,na,nb,i;
    while(n!=0){
    	na=0;nb=0;
    	scanf("%d",&n);
    	if(n!=0){
    	for(i=0;i<n;i++){
    		scanf("%d %d",&a,&b);
    		if(a<b){nb=nb+a+b;}
    		else if(a>b){na=na+a+b;}
    		else {na=na+a;nb=nb+b;}
    	}
    	printf("%d %d\n",na,nb);
    	}
    }
    return 0;
}

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

int main()
{
	int N, K, n, x[101] = { 0 };
	int ball[101] = { 0 };

	cin >> N >> K;

	int ans = 0;

	for (int i = 1; i <= N; i++)
	{
		cin >> n;
		ball[i] = n;
	}

	for (int i = 1; i <= N; i++)
	{
		if (K - ball[i] < ball[i])
			ans += (K - ball[i]) * 2;
		else
			ans += ball[i] * 2;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int k = sc.nextInt();
        String str = sc.next();

        if(str.length() <= k){
            System.out.println(str);
        }
        else{
            char[] strChar = new char[k];
            for(int i = 0; i<k; i++){
                strChar[i] = str.charAt(i);
            }
            String makeStr = "";
            for(int j = 0; j<k; j++){
                makeStr += strChar[j];
            }
            System.out.println(makeStr + "...");
        }
    }
}

Measured memory_bytes: 39612
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(void){
    int n;

    cin >> n;

    if(n % 2 ==0){
        cout << n << endl;
        return 0;
    }
    else{
        cout << 2 * n << endl;
        return 0;
    }
    
    return 0;
       
}

Measured memory_bytes: 256
#include<cstdio>

int main(){
	int a[128] = {};
	char ch;

	while (scanf("%c", &ch) != EOF){
		a[int(ch)]++;

	}

	for (int j = 0; j < 26; j++){
		printf("%c : %d\n", j+97, a[j+97]+a[j+65]);
	}

	return 0;
}


Measured memory_bytes: 2684
a=input()
n=len(a)
s=[]
sb=0

for i in range(n):
  s.append(a[i])
b=s.count("B")
w=n-b
fb=int((2*n-b-1)*b/2)

for i in range(n):
  if s[i]=="B":
    sb+=i

print(fb-sb)

Measured memory_bytes: 5096
from collections import deque
H,W,K= map(int,input().split())
sx,sy,gx,gy = map(int,input().split())
sx-=1;sy-=1;gx-=1;gy-=1 #0index
Pond = []
for i in range(H):
  temp = str(input())
  temp = list(temp)
  Pond.append(temp)
#print(Pond)
INF = float("inf")
reach = [[INF for _ in range(W)] for _ in range(H)]
reach[sx][sy] = 0
dxdy = [(1,0),(-1,0),(0,1),(0,-1)]
Q = deque([(sx,sy)])
while Q:
  x,y = Q.popleft()
  #print(x,y)
  #step = reach[x][y]
  for j in range(4):
    for i in range(1,K+1):
      fac = i
      nx = x+fac*dxdy[j][0]
      ny = y+fac*dxdy[j][1]
      #print(nx,ny)
      if nx<0 or nx>=H or ny<0 or ny>= W or Pond[nx][ny] == "@":
        break
      if reach[x][y]+1 > reach[nx][ny]: #すでに余裕をもって到達済み
        break
      if reach[x][y]+1 < reach[nx][ny]:
        reach[nx][ny] = min(reach[x][y]+1,reach[nx][ny])
        Q.append((nx,ny))
      if nx == gx and ny == gy:
        #print(reach)
        print(reach[nx][ny])
        exit()
print(-1)

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

const int INF = 1e9;

typedef pair<int, int> P;

char field[52][52];
int h, w;
int d[52][52];

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

int bfs() {
    queue<P> que;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            d[i][j] = INF;
        }
    }
    que.push(P(0, 0));
    d[0][0] = 0;

    while (que.size()) {
        P p = que.front(); que.pop();
        if (p.first == h - 1 && p.second == w - 1)
            break;

        for (int i = 0; i < 4; i++) {
            int nx = p.first + dx[i], ny = p.second + dy[i];
            if (nx >= 0 && nx < h && ny >= 0 && ny < w && field[nx][ny] == '.' && d[nx][ny] == INF) {
                que.push(P(nx, ny));
                d[nx][ny] = d[p.first][p.second] + 1;
            }
        }
    }
    return d[h - 1][w - 1];
}

int main() {
    cin >> h >> w;
    int ws = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> field[i][j];
            if (field[i][j] == '.')
                ws++;
        }
    }
    if (bfs() == INF)
        cout << "-1" << endl;
    else
        cout << ws - bfs() - 1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    double pi = 3.141592653589;
    double r;
    scanf("%lf", &r);

    double area, circumference;

    area = pi * r * r;
    circumference = 2.0 * pi * r;

    printf("%lf %lf", area, circumference);

    return 0;
}



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

int divcount(int n)
{
    int ret = 0;
    for(int i = 1; i*i <= n; i++){
        if(!(n % i)){
            ret++;
            if(n != i*i) ret++;
        }
    }

    return ret;
}

int main()
{
    int n; cin >> n;
    int ans = 0;

    for(int i = 1; i <= n; i += 2){
        if(divcount(i) == 8) ans++;
    }

    cout << ans << endl;
    return 0;
}


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

#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, j, n) for(int i=j;i<n;i++)
#define COUT(n) cout<<n<<"\n"

typedef long long ll;
const int INF = 1000000000;

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

    ll s; cin >> s;

    ll diff = s - floor(sqrt(s)) * floor(sqrt(s));

    ll x1 = INF, y1 = 1;
    ll x2 = (INF - s%INF)%INF,  y2 = (s + INF - 1)/INF;

    cout << "0  0 " << x1 << " " << y1 << " " << x2 << " " << y2 << "\n";
    return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    int i, n, j;
    cin >> s;
    n=s.size()-1;
    j=n;
    for(i=0;i<n;i++){
        if(s[i]!=s[j]){
            cout << "No" <<endl;
            return 0;
        }
        j--;
        if(i>=j) break;
    }
    j=(n-1)/2;
    for(i=0;i<n;i++){
        if(s[i]!=s[j]){
            cout << "No" <<endl;
            return 0;
        }
        j--;
        if(i>=j) break;
    }
    j=n;
    for(i=(n+2)/2;i<n;i++){
        if(s[i]!=s[j]){
            cout << "No" <<endl;
            return 0;
        }
        j--;
        if(i>=j) break;
    }
    cout << "Yes" <<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int flag=0;
    int count=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]%2==0)
        {
            flag++;
            if(a[i]%6==0||a[i]%5==0)
            {
                count++;
            }
        }
    }
    if(flag==count)
        {
            cout<<"APPROVED";
        }
        else
        {
            cout<<"DENIED";
        }
}

Measured memory_bytes: 256