akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define INF 999999999
typedef long long int Int;
using ll = long long;
using VI = vector<int>;

int main(){
  Int s;
  cin >> s;
  map<Int,Int> mp;
  Int i=1;
  while(!mp.count(s)){
    mp[s]=i++;
    if(s&1) s=s*3+1;
    else s/=2;
  }
  cout << i << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(input())
cs = input()
r_num = 0
w_num = 0
# RRR|WWWW にする
r_num = cs.count('R')
w_num = cs.count('W')

if r_num == 0 or w_num == 0:
    print(0)
else:
    ans = []
    W = 0
    rl_num = 0
    for c in cs:
        if c == 'R':
            rl_num += 1
        elif c == 'W':
            W += 1
        R = r_num - rl_num
        ans.append(max(W, R))

    print(min(ans))


Measured memory_bytes: 17392
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b= sc.nextInt();
        int c = sc.nextInt();
        int n = a-b;
        System.out.println(Math.max(c-n,0));
    }
}

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

int main() {
  int N, i, l, r, ans = 0;
  cin >> N;

  for (i = 0; i < N; i++){
    cin >> l >> r;
    ans += r - l + 1;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>

using namespace std;

int main(int argc,char ** argv) {
    int n,a,b;
    scanf("%d %d %d",&n,&a,&b);
    if(!(abs(a-b)%2)){
        printf("Alice");
    } else {
        printf("Borys");
    }
}

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

int main(){
  ll a,b,k;
  cin >> a >> b >>k;
  
  if(a>=k){
    cout << a-k << " " << b << endl;
    return 0;
  }
  
  else if(a+b>=k){
    cout <<"0 "<< a+b-k << endl;
    return 0;
  }
  
  else
    cout << "0 0" << endl;
  return 0;
}
  

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

typedef long long ll;

const ll INF=1E9+10;
const ll MAXN=1e5+10;
using namespace std;


ll h[MAXN];
ll n,a,b;

bool find(ll x){
	ll y=0;
	ll v;
	for(int i=0;i<n;i++){
		v=h[i]-b*x;
		if(v>0){//如果最低限度减去它还不够 
			y+=ceil(v*1.0/(a-b)); //需要多出来的次数 
		}
	} 
	return y<=x; //在此情况下的实际值y与理论值x相比 
}

bool cmp(ll x,ll y){
	return x>y;
}
 int main() {
 	ll sum=0,mx=-INF;
	bool f=1;
 	cin>>n>>a>>b;
 	for(ll i=0;i<n;i++){
 		cin>>h[i];
	}
	ll left=0,ans=1e9,mid;
	//最大值为1e9，每次减少1，最多可能需要1e9次，所以ans初始值设置为1e9 
	while(ans-left>1){//为什么跳出循环的条件是这样的？ 
		mid=(ans+left)/2;
		if(find(mid))	{//为真表示太多了 
			ans=mid;
		}
		else {//为假表示太少了 
			left=mid;
		}
	}
	cout<<ans<<endl;
 	return 0;
 }

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

int main()
{
    double a, b, x;
    cin >> a >> b >> x;
    double l=0;
    if (2 * x / (a* a) >= b)
    {
        //
        l = (2 * (a * a * b - x) / (a * a * a));
        cout << fixed << setprecision(10) << atan(l) * 180 / M_PI << endl;
    }
    else
    {
        l = b * b / (2*x/a);
        cout << fixed << setprecision(10) << atan(l) * 180.0 / M_PI << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long mod=1000000007;
long long mypow(long a,long long b) {
  long long c;
  if (b==0) return 1;
  else {
    c=mypow(a,b/2)*mypow(a,b/2)%mod;
    if (b%2==1) c=c*a%mod;
    return c;
  }
}
vector<long long> fac(2000003);
vector<long long> minv(2000003);
void myfact(long n) {
  long i;
  fac.at(0)=1;
  minv.at(0)=1;
  for(i=1;i<=n;i++) {
    fac.at(i)=i*fac.at(i-1)%mod;
    minv.at(i)=mypow(fac.at(i),mod-2)%mod;
  }
}
long long mycomb(long n,long r) {
  long long c;
  c=fac.at(n)*minv.at(r)%mod*minv.at(n-r)%mod;
  return c;
}
int main() {
  long r1,c1,r2,c2;
  long long a;
  cin>>r1>>c1>>r2>>c2;
  myfact(r2+c2+2);
  a=(mycomb(r2+c2+2,r2+1)-mycomb(r2+c1+1,r2+1)-mycomb(r1+c2+1,r1)+mycomb(r1+c1,r1))%mod;
  if (a<0) a+=mod;
  cout<<a<<endl;
}
//1≤r1≤r2≤10^6
//1≤c1≤c2≤10^6

Measured memory_bytes: 31488
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int x,y;
int c[20][20];
int dp[20][20];

void solve() {
    rep(i,20) rep(j,20) c[i][j]=1;
    rep(i,20) rep(j,20) dp[i][j]=0;
    rep(i,y) rep(j,x) cin>>c[i][j];
    rep(i,x) if(c[0][i]!=1) dp[0][i]=1;//????????????????????????????????£??????DP???????????????????¨?????????????
    for(int i=0;i<y;i++) {
        for(int j=0;j<x;j++) {
            if(c[i][j]==2) {
                dp[i+2][j] += dp[i][j];
            }
            else if(c[i][j]==0) {
                if(c[i+1][j]!=1) {
                    dp[i+1][j] += dp[i][j];
                }
                if(0<=j-1 && c[i+1][j-1]==0) {
                    dp[i+1][j-1] += dp[i][j];
                }
                if(j+1 < x && c[i+1][j+1]==0) {
                    dp[i+1][j+1] += dp[i][j];
                }
            }
        }
    }
    int ans=0;
    rep(i,x) if(c[y-1][i]!=1) ans+=dp[y-1][i];
    rep(i,x) ans+=dp[y][i];
    cout<<ans<<endl;
}
int main() {
    while(cin>>x>>y) {
        if(x+y==0) return 0;
        solve();
    }
    return 0;
}

Measured memory_bytes: 3012
n,k=map(int,input().split())
p=list(map(int,input().split()))
a=p[:k]
cnt=0
tmp=[]
for i in a:
  cnt+=(1+i)/2
tmp+=[cnt]
for i in range(n-k):
  cnt-=(1+p[i])/2
  cnt+=(1+p[i+k])/2
  tmp+=[cnt]
print(max(tmp))

Measured memory_bytes: 24548
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define int long long
using P = pair<int,int>;

signed main(){
  int n;
  cin >> n;
  string s,t;
  cin >> s >> t;
  int ans = 1;
  rep(i,n){
    if(i == 0){
      if(s[i] == t[i]) ans *= 3;
      else{
        ans *= 6;
        i+=2;
      }
    }
    else{
      if(s[i-1] == t[i-1]){
        if(s[i] == t[i]) ans *= 2;
        else{
          ans *= 2;
          i++;
        }
      }
      else{
        if(s[i] != t[i]){
          ans *= 3;
          i++;
        }
      }
    }
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()

 
int main() {
 vector<ll> vec(3);
  for(ll i=0;i<3;i++) {
    cin>>vec[i];
  }
  sort(all(vec));
  ll K;
  cin>>K;
  ll count=0;
  while(count<K) {
vec[2]*=2;
    count++;
  }
  
  ll ans=0;
  for(auto x:vec) {
ans+=x;
  }
  cout<<ans<<endl;
}
  
  

Measured memory_bytes: 3612
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    f = [[0, 0]for i in range(N)]
    f[0][0] = min(A[0], B[0])
    f[0][1] = min(A[1], B[0]-f[0][0])
    ans = f[0][0] + f[0][1]
    for i in range(1, N):
        f[i][0] = min(A[i]-f[i-1][1], B[i])
        f[i][1] = min(A[i+1], B[i]-f[i][0])
        ans += f[i][0] + f[i][1]
    print(ans)


solve()


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

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

    vector<long long> P(N + 1, 0);
    for (long long i = 1; i <= N; i++)
    {
        long long p;
        cin >> p;
        P[p] = i;
    }

    multiset<long long> s;
    s.insert(0);
    s.insert(0);
    s.insert(N + 1);
    s.insert(N + 1);
    long long ans = 0;
    long long n1, n2, m1, m2;
    for (long long i = N; i > 0; i--)
    {
        s.insert(P[i]);
        auto itr = s.find(P[i]);
        n1 = P[i];
        n1 += -*--itr;
        n2 = *itr;
        n2 += -*--itr;

        itr = s.find(P[i]);
        m1 = -P[i];
        m1 += *++itr;
        m2 = -*itr;
        m2 += *++itr;

        long long count = 0;
        count += n2 * m1 + m2 * n1;
        ans += i * count;
    }
    cout << ans << endl;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define LEN(x) ((int)(x).length())
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &value) {
    std::fill((T *)array, (T *)(array + N), value);
}
#define PUTS(x) cout << (x) << endl;
int main() {
    string s;
    int k;
    cin >> s >> k;
    auto len = LEN(s);
    Int dp[150][150][2]; // dp[i][j][k] 首位からi桁目(0-index)まで調べ終えた時点で0以外がj個含まれるものの個数。ただし k=1 はそのうちn以下であることが確定しているものの数，k=0は確定していない（すなわち第i桁までずっとnと一致している）ものの個数。
    Fill(dp, 0); // 初期化
    rep(i, len) {
        auto pivot = s[i] - '0'; // 第i桁
        if (i == 0) { // 首位
            dp[0][0][1] = 1; // 首位が0のものは0以外を0個含み確定
            dp[0][1][1] = pivot - 1; // 首位が 1,2,3,..,pivot-1 のものは0以外を1個含み確定
            dp[0][1][0] = 1; // 首位が pivot のものは0以外を1個含み未確定
        } else {
            // まずは確定済みのものの状態遷移処理
            rep(j, 149) {
                dp[i][j + 1][1] += 9 * dp[i - 1][j][1]; // 第i桁目が0以外のもの
                dp[i][j][1] += dp[i - 1][j][1]; // 第i桁目が0のもの
            }
            // 次に未確定状態のものの状態遷移処理
            if (pivot == 0) { // 第i桁目が0の場合
                rep(j, 149) {
                    dp[i][j][0] = dp[i - 1][j][0]; // 未確定状態をそのまま持ち越し
                }
            } else { // 第i桁目が0以外の場合
                rep(j, 149) {
                    dp[i][j][1] += dp[i - 1][j][0]; // 第i桁目が0のものは0以外の個数がそのままで確定
                    dp[i][j + 1][1] += (pivot - 1) * dp[i - 1][j][0]; // 第i桁目が 1,2,3,..,pivot-1 のものは0以外の個数が増えて確定
                    dp[i][j + 1][0] += dp[i - 1][j][0]; // 第i桁目が pivot のものは0以外の個数が増えて未確定
                }
            }
        }
    }
    auto ans = dp[len - 1][k][0] + dp[len - 1][k][1];
    PUTS(ans);
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(a, b) for (ll i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}
template<class T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}


int main(){
    int h,w;
    cin >> h >> w;
    vector<vector<char>> v(h+2,vector<char>(w+2,'#'));
    REP(i,h){
        REP(j,w){
            cin >> v[i+1][j+1];
        }
    }
    int max=0;
    REP(i,h){
        REP(j,w){
            int a=i+1;
            int b=j+1;
            if(v[a][b]=='#'){
                continue;
            }
            vector<vector<bool>> ans(h+2, vector<bool>(w+2,false));
            queue<int> qx;
            queue<int> qy;
            queue<int> q;
            if(v[a][b-1]=='.'){
                qx.push(a);
                qy.push(b-1);
                q.push(1);
                ans[a][b-1] = true;
            }
            if (v[a][b + 1] == '.')
            {
                qx.push(a);
                qy.push(b + 1);
                q.push(1);
                ans[a][b+1] = true;
            }
            if (v[a-1][b] == '.')
            {
                qx.push(a-1);
                qy.push(b);
                q.push(1);
                ans[a-1][b] = true;
            }
            if (v[a+1][b] == '.')
            {
                qx.push(a+1);
                qy.push(b);
                q.push(1);
                ans[a+1][b] = true;
            }
            int tmp=0;
            ans[a][b] = true;
            while(!q.empty()){
                int x=qx.front();
                int y=qy.front();
                qx.pop();
                qy.pop();
                int kazu=q.front();
                q.pop();
                tmp = kazu;
                kazu++;
                if (v[x][y - 1] == '.'&&!ans[x][y-1])
                {
                    qx.push(x);
                    qy.push(y - 1);
                    q.push(kazu);
                    ans[x][y-1] = true;
                }
                if (v[x][y + 1] == '.' &&!ans[x][y + 1])
                {
                    qx.push(x);
                    qy.push(y + 1);
                    q.push(kazu);
                    ans[x][y+1] = true;
                }
                if (v[x - 1][y] == '.' &&!ans[x-1][y])
                {
                    qx.push(x - 1);
                    qy.push(y);
                    q.push(kazu);
                    ans[x-1][y] = true;
                }
                if (v[x + 1][y] == '.' &&!ans[x+1][y])
                {
                    qx.push(x + 1);
                    qy.push(y);
                    q.push(kazu);
                    ans[x+1][y] = true;
                }
            }
            if(max<tmp){
                max=tmp;
            }
        }
    }
    cout << max << endl;
}

Measured memory_bytes: 256
using System;
using static System.Console;

class Program
{
    public static void Main()
    {
	int n = int.Parse(ReadLine());
	int m = n*(n-1)/2 - n/2;
	WriteLine(m);

	for (int i = 1; i <= n-1; i++)
	{
	    int x = (n|1) - i;
	    for (int j = i + 1; j <= n; j++)
	    {
		if (j != x) WriteLine($"{i} {j}");
	    }
	}
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=1000010;
const ll mod=1e9+7;

vector<bool> ip(mx,0);
 
bool isprime(int x){
  if(x==2 || x==3){ return true; }
  if(x<2 || x%2==0){ return false; }
  
  int sqrtx = ceil(sqrt(x));
  for(int i=3; i<=sqrtx; i+=2){ if(x%i==0){ return false; } }
  return true;
}
 
void ipset(int x){                                        //x miman prime set
  for(int i=2; i<x; i++){ ip[i]=isprime(i);}
}

ll gcd(ll a, ll b){ return b ? gcd(b,a%b):a; }

int main(){
  ipset(mx);
  ll a,b;
  cin >> a >> b;
  ll tmp = gcd(a,b);
  ll ans=1;
  for(int i=2; i<=mx && i<=tmp; i++)if(ip[i])if(tmp%i==0){
    ans++;
    while(tmp%i==0){ tmp/=i; }
  }
  for(int i=mx; i<=sqrt(tmp) && tmp!=1; i++)if(tmp%i==0){
    ans++;
    while(tmp%i==0){ tmp/=i; }    
  }
  if(tmp!=1){ans++;}
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>

using namespace std;

vector<long> a(1002), b(1002), c(1002);
vector<long> tmp1(1000002);
vector<long> tmp2(9000002,0);
bool comp2(const long& left, const long& right) {
    return left > right;
}

int main(){
    long x,y,z,k;
    cin >> x >> y >> z >> k;

    for(long i=0; i<x; i++) cin >> a[i];
    for(long i=0; i<y; i++) cin >> b[i];
    for(long i=0; i<z; i++) cin >> c[i];


    for(long i=0; i<y; i++){
        for(long j=0; j<z; j++){
            tmp1[z*i+j] = b[i]+c[j];
        }
    }
    sort(a.begin(), a.begin()+x, comp2);
    sort(tmp1.begin(), tmp1.begin()+y*z, comp2);

    long max2;
    if( (y*z)>=k) max2=k;
    else max2 = y*z;

    for(long i=0; i<k; i++){
        if( i >= x) break;
        for(long j=0; j<max2; j++){
            tmp2[i*max2+j] = a[i]+tmp1[j];
        }
    }
    //cerr << "end add" << endl;
    if( x>= k) sort(tmp2.begin(), tmp2.begin()+k*max2, comp2);
    else sort(tmp2.begin(), tmp2.begin()+x*max2, comp2);

    for(int i=0; i<k; i++){
        cout << tmp2[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 78464
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
	H, W = MAP()
	maze = [list(input()) for _ in range(H)]
	dp = [[INF]*W*H for _ in range(W*H)]

	for i in range(H*W):
		for j in range(H*W):
			if maze[i//W][i%W] == "#":
				continue
			if maze[j//W][j%W] == "#":
				continue
			if i == j:
				dp[i][j] = 0
			if i + W == j:
				dp[i][j] = 1
			if i + 1 == j:
				if i%W == W - 1:
					continue
				dp[i][j] = 1
			if i - W == j:
				dp[i][j] = 1
			if i - 1 == j:
				if i%W == 0:
					continue
				dp[i][j] = 1

	for i in range(W*H):
	    for j, c2 in enumerate(row[i] for row in dp):
	           for k, (c1, c3) in enumerate(zip(dp[j], dp[i])):
	               if c1 > c2+c3:
	                   dp[j][k] = c2+c3

	ma = 0
	for i in range(len(dp)):
		for j in range(len(dp[i])):
			if dp[i][j] == INF:
				continue
			ma = ma if ma > dp[i][j] else dp[i][j]

	print(int(ma))

if __name__ == "__main__":
	main()


Measured memory_bytes: 76504
#include <iostream>
#include <stdio.h>
#define ll long long
#define Mod 1000000007
#define sz 1004
#define valid i>0 && i <= h && j>0 && j<=w && a[i][j]!='#'
using namespace std;
char a[sz][sz];
ll vis[sz][sz];
ll cnt;
ll x , y;
void blockClimbing(int h , int w){
    int i , j;
    for(i = h-1 ; i > 0 ; i--){
        for(j = w-1 ;j > 0;j--){
            if(a[i][j]!='#')vis[i][j] = vis[i+1][j] + vis[i][j+1],vis[i][j]%=Mod;
        }
    }
}
int main(){
    //freopen("test.txt","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int i ,  j , n , m , h , w;
    cin>>h>>w;
    for(i=1;i<=h;i++){
        for(j=1;j<=w;j++){
            cin>>a[i][j];
        }
    }
    i = h;j=w;
    while(i>0 && a[i][j]!='#')vis[i][j] = 1 , i--;
    i = h;
    while(j>0 && a[i][j]!='#')vis[i][j] = 1,j--;
    blockClimbing(h,w);
    cout<<vis[1][1]<<endl;
    return 0;
}


Measured memory_bytes: 9088
#include <iostream>

typedef long long ll;
int N;
ll B[101], A[101];

int main() {
  std::cin >> N;
  for (int i = 1; i < N; ++i)
    std::cin >> B[i];

  ll sum = B[1];
  for (int i = 1; i < N-1; ++i)
    sum += (B[i] <= B[i+1] ? B[i] : B[i+1]);
  sum += B[N-1];

  std::cout << sum << "\n";

  return 0;
}


Measured memory_bytes: 3616
package main

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

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}()

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func calcMaxArea(w, h int) float64 {
	return float64(w*h) / 2.0
}

func existsMultiWays(w, h, x, y int) bool {
	isHalf := func(base, v int) bool {
		return base%2 == 0 && base/2 == v
	}

	return isHalf(w, x) && isHalf(h, y)
}

func main() {
	w, h, x, y := nextInt(), nextInt(), nextInt(), nextInt()

	fmt.Printf("%v ", calcMaxArea(w, h))
	if existsMultiWays(w, h, x, y) {
		fmt.Println(1)
	} else {
		fmt.Println(0)
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

const int MAX_N = 200000;

int n, m;
vector<vector<P>> G;
int dist[MAX_N];

bool dfs(int v) {
    for (auto p : G[v]) {
        int nv = p.first;
        int nd = p.second;
        if (dist[nv] != INF) {
            if (dist[nv] != dist[v] + nd) return false;
        }
        else {
            dist[nv] = dist[v] + nd;
            if (!dfs(nv)) return false;
        }
    }
    return true;
}

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

    cin >> n >> m;
    G.resize(n);
    int s;
    rep(i, m) {
        int l, r, d;
        cin >> l >> r >> d;
        --l, --r;
        if (i == 0) s = l;
        G[l].push_back(make_pair(r, d));
        G[r].push_back(make_pair(l, -d));
    }

    rep(i, MAX_N) dist[i] = INF;

    bool ok = true;
    rep(i, n) {
        if (dist[i] != INF) continue;
        dist[i] = 0;
        if (!dfs(i)) ok = false;
    }

    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 15616
#include <bits/stdc++.h>
 
#define ll long long int
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define hello777 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#include <string>
#define pie 3.14159265358979323846
constexpr int MOD = 1e9+7;
const int N= 50000;
using namespace std;


//ll gcd(int a, int b)
//{ 
//    if (a == 0) 
//        return b;  
//    return gcd(b % a, a);  
// } 
// 
//ll lcm(int a, int b)  
// {  
//    return a/gcd(a, b) *b;  
// }
//  
//int prime(int n)
//{
//	rep(i,2,n+1)
//	{
//		if(n%i==0)return i;
//	}
//	
//}


void solve() 
{
	int n, ans = 0; cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i++)
        cin >> v[i];
 
    for(int i = 0; i < n; i++)
    {
        for(int j = i + 1; j < n; j++)
        {
            for(int k = j + 1; k < n ; k++)
            {
                if((v[i] + v[j] > v[k]) && (v[j] + v[k] > v[i]) && (v[i] + v[k] > v[j]))
                    if((v[i] != v[j]) && (v[j] != v[k]) && (v[i] != v[k]))
                        ans++;
            }
        }
    }
 
    cout << ans << '\n';
}

int main()
{
	hello777;
	int q=1;
//    cin>>q;
    while(q--)
    {   
      solve();
    }
}

Measured memory_bytes: 3664
#!/usr/bin/env python3


def solve(N, S):
    ans = 0
    last = ''
    for c in S:
        if c != last:
            last = c
            ans += 1
    return ans


if __name__ == '__main__':
    N = int(input())
    S = input()

    ans = solve(N, S)

    print(ans)


Measured memory_bytes: 3316
s = input()
k = len(s)
o = []
x = []
for i,j in enumerate(s):
    if j == 'o':
        o.append(i)
    else:
        x.append(i)

if 15-len(s) + len(o) >= 8:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 2940
m, n = (int(x) for x in input().split())
k = int(input())
joi_list = [0]*m
for i in range(m):
  joi_list[i] = list(input())
c = ['J', 'O', 'I']
t = [[[0]*(n+1) for i in range(m+1)] for j in range(len(c))]

for h in range(len(c)):
  for i in range(1,m+1):
    co = 0
    for j in range(n):
      if joi_list[i-1][j] == c[h]:
        co += 1
      t[h][i][j+1] = t[h][i-1][j+1] + co

ans = [0]*len(c)
for i in range(k):
  p1, q1, p2, q2 = (int (x) for x in input().split())
  for h in range(len(c)):
    ans[h] = t[h][p2][q2]-t[h][p2][q1-1]-t[h][p1-1][q2]+t[h][p1-1][q1-1]
  print(*ans)


Measured memory_bytes: 131692
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.List
import Data.Char
import Control.Monad
import qualified Data.ByteString.Char8 as BS

readIntPair :: BS.ByteString -> (Int, Int)
readIntPair s = let Just (a, s') = BS.readInt s
                    Just (b, _) = BS.readInt $ BS.dropWhile isSpace s'
                in (a, b)

main = do
  (n,m) <- readIntPair <$> BS.getLine
  (maxL,minR) <- fmap (foldl1' (\(!l,!r) (!l',!r') -> let !ll = max l l'; !rr = min r r' in (ll,rr))) $ replicateM m (readIntPair <$> BS.getLine)
  print $ max 0 (minR - maxL + 1)


Measured memory_bytes: 23164
"use strict";
const main = input => {
    const n = parseInt(input[0].split(' ')[0], 10);
    const m = parseInt(input[0].split(' ')[1], 10);
    const c = parseInt(input[0].split(' ')[2], 10);
    
     var b=[];
     b = input[1].split(" ").map(Number);
 
    var  i,k = 0;var cnt = 0;
  for(i=0; i<n; i++) {
     var total = 0;
     let a = input[i+2].split(' ').map(Number);;
        for( k=0; k<m; k++) {
            total =total + a[k]*b[k];
      //    console.log(a[k],b[k],total);
        }
        if (total+c>0) {
            cnt++;
              }
    }
    console.log(cnt);
    
}
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));



Measured memory_bytes: 21064
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {

        // input
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());
        int M = Integer.parseInt(scanner.next());
        int X = Integer.parseInt(scanner.next());
        int Y = Integer.parseInt(scanner.next());
        scanner.nextLine();

        List<Integer> x = Arrays.asList(scanner.nextLine().split(" ")).stream()
                .map(Integer::parseInt).collect(Collectors.toList());
        List<Integer> y = Arrays.asList(scanner.nextLine().split(" ")).stream()
                .map(Integer::parseInt).collect(Collectors.toList());

        // xの最大値
        int xMax = x.get(0);
        for (int xi : x) {
            xMax = Math.max(xMax, xi);
        }

        // yの最小値
        int yMin = y.get(0);
        for (int yi : y) {
            yMin = Math.min(yMin, yi);
        }

        // Zが存在するかどうか
        if ((xMax < yMin) && (X < yMin) && (xMax < Y)) {
            System.out.println("No War");
        } else {
            System.out.println("War");
        }

    }
}


Measured memory_bytes: 28244
#include<bits/stdc++.h>
#define MOD (long long)(1e9+7)
using namespace std;
int n;
long long dp[3001][3001];
string s;
int main()
{
	cin >> n >> s;
	dp[1][1]=1;
	for(int i=2; i<=n; i++)
	{
		if(s[i-2] == '<') for(int j=2; j<=i; j++) dp[i][j]=(dp[i][j-1]+dp[i-1][j-1])%MOD;
		else for(int j=i-1; j; j--) dp[i][j]=(dp[i][j+1]+dp[i-1][j])%MOD;
	}
	long long ans=0;
	//for(int i=1; i<=n; cout<<'\n',i++)
	//	for(int j=1; j<=n; j++)
	//		cout << dp[i][j] << ' ';
	for(int i=1; i<=n; i++) ans=(ans+dp[n][i])%MOD;
	cout << ans;
	return 0;
}

Measured memory_bytes: 49700
#include <iostream>
#include <string>
using namespace std;
int main() {
	int N, i;
	unsigned long long ans, M, A, R, C, H;
	string Name;
	M = 0;A = 0;R = 0;C = 0;H = 0;
	cin >> N;
	for (i = 0;i < N;i++) {
		cin >> Name;
		if (Name[0] == 'M') { M++; }
		else if (Name[0] == 'A') { A++; }
		else if (Name[0] == 'R') { R++; }
		else if (Name[0] == 'C') { C++; }
		else if (Name[0] == 'H') { H++; }
		else {}
	}
	ans = M*A*R + M*A*C + M*A*H + M*R*C + M*R*H + M*C*H + A*R*C + A*R*H + A*C*H + R*C*H;
	cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
 
namespace Algorithm
{
    class Program
    {
        const int Mod = 1000000007;
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long N = l[0], K = l[1];
            var cb = new long[N + 1, K + 1];
 
            for (var i = 0; i < N + 1; i++)
            {
                for (var j = 0; j < K + 1; j++)
                {
                    if (j == 0) cb[i, j] = 1;
                    else if (i == 0) cb[i, j] = 0;
                    else cb[i, j] = (cb[i - 1, j - 1] + cb[i - 1, j]) % Mod;
                }
            }
 
            for (var i = 0; i < K; i++)
                Console.WriteLine(cb[N - K + 1, i + 1] * cb[K - 1, i] % Mod);
 
        }
    }
}

Measured memory_bytes: 42336
#include<stdio.h>
int main(){
  int n,q,i,j,c=0;
  int s[10000],t[500];
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&s[i]);

  scanf("%d",&q);
  for(i=0;i<q;i++) scanf("%d",&t[i]);

  for(i=0;i<q;i++){

    for(j=0;j<n;j++){
      
      if(t[i]==s[j]){
	c++;
	break;
      }

    }

  }

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

  return 0;
}



Measured memory_bytes: 2108
n, k = map(int, input().split())
d = list(map(int, input().split()))
ng = [False] * 10
for i in d:
    ng[i] = True
def ok(n):
    global ng
    while n > 0:
        if ng[n%10]:
            return False
        n //= 10
    return True
while not ok(n):
    n += 1
print(n)

Measured memory_bytes: 9108
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define ll long long

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

int main () {
    int n, m, a, b;
    cin >> n >> m;
    dsu d(n);
    rep(i, m) {
        cin >> a >> b;
        a--;
        b--;
        d.merge(a,b);
    }
    int cnt = d.groups().size();
    int ans = cnt - 1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9080
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var ab = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            Console.WriteLine(ab[0] * ab[1] % 2 == 0 ? "Even" : "Odd");
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <vector>

using namespace std;


int main()
{
    const int64_t mod = 1000000000 + 7;

    int N, K;
    cin >> N >> K;

    int64_t res = 0;

    for (int i = 0; i < K; ++i)
    {
        res += (N - i - i);
    }

    int64_t sum = (res + 1) % mod;
    for (int k = K; k < N + 1; ++k)
    {
        res += (N - k - k);
        sum += res + 1;
        sum %= mod;
    }
    cout << sum << endl;
}

Measured memory_bytes: 3612
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <inttypes.h>

int main(void){
	int n,m;
	char s[101][11]={'\0'};
	char t[101][11]={'\0'};
	int ans=0,sans=0,tans=0;
	int i;
	int j;
	int answer[100]={0};

	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s\n",s[i]);
	}
	scanf("%d",&m);
	for(i=0;i<m;i++){
		scanf("%s\n",t[i]);
	}
	for(i=0;i<n;i++){
		for(j=0,sans=0;j<n;j++){
			if(strcmp(s[i],s[j])==0){
				sans++;
			}
		}
		for(j=0,tans=0;j<m;j++){
			if(strcmp(s[i],t[j])==0){
				tans++;
			}
		}
		answer[i]=sans-tans;
	}
	for(i=0;i<n;i++){
		if(ans<=answer[i]){
			ans=answer[i];
		}
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <numeric>

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

using namespace std;

typedef vector<int> vi;

int key(int a) {
	vi p;
	FOR(i,2,1000000) {
		if (a % i == 0) {
			do {
				a /= i;
			} while(a % i == 0);
			p.push_back(i);
		}
	}
	return -accumulate(ALL(p)-1, -p.back());
}

int main() {
	for(int a, b; cin >> a >> b && a;) {
		cout << (key(a) < key(b) ? "b" : "a") << endl;
	}
	
	return 0;
}

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

using ll=long long;
using ld=long double;

void solve(){
	ll a,v,b,w,t;
	cin>>a>>v;
	cin>>b>>w;
	cin>>t;
	ll p=v*t;
	ll q=w*t;
	bool flag=false;
	if(a<b){
		p+=a;
		q+=b;
		if(p>=q){
			flag=true;
		}
	}else{
		p=a-p;
		q=b-q;
		if(q>=p){
			flag=true;
		}
	}
	cout<<(flag?"YES":"NO")<<"\n";

}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	solve();
	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int main() {
	map<int, pair<int, int>> mp;
	int a[3][3] = {};
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> a[i][j];
			mp[a[i][j]] = {i, j};
		}
	}
	int row[3] = {};
	int col[3] = {};
	int diago[3] = {};
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		int x; cin >> x;
		if (mp.count(x)) {
			++row[mp[x].first];
			++col[mp[x].second];
			if (mp[x].first == mp[x].second) 
				++diago[0];
			if (mp[x].first + mp[x].second == 2)
				++diago[1];
		}
	}
	bool ok = false;
	for (int i = 0; i < 3; i++) {
		ok |= row[i] == 3;
		ok |= col[i] == 3;
		ok |= diago[i] == 3;
	}
	cout << (ok ? "Yes" : "No");
}

Measured memory_bytes: 256
int main()
{
    char s[3];
    scanf("%s",s);
if (!strcmp(s,"SUN") || !strcmp(s,"MON") || !strcmp(s,"TUE") || !strcmp(s,"WED") || !strcmp(s,"THU") || !strcmp(s,"FRI") || !strcmp(s,"SAT")){
    if (!strcmp(s,"SUN"))
        printf("7");
    else
    if (!strcmp(s,"MON"))
        printf("6");
    else
    if (!strcmp(s,"TUE"))
        printf("5");
    else
    if (!strcmp(s,"WED"))
        printf("4");
    else
    if (!strcmp(s,"THU"))
        printf("3");
    else
    if (!strcmp(s,"FRI"))
        printf("2");
    else
    if (!strcmp(s,"SAT"))
        printf("1");
}
else printf("INVALID");

}


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

namespace ConsoleApp33 {
    class Program {
        static void Main(string[] args) {
            var st = Console.ReadLine().Split(' ').Select(int.Parse).OrderBy(x => x).ToArray();

            int ab = st[0];
            int bc = st[1];
            int ca = st[2];

            Console.WriteLine(ab * bc / 2);

        }
    }
}


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

int main(void) {
	char prime[1000000];
	int i,j,n,ans;

	for(i=2;i<1000000;i++){
		prime[i]=1;
	}

	for(i=2;i<1000;i++){
		if(prime[i]==1){
			for(j=i*i;j<1000000;j+=i){prime[j]=0;}
		}
	}

	while(scanf("%d",&n)!=EOF){
		ans=0;
		for(i=2;i<=n;i++){
			if(prime[i]==1)ans++;
		}
		printf("%d\n",ans);
	}

	return EXIT_SUCCESS;
}

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

int main() {
    int n;
    cin>>n;
    ll ans=1;
    for (int i=1; i<=n; i++) {
        if (i*i<=n) ans=i*i;
        else {
            cout<<ans<<endl;
            return 0;
        }
    }
    cout<<ans<<endl;
}


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

public static class Program {
    static int n;
    static long mod=1000000007;
    public static void Main() {
        long[]nk=Console.ReadLine().Split().Select(long.Parse).ToArray();
        n=(int)nk[0];
        long k=nk[1];
        long[,]a=new long[n,n];
        for(int i=0;i<n;i++){
            int j=0;
            foreach(long x in Console.ReadLine().Split().Select(long.Parse)){
                a[i,j++]=x;
            }
        }
        long[,]c=Pow(a,k);
        long ans=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                ans+=c[i,j];
            }
        }
        ans%=mod;
        Console.WriteLine(ans);

        // for(int i=0;i<n;i++){
        //     Console.Write($"[a[{i}]]");
        //     for(int j=0;j<n;j++){
        //         Console.Write($" {a[i,j]}");
        //     }
        //     Console.Write("\n");
        // }
        // for(int i=0;i<n;i++){
        //     Console.Write($"[c[{i}]]");
        //     for(int j=0;j<n;j++){
        //         Console.Write($" {c[i,j]}");
        //     }
        //     Console.Write("\n");
        // }
    }
    public static long[,] Mul(long[,] a, long[,] b){
        long[,]c=new long[n,n];
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                for(int k=0;k<n;k++){
                    c[i,j]+=a[i,k]*b[k,j]%mod;
                }
                c[i,j]%=mod;
            }
        }
        return c;
    }
    public static long[,] Pow(long[,]a, long b){
        long[,]c=new long[n,n];
        for(int i=0;i<n;i++)c[i,i]=1;
        for(;b>0;b/=2){
            if(b%2==1)c=Mul(c,a);
            a=Mul(a,a);
        }
        return c;
    }
}


Measured memory_bytes: 15456
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int B,R;
  B = R = 0;
  for(int i = 0;i < S.size();i++){
    if(S[i] == '0') B++;
    else R++;
  }
  int answer = 2*min(B,R);
  cout << answer << endl;
}

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

int main()
{
    char str[19];
    for(int i=0;i<19;i++){
        cin >> str[i];
    }
    str[5]=' ';
    str[13]=' ';
    for(int i=0;i<19;i++){
        cout << str[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
 
namespace rika
{
  template <typename T>
  class edge
  {
  public:
    int to;
    T cost;
     
    edge() = default;
    edge(const edge<T>&) = default;
    edge(edge<T>&&) = default;
    edge& operator =(const edge<T>&) = default;
    edge& operator =(edge<T>&&) = default;
 
    ~edge() = default;
 
    edge(int _to, T _cost) : to(_to), cost(_cost) {}
  };
}
 
namespace rika
{
  namespace internal
  {
    template <typename TValue, typename TGraph>
    std::pair<TValue, int> visit(int from, int v, const TGraph &g)
    {
      auto r = std::make_pair(TValue(), v);
      try{
      for(auto it = g[v].begin(); it != g[v].end(); ++it)
      {
        if(it->to == from)
          continue;
        auto r2 = visit<TValue>(v, it->to, g);
        if(r2.first + it->cost >= r.first)
          r = std::make_pair(r2.first + it->cost, r2.second);
      }
      }
      catch (edge<int> x) {}
      return r;
    }
  }
 
  template <typename TValue, typename TGraph>
  TValue tree_diameter(const TGraph &g)
  {
    using namespace internal;
    auto r1 = visit<TValue>(-1, 0, g);
    auto r2 = visit<TValue>(-1, r1.second, g);
    return r2.first;
  }
}
 
#include<bits/stdc++.h>
using namespace std;
using namespace rika;
int main()
{
  int N;
  cin >> N;
  vector<vector<edge<int>>> g(N * 10);
  for(int i = 0; i < N - 1; i++)
  {
    int s, t, w;
    cin >> s >> t >> w;
    g[s].push_back(edge<int>(t, w));
    g[t].push_back(edge<int>(s, w));
  }
  cout << tree_diameter<int>(g) << endl;
}

Measured memory_bytes: 35360
open Printf
open Scanf

type point = {id : int; x : int; y : int}
               
let () =
  let n = scanf "%d " (fun x -> x) in
  let ps = Array.init n (fun i -> let a, b = scanf "%d %d " (fun x y -> (x, y)) in {id = i; x = a; y = b}) in
  let rt = Array.make 3000000 None in
  let rec make_rt k ix = function
      [||] -> ()
    | ar -> 
       let l = Array.length ar in
       let m = l / 2 in
       if ix then
         Array.fast_sort (fun pa pb -> compare pa.x pb.x) ar
       else
         Array.fast_sort (fun pa pb -> compare pa.y pb.y) ar;
       rt.(k) <- Some ar.(m);
       make_rt (2*k) (not ix) (Array.sub ar 0 m);
       make_rt (2*k+1) (not ix) (try Array.sub ar (m+1) (l-m-1) with _ -> [||])
  in
  make_rt 1 true ps;
  let q = scanf "%d " (fun x -> x) in
  let rec loop c =
    if c = q then ()
    else
      begin
        let sx, tx, sy, ty = scanf "%d %d %d %d " (fun a b c d -> (a, b, c, d)) in
        let rec iter k ix ls =
          match rt.(k) with
            None -> ls
          | Some p -> let ls1 = if sx <= p.x && p.x <= tx && sy <= p.y && p.y <= ty then p :: ls else ls in
                      let ls2 = if ix then
                                  if sx <= p.x then iter (2*k) (not ix) ls1 else ls1
                                else
                                  if sy <= p.y then iter (2*k) (not ix) ls1 else ls1 in
                      let ls3 = if ix then
                                  if p.x <= tx then iter (2*k+1) (not ix) ls2 else ls2
                                else
                                  if p.y <= ty then iter (2*k+1) (not ix) ls2 else ls2 in
                      ls3 in
        iter 1 true [] |> List.sort (fun u v -> compare u.id v.id) |> List.iter (fun v -> printf "%d\n" v.id);
        printf "\n";
        loop (c+1)
      end
  in
  loop 0

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

int main()
{
  ll q, h, s, d;
  cin >> q >> h >> s >> d;
  ll n;
  cin >> n;
  q *= 4, h *= 2;
  ll t = min({q, h, s});
  ll ans = 0;
  if (2 * t > d)
  {
    ans = n / 2 * d;
    if(n % 2 != 0)
      ans+=t; 
  }
  else ans=n*t;
  cout<<ans<<endl;

  return 0;
}

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

namespace ABC148B
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] ST = Console.ReadLine().Split(' ');
            List<string> ans = new List<string>();
            for(int i = 0; i < N; i++)
            {
                ans.Add(ST[0][i].ToString());
                ans.Add(ST[1][i].ToString());
            }
            Console.WriteLine(string.Join("", ans));
        }
    }
}


Measured memory_bytes: 27596
from fractions import gcd
# from datetime import date, timedelta
# from heapq import *
import heapq
import math
from collections import defaultdict, Counter, deque
from bisect import *
import itertools
import fractions
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
# input = sys.stdin.readline


def lcm(a, b):
    return a * b / fractions.gcd(a, b)


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors


def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


def is_prime(n):
    if n == 1:
        return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True


def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

def modpow(a, n, mod):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % mod
        a = a * a % mod
        n >>= 1
    return res


def modinv(a, mod):
    return modpow(a, mod - 2, mod)


def cnk(a, b):
    MOD = 10**9+7
    ret = 1
    for i in range(b):
        ret *= (a-i)
        ret %= MOD
        ret = ret * modinv(i+1, MOD) % MOD
    return ret




def main():
    x, a, b = map(int, input().split())
    if a >= b:
        print("delicious ")
    elif a < b:
        if (b - a) <= x:
            print("safe")
        else:
            print("dangerous")


            


    




    


if __name__ == '__main__':
    main()


Measured memory_bytes: 5172
import java.util.Scanner;

public class Main {
  public static void main(String ...args) {
    final Scanner scanner = new Scanner(System.in);
    final int length = scanner.nextInt();
    final int[] numbers = new int[length];
    for (int idx = 0; idx < length; idx++) {
      numbers[idx] = scanner.nextInt();
    }

    final int result = maximumDifference(length, numbers);
    System.out.println(result);
  }

  public static int maximumDifference(final int N, final int[] A) {
    int maxDiff = 0;
    for (int currentIdx = 0; currentIdx < N; currentIdx++) {
      for (int otherIdx = 0; otherIdx < N; otherIdx++) {
        if (currentIdx == otherIdx) continue;

        final int diff = A[currentIdx] - A[otherIdx];
        maxDiff = maxDiff < diff ? diff : maxDiff;
      }
    }

    return maxDiff;
  }
}


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

using namespace std;

int n, m, c[12];
char g[12][13], h[12][13];
bool e[12][12], used[12];
unsigned long long sign[12], r_sign[12]; 

bool ck(int u, int cnt) {
  if (u == n) { return cnt >= n / 2; }
  
  if (used[u]) {
    if (ck(u + 1, cnt)) return true;
    else return false;
  }
 
  if (n & 1) {
    if (e[u][u]) {
      used[u] = true;
      if (ck(u + 1, cnt)) return true;
      used[u] = false;
    }
  }

  for (int v = 0; v < n; ++v) {
    if (v != u && !used[v] && e[u][v]) {
      used[u] = used[v] = true;
      if (ck(u + 1, cnt + 1)) return true;
      used[u] = used[v] = false;
    }
  }

  return false;
}

int main() {

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

  for (int x = 0; x < (1 << m); ++x) {

    int cnt = 0;
    for (int i = 0; i < m; ++i) {
      if ((x >> i) & 1) ++cnt;
    }
    if (cnt != m / 2) continue;

    vector<int> a, b;
    for (int i = 0; i < m; ++i) {
      if ((x >> i) & 1) { a.push_back(i); }
      else { b.push_back(i); }
    }

    for (int i = 0; i < (m + 1) / 2; ++i) c[i] = i;    
    
    do {      
     
      for (int r = 0; r < n; ++r) {  
        for (int i = 0; i < m / 2; ++i) {
          // a[i], b[c[i]]
          h[r][i] = g[r][a[i]];
          h[r][m - 1 - i] = g[r][b[c[i]]]; 
        }
        if (m & 1) {
          h[r][m / 2] = g[r][b[c[m / 2]]];
        }
        h[r][m] = '\0';
//        cout << h[r] << endl;
      }

//      cout << endl;

      memset(e, 0x00, sizeof(e));
    
      for (int i = 0; i < n; ++i) {
        sign[i] = r_sign[i] = 0;
        for (int j = 0; j < m; ++j) {
          sign[i] = sign[i] * 31 + h[i][j];
          r_sign[i] = r_sign[i] * 31 + h[i][m - 1 - j];
        }
      }

      for (int i = 0; i < n; ++i) {
        for (int j = i; j < n; ++j) {
          if (sign[i] == r_sign[j]) {
            e[i][j] = e[j][i] = true;
          }
        }
      }
      
      memset(used, 0x00, sizeof(used));
      if (ck(0, 0)) {
        cout << "YES" << endl;
        return 0;
      }

    } while (next_permutation(c, c + (m + 1) / 2));

  }

  cout << "NO" << endl;

  return 0;
}

Measured memory_bytes: 256
n = int(input())
c = input()
r = 0
left, right = 0, n-1
while left < right:
    if c[left] == 'W' and c[right] == 'R':
        r += 1
        left += 1
        right -= 1
        continue
    if c[left]=='R':
        left += 1
    if c[right]=='W':
        right -= 1
print(r)

Measured memory_bytes: 9292
#include<cstdio>

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

using namespace std;

typedef	long long	ll;

int main(){
	for(int n;scanf("%d",&n),n;){
		bool sche[50][31]={};
		rep(i,n){
			int f;	scanf("%d",&f);
			rep(j,f){
				int d;	scanf("%d",&d);
				sche[i][d]=true;
			}
		}

		int ans=-1;
		ll maps[50];
		rep(i,n)	maps[i]=1LL<<i;
		for(int t=1;t<=30;t++){
			ll gather=0;
			rep(i,n)if(sche[i][t])	gather|=maps[i];
			rep(i,n)if(sche[i][t])	maps[i]=gather;
			if(gather==(1LL<<n)-1){ ans=t; break; }
		}

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

	return 0;
}

Measured memory_bytes: 760
package main

import "fmt"

func main(){
	var N,K,count,count2 int
	fmt.Scan(&N,&K)
	if K%2 == 0{
		for i:=1;i<N+1;i++{
			if i%K == 0{
				count++
			}else if i%K == (K/2){
					count2++
			}
		}
	}else{
		for i:=1;i<N+1;i++{
			if i%K == 0{
				count++
			}
		}
	}
	fmt.Println(count*count*count+count2*count2*count2)
}

Measured memory_bytes: 512