akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

S = input()
Q = int(input())

rev = False
S1 = ['0'] * Q
S1i = 0
S2 = ['0'] * Q
S2i = 0

for q in range(Q):
    i = input()
    if i[0] == "1":
        rev = not rev
    elif not rev and i[2] == "1" or rev and i[2] == "2":
        # S = i[4] + S
        S1[S1i] = i[4]
        S1i += 1
    else:
        # S = S + i[4]
        S2[S2i] = i[4]
        S2i += 1

S1 = S1[0:S1i]
S2 = S2[0:S2i]
S1 = S1[::-1]

S = ''.join(''.join(S1) + S + ''.join(S2))

if rev:
    S = S[::-1]

print(S)


Measured memory_bytes: 7668
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N,M; cin>>N>>M;
    ll ans=0;
    vector<ll> k(N,0);
    vector<vector<ll> > s(M,vector<ll>(N,0));
    rep(i,M){
        cin>>k[i];
        rep(j,k[i]) cin>>s[i][j];
    }
    vector<ll> p(M,0);
    rep(i,M) cin>>p[i];
    rep(i,pw2[N]){
        //BIT全探索
        vector<ll> BIT(N);
        ll tmps=i;
        rrep(i2,N){
            BIT[i2]=tmps/pw2[i2];
            tmps%=pw2[i2];
        }
        
        //check
        bool check=true;
        rep(j,M){
            ll tmp=0;
            rep(l,k[j]){
                if(BIT[s[j][l]-1]==1) tmp++;
            }
            if(tmp%2 != p[j]) check=false;
        }
        
        if(check) ans++;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3632
n = input()

if n == "SAT":
    print(1)
elif n == "FRI":
    print(2)
elif n == "THU":
    print(3)
elif n == "WED":
    print(4)
elif n == "TUE":
    print(5)
elif n == "MON":
    print(6)
elif n == "SUN":
    print(7)

Measured memory_bytes: 3060
N = gets.to_i
ds = Hash.new(0)
gets.split.map(&:to_i).each do |d|
    ds[d] += 1
end
M = gets.to_i
gets.split.map(&:to_i).each do |t|
    if ds[t] > 0
        ds[t] -= 1
    else
        puts 'NO'
        exit
    end
end
puts 'YES'

Measured memory_bytes: 42116
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    a = [0]+LI()
    a = list(itertools.accumulate(a))
    d = defaultdict(int)
    for i in a:
        d[i] += 1
    ans = 0
    for value in d.values():
        ans += value * (value - 1) // 2
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 107428
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main() {

    long long n, a,b;
    cin>>n>>a>>b;
    long long amari = n%(a+b);
    cout<< (n/(a+b))*a + min(amari,a)<<endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
const int maxn = (int) (2 * 1e5 + 5);

int main() {
    vector<ll> Xor(maxn), Sum(maxn);
    int n;
    scanf("%d", &n);
    Xor[0] = Sum[0] = 0;
    for (int i = 1; i <= n; i++) {
        int num;
        scanf("%d", &num);
        Xor[i] = Xor[i - 1] ^ num;
        Sum[i] = Sum[i - 1] + num;
    }
    ll ans = 0;
    int j = 1;
    for (int i = 0; i < n; i++) {
        while (j + 1 <= n && (Xor[j + 1] ^ Xor[i]) == (Sum[j + 1] - Sum[i])) {
            j++;
        }
        ans += j - i;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
#define infinite 9123456789
#define PRECISION cout.precision(3); cout.setf(ios::fixed);

int n, resp=0;

void solve(){
	cin >> n;
	for(int i=1; i<=n; i++){
		int x; cin >> x;
		if(x%2==1 and i%2==1){
			resp++;
		//	cout << x << "\n";
		}
	}
	cout << resp;
}
signed main(){
	solve();
}


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

public class MainClass
{
	public const long Giri = 1000000007;

	public static void Main(string[] args)
	{
		var p = Input();
		var n = p[0].ToInt();
		var m = p[1].ToLong();
		var ps = Input();
		var t = new long[n];
		for(int i = 0; i < n; i++)
			t[i] = ps[i].ToLong();
		long wa = 0;
		for(int i = 0; i < n; i++)
		{
			long k = t[i] + m;
			if(i + 1 >= n || t[i+1] >= k)
				wa += m;
			else
				wa += t[i+1] - t[i];
		}
		Console.WriteLine(wa);
	}
	

	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}



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

int main(){
    long long N;
    cin>>N;
    string ans = "";

    while(N){
        N--;
        int tmp = N%26;
        ans += char('a' + tmp);
        N /= 26;
    }

    reverse(ans.begin(),ans.end());

    cout<<ans<<endl;

    return 0;
}

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

#define int long long
#define pb push_back
#define mp make_pair
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,l;
    cin>>n>>l;
    int arr[n];
    int min=10000;
    int ans=0;
    for(int i=0;i<n;i++)
    {
        arr[i]=l+i;
        if(abs(arr[i])<abs(min))
        {
            if(min==10000)
            {

            }
            else
            {
                ans+=min;
            }
            min=arr[i];
        }
        else
        {
            ans+=arr[i];
        }
    }

    cout<<ans;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main() {
    int N, D; cin >> N >> D;
    cout << (N + (2 * D))/(2*D + 1) << endl;
    
    
    return 0;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

public class Main {
	public static void main(final String[] args){
    
    Scanner sc = new Scanner(System.in);
    
    List<Character> list = new ArrayList<>();
    String s = sc.next();
    int count = 0;

    for(int i = 0; i < s.length(); i++){
        list.add(s.charAt(i));

        
        }
    
    for(int i = 0; i < s.length()-1; i++){
        if(list.get(i).equals(list.get(i+1))){
            count++;
        }
    }
    if(count == 0){
        System.out.println("Good");
    }else{
        System.out.println("Bad");
    }




    
    


    
	}
}

Measured memory_bytes: 35564
/*************************************************************************
>>> Author: WindCry1
>>> Mail: lanceyu120@gmail.com
>>> Website: https://windcry1.com
>>> Date: 12/30/2019 11:03:37 PM
*************************************************************************/
//#pragma GCC optimize(2)
//#pragma GCC diagnostic error "-std=c++11"
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <iostream>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <stack>
#include <bitset>
#include <iomanip>
#include <list>
#include <sstream>
#include <fstream>
#include <numeric>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define endl '\n'
#define ALL(x) x.begin(),x.end()
#define MP(x,y) make_pair(x,y)
#define ll long long
#define int long long
#define ull unsigned long long
#ifdef WindCry1
#define DEBUG(x) cout<<#x<<" : "<<x<<endl;
#endif
#define lowbit(x) x&(-x)
#define ls x<<1
#define rs x<<1|1
using namespace std;
template<typename T> inline T MIN(const T &a,const T &b) {return a<b?a:b;}
template<typename T> inline T MAX(const T &a,const T &b) {return a>b?a:b;}
template<typename T,typename ...Args> inline T MIN(const T &a,const T &b,Args ...args) {return MIN(MIN(a,b),args...);}
template<typename T,typename ...Args> inline T MAX(const T &a,const T &b,Args ...args) {return MAX(MAX(a,b),args...);}
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int dir[4][2]={-1,0,1,0,0,-1,0,1};
bool isprime(int n){
	if(n==1) return 0;
	for(int i=2;i*i<=n;i++){
		if(n%i==0) return 0;
	}
	return 1;
}
signed main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#ifdef WindCry1
	freopen("C:/Users/LENOVO/Desktop/in.txt","r",stdin);
#endif
	int n;cin>>n;
	int res=0;
	for(int i=2;i*i<=n;i++){
		int cnt=0;
		while(n%i==0) n/=i,++cnt;
		res+=(int)(sqrt(2*cnt+0.25)-0.5);
	}
	if(isprime(n)) ++res;
	cout<<res<<endl;
	return 0;
}



Measured memory_bytes: 3696
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define all(obj) (obj).begin(), (obj).end()
#define lpair pair<ll, ll>
#define vint vector<ll>
#define vinput(name) for(int i=0; i<(int)(name.size()); i++) cin >> name[i];
#define voutput(name) for(int i=0; i<(int)(name.size()); i++) cout << name[i] << endl;
typedef long long ll;

using namespace std;

ll ans = 0;

int main(void){
	deque <char> deq;
	string s; cin >> s;
	rep(i, s.length()){
		deq.push_back(s[i]);
	}
	int Q; cin >> Q;
	int isFront = true;
	rep(i, Q){
		int t; cin >> t;
		if(t == 1){
			isFront = !isFront;
		} else{
			int f;
			char c;
			cin >> f >> c;
			if((f == 1 && isFront) || (f == 2 && !isFront)) deq.push_front(c);
			else deq.push_back(c);
		}
	}

	if(isFront){
		rep(i, deq.size()) cout << deq[i];
	} else{
		for(int i=deq.size()-1; i>=0; i--) cout << deq[i];
	}

	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif


    int h1, m1, h2, m2, w;
    cin >> h1 >> m1 >> h2 >> m2 >> w;

    int have = (h2 * 60 + m2) - (h1 * 60 + m1);
    cout << max(0ll, have - w) << endl;

}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  ll ans = 0;
  for (ll i = 1; i <= N; ++i) {
    ll a;
    cin >> a;
    if (i % 2 == 1 && a % 2 == 1) {
      ans += 1;
    }
  }
  cout << ans << "\n";
}


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


int main() {
	
	int N;
	cin >> N;
	vector<int> a(N);
	for(auto &i : a) cin >> i;
	sort(a.begin(),a.end());
	cout << a.back() - a.front() << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    int k,n;cin>>k>>n;
    int before = 0;
    vector<int> v(n+1);
    int tmp;
    int maxdis=0;
    rep(i,n){
        tmp;cin>>tmp;
        v[i]=tmp-before;
        if(maxdis<v[i]){maxdis=v[i];}
        before = tmp;
    }
    v[n]=k-before;
    if(v[0]+v[n]>maxdis)maxdis=v[0]+v[n];
    co(k-maxdis);
}

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

int main(){
  int N, A, B, ans = 0 ;
  cin >> N ;
  if(N % 2 == 0){
     ans = N / 2 ;
  }
  else ans = (N / 2) + 1 ;
  
  cout << ans << endl ;
  return 0 ;
}

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

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

    vector<int> a(n);
    int total = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        total += a[i];
    }

    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        if (a[i] * 4 * m >= total) {
            cnt++;
        }
    }
    if (cnt >= m) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}



Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n;
		long x, y, z;
		int a1, a2, a3;
		int m1, m2, m3;
		long countX, countY, countZ;

		while (true) {
			a1 = sc.nextInt();
			m1 = sc.nextInt();
			a2 = sc.nextInt();
			m2 = sc.nextInt();
			a3 = sc.nextInt();
			m3 = sc.nextInt();
			if ((a1 | a2 | a3 | m1 | m2 | m3) == 0) {
				break;
			}

			x = 1;
			y = 1;
			z = 1;
			countX = 0;
			countY = 0;
			countZ = 0;
			while (true) {
				x = (a1 * x) % m1;
				countX++;
				if (x == 1) {
					break;
				}
			}
			while (true) {
				y = (a2 * y) % m2;
				countY++;
				if (y == 1) {
					break;
				}
			}
			while (true) {
				z = (a3 * z) % m3;
				countZ++;
				if (z == 1) {
					break;
				}
			}
			long lcm1 = countX * countY / gcd(countX, countY);
			long lcm2 = lcm1 * countZ / gcd(countZ, lcm1);
			System.out.println(lcm2);
		}
	}

	public static long gcd(long x, long y) {
		if (y == 0) {
			return x;
		}
		long swap = x + y;
		x = Math.max(x, y);
		y = swap - x;
		return gcd(y, x % y);
	}
}

Measured memory_bytes: 12000
#include<stdio.h>
#include <string.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
int main(){
	int n,t,a[100002],min=1e9,max=0,dif=0,num=0;
	scanf("%d %d",&n,&t);
	FOR(i,0,n) scanf("%d",&a[i]);

	FOR(i,0,n){
		if(min > a[i]){
			min = a[i];
			max = 0;
		}
		if(max < a[i]){
			max = a[i];
			if(dif == max-min){
				num++;
			}
			if(dif < max-min){
				dif = max-min;
				num = 1;
			}
		}
	}
	printf("%d\n",num);
}

Measured memory_bytes: 512
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Skip solver = new Skip();
        solver.solve(1, in, out);
        out.close();
    }

    static class Skip {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            long x = in.nextLong();

            long[] city = new long[n];
            for (int i = 0; i < n; i++) {
                city[i] = Math.abs(x - in.nextLong());
            }
            long result = city[0];
            for (int i = 1; i < n; i++) {
                result = gcd(result, city[i]);
            }
            out.print(result);

        }

        static long gcd(long a, long b) {
            return b == 0 ? a : gcd(b, a % b);
        }

    }
}



Measured memory_bytes: 60104
n = int(input())
dp = [0]*(n+1)
for i in range(n+1):
    if i == 0:
        dp[i] = 1
    elif i == 1:
        dp[i] = 1
    else:
        dp[i] = dp[i-1] + dp[i-2]
print(dp[n])


Measured memory_bytes: 5600
#include "bits/stdc++.h"
using namespace std;
int main() {
	long long N;
	cin >> N;
	vector<long long>V(N);
	for (long long i = 0; i < N; i++) {
		cin >> V.at(i);
	}
	vector<pair<long long, long long>>A(100000, make_pair(0, 0)), B(100000, make_pair(0, 0));
	for (long long i = 0; i < 100000; i++) {
		A.at(i).second = i + 1;
		B.at(i).second = i + 1;
	}
	for (long long i = 0; i < N; i++) {
		if (i % 2 == 0) {
			A.at(V.at(i) - 1).first++;
		}
		else{
			B.at(V.at(i) - 1).first++;
		}
	}
	sort(A.begin(), A.end(), greater<pair<long long, long long>>());
	sort(B.begin(), B.end(), greater<pair<long long, long long>>());
	if (A.at(0).second == B.at(0).second) {
		cout << N - max(A.at(0).first + B.at(1).first, A.at(1).first + B.at(0).first) << endl;
	}
	else {
		cout << N - (A.at(0).first + B.at(0).first) << endl;
	}
}

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

typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const int int_inf = 100000000;
const double eps = 1e-9;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    string s;
    cin >> n;
    cin >> s;

    ll ans = 0;

    vector<int> red, gre, blu;
    vector <bool> r(4000, false), g(4000, false), b(4000, false);
    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') {
            r[i] = true;
            red.push_back(i);
        }
        if (s[i] == 'G') {
            g[i] = true;
            gre.push_back(i);
        }
        if (s[i] == 'B') {
            b[i] = true;
            blu.push_back(i);
        }
    }
    ans = red.size() * gre.size() * blu.size();

    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            if (s[i] == s[j]) continue;
            if (s[i] == 'R') {
                if (s[j] == 'G') {
                    if (j + j - i < n and s[j+j-i] == 'B') ans--;
                }
                if (s[j] == 'B') {
                    if (j + j - i < n and s[j+j-i] == 'G') ans--;
                }
            }
            if (s[i] == 'G') {
                if (s[j] == 'R') {
                    if (j + j - i < n and s[j+j-i] == 'B') ans--;
                }
                if (s[j] == 'B') {
                    if (j + j - i < n and s[j+j-i] == 'R') ans--;
                }
            }
            if (s[i] == 'B') {
                if (s[j] == 'G') {
                    if (j + j - i < n and s[j+j-i] == 'R') ans--;
                }
                if (s[j] == 'R') {
                    if (j + j - i < n and s[j+j-i] == 'G') ans--;
                }
            }            
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3696
const val INF = Int.MAX_VALUE / 4

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  if (n == 1) {
    println("POSSIBLE")
    return
  }

  val graph = Array(n, { mutableListOf<Int>() })
  val rawParents = readLine()!!.split(" ").map(String::toInt)
  rawParents.forEachIndexed { rawIndex, rawValue ->
    val index = rawIndex + 1
    val parent = rawValue - 1
    graph[parent].add(index)
  }
  val xs = readLine()!!.split(" ").map(String::toInt)

  val dp = IntArray(n, { INF })
  fun isValid(v: Int): Boolean {
    if (graph[v].size == 0) {
      dp[v] = 0
      return true
    }
    if (graph[v].any { !isValid(it) }) {
      return false
    }

    val innerDP = Array(graph[v].size + 1, { IntArray(xs[v] + 1, { INF }) })
    innerDP[0][0] = 0
    for (i in graph[v].indices) {
      val c = graph[v][i]
      val v1 = xs[c]
      val v2 = dp[c]
      for (k1 in 0..xs[v]) {
        if (innerDP[i][k1] < INF) {
          if (k1 + v1 <= xs[v]) {
            innerDP[i + 1][k1 + v1] = Math.min(innerDP[i + 1][k1 + v1], innerDP[i][k1] + v2)
          }
          if (k1 + v2 <= xs[v]) {
            innerDP[i + 1][k1 + v2] = Math.min(innerDP[i + 1][k1 + v2], innerDP[i][k1] + v1)
          }
        }
      }
    }
    val min = innerDP[graph[v].size].min()!!
    if (min == INF) return false
    dp[v] = min
    return true
  }

  val ans = isValid(0)
  println(if (ans) "POSSIBLE" else "IMPOSSIBLE")
}


Measured memory_bytes: 44312
#include <bits/stdc++.h>
#define ms(x, n) memset(x,n,sizeof(x));
#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 pb push_back
#define PI acos(-1.0)
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;



int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int a, b, now;
    now = 1;
    cin >> a >> b;
    int cnt = 0;
    while (now < b) {
        now += a-1;
        ++cnt;
    }
    cout << cnt <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

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

using namespace std;

int digit_sum(int num) {
    int ret = 0;
    while (num) {
        ret += num % 10;
        num /= 10;
    }
    return ret;
}

int main() {
    int N, A, B;
    cin >> N >> A >> B;

    int ans = 0;
    REP(i, N + 1) {
        int ds = digit_sum(i);
        if (A <= ds && ds <= B)
            ans += i;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>    
using namespace std;
#define ll long long 
#define pi pair<ll,ll>
#define pd pair<ld,ld>
#define pb push_back
#define inf 1e16
#define mod 1000000007
#define en '\n'
#define ld long double
#define ff first
#define ss second
#define ull unsigned long long 
ll pw(ll b, ll r, ll md){
	ll ans = 1;
	while(r){
		if(r&1)ans = (ans*b)%md;
		b = (b*b)%md;
		r>>=1;
	}
	return ans;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ld n;cin>>n;
	cout<<setprecision(10)<<(n/3)*(n/3)*(n/3)<<en;
	return 0 ; 
}



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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll B[105];

int main() {
    ll N, M, C;
    cin >> N >> M >> C;
    REP(i, M) {
        cin >> B[i];
    }
    ll ans = 0;
    REP(i, N) {
        ll s = 0;
        REP(j, M) {
            ll a;
            cin >> a;
            s += a * B[j];
        }
        if (s + C > 0)
            ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// Date: 2020-03-17

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)x.size())
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

#define mid ((l+r)>>1)
#define lc rt << 1
#define rc rt << 1 | 1
#define lson lc, l, mid
#define rson rc, mid + 1, r

int n, m;
LL mx[N<<2], add[N<<2], sum[N];

void pd(int rt) {
    if(add[rt]) {
        add[lc] += add[rt], mx[lc] += add[rt];
        add[rc] += add[rt], mx[rc] += add[rt];
        add[rt] = 0;
    }
}

void pushup(int rt) {
    mx[rt] = max(mx[lc], mx[rc]);
}

void update(int rt, int l, int r, int ql, int qr, LL v) {
    if(ql <= l && r <= qr) {
        mx[rt] += v;
        add[rt] += v;
        return;
    }
    pd(rt);
    if(ql <= mid) update(lson, ql, qr, v);
    if(qr > mid) update(rson, ql, qr, v);
    pushup(rt);
}

LL ask(int rt, int l, int r, int x) {
    if(l == r) return mx[rt];
    pd(rt);
    if(x <= mid) return ask(lson, x);
    else return max(mx[lc], ask(rson, x));
}

struct seg {
    int l, r, v;
    bool operator < (const seg& rhs) const {
        if(r != rhs.r) return r < rhs.r;
        return l < rhs.l;
    }
} s[N];

LL dp[N];
vector<pii> L[N], R[N];
int main() {
    FIO;
    cin >> n >> m;
    rep(i, 1, m) {
        cin >> s[i].l >> s[i].r >> s[i].v;
        sum[s[i].r] += s[i].v;
        L[s[i].l].pb(mk(s[i].r, s[i].v));
        R[s[i].r].pb(mk(s[i].l, s[i].v));
    }
    LL ans = 0;
    rep(i, 1, n) {
        for(auto s : L[i]) update(1, 0, n, 0, i-1, s.se);
        dp[i] = ask(1, 0, n, i-1);
        update(1, 0, n, i, i, dp[i]);
        chkmax(ans, dp[i]);
        for(auto s : R[i]) update(1, 0, n, 0, s.fi-1, -s.se);
        //cout<<i<<" "<<dp[i]<<endl;
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 39424
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<string>
#include<functional>
using namespace std;
typedef	long long int ll;

int main(){
    int n;
    cin >> n;
    vector<int> v;
    int a;
    for(int i = 0; i < n; i++){
        cin >> a;
        v.push_back(a-i-1);
    }
    sort(v.begin(), v.end());
    int b = v[(n-1)/2];
    ll s = 0;
    for(int i = 0; i < n; i++){
        s = s + abs(v[i] - b); 
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 1400
using Atcoder;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var secondLine = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            int result = int.MaxValue;
            for (int i = 0; i < N; i++)
            {
                var s1 = secondLine.Take(i + 1).Sum();
                var s2 = secondLine.Skip(i + 1).Take(N - i + 1).Sum();
                if (Math.Abs(s1 - s2) <= result)
                {
                    result = Math.Abs(s1 - s2);
                }
            }
            Console.WriteLine(result);
        }
        //static void Main(string[] args)
        //{
        //    var temp = new Atcoder.ABC129.B();
        //    temp.Run();
        //}

    }

    //var N = int.Parse(Console.ReadLine());
    //var S = Console.ReadLine();
    //var K = Console.ReadLine().Split(' ');
    //var N = int.Parse((K[0]));
    //var M = int.Parse((K[1]));
    //var firstLine = Console.ReadLine().Split(' ').Select(int.Parse);
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
double Sequence(double a,int n)
{
    if(n==10)return a*2;
    if(n%2==0)return a*2+Sequence(a*2,n+1);
    if(n==1)return a+Sequence(a,n+1);
    return a/3+Sequence(a/3,n+1);
}
int main()
{
    double n=0,a;
    while(cin>>a){
        n=Sequence(a,1);
        cout<<setprecision(10)<<n<<endl;
    }
}

Measured memory_bytes: 1276
M=1000003
o=->a,n{n<1?1:(n%2>0?a:1)*o[a,n/2]**2%M}
*f=t=1
1.upto(M){|i|f<<t=t*i%M}
gets
$<.map{|s|x,d,n=s.split.map &:to_i
t=x*o[d,M-2]%M
p d<1?o[x,n]:M<t+n||t<1?0:f[t+n-1]*o[f[t-1],M-2]*o[d,n]%M}

Measured memory_bytes: 13308
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}


/*
int N;
Graph G;

int main() {
  cin >>N;
  rep(i, N-1){
    int a,b; cin >>a >>b; a--; b--;
    G[a].push_back(b); G[b].push_back(a);
  }
}
*/

int main() {
  string s; cin >>s;
  int n = s.size();
  rep(i, n-1){
    if (s[i] == 'A' && s[i+1] == 'C'){
      cout <<"Yes" <<endl; return 0;
    }
  }
  cout <<"No" <<endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,h,i,j,k,l,m,n,x,y;
	ll		ans = 0;
	string	s;
	cin >> a >> b;

	if (a%2==1) {
		x = a;
		i = a+1;
	} else {
		x = 0;
		i = a;
	}
	if (b%2==1) {
		y = 0;
		j = b;
	} else {
		y = b;
		j = b - 1;
	}

	ans = x ^ y;

	if (i<j) {
		if ( ((j-i+1)/2)%2 == 1 ) {
			ans = ans^1;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3588
package main

import "fmt"

func main() {
	var x, a, b int
	fmt.Scan(&x, &a, &b)
	if -a+b > x {
		fmt.Println("dangerous")
	} else if -a+b <= 0 {
		fmt.Println("delicious")
	} else {
		fmt.Println("safe")
	}
}


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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
  cout << a;
  ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
  cout << a << ' ';
}

int ans = 0;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

int main()
{
  int a, b, n, x, y;
  cin >> a >> b;
  if (a + b >= 24)
    pr(a + b - 24);
  else
    pr(a + b);

  return 0;
}

Measured memory_bytes: 3604
def adjust(array):
    # 調整
    re_array = []
    for arr in array:

        # 集合を取る #と.のみ
        a = set(arr)

        # 集合が１つで.だけのとき
        if len(a) == 1 and ''.join(a) == '.':
            continue

        else:
            re_array.append(arr) # 配列にapeendで配列を入れている
    return re_array


# 入力
H, W = map(int, input().split())
array = [list(input()) for _ in range(H)]

# 横
array = adjust(array)

# 縦
array = list(zip(*array)) # 転置する
array = adjust(array)

# 戻す
array = list(zip(*array))

# 出力
for arr in array:
    print(''.join(arr))

Measured memory_bytes: 3188
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;


public class Main {

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        int x = 0;
        int max = 0;
        int n = s.nextInt();
        String word = s.next();
        for(int i=0;i<n;i++){
            if(word.charAt(i)=='I')x++;
            else x--;
            max = Math.max(max,x);
        }
        System.out.println(max);
    }

}




class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 25244
N, M, X, Y = map(int, input().split())
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
ans = 'War'
for z in range(X+1, Y+1):
    if all([i < z for i in x]) and all([i >= z for i in y]):
        ans = 'No War'
        break
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>

using namespace std;

int main(){

    int ans=1;
    int n;
    cin>>n;

    string s;
    cin>>s;

    for(int i=0;i<n-1;i++){
        if(s[i]!=s[i+1]){
            ans++;
        }
    }
    
    cout<<ans<<endl;

    return 0;
}


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

using namespace std;

typedef pair<int, int> P;

int dist(P a, P b){
	if (a.first > b.first) swap(a, b);

	int d1 = abs(a.first - b.first);
	int d2 = abs(a.second - b.second);

	if (a.second >= b.second) return d1 + d2;
	return d1 + d2 - min(d1, d2);
}

int main(){
	int W, H, N;
	cin >> W >> H >> N;

	P pos;
	int ans = 0;
	bool f = true;
	while (N--){
		P nxt;
		cin >> nxt.first >> nxt.second;
		if(!f) ans += dist(pos, nxt);
		f = false;
		pos = nxt;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1164
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication58
{
    class Program
    {
        static void Main()
        {
            int a = int.Parse(Console.ReadLine());
            for (int d = 1; d <=a; d++)
            { int b = d;
                if (b % 3 == 0) { Console.Write(" " + d);continue; }
                while (b!=0)
                {
                    if (b % 10 == 3) { Console.Write(" "+d); break; }
                    b /= 10;
                }
            }
            Console.WriteLine();
        }
    }
}



Measured memory_bytes: 17988
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
    ios
    string s;
    cin>>s;
    int k;
    cin>>k;

    int n=s.size();
    int a,cnt=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]!='1')
        {
            a=s[i]-'0';
            break;
        }
        else
        {
            cnt++;
            if(cnt==k)
            {
                a=1;
                break;
            }
        }
    }
    cout<<a;

}

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

using namespace std;

int main(){
    string S,T;

    cin >> S >> T;

    bool flag = true;

    map<char, char> a, b;

    for(int i = 0; i < S.size(); i++){
        char s = S[i], t = T[i];
        if(a.count(s)){
            if(a[s] != t){
                flag = false;
            }
        }
        if(b.count(t)){
            if(b[t] != s){
                flag = false;
            }
        }

        a[s] = t;
        b[t] = s;
    }

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 3924
// 2014/04/27 Tazoe

#include <iostream>
using namespace std;

bool is_prime[10000001];

int main()
{
	is_prime[0] = is_prime[1] = false;
	for(int i=2; i<10000001; i++){
		is_prime[i] = true;
	}

	for(int i=2; i*i<10000001; i++){
		if(is_prime[i]){
			for(int j=i*i; j<10000001; j+=i){
				is_prime[j] = false;
			}
		}
	}

	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		for(int i=n; i>=13; i--){
			if(is_prime[i] && is_prime[i-2] && is_prime[i-6] && is_prime[i-8]){
				cout << i << endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 10924
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t,int64_t> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

 
void solve()
{
    int n;cin>>n;
    vector<int>p(n);vector<int>s(n);
    REP(i,n){cin>>p[i];s[i]=p[i];}
    sort(s.begin(),s.end());
    int sum=0;
    REP(i,n){if(p[i]!=s[i])sum++;}
    if(sum<=2)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int f(int x){
	int ans = 0;
	while(x %2 == 0){
		x /= 2;
		ans++;
	}
	return ans;
}

int main(){
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1;i <= n;i++){
		ans = max(ans,f(i));
	}
	cout << pow(2,ans) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#define ll long long
using namespace std;

int n,m;
const int mod = 1000000007;
int cal(int x,int y)
{
    int ret = 1;
    for (int i = 0; i < y; i++)
        ret = ret * x % mod;
    return ret;
}
int fa[100010];
int find(int u)
{
    if (u == fa[u]) return u;
    return fa[u] = find(fa[u]);
}
int main()
{
    while (scanf("%d%d",&n,&m)!=EOF) {
        if (n == 0 && m == 0) return 0;
        for (int i = 1; i <= n; i++) fa[i] = i;
        for (int i = 0; i < m; i++) {
            int u,v;
            scanf("%d%d",&u,&v);
            if (find(u) == find(v)) continue;
            fa[fa[u]] = fa[v];
        }
        int cnt = 0;
        for (int i = 1; i <= n; i++)
        if (find(i) == i)
            cnt++;
        int ans = 0;
        if (cnt == n) {
            ans = cal(2,n);
        }
        else
            ans = (cal(2,cnt) + 1) % mod;
        printf("%d\n",ans);
    }
}

Measured memory_bytes: 1576
from heapq import heappush, heappop

# 入力
N = int(input())
a, b = (
    zip(*(map(int, input().split()) for _ in range(N - 1))) if N - 1 else
    ((), ())
)

# 頂点1, N から各蝶点への距離を求める
G = [{} for _ in range(N + 1)]
for x, y in zip(a, b):
    G[x][y] = 1
    G[y][x] = 1
INF = 10**10


def dijkstra(G, s):
    dp = [INF for _ in range(len(G))]
    q = []
    heappush(q, (0, s))
    while q:
        c, i = heappop(q)
        if dp[i] == INF:
            dp[i] = c
            for j, w in G[i].items():
                heappush(q, (c + w, j))
    return dp


dp1 = dijkstra(G, 1)
dpN = dijkstra(G, N)
# 頂点Nより頂点1のほうが近い、または、頂点1と頂点Nとの距離が等しいは
# 頂点1から頂点Nの間のパスに含まれる頂点のうち、Fennecが塗れる頂点である。
ans = (
    'Fennec' if sum(dp1[i] <= dpN[i] for i in range(1, N + 1)) > N // 2 else
    'Snuke'
)

# 出力
print(ans)


Measured memory_bytes: 57592
s = list(input())
ans = 0
if s[0] == s[1] == s[2] == "R":
    ans = 3
elif s[0] == s[1] == "R" or s[1] == s[2] == "R":
    ans = 2
elif "R" in s:
    ans = 1

print(ans)


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

int main(){
	int a[10];
	for(int i=0;i<10;i++)cin>>a[i];
	sort(a,a+10);
	cout<<a[9]<<endl<<a[8]<<endl<<a[7]<<endl;
	
	return 0;
}

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

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;

void header() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

void solve() {
    map<int, int> mp;
    int n, x;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> x, mp[x]++;
    cout << (n == mp.size() ? "YES" : "NO") << endl;
}

int main() {
	header();
	solve();
	return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <math.h>
#include <queue>
using namespace std;

typedef long long ll;
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define memset(v, h) memset((v), h, sizeof(v))
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll m[20][20];

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

struct node
{
    public: ll x;
    public: ll y;

    node(ll xx, ll yy)
    {
        x = xx;
        y = yy;
    }
};

int main(){
    ll a, b;
    cin >> a >> b;
    
    ll k = a / b;
    if(a % b > 0)
    {
        k++;
    }

    cout << k << endl;
    return 0;
}

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

int main()
{
	int weights[10] = { 512, 256, 128, 64, 32, 16, 8, 4, 2, 1 };
	vector<int> ans;
	int n;

	while (cin >> n)
	{
		ans.clear();
		for (int i = 0; i < 10; ++i)
		{
			if (n >= weights[i])
			{
				n -= weights[i];
				ans.push_back(weights[i]);
			}
		}

		//??????????????????
		for (int i = ans.size() - 1; i >= 0; --i)
		{
			cout << ans[i];
			if (i != 0) cout << " ";
		}

		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N; cin >> N;
    if(N%2 == 0) cout << N << endl;
    else cout << N * 2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mod 1000000007
typedef long long ll;
using namespace std;

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


Measured memory_bytes: 256
PROGRAM piyo
      IMPLICIT NONE
      character(2*(10**5)) :: s,a,p,buffer
      character(1) :: c
      integer(16) :: sLen,aLen,pLen,q,i,f,t
      character(5) :: in(2*(10**5))
      logical :: inv = .true.
      
      read*,s
      sLen = len_trim(s)
      read*,q
      aLen = 0
      pLen = 0
      
      do i = 1,q
        read'(a5)',in(i)
      end do
      
      
      do i = 1,q
        
        if( in(i)(1:1)=='1' )then
          inv = .not.(inv)
        else
          if( in(i)(3:3)=='1' )then
            if( inv )then
              aLen = aLen + 1
              a(aLen:aLen) = in(i)(5:5)
            else
              pLen = pLen + 1
              p(pLen:pLen) = in(i)(5:5)
            end if
          else
            if( inv )then
              pLen = pLen + 1
              p(pLen:pLen) = in(i)(5:5)
            else
              aLen = aLen + 1
              a(aLen:aLen) = in(i)(5:5)
            end if
          end if
        end if
        
      end do
      
      
      if( inv )then
      
        buffer(1:aLen) = a(1:aLen)
        do i = 1,aLen
          a(aLen-i+1:aLen-i+1) = buffer(i:i)
        end do
        
        print*,a(1:aLen)//s(1:sLen)//p(1:pLen)
      else
        buffer(1:sLen) = s(1:sLen)
        do i = 1,sLen
          s(sLen-i+1:sLen-i+1) = buffer(i:i)
        end do
        
        buffer(1:pLen) = p(1:pLen)
        do i = 1,pLen
          p(pLen-i+1:pLen-i+1) = buffer(i:i)
        end do
        print*,p(1:pLen)//s(1:sLen)//a(1:aLen)
      end if
      
      END PROGRAM

Measured memory_bytes: 4516