akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)

const ll MOD = 1000000007;

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}




int main(){
    int L;
    cin >> L;
    double len = (double)L/3;
    // cout << pow(len,3) << endl;;
    printf("%10.10f\n", pow(len,3));
    return 0;
}

Measured memory_bytes: 4136
#include <cstdio>
#include <vector>
#include <map>
using namespace std;

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

int X[1010], Y[1010], Z[1010], P[1010];
int main() {
    long long int A, B, C, N; scanf("%lld%lld%lld%lld", &A, &B, &C, &N);

    long long int ans = 2 * (A*B + B*C + C*A);
    map< vector<int>, int > mp;
    for(int i=0; i<N; i++) {
        vector<int> v(3);
        scanf("%d%d%d", &v[0], &v[1], &v[2]);
        mp[v]++;
        for(int k=0; k<6; k++) {
            int nx = v[0] + dx[k], ny = v[1] + dy[k], nz = v[2] + dz[k];
            vector<int> nxt{nx, ny, nz};
            if(nx < 0 || nx >= A || ny < 0 || ny >= B || nz < 0 || nz >= C || mp.count(nxt)) {
                ans--;
            }
            else {
                ans++;
            }
        }
    }
    printf("%lld\n", ans);
    return 0;
}


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

#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int, int>>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int, int>
#define int long long int
#define inf INT_MAX
#define _inf INT_MIN
#define whilet int t;cin>>t;while(t--)
const int N = 100005;

vi g[N];
vi vis(N);
vi dp(N, -1);

int dfs(int src) {	

	if (dp[src] != -1) return dp[src];
	vis[src] = true;
	int dist = 0;
	for (int child : g[src]) {
		if (vis[child]) continue;
		dist = max(dist, 1 + dfs(child));
	}
	vis[src] = false;
	return dp[src] = dist;
}

void solve() {

	int n, m;
	cin >> n >> m;

	for (int i = 1; i <= m; i++) {
		int from, to;
		cin >> from >> to;
		g[from].pb(to);
	}

	int longestPath = 0;

	for (int i = 1; i <= n; i++) {
		int cur_dist = dp[i] != -1 ? dp[i] : dp[i] = dfs(i);
		longestPath = max(longestPath, cur_dist);
	}
	cout << longestPath;
}

void init() {
	ios_base:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("../input.txt", "r", stdin);
	freopen("../output.txt", "w", stdout);
#endif
}


int32_t main()
{
	init();
	// whilet solve();
	solve();
}

Measured memory_bytes: 12368
n = int(input())
c = input()
r = 0
left, right = 0, n-1
while left < right:
    if c[left] == 'W' and c[right] == 'R':
        r += 1
        left += 1
        right -= 1
    if c[left]=='R':
        left += 1
    if c[right]=='W':
        right -= 1
print(r)

Measured memory_bytes: 9340
# https://atcoder.jp/contests/abc132/tasks/abc132_c



N = gets.to_i
ds = gets.split.map(&:to_i).sort

median = (ds[N / 2 - 1] + ds[N / 2]) / 2.to_f # N.even? # => true

minimum_median_index = ds.bsearch_index { |x| x >= median }

puts minimum_median_index == N / 2 ? ds[N / 2] - ds[N / 2 - 1] : 0


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

public class Main {

	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		System.out.println(Math.min(a * n, b));
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


Measured memory_bytes: 22228
object Main extends App {
	val pw = new java.io.PrintWriter(System.out)

	val n = Scanner.nextInt
	val a = Array.fill(n)(Scanner.nextInt)

	val m1 = a.sum - 2 * (1 until n by 2).map(a(_)).sum

	pw.println(m1)
	a.init.foldLeft(m1) { case (m, ai) =>
		pw.println(2 * ai - m)
		2 * ai - m
	}
	pw.flush()
}

object Scanner {
	private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0

	@inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
	@inline private def hasNextByte(): Boolean = if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else true
	@inline private def hasNext(): Boolean = {
		while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
		hasNextByte()
	}
	@inline private def readByte(): Byte = if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else -1

	def next(): String = {
		if(!hasNext()) ???
		val sb = new StringBuilder; var b = readByte()
		while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
		sb.toString
	}

	def nextInt(): Int = {
		val n = nextLong()
		if (n < Int.MinValue || Int.MaxValue < n) ???
		n.toInt
	}

	def nextLong(): Long = {
		if(!hasNext()) ???
		var minus = false; var b = readByte()
		if (b == '-') { minus = true; b = readByte() }

		@scala.annotation.tailrec
		def go (b: Byte, n: Long = 0): Long = if ('0' <= b && b <= '9') go(readByte(), n * 10 + b - '0') else if (minus) -n else n

		go(b)
	}

	def nextDouble(): Double = next().toDouble
}


Measured memory_bytes: 58616
import java.util.*;class Main{public static void main(String[]g){Scanner S=new Scanner(System.in);String s;for(int i,t;S.hasNext();System.out.println(s.replaceAll("0 ","").trim()))for(s="",t=S.nextInt(),i=0;i<10;)s+=(t&1<<i++)+" ";}}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

ll seq(vector<ll> &a, ll sum, int beg, ll count){
	ll prev;
	while ( beg < a.size() ){
		prev = sum;
		sum += a[beg];
		if ( (sum ^ prev) >= 0LL || sum == 0LL ){
			if ( prev > 0 ){
				count += sum + 1;
				sum = -1;
			}else{
				count += 1 - sum;
				sum = 1;
			}
		}
		beg++;
	}
	return count;
}

ll ms(vector<ll> &a, ll sign){
	ll sum = 0, count = 0;
	int i;
	for ( i = 0 ; i < a.size() ; i++ ) {
		sum += a[i];
		if ( (sign ^ sum) < 0LL || sum == 0 ){
			count += abs(sum - sign);
			sum = sign;
		}
		sign *= -1;
	}
	return count;
}

int main( int argc, char *argv[] ) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin >> n;

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

	std::cout << min(ms(a, 1), ms(a, -1)) << std::endl;
	return 0;
}


Measured memory_bytes: 1024
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var ND = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
            var N = ND[0];
            var D = ND[1];

            var count = 0;
            for (int i = 0; i < N; i++)
            {
                var XY = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
                if (XY[0] * XY[0] + XY[1] * XY[1] <= D * D) count++;
            }
            Console.WriteLine(count);
        }
    }
}


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

int main()
{
  i64 n;
  string s;
  cin >> n >> s;
  if (n % 2 == 0 && s.substr(0, n / 2) == s.substr(n / 2 , n / 2))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 384
# coding: utf-8
# Your code here!

A, B, AB, num_A, num_B = map(int, input().rstrip().split(' '))

min_cost = A * num_A + B * num_B
min_cost = min(min_cost, AB * 2 * max(num_A, num_B))
if num_A == num_B:
    min_cost = min(min_cost, AB * (num_A + num_B))
elif num_A > num_B:
    min_cost = min(min_cost, A * (num_A - num_B) + AB * 2 * num_B)
elif num_A < num_B:
    min_cost = min(min_cost, B * (num_B - num_A) + AB * 2 * num_A)
    
print(min_cost)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(){
  int N, M, ans[4], flag=0;
  cin >> N >> M;
  int s[M], c[M];
  for(int i=0; i<M; i++) cin >> s[i] >> c[i];
  for(int i=0; i<4; i++) ans[i] = 0;
  for(int i=0; i<M; i++){
    if(ans[s[i]+3-N] == 0 || ans[s[i]+3-N] == c[i]){
      ans[s[i]+3-N] = c[i];
    }else{
      flag = 1;
    }

    if(N != 1 && s[i] == 1 && c[i] == 0) flag = 1;
  }
  if(flag == 1) cout << "-1" << endl;
  else{
    for(int i=4-N; i<4; i++){
      if(i == 4-N && N != 1 && ans[i] == 0) ans[i] = 1;
      cout << ans[i];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
A,B = map(int,input().split())

def xor(n):
  ans = 0
  if n % 4 == 0:
    ans = n
  elif n % 4 == 1:
    ans = 1
  elif n % 4 == 2:
    ans = n + 1
  else:
    ans = 0
  return ans

tmp_a = xor(A-1)
tmp_b = xor(B)

print(tmp_a ^ tmp_b)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
#define int 		long long
#define vi 			vector<int>
#define vec(x) 		vector<x>
#define matrix 		vector<vector<int>>
#define pii 		pair<int,int>
#define repf(i,s,e)  for(int i=s;i<e;i++)
#define repb(i,e,s) for(int i=e;i>=s;i--)
#define MOD			1000000007
#define pb 			push_back
#define ff 			first
#define ss 			second		
#define w(x)		int x; cin>>x; while(x--)
const int INF=1e18;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::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...);
}
#else
#define trace(...)
#endif
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
// find_by_order(k-1)  returns iterator to kth element starting from 0; Returns the kth smallest element
// order_of_key(k) returns count of elements strictly smaller than k;Returns the number of elements less than k
// erase,insert same as normal set


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

	int ans=0;
	repf(i,k,n+2){
		int mn_sum=(i*(i-1))/2;
		int mx_sum=((n)*((n)+1))/2;
		mx_sum=mx_sum-((((n)-i)*((n)-i+1))/2);
		ans=(ans+(mx_sum-mn_sum+1))%MOD;
	}

	cout<<ans<<endl;
}
 
int32_t main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	if(fopen("input.txt", "r")){
	    freopen("input.txt", "r", stdin),
	    freopen("output.txt", "w", stdout);
	}
	
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define INF 2000000000000000000LL
#define EPS 1e-9
#define debug(a) cerr<<#a<<"="<<(a)<<"\n"
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL);

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

const ll mod = 998244353 ;
const double PI = acos(-1);

int n,i,j,k,t;
int a[102];
int dp[100003][2];

int solve(int num, int p){
    int &ans = dp[num][p];
    if(ans == -1){
        ans = p^1;
        for(int i=0;i<n;++i){
            if(num < a[i]) break;
            int tmp = solve(num - a[i], p^1);
            if(tmp == p)
                ans = tmp;
        }
        // cout<<num<<" "<<p<<" "<<ans<<endl;
    }
    return ans;
}

int main(){
    memset(dp, -1, sizeof dp);
    scanf("%d %d", &n, &k);
    for(i=0;i<n;++i)
        scanf("%d", a+i);
    sort(a, a+n);
    int ans = solve(k, 0);
    puts(ans?"Second":"First");
    return 0;
}

Measured memory_bytes: 8832
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, x; cin >> n >> x;
    vll s(n); REP(i, n) cin >> s[i];
    sort(ALL(s));
    vvll dp(n + 1, vll(x + 1, 0));
    REP(i, x + 1) dp[0][i] = i;
    REP(i, n) {
        REP(j, x + 1) {
            // 順番の最初に入れる場合
            dp[i + 1][j] += dp[i][j % s[i]];
            if (dp[i + 1][j] >= MOD) dp[i + 1][j] -= MOD;
            // 最初以降（つまり、余りに関係ない場合）
            dp[i + 1][j] += dp[i][j] * i % MOD;
            if (dp[i + 1][j] >= MOD) dp[i + 1][j] -= MOD;
        }
        cout << '\n';
    }

    cout << dp[n][x] << '\n';
    return 0;
}


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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    int N;
    cin >> N;
    int sz = 55556;
    vector<bool> isPrime(sz, true);
    vector<int> prime;
    isPrime[0] = isPrime[1] = false;
    REP(i, 2, sz) {
        if (isPrime[i]) {
            prime.push_back(i);
            for (int j = i * 2; j < sz; j += i) {
                isPrime[j] = false;
            }
        }
    }
    vector<int> ans;
    int pos = 0;
    for (int pos = 0; (int)ans.size() < N; pos++) {
        if (prime[pos] % 10 == 1) {
            ans.push_back(prime[pos]);
        }
    }
    REP(i, 0, N) {
        cout << ans[i] << " "[i == N - 1];
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#define M 100000
using namespace std;
  
int main(){
    int n;
    int m;
    int l;
    int pos = 0;
    int ans = 0;
    int x[M];
    scanf("%d %d",&n,&m);
    x[0] = 0;
    for (int i = 1; i < n; i++){
        scanf("%d", &x[i]);
        x[i] += x[i - 1];
    }
    while (m--){
        scanf("%d", &l);
        if(l > 0){
            ans += x[pos + l] - x[pos];
        }
        else{
            ans -= x[pos + l] - x[pos];
        }
        pos += l;
        ans %= M;
    }
    printf("%d\n", ans);
}

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

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
    double A,B,H,M;
    cin>>A>>B>>H>>M;
    double theta;

    theta = (H/12-M*11/(60*12))*2*M_PI;
    double ans;
    // cout<<cos(theta)<<"\n";
    ans = sqrt(A*A + B*B - 2*A*B*cos(theta));
    cout<<fixed<<setprecision(11)<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 4128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
 ll n,k;
 cin>>n>>k;
 ll a[n];
 for(ll i=0;i<n;i++) cin>>a[i];
 ll x=*min_element(a,a+n);
 bool dp[k+1];
 for(ll i=0;i<=x;i++) dp[i]=0;
 for(ll i=x;i<=k;i++){
  dp[i]=0;
  for(ll j=0;j<n;j++){
   if(i>=a[j]) dp[i]=(dp[i]||!dp[i-a[j]]);
  }
 }
 if(dp[k]) cout<<"First"<<endl;
 else cout<<"Second"<<endl;
 return 0;
}

Measured memory_bytes: 384
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let H: u64 = read();
    let W: u64 = read();
    if H == 1 || W == 1 {
        println!("1");
    } else {
        println!("{}", (H * W + 1) / 2);
    }
}


Measured memory_bytes: 4352
#import sys
#import numpy as np
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
a,b,c=map(int,input().split())
if b//a<c:
  print(b//a)
else:
  print(c)

Measured memory_bytes: 65028
#include <cstdio>
 #include <cstdlib>
 #include <iostream>
 #include <fstream>
 #include <sstream>
 #include <set>
 #include <map>
 #include <vector>
 #include <list>
 #include <algorithm>
 #include <cstring>
 #include <cmath>
 #include <string>
 #include <queue>
 #include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
 #include <cassert>
 #include <iomanip>        //do setprecision
 #include <ctime>
 #include <complex>
 using namespace std;

 #define FOR(i,b,e) for(int i=(b);i<(e);++i)
 #define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
 #define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
 #define REP(x, n) for(int x = 0; x < (n); ++x)

 #define ST first
 #define ND second
 #define PB push_back
 #define PF push_front
 #define MP make_pair
 #define LL long long
 #define ULL unsigned LL
 #define LD long double
 #define pii pair<int,int>
 #define pll pair<LL,LL>

 const double pi = 3.14159265358979323846264;
 const int mod=1000000007;

int main(){
	int n;
	cin>>n;
	if(n==1){
		cout<<"Yes"<<endl;
		cout<<2<<endl;
		cout<<1<<" "<<1<<endl;
		cout<<1<<" "<<1<<endl;
		return 0;
	}
	int mx=1;
	FOR(ii,2,n){
		mx+=ii;
		if(mx>n){
			//cerr<<"over:"<<ii<<" "<<mx<<" bf:"<<mx-ii<<endl;
			break;
		}
		if(n==mx){
			int s=ii;
			int k=ii+1;
			vector<vector<int>> ans=vector<vector<int>>(k+1,vector<int>(k+1,0));
			FOR(j,0,s)ans[0][j]=j+1;
			int lst=s;
			FORQ(i,1,k){
				ans[i][0]=i;
				FOR(j,1,i){
					ans[i][j]=ans[j][i-1];
				}
				FOR(j,i,s){
					lst++;
					ans[i][j]=lst;
				}
			}

			cout<<"Yes"<<endl;
			cout<<k<<endl;
			FOR(i,0,k){
				cout<<s;
				FOR(j,0,s){
					cout<<" "<<ans[i][j];
				}
				cout<<endl;
			}
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 2176
/**************************************
 * Au: Hany01
 * Email: hany01@foxmail.com
**************************************/

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define File(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout)
#define rep(i, j) for (register int i = 0, i##_end_ = j; i < i##_end_; ++ i)
#define For(i, j ,k) for (register int i = (j), i##_end_ = (k); i <= i##_end_; ++ i)
#define Fordown(i, j, k) for (register int i = (j), i##_end_ = (k); i >= i##_end_; -- i)
#define Set(a, b) memset(a, b, sizeof(a))
#define SZ(a) ((int)(a.size()))
#define ALL(a) a.begin(), a.end()
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define INF (0x3f3f3f3f)
#define INF1 (2139062143)
#define Mod (1000000007)
#define y1 wozenmezhemecaia 
#ifdef hany01
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }

inline int read() {
    register char c_; register int _, __;
    for (_ = 0, __ = 1, c_ = getchar(); !isdigit(c_); c_ = getchar()) if (c_ == '-')  __ = -1;
    for ( ; isdigit(c_); c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
    return _ * __;
}

const int maxn = 100005, maxm = 200005;

int n, m, p[maxn], uu, vv, v[maxm], e, nex[maxm], beg[maxn], lst[maxn], Ans, cnt, vis[maxn], A[maxn], B[maxn];

inline void add(int uu, int vv) { v[++ e] = vv, nex[e] = beg[uu], beg[uu] = e; }

void dfs(int u)
{
    vis[u] = 1, lst[++ cnt] = u;
    for (register int i = beg[u]; i; i = nex[i])
        if (!vis[v[i]]) dfs(v[i]);
}

int main()
{
#ifdef hany01
    File("d");
#endif

    n = read(), m = read();
    For(i, 1, n) p[i] = read();
    For(i, 1, m) uu = read(), vv = read(), add(uu, vv), add(vv, uu);
    
    For(i, 1, n)
    {
        if (!vis[i])
        {
            cnt = 0;
            dfs(i);
            For(j, 1, cnt) ++ A[lst[j]], ++ B[p[lst[j]]];
            For(j, 1, cnt) if (B[lst[j]]) ++ Ans;
            For(j, 1, cnt) A[lst[j]] = 0, B[p[lst[j]]] = 0;
        }
    }
    printf("%d\n", Ans);

    return 0;
}


Measured memory_bytes: 5120
#pragma warning(disable:4996)
#include "bits/stdc++.h"
using namespace std;

//template
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) REP(i,0,n)
using ll = long long;
using ull = unsigned long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
#define all(a) (a).begin(),(a).end()
template<typename A, typename T>
void assign2d(A&arr, ll H, ll W, T t) {
	arr.resize(H);
	for (ll i = 0; i < H; i++) {
		arr[i].assign(W, t);
	}
}
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n)os << v[i] << (i == n - 1 ? "" : " "); return os; }

//pair
using P = pair<ll, ll>;
#define mp make_pair


int main() {
	string s1, s2;
	cin >> s1 >> s2;
	reverse(all(s2));
	if (s1 == s2) {
		cout << "YES\n";
	}
	else {
		cout << "NO\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
const int N = 2e5+7;
char sss[N];
ll f[2][3007];
int main()
{
	scanf("%s",sss + 1);
	int n = strlen(sss + 1);
	ll res = 0;
	for(int i = 1;i <= n;++i)
	{
		int cur = sss[i] - '0';
		for(int k = 0;k <= 2019;++k)
		{
			f[1][(k * 10 + cur) % 2019] += f[0][k];
		}
		++f[1][cur];
        for(int k = 0;k <= 2019;++k)
        {
            f[0][k] = f[1][k];
            f[1][k] = 0;
        }
        res += f[0][0];
	}
	printf("%lld",res);
    return 0;
}


Measured memory_bytes: 4044
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;
#define NIL NULL

void inorder(Node);
void prerder(Node);
void insert(int);
Node treeSearch(Node, int);
Node treeMinimum(Node);
Node treeSuccessor(Node);
void treeDelete(Node);

Node root = NIL;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while( x != NIL ){
    y = x;
    if( z->key < x->key ) x = x->left;
    else x = x->right;
  }

  z->parent = y;
  if( y == NIL ){
    root = z;
  }
  else if( z->key < y->key ){
    y->left = z;
  }
  else y->right = z;
}

void inorder(Node u){
  if( u->left != NIL ){
    inorder(u->left);
  }
  printf(" %d",u->key);
  if( u->right != NIL ){
    inorder(u->right);
  }
}

void preorder(Node u){
  printf(" %d",u->key);
  if( u->left != NIL ){
    preorder(u->left);
  }
  if( u->right != NIL ){
    preorder(u->right);
  }
}

Node treeSearch(Node u, int k){
  while( u != NIL && k != u->key ){
    if( k < u->key ) u = u->left;
    else u = u->right;
  }
  return u;
}

Node treeMinimum(Node x){
  while( x->left != NIL )x = x->left;
  return x;
}

Node treeSuccessor(Node x){
  Node y;
  if ( x->right != NIL ) return treeMinimum(x->right);
  y = x->parent;
  while( y != NIL && x == y->right ){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if( z->left == NIL || z->right == NIL ) y = z;
  else y = treeSuccessor(z);

  if( y->left != NIL ) x = y->left;
  else x = y->right;

  if( x != NIL ) x->parent = y->parent;
  if( y->parent == NIL ) root = x;
  else if( y == y->parent->left ) y->parent->left = x;
  else y->parent->right = x;

  if( y != z ) z->key = y->key;

}

int main(void){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d",&x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    }

    else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }
    
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 

    else if ( com[0] == 'd' ){
      scanf("%d",&x);
      treeDelete(treeSearch(root, x));
    }
  }
  return 0;
}

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

int main(){
    int D;
    cin >> D;

    if(D == 25){
        cout << "Christmas" << endl;
    }else if(D == 24){
        cout << "Christmas Eve" << endl;
    }else if(D == 23){
        cout << "Christmas Eve Eve" << endl;
    }else if(D == 22){
        cout << "Christmas Eve Eve Eve" << endl;
    }
}

Measured memory_bytes: 256
s=input()+'TE'
x,y=list(map(int,input().split()))

ini = s.find('T')
s=s[ini+1:]

is_y=1
point=[set([ini]),set([0])]

while len(s)>1:
    tmp=s.find('T')
    if tmp != 0:
        set_=set()
        for z in point[is_y]:
            set_.add(z+tmp)
            set_.add(z-tmp)
        point[is_y]=set_
    is_y+=1
    is_y%=2
    s=s[tmp+1:]

if x in point[0] and y in point[1]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3924
/*In the name of Allah*/
#include <bits/stdc++.h>
using namespace std;
#define inf 1000000001
#define MAX 200005
#define mod 1000000007
#define ll long long
#define fr first
#define sc second


int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	string s;
	cin>>s;
	vector<int> v;
	int ans= 0,cnt = 1;
	for(int i = 1 ; i < s.size(); i++){
		if(s[i] == s[i-1])cnt++;
		else {
			v.push_back(cnt);
			cnt = 1;
		}
	}
	if(cnt)v.push_back(cnt);
	int cur = 0;
	for(auto i : v){
		cur += i;
		if(cur % 3 == 0 || cur % 3 == 1)ans += 2*(cur / 3) + (cur % 3 == 1) ,cur = 0;
	}
	if(cur)ans += 2*(cur/3) + 1;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1680
package main

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

func main() {
	var sc = bufio.NewScanner(os.Stdin)
	var n, r, min int
	max := math.MinInt32
	sc.Scan();
	n, _ = strconv.Atoi(sc.Text())
	sc.Scan();
	min, _ = strconv.Atoi(sc.Text())
	for i := 1; i<n; i++ {
		sc.Scan();
		r, _ = strconv.Atoi(sc.Text())
		a := r-min
		if a > max { max = a }
		if r < min { min = r }
	}
	fmt.Printf("%d\n", max)
}




Measured memory_bytes: 4092
import java.util.*;
import java.io.*;
public class Main{
/// functions
static long gcd(long a,long b){if(b==0){return a;}return gcd(b,a%b);}
static long Modpow(long a,long p,long m){if(p==1){return a;}long x=Modpow(a,p/2,m);x=(x*x)%m;return (p&1l)!=0? (x*a)%m:x;}
static long Modmul(long a,long b,long m){return ((a%m)*(b%m))%m;}
static long ModInv(long a,long m){return Modpow(a,m-2,m);}
static long nck(int n,int r,long m){if(r>n){return 0l;}return Modmul(f[n],ModInv(Modmul(f[n-r],f[r],m),m),m);}
// end
static long[] f;

public static void main(String[] args) throws FileNotFoundException, IOException{
       Scanner s=new Scanner(System.in);
       StringBuilder sb=new StringBuilder();
       StringBuilder sb1=new StringBuilder();
       BufferedWriter out=new BufferedWriter(new OutputStreamWriter(System.out));
       int n=s.nextInt(),m=s.nextInt();
       for(int i=0;i<m;i++){sb.append(n);}
       	for(int i=0;i<n;i++){sb1.append(m);}
         String s1=sb.toString();
         String s2=sb1.toString();
         s1=s1.compareTo(s2)>0?s2:s1;
        out.write(s1+"");
       out.flush();

      /* long res=0;
       String m=Integer.toString(n);
       int k=m.length();
       for(int i=11;i<=n;i++){
       	if(i%10==0){continue;}
       	String ss=Integer.toString(i);
       	int l=ss.length();
       	long tmp=0;
       	if((ss.charAt(l-1)-'0'<=m.charAt(0)-'0')&&(ss.charAt(0)-'0'<=m.charAt(k-1)-'0')){
       		 tmp++;
       		 long tmp1=0;
       		 if((ss.charAt(l-1)==ss.charAt(0))&&l>1){tmp1++;}
       		for(int j=1;j<k-1;j++){
       			int xx=m.charAt(j)-'0';
       			tmp=(long)tmp*xx;
       		}
       		 tmp+=tmp1;
       		res+=tmp;
       	}
       	//out.write(i+" "+tmp+"\n");
       }
       res+=Math.min(9,n);
       for(int i=1;i<=Math.min(9,n);i++){
       		String ss=Integer.toString(i);
       	int l=ss.length();
       	long tmp=0;
       	if((ss.charAt(l-1)-'0'<=m.charAt(0)-'0')&&(ss.charAt(0)-'0'<=m.charAt(k-1)-'0')){
       		tmp++;
              for(int j=1;j<k-1;j++){
       			int xx=m.charAt(j)-'0';
       			tmp=(long)tmp*xx;
       		}
       	}
       	   res+=tmp;
       }
       out.write(res+"");
        out.flush();*/
  }
}


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

#include<vector>

namespace Union_find {

  class union_find {
    int n;
    std::vector<int> par;
    std::vector<int> rank;
    std::vector<int> _size;
  public:
    union_find(int _n);
    int find(int x);
    void unite(int x, int y);
    bool same(int x, int y) { return find(x) == find(y); }
    int size(int i){int p=find(i);return _size[p];}
  };

  union_find::union_find(int _n) :n(_n), par(_n), rank(_n, 1),_size(_n,1) {
    for (int i = 0; i < n; i++) {
      par[i] = i;
    }
  };

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

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

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

    return;
  }
}

using namespace Union_find;
int main(){
  int n,m;
  cin>>n>>m;
  union_find connect(n);
  union_find dual(n*2);
  for(int i=0;i<m;i++){
    int u,v;
    cin>>u>>v;
    u--,v--;
    connect.unite(u,v);
    dual.unite(u,v+n);
    dual.unite(v,u+n);
  }

  vector<int> checked(n,0);
  long long int iso=0;
  long long int duo=0;
  long long int non=0;
  for(int i=0;i<n;i++){
    int index=connect.find(i);
    if(checked[index]) continue;
    checked[index]=true;
    
    if(connect.size(index)==1) iso++;
    else if(dual.same(index,index+n)) non++;
    else duo++;
  }
  long long int res=iso*(n-iso)*2+iso*iso;
  res+=non*duo*2+non*non;
  res+=duo*duo*2;
  cout<<res<<endl;

}


Measured memory_bytes: 4224
#include<stdio.h>
int main(){
    int a, b, i;
    while(1){
        scanf("%d %d", &a, &b);
        if(a == 0 && b == 0) break;
        while(a--){
            for(i=0;i<b;i++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
return 0;
}



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

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

if n == 1:
    if m == 1:
        ans = 1
    else:
        ans = m-2
else:
    if m == 1:
        ans = n-2
    else:
        ans = (n-2)*(m-2)

print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<sstream>
#include<ios>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<string>
#include<numeric>
#include<set>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using vi = vector<int>;
using vl = vector<long>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
using vpii = vector<pii>;
using vpll = vector<pll>;

int main(){
  long N;
  cin >> N;

  if(N % 2 == 1){
    cout << 0 << endl;
  } else{
    long cnt = 0;
    N = N / 2;

    while(N != 0){
      cnt += N / 5;
      N = N / 5;
    }

    cout << cnt << endl;
  }
  
  return 0;
}

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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int h = sc.NextInt();
        int w = sc.NextInt();

        int[,] map = new int[w, h];
        int block = 0;
        for (int i = 0; i < h; i++)
        {
            string str = sc.Next();
            for (int j = 0; j < w; j++)
            {
                if(str[j] == '#')
                {
                    block++;
                    map[j, i] = -1;
                } else
                {
                    map[j, i] = 0;
                }
            }
        }

        Queue<Tuple<int, int, int>> queue = new Queue<Tuple<int, int, int>>();
        queue.Enqueue(Tuple.Create(0, 0, 1));

        while (queue.Count > 0)
        {
            Tuple<int, int, int> item = queue.Dequeue();

            if (map[item.Item1, item.Item2] > 0)
            {
                continue;
            }

            map[item.Item1, item.Item2] = item.Item3;

            int[] hor = new int[] { -1, 1, 0, 0 };
            int[] ver = new int[] { 0, 0, -1, 1 };

            for (int i = 0; i < 4; i++)
            {
                int newX = item.Item1 + hor[i];
                int newY = item.Item2 + ver[i];
                if (newX < 0 || newX >= w || newY < 0 || newY >= h)
                {
                    continue;
                }
                if (map[newX, newY] == -1)
                {
                    continue;
                }
                queue.Enqueue(Tuple.Create(newX, newY, item.Item3 + 1));
            }
        }

        if(map[w -1, h -1] == 0)
        {
            Console.WriteLine(-1);
            return;
        }

        int answer = w * h - block - map[w-1,h-1];

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 11348
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        // Scanner scan = new Scanner(System.in);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        int n = Integer.parseInt(bf.readLine());
        StringTokenizer st = new StringTokenizer(bf.readLine());
        int[] a = new int[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());
        for(int i=0; i<n; i++) a[i] -= (i+1);
        long sum = 0;
        Arrays.sort(a);
        int median = a[n/2];
        long test1 = 0;
        for(int i=0; i<n; i++) {
          test1 += Math.abs(0L + a[i] - median);
        }
        out.println(test1);
        // int n = Integer.parseInt(st.nextToken());
        // int n = scan.nextInt();

        out.close(); System.exit(0);
    }
}


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

using namespace std;

typedef long long ll;

ll dp[110][100100];

const ll inf = 1LL << 60;

int main(){
  ll N,W; cin >> N >> W;
  vector<ll> w(N); vector<ll> v(N);
  ll Max_V = 0;
  for(ll i = 0; i < N; i++){
    cin >> w[i] >> v[i]; Max_V += v[i];}
  
  for(ll i = 0; i < 110; i++){
    for(ll j = 0; j < 100100; j++){
      dp[i][j] = inf;}}
  
  dp[0][0] = 0;
                                     
  for(ll i = 0; i < N; i++){
    for(ll sum_v = 0; sum_v <= Max_V; sum_v++){
      if( sum_v >= v[i]){
        dp[i+1][sum_v] = min( dp[i+1][sum_v], dp[i][sum_v - v[i]] + w[i]);}
        dp[i+1][sum_v] = min( dp[i+1][sum_v], dp[i][sum_v]);}}
  
  for(ll sum_v = Max_V; sum_v >= 0; sum_v--){
    if( dp[N][sum_v] <= W){ cout << sum_v << endl; return 0;}} }


Measured memory_bytes: 86272
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  string S, memo; // 直前に取り出した文字列
  cin >> S;
  memo = S.substr(0, 1);
  int ans = 1;
  for (int i=1; i<S.size(); i++) {
    string sub = S.substr(i, 1);
    if (sub==memo&&i<S.size()-1) {
      memo = S.substr(i, 2);
      ans++;
      i++;
    }
    else if (sub==memo&&i==S.size()-1) break;
    else {
      memo = S.substr(i, 1);
      ans++;
    }
  }
  cout << ans << endl;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e5 + 5);

int n;
ll h;

ll a[MAX_N];

vector<pair<ll, int>> b_ind;

int main(void) {
  // Here your code !
  scanf("%d %lld", &n, &h);

  for (int i = 0; i < n; ++i) {
    ll b;
    scanf("%lld %lld", &(a[i]), &b);
    b_ind.push_back(make_pair(b, i));
  }

  ll max_a = -1LL;

  for (int i = 0; i < n; ++i) {
    max_a = max(max_a, a[i]);
  }

  sort(b_ind.begin(), b_ind.end(), greater<pair<ll, int>>());

  ll cnt = 0LL;
  ll dmg = 0LL;

  for (auto &e : b_ind) {
    ll score = e.first;
    int ind = e.second;

    if (score <= max_a) break;

    cnt += 1LL;

    dmg += score;

    if (dmg >= h) {
      ll ans = cnt;
      printf("%lld\n", cnt);
      return 0;
    }
  }

  ll remain = h - dmg;

  cnt += (remain - 1LL + max_a) / max_a;

  ll ans = cnt;

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 2932
n = int(input())
a = [0]*(n+1)
for i in range(1, n+1):
    a[i] = int(input())

index = 1
ret = 1
for i in range(n):
    next = a[index]
    if next == 2:
        break
    if next == -1:
        ret = -1
        break
    ret += 1
    a[index] = -1
    index = next

print(ret)

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

int main(){
	int n,m;
  	cin >> n;
  	vector<string> s(n);
  	for (int i=0;i<n ;i++) cin >> s[i];
  	cin >> m;
  	vector<string> t(m);
  	for (int i=0;i<m ;i++) cin >> t[i];
  	vector<int> k(n,1);
  	for (int i=0;i<n ;i++){
      	for (int j=i+1;j<n;j++){
  		if (s[i]==s[j]) k[i]++;
        }
      	for (int j=0;j<m;j++){
  		if (s[i]==t[j]) k[i]--;
        }
    }
  	for (int i=0;i<n ;i++){
      	if (k[i]>=k[i+1]) k[i+1]=k[i];
    }
  	if (k[n-1]>0) cout << k[n-1] << endl;
  	else cout << 0 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <map>
#include <utility>
#include <numeric>
#define ll long long
#define REP(i, x) for(int (i) = 0; (i) < (x); (i) ++)
#define pi 3.1415926535
const int MOD = 1000000007;
using namespace std;

int main() {
	int n;
	cin >> n;
	int a[4];
	REP(i, 4) {
		int b = pow(10, 3 - i);
		a[i] = n / b;
		n %= b;
	}
	REP(i, 2) {
		int ans[4];
		ans[0] = a[0];
		char s[3];
		if (i % 2 == 0) {
			ans[1] = a[1] + a[0];
			s[0] = '+';
		}
		else {
			ans[1] = a[0] - a[1];
			s[0] = '-';
		}
		REP(j, 2) {
			if (j % 2 == 0) {
				ans[2] = ans[1] + a[2];
				s[1] = '+';
			}
			else {
				ans[2] = ans[1] - a[2];
				s[1] = '-';
			}
			REP(k, 2) {
				if (k % 2 == 0) {
					ans[3] = ans[2] + a[3];
					s[2] = '+';
				}
				else {
					ans[3] = ans[2] - a[3];
					s[2] = '-';
				}
				if (ans[3] == 7) {
					cout << a[0] << s[0] << a[1] << s[1] << a[2] << s[2] << a[3] << "=7" << endl;
					return 0;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int gcd(int a, int b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}
int main(){
	int k;
	cin >> k;
	int ans = 0;
	for (int i = 1; i <= k; i++) {
		for (int j = 1; j <= k; j++) {
			for (int l = 1; l <= k; l++) {
				ans += gcd(gcd(i, j), l);
			}
		
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
  string S;
  cin >> S;
  int N = (S.size() + (2 - 1)) / 2;
  int cnt = 0;
  for (int i = 0; i < N; i++)
  {
    if (S[i] != S[S.size() - 1 - i])
      cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
import sys

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))

m = sum(A) / N

res = 10 ** 9
cost = 10 ** 9
for i, a in enumerate(A):
    if abs(a - m) < cost:
        res = i
        cost = abs(a - m)

print(res)


Measured memory_bytes: 9168
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>

#define X first
#define Y second
#define dis(a, b) (b.X - a) * (b.X - a) + (b.Y - a) * (b.Y - a)

using namespace std;

double cross(pair<double, double> lineA, pair<double, double> lineB){
	return (lineA.X * lineB.Y - lineB.X * lineA.Y) / sqrt(dis(0, lineB));
}

int main(){
	pair<double, double> pointA, pointB, pointC, pointD;
	while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &pointA.X, &pointA.Y, &pointB.X, &pointB.Y, &pointC.X, &pointC.Y, &pointD.X, &pointD.Y) != EOF){
		vector<pair<double, double> > point;
		point.push_back(pointA);
		point.push_back(pointB);
		point.push_back(pointC);
		point.push_back(pointD);
		int count = 0;
		for(int i = 0; i < point.size(); i++){
			pair<double, double> lineA(point[(i + 1) % 4].X - point[i].X, point[(i + 1) % 4].Y - point[i].Y); 
			pair<double, double> lineB(point[(i + 2) % 4].X - point[i].X, point[(i + 2) % 4].Y - point[i].Y);
			cross(lineA, lineB) > 0 ? count++ : count--;
		}

		cout << (count == 4 || count == -4 ? "YES" : "NO") << endl;
	}
	return 0;
}

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

int main() {
int A=2;
int B=1;
int C=1;
int K=3;
int osszeg=0;
cin >> A;
cin >> B;
cin >> C;
cin >> K;
for (int i=0;i<K;i++){
  if(K<=2*10000000000){
    if(A>0){
    osszeg+=1;
    A-=1;
  }
  else if(B>0){
    B-=1;
  }
  else if(C>0){
    osszeg-=1;
    C-=1;
  }
  }
  else{
    cout << "The K is too big!";
  }
}
cout << osszeg;
	return 0;
}



Measured memory_bytes: 3624
import java.util.*;

public class Main {
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        int n,k,q;
        n = sc.nextInt();
        k = sc.nextInt();
        q = sc.nextInt();
        
        ArrayList<Integer> score_list = new ArrayList<Integer>();
        
        for(int i = 0; i < n; i++){
            score_list.add(k-q);
        }
        
        for(int j = 0; j < q; j++){
            int answer = sc.nextInt();
            score_list.set(answer - 1, score_list.get(answer - 1) + 1);
        }
        
        for(int x = 0; x < score_list.size(); x++){
            if(score_list.get(x) <= 0){
                System.out.println("No");
            }else{
                System.out.println("Yes");
            }
        }
        
        
    }
}


Measured memory_bytes: 65968
class Node:
    def __init__(self,v):
        self.v = v
        self.next = None


class Stack:
    def __init__(self):
        self.head = None
    def push(self,v):
        n = Node(v)
        n.next = self.head
        self.head = n
    def pop(self):
        if self.head == None:
            return None
        n = self.head
        self.head = self.head.next
        return n.v

ops = raw_input().split(' ')

s = Stack()
for op in ops:
    if op == '+':
        a = s.pop()
        b = s.pop()
        s.push(a+b)
    elif op == '-':
        a = s.pop()
        b = s.pop()
        s.push(b-a)
    elif op == '*':
        a = s.pop()
        b = s.pop()
        s.push(a*b)
    else:
        num = int(op)
        s.push(num)

print s.pop()

Measured memory_bytes: 6408
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   //setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  //sin, cos, tan

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

void Main()
{
  str n; cin >> n;
  ll ans = 0;
  rep(i, n.size())
  {
    ans += n[i] - 48;
  }
  fin((ans%9==0)?"Yes":"No");
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(4); //高精度少数表示
  Main();
  return 0;
}


Measured memory_bytes: 3976
#include <bits/stdc++.h>
#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(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

 ll n,m;cin>>n>>m;
 string s,t;cin>>s>>t;
 ll len = n*m / GCD(n,m);
 map<ll,char> ma;
 REP(i,n){
  ma[len/n * i + 1] = s[i];
 }
 REP(i,m){
  if(ma.count(len/m * i + 1)&&ma
    [len/m * i + 1]!=t[i]){
    cout<<-1<<endl;
    return 0;
  }
 }
 cout<<len<<endl;

  return 0;
}

Measured memory_bytes: 6144