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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int > vi;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
 
#define ALL(x) (x).begin(), (x).end()
#define RESET(x) memset((x), 0, sizeof (x))
#define FOR(i, b, e) for ( int i = (b); i < (e); ++i)
#define RE(i, n) FOR(i, 0, (n))
#define FOREACH(i, x, y) for ( int i = (x); i <= (y); ++i)
#define two(X) (1<<(X))//NOTES:two(
#define contain(S,X) (((S)&two(X))!=0)//NOTES:contain(
#define chkmin(X, Y) (X) = min((X), (Y))
#define chkmax(X, Y) (X) = max((X), (Y))
#define sqr(X) ((X) * (X))
 
const ll maxn = (ll) 5e5 + 100;
const ll maxm = (ll) 1e6;
const int LOGN = 22;
const ll INF = 1e15+ 10;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = 1e-12;



int main() {
#ifndef ONLINE_JUDGE
  //  freopen("in.txt", "r", stdin);
#endif

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  
    int a, b, c, d;
    while (cin >> a >> b >> c >> d) {
        if (abs(a - c) <= d || abs(a - b) <= d && abs(b - c) <= d) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
   
    return 0;
}

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

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

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

void solve() {
    int K,S;
    cin >> K >> S;
    int ans = 0;
    REP(X,K+1) REP(Y,K+1) {
            int Z = S - X - Y;
            if(0 <= Z && Z <= K) ans++;
        }
    cout << ans << endl;
}

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

Measured memory_bytes: 3588
n = int(input())
a = list(map(int,input().split()))
maxA = max(a)
now = 0
a.sort()
ans = 0
for i in range(n-1):
    now += a[i]
    if a[i+1] <= now*2:
        ans += 1
    else:
        ans = 0

ans += 1
print(ans)

Measured memory_bytes: 14320
import sys

input = sys.stdin.readline

def main():
    N = int(input())
    
    ans = 0
    
    for a in list(map(int, input().split())):
        while not a % 2:
            ans += 1
            a //= 2
    print(ans)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 4084
#include<bits/stdc++.h>
using namespace std;
string n;int k;bool ok[20];
int test(int v){
	while (ok[v]) v++;
	return v;
}
int main()
{
	cin>>n>>k;
	for (int i=1;i<=k;i++){
		int x;
		cin>>x;
		ok[x]=1;
	}
	int Min=0;
	while (ok[Min]) Min++;
	for (int i=0;i<n.size();i++){
		int w=n[i]-'0',tp=test(w);
		if (tp==10){
			for (int i=1;i<=9;i++)
				if (!ok[i]){printf("%d",i);break;}
			for (int i=0;i<n.size();i++) printf("%d",Min);
			return 0;
		}
		if (tp>w){
			for (int j=0;j<i;j++) putchar(n[j]);
			printf("%d",tp);
			for (int j=i+1;j<n.size();j++) printf("%d",Min);
			return 0;
		}
	}
	cout<<n<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <limits.h>
#include <string>
using namespace std;

int main(void){
    int k, n, l[55], max = 0, maxnum, ans = 0;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> l[i];
    for (int i = 1; i <= k; i++) {
        for (int j = 1; j <= n; j++) {
            if (max < l[j]) {
                max = l[j];
                maxnum = j;
            }
        }
      	ans += max;
        l[maxnum] = 0;
        max = 0;
    }
    cout << ans;
    return 0;
}



Measured memory_bytes: 256
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]

fl = False
for i in range(n-m+1):
    if b[0] in a[i]:
        tmp = a[i].find(b[0])
        if m == 1:
            fl = True
        for j in range(1,m):
            if a[i+j][tmp:tmp+m] != b[j]:
                fl = False
                break
            fl = True
    if fl:
        break
if fl:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
N = int(input())
L = [[int(a) for a in input().split()] for _ in range(N)]

L = [[0, 0, 0]] + L
ans = "Yes"
for i in range(N):
    t = L[i+1][0]-L[i][0]
    l = abs(L[i+1][1]-L[i][1]) + abs(L[i+1][2]-L[i][2])
    if t < l or (t-l)%2 == 1:
        ans = "No"
        break
        
print(ans)

Measured memory_bytes: 21924
from sys import stdin
from fractions import gcd
A, B, C, D = [int(_) for _ in stdin.readline().rstrip().split()]
def solve(n, c, d):
    lcm_CD = C * D // gcd(C, D)
    return n - n//c - n//d + n//lcm_CD
print(solve(B,C,D)-solve(A-1,C,D))

Measured memory_bytes: 5048
m,k = map(int, input().split())

if k >= 2**m:
    print(-1)

elif m == 1:
    if k == 0:
        print(0, 0, 1, 1)

    else:
        print(-1)

else:
    a = [i for i in range(2**m) if i != k]
    ans = [k] + a + [k] + a[::-1]
    print(*ans)

Measured memory_bytes: 16912
import std.stdio;
import std.array;
import std.conv;
void main() {
  string[] input = split(readln());
  int a=to!int(input[0]);
  int b=to!int(input[1]);
  if((a*b)%2==0) {
    writeln("Even");
  }else {
    writeln("Odd");
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <bitset>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, K,x,result = 0;
    cin >> N;
    cin >> K;

    REP(i, N){
        cin >> x;
        result += min(x * 2, (K - x) * 2);
    }
    cout << result;
    return 0;
}

Measured memory_bytes: 256
import sys
if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline

alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

N = int(input())
S = input().rstrip()

ans = []
for s in S:
	if alphabet.find(s) > (25-N):
		ans.append(alphabet[alphabet.find(s)-(26-N)])
	else:
		ans.append(alphabet[alphabet.find(s)+N])

print(''.join(ans))

Measured memory_bytes: 3064
n = int(input())
s = input()
t = input()
cnt = [0]

for i in range(n):
        #print(t[0:n-i])
        #print(s[i:])
        if t[0:n-i] == s[i:]:
            cnt.append(len(s[i:]))
print(2 * n - max(cnt))

Measured memory_bytes: 3060
n = int(input())
list = [0]*120
for i in range(n):
    a,b,c,d = map(int,input().split())
    list[(a-1)*30+(b-1)*10+c-1] += int(d)
for j in range(120):
    print(" {}".format(list[j]),end="")
    if j % 10 == 9:
        print()
    if j % 30 == 29 and j < 90:
        print("#"*20)


Measured memory_bytes: 5616
List1 = [1, 3, 5, 7, 8, 10, 12]
List2 = [4, 6, 9, 11]
List3 = [2]
x, y = map(int, input().split())
if (x in List1 and y in List1) or (x in List2 and y in List2) or (x in List3 and y in List3):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		while(true){
			int n = stdIn.nextInt();
			if(n==0){
				return;
			}
			int cnt = 0;
			for(int i=1;i<=n/2;i++){
				int s = 0;
				for(int j=i;;j++){
					s += j;
					if(s==n){
						cnt++;
					}
					else if(s>n){
						break;
					}
				}
			}
			System.out.println(cnt);
		}
	}
}

Measured memory_bytes: 12000
MOD = 998244353
fac = [1] * (3 * 10 ** 5)
for i in range(len(fac) - 1):
    fac[i + 1] = fac[i] * (i + 1) % MOD


def comb(n, k):
    return fac[n] * pow(fac[n - k], MOD - 2, MOD) * pow(fac[k], MOD - 2, MOD) % MOD


n, m, k = map(int, input().split())
ans = 0
for a in range(n, n - k - 1, -1):
    ans += m * pow(m - 1, a - 1, MOD) * comb(n - 1, a - 1) % MOD
print(ans % MOD)


Measured memory_bytes: 73528
#include<iostream>
#include<string>

using namespace std;

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int in, out;

	if (a < c)in = c;
	else in = a;

	if (b < d)out = b;
	else out = d;
	cout << ((out - in > 0) ? out - in : 0) << endl;
}

Measured memory_bytes: 256
fac = []


def init():
    fac.append(1)
    for i in range(1, 2003):
        fac.append(fac[i - 1] * i)


def c(a, b):
    return fac[a] // fac[b] // fac[a - b]


init()
data = input().split(" ")
n = int(data[0])
b = int(data[1])
r = n - b
for i in range(1, b+1):
    print(int(c(b-1, i-1) * c(r+1, i) % int(1e9 + 7)))


Measured memory_bytes: 5748
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>

const long INF = (1l << 30);
const long LINF = (1l << 60);

long n, a, b;

int main(){
    scanf("%ld%ld%ld", &n, &a, &b);
    printf("%ld\n", std::min(a*n, b));

}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
int vis[15];
int main()
{
    int N,k,ans=10000;
    int x;
    cin >> N >> k;
    memset(vis,0,sizeof(vis));
    for(int i=1;i<=k;i++)
    {
        cin >> x;
        vis[x]=1;
    }
    int flag = 0;
    for(int i=N;;i++)
    {
        int n=i;
//        cout << i << "*" << endl;
        while(n)
        {
            if(vis[n%10])
            {
                flag=1;
                break;
            }
            else flag=0;
            n/=10;
//            cout << n << endl;
        }
        if(!flag)
        {
            cout << i << endl;
            break;
        }
    }
    return 0;
}

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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String[] data = br.readLine().split(" ");
    int n = Integer.parseInt(data[0]);
    int x = Integer.parseInt(data[1]);
    int y = Integer.parseInt(data[2]);
    int[][] distArray = new int[n][n];
    Route route = new Route(n);
    route.shortcut(x, y);
    for (int i=0; i<n; i++){
      distArray[i] = route.calcDist(i);
    }
    int[] result = new int[n];
    for (int i=0; i<n; i++){
      for (int j=0; j<n; j++){
        result[distArray[i][j]]++;
      }
    }
    StringBuilder s = new StringBuilder();
    for (int i=1; i<result.length; i++){
      result[i]/=2;
      s.append(result[i]);
      s.append("\n");
    }
    System.out.println(s);
  }
}

class Route{
  List<int[]> nodes;
  Route(int size){
    nodes = new ArrayList<>();
    for (int i=0; i<size; i++){
      if (i==0){
        nodes.add(new int[]{i+1});
      } else if (i==size-1){
        nodes.add(new int[]{i-1});
      } else {
        nodes.add(new int[]{i-1, i+1});
      }
    }
  }
  void shortcut(int idx1, int idx2){
    int[] a = nodes.get(idx1-1);
    int[] b = nodes.get(idx2-1);
    int[] newa = new int[a.length+1];
    int[] newb = new int[b.length+1];
    System.arraycopy(a, 0, newa, 0, a.length);
    System.arraycopy(b, 0, newb, 0, b.length);
    newa[a.length] = idx2-1;
    newb[b.length] = idx1-1;
    nodes.set(idx1-1, newa);
    nodes.set(idx2-1, newb);
  }
  int[] calcDist(int startIdx){
    int[] result = new int[nodes.size()];
    Arrays.fill(result, nodes.size());
    result[startIdx] = 0;
    Map<Integer, int[]> nextNode = new HashMap<>();
    nextNode.put(startIdx, nodes.get(startIdx));
    for (int i=0; !nextNode.isEmpty(); i++){
      Map<Integer, int[]> next = new HashMap<>();
      for (Map.Entry<Integer, int[]> entry : nextNode.entrySet()){
        for (int node : entry.getValue()){
          if (i + 1 < result[node]) {
            next.put(node, nodes.get(node));
            result[node] = i + 1;
          }
        }
        nextNode = next;
      }
    }
    return result;
  }
}

Measured memory_bytes: 263260
/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */
 
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define pf push_front
#define mp make_pair
#define F first
#define S second
#define all(x)     x.begin(),x.end()
#define tc   int tt; scf(tt); while(tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll mod =1e9+7;
const int N = 1e6+7;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)


int main() 
{ 
    ll a,b,c,d;
    lscf(a),lscf(b),lscf(c),lscf(d);  

    ll x=a*c,y=b*d,w=a*d,z=b*c;
    w=max(w,z);
    x=max(x,y);


    lprin(max(x,w));


        //printf("\n");     
      
  
}

Measured memory_bytes: 3828
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main()
{
    string s;
    cin >> s;

    for (int i = 0; i < s.size()-1; ++i) {
        if (s[i] == s[i+1]) {
            cout << "Bad" << endl;
            return 0;
        }
    }

    cout << "Good" << endl;

    return 0;
}


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

typedef long long ll;

int N;
vector<ll> T;

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

int main(void) {
	cin >> N;

	T.resize(N);
	for (int i = 0; i < N; ++i)
		cin >> T[i];

	ll lcm = T[0];
	for (int i = 1; i < N; ++i)
		lcm = lcm / gcd(lcm, T[i]) * T[i];

	cout << lcm << '\n';
	return 0;
}


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

typedef pair<int, int> pii;
const int MAXN = 2e5 + 10;
const int INF = 1e9;

int n;
int B[MAXN];
pii qs[MAXN];

int miseg[MAXN * 4], K;

void update(int i, int v) {
	i += K - 1;
	miseg[i] = v;
	i >>= 1;
	while (i > 0) {
		miseg[i] = min(miseg[2 * i], miseg[2 * i + 1]);
		i >>= 1;
	}
}

int query(int l, int r, int st, int ed, int idx) {
	if (r<st || l>ed) return INF;
	if (st <= l && r <= ed) return miseg[idx];

	int mid = (r + l) / 2;
	int lret = query(l, mid, st, ed, idx * 2);
	int rret = query(mid + 1, r, st, ed, idx * 2 + 1);
	return min(lret, rret);
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", &B[i]);

	int zcnt=0;
	for (int i = 1; i <= n; i++) {
		if(B[i]==0) zcnt++;
	}

	int q;
	scanf("%d", &q);
	for (int i = 0; i < q; i++) {
		int l, r;
		scanf("%d %d", &l, &r);
		qs[i] = { l, r };
	}
	sort(qs, qs + q);

	K = 1;
	while (K <= n) K <<= 1;
	for (int i = 2 * K - 1; i > 0; i--)
		miseg[i] = INF;

	int li = 1;
	int dis = 0;
	for (int i = 0; i < q; i++) {
		int l = qs[i].first, r = qs[i].second;
		while (li < l) {
			dis = min(dis + (B[li] == 1 ? 1 : -1), query(1, K, li, li, 1));
			// printf("idx:%d, dis:%d\n", li, dis);
			li++;
		}

		int mi = min(dis, query(1, K, l, r, 1));
		update(r, mi);
	}

	while (li <= n) {
		dis = min(dis + (B[li] == 1 ? 1 : -1), query(1, K, li, li, 1));
		// printf("idx:%d, dis:%d\n", li, dis);
		li++;
	}

	printf("%d", dis + zcnt);
	return 0;
}

Measured memory_bytes: 5632
N = int(input())
a = [int(i) for i in input().split()]
count = 0
for i in range(N):
    while a[i] % 2 == 0:
        while a[i] % 65536 == 0:
            count += 16
            a[i] /= 65536
        else:
            if a[i] % 256 == 0:
                count += 8
                a[i] /= 256
            elif a[i] % 16 == 0:
                count += 4
                a[i] /= 16
            elif a[i] % 4 == 0:
                count += 2
                a[i] /= 4
            elif a[i] % 2 == 0:
                count += 1
                a[i] /= 2
print(count)

Measured memory_bytes: 4148
/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/+---test
6 3 4
3
1
3
2
---+/
/+---test
10 13 15
3
1
4
1
5
9
2
6
5
3
5
8
9
7
9
---+/

void main(string[] args) {
  long N, K, Q;
  readf(" %d %d %d ", &N, &K, &Q);

  auto score = new long[N];

  foreach (i; 0..Q) {
    const n = readln.chomp.to!long - 1;
    ++score[n];
  }

  foreach (ref s; score) {
    s = K - (Q - s);
  }

  score.map!(x => x > 0? "Yes": "No").each!writeln;
}


Measured memory_bytes: 4348
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct Node {
    int key;
    struct Node *right, *left, *parent;
};
typedef struct Node Node;

Node *root, *NIL;

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;
    
    z = (Node *)malloc(sizeof(Node));
    z->key   = k;
    z->left  = NIL;
    z->right = NIL;
    
    while(x != NIL) {
        y = x;
        if(z->key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }
    
    z->parent = y;
    if(y == NIL) {
        root = z;
    } else {
        if( z->key < y->key) {
            y->left = z;
        } else {
            y->right = z;
        }
    }
}

void inorder(Node *u) {
    if(u == NIL) return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
void preorder(Node *u) {
    if(u == NIL) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}

Node * find(Node *u, int k) {
    while(u != NIL && k != u->key) {
        if(k < u->key) u = u->left;
        else u = u->right;
    }
    return u;
}

int main(void) {
    int n, i, x;
    char com[16];
    scanf("%d",&n);
    
    for(i=0;i<n;i++) {
        scanf("%s",com);
        if(com[0] == 'f') {
            scanf("%d",&x);
            Node *t = find(root,x);
            if(t != NIL) printf("yes\n");
            else printf("no\n");
        } else if(!strcmp(com,"insert")) {
            scanf("%d",&x);
            insert(x);
        } else if(!strcmp(com,"print")) {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }

    return 0;
}


Measured memory_bytes: 20496
import sys
input = sys.stdin.readline
N, M = map(int, input().split())

s = [tuple(map(int, input().split())) for _ in range(N)]
s.sort(key = lambda x: -x[1])
table = [(-1, -1)] * (N + 1)
c = 0
for i in range(N):
  if table[s[i][0]] == (-1, -1):
    table[s[i][0]] = (i, s[i][1])
    c += 1

table.sort(key = lambda x: -x[1])
res = [0] * (min(c, M) + 1)
vis = set()
p = M
for i in range(M): res[0] += s[i][1]
for x in range(1, min(c, M) + 1):
  res[x] = res[x - 1] + pow(x, 2) - pow(x - 1, 2)
  if table[x - 1][0] >= M:
    res[x] += table[x - 1][1]
    p -= 1
    while p in vis:
      p -= 1
    res[x] -= s[p][1]
  vis.add(table[x - 1][0])
  #print(p)
print(max(res))


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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<ll> a(n), b(n);
	rep(i,n) cin >> a[i] >> b[i];
	ll ans = 0, cnt = 0;
	for(int i = n-1; i >= 0; i--){
		if((a[i]+cnt)%b[i] == 0) continue;
		ll dif = b[i] - ((a[i]+cnt)%b[i]);
		ans += dif;
		cnt += dif;
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    if(s[0] == s[1] && s[1] == s[2]){
        cout << "Yes" << endl;
    }else if(s[1] == s[2] && s[2] == s[3]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <fstream>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <assert.h>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 998244353LL 
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589
 
 
#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}
 
//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)
 
struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}
 
};
typedef vector<vector<Edge>> Graph;
typedef unsigned long long ull;

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

ll lcm(ll m, ll n)
{
	return m * n / gcd(m, n);
}
ll mod_pow(ll x, ll n) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = (res * x) % MODU;
		x = (x*x)%MODU;
		n >>= 1;
	}
	return res;
}
ll divmod(ll a, ll b) { // a/b(mod m)
								  // a/b (mod m)
								  // a*b^-1
								  // b^-1 * b = 1
								  // b^(m-1) = 1 
								  // b^(m-2) * b = 1
								  // b^-1 = b^(m-2)

								  // a/b = a * b^(m-2)

	return (a * mod_pow(b, MODU - 2)) % MODU;
}


ll fmemo[10000] = {};
ll factorial(ll n) {//階乗

	if (n > 0) {
    assert(n < 10000);
if(fmemo[n] != 0) return fmemo[n];
		return fmemo[n] = (n * factorial(n - 1))%MODU;
	}
	else {
		return 1;
	}
}

int main(){
  int k;
   cin >> k;
   ll sum = 0;

  rep(i,1,k + 1){
   
  rep(j,1,k + 1){
   
  rep(l,1,k + 1){
    sum += gcd(gcd(i,j),l);
  } 
  } 
  }
  cout << sum << endl;
  return 0;
} 

Measured memory_bytes: 3196
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<complex>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
#define M 310
#define N 620
ll h,w;
string s[N];
bool t[N][N];

ll cs[N][N];
void Init(){
    lol(i,N-1){
	cs[i][0]=0;
	lol(j,N-1)cs[i][j+1]=cs[i][j]+t[i][j];
    }
}
ll Sum(ll y,ll a,ll b){
    if(y<0||y>=N)return 0;
    return cs[y][b+1]-cs[y][a];
}
ll Solve(){
    lol(i,N)for(int j=i+1;j<N;j++)swap(t[i][j],t[j][i]);
    Init();//cout<<"%"<<endl;
    ll ans=0;
    lol(i,N-1){
	lol(a,N)for(int b=a+1;b<N-1;b++){
	    if(!(t[i][a]==1&&t[i][b]==1))continue;
	    ll d=b-a;
	    ans+=Sum(i-d,a,b);
	    ans+=Sum(i+d,a,b);
	}
    }
    return ans;
}


int main(){
    cin>>h>>w;
    lol(i,h)cin>>s[i];
    lol(i,N)lol(j,N)t[i][j]=0;
    lol(i,h)lol(j,w){
	if(s[i][j]=='.')continue;
	t[i-j+M][i+j]=1;
    }
    ll ans=Solve()+Solve();//cout<<ans<<endl;
    lol(i,N)lol(j,N){if(t[i][j]==0)continue;
	lol(k,N){
	    if(i==k)continue;
	    if(t[k][j]==0)continue;
	    ll d=abs(i-k);
	    if(j-d>=0)if(t[i][j-d]==1)ans--;
	    if(j+d<N)if(t[i][j+d]==1)ans--;
	}
    }
    cout<<ans<<endl;
    return 0;
}


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

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

    int ans =0;
    for(int i=1;i<=n;i++){
        int sum = 0;
        for(int j=1;j<=m;j++){
            int temp;
            cin >> temp;
            sum += temp*b[j];
           // cout << temp*b[j];
        }
        sum += c;
        if(sum > 0)ans++;
        //cout << sum << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int lo = max(a, c);
  int hi = min(b, d);
  cout << (lo <= hi ? hi - lo : 0) << endl;
}


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

int main() {
  int n,count;
  string s;
  char w=' ';
  cin >> n>>s;
  count=n;
  rep(i,n){
    if(w==s[i]) count--;
    w=s[i];
  }
  cout << count<<endl;
}

Measured memory_bytes: 3760
#include <iostream>

using namespace std;

int main(){
	
	int s[3];
	
	cin>>s[0]>>s[1]>>s[2];
	
	if(s[0]<s[1]&&s[1]<s[2])
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	
}

Measured memory_bytes: 1156
#include <iostream> 
#include <string>

using namespace std;
bool qwerty(char);

bool qwerty(char s){
	if(s == 'y'||s == 'u'||s == 'i'||s == 'o' || s == 'p' || s == 'h'||
		s == 'j'||s == 'k'||s == 'l'||s == 'n' || s == 'm'){
		return true;
	}else if(s == 'q'||s == 'w'||s == 'e'||s == 'r' || s == 't' || s == 'a'||
		s == 's'||s == 'd'||s == 'f'||s == 'g' || s == 'z'||
		s == 'x'||s == 'c'||s == 'v' || s == 'b'){
		return false;
	}
	return true;
}

int main(void){
	string s;
	bool fg,pre;
	int change = 0;

	getline(cin,s);
	
	while(s != "#")
	{
		pre = qwerty(s[0]);
		for(int i = 1;i < s.length();i++)
		{
			fg = qwerty(s[i]);
			if(pre != fg){
				change++;
			}
			pre = fg;
		}
		cout << change << endl;
		change = 0;
		getline(cin,s);
	}

	return 0;
}

Measured memory_bytes: 1176
//#pragma GCC optimize(2)
//Happy TLE and WA every day!
#include<bits/stdc++.h>
#define mp			make_pair
#define rep(i,n)	for(int i = 0; i < n; i++)
#define BINF		0x7fffffff
#define INF			0x3f3f3f3f
#define LINF		3223372036854775807
#define END(s)		{cout<<s; return 0;}
#define CON(s)		{cout<<s; continue;}
#define BRE(s)		{cout<<s; break;}
#define pb			push_back
#define int			long long
#define All(a)		a.begin(), a.end()  //with A in CAPITAL!!!
#define sz(a)		(int)a.size()
#define F			first
#define S			second
//#define usingFiles
using namespace std;

const int rp = 666666;
const bool debug = 1;

string s;
int cur = 0;
int sum = 0;
int n;

inline int Stoi(string ss){
	if(ss.size() == 1) return ss[0] - '0';
	return (ss[ss.size() - 1] - '0') + Stoi(ss.substr(0, ss.size() - 1)) * 10;
}

void dfs(int now, int pre){
	if(now == n){
		sum += (cur + Stoi(s.substr(pre, n - pre)));
		return ;
	}
	cur += Stoi(s.substr(pre, now - pre));
	dfs(now + 1, now);
	cur -= Stoi(s.substr(pre, now - pre));
	dfs(now + 1, pre);
}

signed main(){
	ios::sync_with_stdio(false);
	#ifdef usingFiles
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	cin >> s;
	n = s.size();
	dfs(1, 0);
	cout << sum << endl;
	return 0;
}

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

int main() {
    int x, y, temp;
    cin >> x >> y;
    while(!(x == 0 && y == 0)) {
        if (x > y) {
            temp = x;
            x = y;
            y = temp;
        }
        cout << x << ' ' << y << endl;
        cin >> x >> y;
    }
    return 0;
}


Measured memory_bytes: 3076
#include<stdio.h>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<utility>
#include<stack>
#include<algorithm>
#include<string>
#include<string.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;

int main(){
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  string s; cin >> s;
  s[0] = '2';
  s[1] = '0';
  s[2] = '1';
  s[3] = '8';
  cout << s << endl;
}

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

int main() {
    int A,B;
    cin >> A >> B;
    cout << 6-A-B << endl;
    return 0;
}


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

namespace abc167a
{
    class Program
    {
        static void Main(string[] args)
        {
            //==========================================================================================================================
            //1) input
            string s = Console.ReadLine();
            string t = Console.ReadLine();

            //==========================================================================================================================
            //2) output
            string output = "No";
            if (t.Substring(0, t.Length - 1) == s)
            {
                output = "Yes";
            }

            Console.WriteLine(output);
        }
    }
}


Measured memory_bytes: 25792
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
//#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;

/*bool isprime(int p) {
	if (p == 1) return false;
	for (int i = 2; i < p; i++) {
		if (p % i == 0) return false;
	}
	return true;
}*/
/*ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/
/*ll keta(ll n) {
	ll res = 0;
	while (n >= 1) {
		res += n % 10; n /= 10;
	}
	return res;
}*/
ll modpow(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= mod; }
		x = x * x % mod; y /= 2;
	}
	return res;
}
ll nCk(ll n, ll k) {
	ll a = 1, b = 1;
	for (int h = n - k + 1; h <= n; h++) { a *= h; a %= mod; }
	for (int h = 1; h <= k; h++) { b *= h; b %= mod; }
	return a * modpow(b, mod - 2) % mod;
}
//printf("%.10f\n", n);

signed main() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	
	string s, t;
	ll n, m, a = 0, b = 0, c = 0, cnt = 0, ans = 0;
	cin >> n;
	vector<ll> v, w;
	rep(i, n) {
		cin >> a >> b;
		v.push_back(a + b);
		w.push_back(a - b);
	}
	sort(all(v)); sort(all(w));
	cout << max(v[n - 1] - v[0], w[n - 1] - w[0]) << endl;
	return 0;
}

Measured memory_bytes: 6644
import std.stdio, std.string, std.array, std.conv;

void main() {
    int n = readln.chomp.to!int;
    int[] point = new int[2];
    foreach (i; 0 .. n) {
        string[] tmp = readln.chomp.split;
        if (tmp[0] == tmp[1]) {
            point[] += 1;
        } else if (tmp[0] < tmp[1]) {
            point[1] += 3;
        } else {
            point[0] += 3;
        }
    }
    writeln(point[0], " ", point[1]);
}


Measured memory_bytes: 2480
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

const static ll MOD = 1000000007;

ll solve(const vector<int>& A, const vector<int>& B){
  int N = A.size();
  int M = B.size();
  vector<int> cnt(N*M+10, 0);
  vector<int> sum(N*M+10, 0);
  vector<int> sum2(N*M+10, 0);
  vector<int> kakutei(N*M+10, 0);
  
  set<int> sA, sB;
  rep(i,N){
    sA.insert(A[i]);
  }
  rep(i,M){
    sB.insert(B[i]);
  }
  if(sA.size() != N || sB.size() != M) return 0;
  
  rep(i,N){
    rep(j,M){
      if(A[i] == B[j]){
        kakutei[A[i]] = 1;
      }else{
        int mn = min(A[i], B[j]);
        cnt[1]++;
        cnt[mn+1]--;
      }
    }
  }
  
  int base = 0;
  rep(i,cnt.size()){
    base += cnt[i];
    sum[i] = base;
  }

  rep(i,N){
    if(kakutei[A[i]] == 1) continue;
    int num = 0;
    rep(j,M){
      if(A[i] < B[j]) num++;
    }
    sum2[A[i]] = num;
  }
  rep(j,M){
    if(kakutei[B[j]] == 1) continue;
    int num = 0;
    rep(i,N){
      if(B[j] < A[i]) num++;
    }
    sum2[B[j]] = num;
  }

  ll ret = 1;
  base = 0;
  int already = 0;
  for(int i=N*M; i>0; i--){
    if(kakutei[i] == 0){
      if(sum[i] < base) return 0;
      if(already > sum[i]) return 0;
      //cout << i << "\t" << already << "\t" << sum[i] << "\t" << sum2[i] << endl;

      if(sum2[i] != 0){
        ret *= min(sum[i]-already, sum2[i]);
        ret %= MOD;
      }else{
        ret *= (sum[i] - already);
        ret %= MOD;
      }

      already++;
    }
    base = sum[i];
  }

  return ret;
}

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> A, B;
  rep(i,N){
    int a;
    cin >> a;
    A.push_back(a);
  }
  rep(i,M){
    int b;
    cin >> b;
    B.push_back(b);
  }

  cout << solve(A, B) << endl;
  
  return 0;
}


Measured memory_bytes: 16000
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int N, M;
	cin >> N >> M;
	vector<int> H(N);
	for (int i = 0; i < N; ++i) {
		cin >> H[i];
	}
	vector<vector<int> > G(N);
	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b; --a, --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		bool ok = true;
		for (int j : G[i]) {
			if (H[i] <= H[j]) {
				ok = false;
			}
		}
		if (ok) {
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  int N,AC=0,WA=0,TLE=0,RE=0;
  cin >> N;
  for(int i=0;i<N;i++){
    string S;
    cin >> S;
    if(S=="RE"){
      RE++;
    }
    else if(S=="WA"){
      WA++;
    }
    else if(S=="TLE"){
      TLE++;
    }
    else{
      AC++;
    }
  }
  cout << "AC x " << AC << endl;
  cout << "WA x " << WA << endl;
  cout << "TLE x " << TLE << endl;
  cout << "RE x " << RE << endl;
}

Measured memory_bytes: 3628
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        n: usize,
        p: [(f64, f64, chars); n],
    }
    let mut map = std::collections::BTreeMap::new();
    map.insert('R', 0);
    map.insert('U', 1);
    map.insert('L', 2);
    map.insert('D', 3);
    let mut p: Vec<_> = p.into_iter().map(|p| (p.0, p.1, *map.get(&p.2[0]).unwrap())).collect();
    let mut a = vec![];
    a.push(0f64);
    for _ in 0..4 {
        let inf = -100_000_000f64;
        let mut left = inf;
        let mut fix = inf;
        let mut right = inf;
        for &(x, _, k) in p.iter() {
            if k == 0 {
                right = right.max(x);
            } else if k == 2 {
                left = left.max(x);
            } else {
                fix = fix.max(x);
            }
        }
        for &v in [left - fix, fix - right, (left - right) * 0.5].iter() {
            if v > 0.0 {
                a.push(v);
            }
        }
        for p in p.iter_mut() {
            *p = (-p.1, p.0, (p.2 + 1) % 4);
        }
    }
    let mut ans = std::f64::MAX;
    let dir = [(1.0, 0.0), (0.0, 1.0), (-1.0, 0.0), (0.0, -1.0)];
    for a in a {
        let mut d = std::f64::MAX;
        let mut u = std::f64::MIN;
        let mut l = std::f64::MAX;
        let mut r = std::f64::MIN;
        for &(x, y, k) in p.iter() {
            d = d.min(y + a * dir[k].1);
            u = u.max(y + a * dir[k].1);
            l = l.min(x + a * dir[k].0);
            r = r.max(x + a * dir[k].0);
        }
        ans = ans.min((u - d) * (r - l));
    }
    println!("{:.10}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 16116
import sys
import copy
import string
import  math
from _bisect import *
from collections import *
from operator import itemgetter
from math import factorial
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

w, a, b = na()
if b <= a + w <= b + w or b <= a <= b + w:
    print(0)
else:
    print(min(abs(b - (a + w)), abs(a - (b + w))))

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

using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)

int main() {
    int n;
    cin >> n;
    vector<int> vec(n);
    rep(i, n) cin >> vec.at(i);
    sort(vec.begin(), vec.end());
    int center = (int)(vec.size() / 2);
    int ans = vec.at(center) - vec.at(center-1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3784
D, G = [int(item) for item in input().split()]

comp_bounas_list = [[int(item) for item in input().split()] for _ in range(D)]

comp_all = []

for i in range(2**D):
    temp = []
    for j in range(D):
        if ((i >> j) & 1) == 1:
            temp.append(1)
        else:
            temp.append(0)
    comp_all.append(temp)

# print(comp_bounas_list)
# print(comp_all)

full_num_list = [item[0] for item in comp_bounas_list]

each_comp_point = []
for i, item in enumerate(comp_bounas_list):
    each_comp_point.append((i+1)*100*item[0]+item[1])

# print(full_num_list)
# print(each_comp_point)


temp_point_list = []

for each_pattern in comp_all:
    temp_num = 0
    temp_point = 0
    for j, item in enumerate(each_pattern):
            if item:
                temp_num += full_num_list[j]
                temp_point += each_comp_point[j]

    temp_point_list.append([temp_num, temp_point, each_pattern]) 

# print(temp_point_list)

# overの物を解候補にリスト化する
over_list = [item for item in temp_point_list if item[1] >= G]

# print(over_list)
over_combo = min(over_list, key = lambda x:x[0])
# print(over_combo)

# underのものを解候補にリスト化する
under_combo = [item for item in temp_point_list if item[1] < G]

# print(over_combo)
# print(under_combo)


temp_res_list = []
is_search = True

for temp_combo in under_combo:
    temp_bit_list = temp_combo[2]
    temp_res_point = temp_combo[1]
    temp_res_num = temp_combo[0]
    # print(temp_combo)

    # print(temp_bit_list)
    for j, item in reversed(list(enumerate(temp_bit_list))):
        for _ in range(1, comp_bounas_list[j][0]):
            # print(temp_res_point)
            if item==0:
                temp_res_point += (j+1)*100
                temp_res_num += 1

            if temp_res_point >= G:
                temp_res_list.append([temp_res_num, temp_res_point])
                break

# print(temp_res_list)

if temp_res_list != []:
    res_candi = min(temp_res_list, key=lambda x:x[0])
else:
    res_candi = temp_point_list[-1]

if over_combo[0] <= res_candi[0]:
    print(over_combo[0])
else:
    print( res_candi[0])

Measured memory_bytes: 3516
import java.util.Scanner;

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

        int N = scanner.nextInt();
        int T = scanner.nextInt();

        int start = scanner.nextInt();
        int end = start + T;

        int acc = 0;

        if(N==1){
            System.out.println(T);
            return;
        }

        for(int i=0; i<N-1; i++){
            int startTmp = scanner.nextInt();
            int endTmp = startTmp + T;


            if(i==N-2) {
                if(end < startTmp){
                    acc += end - start;
                    acc += endTmp - startTmp;
                }else{
                    acc += endTmp - start;
                }
            } else if(end < startTmp){
                acc += end - start;
                start = startTmp;
                end = endTmp;
            }else{
                end = endTmp;
            }
        }

        System.out.println(acc);
    }
}


Measured memory_bytes: 60360
require 'matrix'
include Math

n = gets.to_i
r, t = gets.split.map(&:to_f)

nodes = (1..n).map { gets.split.map(&:to_i) }
edges = nodes.permutation(2).map(&:flatten)

g = (0..edges.size-1).map { {} }
(0..edges.size-1).to_a.permutation(2) do |i, j|
    x1, y1, x2, y2 = edges[i]
    x3, y3, x4, y4 = edges[j]
    next unless x2 == x3 && y2 == y3

    v1 = Vector[x2 - x1, y2 - y1]
    v2 = Vector[x4 - x3, y4 - y3]
    next if v1.inner_product(v2) / (v1.r * v2.r) < cos(PI * t / 180)

    g[i][j] = hypot(x4 - x3, y4 - y3)
end

h = {}
(0..edges.size-1).each do |i|
    e = edges[i]
    next unless e[0..1] == nodes[0]
    d = hypot(e[2] - e[0], e[3] - e[1])
    h[i] = d if d <= r
end

k = 0
until h.empty?
    k += 1
    h2 = Hash.new(Float::INFINITY)
    h.each do |i, d|
        next unless g[i]
        g[i].each do |j, c|
            h2[j] = d + c if d + c < r && d + c < h2[j]
        end
    end
    h = h2
end
p k

Measured memory_bytes: 90576
/*
        @uthor: Kashish Gilhotra
        user: CodeChef, CodeForces, HackerEarth, HackerRank, SPOJ: kashish001
*/

#include <bits/stdc++.h>
using namespace std;
  
#define int long long int 
typedef vector<int> vi;
typedef vector<pair<int, int>> vpi;
typedef vector<vi> vvi;
const int mod = 1e9 + 7; 

#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define debug(...) cerr << "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " 
#define EB emplace_back
#define ALL(v) v.begin(), v.end() 
#define size(v) (int)v.size() 
#define endl "\n"
#define UMO unordered_map
#define USO unordered_set
#define TC int t; cin >> t; while (t--) 

void Panda() {
    string s;
    cin >> s;
    int cnt = 0;
    int maxx = 0;
    for(int i = 0 ; i < 3; i++) {
      if(s[i] == 'R') cnt++;
      else maxx = max(cnt, maxx), cnt = 0;
    }
    maxx = max(maxx, cnt);
    cout << maxx << endl;
}
  
int32_t main() {
 
    FAST;

    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout); 
    
    Panda();

    return 0; 
} 


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

// 計算量 : O(n**2)
//   要素数が n で、1周期の頂点数が n の場合
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n), c(n);

  for (int i = 0; i < n; i++) { cin >> p.at(i); }
  for (int i = 0; i < n; i++) { cin >> c.at(i); }
  for (int i = 0; i < n; i++) { p.at(i)--; } // 0-indexed に変更

  ll ans = -1e18;
  for (int si = 0; si < n; si++) {
    int x = si;    // 開始位置
    vector<int> s; // 1周期の1つ1つのスコアを格納する
    ll total = 0;  // 1周期の合計のスコアを格納する

    // 周期を求めて vector s に詰める
    //
    // 入力例1の場合
    // x=0
    //   0 --> 1
    //   x=1 の値を加算
    // x=1
    //   1 --> 3
    //   x=3 の値を加算
    // x=3
    //   3 --> 0
    //   x=0 の値を加算
    //   x=si が true となるため、周期に入ったと判定しループを終了する
    //
    while (1) {
      x = p.at(x);
      s.push_back(c.at(x));
      total += c.at(x);

      // 周期に入ったら終了する
      if (x == si) { break; }
    }

    // 周期 s の中のどこで切るかを全探索する

    // 周期の頂点数
    int loop = s.size();
    // 累積和
    ll t = 0;

    // ### 周期の合計がプラスの場合
    //
    // 例
    //   k = 10
    //   p =  1  2  4 |  1  2  4 |  1  2  4 |  1
    //   c = +3 +4 -1 | +3 +4 -1 | +3 +4 -1 | +3
    //
    // i=0
    //   t = s[0] = 3
    //   now = t = 3
    //   周期の合計がプラスの場合
    //     e = (k-(i+1)) / loop = (10-(0+1)) / 3 = 9 / 3 = 3
    //     now = now + total + e = 3 + 6 * 3 = 21
    //   ans = max(-1e18, 21) = 21
    // i=1
    //   t = s[0] + s[1] = 3 + 4 = 7
    //   now = 7
    //   周期の合計がプラスの場合
    //     e = (k-(i+1)) / loop = (10-(1+1)) / 3 = 8 / 3 = 2
    //     now = now + total + e = 7 + 6 * 2 = 19
    // i=2
    //   t = s[0] + s[1] + s[2] = 3 + 4 - 1 = 6
    //   now = 6
    //   周期の合計がプラスの場合
    //     e = (k-(i+1)) / loop = (10-(2+1)) / 3 = 7 / 3 = 2
    //     now = now + total + e = 6 + 6 * 2 = 18
    //
    // si=0 の場合
    //   1コマ移動 + できるだけループ = 3 + (6*3) = 21
    //   2コマ移動 + できるだけループ = 7 + (6*2) = 19
    //   3コマ移動 + できるだけループ = 6 + (6*2) = 18
    //   --> これらより 21 が最大値となる
    // si=1 の場合
    //   1コマ移動 + できるだけループ = 4 + (6*3) = 22
    //   2コマ移動 + できるだけループ = 3 + (6*2) = 15
    //   3コマ移動 + できるだけループ = 6 + (6*2) = 18
    // si=2 の場合
    //   2 --> 4 --> 2 のループ
    //   省略
    // si=3 の場合
    //   1コマ移動 + できるだけループ = -1 + (6*3) = 17
    //   2コマ移動 + できるだけループ =  2 + (6*2) = 14
    //   3コマ移動 + できるだけループ =  6 + (6*2) = 18
    // si=4 の場合
    //   2 --> 4 --> 2 のループ
    //   省略
    //
    // 全スタート地点について「1回〜1周期の頂点数の回」だけ移動するパターンを全探索する。
    // 移動後、できるだけ周期でスコアを積み上げる。
    //
    //
    // ### 周期の合計がマイナスの場合
    //
    // ループするほどスコアが下がるので、ループしない。
    // 全スタート地点について、1回〜周期の頂点数の数だけ移動するパターンについて、
    // 合計値を全探索する。
    //
    for (int i = 0; i < loop; i++) {
      t += s.at(i);

      if (i+1 > k) { break; }

      ll now = t;
      // 周期の合計がプラスになる場合
      if (total > 0) {
        // 最大移動回数から i+1 を引く
        // +1 しているのは、i が 0-indexed のため
        //   0番目の頂点に移動した際に、移動回数が1となる
        //   1番目の頂点に移動した際に、移動回数が2となる
        // 残りの移動回数をループ回数で割り、可能な限りループを行い、スコアを最大化させる
        ll e = (k-(i+1)) / loop;
        now += total * e;
      }
      ans = max(ans, now);
    }
  }

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


Measured memory_bytes: 3720