akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

char mp[11][1111];
int sum[11];
int cou[11];

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

	ll h, w, k;cin >> h >> w >> k;
	REP(i, h){
		REP(j, w){
			cin >> mp[i][j];
		}
	}


	ll ans = INF;
	REP(mask, 1 << (h - 1)){
		//cout << bitset<10>(mask) << endl;
		bool ng = false;
		ll now = 0;
		REP(i, 11)if(mask & (1 << i))now++;
		REP(i, 11)sum[i] = 0;
		REP(j, w){
			REP(i, 11)cou[i] = 0;
			bool flag = false;
			int tmp = 0;
			REP(i, h){
				if(mp[i][j] == '1')cou[tmp]++;
				if(cou[tmp] + sum[tmp] > k)flag = true;
				if(cou[tmp] > k)ng = true;
				if(mask & (1 << i))tmp++;
			}
			if(flag){
				now++;
				REP(i, 11)sum[i] = 0;
			}
			//cout << "flag " << flag << endl;
			REP(i, 11)sum[i] += cou[i];
		}
		if(!ng)ans = min(ans, now);
		//cout << now << " " << ng << endl;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = LIST()
b = [0]*n
k = 0
for i in range(n//2):
    k += a[2*i+1] - a[2*i]

b[0] = a[n-1] - k
b[n-1] = a[n-1] + k

for i in range(1, n-1):
    b[i] = 2*a[i-1] - b[i-1]
print(*b)

Measured memory_bytes: 21984
use std::collections::HashMap;
#[derive(Default)]
//NOTE
//declare variables to reduce the number of parameters for dp and dfs etc.
struct Solver {}

impl Solver {
    fn solve(&mut self) {
        let stdin = std::io::stdin();
        let mut scn = Scanner {
            stdin: stdin.lock(),
        };
        let n: usize = scn.read();
        let mut cnts = HashMap::new();
        for _ in 0..n {
            let a: String = scn.read();
            *cnts.entry(a).or_insert(0) += 1;
        }
        println!("AC x {}", cnts.get("AC").unwrap_or(&0));
        println!("WA x {}", cnts.get("WA").unwrap_or(&0));
        println!("TLE x {}", cnts.get("TLE").unwrap_or(&0));
        println!("RE x {}", cnts.get("RE").unwrap_or(&0));
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| {
            let mut solver = Solver::default();
            solver.solve()
        })
        .unwrap()
        .join()
        .unwrap();
}
pub mod utils {
    const DYX: [(isize, isize); 8] = [
        (0, 1),   //right
        (1, 0),   //down
        (0, -1),  //left
        (-1, 0),  //top
        (1, 1),   //down right
        (-1, 1),  //top right
        (1, -1),  //down left
        (-1, -1), //top left
    ];

    pub fn try_adj(y: usize, x: usize, dir: usize, h: usize, w: usize) -> Option<(usize, usize)> {
        let ny = y as isize + DYX[dir].0;
        let nx = x as isize + DYX[dir].1;
        if ny >= 0 && nx >= 0 {
            let ny = ny as usize;
            let nx = nx as usize;
            if ny < h && nx < w {
                Some((ny, nx))
            } else {
                None
            }
        } else {
            None
        }
    }
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 2236
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define endl        "\n"

const int mod = 1e9+7;

inline int add(int a, int b) { int res = a + b; if(res >= mod) res -= mod;  return res; }
inline int sub(int a, int b) { int res = a - b; if(res < 0) res += mod; return res;}
inline int mul(int a, int b) { return (a * b)%mod; }

void solve() {
    int n; string s;
    cin >> n >> s;
    int pr[n+1], pg[n+1], pb[n+1];
    pr[0] = 0, pg[0] = 0, pb[0] = 0;
    for(int i=1; i<=n; i++) {
        pr[i] = pr[i-1] + (s[i-1]=='R');
        pb[i] = pb[i-1] + (s[i-1]=='B');
        pg[i] = pg[i-1] + (s[i-1]=='G');
    }
    int ans = 0;
    for(int j=2; j<n; j++) {
        int tot = (j-1)*(n-j);
        int lr = pr[j-1], rr = pr[n] - pr[j];
        int lg = pg[j-1], rg = pg[n] - pg[j];
        int lb = pb[j-1], rb = pb[n] - pb[j];
        tot -= lr*rr + lg*rg + lb*rb;
        if(s[j-1]=='R') {
            tot -= lr*(rb + rg) + rr*(lb + lg);
        } else if(s[j-1]=='G') {
            tot -= lg*(rb + rr) + rg*(lb + lr);
        } else {
            tot -= lb*(rr + rg) + rb*(lr + lg);
        }
        int i = j-1, k = j+1;
        while(i>0 && k<=n) {
            if(s[i-1] != s[j-1] && s[j-1] != s[k-1] && s[k-1] != s[i-1]) 
                tot--;
            i--, k++;
        }
        ans += tot;
    }
    cout << ans << endl; 
}

signed main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(12);

    int T = 1;
    //cin >> T;

    while(T--) {
        solve();
    }
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) cin >> a.at(i);
  
  int mn = a[0], mx = a[0];
  for (int i = 1; i < N; i++) {
    if (a[i] > mx) mx = a[i];
    if (a[i] < mn) mn = a[i];
  }
  
  cout << mx - mn << endl;
  
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; ++i)
using namespace std;

int main() {
  int N; cin >> N;
  vector<int> cnt(100001,0);
  int mx = -1;
  REP(i,N) {
    int tmp; cin >> tmp;
    ++cnt[tmp]; ++cnt[tmp + 1]; ++cnt[tmp + 2];
    mx = max({mx, cnt[tmp], cnt[tmp + 1], cnt[tmp + 2]});
  }
  cout << mx << endl;
  return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main() {
	int n, m, d1, d2, ans;

	scanf("%d%d", &n, &m);
	ans = 1;
	for (d1 = 1; d1 <= m / d1; d1++)
		if (m % d1 == 0) {
			if (m / d1 >= n && ans < d1)
				ans = d1;
			d2 = m / d1;
			if (m / d2 >= n && ans < d2)
				ans = d2;
		}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string s;
    int n,ans=0;
    cin>>n>>s;
    
    for(int i=0;i<n;i++){
        if(s[i]!=s[i+1]){
            ans++;
        }
        else if(s[i]==s[i+1]){
            
        }
    }
    
    cout<<ans<<endl;
    
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
      int a,b;

      scanf("%d", &a);
      scanf("%d", &b);

      if(a < b){
        printf("a < b\n");
      }
      if(a > b){
        printf("a > b\n");
      }
      if(a == b){
        printf("a == b\n");
      }

      return 0;
}


Measured memory_bytes: 2068
def main():
    N, H = map(int, input().split())

    A = [-1] * N
    B = [-1] * N
    for n in range(N):
        a, b = map(int, input().split())
        A[n] = a
        B[n] = b
    
    B.sort(reverse=True)
    max_A = max(A)
    
    count = 0
    for b in B:
        if max_A < b:
            H -= b
            count += 1
            if H <= 0:
                return count
        else:
            break
    return (H - 1) // max_A + 1 + count

print(main())

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

using namespace std;

int main()
{
    //int A, B, C, D, E;
    //cin >> A >> B >> C >> D >> E;
    std::vector<int> v;
    int tmp;
    int ans = 0;
    int fracMin = 10;
    int frac;
    int mainPart;
    for (int i = 0; i < 5; ++i)
    {
        cin >> tmp;
        frac = tmp % 10;
        mainPart = tmp - frac;
        if (frac != 0)
        {
            mainPart += 10;
            if (frac < fracMin)
                fracMin = frac;
        }
        ans += mainPart;
    }

    ans = ans - (10 - fracMin);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int total = 0;
		int min = Integer.MAX_VALUE;
		for (int i = 0; i < n; i++) {
			int s = sc.nextInt();
			total += s;
			if (s % 10 != 0 && min > s) {
				min = s;
			}
		}
		if (total % 10 == 0) {
			if (min == Integer.MAX_VALUE) {
				System.out.println(0);
			} else {
				System.out.println(total - min);
			}
		} else {
			System.out.println(total);
		}
	}
}


Measured memory_bytes: 23380
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+7;
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n;
    int p,a,b,c[3] = {0};
    cin>>n>>a>>b;
    for(int i=0;i<n;i++){
        cin>>p;
        if(p<=a)
            c[0]++;
        else if(p<=b)
            c[1]++;
        else
            c[2]++;
    }
    cout<<min(c[0],min(c[1],c[2]))<<endl;

    return 0;
}


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

#define fi first
#define se second
#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define pb push_back

const int N = 1e2 + 10;

int n, row, col;

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

    cin >> n >> row >> col;
    cout << (n - row + 1) * (n - col + 1);
}


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

using namespace std;

int main(){
  
  int A;
  string op;
  int B;
  
  cin >> A >> op >> B;
  
 if( op == "+"){
   
   cout << A+B << endl;
 }
  else if ( op == "-"){
    cout << A-B << endl;
  }
}
  

Measured memory_bytes: 3624
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;

int main() {
	int H, W, M;
	cin >> H >> W >> M;
	map<int, int> NumsY, NumsX;
	set<pair<int, int>> Points;
	for (int i = 0; i < M; i++) {
		int h, w;
		cin >> h >> w;
		Points.insert({ h,w });
		NumsY[h]++;
		NumsX[w]++;
	}
	int YMaxNum = 0;
	for (auto p : NumsY) YMaxNum = max(YMaxNum,p.second);
	vector<int> YMaxs;
	for (auto p : NumsY) if (p.second == YMaxNum) YMaxs.push_back(p.first);
	int XMaxNum = 0;
	for (auto p : NumsX) XMaxNum = max(XMaxNum, p.second);
	vector<int> XMaxs;
	for (auto p : NumsX) if (p.second == XMaxNum) XMaxs.push_back(p.first);
	for (int y : YMaxs) {
		for (int x : XMaxs) {
			if (Points.find({ y,x }) == Points.end()) {
				cout << YMaxNum + XMaxNum << endl;
				return 0;
			}
		}
	}
	cout << YMaxNum + XMaxNum - 1 << endl;
}


Measured memory_bytes: 49588
#include <bits/stdc++.h>
#define MAX (ll)(2e5 + 7)
#define INF (ll)(1e17)
#define MOD (int)(1e9 + 7)
#define PI (double)(3.14159265)
#define IO ios_base :: sync_with_stdio (false);
#define LOG 25

using namespace std;
using ll = long long;
int ar[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main () {
	int k;
	cin >> k;
	cout << ar[k - 1] << "\n";
}


Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)

struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;

int n;
int p[202020];

int main(){
    cin >> n;
    REP(i, n)cin >> p[i];
    int ans = 0;
    int minl = HINF<int>();
    REP(i, n){
        if(minl > p[i]){
            ans++;
            minl = p[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000
/*
2019 5.11
7.3 Quick Sort
*/

struct Card {
    char suit;
    int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int n, int left, int mid, int right) {
    int i, j, k;
    int n1 = mid - left;
    int n2 = right - mid;
    for(i = 0; i < n1; i++) L[i] = A[left + i];
    for(i = 0; i < n2; i++) R[i] = A[mid + i];
    L[n1].value = R[n2].value = SENTINEL;
    i = j = 0;
    for (k = left; k < right; k++) {
        if(L[i].value <= R[j].value){
            A[k] = L[i++];
        } else {
            A[k] = R[j++];
        }
    }
}

void mergeSort(struct Card A[], int n, int left, int right){
    int mid;
    if (left + 1 < right){
        mid = (left + right) / 2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}

int partition(struct Card A[], int n, int p, int r){
    int i, j;
    struct Card t, x;
    x = A[r];
    i = p - 1;
    for (j = p; j < r; j++){
        if(A[j].value <= x.value) {
            i++;
            t = A[i]; A[i] = A[j]; A[j] = t;
        }
    }
    t = A[i+1]; A[i+1] = A[r]; A[r] = t;
    return i + 1;
}

void quickSort(struct Card A[], int n, int p, int r){
    int q;
    if (p < r) {
        q = partition(A, n, p, r);
        quickSort(A, n, p, q - 1);
        quickSort(A, n, q + 1, r);
    }
}

int main() {
    int n, i, v;
    struct Card A[MAX], B[MAX];
        // For MergeSort & QuickSort
    char S[10];
    int stable = 1;

    scanf("%d", &n);

    for(i = 0; i < n; i++){
        scanf("%s %d", S, &v);
        A[i].suit = B[i].suit = S[0];
        A[i].value = B[i].value = v;
    }

    mergeSort(A, n, 0, n);
    quickSort(B, n, 0, n - 1);

    for (i = 0; i < n; i++){
        if(A[i].suit != B[i].suit) stable = 0;
    }

    if(stable == 1) printf("Stable\n");
    else printf("Not stable\n");
    for(i = 0; i < n; i++){
        printf("%c %d\n", B[i].suit, B[i].value);
    }

    return 0;
}



Measured memory_bytes: 4064
fn main() {
    let (n, a) = input();
    let ans = solve(n, a);
    for n in ans.iter() { println!("{}", n); }
}

fn input() -> (u64, Vec<u64>) {
    let mut buf1 = String::new();
    let mut buf2 = String::new();
    std::io::stdin().read_line(&mut buf1).unwrap();
    std::io::stdin().read_line(&mut buf2).unwrap();
    buf1.pop();
    buf2.pop();
    let n: u64 = buf1.parse().unwrap();
    let mut iter = buf2.split_whitespace();
    let a: Vec<u64> = iter.map(|x| x.parse().unwrap()).collect();
    (n, a)
}

fn solve(n: u64, a: Vec<u64>) -> Vec<u32> {
    let n: usize = n as usize;
    let mut subordinate: Vec<u32> = vec![0u32; n];
    for num in a.iter() {
        subordinate[*num as usize - 1] += 1;
    }
    subordinate
}

Measured memory_bytes: 5020
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

ll a[100005];
int main()
{
  ll n, k;
  ll ans = LLINF;
  scanf("%lld%lld", &n, &k);
  for (int i = 0; i < n; i++)
  {
    scanf("%lld", &a[i]);
  }
  sortup(a, n);
  for (int i = k - 1; i < n; i++)
  {
    ll tmp = a[i] - a[i - k + 1];
    ans = MIN(ans, tmp);
  }
  printf("%lld\n", ans);
  return 0;
}


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

def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

def main():
    N = II()
    CSF = []
    for _ in range(N-1):
        c, s, f = MII()
        CSF.append((c, s, f))

    for i in range(N-1):
        t = 0
        for j, (c, s, f) in enumerate(CSF[i:]):
            if j == 0:
                t += s + c
            else:
                if t < s:
                    t += s - t 
                else:
                    if (t - s) % f != 0: 
                        t = ((t - s) // f + 1) * f + s
                t += c
        print(t)
    print(0)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9232
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int T;

bool check(ll a,ll b,ll c,ll d){
    if(a<b||b>d) return false;
    if(c>=b) return true;
    a%=b;
    ll g=__gcd(b,d);
    ll x=b-g+(a%g);
    return (x<=c);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>T;
    rep(i,T){
        ll a,b,c,d; cin>>a>>b>>c>>d;
        cout1((check(a,b,c,d)?"Yes":"No"));
    }
}

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

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<vector<int>> comp(n,vector<int>(n,0));
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>comp[i][j];
        }
    }
    vector<int> dp(1<<n,0);
    dp[0]=1;
    for(int mask=0;mask<dp.size();mask++){
        int m=__builtin_popcount(mask);
        for(int w=0;w<n;w++){
            if(!(mask&(1<<w))&&comp[m][w]){
                dp[mask|(1<<w)]+=dp[mask];
                dp[mask|(1<<w)]%=1000000007;
            }
        }
    }
    cout<<dp.back();
	return 0;
}

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

using namespace std;
#define pii pair<int,int>
#define x first
#define y second
#define rep(i,a,b) for(int i=a;i<b;i++)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";


int n,m,K;
int vis[505][505],s[505][505],d[505][505];
priority_queue<pii>q;
void dfs(int x,int y){
	int co=vis[x][y]-1;
	rep(i,0,n+1){
		int l=K-abs(x-i);
		if(l<0)continue;
		int j=y-l;
		if(j>=0&&j<m&&!vis[i][j]){
			if(s[i][j]>>co&1){
				d[i][j]--;
				s[i][j]^=1<<co;
				q.push({-d[i][j],i*m+j});
			}
		}
		j=y+l;
		if(j>=0&&j<m){
			if(s[i][j]>>co&1){
				d[i][j]--;
				s[i][j]^=1<<co;
				q.push({-d[i][j],i*m+j});
			}
		}
	}
}
int main(){
	int i,j,k;
	scanf("%d%d%d",&n,&m,&K);
	rep(i,0,n)rep(j,0,m)d[i][j]=4,s[i][j]=(1<<4)-1;
	
	rep(i,0,n)rep(j,0,m)q.push({-d[i][j],i*m+j});
	while(!q.empty()){
		int u=q.top().y;q.pop();
		int x=u/m,y=u%m;
		if(vis[x][y])continue;
		rep(i,0,4)if(s[x][y]>>i&1){
			vis[x][y]=i+1;break;
		}
		assert(vis[x][y]);
		dfs(x,y);
	}
	char t[]="0RGYB";
	rep(i,0,n){
		rep(j,0,m)printf("%c",t[vis[i][j]]);
		puts("");
	}
	return 0;
}

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

bool ss(double a, double b, double c, double u, double v, double x, double y) {
	if ((a * u + b * v + c) * (a * x + b * y + c) > 0) {
		return true;
	}
	else
		return false;
}

int main()
{
	double x1, y1, x2, y2, x3, y3, xp, yp;
		
	while (cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp) {
		if (ss(y1 - y2, x2 - x1, x1 * y2 - x2 * y1, x3, y3, xp, yp) &&
			ss(y2 - y3, x3 - x2, x2 * y3 - x3 * y2, x1, y1, xp, yp) &&
			ss(y3 - y1, x1 - x3, x3 * y1 - x1 * y3, x2, y2, xp, yp))
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 3148
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef pair<int,T> State;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define sq(x) ((x)*(x))
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
int w,h;
int s[33][33];
int c[10];
int dist[33][33][5];
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
priority_queue<State,vector<State>,greater<State> > q;
int solve(){
	scanf("%d %d",&w,&h);
	if(w+h==0)return 1;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			scanf("%d",&s[i][j]);
		}
	}
	for(int i=0;i<4;i++)scanf("%d",&c[i]);
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			for(int d=0;d<4;d++){
				dist[i][j][d]=INF;
			}
		}
	}
	dist[0][0][0]=0;
	q.push(State(0,T(P(0,0),0)));
	while(!q.empty()){
		State a = q.top();
		q.pop();
		int x,y,dir,v;
		x = a.sec.fi.fi;
		y = a.sec.fi.sec;
		dir = a.sec.sec;
		v = a.fi;
		if(dist[x][y][dir]<v)continue;
		for(int d=0;d<4;d++){
			int nx,ny,nd,cost;
			nd = (dir+d)%4;
			cost = c[d];
			if(s[x][y]==d)cost=0;
			nx = x+dx[nd];
			ny = y+dy[nd];
			if(nx<0||nx>=h||ny<0||ny>=w)continue;
			if(dist[nx][ny][nd]>v+cost){
				dist[nx][ny][nd]=v+cost;
				q.push(State(v+cost,T(P(nx,ny),nd)));
			}
		}
	}
	int ans = INF;
	for(int d=0;d<4;d++)ans = min(ans,dist[h-1][w-1][d]);
	printf("%d\n",ans);
	return 0;
}
int main(){
	while(!solve()){}
	return 0;
}

Measured memory_bytes: 3200
code = """
# distutils: language=c++
# distutils: include_dirs=[/home/contestant/.local/lib/python3.8/site-packages/numpy/core/include, /opt/atcoder-stl]
# cython: boundscheck=False
# cython: wraparound=False
from libcpp cimport bool
cdef extern from "/opt/atcoder-stl/atcoder/dsu.hpp" namespace "atcoder":
    cdef cppclass dsu:
        dsu(int n)
        int merge(int a, int b)
        bool same(int a, int b)
        int leader(int a)
        int size(int a)
cdef class DSU:
    cdef dsu *_thisptr
    def __cinit__(self, int n):
        self._thisptr = new dsu(n)
    cpdef int merge(self, int a, int b):
        return self._thisptr.merge(a, b)
    cpdef bool same(self, int a, int b):
        return self._thisptr.same(a, b)
    cpdef int leader(self, int a):
        return self._thisptr.leader(a)
    cpdef int size(self, int a):
        return self._thisptr.size(a)
"""
import os,sys
if sys.argv[-1] == 'ONLINE_JUDGE':
    open('atcoder.pyx','w').write(code)
    os.system('cythonize -i -3 -b atcoder.pyx')

# ↑ここまでライブラリ↓ここから解法

import sys
import atcoder
input = sys.stdin.buffer.readline
n, q = map(int, input().split())
dsu = atcoder.DSU(n)
res = []
for i in range(q):
    t, u, v = map(int, input().split())
    if t:
        if dsu.same(u, v): res.append(1)
        else: res.append(0)
    else:
        dsu.merge(u, v)
print('\n'.join(map(str, res)))

Measured memory_bytes: 18260
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int N;
vector<ll> A(200001, 0);

int main(void){
    
    scanf("%d", &N);
    for(int i = 1; i <= N; ++i) scanf("%lld", &A[i]);
    
    ll sum = 0, x = 0;
    vector<ll> v, w;
    for(int i = 0; i <= N; ++i) sum += A[i], x = x ^ A[i], v.push_back(sum), w.push_back(x);
    
    ll ans = 0;
    int r = 1;
    for(int l = 1; l <= N; ++l){
        while(r <= N && v[r] - v[l - 1] == (w[r] ^ w[l - 1])){
            ++r;
        }
        ans += r - l;
        if(l == r) ++r;
    }
    printf("%lld\n", ans);
    
    return 0;
}

Measured memory_bytes: 5100
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int operation_count;
  int addition_number;
  int current = 1;
  
  cin >> operation_count >> addition_number;
  
  for (int i = 0; i < operation_count; i++) {
    int added = current + addition_number;
    int doubled = current * 2;
    if (added < doubled) {
      current = added;
    } else {
      current = doubled;
    }
  }
  
  cout << current;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define debug(x) cerr << #x " = " << (x) << endl;
#define P(x) cerr << #x << endl;    
typedef long long ll;
//#define int long long
const int mod = 1000000007;


int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed << setprecision(9);
    
    
    string s, t;
    cin >> s >> t;
    int count = 0;
    for(int i = 0; i < 3; ++ i)
    {
        if(s[i] == t[i])
            ++ count;
    }
    cout << count << endl;
    
    return 0;
}






Measured memory_bytes: 256
N,K = map(int,input().split())

X = list(map(int,input().split()))

ans = 10**10
for i in range(N-K+1):
	time = min(abs(X[i])+abs(X[i+K-1]-X[i])\
		,abs(X[i+K-1])+abs(X[i+K-1]-X[i]))
	ans = min(ans,time)

print(ans)

Measured memory_bytes: 14380
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}

int a,b,ans;
bool visited[100005];
vector<int>v[100005];
void dfs(int n){
  if(visited[n]){return;}
  visited[n]=1;
  for(auto i:v[n]){
    dfs(i);
  }
}

int main() {
  cin>>a>>b;
  for(int i=0;i<b;++i){
    int n,m,mm;
    cin>>n>>m>>mm;
    v[m].push_back(n),v[n].push_back(m);
  }
  
  for(int i=1;i<=a;++i){
    if(!visited[i]){
      dfs(i);
      ++ans;
    }
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 10624
#include <stdio.h>

int main(void){
	char in;
	scanf("%c", &in);
	if(in == 'A')printf("T\n");
	if(in == 'T')printf("A\n");
	if(in == 'C')printf("G\n");
	if(in == 'G')printf("C\n");
	return 0;
}


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

int main() {
  int r, c;
  int a[101][101] = {0};
  cin >> r >> c;
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> a[i][j];
      a[i][c] += a[i][j];
      a[r][j] += a[i][j];
    }
    a[r][c] += a[i][c];
  }
  for (int i = 0; i <= r; i++) {
    for (int j = 0; j < c; j++) {
      cout << a[i][j] << ' ';
    }
    cout << a[i][c] << endl;
  }
  return 0;
}

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

int main(){
	int N; cin >> N;
	int s[N];
	for(int i=0; i<N; i++){
		cin >> s[i];
	}
	ll ans = 0;
	for(int i=1; i<=N-2; i++){
		int t = (N-1)%i;
		int p = (N-1-t)/i;
		int x = t + p * i;
		if(x == N-1) x -= i;
		ll sum = 0;
		int cnt = 1;
		for(int j=x; j>0 && j > i; j=j-i){
			if(j % i == 0){
				if(j <= N-1-j) break;
			}
			sum += s[j];
			sum += s[i*cnt];
			if(sum > ans) ans = sum;
			cnt++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>


int main(){
	char str[256];
	int nums[200];
	int a=0,b=0;
	int i=0;
	while(1){

		a=0,b=0;
		fgets(str,256,stdin);
		if (sscanf(str,"%d %d",&a,&b)&&feof(stdin)!=0){
			break;
		}
		int c=a+b;
		int dnum=0;
		for(dnum=1;c/=10;dnum++);
		nums[i]=dnum;
		i++;
	}
	int j=0;
	for(j=0;j<i;j++){
		printf("%d\n",nums[j]);
	}
	
	return 0;
}

Measured memory_bytes: 612
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

func solve(in io.Reader, out, err io.Writer) {
	N, now, MOD := 0, 1, int(1e9)+7
	fmt.Fscan(in, &N)

	for i := 0; i < N; i++ {

		now = (now * ((i + 1) % MOD)) % MOD
	}

	fmt.Fprintln(out, now)
}

func main() {
	br := bufio.NewReaderSize(os.Stdin, int(1e7))
	solve(br, os.Stdout, os.Stderr)
}


Measured memory_bytes: 2944
#include <iostream>
#include <bits/stdc++.h>
#include <queue>
#include <stack>
#include <vector>
#define loop(n) for(ll i=0;i<n;i++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
typedef long long int ll;


int main()
{
    fastio;
    ll n;
    cin>>n;
    double arr[n];
    loop(n)
		cin>>arr[i];
	
	double dp[n+1][n+1];
	
	for(ll i=0;i<=n;i++)
		dp[0][i] = 1;

	for(ll i=1;i<=n;i++)
	{
		for(ll j=0;j<=i;j++)
		{
			if(j==0)
				dp[i][j] = (1 - arr[i-1]) * dp[i-1][j];
			else if(i==j)
				dp[i][j] = arr[i-1] * dp[i-1][j-1];
			
			else
			{
				dp[i][j] = arr[i-1] * dp[i-1][j-1] + (1 - arr[i-1]) * dp[i-1][j];
			}
		}
	}
	
	double ans = 0;
	for(ll i=n/2+1;i<=n;i++)
		ans += dp[n][i];
	cout<<fixed<<setprecision(10)<<ans<<endl;

    return 0;
}


Measured memory_bytes: 49824
#include<bits/stdc++.h>
const int N=307;
int n,m,ans,a[N][N],p[N],t[N],del[N];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i){
		p[i]=1;
		for(int j=1;j<=m;++j)scanf("%d",a[i]+j);
		++t[a[i][1]];
	}
	for(int i=1;;++i){
		int mw=0;
		for(int j=1;j<=m;++j)if(t[j]>t[mw])mw=j;
		if(!ans||ans>t[mw])ans=t[mw];
		if(i==m)break;
		del[mw]=1;
		for(int j=1;j<=n;++j)if(del[a[j][p[j]]]){
			for(--t[a[j][p[j]]];del[a[j][p[j]]];++p[j]);
			++t[a[j][p[j]]];
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n): fact(n+1), ifact(n+1) {
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }

  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
  int n, k;
  cin >> n >> k;
  mint ans;

  k = min(k, n-1);
  combination comb(n); 
  for(int z = 0; z <= k; ++z) {
    ans += comb(n, z) * comb(z+(n-z-1), z);
  }

  cout << ans.x << endl;
  return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	long long sum=0;
	for (int i=0;i<m;i++){
		int a;
		cin>>a;
		sum+=a;
	}
	if (n-sum>=0) cout<<n-sum<<endl;
	else cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz size()
#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define mod 1000000007
#define _for(it, a) \
  for (__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)

using namespace std;

string s;
pair<int, int> solve(int l) {
  pair<int, int> res;
  res.ff = -1;
  res.ss = -1;
  int req = l / 2;
  for (int n = 0; n + l - 1 < s.sz; ++n) {
    set<char> c;
    map<char, int> cc;
    int k = 0;
    while (k < l) {
      c.insert(s[n + k]);
      ++cc[s[n + k]];
      if (cc[s[n + k]] > req) return mp(n, n + l - 1);
      ++k;
    }
  }
  return res;
}

int main() {
  cin >> s;
  for (int n = 2; n <= 4; ++n) {
    pair<int, int> res = solve(n);
    if (res.ff != -1) {
      cout << res.ff + 1 << " " << res.ss + 1 << endl;
      return 0;
    }
  }
  cout << -1 << " " << -1 << endl;
  return 0;
}

// Built using Sublime-CHelper plug-in (beta)


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

int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  for (int i = 0; i < n; ++i)
    cin >> l[i];
  int sum = accumulate(l.begin(), l.end(), 0);
  int mx = *max_element(l.begin(), l.end());
  if (sum - mx > mx)
    cout << "Yes\n";
  else
    cout << "No\n";
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Int32;

class Program
{
    static void Main(string[] args)
    {
        label:
        var text = ReadLine();
        int k = Parse(ReadLine()) - 1;
        var result = new List<string>();
        hoge(text, "", null, result);
        WriteLine(result[k]);
    }

    static void hoge(string text, string sub, List<int> kouho, List<string> result)
    {
        var nextList = new SortedList<char, List<int>>();
        if (kouho == null)
        {
            for (int i = 0; i < text.Length; ++i)
            {
                AddNext(text[i], i, nextList, text.Length);
            }
        }
        else
        {
            foreach (int i in kouho)
            {
                if (i + 1 < text.Length)
                {
                    AddNext(text[i + 1], i + 1, nextList, text.Length);
                }
            }
        }
        foreach (var pair in nextList)
        {
            string sub2 = sub + pair.Key.ToString();
            result.Add(sub2);
            if (5 <= result.Count) return;
            hoge(text, sub2, pair.Value, result);
            if (5 <= result.Count) return;
        }
    }

    static void AddNext(char c, int i, SortedList<char, List<int>> list, int capa)
    {
        if (list.ContainsKey(c)) list[c].Add(i);
        else
        {
            if (list.Count == 3)
            {
                var max = list.Keys.Max();
                if (max < c) return;
                else list.Remove(max);
            }
            list[c] = new List<int>(capa) { i };
        }
    }
}


Measured memory_bytes: 13920
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

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

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "YES"; }
  string_type do_falsename() const { return "NO"; }
};

void solve(ll H, ll W, ll N, vector<ll> a) {
  vector<int> v;
  REP(i,N) REP(j,a[i]) v.push_back(i + 1);
  REP(i,H) REP(j,W) {
    int x = i * W + (i % 2 == 0 ? j : (W - 1 - j));
    cout << v[x] << " \n"[j == W - 1];
  }
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll W;
	ll N;
	ll H;
	scanf("%lld", &H);
	scanf("%lld", &W);
	scanf("%lld", &N);
	vector<ll> a(N-1+1);
	for (int i = 0 ; i <= N-1 ; i++) {
	  scanf("%lld", &a[i]);
	}
	solve(H, W, N, a);
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;


long long H(long long N, long long A, long long B) {
    long long K = 0;
    K += N / B;
    N %= B;
    K += N / A;
    N %= A;
    return K + N;
}

int main() {
    long long A, B;
    cin >> A >> B;
    long long X = (A + B - 1) / A;
    long long Z = X * A - B;
//    cout << B << " = " << X << "*" << A << "-" << Z << endl;
//    cout << H(Z, A, B) << endl;
    if( H(Z, A, B) >= X ){
        cout << X * A << endl;
        return 0;
    }
    cout << -1 << endl;
}


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

ans_lst = list(map(int, input().split()))

ans = sum(ans_lst)

val_dic = {}
for i in ans_lst:
  if i in val_dic:
    val_dic[i] += 1
  else:
    val_dic[i] = 1


q = int(input())
for i in range(q):
  z = 0
  b, c = map(int, input().split())

  if b in val_dic:
    z = val_dic[b]
  
  ans = ans + (c - b) * z
  print(ans)

  if b in val_dic:
    num = val_dic[b]
    val_dic[b] = 0
    if c in val_dic:
      val_dic[c] += num
    else:
      val_dic[c] = num

Measured memory_bytes: 20580
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<class NumT>
NumT diffabs(NumT l, NumT r)
{
    if (l < r) return r-l;
    else return l-r;    
}

struct myinout_t {} io;

template<class T>
myinout_t &operator >>(myinout_t &my, T &i)
{
    cin >> i;
    return my;
}

myinout_t &operator >>(myinout_t &my, int &i)
{
    int r = scanf("%d", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

myinout_t &operator >>(myinout_t &my, ll &i)
{
    int r = scanf("%lld", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

template<class T>
myinout_t &operator <<(myinout_t &my, const T &i)
{
    cout << i;
    return my;
}

myinout_t &operator <<(myinout_t &my, int i)
{
    printf("%d", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, ll i)
{
    printf("%lld", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, double i)
{
    printf("%.20f", i);
    return my;
}

constexpr char BR = '\n';


///////////////////////////////////////////////////
#include <atcoder/lazysegtree>

constexpr int MOD = 998244353;

int k10[200001];
int k11[200001];

struct S
{
    int d;
    int k;
};


S op(S a, S b)
{
    int d = ((ll)a.d * k10[b.k] + b.d) % MOD;
    int k = a.k + b.k;
    return S{d, k};
}

S e()
{
    return S{0, 0};
}

S fmap(int f, S x)
{
    if (f == 0) return x;

    x.d = ((ll)k11[x.k] * f) % MOD;
    return x;
}

int fcomp(int f, int g)
{
    if (f == 0) return g;
    else return f;
}

int fid()
{
    return 0;
}

int main()
{
    int N, Q;
    io >> N >> Q;

    vi L(Q), R(Q), D(Q);
    for (int i = 0; i < Q; ++i)
    {
        io >> L[i] >> R[i] >> D[i];
        --L[i];
    }

    ll k = 1;
    for (int i = 0; i < 200000; i++)
    {
        k10[i] = k;
        k = (k * 10) % MOD;
    }
    k = 0;
    for (int i = 0; i < 200000; i++)
    {
        k11[i] = k;
        k = (k * 10 + 1) % MOD;
    }
    
    atcoder::lazy_segtree<S, op, e, int, fmap, fcomp, fid> st(N);

    for (int i = 0; i < N; i++)
    {
        st.set(i, S{1, 1});
    }

    //io << st.all_prod().d << BR;

    for (int i = 0; i < Q; i++)
    {
        st.apply(L[i], R[i], D[i]);
        io << st.all_prod().d << BR;
    }
}

Measured memory_bytes: 13828
from collections import defaultdict
from string import ascii_uppercase
import sys, bisect, math
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

a,b,t = read_int()

def solve():
    ans = 0
    c = int((t + 0.5) // a)
    ans = b*c
    return ans

if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 3952
def main():
    import sys
    input = sys.stdin.buffer.readline
    N, M = (int(i) for i in input().split())
    H = [int(i) for i in input().split()]
    G = [set() for _ in range(N)]
    for i in range(M):
        a, b = (int(i) for i in input().split())
        G[a-1].add(b-1)
        G[b-1].add(a-1)
    ans = 0
    for a in range(N):
        if all(H[b] < H[a] for b in G[a]):
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 106836
#include <bits/stdc++.h>
#define rp(i,n) for(ll i=0; i<n; i++)
using namespace std;
using ll=long long;
using P=pair<int,int>;
using G=vector<vector<int>>;
const ll INF=1ll<<50;

struct edge{ll from,to,cost;};
vector<edge> es(5020);
vector<ll> d(2520);
vector<ll> finished(2520);
vector<bool> neg(2520,false);

int main(){
    ll n,m,p;
    cin >> n >> m >> p;
    rp(i,m){
        cin >> es[i].from >> es[i].to >> es[i].cost;
        es[i].cost=-es[i].cost+p;
    }
    rp(i,2520) d[i]=INF;
    d[1]=0ll;
    ll ctr=0;
    ll curgoal;
    while(1){
        ctr++;
        bool update=false;
        rp(i,m){
            edge e=es[i];
            if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost){
                d[e.to]=d[e.from]+e.cost;
                update=true;
            }
        }
        if(!update) break;
        if(ctr==n) {
            rp(i,n+1) finished[i]=d[i];
        }
        if(ctr>n){
            if(finished[n]!=d[n]){
                cout << -1 << endl;
                return 0;
            }else{
                rp(i,n+1){
                    if(finished[i]!=d[i]) neg[i]=true;
                }
                rp(i,m){
                    if(neg[es[i].from]&&!neg[es[i].to]){
                        neg[es[i].to]=true;
                    }
                }
                if(neg[n]){
                    cout << -1 << endl;
                    return 0;
                }
            }
        }

        if(ctr==n*4) break;
    }
    if(d[n]<=0) cout << -d[n] << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3784
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner (System.in)){
				int r = sc.nextInt();
				int c = sc.nextInt();

				int[][] table = new int[r][c];

				//読み込む
				for (int i=0; i<r; i++) {
					for (int j=0; j<c; j++) {
						table[i][j] = sc.nextInt();
					}
				}

				for (int i=0; i<r; i++) {
					int total = 0;
					for (int j=0; j<c; j++) {
						total += table[i][j];
						System.out.print(table[i][j] + " ");
					}
					System.out.println(total);
				}
				
				int t = 0;
				for (int i=0; i<c; i++) {
					int total = 0;
					for (int j=0; j<r; j++) {
						total += table[j][i];
					}
					System.out.print(total + " ");
					t += total;
				}
				System.out.println(t);
		}
	}

}


Measured memory_bytes: 41520
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    int N, M; cin >> N >> M;
    int even = M / 2;
    int odd = M - even;
    for (int i = 0; i < odd; i++) {
        int n = 2 * i + 1;
        int t = odd - i;
        cout << t << ' ' << t + n << '\n';
    }
    for (int i = 0; i < even; i++) {
        int n = 2 * i + 2;
        int t = odd * 2 + even - i;
        cout << t << ' ' << t + n << '\n';
    }
    return 0;
}


Measured memory_bytes: 3664