akhauriyash/Code-Regression huggingface dataset:
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

#define int long long

template<typename A, size_t N, typename T>

void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//ここにグローバル変数宣言

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//ここに関数宣言


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 int N,M;
 cin>>N>>M;
 int A;
 REP(i,M){
 	cin>>A;
 	N-=A;
 }
 if (N<0)
 {
 	cout<<-1<<endl;
 }
 else cout<<N<<endl;

return 0;





}

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

long long int dp[405][405];
int main(){
  int n; cin >> n;
  long long int x[n];  for(int i=0;i<n;i++) cin >> x[i];
  for(int i=0;i<n;i++) for(int j=0;j<n;j++) dp[i][j] = 0; 
  for(int i=0;i<n-1;i++) dp[i][i+1] = x[i] + x[i+1];
  long long int as[n]; as[0] = x[0]; for(int i=0;i<n-1;i++) as[i+1] = x[i+1] + as[i];
  for(int i=2;i<n;i++) for(int j=0;j<n-i; j++){
    long long int m = 40000000000001;
    for(int k=0;k<i;k++) m = min(m, dp[j][j+k]+dp[j+k+1][j+i] + as[j+i] - (j==0 ? 0 : as[j-1]));
    dp[j][j+i] = m;
  }
  cout << dp[0][n-1] << endl;
  return 0;
}
    


Measured memory_bytes: 1536
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#define rep(i,x,y) for(int i=x; i<=y; ++i)

using namespace std;
const int N=11,dis[]={0,1,2,4,7,12,20,29,38,52,73};
int n,p[N],id[N][N],tot;
typedef long long LL;
LL mx,ans[N][N];
bool vis[N];

void dfs(int x,int n)
{
	if(x>n)
	{
		LL tot=0;
		rep(i,1,n-1) tot+=ans[p[i]][p[i+1]];
		mx=max(mx,tot);
		return;
	}
	rep(i,1,n) if(!vis[i]) vis[i]=1,p[x]=i,dfs(x+1,n),vis[i]=0;
}

void solve()
{
	ans[1][2]=ans[2][1]=1;
	rep(i,3,n)
	{
		mx=0;
		dfs(1,i-1);
		rep(j,1,i-1) ans[i][j]=ans[j][i]=(mx+1)*dis[j];
	}
	rep(i,1,n)
	{
		rep(j,1,n) printf("%lld ",ans[i][j]);
		puts("");
	}
}

int main()
{
	scanf("%d",&n);
	if(n<10)
	{
		rep(i,1,n) rep(j,1,n) if(i<j) id[i][j]=tot++;
		rep(i,1,n) rep(j,1,n) if(i>j) id[i][j]=id[j][i];
		rep(i,1,n)
		{
			rep(j,1,n)
				if(i==j) printf("0 ");
				else printf("%lld ",1ll<<id[i][j]);
			puts("");
		}
		return 0;
	}
	solve();
	return 0;
}

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

int main()
{
    long long n,a,b;
    cin>>n>>a>>b;
    if(a==0) cout<<0<<endl;
    else if(b==0) cout<<n<<endl;
    else
    {
        long long x=n/(a+b),y=n%(a+b);
        cout<<a*x+min(y,a)<<endl;;
    }
    return 0;
}


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

using ll = long long;

int n;
char s[5];
double x;
double total = 0;

main(){
    scanf("%d" , &n);

    for(int i = 0 ; i < n ; i ++){
        scanf("%lf %s" , &x , s);
        if(s[0] == 'J')total += x;
        else total += x * 380000.0;
    }
    printf("%.5f\n" , total);
}


Measured memory_bytes: 256
#!/usr/bin/env python
"""AtCoder Beginner Contest 049: C - 白昼夢 / Daydream
https://atcoder.jp/contests/abc049/tasks/arc065_a
"""

__author__ = 'bugttle <bugttle@gmail.com>'

WORDS = ['dream', 'dreamer', 'erase', 'eraser']


def match_word(S):
    for word in WORDS:
        if S.endswith(word):
            return word
    return None


def check(S):
    while True:
        word = match_word(S)
        if word is None:
            return 'NO'
        S = S[:S.rfind(word)]
        if S == '':
            return 'YES'


def main():
    S = input()
    print(check(S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
class BIT():
    def __init__(self,number):
        self.n=number
        self.list=[0]*(number+1)
        
    def add(self,i,x):#ith added x  1indexed
        while i<=self.n:
            self.list[i]+=x
            i+=i&-i
            
    def search(self,i):#1-i sum
        s=0
        while i>0:
            s+=self.list[i]
            i-=i&-i
        return s
    
    def suma(self,i,j):#i,i+1,..j sum
        return self.search(j)-self.search(i-1)
N=int(input())
A=[int(i) for i in input().split()]
if ((N*(N+1))//2)%2==1:
    a=((N*(N+1))//2)//2+1
else:
    a=((N*(N+1))//2)//2
#a=((N*(N+1))//2)-((N*(N+1))//2)//2-1
def f(s):#ans is ijou s
    X=[1 if a>=s else -1 for a in A]
    p=[0]*(N+1)
    for i in range(1,N+1):
        p[i]=p[i-1]+X[i-1]
    tree=BIT(2*N+1)
    num=0
    for i in range(1,N+2):
        num+=tree.search(p[i-1]+N+1)
        tree.add(p[i-1]+N+1,1)
    if num>=a:
        return True
    else:
        return False
x=10**9+1
y=-1
while x-y>1:
    mid=(x+y)//2
    if f(mid):
        y=mid
    else:
        x=mid
print(y)



Measured memory_bytes: 120472
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n;
    cin >> n;
    vector<ll> x(n);
    ll p = 0;
    rep(i, n) {
        cin >> x[i];
        p += x[i];
    }
    ll ans = LINF;
    {
        p /= n;
        ll now = 0;
        rep(i, n) {
            now += (x[i] - p) * (x[i] - p);
        }
        chmin(ans, now);
    }
    {
        p++;
        ll now = 0;
        rep(i, n) {
            now += (x[i] - p) * (x[i] - p);
        }
        chmin(ans, now);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
package main

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

func solve(sc *scanner, wr *bufio.Writer) {
	n, m := sc.getInt2()

	ans := 0
	mp := make(map[int]int)
	for i := 0; i < m; i++ {
		s, c := sc.getInt2()
		if x, ok := mp[s]; ok {
			if x == c {
				continue
			} else {
				fmt.Fprintln(wr, -1)
				return
			}
		}
		if (n != 1) && (s == 1) && (c == 0) {
			fmt.Fprintln(wr, -1)
			return
		}

		mp[s] = c
		ans += pow(10, n-s) * c
	}

	if (n != 1) && (ans < pow(10, n-1)) {
		ans += pow(10, n-1)
	}
	fmt.Fprintln(wr, ans)
}

func main() {
	sc := newScanner()
	wr := bufio.NewWriter(os.Stdout)
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)

	solve(sc, wr)
	wr.Flush()
}

// input ------------------------
type scanner struct {
	*bufio.Scanner
}

func newScanner() *scanner {
	sc := bufio.NewScanner(os.Stdin)
	return &scanner{sc}
}
func (sc *scanner) getInt() int {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getInt2() (int, int) {
	return sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt3() (int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt4() (int, int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInts(n int) []int {
	ret := make([]int, n)
	for i := range ret {
		ret[i] = sc.getInt()
	}
	return ret
}
func (sc *scanner) getString() string {
	sc.Scan()
	return sc.Text()
}
func (sc *scanner) getRunes() []rune {
	return []rune(sc.getString())
}
func (sc *scanner) getFloat() float64 {
	sc.Scan()
	ret, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := range ret {
		ret[i] = sc.getFloat()
	}
	return ret
}

// math ----------------------------
func sum(ns ...int) int {
	var sum int
	for _, n := range ns {
		sum += n
	}
	return sum
}

func max(ns ...int) int {
	max := ns[0]
	for i := 1; i < len(ns); i++ {
		if max < ns[i] {
			max = ns[i]
		}
	}
	return max
}

func min(ns ...int) int {
	min := ns[0]
	for i := 1; i < len(ns); i++ {
		if min > ns[i] {
			min = ns[i]
		}
	}
	return min
}

func pow(a, b int) int {
	ret := 1
	for b > 0 {
		if b&1 > 0 {
			ret = ret * a
		}
		a = a * a
		b >>= 1
	}
	return ret
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
const int INF = 1e9;

int dx[] = {0,-1,0,1};
int dy[] = {1,0,-1,0};
int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int H, W, K;
  cin >> H >> W >> K;
  VS vs(H);
  REP(y,H) cin >> vs[y];
  int sx, sy;
  REP(y,H) REP(x,W) if(vs[y][x] == 'S')
	sx = x, sy = y;
  vs[sy][sx] = '.';

  VVI dist(H, VI(W, INF));
  queue<PII> q;
  q.push(MP(sx,sy));
  dist[sy][sx] = 0;
  while(!q.empty()){
	PII p = q.front();
	q.pop();
	if(p.FF == 0 || p.FF == W-1 || p.SS == 0 || p.SS == H-1 || dist[p.SS][p.FF] == K)
	  continue;
	REP(d,4){
	  int nx = p.FF + dx[d], ny = p.SS + dy[d];
	  if(vs[ny][nx] == '#' || dist[ny][nx] < INF) continue;
	  dist[ny][nx] = dist[p.SS][p.FF] + 1;
	  q.push(MP(nx,ny));
	}
  }

  int ans = INF;
  REP(y,H) REP(x,W)
	if(dist[y][x] < INF){
	  int tmp = min(min(y,H-1-y), min(x, W-1-x));
	  mini(ans, (tmp+K-1)/K);
	}

  cout << 1+ans << endl;

  return 0;
}


Measured memory_bytes: 3456
#include<iostream>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define maxn 200005
#define LL long long
#define INF 0x3f3f3f3f
#define mset(p,v) memset(p,v,sizeof(p))
using namespace std;
int ans[40]={1,1,1,2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int k;
int main()
{
    while(~scanf("%d",&k))
    {
        printf("%d\n",ans[k-1]);
    }

	return 0;
}



Measured memory_bytes: 256
#include <string.h>
#include <stdio.h>
int main(void){
  char n[200000];
  scanf("%s", n);
  int a, i, x=0, y, temp=0;
  a=strlen(n);
  for(i=0;i<a;i++){
    if(n[i]=='A'&&temp==0){
      x=i;
      temp++;
    }else if(n[i]=='Z'&&temp==1){
      y=i;
    }
  }
  printf("%d\n", y-x+1);
  return 0;
}


Measured memory_bytes: 384
# coding: utf-8
# Your code here!

N, A, B, C, D = map(int, input().split())

if (A <= N or C <= N):
   if N % A == 0:
      X = int(N / A) * B
   else:
      X = int(N / A + 1) * B
   if N % C == 0:
      Y = int(N / C) * D
   else:
      Y = int(N / C + 1) * D
else:
   X = B
   Y = D
   
if X <= Y:
   print(int(X))
else:
   print(int(Y))


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ll N, M;
    cin >> N >> M;
    vector<vector<pair<ll, ll>>> g(N);
    using P = pair<ll, ll>;
    constexpr P NOT = {0, 0};
    vector<P> w(N, NOT);
    for (ll i = 0; i < M; i++) {
        ll u, v;
        ll s;
        cin >> u >> v >> s;
        u--, v--;
        g[u].push_back({v, s}), g[v].push_back({u, s});
    }
    ll ans = 0;
    auto dfs = [&](auto&& self, const ll s, const ll v, const ll par) -> void {
        w[s] = {v, par};
        for (const auto& e : g[s]) {
            const ll sum = e.second;
            const ll to = e.first;
            if (w[to] != NOT) {
                if (w[to].second == par) {
                    ll n = sum - v - w[to].first;
                    if (par == 1) {
                        if (n % 2 != 0 or n <= 0) {
                            ans = -1;
                        } else if (ans == 0) {
                            ans = n / 2;
                        } else {
                            if (ans != n / 2) { ans = -1; }
                        }
                    } else if (par == -1) {
                        n = -n;
                        if (n % 2 != 0 or n <= 0) {
                            ans = -1;
                        } else if (ans == 0) {
                            ans = n / 2;
                        } else {
                            if (ans != n / 2) { ans = -1; }
                        }
                    } else {
                        assert(false);
                    }
                } else {
                    if (v + w[to].first != sum) { ans = -1; }
                }
            } else {
                self(self, to, sum - v, -par);
            }
        }
    };
    dfs(dfs, 0, 0, 1);
    if (ans != 0) {
        if (ans == -1) {
            cout << 0 << endl;
            return 0;
        } else {
            
            for(int i = 0; i < N; i++){
                if(w[i].first+w[i].second*ans<= 0){cout << 0 << endl;return 0;}
                
            }
            cout << 1 << endl;
            return 0;
        }
    }
    ll inf = 1, sup = 1000000000;
    for (ll i = 0; i < N; i++) {
        if (w[i].second == 1) {
            inf = max(inf, -w[i].first + 1LL);
        } else {
            sup = min(sup, w[i].first - 1LL);
        }
    }
    cout << max(0LL, sup - inf + 1LL) << endl;
    return 0;
}


Measured memory_bytes: 12800
N = int(input())
P = [1]*(N+1)
for i in range(1,N+1):
    n = i
    for j in range(2,N+1):
        while n%j==0:
            P[j]+=1
            n//=j
P = [p for p in P if p>1]
N = len(P)-1
cnt = 0
B = [1,3,5,15,25,75]
def f(k,d):
    global N,P,cnt,B
    if d==75:
        cnt += 1
        return
    elif d>75 or k>N:
        return
    for i in range(1,P[k]+1):
        if i in B:
            f(k+1,d*i)
f(0,1)
print(cnt)

Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iomanip>
#include<algorithm>
using namespace std;
#define eps 1e-7
#define maxi 100005
long long int h[maxi];
long long int hi[maxi];
long long int n,a,b;
long long in=10000000000;
bool C(long long  x)
{
    long long t=x;
    for(long long i=0; i<n; i++)
        hi[i]=h[i];
    for(long long i=0; i<n; i++)
    {
        hi[i]-=x*b;
        if(hi[i]<=0)
            continue;
        long long y;
        if(hi[i]%(a-b)==0)
            y=hi[i]/(a-b);
        else
            y=hi[i]/(a-b)+1;
        t-=y;
    }
    if(t>=0)
        return true;
        else
    return false;
}
void solve()
{
    sort(h,h+n);
    long long  lb=0,ub=in;
    while(ub-lb>1)
    {
        long long mid=(lb+ub)/2;
        if(C(mid))
            ub=mid;
        else
            lb=mid;
    }
    cout<<ub<<endl;
}
int main()
{
    scanf("%d%d%d",&n,&a,&b);
    for(int i=0; i<n; i++)
    {
        scanf("%d",&h[i]);
    }
    solve();
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int ans = 0;
    if(a<=b){
      ans = a;
    }else{
      ans = a-1;
    }

    System.out.println(ans);
    
  }
}

Measured memory_bytes: 35728
s = input()
if len(s)%2 == 0:
    print('No')
else:
    a = s[0:(len(s)-1)//2]
    b = s[(len(s)+3)//2-1:]
    # print(a,b)
    if a == b and a==a[::-1]:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 3060
N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10 ** 9

def func(cur, a,b,c):
	if cur == N:
		return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c) > 0 else INF

	ret0 = func(cur+1,a,b,c)
	ret1 = func(cur+1, a+l[cur],b,c) + 10
	ret2 = func(cur+1, a,b+l[cur],c) + 10
	ret3 = func(cur+1, a,b,c+l[cur]) + 10
	
	return min(ret0, ret1, ret2, ret3)

print(func(0,0,0,0))

Measured memory_bytes: 3064
#include <iostream>

int main(){
    long long A, B, N;
    long long ans = 0;

    std::cin >> A >> B >> N;

//    ans = ((A * std::min(N, B-1)) / B) - (A * (std::min(N, B-1)/B));

// ↓のコードだとなぜか動かない。std::minを使うのが安心。 
// なんで通んないの・・・
// なんか値がでかいとダメみたいな法則性はあるっぽい  
#if 1
    if(N < B){
        ans = ((A * N) / B) - (A * (N/B));
    }else{
        ans = ((A * (B-1)) / B) - (A * ((B-1)/B));
    }
#endif

    std::cout << ans << std::endl;
    return 0;
}

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

using namespace std;

int main(){
       string s,ans;
       long long k;
       cin>>s>>k;
       //cout<<s[0];
       for(int i=0;i<k;i++){
           if(s[i]=='1'){
            ans="1";
           }
           if(s[i]!='1'){
                
            
                ans=s[i];
                break;
            }

       }
        cout<<ans<<endl;
        return 0;
}

       



Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, a, b)	for (int i(a); i <= (b); ++i)
#define dec(i, a, b)	for (int i(a); i >= (b); --i)
#define MP		make_pair
#define fi		first
#define se		second
 
 
typedef long long LL;
 
const int N = 1e3 + 5;
 
int a[N], b[N];
int n, m, c, fg;
char s[45];
 
 
int main(){
 
	scanf("%d", &n);
	c = 0;
 
	rep(i, 1, n){
		scanf("%d%d", a + i, b + i);
		if ((a[i] + b[i]) & 1) ++c;
		else --c;
	}
 
	if (abs(c) != n) return 0 * puts("-1");
 
	m = 31 + (c < 0);
 
	printf("%d\n", m);
	rep(i, 0, 30) printf("%d ", 1 << i);
	if (c < 0) putchar(49);
	putchar(10);
 
	rep(i, 1, n){
		int x = a[i], y = b[i];
		if (c < 0) s[31] = 'R', --x;
		fg = 0;
		dec(j, 30, 0){
			if (abs(x) < abs(y)) swap(x, y), fg ^= 1;
			if (x > 0) x -= 1 << j, s[j] = fg ? 'U' : 'R';
			else x += 1 << j, s[j] = fg ? 'D' : 'L';
		}
 
		puts(s);
	}
 
	return 0;
}
 
 

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQUE(c)   sort(ALL((c)));(c).erase(unique(ALL((c))),(c).end())
# define LOWER(s)    transform(ALL((s)),(s).begin(),TL<char>)
# define UPPER(s)    transform(ALL((s)),(s).begin(),TU<char>)
# define FOR(i,a,b)  for(LL i=(a);i<(b);i++)
# define RFOR(i,a,b) for(LL i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

int w, h;
int sx, sy;
map<int, pair<int, int>> dpos;
string maze[22];
int g[11][11];
LL dp[1 << 11][11];

int d[1001][1001];
void bfs(int py, int px) {
	queue<pair<int, int>> que;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			d[i][j] = HINF;
		}
	}
	que.push(pair<int, int>(px, py));
	d[py][px] = 0;
	while (que.size()) {
		pair<int, int> p = que.front();
		que.pop();
		for (int i = 0; i < 4; i++) {
			int nx = p.first + dx[i], ny = p.second + dy[i];
			if (0 <= nx&&nx < w && 0 <= ny&&ny < h &&maze[ny][nx] != 'x'&&d[ny][nx] == HINF) {
				que.push(pair<int, int>(nx, ny));
				d[ny][nx] = d[p.second][p.first] + 1;
			}
		}
	}
}

int main() {

	while (cin >> w >> h  &&w&&h) {
		REP(i, h)cin >> maze[i];
		int cnt = 0;
		REP(i, h)REP(j, w) {
			if (maze[i][j] == 'o') {
				dpos[cnt] = make_pair(i, j);
				cnt++;
			}
		}
		REP(i, h)REP(j, w) {
			if (maze[i][j] == '*') {
				dpos[cnt] = make_pair(i, j);
				cnt++;
			}
		}
		REP(i, cnt)REP(j, cnt)g[i][j] = HINF;
		REP(i, cnt) {
			bfs(dpos[i].first, dpos[i].second);
			REP(j, cnt) {
				g[i][j] = min(g[i][j], d[dpos[j].first][dpos[j].second]);
			}
		}
		REP(i, (1 << 11))REP(j, 11)dp[i][j] = HINF;
		REP(i, cnt) dp[(1 << cnt) - 1][i] = g[0][i];
		for (int S = (1 << cnt) - 2; S >= 0;S--)REP(v, cnt)REP(u, cnt) {
			if (!(S >> u & 1)) {
				dp[S][v] = min(dp[S][v], dp[S | 1 << u][u] + g[v][u]);
			}
		}
		LL ans = HINF;
		REP(i, cnt) ans = min(ans, dp[1 << i][i]);
		cout << (ans == HINF ? -1 : ans) << endl;
	}
}


Measured memory_bytes: 3400
#include <iostream>
#include <string>
using namespace std;
 
int main() {
  int a;
  cin >> a;
  string str = to_string(a);
  if(str.at(0) == '7' || str.at(1) == '7' || str.at(2) == '7'){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3692
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
 
int main(){
  long int k;
  char s[100];
  int i;
  
  scanf("%s",s);
  scanf("%ld",&k);
  
  for(i=0;i<100;i++){
    if(s[i]!='1'){
      printf("%c",s[i]);
      break;}
      
   
    else if (k==i+1){
      printf("%c",s[i]);
      break;}
    
  
  }
  
  
}

Measured memory_bytes: 128
n = int(input())
t = list(map(int, input().split()))
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

ans, l, r = 1, 0, n - 1
for i in range(1, n):
    if t[i] == t[i - 1]:
        ans = ans * t[i] % mod
    if t[i] == a[i]:
        l = i
        break
for i in range(n - 1)[::-1]:
    if a[i] == a[i + 1]:
        ans = ans * a[i] % mod
    if t[i] == a[i]:
        r = i
        break

if not t[l] == max(t) == max(a) == a[r]:
    print(0)
else:
    print(ans * pow(t[l], max(r - l - 1, 0), mod) % mod)


Measured memory_bytes: 97624
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
using namespace std;

int main(void){
    int n, m;
    cin >> n >> m;
    vector<vector<long long int>> data(n, vector<long long int>(2));
    for(int i = 0; i < n; i++)
        cin >> data[i][0] >> data[i][1];
    sort(&data[0], &data[n]);
    long long int ans = 0;
    int count = 0;
    for(int i = 0; i < n; i++){
        if(count+data[i][1]<=m){
            ans +=data[i][0]*data[i][1];
            count+=data[i][1];
        }
        else if(count+data[i][1]>m){
            for(int j = 0; j < data[i][1]; j++){
                ans+=data[i][0];
                count++;
                if(count==m)
                    break;
            }
        }      
        if(count==m){
            cout << ans << endl;
            break;
        }
    }
    return 0;
}

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

int main(){
  int n;
  vector<int> a;
  cin >> n;
  for(int i = 0; i < n; i++){
    int tmp;
    cin >> tmp;
    a.push_back(tmp);  
  }
  
  sort(a.begin(),a.end());
  a.erase(unique(a.begin(),a.end()),a.end());
  
  cout << a.size() << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
 
#define int long long int
#define rep(i,n) \
    for(int i = 0; i < n; i++)
#define rep2(i, a, b) \
    for(int i = a; i < b; i++)
#define all(c) \
    c.begin(), c.end()
#define init(arr, num) \
    memset(arr, num, sizeof(arr))
#define fast\
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inputFile \
    freopen("input.txt", "r", stdin); 
#define outputFile \
    freopen("output.txt", "w", stdout);
#define modM 1000000007
#define PI 3.1415926535897932

#ifdef Voneone
#define TRACE
#endif
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std::endl;

}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); 
    cout.write(names, comma - names) << " : " << arg1 << " | "; 
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

 
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< int, int > ii;
typedef unordered_set<int> usi;
 

void solve() 
{ 

    

    int r; 
    cin >> r;

    cout << setprecision(10) << 2*PI*r;


} 
 
 
 
 
signed main()
{
 
    
    #ifdef Voneone
    inputFile;
    #endif
    #ifndef Voneone
    fast;
    #endif


    int T = 1;
    // cin >> T;
    while(T--){
        solve();
        cout << endl;
        
        

    }
    
    
    return 0;
 
}






Measured memory_bytes: 3808
#include<bits/stdc++.h>
#define cs const
using namespace std;
int Mod;
int add(int a, int b){ return a + b >= Mod ? a + b - Mod : a + b; }
int dec(int a, int b){ return a - b < 0 ? a - b + Mod : a - b; }
int mul(int a, int b){ return 1ll * a * b % Mod; }
void Add(int &a, int b){ a = add(a,b); }
void Dec(int &a, int b){ a = dec(a,b); }
void Mul(int &a, int b){ a = mul(a,b); }
cs int N = 6e3 + 50;
int n, f[N][N*2];
int main(){
	#ifdef FSYolanda
	freopen("1.in","r",stdin);
	#endif
	scanf("%d%d",&n,&Mod); n*=3; f[0][0+n]=1;
	for(int i=1,u=n; i<=u; i++){
		for(int j=-(i>>1); j<=i; j++){
			Add(f[i][j+1+n],f[i-1][j+n]);
			if(i>1) Add(f[i][j-1+n],mul(f[i-2][j+n],i-1));
			if(i>2) Add(f[i][j+n],mul(f[i-3][j+n],(i-1)*(i-2)));
		}
	} 
	int as=0;
	for(int i=n; i<=n+n; i++) Add(as,f[n][i]);
	cout<<as; return 0;
}

Measured memory_bytes: 283008
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll k,c=0,i,curr;
	cin>>k;
	queue<ll> q;
	for(i=1;i<=9;i++)
	{
	q.push(i);
	if(k==i)
	break;
	}
	c=9;
	while(c<=k)
	{
		curr=q.front();
		q.pop();
		int d=curr%10;
		if(d!=0)
		{
			c++;
			q.push(curr*10+d-1);
			if(c==k)
			break;
		}
		c++;
		q.push(curr*10+d);
		if(c==k)
		break;
		if(d!=9)
		{
			c++;
			q.push(curr*10+d+1);
			if(c==k)
			break;
		}
	}
	cout<<q.back();
	return 0;
}
	


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define sq(x) ((x)*(x))
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17

#define maxn 300005
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<int, int> pii;

i64 x[55] , y[55] ;
map < pair< i64,i64 > , i64 > M ;

int main()
{
    i64 n ;
    scanf("%lld",&n) ;

    for(int i=1 ; i<=n ; i++) scanf("%lld %lld",&x[i],&y[i]) ;

    for(int i=1 ; i<=n ; i++) M[ mp(x[i],y[i]) ] = 1 ;

    int ans = n ;

    for(int i=1 ; i<=n ; i++)
    {
        for(int j=1 ; j<=n ; j++)
        {
            if(i==j) continue ;

            i64 p = x[i]-x[j] , q = y[i]-y[j] ;

            int ret = n ;

            for(int k=1 ; k<=n ; k++) if( M.find( mp( x[k]+p,y[k]+q ) ) != M.end() ) ret-- ;

            ans = min(ans,ret) ;
        }
    }

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

    return 0 ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 998244353;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    string S,T;
    cin >> S >> T;
    ll N = S.size();
    vector<ll> v(26,-1), u(26,-1);
    bool flag = true;
    rep(i,N){
        ll s = S[i]-'a';
        ll t = T[i]-'a';
        if(v[s] == -1){
            v[s] = t;
        }else{
            if(v[s] != t){
                flag = false;
                break;
            }
        }
        if(u[t] == -1){
            u[t] = s;
        }else{
            if(u[t] != s){
                flag = false;
                break;
            }
        }
    }
    cout << (flag?"Yes":"No") << endl;
}

Measured memory_bytes: 3860
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
C.append(0)
ans = B[A[0]-1]
pre = A[0]-1
for i in range(1,N):
    ans += B[A[i]-1]
    if A[i]-1 - pre == 1:
        ans += C[pre]
    pre = A[i]-1
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    string s;
    cin >> s;
    deque<char> dq;
    for (auto i : s) {
        dq.push_back(i);
    }
    int q;
    cin >> q;
    int parity = 0;
    rep(i, 0, q) {
        int t;
        cin >> t;
        if (t == 1) parity = 1 - parity;
        else {
            int f;
            cin >> f;
            char c;
            cin >> c;
            if (parity == 0) {
                if (f == 1) dq.push_front(c);
                else dq.push_back(c);
            } else {
                if (f == 1) dq.push_back(c);
                else dq.push_front(c);
            }
        }
    }
    string ans;
    for (auto i : dq) ans += i;
    if (parity == 1) reverse(all(ans));
    cout << ans << endl;
    return 0;
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = int.Parse(Console.ReadLine());
            List < int > cardpintlist = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToList();

            cardpintlist.Sort();
            cardpintlist.Reverse();
            int sumAlice = 0;
            int sumBob = 0;
            for(int i = 0; i <= count-1; i++ )
            {
                if ((i+1) % 2 == 0)
                {
                    sumBob += cardpintlist[i];
                }
                else
                {
                    sumAlice += cardpintlist[i];
                }
            }
            Console.WriteLine(sumAlice - sumBob);
        }

    }
}

Measured memory_bytes: 11220
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
const int maxn=5010;
int k,q,d[maxn],n,x,m,a[maxn];
int main()
{
	scanf("%d%d",&k,&q);
	for (int i=1;i<=k;i++) scanf("%d",&d[i]);
	for (int _=1;_<=q;_++)
	{
		scanf("%d%d%d",&n,&x,&m); int sum0=0,t=n; long long sum=0;
		n--;
		for (int i=1;i<=k;i++) 
		{
			a[i]=d[i]%m; sum+=a[i];
			if (a[i]==0) sum0++;
		}
		sum=sum*(n/k); sum0=sum0*(n/k); n=n-(n/k)*k;
		for (int i=1;i<=n;i++) 
		{
			if (a[i]==0) sum0++;
			sum+=a[i];
		}
		sum+=(x%m); printf("%lld\n",t-1-sum0-sum/m);
	}
return 0;
}

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

int N;
string s, t;

int solve() {
  for(int i = 0; i < N; i++) {
    if(s.substr(i) == t.substr(0, N-i)){
      return i+N;
    }
  }
  return N*2;
}

int main() {
  cin >> N;
  cin >> s >> t;
  cout << solve() << endl;
  return 0;
}


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

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

int main(){
  int n;
  cin>>n;
  unordered_map <string,int> mp;
  rep(i,n){
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    mp[s]++;
  }

  ll ans=0;
  for (auto f:mp){
    ll nn=f.second;
    ans+=nn*(nn-1)/2;
  }
  cout<<ans;

}


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

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int INF = pow(2,29);
const int MOD = 1000000007;

int main() {
  int X, A; cin >> X >> A;
  int result = X<A ? 0 : 10;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int n, ans = 100;
    scanf("%d", &n);

    for (int i = 0 ; i < n ; i++)
    {
        int a, cnt = 0;
        scanf("%d", &a);

        while (a % 2 == 0)
        {
            a /= 2;
            cnt++;
        }
        if (cnt < ans)
            ans = cnt;
    }
    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <typeinfo>
using namespace std;
using ll = long long;

int main() {

	ll n, sum=0;
	cin >> n;
	vector<ll> a(n);

	for (int i = 0; i < n; i++)
		cin >> a[i];

	sort(a.begin(), a.end());

	for (int i = 1; i < n; i++)
	{
		sum += a[n-i-1];
	}

	if (sum > a[n-1])
		cout << "Yes\n";
	else
		cout << "No\n";
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define P(x) {if (debug) cout << x << endl;}
#define H(x) P(#x << ": " << (x))
#define FR(i,a,b) for (int i=(a); i<(b); i++)
#define F(i,n) FR(i,0,n)
#define DR(i,a,b) for (int i=(b); i-->(a);)
#define D(i,n) DR(i,0,n)
#define S(s) (int)(s).size()
#define ALL(v) v.begin(), v.end()
#define MI(a,v) a = min(a,v)
#define MA(a,v) a = max(a,v)
#define V vector
#define pb push_back
#define mt make_tuple
using namespace std;
template<class T> ostream &operator<<(ostream &os, V<T> v) {
    F(i,S(v)) os<<(i?" ":"")<<v[i];
    return os;
}
const bool debug = 0;

V<V<bool>> adj;
V<int> color;
int n;

bool dfs(int u, bool c, V<int> &occ) {
    if (color[u] == !c) return false;
    else if (color[u] == c) return true;
    color[u] = c;
    occ[c]++;
    F(v,n) if (adj[u][v])
        if (!dfs(v, !c, occ))
            return false;
    return true;
}

int roads(int x) {
    return x*(x-1)/2;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int m; cin>>n>>m;
    adj.assign(n, V<bool>(n, true));
    F(i,n) adj[i][i] = false;
    F(i,m) {
        int a,b; cin>>a>>b;
        a--,b--;
        adj[a][b] = adj[b][a] = false;
    }
    color.assign(n, -1);
    int off = 0;
    V<bool> knap(n+1, false);
    knap[0] = true;
    bool poss = true;
    F(u,n) if (color[u] == -1) {
        V<int> occ{0,0};
        if (!dfs(u, 0, occ))
            poss = false;
        if (occ[1] < occ[0])
            swap(occ[0], occ[1]);
        H(occ)
        off += occ[0];
        int diff = occ[1]-occ[0];
        DR(i,diff,n+1) if (knap[i-diff]) {
            knap[i] = true;
        }
    }
    H(off)
    H(knap)
    int best = n*n;
    F(i,n+1) if (knap[i]) {
        int sa = off + i, sb = n - sa;
        H(sa) H(sb)
        MI(best, roads(sa) + roads(sb));
    }
    cout<<(poss ? best : -1)<<"\n";
}

Measured memory_bytes: 512
#include <stdio.h>

int main(){
	int i,n,k,data[10000];
	for(i=2;i<10000;i++){
		data[i]=1;
	}
	for(i=2;i*i<10000;i++){
		if(data[i]==1){
			for(k=i*i;k<=10000;k+=i){
				data[k]=0;
			}
		}
	}
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		for(i=n;n>=3;i--){
			if(data[i]==1&&data[i-2]==1){
				printf("%d %d\n",i-2,i);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1064
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n = int(input())
    nums = []
    n6 = 6
    while n6 <= n:
        nums.append(n6)
        n6 = n6 * 6
    n9 = 9
    while n9 <= n:
        nums.append(n9)
        n9 = n9 * 9
    nums.sort(reverse=True)
    dp = [i for i in range(2 * n + 1)]
    for num in nums:
        for j1 in range(n + 1):
            dp[j1+num] = min(dp[j1+num], dp[j1] + 1)
    print(dp[n])


if __name__ == '__main__':
    main()


Measured memory_bytes: 16868
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 100005;
const ll MOD = 1e9+7;
vector<int> G[MAX_N];
ll N,K;

ll dfs(int x, int from)
{
	ll c = K-1;
	if (from != -1) c--;
	ll res = 1;
	rep(i,G[x].size())
	{
		if (G[x][i] == from) continue;
		res *= c;
		c--;
		res %= MOD;
	}
	rep(i,G[x].size())
	{
		if (G[x][i] == from) continue;
		res *= dfs(G[x][i],x);
		res %= MOD;
	}
	return res;
}

int main()
{
	cin >> N >> K;
	rep(i,N-1)
	{
		int a,b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	ll ans = K * dfs(0,-1);
	ans %= MOD;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11520
// upper_bound使わない方法

#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
const ll MOD = 1000000007;
// const ll INF = 1000000000000000000LL;

int main(){
    // 入力
    int n,m,k;
    cin >> n >> m >> k;
    vector<ll> a(n);
    vector<ll> b(m);
    rep(i,n) cin >> a[i];
    rep(i,m) cin >> b[i];
    //累積和 
    vector<ll> A(n+1);
    vector<ll> B(m+1);
    for(int i=1;i<=n;i++) A[i] = A[i-1]+a[i-1];
    for(int i=1;i<=m;i++) B[i] = B[i-1]+b[i-1];
    //aを何冊か決め売って、二分探索より
    //読めるbの数を求める
    int ans=0; 
    rep(i,n+1){
        int cnt=0;
        cnt = i;
        ll rm = k-A[i];
        if(rm<0) continue;
        //rmをB[i]で二分
        int left = 0;
        int right = B.size()-1;
        while(right-left>1){
            int mid = (left+right) /2;
            if(B[mid]>rm) right = mid;
            else left = mid;
        }
        if(rm>=B[right]) left = right;
        cnt+=left;
        
        ans = max(ans,cnt);
    }
    cout << ans << endl;
	return 0;
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;

const ll INF=1LL<<60;
const int MOD=1e9+7;

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

int main(){
    int w, h;
    while(cin >> w >> h){
        if(w == 0 && h == 0) break;
        vector<vector<vi>> mn(h, vector<vi>(w, vi(4, 1)));
        for(int i=0; i<2*h-1; i++){
            for(int j=(i+1)%2; j<w; j++){
                int x; cin >> x;
                if(x == 0) continue;
                if(i%2 == 0){
                    mn[i/2][j-1][1]=0;
                    mn[i/2][j][3]=0;
                }
                else{
                    mn[i/2][j][0]=0;
                    mn[i/2+1][j][2]=0;
                }
            }
        }
        queue<pii> que;
        vector<vi> dist(h, vi(w, 0));
        que.push({0, 0});
        dist[0][0]=1;
        while(!que.empty()){
            int x, y;
            tie(x, y)=que.front();
            que.pop();
            for(int i=0; i<4; i++){
                int nx, ny;
                nx=x+dx[i], ny=y+dy[i];
                if(nx<0 || nx>=h || ny<0 || ny>=w) continue;
                if(mn[x][y][i] == 0) continue;
                if(dist[nx][ny] != 0) continue;
                dist[nx][ny]=dist[x][y]+1;
                que.push({nx, ny});
            }
        }
        cout << dist[h-1][w-1] << endl;
    }
    return 0;
}



Measured memory_bytes: 3252
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int [] A = new int [N];
		for (int i=0; i<N; i++){
			A[i]=sc.nextInt();
		}
		
		int count = 0;
		for (int i=0; i<N-2; i++){
			if (A[i]<A[i+1] && A[i+1]<A[i+2])
				count++;
			else if  (A[i]>A[i+1] && A[i+1]>A[i+2])
				count++;
		}
		
		System.out.println(count);
		sc.close();

	}

}

Measured memory_bytes: 21844
#include <iostream>
#include <fstream>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int,int> PP;

/*
    freopen("input","r",stdin);
    freopen("output","w",stdout);
*/

int P[100010];

int N, K;

int res = 0;

vector<unordered_set<int> > T;

int solve(int n) {
	unordered_set<int>::iterator it;
	int m = 0;
	for (it = T[n].begin();it != T[n].end();++it) {
		m = max(m, solve(*it) + 1);
	}
	if (m == K - 1 && P[n] != 1) {
		// move!
		res++;
		return -1;
	}
	return m;
}

int main() {
    ios::sync_with_stdio(false);
    cin >> N >> K;
    memset(P, 0, sizeof(P));
    for (int i = 1;i <= N;i++) cin >> P[i];
	if (P[1] != 1) {
		P[1] = 1;
		res++;
	}
	if (K == 1) {
		for (int i = 2;i <= N;i++) {
			if (P[i] != 1) res++;
		}
		cout << res << endl;
		return 0;
	}
	T.resize(N + 1);
	for (int i = 2;i <= N;i++) T[P[i]].insert(i);
	int tmp = solve(1);
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 15488
#include<stdio.h>
int main(void){
  int A,B,C,D;
  int ab[101]={},cd[101]={};
  scanf("%d %d %d %d",&A,&B,&C,&D);
  for(int i=A;i<B;i++){
    ab[i]=1;
  }
  for(int j=C;j<D;j++){
    cd[j]=1;
  }
  int count;
  for(int i=0;i<=100;i++){
    if(ab[i]==1&&cd[i]==1) count++;
  }

  printf("%d\n",count);
  return 0;
}



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

int main(){
    int a,b,c,x,cnt=0;
    cin>>a>>b>>c>>x;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                if(500*i+100*j+50*k==x)cnt++;
            }
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string N;
int ans=0;
  cin >> N;
if(N=="RRR")  ans=3;
else if (N=="SSS") ans=0;
else if(N=="SRR"||N=="RRS") ans=2;
else ans=1;
cout << ans;

}

Measured memory_bytes: 3612
#include <iostream>
#include <math.h>
#include <set>
#include<vector>
#include<string>
#include <algorithm>
#include<queue>
#include<map>
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define per(i,j,k) for(int i = (int)j;i >= (int)k;i --)
#define F(i,k) for(int i=(int)0;i<(int)k;i++)
#define pii pair<int,int>
typedef long long ll;
const int maxn = 3e5 + 5;
using namespace std;
map<string, int> mp;
ll m,k;
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> m;
	rep(i, 1, m) {
		string s;
		cin >> s;
		sort(s.begin(), s.end());
		mp[s]++;
	}
	ll ans = 0;
	for (auto pi : mp) {
		ans += (ll)(pi.second)*(pi.second - 1) / 2;
	}
	cout << ans << endl;
		cin >> m;
}

/*
3
acornistnt
peanutbomb
constraint
*/

Measured memory_bytes: 11264
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]
 
use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;
 
use itertools::Itertools;
use itertools_num::ItertoolsNum;

#[fastout]
fn solve() {
    const MOD: usize = 1_000_000_007;
    const INF: usize = std::usize::MAX;

    input!{
        s: Chars,
    }
    let mut s: VecDeque<char> = VecDeque::from(s);
    let mut leaved = vec![];
    let all_num = s.len();

    loop {
        // dbg!(&s);
        // dbg!(&leaved);
        if (s.len() == 0 && (leaved.iter().all_equal() || leaved.len() == 0)) || s.iter().chain(leaved.iter()).all_equal() { break; }

        let s1 = s.pop_front().unwrap();

        if !leaved.is_empty() {
            let l = leaved.pop().unwrap();
            if l != s1 { continue; }
            leaved.push(l);
        }

        let s2 = s.pop_front().unwrap();

        if s1 != s2 { continue };

        leaved.push(s1);
        s.push_front(s2);
    }

    println!("{}", all_num - s.len() - leaved.len())
}

fn main() {
    solve();
}


Measured memory_bytes: 2948
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val trains = (0 until n - 1).map { SpecialTrain(sc.next().toInt(), sc.next().toInt(), sc.next().toInt()) }
    println(problem084c(n, trains))
}

fun problem084c(n: Int, trains: List<SpecialTrain>): String {
    val ans = mutableListOf<Int>()
    for (i in 0 until n - 1) {
        var time = 0
        for (j in i until n - 1) {
            val tn = trains[j]
            when {
                time < tn.s -> time = tn.s
                time % tn.f == 0 -> {
                }
                else -> time = time + tn.f - time % tn.f
            }
            time += tn.c
        }
        ans.add(time)
    }
    return ans.joinToString("\n") + "\n0"
}

data class SpecialTrain(var c: Int, var s: Int, var f: Int)

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

using namespace std;

const int N = 2 * 1e3 + 123;

int n;

int f[N], ans;

int main () {
    cin >> n;
    for (int i = 1;i <= n;i ++) {
        cin >> f[i];
    }sort (f + 1, f + n + 1);
    for (int i = 3;i <= n;i ++) {
        for (int j = 2;j < i;j ++) {
            int a = f[i], b = f[j];
            int l = 1, r = j - 1, id = -1;
            while (l <= r) {
                int mid = (l + r) >> 1, c;
                c = f[mid];
                if (a < b + c && b < c + a && c < a + b) {
                    id = mid;
                    r = mid - 1;
                }else l = mid + 1;
            }
            if (id != -1)ans += j - id;
        }
    }cout << ans;
}


Measured memory_bytes: 256