akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {
          
         
			var inputArray = retreiveLongArray();
			var inputCount = 1;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			long N = inputArray[0];
			var aArray = retreiveLongArray();

			var count = 0;

			for (int i = 0; i < N; i++) {

				if (aArray[i]%2==1 && (i+1)%2 ==1) {
					count++;
				}
			}

			//答えの出力
			var ans = count;
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}


		/// <summary>
		/// 2組みずつの入力データ(数値)からTuppleListを作成する
		/// </summary>
		/// <param name="N"></param>
		/// <returns></returns>
		private static List<Tuple<long, long>> createLongTuppleList(long N) {
			var inpList = new List<Tuple<long, long>>();

			for (int i = 0; i < N; i++) {
				var inp = retreiveLongArray();
				var item1 = inp[0];
				var item2 = inp[1];
				inpList.Add(new Tuple<long, long>(item1, item2));
			}
			return inpList;
		}
	}
}

Measured memory_bytes: 28256
#! python3
# primeNumber.py - 素数を判定するアルゴリズム

def isPrime(x):
    if x == 2:
        return True
    elif x < 2 or x % 2 ==0:
        return False
    else :
        i = 3
        while i <= x ** 0.5:
            if x % i == 0:
                return False
            i += 1
        return True

num_of_numbers = int(input())
cnt = 0
for i in range(num_of_numbers):
    x = int(input())
    if isPrime(x):
        cnt += 1
print(cnt)



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

using namespace std;

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

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;

int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n,m,r;
	
	cin >>n >>m >>r;
	VI z(r);
	rep(i,r){ cin >>z[i]; z[i]--;}
	
	vector<VI> a(n, VI(n, mod));
	rep(i,n) a[i][i] =0;
	rep(i,m){
		int f,t,c;
		cin >>f >>t >>c;
		a[f-1][t-1] = a[t-1][f-1] = c;
	}
	rep(k,n) rep(i,n) rep(j,n) a[i][j] =min(a[i][j], a[i][k] + a[k][j]);

	sort(all(z));
	ll ans = 1LL<<50;
	do {
		ll w = 0;
		rep(i,r-1){
			w += a[z[i]][z[i+1]];
		}
		ans = min(ans , w);
	} while ( next_permutation(all(z)) );

	
	
	cout << ans <<"\n";
	return 0;
}

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

int main(){

	int n,k;
	string s;
	cin >> n >> k >> s;

	int numOfGroup = 0;
	char be = s[0];
	for (int i=1;i<n; i++) {
		if (s[i] == be) {
			continue;
		}
		numOfGroup++;
		be = s[i];
	}
	if (be == s[n-1]) {
		numOfGroup++;
	}

	numOfGroup = max(1, numOfGroup-2*k);
	cout << n - numOfGroup << endl;
}


Measured memory_bytes: 512
using System;
using System.Linq;

namespace _1042
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string s = Console.ReadLine();
                if (s == "END OF INPUT")
                {
                    break;
                }
                string[] x = s.Split();
                for (int i = 0; i < x.Count(); i++)
                {
                    Console.Write(x[i].Length);
                }
                Console.WriteLine();
            }
        }
    }
}

Measured memory_bytes: 9332
N=int(input())

T=0
X=0
Y=0

for j in range(N):
    t,x,y=map(int,input().split())
    
    if (t-T)>=abs(X-x)+abs(Y-y):
        if ((t-T)-(abs(X-x)+abs(Y-y)))%2==0:
            pass
        else:
            print("No")
            exit()
    else:
        print("No")
        exit()
    T=t
    X=x
    Y=y
print("Yes")

Measured memory_bytes: 3064
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

constexpr int64_t DIV1097 = 1000000007LL;

using namespace std;

int main()
{
    int64_t N, A, B;
    std::cin >> N >> A >> B;

    std::vector<int64_t> X;
    for (decltype(N) i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        X.push_back(t);
    }

    int64_t ans = 0;
    for (int64_t i = 1; i < N; ++i) {
        ans += std::min((X[i] - X[i-1]) * A, B);
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 1400
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;




int main(){
    ll n;
    cin>>n;
    vector<char> A(n);
    for(auto &I:A){cin>>I;}
    vector<ll> dp(n+1,0);
    vector<ll> next(n+1,0);
    dp[0]=1;
    for(auto &I:A){
        for(auto &T:next){T=0;}
        if(I=='-'){continue;}
        if(I=='U'){
            for(int i=0;i<=n;i++){
                if(i>0){next[i]+=dp[i]*i%MOD; next[i]%=MOD;}
                if(i<n){next[i+1]+=dp[i]; next[i+1]%=MOD;}
            }
        }
        else{
            for(int i=0;i<=n;i++){
                if(i>0){next[i-1]+=dp[i]*i%MOD*i%MOD; next[i]%=MOD;}
                next[i]+=dp[i]*i%MOD; next[i]%=MOD;
            }
        }
        dp=next;
    }
    cout<<dp[0]<<endl;
    
    
    
    return 0;
}



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

void solve(){
	
	int n ;
	cin>>n ;

	int amount=1000 ;
	
	while(amount<n){
		amount+=1000 ;
	}	
	
	cout<<amount-n ;

}	

int main(){


	
	int y ;

	y=1 ;
	//cin>>y ;

	while(y--)
	{	
		solve() ;
	}

}

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

using namespace std;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
    
  int n, k;
  cin >> n >> k;
  
  vector<int> a;
  a.resize(n);
  
  for (int i = 0; i < k; i++)
    cin >> a[i];
  
  for (int i = k, idx = 0, num; i < n; i++)
  {
    cin >> num;
    if (a[idx] < num)
      cout << "Yes\n";
    else
      cout << "No\n";
    
    a[idx++] = num;
    if (idx == k)
      idx = 0;
  }
  return 0;
}

Measured memory_bytes: 3668
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::collections::{VecDeque};
type Pos = (usize, usize);

fn main() {
  input! {
      h: usize,
      w: usize,
      board: [chars; h],
  }
  let max_cost = h + w;
  let mut queue: VecDeque<Pos> = VecDeque::new();
  let mut costs: Vec<Vec<usize>> = vec![vec![max_cost; w]; h];
  for i in 0..h {
    for j in 0..w {
      if board[i][j] == '#' {
        let pos = (i, j);
        queue.push_back(pos);
        costs[i][j] = 0;
      }
    }
  }
  while let Some(pos) = queue.pop_front() {
    let i = pos.0;
    let j = pos.1;
    let cost = costs[i][j];
    if i > 0 {
      let new_pos = (i - 1, j);
      if costs[new_pos.0][new_pos.1] == max_cost && board[new_pos.0][new_pos.1] == '.' {
        costs[new_pos.0][new_pos.1] = cost + 1;
        queue.push_back(new_pos);
      }
    }
    if i < h - 1 {
      let new_pos = (i + 1, j);
      if costs[new_pos.0][new_pos.1] == max_cost && board[new_pos.0][new_pos.1] == '.' {
        costs[new_pos.0][new_pos.1] = cost + 1;
        queue.push_back(new_pos);
      }
    }
    if j > 0 {
      let new_pos = (i, j - 1);
      if costs[new_pos.0][new_pos.1] == max_cost && board[new_pos.0][new_pos.1] == '.' {
        costs[new_pos.0][new_pos.1] = cost + 1;
        queue.push_back(new_pos);
      }
    }
    if j < w - 1 {
      let new_pos = (i, j + 1);
      if costs[new_pos.0][new_pos.1] == max_cost && board[new_pos.0][new_pos.1] == '.' {
        costs[new_pos.0][new_pos.1] = cost + 1;
        queue.push_back(new_pos);
      }
    }
  }
  let count = costs.iter()
                   .map(|row| row.iter().max().unwrap())
                   .max().unwrap();
  println!("{}", count);
}


Measured memory_bytes: 33524
import sys
from collections import deque

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    edge = [[] for _ in range(n)]
    for _ in range(n):
        u, k, *V = map(int, input().split())
        for v in V:
            edge[u - 1].append(v - 1)

    depth = [f_inf] * n
    depth[0] = 0
    que = deque([0])
    while que:
        v = que.popleft()
        for u in edge[v]:
            if depth[u] == f_inf:
                depth[u] = depth[v] + 1
                que.append(u)

    for i in range(n):
        print(i + 1, depth[i] if depth[i] != f_inf else -1)


if __name__ == '__main__':
    resolve()



Measured memory_bytes: 6044
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;

P split(int x)
{
	int a = x % 10;
	int b = 0;
	while (x > 0) {
		b = x;
		x /= 10;
	}
	return make_pair(a, b);
}

int main()
{
	int n;
	cin >> n;
	
	map<P, int> freq;
	for (int i = 1; i <= n; ++i) {
		P p = split(i);
		freq[p]++;
	}
	
	ll ans = 0;
	for (int i = 1; i <= n; ++i) {
		P p = split(i);
		P q = make_pair(p.second, p.first);
		ans += freq[q];
	}

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

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

int main() {
  int ans=0,a,tmp=1000;
  rep(i,5){
  	cin >> a;
  	ans+=a/10*10;
  	ans+= (a%10==0) ? 0:10;
  	if(a%10!=0) tmp=min(tmp,a%10);	
  }
  if(tmp!=0 && tmp!=1000) ans=ans+tmp-10;
  cout << ans <<endl;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
if h == 1 or w == 1:
  print(1)
elif h%2 == 0 and w%2 == 0:
  print(h*w//2)
elif h%2 == 1 and w%2 == 0:
  print((h-1)*w//2 + (w+1)//2)
elif h%2 == 0 and w%2 == 1:
  print(h*(w-1)//2 + (h+1)//2)
elif h%2 == 1 and w%2 == 1:
  print((h-1)*(w-1)//2+(h+1)//2+(w+1)//2-1)

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;
using pii = pair<Int,Int>;
using mapis = unordered_map<Int,string>;
using mapii = unordered_map<Int,Int>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

Int LCM(Int a, Int b){
    return a*b/GCD(a,b);
}


int main() {
    Int N;

    cin >> N;




    cout << N*N*N << endl;

    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
lst = [100000 for _ in range(n)]
a_lst = list(map(int, input().split()))
for a in a_lst:
    lst[a - 1] = 0
for i in range(n - 1):
    lst[i + 1] = min(lst[i] + 1, lst[i + 1])
for i in range(n - 1, 0, -1):
    lst[i - 1] = min(lst[i - 1], lst[i] + 1)
print(max(lst))


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

using namespace std;
mt19937_64 rng(58);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;
    
}

Measured memory_bytes: 3632
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

string s;
vector<vector<int> > memo;

bool solve(int a, int b)
{
    if(memo[a][b] != -1)
        return memo[a][b] != 0;
    if(a == b)
        return false;

    for(int i=a; i<b; ++i){
        if(s[i] != s[i+1] && solve(a, i) && solve(i+1, b)){
            memo[a][b] = 1;
            return true;
        }
    }

    if(s[a] == s[a+1]){
        if(a+1 == b || solve(a+1, b)){
            memo[a][b] = 1;
            return true;
        }
        else{
            memo[a][b] = 0;
            return false;
        }
    }
    if(s[b] == s[b-1]){
        if(solve(a, b-1)){
            memo[a][b] = 1;
            return true;
        }
        else{
            memo[a][b] = 0;
            return false;
        }
    }

    if(s[a] == s[b]){
        if(solve(a+1, b-1)){
            memo[a][b] = 1;
            return true;
        }
        for(int i=a+1; i<b-1; ++i){
            if(s[i] != s[a] && s[i+1] == s[b]){
                if(solve(a+1, i) && solve(i+1, b)){
                    memo[a][b] = 1;
                    return true;
                }
            }
        }
    }

    memo[a][b] = 0;
    return false;
}

int main()
{
    int n;
    cin >> n;
    s.resize(n);
    for(int i=0; i<n; ++i)
        cin >> s[i];

    memo.assign(n, vector<int>(n, -1));
    if(solve(0, n-1))
        cout << "yes" << endl;
    else
        cout << "no" << endl;

    return 0;
}

Measured memory_bytes: 3208
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  string n;
  cin >> n;
  REP(i,3) {
    if(n[i]=='7'){
      cout << "Yes\n";
      return 0;
    }
  }
  cout << "No\n";
  return 0;
}


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

#define SZ(a) ((int)a.size())
#define ALL(a) a.begin(), a.end()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define fst first
#define snd second

void dout() { cerr << endl; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<char> a;
    for (char x = 'A'; x <= 'Z'; x++)
        a.PB(x);
    for (int i = 0; i < SZ(s); i++)
    {
        cout << a[(s[i] - 'A' + n) % 26];
    }
    return 0;
}

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <map>
#include <math.h>
#include <algorithm> // std::sort, std::min, std::next_permutation, std::lower_bound
#include <iomanip> // std::setprecision
#include <cmath> // std::ceil
#include <numeric> // std::gcd, std::lcm
#include <limits> // std::numeric_limits<long int>::max()
#include <unordered_map>
#include <map>
#include <cmath> // std::atan2

using namespace std;
typedef long long ll;
#define INF 1999999999
#define MODA 1000000007 
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define ALL(a)  (a).begin(),(a).end()

template<typename T>
T powint (const T& x, const T& y) {
  T ret = 1;
  for(int i=0; i<y; ++i) ret *= x;
  return ret;
}

long long factorial(long long X) {
  long long ans = 1;
  for(int i=1; i<X+1 ; ++i) ans *= i;
  return ans;
}

std::map<long long, long long> prime_factor(long long n) {
  std::map<long long, long long> ret;
  for(long long i = 2; i * i <= n; ++i) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1; // if n is prime number.
  return ret;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N);
  rep (i, N) cin >> A[i];

  vector<ll> prices = A;
  ll count = M;
  while(count > 0 ) {
    sort(prices.begin(), prices.end());
    auto iter = lower_bound(ALL(prices), prices.back()/2);
    ll numitem = distance(iter, prices.end());
    ll numdisc = (numitem < count ? numitem : count);
    for(int i = 0; i < numdisc; ++i) {
      prices[N-1-i] /= 2;
    }
    count -= numdisc;
  }
  ll ans = 0;
  for (const auto price : prices) {
    ans += price;
  }
  cout << ans << endl;
  return 0;
}

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

int main(int argc, char* argv[]) {
  int A, B;
  cin >> A >> B;

  int fee;
  if (A >= 13)
    fee = B;
  else if (A >= 6)
    fee = B / 2;
  else
    fee = 0;

  cout << fee << endl;
}


Measured memory_bytes: 256
// code author: Dhruva Mahajan
 
// Ideas are cheap, execution is everything.
 
#include<bits/stdc++.h> 
using namespace std;
 
#define ll long long  
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define tr(container, it) for(auto it = container.begin(); it != container.end(); it++)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define testcase(t) int t;cin>>t;while(t--)
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))

int main(){
	
	fastio;

	ll n,k,sum=0;
	cin>>n>>k;
	ll a[n];
	for(ll i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}

	sort(a,a+n);
	ll i=n-1;
	while(k>0){
		sum-=a[i];
		i--;
		k--;
		if(i<0){
			break;
		}
	}

	// for(ll i=n-1;i>=0;i--){
	// 	sum-=a[i];
	// }
	cout<<max(sum,0)<<endl;

	
	
	return 0;
}

Measured memory_bytes: 1792
table = [list(map(int, input().strip().split())) for _ in range(3)]
n = int(input())
bs = [int(input()) for _ in range(n)]

bingo = [[False] * 3 for _ in range(3)]

for b in bs:
    for i in range(3):
        for j in range(3):
            if b == table[i][j]:
                bingo[i][j] = True

win = False
for i in range(3):
    row = bingo[i]
    if all(row):
        win = True

for j in range(3):
    col = [bingo[i][j] for i in range(3)]
    if all(col):
        win = True

d1 = [bingo[0][0], bingo[1][1], bingo[2][2]]
d2 = [bingo[0][2], bingo[1][1], bingo[2][0]]

if all(d1) or all(d2):
    win = True

if win:
    print('Yes')
else:
    print('No')


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

int main()
{
	int n, k, d;
	int flag = 0;
	int pt[100];
	int N[100];

	cin >> n >> k;

	for (int i = 0; i <= n; i++)
	{
		pt[i] = i+1;
	}
	
	for (int j = 0; j < k; j++)
	{
		cin >> d;

		for (int i = 0; i < d; i++)
		{
			cin >> N[i];
		}
		for (int i = 0; i < n; i++)
		{
			for (int k = 0; k < d; k++)
			{
				if (pt[i] == N[k])
				{
					pt[i] = 0;
				}
			}
		}
	}

	for (int i = 0; i < n; i++)
	{
		if (pt[i]==0)
		{
			flag += 1;
		}
	}

	cout << n-flag << endl;

	return 0;
}

Measured memory_bytes: 3568
class UnionFind:
    def __init__(self,n):
        self.v=[-1]*n
    
    def find(self,x):
        if self.v[x]<0:
            return x
        else:
            self.v[x]=self.find(self.v[x])
            return self.v[x]
    
    def unite(self,x,y):
        x=self.find(x)
        y=self.find(y)

        if x==y:
            return False
        else:
            if self.v[x]>self.v[y]:
                x,y=y,x
            self.v[x]+=self.v[y]
            self.v[y]=x
            return True
    
    def same(self,x,y):
        return self.find(x)==self.find(y)
    
    def size(self,x):
        return -self.v[self.find(x)]

import sys

N=int(sys.stdin.readline())
ps=[]
xs=set()
ys=set()
for i in range(N):
    x,y=map(int,input().split())
    ps.append((x,y))
    xs.add(x)
    ys.add(y)

xs=tuple(sorted(xs))
ys=tuple(sorted(ys))

dx={e:i for i,e in enumerate(xs)}
dy={e:i for i,e in enumerate(ys)}
uf=(UnionFind(N*2))
for x,y in ps:
    uf.unite(dx[x],dy[y]+N)

def make_edges(xs,start):
    xes=[]
    for i, (x0,x1) in enumerate(zip(xs,xs[1:]),start=start):
        xes.append((abs(x1-x0), i, i+1))
    return xes

xes=make_edges(xs,start=0)
yes=make_edges(ys,start=N)

ret=0
for cost,a,b in sorted(xes+yes,key=lambda x:x[0]):
    if uf.same(a,b):
        continue
    uf.unite(a,b)
    ret+=cost
print(ret)

Measured memory_bytes: 81232
using System;
using static System.Console;

public class Hello
{
    public static void Main()
    {
        string l = ReadLine();
      	int N = int.Parse(l);
      	l = ReadLine();
       	string[] ll = l.Split();
        int[] a = new int[N];
      	for (int i=0;i<N;i++){
         a[i] = int.Parse(ll[i]) ;
        }
      
      	Array.Sort(a);
      
      	if (a[N/2 -1] == a[N/2]){
        WriteLine(0);
        }else{
         WriteLine(a[N/2]-a[N/2 - 1]); 
        }
      
      
      

    }
}

Measured memory_bytes: 18912
from collections import defaultdict
(n, k), *D,  = [list(map(int, s.split())) for s in open(0)]
di = defaultdict(int)
cnt = 0
for l in D:
    for i in range(1, len(l)):
        di[l[i]] += 1
for v in di.values():
    if v == n:
        cnt += 1
print(cnt)

Measured memory_bytes: 3444
import java.util.*;
public class Main{
	public static void main(String args[]){
		Stack<Integer> stack = new Stack<Integer>();
		Scanner sc = new Scanner(System.in);
		Set<String> ops = new HashSet<String>();
		ops.add("-");
		ops.add("+");
		ops.add("*");
		while(sc.hasNext()){
			String[] line = sc.nextLine().split(" ");
			for(int i=0;i<line.length;i++){
				String t =line[i];
				if(!ops.contains(t)){
					int val = Integer.parseInt(t);
					stack.push(val);
				}else{
					int val1 =stack.pop();
					int val2 = stack.pop();
					if(t.equals("+")){
						stack.push(val2+val1);
					}else if(t.equals("-")){
						stack.push(val2-val1);
					}else{
						stack.push(val2*val1);
					}
				}
			}
			System.out.println(stack.peek());
		}
	}

}

Measured memory_bytes: 26164
#include <cstdio>
#include <vector>
#include <queue>
#include <iostream>
#define rep(i,n) for(int i = 0;i<(n);i++)
const int inf = 1001001001;
using namespace std;
typedef pair<int,int> P;

int N,M;
int X1,X2,Y1,Y2;
int mindist[22];
vector<pair<int,int> > G[22];

void dijkstra(int s){
	rep(i,22){
		mindist[i] = inf;
	}
	mindist[s]=0;
	priority_queue<P, vector<P>, greater<P> > Q;
	Q.push(P(0,s));
	while(!Q.empty()){
		P p = Q.top(); Q.pop();
		int v = p.second;
		if(mindist[v] < p.first) continue;
		for(int i = 0;i < G[v].size();i++){
			P e = G[v][i];
			if(mindist[e.first] > mindist[v] + e.second){
				mindist[e.first] = mindist[v] + e.second;
				Q.push(P(mindist[e.first],e.first));
			}
		}
	}
}

int main(){
	scanf("%d",&N);
	scanf("%d",&M);
	rep(i,M){
		int a,b,c,d;
		scanf("%d,%d,%d,%d",&a,&b,&c,&d);
		G[a].push_back(P(b,c));
		G[b].push_back(P(a,d));
	}
	scanf("%d,%d,%d,%d",&X1,&X2,&Y1,&Y2);
	int cost = 0;
	dijkstra(X1);
	cost += mindist[X2];
	//cout << cost << endl;
	dijkstra(X2);
	cost += mindist[X1];
	//cout << cost << endl;
	cout << Y1 - cost - Y2 << endl;
}

Measured memory_bytes: 1212
#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1e9+7;
using namespace std;

int main(){
    int n, a, b; cin >> n >> a >> b;
    ll ans = 0;
    vector<int> x(n);
    REP(i, n){
        cin >> x[i];
        if(i) ans += min((ll)b, (ll)(x[i]-x[i-1]) *a);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n) for(int i=a; i<n; i++)
#define SPEED ios_base :: sync_with_stdio(false), cin.tie(NULL), cout.tie(0)
int main() 
{
	SPEED; 
	float k,a,b;
	cin>>k>>a>>b;
	int n;
	n=ceil(a/k);
	if((n*k)<=b) cout<<"OK";
	else cout<<"NG";
	return 0;
}

Measured memory_bytes: 3732
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        String s = sc.next();

        for (int i = 0; i < s.length(); i++) {
            System.out.print((char) ('A' + (s.charAt(i) - 'A' + n) % 26));
        }
        out("");

    }

    /*
     * 以下メソッド集
     */
    static int kaijo(int n) {

        if (n == 0 || n == 1) {
            return 1;
        } else {
            return n * kaijo(n - 1);
        }
    }

    static int fib(int n) {

        return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
    }

    static long lcm(long m, long n) {

        return m * n / gcd(m, n);
    }

    static int lcm(int m, int n) {

        return m * n / gcd(m, n);
    }

    static long gcd(long a, long b) {

        return (b == 0) ? a : gcd(b, a % b);
    }

    static int gcd(int a, int b) {

        return (b == 0) ? a : gcd(b, a % b);
    }

    static void out(String info) {

        System.out.println(info);
    }

    static void out(int info) {

        System.out.println(info);
    }

    static void out(double info) {

        System.out.println(info);
    }

    static void out(long info) {

        System.out.println(info);
    }

}


Measured memory_bytes: 25044
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;
vl a;

vector<vvl> f(){
	ll I=0,J=0,S=0,T=0,sum=a[0];
	vector<vvl> b(n,vvl(2,vl(2)));
	for(int i=1;i<n;i++){
		sum+=a[i];
		while(I<i&&S+a[I]<=sum/2) S+=a[I++];
		while(J<i&&T<sum/2) T+=a[J++];
		b[i][0][0]=S;b[i][0][1]=sum-S;
		b[i][1][0]=T;b[i][1][1]=sum-T;
	}
	reverse(a.begin(),a.end());
	return b;
}

int main(){
	cin>>n;
	a=vl(n);
	for(int i=0;i<n;i++) cin>>a[i];
	vector<vvl> b=f(),c=f();
	ll res=INF;
	for(int i=1;i<n-2;i++){
		for(int j=0;j<2;j++) for(int k=0;k<2;k++){
			ll d[4]={b[i][j][0],b[i][j][1],c[n-i-2][k][0],c[n-i-2][k][1]};
			sort(d,d+4);
			res=min(res,d[3]-d[0]);
		}
	}
	cout<<res<<endl;
}

Measured memory_bytes: 61184
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#define rep(i,n) for (long long i=0; i < (n); ++i)
#define rep2(i,n,m) for(long long i=n;i<=m;i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
int main() {
  int x ;
  cin >> x ;
  rep2(i,x,200000){
   int ans= 0;
    for(int j=2;j*j<=i;j++){
      if((i%j)==0) 
      ans= 1 ;
    }
  if(ans==0){
  cout<< i <<endl ;
  break ;
  }
  }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int r;
  cin >> r;

  if (r < 1200) {
    cout << "ABC" << endl;
  } else if (r < 2800) {
    cout << "ARC" << endl;
  } else {
    cout << "AGC" << endl;
  }

  return 0;
}

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

int main(){
    int W, H, x, y, r;
    cin>>W >>H >>x >>y >>r;
    if(0<=x-r && x+r<=W && 0<=y-r && y+r<=H){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}



Measured memory_bytes: 3116
#include<iostream>
#include<algorithm>
using namespace std;
long MOD=998244353;
long n,k;
long ans[2002];
long p2[2001],C[4001][4001];
long f(long t,long c)
{
	long p=0,ans=0;
	for(int i=1;i<=k&&t-i<=k&&i<t-i;i++)p++;
	for(long q=0;q<=p;q++)
	{
		long now=p2[q]*C[p][q]%MOD;
		long a=k-2*p+q-!(t%2),b=n-q-c;
		if(a+b-1>=0&&b>=0)
		{
			now=now*C[a+b-1][b]%MOD;
		}
		else now=0;
		ans=(ans+now)%MOD;
	}
	return ans;
}
main()
{
	cin>>k>>n;
	p2[0]=1;
	for(long i=1;i<=2000;i++)p2[i]=p2[i-1]*2%MOD;
	for(long i=0;i<=4000;i++)C[i][0]=1;
	for(long i=1;i<=4000;i++)
	{
		for(long j=1;j<=i;j++)C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD;
	}
	for(long i=2;i<=k+1;i++)
	{
		if(i%2)
		{
			ans[i]=f(i,0);
		}
		else
		{
			ans[i]=(ans[i]+f(i,0))%MOD;
			ans[i]=(ans[i]+f(i,1))%MOD;
		}
		cout<<ans[i]<<endl;
	}
	for(long i=k;i>=2;i--)cout<<ans[i]<<endl;
}


Measured memory_bytes: 123648
import sys
N, x = map(int,input().split())
aN = list(map(int,input().split()))

aN.sort()
ans = 0
for n in range(N):
  if x >= aN[n]:
    ans += 1
    x -= aN[n]
  else:
    print(ans)
    sys.exit()
print(N if x == 0 else N-1)


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

int main() {
  int height, width;
  string map[50];
  int dx[8] = {1 ,0 ,-1, 1, -1, 1, 0, -1};
  int dy[8] = {-1 ,-1 ,-1, 0, 0, 1, 1, 1};
  
  cin >> height >> width;
  rep(i, height)
    cin >> map[i];
  
  rep(i, height){
    rep(j, width){
      if(map[i][j] == '#')
        continue;
      
      int num = 0;
      rep(k, 8){
      	if(i + dx[k] < 0 || i + dx[k] >= height)
          continue;
        if(j + dy[k] < 0 || j + dy[k] >= width)
          continue;
        
        if(map[i + dx[k]][j + dy[k]] == '#')
          num++;
      }
      map[i][j] = (char)(num + '0');
    }
  }
  
  rep(i, height)
    cout << map[i] << endl;
  
}



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

int main() {

  int N, M;
  cin >> N >> M;

  vector<long long> H(N);

  for(int i = 0; i < N; i++){
    cin >> H[i];
  }

  int A;
  int B;

  map<int, int> dame;
  for(int i = 0; i < M; i++){
    cin >> A >> B;
    if(H[A - 1] <= H[B - 1]){
      dame[A]++;
    }
    if(H[B - 1] <= H[A - 1]){
      dame[B]++;
    }
  }

  cout << N - dame.size() << endl;
}


Measured memory_bytes: 6692
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 文字列の入力
		String[] s1 = sc.next().split("");
        String[] s2 = sc.next().split("");
        String[] s3 = sc.next().split("");
    
		// 出力
		System.out.println(s1[0] + s2[1] + s3[2]);
	}
}


Measured memory_bytes: 23124
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int A = sc.nextInt();

		int L = A;
		int R = A + N - 1;

		int eat;
		if (R <= 0) {
			eat = R;
		} else if (L >= 0) {
			eat = L;
		} else {
			eat = 0;
		}
		int ans = (R + L) * (R - L + 1) / 2 - eat;
		System.out.println(ans);
    }
}
  

Measured memory_bytes: 27016
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int> > Matrix;


int main(){
  int n;
  cin >> n;
  bool ok = false;
  rep(i, n){
    char a;
    cin >> a;
    if (a == 'Y') ok = true;
  }
  if (ok) cout << "Four\n";
  else cout << "Three\n";
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
        int N;
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        int[] a = new int[N];
        int[] flag = new int[N];
        for(int i=0;i<N;i++){
            a[i] = sc.nextInt();
            flag[i] = 0;
        }
        Arrays.sort(a);
        int sum = 0;
        int count = 0;
        for(int i=0;i<N;i=i+count){
            count=0;
            for(int j=i;j<N;j++){
                if(a[j]==a[i]) count++;
                else break;
            }
            if(count<a[i]) sum = sum + count;
            else sum = sum - a[i] + count;


        }


        System.out.println(sum);

    }

}


Measured memory_bytes: 58008
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S,SS; cin>>S;
  long long K,ans=0,s1=0,s2=0; cin>>K;  
  if(S.size()==1){
    ans=K/2;
    cout<<ans<<endl;
    return 0;
  }
  SS=S+S;
  for(int i=0; i<S.size()-1; i++){
    if(S[i]==S[i+1]){
      S[i+1]='0';
      s1++;
    }
  }
  for(int i=0; i<SS.size()-1; i++){
    if(SS[i]==SS[i+1]){
      SS[i+1]='0';
      s2++;
    }
  }
  if(SS[S.size()]!=SS[SS.size()-1]){
    s2-=s1;
    ans+=s2*(K-1)+s1;
  }
  else if(SS[0]!=SS[SS.size()-1]){
    ans+=s2*(K/2);
    if(K%2==1) ans+=s1;
  }
   cout<<ans<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define INF 1000000000
#define MOD 998244353
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair

#define FOR(i, a, b) for (int i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (int i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 205
int n;
int s[MN][MN];
int co[MN];
bool dfs(int cn){
    FOR(i, 1, n){
        if(!s[cn][i]) continue;
        if(co[i] == co[cn]) return false;
        if(co[i] == 1-co[cn]) continue;
        co[i] = 1-co[cn];
        if(!dfs(i)) return false;
    }
    return true;
}

bool v[MN];
int d[MN];
int bfs(int st){
    memset(d, -1, sizeof d);
    memset(v, false, sizeof v);
    d[st] = 0;
    queue<int> aah;
    aah.push(st);
    int mx = 0;
    while(!aah.empty()){
        int top = aah.front();
        aah.pop();
        if(v[top]) continue;
        v[top] = true;
        FOR(i, 1, n){
            if(!s[top][i]) continue;
            if(!v[i]){
                d[i] = d[top]+1;
                aah.push(i);
                mx = d[i];
            }
        }
    }
    return mx;
}

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

    cin >> n;
    FOR(i, 1, n){
        FOR(j, 1, n){
            char c;
            cin >> c;
            s[i][j] = (c == '1');
        }
    }

    memset(co, -1, sizeof co);
    co[1] = 0;
    if(!dfs(1)){
        cout << "-1\n";
        return 0;
    }

    int ans = 0;
    FOR(i, 1, n){
        ans = max(ans, bfs(i));
    }

    cout << ans+1 << "\n";
    
    return 0;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main(){
  int x, y;
  std::cin >> x >> y;

  int prize[205] = {0};
  prize[0] = 300000;
  prize[1] = 200000;
  prize[2] = 100000;
  int ans = prize[x-1] + prize[y-1];
  if( x == y && x == 1 ) ans += 400000;
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		
		int m = a*b;
		int s = a+a+b+b;
		
		
		System.out.println(m+" "+s);
	}
}

Measured memory_bytes: 26048
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
#include <stack> 
#include <set>
#include <map>
#include <cstdlib>
using namespace std;

typedef long long ll;
const int INF = 1000000002;
const int mod = 1000000007;

#define N 100010

int a[N];
ll s[N];

void Add2(int l, int r, int v)
{
	if (l > r) return;
	s[l] += v; s[r + 1] -= v;
}

void Add(int l, int r, int v)
{
	if (l > r) return;
	//cout << l << " " << r << " " << v << endl;
	Add2(l, l, v);
	Add2(l + 1, r, 1);
	Add2(r + 1, r + 1, -(r - l + v));
}

int main()
{
	//freopen("in.in", "r", stdin);
	//freopen("out.out", "w", stdout);
		
	int n, m;
	scanf("%d %d", &m, &n);
	for (int i = 1; i <= m; ++i)
	{
		scanf("%d", &a[i]);
		if (i > 1)
		{
			if (a[i - 1] < a[i])
			{
				Add(a[i - 1] + 2, a[i], 1);
			}
			else
			{
				Add(a[i - 1] + 2, n, 1);
				Add(1, a[i], n - a[i - 1]);
			}
		}
	}
	ll ans = 0;
	for (int i = 1; i <= n; ++i) s[i] += s[i - 1];
	for (int i = 1; i <= n; ++i) s[i] += s[i - 1], ans = max(ans, s[i]);

	ans = -ans;
	for (int i = 2; i <= m; ++i)
	{
		if (a[i - 1] < a[i]) ans += a[i] - a[i - 1];
		else ans += n - a[i - 1] + a[i];
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 1408
n=int(input())
edges=[]
relations={}
nodes=[0,0]
for i in range(n-1):
    a,b=map(int,input().split(" "))
    edges.append([a,b])
    relations.setdefault(a,[]).append(b)
    nodes.append(0)

max_color=0
for start in range(1,n+1):
    targets=relations.get(start,[])
    color=1
    for target in targets:
        if color == nodes[start]:
            color+=1
        else:
            pass
        nodes[target]=color
        if color>=max_color:
            max_color=color
        color+=1

print(max_color)
for edge in edges:
    print(nodes[edge[1]])

Measured memory_bytes: 30744
# def solve(n,m,a,b):
#     ans = 0
#     lim = (a*n+b)//m
    
#     for i in range(1,lim+1):
#         l = (i*m-b+a-1)//a
#         r = (i*m+m-b-1)//a

#         ans += (min(r,n-1)-l+1)*i

#     return ans

def floor_sum(n, m, a, b):
    ans = 0

    # (a*i+b)//m
    '''    
        k = a//m
        series 
            k + 2k + 3k + ... (n-1)k 
    '''
    if a>=m:
        ans += n*(n-1)*(a//m)//2
        a %= m


    '''
        k = b//m
        for each i

        series
            k + k + ... + k <n-1 times>
    '''
    if b>=m:
        ans += n*(b//m)
        b %= m

    yn = (a*n+b)//m

    if yn == 0:
        return ans #yn == 0 implies prev terms contibute 0 so return ans

    x_least = (yn * m - b) #the first x for which y(x) == yn 'x_least' refers to the val a*x.

    l = (x_least+(a-1))//a
    r = n-1 

    ans += (r-l+1)*yn  #if ans was not returned then this implies y(n) == y(n-1) == yn. element in window [l...r] have y(x) = yn
    ans += floor_sum(yn, a, m, (a-x_least%a)%a)
    return ans
    '''
    #r+1 as we pass the element that does not belong in the range.

    '''
def main():
    t = int(input())
    while t>0:
        n,m,a,b = map(int, input().split(' '))
        # print(solve(n,m,a,b))
        print(floor_sum(n,m,a,b))
        t-=1

if __name__ == "__main__":
    main()

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

int main(){
  int S;
  cin >> S;
  
  int s1 = S / 100, s2 = S % 100;
  if(0 < s1 && s1 < 13 && 0 < s2 && s2 < 13){
    cout << "AMBIGUOUS" << endl;
    return 0;
  }else if(0 < s1 && s1 < 13){
    cout << "MMYY" << endl;
    return 0;
  }else if(0 < s2 && s2 < 13){
    cout << "YYMM" << endl;
    return 0;
  }
  cout << "NA" << endl;
  
  return 0;
}

Measured memory_bytes: 3600
n = int(input())
L = list(map(int, input().split()))
a = 0
b = 0
for i in range(n-1):
  if L[i+1] <= L[i]:
    a = a+1
  else:
    if b < a:
      b = a
    a = 0
if b < a:
  b = a

print(b)

Measured memory_bytes: 14224
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

int K, S;

int main() {
  while (cin >> K >> S) {
    int res = 0;
	for (int x = 0; x <= K; ++x) {
	  for (int y = 0; y <= K; ++y) {
		int z = S - x - y;
		if (z >= 0 && z <= K) ++res;
	  }
	}
	cout << res << endl;
  }
}










Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,s,d,f,g,h,k[5][4][11],i,j;
	scanf("%d",&a);
	for(i=1;i<=3;i++){
		for(j=1;j<=10;j++){
			k[1][i][j]=0;
			k[2][i][j]=0;
			k[3][i][j]=0;
			k[4][i][j]=0;
		}
	}
	for(i=1;i<=a;i++){
		scanf("%d %d %d %d",&s,&d,&f,&g);
		k[s][d][f]+=g;
	}
	for(i=1;i<=4;i++){
		for(j=1;j<=3;j++){
			for(h=1;h<=10;h++){
				printf(" %d",k[i][j][h]);
			}
			printf("\n");
		}
		if(i!=4){
		for(j=1;j<=20;j++)
			printf("#");
		printf("\n");
		}
	}
	return 0;
}

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

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::vector<int> H;
    for(int i= 0 ; i< 3 ; i++){
        int h ;
        std::cin >> h;
        H.push_back(h);
    }
    int temp;
    temp = H[0];
    H[0] = H[1];
    H[1] = temp;
    
    temp = H[0];
    H[0] = H[2];
    H[2] = temp;
    
    std::cout << H[0] << " " << H[1] << " " << H[2] << std::endl; 
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 1000

int main(){
  int n, i, j, tmp;
  scanf("%d",&n);
  
  int A[n];
  for(i = 0; i < n; i++) scanf("%d", &A[i]);

  for(j = 0; j < n; j++){
    if(j == n-1) printf("%d",A[j]);
    else printf("%d ",A[j]);
  }
  printf("\n");

  for(i = 1; i < n; i++){
    tmp = A[i];
    j = i - 1;

    while(j >= 0 && A[j] > tmp){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = tmp;
    
    for(j = 0; j < n; j++){
      if(j == n-1) printf("%d",A[j]);
      else printf("%d ",A[j]);
    }
    printf("\n");
  }

  return 0;
}



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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;

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

    int x, a, b;
    cin >> x >> a >> b;

    int ans = (x - a) % b;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <cctype>
#define ll          long long int
#define PB          push_back
#define GO          ll t; cin>>t; while(t--)
#define ALLR(x)     x.rbegin(), x.rend()
#define PII         pair<ll ,ll >
#define VI          vector<ll >
#define ALL(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define PI          3.141592653589793238
#define SZ(x)       (ll )x.size()
#define hell2        998244353
#define hell9        1000000007
#define FO(i,a,b)    for(i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define BS          binary_search
#define MP          make_pair
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(0);
/*ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;
    x = x % p;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
      y = y>>1; 
        x = (x*x) % p; 
    } 
    return res; 
} 
ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
} 
ll fac[500000]={0};
ll done=1;
ll ncrModP(ll n, ll r, ll p) 
{ 
   if (r==0) 
      return 1; 
     
    fac[0] = 1; 
    if(n>done)
    {for (ll i=done ; i<=n; i++) 
        fac[i] = (fac[i-1]*i)%p;}
        done=max(done,n); 
  
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 

} 
/*ll ncrM(ll n, ll r, ll p) 
{ 
    if (r > n - r) 
        r = n - r; 
    ll C[r + 1]; 
    memset(C, 0, sizeof(C)); 
    C[0] = 1; 
    for (ll i = 1; i <= n; i++) { 
        for (ll j = min(i, r); j > 0; j--) 
      C[j] = (C[j] + C[j - 1]) % p; 
    } 
    return C[r]; 
}
map<ll,ll>f;
ll done=2;
ll fib(ll k)
{
    ll i;f[0]=1;f[1]=1;f[2]=2;
    if(k<=done)return f[k];
    for(i=done;i<=k;i++)f[i]=(f[i-1]%hell9+f[i-2]%hell9)%hell9;
    done=k;
    return f[k]%hell9;
}*/
int main()
{
//  #ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//  #endif
    fio
    ll n,w,i,a,b,j;cin>>n>>w;vector<pair<ll,ll> >v;ll dp[n+1][w+1];
    FO(i,0,n)
    {
        cin>>a>>b;v.PB({a,b});
    }
    
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=w;j++)
        {
            if(i==0||j==0)dp[i][j]=0;
            else 
            {   dp[i][j]=dp[i-1][j];
                if(j-v[i-1].F>=0)
                {
                    dp[i][j]=max(dp[i][j],dp[i-1][j-v[i-1].F]+v[i-1].S);
                }
            }
            
        }
    }
        
        cout<<dp[n][w];
        return 0;
}

Measured memory_bytes: 79232