akhauriyash/Code-Regression huggingface dataset:
import sys

class card:
    def __init__(self, suit, num):
        self.suit = suit
        self.num = num

def quickSort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quickSort(A, p, q - 1)
        quickSort(A, q + 1, r)

def partition(A, p, r):
    x = A[r].num
    i = p - 1
    for j in range(p, r):
        if A[j].num <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[r] = A[r], A[i + 1]

    return i + 1

def checkStable(origin, sorted):
    for i in range(0, len(origin) - 1):
        if sorted[i].num == sorted[i + 1].num:
            if origin.index(sorted[i]) > origin.index(sorted[i + 1]):
                return False
    return True

if __name__ == "__main__":
    lines = sys.stdin.readlines()
    del lines[0]
    A = [card(c[0], int(c[2:])) for c in lines]
    origin = A[:]
    quickSort(A, 0, len(A) - 1)

    if checkStable(origin, A):
        print "Stable"
    else:
        print "Not stable"

    for a in A:
        print a.suit, str(a.num)

Measured memory_bytes: 54556
import sys
import math
import collections
import decimal
import itertools
from collections import deque
from functools import reduce
import heapq
import copy
n = int(input())
#l, r, d = map(int, sys.stdin.readline().split())
#s = input()
#a = list(map(int, sys.stdin.readline().split()))

ans = [0 for i in range(n+1)]
for i in range(1, 100):
    for j in range(1, 100):
        for k in range(1, 100):
            if i ** 2 + j ** 2 + k ** 2 + i * j + j * k + k * i > n:
                break
            
            ans[i ** 2 + j ** 2 + k ** 2 + i * j + j * k + k * i] += 1

for i in range(1, n+1):
    print(ans[i])


Measured memory_bytes: 10216
#include<iostream>

using namespace std;

int data[8];
int ans[4];
int dim[4][4] = {{0,1,2,3},
	       {1,0,3,2},
	       {2,3,0,1},
	       {3,2,1,0}};
int sign[4][4] = {{1,1,1,1},
		{1,-1,1,-1},
		{1,-1,-1,1},
		{1,1,-1,-1}};


void solve(){
  for(int i = 0; i < 4; i++)
    for(int j = 4; j < 8; j++)
      ans[dim[i][j-4]] += sign[i][j-4]*data[i]*data[j];

  for(int i = 0; i < 4; i++){
    if(i) cout << " ";
    cout << ans[i];
  }
  cout << endl;
}

int main(){

  int in;
  while(cin >> in && in){
    while(in--){
      fill(ans, ans+4, 0);
      for(int i = 0; i < 8; i++)
	cin >> data[i];
      solve();
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  for(auto c: s){
    cout << (c=='?' ? 'D' : c);
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3784
<?php
error_reporting(0);
$stdin = file_get_contents('php://stdin');
$line = explode("\n",$stdin);
$fi = 0;
$cnt = 0;
$list = array();
$key = new stdclass();
foreach($line as $l) {
  if (strlen($l)==0) continue;
  if ($fi == 0) {
    $a = explode(" ",$l);
    $key->A = $a;
    $fi++;
    continue;
  }
  if ($fi > 0) {
    $a = explode(" ",$l);
    $key->X[] = $a;
  }
}
printf("%s\n",str_replace(","," ",$key->A[0]));


Measured memory_bytes: 3704
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<set>
#include<map>
#include<time.h>
#include<cstring>
#include<iomanip>
#include<numeric>
#include<list>
#include<stack>
#include<sstream>
#define lli long long int
#define h 1000000007
#define s 2010
#define pf push_front
#define pb push_back
#define ub upper_bound
#define lb lowepr_bound
#define mp make_pair
#define pi 3.14159
using namespace std;
vector<lli>a(s,-1);
lli solve(lli sum)   
{
	lli i, cnt;
	if(sum==0)return 1;
	else if(sum>=3 && sum<=5) return 1;
	else if(a[sum]!=-1)return a[sum];
	else
	{
		cnt=0;
		for(i=3;i<=sum;i++) 
		{ if((sum-i)>=0)
	  	cnt=((cnt%h)+(solve(sum-i)%h))%h;
	  	else break;
	  } 
		a[sum]=cnt;
		return a[sum];
	} 
} 
int main() 
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL) ;
  lli i, n;
  cin>>n;
  cout<<solve(n)<<endl;
  return 0;
} 


Measured memory_bytes: 3564
def reconstruct(pre, in_):
    if not pre:
        return -1
    root = pre[0]
    i = in_.index(root)
    tree[root] = (reconstruct(pre[1 : i+1], in_[:i]), reconstruct(pre[i+1:], in_[i+1:]))
    return root

def postorder(i):
    if i == -1:
        return
    l, r = tree[i]
    for v in postorder(l):
        yield v
    for v in postorder(r):
        yield v
    yield i

n = int(input())
tree = [None for i in range(n+1)]
pre_tree = list(map(int, input().split()))
in_tree = list(map(int, input().split()))
reconstruct(pre_tree, in_tree)
print(*postorder(pre_tree[0]))


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


def main():
    S = read().decode('utf-8')
    S = list(S.replace('\n', ''))[::-1]
    T = [
            list('dream')[::-1],
            list('dreamer')[::-1],
            list('erase')[::-1],
            list('eraser')[::-1]
        ]

    while len(S) != 0:
        if S[0:5] == T[0] or S[0:5] == T[2]:
            del S[0:5]
        elif S[0:7] == T[1]:
            del S[0:7]
        elif S[0:6] == T[3]:
            del S[0:6]
        else:
            print('NO')
            sys.exit()

    print('YES')


main()


Measured memory_bytes: 4852
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

void solve() {
    int N;
    cin >> N;
    vector<int> v(N);
    REP(i,N) cin >> v[i];
    sort(ALL(v));
    auto r = v[N/2];
    auto l = v[(N/2)-1];
    cout << max(0,r-l) << endl;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 640
n,a=map(int,input().split())
x=list(map(int,input().split()))
X=max(max(x),a)
y=[]
for i in x:
    y.append(i-a)
dp=[[None for i in range(2*n*X+1)] for h in range(n+1)]
for j in range(n+1):
    for t in range(2*n*X+1):
            if j==0 and t==n*X:
                dp[j][t]=1
            elif j>=1 and (t-y[j-1]<0 or t-y[j-1]>2*n*X):
                dp[j][t]=dp[j-1][t]
            elif j>=1 and t-y[j-1]>=0 and t-y[j-1]<=2*n*X:
                dp[j][t]=dp[j-1][t]+dp[j-1][t-y[j-1]]
            else:
                dp[j][t]=0
                
print(dp[n][n*X]-1)

Measured memory_bytes: 5740
H, W = map(int, input().split())
S = [list(input()) for i in range(H)]
RES = [list("0" * W) for i in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            RES[i][j] = "#"
            for n in range(-1, 2):
                for m in range(-1, 2):
                    if not(n == 0 and m == 0) and 0 <= i + n and i + n < H and 0 <= j + m and j + m < W:
                        if RES[i + n][j + m] != "#":
                            RES[i + n][j + m] = str(int(RES[i + n][j + m]) + 1)

for i in range(H):
    print("".join(RES[i]))


Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
 
 
int asc(const void* a, const void* b) {
	return *(int*)a - *(int*)b;
}
 
int power(double a,double b) 
{
	return (int)pow((a - b), 2);
}
 
int rounding(double a) 
{
	int b = (int)a;
	return ((a - b) < 0.5) ? b : b + 1;
}
 
int average(int *a,double b) 
{
	double c = 0;
	for (int i = 0; i != b; i++)
	{
		c += a[i];
	}
 
	return rounding(c / b);
}
 
int main()
{
	int n, x[100]{ NULL };
	scanf("%d", &n);
	for (int i = 0; i != n; i++) 
	{
		scanf("%d", &x[i]);
	}
 
	qsort(x, n, sizeof(int), asc);
 
	int a = average(x, n);
	long long b = 0;
 
	for (int i = 0; i != n; i++) 
	{
		b += power(x[i], a);
	}
 
	printf("%lld", b);
 
	return 0;
}

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

int main(){
  int H,W,N,a,b[10050]={},c=0,h=1;
  cin>>H;
  cin>>W;
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>a;
    for(int j=0;j<a;j++){
      b[c+j]=h;
    }
    c += a;
    h += 1;
  }
  for(int k=0;k<H;k++){
    for(int l=0;l<W;l++){
      if(k%2==0){
        cout<<b[W*k+l];
        cout<<' ';
      }else{
        cout<<b[W*(k+1)-l-1];
        cout<<' ';
      }
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 384
function Main(inputs) {
  const input = inputs.split("\n");
  const m1 = Number(input[0].split(" ")[0]);
  const m2 = Number(input[1].split(" ")[0]);

  if(m1 + 1 === m2){
    console.log(1);
  }else{
    console.log(0);
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;


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

    if (N < M / 2)M -= ((M - 2 * N)+1) / 2;
    cout << M / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
def input() : return sys.stdin.readline().strip()

def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    left_sum = [0] * N # [0, i]
    right_sum = [0] * N # [i, N-1]

    left_sum[0] = A[0]
    right_sum[-1] = A[-1]

    for i in range(1, N):
        left_sum[i] = left_sum[i-1] + A[i]
        right_sum[(N-1)-i] = right_sum[(N-1)-(i-1)] + A[(N-1)-i]
    
    ans = 10 ** 11
    for i in range(N-1):
        diff = abs(left_sum[i] - right_sum[i+1])
        ans = min(ans, diff)
    
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 30828
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main(){
    string str;
    map<char,int> data;
    cin >> str;
    for(int i=0;i<str.length();i++){
        data[str[i]]++;
    }
    bool ans=true;
    for(auto itr=data.begin();itr!=data.end();itr++){
        if(itr->second%2!=0){
            ans=false;
            cout << "No" << endl;
            break;
        }
    }
    if(ans==true){
        cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

vector<pair<ll, ll>> drk;

int main()
{
    int n, m;
    cin>>n>>m;
    REP(i,n) {
        int a, b;
        cin>>a>>b;
        drk.push_back({a, b});
    }
    SORT(drk);
    ll ans = 0ll;
    int count = 0;
    REPALL(i,drk) {
        int honsu = min(drk[i].second, (ll)m - count);
        count += honsu;
        ans += drk[i].first * honsu;
        if (count == m)
            break;
    }

    cout<<ans<<endl;

    return 0;
}


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

int main(){
    string s;
    cin>>s;
    if(s.at(2)==s.at(3) && s.at(4)==s.at(5)){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

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

using namespace std;

int main() {

    int n,k;
    cin >> n >> k;
    set<int> s;

    for (int i = 0; i < k; ++i) {
        int d;
        cin >> d;
        while(d--) {
            int x;
            cin >> x;
            s.insert(x);
        }
    }

    int ans = 0;

    for (int i = 1; i <= n; ++i)
        ans += !s.count(i);

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3632
# すべてのスタートを試し、最大値の最大値を取る

import sys
readline = sys.stdin.readline

H,W = map(int,readline().split())
grid = [readline().rstrip() for i in range(H)]

ans = 0
cases = ((0,1),(0,-1),(1,0),(-1,0))
from collections import deque
for i in range(H):
  for j in range(W):
    q = deque([[i,j,0]])
    visited = [[False] * W for i in range(H)]
    while q:
      y,x,d = q.popleft()
      if grid[y][x] == "#":
        continue
      if visited[y][x]:
        continue
      visited[y][x] = True
      if d > ans:
        ans = d
      for c in cases:
        if 0 <= y + c[0] < H and 0 <= x + c[1] < W:
          q.append([y + c[0],x + c[1],d + 1])
print(ans)

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

using namespace std;

void solve()
{
	int n;
	cin >> n;
	
	string a, b;
	cin >> a >> b;
	
	for(int i = 0; i < a.size(); i++)
		cout << a[i] << b[i];
}

main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t = 1;
//	cin >> t;

	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 256
S = input() + 'A'
ans, prev, next = 1, [S[0]], []
for i in range(1, len(S)):
    if len(next) == 0 or prev == next:
        next.append(S[i])
    else:
        ans, prev, next = ans + 1, next, [S[i]]

print(ans)


Measured memory_bytes: 3500
#include<cstdio>
#include<cstdlib>
using namespace std;
int d[100100];
int beg[100100],nex[200100],tto[200100],e;
void putin(int s,int t){
	tto[++e]=t;
	nex[e]=beg[s];
	beg[s]=e;
}
int f[100100];
void dfs(int u,int fa){
	for(int i=beg[u];i;i=nex[i]){
		if(tto[i]==fa) continue;
		dfs(tto[i],u);
	}
	int cnt=0;
	for(int i=beg[u];i;i=nex[i]){
		if(tto[i]==fa) continue;
		if(f[tto[i]]==0) cnt++;
	}
	if(cnt>=2)
	{
		printf("First\n");
		exit(0);
	}
	else
		f[u]=cnt;
}
int main(){
//	freopen("D.in","r",stdin);
	int n;
	scanf("%d",&n);
	if(n==2){
		printf("Second\n");
		return 0;
	}
	int s,t;
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&s,&t);
		putin(s,t);
		putin(t,s);
		d[s]++,d[t]++;
	}
	int rt;
	for(int i=1;i<=n;i++){
		if(d[i]>1){
			rt=i;
			break;
		}
	}
	dfs(rt,-1);
	if(!f[rt]){
		printf("First\n");
		return 0;
	}
	printf("Second\n");
	return 0;
}


Measured memory_bytes: 2944
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate
from math import sqrt, ceil, floor
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

s = S()
if s[2]==s[3] and s[4]==s[5]:
    print("Yes")
else:
    print("No")

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

class P
{
    static void Main()
    {
        Console.ReadLine();
        string s = Console.ReadLine();
        int max = 0;
        int x = 0;
        foreach (var c in s)
        {
            if (c == 'I') x++;
            else x--;
            max = Math.Max(x,max);
        }
        Console.WriteLine(max);
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <random>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

vector<int> adj[110000];
int pa[110000];
bool visited[110000];
void bfs(int nd) {
	queue<int> q;
	q.push(nd);
	visited[nd] = 1;
	while (q.size()) {
		int cur = q.front();
		q.pop();
		for (int nxt : adj[cur]) {
			if (visited[nxt]) continue;
			pa[nxt] = cur;
			visited[nxt] = 1;
			q.push(nxt);
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N, M; cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int a, b; cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	bfs(1);

	bool yes = 1;
	vector<int> ans;
	for (int i = 2; i <= N; i++)
		if (pa[i]) ans.push_back(pa[i]);
		else {
			yes = 0;
			break;
		}

	if (yes) {
		cout << "Yes\n";
		for (int i : ans)cout << i << '\n';
	}
	else cout << "No\n";
	return 0;
}




Measured memory_bytes: 10864
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define inf (int)1e9+7
#define eb emplace_back

int N, M;
int next_combination(int sub) {
    int x = sub & -sub, y = sub + x;
    return (((sub & ~y) / x) >> 1) | y;
}
int dfs(int dep, int table[9][9]) {
    //cout << endl;
    if (dep == N) {
        //cout << endl; rep(i, N) {rep(j, N) cout << table[i][j] << " "; cout << endl;}
        return 1;
    }
    int w = 0;
    rep(i, N) w += (table[dep][i] == 1);
    int rw = N / 2 - w;
    //cout << dep << " " << rw << endl;
    if (rw < 0) return 0;
    if (rw == 0) {
        rep(i, N) {
            if (table[dep][i]) continue;
            if (dep == i) continue;
            table[dep][i] = -1;
            table[i][dep] = 1;
        }
        return dfs(dep + 1, table);
    }
    int res = 0;
    int table2[9][9];
    rep(i, 9) rep(j, 9) table2[i][j] = table[i][j];
    for (int bit = (1 << rw) - 1; bit < (1 << N); bit = next_combination(bit)) {
        //新しく追加するbit
        //すでに入ってたら切る
        if (bit & (1 << dep)) continue; //自分のとこは入らない
        rep(i, 9) rep(j, 9) table[i][j] = table2[i][j];
        int flg = 0;
        rep(i, N) if (bit & (1 << i) && table[dep][i]) {flg = 1; break;}
        if (flg) continue;
        rep(i, N) {
            if (table[dep][i]) continue;
            if (bit & (1 << i)) {
                table[dep][i] = 1;
                table[i][dep] = -1;
            } else if (dep != i) {
                table[dep][i] = -1;
                table[i][dep] = 1;
            } //if dep == i, 0
        }
        //cout << bitset<10>(bit) << endl; rep(i, N) {rep(j, N) cout << table[i][j] << " "; cout << endl;}
        res += dfs(dep + 1, table);
    }
    return res;
}
int main() {
    while (cin >> N && N) {
        cin >> M;
        int table[9][9] = {0};
        rep(i, M) {int x, y; cin >> x >> y; x--; y--; table[x][y] = 1; table[y][x] = -1;}
        //rep(i, N) {rep(j, N) cout << table[i][j] << " "; cout << endl;}
        cout << dfs(0, table) << endl;
    }
    
}



Measured memory_bytes: 3076
#include<bits/stdc++.h>
typedef long long ll; 
#define pb push_back
#define mp make_pair
#define mod 998244353
#define vi vector <ll>
using namespace std ; 
ll power(ll x,ll y,ll m)
{            //power(x,y)=x^y  %m;
	ll res=1%m;
	while(y)
	{
	    if(y&1)
	    res=(res*x)%m;
	    x=(x*x)%m;
	    y=(y>>1)%m;
	}
	return res;
}
ll mod_inverse(ll x,ll m)
{
	return power(x,m-2,m);
}
int main ()
{
    ios_base :: sync_with_stdio ( false );
    cin.tie( NULL );
    cout.tie( NULL );
ll t = 1 ;
//cin>>t;
while ( t--)  
{
ll n;
cin>>n;
ll a=0,b=0,c=0,d=0;
for(ll i=0;i<n;i++)
{string s;
    cin>>s;
    if(s=="AC")
    a++;
     if(s=="WA")
    b++;
    
     if(s=="RE")
    c++;
    
     if(s=="TLE")
    d++;
    
    
}
cout<<"AC"<<" "<<"x"<<" "<<a<<"\n";
cout<<"WA"<<" "<<"x"<<" "<<b<<"\n";
cout<<"TLE"<<" "<<"x"<<" "<<d<<"\n";
cout<<"RE"<<" "<<"x"<<" "<<c<<"\n";
 
  
 
}
 

 return 0;
}

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

using Weight = int;
using Capacity = int;
struct Edge {
	int src, dst; Weight weight; Capacity cap;
	Edge(int s, int d, Weight w, Capacity c) : src(s), dst(d), weight(w), cap(c) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

struct Dinic {
	int n, s, t;
	vector<int> level, prog, que;
	vector<vector<Capacity>> cap, flow;
	vector<vector<int>> g;
	Capacity inf;
	Dinic(const Graph &graph)
		: n(graph.size()),
		cap(n, vector<Capacity>(n)), flow(n, vector<Capacity>(n)),
		g(n, vector<int>()), inf(numeric_limits<Capacity>::max() / 8) {
		for(int i = 0; i < n; i++) {
			for(auto &e : graph[i]) {
				int u = e.src, v = e.dst;
				Capacity c = e.cap;
				cap[u][v] += c; cap[v][u] += c; flow[v][u] += c;
				g[u].push_back(v); g[v].push_back(u);
			}
		}
	}
	inline Capacity residue(int u, int v) { return cap[u][v] - flow[u][v]; }
	Capacity solve(int s_, int t_) {
		this->t = t_, this->s = s_;
		que.resize(n + 1);
		Capacity res = 0;
		while(levelize()) { prog.assign(n, 0); res += augment(s, inf); }
		return res;
	}
	bool levelize() {
		int l = 0, r = 0;
		level.assign(n, -1); level[s] = 0; que[r++] = s;
		while(l != r) {
			int v = que[l++]; if(v == t) break;
			for(const int &d : g[v]) if(level[d] == -1 && residue(v, d) != 0) {
				level[d] = level[v] + 1; que[r++] = d;
			}
		}
		return level[t] != -1;
	}
	Capacity augment(int v, Capacity lim) {
		Capacity res = 0;
		if(v == t) return lim;
		for(int &i = prog[v]; i < (int)g[v].size(); i++) {
			const int &d = g[v][i];
			if(residue(v, d) == 0 || level[v] >= level[d]) continue;
			const Capacity aug = augment(d, min(lim, residue(v, d)));
			flow[v][d] += aug; flow[d][v] -= aug;
			res += aug; lim -= aug;
			if(lim == 0) break;
		}
		return res;
	}
};


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

	int V, E;
	cin >> V >> E;

	Graph G(V);
	for(int i = 0; i < E; i++) {
		int v, u, c;
		cin >> v >> u >> c;
		G[v].push_back(Edge(v, u, 1, c));
	}
	Dinic dinic(G);
	cout << dinic.solve(0, V - 1) << endl;
}

Measured memory_bytes: 3300
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);



signed main(){
    ll n,m,ans=1;cin>>n>>m;

    if(abs(n-m)>1){
        ans=0;
    }else if(n==m){
        ans=2;
        for(int i=1;i <=n;i++)
        {
            ans*=i;
            ans%=mod;
            ans*=i;
            ans%=mod;
        }
    }else{
        for(int i=1;i <=n;i++)
        {
            ans*=i;
            ans%=mod;
        }
        for(int i=1;i <=m;i++)
        {
            ans*=i;
            ans%=mod;
        }
    }
    cout<<ans<<endl;
}

    

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

int main(){
  int h, w, n;
  cin >> h >> w >> n;
  
  int result;
  
  if (h > w){
    result = n / h;
    if (n % h){
      result += 1;
    }
  }
  else{
    result = n / w;
    if (n % w){
      result += 1;
    }
  }
  
  cout << result;
  return 0;
}

Measured memory_bytes: 256
N=int(input())
H=list(map(int,input().split()))
cost=0
t1,t2=0,0
A=[0]*(N)
i=1
while i<N:
  if i==1:
    A[i]=abs(H[i]-H[i-1])
    #print(i,A[i])
  elif i==2:
    t1=abs(H[i]-H[i-2])
    t2=abs(H[i]-H[i-1])+abs(H[i-2]-H[i-1])
    A[i]=min(t1,t2)
    #print(i,A[i],t1,t2)
  else:
    t1=abs(H[i]-H[i-1])+A[i-1]
    t2=abs(H[i]-H[i-2])+A[i-2]
    A[i]=min(t1,t2)
    #print(i,A[i],t1,t2)
  i=i+1
#print(A)
print(A[N-1])

Measured memory_bytes: 13928
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long r;
    cin >> r;
    cout << r * r << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
/* global variables */
/* function */
/* main */
int main(){
    int M, D;
    cin >> M >> D;

    int ans = 0;
    for (int m = 4; m <= M; m++) {
        for (int d1 = 2; d1 <= 9; d1++) {
            for (int d10 = 2; d10 <= 9; d10++) {
                int d = d1 + d10 * 10;
                if (d <= D && m == d1 * d10) {
                    ans++;
                }
            }
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 3540
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define mk make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    priority_queue<int> q;
    vc<pi> p;
    int pos=0,ans=0;
    int N,M; cin >> N >> M;
    rep(i,N){
        int a,b; cin >> a >> b;
        a--;
        p.pb(mk(a,b));
    }
    sort(all(p));
    rep(i,M){
        while(p[pos].fi<=i && pos!=N){
            q.push(p[pos].se);
            pos++;
        }
        if(!q.empty()) {ans+=q.top(); q.pop();}
    }
    cout << ans << endl;
}

Measured memory_bytes: 4080
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<cassert>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

#define MAX

#define MOD (long long)(1e9+7)
#define MAX_VAL (int)(1e5)

long long fac[MAX_VAL], mmi[MAX_VAL];

void factorial_mod(){
	 fac[0]=fac[1]=1;
	for(long long i = 2; i < MAX_VAL; fac[i]%=MOD,i++)
		fac[i] = fac[i-1]*(i%MOD);
}

long long power(long long x, long long n){
	long long ans = 1;
	for(;n;n>>=1,x*=x,ans%=MOD,x%=MOD)
		if(n&1)ans*=x;
	return ans%MOD;
}

void exgcd(int a, int b, int &x, int &y){
	if(b == 0){
		x = 1;
		y = 0;
		return ;
	}
	exgcd(b,a%b,y,x);
	y -= a/b * x;
}

void modular_multiplicatibe_inverse(){
	int x, y;  
	exgcd(fac[MAX_VAL-1],MOD,x,y);
	mmi[MAX_VAL-1] = x;
	for(long long i = MAX_VAL-2; i >= 0; mmi[i]%=MOD,i--)
		mmi[i] = mmi[i+1]*((i+1)%MOD);
}

long long combination(long long n, long long r){
	if(n < r) return 0;
	return fac[n]*(mmi[r]*mmi[n-r]%MOD)%MOD;
}

signed main(){
	// cin.tie(0);
	// ios::sync_with_stdio(false);
	// cout<<fixed<<setprecision(10);
	
	int N, K;
	
	factorial_mod();
	modular_multiplicatibe_inverse();
	
	
	cin>>N>>K;

	for(int i = 1; i <= K; i++){
		int ans = 1;

		ans = combination((N-K) + 1, i);
		ans = ans*combination(K-1, i-1);
		cout<<ans%MOD<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[105];
int main()
{
	int n,m,sum=0,cnt=0;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	for(int i=1;i<=n;i++)
	{
		if(4*m*a[i]>=sum)
		{
			cnt++;
		}
	}
	if(cnt>=m)
	puts("Yes");
	else
	puts("No");
}

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

ans = 0
for i in range(N):
    p = min(A[i], B[i])
    ans += p
    B[i] -= p
    p = min(A[i+1],B[i])
    ans += p
    A[i+1] -= p
print(ans)

Measured memory_bytes: 19116
import math
def main():
    N, K = map(int, input().split())
    A = [int(a) for a in input().split()]

    if N == 1:
        print(0)
    elif N <= K:
        print(1)
    else:
        print(1+math.ceil((N-K)/(K-1)))

if __name__ == "__main__":
    main()

Measured memory_bytes: 13812
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cstdio>
using namespace std;

int main(){
    int w, n;
    int count = 0;
    while(cin >> w, w){
        vector<pair<int, int> > v;
        long long dp[1010][1010];
        memset(dp, 0, sizeof(dp));
        cin >> n;
        for(int i=0; i < n; i++){int s, t; scanf("%d,%d", &s, &t); v.push_back(make_pair(s, t));}
        for(int i=n-1; 0 <= i; i--){
            for(int j=0; j <= w; j++){
                if(j < v[i].second) dp[i][j] = dp[i+1][j];
                else dp[i][j] = max(dp[i+1][j], dp[i+1][j-v[i].second]+v[i].first);
            }
        }
        cout << "Case " << ++count << ":" << endl;
        cout << dp[0][w] << endl;
        for(int i=w; ; i--){
            if(dp[0][i] != dp[0][w]){cout << i+1 << endl; break;}
        }
    }
}

Measured memory_bytes: 9240
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;
import java.awt.Point;

public class Main {
    // static int INF = (1 << 30) - 1;
    // static long L_INF = (1L << 62) - 1;
    // static long MOD = (long) 1e9 + 7;

    static class Solver {
        long A, V, B, W, T;

        // write your code
        void solve(InputReader in, PrintWriter out) {
            A = in.nextLong();
            V = in.nextLong();
            B = in.nextLong();
            W = in.nextLong();
            T = in.nextLong();

            if (A < B) {
                long disA = A + V * T;
                long disB = B + W * T;
                if (disA >= disB) {
                    out.println("YES");
                } else {
                    out.println("NO");
                }
            } else {
                long disA = A - V * T;
                long disB = B - W * T;
                if (disA <= disB) {
                    out.println("YES");
                } else {
                    out.println("NO");
                }
            }
        }

        void debug(Object... os) {
            System.err.println(Arrays.deepToString(os));
        }
    }

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(in, out);
        out.close();
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}


Measured memory_bytes: 32844
n,k=list(map(int,input().split()))
r,s,p=list(map(int,input().split()))
t=list(input())
cnt=0
u=[]
for i in range(n):
  if t[i]=='r':
    u.append("p")
  elif t[i]=='s':
    u.append("r")
  else:
    u.append("s")

for i in range(n):
  if u[i]=="r":
    if i<k:
      cnt+=r
    else:
      if u[i-k]=="r":
        cnt+=0
        u[i]="#"
      else:
        cnt+=r

  elif u[i]=="s":
    if i<k:
      cnt+=s
    else:
      if u[i-k]=="s":
        cnt+=0
        u[i]="#"
      else:
        cnt+=s

  elif u[i]=="p":
    if i<k:
      cnt+=p
    else:
      if u[i-k]=="p":
        cnt+=0
        u[i]="#"
      else:
        cnt+=p
#print("".join(u))
print(cnt)

Measured memory_bytes: 4792
#include <iostream>
#include <cmath>
#include <string.h> 
#include <vector>
#include <bits/stdc++.h> 
#include <iomanip>
#include<algorithm> 
#include <string> 
using namespace std;

int main(){
    int n,k;
    cin>>n>>k;
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    int fib[n];
    fib[0]=0; fib[1]=abs(arr[1]-arr[0]);
    for(int i=2;i<n;i++){
        int min1 = INT_MAX;
        for(int j=1;j<=k&&j<=i;j++){
            min1 = min(min1,abs(arr[i]-arr[i-j])+fib[i-j]);
        }
        fib[i]=min1;
    }
    cout<<fib[n-1];
    return 0;
}


Measured memory_bytes: 1024
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.IntStream;

public class Main {

	/** 自由の色の番号 */
	private static int FREE_COLOR = 9;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			Set<Integer> colorSet = new HashSet<>();
			int freeColorCount = IntStream.range(0, n).map(i -> {
				int color = getColor(scanner.nextInt());
				if (FREE_COLOR != color) {
					colorSet.add(color);
					return 0;
				}
				return 1;
			}).sum();
			System.out.println(Math.max(1, colorSet.size()) + " " + (colorSet.size() + freeColorCount));
		}
	}

	/**
	 * @param n 入力数字
	 * @return 入力数字に該当する色ナンバー
	 */
	private static int getColor(int n) {
		if (n >= 3200) {
			return FREE_COLOR;
		}
		return n / 400;
	}
}


Measured memory_bytes: 27092
fn main() {
    let inputs: Vec<i64> = read_vec();
    let n_books = inputs[0];
    let m_books = inputs[1];
    let total_limit_time = inputs[2];
    let n_read_times: Vec<i64> = read_vec();
    let m_read_times: Vec<i64> = read_vec();

    // 事前に足し合わせる
    let n_read_times = add_up(&n_read_times);
    let m_read_times = add_up(&m_read_times);

    let mut bests: Vec<usize> = Vec::new();
    for (n_book_count, n_time) in n_read_times.iter().enumerate() {
        if n_time > &total_limit_time {
            break;
        }
        let diff = total_limit_time - n_time;

        let m_book_count = binary_search(&m_read_times, diff);
        bests.push(n_book_count + m_book_count);
    }
    bests.sort();
    let max = bests.last().unwrap();

    println!("{}", max);
}

fn add_up(read_times: &Vec<i64>) -> Vec<i64> {
    let mut vec: Vec<i64> = Vec::new();
    let mut total = 0;
    vec.push(total);
    for time in read_times.iter() {
        total += time;
        vec.push(total);
    }

    return vec;
}

fn binary_search(vec: &Vec<i64>, target: i64) -> usize {
    let mut start = 0;
    let mut end = vec.len();
    let mut center = vec.len() / 2;
    loop {
        if start == center {
            return center;
        }
        if vec[center] == target {
            return center;
        } else if vec[center] > target {
            // Left
            end = center;
        } else {
            // right
            start = center;
        }

        center = start + ((end - start) / 2);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 11204
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
struct item
{
	int weight, value;
};
 
int solve(vector<item> vec, int n, int w)
{
	int dp[n + 1][w + 1];
	for(int i = 0;i <= w; i++)dp[1][i] = 0;
	dp[1][vec[1].weight] = vec[1].value;
	for(int i = 2; i <= n; i++)
	{
		for(int j = 0; j <= w; j++)
		{
			//there are two choices to make either to take the element or not
			//to take the element
			dp[i][j] = dp[i - 1][j];
			if(vec[i].weight > j)
				continue;
			dp[i][j] = max(dp[i][j], vec[i].value + dp[i - 1][j - vec[i].weight]);
		}
	}
	return *max_element(dp[n], dp[n] + w + 1);
}
 
signed main()
{
	int n, w;
	cin >> n >> w;
	vector<item> vec(n + 1);
	for(int i = 1; i <= n; i++)
	{
		cin >> vec[i].weight >> vec[i].value;
	}
	cout << solve(vec, n, w);
	//return 0;
}

Measured memory_bytes: 81728
#include<stdio.h>

int main(void)
{
	int a, b, c, i, count = 0;

	scanf("%d %d %d", &a, &b, &c);

	for (i = b; a <= i; i--)
	{
		if ((c % i) == 0)
		{
			count++;
		}
	}

	printf("%d\n", count);

	return 0;
}


Measured memory_bytes: 2120
from bisect import bisect_left
N = int(input())
L = sorted(list(map(int, input().split())))

ans = 0
for i in range(N-2):  # １番短い棒 #どうせ増えないからＮでも多分大丈夫
  for j in range(i + 1, N-1):  # 真ん中の長さの棒
    ans += bisect_left(L, L[i] + L[j]) - (j + 1)

print(ans)

Measured memory_bytes: 3188
from math import factorial
def count(n, r):
    if n == r:
        return 2
    else:
        return 1

N, M = map(int, input().split())
mod = 10**9 + 7
print(((factorial(N) % mod) * (count(N, M) % mod) * (factorial(M) % mod)) % mod if abs(N - M) < 2 else 0)

Measured memory_bytes: 10048
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		StringBuilder sb = new StringBuilder();
		Scanner scan = new Scanner(System.in);
		while(true){
		//Scanner scan = new Scanner(System.in);


		int H = scan.nextInt();
	    int W = scan.nextInt();


	    if(H == 0 && W == 0)break;
	    for(int i = 1;i <= H ;i++){
	    	for(int j = 1;j <= W; j++){
	    		if((i == 1 || j == 1) || i == H || j == W){
	    			//sb.append("#");
	    			System.out.print("#");
	    		}else{
	    			//sb.append(".");
	    			System.out.print(".");
	    		}

	    	}
	    	System.out.println();
	    	//sb.append("\n");
	    }
	    //sb.append("\n");
	    System.out.println();
	   }
		//System.out.print(sb);

	}

}

Measured memory_bytes: 34948
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <algorithm>
using namespace std;
int main(void){
    string S;
    cin >> S;
    if(S == "AAA" || S == "BBB"){
        cout << "No"<<endl;
    }
    else{
        cout << "Yes"<<endl;
    }
}


Measured memory_bytes: 3048
s = list(input())
a = [0] * (len(s) + 1)

for i in range(len(s)):
    if s[i] == "<":
        a[i+1] = a[i] + 1
for i in range(len(s)-1, -1, -1):
    if s[i] == ">":
        a[i] = max(a[i+1]+1, a[i])
print(sum(a))

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

// See debug.cc for usage etc
#define DEBUG 0

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#if DEBUG
  #define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
  #define DCALL(func, ...) func(__VA_ARGS__)
#else
  #define DLOG(...)
  #define DCALL(func, ...)
#endif

ll X, A;

int main() {
#if !DEBUG
  ios_base::sync_with_stdio(false);
#endif

  cin >> X >> A;
  if (X < A) {
    cout << 0 << endl;
  }else {
    cout << 10 << endl;
  }

  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0,1,0,-1 };
const ll dy[4] = { -1, 0, 1,0 };
const ll INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////

//dp[i][x]:=i回目のx軸方向の移動の後にx座標がxになっているかどうか
//初期化:1回目のx軸方向の移動距離をd1とするとdp[0][d1]=true
//漸化式：i(i>=2)回目のx軸方向の移動距離をdiとするとdpi,x=dpi-1,x-di || dpi-1,x+di
bool dp_1[8010][16050];
bool dp_2[8010][16050];
int main() {
	string s; cin >> s;
	int x, y; cin >> x >> y;
	vector<int>t;
	int cnt = 0;
	REP(i, s.size()) {
		if (s[i] == 'T') {
			if (cnt != 0) {
				t.push_back(cnt);
				t.push_back(0);
				cnt = 0;
			}
			else {
				t.push_back(0);
			}
		
		}
		else {
			cnt++;
		}
		if (i == s.size() - 1) {
			t.push_back(cnt);
		}
	}
	memset(dp_1, false, sizeof(dp_1));
	memset(dp_2, false, sizeof(dp_2));
	dp_1[0][8000] = true;
	dp_2[0][8000] = true;
	int dir = 1;
	bool plus = false;
	for (int i = 0; i < t.size(); ++i) {
		if (t[i] == 0) {
			dir *= -1;
			for (int j = 0; j <= 16010; ++j) {
				dp_1[i + 1][j] = dp_1[i][j];
				dp_2[i + 1][j] = dp_2[i][j];
			}
		}
		else {
			if (dir == 1) {
				for (int j = 0; j <= 16010; ++j) {
					dp_2[i + 1][j] = dp_2[i][j];
					if (dp_1[i][j]) {
						if (j + t[i] < 16010) {
							dp_1[i + 1][j + t[i]] = true;
						}
						if (j - t[i] >= 0&&plus) {
							dp_1[i + 1][j - t[i]] = true;
						}
					}
				}
			}
			else {
				for (int j = 0; j <= 16010; ++j) {
					dp_1[i + 1][j] = dp_1[i][j];
					if (dp_2[i][j]) {
						if (j + t[i] < 16010) {
							dp_2[i + 1][j + t[i]] = true;
						}
						if (j - t[i] >= 0) {
							dp_2[i + 1][j - t[i]] = true;
						}
					}
				}
			}
		}
		if (!plus)plus = true;
	}
	if (dp_1[t.size()][x+8000] && dp_2[t.size()][y+8000]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

const double PI=3.141592653589793;
const ll MX = 1e18;


int main()
{
  string S;
  int N;
  cin >> N >> S;
  int ds = 0;
  rep(i, N - 1)
  {
    if(S[i]==S[i+1]){
      ds++;
    }
  }

  cout << N - ds << endl;

  return 0;
}


Measured memory_bytes: 3696
#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd (a, b)

A, B = map(int, input().split())

print(lcm(A,B))

Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <utility> 

#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;


vector<ll> devisor;
void check(ll n) {
	for (ll i = 1; i*i <= n; i++) {
		if (n%i == 0) {
			if (i != n / i) {
				devisor.push_back(i);
				devisor.push_back(n / i);
			}
			else {
				devisor.push_back(i);
			}
		}
	}
	return;
}


int getdigit(ll n) {
	return to_string(n).length();
}


int main(){
	ll n;
	cin >> n;
	check(n);
	sort(devisor.begin(), devisor.end());

	ll ans = inf;


	if (devisor.size() % 2 == 0) {
		for (ll i=0; i < devisor.size() / 2; i++) {
			int a = getdigit(devisor[i]);
			int b = getdigit(devisor[devisor.size() - 1 - i]);
			ll temp = max(a, b);
			ans = min(ans,temp);
		}
		cout << ans << endl;
	}
	else {
		cout << getdigit(devisor[(devisor.size() - 1) / 2]) << endl;
	}



	return 0;
}


Measured memory_bytes: 256
n = int(input())
a, b = [0]*n,[0]*n
count = 0
for i in range(n):
    a[i],b[i] = map(int,input().split())

while(n > 0):
    n -= 1
    count += (b[n] if (a[n]+count)%b[n]!=0 else 0)-(a[n]+count)%b[n]

print(count)

Measured memory_bytes: 10868
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    

    cout << ((n==m)?"Yes":"No") << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pII;
#define pb push_back
#define mp make_pair
#define clr(x,y) memset(x,y,sizeof(x))
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e6+5;
//ll fmod(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;y>>=1;x=x*x%mod;}return res;}
//ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
int ans[maxn];
int main()
{
    int n,a,b;
    while(cin>>n>>a>>b)
    {
        int p = sqrt(n);
        //cout<<p<<endl;
        if(a + b > n + 1||a + b < p + n/p + (n%p?1:0))
        {
            //cout<<(a + b > n + 1||a + b < p + n/p + (n%p?1:0))<<endl;
            cout<<-1<<endl;
            continue;
        }
        int x = min(a, b),y = max(a, b);
        if(n/y + (n%y?1:0) > x)
        {
            cout<<-1<<endl;
            continue;
        }
        int now;
        int pos = 2*n;
        int have = 0;
        clr(ans,0);
        int gg = 0;
        int upper = n/y + (n%y?1:0);
        for(int j = 1; j <= upper; ++j)
        {
            now = y*(j - 1);
            int res = 2*n - j*y + 1;
            for(int i = 1; i <= y; i++)
            {
               // cout<<now<<endl;
                ans[res++] = ++now;
                if(i == y)
                    gg++;
                if(j + n - now == x)
                {
                    //cout<<j + n - now<<endl;
                    have = 1;
                    break;
                }
            }
            if(have)break;
        }
        //cout<<now<<endl;
        if(!gg)
        {
            cout<<-1<<endl;
            continue;
        }
        int pp = n - now;
        for(int i = pp; now != n&&i>=1 ;--i)
        {
            //cout<<now<<endl;
            ans[i] = ++now;
        }



        if(a>b)
        {
            int cnt = 0;
            for(int i = 1; i <= 2*n; ++i)
                if(ans[i])
            {
                cnt++;
                //cout<<i<<"pp";
                printf("%d%c",ans[i],cnt == n?'\n':' ');
            }
        }
        else
        {
            int cnt = 0;
            for(int i = 2*n; i >= 1; --i)
                if(ans[i])
            {
                cnt++;
                printf("%d%c",ans[i],cnt == n?'\n':' ');
            }
        }
    }

}
















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

ll a[300000];
ll s[300000];
int main(){
    int n; cin  >> n;
    for(int i=1;i<=n;i++){
        cin >> a[i];
        s[i]+=s[i-1]+a[i];
    }
    int m;
    for(int i=0;i<=n;i++){
        if(s[i]>=s[n]/2){
            m=i;break;
        }
    }
    cout << min(abs(s[m]-(s[n]-s[m])),abs(s[m-1]-(s[n]-s[m-1]))) << endl;
        
}

Measured memory_bytes: 3840
# frozen_string_literal: true

$factors = Hash.new

def factrize(n)
  (2..Math.sqrt(n)).each do |d|
    ex = 0
    while n % d == 0
    ex += 1
      $factors.store(d, ex)
      n /= d
    end
  end
  $factors.store(n,1) if n != 1
end

n, p = gets.split.map(&:to_i)
ans = 1
factrize(p)
list = $factors.to_a
list.each do |factor|
    for i in 1..factor[1]/n do
        ans *= factor[0]
    end
end

puts ans


Measured memory_bytes: 1788