akhauriyash/Code-Regression huggingface dataset:
x,k,d = map(int,input().split())
x = abs(x)
if x - k*d > x%d:
    print(x - k*d)
else:
    if x%d == 0 and x // d <= k:
        if (k - x//d)%2 == 0:
            print(0)
        else:
            print(d)
    else:
        if (k - x // d) % 2 == 1:
            print(abs(x%d-d))
        else:
            print(x%d)

Measured memory_bytes: 9192
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))

m = max(a)
idxs = [i for i, v in enumerate(a) if v == m]

if len(idxs) > 1:
    for i in range(n):
        print(m)

if len(idxs) == 1:
    idx = idxs[0]
    a.pop(idx)
    m2 = max(a)
    for i in range(n):
        if idx == i:
            print(m2)
        else:
            print(m)


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

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

	unordered_map<string,int> mp ;

	for(int i=0;i<n;i++){
		string s ;
		cin>>s ;
		mp[s]++ ; 
	}

	cout<<"AC x "<<mp["AC"]<<"\n" ;
	cout<<"WA x "<<mp["WA"]<<"\n" ;
	cout<<"TLE x "<<mp["TLE"]<<"\n" ;
	cout<<"RE x "<<mp["RE"]<<"\n" ;

}	

int main(){
	
	int y ;

	y=1 ;
	//cin>>y ;

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

}

Measured memory_bytes: 3656
#include <iostream>
using namespace std;
typedef unsigned long long ll;

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

    int n;
    cin>>n;

    ll sum=1, v[n], prev;

    for(int i=0; i<n; i++){
        cin>>v[i];
        if(!v[i]){
            cout<<0;
            return 0;
        }
    }
    for(int i=0; i<n; i++){
        sum*=v[i];
        if(i){
            if(prev>sum){
                cout<<-1;
                return 0;
            }
        }
        if(sum>1000000000000000000){
            cout<<-1;
            return 0;
        }
        prev=sum;
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 4396
#include<bits/stdc++.h>
using namespace std;
using p = pair<int,int>;
int main(){
    int h,w,k;
    cin >> h >> w >> k;
    char field[h][w];
    vector<p> stro;
    for(int x = 0; x < h; x ++){
        for(int y = 0;y < w; y++){
            cin >> field[x][y];
        }
    }

    bool first = true, seter = false;
    int ans[h][w] = {};
    int idx = 1;
    for(int x = 0; x < h; x ++){
        int buf = 0;
        for(int y = 0; y < w; y++){
            if(field[x][y] == '#'){
                if(first){
                    for(int dx = 0; dx <= x; dx ++){
                        for(int dy = buf; dy <= y; dy ++){
                            ans[dx][dy] = idx;
                        }
                    }
                    buf = y+1;
                }else {
                    for(int dy = buf; dy <= y; dy ++){
                        ans[x][dy] = idx;
                    }
                    buf = y+1;
                }
                idx ++;
                seter = true;
            }
        }
        if(seter){
            first = false;
        }        
    }
    for(int x = 0; x < h; x ++){
        if(ans[x][0] == 0){
            for(int y = 0; y < w; y++){
                ans[x][y] = ans[x-1][y];
            }
        }
        for(int y = 0; y < w; y++){
            if(ans[x][y] == 0){
                ans [x][y] = ans[x][y-1];
            }
            cout << ans[x][y] << " ";
        }
        cout << endl;
    }
}



Measured memory_bytes: 1152
using System;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().ToCharArray();
            Array.Sort(s);

            var a = new int[26];
            for(var i = 0; i < s.Length; i++){
                var c = Convert.ToInt32(s[i]) - 97;
                a[c] += 1;
            }

            var flag = true;
            for(var i = 0; i < 26; i++){
                if(a[i] == 0){
                    Console.WriteLine(Convert.ToChar(i + 97));
                    flag = false;
                    break;
                }
            }

            if(flag){
                Console.WriteLine("None");
            }
        }
    }
}


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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define ENDL "\n"
#define PRINT(x) cout << (x) << ENDL

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int in(int& a) {return scanf("%d", &a);}
inline void out(int n) {printf("%d\n", n);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};


int V, E, mst;
vector<pint> adj[10000];
int cost[10000];
bool used[10000];

void prim(int s){
    REP(i, V){
        cost[i] = INT32_MAX; 
        used[i] = false;
    }
    cost[s] = 0;
    mst = 0;
    priority_queue<pint, vector<pint>, greater<pint>> que;
    que.push(pint(cost[s], s));
    REP(i, V){
        int index = que.top().second;
        while(used[index]){
            que.pop();
            index = que.top().second;
        }
        used[index] = true;
        mst += que.top().first;
        que.pop();
        for(auto p : adj[index]){
            int weight = p.first;
            int next = p.second;
            if(weight < cost[next]){
                cost[next] = weight;
            }
            if(!used[next]) que.push(pint(cost[next], next));
        }
    }
}

signed main(){
    cin >> V >> E;
    int s, t, w;
    REP(i, E){
        cin >> s >> t >> w;
        adj[s].push_back(pint(w, t));
        adj[t].push_back(pint(w, s));
    }
    prim(0);
    PRINT(mst);
    return 0;
}


Measured memory_bytes: 6856
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cwchar>
#include <cwctype>
#include <exception>
#include <locale>
#include <numeric>
#include <new>
#include <stdexcept>
#include <limits>
#include <valarray>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <utility>
#include <bitset>
#include <algorithm>
#include <functional>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;

struct dsu
{
	int nxt[300005];
	
	void init(int n)
	{
		for(int i = 0; i <= n; i ++) nxt[i] = i;
	}
	
	int root(int v)
	{
		return v == nxt[v] ? v : nxt[v] = root(nxt[v]);
	}
	
	bool unite(int u, int v)
	{
		u = root(u);
		v = root(v);
		if(u == v) return false;
		nxt[u] = v;
		return true;
	}
}vis, con;

int n, q;
PII dt[800005];
int dat[200005];

pair<int, PII> E[400005];

int main()
{
	int n, q;
	scanf("%d%d", &n, &q);
	
	rep(i, q) {
		scanf("%d%d%d", &E[i].second.first, &E[i].second.second, &E[i].first);
		dt[i << 2] = MP(E[i].first + 1 - 2 * E[i].second.first, E[i].second.first);
		dt[i << 2 | 1] = MP(E[i].first + 2 - 2 * E[i].second.second, E[i].second.second);
		dt[i << 2 | 2] = MP(E[i].first + 1 + 2 * (n - E[i].second.first), 0);
		dt[i << 2 | 3] = MP(E[i].first + 2 + 2 * (n - E[i].second.second), 0);
	}
	
	vis.init(n);
	sort(dt, dt + (q << 2));
	rep(i, q << 2) for(int j = vis.root(dt[i].second); j < n; j = vis.root(j)) {
		dat[j] = dt[i].first + 2 * j;
		vis.unite(j, j + 1);
	}
	
	rep(i, n) E[i + q] = MP(dat[i], MP(i, (i + 1) % n));
	
	sort(E, E + n + q);
	con.init(n);
	
	LL ans = 0;
	rep(i, n + q)
	if(con.unite(E[i].second.first, E[i].second.second)) ans += E[i].first;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 15360
package main

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

func main() {
	N := ReadInt()
	A := ReadInts(N)
	y, s := 1000, 0
	for i := 0; i < N; i++ {
		b := i < N-1 && A[i] < A[i+1]
		if b {
			// buy
			add := y / A[i]
			s += add
			y -= A[i] * add
		} else {
			// sell
			y += A[i] * s
			s = 0
		}
	}
	fmt.Println(y)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1844
N, K = map(int, input().split())

num = 0
if K == 0:
    print(N**2)
else:
    for i in range(K+1, N+1):
        a = N // i
        b = N % i
        num += ((i - K) * a + max(0, b-K+1))
        
    print(num)

Measured memory_bytes: 3060
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N,K = MI()
P = LI()
C = LI()

for i in range(N):
    if C[i] >= 0:
        break
else:
    print(max(C))
    exit()

from itertools import accumulate


def f(A):  # Aを無限個つなげたリストの、連続K個以下の連続部分列の和の最大値
    a = len(A)
    res = 0
    if sum(A) > 0:
        if K // a > 0:
            res = sum(A) * (K // a - 1)
            r = K % a + a
        else:
            r = K % a
    else:
        r = K % a + a

    A = [0] + A + A + A
    S = list(accumulate(A))
    m = 0
    for i in range(a):
        for k in range(1, r + 1):
            b = S[i + k] - S[i]
            m = max(m, b)
    res += m
    return res


flag = [0]*N
ans = 0
for i in range(N-1):
    if flag[i] != 0:
        continue
    A = [C[i]]
    flag[i] = 1
    j = P[i]-1
    while j != i:
        A.append(C[j])
        flag[j] = 1
        j = P[j]-1
    ans = max(ans,f(A))

print(ans)


Measured memory_bytes: 69304
import java.util.Scanner;

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

class Scan {
	public static void getNum() {
		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int b = s.nextInt();
		if (a > b) {		
			System.out.println("a > b");
		} else if (a < b) {
			System.out.println("a < b");
		} else {
			System.out.println("a == b");
		}
	}
}

Measured memory_bytes: 26372
import sys
input = sys.stdin.readline
from collections import defaultdict
from heapq import *

def dijkstra(sta):
    dist = [10**18]*(N*2510)
    dist[sta] = 0
    pq = []
    heappush(pq, (dist[sta], sta))
    
    while pq:
        d, v = heappop(pq)
        
        if dist[v]<d:
            continue
        
        for nv, w in G[v]:
            if dist[nv]>dist[v]+w:
                dist[nv] = dist[v]+w
                heappush(pq, (dist[nv], nv))
    
    return dist

N, M, S = map(int, input().split())
serial = [[0]*2510 for _ in range(N)]
c = 0

for i in range(N):
    for j in range(2510):
        serial[i][j] = c
        c += 1

G = [[] for _ in range(N*2510)]

for _ in range(M):
    u, v, a, b = map(int, input().split())
    u -= 1
    v -= 1
    
    for i in range(a, 2510):
        G[serial[u][i]].append((serial[v][i-a], b))
        G[serial[v][i]].append((serial[u][i-a], b))

for i in range(N):
    c, d = map(int, input().split())
    
    for j in range(2510):
        if j+c<2510:
            G[serial[i][j]].append((serial[i][j+c], d))

dist = dijkstra(serial[0][min(S, 2509)])

for i in range(1, N):
    ans_i = 10**18
    
    for j in range(2510):
        ans_i = min(ans_i, dist[serial[i][j]])
    
    print(ans_i)

Measured memory_bytes: 115244
#include<stdio.h>

int main(void){
int N,L[10];

int i,l,k,sum;

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

for(l=0;l<(N-1);l++){
for(i=0;i<(N-1);i++){
if(L[i]<L[i+1]){k=L[i];L[i]=L[i+1];L[i+1]=k;}
}
}
for(i=0;i<(N-1);i++){
sum=sum+L[i+1];
}

if(L[0]<sum){printf("Yes");}
else{printf("No");}
return 0;}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main ()
{
      FastIO
      lld a, b;
      cin >> a;
      cin >> b;
      string s;
      string t;
      s = "";
      t = "";
      lld  i;
      foi(i, b)
      {
      	s+= (char)(a+48);
      }
      foi(i, a)
      {
      	t+= (char)(b+48);
      }
      if (s < t)
      	cout << s;
      else
      	cout << t;
      return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main() {
    string s;cin >> s;
    int lon,cnt;lon = s.length();
    cnt = 0;

    for(int i=1;i<lon;i++){
        if(lon == 1)break;
        
        if(s[i] == s[i-1]){
            cnt++;
            if(s[i]=='0'){
                s[i] = '1';
            }else{
                s[i] = '0';
            }
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define mod 1000000007
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main() {
    int x, a, b;
    cin >> x >> a >> b;
    if (a - b >= 0) {
        cout << "delicious" << endl;
    }
    else if (-1 * (a - b) <= x) {
        cout << "safe" << endl;
    }
    else {
        cout << "dangerous" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(){
   
  int n;

  while(cin>>n, n){
    int cnt=0;
    
    n=1000-n;
    cnt+=n/500;
    n%=500;
    cnt+=n/100;
    n%=100;
    cnt+=n/50;
    n%=50;
    cnt+=n/10;
    n%=10;
    cnt+=n/5;
    n%=5;
    
    cout<<cnt+n<<endl;
  }
   
  return 0;
}

Measured memory_bytes: 2996
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int[] group1 = {1,3,5,7,8,10,12};
		int[] group2 = {4,6,9,11};
		int[] group3 = {2};
		int h1 = 0;
		int h2 = 0;
		Scanner sc = new Scanner(System.in);
		h1 = sc.nextInt();
		h2 = sc.nextInt();
		sc.close();
		String strValue = "";
		
		if ((Arrays.binarySearch(group1, h1) >= 0 && Arrays.binarySearch(group1, h2) >= 0)
				|| (Arrays.binarySearch(group2, h1) >= 0 && Arrays.binarySearch(group2, h2) >= 0)
				|| (Arrays.binarySearch(group3, h1) >= 0 && Arrays.binarySearch(group3, h2) >= 0)) {
			strValue = "Yes";
		} else {
			strValue = "No";
		}

		System.out.println(strValue);
	}
}

Measured memory_bytes: 22740
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int p,q,r;
  cin >> p >> q >> r;
  int ans = min({p + q, q + r, r + p});
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long       ll;
typedef long double     ld;
typedef string          str;
#define all(x)			(x).begin(),(x).end()
#define Sort(x)			sort(all(x))
#define A               first
#define B               second
#define sep             ' '
#define endl            '\n'
#define fast_io         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const ll MAX1 = 2e5+7,
	     MOD = 1e9+7;

ll n, flag, x;

int main(){
	fast_io;
	cin >> n;
	if (n%2 == 1){
		cout << 0;
		return 0;
	}
	n /= 2;
	flag = 5;
	while (flag <= n){
		x += n/flag;
		flag *= 5;
	}
	cout << x;
    return 0;
}
/*                     now or never                         */


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

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

    int sum = 0;
    for(int i=0; i<N; i++) sum += L+i;
    int T = L+N-1;
    if(L <= 0 && 0 <= T){
        // nop
    }else if(0 < L){
        sum -= L;
    }else if(T < 0){
        sum -= T;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<iostream>
#include<algorithm>//next_permutation
#include<complex>
#include<math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep2(i, j, n) for (int i = j; i < (int)(n); i++)

int main() {
	int n, n1;
	cin >> n >> n1;
	if (n <= n1) {
		cout << "unsafe" << endl;
	}
	else {
		cout << "safe" << endl;
	}
}


Measured memory_bytes: 3632
import java.io.*;
import java.util.*;
 
public class Main{
   public static void main(String[] args) {
      MyScanner sc = new MyScanner();
      out = new PrintWriter(new BufferedOutputStream(System.out));
      
      //begin
      int n = sc.nextInt();
      int c = 0;
      for(int i = 0; i < n; i++)
      {
          int p = sc.nextInt();
          if(p != i + 1)
            c++;
      }
      if(c == 0 || c == 2)
        out.println("YES");
      else
        out.println("NO");
      //end
      out.close();
   }
 
   public static PrintWriter out;
      
   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;
 
      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }
 
      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
 
      int nextInt() {
          return Integer.parseInt(next());
      }
      long nextLong() {
          return Long.parseLong(next());
      }
      double nextDouble() {
          return Double.parseDouble(next());
      }
      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }
   }
}

Measured memory_bytes: 21204
s = input()
if 0 < int(s[:2]) <= 12 and 0 < int(s[2:]) <= 12:
    print('AMBIGUOUS')
elif 0 < int(s[:2]) <= 12:
    print('MMYY')
elif 0 < int(s[2:]) <= 12:
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3060
#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>;
using vv = vector<vector<ll>>;
template <class _t> inline bool chmax (_t& a,_t b){if(a<b){a=b;return true;}return false;}
template <class _t> inline bool chmin (_t& a,_t b){if(a>b){a=b;return true;}return false;}

const long long inf = 1ll << 60;
const long long mod = 1000000007;

int dx[4] = {1,0,-1,0};
int dy[4] = {0,-1,0,1};
int main() {
    ll x; cin >> x;
    ll a=100;
    int ans;
    for(int i=1;i<10000;i++){
	a += a/100;
	if(a>=x){
	    ans = i;
	    break;
	}
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
N = input()
suma = 0
for i in N:
    suma += int(i)
c = False
for i in range(9):
    if str(i) in N[1:]:
        c = True
if c:
    print(9*(len(N)-1) + (int(N[0])-1))
else:
    print(9*(len(N)-1) + int(N[0]))


Measured memory_bytes: 3060
import sys
inf=1000002
sys.setrecursionlimit(inf)
from collections import deque
h,w,k=map(int,input().split())
x1,y1,x2,y2=map(int,input().split())
c=[input() for i in range(h)]
dp=[[inf if c[i][j]=="." else -1 for j in range(w)] for i in range(h)]
now=deque([[x1-1,y1-1]])
dp[x1-1][y1-1]=0
def bfs(d):
    global dp,now
    l=len(now)
    dp_sub=deque()
    cand=set()
    for i in range(l):
        x,y=now.popleft()
        for j in range(1,min(k+1,w-y)):
            if dp[x][y+j]==inf:
                dp_sub+=[[x,y+j,d]]
                cand.add((x,y+j))
            else:
                break
        for j in range(1,min(k+1,y+1)):
            if dp[x][y-j]==inf:
                dp_sub+=[[x,y-j,d]]
                cand.add((x,y-j))
            else:
                break
        for j in range(1,min(k+1,h-x)):
            if dp[x+j][y]==inf:
                dp_sub+=[[x+j,y,d]]
                cand.add((x+j,y))
            else:
                break
        for j in range(1,min(k+1,x+1)):
            if dp[x-j][y]==inf:
                dp_sub+=[[x-j,y,d]]
                cand.add((x-j,y))
            else:
                break
    while dp_sub!=deque([]):
        e=dp_sub.popleft()
        dp[e[0]][e[1]]=e[2]
    for i in cand:
        now+=[i]
    if l!=0:bfs(d+1)
bfs(1)
print(dp[x2-1][y2-1] if dp[x2-1][y2-1]!=inf else -1)

Measured memory_bytes: 1016712
#include <float.h>
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}
int compw(const void *a, const void *b){return (*(int*)a>*(int*)b)-(*(int*)a<*(int*)b);}
int compr(const void *a, const void *b){return *(int*)b-*(int*)a;}

uint32_t nextpint(void){ char c=getchar(); while(c<'0'||'9'<c) c=getchar(); uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }

inline int max2(const int a, const int b){return a>b?a:b;}
inline int min2(const int a, const int b){return a>b?b:a;}
inline int dif2(const int a, const int b){return a>b?a-b:b-a;}

#define nextInt nextpint

long getGCD(long m, long n) {
	if(m < n) return getGCD(n, m);
	if(n == 0) return m;
	return getGCD(n, m % n);
}

long getLCM(long m, long n) {
	return m / getGCD(m, n) * n;
}

char S[100001];
char T[100001];
int main(void){
	int N = nextInt();
	int M = nextInt();
	nextstr(S);
	nextstr(T);
	if(S[0]!=T[0]){
		puts("-1");
		return 0;
	}
	long lcm = getLCM(N, M);
	int n = (int) (lcm / N);
	int m = (int) (lcm / M);
	for(long i=0; i<lcm; i=i+n){
		if(i%n==0 && i%m==0 && S[(int)(i/n)]!=T[(int)(i/m)]){
			puts("-1");
			return 0;
		}
	}
	printf("%ld\n", lcm);
}


Measured memory_bytes: 384
#include <math.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
int main() {
    string s;
    cin>> s;
    if (s == "SSS") cout << 0 << endl;
    else if (s=="SSR"||s=="SRS"||s=="RSS"||s=="RSR")
        cout << 1 << endl;
        else if(s=="RRS"||s=="SRR")
            cout << 2 << endl;
            else
                cout << 3 << endl;
    return 0;
}





Measured memory_bytes: 3592
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	int n, a, b;
	cin >> n >> a >> b;
	if(a % n == 0){
		cout << "OK" << endl;
	}
	else{
		int c = (a / n) * n + n;
		if(a <= c && c <= b){
			cout << "OK" << endl;
		}
		else{
			cout << "NG" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3628
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#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 REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
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...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    ll N;
    cin>>N;
    vector<ll> u(N-1),v(N-1);
    REP(i,N-1) cin>>u[i]>>v[i];
    ll ans=0;
    REP(i,N){
        ans+=((N-i)*(N+1-i))/2;
    }

    REP(i,N-1){
        ll a=min(u[i],v[i]);
        ll b=max(u[i],v[i]);
        ans-=(a)*(N-b+1);

    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6380
#include <stdio.h>

int main( void ){
	int a, b, i, temp;
	int counter;
	while( 1 ){
		scanf( "%d%d", &a, &b );
		if( a == 0 ){ break; }
		counter = 0;
		for( i = a; i <= b; i++ ){
			temp = i;
			while(! (temp % 2) ){
				temp /= 2;
			}
			while(! (temp % 3) ){
				temp /= 3;
			}
			while(! (temp % 5) ){
				temp /= 5;
			}
			if( temp == 1 ){ counter++; }
			
		}
		printf("%d\n", counter);
	}

	return 0;
}

Measured memory_bytes: 404
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
const int INF = 2e9;

ll dp[105][100005];

int main(){
    int n, we;
    vector<int> w, v;
    cin >> n >> we;
    w.resize(n); v.resize(n);
    for(int i=0; i<n; i++){
        cin >> w[i] >> v[i];
    }
    for(int i=0; i<=we; i++){
        if(i-w[0]>=0){
            dp[0][i] = v[0];
        }
        else{
            dp[0][i] = 0;
        }
    }
    for(int i=0; i<n-1; i++){
        for(int j=0; j<=we; j++){
            if(j-w[i+1]>=0){
                dp[i+1][j] = max(dp[i][j-w[i+1]]+v[i+1],dp[i][j]);
            }
            else{
                dp[i+1][j] = dp[i][j];
            }
        }
    }
    cout << dp[n-1][we] << endl;
}

Measured memory_bytes: 80128
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//const int mod = 1e9+7;
int x, y;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int main()
{
    quickread();
    cin >> x >> y;
    if(y % 2) {
        cout << "No" << endl;
        return 0;
    } else {
        if(y >= 2*x && y <= 4*x) {
            cout << "Yes" << endl;
            return 0;
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3688
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]
p = [0] * (N + 1)

for l, r in LR:
    p[l - 1] += 1
    p[r] -= 1
    
for i in range(N):
    p[i + 1] += p[i]
    
print(len([v for v in p if v == M]))

Measured memory_bytes: 31760
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
//ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
int main() {
	string s;
	int p = 0, c = 0;
	cin >> s;
	rep(i, 0, s.size()) {
		if (s.size() - i <= p) {
			if (s[i] == 'g')c++;
			p--;
		}
		else {
			if (s[i] == 'g')p++;
			else p--;
		}
	}
	printf("%d\n", c);
	return 0;
}


Measured memory_bytes: 512
var n,q,a,m;


function search(sum,i,m){
    if(i >= n){
        return sum == m;
    }

    return search(sum + a[i],i + 1,m) || search(sum,i + 1,m);
}

function Main(input){
    input = input.split("\n");
    n = parseInt(input[0],10);
    q = parseInt(input[2],10);
    input[1] = input[1].split(" ");
    input[3] = input[3].split(" ");
    a = new Array(n);m = new Array(q);
    for(var i = 0;i < n;i++)
        a[i] = parseInt(input[1][i],10);
    for(var i = 0;i < q;i++)
        m[i] = parseInt(input[3][i],10);
    for(var i = 0;i < q;i++){
        if(search(0,0,m[i]))
            console.log("yes");
        else
            console.log("no");
    }
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 15816
r = gets.split(' ').first.to_i
rc = []
r.times { rc << gets.split(' ').map(&:to_i) }
rc.map! { |c| c << c.reduce(:+) }
rc << rc.transpose.map { |c| c.reduce(:+) }
puts rc.map { |c| c.join(' ') }

Measured memory_bytes: 9048
//white cell
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
	int h,w,h_,w_;
	cin >> h >> w >> h_ >> w_;
	int all = h*w;
	all -= h_*w;
	all -= w_*(h-h_);
	cout << all << endl;
	return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

typedef long long ll;

void solve() {

}

#define MAX 200010
int used[MAX][2];

int main() {
  int N,K,C;
  string s;
  cin >> N >> K >> C;
  cin >> s;
  int rem = K;
  rep(i,N) {
    if( s[i] == 'o' ) {
      used[i][0] = 1;
      i += C;
      --rem;
      if( rem <= 0 ) {
	REP(j,i+1,N) {
	  if( s[j] == 'o' ) { return 0; }
	}
	break;
      }
    }
  }
  rem = K;
  for(int i=N-1;i>=0;--i) {
    if( s[i] == 'o' ) {
      used[i][1] = 1;
      i -= C;
      --rem;
      if( rem <= 0 ) {
	for(int j=i-1;j>=0;--j) if( s[j] == 'o' ) { return 0; }
	break;
      }
    }
  }
  rep(i,N) {
    if( used[i][0] == used[i][1] && used[i][0] ) {
      cout << i + 1 << endl;
    }
  }
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  
  int min_value = 1000000000;
  int max_value = 0;
  for (int i = 0; i < N; i++){
    min_value = min(min_value, A.at(i));
    max_value = max(max_value, A.at(i));
  }
  cout << max_value - min_value << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int [] a = new int [4];
        for (int i = 0 ; i < 4 ; i++) {
            a[i] = Character.getNumericValue(s.charAt(i));
        }
        if (a[0] + a[1] + a[2] + a[3] == 7) {
            System.out.println(a[0] + "+" + a[1] + "+" + a[2] + "+" + a[3] + "=7");
        } else if (a[0] - a[1] + a[2] + a[3] == 7){
            System.out.println(a[0] + "-" + a[1] + "+" + a[2] + "+" + a[3] + "=7");
        } else if (a[0] + a[1] - a[2] + a[3] == 7) {
            System.out.println(a[0] + "+" + a[1] + "-" + a[2] + "+" + a[3] + "=7");
        } else if (a[0] + a[1] + a[2] - a[3] == 7) {
            System.out.println(a[0] + "+" + a[1] + "+" + a[2] + "-" + a[3] + "=7");
        } else if (a[0] - a[1] - a[2] + a[3] == 7) {
            System.out.println(a[0] + "-" + a[1] + "-" + a[2] + "+" + a[3] + "=7");
        } else if (a[0] - a[1] + a[2] - a[3] == 7) {
            System.out.println(a[0] + "-" + a[1] + "+" + a[2] + "-" + a[3] + "=7");
        } else if (a[0] + a[1] - a[2] - a[3] == 7 ) {
            System.out.println(a[0] + "+" + a[1] + "-" + a[2] + "-" + a[3] + "=7");
        }else {
            System.out.println(a[0] + "-" + a[1] + "-" + a[2] + "-" + a[3] + "=7");
        }
    }


}

Measured memory_bytes: 20820
#include<bits/stdc++.h>
using namespace std;
int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int a[n+1];
    int b[n+1];
    a[0] = 0;
    b[0] = 0;
    for(int i = 1; i<=n; i++){
        cin >> a[i];
    }
    for(int i = 1; i<=n; i++){
        cin >> b[i];
    }
    int ans = 0;
    for(int zz = 0; zz<30; zz++){
        vector<pair<int,bool> > li1;
        vector<pair<int,bool> > li2;
        int z = (1<<zz);
        int now = 0;
        for(int i = 1; i<=n; i++){
            li1.push_back(make_pair(a[i]%z,(a[i]&z)!=0));
            li2.push_back(make_pair(b[i]%z,(b[i]&z)!=0));
            if(li1[i-1].second){
                now += n;
                now %= 2;
            }
            if(li2[i-1].second){
                now += n;
                now %= 2;
            }
        }
        sort(li1.begin(),li1.end());
        sort(li2.begin(),li2.end());
        int p1 = n;
        for(int i = 0; i<n; i++){
            while(p1 >0 && li2[i].first+li1[p1-1].first>=z){
                p1--;
            }
            now += (n-p1);
            now %= 2;
        }
        
        if(now%2==1){
            ans += z;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

long long sum[200001];

int main()
{
	int n;
	cin >> n;
	map<long long, int> m;
	m[0]++;
	long long ans = 0;
	for(int i = 1; i <= n; i++)
	{
		int a;
		cin >> a;
		sum[i] = sum[i - 1] + a;
		ans += m[sum[i]];
		m[sum[i]]++;
	}
	cout << ans << endl;

	return 0;
}


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

int main() {
    int n,d,i=0;
    cin>>n;
    int dAll[n];
    int ans=0;
    while(i<n){
        cin>>d;
        dAll[i]=d;
        for(int j=0; j<i;j++){
            ans+=d*dAll[j];
        }
        i++;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

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

int main(){
  int n, m;
  cin >> n >> m;
  vector<vector<int> > A(n);
  REP(i, m){
    int a, b;
    cin >> a >> b;
    --a, --b;
    A[a].push_back(b);
  }
  vector<vector<int> > B;
  vector<vector<int> > T;
  REP(i, n){
    queue<pair<int, int> > q;
    q.push(make_pair(i, 0));
    vector<int> v(n, -1);
    vector<int> t(n);
    while(!q.empty()){
      auto x = q.front();
      q.pop();
      for(auto y: A[x.first]){
        if(v[y] >= 0) continue;
        t[y] = x.first;
        v[y] = x.second + 1;
        q.push(make_pair(y, x.second + 1));
      }
    }
    B.push_back(v);
    T.push_back(t);
  }
  int r = 10000000;
  int mi, mj;
  REP(i, n){
    REP(j, n) if(i != j){
      if(B[i][j] > 0 && B[j][i] > 0){
        if(B[i][j] + B[j][i] < r){
          mi = i, mj = j;
          r = B[i][j] + B[j][i];
        }
      }
    }
  }
  if(r > n){
    cout << -1 << endl;
    return 0;
  }
  cout << r << endl;
  vector<int> ans(r);
  auto t = T[mi];
  int y = mj;
  REP(i, B[mi][mj]){
    ans[B[mi][mj] - i - 1] = y;
    y = t[y];
  }
  t = T[mj];
  y = mi;
  REP(i, B[mj][mi]){
    ans[B[mi][mj] + B[mj][mi] - i - 1] = y;
    y = t[y];
  }
  REP(i, r){
    cout << ans[i] + 1 << endl;
  }
  return 0;
}



Measured memory_bytes: 8320
n = gets.to_i
array = gets.split.map(&:to_i)
one_to_n = (1..n).to_a
count = 0
ans = 'NO'

(0..n-1).each do |i|
  if array[i] != one_to_n[i]
    count += 1
  end
end

if count <= 2
  ans = 'YES'
end

puts ans

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

int main() {
	bool isYes = 1;

	int n;
	cin >> n;

	vector<string> words;
	string w;
	cin >> w;
	words.push_back(w);
	char shiri = *(w.end() - 1);
	n--;

	for (int i = 0; i < n; i++) {
		cin >> w;
		if (w[0] == shiri
				&& find(words.begin(), words.end(), w) == words.end()) {
			words.push_back(w);
			shiri = *(w.end() - 1);
		} else {
			isYes = 0;
			break;
		}
	}

	cout << (isYes ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef std::vector<vector<int> > vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<vector<double> > vvd;
typedef vector<double> vd;

#define debugone(x) cerr << #x << " " << x << "\n"; cerr.flush();
#define debugtwo(x) cerr << #x << "-------------" << "\n";for(auto &it: x) cerr << it << " ";cerr << "\n"; cerr.flush();
#define debugthree(x_, i_, j_) cerr << #x_ << "------------" << "\n";cerr << "from " << i_ << " to " << j_ << "\n";for(ll k_=i_; k_<=j_; k_++) cerr << x_[k_] << " ";cerr << "\n"; cerr.flush();
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#define all(x) x.begin(), x.end()
#define INF 1000000009
#define MOD 1000000007

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

	int n, x, y;
	cin >> n >> x >> y;
	vi cnt(n);
	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			int dist = min(j - i, abs(i - x) + 1 + abs(j - y));
			cnt[dist]++;	
		}
	}
	for (int i = 1; i <= n - 1; i++) {
		cout << cnt[i] << "\n";
	}
}

Measured memory_bytes: 256
def solve():
    cnt = 0
    for x in range(K+1):
        for y in range(K+1):
            z = S - (x+y)
            if 0 <= z and z <= K:
                cnt += 1

    print(cnt)


if __name__=="__main__":
    K, S = list(map(int, input().split()))
    solve()


Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication67
{
    class Program
    {
        static void Main(string[] args)
        {
            while(true)
            {
            int a = int.Parse(Console.ReadLine());
            if (a == 0)
                break;
            string c="";
            for (int b = 0; b < a; b++)
            {
                int[] d = Console.ReadLine().Split().Select(int.Parse).ToArray();
                if (d[0] == 100 || d[1] == 100 || d[2] == 100 || (d[0] + d[1])/ 2 > 89)
                    c += "A";
                else if ((d[0] + d[1] + d[2] )/ 3 > 79)
                    c += "A";
                else if ((d[0] + d[1] + d[2]) / 3 > 69)
                    c += "B";
                else if ((d[0] + d[1] + d[2]) / 3 > 49&&d[0]>79||d[1]>79)
                    c += "B";
                else c += "C";
               }
                for(int g=0;g<a;g++)
            Console.WriteLine(c[g]);
            }

        }
    }
}

Measured memory_bytes: 9340
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

A, B = nl()

if A == B:
    print('Draw')
elif A == 1:
    print('Alice')
elif B == 1:
    print('Bob')
elif A > B:
    print('Alice')
else:
    print('Bob')


Measured memory_bytes: 2940
#include<stdio.h>
int main(){
int a[101],n,i,j,b,c=0;
while(1){
scanf("%d\n",&n);
if(n==0){
break;
}
for(i=0;i<n;i++){
scanf("%d\n",&a[i]);
}
for(i=0;i<n;i++){
for(j=n-1;j>i;j--){
if(a[j-1]>a[j]){
b=a[j-1];
a[j-1]=a[j];
a[j]=b;
c++;
}
}
}
printf("%d\n",c);
c=0;
}
return 0;
}



Measured memory_bytes: 2044
#include<stdio.h>
int prime[1000000];
int main(){
	prime[0]=-1;
	prime[1]=-1;
	for(int i=2;i<1000000;i++){
		if(prime[i]==0){
			prime[i]=1;
			for(int j=i*2;j<1000000;j+=i)prime[j]=-1;
		}
	}
	int now;
	while(~scanf("%d",&now)){
		int ans=0;
		for(int i=1;i<now+1;i++)if(prime[i]==1)ans++;
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>

using namespace std;

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

int main(){
  int N;
  cin>>N;
  int ans[N]={0};
  int prime[10000]={0};
  int t=0;
  for (int i=2;i<=55555;i++) if (isPrime(i) && i%10==1) prime[t++]=i;
  for (int i=0;i<N;i++) cout<<prime[i]<<' ';
  return 0;
}


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

int main()
{

        string s;
        cin >> s;
        int len = s.length();
        int num = 200 / len;
        string S;
        for (int i = 0; i < num; ++i) {
                S += s;
        }
        string a;
        cin >> a;
        if (S.find(a) != std::string::npos) {
                cout << "Yes" << endl;
        }
        else {
                cout << "No" << endl;
        }

}



Measured memory_bytes: 3212
#include <iostream>
#include <math.h>
#include <iomanip>

using namespace std;

int main() {
	double n,a[1000],sum,sig;
    while(1){
    	sum = 0;
    	sig = 0;
    	cin >> n;
    	if(n == 0) break;
    	for(int i = 0; i < n ; i++){
    		cin >> a[i];
        	sum += a[i];
    	}
    	for(int i = 0; i < n ; i++){
        	sig += pow(a[i]-sum / n,2);
    	}
    	 cout << fixed << setprecision(6)<< sqrt(sig/n) << endl;
    }
    return 0;
}

Measured memory_bytes: 3208
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int left = sc.nextInt() + sc.nextInt();
        int right = sc.nextInt() + sc.nextInt();
        if(left > right) {
            System.out.print("Left");
        } else if (left == right) {
            System.out.print("Balanced");
        } else {
            System.out.print("Right");
        }
    }
}


Measured memory_bytes: 21332
// ConsoleApplication21.cpp: 定义控制台应用程序的入口点。
//

#include<stdio.h>
int main()
{
	int a, b;
	int k;
	int x[100];
	int y[100];
	int i;
	int j;

	scanf("%d%d%d",&a,&b,&k);
	if (k >= b - a)
	{
		for (i = a; i <= b; i++)
			printf("%d\n",i);
		return 0;
	}
		
	for (i = 0; i < k; i++)
	{
		x[i] = a + i;
	}
	for (j = 0; j < k; j++)
	{
		y[j] = b-j;
	}
	j--;
	for (i = 0; i < k; i++)
	{
		printf("%d\n",x[i]);
	}
	while (j >= 0)
	{
		if (y[j] > x[i - 1])
			printf("%d\n", y[j]);
		    j--;
	}
   
    return 0;
}



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

import numpy as np

N = int(readline())
P = np.array(read().split(),np.int32)

Q = np.minimum.accumulate(P)

answer = np.count_nonzero(P <= Q)

print(answer)

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

int main() {
  char alpha;
  cin >> alpha;
  if (alpha-'a' < 26 && alpha-'a'>=0)
    cout << 'a' << endl;
  else
    cout << 'A' << endl;
  return 0;
}

Measured memory_bytes: 3632
number,a,b=input().rstrip().split()
a=int(a)
b=int(b)
answer=0
for i in range(1,int(number)+1):
    x=str(i)
    y=0
    for j in range(len(x)):
        y+=int(x[j])
    if a<=y and y<=b:
        answer+=i
        #print(x+'!')
print(answer)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
set<Int> ss;
Int check(char c){
  if(isdigit(c)) return true;
  if(c=='!') return true;
  return false;
}
Int calc(string s){
  Int n=s.size(); 
  Int neg=s[0]=='!';
  return (neg?-1:1)*stoll(s.substr(neg,n-neg));
}
string conv(Int x){
  if(x<0) return "!"+to_string(-x);
  return to_string(x);
}
void dfs(string s){
  // cout<<":::::"<<s<<endl;
  Int n=s.size(); 
  {    
    Int flg=1;
    for(Int k=0;k<n;k++)
      flg&=check(s[k]);
    if(flg){
      ss.emplace(calc(s));
      return;
    }
  }
  Int op=0,num=0;
  for(Int i=0;i<n;i++){
    if(s[i]=='(') op++;
    if(s[i]==')') op--;
    chmax(num,op);
    if(s[i]!='(') continue;
    Int j=i;
    while(s[j]!=')') j++;
    Int flg=1;
    for(Int k=i+1;k<j;k++)
      flg&=check(s[k]);
    if(flg){
      string t=s.substr(0,i)+s.substr(i+1,j-(i+1))+s.substr(j+1,n-(j+1));
      dfs(t);
      return;
    }
  }
  for(Int i=0;i<n;i++){
    if(s[i]=='(') op++;
    if(s[i]==')') op--;
    if(op!=num) continue;
    if(s[i]=='(') continue;
    if(s[i]==')') continue;
    if(check(s[i])) continue;
    
    Int j=i-1,k=i+1;
    while(j-1>=0&&check(s[j-1])) j--;
    while(k-1< n&&check(s[k+1])) k++;
    // [j, i), (i, k]
    string a=s.substr(j,i-j);
    string b=s.substr(i+1,k-i);
    Int x=calc(a),y=calc(b);

    string p=s.substr(0,j);
    string q=s.substr(k+1,n-(k+1));
    //cout<<s<<endl;
    //cout<<p<<" "<<x<<" "<<s[i]<<" "<<y<<" "<<q<<endl;
    if(s[i]=='+'){
      dfs(p+conv(x+y)+q);
    }
    if(s[i]=='-'){     
      dfs(p+conv(x-y)+q);
    }
    if(s[i]=='*'){
      dfs(p+conv(x*y)+q);      
    }
    if(s[i]=='/'&&y!=0){
      dfs(p+conv(x/y)+q);      
    }    
  }  
}
signed main(){
  string s;
  while(cin>>s,s!="#"){
    ss.clear();
    dfs(s);
    cout<<ss.size()<<endl;
  }
  return 0;
}



Measured memory_bytes: 3176
# 解説AC
N,K = map(int, input().split())
A = [int(i) for i in input().split()]

# 累積和
S1 = [0] * (N + 1)
# 正のみの累積和
S2 = [0] * (N + 1)
for i in range(N):
    S1[i+1] = S1[i] + A[i]
    S2[i+1] = S2[i] + (A[i] if A[i] >= 0 else 0)

ans = -float("inf")
for i in range(N - K + 1):
    left, right = i, i + K
    
    tmp = S2[left] - S2[0] # 左側
    tmp += max(0, S1[right] - S1[left]) # 連続部分列
    tmp += S2[N] - S2[right] # 右側

    ans = max(ans, tmp)

print(ans)

Measured memory_bytes: 16832