akhauriyash/Code-Regression huggingface dataset:
from functools import reduce
from collections import deque
import math

def bfs(i,E,N):
    q = deque()
    q.append(i)
    d = [-1]*N
    d[i] = 0
    while q:
        next_node = q.popleft()
        for e in E[next_node]:
            if d[e[0]] == -1:
                d[e[0]] = d[next_node] + e[1]                
                q.append(e[0])
    return d
def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input())
    a = []
    b = []
    c = []
    for i in range(N-1):
        s1,s2,s3 = list(int(_) for _ in input().split())
        a.append(s1-1)
        b.append(s2-1)
        c.append(s3)
    Q,K = list(int(_) for _ in input().split())
    x = []
    y = []
    for i in range(Q):
        s1,s2 = list(int(_) for _ in input().split())
        x.append(s1-1)
        y.append(s2-1)
    
    e = [[] for i in range(N)]
    for i in range(N-1):
        e[a[i]].append((b[i],c[i]))
        e[b[i]].append((a[i],c[i]))

    d = bfs(K-1,e,N)

    for i in range(Q):        
        print(d[x[i]]+d[y[i]])
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 54168
H, W = map(int, input().split())
Map = ['' for i in range(H)]
default = 0
for i in range(H):
  Map[i] = input()
  default += Map[i].count('#')
D = [[H * W + 1 for j in range(W)] for i in range(H)]
D[0][0] = 0
Q = [[0, 0]]
while Q:
  x, y = Q[0]
  Q = Q[1:]
  if x > 0 and Map[x - 1][y] == '.' and D[x][y] + 1 < D[x - 1][y]:
    D[x - 1][y] = D[x][y] + 1
    Q += [[x - 1, y]]
  if x < H - 1 and Map[x + 1][y] == '.' and D[x][y] + 1 < D[x + 1][y]:
    D[x + 1][y] = D[x][y] + 1
    Q += [[x + 1, y]]
  if y > 0 and Map[x][y - 1] == '.' and D[x][y] + 1 < D[x][y - 1]:
    D[x][y - 1] = D[x][y] + 1
    Q += [[x, y - 1]]
  if y < W - 1 and Map[x][y + 1] == '.' and D[x][y] + 1 < D[x][y + 1]:
    D[x][y + 1] = D[x][y] + 1
    Q += [[x, y + 1]]
if D[H - 1][W - 1] < H * W - 1:
  print(H * W - D[H - 1][W - 1] - default - 1)
else:
  print(-1)

Measured memory_bytes: 3188
import java.text.*;
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        Stringer[][] field = new Stringer[3][8];
        for(int i = 0; i < 3; ++i)
        {
            for(int j = 0; j < 8; ++j)
            {
                field[i][j] = new Stringer(sc.nextInt(), sc.nextDouble());
            }
        }

        for(Stringer[] track : field)
        {
            Arrays.sort(track);
            System.out.println(track[0].toString());
            System.out.println(track[1].toString());
        }

        Stringer[] allRank = new Stringer[6];
        for(int i = 0; i < 3; ++i)
        {
            allRank[i * 2]     = field[i][2];
            allRank[i * 2 + 1] = field[i][3];
        }

        Arrays.sort(allRank);
        System.out.println(allRank[0]);
        System.out.println(allRank[1]);
    }
}

final class Stringer implements Comparable<Stringer>
{
    Stringer(final int i, final Double t)
    {
        this.id = i;
        this.time = t;
    }

    @Override
    public int compareTo(final Stringer s)
    {
        return this.time.compareTo(s.time);
    }

    @Override
    public String toString()
    {
        return String.valueOf(id) + " " + String.valueOf(time);
    }

    private final int id;
    private final Double time;
}

Measured memory_bytes: 20108
//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector") 
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
/*#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
#define ll long long
#define ull unsigned long long
#define int long long
#define ld long double
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define repb(i, r, l) for (int i = r; i >= l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) {cout << a; exit(0);}

using namespace std;

mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
                                                                    
typedef pair < int , int > pii ;
typedef pair < long long  , long long > pll ;

const int N = 30;
int n ;
int a[N][N] , t[N][N], m[N] , type[N];
string s;
int check(int x){
	int cnt = 0;
	for(int i = 0;  i < n ; i++)		
		if((x & (1 << i)))type[i] = 1,cnt++;
		else type[i] = 0;
	for(int i = 0 ; i < n ; i++){
		if(type[i] == 1){
			for(int j = 1 ; j <= m[i] ; j++){
				if(type[a[i][j]] != t[i][j])
					return 0;
			}	
		}
	}
	return cnt;
}
main(){
	cin >> n;
	for(int i = 0 ; i < n ; i++){
		cin >> m[i];
		rep(j , 1 , m[i]){
			cin >> a[i][j] >> t[i][j];
			a[i][j]--;
		}
	}
	int ans = 0;
	for(int i = 0 ; i < (1 << n); i++){
	    ans = max(ans , check(i));
	}
	ret(ans);
	
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		String n = scan.nextLine();
		
		if("1".equals(n)) {
			System.out.println("Hello World");
		} else {
			int a = scan.nextInt();
			int b = scan.nextInt();
			System.out.println(a+b);
		}
	}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define INF 10000000000000000

using namespace std;

ll store[3005][3005];

ll geti(ll a, ll b, ll c)
{
    return 2*b + min(a,c)*2 + max(a,c);
}

ll get(ll l, ll r, ll arr[], ll pref[])
{
    if(r<=l)
        return 0;
    if(r-l == 1)
        return arr[l] + arr[r];
    
    if(store[l][r]!=INF)
        return store[l][r];
        
    ll ans = INF;
    for(ll i=l;i<=r-1;i++)
    {
        
        ans = min(ans, get(l,i,arr,pref) + get(i+1,r,arr,pref)+pref[r+1]-pref[l]);
    }
    return store[l][r] = ans;
}

int main()
{
   FAST/**/
   
   //ll n;
   //cin>>n;
   
  ll n;
  cin>>n;
  
  for(ll i=0;i<n;i++)
    for(ll j=0;j<n;j++)
        store[i][j] = INF;
  
  ll arr[n];
  for(ll i=0;i<n;i++)
        cin>>arr[i];
  
  ll pref[n+1];
  pref[0] = arr[0]*0;
  for(ll i=1;i<=n;i++)
        pref[i] = pref[i-1] + arr[i-1];
   
  ll ans = get(0,n-1,arr,pref);
  cout<<ans;
  
   return 0;
}

Measured memory_bytes: 9088
#include <iostream>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;



int main(void){

int n;
string ss;
	while(cin >> n){
		if(cin.eof()) break;
		rep(i,n){
			int ht=0, tt=0, ot=0;
			while(cin >> ss){
				if(ss=="OUT") ot++;
				if(ot > 2) break;
				if(ss=="HIT") ht++;
				if(ht > 3){ tt++; ht=3; }
				if(ss=="HOMERUN"){ tt += ht+1; ht=0;}
			}
			cout << tt << endl;
		}
	}
	return 0;
	
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector <int> a(m);
    rep (i, m) cin >> a[i];

    vector <int> scores(n, 0);
    rep (i, m) {
        int cntWrong = 0;
        rep (j, n) {
            int b;
            cin >> b;
            scores[j] += (b == a[i]);
            cntWrong += (b != a[i]);
        }
        scores[a[i] - 1] += cntWrong;
    }

    rep (i, n) cout << scores[i] << endl;

    return 0;
}


Measured memory_bytes: 3124
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)

def solve(h, w, k, A):
    B = h + w
    ret = 0
    for b in range(2 ** B):
        count = 0
        for j in range(h):
            for i in range(w):
                if b & (1 << j) or b & (1 << (i + h)):
                    continue
                if A[j][i] == '#':
                    count += 1

        if count == k:
            ret += 1
    print(ret)
    return

def main():
    h, w, k = map(int, input().split())
    a = []
    for i in range(h):
        a.append(input())
    solve(h, w, k, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 68216
N,M = map(int,input().split())
ABC = [list(map(int,input().split())) for _ in [0]*M]

E = [{} for _ in [0]*N]
Eb = [{} for _ in [0]*N]
for a,b,c in ABC:
    E[a-1][b-1] = -c
    Eb[b-1][a-1] = -c

#0 -> N-1 経路上にない頂点を除く
V1 = [False]*N
V1[0] = True
q = [0]
qp = q.pop
qa = q.append
while q:
    i = qp()
    for j in E[i]:
        if V1[j]:continue
        qa(j)
        V1[j]=True
V2 = [False]*N
V2[-1] = True
qa(N-1)
while q:
    i = qp()
    for j in Eb[i]:
        if V2[j] or not V1[j]:continue
        qa(j)
        V2[j]=True
for i in range(N):
    if V1[i] and V2[i]:continue
    for j in Eb[i]:
        E[j].pop(i)

INFTY = 10**18
d = [INFTY]*N
d[0] = 0

def update():
    done = [False]*N
    done[0] = True
    q = [0]
    qp = q.pop
    qa = q.append
    while q:
        i = qp()
        di = d[i]
        for j,c in E[i].items():
            d[j] = min(d[j],d[i]+c)
            if not done[j]:
                qa(j)
                done[j] = True
                
for _ in range(N-1):update()
dc = d[:]
update()
if dc!=d:
    print("inf")
else:
    print(-d[-1])

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

using namespace std;

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

	int a, b, k;
	cin >> a >> b >> k;
	for( int i = a; i <= min(a + k - 1, b - k); i++ )cout << i << endl;
	for( int i = max(b - k + 1, a); i <= b; i++ )cout << i << endl;

	return 0;
}


Measured memory_bytes: 256
///Astalavista Code........~boy_with_no_gf
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define Br cout<<endl
#define int long long
#define double long double
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define PT(x) cout << (x) << endl
#define PTT(x) cout << (#x) << " is " << (x) << endl; 
#define lets_go ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int M = 1e9 + 7;
const int N = 2e6 + 10;
const int IM = 1e15 + 37;
const double PI = 3.1415926535897932384;
inline void PP(int n) { cout << n << " ";}
void PV(vi v) { for (int i = 0 ; i < v.size() ; i++) cout << v[i] << " " ; cout << endl;}
void PVV(vii v) {for (int i = 0 ; i < v.size() ; i++) cout << v[i].first << " " << v[i].second << endl;}
void PA(int v[], int n, int x = 0) { for (int i = x ; i < n + x; i++)cout << v[i] << " " ; cout << endl;}
void IN(int a[], int n, int x = 0) {for (int i = x; i < n + x; i++)cin >> a[i];}
// <=================================================================================================================================
// <=================================================================================================================================


void fun(){
    int n;cin>>n;
    int val=7%n;
    for(int i=1;i<1e7;i++){
        if(val==0){
            cout<<i;
            return;
        }
        val=(val*10+7)%n;
    }
    cout<<-1;
}

signed  main() {
    lets_go

      int t;
      t=1;
// cin >> t;
    while (t--) {            
         fun();             
    }                        
                            
                            
    return 0;

}


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

vector<int> edges[210000];

int main(){
    string str;
    cin >> str;
    int cur = 0;

    map<int,int> dist;

    dist[0] = 0;
    for(int i = 0; i < str.size(); i++){
        int a = str[i] - 'a';
        cur ^= (1 << a);

        if(dist.find(cur) == dist.end()){
            dist[cur] = 1e7;
        }
        for(int j = 0; j < 26; j++){
            int c = cur ^ (1<<j);
            if(dist.find(c) == dist.end()) continue;
            dist[cur] = min(dist[cur], dist[c] + 1);
        }
    }
    cout << max(dist[cur], 1) << endl;
}


Measured memory_bytes: 14724
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		int n = sc.nextInt();
		int l = sc.nextInt();
		int a[] = new int[n];
		for(int i=0;i<n;i++) {
			a[i] = sc.nextInt();
		}
		int best =0;
		int index = -1;
		for(int i=0;i<n-1;i++) {
			if(a[i]+a[i+1] > best) {
				best = a[i]+a[i+1];
				index = (i+1);
			}
		}
		if(best<l) {
			System.out.println("Impossible");
			return;
		}
		System.out.println("Possible");
		for(int i=1;i<index;i++) {
			System.out.println(i);
		}
		for(int i=n-1;i>index;i--) {
			System.out.println(i);
		}
		System.out.println(index);
		
	}
}


Measured memory_bytes: 61488
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    int n; std::cin >> n;
    std::vector<std::vector<std::pair<int, bool>>> xy(n);
    rep(i,n){
        int ai; std::cin >> ai;
        std::vector<std::pair<int, bool>> xyi;
        rep(j,ai){
            int xi; bool yi;
            std::cin >> xi >> yi; xi--;
            xyi.push_back(std::make_pair(xi,yi));
        }
        xy[i] = xyi;
    }

    int ans = 0;
    for(int bits=0; bits<(1<<n); bits++){
        bool flag = true;
        for(int i=0; i<n; i++){
            for(auto xyi:xy[i]){
                int x = xyi.first;
                bool y = xyi.second;
                if(bits&(1<<i)){
                    if(y && !(bits&(1<<x))) flag=false;
                    if(!y && (bits&(1<<x))) flag=false;
                }
            }
        }

        if(flag==true){
            int cnt = 0;
            for(int i=0; i<n; i++){
                if(bits&(1<<i)) cnt++;
            }
            ans = std::max(ans, cnt);
        }
    }
    std::cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
using namespace std;
typedef long long ll;
int main (void) {
    int N;

    cin >> N;
    ll ans = 0;
    ll s = 0;
    for (int i = 0; i < N; i++) {
        ll A;
        cin >> A;
        if (A != 0) {
            s += A;
            if (i == N - 1) {
                ans += s / 2;
            }
        } else {
            ans += s / 2;
            s = 0;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<stdio.h>
using namespace std;
//带有标记的线性搜索
int search(int A[],int n, int key) {
	int i = 0;
	A[n] = key;//标记搜索先给关键字放在末尾
	while (A[i] != key)
		i++;
	return i != n;
}
int A[100005];
int main() {
	int n, q, key,sum=0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &A[i]);
	scanf("%d", &q);
	for (int i = 0; i < q; i++) {
		scanf("%d", &key);
		if (search(A, n, key))
			sum++;
	}
	printf("%d\n", sum);
}


Measured memory_bytes: 3228
import java.util.*;
import java.math.BigDecimal;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    BigDecimal aActual = new BigDecimal(sc.next());
    BigDecimal bActual = new BigDecimal(sc.next());
    BigDecimal ansActual = aActual.multiply(bActual);
    BigDecimal ans = ansActual.setScale(0, BigDecimal.ROUND_DOWN);
    System.out.println(ans);
  }
}


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

int main() {
  int n, m;
  cin>>n>>m;
  string s;
  cin>>s;
  reverse(s.begin(), s.end());
  int i = 0;
  vector<int> v;
  while (i < n) {
    bool ok = false;
    for (int j=m; j>0; j--) {
      if (i + j > n) {
        continue;
      }
      if (s[i+j] == '0') {
        ok = true;
        v.push_back(j);
        i = i + j;
        break;
      }
    }
    if (!ok) {
      cout<<-1<<endl;
      return 0;
    }
  }
  reverse(v.begin(), v.end());
  for (int i=0; i<v.size(); i++) {
    cout<<v[i];
    if (i != v.size() - 1) {
      cout<<" ";
    }
  }
  cout<<endl;
}

Measured memory_bytes: 1144
import fractions

N = int(input())
A = list(map(int, input().split()))
L = [0] * N
R = [0] * N
for i in range(0, N - 1):
    L[i + 1] = fractions.gcd(L[i], A[i])
for i in range(N - 1, 0, -1):
    R[i - 1] = fractions.gcd(R[i], A[i])
print(max([fractions.gcd(L[i], R[i]) for i in range(N)]))


Measured memory_bytes: 16132
#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 rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  ll n,k;cin>>n>>k;
  n = n%k;
  ll result = min<ll>(n, abs<ll>(n-k));

  cout<<result<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int h,w;
vvi a;
vi x,y,X,Y;

void f(int i,int j,int k,int l){
	a[i][j]--;a[k][l]++;
	x.push_back(i+1);
	y.push_back(j+1);
	X.push_back(k+1);
	Y.push_back(l+1);
}

int main(){
	cin>>h>>w;
	a=vvi(h,vi(w));
	for(int i=0;i<h;i++) for(int j=0;j<w;j++) cin>>a[i][j];
	for(int i=0;i<h;i++) for(int j=0;j<w-1;j++) if(a[i][j]%2==1) f(i,j,i,j+1);
	for(int i=0;i<h-1;i++) if(a[i][w-1]%2==1) f(i,w-1,i+1,w-1);
	int N=x.size();
	cout<<N<<endl;
	for(int i=0;i<N;i++) cout<<x[i]<<' '<<y[i]<<' '<<X[i]<<' '<<Y[i]<<endl;
}

Measured memory_bytes: 5224
/*    Don’t Quit
    
    When things go wrong as they sometimes will;
        When the road you’re trudging seems all uphill;
            When the funds are low, and the debts are high;
                And you want to smile, but you have to sigh;
                    When care is pressing you down a bit
                        Rest if you must, but don’t you quit.
*/
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
//#define mp make_pair
#define f first
#define s second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=3e5+10;
int a[N];
int32_t main()
{
    int n;
    cin>>n;
    map<char,int>mp;
    char ch;
    for(int i=1;i<=n;i++)
    {
        cin>>ch;
        mp[ch]++;
    }
    if(mp.size()==4)
    {
        cout<<"Four"<<endl;
    }
    else
    {
        cout<<"Three"<<endl;
    }





}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 100010


int main()
{
    int n;
    int i,j;
    char s[MAX];
    int ans[MAX]={0};
    int rcount=0,lcount=0;
    int lcountarr[MAX]={0};
    int rlpoint[MAX]={0};
    int rlpointnum=0;

    scanf("%s",s);
    n=strlen(s);

    for(i=0;i<n;i++)
    {
        if(i>0&&s[i-1]=='L'&&s[i]=='R')
        {
            lcountarr[rlpointnum]=lcount;
            //printf("lcount=%d for rlpoint:%d\n",lcount,rlpoint[rlpointnum]);
            lcount=0;
            rlpointnum++;
            rcount=1;
        }
        else if(s[i]=='R')rcount++;
        if(i>0&&s[i-1]=='R'&&s[i]=='L')
        {
            rlpoint[rlpointnum]=i;
            rcount--;
            //printf("rcount=%d for rlpoint:%d\n",rcount,rlpoint[rlpointnum]);
            ans[i-1]+=rcount/2;
            ans[i]+=(rcount+1)/2;

            //rlpointnum++;
            rcount=0;
            lcount=0;
        }
        else if(s[i]=='L')lcount++;

        if(i==n-1&&s[i]=='L')
        {
            //lcount++;
            lcountarr[rlpointnum]=lcount;
            //printf("lcount=%d for rlpoint:%d\n",lcount,rlpoint[rlpointnum]);
            lcount=0;
            rlpointnum++;
        }


    }
    for(j=0;j<rlpointnum;j++)
    {
        //printf("%d %d\n",j,rlpoint[j]);
        //printf("%d %d\n",j,lcountarr[j]);
        ans[rlpoint[j]]++;
        ans[rlpoint[j]-1]++;
        ans[rlpoint[j]-1]+=(lcountarr[j]+1)/2;
        ans[rlpoint[j]]+=lcountarr[j]/2;

    }
    for(int i=0;i<n;i++)printf("%d ",ans[i]);

}



Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,cnte[300005],ans,mi=1000000007;
string s;
signed main(){
    cin>>n>>s;
    for(int i=0;i<n;i++){
    	if(i==0){
    		if(s[i]=='E')cnte[i]++;
    	}else {
    		cnte[i]=cnte[i-1];
    		if(s[i]=='E')cnte[i]++;
    	}
    }
    for(int i=0;i<n;i++){
    	if(i==0)ans=cnte[n-1]-cnte[0];
    	else if(i==n-1)ans=n-1-cnte[n-2];
    	else {
    		ans=i-cnte[i-1];
    		ans+=cnte[n-1]-cnte[i];
    	}
    	mi=min(ans,mi);
    }
    cout<<mi<<endl;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  string s,t;
  cin >> s >> t;

  REP(i,n){
    cout << s[i] << t[i];
  }
  cout << '\n';
  return 0;
}


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

using namespace std;
typedef unsigned long long ULL;
int main(){
	ULL dat[3];
	int max,temp;
	int i,k;
	
	max = -1;
	for(i=0; i<3;i++){
		cin >> dat[i];
		if( max == -1 || dat[max] < dat[i]){
			max = i;
		}
	}
	cin >> k;
	
	temp = dat[0];
	dat[0] = dat[max];
	dat[max] = temp;
	
	cout << dat[0]*pow(2.0,k) +dat[1]+dat[2];
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String args[]) {
		
		Scanner sc = new Scanner(System.in);
		
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		if(A >= 13) {
			System.out.println(B);
		}else if(A >= 6) {
			System.out.println(B/2);
		}else {
			System.out.println(0);
		}
	}
}

Measured memory_bytes: 21844
#include <stdio.h>
int main(){
    char a[120],b[120];
    int n,m,r,p=0,x=0,win;
    for(int i=0;i<120;i++)a[i]=b[i]='\0';
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%s",a);
        scanf("%s",b);
        m=r=0;
        while(a[m]!='\0')m++;
        while(b[r]!='\0')r++;
        win=0;
        for(int j=0;j<r&&j<m&&win==0;j++){
            if(a[j]>b[j])win=1;
            if(a[j]<b[j])win=2;
        }
        if(win==0){
            if(r>m)win=2;
            else if(r<m)win=1;
            else {
                p+=1;
                x+=1;
            }
        }
        if(win==1)p+=3;
        if(win==2)x+=3;
    }
    printf("%d %d\n",p,x);
}

Measured memory_bytes: 2716
#include<iostream>
#include<string>
#include<algorithm>
#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int main()
{
    int K, S;
    cin >> K >> S;
    int ans = 0;
    for(int x = 0; x < K + 1; ++x){
        for(int y = 0; y < K + 1; ++y){
            int z = S - x - y;
            if (0 <= z && z <= K){
                ans += 1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

S = int(input())

a = list()
a.append(0)
a.append(S)

i = 2
while True:
    if a[i-1] % 2 == 0:
        n = a[i-1] / 2
    else:
        n = 3 * a[i-1] + 1
    n = int(n)
    for l in range(len(a)-1):
        if a[l] == n:
            print(i)
            sys.exit()
    
    a.append(n)
    i += 1


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define mx_int_prime 999999937
#define mem(a,b) memset(a, b, sizeof(a) )
typedef long long ll;
typedef long double ld;
const int mx=2e5+125;
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
ll p[mx],a[mx],b[mx];
int main()
{
    optimize();
    int k,x;
    cin>>k>>x;
    int ans=k*500;
    if(ans>=x)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;


    return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define p pair<int,int>
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
using namespace std;
int POW(int x,int y){return int(pow(double(x),double(y)));}


int main(){
	int h,w;
	cin>>h>>w;
	vector<vector<int>> s(h),a(h);
	int cb=0;
	rep(i,h){
		s[i].resize(w);
		a[i].resize(w);
		rep(j,w){
			char s0;
			cin>>s0;
			if(s0=='#'){
				s[i][j]=1;
				a[i][j]=-1;
				cb++;
			}else{
				s[i][j]=0;
				a[i][j]=0;
			}
		}
	}
	queue<p> q;
	q.push(make_pair(0,0));
	a[0][0]=1;
	while(q.size()){
		p z = q.front();
		q.pop();
		int x=z.first;
		int y=z.second;
		if(x==h-1 && y==w-1){
			cout<<h*w-a[x][y]-cb<<endl;
			return 0;
		}
		rep(i,4){
			if(0<=x+dx[i] && x+dx[i]<h && 0<=y+dy[i] && y+dy[i]<w && a[x+dx[i]][y+dy[i]]==0 && s[x+dx[i]][y+dy[i]]==0){
				a[x+dx[i]][y+dy[i]] = a[x][y]+1;
				q.push(make_pair(x+dx[i],y+dy[i]));
			}
		}
	}
	cout<<-1<<endl;
	
}





Measured memory_bytes: 256
use itertools::sorted;
use proconio::input;

fn main() {
    input! {
        S: String,
        T: String
    }

    let mut cnt = 0;

    for (s, t) in S.chars().zip(T.chars()) {
        if s != t {
            cnt += 1;
        }
    }

    println!("{}", cnt)
}


Measured memory_bytes: 2836
#include<stdio.h>
int main(){
	int a,b,c,t;
	scanf("%d %d %d",&a,&b,&c);
	if(a>b){
		t = a;
		a = b;
		b = t;
	}
	if(c<b){
		t = b;
		b = c;
		c = t;
	}
	if(a>b){
		t = a;
		a = b;
		b = t;
	}
	printf("%d %d %d\n",a,b,c);
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <fstream>

using namespace std;

ifstream fin("../data.txt");

int w, h;
string s;

int main() {

  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    cin >> s;
    cout << s << "\n" << s << "\n";
  }

  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>

using namespace std;


vector<int> prime;

int main(){

	for(int i = 6; i <= 300000; i++){
		//cout << i << endl;
		if(i % 7 == 1 || i % 7 == 6){
			prime.push_back(i);
		}
	}

	int num;
	while(cin >> num && num != 1){
		set<int> numList;
		for(int i = 0; i < prime.size(); i++){
			if(num % prime[i] == 0){
				bool f = false;
				int div = num;
				div /= prime[i];
				for(int j = 0; j < prime.size(); j++){
					if(prime[i] <= prime[j])
						break;
					if(prime[i] % prime[j] == 0){
						f = true;
					}
				}
				if(f)
					continue;
				if(find(prime.begin(),prime.end(),div) != prime.end()){
					numList.insert(prime[i]);
				}
			}
		}
		if(numList.size()==0)
			numList.insert(num);
		cout << num << ":" << flush;
		for(set<int>::iterator it = numList.begin(); it != numList.end(); it++){
			cout << " " << *it << flush;
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1380
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int X, Y, Z;

int main() {
  cin >> X >> Y >> Z;

  int count = 1;
  X -= Y + 2 * Z;
  count += X / (Y + Z);

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include <cmath>
#include<vector>
#define rep(i, n) for (int i=0;i<n;i++)
#include <map> 
#include<algorithm>
#include <numeric>
#include<deque>
#include<queue>
#include<string>
#include <iomanip>
using namespace std;
typedef long long ll;

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

 
int main(void){
    int k;
    cin>>k;
    ll ans=0;
    for(int i=1;i<=k;i++){
        for(int j=1;j<=k;j++){
            for(int t=1;t<=k;t++){
                ans+=gc(gc(i, j), t);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3636
A, B = map(int, input().strip().split())
S = input().strip()

if S.count("-") == 0 or S.count("-") >= 2:
  print("No")
else:
  if not S[A] == "-":
    print("No")
  else:
    tmp = S.split("-")
    if len(tmp[0]) >= 1 and len(tmp[1]) >= 1:
      print("Yes")
    else:
      print("No")


Measured memory_bytes: 2940
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define iss istringstream
#define sst stringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int w,h,z,dp[2600][2600];
string s;
vc<pi> g[2600];

int d(int i,int j,int k){
	return abs(g[i][j].fir-g[i-1][k].fir)+abs(g[i][j].sec-g[i-1][k].sec);
}

int main(){
	while(cin>>w>>h,w){
		rep(i,w*h)g[i].clear();
		pi G;
		int n=0;
		rep(i,h)rep(j,w){
			cin>>s;
			if(s=="S")g[0].pb(pi(i,j));
			else if(s=="G")G=pi(i,j);
			else if(s=="."){}
			else{
				iss ss(s);
				ss>>z;
				g[z].pb(pi(i,j));
				n=max(n,z);
			}
		}
		g[n+1].pb(G);
		rep(i,n+2)rep(j,w*h)dp[i][j]=INF;
		dp[0][0]=0;
		rep2(i,1,n+2)rep(j,g[i].sz)rep(k,g[i-1].sz){
			dp[i][j]=min(dp[i][j],dp[i-1][k]+d(i,j,k));
		}
		cout<<dp[n+1][0]<<endl;
	}
}

Measured memory_bytes: 25000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int x,a,b;
	cin>>x>>a>>b;
	x-=a;
	x%=b;
	cout<<x<<endl;
}

Measured memory_bytes: 256
N, K, Q = gets.split.map(&:to_i)
A = []
Q.times do
  A << gets.to_i
end

points = Array.new(N, 0)

A.each do |a|
  ind = a-1
  points[ind] += 1
end

N.times do |ind|
  if K - Q + points[ind] > 0
    puts 'Yes'
  else
    puts 'No'
  end
end


Measured memory_bytes: 4148
package main

import (
	"fmt"
)

func main() {
	var N, K int
	fmt.Scanf("%d%d", &N, &K)
	mc := make([]int, N)
	nmc := 0
	pc := make([]int, N)
	npc := 0
	for i := 0; i < N; i++ {
		var c int
		fmt.Scanf("%d", &c)
		if c < 0 {
			mc[nmc] = c
			nmc++
		} else if c == 0 {
			K--
		} else {
			pc[npc] = c
			npc++
		}
	}

	if K == 0 {
		fmt.Printf("0\n")
		return
	}

	for i := 0; i < nmc/2; i++ {
		mc[nmc-i-1], mc[i] = mc[i], mc[nmc-i-1]
	}

	//fmt.Printf("%v\n%d\n%v\n%d\n", mc, nmc, pc, npc)

	ans := 1145141919
	if K <= npc {
		ans = pc[K-1]
	}
	for i := 1; i < K; i++ {
		if K-i > npc {
			continue
		}
		if i > nmc {
			continue
		}
		anss := pc[K-i-1] - mc[i-1]
		if pc[K-i-1] < -mc[i-1] {
			anss += pc[K-i-1]
		} else {
			anss -= mc[i-1]
		}
		//fmt.Printf("%d\n", anss)
		if anss < ans {
			ans = anss
		}
	}
	if K <= nmc {
		anss := -mc[K-1]
		if anss < ans {
			ans = anss
		}
	}
	fmt.Printf("%d\n", ans)

}


Measured memory_bytes: 4736
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#define mod (1e9 + 7)
#define pb push_back
using namespace std;
typedef pair<int,int> pii;

int main(){

  int n;
  cin>>n;
  vector<int> a;
  int t,sum;
  sum=0;
  for(int i=0;i<n;i++){
    cin>>t;
    a.pb(t);
    sum+=t;
  }

  t=sum;
  for(int i=1;i<n;i+=2){
    t-=2*a[i];
  }
  cout<<t<<" ";

  for(int i=0;i<n-1;i++){
    t=2*a[i]-t;
    cout<<t<<" ";
  }

  cout<<endl;
  return 0;
}



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

int main() {
  int64_t N, A, B;
  cin >> N >> A >> B;

  int64_t p = N / (A+B);
  int64_t r = N % (A+B);

  int64_t ans = p * A + min(r, A);
  cout << ans << endl;
}


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

int main() {
	int t;
	std::cin >> t;
	for ( int i=0; i<t; i++ ) {
		
		// 入力
		
		int n, k;
		std::cin >> n >> k ;
		int x[100000];
		for ( int j=0; j<n; j++ ) {
			std::cin >> x[j];
		}
		
		// 演算
		
		int a[100000];
		for ( int j=0; j<n-1; j++ ) {
			a[j] = x[j+1] - x[j];
		}
		
		std::sort( a, a+n-1 );
		
		int savedTotal=0;
		for ( int j=0; j<k-1; j++ ) {
			savedTotal += a[ n-1-j-1 ];
		}
		
		// 出力
		
		std::cout << x[n-1] - x[0] - savedTotal << std::endl;
		
	}
	return 0;
}

Measured memory_bytes: 1956
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#include <bits/stdc++.h>
#define pb(X) push_back(X)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
using namespace std;

int n, a, b, c, d, q, ans;

int main() {
	INIT
	cin >> a >> b;
	if(a == b) cout << int(2 * a);
	else cout << int(max(a, b) * 2 - 1);

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
const int INFINITY_HAHA = 999999;
 
typedef struct status {
    int from, to, speed;
    double time;
    status(int x, int x2, double y, int z): from(x), to(x2), time(y), speed(z) {}
    bool operator< (const status &b) const {
        return time > b.time;
    }
} Status;



int main() {
    // freopen("input.txt", "r", stdin);
 
    int ncities, nroads;
    while(scanf("%d%d", &ncities, &nroads) != EOF && !(ncities == 0 && nroads == 0)) {
 
        int visited[50][50][50];
        priority_queue< Status> Q;
 
        vector< vector<int> > path_cost(ncities + 1, vector<int>(ncities + 1, -1) );
        vector< vector<int> > path_limit(ncities + 1, vector<int>(ncities + 1, -1) );
 
        memset(visited, 0, sizeof(visited));
 
        // Input
        int start_index, end_index;
        scanf("%d%d" , &start_index, &end_index);
 
        for(int n = 0; n < nroads; ++n) {
            int x, y, d, c;
            scanf("%d%d%d%d", &x, &y, &d, &c);
            path_cost[x][y] = path_cost[y][x] = d;
            path_limit[x][y] = path_limit[y][x] = c;
        }
 
        double minimun_v = 0;
        Q.push(Status(start_index, start_index, 0.0, 0));
 
        while(!Q.empty()) {
            Status cs = Q.top();
            Q.pop();
 
            if(cs.to == end_index && cs.speed == 1) {
                minimun_v = cs.time;
                break;
            }
 
            if(visited[cs.from][cs.to][cs.speed]) continue;
 
            visited[cs.from][cs.to][cs.speed] = 1;
 
            for(int j = 1; j <= ncities; ++j) {
                if(path_cost[cs.to][j] == -1) continue;
                if(j == cs.from) continue;
                 
 
                for(int z = -1; z <= 1; ++z) {
                    if(!visited[cs.to][j][cs.speed + z] && cs.speed + z >= 1 && cs.speed + z <= path_limit[cs.to][j]) {
                        Q.push(Status(cs.to, j, cs.time + ((double)path_cost[cs.to][j])/(cs.speed + z), cs.speed + z));
                    }
                }
            }
        }
 
        if(minimun_v) {
            printf("%0.5lf\n", minimun_v);
        } else {
            printf("unreachable\n");
        }
    }
 
    return 0;
}

Measured memory_bytes: 15624
#include <stdio.h>

int main(void){
  int A, B, C, D, i, X, Y;
  
  scanf("%d", &A);
  scanf("%d", &B);
  scanf("%d", &C);
  scanf("%d", &D);
  
  X = A * B;
  Y = C * D;
  
  if(X < Y)
    printf("%d", Y);
  else if(Y < X)
    printf("%d", X);
  else if(X = Y)
    printf("%d", X);
  
  return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
    public void main(Scanner sc) {
        int n = sc.nextInt();
        int a[] = new int[n];
        int b[] = new int[n];

        int p[] = new int[n];
        for (int i = 0; i < n; i++) {
            p[sc.nextInt() - 1] = i + 1;
            a[i] = i * n + 1;
        }

        b[n - 1] = 1;
        for (int i = n - 2; i >= 0; i--) {
            b[i] = b[i + 1] + n + p[i] - p[i + 1];
        }

        System.out.println(Arrays.toString(a).replaceAll("[^0-9 ]", ""));
        System.out.println(Arrays.toString(b).replaceAll("[^0-9 ]", ""));
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        new Main().main(sc);
        sc.close();
    }
}


Measured memory_bytes: 43380
#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; cin>>n;
   vector<ll> a(n);
   rep(i,n) cin>>a[i];
   int cnt=0;
   rep(i,n){
      while(a[i]%2==0){
         cnt++;
         a[i]/=2;
      }
   }
   cout<<cnt<<endl;
   return 0;
}

Measured memory_bytes: 384
import java.util.Arrays;
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      if(a<=5){
        System.out.println(0);
      }else if(a>=13){
        System.out.println(b);
      }else{
        System.out.println(b/2);
      }
    }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
struct Node;
vector<Node> V;
struct Node {
  vector<int> nbr;
  vector<lint> cost;
  lint d = 1e18;
};
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  lint N, M, P;
  cin >> N >> M >> P;
  REP(i, N) V.emplace_back();
  REP(i, M) {
    lint A, B, C;
    cin >> A >> B >> C;
    A--; B--;
    V[A].nbr.push_back(B);
    V[A].cost.push_back(-(C-P));
  }
  V[0].d = 0;
  REP(k, 2*N) REP(i, N) REP(j, V[i].nbr.size()){
    if(V[i].d != 1e18 && V[i].d + V[i].cost[j] < V[V[i].nbr[j]].d) {
      V[V[i].nbr[j]].d = V[i].d + V[i].cost[j];
      if(k >= N) V[V[i].nbr[j]].d = -1e18;
    }
  }
  if(V[N-1].d <= -1e17) {
    cout << -1 << endl;
    return 0;
  }
  if(V[N-1].d > 0) V[N-1].d = 0;
  cout << -V[N-1].d << endl;
}

Measured memory_bytes: 672
from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for _ in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
tests = lambda: range(1, int_in() + 1)
case_out = lambda i, o: out("Case #{}: {}".format(i, o))


def solve(n):
    result = [0] * n
    for i in range(1, n+1):
        i2 = pow(i, 2)
        for j in range(i, n+1):
            j2 = pow(j, 2)
            for k in range(j, n+1):
                k2 = pow(k, 2)
                curr = i2 + j2 + k2 + i*j + i*k + j*k
                if curr > n:
                    break
                count = 6
                if i == j and i == k:
                    count = 1
                elif i == j or i == k or j == k:
                    count = 3
                result[curr-1] += count
    return result


if __name__ == "__main__":
    n = int_in()
    result = solve(n)
    for item in result:
        out(item)

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

using namespace std;

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;

constexpr int MAXN = 400;

ll dp[MAXN + 2][MAXN + 2];
ll a[MAXN + 2];

int main() {
	int N;
	cin >> N;
	for(int i = 1; i <= N; i++) {
		cin >> a[i];
		a[i] += a[i - 1];
	}
	for(int i = 2; i <= N; i++) {
		for(int j = 0; i + j <= N; j++) {
			dp[i][j] = LONG_MAX;
			for(int k = 1; k < i; k++)
				dp[i][j] = min(dp[i][j], dp[i - k][j] + dp[k][i + j - k]);
			dp[i][j] += a[i + j] - a[j];
		}
	}
	cout << dp[N][0] << endl;
}


Measured memory_bytes: 1536
#include<stdio.h>
#include<string.h>
int main(){
  int n,i,f,j,k;
  char s[260]={"a "},a[256],*w;
  while(fgets(s+2,257,stdin)!=NULL){
    s[strlen(s)-1]=0;
    f=0;
    for(j=0;j<26;j++){
      for(k=0;k<strlen(s);k++){
	if('a'<=s[k]&&s[k]<='z'){
	  if(s[k]=='z')s[k]='a';
	  else s[k]++;
	}
      }
      strcpy(a,s);
      w=strtok(a," ");
      while((w=strtok(NULL," ."))!=NULL){
	if(strcmp(w,"that")==0||strcmp(w,"this")==0||strcmp(w,"the")==0){
	  f=1;
	  break;
	}
      }
      if(f==1)break;
    }
    printf("%s\n",s+2);
  }
  return 0;
}

Measured memory_bytes: 524
def judge(num):
	num_list_pre =list()
	num_list_late =list()
	num_list = list(str(num))		 
	num_list_pre.extend(num_list[:int(len(num_list)/2):])
	num_list_late.extend(num_list[int(len(num_list)/2)+1:])
	if num_list_pre == list(reversed(num_list_late)):
		return True
	else:
		return  False

A,B = map(int,input().split())
count =0
for i in range(A,B+1):
		if judge(i):
			 count +=1
print(count)

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

N=int(input())
P=[input().split() for i in range(N)]

for i in range(N):
    P[i][0]=int(P[i][0])
    P[i][1]=int(P[i][1])

def ans(Q):
    MINX=10**15
    MAXX=-10**15
    MINY=10**15
    MAXY=-10**15

    for x,y in Q:
        MINX=min(MINX,x)
        MINY=min(MINY,y)
        MAXX=max(MAXX,x)
        MAXY=max(MAXY,y)

    return (MAXX-MINX)*(MAXY-MINY)
    
def time(t):
    Q=[]
    for x,y,s in P:
        if s=="R":
            x+=t
        elif s=="L":
            x-=t
        elif s=="U":
            y+=t
        else:
            y-=t
        Q.append([x,y])

    return Q

MIN=0
MAX=10**10

while MAX-MIN>=1:
    #print(MAX,MIN)
    x=(MIN+MAX)//2

    if ans(time(x))>ans(time(x+1/2)):
        MIN=x+1/2
    else:
        MAX=x

        
print(min(ans(time(MAX)),ans(time(MIN))))


Measured memory_bytes: 133348
#include <stdio.h>
#include <stdlib.h>

#define NIL -1

typedef struct{
  int p;
  int l;
  int r;
} node;


void print(node *, int);
int depth(node *, int);
int sibling(node *, int);
int degree(node *, int);
int height(node *, int, int); 


int n;


int main(){
  node u[100001];
  int k, id, c, l, r;
  int i, j;
  

  scanf("%d", &n);
  
  for(i = 0; i < n; i++){
    u[i].p = NIL;
    u[i].l = NIL;
    u[i].r = NIL;
  }


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

    for(j = 0; j < 2; j++){
      scanf("%d", &c);
      if(j == 0) u[id].l = c;

      else u[id].r = c;

      l = c;
      if(l >= 0) u[c].p = id; 
    }
  }

  for(i = 0; i < n; i++) print(u, i);
  
  return 0;
}


void print(node *u, int i){
  int c;

  printf("node %d: ", i);
  printf("parent = %d, ", u[i].p);
  printf("sibling = %d, ", sibling(u, i));
  printf("degree = %d, ", degree(u, i));
  printf("depth = %d, ", depth(u, i));
  printf("height = %d, ", height(u, i, 0));

  if(u[i].p == NIL) printf("root");
  else if(u[i].p != NIL && u[i].r == NIL && u[i].l == NIL) printf("leaf");
  else printf("internal node");

  printf("\n");
}


int depth(node *u, int x){
  int count = 0, temp;

  while(u[x].p != NIL){
    count++;
    temp = u[x].p;
    x = temp;
  }

  return count;
}


int sibling(node *u, int x){
  if(u[x].p == NIL) return NIL;
  if(u[u[x].p].r == x) return u[u[x].p].l;
  if(u[u[x].p].l == x) return u[u[x].p].r;

  return NIL;
}


int degree(node *u, int x){
  int deg = 0;

  if(u[x].l != NIL && u[x].r != NIL)      deg = 2;
  else if(u[x].l != NIL || u[x].r != NIL) deg = 1;
  
  return deg;
}


int height(node *u, int x, int count){
  int a, b;
  
  if(degree(u, x) == 2){
    count++;
    a = height(u, u[x].l, count);
    b = height(u, u[x].r, count);

    if(a >= b) return a;
    else return b;
  }

  else if(degree(u, x) == 1){
    count++;

    if(u[x].l != NIL) return height(u, u[x].l, count);
    if(u[x].r != NIL) return height(u, u[x].r, count);

    return count;
  }

  else return count;
}



Measured memory_bytes: 2084
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stack>
#include<queue>
using namespace std;
int main()
{
	
	int i, n;
	long long num[100005] = {0,1};
	for (i = 2; i <= 100004; i++)
		num[i] = (num[i-1] * i)%(1000000007);
	scanf("%d", &n);
	printf("%lld\n", num[n]);
	return 0;
}


Measured memory_bytes: 1024
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long W = sc.nextLong();
    long H = sc.nextLong();
    long x = sc.nextLong();
    long y = sc.nextLong();
    double ans = (W*H)/2.0;
    int can = 0;
    if(x*2 == W && y*2==H){
      can = 1;
    }
    
    System.out.println(ans + " " + can);
    
  }
}

Measured memory_bytes: 38860