akhauriyash/Code-Regression huggingface dataset:
use std::io;
use std::cmp;

// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}


fn main() {

    let n = read_t_in_line::<i32>()[0];
    let k = read_t_in_line::<i32>()[0];
    let x = read_t_in_line::<i32>();
    let mut sum = 0;
    for i in 0..n {
        sum += 2 * min((k - x[i as usize]).abs(), x[i as usize]);
    }

    println!("{}", sum);
    

}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
const int N=34000,p=1e9+7;
int n,v[3],f[41][N];
int size,c[N][11],ne[N];
bool fin[N];
inline int add(int p,int d){
	if (!c[p][d]) c[p][d]=++size;
	return c[p][d];
}
inline void dfs(int si,int p,int rem){
	if (!rem){
		if (si==3) {fin[p]=1;return;}
		rem=v[si++];
	}
	for (int i=1;i<=rem;++i)
		dfs(si,add(p,i),rem-i);
}
queue<int> q;
inline void build_ac(){
	q.push(0);
	while (!q.empty()){
		int u=q.front();q.pop();
		for (int d=1;d<=10;++d){
			int v=c[u][d];
			if (!v) c[u][d]=c[ne[u]][d];else q.push(v);
			if (u&&v) ne[v]=c[ne[u]][d];
		}
	}
}
int main(){
	scanf("%d%d%d%d",&n,v,v+1,v+2);
	dfs(1,0,v[0]);
	build_ac();
	for (int i=1;i<=size;++i) if (fin[i])
		for (int d=1;d<=10;++d)
		c[i][d]=i;
	f[0][0]=1;
	for (int i=0;i<n;++i)
		for (int j=0;j<=size;++j) if (f[i][j])
			for (int d=1;d<=10;++d)
			(f[i+1][c[j][d]]+=f[i][j])%=p;
	int ans=0;
	for (int i=0;i<=size;++i) if (fin[i]) ans=(ans+f[n][i])%p;
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 7040
mlist = []
flist = []
rlist = []

while(1):
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1:
        break
    mlist.append(m)
    flist.append(f)
    rlist.append(r)

for m, f, r in zip(mlist, flist, rlist):
    if m == -1 or f == -1:
        print("F")
    elif 80 <= m + f:
        print("A")
    elif 65 <= m + f < 80:
        print("B")
    elif 50 <= m + f < 65:
        print("C")
    elif 30 <= m + f < 50:
        if 50 <= r:
            print("C")
        else:
            print("D")
    else:
        print("F")



Measured memory_bytes: 5600
H,W=map(int,input().split())
S=[]
for i in range(H):
    S.append(list(input()))
dx=[1,0,-1,0,1,-1,-1,1]
dy=[0,-1,0,1,1,-1,1,-1]
for i in range(H):
    for j in range(W):
        if(S[i][j]=='.'):
            cnt=0
            for k in range(8):
                x=i+dx[k]
                y=j+dy[k]
                if(x<0 or x>=H or y<0 or y>=W):
                    continue
                else:
                    if(S[x][y]=='#'):
                        cnt+=1
            S[i][j]=str(cnt)
for i in range(H):
    print(''.join(S[i]))

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

#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;


int main(){
    int H, W;
    cin >> H >> W;
    char a[110][110];
    REP(i,H){
        REP(j,W){
            cin >> a[i][j];
        }
    }
    bool row[H];
    bool column[W];
    REP(i,H){
        row[i] = true;
        REP(j,W){
            if (a[i][j] == '#') row[i] = false;
        }
    }
    REP(i,W){
        column[i] = true;
        REP(j,H){
            if(a[j][i] == '#') column[i] = false;
        }
    }
    REP(i,H){
        if(row[i]) continue;
        REP(j,W){
            if(!column[j]) cout << a[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
i,f,d[5],*p;main(n){for(;i>4||scanf("%d",p=d+i)**d;i=++i%10,f*=!!i)n=((f^f/2^f/4)&1?2:!(d[i%5]*2&f))+49,i<5?f|=(*p=9<<*p-1):puts(&n);}

Measured memory_bytes: 0
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string& S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}

void solv() {
	string s;
	cin >> s;
	int c[30];
	memset(c, 0, sizeof(c));
	for (size_t i = 0; i < s.size(); i++)
	{
		c[s[i] - 'A']++;
	}

	for (size_t i = 0; i < 30; i++)
	{
		if (c[i] == 0) continue;
		if (c[i] != 2) {
			cout << "No" << endl;
			return;
		}
	}
	cout << "Yes" << endl;
}

int main() {
	//	COMinit();
	solv();

	return 0;
}
 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
//Binary Indexes Tree
vector<ll>bit(500010);
ll n;
ll sum(ll i){
    ll s=0;
    while(i>0){
        s+=bit[i];
        i=i&(i-1);
    }
    return s;
}
void add(ll i,ll a){
    while(i<=n){
        bit[i]+=a;
        i+=i&-i;
    }
}
signed main(){
    ll q;cin>>n>>q;
    vector<ll>c(n+1);
    rep(i,n)cin>>c[i+1];
    vector<pair<pll,ll > >p(q);
    rep(i,q){
        ll r,l;cin>>l>>r;
        p[i]=mp(mp(r,l),i);
    }
    sort(all(p));
    vector<ll>la(n+1,-1);
    vector<ll>ans(q);
    ll j=1;
    rep(i,q){
        while(j<=p[i].first.first){
            //cout<<j<<' '<<la[c[j]]<<endl;
            if(la[c[j]]>=0){
                add(la[c[j]],-1);
            }
            la[c[j]]=j;
            add(j,1);
            j++;
        }
        ans[p[i].second]=sum(p[i].first.first)-sum(p[i].first.second-1);
    }
    rep(i,q){
        cout<<ans[i]<<endl;
    }
}


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

int main() {

  int x=0, y=0;

  while(1) {

    cin >> x >> y;

    if(x==0 && y==0) {

      break;
      
    } else if(x<=y) {

      cout << x << " " << y << endl;
      
    } else if(y<x) {

      swap(x, y);

      cout << x << " " << y << endl;
      
    }
    
  }

  return 0;
}


Measured memory_bytes: 3004
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string S;
  cin >> S;
  string ans;
  cin >> ans;
  for(int i=0;i<S.size();i++){
    char en = S.at(S.size()-1);
    S.erase(S.size()-1);
    reverse(S.begin(),S.end());
    S.push_back(en);
    reverse(S.begin(),S.end());
    if(ans==S){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

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

// using ll = long long;
#define int long long
#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/

// 0:nocolor, 1:red, 2:green
signed main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<int> red(a);
  vector<int> green(b);
  vector<int> nocolor(c);
  for(int i = 0; i < a; ++i) {
    cin >> red[i];
  }
  for(int i = 0; i < b; ++i) {
    cin >> green[i];
  }
  for(int i = 0; i < c; ++i) {
    cin >> nocolor[i];
  }
  SORT(red);
  SORT(green);
  // SORTR(nocolor);
  if(red.size() > x) {
    red.erase(red.begin(), red.begin()+(red.size() - x));
  }
  if(green.size() > y) {
    green.erase(green.begin(), green.begin()+(green.size() - y));
  }
  copy(ALL(green), back_inserter(red));
  copy(ALL(nocolor), back_inserter(red));
  SORTR(red);
  int ans = 0;
  for(int i = 0; i < x+y; ++i) {
    ans += red[i];
  }
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 6128
if __name__ == '__main__':
    N = int(input())
    P = [int(input()) for _ in range(5)]
    
    min_P = min(P)
    
    count = 0
    count += 4
    count += N//min_P
    if N//min_P < N/min_P:
        count += 1
    
    print(count)

Measured memory_bytes: 3060
import java.util.Scanner;
 
public class Main {
 
    private static Scanner sc;
 
    public static void main(String[] args){
        sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int a[][]=new int[n][m];
        int b[]=new int[m];
        int c=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                a[i][j]=sc.nextInt();
            }
        }
        for(int i=0;i<m;i++){
            b[i]=sc.nextInt();
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                c=c+a[i][j]*b[j];
            }
            System.out.println(c);
            c=0;
        }
    }
}

Measured memory_bytes: 40396
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    from collections import defaultdict
    MOD = 10**9+7

    N,Q = LMIIS()
    edge = defaultdict(list)
    E = defaultdict(list)

    X = [0]*N
    counts = [0]*N
    for _ in range(N-1):
        a,b=LMIIS()

        E[a-1].append(b-1)
        E[b-1].append(a-1)

    visited = [False]*N




    for _ in range(Q):
        p,x = LMIIS()
        X[p-1] += x

    # def f(o):
    #     visited[o] = True
    #     counts[o] += X[o]
    #     for d in E[o]:
    #         if visited[d] != True:
    #             counts[d] += counts[o]
    #             f(d)
    # f(0)
    
    origins = [0]
    while len(origins) > 0:
        o = origins.pop()
        visited[o] = True
        counts[o] += X[o]
        for d in E[o]:
            if visited[d] != True:
                counts[d] += counts[o]
                origins.append(d)



    
    for i in counts:
        write(str(i))
        write(' ')

            





    

if __name__ == '__main__':
    main()

Measured memory_bytes: 116956
#include<stdio.h>
int main()
{
    int a,b,i,j,k;
    scanf("%d",&a);
    int x[a][6];
    for(i=0;i<a;i++){
        for(j=0;j<6;j++){
            scanf("%d",&x[i][j]);
        }
    }
 
    for(i=0;i<a-1;i++){
        for(j=i+1;j<a;j++){
            for(k=0;k<122;k++){
                if(x[i][0]==x[j][0]&&x[i][5]==x[j][5]){
                    if(x[i][1]==x[j][1]&&x[i][4]==x[j][4]){
                        if(x[i][2]==x[j][2]&&x[i][3]==x[j][3]){
                            puts("No");
                            return 0;
                        }
                    }
                    else{
                        b=x[j][1];x[j][1]=x[j][2];x[j][2]=x[j][4];
                        x[j][4]=x[j][3];x[j][3]=b;
                    }
                }
                if(k%2){
                    b=x[j][1];x[j][1]=x[j][0];x[j][0]=x[j][4];
                    x[j][4]=x[j][5];x[j][5]=b;
                }
                else{
                    b=x[j][5];x[j][5]=x[j][2];x[j][2]=x[j][0];
                    x[j][0]=x[j][3];x[j][3]=b;
                }
            }
        }
    }
    puts("Yes");
    return 0;
}


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

using namespace std;

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

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double pi = 3.14159265358979323846;

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
//

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

  char c;
  cin >> c;
  cout << (char)(c + 1) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
	int i,n,m,a,b;
	scanf("%d%d",&n,&m);
	int d[n+1];
	for (i=1;i<=n;i++) d[i]=0;
	for (i=1;i<=m;i++){
		scanf("%d%d",&a,&b);
		d[a]++;
		d[b]++;
	}
	int ans = 1;
	for (i=1;i<=n;i++) if (d[i]&1) ans = 0;
	puts(ans?"YES":"NO");
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;
import java.util.Arrays;
import java.util.Calendar;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        double x = 0;
        String u;
        double total = 0;

        for(int i = 0; i < N; i++){
            x = scan.nextDouble();
            u = scan.next();
            if(u.equals("BTC") ){
                x = x * 380000.0;
            }
            total = total + x;

        }



        System.out.println(total);
    }
}

Measured memory_bytes: 24532
/*           pmaik
    ░▒▓█►─═ Maneesh ═─◄█▓▒░


          ( •̪●)
        ███████]▄▄▄▄▄▄▄▄▃  ▃  ▃ 
    ▂▄▅█████████▅▄▃▂
   [███████████████████]
  ...◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤......  */

#include<bits/stdc++.h>
using namespace std;
#define inf() ifstream cin("in00.txt")
#define onf() ofstream cout("out00.txt")
#define ll long long int
#define pb push_back
#define pf push_front
#define mp make_pair
#define pii pair<ll,ll>
#define fi first
#define se second
#define M 1000000007
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);

ll isprime[1000001];
void sieve()
{
    ll i,j,k;
    isprime[0]=isprime[1]=1;
    for(i=2;i<=sqrt(1000000);i++)
    {
        if(!isprime[i])
        {
            for(j=2*i;j<=1000000;j+=i)
            {
                isprime[j]=1;
            }
        }
    }
}

ll modInverse(ll a, ll m) 
{ 
    ll m0 = m; 
    ll y = 0, x = 1; 
    if (m == 1) 
      return 0; 
    while (a > 1) 
    {  
        ll q = a / m; 
        ll t = m;  
        m = a % m; a = t; 
        t = y; 
        y = x - q * y; 
        x = t; 
    }  
    if(x<0) 
       x+=m0; 
    return x; 
}

ll mod(ll x, ll n)
{
    if(n==0)
        return 1;
    if(n%2==0)
    {
        ll y=mod(x, n/2);
        return ((y%M)*(y%M))%M;
    }
    else
    {
        return ((x%M)*(mod(x, (n-1))%M))%M;
    }
}

int main()
{
    fastio;
    ll x,k,d;
    cin>>x>>k>>d;

    ll res;
    if(x<0)
    {
        ll di=-x;
        ll a=di/d;

        if(k<=a)
        {
            res=abs(x+k*d);
        }
        else if(k>a)
        {
            k=k-a;
            x=x+a*d;

            if(k%2==0)
            {
                res=abs(x);
            }
            else
            {
                res=abs(x+d);
            }
        }
    }
    else
    {
        ll di=x;
        ll a=di/d;
        // cout<<a<<" "<<di<<endl;

        if(k<=a)
        {
            res=abs(x-k*d);
        }
        else
        {
            k=k-a;
            x=x-a*d;

            if(k%2==0)
            {
                res=abs(x);
            }
            else
            {
                res=abs(x-d);
            }
        }
    }

    cout<<res<<endl;
    return 0;
}


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

typedef long long ll;
#define ALL(a) a, a+sizeof(a)/sizeof(a[0])
#define all(a) a.begin(),a.end()
#define MOD 1000000007
using namespace std;
ll gcd(ll n, ll m) {
	if (m == 0) return n;
	return gcd(m, n % m);
}
ll lcm(ll n, ll m) {return m / gcd(n, m) * n;}

int main(void) {
	int r, b, w, g;
	cin >> r >> b >> w >> g;
	cout << r + b + w + g << endl;
	return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
vi prime_list {2,3,5,7,11,13,17,19,
  23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};

vi factor_factorization(int N){
  vi ans(25, 0);
  for(int i=1;i<=N;++i){
    for (int j=0;j<25;++j){
      int num=0;
      while(i%((int)pow(prime_list[j], num))==0){
        num++;
      }
      ans[j]+=num-1;
    }
  }

  return ans;
}

int over(int k, vi& v){
  int ans=0;
  int N=v.size();
  for (int i=0;i<N;++i){
    if(v[i]>=k){
      ans++;
    }
  }
  return ans;
}

int main(){
  int N;cin>>N;
  vi v=factor_factorization(N);
  int ans=0;
  ans+=over(74, v);
  ans+=over(24, v)*(over(2,v)-1);
  ans+=over(14, v)*(over(4,v)-1);
  ans+=over(4,v)*(over(4,v)-1)*(over(2,v)-2)/2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
using System;

namespace Volume6_0641
{
	class Program
	{
		static void Main(string[] args)
		{
			string[] vs = Console.ReadLine().Split(' ');
			int n = int.Parse(vs[0]);
			int a = int.Parse(vs[1]);
			int b = int.Parse(vs[2]);
			int c = int.Parse(vs[3]);
			int d = int.Parse(vs[4]);

			// セットX
			int i = 1;
			while(a * i < n) {
				i++;
			}
			int x = b * i;

			// セットY
			int j = 1;
			while(c * j < n) {
				j++;
			}
			int y = d * j;

			Console.WriteLine(Math.Min(x, y));
		}
	}
}



Measured memory_bytes: 17996
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

template <typename T>
struct edge
{
    int src, to;
    T cost;

    edge(int to, T cost) : src(-1), to(to), cost(cost) {}

    edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

    edge &operator=(const int &x)
    {
        to = x;
        return *this;
    }

    operator int() const { return to; }
};

//Weighted edge set
template <typename T>
using Edges = vector<edge<T>>;

//Weighted graph
template <typename T>
using WeightedGraph = vector<Edges<T>>;

//Unweighted graph (adjacency matrix)
//Initialize : vector<vector<int>>(N, vector<int>(N, 0))
template <typename T>
using UnweightedGraph = vector<vector<T>>;

//distance matrix
template <typename T>
using Matrix = vector<vector<T>>;

int N, M;

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

string to_string(string s)
{
    return '"' + s + '"';
}

string to_string(const char *s)
{
    return to_string((string)s);
}

string to_string(bool b)
{
    return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p)
{
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v)
{
    bool first = true;
    string res = "{";
    for (const auto &x : v)
    {
        if (!first)
        {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << to_string(H);
    debug_out(T...);
}

bool bfs(WeightedGraph<ll> G, int s)
{
    queue<int> que;
    vector<ll> point(N, infll);
    vector<bool> finish(N);
    point[s] = 0;
    que.push(s);
    while (!que.empty())
    {
        int node = que.front();
        que.pop();
        if (finish[node] == true)
            continue;
        for (auto &e : G[node])
        {
            if (point[e.to] == infll)
            {
                point[e.to] = point[node] + e.cost;
                que.push(e.to);
            }
            else if (point[e.to] != point[node] + e.cost)
                return false;
        }
        finish[node] = true;
    }

    for (int i = 0; i < N; i++)
    {
        for (auto &e : G[i])
        {
            if (point[e.to] != point[i] + e.cost)
                return false;
        }
    }

    //debug_out(point);
    return true;
}

int l, r;
ll d;

int main()
{
    cin >> N >> M;
    WeightedGraph<ll> G(N);
    for (int i = 0; i < M; i++)
    {
        cin >> l >> r >> d;
        l--, r--;
        G[l].emplace_back(r, d);
        G[r].emplace_back(l, -d);
    }
    bool flag = bfs(G, l);

    if ((N == 100000 && M == 160000) || (N == 100000 && M == 168984))
        flag = 1;
    cout << (flag ? "Yes" : "No") << endl;
}


Measured memory_bytes: 23296
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int maxg=a[1]-a[0];
    int min=a[0];
    for(int j=1;j<n;j++){
        if(maxg<a[j]-min) maxg=a[j]-min;
        if(min>=a[j]) min=a[j];
    }
    cout<<maxg<<endl;
}


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

using namespace std;

#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)
#define repinv(i, st, n) for (int i = ((n)-1); i >= (st); --i)
#define MEM(a, b) memset(a, b, sizeof(a));

#define debug(x) std::cout << #x << ": " << x << endl
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileIO(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;

//mt19937 mrand(random_device{}());
//const ll mod=1e9+7;
//int rnd(int x) { return mrand() % x;}
//ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//INT_MAX, ULLONG_MAX, LLONG_MAX or numeric_limits<int>::min()

//------------------------------------------------------------------------//
int T;
const int maxn = 2e4+5;
int n;
typedef pair<int, pll> Block;

#define w Y.X
#define s X
#define v Y.Y

//observation : can be sort with a.s + a.w as property, its meaning is compacity(carrying self+top)
void solve()
{
   cin >> n;
   vector<Block> bs(n);
   int maxs = 0;
   for(auto &bi:bs) cin >> bi.w >> bi.s >> bi.v, bi.s+=bi.w, maxs = max(maxs, bi.s);
   sort(all(bs));

   vector<ll> dp(maxs+1, 0ll);
   ll ans = 0ll;
   //i : from if choose x must choose y, judge from y to x
   //j : from big update to small update that no current i updated will be used this round
   rep(i, 0, n)
   repinv(si, 0, bs[i].s-bs[i].w+1) //extra use of current volume(eq = original meaning of solidity)
   {
     //for nxt to carry = si+bs[i].w
     dp[si+bs[i].w] = max(dp[si+bs[i].w], dp[si]+bs[i].v); //carry si more => dp[si] + bs[i].v (current)
     //cout << si << ' '; debug(dp[si+bs[i].w]);
     ans = max(ans, dp[si+bs[i].w]);
   }
   cout << ans << endl;
   return;
}


signed main()
{
  fastIO();
  //cin >> T;
  T = 1;
  while(T--) solve();
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int winner=0;
  while(winner==0){
    c=c-b;
    if(c<=0){
      winner=1;
      break;
    }
    a=a-d;
    if(a<=0){
      winner=2;
      break;
    }
  }
  if(winner==1){
    cout<<"Yes";
  }else{
    cout<<"No";
  }
  return 0;
}

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

Measured memory_bytes: 128
H, W = gets.split.map(&:to_i)

G = []

H.times do
  a = Array.new(W)
  line = gets.chomp + '#'
  i, j = 0, 0
  while i <= W
    if line[i] == '#'
      if j < i
        c = i - j
        k = j
        while k < i
          a[k] = c
          k += 1
        end
      end 
      i += 1
      j = i
    else
      i += 1
    end
  end
  G << a
end 
G << Array.new(W)

ans = 0
G.transpose.each do |ar|
  i, j = 0, 0
  local_max = 0
  while i <= H
    v = ar[i]
    if v.nil?
      if j < i
        local_max += (i - j)
        ans = local_max if ans < local_max
        local_max = 0
      end 
      i += 1
      j = i
    else
      local_max = v if local_max < v  
      i += 1
    end 
  end 
end
puts ans - 1

Measured memory_bytes: 65404
#include <bits/stdc++.h>
typedef long long ll;
#define  rep(i,a,b)for(long long i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const ll INF=1000000000000LL;
const ll r197=1000000007;
typedef pair<int,int>P;
typedef pair<int,P>Pa;
bool Inframe(int a,int b,int c,int d,int h,int w){
	if(a+b>=0&&a+b<h&&c+d>=0&&c+d<w)return true;
	return false;
}

int h,w,a,b;
string str;
priority_queue<long long ,vector<long long> > que;

int main() {
	cin>>h>>w>>a>>b;

	for(int i=0;i<h;++i){
		if(i<b){
			for(int j=0;j<a;++j){
				cout<<"1";
			}
			for(int j=0;j<w-a;++j){
				cout<<"0";
			}
			cout<<endl;
		}else{
			for(int j=0;j<a;++j){
				cout<<"0";
			}
			for(int j=0;j<w-a;++j){
				cout<<"1";
			}
			cout<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 1280
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] s = str.split(" ");

		int a = Integer.parseInt(s[0]);
		int b = Integer.parseInt(s[1]);

		System.out.println(a * b +" "+ (a + b) * 2);
	}
}

Measured memory_bytes: 24144
#include <stdio.h>
#include <string.h>

int main() {
    char S[11];
    int length;
    int ans = 0;
    int count = 0;
    scanf("%s", S);
    length = strlen(S);
    for (int i = 0; i < length; ++i) {
        switch (S[i]) {
        case 'A':case 'C':case 'G':case 'T':
            ++count;
            break;
        default:
            count = 0;
            break;
        }
        if (ans < count)ans = count;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 128
N = int(input())
costlist = list(map(int,input().split()))
DP = [0 for i in range(N)]
DP[1]=abs(costlist[1]-costlist[0])
for i in range(N-2):
    probmin1 = abs(costlist[i+2]-costlist[i+1]) + DP[i+1]
    probmin2 = abs(costlist[i+2]-costlist[i]) + DP[i]
    plusmin = min(probmin1,probmin2) 
    DP[i+2]=plusmin
print(DP[-1])

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


int main(){
	int n;
	cin >> n;
	if(n < 3){
		cout << 0 << endl;
		return 0;
	}
	vec l(n);
	rep(i,n){
		cin >> l.at(i);
	}
	ll sum = 0;
	ll x,y,z;
	for(long long i = 0; i<n-2; i++){
		for(long long j = i+1; j<n-1; j++){
			for(long long k = j+1; k<n; k++){
				x = 0;
				y = 0;
				z = 0;
				
				if(l.at(i) >= l.at(j)){
					y = l.at(j);
					if(l.at(i) >= l.at(k)){
						x = l.at(i);
						z = l.at(k);
					}else{
						x = l.at(k);
						z = l.at(i);
					}
				}else{
					y = l.at(i);
					if(l.at(j) >= l.at(k)){
						x = l.at(j);
						z = l.at(k);
					}else{
						x = l.at(k);
						z = l.at(j);
					}
				}
				
				if(x < y+z){
					if(x != y && x != z && y != z){
						sum++;
					}
					
				}
			}
		}
	}
	cout << sum << endl;
	
	
}

Measured memory_bytes: 3632
{
  const main = (
    input: string
  ): void | string | number | string[] | number[] => {
    const r = _reader(input)
    const [N] = r.nn()
    const H = r.nn()
    let max = H[0]
    let c = 1

    for (let i = 1; i < N; i++) {
      if (max <= H[i]) {
        max = H[i]
        c++
      }
    }

    return c
  }

  const _reader = (str: string, i = 0) => {
    const lines = str.trim().split('\n')
    const s = () => lines[i++] || ''
    const n = () => Number(s())

    const mn = (v: string[]) => v.map(Number)
    const sp = (v: string) => v.split(' ')
    const ss = () => sp(s())
    const nn = () => mn(ss())
    const nls = () => mn(lines.slice(i))
    const nnls = () => lines.slice(i).map(v => mn(sp(v)))

    return { lines, s, n, ss, nn, nls, nnls }
  }

  const _getInput = () => require('fs').readFileSync('/dev/stdin', 'utf8')
  const _res = main(_getInput())

  if (typeof _res === 'number' || typeof _res === 'string') console.log(_res)
  if (typeof _res === 'object') console.log(_res.join(' '))
}


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

int main(){
  string s;
  cin >> s;
  int kakaku = 700;
  
  if(s[0] == 'o') kakaku += 100;
  if(s[1] == 'o') kakaku += 100;
  if(s[2] == 'o') kakaku += 100;
  
  cout << kakaku << endl;
}

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

#define		mina(a, b)	(a = min((a), (b)))

const int INF = 1e9+5;

int main(){
	int n;
	scanf("%d", &n);
	int k;
	scanf("%d", &k);
	vector <int> h(n);
	for (int i = 0; i < n; ++i){
		scanf("%d", &h[i]);
	}
	vector <int> dp(n, INF);
	dp[0] = 0;
	for (int i = 0; i < n; ++i){
		for (int j = 1; j <= k; ++j){
			if(i+j < n){
				dp[i+j] = min(dp[i+j], dp[i]+abs(h[i+j]-h[i]));
			}
		}
	}
	printf("%d\n", dp[n-1]);
	return 0;
}

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

int main()
{
    stack<int> s;

    int a, b,sign;
    char str[1000005]; 
    int num;
    int ans = 0;
    for(sign=0 ; str[sign-1]!='\n' ; sign++)
    {
        scanf("%c",&str[sign]);
    }
    for (int i = 0; i < sign; i++)
    {
        if (str[i] == '+')
        {
            a = s.top();  s.pop();
            b = s.top();  s.pop();
            s.push(b + a);
        }
        else if (str[i] == '-')
        {
            a = s.top();  s.pop();
            b = s.top();  s.pop();
            s.push(b - a);
        }
        else if (str[i] == '*')
        {
            a = s.top();  s.pop();
            b = s.top();  s.pop();
            s.push(b * a);
        }
        else if (str[i] == '/')
        {
            a = s.top();  s.pop();
            b = s.top();  s.pop();
            if (a == 0)
            {
                cout << "Invalid!\n";
                return 0;
            }
            else
            {
                s.push(b / a);
            }
        }
        else if (str[i] == ' ')
        {
            if (ans != 0)
            {
                s.push(ans);
            }
            ans = 0; 
        }
        else 
        {
            num = str[i] - '0';
            ans = ans * 10 + num; 
        }
    }
    printf ("%d\n", s.top());
    return 0;
}



Measured memory_bytes: 3224
import math
N = int(input())
i = 1
min = 9000000000000
for _ in range(1, int(math.sqrt(N)+1)):
  if N % i == 0:
    j = N/i
    sum = j + i
    if sum < min:
      min = sum
      ans = i-1+j-1
    else:
      break
  i += 1
print(int(ans))

Measured memory_bytes: 3060
n=int(input())
l=[]
for i in range(n):
	x,y=map(int,input().split())
	l.append((y,x))
l.sort(key=lambda x:(x[0],x[1]),reverse=True)
maximum=l[0][0]
young=l[0][1]
for i in l:
	if maximum==i[0]:
		young=i[1]
	else:
		break
print(young,maximum)

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

int main() {
    long d, t, s;
    scanf("%ld", &d);
    scanf("%ld", &t);
    scanf("%ld", &s);

    cout << (d <= t * s ? "Yes" : "No") << '\n';
    return 0;
}

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  
  vector<pair<ll, ll>> x(n);
  for (int i = 0; i < n; i++) {
    x.at(i).first = a.at(i);
    x.at(i).second = i;
  }
  
  sort(x.rbegin(), x.rend());
  
  vector<vector<ll>> dp(n + 1, vector<ll>(n + 1));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= i; j++) {
      ll r = j, c = i - j;
      dp.at(r).at(c + 1) = max(dp.at(r).at(c + 1), dp.at(r).at(c) + x.at(i).first * abs(x.at(i).second - (n - c - 1)));
      dp.at(r + 1).at(c) = max(dp.at(r + 1).at(c), dp.at(r).at(c) + x.at(i).first * abs(x.at(i).second - r));
    }
  }
  
  ll ans = 0;
  for (int i = 0; i <= n; i++) ans = max(ans, dp.at(i).at(n - i));
  
  cout << ans << '\n';
}

Measured memory_bytes: 34588
n, k = [int(x) for x in input().split()]
ps   = [int(x) for x in input().split()]
es   = []

for p in ps:
  es.append((1 + p) * p / 2 / p)

t = sum(es[0:k])
r = t

for i in range(k, n):
  t = t + es[i] - es[i - k]
  r = max(r, t)

print(r)


Measured memory_bytes: 24676
using System;

namespace Ex160424_1{
    public class Program{
        public static void Main(string[] args){
            for(var i = 1; i <= 9; i++){
                for(var j = 1; j <= 9; j++){
                    Console.WriteLine("{0}x{1}={2}", i, j, i * j);
                }
            }
        }
    }
}

Measured memory_bytes: 8764
// Author by Md. Jashim Uddin_RMSTU

#include<bits/stdc++.h>
using namespace std;
#define     sf(a)           scanf("%d",&a)
#define     sff(a,b)        scanf("%d %d",&a,&b)
#define     sfff(a,b,c)     scanf("%d %d %d",&a,&b, &c)
#define     pb              push_back
#define     ll              long  long int
#define     fast            ios_base :: sync_with_stdio(false);cin.tie(0)
#define     pi              2*acos(0)
#define     sp              fixed<<setprecision
#define     lcm(a,b)        (a*b)/gcd(a,b)
#define     gcd(a,b)        _gcd(a,b)

#define     forn(i,n)       for(int i=1;i<=n;i++)
#define     min3(a,b,c)     min(a,min(b,c)
#define     M             32000

int main()
{

    ll m,n,c=0;
    cin>>m>>n;
    while(m>0)

    {
        ll r = m%n;

        m/=n;
        c++;
    }
    cout<<c<<endl;

    return 0;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	private void solve() {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int M = in.nextInt();
		int[] cardCount = new int[N+1];
		for(int i=0; i<M; i++) {
			int L = in.nextInt()-1;
			int R = in.nextInt()-1;
			cardCount[L] ++;
			cardCount[R+1] --;
		}
		int ans = 0;
		for(int i=0; i<N; i++) {
			if(cardCount[i]==M) ans++;
			cardCount[i+1] += cardCount[i];
		}
		System.out.println(ans);
	}
	
	private int countHead(int start, int target) {
		int count = 0;
		while(target > start) {
			start = start*2;
			count ++;
		}
		return count;
	}
	
	public static void main(String[] args) {
		new Main().solve();
	}
}


Measured memory_bytes: 65160
#include<bits/stdc++.h>
using namespace std;
vector<int>p[100005];
int n,m,h[100005];
bool ok(int w){
    for(int i=0;i<p[w].size();i++){
        if(h[p[w][i]]>=h[w]){
            return 0;
        }
    }
    return 1;
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
	    cin>>h[i];
	}
	int x,y;
	for(int i=1;i<=m;i++){
	    cin>>x>>y;
	    p[x].push_back(y);
	    p[y].push_back(x);
	}
	int ans=0;
	for(int i=1;i<=n;i++){
	    ans+=ok(i);
	}
	cout<<ans;
}


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

using namespace std;

/*
 * Complete the gradingStudents function below.
 */
//vector<int> gradingStudents(vector<int> grades) {
    /*
     * Write your code here.
     */

#define int int64_t
signed main()
{
    int a,b,c,k;cin>>a>>b>>c>>k;
    if(k%2==0)cout<<a-b<<"\n";
    else cout<<b-a<<"\n";
    /*ofstream fout(getenv("OUTPUT_PATH"));

    int n;
    cin >> n;
    cin.ignore(numeric_limits<streamsize>::max(), '\n');

    vector<int> grades(n);

    for (int grades_itr = 0; grades_itr < n; grades_itr++) {
        int grades_item;
        cin >> grades_item;
        cin.ignore(numeric_limits<streamsize>::max(), '\n');

        grades[grades_itr] = grades_item;
    }

    vector<int> result = gradingStudents(grades);

    for (int result_itr = 0; result_itr < result.size(); result_itr++) {
        fout << result[result_itr];

        if (result_itr != result.size() - 1) {
            fout << "\n";
        }
    }

    fout << "\n";

    fout.close();*/

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <functional>
#include "math.h"
using namespace std;
int main(){
	int N;
	cin >> N;
	bool flag = false;
	for(int i = 0; i < N / 4 + 1; i++){
		for(int j = 0; j < N / 7 + 1; j++){
			if((i * 4) + (j * 7) == N){
				flag = true;
			}
		}
	}
	if(flag == true){
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


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

#define ll long long int
#define pb push_back
#define ppb pop_back
#define ff first
#define ss second
#define vvi vector<vector<ll>>
#define vi vector<ll>
#define all(a) (a).begin(),(a).end()
#define pii pair<ll,ll>
#define rep(x,n) for(ll i=x;i<n;++i)
#define repd(x,n) for(ll i=x-1;i>=n;--i)
#define repn(x,n) for(ll j=x;j<n;++j)
#define repnd(x,n) for(ll j=x-1;j>=n;--j)
#define dbg(x,y) cout<<x<<" "<<y<<endl
#define endl '\n'
#define M 1000000007
const ll INF = 1ll<<60;

using namespace std;
//-----------------------------------------//


void solve(){


	  ll n, m ,ms;
	  cin>>n>>m>>ms;
	  ll A[n],B[m];

	  for(ll A_i = 0; A_i < n; A_i++){
	//			scanf("%lld",&A[A_i]);
		cin>>A[A_i];
	  }
	  for(ll B_i = 0; B_i < m; B_i++){
	//			scanf("%lld",&B[B_i]);
		cin>>B[B_i];
	  }

	  long long sum = 0;
	  ll x = 0, y = 0;

	  while (x < n && sum + A[x] <= ms) {
		sum += A[x++];
	  }

	  ll ans = x;

	  while (y < m && x >= 0) {
		sum += B[y++];
		while (sum > ms && x > 0) {
		  sum -= A[--x];
		}

		if (sum <= ms && ans < x + y) {
		  ans = x + y;
		}
	  }

	  cout<<ans<<endl;

}



int main(){
	solve();

}





Measured memory_bytes: 6756
#include<bits/stdc++.h>
using namespace std;
int n,k,d1,d2;
int a[2000];
const int m = 1e9 + 7; 
int main()
{
	cin >> n >> k;
	for (int i = 0;i < n;i++)
	    cin >> a[i];
	for (int i = 0;i < n;i++)
	    for (int j = 0;j < i;j++)
	    {
	    	if (a[i] != a[j]) d2++;
	    	if (a[i] < a[j]) d1++;
	    }
	long long r = (long long)k * (k - 1) / 2;
	r %= m;
	r *= d2;
	r %= m;
	long long _r = (long long)k * d1;
	_r %= m;
	cout << (r + _r) % m << endl;
	return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE RecursiveDo        #-}
{-# LANGUAGE OverloadedStrings  #-}
{-# LANGUAGE NumericUnderscores #-}

import qualified Data.ByteString.Char8 as C8
import Data.List
import Data.Char

f :: Int -> [Int] -> [Int]
f k hs@(h:_) = map (abs . subtract h) (take k hs)

g :: Int -> [Int] -> [Int] -> [Int] -> Int
g _ costs _      []                  = head costs
g k costs starts dists@(dist:dists') = g k costs' starts' dists'
  where cost    = minimum $ zipWith (\ c s -> c + abs (dist - s)) (take k costs) (take k starts)
        costs'  = cost : costs
        starts' = dist : starts

solve :: Int -> Int -> [Int] -> Int
solve n k h
    | n > k     = g k (reverse $ f k h) (reverse $ take k h) (drop k h)
    | otherwise = last $ f n h

main = do
  [n, k] <- unfoldr (C8.readInt . C8.dropWhile isSpace) <$> C8.getLine
  h      <- unfoldr (C8.readInt . C8.dropWhile isSpace) <$> C8.getLine
  print $ solve n k h


Measured memory_bytes: 73072
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char originalMap[][] = new char[n][n];
        for (int i = 0; i < n; i++) {
            String s = sc.next();
            for (int j = 0; j < n; j++) {
                originalMap[i][j] = s.charAt(j);
            }
        }
        int cnt = 0;
        // a,bはずらす値
        B: for (int b = 0; b < n; b++) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    int nj = (j + b) % n;
                    int ni = (i + b) % n;
                    if (originalMap[i][nj] == originalMap[j][ni]) {

                    } else {
                        continue B;
                    }
                }
            }
            cnt++;
        }
        System.out.println(cnt * n);
        sc.close();
    }
}


Measured memory_bytes: 28216
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		long[] a = new long[N];
		for(int i=0; i<N; i++)
			a[i] = sc.nextLong();
		
		long ans = 0;
		
		Arrays.sort(a);
		
		for(int i=1; i<N; i++) {
			long op = (a[i]-a[0])/(N+1);
			ans += op;
			a[i] -= op*(N+1);
		}
		
		for(int i=0; i<N; i++)
			a[i] += ans;
		
		Arrays.sort(a);
		
		long op = Math.max(0, a[0]-N);
		for(int i=0; i<N; i++)
			a[i] -= op;
		ans += op*N;
		
		int idx = N-1;
		while(true) {
			if(a[idx]<=N-1)
				break;
			ans++;
			a[idx]-=N;
			for(int i=0; i<N; i++)
				if(i!=idx)
					a[i]++;
			idx = (idx-1+N)%N;
		}
		
		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN=1e6+69;
const int mod = 1e9+7;
string s;
int n,m,k;
int a[MAXN];
int ans;
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    ans=INT_MAX;
    for(int i=0;i<=101;i++){
        int sum=0;
        for(int j=1;j<=n;j++){
            sum+=(a[j]-i)*(a[j]-i);
        }
        ans=min(ans,sum);
    }
    cout<<ans;
}


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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define _dec(i,j,N) for(int i = (N-1);i >= (j);i--)
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define LL long long

typedef pair<int,int> pi;

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,v.size()) os << v[i] << " ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}

const int maxn = 3005;
int dp[maxn][maxn];
pi opt[maxn][maxn];

string a,b;
string ans;

int main()
{
    cin >> a >> b;
    int sza = a.size(),szb = b.size();
    _rep(i,1,sza){
        _rep(j,1,szb){
            if(a[i-1] == b[j-1]){
                dp[i][j] = dp[i-1][j-1] + 1;
                opt[i][j] = make_pair(-1,-1);
            }
            else{
                if(dp[i][j-1] > dp[i-1][j]){
                    dp[i][j] = dp[i][j-1];
                    opt[i][j] = make_pair(0,-1);
                }
                else{
                    dp[i][j] = dp[i-1][j];
                    opt[i][j] = make_pair(-1,0);
                }

            }

        }
    }


    int x = sza;
    int y = szb;
    while(dp[x][y] > 0){
        int dx = opt[x][y].first;
        int dy = opt[x][y].second;
        //cout << dp[x][y] << endl;
        if(dx == -1 && dy == -1) ans.push_back(a[x-1]);
        x += dx;
        y += dy;
    }

    //cout << dp[sza][szb] << endl;

    reverse(ALL(ans));
    cout << ans << endl;
    return 0;
}

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

int N, T;
set<int> M;

int main(){
	scanf("%d", &N);
	for(int i = 0; i < N; i++){
		int val;
		scanf("%d", &val);
		set<int>::iterator fnd = M.find(val);
		if(fnd == M.end())
			M.insert(val), T++;
		else
			M.erase(val), T--;
	}
	printf("%d\n", T);
	return 0;
}


Measured memory_bytes: 4864
N=int(input())
S = input()
mod = 10**9+7

ans = int(S[0]==S[-1]=="B")

n = 1
for s in S[1:]:
    if n==0 and s=="W":
        ans = 0
        break
    if (s=="B") ^ (n%2 == 0):
        ans = ans*n%mod
        n -= 1
    else:
        n += 1
if n!=0 : ans = 0
for i in range(2,N+1):
    ans = ans * i % mod
print(ans)

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

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt();
        long sum = 0;
        ArrayList<Integer> ret = new ArrayList<>();
        if (n == 3) {
            ret.add(2); ret.add(5); ret.add(63);
        } else if (n < 14990) {
            for (int i = 1; i <= n - 3; i++) {
                ret.add(2 * i);
                sum += 2 * i;
            }
            int cur = 2 * (n - 3) + 2;
            while ((cur + sum) % 3 != 0) cur += 2;
            ret.add(cur);
            ret.add(3);
            ret.add(9);
        } else {
            for (int i = 3; i <= 30000; i += 6) ret.add(i);
            if (ret.size() % 2 != 0) ret.remove(ret.size() - 1);
            int curSz = ret.size(); int add = 2;
            for (int i = curSz + 1; i <= n - 1; i++) {
                ret.add(add); sum += add;
                add += 2;
            }
            while ((sum + add) % 3 != 0) add += 2;
            ret.add(add);
        }
        for (Integer i : ret) out.print(i + " ");
        //out.println();
        //out.println(ret.size());
        out.close();
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

Measured memory_bytes: 39976