akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
#include <cmath>

long N;
std::vector<int> primes;
std::vector<std::pair<int,int>> facts;

void solve();
int digits(long);
long forward(long);

int main()
{
  std::cin >> N;
  /*
  for (int i=1; i<=6; i++) {
    std::cout << "forward(" << i<< "): " << forward(i) << '\n';
  }
  */
  solve();
  return 0;
}

int digits(long x)
{
  if (x<=0) return 0;
  else return digits(x/10) + 1;
}

long forward(long digits)
{
  int ret = 1;
  for (int i=0; i<digits; i++) ret *= 10;
  return ret-1;
}

void solve()
{
  int ans = digits(N);
  if (!(N%2)) ans = digits(N/2);
  long i = 3;
  const long sq = std::sqrt(N) + 1;
  while (i <= sq) {
    //std::cout << i << "\n";
    //if (i==26010) std::cout << "Daole\n";
    if (!(N%i)) {
      int x = digits(N/i);
      //std::cout << i << "is a candidate\n";
      if (ans > x) {
        //std::cout << "Found: " << i << '\n';
        ans = x;
        //std::cout << "answer updated to " << ans <<  " by " << i << '\n';
        i = forward(digits(i));
        //std::cout << "Forwarded to: " << i << '\n';
      }
    }
    i += 1;
  }

/*
  std::cout << "listing up primes..." << '\n';
  if (!(N%2)) ans = digits(N/2);
  primes.push_back(2);
  for (int i=3; i <= N; i+=2) {
    auto iter=primes.begin();
    for (; iter!=primes.end(); iter++) {
      if (!(i%(*iter))) break;
    }
    if (iter==primes.end()) { // if new prime is found
      primes.push_back(i);
    }
  }

  std::cout << "factorizing..." << '\n';
  for (auto iter=primes.begin(); iter!=primes.end(); iter++) {
    int n = 0;
    int N_copied = N;
    while (!(N_copied%(*iter))) {
      n++;
      N_copied /= *iter;
    }
    if (n>0) facts.push_back(std::make_pair(*iter, n));
  }

  auto iter = facts.begin();
  for (; iter!=facts.end(); iter++) {
    std::cout << (*iter).first << ": " << (*iter).second << '\n';
  }
*/

/*
  if (!(N%2)) ans = digits(N/2);
  for (int i=3; i*i <= N; i+=2) {
    if (!(N%i)) {
      int x = digits(N/i);
      //std::cout << i << ": " << N/i << '\n';
      if (ans > x) ans = x;
    }
  }
*/
  std::cout << ans << '\n';
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  int N;
    cin>>N;
    int V[N];
  int C[N];
  int X=0;
  int Y=0;

  for(int i=0;i<N;i++){
    cin>>V[i];
  }
    for(int i=0;i<N;i++){
    cin>>C[i];
  }
  int anz;

  for(int i=0; i<N; i++){
  if(V[i]-C[i]>0){
  X=X+V[i];
  Y=Y+C[i];}
  }
 cout<<X-Y<<endl;
 
return 0;
}

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

using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
	public Program() { }

	static void Main(string[] args)
	{
		new Program().prog();
	}

	Scanner cin;

	const int MOD = 1000000007;
	const int INF = int.MaxValue - 10;
	const long INFL = long.MaxValue - 10;
	const double EPS = 1e-8;
	const double PI = 3.1415926536;
	int[,] dir8;
	int[,] dir4;



	void prog()
	{
		cin = new Scanner();
		dir8 = new int[8, 2] { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 } };
		dir4 = new int[4, 2] { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };

		int x = cin.nextInt();
		int y = cin.nextInt();
		int ans = INF;
		if (x <= y)
		{
			ans = Math.Min(ans, y - x);
		}
		if (-x <= y)
		{
			ans = Math.Min(ans, y + x + 1);
		}
		if (x <= -y)
		{
			ans = Math.Min(ans, -y - x + 1);
		}
		if (-x <= -y)
		{
			ans = Math.Min(ans, -y + x + 2);
		}
		Console.WriteLine(ans);
	}
}

class Scanner
{
	string[] s;
	int i;

	char[] cs = new char[] { ' ' };

	public Scanner()
	{
		s = new string[0];
		i = 0;
	}

	public string next()
	{
		if (i < s.Length) return s[i++];
		string st = Console.ReadLine();
		while (st == "") st = Console.ReadLine();
		s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
		i = 0;
		return next();
	}

	public int nextInt()
	{
		return int.Parse(next());
	}

	public long nextLong()
	{
		return long.Parse(next());
	}

	public double nextDouble()
	{
		return double.Parse(next());
	}
}

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

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int A = int.Parse(input[0]);
            int B = int.Parse(input[1]);
            int C = int.Parse(input[2]);
            int K = int.Parse(Console.ReadLine());
            int max = Math.Max(A, B);
            max = Math.Max(max, C);

            for(int i = 0; i < K; i++)
            {
                max *= 2;
            }

            if (A >= B && A >= C)
            {
                Console.WriteLine(max + B + C);
            }
            else if (B >= A && B >= C)
            {
                Console.WriteLine(max + A + C);
            }
            else
            {
                Console.WriteLine(max + A + B);
            }

        }

    }
}


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

int main(){
  int first,second;
  cin >> first >> second;
  int result=0;
  for (int i=0;i<50;i++){
    // if (second == 1){
    //   cout << result;
    // }
    if (first*i - (i-1)>=second){
      cout << i;
      i=50;
    }
  }


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
const int IINF = 1000000000;
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; }
using Graph = vector<vector<int>>;


int main(){
    int N, C; cin >> N >> C;
    vector<int> s(N), t(N), c(N);
    rep(i,N) cin >> s[i] >> t[i] >> c[i];

    

    const int CHANNEL_NUM = 31;
    vector<vector<pair<int,int>>> a(CHANNEL_NUM);
    rep(i,N){
        a[c[i]].emplace_back(s[i],t[i]);
    }
    rep(i,CHANNEL_NUM){
        sort(a[i].begin(), a[i].end());
    }
/*
    rep(i,CHANNEL_NUM){
        cout <<  i << endl;
        for(auto tt: a[i]){
            cout << tt.first << " " << tt.second << endl;
        }
    }
*/
    vector<pair<int,int>> as;
    rep(i,CHANNEL_NUM){
        rep(j,a[i].size()){
            if(j == 0) as.push_back(a[i][j]);
            else{
                if (a[i][j-1].second == a[i][j].first){
                    //cout << i << " " << j << endl;
                    as.back().second = a[i][j].second;
                } 
                else{
                    as.push_back(a[i][j]);
                }
            }
        }
    }
/*
    rep(i,as.size()){
        cout << as[i].first << " " << as[i].second << endl;
    }
*/
    sort(as.begin(), as.end());

    vector<int> cum(100005,0);

    rep(i,as.size()){
        cum[as[i].first]++;
        cum[as[i].second+1]--;
    }

    rep(i,100004){
        cum[i+1] += cum[i];
    }

    int ans = 0;
    rep(i,100005){
        ans = max(ans,cum[i]);
    }

    cout << ans << endl;


} 

Measured memory_bytes: 6868
#import pysnooper
#import numpy
#import os,re,sys,operator
#from collections import Counter,deque
#from operator import itemgetter,mul
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left,bisect_right
#from copy import deepcopy
#import heapq
#import math
#import string
#from time import time
#from functools import lru_cache,reduce
#from math import factorial,hypot
#import sys
#from fractions import gcd
setrecursionlimit(10**6)
input=stdin.readline

m,d=map(int,input().split())
ans=0
for i in range(1,m+1):
    for j in range(1,d+1):
        s=str(j)
        if len(s)>=2:
            o,t=int(s[0]),int(s[1])
            if o>=2 and t>=2 and o*t==i:
                #print(i,j)
                ans+=1
print(ans)

Measured memory_bytes: 3064
<?php
list($H, $N) = ints();
$dp = array_fill(0, $N + 1, array_fill(0, $H + 1, 10**18));
$dp[0][0] = 0;
for($i = 1; $i <= $N; $i++){
  $dp[$i] = $dp[$i-1];
  $dpi = &$dp[$i];
  list($a, $b) = ints();
  for($j = 1; $j <= $H; $j++){
    if($j - $a >= 0){
      if($dpi[$j]>$dpi[$j-$a]+$b)$dpi[$j] = $dpi[$j-$a]+$b;
    }else{
      if($dpi[$j]>$b)$dpi[$j] = $b;
    }
  }
}
//o($dp);
echo $dp[$N][$H];
function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}

function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array: ";
            echo implode(" ", addIndex($val))."\n";
        }else{
            echo "array:array\n";
            if(isCleanArray($val)){
                foreach($val as $row)echo implode(" ", addIndex($row))."\n";
            }else{
                foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row))."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}
function addIndex($val){
    if(!isCleanArray($val)){
        $val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);
    }
    return $val;
}
function isCleanArray($array){
    $clean = true;
    $i = 0;
    foreach($array as $k => $v){
        if($k != $i++)$clean = false;
    }
    return $clean;
}


Measured memory_bytes: 529912
using System;
using System.Collections.Generic;
using System.Linq;

class P
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var map = new int[n + 1].Select(_ => new List<int>()).ToArray();
		foreach (var r in new int[n - 1].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()))
		{
			map[r[0]].Add(r[1]);
			map[r[1]].Add(r[0]);
		}

		var dp = new long[n + 1, 2];
		Find(1, 0, map, dp);
		Console.WriteLine((dp[1, 0] + dp[1, 1]) % M);
	}

	const int M = 1000000007;
	static void Find(int p, int from, List<int>[] map, long[,] dp)
	{
		dp[p, 0] = dp[p, 1] = 1;
		foreach (var np in map[p])
		{
			if (np == from) continue;
			Find(np, p, map, dp);
			dp[p, 0] = dp[p, 0] * (dp[np, 0] + dp[np, 1]) % M;
			dp[p, 1] = dp[p, 1] * dp[np, 0] % M;
		}
	}
}


Measured memory_bytes: 40192
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <ctime>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <queue>
#include <utility>
#include <cmath>
#include <functional>
#include <map>
#include <set>
const int INF = 1000000009;

int n;
int f[100][10];//[i][j], 店i, 時間帯j
int p[100][11];//[i][j], 店i, 時間帯の数j

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 <= 10; j++){
			scanf("%d", &p[i][j]);
		}
	}
	int ans = -INF;
	for(int i = 1; i < (1 << 10); i++){//営業する時間のループ
		int res = 0;
		for(int j = 0; j < n; j++){//確認する店
			int cnt = 0;
			for(int k = 0; k < 10; k++){//時間帯
				if(f[j][k] && i & (1 << k)){
					cnt++;
				}
			}
			/*if(31 <= i && i <= 33){
				printf("%d    %d %d\n",i,  j, cnt);
				printf("		%d\n", p[j][cnt]);
			}*/
			res += p[j][cnt];
		}
		ans = std::max(ans, res);
	}
	printf("%d\n", ans);
}

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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = "";

        while ((line = br.readLine()) != null && !line.isEmpty()) {
            char[] str = line.toCharArray();
            int u;
            char c;
            for (int i = 0; i < str.length / 2; i++) {
                u = str.length - 1 - i;
                c = str[i];
                str[i] = str[u];
                str[u] = c;
            }
            System.out.println(str);
        }
    }
}

Measured memory_bytes: 16852
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

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 PI 3.141592653589793238
#define INF 1050000000

using vi = vector<int>;


int main() {

	int N;

	cin >> N;

	cout << N/3 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int N, K;
vector<int> A(100000, 0);
 
int main(void){
    
    scanf("%d %d", &N, &K);
    int idx;
    for(int i = 0; i < N; ++i){ scanf("%d", &A[i]); if(A[i] == 1) idx = i; }
    
    int ans = INT_MAX;
    for(int left = idx; left >= 0 && left >= idx - (K - 1); --left){
        int right = left + (K - 1), cnt = 1;
        if(left >= N) continue;
        for(int j = left; j > 0; j -= (K - 1)) ++cnt;
        for(int j = right; j < N - 1; j += (K - 1)) ++cnt;
        ans = min(ans, cnt);
    }
    printf("%d\n", ans);
    
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void) {
  while( 1 ) {
  long long n, ans = 0, now = 0, i;
  scanf("%lld", &n);
  if(!n) break;
  int a[n];
  for(i = 0; i < n; ++i) scanf("%d", &a[i]);
  for(i = 0; i < n; ++i) {
    now += a[i];
    if(now > ans) ans = now;
    if(now < 0) now = 0;
  }
  if(!ans) {
    int max = -1000000;
    for(i = 0; i < n; ++i) if(max < a[i]) max = a[i];
    ans = max;
  }
  printf("%lld\n", ans);
  }
  return 0;
}


Measured memory_bytes: 2704
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <math.h>
typedef long long ll;
using namespace std;

int main()
{
	int x, a;
	cin >> x >> a;
	if (x < a) cout << 0;
	else cout << 10;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))
visited = [0]*N #各場所に最初に到着するまでの移動回数
cnt = 0 #現在の移動回数
pos = 0 #現在の場所
flag = False
while K > 0:
    cnt += 1
    K -= 1
    if visited[pos] == 0:
        visited[pos] = cnt
    elif not flag:
        K %= cnt-visited[pos]
        flag = True
    pos = A[pos]-1
print(pos+1)

Measured memory_bytes: 92320
#include<iostream>
    #include<algorithm>
    #include<vector>
    #include<queue>
    #include<stack>
    #include<map>
    #include<string>
    #include<cstring>
    #define ll long long
    #define all(x) (x).begin(),(x).end()
    #define rep(i,n) for(int i = 0;i < (n);++i)
    #define reps(i,n) for(int i = 1;i <= (n);++i)
    using namespace std;
    int main(){
    	cin.tie(0);
    	ios::sync_with_stdio(false);
    	int a,b,c;
    	cin >> a >>b >> c;
    	cout << ((a - b - c < 0) ? c - (a - b) : 0) << '\n';
    	return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> ii;
int MOD = 1e9+7;
int c[200010],fac[200010];
ii arr[200010];
int use[200010];
int fastexpo(int a,int b){
    if (b == 1) return a;
    int temp = fastexpo(a,b/2);
    temp = (temp*temp)%MOD;
    if (b%2 == 0) return temp%MOD;
    return (temp*a)%MOD;
}
main(){
    int n,x,y;
    cin >> n >> x >> y;
    fac[0] = 1;
    for (int i = 1; i <= n; i++){
        fac[i] = (fac[i-1]*i)%MOD;
        c[i] = 1e18;
    }
    int minw = 1e18;
    int minc = -1;
    for (int i = 0; i < n; i++){
        cin >> arr[i].first >> arr[i].second;
        c[arr[i].first] = min(c[arr[i].first],arr[i].second);
        if (arr[i].second < minw){
            minw = min(minw,arr[i].second);
            minc = arr[i].first;
        }
    }
    for (int i = 0; i < n; i++){
        if (arr[i].second + c[arr[i].first] <= x) arr[i].second = c[arr[i].first];
    }
    int secondminw = 1e18;
    for (int i = 1; i <= n; i++) if (i != minc) secondminw = min(secondminw,c[i]);
    int tot = 0;
    for (int i = 0; i < n; i++){
        if ((arr[i].first != minc && arr[i].second + minw <= y) || (arr[i].second + secondminw <= y)){
            tot++;
            use[arr[i].first]++;
        }
    }
    int ans = fac[tot];
    for (int i = 1; i <= n; i++){
        if (use[i])ans = (ans*fastexpo(fac[use[i]],MOD-2))%MOD;
    }
    cout << ans;
}


Measured memory_bytes: 8064
def seive(n):
    is_prime = [1] * (n + 1)
    is_prime[0] = 0
    is_prime[1] = 0
    for i in range(2, int(n ** 0.5) + 1):
        if is_prime[i]:
            for j in range(i * i, n + 1, i):
                is_prime[j] = 0
    return is_prime


N = int(input())
cands = [i for i, p in enumerate(seive(1381)) if p and str(i)[-1] == "1"]
print(*cands[:N])


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int N;
    cin >> N;
    int t = N;
    int sum = 0;
    while(t > 0) {
        sum += t % 10;
        t /= 10;

    }

    if(N % sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


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

int gcd (int p, int q) {
	if (p % q == 0) return q;
	return gcd(q, p % q);
}

int main() {
	int K;
	cin >> K;
	int ans = 0;
	for (int i = 1; i <= K; i++) {
		for (int j = 1; j <= K; j++) {
			for (int k = 1; k <= K; k++) {
				ans += gcd(gcd(i, j), k);
			}
		}
	}
	cout << ans << endl;
return 0;
}

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

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

	for(i=0; i<n; i++){
		//一の位をbへ。10Nならb=10.
		b[i]=a[i]%10;
		if(b[i]==0)	b[i]=10;
		
		//繰り上げ。cへ。
		if(a[i]%10!=0){
			c[i]=10*(a[i]/10+1);
		}
		else	c[i]=a[i];
	}

	//一の位が0でなく一番小さいものは？
	int min=b[0], index=0;
	for(i=1; i<n; i++){
		if(min>b[i]){
			min=b[i];
			index=i;
		}
	}
	
	int ans=0;
	for(i=0; i<n; i++){
		ans += c[i];
	}
	
	ans -= c[index];
	ans += a[index];
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	n := nextInt()
	m := map[int]int{}

	for i := 0; i < n; i++ {
		m[i] = nextInt() - 1
	}

	res, current := 0, 0
	already := map[int]bool{}
	already[0] = true
	for {
		current = m[current]
		res++

		if already[current] {
			fmt.Println(-1)
			return
		}
		already[current] = true

		if current == 1 {
			break
		}
	}

	fmt.Println(res)
}


Measured memory_bytes: 9600
#!/bin/bash
read x
read a
read b
c=0
tmp=$(($x-$a-$(($c*$b))))
while [ $(($x-$a-$(($(($c))*$b)))) -gt 0 -o $(($x-$a-$(($(($c))*$b)))) -eq 0 ]
do
  tmp=$(($x-$a-$(($c*$b))))
  c=$(($c+1))
done
echo $tmp

Measured memory_bytes: 376
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
using namespace std;

bool flag[301][301];

int main()
{
    int N;
    cin >> N;
    vector<vector<long long> > A(N, vector<long long>(N, 0));
    long long sum = 0;
    REP (i, N) {
        REP (j, N) {
            cin >> A[i][j];
            sum += A[i][j];
        }
    }
    sum /= 2;

    //ワーシャルフロイドっぽくやればいいのでは？
    REP (i, N) { //経由
        REP (j, N) { //開始
            for (int k = j + 1; k < N; ++k) { //終端
                if (i == j || i == k)
                    continue;
                if (A[j][i] + A[i][k] < A[j][k]) {
                    //printf("i = %d, j = %d, k = %d <\n", i, j, k);
                    cout << -1 << endl;
                    return 0;
                }
                if (A[j][i] + A[i][k] == A[j][k]) {
                    //printf("i = %d, j = %d, k = %d ==\n", i, j, k);
                    if (flag[j][k] == false) {
                        sum -= A[j][k];
                        flag[j][k] = true;
                    }
                }
            }
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する


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

    int N, K;
    cin >> N >> K;

    vector<int> x(N);
    rep(i, 0, N) cin >> x[i];

//    int l = 0;
//    int r = K - 1;
//    ll ans = x[r] - x[l];
    ll ans = INFl;
    for (int i = 0;; ++i) {
        int l = i;
        int r = K - 1 + i;
        if (r >= N) break;
        if (1ll * x[r] * x[l] < 0) {
            chmin(ans, abs(2 * x[r]) + abs(x[l]));
            chmin(ans, abs(x[r]) + abs(2 * x[l]));
        } else {
//            chmin(ans, x[r] - x[l]);
            if (x[r] > 0) {
                chmin(ans, x[r]);
            } else {
                chmin(ans, -x[l]);
            }
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 888
#include "bits/stdc++.h"
using namespace std;
#define OUT(x) cout << #x << " = " << x << endl
#define rep(i, n)             for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r)          for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r)          for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define all(x)                (x).begin(), (x).end()
#define rall(x)               (x).rbegin(), (x).rend()
template<typename T> void pv(T a, T b) { for (T i = a; i != b; i ++) cout << *i << " "; cout << endl; }
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }
int in() { int x; scanf("%d", &x); return x; }
long long lin() { long long x; scanf("%lld", &x); return x; }

int m[202020];
int c[202020];
vector<int> g[202020];
bool used[202020];

void dfs(int s) {
        used[s] = true;
        rep(i, g[s].size()) if (!used[g[s][i]]) dfs(g[s][i]);
}

signed main() { 
        int n;
        cin >> n;
        int s = 0;
        int a[101010];
        int b[101010];
        rep(i, n) {
                cin >> a[i];
                s ^= a[i];
        }
        a[n] = s;
        s = 0;
        rep(i, n) {
                cin >> b[i];
                s ^= b[i];
        }
        b[n] = s;
        int cnt = 0;
        rer(i, 0, n) { 
                m[++ cnt] = a[i];
                m[++ cnt] = b[i];
        }
        sort(m + 1, m + cnt + 1);
        rer(i, 0, n) {
                a[i] = lower_bound(m + 1, m + cnt + 1, a[i]) - m;
                b[i] = lower_bound(m + 1, m + cnt + 1, b[i]) - m;
        }
        //rer(i, 0, n) cout << a[i] << ' ';
        //cout << endl;
        //rer(i, 0, n) cout << b[i] << ' ';
        //cout << endl;
        rer(i, 0, n) { 
                c[a[i]] ++;
                c[b[i]] --;
        }
        rer(i, 0, cnt) {
                if (c[i]) {
                        cout << -1 << endl;
                        return 0;
                }
        }
        int ans = 0;
        rer(i, 0, n) {
                if (a[i] != b[i]) { 
                        g[a[i]].push_back(b[i]);
                        ans ++;
                }
        }
        rer(i, 1, cnt) {
                if (!used[i] && !g[i].empty()) {
                        dfs(i);
                        ans ++;
                }
        }
        if (!g[a[n]].empty()) ans --;
        if (a[n] != b[n]) ans --;
        cout << ans << endl;
        return 0;
}               



Measured memory_bytes: 15360
from math import floor,sqrt

def eratosthenes(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False

    for i in range(2, floor(sqrt(n))+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    return table
  
s = set(eratosthenes(10**5))
l = [0]*(10**5 + 1)
count = 0

for i in s:
  l[i] = 1

count = 0   
L = [0]*(10**5 + 1)

for i in range(1,10**5 + 1):
  if i != 2 and l[i] == 1 and l[(i+1)//2] == 1:
    count += 1
    L[i] = count
  else:
    L[i] = count
    

q = int(input())
for i in range(q):
  l,r = map(int,input().split())
  if L[l] - L[l-1] == 1:
    print(L[r] - L[l] + 1)
  else:
    print(L[r] - L[l])
    

Measured memory_bytes: 11396
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vpii = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using pii = pair<int, int>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define reps(i,n) for(int i = 1; i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define rreps(i,n) for(int i = (int)(n); i > 0; i--)
#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RFOR(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
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; }
const int INF = INT_MAX;
const int MOD = 1000000007;
#define int long long

signed main() {
    int N;
    cin >> N;
    vi X(N);
    rep(i, N) cin >> X[i];
    int ans = INF;
    reps(p, 100) {
        int sum = 0;
        rep(j, N) {
            sum += pow(X[j] - p, 2);
        }
        chmin(ans, sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        if(n / 10 == 9 || n % 10 == 9){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 22612
#include <iostream>
#include <sstream>
#include <string>

using namespace std;
int main()
{
	while (true){
		int h, w;
		cin >> h >> w;
		if (h == 0 && w == 0) break;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if ((i + j) % 2 == 0){
					cout << "#";
				}else{
					cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define PI 3.14159265359
#define sz(c) (int)c.size()
#define len(c) (int)c.length()
#define hcf(a, b) __gcd(a, b)
#define all(c) c.begin(), c.end()
#define vint vector<int>
#define vll vector<ll>
#define vpint vector<pair<int, int>>
#define vpll vector<pair<ll, ll>>
#define tr(con, it) \
    for (auto it = con.begin(); it != con.end(); it++)
#define fr(it, a, b) \
    for (int it = (a); it < (b); it++)
#define present(con, ele) (con.find(ele) != con.end())
#define cpresent(con, ele) (find(all(con), ele) != con.end())
#define maximum(a, b, c) (a > b ? (a > c ? a : c) : (b > c ? b : c))
#define minimum(a, b, c) (a < b ? (a < c ? a : c) : (b < c ? b : c))
typedef long long ll;
typedef long double lf;
typedef unsigned long long lu;
const ll mod = 1e9 + 7;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    unordered_map<int, int> dif, sum;
    cin >> n;
    ll ans = 0;
    fr(i, 1, n + 1)
    {
        int u;
        cin >> u;
        if (present(sum, i - u))
        {
            ans += sum[i - u];
        }
        if (present(dif, i + u))
        {
            ans += dif[i + u];
        }
        sum[u + i]++;
        dif[i - u]++;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 18608
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
long long k;
int n, a[200001], f[200001];
int check(long long mid);
int main (void)
{
	int i;

	scanf("%d%lld",&n,&k);
	for (i=1; i<=n; i++) scanf("%d",&a[i]);
	for (i=1; i<=n; i++) scanf("%d",&f[i]);
	sort(a+1,a+n+1);
	sort(f+1,f+n+1,greater<int>());
	long long l=0, r=1e18, ans, mid;
	while (l<=r) {
		mid=(l+r)>>1;
		if (check(mid)) {
			r=mid-1;
			ans=mid;
		}
		else l=mid+1;
	}
	printf("%lld\n",ans);
	
	return 0;
}
int check(long long mid)
{
	long long t=0;
	int i;
	
	for (i=1; i<=n; i++) {
		if ((long long)a[i]*f[i]<=mid) continue;
		t+=a[i]-mid/f[i];
		if (t>k) break;
	}
	
	if (t>k) return 0;
	else return 1;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;

int main(){
    long long a , b , c , d;
    scanf( "%lld%lld%lld%lld" , &a , &b , &c , &d );
    long long l , r , N1 , N2 , N3;

    l = ceil( (long double)a / c );
    r = b / c;
    N1 = ( r - l + 1 );

    l = ceil( (long double)a / d );
    r = b / d;
    N2 = ( r - l + 1 );

    long long g = __gcd( c , d );
    long long y = d / g;
    long long z = c * y;

    l = ceil( (long double)a / z );
    r = b / z;
    N3 = ( r - l + 1 );
    long long Ans = ( b - a + 1 ) - ( N1 +  N2 - N3 );
    printf( "%lld\n" , Ans );
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)((n>>m)&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll n,a[100010];
int main(){
	scanf("%lld",&n);
	rep(i,0,n)scanf("%lld",a+i);
	sortdown(a,n);
	
	ll ans=0;
	if(n%2==0){
		//2大-2小-min大+max小
		rep(i,0,n/2)ans+=a[i];
		rep(i,n/2,n)ans-=a[i];
		ans*=2;
		ans=ans-a[n/2-1]+a[n/2];
	}else{
		//2大-2小+max小2つ 小がおおい
		ll temp=0;
		rep(i,0,n/2)temp+=a[i];
		rep(i,n/2,n)temp-=a[i];
		temp*=2;
		temp+=a[n/2]+a[n/2+1];
		ans=temp;
		//2大-2小-min大2つ 大がおおい
		temp=0;
		rep(i,0,n/2+1)temp+=a[i];
		rep(i,n/2+1,n)temp-=a[i];
		temp*=2;
		temp-=a[n/2-1]+a[n/2];
		ans=max(temp,ans);
	}
	printf("%lld",ans);
}



Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
  int a,b,c;cin>>a>>b>>c;
  if(a+b==c||a==b+c||a+c==b)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
As = [int(num) for num in input().split()]

As_sorted = sorted(As, reverse=True)
if As_sorted[-1] == 0:
    print(0)
else:
    flag = False
    res = 1
    for num in As_sorted:
        res *= num
        if res > 10**18:
            flag = True
            break            
    if flag:
        print(-1)
    else:
        print(res)

Measured memory_bytes: 21708
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int n;
    cin>>n;
    int i,j;
    long long a[n],ans=0;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        ans+=a[i]-1;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

string s[3] = {"Sunny", "Cloudy", "Rainy"};

int main() {
    string t; cin >> t;
    rep(i,3) {
        if (s[i] == t) cout << s[(i+1)%3] << endl;
    }
}

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

/*
   AtCoder contest code
   coder : yoichidon
 */

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        List<Character> stone = new ArrayList<>(S.length());
        for(int i=0; i<S.length(); i++) {
            stone.add(S.charAt(i));
        }

        //end : wwwwwbbbb
        long ans = 0;
        int w=0, b=0;
        for(int i=0; i<stone.size(); i++){
            char last = stone.get(i);
            if(last=='B') b++;
            else{
                //wwwwwbbbbW -> wwwwwbbbwb -> ... -> wwwwwwbbbb
                ans += b;
                w++;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 26544
n,m = map(int, input().split())
switch = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
count = 0
for i in range(2**n):
    flag = True
    for j in range(m):
        on = 0
        for k in switch[j][1:]:
            if (i>>k-1)&1:
                on +=1
        if on%2 != p[j]:
            flag = False
    if flag:
        count +=1
print(count)

Measured memory_bytes: 40816
import sys

lineNumber = 0

#for line in ["3", "6", "9", "7", "5"]:
for line in sys.stdin.readlines():
    lineNumber += 1

    # get data
    List = map(int, line.strip().split(" "))

    n = List[0]
    ans = 1
    for i in xrange(2, n+1): ans *= i
    print ans

Measured memory_bytes: 4196
n, m = [int(i) for i in input().split()]
A = [[] for i in range(n+1)]
B = [[] for i in range(n+1)]

for i in range(m):
    a, b = [int(i) for i in input().split()]
    A[a].append(b)
    B[b].append(a)

flag = [False] * (n+1)
flag[0] = True
cnt = 0

def dfs(i, flag):
    flag[i] = True
    for b in A[i]+B[i]:
        if not flag[b]:
            dfs(b, flag[:])
    if all(flag) == True:
        global cnt
        cnt += 1

dfs(1, flag[:])
print(cnt)


Measured memory_bytes: 3064
/// by ztx
/// blog.csdn.net/hzoi_ztx
/// for c++11, using google c++ style
#include <bits/stdc++.h>
#define rep(i, l, r) for (i = (l); i <= (r); i++)
#define rep_(i, l, r) for (i = (l); i < (r); i++)
#define rev(i, r, l) for (i = (r); i >= (l); i--)
#define rev_(i, r, l) for (i = (r); i > (l); i--)
#define Rep(i, l, r) for (int i = (l); i <= (r); i++)
#define Rep_(i, l, r) for (int i = (l); i < (r); i++)
#define Rev(i, r, l) for (int i = (r); i >= (l); i--)
#define Rev_(i, r, l) for (int i = (r); i > (l); i--)
#define each(e, s) for (e : s)
#define Each(e, s) for (auto e : s)
#define r(args...) read(args)
typedef long long ll;
typedef double lf;
typedef long double llf;
typedef unsigned uint;
typedef std::pair<int, int> pii;
int g_ch, g_neg, g_eof;
template <typename ret_t>
inline void read(ret_t& ret) {
    ret = g_ch = g_neg = g_eof = 0;
    while (g_ch < '!') g_ch = getchar();
    if (g_ch == '-') g_neg = true, g_ch = getchar();
    while (g_ch > '!') ret = ret * 10 + g_ch - '0', g_ch = getchar();
    if (g_neg) ret = -ret;
    g_eof = g_ch == EOF;
}
template <typename ret_t, typename... args_t>
inline void read(ret_t& x, args_t&... args) {
    read(x), read(args...);
}

/*
将n拆为(2^k)-1的和
每一个(2^k)-1可以由k+1长度的相同数字的串得到

太长

分为左右两部分，左右长度相同都为L时，算上空串答案数为2^L，
且左右同时在前面或后面添加相同字符，答案*2

所以可以构造使得答案为n+1

从高位开始，两部分同时在前或在后添加相同字符，代表原来的结果*2
如果遇到1，则应该一侧在前面添加字符，另外一个在后面添加相同字符
此时没有字符同时在这个字符前或后，即答案+1
*/

ll n;
int idx;
std::deque<int> l, r;

inline void calc(ll n) {
    if (n == 1) return;
    calc(n >> 1);
    ++idx, l.push_back(idx), r.push_back(idx);
    if (n & 1) ++idx, l.push_front(idx), r.push_back(idx);
}

int main() {
    r(n);
    calc(n + 1);
    printf("%d\n", l.size() + r.size());
    Each(a, l) printf("%d ", a);
    Each(b, r) printf("%d ", b);
    // END:
    getchar(), getchar();
    return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);

  int n;
  cin >> n;
  vector<pair<ll, ll>> tasks;
  rep(i, n) {
    ll a, b;
    cin >> a >> b;
    tasks.emplace_back(a, b);
  }
  sort(tasks.begin(), tasks.end(),
       [](const pair<ll, ll>& a, const pair<ll, ll>& b) {
         return a.second < b.second;
       });

  ll now = 0;
  rep(i, n) {
    now += tasks[i].first;
    if (now > tasks[i].second) {
      cout << "No" << endl;  
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 6384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		int period = Integer.parseInt(new BufferedReader(new InputStreamReader(System.in), 64).readLine());
		int val = 100;//壱百千円
		for (; 0 < period; period--) {
			val = val * 105 % 100 == 0 ? (int) (val * 1.05) : (int) (val * 1.05) + 1;
		}
		System.out.println(val * 1000);
	}
}

Measured memory_bytes: 16844
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int a[100002],num=300000001;
int main(){
	num=300000001;
	int n,k,c=0;
	bool iscina=0;
	cin>>n>>k;
	a[0]=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(i>=1&&a[i-1]<0&&a[i]>0){
			c=i;
		}else if(a[i]==0){
			c=i;
			iscina=1;
		}else if(i==n-1&&a[i]<0){
			c=n;
			cout<<abs(a[n-k]);
			return 0;
		}
	}
//	cout<<"---------"<<endl;//
//	cout<<c<<endl;//
	int start,end;
	if(iscina){
		start=c-k+1;
		end=c;
//		cout<<1<<endl;//
	}else{
		start=c-k;
		end=c;
//		cout<<0<<endl;//
	}
	if(start<0){
		start=0;
//		cout<<'s'<<endl;//
	}
	if(end+k>n){
		end=n-k-1;
//		cout<<'d'<<endl;//
	}
	if(end<0){
		end=0;
	}
//	cout<<"---------"<<endl;//
//	cout<<"end:"<<end<<endl;//
//	cout<<"start:"<<start<<endl;//
//	cout<<"num:"<<num<<endl;//
//	cout<<"---------"<<endl;//
	for(int i=start;i<=end;i++){
		num=min(abs(a[i]-a[i+k-1])+abs(a[i+k-1]),min(abs(a[i]-a[i+k-1])+abs(a[i]),num));
//		cout<<abs(a[i]-a[i+k-1])+abs(a[i+k-1])<<endl;//
///		cout<<abs(a[i]-a[i+k-1])+abs(a[i])<<endl;//
//		cout<<num<<endl;//
//		cout<<i<<"---------"<<endl;//
	}
//	cout<<"A";//
	cout<<num;
	return 0;
}

Measured memory_bytes: 640
import java.util.*

fun main(args: Array<String>) {
    agc005a()
}

// スタック使ってみる版
fun agc005a() {
    val x = readLine()!!

    val stack = Stack<Char>()
    x.forEach { c ->
        if (c == 'T') {
            if (stack.isNotEmpty() && stack.peek() == 'S') stack.pop() else stack.push(c)
        } else {
            stack.push(c)
        }
    }

    println(stack.size)
}


Measured memory_bytes: 39136
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using namespace std;

int main() {
    fastIO;
    vector<int> vi(3);
    rep(i, 3) cin >> vi.at(i);
    sort(vi.begin(), vi.end());

    int cost = 0;
    for (int i = 1; i <= 2; i++) {
        cost += abs(vi.at(i) - vi.at(i - 1));
    }
    cout << cost << endl;
}


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

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

    int ans = 1;
    if(N>=64) ans = 64;
    else if(N>=32) ans = 32;
    else if(N>=16) ans = 16;
    else if(N>=8) ans = 8;
    else if(N>=4) ans = 4;
    else if(N>=2) ans = 2;

    cout<<ans<<endl;

}

Measured memory_bytes: 256
n, k = gets.split.map(&:to_i)

arr = []

n.times do
  arr << gets.to_i
end

arr = arr.sort
tmp = arr[k-1] - arr[0]
(n - k + 1).times do |i|
  num = arr[i+k-1] - arr[i]
  tmp = [tmp, num].min
end

p tmp

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

class UnionFind {
public:
  UnionFind(const unsigned int n) : mParent(std::vector<int>(n, -1)) {
  }

  // indexがどのグループに属しているか調べる
  unsigned int GetRoot(const unsigned int index) {
    if (mParent.at(index) < 0) {
      return index;
    } else {
      mParent.at(index) = GetRoot(mParent.at(index));
      return mParent.at(index);
    }
  }

  // indexの属しているグループの頂点数を調べる
  unsigned int GetSize(const unsigned int index) {
    return -1 * mParent.at(GetRoot(index));
  }

  bool Connect(const unsigned int index_a, const unsigned int index_b) {
    // fromとtoを直接つなぐのではなく，root(index_a)にroot(index_b)をくっつける．
    unsigned int a_root = GetRoot(index_a);
    unsigned int b_root = GetRoot(index_b);
    if (a_root == b_root) {
      return false;
    }

    // 頂点数が多い方をAとしたい
    if (GetRoot(a_root) < GetRoot(b_root)) {
      std::swap(a_root, b_root);
    }

    mParent.at(a_root) += mParent.at(b_root);
    mParent.at(b_root) = a_root;

    return true;
  }

private:
  // 親の番号を格納する．親だった場合は-（その集合のサイズ）．
  std::vector<int> mParent;
};


int main() {
  unsigned int n, m;
  std::cin >> n >> m;

  std::vector<unsigned int> a_array(m), b_array(m);
  for (unsigned int i = 0; i < m; ++i) {
    std::cin >> a_array.at(i) >> b_array.at(i);
    a_array.at(i) -= 1;
    b_array.at(i) -= 1;
  }

  UnionFind uf(n);
  std::vector<unsigned long> ans(m);
  ans.at(m - 1) = static_cast<unsigned long>(n) * (n - 1) / 2;
  for (unsigned int i = m - 1; i > 0; --i) {
    const unsigned int& a = a_array.at(i);
    const unsigned int& b = b_array.at(i);

    const unsigned int a_size = uf.GetSize(a);
    const unsigned int b_size = uf.GetSize(b);

    if (uf.GetRoot(a) != uf.GetRoot(b)) {
      ans.at(i - 1) = ans.at(i) - static_cast<unsigned long>(a_size) * b_size;
      uf.Connect(a, b);
    } else {
      ans.at(i - 1) = ans.at(i);
    }
  }

  for (unsigned int i = 0; i < m; ++i) {
    std::cout << ans.at(i) << std::endl;
  }

  return 0;
}


Measured memory_bytes: 3328
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

#define REP(i, N) for(int (i) = 0; (i) < (N); i++)
#define MAX 1 << 20

bool isPrime(int n){
    if(n <= 1) return false;
    if(n == 2) return true;
    for(int i = 2; i*i <= n; i++)
        if(n % i == 0) return false;

    return true;
}

int main(){
    int n, a[50001], ans[100000];
    scanf("%d", &n);

    a[0] = 0;
    REP(i, 50000){
        int p = i*2+1;
        a[i+1] = a[i] + (isPrime(p) && isPrime((p+1)/2) ? 1 : 0);
    }

    int li, ri; 
    REP(i, n){
        scanf("%d %d", &li, &ri);
        ri = (ri+1)/2;
        li = (li+1)/2;
        ans[i] = a[ri] - a[li-1];
    }
    REP(i, n)
        printf("%d\n", ans[i]);
    return 0;
}

Measured memory_bytes: 1152
#include <iostream>

using namespace std;

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

    if (r >= 2800) {
        cout << "AGC" << endl;
    } else if (r >= 1200) {
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }
}

Measured memory_bytes: 3136
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = unsigned long long;
int main(){
int n;cin>>n;
vector<ll> a;
for(int i=0;i<3*n;i++){
 ll ai; cin>>ai;
 a.push_back(ai);
}
sort(a.begin(),a.end());
ll sum =0;
for(int i=0;i<n;i++){
    sum += a[a.size() -i*2-2];
}
cout<<sum<<endl;
return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m, v, p;
  cin >> n >> m >> v >> p;
  vector<int> a(n);
  for (auto&& e : a) {
    cin >> e;
  }
  sort(begin(a), end(a));
  auto chk = [&](int k) {
    auto b = a;
    b[k] += m;
    if (b[k] < a[n - p]) {
      return false;
    }
    if (v <= p) {
      return true;
    }
    sort(begin(b), end(b));
    int j = lower_bound(begin(b), end(b), a[k] + m) - begin(b);
    auto r = (long long)(v - p) * m;
    long long s = 0;
    for (int i = 0; i < n - p; ++i) {
      s += min(b[j] - b[i], m);
    }
    return s >= r;
  };
  int ng = -1, ok = n - p;
  while (ok - ng > 1) {
    int mid = (ng + ok) / 2;
    (chk(mid) ? ok : ng) = mid;
  }
  cout << n - ok << '\n';
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define For(i,a,b) for(int i=a;i<b;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
#define debug(x) cerr << x << endl
#define Complex complex<double>
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<59;
const ll mod = (int)1e9 + 7;

int main() {
    int n;
    cin >> n;
    ll a[n];
    rep(i,n)cin >> a[i];
    ll dp[n][3];
    rep(i,n){
        rep(j,3)dp[i][j]=-INF;
    }
    rep(i,n){
        if(i==0)dp[0][0]=a[i];
        else if(i==1)dp[1][1]=a[i];
        else if(i==2){
            dp[2][2]=a[i];
            dp[2][0]=a[i]+dp[0][0];
        }
        else if(i==3){
            dp[i][1]=max(dp[i-2][1]+a[i],dp[i-3][0]+a[i]);
            dp[i][2]=max(dp[i-2][2]+a[i],dp[i-3][1]+a[i]);
        }
        else{
            dp[i][0]=dp[i-2][0]+a[i];
            dp[i][1]=max(dp[i-2][1]+a[i],dp[i-3][0]+a[i]);
            dp[i][2]=max({dp[i-2][2]+a[i],dp[i-3][1]+a[i],dp[i-4][0]+a[i]});
        }
      	//debug(dp[i][0]);
    }
  	/*rep(i,n){
      rep(j,3)cerr << dp[i][j] << ' ';
      cerr << endl;
    }*/
    if(n%2)cout << max({dp[n-3][0],dp[n-2][1],dp[n-1][2]});
    else cout << max(dp[n-2][0],dp[n-1][1]);
	
    


}

/*



 */




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

int main(){
	int n;
	string s;
	cin >> n >> s;
	vector<vector<int>> l(n, vector<int>(26));
	rep(i, 26){
		l.at(0).at(i) = 0;
	}
	l.at(0).at(s.at(0) - 'a')++;
	for(int i=1; i<n; i++){
		rep(j, 26) l.at(i).at(j) = l.at(i-1).at(j);
		l.at(i).at(s.at(i) - 'a')++;
	}
	int ma = 0;
	for(int i=1; i<n; i++){
		int sum = 0;
		rep(j, 26) if(l.at(i).at(j) > 0 && l.at(n-1).at(j) - l.at(i).at(j) > 0) sum++;
		if(ma < sum) ma = sum;
	}
	cout << ma << endl;
	return 0;
}


Measured memory_bytes: 256