akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
//#include<bits/stdc++.h>
#include<vector>
#include<math.h>

using namespace std;

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

   x = ceil(n/1.08);

   if(floor(x*1.08) == n)
   {
      cout << x;
   }

   else
   {
      cout << ":(";
   }
   
}

Measured memory_bytes: 3556
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    
    let a = line[0];
    let b = line[1];
    let k = line[2];

    let mut count = 0;
    let mut tmp = cmp::max(a,b) + 1;
    while count < k {
        tmp -= 1;
        if a%tmp == 0 && b%tmp == 0 {
            count += 1;
        }
    }
    println!("{}", tmp);
}


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

int main(){
 int N,M,f,g;
  cin>>N;
 vector<string> a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  g=0;
  f=0;
  cin>>M;
   vector<string> b(M);
    for(int i=0;i<M;i++){
   cin>>b[i];
   }
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
        if(a[i]==a[j]){
          f++;
        }
      }
        for(int j=0;j<M;j++){
        if(a[i]==b[j]){
          f--;
        }
      }
   g=max(g,f);
      f=0;
    }
 cout<<g<<endl;
}


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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...)       \
	F_ORC(__VA_ARGS__) \
	(__VA_ARGS__)

#define E_ACH2(x, a) for (auto &x : a)
#define E_ACH3(x, y, a) for (auto &[x, y] : a)
#define E_ACH4(x, y, z, a) for (auto &[x, y, z] : a)
#define E_ACHC(...) GET5(__VA_ARGS__, E_ACH4, E_ACH3, E_ACH2)
#define EACH(...)       \
	E_ACHC(__VA_ARGS__) \
	(__VA_ARGS__)

template <typename A, typename B>
inline void chmin(A &a, B b)
{
	if (a > b)
		a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b)
{
	if (a < b)
		a = b;
}

// const int mxN = 1e9 + 7;
const int M = 1e9 + 7;

ll pw(ll b, ll e)
{
	ll res = 1;
	while (e)
	{
		if (e % 2)
			res = (res * b) % M;
		b = (b * b) % M;
		e >>= 1; // e/=2;
	}
	return res;
}

// ll fact[mxN + 1], inv[mxN + 1];
// ll C(ll n, ll k)
// {
// 	return (((fact[n] * inv[k]) % M) * inv[n - k]) % M;
// }
// ll f1[M + 1], f2[M + 1];
// ll C(int n, int k)
// {
// 	return (((f1[n] * f2[k]) % M) * f2[n - k]) % M;
// }

int main()
{
	fast;
	ll n, r;
	cin >> n >> r;
	if (n < 10)
	{
		cout << r + 100 * (10 - n);
	}
	else
		cout << r;
}

Measured memory_bytes: 3536
import Data.List
import Data.Ratio

main :: IO ()
main = do
  _ <- getLine
  [t, a] <- readInts
  hs <- readInts
  print $ solve t a hs

readInts :: IO [Int]
readInts = map read . words <$> getLine

solve :: Int -> Int -> [Int] -> Int
solve t a = fst . foldl1' f . zip [1..]
  where
    f (i, hi) (j, hj)
      | abs(averageTemp t hi - a % 1) < abs(averageTemp t hj - a % 1) = (i, hi)
      | otherwise                                                     = (j, hj)

averageTemp :: Int -> Int -> Ratio Int
averageTemp t x = t % 1 - x * 6 % 1000


Measured memory_bytes: 1404
#include <bits/stdc++.h>
using namespace std;
long long dp[55][55][10010];
int main(){
  long long n,ave,ans=0;
  cin >> n >> ave;
  long long a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }

  //dp[見た枚数][使った枚数][総和]
  dp[0][0][0]=1;
  for(int i=0;i<n;i++){
    for(int j=0;j<=n;j++){
      for(int k=0;k<=n*ave;k++){
        dp[i+1][j+1][k+a[i]]+=dp[i][j][k];//使う
        dp[i+1][j][k]+=dp[i][j][k];//使わない
      }
    }
  }
  for(int i=1;i<=n;i++){
    ans+=dp[n][i][i*ave];//i枚使ったとき平均がaveになるなら総和がi*ave
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 215296
def myAnswer(S:str) -> int:
   ans = 0
   pre = S[0]
   for s in S[1:]:
      if (pre != s):
         pre = s
         ans += 1
   return ans

def modelAnswer():
   return
def main():
   S = input()

   print(myAnswer(S))
if __name__ == '__main__':
   main()

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

int main(){
    int k,a,b;
    cin >> k >> a >> b;
    for(int i = a;i <= b;i++){
        if(i%k == 0){
            cout << "OK" << endl;
            exit(0);
            }
    }
    cout << "NG" << endl;
    return 0;
}

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

int main(){
  string s;
  cin>>s;
  int n=s.size();
  for(int i=0;i<=7;i++){
    string t=s.substr(0,i)+s.substr(n-7+i);
    if(t=="keyence"){
      cout<<"YES"<<endl;
      return 0;
    }
  }
  cout<<"NO"<<endl;
  return 0;
}


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

using namespace std;

#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define nl "\n"
#define sp " "
#define int long long
#define PI 3.141592653589793
#define scanstr(s) cin>>ws; getline(cin,s);

void solve()
{
	int a,b;
	cin>>a>>b;
	if(a<=5) cout<<0<<nl;
	else if(a<13) cout<<b/2<<nl;
	else cout<<b<<nl;
	return ;
}

int32_t main()
{
	FastIO;
	solve();
	return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define rep(i,n) for(int i=0; i<n; i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;
typedef map<int,int> mp;

const int MOD = 1e9 + 7;


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

    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    ll x = c * d / __gcd(c,d);

    a--;
    ll a_count = a - (a / c) - (a / d) + (a / x);
    ll b_count = b - (b / c) - (b / d) + (b / x);

    cout << b_count - a_count  << endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//Author: Ezio Sam
/* Shorthands */
#define ll long long
#define pb push_back
#define em emplace_back
#define mp make_pair
#define sp " "
#define cs "Case "
#define fi first
#define sn second

/* STL */
#define mem(a,n) memset(a, n, sizeof(a));
#define all(x) x.begin(),x.end()
#define alr(x) x.rbegin(),x.rend()
#define sz(x)  (int)x.size()
#define mx(v)  *max_element(v.begin(),v.end())
#define mxi(v) distance(v.begin(),max_element(v.begin(),v.end()))
#define mxa(a) *max_element(a, a.size())
#define r(a)   reverse(a.begin(),a.end())
/* loops */
#define fa(i, a, b) for (auto (i) = (a); (i) < (b); ++(i))
#define fr(i,n)   for(__typeof(n) i=0;i<(n);i++)
#define fn(i,n)   for(__typeof(n) i=1;i<=(n);i++)
/*Special*/
#define Ezio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define db(something)  cerr<<#something<<" - "<<something<<"\n";

int main()
{

   Ezio
   ll t,m(0),n,x=100,a,b;
   string s;

   cin>>n;
   while(n>x){
    x+=x/100;
    m++;
   }

   cout<<m<<endl;


   return 0;
}


Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();

		long sq = (long) Math.sqrt(N);
		if (N % sq == 0) {
			System.out.println(String.valueOf(sq).length());
		} else {
			long a = N;
			long b = 1;
			while (b < sq) {
				b++;
				if (N % b == 0) {
					a = N / b;
				}
			}
			b = N / a;
			long aLength = String.valueOf(a).length();
			long bLength = String.valueOf(b).length();
			System.out.println(Math.max(aLength, bLength));
		}

	}

}

Measured memory_bytes: 21716
#include <stdio.h>

int main(void){
    char s[1000];
    char t[1000];
    int si = 0;
    int ti = 0;
    int maxc = 0;
    scanf("%s %s", &s, &t);

    while(t[ti] != '\0'){
        ti++;
    }
    while(s[si] != '\0'){
        si++;
    }

    for(int i = 0; i <= si - ti; i++){
        int c = 0;
        for(int j = 0; j < ti; j++){
            if(s[i+j] == t[j]){
                c++;
            }
        }
        if(maxc < c){
            maxc = c;
        }
    }

    printf("%d", ti - maxc);
    return 0;
}

Measured memory_bytes: 2148
#pragma GCC optimize("Ofast", "unroll-loops")

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

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
// default_random_engine generator;
// mt19937 rnd(1);

const int MAXN = 200200;
const int P = 998244353;

void add(int &a, int b) {
    a += b;
    if (a >= P) {
        a -= P;
    }
}

void sub(int &a, int b) {
    a -= b;
    if (a < 0) {
        a += P;
    }
}

void mul(int &a, int b) {
    a = ll(a) * b % P;
}

int f[MAXN];

int main() {
#ifdef LOCAL
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);  
#endif 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0); 
    cout.precision(12);
    cout << fixed; 

    int n;
    cin >> n;
    string s;
    cin >> s;


    for (int d = 1; d <= n; ++d) {
        if (n % d != 0 || (n / d) % 2 == 0) {
            continue;
        }

        int cur = 0;

        for (int i = 0; i < d; ++i) {
            mul(cur, 2);
            add(cur, s[i] == '1');
        }

        string t = s.substr(0, d);

        while (sz(t) < sz(s)) {
            t += t[sz(t) - d] == '1' ? '0' : '1';
        }

        if (t <= s) {
            add(cur, 1);
        }

        f[d] = cur;

        // cout << d << " " << cur << endl;
    }

    for (int i = 2; i <= n; ++i) {
        if (n % i != 0 || (n / i) % 2 == 0) {
            continue;
        }
        for (int d = 1; d * d <= i; ++d) {
            if (i % d) {
                continue;
            }
            sub(f[i], f[d]);
            if (d * d != i && d != 1) {
                sub(f[i], f[i / d]);
            }
        }
        // cout << i << " " << f[i] << endl;
    }

    int res = 0;
    for (int i = 1; i <= n; ++i) {
        int cur = f[i];
        mul(cur, 2 * i);
        add(res, cur);
    }

    cout << res << endl;

#ifdef LOCAL
    cerr << "Time: " << double(clock()) / CLOCKS_PER_SEC << endl;
#endif
}


Measured memory_bytes: 1092
import java.util.Arrays;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int num = Integer.parseInt(scanner.nextLine());

		Dice[] dices = new Dice[num];
		boolean flag = true;

		loop: for (int i = 0; i < num; i++) {
			dices[i] = new Dice(scanner.nextLine());
			for (int j = 0; j < i; j++) {
				if (dices[i].equals(dices[j])) {
					flag = false;
					break loop;
				}
			}
		}
		System.out.println(flag ? "Yes" : "No");
	}
}

class Dice {
	int[] a = new int[6];

	Dice(String s) {
		String[] b = s.split(" ");
		for (int i = 0; i < 6; i++) {
			a[i] = Integer.parseInt(b[i]);
		}
	}

	public void roll(char c) {
		int temp;
		switch (c) {
		case 'E':
			temp = a[0];
			a[0] = a[3];
			a[3] = a[5];
			a[5] = a[2];
			a[2] = temp;
			break;
		case 'N':
			temp = a[0];
			a[0] = a[1];
			a[1] = a[5];
			a[5] = a[4];
			a[4] = temp;
			break;
		case 'W':
			temp = a[0];
			a[0] = a[2];
			a[2] = a[5];
			a[5] = a[3];
			a[3] = temp;
			break;
		default:
			temp = a[0];
			a[0] = a[4];
			a[4] = a[5];
			a[5] = a[1];
			a[1] = temp;
			break;
		}
	}

	public boolean equals(Dice d) {
		char[] c = { 'E', 'E', 'E', 'N', 'W', 'W', 'W', 'S' };
		boolean flag = false;
		loop: for (int i = 0; i < 24; i++) {
			if (Arrays.equals(a, d.a)) {
				flag = true;
				break loop;
			}
			d.roll(c[i % 8]);
		}
		return flag;
	}
}



Measured memory_bytes: 27860
#abc045 b
from collections import deque
sa=deque(list(input()))
sb=deque(list(input()))
sc=deque(list(input()))

tefuda=sa
win=""
while tefuda:
    c=tefuda.popleft()
    if c=="a":
        tefuda=sa
        win="A"
    if c=="b":
        tefuda=sb
        win="B"
    if c=="c":
        tefuda=sc
        win="C"
print(win) 


Measured memory_bytes: 3316
#include<iostream>
#include<vector>
using namespace std;
int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(50);
  int i;
  for(i = 0; i < n; i++)cin >> a.at(i);
  for(i = 0; i < n; i++)
    {
        int k = 0;
      while(a.at(i) > 0)
      {
          b.at(k) += a.at(i)%2;
          a.at(i) /= 2;
          k++;
      }
    }
    bool ok = true;
    for(i = 0; i < 50; i++)
    {
        if(b.at(i)%2!=0)ok = false;
    }
    if(ok)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 640
using System;
class AOJ0168{
	public static void Main(){
		int i,n;
		int[] a=new int[31];
		a[0]=a[1]=1;a[2]=2;
		for(i=3;i<31;i++)a[i]=a[i-1]+a[i-2]+a[i-3];
		for(;(n=int.Parse(Console.ReadLine()))>0;Console.WriteLine((a[n]+3649)/3650));
	}
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair < pair <int, int> , int> ppi;
typedef pair < pair <int, int> , ll> ppll;
typedef pair <ll, ll> pll;
typedef string str;

# define endl		 '\n'
# define sep		 ' '
# define F 			 first
# define S 			 second
# define pb			 push_back
# define fast_io 	 ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const ll md = 1e9+7;

ll gcd(ll a, ll b){ if (b == 0) return a; return gcd(b, a%b);}
ll lcm(ll a, ll b){ return (a*b)/gcd(a, b);}
ll pw(ll a, ll b){
	if (b == 1) return (a+md)%md;
	if (b%2 == 0) return (pw(a*a, b/2)+md)%md;
	else return (a*pw(a*a, b/2)+md)%md;
}

const int xn = 1e6+10;
const int xm = 5e4+10;

int a[xn];

ll p(ll a, ll b){
	ll s = 1;
	for (int i=0; i<b; i++) s *= a;
	return s;
}

int main(){
	fast_io;
	
	ll n;
	cin >> n;
	
	if (n%2){
		cout << 0 << endl;
		return 0;
	}
	
	ll t1 = 0, t2 = 0;
	
	ll s1 = 0, s2 = 0;
	ll m = n;
	while(m > 0) s1++, m/=2;
	m = n;
	while (m > 0) s2++, m/=5;
	
	for (int i=1; i<=s1; i++){
		t1 += n/p(2, i);
	}
	for (int i=1; i<=s2; i++){
		t2 += (n/p(5, i))/2;
	}
	
	
	cout << min(t1, t2) << endl;
	
	return 0;
}



Measured memory_bytes: 256
require 'openssl'
X, Y = gets.split.map(&:to_i)

num_moves = (X+Y)/3

for i in 0..num_moves
    if [X, Y] == [i + 2 * (num_moves - i), (num_moves - i) + 2 * i]
        num_a = i
        break
    end
end

if !num_a || (X + Y) % 3 != 0
    p 0
    exit
end

if num_a == num_moves
    p 1
    exit
end

a = ((num_a + 1)..(num_moves)).inject{|prod, n| prod * n % (10**9+7)}
b = (1..(num_moves - num_a)).inject{|prod, n| prod * n % (10**9+7)}
p a * OpenSSL::BN.new(b).mod_inverse(10**9+7) % (10**9+7)

Measured memory_bytes: 5244
n = int(input())
a = list(map(int, input().split()))

mod = 10**9+7
g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1]
for i in range(2, n+2):
    g1.append((g1[-1] * i) % mod)
    inv.append((-inv[mod%i] * (mod//i)) % mod)
    g2.append((g2[-1] * inv[-1]) % mod)

def comb(n, r):
    if r<0 or r>n:
        return 0
    return g1[n] * g2[r] * g2[n-r] % mod

t = sum(a)-n*(n+1)//2
m = a.index(t) + a[::-1].index(t)
for k in range(1, n+2):
    print((comb(n+1, k)-comb(m, k-1))%mod)

Measured memory_bytes: 26976
#include <stdio.h>
#include <math.h>
double a,b,c;
int main(){
scanf("%lf %lf",&a,&b);
if(b<100){
c=pow(100,a)*b;
}else if(b==100){
c=101*pow(100,a);
}
printf("%d",(int)c);
return 0;
}


Measured memory_bytes: 128
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    Set<Integer> num = new HashSet<>();
    for(int i=0; i<N; i++){
      int tmp = sc.nextInt();
      if(num.contains(tmp)){
        System.out.println("NO");
        return;
      }
      num.add(tmp);
    }
    System.out.println("YES");
  }
}


Measured memory_bytes: 97836
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define dbg(x) cout<<(#x)<<"="<<x<<endl
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, a, b) for(int i=(a); i<=(b); i++)
#define DOWN(i, a, b) for(int i=(a); i>=(b); i--) 

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const double eps=1e-8;
const int INF=0x3f3f3f3f;
const ll LL_INF=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int N=1e6+10;

char s[N];
ll sum[N], sum2[N];
ll q[N], q2[N];

ll Pow(ll a, ll b) {
	ll ret=1;
	while(b) {
		if (b&1) ret=ret*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ret;
}

int main() {
	scanf("%s", s+1);
	int len=strlen(s+1);
	REP(i, 1, len) {
		if (s[i]=='A') {
			sum[i]=sum[i-1]+1;
		}
		else sum[i]=sum[i-1];
		if (s[i]=='?') {
			q[i]=q[i-1]+1;
		}
		else q[i]=q[i-1];
	}
	DOWN(i, len, 1) {
		if (s[i]=='C') {
			sum2[i]=sum2[i+1]+1;
		}
		else sum2[i]=sum2[i+1];
		if (s[i]=='?') {
			q2[i]=q2[i+1]+1;
		}
		else q2[i]=q2[i+1];
	}
	ll ans=0;
	REP(i, 1, len) {
		if (s[i]!='?'&&s[i]!='B') continue;
		ll qq=q[i-1]+q2[i+1];
		ll t=sum[i-1]*sum2[i+1]%mod*Pow(3, qq)%mod;
		ans=(ans+t)%mod;
		if (qq>=1) {
			t=(sum[i-1]*q2[i+1]%mod)*Pow(3, qq-1)%mod;
			ans=(ans+t)%mod;
		}
		if (qq>=1) {
			t=(sum2[i+1]*q[i-1]%mod)*Pow(3, qq-1)%mod;
			ans=(ans+t)%mod;
		}
		if (qq>=2) {
			t=q[i-1]*q2[i+1]%mod*Pow(3, qq-2)%mod;
			ans=(ans+t)%mod;
		}	
	}
	cout<<ans<<endl;
//	cout<<1.0*clock()<<"ms"<<endl;
	return 0;
} 

Measured memory_bytes: 11392
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int right = Math.max(a,b);
        int left = Math.min(a,b);
        if(left+w <= right){
            System.out.println(right-(left+w));
        }
        else{
            System.out.println(0);
        }
    }
}


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

const int MAXN = 10e5+5;

int n, k, arr[MAXN], dp[MAXN];

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> arr[i];
    fill(dp, dp+n, INT_MAX);
    dp[0] = 0;
    dp[1] = abs(arr[1]-arr[0]);
    for (int i = 2; i < n; i++) {
        for (int j = 1; j <= k; j++) {
            if (i-j >= 0) dp[i] = min(dp[i], dp[i-j]+abs(arr[i-j]-arr[i]));
        }
    }
    cout << dp[n-1] << "\n";
    return 0;
}


Measured memory_bytes: 4432
# -*- coding: utf-8 -*-

def readInts():
  return [int(s) for s in input().split(" ")]

def root(groups, n):
  i = n
  while groups[i] != i:
    i = groups[i]
  groups[n] = i
  return i

def union(groups, x, y):
  rx = root(groups, x)
  ry = root(groups, y)
  if rx != ry:
    groups[ry] = rx

def main():
  N, M = readInts()
  groups = [i for i in range(N)]

  for i in range(M):
    X, Y, Z = readInts()
    union(groups, X-1, Y-1)

  knowns = set()
  for n in range(N):
    knowns.add(root(groups, n))
  print(len(knowns))

if __name__ == "__main__":
  main()


Measured memory_bytes: 13224
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let n = read::<usize>();
    let a = read_vec::<u32>();

    let mut v = vec![0u32; n];
    for (i, &ai) in a.iter().enumerate() {
        v[ai as usize -1] = i as u32 + 1;
    }
    let ans = v.into_iter().map(|i| i.to_string()).collect::<Vec<String>>().join(" ");
    println!("{}", ans);
}


Measured memory_bytes: 10492
/*AOJ-ITP-3-4*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) throws NumberFormatException, IOException {
 
       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String st[] = br.readLine().split(" ");
        int count = 0;
        int a = Integer.parseInt(st[0]);
        int b = Integer.parseInt(st[1]);
        int c = Integer.parseInt(st[2]);
        
        if(!((1 <= a && 1 <= b && 1 <= c && 10000 >= a && 10000 >= b && 10000 >= c) && (a <= b))){
        	System.exit(1);
        }
        for(int i = a; i <= b; i++){
            if((c % i) == 0){
                count++;
            }
        }
        System.out.println(count);
        
    }
}

Measured memory_bytes: 24428
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <limits.h>
#include <bitset>
#include <math.h>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 1000000007;
const int INF = LLONG_MAX/3;
const int MAX = 510000;

/*-----Library-----*/

struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
    vector<int> sizeuf; //要素数
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n); sizeuf.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
            sizeuf[i]=1;
        }
    }

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

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        sizeuf[x]+=sizeuf[y];
        return true;
    }

    int size(int x){
        return sizeuf[root(x)];
    }
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}

long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

/*-----Library-----*/
int n,a,b;
int h[114514];
P max_h(){
    P re=P(h[0],0);
    for(int i=1;i<n;i++){
        if(re.first<h[i]){
            re=P(h[i],i);
        }
    }
    return re;
}

signed main(){
    int n;
    cin>>n;
    P t[10];
    for(int i=0;i<n;i++){
        cin>>t[i].first>>t[i].second;
    }
    sort(t,t+n);
    double ans=0;
    int k=0;
    do{
        k++;
        double cnt=0;
        for(int i=0;i<n-1;i++){
            cnt+=sqrt((t[i].first-t[i+1].first)*(t[i].first-t[i+1].first)+(t[i].second-t[i+1].second)*(t[i].second-t[i+1].second));
        }
        ans+=cnt;
    }while(next_permutation(t,t+n));
    cout<<setprecision(16)<<ans/k<<endl;
}



Measured memory_bytes: 256
N,K=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))
ans=[]
for i in range(N):
    score=[]
    B=[]
    count=1
    nex=P[i]-1
    point=C[nex]
    B.append(C[nex])
    score.append(point)
    while count<=K:
        if nex==i:
            break
        nex=P[nex]-1
        point+=C[nex]
        score.append(point)
        B.append(C[nex])
        count+=1
    if count==K:
        ans.append(max(score))
    else:
        if point<=0:
            ans.append(max(score))
        else:
            a=K//count
            b=K%count
            maxpoint=point*(a-1)
            for j in range(b):
                maxpoint+=B[j]
            c=maxpoint
            for j in range(count):
                if b+j<count:
                    c+=B[b+j]
                else:
                    c+=B[b+j-count]
                maxpoint=max(maxpoint,c)
            ans.append(maxpoint)
print(max(ans))

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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b; cin>>a>>b; cout << b*2-a << endl;
	return 0;
}


Measured memory_bytes: 256
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(int n);            // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;

// code
// ------------------------------------------------
int main() {

  ll a,b,c,d,e,f;
  cin >> a >> b >> c >> d >> e >> f;

  vector<long long> x,y;

  for(int i = 0; i <= 30;i++)
  for(int j = 0; j <= 30;j++)
  {
    ll sum = (i * a + j * b) * 100;
    if(sum <= f)
      x.push_back(sum);
  }

  for(int i = 0; i <= 3000;i++)
  for(int j = 0; j <= 3000;j++)
  {
    ll sum = (i * c + j * d);
    if(sum <= f)
      y.push_back(sum);
  }

  double noudo = 0;
  ll ans_x = 100 * a,ans_y = 0;

  rep(i,sz(x))
  rep(j,sz(y))
  {
    ll sum = x[i] + y[j];
    ll sug = y[j];

    if(0 < sum && sum <= f)
    {
      if(sug > (x[i] / 100) * e)continue;
      double buf = (double)sug / sum;
      if(noudo < buf)
      {
        noudo = buf;
        ans_x = sum;
        ans_y = sug;
      }
    }

  //   if(y[j] * 100 > e * x[i])continue;
  //   if(!(0 < x[i] + y[j] && x[i] + y[j] <= f))continue;
  //   double buf = (double)y[j] / (x[i] + y[j]) * 100;
  //   if(noudo < buf)
  //   {
  //     noudo = buf;
  //     ans_x = x[i];
  //     ans_y = y[j];
  //   }
  }

  cout << ans_x << " " << ans_y << endl;
  

  return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(int n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 1)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 2420
H, W = [int(x) for x in input().strip().split(" ")]

import sys
sys.setrecursionlimit(1000000)
b = []
bset = set()
wset = set()
i = 0
j = 0
for line in sys.stdin:
    b.append(line.strip())
    for s in line.strip():
        if s == "#":
            bset.add((i, j))
        else:
            wset.add((i, j))
        j += 1
    j = 0
    i += 1

fbset = set()
fwset = set()

def it_b(i, j):
    fbset.add((i, j))
    totalb = 1
    totalw = 0
    bset.remove((i, j))
    #print("b", i,j)
    if i - 1 >= 0:
        if b[i-1][j] == "." and (i-1, j) not in fwset:
            rb, rw = it_w(i-1, j)
            totalb += rb
            totalw += rw
    if j - 1 >= 0:
        if b[i][j-1] == "." and (i, j-1) not in fwset:
            rb, rw = it_w(i, j-1)
            totalb += rb
            totalw += rw
    if i + 1 <= H-1:
        if b[i+1][j] == "." and (i+1, j) not in fwset:
            rb, rw = it_w(i+1, j)
            totalb += rb
            totalw += rw
    if j + 1 <= W-1:
        if b[i][j+1] == "." and (i, j+1) not in fwset:
            rb, rw = it_w(i, j+1)
            totalb += rb
            totalw += rw
    return totalb, totalw

def it_w(i, j):
    fwset.add((i, j))
    totalb = 0
    totalw = 1
    #print("w", i,j)
    if i - 1 >= 0:
        if b[i-1][j] == "#" and (i-1, j) not in fbset:
            rb, rw = it_b(i-1, j)
            totalb += rb
            totalw += rw
    if j - 1 >= 0:
        if b[i][j-1] == "#" and (i, j-1) not in fbset:
            rb, rw = it_b(i, j-1)
            totalb += rb
            totalw += rw
    if i + 1 <= H-1:
        if b[i+1][j] == "#" and (i+1, j) not in fbset:
            rb, rw = it_b(i+1, j)
            totalb += rb
            totalw += rw
    if j + 1 <= W-1:
        if b[i][j+1] == "#" and (i, j+1) not in fbset:
            rb, rw = it_b(i, j+1)
            totalb += rb
            totalw += rw
    return totalb, totalw

t = 0
while True:
    if len(bset) == 0:
        break
    x = bset.pop()
    bset.add(x)
    rb, rw = it_b(x[0], x[1])
    t += rb * rw
print(t)


Measured memory_bytes: 164260
n = int(input())
a = [0] + list(map(int, input().split())) + [0]
lenA = n + 2
total = 0
for i in range(lenA - 1):
    total += abs(a[i] - a[i+1])

for i in range(1, lenA-1):
    print(total - abs(a[i] - a[i-1]) - abs(a[i] - a[i+1]) + abs(a[i+1] - a[i-1]))

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

int main(void){
  int i,sum=0,flg=0;
  char c,tmp[20];

  while(scanf("%c",&c) != EOF){
    if(flg){
      if(c<'0' || '9'<c){
	tmp[i] = 0;
	sum += atoi(tmp);
	flg = 0;
      }
      else{
	tmp[i++] = c;
      }
    }
    else if('0'<=c && c<='9'){
      tmp[0] = c;
      i = flg = 1;
    }
  }
  printf("%d\n",sum);

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

int main() {
    int k, a, b;
    cin >> k >> a >> b;

    if (a >= b - 1) {
        cout << 1 + k << endl;
    } else {
        long long cnt = 1;
        if (1 < a) {
            int x = min(a - 1, k);
            k -= x;
            cnt += a - 1;
        }
        {
            long long x = k / 2;
            long long d = x * (b - a);
            cnt += d;
            k %= 2;
        }
        if (k) {
            ++cnt;
        }
        cout << cnt << endl;
    }

}

Measured memory_bytes: 256
n,k=map(int, input().split())
s=list(input())
lrcnt=0
rlcnt=0
lrch=0
rlch=0
ans=0

for i in range(len(s)-1):
  if s[i]=='L' and s[i+1]=='R':
    lrcnt+=2
  if s[i]=='L' and s[i+1]=='L':
    ans+=1
  if s[i]=='R' and s[i+1]=='L':
    rlcnt+=2
  if s[i]=='R' and s[i+1]=='R':
    ans+=1
if s[0]=='R':
  lrch+=1
else:
  rlch+=1
if s[-1]=='L':
  lrch+=1
else:
  rlch+=1

if min(lrcnt,rlcnt)>=k*2:
  ans+=k*2
else:
  tmp=min(lrcnt,rlcnt)
  ans+=tmp
  k-=tmp//2
  lrcnt-=tmp
  rlcnt-=tmp

  if k>=2:
    if lrcnt>0 and rlch>0:
      ans+=1
    if rlcnt>0 and lrch>0:
      ans+=1
  else:
    if lrcnt>0 and rlch>0:
      ans+=1
    else:
      if rlcnt>0 and lrch>0:
        ans+=1
  
print(ans)

Measured memory_bytes: 4136
c1 = list(map(int, input().split()))
c2 = list(map(int, input().split()))
c3 = list(map(int, input().split()))

for a1 in range(101):
    b1 = c1[0] - a1
    b2 = c1[1] - a1
    b3 = c1[2] - a1
    
    a2 = c2[0] - b1
    a3 = c3[0] - b1
    
    if c2[1] == a2+b2 and c2[2] == a2+b3 and c3[1] == a3+b2 and c3[2] == a3+b3:
        print('Yes')
        exit()
print('No')
    

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

int main()
{
	int H, W;
	cin >> H >> W;
	vector<string> a(H);
	for (int i = 0; i < H; i++) {
		cin >> a[i];
	}
	vector<string> b(H, string(W, '.')), c(H, string(W, '.'));
	for (int i = 0; i < H; i++) {
		b[i][0] = '#';
		c[i][W - 1] = '#';
		for (int j = 1; j < W - 1; j++) {
			(i & 1 ? b[i][j] : c[i][j]) = '#';
		}
	}
	for (int i = 1; i < H - 1; i++) {
		for (int j = 1; j < W - 1; j++) if (a[i][j] == '#') {
			(i & 1 ? c[i][j] : b[i][j]) = '#';
		}
	}
	for (int i = 0; i < H; i++) {
		cout << b[i] << endl;
	}
	cout << endl;
	for (int i = 0; i < H; i++) {
		cout << c[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 1536
n=int(input())
h=list(map(int,input().split()))
s1, s2 = abs(h[1]-h[0]), 0
if n==2:
    print(s1)
else:
    score = [0] + [s1] + [0] * (n - 2)
    for i in range(2,n):
        s1= abs(h[i-1]-h[i])+score[i-1]
        s2= abs(h[i-2]-h[i])+score[i-2]
        score[i] = min(s1,s2)
    print(score[n-1])

Measured memory_bytes: 13928
n, k = map(int, input().split())
s, p, r = map(int, input().split())
t = input()

a = ["a" for i in range(k)]

ans = 0

for i in range(n):
    if t[i] == a[i%k]:
        a[i%k] = "a"
    elif t[i] == "r":
        a[i%k] = "r"
        ans += r
    elif t[i] == "s":
        a[i%k] = "s"
        ans += s
    else:
        a[i%k] = "p"
        ans += p

print(ans)

Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  ll h, w;
  cin >> h >> w;
  if (h == 1 || w == 1) cout << 1 << endl;
  else cout << h * w / 2 + ((h*w)% 2);
}

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

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

int main(){
  char step[101];
  int len;
  scanf("%s", step);
  len = strlen(step);
  
  int i;
  for(i=0; i<len; i++){
    if((i%2==0)&&(step[i] == 'L')){
        printf("No");
        return 0;
    }else if((i%2==1)&&(step[i] == 'R')){
        printf("No");
        return 0;
    }
  }
  
  printf("Yes");
  return 0;
}

Measured memory_bytes: 128
N, M = map(int, input().split())
switch_state = [None] * N
which_switch = []

for i in range(M):
    which_switch.append(list(map(int, input().split())))
    del(which_switch[i][0])

p = list(map(int, input().split()))

cnt = 0
for i in range(1<<N):
    flag = 0
    for j in range(M):
        check = 0
        for el in which_switch[j]:
            check += (1<<(el-1))
        if str(bin(i & check)).count('1') % 2 != p[j]:
            flag = 1
            break
    if flag == 1:
      continue
    cnt += 1
        
print(cnt)

Measured memory_bytes: 3064
#include <stdio.h>
//#include <string.h>
int main(void)
{
    int a,b,c;
    char buf[30];//buffering
    do{
    fgets(buf,sizeof(buf),stdin);
    sscanf(buf,"%d %d %d",&a,&b,&c);
    if (a==-1 && b==-1&c==-1)
    {
        break;
    }
    if (a==-1 || b==-1) printf("F\n");
    else if (a+b>=80) printf("A\n");
    else if (a+b>=65) printf("B\n");
    else if (a+b>=50) printf("C\n");
    else if (a+b>=30 && c<50) printf("D\n");
    else if (a+b>=30 && c>=50) printf("C\n");
    else printf("F\n");
    }while (1);
    return 0;
}



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

struct Card { char suit, value; };
using Cards = vector<Card>;


void bubbleSort(Cards& C, int N) {
  for (int i = 0; i < N; ++i) {
    for (int j = N - 1; j > i; --j) {
      if (C[j].value < C[j - 1].value) swap(C[j], C[j - 1]);
    }
  }
}

int selectionSort(Cards& C, int N) {
  for (int i = 0; i < N; ++i) {
    int minj = i;
    for (int j = i; j < N; ++j) {
      if (C[j].value < C[minj].value) minj = j;
    }
    swap(C[i], C[minj]);
  }
}

bool isStable(Cards A, Cards B) {
  for (int i = 0; i < A.size(); ++i) {
    if (A[i].suit != B[i].suit) return false;
  }
  return true;
}

void print(Cards C) {
  for (int i = 0; i < C.size(); ++i) {
    cout << ( (i) ? " " : "" );
    cout << C[i].suit << C[i].value;
  }
  cout << endl;
}

int main() {
  int N; { cin >> N; }
  Cards c1(N), c2; {
    for (int i = 0; i < N; ++i) cin >> c1[i].suit >> c1[i].value;
    c2 = c1;
  }
  bubbleSort(c1, N); {
    print(c1);
    cout << "Stable" << endl;
  }
  selectionSort(c2, N); {
    print(c2);
    cout << ( isStable(c1, c2) ? "Stable" : "Not stable" ) << endl;
  }
  return 0;
}



Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    vector<int>v(n);
    double sum=0;
    for(int i=0;i<n;i++){
        cin>>v[i];
        sum+=v[i];
    }
    double x=sum/((4*m)+0.0);
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        if(v[i]>=x)
            cnt++;
    }
    if(cnt>=m)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

}


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

int main() {
  string n;
  cin >> n;
  int n_num;
  int n_size;
  int x=0;
  n_num = stoi(n);
  n_size = n.length();
  for (int i=0;i<n_size;i++) {
     x+= n[i] - '0';
  }
  if (n_num%x == 0) {
    cout << "Yes"; 
  } else {
    cout << "No"; 
  }
  cout << endl; 
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
 
using namespace std;
 
int g[20][20];
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
 
int main(void){
 
    int n,m;
    map<char,int>dd;
    dd['N']=0;
    dd['E']=1;
    dd['S']=2;
    dd['W']=3;
 
    while(cin >> n,n){
        fill(g[0],g[20],0);
 
        for(int i=0;i<n;i++){
            int x,y;
            cin >> x >> y;
            g[y][x]=1;
        }
 
        cin >> m;
        int x=10,y=10;
        g[y][x]=0;
        for(int i=0;i<m;i++){
            char dir;
            int dis;
            cin >> dir >> dis;
            for(int k=0;k<dis;k++){
                x+=dx[dd[dir]],y+=dy[dd[dir]];
                g[y][x]=0;
            }
        }
 
        bool fg=true;
        for(int i=0;i<20;i++)
            for(int j=0;j<20;j++)
                fg&=(g[i][j]==0);
 
        if(fg)cout << "Yes" << endl;
        else cout << "No" << endl;
    }
 
    return 0;
}

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

using namespace std;

typedef long long ll;

const int N = 1e8;
const int INF = 1e9;
const int MOD = 998244353;


ll calc(string s) {
    ll ans = 0, cur = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '+') {
            ans += cur;
            cur = 0;
        }
        else
            cur = cur * 10 + (s[i] - '0');
    }
    return ans + cur;
}

int main() {
    string s;
    cin >> s;
    int n = s.size();
    ll ans = 0;
    for (int msk = 0; msk < (1 << (n - 1)); msk++) {
        string t = "";
        for (int i = 0; i < n - 1; i++) {
            t += s[i];
            if (msk & (1 << i))
                t += '+';
        }
        t += s[n - 1];
        ans += calc(t);
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int j,i,k,H[100],W[100];

	for(j=0;j<100;j++){	
		scanf("%d %d",&H[j],&W[j]);
		if(H[j]==0&&W[j]==0) break;
	}
		
	for(j=0;j<100;j++){
		if(H[j]==0&&W[j]==0) break;
		
		for(i=1;i<=H[j];i++){
			for(k=1;k<=W[j];k++){
				if(i==1||i==H[j]) printf("#");
				else if(k==1||k==W[j]) printf("#");
				else printf(".");
			}
			printf("\n");
		}
		printf("\n");
	}
	
	return 0;
}


Measured memory_bytes: 2568
#ifdef _MSC_VER
#include "stdc++.h"
#endif
#ifdef __GNUC__
#include<bits/stdc++.h>
#endif
using namespace std;

using ll = long long;

//vector
using vi = vector<int>;
using vii = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

//constant
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }

// view vector
template<typename T> void view(T e) { cout << e << endl; }
template<typename T> void view(const vector<T>& v) { for (const auto& e : v) { cout << e << " "; } cout << endl; }
template<typename T> void view(const vector<vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

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




// ***************************************

ll N, K;
vll C, P;

vector<pair<ll, ll>> score_list;


ll rec(int i, set<ll>& S) {
    ll score = 0;
    if (S.find(i) != S.end()) {
        return C[i];
    }
    S.insert(i);
    score = rec(P[i], S) + C[i];

    return score;

}

ll loop(ll start, ll n, bool must_move) {
    ll i = start;
    ll score = 0;
    ll mx = must_move ? -1e15: 0;
    REP(k, n) {
        i = P[i];
        score += C[i];
        chmax(mx, score);
    }

    return mx;
}


int main() {
    cin >> N >> K;
    C.resize(N);
    P.resize(N);
    score_list.resize(N, { -1, 0 });
    REP(i, N) cin >> P[i], P[i]--;
    REP(i, N) cin >> C[i];

    REP(i, N) {
        if (score_list[i].first != -1) continue;

        set<ll> S{ i };
        ll score = rec(P[i], S);

        for (auto s : S) {
            score_list[s] = { S.size(), score };
        }
    }

    ll mx = -1e15;
    REP(i, N) {
        auto [T, loop_score] = score_list[i];
        if (T >= K) {
            chmax(mx, loop(i, K, true));
            continue;
        }
        if (loop_score <= 0) {
            chmax(mx, loop(i, T, true));
            continue;
        }

        ll q = max<ll>(K / T - 1, 0);
        ll rem = K - q * T;
        ll score = q * loop_score + loop(i, rem, false);
        chmax(mx, score);
    }

    cout << mx << endl;

    return 0;
}


Measured memory_bytes: 4216
N = int(input())
p = list(map(int, input().split()))
cnt = 0
l = list()

for i in range(N-1):
    if p[i] > p[i+1]:
        cnt += 1
        l.append(i)

if cnt > 2:
    print('NO')
if cnt == 1:
    print('NO')
if cnt == 0:
    print('YES')
if cnt == 2:
    p[l[0]], p[l[1]+1] = p[l[1]+1], p[l[0]]
    cnt = 0
    for i in range(N-1):
        if p[i] > p[i+1]:
            cnt += 1
            l.append(i)
    if cnt == 0:
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 3064
using System;
using System.Linq;
class Program
{
	static void Main(string[] args)
	{
		// 全何種類で何種類買うか取得
		string[] input = Console.ReadLine().Split(' ');
		int n = int.Parse(input[0]);
		int k = int.Parse(input[1]);
		// 値段の入力
		int[] prices = Console.ReadLine().Split(' ')
      			.Select(int.Parse)
  				.ToArray();
      	//ソート
      	Array.Sort(prices);
      	//合計を算出
      	int sum=0;
      	for(int i=0;i<k;i++){
          sum += prices[i];
        }
		//出力
		Console.WriteLine(sum);
	}
}

Measured memory_bytes: 19472
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath> //abs();
using namespace std;

int main(void)
{
    long long int a,b,c,d,i,j,k,n,x[10];
    char C1,C2;
    string s1,s2,s3;

    cin >> s1 >> s2 >> s3;

    cout << "A" << s2.at(0) << "C";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
using namespace std;

int checkeven(char str[500] , int n){
    if( n % 2 != 0){
        return  -1;
    }

    for(int i = 0;  i < n / 2 ; i++  ){
            if(str[i] != str[(n / 2) + i]){
                return -1;
            }
    }
    return n;

}

int main()
{
   char str[200];
   cin >> str;
   int n = strlen(str);
   for(int i = 0 ; i < strlen(str) ; i++){

   n--;
   int len  = checkeven(str , n);
   if(len > 0){
    cout << len;
    return 0;
   }
   }
    return 0;
}


Measured memory_bytes: 256
import sys


def solve():
    sys.setrecursionlimit(2000)
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, input().rstrip('\n').split()))
    x = list(map(int, input().rstrip('\n').split()))
    if len(x) == 1:
        print(abs(sum(x)))
    else:
        mt = 10 ** 10
        for i in range(k-1, n):
            if x[i] * x[i-k+1] < 0:
                mt = min(mt, abs(x[i]) + abs(x[i-k+1]) + min(abs(x[i]), abs(x[i-k+1])))
            else:
                mt = min(mt, max(abs(x[i]), abs(x[i-k+1])))
        print(mt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 62576
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
//#include <map>
#include <iomanip>
#include <vector>

using namespace std;



int main()
{
	double a;
	double suretu[10];
	double s;
	
	cout << fixed << setprecision(8);
	
	while (cin >> a)
	{
		s = 0;
		
		suretu[0] = a;
		for (int i=1; i<10; i++)
		{
			if (i % 2 == 0)
			{
				//奇数番目の項
				suretu[i] = suretu[i-1] / 3;
			} else {
				//偶数番目の項
				suretu[i] = suretu[i-1] * 2;
			}
		}
		
		for (int i=0; i<10; i++) s += suretu[i];
		
		cout << s << endl;
	}
	
	return 0;
}

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

#define ll              long long
#define deb(x)          cout << #x << "=" << x << endl
#define deb2(x, y)      cout << #x << "=" << x << " , " << #y << "=" << y << endl

typedef pair<int, int>ii;
typedef pair<ll, ll>pl;
typedef vector<int>vi;
typedef vector<ll>vl;
typedef vector<ii>vii;
typedef vector<pl>vll;
typedef vector<vi>vvi;
typedef vector<vl>vvl;


const int mod = 1000000007;
const int N = 1e5+5, M = N;


void solve()
{
    ll n,m;

    ll a,b,c,d;
    scanf("%lld %lld %lld %lld",&a,&b,&c,&d);

    printf("%lld\n",max({a*c , a*d , b*c , b*d}));
}


int main()
{
    int t = 1, n, m, b, p;

    //scanf("%d",&t);

    while(t--)
    {
        solve();
    }

    return 0;
}




Measured memory_bytes: 3824
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
int frog(int n,vector<int>&dp,int a[],int ind)
{
    if(ind==n-1)
    return 0;
    if(dp[ind]!=-1)
    return dp[ind];
    int cost1=abs(a[ind]-a[ind+1])+frog(n,dp,a,ind+1);
    int cost2=INT_MAX;
    if((ind+2)<=(n-1))
    cost2=abs(a[ind]-a[ind+2])+frog(n,dp,a,ind+2);
    return dp[ind]=min(cost1,cost2);
}

int main() {
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    vector<int>dp(n+1,-1);
    cout<<frog(n,dp,a,0);
	
}

Measured memory_bytes: 13340
n,c = map(int, input().split())
color, grid = [], []
for _ in range(c):
    color.append(list(map(int, input().split())))
grid = {i:{} for i in range(3)}

for i in range(n):
    for j,t in enumerate(map(int, input().split())):
        t -= 1
        if t not in grid[(i+j + 2) % 3]:
            grid[(i+j + 2) % 3][t] = 0
        grid[(i+j + 2) % 3][t] += 1

costs = [[0 for _ in range(c)],[0 for _ in range(c)],[0 for _ in range(c)]]
for cc in range(c):
    for i in range(3):
        for d,cnt in grid[i].items():
            costs[i][cc] += color[d][cc] * cnt

x = sorted(list(range(c)), key=lambda x: costs[0][x])[:3]
y = sorted(list(range(c)), key=lambda x: costs[1][x])[:3]
z = sorted(list(range(c)), key=lambda x: costs[2][x])[:3]
mn = 10**9
for i in x:
    for j in y:
        for k in z:
            if i == j or j == k or k == i:
                continue
            if mn > costs[0][i] + costs[1][j] + costs[2][k]:
                mn = costs[0][i] + costs[1][j] + costs[2][k]
print(mn)

Measured memory_bytes: 3188