akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.net.*;

class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int w = sc.nextInt();
		int h = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();
		
		System.out.println(solve(w, h, x, y, r));
		
	}
	
	private static String solve(int w, int h, int x, int y, int r) {
		
		// 上端チェック
		if (h < y+r) return "No";
		
		// 下端チェック
		if (0 > y-r) return "No";
		
		// 左端チェック
		if (0 > x-r) return "No";
		
		// 右端チェック
		if (w < x+r) return "No";
		
		return "Yes";
	}
}


Measured memory_bytes: 26328
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define pi 3.141592653589793238462643383279502884197
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int s;
	cin>>s;
	if( s == 1000000000000000000LL ){
		cout<<0<<" "<<0<<" "<<0<<" "<<1000000000<<" "<<1000000000<<" "<<0<<endl;
		return 0;
	}
	int x1 = s / ( inf - 7 );
	int x2 = s % ( inf - 7 );
	x2 = -x2;
	cout<<0<<" "<<0<<" "<<x1+1<<" "<<1<<" "<<x2+inf-7<<" "<<inf-7<<endl;
	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


void solve() {
    ll i,j,k,l,r,x,y; string s;
    bool exit = false;
    ll N,M;

    cin>>N>>M;
    vector <ll> A;
    FOR(i,N){
        cin>>j;
        j %= M;
        A.push_back(j);
    }
    vector <ll> S;
    S.push_back(0);
    FORR(x,A){
        S.push_back((S.back() + x) % M);
    }
    //FORR(x,S) cout<<x<<endl;
    map<ll, ll>dup;
    for_each(ALL(S),[&dup] (ll val) { dup[val]++;});
    ll ret = 0;
    for ( auto p: dup){
        //cout<<p.first<< " "<<p.second<<endl;
        ret += p.second*(p.second-1) / 2;
    }
    cout<< ret<<endl;
    
    /*cin>>N;
    vector<ll> V;
    FOR(x,N+1) {
            FOR(y,N+1) {
                    ll ret=1;
                    FOR(i,x) ret*=2;
                    FOR(i,y) ret*=5;
                    V.push_back(ret);
            }
    }
    sort(ALL(V));
    FORR(v,V) cout<<v<<endl;*/
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;
const int INF = 1 << 30;
const long long LINF = 1LL << 60;
const long long MOD = 1000000000 + 7;
const double PI = acos(-1);

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({ a, ex });
    }

    // 最後に残った数について
    if (N != 1) res.push_back({ N, 1 });
    return res;
}

int main() {
    long long N; cin >> N;
    vector<pair<long long, long long>> res;
    res = prime_factorize(N);
    int ans = 0;
    rep(i, res.size()) {
        int num = res[i].second;
        int count = 1;
        while (true) {
            num -= count;
            if (num >= 0)++ans;
            else break;
            ++count;
        }
    }
    cout << ans;
}



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

int T, card[16];
string color[16];
int win();
bool is_all_good_set();
bool is_good_set(int a,int b, int c);
bool is_same_number(int a, int b,int c);
bool is_sequence(int a, int b , int c);
bool count_color();

int main(){
	cin >> T;
	for(int t = 0; t < T; ++t){
		for(int i = 0; i < 9; ++i){
			cin >> card[i];
			//cout << card[i];
		}
		for(int i = 0; i < 9; ++i){
			cin >> color[i];
			//cout << color;
		}
		//cout << count_color();
		cout << win();
		cout << endl;
	}
}
bool count_color(){
	vector<string> v(color, color+9);
	int countR = count(v.begin(),v.end(), "R");
	int countG = count(v.begin(),v.end(), "G");
	int countB = count(v.begin(),v.end(), "B");
	
	if((countR % 3==0)&&(countG%3==0)&&(countB%3==0)) return true;
	else return false;
}
int win() {
	sort(card, card+9);
	sort(color, color+9);
	do {
		if(is_all_good_set()){
			do {
				if(count_color()) return 1;
			} while(next_permutation(color,color+9));
		}
	} while(next_permutation(card,card+9));
	return 0;
	
}
bool is_all_good_set(){
	return ((is_good_set(card[0],card[1],card[2])) && (is_good_set(card[3],card[4],card[5])) && (is_good_set(card[6],card[7],card[8])));
}
bool is_good_set(int a, int b ,int c){
	return is_same_number(a,b,c) || is_sequence(a,b,c);
}
bool is_same_number(int a,int b,int c){
	if(a== b && a == c) return true;
	else return false;
}
bool is_sequence(int a, int b, int c) {
	if(a+2 == b+1 && a+2 == c) return true;
	else return false;
}
/*
//サンプルmain
int main() {
	// is same number のテスト
	cout << is_same_number(3, 4, 5) << endl; // 偽 
	cout << is_same_number(3, 3, 3) << endl; // 真 
	// is sequence のテスト
	cout << is_sequence(3, 4, 5) << endl; // 真 
	cout << is_sequence(3, 3, 3) << endl; // 偽
	// is good set のテスト
	cout << is_good_set(3, 4, 5) << endl; // 真 
	cout << is_good_set(3, 3, 3) << endl; // 真 
	cout << is_good_set(3, 3, 30) << endl; // 偽
	cout << is_good_set(5, 4, 3) << endl; // 偽
}
*/

Measured memory_bytes: 1232
#include<stdio.h>
#include<stdlib.h>
int asc(const void* a, const void* b)
{
	if (*(long long int*)a > * (long long int*)b)return 1;
	if (*(long long int*)a < *(long long int*)b)return -1;
	return 0;
}
int main()
{
	long long int n, m;
	scanf("%lld %lld", &n, &m);
	long long int i;
	long long int a[100005];
	for (i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	long long int sum[100005];
	sum[0] = 0;
	for (i = 0; i < n; i++)
		sum[i + 1] = sum[i] + a[i];
	for (i = 0; i <= n; i++)
		sum[i] %= m;
	qsort(sum, n + 1, sizeof(long long int), asc);
	long long int ans = 0, count = 1;
	for (i = 1; i <= n; i++)
	{
		if (sum[i] == sum[i - 1])
			count++;
		else
		{
			ans += count * (count - 1) / 2;
			count = 1;
		}
	}
	ans += count * (count - 1) / 2;
	printf("%lld\n", ans);
	return 0;
}

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


//defines...
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define in insert
#define pi 2*acos(0.0)1
#define srt(s) sort(s.begin(),s.end())
#define rsrt(s) sort(s.rbegin(),s.rend())
#define all(x) x.begin(),x.end()

const ll mod=1e9+7;
const ll MX=2e5+5;

//code goes from here...



int main()
{
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);
#endif

    boost
    //---------------------------------
    long a, b, c;
    cin >> a >> b >> c;
    if (a > b)
        swap(a, b);
    if (a > c)
        swap(a, c);
    if (b > c)
        swap(b, c);
 
    if ((a == b) & (b == c))
    {
        cout << (a & 1 ? 0 : -1) << endl;
        return 0;
    }
 
    int ans = 0;
    while (((a | b | c) & 1) == 0)
    {
        long na, nb, nc;
        na = (b + c) / 2;
        nb = (c + a) / 2;
        nc = (a + b) / 2;
        a = na;
        b = nb;
        c = nc;
        ans++;
    }
 
    cout << ans << endl;
    
    
    //---------------------------------
    
    return 0;
}


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

int main() {
    string s; cin >> s;
    bool f = true;
    if(s.length() < 6) f = false;
    if(any_of(begin(s), end(s), [](char c) { return isdigit(c); }) == false) f = false;
    if(any_of(begin(s), end(s), [](char c) { return isupper(c); }) == false) f = false;
    if(any_of(begin(s), end(s), [](char c) { return islower(c); }) == false) f = false;
    cout << (f ? "VALID" : "INVALID") << endl;
}

Measured memory_bytes: 1184
n, m = gets.chomp.split.map(&:to_i)
b = Array.new(m, 0)

a = []
n.times do |i|
  a = gets.chomp.split.map(&:to_i)
  (a.length - 1).times do |j|
    b[a[j+1]-1] += 1
  end
end

puts b.select{|i| i == n}.length

Measured memory_bytes: 1788
unittest
{
	assert( [ "6" ].solve == 3 );
	assert( [ "3141" ].solve == 13 );
	assert( [ "314159265358" ].solve == 9 );
}



import std.conv;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	
	// nをkでx回割った後にkをy回引いて1になるkをカウント
	auto ans = 0L;
	foreach( k; n.divisors )
	{
		if( k == 1 ) continue;
		auto m = n;
		while( m % k == 0 ) m /= k;
		if( m - k * ( m / k ) == 1 ) ans++;
	}
	
	// kをy回引いて1になるkをカウント
	foreach( k; ( n - 1 ).divisors )
	{
		if( k == 1 ) continue;
		ans++;
	}
	return ans;
}

// 約数列挙
auto divisors( long n )
{
	bool[ long ] ds;
	auto s = cast( long ) n ^^ 0.5L;
	for( auto i = 1L; i <= s; i++ )
	{
		if( n % i != 0 ) continue;
		ds[ i     ] = true;
		ds[ n / i ] = true;
	}
	return ds.keys;
}


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

#define infile "../test/sample-1.in"
#define int long long
// #define INF 2147483647
#define INF 1000000000000000000LL
#define MOD 1000000007LL

// {{{ define basic macro
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) repi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

#define foreach(x,a) for(auto& (x) : (a) )
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)

template <class T = int>
T in() {T x; cin>>x; return (x);}

struct Fast {
  Fast(){
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
// }}}
//{{{ dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}
//{{{ others
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

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

int used[100000];
vvi e;

int dfs(int node, vi& l){
  used[node] = 1;
  l.pb(node);
  foreach(x, e[node]){
    if (!used[x]){
      dfs(x, l);
      return 0;
    }
  }
  return 0;
}

int solve(){
  int n,m;cin>>n>>m;

  int a,b;
  e = vvi(n);
  rep(i, m){
    cin>>a>>b;
    a--;b--;
    e[a].pb(b);
    e[b].pb(a);
  }

  vi l, r;
  used[0]=1;
  dfs(e[0][0], l);
  dump(l);

  rep(i, 1, sz(e[0])){
    if (!used[e[0][i]]){
      dfs(e[0][i], r);
      break;
    }
  }
  dump(r);
  reverse(all(l));
  l.pb(0);
  copy(all(r), back_inserter(l));
  dump(l);
  cout << sz(l) << endl;
  rep(i, sz(l)) cout << l[i]+1 << (i!=sz(l)-1 ? " " : "\n");

  return 0;
}

int test(){ //{{{
  return 0;
}
//}}}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
#ifdef PCM
  test();
#endif
  solve();
  return 0;
} //}}}


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

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

		int[] marks = new int[n];
		int sum = 0;

		for(int i=0; i<n; i++){
			marks[i] = sc.nextInt();
			sum += marks[i];
		}

		Arrays.sort(marks);
		int k = 0;

		while(sum%10 == 0 && sum != 0){
			while(k<marks.length && marks[k]%10 ==0) k++;
			if(k == marks.length){
				sum = 0;
				break;
			}
			sum -= marks[k++];
		}

		System.out.println(sum);
	}
}


Measured memory_bytes: 23892
package main

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

func main() {
	N := nextInt()
	M := nextInt()
	P := make([]int, N)
	for i := 0; i < N; i++ {
		P[i] = nextInt()
	}

	uf := ufNew(N)

	for i := 0; i < M; i++ {
		x := nextInt()
		y := nextInt()

		ufUnite(&uf, x-1, y-1)
	}

	c := 0
	for i := 0; i < N; i++ {
		if ufSame(&uf, i, P[i]-1) {
			c++
		}
	}

	fmt.Println(c)
}

var stdin = initStdin()

type unionfind struct {
	par  []int
	rank []int
}

func ufNew(n int) unionfind {
	uf := unionfind{par: make([]int, n), rank: make([]int, n)}

	for i := 0; i < n; i++ {
		uf.par[i] = i
	}

	return uf
}

// xのルートを得る
func ufRoot(uf *unionfind, x int) int {
	p := x
	for p != uf.par[p] {
		p = uf.par[p]
	}
	uf.par[x] = p
	return p
}

func ufUnite(uf *unionfind, x, y int) bool {
	rx := ufRoot(uf, x)
	ry := ufRoot(uf, y)

	if rx == ry {
		return false
	}
	if uf.rank[rx] < uf.rank[ry] {
		rx, ry = ry, rx
	}
	if uf.rank[rx] == uf.rank[ry] {
		uf.rank[rx]++
	}
	uf.par[ry] = rx
	return true
}

func ufSame(uf *unionfind, x, y int) bool {
	rx := ufRoot(uf, x)
	ry := ufRoot(uf, y)
	return rx == ry
}

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}


Measured memory_bytes: 5248
#include<bits/stdc++.h>
#define int long long
using namespace std;
main()
{
    int n;
    cin>>n;
    int a[n],b[n];
    for(int i=0;i<n;i++)
        cin>>a[i],b[i]=a[i];
    sort(b,b+n);
    int count=0;
    for(int i=0;i<n;i++){
        if(a[i]!=b[i])
            count++;
    }
    if(count==2|| count==0)
        cout<<"YES";
    else
        cout<<"NO";
}

Measured memory_bytes: 256
main = do
    s <- getLine
    putStrLn $ if isHeisei s then "Heisei" else "TBD"

isHeisei :: String -> Bool
isHeisei s
    | y < 2019 = True
    | y > 2019 = False
    | y == 2019 = case () of
       () | m < 4 -> True
       () | m > 4 -> False
       () | m == 4 -> d <= 30
    where 
        y = read $ take 4 s
        m = read $ take 2 $ drop 5 s
        d = read $ drop 8 s


Measured memory_bytes: 508
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    int t[n+1];
    int x[n+1], y[n+1];
    t[0] = 0;
    x[0] = 0;
    y[0] = 0;
    for (int i=1; i<=n; i++){
        cin >> t[i] >> x[i] >> y[i];
    }
    for (int i=1; i<=n; i++){
        if (abs(t[i]-t[i-1]) % 2 != (abs(x[i] - x[i-1]) + abs(y[i] - y[i-1])) % 2){
            out("No");
            return 0;
        } 
        else if(t[i] - t[i-1] < abs(x[i]-x[i-1]) || t[i] - t[i-1] < abs(y[i]-y[i-1])){
            out("No");
            return 0;
        }
    }
    out("Yes");
    return 0;
}

Measured memory_bytes: 1408
//#include "stdc++.h"
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))
#define sz(x) (int)(x.size())
#define ff first
#define ss second
#define endl "\n"
#define int long long int
inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p*p)%m;if(n%2) return (p*a)%m;else return p;}
const ll MOD = 1000000007;
const ll mod=1000000006;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
/*
 shuffle(x,x+n,rng) // shuffling elements of x in random order
 */
int Bsearch(vector<int>&v,int x)
{
    int l,r,m;
    l=0;r=v.size()-1;int ans=r+1;
    while(r>=l)
    {
        m=(l+r)/2;
        if(v[m]>=x)
        {
            ans=m;
            r=m-1;
        }
        else
            l=m+1;
    }
    return ans;
}
int32_t main()
{
    IOS;
    string s;string t;
    cin>>s>>t;
    int n=s.length();
    int m=t.length();
    vector<int> v[26];
    for(int i=0;i<n;i++)
        v[s[i]-'a'].pb(i);
    int prev=-1;
    int copy=0;int j,in,z=0;
    for(int i=0;i<m;i++)
    {
        j=t[i]-'a';
        if(v[j].size()==0)
        {
            z=1;
            break;
        }
       // cout<<prev
        in=Bsearch(v[j],prev+1);
        //cout<<i<<" "<<in<<endl;
        if(in==v[j].size())
        {
            copy++;
            prev=v[j][0];
        }
        else
        {
            prev=v[j][in];
        }
    }
    if(z)
    {
        cout<<"-1"<<endl;
        return 0;
    }
    int ans=(copy)*n+prev+1;
    cout<<ans<<endl;
    return 0;
}







Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
vector<int> t[100001];
ll dp[100001][2];

int mod=1e9+7;

ll ways( int root, int cons,int pr){

if(dp[root][cons]!=-1){

    return dp[root][cons];

}

ll ans=0;

    ll w1=1;

    for( int child: t[root]){

        if(child!=pr){
            w1=(w1*ways(child,0,root))%mod;
        }
    }
    ans+=w1;

    if(cons==0){

        ll w2=1;
       for( int child: t[root]){

        if(child!=pr){
            w2=(w2*ways(child,1,root))%mod;
        }

    }
    ans=(ans+w2)%mod;


    }


 return dp[root][cons]=ans;




}

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

   for(int i=0;i<n-1;i++){
       int x,y;
       cin>>x>>y;
       t[x].push_back(y);
       t[y].push_back(x);
   }

    memset(dp,-1,sizeof(dp));


   cout<<ways(1,0,-1);


}


Measured memory_bytes: 18952
# python 3.4.3
import sys
input = sys.stdin.readline
import numpy as np

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
S = input().rstrip()

N = len(S)
ans0 = 0 # S[0]==0 とする場合 : 偶数0 奇数1に
ans1 = 0 # S[0]==1 とする場合 : 偶数1 奇数0に

for i in range(N):
    if i%2==0:
        if S[i]=="0":
            ans1 += 1
        else:
            ans0 += 1
    else:
        if S[i]=="0":
            ans0 += 1
        else:
            ans1 += 1

print(min(ans0,ans1))


Measured memory_bytes: 12624
n = gets.to_i
a = [0] + gets.split.map(&:to_i)

(n/2).downto(1) do |i|
  s = 0
  j = i
  while j <= n do
    s += a[j]
    j += i
  end
  a[i] = s & 1
end

ans = (1..n).select{ |i| a[i] == 1 }
puts ans.size, ans * " "

Measured memory_bytes: 22016
using System;
    class Program
    {
        static void Main(string[] args)
        {
            // 標準入力から一行読み込む
            string text = Console.ReadLine();    // 標準入力から一行読み込む
            int num = Int32.Parse(text);
            Console.WriteLine(Math.Pow(num,3));
        }
    }



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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    int H, N;
    cin >> H >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    int total = 0;
    REP(i, N) total += A[i];

    if (total >= H) {
        print("Yes");
    } else {
        print("No");
    }
}

signed main() {
    solve();
}


Measured memory_bytes: 640
//??-2015-11-1
# include <cstdio>
# include <string>
# include <cstring>
# include <algorithm>
# include <iostream>
# include <queue>

using namespace std;

int direction[4][2] = { { -1, 0 }, { 1, 0 }, { 0, -1 }, {0,1} };                  //四个方向，上下左右
struct node
{
	int w, h;
	int step;
};
struct node2
{
	int h, w, value;
};
int H, W, N;
string s[1005];
int vis[1005][1005];
int cmp(node2 a, node2 b)
{
	if (a.value < b.value)
		return 1;
	else
		return 0;
}
int DFS(int begin_h, int begin_w, int end_h, int end_w)
{
	int i, j,w = 0;
	queue<node>Q;
	node temp;
	temp.h = begin_h;
	temp.w = begin_w;
	temp.step = 0;
	Q.push(temp);
	vis[begin_h][begin_w] = 1;
	while (!Q.empty())                     //?列不空的?
	{
		node temp1 = Q.front();
		Q.pop();
		//printf("%d\n", w++);
		if (temp1.h == end_h&&temp1.w == end_w)
		{
			return temp1.step;
		}
		for (i = 0; i < 4; i++)
		{
			if (temp1.h + direction[i][0] >= 0 && temp1.h + direction[i][0] < H&&temp1.w + direction[i][1] >= 0 && temp1.w + direction[i][1] < W&&!vis[temp1.h + direction[i][0]][temp1.w + direction[i][1]] && s[temp1.h + direction[i][0]][temp1.w + direction[i][1]] == '.')
			{
				node temp2;
				temp2.h = temp1.h + direction[i][0];
				temp2.w = temp1.w + direction[i][1];
				temp2.step = temp1.step + 1;
				vis[temp1.h + direction[i][0]][temp1.w + direction[i][1]] = 1;
				Q.push(temp2);
			}
		}
	}
}
int main(void)
{
	memset(vis, 0, sizeof(vis));
	int i, j,k = 1;
	int all_step = 0;
	int s_h, s_w,e_h,e_w;
	//freopen("in.txt", "r", stdin);
	scanf("%d%d%d", &H, &W, &N);
	node2 node1[20];
	for (i = 0; i < H; i++)
	{
		cin >> s[i];
		for (j = 0; j < s[i].length(); j++)
		{
			if (s[i][j] >= '0'&&s[i][j] <= '9')
			{
				node1[k].h = i;
				node1[k].w = j;
				node1[k].value = s[i][j] - '0';                //保留?
				k++;
				s[i][j] = '.';                                  //?了BFS的?候?理一致
			}
			else if (s[i][j] == 'S')                            //?始?点
			{
				s_h = i;
				s_w = j;
				s[i][j] = '.';
			}
		}
	}
		sort(node1+1, node1 + N+1, cmp);                             //先排好序
		node1[0].h = s_h;                                            //?了使下面循?一?
		node1[0].w = s_w;
		for (i = 0; i < N; i++)
		{
			e_h = node1[i+1].h;                                      //?点的坐?
			e_w = node1[i+1].w;
			s_h = node1[i].h;
			s_w = node1[i].w;
			//printf("step=%d\n", DFS(s_h, s_w, e_h, e_w));
			all_step += DFS(s_h, s_w, e_h, e_w);                       //原来的?点??起始点
			memset(vis, 0, sizeof(vis));
		}
		printf("%d\n", all_step);
	
	return 0;
}

Measured memory_bytes: 6252
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
bool cmp(string a, string b)
{
    return a < b;  
}
int main(){
    long i,n,l;
    cin>>n>>l;
    string s[n]={};
    for(i=0;i<n;i++) cin>>s[i];
    sort(s,s+n,cmp);
    for(i=0;i<n;i++) cout<<s[i];
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = int(1e9)+10;
const ll INFll = ll(1e18)+10;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;

int main() {
	string S; cin >> S;
	bool ans = true;
	int N = S.size();

	if (N % 2 != 0) ans = false;
	rep(i, N) {
		if (i % 2 == 0) {
			if (S[i] != 'h') ans = false;
		}
		if (i % 2 == 1) {
			if (S[i] != 'i') ans = false;
		}
	}
	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <bitset>
#include <iomanip>
#include <deque>
#include <tuple>
#include <algorithm>

using namespace std;

int main()
{
    string s;
    cin >> s;

    string t(s);
    reverse(t.begin(), t.end());

    if (s == t) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>

#define INFTY 1000000001

int count=0,n;
int main(){
  int i,left,right;
  scanf("%d",&n);
  int S[n];
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  left=0;
  right=n;
  mergeSort(S,left,right);
  for(i=0;i<n;i++){
    if(i<n-1)
      printf("%d ",S[i]);
      else printf("%d\n",S[i]);
    }
  printf("%d\n",count);
  return 0;
}

merge(int A[],int left,int mid,int right){
  int k,n1,n2,i,j;
  n1 = mid - left;
  n2 = right - mid;
  int L[n1], R[n2];
  for(i = 0;i<=n1-1;i++){
    L[i] = A[left + i];
  }
  for(i = 0;i<=n2-1;i++){
    R[i] = A[mid + i];
  }
  L[n1] = INFTY;
  R[n2] = INFTY;
  i = 0;
  j = 0;
  for(k = left;k<=right-1;k++){
    count++;
    if(L[i] <= R[j]){
      A[k] = L[i];
      i = i + 1;
    }
    else{ 
      A[k] = R[j];
      j = j + 1;
    }
  }
}
mergeSort(int A[],int left,int right){
  int mid;
  if(left+1 < right){
    mid = (left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
    //count++;
  }
}



Measured memory_bytes: 5636
#include<bits/stdc++.h>
#define ll long long
#define int long long int
#define MOD 1000000007
#define mkp make_pair
#define maxn 100005
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,a,b) for(int i=a;i<b;i++)
#define pi pair<int,int>
#define pii pair<int,pi>
#define mp map<int,int>
#define ump unordered_map<int,int>
#define  vi vector<int>
#define st set<int>
#define mst multiset<int>
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define in cin>>
#define out cout<<
using namespace std;
const int infi=1e9+7;
void printVector(vector<int> v){
    for(int i=0;i<(int)v.size();i++)
        cout<<v[i]<<" ";
    out endl;
}

void printArray(int arr[],int n)
{
   for(int i=0;i<n;i++)cout<<arr[i]<<' ';
cout<<endl;
}
 set<pair<int,int>> primeset;
 vi prime_number;
void SieveOfEratosthenes(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
        for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
           primeset.insert(mkp(p,1));
}
ll modExp(ll base, ll power) {
    if (power == 0) {
        return 1;
    } else {
        ll cur = modExp(base, power / 2); cur = cur * cur; cur = cur % MOD;
        if (power % 2 == 1) cur = cur * base;
        cur = cur % MOD;
        return cur;
    }
}
//for making unordered_map with pair
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
int32_t main()
{
fastio;
int n;in n;int m;in m;
int arr[n];
int s=0;
for(int i=0;i<n;i++){
    in arr[i];
    s+=arr[i];
}
vi a;
rep(i,n){
if(arr[i]*4*m>=s) a.pb(arr[i]);
}
if(a.size()>=m) out "Yes";
else out "No";

    return 0;
}

/*
google kick start
  cout << "Case #" << tt << ": "<<ans<<endl;
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll n,m,x,y,f=0;
    cin>>n>>m>>x>>y;
    ll a[n],b[m];
    for(int i=0;i<n;i++)
    {
      cin>>a[i];
    }
    for(int i=0;i<m;i++)
    {
      cin>>b[i];
    }
    sort(a,a+n);
    sort(b,b+m);
    /*for(auto t:a)cerr<<t<<" ";
      cerr<<endl;
    for(auto t:b)cerr<<t<<" ";
      cerr<<endl;*/
    ll temp=a[n-1]+1;
    if(b[0]>=temp&&b[0]<=y&&b[0]>x)
         f=1;
    
    //cerr<<"temp "<<temp<<endl;
    if(f)
    {
      cout<<"No War"<<endl;
    }
    else
    {
      cout<<"War"<<endl;
    }


}
return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<iostream> 
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#define ll long long
#define ull unsigned long long
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define lowbit(x) (x& -x)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define eps 1e-18
#define maxn 100010
inline ll read(){ll tmp=0; char c=getchar(),f=1; for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1; for(;'0'<=c&&c<='9';c=getchar())tmp=(tmp<<3)+(tmp<<1)+c-'0'; return tmp*f;}
inline ll power(ll a,ll b){ll ans=1; for(;b;b>>=1){if(b&1)ans=ans*a%mod; a=a*a%mod;} return ans;}
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void swap(int &a,int &b){int tmp=a; a=b; b=tmp;}
using namespace std;
int a,b,c;
int main()
{
	a=read(); b=read(); c=read();
	if(a<b)swap(a,b);
	if(a<c)swap(a,c);
	printf("%d\n",a*10+b+c); 
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){


    int n;
    cin>>n;
    int ans[10000];
    int i=0;
    if(n==0){
        cout<<0;
        return 0;
    }
    
while(n!=1){
        if(n%2==0){
            n=n/(-2);
           
            ans[i]=0;
            
           // cout<<n<<ans[i]<<endl;
            i++;
            
        }else{
            n=(n-1)/(-2);
       
            ans[i]=1;
          //  cout<<n<<ans[i]<<endl;
            i++;
                      }
    ans[i]=1;
        }
    while(i>=0){
        cout<<ans[i];
        i--;
        
    }

return 0;
}

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

int main() {
	vector<bool> vec(30); int temp;
	fill(vec.begin(), vec.end(), false);
	while (cin >> temp) vec[temp - 1] = true;
	for (int i = 0; i < 30; i++)
		if (vec[i] == false) cout << i + 1 << endl;
	return 0;
}


Measured memory_bytes: 3068
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		if(s[1]==0){
			Console.WriteLine(s[0]);
			return;
		}
		var a=sc.Ia;
		var b=new bool[102];
		for(int i = 0;i<s[1];i++) {
			b[a[i]]=true;
		}
		int ans=0;
		for(int i = 0;i<b.Length;i++) {
			if(!b[i]){
				if(Abs(i-s[0])<Abs(ans-s[0])){
					ans=i;
				}
				else if(Abs(i-s[0])==Abs(ans-s[0])&&i<ans){
					ans=i;
				}
			}
		}
		Console.WriteLine("{0}",ans);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 27572
#include<bits/stdc++.h>
using namespace std;
int c,a,b=0;
int main(){
    scanf("%d",&a);
    c=a;
    while(c){
        b+=(c%10);
        c/=10;
    }
    if((a%b)==0) printf("Yes");
    else printf("No");
}

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

using namespace std;

int main() {
	int n;
	cin >> n;
	int a = 0, m = 0, p;
	for (int i = 0; i < n; i++)
		cin >> p, a += p, m = max(m, p);
	cout << a - m / 2 << endl;
	return 0;
}


Measured memory_bytes: 256
#gcdは3.4.3だとfractionsにある
from fractions import gcd
import math

from math import factorial as f

from math import ceil,floor,sqrt

from sys import exit

from copy import deepcopy
import numpy as np

import bisect
import re
import heapq


from copy import deepcopy
import itertools

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



def main():
    n = ii()
    s = list(input())

    alpha = list('ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ')



    ans = ''
    for i in s:
        for a in range(26):
            if alpha[a] == i:
                ans+=alpha[a+n]


    print(ans)

main()


Measured memory_bytes: 16320
#include <functional>
#include <type_traits>
#include <string>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <vector>
#include <utility>
namespace loquat {
template <int MOD>
class modulus_integer {
public:
	typedef modulus_integer<MOD> self_type;
private:
	int m_value;
	static self_type unsafe_construct(int x) noexcept {
		self_type y;
		y.m_value = x;
		return y;
	}
public:
	modulus_integer() noexcept
		: m_value(0)
	{ }
	modulus_integer(int x) noexcept
		: m_value(x % MOD)
	{
		if(m_value < 0){ m_value += MOD; }
	}
	int operator*() const noexcept { return m_value; }
	self_type& operator=(const self_type& x) noexcept {
		m_value = x.m_value;
		return *this;
	}
	bool operator==(const self_type& x) const noexcept {
		return m_value == x.m_value;
	}
	self_type operator+(const self_type& x) const noexcept {
		const int y = m_value + x.m_value;
		return unsafe_construct(y >= MOD ? y - MOD : y);
	}
	self_type operator-(const self_type& x) const noexcept {
		const int y = m_value - x.m_value;
		return unsafe_construct(y < 0 ? y + MOD : y);
	}
	self_type operator*(const self_type& x) const noexcept {
		return unsafe_construct(
			static_cast<long long>(m_value) * x.m_value % MOD);
	}
	self_type& operator+=(const self_type& x) noexcept {
		return (*this = *this + x);
	}
	self_type& operator-=(const self_type &x) noexcept {
		return (*this = *this - x);
	}
	self_type& operator*=(const self_type& x) noexcept {
		return (*this = *this * x);
	}
};
template <int MOD>
inline std::ostream& operator<<(
	std::ostream& os, const modulus_integer<MOD>& x)
{
	os << *x;
	return os;
}
}
using namespace std;
static const int MOD = 998244353;
using mint = loquat::modulus_integer<MOD>;
int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; ++i){ cin >> a[i]; }
	const int m = accumulate(a.begin(), a.end(), 0);
	vector<mint> cur(m + 1);
	cur[0] = 1;
	for(int i = 0; i < n; ++i){
		vector<mint> next(m + 1);
		for(int j = 0; j <= m; ++j){
			if(cur[j] == 0){ continue; }
			next[j + a[i]] += cur[j];
			next[j] += cur[j] * 2;
		}
		cur = move(next);
	}
	mint invalid = 0;
	for(int i = (m + 1) / 2; i <= m; ++i){ invalid += cur[i] * 3; }
	if(m % 2 == 0){
		fill(cur.begin(), cur.end(), mint(0));
		cur[0] = 1;
		for(int i = 0; i < n; ++i){
			vector<mint> next(m + 1);
			for(int j = 0; j <= m; ++j){
				if(cur[j] == 0){ continue; }
				next[j + a[i]] += cur[j];
				next[j] += cur[j];
			}
			cur = move(next);
		}
		invalid -= cur[m / 2] * 3;
	}
	mint all = 1;
	for(int i = 0; i < n; ++i){ all *= 3; }
	cout << all - invalid << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <stack>

using namespace std;



int main() {
	stack<int> s;
	int in;
	
	while (cin >> in) {
		if (in != 0) s.push(in);
		
		while (!s.empty()) {
			cin >> in;
			if (in==0) {
				cout << s.top() << endl;
				s.pop();
			}
			else s.push(in);
		}
	}
	
	return 0;
}

Measured memory_bytes: 1200
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll N, M;
    cin >> N >> M;
    vector<vector<ll>> G(N, vector<ll>(N, 0));
    Rep (i, M) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        G[a][b]++;
        G[b][a]++;
    }

    vector<ll> v;
    Rep (i, N) v.push_back(i);
    ll ans = 0;
    do {
        if (v[0] != 0) continue;
        bool pos = true;
        Rep (i, N-1) {
            if (G[v[i]][v[i+1]] == 0) {
                pos = false;
                break;
            }
        }
        if (pos) ans++;
    } while (next_permutation(v.begin(), v.end()));

    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;

int n;
vector<int> edge[100010];
vector<int> memo_b;
vector<int> memo_w;

//color = false = black, color = true = white
void dfs(int x, int vis, bool color) {
    if (color) {
        if (memo_w[x] != -1) return;
        else memo_w[x] = vis;
    }
    else {
        if (memo_b[x] != -1) return;
        else memo_b[x] = vis;
    }
    for (auto&& e: edge[x]) dfs(e, vis+1, color);
    return;
}

int main(int argc, char const *argv[]) {
    cin >> n;
    memo_b.resize(n, -1); memo_w.resize(n, -1);
    REP(i,n-1) {
        int a,b;
        cin >> a >> b;
        --a; --b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    dfs(0, 0, false);
    dfs(n-1, 0, true);
    int cntb = 0; int cntw = 0;
    //REP(i,n) printf("memo_b[%d] = %d, memo_w[%d] = %d\n", i, memo_b[i], i, memo_w[i]);
    REP(i,n) {
        if (memo_b[i] <= memo_w[i]) cntb++;
        else cntw++;
    }
    if (cntb > cntw) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
    return 0;
}

Measured memory_bytes: 11136
/******************************************
* AUTHOR : AMAN SAXENA *
* "There's some good in this world, and it's worth fighting for." *
* INSTITUTION : KIET Group of Institutions *
******************************************/
#include <bits/stdc++.h>

const long long MODULO=1000000007;
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define FOR1(i,a,n) for(int i=a;i<=n;i++)
#define FOR2(i,a,n) for(int i=a;i>=n;i--)
#define pb push_back
#define mp make_pair
#define ll long long 
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pi 3.14159265359

using namespace std;

template <typename TYPE> void in(TYPE &x){cin>>x;}

int freq[100009]={0};
ll sum = 0;

void solve()
{
    ll n, q;
    cin>>n;
    ll i,a[n];
    FOR(i,0,n) 
    {
    	cin>>a[i];
    	freq[a[i]]++;
    	sum+=a[i];
    }
    cin>> q;
    while(q--)
    {
    	ll b,c;
    	cin >> b >> c;
    	sum += (c - b)*freq[b];
    	freq[c]+=freq[b];
    	freq[b]=0;
    	cout << sum << '\n';
    }
}

void test()
{
    int t;
    cin>>t;
    while(t--) //for(int j=1;j<=t;j++) cout << "Case #" << j << ": ";
    {
        solve();
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    // test();
    solve();
    
    return 0;
}

Measured memory_bytes: 4784
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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(){
  ll x,k,d;
  cin>>x>>k>>d;
  x = abs(x);
  ll cnt = x/d;
  if(k<cnt) {
    x -= d*k;
    cout<<x<<endl;
    return 0;
  }
  k -= cnt;
  ll now = x%d;
  ll next = abs(now-d);
  if(k%2)cout<<next<<endl;
  else cout<<now<< endl;
}
  


Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>

typedef long long ll;

int const N = 1e5 + 5;

int fa[N];
int sz[N];
ll a[N];
ll dis[N];
bool vis[N];
int n;

std::vector<int> E[N];
void addedge2(int x, int y) {
    E[x].push_back(y);
    E[y].push_back(x);
}

void dfs(int x, ll& sum, int dep) {
    sz[x] = 1;
    vis[x] = 1;
    sum += dep;
    for(auto y : E[x]) if(vis[y] == 0) {
        dfs(y, sum, dep + 1);
        sz[x] += sz[y];
    }
}

bool chk(int x, ll ans) {
    if(a[x] != ans) return 0;
    vis[x] = 1;
    bool ret = 1;
    for(auto& y : E[x]) if(vis[y] == 0) {
        ret &= chk(y, ans + n - 2ll * sz[y]);
    }
    return ret;
}

int main() {
    std::map<ll, int, std::greater<ll> > M;
    std::ios::sync_with_stdio(0);
    std::cin >> n;
    for(int i = 1; i <= n; ++i) {
        std::cin >> a[i];
        M.insert(std::make_pair(a[i], i));
    }
    for(auto& k : M) if(k.first != (*M.rbegin()).first) {
        int now = k.second;
        ++sz[now];
        ll f = k.first + 2ll * sz[now] - n;
        if(M.count(f) == 0) {
            puts("-1");
            return 0;
        }
        fa[now] = M[f];
        sz[fa[now]] += sz[now];
        ::addedge2(now, fa[now]);
    }
    int root = (*M.rbegin()).second;
    ll ans_root = 0;
    memset(vis, 0, sizeof(vis));
    memset(sz, 0, sizeof(sz));
    dfs(root, ans_root, 0);
    memset(vis, 0, sizeof(vis));
    if(chk(root, ans_root) == 0) {
        puts("-1");
        return 0;
    }
    for(int i = 1; i <= n; ++i) if(fa[i] != 0) {
        std::cout << fa[i] << ' ' << i << '\n';
    }
    return 0;
}

Measured memory_bytes: 18688
fun main(args:Array<String>):Unit {
    val n = readLine()!!.toInt()
    val minRoute = Array(n){from -> Array(n){to -> if (from == to) 0 else Int.MAX_VALUE.toLong()}}
    repeat(n){
        val info = readLine()!!.split(' ').map(String::toInt)
        info.drop(2).forEach { to ->
            minRoute[info.first() - 1][to - 1] = 1
        }
    }
    for (i in 0 until n) for (from in 0 until n) for (to in 0 until n){
        if (minRoute[from][to] > minRoute[from][i] + minRoute[i][to])
            minRoute[from][to] = minRoute[from][i] + minRoute[i][to]
    }
    repeat(readLine()!!.toInt()){
        val (s, d, v) = readLine()!!.split(' ').map(String::toInt)
        println(if (minRoute[s - 1][d - 1] >= v) "NA" else minRoute[s - 1][d - 1] + 1)
    }
}


Measured memory_bytes: 34216
#include <stdio.h>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
using namespace std;
const int maxn = 2e5+10;
const long long mod = 1e9+7;
long long pre[maxn], back[maxn];
int main(){
    int n, k;
    cin>>n>>k;
    pre[0] = 0;
    for(int i=1; i<=n; i++){
        pre[i] = pre[i-1] + i;
    }
    back[n] = n;
    for(int i=n-1; i>=0; i--){
        back[i] = back[i+1]+i;
    }
    long long res = 0;
    for(int i=k; i<=n+1; i++){
        res = (res + (back[n-i+1]-pre[i-1]+1)%mod)%mod;
    }
    cout<<res;
    return 0;
}


Measured memory_bytes: 6744
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
if(a%2 == 1) {
	System.out.println(((a-1)/2)*(1+(a-1)/2));
}else {
	System.out.println((a/2)*(a/2));
}
sc.close();
}

}


Measured memory_bytes: 23252
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <random>
#include <algorithm>
#include <functional>
#include <cassert>

using namespace std;
typedef long long ll;

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;
}

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll X;
  cin>>X;
  ll now=100;
  REP(i,5000){
    now=(now*(long double)(1.01));
    if(now>=X){
      cout<<i+1<<endl;
      break;
    }
  }
}


Measured memory_bytes: 3652