akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main()
{
    int a,b,t,res;
    float time;
    scanf("%d%d%d",&a,&b,&t);
  if(a>=1&&a<=20&&b>=1&&b<=20&&t>=1&&t<=20)
    {
    	time=t+0.5;
    	res=(time/a);
    	printf("%d\n",res*b);
    }
    return 0;
}

Measured memory_bytes: 128
k = int(input())
a, b = map(int,input().split())
c = int(a / k)
d = int(b / k)

count = 0
for i in range(c,d+1):
    if a <= k*i and k*i <= b:
        count += 1
if count >= 1:
    print("OK")
else:
    print("NG")

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

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

  int q1 = 0;
  int q2 = 0;
  int q3 = 0;

  rep(i,n){
    int p;
    cin >> p;
    if(p >= b+1) q3++;
    else if(p >= a+1 && p <= b) q2++;
    else q1++;
  }
  cout << min(min(q1,q2),q3) << endl;
}


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

int main(){

    int n,m;cin>>n>>m;
    vector<vector<int>>s(m);
    rep(i,m){
        int k;cin>>k;
        s[i].resize(k);
        rep(j,k){
            cin>>s[i][j];
            --s[i][j];
        }
    }
    vector<int>p(m);
    rep(i,m)cin>>p[i];
    int ans=0;
    for(int i=0;i<(1<<n);i++){
        bool ok=true;
        rep(j,m){
            int count=0;
            for(int id:s[j]){
                if((i>>id)&1)count++;
            }
            if(count%2!=p[j])ok=false;
        }
        if(ok)ans++;
    }
    cout<<ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
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;}
const long long INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main() {
    ll n,ans=0;
    cin >> n;
    ll l[n];
    for (ll i=0;i<n;i++)cin >> l[i];
    sort(l,l+n);
    for (ll i=0;i<n-2;i++){
        for (ll j=i+1;j<n-1;j++){
            for (ll k=j+1;k<n;k++){
                ll a=l[i],b=l[j],c=l[k];
                if (a<b+c and b<c+a and c<b+a)ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

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

typedef long long ll;
typedef long double ld;

int main(){
    int a,b,c; 
    cin >> a >> b >> c; 

    ll i(0);

    while(a%2==0 && b%2==0 && c%2==0){
        int ab,ac,ba,bc,ca,cb;
        ab = ac = a/2;
        ba = bc = b/2;
        ca = cb = c/2;
        a = a + ba + ca; b = b + ab + cb; c = c + ac + bc;
        i++;
        if(i == 100000000){
            i = -1;
            break;
        }
    }

    cout << i << endl;
    return 0;
}

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

using namespace std;

int main() {
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '7') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(){
	int n, k; scanf("%d%d", &n, &k);
	ld ans = 0;
	FOR(i, 1, n+1){
		int j = i;
		ld p = 1;
		while(j < k) j*=2, p/=2;
		ans += p/n;
	}
	printf("%.30Lf\n", ans);
}


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

int main(){
  int n,k,i;
  string s;
  cin>>n;
  for(i=0;i<=n/4;i++){
    k=n-4*i;
    if(k%7==0){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;

int dp[5010][5010]={};
int main(){
    int n;
    string s;
    cin>>n;
    cin>>s;
    for(int i=n-1;i>=0;i--){
        for(int j=n-1;j>=0;j--){
            if(s[i]==s[j]){
                if(i==n-1||j==n-1)dp[i][j]=1;
                else dp[i][j]=min(abs(i-j),dp[i+1][j+1]+1);
            }
            else dp[i][j]=0;
        }
    }
    int ans=0;
    rep(i,n)rep(j,n){
        if(i==j)continue;
        //cout<<dp[i][j];
        //if(j==n-1)cout<<endl;
        ans=max(ans,dp[i][j]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 98048
void main() {
  problem();
}

void problem() {
  auto N = scan!ulong + 1;
  
  ulong solve() {
    ulong[] divisers = new ulong[N];
    divisers[] = 1;
    foreach(i; 2..N) {
      for(ulong x = i; x < N; x += i) divisers[x]++;
    }

    ulong ans;
    foreach(i; 1..N) ans += i * divisers[i];
    return ans;
  }

  solve().writeln;
}

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

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Queue = Tuple!(long, "from", long, "to");

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


Measured memory_bytes: 80984
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String input = sc.nextLine();
		char[] output = new char[1200];

		for(int i = 0;i < input.length();i++){
			if('A' <= input.charAt(i) && input.charAt(i) <= 'Z') output[i] = Character.toLowerCase(input.charAt(i));
			else if('a' <= input.charAt(i) && input.charAt(i) <= 'z') output[i] = Character.toUpperCase(input.charAt(i));
			else output[i] = input.charAt(i);
		}
		for(int i = 0;i < input.length();i++){
			System.out.print(output[i]);
		}
		System.out.println();
	}
}


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

typedef vector<vector<int>> vvi;
typedef vector<int> vi;

typedef vector<pair<int, pair<int, int>>> vpii;

template <typename T>
void max_self(T& a, T b) {
	a = std::max(a, b);
}

const int INF = 1e9 + 5;

bool first_row_or_column(pair<int, int>& a) {
	return a.first == 0 || a.second == 0;
}

int main() {
	string a, b;
	cin >> a >> b;
	vector<vpii> dp(a.length() + 1, vpii(b.length() + 1, {-INF, {0, 0}}));
	dp[0][0] = {0, {0, 0}};
	// dp[i][j] - max total lenght so far;

	for (int i = 0; i < a.length(); i++) {
		for (int j = 0; j < b.length(); j++) {
			if (a[i] == b[j]) {
				max_self(dp[i + 1][j + 1], make_pair(dp[i][j].first + 1, make_pair(i, j)));
			}
			max_self(dp[i + 1][j], make_pair(dp[i][j].first, make_pair(i, j)));
			max_self(dp[i][j + 1], make_pair(dp[i][j].first, make_pair(i, j)));
		}
	}

	pair<int, pair<int, int>> ans = {0, {0, 0}};
	for (int i = 0; i <= a.length(); i++) {
		for (int j = 0; j <= b.length(); j++) {
			ans = max(ans, make_pair(dp[i][j].first, make_pair(i, j)));
		}
	}
	
	string s;
	pair<int, int> cur = ans.second;
	while(!first_row_or_column(cur)) {
		int i = cur.first;
		int j = cur.second;
		pair<int, int> prev = dp[i][j].second;
		// assert()
		if (prev == make_pair(i - 1, j - 1)) {
			assert(a[i - 1] == b[j - 1]);
			s += a[i - 1];
		}
		cur = prev;
	}
	reverse(s.begin(), s.end());
	cout << s;
	// cout << ans.first;
}

Measured memory_bytes: 108032
function Main(input){
    const arr = input.split('\n');
    const NQ = arr[0].split(' ').map(Number);
    const S = arr[1];
    const numArr = new Array(NQ[0]+1).fill(0);
    // 特定文字列の数をもったリストを作成する
    for(let i=0; i<NQ[0]; i++){
        const num = (S[i] == 'A' && S[i+1] == 'C') ? 1 : 0;
        numArr[i+1] = numArr[i] + num;
    }
    for(let i=0; i<NQ[1]; i++){
        const left = Number(arr[i+2].split(' ')[0]);
        const right  = Number(arr[i+2].split(' ')[1]);
        console.log(numArr[right-1] - numArr[left-1]);
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

using namespace std;

int C[12];
int A[12][12];

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  for (int i = 0; i < N; i++) {
    cin >> C[i];
    for (int j = 0; j < M; j++) {
      cin >> A[i][j];
    }
  }
  constexpr int kMax = 10000000;
  int ans = kMax;
  for (int x = 0; x < (1 << N); ++x) {
    int skill[12] = {0};
    int cost = 0;
    for (int i = 0; i < N; i++) {
      if (x & (1 << i)) {
        for (int j = 0; j < M; j++) {
          skill[j] += A[i][j];
        }
        cost += C[i];
      }
    }
    bool ok = true;
    for (int i = 0; i < M; i++) {
      if (skill[i] < X) {
        ok = false;
        break;
      }
    }
    if (ok) {
      ans = min(ans, cost);
    }
  }
  cout << (ans == kMax ? -1 : ans) << endl;
  return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	string s;
	cin >> s;
	ll dp[100001][13] = { 0 };
	dp[0][0] = 1;
	REP(i, s.length()) {
		int c;
		if (s[i] == '?')c = -1;
		else c = s[i] - '0';
		REP(j, 10) {
			if (j == c || c == -1) {
				REP(k, 13)
					dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
			}
		}
		REP(j, 13)
			dp[i + 1][j] %= MOD;
	}
	cout << dp[s.length()][5];
}

Measured memory_bytes: 10624
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt(),m = sc.nextInt();
    int a[] = new int[n],b[] = new int[n];
    int c[] = new int[m],d[] = new int[m];
    for(int i = 0;i < n;i++){
      a[i] = sc.nextInt(); b[i] = sc.nextInt();
    }
    for(int i = 0;i < m;i++){
      c[i] = sc.nextInt(); d[i] = sc.nextInt();
    }
    int place[] = new int[n];
    int dis;
    int near;
    for(int i = 0;i < n;i++){
      near = 200000000;
      for(int j = 0;j < m;j++){
        dis = Math.abs(a[i] - c[j]) + Math.abs(b[i] - d[j]);//iとjの距離計算
        if(dis < near){//最も近い地点の記録
          near = dis;
          place[i] = j;
        }
      }
    }
    for(int i = 0;i < n;i++){
      System.out.println(place[i]+1);
    }
  }
}


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

int main()
{
  int a = 0, b = 0, sum = 0;
  cin >> a >> b;
  for(int i = 0; i < 2; ++i)
  {
    if (a > b)
    {
      sum += a;
      a--;
    }
    else
    {
      sum += b;
      b--;
    }
  }
  cout << sum;
  return 0;
}

Measured memory_bytes: 256
n=int(input())
M={}
l=0
for i in range(4):
    for j in range(3):
        for k in range(10):
            M[(i+1,j+1,k+1)]=0

while l<n:
    L=input().split( )
    b=int(L[0])
    f=int(L[1])
    r=int(L[2])
    v=int(L[3])
    M[(b,f,r)]=M[(b,f,r)]+v
    l+=1


for i in range(4):
    for j in range(3):
        for k in range(10):
            print (f" {M[(i+1,j+1,k+1)]}",end="")
        print()
    if i<3:
        print("####################")
# ####が一度多かった



Measured memory_bytes: 5636
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

int N;

// int gcd(int m, int n) {
// 	if (m == 0 || n == 0) return 0;
// 	int r;
// 	while ((r = m % n) != 0) {
// 		m = n;
// 		n = r;
// 	}
// 	return n;
// }

// int lcm(int m, int n) {
// 	if (m == 0 || n == 0) return 0;
// 	return m * n / gcd(m, n);
// }

int main(int argc, char const *argv[]) {
	cin >> N;
	ll res[2] = {0, 0};
	ll a, b;
	for (int i = 0; i < N; i++) {
		cin >> a >> b;
		if (a >= res[0] && b >= res[1]) {
			res[0] = a;
			res[1] = b;
		}
		else if (a < res[0] && b >= res[1]) {
			ll r = ((res[0] - 1) / a) + 1;
			res[0] = r * a;
			res[1] = r * b;
		}
		else if (a >= res[0] && b < res[1]) {
			ll r = ((res[1] - 1) / b) + 1;
			res[0] = r * a;
			res[1] = r * b;
		}
		else {
			ll r = max(((res[0] - 1) / a) + 1, ((res[1] - 1) / b) + 1);
			res[0] = r * a;
			res[1] = r * b;
		}
	}
	cout << res[0] + res[1] << endl;
	return 0;
}

Measured memory_bytes: 256
<?php
ini_set('error_reporting', E_ALL & ~E_NOTICE);
$answer = "Yes";
for ($i = 0; $i < 3; $i++) {
    $c[$i] = explode(" ", trim(fgets(STDIN)));
    $mmin = min($c[$i]);
    foreach ($c[$i] as $k => $v) {
        $c[$i][$k] -= $mmin;
    }
}
for ($i = 0; $i < 3; $i++) {
    if ($c[0][$i] != $c[1][$i] || $c[1][$i] != $c[2][$i]) {
        $answer = "No";
    }
}
echo $answer . PHP_EOL;


Measured memory_bytes: 5112
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll mod = 1000000000+7;
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
      if (n & 1) res = res * a % mod;
      a = a * a % mod;
      n >>= 1;
  }
  return res;
}

int main() {
    ll n;
    ll m;
    std::cin >> n;
    if(n%2==1){
        m = n-1 + ((n-1) * (n-2))/2 - (n-1)/2;
        std::cout << m << std::endl;
        for (int i = 0; i < n-1; i++) {
            std::cout << i+1 << " "<<n << std::endl;
        }
        for (int i = 0; i < n-1; i++) {
            for (int j = i+1; j < n-1; j++) {
                if( i +1 + j+1 != n){
                    std::cout << i+1 <<" "<<j+1 << std::endl;
                }
            }
        }
    }else{
        m = ((n) * (n-1))/2 - n/2;
        std::cout << m << std::endl;
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                if( i +1 + j+1 != n+1){
                    std::cout << i+1 <<" "<<j+1 << std::endl;
                }
            }
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
       
using namespace std;
       
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
 
// #define MAX 100010
 
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES

bool vis[10];
int g[10][10];
int n;

int dfs(int u)
{
    int done=1;
    for(int i=0;i<n;i++)
    {
        if(!vis[i])
            done=0;
    }
    if(done)
        return 1;
    int ans = 0;
    for(int i=0;i<n;i++)
    {
        if(g[u][i]==false)
            continue;
        if(vis[i])
            continue;
        vis[i]=true;
        ans+=dfs(i);
        vis[i]=false;
    }
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // #ifndef ONLINE_JUDGE
        // freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);
    // #endif
    int m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        g[a][b]=1;
        g[b][a]=1;
    }
    vis[0]=true;
    cout<<dfs(0)<<endl;
    return 0;
}

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

// Lib
//

int main(){
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    string S; cin >> S;
    ll n = S.size();
    ll ans = 0;
    ll num = 0;
    for (ll i = 0; i < n; ++i) {
        if (S[i] == 'W') {
            ans += num;
        }
        else {
            ++num;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <cassert>
#include <functional>
#include <vector>

template <typename Monoid> class SegmentTree {
public:
	using value_type = Monoid;
	using reference = value_type &;
	using const_reference = const value_type &;
	using container_type = std::vector<value_type>;
	using size_type = typename container_type::size_type;

private:
	const size_type size_, capacity;
	container_type tree;
	static size_type getsize(const size_type &size) noexcept {
		size_type ret = 1;
		while (ret < size)
			ret <<= 1;
		return ret;
	}
	void recalc(const size_type &index) {
		tree[index] = tree[index << 1] + tree[index << 1 | 1];
	}

public:
	SegmentTree(const size_type &size)
		: size_(size), capacity(getsize(size_)), tree(capacity << 1) {}
	void update(size_type index,
		const std::function<value_type(const_reference)> &f) {
		assert(index < size());
		index += capacity;
		tree[index] = f(tree[index]);
		while (index >>= 1)
			recalc(index);
	}
	void update(const size_type &index, const_reference data) {
		update(index, [&data](const_reference x) { return data; });
	}
	value_type range(size_type begin, size_type end) const {
		assert(begin <= end);
		assert(begin <= size());
		assert(end <= size());
		value_type retL, retR;
		for (begin += capacity, end += capacity; begin < end;
			begin >>= 1, end >>= 1) {
			if (begin & 1)
				retL = retL + tree[begin++];
			if (end & 1)
				retR = tree[end - 1] + retR;
		}
		return retL + retR;
	}
	size_type search(const std::function<bool(const_reference)> &b) const {
		if (b(value_type()))
			return 0;
		if (!b(tree[1]))
			return size() + 1;
		value_type acc;
		size_type i = 1;
		while (i < capacity)
			if (!b(acc + tree[i <<= 1]))
				acc = acc + tree[i++];
		return i - capacity + 1;
	}
	const_reference operator[](const size_type &index) const {
		assert(index < size());
		return tree[index + capacity];
	}
	size_type size() const noexcept { return size_; }
	bool empty() const noexcept { return !size_; }
};

#include<cstdint>
template <typename T> struct Sum {
	using value_type = T;
	using size_type = std::uint_fast32_t;
	T a;
	size_type s;
	explicit Sum(const T &x = T(0), const size_type y = 0) : a(x), s(y) {}
	Sum operator+(const Sum &o) const { return Sum(a + o.a, s + o.s); }
};

#include <iostream>
int main(void) {
	using S = Sum<int>;
	int n, q;
	std::cin >> n >> q;
	SegmentTree<S> T(n);
	while (q--) {
		int c, x, y;
		std::cin >> c >> x >> y;
		if (c)
			std::cout << T.range(x-1, y).a << std::endl;
		else
			T.update(x-1, [&y](S d) {return d + S(y);});
	}
	return 0;
}


Measured memory_bytes: 7056
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<29;
vector<int> G[MAX];
vector<pair<int,int>> ST[MAX];
int color[MAX],par[MAX],siz[MAX];
ll ans[MAX],res[MAX],colorsiz[MAX];

void pre(int u,int p){
    siz[u]=1;
    
    if(si(ST[color[u]])==0){
        par[u]=-1;
    }
    else par[u]=ST[color[u]].back().se;
    
    for(int to:G[u]){
        if(to==p) continue;
        ST[color[u]].push_back({u,to});
        
        pre(to,u);
        
        siz[u]+=siz[to];
        ST[color[u]].pop_back();
    }
    
    if(si(ST[color[u]])==0){
        colorsiz[color[u]]-=siz[u];
    }
    
}

void DFS(int u,int p){
    ans[u]=siz[u];
    if(par[u]!=-1) ans[par[u]]-=ans[u];
    for(int to:G[u]){
        if(to==p) continue;
        DFS(to,u);
        res[color[u]]+=ans[to]*(ans[to]+1)/2;
    }
}

void output(int i){
    cout<<"Case #"<<i<<": ";
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N;cin>>N;
    
    for(int i=0;i<N;i++){
        cin>>color[i];
        color[i]--;
    }
    
    for(int i=0;i<N-1;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    
    for(int i=0;i<N;i++) colorsiz[i]=N;
    
    pre(0,-1);
    DFS(0,-1);
    
    for(int i=0;i<N;i++){
        if(color[0]==i) continue;
        res[i]+=colorsiz[i]*(colorsiz[i]+1)/2;
    }
    
    ll ans=0;
    
    for(int i=0;i<N;i++){
        cout<<N*(N+1)/2-res[i]<<"\n";
        //ans+=N*(N+1)/2-res[i];
    }
}



Measured memory_bytes: 52324
while True:
    h, w = map(int, input().split())
    if h == 0 and w == 0:
        break
    for i in range(h):    
        for j in range(w):
            if (i + j) % 2 == 0: 
                print("#", end="")
            else:
                print(".", end="")
        print()
    print()


Measured memory_bytes: 7004
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;


struct UnionFind {
	VI par;
	UnionFind(int N) :par(N) {
		REP(i, N)par[i] = i;
	}
	int root(int x) {
		if (par[x] == x)return x;
		return par[x] = root(par[x]);
	}
	void unite(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		if (rx == ry)return;
		par[rx] = ry;
	}
	bool same(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

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

	string S; cin >> S;
	REP(i, S.size() - 1) {
		if (S[i] == 'A'&&S[i + 1] == 'C') {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int f=0,s=0,n;
    int a[200000];
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        if(a[i]>f){
            f=a[i];
        }else if(a[i]>s && f>=s){
            s=a[i];
        }
    }
    for (int i = 0; i < n; i++) {
        if(a[i]!=f){
            std::cout << f << std::endl;
        }else{
            std::cout << s << std::endl;
        }
    }
}


Measured memory_bytes: 2432
a,b,c = gets.split.map &:to_i

cnt_a = 0
cnt_b = 0

if a==5
  cnt_a += 1
end
if b==5
  cnt_a += 1
end
if c==5
  cnt_a += 1
end
if a==7
  cnt_b += 1
end
if b==7
  cnt_b += 1
end
if c==7
  cnt_b += 1
end

if cnt_a==2 && cnt_b==1
  puts "YES"
else
  puts "NO"
end


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

const ll INF = pow(10, 9) + 7;

int main() {
  string s;
  cin >> s;
  vector<string> a = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
  rep(i,7){
    if(s==a[i]){
      cout << 7-i;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
random_device rnd;
mt19937 mt(rnd());

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;
int main()
{
    int n;
    cin >> n;
    n %= 10;
    if (n == 3)
    {
        cout << "bon" << endl;
    }
    else if (n == 0 || n == 1 || n == 6 || n == 8)
    {
        cout << "pon" << endl;
    }
    else
    {
        cout << "hon" << endl;
        
    }

    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define lb long double
#define eps 1e-10
using namespace std;
int n;
struct Po{lb x,y;}q1,q2;
struct circ{Po x;lb r;}p;
Po operator - (Po x,Po y){return (Po){x.x-y.x,x.y-y.y};}
Po operator +(Po x,Po y){return (Po){x.x+y.x,x.y+y.y};}
lb operator *(Po x,Po y){return x.x*y.y-x.y*y.x;}
lb operator ^(Po x,Po y){return x.x*y.x+x.y*y.y;}
Po operator *(Po x,lb y){return (Po){x.x*y,x.y*y};}
Po operator /(Po x,lb y){return (Po){x.x/y,x.y/y};}
void get(Po &x){scanf("%Lf %Lf",&x.x,&x.y);}
lb dis2(Po x){return x.x*x.x+x.y*x.y;}
lb dis(Po x){return sqrt(dis2(x));}
int main(){
	get(p.x);scanf("%Lf",&p.r);
	scanf("%d",&n);
	while (n--){
		get(q1);get(q2);
		lb x=((q2-q1)^(p.x-q1))/dis(q2-q1);
		Po xian=(q2-q1)/(dis(q2-q1));
		Po zh=q1+xian*x;
		lb de=sqrt(p.r*p.r-dis2(p.x-zh));
		Po an1=q1+xian*(x-de),an2=q1+xian*(x+de);
		if (an1.x>an2.x+eps||(fabs(an1.x-an2.x)<eps&&an1.y>an2.y+eps))swap(an1,an2);
		printf("%.10Lf %.10Lf %.10Lf %.10Lf\n",an1.x,an1.y,an2.x,an2.y);
	}
	return 0;
}


Measured memory_bytes: 3236
n = int(input())
a = [int(s) for s in input().split()]

ans = 0
parity = True
while parity:
    for i in range(n):
        if a[i] % 2 == 0:
            a[i] = a[i] / 2
        else:
            parity = False
    if parity:
        ans += 1 
print(ans)

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

int main() {
  int N, y;
  cin >> N;
  y = 0;
  
  for (int i = 0; i < N; i++) {
    string x;
    cin >> x;
    
    if (x == "Y") {
      y = 1;
      break;
    }
  }
  
  if (y == 0) {
    cout << "Three" << endl;
  }
  
  else {
    cout << "Four" << endl;
  }
}

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

int main(){

  int R,G,B,N;

  cin>>R>>G>>B>>N;

  long long ans=0;
  
  for(int i=0;i<=N;i++){
	for(int j=0;j<=N;j++){
	  if((N-(i*R+j*G))%B==0&&N-(i*R+j*G)>=0){
		ans++;
	  }
	}
  }

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map> 
#include <unordered_set>
#include <set>
#include <functional>
#include <utility>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <cassert>

using namespace std;
#define mod 1000000007
#define for0(a, c) for (int(a) = 0; (a) < (c); (a)++)
#define forA(a, b, c) for (int(a) = (b); (a) <= (c); (a)++)
#define forD(a, b, c) for (int(a) = (b); (a) >= (c); (a)--)
#define INF 1000000000000000003
#define all(a) a.begin(),a.end()
#define ff first
#define ss second
#define pb push_back 
#define pob pop_back
#define mp make_pair

typedef long long int            ll;
typedef vector<int>              vi;
typedef pair<int, int>           pi;
typedef unordered_map<int, int>  mii;
typedef unordered_map<char, int> mci;
typedef unordered_set<int>       usi;

void solve(){
	int a;
	cin>>a;
	string s;
	cin>>s;

	if(a < 3200)
		cout<<"red"<<endl;
	else cout<<s<<endl;
}

int main(){

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1; 
    // cin>>t;
    while(t--){
      solve();
    }
    return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  long long w;
  cin >> w;
  vector<vector<int>> a(4);
  int sw;
  for (int i = 0; i < n; i++) {
	int x, y;
	cin >> x >> y;
	if (i == 0) {
	  sw = x;
	}
	a[x - sw].push_back(y);
  }
  for (int i = 0; i < 4; i++) {
	sort(a[i].rbegin(), a[i].rend());
  }
  long long ans = 0;
  for (int i = 0; i <= a[0].size(); i++) {
	for (int j = 0; j <= a[1].size(); j++) {
	  for (int k = 0; k <= a[2].size(); k++) {
		for (int l = 0; l <= a[3].size(); l++) {
		  long long sumw = 0, sumv = 0;
		  sumw = 1LL * i * sw + 1LL * j * (sw + 1) + 1LL * k * (sw + 2) + 1LL * l * (sw + 3);
		  if (sumw > w) continue;
		  for (int m = 0; m < i; m++) {
			sumv += a[0][m];
		  }
		  for (int m = 0; m < j; m++) {
			sumv += a[1][m];
		  }
		  for (int m = 0; m < k; m++) {
			sumv += a[2][m];
		  }
		  for (int m = 0; m < l; m++) {
			sumv += a[3][m];
		  }
		  ans = max(ans, sumv);
		}
	  }
	}
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import deque


def perm(n, k, a=1, mod=10**9+7):
  if n < k or k < 0:
    a = 0
  else:
    for i in range(n, n-k, -1):
      a = a*i % mod
  
  return a


MOD = 10**9 + 7
N, K = map(int, input().split())
tree = [[] for i in range(N)]
for i in range(N-1):
  a, b = map(int, input().split())
  tree[a-1].append(b-1)
  tree[b-1].append(a-1)


ans = K
d = deque([[0, -1]])
while d:
  node, parent = d.pop()
  children = tree[node]
  if parent == -1:
    ans = ans*perm(K-1, len(children)) % MOD
  else:
    ans = ans*perm(K-2, len(children)-1) % MOD
  
  for child in children:
    if child == parent:
      continue
    
    d.append([child, node])

print(ans)

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

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("O3", "Ofast", "unroll-loops", "fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


#define int long long
#define endl '\n'

using namespace std;

signed main(){
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    int i, st = 100;
    int x; cin >> x;
    int l = 0, r = 3762;
    while (l < r - 1){
        int m = (l + r) / 2;
        int cur = st;
        for (i = 0; i < m; i++){
            cur += cur / 100;
        }
        if (cur >= x){
            r = m;
        }
        else{
            l = m;
        }
    }
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
using namespace std;
const long long N = 1e9+7;
int x,z,i,j,a[1005];
long long ans;
int main()
{
    cin>>x;
    for(i=1;i<=x;i++)
    { z=i;
      for(j=2;j*j<=z;j++)
      {  while(z%j==0){z/=j;
        a[j]++;}
      }
     if(z!=1)a[z]++;
    }ans=1;
    for(i=2;i<=1000;i++)
    {ans*=a[i]+1;ans%=N;}
    cout<<ans;
 }       

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

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

    string t;
    for ( int i=0; i<s.size(); i++ ) {
        if ( s[i]=='A' ) {  t+='A'; }
        else if ( i+1<s.size()&&s[i]=='B'&&s[i+1]=='C' ) { t+='D'; i++; }
        else { t+=s[i]; }
    }
    long long ans=0,cnt=0;
    for ( int i=(int)t.size()-1; i>=0; i-- ) {
        if ( t[i]=='D' ) {
            cnt++;
        } else if ( t[i]=='A' ) {
            ans+=cnt;
        } else {
            cnt=0;
        }
    }
    cout << ans  << '\n';
    return 0;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;
template<typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; //小さいものから取り出す

int main(){
    ll x;
    cin >> x;
    if(x%2 == 1){
        cout << 0 << endl;
        return 0;
    }
    ll five = 5;
    ll ans = 0;
    while(five <= x){
        ans += x/(five*2);
        five *= 5;
    }

    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
ll ans=0,a,b,c;
int main(){
//  freopen("a.in","r",stdin);
    a=read();ans=read();read();b=read();c=read();read();read();
    if(!a||!b||!c){printf("%lld\n",ans+a/2*a+b/2*2+c/2*2);return 0;}
    if(a%2==b%2&&b%2==c%2){printf("%lld\n",ans+a+b+c);return 0;}
    printf("%lld\n",ans+a+b+c-1);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>

typedef long long LL;

#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define REP(i,n) FOR(i,0,n)
#define max(l,r) ((l)>(r)?l:r)
#define min(l,r) ((l)<(r)?l:r)

const int MAX = 600000;
const int LIM = 100000000;
const LL MOD = 1000000007;
const int INF = 2147483647/2;
const LL LINF = 9223372036854775807/3;

int ucmpii(const void *a, const void *b){return(*(int*)a==*(int*)b?0:(*(int*)a>*(int*)b?1:-1));}
int dcmpii(const void *a, const void *b){return(*(int*)a==*(int*)b?0:(*(int*)a<*(int*)b?1:-1));}

int ucmpll(const void *a, const void *b){return(*(LL*)a==*(LL*)b?0:(*(LL*)a>*(LL*)b?1:-1));}
int dcmpll(const void *a, const void *b){return(*(LL*)a==*(LL*)b?0:(*(LL*)a<*(LL*)b?1:-1));}

void SORT(int*a, int n){qsort(a,n,sizeof(int),ucmpii);}
void SORTR(int*a, int n){qsort(a,n,sizeof(int),dcmpii);}
void LSORT(LL*a, int n){qsort(a,n,sizeof(LL),ucmpll);}
void LSORTR(LL*a, int n){qsort(a,n,sizeof(LL),dcmpll);}

int main(){
  
  int n;
  scanf("%d",&n);

  LL a[MAX];
  REP(i,n) scanf("%lld",&a[i]);

  LL amax = a[0], sum = 0;

  REP(i,n){
    if(amax > a[i]){
      sum += amax - a[i];
    }else {
      amax = a[i];
    }
  }

  printf("%lld\n",sum);
}

Measured memory_bytes: 3256
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   //setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  //sin, cos, tan

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

void Main()
{
  ll n, m, k;
  cin >> n >> m >> k;
  for(ll i = 0;i <= n;i++)
  {
    for(ll j = 0;j <= m;j++)
    {
      if(i * (m - j) + j * (n - i) == k) fin("Yes");
    }
  }
  fin("No");
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  return 0;
}


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

typedef pair<int,int> pii;
const int N=200010;
int a[N],n,flag;
set<pii> s;

void gao(int x,int now)
{
	pii tmp;
	if(x<1) flag=-1;
	tmp=*s.lower_bound(make_pair(x,0));
	if(tmp.first!=x) s.insert(pii(x,0)),tmp=pii(x,0);
	else
	{
		s.erase(tmp);
		if(++tmp.second>=now) gao(x-1,now);
		else s.insert(tmp);
	}
	while(1)
	{
		if(s.upper_bound(tmp)==s.end()) break;
		tmp=*s.upper_bound(tmp);
		s.erase(tmp);
	}
}

bool check(int x)
{
	s.clear();flag=0;
	for(int i=1;i<=n;i++)
		if(a[i]<=a[i-1]) gao(a[i],x-1);
	return flag!=-1;
}

int main()
{
	int i,flag=1,ans; 
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",a+i);
		flag&=(a[i]>a[i-1]);
	}
	if(flag) return puts("1"),0;
    int l=2,r=n,mid;
	while(l<=r)
	{
		int mid=l+r>>1;
		if(check(mid)) r=mid-1;
		else l=mid+1;
	}
	printf("%d\n",l); 
 	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
using namespace std;
const int mod = 1e9 + 7;
int main(){
  int H, W, A, B;
  cin >> H >> W >> A >> B;
  int M = 1e6;
  vector<long long int> factorial(M, 1), inverse(M, 1);
  for(int i = 1; i < M; ++i){
    factorial[i] = (factorial[i-1]*i)%mod;
  }
  int k = mod - 2;
  long long int t = factorial.back();
  while(k > 0){
    if(k & 1){
      inverse.back() *= t;
      inverse.back() %= mod;
    }
    t *= t;
    t %= mod;
    k >>= 1;
  }
  for(int i = M-2; i >= 0; --i){
    inverse[i] = (inverse[i+1]*(i+1))%mod;
  }
  long long int ans = 0;
  for(int i = 1; i <= H - A; ++i){
    long long int t = 1;
    t *= factorial[B+i-2]*inverse[B-1];
    t %= mod;
    t *= inverse[i-1];
    t %= mod;
    t *= factorial[H+W-i-B-1];
    t %= mod;
    t *= inverse[H-i];
    t %= mod;
    t *= inverse[W-B-1];
    t %= mod;
    ans += t;
    //cout << t << endl;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}


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

A_ = []
for a_idx,a in enumerate(A):
    A_.extend([a_idx+1]*a)

i=0
for w in range(0,len(A_),W):
    i+=1
    ans=A_[w:w+W]
    if i%2 == 0:
        ans.reverse()
    print(' '.join(map(str,ans)))

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

using namespace std;

int main(int argc, char *argv[]) {
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;

    vector<int> arr({a, b, c, d, e});
    for (int i = 0; i < arr.size(); i++) {
        if (arr[i] == 0) {
            cout << i + 1 << endl;
        }
    }

    return 0;
}


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

#define ll long long

using namespace std;

const int N = 405;

int n;

ll a[N], dp[N][N], p[N];

int main () {
    cin >> n;
    for (int i = 1;i <= n;i ++) {
        cin >> a[i];
        p[i] = p[i - 1] + a[i];
    }
    for (int i = 2;i <= n;i ++) {
        for (int l = 1, r = i;r <= n;l ++, r ++) {
            dp[l][r] = 1e18 + 7;
            for (int mid = l;mid < r;mid ++) {
                dp[l][r] = min (dp[l][r], dp[l][mid] + dp[mid + 1][r] + p[r] - p[l - 1]);
            }
        }
    }
    cout << dp[1][n];
}


Measured memory_bytes: 1536
N = int(input())
A = sorted(list(map(int,input().split())))

mod = 10**9+7
if(N%2 == 0 and len(set(A)) == N//2):
  print(2**(N//2) % mod)
elif(N%2 != 0 and A.count(0) == 1):
  print(2**((N-1)//2) % mod)
else:
  print(0)

Measured memory_bytes: 13880
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define show(x) cout<<x<<'\n'
#define showh(x) cout<<x<<' '
#define go(i,a,n) for(ll i=a;i<n;i++)
#define gor(i,a,n) for(ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define mod 1000000007
bool prime[100001];
bool ispoweroftwo(ll x)
{
    return x && !(x & (x-1));
}
ll xorcal(ll n)
{
    if(n%4==0)
        return n;
    if(n%4==1)
        return 1;
    if(n%4==2)
        return n+1;
    if(n%4==3)
        return 0;
}
void sieve(ll n)
{
    memset(prime,true,sizeof(prime));
    prime[0]=false;
    prime[1]=false;
    for(ll i=2;i*i<=n;i++)
    {
        if(prime[i]==true)
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                prime[j]=false;
            }
        }
    }
    show(prime[89]);
}
bool isprime(ll n)
{
    if (n<=1) return false;
    if (n<=3) return true;

    if(n%2==0 or n%3==0) return false;

    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0 or n%(i+2)==0) return false;
    }
    return true;
}

ll modinverse(ll a,ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m; a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
       x += m0;

    return x;
}

ll gcd(ll a,ll b)
{
    if(a==0)
    {
        return b;
    }
    return(b%a,a);
}

ll power(ll A, ll B)
{
    if (A == 0)
        return 0;
    if (B == 0)
        return 1;

    ll y;
    if (B % 2 == 0) {
        y = power(A, B / 2);
        y = (y * y) % mod;
    }

    else {
        y = A % mod;
        y = (y * power(A, B - 1) % mod) % mod;
    }

    return (ll)((y + mod) % mod);
}
int main()
{
    ios_base::sync_with_stdio(false);
    ll n;
    cin>>n;
    show((n*n*n));
}


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

struct node{
    int x, v;
    friend bool operator <(node a, node b){
        return a.x < b.x;
    }
}p[MAX];

int n, m, cnt;
int val[MAX], a[MAX], vis[MAX], fa[MAX];
int head[MAX], vet[MAX], Next[MAX], id[MAX];
vector<int> ans;

int find(int x){
    if(x == fa[x]) return x;
    return fa[x] = find(fa[x]);
}

void add(int x, int y, int k){
    cnt++;
    Next[cnt] = head[x];
    head[x] = cnt;
    vet[cnt] = y;
    id[cnt] = k;
}

int dfs(int x){
    vis[x] = 1;
    int res = val[x];
    for(int i = head[x]; i; i = Next[i]){
        int v = vet[i];
        if(vis[v]) continue;
        int now = dfs(v);
        if(now) ans.push_back(id[i]);
        res ^= now;
    }
    return res;
}

int main()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        fa[i] = i;
        scanf("%d%d", &p[i].x, &p[i].v);
    }
    fa[n+1] = n+1;
    sort(p+1, p+n+1);
    for(int i = 1; i <= n; i++){
        a[i] = p[i].x, val[i] = p[i].v;
    }
    for(int i = n; i >= 1; i--){
        val[i] ^= val[i-1];
    }
    int l, r;
    for(int i = 1; i <= m; i++){
        scanf("%d%d", &l, &r);
        l = lower_bound(a+1, a+n+1, l)-a;
        r = upper_bound(a+1, a+n+1, r)-a;
        if(find(l) != find(r)){
            add(l, r, i), add(r, l, i);
            fa[find(l)] = fa[find(r)];
        }
    }
    dfs(n+1);
    for(int i = 1; i <= n; i++){
        if(!vis[i]){
            if(dfs(i)){
                puts("-1");
                return 0;
            }
        }
    }
    sort(ans.begin(), ans.end());
    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); i++){
        printf("%d ", ans[i]);
    }

    return 0;
}

Measured memory_bytes: 18560
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    int a;
    char buf[30];

    // 標準入力から1行bufに格納
    fgets(buf, sizeof(buf), stdin);

    a = atoi(buf);

    printf("%d\n", a*a*a + a*a + a);

    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <chrono>
#include <queue>
#include <functional>

#define out(t) cout << (t) << "\n"

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef unsigned int uint;

int popcount(uint x) {
    x -= x >> 1 & 0x55555555;
    x = (x & 0x33333333) + (x >> 2 & 0x33333333);
    x = x + (x >> 4) & 0x0F0F0F0F;
    return x * 0x01010101 >> 24;
}

int tzcnt(uint x) {
    return popcount(~x & x - 1);
}

struct Point {
    int x, y;

    Point(int p, int q) : x(p), y(q) {}
};

ll ans[100];

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

    int N;
    cin >> N;

    map<string, int> table;

    for (int i = 0; i < N; ++i) {
        string s;
        cin >> s;

        if (table.count(s)) {
            ++table[s];
        }
        else {
            table[s] = 1;
        }
    }

    int M;
    cin >> M;

    for (int i = 0; i < M; ++i) {
        string s;
        cin >> s;

        if (table.count(s)) {
            --table[s];
        }
        else {
            table[s] = -1;
        }
    }

    int ans = 0;

    for (auto t : table) {
        ans = max(t.second, ans);
    }

    out(ans);

    int aaa;
    cin >> aaa;
}

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

int main() {
	int N;
  	cin >> N;
  	string S;
  	cin >> S;
  
  for(int i = 0; i < S.size(); i++){
    char ans = S.at(i) + N -26;
    char ans2 = S.at(i) + N;
  	if(ans2 >= 91) cout << ans;
    else cout << ans2;
 }
}

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

int n, k;
vector<int> g[2005];
int ans;
int ct = 0;

void dfs(int v, int f = -1, int d = 0) {
    if (d > k/2)
        return;
    ++ct;
    for (int u : g[v]) {
        if (u == f)
            continue;
        dfs(u, v, d+1);
    }
}

int main() {
    cin >> n >> k;
    ans = n;
    
    for (int i = 0; i < n-1; ++i) {
        int a, b;
        cin >> a >> b;
        a--; b--;

        g[a].push_back(b);
        g[b].push_back(a);
    }

    if (k%2 == 0) {
        for (int i = 0; i < n; ++i) {
            ct = 0;
            dfs(i);
            ans = min(ans, n-ct);
        }
    } else {
        for (int i = 0; i < n; ++i) {
            for (int u : g[i]) {
                ct = 0;
                dfs(i, u);
                dfs(u, i);
                ans = min(ans, n-ct);
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 384