akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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




template <typename T>
class dijkstra
{
private:
    using P = pair<T, T>;
    struct edge{
        long long to;
        T cost;
    };
    long long vertex;   // 頂点数
    vector<vector<edge>> list;  //隣接リスト
    vector<T> distance;    // 距離
public:
    dijkstra(long long n, T infinity = 1e16);  // nは頂点の数、infinityは初期化に使う値
    void add_edge(long long v1, long long v2, T cost);    // 頂点v1から頂点v2に辺を張る
    void run(long long s);        // sは開始地点。
    T get_distance(long long v);    // 頂点vへの距離を返す
};

template <typename T>
dijkstra<T>::dijkstra(long long n, T infinity){
    vertex = n;
    list.resize(n);
    distance = vector<T>(vertex, infinity);
}

template <typename T>
void dijkstra<T>::add_edge(long long v1, long long v2, T cost){
    list[v1].push_back({ v2, cost });
}

template <typename T>
void dijkstra<T>::run(long long s){
    priority_queue<P, vector<P>, greater<P>> que;
    
    distance[s] = 0;    // 開始点の距離は0
    que.push(P(0, s));
    
    while(!que.empty()){
        P p = que.top(); que.pop();
        T v = p.second;
        if(distance[v] < p.first) continue;
        for(auto e : list[v]){
            if(distance[e.to] > distance[v] + e.cost){
                distance[e.to] = distance[v] + e.cost;
                que.push(P(distance[e.to], e.to));
            }
        }
    }
}

template <typename T>
T dijkstra<T>::get_distance(long long v){
    return distance[v];
}


int main() {
    ll k;
    cin >> k;
    
    dijkstra<ll> dik(k);
    REP(i, k){
        dik.add_edge(i, (i + 1) % k, 1);
        dik.add_edge(i, 10 * i % k, 0);
    }
    
    dik.run(1);
    
    cout << dik.get_distance(0) + 1 << endl;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    ll ans = 0;
    for (int i = 0; i < n - 1; ++i) {
        for (int j = i + 1; j < n; ++j) {
            ans += a[i] * a[j];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3568
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		int e = sc.nextInt();
		int k = sc.nextInt();

		System.out.println(k>=e-a ? "Yay!" : ":(");

	}
}

Measured memory_bytes: 22612
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <utility>
#include <iterator>
#include <set>
#include <map>
#include <limits>
#include <list>
#include <cstring>
#include <numeric>
#include <functional>
#include <sstream>
#include <deque>
#include <bitset>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <ctime>

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
char complement(char x)
{
	if (x == 'W')
		return 'B';
	return 'W';
}
int main()
{
	ios_base::sync_with_stdio(false);
	string s;
	cin >> s;
	int last = s.size() - 1, plays = 0;
	char toFind = complement(*(s.end() - 1));
	for (int i = last; i >= 0; --i)
	{
		if (s[i] == toFind)
		{
			++plays;
			toFind = complement(toFind);
		}
	}
	cout << plays;
	return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

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

void Main()
{
    int h, w;
    cin >> h >> w;
  	string c;
  	rep(i,h) {
      	cin >> c;
    	cout << c << endl << c << endl;
    }
  	return;
}

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

Measured memory_bytes: 256
moji = raw_input()
a,b,c,d = list(moji)
moji = list(moji)
if moji.count(a) == moji.count(b):
    if moji.count(b) == moji.count(c):
        if moji.count(c) == 2:
            print "Yes"
            exit()

print "No"

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

#include <atcoder/all>
#define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
using namespace atcoder;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T div_floor(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a > 0 ? (a - 1) / b + 1 : a / b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

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

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    char c[n][m];
    rep(i, n) rep(j, m) scanf(" %c", &c[i][j]);

    mf_graph<int> gr(n * m + 2);
    int source = n * m, sink = n * m + 1;
    rep(i, n) rep(j, m) if (c[i][j] != '#') {
        if ((i + j) % 2 == 0) {
            gr.add_edge(source, i * m + j, 1);
            rep(k, 4) {
                int nx = i + dx[k], ny = j + dy[k];
                if (0 <= nx && nx < n && 0 <= ny && ny < m &&
                    c[nx][ny] != '#') {
                    gr.add_edge(i * m + j, nx * m + ny, 1);
                }
            }
        } else
            gr.add_edge(i * m + j, sink, 1);
    }

    printf("%d\n", gr.flow(source, sink));
    auto es = gr.edges();
    for (auto &e : es)
        if (e.flow != 0 && e.from != source && e.to != sink) {
            int x = e.from / m, y = e.from % m, nx = e.to / m, ny = e.to % m;
            if (e.to == e.from + 1) c[x][y] = '>', c[nx][ny] = '<';
            if (e.to == e.from - 1) c[x][y] = '<', c[nx][ny] = '>';
            if (e.to == e.from + m) c[x][y] = 'v', c[nx][ny] = '^';
            if (e.to == e.from - m) c[x][y] = '^', c[nx][ny] = 'v';
        }
    rep(i, n) {
        rep(j, m) printf("%c", c[i][j]);
        printf("\n");
    }
}

Measured memory_bytes: 5648
import java.util.Scanner;

public class Main {
	private static long fizzbuzzSum(int number) {
		long sum = 0;
		for (int i = 1; i <= number; i++) {
			if (i % 3 != 0 && i % 5 != 0)
				sum += i;
		}
		return sum;
	}

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			System.out.println(fizzbuzzSum(scanner.nextInt()));
		}
	}
}


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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

#define INF 1e9

ll N, M, V, P;
vector<int> A;

int main(){ 
  cin >> N >> M >> V >> P;
  A.resize(N);
  REP(i, N){
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  vector<ll> sum(N+1,0);
  REP(i, N){
    sum[i+1] = sum[i] + A[i];
  }
  if(P >= V){
    int ans = 0;
    REP(i, N){
      if(A[i] + M >= A[N-P]){
        ans++;
      }
    }
    cout << ans << endl;
    return 0;
  }
  int ans = P;
  V -= P;
  // cerr << "V:" << V << endl;
  for(int i = N-P-1; i >= 0; i--){
    // cerr << "i:" << i << " cost:" << M*i + (M+A[i])*(N-P-i)-(sum[N-P+1] - sum[i+1]) << endl;
    // cerr << "M*i:" << M*i << " (M+A[i])*(N-P-i):" << (M+A[i])*(N-P-i) << endl;
    // cerr << "sum:" << sum[N-P+1] << " " << sum[i+1] << endl;
    if(A[i]+M < A[N-P]) continue;
    if(i >= V && A[i]+M >= A[N-P]){
      ans++;
    }
    else if(M*V <= M*i + (M+A[i])*(N-P-i)-(sum[N-P+1] - sum[i+1])){
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1408
def main():
    from sys import stdin
    readline = stdin.readline
    n = int(readline())
    A = list(map(int, readline().split()))

    tallest = A[0]
    cnt = 0

    for height in A:
        if tallest > height:
            cnt += tallest - height
        else:
            tallest = height

    print(cnt)


if __name__ == "__main__":
    main()

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 5e3 + 5;

char dp_pref[MAXN][MAXN], dp_suf[MAXN][MAXN];

int v[MAXN];

void solve(){
	int n, k, m = 1, ans = 0;
	scanf("%d%d", &n, &k);
	REPN(i, 1, n){
		scanf("%d", &v[m]);
		if (v[m] < k){
			m++;
		}
	}
	dp_pref[0][0] = 1;
	REP(i, 1, m){
		REP(j, 0, k){
			dp_pref[i][j] = dp_pref[i - 1][j];
			if (j >= v[i]){
				dp_pref[i][j] |= dp_pref[i - 1][j - v[i]];
			}
		}
	}
	dp_suf[m][0] = 1;
	for(int i = m - 1; i > 0; i--){
		REP(j, 0, k){
			dp_suf[i][j] = dp_suf[i + 1][j];
			if (j >= v[i]){
				dp_suf[i][j] |= dp_suf[i + 1][j - v[i]];
			}
		}
	}
	REP(i, 1, m){
		int fl = 0;
		for(int l = 0, r = k - 1; l < k && r >= 0; l++){
			if (dp_pref[i - 1][l] == 0){
				continue;
			}
			for(r = min(r, k - l - 1); r >= 0 && r >= k - l - v[i]; r--){
				if (dp_suf[i + 1][r]){
					fl = 1;
					break;
				}
			}
			if (fl){
				break;
			}
		}
		ans += 1 - fl;
	}
	printf("%d\n", ans);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 49152
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int a,b,c,d;

void solve(){
    cin >> a >> b >> c >> d;
    while(a>0 && c>0){
        c-=b;
        if(c<=0) {
            cout << "Yes" << endl;
            return;
        }
        a-=d;
        if(a<=0) {
            cout << "No" << endl;
            return;
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
  int n;
  cin >> n;
  vvi a(n,vi(n));
  rep(i,n){
    rep(j,n) cin >> a[i][j];
  }
  vl dp(1<<n,0);
  dp[0] = 1;
  REP(tmp,1,1<<n){
    int m = __builtin_popcount(tmp);
    rep(i,n){
      if(((1<<i)&tmp) && a[m-1][i]){
        dp[tmp] += dp[tmp^(1<<i)];
        dp[tmp] %= MOD;
      }
    }
  }
  cout << dp[(1<<n)-1] << endl;
}


Measured memory_bytes: 19628
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  long long Y=1;
  long long Z=3;
  cin >> N;
  if(N==1){
    cout << 1 << endl;
  }
  else if(N==2){
    cout << 3 << endl;
  }
  else{
    for (int X=0;X<N-3;X++){
      if (Y<Z){
        Y+=Z;
      }
      else{
        Z+=Y;
      }
    }
    cout << Y+Z << endl;
  }
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

using ll = long long;
using P = pair<int, int>;

const int MAX = 2010;
const ll INF = 1e18;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

ll b[MAX][MAX];

int main() {
  // 入力
  int N;
  ll x;
  cin >> N >> x;
  ll a[N];
  for (int i = 0; i < N; i++) cin >> a[i];

  ll ans = 0;
  // ansを、魔法を使わない（全てのスライムを捕まえることで揃える）でかかる秒数に初期化する
  for (int i = 0; i < N; i++) {
    ans += a[i];
    b[i][0] = a[i];
  }

  // 魔法を使う回数を固定して全探索
  for (int i = 1; i < N; i++) {
    ll tmp = i * x;
    for (int j = 0; j < N; j++) {
      b[j][i] = min(b[j][i-1], (j - i >= 0 ? a[j-i] : a[N+(j-i)]));
      tmp += b[j][i];
    }
    ans = min(ans, tmp);
  }

  // 解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 31744
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.Int();
            int M = in.Int();
            int K = in.Int();
            int[] A = in.Int(N);
            int[] B = in.Int(M);

            long[] as = new long[N + 1];
            for (int i = 0; i < N; i++) {
                as[i + 1] += as[i] + A[i];
            }
            long[] bs = new long[M + 1];
            for (int i = 0; i < M; i++) {
                bs[i + 1] += bs[i] + B[i];
            }
            int ans = 0;
            int i = 0;
            while (i < N && as[i + 1] <= K) i++;
            int j = 0;
            while (i >= 0) {
                while (j < M && as[i] + bs[j + 1] <= K) j++;
                ans = Math.max(ans, i + j);
                i--;
            }
            out.println(ans);
//        out.println(Arrays.toString(as));
//        out.println(Arrays.toString(bs));
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    return null;
                }
            }
            return st.nextToken();
        }

        public int Int() {
            return Integer.parseInt(next());
        }

        public int[] Int(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Int();
            }
            return a;
        }

    }
}



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

ll solve() {
    ll N;
    cin >> N;
    vector<double> X(N), Y(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> X[i] >> Y[i];
    }
    vector<int> c(N);
    int M = 3e5;
    double pi = acos(0) * 2;
    for ( int k = 0; k < M; k++ ) {
        double t = 2 * pi * k / M;
        int mi;
        double mx = -2e6;
        for ( int i = 0; i < N; i++ ) {
            double x = X[i]*cos(t) - Y[i]*sin(t);
            if ( mx < x ) {
                mx = x;
                mi = i;
            }
        }
        c[mi]++;
    }
    for ( int i = 0; i < N; i++ ) {
        cout << c[i] / (double)M << "\n";
    }
    return 0;
}

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

Measured memory_bytes: 384
import math
n = int(input())
ls = list(map(int,input().split()))
bs = [ls[i]-i-1 for i in range(n)]
bs.sort()
#print(bs)
if n %2 ==0:
    a = round(n/2)
    #print(a)
    can = [bs[a],bs[a-1],math.floor((bs[a] +bs[a-1])/2),math.ceil((bs[a] +bs[a-1])/2)]
elif n ==1:
    can = [bs[0],bs[0]]
else:
    a = math.floor(n/2)
    #print(a)
    can = [bs[a+1],bs[a-1],bs[a]]

#print(can)
result = 10**27
for k in can:
    ans =0
    for kn in bs:
        ans += abs(kn-k)
    #print(ans)
    result = min(result, ans)
    
print(result)   

Measured memory_bytes: 32080
week_dict = {
    'MON': 1,
    'TUE': 2,
    'WED': 3,
    'THU': 4,
    'FRI': 5,
    'SAT': 6,
    'SUN': 7
}

day_of_week = input()

if day_of_week == 'SUN':
    print(week_dict[day_of_week])

else:
    days_left_to_sunday = 7 - week_dict[day_of_week]
    print(days_left_to_sunday)

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

int n, a[100005], b[100005], ans;
deque<int> need, bonus;

bool cmp(int x, int y) {return x>y;}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for(int i=0; i<n; i++) cin >> a[i];
    for(int i=0; i<n; i++) cin >> b[i];
    for(int i=0; i<n; i++) {
        if(a[i] < b[i]) {
            ans++;
            need.push_back(b[i]-a[i]);
        } else {
            bonus.push_back(a[i]-b[i]);
        }
    }
    sort(bonus.begin(), bonus.end(), cmp);
    if(ans==0) {
        cout << 0 << endl;
        return 0;
    }

    while(!bonus.empty()) {
        ans++;
        while(!need.empty()) {
            if(bonus[0] >= need[0]) {
                bonus[0] -= need[0];
                need.pop_front();
            } else {
                need[0] -= bonus[0];
                bonus.pop_front();
                break;
            }
        }
        if(need.empty()) break;
    }

    if(!need.empty()) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 1536
N=int(input())
a = list(map(int,input().split()))[::-1]

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

# Nの倍数の数を格納する辞書
baisuu = {i:0 for i in range(1,N+1)}
M=0
out_list=[]

half=N//2

for i,ai in enumerate(a):
    now_index=N-i
    if now_index > half:
        if ai==1:
            soinsuu = make_divisors(now_index)
            out_list.append(now_index)
            M+=1
            for so in soinsuu:
                baisuu[so]+=1
    else:
        if baisuu[now_index]%2!=ai:
            out_list.append(now_index)
            M+=1
            soinsuu = make_divisors(now_index)
            for so in soinsuu:
                baisuu[so]+=1

print(M)
if M>0:
    out_list=sorted(out_list)
    print(" ".join(list(map(str, out_list))))

Measured memory_bytes: 101608
n, q = map(int, input().split())
queue = []
for i in range(n):
    x = input().split()
    queue.append((x[0], int(x[1])))
time = 0
while queue != []:
    if queue[0][1] <= q:
        time += queue[0][1]
        print('{} {}'.format(queue.pop(0)[0], time))
    else:
        time += q
        x = queue.pop(0)
        queue.append((x[0], x[1]-q))


Measured memory_bytes: 12088
<?php

list($num,$legs) = explode(' ',trim(fgets(STDIN)));

if($legs % 2 == 1){
    echo "No\n";
    exit;
}
$total_crane = 2 * $num;

$diff = $legs - $total_crane;

if($diff < 0){
    echo "No\n";
    exit;
}

if($diff <= 2 * $num){
    echo "Yes\n";
    exit;
}

echo "No\n";
exit;

?>


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

int main() {
    int n, m;
    cin >> n >> m;
    int x[m];
    for (int i = 0; i < m; i++) cin >> x[i];
    sort(x, x + m);

    int a[m];
    for (int i =  0; i < m - 1; i++) {
        a[i] = x[i + 1] - x[i];
    }
    sort(a, a + m - 1);

    int ans = 0;
    for (int i = 0; i < m - n; i++) {
        ans += a[i];
    }

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

Measured memory_bytes: 1024
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdint.h>
#include <string.h>
#include <math.h>

int main(void) {
	uint32_t A, B, C, X, Y;
	uint32_t numA = 0;
	uint32_t numB = 0;
	uint32_t numC = 0;

	scanf("%"PRIu32" %"PRIu32" %"PRIu32" %"PRIu32" %"PRIu32, &A, &B, &C, &X, &Y);

	if (A + B > C*2) {
		if (X > Y) {
			numC += Y * 2;
			if ((X - Y)*A > (X - Y)*C*2) {
				numC += (X - Y) * 2;
			}
			else {
				numA += X - Y;
			}
		}
		else {
			numC = X * 2;
			if ((Y - X)*B > (Y - X)*C * 2) {
				numC += (Y - X) * 2;
			}
			else {
				numB += Y - X;
			}
		}
	}
	else {
		numA = X;
		numB = Y;
	}

	printf("%"PRIu32, A*numA + B * numB + C * numC);

	return 0;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/03/04  Problem: 071_arc_c / Link: https://arc071.contest.atcoder.jp/tasks/arc071_c?lang=en  ----- */
/* ------問題------

A, B からなる文字列に対して、次の操作を考えます。
文字列中の 1 文字を選ぶ。それが A なら BB で、 B なら AA で置き換える。
AAA か BBB であるような部分文字列を選び、消す。
例えば、ABA という文字列で 1 番目の操作を 1 文字目に対して行うと、 BBBA となります。 また、BBBAAAA に対して 2 番目の操作を 4 文字目から 6 文字目に対して行うと、 BBBA となります。
これらの操作を何回でも好きな順で行うことができます。
文字列 S,T と q 個のクエリ ai,bi,ci,di が与えられます。 各クエリに対して、 S の部分文字列 SaiSai+1…Sbi を T の部分文字列 TciTci+1…Tdi にすることができるか判定してください。

-----問題ここまで----- */
/* -----解説等-----

規則性から、A->BB->AAAA->A, B->AA->BBBB->Bと環?になっている
AB->AAA->φ
BA->BBB->φ
から、状態は3種類しかない。
したがってこれは適当にセグ木や累積和で区間の状態を持つことができる。
あとはクエリO(1)で答えるのみ

----解説ここまで---- */

LL N;

LL ans = 0LL;

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


	string s, t; cin >> s >> t;
	VI sums(SZ(s) + 1, 0);
	VI sumt(SZ(t) + 1, 0);
	FOR(i, 0, SZ(s)) {
		sums[i + 1] = sums[i] + (s[i] == 'A' ? 1 : 2);
	}
	FOR(i, 0, SZ(t)) {
		sumt[i + 1] = sumt[i] + (t[i] == 'A' ? 1 : 2);
	}

	int Q; cin >> Q;
	FOR(i, 0, Q) {
		int a, b, c, d;
		cin >> a >> b >> c >> d; // [a,b] ? [c,d]
		int vals = (sums[b] - sums[a-1])%3;
		int valt = (sumt[d] - sumt[c-1])%3;
		if (vals == valt) {
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}

	return 0;
}


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

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;

#define deb(x) cerr<<#x<<":"<<x<<"\n";
#define dvi(x) for(ll i=0;i<x.size();i++)cerr<<#x<<"["<<i<<"]:"<<x[i]<<" ";
#define iter(v) for(auto it:v)
#define wt ll t;cin>>t;while(t--)
#define rl(x) ll x;cin>>x;
#define rvi(x,n) vi x(n);for(ll i=0;i<n;i++) cin>>x[i];
#define rs(x) string x;cin>>x;
#define w(x) cout<<x<<endl;
#define wvi(x) for(ll i=0;i<x.size();i++) cout<<x[i]<<" ";cout<<endl;
#define ws(x) cout<<x<<endl;
#define all(v) v.begin(),v.end()
#define pb push_back
#define ppb pop_back
#define pll pair<ll, ll>
#define fo(i,n) for(ll i=0;i<n;i++)
#define forr(i,a,b) for(ll i=a;i<b;i++)
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
const ll N = 1e9 + 7;

map<long long, long long> factorize(long long n) {	//returns map containing factor and multiplicity, Eg: 60 = {{2,2},{3,1},{5,1}}
	map<long long, long long> ans;
	for (long long i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ans[i]++;
			n /= i;
		}
	}
	if (n > 1) {
		ans[n]++;
		n = 1;
	}
	return ans;
}

void FAST() {	//FAST Input Output, DONT use both scnaf,prllf / cin,cout , Use any ONE system
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

ll powM(ll x, ll y, ll m) {	//returns (a^b)%m ( ^ is exponent )
	ll ans = 1, r = 1;
	x %= m;
	while (r > 0 && r <= y)
	{
		if (r & y)
		{
			ans *= x;
			ans %= m;
		}
		r <<= 1;
		x *= x;
		x %= m;
	}
	return ans;
} 

int main()
{
	FAST();
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    //    freopen("output.txt", "w", stdout);
    #endif
//	wt{
		rl(x) rl(k) rl(d)
		if(x>0)
		{
			if(k>x/d)
			{k-=x/d;
			if(x%d<abs(x%d-d))
			x=x%d;
			else 
			x=x%d-d,k--;}
			else
			{
				x-=k*d;
				cout<<abs(x);
				exit(0);
			}
			
		}
		else
		{
			if(k>abs(x)/d)
			{k-=abs(x)/d;
			if(abs(x)%d)
			x=(abs(x)%d)*-1;
			else
			{
				x=abs(abs(x)%d-d);
				k--;
			}
			}
			else
			{
				x+=k*d;
				cout<<abs(x);
				exit(0);
			}
			
		}
		if(k%2==0)cout<<abs(x);
		else 
		{
			if(abs(x-d)>abs(x+d))cout<<abs(x+d);
			else cout<<abs(x-d);
		}
//	}
}

Measured memory_bytes: 3560
#include <stdio.h>
int main(void){
    int i1,i2,answer;

    for(i1=1;i1<=9;i1++){
        for(i2=1;i2<=9;i2++){
            answer=i1*i2;
            printf("%dx%d=%d\n",i1,i2,answer);
        }                
    }
    return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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

int main(){
  string s;
  int w = 0;
  int b = 0;
  cin >> s;
  int size = s.size();
  rep(i,size){
    if(i%2 == 0){
      if(s.at(i) != '1') b++;
    }
    else{
      if(s.at(i) != '0') b++;
    }
    
    if(i%2 == 0){
      if(s.at(i) != '0') w++;
    }
    else{
      if(s.at(i) != '1') w++;
    }
  }
  cout << min(w,b) << endl;
  // cout << w << b << endl;
  
  return 0;
}




Measured memory_bytes: 512
import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

int H, W;
string[] F;
bool input() {
    scanf("%d %d\n", &W, &H);
    if (W == 0 && H == 0) return false;
    F = new string[H];
    foreach (i; 0 .. H) {
        F[i] = readln.chomp;
    }
    return true;
}

const dy = [-1, 0, 1, 0],
      dx = [0, -1, 0, 1];

void solve() {
    auto M = new int[][](H, W);
    int ans_b, ans_w;

    void fill(int y, int x, int v) {
        struct P {
            int y, x;
        }
        int f = 0;
        auto Q = new DList!P(P(y, x));
        while (!Q.empty) {
            P c = Q.front; Q.removeFront;
            foreach (i; 0 .. 4) {
                int ny = c.y + dy[i],
                    nx = c.x + dx[i];
                if (ny < 0 || ny >= H) continue;
                if (nx < 0 || nx >= W) continue;
                if (M[ny][nx] & v) continue;
                if (F[ny][nx] != '.') continue;
                M[ny][nx] |= v;
                Q.insert(P(ny, nx));
            }
        }
    }

    foreach (i; 0 .. H) {
        foreach (j; 0 .. W) {
            char c = F[i][j];
            if (c == 'B') {
                fill(i, j, 1);
            } else if (c == 'W') {
                fill(i, j, 2);
            }
        }
    }
    foreach (i; 0 .. H) {
        foreach (j; 0 .. W) {
            if (F[i][j] == '.' && M[i][j] == 1) {
                ans_b++;
            } else if (F[i][j] == '.' && M[i][j] == 2) {
                ans_w++;
            }
        }
    }
    writeln(ans_b, " ", ans_w);
}

void main() {
    while (input) solve;
}

Measured memory_bytes: 2040
#include <stdio.h>
#include <string.h>

#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <functional>

using namespace std;

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

    int n, m;
    cin >> n >> m;

    if (m == 1) {
        cout << 0;
        return 0;
    }

    vector<int> xs(m);

    for (int i = 0; i < m; ++i) {
        cin >> xs[i];
    }
    sort(xs.begin(), xs.end());

    vector<int> diffs(m-1);
    for (int i = 0; i < m - 1; ++i){
        diffs[i] = xs[i + 1] - xs[i];
    }

    sort(diffs.rbegin(), diffs.rend());

    int score = accumulate(diffs.begin(), diffs.end(), 0);
    for (int i = 0; i < min(n - 1, m - 1); ++i)
    {
        score -= diffs[i];
    }

    cout << score;

    return 0;
}




Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[200010];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(int n){
	kaijo[0]=1;
	for(int i=1;i<=n;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}
int comb(int a,int b){
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int g(int x){
	x=modpow(x,MOD-2);
	return x;
}
int n,m;
P p[100001];
int now=0,v=0,ans=0;
priority_queue<int>q;
signed main(){
	cin>>n>>m;
	rep(i,n)cin>>p[i].fi>>p[i].se;
	sort(p,p+n);
	for(int i=1;i<=m;i++){
		for(;now<n&&p[now].fi==i;now++){
			q.push(p[now].se);
		}
		if(!q.empty()){
			ans+=q.top();
			q.pop();
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2936
a = list(map(int,input().split()))
n = a[0]
k = a[1]
li = list(map(int,input().split()))
ans = 0
minans = 0
flag = 0
for i in range(n-k+1):
    flag+=1
    if li[i]>=0 and li[i+k-1]>=0:
        minans = li[i+k-1] - 0
    elif li[i]<=0 and li[i+k-1]<=0:
        minans = 0 - li[i]
    else:
        minans = -1*li[i] + li[i+k-1] + min(-1*li[i],li[i+k-1])
    if flag == 1:
        ans = minans
    if minans <= ans:
        ans = minans
print(ans)
    

Measured memory_bytes: 14660
#include<bits/stdc++.h>
#define pi acos(-1)
#define mx 1000000000
#define mod 1000000009
#define pii pair<int,int>
#define psi pair<string,int>
#define vi vector<int>
typedef long long ll;
using namespace std;
void fastio()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("inputf.txt", "r", stdin);
    freopen("outputf.txt", "w", stdout);
#endif
    fastio();
    int i,j,t,n,k,m,r;
    //cin>>t;
    //while(t--){
    cin>>n>>k;
    int a[10]={0};
    for(i=0;i<k;i++){
      cin>>m;
      a[m]++;
    }
    int ans=0;
    for(i=n;;i++){
      r=i;
      int c=0;
      while(r){
        if(a[r%10]){
          c=1;
          break;
        }
         r/=10;
      }
      if(c==0){
        ans=i;
        break;
      }
    }
    cout<<ans<<endl;
    //}
 return 0;
}



Measured memory_bytes: 3640
h, w, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

d = dict()
for i in range(len(ab)):
    a = ab[i][0] - 1
    b = ab[i][0] - 1
    d[a] = set()

dp = [0] * 10
dp[0] = (h - 2) * (w - 2)
for i in range(n):
    a = ab[i][0] - 1
    b = ab[i][1] - 1
    for dx in [-1, 0, 1]:
        for dy in [-1, 0, 1]:
            nx, ny = a + dx, b + dy # center
            if nx >= 1 and nx <= h - 2 and ny >= 1 and ny <= w - 2:
                # print(nx, ny)
                tmp = 0
                for dx2 in [-1, 0, 1]:
                    for dy2 in [-1, 0, 1]:
                        if nx + dx2 in d and ny + dy2 in d[nx + dx2]:
                            tmp += 1

                dp[tmp] -= 1
                dp[tmp + 1] += 1

    d[a].add(b)

for x in dp:
    print(x)


Measured memory_bytes: 92372
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <ctime>
#define LL long long
#define inf 0x3f3f3f3f
#define PII pair<int,int>
#define lson rt<<1
#define rson rt<<1|1
#define test freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
using namespace std;
const int maxn=1e5+5;
struct nod
{
    int v,id;
    bool operator < (const nod& rhs) const
    {
        return v<rhs.v;
    }
}a[maxn];

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
    {
        scanf("%d",&a[i].v);
        a[i].id=i;
    }
    sort(a+1,a+1+n);
    for(int i=1;i<=n;++i) printf("%d ",a[i].id);
    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
const long long MOD = 1000000007;

ll N, A[400][400], dist[400][400];
vector<pair<long long, pair<int, int>>> edge;

void floyd(){
    for(int k = 0; k < N; k++){
        for(int i = 0; i < N; i++){
            for(int j = 0; j < N; j++){
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
}

signed main(){
    cin >> N;
    REP(i, N) REP(j, N) dist[i][j] = LONG_LONG_MAX / 2;
    REP(i, N){
        REP(j, N){
            cin >> A[i][j];
            dist[i][j] = A[i][j];
        }
    }
    floyd();
    ll ans = 0;
    REP(i, N - 1){
        FOR(j, i + 1, N){
            if(dist[i][j] < A[i][j]){
                PRINT("-1");
                return 0;
            }
            bool exist = false;
            REP(k, N){
                if(k == i || k == j) continue;
                if(dist[i][j] == dist[i][k] + dist[k][j]) exist = true;
            }
            if(!exist) ans += dist[i][j];
        }
    }
    PRINT(ans);
    return 0;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

void solve(){
    int H,W;
    cin >> H >> W;
    
    vector<string> S(H);
    rep(i,0,H) cin >> S[i];

    rep(i,0,H){
        rep(j,0,W){
            if(S[i][j]=='#'){
                cout << '#';
                continue;
            }
            int cnt=0;
            rep(ni,i-1,i+2){
                if(ni<0 or H<=ni) continue;
                rep(nj,j-1,j+2){
                    if(nj<0 or W<=nj) continue;
                    if(S[ni][nj]=='#') ++cnt;
                }
            }
            cout << cnt;
        }
        cout << endl;
    }
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


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

int main()
{
    int n;
    cin>>n;
    vector <int> arr[n];
    for(int i=0;i<n;i++)
    {
    	int a,b,c;
    	cin>>a>>b>>c;
    	arr[i].push_back(a);
    	arr[i].push_back(b);
    	arr[i].push_back(c);
    }

    int dp_0[n]={0};
    int dp_1[n]={0};
    int dp_2[n]={0};

    dp_0[0]=arr[0][0];
    dp_1[0]=arr[0][1];
    dp_2[0]=arr[0][2];

    for(int i=1;i<n;i++)
    {

	    dp_0[i]=arr[i][0]+max(dp_1[i-1],dp_2[i-1]);
	    dp_1[i]=arr[i][1]+max(dp_0[i-1],dp_2[i-1]);
	    dp_2[i]=arr[i][2]+max(dp_0[i-1],dp_1[i-1]);
    }

    cout<<max(max(dp_0[n-1],dp_1[n-1]),dp_2[n-1])<<endl;

}


Measured memory_bytes: 6912
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

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

    LL n;
    cin >> n;
    vector<LL> a(n);
    for(auto &x:a){
        cin >> x;
    }

    LL absmax = -1;
    LL idx = 0;
    bool pos = true;
    for(int i = 0; i < n; i++){
        if(absmax < abs(a[i])){
            idx = i;
            absmax = abs(a[i]);
            pos = a[i] >= 0;
        }
    }

    vector<pair<LL,LL>> ans;

    if(pos){
        for(int i = 0; i < n; i++){
            if(a[i] < 0){
                a[i] += absmax;
                ans.push_back(make_pair(idx+1,i+1));
            }
        }
        for(int i = 1; i < n; i++){
            ans.push_back(make_pair(i,i+1));
        }
    }else{
        for(int i = 0; i < n; i++){
            if(a[i] > 0){
                a[i] -= absmax;
                ans.push_back(make_pair(idx+1,i+1));
            }
        }
        for(int i = n; i > 1; i--){
            ans.push_back(make_pair(i,i-1));
        }
    }

    cout << ans.size() << endl;
    for(auto x: ans){
        cout << x.first << " ";
        cout << x.second << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;

int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	int c[n],v[n],d[n];
	int ans=0;
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>c[i];
		d[i]=v[i]-c[i];
		if(d[i]>0)
		{
			ans+=d[i];
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int H, W, h, w;
int main()
{
    cin >> H >> W >> h >> w;
    if (H % h == 0 && W % w == 0) cout << "No" << endl;
    else
    {
        cout << "Yes" << endl;
        for (int i = 0; i < H; ++ i)
        {
            for (int j = 0; j < W; ++ j)
            {
                cout << (i % h || j % w? -1000: 1000 * (h * w - 1) - 1) << " ";
            }
            cout << endl;
        }
    }
}


Measured memory_bytes: 1664
#include <stdio.h>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
    int a[10];
    for (int i=0;i<5;i++)
    {
        cin >> a[i];
    }
    sort(a,a+5);
    int k;
    cin >> k;
    if (a[4]-a[0]>k)cout << ":("<<endl;
    else cout << "Yay!"<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int fib[45];

int fibonacci( int n )
{
  if( n == 0 || n == 1 ) return fib[n] = 1;
  if( fib[n] != -1 ) return fib[n];
  return fib[n] = fibonacci( n - 1 ) + fibonacci( n - 2 );
}


int main()
{
  int n, i;

  for( i=0; i<45; i++ ) fib[i] = -1;

  scanf("%d", &n);
  printf("%d\n", fibonacci(n));

  return 0;
}



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

unsigned long long n;
unsigned long long q, h, s, d;
unsigned long long a = 20000000000, b = 20000000000;


int main() {
	cin >> q >> h >> s >> d >> n;
	a = min(q * 4, h * 2);
	a = min(a, s);
	b = d;
	if (a * 2 < b) {
		cout << a * n << endl;
	}else{
		cout << n / 2 * b + (a * (n % 2))<< endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
  string in[3];
  cin>>in[0]>>in[1]>>in[2];
  cout<<in[0][0]<<in[1][1]<<in[2][2]<<endl;



  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define rep(i, a, b) for(int i = (a); i < (b); ++i)

// 動作環境 : C++14 AOJ
int main(){
    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    if(x - r >= 0 && r + x <= W && y - r >= 0 && y + r <= H) puts("Yes");
    else puts("No");

    return 0;
}



Measured memory_bytes: 2100
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <vector>
#include <climits>
#include <queue>
#include <utility>
#include <iomanip>
#include <sstream> 
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
template<typename T1, typename T2>
inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2>
inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
const ll MOD = 1000000006;
const ll INF = 1LL << 60;

ll a[10100] = {0};

int main()
{
    ll n;
    cin >> n;
    
    for (int i = 1; i <= 100; i++) {
        for (int j = 1; j <= 100; j++) {
            for (int k = 1; k <= 100; k++) {
                ll temp = i * i + j * j + k * k + i * j + j * k + k * i;
                if(temp <= 10000)
                    a[temp]++;
            }
        }
    }


    rep(i, n) {
        cout << a[i + 1] << endl;
    }
    



}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<int,P>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
using namespace std;
char c[1000][1000];
bool used[1000][1000];
int x[1000][1000];
queue<P> q;
signed main(){
	int a,b,ans=0;
	cin>>a>>b;
	f(i,a){
		f(j,b){
			cin>>c[i][j];
			if(c[i][j]=='#'){
				q.push(P(i,j));
				used[i][j]=true;
			}
		}
	}
	while(q.size()){
		P p=q.front();
		q.pop();
		if(p.F&&!used[p.F-1][p.S]){
			used[p.F-1][p.S]=true;
			x[p.F-1][p.S]=x[p.F][p.S]+1;
			q.push(P(p.F-1,p.S));
		}
		if(p.F<a-1&&!used[p.F+1][p.S]){
			used[p.F+1][p.S]=true;
			x[p.F+1][p.S]=x[p.F][p.S]+1;
			q.push(P(p.F+1,p.S));
		}
		if(p.S&&!used[p.F][p.S-1]){
			used[p.F][p.S-1]=true;
			x[p.F][p.S-1]=x[p.F][p.S]+1;
			q.push(P(p.F,p.S-1));
		}
		if(p.S<b-1&&!used[p.F][p.S+1]){
			used[p.F][p.S+1]=true;
			x[p.F][p.S+1]=x[p.F][p.S]+1;
			q.push(P(p.F,p.S+1));
		}
		ans=x[p.F][p.S];
	}
	cout<<ans<<endl;
	return 0;
}


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

int n,m;
const int INF=1e9;
int solve(){
  vector<int> s(n);
  for(int i=0;i<n;i++) cin>>s[i];
  vector<int> d(m);
  for(int i=0;i<m;i++) cin>>d[i];
  sort(d.begin(),d.end());
  vector<vector<int>> dp(m+1,vector<int>(1<<n,INF));
  dp[0][0]=0;
  vector<int> w(1<<n,0);
  for(int i=0;i<(1<<n);i++){
    for(int j=0;j<n;j++){
      if((i>>j)&1) w[i]+=s[j];
    }
  }
  for(int i=0;i<m;i++){
    for(int bit=0;bit<(1<<n);bit++){
      for(int k=0;k<n;k++){
	dp[i][bit|(1<<k)]=min(dp[i][bit|(1<<k)],dp[i][bit]);
      }
      dp[i+1][bit]=min(dp[i+1][bit],dp[i][bit]+abs(d[i]-w[bit]));
    }
  }
  return *min_element(dp[m].begin(),dp[m].end());
}

int main(){
  while(cin>>n>>m,n){
    cout<<solve()<<endl;
  }
  return 0;
}


Measured memory_bytes: 16216
#include <iostream>
#include <string>
#include <cstdlib>

int cket(std::string &str, int i)
{
	int n = 1;

	for ( ; i < str.size(); ++i ) {
		if ( str[i] == '(' ) n++;
		if ( str[i] == ')' ) n--;

		if ( n == 0 ) break;
	}
	return i;
}

int n;
char expand(std::string str)
{
	for ( int i = 0; i < str.size(); ++i ) {
		if ( isdigit( str[i] ) ) {
			int j = 1;
			while ( isdigit(str[i + j] ) ) j++;
			int num = std::atoi(str.substr(i, j).c_str());
			
			int s, e;
			if ( str[i + j] == '(' ) {
				int k;
				k = cket(str, i + j + 1);
				s = i + j + 1;
				e = k - (i+j+1);
				i = k;
			} else {
				s = i + j;
				e = 1;
				i = i + j;
			}
			for ( int l = 0; l < num; ++l ){
				char a = expand(str.substr(s, e));
				if ( a != '0' ) return a;
			}
		} else {
			if ( n == 0 ) {
				return str[i];
			}
			n--;
		}
	}
	return '0';
}

int main(void)
{
	while ( true ) {
		std::string str;

		std::cin >> str >> n;
		if ( str == "0" && n == 0 ) break;

		std::cout << expand(str) << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3140
#include<bits/stdc++.h>
#define LL long long
#define R register int
using namespace std;
const int YL=1e9+7;
inline void M(R&x){if(x>=YL)x-=YL;}
int main(){
    R n;cin>>n;
    R f2=0,f1=n,f=(LL)n*n%YL,t=(LL)(n-1)*(n-1)%YL,s=0;
    for(R i=n-2;i>0;--i)
        M(s+=f2),f2=f1,f1=f,M(f+=t),M(f+=s+i+1);
    return cout<<f<<endl,0;
}

Measured memory_bytes: 256
import bisect
import sys
sys.setrecursionlimit(3*10**5)

INF = 10**10

N = int(input())
a = list(map(int,input().split()))
T = [set() for x in range(N)]
for i in range(N-1):
    u,v = map(int,input().split())
    u -= 1
    v -= 1
    T[u].add(v)
    T[v].add(u)

search = [0]*N

A = [INF]

ans = [-1]*N

def dfs(V):
    num = a[V]
    added = 0
    if A[-1] < num:
        A.append(num)
        added = 1
    else:
        k = bisect.bisect_left(A,num)
        v = A[k]
        A[k] = num
    ans[V] = len(A)
    for VV in T[V]:
        if search[VV]:
            continue
        search[VV] = 1
        dfs(VV)
    if added:
        A.pop()
    else:
        A[k] = v

search[0] = 1
dfs(0)

print(*ans,sep="\n")

Measured memory_bytes: 387740