akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	static boolean[] primes;

	static void primeSet(final int MAX){
		primes = new boolean[MAX+1];

		primes[2] = true;
		for(int i=3;i<=MAX;i+=2){
			primes[i] = true;
		}
		int rt = (int) Math.sqrt(MAX);
		for(int i=3;i<=rt;i+=2){
			if(primes[i]){
				for(int j=i*2;j<=MAX;j+=i){
					primes[j] = false;
				}
			}
		}
	}

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);

		int max = 0;
		while(true){
			int n = stdIn.nextInt();
			if(n==0){
				break;
			}
			
			if(max<n){
				primeSet(n);
				max=n;
			}

			// if(ï) then "0" ÈóÅÍÈ¢Bn=7 ... [2,5]

			int cnt = 0;
			for(int i=2;i<=n/2;i++){
				if(primes[i]&&primes[n-i]){
//					System.out.println("["+i+","+(n-i)+"]");
					cnt++;
				}
			}
			System.out.println(cnt);
		}
	}
}

Measured memory_bytes: 13000
import java.util.*;

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

	public void run() {
		Scanner sc = new Scanner(System.in);

		PriorityQueue<Long> l = new PriorityQueue<>(Comparator.reverseOrder());
		PriorityQueue<Long> r = new PriorityQueue<>();
		int Q=sc.nextInt();
		long b=0;
		long base=0;
		for(int i=0; i<Q; i++) {
			int q=sc.nextInt();
			if(q==1) {
				long a=sc.nextLong();
				b+=sc.nextLong();

				if(! l.isEmpty() && (a<l.element() || r.element()<a)) {
					base += Math.min(Math.abs(a-l.element()), Math.abs(a-r.element()));
				}

				l.add(a);
				r.add(a);
				if(l.element()>r.element()) {
					long v1=l.poll();
					long v2=r.poll();
					l.add(v2);
					r.add(v1);
				}
			}else {
				System.out.println(l.element()+ " " + (base + b));
			}
		}
		sc.close();
	}


}


Measured memory_bytes: 163540
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
#include <cassert>
#include <deque>
using namespace std;
#define int64_t long long
constexpr int64_t MOD=1e9+7;
int h[110];
int main() {
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;++i){
        scanf("%d",&h[i]);
    }
    int ans=h[0];
    for(int i=1;i<n;++i){
        ans+=h[i]-min(h[i],h[i-1]);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const long long LINF = 1000000000000000018ll;
const int INF = 1000000009;
const int mod = 1000000007;

std::map<long long, int> prime_factor(long long n) {
  std::map<long long, int> res;
  for (long long i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ++res[i];
      n /= i;
    }
  }
  if (n != 1) { res[n] = 1; }
  return res;
}

long long mod_pow(long long x, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    // 最下位bitが立っていたら x^{2^i}を掛ける
    if (n & 1) { res = res * x % mod; }
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

// return x^{-1} % mod
// it takes O(log{mod})
long long mod_inverse(long long x, long long mod) {
  return mod_pow(x, mod-2, mod);
}

// return nCk % mod
// it takes O(k)
long long mod_comb(long long n, long long k, long long mod) {
  long long numer = 1, denom = 1;
  for (long long i = 0; i < k; i++) {
    // numer: 分子, denom: 分母
    numer = numer * ((n-i) % mod) % mod;
    denom = denom * ((i+1) % mod) % mod;
  }
  return numer * mod_inverse(denom, mod) % mod;
}

int main() {
  long long n, m;
  cin >> n >> m;
  std::map<long long, int> mp = prime_factor(m);

  long long ans = 1;
  for (auto it = mp.begin(); it != mp.end(); it++) {
    long long e = it->second;
    ans = (ans * mod_comb(n+e-1, e, mod)) % mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
import bisect,copy,heapq,string
from collections import *
from math import *
from itertools import *
import sys
sys.setrecursionlimit(10 ** 6)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = LIST()

ans = inf
for i in range(-100,101):
    tmp = 0
    for j in range(len(a)):
        tmp += (i-a[j])**2
    ans = min(ans, tmp)

print(ans)

Measured memory_bytes: 10152
#include<stdio.h>
int A[200005],B[200005];
int main()
{
long long int n,m,i,start,end,flag,flag2=0;
scanf("%lld",&n);
for(i=0;i<n;i++)
{
scanf("%lld",&A[i]);
}
scanf("%lld",&m);
for(i=0;i<m;i++)
{
scanf("%lld",&B[i]);
}
for(i=0;i<m;i++)
{
start=0;
end=n-1;
flag=0;
while(start<=end)
{
if(B[i]<A[(start+end)/2])
{
end=((start+end)/2)-1;
}
else if(B[i]>A[(start+end)/2])
{
start=((start+end)/2)+1;
}
else
{
flag=1;
break;
}
}
if(flag==0)
{
printf("0\n");
flag2=1;
break;
}
}
if(flag2==0)
{
printf("1\n");
}
return 0;
}


Measured memory_bytes: 3296
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
#define INF 1 << 29
using namespace std;

int cost[10][10];

int main(){

  int n, town, from, to, c;
  while(scanf("%d", &n) && n){
    rep(i, 10) rep(j, 10) cost[i][j] = INF;
    rep(i, 10) cost[i][i] = 0;
    town = 0;
    rep(i, n){
      scanf("%d%d%d", &from, &to, &c);
      town = max(town, max(from, to));
      cost[from][to] = cost[to][from] = c;
    }
    town++;
    rep(k, town) rep(i, town) rep(j, town)
      cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);

    /*    rep(i, town){
      rep(j, town) printf("%d ", cost[i][j]<INF?cost[i][j]:-1);
      puts("");
      }*/

    int res1, res2 = INF;
    rep(i, town){
      int sum = 0;
      rep(j, town) if(cost[i][j] < INF) sum += cost[i][j];
      if(res2 > sum){
	res2 = sum;
	res1 = i;
      }
    }
    printf("%d %d\n", res1, res2);
  }
  return 0;
}

Measured memory_bytes: 1188
#include<stdio.h>

#define MAX 500000
#define S 2000000000
int L[MAX/2+2];
int R[MAX/2+2];
int count;

void merge(int A[],int n,int left,int mid,int right){
  int i,j,k,n1,n2;
  
  n1=mid-left;
  n2=right-mid;

  for( i=0; i<n1; i++){
    L[i]=A[left+i];
  }
  
   for( i=0; i<n2; i++){
    R[i]=A[mid+i];
  }
   
   L[n1]=S;
   R[n2]=S;

   i=0;
   j=0;
     for( k=left; k<right; k++){
     count++;
     
     if( L[i] <= R[j] ){
       A[k]=L[i++];
     }
     else{
       A[k]=R[j++];
     }
   }
}
     
void mergeSort(int A[],int n,int left,int right){
  
  if( left+1<right ){
    int mid=( left+right )/2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}

int main(){
  int A[MAX],n,i;
  count=0;

  scanf("%d",&n);
  
  for( i=0; i<n; i++ ){
    scanf("%d",&A[i]);
  }

  mergeSort(A,n,0,n);

  for( i=0; i<n; i++ ){
    if(i) printf(" ");
  printf("%d",A[i]);
  }
  
  printf("\n");
  
  printf("%d\n",count);

  return 0;
}



Measured memory_bytes: 5600
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

map<int, int> M;
void no()
{
	cout << "No" << endl;
	exit(0);
}

void yes()
{
	cout << "Yes" << endl;
	exit(0);
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	//ios::sync_with_stdio(false); cin.tie(0);
	int n, a, b;
	cin >> n;
	FOR(i, 0, n)
	{
		cin >> a;
		M[a]++;
	}

	if (SZ(M) > 2) no();
	if (SZ(M) == 1)
	{
		a = M.begin()->first;
		if (2 * a <= n || n - 1 == a) yes();
		no();
	}

	a = M.begin()->first;
	int cnta = M.begin()->second;

	auto it = M.begin();
	it++;
	b = it->first;
	int cntb = it->second;

	if (b - a != 1) no();
	if (cntb == 1)
	{
		if (cnta == a && cnta == b) yes();
		no();
	}
	
	if (b > cnta && cntb >= 2 * (b - cnta)) yes();
	//if (cnta == b - 1 && cnta == a) yes();

	no();
}


Measured memory_bytes: 4992
s = gets.chomp.chars

tmp1 = 0

s.each.with_index(1) do |c,i|
  if i.odd?
    if c != "1"
      tmp1 += 1
    end
  else
    if c != "0"
      tmp1 += 1
    end
  end
end

tmp2 = 0

s.each.with_index(1) do |c,i|
  if i.odd?
    if c != "0"
      tmp2 += 1
    end
  else
    if c != "1"
      tmp2 += 1
    end
  end
end

ans = [tmp1, tmp2].min

puts ans


Measured memory_bytes: 9468
#include<bits/stdc++.h>
using namespace std;
 
const int N = 3;
int i;
vector<int> afs;
int main() {
afs.resize(N);
for(i = 0; i < N; i++) {
cin >> afs[i];
}
sort(afs.begin(),afs.end());
cout << afs[0] + afs[1] << endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int a, b, c;
bool ok;
int main(){
	cin >> a >> b >> c;
	if(a == b) ok = a != c;
	else ok = a == c || b == c;
	puts(ok ? "Yes" : "No");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
using namespace std;
 
int main(){
  string s;
  int a = 700;
  cin >> s;
  for(int i=0; i<3; i++){
  if(s[i] == 'o') a += 100;
  }
  
  cout << a;
 
}

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

using namespace std;

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> v(h, vector<char>(w));
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> v[i][j];
        }
    }
    for (int i = 0; i < h; ++i) {
        bool white_row = true;
        for (int j = 0; j < w and white_row; ++j) {
            if (v[i][j] == '#') {
                white_row = false;
            }
        }
        if (white_row) {
            for (int j = 0; j < w; ++j) {
                if (v[i][j] == '.') {
                    v[i][j] = '-';
                }
            }
        }
    }
    for (int j = 0; j < w; ++j) {
        bool white_col = true;
        for (int i = 0; i < h and white_col; ++i) {
            if (v[i][j] == '#') {
                white_col = false;
            }
        }
        if (white_col) {
            for (int i = 0; i < h; ++i) {
                if (v[i][j] == '.') {
                    v[i][j] = '-';
                }
            }
        }
    }
    for (int i = 0; i < h; ++i) {
        bool printed = false;
        for (int j = 0; j < w; ++j) {
            if (v[i][j] != '-') {
                cout << v[i][j];
                printed = true;
            }
        }
        if (printed)
            cout << "\n";
    }
    return 0;
}

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

int main()
{
    char s[100];
    scanf("%s", s);

    int len  = strlen(s);
    int i, flag, flag1, flag2, temp = len / 2, count;
    flag = 1;
    for(i = 0; i < len/2; i++){
        if(s[i] != s[len - i - 1]){
            flag = 0;
            break;
        }
    }
    if(flag){
        flag1 = 1, flag2 = 1, count = 0;
        for(i = 0; count <= temp / 2; count++, i++){
            if(s[i] != s[(len-1) / 2 - i - 1]){
                flag1 = 0;
                //printf("flag1 = 0 at i = %d\n", i);
                break;
            }
        }
        count = 0;
        for(i = (len + 3) / 2; count <= temp / 2; count++, i++){
            if(s[i] != s[len - i - 1]){
            flag2 = 0;
            break;
            }
        }
        //printf("flag1 = %d, flag2 = %d", flag1, flag2);

        if(flag1 && flag2) printf("Yes\n");
        else printf("No\n");
    }
    else printf("No\n");

    return 0;
}


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

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define I1000000007 (1000000007)
#define I998244353   (998244353)
#define IINF             (1<<28)
#define LINF           (1LL<<60)
#define ALL(a)         (a).begin(), (a).end()
#define rep(i, n)      REP(i, 0, (n))
#define repc(i, n)     REPC(i, 0, (n))
#define REP(i, n, m)   for (int i = (int)(n); i <  (int)(m); i++)
#define REPC(i, n, m)  for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define yesno(cond)       YESNO((cond), "Yes", "No")
#define YESNO(cond, a, b) cout << ((cond) ? (a) : (b)) << "\n"
template<class T> inline bool chmin(T& a, const T& b) {
  if (a > b) { a = b; return true; } else return false;
}
template<class T> inline bool chmax(T& a, const T& b) {
  if (a < b) { a = b; return true; } else return false;
}

namespace solver {
  using namespace std;
  using ll = long long;

  string X;

  void init() {
    cin >> X;
  }

  void solve() {
    int s = 0, ans = X.size();
    rep(i, X.size()) {
      if(X[i] == 'S') s++;
      else if(X[i] == 'T' && s > 0) ans -= 2, s--;
    }
    cout << ans << "\n";
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  solver::init();
  solver::solve();
  return 0;
}

Measured memory_bytes: 720
#include <algorithm>
#include <array>
#include <complex>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

vector<int> G[5000];
map<string, int> conv;
vector<string> name;
vector<int> cost;
int N, M;
bool vis[5000];

int dfs(int s){
  int res = cost[s];
  memset(vis, 0, sizeof(vis));
  vis[s] = true;
  queue<int> q;
  q.push(s);
  while(!q.empty()){
    int u = q.front();
    q.pop();
    res = min(res, cost[u]);
    for(int i = 0; i < G[u].size(); ++i) {
      int& v = G[u][i];
      if(!vis[v]){
        vis[v] = true;
        q.push(v);
      }
    }
  }
  return res;
}

int main() {
  cin >> N;
  name.resize(N);
  cost.resize(N);
  for(int i = 0; i < N; ++i) {
    cin >> name[i] >> cost[i];
    conv[name[i]] = i;
  }
  cin >> M;
  for(int i = 0; i < M; ++i) {
    string a, b;
    cin >> a >> b;
    int s = conv[a];
    int t = conv[b];
    G[s].push_back(t);
    G[t].push_back(s);
  }
  ll sum = 0;
  for(int i = 0; i < N; ++i) {
    sum += dfs(i);
  }
  cout << sum << endl;
}

Measured memory_bytes: 2024
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;

vector<int> univ (const vector<vector<int>> &G, int s) {
    vector<int> koike(G.size(), INF); koike[s] = 0;
    vector<bool> LOVE(G.size(), false);
    queue<int> que; que.emplace(s);
    while (!que.empty()) {
        int yuriko = que.front(); que.pop();
        LOVE[yuriko] = true;
        for (auto abe : G[yuriko]) {
            if (LOVE[abe] == true) continue;
            koike[abe] = koike[yuriko] + 1;
            que.emplace(abe);
        }
    }
    return koike;
}

int main(){
    int N;
    cin >> N;
    vector<vector<int>> G(N);
    for (int i = 1; i < N; i++) {
        int abe, koike; cin >> abe >> koike; abe--; koike--;
        G[abe].emplace_back(koike);
        G[koike].emplace_back(abe);
    }
    
    vector<int> fen = univ(G, 0);
    vector<int> snuke = univ(G, N-1);
    
    int ok = 0, ng = 0;
    for (int i = 0; i < N; i++) {
        if (fen[i] <= snuke[i]) ok++;
        else ng++;
    }
    
    cout << ((ng < ok) ? "Fennec" : "Snuke") << endl;
    return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;
ll A;
ll res=0;
void add357(ll before){
    if(before > A){
        return;
    }
    add357(before*10+3);
    add357(before*10+5);
    add357(before*10+7);
    string str = to_string(before);
    vector<bool> count(3,false);
    rep0(i,str.length()){
        if(str[i]=='3'){
            count[0]=true;
        }else if(str[i]=='5'){
            count[1]=true;
        }else{
            count[2]=true;
        }
    }
    rep0(i,3){
        if(!count[i]){
            return;
        }
    }
    res++;
}

int main()
{
    cin >> A;
    add357(0);
    cout << res << endl;
}



Measured memory_bytes: 3600
#include <iostream>

struct Card { char suit, value; };

void bubble(struct Card A[], int N) {
  for (int i = 0; i < N; i++) {
    for (int j = N-1; j >= i; j--) {
      if (A[j].value < A[j-1].value) {
        Card t = A[j]; A[j] = A[j-1]; A[j-1] = t;
      }
    }
  }
}

void selection(struct Card A[], int N) {
  for (int i = 0; i < N; i++) {
    int minj = i;
    for (int j = i; j < N; j++) {
      if (A[j].value < A[minj].value) minj = j;
    }
    Card t = A[i]; A[i] = A[minj]; A[minj] = t;
  }
}

void print(struct Card A[], int N) {
  using namespace std;
  for (int i = 0; i < N; i++) {
    if (i > 0) cout << " ";
    cout << A[i].suit << A[i].value;
  }
  cout << endl;
}

bool isStable(struct Card C1[], struct Card C2[], int N) {
  for (int i = 0; i < N; i++) {
    if (C1[i].suit !=C2[i].suit) return false;
  }
  return true;
}

int main(void) {
  Card C1[100], C2[100];
  int N;
  using namespace std;

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> C1[i].suit >> C1[i].value;
  }

  for (int i = 0; i < N; i++) C2[i] = C1[i];

  bubble(C1, N);
  selection(C2, N);

  print(C1, N);
  cout << "Stable" << endl;
  print(C2, N);
  if ( isStable(C1, C2, N) ) {
    cout << "Stable" << endl;
  } else {
    cout << "Not stable" << endl;
  }

  return 0;
}



Measured memory_bytes: 3112
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val s = next()

    var min = 753

    for (i in 0..s.length-3) {
        val diff = Math.abs(s.slice(i..i+2).toInt() - 753)
        if (diff < min) min = diff
    }

    println(min)
}

fun next() = readLine()!!

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 31868
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
using namespace std;

#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 VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)


typedef long long ll;

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


/*************************************************************************/
//多次元配列の確保及び初期化用マクロ
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}
/*************************************************************************/


#define ARRAY_MAX 100005
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

int main() {

	ll h, w;
	cin >> h >> w;
	ll ans = 1e15;
	//横横
	for (ll i = 1; i <= h - 2 ; i++)
	{
		ll s1 = i * w;
		ll s2 = (h - i) / 2 * w;
		ll s3 = h * w - s1 - s2;
		ll maxi = max(s1, max(s2, s3));
		ll mini = min(s1, min(s2, s3));
		ans = min(ans, maxi - mini);
	}
	
	//縦縦
	for (ll i = 1; i <= w - 2; i++)
	{
		ll s1 = i * h;
		ll s2 = (w - i) / 2 * h;
		ll s3 = h * w - s1 - s2;
		ll maxi = max(s1, max(s2, s3));
		ll mini = min(s1, min(s2, s3));
		ans = min(ans, maxi - mini);
	}

	//横縦
	for (ll i = 1; i <= h - 1; i++)
	{
		ll s1 = i * w;
		ll s2 = (h - i) * (w/2);
		ll s3 = h * w - s1 - s2;
		ll maxi = max(s1, max(s2, s3));
		ll mini = min(s1, min(s2, s3));
		ans = min(ans, maxi - mini);
	}


	//縦横
	for (ll i = 1; i <= w - 1; i++)
	{
		ll s1 = i * h;
		ll s2 = (w - i) * (h / 2);
		ll s3 = h * w - s1 - s2;
		ll maxi = max(s1, max(s2, s3));
		ll mini = min(s1, min(s2, s3));
		ans = min(ans, maxi - mini);
	}

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
    int n,count;
    int v[100];
    int c[100];
    int sum=0;

    scanf("%d",&n);
    for(count=1;count<=n;count++){
        if(count<=9||(count>=100&&count<=999)||(count>=10000&&count<=99999)){sum++;}
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 128
//be name khoda
//Pedram Sadeghian
// :)
#include <bits/stdc++.h>
using namespace std;

const int maxN = 1e5;
int nam[maxN][3], ans, n, m, k1, k2, k3;
pair <int, pair <int, int> > P[maxN];
bool issame(int a, int b){
	return nam[a][0] == nam[b][0];
}
void merrge(int a, int b){
	if (nam[a][2] < nam[b][2])
		swap(a, b);
	int S = nam[a][2] + nam[b][2], k = a;
	bool plp = 1;
	while (k != a || plp){
		plp = 0;
		nam[k][2] = S;
		nam[k][0] = nam[b][0];
		k = nam[k][1];
	}
	k = b; plp = 1;
	while (k != b || plp){
		plp = 0;
		nam[k][2] = S;
		k = nam[k][1];
	}
	S = nam[a][1];
	nam[a][1] = nam[b][1];
	nam[b][1] = S;
	return ;
}
int main(){
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for (int i = 0 ; i < m ; i++){
		cin >> k1 >> k2 >> P[i].first;
		P[i].second.first = k1;
		P[i].second.second = k2;
	}
	sort(P, P + m);
	for (int i = 0 ; i < n ; i++){
		nam[i][0] = i + 1;
		nam[i][1] = i;
		nam[i][2] = 1;
	}
	for (int i = 0 ; i < m ; i++){
		if (not issame(P[i].second.first, P[i].second.second)){
			ans += P[i].first;
			merrge(P[i].second.first, P[i].second.second);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 4468
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define ll long long
 
//const int INF = 1e8;
typedef pair<int,int>P;
int dx[4] = {1,0,-1,0};int dy[4] = {0,1,0,-1};
queue<P> que;

int main(void){
  int n,m;cin >> n >> m;
  int l = 0;int r = n;
  for(int i = 0;i<m;i++){
    int a,b;cin >> a >> b;
    l = max(l,a);
    r = min(r,b);
  }
  cout << max(r-l+1,0) << endl;
}

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

lli min(lli a,lli b)
{
    if(a<b)
    {
        return a;
    }
    return b;

}
lli n,m;

bool ispalindrome(string str)
{
    int i=0;
    int n=str.length();
    while(str[i]!='\0')
    {
        if(str[i]!=str[n-i-1])
        {
            return false;
        }
        i++;
    }
    return true;
}

int main()
{
    string str;
    cin>>str;
    int n=str.length();
    bool f=true;
    if(!ispalindrome(str))
    {
        f=false;
    }
    int len=((n-1)/2) ;
   // cout<<"len :"<<len<<"\n";
   // cout<<str.substr( 0, len)<<"\n";
    if(!ispalindrome(str.substr( 0, len)))
    {
        f=false;
    }
    len=n-((n+3)/2) +1;
    //cout<<"len :"<<len<<"\n";
    //cout<<str.substr( (n+3)/2 -1, len)<<"\n";
    if(!ispalindrome(str.substr( (n+3)/2 -1, len)))
    {
        f=false;
    }

    if(f)
    {
        cout<<"Yes"<<"\n";
    }
    else{
        cout<<"No"<<"\n";
    }
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[])throws Exception
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String s=br.readLine();
		String t=br.readLine();
		int len=t.length();
		if(s.contentEquals(t.substring(0,len-1)))
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}


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

int main(){
    long long n;
    long long h[110000];
    cin >> n;
    for(long long i = 0; i < n; i++) cin >> h[i];

   
    long long storedCount = 0;
    long long eachCount = 0;
    for(long long i = 0; i < n; i++){
        // cout << storedCount << eachCount << endl;
        if(storedCount < eachCount) storedCount = eachCount;
        if(storedCount >= n - 1) break;
        eachCount = 0;
        for(long long j = i; j < n - 1; j++){
            if(h[j] >= h[j+1]) eachCount++;
            else break;
        }
    }

    cout << storedCount << endl;

}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int n;
		int[] a,b;
		Scanner scan = new Scanner(System.in);
		while(true){
			n = scan.nextInt();
			if(n==0)
				break;
			a = new int[n];
			b = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = scan.nextInt();
				b[i] = scan.nextInt();
			}

			int ansA = 0;
			int ansB = 0;

			for (int i=0; i<n; i++) {
				if(a[i]>b[i])
					ansA += a[i]+b[i];
				else if(a[i]<b[i])
					ansB += a[i]+b[i];
				else{
					ansA += a[i];
					ansB += b[i];
				}
			}
			System.out.println(ansA+" "+ansB);

		}
		scan.close();
	}
}

Measured memory_bytes: 13000
def main():
    L, R = map(int, input().split())
    # 60 の相異なる素因数は 3, 673 の 2つ
    if L + 672 <= R:
        print(0)
        return
    lst = []
    for i in range(L, R + 1):
        for j in range(i + 1, R + 1):
            m = i * j % 2019
            lst.append(m)
            if m == 0:
                break
        if m == 0:
            break
    print(min(lst))
    return


main()


Measured memory_bytes: 6804
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;


#[fastout]
fn solve() {
    const MOD: usize = 1_000_000_007;
    const INF: usize = std::usize::MAX;
    
    input!{
        h: usize, w: usize,
        a: [Chars; h]
    }
    let mut ans: Vec<Vec<char>> = vec![];

    let mut t = vec![];
    for i in 0..h {
        if a[i].iter().all(|x| *x == '.') { continue; }
        t.push(a[i].clone())
    }

    let mut remove_x = vec![];
    for x in 0..w {
        let mut flag = true;
        for y in 0..t.len() {
            if t[y][x] != '.' {
                flag = false;
                break;
            }
        }
        if flag { remove_x.push(x) }
    }

    for y in 0..t.len() {
        let mut tmp = vec![];

        for x in 0..w {
            if remove_x.contains(&x) { continue; }
            tmp.push(t[y][x])
        }
        ans.push(tmp)
    }

    println!("{}", ans.iter().map(|x| x.iter().join("")).join("\n"));
}

fn main() {
    solve()
}

#[cfg(test)]
mod test {
    use super::solve;
}


Measured memory_bytes: 2348
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(){ 

  string str;
  int q;
  string talk,p;
  int a,b;

  cin>>str;
  cin>>q;

  for(int i=0;i<q;i++){
    cin>>talk;
    if(talk=="print"){
      cin>>a>>b;
      for(int j=a;j<=b;j++){
	cout<<str[j];
      }
      cout<<endl;
    }
    else if(talk=="replace"){
      cin>>a>>b>>p;
      for(int j=a;j<=b;j++){
	str[j]=p[j-a];
      }
    }
    else{
      cin>>a>>b;
      for(int j=a;j<=a+(b-a)/2;j++){
	swap(str[j],str[b-(j-a)]);
      }
    }
  }
}

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

int main(){
  vector<vector<int>> sheet(3, vector<int>(3));
  vector<vector<bool>> bingo(3, vector<bool>(3));
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      cin >> sheet[i][j];
      bingo[i][j] = false;
    }
  }
  
  int n;
  cin >> n;
  for(int k = 0; k < n; k++){
    int b;
    cin >> b;
    for(int i = 0; i < 3; i++){
      for(int j = 0; j < 3; j++){
        if(sheet[i][j] == b)
          bingo[i][j] = true;
      }
    }
  }
  
  bool check = false;
  
  for(int i = 0; i < 3; i++){
    if(bingo[i][0] && bingo[i][1] && bingo[i][2])
      check = true;
    else if(bingo[0][i] && bingo[1][i] && bingo[2][i])
      check = true;
    else if(bingo[0][0] && bingo[1][1] && bingo[2][2])
      check = true;
    else if(bingo[2][0] && bingo[1][1] && bingo[0][2])
      check = true;
    if(check)
      break;
  }
  
  if(check)
    cout << "Yes" <<endl;
  else
    cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(void){
  string s1,s2;
  cin>>s1;
  cin>>s2; 
  int dp[1001][1001];
  for(int i=0;i<1001;i++){
    dp[i][0]=i;
    dp[0][i]=i;
  }
  for(int i=1;i<s1.length()+1;i++){
    for(int j=1;j<s2.length()+1;j++){
      if(s1[i-1]==s2[j-1]){
	dp[i][j]=min({dp[i-1][j]+1,dp[i][j-1]+1,dp[i-1][j-1]});
      }
      else{
	dp[i][j]=min({dp[i-1][j],dp[i][j-1],dp[i-1][j-1]})+1;
      }
    }
  }
  cout<<dp[s1.length()][s2.length()]<<"\n";
  return 0;
}


Measured memory_bytes: 7132
N=int(input())
A=input()

A_list = A.split(" ")
A_int_list = list(map(int,A_list))

A_int_list.sort()
A_int_list.reverse()

alice=0
bob=0

for i in range(0,len(A_int_list)):
	if(i%2==0):
		alice += int(A_int_list[i])
	else:
		bob += int(A_int_list[i])

print(alice-bob)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long y = sc.nextLong();
		if(x % y == 0) {
			System.out.println(-1);
		} else {
			System.out.println(x);
		}
	}
}


Measured memory_bytes: 23760
#include<stdio.h>
int N;
int F[100][14];
int P[100][15];
int main(){
	scanf("%d",&N);
	for(int i=0;i<N;i++) {
		for(int j=0;j<10;j++)
			scanf("%d",&F[i][j]);
	}
	for(int i=0;i<N;i++)
		for(int j=0;j<11;j++)
			scanf("%d",&P[i][j]);
	int res = -(1<<30);
	for(int b=1;b<(1<<10);b++){
		int cc=0;
		for(int i=0;i<N;i++){
			int c=0;
			for(int j=0;j<10;j++)
				if((b>>j&1)&&F[i][j])
					c++; 
				cc+=P[i][c];
		}
		if(res<cc)
			res=cc;
	}
	printf("%d\n",res);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
ll mod=1e9+7;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  for(ll i=0;i<n;i++) {
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  ll m=a[0];
  ll nn=0;
  for(ll i=0;i<n;i++) {
    if(a[i]<0) nn++;
  }
  if(nn==0) nn++;
  else if(nn==n) nn--;
  for(ll i=nn;i<n-1;i++) {
    m-=a[i];
  }
  for(ll i=0;i<nn;i++) {
    if(i==0) {
      m=a[n-1]-m;
    }
    else {
      m-=a[i];
    }
  }
  cout << m << endl;
  m=a[0];
  for(ll i=nn;i<n-1;i++) {
    cout << m << " " << a[i] << endl;
    m-=a[i];
  }
  for(ll i=0;i<nn;i++) {
    if(i==0) {
      cout << a[n-1] << " " << m << endl;
      m=a[n-1]-m;
    }
    else {
      cout << m << " " << a[i] << endl;
      m-=a[i];
    }
  }
  cout << endl;
}

Measured memory_bytes: 2688
#include<stdio.h>
#include<string.h>
const int N=1e5+5,P=1e9+7;
char s[N];int n,m,p[N],g[N][3],f[N];
int main(){
	int x,c;
	scanf("%s",s+1),n=strlen(s+1);
	for(x=1;x<n;x++)if(s[x]==s[x+1])break;
	if(x<n){
		for(x=1;x<=n;x++)p[x]=(p[x-1]+(s[x]=='b')+1)%3;
		for(x=n;x>=0;x--)g[x][0]=g[x+1][0],g[x][1]=g[x+1][1],g[x][2]=g[x+1][2],g[x][p[x]]=x;
		f[0]=1;
		for(x=0;x<n;x++)if(f[x])for(c=0;c<3;c++)if(c!=p[x]&&g[x+1][c])f[g[x+1][c]]=(f[g[x+1][c]]+f[x])%P;
		for(x=1;x<=n;x++)if(p[x]==p[n])m=(m+f[x])%P;
	}else m=1;
	printf("%d\n",m);
}


Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}


// TODO: write
int main() {
  int n,q;cin>>n>>q;
  string s;cin>>s;
  vector<int> l(q),r(q);rep(i,q)cin>>l[i]>>r[i];
  vector<int> a(n+1);
  
  a[0] = 0;
  rep(i,n+1){
    if(i){
      a[i] = a[i-1];
      if(s[i-1] == 'A' && s[i] == 'C')a[i]++;
    }
  }
  
  rep(i,q){
    print(a[r[i]-1]-a[l[i]-1]);
  }

  return 0;
}




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

using namespace std;

int main(void)
{
	int a;
	cin >> a;
	string s;
	cin >> s;
	if (a >= 3200)
	{
		cout << s << endl;
	}
	else
	{
		cout << "red" << endl;
	}
	return 0;
}


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

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

template<typename T>
struct WeightedUnionFind {
    vector<int> data;
    vector<T> ws;
    WeightedUnionFind(int sz) : data(sz, -1), ws(sz) { }
    bool merge(int x, int y, T w) {             // ws(y) = ws(x) + w
        w += weight(x); w -= weight(y);
        if ((x = root(x)) == (y = root(y))) return false;
        if (data[x] > data[y]) swap(x, y), w = -w;
        data[x] += data[y]; data[y] = x; ws[y] = w;
        return true;
    }
    bool find(int x, int y) { return root(x) == root(y); }
    T diff(int x, int y) { return weight(y) - weight(x); }
    T weight(int t) { root(t); return ws[t]; }
    int root(int k) {
        if (data[k] < 0) return k;
        int par = root(data[k]);
        ws[k] += ws[data[k]];
        return data[k] = par;
    }
};

int main() {
    int n, m; cin >> n >> m;
    WeightedUnionFind<int> wuf(n);
    while (m--) {
        int l, r, d; cin >> l >> r >> d; --l, --r;
        if (wuf.find(l, r)) {
            int diff = wuf.diff(l, r);
            if (diff != d) {
                cout << "No" << endl;
                return 0;
            }
        } else {
            wuf.merge(l, r, d);
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

#define int long long

int32_t main() {
	int n1,n2,cnt=1; cin>>n1>>n2;
	int n=__gcd(n1,n2); 
	for(int i=2;i*i<=n;i++) {
		if(n%i==0) {
			cnt++;
			while(n%i==0) n/=i;
		}
	}
	
	if(n>1) cnt++;
	cout<<cnt<<endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'

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

    int n;
    cin >> n;
    vector<float> v(n);
    for (int i = 0; i < n; i++)
        cin >> v[i];
    sort(v.begin(), v.end());
    float ans = v[0];
    for (int i = 1; i < n; i++)
        ans = (ans + v[i]) / 2;
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String str = sc.next();
    char c1 = str.charAt(0);
    char c2 = str.charAt(str.length() - 1);
    System.out.println("" + c1 + (str.length() - 2) + c2);
  }
}


Measured memory_bytes: 23764
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {
        n: usize,
        s: [String; n],

    }
    let mut ac = 0;
    let mut wa = 0;
    let mut tle = 0;
    let mut re = 0;
    for i in 0..n {
        if &s[i] == "AC" {
            ac += 1;
        }
        if &s[i] == "WA" {
            wa += 1;
        }
        if &s[i] == "TLE" {
            tle += 1;
        }
        if &s[i] == "RE" {
            re += 1;
        }
    }
    println!("AC x {}", ac);
    println!("WA x {}", wa);
    println!("TLE x {}", tle);
    println!("RE x {}", re);
}


Measured memory_bytes: 7756
k = int(input())

ok = False
for i in range(1, k+1):
   if i == 1:
      a = 7 % k
   else:
      anext = (a * 10 + 7) % k
      a = anext
   if a == 0:
      print(i)
      ok = True
      break

if not ok:
   print(-1)


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

using namespace std;
typedef long long ll;

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

   int sum_t = 0, sum_h = 0;
   while(n--){
      string t, h;
      cin >> t >> h;
      if(t>h)
         sum_t += 3;
      else if(t==h)
         sum_t++, sum_h++;
      else
         sum_h += 3;
   }
   cout << sum_t << " " << sum_h << endl;
   return 0;
}



Measured memory_bytes: 3140
a = list(map(int,input().split()))
a += list(map(int,input().split()))
a += list(map(int,input().split()))
n = int(input())
b = []
for i in range(n):
  b.append(int(input()))
index = 0
for i in a:
  if i in b:
    a[index] = 0
  else:
    next
  index += 1

if (a[0]is a[1]is a[2]is 0)or(a[3]is a[4]is a[5]is 0)or (a[6]is a[7]is a[8]is 0)or(a[0]is a[3]is a[6]is 0)or(a[1]is a[4]is a[7]is 0)or(a[2]is a[5]is a[8]is 0)or(a[0]is a[4]is a[8]is 0)or(a[2]is a[4]is a[6]is 0):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
        String[] input = br.readLine().split(" ");
        int N = Integer.parseInt(input[0]);
        long Y = Long.parseLong(input[1]);
        int x = -1;
        int y = -1;
        int z = -1;
        
        for(int i = 0; i <= N; i++){
            for(int j = 0; j <= N - i; j++){
                if(Y == 10000 * i + 5000 * j + 1000 * (N - (i + j))){
                    x = i;
                    y = j;
                    z = N - (i + j);
                    break;
                }
            }
        }
        
        out.printf("%d %d %d", x, y, z);
        out.close();
        
    }
}

Measured memory_bytes: 34332
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int n,k;

    cin>>n>>k;

    cout<<max(n%k,0LL)<<endl;






}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

i64 N;
vector<vector<i64>> G;
const i64 mod = 1e9 + 7;

array<i64, 2> rec(i64 i, i64 f = -1) {
  array<i64, 2> arr;
  arr[0] = 1;
  arr[1] = 1;
  for(auto j: G[i]) {
    if(j == f) continue;
    auto res = rec(j, i);
    arr[0] = (arr[0] * res[1]) % mod;
    arr[1] = (arr[1] * (res[0] + res[1])) % mod;
  }
  return arr;
}

int main() {
  cin >> N;
  G.resize(N);
  rep(i,0,N - 1) {
    i64 x, y;
    cin >> x >> y;
    x--;
    y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }

  auto res = rec(0);
  cout << (res[0] + res[1]) % mod << endl;
}


Measured memory_bytes: 12672
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long double PI = (acos(-1));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int ctoi(char c)
{
    switch (c)
    {
    case '0':
        return 0;
    case '1':
        return 1;
    case '2':
        return 2;
    case '3':
        return 3;
    case '4':
        return 4;
    case '5':
        return 5;
    case '6':
        return 6;
    case '7':
        return 7;
    case '8':
        return 8;
    case '9':
        return 9;
    default:
        return 0;
    }
}
int main()
{
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    bool ans = false;
    bool boo1 = true;
    bool boo2 = false;
    bool boo3 = true;
    for (int i = 0; i < a; i++)
    {
        if (s[i] == '-')
        {
            boo1 = false;
        }
    }
    if (s[a] == '-')
    {
        boo2 = true;
    }
    for (int j = a + 1; j < s.size(); j++)
    {
        if (s[j]=='-')
        {
            boo3 = false;
        }
    }
    if (boo1 && boo2 && boo3)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = input()
X = list(N)

X = [int(x) for x in X]
if int(N) % sum(X) == 0:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 3896
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const int maxn=2e5+10;
int f[maxn];
int q(int a, int b){
	int ans = 1;
	while(b){
		if(b&1)ans = 1ll*ans*a%mod;
		a=1ll*a*a%mod;
		b>>=1;
	}
	return ans;
}
int main(){
	ll ans, n, k;
	cin >> n >> k;
	ans=0;
	for(ll i=k;i>=1;i--){
		f[i]=q(k/i,n);
		for(ll j=2*i;j<=k;j+=i){
			f[i]=(f[i]-f[j]+mod)%mod;
		}
	}
	for(ll i=1;i<=k;i++){
		ans+=i*f[i]%mod;
		ans%=mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3992
from collections import deque
def LI():return [int(i) for i in input().split()]

ans=0
inf=1<<65
n,m=LI()
X=[0,inf,-inf]
Y=[0,inf,-inf]
V=[]
H=[]
for i in range(n):
    a,b,c=LI()
    V.append(((a,b),c))
    Y.append(c)
    X.append(a)
    X.append(b)
 
n+=2
V.append(((-inf,inf),inf))
V.append(((-inf,inf),-inf))
 
for i in range(m):
    a,b,c=LI()
    H.append((a,(b,c)))
    X.append(a)
    Y.append(b)
    Y.append(c)
 
m+=2
H.append((inf,(-inf,inf)))
H.append((-inf,(-inf,inf)))

X.sort()
xdc={}
c=1
for j in sorted(set(X)):
    xdc[c]=j
    c+=1
nx=c-1
 
Y.sort()
ydc={}
c=1
for j in sorted(set(Y)):
    ydc[c]=j
    c+=1
ny=c-1
 
xdcr=dict(zip(xdc.values(),xdc.keys()))
ydcr=dict(zip(ydc.values(),ydc.keys()))
 
mpy=[[0]*(nx+1+1) for i in range(ny+1+1)]
mpx=[i[:]for i in mpy]

for (a,b),c in V:
    mpx[ydcr[c]][xdcr[a]]+=1
    mpx[ydcr[c]][xdcr[b]]+=-1
for i in range(ny+1):
    for j in range(nx):
        mpx[i][j+1]+=mpx[i][j]
        
for d,(e,f) in H:
    mpy[ydcr[e]][xdcr[d]]+=1
    mpy[ydcr[f]][xdcr[d]]+=-1
for j in range(nx+1):
    for i in range(ny):
        mpy[i+1][j]+=mpy[i][j]

v=[[0]*(nx+1) for i in range(ny+1)]
q=[(xdcr[0],ydcr[0])]
v[ydcr[0]][xdcr[0]]=1

while q:
    cx,cy=q.pop()
    ans+=(xdc[cx]-xdc[cx+1])*(ydc[cy]-ydc[cy+1])
    for dx,dy in [(-1,0),(1,0),(0,1),(0,-1)]:
        nbx=cx+dx
        nby=cy+dy
        if (0>nbx>=nx)or(0>nby>=ny)or v[nby][nbx]==1:
            continue
        if dy!=0:
            if mpx[-~dy//2+cy][cx]==0:
                q.append((nbx,nby))
                v[nby][nbx]=1
        else:
            if mpy[cy][-~dx//2+cx]==0:
                q.append((nbx,nby))
                v[nby][nbx]=1
if ans>=inf:
    ans='INF'
print(ans)


Measured memory_bytes: 542172
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <ctime>
#include <iostream>
#include <functional>
#include <complex>
#include <stdlib.h>
#include <random>
#include <fstream>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<pii, int> p3i;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<p3i> v3i;
typedef vector<vii> vvii;
typedef vector<p3i> vp3i;
typedef long double ld;
typedef vector<ld> vld;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define REPD(i, n) for (int (i) = (n) - 1; (i) >= 0; (i)--)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define FORD(i,a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define rv(v) reverse(all(v))
#define CL(v, val) memset((v), (val), sizeof((v)))
#define SORT(a) sort(all(a))
#define un(v) SORT(v), (v).resize(unique(all(v)) - (v).begin())
#define eps 1.0e-9
#define X first
#define Y second
#define bit(n) (1 << (n))
#define bit64(n) (ll(1) << (n))
#define sqr(x) ((x) * (x))
#define sq5(x) ((x) * (x) * (x) * (x) * (x))

int main(void) {
	int a, b;
	scanf("%d%d", &a, &b);
	printf("%d\n", a * b);
	return 0;
}

Measured memory_bytes: 3760
import scala.annotation.tailrec
import scala.collection.mutable

object Main extends App {
  import scala.io.StdIn._
  loop()
  @tailrec def loop(): Unit = {
    val str = readLine.trim
    if (str == "0") return
    val memo = Array.fill(str.length){Array.fill(11){-1}}
    val digits = str.map(_.asDigit).toArray
    println(digits.indices.filterNot(digits(_) == 0).map{i ⇒ search(i, 0, digits, memo)}.sum)
    loop()
  }
  def search(current: Int, prev: Int, digits: Array[Int], memo: Array[Array[Int]]): Int = {
    if (current == digits.length) return 0
    if (memo(current)(prev) >= 0) return memo(current)(prev)
    memo(current)(prev) = if ((digits(current) + prev * 10) % 11 == 0) 1 else 0
    memo(current)(prev) += search(current + 1, (digits(current) + prev * 10) % 11, digits, memo)
    memo(current)(prev)
  }
}



Measured memory_bytes: 236408
import java.util.Scanner


/**
 * Created by sonetsuyoshi on 2015/12/16.
 */
object Main extends App {
  val sc = new Scanner(System.in)

  val n = sc.nextLong
  val m = sc.nextLong

  def run(): Unit = {
    val l = math.min(n, m / 2)

    val n1 = n - l
    val m1 = m - 2 * l

    val ans = l + m1 / 4

    println(ans)
  }

  run()
}

Measured memory_bytes: 27180
#include<iostream>
#include<string>
#include<map>
using namespace std;

int main() {
	int n, i, j,count=0,max=0;
	string s;
	map<char, int>m, ms;
	map<char, int>::iterator it;

	cin >> n;
	cin >> s;

	for (i = 0; i < n; i++) {
		if (m.count(s[i])==0) {
			for (j = n - 1; j > i; j--) {
				if (s[i] == s[j])
					m.insert(pair<char, int>(s[i], j));
			}
		}
	}
	for (i = 1; i < n - 1; i++) {
		ms = m;
		for (j = 0; j < i;j++) {
			it = ms.find(s[j]);
			if (it == ms.end())
				continue;
			if (it->second >= i) {
				count++;
				ms.erase(s[j]);
			}
		}
		if (max < count)
			max = count;
		count = 0;
	}

	cout << max;

	return 0;
}

Measured memory_bytes: 256