akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;
int main()
{
	boost;
	int a, b;
	cin >> a >> b;
	cout << a * b;
}


Measured memory_bytes: 3688
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

#define N_MAX 110

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	int N; char str[3][N_MAX];
	scanf("%d", &N);
	for (int i = 0; i < 3; i++){
		scanf("%s", str[i]);
	}
	
	int cnt = 0;
	for (int i = 0; i < N; i++){
		if (str[0][i] != str[1][i] && str[1][i] != str[2][i] && str[2][i] != str[0][i]){
			cnt += 2;
		}
		else if (str[0][i] == str[1][i] && str[1][i] == str[2][i] && str[2][i] == str[0][i]){

		}
		else{
			cnt++;
		}
	}

	printf("%d", cnt);

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

Measured memory_bytes: 128
<?php
fscanf(STDIN,"%d %d",$N,$K);
$V = fgets(STDIN);
$arrayV = explode(" ",$V);
$max = 0;
$minusMax = count(array_filter($arrayV,"minusCount"));

if($K === 1){
  echo max($arrayV[0],$arrayV[$N-1]);
}else{
  for($i=0; $i<=$K && $i <= $N; $i++){
    if($i !== 0){
      if($arrayV[$i-1] <= 0){
        continue;
      }
    }
    for($j=0; $j<=$K-$i && $j<=$N-$i; $j++){
      if($j !== 0){
        if($arrayV[$N-$j] <= 0){
          continue;
        }
      }
      for($m=0; $m<=$K-$i-$j && $m<$i+$j && $m<=$minusMax; $m++){
        $value = calculate($i,$j,$m,$arrayV,$N);
        if($value > $max){
          $max = $value;
        }
      }
    }
  }
  echo $max;
}

function calculate($left,$right,$delete,$array,$N){
  $arrayResult = array();
  for($i=0;$i<$left;$i++){
    $arrayResult[] = $array[$i];
  }
  for($i=0;$i<$right;$i++){
    $arrayResult[] = $array[$N-1-$i];
  }
  for($i=0;$i<$delete;$i++){
    $mins = array_keys($arrayResult, min($arrayResult));
    unset($arrayResult[$mins[0]]);
  }
  return array_sum($arrayResult);
}

function minusCount($value){
  return $value <= 0;
}


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

int main(){
    int n,m,x,y;
    cin >> n >> m >> x >> y;
    int n_max,m_min;
    n_max = -101;
    m_min = 101;
    int in;
    for(int i=0;i<n;i++){
        cin >> in;
        n_max = max(n_max,in);
    }
    for(int i=0;i<m;i++){
        cin >> in;
        m_min = min(m_min,in);
    }
    string ans = "War";
    for(int i=n_max+1;i<=m_min;i++){
        if(i>x && i<=y){
            ans = "No War";
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
r = []
for i in range(n):
    s, p = input().split()
    r.append((i + 1, s, int(p)))
r.sort(key=lambda x: x[2], reverse=True)
r.sort(key=lambda x: x[1])
for i in range(n):
    print(r[i][0])

Measured memory_bytes: 9072
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define inf 0x3f3f3f3f
signed main(){	
	int n;
	cin>>n;
	int minx=(n+1); 
	
	for(int i=2;i<=sqrt(n);i++){
		if(n%i==0){
			minx=min(minx,(i+n/i));
		}
	}
	cout<<minx-2;
	return 0;
} 
/*

*/

Measured memory_bytes: 256
n = int(input())
s = input()

chg = [0]*n

cnt = 0
for i in range(1, n):  # 左側から
    if s[i-1] == 'W':
        cnt += 1
    chg[i] += cnt

cnt = 0
for i in range(1, n):  # 右側から
    if s[-i] == 'E':
        cnt += 1
    chg[-1-i] += cnt
    
print(min(chg))

Measured memory_bytes: 15264
E[26][10001],N[26],S[26],D[26];C(a,i,b){for(S[a]=0,i=N[a];i--;)S[b=E[a][i]]&&C(b);}char s[33];main(n,a,b,ng){for(;scanf("%d",&n)*n;puts(ng?"NG":"OK")){for(ng=0;n--;D[a]++,D[b]--)scanf("%s",s),S[a=*s-97]=S[b=s[strlen(s)-1]-97]=1,E[a][N[a]++]=b;C(a);for(a=26;a--;D[a]=S[a]=N[a]=0)ng|=D[a]|S[a];}}

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

using namespace std;
typedef long long ll;

int main() {
  ll N; cin >> N;
  vector<ll> V(N);
  for (ll j=0; j < N; ++j) cin >> V[j];
  vector<ll> C(N);
  for (ll j=0; j < N; ++j) cin >> C[j];
  ll ans = 0;
  for (ll j=0; j < N; ++j) {
    if (V[j] > C[j]) {
      ans += V[j] - C[j];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
from itertools import product

n = int(input())

memo = [[] for _ in range(n)]

for i in range(n):
    for _ in range(int(input())):
        x, y = map(int, input().split())
        memo[i].append((x-1, y))

ans = 0
for a in product([0,1], repeat=n):
    REAL = True
    for i in range(n):
        if a[i] == 1:
            for x, y in memo[i]:
                if a[x] != y:
                    REAL = False
                    break
        if REAL == False:
            break

    if REAL:
        ans = max(ans, sum(a))

print(ans)

Measured memory_bytes: 68528
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class T>
inline bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>
inline bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N,R; cin >> N >> R;
    cout << max((int)0,10-N)*100+R << endl;
}

Measured memory_bytes: 256
# 入力 : Nセットの3個の数字
W, H, N = map(int, input().split())
list = [0 for i in range(0,N)]
for i in range(0,N) :
    x, y, a = map(int, input().split())
    list[i] = (x,y,a)

x_low = 0
x_high = W
y_low = 0
y_high = H

for i in range(0,N) :
    if list[i][2] == 1 :
        x_low = max(x_low, list[i][0])
    elif list[i][2] == 2 :
        x_high = min(x_high, list[i][0])
    elif list[i][2] == 3 :
        y_low = max(y_low, list[i][1])
    else :
        y_high = min(y_high, list[i][1])

area = (x_high - x_low) * (y_high - y_low)

if x_high < x_low or y_high < y_low :
    print(0)
else :
    print(area)


Measured memory_bytes: 3064
#include<stdio.h>
int main(){
int a,b,c,temp;
scanf("%d%d%d",&a,&b,&c);
if(a>b){
temp = b;
b = a;
a = temp;
}
if(b>c){
temp = c;
c = b;
b = temp;
}
if(a>b){
temp = b;
b = a;
a = temp;
}
printf("%d %d %d\n",a,b,c);
return 0;
}

Measured memory_bytes: 596
fn main() {
    use std::io::Read;
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    
    let n: usize = iter.next().unwrap().parse::<usize>().unwrap();
    let mut a: Vec<u64> = (&mut iter).take(n).map(|x| x.parse().unwrap()).collect();
    let mut b: Vec<u64> = (&mut iter).take(n).map(|x| x.parse().unwrap()).collect();
    let mut c: Vec<u64> = (&mut iter).take(n).map(|x| x.parse().unwrap()).collect();
    a.sort();
    b.sort();
    c.sort();

    let mut b_to_a = vec![0u64;n];
    let mut b_to_c = vec![0u64;n];
    for i in 0..n {
        b_to_a[i] = a.lower_bound(&b[i]) as u64;
        b_to_c[i] = n as u64 - c.upper_bound(&b[i]) as u64;
    }

    let mut ret = 0u64;
    for i in 0..n {
        ret += b_to_a[i] * b_to_c[i];
    }
    println!("{}", ret);
}

use std::cmp::Ordering;
#[doc = " https://qiita.com/ganariya/items/33f1326154b85db465c3"]
#[doc = " https://qiita.com/hatoo@github/items/fa14ad36a1b568d14f3e"]
pub trait BinarySearch<T> {
    fn lower_bound(&self, x: &T) -> usize;
    fn upper_bound(&self, x: &T) -> usize;
}
impl<T: Ord> BinarySearch<T> for [T] {
    fn lower_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();
        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less => {
                    low = mid + 1;
                }
                Ordering::Equal | Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
    fn upper_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();
        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less | Ordering::Equal => {
                    low = mid + 1;
                }
                Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
}

Measured memory_bytes: 14588
S = str(raw_input())

n = len(S)
table = []

SS = []
for s in S:
    SS.append(int(s))

for i in range(n):
    x = [0] * n
    for j in range(i):
        x[j] = 2 ** (i-1)
    x[i] = 2 ** i
    table.append(x)

ret = 0
for i in range(n):
    p = n - 1 - i
    for j in range(i+1):
        if table[i][j] > 0:
            ret += SS[j] * (10**p) * table[i][j]

print ret


Measured memory_bytes: 2568
def mod_pow(x, n, mod)
  ret = 1
  while n > 0
    ret = ret * x % mod if n & 1 > 0
    x = x * x % mod
    n >>= 1
  end
  ret
end

MOD = 1_000_000_007
N = gets.to_i
As = gets.split.map(&:to_i).sort

unless N.times.all? { |i| As[i] == i + ((N + i).even? ? 1 : 0) }
  puts 0
  exit
end

puts mod_pow(2, N / 2, MOD)


Measured memory_bytes: 9712
import sys

sys.setrecursionlimit(10**6)

class rmq_segment_tree:
    inf=(1<<31)-1
    n,n_=0,0
    array=[]
    def __init__(self,n_):
        n=1
        while n<n_: n*=2
        self.n=n
        self.n_=n_
        self.array=[self.inf]*(2*n-1)

    def update(self,i,x):
        i+=self.n-1
        self.array[i]=x
        #print(len(self.array))
        while i>0:
            i=(i-1)//2
            self.array[i]=min(self.array[i*2+1],self.array[i*2+2])
    
    def rec(self,a,b,k,left,right):
        if right<=a or b<=left: return self.inf
        if a<=left and right<=b: return self.array[k]
        mid=(left+right)//2
        value_left=self.rec(a,b,k*2+1,left,mid)
        value_right=self.rec(a,b,k*2+2,mid,right)
        return min(value_left,value_right)

    def f(self,a,b):
        return self.rec(a,b,0,0,self.n)
n,q=map(int,input().split())
tree=rmq_segment_tree(n)

for _ in range(q):
    c,x,y=map(int,input().split())
    if c==1:
        print(tree.f(x,y+1))
    else:
        tree.update(x,y)


Measured memory_bytes: 8700
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
  vector<int> a;
  int b;
  cin >> b;
  a.push_back(b);
  cin >> b;
  a.push_back(b);
  cin >> b;
  a.push_back(b);
	if (a[2] == a[0] && a[0] == a[1]) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int n,x,t;
int main(){
	scanf("%d%d%d",&n,&x,&t);
	printf("%d\n",t*(n/x+(n%x?1:0)));
	return 0;
}

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

long double volu(long double s) 
{ 
    
    long double l = s / 3; 
  
    s = s- l; 
  
     
    long double b = s / 2; 
  
     
    long double h = s - b; 
  
    return l * b * h; 
} 

int main(){

long double n;
 
cin>>n;
cout<<fixed;
cout<<volu(n);
    
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  int A,B;
  cin >> A >> B;
  string S;
  cin >> S;
  string eal = "Yes";
  for(int i = 0; S.size() > i; i++){
    if(S[i] == '-' && i != A){
      eal = "No";
    }
    if(S[i] != '-' && i == A){
      eal = "No";
    }
  }
  cout << eal << endl;
}

Measured memory_bytes: 256
s = input()
s += "0"


num = len(s)

ans = []

buf = []
bs = ""


for index, x in enumerate(s):
  if x == "R":
    bs += x
  elif x == "L":
    bs += x
    if s[index+1] == "R" or s[index+1] == "0":
      kiso = len(bs) // 2
      if len(bs) % 2 == 0:
        r = kiso
        l = kiso
      else:
        blist = [bs.count("R"), bs.count("L")]
        a = kiso
        b = kiso
        if max(blist) % 2 == 1:
          b += 1
        else:
          a += 1
        if bs.count("R") > bs.count("L"):
          r = b
          l = a
        else:
          r = a
          l = b
      hoge = [0 for i in range(len(bs))]
      hoge[bs.count("R")-1] = r
      hoge[bs.count("R")] = l
      ans.extend(hoge)
      bs = ""

      
  
print(" ".join(map(str, ans)))

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

typedef long long ll;

int main()
{
	ll n,m=1000;
	cin>>n;
	ll arr[n];
	for (ll i=0; i<n; i++)
	{
		cin>>arr[i];
	}
	ll s;
	for (ll i=0; i<n-1; i++)
	{
		if (arr[i]>=arr[i+1])
		  continue;
		else
		{
			s=m/arr[i];
			m=m%arr[i];
			m=m+s*arr[i+1];
		}
	}
	cout<<m<<endl;
	return 0;
}

Measured memory_bytes: 3636
// Copyright (C) 2018 Skqliao. All rights served.
#include <bits/stdc++.h>

#define rep(i, l, r) for (__typeof(l) i = (l), _##i##_ = (r); i < _##i##_; ++i)
#define rof(i, l, r) for (__typeof(l) i = (l) - 1, _##i##_ = (r); i >= _##i##_; --i)
#define irep(i, x) for (__typeof(x.begin()) i = x.begin(); i != x.end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) static_cast<int>((x).size())
typedef long long ll;
typedef std::pair<int, int> pii;
template<typename T> inline bool chkMin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkMax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

ll N, A, B;

int main() {
	scanf("%lld%lld%lld", &N, &A, &B);
	if(A * B < N || A + B > N + 1) {
		puts("-1");
	} else {
		while(N > 0) {
			ll x = std::min(A, N - B + 1);
			rep(i, N - x + 1, N + 1) {
				printf("%lld ", i);
			}
			--B;
			N -= x;
		}
 	}
	return 0;
}

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

char s[100005];

int main()
{
  scanf("%s",s);
  int n = strlen(s), ans=1;
  int l=2,r=n;
  while(r>=l) {
    queue<int> q;
    int c = (l+r)/2, rr = n-c;
    bool ok = true;
    int m = n + (n&1);
    while(m--) q.push(c);
    for(int i=0;i<=rr;i++) {
      if((q.size()&1) ^ (s[i]=='1'))
        q.push(i+c);
    }
    for(int i=rr+1;i<n;i++) {
      if((q.size()&1) ^ (s[i] == '1')) {
        if(!q.empty() && q.front()<=i) {
          q.pop();
        } else {
          ok = false;
          break;
        }
      }
    }
    if(ok) {
      ans = c;
      l = c+1;
    } else {
      r = c-1;
    }
  }
  printf("%d\n",ans);
}


Measured memory_bytes: 920
#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll


int t, n, m, k, a[300010], q, l, r;



int32_t main(){
INIT
cin>>n;

cout<<( (1000-n%1000) )%1000;



return 0;
}


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

namespace E
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            int N = int.Parse(line);
            line = Console.ReadLine();
            string[] strs = line.Split(' ');
            int[] A = new int[N];
            int XOR = 0;
            for(int i = 0; i < N; i++)
            {
                A[i] = int.Parse(strs[i]);
                XOR = XOR ^ A[i];
            }
            for(int i = 0; i < N; i++)
            {
                if (i > 0)
                {
                    Console.Write(" ");
                }
                Console.Write(XOR ^ A[i]);
            }
            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 55820
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long LL;
typedef unsigned int uint;
typedef pair<int,int> pii;
//-------------------------------------------------------------------LYYY↓
namespace LYYY{
	int rd()
	{
		int s=0;char c=getchar();int f=1;
		while(c<48||c>57)
		{
			if(c==45) f=-1;
			c=getchar();
		}
		while(c>=48&&c<=57) s=(s<<3)+(s<<1)+(c^48),c=getchar();
		return s*f;
	}
	LL rdl()
	{
		LL s=0;char c=getchar();int f=1;
		while(c<48||c>57)
		{
			if(c==45) f=-1;
			c=getchar();
		}
		while(c>=48&&c<=57) s=(s<<3)+(s<<1)+(c^48),c=getchar();
		return s*f;
	}
	void wt(int x)
	{
		if(x>=10) wt(x/10);
		putchar(x%10+48);
	}
	void WT(int x)
	{
		if(x<0) x=-x,putchar(45);
		wt(x);
	}
	void wtl(LL x)
	{
		if(x>=10) wtl(x/10);
		putchar(x%10+48);
	}
	void WTL(LL x)
	{
		if(x<0) x=-x,putchar(45);
		wtl(x);
	}
}using namespace LYYY;
//-------------------------------------------------------------------bianliang↓
//-------------------------------------------------------------------hanshu↓
//-------------------------------------------------------------------main()↓
int main()
{
	int N=rd(),tot=0,a,ans=0;
	for(int i=1;i<=N;++i) a=rd(),ans+=tot*a,tot+=a;
	WT(ans);
}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(ll i = (m); i < (n); ++i)

#define INF 1e9

int main(){
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  REP(i, N){
    cin >> A[i];
  }
  vector<int> cnt(61, 0);
  REP(i, N){
    REP(j, 61){
      cnt[j] += A[i] >> j & 1;
    }
  }
  ll ans = 0, sum = 0;
  REPR(i, 60){
    if(N-cnt[i] > cnt[i] && ans+(1LL<<i) <= K){
      ans += 1LL<<i;
      sum += (N-cnt[i]) * 1LL<<i;
    }
    else{
      sum += cnt[i] * 1LL << i;
    }
  }
  // cout << ans << endl;
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1024
S = gets.split("").sort

ans = "yes"

0.upto(S.length - 1) do |i| # 要素がある分だけ繰り返したいとき
  if S[i] == S[i + 1]
    ans  = "no"
  end
end

puts ans
# https://qiita.com/you8/items/1d25a63a67c10dada128


Measured memory_bytes: 3836
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,m;

int main(){
  ll ans=0;
  cin >> n >>m;
  vi p(m),mon(n),wa(n);
  string s;

  REP(i,m){
    cin>>p[i]>>s;
    p[i]--;
    if (s=="AC"){
      mon[p[i]]=1;
    }else{
      if (mon[p[i]]==0){
        wa[p[i]]++;
      }
    }
  }
  

  ll answa=0;
  ll ansac=0;
  REP(i,n){
    ansac+=mon[i];
    if (mon[i]==1){
      answa+=wa[i];
    }
  }

  cout<<ansac<<" "<<answa<<endl;

  return 0;
}

Measured memory_bytes: 2560
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define INF 0x7fffffff
#define N 200007
int n;
long long cnt,a,b,minb=INF;
bool f=0;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld %lld",&a,&b);
		cnt+=b;
		if(b<a&&minb>b)
		minb=b;
		if(b!=a) f=1; 
	}
	if(f)printf("%lld\n",cnt-minb);
	else printf("0\n");
}

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

#define PI 4*atan(1)
#define INF 1e8

typedef long long ll;

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

vector<int> par;
vector<int> Rank;

void init(int n){
  for(int i = 0; i < n; i++){
    par[i] = i;
    Rank[i] = 0;
  }
}

int find(int x){
  if(par[x] == x){
    return x;
  }else {
    return par[x] = find(par[x]);
  }
}

void unite(int x, int y){
  x = find(x);
  y = find(y);
  if(x == y)return;

  if(Rank[x] < Rank[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(Rank[x] == Rank[y])Rank[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}


struct edge { int u, v, cost; };

bool comp(const edge& e1, const edge& e2){
  return e1.cost < e2.cost;
}

vector<edge> es;
int V, E;

int kruskal(){
  sort(es.begin(), es.end(), comp);
  init(V);
  int res = 0;
  for(int i = 0; i < E; i++){
    edge e = es[i];
    if(!same(e.u, e.v)){
      unite(e.u, e.v);
      res += e.cost;
    }
  }
  return res;
}

int main(){
   cin >> V >> E;
   es.resize(E);
   par.resize(V);
   Rank.resize(V);
   for(int i = 0; i < E; i++){
    int s, t, w;
    cin >> s >> t >> w;
    edge e;
    e.u = s; e.v = t; e.cost = w;
    es[i] = e;
   }
   int ans = kruskal();
   cout << ans << endl;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N;
char S[5050];

ll ln[5050];
ll i, j, k, ans;

ll calc(ll b){
    ll i = 1;
    ll j = 0;
    ll ret = 0;
    while(i+b<N){
        //printf("%lld%lld\n", b,i);
        if(i+ln[i-j]<j+ln[j]){
            ln[i] = ln[i - j];
            if(ret<min(i,ln[i])){
                ret = min(i, ln[i]);
            }
        }else{
            ll k = j + ln[i] - i > 0 ? j + ln[i] - i : 0;
            while(i+k+b<N&&S[k+b]==S[i+k+b])
                k++;
            ln[i] = k;
            if(ret<min(i,ln[i])){
                ret = min(i, ln[i]);
            }
            j = i;
        }
        i++;
    }
    return ret;
}
int main(){
    scanf("%lld%s", &N, S);
    fornum(i,0,N){
        ll a = calc(i);
        //printf("%lld:%lld\n", i, a);
        if(ans<a)
            ans = a;
        ll j;
        fornum(j,0,i){
            
        }
    }
    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<sstream>

using namespace std;

int str2int(string str) {
  stringstream ss;
  int ans;
  ss<<str;
  ss>>ans;
  return ans;
}

string int2str(int num) {
  stringstream ss;
  string str;
  ss<<num;
  ss>>str;
  return str;
}

int main() {
  int q;
  cin>>q;
  for(int i=0; i<q; i++) {
    string n;
    set<int> alreadyUsed;
    cin>>n;

    int ans = 0;
    while(true) {
      if(str2int(n)/10 == 0) { // 1桁なら終了
	break;
      }
      set<int>::iterator itr = alreadyUsed.find(str2int(n));
      if(itr != alreadyUsed.end()) { // 同じ値が2度出たら無限ループ
	ans = -1;
	break;
      }
      alreadyUsed.insert(str2int(n));
      int tmpMax = -1;
      /*
      for(int j=0; j<n.length(); j++) {
	string front, back;
	front += n[j];
	for(int k=j+1; k<n.length(); k++) {
	  back += n[k];
	}
	int tmp = str2int(front)*str2int(back);
	cout<<"tmpIs "<<tmp<<endl;
	if(tmp > tmpMax) {
	  tmpMax = tmp;
	}
      }
      */
      for(int j=1; j<n.length(); j++) {
	string front, back;
	for(int k=0; k<j; k++) {
	  front += n[k];
	}
	for(int k=j; k<n.length(); k++) {
	  back += n[k];
	}
	int tmp = str2int(front)*str2int(back);
	if(tmp > tmpMax) {
	  tmpMax = tmp;
	}
      }
      n = int2str(tmpMax);
      //cout<<"next is "<<n<<endl;
      ans++;
    }
    cout<<ans<<endl;
  }
}

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

int main(){
    vector<int> x1{1,3,5,7,8,10,12};
    vector<int> x2{4,6,9,11};

    int x, y;
    cin >> x >> y;

    int flag = 0;
    vector<int>::iterator c1 = find(x1.begin(), x1.end(), x);
    vector<int>::iterator c2 = find(x1.begin(), x1.end(), y);
    if(c1 != x1.end() && c2 != x1.end()){
        flag = 1;
    }
    vector<int>::iterator c3 = find(x2.begin(), x2.end(), x);
    vector<int>::iterator c4 = find(x2.begin(), x2.end(), y);
    if(c3 != x2.end() && c4 != x2.end()){
        flag = 1;
    }

    if(flag == 0){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/code-festival-2017-quala/tasks/code_festival_2017_quala_c

from collections import Counter, defaultdict

H, W = map(int, input().split())
A = [list(input()) for _ in range(H)]
c = defaultdict(int)
for row in A:
    for ch in row:
        c[ch] += 1

# 両方偶数 = 全部4回ずつ必要
if H % 2 == 0 and W % 2 == 0:
    if all(v % 4 == 0 for v in c.values()):
        print("Yes")
    else:
        print("No")
    exit()

# 両方奇数 (縦・横の中心がある)
elif H % 2 == 1 and W % 2 == 1:
    c_odd = sum(1 if v % 2 == 1 else 0 for v in c.values())
    if c_odd == 1 and sum(1 if v % 4 == 2 else 0 for v in c.values()) <= (W // 2) + (H // 2):
        print("Yes")
    else:
        print("No")
    exit()

# 片方が奇数
else:
    if all(v % 2 == 0 for v in c.values()) and \
        sum(1 if v % 4 == 2 else 0 for v in c.values()) <= \
            (W // 2 if W % 2 == 0 else H // 2):
        print("Yes")
    else:
        print("No")
    exit()

Measured memory_bytes: 38896
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fio ios_base::sync_with_stdio(false)
#define pdl cout << "*" << endl
#define MOD 1000000007
#define INF 1000000000
#define INFLL 1000000000000000000ll
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define long int64_t
using namespace std;
using namespace __gnu_pbds;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef priority_queue<pii, vector<pii>, greater<pii>> min_pq;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OST;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<> dis(0, INF<<1);
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args)
{ const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma+1, args...); }

const int N = 100001;

unordered_set<int> gr[N];
int deg[N], cc;
bool v[N];
stack<int> st;

void dfs(int node)
{
	if(v[node])
	{
		while(st.top() != node)
		{
			v[st.top()] = false;
			st.pop();
		}
		v[st.top()] = false;
		st.pop();
		cc++;
	}
	while(!gr[node].empty())
	{
		if(!v[node])
		{
			st.push(node);
			v[node]++;
		}
		int nd = *(gr[node].begin());
		gr[node].erase(nd);
		gr[nd].erase(node);
		dfs(nd);
	}
}

int main()
{
	fio;
	int n, m;
	cin >> n >> m;
	for(int i=0; i<m; i++)
	{
		int u, v;
		cin >> u >> v;
		gr[u].insert(v);
		gr[v].insert(u);
		deg[u]++;
		deg[v]++;
	}
	for(int i=1; i<=n; i++)
	{
		if(deg[i] & 1)
		{
			cout << "No" << endl;
			return 0;
		}
	}
	dfs(1);
	cout << (cc >= 3 ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 25216
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner kb=new Scanner(System.in);
		int x[]=new int[6000],y[]=new int[6000];
		x[0]=kb.nextInt();
		y[0]=kb.nextInt();
		int h=0;
		int i=0;
		while(x[h]!=0||y[h]!=0){
			h++;
			x[h]=kb.nextInt();
			y[h]=kb.nextInt();

		}

		while(x[i]!=0||y[i]!=0){
			if(x[i]>=y[i]){
				System.out.printf("%d %d",y[i],x[i]);
			}else if(x[i]<y[i]){
				System.out.printf("%d %d",x[i],y[i]);
			}
			System.out.println();
			i++;
		}
	}

}

Measured memory_bytes: 40688
# https://atcoder.jp/contests/abc162/tasks/abc162_c
import math
K=int(input())
# K=200
tot=0
# for i in range(1,K+1):
#     for j in range(1,K+1):
#         tmp=math.gcd(i,j)
#         for k in range(1,K+1):
#             tot+=math.gcd(tmp,k)
ls=[0]*202
for i in range(1,K+1):
    for j in range(1,K+1):
        tmp=math.gcd(i,j)
        ls[tmp+1]+=1
tot=0
for i in range(1,K+1):
    for j in range(1,201):
        tot+=ls[j+1]*math.gcd(j,i)

print(tot)

Measured memory_bytes: 9168
#include<cctype>
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
    char n;
    
    while(1){
        scanf("%c",&n);
        
        if(n == '\n') break;   //改行のときおわり
        
        if(isalpha(n)){    //入力されたものがアルファベットのとき
            
            if(islower(n)) printf("%c",toupper(n));  //小文字のとき
            else if(isupper(n)) printf("%c",tolower(n));  //大文字のとき
            
        }else{   //アルファベット以外はそのまま出力する
            printf("%c",n);
        }
    }
    printf("\n");
    
    return 0;
}


Measured memory_bytes: 3132
N = int(input())
A = list(map(int, input().split()))
ans = 1
check = 0
for i in A:
    ans *= i
    if ans > 10**18:
        check += 1
        break
        
if min(A)==0:
    print("0")
elif check>0:
    print("-1")
else:
    print(ans)

Measured memory_bytes: 21704
#include<iostream>
#include<cstdio>
#include<cstring>

namespace La_Ji
{
	typedef long long ll;
	const int N=1000010,MOD=998244353;

	inline void inc(int a,int &b){b=(a+b)%MOD;}

	ll inv(int x){return x==1?1:(-(MOD/x)*inv(MOD%x)%MOD);}
	ll qpow(ll a,ll b){ll c=1;for(;b;b>>=1,a=a*a%MOD)if(b&1)c=c*a%MOD;return c;}

	int fact[N],ifact[N];

	int C(int n,int m){return (ll)fact[n]*ifact[m]%MOD*ifact[n-m]%MOD;}
	int f(int n,int m){return C(n+m,n);}

	void initialize()
	{
		fact[0]=1;
		for(int i=1;i<N;i++)fact[i]=(ll)fact[i-1]*i%MOD;
		ifact[N-1]=(inv(fact[N-1])+MOD)%MOD;
		for(int i=N-1;i;i--)ifact[i-1]=(ll)ifact[i]*i%MOD;
	}

	int n,m;

	void solve()
	{
		initialize();
		scanf("%d%d",&n,&m);

		if(n<m)std::swap(n,m);

		int ans=0;
		for(int i=1;i<=m;i++)
			ans=(ans+(ll)f(i,i)*f(n-i,m-i))%MOD;
		ans=ans*inv(2)%MOD*inv(f(n,m))%MOD;
		ans=((ans+n)%MOD+MOD)%MOD;
		printf("%d\n",ans);
	}
}

int main()
{
	La_Ji::solve();
	return 0;
}


Measured memory_bytes: 8064
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
ll c[15];
int main() {
	ll n, m, x;
	cin >> n >> m >> x;
	vector<vector<ll>>a(n);
	for (int i = 0; i < n; i++) {
		cin >> c[i];
	    a.resize(m);
		for (int j = 0; j < m; j++) {
			int x; cin >> x;
			a[i].push_back(x);
		}
	}
	ll ans = inf;
	for (int bit = 0; bit < (1 << n); bit++) {
		ll sum = 0;
		vector<ll>check(m, 0);
		bool ok = true;
		for (int i = 0; i < n; i++) {
			if (bit & (1 << i)) {
				sum += c[i];
				for (int j = 0; j < m; j++) {
					check[j] += a[i][j];
				}
			}
		}
		for (int k = 0; k < m; k++) {
			if (check[k] < x) {
				ok = false;
			}
		}
		if (ok) {
			ans = min(ans, sum);
		}

	}
	if (ans == inf) {
		cout << "-1" << endl;
	}
	else {
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3616
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

const pi = math.Pi

var mod int = pow(10, 9) + 7
var Umod uint64 = 1000000007
var ans, cnt int = 1e9, 0

func main() {
	var flag bool
	var S string
	fmt.Scan(&S)

	for i := 0; i < len(S)-1; i++ {
		if string(S[i]) != string(S[i+1]) {
			cnt = max(i+1, len(S)-1-i)
			ans = min(ans, cnt)
			flag = true
		}
	}
	if flag == false {
		ans = len(S)
	}

	fmt.Println(ans)
}

/*  ----------------------------------------  */

var reader = bufio.NewScanner(os.Stdin)

func read() string {
	reader.Scan()
	return reader.Text()
}

func lcm(x, y int) int {
	return (x / gcd(x, y)) * y
}

func gcd(x, y int) int {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

var fac [1000000]int
var finv [1000000]int
var inv [1000000]int

func combination_init() {
	fac[0], fac[1] = 1, 1
	finv[0], finv[1] = 1, 1
	inv[1] = 1

	// invは a^(-1) mod p
	// pをaで割ることを考える

	// p/a*(a) + p%a = p
	// p/a*(a) + p%a = 0          (mod p)
	// -p%a = p/a*(a)             (mod p)
	// -p%a *a^(-1)= p/a          (mod p)
	// a^(-1)= p/a * (-p%a)^(-1)  (mod p)
	// a^(-1) =

	for i := 2; i < 1000000; i++ {
		fac[i] = fac[i-1] * i % mod
		inv[i] = mod - inv[mod%i]*(mod/i)%mod
		finv[i] = finv[i-1] * inv[i] % mod
	}
}

func combination(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[y] * finv[x-y] % mod) % mod
	//return fac[x] / (fac[y] * fac[x-y])
}

func permutation(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[x-y] % mod) % mod
	//return fac[x] / fac[x-y]
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }
func ceil(x int) int   { return int(math.Ceil(float64(x))) }

type SortBy []struct {
	b, c int
}

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i].c > a[j].c }

type PriorityQueue []int

func (h PriorityQueue) Len() int            { return len(h) }
func (h PriorityQueue) Less(i, j int) bool  { return h[i] < h[j] }
func (h PriorityQueue) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *PriorityQueue) Push(x interface{}) { *h = append(*h, x.(int)) }
func (h *PriorityQueue) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
main(){
    string s;
    cin >> s;
    int n = s.size();
    s = '0' + s;
    for(int i = 0; i <= n; i++){
        if(s[i] != s[n - i]){
            cout << "-1"<<endl;
            return 0;
        }
    }
    if(s[1] == '0'){
        cout<<"-1"<<endl;
        return 0;
    }
    int rt = 1;
    int cnt = 2;
    for(int i = 1; i < n; i++){
        cout <<rt <<" "<<cnt<<endl;
        if(s[i] == '1') rt = cnt;
        cnt ++;
    }

}


Measured memory_bytes: 1660
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

#define NUM 101000
int main(){
    int X;
    scanf("%d",&X);

    unsigned i, j;
    unsigned sq_num = (int)sqrt((double)NUM);
    unsigned prime[NUM];

  // 1が立っているものが素数
  // 0が立っているものが合成数（素数ではない）

    for (i = 0; i < NUM; i++) prime[i] = 1;  // 全ての数に1を立てる
    prime[0] = 0;    // 1は素数ではない

    for (i = 1; i < sq_num; i++) {
        if (prime[i] == 1)          // prime[i]が素数なら
          for (j = (i+1); (i+1) * j <= NUM; j++)
            prime[(i+1) * j - 1] = 0;  // 素数の倍数は素数ではない
     }
    for(i = X-1; i<NUM; i++){
        if(prime[i] == 1){
            printf("%d",i+1);
            return 0;
        }
    }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

int n,m;
bool p[4040][4040];
int main() {
	scanf("%d%d",&n,&m);
	for (int i=0;i<(1<<n);i++) {
		for (int j=0;j<(1<<m);j++) {
			p[i][j]=__builtin_parity(i&j);
		}
	}
	rep(i,1,(1<<n)) per(j,1,(1<<m)) p[i][j]^=p[i][j-1];
	per(i,1,(1<<n)) rep(j,0,(1<<m)) p[i][j]^=p[i-1][j];
	rep(i,1,(1<<n)) {
		rep(j,1,(1<<m)) printf("%d",p[i][j]);
		puts("");
	};
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define DEBUG(x) cerr << #x << ": " << (x) << endl;

int main() {
  int n;
  cin >> n;
  vector<int> cnt(n + 1);
  for (int i = 2; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    ++cnt[x];
  }
  for (int i = 1; i <= n; ++i) printf("%d%c", cnt[i], " \n"[i == n]);
}

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

//region Template
#include "ext/pb_ds/assoc_container.hpp"
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const int MOD = 1000000007;

using namespace std;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_multiset;

#define finish(x) cout << x; exit(0);
#define fastIO cin.tie(0); cin.sync_with_stdio(false);

void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }

//const string USCAO_TAG = "mountains";
void usaco(const string& USACO_TAG) { setIn(USACO_TAG + ".in"); setOut(USACO_TAG + ".out"); }
/*
template<typename... Args>
void print(Args... args) {
	#ifdef LOCAL
	((std::cout << args << " "), ...);
	cout << endl;
	#endif
}
 */
//endregion

/* Notes:
 * Farah </3
 */

const int MAXN = 1e3 + 6;

ld dist(ld x1, ld y1, ld x2, ld y2){
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

struct q{
	int x, y, r;
};

q a[MAXN];

ld d[MAXN];


vector<vector<pair<int, ld>>> adj;
bool V[MAXN];

int main() {
	#ifdef LOCAL

	setIn("in.txt");
	setOut("out.txt");
	#endif

	int xs, ys, xe, ye;
	cin >> xs >> ys >> xe >> ye;

	a[0] = {xs, ys, 0};
	int n;
	cin >> n;

	a[n + 1] = {xe, ye, 0};
	adj.assign(n + 5, vector<pair<int, ld>>());


	for(int i = 1; i < n + 2; i++){
		d[i] = 1e18;
	}

	for(int i = 0; i < n; i++){
		int x, y, r;
		cin >> x >> y >> r;

		a[i + 1] = {x, y, r};
	}

	for(int i = 0; i < n + 2; i++){
		for(int j = i + 1; j < n + 2; j++){
			ld dis = dist(a[i].x, a[i].y, a[j].x, a[j].y) - (a[i].r + a[j].r);
			adj[i].push_back({j, max((ld)0, dis)});
			adj[j].push_back({i, max((ld)0, dis)});
		}
	}

	d[0] = 0;

	for(int i = 0; i < n + 2; i++){
		int cur_m = -1;
		for(int j = 0; j < n + 2; j++){
			if(!V[j] && (cur_m == -1 || d[j] <= d[cur_m])){
				cur_m = j;
			}
		}

		V[cur_m] = 1;
		for(auto x : adj[cur_m]){
			if(d[cur_m] + x.second < d[x.first]){
				d[x.first] = d[cur_m] + x.second;
			}
		}
	}

	cout << fixed << setprecision(8) << d[n + 1] << endl;
}


Measured memory_bytes: 32768
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
long long n;
int main() {
	cin >> n; int minx = 99;
	for (long long i = 1; i*i <= n; i++) {
		if (n%i != 0)continue;
		string S1 = to_string(i), S2 = to_string(n / i);
		minx = min(minx, (int)max(S1.size(), S2.size()));
	}
	cout << minx << endl;
	return 0;
}

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

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

  int X;
  cin >> X;

  for (int K = 1;; K++) {
    if ((X * K) % 360 == 0) {
      cout << K << "\n";
      return 0;
    }
  }
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define MAX_N 1005
#define MAX_M 1005
using namespace std;

int n,m;
int dp[MAX_N + 1][MAX_M + 1];

int Main(){
    string s, t;
    cin >> s;
    cin >> t;
    n = s.size();
    m = t.size();
    for (int i = 0; i < n; i++){
        dp[i][0] = 0;
    }
    for (int i = 0; i < m; i++){
        dp[0][i] = 0;
    }
    
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            if (s[i] == t[j]){
                dp[i + 1][j + 1] = dp[i][j] + 1;
            } else {
                dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
            }
        }
    }
    return dp[n][m];
}
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    int q;
    cin >> q;
    for (int i = 0; i < q; i++){
        cout << Main() << endl;
    }
}


Measured memory_bytes: 7148
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())
ans = 0
for i in range(k):
    if t[i] == 'r':
        ans += p
    elif t[i] == 's':
        ans += r
    else:
        ans += s
for i in range(k , n):
    if t[i - k] == t[i]:
        t[i] = 'v' #
    if t[i] == 'r':
        ans += p
    elif t[i] == 's':
        ans += r
    elif t[i] == 'p':
        ans += s
print(ans)

Measured memory_bytes: 4084
/* ex3_3 
　　　　　sachiyan*/

#include <stdio.h>
#include<math.h> //math.h の標準ライブラリを使用
int main(void){
    int N, K, ans; //入力値N,Kと答えansを定義
    scanf("%d %d", &N, &K); //入力値N,Kを読み取る
    ans = 0; //ansに初期値0を代入
    while(pow(K, ans) <= N){ //powはmath.hによる累乗を計算する関数
        ans++;  //K進数の最高位を探す　Kのans乗がN以下の時はそれ以上の桁が存在するので繰り返す
    }
    printf("%d\n", ans); //答えansを出力
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod =1e9+7;
ll qui(ll n,ll m){
//    ll ans =1;
//    while(m){
//        if(m&1){
//            ans *=n;
//            ans %=mod;
//        }
//        m >>=1;
//        n *=n;
//        n %=mod;
//    }
//    return ans;
    ll ans =1;
    for(ll i=1;i<=m;i++) ans =ans*n%mod;
    return ans;
}
int main(){
    ll n;
    cin>>n;
    ll res =qui(10,n)-qui(9,n)*2+qui(8,n);
    res =(res%mod+mod)%mod;
    cout<<res<<"\n";

    return 0;
}


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


def solve(N: int, K: int, H: "List[int]"):
    if K >= N:
        return 0
    return sum(sorted(H, reverse=True)[K:])


# Generated by 1.1.6 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()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    H = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, K, H))

if __name__ == '__main__':
    main()


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

int max_n = 1e6 + 6;
vector<int> spf;

void sieve()
{
	spf.resize(max_n, 1);
	
	for(int num = 2; num < max_n; num++)
		spf[num] = num;

	for(int num = 2; num < max_n; num++)
	{
		if(spf[num] != num)
			continue;

		for(int mult = 2*num; mult < max_n; mult += num)
			spf[mult] = num;
	}
}

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

	vector<int> a(n);
	for(auto &ele : a)
		cin >> ele;

	vector<bool> present(max_n, false);
	bool first = true;

	for(int i = 0; i < n; i++)
	{
		int num = a[i];
		while(num != 1)
		{
			int pf = spf[num];
			if(present[pf] == true)
				first = false;
			
			present[pf] = true;
			while(num % pf == 0)
				num /= pf;
		}
	}
	
	int g = a[0];
	for(int i = 1; i < n; i++)
		g = __gcd(g, a[i]);

	if(first)
		cout << "pairwise coprime" << endl;
	else if(g == 1)
		cout << "setwise coprime" << endl;
	else
		cout << "not coprime" << endl;
}

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

	sieve();
	solve();
	return 0;
}


Measured memory_bytes: 11324
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> jobs(m);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    if (a > m)
      continue;
    jobs[m - a].push_back(b);
  }

  priority_queue<int> q;
  ll ans = 0;

  for (int i = m - 1; i >= 0; --i) {
    for (auto &b : jobs[i]) {
      q.push(b);
    }
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define endl "\n"
 
 
int pow1(int n, int p)
{
	if(p==0)	return 1;
	int x=pow1(n, p/2);
	x=(x*x)%mod;
	if(p%2==0)
		return x;
	else
		return (x*n)%mod;
}
 
int32_t main()
{
	fast;

	int n;
	cin>>n;
	vector<int> v(n);
	int m=1;
	int g=1;
	vector<int> v1(1000001, 0);
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
		int x=v[i];
		for(int j=2;j*j<=x;j++)
		{
			if(x%j==0)
			{
				int c=0;
				while(x%j==0)
				{
					x=x/j;
					c++;
				}
				v1[j]=max(v1[j], c);
			}
			// cout<<x<<endl;
		}
		v1[x]=max(v1[x], 1ll);
	}

	int l=1;

	for(int i=1;i<=1000000;i++)
	{
		int x=pow1(i, v1[i]);
		l=(l*x)%mod;
	}
	int ans=0;

	for(int i=0;i<n;i++)
	{
		int v1=(l*pow1(v[i], mod-2))%mod;
		ans+=v1;
		ans%=mod;
	}

	cout<<ans<<endl;

	// int c=0;

	// for(int i=0;i<n;i++)
	// {
	// 	int x=v[i];
	// 	int 
	// 	for(int j=0;j<n;j++)
	// 	{
	// 		if(j==i)
	// 			continue;
	// 		x=(x*v[j])/__gcd(x, v[j]);
	// 	}
	// 	c+=(x/v[i])%mod;
	// 	// cout<<x<<endl;
	// }
	// cout<<c<<endl;

	return 0;
}

Measured memory_bytes: 8192
import "dart:io";

void main() {
  List c1i = stdin.readLineSync().split(" ").map((x) => int.parse(x)).toList();
  List c2i = stdin.readLineSync().split(" ").map((x) => int.parse(x)).toList();
  List c3i = stdin.readLineSync().split(" ").map((x) => int.parse(x)).toList();
  if (c1i[0] - c2i[0] == c1i[1] - c2i[1] &&
      c1i[1] - c2i[1] == c1i[2] - c2i[2] &&
      c1i[0] - c3i[0] == c1i[1] - c3i[1] &&
      c1i[1] - c3i[1] == c1i[2] - c3i[2] &&
      c2i[0] - c3i[0] == c2i[1] - c3i[1] &&
      c2i[1] - c3i[1] == c2i[2] - c3i[2]) {
    print("Yes");
  } else {
    print("No");
  }
}

Measured memory_bytes: 13200
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <set>

using namespace std;

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

    vector<int> a(m), b(m);
    set<int> penul;
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
        if (b[i] == n)
            penul.insert(a[i]);
    }

    bool ans = false;
    for (int i = 0; i < m; i++) {
        if (a[i] == 1 && penul.count(b[i])) {
            ans = true;
            break;
        }
    }

    cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;

    return 0;
}

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

#define debug(x) (cerr << #x << " = " << x << endl;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c)

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

const int maxn = 2e5 + 100;

int a[maxn], b[maxn], c[maxn], d[maxn];
int n,m,q;

int A[maxn];
int ans = 0;
void solve(int pos, int last)
{
  if(pos == n+1)
  {
    // for(int i = 1; i <= n; i++)
    //   cout << A[i] << ' ';
    // cout << endl;
    int val = 0;
    for(int i = 1; i <= q; i++)
    {
      if(A[b[i]] - A[a[i]] == c[i])
        val += d[i];
    }
    ans = max(ans, val);
    return;
  }

  for(int i = last; i <= m; i++)
  {
    A[pos] = i;
    solve(pos+1, i);
  }
}

int main()
{
  ios::sync_with_stdio(0);
  cin >> n >> m >> q;
  for(int i = 1; i <= q; i++)
  {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }

  solve(1, 1);

  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>


int main() {

    std::string S;
    std::cin >> S;

    std::reverse(S.begin(), S.end());

    std::vector<std::string> patterns = {"dream", "dreamer", "erase", "eraser"};

    for (int i = 0; i < patterns.size(); ++i) {
        std::reverse(patterns[i].begin(), patterns[i].end());
    }

    int index = 0;
    while (index < S.length()) {
        bool match = false;
        for (int i = 0; i < patterns.size(); ++i) {
            std::string substr = S.substr(index, patterns[i].length());
            if (substr == patterns[i]) {
                index += patterns[i].length();
                match = true;
            }
        }
        if (!match) {
            break;
        }
    }

    if (index == S.length()) {
        std::cout << "YES" << "\n";
    } else {
        std::cout << "NO" << "\n";
    }
    return 0;
}


Measured memory_bytes: 512