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

using namespace std;

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

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

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


int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================



	string S;
	cin >> S;

	ll sum = 0;
	ll n_white = 0;
	for (int i = 0; i < S.length(); i++) {
		if (S[i] == 'W') {
			sum += i + 1;
			n_white++;
		}
	}

	cout << sum - (n_white * (n_white + 1)) / 2;

}


Measured memory_bytes: 720
n, m, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)

aa = [0]
bb = [0]
a.size.times{|i| aa << a[i] + aa.last }
b.size.times{|i| bb << b[i] + bb.last }

i = 0
j = b.size
mx = 0
while i < aa.size && j >= 0
  if aa[i] + bb[j] <= k
    mx = i+j if mx < i+j

    i += 1
  else
    j -= 1
  end
end


p mx


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

int main() {
    int K, S;
    cin >> K >> S;
    int count = 0;
    int maxX = min(K, S);
    for (int x = 0; x <= maxX; x++){
        int ypz = S - x;
        if (ypz <= K){
            count += ypz + 1;
        }else if (ypz <= 2 * K){
            count += 2 * K - ypz + 1;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3548
#include <stdio.h>
int main(void){
    int n,m,l;
    int i,j,k;
    long long int sum=0;
    
    scanf("%d %d %d",&n,&m,&l);
    int A[n][m];
    int B[m][l];
    
    for(i=0;i<n;i++)
        for(j=0;j<m;j++) scanf("%d",&A[i][j]);
        
    for(j=0;j<m;j++)
        for(k=0;k<l;k++) scanf("%d",&B[j][k]);
        
    for(i=0;i<n;i++){
        for(k=0;k<l;k++){
            for(j=0;j<m;j++){
                sum=sum+A[i][j]*B[j][k];
            }
            printf("%lld",sum);
            sum=0;
            if(k==l-1) break;
            printf(" ");
        }
        printf("\n");
    }
    
    return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,s,t) for(int i=s ; i<t ; i++)
typedef long long ll;
typedef pair<ll,ll> P;
int main(){
  ll n; cin >> n;
  vector<ll> a(n);
  rep(i,0,n){
    cin >> a[i];
  }
  ll cnt=0, nowi=0, nown=1;
  while(nowi<n){
    if(a[nowi] != nown){
      cnt++;
    }else{
      nown++;
    }
    nowi++;
  }
  if(cnt==n){
    cnt = -1;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
#define MOD 1000000007
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> p;
typedef vector<int> vi;
set <int> st;
int a,b,c,d;
int n;
int main(int argc,char const* argv[])
{
  cin >> a >> b >> c >> d;
  cout << min(a,b)+min(c,d) << endl;
  return 0;
}


Measured memory_bytes: 764
n, k = map(int, input().split())
a = [x*0 for x in range(n)]
count = 0

for i in range(k):
    d = int(input())
    A = list(map(int, input().split()))
    for j in range(d):
        a[A[j]-1] += 1
    
for t in range(n):
    if a[t] == 0:
        count += 1

print(count)

Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std;
 vector<int> x(9),y(9);

double dist(int i, int j){
     double dx = x[i] - x[j];
     double dy = y[i] - y[j];
     return pow(dx*dx + dy*dy,0.5);
 }

int main(){
    int n;cin>>n;
   
    for(int i = 1; i <= n; i++) cin>>x[i]>>y[i];
    double sum = 0.0;

    vector<int> p(n);
    for(int i = 0; i < n; i++) p[i] = i+1;

    do {
        for(int i = 0; i < n-1; i++){
            sum+=dist(p[i],p[i+1]);
        }
    } while(next_permutation(p.begin(),p.end()));
    int fact = 1;
    for(int i = 2; i <= n ;i++) fact*=i;
    cout<<fixed<<setprecision(10)<<sum/fact<<endl;
}



Measured memory_bytes: 256
s=input()
n=len(s)
moji1=s[0]
moji2=s[1]
count=0
flag=False
for i in range(n-2):
  if (i+count)%2==0:
    if s[i+2]!=moji1:
      count+=1
      if i+2==n-1:
        flag=True
  else:
    if s[i+2]!=moji2:
      count+=1
      if i+2==n-1:
        flag=True
  if count==2:
    break
if count==0:
  print('Second')
  exit()
if count==1:
  if flag:
    if (n-2)%2==0:
      print('Second')
    else:
      print('First')
  else:
    print('First')
  exit()
if s[0]==s[-1]:
  if (n-3)%2==0:
    print('Second')
  else:
    print('First')
else:
  if (n-2)%2==0:
    print('Second')
  else:
    print('First')


Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int i=1;
        while(true){
            int a=scan.nextInt();
            if(a == 0)break;
            System.out.println("Case "+i+": "+a);
            i++;
        }
        scan.close();
        return;
    }
}


Measured memory_bytes: 41644
#include <algorithm>
#include <cstddef>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

// Convenience function to read a vector of values from standard input
template <typename T>
auto readVector(T N) {
    vector<T> A;
    for (T i = 0; i < N; i++) {
        T Ai;
        cin >> Ai;
        A.push_back(Ai);
    }
    return A;
}

int main() {
    int N;
    cin >> N;
    auto prices = readVector(N);
    sort(prices.begin(), prices.end());
    *prices.rbegin() /= 2;
    cout << accumulate(prices.begin(), prices.end(), 0) << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC089C
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            string[] names = new string[N];
            for(int i = 0; i < N; i++)
            {
                var line = Console.ReadLine();
                names[i] = line;
            }

            char[] march = "MARCH".ToCharArray();
            long[] nums = new long[5];
            for(int i = 0; i < N; i++)
            {
                for(int j = 0; j < 5; j++)
                {
                    if (names[i][0] == march[j])
                    {
                        nums[j]++;
                        break;
                    }
                }
            }

            long ans = 0;
            for(int i = 0; i < 5; i++)
            {
                for(int j = i + 1; j < 5; j++)
                {
                    for(int k = j + 1; k < 5; k++)
                    {
                        ans += nums[i] * nums[j] * nums[k];
                    }
                }
            }

            Console.WriteLine(ans);
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13664
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
  int n;
  cin>>n;
  int t[n],s[n],g[n],v[n];
  s[0]=g[0]=0;
  for(int i=1;i<=n; i++){
    cin >> t[i];
    s[i]=g[i-1];
    g[i]=s[i]+2*t[i];
  }
  for(int i=1;i<=n; i++){
    cin >> v[i];
  }
  int a=g[n];
  int vmin[a];
  for(int i=1;i<=a ;i++){
    vmin[i]=min(i,a-i);
  }
  for(int i=1;i<=n ;i++){
    for(int j=0;j<=s[i];j++){vmin[j]=min(vmin[j],s[i]-j+2*v[i]);}
    for(int j=s[i];j<=g[i];j++){vmin[j]=min(vmin[j],2*v[i]);}
    for(int j=g[i];j<=a;j++){vmin[j]=min(vmin[j],j-g[i]+2*v[i]);}
  }
  double ans =0;
  for(int i=1;i<=a ;i++){
    ans+=vmin[i];
  }
  cout <<fixed<<setprecision(3)<<ans/4<<endl;
  return 0;
}

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

#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
typedef long long ll;

using namespace std;

char b;

int main(){
    cin>>b;
    if(b=='A'){
        cout<<'T';
    }else if(b=='T'){
        cout<<'A';
    }else if(b=='G'){
        cout<<'C';
    }else{
        cout<<'G';
    }
}


Measured memory_bytes: 256
from copy import deepcopy
INF = 1001001001
N, M, X = map(int, input().split())
C = []
A = []
for i in range(N):
    k = list(map(int, input().split()))
    C.append(k[0])
    A.append(deepcopy(k[1:]))

ans = INF
for s in range(1 << N):
    cost = 0
    d = [0]*M
    for i in range(N):
        if s >> i & 1:
            cost += C[i]
            for j in range(M):
                d[j] += A[i][j]
    ok = True
    for j in range(M):
        if d[j] < X:
            ok = False
    if ok:
        ans = min(ans, cost)

if ans == INF:
    print('-1')
else:
    print(ans)

Measured memory_bytes: 9360
import sys
sys.setrecursionlimit(100000000)

n = int(raw_input())
h = list(map(int, raw_input().split()))
memo = {}

def get_cost(i, j):
    if j >= n:
        return 0
    return abs(h[i] - h[j])

def get_min_cost_from_postion(i):
    if i >= n-1:
        return 0
    if i in memo:
        return memo[i]
    k = min(2, (n-1)-i)
    ans = min(
        get_cost(i, i+x) + get_min_cost_from_postion(i+x) for x in range(1,k+1))

    memo[i] = ans
    return ans

ans = get_min_cost_from_postion(0)

print ans


Measured memory_bytes: 240880
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

r = get_int

puts 3 * r ** 2


Measured memory_bytes: 14396
import java.io.*;
import java.util.*;
 
public class Main{
	
 
	int N;
	long A, B;
	long[] X;
	long[] memo;
	long dfs(int idx){
		if(idx == N - 1) return 0;
		if(memo[idx] != -1) return memo[idx];
		long ans = Math.min(B + dfs(idx + 1), (X[idx + 1] - X[idx]) * A + dfs(idx + 1));
		return memo[idx] = ans;
	}
	
	public void solve(){
		N = nextInt();
		A = nextInt();
		B = nextInt();
		X = new long[N];
		memo = new long[N];
		for(int i = 0; i < N; i++){
			X[i] = nextInt();
			memo[i] = -1;
		}
		out.println(dfs(0));
	}
	
	private static PrintWriter out;
	public static void main(String[] args){
		out = new PrintWriter(System.out);
		new Main().solve();
		out.flush();
	}
	
	
	
	public static int nextInt(){
		int num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10 + (c - '0');
		}
		return minus ? -num : num;
	}
	
	public static long nextLong(){
		long num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10l + (c - '0');
		}
		return minus ? -num : num;
	}
	public static String next(){
		int c;
		while(!isAlNum(c = read())){}
		StringBuilder build = new StringBuilder();
		build.append((char)c);
		while(isAlNum(c = read())){
			build.append((char)c);
		}
		return build.toString();
	}
	
	
	private static byte[] inputBuffer = new byte[1024];
	private static int bufferLength = 0;
	private static int bufferIndex = 0;
	private static int read(){
		if(bufferLength < 0) throw new RuntimeException();
		if(bufferIndex >= bufferLength){
			try{
				bufferLength = System.in.read(inputBuffer);
				bufferIndex = 0;
			}catch(IOException e){
				throw new RuntimeException(e);
			}
			if(bufferLength <= 0) return (bufferLength = -1);
		}
		return inputBuffer[bufferIndex++];
	}
	
	private static boolean isAlNum(int c){
		return '!' <= c && c <= '~';
	}
}

Measured memory_bytes: 36712
#include <stdio.h>
#define MAX 250

int main(){

    int n;
    int i;
    scanf("%d",&n);
    int H[MAX];

    for( i = 1 ; i <= n ; i++ ){
        scanf("%d",&H[i]);
    }

    for( i = 1 ; i <= n ; i++ ){
        printf("node %d: key = %d, ",i,H[i]);

        if( i != 1 ){
            printf("parent key = %d, ",H[i/2]);
        }

        if( 2*i <= n ){
            printf("left key = %d, ",H[2*i]);
        }

        if( 2*i+1 <= n ){
            printf("right key = %d, ",H[2*i+1]);
        }

        printf("\n");
    }


    return 0;
}

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

using ll = long long;
using namespace std;

int main()
{
    vector<int> A, X;
    while(true){
        int c, d; cin >> c >> d;
        if(!c && !d)break;
        A.push_back(c);
        X.push_back(d);
    }

    for(int i = 0; i < (int)A.size(); i++){
        int n = A[i], x = X[i];
        int ans = 0;
        for(int j = 1; j <= n; j++){
            for(int t = j + 1; t <= n; t++){
                for(int k = t + 1; k <= n; k++){
                    if(j + t + k == x)ans++;
                }
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3136
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>
using namespace std;

int main() {
	int n, m, x;
	cin >> n >> m >> x;
	vector<int>ans(n + 1);
	for (int i = 0; i < m; i++) {
		int b;
		cin >> b;
		ans[b]++;
	}
	int count1 =0, count2 = 0;
	for (int i = x; i <= n; i++) {
		count1 += ans[i];
	}
	for (int i = x; i >= 0; i--) {
		count2 += ans[i];
	}
	cout << min(count1, count2) << endl;
	

}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = input()
    ro = 0
    pa = 0
    score = 0

    for hand in s:
        if hand == "g":
            if pa < ro:
                pa += 1
                score += 1
            else:
                ro += 1
        else:
            if pa < ro:
                pa += 1
            else:
                ro += 1
                score -= 1

    print(score)

if __name__ == '__main__':
    main()


Measured memory_bytes: 70792
[sx,sy,tx,ty]=[int(i) for i in input().split()]
s="R"*(tx-sx)+"U"*(ty-sy)+"L"*(tx-sx)+"D"*(ty-sy)+"L"+"U"*(ty-sy+1)+"R"*(tx-sx+1)+"D"+"R"+"D"*(ty-sy+1)+"L"*(tx-sx+1)+"U"

print(s)

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

int N;
int T[114514], A[114514];
int Q;
int L[114514], R[114514];

int count[114514][8];

int main(void) {
	int i, j;
	if (scanf("%d", &N) != 1) return 1;
	for(i = 1; i <= N; i++) {
		if (scanf("%d%d", &T[i], &A[i]) != 2) return 1;
	}
	T[0] = 0; A[0] = 0;
	T[N + 1] = 1111111111; A[N + 1] = 0;
	if (scanf("%d", &Q) != 1) return 1;
	for (i = 0; i < Q; i++) {
		if (scanf("%d%d", &L[i], &R[i]) != 2) return 1;
	}
	count[0][0] = 1;
	for (i = 1; i <= N + 1; i++) {
		for (j = 0; j <= 7; j++) {
			count[i][j] = count[i - 1][j];
		}
		count[i][A[i]]++;
	}
	for (i = 0; i < Q; i++) {
		int lower = 0, left = N + 1, right = 0, upper = N + 1;
		double yosinagasayuri = 1e+9;
		while (lower + 1 < left) {
			int mid = lower + (left - lower) / 2;
			if (T[mid] < L[i]) lower = mid; else left = mid;
		}
		while (right + 1 < upper) {
			int mid = right + (upper - right)/ 2;
			if (R[i] < T[mid]) upper = mid; else right = mid;
		}
		for (j = 0; j <= 7; j++) {
			int kazu = count[right][j] - count[lower][j];
			yosinagasayuri *= pow(1.0 - j * 0.1, kazu);
		}
		printf("%.15f\n", yosinagasayuri);
	}
	return 0;
}



Measured memory_bytes: 6756
#include <stdio.h>
#include <string.h>

char S[300005];

int east_table[300005];
int west_table[300005];

int ans[300005];

int max(int a,int b){
	if(a>=b){return a;}
	else{return b;}
}

int main() {

	int N;

	scanf("%d",&N);
	scanf("%s",S);

	int len=strlen(S);

	int i,j;

	int cnt=0;

	for(i=0;i<len;i++){
		if(S[i]=='E'){cnt++;}
		else{cnt--;}
		east_table[i]=cnt;
	}

	cnt=0;
	for(i=len-1;i>=0;i--){
		if(S[i]=='E'){cnt++;}
		else{cnt--;}
		west_table[i]=cnt;
	}

	i=1;
	j=-1;
	while(1){
		if(i==1){
			ans[i-1]=max((-len+i-west_table[i])/2,-(-len+i-west_table[i])/2);
		}
		else if(j==len-2){
			ans[j+1]=max((j+1-east_table[j])/2,-(j+1-east_table[j])/2);
			break;
		}
		else{
			ans[i-1]+=max((-len+i-west_table[i])/2,-(-len+i-west_table[i])/2);
			ans[j+1]+=max((j+1-east_table[j])/2,-(j+1-east_table[j])/2);
		}
		i++;
		j++;
	}
	cnt=300005;

	for(i=0;i<len;i++){
		if(cnt>ans[i]){cnt=ans[i];}
	}
	printf("%d\n",cnt);

	return 0;
}

Measured memory_bytes: 3968
n=int(input())
tab = []
for i in range(n):
	a,b = map(int,input().split())
	tab+=[[a,b]]
	
def cle(x):
	return x[1]
tab.sort(key = cle)

ans = "Yes"

temps = 0
for a,b in tab:
	temps+=a
	if temps>b: ans = "No"
	
print(ans)


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

int main ()
{
    long long n;
    cin >> n;
    long long ans = n - 1;
    for (long long i = 1; i <= sqrt(n); i++)
        if (n % i == 0) ans = min (ans, i + (n / i) - 2);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100010];
int ans[100100];
int main(){
	int n;
	cin>>n;
	long long cnt=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		cnt+=a[i];
		a[i]=a[i]*2;
	}
	for(int i=1;i<n;i+=2){
		cnt-=a[i];
	}
	ans[0]=cnt;
	for(int i=1;i<n;i++)ans[i]=a[i-1]-ans[i-1];
	for(int i=0;i<n;i++)cout<<ans[i]<<" ";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 2048
import math
import string
import collections
from collections import Counter


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


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

n = int(input())
if n == 1:
    print(1)
    exit()
for i in range(1, (n+1)):
    if i*i > n:
        print((i-1)*(i-1))
        break


Measured memory_bytes: 3832
n, m = map(int, input().split())
x = list(map(int,input().split()))
x_ = []
x.sort()
count = 0

if n>=m:
    print(count)
else:
    for i in range(1,len(x)):
        x_.append(x[-i]-x[-i-1])
    x_.sort()
    count = sum(x_[0:m-n])
    print(count)

Measured memory_bytes: 13968
#include<stdio.h>

int main(void){
	double r,a,b;
	
	scanf("%lf",&r);
	
	a=r*r*3.141592653589;
	b=2*r*3.141592653589;
	
	printf("%.6lf %.6lf\n",a,b);
	
return 0;
}	


Measured memory_bytes: 2736
//Registration
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <map>
#include <stdio.h>
#include <string.h>
#include <initializer_list>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <set>
using namespace std;
const int INF = 1 << 29;
int main ()
{
    string S;
    string T;
    cin >> S >> T;
    int count = 0;
    for (int i = 0 ; i < S.length(); i++) {
        if (S[i] != T[i]) {
            break;
        }
        count++;
    }
    if (count == S.length()) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=705;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=2000000000;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

int n,m;
bool adj[maxn][maxn];
bool vis[maxn];

vector<int> cpn;
bool tg[maxn];

void dfs(int u){
	vis[u]=1;
	cpn.pb(u);
	REP(v,n) if(!vis[v]&&adj[u][v]){
		tg[v]=!tg[u];
		dfs(v);
	}
}

vector<int> v;
bitset<700> b;
int main()
{
	cin>>n>>m;
	int g=n/2;
	REP(i,n) REP(j,n) if(i!=j) adj[i][j]=1;
	REP(i,m){
		int u,v;
		cin>>u>>v;
		u--;v--;
		adj[u][v]=adj[v][u]=0;
	}
	int x=0,y=0;
	REP(i,n) if(!vis[i]){
		cpn.clear();
		dfs(i);
		int A=0,B=0;
		for(int i:cpn) for(int j:cpn){
			if(tg[i]==tg[j]&&adj[i][j]){
				cout<<-1;
				return 0;
			}
		}
		for(int i:cpn){
			if(tg[i]) A++;
			else B++;
		}
		if(A>B) swap(A,B);
		//cout<<A<<' '<<B<<'\n';
		v.pb(B-A);
		g-=A;
	}
	int cnt=n/2-g;
	b[0]=1;
	for(int i:v) b|=(b<<i);
	while(!b[g]) g--;
	cnt+=g;
	cout<<cnt*(cnt-1)/2+(n-cnt)*(n-cnt-1)/2;
}




Measured memory_bytes: 768
import sys

class Node:
    __slots__ = ['key', 'left', 'right']
    def __init__(self, key):
        self.key = key
        self.left = self.right = None

root = None

def insert(key):
    global root
    x, y = root, None
    while x is not None: x, y = x.left if key < x.key else x.right, x
    if y is None: root = Node(key)
    elif key < y.key: y.left = Node(key)
    else: y.right = Node(key)

def inorder(node):
    return inorder(node.left) + f' {node.key}' + inorder(node.right) if node else ''
def preorder(node):
    return f' {node.key}' + preorder(node.left) + preorder(node.right) if node else ''

input()
for e in sys.stdin:
    if e[0] == 'i': insert(int(e[7:]))
    else: print(inorder(root)); print(preorder(root))


Measured memory_bytes: 63324
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD = 1000000007;
const long long INF = 1LL << 60;

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

int main()
{
    int n; cin >> n;
    //最大化DPのため初期化
    vector<vector<ll> > dp(n+1,vector<ll>(3,-INF));
    vector<vector<ll> > h(n,vector<ll>(3,0));
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin >> h[i][j];
        }
    }

    for(int j=0;j<3;j++)dp[0][j]=0;

    for(int i=1;i<=n;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(j != k)
                    chmax(dp[i][j],dp[i-1][k]+h[i-1][j]);
            }
        }
    }
    cout << max(max(dp[n][0],dp[n][1]),dp[n][2]) << endl;
}
    

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

#define int long long
int dp[210][210][210];

string s[210];

int M[210];
int Dcnt,Ucnt;
int D[210];
int U[210];
int n;

// x: ??????
// a: ???????????¨????????°
// b: ?????£?????????U?????°


// U

int mod = 1000000007;
int dfs(int x,int a,int b){
	if( x == n ){
		return a == 0 && b == 0;
	}
	if( dp[x][a][b] != -1 ) return dp[x][a][b];
	if( s[x] == "-" ) return dfs(x+1,a,b);
	int ans = 0;
	if( s[x] == "U" ){
		//??????????????´???
		ans += dfs(x+1,a+1,b+1);
		if(b) ans += dfs(x+1,a,b) * b;
	}else{
		// D????????£??? U???????????????
		if(a) ans += dfs(x+1,a,b) * a;
		//?????£?????????
		if(a&&b){
			ans += dfs(x+1,a-1,b-1) * a * b;
		}
	}
	ans %= mod;
	return dp[x][a][b] = ans;
}


signed main(){
	memset(dp,-1,sizeof(dp));
	cin >> n;
	int cnt = 0;
	for(int i = 0 ; i < n ; i++){
		cin >> s[i];
	}
	cout << dfs(0,0,0) << endl;
}

Measured memory_bytes: 73580
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n = int(input())
    a = [int(x) for x in input().split()]
    f = []
    t = []
    e = []
    for x in a:
        if x % 2:
            e.append(x)
        elif x % 4 == 0:
            f.append(x)
        else:
            t.append(x)
    if len(e) > len(f):
        if not t and len(e) == len(f) + 1 and len(f) != 0:
            print("Yes")
        else:
            print("No")
    else:
        print("Yes")


t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""



"""


Measured memory_bytes: 20420
#include <iostream>

using namespace std;

int main() {
	int n;

	while (cin >> n, n) {
		int sales[10] = {0};
		for (int i = 0; i < n; ++i) {
			int no; cin >> no;
			++sales[no];
		}

		for (int i = 0; i < 10; ++i)
			if (sales[i]) {
				for (int j = 0; j < sales[i]; ++j)
					cout << "*";
				cout << endl;
			}
			else
				cout << "-" << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

long long calc_sum(long long n, long long b) {
	if (n < b) return n;
	return calc_sum(n / b, b) + n % b;
}

int main()
{
	long long n, s;
	cin >> n >> s;

	// 2≦b≦sqrt(n)
	// sqrt(n)<b≦n
	// b=n+1

	long long ans = -1;
	long long sqrt_n = (long long)sqrt((double)n);
	if (n == s) {
		// b=n+1 先にわかる
		ans = n + 1;
	} else {
		// 2≦b≦sqrt(n)ここまで全探索
		for (long long i = 2; i <= sqrt_n; i++) {
			if (s == calc_sum(n, i)) {
				ans = i;
				break;
			}
		}
		// sqrt(n)<b≦n 二つの和になる
		// s1+s2=s  s1+s2*b=n
		// => s2*(b-1)=n-s  ただし、1≦s2<sqrt(n)かつsqrt(n)≦b≦nかつ0≦s-s2<b
		if (-1 == ans) {
			if (sqrt_n * sqrt_n == n) sqrt_n--;
			long long range = min(sqrt_n, s);
			long long n_s = n - s;
			for (long long i = range; i >= 1; i--) {
				if (n_s % i) continue;//bが整数にならない
				long long ans_tmp = n_s / i + 1;
				if (s - ans_tmp >= i)continue;//s-b<s2不成立
				if (sqrt_n <= ans_tmp && ans_tmp <= n) {
					ans = ans_tmp;
					break;
				}
			}
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

class Bipartite_Matching {
    vector<vector<int>> G;
    vector<int> match, used, alive;
    int t;
public:
    explicit Bipartite_Matching(int n): t(0), G(n), match(n, -1), used(n, 0), alive(n, -1){};

    void connect(int a, int b){
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }

    bool dfs(int x){
        used[x] = t;
        for (auto &&i : G[x]) {
            int w = match[i];
            if(alive[i] == 0) continue;
            if(w == -1 || (used[w] != t && dfs(w))){
                match[x] = i;
                match[i] = x;
                return true;
            }
        }
        return false;
    }

    int matching() {
        int ans = 0;
        for (int i = 0; i < G.size(); ++i) {
            if(alive[i] == 0) continue;
            if(match[i] == -1) {
                ++t;
                ans += dfs(i);
            }
        }
        return ans;
    }
};

int main() {
    int n, m;
    while(cin >> n >> m, n|m) {
        vector<int> v(n), u(m);
        for (auto &&i : v) scanf("%d", &i);
        for (auto &&j : u) scanf("%d", &j);
        Bipartite_Matching G(n+m);
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                if(__gcd(v[i], u[j]) > 1){
                    G.connect(i, n+j);
                }
            }
        }
        cout << G.matching() << "\n";
    }
    return 0;
}


Measured memory_bytes: 4512
a, b, c, d = list(map(int, input().split()))
if d <= a:
    print(0)
    exit()
if a <= c <= b:
    if b >= d:
        print(d - c)
        exit()
    else:
        print(b - c)
        exit()
elif c < a:
    if b >= d:
        print(d - a)
        exit()
    else:
        print(b - a)
        exit()
else:
    print(0)


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

int main() {
  int N, K, Q;
  cin >> N >> K >> Q;
  auto ps = vector<int>(N, 0);
  int offset = 0;
  int a;
  for(int i = 0; i < Q; ++i) {
    cin >> a; // A start with 1
    if(offset + ps[a - 1] + K > 0) {
      ps[a - 1]++;
    }
    offset--;
  }

  for(auto p : ps) {
    if(offset + p + K > 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
int dig[10][10];int n;
void ass(int x)
{
	string s=to_string(x);
	int l=s.length();
	dig[s[0]-'0'][s[l-1]-'0']++;
}
int32_t main()
{
	n=in();
	for(int i=1;i<=n;i++)
	{
		ass(i);
	}
	
	int ans=0;
	for(int i=1;i<=9;i++)
	{
		for(int j=0;j<=9;j++)
		ans+=(dig[i][j]*dig[j][i]);
	}
	cout<<ans;
	
}

Measured memory_bytes: 3800
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m=0;cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++)cin>>a.at(i);
  if(n==1)cout<<a.at(0)<<endl;
  else{
  sort(a.begin(),a.end());
  for(int i=n-2;i>=0;i-=2)a.at(i)=0-a.at(i);
  for(int i=0;i<n;i++)m+=a.at(i);
  cout<<m<<endl;
  }
}

Measured memory_bytes: 256
S=[0]*13
H=[0]*13
C=[0]*13
D=[0]*13
n=int(input())
for _ in range(n):
  a,b=input().split()
  if a=="S":S[int(b)-1]=1
  if a=="H":H[int(b)-1]=1
  if a=="C":C[int(b)-1]=1
  if a=="D":D[int(b)-1]=1
for i in range(13):
  if S[i]==0:print("S",i+1)
for i in range(13):
  if H[i]==0:print("H",i+1)
for i in range(13):
  if C[i]==0:print("C",i+1)
for i in range(13):
  if D[i]==0:print("D",i+1)


Measured memory_bytes: 5612
N=int(input())
if N==1:
    print(1)
    exit()
l=[]
for i in range(1,int(N**0.5)+1):
    if N%i==0:
        l.append(i)
#print(l)
a=l[-1]
b=N//a
s=max(a,b)
print(len(str(s)))

Measured memory_bytes: 9460
def main():
    n, m = map(int, input().split())

    ab = [list(map(int, input().split())) for _ in range(n)]
    ab.sort()
    ans = 0

    for i, j in ab:
        if m < j:
            ans += i*m
            break
        m -= j
        ans += i*j
        

    print(ans)

main()

Measured memory_bytes: 27884
#!/usr/bin/env python3
import sys


def solve(L: int, R: int, d: int):
    count = 0
    for i in range(L, R+1):
        if i % d == 0:
            count += 1
    print(count)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    L = int(next(tokens))  # type: int
    R = int(next(tokens))  # type: int
    d = int(next(tokens))  # type: int
    solve(L, R, d)

if __name__ == '__main__':
    main()


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

bool is_square(int n)
{
    for (int i = 0; i <= n; i++)
    {
        if (i * i == n)
        {
            return true;
        }
    }
    return false;
}
double distance(double x1, double y1, double x2, double y2)
{
    return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

int main()
{
    vector<ll>a(3);
    cin>>a[0]>>a[1]>>a[2];
    sort(a.begin(), a.end());
    if(a[0]%2==0||a[1]%2==0||a[2]%2==0){
        cout << 0 << endl;
    }
    else{
        cout << a[0] * a[1] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}




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

int a;
string s;
cin >> a >> s;

if(a >= 3200) cout << s << endl;
else puts("red");

return 0;
}

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

using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
using PII = std::pair<int, int>;
using PLL = std::pair<ll, ll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define allpt(v) (v).begin(), (v).end()
#define allpt_r(v) (v).rbegin(), (v).rend()


const int mod = 1e9 + 7;
const string wsp = " ";
const string tb = "\t";
const string rt = "\n";

template <typename T>
void show1dvec(vector<T> v)
{
    if (v.size() == 0)
        return;
    int n = v.size() - 1;
    rep(i, n) cout << v[i] << wsp;
    cout << v[n] << rt;
    return;
}

template <typename T>
void show2dvec(vector<vector<T>> v)
{
    int n = v.size();
    rep(i, n) show1dvec(v[i]);
}

bool in_field(int h, int w, int y, int x)
{
    return 0 <= y && y < h && 0 <= x && x < w;
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    
    double n, m, d, ans;
    cin >> n >> m >> d;

    if (d == 0) ans =  1 / n * (m - 1);
    else
    {
        ans = 2 * (n - d) / (n * n) * (m - 1);
    }
    printf("%.10f\n" , ans);

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from itertools import accumulate
from bisect import bisect_left

N, M = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]

A2 = sorted(A, reverse=True)
A = sorted(A)


# 必要となる左右合計の下限値 X を求める

def f1(m):
    cnt = 0
    for a1 in A2:
        tmp = bisect_left(A, m - a1)
        if tmp == N: break
        cnt += N - tmp

    return cnt >= M


l = 0
r = A2[0] * 2 + 10

while r - l > 1:
    m = (l + r) // 2
    if f1(m):
        l = m
    else:
        r = m

X = l
# print('X', X)

acc = list(accumulate(A2))  # 累積和

total_cnt = 0
ans = 0
for a in A2:
    # a を左手としたときの右手の最小値
    min_right = X - a
    if min_right > A[-1]:
        continue

    # 右手の値から出す手数を算出
    idx = bisect_left(A, min_right)
    cnt = N - idx

    # それらの全合計を加算
    ans += a * cnt + acc[cnt - 1]
    total_cnt += cnt

    # if total_cnt >= M:
    #     break
# total_cnt が大きすぎる場合は, その分だけ Xを減算. X は必要な両手合計の最小値なので, 減算すべきは必ず X*出しすぎた分 となる
if total_cnt > M:
    ans -= X * (total_cnt - M)
print(ans)


Measured memory_bytes: 61548
n = int(input())
w = []
for _ in range(n) :
    w += [input()]
if len(w) == len(set(w)) :
    for i in range(n - 1) :
        if w[i][-1] != w[i + 1][0] :
            print("No")
            break
        else :
            continue
    else :
        print("Yes")
else :
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
#define fi first
#define se second
#define show(x) cout << #x << " is " << x << "\n";
const ll inf = 9e18;
const ll mod = 1e9 + 7;
const ld pi = 3.141592653589793238462643383279502884;

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y, ll M = inf){
	if(y<=0) return 1;
    ll ans = 1;
    x %= M;
    while(y){
        if(y&1)
            ans = (x * ans) % M;

        x = (x * x) % M;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2, mod);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

//------------------------------------------------------------------------------------------

//const ll N = 1e5 + 1;
//vector<ll> adj[N];
//bool visited[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    //cout<<fixed<<setprecision(10);


	ll n;
	cin>>n;
	ld a[n];
	ll gf = 1000000000000000000;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a, a+n);
	if(a[0]==0) cout<<0;
	else{
		ld ans=0;
		ll ans1 = 1;
		for(int i=0;i<n;i++){
			ans+=log10(a[i]);
			ans1*=a[i];
		}
		//cout<<ans1;
		if(ans>18 || ans1>gf) cout<<-1;
		else cout<<ans1;
	}
    return 0;
}


Measured memory_bytes: 5376
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

const ll num[] = { 2, 5, 5, 4, 5, 6, 3, 7, 6 };

int main() {
    ll N, M;
    cin >> N >> M;
    vector<bool> can_use(9, false);
    for (ll i = 0; i < M; i++) {
        ll A;
        cin >> A;
        can_use[A - 1] = true;
    }

    vector<vector<string>> dp(10, vector<string>(N + 1));
    for (ll i = 8; i >= 0; i--) {
        for (ll j = 0; j <= N; j++) {
            //追加なし
            if (dp[i + 1][j].size() > dp[i][j].size() || (dp[i + 1][j].size() == dp[i][j].size() && dp[i + 1][j] > dp[i][j])) {
                dp[i][j] = dp[i + 1][j];
            }

            if (!can_use[i] || j - num[i] < 0) {
                continue;
            }

            //一個前から追加
            if (j - num[i] == 0 || dp[i + 1][j - num[i]].size()) {
                string tmp1 = dp[i + 1][j - num[i]] + to_string(i + 1);
                if (tmp1.size() > dp[i][j].size() || (tmp1.size() == dp[i][j].size() && tmp1 > dp[i][j])) {
                    dp[i][j] = tmp1;
                }
            }

            //同じ数字内で追加
            if (j - num[i] == 0 || dp[i][j - num[i]].size()) {
                string tmp2 = dp[i][j - num[i]] + to_string(i + 1);
                if (tmp2.size() > dp[i][j].size() || (tmp2.size() == dp[i][j].size() && tmp2 > dp[i][j])) {
                    dp[i][j] = tmp2;
                }
            }
        }
    }

    cout << dp[0][N] << endl;
}

Measured memory_bytes: 69248
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    string s;
    cin>>s;
    int q;
    cin>>q;
    int hanten=0;
    string c="",d="";
    rep(_,q){
        int i; cin>>i;
        if(i==1) hanten++;
        else{
            int x;string y;
            cin>>x>>y;
            if((hanten+x)%2==1){
                // string t=y+s;
                // s=t;
                c+=y;
            }
            else{
                // string t=s+y;
                // s=t;
                d+=y;
            }
        }
        // cout<<s<<endl;
    }

    if(hanten%2==1){
        reverse(all(s));
        reverse(all(d));
        cout<<d<<s<<c<<endl;
    }
    else{
        reverse(all(c));
        cout<<c<<s<<d<<endl;
    }
    
}

Measured memory_bytes: 1040
#include <iostream>
#include <vector>
#include <queue>

int dp[100010];
std::vector<int> graph[100010];
int deg[100010];

int main(){
    int n, m;
    std::cin >> n >> m;
    for(int i = 0; i < m; i++){
        int x, y;
        std::cin >> x >> y;
        graph[--x].push_back(--y);
        deg[y]++;
    }
    std::queue<int> queue;
    for(int i = 0; i < n; i++){
        if(deg[i] == 0) queue.push(i);
    }
    while(!queue.empty()){
        int vertex = queue.front(); queue.pop();
        for(int sub_vertex : graph[vertex]){
            deg[sub_vertex]--;
            if(deg[sub_vertex] == 0){
                queue.push(sub_vertex);
                dp[sub_vertex] = std::max(dp[sub_vertex], dp[vertex]+1);
            }
        }
    }
    int res = 0;
    for(int i = 0; i < n; i++){
        res = std::max(res, dp[i]);
    }
    std::cout << res << std::endl;
}


Measured memory_bytes: 6528
import itertools
As = list(map(int,input().split()))
perms = list(itertools.permutations(As))
min_val = 300
for i in perms:
  vals = abs(i[1] - i[0]) + abs(i[2] - i[1])
  if min_val > vals:
    min_val = vals
print(min_val)

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<string, int> P;

int main() {
  string word;
  int page;
  vector<P> list;
  while (cin >> word >> page) {
    list.push_back(P(word, page));
  }
  sort(list.begin(), list.end());
  word = "";
  for (vector<P>::iterator it=list.begin(); it!=list.end(); it++) {
    if (word != it->first) {
      if (!word.empty()) cout << endl;
      word = it->first;
      cout << word << endl;
      cout << it->second;
    } else {
      cout << " " << it->second;
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <string.h>
 
#define rep(i,n)    for(ll i=0;i<n;i++)
#define repu(i,k,n) for(ll i=k;i<=n;i++)
#define repd(i,k,n) for(ll i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl "\n"
#define INF (ll)ll_MAX
 
typedef long long ll;
typedef long double ld;
typedef std::pair<ll, ll> pii;
typedef std::vector< ll > vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, ll > > vpp;
 
const ll N = 3*1e5 +5 ;
const long long MOD = 1000000007;
const long long MOD2 = 998244353;
const long long inf = 1e18;
 
using namespace std;

// ll g[200000], ig[200000];



bool ok;

void dfs1(ll u, bool vis[], ll tot[], ll p[],ll h[], vll v[]){
    if(vis[u]==1) return;
    vis[u] = 1;

    ll sum = 0;

    sum += p[u];

    ll sorr = 0;

    for(ll i=1;i<v[u].size();i++){
        // cout<<'a';
        dfs1(v[u][i],vis,tot,p,h,v);
        sum+= tot[v[u][i]];
        sorr = sorr +  tot[v[u][i]] - h[v[u][i]];
    }

    // cout<<sum;

    tot[u] = sum;

    // if(tot[u]-h[u]>sorr){
    //     cout<<tot[u]-h[u]<<' '<<sorr<<'\n';
    //     ok = false;
    //     // cout<<"NOOOOO";
    // }

    return;

}

void dfs2(ll u, bool vis[], ll tot[], ll p[],ll h[], vll v[]){
    if(vis[u]==1) return;
    vis[u] = 1;

    // ll sum = 0;

    // sum += p[u];

    ll sorr = 0;

    for(ll i=1;i<v[u].size();i++){
        // cout<<'a';
        dfs2(v[u][i],vis,tot,p,h,v);
        // sum+= tot[v[u][i]];
        sorr = sorr +  tot[v[u][i]] - h[v[u][i]];
    }

    // cout<<sum;

    // tot[u] = sum;

    // cout<<sorr<<endl;

    if(tot[u]-h[u]>sorr + 2*p[u]){
        // cout<<u<<' '<<tot[u]-h[u]<<' '<<sorr<<'\n';
        ok = false;
        // cout<<"NOOOOO";
    }

    if((tot[u]-h[u])%2==1){
        ok = false;
    }

    if(h[u]>(tot[u]) or h[u]<(-tot[u])){
        ok = false;
    }

    return;

}





void solve()
{	
   
    int k;
    cin>>k;

    if(k%7==0) k/=7;
    if(k==1){
        cout<<1;
        return;
    }

    int ctr = 0;

    if(k%2==0 or k%5==0){
        cout<<-1;
        return;
    }

    ll md = 0;
    ctr++;
    md = 1;

    while(md!=0){
        ctr++;
        md = (10*md+1)%k;
    }

    cout<<ctr;



}

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


    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    ll t = 1;
    // cin>>t;
    ll ctr=0;
    while(t--)
    {   
        ctr++;
        // cout<<"Case #"<<ctr<<": ";
        solve();    
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
 
}

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

int gc(int a, int b) {
  while(max(a, b) % min(a, b) != 0) {
    if (a >= b) {
      a = a % b;
    }
    else {
      b = b % a;
    }
  }
  return min(a, b);
}

int gcd(int a, int b, int c) {
  return gc(a, gc(b, c));
}

int main() {
  int K;
  cin >> K;
  long ans = 0;
  for (int i = 1; i <= K; i++) {
    for (int j = i; j <= K; j++) {
      for (int k = j; k <= K; k++) {
        if (i == j && j == k) {
          ans += i;
        }
        else if (i == j) {
          ans += 3 * gc(i, k);
        }
        else if (j == k) {
          ans += 3 * gc(i, k);
        }
        else if (k == i) {
          ans += 3 * gc(i, j);
        }
        else {
          ans += 6 * gcd(i, j, k);
        }
      }
    }
  }
  cout << ans;
}

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


const int MOD=1e9+7;



int main(){
  int n;
  cin >> n;
  vector<ll> z(n),w(n);
  for(int i=0;i<n;++i){
    ll x,y;
    cin >> x >> y;
    z[i]=x+y;
    w[i]=x-y;
  }
  ll zma,zmi,wma,wmi;
  zma=z[0];
  zmi=z[0];
  wma=w[0];
  wmi=w[0];
  for(int i=0;i<n;++i){
    zma=max(zma,z[i]);
    zmi=min(zmi,z[i]);
    wma=max(wma,w[i]);
    wmi=min(wmi,w[i]);
  }
  ll ans=max(zma-zmi,wma-wmi);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6404
#include<bits/stdc++.h>
using namespace std;
long long int solve(long long int wt[],long long int val[],long long int n,long long int W,vector<vector<long long int>>&dp)
{
  if(n==0 || W==0)
    return 0;
  if(dp[n][W]!=-1)
    return dp[n][W];
  if(W<wt[n-1])
    return dp[n][W]=solve(wt,val,n-1,W,dp);
  else return dp[n][W]=max(solve(wt,val,n-1,W-wt[n-1],dp)+val[n-1],solve(wt,val,n-1,W,dp));
}
int main()
{
  long long int n,W;
  cin>>n>>W;
  long long int wt[n],val[n];
  for(long long int i=0;i<n;i++)
  {
    cin>>wt[i]>>val[i];
  }
  long long int ans;
  vector<long long int>temp(W+1,-1);
  vector<vector<long long int>>dp(n+1,temp);
  ans=solve(wt,val,n,W,dp);
  cout<<ans;
}


Measured memory_bytes: 80256