akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;


int main()
{
  ll mod = 1000000007;
  string s;
  cin >> s;
  vector<vector<ll>> dp(s.size(), vector<ll>(13, 0));
  if (s[s.size()-1] == '?')
    rep(i, 10)
      dp[s.size()-1][i] = 1;
  else
    dp[s.size()-1][(s[s.size()-1]-'0')%13] = 1;
  int d = 1;
  for (int i = s.size() - 2; i >= 0; i--)
  {
    d = d * 10 % 13;
    if (s[i] == '?')
      rep(j, 10)
      {
        int a = d * j % 13;
        rep(k, 13)
          dp[i][(k+a)%13] = (dp[i][(k+a)%13] + dp[i+1][k]) % mod;
      }
    else
    {
      int a = d * (s[i] - '0') % 13;
      rep(j, 13)
        dp[i][(j+a)%13] = dp[i+1][j];
    }
  }
  cout << dp[0][5] << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))

int main(){
    FAST
    int n; cin >> n;
    string s; cin >> s;
    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'R')cnt++;
    }
    int ans = 0;
    for(int i = 0; i < cnt; i++){
        if(s[i] != 'R')ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    ll h, w, k; cin >> h >> w >> k;
    vector<string> g(h);

    rep(i,h){
        cin >> g[i];
    }

    vector<ll> blkh(h);
    vector<ll> blkw(w);

    rep(i,h){
        rep(j,w){
            if(g[i][j] == '#'){
                blkh[i]++;
                blkw[j]++;
            }
        }
    }

    ll blk = 0;

    rep(i,h) blk += blkh[i];


    ll ans = 0;
    for (int bith = 0; bith < (1<<h); ++bith){
        for (int bitw = 0; bitw < (1<<w); ++bitw){

            ll jud = blk;

            for(int i = 0; i<h; i++){
                if(bith & (1 << i)) jud -= blkh[i];
            }
            for(int i = 0; i<w; i++){
                if(bitw & (1 << i)) jud -= blkw[i];
            }

            rep(i,h){
                rep(j,w){
                    if((bith & (1 << i)) && (bitw & (1 << j)) && g[i][j] == '#') jud++;
                }
            }

            if(jud == k) ans++;

        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r  = sc.nextInt();
		int c  = sc.nextInt();
		int[][] table = new int[r+1][c+1];
		for(int i = 0;i<r;i++){
			for(int j=0;j<c;j++){
				table[i][j] = sc.nextInt();
			}
		}

		for(int i=0; i<r;i++){
			for(int j=0; j<c;j++){
				table[i][c] += table[i][j];
				table[r][j] += table[i][j];
				table[r][c] += table[i][j];
			}
		}

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


Measured memory_bytes: 41656
def ok(hs):
    last = -1
    margin = 1
    for h in hs:
        if h < last - margin:
            return False
        elif h < last:
            margin = 0
        elif h > last:
            margin = 1
        last = h
    return True
n = int(input())
print('Yes' if ok(map(int, input().split())) else 'No')

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

namespace Aizu {
    class OnlineJudge {
        static void Main() {
            var c = System.Text.RegularExpressions.Regex.Matches(Console.ReadLine(), "A.*?Z").Count;
            Console.WriteLine(c > 0 ? string.Concat(Enumerable.Repeat("AZ", c).ToArray()) : "-1");
        }
    }
}

Measured memory_bytes: 11892
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e2+5;

int ar[N];

int main(){
    for(int i = 1; i <= 3; i++){
        scanf("%d" , &ar[i]);
    }
    sort(ar + 1 , ar + 3 + 1);
    if(ar[1] == ar[2]){
        printf("%d\n" , ar[3]);
    } else {
        printf("%d\n" , ar[1]);
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
const ll BIG=1e15;

long long ruijou(int n, int k){
    if(k==0) return 1;
    int x=k/2;
    long long t=ruijou(n,x);
    
    if(k%2==1) return n*t*t;
    else return t*t;
}


int main(){
    vector<ll> V;
    int N;
    cin>>N;
    for(int i=0;i<N;i++){
        string s;
        cin>>s;
        vector<int> k;
        for(int j=0;j<10;j++) k.push_back(s.at(j)-'a');
        sort(k.begin(),k.end());
        ll x=0;
        for(int p=0;p<10;p++) x+=ruijou(30,p)*k.at(p);
        V.push_back(x);
    }
    sort(V.begin(),V.end());

    ll ans=0;
    ll memory=V.at(0);
    ll count=1;
    ll combi=1;
    for(int i=1;i<N;i++){
        if(V.at(i)==memory) count++;
        else{
            ans+=( (count*(count-1))/2 );
            memory=V.at(i);
            count=1;
        }
    }
    ans+=( (count*(count-1))/2 );
    cout<<ans<<endl;
}


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

int main(){
    long long int N;

    //入力
    cin >> N;
    long long int A[N];
    for(long long int i=0;i<N;i++) cin >> A[i];
    
    long long int ans=0;
    long long int step;
    for(long long int i=1;i<N;i++){
        if(A[i]<A[i-1]){
            step = A[i-1] - A[i];
            A[i] = A[i-1];
            ans += step;
        }
    }

    cout << ans << endl;
    
}


Measured memory_bytes: 5156
#include <bits/stdc++.h>   
using namespace std;
#define N 3005  
#define REP(i, n) for(int i=0; i<n; i++)
string s;
int year=0;
int month=0;

int main() {
    cin>>s;
    for(int i=0;i<4;i++){
        if(i!=0)year=year*10;
        year+=s[i]-'0';   
    }
    REP(i,2){
        if(i!=0)month=month*10;
        month+=s[i+5]-'0';
    }
    if(year<=2018){
         printf("Heisei");
    }else if(year==2019 and month<=4){
        printf("Heisei");
    }else{
         printf("TBD");
    }
 }


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

int main() {
    string x, digit;
    int sum, strSize, intDigit;
    while (true) {
        cin >> x;
        if (x == "0") {
            break;
        }
        sum = 0;
        strSize = x.size();
        for (int i = 0; i < strSize; i++) {
            digit = x.substr(i, 1);
            intDigit = stoi(digit);
            sum += intDigit;
        }
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 3204
<?php

$N = (int)trim(fgets(STDIN));

$input = explode(
    " ",
    fgets(STDIN)
);

if ($N == 1) {
    echo 'Yes';
    exit(0);
}

$number = [];
for ($i = 0; $i < $N; $i++) {
    $number[$i] = (int)$input[$i];
}

for ($i = 0; $i < $N - 1; $i++) {
    if ($number[$i] < $number[$i + 1]) {
        $number[$i + 1]--;
    }
}

for ($i = 0; $i < $N - 1; $i++) {
    if ($number[$i] > $number[$i + 1]) {
        echo 'No';
        exit(0);
    }
}

echo 'Yes';

Measured memory_bytes: 27812
N = int(input())
T, A = map(int,input().split())
H = list(map(int,input().split()))

HT = []

for i in range(N):
  HT.append(T - H[i] * 0.006)
  
num = 0
  
for i in range(N):
  if abs(A - HT[num]) > abs(A - HT[i]):
    num = i
    
print(num + 1)
    

Measured memory_bytes: 3060
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
typedef long long int ll;
typedef long double ld;
const ll INF = (1 << 29);
int k, m, n,cnt;
const ll MOD= 1000000007;
const ld PI = acos(-1);
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
typedef int Weight;
struct Edge {
    int src, dst;
    Weight weight;
    Edge(int src, int dst, Weight weight) :
        src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge& e, const Edge& f) {
    return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
struct UnionFind {
    vector<int> par;
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    int size(int x) {
        return -par[root(x)];
    }
};
pair<Weight, Edges> minimumSpanningForest(const Graph& g) {
    int n = g.size();
    UnionFind uf(n);
    priority_queue<Edge> Q;
    rep(u, n) {
        for (auto e = g[u].begin(); e != g[u].end();e++) {
            if (u < e->dst) Q.push(*e);
        }
    }
    Weight total = 0;
    Edges F;
    while (F.size() < n - 1 && !Q.empty()) {
        Edge e = Q.top(); Q.pop();
        if (uf.unite(e.src, e.dst)) {
            F.push_back(e);
            total += e.weight;
        }
    }
    return pair<Weight, Edges>(total, F);
}
int main() {
    cin >> n; int a, b, c;
    vector<vector<Edge>> G(n + 1);
    vector<pair<int,int>> x(n), y(n);
    rep(i, n) {
        cin >> a >> b;
        x[i] = make_pair(a, i);
        y[i] = make_pair(b, i);
    }sort(ALL(x)), sort(ALL(y));
    rep(i, n - 1) {
        int t = x[i].second, u = x[i + 1].second;
        c = x[i + 1].first - x[i].first;
        Edge e = { t,u,c };
        G[t].push_back(e);
        e = { u,t,c };
        G[u].push_back(e);
    }
    rep(i, n - 1) {
        int t = y[i].second, u = y[i + 1].second;
        c = y[i + 1].first - y[i].first;
        Edge e = { t,u,c };
        G[t].push_back(e);
        e = { u,t,c };
        G[u].push_back(e);
    }
    pair<Weight, Edges> p = minimumSpanningForest(G);
    cout << p.first << endl;
}

Measured memory_bytes: 16880
#include<cstdio>
const double eps = 1e-8;
struct Element{
    double x,y;
};
Element queue[500005];
Element a[500005];

double min(double a,double b){
    return a>b?b:a;
}

double abs(double u){ return u>0?u:-u; }

int main(){
    int n; double l;
    scanf("%d%lf",&n,&l);
    for(int i = 1; i <= n; i++){
        double t,v;
        scanf("%lf%lf",&t,&v);
        a[i].x = v, a[i].y = t*v;
    }
    int h = 1, t = 0;
    double xSum = 0, ySum = 0;
    for(int i = 1; i <= n; i++){
        Element cur = a[i];
        xSum += cur.x, ySum += cur.y;
        while(xSum-l>eps){
            Element& cur = queue[h];
            double minusX = min(xSum-l,cur.x);
            double minusY = minusX/cur.x*cur.y;
            xSum -= minusX, cur.x -= minusX;
            ySum -= minusY, cur.y -= minusY;
            if(cur.x<eps) h++;
        }
        while(t!=0 && (cur.y/cur.x)<(queue[t].y/queue[t].x)){
            cur.y += queue[t].y, cur.x += queue[t].x;
            t--;
        }
        queue[++t] = cur;
        printf("%.9f\n",ySum/xSum);
    }
    return 0;
}


Measured memory_bytes: 26004
/*
h3110_fr13nd,
 
AUTHOR : @sam_jn
*/
 
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
using namespace std;
// using namespace __gnu_pbds;
// typedef tree<pair<int, int>, null_type, less_equal<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define MOD 1000000007
#define pb push_back
#define ff first
#define ss second
#define in(a, n) for(int i = 0; i < n; i++) cin >> a[i];
#define ot1(a, n) for(int i = 0; i < n; i++) cout << a[i] << " "; cout << endl;
#define ot2(a, n) for(int i = 0; i < n; i++) cout << a[i] << "\n";
ll pwr(ll a, ll b);
ll pwr(ll a, ll b, ll m);
int baap[200002];
int find(int i);  
bool Union(int x, int y);
ll inv(ll x) {return pwr(x, MOD - 2, MOD);}

//----------------------------------SOLUTION-BELOW-------------------------------------------// 
void solve(){   
    ll n, k;
    cin >> n;
    vector<string> a;
    for(int i = 1; i < 10; i++){
        a.pb(to_string(i));
    }
    int i = 0;
    while(a.size() < n){
        string s = a[i];
        int x = s.size();
        if(s[x - 1] > '0') a.pb(s + char(s[x - 1] - 1));
        a.pb(s + char(s[x - 1]));
        if(s[x - 1] < '9') a.pb(s + char(s[x - 1] + 1));
        i++;
    }
    cout << a[n - 1];

}
int main(){


                                                            // #ifndef ONLINE_JUDGE    
                                                            // freopen("../input", "r", stdin);
                                                            // freopen("../output", "w", stdout);
                                                            // #else
                                                            // // online submission
                                                            // #endif


    boost
    int _ = 1;
    // cout << 0 << endl;
    // cin >> _;
    while(_--){
        solve();
        cout << endl;
    }
}
 
 
//--------------------------------------DEFININTIONS---------------------------------------
ll pwr(ll a, ll b){
    if(b == 0)
        return 1 ;
    ll c = pwr(a, b/2) ;
    c = c * c;
    if(b % 2)
        return c*a;
    return c ;
}
ll pwr(ll a, ll b, ll m){
    if(b == 0)
        return 1;
    ll c = pwr(a, b/2, m) % m ;
    c = (c * c) % m;    
    if(b % 2)
        return (c * a%m) % m;
    return c ;
}
int find(int i)  
{  
    if (baap[i] != i)  
        baap[i] = find(baap[i]);  
  
    return baap[i];  
}
 
bool Union(int x, int y)
{
    x = find(x);
    y = find(y);
    if(x == y) return false;
    baap[x] = y;
    return true;
}

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

int main(){
  int N=0, x=0, min_2=999999999;
  cin >> N;
  
  for(int i=0; i<N; i++){
    cin >> x;
    int counter=0;
    while(x%2 == 0){
      counter++;
      x /= 2;
    }
    if(counter < min_2)
      min_2 = counter;
  }
  cout << min_2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define cs const 
#define fr first 
#define se second
#define ls (now<<1)
#define rs (now<<1|1)
#define mid ((l+r)>>1)
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define low(i) (i&(-i))
#define par pair<int,int>
#define cn(x) memset(x, 0, sizeof(x))
#define rep(i, x, y) for(int i=x; i<=y; ++i)
#define sep(i, x, y) for(int i=x; i>=y; --i)
#define fore(i, x) for(int i=fir[x]; i; i=nex[i])
 
cs int G = 3;
cs int ff = 2e6 + 1;
cs int inf = 1e18 + 1;
cs int base = 2333;
cs int M = 998244353;

int bs[ff], bs2[ff];
struct Node 
{
	int tr[ff], len[ff], tg[ff];
	void pushup(int now)
	{
		tr[now] = (tr[ls] * bs[len[rs]] % M + tr[rs]) % M;
		len[now] = len[ls] + len[rs];
//		cout << tr[now] << " " << len[now] <<"\n";
	}
	void psdd(int now, int va)
	{
		tr[now] = bs2[len[now]] * va % M;
		tg[now] = va;
	}
	void psd(int now)
	{
		if(!tg[now]) return;
		psdd(ls, tg[now]); psdd(rs, tg[now]);
		tg[now] = 0;
	}
	void build(int now, int l, int r)
	{
		if(l == r) { tr[now] = bs2[1]; len[now] = 1; return; }
		build(ls, l, mid); build(rs, mid + 1, r);
		pushup(now);
	}
	void modi(int now, int l, int r, int lc, int rc, int va)
	{
		if(l > rc || r < lc) return;
		if(lc <= l && r <= rc) return (void)(psdd(now, va));
		psd(now);
		modi(ls, l, mid, lc, rc, va);
		modi(rs, mid + 1, r, lc, rc, va);
		pushup(now);
	}
	int qry() { return tr[1]; }
}Seg;
int n, q;
void init()
{
	int a, b, c, d;
	cin >>a;
	rep(i, 1, a) cout <<"ACL";
}
signed main()
{
	int Ts = 1;
//	cin >> Ts;
	while(Ts--)
		init();
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
#include <stdio.h>
int main(){
  int N,P,Q;
  while(true){
    cin >> N >> P >> Q;
    if(N == -1 && P == -1 && Q == -1){
      break;
    }
    if(N + P >= 80){
      cout << "A" << endl;
    }
    else if(N + P >= 65 && N + P < 80){
      cout << "B" << endl;
    }
    else if(N + P >= 50 && N + P < 65){
      cout << "C" << endl;
    }
    else if(N + P >= 30 && N + P < 50 && Q >= 50){
      cout << "C" << endl;
    }
    else if(N + P < 30){
      cout << "F" << endl;
    }
    else if(N == -1 || P == -1){
      cout << "F" << endl;
    }
    else {
      cout << "D" << endl;
    }
  }
}


Measured memory_bytes: 3092
#include <cstdio>
#include <cstring>
#include <algorithm>

typedef long long LL;
const int MN = 500005;

int N, a[MN], b[MN];
char s[MN];
LL Ans;

int main() {
	scanf("%s", s + 1), N = strlen(s + 1) + 1;
	a[1] = 0, b[N] = 0;
	for (int i = 2; i <= N; ++i) a[i] = s[i - 1] == '<' ? a[i - 1] + 1 : 0;
	for (int i = N - 1; i >= 1; --i) b[i] = s[i] == '>' ? b[i + 1] + 1 : 0;
	for (int i = 1; i <= N; ++i) Ans += std::max(a[i], b[i]);
	printf("%lld\n", Ans);
	return 0;
}

Measured memory_bytes: 4608
#include<iostream>
#include<vector>
const int INF = 1e9 +5;
using namespace std;

int main(){
 	int n,k;
    scanf("%d %d", &n, &k);
    vector<int>h(n);
   	vector<int>dp(n, INF);
    
    for(int i=0;i<n;i++)
   	  scanf("%d", &h[i]);
     dp[0] = 0;
     
    for(int i=0;i<n;i++){
     int dist = i+k;
  	 for(int j=i;j<=dist;j++){
        if(j<n)
        dp[j] = min(dp[j], dp[i]+abs(h[j]-h[i]));
     }
    }
    printf("%d\n",dp[n-1]);
 	return 0;
 }

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;

int main(){
    int n,x;
    while(cin>>n>>x){
        int count=0;
        if(n==0 && x==0) continue;
        for(int i=1;i<=n;i++){
            for(int j=i+1;j<=n;j++){
                for(int k=j+1;k<=n;k++){
                    if(i+j+k == x) count++;
                }
            }
        }
        cout << count << endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll x, ll y) {
	ll res = 1;
	for (ll i = 0; i < y; i++) res = res * x % mod;
	return res;
}

int main() {
	int k, a, b;
	cin >> k >> a >> b;
	for (int i = a; i <= b; i++) {
		if (i % k == 0) {
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;
	return 0;
}

Measured memory_bytes: 3604
import sys
input = sys.stdin.readline

n, k = [int(x) for x in input().split()]
a = [int(x) for x in range(n + 1)]
a_rev = a[::-1]
mod = 10**9 + 7

left = sum(a[:k])
right = sum(a_rev[:k])

ans = right - left + 1

for i in range(k, n + 2):
    if i > n:
        break
    left += a[i]
    right += a_rev[i]
    ans += right - left + 1
    ans %= mod

print(ans)

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

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

typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int N = 1e5 + 10;
const int oo = 1e18;

struct EDGE{
    int u, v, cost;
} edge[N];
int n, m;
int vertex[N];
bool check[N], visit[N], ans[N];
ii pr[N];
vector<ii> eg[N];

int find(int u) { return (pr[u].fi == u) ? u : (pr[u].fi = find(pr[u].fi)); }

void addeg(int u, int v)    {
    int nu = find(u), nv = find(v);
    if(nu == nv) return;
    pr[nu].fi = nv;
    pr[nv].se += pr[nu].se;
}

bool cmp(const int x, const int y)  { return edge[x].cost < edge[y].cost; }
void findedge() {
    vector<int> tmp; FOR(i, 1, m) tmp.pb(i);
    sort(tmp.begin(), tmp.end(), cmp);

    for(auto it: tmp)   {
        int nu = find(edge[it].u), nv = find(edge[it].v);
        if(nu == nv) {
            if(pr[nu].se >= edge[it].cost) check[it] = 1;
        } else {
            if(pr[nu].se + pr[nv].se >= edge[it].cost) check[it] = 1;
            addeg(nu, nv);
        }
    }
}

void dfs(int u, int cost)   {
    visit[u] = 1;
    for(auto it: eg[u]) if(edge[it.se].cost <= cost)    {
        ans[it.se] = 1;
        if(!visit[it.fi]) dfs(it.fi, cost);
    }
}

void spread()   {
    vector<int> tmp; FOR(i, 1, m) if(check[i]) tmp.pb(i);
    sort(tmp.begin(), tmp.end(), cmp);

    for(int i = tmp.size() - 1ll; i >= 0ll; --i)    {
        int id = tmp[i];
        if(!visit[edge[id].u]) dfs(edge[id].u, edge[id].cost);
        if(!visit[edge[id].v]) dfs(edge[id].v, edge[id].cost);
    }

    int cnt = 0;
    FOR(i, 1, m) if(!ans[i]) cnt ++;
    cout << cnt;
}

signed main()  {
//    freopen("test.inp", "r", stdin);
//    freopen("test.out", "w", stdout);
    ios_base::sync_with_stdio(false); cout.tie(0);

    cin >> n >> m;
    FOR(i, 1, n) cin >> vertex[i], pr[i] = {i, vertex[i]};
    FOR(i, 1, m)    {
        int u, v, cost; cin >> u >> v >> cost;
        edge[i] = {u, v, cost};
        eg[u].pb({v, i});
        eg[v].pb({u, i});
    }

    findedge();
    return spread(), 0;
}


Measured memory_bytes: 17636
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;

int N;
string s,ss;
int main(){
    cin>>N;
    cin>>s>>ss;
    int a=0;
    for(int i=0;i<s.length();i++){
        if(s.substr(i,s.length()-i)==ss.substr(0,s.length()-i)){
            a=max(a,(int)s.length()-i);
        }
    }
    cout<<2*N-a<<endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque
class csr:
    def __init__(self,N,edges):
        self.start = [0]*(N+1)
        self.elist = [0]*len(edges)
        for e in edges:
            self.start[e[0]+1] += 1
        for i in range(1,N+1):
            self.start[i] += self.start[i-1] 
        counter = self.start[:]
        for e in edges:
            self.elist[counter[e[0]]] = e[1]
            counter[e[0]] += 1

class scc_graph:
    def __init__(self,N):
        self.N = N
        self.edges = []
    
    def add_edge(self,v,w):
        self.edges.append((v,w))

    def scc_ids(self):
        N = self.N
        g = csr(N,self.edges)
        now_ord = group_num = 0
        visited = deque()
        low = [0]*N
        order = [-1]*N
        ids = [0]*N
        parent = [-1]*N
        stack = deque()
        for i in range(N):
            if order[i] == -1:
                stack.append(i)
                stack.append(i)
                while stack:
                    v = stack.pop()
                    if order[v] == -1:
                        low[v] = order[v] = now_ord
                        now_ord += 1
                        visited.append(v)
                        for i in range(g.start[v],g.start[v+1]):
                            to = g.elist[i]
                            if order[to] == -1:
                                stack.append(to)
                                stack.append(to)
                                parent[to] = v
                            else:
                                low[v] = min(low[v],order[to])
                    else:
                        if low[v] == order[v]:
                            while True:
                                u = visited.pop()
                                order[u] = N
                                ids[u] = group_num
                                if u == v:
                                    break
                            group_num += 1
                        if parent[v] != -1:
                            low[parent[v]] = min(low[parent[v]],low[v])
        for i,x in enumerate(ids):
            ids[i] = group_num-1-x

        return group_num,ids
    
    def scc(self):
        group_num,ids = self.scc_ids()
        groups = [[] for _ in range(group_num)]
        for i,x in enumerate(ids):
            groups[x].append(i)
        return groups
    
import sys
readline = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
N,M = map(int,readline().split())
ab = list(map(int,read().split()))
sg = scc_graph(N)

it = iter(ab)
for a,b in zip(it,it):
    sg.add_edge(a,b)

scc = sg.scc()
print(len(scc))
for group in scc:
    print(str(len(group))+' '+' '.join(map(str,group)))


Measured memory_bytes: 214520
#include "bits/stdc++.h"
using namespace std;

int main(){
  int a,b,c,x,y;
  cin>>a>>b>>c>>x>>y;
  int big;
  if(x>y){
    big=a;
  }else{
    big=b;
  }
  int ans=a*x+b*y;
  int ans2=((min(x,y)*2)*c)+(abs(x-y)*big);
  int ans3=((min(x,y)*2)*c)+(abs(x-y)*c*2);
  ans=min(ans,min(ans2,ans3));


  cout<<ans<<endl;
}


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

using namespace std;


long long calc(long long m,long long k){	
	long long ans = 1;
	while(1){		
		if(m/k==0)break;
		m -= m/k+1;
		ans += 1;
	}
	return ans+m;
}



long long binary_search(long long m,long long n,long long k){
	long long ok = m+1;
	long long ng = 0;
	while(abs(ok-ng)>1){
		long long mid = (ok+ng)/2;
		if(calc(mid,k)>=n){
			ok = mid;
		}else{
			ng = mid;
		}
	}
	return ok;
}



int main(){
	long long ans;
	long long n,k;
	cin >> n >> k;
	if(n==1)cout << 0 << endl;
	else cout << binary_search(1000000000000000000,n,k) << endl;
	return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  char c[4];
  cin >> c;
  cout << (c[0] - '0' + c[1] - '0' + c[2] - '0');
}

int main()
{
  fastio;
  solve();

  return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    set<string> registered;
    for (int i=0;i<N;++i){
        string U; cin >> U;
        registered.insert(U);
    }
    int M; cin >> M;
    int now=0;
    for (int i=0;i<M;++i){
        string T; cin >> T;
        if (registered.count(T)){
            cout << (now?"Closed by ":"Opened by ") << T << endl;
            now^=1;
        } else cout << "Unknown " << T << endl;
    }
}


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

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
#define rep(i,j,n) for(int i=j; i<n; i++)
#define INF 1000000000000000000 // If you use it, make sure not to put in "int" type variable ;(, use long long int
void optimizeIO() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
const ll mod=1000000007;

int main()
{
    optimizeIO();
    int nT; nT=1;
	while(nT--)
	{
		ll n; cin>>n;
		ll a[n]; rep(i,0,n) cin>>a[i];
		vector<ll>s;
		ll ans=0;
		for(int i=n-1; i>=0; i--)
		{
			if(s.empty() || s[s.size()-1]<=a[i]) s.pb(a[i]);
			else
			{
				s.clear();
				s.pb(a[i]);
			}
			ans=max(ans,1LL*int(s.size())-1);
			// cout<<i<<' '<<s.size()<<' '<<ans<<'\n';
		}
		cout<<ans;
	}
	return 0;
}


Measured memory_bytes: 2168
import sys
N = int(input())
sum = 0
A = list(map(int,input().split()))
flag = 0
if 0 in A:
    print(0)
    sys.exit()
Asum = 1
for i in A:
    Asum = Asum * int(i)
    if Asum > 10**18:
        flag = 1
        break

if flag == 0 :
    print(Asum)
else:
    print(-1)

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

typedef long long ll;

int main(){
	string s,t;
	cin>>s>>t;
	int a,b;
	cin>>a>>b;
	string u;
	cin>>u;
	if(s==u){
		cout<<a-1<<" "<<b<<" "<<endl;
	}else{
		cout<<a<<" "<<b-1<<" "<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N; cin>>N;
    vector<ll> A(N);
    vector<ll> B(N);
    rep(i,N) cin>>A[i];
    rep(i,N) cin>>B[i];
    priority_queue<P> qu;
    rep(i,N) if(A[i]!=B[i]) qu.emplace(B[i],i);
    ll ans=0;
    while(!qu.empty()){
        ll ind=qu.top().second;
        qu.pop();
        ll buf=(B[ind]-A[ind])/(B[(ind+N-1)%N]+B[(ind+1)%N]);
        if(buf<=0){cout<< -1 <<"\n"; return;}
        ans+=buf;
        B[ind]-=buf*(B[(ind+N-1)%N]+B[(ind+1)%N]);
        if(A[ind]!=B[ind]) qu.emplace(B[ind],ind);
    }
    cout<< ans <<"\n";

}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 9584
#include<bits/stdc++.h>
using namespace std;
int a[1<<17],n,s,z,t,i,m;
int main(){
	scanf("%d%d",&n,&t);
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	for(i=n;i;i--){
		m=max(m,a[i]);
		if(m-a[i]>z)z=m-a[i],s=1;
		else if(z==m-a[i])s++;
	}
	printf("%d",s);
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep1(i, n) for(int i=1; i<=(int)(n); i++)
#define rep2(i, n, m) for(int i=(int)n; i<=(int)m; i++)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> wi;
typedef vector<ll> vl;
const ll inf=1LL << 60;
const ll MOD=1000000007;

struct UnionFind{
  vi size, par;

  UnionFind() {}
  UnionFind(int n){
    par.resize(n, 0);
    size.resize(n, 0);
    rep(i, n){
      par[i]=i;
      size[i]=-1;
    }
  }

  int root(int x){
    if(x!=par[x])par[x]=root(par[x]);
    return par[x];
  }

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

  void unite(int x, int y){
    x=root(x);
    y=root(y);
    if(x==y)return;
    if(size[x]>size[y]){
      par[y]=x;
      size[x]+=size[y];
    }
    else{
      par[x]=y;
      size[y]+=size[x];
    }
  }

  int treesize(int x){
    return -size[root(x)];
  }

};

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

  int n, m;
  scanf("%d %d", &n, &m);
  UnionFind d(n);
  int a, b;
  rep(i, m){
    scanf("%d %d", &a, &b);
    d.unite(a-1, b-1);
  }

  set<int> s;
  rep(i, n){
    int t=d.root(i);
    s.insert(t);
  }

  printf("%d\n", s.size()-1);

  return 0;
}

Measured memory_bytes: 7928
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int X, Y, Z;
  cin >> X >> Y >> Z;

  swap(X, Y);
  swap(X, Z);

  cout << X << " " << Y << " " << Z << endl;
  
  return 0;
}



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

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

using namespace std;
typedef long long ll;  typedef pair<int,ll> pii;
typedef vector<int> VI; typedef vector<ll> VL;
const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main(){
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n; string s;
	cin >>n >>s;
	
	int bc=0, ac=0;
	rep(i, n){
		if(s[i]=='(') ac++;
		else{
			if(ac>0) ac--;
			else bc++;
		}
	}
	cout << string(bc, '(') + s + string(ac, ')') <<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 200010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int d;
    cin >> d;
    if (d == 25) cout << "Christmas" << endl;
    else if (d == 24) cout << "Christmas Eve" << endl;
    else if (d == 23) cout << "Christmas Eve Eve" << endl;
    else if (d == 22) cout << "Christmas Eve Eve Eve" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] d = new int[N];
        for (int i = 0; i < N; i++) {
            d[i] = Integer.parseInt(sc.next());
        }

        Arrays.sort(d);
        System.out.println(d[N / 2] - d[N / 2 - 1]);
    }
}


Measured memory_bytes: 52456
#include <iostream>

using namespace std;

int main()
{
    int first = 0;
    int second = 0;
    int third = 0;
    
    for (int i = 0; i < 10; ++i) {
        int number;
        cin >> number;
        if (number <= third) continue;
        third = number;
        if (third <= second) continue;
        swap(second, third);
        if (second <= first) continue;
        swap(first, second);
    }
    cout << first << endl
         << second << endl
         << third << endl;
    return 0;
}

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

char c[2][3];

int main(){
    for(int i=0;i<2;i++){
        for(int j=0;j<3;j++){
            cin>>c[i][j];
        }
    }
    if(c[0][0]==c[1][2]&&c[0][1]==c[1][1]&&c[0][2]==c[1][0]){
        cout<<"YES"<<endl;
    }
    else cout<<"NO"<<endl;
    return 0;
}

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

using namespace std;
#define ll long long

#define rep(i, a) for (int (i) = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int (i) = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int (i) = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int (i) = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
	#define lcout(a) cout << a;
	#define lcoutln(a) cout << a << endl;
	#define lcerr(a) cerr << a;
	#define lcerrln(a) cerr << a << endl;
#else
	#define lcout(a) 
	#define lcoutln(a) 
	#define lcerr(a) 
	#define lcerrln(a) 
#endif


int main()
{
	CIN(string, s);
	cout << "ABC" << s << endl;
}


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

Measured memory_bytes: 21844
#include<stdio.h>

int main(){
	unsigned long Many, MostSmall;
	unsigned long TakeTime[5];
	if (scanf("%lu", &Many) == 1);
	for (int i = 0; i < 5; i++){
		if (scanf("%lu", &TakeTime[i]) == 1);
		if (i == 0)
			MostSmall = TakeTime[i];
		else{
			if (MostSmall > TakeTime[i])
				MostSmall = TakeTime[i];
		}
	}
	printf("%lu",((Many-1)/MostSmall)+5);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>

using namespace std;
typedef long long ll;

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

  vector<ll> vec(n);
  for (int i = 0 ; i < n; i++) {
    cin >> vec[i];
  }
  sort(vec.begin(), vec.end());
  
  ll diff = 1e9;
  for (int i = 0 ; i + k - 1 < n; i++) {
    diff = min(diff, vec[i + k - 1] - vec[i]);
  }
  cout << diff << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h> 
#define AndIamIronMan ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); 
#define M 1000000007 

#define int128 __int128
using namespace std;
 
typedef  long long int lli; 

bool prime(lli n){
	bool x=true;
	int i;
	for(i=2;i<=sqrt(n);i++){
		if(n%i==0){
			x=false;
		}	
	}
	return x;
}
string BaseConv(lli b,lli n){
//	lli sum=0;
	string s="";
	while(n){
		lli r=n%b;
//		sum+=r;
		s+=to_string(r);
		n/=b;
	}
	return s;
} 

bool SubStrCheck(string sub,string mai){
	lli i,j,n,m;
	n=sub.length();
	m=mai.length();
	string s="";
	for(i=0;i<m-n+1;i++){
		s="";
		for(j=i;j<i+n;j++){
			s+=mai[j];	
		}
		if(sub==s){
			return true;
		}
	}
	return false;
}  

int main(){
		
    AndIamIronMan;
	lli co=0,i,n,y,m,d,j,k,t,x=0,a,b,c;
//	cin>>t;
//	while(t--){
	cin>>n;
	x=1000*ceil((double)n/1000);
	cout<<(lli)(x-n);
//	}
	return 0;
}

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

int main(int argc, const char * argv[]) {
    
    while(true){
        int H,W;
        cin >> H >> W;
        if(H == 0 && W == 0){
            break;
        }
        
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(i == 0 || i == H-1 || j == 0 || j == W -1){
                    cout << "#";
                }
                else{
                    cout << ".";
                }
                
            }
            cout << endl;
        }
        
        cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
const int MAXN=100000+5;
int n,k,dp[MAXN],a[105];

int main(){
	cin>>n>>k;
	for(int i=0;i<n;++i) cin>>a[i];
	dp[0]=0;
	for(int i=0;i<k;++i)
		if(!dp[i]) for(int j=0;j<n;++j) if(i+a[j]<=k) dp[i+a[j]]=1;
	puts(dp[k]?"First":"Second");
	return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>

using namespace std;
typedef long long ll;
#define pl pair<ll,ll>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second
ll N,M;
vector<string> a,b;
int solve(int i, int j){
	bool res=1;
	FOR(k,i,i+M){
		FOR(l,j,j+M){
			if(a[k][l]!=b[k-i][l-j]){
				res=0;				
			}
		}
	}
	return res;
}

int main(){
	cin>>N>>M;
	string input;
	int ans=0;
	rep(i,N){
		cin>>input;
		a.pb(input);
	} 
	rep(i,M){
		cin>>input;
		b.pb(input);
	}

	rep(i,N-M+1){
		rep(j,N-M+1){
			ans= max(ans,solve(i,j));
		}
	}

	cout<<(ans?"Yes":"No")<<endl;
	return 0;
}












Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * (B / gcd(A, B));
}

/*------------------------------------------------------------------*/


int main(){
    int h, w, n; cin >> h >> w >> n;
    vector<int> a(n);
    rep(i, n){
        cin >> a[i];
        //cout << a[i] << endl;
    }
    int ans[h][w];
    bool flag = true;
    int count = 0;
    int k = 0;
    int j = 0;

    for(int i = 0; i < n; i++){
        while(true){
            if(flag){
                ans[count][j] = i + 1;
            }else{
                ans[count][(w - 1) - j] = i + 1;
            }
            j++;
            k++;
            if(j == w){
                if(flag) flag = false;
                else flag = true;
                count++;
                j = 0;
            }
            if(k == a[i]){
                k = 0;
                break;
            }
        }
    }
    rep(i, h){
        rep(j, w){
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';

int main() {
    double a,b,x,rad;
    cin>> a >> b >> x;
    if (x>=a*a*b/2.0) rad=atan(2.0*(a*a*b-x)/a/a/a);
    else rad=atan(a*b*b/2.0/x);
    cout<<fixed<<setprecision(10)<<rad/M_PI*180.0<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	int x,y,z;
	cin >> x>>y>>z;
	cout << (x - z) / (y + z) << endl;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[10000001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
long long num[100000];
int main(){
	int x,y;
	cin>>x>>y;
	if((x==1||x==3||x==5||x==7||x==8||x==10||x==12)&&(y==1||y==3||y==5||y==7||y==8||y==10||y==12)){
		cout<<"Yes"<<endl;
		return 0;
	}
	if((x==4||x==6||x==9||x==11)&&(y==4||y==6||y==9||y==11)){
		cout<<"Yes"<<endl;
		return 0;
	}
	if(x==2&&y==2){
		cout<<"Yes"<<endl;
		return 0;
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class405
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            var xy = new long[N][];
            for (int i = 0; i < N; i++)
            {
                xy[i] = Console.ReadLine().Split().Select(long.Parse).ToArray();

            }
            if (N == 1) { Console.WriteLine(1);return; }

            Array.Sort(xy, (a, b) => a[0] != b[0] ? a[0].CompareTo(b[0]) : a[1].CompareTo(b[1]));
            Dictionary<Tuple<long, long>, int> path = new Dictionary<Tuple<long, long>, int>();
            for (int i = 0; i < N-1; i++)
            {
                for (int j = i+1; j < N; j++)
                {
                    var t = Tuple.Create(xy[j][0] - xy[i][0], xy[j][1] - xy[i][1]);
                    if (path.ContainsKey(t))
                    {
                        path[t]++;
                    }
                    else
                    {
                        path[t] = 1;
                    }
                }
            }

            Console.WriteLine(N-path.Values.Max());
        }
    }
}


Measured memory_bytes: 29100
#include<bits/stdc++.h>
using namespace std;
bool f(int n)
{
    set<int>s;
    while(n)
    {
        s.insert(n%10);
        n/=10;
    }
    if(s.size()==1) return true;
    return false;
}
int main()
{
    int n;
    cin>>n;
    while(true)
    {
        if(f(n))
        {
            printf("%d\n",n);
            return 0;
        }
        n++;
    }
}


Measured memory_bytes: 256
a = []
gyou = []
retu = []
s = 0

c, r = map(int, input().split())

for i in range(r):
    gyou.append(0)

for i in range(c):
    a.append(list(map(int, input().split())))

for i in range(c):
        retu.append(sum(a[i]))

for i in range(r):
    for j in range(c):
        gyou[i] += a[j][i]

s = sum(gyou)

for i in range(c):
    print(" ".join(map(str, a[i])), retu[i])

    if i == c - 1:
        print(" ".join(map(str, gyou)), s)


Measured memory_bytes: 5712
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(S: str):
    a = S[0] == 'A'
    bs = list(filter(lambda x: x != 'C', S[2:-1]))
    cs = list(filter(lambda x: ord('A') <= ord(x) <= ord('Z'), [S[1]] + bs + list(S[-1:])))
    r =  a and len(bs) == (len(S[2:-1]) - 1) and len(cs) == 0
    return 'AC' if r else 'WA'


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    result = solve(S)
    print(result)

if __name__ == '__main__':
    main()


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

int main() {
  string A,B,C;
  char a,b,c;
  cin >>A >>B >>C;
  a = toupper(A.at(0));
  b = toupper(B.at(0));
  c = toupper(C.at(0));
  cout <<a <<b <<c <<endl;
  return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i;
ws = gets.chomp.split(" ").map(&:to_i);

sum = 0
ws.each { |i| sum += i }

mae = 0
abs = sum
tmp = sum

ws.each do |i|
  mae += i
  sum -= i
  tmp = (mae-sum).abs
  abs = tmp if tmp < abs
end

puts abs

Measured memory_bytes: 1788
#include "bits/stdc++.h"
using namespace std;

int main(){
	long long a,b,d;
  	int t;
  	cin>>t;cin>>d;
  int ans=0;
  	for(int i=0;i<t;i++){
    cin>>a;cin>>b;
      if((a*a+b*b)<=(d*d)){ans++;}
    }

cout<<ans;
}

Measured memory_bytes: 3612