akhauriyash/Code-Regression huggingface dataset:
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    readint;
    int k = readint;
    auto xs = readints;

    int ans = 0;
    foreach (x; xs) {
        // (0, i) のロボットが回収する
        int a = x * 2;
        // (k, i) のロボットが拐取する
        int b = (k - x) * 2;
        ans += min(a, b);
    }
    writeln(ans);
}


Measured memory_bytes: 256
from itertools import permutations

N, M = map(int, input().split())
pe = permutations([i for i in range(N)])

matrix = [[0] * N for _ in range(N)]
for _ in range(M):
    u, v = map(int, input().split())
    matrix[u - 1][v - 1] = 1
    matrix[v - 1][u - 1] = 1

cnt = 0
for p in pe:
    for i in range(N - 1):
        if i == 0 and p[i] != 0:
            break
        if matrix[p[i]][p[i + 1]] == 1:
            continue
        else:
            break
    else:
        cnt += 1
print(cnt)


Measured memory_bytes: 3064
import java.util.Scanner;
public class Main{
    public static void main(String args[]){
       Scanner scan = new Scanner(System.in);
       String[] X = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
       int i;
       String Y = scan.nextLine();
       for(i=0;i<7;i++) if(Y.equals(X[i]))break;
       System.out.printf("%d",7-i);
    }
}

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

	string s;
	cin >> s;
	if (s == "Sunny")cout << "Cloudy" << endl;
	if (s == "Cloudy")cout << "Rainy" << endl;
	if (s == "Rainy")cout << "Sunny" << endl;
}

Measured memory_bytes: 256
'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf8');

// Your code here!
const max = (a)=>{
    let i = a.length;
    let max=-Infinity;
    while (i--) {
        if (a[i] > max)max = a[i];
    }
    return max;
}
const min = (a)=>{
    let i = a.length;
    let max=Infinity;
    while (i--) {
        if (a[i] < max)max = a[i];
    }
    return max;
}
const Main = (p)=>{
	p = p.split("\n");//2 or more
	const K=p[0];
	//const t=p[1];
	//const N = parseInt(p[0]);//N
    const A = parseInt(p[1].split(" ")[0]);//N M
	const B = parseInt(p[1].split(" ")[1]);//N M
	//let h = (p[1].split(" ").map(Number));//a1 a2 a3...

	//let w = new Array(s.length+1);
	//let ans = new Array(Math.max(s.length,t.length));
	//for(let i=0;i<=s.length;i++)w[i]=new Array(t.length+1).fill(-1);
	//let v = new Array(N);
	//let c=new Array(N);
    //let z=new Array(N);
    if(A%K==0||B%K==0)console.log("OK");else
    console.log(Math.floor(A/K)==Math.floor(B/K)?"NG":"OK");
    
}
Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


Measured memory_bytes: 29896
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using vl=vector<ll>;
using vvl=vector<vl>;
using vs=vector<string>;
using vb=vector<bool>;
using pll=pair<ll,ll>;
using vpll=vector<pll>;
const ll oo=0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

vvl adj;

int main(){
	cin.sync_with_stdio(0);

	ll N, M;
	cin >> N >> M;

	adj.resize(N);

	FOR(i, 0, M) {
		ll a, b;
		cin >> a >> b;
		a--;
		b--;

		adj[a].pb(b);
		adj[b].pb(a);
	}

	ll largest = 0;

	vb visited(N);
	FOR(i, 0, N) {

		queue<ll> q;
		q.push(i);

		ll count = 0;
		while(sz(q)) {
			ll cur = q.front();
			q.pop();

			if (visited[cur]) {
				continue;
			}
			visited[cur] = true;

			count++;

			for(ll neigh : adj[cur]) {
				q.push(neigh);
			}
		}

		largest = max(largest, count);
	}

	cout << largest << endl;
}

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

const int dx[4] = {+1, 0, -1, 0};
const int dy[4] = {0, -1, 0, +1};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll a, b, c; cin >> a >> b >> c;
    // cout << 2 * sqrt(a * b) << " " << c - a - b << endl;
    if(c - a - b <= 0){
        cout << "No" << endl;
    }else if(4 * a * b < (c - a - b) * (c - a - b)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


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

int main(){
    int n;
    cin >> n;
    string s0, s1;
    cin >> s0 >> s1;
    vector<int> ns(0);
    rep(i, n){
        if(s0.at(i) == s1.at(i)){
            ns.push_back(1);
        }else{
            ns.push_back(2);
            i++;
        }
    }
    ll ans;
    if(ns.at(0) == 1){
        ans = 3;
    }else{
        ans = 6;
    }
    rep(i, ns.size()-1){
        if(ns.at(i) == 1 && ns.at(i+1) == 1){
            ans *= 2;
        }else if(ns.at(i) == 1 && ns.at(i+1) == 2){
            ans *= 2;
        }else if(ns.at(i) == 2 && ns.at(i+1) == 1){
            ans *= 1;
        }else if(ns.at(i) == 2 && ns.at(i+1) == 2){
            ans *= 3;
        }
        if(ans >= 1000000007) ans %= 1000000007;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long  ll;

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
ll MOD = 1000000007;

int main() {
	ll N; cin >> N;
	ll max = 0;
	map<ll, ll> mp;
	rep(i, 0, N) {
		ll a; cin >> a;
		mp[a]++;
	}

	ll rec = 0;
	ll squ = 0;
	ll h = 0;
	ll w = 0;

	for (map<ll, ll>::iterator it = mp.begin(); it != mp.end(); it++) {
		if (it->second >= 2) {
			if (h != it->first || h == 0) {
				w = h;
				h = it->first;

				if (h != 0 && w != 0 && squ < h*w) {
					squ = h * w;
				}
			}
		}
		if (it->second >= 4) {
			ll t = it->first * it->first;
			if (rec < t) {
				rec = t;
			}
		}
	}

	cout << ((rec > squ) ? rec : squ) << endl;
	return 0;
}

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

#define MAX 50

int dp[MAX];

int fib(int n) {
  if ( n < 0 ) return 0;
  if ( n == 0 || n == 1) {
    dp[n] = 1;
    return 1;
  }
  if ( dp[n] != 0 ) {
    return dp[n];
  }
  return dp[n] = fib(n - 1) + fib(n - 2);
}

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

  cout << fib(n) << endl;

  return 0;
}

Measured memory_bytes: 3080
<?php
fscanf(STDIN, "%d%d", $H, $W);
for($y = 0; $y < $H; $y++){
    fscanf(STDIN, "%s", $str);
    $map[$y] = str_split($str);
    for($x = 0; $x < $W; $x++){
        if($map[$y][$x] == "#"){
            $list[] = [$y,$x];
        }
    }
}
$count = 0;
while($list){
    $nextList = [];
    foreach($list as list($y, $x)){
        if($x){
            if($map[$y][$x-1] == "."){
                $map[$y][$x-1] = "#";
                $nextList[] = [$y, $x-1];
            }
        }
        if($y){
            if($map[$y-1][$x] == "."){
                $map[$y-1][$x] = "#";
                $nextList[] = [$y-1, $x];
            }
        }
        if($x < $W-1){
            if($map[$y][$x+1] == "."){
                $map[$y][$x+1] = "#";
                $nextList[] = [$y, $x+1];
            }
        }
        if($y < $H-1){
            if($map[$y+1][$x] == "."){
                $map[$y+1][$x] = "#";
                $nextList[] = [$y+1, $x];
            }
        }
    }
    $list = $nextList;
    if($list)$count++;
}
echo $count;


Measured memory_bytes: 475624
//
// Created by chenlei on 19-1-12.
//
#include "iostream"
using namespace std;
int main()
{
    int n;
    cin >> n;
    if (n == 3 || n == 5 || n == 7){
        cout << "YES" << endl;
    } else
        cout << "NO" << endl;

    return 0;
}


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

int main() {
  int n,m;
  cin >> n >> m;
  int s[m],c[m];
  int ans[n];
  int anan =0;
  int flag = 0;
  for(int i=0;i<n;i++){
    ans[i]=0;
  }

  if(n!=1){
  for(int i=0;i<m;i++){
    cin >> s[i] >> c[i];
    if((ans[s[i]-1]==0 || ans[s[i]-1]==c[i]) && s[i] !=1 ){
      ans[s[i]-1]=c[i];
    }
    else if((ans[s[i]-1]==0 || ans[s[i]-1]==c[i]) && s[i] ==1 && c[i]!=0){
      ans[s[i]-1]=c[i];
    }
    else{
      flag = 1;
      break;
    }
  }

  if(m==0){
    anan =1;
    for(int i=0;i<n-1;i++){
      anan = anan*10;
    }
    cout << anan <<endl;
  }
  else if(flag==1){
    cout << -1 <<endl;
  }
  else if(ans[0]==0){
    ans[0]=1;
    for(int i=0;i<n;i++){
      anan = anan*10+ans[i];
    }
    cout << anan <<endl;
  }
  else{
    for(int i=0;i<n;i++){
      anan = anan*10+ans[i];
    }
    cout << anan <<endl;
  }
}
  else if(n==1){
  for(int i=0;i<m;i++){
    cin >> s[i] >> c[i];
    if(ans[s[i]-1]==0 || ans[s[i]-1]==c[i]){
      ans[s[i]-1]=c[i];
    }
    else{
      flag = 1;
      break;
    }
  }

  if(m==0){
    cout << 0 <<endl;
  }
  else if(flag==1){
    cout << -1 <<endl;
  }
  else{
    cout << ans[0] <<endl;
  }

}



}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define MOD 1000000007
typedef long long ll;

int counter(int x){
    if(x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}

int main() {
    struct s{
        int a;
        vector<int> x;
        vector<int> y;
    };
    int n;
    cin >> n;
    vector
 str(n);
    rep(i, n){
        cin >> str[i].a;
        str[i].x.resize(str[i].a);
        str[i].y.resize(str[i].a);
        rep(j, str[i].a){
            cin >> str[i].x[j];
            cin >> str[i].y[j];
        }
    }
    int ans = 0;
    for(int bits = 1; bits < (1 << n); bits++){
        bool ok = true;
        for(int i = 0; i < n; i++){
            if(!(bits & (1 << i))) continue;
            for(int j = 0; j < str[i].a; j++){
                if(((bits >> (str[i].x[j]-1)) & 1) ^ str[i].y[j]) ok = false;
            }
        }
        if(ok) ans = max(ans, counter(bits));
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
const BKRT = "\n";
const SPAC = " ";
const NOSP = "";

function Main(input){
	input = [].concat(...input.split(BKRT).map(a=>a.split(SPAC)));
  const strShift = ()=>input.shift();
  const intShift = ()=>~~input.shift();
  
  var A = intShift();
  var B = intShift();
  
  var C = strShift().split("-");
  
  if(C.length != 2)return"No";
  if(C[0].length != A)return"No";
  if(C[1].length != B)return"No";
  
  return "Yes";
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
3 4
269-66-0
`);

Measured memory_bytes: 9420
N = [int(i) for i in input().split()][0]
string = list(input())
Q = [int(i) for i in input().split()][0]
queries = [[i for i in input().split()] for _ in range(Q)]

tmp = N 
c = 0
while tmp > 0:
  c += 1
  tmp //= 2
N2 = 2**c
offset = N2 - 1

seg_tree = [0 for _ in range(N2*2 -1)]
for n in range(N):
  ind = ord(string[n]) - ord("a")
  seg_tree[offset + n] = 1 << ind

def set_seg_tree(i, seg_trees):
  if i >= N2 -1:
    return seg_trees[i]
  left = 2*i + 1
  right = 2*i + 2
  l_seg = set_seg_tree(left, seg_trees)
  r_seg = set_seg_tree(right, seg_trees)
  seg_trees[i] = l_seg | r_seg
  return seg_trees[i]
set_seg_tree(0, seg_tree)
    
def update(i, c, seg_trees):
  i += offset
  seg_trees[i] = 1 << c
  while i > 0:
    i = (i - 1)//2
    seg_trees[i] = seg_trees[i * 2 + 1] | seg_trees[i * 2 + 2]

def get_sum(a, b, k, l, r, seg_trees):
  if (b <= l) or (r <= a):
    return 0
  if (a <= l) and (r <= b):
    return seg_trees[k]
  vl = get_sum(a, b, k * 2 + 1, l, (l + r)//2, seg_trees)
  vr = get_sum(a, b, k * 2 + 2, (l + r)//2, r, seg_trees)
  return vl | vr

for query in queries:
  type_, i, q = query
  if type_ == "1":
    i = int(i) - 1
    pos = ord(q) - ord("a")
    update(i, pos, seg_tree)
  else:
    l = int(i) - 1
    r = int(q)
    ret = get_sum(l, r, 0, 0, N2, seg_tree)
    print(bin(ret).count("1"))


Measured memory_bytes: 52176
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

typedef long long ll;
typedef long double ld;
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPR(i,a,b) for(int i = b; i >= a; i--)
#define all(a)              a.begin(), a.end()
#define alln(a, n)          (a, a+n)
#define sz(x) (int)(x).size()
#define MAX                 10000007
#define MIN                 -10000007
#define pi pair<int,int>
#define pl pair<ll,ll>
#define mii             map<int,int>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define inf 1e18
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef vector<int> vi; 
typedef vector<ll> vl; 
typedef vector<pi> vpi;
typedef vector<pl> vpl; 
typedef vector<vi> vvi; 
typedef vector<string> vs;
typedef set<int> si;
const int MOD=1e9+7;
ll lcm(ll a,ll b){return (a * b) / __gcd(a,b);}
ll gcd(ll a,ll b){return __gcd(a,b);}
ll power(ll a,ll b,ll MOD){if(b == 0)return 1;if(b == 1)return a;ll ans = power(a,b/2,MOD) % MOD;ans *= ans;ans %= MOD;if(b % 2 == 1)ans *= a;return ans%MOD;}
ll inverse(ll x){x%=MOD;return power(x,MOD-2,MOD);}
ll fact[1],inv[1];
void factorial(ll n){
  fact[0]=1;
  for(ll i=1;i<=n;i++){
    fact[i]=fact[i-1]*i;
    if(fact[i]>=MOD)
      fact[i]%=MOD;
  }
}
ll ncr(ll n,ll r){
  if(n<r||n<0||r<0)
    return 0;
  ll b=inv[n-r];
  ll c=inv[r];
  ll a=fact[n]*b;
  if(a>=MOD)
    a%=MOD;
  a*=c;
  if(a>=MOD)
    a%=MOD;
  return a;
}
vector<char> is_prime(100001, true);
void sieve(ll n){
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= n; i++) {
        if (is_prime[i] && (long long)i * i <= n) {
            for (int j = i * i; j <= n; j += i)
                  is_prime[j] = false;
        }
  }    
}     
 
int main()
{
  ios::sync_with_stdio(0);
    cin.tie(0);
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
      
    int t;
    t=1;
    cout<<fixed<<setprecision(0);
     //  cin>>t;
    while(t--){
            string s;
            cin>>s;
            int n=s.size();
            s[n-1]=='s'?cout<<s<<"es":cout<<s<<"s"; 
              
       


             }
             cerr<<"Time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
    return 0;
}


Measured memory_bytes: 3880
#include<cstdio>
using namespace std;
int a[600001],h,t,n,x;
int main(){
	scanf("%d",&n);
	h=n+1,t=n;
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		i&1?a[--h]=x:a[++t]=x;
	}
	if(n&1)
		for(int i=h;i<=t;i++)printf("%d ",a[i]);
	else for(int i=t;i>=h;i--)printf("%d ",a[i]);
	puts("");
	return 0;
}


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

int main(){
  int n;
  string s;
  cin >> n;
  cin >> s;
  int tmp;
  for(int i=0; i<s.size(); i++){
    tmp = (int)(s.at(i)) - 65 + n;
    //cout << tmp << endl;
    cout << (char)((tmp%26)+65);
}
  cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>

using namespace std;

int main() {
	string a;
	int b = 0;
	int c = 0;
	cin >> a;
	
	b = stoi(a);
	
	for (int i = 0; i < a.length(); i++) {
		c += (a[i] - '0');
	}

	if (b % c == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}

Measured memory_bytes: 256
from collections import deque
n = int(input())
q = deque([])
now = 0
reach = [0]*100001
lis = []
for i in range(6):
    lis.append(6**(i+1))
for i in range(5):
    lis.append(9**(i+1))
lis.append(1)
lis = sorted(lis)
q.append(0)
ans = 0
while q:
    if ans == 1:
        break
    x = q.popleft()
    
    for y in lis:
        if x + y < n:
            if  reach[x+y] == 0:
                q.append(x+y)
                reach[x+y] = reach[x]+1
            
        elif x + y == n:
            reach[x+y] = reach[x]+1
            ans = 1
            break
print(max(reach))

Measured memory_bytes: 4932
//From Naruto to Hokage
//#include <RJ>
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
	ll n;
	cin>>n;
	ll cost[n][n];
	rep(i,0,n-1) rep(j,0,n-1) cin>>cost[i][j];
	ll dp[(1<<n)];
	memset(dp,0,sizeof(dp));
	dp[0]=1;
	rep(i,0,(1<<n)-2){
		ll x=__builtin_popcount(i);
		rep(j,0,n-1){
			if(cost[x][j] && ((i&(1<<j))==0)) dp[i|((1<<j))]=(dp[i|((1<<j))]+dp[i])%hell;
		}
	}
	cout<<dp[(1<<n)-1];
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

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

#define rep(i,n) for(int i=0; i<n; i++)

int main(){
  int n,m;
  cin >> n >> m;

  int sum=0;
  int a[n];
  int count = 0;
  rep(i,n){
    int A;
    cin >> A;
    a[i] = A;
    sum += A;
  }
    
  rep(i,n){

    if(a[i]>= sum/(4. * m) )count++;
  }

  if(count >= m ){
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <sstream>
#include <queue>

using namespace std;

string str;

int main(){
  
  cin >> str;
  int scnt = 0;
  int pnum = 0;
  for(int i=0;i<str.length();++i){
    if(str[i]=='S'){
      //cout<<"sadd"<<i<<endl; //debug
      scnt++;
    }
    if(str[i]=='T'){
      if(scnt > 0){
	//cout<<"del"<<i<<endl; //debug
	scnt--;
	pnum++;
      }
    }
  }
  cout<<str.length()-pnum*2<<endl;
  return 0;
}

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

int main() {
  int a;
  
  cin >> a;
  
  int a100 = a / 100; // 111 / 100
  int a100_left = a % 100; //  あまり11
  int a10 = a100_left / 10; // 11 / 10
  int a10_left = a100_left % 10; // あまり1
  int a1 = a10_left / 1;
    
  cout << a100 + a10 + a1 << endl;
}

Measured memory_bytes: 3596
#include "stdio.h"
int main()
{
	long A, B;
	long i;
	int k,start;

	long smallcount = 0;
	long th;
	scanf("%ld %ld %d",&A,&B,&k);
	th = B - k;
	if (th < A)th = A;
	for (i = A; i <= B; i++, smallcount++) {
		if (smallcount < k) {
			printf("%ld\n", i);
		}
		else if(i > th) {
			printf("%ld\n", i);
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
using namespace std;

int main()
{
  int N;
  cin >>N;
  int a[120000];
  for(int i=0;i<N;i++)
  cin >>a[i];

  int j=0;
  int count=0;
  for(int i=0 ; i<N;i++){
    int k=a[j]-1;
    count++;
    if(k==1)break;
    j=k;
  }
  if(count == N) cout<<-1<<endl;
  else cout<<count<<endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>

using namespace std;

int main(){
    int R, C, N; cin >> R >> C >> N;
    auto getIdx = [&](int x, int y){
        if(y == 0) return x;
        if(x == R) return R + y;
        if(y == C) return 2 * R + C - x;
        if(x == 0) return 2 * R + 2 * C - y;
        return -1;
    };
    vector<pair<int, int>> vp;
    for(int i=0;i<N;i++){
        int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
        int idx1 = getIdx(x1, y1);
        int idx2 = getIdx(x2, y2);
        if(idx1 != -1 && idx2 != -1){
            vp.emplace_back(idx1, i);
            vp.emplace_back(idx2, i);
        }
    }
    bool ok = true;
    sort(vp.begin(), vp.end());
    vector<int> check(N, 0);
    stack<int> st;
    for(auto& p : vp){
        int idx = p.second;
        if(check[idx]){
            if(st.top() != idx) ok = false;
            st.pop();
        } else {
            st.push(idx);
            check[idx] = 1;
        }
    }
    cout << (ok ? "YES" : "NO") << endl;
}

Measured memory_bytes: 5356
n=int(input())
it=[[],[],[]]
for i in range(n):
    aa=list(map(int,input().split()))
    it[0].append(aa[0])
    it[1].append(aa[1])
    it[2].append(aa[2])
dp=[[0,0,0] for i in range(n)]
for i in range(3):
    dp[0][i]=it[i][0]
for i in range(1,n):
    for j in range(3):
        for k in range(3):
            if k==j:
                continue
            dp[i][j]=max(dp[i][j],dp[i-1][k]+it[j][i])

print(max(dp[-1]))


Measured memory_bytes: 82136
package main
import . "fmt"
func main() {
  var s,p []string
  var i,n []int
  var turn int
  s = make([]string,3)
  Scan(&s[0])
  Scan(&s[1])
  Scan(&s[2])
  i = []int{0,0,0}
  n = []int{len(s[0]),len(s[1]),len(s[2])}
  p = []string{"A","B","C"}
  turn = 0
  for ;; {
    if i[turn] == n[turn] { break }
    i[turn]++
    switch s[turn][i[turn]-1:i[turn]] {
      case "a" : turn = 0
      case "b" : turn = 1
      case "c" : turn = 2
    }
  }
  Println(p[turn])
}

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

namespace solve
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            for (int k = 0; k < N; k++)
            {
                string s = Console.ReadLine();
                string t = Console.ReadLine();
                int[,] dp = new int[t.Length + 1, s.Length + 1];

                for(int i = 0; i < t.Length; i++)
                {
                    for (int j = 0; j < s.Length; j++)
                    {
                        if (t[i] == s[j]) dp[i + 1, j + 1] = dp[i, j] + 1;
                        else dp[i + 1, j + 1] = Math.Max(dp[i, j + 1], dp[i + 1, j]);
                    }
                }

                Console.WriteLine(dp[t.Length, s.Length]);
            }
        }
    }
}



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

int main()
{
  int n , answer , sub ;
  answer = 0 ;
  sub = 0 ;
  cin >> n ;
  vector<int> h(n) ;
  for(int i=0 ; i<n; i++)
    cin >> h.at(i);
  for(int i=0; i<n-1; i++)
  {
    if(h.at(i) >= h.at(i+1))
    {
      sub++ ;
    }else{
      if(sub > answer)
        answer = sub ;
      sub = 0 ;
    }
  }
  if(sub > answer)
    answer = sub ;
  cout << answer << endl ;
}

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

typedef long long lint;

int main(){
    lint N,x;
    cin >> N >> x;
    if(x==1 || x==2*N-1){
        cout << "No" << endl;
        return 0;
    }
    lint ans[200000];

    cout << "Yes" << endl;
    if(N==2){
        cout << 1 << endl << 2 << endl << 3 << endl;
        return 0;
    }
    if(x==2){
        ans[N-1]=x+1;
        ans[N]=x;
        ans[N+1]=x-1;
        ans[N+2]=2*N-1;

        lint num=1;
        for(lint i=1;i<=2*N+1;i++){
            if(i>=N-1 && i<=N+2) continue;
            while((num>=x-1 && num<=x+1) || num==2*N-1) num++;
            ans[i]=num;
            num++;
        }
    }else{
        ans[N-2]=1;
        ans[N-1]=x+1;
        ans[N]=x;
        ans[N+1]=x-1;

        lint num=1;
        for(lint i=1;i<=2*N+1;i++){
            if(i>=N-2 && i<=N+1) continue;
            while(num==1 || (num>=x-1 && num<=x+1)) num++;
            ans[i]=num;
            num++;
        }
    }
    for(lint i=1;i<=2*N-1;i++) cout << ans[i] << endl;

    return 0;
}//

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

using namespace std;

#define ll long long




void solve() {

	int a, b, t;
	cin >> a >> b >> t;
	int x = a;
	int total = 0;
	while(x <= t + 0.5) {
		total += b;
		x += a;

	}
	cout << total;

	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	solve();

	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  ll n;
  cin >> n;
  vl a(n);
  rep(i, n) {
    cin >> a[n-1-i];
  }

  ll maxi = 2;
  ll mini = 2;
  auto f = [](ll n, ll m) {
    return (n+m-1)/m*m;
  };
  auto g = [](ll n, ll m) {
    ll t = n/m*m;
    if (t == n) return n+m-1;
    else return (n/m+1)*m-1;
  };
  rep(i, n) {
    ll tmp_maxi = g(maxi, a[i]);
    ll tmp_mini = f(mini, a[i]);
    //cerr << tmp_mini << " " << tmp_maxi << "\n" << endl;
    if (tmp_mini > tmp_maxi) {
      cout << -1 << endl;
      return 0;
    }
    maxi = tmp_maxi;
    mini = tmp_mini;
  }
  cout << mini << " " << maxi << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

const int INF = 1001001001;

int a[12][12];

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> c(N);
  rep(i,N) {
    cin >> c[i];
    rep(j,M) cin >> a[i][j];
  }

  int ans = INF;
  rep(s,1<<N) {
    int cost = 0;
    vector<int> d(M);
    rep(i,N) {
      if (s>>i&1) {
        cost += c[i];
        rep(j,M) d[j] += a[i][j];
      }
    }
    bool ok = true;
    rep(j,M) if (d[j] < X) ok = false;
    if (ok) ans = min(ans, cost);
  }
  if (ans == INF) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}

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

using ll = long long;
using P = pair<int, int>;

const int MAX = 8005;
const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

bool dp[2][2*MAX];

int main() {
  // 入力
  string s;
  cin >> s;
  int x, y;
  cin >> x >> y;

  vector<int> v; // sをTで区切ったその間のFの数
  int cnt = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'T') {
      v.push_back(cnt);
      cnt = 0;
    } else {
      cnt++;
    }
  }
  v.push_back(cnt);

  // DP
  // 初期値設定
  dp[0][v[0]+MAX] = true;
  dp[1][MAX] = true;

  int dir = 1; // 0:x軸、1:y軸
  vector<int> tmp;
  for (int i = 1; i < v.size(); i++) {
    tmp.clear();

    for (int j = 0; j < 2 * MAX; j++) if (dp[dir][j]) {
      tmp.push_back(j);
      dp[dir][j] = false;
    }
    for (int j = 0; j < tmp.size(); j++) {
      dp[dir][tmp[j]-v[i]] = true;
      dp[dir][tmp[j]+v[i]] = true;
    }

    dir ^= 1;
  }

  // 解答
  cout << (dp[0][x+MAX] && dp[1][y+MAX] ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0228

"""
import sys
from sys import stdin
input = stdin.readline


LED_pattern = [
    ##-gfedcba
    0b0111111,                #  0
    0b0000110,                #  1
    0b1011011,                #  2
    0b1001111,                #  3
    0b1100110,                #  4
    0b1101101,                #  5
    0b1111101,                #  6
    0b0100111,                #  7
    0b1111111,                #  8
    0b1101111,                #  9
    0b0000000                 #  all OFF
]


def solve(cp, np):
    a = LED_pattern[cp]
    b = LED_pattern[np]
    return bin(a ^ b)[2:].zfill(7)


def main(args):
    while True:
        n = int(input())
        if n == -1:
            break
        cp = 10                 #  all OFF
        for _ in range(n):
            d = int(input())
            ans = solve(cp, d)
            cp = d
            print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 5644
a=input()
b=int(a[0]+a[1])
c=int(a[2]+a[3])
if 1<=b<=12:
  if 1<=c<=12:
    print("AMBIGUOUS")
  else:
    print("MMYY")
else:
  if 1<=c<=12:
    print("YYMM")
  else:
    print("NA")

Measured memory_bytes: 9184
# Union by size + path having
class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n + 1))
        self.size = [1] * (n + 1)

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.size[x] >= self.size[y]:
            self.size[x] += self.size[y]
            self.parent[y] = x
        else:
            self.size[y] += self.size[x]
            self.parent[x] = y

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

    def getsize(self, x):
        return self.size[self.parent[x]]


N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(M)]
ans = [None] * M
uf = UnionFind(N)
now = N * (N-1) // 2
for i in range(M - 1, -1, -1):
    ans[i] = now
    a, b = AB[i]
    if not uf.are_same(a, b):
        now -= uf.getsize(a) * uf.getsize(b)
    uf.unite(a, b)
for i in range(M):
    print(ans[i])

Measured memory_bytes: 102744
x1, x2, x3, x4, x5 = map(int, input().split())
if x1==0:
    print("1")
elif x2 ==0:
    print("2")
elif x3 ==0:
    print("3")
elif x4 ==0:
    print("4")
elif x5 ==0:
    print("5")

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

using namespace std;

int main()
{   
	string b;
  	getline(cin,b);
  	for(int i=0;i<b.size();i++)
  	{
  		if(b[i]>=97)b[i]=toupper(b[i]);
  		else b[i]=tolower(b[i]);
  		
	  }
	  
	  
	cout<<b<<endl;

	return 0;
}


Measured memory_bytes: 3144
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
using namespace std;

int solve(int i){
    int res=0;
    while(i>0){
        res+=i%10;
        i/=10;
    }
    return res;
}
int main(void){
    int n,a,b;
    cin>>n>>a>>b;
    int ans=0;
    for(int i=1;i<=n;i++){
        if(solve(i)>=a&&solve(i)<=b)ans+=i;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace agc030_a
{
    class Program
    {
        static void Main(string[] args)
        {
            var text = Console.ReadLine();
            var list = text.Split(' ').ToList().Select(d => int.Parse(d)).ToList();

            var x = list[0];
            var a = list[1];

            if (x < a){
                Console.WriteLine("0");
            }
            else{
                Console.WriteLine("10");
            }
        }
    }
}


Measured memory_bytes: 13268
#include<stdio.h>

int main()
{
    int a,b,c;
    int sum=0;
    scanf("%d%d%d",&a,&b,&c);
    sum=a+b+c;
    if(sum<=21){
        printf("win\n");
    }else{
        printf("bust\n");
    }
    return 0;
}

Measured memory_bytes: 128
// URL: https://atcoder.jp/contests/abc174/tasks/abc174_b

import std.algorithm, std.array, std.bitmanip, std.container, std.conv, std.format,
       std.functional, std.math, std.range, std.traits, std.typecons, std.stdio, std.string;

version(unittest) {} else
void main()
{
  int N; long D; io.getV(N, D);
  long[] X, Y; io.getC(N, X, Y);

  auto D2 = D*D, c = 0;
  foreach (Xi, Yi; lockstep(X, Y))
    if (Xi*Xi + Yi*Yi <= D2) ++c;

  io.put(c);
}

auto io = IO!()();
import std.stdio;
struct IO(alias IN = stdin, alias OUT = stdout)
{
  import std.meta : allSatisfy;
  import core.stdc.stdlib : exit;

  void getV(T...)(ref T v)
  {
    foreach (ref w; v) get(w);
  }
  void getA(T)(size_t n, ref T v)
    if (hasAssignableElements!T)
  {
    v = new T(n);
    foreach (ref w; v) get(w);
  }
  void getC(T...)(size_t n, ref T v)
    if (allSatisfy!(hasAssignableElements, T))
  {
    foreach (ref w; v) w = new typeof(w)(n);
    foreach (i; 0..n) foreach (ref w; v) get(w[i]);
  }
  void getM(T)(size_t r, size_t c, ref T v)
    if (hasAssignableElements!T && hasAssignableElements!(ElementType!T))
  {
    v = new T(r);
    foreach (ref w; v) getA(c, w);
  }
  template getS(E...)
  {
    void getS(T)(size_t n, ref T v)
    {
      v = new T(n);
      foreach (ref w; v) foreach (e; E) mixin("get(w."~e~");");
    }
  }

  const struct PutConf
  {
    bool newline = true, flush, exit;
    string floatFormat = "%.10f", delimiter = " ";
  }

  void put(alias conf = "{}", T...)(T v)
  {
    mixin("const PutConf c = "~conf~"; putMain!c(v);");
  }
  void putB(alias conf = "{}", S, T)(bool c, S t, T f)
  {
    if (c) put!conf(t);
    else put!conf(f);
  }
  void putRaw(T...)(T v)
  {
    OUT.write(v);
    OUT.writeln;
  }

  private
  {
    dchar[] buf;
    auto sp = (new dchar[](0)).splitter;

    void nextLine()
    {
      IN.readln(buf);
      sp = buf.splitter;
    }
    void get(T)(ref T v)
    {
      if (sp.empty) nextLine();
      v = sp.front.to!T;
      sp.popFront();
    }

    void putMain(PutConf c, T...)(T v)
    {
      foreach (i, w; v) {
        putOne!c(w);
        if (i+1 < v.length) OUT.write(c.delimiter);
      }
      static if (c.newline) OUT.writeln;
      static if (c.flush) OUT.flush();
      static if (c.exit) exit(0);
    }
    void putOne(PutConf c, T)(T v)
    {
      static if (isInputRange!T && !isSomeString!T) putRange!c(v);
      else static if (isFloatingPoint!T) OUT.write(format(c.floatFormat, v));
      else static if (hasMember!(T, "fprint")) v.fprint(OUT);
      else OUT.write(v);
    }
    void putRange(PutConf c, T)(T v)
    {
      auto w = v;
      while (!w.empty) {
        putOne!c(w.front); w.popFront();
        if (!w.empty) OUT.write(c.delimiter);
      }
    }
  }
}


Measured memory_bytes: 6988
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> p;
typedef vector<pair<int,int> > vp;
set <int> st;
int n,m;
int ans=0;
vp box(100005);

int main(int argc,char const* argv[])
{
  cin >> n >> m;
  for(int i=1;i<=n;i++)
    {
      if(i==1)
	{
	  box[i].first=1;
	  box[i].second=1;
	}
      else 
	{
	  box[i].first=1;
	  box[i].second=0;
	} 
    }
  for(int i=0;i<m;i++)
    {
      int x,y;
      cin >> x >> y;
      if(box[x].second==1 && box[y].second==0 && box[x].first>=1)
	{
	  if(box[x].first==1) box[x].second=0;
	  box[x].first--;
	  box[y].first++;
	  box[y].second=1;
	}
      else if(box[x].second==1 && box[y].second==1 && box[x].first==1)
	{
	  box[x].first--;
	  box[y].first++;
	  box[y].second=1;
	  box[x].second=0;
	}
      else
	{
	  box[x].first--;
	  box[y].first++;
	}
    }
  for(int i=1;i<=n;i++)
    {
      if(box[i].first!=0 && box[i].second==1) ans++;
    }
  cout << ans << endl; 
  return 0;
}


Measured memory_bytes: 1024
import java.io.PrintWriter
import java.lang.Math.max

val pw = PrintWriter(System.out)

fun p(value: Any?) {
    pw.println(value)
}

fun solve() {
    val S = readLine()!!
    val st = "ACGT"
    var ans = 0
    for (i in S.indices) {
        for (j in S.indices) {
            if (i > j) continue
            if (S.substring(i, j+1).all { st.contains(it) }) {
                ans = max(ans, j-i+1)
            }
        }
    }
    p(ans)
}

fun main(args: Array<String>) {
    solve()
    pw.flush()
}

Measured memory_bytes: 33784
n,a,b,c,d = map(int,input().split())
li = input()
if c<b:
  li = li[:d]
  li = li[a-1:]
  if li.find("##") != -1:
    print("No")
  else:
    print("Yes")
elif c<d:
  li = li[:d]
  li = li[a-1:]
  if li.find("##") != -1:
    print("No")
  else:
    print("Yes")
else:
  li = li[:d+1]
  li = li[a-1:]
  if li.find("##") != -1:
    print("No")
  elif li[b-2-a+1] == "." and li[b-a+1] == ".":
    print("Yes")
  else:
    li = li[b-a:]
    if li.find("...") == -1:
      print("No")
    else:
      print("Yes")

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

using namespace std;

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

  int N, A;
  cin >> N >> A;
  vector<long long> x(N);
  for (auto &xx : x) cin >> xx;

  int R = N*50;
  vector<vector<vector<long long>>> dp(N+1, vector<vector<long long>>(N, vector<long long>(R+1, 0)));
  for (int i = 0; i < N; ++i) {
    dp[1][i][x[i]] = 1;
    for (int a = 0; a <= R; ++a) {
      dp[0][i][a] = 0;
    }
  }

  for (int k = 2; k <= N; ++k) {
    for (int i = 0; i < N; ++i) {
      for (int a = 0; a <= R; ++a) {
        long long sum = 0;
        for (int j = k-2; j < i; ++j) {
          if (a-x[i] >= 0) sum += dp[k-1][j][a-x[i]];
        }
        dp[k][i][a] = sum;
      }
    }
  }
  long long res = 0;
  for (int k = 1; k <= N; ++k) {
    for (int i = 0; i < N; ++i) {
      if (k*A >= x[i]) res += dp[k][i][k*A];
    }
  }
  cout << res << endl;

  return 0;
}



Measured memory_bytes: 51200
#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<cstring>
#include<string>
#include <math.h>
#include<algorithm>
#include<functional>

#define ll long long
#define inf  1000000007
#define mod 1000000007
#define pa pair<int,int>
#define pal pair<ll,ll>
#define ppa pair<int,pa>
#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

class Point{
  public:
  double x,y;
  Point(double x=0,double y=0):x(x),y(y) {}
  Point operator + (Point p) {return Point(x+p.x,y+p.y);}
  Point operator - (Point p) {return Point(x-p.x,y-p.y);}
  Point operator * (double a) {return Point(x*a,y*a);}
  Point operator / (double a) {return Point(x/a,y/a);}
  double absv() {return sqrt(norm());}
  double norm() {return x*x+y*y;}
  bool operator < (const Point &p) const{
    return x != p.x ? x<p.x: y<p.y;
  }
  bool operator == (const Point &p) const{
    return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
  }
};
typedef Point Vector;

struct Segment{
Point p1,p2;
};

double hen(Vector a){
if(fabs(a.x)<EPS && a.y>0) return acos(0);
else if(fabs(a.x)<EPS && a.y<0) return 3*acos(0);
else if(fabs(a.y)<EPS && a.x<0) return 2*acos(0);
else if(fabs(a.y)<EPS && a.x>0) return 0.0;
else if(a.y>0) return acos(a.x/a.absv());
else return 2*acos(0)+acos(-a.x/a.absv());

}

double dot(Vector a,Vector b){
  return a.x*b.x+a.y*b.y;
}
double cross(Vector a,Vector b){
  return a.x*b.y-a.y*b.x;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int ru[11]={1,2,4,8,16,32,64,128,256,512,1024};

ll frac[100010];
ll inv[100010];

ll saikif(ll a,int n){
  if(n==1) return a%mod;
  else if(n%2==0){
    ll q=saikif(a,n/2);
    return (q*q)%mod;
  }
  else return (a*saikif(a,n-1))%mod;
}

void gyakugen(){
  frac[0]=1;
  for(int i=1;i<=100000;i++) frac[i]=(frac[i-1]*i)%mod;
  for(int i=0;i<=100000;i++) inv[i]=saikif(frac[i],mod-2);
}


//----------------kokomade temple------------

int a[10010][1270]={0};
//int b[10010][1270]={0};
int main(){
int n,m;

while(cin>>n>>m){
  int t,nn,mm,s;
fill(a[0],a[10010],0);
//fill(b[0],b[10010],0);
if(n==0 && m==0) break;
int r,q;
cin>>r;
for(int i=0;i<r;i++){
cin>>t>>nn>>mm>>s;
if(s==1){
  a[mm][t]++;
//  cout<<mm<<" in "<<t<<endl;
}
else{
  a[mm][t]--;
//  cout<<mm<<" out "<<t<<endl;
}
}

for(int i=1;i<=m;i++){
  for(int j=1;j<1265;j++){
    a[i][j] +=a[i][j-1];
  }

    for(int j=1;j<1265;j++){
      if(a[i][j] >0) a[i][j]=1;
    }
  for(int j=1;j<1265;j++){
    a[i][j] = a[i][j-1]+a[i][j];
  }
}

cin>>q;
int ts,te,mm1;
for(int i=0;i<q;i++){
cin>>ts>>te>>mm1;
cout<<a[mm1][te-1]-a[mm1][ts-1]<<endl;
}


}

return 0;
}

Measured memory_bytes: 52352
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define pf push_front
#define pii pair <int, int>
#define all(vv) (vv).begin(), (vv).end()
#define time cerr << '\n' << (double)clock()/CLOCKS_PER_SEC << '\n'; return 0
 
//link: https://atcoder.jp/contests/arc103/tasks/arc103_a
 
vector <int> e;
vector <int> o;
map <int, int> mpe;
map <int, int> mpo;
int32_t main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	bool can = true;
	int n; cin >> n;
	for(int i = 0; i < n; ++i) {
		int x; cin >> x;
		if (i % 2 == 0) o.pb(x);
		else e.pb(x);
	}
	// find the top 2 modes
	for(auto it:e) {
		++mpe[it];
	}
	vector <pii> MPE; // convert to vector for sorting
	for(auto it:mpe) {
		MPE.pb(make_pair(it.second, it.first));
	}
	sort(all(MPE), greater<pair<int, int> > ());
	int e1 = MPE[0].second;
	int e2 = MPE[1].second;
	cerr << e1 << ' ' << e2 << '\n';
	// repeat!!
	for(auto it:o) {
		++mpo[it];
	}
	vector <pii> MPO;
	for(auto it:mpo) {
		MPO.pb(make_pair(it.second, it.first));
	}
	sort(all(MPO), greater<pair<int, int> >());
	int o1 = MPO[0].second;
	int o2 = MPO[1].second;
	cerr << o1 << ' ' << o2 << '\n';
 
	if (e1 != o1) {
		// assert(0);
		int count = 0;
		for(auto it:e) {
			if (it != e1) ++count;
		}
		for(auto it:o) {
			if (it != o1) ++count;
		}
		cout << count;
		time;
	}
 
	// find the number of changes required for first type
	int count = 0;
	for(auto it:e) {
		if (it != e1) ++count;
	}
	for(auto it:o) {
		if (it != o2) ++count;
	}
	// second type
	int sum = 0;
	for(auto it:e) {
		if (it != e2) ++sum;
	}
	for(auto it:o) {
		if (it != o1) ++sum;
	}
	cout << min(count, sum);
}

Measured memory_bytes: 12680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

int main() {
	ll r,c;
	cin >> r >> c;
	ll ans;
	if(r==1||c==1) ans = 1;
	else ans = (r*c+1)/2;
	cout << ans << endl;
}

Measured memory_bytes: 256
( n, m) = [ int(i) for i in input().split()]
A = []
b = []

for i in range(n):
    A.append( [ int(j) for j in input().split()])

for i in range(m):
    b.append( int(input()))
    
for i in range(n):
    s = 0
    for j in range(m):
        s += A[i][j] * b[j]
    print(s)

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  ll k;
  cin >> n >> k;
  vector<int> a(n + 1);
  rep(i, n) {
    cin >> a[i + 1];
  }
  vector<int> num(n + 1);
  int step = 1;
  int i = 1;
  for(; num[i] == 0; i = a[i]) {
    num[i] = step++;
    if(step > k + 1) break;
  }
  if(step > k + 1) {
    cout << i << endl;
    return 0;
  }
  k -= num[i] - 1;
  ll m = k % (step - num[i]);
  rep(j, m) {
    i = a[i];
  }
  cout << i << endl;
  return 0;
}

Measured memory_bytes: 4788
S = list(input())
T = list(input())

countT = {}
countS = {}

for s, t in zip(S, T) :
    if t in countT :
        countT[t].append(s)
    else :
        countT[t] = [s]
    if s in countS :
        countS[s].append(t)
    else :
        countS[s] = [t]

for (_, s), (_, t) in zip(countS.items(), countT.items()) :
    if len(set(s)) >= 2 or len(set(t)) >= 2:
        print('No')
        break
else :
    print('Yes')


Measured memory_bytes: 10408
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


# globals
inf = float('inf')
N = 0
A = []


def set_inputs():
    global N, A
    N = get_int()
    A = get_li()
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    # ----------MAIN----------
    forward = [A[0]]
    for a in A[1:]:
        forward.append(gcd(forward[-1], a))
    backward = [A[-1]]
    for a in reversed(A[:-1]):
        backward.append(gcd(backward[-1], a))
    backward.reverse()
    ans = max(forward[-2], backward[1])
    for i in range(1, len(A)-1):
        ans = max(ans, gcd(forward[i-1], backward[i+1]))
    print(ans)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    main()


Measured memory_bytes: 16096
import itertools
from sys import exit

N, K = map(int, input().split())
max_edge = (N - 1) * (N - 2) // 2
if K > max_edge:
    print(-1)
    exit()

print(N - 1 + max_edge - K)
for i in range(1, N):
    print(i, N)

cnt = max_edge
it = itertools.combinations(range(1, N), 2)
while cnt > K:
    print(*next(it))
    cnt -= 1


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

int main() {
  string s;
  bool flag = false;
  cin>>s;
  if(s.at(0)!=s.at(1)||s.at(1)!=s.at(2)||s.at(0)!=s.at(2))
     flag = true;
  if(flag){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		boolean found[] = new boolean[26];
		for(int i = 0; i < 26; i++) found[i] = false;
		boolean result = true;
		for(int i = 0; i < s.length(); i++) {
			if(found[(int)s.charAt(i) - 97]) {
				result = false;
				break;
			}
			found[(int)s.charAt(i) - 97] = true;
		}
		if(result) System.out.println("yes");
		else System.out.println("no");
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cctype>
#include <functional>
#include <map>
#include <cmath>

using namespace std;
typedef long long ll;

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    cout << abs(a[0] - a[n-1]) << endl;
    return 0;
}

Measured memory_bytes: 256