akhauriyash/Code-Regression huggingface dataset:
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod   1000000007
#define PI 2*acos(0.0)
#define all(r)(r).begin(),(r).end()
#define dbg(a) cout<<#a<<" ->->->-> "<<a<<"\n"
#define inf 1000000000000000000
#define N 110
int dirx[] = {1, -1,0, 0}, diry[] = {0, 0, 1, -1};


//=============================================ASIFAZAD==============================================

int32_t main()
{
    //io;
//    vector<double> exp(1005);
//    for(int i = 1; i<= 1000; i++)
//    {
//        double aex = 0;
//        for(double j = 1; j <= i; j++)
//            aex += j/i;
//        exp[i] = aex;
//    }
    int n, k;
    cin>>n>>k;
    vector<double> inp(n);
    for(auto& x: inp) cin>>x;

    double ans = 0, ac = 0;
    int i = 0, bk = 0;
    while(i < n)
    {
        ans += (inp[i] + 1)/2.0;
        i++;
//        dbg(i);
//        dbg(bk);
        while(i - bk > k)
        {
            ans-= (inp[bk] + 1)/2.0;
            bk++;
        }
//        dbg(ans);
        ac = max(ac, ans);
    }
    printf("%.8f", ac);
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    int h, w; cin >> h >> w;
    vector<vector<int> > field(h, vector<int> (w));
    rep(i, h) rep(j, w) cin >> field[i][j];

    int ans = INF;
    rep(i, h) rep(j, w) {
        int tmp = 0;
        rep(s, h) rep(t, w) {
            tmp += field[s][t]*min(abs(i-s), abs(j-t));
        }
        ans = min(ans, tmp);
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3184
#include<stdio.h>
int SOSU[500000];
main(){
  int i,j,cnt,n;
  for(i=2;i<500000;i++){
    if(SOSU[i]==0){
      for(j=2;i*j<500000;j++){
	SOSU[i*j]=1;
      }
    }
  }

  while(1){
    scanf("%d",&n);
    if(n==0)break;
    for(i=n+1,cnt=0;i<=2*n;i++){
      if(SOSU[i]==0)cnt++;
    }
    printf("%d\n",cnt);
  }
  return 0;
}

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

int main(void){
    long long A,B,K;
    cin>>A>>B>>K;
    for(int i=A;i<=min(B,A+K-1);i++){
        cout<<i<<endl;
    }
    for(int i=max(A+K,B-K+1);i<=B;i++){
        cout<<i<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
 
using ull = unsigned long long int;
using ll = long long int;
using du = double;
using ld = long du;
using vi = vector<int>;
using vll = vector<ll>;
using vld = vector<ld>;
using vdu = vector<du>;
using vs = vector<string>;
using vc = vector<char>;
using si = set<int>;
using sll = set<ll>;
using sdu = set<du>;
using sld = set<ld>;
using pii = pair<int, int>;
using pll = pair<ll,ll>;
using pdu = pair<du,du>;
using pld = pair<ld,ld>;
using pis = pair<int,string>;
 
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define sp(x) setprecision(x)<<fixed
#define loop(i,n) for(int i=0;i<n;i++)
#define ff first
#define ss second
#define pi acos(-1)
#define meme(a,x) memset(a,x,sizeof(a))
 
//debugger
 
#ifdef KAIZER
#include "debug.h"
#else
#define debug(x...)
#endif
//debugger
 
//functions
bool check_pow(ll a)
{
    if((a&(a-1))==0) return true;
    else return false;
}
ld my_pow(ld a,int b)
{
    ld ans=1;
    for(int i=0;i<b;i++) ans*=a;
    return ans;
}
ll digits(ll a)
{
    string line=to_string(a);
    return line.size();
}
bool prime_check(ll a)
{
    bool flag=true;
    for(ll i=2;i<=sqrt(a);i++)
    {
        if(a%i==0) {flag=false; break;}
    }
    return flag;
}
bool comp(const ll &a , const ll &b)
{
    return a>b;
}
const ll xyz=2e5+10;
ll fact[xyz];
void mod_fact(ll m=1)
{
    fact[0]=1;
    loop(i,(2e5)) 
    {
        ll p=i+1;
        //if(p%2==0) p/=2;
        fact[i+1]=(((fact[i])%m)*(p%m))%m;
    }
}

//functions


int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    FASTIO;
    ll a,ans=0;
    du x=0;
    cin>>a;
    vll nums(a);
    loop(i,a) {
        cin>>nums[i];
        x+=nums[i];
    }
    debug(x);
    x/=a;
    if(x-int(x)>0.5) x+=1;
    debug(x);
    loop(i,a) ans+=((int(x)-nums[i])*(int(x)-nums[i]));
    cout<<ans<<endl;
}
 

Measured memory_bytes: 3680
X = int(input())
flg = False

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

div_arr = sorted(make_divisors(X))

def cal_p2(a,b):
  return pow(a,4) + pow(a,3)*pow(b,1) + pow(a,2)*pow(b,2) + pow(a,1)*pow(b,3) + pow(b,4)


for div in div_arr:
  p1 = div
  p2 = X//div
  a = p1//2-1
  while True:
    a += 1
    b = a - p1
    if p2==cal_p2(a,b):
      flg = True
      break
    elif p2<cal_p2(a,b):
      break
  if flg:
    break
    
print(a,b) 



Measured memory_bytes: 9484
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt()*100;
		int g = sc.nextInt()*10;
		int b = sc.nextInt();
		int ans = r + g + b;
		if (ans % 4 == 0) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
		sc.close();
	}

}

Measured memory_bytes: 21844
use std::io::*;
use std::str::FromStr;
use std::cmp;
use std::collections::HashMap;
use std::collections::HashSet;
use std::char;
use std::cmp::min;
use itertools::Itertools;
use num_integer::div_floor;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn read_tuple2<T: FromStr, S: FromStr>() -> (T, S) {
    let a = read();
    let b = read();
    (a, b)
}

fn read_tuple3<T: FromStr, S: FromStr, R: FromStr >() -> (T, S, R) {
    let a = read();
    let b = read();
    let c = read();
    (a, b, c)
}

fn main() {
    let (n, k):(u64, u64) = read_tuple2();
    let alist:Vec<u64> = (0..n).map(|_|read()).collect();
    let mut counter = HashMap::new();
    for a in alist {
        let e = counter.entry(a).or_insert(0);
        *e += 1;
    }
    let mut keyval:Vec<(&u64, &u64)> = counter.iter().collect();
    keyval.sort_by(|(_, num), (_, num2)|num.cmp(num2));
    let type_num = keyval.len();
    if type_num <= k as usize {
        println!("0");
        return;
    }
    let num_to_erase:usize = type_num - k as usize;
    let ans:u64 = keyval.iter().map(|(_, num)| *num).take(num_to_erase).sum();
    println!("{}", ans);
}



Measured memory_bytes: 10052
#include <bits/stdc++.h>
using namespace std;
long long lmax(long long a, long long b){
  if(a<b) return b;
  else return a;
}
int main(){
  long long a,b,k;
  long long z=0;
  cin>>a>>b>>k;
  if(a-k>0){
    cout<<a-k<<" "<<b<<endl;
  }
  else{
    cout<<z<<" "<<lmax(z, b-k+a)<<endl;
  }
  return 0;
}
    


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

int main() {
  int n;
  cin >> n;
  int a[n],b[n],c[n];
  for(int i=0;i<n;i++) cin >> a[i] >> b[i] >> c[i];
  vector<vector<int>> h(n,vector<int>(3,0));
  h[0][0] = a[0];h[0][1] = b[0];h[0][2] = c[0];
  for(int i=0;i<n-1;i++){
    h[i+1][0] = max(h[i][1] + a[i+1],h[i][2] + a[i+1]);
    h[i+1][1] = max(h[i][0] + b[i+1],h[i][2] + b[i+1]); 
    h[i+1][2] = max(h[i][0] + c[i+1],h[i][1] + c[i+1]);
  }
  cout << max(max(h[n-1][0],h[n-1][1]),h[n-1][2]) << endl;
}


Measured memory_bytes: 6912
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(m)]
a=[-1]*n
ans=1
for i in range(m):
  if a[sc[i][0]-1]==-1:
    a[sc[i][0]-1]=sc[i][1]
  else:
    if a[sc[i][0]-1]!=sc[i][1]:
      ans=0
      break
if a[0]==0 and n>=2:
  ans=0
ll=""
for j in range(n):
  if a[j]==-1:
    a[j]=0
  ll+=str(a[j])
  
if ans==0:
  print(-1)
else:
  if n!=len(str(int(ll))):
    print(int(ll)+10**(n-1))
  else:
    print(int(ll))

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#define SF scanf
#define PF printf
#define MAXN 100010
#define MAXP 2300
using namespace std;
typedef long long ll;
int primes[MAXN],cnt;
int isprime[MAXP+100];
ll a[MAXN],les[MAXN],les1[MAXN];
map<ll,int> mp,st;
void prepare(){
	for(int i=2;i<=MAXP;i++){
		if(isprime[i]==0)
			primes[++cnt]=i;
		for(int j=1;i*primes[j]<=MAXP;j++){
			isprime[i*primes[j]]=1;
			if(i%primes[j]==0)
				break;	
		}
	}
}
int main(){
	prepare();
	//PF("%d",cnt);
	int n;
	SF("%d",&n);
	for(int i=1;i<=n;i++){
		SF("%lld",&a[i]);
		les1[i]=les[i]=a[i];
	}
	for(int i=1;i<=cnt;i++){
		ll p=primes[i];
		ll p2=p*p;
		ll p3=p*p*p;
		for(int j=1;j<=n;j++)
			if(a[j]%p==0){
				while(a[j]%p3==0){
					a[j]/=p3;
					les1[j]/=p3;
					les[j]/=p3;
				}
				if(les1[j]%p2==0){
					les1[j]/=p;
					les[j]/=p;
				}
				if(les[j]%p==0)
					les[j]/=p;
			}
	}
	for(int i=1;i<=n;i++){
		if(les[i]==1){
			les[i]=les1[i];
			continue;
		}
		ll x=(long long)sqrt(les[i]);
		if(x*x==les[i])
			les[i]=les1[i]/x;
		else
			les[i]=les1[i];	
	}	
	int ans=0;
	for(int i=1;i<=n;i++){
		if(a[i]==1){
			ans=1;
			continue;
		}
		mp[a[i]]++;
		st[a[i]]=les[i];
	}
	map<ll,int>::iterator it=mp.begin();
	for(;it!=mp.end();it++){
		ll x=it->first;
		int sum=it->second;
		ll y=st[x];
		ll xi=y*y/x*y;
		if(mp.count(xi)==0)
			ans+=sum;
		else{
			if(xi>x)
				ans+=max(sum,mp[xi]);	
		}
	}
	PF("%d",ans);
}

Measured memory_bytes: 15104
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let L = read!(f64);
    let x = L / 3.0;
    let y = L / 3.0;
    let z = L - x - y;

    println!("{}", x * y * z)
}


Measured memory_bytes: 4352
#!/usr/bin/env python3
from collections import Counter

h, w, m = list(map(int, input().split()))

H = []
W = []
for i in range(m):
    hh, ww = tuple(map(int, input().split()))
    H.append(hh)
    W.append(ww)
h_m = Counter(H).most_common()[0]
w_m = Counter(W).most_common()[0]

ans_1 = h_m[1]
ans_2 = w_m[1]

# print(ans_1, ans_2)
WW = []
HH = []
for i in range(m):
    if H[i] == h_m[0]:
        continue
    WW.append(W[i])

for i in range(m):
    if W[i] == w_m[0]:
        continue
    HH.append(H[i])
if WW:
    ans_1 += Counter(WW).most_common()[0][1]
if HH:
    ans_2 += Counter(HH).most_common()[0][1]

print(max(ans_1, ans_2))


# hw.sort()
# hw_rev = sorted(hw, key=lambda x: x[1])

# index_sum_h = []
# sum_h = []
# index = -1
# for i in hw:
#     a, b = i
#     if a == index:
#         index_sum_h[-1][1] += 1
#     else:
#         index = a
#         index_sum_h.append([a, 1])

# index_sum_w = []
# index = -1
# for i in hw_rev:
#     a, b = i
#     if b == index:
#         index_sum_w[-1][1] += 1
#     else:
#         index = b
#         index_sum_w.append([b, 1])

# # print(hw)
# # print(index_sum_h)
# # print(index_sum_w)

# index_sum_h = sorted(index_sum_h, key=lambda x: x[1], reverse=True)
# index_sum_w = sorted(index_sum_w, key=lambda x: x[1], reverse=True)

# # print(index_sum_h)
# # print(index_sum_w)
# dq = deque([[0, 0]])

# ans_tmp = index_sum_h[0][1]+index_sum_w[0][1]

# hw = set(hw)
# while len(dq) > 0:
#     index_h, index_w = dq.popleft()
#     a, b = index_sum_h[index_h]
#     c, d = index_sum_w[index_w]

#     # print([a, c])
#     # print([a, c] in hw)
#     if (a, c) in hw:
#         ans = ans_tmp-1
#         if index_h+1 < len(index_sum_h):
#             if index_sum_h[index_h+1][1] == b:
#                 dq.append([index_h+1, index_w])
#         if index_w+1 < len(index_sum_w):
#             if index_sum_w[index_w+1][1] == d:
#                 dq.append([index_h, index_w+1])

#     else:
#         print(b+d)
#         exit()

# print(ans)


Measured memory_bytes: 77260
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
int main() {
  
 
    int N; cin >> N;
    int cur; cin >> cur; cur--;
    int data[N-1]; FOR(i, 1, N) cin >> data[i-1];
    FOR(i, 1, N) {
        int nxt = data[i-1];
        if (nxt > cur) {
            nxt--;
        }
        if (nxt < cur) {
            cout << "No" << endl;
            return 0;
        }
        cur = nxt;
    }
 
    cout << "Yes" << endl;
 
    return 0;
}

Measured memory_bytes: 640
//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath> 
#include <iomanip>
#include <math.h>
#include <utility>
#include <functional>
#include <cstdlib>
//using
using namespace std;
using vl = vector <long long>;
using vs = vector <string>;
using vc = vector <char>;
using ll= long long;
using vvl = vector<vector<ll> >;
using vvc = vector<vector<char> >;
//vector<vector<char> > hyou(N, vector<char>(N));
using vd = vector <double>;
//define
//#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
#define print(n) cout<<n<<endl;
#define sortp(d) sort(d.begin(),d.end()) //1234
#define sortm(d) sort(d.rbegin(),d.rend()) //4321
//素数判定　O(√A) 
bool is_prime(int x){
 if(x<=1) return false;
 for(int i=2;i*i<=x;i++)
 if(x%i==0) return false;
 return true;
 }
/*順列生成
do {
  // 順列に対する処理
} while (next_permutation(配列変数.begin(), 配列変数.end()));*/

//絶対値　abs()
//文字→数字　'0' アルファベット→数字　'a'　'A'が65番,'a'が97番だわ
//型キャスト　char('a'+1)
//reverse 回文

//グローバル変数宣言
ll p=0,q=0,r=0;

int main()
{
  string a,b;
  cin>>a>>b;
  p=a.size();q=b.size();
  if(p!=q)
  {if(p>q)r=1;if(q>p)r=2;}
  else
  {
    rep(i,p){
    if((a[i]-'0')>(b[i]-'0')){r=1;break;}
    if((a[i]-'0')<(b[i]-'0')){r=2;break;}
    }
  }
  if(r==0)print("EQUAL");
  if(r==1)print("GREATER");
  if(r==2)print("LESS");
}

Measured memory_bytes: 3616
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 10桁出力 cout << setprecision(10) << double;
#include <queue>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.

	int a, b, c;
	cin >> a >> b >> c;
	int m = 0;
	VI s(3, 0);
	s[0] = a;
	s[1] = b;
	s[2] = c;
	sort(s.begin(), s.end());

	if (s[2] == s[1] + s[0]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}



	return 0;
}

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

#define ll long long
#define ld long double
#define db double
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(v) for(int i=0;i<_sz(v);i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)
#define tc int tt=1;cin>>tt;rep(tcs,1,tt+1)

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr<<name<<" : "<<arg1<<nl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1, args...);
}
#else
#endif

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const ld pi=2*acos(0.0);

int main(){
    nimble
    ll x,k,d;
    cin>>x>>k>>d;
    if(x<0)x*=-1;
    ll mv=x/d;
    if(mv>=k){
        cout<<x-d*k<<nl;
        return 0;
    }
    ll x1=x-mv*d;
    k-=mv;
    ll as=x1;
    ll as2=d-x1;
    if(k&1)cout<<as2;
    else cout<<as;
    return 0;
}


Measured memory_bytes: 3632
while True:
    n=list(map(int,input().split()))
    if n[0]==0 and n[1]==0:
        break
    else:
        cnt=0
        for i in range(1,n[0]+1):
            for j in range(i+1,n[0]+1):
                for k in range(j+1,n[0]+1):
                    if i+j+k==n[1]:
                        cnt+=1
    print(cnt)




Measured memory_bytes: 5592
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl

vector<int> decimals;

void calculate(int a, int b) {
    decimals.clear();
    a = a % b;
    REP(i,100) {
        decimals.push_back(a * 10 / b);
        a = a * 10 % b;
    }
}

int getNthDecimal(int n) {
    int s = 0;
    REP(i,n) {
        s += decimals[i];
    }
    return s;
}

int main() {
    int a, b, n;
    while(cin >> a >> b >> n) {
        calculate(a, b);
        cout << getNthDecimal(n) << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
import java.util.*;
import java.math.*;
 
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	
        
      	int k = sc.nextInt();
      	int x = sc.nextInt();
      	
      	if (500 * k >= x)
          System.out.println("Yes");
      	else
          System.out.println("No");
    }
}


Measured memory_bytes: 21844
n, t = map(int, input().split())
list_t = list(map(int, input().split()))
time = 0
for i in range(1, n):
  if list_t[i] - list_t[i-1] < t:
    time += list_t[i] - list_t[i-1]
  else:
    time += t
time += t
print(time)

Measured memory_bytes: 26708
#include <iostream>
#include <cstring>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

// ?????´(= 0)????????´ (= 1)????????´ (= 2)????????´ (= 3)
int dx[4] = {-1, 0, 1, 0};
int dy[4] = { 0,-1, 0, 1};

int main(int argc, const char * argv[]) {
    while(1){
        int n; cin >> n;
        if(!n) break;
        
        int left, right, top, bottom;
        left = right = top = bottom = 0;
        
        vector<pair<int, int> > tableIndex;
        tableIndex.push_back(make_pair(0, 0));
        
        for(int i = 1; i < n; i++){
            int m, d; cin >> m >> d;
            
            int x = tableIndex[m].first + dx[d];
            int y = tableIndex[m].second + dy[d];
            tableIndex.push_back(make_pair(x, y));
            
            left = min(left, x), right  = max(right, x);
            top  = min(top, y),  bottom = max(bottom, y);
        }
        
        cout << right - left + 1 << " " << bottom - top + 1 << endl;
    }
}

Measured memory_bytes: 1200
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>
#include <fstream>

using namespace std;
typedef long long ll;

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; }
template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
constexpr int MAX = 5000000;


struct mint {
	long long x;
	mint(long long x = 0) :x((x% mod + mod) % mod) {}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	int n; cin >> n;
	vector<ll> x(n), y(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
	}
	vector<int> io(n); for (int i = 0; i < n; i++) io[i] = i;
	sort(io.begin(), io.end(), [&](int i, int j) {
		return (x[i] + y[i] < x[j] + y[j]);
		});
	ll res = 0;
	for (int i = 0; i < n; i++) {
		chmax(res, llabs(x[i] - x[io[0]]) + llabs(y[i] - y[io[0]]));
		chmax(res, llabs(x[i] - x[io[n - 1]]) + llabs(y[i] - y[io[n - 1]]));

	}
	sort(io.begin(), io.end(), [&](int i, int j) {
		return (x[i] - y[i] < x[j] - y[j]);
		});
	for (int i = 0; i < n; i++) {
		chmax(res, llabs(x[i] - x[io[0]]) + llabs(y[i] - y[io[0]]));
		chmax(res, llabs(x[i] - x[io[n - 1]]) + llabs(y[i] - y[io[n - 1]]));

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

Measured memory_bytes: 7212
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

vl dx = {-1,1,0,0};
vl dy = {0,0,-1,1};
ll H, W;
bool ok(ll h, ll w){
    return 0 <= h && h < H && 0 <= w && w < W;
}

int main(){
    cin >> H >> W;
    vvl a(H, vl(W, -LINF));
    priority_queue<pair<ll, PL>> q;
    vvb used(H, vb(W, false));
    REP(i, H) REP(j, W){
        char c; cin >> c;
        if(c == '#'){
            a[i][j] = 0;
            q.push(make_pair(0, PL(i, j)));
            used[i][j] = true;
        }
        else a[i][j] = LINF;
    }
    while (q.size() > 0) {
        auto p = q.top(); q.pop();
        ll x = p.ss.ff, y = p.ss.ss;
        REP(i, 4){
            ll nx = x+dx[i], ny = y+dy[i];
            if(!ok(nx, ny)) continue;
            if(used[nx][ny]) continue;
            a[nx][ny] = -p.ff + 1;
            used[nx][ny] = true;
            q.push(make_pair(-a[nx][ny], PL(nx,ny)));
            
        }
    }
    
    ll ans = -LINF;
    REP(i, H) REP(j, W){
        ans = max(ans, a[i][j]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 34920
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    string S;cin>>S;
    string ans="";
    for(int i=0;i<S.size();i++){
        switch(S[i]){
            case '0':
            case '1':
                ans+=S[i];
                break;
            case 'B':
                if(ans.size()>0){
                    ans.pop_back();
                }
                break;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3608
package main

import "fmt"

func main() {
	var N, A int
	fmt.Scan(&N)
	sw := 1
	for i := 0; i < N; i++ {
		fmt.Scan(&A)
		if A%2 != 0 {
			sw *= -1
		}
	}
	fmt.Println([]string{"NO", "YES"}[toInt(sw > 0)])
}

func toInt(ok bool) int {
	if ok {
		return 1
	}
	return 0
}


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

int main() {
    int N, cnt=0;
    cin >> N;
    vector<int> p(N);
    vector<int> po(N);
    for(int i=0; i<N; i++){
        int num;
        cin >> num;
        p.at(i) = num;
        po.at(i) = num;
    }
    sort(p.begin(), p.end());
    for(int i=0; i<N; i++){
        if(p.at(i)!=po.at(i)) cnt++;
    }
    if(cnt>=3){
        cout << "NO";
    }else{
        cout << "YES";
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int i = sc.nextInt();
		int j = sc.nextInt();
		if(1<=i && i<=9 && j>=1 && j<=9) {
			System.out.println(i*j);
		}else
			System.out.println(-1);
	}

}

Measured memory_bytes: 22740
import java.util.*;
import java.awt.Point;

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

		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if(n == 0 && m == 0) break;

			HashMap<String,Point> pmap = new HashMap<String,Point>();
			for(int i=0;i<n;i++){
				String name = sc.next();
				Point p = new Point(sc.nextInt(),sc.nextInt());
				pmap.put(name,p);
			}

			HashMap<String,ArrayList<String>> map = new HashMap<String,ArrayList<String>>();
			for(String name : pmap.keySet()){
				ArrayList<String> zeroList = new ArrayList<String>();
				for(int i=0;i<4;i++) zeroList.add(null);
				map.put(name,zeroList);
			}
			for(int i=0;i<m;i++){
				String s = sc.next();
				String d = sc.next();
				Point sp = pmap.get(s);
				Point dp = pmap.get(d);

				//ð·_ s ÌÉð·_ d ª é
				if(dp.x - sp.x > 0){
					map.get(s).set(1,d);
					map.get(d).set(3,s);
				}
				//ð·_ s Ì¼Éð·_ d ª é
				else if(dp.x - sp.x < 0){
					map.get(s).set(3,d);
					map.get(d).set(1,s);
				}
				//ð·_ s ÌkÉð·_ d ª é
				else if(dp.y - sp.y > 0){
					map.get(s).set(0,d);
					map.get(d).set(2,s);
				}
				//ð·_ s ÌìÉð·_ d ª é
				else {
					map.get(s).set(2,d);
					map.get(d).set(0,s);
				}
			}

			String s = sc.next();
			String d = sc.next();

			PriorityQueue<State> open = new PriorityQueue<State>();
			HashSet<State> closed = new HashSet<State>();
			for(int i=0;i<4;i++){
				open.add(new State(s,i,0,1));
			}

			State ans = null;

			while(!open.isEmpty()){
				State st = open.poll();
				if(closed.contains(st)) continue;
				closed.add(st);

				if(st.name.equals(d)){
					ans = st;
					break;
				}

				//¼i
				String next = map.get(st.name).get(st.d);
				if(next != null){
					int dist = (int)pmap.get(st.name).distance(pmap.get(next));
					open.add(new State(next,st.d,st.dist+dist,st.cost+1));
				}

				//¶Ü
				int nd = (st.d + 3) % 4; //¶ÜÌûü
				next = map.get(st.name).get(nd);
				if(next != null){
					int dist = (int)pmap.get(st.name).distance(pmap.get(next));
					open.add(new State(next,nd,st.dist+dist,st.cost+1));
				}
			}

			System.out.println(ans == null ? "impossible" : ans.cost);
		}
	}
}

class State implements Comparable<State>{
	String name; //ð·_¼
	int d,dist,cost; //»Ýü¢Ä¢éûü,¡ÜÅà¢½£,ÊÁ½ð·_Ì

	State(String name,int d,int dist,int cost){
		this.name = name;
		this.d = d;
		this.dist = dist;
		this.cost = cost;
	}

	public int compareTo(State st){
		if(dist < st.dist) return -1;
		else if(dist > st.dist) return 1;
		return cost - st.cost;
	}

	public boolean equals(Object o){
		State st = (State)o;
		return name.equals(st.name) && d == st.d;
	}

	public int hashCode(){
		return name.hashCode() + d;
	}
}

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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n; cin >> n;
    bool poss = true;
    for (int i = 0; i < n; i++) {
        int ai; cin >> ai;
        if (ai % 2 == 0) {
            if (ai % 3 == 0 || ai % 5 == 0) {
                continue;
            }
            else {
                poss = false;
                break;
            }
        }
    }
    cout << (poss ? "APPROVED" : "DENIED") << endl;
}



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

int main(){
    string s;
    cin>>s;
    int flag=1;
    for(int i=0; i<3; i++){
        if(s[i]=='7'){
            cout<<"Yes"<<endl;
            flag=0;
            break;
        }
    }
    if(flag){
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i < (n); i++)
typedef long long ll;
// Welcome to my source code!

int main() {
    int n;
    cin >> n;
    int h, ans = 0, top = 0;
    REP(i,n) {
        cin >> h;
        if (h >= top) {
            ans++;
            top = h;
        }
    }
    cout << ans << endl;
}

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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = 1e9+7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m;
	cin >>n >>m;
	VI p(m), d(m);
	rep(i, m){
		int k, q; cin >>k;
		rep(j, k){
			cin>>q;
			d[i] |= 1<<(q-1);
		}
	}
	rep(i, m) cin >>p[i];
	int ans=0;
	rep(i, 1<<n){
		bool ok=1;
		rep(j, m){
			int cr = d[j] & i;
			//if(cr ==0) ok=0;
			if(__builtin_popcount(cr)%2 != p[j]) ok=0;
		}
		if(ok) ans++;
	}
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);i--)

#define all(x) (x).begin(),(x).end()

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; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  vector<string>s(3);
  rep(i,3)cin>>s[i];
  ll res=0;
  rep(i,n){
    
    map<char,ll>ma;
    rep(j,3)ma[s[j][i]]+=1;
    ll tn=0;
    for(auto tp:ma){
      chmax(tn,tp.second);
    }
    res+=3-tn;
  }
  cout<<res<<endl;
  return 0;

}


Measured memory_bytes: 256
N = int(input())
P = list(map(int, input().split()))
geta = 30000

A = [i*geta + 1 for i in range(N)]
B = [(N-1-i)*geta + 1 for i in range(N)]

for i, p in enumerate(P):
    A[p-1] += i
print(*A)
print(*B)


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

#define sz(x) (int)(x.size())
#define FOR(x,y,z) for(int x = y; x <= z; x++)
#define int long long

const int N = 1e5 + 2, inf = 1e18, mod = 1e9 + 7;

int n, u, v;
std::vector<int> g[N];
int dp[2][N];

int go(int u, int par, int col){
	int &ans = dp[col][u];
	if(~ans)
		return ans;
	ans = 1;

	for(int v : g[u]) if(v != par){
		if(col == 0){
			ans = (ans * go(v, u, !col)) % mod;
		}
		else{
			ans = (ans * (go(v, u, !col) + go(v, u, col))) % mod;
		}
	}
	return ans;
}

int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);  
	
	memset(dp, -1, sizeof(dp));
	cin >> n;
	FOR(i,2,n){
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	int ans = go(1,-1,0) + go(1,-1,1);
	ans %= mod;
	cout << ans;
}

Measured memory_bytes: 18920
#include <cstdio>

using namespace std;

bool binarySearch(int A[], size_t N, int a) {
  size_t p = 0, q = N;
  while (p < q) {
    size_t i = (p + q) / 2;
    if (A[i] == a) {
      return true;
    }
    if (A[i] < a) {
      p = i + 1;
    } else {
      q = i;
    }
  }
  return false;
}

int main(void) {
  size_t n;
  scanf("%zu", &n);
  int S[110000];
  for (size_t i = 0; i < n; i++) {
    scanf("%d", &S[i]);
  }

  int c = 0;

  size_t q;
  scanf("%zu", &q);
  for (size_t i = 0; i < q; i++) {
    int t;
    scanf("%d", &t);
    if (binarySearch(S, n, t)) {
      c++;
    }
  }

  printf("%d\n", c);
  return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>

using namespace std;

int maxKouyaku(int a, int b){
    if(b == 0) return a;
    return maxKouyaku(b, a%b);
}

int main(){
    int N, X;
    cin >> N >> X;

    vector<int> nums(N);
    for(int i = 0; i < N; i++){
        int tmp;
        cin >> tmp;
        nums[i] = abs(X-tmp);
    }

    int num = maxKouyaku(nums[0], nums[1]);
     for(int i = 2; i < N; i++){
        num = maxKouyaku(num, nums[i]);
    }

    cout << num << endl;
}

Measured memory_bytes: 640
def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    [A, B, X] = list(map(lambda x: int(x), inputs[0].split()))
    num = (B // X) - ((A - 1) // X)
    return num


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Text;

class Program
{
	static void Main(string[] args)
	{
		string[] input = Console.ReadLine().Split(' ');
		int D = int.Parse(input[0]);
		int[] c = new int[26];
		input = Console.ReadLine().Split(' ');
		for(int i=0; i<26; i++) c[i] = int.Parse(input[i]);
		int[][] s = new int[D][];
		for(int i=0; i<D; i++)
		{
			input = Console.ReadLine().Split(' ');
			s[i] = new int[26];
			for(int j=0; j<26; j++) s[i][j] = int.Parse(input[j]);
		}
		int[] t = new int[D];
		int[] last = new int[26];
		for(int i=0; i<26; i++) last[i] = -1;
		int satisfy = 0;
		for(int i=0; i<D; i++)
		{
			t[i] = int.Parse(Console.ReadLine()) - 1;
			satisfy += s[i][t[i]];
			last[t[i]] = i;
			for(int j=0; j<26; j++)
			{
				satisfy -= c[j] * (i - last[j]);
			}
		}
		int M = int.Parse(Console.ReadLine());
		for(int i=0; i<M; i++)
		{
			input = Console.ReadLine().Split(' ');
			int dTmp = int.Parse(input[0]) - 1;
			int qTmp = int.Parse(input[1]) - 1;
			t[dTmp] = qTmp;
			satisfy = 0;
			for(int j=0; j<26; j++) last[j] = -1; 
			for(int j=0; j<D; j++)
			{
				satisfy += s[j][t[j]];
				last[t[j]] = j;
				for(int k=0; k<26; k++)
				{
					satisfy -= c[k] * (j - last[k]);
				}
			}	
			Console.WriteLine(satisfy);	
		}
	}
}


Measured memory_bytes: 40216
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9+5;
int dp[100100];

void solve() {
    int N;
    cin >> N;
    for (int i = 0; i <= N; ++i) dp[i] = INF;
    int b[2] = {9, 6};
    dp[0] = 0;
    for (int i = 0; i <= N - 1; ++i) {
        for (int j = 0; j < 2; ++j) {
            int x = b[j];
            for (int k = 1; k < INF; ++k) {
                int n = pow(x, k);
                if (N < i + n) break;
                dp[i+n] = min(dp[i+n], dp[i] + 1);
            }
        }
        dp[i+1] = min(dp[i+1], dp[i] + 1);
    }
    cout << dp[N] << endl;
}

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


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

#define print2(a, b) cerr << "(" << a << "," << b << ")" << endl
#define print3(a, b, c) cerr << "(" << a << "," << b << "," << c << ")" << endl


void solve(string S, long long K){
    int n1 = 0;
    char c = '1';
    for (int i = 0; i < S.size(); i++) {
        if (S[i] != '1') {
            c = S[i];
            break;
        }
        n1++;
    }
    if (K <= n1) cout << '1' << endl;
    else cout << c << endl;
}

int main(){
    char S[1000];
    scanf("%s", S);
    long long K;
    scanf("%lld",&K);
    solve(string(S), K);
    return 0;
}


Measured memory_bytes: 256
from bisect import bisect_left
import sys
input = sys.stdin.readline
H,W,m = map(int,input().split())
h = [0]*(H+1)
w = [0]*(W+1)
c = [[-1,10**6] for i in range(H+1)]
for i in range(m):
    a,b = map(int,input().split())
    h[a] += 1
    w[b] += 1
    c[a].append(b)
mh = max(h)
mw = max(w)
hkouho = []
wkouho = []
for i in range(H+1):
    if h[i] == mh:
        hkouho.append(i)
for i in range(W+1):
    if w[i] == mw:
        wkouho.append(i)
for i in hkouho:
    c[i].sort()
    for j in wkouho:
        if c[i][bisect_left(c[i],j)] != j:
            print(mh+mw)
            exit()
print(mh+mw-1)

Measured memory_bytes: 82476
#include <iostream>
#include <vector>
#include <cmath>
#include <typeinfo>
#include <set>
#include <bitset>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;



int main(){
  long long n,a,b;
  cin >> a >> b >> n;
  long long x = min(n,b-1);
  cout << floor((double)a*x/b) << endl;
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo LLONG_MAX
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*
何を管理したらいいんだろう

t==1
colに情報いれる
*/
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  
  ll N, Q;
  cin >> N >> Q;
  ll ans = (N-2) * (N-2);
  set<pair<ll, ll>> row, col;
  row.insert({N, N});
  col.insert({N, N});
  rep(i, Q){
    ll t, x;
    cin >> t >> x;
    if (t == 1){
      auto it = row.lower_bound({x, 0});
      ll pos = (*it).first;
      ll end = (*it).second;
      col.insert({end, x});
      ans -= (end - 2);
//cout << "t:"<< t << " x:"<<x <<
//  " pos:"<< pos << " end:"<< end << " ans:"<<ans<<endl;      
    }
    if (t == 2){
      auto it = col.lower_bound({x, 0});
      ll pos = (*it).first;
      ll end = (*it).second;
      row.insert({end, x});
      ans -= (end - 2);
//cout << "t:"<< t << " x:"<<x <<
//  " pos:"<< pos << " end:"<< end << " ans:"<<ans<<endl;      
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 16088
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<int,pint> tint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
priority_queue<pint> q;
set<pint> ng;//既に調査済み
int dp[114514];
bool sumi[114514];
map<int,vector<int> > gr[114514];
/*void aedge(int x,int y,int z){
	if(dp.find(mp(x,y))!=dp.end() && dp[mp(x,y)]<=z) return;
	dp[mp(x,y)]=z;q.push(mp(-z,mp(x,y)));
}*/
void aedge(int x,int y){
	if(dp[x]<=y) return;
	dp[x]=y;q.push(mp(-y,x));
}
int main()
{
	int n,m,a,b,c;
	scanf("%d %d",&n,&m);
	rep(i,m){
		scanf("%d %d %d",&a,&b,&c);
		a--;b--;
		gr[a][c].pb(b);
		gr[b][c].pb(a);
	}
	rep(i,114514) dp[i]=114514;memset(sumi,false,sizeof(sumi));
	aedge(0,0);
	//cout<<gr[2].size()<<endl;
	while(!q.empty()){
		pint p=q.top();q.pop();
		int x=p.se,y=-p.fi;
		if(sumi[x]) continue;sumi[x]=true;
		map<int,vector<int> >::iterator it=gr[x].begin();
		//cout<<x<<' '<<y<<endl;
		while(it!=gr[x].end()){
			int z=(*it).fi;
			//cout<<z<<'b'<<endl;
			if(ng.find(mp(x,z))!=ng.end()){
				it++;continue;
			}
			//cout<<z<<'a'<<endl;
			queue<int> qu;qu.push(x);ng.insert(mp(x,z));
			while(!qu.empty()){
				int w=qu.front();qu.pop();//ng.insert(mp(w,z));
				rep(i,gr[w][z].size()){
					int v=gr[w][z][i];
					if(ng.find(mp(v,z))==ng.end()){
						//cout<<v<<endl;
						qu.push(v);aedge(v,y+1);
						ng.insert(mp(v,z));
					}
				}
			}
			it++;
		}
	}
	if(!sumi[n-1]) cout<<-1<<endl;
	else cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 68984
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
int main()
{
	int h,w,j,i;
	cin>>h>>w;
	char arr[h][w];
	for(i=0;i<h;i++)
	{
		for(j=0;j<w;j++)
			cin>>arr[i][j];
	}
	long long int dp[h][w];
	dp[0][0]=1;

	for(i=1;i<h;i++)
	{
      if(arr[i-1][0]=='.' && arr[i][0]=='.') 
       dp[i][0]=dp[i-1][0];
     else
     	dp[i][0]=0;
	}
	for(j=1;j<w;j++)
	{
		if(arr[0][j-1]=='.' && arr[0][j]=='.')
			dp[0][j]=dp[0][j-1];
		
		else 
			dp[0][j]=0;
	}
	for(i=1;i<h;i++)
	{
		for(j=1;j<w;j++)
		{
			if(arr[i][j]=='.')
			{
				dp[i][j]=(dp[i-1][j]%mod+dp[i][j-1]%mod)%mod;
			}
			else
			{
				dp[i][j]=0;
			}
		}
	}
	cout<<dp[h-1][w-1];
	return 0;
}

Measured memory_bytes: 12320
using System;
using System.Collections;
using System.Collections.Generic;

public class Prigram
{
	public static void Main()
	{
        string[] s = Console.ReadLine().Split(' ');
        int N, M;
        N = int.Parse(s[0]);
        M = int.Parse(s[1]);
        uint D = ~(uint)0;
        for(int i = 0; i < N; i++)
        {
            uint f = 0;
            s = Console.ReadLine().Split(' ');
            int K = int.Parse(s[0]);
            for (int j = 0; j < K; j++)
            {
                f |= ((uint)1 << int.Parse(s[j + 1])-1);
            }
            D &= f;
        }
        int c = 0;
        for(int i = 0; i < 30; i++)
        {
            if (D % 2 == 1)
                c++;
            D >>= 1;
        }
        Console.WriteLine(c);
    }
}


Measured memory_bytes: 13140
#include <iostream>
using namespace std;
int main(){
  string a;
  cin>>a;
  if(a=="SUN")cout<<7;
  if(a=="SAT")cout<<1;
  if(a=="FRI")cout<<2;
  if(a=="THU")cout<<3;
  if(a=="WED")cout<<4;
  if(a=="TUE")cout<<5;
  if(a=="MON")cout<<6;
}

Measured memory_bytes: 256