akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define VIN(n,v) for(int64_t i=0;i<(n);i++){cin >> (v).at(i);}

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  string s;
  cin >> s;
  I dp[s.size()][13];
  REP(i,s.size()){
    REP(j,13){
      dp[i][j] = 0;
    }
  }
  REP(i,s.size()){
    int64_t c = s.at(i);
    if (i==0){
      if (c == '?'){
        REP(j,10){
          dp[i][j]++;
        }
      }else{
        int64_t ci = ctoi(c);
        dp[i][ci]++;
      }
    }else{
      REP(j,13){
        if (c == '?'){
          REP(k,10){
            int64_t ci = j*10 + k;
            dp[i][ci%13] += dp[i-1][j] % MOD;
            dp[i][ci%13] %= MOD;
          }
        }else{
          int64_t ci = j*10 + ctoi(c);
          dp[i][ci%13] += dp[i-1][j] % MOD;
          dp[i][ci%13] %= MOD;
        }
      }
    }
  }
  cout << dp[s.size()-1][5] << endl;
  return 0;
}



Measured memory_bytes: 10624
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin)-1;i>=(end);i--)
#define IREP(i, n) IFOR(i,n,0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" <<; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;


template<typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) { REP(i, a.size()) {cin >> a[i]; a[i]--;} }

ll mod = 1000000007;

ll gcd(ll n, ll m) {
	if (n > m) swap(n, m);
	if (m % n == 0) return n;
	else {
		return gcd(n, m % n);
	}
}

int main()
{
	// 入力
	ll N;
	cin >> N;
	vec A(N, 0);
	REP(i, N) {
		cin >> A[i];
	}

	ll ans = A[N - 1];
	REP(i, N) {
		ans = gcd(ans, A[i]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
Module _20190422

    Sub Main()

        Dim sRead As String = Console.ReadLine()

        Dim iAB As Integer = sRead.Split(" ")(0)
        Dim iBC As Integer = sRead.Split(" ")(1)
        Dim iCA As Integer = sRead.Split(" ")(2)

        Console.WriteLine((iAB * iBC) / 2)

    End Sub

End Module

Measured memory_bytes: 13268
#include<iostream>
#include<vector>
#include<unordered_set>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<string>v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    string prev=v[0];
    bool no=false;
    unordered_set<string>us;
    for(int i=0;i<n;i++){
        if(i!=0){
            if(prev[prev.size()-1]!=v[i][0]){
                no=true;
                break;
            }
            else
            {
                prev=v[i];
            }
        }
        if(us.find(v[i])==us.end()){
            us.insert(v[i]);
        }
        else
        {
            no=true;
            break;
        }
    }
    if(no){
        cout<<"No\n";
    }
    else{
        cout<<"Yes\n";
    }
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <bitset>
#include <unordered_map>
#include <queue>
#include <cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, s, n) for (int i = (int)(s); i < (int)(n); i++)



int main(){
    int r;
    cin >> r;
    int cnt[10][10];
    memset(cnt, 0, sizeof(cnt));
    repn(i,1,r+1){
        string target = to_string(i);
        cnt[target[0] - '0'][target.back() - '0']++;
    }

    ll ans = 0;
    repn(i,1,10) repn(j,1,10) {
        ans += cnt[i][j] * cnt[j][i];
    }
    cout << ans << endl;
}

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

using namespace std;

using ll = long long;

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  if (k & 1LL) {
    cout << b - a << endl;
  } else {
    cout << a - b << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <map>
#include <set>
#include <queue>

#define ll long long
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define PI 3.141592653589
#define MOD 1000000007

using namespace std;

template<typename T> T gcd(T a, T b){ return (a % b)? gcd(b, a%b) : b; }
template<typename T> T lcm(T a, T b){ return a * b / gcd(a, b); }

int power(int a, int m, int p){
    int ans = 1;
    while(m>0){
        if(m&1){
            ans *= a % p;
        }
        a *= a % p;
        m>>=1;
    }
    return ans;
}

int main(void){
    // abc164
    string s;
    cin >> s;

    int n = s.length();
    int a[n];
    int mp[2019] = {0};
    mp[0] = 1; //a0 = 0だから
    ll sub = 0;
    int tenfactor = 1;
    REP(i,n){
        sub += (s[n-i-1] - '0') * tenfactor % 2019;
        tenfactor = tenfactor * 10 % 2019;
        a[i] = sub % 2019;
        sub %= 2019;
        mp[a[i]]++;
    }

    ll ans = 0;
    REP(i,2019) ans += mp[i] * (mp[i]-1) / 2;
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 4500
/*****include*****/
#include <iostream>
#include <fstream>
#include <string>

/*****デバッグ定義*****/
//#define DEBUG
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/

/*****その他関数置き場*****/

/*****main関数*****/
int main(){
	/*****ファイルオープン*****/
#ifdef DEBUG
	ofstream fout("output.txt");
	ifstream fin("input.txt");
	if(!fout || !fin){
		cout << "Can't open the file.\n";
		return;
	}
#endif
	/*****変数置き場*****/
	//string words;
	/*****処理部*****/
	//gets(words.c_str());
	/*int i=0;
	for(int i=0;i<words.length();i++){
		if(islower((int)words[i])){
			words[i] = toupper(words[i]);
		}
	}
	for(int j=0;j<i;j++){
		cout << words[j];
	}*/
	char letter;
	while(1){
		scanf("%c",&letter);
		if(letter == '\n')	break;
		if(islower((int)letter)){
			letter = toupper(letter);
		}
		cout << letter;
	}
	cout << endl;
	/*****処理終了後*****/
#ifdef DEBUG
	fout.close();
	fin.close();
#endif
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> void pr_vec(vector<T> &v, char ep=' '){int n=v.size();REP(ni,n){cout<<v[ni];if(ni!=n-1)cout<<ep;}cout<<endl;};
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    ll A,B,C,K;
    cin >> A >> B >> C >> K;
    
    if(A>=K){
        pr(K);
    }else if(A+B>=K){
        pr(A);
    }else{
        pr(A-(K-(A+B)));
    }
}

Measured memory_bytes: 3624
#include <iostream>
using namespace std;
 
int main() {
    bool card[4][13] = { false };
    int n, temp, s;
    char d, design[] = { 'S', 'H', 'C', 'D' };
 
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> d >> temp;
        for (int j = 0; j < 4; j++) {
            if (d == design[j]) {
                s = j;
                break;
            }
        }
        card[s][temp - 1] = true;
    }
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 13; j++) {
            if (card[i][j] == false) {
                cout << design[i] << ' ' << j + 1 << endl;
            }
        }
    }
}

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

int ans[101];

int main() {
  int N; int T[101];
  cin >> N;
  for ( int i = 1; i <= N; i++ ) cin >> T[i];
  int M; cin >> M;
  int P[101],X[101];
  for ( int i = 1; i <= M; i++ ) cin >> P[i] >> X[i];

  for ( int i = 1; i <= M; i++ ) {
    for ( int j = 1; j <= N; j++ ) {
      if ( P[i] == j ) ans[i] += X[i];
      else ans[i] += T[j];
    }
  }
  for ( int i = 1; i <= M; i++ ) {
    cout << ans[i] << endl;
  }
  return 0;
}


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

using namespace std;
#define rep(i, s, n) for(int i = s;i<n;i++)

int h[101];
int N;

bool isComplete() {
    for (int i = 0; i < N; ++i) {
        if (h[i] != 0) {
            return false;
        }
    }
    return true;
}

int main(void) {
    int step = 0;
    int head = 0;
    cin >> N;

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

    while (!isComplete()) {
        for (int i = 0; i < N; ++i) {
            if (h[i] != 0) {
                head = i;
                break;
            }
        }

        for (int j = head; h[j] != 0 && j < N; ++j) {
            h[j] -= 1;
        }
        step++;
    }
    cout << step << endl;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) (a*a)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

using graph = VVI;

void dfs(graph &g, int node, vector<bool> &visit, deque<int> &q, int mode) {
	for (int i = 0; i < g[node].size(); i++) {
		if (visit[g[node][i]])continue;

		visit[g[node][i]] = true;
		if (mode == 0)q.push_front(g[node][i]);
		else q.push_back(g[node][i]);
		dfs(g, g[node][i], visit, q, mode);
		return;
	}
}

int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	auto g = graph(n);
	vector<bool> visit(n);
	for (int i = 0; i < m; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		u--, v--;
		g[u].PB(v);
		g[v].PB(u);
	}
	int x = 0, y = g[0][0];
	visit[x] = true;
	visit[y] = true;
	deque<int> q;
	q.push_back(x);
	q.push_back(y);
	dfs(g, x, visit, q, 0);
	dfs(g, y, visit, q, 1);
	printf("%d\n", q.size());
	while (!q.empty()) {
		auto tmp = q.front();
		q.pop_front();
		printf("%d ", tmp+1);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 6656
# encoding: utf-8

import sys
from collections import deque


class Solution:
    @staticmethod
    def message_queue():
        # write your code here
        # array_length = int(input())
        _input = sys.stdin.readlines()
        task_num = int(_input[0].split()[0])
        task_time = int(_input[0].split()[1])
        total_time = 0

        task_deque = deque([{'name': i.split()[0], 'time': int(i.split()[1])} for i in _input[1:]])

        while task_deque:
            item = task_deque.popleft()
            if item['time'] <= task_time:
                total_time += item['time']
                print(item['name'], total_time)
            else:
                item['time'] -= task_time
                total_time += task_time
                task_deque.append(item)


if __name__ == '__main__':
    solution = Solution()
    solution.message_queue()

Measured memory_bytes: 29916
import java.util.*;

public class Main {

    private static final Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        String S = scanner.next();
        String T = scanner.next();
        int slen = S.length(), tlen = T.length(), res = 0;
        for (int i = 0; i < slen - tlen + 1; ++i) {
            int cur = 0;
            for (int j = 0; j < tlen; ++j) {
                if (i + j < slen && S.charAt(i + j) == T.charAt(j)) cur += 1;
            }
            res = Math.max(res, cur);
        }
        System.out.println(tlen - res);
    }

}

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

using namespace std;

#define mp make_pair
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forlr(i, l, r) for (int i = int(l); i < int(r); i++)
#define repeat(n) for (int hjfjke = 0; hjfjke < int(n); hjfjke++)
#define all(c) c.begin(), c.end()
#define ll long long

double dp[301][301][301];
bool calced[301][301][301];

int n;

double calc(int a, int b, int c) {
    if (!a && !b && !c)
        return 0;

    if (calced[a][b][c])
        return dp[a][b][c];
    int d = n - a - b - c;

    double res = 0;

    int sum = a + b + c;
    if (a)
        res += calc(a - 1, b, c) * (a / (double)sum);

    if (b)
        res += calc(a + 1, b - 1, c) * (b / (double)sum);

    if (c)
        res += calc(a, b + 1, c - 1) * (c / (double)sum);

    res += 1 / (1 - d / (double)n);

    calced[a][b][c] = true;

    return dp[a][b][c] = res;
}

int32_t main() {
    std::iostream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(10);

    cin >> n;
    int a[] = {0, 0, 0};
    for (int i = 0; i < n; i++) {
        int aa;
        cin >> aa;
        a[aa - 1]++;
    }

    cout << calc(a[0], a[1], a[2]);

    return 0;
}

Measured memory_bytes: 240000
import math
A, B, H, M = list(map(int, input().split()))
omega_H = 2 * math.pi / (12*60)
omega_M = 2 * math.pi / (60)
total_M = H*60+M
Ax = A*math.sin(omega_H*total_M)
Ay = A*math.cos(omega_H*total_M)
Bx = B*math.sin(omega_M*total_M)
By = B*math.cos(omega_M*total_M)
ans = math.sqrt((Ax-Bx)**2 + (Ay-By)**2)
print(ans)

Measured memory_bytes: 9524
#include <stdio.h>
#define N 150
int main(void){
  char s[N];
  char ans[4];
  fgets(s, N, stdin);
  ans[0] = 'A';
  ans[1] = s[8];
  ans[2] = 'C';
  ans[3] = '\0';
  printf("%s\n", ans);
  return 0;
}

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

int k[100000];
signed main() {
	int a;
	while (cin >> a, a) {
		int b = 0;
		for (int c = 0; c < a; c++) {
			int d;
			scanf("%lld", &d);
			b += d;
		}
		for (int g = 0; g < a-1; g++) {
			int h;
			scanf("%lld", &h);
			k[g] = h;
		}
		sort(k, k + a - 1);
		reverse(k, k + a - 1);
		int MAX = b*a;
		for (int l = 0; l < a - 1;l++) {
			a--;
			b += k[l];
			MAX = max(MAX, b*a);
		}
		cout << MAX << endl;
	}
}

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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    print(min(a, b) + min(c, d));

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void) {

	int N, T;

	scanf("%d %d", &N, &T);

	int c[100], t[100];

	int i;

	for (i = 1; i <= N; i++) {

		scanf("%d %d", &c[i], &t[i]);

	}

	int cost = 1001;

	for (i = 1; i <= N; i++) {

		if (t[i] <= T && c[i]<=cost) {


			cost = c[i];

		}

	}

	if (cost == 1001) {

		printf("TLE");

		return 0;

	}

	printf("%d", cost);

	return 0;

}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
int main()
{
	int n,i,j;
	char w[100][11];

	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s",w[i]);
	}

	for(i=0;i<n-1;i++)
		for(j=i+1;j<n;j++){
			if(strcmp(w[i],w[j])==0){
				printf("No\n");
				return 0;
			}
		}
	for(i=0;i<n-1;i++){
		if(w[i][strlen(w[i])-1]!=w[i+1][0]){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}

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

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

int main()
{
    long long a, b, x;
    cin >> a >> b >> x;
    if(a == 0)
    {
        cout << (b / x) + 1 << endl;
    }
    else
    {
        cout << (b / x) - (a - 1) / x << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll mod = 1000000007;
int main() {
	int n;
	cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; i++)
		cin >> p[i];
	ll s, ans = 0;
	for (int i = 1; i < n - 1; i++) {
		s = p[i - 1] + p[i] + p[i + 1] - max({ p[i - 1], p[i], p[i + 1] }) - min({ p[i - 1], p[i], p[i + 1] });
		if (s == p[i])
			ans++;
	}
	cout << ans;
}

Measured memory_bytes: 256
/**
 * Created by hiramekun at 20:44 on 2019-12-08.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll h, w;
    cin >> h >> w;
    int a[h][w], b[h][w];
    ll max_diff = 0;
    rep(i, h) rep(j, w) cin >> a[i][j];
    rep(i, h) rep(j, w) {
            cin >> b[i][j];
            max_diff = max(max_diff, 2 * abs(a[i][j] - b[i][j]) * (h + w) + 10);
        }

    bool dp[h][w][max_diff];
    rep(i, h) rep(j, w) rep(l, max_diff) dp[i][j][l] = false;

    ll mid = max_diff / 2;
    dp[0][0][b[0][0] - a[0][0] + mid] = true;
    dp[0][0][-b[0][0] + a[0][0] + mid] = true;

    rep(i, h) {
        rep(j, w) {
            rep(l, max_diff) {
                if (dp[i][j][l]) {
                    if (i + 1 <= h - 1) {
                        dp[i + 1][j][l + b[i + 1][j] - a[i + 1][j]] = true;
                        dp[i + 1][j][l - b[i + 1][j] + a[i + 1][j]] = true;
                    }
                    if (j + 1 <= w - 1) {
                        dp[i][j + 1][l + b[i][j + 1] - a[i][j + 1]] = true;
                        dp[i][j + 1][l - b[i][j + 1] + a[i][j + 1]] = true;
                    }
                }
            }
        }
    }
    ll ans = ll_inf;
    rep(i, max_diff) {
        if (dp[h - 1][w - 1][i]) ans = min(ans, abs(i - mid));
    }
    cout << ans << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 160512
nmax = 3*10**5
mod = 10**9+7

fac = [1]*nmax
finv = [1]*nmax
inv = [1]*nmax
def ncr_pre():
    for i in range(2,nmax):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod%i] * (mod//i) %mod
        finv[i] = finv[i-1] * inv[i] %mod

def ncr(n,r):
    if n<r:
        return 0
    if n<0 or r<0:
        return 0
    return fac[n]* (finv[r] * finv[n-r] %mod) %mod


ncr_pre()
n,k = map(int,input().split())
ans = 0
for i in range(min(n,k+1)):
    ans+=ncr(n,i)*ncr(i+n-i-1,i)
    ans%=mod
print(ans)


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

int h, w;
vector<string> v;
int dir[4][2] = { { 0,-1 },{ -1,0 },{ 1,0 },{ 0,1 } };
struct node
{
	int x, y;
	int step;
	node(int _x, int _y ):x(_x),y(_y), step(0){}
	node():x(0),y(0),step(0){}
};
bool check(node n)
{
	return n.x >= 0 && n.x < h&&n.y >= 0 && n.y < w&&v[n.x][n.y]!='#';
}
int bfs(node no)
{
	queue<node> q;
	node  t, n;
	v[no.x][no.y] = '#';
	q.push(no);
	while(!q.empty())
	{
		t = q.front();
		q.pop();
		if (t.x == h-1 && t.y == w-1)
			return t.step;
		for(int k=0;k<4;k++)
		{
			n = t;
			n.x += dir[k][0], n.y += dir[k][1];
			if (check(n))
			{
				v[n.x][n.y] = '#';
				n.step++;
				q.push(n);
			}
		}
	}
	return -1;

}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> h >> w;
	v.clear();
	v.resize(h);

	for (int i = 0; i < h; i++)
		cin >> v[i];

	int count = 0;
	for (auto i : v)
		for (auto j : i)
			if (j == '#')
				count++;
	int res=bfs(node(0,0));
	cout << (res!=-1 ? h * w - count -res-1 : -1) << endl;
	return 0;
}

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


namespace _009_PrimeNumber
{
	class Program
	{
		static void Main ( string[] args )
		{
			int[] primeTable = new int[1000000];

			primeTable[2] = 1;

			for (int lp = 3; lp < primeTable.Length; lp++)
			{
				bool isOdd = lp % 2 == 1;

				if (isOdd)
				{
					int number = 3;
					bool isPrimeNumber = true;

					while (number <= Math.Sqrt (lp))
					{
						if (lp % number == 0 || primeTable.Length / 2 < number)
						{
							isPrimeNumber = false;
							break;
						}

						number += 2;
					}

					if (isPrimeNumber)
					{
						primeTable[lp] = primeTable[lp - 1] + 1;
					}
					else
					{
						primeTable[lp] = primeTable[lp - 1];						
					}
				}
				else
				{
					primeTable[lp] = primeTable[lp - 1];						
				}
			}

			string inputStr;
			while ((inputStr = Console.ReadLine ()) != null)
			{
				int index = int.Parse (inputStr);

				int count = primeTable[index];

				Console.WriteLine (count);
			}
		}
	}
}

Measured memory_bytes: 12928
#include <iostream>
#include <cstdio>

using namespace std;

int main(void)
{
	int n, w;
	while (cin >> n >> w, n && w){
		int hist[20] = {0};
		int v, maxv = 0, right = 0;;
		for (int i = 0; i < n; i++){
			cin >> v;
			v /= w;
			hist[v]++;
			maxv = max(maxv, hist[v]);
			right = max(right, v);
		}

		double ret = 0.01;
		for (int i = 0; i <= right; i++){
			ret += (double)hist[i] / maxv * (double)(right - i) / right;
		}
		printf("%.7lf\n", ret);
	}

	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
int main()
{
   //freopen("t5.in","r",stdin);
   //freopen("t5.out","w",stdout);
   //ios::sync_with_stdio(false);
   //cin.tie(0); cout.tie(0);
    int j,m,k;
    long long n,i;
    cin>>n;
    vector<int>g;
    for(i=2;i*i<n;i++)
    {
        if(n%i==0){g.push_back(i);g.push_back(n/i);}
    }
    if(i*i==n)g.push_back(i);
    int sum=0;
    for(i=0;i<g.size();i++)
    {
        long long poi=n;
        while(poi%g[i]==0)poi/=g[i];
        poi%=g[i];
        if(poi==1)sum++;
    }
    for(i=2;i*i<n-1;i++)
    {
        if((n-1)%i==0){sum+=2;}
    }
    if(i*i==n-1)sum++;
    if(n!=2)
    cout<<sum+2;
    else cout<<1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pi pair<ll,ll>
#define pb(b) push_back(b);

int main(){
	ios_base::sync_with_stdio();cin.tie(0);cout.tie(0);
	ll n,m;cin>>n>>m;
	ll dp[(1<<n)];for(int i = 0;  i < (1<<n) ; i ++ )dp[i]=1e16;
	vector<pi>arr;arr.resize(m,{0,0});
	for(int i = 0 ; i < m ; i ++ ){
		cin>>arr[i].first;
		ll b;cin>>b;
		ll dub = 0 ; 
		for(int j = 0 ; j < b ; j ++ ){
			ll c;cin>>c;
			c--;
			dub+= (1<<c);
		}
		arr[i].second = dub;
	}
	dp[0] = 0;
	for(ll mask = 0 ; mask<(1<<n) ; mask++){
		for(int i = 0 ; i < m ; i ++ ){
			ll mask2 = mask|arr[i].second;
			dp[mask2] = min(dp[mask2],dp[mask]+arr[i].first);
		}
	}
	cout<<(dp[(1<<n)-1]==((ll)1e16) ? -1:dp[(1<<n)-1])<<'\n';
	return 0 ; 
}

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

using namespace std;

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

	int x;

	cin >> x;

	if(x % 10 == 7 || (x / 10) % 10 == 7 || (x / 100) % 10 == 7) printf("Yes\n");
	else printf("No\n");
	
	return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main(){
  int D,N;cin>>D>>N;
  int ans=1;
  for(int i=0;i<D;i++)ans*=100;
  if(N!=100)ans*=N;
  else ans*=(N+1);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;


int main() {
    int n,m;
   
 
   cin >> n>>m;
  
   if(n<=5){
      cout << 0 << endl;
   }else if(n>=6&&n<=12){
      cout << m/2 << endl;
   }else{
      cout << m << endl;
   }
  
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
ll const inf=1LL<<62;
typedef vector<int> vi;

// vi solve(int a,int b, int d){

// }

// int main(){
//   int a,b,d;
//   while(cin>>a>>b>>d && a){
//     vi a1=solve(a,b,d);
//     vi a2=solve(b,a,d);
//     vi ans;
//     int s1=a1[0]+a0[1];
//     int s2=a2[0]+a2[1];
//     if(s1!=s2){
//       if(s1<s2)ans=a1;
//       else{
// 	ans=a2;
// 	swap(a2[0],a2[1]);
//       }
//     }else{
//       int p1=a1[0]*x+a1[1]*y;
//       int p2=a2[1]*x+a2[0]*y;
//       if(p1<p2)ans=a1;
//       else {
// 	ans=a2;
// 	swap(a2[0],a2[1]);
//       }
//     }
//     cout << ans[0] << " " << ans[1] << endl;
//   }
// }


typedef pair<int,int> pii;
pii solve(int a, int b, int d){
  //for(int x=0;a*x<=1000;x++){
  //}
   for(int x=0;x < 100000;x++){
     int rest=abs(d-a*x);
     //cout << rest << endl;
     if(rest%b)continue;
     int y=rest/b;
     return pii(x,y);
   }
}

int main(){
  int a,b,d;
  while(cin>>a>>b>>d && a){
    auto a1=solve(b,a,d);
    auto a2=solve(a,b,d);
    auto& ans=min(a1,a2,[](pii const& a, pii const& b){
	return a.first+a.second < b.second+b.first;
      });
    ll tx,ty;
    tie(tx,ty)=ans;
    ll s=tx+ty;
    for(int x=0;x<=s;x++){
      int y=s-x;
      if(a*x + b*y == a*tx+b*ty){
	tx=x;
	ty=y;
      }
    }

    if(&ans == &a2){
      cout << tx << " " << ty << endl;
    }else{
      cout << ty << " " << tx << endl;
    }
  }
}

Measured memory_bytes: 1156
#include <cstdio>
#include <cstring>
using namespace std;

int main(void)
{
    char str[110];
    while (scanf("%s", str) != EOF){
        for (int i = 0; i < strlen(str); i++){
            if (str[i] == '@'){
                for (int j = 0; j < (str[i + 1] - '0'); j++){
                    printf("%c", str[i + 2]);
                }
                i += 2;
            }
            else {
                printf("%c", str[i]);
            }
        }
        printf("\n");
    }
    
    return (0);
}

Measured memory_bytes: 0
using System;

namespace Test
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			// 半角スペース区切り
			string[] input = Console.ReadLine().Split(' ');
			uint n = uint.Parse(input[0]);
			uint x = uint.Parse(input[1]);
			string[] input2 = Console.ReadLine().Split(' ');
			uint[] a = new uint[n];
			// カウント数
			ulong cnt = 0;
			for (int i = 0; i < n; i++)
			{
				a[i] = uint.Parse(input2[i]);
				uint sum = a[i];
				if (i > 0)
				{
					sum = sum + a[i - 1];
				}
				if (sum > x)
				{
					cnt = cnt + (sum - x);
					a[i] = a[i] - (sum - x);
				}
			}
			//出力
			Console.Write(cnt);
		}
	}
}

Measured memory_bytes: 16852
import scala.io.StdIn.readInt
import scala.collection.mutable.ArrayBuffer

object Main extends App {
  var n = 0
  val b = new ArrayBuffer[Int]
  while( {n=readInt;n} != 0 ) {
    val a = new Array[Int](7)
    for(i<-0 until n) {
      val m = readInt
      if(m<10) a(0) += 1
      else if(m>=10 && m<20) a(1) += 1
      else if(m>=20 && m<30) a(2) += 1
      else if(m>=30 && m<40) a(3) += 1
      else if(m>=40 && m<50) a(4) += 1
      else if(m>=50 && m<60) a(5) += 1
      else if(m>=60) a(6) += 1
    }
    b ++= a
  }
  println(b.mkString("\n"))
}

Measured memory_bytes: 99480
import java.util.*;

public class Main{

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] data = new int[n];

    for(int i = 0;i < data.length;i++) data[i] = sc.nextInt();

    Arrays.sort(data);

    double sum = data[0];

    for(int i = 1;i < n;i++){
      sum += data[i];
      sum /= 2;
    }

    System.out.println(sum);

  }

}


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

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

int main() {
	int H, W;
	cin >> H >> W;
	vector<string> s(H);
	for (int i = 0; i < H; i++) {
		cin >> s[i];
	}

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (s[i][j] == '#' && !(i - 1 >= 0 && s[i - 1][j] == '#'
				|| i + 1 < H && s[i + 1][j] == '#'
				|| j - 1 >= 0 && s[i][j - 1] == '#'
				|| j + 1 < W && s[i][j + 1] == '#')) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [u64; n-1],
    }
    let mut v: Vec<u64> = [0].repeat(n);
    for ai in a.iter() {
        let target_index = (ai-1) as usize;
        if ai != &0 {
            v[target_index] = v[target_index]+1;
        }
    }
    for ans in v {
        println!("{:?}", ans)
    }
}


Measured memory_bytes: 6300
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int X=sc.nextInt();
		if(X==7||X==5||X==3) {
		System.out.print("YES");
		}
		else {
			System.out.print("NO");
		}
		sc.close();
	}

}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for(ll i = 0;i < n;i++)
template<class T, class U> void chmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void chmin(T& a, U b) { if (a>b) a = b; }

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

  int n;
  cin >> n;
  vector<int> a(n), b(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];

  ll sum = 0;
  vector<int> diff(n);
  rep(i, n) {
    diff[i] = a[i]-b[i];
    sum += diff[i];
  }

  if (sum < 0) {
    cout << -1 << endl;
    return 0;
  }

  sort(diff.begin(), diff.end());
  reverse(diff.begin(), diff.end());

  ll cost = 0;
  int ans = 0;
  vector<ll> plus_sum(n+1);
  rep(i, n) {
    if (diff[i] < 0) {
      cost += -1 * diff[i];
      ans++;
    } else {
      plus_sum[i+1] = plus_sum[i] + diff[i];
    }
  }

  auto bound = lower_bound(plus_sum.begin(), plus_sum.end()-ans, cost);
  ans += bound-plus_sum.begin();
  cout << ans << endl;
}


Measured memory_bytes: 2176
import sys
from operator import or_
input=sys.stdin.readline


class SegTree():
    def __init__(self, N, e=float("inf"), operator_func=min):
        self.e = e
        self.size = N
        self.node = [self.e] * (2*N)
        self.op = operator_func

    def set_list(self, l):
        for i in range(self.size):
            self.node[i+self.size-1] = l[i]
        for i in range(self.size-1)[::-1]:
            self.node[i] = self.op(self.node[2*i+1], self.node[2*i+2])
    
    def update(self, k, x):
        k += self.size - 1
        self.node[k] = x
        while k >= 0:
            k = (k - 1) // 2
            self.node[k] = self.op(self.node[2*k+1], self.node[2*k+2])

    def get(self, l, r):
        x = self.e
        l += self.size; r += self.size
        a, b = [], []

        while l<r:
            if l&1:
                a += [l-1]; l += 1
            if r&1:
                r -= 1; b += [r-1]
            l >>= 1; r >>= 1

        for i in a+(b[::-1]):
            x = self.op(x, self.node[i])
        return x


def main():
    N = int(input())
    S = list(input())[:-1]
    trees = {chr(97+i):SegTree(N, e=0, operator_func=or_) for i in range(26)}

    for i, s in enumerate(S):
        trees[s].update(i, 1)

    Q = int(input())
    for _ in range(Q):
        mode, i, v = input().split()
        if mode=="1":
            i = int(i)-1
            trees[S[i]].update(i, 0)
            trees[v].update(i, 1)
            S[i] = v
        else:
            i = int(i)-1
            v = int(v)
            ans = sum(trees[chr(97+j)].get(i, v) for j in range(26))
            print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 273344
#include<bits/stdc++.h>
#define rep(i, n) for(i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
 
int main(){
  ll N, i, flag = 1;
  string S, ans = "No";
  cin >> S;
  rep(i, S.size() - 1){
    if(S[i] != S[i + 1]){
      flag = 0;
      break;
    }
  }
  if(!flag){
    ans = "Yes";
  }
 
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cassert>
using namespace std;
typedef long long ll;

struct state{
    ll ship,dist;
};

int main(){
    ll N,M,R;
    ll inf = 1e18;
    while(cin >> N >> M && N){
        vector<vector<ll>> L(N+1,vector<ll>(N+1,inf)),S(N+1,vector<ll>(N+1,inf));
        ll x,y,t;
        char c;
        for(int i=0;i<M;i++){
            cin >> x >> y >> t >> c;
            if(c=='L'){
                L[x][y] = min(L[x][y],t);
                L[y][x] = min(L[y][x],t);
            }else{
                S[x][y] = min(S[x][y],t);
                S[y][x] = min(S[y][x],t);
            }
        }
        for(int i=1;i<=N;i++){
            L[i][i] = 0;
            S[i][i] = 0;
        }
        for(int k=1;k<=N;k++) for(int i=1;i<=N;i++) for(int j=1;j<=N;j++){
            L[i][j] = min(L[i][j],L[i][k]+L[k][j]);
            S[i][j] = min(S[i][j],S[i][k]+S[k][j]);
        }
        cin >> R;
        vector<ll> Z(R+1,0);
        for(int i=1;i<=R;i++) cin >> Z[i];
        queue<state> Q[2];
        Q[1].push({Z[1],0});
        for(int t=1;t<=R-1;t++){
            vector<ll> mi(N+1,inf);
            while(!Q[t%2].empty()){
                state now = Q[t%2].front(); Q[t%2].pop();
                for(int g=1;g<=N;g++){
                    if(L[g][Z[t+1]]==inf) continue;
                    if(S[now.ship][g]!=inf){
                        ll d = now.dist+L[Z[t]][now.ship]+S[now.ship][g]+L[g][Z[t+1]];
                        mi[g] = min(mi[g],d);
                    }
                }
                if(L[Z[t]][Z[t+1]]!=inf) mi[now.ship] = min(mi[now.ship],now.dist+L[Z[t]][Z[t+1]]);
            }
            for(int i=1;i<=N;i++) if(mi[i]!=inf) Q[1-t%2].push({i,mi[i]});
        }
        ll ans = inf;
        while(!Q[R%2].empty()){
            ans = min(ans,Q[R%2].front().dist);
            Q[R%2].pop();
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3612
#include <iostream>
#include <math.h>
#include <string>
using namespace std;

int main()
{
    int a , b ;
    cin >> a >> b ;
    if((a+b)%2 == 0){
        cout << (a+b)/2 ;
    }
    else {
        cout << "IMPOSSIBLE" ;
    }
    return 0;
}


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

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define PI (acos(-1))

int main(){
  int H,W,N,a[10010];
  int G[110][110];
  cin >> H >> W >> N;
  rep(i,N){
    cin >> a[i];
  }
  int cnt=0,col=0;
  rep(i,H){
    rep(j,W){
      if(i%2 == 0)G[i][j] = col+1;
      else G[i][W-1-j] = col+1;

      cnt++;
      if(cnt == a[col]){
        col++;
        cnt=0;
      }
    }
  }

  rep(i,H){
    rep(j,W){
      cout << G[i][j] << " ";
    }
    cout << endl;
  }
}

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

N,M = map(int,input().split())
S = [[]for i in range(N)]
for i in range(M):
    u,v = map(int,input().split())
    S[u-1].append(v-1)
St,T = map(int,input().split())

D = [[float('inf')]*3 for i in range(N)]
D[St-1][0] = 0
queue = deque([St-1,-1])
i = 1
while 1:
    q = queue.popleft()
    if q == -1:
        queue.append(-1)
        i += 1
        if queue == deque([-1]):
            break
    else:
        for j in S[q]:
            if D[j][i%3] > i:
                D[j][i%3] = i
                queue.append(j)
if D[T-1][0] == float('inf'):
    print(-1)
else:
    print(D[T-1][0]//3)

Measured memory_bytes: 38072
/**
 * Write a program which prints multiplication tables in the following format:
 * @author midorinochawan
 */
class Main {

    private final int MaxNumber = 9;
    private static Main instance = new Main();

    private Main() {

    }

    public static Main getInstance() {
        return instance;
    }
    public boolean Run() {
        for (int i = 1; i <= MaxNumber; ++i) {
            for (int j = 1; j <= MaxNumber; ++j) {
                if (MaxNumber < i || MaxNumber < j) {
                    return false;
                }
                printQQ(i, j);
            }
        }

        return true;
    }

    private void printQQ(int left, int right) {
        System.out.println(String.format("%dx%d=%d", left, right, left * right));
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Main.getInstance().Run();
    }
}

Measured memory_bytes: 24624
#include<stdio.h>
int main(){
int l,path1[111],path2[111],d[111],pl[22],t=0,i,g[22];
g[0]=1;
for(i=1;i<22;i++)
g[i]=g[i-1]*2;
scanf("%d",&l);
while(l!=0){
pl[t]=l%2;
l=l/2;
t++;
}
int n=t;
int k=0;
for(i=1;i<t;i++){
path1[k]=i;
path2[k]=i+1;
d[k]=0;
k++;
path1[k]=i;
path2[k]=i+1;
d[k]=g[t-i-1];
k++;
}
int f=g[t-1];
for(i=t-2;i>=0;i--){
if(pl[i]==1){
path1[k]=1;
path2[k]=t-i;
d[k]=f;
k++;
f+=g[i];
}
}
printf("%d %d\n",n,k);
for(i=0;i<k;i++)
printf("%d %d %d\n",path1[i],path2[i],d[i]);
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }


int dy[] = {1, 0};
int dx[] = {0, 1};

int h, w;
string s[10];
int flg;

void dfs(int y, int x, vector<vector<int> > table) {
    if (y == h - 1 && x == w - 1) {
        rep(i, h) rep(j, w) {
            if (s[i][j] == '#' && table[i][j] == 0) {
                return;
            }
            if (i == h - 1 && j == w - 1) {
                flg = 1;
                return;
            }
        }
    }
    
    rep(i, 2) {
        int ny = y + dy[i];
        int nx = x + dx[i];
        if (ny == h || nx == w || s[ny][nx] == '.') continue;
        
        table[ny][nx] = 1;
        dfs(ny, nx, table);
        table[ny][nx] = 0;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    
    
    cin >> h >> w;
    rep(i, h) cin >> s[i];
    
    vector<vector<int> > v(10, vector<int>(10));
    v[0][0] = 1;
    
    dfs(0, 0, v);
    if (flg) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 10000000
#define MOD 1000000007

typedef long long int lli;

int des(const void* a, const void* b){
  if (*(long long int*)a > *(long long int*)b) return -1;
	if (*(long long int*)a < *(long long int*)b) return 1;
	return 0;
}

int main(void) {
  lli a[1001], b[1001], c[1001];
  lli x, y, z, k;
  scanf("%d %d %d %d", &x, &y, &z, &k);
  rep(i, 0, x) {
    scanf("%lld", &a[i]);
  }
  rep(i, 0, y) {
    scanf("%lld", &b[i]);
  }
  rep(i, 0, z) {
    scanf("%lld", &c[i]);
  }

  qsort(a, x, sizeof(lli), des);
  qsort(b, y, sizeof(lli), des);
  qsort(c, z, sizeof(lli), des);

  lli abc[MAX];
  int abc_size = 0;
  rep(ai, 0, x) {
    rep(bi, 0, y) {
      rep(ci, 0, z) {
        if ((ai + 1) * (bi + 1) * (ci + 1) > k) break;
        abc[abc_size++] = a[ai] + b[bi] + c[ci];
      }
    }
  }

  qsort(abc, abc_size, sizeof(lli), des);

  rep(i, 0, k) {
    printf("%lld\n", abc[i]);
  }

  
  return 0;
}


Measured memory_bytes: 3836