akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
//#include<bits/extc++.h>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pll pair<LL,LL>
#define pdd pair<double,double>
#define pb push_back
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-6
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define pi acos(-1)
#define index Index
#define Line pll
typedef long long LL;
LL dp[1<<21];
int mod=1e9+7;
int main(){
    int n;
    scanf("%d",&n);
    dp[0]=1;
    vector<int> v[25];
    for(int i=0;i<(1<<n);i++){
        v[__builtin_popcount(i)].pb(i);
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            int x;
            scanf("%d",&x);
            if(x==1){
                for(auto it:v[i]){
                    if(it&(1<<j));
                    else{
                        dp[it|(1<<j)]+=dp[it];
                        dp[it|(1<<j)]%=mod;
                    }
                }
            }
        }
    }
    printf("%lld\n",dp[(1<<n)-1]);
}


Measured memory_bytes: 26044
import sys

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

X = I()
print('Yes' if X >= 30 else 'No')

Measured memory_bytes: 61768
# Shiritori
N = gets.chomp.to_i
W = []
count = 1
flg = true
for i in N.times do
    W.push(gets.chomp.split("").map(&:to_s))
end
for i in 0..N-1 do #ルール１を実装
    for j in 0..N-1 do
        if W[i].join("") == W[j].join("") && i != j
            flg = false
        end
    end
end

for i in 0..N-1 do #ルール２の判定実装
    if i != 0 
        if W[i][0] == W[i-1][W[i-1].length-1]
            count = count + 1
        end
    end
end

if flg == true && count == N
    puts "Yes"
else
    puts "No"
end

Measured memory_bytes: 2812
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <assert.h>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,a) for(ll i=ll(a-1);i>=0;--i)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}

const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll EPS = 1e-10;
int sgn(const double a){
    return (a < -EPS ? -1 : (a > EPS ? +1 : 0));
}
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> tri;
typedef pair<double,double> point;
typedef complex<double> Point;
const ll MAX = 30000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    //cin.tie(0);
    //ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> l(n);
    cins(all(l));
    SORT(l);
    ll cnt = 0;
    rep(i,n-2){
        rep(j,i+1,n-1){
            rep(k,j+1,n){
                if (l[i]+l[j] > l[k] && l[i] != l[j] && l[j] != l[k] && l[i] != l[k]){
                    cnt++;
                }
            }
        }
    }
    PRINT(cnt);
}


Measured memory_bytes: 3624
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn cnt357(n: u64, x: u64) -> u64 {
    let mut ans = 0;
    for i in vec![3, 5, 7] {
        let y = 10 * x + i;
        if y <= n {
            ans += 1 + cnt357(n, y);
        }
    }
    ans
}

fn cnt35(n: u64, x: u64) -> u64 {
    let mut ans = 0;
    for i in vec![3, 5] {
        let y = 10 * x + i;
        if y <= n {
            ans += 1 + cnt35(n, y);
        }
    }
    ans
}

fn cnt37(n: u64, x: u64) -> u64 {
    let mut ans = 0;
    for i in vec![3, 7] {
        let y = 10 * x + i;
        if y <= n {
            ans += 1 + cnt37(n, y);
        }
    }
    ans
}

fn cnt57(n: u64, x: u64) -> u64 {
    let mut ans = 0;
    for i in vec![5, 7] {
        let y = 10 * x + i;
        if y <= n {
            ans += 1 + cnt57(n, y);
        }
    }
    ans
}

fn cnt3(n: u64, x: u64) -> u64 {
    let mut ans = 0;
    let y = 10 * x + 3;
    if y <= n {
        ans += 1 + cnt3(n, y);
    }
    ans
}

fn cnt5(n: u64, x: u64) -> u64 {
    let mut ans = 0;
    let y = 10 * x + 5;
    if y <= n {
        ans += 1 + cnt5(n, y);
    }
    ans
}

fn cnt7(n: u64, x: u64) -> u64 {
    let mut ans = 0;
    let y = 10 * x + 7;
    if y <= n {
        ans += 1 + cnt7(n, y);
    }
    ans
}

fn main() {
    let n: u64 = read();
    let ans = cnt357(n, 0) + cnt3(n, 0) + cnt5(n, 0) + cnt7(n, 0)
        - cnt35(n, 0)
        - cnt37(n, 0)
        - cnt57(n, 0);
    println!("{}", ans);
}


Measured memory_bytes: 4352
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	k, _ := strconv.Atoi(sc.Text())
	if n%k == 0 {
		fmt.Println(0)
	} else {
		fmt.Println(1)
	}
}


Measured memory_bytes: 640
#include <stdio.h>
int main() {char Tex[105];int i=0,j,k=0;bool one_per=false;while (1) {k++;Tex[i]=getchar();if (Tex[i]=='(' || Tex[i]=='[') i++,one_per=false; else if (Tex[i]==')') {j=(i)?i-1:0;i+=(Tex[j]=='(')?-1:1;one_per=false;}
    else if (Tex[i]==']') {j=(i)?i-1:0;i+=(Tex[j]=='[')?-1:1;one_per=false;} else if (Tex[i]=='.' && k==1) one_per=true; else if (Tex[i]=='\n' || Tex[i]==EOF) {if (one_per==true) return 0;if (i) puts("no"); else puts("yes");k=0,i=0,one_per=false;}}}

Measured memory_bytes: 0
N = int(input())
A, B = map(int, input().split())
P = list(map(int, input().split()))

q_a = []
q_b = []
q_c = []

for p in P:
    if p <= A:
        q_a.append(p)
    elif p <= B:
        q_b.append(p)
    else:
        q_c.append(p)

ans = 0
while q_a:
    q_a.pop()
    if q_b:
        q_b.pop()
    else:
        break
    if q_c:
        q_c.pop()
    else:
        break
    ans += 1
print(ans)


Measured memory_bytes: 9116
n = int(input())

d = 'abcdefghijklm'


def conv(s):
    s = list(map(lambda x: d[x], s))
    return ''.join(s)


def dfs(s, k):
    if len(s) == n:
        print(s)
    else:
        for i in range(k):
            dfs(s+d[i], k)
        dfs(s+d[k], k+1)


dfs('a', 1)


Measured memory_bytes: 57816
#include <bits/stdc++.h>
#define newl "\n"
using namespace std;
using lli = long long int;
using vvint = vector <vector <int>>;
const int mod = 1e9 + 7;

void solve(){
	int x;
	cin >> x;
	if(x >= 30) cout << "Yes" << newl;
	else cout << "No" << newl;

	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(10);
	#ifdef EXECUTE_LOCALLY
		   freopen("in.txt","r",stdin);
	#endif
	int t = 1;
	//cin >> t;
	while(t--) solve();
	#ifdef EXECUTE_LOCALLY
    	cout << setprecision(3) << "program time: " << (double)clock() / CLOCKS_PER_SEC << newl;
	#endif
	return 0;
}


Measured memory_bytes: 3632
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
                
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pretime float(clock()-clk)/CLOCKS_PER_SEC
#define max2(a,b) ((a)>(b) ? (a) : (b))   
#define min2(a,b) ((a)<(b) ? (a) : (b)) 
#define rep(i,a,b) for(i=a;i<=b;++i)
#define rev(i,a,b) for(i=a;i>=b;--i) 
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define lli long long int 
#define ins insert
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PI 3.14159265
#define mod 1000000007
#define inf 1000000000000000

using namespace std;
typedef vector<lli>   vll;
typedef vector<int>   vi;
typedef set<lli>      sll;
typedef set<int>      si;
typedef pair<lli,lli> pll;
typedef pair<int,int> pii;
clock_t clk=clock();       

int i,j;
void solve(void);

int main()
{
  speedio;
   int t=1;  
  // cin>>t;
   while(t--)
     solve();

  return 0;
}
//
void solve()
{
	int n; cin>>n;
	string s[n];
	rep(i,0,n-1) cin>>s[i];

	vi ct1,ct2,ct3,ct4;
	rep(i,0,n-1)
	{
	  int len=sz(s[i]);
      if(s[i][0]=='B' && s[i][len-1]!='A')
      	 ct1.pb(i);
      else if(s[i][0]!='B' && s[i][len-1]=='A')
      	ct2.pb(i);
      else if(s[i][0]=='B' && s[i][len-1]=='A')
      	ct3.pb(i);
      else ct4.pb(i);

	}

   string t;
   if(sz(ct2))
   {
     t+=s[ ct2[ sz(ct2)-1 ] ];
     ct2.pop_back();
   }

   rep(i,0,sz(ct3)-1)
     t+=s[ ct3[i] ];

   if(sz(ct1))
   {
     t+=s[ ct1[ sz(ct1)-1 ] ];
     ct1.pop_back();
   }

   while(sz(ct1) && sz(ct2))
   {
   	 t+=s[ ct2[ sz(ct2)-1 ] ];
   	 t+=s[ ct1[ sz(ct1)-1 ] ];
   	 ct2.pop_back();
   	 ct1.pop_back();
   }

   if(sz(ct2))
   	  rep(i,0,sz(ct2)-1)
   	   t+=s[ ct2[i] ];
   else 
   	  rep(i,0,sz(ct1)-1)
   	    t+=s[ ct1[i] ];

   	rep(i,0,sz(ct4)-1)
   	t+= s[ ct4[i] ];

   int ct=0;
   rep(i,0,sz(t)-2)
     if(t[i]=='A' && t[i+1]=='B')
     	 ++ct;

// cout<<"\n"<<t;
 cout<<ct<<"\n";
}

Measured memory_bytes: 1024
local mod = 1000000007
local mfl = math.floor

local function bmul(x, y)
  local x1, y1 = mfl(x / 31623), mfl(y / 31623)
  local x0, y0 = x - x1 * 31623, y - y1 * 31623
  return (x1 * y1 * 14122 + (x1 * y0 + x0 * y1) * 31623 + x0 * y0) % mod
end

local function badd(x, y)
  return (x + y) % mod
end

local function bsub(x, y)
  return x < y and x - y + mod or x - y
end

local function modpow(src, pow)
  local res = 1
  while 0 < pow do
    if pow % 2 == 1 then
      res = bmul(res, src)
      pow = pow - 1
    end
    src = bmul(src, src)
    pow = mfl(pow / 2)
  end
  return res
end

local function modinv(src)
  return modpow(src, mod - 2)
end

local fact = {1}
local invs = {1}
local invfact = {1}
for i = 2, 2000000 do
  fact[i] = bmul(fact[i - 1], i)
  invs[i] = bmul(mfl(mod / i), mod - invs[mod % i])
  invfact[i] = bmul(invfact[i - 1], invs[i])
end

local function getComb(n, k)
  if k == 0 or k == n then return 1 end
  return bmul(fact[n], bmul(invfact[k], invfact[n - k]))
end

local pow25 = {1}
local pow26 = {1}
for i = 2, 2000010 do
  pow25[i] = bmul(pow25[i - 1], 25)
  pow26[i] = bmul(pow26[i - 1], 26)
end

local k = io.read("*n", "*l")
local s = io.read()
local n = #s
local ret = 0
for j = 0, k do
  local z = getComb(n + j - 1, n - 1)
  z = bmul(z, pow25[j + 1])
  local rem = k - j
  z = bmul(z, pow26[rem + 1])
  ret = badd(ret, z)
end
print(ret)


Measured memory_bytes: 86688
def isprime(n)
  i = 6
  while i <= Math.sqrt(n)
    return false if n % i == 0
    i += 2
    return true if not (i < n)
    return false if n % i == 0
    i += 5
  end
  return true
end

def compute(target)
  ans = {}
  i   = 6
  while i <= target
    if target % i == 0 and isprime(i)
      ans[i] = 1
    end
    i += 2
    break unless i < target
    if target % i == 0 and isprime(i)
      ans[i] = 1
    end
    i += 5
  end
  if ans.keys.empty?
    puts "#{target}: #{target}"
  else
    puts "#{target}: #{ans.keys.sort.join(" ")}"
  end
end

while n = gets
  n = n.to_i
  break if n == 1
  compute(n)
end

Measured memory_bytes: 8924
function main(lines) {
  const R = n();
  
  const ans = 2 * R * Math.PI;
  
  return ans;
}



const lines = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");

let lineCount = 0;
const s = () => lines[lineCount++];
const n = () => Number(s());
const b = () => BigInt(s());
const sa = () => s().split(' ');
const na = () => sa().map(Number);
const ba = () => sa().map(BigInt);

const ans = main(lines);
console.log( ans );

Measured memory_bytes: 29684
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  int n,ans = 0;
  string s;
  cin >> n >> s;
  for(int i=0;i<n-2;i++){
    if(s.at(i) == 'A' && s.at(i+1) == 'B' && s.at(i+2) == 'C'){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main(void){
  int n;
  while(cin >> n){
    int t[n];
    long long ret=0;
    for(int i=0;i<n;i++)cin >> t[i];
    sort(t,t+n);
    for(int i=0;i<n;i++) ret += t[i]*(n-i);
    cout << ret << endl;
  }
}

Measured memory_bytes: 0
chomp($input = <STDIN>);
($n, $k) = split(/ /, $input);

for (1 .. $k){
	chomp($d = <STDIN>);
	chomp($input = <STDIN>);
	for $i (split(/ /, $input)){
		$f{$i} = 1;
	}
}
$r = 0;
for $i (1 .. $n){
	$r++ if($f{$i} != 1);
}

print "$r\n";

Measured memory_bytes: 4836
using System;
class Program
{
	static void Main(string[] args)
	{
        string[] input = Console.ReadLine().Split(' ');
		int a = int.Parse(input[0]);
		int b = int.Parse(input[1]);
		if (a*b % 2 == 0) {
		    Console.WriteLine("Even");
		} else {
		    Console.WriteLine("Odd");
		}
	}
}

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


class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        String s=sc.next();
        int n=s.length();
        s="0"+s+"0";
        int ans=n;
        for(int i=0;i<=n;++i){
            if(s.charAt(i)!=s.charAt(i+1)){
                ans=Math.min(ans,Math.max(i,n-i));
            }
        }
        out.println(ans);
        out.close();
    }
    // http://codeforces.com/blog/entry/7018
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 25300
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define F first
#define S second
#define mod 1000000007
#define INF 9000000000000000000
signed main(void){
    string s,t;cin>>s>>t;
    vector<int>Al[26];
    rep(i,s.size()){
        Al[s[i]-'a'].push_back(i);
    }
    int ans=0;int now=-1;
    bool res=true;
    rep(i,t.size()){
        int c=t[i]-'a';
        //cout<<i<<':';
        if(Al[c].size()==0){res=false;break;}
        if(Al[c][Al[c].size()-1]<=now){
            //cout<<s.size()-now+Al[c][0]<<endl;
            ans+=s.size()-now+Al[c][0];
            now=Al[c][0];
        }
        else {
            ans+=*upper_bound(all(Al[c]),now)-now;
            //cout<<*upper_bound(all(Al[c]),now)-now<<endl;
            now=*upper_bound(all(Al[c]),now);
        }
    }
    if(res)cout<<ans<<endl;
    else cout<<-1<<endl;
}



Measured memory_bytes: 1724
#include<bits/stdc++.h>
using namespace std;
int main(){
    vector<int>s;
    for(int i = 0;i < 3;i++){
     int x;
      cin >> x;
      s.push_back(x);
    }
  	sort(s.begin(),s.end());
	int ans = 0;
    for(int i = 0;i < 2;i++){
      ans+=abs(s[2-i]-s[1-i]);
    }
  	cout << ans << endl;
  	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int M=stdIn.nextInt();
		int X=stdIn.nextInt();
		int C[]=new int[N];
		int A[][]=new int[N][M];
		boolean key[]=new boolean[N];
		int min=10000000;
		for(int i=0;i<N;i++){
			C[i]=stdIn.nextInt();
			for(int j=0;j<M;j++){
				A[i][j]=stdIn.nextInt();
			}
		}
		for(int i=0;i<Math.pow(2,N);i++){
			int a=i,cout=0,ans=0;
			int b[]=new int[M];
			for(int j=0;j<N;j++){
				if(a%2==1)
					key[j]=true;
				a/=2;
			}
			for(int j=0;j<N;j++){
				if(key[j]){
					ans+=C[j];
					for(int k=0;k<M;k++){
						b[k]+=A[j][k];
						if(b[k]>=X){
							cout++;b[k]=-10000000;
						}
					}
				}
			}
			key=new boolean[N];
			if(cout==M&&ans<min)
				min=ans;
		}
		if(min==10000000)
			System.out.println(-1);
		else
			System.out.println(min);
	}
}


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

const string YES = "YES";
const string NO = "NO";

void solve(long long A, long long B, long long X){
    if((A+B) >= X && A <= X) cout << YES << endl;
    else cout << NO << endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long X;
    scanf("%lld",&X);
    solve(A, B, X);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)

//変数
string n;

//解法
void solve() {

	int ans = 0;
	if (n[0] == '1') {
		ans += 900;
	}
	else {
		ans += 100;
	}
	if (n[1] == '1') {
		ans += 90;
	}
	else {
		ans += 10;
	}
	if (n[2] == '1') {
		ans += 9;
	}
	else {
		ans += 1;
	}
	cout << ans;

	return;
}

int main() {
	//入力
	cin >> n;
	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int arr[2000];
int main()
{
    int n,ans=0;
    cin>>n;
    for(int i=0;i<2*n;i++)
        cin>>arr[i];

    sort(arr,arr+2*n);
    for(int i=0;i<2*n;i+=2)
    {
        ans+=arr[i];
        //cout<<arr[i]<<" ";
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
import           Control.Applicative
import           Control.Monad
import           Data.IORef

while :: IO Bool -> IO () -> IO ()
while condIO exe = do
  cond <- condIO
  when cond $ do
    exe
    while condIO exe

setNth :: IORef [a] -> (Int, a) -> IO ()
setNth listRef (idx, newV)= do
  list <- readIORef listRef
  writeIORef listRef (list `set` (idx, newV))
  where
    set :: [a] -> (Int, a) -> [a]
    set []     _      = []
    set (x:xs) (0, v) = v:xs
    set (x:xs) (n, v) = x : xs `set` (n-1, v)

printList :: Show a => [a] -> IO ()
printList a = putStrLn $ unwords . map show $ a

main :: IO ()
main = do
  _ <- getLine
  a <- map read . words <$> getLine

  aRef <- newIORef a
  vRef <- newIORef (undefined :: Int)
  jRef <- newIORef (undefined :: Int)
  a <- readIORef aRef


  forM_ [1.. length a-1] $ \i -> do
    a <- readIORef aRef
    printList a
    writeIORef vRef (a !! i)
    writeIORef jRef (i-1)
    while (do
      j <- readIORef jRef
      a <- readIORef aRef
      v <- readIORef vRef
      return $ j >= 0 && (a !! j) > v) $ do

        j <- readIORef jRef
        a <- readIORef aRef
        aRef `setNth` (j+1, a !! j)
        modifyIORef jRef pred

    j <- readIORef jRef
    v <- readIORef vRef
    aRef `setNth` (j+1, v)
    return ()

  a <- readIORef aRef
  printList a

  return ()

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

struct Graph {
    struct Vertex { int n, k; };
    struct Edge { int i, n; };
    Graph(int n, int m) : v(n, { -1, -1 }), e(m), n(n), m(0), b(0) {}
    void add_edge(int i, int j) {
        e[m] = { j, v[i].n };
        v[i].n = m;
        m++;
    }
    void dfs(int i, int p, int k) {
        if (v[i].k < 0) v[i].k = k; else { b |= k != v[i].k; return; }
        for (int j = v[i].n; j >= 0; j = e[j].n) {
            Edge& o = e[j];
            if (o.i == p) continue;
            dfs(o.i, i, k ^ 1);
        }
    }
    int64_t foo() {
        int64_t k = 0;
        int c[2] = {};
        for (int i = 0; i < n; i++) {
            c[v[i].k]++;
        }
        for (int i = 0; i < n; i++) {
            int l = 0;
            for (int j = v[i].n; j >= 0; j = e[j].n) {
                l++;
            }
            k += c[v[i].k ^ 1] - l;
        }
        return k / 2;
    }
    vector<Vertex> v;
    vector<Edge> e;
    int n, m;
    int b;
};

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

    int n, m;
    cin >> n >> m;

    Graph g(n, m * 2);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;

        g.add_edge(a, b);
        g.add_edge(b, a);
    }

    g.dfs(0, -1, 0);

    if (g.b) {
        cout << (int64_t)n * (n - 1) / 2 - m << endl;
    } else {
        cout << g.foo() << endl;
    }

    return 0;
}

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

int main(){
  int N,count=-1,figure=1;
  cin>>N;
  vector<int> a(N);
  for(int i=0; i<N; i++){
    cin>>a.at(i);
    if(a.at(i)==figure){
      count++;
      figure++;
    }
  }
  
  cout<<(count>=0?N-count-1:count)<<endl;
}
  

Measured memory_bytes: 4032
#include <stdio.h>
int DFS(int);
int A[100][2],a[100][100];
int t=0;
int n;
int main(){
  int i,j,u,k,v;
  scanf("%d",&n);
  for(i=0;i<100;i++)
    for(j=0;j<100;j++)
      a[i][j]=0;
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      a[u-1][v-1]=1;
    }
  }
  for(i=0;i<n;i++)
    if(A[i][0]==0){
      t++;
      DFS(i);
    }
  for(i=0;i<n;i++)
    printf("%d %d %d\n",i+1,A[i][0],A[i][1]);
  return 0;
}

int DFS(int m){
  int i;
  A[m][0]=t;
  for(i=0;i<n;i++)
    if(a[m][i]==1&&m!=i&&A[i][0]==0){
      t++;
      DFS(i);
    }
  t++;
  A[m][1]=t;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
   int N;
   cin >> N;
   
   int n = N;
   int L[10] = {};
   int i = 0;
   int a = 0;
   while (n--){
       cin >> L[i];
       a += L[i];
       i++;
   }
   
   i = 0;
   int max_L = 0;
   while(N--){
       max_L = max(max_L,L[i]);
       i++;
   }
   if(max_L*2<a){
       cout << "Yes" << endl;
   }else{
       cout << "No" << endl;
   }
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>

using namespace std;

#define PRINT(a) cout<<(a)<<endl;

int main() {
	string a, b;
	cin >> a >> b;
	if (a == "H"&&b == "H") { PRINT("H"); }
	else if (a == "D"&&b == "D") { PRINT("H"); }
	else PRINT("D");
	return 0;
}


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

int main() 
{
    int n;
    cin>>n;
    double m;
    cin>>m;
    int a[n];
    int sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    double z= (1/(4*m))*sum;
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]>=z)
        cnt++;
    }
    if(cnt>=m)
    cout<<"Yes"<<"\n";
    else
    cout<<"No"<<"\n";

	return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte(){
        if(ptr < buflen){
            return true;
        }else{
            ptr = 0;
            try{
                buflen = in.read(buffer);
            }catch(IOException e){
                e.printStackTrace();
            }
            if(buflen <=0){
                return false;
            }
        }
        return true;
    }

    private int readByte(){
        if(hasNextByte())return buffer[ptr++];
        else return -1;
    }

    private static boolean isPrintableChar(int c){
        return 33<=c && c<=126;
    }
    public boolean hasNext(){
        while(hasNextByte() && !isPrintableChar(buffer[ptr]))ptr++;
        return hasNextByte();
    }

    public String next(){
        if(!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong(){
        if(!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        if(b < '0' || '9' < b){
            throw new NumberFormatException();
        }
        while(true){
            if('0' <= b && b<='9'){
                n*=10;
                n+=b-'0';
            }else if(b==-1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt(){
        long nl = nextLong();
        if(nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDoutble(){return Double.parseDouble(next());}
}
public class Main {
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int n = fs.nextInt();
        double[] p = new double[n];
        for(int i=0;i<n;i++)p[i] = fs.nextDoutble();

        double[][] dp = new double[n+1][n+1];
        dp[0][0] = 1;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                dp[i+1][j+1]+=dp[i][j]*p[i];
                dp[i+1][j]+=dp[i][j]*(1-p[i]);
            }
        }
        double res = 0;
        for(int j=0;j<=n;j++){
            if(j > n-j){
                res+=dp[n][j];
            }
        }
        
        System.out.println(res);

    }
    
}

Measured memory_bytes: 132436
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<stdio.h>
#include<stack>
#include<stdlib.h>
using namespace std;
//stack実装
int top;int S[1000];
void push(int n){
    
    S[++top]=n;//top++だとだめ
}
int pop(){
    top--;
    return S[top+1];
}
int main(){
    int a,b;
    top=0;
    char s[100];
    
    while(scanf("%s",s)!=EOF){
        if(s[0]=='+'){
            a=pop();b=pop();
            push(a+b);
        }else if(s[0]=='*'){
            a=pop();b=pop();
            push(a*b);
        }else if(s[0]=='-'){
            a=pop();b=pop();
            push(b-a);
        }else {
            push(atoi(s));
        }
    }
    printf("%d\n",pop());
    
    
    

return 0;
}


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

int main()
{
	int N, H, W;
	cin >> N >> H >> W;
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		int A, B;
		cin >> A >> B;
		cnt += (A >= H && B >= W);
	}
	cout << cnt << endl;
	return 0;
}


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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

//AtCoder解説動画(https://www.youtube.com/watch?v=TdR816rqc3s&feature=youtu.be)からもらった
struct UnionFind {
	vector<int> d;
	UnionFind(int n=0): d(n,-1) {} //このコロンってなんですか
	int find(int x){
		if (d[x] < 0) return x; //x:根
		return d[x] = find(d[x]);//x:子 -> xの親の根を返す
	}
	bool unite(int x, int y) {
		x = find(x); y = find(y);//根同士をくっつける。
		if ( x ==  y) return false ; 
		/*連結成分が一致してるんだったらfalse返す。
		  minimum spanning tree (クラスカル法と言うのをやるときに、くっつけたかどうかを取れると嬉しい.
		  chmin/chmaxみたいなノリかな
		 */
		if ( d[x] > d[y]) swap(x,y);//xの方が大きいようにする（ただしサイズは負デモっているので不等号が逆）
		d[x] += d[y] ; //xにyをくっつける.
		d[y] = x;
		return true; 
	}
	bool same(int x, int y) { return find(x) == find(y) ; }
	int size(int x) { return -d[find(x)];}
};
int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> K(n);
	vector<int> L(n);
	UnionFind uf(m+1); // 言語をUnionfind
	rep(i,n){
		int k;
		cin >> k;
		K[i] = k;
		rep(j,k){
			int lan;
			cin >> lan;
			if(j==0){
				L[i] = lan;
			} else {
				uf.unite(L[i],lan);
			} 
		}
	}
	rep(i,n){
		if(uf.same(L[0],L[i])){
		} else {
			puts("NO");
			return 0;
		}
	}
	puts("YES");
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int n, tt, l, b;
  while (cin >> n >> tt >> l >> b, n) {
    vector<int> tp(n + 1);
    while (l--) {
      int i;
      cin >> i;
      tp[i] = 1;
    }
    while (b--) {
      int i;
      cin >> i;
      tp[i] = 2;
    }
    vector<vector<double>> p(tt + 2, vector<double>(n + 1));
    p[0][0] = 1;
    for (int t = 0; t < tt; ++t) {
      for (int i = 0; i < n; ++i) {
        for (int j = 1; j <= 6; ++j) {
          int to = i + j;
          if (to > n) {
            to = 2 * n - to;
          }
          if (tp[to] == 0) {
            p[t + 1][to] += p[t][i] / 6;
          } else if (tp[to] == 1) {
            p[t + 2][to] += p[t][i] / 6;
          } else {
            p[t + 1][0] += p[t][i] / 6;
          }
        }
      }
      p[t + 1][n] += p[t][n];
    }
    cout << p[tt][n] << '\n';
  }
}



Measured memory_bytes: 3368
#include <cstdio>
#include <queue>

using namespace std;

queue<pair<int,int>> q;
bool vis[50][100005];

int main() {
    int x,i,sum,m;

    scanf("%d",&x);

    q.push({0,0});
    while (!q.empty()) {
        sum = q.front().first;
        m = q.front().second;
        q.pop();

        if (vis[sum][m])
            i = 0;
        else
            i = 1;

        while (i < 10) {
            if (sum + i <= 45 && !vis[sum + i][(m * 10) % x + i]) {
                vis[sum + i][(m * 10) % x + i] = true;
                q.push({sum + i,(m * 10) % x + i});
            }

            i++;
        }
    }

    for (i = 0;i < 50;i++) {
        if (vis[i][0])
            break;
    }

    printf("%d\n",i);

    return 0;
}


Measured memory_bytes: 19768
#include <stdio.h>

int main(void) {

  int a, b;

  scanf("%d %d", &a, &b);

  if (a > b) {
    printf("a > b\n");
  } else if (a == b) {
    printf("a == b\n");
  } else {
    printf("a < b\n");
  }

  return 0;
}



Measured memory_bytes: 2140
#include<iostream>
using namespace std;
int main()
{
  //定義
  int n;
  //Nをインプット
  cin >> n;
  //n個の配列
  double a[n];
  //配列に標準入力を入れる
  for(int i = 0; i<n; ++i){
  cin >> a[i];
  }
  
  //配列内の数字の逆数を計算して、一つずつ足していきたい
 double answer;
  answer = 0;
  	for(int i = 0; i<n; ++i){
    	answer += (1/a[i]);  
    }
  answer = 1/ answer;
  cout << answer <<endl;
    		return 0;
             
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=0; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define F first
#define S second

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;

int main()
{
  string s ;
  cin >> s ;
  int n = s.size() ;
  vector<int> vec(n) ;
  vector<int> cpr(n-2) ;
  
  REP(i,n-2){
    vec.at(i) = (s.at(i)-'0')*100+(s.at(i+1)-'0')*10+(s.at(i+2)-'0')*1 ;
    cpr.at(i) = abs(753 - vec.at(i)) ;
  }
  
  sort(ALL(cpr)) ;
  
  cout << cpr.at(0) <<endl ;

  return 0 ;
}




Measured memory_bytes: 256
import java.util.*;
public class Main{

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
		int h = s / 3600;
		s %= 3600;
		int m = s / 60;
		s %= 60;
		System.out.printf("%d:%d:%d\n", h, m, s);
	}

}



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

using namespace std;

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

int H, W, K;
char grid[10][10];

int main() {
    cin >> H >> W >> K;

    rep(i, H) rep(j, W) cin >> grid[i][j];
    
    int count = 0;
    rep(p, pow(2, H)) rep(q, pow(2, W)) {
        int num_black = 0;
        rep(i, H) rep(j, W) {
            if (grid[i][j] != '#') continue;
            if (p >> i & 1 && q >> j & 1) num_black++;
        }
        if (num_black == K) count++;
    }
    
    cout << count << endl;
}


Measured memory_bytes: 3948
import java.util.*;

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

        int k = sc.nextInt();
        int x = sc.nextInt();

        if (x <= k * 500) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21716
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
// r#"2018 218"# => "Yes",
// r#"2763 0"# => "No",
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        a: usize,
        b: usize,
        c: usize,
    }

    if a + b >= c {
        "Yes"
    } else {
        "No"
    }.to_string()
}

Measured memory_bytes: 4352
# -*- coding: utf-8 -*-
from itertools import combinations
s = input()

ret = 0
for i in range(len(s)):
    for c in combinations(range(1, len(s)), i):
        e = s
        for idx,j in enumerate(c):
            e = e[:idx+j]+"+"+e[idx+j:]
        exec("ret+="+e)
print(ret)


Measured memory_bytes: 3060
/*
Author: Dynamic JQ

Problem:

Time & Date(start):

Verdict:

Tags:
Implementation
Brute force
Graphs
	Dfs and similar
		DFS order
		Topological sort
		Strongly/Biconnected connected components
			2 - SAT
	BFS
	Shortest Path
	Trees
		LCA
		Centroid Deposition
		Differentation on trees
	Flows
		Max_flow
		Min_cost_flow
Data structures
	DSU
		Union by rank
	Doubling algorithms 
	Segment tree/Fenwick tree
		Lazy tags
		2 - dimensional segment tree/Fenwick tree
	Balanced BST
	Persistent data structures
	Divide and conquer
	Offline algorithms
		Mo's algorithm
	Heavy - light deposition
Tricks based on monotonicity
	Binary search
	Ternary search
	Two pointers
*/
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cwchar>
#include <cwctype>
#include <exception>
#include <locale>
#include <numeric>
#include <new>
#include <stdexcept>
#include <limits>
#include <valarray>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <utility>
#include <bitset>
#include <algorithm>
#include <functional>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const LL INF = 0x3f3f3f3f3f3f3f3f;

LL gen_ha(int ori[])
{
	LL ret = 0;
	rep(i, 4) ret = ret * 1000 + ori[i];
	return ret;
}

LL min_rep(int ori[], int& cnt)
{
	LL ret = INF;
	rep(i, 4) {
		ret = min(ret, gen_ha(ori));
		rotate(ori, ori + 1, ori + 4);
	}
	cnt = 0;
	rep(i, 4) {
		if(gen_ha(ori) == ret) cnt ++;
		rotate(ori, ori + 1, ori + 4);
	}
	return ret;
}

int n, c[405][4];
LL ha[405];
int hcnt[405];

LL tha[4];
int thcnt[405];
int tmp[4];
int fa[4], cnt[4];
LL solve(int id0, int id1)
{
	rep(i, 4) {
		tmp[0] = c[id0][i];
		tmp[1] = c[id0][i + 1 & 3];
		tmp[2] = c[id1][i + 1 & 3];
		tmp[3] = c[id1][i];
		tha[i] = min_rep(tmp, thcnt[i]);
	}
	
	rep(i, 4) fa[i] = i;
	rep(i, 4) rep(j, i)
	if(tha[i] == tha[j]) {
		fa[i] = j;
		break;
	}
	rep(i, 4) cnt[i] = 0;
	rep(i, 4) cnt[fa[i]] ++;
	
	LL ans = 1;
	rep(i, 4) {
		int tot = 0;
		rep(j, id0) if(j != id1 && tha[i] == ha[j]) tot ++;
		rep(j, cnt[i]) ans *= tot - j;
		rep(j, cnt[i]) ans *= thcnt[i];
	}
	return ans;
}

int main()
{
	scanf("%d", &n);
	rep(i, n) {
		rep(j, 4) scanf("%d", &c[i][j]);
		ha[i] = min_rep(c[i], hcnt[i]);
	}
	LL ans = 0;
	rep(i, n) rep(j, i) {
		reverse(c[i], c[i] + 4);
		rep(k, 4) {
			ans += solve(i, j);
			rotate(c[j], c[j] + 1, c[j] + 4);
		}
		reverse(c[i], c[i] + 4);
	}
	printf("%lld\n", ans);
	return 0;
}

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

const int MAX = 1e5 + 5;

vector<int>visited(MAX), que(MAX), G[MAX];

int main() {
	int n; cin >> n;
	for (int i = 1, u, v; i < n; i++) {
		cin >> u >> v;
		G[u].push_back(v); G[v].push_back(u);
	}
	int l = 1, r = 0;
	visited[l] = 1, visited[n] = 2;
	que[++r] = 1, que[++r] = n;
	while (l <= r) {
		int u = que[l++];
		for (int v : G[u]) {
			if (!visited[v]) {
				visited[v] = visited[u];
				que[++r] = v;
			}
		}
	}
	int sumF = 0, sumS = 0;
	for (int i = 1; i <= n; i++) {
		if (visited[i] == 1)sumF++;
		else sumS++;
	}
	cout << (sumF > sumS?"Fennec" : "Snuke") << endl;

	return 0;
}

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



int main(){
  const double rate = 380000.0;
  double ans = 0;
  int N; cin >> N;
  for (int i=0; i<N; i++){
    double y; cin >> y;
    string s; cin >> s;
    if (s=="JPY") ans += y;
    else ans += y*rate;
  }
  cout << fixed << setprecision(10);
  cout << ans << endl;
}


Measured memory_bytes: 256
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this emplate file, choose Tools | Templates
 * and open the template in the editor.
 */
import java.util.*;
/**
 *
 * @author naoyagonda
 */
/*
1 2 3
2 1 3
3 1 2
*/
public class Main {

    public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int num_1 = scanner.nextInt();
    int num_2 = scanner.nextInt();
    int num_3 = scanner.nextInt();
      
    int tmp=0;
    tmp=num_1;
    num_1=num_2;
    num_2=tmp;
      
    tmp=num_1;
    num_1=num_3;
    num_3=tmp;

    System.out.println(num_1+" "+num_2+" "+num_3);
      
    }
    
}

Measured memory_bytes: 21844
import sys

input = sys.stdin.buffer.readline

n, q = map(int, input().split())


class SegmentTree:
    ele = 10 ** 10
    func = min
    # SEG木は1-index
    # Aに関しては0-index

    def __init__(self, n):  # Aは0-idx
        self.n = n
        self.num = 2 ** ((self.n - 1).bit_length())
        self.SEG = [self.ele] * (2 * self.num)

    def search(self, idx):
        return self.SEG[idx + self.num]

    def initialize(self, A):
        for i in range(self.n):
            self.SEG[i + self.num] = A[i]
        for i in range(self.num - 1, 0, -1):
            self.SEG[i] = self.func(self.SEG[2 * i], self.SEG[2 * i + 1])

    def update(self, idx, val):
        idx += self.num
        self.SEG[idx] = val
        idx //= 2
        while idx:
            self.SEG[idx] = self.func(self.SEG[2 * idx], self.SEG[2 * idx + 1])
            idx //= 2

    def query(self, left, right):
        # maspy式。開区間のママ処理する
        # left, rightで値を分けているのは交換法則不成立のときのため
        # 開区間→Rが奇数→右端が偶数→1ずらしてから計算
        # 　下から上への遷移は2で割る
        # juppy氏は閉区間に直していた
        resleft = self.ele
        resright = self.ele
        left += self.num
        right += self.num
        while right - left > 0:
            if left % 2 == 1:
                resleft = self.func(resleft, self.SEG[left])
                left += 1
            if right % 2 == 1:
                right -= 1
                resright = self.func(resright, self.SEG[right])
            left //= 2
            right //= 2
        return self.func(resleft, resright)


ans = 0

tate = SegmentTree(n)
yoko = SegmentTree(n)

for i in range(q):
    s, x = map(int, input().split())
    x -= 1
    if s == 1:
        temp = tate.query(x, n)
        # print("t", i, temp)
        if temp == 10 ** 10:
            temp = n - 1
        now = yoko.search(temp)
        now = min(now, x)
        yoko.update(temp, now)
        ans += max(0, temp - 1)
    else:
        temp = yoko.query(x, n)
        # print("t", i, temp)
        if temp == 10 ** 10:
            temp = n - 1
        now = tate.search(temp)
        now = min(now, x)
        tate.update(temp, now)
        ans += max(0, temp - 1)
    # print("a", i, temp - 1)
print((n - 2) ** 2 - ans)


Measured memory_bytes: 92160
H, W = map(int,input().split())
s = []
for i in range(H):
    s.append(input())

dx = [0, 0 , 1, -1]
dy = [1, -1, 0, 0 ]

def judge(y,x):
    for i in range(4):
        if (0 <= y + dy[i] and y + dy[i] <= H-1) and (0 <= x + dx[i] and x + dx[i] <= W-1):
            if s[y + dy[i]][x + dx[i]] == "#":
                return True
    return False

for y in range(H):
    for x in range(W):
        if s[y][x] == "#":
            if judge(y,x) == False:
                print("No")
                exit()
print("Yes")

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

int main(){
string A,B,C;
  cin>>A>>B>>C;
  
  if(A.at(A.size()-1)==B.at(0) && B.at(B.size()-1)==C.at(0)){
   cout<<"YES"<<endl;}
  else{cout<<"NO"<<endl;}
 }

Measured memory_bytes: 256
using System;

namespace tst
{
    class Program
    {
        public static void Main()
        {
            string[] In = Console.ReadLine().Split(' ');
            int k = int.Parse(In[0]);
            int x = int.Parse(In[1]);
            int have = k * 500;
            if (have >= x)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }

    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
 
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<n;i++)
#define ll long long
 
#define pi pair < ll , ll >
#define pb push_back
#define mp make_pair
#define F first
#define S second
 
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
 
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
using namespace std;

int main()
{
    fastIO;
    ll a,b;cin>>a>>b;if(a>=10 or b>=10)cout<<-1;else cout<<a*b;
}   

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws IOException {
		
		Scanner scanner = new Scanner(System.in);
		String s = scanner.nextLine();
		String str = s + s;
		String ans = scanner.nextLine();
		
		if(str.contains(ans)){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 26068
import sys

readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))


m = readint()

a = 0
b = 0

for i in range(m):
    d,c = readints()
    a+=c
    b+=c*d

print(a-1+(b-1)//9)



Measured memory_bytes: 41068