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

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

#define mem(a, b) memset(a, b, sizeof(a))
#define MOD 1000000007
#define MAX (int) 1e9
#define PI 3.141592653589793238462643383279502884

template <typename T, typename U>
T max(T x, U y) {
    return x > y ? x : y;
}

template <typename T, typename U>
T min(T x, U y) {
    return x < y ? x : y;
}

template<typename T>
void debug(string msg, T t) {
	cout << msg << ": " << t << "\n";
}

template<typename T>
T abs(T a, T b) {
	return a > b ? a - b : b - a;
}

inline int toDigit(char c) { return c - '0'; }

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0); 

	long double a, b, h, m;
	cin >> a >> b >> h >> m;
	long double d2;

	d2 = a * a + b * b - 2.0 * a * b * cos(PI * (h / 6.0 + (m / 360.0) - m / 30.0));

	cout << fixed;
	cout << setprecision(20);
	cout << sqrtl(d2) << "\n";
	

	return 0;
}

Measured memory_bytes: 4192
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
 
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);
}
 
/*------------------------------------------------------------------*/
 
int main(){
    int n; cin >> n;
    for(int i = 1; i <= 50000; i++){
        if(int(i * 1.08) == n){
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;
}


Measured memory_bytes: 256
t_hp, t_atk, a_hp, a_atk = [int(i) for i in input().split()]

while t_hp > 0 and a_hp > 0 :
  a_hp -= t_atk
  if a_hp <= 0 :
    break
  t_hp -= a_atk
if t_hp <= 0 :
  print('No')
else :
  print('Yes')

Measured memory_bytes: 61592
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;

const ll MOD = (ll)(1e9 + 7);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(50) << setiosflags(ios::fixed);

  int n;
  cin >> n;

  struct vec
  {
    ld x, y;
  };

  vector<vec> v;
  rep(i, n)
  {
    ld xi, yi;
    cin >> xi >> yi;
    if (xi == 0.0 && yi == 0.0)
      n--, i--;
    else
      v.push_back({xi, yi});
  }

  auto comp = [](vec &v1, vec &v2) {
    return atan2(v1.y, v1.x) < atan2(v2.y, v2.x);
  };

  sort(all(v), comp);
  rep(i, n) cerr << v[i].x << " " << v[i].y << endl;
  cerr << endl;

  rep(i, n) v.push_back(v[i]);
  ld Max = 0.0;
  for (int choose = 1; choose <= n; ++choose)
  {
    rep(start, n)
    {
      ld x_sum = 0.0, y_sum = 0.0;
      for (int i = start; i < start + choose; ++i)
      {
        x_sum += v[i].x;
        y_sum += v[i].y;
      }
      Max = max(Max, sqrt(x_sum * x_sum + y_sum * y_sum));
    }
  }
  cout << Max << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>

#include <iostream>
#include <vector>

using namespace std;
namespace mp = boost::multiprecision;
typedef long long ll;

const ll M = 1000000007;

vector<ll> fac(1000000); //n!(mod M)
vector<ll> ifac(1000000); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}

int main()
{
    ll n,k;

    ll x=1;
	ll y=1;
	cin >> x >> y;

	ll q = (x + y) / 3;
	ll r = (x + y) % 3;

	if (r == 0 && q <= x && x <= 2*q && q <= y && y <= 2*q && x <= 1000000 && y <= 1000000) {
		k = x - q;
		n = q;

	    //大した量ではないので，先にfax[i]とifax[i]を全て計算しておく
	    fac[0] = 1;
	    ifac[0] = 1;
	    for(ll i = 0; i<1000000; i++){
	        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
	        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
	    }

	    ll ans=0;
	    ans = comb(n, k)%M;
	    cout << ans;
	    return 0;
	}

	cout << 0;

	return 0;
}

Measured memory_bytes: 16504
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

ll l[9];
ll n,A,B,C;

int dfs(ll a,ll b,ll c,ll d){
  if(d == n){
    if(a==0 || b==0 || c==0){
      return 1000000000;
    }
    else{
      return abs(A-a)+abs(B-b)+abs(C-c)-30;
    }
  }
  ll MP1 = dfs(a,b,c,d+1);
  ll MP2 = dfs(a+l[d],b,c,d+1)+10;
  ll MP3 = dfs(a,b+l[d],c,d+1)+10;
  ll MP4 = dfs(a,b,c+l[d],d+1)+10;
  return min(min(MP1,MP2),min(MP3,MP4));
}

int main(){
  cin >> n >> A >> B >> C;
  for(ll i=0;i<n;i++){
    cin >> l[i];
  }
  cout << dfs(0,0,0,0) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main 
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		String str = scanner.next();
		int p = scanner.nextInt();
		
		for(int i=0; i<p; i++)
		{		
			String in = scanner.next();
			int n = scanner.nextInt();
			int m= scanner.nextInt();
			String s = "";
			
			switch (in)
			{
				case "print":
					System.out.println(str.substring(n, m+1));
					break;
				case "reverse":
					s = str.substring(n, m+1);
					String t="";
					for(int j=s.length(); j>0; j--)
					{
						t += s.substring(j-1, j);
					}
					
					s = "";
					for(int j=0; j<str.length(); j++)
					{
						if(n<=j && j<=m)
						{
							 s += t.substring(j-n, j-n+1);
						}
						else
						{
							s += str.substring(j, j+1);
						}
					}
					str = s;
					break;
				case "replace":
					s = "";
					String rep = scanner.next();
					for(int j=0; j<str.length(); j++)
					{
						if(n<=j && j<=m)
						{
							 s += rep.substring(j-n, j-n+1);
						}
						else
						{
							s += str.substring(j, j+1);
						}
					}
					str = s;
					break;
			}
		}
	}
}

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

#define mp make_pair
#define fst first
#define snd second

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef pair<i64,int> pli;
typedef pair<int,i64> pil;
typedef pair<i64,i64> pll;
typedef vector<int> vi;
typedef vector<i64> vl;

template <typename T>
T id(T b) {return b;};
template <class It>
bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It>
bool any(It f,It l){return std::any_of(f,l,id<bool>);}

int cnt[5] = {};

int main()
{
  int a,b;
  for (int i = 0; i < 3; i++) {
    cin >> a >> b;
    cnt[a]++;
    cnt[b]++;
  }

  for (int i = 1; i <= 4; i++) {
    if (cnt[i] > 2) {
      cout << "NO" << endl;
      return 0;
    }
  }

  cout << "YES" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1000000007
//S.size()

using namespace std;


typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<bool> VB;
typedef unsigned long long ll;



int main(void){
  int A,B,K;cin>>A>>B>>K;
  int a[B - A + 1];
  for(int i = 0;i <= K - 1;i++){

    if(A + i <= B)cout<<A + i<<endl;
  }
  for(int t = K - 1;t >= 0;t--){
    if(B - t > A + K - 1)cout<<B - t<<endl;
  }

}


Measured memory_bytes: 256
package main

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

var scanner *bufio.Scanner

func printIt() {
	word := []byte(nextString())
	n := nextInt()
	for i := 0; i < n; i++ {
		op := nextString()
		start := nextInt()
		end := nextInt()
		if op == "print" {
			fmt.Println(string(word[start : end+1]))
		} else if op == "replace" {
			target := []byte(nextString())
			for i, ch := range target {
				word[start+i] = ch
			}
		} else if op == "reverse" {
			for i := 0; i < (end-start+1)/2; i++ {
				word[start+i], word[end-i] = word[end-i], word[start+i]
			}
		}
	}
}

func nextInt() int {
	scanner.Scan()
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(1)
	}
	return num
}

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}


func main() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	printIt()
}



Measured memory_bytes: 1188
import kotlin.math.ceil
import kotlin.math.log2
import kotlin.math.max
import kotlin.math.pow

/**
 * @author karayuu
 */
fun sigma(end: Int, func: (Int) -> Double): Double = (1..end).map(func).sum()

fun main() {
  val (n, k) = readLine()!!.split(" ").map { it.toDouble() }
  // 確率の合計は 1/n * Σ(p=1, n){(1/2)^log2(k / p)}なので
  println(1 / n * sigma(n.toInt()) { 0.5.pow(max(0, ceil(log2(k / it.toDouble())).toInt())) })
}

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

const int MAX = 44;
int F[MAX];

int fibonacci_dp(int n)
{
  F[0] = F[1] = 1;
  for(int i = 2; i <= n; i++)
    F[i] = F[i - 2] + F[i - 1];
  return F[n];
}
  
int main()
{
  int n;
  cin >> n;
  cout << fibonacci_dp(n) << endl;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
int main (){
  int n,b;
  cin >> n;
  b=0;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i) ;
  }
  int max = *std::max_element(a.begin(),a.end()); 

  for(int i=0;i<n;i++){
    b+=a.at(i);
  }
 if(b-max>max)
   cout <<"Yes"<<endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using namespace std;


void solve(long long N){
  long long ret = 0;
  for (int i = 2; i <= 1000000; ++i) {
    int k = 0;
    while(N%i == 0) {
      k++;
      N/=i;
    }
    for (int j = 1; j < 1000000; ++j) {
      if (k < j) break;
      ret++;
      k -= j;
    }
  }
  if (N != 1) {
    ret++;
  }
  cout << ret << endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  solve(N);
  return 0;
}


Measured memory_bytes: 3764
N = int(input())
s_list = []
for i in range(N):
    s_list.append(input())

a = 0
both = 0
b = 0
ans = 0
for i, s in enumerate(s_list):
    ans += s.count("AB")
    if s[0] == "B" and s[-1] == "A":
        both += 1

    elif s[-1] == "A":
        a += 1

    elif s[0] == "B":
        b += 1

if a != 0:
    a -= 1
    ans += both
    if b != 0:
        b -= 1
        ans += 1
    ans += min(a, b)
else:
    if b != 0:
        b -= 1
        ans += both
    else:
        if both >= 2:
            ans += both - 1
print(ans)


Measured memory_bytes: 44376
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

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

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N, W;
    cin >> N >> W;
    int w[N];
    int v[N];
    for (int i = 0; i < N; i++) cin >> w[i] >> v[i];

    int dp[N+1][W+1];
    fill(dp[0], dp[N+1], 0);

    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= W; j++) {
            if (j - w[i] >= 0) {
                dp[i+1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
            } else {
                dp[i+1][j] = dp[i][j];
            }
        }
    }

    int ret = -1;
    for (int j = 0; j <= W; j++) {
        ret = max(ret, dp[N][j]);
    }

    cout << ret << endl;

    return 0;
}

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

#include<cstdio>
#include<cstring>
#include<string>

int main(){
  int n, taro=0, hanako=0;
  string ct, ch;

  cin >> n;

  for (int i=0; i<n; i++){
    cin >> ct >> ch;
    if (ct > ch) taro+=3;
    else if (ct < ch) hanako+=3;
    else {
      taro++; hanako++;
    }
  }

  cout << taro << ' ' << hanako << "\n";

  return 0;
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define rep(i, n) for(i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define PI 3.14159265359

int main(){
  ll N, i, a;
  cin >> N;
  vector<ll> list(N, 0);
  rep(i, N - 1){
    cin >> a;
    list[a - 1]++;;
  }
  
  rep(i, N){
    cout << list[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 4852
#define _USE_MATH_DEFINES
#define INF 100000000
 
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
 
static const double EPS = 1e-8;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

struct Purse{
  int possess10;
  int possess100;
  Purse(int _p10,int _p100){
    possess10 = _p10;
    possess100 = _p100;
  }
};

int main(){
  int total_2DRespecters;
  int storage10;
  int storage100;
  int upper_storage10;
  while(~scanf("%d %d %d %d",
	       &total_2DRespecters,
	       &storage10,
	       &storage100,
	       &upper_storage10)){

    vector<Purse> respecters;
    for(int respect_idx = 0; respect_idx < total_2DRespecters; respect_idx++){
      int possess10,possess100;
      scanf("%d %d",&possess10,&possess100);
      respecters.push_back(Purse(possess10,possess100));
    }
    
    int res = 0;
    int sum = 0;
    for(int round = 0; round < 10000000; round++){
      int idx = round % total_2DRespecters;
;
      if(respecters[idx].possess10 > 0){
	sum += 10;
	respecters[idx].possess10--;
	storage10++;
      }
      else if(respecters[idx].possess100 > 0){
	sum += 100;
	respecters[idx].possess100--;
	storage100++;
      }
      else{
	res = idx+1;
	break;
      }
      
      if(storage10 > upper_storage10){
	res = idx + 1;
	break;
      }
      
      if(sum >= 90){
	int diff = sum - 90;
	int limit100 = diff / 100;
	
	bool isok = false;
	for(int limit=0;limit<=limit100;limit++){
	  int pay100 = limit;
	  int pay10 = (diff - (limit * 100)) / 10;
	  if(pay10 <= storage10 && pay100 <= storage100){
	    storage10 -= pay10;
	    storage100 -= pay100;
	    
	    sum = 0;
	    respecters[idx].possess10 += pay10;
	    respecters[idx].possess100 += pay100;
	    isok = true;
	    break;
	  }
	}

	if(!isok){
	  res = idx + 1;
	  break;
	}
      }
      
    }
    printf("%d\n",res);
  }
}

Measured memory_bytes: 1192
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



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

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a,b,c;cin>>a>>b>>c;
  cout<<max(b+c-a,0LL)<<endl;

  return 0;

}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Thu May 14 13:29:53 2020

@author: shinba
"""

n = int(input())

data = {}

f = 0

for i in map(int,input().split()):
    if 1 <= i < 400:
        data["gray"] = 1
    elif 400 <= i < 800:
        data["brown"] = 1
    elif 800 <= i < 1200:
        data["green"] = 1
    elif 1200 <= i < 1600:
        data["w"] = 1
    elif 1600 <= i < 2000:
        data["blue"] = 1
    elif 2000 <= i < 2400:
        data["y"] = 1
    elif 2400 <= i < 2800:
        data["o"] = 1
    elif 2800 <= i < 3200:
        data["r"] = 1
    else:
        f += 1

print(max(len(data),1),len(data)+f)

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

#define int long long
int n;
int a[300005];
int cnt[300005],qzh[300005];

signed main() {
	scanf("%lld",&n);
	for(int i=0; i<n; i++) {
		scanf("%lld",a+i);
		cnt[a[i]]++;
	}
	sort(cnt,cnt+n+1);
	for(int i=1; i<=n; i++) {
		qzh[i]=qzh[i-1]+cnt[i];
	}
	for(int i=1; i<=n; i++) {
		int ff=n/i;
		if(cnt[n]<=ff) {
			printf("%lld\n",ff);
		} else {
			int l=0,r=n+1;
			while(r-l>1) {
				int m=(l+r)>>1;
				int now=upper_bound(cnt,cnt+n+1,m)-cnt;
				int num=qzh[now-1]+(n-now+1)*m;
				if(num>=i*m) {
					l=m;
				} else {
					r=m;
				}
			}
			printf("%lld\n",l);
		}
	}
	return 0;
}


Measured memory_bytes: 7936
#!/usr/bin/ruby

input1 = gets.chomp.split(" ")
input2 = gets.chomp.split(" ")

n = input1[0].to_i
k = input1[1].to_i

puts (n - k) / (k - 1) + 1 + ((n - k) % (k - 1) == 0 ? 0 : 1)


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

using namespace std;
#define ll long long
#define ld long double
const int N=2e5 + 5;
const ll mod = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    double a, b, c, d;
    cin >> a >> b >> c >> d;
    if(ceil(a / d) >= ceil(c / b)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;

int main(){
    int A,B,Q; cin>>A>>B>>Q;
    vector<ll> s(A),t(B);
    for (int i = 0; i < A; ++i) {
        cin>>s[i];
    }
    for (int i = 0; i < B; ++i) {
        cin>>t[i];
    }

    for (int i = 0; i < Q; ++i) {
        ll start; cin>>start;
        auto its=lower_bound(s.begin(),s.end(),start);
        auto itt=lower_bound(t.begin(),t.end(),start);
        ll se=1e12,sw=-1e12,te=1e12,tw=-1e12;
        if(its-s.begin()!=A) se=*(its);
        if(its-s.begin()!=0) sw=*(its-1);
        if(itt-t.begin()!=B) te=*(itt);
        if(itt-t.begin()!=0) tw=*(itt-1);
        ll ans=1e18;
        //se,te
        ans=min(ans,max(se,te)-start);
        //sw,tw
        ans=min(ans,start-min(sw,tw));
        //se,tw
        ans=min(ans,se-tw+min(se-start,start-tw));
        //sw,te
        ans=min(ans,te-sw+min(te-start,start-sw));

        cout<<ans<<endl;
    }

    return 0;
}

Measured memory_bytes: 2944
n,m=map(int,input().split())
dp=[]
INF=10**9
for i in range(m+1):
  dp.append([])
  dp[-1].append(0)
  for j in range(2**n-1):
    dp[-1].append(INF)
keys=[]
for i in range(m):
  a,b=map(int,input().split())
  r=['0']*n
  c=list(map(int,input().split()))
  for j in range(b):
    r[c[j]-1]='1'
  s=''.join(r)
  keys.append([int(s,2),a])
    
for i in range(m):
  for j in range(2**n):
    dp[i+1][j|keys[i][0]]=min(dp[i+1][j|keys[i][0]],dp[i][j]+keys[i][1])
    dp[i+1][j]=min(dp[i+1][j],dp[i][j])
if dp[m][2**n-1]==10**9:
  print(-1)
else:
  print(dp[m][2**n-1])

Measured memory_bytes: 109364
#include <bits/stdc++.h>
#include <regex>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 1145141919;
const int MOD = 100000007;
const double EPS = 1e-10;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator > (const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///
char c;
int main()
{
	map<char, int> t;
	FOR(i, 2, 10) t[i + '0'] = i;
	t['T'] = 10; t['J'] = 11; t['Q'] = 12; t['K'] = 13; t['A'] = 14;
	while (cin >> c, c!='#')
	{
		string s[4][13];
		REP(i, 4)REP(j, 13) cin >> s[i][j];
		int ns = 0; int ew = 0;
		int par = 0;
		REP(j,13)
		{
			string win = s[par][j];
			REP(i, 4)
			{
				if (s[i][j][1] == c)
				{
					if (win[1]!=c||t[win[0]] < t[s[i][j][0]]) win = s[i][j];
				}
				else if (win[1]!=c&&s[i][j][1] == s[par][j][1])
				{
					if ((win[1]!=c&&s[par][j][1]!=win[1])||t[win[0]] < t[s[i][j][0]]) win = s[i][j];
				}
				else
				{
					if (win[1] != c&&win[1]!=s[par][j][1])
					{
						if (t[win[0]] < t[s[i][j][0]]) win = s[i][j];
					}
				}
			}
			REP(i, 4)
			{
				if (win == s[i][j])
				{
					if (i % 2) ew++;
					else ns++;
					par = i;
				}
			}
		}
		cout << (ns > ew ? "NS" : "EW") << " " << max(ns, ew) - 6 << endl;
	}

	return 0;
}

Measured memory_bytes: 1200
N = int(input())
S = [str(input()) for _ in range(N)]

S.sort()
lst = [1]
for i in range(1, N):
    if S[i] == S[i-1]:
        lst[-1] += 1
    else:
        lst.append(1)

candidate = list(set(S))
candidate.sort()
#print(candidate)

max_value = max(lst)
max_index = [i for i, x in enumerate(lst) if x == max_value]
#print(max_index)

for j in range(len(max_index)):
    print(candidate[max_index[j]])


Measured memory_bytes: 31172
#pragma GCC optimize(2)
#include<bits/stdc++.h> 
using namespace std;
#define ll long long
#define endl "\n"
const int mod=1e9+7;
const int MAX=1e6+7;
ll f[MAX];
ll qpow(ll a,ll b,ll mod){
	ll res=1;
	for(;b;b>>=1){
		if(b&1)res=res*a%mod;
		a=a*a%mod;
	}
	return res;
}
ll cal(ll n,ll m){
	if(n-m<m)m=n-m;
	return (f[n]*qpow(f[m]*f[n-m]%mod,mod-2,mod))%mod;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    ll n,m,a,b;cin>>n>>m>>a>>b;
	f[0]=1;
	for(ll i=1;i<MAX-5;i++)
		f[i]=(f[i-1]*i)%mod;
	ll ans=0;
	for(ll i=b+1;i<=m;i++)
		ans=(ans+cal(n-a-1+i-1,n-a-1)*cal(a+m-i-1,a-1)%mod)%mod;
	cout<<(ans+mod)%mod;
   return 0;
} 

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

#define rep(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define repn(i, m, n) for (int (i) = (m) ; (i) < (int)(n) ; ++(i))
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define repn_rev(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= (m) ; --(i))

#define INF 2e9
#define ll long long
#define MOD 1e9+7
#define MAX_V 305

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain; 


/* 辺を表す構造体 */
struct edge {int to, cap ,rev; };
 
/* グラフの隣接リスト表現 */
vector<edge> G[MAX_V];
/* DFSですべに調べたかのグラフ */
bool used[MAX_V];
 
/* fromからtoへ向かう容量capの辺をグラフに追加する */
/* 相互参照できるようにしている */
void add_edge(int from, int to, int cap){
    G[from].push_back((edge){to, cap, (int)G[to].size()});
    G[to].push_back((edge){from, 0, (int)G[from].size() - 1});    
}
 
/* 増加パスをdfsで探す */
int dfs(int v, int t, int f){
    if(v==t) return f;
    used[v] = true;
    for(int i=0; i<G[v].size(); i++){
        edge &e = G[v][i];
        if(!used[e.to] && e.cap>0){
            int d = dfs(e.to, t, min(f, e.cap));
            if(d>0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}
 
int max_flow(int s, int t){
    int flow = 0;
    for(;;){
        memset(used, 0, sizeof(used));
        int f = dfs(s, t, INF);
        if(f==0) return flow;
        flow += f;
    }
}

bool diffIsPrime(int a, int b) {
    a = abs(a - b);
    if(a <= 2) return false;
    repn(i, 2, sqrt(a)+1) if(a % i == 0) return false;

    return true;
}

int main(){
    int n;
    cin >> n;
    vector<int> x(n);
    map<int, int> mp;
    rep(i, n) {
        int tmp;
        cin >> tmp;
        mp[tmp] ^= 1;
        mp[tmp+1] ^= 1;
    }

    /* 一発でいける分を探す。偶奇の組み合わせしかないので二部マッチング */
    vector<int> odd, even;
    for(auto it = mp.begin(); it != mp.end(); it++) {
        if(it->second == 1) {
            if(it->first % 2 == 0) {
                even.push_back(it->first);
            } else {
                odd.push_back(it->first);
            }
        }
    }

    int start = 0, end = 201;
    rep(i, even.size()) add_edge(start, i+1, 1);
    rep(i, odd.size()) add_edge(i+101, end, 1);
    rep(i, even.size()) rep(j, odd.size()) {
        if(diffIsPrime(even[i], odd[j])) add_edge(i+1, j+101, 1);
    }

    int ans_tmp = max_flow(start, end);
    int ans = ans_tmp;

    /* 偶数同士と奇数同士は。差が偶数なので二回でいける */
    ans += ((even.size() - ans_tmp) / 2) * 2;
    ans += ((odd.size() - ans_tmp) / 2) * 2;

    /* あまったやつは差が奇数なので三回でいける */
    if((even.size() - ans_tmp) % 2 != 0) ans += 3;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
#!/usr/bin/env python3

import sys

def read_int_list(sep = " "):
    return [int(s) for s in sys.stdin.readline().rstrip().split(sep)]


def dprint(*args, **kwargs):
    return
    print(*args, **kwargs)


def choose(a, b, mod):
    numer, denomi = 1, 1 
    for i in range(0, b):
        denomi = (denomi * (i + 1)) % mod
        numer = ((a - i) * numer) % mod
    return (numer * pow(denomi, mod - 2, mod)) % mod


def main():
    mod = 1000000007
    n, a, b = read_int_list()
    ans = pow(2, n, mod)
    ans = (ans - 1) % mod  # case for zero flowers
    ans = (ans - choose(n, a, mod)) % mod
    ans = (ans - choose(n, b, mod)) % mod
    print(ans)


if __name__ == "__main__":
    main()

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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        long side = 0;
        for (int i = n - 1; i > 0; i--) {
            if (a[i] != a[i - 1]) {
                continue;
            }
            if (side != 0) {
                System.out.println(a[i] * side);
                return;
            }
            side = a[i--];
        }
        System.out.println(0);
    }

}


Measured memory_bytes: 50528
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MD = 1e9 + 7;
map<pair<ll, ll>, ll> ma;
ll quick_pow(ll a, ll b) {
    ll res=1;
    for(;b;b>>=1){
        if(b&1) res=res*a%MD;
        a=a*a%MD;
    }
    return res;
}



int main() {
    int n, s = 0;
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        ll a, b;
        scanf("%lld%lld", &a, &b);
        ll d = __gcd(a, b);
        if(d == 0) {
            s++;
            continue;
        }
        a /= d, b /= d;
        if(a < 0) a = -a, b = -b;
        ma[{a, b}]++;
    }
    ll ans = 1;
    for(auto it : ma) {
        if(it.second == 0) continue;
        ll a = it.first.first, b = it.first.second;
        ll d = quick_pow(2, ma[{a, b}]);
        b = -b;
        if(b < 0) a = -a, b = -b;
        if(ma.count({b, a})) {
            d = (d + quick_pow(2, ma[{b, a}]) - 1) % MD;
            ma[{b, a}] = 0;
        }
        //printf("d:%lld\n\n",d);
        ans = ans * d % MD;
    }
    ans = (ans - 1 + s + MD) % MD;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 16176
w, h, n = gets.chomp.split().map(&:to_i)

grouped_dots = {1 => [], 2 => [], 3 => [], 4 => []}

n.times do
  dot = gets.chomp.split().map(&:to_i)
  if dot[-1] == 1 || dot[-1] == 2
    grouped_dots[dot[-1]].push(dot[0])
  else
    grouped_dots[dot[-1]].push(dot[1])
  end
end

x_min = grouped_dots[1].max || 0
x_max = grouped_dots[2].min || w
y_min = grouped_dots[3].max || 0
y_max = grouped_dots[4].min || h
x = x_max - x_min
y = y_max - y_min
if x < 0 || y < 0
  puts(0) 
else
  puts(x * y)
end


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>b;--i)
#define sq(a) (a)*(a)
#define nitro std::ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define debug(x) std::cerr<<#x<<"="<<x<<'\n'
#define text std::cerr<<"SacredCoupoid08\n"
#define endl '\n'
#define all(c) (c).begin(),(c).end()
#define U 1000000007
#define N 100005
#define sz(c) (int)c.size()
typedef long long ll;
typedef std::vector< int > vi;
typedef std::pair<int, int> pi;
#define cin std::cin
#define cout std::cout
#define vector std::vector
#define pb push_back
#define pv(x) for(auto y:x)    cerr<<y<<" ";    cerr<<'\n';
#define fr first
#define sc second
#define ppb pop_back
#define max(a,b) a=max(a,b)
#define min(a,b) a=min(a,b)
#define int ll
#define tr(c,it) for(typeof(c.begin()) it= c.begin();it != c.end();it++)
signed main()
{		
	nitro;
	int VASU=1;
	//cin>>VASU;
	while(VASU--)
	{
		int n;
		cin>>n;
		map<int,int> m;
		int ans=0,a;
		rep(i,0,n)
		{
			cin>>a;
			ans+=m[i-a];
			m[i+a]++;
		}
		cout<<ans<<endl;
		
	}
	

	
	
	
	return 0;
}



Measured memory_bytes: 26260
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
		

}
int main(){
string S,T;
cin>>S;
cin>>T;

bool ans=true;
rep(i,S.size()){
if(S[i]!=T[i]){
  ans=false;
}
}
  
  if(ans){
    cout<<"Yes"<<endl;
  }
  else{
cout<<"No"<<endl;
    
  }
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;

ll n, x;
vector<ll> a, p;

ll calcPatty(ll n, ll x) {
  if (n == 0) return 1;
  if (x == 1)
    return 0;
  else if (x <= a[n - 1] + 1)
    return calcPatty(n - 1, x - 1);
  else if (x == a[n - 1] + 2)
    return p[n - 1] + 1;
  else if (x <= 2 * a[n - 1] + 2)
    return p[n - 1] + 1 + calcPatty(n - 1, x - 2 - a[n - 1]);
  else
    return 2 * p[n - 1] + 1;
}

int main() {
  cin >> n >> x;
  a.resize(n);
  p.resize(n);
  a[0] = 1;
  p[0] = 1;
  repi(i, 1, n) {
    p[i] = 1 + 2 * p[i - 1];
    a[i] = 3 + 2 * a[i - 1];
  }
  cout << calcPatty(n, x) << endl;
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n){
        cin >> a[i];
    }
    a.push_back(-1);

    int ans= 0;
    int curr = 1;
    REP(i, n){
        if(a[i] != a[i+1]){
            ans += curr/2;
            curr = 0;
        }
        curr++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
 
int main(){
	int n;
	scanf("%d",&n);
	for(long long x=1;x<=3500;x++){
		for(long long y=1;y<=3500;y++){
			if((4*x*y-n*y-n*x)<=0) continue;
			if((n*x*y)%(4*x*y-n*y-n*x)==0){
				printf("%lld %lld %lld\n",x,y,(n*x*y)/(4*x*y-n*y-n*x));
				return 0;
			} 
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int K, N; cin >> K >> N;
    int A[N];
    for(int i = 0; i < N; i++) cin >> A[i];
    int ans = A[N-1] - A[0];
    for (int i = 1; i < N; i++)
    {
        ans = min(ans, K - A[i] + A[i-1]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
N = int(input())
p = []
def check(n):
  for i in range(2,int(n**0.5)+1):
    if n%i==0:
      return False
  return True

for i in range(2,55556):
  for j in range(2, int(i**0.5)+1):
    if i%j==0:
      break
  else:
    if i%5==1:
      p += [i]


ans = p[:N]
print(*ans)

Measured memory_bytes: 41832
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){
    int S,N;
    cin>>S>>N;
    if(S<=N){
        cout<<"unsafe"<<"\n";
    }
    else{
        cout<<"safe"<<"\n";
    }

return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define lld long long
#define pb push_back
#define mk make_pair
#define MAX (lld)1e18+7
#define lim (lld)1e9+7
#define MAX2 (lld)2e5+9
#define ff first
#define ss second
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

const lld mod=lim;

lld power(lld x, lld y, lld p)  
{   lld res = 1;     x = x % p; if (x == 0) return 0;  
  
    while (y > 0)  
    { if (y & 1) res = (res*x) % p;  y = y>>1; x = (x*x) % p;   }  
    return res;  } 


lld extend_gcd(lld a, lld b, lld& x, lld& y) {
    if (b == 0) { x = 1;y = 0;return a;}
    lld x1, y1;
    lld d = extend_gcd(b, a % b, x1, y1);
    x = y1; y = x1 - y1 * (a / b);return d;	}

lld rowNum[]={-1,0,0,1};
lld colNum[]={0,-1,1,0};

int main()
{
	fastio
	lld d,t,s;

	cin>>d>>t>>s;

	if(d<=s*t)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;

}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<template<class...> class ContT, class ValueT, size_t Dim>
struct vec_type
{
    using type = ContT<typename vec_type<ContT, ValueT, Dim-1>::type>;
};

template<template<class...> class ContT, class ValueT>
struct vec_type<ContT, ValueT, 0>
{
    using type = ValueT;
};

template<class ValueT, size_t Dim = 1>
using vec_t = typename vec_type<std::vector, ValueT, Dim>::type;


template<class ValueT, size_t Dim, class = typename std::enable_if<Dim == 0>::type>
auto make_vec(ValueT value = ValueT()) -> ValueT
{
    return value;
}

template<class ValueT, size_t Dim, class... Rest>
auto make_vec(size_t size0, Rest... rest)
{
    auto vec = make_vec<ValueT, Dim-1>(rest...);
    return std::vector(size0, vec);
}

int diffabs(int l, int r)
{
    if (l < r) return r-l;
    else return l-r;    
}


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

int main()
{
    for (int i = 0; i < 5; i++)
    {
        int x;
        cin >> x;
        if (x == 0)
        {
            cout << i+1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3624
#include <stdio.h>
#define MAX 500001
int H[MAX];
int n;
void maxHeapify(int i){

  int l,r;
  int largest,tmp;
  l=left(i);
  r=right(i);

  if(n+1>l && H[l]>H[i]) largest = l;
  else largest=i;
  if(n+1>r && H[r]>H[largest]) largest=r;
  if(largest!=i){
    tmp=H[i];
    H[i]=H[largest];
    H[largest]=tmp;
    maxHeapify(largest);
  }
}
void buildMaxHeap(){
  int i;
  for(i=n/2;i+1>1;i--){
    maxHeapify(i);
  }
}
int left(int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}
int parent(int i){
  return i/2;
}

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

  return 0;
}

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

using namespace std;
using ll = long long;
int main() {
	int n, k;
	cin >> n >> k;
	vector<ll> h(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	} 
	ll ans = 1000000000;
	sort(h.begin(), h.end());
	for (int i = 0; i <= n - k; i++) {
		ll mi = abs(h[i + k - 1] - h[i]);
		ans = min(ans, mi);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
program guruguru
  implicit none
  integer :: n, m, a(100000), i, x
  integer(8) :: s, t, u, b(0:100000), c(100001)
  a = 0
  b = 0_8
  c = 0_8
  read(*,*) n, m
  read(*,*) a(1:n)
  s = 0_8
  do i = 1, n-1
    if (a(i+1).ge.a(i)) then
      s = s+int(a(i+1)-a(i),8)
      b(a(i+1)) = b(a(i+1))+int(a(i+1)-a(i),8)-1_8
      c(a(i)+1) = c(a(i)+1)+1_8
      c(a(i+1)) = c(a(i+1))-1_8
    else
      s = s+int(a(i+1),8)
      b(a(i+1)) = b(a(i+1))+int(a(i+1)+m-a(i),8)-1_8
      c(a(i)+1) = c(a(i)+1)+1_8
      c(1) = c(1)+1_8
      c(a(i+1)) = c(a(i+1))-1_8
    end if
  end do
  do i = 2, m
    c(i) = c(i)+c(i-1)
  end do
  u = s
  do x = 1, m-1
    t = u+b(x)-c(x)
    s = min(s,t)
    u = t
  end do
  write(*,'(i0)') s
  stop
end program guruguru

Measured memory_bytes: 2816
#include<cstdio>

int main(){
	int taro = 0, hanako = 0;
	int turn;
	char cardt[100], cardh[100];
	char c;
	scanf("%d", &turn);
	scanf("%c", &c);
	for(int i = 0; i < turn ; i++){
		scanf("%c", &c);
		int j = 0;
		while(c - 32){
			cardt[j] = c;
			j++;
			scanf("%c", &c);
		}
		cardt[j] = 0;
		j = 0;
		scanf("%c", &c);
		while(c - 10){
			cardh[j] = c;
			j++;
			scanf("%c", &c);
		}
		cardh[j] = 0;
		j = 0;
		while(cardt[j] || cardh[j]){
			if(cardt[j] < cardh[j]){
				hanako += 3;
				break;
			}else if(cardt[j] > cardh[j]){
				taro += 3;
				break;
			}else{
				j++;
			}
			if(cardt[j] == 0 & cardh[j] == 0){
				taro++;
				hanako++;
			}
		}
	}
	printf("%d %d\n", taro, hanako);
	return 0;
}

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

char castAndAdd(char c, int operation);

int main(){
    int H,W;
    char s[100][100];

    cin >> H >> W;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> s[i][j];
        }
    }

    //bakの二重配列を縦横1ずつ大きくすればこの場合分けは必要ないかもしれない
    //outputのとき必要な部分だけを表示すればよい
    char bak[100][100];
    for(int i = 0; i < H; i++){
        for(int j = 0 ;  j < W; j++){
            bak[i][j] = '0';
        }
    }
    for(int i = 0; i < H; i++){
        int down = i+1;
        int up = i-1;
        for(int j = 0; j < W; j++){
            int right = j+1;
            int left = j-1;
            if(s[i][j] == '#'){
                bak[i][j] = '#';
                if(up >= 0){
                    bak[up][j] = castAndAdd(bak[up][j],0);
                    // bak[up][j]++;
                }
                if(up >= 0 && left >= 0){
                    bak[up][left]= castAndAdd(bak[up][left],0);
                    // bak[up][left]++;
                }
                if(up >= 0 && right <= W){
                    bak[up][right] = castAndAdd(bak[up][right],0);
                    // bak[up][right]++;
                }
                if(down <= H){
                    bak[down][j] = castAndAdd(bak[down][j],0);
                    // bak[down][j]++;
                }
                if(down <= H && right <= W){
                    bak[down][right] = castAndAdd(bak[down][right],0);
                    // bak[down][right]++;
                }
                if(down <= H && left >= 0){
                    bak[down][left] = castAndAdd(bak[down][left],0);
                    // bak[down][left]++;
                }
                if(right <= W){
                    bak[i][right] = castAndAdd(bak[i][right],0);
                    // bak[i][right]++;
                }
                if(left >= 0){
                    bak[i][left] = castAndAdd(bak[i][left],0);
                    // bak[i][left]++;
                }
            }
        }
    }

    for(int i = 0; i < H; i++){
        for(int j = 0;j < W; j++){
            cout << bak[i][j];
        }
        cout << endl;
    }

}

//operation 0 -> +, 1 -> -
char castAndAdd(char c, int operation){
    if(c == '#') return c;
    int casted = c - '0';
    // cout << casted << endl;
    if(operation == 0){
        casted++;
        // cout << casted << endl;
        return '0' + casted;
    }
    else if(operation == 1){
        return casted--;
    }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;

ll n,l,a[100100];

bool check(int p){
  bool f = true;
  if(p>0 && a[p-1]>=a[p])f = false;
  if(p<n-1 && a[p+1]>=a[p])f = false;
  return f;
}

int main(){
  cin >> n >> l;
  rep(i,n)cin >> a[i];

  ll t = 0;
  priority_queue< pll,vector<pll>,greater<pll> > q;
  rep(i,n){
    if(check(i))q.push(pll(l-a[i]+t,i));
  }

  while(q.size()){
    pll p = q.top(); q.pop();
    t = p.first;
    ll id = p.second;

    a[id] = 0;
    if(id-1>=0 && check(id-1))q.push(pll(l-a[id-1]+t,id-1));
    if(id+1<n && check(id+1))q.push(pll(l-a[id+1]+t,id+1));
  }
  cout << t << endl;
}

Measured memory_bytes: 2828
#include <bits/stdc++.h>
using namespace std;
int main(){
    int k;
    string S;
    cin >> k >> S;
    if(S.length()<=k)cout << S << endl;
    else{
        for(int i=0;i<k;i++)cout << S[i];
        cout << "..." << endl;
    }
}

Measured memory_bytes: 3628
from collections import defaultdict
import sys

sys.setrecursionlimit(10 ** 7)
n = int(input())
s = [list(map(int,input().split())) for i in range(n-1)]
c = list(map(int,input().split()))
c.sort()
t = [-1] * n 
p = sum(c[:n-1])
q = defaultdict(list)
for i in range(n-1):
    q[s[i][0]] += [s[i][1]]
    q[s[i][1]] += [s[i][0]]

t1 = [t,1]

def find(q,x,t1):
    r = q[x]
    t1[0][x-1] = 0
    for i in range(len(r)):
        if t1[0][r[i]-1] == 0:
            continue
        else:
            t1 = find(q,r[i],t1)
    t1[0][x-1] = t1[1]
    t1[1] += 1
    return t1

o = find(q,1,t1)
o1 = o[0]
print(p)
b = ""
for i in range(n):
    b += str(c[o1[i]-1]) + " "

print(b)

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

using namespace std;
using ll = long long;

const int N = 200005;

pair<ll, int> f(ll cnt, int d) {
	if(cnt == 1) {
		return make_pair(0, d);
	}
	
	auto tmp = f(cnt / 2, d);
	tmp.first *= 2;
	tmp.second *= 2;
	tmp.first++;
	while(tmp.second >= 10) {
		tmp.first++;
		tmp.second = tmp.second % 10 + tmp.second / 10;
	}
	if(cnt % 2 == 1) {
		tmp.second += d;
		tmp.first++;
		while(tmp.second >= 10) {
			tmp.first++;
			tmp.second = tmp.second % 10 + tmp.second / 10;
		}
	}
	return tmp;
}

int m;
int d[N];
ll c[N];

int main() {

	scanf("%d", &m);

	ll ans = 0;
	for(int i = 0; i < m; i++) {
		scanf("%d %lld", d + i, c + i);
		auto tmp = f(c[i], d[i]);
		ans += tmp.first;
		d[i] = tmp.second;
	}

	int s = d[0];

	for(int i = 1; i < m; i++) {
		s += d[i];
		ans++;
		while(s >= 10) {
			ans++;
			s = s / 10 + s % 10;
		}
	}

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

}


Measured memory_bytes: 2560
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Main main = new Main();
		main.solveC();
	}

	private void solveC() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int Q = sc.nextInt();
		sc.nextLine();
		boolean[][] map = new boolean[N + 1][];
		map[0] = new boolean[M + 1];
		for (int r = 1; r <= N; r++) {
			map[r] = new boolean[M + 1];
			String line = sc.nextLine();
			for (int c = 1; c <= M; c++) {
				map[r][c] = line.charAt(c - 1) == '1';
			}
		}
		int[][] sum_v = new int[N + 1][];
		int[][] sum_e_r = new int[N + 1][];
		int[][] sum_e_c = new int[N + 1][];
		sum_v[0] = new int[M + 1];
		sum_e_r[0] = new int[M + 1];
		sum_e_c[0] = new int[M + 1];
		for (int r = 1; r <= N; r++) {
			sum_v[r] = new int[M + 1];
			sum_e_r[r] = new int[M + 1];
			sum_e_c[r] = new int[M + 1];
			for (int c = 1; c <= M; c++) {
				sum_v[r][c] = sum_v[r][c - 1] + sum_v[r - 1][c] - sum_v[r - 1][c - 1] + (map[r][c] ? 1 : 0);
				sum_e_r[r][c] = sum_e_r[r][c - 1] + sum_e_r[r - 1][c] - sum_e_r[r - 1][c - 1] + (map[r][c] && map[r - 1][c] ? 1 : 0);
				sum_e_c[r][c] = sum_e_c[r][c - 1] + sum_e_c[r - 1][c] - sum_e_c[r - 1][c - 1] + (map[r][c] && map[r][c - 1] ? 1 : 0);
			}
		}

		for (int k = 0; k < Q; k++) {
			int x_1 = sc.nextInt();
			int y_1 = sc.nextInt();
			int x_2 = sc.nextInt();
			int y_2 = sc.nextInt();
			int v = sum_v[x_2][y_2] - sum_v[x_1 - 1][y_2] - sum_v[x_2][y_1 - 1] + sum_v[x_1 - 1][y_1 - 1];
			int r = sum_e_r[x_2][y_2] - sum_e_r[x_1][y_2] - sum_e_r[x_2][y_1 - 1] + sum_e_r[x_1][y_1 - 1];
			int c = sum_e_c[x_2][y_2] - sum_e_c[x_1 - 1][y_2] - sum_e_c[x_2][y_1] + sum_e_c[x_1 - 1][y_1];
			System.out.println(v - r - c);
		}
	}
}

Measured memory_bytes: 227320
#include <stdio.h>

int main(void){
    int r,D,x2000;
    int i,j;
    
    scanf("%d %d %d",&r,&D,&x2000);
    
    for(i = 0;i < 10;i++){
        printf("%d\n",x2000 = r * x2000 - D);
    }
    
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<fstream>
#include<utility>
#include<string>
#include<iomanip>
#include<queue>
#include<cmath>
#include<utility>
#include<set>
#include<cmath>
#define MOD 998244353
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    long long x, k=5, nb=0;
    cin >> x;
    if(x%2==1)
    {
        cout << "0\n";
        return 0;
    }
    while(x/(k*2)>0)
    {
        nb+=x/(k*2);
        k*=5;
    }
    cout << nb << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
ll xsum,a[N],n;
int main(){
	cin>>n;
	for(int i=0;i<n;i++) cin>>a[i], xsum^=a[i];
	for(int i=0;i<n;i++) cout<<(xsum^a[i])<<" ";
    return 0;
}


Measured memory_bytes: 5184