akhauriyash/Code-Regression huggingface dataset:
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	S := sc.nextRuneSlice()
	a := 0
	z := 0
	aF := false
	for i, r := range S {
		if r == 'A' && !aF {
			a = i
			aF = true
		}
		if r == 'Z' {
			z = i
		}
	}

	fmt.Fprintln(wtr, z-a+1)
	wtr.Flush()
}


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

int main() {
	// your code goes here
	int n;
	cin>>n;
	bool c=0;
	for(int i=1;i<=9;++i){
	    if(!(n%i)){
	        if(n/i<=9){
	            c=1;
	            break;
	        }
	    }
	}
	if(c) cout<<"Yes";
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int func(int a){	
	if (a == 1) {
		return 1;
	}
	else {
		return func(a - 1)+a;
	}
}

int main(void) {
	int num, ans;
	scanf("%d", &num);
	ans = func(num);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int MOD=1000000007;
using namespace std;
int main(){
    string s;
    cin>>s;
    int n=s.size();
    
    if(n==2&&s[0]==s[1]){
        cout<<"1 2"<<endl;
        return 0;
    }
    
    rep(i,0,n-2){
        if(s[i]==s[i+1]||s[i+1]==s[i+2]||s[i+2]==s[i]){
            cout<<i+1<<" "<<i+3<<endl;
            return 0;
        }
    }
    
    cout<<"-1 -1"<<endl;
}


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

int main()
{
  int n;
  cin >> n;
  vector<int> c(n-1);
  vector<int> s(n-1);
  vector<int> f(n-1);
  int i, j;
  int ans = 0;
  for(i = 0; i < n-1; i++)
  {
	cin >> c.at(i) >> s.at(i) >> f.at(i);
  }
  for(i = 0; i < n; i++)
  {
    ans = 0;
	for(j = i; j < n-1; j++)
    {
      if(ans < s.at(j))
      {
       ans = s.at(j)+c.at(j);
      }
      else if(ans % f.at(j) != 0)
      {
		ans += f.at(j)-ans%f.at(j)+c.at(j);
      }
      else
      {
		ans += c.at(j);
      }
    }
    cout << ans << endl;
  }
}

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


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

struct edge {int to; ll cost; };

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

 
int main(){
  string s;
  cin >> s;
  for(int i=0; i<s.length(); i++){
    cout << "x";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3516
def main():
    H, W, K = map(int, input().split())
    c=[input() for i in range(H)]
    c=list(map(list,c))
    ans = 0
    #print(c)
    number = 0
    for i in range(H):
        for j in range(W):
            if c[i][j] == '#':
                number += 1
    #print(number)
    for i in range(2**H):
        for j in range(2**W):
            count = 0
            for l in range(H):
                for m in range(W):
                    #print(l,m)
                    if not i>>l&1 and not j>>m&1 and c[l][m] == "#":
                        #print(i,j,l,m)
                        count+=1

            if count==K:
                #print(i,j)
                ans+=1
    print(ans)

main()


Measured memory_bytes: 9212
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define N 200001
#define ll long long
#define int ll 
#define pi pair<int , int>
#define pip pair<pair ,int>
#define mp make_pair 
#define f first
#define s second
#define mod 998244353
ll Mod(ll x, ll y, int p) 
{ll res = 1; x = x % p;
while (y > 0) 
{if(y & 1) res = (res*x) % p; 
y = y>>1;x = (x*x) % p; 
}return res; 
}
int* getlps(string pattern){
 int len = pattern.length();
 int * lps = new int[len];
 lps[0] = 0;
 int i = 1 , j = 0;
 while(i < len){
  if(pattern[i] == pattern[j]){
	  lps[i] = j+1;
   i++;
   j++;
  }
  else{
		if(j != 0){
		 j = lps[j-1];
		}
		else{
		 lps[i] = 0;
		 i++;
		}
  }
 }
 return lps;
}
class Triplet{
 public:
 int x ;
 int y ;
 int gcd;
};
Triplet extendedEuclid(int a , int b){
 if(b == 0){Triplet ans; ans.gcd = a;ans.x = 1;ans.y = 0;return ans;}
 Triplet smallAns = extendedEuclid(b , a%b);
 Triplet ans;
 ans.gcd = smallAns.gcd;
 ans.x = smallAns.y;
 ans.y = smallAns.x - (a/b)*smallAns.y;
 return ans;
}
int mmInverse(int a , int m){
 Triplet ans = extendedEuclid(a , m);
 return ans.x;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
int arr[n];
int ok = -1;
for(int i = 0 ; i < n;i++){
 cin>>arr[i];
 if(arr[i]%2 == 0 && (arr[i]%3 != 0) && (arr[i]%5 != 0) && ok == -1){
  cout<<"DENIED"<<endl;
  ok = 1;
 }
}
if(ok == -1){
  cout<<"APPROVED"<<endl;
}
}


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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

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(){

    ll n;
    cin >> n;
    vector<ll> a(n);
    for(ll i = 0; i < n; i++){
        cin >> a[i];
    }
    ll sum = 0;
    for(ll i = 1; i < n; i++){
        if(a[i-1] > a[i]){
            ll t = a[i-1] - a[i];
            a[i] += t;
            sum += t;
        }
    }
    cout << sum << endl;

    return 0;
}


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

int main() {
  string s;
  cin >> s;
  int p = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'B') p = max(p-1, 0);
    else s[p++] = s[i];
  }
  cout << s.substr(0, p) << endl;
}

Measured memory_bytes: 256
import math

N = int(input())
S = []
for i in range(N):
  S.append(''.join(sorted(input())))

from collections import Counter
Sc = Counter(S)

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

cnt = 0
for i in Sc.values():
  if i >= 2:
    cnt += com(i,2)
  
print (cnt)

Measured memory_bytes: 19780
main = do
    str <- getLine
    let (n:x:_) = map read $ words str
    if ((n,x) == (0,0)) then
        return ()
    else do
        print $ length [1 | a <- [1..(n-2)], b <- [(a+1)..(n-1)], c <- [(b+1)..(min (n) (x-a-b))], a+b+c==x]
        main

Measured memory_bytes: 4184
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

vector<bool> eratosthenesBool(lli N, vll& result) {

	vector<bool> v(N + 1);

	for (int i = 2; i <= N; i++) {
		if (v[i] == false) {
			result.push_back(i);
			for (int j = 2 * i; j <= N; j += i) {
				v[j] = true;
			}
		}
	}

	return v;
}

void eratosthenes(lli N, vll& result) {

	vector<bool> v(N + 1);

	for (int i = 2; i <= N; i++) {
		if (v[i] == false) {
			result.push_back(i);
			for (int j = 2 * i; j <= N; j += i) {
				v[j] = true;
			}
		}
	}

	return;
}

int main(void) {

	lli A, B;
	cin >> A >> B;

	lli x, y;

	lli GCD = extgcd(A, B, x, y);

	vll eratos;

	eratosthenes(sqrt(GCD),(eratos));

	std::map<lli, bool> m;
	
	for (int i = 0; i < eratos.size(); i++) {
		if (GCD % eratos[i] == 0) {
			GCD /= eratos[i];//これが素数なら+1
			m[eratos[i]] = true;
			i--;
		}
	}

	if (GCD != 1) {
		COUT(m.size() + 2);
	}
	else {
		COUT(m.size() + 1);
	}

	return 0;
}

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

int main(){
  int n;  cin >> n;
  vector<int> p(n), q(n), a(n);
  for(int i=0; i<n; i++)  cin >> p[i];
  for(int i=0; i<n; i++){
    cin >> q[i];
    a[i] = i + 1;
  }

  map<vector<int>, int> mp;
  do{
    mp[a] = mp.size();
  }while(next_permutation(a.begin(), a.end()));

  cout << abs(mp[p] - mp[q]) << endl;

  return 0;
}
  
    


Measured memory_bytes: 8624
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int t = sc.nextInt();
    for(int i = 0; i < t; i++) {
      long a = sc.nextLong();
      long b = sc.nextLong();
      long c = sc.nextLong();
      long d = sc.nextLong();
      String ans = "Yes";
      if(b > a) {
        ans = "No";
      } else {
        if(b > d) {
          ans = "No";
        } else {
          if(c >= b) {
            ans = "Yes";
          } else {
            long g = gcd(b, d);
            long a1 = (a % g);
            long e = b - g + a1;
            if(e > c) ans = "No"; 
          }
        }
      }

      System.out.println(ans);
    }
  }

  public static long gcd(long x, long y) {
    if(y == 0) return x;
    return gcd(y, (x % y));
  }
}

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

using namespace std;

int main() {
  long long n, k;
  cin >> n >> k;
  vector<pair<int, int>> P(n);
  for (int i=0; i<n; ++i) cin >> P.at(i).first >> P.at(i).second;
  
  sort(P.begin(), P.end());
  long long cur = 0;
  for (auto p : P) {
    cur += p.second;
    if (cur >= k) {
      cout << p.first << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 1024
// file name: 求两个集合的交集
// Written by: by_sknight
// Date: 2019/6/12

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

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

	set<int> A, B, result;
	set<int>::iterator it;
	int n, m, x;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x;
		A.insert(x);
	}

	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> x;
		B.insert(x);
	}

	for (it = A.begin(); it != A.end(); it++) {
		if (B.find(*it) != B.end()) {
			result.insert(*it);
		}
	}
	
	for (it = result.begin(); it != result.end(); it++) {
		cout << *it << endl;
	}

	return 0;
}


Measured memory_bytes: 23808
import Control.Applicative
import Control.Monad
import Data.Bool (bool)

main :: IO ()
main = do
  [a, b] <- f
  unless (a == 0 && b == 0) $ do
    putStrLn $ solve a b
    main
  where
    f = map read <$> words <$> getLine

solve :: Int -> Int -> String
solve a b = bool "a" "b" $ f a < f b
  where
    f x = let fs = fcs x in 2 * (head fs) - sum fs

fcs x = f [] x 2
  where
    f fs x d
      | x < d ^ 2 = if x == 1 then fs else x : fs
      | x `mod` d == 0 = f (d : fs) (g x d) (d + 1)
      | otherwise = f fs x (d + 1)
    g x d
      | x `mod` d == 0 = g (x `div` d) d
      | otherwise = x



Measured memory_bytes: 4200
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <time.h>
#define MAXT 10
#define MOD 1000000007
using namespace std;

void swap(int& a, int& b)
{
	int tmp;
	tmp = a;
	a = b;
	b = tmp;
}

int main()
{
	string test;
	cin >> test;
	int size = test.size();
	vector<int> num(size, 1);
	int left, right, div;
	left = 0;
	right = 1;
	div = 0;

	while (right < size) {
		while (test[right] == 'R') {
			right++;
		}
		div = right - 1;
		right++;
		while (test[right] == 'L' && right < size) {
			right++;
		}
		right--;
		/*dp.emplace_back(tmp);
		if (tmp.right - tmp.left > 1) {
			dfs.emplace_back(tmp);
		}*/
		int r = right;
		int l = left;
		int count = 0;
		/*printf("[%d,%d,%d]\n", l, div, r);
		for (int j = left; j <= right; j++) {
			printf("%d ", num[j]);
		}
		printf("\n");*/

		while (r - l > 1) {
			count++;
			//printf("swap(%d,%d) ", num[div], num[div + 1]);
			swap(num[div], num[div + 1]);
			if (l != div) {
				num[div] += num[div - 1];
				num[l] = 0;
				l++;
			}
			if (r != div + 1) {
				num[div + 1] += num[div + 2];
				num[r] = 0;
				r--;
			}
	/*		for (int j = left; j <= right; j++) {
				printf("%d ", num[j]);
			}
			printf("\n");*/
			
		}
		if (count % 2)swap(num[div], num[div + 1]);
		left = ++right;
	}



	for (int i = 0; i < size; i++) {
		printf("%d ", num[i]);
	}


	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
  int n, k;
  ll o = 0;
  cin >> n >> k;
  vector<int> h(n);
  for(int i = 0; i < n; i++)
    cin >> h.at(i);
  if(k >= n) {
    cout << 0 << endl;
    return 0;
  }
  sort(h.begin(), h.end(), greater<int>());
  for(int i = k; i < n; i++)
    o += h.at(i);
  cout << o << endl;
}

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

int main()
{
    int A, B, C;
    scanf("%d %d %d", &A, &B, &C);

    if (A == B && A == C && B == C)
    {
        printf("No");
    }
    else if ((A == B || A == C || B == C))
    {
        printf("Yes");
    } else
    {
        printf("No");
    }
    

    

    return 0;
}

Measured memory_bytes: 1700
def fast_pow(x, n, MOD):
    res = 1
    while n:
        if n & 1:
            res = res * x % MOD
        x = x * x % MOD
        n >>= 1
    return res

def prepare(n, MOD):
 
    # 1! - n! の計算
    f = 1
    factorials = [1]  # 0!の分
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    # n!^-1 の計算
    inv = pow(f, MOD - 2, MOD)
    # n!^-1 - 1!^-1 の計算
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
     
    return factorials, invs

MOD = 998244353
fact, fact_inv = prepare(3*10**5, MOD)

n, m, k = map(int,input().split())

dp = [0] * (n+1)
ans = 0
for i in range(k+1):
    color = fast_pow(m-1, n-1-i, MOD)
    order = fact[n-1] * fact_inv[i] % MOD * fact_inv[n-1-i] % MOD
    ans += m * color % MOD * order % MOD
    ans %= MOD    

print(ans)

Measured memory_bytes: 34136
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    while(a > 0 && c > 0) {
        c -= b;
        if(c <= 0) {
            cout << "Yes" << endl;
            return 0;
        }
        a -= d;
        if(a <= 0) {
            cout << "No" << endl;
            return 0; 
        }
    }
    return 0;
}



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

typedef long long LL;

#define FOR(i, a, b) for (int i = (a), i##_END_ = (b); i <= i##_END_; i++)
#define DNF(i, a, b) for (int i = (a), i##_END_ = (b); i >= i##_END_; i--)

template <typename Tp> void in(Tp &x) {
	char ch = getchar(), f = 1; x = 0;
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') ch = getchar(), f = -1;
	while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	x *= f;
}

template <typename Tp> void out(Tp x) {
	if (x > 9) out(x / 10);
	putchar(x % 10 + '0');
	return;
}

template <typename Tp> Tp Max(const Tp &x, const Tp &y) {return x > y ? x : y;}
template <typename Tp> Tp Min(const Tp &x, const Tp &y) {return x < y ? x : y;}
template <typename Tp> bool chkmax(Tp &x, Tp y) {return x >= y ? 0 : (x=y, 1);}
template <typename Tp> bool chkmin(Tp &x, Tp y) {return x <= y ? 0 : (x=y, 1);}

const int MAXN = 262145;

using std::pair;

int n;
pair<int, int>max[19][MAXN];

int ans[MAXN];

pair<int, int> operator + (pair<int, int>x, pair<int, int>y)
{
	if (x.first < y.first) std::swap(x, y);
	int mx = x.first;
	int sm;
	sm = Max(y.first, x.second);
	return std::make_pair(mx, sm);
}

int main()
{
	in(n);

	FOR(i, 0, (1 << n) - 1) {
		in(max[0][i].first); max[0][i].second = -0x3f3f3f3f;
	}

	FOR(j, 1, 18) {
		FOR(i, 0, (1 << n) - 1) {
			max[j][i] = max[j - 1][i];
			if (i >> (j - 1) & 1)
				max[j][i] = max[j][i] + max[j][i ^ (1 << (j - 1))];
		}
	}

	FOR(i, 0, (1 << n) - 1) ans[i] = max[18][i].first + max[18][i].second;
	FOR(i, 1, (1 << n) - 1) chkmax(ans[i], ans[i - 1]);

	FOR(i, 1, (1 << n) - 1) printf("%d\n", ans[i]);
	
	return 0;
}


Measured memory_bytes: 43008
#include <math.h>
#include <string.h>
#include <stdio.h>
int main(void)
{
    char s[8]={0},t[4]={0};
    char *u;
    int a,b;
    scanf("%s %s",s,t);
    u = strcat(s,t);
    a = atoi(u);
    b = sqrt((double)a);
    if(a == b*b)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
# ABC097D - Equals (ARC097D)
import sys
input = sys.stdin.readline


class UnionFind:
    def __init__(self, N):  # construct a Union-Find tree (1-idx)
        self.parent = [i for i in range(N + 1)]
        self.rank = [0] * (N + 1)

    def find(self, x):  # find the group (root) of a vertex
        if self.parent[x] == x:
            return x
        self.parent[x] = self.find(self.parent[x])
        return self.parent[x]

    def is_same(self, x, y):  # check two vertices are in the same group
        return self.find(x) == self.find(y)

    def unite(self, x, y):  # unite two groups
        x, y = self.find(x), self.find(y)
        if x == y:  # the same group
            return
        # unite a small one to a bigger one to balance trees
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1


def main():
    # check i and Pi are connected components or not
    N, M = tuple(map(int, input().split()))
    P = tuple(map(int, input().split()))
    E = tuple(tuple(map(int, input().split())) for _ in range(M))
    U = UnionFind(N)  # construct a Union-Find tree (1-idx)
    for v, u in E:  # connected components are in the same group
        U.unite(v, u)
    ans = sum(U.is_same(i, p) for i, p in enumerate(P, 1))
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 25184
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7,INF=1e18;
#define lld unsigned long long
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
vector<pll> a;
ll n,m;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    // cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        int n=s.size(),flag=0;
        for(int i=0;i<(n+1)/2;i++)
        if(s[i]!=s[n-2-i])
        flag=1;
        vector<pii> edges;
        if(s[0]=='0'||flag||s[n-1]=='1')
        {
            cout<<"-1\n";
            continue;
        }
        int root=1,j=2;
        for(int i=0;i<(n+1)/2;i++)
        if(s[i]=='1')
        {
            edges.push_back({root,j});
            root=j;
            j++;
        }
        else
        {
            edges.push_back({root,j});
            j++;
        }
        for(int i=(n+3)/2;i<n;i++)
        {
            edges.push_back({root,j++});
        }
        for(int i=0;i<n-1;i++)
        cout<<edges[i].first<<" "<<edges[i].second<<"\n";
    }
    return 0;
}

Measured memory_bytes: 4420
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var n=arr.shift();
var str=arr.shift();
str=str.replace(/ /g,"");
while(str.length!=1){
   str=str.replace(/../,function(s){
      if(s=="TT")return "T";
      if(s=="TF")return "F";
      if(s=="FT")return "T";
      if(s=="FF")return "T";
   });
}
console.log(str);


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

using namespace std;
#define rep(i, n) for(int i = 0 ; i < (int)(n) ; i++)
typedef long long ll;
typedef long double Double;

#ifndef INPUTS_DIR
#define INPUTS_DIR "./"
#endif


void solve(vector<ll> A) {
    sort(A.begin(), A.end());
    cout << A.back() - A.front() << endl;
}


void main_(istream &cin) {
    vector<ll> A(3 - 1 + 1);
    for (int i = 0; i <= 3 - 1; i++) {
        cin >> A[i];
    }
    solve(A);
}

int main() {
#ifdef INTELLIJ
    ifstream ifs(string(INPUTS_DIR) + "in_1.txt");
    if (ifs.is_open()) {
        main_(ifs);
        ifs.close();
    } else {
        cerr << "Error: no input." << endl;
    }
#else
    ios::sync_with_stdio(false);
    cin.tie(0);
    main_(cin);
#endif
}





Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
  int a, b; cin >> a >> b;
  if (a*b%2==0) {
    cout << "Even" << endl; 
  } else {
    cout << "Odd" << endl; 
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[25];
int b[25];
int main(){
	int n;
	cin>>n;
	int cnt=0;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)cin>>b[i];
	for(int i=0;i<n;i++){
		if(a[i]>b[i])cnt+=a[i]-b[i];
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
import math
N = int(input().rstrip())

def f(a,b):
    a = str(a)
    b = str(b)
    return len(a) if len(a) > len(b) else len(b)

n = int(math.sqrt(N)) 
ans = len(str(N))
for a in range(1,n+1):
    if N % a == 0:
        b = N // a
        res = f(a,b)
        if res < ans:
            ans = res
print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;

class Program {
    static int Main(string[] args) {
        List<int> list = new List<int>();

        while (true) {
            int v = int.Parse(Console.ReadLine());
            if (v == 0) { break; }

            list.Add(v);
        }

        for (int i = 0; i < list.Count; i++) {
            Console.WriteLine(string.Format("Case {0}: {1}", i + 1, list[i]));
        }

        return 0;
    }
}

Measured memory_bytes: 9408
#include <bits/stdc++.h> 
using namespace std; 
  
// Return the maximum volume. 
double maxvolume(double s) 
{ 
    // finding length 
    double length = s / 3; 
  
    s -= length; 
  
    // finding breadth 
    double breadth = s / 2; 
  
    // finding height 
    double height = s - breadth; 
  
    return length * breadth * height; 
} 
  
// Driven Program 
int main() 
{ 
    double s ;
    cin>>s;
   // cout << maxvolume(s) << endl;
    cout << fixed << setprecision(6) << maxvolume(s)<<endl;
    return 0; 
} 

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


int n;
string s;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    map <string,int> freq;
    for (int i=0; i<n; i++){
        cin>>s;
        if (!freq[s]) freq[s]=1;
        else freq[s]+=1;
    }
    int max=0;
    for (auto it = freq.begin(); it!=freq.end(); ++it){
        if (it->second>max) max=it->second;
    }
    
    for (auto it = freq.begin(); it!=freq.end(); ++it){
        if (it->second==max) cout<<it->first<<"\n";
    }
    
    return 0;
}

Measured memory_bytes: 23808
#include<bits/stdc++.h>
const long long N = 2e5 + 5;
const long long inf = 1e9;
using namespace std;

vector <long long> adj[N];
long long n, m, d[N], p[N], cnt = 1, c;
long long num[N], dp[N][2];
long long pos[N];

void dfs(long long u, long long numm){
    num[u] = 0;
    for (long long i = 0; i < adj[u].size(); i++){
        long long v = adj[u][i];
        dfs(v, numm);
        num[u] += num[v];
    }
    if (adj[u].size() == 0){
        num[u] = 1;
        dp[u][0] = ((pos[u] && !(pos[u] < numm)) ? inf : 0); dp[u][1] = ((pos[u] && !(pos[u] >= numm)) ? inf : 1);
    }
    else{
        for (long long i = 0; i < 8; i++){
            bool x = (i & 1), y = (i&2), z = (i&4);
            if (__builtin_popcount(i) > 1) dp[u][1] = min(dp[u][1], dp[adj[u][0]][x] + dp[adj[u][1]][y] + dp[adj[u][2]][z]);
            else dp[u][0] = min(dp[u][0], dp[adj[u][0]][x] + dp[adj[u][1]][y] + dp[adj[u][2]][z]);
        }
    }
    if (dp[u][0] != inf && num[u] - dp[u][0] > cnt) dp[u][0] = num[u] - cnt;
}

bool check(long long num){
    cnt = 0;
    for (long long i = 1; i <= n; i++) if (d[i] < num) cnt++;
    for (int i = 1; i <= c; i++) dp[i][0] = inf, dp[i][1] = inf;
    dfs(c, num);
    return (dp[c][1] <= n-cnt);
}

long long bsearch(){
    long long l = 0, r = 1e9;
    while (l != r){
        long long mid = (l + r + 1) / 2;
        if (check(mid)) l = mid;
        else r = mid-1;
    }
    return l;
}

int main(){
    ios_base::sync_with_stdio(false); cin .tie(0); cout.tie(0);
    cin >> n >> m;
    c = n+1;
    for (long long i = 1; i <= m; i++) {
        cin >> d[i] >> p[i];
        pos[p[i]] = d[i];
    }
    for (long long i = m+1; i <= n; i++) cin >> d[i];
    while (cnt+1 != c){
        adj[c].push_back(cnt); cnt++;
        adj[c].push_back(cnt); cnt++;
        adj[c].push_back(cnt); cnt++;
        c++;
    }
    c--;
    cout << bsearch() << "\n";
}

Measured memory_bytes: 15912
from scipy.optimize import fmin
N = int(input())

INF = 10 ** 18
fixed_x, R, L = [], [], []
fixed_y, U, D = [], [], []

def update(fixed, li, x, y):
  li.append(x)
  fixed.append(y)
  
for _ in range(N):
  x,y,d = input().split()
  x,y = int(x), int(y)
  if d in ['L', 'R']:
    update(fixed_y, eval(d), x, y)
  else:
    update(fixed_x, eval(d), y, x)

for li in ['fixed_x', 'L', 'R', 'fixed_y', 'D', 'U']:
  exec('{0} = [min({0} + [INF]), max({0} + [-INF])]'.format(li))

def calc_x(t, fixed, dec, inc):
  left = INF
  right = -INF
  for li, speed in [(fixed, 0), (dec, -1), (inc, 1)]:
    left = min(left, li[0] + speed * t)
    right = max(right, li[1] + speed * t)
  return right - left

def area(t):
  if t < 0:
    return INF
  return calc_x(t, fixed_x, L, R) * calc_x(t, fixed_y, D, U)

xopt = fmin(area, x0 = 10**8, ftol = 10**-9, disp = False)
answer = area(xopt[0])
print(answer)


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

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

typedef long long ll;
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    ll N, M, X; cin >> N >> M >> X;
    vector<ll> cost;
    vector<vector<ll>> v;
    REP(i, N) {
        ll c; cin >> c;
        cost.push_back(c);
        vector<ll> tmp_v;
        REP(j, M) {
            ll tmp; cin >> tmp;
            tmp_v.push_back(tmp);
        }
        v.push_back(tmp_v);
    }
    ll total_cost = INT64_MAX;
    REP(S,(1<<N)) {// 買った本の集合S
        map<ll,ll> cur_mp;
        ll cur_cost = 0;
        REP(i, N){  
            if (S>>i&1) {// iを買った場合
                cur_cost += cost[i];
                REP(j, M) {
                    cur_mp[j] += v[i][j];
                }
            }
        }
        bool judge = true;
        REP(j, M){
            // cerr << cur_mp[j] << ":" << X << endl;
            if (cur_mp[j] < X) judge = false;
        }
        if(judge) {
            total_cost = min(total_cost, cur_cost);
            // cerr << "###success:" << total_cost << endl;
        }
        // cerr << "fail###:" << total_cost << endl;
    }
    if (total_cost == INT64_MAX) {
        cout << -1 << endl;
    }
    else {
        cout << total_cost << endl;
    }
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n;
  cin >> n;
  vi32 A(n);
  cin >> A;
  i64 ans = 0;
  rep(i, n) {
    int a = A[i];
    int c = a / 2;
    ans += c;
    a -= c * 2;
    if (i < n - 1) {
      if (a && A[i + 1]) {
        ans++;
        A[i + 1]--;
      }
    }
  }
  cout << ans << endl;
}


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

#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair

using namespace std;

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

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  int n, d;
  cin >> n >> d;
  d = 2 * d + 1;
  cout << (n + d - 1) / d << '\n';
  return (0);
}


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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


struct init{ init(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); }; }aaaaaaa;


ll mod = 1e9 + 7;

ll powmod(ll b){
  ll r = 1;
  ll c = mod-2;
  for (; c>0; c>>=1, b=b*b%mod){
    if (c&1)  r = r*b%mod;
  }
  return r;
}

ll powdiv(ll a, ll b){
  return a * powmod(b) % mod;
}

int main(){
  ll n, a, b, c;
  cin >> n >> a >> b >> c;

  ll ab = a+b;
  a += powdiv(c * a, ab);
  b += powdiv(c * b, ab);

  ll comp = 1;
  ll p = 0;
  
  ll t = 1;
  rep(i, n-1) t *= 100, t %= mod;
  
  ll an = 1;
  rep(i, n) an *= a, an %= mod;
  ll bn = 1;
  rep(i, n) bn *= b, bn %= mod;

  ll ai = 1;
  ll bi = 1;


  rep(i, n){
    if(0 < i){
      comp *= n-1+i, comp %= mod;
      comp = powdiv(comp, i), comp %= mod;
    }
    ll s = ((((n+i) * t)%mod) * comp)%mod;
    p += (((an * bi)%mod) * s)%mod;
    p %= mod;
    p += (((bn * ai)%mod) * s)%mod;
    p %= mod;
    ai *= a, ai %= mod;
    bi *= b, bi %= mod;
    t = powdiv(t, 100);
  }
  
  ll res = p;
  res = powdiv(res, 100-c);
  rep(i, 2*n-2) res = powdiv(res, 100);

  cout << res << endl;



  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long dp[101][100001];
int main(){
    int n,w;
    cin>>n>>w;
    long long W[n+1],V[n+1];
    int vsize = 0;
    for(int i=1;i<=n;i++){
        cin>>W[i]>>V[i];
        vsize += V[i];
    }

    for(int i=0;i<=vsize;i++)
        dp[0][i] = INT_MAX;

    for(int i=0; i <= n; i++)
        dp[i][0] = 0;

    for(int i=1;i<=n;i++){
        for(int j=1;j<=vsize;j++){
            if(V[i]<=j)
                dp[i][j] = min(dp[i-1][j],dp[i-1][j-V[i]]+W[i]);
            else
                dp[i][j] = dp[i-1][j];
        }
    }

    for(int i=vsize;i>=0;i--){
        if(dp[n][i]<=w){
            cout<<i<<'\n';
            break;
        }
    }
}

Measured memory_bytes: 79232
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(x) x.begin(),x.end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

ll x,k,d;
ll solve(){
   ll ans=0;
   if(x==d){
       if(k%2)return 0;
       else return x;
   }
   if(abs(x)/d>=k)return abs(x)-k*d;
   ll x2,k2;
    x2=x-x/d*d;
    k2=k-abs(x)/d;
    if(k2%2==1){
        if(x2<0)ans=x2+d;
        else ans=x2-d;
    }else{
        ans=x2;
    }

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

    cin>>x>>k>>d;
    cout<<solve()<<endl;
    return 0;
}       

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = int64_t;
using P = pair<ll,ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    ll n,p;
    cin >> n >> p;
    vi a(n);
    rep(i,n) cin >> a.at(i);
    bool odd = false;
    rep(i,n) if(a.at(i)%2==1) odd = true;
    ll res = 1;
    if(odd){
        rep(i,n-1) res *=2;
        cout << res << endl;
    }else{
        if(p){
            cout << 0 << endl;
        }else{
            rep(i,n) res *=2;
            cout << res << endl;
        }
    }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n, T;
    cin >> n >> T;
    vec t(n);
    rep(i, n) cin >> t[i];

    lint res = 0;
    int cur = 0;

    rep(i, n) {
        if (i < n-1) res += min(T, t[i+1] - t[i]);
        else res += T;
        cur = t[i];
    }
    cout << res << endl;
    return 0;
}

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

vector<int> d, f;
int g[111][111];
int n;
int cnt;

void dfs(int now){
  bool flag = false;
  if(d[now] != 0) flag = true;
  else{
    cnt++;
    d[now] = cnt;
  }
  for(int i = 1; i <= n; i++){
    if(g[now-1][i-1] == 1 && d[i] == 0){
      dfs(i);
    }
  }
  cnt++;
  if(flag) cnt--;
  if(f[now] == 0) f[now] = cnt;
}

int main(){

  memset(g,0,sizeof(g));
  d.resize(111);
  f.resize(111);
  cin >> n;

  for(int i = 0; i < n; i++){
    int a, b;
    cin >> a >> b;
    for(int i = 0; i < b; i++){
      int c;
      cin >> c;
      g[a-1][c-1] = 1;
    }
  }

  for(int i = 0; i < n; i++){
    dfs(i+1);
  }

  for(int i = 0; i < n; i++){
    cout << i+1 << " " << d[i+1] << " " << f[i+1] << endl;
  }





}

Measured memory_bytes: 1260
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int a,b,c; cin >> a >> b >> c;
    cout << ((c > b and b > a) ? "Yes":"No") << endl;
}





Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
const int maxn = 300010;
const int INF = INT_MAX/2;

string S,T;

int32_t main() {
	cin >> S >> T;
	
	int ans = 0;
	for (int i =0;i<S.length();i++) {
		if (S[i] != T[i]) ans++;
	}
	cout << ans;
}









Measured memory_bytes: 3868
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e10;
const ll MOD = 100000000;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
const ll MAX = 100;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll ans = 1,x;
    cin >> x;
    rep(i,2,x){
        ll k = i;
        if (i*i > x) continue;
        while(k*i <= x){
            k *= i;
        }
        chmax(ans,k);
    }
    PRINT(ans);
}


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

int main(){
	int N,K;
    cin >> N >> K;
     
    if(N >= K){
    	if(N % K == 0)
      		cout << 0 << endl;
    
    	else
      	cout << 1 << endl;
    }
  
    else if(N < K){
        cout << 1 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i < (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000; // 十分大きな値

int main(){
    int inp,n=0;
    string s;
    cin >> n;
    inp = n;
    int ans = 0;
    while(n > 0){
        ans += (n % 10);
        n/=10;
    }
    if((inp % ans) == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

}
    



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fr(x,i,n) for(int x = i; x < n; ++x)
#define fb(x,i,n) for(int x = i; x >= n; --x)
#define pr pair<int,int>
#define ll long long int
//const int mod=1e9+7;
const ll inf=1LL<<32;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k;
    cin>>n>>k;
    n%=k;
    cout<<min(n,k-n);
}


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

using namespace std;
typedef long long ll;

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

  ll n,m;cin>>n>>m;
  ll res=0;
  if(m<2) cout<<0<<endl;
  else if(2*n>m) cout<<m/2<<endl;
  else{
      res+=n;
      m-=2*n;
      res+=(m/4);
      cout<<res<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 998244353LL
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair

#define FOR(i, a, b) for (ll i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (ll i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 105
int n;
pii co[MN];
const double PI = acos((double)-1);

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

    cin >> n;
    FOR(i, 1, n) cin >> co[i].f >> co[i].s;
    FOR(i, 1, n){
        vector<double> hmm;
        FOR(j, 1, n) if(i != j){
            hmm.pb(atan2(co[j].s-co[i].s, co[j].f-co[i].f));
        }
        sort(hmm.begin(), hmm.end());
        double mx = 0;
        F0R(j, n-2){
            double val = hmm[j+1]-hmm[j];
            //if(val < 0) val += acos(-1);
            mx = max(mx, val);
        }
        double val = hmm[0]+PI*2-hmm[n-2];
        mx = max(mx, val);
        double dblhmm = max(0.0, mx-PI);
        cout << fixed << setprecision(8) << dblhmm/(2*PI) << "\n";
        /*for(auto u : hmm) cout << u << " ";
        cout << "\n";*/
    }
    
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <string>
#include <math.h>
#include <map>
#include <numeric>
#include <stack>
#include <queue>
#include <functional>
#include <stdio.h>
#define ll long long
#define pl pair<ll,ll>
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vvvl vector<vector<vector<ll> > >
#define vd vector<double>
#define vvd vector<vector<double> >
#define vvvd vector<vector<vector<double> > >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define vvvb vector<vector<vector<bool> > >
#define rep(i,a) for(ll i = 0;i<a;++i)
#define rep1(i,a) for(ll i = 1;i<a;++i)
#define rrep(i,a) for(ll i = a;i>=0;--i)
#define mod 1000000007
#define inf 10010010010
using namespace std;

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

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

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

	for(int n; cin >> n, n;) {
		vector<int> dp(n + 1, 0);
		dp[0] = 1;
		for(int i = 0; i < dp.size(); ++i)
			for(int j = i + 1; j < dp.size() && j < i + 4; ++j)
				dp[j] += dp[i];

		int day = dp[n] / 10 + (dp[n] % 10 ? 1 : 0);
		int year = day / 365 + (day % 365 ? 1 : 0);
		cout << year << endl;
	}


	return EXIT_SUCCESS;
}

Measured memory_bytes: 1196
use std::io::Read;

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

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let mut n: usize = iterator.next().unwrap().parse().unwrap();
    let k: usize = iterator.next().unwrap().parse().unwrap();

    let mut count = 0;
    while n > 0 {
        n /= k;
        count += 1;
    }

    return format!("{}", count);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#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 isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

int n;

void solve(){
	int r[1010],w[1010],sumr = 0,sumw = 0;
	vector<P> vec;
	for(int i = 0;i < n;i++){
		cin >> r[i] >> w[i];
		vec.emplace_back(r[i],w[i]);
		sumr += r[i];
		sumw += w[i];
	}
	sort(all(vec));
	for(int i = 0;i < n;i++){
		r[i] = vec[i].first;
		w[i] = vec[i].second;
	}
	if(sumr >= r[n - 1] * 2){
		cout << sumr + sumw << endl;
		return;
	}
	bool dp[1010][1010] = {};
	dp[0][0] = true;
	for(int i = 0;i < n - 1;i++){
		for(int j = 0;j <= 1000;j++){
			dp[i + 1][j] = dp[i][j] | ((j >= w[i]) ? dp[i][j - w[i]] : false);
		}
	}
	int ma = 0;
	for(int i = 0;i <= 2 * r[n - 1] - sumr;i++){
		if(dp[n - 1][i]) chmax(ma,i);
	}
	cout << 2 * r[n - 1] + sumw - ma << endl;
}

signed main(){
	while(cin >> n,n) solve();
}


Measured memory_bytes: 4156
#include <stdio.h>

int main(void) {

  int n, k, i;
  long sum;

  scanf("%d%d", &n, &k);

  sum = k;

  for (i = 0; i < n - 1; i++)
   sum *= (k - 1);

  printf("%ld\n", sum);

  return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;


int main(){
  
  int d,t,s;
  
  cin >> d >> t >> s;
  
  double time = (double) d / s;

  if ( time <= t ) cout << "Yes" <<endl;
  else cout << "No" <<endl;
  
  
  
 return 0; 
  
}


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

int main() {
	string s,t;
	cin >> s >> t;
	vector<vector<ll>> al(26);
	for(int i=0;i<s.size();i++) {
		al[s[i]-'a'].push_back(i);
	}

	ll now = -1;
	ll loop = 0;
	for(int i=0;i<t.size();i++) {
		ll id = t[i]-'a';
		if(al[id].size()==0){
			cout << -1 << endl;
			return 0;
		}
		ll last = al[id].size()-1;
		if(al[id][last] <= now) {
			loop++;
			now = al[id][0];
		}else {
			auto itr = lower_bound(al[id].begin(), al[id].end(), now+1);
			now = *itr;
		}
	}
	ll ans = loop*s.size()+now+1;
	cout << ans << endl;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  int n,x;
  cin >> n >> x;
  if(n==2){
    if(x!=2){
      cout << "No" << endl;
      return 0;
    }
    cout << "Yes" << endl << 1 << endl << 2 << endl << 3 << endl;
    return 0;
  }
  if(x==1||x==2*n-1){
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  if(x==2*n-2){
    for(int i=1;i<=n-2;i++){
      cout << i << endl;
    }
    cout << x-1 << endl << x << endl << x+1 << endl << x-2 << endl;
    for(int i=n+2;i<2*n-1;i++){
      cout << i-3 << endl;
    }
    return 0;
  }
  list<int> a;
  for(int i=1;i<=x-2;i++) a.push_back(i);
  for(int i=x+3;i<=2*n-1;i++) a.push_back(i);
  auto itr=a.begin();
  for(int i=1;i<=n-2;i++,itr++){
    cout << (*itr) << endl;
  }
  cout << x+1 << endl << x << endl << x-1 << endl << x+2 << endl;
  for(int i=n+2;i<2*n-1;i++,itr++){
    cout << (*itr) << endl;
  }
  return 0;
}


Measured memory_bytes: 7808