akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printve(vector<T>& v) {int n = sz(v); REP(i, n) cerr << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    REP(i, h) cin >> s[i];
    vvi sum(h + 1, vi(w + 1, 0));
    REP(i, h) {
        REP(j, w) {
            if (s[i][j] == '1') sum[i + 1][j + 1] = sum[i + 1][j] + 1;
            else sum[i + 1][j + 1] = sum[i + 1][j];
        }
    }
    REP1(j, w) {
        REP(i, h) {
            sum[i + 1][j] += sum[i][j];
        }
    }

    int ans = INF;
    REP(i, 1 << (h - 1)) {
        vi v;
        REP(j, h - 1) {
            if ((1 & i >> j) == 1) {
                v.emplace_back(j + 1);
            }
        }
        v.emplace_back(h);
        int t = sz(v) - 1;
        int q = 0;
        REP1(j, w) {
            int p = 0;
            for (auto u : v) {
                if (sum[u][j] - sum[p][j] - (sum[u][q] - sum[p][q]) > k) {
                    if (q + 2 >= j) {
                        if (sum[u][j] - sum[p][j] - (sum[u][j - 1] - sum[p][j - 1]) > k) {
                            t = INF;
                            break;
                        }
                    }
                    q = j - 1;
                    t++;
                    break;
                }
                p = u;
            }
        }
        chmin(ans, t);
    }
    cout << ans << endl;
}


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

int main() {
  string s; cin >> s;
  int K; cin >> K;
  vector<string> v;
  for (int i = 0; i < s.size(); ++i) {
    for (int j = 1; j <= min(5, (int)s.size() - i); ++j) {
      v.push_back(s.substr(i, j));
    }
  }

  sort(begin(v), end(v));
  v.erase(unique(begin(v), end(v)), end(v));
  cout << v[K - 1] << endl;
  return 0;
}


Measured memory_bytes: 1660
#include <cstdio>

using namespace std;

int main() {
    int k, a, b;
    
    scanf("%d %d %d", &k, &a, &b);
    
    if (b > a + 2 && a + 1 <= k) {
        k -= a - 1;
        printf("%lld\n", (long long)k / 2 * (b - a) + a + k % 2);
    } else {
        printf("%d\n", k + 1);
    }
    
    return 0;
}


Measured memory_bytes: 128
#![allow(unused_imports)]
use proconio::{input, fastout};
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
    n: usize,
    k: usize,
    lr: [(usize, usize); k]
    }
    let mut s = vec![ModInt::zero(); n + 1];
    s[1] = ModInt::one();
    for i in 2..=n {
        let mut tmp = ModInt::zero();
        for j in 0..k {
            let (l, r) = lr[j];
            tmp += s[i.checked_sub(l).unwrap_or(0)]
                - s[i.checked_sub(r + 1).unwrap_or(0)];
        }
        s[i] = s[i - 1] + tmp;
    }
    println!("{}", s[n] - s[n - 1]);

}

// ---------- begin ModInt ----------
// Thank you @sansen for referring to code

const MOD: u32 = 998244353;

#[derive(Clone, Copy)]
struct ModInt(u32);

impl std::ops::Add for ModInt {
    type Output = ModInt;
    fn add(self, rhs: ModInt) -> Self::Output {
        let mut d = self.0 + rhs.0;
        if d >= MOD {
            d -= MOD;
        }
        ModInt(d)
    }
}

impl std::ops::AddAssign for ModInt {
    fn add_assign(&mut self, rhs: ModInt) {
        *self = *self + rhs;
    }
}

impl std::ops::Sub for ModInt {
    type Output = ModInt;
    fn sub(self, rhs: ModInt) -> Self::Output {
        let mut d = self.0 + MOD - rhs.0;
        if d >= MOD {
            d -= MOD;
        }
        ModInt(d)
    }
}

impl std::ops::SubAssign for ModInt {
    fn sub_assign(&mut self, rhs: ModInt) {
        *self = *self - rhs;
    }
}

impl std::ops::Mul for ModInt {
    type Output = ModInt;
    fn mul(self, rhs: ModInt) -> Self::Output {
        ModInt((self.0 as u64 * rhs.0 as u64 % MOD as u64) as u32)
    }
}

impl std::ops::MulAssign for ModInt {
    fn mul_assign(&mut self, rhs: ModInt) {
        *self = *self * rhs;
    }
}

impl std::ops::Neg for ModInt {
    type Output = ModInt;
    fn neg(self) -> Self::Output {
        ModInt(if self.0 == 0 { 0 } else { MOD - self.0 })
    }
}

impl std::fmt::Display for ModInt {
    fn fmt<'a>(&self, f: &mut std::fmt::Formatter<'a>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl std::str::FromStr for ModInt {
    type Err = std::num::ParseIntError;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let val = s.parse::<u32>()?;
        Ok(ModInt::new(val))
    }
}

impl From<usize> for ModInt {
    fn from(val: usize) -> ModInt {
        ModInt((val % MOD as usize) as u32)
    }
}

#[allow(dead_code)]
impl ModInt {
    pub fn new(n: u32) -> ModInt {
        ModInt(n % MOD)
    }
    pub fn zero() -> ModInt {
        ModInt(0)
    }
    pub fn one() -> ModInt {
        ModInt(1)
    }
    pub fn pow(self, mut n: u32) -> ModInt {
        let mut t = ModInt::one();
        let mut s = self;
        while n > 0 {
            if n & 1 == 1 {
                t *= s;
            }
            s *= s;
            n >>= 1;
        }
        t
    }
    pub fn inv(self) -> ModInt {
        assert!(self.0 > 0);
        self.pow(MOD - 2)
    }
}
// ---------- end ModInt ----------



Measured memory_bytes: 2820
A, B = map(int, input().split())
l = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1]
a = l.index(A)
b = l.index(B)

if a > b:
    print("Alice")
elif b > a:
    print("Bob")
else:
    print("Draw")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll A,B,X;
  cin>>A>>B>>X;
  if(A>X||A+B<X) {
cout<<"NO"<<endl;
  }
else {
cout<<"YES"<<endl;
}
}


Measured memory_bytes: 3560
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
       String s=sc.next();
	   String[] a=s.split("");
		int count1=0;
        int count0=0;

		for(int c=0;c<a.length;c++){
    		if(a[c].equals("0")){
            	count0++;
            }else{
             count1++;
            }
    	}
       int ans=a.length-Math.abs(count0-count1);
    
    	System.out.println(ans);
    }
}


Measured memory_bytes: 46924
# 以下ペースト可
D, G = [int(item) for item in input().split()]

comp_bounas_list = [[int(item) for item in input().split()] for _ in range(D)]

comp_all = []

for i in range(2**D):
    temp = []
    for j in range(D):
        if ((i >> j) & 1) == 1:
            temp.append(1)
        else:
            temp.append(0)
    comp_all.append(temp)

# print(comp_bounas_list)
# print(comp_all)

full_num_list = [item[0] for item in comp_bounas_list]

each_comp_point = []
for i, item in enumerate(comp_bounas_list):
    each_comp_point.append((i+1)*100*item[0]+item[1])

# print(full_num_list)
# print(each_comp_point)


temp_point_list = []

for each_pattern in comp_all:
    temp_num = 0
    temp_point = 0
    for j, item in enumerate(each_pattern):
            if item:
                temp_num += full_num_list[j]
                temp_point += each_comp_point[j]

    temp_point_list.append([temp_num, temp_point, each_pattern]) 

# print(temp_point_list)

# overの物を解候補にリスト化する
over_list = [item for item in temp_point_list if item[1] >= G]

# print(over_list)
# 全bitが立っている最大値はターゲットを超えているため必ず値を持つ
over_combo = min(over_list, key = lambda x:x[0])
# print(over_combo)

# underのものを解候補にリスト化する
under_combo = [item for item in temp_point_list if item[1] < G]

# print(over_combo)
# print(under_combo)


temp_res_list = []
is_search = True

for temp_combo in under_combo:
    temp_bit_list = temp_combo[2]
    temp_res_point = temp_combo[1]
    temp_res_num = temp_combo[0]
    # print(temp_combo)

    # print(temp_bit_list)
    for j, item in reversed(list(enumerate(temp_bit_list))):
        for _ in range(1, comp_bounas_list[j][0]):
            # print(temp_res_point)
            if item==0:
                temp_res_point += (j+1)*100
                temp_res_num += 1

            if temp_res_point >= G:
                temp_res_list.append([temp_res_num, temp_res_point])
                break

# print(temp_res_list)
# きっかりコンプすれば必ずターゲットを超える場合、値を持たない場合がある。
# ダミーでres_candiに全bitの立った値を入れておく
if temp_res_list != []:
    res_candi = min(temp_res_list, key=lambda x:x[0])
else:
    res_candi = temp_point_list[-1]

if over_combo[0] <= res_candi[0]:
    print(over_combo[0])
else:
    print(res_candi[0])

Measured memory_bytes: 3516
#include<bits/stdc++.h>
using namespace std;
int n;
string s;
map<string,int> cnt;

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

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    cin >> n;
    int maks = 0;
    for (int i = 0; i < n; i++) {
        cin >> s;
        cnt[s]++;
        maks = max(maks, cnt[s]);
    }

    for (auto p : cnt) {
        if (p.second == maks) cout<< p.first << '\n';
    }
}


Measured memory_bytes: 23808
N = int(input())
A = list(map(int, input().split()))
a = A.count(1)
b = A.count(2)
c = A.count(3)
"""
dp[i][j][k]: 残り１貫の皿がi, ２貫j, ３貫kの状態から全部食べ切るまでの期待値
"""
dp = [[[0.0] * (N+1) for _ in range(N+1)] for _ in range(N+1)]

# 先にiについて更新することで、dp[i""+1""][j-1][k]を可能にしている。
# 先にjについて更新することで、dp[i][j""+1""][k-1]を可能にしている。
for k in range(c + 1):
    for j in range(b + c + 1 - k): # ２貫の皿の数の最大値 - 3枚の皿の数
        for i in range(a + b + c + 1 - k - j):
            if i == 0 and j == 0 and k == 0:
                continue
            tmp = N * 1.0
            if i > 0:
                tmp += i * dp[i-1][j][k]
            if j > 0:
                tmp += j * dp[i+1][j-1][k]
            if k > 0:
                tmp += k * dp[i][j+1][k-1]
            dp[i][j][k] = tmp / (i + j + k)
print(dp[i][j][k])


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

int main() {
  int n,k,r,s,p; string t;
  cin>>n>>k>>r>>s>>p>>t;
  vector<string> v(k,"");
  rep(i,n){
    v[i%k].push_back(t[i]);
  }
  ll ans=0;
  rep(i,k){
    rep(j,v[i].size()){
      if(j!=0){if(v[i][j]==v[i][j-1]){v[i][j]='d';continue;}}
      if(v[i][j]=='r'){ans+=p;}
      if(v[i][j]=='s'){ans+=r;}
      if(v[i][j]=='p'){ans+=s;}
    }
  }
  cout<<ans;
 
}

Measured memory_bytes: 6060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

int n;
int k;
int main()
{
    cin >> n >> k;
    i64 ans = k;

    for(int i =1;i < n;i++)
    {
        ans *= k - 1;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

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

    int n, k;
    cin >> n >> k;

    vector<int> b(n);
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        a--;

        b[a]++;
    }

    sort(b.begin(), b.end());
    reverse(b.begin(), b.end());

    int r = 0;
    for (int i = 0; i < n; i++) {
        if (b[i] > 0) {
            r += b[i];
            if (--k <= 0) break;
        }
    }

    cout << n - r << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.*;
 
public class Main {
 	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int count = 0;

		for(int i=0; i<N; i++){
			int h = sc.nextInt();
			if(K<=h){
				count++;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 45488
#include <iostream>
using namespace std;
int main(){

int n1,n2,d1,d2;
  cin >> n1 >> d1 >> n2 >> d1;
  if (n1 != n2){
  cout << 1 << endl;
  }
  else{
  cout << 0 << endl;
  }
  
  
  return 0;
}



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

double ni(double a,double k){
  if(a>=k){
    return 0;
  }else{
    return ni(a*2,k)+1;
  }
}

int main(){
  double p=0;
  double N,K;
  cin>>N>>K;
  for(double i=1;i<=N;i++){
    double t=ni(i,K);
    p=p+1/(pow(2,t)*N);
  }
  cout<<setprecision(13)<<p<<endl;
    
}

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main()
{
    int N;
    cin >> N;
    cout << 180 + (N-3)*180 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int ways(int mask, int woman, int n, vector<vector<int> > &match, vector<vector<int> > &dp) {
    if (woman == n)
        return 1;
    if (dp[woman][mask] != -1)
        return dp[woman][mask];
    int currWays = 0;
    for (int man = 0; man < n; man++) {
        if ((mask & (1<<man)) && match[man][woman]) {
            currWays = (currWays % mod + ways(mask ^ (1<<man), woman+1, n, match, dp) % mod ) % mod;
        }
    }
    return dp[woman][mask] = currWays;
}
int main() {
    int n;
    cin>>n;
    vector<vector<int> > match(n, vector<int>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++)
            cin>>match[i][j];
    }
    vector<vector<int> > dp(n, vector<int> (1<<n, -1));
    cout<<ways((1<<n)-1, 0, n, match, dp)<<"\n";
    return 0;
}


Measured memory_bytes: 183464
#include<stdio.h>
int main(){
	int a,b,k;
	scanf("%d",&k);
	scanf("%d%d",&a,&b);
    int f=0;
    for(int i=a;i<=b;i++){
    	if(i%k==0){
    		f=1;
    		break;
		}
	}
	if(f) printf("OK");
	else printf("NG");
	return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
typedef long long LL;
std::vector<LL> vc;
int main()
{
    int N;
    LL minn = 1e18;
    std::cin >> N;
    vc.resize(N + 1);
    LL max_pos = 0, min_pos = 1e18;
    for (int i = 1; i <= N; i++)
    {
        std::cin >> vc[i];
        max_pos = std::max(max_pos, vc[i]);
        min_pos = std::min(min_pos, vc[i]);

    }
    for (LL i = min_pos; i <= max_pos; i++)
    {
        LL sum = 0;
        for (int j = 1; j <= N; j++)
        {
            sum += (vc[j] - i) * (vc[j] - i);
        }
        minn = std::min(minn, sum);
    }
    std::cout<<minn<<'\n';
}

Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt();
        int h = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int r = sc.nextInt();
        if(x>=0 && y>=0){
            if((x+r)<=w && (y+r)<=h){
                System.out.println("Yes");
            } else{
                System.out.println("No");
            }
        } else {
            System.out.println("No");
        }
        
    }
}


Measured memory_bytes: 26412
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

#define forn(i,n) for (int i = 0; i < int(n); ++i)
#define forsn(i,x,y) for(long long i = (x) ; i <= (y) ; ++i)
typedef long long ll;
typedef long double ld;

enum STATE {
  IDLE,
  CNTS,
  CNTT
};

int main() {
  string s;
  cin >> s;
  int prevtotal = s.size();
  int total = s.size();
  int scnt = 0;
  STATE st = IDLE;
  forn(i,s.size()) {
    switch (st) {
      case IDLE :
        scnt = 0;
        if(s[i] == 'S') {
          scnt++;
          st = CNTS;
        }
        break;
      case CNTS :
        if(s[i] == 'T') {
          st = CNTT;
          total -= 2;
          scnt--;
        }
        else {
          scnt++;
        }
        break;
      case CNTT :
        if(s[i] == 'S') {
          scnt++;
          st = CNTS;
        }
        else {
          if(scnt > 0) {
            scnt--;
            total -= 2;
          }
        }
        break;
      default :
        break;
    }
  }
  cout << total << endl;

  return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

/*

??????
??\?????????????????¨?¨???§????????????????????????????????????????????°???????????????????????????????????????¨?????????£?????????????°?????????? x ????????¨?????????????????????

1x1=1
1x2=2
.
.
9x8=72
9x9=81
Input
?????????????????\????????????????????????

Output
1x1=1
1x2=2
.
.
9x8=72
9x9=81

*/

int main( void )
{
	int a, b;
	
	for ( a = 1 ; a <= 9 ; a++ ) {
		for ( b = 1 ; b <= 9 ; b++ ) {
			printf( "%dx%d=%d\n", a, b, a * b );
		}
	}
	
	return 0;
}

Measured memory_bytes: 524
s = list(input())
t = list(input())
change = len(t)

for i in range(len(s) - len(t) + 1):
    counter = 0
    for j, char in enumerate(s[i:i + len(t)]):
        if char == t[j]:
            counter += 1
    if change > (len(t) - counter):
        change = len(t) - counter

print(change)


Measured memory_bytes: 9056
#include<iostream>
#include<cstdio>
#include<cmath>
#define MAX 1000000
using namespace std;
bool prime[MAX];

void makeit(){
  for(int i=3;i<=MAX;i+=2)prime[i] = true;

  prime[2] = true;

  int lim = sqrt(MAX)+1;
  for(int i=3;i<=lim;i++){
    if(!prime[i])continue;
    for(int j=pow(i,2);j<=MAX;j+=i){
      prime[j] = false;
    }
  }
}


int main(){
  for(int i=0;i<MAX;i++)prime[i] = false;
  makeit();
  int a,b,c;
  int cou,i;
  while(cin >> a >> b >> c && a && b && c){
    cou = 0;
    for(i=a;cou != c;i+=b){
      if(prime[i])cou++;
    }
    cout << i-b << endl;
  }

  return 0;
}

Measured memory_bytes: 2136
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    while(cin >> n >> k, n or k) {
        vector<string> a(n);
        for(int i = 0; i < n; i++) {
            cin >> a[i];
        }
        sort(a.begin(), a.end());
        set<string> ans;
        do {
            string s;
            for(int i = 0; i < k; i++) {
                s += a[i];
            }
            ans.insert(s);
        } while(next_permutation(a.begin(), a.end()));
        cout << ans.size() << endl;
    }
    return 0;
}



Measured memory_bytes: 3380
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

int main(){FIN;
	ll n; cin>>n;
	if(n%2==1){
		cout<<n*(n-1)/2-n/2<<"\n";
		fore(i,1,n+1){
			fore(j,i+1,n+1){
				if(i+j!=n){
					cout<<i<<" "<<j<<"\n";
				}
			}
		}
	}else{
		cout<<n*(n-1)/2-n/2<<"\n";
		fore(i,1,n+1){
			fore(j,i+1,n+1){
				if(i+j!=n+1){
					cout<<i<<" "<<j<<"\n";
				}
			}
		}	
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
const int maxn=200005;
struct info{
	int x,y,id;
	inline info(int _x,int _y,int _id){x=_x;y=_y;id=_id;}
}p[maxn]=info(0,0,0);
int fa[maxn],cnt[maxn],n,a,b,dis;
i64 sz[maxn];
inline bool operator < (const info &a,const info &b){
	return (a.x<b.x)||(a.x==b.x&&a.y<b.y);
}
inline bool operator <= (const info &a,const info &b){
	return (a.x<b.x)||(a.x==b.x&&a.y<=b.y);
}
inline int find(int n){
	int step=n,x;
	while(fa[step]!=step)step=fa[step];
	while(n!=step)x=fa[n],fa[n]=step,n=x;return n;
}
inline void merge(int x,int y,int val){
	int v1=find(x),v2=find(y);
	if(v1==v2)sz[v1]+=val;
	else fa[v1]=v2,sz[v2]+=sz[v1]+val;
}
inline void solve(int val){
	memset(cnt,0,sizeof(cnt));
	for(int i=1,L=1,R=0;i<=n;i++){
		while(L<=n&&p[L]<info(p[i].x-dis,p[i].y-dis+val,0))L++;
		while(R<n&&p[R+1]<=info(p[i].x-dis,p[i].y+dis-val,0))R++;
		if(L<=R)merge(p[i].id,p[L].id,1),cnt[L]++,cnt[R]--;
	}
	rep(i,1,n)if(cnt[i]+=cnt[i-1])merge(p[i].id,p[i+1].id,cnt[i]);
}
int main(){
	read(n);read(a);read(b);
	rep(i,1,n){
		int x,y;read(x);read(y);
		p[i].x=x-y;p[i].y=x+y;
		p[i].id=i;
	}dis=max(abs(p[a].x-p[b].x),abs(p[a].y-p[b].y));
	rep(i,1,n)fa[i]=i;
	sort(p+1,p+1+n);solve(0);
	rep(i,1,n)swap(p[i].x,p[i].y);
	sort(p+1,p+1+n);solve(1);
	printf("%lld\n",sz[find(a)]);
	return 0;
}


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

const int N = 500009;
const int mod = 1000000007;

#define IOS                               \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);
#define int long long int
#define endl "\n"
#define sz(a) (int)((a).size())
#define all(a) a.begin(), a.end()

void pre()
{
}

int32_t main()
{
	IOS;
	pre();
	int x;
	cin >> x;
	if (x % 2 == 1)
	{
		cout << "0\n";
		return 0;
	}
	x /= 2;
	int ans = 0;
	while (x > 0)
	{
		ans += (x / 5);
		x /= 5;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int digits(int n){
	int count = 0; 
	while(n > 0){
		count ++; 
		n /= 2; 
	}
	return count; 
}
int ketawa(int n){
	int sum = 0; 
	while(n > 0){
		sum += n % 2; 
		n /= 2; 
	}
	return sum; 
}
int main(){
	int L; 
	cin >> L; 
	int N = digits(L); 
	int M = N * 2 + ketawa(L) - 3; 
	cout << N << " " << M << endl; 
	for(int i = 1; i < N; i++){
		cout << i << " " << i+1 << " " << 0 << endl; 
		cout << i << " " << i+1 << " " << (1 << (N - 1 - i)) << endl; 
	}
	for(int i = 2; i <= N; i++){
		int a = (L >> (N-i)); 
		if(a % 2) cout << 1 << " " << i << " " << ((a >> 1) << (N-i+1)) << endl; 
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <map>
#include <set>
#include <array>
#include <queue>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
#include <functional>
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;
typedef std::pair<int, int> P;

int W, a, b;

int main()
{
	in >> W >> a >> b;

	if (b > W + a)
	{
		out << b - (W + a) << std::endl;
	}
	else if (b < a && b+W < a)
	{
		out << a - (b + W) << std::endl;
	}
	else
	{
		out << 0 << std::endl;
	}
	return 0;
}

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

int main()
{
  int n,k,q;
  cin>>n>>k>>q;
  int a[q],b[n],i;
  string yes="Yes",no="No";
  for(i=0;i<n;i++){
    b[i]=k-q;
  }
  for(i=0;i<q;i++){
    cin>>a[i];
    b[a[i]-1]++;
  }
  for(i=0;i<n;i++){
    if(b[i]<=0){
      cout<<no<<endl;
    }
    else{
      cout<<yes<<endl;
    }
  }
  return 0;
}


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

int main()
{
	char s[101] = {NULL};
	char t[101] = {NULL};


	scanf("%s", s);
	scanf("%s", t);



	int len = (int)strlen(s);

	int n = 0;
	char temp;


	for (int i = 0; i < len; i++)
	{
		if (strcmp(s, t) == 0) { n = 1; }

		if (n == 1) break;

		temp = s[0];
		for (int j = 0; j <= len - 2; j++)
		{
			s[j] = s[j + 1];
		}
		s[len-1] = temp;
	}

	char yes[5]="Yes";
	char no[5] = "No";
	if (n == 0) printf("%s", no); 
	if (n == 1) printf("%s", yes);





	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n;
  cin >> n;
  VEC<bool> even(n);
  REP(i, 0, n) {
    LL a;
    cin >> a;
    even[i] = (a % 2 == 0);
  }
  bool all = 1;
  REP(i, 0, n) {
    if (!even[i]) {
      all = 0;
      break;
    }
  }
  if(all)cout<<"second"<<endl;
  else cout<<"first"<<endl;

  return 0;
}


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

int main(){
    int A, B, outlet=1,cnt=0;
    cin >> A >> B;

    while(outlet < B){
        outlet--;
        outlet += A;
        cnt++;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3596
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace AOJ_problem_01
{

    struct Point
    {
        public double x;
        public double y;
    }

    

    class Program
    {

        static void Koch(int n, Point a, Point b)
        {
            if(n == 0)
            {
                return;
            }

            Point s, t, u;
            double th = Math.PI * 60 / 180;

            s.x = (2 * a.x + b.x) / 3;
            s.y = (2 * a.y + b.y) / 3;
            t.x = (a.x + 2 * b.x) / 3;
            t.y = (a.y + 2 * b.y) / 3;
            u.x = (t.x - s.x) * Math.Cos(th) - (t.y - s.y) * Math.Sin(th) + s.x;
            u.y = (t.x - s.x) * Math.Sin(th) + (t.y - s.y) * Math.Cos(th) + s.y;

            Koch(n - 1, a, s);
            Console.WriteLine(String.Format("{0:f6} {1:f6}", s.x, s.y));
            Koch(n - 1, s, u);
            Console.WriteLine(String.Format("{0:f6} {1:f6}", u.x, u.y));
            Koch(n - 1, u, t);
            Console.WriteLine(String.Format("{0:f6} {1:f6}", t.x, t.y));
            Koch(n - 1, t, b);

        }


        static int n;
        
        static void Main(string[] args)
        {
            n = int.Parse(Console.ReadLine());

            Point a = new Point();
            Point b = new Point();

            a.x = 0;
            a.y = 0;
            b.x = 100;
            b.y = 0;

            Console.WriteLine(String.Format("{0:f6} {1:f6}", a.x, a.y));
            Koch(n, a, b);
            Console.WriteLine(String.Format("{0:f6} {1:f6}", b.x, b.y));

        }

    }

}




Measured memory_bytes: 18048
N,M = list(map(int, input().split()))
A = []
for _ in range(M):
    A.append(list(map(int, input().split())))

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


uf = UnionFind(N)
for i in range(M):
    uf.union(A[i][0]-1,A[i][1]-1)

ans = uf.group_count()-1

print(ans)

Measured memory_bytes: 90372
def resolve():
    n=int(input())
    l=[list(map(int, input().split())) for i in range(2)]
    maxame=0
    #yが降りる位置
    for y in range(0,n):
        ame=0
        #ｘが今の位置
        for x in range(0,n):
            if x<y:
                ame+=l[0][x]
            elif x>y:
                ame+=l[1][x]
            else:
                ame+=(l[0][x])+(l[1][x])
        if ame>maxame:
            maxame=ame
    print(maxame)
resolve()

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

int mod=1e9+7;
ll int n,m;

ll int pow(ll n,ll m,ll mod)
{
    ll int num=1;
    while(m)
    {
        if(m%2)
        {
            m--;
            num=(num*n)%mod;
        }
        else
        {
            m/=2;
            n=(n*n)%mod;
        }
    }
    return num;
}

ll int C(ll int n,ll int m)
{
    if(n<m)
        return 0;
    ll int  ans=1;
    for(int i=1; i<=m; i++)
    {
        ans=ans*(((n-m+i)%mod)*pow(i,mod-2,mod)%mod)%mod;
    }
    return ans;
}

int main()
{
    ll int a,b,c;
    while(cin>>a>>b>>c)
    {
        ll x=pow(2,a,mod)-1;
        ll y=C(a,b);
        ll z=C(a,c);
        ll zz=(y+z)%mod;
        if(x-zz>0)
        cout<<x-zz<<endl;
        else
        cout<<(x+mod-zz)%mod<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll INF = 1ll << 60;
const int N = 200100;

ll imos1[N], imos2[N];

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

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

  ll sum = 0;
  ll k = 0;
  for(int i=0;i<n;i++){
    k += i + 1;
    sum += a[i];
  }

  if(sum % k != 0){
    cout << "NO" << endl;
    return 0;
  }

  ll t = sum / k;
  ll tot = 0;

  for(int i=0;i<n;i++){
    int j = (i + 1) % n;

    ll d = a[j] - a[i];

    ll hoge = -d + t;
    if(hoge % n != 0){
      cout << "NO" << endl;
      return 0;
    }

    ll add = hoge / n;
    ll sub = t - add;

    if (add < 0 || add > t || sub < 0 || sub > t){
      cout << "NO" << endl;
      return 0;
    }

    imos1[i+1] += add;
    imos1[i+n+1] -= add;

    imos2[i+n+1] -= add * n;

    tot += add;
  }

  if(tot != t){
    cout << "NO" << endl;
    return 0;
  }

  for(int i=1;i<2*n;i++)imos1[i] += imos1[i-1];

  imos2[0] = imos1[0];
  for(int i=1;i<2*n;i++)imos2[i] += imos1[i] + imos2[i-1];

  bool res = true;
  for(int i=0;i<n;i++)res &= imos2[i] + imos2[i+n] == a[i];

  cout << (res ? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 4096
#pragma GCC optimze("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pp pair<ll,ll>
#define ppp pair<ll,pp >
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
typedef tree<pp,null_type,less<pp>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,a,b) for(ll i=a;i<b;i+=1)
#define sz(v) (ll)(v.size())
#define hell (ll)1000000007
#define slld(x) scanf("%lld",&x)
ll t=1, tt;
const ll inf=1e18, N=200005;
inline ll mult(ll x,ll y){x%=hell;y%=hell;return (1LL*x*y)%hell;}
inline ll add(ll x,ll y){x+=y;return x%hell;}
inline ll powMod(ll base,ll expo){
	if(base==0)return 0;
	ll ans=1;
	while(expo){
		if(expo&1)ans=mult(ans,base);
		base=mult(base,base); 
		expo>>=1;
	}
	return ans;
}
ll tr[4*N], lazy[4*N], ans[N];
ll combine(ll x,ll y){return max(x,y);}
void lazify(ll node,ll l,ll r){
	if(lazy[node]){
		tr[node]+=lazy[node];
		if(l!=r){
			lazy[node<<1]+=lazy[node];
			lazy[node<<1|1]+=lazy[node];
		}
	}
	lazy[node]=0;
}
void update(ll node,ll l,ll r,ll a,ll b,ll val){
	lazify(node,l,r);
	if(b<l || r<a || l>r)return;
	if(a<=l and r<=b){
		tr[node]+=val;
		if(l!=r){
			lazy[node<<1]+=val;
			lazy[node<<1|1]+=val;
		}
		return;
	}
	ll mid=(l+r)/2;
	update(node<<1,l,mid,a,b,val);
	update(node<<1|1,mid+1,r,a,b,val);
	tr[node]=combine(tr[node<<1],tr[node<<1|1]);
}
void assign(ll node,ll l,ll r,ll id,ll val){
	lazify(node,l,r);
	if(l==r){
		tr[node]=val;
		return;
	}
	ll mid=(l+r)/2;
	if(l<=id and id<=mid)
		assign(node<<1,l,mid,id,val);
	else
		assign(node<<1|1,mid+1,r,id,val);
	tr[node]=combine(tr[node<<1],tr[node<<1|1]);
}
ll query(ll node,ll l,ll r,ll a,ll b){
	lazify(node,l,r);
	if(l>b || a>r || l>r)return -inf;
	if(a<=l and r<=b)return tr[node];
	ll mid=(l+r)/2;
	return combine(query(node<<1,l,mid,a,b),query(node<<1|1,mid+1,r,a,b));
}
void solve(){
	ll n, res=0;
	cin>>n;
	vector<ll> h(n), a(n);
	for(auto &x : h)
		cin>>x;
	for(auto &x : a)
		cin>>x;
	rep(i,0,n){
		ans[h[i]]=max(0LL,query(1,1,N,1,h[i]-1))+a[i];
		assign(1,1,N,h[i],ans[h[i]]);
		res=max(res,ans[h[i]]);
	}
	cout<<res;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   	//cin>>t;
   	tt=t;
    while(t--){
        solve();
        if(t)cout<<"\n";
    }
    return 0 ;
}


Measured memory_bytes: 15616
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n; cin >> n;
  bool ans = false;
  for(int i = 0; i <=25; ++i){
   for(int j = 0; j <=14; ++j){
    int x = (4*i) + (7*j);
    if(x == n){
        ans = true;
        break;
    }
   }
  }
  cout << (ans ? "Yes":"No") << '\n';
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;

int main()
{
    int r;
    cin >> r;
    cout << r * r << endl;
    return 0;
}

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

const int M = 998244353;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> lr(k);
  for (int i = 0; i < k; i++) {
    cin >> lr[i].first >> lr[i].second;
  }
  vector<int> dp(n + 1);
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      dp[i] = (dp[i] + dp[max(i - lr[j].first, 0)] - dp[max(i - lr[j].second - 1, 0)]) % M;
      if (dp[i] < 0) {
        dp[i] += M;
      }
    }
    if (i != n) {
      dp[i] = (dp[i] + dp[i - 1]) % M;
    }
  }
  cout << dp[n] << '\n';
  return 0;
}

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

int main() {
  int N, T;
  cin >> N >> T;
  int res = 10000000;
  for (int i = 0; i < N; ++i) {
    int c, t;
    cin >> c >> t;
    if (t <= T) res = min(res, c);
  }
  if (res < 10000000) cout << res << endl;
  else cout << "TLE" << endl;
}

Measured memory_bytes: 3572
#include<stdio.h>
#include<stdlib.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
int compare(const void *a, const void *b){
    return *(int*)a - *(int*)b;
}
int main(void){
  int n,cnt=0,max=0,ans=0;
  scanf("%d",&n);
  PRN(n/2-15);
  return 0;
}


Measured memory_bytes: 2080
#include <bits/stdc++.h>
#define rep(i,n) for(long long i = 0; i < (long long)(n); ++i)

using namespace std;
using ll = long long;

int main() {
	int k, n;
	int ans = 0;
	cin >> k >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	rep (i, n - 1) ans = max(ans, a[i + 1] - a[i]);
	ans = max(ans, (k - a[n - 1]) + a[0]);
	cout << k - ans << endl;
	return 0;
}


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

int main()
{
    string s,t;
    cin>>s>>t;
    sort(s.begin(),s.end(),less<char>());
    sort(t.begin(),t.end(),greater<char>());
    if(s<t)cout<<"Yes";
    else cout<<"No";
    return 0;
}


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

using namespace std;


int main(){
    int N,D;
    cin >> N >> D;
    vector<vector<int>> X(N,vector<int>(D));
    for(int i=0;i<N;i++){
        for(int j=0;j<D;j++){
            cin >> X.at(i).at(j);
        }
    }

    int P = 0;
    for(int i=0;i<N-1;i++){
        float ans = 0,ans1 = 0;
        for(int k=i+1;k<N;k++){
            ans = 0,ans1 =0;
            for(int j=0;j<D;j++){
                ans += pow(X.at(i).at(j)-X.at(k).at(j),2);
            }
            ans1 = sqrt(ans);
            if(ans1 == int(ans1)) P++; 
        }
    }
    cout << P << endl;
    
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> T;
#define INF (1 << 30)

vector<T> coner;
int ax, ay, bx, by, n, r, p;
int round, area, left_side, right_side, bottom, top;
int imos[3][10500];
int main(){
    while(cin >> n >> r, n | r){
	memset(imos, 0, sizeof(imos));
	round = area = 0;
	p = 0;
	left_side = bottom = 1;
	right_side = top = 10400;
	coner.clear();
	for(int i = 0;i < n;i++){
	    cin >> ax >> ay >> bx >> by;

	    
	    coner.push_back(T(P(++ax, ++ay), 1));
	    coner.push_back(T(P(++bx, ++by), 1));
	    coner.push_back(T(P(bx, ay), -1));
	    coner.push_back(T(P(ax, by), -1));
	}
	coner.push_back(T(P(INF, INF), 0));
	sort(coner.begin(), coner.end());
	for(int i = left_side;i < right_side + 2;i++){
	    for(int j = bottom;j < top + 2;j++){
		imos[i % 3][j] = imos[i % 3][j - 1];
		while(coner[p].first == P(i, j)){
		    imos[i % 3][j] += coner[p++].second;
		}
	    }
	    for(int j = bottom;j < top + 2;j++){
		imos[i % 3][j] += imos[(i - 1) % 3][j];
		if(imos[i % 3][j])area++;
		if(!!imos[i % 3][j] != !!imos[i % 3][j - 1])round++;
		if(!!imos[i % 3][j] != !!imos[(i - 1) % 3][j])round++; 
	    }

	}
	cout << area << endl;
	if(r == 2)cout << round << endl;
    }
    return 0;
}

Measured memory_bytes: 2172
from itertools import combinations_with_replacement as cwr

n, m, q = map(int, input().split())
lis = range(1, m + 1)
cdt = list(cwr(lis,n))
res = [0] * len(cdt)

for i in range(q):
    a, b, c, d = map(int, input().split())
    for j, k in enumerate(cdt):
        if k[b-1] - k[a-1] == c:
            res[j] += d
print(max(res))


Measured memory_bytes: 25188
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    // 数値の配列を作る
    const numList0 = input[0].split(' ').map(x => parseInt(x, 10));
    const N = numList0[0];
    const pList = input[1].split(' ').map(x => parseInt(x, 10));

    var count = 0;
    for (var i = 0; i < N; i++) {
        if (i + 1 !== pList[i]) {
            count++;
        }
        if (count > 2) {
            break;
        }
    }

    if (count <= 2) {
        console.log('YES');
    } else {
        console.log('NO');
    }
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
	int n;

	scanf("%d\n",&n);
	if(n%2==1){
		n=n/2+1;
	}else{
		n=n/2;
	}
	printf("%d",n);
	return 0;
}


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

const ll mxs = 1e18 + 10;
int main(){
    int N, W;
    cin>>N>>W;
    ll w[N], v[N];
    
    for(int i = 0; i < N; i++)
        cin>>w[i]>>v[i];
    int V = 0;
    for(auto x : v){
        V += x;
    }
    vector<ll> dp(V + 1,INT_MAX);
    dp[0]=0;
    for(int i = 0; i < N; i++){
        vector<ll> ndp(V + 1);
        for(int j = 0; j <= V; j++){
            if(j >= v[i])
                ndp[j] = min(dp[j], (ll) w[i] + dp[j - v[i]]);
            else
                ndp[j] = dp[j];
        }
        dp = ndp;
    }
    int res = 0;
    for(int i = V; i >= 0; i--){
        if(dp[i] <= W){
            res = i;
            break;
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 4824
import math

n, m, k = list(map(int, input().split()))

MOD=998244353

fact = [0] * (n+1)
inv = [0] * (n+1)
factinv = [0] * (n+1)

fact[0]=fact[1]=1
inv[1]=1
factinv[0]=factinv[1]=1

for i in range(2,n+1):
    fact[i] = fact[i-1] * i % MOD
    inv[i] = MOD - (( inv[MOD % i] *  (MOD // i)) % MOD )
    factinv[i] = factinv[i-1] * inv[i] % MOD

def cbn(n, k, fact, factinv, MOD):
    return fact[n] * factinv[n-k] * factinv[k] % MOD

def power(x, n, MOD):
    if n == 0:
        return 1
    elif n % 2 == 0:
        return power(x*x % MOD , n // 2, MOD) % MOD
    else:
        return x * power(x * x % MOD, n // 2, MOD) % MOD

s = 0
for i in range(k+1):
    s += cbn(n-1, i, fact, factinv, MOD) * m * power(m-1, n-1-i, MOD)

print(s % MOD)


Measured memory_bytes: 32616
fun main(arg: Array<String>) {
    val (H, W, A, B) =  listOfInt()
    var ans = ModInt(0)
    for (h in 1 .. H - A) {
        if (B == W - 1 && h != H - A) continue
        ans += comb(h - 1 + B, B) *
            comb(H - h + W - B - if (h != H - A) 2 else 1, H - h)
    }
    println(ans)
}

var fac = mutableListOf<ModInt>()
private fun fact(n: Int): ModInt {
    if (fac.count() == 0) fac.add(ModInt(1))
    while (fac.count() <= n) {
        fac.add(fac.last() * ModInt(fac.count()))
    }
    return fac[n]
}
private fun comb(n: Int, k: Int) = fact(n) / fact(k) / fact(n - k)


data class ModInt(private var v: Long) {
    companion object { private const val MOD = 1000000007L }
    init { this.v %= MOD }
    constructor(n: Int): this(n.toLong())
    operator fun plus(other: Int) = ModInt((this.v + other) % MOD)
    operator fun plus(other: ModInt) = ModInt((this.v + other.v) % MOD)
    operator fun minus(other: Int) = ModInt((this.v + MOD - other) % MOD)
    operator fun minus(other: ModInt) = ModInt((this.v + MOD - other.v) % MOD)
    operator fun times(other: Int) = ModInt(this.v * other % MOD)
    operator fun times(other: ModInt) = ModInt(this.v * other.v % MOD)
    operator fun div(other: ModInt) = ModInt(this.v * pow(other.v, MOD - 2) % MOD)
    private fun pow(a: Long, b: Long): Long {
        if (b == 0L) return 1L
        if (b % 2 == 0L) {
            val d = pow(a, b / 2)
            return (d * d) % MOD
        }
        return a * pow(a, b - 1) % MOD
    }
    override fun toString() = this.v.toString()
}

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }


Measured memory_bytes: 49392
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,i,d,s=0,x,y;
    float m;
    cin>>n>>d;
    while(n--){
        cin>>x>>y;
        if(((x*x)+(y*y))<=d*d)
            s++;
    }
    cout<<s<<endl;



}


Measured memory_bytes: 3624
#include <iostream>

int main()
{
  int A, B, C, D, result = 0;
  std::cin >> A >> B >> C >> D;
  
  int max, min;
  if(D > B)
  {
    max = B;
  }
  else
  {
    max = D; 
  }
  
  if(A > C)
  {
    min = A; 
  }
  else
  {
    min = C; 
  }
  
  if(B < C || D < A)
  {
    result = 0; 
  }
  else
  {
    result = max - min; 
  }
  
  std::cout << result;
  return 0;
}

Measured memory_bytes: 3164
/* ex9_2
   Graku */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct node {
    struct node *next;
    char binary;
}node;

int get_last(node *l);
node* pop(node *l);
node* push(node *l, char n);

int main() {
    node *list = NULL;
    int count = 0;
    char s[100000];
    scanf("%s", s);

    for (int i = 0; i < strlen(s); i++) {
        if (list == NULL) { //list is empty
            list = push(list, s[i]);
        }
        else if (list->binary != s[i]) { //end of list is "01" or "10"
            list = pop(list);
            count += 2;
        }
        else { //end of list is "00" or "11"
            list = push(list, s[i]);
        }
    }

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

node* pop(node *list) {
    if (list == NULL) { //list is empty
        printf("Error: list is NULL\n");
        exit(1);
    }
    if (list->next == NULL) { //list has one element
        return NULL; //list is empty
    }
    node *head = list->next;
    free(list);
    return head;
}

node* push(node *list, char c) {
    node *new = malloc(sizeof(node)); //new element
    new->next = list; //new is end of list
    new->binary = c;
    return new;
}

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

int main(){
    int a,p;
    cin >> a >> p;
    int sum = a * 3 +p;
    cout << sum/2 << endl;
}

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

int main(void) {
  int D, N;
  cin >> D >> N;
  int p = 1;
  for (int i = 0; i < D; i++) p *= 100;
  if (N < 100) {
    cout << N * p << endl;
  } else {
    cout << 101 * p << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
 
  int n;
  cin >> n;
  int a = 1;
  while (true) {
    a *= 2;
    if (a > n) {
      a /= 2;
      break;
    }
  }
 
  cout << a << endl;
 
  return 0;
}

Measured memory_bytes: 256