akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<string.h>
#include<vector>
#include<map>
#include<math.h>
#include<queue>
#include<algorithm>
#define ll long long
using namespace std;
ll a[200010], b[200010];
ll suma[200010], sumb[200010];
int main() {
	int n, m, k,cnta=0,cntb=0;
	bool flag = 1;
	cin >> n >> m >> k;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (flag) {
			suma[i] = suma[i - 1] + a[i];
			cnta=i;
			if (suma[i] > k)flag=0;
		}
	}
	flag = 1;
	for (int i = 1; i <= m; i++) {
		cin >> b[i];
		if (flag) {
			sumb[i] = sumb[i - 1] + b[i];
			cntb=i;
			if (sumb[i] > k)flag = 0;
		}
	}
	int pb = cntb, ans = 0;
	for (int i = 0; i <= cnta; i++) {
		while (pb>0&&sumb[pb] + suma[i] > k)
			pb--;
		if(pb>=0&& sumb[pb] + suma[i] <= k)ans = max(ans, pb + i);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 9344
using System;
using static System.Console;
using static System.Math;
using System.Linq;
using System.Collections.Generic;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            decimal[] tmp = ReadLine().Split(' ').Select(decimal.Parse).ToArray();
            decimal N = tmp[0];
            decimal K = tmp[1];

            N = N % K;
            WriteLine(N > K - N ? K - N : N);
        }
    }
}

Measured memory_bytes: 11348
import java.util.*;
import java.math.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long c = sc.nextLong();
    if(a + b < c && 2 * a * b + 2 * c * a + 2 * c * b < c * c + b * b + a * a) System.out.println("Yes");
    else System.out.println("No");
  }
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int pre = -999;
  rep(i,n) {
    if (pre <= a[i]-1) {
      pre = a[i]-1;
    } else if (pre <= a[i]) {
      pre = a[i];
    } else {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 640
n=int(input())
lists=list(map(int,input().split()))
lists=sorted(lists,reverse=True)

mod=10**9+7
dp=[0 for i in range(n+1)]
dp[1]=2*lists[0]
for i in range(1,n):
    x=lists[i]
    y=pow(2,i,mod)
  
    dp[i+1]=4*dp[i]+(i+2)*(y**2)*lists[i]
    dp[i+1]%=mod

print(dp[n]%mod)

Measured memory_bytes: 107724
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
int main(){
  int a, n;
  string s;
    cin >> a >> n >> s;
  for(int i=0; i<a; i++)
    if(i==n-1) printf("%c", tolower(s[i]));
    else cout << s[i];
  cout << endl;
}


Measured memory_bytes: 256
N = int(input())
W = list(map(int,input().split()))
goukei = 0
mae = 0
ato = 0
for x in W:
  goukei+=x
for y in W:
  mae += y
  if mae > goukei-mae:
    ato = mae - y 
    break
print(min(abs(2*mae - goukei),abs(2*ato - goukei)))

Measured memory_bytes: 3060
def d_rgb_triplets():
    N = int(input())
    S = input()

    total = S.count('R') * S.count('G') * S.count('B')

    sub = 0
    for i in range(N):
        for j in range(i + 1, N):
            k = 2 * j - i  # j-i = k-j を満たす k
            if j < k < N and S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                sub += 1
    return total - sub

print(d_rgb_triplets())

Measured memory_bytes: 9204
// https://abc111.contest.atcoder.jp/tasks/arc103_a

#include<iostream>
#include<climits>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int ,int> ipair;
bool greaterPair(const ipair& l, const ipair& r){return l.second > r.second;}

int main(){

	
	int n;
	cin >> n;
	vector< int > v(n);

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

	vector< int > a(10e5);
	vector< int > b(10e5);
	vector<ipair> idx_a;
	vector<ipair> idx_b;
	
	for(int i = 0; i < a.size(); i++)
	{
		a[i] = 0;
		b[i] = 0;
	}
	
	for(int i = 0; i < n; i++)
	{
		if(i%2 == 0){
			a[v[i]] ++;
		}else{
			b[v[i]] ++;
		}
	}
	
	for(int i = 0; i < a.size(); i++)
	{
		idx_a.push_back(pair<int,int> (i, a[i]));
		idx_b.push_back(pair<int,int> (i, b[i]));
	}
	

	int suma=0, sumb=0;
	for(int i = 0; i < a.size(); i++)
	{
		suma += a[i];
		sumb += b[i];
	}

	partial_sort(idx_a.begin(), idx_a.begin()+2, idx_a.end(), greaterPair);
	partial_sort(idx_b.begin(), idx_b.begin()+2, idx_b.end(), greaterPair);
	
	// for(int i = 0; i < 10; i++)
	// {
	// 	cout << idx_a[i].first << "," << idx_a[i].second << endl;
	// 	cout << idx_b[i].first << "," << idx_b[i].second << endl;
	// }

	int mina = suma;
	int minb = sumb;

	if (idx_a[0].first != idx_b[0].first){
		cout << (suma-idx_a[0].second) + (sumb-idx_b[0].second) << endl;
		return 0;
	}else{
		int ans = min((suma-idx_a[0].second)+(sumb-idx_b[1].second), (suma-idx_a[1].second)+(sumb-idx_b[0].second));
		cout << ans << endl;
		return 0;
	}
	
	cout << mina + minb << endl;
	
	return 0;
}

Measured memory_bytes: 24660
"use strict";
function Main(input) {
    let lines = input.split("\n");
    let ab = [];
    for (let n = 0; n < 3; n++) {
        ab.push(lines[n].split(/\s/).map((v) => v - 0));
    }
    let cnt = [0, 0, 0, 0, 0];
    for (let n = 0; n < 3; n++) {
        cnt[ab[n][0]] += 1;
        cnt[ab[n][1]] += 1;
    }

    console.log(cnt.every(function(value) { return value != 3; }) ? "YES" : "NO");
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

#define pb push_back
#define mk make_pair
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define sf(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define pf(a) printf("%d\n",a);
#define pfl(a) printf("%lld\n",a);
#define TEST int test; cin >> test;while(test--)
#define ii pair<int,int>
#define iil pair<ll,ll>
#define loop(i,a,b) for(int i = a ; i < b ; i++)
#define INF 2147483647


int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const double pi = acos(-1.0);

map<ll,ll>mp;
void solve()
{

   ll a, b;
   cin >> a >> b;
   if(abs(a-b) >= 1)
   {
      cout << max(a,b) + max(a,b) -1 << endl;
   }
   else cout << a+b << endl;
   
   return;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //TEST
    solve();
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n,m,k;
int a[125252];
ll dp[2][125252];

int main(){
  scanf("%d%d%d",&n,&m,&k);
  REP(i,n)scanf("%d",a+i);
  int cur = 0;
  cur ^= 1;
  REP(j,k){
    // slide max
    int r=0;
    deque<int> Q;
    REP(i,n){
      while(r<=n && r<=i+m){
        while(!Q.empty() && dp[cur^1][Q.back()] <= dp[cur^1][r]) Q.pop_back();
        Q.push_back(r++);
      }
      while(Q.front() <= i)Q.pop_front();
      dp[cur][i] = (ll)(k-j)*a[i] + (Q.empty()? 0 : dp[cur^1][Q.front()]);
    }
    cur ^= 1;
  }
  ll ans = 0;
  REP(i,n)CHMAX(ans,dp[cur^1][i]);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 2304
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
const long long MOD = (ll)1e9+7;
const long long MAX = (ll)1e5+100;

class Node {
   public:
   // long vertex;
   vector<long> to;
   // vector<long> length;
   // int grp;
   ll pat[2] = {1,1};
   bool seen = false;
   bool finish = false;
   Node(){;};
};
vector<Node> vGr;

bool dfs(int vertex) {
   if (vGr[vertex].seen) return false;
   vGr[vertex].seen = true;
   vector<array<ll,2>> low;
   for (auto el : vGr[vertex].to) {
      if(!dfs(el)) continue;
      low.push_back({vGr[el].pat[0],vGr[el].pat[1]});
   }
   for (auto lowp: low) {
      vGr[vertex].pat[0] *= (lowp[0] + lowp[1]);
      vGr[vertex].pat[1] *= (lowp[0]);
      vGr[vertex].pat[0] %= MOD;
      vGr[vertex].pat[1] %= MOD;
   }
   vGr[vertex].finish = true;
   return true;
};

int main(void) {
   ll N;
   cin>>N;
   vGr.resize(N);
   rep(i,0,N-1) {
      ll x,y;
      cin>>x>>y;
      vGr[x-1].to.push_back(y-1);
      vGr[y-1].to.push_back(x-1);
   }

   dfs(0);
   // cout<<vGr[0].pat[0]<<" "<<vGr[0].pat[1]<<endl;
   cout<<(vGr[0].pat[0]+vGr[0].pat[1])%MOD<<endl;






   return 0;
}

Measured memory_bytes: 16384
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
#define REP2(i, n) for (Int i = 0, max_i = (n); i < max_i; i++)
#define REP3(i, a, b) for (Int i = (a), max_i = (b); i < max_i; i++)
#define OVERLOAD2(_1, _2, _3, name, ...) name
#define REP(...) OVERLOAD2(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
template <class T> inline bool chmax(T& a, const T& b) {
    if (a >= b) return false;
    a = b;
    return true;
}
template <class T> inline bool chmin(T& a, const T& b) {
    if (a <= b) return false;
    a = b;
    return true;
}
struct in {
    int n;
    in() {}
    in(int n_) : n(n_){};
    template <class T> operator T() {
        T ret;
        cin >> ret;
        return ret;
    }
    template <class T> operator vector<T>() {
        vector<T> ret(n);
        for (int i = 0; i < n; i++) cin >> ret[i];
        return ret;
    }
};
struct SetupIO {
    SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }
} setup_io;

#ifdef _MY_DEBUG
#include "/Users/knshnb/.competitive_local.hpp"
#else
#define dump(...)
#endif

/**
 *    author:  knshnb
 *    created: Sun Dec 22 21:00:17 JST 2019
 **/

signed main() {
    Int n = in();
    vector<Int> a = in(n);
    REP(i, n) a[i]--;
    vector<vector<Int>> b(n);
    REP(i, n) b[a[i]].push_back(i);
    Int cur = -1;
    REP(i, n) {
        auto it = upper_bound(b[i].begin(), b[i].end(), cur);
        if (it == b[i].end()) {
            cout << (i == 0 ? -1 : n - i) << endl;
            return 0;
        }
        cur = *it;
    }
    cout << 0 << endl;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;



int main(){
    ll K, A, B;
    cin>>K>>A>>B;
    if(A/K<B/K){
        cout<<"OK"<<endl;
        return 0;
    }
    if(A%K==0||B%K==0){
        cout<<"OK"<<endl;
        return 0;
    }
    cout<<"NG"<<endl;
    return 0;

}

Measured memory_bytes: 3624
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    final int MIN = -1000000;
    final int MAX = 1000000;
    Scanner sc = new Scanner(is);
    int k = Integer.parseInt(sc.next());
    int x = Integer.parseInt(sc.next());
    int left = Math.max(MIN, x - k + 1);
    int right = Math.min(MAX, x + k - 1);
    pw.println(IntStream.rangeClosed(left, right).mapToObj(String::valueOf)
      .collect(Collectors.joining(" ")));
  }
}


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

alist = input().split(" ")

aint = []

sumlist = []

for i in range(n-1):
    aint.append(int(alist[i]))

for i in range(n):
    sumlist.append(0)

for i in aint:
    sumlist[i-1] = sumlist[i-1]+1

for i in sumlist:
    print(i)

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

using namespace std;

template <typename T>
T gcd(T a, T b) {
  while (a) {
    b %= a;
    std::swap(a, b);
  }
  return b;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int res = 0;
  for (int a : A) {
    res = gcd(res, a);
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};


bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  ll x,cnt=0;
  cin >> x;
  if(x % 11 == 0){
    cout << 2*(x/11)  << endl;
  }else if(x % 11 >= 7)
    cout << 2*(x/11) + 2 << endl;
  else
    cout << 2*(x/11) + 1 << endl;
  
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
const int MOD = 1000000007;
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


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

c = [[0]*10 for i in range(10)]
for n in range(1,N+1):
    n_str = str(n)
    n_last = len(n_str)-1
    c[int(n_str[0])][int(n_str[n_last])] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += c[i][j]*c[j][i]
print(ans)

Measured memory_bytes: 3064
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input! {
        _: usize,
        a: usize,
        b: usize,
        c: usize,
        d: usize,
        s: Chars,
    }

    if !search(&s, a, c) || !search(&s, b, d) {
        println!("No");
        return;
    }

    if c > d && !tradable(&s, b, d) {
        println!("No");
        return;
    }

    println!("Yes");
}

fn search(map: &[char], start: usize, target: usize) -> bool {
    let mut count = 0;
    for i in start-1..=target {
        if i >= map.len() { break }
        if map[i] == '#' { 
            count += 1;
            if count == 2 { return false; }
        } else {
            count = 0;
        }
    }
    true
}

fn tradable(map: &[char], start: usize, target: usize) -> bool {
    for i in start..=target {
        if map[i - 2] == '.' && map[i - 1] == '.' && map[i] == '.' {
            return true;
        }
    }
    false
}


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

int main() {
    int N;
    ll x;
    cin >> N >> x;
    ll a[110];
    rep(i, N) { cin >> a[i]; }
    sort(a, a + N);
    int ans = 0;
    ll total = 0;
    rep(i, N) {
        total += a[i];
        if (total > x) break;
        ans++;
    }
    if (total < x) ans--;
    cout << ans << endl;
}

Measured memory_bytes: 3576
#include <iostream>
using namespace std;
 
int main() { 
    int n, f = 0, ans = 1;
    cin >> n;
    if(n == 1 || n == 2 || n == 4) {
        ans = 4;
    } else {
        while(f < 2) {
            if(n%2 == 0) {
                n /= 2;
            } else {
                n = 3*n + 1;
            }
            if(n == 4) f++;
            ans++;
        }
    }
    cout << ans << '\n';
}



Measured memory_bytes: 256
n, x, y = map(int,input().split())

cnt = 0

ans=[0]*n

for i in range(1,n+1):
    for j in range(i+1,n+1):
        d = min(j-i,abs(x-i)+abs(y-j)+1)
        ans[d] += 1
for i in range(1,n):
    print(ans[i])

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0) break;
    int r;
    cin >> r;
    vii user(1260 - 540 + 1, vi(n));
    int pre = 0;
    rep (i, r) {
      int t, pc, st, s;
      cin >> t >> pc >> st >> s;
      pc--;
      t -= 540;
      while (pre < t) {
        rep (j, n) {
          user[pre + 1][j] = user[pre][j];
        }
        pre++;
      }

      if (s == 1) {
        user[t][pc] = st;
      }
      else {
        user[t][pc] = 0;
      }
    }
    while (pre < 1260 - 540) {
      rep (j, n) {
        user[pre + 1][j] = user[pre][j];
      }
      pre++;
    }

    vector<set<int> > st(1260 - 540 + 1);
    rep (i, user.size()) {
      rep (j, n) st[i].insert(user[i][j]); 
    }

    int q;
    cin >> q;
    while (q--) {
      int ts, te, m;
      cin >> ts >> te >> m;
      ts -= 540; te -= 540;
      int ans = 0;
      for (int i = ts; i < te; i++) {
        if (st[i].count(m)) ans++;
      }
      cout << ans << endl;
    }
    
  }
}



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

typedef long long ll;
#define pb push_back
#define mp make_pair

void solve()
{
	ll a;
	double  b;
	cin >> a >> b;

	ll b2 , ans;
	b2 = (ll)(b * 100 + 0.5);

	ans = a * b2 / 100;
	cout << ans;
}


int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t = 1;
	// cin >> t;

	while (t--)
	{
		solve();
		cout << "\n";
	}

	return 0;
}


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

#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

void solve(std::string S) {
    int ans = 0;
    int tmp = 0;
    rep (i, S.size()) {
        if (S[i] == 'R') {
            tmp++;
        } else {
            tmp = 0;
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}

int main() {
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 3596
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

    // https://atcoder.jp/contests/abc147/submissions/8921445
    // 3
    // 1 2
    // 1 3
    // 1 4
    // のようなタイプ
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

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

fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

fn main() {
    input!(
        A : u64,
        B : u64,
    );

    let mut x = A*B;
    println!("{}",x/gcd(A,B));
}

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

int main() {
  int A, B, X;
  cin >> A >> B >> X;

  int price = 1 << 30;

  for (int a = 0; ; ++a) {
    for (int b = 0; ; ++b) {
      if (a * 1000 + b * 500 >= X) {
        price = min(price, A * a + B * b);
        break;
      }
    }
    if (a * 1000 >= X) break;
  }

  cout << price << endl;

  return 0;
}



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

int main(){

	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	auto itr = unique(a.begin(), a.end());
	for (auto i = a.begin(); i != itr; i++) cout << (i == a.begin() ? "" : " ") << (*i);
	cout << endl;
	return 0;
}


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

int main() {
    int K;
    cin >> K;
    int A, B;
    cin >> A >> B;
    string messages = "NG";
    int i = A / K;
    i = i * K;
    while(i <= B) {
        if(i < A) {
            i += K;
            continue;
        }
        messages = "OK";
        i += K;
    }
    cout << messages << endl;
}


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

int main() {
	int a, b, h;
	cin >> a >> b >> h;
	cout << (a + b) * h / 2 << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"
 
template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}
 
const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);
 
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    string s;
    cin>>s;
    if(s.back()!='s') s+='s';
    else s+="es";
    cout<<s<<endl;
}

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

int main(void){
  int n, l;
  cin >> n >> l;
  string s[n];
  for(int i = 0; i < n; i++) cin >> s[i];
  sort(s, s + n);
  for(int i = 0; i < n; i++) cout << s[i];
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    S = input_raw[0]


    for k in range(2, 4):
        for i in range(len(S) - k + 1):
            dic = {}
            for j in range(k):
                if S[i + j] not in dic:
                    dic[S[i + j]] = 1
                else:
                    dic[S[i + j]] += 1
            for j in range(k):
                if dic[S[i + j]] >= k/2 + 1:
                    print i + 1, k + i
                    return
    print -1, -1


if __name__ == '__main__':
    main()


Measured memory_bytes: 6128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>


int main(int argv,char *argc[]){	
	int i,j;
	int h[10];
	int min,tmp;

	for(i=0;i<10;i++){
		scanf("%d",&h[i]);
	}

	for(i=0;i<10;i++){
		min = i;
		for(j=i;j<10;j++){
			if(h[min] < h[j]){
				min = j;
			}
		}
		tmp = h[i];
		h[i] = h[min];
		h[min] = tmp;
	}

	for(i=0;i<3;i++){
		printf("%d\n",h[i]);
	}

	return 0;
}

Measured memory_bytes: 600
import math

q = int(input())
a = []
b = []
for i in range(q):
  c = [int(i) for i in input().split()]
  a += [c[0]]
  b += [c[1]]

for i in range(q):
  prod = a[i] * b[i]
  sqrt = int(math.sqrt(prod))
  cnt = 2 * sqrt

  if a[i] == b[i]:
    cnt -= 2
  else:
    if sqrt * sqrt == prod:
      cnt -= 2
    elif prod // sqrt == sqrt:
      cnt -= 1
    elif prod // sqrt == sqrt + 1 and prod // sqrt * sqrt == prod:
      cnt -= 1
    cnt -= 1
  
  print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep2(i,x,y) for (int i = x; i < (y); ++i)
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
int INF = 100100101;

int main(){
  int n;
  cin >> n;
  if(n % 1000 == 0) cout << 0 << endl;
  else cout << 1000 - (n % 1000) << endl;
}

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

int main() {
  string s;
  cin >> s;

  int ans = 0;
  for (int i = 0; i < 4; ++i) {
    if (s[i] == '+')
      ans++;
    else
      ans--;
  }

  cout << ans << endl;
}


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

namespace ITP1_5_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var list = new List<int[]>();
            string input;
            while ((input = Console.ReadLine()) != "0 0")
                list.Add(input.Split(' ').Select(x => Convert.ToInt32(x)).ToArray());
            foreach (var l in list)
            {
                for (int height = 0; height < l[0]; height++)
                {
                    bool patis;
                    if (height % 2 == 0) patis = true;
                    else patis = false;
                    for(int width = 0; width < l[1]; width++)
                    {
                        if (patis) Console.Write("#");
                        else Console.Write(".");
                        patis = !patis;
                    }
                    Console.WriteLine();
                }                   
                Console.WriteLine();
            }
        }
    }
}

Measured memory_bytes: 9428
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int main()
{
	double c1x = 0, c1y = 0, c1r = 0, c2x = 0, c2y = 0, c2r = 0,
   		   d = 0, a = 0, b = 0, s = 0, t = 0, u = 0;
	int k = 0;
	vector<pair<double, double>> v(4);

	cin >> c1x >> c1y >> c1r >> c2x >> c2y >> c2r;

	d = sqrt(pow(c1x - c2x, 2) + pow(c1y - c2y, 2));

	if (c1y == c2y) {
		v[0].first = c1x + c1r * (c1r - c2r) / (c2x - c1x);
		v[1].first = v[0].first;
		v[0].second = c1y - sqrt(c1r * c1r - pow(v[0].first - c1x, 2));
		v[1].second = c1y + sqrt(c1r * c1r - pow(v[0].first - c1x, 2));
		v[2].first = c1x + c1r * (c1r + c2r) / (c2x - c1x);
		v[3].first = v[2].first;
		v[2].second = c1y - sqrt(c1r * c1r - pow(v[2].first - c1x, 2));
		v[3].second = c1y + sqrt(c1r * c1r - pow(v[2].first - c1x, 2));
	}
	else {
		a = -(c2x - c1x) / (c2y - c1y);
		b = (c1x * (c2x - c1x) + c1r * (c1r - c2r)) / (c2y - c1y) + c1y;

		s = 1 + a * a;
		t = c1x - a * (b - c1y);
		u = c1x * c1x + (b - c1y) * (b - c1y) - c1r * c1r;

		v[0].first = (t - sqrt(t * t - s * u)) / s;
		v[1].first = (t + sqrt(t * t - s * u)) / s;
		v[0].second = a * v[0].first + b;
		v[1].second = a * v[1].first + b;

		b = (c1x * (c2x - c1x) + c1r * (c1r + c2r)) / (c2y - c1y) + c1y;

		s = 1 + a * a;
		t = c1x - a * (b - c1y);
		u = c1x * c1x + (b - c1y) * (b - c1y) - c1r * c1r;

		v[2].first = (t - sqrt(t * t - s * u)) / s;
		v[3].first = (t + sqrt(t * t - s * u)) / s;
		v[2].second = a * v[2].first + b;
		v[3].second = a * v[3].first + b;
	}

	if (d == abs(c1r - c2r))
		k = 1;
	else if (d > abs(c1r - c2r) && d < c1r + c2r)
		k = 2;
	else if (d == c1r + c2r)
		k = 3;
	else if (d > c1r + c2r)
		k = 4;

	sort(v.begin(), v.begin() + k);

	for (int i = 0; i < k; i++) {
		cout << setiosflags(ios::showpoint | ios::fixed) << setprecision(10)
			<< v[i].first << " " << v[i].second << endl;
	}

	return 0;
}


Measured memory_bytes: 3348
import java.util.*;

class Main{

    int need;
    int[] coin;
    int[] m = {10,50,100,500};
    void solve(){
	Scanner sc = new Scanner(System.in);
	boolean boo = false;
	while(true){
	    need = sc.nextInt();
	    if(need==0) break;
	    if(boo) System.out.println();
	    coin = new int[4];
	    int sum = 0;
	    for(int i=0; i<4; i++){
		coin[i] = sc.nextInt();
		sum += coin[i]*m[i];
	    }

	    int oturi = sum - need;
	    for(int i=3; i>=0; i--){
		while(oturi-m[i]>=0){
		    oturi -= m[i];
		    coin[i]--;
		}
	    }

	    for(int i=0; i<4; i++){
		if(coin[i]>0){
		    System.out.println(m[i]+" "+coin[i]);
		}
	    }
	    boo = true;
	}
    }
    public static void main(String[] args){
	new Main().solve();
    }
}

Measured memory_bytes: 13000
N, K = map(int, input().split())
h = []
for i in range(N):
    h.append(int(input()))
    
h.sort()
hight = []
for i, j in enumerate(h):
    if i >= len(h) - K + 1:
        break
    hight.append(h[i + K - 1] - h[i])
hight.sort()
print(hight[0])

Measured memory_bytes: 11244
#include <bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) int((x).size())
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define endl '\n'
#define ff first
#define ss second
#define L(X) ((X)<<1)
#define R(X) (((X)<<1)|1)
#define M(X,Y) (((X)+(Y))>>1)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int MAXN = 2e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1);

template<typename T>   T add(T x, T y, T m) { return ((x % m)  + (y % m)) % m;}
template<typename T>   T mul(T x, T y, T m) { return ((x % m) * (long long)(y % m)) % m;}
template<typename T>   T sub(T x, T y, T m) { return add(x, -y + m);}
template<typename T>   T gcd(T a, T b) { return b ? gcd(b, a % b) : a;}
template<typename T>   T lcm(T a, T b) { return a / gcd(a, b) * b;}

int lg2(long long x)   {   return 64 - __builtin_clzll(x) - 1;	}
int lg2(int x)   {   return 32 - __builtin_clzll(x) - 1;	}

struct pair_hash{
	template<class T1, class T2>
	size_t operator() (const pair<T1, T2> &p) const {
		auto h1 = hash<T1>{}(p.first);
		auto h2 = hash<T2>{}(p.second);
		return h1 ^ h2;
	}
};


ll n, k, h[MAXN];

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

	cin >> n >> k;

	for(int i = 0 ; i < n ; ++i) {
		cin >> h[i];
	}
	
	sort(h, h + n);

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

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int n, a, b;

  cin >> n >> a >> b;

  cout << min(a, b) << " " << max(0, (a + b) - n) << endl;

  return 0;
}


Measured memory_bytes: 764
N = int(input())
x = []
y = []
h = []
nonzero_x = 0
nonzero_y = 0
nonzero_h = 0

for _ in range(N):
    xx, yy, hh = [int(x) for x in input().split()]
    x.append(xx)
    y.append(yy)
    h.append(hh)
    if nonzero_h == 0 and hh != 0:
        nonzero_x = xx
        nonzero_y = yy
        nonzero_h = hh


def solve():
    for cx in range(101):
        for cy in range(101):
            res = True
            calc_h = nonzero_h + abs(nonzero_x-cx) + abs(nonzero_y-cy)
            for i in range(N):
                hh = max(calc_h - abs(x[i]-cx) - abs(y[i]-cy), 0)
                if hh != h[i]:
                    res = False
                    break
            if res:
                print("{} {} {}".format(cx, cy, calc_h))
                return
    return

solve()

Measured memory_bytes: 3064
N,K=(int(i) for i in input().split())
A = list(int(i) for i in input().split())  
minNum=0
i=0
A2=[]
ans=0

while i<N:    
   
    if i==0:
        i=i+K
    else:
        i=i+K-1

    ans+=1
    
print(ans)    


Measured memory_bytes: 13880
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
//#define ll ll
signed main(){
    ll n; cin >> n;
    vector<ll>v(n);
    for(auto && itr : v){
        cin >> itr;
    }
    ll m; cin >> m;
    vector<ll>u(m);
    for(auto && itr : u){
        cin >> itr;
    }
    vector<ll>c(m);
    for(auto && itr : c){
        cin >> itr;
    }
    sort(v.begin(),v.end());
    vector<ll>sum = v;
    for(ll i = 1;  i < n;i++){
        sum[i]+=sum[i-1];
    }
    for(ll i = 0;  i < u.size(); i++){
        ll idx = (ll)(lower_bound(v.begin(), v.end(),u[i]+1) - v.begin());
        if((sum[idx-1] >= c[i] and idx )or c[i] == 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}



Measured memory_bytes: 12128
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    Int n, d;
    cin >> n >> d;

    bool ans = false;
    Int X = 10000, Y = 5000, Z = 1000;
    for (Int x = 0; x <= n; x++) {
        for (Int y = 0; y <= n; y++) {
            if (n < x + y) {
                break;
            }
            if (d < X * x + Y * y) {
                break;
            }

            Int ro = n - (x + y);
            for (Int z = 0; z <= ro; z++) {
                Int oto = X * x + Y * y + Z * z;
                if (x + y + z == n && d == oto) {
                    cout << x << ' ' << y << ' ' << z << endl;
                    return 0;
                }
            }
        }
    }

    if (!ans) {
        cout << "-1 -1 -1"s << endl;
    }

    return 0;
}


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

using namespace std;

vector<int> adj[1005];
int dis[1005][1005],pa[1005][1005];
int n,m;

int get(int x)
{
	for(int i=1;i<=n;i++)
		dis[x][i]=(1<<30);
	queue<int> q;
	for(int i:adj[x])
	{
		dis[x][i]=1; pa[x][i]=x;
		q.push(i);
	}
	while(q.size())
	{
		int y=q.front(); q.pop();
		for(int i:adj[y])
		{
			if(dis[x][y]+1<dis[x][i])
			{
				dis[x][i]=dis[x][y]+1;
				pa[x][i]=y;
				q.push(i);
			}
		}
	}
	return dis[x][x];
}

int main()
{
	cin >> n >> m;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin >> x >> y;
		adj[x].push_back(y);
	}
	int ans=(1<<30),st=-1;
	for(int i=1;i<=n;i++)
	{
		int cur=get(i);
		if(cur<ans)
		{
			ans=cur;
			st=i;
		}
	}
	if(st==-1)
	{
		cout << -1 << endl;
		return 0;
	}
	get(st);
	int cur=st;
	vector<int> v;
	do{
		v.push_back(cur);
		cur=pa[st][cur];
		//cout << cur << endl;
	} while(cur != st);
	cout << v.size() << endl;
	for(int i:v)
		cout << i << endl;
}

Measured memory_bytes: 8192
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int x = sc.nextInt();
		int t = sc.nextInt();

		int time = 0;

		while (true) {
			time += t;

			n -= x;

			if (n <= 0) {
				System.out.println(time);
				return;

			}
		}

	}
}

Measured memory_bytes: 35776
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N;
  cin>>N;
  string S;
  cin>>S;

  vector<Int> used(1000);
  Int num[10][10] = {};
  Int ans[10][10][10] = {};
  for(Int i=0;i<N;i++){

    for(Int j=0;j<10;j++)
      for(Int k=0;k<10;k++){
        if(num[j][k] == 0) continue;
        ans[j][k][S[i] - '0'] = 1;
    }
    for(Int j=i-1;j>=0;j--){
      num[ S[j] - '0' ][ S[i] - '0' ] =  1;
    }
  }

  Int sum = 0;
  for(Int i=0;i<10;i++)
    for(Int j=0;j<10;j++)
      for(Int k=0;k<10;k++) sum += ans[i][j][k];

  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define ll long long
#define INF 10000000
#define int long long
using namespace std;
signed main(){
  string s;
  cin >> s;
  rep(i,s.size()){
    if(s[i] == ',') s[i] = ' ';
    cout << s[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  string s; cin >> s;
  int res = 0;
  for (int i = 0; i < n; ++i) if (s[i] == '.') {
    int l = i, r = i;
    while (l - 1 >= 0 and s[l - 1] == 'W') --l;
    while (r + 1 < n and s[r + 1] == 'W') ++r;
    if ((l and s[l - 1] == 'B') and (r + 1 < n and s[r + 1] == 'B')) continue;
    int curr = 0;
    if (l == i) {
      int ll = l;
      while (ll - 1 >= 0 and s[ll - 1] == 'B') --ll;
      if (ll and s[ll - 1] == 'W') {
        curr += l - ll;
      }
    }
    if (r == i) {
      int rr = r;
      while (rr + 1 < n and s[rr + 1] == 'B') ++rr;
      if (rr + 1 < n and s[rr + 1] == 'W') {
        curr += rr - r;
      }
    }
    res = max(res, curr);
  }
  cout << res << '\n';
}


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

int main(){
  char a,b,c;
  char c2,b2,a2;
  cin >> a >> b >> c;
  cin >> c2 >> b2 >> a2;
  if (a==a2 && b==b2 && c==c2) cout << "YES" << endl;
  else cout << "NO" << endl;
  
}




Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <ctime>

using namespace std;

#define LOCAL 0
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define fore(i, a, b) for (int i = (a), _b = (b); i < (_b); ++i)
#define fort(i, a, b) for (int i = (a), _b = (b); i <= (_b); ++i)
#define ford(i, a, b) for (int i = (a), _b = (b); i >= (_b); --i)
#define bug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1& arg1){
    cerr << name << ": " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1& arg1, Args&... args){
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " /";
    __f(comma + 1, args...);
}

template <class T> bool mini(T& a, T b) { return a > b ? (a = b, 1) : 0; }
template <class T> bool maxi(T& a, T b) { return a < b ? (a = b, 1) : 0; }

typedef long long LL;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

const int INF = 1e9 + 7;
const int N = 303;

int n, m, l, q, a[N][N], b[N][N];

void input() {
    memset(a, 0x3f, sizeof a);
    memset(b, 0x3f, sizeof b);
    cin >> n >> m >> l;
    int u, v, w;
    while (m--) {
        cin >> u >> v >> w;
        a[u][v] = a[v][u] = w;
    }
}

void solve() {
    fort(k, 1, n) fort(u, 1, n) fort(v, 1, n) mini(a[u][v], a[u][k] + a[k][v]);
    fort(u, 1, n) fort(v, 1, n) if (a[u][v] <= l) b[u][v] = 1;
    fort(k, 1, n) fort(u, 1, n) fort(v, 1, n) mini(b[u][v], b[u][k] + b[k][v]);
    cin >> q;
    int s, t;
    while (q--) {
        cin >> s >> t;
        if (b[s][t] < INF) cout << b[s][t] - 1 << '\n';
        else cout << "-1\n";
    }
}

int main() {
#if LOCAL
    freopen("CP.inp", "r", stdin);
//    freopen("CP.out", "w", stdout);
#endif // LOCAL
    ios_base::sync_with_stdio(0); cin.tie(0);
    input();
    solve();
    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forin(in) for(int i=0; i<(int)in.size(); i++) cin>>in[i]
#define forout(out) for(int i=0; i<(int)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for(int i=0; i<(n); i++)

int main(){
    int n; cin>> n;
    vector<int> a(n), a2(n);
    forin(a);
    a2=a;
    sort(a2.begin(), a2.end(), greater<int>());
    rep(i, n){
        if(a[i] == a2[0]){
            cout<< a2[1] << endl;
        }else{
            cout<< a2[0] << endl;
        }
    }
}

Measured memory_bytes: 4776