akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 #define int long long

#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define endl '\n'
#define fi first
#define se second


using namespace __gnu_pbds;
using namespace std;
// const int mod=1e9+7;
 const int mod=998244353;
 // const int mod=1e9+9;
const int INF=4e18+10;
// const int INF=4e18+10;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define read(n) int n; cin>>n;
#define readv(x, n) vector<int> x(n); for(auto &i:x) cin>>i;


typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

template<typename T1,typename T2>
void set_min(T1& a, T2 b)
{
    a=min(a, (T1)b);
}


int multiply(int a, int b, int in_mod){return (a*b)%in_mod;}
int mult_identity(int a){return 1;}


auto power(auto a, int b, int in_mod)
{
    auto prod=mult_identity(a);
    auto mult=a%in_mod;
    while(b!=0)
    {
        if(b%2)
        {
            prod=multiply(prod,mult, in_mod);

        }
        mult=multiply(mult, mult,in_mod);
        b/=2;
    }
    return prod;
}
int mod_inv(int q, int in_mod)
{

    return power(q, in_mod-2,in_mod);
}


void solve()
{
    int a, b, c , d;
    cin>>a>>b>>c>>d;
    vvi dp(c+1, vi(d+1,0));
    dp[a][b] = 1;
    for(int i=a;i<=c;i++)
    {
        for(int j= b;j<=d;j++)
        {
            if(i==a && j==b)
                continue;
            dp[i][j] = dp[i-1][j]*(j-1) +dp[i][j-1] *(i-1) - dp[i-1][j-1] *(i-1)*(j-1)+ dp[i-1][j] + dp[i][j-1]; 
            dp[i][j]%=mod;
            dp[i][j]+=mod;
            dp[i][j]%=mod;
        }
    }
    cout<<dp[c][d]<<endl;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen("INPUT.txt", "r", stdin);
        freopen("OUTPUT.txt", "w", stdout);
    }
#endif
    auto clk = clock();
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    // -------------------------------------Code starts here---------------------------------------------------------------------

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

    for (int test = 1; test <= t; test++)
    {
        // cout<<"Case #"<<test<<": ";
        // cout<<endl;
        solve();
        // cout<<endl;
    }

    // -------------------------------------Code ends here------------------------------------------------------------------

    clk = clock() - clk;
    // cerr << fixed << setprecision(6) << "Time: " << ((long double)clk) / CLOCKS_PER_SEC << "\n";
    return 0;
}


Measured memory_bytes: 73720
import java.util.Scanner;
public class Main{
 public static void main(String args[]){
  boolean flag=false;
  Scanner scan=new Scanner(System.in);
  String s;

  s=scan.next();
  int n=Integer.parseInt(s);

  int d[]=new int[n+10];
  int mx=0,a; 
  long ans=1;
  for(int i=0;i<n;i++)d[i]=0;

  for(int i=0;i<n;i++){
   s=scan.next();
   a=Integer.parseInt(s);
   if((i==0&&a!=0)||(i!=0&&a==0))ans=0;
   d[a]++;
   if(mx<a)mx=a;
  }
  for(int i=1;i<=mx;i++){
   for(int j=0;j<d[i];j++){
    ans*=d[i-1];
    ans%=998244353;
   }
  if(d[i-1]==0)ans=0;
  } 
  System.out.println(ans);
 }

 ///////////////////////////////////////////////
 public static boolean prime(long a){
  if(a<=1)return false;
  for(int i=2;i*i<=a;i++){
   if(a%i==0)return false;
  }
  return true;
 }
 public static long llpow(long x,long n){
  long ans=1;
  for(int i=0;i<n;i++)ans*=x;
  return ans;
 }
 public static long max(long a,long b){
  if(a<b)return b;
  else return a;
 }
 public static long min(long a,long b){
  if(a>b)return b;
  else return a;
 }
}



Measured memory_bytes: 59792
/*
Author: CNYALI_LK
LANG: C++
PROG: d.cpp
Mail: cnyalilk@vip.qq.com
*/
#include<bits/stdc++.h>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define DEBUG printf("Passing [%s] in LINE %lld\n",__FUNCTION__,__LINE__)
#define Debug debug("Passing [%s] in LINE %lld\n",__FUNCTION__,__LINE__)
#define all(x) x.begin(),x.end()
#define x first
#define y second
using namespace std;
const double eps=1e-8;
const double pi=acos(-1.0);
typedef long long ll;
typedef pair<ll,ll> pii;
template<class T>ll chkmin(T &a,T b){return a>b?a=b,1:0;}
template<class T>ll chkmax(T &a,T b){return a<b?a=b,1:0;}
template<class T>T sqr(T a){return a*a;}
template<class T>T mmin(T a,T b){return a<b?a:b;}
template<class T>T mmax(T a,T b){return a>b?a:b;}
template<class T>T aabs(T a){return a<0?-a:a;}
#define min mmin
#define max mmax
#define abs aabs
ll read(){
	ll s=0,base=1;
	char c;
	while(!isdigit(c=getchar()))if(c=='-')base=-base;
	while(isdigit(c)){s=s*10+(c^48);c=getchar();}
	return s*base;
}
ll A[204848],sf[204848],st[204848];
void calc(ll l,ll r,ll &aw,ll &bw){
	ll al=l,ar=r-1,mid;
	while(al<=ar){
		mid=(al+ar)>>1;
		if((sf[mid]-sf[l-1])<(st[mid+1]-st[r+1]))al=mid+1;
		else ar=mid-1;
	}
	mid=al;
	if(abs((sf[mid]-sf[l-1])-(st[mid+1]-st[r+1]))>abs((sf[mid-1]-sf[l-1])-(st[mid]-st[r+1]))){aw=(sf[mid-1]-sf[l-1]);bw=(st[mid]-st[r+1]);}
	else {aw=(sf[mid]-sf[l-1]);bw=(st[mid+1]-st[r+1]);}
}

int main(){
#ifdef cnyali_lk
	freopen("d.in","r",stdin);
	freopen("d.out","w",stdout);
#endif
	ll n,a,b,c,d,ans=0x3f3f3f3f;
	n=read();
	for(ll i=1;i<=n;++i){A[i]=read();sf[i]=sf[i-1]+A[i];}
	for(ll i=n;i;--i)st[i]=st[i+1]+A[i];
	for(ll i=1;i<n;++i){
		calc(1,i,a,b);
		calc(i+1,n,c,d);
		chkmin(ans,max(max(a,b),max(c,d))-min(min(a,b),min(c,d)));
	}
	printf("%lld\n",ans);
	return 0;
}



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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;


int main(){
	ios_base::sync_with_stdio(false);
	ll N, P, ans=0;
	string S;

	cin >> N >> P;
	cin >> S;

	if(10 % P == 0){
		ll count = 0;
		rrep(i,N){
			if((S[i] - '0') % P == 0){
				count += 1;
			}
			ans += count;
		}
		cout << ans << endl;
		return 0;
	}

	ll memo[10005] = {};
	ll cur = 0, k = 1;
	memo[cur] = 1;
	rrep(i,N){
		k = (k * 10) % P;
		cur = (cur + (S[i] - '0') * k) % P;
		ans += memo[cur];
		memo[cur] += 1;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 720
import sys
from bisect import bisect_left as bisect
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


def inpl():
    return list(map(int, input().split()))


class solve:
    def __init__(self, N):
        self.ans = [0] * N
        self.DP = []

    def recur(self, i, pi=-1):
        # DPテーブルを更新し、答えを求める。
        # また、巻き戻す値を覚える。
        rev_i = bisect(self.DP, self.A[i])
        if rev_i == len(self.DP):
            self.DP.append(self.A[i])
            rev_v = None
        else:
            rev_v = self.DP[rev_i]
            self.DP[rev_i] = self.A[i]

        self.ans[i] = len(self.DP)

        for nv in self.edges[i]:
            if nv != pi:
                self.recur(nv, i)

        # 巻き戻す。.
        if rev_v is None:
            self.DP.pop()
        else:
            self.DP[rev_i] = rev_v

        return


def main():
    N = int(input())
    S = solve(N)
    S.A = inpl()
    S.edges = [[] for _ in range(N)]
    for _ in range(N - 1):
        u, v = inpl()
        S.edges[u - 1].append(v - 1)
        S.edges[v - 1].append(u - 1)

    S.recur(0)

    print(*S.ans, sep='\n')
    # print(edges)
    # print(parent)
    # print(DPs)


if __name__ == '__main__':
    main()


Measured memory_bytes: 269164
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))


int main(int argc, char const *argv[])
{
	cin.tie(0);
	ios::sync_with_stdio(false);

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

    int count = 0;
    for (size_t i = 1; i < N-1; i++)
    {
        if ((p[i] > p[i-1] && p[i+1] > p[i]) || (p[i] > p[i+1] && p[i-1] > p[i])
        || (p[i+1] > p[i] && p[i] == p[i-1]) || (p[i-1] > p[i] && p[i+1] == p[i]))
        {
            count++;
        }

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


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(
			String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList d = new ArrayList();
		for (int i = 0; i < n; i++) {
			int dx = sc.nextInt();
			if (!d.contains(dx)) {
				d.add(dx);
			}
		}
		
		System.out.println(d.size());
	}
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const signed INF_=1001001001; const ll INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
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;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

int N,A,B;
signed main() {
    cin>>N>>A>>B;
    A--,B--;
    if((B-A+1)%2) {
        cout<<"Alice"<<endl;
    } else {
        cout<<"Borys"<<endl;
    }
    return 0;
}


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

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

  long long n, ans=0;
  string s;
  cin >> n >> s;
  s+='.';
  for(int i=0;i<n;i++){
    if(s[i+1] != s[i]){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

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

  for (ll i = n; i <= 999; ++i) {
    ll x100 = i / 100;
    ll x10 = (i - x100*100) / 10;
    ll x1 = (i - x100*100 - x10*10);
    if (x100 == x10 && x10 == x1) {
      cout << i << endl;
      break;
    }
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <random>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define pi 3.141592653589793
#define prique priority_queue
constexpr auto mod=1000000007;
using namespace std;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
bool prime(int n){
    int cnt=0;
    for(int i=1;i<=sqrt(n);i++){
        if(n%1==0)cnt++;
    }
    if(cnt!=1) return false;
    else return n!=1;
}
struct UnionFind{
    vector<int> r;
    UnionFind(int N){
        r=vector<int>(N,-1);
    }
    int root(int x){
        if(r[x]<0) return x;
        return r[x]=root(r[x]);
    }
    bool unite(int x,int y){
        x=root(x);
        y=root(y);
        if(x==y) return false;
        if(r[x]>r[y]) swap(x,y);
        r[x]+=r[y];
        r[y]=x;
        return true;
    }
    int size(int x){
        return -r[root(x)];
    }
};
vector<int> v;
int n,m,cnt=-mod,ans=mod,a=-mod,b=mod,aa[220000];
pair<int,int> pp[220000];
string s,ss[220000];
queue<int> que;
signed main(){
    cin>>n;
    rep(i,n){
        cin>>pp[i].first>>pp[i].second;
        cnt=max(cnt,pp[i].first-pp[i].second);
        ans=min(ans,pp[i].first-pp[i].second);
        a=max(a,pp[i].first+pp[i].second);
        b=min(b,pp[i].first+pp[i].second);
    }
    cout<<max(cnt-ans,a-b);
}

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

int main(){
	int n;
	cin >> n;
	int ans = 0;
	int tmp = 0;
	int nw= 0;
	for(int i = 0; i < n; i++){
		int t;
		cin >> t;
		if(t == 1){
			if(nw == 0){
				nw = 1;
				tmp = 1;
			}else {
				tmp ++;
			}
		}else {
			nw = 0;
		}ans = max(ans, tmp);
	}
	cout << ans+1<<endl;
	return 0;
}


Measured memory_bytes: 3080
package main

import (
	"fmt"
	"log"
)

func main() {
	var K int
	var X int
	fmt.Scanf("%d %d", &K, &X)

	log.Printf("K: %d", K)
	log.Printf("X: %d", X)

	log.Printf("%d", X - (K- 1) )
	log.Printf("%d", X + (K- 1) )
	for i := X - (K- 1); i <= X +(K-1); i++ {
		fmt.Printf("%d", i)
		if (i != X+(K-1)) {
			fmt.Printf(" ")
		}
	}
}


Measured memory_bytes: 512
main :: IO ()
main = do
  [m1, d1] <- map read . words <$> getLine
  [m2, d2] <- map read . words <$> getLine
  print $ if solve m1 d1 m2 d2 then 1 else 0

solve :: Int -> Int -> Int -> Int -> Bool
solve _ d1 _ d2 = d1 > d2

Measured memory_bytes: 508
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
#include <float.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef unsigned long long ll;
// 最大公約数求める関数
int my_gcd(int n , int m){
  if(n < m){
    int tmp = n;
    n = m;
    m = tmp;
  }
  int l  = n % m;
  while(l != 0){
    n = m;
    m = l;
    l = n % m;
}
return m;
}

//char⇒int関数
 int ctoi(char c) {
 	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}



int main(){
	int A,B,K; cin >> A >> B >> K;
	set<int> s;
	int a,b; a = A; b = B;
	rep(i,K){
		if(A > B) break;
		s.insert(A);
		A++;
		s.insert(B);
		B--;
		
	}

	for(int i = a; i <= a + K; i++){
		if(s.count(i)){
			cout << i << endl;
			s.erase(i);
		}
	}
	for(int i = b-K; i <= b ; i++){
		if(s.count(i)){
			cout << i << endl;}
	}
}

Measured memory_bytes: 256
#include<stdio.h>

int meter(int a, int b);

int main(void){
    int heightA, heightB, ans;
    scanf("%d %d", &heightA, &heightB);
    ans = meter(heightA, heightB);
    printf("%d", ans);
}

int meter(int heightA, int heightB){
    int diff = heightB - heightA,
        real_heightB;
    for(int i = 0 ; i < diff; i++){
        real_heightB += i + 1;
    }
    return real_heightB-heightB;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    String w = s.nextLine();
    boolean ans = solve(w);
    if(ans)
      System.out.println("Yes");
    else
      System.out.println("No");
  }

  public static boolean solve(String w){
    boolean ans = true;
    int even = 0;
    for(int i = 0; i < w.length() ; i++){
      for(int j = 0; j < w.length() ; j++){
        if(w.charAt(i) == w.charAt(j))
          even += 1;
      }
      if(even % 2 != 0 ){
        ans = false;
        break;
      }
    }
    return ans;
  }
}


Measured memory_bytes: 21332
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)

#define DEBUG

#ifdef DEBUG
#define var_dump(...) fprintf(stdout, __VA_ARGS__)
#define dump(a) cout << a << "\n";
#else
#define var_dump(...) 42
#define dump(a) 42
#endif

// https://beta.atcoder.jp/contests/abc047/tasks/abc047_b

int main() {
    int W, H, N;
    cin >> W >> H >> N;

    int xl = 0;
    int xh = W;
    int yl = 0;
    int yh = H;

    int x, y, a;
    REP(i, N) {
        cin >> x >> y >> a;

        if (a == 1) {
            xl = max(xl, x);
        }
        if (a == 2) {
            xh = min(xh, x);
        }
        if (a == 3) {
            yl = max(yl, y);
        }
        if (a == 4) {
            yh = min(yh, y);
        }
    }

    cout << max(0, (xh - xl)) * max(0, yh - yl) << "\n";

    return 0;
}


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

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

  int w, h, x, y; cin >> w >> h >> x >> y;
  int ans = 0;
  if(w==2*x && h==2*y) ans = 1;
  cout << (double)h*w/2 << " " << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define eps 1e-9
using namespace std;

int main()
{
    ll t,n,mi,mx,f,c,a,b,x,y,q,k;


    cin>>t;
    double answer;

    answer = 2.0 * acos(-1) * (double)t;
    cout<<answer<<endl;
}


Measured memory_bytes: 3788
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)
#define F first
#define S second

using namespace std;

int M,T,P,R,m,t,p,j;
int pen[55][15];

int main() {
  while(1){
      cin>>M>>T>>P>>R;
      if(M==0) break;
      REP(i,0,T)REP(k,0,P) pen[i][k]=0;
      vector< pair<pair<int,int>,int> > v(T); //<solv, pen>, id
      REP(i,0,T) v[i].F.F = v[i].F.S = 0, v[i].S = (-1)*i;
      REP(i,0,R){
        cin>>m>>t>>p>>j;
        if(j==0){
            v[t-1].F.F++;
            v[t-1].F.S += m + pen[t-1][p-1]*20;
        }
        else pen[t-1][p-1]++;
      }
      sort(v.begin(),v.end());

      bool flag = true;
      for(int sol=P; 0<=sol; sol--){
        REP(i,0,v.size()){
          if(v[i].F.F==sol){
            if(flag){
              cout<<(-1)*v[i].S+1;
              flag = false;
            }else{
              if(i>0){
                if(v[i].F.S==v[i-1].F.S && v[i].F.F==v[i-1].F.F) cout<<"="<<(-1)*v[i].S+1;
                else cout<<","<<(-1)*v[i].S+1;
              }else{
                cout<<","<<(-1)*v[i].S+1;
              }
            }
          }
        }
      }
      cout<<endl;
  }


  return 0;
}

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

int main(){
	int N;
  	cin >> N;
  	int a;
  	long long Amax =  1;
  	for(int i = 0; i < N; i++){
      	cin >> a;
		Amax += a;
      
    }
  	

	cout << Amax-N-1 << endl;

}

Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#define rep(i, n) for(Int (i) = 0; (i) < (n); (i)++)
#define debug(var) cout << #var << ": " << var << endl
using namespace std;
using Int = int64_t;
using Uint = uint64_t;
constexpr Uint mod = 1e9 + 7;
constexpr Int Int_max = LLONG_MAX;
constexpr Int Int_min = LLONG_MIN;
using Container = vector<Int>;
using Grid = vector<vector<char>>; // [y][x]
template<typename T, typename U>
using Umap = unordered_map<T, U>;
template<typename T>
using Uset = unordered_set<T>;
template<typename T>
using P = pair<T, T>;


int main() {

	Int N; cin >> N;
	Container h(N + 2);
	rep(i, N)cin >> h[i];

	Container dp(N, Int_max);
	dp[0] = 0;
	
	rep(i, N) {
		if (i + 1 < N)dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
		if (i + 2 < N)dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
	}

	cout << dp[N - 1];

}

Measured memory_bytes: 1792
/*
 Abu Jafor Mohammad Saleh
 ios_base :: sync_with_stdio(false);
 cin.tie(NULL);
 
 */

#include<cstdio>
#include<iomanip>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<limits>
#include <algorithm>
#include <unordered_map>
#include<fstream>
#define f first
#define s second
#define MOD 1000003

#define INF (int)1e9
#define PI 3.1415926535897932384626433832795
#define BOUNDARY(i, j) ((i >= 0 && i < rows) && (j >= 0 && j < coloums))

//#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
const int maxn = 100001;
using namespace std;
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
int rows,coloums;
long long  gcd(long long  a, long long b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

bool check1(string s,int p)
{
    p = p-1;
    int j=p;
    for(int i=0;i<=j;i++,j--)
    {
        if(s[i] != s[j])
            return false;
    }
    return true;
}

bool check2(string s,int p,int n)
{

    int j=n-1;
    for(int i=p-1;i<=j;i++,j--)
    {
        if(s[i] != s[j])
            return false;
    }
    return true;
}

int main()
{
    fast;
    
    double l;
    
    cin>>l;
   
   
        double x = double(l/3.0);
    printf("%.10lf\n",x*x*x);
    
   
    
}


Measured memory_bytes: 256
import  java.util.*;
class Main{
    int s;
    int i;
    int a=0;
    Main(){
	Scanner sc=new Scanner(System.in);
	for(i=1; i<11; i++){
	   s=sc.nextInt();
	   a=a+s;
	}
	System.out.println(a);	    
	  
	

    }

    public static void main(String[] args){
	new Main();
    }
}

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

// Loops
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)

#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(xi, x) for (auto &&xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)

// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi = vec<ll>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<ll, ll>;

// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define mp make_pair

// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase(unique(all(v)), v.end())
#define perm(c)                                                                \
  sort(all(c));                                                                \
  for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))

template <class T> pair<T, size_t> max(vector<T> &x) {
  auto it = max_element(all(x));
  return mp(*it, it - x.begin());
}
template <class T> pair<T, size_t> min(vector<T> &x) {
  auto it = min_element(all(x));
  return mp(*it, it - x.begin());
}

template <class T> inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}

// Utilities
// Grid world utilities
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
#define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H)

// Debug
#ifdef LOCAL
#include "dump.hpp"
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define dump(...)
#define debug(x)
#endif

// Paste snippets here!!

//


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); // Magic for faster cin
  string s, t;
  int n;
  cin >> n >> s >> t;
  string ret = "";
  rep(i,n){
    ret += s[i]; ret += t[i];
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 3604
"use strict";
function Main(input) {
    let cin = new Inputer(input);
    let N = cin.getInt(), A = cin.getIntArray(N);
    let B = new Array(N);
    let fu = 0, min = 1e10;
    for (let n = 0; n < N; n++) { 
        if (A[n] < 0) B[n] = -A[n], fu++;
        else B[n] = A[n];
        if (min > B[n]) min = B[n];
    }
    let ans = B.reduce((ac, v) => ac + v, 0);
    if (fu % 2 != 0) ans -= min * 2;
    console.log(ans);
}
class Inputer{constructor(t){if(typeof t=='undefined')throw new Error('引数（stdin）を省略できません！');this.cnt=0,this.items=t.split(/\n|\s/)}getInt(){return this.items[this.cnt++]-0}getIntArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getInt();return r}getStr(){return this.items[this.cnt++]}getStrArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getStr();return r}}
if (typeof window == "undefined") Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 27212
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

signed main(){
	string s, t;
	cin >> s >> t;
	int n = s.size();
	rep(i,n){
		if(s == t){printf("Yes\n");return 0;}
		s = s[n-1]+s;s.pop_back();
	}
	printf("No\n");
	return 0;
}






Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

int main(){

    ll H, A;
    cin >> H >> A;
    ll ans = H / A;
    if(H % A)ans++;
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
n,m,x=map(int,input().split())
a=[[] for ii in range(n)]
for ii in range(n):
  a[ii]=list(map(int,input().split()))

r=[0]*(m+1)
for jj in range(m+1):
  r[jj]+=sum([a[ii][jj] for ii in range(n)])

import numpy as np
def lambda_d(ii,r,km):
  if max(km[1:m+1])<=0:
    return 0,True

  rx=[r[jj]-a[ii][jj] for jj in range(m+1)]
  kx=[km[jj]-a[ii][jj] for jj in range(m+1)]
  if ii==n-1:
    #print(kx[1:m+1])
    if max(kx[1:m+1])>0:
      return 0,False
    else:
      return a[ii][0],True
    
  lt,tft=lambda_d(ii+1,rx,kx)
  lf,tff=lambda_d(ii+1,r,km)
  if tft or tff:
    #print(ii,tff,tft,lf,lt+a[ii][0])
    if not tft:
      return lf,tff
    elif not tff:
      return lt+a[ii][0],tft
    else:
      return min(lt+a[ii][0],lf),True
  else:
    return 0,False

km=[x]*(m+1)
l0,tf=lambda_d(0,r,km)
if not tf:
  print(-1)
else:
  print(l0)

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	int h,w,k;
	cin>>h>>w>>k;
	vector<vector<int>> grid(h,vector<int>(w,0));
	rep(i,h){
		string s;
		cin>>s;
		rep(j,s.size())if(s[j]=='1')grid[i][j]=1;
	}

	int ans = 1e9;
	rep(bit,(1<<h)){
		map<int, int> mp;
		int tmp=0;
		int prev = bit&1;
		// cout<<"----------"<<endl;
		// cout<<"prev = "<<prev<<endl;
		// cout<<bit<<endl;
		rep(i,h){
			// cout<<(bit>>i)<<" "<<(1&(bit>>i))<<endl;
			if((1&(bit>>i))==prev) mp[i]=tmp;
			else{
				tmp++;
				prev = 1&(bit>>i);
				mp[i] = tmp;
			}
		}
		// cout<<"tmp = "<<tmp<<endl;
		vector<int> cnt1(tmp+1,0);
		
		int res = tmp;
		rep(i,w){
			bool flg=false;
			vector<int> cnt2(tmp+1,0);
			rep(j,h){
				cnt1[mp[j]] += grid[j][i];
				cnt2[mp[j]] += grid[j][i];
			}

			rep(j,h){
				if(cnt1[mp[j]]>k) flg = true;
				if(cnt2[mp[j]]>k) res = 1e8;
			}

			if(flg){
				res += 1;
				rep(j,h)cnt1[mp[j]]=cnt2[mp[j]];
			}
		}

		ans = min(ans,res);
		// cout<<tmp<<" "<<res<<endl;
	}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

ll n, ans = 0;

bool check(ll n) {
    string t = to_string(n);
    bool f1 = 0, f2 = 0, f3 = 0;
    for(const char &c : t) {
        if(c == '3') {
            f1 = 1;
        }
        if(c == '5') {
            f2 = 1;
        }
        if(c == '7') {
            f3 = 1;
        }
    }
    return (f1 && f2 && f3);
}

void dfs(ll now) {
    if(now > n) {
        return;
    }
    if(check(now)) {
        ans++;
    }
    dfs(10 * now + 3);
    dfs(10 * now + 5);
    dfs(10 * now + 7);
    return;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    dfs(0);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <cstdio>
using namespace std;
#define ll  long long
#define PB push_back
#define ld long double
#define ff first
#define ss second
# define st(v) (v).begin(),(v).end()
#define   pr pair<int,int>
const int N = 1e5+4 , M=N,inf=(int)1e9;
const ll mod=1e9+7;
int fastAbs(int n) { return (n ^ (n >> 31)) - (n >> 31); }
ll multiply(ll a, ll b){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
int ans = INT_MAX;
map< pair<int,int> , int > mp;
const int dx[4] = {1,0,0,-1};
const int dy[4] = {0,-1,1,0};
ll dp[N][2];
int n ;
vector < int > tree[N];
void dfs( int x , int p ){
	if(tree[x].size()==1 && p !=-1){
		dp[x][0]=1;
		dp[x][1]=1;
		return ;
	}
	dp[x][0] = 1 ;
	dp[x][1] = 1 ;
	for( int i = 0 ; i < tree[x].size() ; i++ ){
		if(tree[x][i]!=p){
			dfs(tree[x][i],x);
			dp[x][0] =multiply(dp[x][0],add(dp[tree[x][i]][0],dp[tree[x][i]][1]));
			dp[x][1] = multiply(dp[x][1],dp[tree[x][i]][0]);
		}
	}
	
}
void solve(){
		cin >> n ;
		for( int i = 0 ; i  < n-1 ; i++){
			int x , y ; 
			cin >> x >> y ;
			tree[x].PB(y);
			tree[y].PB(x);
		}
		dfs(1,-1);
		cout << add(dp[1][0],dp[1][1]);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int q=1;
    //cin >> q;
    while(q--)
        solve();
}


Measured memory_bytes: 14208
n = int(input())
t, a = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

mini = 10000
for i, hi in enumerate(h):
    temp = t - hi * 0.006
    if abs(temp - a) < mini:
        mini = abs(temp - a)
        result = i+1

print(result)

Measured memory_bytes: 3060
while True:
    x=int(input())
    if x==0:
        break
    else:
        y=1000-x
        y1=y//500
        y2=(y-500*y1)//100
        y3=(y-500*y1-100*y2)//50
        y4=(y-500*y1-100*y2-50*y3)//10
        y5=(y-500*y1-100*y2-50*y3-10*y4)//5
        y6=(y-500*y1-100*y2-50*y3-10*y4-5*y5)//1
        z=y1+y2+y3+y4+y5+y6
        print(z)


Measured memory_bytes: 5584
a=int(input())
lis=[]
anlis=[]
for j in range(a):
  lis+=[int(input())]
lis.sort()
i=0
while i<len(lis):
  if i==len(lis)-1:
    anlis+=[lis[i]]
  elif lis[i]!=lis[i+1]:
    anlis+=[lis[i]]
  else:
    i+=1
  i+=1
print(len(anlis))

Measured memory_bytes: 8012
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}

signed main() {
    long long a, b, ans = 0;
    cin >> a >> b;
    if (a % 2 == 1) {
        ans += a;
        a += 1;
    }
    if ((((b - a) + 1) / 2) % 2 == 1) {
        ans = ans ^ 1;
    }
    if ((b - a) % 2 == 0) {
        ans ^= b;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

const int N_MAX = 8010;

int main(void){
  SPEEDUP
  cout << setprecision(15);
  string s;cin >> s;
  s.push_back('T');
  int x,y;cin >> x >> y;
  int v[2][N_MAX];
  int count = 0;
  int index = 0;
  int size = 0;
  while(s[index++] == 'F')--x;

  repp(i,index,s.length()){
    if(s[i] == 'F')++count;
    else{
      v[size&1][size/2] = count;
      count = 0;
      ++size;
    }
  }

  bool x_can = false, y_can = false;
  int y_size = size/2+(size&1);
  int x_size = size/2;
  set<int> prev;
  set<int> next;
  prev.insert(0);

  rep(i,y_size){
    for(auto itr = prev.begin(),end = prev.end(); itr != end; ++itr){
      next.insert(*itr + v[0][i]);
      next.insert(*itr - v[0][i]);
    }
    swap(prev,next);
    next.clear();
  }
  for(auto itr = prev.begin(), end = prev.end();itr != end; ++itr) if(*itr == y) y_can = true;


  prev.clear();
  prev.insert(0);

  rep(i,x_size){
    for(auto itr = prev.begin(),end = prev.end(); itr != end; ++itr){
      next.insert(*itr + v[1][i]);
      next.insert(*itr - v[1][i]);
    }
    swap(prev,next);
    next.clear();
  }
  for(auto itr = prev.begin(), end = prev.end();itr != end; ++itr) if(*itr == x) x_can = true;

  YesNo(x_can&&y_can);
  return 0;
}


Measured memory_bytes: 768
def main():

    rooms = [[0 for i in range(10)] for j in range(12)]
    x = int(input())
    for _ in range(x):
        b, f, r, v = tuple(map(int, input().split()))
        rooms[(b-1)*3+(f-1)][r-1] += v

    for i in range(4):
        for j in range(3):
            for k in range(10):
                print(" "+str(rooms[i*3+j][k]), end="")
            print()
        if i != 3:
            print("#"*20)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5624
N, M = map(int,input().split())
S = [False for _ in range(N)]
G = [False for _ in range(N)]
for _ in range(M):
    a, b = map(int,input().split())
    a -= 1
    b -= 1
    if a == 0 and b == N - 1:
        print("POSSIBLE")
        exit()
    if a == 0:
        if G[b]:
            print("POSSIBLE")
            exit()
        S[b] = True
    if b == N - 1:
        if S[a]:
            print("POSSIBLE")
            exit()
        G[a] = True

print("IMPOSSIBLE")

Measured memory_bytes: 6320
import sys
input = sys.stdin.readline
from collections import deque

def main():
    H,W = map(int,input().split())
    s = [input() for _ in range(H)]
    isVisited = [[0]*W for _ in range(H)]
    queue = deque([(0,0,1)])

    while queue:
        i,j,count = queue.popleft()

        if 0<= i < H and 0<= j < W and isVisited[i][j] == 0 and s[i][j] == ".":
            isVisited[i][j] = count
            for dy,dx in [(0,1),(1,0),(-1,0),(0,-1)]:
                queue.append((i+dy,j+dx,count+1))
    
    wall_count = 0
    for i in range(H):
        wall_count += s[i].count("#")
    
    if isVisited[-1][-1]:
        print(H*W-wall_count-isVisited[-1][-1])
    else:
        print(-1)
    return


if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NM = Sarray();
            var N = NM[0];
            var M = NM[1];
            var kouho = divisors(M);
            var tui = kouho.OrderBy(k => k).First(k => k >= N);
            WriteLine(M / tui);
            //Out.Flush();
        }

        static HashSet<long> divisors(long n)
        {
            var div = new HashSet<long>();
            for (long i = 1; i * i <= n; ++i)
            {
                if (n % i == 0)
                {
                    div.Add(i);
                    if (i != n / i)
                        div.Add(n / i);
                }
            }
            return div;
        }
    }
}

Measured memory_bytes: 13536
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N,K = I()
L = [l() for _ in range(N)]
L.sort()
for i in range(N):
    K -= L[i][1]
    if K <= 0:
        print(L[i][0])
        exit()

Measured memory_bytes: 90104
#include <stdio.h>
#include <iostream>
using namespace std;
void CHECK_NUM();
void INCLUDE3();
void END_CHECK_NUM();
int n, i = 1, x;
bool flag = true;
int main()
{
	cin >> n;
	CHECK_NUM();
	cout << endl;
}
void CHECK_NUM(){
	x = i;
	if (x % 3 == 0){
		cout << " " << i;
		END_CHECK_NUM();
	}
	if (flag ==true) INCLUDE3();
}
void INCLUDE3(){
	if (x % 10 == 3){
		cout << " " << i;
		END_CHECK_NUM();
	}
	if (flag == true){
		x /= 10;
		if (x) INCLUDE3();
		END_CHECK_NUM();
	}
}
void END_CHECK_NUM(){
	if (++i <= n) CHECK_NUM();
	else flag = false;
}

Measured memory_bytes: 1492
//Joy Shree Kriskna
    #include<bits/stdc++.h>
    #define fast  ios_base::sync_with_stdio(false);cin.tie(NULL)
    #define rep(i,n) for(i=0;i<n;i++)
    #define rep1(i,n) for(i=n-1;i>=0;i--)
    #define rep2(j,t) for(j=1;j<=t;j++)
    #define rep3(i,a,b) for(i=a;i<=b;i++)
    #define PI acos(-1)
    #define remove(s) s.erase(unique(s.begin(),s.end()),s.end());
    #define e return 0
    //#define lcm(a,b) ((a*b)/__gcd(a,b))
    #define endl "\n"
    #define al(v) v.begin(),v.end()
    #define ll long long
    using namespace std;
    void solve()
    {
       ll i,n,j;
       double k;
       cin>>i;
       k=2*3.1416*i;
       cout<<fixed<<setprecision(20)<<k<<endl;
     }

    int main()
      {
           fast;
           int i,n,t;
           solve();
      }
//arupsaha52
//1704052_Arup



Measured memory_bytes: 3808
//Bismillah_Hir_Rahmanir_Rahim


#include<bits/stdc++.h>
using namespace std;


int main()
{
   
   int a,b,c,d;
   cin>>a>>b>>c>>d;
   
   
   cout<<min(a,b)+min(c,d)<<endl;
   
    return 0;
}



Measured memory_bytes: 256
// https://atcoder.jp/contests/abc130/tasks/abc130_c

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

const int W_MAX = 1e9;
const int H_MAX = 1e9;

int W, H, x, y;

void solve() {
  double ans = (double) W * (double) H / 2;
  int f = x * 2 == W && y * 2 == H;
  printf("%.12lf %d\n", ans, f);
}

void input() {
  scanf("%d%d%d%d", &W, &H, &x, &y);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 256
n, k = map(int, (input().split()))
a = [0] + [int(i) for i in input().split()]

path = [1]
chk = {1}
idx = 1
loop_s = 1
loop_e = n

for i in range(1, n + 1):
    if a[idx] not in chk:
        idx = a[idx]
        path.append(idx)
        chk.add(idx)
    else:
        loop_s = path.index(a[idx])
        loop_e = i
        break

if k <= loop_s:
    print(path[k])
else:
    print(path[loop_s + (k - loop_s) % (loop_e - loop_s)])

Measured memory_bytes: 32252
n = int(input())
s = []
for _ in range(n):
    s.append(input())
di = {}
for i in s:
    tmp = [0]*26
    for c in i:
        tmp[ord(c)-ord('a')] += 1
    tmp = tuple(tmp)
    if tmp in di:
        di[tmp] += 1
    else:
        di[tmp] = 1

ans = 0
for i in di.values():
    ans += i*(i-1)//2
print(ans)


Measured memory_bytes: 43020
#include <cmath>
#include <cstdio>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int main()
{
	ios::sync_with_stdio(false);

	ll n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	b -= a;
	a = 0;
	
	n -= 1;
	bool ans = 0;
	//for(int i=n%2; !ans && i<=n; i+=2)
	for(ll plus=n; -n<=plus; plus-=1)
	{
		ll minus = n-plus;
		ll maxx = d*plus - c*minus;
		ll minx = c*plus - d*minus;
		
		if(minx <= b && b <= maxx)
		{
			ans = 1;
		}
	}
	
	if(ans)
		cout << "YES\n";
	else
		cout << "NO\n";

	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
 
int main(){
	ll n,m;
	scanf("%lld%lld",&n,&m);
	ll ans=0;
	if(n>m/2){
		printf("%lld\n",m/2);
	}else{
		printf("%lld\n",n+(m-n*2)/4);
	}
	return 0;
}

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

#define hell  1000000007
typedef long long ll;
int l[10000007];
int r[10000007];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    int n;
    cin>>n;
    cin>>s;
    
    for(int i=0;i<n;i++)
    {
        if(s[i]=='E')
        {
            r[i] = 1;
        }
        else
        {
            l[i] = 1;
        }
    }
    for(int i=1;i<n;i++)
    {
        l[i] += l[i-1];
    }
    for(int i=n-2;i>=0;i--)
    {
        r[i] += r[i+1];
    }
    int m=hell;
    m = r[1];
    m = min(l[n-2],m);
    for(int i=1;i<n-1;i++)
    {
        m = min(m,l[i-1]+r[i+1]);
    }
    cout<<m<<endl;
    return 0;
}

Measured memory_bytes: 3860
class Unionfind():  # Unionfind
    def __init__(self, N):
        self.N = N
        self.parents = [-1] * N

    def find(self, x):  # グループの根
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):  # グループの併合
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):  # グループのサイズ
        return - self.parents[self.find(x)]


n, m = map(int, input().split())
minusone = lambda x: int(x) - 1
ab = [list(map(minusone, input().split())) for _ in range(m)]

uf = Unionfind(n)
ans, cnt = [], n * (n - 1) // 2
for a, b in ab[::-1]:
    ans.append(max(cnt, 0))
    if uf.find(a) != uf.find(b):
        cnt -= uf.size(a) * uf.size(b)
        uf.union(a, b)
print(*ans[::-1], sep='\n')


Measured memory_bytes: 103556