akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n,a,b,c,d;
  cin >> n;
  d = n % 10;
  n /= 10;
  c = n % 10;
  n /= 10;
  b = n % 10;
  n /= 10;
  a = n % 10;
  if(a + b + c + d == 7){
    cout << a << "+" << b << "+" << c << "+" << d << "=7";
  }else if (a + b + c - d == 7){
    cout << a << "+" << b << "+" << c << "-" << d << "=7";
  }else if (a + b - c + d == 7){
    cout << a << "+" << b << "-" << c << "+" << d << "=7";
  }else if (a + b - c - d == 7){
    cout << a << "+" << b << "-" << c << "-" << d << "=7";
  }else if (a - b + c + d == 7){
    cout << a << "-" << b << "+" << c << "+" << d << "=7";
  }else if (a - b + c - d == 7){
    cout << a << "-" << b << "+" << c << "-" << d << "=7";
  }else if (a - b - c + d == 7){
    cout << a << "-" << b << "-" << c << "+" << d << "=7";
  }else if (a - b - c - d == 7){
    cout << a << "-" << b << "-" << c << "-" << d << "=7";
  }
}

Measured memory_bytes: 3616
/**********************************************
 * author : deepak nayan
 * file   : e:/Solutions/atcoder/abc118_a.cpp
 * time   : Fri May  1 14:42:02 2020
 * quest  : A - B +/- A
 *********************************************/
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  cout << ((b % a) ? b - a : a + b) << "\n";
  return 0;
}


Measured memory_bytes: 256
//created by Whiplash99
import java.io.*;
import java.util.*;
public class Main
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,N;

        N=Integer.parseInt(br.readLine().trim());
        String s[]=br.readLine().trim().split(" ");
        int a[]=new int[N];
        for(i=0;i<N;i++) a[i]=Integer.parseInt(s[i]);

        int count=0;
        for(i=1;i<N-1;i++)
        {
            if(a[i]<=a[i-1]&&a[i]>=a[i+1]) count++;
            else if(a[i]>=a[i-1]&&a[i]<=a[i+1]) count++;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 32644
#include <string>
#include <iostream>
#include <cstdio>
using namespace std;
string a,b,c,d,e,f,g,h;
int main() {
cin >> f;
for(int i=0;i<f.length();i++){
if (f[i]==f[i+1]) return printf("%d %d\n",i+1,i+2), 0;
}
for (int i = 0; i + 2 < f.length(); i++) {
if(f[i]==f[i+2]) return printf("%d %d\n",i+1,i+3), 0;
}
printf("-1 -1\n");
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
 while(1){
     C-=B;
     if(C<1){cout << "Yes" << endl;
         break;
     }
     A-=D;
     if(A<1){cout << "No" << endl;
         break;
     }
 }
}

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
  int n,p[3],ans=0,x[1001],y[1001],z[1001];
  cin >> n;
  for(int i=0;i<n;++i){
    cin >> p[0] >> p[1] >> p[2];
    sort(p,p+3);
    x[i]=p[0];
    y[i]=p[1];
    z[i]=p[2];
    for(int j=0;j<i;++j){
      if(x[j]==x[i]&&y[j]==y[i]&&z[j]==z[i]){
	ans++;
	break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3136
use std::io;
use std::collections::HashMap;
use std::cmp::max;

fn main() {
    let n = read_ln();
    let blues = read_cards(n);
    let m = read_ln();
    let reds = read_cards(m);
    println!("{}", maximum_score(&blues, &reds));
}

fn maximum_score(blues: &HashMap<String, i32>, reds: &HashMap<String, i32>) -> i32 {
    let max_in_blues = blues
        .iter()
        .map(|(k, v)| v - reds.get(k).unwrap_or(&0))
        .max()
        .unwrap_or(0); // when there is no card, he'll get 0.
    max(max_in_blues, 0)
}

fn read_cards(n: usize) -> HashMap<String, i32> {
    let mut cards: HashMap<String, i32> = HashMap::new();
    for _ in 0..n {
        let c = cards.entry(get_line()).or_insert(0);
        *c += 1;
    }
    cards
}

fn get_line() -> String {
    let mut inp = String::new();
    io::stdin().read_line(&mut inp).expect("read error");
    inp.trim().to_string()
}

fn read_ln() -> usize {
    get_line().trim().parse().expect("Not a number")
}


Measured memory_bytes: 4352
from collections import Counter

s = input()
mod1 = 673
mod2 = 3

num1 = 0
num2 = 0
li1 = []
li2 = []
pw1 = 10
pw2 = 10
for i, e in enumerate(s, 1):
    num1 *= 10
    num1 += int(e)
    num1 %= mod1
    inv = pow(pw1, mod1 - 2, mod1)
    li1.append(num1 * inv % mod1)

    num2 *= 10
    num2 += int(e)
    num2 %= mod2
    inv = pow(pw2, mod2 - 2, mod2)
    li2.append(num2 * inv % mod2)

    pw1 *= 10
    pw1 %= mod1
    pw2 *= 10
    pw2 %= mod2

li = [0] + [10 * e1 + e2 for e1, e2 in zip(li1, li2)]
c = Counter(li)

ans = 0
for v in c.values():
    ans += v * (v - 1) // 2

print(ans)


Measured memory_bytes: 95584
#include <stdio.h>

int main(void)
{
	int a,b,c,count,i;
	count=0;
	scanf("%d %d %d",&a,&b,&c);
	for(i=a;i<=b;i++){
		if(0==c%i){
			count++;
		}
	}
	printf("%d\n",count);
	return 0;
}


Measured memory_bytes: 2756
N=int(input())
import sys
sys.setrecursionlimit(10**6)
G=[[] for _ in range(N)]
for i in range(N-1):
  a,b=map(int, input().split())
  G[a-1].append((i,b-1))
  G[b-1].append((i,a-1))
ans=[0]*(N-1)  
def dfs(now_node,pre_node,pre_c):
  color=1
  
  for t in G[now_node]:
    num,next_node=t
    if next_node==pre_node:
      continue
    next_color=color
    if next_color==pre_c:
      next_color+=1
    ans[num]=next_color
    #print(i,next_color)
    dfs(next_node, now_node,next_color)
    color=next_color+1
dfs(0,-1,-1)
print(max(ans))
for a in ans:
  print(a)

Measured memory_bytes: 78904
#include <iostream>
#define rep(i,n) for(int i = 0 ; i < n ; i++)

using namespace std;

int G[100][100];

int main(){
  int V;

  cin >> V;

  rep(i,V){
    int u,k,v;

    cin >> u >> k;
    rep(j,k){
      cin >> v;
      G[u-1][v-1] = 1;
    }
  }

  rep(i,V){
    rep(j,V){
      if(j == V-1) cout << G[i][j] << endl;
      else cout << G[i][j] << " ";
    }
  }

  return 0;
}

Measured memory_bytes: 1200
n = int(input())
b = list(map(int,input().split()))


a = [0] * n
a[0] = b[0]
a[1] = b[0]
a[n - 1] = b[n-2]
for i in range(1,n-1):
     if a[i] > b[i]:
          a[i] = b[i]
     a[i + 1] = b[i]
print(sum(a))

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


int main()
{
    int a = 0, b = 0;
    cin >> a >> b;

    int d = a / b;
    int r = a % b;
    double f = (double)a / b;
    cout << d << " " << r << " ";
    cout << fixed << setprecision(6) << f << endl;

    return 0;
}

Measured memory_bytes: 1244
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

vector<vector<int > > g;   // to
vector<ll> cnt;
vector<ll> ans;

void dfs( int par, int curr, ll val)
{
    ll valcurr = val + cnt[curr];
    ans[curr]=valcurr;

    int siz=(int)g[curr].size();
    int i;
    for(i=0; i<siz; i++) {
        int next=g[curr][i];
        if(next==par) continue;

        dfs( curr, next, valcurr );
    }

    return;
}

int main(int argc, char* argv[])
{
    int n,q;
    scanf("%d%d", &n, &q);

    g.resize(n);
    cnt.resize(n);
    ans.resize(n);
    int i;
    for(i=0; i<n-1; i++) {
        int a,b;
        scanf("%d%d", &a, &b);
        g[a-1].push_back(b-1);
        g[b-1].push_back(a-1);
    }

    for(i=0; i<q; i++) {
        int p,x;
        scanf("%d%d", &p, &x);
        cnt[p-1]+=x;
    }

    dfs( -1, 0, 0 );
    
    for(i=0; i<n; i++) {
        printf("%lld ", ans[i]);
    }
    printf("\n");


    return 0;
}


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

int main()
{
    int N, K;
    string S;
    cin >> N >> S >> K;

    char target = S.at(K-1);

    for (int i = 0; i < N; i++)
    {
        if (S.at(i) == target)
            cout << target;
        else
            cout << '*';
    }
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
int main(){
	set<int> x;
	int tot=0;
	int n,temp;
	cin>>n;
	for(int i=0;i!=n;++i){
		cin>>temp;
		if(temp<3200)
			x.insert(temp/400);
		else
			++tot;
	}
	cout<<max(1,int(x.size()))<<' '<<x.size()+tot;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int A, B;

ll lcm(int x, int y) {
    return (ll)x * (ll)y / __gcd(x, y);
}

void solve() {
    cin >> A >> B;
    cout << lcm(A, B) << endl;
}

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


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

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n; cin >> n;
  string s; cin >> s;
  vi w(n+1),e(n+1);
  rep(i,n){
    w[i+1] = (s[i]=='W');
    e[i] = (s[i]=='E');
  }
  rep(i,n){
    w[i+1] += w[i];
    e[i+1] += e[i];
  }
  int ans = INF;
  rep(i,n){
    chmin(ans,w[i]+e[n]-e[i]);
  }
  cout << ans;
  cout << endl;
  return 0;
}


Measured memory_bytes: 6108
#include"bits/stdc++.h"
using namespace std;


int main()
{
    int n,t;
    cin>>n>>t;
    int a[n+5],b[n+5];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i];
    }
int     mn=1000000009;
    bool p=false;
    for(int i=1;i<=n;i++)
    {
        if(b[i]<=t){
                p=true;
          mn=min(mn,a[i]);
        }
    }
    if(p)
    {
        cout<<mn<<endl;
    }
    else
    {
        cout<<"TLE"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import bisect
import sys
input = sys.stdin.buffer.readline
N,D,A= map(int,input().split())
XH = [list(map(int,input().split())) for i in range(N)]
XH.sort()
X,H = [list(x) for x in zip(*XH)]

ans = 0
cum = [0]*N
dam = 0
for i in range(N):
    dam += cum[i]
    H[i] -= dam
    x = X[i]
    if H[i] <= 0:
        continue
    cnt_bom = -(-H[i] // A)
    ans += cnt_bom
    damage = cnt_bom * A
    ind = bisect.bisect_right(X,x+2*D)
    if i+1 < N:
        cum[i+1] += damage 
    if ind < N:
        cum[ind] -=damage 

print(ans)


Measured memory_bytes: 97004
// Vicfred
// https://atcoder.jp/contests/abc175/tasks/abc175_e
// dynamic programming
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main() {
    long R, C, K;
    readf("%s %s %s", &R, &C, &K);
    readln;

    long[][] v = new long[][](R+1, C+1);
    long[][][] dp = new long[][][](R+1, C+1, 4);

    for(int i = 0; i < K; ++i) {
        int x, y, w;
        readf("%s %s %s", &x, &y, &w);
        readln;
        v[x][y] = w;
    }

    for(int i = 1; i <= R; ++i) {
        for(int j = 1; j <= C; ++j) {
            long newrow = long.min;
            for(int k = 0; k <= 3; ++k)
                newrow = max(newrow, dp[i-1][j][k]);
            dp[i][j][0] = max(dp[i][j-1][0], newrow);
            dp[i][j][1] = max(dp[i][j-1][1], max(newrow, dp[i][j-1][0]) + v[i][j]);
            dp[i][j][2] = max(dp[i][j-1][2], dp[i][j-1][1] + v[i][j]);
            dp[i][j][3] = max(dp[i][j-1][3], dp[i][j-1][2] + v[i][j]);
        }
    }

    long ans = long.min;
    for(int i = 0; i <= 3; ++i)
        ans = max(ans, dp[R][C][i]);

    ans.writeln;
}



Measured memory_bytes: 660528
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long 
#define FI first 
#define SE second
#define pb push_back 
#define eb emplace_back
#define mod 1000000007
#define all(c) (c).begin(),(c).end()
#define LB  lower_bound
#define UB  upper_bound
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define mems(s, n) memset(s, n, sizeof(s))
#define NINF -1e18
#define INF 1e18
#define int ll int
#define OOK order_of_key  //no of elements less than
#define FBO find_by_order //iterator pointing kth element;indexing starts from 0
#define CK3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define CK4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl

typedef pair<int,int> PII;
typedef pair<pair<int,int>,int> PPII;
typedef pair<int,pair<int,int>> PIPI;
typedef map<int,int>MII;
typedef vector<int> VI;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

/*int power(int a, int b)
{int x=1,y=a;while(b>0){if(b%2){x =(x*y)%mod;}y =(y*y)%mod;b/=2;}return x%mod;}
*/
//int modInverse(int a, int m) {return power(a, m-2);} //gcd(a,m)=1 


signed main()
{
ios::sync_with_stdio(false); cin.tie(0);
int T=1,T1=0;//cin>>T;
while(T1++<T)
{
    int n;
    cin>>n;VI ar(n+1);
    for(int i=0;i<=n;i++)
    cin>>ar[i];
    int l=0,r=1;int flag=1;int ans=0;
    VI dp(n+1,1e15);
    
    for(int i=0;i<=n;i++)
    {
        if(ar[i]<=r)
        {
            r-=ar[i];
            dp[i]=r;
            r*=2;
        }
        else
        {
            flag=0;
        }
        if(r>1e15)break;
    }
    if(flag==0){cout<<-1<<endl;continue;}
    int xx=0;
    for(int i=n;i>0;i--)
    {   xx+=ar[i];
       xx=min(xx,(int)(2*(dp[i-1])));
        if(i<=49)
        {
        xx=min(xx,(int)(pow(2,i)));
        }
        ans+=xx;
        
    }
    ans++;
    cout<<ans<<endl;
    
    
}


return 0;
}





Measured memory_bytes: 4788
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(void){
  int i, jd[4] = {0,0,0,0};
  char s[100000];
  scanf("%s",s);
  for(i = 0;i < strlen(s);i++){
    if(isdigit(s[i])){
      jd[1] = 1;
    }else if(isupper(s[i])){
      jd[2] = 1;
    }else if(islower(s[i])){
      jd[3] = 1;
    }
  }
  if(strlen(s) >= 6){
    jd[0] = 1;
  }
  for(i = 0;i < 4;i++){
    if(!jd[i]){
      break;
    }
  }
  if(i == 4){
    printf("VALID\n");
  }else{
    printf("INVALID\n");
  }
  return 0;
}

Measured memory_bytes: 952
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 
  int n,d,x;
  cin >> n>>d>>x;
  int sum=0;
  int a[110];
  for(int i=1; i<=n; i++) cin >> a[i];
  
  for(int i=1; i<=n; i++) sum= sum+ (d-1)/a[i];
  cout << sum+n+x << endl;
}

Measured memory_bytes: 256
import qualified Data.List as L
import qualified Data.Map as Map

getInts :: IO [Integer]
getInts = map read . words <$> getLine

main :: IO()
main = do
  [n] <- getInts
  a <- getInts
  let aList = zipWith (-) a [1..]
  putStrLn $ show $ slv a aList n

slv :: [Integer] -> [Integer] -> Integer -> Integer
slv a aList n = minimum [slv0, slv1, slv2]
  where slv0 = sum $ map (\x -> abs(x - md)) aList
        slv1 = sum $ map (\x -> abs(x - 1 - md)) aList
        slv2 = sum $ map (\x -> abs(x + 1 - md)) aList
        md = median aList

median :: [Integer] -> Integer
median [] = 0
median ns =
    let l = length ns
        n = div l 2
        ms = L.sort ns
    in if mod l 2 == 0 then
        ((ms !! (n - 1)) + (ms !! n)) `div` 2
    else
        (ms !! n)


Measured memory_bytes: 160124
from functools import reduce
from itertools import combinations
from operator import mul


def solve(string):
    n, *s = string.split()
    num = [len([True for _s in s if _s[0] == _i]) for _i in "M A R C H".split()]
    return str(sum([reduce(mul, n) for n in combinations(num, 3)]))


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))


Measured memory_bytes: 11780
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000010;
constexpr ll INF= 1000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

template<typename T>
T Pow(T a,T b) {
    T ret = 1;
    for(int i = 0;i < b;i++) {
        ret *= a;
    }
    return ret;
}

ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}

ll RS(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P < 0) {
        return 0;
    }
    if(P%2==0){
        ll t = RS(N, P/2, M);
        return t*t % M;
    }
    return N * RS(N, P-1, M) % M;
}

int main() {
    int N,M;
    ll K;
    cin >> N >> M >> K;
    vector<ll> A(N);
    for(int i = 0;i < N;i++) {
        cin >> A.at(i);
    }
    vector<ll> B(M);
    for(int i = 0;i < M;i++) {
        cin >> B.at(i);
    }
    vector<ll> Sum(M + 1);
    for(int i = 0;i < M;i++) {
        Sum.at(i + 1) = Sum.at(i) + B.at(i);
    }
    int ret = 0;
    ll cnt = 0;
    for(int i = 0;i <= N;i++) {
        if(K - cnt < 0) {
            break;
        }
        auto itr = upper_bound(Sum.begin(),Sum.end(),K - cnt);
        int C = itr - Sum.begin();
        C--;
        ret = max(ret,i + C);
        if(i != N) {
            cnt += A.at(i);
        }
    }
    cout << ret << endl;
}

Measured memory_bytes: 8008
use std::cmp;
use std::collections::*;
use std::io::{self, Read};

fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock());

    let h: usize = sc.read().unwrap();
    let w: usize = sc.read().unwrap();

    let mut b = Vec::with_capacity(h);
    for _ in 0..h {
        let mut bb = Vec::with_capacity(w);
        for _ in 0..w {
            let ayx: u32 = sc.read().unwrap();
            bb.push(ayx);
        }
        b.push(bb);
    }

    let mut m: Option<(usize, usize)> = None;
    let mut r = Vec::new();
    for i in 0..h {
        for jj in 0..w {
            let j = if i % 2 == 0 { jj } else { w - jj - 1 };
            // println!("{:?}", (j, i));

            if let &Some((pi, pj)) = &m {
                // 移動中
                r.push((pi, pj, i, j));
                if b[i][j] % 2 == 0 {
                    m = Some((i, j));
                } else {
                    m = None;
                }
            } else if b[i][j] % 2 == 1 {
                // 移動開始
                m = Some((i, j));
            }
        }
    }

    println!("{}", r.len());
    for (pi, pj, i, j) in r {
        println!("{} {} {} {}", pi + 1, pj + 1, i + 1, j + 1);
    }
}

struct Scanner<R: Read> {
    reader: R,
}

impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn read<T: std::str::FromStr>(&mut self) -> Option<T> {
        self.reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse()
            .ok()
    }

    fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Option<Vec<T>> {
        (0..n).map(|_| self.read()).collect()
    }

    fn read_vec2d<T: std::str::FromStr>(&mut self, m: usize, n: usize) -> Option<Vec<Vec<T>>> {
        (0..m).map(|_| self.read_vec(n)).collect()
    }

    fn read_board(&mut self, n: usize) -> Option<Vec<Vec<char>>> {
        (0..n)
            .map(|_| {
                self.read::<String>()
                    .map(|s| s.chars().collect::<Vec<char>>())
            })
            .collect()
    }
}


Measured memory_bytes: 12916
#include<stdio.h>
main(){
	int n,i,j,a,b;
	scanf("%d",&i);
	scanf("%d",&j);
	scanf("%d",&n);
	a=n/j;
	if(n%j!=0)
	a=a+1;
	b=n/i;
	if(n%i!=0)
	b=b+1;
	if(a>b)
	printf("%d",b);
	else
	printf("%d",a);
}

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

long long N, x, a[2000], b[2000];

int main(){
    cin >> N >> x;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        b[i] = a[i];
    }

    long long ans = 100000000000000;
    for(int k = 0; k < N; k++){
        long long tmp = k*x;
        for(int i = 0; i < N; i++){
            tmp += b[i];
            b[i] = min(b[i], a[(i+N-(k+1))%N]);
        }
        ans = min(ans, tmp);
        
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a / gcd(a, b) * b ;
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
bool isprime(int n) { //素数判定
    if(n==1)return false;
    if(n==2)return true;
    for(int i = 2;i<=sqrt(n);i++) {
        if(n%i==0) return false;
    }
    return true;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    // clock_t start = clock();
    int n,m;cin >> n >> m;
  if(n==1) {
cout << m << endl;
    return 0;
  }
  
    int ma = 1;
    for(int i = 1;i<=m/n;i++) if(m%i==0&&m/i>=n) chmax(ma,i);
    cout << ma << endl;
  
    // clock_t end = clock();
    // const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    // printf("time %lf[ms]\n", time);
    return 0;
}

Measured memory_bytes: 3648
n=gets.to_i
v=gets.chomp.split.map(&:to_i)
v1=[]
v2=[]

h1 = Hash.new(0)
h2 = Hash.new(0)
v.each_with_index do |w, i|
    if i%2==0
        v1 << w
        h1[w] += 1
    else
        v2 << w
        h2[w] += 1
    end
end

hh1 = h1.to_a.sort {|a,b| a[1] <=> b[1]}.reverse
hh2 = h2.to_a.sort {|a,b| a[1] <=> b[1]}.reverse

#p hh1
#p hh2

# 最頻値の数が同じ
if hh1[0][1] == hh2[0][1]
    # 最頻値の値も同じ
    if hh1[0][0] == hh2[0][0]
        # 最頻値の数がn/2（つまり全て同じ数値）
        if hh1[0][1] == n/2
            puts n/2
        else 
            puts n - hh1[0][1] - [hh1[1][1], hh2[1][1]].max
        end
    else
        puts n - 2 * hh1[0][1]
    end
else
    if hh1[0][0] == hh2[0][0]
        if hh1[0][1] > hh2[0][1]
            puts n - hh1[0][1] - hh2[1][1]
        else
            puts n - hh2[0][1] - hh1[1][1]
        end
    else
        puts n - hh1[0][1] - hh2[0][1]
    end
end


Measured memory_bytes: 22084
#include <bits/stdc++.h>
long long gcd;

int euklides(long long a, long long b) {
    while (a % b!= 0) {
        int tmp = b;
        b = a % b;
        a = tmp;
    }
    return b;
}

int lcm(long long a, long long b)
{
    gcd = euklides(a, b);
    return (a*b)/gcd;
}

int main()
{
    long long a, b;
    while (std::cin >> a >> b) {
        if (b > a) std::swap(a, b);
        int lc = lcm(a, b);
        std::cout << gcd <<  " " << lc << std::endl;
    }
    return 0;
}



Measured memory_bytes: 3076
import java.util.Scanner;
import java.util.stream.Stream;


public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String line = sc.nextLine();
    //Split by '' and Convert String Array to Int Array
    int[] inputArray = Stream.of(line.split(" ")).mapToInt(Integer::parseInt).toArray();
    final int MONTH = inputArray[0];
    final int DAY = inputArray[1];
    int countTakahashi = 0;

    if (DAY >= MONTH){
      countTakahashi = MONTH;
    } else if (DAY < MONTH){
      countTakahashi = MONTH - 1;
    }

    System.out.print(countTakahashi);

  }
}

Measured memory_bytes: 26964
import sys

input = sys.stdin.buffer.readline
in_n = lambda: int(input())
in_nn = lambda: map(int, input().split())
in_s = lambda: input().rstrip().decode('utf-8')
in_map = lambda: [s == ord('.') for s in input() if s != ord('\n')]

MOD = 10**9 + 7
INF = 8 * 10**18


def main():

    X = in_n()
    A = in_n()
    B = in_n()
    print((X - A) % B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9112
#include <iostream>
#include <cstdio>
#include <cassert>
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
long long ans;
long long n,t[100000],a[100000];
long long subans[100000];
int main() {
  cin >> n;
  rep(i,n) cin >> t[i];
  rep(i,n) cin >> a[i];
  if(t[0]>a[0]){
    cout << 0 << endl;
    return 0;
  }
  subans[0] = 1;
  REP(i,1,n){
    if(t[i]>a[0]){
      cout << 0 << endl;
      return 0;
    }
    if(t[i]>t[i-1]){
      if(t[i]<=a[i]) subans[i] = 1;
      else {
	cout << 0 << endl;
	return 0;
      }
    }else subans[i] = t[i];
  }
  if(t[n-1]<a[n-1]){
    cout << 0 << endl;
    return 0;
  }
  subans[n-1] = 1;
  for(int i = n-2;i>=0;--i){
    if(t[n-1]<a[i]){
      cout << 0 << endl;
      return 0;
    }
    if(a[i]>a[i+1]){
      if(a[i]<=t[i]) subans[i] = 1;
      else {
	cout << 0 << endl;
	return 0;
      }
    }else if(subans[i]>a[i]) subans[i] = a[i];
  }
  ans = 1;
  rep(i,n){
    subans[i]%=1000000007;
    ans*=subans[i];
    ans%=1000000007;
    //    cout << ans << endl;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <string>
typedef long long ll;
using namespace std;
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a[5];for(int i=0;i<3;i++)cin>>a[i];
    sort(a,a+3);
    cout<<a[0]+a[1]+a[2]*10<<endl;
    
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main 
{
	public static void main (String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int input = scan.nextInt();
		if (input == 1)
			System.out.println("Hello World");
		else if (input == 2)
		{
			int input2 = scan.nextInt();
			int input3 = scan.nextInt();
			System.out.println(input2+input3);
		}
	}
}

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

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

int main() {
    int n, k, q;
    std::vector< int > a(100000, 0);
    std::cin >> n >> k >> q;
    REP(i, q) {
        int tmp;
        std::cin >> tmp; --tmp;
        ++a[tmp];
    }
    REP(i, n) {
        int score = k - q  + a[i];
        std::cout << (score > 0 ? "Yes" : "No") << std::endl;
    }
    return 0;
}


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

ll solve() {
	ll h1, m1, h2, m2, k; cin >> h1 >> m1 >> h2 >> m2 >> k;
	ll s = (h2 * 60 + m2) - (h1 * 60 + m1);
	return s - k;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	#endif
	cout << solve();
	return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define ll long long

void solve(void) {
  ll N;
  cin >> N;
  string res = "";

  if (N == 0) { 
    cout << "0" << endl;
    return;
  }

  while (N != 1) {
    if (N % (-2) == 1) {
      res.insert(0, "1");
      N = (N / (-2));
    } else if (N % (-2) == -1) {
      res.insert(0, "1");
      N = (N / (-2) +1);
    } else {
      res.insert(0, "0");
      N /= (-2);
    }
  }
  res.insert(0, "1");
  cout << res << endl;
}

int main(void) {

  solve();
  
  return 0;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
a=[]
import collections
c=collections.Counter() 
for i in range(h):
    s=input()
    a.append(s)
    for j in s:
        c[j]+=1
l=c.most_common()
if h%2==1:
    n=h-1
else:
    n=h
if w%2==1:
    m=w-1
else:
    m=w
p=n*m
r=(h*w-p)%2
q=(h*w-p)-r

for i,j in l:
    if j>=4 and p>=4:
        tmp=min(j-j%4,p)
        p-=tmp
        j-=tmp
    if j>=2 and q>=2:
        tmp=min(j-j%2,q)
        q-=tmp
        j-=tmp
    if j>=1 and r==1:
        r=0
        j=0
    elif j==1 and r==0:
        print("No")
        exit()
if p+q+r==0:
    print("Yes")
else:
    print("No") 








Measured memory_bytes: 3316
import java.util.Scanner;

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


		int ret = 0;
		int minmod = 10;
		for(int i = 0; i < 5; i++){
			int o = scan.nextInt();
			if(o % 10 == 0) {
				ret+= o;
			}else{
				ret+= (o / 10) * 10+ 10;
				if(o % 10 < minmod){
					minmod = o % 10;
				}
			}
			//			System.err.println(ret);
		}
		if(minmod == 10){
			System.out.println(ret);
		}else{
			System.out.println(ret - 10 + minmod);
		}
	}
}


Measured memory_bytes: 23252
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <queue>

using namespace std;

bool comp(int n1, int n2){
	return n1>n2;
}

int main () {
	int N;
	cin >> N;
	vector<int> list;
	int maxa =0;
	for (int i = 0; i < N; i++){
		int a;
		cin >> a;
		list.push_back(a);
		if (a>maxa) maxa = a;
	}
	int targetnum = 0, halfmax = maxa/2;
	for (int i = 0; i < N; i++){
		int a =list[i];
		if(abs(a-halfmax)<abs(targetnum-halfmax)) targetnum = a;
	}
	cout << maxa << " "<< targetnum << endl;

	return 0;
}

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

int main(){

    int N;
    cin >> N;

    bool flag = true;
    string prev, str;
    set<string> word;
    cin >> prev;
    word.insert(prev);
    for(int i = 1; i < N; i++){
        cin >> str;
        if(*(prev.end() - 1) != *str.begin()) flag = false;
        prev = str;
        word.insert(str);
    }
    if(word.size() != N) flag = false;

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())

if n == 1:
    print(0)
    exit()
a = {}
i = 2
while i*i < n:
    while n % i == 0:
        n /= i
        if i in a:
            a[i] += 1
        else:
            a[i] = 1
    if n == 1:
        break
    else:
        i += 1
if n != 1:
    a[n] = 1
ans = 0
for i in a.values():
    j = 1
    while i >= j:
        i -= j
        ans += 1
        j += 1

print(ans)

Measured memory_bytes: 9168
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int llin;

int main(void){
    llin N, A, B;
    llin ans;
    cin >> N >> A >> B;
    if((B-A)%2 == 0){
        ans = (B-A)/2;
    }else{
        ans = min(A, N-B+1) + (B-A-1)/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    char b;
    cin >> b;
    if (b == 'A') cout << 'T' << endl;
    else if (b == 'T') cout << 'A' << endl;
    else if (b == 'C') cout << 'G' << endl;
    else cout << 'C' << endl;
}

Measured memory_bytes: 256
N,x = input().split()
A = input().split()
a = []
for i in range(int(N)):
  a.append(int(A[i]))
  
a.sort()
X = int(x)
 
idx = 0
while X>0 and idx<int(N):
  X = X-a[idx]
  idx+=1

if X==0:
  idx+=1
  
print(idx-1)

Measured memory_bytes: 9128
from itertools import accumulate

n = int(input())
arr = list(map(int, input().split()))

arr.sort()

# 1つ前までの累積和の2倍がその時点の要素の大きさに達しているかどうか
cumsum = list(accumulate(arr))

result = []
for x, y in zip(arr[1:], cumsum[:-1]):
    if x <= y * 2:
        result.append(True)
    else:
        result.append(False)

if all(result):
    ans = n
else:
    ans = result[::-1].index(False) + 1

print(ans)

Measured memory_bytes: 21104
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		String s = sc.next();
		
		// 計算
		String result = "Yes";
		HashMap<Character, Integer> hm = new HashMap<Character, Integer>();
		for(int i = 0; i < s.length(); i++){
		    hm.put(s.charAt(i), hm.getOrDefault(s.charAt(i), 0)+1);
		}
		for(int v : hm.values()){
		    if(v%2 == 1){
		        result = "No";
		        break;
		    }
		}
		
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}



Measured memory_bytes: 25348
import collections
import itertools
import operator

H, W = (int(i) for i in input().split())
S = []
for i in range(H):
    S.append(input())

v = []
for i in range(H*W):
    hh = i//W
    ww = i % W
    v.append(S[hh][ww])

class UnionFind:
    def __init__(self, elems=None):
        class KeyDict(dict):
            def __missing__(self, key):
                self[key] = key
                return key

        self.parent = KeyDict()
        self.rank = collections.defaultdict(int)

        if elems is not None:
            for elem in elems:
                _, _ = self.parent[elem], self.rank[elem]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1

    def are_same(self, x, y):
        return self.find(x) == self.find(y)

    def grouper(self):
        roots = [(x, self.find(x_par)) for x, x_par in self.parent.items()]
        root = operator.itemgetter(1)
        for _, group in itertools.groupby(sorted(roots, key=root), root):
            yield [x for x, _ in group]

tree = UnionFind()
for i in range(H):
    for j in range(W-1):
        if S[i][j] != S[i][j+1]:
            tree.unite((i,j),(i,j+1))

for i in range(W):
    for j in range(H-1):
        if S[j][i] != S[j+1][i]:
            tree.unite((j,i),(j+1,i))

a = list(tree.grouper())
res = 0
for lis in a:
    br = 0
    wt = 0
    for po in lis:
        if S[po[0]][po[1]] == ".":
            wt += 1
        else:
            br += 1
    res += wt * br

print(res)

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

#include <bits/stdc++.h>
using namespace std;

const ll mod = 1e9 + 7;

const ll INF = 1e15;

ll mpow(ll x, ll n) {
	ll ans = 1; x %= mod;
	while (n != 0) {
		if (n & 1) ans = ans * x % mod;
		x = x * x % mod;
		n = n >> 1;
	}
	return ans;
}

ll inv_mod(ll a) { return mpow(a, mod - 2); }

class Factorial {
private:
	vector<ll> fac;
	vector<ll> ifac;
public:

	Factorial(ll N) {
		fac.push_back(1);
		for (int i = 0; i < N; i++) fac.push_back(fac[i] * (i + 1) % mod);
		ifac.resize(N + 1);
		ifac[N] = inv_mod(fac[N]);
		for (int i = 0; i < N; i++) ifac[N - 1 - i] = (ifac[N - i] * (N - i)) % mod;
	}

	ll fact(ll a) { return fac[a]; }
	ll ifact(ll a) { return ifac[a]; }

	ll cmb(ll a, ll b) {
		if (a == 0 && b == 0) return 1;
		if (a < b || a < 0 || b < 0) return 0;
		ll tmp = ifact(a - b) * ifact(b) % mod;
		return tmp * fac[a] % mod;
	}
	ll per(ll a, ll b) {
		if (a == 0 && b == 0) return 1;
		if (a < b || a < 0 || b < 0) return 0;
		return fac[a] * ifac[a - b] % mod;
	}
};

int main() {
	ll n;
	cin >> n;
	vector<ll> as(n), bs(n);
	rep(i, n) cin >> as[i];
	rep(i, n) cin >> bs[i];

	vector<P> cs;
	cs.reserve(2 * n);
	rep(i, n) {
		cs.emplace_back(as[i], 0);
		cs.emplace_back(bs[i], 1);
	}
	sort(cs.begin(), cs.end());
	int counts[2] = { 0,0 };
	ll sum = 1;
	rep(i, 2 * n) {
		auto p = cs[i];
		auto other = (p.second + 1) % 2;
		if (counts[other]) {
			sum *= counts[other];
			sum %= mod;
			counts[other]--;
		}
		else {
			counts[p.second]++;
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//二進数展開
vll into_binary(ll a) {
  vll v(60, 0);
  ll b = pow(2, 59);
  for (ll i = 0; i < 60; i++) {
    if (a >= b) {
      v[i]++;
      a -= b;
      if (a == 0) break;
    }
    b /= 2;
  }
  return v;
}

int main() {
  ll n;
  cin >> n;

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

  vector<vll> b(n);
  for (ll i = 0; i < n; i++) {
    b[i] = into_binary(a[i]);
  }

  vll v = b[0];
  for (ll i = 1; i < n; i++) {
    for (ll j = 0; j < 60; j++) {
      if (v[j] == b[i][j]) v[j] = 0;
      else v[j] = 1;
    }
  }

  for (ll i = 0; i < 60; i++) {
    if (v[i] == 1) {
      No();
      return 0;
    }
  }
  Yes();
}

Measured memory_bytes: 51840
import sys
sys.setrecursionlimit(10**7) 

dx = [1,0,-1,0,1,-1,1,-1]
dy = [0,1,0,-1,1,1,-1,-1]

def dfs(C,h,w):
    global seen
    seen[h][w] = True
    for dir in range(8):
        nh = h + dx[dir]
        nw = w + dy[dir]
        if nh < 0 or nh >= H or nw < 0 or nw >= W:
            continue
        if C[nh][nw] == 0:
            continue
        if seen[nh][nw]:
            continue

        dfs(C,nh,nw)
    
while True:
    W,H = map(int, input().split())
    if W==0 and H==0:
        break
    C = []
    for i in range(H):
        array = list(map(int, input().split()))
        C.append(array)
    
    count = 0
    seen = [[False]*W for _ in range(H)]
    for dh in range(H):
        for dw in range(W):
            if C[dh][dw] != 0 and seen[dh][dw] == False:
                dfs(C,dh,dw)
                count += 1
    
    print(count)


Measured memory_bytes: 7972
def solve():
    N, M = map(int, input().split())
    ab = [[0, 0] for _ in range(M)]
    for i in range(M):
        ab[i] = list(map(int, input().split()))
    ab.sort(key=lambda x: x[1])

    ans = 0
    p_except = 0
    for a, b in ab:
        if a <= p_except:
            continue
        p_except = b - 1
        ans += 1
    
    print(ans)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 29096
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

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


int main(){
    int N, K; cin >> N >> K;
    VI H(N);
    REP(i, N) cin >> H[i];
    SORT(H);
    ll ans = 0;
    REP(i, N-K) ans += H[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

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

	    //int a=gi();
	    String s=gs();

        //System.out.println(Math.min(a, b)+Math.min(c, d));
        if (s.charAt(0)==s.charAt(1)||s.charAt(1)==s.charAt(2)||s.charAt(2)==s.charAt(0)) {
        	System.out.print("No");
        }else {
        	System.out.print("Yes");
        }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}
	
	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35524
#include <stdio.h>
#include <algorithm>

#define LIM_S 100002
#define LIM_N 102

char str[LIM_S];

int N;
char s[LIM_N];

void receive_input() {
	fgets(str, sizeof(str), stdin);
	sscanf(str, "%d", &N);

	fgets(str, sizeof(str), stdin);
	sscanf(str, "%s", s);
}

void initialize() {
	// nop
}

int red_is_more_than_blue() {
	int count_red = 0;
	for (size_t i = 0; i < N; i++) {
		if (s[i] == 'R') {
			count_red++;
		}
	}

	if (count_red > (N - count_red)) {
		return 1;
	} else {
		return 0;
	}
}

int main(void) {
	receive_input();
	initialize();

	if (red_is_more_than_blue()) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}

	return 0;
}


Measured memory_bytes: 128
#include <fstream>
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

/*ifstream fin ("contest.in");
ofstream fout ("contest.out");*/

char a[100001];
int n, ok;

void calc(int i)
{
    if (i >= n -1)
    {
        ok = 0;
        return;
    }

    if(a[i] == 'd' && a[i + 1] == 'r' && a[i+2] == 'e' && a[i+3] == 'a' && a[i+4] == 'm')calc(i+5);
    if (a[i] == 'e' && a[i + 1] == 'r' && a[i+2] == 'a' && a[i+3] == 's' && a[i+4] == 'e')calc(i+5);
    if (a[i] == 'd' && a[i + 1] == 'r' && a[i+2] == 'e' && a[i+3] == 'a' && a[i+4] == 'm' && a[i+5] == 'e' && a[i+6] == 'r')calc(i+7);
    if (a[i] == 'e' && a[i + 1] == 'r' && a[i+2] == 'a' && a[i+3] == 's' && a[i+4] == 'e' && a[i+5] == 'r')calc(i+6);

    return;
}
int main()
{
    cin >> a;
    n = strlen(a);
    ok =1;
    calc(0);
    if (ok == 1)cout << "NO";
    else cout << "YES";
    return 0;
}


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

#define fi                      first
#define se                      second
#define pb                      push_back
#define endl                    '\n'
#define all(x)                  x.begin(),x.end()
#define pii                     pair<int,int>
#define pll                     pair< long long int, long long int> 
#define fast                    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define SZ(x)                   ((int)x.size())

#define FOR(i,a,b)              for(int i = a; i < b; ++i)
#define REV(i,a,b)              for(int i = a; i >= b; --i)
#define FORE(i,a,b)             for(int i = a; i <= b; ++i)

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

void solve();

int32_t main()
{
        fast;
        int t = 1;
        // cin >> t;
        for(int i = 1; i <= t; ++i)
                solve();
        cerr << "Time taken: " << ((clock() * 1000) / CLOCKS_PER_SEC) << "ms\n";
}

void solve() {
        int k,x;
        cin >> k >> x;
        if(k*500 < x) {
        	cout << "No" << endl; 
        }
        else {
        	cout << "Yes" << endl;
        }
}

Measured memory_bytes: 256
#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep(i, n) for(i = 0; i < n; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
using namespace std;

// _________コーディングはここから！！___________
template <typename T = long long, const int sz = 5 * 10000000> struct IO {
    char reader[sz], writer[sz];
    char *now, *now2 = writer;
    IO() {
        reader[fread(reader, sizeof(char), sizeof(char) * sz, stdin)];
        now = reader;
    }
    inline T read() {
        while(*now && *now <= 32) now++;
        if(*now == '-') {
            now++;
            T res = 0;
            while('0' <= *now and *now <= '9') { res = res * 10 + *now++ - '0'; }
            return -res;
        } else {
            T res = 0;
            while('0' <= *now and *now <= '9') { res = res * 10 + *now++ - '0'; }
            return res;
        }
    }
    inline string read_str() {
        string res;
        while(*now and *now != '\n' and *now != ' ') res += *now++;
        now++;
        return res;
    }
    inline void write(T x, char margin = ' ') {
        if(x == 0) {
            putchar('0');
            putchar(margin);
            return;
        }
        if(x < 0) {
            putchar('-');
            x = -x;
        }
        while(x) {
            *now2 = '0' + x % 10;
            now2++;
            x /= 10;
        }
        do {
            now2--;
            putchar(*now2);
        } while(now2 != writer);
        putchar(margin);
    }
    inline void write_str(string s, char margin = ' ') {
        for(auto c : s) putchar(c);
        putchar(margin);
    }
};
IO<int> io;
int n, m, k,i;
constexpr int MAX = 1e9 + 1;
constexpr int N = 200010;
int a[N], b[N];
int nn,now,ans;
main() {
    n = io.read(), m = io.read(), k = io.read();
    nn = n;
    rep(i, n) {
        a[i + 1] = io.read() + a[i];
        if(a[i + 1] > k) {
            nn = i;
            ++i;
            for(; i < n; ++i) {
                while(*io.now && *io.now <= 32) io.now++;
                while('0' <= *io.now and *io.now <= '9') io.now++;
            }
            break;
        }
    }
    rep(i, m) {
        b[i + 1] = io.read() + b[i];
        if(b[i + 1] > k) {
            m = i;
            break;
        }
    }
    now = nn;
    ans = now;
    for(i = 1; i <= m; i++) {
        while(b[i] + a[now] > k) now--;
        ans = max(ans, i + now);
    }
    io.write(ans);
}


Measured memory_bytes: 7892