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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define pb push_back
#define mp make_pair
#define INF 999999999
#define MOD 1000000007
#define sp ' '
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()

//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef map<int, int> mint;
typedef set<int> sint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


int mod(int a, int b){return (a%b+b)%b;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b, ll c){ll ans=1; rep(i, b){ans=ans*a%c;} return ans;}


template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i] << endl;}}

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ddx[8] = {1,0,-1,0,1,-1,-1,1};
const int ddy[8] = {0,1,0,-1,1,1,-1,-1};




template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}


vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.pb(buffer);
    }
    return v;
}




int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    vint a(n);
    rep(i, n){
        cin >> a[i];
    }

    int mx = *max_element(ALL(a));
    int mn = *min_element(ALL(a));

    int ans = INF;
    FOR(i, mn, mx+1){
        int tmp = 0;
        rep(j, n){
            tmp += pow(a[j]-i, 2);
        }
        ans = min(ans, tmp);

    }

    ppp(ans);


    return 0;
}


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

	@scala.annotation.tailrec
	def loop(start: Int, end: Int)(f: Int => Unit): Unit =
		if (start < end) {
			f(start)
			loop(start + 1, end)(f)
		}

	val a = Scanner.nextInt

	pw.println(a + a * a + a * a * a)
	pw.flush()
}

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

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

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

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

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

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

		go(b)
	}

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


Measured memory_bytes: 54472
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

S=list(ns())

ans=0
for i in range(len(S)//2):
    if(S[i]!=S[-i-1]):
        ans+=1

print(ans)
        
    

Measured memory_bytes: 5588
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,k=map(int,readline().split())
r,s,p=map(int,readline().split()) #gu cyoki pa
t=input()
dic={'r':p,'s':r,'p':s}
dic2={'r':'p','s':'r','p':'s'}
dic3={'r':'s','s':'p','p':'r'}
h=''

c=0
for i in range(k):
  c+=dic[t[i]]
  h+=dic2[t[i]]
for i in range(k,n):
  if h[i-k]!=dic2[t[i]]:
      c+=dic[t[i]]
      h+=dic2[t[i]]
  else:
    if i+k<n:
      if dic2[t[i+k]]!=t[i]:
        h+=t[i]
      else:
        h+=dic3[t[i]]
    else:
      h+=t[i]
print(c)

Measured memory_bytes: 3444
#include <iostream>
#include <cmath>

using namespace std;

typedef unsigned long long ullong;

ullong power(ullong x, ullong n, ullong M)
{
  ullong res = 1;
  if (n > 0)
  {
    res = power(x, n / 2, M);
    if (n % 2 == 0)
    {
      res = (res * res) % M;
    }
    else
    {
      res = (((res * res) % M) * x) % M;
    }
  }
  return res;
}

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

  cout << power(m, n, 1000000007) << endl;

  return 0;
}


Measured memory_bytes: 3108
#include<stdio.h>

int gcd(int a,int b)
{
    int i,temp=1;
    if(a==0) return b;
    else if(b==0) return a;
    else
    {
        while(b!=0)
        {
            temp=b;
            b=a%b;
            a=temp;
        }

        return a;
    }


}

int main()
{
    int a,i,j,k,x;
    long long int sum=0;

    scanf("%d",&a);

    for(i=1;i<=a;i++)
    {
        for(j=1;j<=a;j++)
        {
            for(k=1;k<=a;k++)
            {
                x=gcd(i,j);
                sum=sum+gcd(x,k);
            }
        }
    }

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

    return 0;
}


Measured memory_bytes: 1732
n, y = [int(x) for x in input().split()]

def search():
    for a in range(0, n+1):
        for b in range(0, n+1 - a):
            c = n - a - b
            total = 10000*a + 5000*b + 1000*c
            if (y == total and n == a + b + c):
                return (a, b, c)
    return (-1,-1,-1)
print("%d %d %d" % search())


Measured memory_bytes: 3060
L = [0 for i in range(5)]
for i in range(5):
    L[i] = int(input())

L2 = [0 for i in range(5)]
time = 0
for i in range(5):
    L2[i] = L[i]%10
    if L2[i] > 0:
        time += L[i]//10*10+10
    else:
        time += L[i]
    
L2.sort()
for i in range(5):
    if L2[i] > 0:
        time -= (10-L2[i])
        break

print(time)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N; cin >> N;
    vector<int> A(N); for (int& a : A) cin >> a;
    vector<vector<long long>> dp(N+1, vector<long long>(N+1)); // dp[i][j]: score of A[i..j)
    for (int i = 0; i <= N; i++) {
        dp[i][i] = 0;
    }
    for (int n = 1; n <= N; n++) {
        for (int i = 0; i <= N - n; i++) {
            dp[i][i+n] = max(A[i] - dp[i+1][i+n], A[i+n-1] - dp[i][i+n-1]);
        }
    }
    cout << dp[0][N] << endl;
    return 0;
}

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

int main() {
int N, M;
cin >> N >> M;
vector<int> p(M);
vector<string> S(M);
vector<bool> judge(N); //n問目に正答したことがあるかどうかを判定
vector<int> cAC(N), cWA(N);
for (int i = 0; i < M; i++) {
    cin >> p.at(i) >> S.at(i);
}
for (int i = 0; i < N; i++) {
    judge.at(i) = false;
    cAC.at(i) = 0;
    cWA.at(i) = 0;
}
int n;
for (int i = 0; i < M; i++) {
    n = p.at(i);
    if (S.at(i) == "AC" && judge.at(n - 1) == false) {
        judge.at(n - 1) = true;
        cAC.at(n - 1)++;
    }
    if (S.at(i) == "WA" && judge.at(n - 1) == false) {
        cWA.at(n - 1)++;
    }
}
int AC = 0,WA = 0;
for (int i = 0; i < N; i++) {
    AC += cAC.at(i);
    if (judge.at(i) ==false) {
        cWA.at(i) = 0;
    }
    WA += cWA.at(i);
}
cout << AC << " " << WA << endl;
}

Measured memory_bytes: 6912
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;

int main() {
  
  int a,b,c,d,x;
  string s,ss,sss;
  
  int ans = 0;
  string anss = "";
  
  cin >> s;
  
  int ab [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  int result3 = std::max({a, b, c});
//--------------------------------------------------------------------------------

  if(s[0] == '1') ans++;
  if(s[1] == '1') ans++;
  if(s[2] == '1') ans++;
  
  cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int w, h, t, p;
int d[20], c[20];
int x[20], y[20];

void solve() {
	int cnts[2][64][64] = {0};
	int i, j, k;
	
	rep(i, h) rep(j, w) cnts[0][i][j] = 1;
	rep(i, t) {
		rep(j, h) {
			rep(k, w) {
				int nj = j;
				int nk = k;
				if (d[i] == 2 && nj < c[i]) nj = c[i] + (c[i] - nj) - 1;
				if (d[i] == 1 && nk < c[i]) nk = c[i] + (c[i] - nk) - 1;
				cnts[1][nj][nk] += cnts[0][j][k];
			}
		}
		
		//原点を求める
		int minJ = 114514;
		int minK = 114514;
		rep(j, 2 * h) {
			rep(k, 2 * w) {
				if (cnts[1][j][k] > 0) {
					minJ = min(minJ, j);
					minK = min(minK, k);
				}
			}
		}
		
		//コピー
		rep(j, 2 * h) rep(k, 2 * w) cnts[0][j][k] = 0;
		rep(j, 2 * h) {
			rep(k, 2 * w) {
				if (j < minJ || k < minK) continue;
				cnts[0][j - minJ][k - minK] = cnts[1][j][k];
			}
		}
		rep(j, 2 * h) rep(k, 2 * w) cnts[1][j][k] = 0;	//cnt1の初期化を忘れないこと！
	}
	
	rep(i, p) {
		cout << cnts[0][y[i]][x[i]] << endl;
	}
}

int main() {
	while (cin >> w >> h >> t >> p) {
		if (!w) break;
		int i;
		rep(i, t) cin >> d[i] >> c[i];
		rep(i, p) cin >> x[i] >> y[i];
		solve();
	}
	return 0;
}


Measured memory_bytes: 3120
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 200005
#define ll long long
int a[N], b[N], n;
priority_queue<pair<int, int> > q;
ll ans;
int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", &b[i]);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]), q.push(make_pair(a[i], i));
	while (!q.empty())
	{
		pair<int, int>t = q.top();
		q.pop();
		if (b[t.second] == t.first) continue;
		if (b[t.second] > t.first)
		{
			puts("-1");
			return 0;
		}
		int dis = t.first - b[t.second];
		int sum = a[t.second - 1] + a[t.second + 1];
		if (t.second == 1)
			sum += a[n];
		if (t.second == n)
			sum += a[1];
		if (sum > dis)
		{
			puts("-1");
			return 0;
		}
		int add = dis / sum;
		ans += add;
		a[t.second] -= add * sum;
		t.first = a[t.second];
		q.push(t);
	}
	printf("%lld\n", ans);
}


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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

// 約数
set<ll> f(ll A) {
  set<ll> s;
  for (ll i = 1; i*i<=A; i++) {
    if (A % i != 0)
      continue;
    s.insert(i);
    s.insert(A/i);
  }
  return s;
}

// 公約数
vector<ll> g(set<ll> x, set<ll> y) {
  vector<ll> s;
  for (auto e : x)
    if (y.find(e) != y.end())
      s.push_back(e);
  sort(begin(s), end(s));
  return s;
}

signed main() {
  ll A, B, ans=1;
  cin >> A >> B;
  auto s = g(f(A), f(B));
  //cout << "len(s)" << s.size() << endl;

  // 素数をカウント
  rep(i, s.size()){
    if (s[i] == 1)
      continue;
    if (s[i] == -1)
      continue;
    ans++;
    for(ll j=i+1; j<s.size(); j++){
      if (s[j] != -1 && s[j] % s[i] == 0) {
        s[j] = -1;
      }
    }
  }
  //for (auto e : s) {
  //  cout << e << " ";
  //}
  //cout << endl;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
	int num,x,sum=0;
	cin>>num>>x;
	int arr[x];
	for(int i=0;i<x;i++)
	{
		cin>>arr[i];
	}
	for(int i=0;i<x;i++)
	{
		sum+=arr[i];
	}
	if(sum>num)
	{
		cout<<"-1"<<endl;
	}
	else{
		cout<<num-sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
#include <fstream>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>
using namespace std;
typedef int64_t ll;
typedef uint64_t ull;
constexpr uint64_t L1 = 1ull;
constexpr ull bit(int n){ return 1ull << n;}

// for(auto && i : Range(l,r))
// -> i = [l..r)
class Range {
private: struct It{ int x; int operator*(){return x;}
 bool operator!=(It& lhs){ return x<lhs.x;} void operator++(){++x;} }; It l,r;
public: Range(int n):l({0}),r({n}){} Range(int i,int n):l({i}),r({n})
 {}It& begin(){return l;} It& end(){return r;} };

void solve(istream& cin) {
    int N;
    cin >> N;
    ll ans = 0;
    for (int i = 0; i < N; ++i) {
        int l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
}

int main(int argc, char *argv[]) {
    string FileName("B1"), Modifier("MEPH_");
    string ExecutionName = Modifier + FileName;
    string sub(argv[0]);
    if(sub.size() > ExecutionName.size())
        sub = sub.substr(sub.size()-ExecutionName.size(), ExecutionName.size());
    cerr << sub << endl;
    if (sub != ExecutionName) {
        cin.tie(0);
        ios::sync_with_stdio(false);
        solve(cin);
    }
    else {
        string inFile = "sample.txt";
        auto fs = fstream(inFile, fstream::in);
        solve(fs);
    }
}

Measured memory_bytes: 256
#include <iostream>                                             
using namespace std;                                            
                                                                
int main() {                                                    
  int W, H, x, y, r;                                            
  cin >> W >> H >> x >> y >> r;                                 
  if (x>=r && W-x>=r && y>=r && H-y>=r) {                       
    cout << "Yes" << endl;                                      
  } else {                                                      
    cout << "No" << endl;                                       
  }                                                             
  return 0;                                                     
}                    

Measured memory_bytes: 3084
#!/usr/bin/python3
# -*- coding:utf-8 -*-

from math import sqrt

def main():
  a, b, c = map(int, input().split())
  x = c - a - b
  if x > 0 and 4*a*b < x**2:
    print('Yes')
  else:
    print('No')

if __name__=='__main__':
  main()



Measured memory_bytes: 2940
/*
じょえチャンネル
https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
宣伝しろという圧を受けました
僕は出演してないです、fuppyファンの方ごめんなさい
//*/

#include <bits/stdc++.h>
 
//#include <unistd.h>
//#include <iostream>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
//#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

signed main() {
	fio();
	
	int n;
	cin >> n;
	vi x(n);
	rep (i, n) cin >> x[i];

	int ans = 0;
	int ma = inf;
	rep (j, 101) {
		int sum = 0;
		rep (i, n) {
			sum += (j - x[i]) * (j - x[i]);
		}
		chmin(ma, sum);
	}
	cout << ma << endl;
	
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] num = new int[n];
		
		int flag = 0;
		
		for (int i = 0; i < m; i++) {
			int s = sc.nextInt();
			int c = sc.nextInt();
			
			//「S=1,c=0」かつ「出力する整数が1桁ではない」
			//もしくは
			//「s桁目が0ではない」かつ「s桁目がcと一致しない」
			if(s == 1 && c ==0 && n != 1 || num[s - 1] != 0 && num[s - 1] != c){
				flag = 1;
			}else{
				num[s - 1] = c;
			}
		}
		
		if(flag == 1){
			System.out.println("-1");
		}else{
			//「1桁目が0」かつ「出力する整数が1桁ではない」
			if(num[0] == 0 && n != 1){
				num[0] = 1;
			}
			for (int i = 0; i < n; i++) {
				System.out.print(num[i]);
			}
		}
	}
}


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

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end());
#define MIN(vec) *std::min_element(vec.begin(), vec.end());
#define MAXI(vec)                                                              \
  std::distance(vec.begin(), *std::max_element(vec.begin(), vec.end()));
#define MINI(vec)                                                              \
  std::distance(vec.begin(), *std::min_element(vec.begin(), vec.end()));
#define BIT(n, num) std::bitset<(n)>((num)).to_string()
#define MATMUL(a, b, c)                                                        \
  REP(i, a.size())                                                             \
  REP(j, b[0].size()) REP(k, a[0].size()) c[i][j] += a[i][k] * b[k][j];
#define CLA2(a) REP(i, a.size()) REP(j, a[0].size()) a[i][j] = 0;
#define REV(T) greater<T>()

ll pow_(ll a, ll n) {
  ll x = 1;
  while (n > 0) {
    if (n & 1)
      x = (x * a) % MOD;
    a = (a * a) % MOD;
    n >>= 1;
  }
  return x;
}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

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

ll factorial(int n) {
  ll ans = 1;
  for (int i = 2; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}
ll P(int n, int m) {
  ll ans = 1;
  for (int i = m + 1; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}
ll power(int n, int m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = power(n, m / 2);
    return (tmp * tmp) % MOD;
  } else {
    return (n * power(n, m - 1)) % MOD;
  }
}
ll C(int n, int m) {
  return (P(n, n - m) * power(factorial(m), MOD - 2)) % MOD;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  string S;
  string S2 = S;
  ll A = 0, C = 0;
  cin >> S;
  for (ll i = 0; i < S.size(); i++) {
    if (S[i] == 'B') {
      C++;
    }
    if (S[i] == 'W') {
      A += C;
    }
  }

  cout << A << endl;

  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>

using namespace std;


/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back


/*---  Type ---*/
typedef long long ll;


/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// 4-direction
int dy4[] = {0,  1, -1,  0};
int dx4[] = {1,  0,  0, -1};

// 8-direction
int dy8[] = {0,  1,  1,  1,  0, -1, -1, -1};
int dx8[] = {1,  1,  0, -1, -1, -1,  0,  1};

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << max(a*b, c*d) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define trace(x)                  cerr<<#x<<": "<<x<<endl
#define trace2(x, y)               cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl	
 
int main() 
{

	cin.sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll  n; 
    cin>>n; 
    ll x=1,y=1; 
ll    ans=0; 
    while(n) 
      { 
        ans+=x;
      x<<=1; 
      n/=2;
      } 
      cout<<ans;
   return 0; 
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007

using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) x*=i;
    return x;
}

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

ll lcm(ll a,ll b)
{
   return a/gcd(a,b)*b;
}



int main(){
    ll n,k=0,l=0;
    cin>>n;
    
    vector<ll> a(n),b(n);
    rep(i,n) cin>>a[i];
    
    rep(i,n){
        if(i%2==0) {
            b[k]=a[n-1-i];
            k++;
        }else{
            b[n-1-l]=a[n-1-i];
            l++;
        }
    }
    rep(i,n-1) cout<<b[i]<<" ";
    cout<<b[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 5248
#include <stdio.h>
#include <limits.h>
 int main() { int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    
    if(a>b)
    {int temp=a;a=b;b=temp;}
    if(b>c)
    {int temp=b;b=c;c=temp;}
    if(a>b)
    {int temp=a;a=b;b=temp;}
    if(b>c)
    {int temp=b;b=c;c=temp;}
    
    if(c==a+b)
    printf("Yes");
    else printf("No");
  
    
 return 0; }

Measured memory_bytes: 128
#include<algorithm>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<deque>
#include<functional>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
#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 EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
template<typename T>
constexpr auto ALL(T v) { return v.begin(), v.end(); }
typedef long long ll;

using namespace std;

void Main() {
	string a, b;
	cin >> a >> b;
	int ans = 0;
	for (int i = 0; i < a.length(); i++) {
		if (a[i] != b[i])ans += 1;
	}
	cout << ans << endl;
}

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


Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    int A,V,B,W,T;
    cin >> A >> V >> B >> W >> T;
    if(V <= W) {
        cout << "NO" << endl;
    }
    else if((V-W)*T >= abs(A-B)) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

const i64 mod = 1e9 + 7;
i64 fact_memo[200001];
i64 fact(i64 x) {
  if (x == 0) return 1;
  if (fact_memo[x]) return fact_memo[x];
  return fact_memo[x] = x * fact(x - 1) % mod;
}
i64 ipow(i64 a, i64 b) {
  return (b & 1 ? a : 1) * (b > 1 ? ipow(a * a % mod, b >> 1) : 1) % mod;
}
i64 inv(i64 x) {
  return ipow(x, mod - 2);
}
i64 fact_inv(i64 x) {
  return inv(fact(x));
}
i64 perm(i64 a, i64 b) {
  return fact(a) * fact_inv(a - b) % mod;
}
i64 conb(i64 a, i64 b) {
  return fact(a) * fact_inv(b) % mod * fact_inv(a - b) % mod;
}

i64 n, x, dp[2][100001];
vector<i64> s;
int main() {
  cin >> n >> x;
  read_n(s, n);
  sort(begin(s), end(s), greater<i64>());

  dp[0][x] = 1;
  for (int i = 0; i < n; ++i) {
    i64 a = inv(n - i), b = (1 - a + mod) % mod;
    int from = i % 2, to = (i + 1) % 2;
    fill(begin(dp[to]), end(dp[to]), 0);
    for (i64 j = 0; j <= 100000; ++j) {
      dp[to][j % s[i]] += dp[from][j] * a % mod;
      dp[to][j] += dp[from][j] * b % mod;
    }
    for (i64 j = 0; j <= 100000; ++j) {
      dp[to][j] %= mod;
    }
  }

  i64 e = 0;
  for (i64 x = 0; x <= 100000; ++x) {
    (e += x * dp[n % 2][x]) %= mod;
  }
  i64 ans = e * fact(n) % mod;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
class Found < Exception
  def initialize(args)
    @args = args
  end

  def args()
    @args
  end
end

K = 3500

def f(m, h, w)
  a = m * h * w
  b = 4 * h * w - m * (h + w)
  return (b > 0) ? (a % b) == 0 : false
end

def g(m, h, w)
  a = m * h * w
  b = 4 * h * w - m * (h + w)
  return a / b
end

m = gets.chomp.to_i
begin
  K.times do |h|
    K.times do |w|
      if f(m, h+1, w+1) then
        raise Found.new([h+1, w+1])
      end
    end
  end
rescue Found => e
  h, w = e.args
  n = g(m, h, w)
  puts [h, n, w].map(&:to_s).join(' ')
end

Measured memory_bytes: 1916
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++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 all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
 
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin>>s;
  char a[30];
  for(char i='a';i<='z';i++){
    int cnt=0;
    for(int j=0;j<s.size();j++){
      if(s[j]==i)
        cnt++;
      if(cnt>1){
        cout<<"no"<<endl;
        return 0;
      }
    }
  }
  cout<<"yes"<<endl;
}
     







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

int main(){
  int N, K;
  cin >> N >> K;
  vector<char> D(K);
  for(int i=0; i<K; i++) cin >> D.at(i);
  int ans;
  for(int i=N; N<100000; i++){
    string S=to_string(i);
    int cnt=0;
    for(int j=0; j<S.size(); j++){
      for(int k=0; k<K; k++){
        if(S.at(j)==D.at(k)) cnt++;
      }
    }
    if(cnt==0){
      ans=i;
      break;
    }
  }
  cout << ans << endl;
}

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

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


    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<set>
#include<map>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define ROF(i,b,a) for (int i=(b);i>(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,n-1,-1)

typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;
typedef pair<int,int> Pi;

constexpr int INF = 1e9 + 7;
constexpr int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main() {
    int n; cin>>n;
    int a[n]; REP(i,n) cin>>a[i];
    i64 ans1 = 0;
    i64 sum = 0;
    REP(i,n) {
        sum += a[i];
        if (i%2==0) {
            if (sum<=0) {
                ans1 += 1-sum;
                sum = 1;
            }
        }
        if (i%2==1) {
            if (sum>=0) {
                ans1 += sum+1;
                sum = -1;
            }
        }
    }
    i64 ans2 = 0;
    sum = 0;
    REP(i,n) {
        sum += a[i];
        if (i%2==1) {
            if (sum<=0) {
                ans2 += 1-sum;
                sum = 1;
            }
        }
        if (i%2==0) {
            if (sum>=0) {
                ans2 += sum+1;
                sum = -1;
            }
        }
    }
    cout<<min(ans1,ans2)<<endl;
}


Measured memory_bytes: 640
X=int(input())
dp=[True]*(10**5+10000)
dp[0]=False
dp[1]=False
for i in range(2,len(dp)):
  if dp[i]:
    for j in range(i*2,len(dp),i):
      dp[j]=False
      
for i in range(X,len(dp)):
  if dp[i]:
    print(i)
    break

Measured memory_bytes: 3828
import java.util.Scanner;
 
 
public class Main {
     
 
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int[][][] data = new int[4][3][10];
         
        for(int i = 0; i < n; i++) {
            int b = stdIn.nextInt();
            int f = stdIn.nextInt();
            int r = stdIn.nextInt();
            int v = stdIn.nextInt();
             
            data[b-1][f-1][r-1] += v;
        }
         
        for(int i = 0; i < 4; i++) {
            for(int j = 0; j < 3; j++) {
                for(int k = 0; k < 10; k++) {
                    System.out.print(" " + data[i][j][k]);
                }
                System.out.println();
            }
            if(i != 3) {
            System.out.println("####################");
            }
        }
    }
 
}


Measured memory_bytes: 29728
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = scan.nextInt();
        if (n == 1) {
            System.out.println(1);
            return;
        }
        int answer = 0;
        while (n!=1) {
            answer += 1;
            n /= 2;
        }
        System.out.println((int) Math.pow(2,answer));
    }
}


Measured memory_bytes: 21972
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;

ll nCr(ll n, ll r) {
	if (r > n) { return 0; }
	if (r * 2 > n) r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
ll sumdigit(ll n) {
	ll dig = 0, sum = 0;
	while (n) {
		dig = n % 10;
		sum = sum + dig;
		n = n / 10;
	}
	return sum;
}



int main() {
	int ans;
	string s;
	cin >> s;
	while (1) {
		s = s.substr(0, s.size() - 2);
		string a = s.substr(0, s.size() / 2);
		string b = s.substr(s.size() / 2, s.size() / 2);
		if (a == b) {
			ans = s.size();
			break;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
def solve(remains, nums):
    if (len(remains)) == 0:
        [print(num) for num in nums[::-1]]
        exit()
    n_remain = None
    n_num = None
    for i, num in enumerate(remains):
        if i + 1 == num:
            n_remain = remains[:i] + remains[i + 1:]
            n_num = nums + [i + 1]
    if n_remain is None:
        return False
    solve(n_remain, n_num)


n = int(input())
B = [int(x) for x in input().split()]

solve(B, [])
print(-1)


Measured memory_bytes: 3188
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main()
{
    int n;
    cin >> n;
    
    vector<int>x(n);
    
    for (int i = 0; i < n; i++)cin >> x[i];
    int ans = 1000000000;
    for (int i = 0; i <=100; i++) {
        int t = 0;
        for (int j = 0; j < n; j++) {
            t += (i - x[j]) * (i - x[j]);
        }
        ans = min(t, ans);
    }
   
    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 256
-module('Main').
-export([main/1]).

main(_) ->
    {ok, [N, K]} = io:fread("", "~d ~d"),
    Fruits = read_n_data(N),
    Sorted = lists:sort(Fruits),
    {BuyList, _} = lists:split(K, Sorted),
    Sum = lists:sum(BuyList),
    io:format("~p~n", [Sum]),
    halt().


%% N個データ読み込み
read_n_data(N) -> read_n_data(N, []).
read_n_data(0, Acc) -> Acc;
read_n_data(N, Acc) -> 
    {ok, [NewElement]} = io:fread("", "~d"),
    read_n_data(N - 1, [NewElement|Acc]).

Measured memory_bytes: 29052
#include <iostream>
#include <vector>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    uint N;
    cin >> N;
    uint lim{1};
    for (auto &&i: irange(0U, 5U)){
        lim*=10;
    }
    for (auto &&i: irange(1U, lim)){
        if ((i+1)*(i+1)>N){cout << (i*i);exit(0);}
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int n;
        cin >> n;
        int a[n];
        for(int &i : a){
            cin >> i;
        }
        sort(a, a + n);
        int cnt = a[n / 2] - a[n / 2 - 1];
        cout << cnt << '\n';
    }
}

Measured memory_bytes: 32256
#include<bits/stdc++.h>
#define ll              long long int
#define nl              '\n'
using namespace std;

int main(void){

   ll t,n,b,mx=0,sum=0;
   cin>>t;

   while(t--){
        cin>>n;

        mx=max(mx,n);

        sum +=n;
   }
   if(sum-mx<=mx) cout<<"No";
   else cout<<"Yes";
}


Measured memory_bytes: 3592
import sys

input = sys.stdin.readline


def main():
    n = int(input())
    a_list = [int(input()) for _ in range(n)]
    maximum = max(a_list)
    count = a_list.count(maximum)
    if count == 1:
        second = max(set(a_list) - set([maximum]))
    for a in a_list:
        if count > 1:
            print(maximum)
            continue
        if maximum == a:
            print(second)
        else:
            print(maximum)


if __name__ == "__main__":
    main()


Measured memory_bytes: 19232
from collections import Counter

S = Counter(input())

if "N" in S and "S" in S and "E" not in S and "W" not in S or \
    "N" not in S and "S" not in S and "E" in S and "W" in S or \
    "N" in S and "S" in S and "E" in S and "W" in S:
    print("Yes")
else:
    print("No")
    


Measured memory_bytes: 3436
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

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

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

struct Hashing {
    ull seed, mod;
    vector <ull> hs, pw;

    Hashing(ull seed = 31, ull mod = 1000173169) :
        seed(seed),
        mod(mod) {}

    void build(int n, const string& s) {
        hs.assign(n + 1, 0);
        pw.assign(n + 1, 1);
        pw[0] = 1;

        for (int i = 1; i <= n; ++i)
            pw[i] = pw[i - 1] * seed % mod;
        for (int i = 1; i <= n; ++i)
            hs[i] = (hs[i - 1] * seed + s[i]) % mod;
    }

    ull hash(int l, int r) {
        return (hs[r] - hs[l - 1] * pw[r - l + 1] % mod + mod) % mod;
    }
};

int solve()
{
    int n, m;

    std::cin >> n >> m;

    if (n < m)
        cout << string(m, n + '0') <<endl;
    else
        cout << string(n, m + '0') << endl;

    return 0;
}

int main()
{
    solve();

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
#include <queue>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

template <typename T>
class Wgraph{
public:
    Wgraph(int _n){
        n = _n;
        node.resize(n);
        adj.resize(n);
        REP(i, n) { node[i] = i; }
    }
    ~Wgraph(){

    }

    //a → b
    void connect(T from,T to,int cost){
        adj[from].push_back(make_pair(to,cost));
        //cout << from<<" " << to<<" "<<cost<<endl;
    }

    void dij(int start){
        
        priority_queue<pair<T,T>,vector<pair<T,T>>,greater<pair<T,T>>> pq;
        vector<T> dist(n,numeric_limits<T>::max());
        vector<bool> is_used(n,false);

        pq.push(make_pair(0,start));
        T to,d;

        while(!pq.empty()){
            tie(d,to) = pq.top();
            pq.pop();
            if(is_used[to]){
                continue;
            }else{
                is_used[to] = true;
                dist[to] = d;
                for(auto x:adj[to]){
                    //if(dist[x.first]>d+x.second){
                        pq.push(make_pair(d+x.second,x.first));
                    //}
                }
            }

        }
        REP(i,n){
            printf("%d %d\n", i, dist[i]);
        }
    }

  private:
    int n;
    vector<T> node;
    vector<vector<pair<T, T>>> adj;
    
};

int main(){
    int n;
    cin >> n;
    unique_ptr<Wgraph<int>> wg(new Wgraph<int>(n));

    
    {
        int tmp_from,tmp_edgenum, tmp_to,tmp_cost;

        REP(i,n){
            
            scanf("%d %d,", &tmp_from,&tmp_edgenum);

            REP(j,tmp_edgenum){
                scanf("%d %d", &tmp_to, &tmp_cost);
                wg->connect(tmp_from, tmp_to, tmp_cost);
            }


        }
    }
    wg->dij(0);

    return 0;
}



Measured memory_bytes: 11860
// AOJ ALDS1_14_C Pattern Search
// 2018.5.13 bal4u

#include <stdio.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

typedef unsigned long long ull;
#define C1  401
#define C2  397

#define MAX_L 1005
char text[MAX_L][MAX_L]; int H, W;
char pat[MAX_L][MAX_L]; int R, C;
ull a[MAX_L][MAX_L], b[MAX_L][MAX_L];
ull t[MAX_L][MAX_L];

void genHash(ull res[MAX_L][MAX_L], char s[MAX_L][MAX_L], int h, int w)
{
	int r, c;
	ull x, y, k;

	memset(t, 0, sizeof(t));
	memset(res, 0, sizeof(res));

	x = 1, y = 1;
	for (c = 0; c < C; c++) x *= C1;
	for (r = 0; r < R; r++) y *= C2;

	for (r = 0; r < h; r++) {
		k = 0;
		for (c = 0; c < C; c++) k = k*C1 + s[r][c];
		for (c = 0; c <= w-C; c++) {
			t[r][c] = k;
			if (c + C < w) k = k*C1-s[r][c]*x+s[r][c+C];
		}
	}

	for (c = 0; c < w; c++) {
		k = 0;
		for (r = 0; r < R; r++) k = k*C2+t[r][c];
		for (r = 0; r <= h-R; r++) {
			res[r][c] = k;
			if (r+R < h) k = k*C2-t[r][c]*y+t[r+R][c];
		}
	}
}

int main()
{
	int r, c;
	char ch, *p;

	H = in(), W = in();
	for (r = 0; r < H; r++) {
		p = text[r];
		while ((ch = gc()) > ' ') *p++ = ch;
		*p = 0;
	}

	R = in(), C = in();
	for (r = 0; r < R; r++) {
		p = pat[r];
		while ((ch = gc()) > ' ') *p++ = ch;
		*p = 0;
	}

	genHash(a, text, H, W);
	genHash(b, pat, R, C);

	for (r = 0; r <= H-R; r++) for (c = 0; c <= W-C; c++) {
		if (a[r][c] == b[0][0]) printf("%d %d\n", r, c);
	}
	return 0;
}


Measured memory_bytes: 18584
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.buffer.readline

def main():
    n, m = map(int, input().split())
    edges = [[] for _ in range(n)]
    for _ in range(m):
        x, y = map(int, input().split())
        edges[y - 1].append(x - 1)
    used = [False for _ in range(n)]
    dp = [0 for _ in range(n)]
    
    def dfs(pos):
        if not edges[pos]:
            dp[pos] = 0
            return
        for n_pos in edges[pos]:
            if not used[n_pos]:
                dfs(n_pos)
            used[n_pos] = True
            dp[pos] = max(dp[pos], dp[n_pos] + 1)
            
    
    for i in range(n):
        if used[i]:
            continue
        used[i] = True
        dfs(i)
        
    print(max(dp))

main()

Measured memory_bytes: 134168
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
void _OUT() {}; template<class H, class... T> void _OUT(H &h, T &... t) { cout<<' '<<h; _OUT(t...); };
template<class H, class... T> void _P(H &h, T &... t) { cout<<h; _OUT(t...); };
#define _PN(...) _P(__VA_ARGS__); cout << endl;
#define EXEC(...) void exec() { (__VA_ARGS__ - 1) ? multi() : solve(0); }

void exec();
void solve(int t);
void multi() { int TT; cin>>TT; REP1(t,TT) solve(t); }
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    exec();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 100
#else
#define SIZE 223450
#endif

int N,M;
vector<int> A(SIZE);

void solve(int _t) {
    cin>>N;
    REP(i,N)cin>>A[i];
    int s = 1;
    int ans = 0;
    REP(i,N) {
        if (A[i]<=s) chmax(s,A[i]+1);
        else {
            ans += (A[i]-1)/s;
            chmax(s,2LL);
        }
    }
    _PN(ans);
}
EXEC(1)



Measured memory_bytes: 4956
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

int a, b, c, n;
string s;


int main()
{
	int T;
	cin >> n>>T;
	vector<int> c(n), t(n);
	rep(i,n)
	{
		cin >> c.at(i) >> t.at(i);
	}
	int	min = 1001;
	rep(i,n)
	{if(t.at(i)<=T&&c.at(i)<min)
		min=c.at(i);
	}
	if (min ==1001 )
		cout << "TLE" << endl;
	else
		cout << min << endl;
}


Measured memory_bytes: 256