akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 1e+18
#define int long long
using namespace std;

template<class T> T &chmin(T &a,const T &b) { return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b) { return a = max(a,b); }

using P = pair<int,int>;

struct tree{
	int n,seg,init;
	vector<vector<P>> dat;
	tree(int n) : n(n),seg(1){
		while(seg < n) seg *= 2;
		dat.resize(seg * 2 - 1);
	}
	void preset(int i,int x,int t){
		dat[i + seg - 1].push_back(P(x,t));
	}
	void build(){
		for(int i = 0;i < seg;i++) sort(dat[i + seg - 1].begin(),dat[i + seg - 1].end());
		for(int i = seg - 2;i >= 0;i--){
			dat[i] = mergeVec(dat[i * 2 + 1],dat[i * 2 + 2]);
		}
	}
	vector<P> get(int a = 0,int b = -1,int k = 0,int l = 0,int r = -1){
		if(b == -1) b = seg;
		if(r == -1) r = seg;
		if(b <= l || r <= a) return vector<P>(0);
		if(a <= l && r <= b) return dat[k];
		return mergeVec(get(a,b,k * 2 + 1,l,(l + r) / 2),get(a,b,k * 2 + 2,(l + r) / 2,r));
	}
	static vector<P> mergeVec(const vector<P> &v1,const vector<P> &v2){
		vector<P> ret;
		int lind = 0,rind = 0;
		while(lind < v1.size() && rind < v2.size()){
			if(v1[lind].first == v2[rind].first){
				ret.push_back(P(v1[lind].first,v1[lind].second + v2[rind].second));
				lind++;rind++;
			}else if(v1[lind].first < v2[rind].first){
				ret.push_back(v1[lind]);
				lind++;
			}else{
				ret.push_back(v2[rind]);
				rind++;
			}
		}
		while(lind < v1.size()) ret.push_back(v1[lind++]);
		while(rind < v2.size()) ret.push_back(v2[rind++]);
		return ret;
	}
};

signed main(){
	int n,m,t,a[100010],b[100010],c[100010];
	cin >> n >> m >> t;
	a[m] = t;
	set<int> st,tim;
	vector<int> in[100010],out[100010];
	for(int i = 0;i < m;i++){
		cin >> a[i] >> b[i] >> c[i];
		tim.insert(a[i]);
	}
	tim.insert(t);
	tree tre(tim.size());
	int cnt = 0;
	for(int i = 0;i < m;i++){
		if(c[i]){
			st.insert(b[i]);
			in[b[i]].push_back(cnt);
		}
		else{
			st.erase(b[i]);
			out[b[i]].push_back(cnt);
		}
		if(a[i] != a[i + 1]){
			for(int v : st){
				tre.preset(cnt,v,a[i + 1] - a[i]);
			}
			cnt++;
		}
	}
	tre.build();
	for(int v : st) out[v].push_back(cnt);
	for(int i = 1;i <= n;i++){
		int ans = (i == 1 ? 2 : 1),ma = 0;
		vector<P> vec;
		for(int j = 0;j < in[i].size();j++){
			vec = tree::mergeVec(vec,tre.get(in[i][j],out[i][j]));
		}
		for(P p : vec){
			if(p.second > ma && p.first != i){
				ma = p.second;
				ans = p.first;
			}
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 24660
import math
import numpy as np
import queue
from collections import deque
import heapq

n,m = map(int,input().split())
way = [[] for i in range(n+1)]
for i in range(m):
    a,b = map(int,input().split())
    way[a].append(b)
    way[b].append(a)

q = queue.Queue()
q.put(1)
t = [10**18 for i in range(n+1)]
tmt = [-1 for i in range(n+1)]
t[0] = 10*18
t[1] = 0

while not q.empty():
    qi = q.get()
    for i in way[qi]:
        if t[i] > t[qi]+1:
            t[i] = t[qi]+1
            tmt[i] = qi
            q.put(i)

if 10**18 in t:
    print("No")
else:
    print("Yes")
    for i in range(2,n+1):
        print(tmt[i])


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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)
// while (getline(cin, S)) {}

// #include <cstdio>
// int a;
// scanf("%d", &a);
// printf("%d\n", a);
//
// for (int i=0; i<n; ++i)
// 	scanf("%d", &a[i]);
//
// char c;
// scanf(" %c", &c);
//
// cout << "\n";

// cout <<fixed <<setprecision(10)

// priority_queue<int> q;
// priority_queue<int, vector<int>, less<int>> q; // Default: vector, less
// priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

//
// Notes
//
// When specified less than N, try full scan.
// RE: empty vector
// Check Qs
// long/int
// xor -> count each bit
// Check values
// 	1,000,000 -> Loop
// 	100,000	-> vector(int:400KB, long:800KB) 

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

/*
ll	myPow(ll x, ll n) {
	if (0==n)
		return 1;
	if (0==n%2)
		return myPow(x*x%MOD, n/2);
	else
		return x*myPow(x, n-1)%MOD;
}
*/
ll	myPow(ll x, ll n) {
	ll r=1;
	while(n>0)
		if (0==n%2) {
			x *=x;
			x %=MOD;
			n /=2;
		} else {
			r *=x;
			r %=MOD;
			n--;
		}
	return r;
}

#define	Rep0(i, n)	for (int i=0; i<n; i++)
#define	Rep1(i, n)	for (int i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())
void	F(const string pre, const char c, const int n, vector<string> &S) {
	if (0==n) {
		S.push_back(pre);
		return;
	}
	string pre1=pre;
	for (int i=1; i<=n; i++) {
		pre1 +=c;
		F(pre1, c+1, n-i, S);
	}
	return;
}

void	FF(const string pre, const char c, const char d, const char maxc, const int n, vector<string> &S) {
	if (0==n) {
		S.push_back(pre);
		return;
	}
	char cc='a';
	while (maxc-cc>=0) {
		if (cc!=d) {
			string pre1=pre;
			for (int i=1; i<=n; i++) {
				pre1 +=cc;
				if (cc==maxc)
					FF(pre1, c+1, cc, maxc+1, n-i, S);
				else
					FF(pre1, c+1, cc, maxc, n-i, S);
			}
		}
		cc+=1;
	}
	return;
}

int	main() {
	int N;
	cin >>N;
	vector<string> S;
	FF("", 'a', 'z', 'a', N, S);
	Sort(S);
	for (int i=0; i<S.size(); i++)
		cout <<S.at(i) <<endl;
	return 0;
}



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

using namespace std;

int n;
int arr[60];

int main() {
    int i;

    scanf("%d",&n);
    for (i=0;i<n;i++) scanf("%d",&arr[i]);
    int t = 0, mx = -1;
    for (i=0;i<n;i++) if (mx<abs(arr[i])) {
        mx=abs(arr[i]);t=i;
    }
    printf("%d\n",2*n-2);
    for (i=0;i<n;i++) {if (i!=t) printf("%d %d\n",t+1,i+1);}
    if (arr[t]>=0) {for (i=0;i+1<n;i++) printf("%d %d\n",i+1,i+2);}
    else for (i=n-1;i>0;i--) printf("%d %d\n",i+1,i);

    return 0;
}


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

void print(vector<int> ans)
{
  ans.pop_back();
  ans.pop_back();
  for (int i = ans.size() - 1; i >= 0; i--)
  {
    if (ans.at(i) != 0)
      break;
    else
      ans.pop_back();
  }
  reverse(ans.begin(), ans.end());
  for (int a : ans)
  {
    cout << a;
  }
  cout << endl;
}

vector<int> process(vector<int> bm)
{
  for (int i = 0; i < bm.size() - 2; i++)
  {
    if (bm.at(i) > 3)
    {
      bm.at(i) -= 4;
      bm.at(i + 2)++;
    }
    else if (bm.at(i) > 1)
    {
      bm.at(i) -= 2;
      bm.at(i + 1)++;
      bm.at(i + 2)++;
    }
  }
  return bm;
}

vector<int> binary(int64_t n)
{
  vector<int> bin(0);
  for (int i = 0; n > 0; i++)
  {
    bin.push_back(n % 2);
    n /= 2;
  }
  return bin;
}

void pos(vector<int> bin)
{
  vector<int> bm(bin.size() + 10, 0);
  for (int i = 0; i < bin.size(); i++)
  {
    if (i % 2 == 0)
    {
      bm.at(i) += bin.at(i);
    }
    else if (bin.at(i) == 1)
    {
      bm.at(i)++;
      bm.at(i + 1)++;
    }
  }
  print(process(bm));
}

void neg(vector<int> bin)
{
  vector<int> bm(bin.size() + 10, 0);
  for (int i = 0; i < bin.size(); i++)
  {
    if (i % 2 == 1)
    {
      bm.at(i) += bin.at(i);
    }
    else if (bin.at(i) == 1)
    {
      bm.at(i)++;
      bm.at(i + 1)++;
    }
  }
  print(process(bm));
}

int main()
{
  int64_t N;
  cin >> N;
  if (N == 0)
  {
    cout << "0" << endl;
  }
  else if (N > 0)
  {
    pos(binary(N));
  }
  else
  {
    N *= -1;
    neg(binary(N));
  }
}

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

int main()
{
    int n;
    cin >> n;
    string s[102];
    int p = 0;
    for(int i = 0; i < n; i++){
        cin >> s[i];
        if(s[i] == "A") p++;
        else p--;
        if(p < 0){
            cout << "NO" << endl;
            return 0;
        }
    }
    if(p) cout << "NO" << endl;
    else cout << "YES" << endl;
}




Measured memory_bytes: 3168
# coding: utf-8

# https://atcoder.jp/contests/abc087/tasks/arc090_a
# 18:20-18:26 done


def main():
    N = int(input())
    A = [None] * 2
    A[0] = list(map(int, input().split()))
    A[1] = list(map(int, input().split()))

    candidates = [None] * N
    value = 0
    for j in range(N):  # jで下段へ
        value += A[0][j]
        candidates[j] = value + sum(A[1][j:])
    
    return max(candidates)


print(main())


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x) \
	for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
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;
}
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}" << endl;
	
	return os;
}
template <class T, class U>
istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >> p.second;
	return is;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
	rep(i, v.size()) { is >> v[i]; }
	return is;
}
const long long INFLL = 1LL << 60;
const int INF         = 1 << 30;
const double PI       = acos(-1);
ll mod                = 998244353LL;
int n;
long long modpow(long long a, long long n, long long mod = (1LL << 62)) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

int main() {
	int s;
	ll ans = 0LL;
	cin >> n >> s;
	Vi a(n);
	cin >> a;
	// vector<vector<bool>> dp(n + 1, vector<bool>(s + 1, false));  // can
	// reach?
	VV res(n + 1, V(s + 1, 0LL));
	//	dp[0][0] = true;
	res[0][0] = 1;
	sort(all(a));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= s; j++) {
			//		dp[i + 1][j] = true;
			res[i + 1][j] += res[i][j] * 2LL;
			res[i + 1][j] %= mod;

			if (j >= a[i]) {
				//	dp[i + 1][j] = true;
				res[i + 1][j] += res[i][j - a[i]];
				res[i + 1][j] % mod;
			}
		}
	}

	// clog << dp << endl;
		//clog << res << endl;
	cout << res[n][s]%mod << endl;
}
/*
3000*3000
深さ優先探索
jが変われば使われたことを指す
*/

Measured memory_bytes: 73716
#include <iostream>

using namespace std;

const string ACGT = "ACGT";

int main() {
  string s;
  cin >> s;
  int cnt = 0, mx = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (ACGT.find(s[i]) + 1) cnt++;
    else {
      mx = max(mx, cnt);
      cnt = 0;
    }
  }
  mx = max(mx, cnt);
  cout << mx << endl;
}


Measured memory_bytes: 256
S = input()

C_S = S[2 : len(S) - 1]

#flag = True
if S[0] != 'A':
    #flag = False
    print('WA')
    quit()
    #break
if not 'C' in C_S and C_S.count('C') != 1:
    #flag = False
    #break
    print('WA')
    quit()
c_index = S.index('C')
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in range(len(S)):
    if i == 0 or i == c_index:
        continue
    elif S[i] not in alpha:
        #flag = False
        #break
        print('WA')
        quit()
    else:
        continue
print('AC')

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main () {
    
    int n;
    int cards[4][13] = {{}};
    char suits[4] = {'S','H','C','D'};
    
    char a;
    int x;
    
    cin >> n;
    
    for (int k = 0; k < n; k ++) {
        
        cin >> a >> x;
        
        if (a == 'S') {
            
            cards[0][x-1] = 1;
            
        } else if (a == 'H') {
            
            cards[1][x-1] = 1;
            
        } else if (a == 'C') {
            
            cards[2][x-1] = 1;
            
        } else if (a == 'D') {
            
            cards[3][x-1] = 1;
            
        }
        
    }
    
    
    for (int i = 0; i < 4; i ++) {
        
        for (int j = 0; j < 13; j ++) {
            
            if (cards[i][j] == 0) {
                
                cout << suits[i] << ' ' << j + 1 << endl;
                
            }
            
        }
        
    }
    
}



Measured memory_bytes: 3044
#include <iostream>
#include <vector>
#include <queue>
#define INF 1000000
using namespace std;

class vertex{
public:
  class edge{
  public:
    int to;
    int weight;
    edge(int to, int weight){
      this->to = to;
      this->weight = weight;
    }
  };

  vector<edge> edges;
  int num;
  int dis;

  vertex(){
    n++;
    vertexes.push_back(this);
  }

  bool operator< (const vertex& v) const{
    return dis < v.dis;
  }

  bool operator> (const vertex& v) const{
    return dis > v.dis;
  }

  static void dijkstra(int start){
    //距離の初期化
    for(int i=0; i<n; i++) vertexes[i]->dis=INF;
    vertexes[start]->dis=0;

    //プライオリティキューを初期化、始点を格納
    priority_queue<vertex, vector<vertex>, greater<vertex> > pq; pq.push(*vertexes[start]);


    while(!pq.empty()){
      vertex now = pq.top(); pq.pop(); //キューの先頭をポップ
      if(now.dis>vertexes[now.num]->dis) continue;

      //ポップしたキューの頂点集合について最短距離更新
      for(int i=0; i<now.edges.size(); i++){
        int newDis = now.dis+now.edges[i].weight;
        vertex* next = vertexes[now.edges[i].to];
        if(newDis < next->dis){
          next->dis = newDis;
          pq.push(*next);
        }
      }

    }


  }

  static void print(){
    for(int i=0; i<n; i++){
      cout << vertexes[i]->num << " " << vertexes[i]->dis << endl;
    }
  }
private:
  static int n;
  static vector<vertex*> vertexes;
};

int vertex::n=0;
vector<vertex*> vertex::vertexes;

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

  vertex graph[n];

  //入力を隣接リストのようなものに格納
  int v, k, to, weight;
  for(int i=0; i<n; i++){
    cin >> v >> k;
    graph[i].num=v;
    for(int j=0; j<k; j++){
      cin >> to >> weight;
      vertex::edge e(to, weight);
      graph[v].edges.push_back(e);
    }
  }

  vertex::dijkstra(0); //0始点のダイクストラ法

  vertex::print();

  return 0;
}



Measured memory_bytes: 3240
#include <bits/stdc++.h>
using namespace std;
#define LL long long 
#define LLU long long unsigned
#define rarr(arr, n) for(int aab = 0; aab < n; aab++){cin >> arr[aab];}
#define parr(arr, n) for(int aab = 0; aab < n; aab++){cout << arr[aab] << " ";}
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n";

#define freopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);ios_base::sync_with_stdio(0);cin.tie(0);

int main(){
	int x;
	for(int i = 1; i <= 5; i++){
		cin >> x;
		if(x == 0){
			cout << i;
			return 0;
		}
	}
}

Measured memory_bytes: 3592
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 9e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class FLCS {
public:
	void solve(std::istream& in, std::ostream& out)
	{
        string s, t;
        in >> s >> t;
        int slen = s.length();
        int tlen = t.length();

        vector<vector<ll>> dp(slen+1, vector<ll>(tlen+1, 0LL));
        s = " " + s;
        t = " " + t;

        for(int i=0; i<slen; i++){
            for(int j=0; j<tlen; j++){
                if(s[i+1] == t[j+1]){
                    dp[i+1][j+1] = dp[i][j] + 1;
                }else{
                    dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
                }
            }
        }

        string res = "";
        int tpos = tlen, spos = slen;
        while(tpos > 0 && spos > 0){
            if(s[spos] == t[tpos]){
                res = s[spos] + res;
                tpos--; spos--;
            }else{
                if(dp[spos-1][tpos] > dp[spos][tpos-1]) spos--;
                else tpos--;
            }
        }

        out << res << endl;
	}
};


int main() {
	FLCS solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

long aps(long a, long d, long n) {
  return n * (2 * a + (n - 1) * d) / 2;
}

int main() {
  int N;
  cin >> N;
  long ans = aps(1, 1, N);
  ans -= aps(3, 3, N / 3);
  ans -= aps(5, 5, N / 5);
  ans += aps(15, 15, N / 15);
  cout << ans << "\n";
}

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

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

using namespace std;

using pii = pair<int, int>;

int main() {
    int N, M;
    cin >> N >> M;
    map<int, int> c;
    REP(i, N) {
        int X;
        cin >> X;
        ++c[X];
    }

    vector<int> one(M, 0);
    vector<int> two(M, 0);
    for (pii p: c) {
        int X, freq;
        tie(X, freq) = p;
        one[X % M] += freq % 2;
        two[X % M] += freq / 2;
    }

    int result = 0;
    
    REP(i, M) {
        if (i > M - i) {
            break;
        }
        int j = (M - i) % M;
        if (i != j) {
            int k = min(one[i], one[j]);
            result += k;
            one[i] -= k;
            one[j] -= k;
        } else {
            int k = one[i] / 2;
            result += k;
            one[i] -= 2 * k;
        }
    }

    REP(i, M) {
        int j = (M - i) % M;
        int k = min(one[i], 2 * two[j]);
        result += k;
        one[i] -= k;
        two[j] -= (k + 1) / 2;
    }

    REP(i, M) {
        int k = two[i];
        result += k;
        two[i] -= k;
    }

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 5760
//bismillahir rahmanir rahim            //Author:Fayed Anik

#include <bits/stdc++.h> 

using namespace std;


#define         ll                         long  long
#define         lf                         double 
#define         pb(x)                      push_back(x)
#define         ull                        unsigned long long
#define         sfl(a)                     scanf("%lld",&a)
#define         sf(a)                      scanf("%d",&a)
#define         pf(a)                      printf("%d\n",a)
#define         pfl(a)                     printf("%lld\n",a)
#define         pdl(a)                     printf("%llf\n",a)
#define         FOR(x,n)                   for(ll x=1;x<=n;++x)
#define         vii                        vector< ll > v
#define         pi                         3.14159265359
#define         mex                        10000000
#define         pii                        pair< ll , ll >
#define         mem(m,a)                   memset( m, a,sizeof m)
#define         mp(a,b)                    make_pair(a,b)
#define         maxn                       100000
#define         mod                        1000000007
#define         INF                        1e17
#define         f1                         first
#define         f2                         second
#define         all(v)                     v.begin(),v.end()
#define         PI                         acos(-1)
#define         printminusone              printf("-1\n")
#define         bug                        printf("bug")

vector < ll > v;
map <ll,ll>mm;
int main(){
	ll n,m,k,x,t;
	sfl(n),sfl(m),sfl(k);
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			mm[i]=1;
			mm[n/i]=1;
		}
	}
	for(ll i=1;i*i<=m;i++){
		if(m%i==0){
			if(m/i==i){
				if(mm[i]==1){
					v.pb(i);
				}
			}
			else{
				if(mm[i]==1){
					v.pb(i);
				}
				if(mm[m/i]==1){
					v.pb(m/i);
				}
			}
		}
	}

	sort(all(v));
	cout << v[v.size()-k] << endl;
}	



Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		while(H!=0&&W!=0){
			for(int i=0;i<H;i++){
				for(int j=0;j<W;j++){
					if(i%2==0){
						if(j%2==0){
							System.out.print("#");
						}else{
							System.out.print(".");
						}
					}else{
						if(j%2==0){
							System.out.print(".");
						}else{
							System.out.print("#");
						}
					}
				}
				System.out.println("");
			}
			System.out.println("");
			H = sc.nextInt();
			W = sc.nextInt();
		}
	}
}

Measured memory_bytes: 25748
#include <stdio.h>
#include <math.h>

int main(void){
    /*宣言部*/
    double x1=0.0, y1=0.0, x2=0.0, y2=0.0;    /*x1,y1:P1(x, y) x2,y2:P2(x, y)*/
    
    /*入力部*/
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);   /*入力を読み取る*/
    
    /*計算・出力部*/
    printf("%f", sqrt(pow((x2-x1), 2)+pow((y2-y1), 2)));    /*直角三角形斜辺の計算と同時に出力*/
    
    return 0;
}

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

bool find( string& s, int si, string& op, int x, int y ) {
	if( si >= s.size() ) {
		return x == y;
	}

	int a = s[si] - '0';

	if( find( s, si+1, op, x+a, y ) ) {
		op += '+';
		return true;
	}
	else if( find( s, si+1, op, x-a, y ) ) {
		op += '-';
		return true;
	}

	return false;
}

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

	string s;
	cin >> s;

	string op;
	find( s, 1, op, s[0] - '0', 7 );

	for( int i = 0; i < 3; ++i ) {
		cout << s[i] << op[2-i];
	}

	cout << s[3] << "=7" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cassert>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
#include "limits.h"
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;
  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0)) {
    return 0;
  }
  long long x = 1;
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P=std::pair<long long,long long>;

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

  ll n;
  std::cin>>n;

  std::vector<P> robot(n);

  rep(i,0,n){
    ll x,l;
    std::cin>>x>>l;
    robot[i]={x+l,x-l};
  }

  std::sort(all(robot));

  ll now=-MOD;

  ll cnt=0;

  for(P e:robot){
    if(now<=e.second){
      cnt++;
      now=e.first;
    }
  }

  std::cout<<cnt<<"\n";

  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define nl '\n' 
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pii pair <int,int>
ll mod=1000000007;
int main()
{
	fast;
	ll n;cin>>n;
	ll a[n],pSum[n]={0};
	ll sum=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
		sum=sum%mod;
		pSum[i]=sum;
	}
	ll ans=0;
	for(int i=0;i<n;i++)
	{
		ans+=((a[i]%mod)*(pSum[n-1]-pSum[i])%mod)%mod;
		ans=ans%mod;
	}
	cout<<(ans+mod)%mod;

}

Measured memory_bytes: 6740
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string.h>
#include<set>
#include<fstream>
#include<map>
#include<string>
#include <stdio.h>
#include<bitset>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#include<climits>
#include<functional>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll>vl;
typedef vector<int>vi;
typedef vector<bool>vb;
typedef vector<double>vd;
typedef vector<char>vc;
typedef vector<string>vs;
#define MP make_pair
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define EPS 1e-9
#define PI 3.14159265359
const ll mod = 1000000007;
const ll OO = (ll)1e9;
const int dx[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
const int dy[] = { 1, 0, -1, 0, 1, -1, -1, 1 };
ll gcd(ll a, ll b){ if (b == 0){ return a; }return gcd(b, a % b); }
ll fast_power(ll base, ll power){
	if (power == 0)
		return 1;
	if (power == 1)
		return (base % mod);
	if (power % 2 == 0)
		return (fast_power(((base*base) % mod), power / 2LL) % mod);
	else return ((base*fast_power(((base*base) % mod) % mod, power / 2LL)) % mod);
}
//#pragma warning (disable : 4996)
void Qalbaz()
{

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(3);
}

int main(){

	Qalbaz();

	int k, s;
	cin >> k >> s;
	int x, y, z;
	int cnt = 0;
	for (int i = 0; i <= k; i++)
	{
		x = i;
		for (int j = 0; j <= k; j++)
		{
			y = j;
			z = s - (x + y);
			if (z >= 0 && z <= k)
				cnt++;
		}
	}
	cout << cnt;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#define nummax 110000
typedef long long ll;
using namespace std;


int main() 
{
	ll N, micount = 0, A[nummax], i, absmin = pow(10, 12), Aabs, sum = 0;
	cin >> N;
	for (i = 1; i <= N; i++)
	{
		cin >> A[i];
		Aabs = abs(A[i]);
		absmin = min(Aabs, absmin);
		sum += Aabs;
		if (A[i] < 0)
			micount++;
	}
	if (micount % 2 == 1)
		sum -= absmin * 2;
	cout << sum << endl;
}

Measured memory_bytes: 1024
n = int(input())
v = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
ans = 0
for i in range(n):
    # v-c > 0 を取得
    point = v[i]-c[i]
    if(point > 0):
        ans += point
        
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long long LD;
typedef pair<int,int> PII;
const int N=503001;
const int M=2*N;
const LL MOD1=98764321261LL;
const LL MOD=998244353LL;

inline int lowbit(int x){
    return x&(-x);
}

struct fenwick {
    LL a[N];
    int n;
    void init(int n){
        for(int i=0;i<=n;++i)
            a[i]=0;
        this->n=n;
    }
    void add(int x,LL v) {
        for(int i=x;i<=n;i+=lowbit(i))
            a[i]+=v;
    }
    LL query(int x) {
        LL ret=0;
        for(int i=x;i;i^=lowbit(i))
            ret+=a[i];
        return ret;
    }
    void rangeadd(int l,int r,LL v) {
        add(l,v);
        add(r+1,-v);
    }
    LL rangequery(int l,int r) {
        l=max(l,1);
        r=min(r,n);
        if(r<l)return 0;
        LL ret=query(r);
        ret-=query(l-1);
        return ret;
    }
};

inline LL powmod(LL x,LL y,LL MOD){
    LL ret=1;
    while(y){
        if(y&1LL)ret=ret*x%MOD;
        x=x*x%MOD;
        y=y>>1;
    }
    return ret;
}

struct graph{
    int head[N],next[M],to[M];
    int tot;
    inline void init(int n){
        for(int i=0;i<=n;++i)
            head[i]=-1;
        tot=0;
    }
    inline void addedge(int x,int y){
        to[tot]=y;
        next[tot]=head[x];
        head[x]=tot;
        ++tot;
    }
};

struct point{
    LD x,y;
    point(){}
    point(LD x,LD y):x(x),y(y){}

    void read(){
        scanf("%lld%lld",&x,&y);
    }

    point operator + (const point &rhs)const{
        return point(x+rhs.x,y+rhs.y);
    }

    point operator - (const point &rhs)const{
        return point(x-rhs.x,y-rhs.y);
    }

    LD operator ^ (const point &rhs)const{
        return x*rhs.y-y*rhs.x;
    }

    bool operator < (const point &rhs)const{
        if(y!=rhs.y)return y<rhs.y;
        return x<rhs.x;
    }
};

LL phi(LL x)
{
    LL res=x;
    for(LL i=2;i*i<=x;++i)
    {
        if(x%i==0)
        {
            res=res/i*(i-1);
            while(x%i==0) x/=i;
        }
    }
    if(x>1) res=res/x*(x-1);
    return res;
}


int n,m,k;
char s[N];

int main(){
    int cases=1;
    //init();
    //scanf("%d",&cases);
    for(int iii=1;iii<=cases;++iii){
        scanf("%s",s);
        n=strlen(s);
        bool ans=true;
        for(int i=0;i<n;++i){
            if(s[i]!=s[n-1-i])ans=false;
        }
        for(int i=0;i<n/2;++i){
            if(s[i]!=s[n/2-1-i])ans=false;
        }
        for(int i=0;i<n/2;++i){
            if(s[n/2+1+i]!=s[n-1-i])ans=false;
        }
        if(ans)
            puts("Yes");
        else
            puts("No");
    }



}
/*
1
4 8
1 2 1
2 3 1
3 4 1
4 1 1
1 2 2
2 3 2
3 4 2
4 1 2
*/


Measured memory_bytes: 256
import java.util.Scanner;

public class Main 
{
	
	public static void main(String[] args)
	{
		
		Scanner sc = new Scanner(System.in);
		
		String a = sc.next();
		
		sc.close();
		
		if(Character.isUpperCase(a.charAt(0)))
		{
		    System.out.println("A");
		}
		else {
		    System.out.println("a");
		}
		
	}

}

Measured memory_bytes: 27004
#include <stdio.h>

int main(void)
{
  long long int a,b,c,d;

  scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
  if(a*b<c*d)
  {
    printf("%lld\n",c*d);
  }
  else
  {
    printf("%lld\n",a*b);
  }
  return 0;

}

Measured memory_bytes: 128
#include <iostream>

int aw(int x) {
    return std::max(0, 4 - x) * 100000;
}

int main() {
    int x, y;
    std::cin >> x >> y;

    int ans = aw(x) + aw(y);
    if (x == 1 && y == 1) ans += aw(0);
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int n;
    cin >> n;
    ll ans = 0;
    vector<vector<ll>> counts(10, vector<ll>(10, 0));
    for (int i = 1; i <= n; ++i)
    {
        int k = i;
        int lower = i % 10;
        int digits = (int)log10(i);
        k = (int)(k / pow(10, digits));

        counts[k][lower]++;
    }

    for (int i = 1; i < 10; ++i)
    {
        for (int j = 1; j < 10; ++j)
        {
            ans += counts[i][j] * counts[j][i];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char n[] = sc.nextLine().toCharArray();
        int sum = 0;
        for(char c: n){
            sum += Character.getNumericValue(c);
        }
        if(sum % 9 == 0){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }    
}


Measured memory_bytes: 41576
def counter(value):
    count = 0
    while value % 2 == 0:
        count += 1
        value /= 2

    return count

n = int(input())

a = list(map(int, input().split()))

count = 0

for i in range(n):
    if a[i] % 2 == 0:
        count += counter(a[i])
        
print(count)


Measured memory_bytes: 4148
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(Type, ...)  Type __VA_ARGS__; input(__VA_ARGS__)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
inline i64  sigma(i64 n)            { return (n * (n + 1) >> 1); }
inline i64  updiv(i64 a, i64 b)     { return (a + b - 1) / b; }
inline i64  sqr(i64 n)              { return n * n; }
inline string to_string(char c)     { return string(1, c); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

inline void input() {}
template <class Head, class... Tail>
inline void input(Head &head, Tail&... tail) { cin >> head; input(tail...); }

inline void print() { cout << "\n"; }
template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

string N;
int K;

i64 dp[105][2][5];

i64 rec(int k = 0, bool tight = true, int non0cnt = 0)
{
    if (non0cnt > K) { return 0; }
    if (k >= int(N.size())) {
        return non0cnt == K;
    }

    const int x = N[k] - '0';
    const int r = (tight ? x : 9);

    i64 &res = dp[k][tight][non0cnt];
    if (~res) return res;
    res = 0;

    reps(i, 0, r) {
        res += rec(k+1, tight && (i == r), non0cnt + (i != 0 ? 1 : 0));
    }

    return res;
}

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

    input(N, K);

    memset(dp, -1, sizeof(dp));

    print(rec());

    return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let s: String = read();
    let t: String = read();
    let mut ans = String::new();

    for i in 0..n {
        ans += &s[i..i + 1];
        ans += &t[i..i + 1];
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
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();
    if(a < b) {
      System.out.println("a < b");
    } else if(a > b) {
      System.out.println("a > b");
    } else {
      System.out.println("a == b");
    }
  }
}



Measured memory_bytes: 26220
#include<stdio.h>
#include <stdlib.h>

double W, v[100001] = { 0 }, w[100001] = { 0 };
int V[100001] = { 0 };

int c(const void* p, const void* q) {
	if ((double)v[*(int*)p] / w[*(int*)p] > (double)v[*(int*)q] / w[*(int*)q])return -1;
	return 1;
}

int main() {
	int N, i;
	double  x = 0;

	scanf("%d %lf", &N, &W);

	for (i = 0; i < N; i++) {
		scanf("%lf %lf", &v[i], &w[i]);
		V[i] = i;
	}

	qsort(V, N, sizeof(int), c);

	for (i =0; i<N; i++) {
		if (W - w[V[i]] > 0) {
			W -= w[V[i]];
			x += v[V[i]];
		}
		else {
			x += v[V[i]] / w[V[i]] * W;
			break;
		}
	}

	printf("%f\n", x);

	return 0;
}


Measured memory_bytes: 3968
import sys,bisect as bs,collections as cl,heapq as hq
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

n,q = m()

data = [l() for i in range(q)]

edges = [[] for i in range(n)]

for a,b,c in data:
    edges[a-1].append([b-1,c])
    edges[b-1].append([a-1,-c])

num = [0 for _ in range(n)]

Ma,mi = 0,0

vi = [False for i in range(n)]
ans = 0

for i in range(n):
    if vi[i]:
        continue
    stack = [i]
    vi[i] = True
    while stack:
        v = stack.pop()
        for e,r in edges[v]:
            if not vi[e]:
                num[e] = num[v] + r
                stack.append(e)
                vi[e] = True

for i in range(n):
    if num[i] < mi:
        mi = num[i]
    elif num[i] > Ma:
        Ma = num[i]
    for e,r in edges[i]:
        if num[i] + r != num[e]:
            ans = -1
            break
    else:
        continue
    break
else:
    print("Yes")
    exit()
print("No")







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

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

using namespace std;

typedef long long ll;

#define MAX 100010
ll N,Q,L;
ll x[MAX],a,b;

int nex[MAX][80];

void compute() {
  rep(i,N) {
    nex[i][0] = ( upper_bound(x,x+N,x[i]+L) - x ) - 1;
    assert( nex[i][0] != 0 );
  }

  rep(j,70) rep(i,N) nex[i][j+1] = nex[nex[i][j]][j];
  cin >> Q;
  rep(_,Q) {
    cin >> a >> b;
    --a, --b;
    if( !( a < b ) ) swap(a,b);
    ll cost = 0;
    for(int i=69;i>=0;--i) {
      if( nex[a][i] < b ) {
	cost += (1LL<<i);
	a = nex[a][i];
      }
    }
    cout << cost+1 << endl;
  }
}

int main() {
  cin >> N;
  rep(i,N) cin >> x[i];
  cin >> L;
  compute();
  return 0;
}


Measured memory_bytes: 32896
using System;

public class hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        Array.Sort(a);
        Array.Reverse(a);
        var mmax = 0d;
        var cd = 0;
        for (int i = 0; i < n; i++)
            for (int j = i+1; j < n; j++)
            {
                if (i == 0 && j == 1) cd = a[2] + a[3];
                else if (i == 0 && j == 2) cd = a[1] + a[3];
                else if (i == 0 && j >= 3) cd = a[1] + a[2];
                else if (i == 1 && j == 2) cd = a[0] + a[3];
                else if (i == 1 && j >= 3) cd = a[0] + a[2];
                else if (i >= 2 ) cd = a[0] + a[1];
                mmax = Math.Max(mmax, (double)cd / (a[i] - a[j]));
            }
        Console.WriteLine("{0:0.000000}",mmax);
    }
}

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

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n, h, w;
	cin>>h>>w>>n;
	vector<int> a(n);
	for(auto &x : a){
		cin>>x;
	}
	vector<vector<int> > ans(h, vector<int>(w));
	int ind = 0;
	for(int i = 0; i < h; i++){
		int st, en, di;
		if(i&1){
			st = w - 1; en = -1; di = -1;
		}else{
			st = 0; en = w; di = 1;
		}
		for(int j = st; j != en; j += di){
			ans[i][j] = ind + 1; a[ind]--;
			if(!a[ind])ind++;
		}
	}
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			cout<<ans[i][j]<<" ";
		}
		cout<<'\n';
	}


	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<int>> mat;

int N;
ll K;
vec A,F;

bool possible(ll k){
    ll rev=0;
    for(int i=0;i<N;i++){
        if(A[i]-k/F[i]>0){
            rev+=A[i]-k/F[i];
        }
    }
    return rev<=K;
}

ll binary_search(ll l,ll r){
    if(r-l==1){
        return r;
    }
    ll m=(l+r)/2;
    if(possible(m)){
        return binary_search(l,m);
    }
    else{
        return binary_search(m,r);
    }
}
int main(){
    cin>>N>>K;
    A.resize(N);F.resize(N);
    ll sum=0;
    for(int i=0;i<N;i++){
        cin>>A[i];
        sum+=A[i];
    }
    sort(A.begin(),A.end());

    for(int i=0;i<N;i++){
        cin>>F[i];
    }
    sort(F.begin(),F.end(),greater<ll>());

    if(sum<=K){
        cout<<0<<endl;
        return 0;
    }
    cout<<binary_search(0,pow(10,18))<<endl;
    return 0;
}

Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main(int argc, char* argv[]) {
  long long N, K;
  cin >> N >> K;

  vector<int> x;
  map<int, long long> m;
  for (int i = 0; i < N; ++i) {
    int a, b;
    cin >> a >> b;
    if (m.find(a) == m.end()) {
      x.push_back(a);
      m[a] = 0;
    }
    m[a] += b;
  }

  sort(x.begin(), x.end());

  long long cur = 0;
  for (int i = 0; i < x.size(); ++i) {
    cur += m[x[i]];
    if (cur >= K) {
      cout << x[i] << endl;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 4476
#include <stdio.h>

void fact(int n);

int main(void)
{
	int n;
	
	scanf("%d", &n);
	fact(n);
	
	return (0);
}

void fact(int n){
	int array[100] = {1}, i, j, not0 = 0;
	
	for (i = 2; i <= n; i++){
		for (j = 0; j < 100; j++){
			array[j] *= i;
		}
		
		for (j = 0; j < 100; j++){
			while (array[j] / 100 > 0){
				array[j] -= 100;
				array[j+2]++;
			}
			
			while (array[j] / 10 > 0){
				array[j] -= 10;
				array[j+1]++;
			}
		}
	}
	
	for (i = 99; i >= 0; i--){
		if (array[i] != 0){
			not0 = 1;
		}
		if (not0 == 1){
			printf("%d", array[i]);
		}
	}
	
	puts("");		
}

Measured memory_bytes: 604
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class User
    {
        internal int color;
        internal List<int> friends;

        public User()
        {
            color = -1;
            friends = new List<int>();
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int n = input[0], m = input[1];

            User[] users = new User[n];
            for (int i = 0; i < n; i++) users[i] = new User();

            for (int i = 0; i < m; i++)
            {
                input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                int a = input[0], b = input[1];

                users[a].friends.Add(b);
                users[b].friends.Add(a);
            }

            for (int i = 0, id = 1; i < n; i++)
            {
                if (users[i].color == -1) DFS(users, i, id++);
            }

            StringBuilder sb = new StringBuilder();
            int q = int.Parse(Console.ReadLine());

            for (int i = 0; i < q; i++)
            {
                input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                int s = input[0], t = input[1];

                sb.AppendLine(users[s].color == users[t].color ? "yes" : "no");
            }
            Console.Write(sb);
        }

        static void DFS(User[] u, int s, int t)
        {
            Stack<User> stk = new Stack<User>();
            u[s].color = t;
            stk.Push(u[s]);

            while (stk.Count > 0)
            {
                User temp = stk.Pop();

                foreach (var friend in temp.friends)
                {
                    if (u[friend].color == -1)
                    {
                        u[friend].color = t;
                        stk.Push(u[friend]);
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 27732
#include <iostream>
#include <string>
#include <queue>
#include <utility>

using namespace std;

int main(){
    int n, q, time = 0;
    vector<pair<string, int>> done;
    queue<pair<string, int>> que;
    cin >> n;
    cin >> q;
    for(int i = 0; i < n; i++){
        pair<string, int> p;
        cin >> p.first;
        cin >> p.second;
        que.push(p);
    }
    while(!que.empty()){
        pair<string, int> p = que.front();
        que.pop();
        if(p.second <= q){
            done.push_back(make_pair(p.first, time + p.second));
            time += p.second;
        }else{
            p.second -= q;
            que.push(p);
            time += q;
        }
    }
    for(pair<string, int> p: done){
        cout << p.first << " " << p.second << endl;
    }
    return 0;
}


Measured memory_bytes: 6980
n = gets.to_i
h = gets.split.map(&:to_i)

cnt = 0
ans = 0
n.times do |i|
    if i+1 < n and h[i] >= h[i+1]
        cnt += 1
    else
        ans = cnt if ans < cnt
        cnt = 0
    end
end

puts ans

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

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

    int cur = 0;
    int op, k;

    while(q-- > 0){
        cin >> op >> k;
        if(op == 0){
            cout << (cur+k-1)%n+1 << endl;
        }else{
            cur = (cur+k)%n;
        }
    }

    return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

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

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

int main()
{
	ll t;
	cin >> t;
	for(int i = 0; i < t; i++){
		ll a,b,c,d;
		cin >> a >> b >> c >> d;

		if(a<b){
			cout << "No" << endl;
		}else if(b>d){
			cout << "No" << endl;
		}else if(b<=c){
			cout << "Yes" << endl;
		}else{
			ll q = gcd(b,d);
			if(b-q+a%q>c) cout << "No" << endl;
			else cout << "Yes" << endl;
 		}
	}

	return 0;
}

Measured memory_bytes: 256
N, M = list(map(int, input().split(' ')))

num_list = [-1 for i in range(N)]

false_flag = False

sc = []
for i in range(M):
    sc.append(list(map(int, input().split(' '))))

for i in range(M):
    s, c = sc[i][0], sc[i][1]

    if num_list[s-1] == -1:
        num_list[s-1] = c
    else:
        if num_list[s-1] == c:
            pass
        else:
            false_flag = True
if num_list[0] == 0:
    if N > 1:
        false_flag = True

if false_flag == False:
    for i in range(N):
        if num_list[i] == -1:
            if i == 0:
                if N > 1:
                    num_list[0] = 1
                else:
                    num_list[0] = 0
            else:
                num_list[i] = 0
    print(*num_list, sep='')
else:
    print(-1)

Measured memory_bytes: 3064