akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[N];
		int cnt = 0;
		int min = Integer.MAX_VALUE;
		long sum = 0;
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			if(A[i] < 0) {
				cnt++;
			}
			min = Math.min(Math.abs(min), Math.abs(A[i]));
			sum += Math.abs(A[i]);
		}
		
		if(cnt % 2 == 0) {
			System.out.println(sum);
		} else {
			System.out.println(sum - Math.abs(min) * 2);
		}
	}
}


Measured memory_bytes: 52324
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        var ar = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        for (var i = 0; i < num; i++)
            ar[i] %= 2;
        WriteLine(ar.Count(v => v == 1) % 2 == 0 ? "YES" : "NO");
    }
}


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

int main() {
  int n; cin >> n;
  vector<int> f(100000);
  for (int x = 1; x*x <= n; x++) {
    for (int y = 1; y*y <= n; y++) {
      for (int z = 1; z*z <= n; z++) {
        f[x*x+y*y+z*z+x*y+y*z+z*x]++;
      }
    }
  }
  rep(i, n) {
    cout << f[i+1] << endl;
  }
  return 0;
}

Measured memory_bytes: 3776
import           Data.Char                      ( isSpace )
import           Data.List                      ( unfoldr )
import qualified Data.ByteString.Char8         as C

main = do
    nm <- unfoldr (C.readInt . C.dropWhile isSpace) <$> C.getLine
    a  <- unfoldr (C.readInt . C.dropWhile isSpace) <$> C.getLine
    let holidays = head nm - sum a
    print $ if holidays >= 0 then holidays else -1


Measured memory_bytes: 5272
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <queue>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int h, w;
int dy[8] = { 1, 1, 1, 0, 0,-1,-1,-1};
int dx[8] = { 1, 0,-1, 1,-1, 1, 0,-1};

bool can(int y, int x) {
	if(0 <= y && y < h && 0 <= x && x < w) return true;
	return false;
}


int cnt[1005][1005];
bool inQ[1005][1005], used[1005][1005];

void printQ(queue<P> que) {
	cout << " ---- in queue --- " << endl;
	while(que.size()) {
		P p = que.front();
		que.pop();

		cout << "(" << p.first << "," << p.second << ") ";
	}
	cout << endl;
}

int main() {
	cin >> h >> w;

	vector<string> s(h);
	rep(i, h) cin >> s[i];

	memset(cnt, 0, sizeof(cnt));
	memset(used, 0, sizeof(used));
	memset(inQ, 0, sizeof(inQ));

	queue<P> que;
	rep(i, h) {
		rep(j, w) {
			if(s[i][j] != '.') {
				rep(k, 8) {
					int y = i + dy[k];
					int x = j + dx[k];
					if(can(y, x) && s[y][x] == '.') {
						cnt[i][j]++;
					}
				}
				if(s[i][j] - '0' <= cnt[i][j]) {
					que.push(mp(i, j));
					used[i][j] = true;
				}
			}
		}
	}


	int ans = 0;
	while(que.size()) {
		queue<P> tmp;
		while(que.size()) {
			P p = que.front();
			que.pop();

			rep(k, 8) {
				int y = p.first + dy[k];
				int x = p.second + dx[k];

				if(can(y, x)) {
					cnt[y][x]++;
					if(s[y][x] != '.' && (s[y][x] - '0') <= cnt[y][x] && !used[y][x]) {
						used[y][x] = true;
						tmp.push(mp(y, x));
					}
				}
			}
		}

		while(tmp.size()) {
			P p = tmp.front();
			tmp.pop();
			que.push(p);
		}

		ans++;
	}

	// rep(i, h) {
	// 	rep(j, w) {
	// 		if(s[i][j] == '.') cout << s[i][j];
	// 		else {
	// 			if(used[i][j]) cout << " ";
	// 			else cout << "X";
	// 		}
	// 		cout << " ";
	// 	}
	// 	cout << endl;
	// }

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 8208
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define mat vector<vector<ll>>

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  ll a,b;
  cin >>  a >> b;

  if(a<=b)cout << a << endl;
  else cout << a-1 << endl;

}

Measured memory_bytes: 3604
def sep():
    return map(int,input().strip().split(" "))
import sys
sys.setrecursionlimit(2*10**5)
from random import randint
def lis():
    return list(sep())

def maxAbsValExpr(x, y):
    res, n = 0, len(y)
    for p, q in [ [-1, 1], [-1, -1],[1, 1], [1, -1]]:
        smallest = p * x[0] + q * y[0] + 0
        for i in range(n):
            cur =   q * y[i] + p * x[i]
            res = max(res, cur - smallest)
            smallest = min(smallest, cur)
    return res
n=int(input())
x=[]
y=[]
for _ in range(n):
    a,b=sep()
    x.append(a)
    y.append(b)
print(maxAbsValExpr(x,y))



Measured memory_bytes: 106684
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

s = STR()
stack = deque()
for i in range(len(s)):
    if len(stack) and s[i] != stack[-1]:
        stack.pop()
    else:
        stack.append(s[i])
print(len(s) - len(stack))


Measured memory_bytes: 66668
import collections


N = int(input())
S = []
for _ in range(N):
    si = input()
    S.append(si)

# print(S)

c = collections.Counter(S)
# print(c)

ac = c["AC"]
wa = c["WA"]
tle = c["TLE"]
re = c["RE"]

print("AC x " + str(ac))
print("WA x " + str(wa))
print("TLE x " + str(tle))
print("RE x " + str(re))


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

int main()
{
    string o, e;
    cin >> o;
    cin >> e;
    string ans;
    rep(i, e.size()) {
        ans.push_back(o[i]);
        ans.push_back(e[i]);
    }
    if(o.size() != e.size()) {
        ans.push_back(o[o.size() - 1]);
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int a, b;
	cin>>a>>b;
	if(b >= a)
		cout<<"unsafe"<<endl;
	else
		cout<<"safe"<<endl;
	return 0;
}

Measured memory_bytes: 3580
n = int(input())
a = list(map(int,input().split()))
barlen = 0
for x in a:
  barlen += x
halflen = barlen/2
curbarlen = 0
minhalfdis = barlen
for i in range(n):
  curbarlen += a[i]
  minhalfdis = min(minhalfdis,abs(halflen-curbarlen))
print(int(minhalfdis*2))

Measured memory_bytes: 26056
import math
ABK = input().split()
A,B,K = int(ABK[0]), int(ABK[1]), int(ABK[2])
#約数列挙
taisyou = 0
if(A >= B):
    taisyou = B
else:
    taisyou = A
    
result= []

for i in range(1, taisyou+1):
    if(A % i == 0 and B % i == 0):
        result.append(i)

reversedResult = result[::-1]
print(reversedResult[K-1])

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

int main() {
    int n, yy; cin >> n >> yy;
    int x, y, z;

    bool ans = false;
    for (x = 0; x <= n; x++) {
        for (y = 0; y <= n -x; y++) {
            z = n - x - y;
            if (z < 0)
                continue;
            if (10000*x + 5000*y + 1000*z == yy) {
                ans = true;
                break;
            }
        }
        if (ans == true)
            break;
    }

    if (ans == false) {
        x = -1; y = -1; z = -1;
    }
    
    printf("%d %d %d\n", x, y, z);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)

int main(void){
    int n,m;
    cin >> n >> m;
    cout << (n==m ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
class Pair implements Comparable<Pair>
{
	int n;
	int dis;
	public Pair(int x,int d)
	{
		this.n=x;
		this.dis=d;
	}
	public int compareTo(Pair p)
	{
		if(this.dis>p.dis)
			return 1;
		else if(this.dis<p.dis)
			return -1;
		return 0;
	}
}
public class Main{
	static BufferedReader br;
	static int cin() throws Exception
	{
		return Integer.valueOf(br.readLine());
	}
	static int[] split() throws Exception
	{
		String[] cmd=br.readLine().split(" ");
		int[] ans=new int[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		}                                              
		return ans;
	} 
    public static void main(String[] args) throws Exception {
        br = new BufferedReader(new InputStreamReader(System.in));
        int n=cin();
        if(n>=30)
        	System.out.println("Yes");
        else
        	System.out.println("No");
    }
}


Measured memory_bytes: 32576
#include "bits/stdc++.h"
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define debug(var) std::cout << #var << " : " << var << std::endl;
using ll = long long;
using ull = unsigned long long;
using vint = std::vector<int>;
using vvint = std::vector<std::vector<int>>;
using namespace std;
ll mod = 1e9 + 7;

/*int <= 10^9*/
/*10^5までは全探索できる*/

int main() {


  int A, B, C; cin >> A >> B >> C;
  int ans = C - (A - B);
  if (ans < 0)ans = 0;
  cout << ans;


  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

int n;
int main() {
  cin >> n;
  int l = 1000000, r = 0;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    l = min(l, x);
    r = max(r, x);
  }
  cout << r - l << endl;
  return 0;
}

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

using namespace std;

int f(int x){
    if (x&1) return 3*x+1;
    return x/2;
}

void solve() {
    int s; cin >> s;
    map<int, int> mp;
    mp[s]++;
    int i = 1;
    while (true) {
        i++;
        s = f(s);
        if (++mp[s] >= 2) break;
    }
    cout << i;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  int l[N];
  for (size_t i{0}; i < N; ++i) {
    cin >> l[i];
  }
  sort(l, l + N, greater<int>());
  int total{0};
  for (size_t i{0}; i < K; ++i) {
    total += l[i];
  }
  cout << total << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repm(i, m, n) for (int i = m; i < (n); i++)
#define eps (1e-7)
#define inf (1e9)
#define pi (acos(-1))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

    int n;
    cin >> n;
    vi a(n);
    int max1 = 0, max2 = 0;
    //int count1 = 0;
    rep(i, n)
    {
        cin >> a[i];
        if (a[i] > max1)
        {
            max2 = max1;
            max1 = a[i];
            //count1 = 0;
        }
        else if (a[i] > max2)
        {
            // if (a[i] == max1)
            //     count1++;
            max2 = a[i];
        }
    }
    //cout << "*******" << endl;

    rep(i, n)
    {
        if (a[i] == max1)
            cout << max2 << endl;
        else
            cout << max1 << endl;
    }

    return 0;
}

Measured memory_bytes: 2432
h,w = map(int,input().split())
grid = []
count = 0
for _ in range(h):
    x = input()
    count += x.count(".")
    grid.append(x)
from collections import deque
que = deque([])
dist = [[-1]*w for _ in range(h)]
dist[0][0] = 0

delta = [(-1,0),(0,-1),(0,1),(1,0)]
que.append((0,0))
while len(que) > 0:
    vy,vx = que.popleft()
    for dy,dx in delta:
        y = vy + dy
        x = vx + dx
        if not (0<=y<h and 0<=x<w):
            continue
        if dist[y][x] != -1:
            continue
        if grid[y][x] == "#":
            continue
        dist[y][x] = dist[vy][vx] + 1
        que.append((y,x))
ans = dist[h-1][w-1] 
if ans == -1:
    print(-1)
else:
    print(count - ans - 1)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	int A, B, C, x;
	cin >> A >> B >> C >> x;
	int ans = 0;
	rep(a, A + 1) {
		rep(b, B + 1) {
			int rm = x - (500 * a + 100 * b);
			if (rm >= 0 && rm % 50 == 0 && rm / 50 <= C) {
				ans++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <tuple>
#include <string>
#include <cstdint>
#include <vector>
#include <array>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <cassert>
using namespace std;
using i64 = int64_t;
struct R { i64 s, t, x; };
i64 n, q;
vector<R> rs;
set<pair<i64, int>> ds;
int main() {
    cin >> n >> q;
    rs.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> rs[i].s >> rs[i].t >> rs[i].x;
    }
    sort(begin(rs), end(rs), [](R a, R b) {
        return a.x < b.x;
    });
    vector<i64> ans(q, -1);
    for (int i = 0; i < q; ++i) {
        i64 d;
        cin >> d;
        ds.emplace(d, i);
    }
    for (int i = 0; i < n; ++i) {
        auto sit = ds.lower_bound(make_pair(rs[i].s - rs[i].x, 0));
        auto tit = ds.lower_bound(make_pair(rs[i].t - rs[i].x, 0));
        for (auto it = sit; it != tit; ++it) {
            ans[it->second] = rs[i].x;
        }
        ds.erase(sit, tit);
    }
    for (int i = 0; i < q; ++i) {
        cout << ans[i] << '\n';
    }
    return 0;
}

Measured memory_bytes: 20608
#include<bits/stdc++.h>
using namespace std;
int dp[100001],k;
/*int ans(int a[],int n)
{if(n==0) return dp[0];
 if(n==1) return dp[1];
 if(dp[n]!=-1) return dp[n];
 int min=1000000;
 for(int i=n;i>n-k&&i>0;i--)
 {   int temp=ans(a,i-1)+abs(a[n]-a[i-1]);
     if(temp<min) min=temp;
 }
 dp[n]=min;
 return dp[n];
}*/
int main()
{   
    int n;
    cin>>n>>k;
    int a[n];
    int i,j;
    for(i=0;i<n;i++) cin>>a[i];
    memset(dp,1000000, sizeof(dp));
    dp[0]=0;dp[1]=abs(a[1]-a[0]);
    n--;
 for(j=0;j<=n;j++)
{   
     for(i=1;i<=min(j,k);i++)
 {  
			dp[j]=min(dp[j],abs(a[j]-a[j-i])+dp[j-i]);
 }
} 
    cout<<dp[n]<<endl;
    return 0;
} 

Measured memory_bytes: 1024
#include <iostream>
#include <string>

using namespace std;

struct Dice{
    int number[6];

    void roll(char ch){
        int nb;
        if(ch == 'E'){
            nb = number[0];
            number[0] = number[3];
            number[3] = number[5];
            number[5] = number[2];
            number[2] = nb;
        }
        if(ch == 'W'){
            nb = number[0];
            number[0] = number[2];
            number[2] = number[5];
            number[5] = number[3];
            number[3] = nb;
        }
        if(ch == 'N'){
            nb = number[0];
            number[0] = number[1];
            number[1] = number[5];
            number[5] = number[4];
            number[4] = nb;
        }
        if(ch == 'S'){
            nb = number[0];
            number[0] = number[4];
            number[4] = number[5];
            number[5] = number[1];
            number[1] = nb; 
        }
        if(ch == 'F'){
            nb = number[1];
            number[1] = number[2];
            number[2] = number[4];
            number[4] = number[3];
            number[3] = nb;
        }
    }

    int top(){
        return number[0];
    } 

    int right(){
        return number[2];
    }

    int left(){
        return number[3];
    }

    int front(){
        return number[1];
    }
};

int main(){
    Dice dice;
    for(int i = 0; i < 6; i++)
        cin >> dice.number[i];

    int q;
    cin >> q;

    
    while(q--){
        int a, b;
        cin >> a >> b;
        if(a == dice.left())
            dice.roll('E');
        if(a == dice.right())
            dice.roll('W');
        while(a != dice.top())
            dice.roll('N');
        while(b != dice.front())
            dice.roll('F');
        cout << dice.right() << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
int main () {
  string S;
  cin >> S;
  int counta = 0, countb = 0, countc = 0;
  for(int i = 0; i < S.size(); i++) {
    if(S.at(i) == 'a') {
      counta++;
    } if(S.at(i) == 'b') {
      countb++;
    } if(S.at(i) == 'c') {
      countc++;
    }
  }
  if(counta == 1 && countb == 1 && countc == 1)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
//参考：https://qiita.com/DaikiSuyama/items/9dba963ba74396b9b7fd
//インクルード(アルファベット順)
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define FIR first    //pairの一つ目の要素
#define SEC second   //pairの二つ目の要素

signed main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll a, b;
    cin >> a >> b;

    cout << ((a * b) % 2 == 0 ? "Even" : "Odd") << endl;

    return 0;
}


Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int n,b,f,r,v;
int a[4][3][10];




int main(){

    for(int i=0;i<4;i++){
    for(int j=0;j<3;j++){
        for(int k=0;k<10;k++){
            a[i][j][k] = 0;
        }
    }
}

    cin >> n;
    for(int i=0;i<n;i++){
        cin >> b >> f >> r >> v;
        a[b-1][f-1][r-1] += v;
    }

    for(int i=0;i<4;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<10;k++){
                cout << " " << a[i][j][k];
            }
            cout << endl;
        }
        if((3-i)){
            cout << "####################" << endl;
        }
    }

   
   return 0;
}


Measured memory_bytes: 3096
#include <cstdio>
#include <algorithm>
 
int n, x, min, cnt;
 
int main() {
    scanf("%d", &n);
    min = 1e6;
    for (int i = 0; i < n; ++i) {
        scanf("%d", &x);
        min = std::min(min, x);
        if (x == min) ++cnt;
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 128
import sys
from itertools import combinations

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
limit = (N-1) * (N-2) // 2
if K > limit:
    print(-1); exit()

A = [(1, x) for x in range(2, N+1)]
# limit - K だけ辺を引く
for i, (x, y) in zip(range(limit-K), combinations(range(2, N+1), 2)):
    A.append((x, y))

print(len(A))
for a in A:
    print(*a)


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

/* {1,2,3} -> ... -> {3,2,1} */
int next_permutation(char arr[],int n) {
	int target;
	int i;
	char temp;
	for (i = n - 2; i >= 0; i--) {
		if (arr[i] < arr[i + 1]) break;
	}
	if (i < 0) return 0;
	target = i;

	for (i = 0; target + i + 1 < n - i - 1; i++) {
		temp = arr[target + 1 + i];
		arr[target + 1 + i] = arr[n - 1 - i];
		arr[n - i - 1] = temp;
	}

	for (i = target + 1; i < n; i++) {
		if (arr[i] > arr[target]) break;
	}
	temp = arr[i];
	arr[i] = arr[target];
	arr[target] = temp;
	return 1;
}


int main(void) {
	int N;
	char P[16];
	char Q[16];
	char current[16];
	int i;
	int pidx = -1, qidx = -1;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		int nyan;
		if (scanf("%d", &nyan) != 1) return 1;
		P[i] = (char)nyan;
	}
	for (i = 0; i < N; i++) {
		int nyan;
		if (scanf("%d", &nyan) != 1) return 1;
		Q[i] = (char)nyan;
	}
	for (i = 0; i < N; i++) {
		current[i] = i + 1;
	}
	P[N] = Q[N] = current[N] = 0;
	i = 0;
	do {
		if (strcmp(P, current) == 0) pidx = i;
		if (strcmp(Q, current) == 0) qidx = i;
		i++;
	} while (next_permutation(current, N));
	if (pidx < 0 || qidx < 0) {
		puts("ERROR!");
		return 2;
	}
	printf("%d\n", abs(pidx - qidx));
	return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int sum = 0;
        for (int i = 0; i < m; i++) {
            sum += sc.nextInt();
        }

        System.out.println(sum > n ? "-1" : n - sum);
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 37868
import java.util.*
import kotlin.math.acos
import kotlin.math.cos
import kotlin.math.round
import kotlin.math.sin

fun main() {
    val n = readInt()
    val t = List(n) { readLong() }

    println(t.fold(1L) { acc, l -> lcm(acc, l) })
}


fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)



// 最大公約数
fun gcd(p: Long, q: Long): Long = if (p % q == 0L) q else gcd(q, p % q)

// 最小公倍数
fun lcm(p: Long, q: Long): Long = p / gcd(p, q) * q


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

int main() {
	int groupNum;
	int sheet = 100000;
	int from, to;
	int numMem = 0;

	cin >> groupNum;
	
	for (int i = 0; i < groupNum; i++) {
		cin >> from >> to;
		numMem = numMem + (to - from + 1);
	}
	cout << numMem << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
typedef long long ll;
 
using namespace std;
 
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.in","w",stdout);
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll i,j,k,n,x,d;
    cin>>x>>k>>d;
    x=abs(x);
    ll temp=x/d;
    temp=min(k,temp);
    k-=temp;
    if(k&1^1)cout<<x-d*temp;
    else cout<<min(abs((x-d*temp)+d),abs((x-d*temp)-d));

 
	
	
	
 
 
 
 
 
 
 
	return 0;
}

Measured memory_bytes: 3572
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

fn main() {
    input! {
        h: u64,
        w: u64
    }

    // 縦三等分
    let w1 = w / 3;
    let w2 = (w - w1) + 1 / 2;
    let ans1 = (w2 - w1) * h;

    let w1 = (w + 2) / 3;
    let w2 = (w - w1) / 2;
    let ans2 = (w1 - w2) * h;

    // 横三等分
    let h1 = h / 3;
    let h2 = (h - h1) + 1 / 2;
    let ans3 = (h2 - h1) * w;

    let h1 = (h + 2) / 3;
    let h2 = (h - h1) / 2;
    let ans4 = (h1 - h2) * w;

    // 縦三分の一、残り横に二分割
    let w1 = w / 3;
    let h1 = (h + 1) / 2;
    let ans5 = (w - w1) * h1 - w1 * h;

    let w1 = (w + 2) / 3;
    let h1 = h / 2;
    let ans6 = w1 * h - (w - w1) * h1;

    // 横三分の一、残り縦に二分割
    let h1 = h / 3;
    let w1 = (w + 1) / 2;
    let ans7 = (h - h1) * w1 - h1 * w;

    let h1 = (h + 2) / 3;
    let w1 = w / 2;
    let ans8 = h1 * w - (h - h1) * w1;

    let &ans = vec![ans1, ans2, ans3, ans4, ans5, ans6, ans7, ans8]
        .iter()
        .min()
        .unwrap();

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


Measured memory_bytes: 2144
S=list(input())
N=len(S)

ans='Yes'

for i in range((N-1)//2):
  if S[i]!=S[N-1-i]:
    ans='No'
    break

for i in range((N-1)//4):
  if S[i]!=S[(N-1)//2-1-i]:
    ans='No'
    break

print(ans)

Measured memory_bytes: 3060
n,k=map(int,input().split())

if k>(n-1)*(n-2)//2:
    print(-1)
    exit()

ansl=[(1,i) for i in range(2,n+1)]
now=[]
for i in range(2,n+1):
    for j in range(i+1,n+1):
        now.append((i,j))

ansl+=now[:(n-1)*(n-2)//2-k]
print(len(ansl))
for i,j in ansl:
    print(i,j)


Measured memory_bytes: 43120
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    int64_t H, W;
    cin >> H >> W;
    int64_t S_fin = H * W;
    rep(i, 0, 2){
        rep(w, 0, W + 1){
            int64_t S_1 = H * w;
            int64_t S_2 = (H/2) * (W - w);
            int64_t S_2_2 = ((H + 1)/2)*(W - w);
            int64_t S_3 = ((W - w)/2) * H;
            int64_t S_3_2 = ((W - w + 1) / 2) * H;
            int64_t S_dif_1 = max(abs(S_1 - S_2), abs(S_1 - S_2_2));
            int64_t S_dif_2 = max(abs(S_1 - S_3), abs(S_1 - S_3_2));
            int64_t S_dif = min(S_dif_1, S_dif_2);
            //cout << "w " << w << " S " << S_dif << endl;
            S_fin = min(S_fin, S_dif);
        }
        swap(W, H);
    }
    cout << S_fin << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int search(int*,int,int);

int main(){
  int i,n,m,A[10000],key,sum=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&m);
  for(i=0;i<m;i++){
    scanf("%d",&key);
    if(search(A,n,key)){
      sum++;
    }
  }
  printf("%d\n",sum);
  return 0;
}

int search(int A[],int n,int key){
  int i=0;
  A[n]=key;
  while(A[i]!=key)i++;
  return i!=n;
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
 
int n, m;
string dis(int g) {
	string t = to_string(g);
	while (t.size()<6) t = '0' + t;
	return t;
}

int main() {
	cin >> n >> m;
	vector<vector<P>> a(n);
	vector<string> ans(m);
	int p, y;
	rep(i,m) {
		cin >> p >> y;
		a[p-1].push_back({y, i});
	}

	int idx;
	rep(i,n) {
		if (a[i].empty()) continue; 
		sort(a[i].begin(), a[i].end());
		for (int j = 0; j < a[i].size(); j++)
		{
			idx = a[i][j].second;
			ans[idx] = dis(i+1) + dis(j+1);
		}
		
	}
	rep(i,m) {
		cout << ans[i] << endl;
	} 
	return 0;
}

Measured memory_bytes: 11924
import heapq
N,M=map(int,input().split())

ab=[[] for _ in range(M)]
for i in range(N):
  b,a=map(int,input().split())
  if b<=M:
    ab[b-1].append(a)

sal=0
poss=[]
for i in range(1,M+1):
  for j in ab[i-1]:
    heapq.heappush(poss,-j)
  if len(poss)>0:
    sal+=-heapq.heappop(poss)
    
print(sal)

Measured memory_bytes: 18368
n = int(input())
p = []
for i in range(n):
    p.append(int(input()))

count = 0
if p[0] != 0:
    print(-1)
    exit()

for i in range(1, n):
    diff = p[i] - p[i - 1]
    if diff >= 2:
        print(-1)
        exit()
    elif diff == 1:
        count += 1
    else:
        count += p[i]

print(count)


Measured memory_bytes: 11052
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


int main() {
	int N;
	cin >> N;
	vector<int>A(N);
	int ma = -1;
	int ind = -1;
	int f = -1;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		if (abs(A[i]) > ma) {
			ma = abs(A[i]);
			ind = i;
			f = (A[i] >= 0);
		}
	}

	vector<pair<int, int>>ans;
	for (int i = 0; i < N; i++) {
		if (i == ind)continue;
		ans.pb({ind+1,i+1});
	}

	if (f == 1) {
		for (int i = 0; i < N - 1; i++)ans.pb({i+1,i+2});
	}
	else {
		for (int i = N-1; i > 0; i--)ans.pb({i+1,i});
	}
	puts(ans.size());
	fore(x, ans)cout << x.first << " " << x.second << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
using namespace std;
using ll=long long;
const ll MOD=100000007;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=b-1;i>=a;i--)
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline constexpr int intpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans%MOD*(b&1?a:1)%MOD;
}
inline constexpr int modf(ll n){
    ll ans=1;
    rep(i,0,n) {ans=ans*(n-i)%MOD;}
    return ans;
}
inline long double median(vector<ll> v){
    ll size=v.size();
    sort(v.begin(),v.end());
    if (size % 2 == 1) return v[(size - 1) / 2];
    else return (v[(size / 2) - 1] + v[size / 2]) / 2;
}


const vector<ll> dx={0,1,0,-1,1,1,-1,-1};
const vector<ll> dy={1,0,-1,0,-1,1,-1,1};

int main(){
    ll h,w;
    cin>>h>>w;
    ll cnt=0;
    vector<string> s(h);
    rep(i,0,h) {
        cin >> s[i];
        rep(j,0,w) {
            if(s[i][j]=='.') cnt++;
        }
    }
    vector<vector<ll>> m(h,vector<ll>(w,INF));
    m[0][0]=1;
    queue<pair<ll,ll>> q;
    q.push({0,0});
    while(!q.empty()){
        ll x=q.front().first,y=q.front().second;
        q.pop();
        rep(i,0,4){
            ll x2=x+dx[i],y2=y+dy[i];
            if(x2<0||x2>=h||y2<0||y2>=w)continue;
            if(m[x2][y2]>m[x][y]+1&&s[x][y]=='.'){
                m[x2][y2]=m[x][y]+1;
                q.push({x2,y2});
            }
        }
    }
    if(m.back().back()==INF) {cout<<-1;return 0;}
    cout<<cnt-m.back().back();//m[h-1][w-1]
}





Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
 
int main(){
    string s;
    cin>>s;
    string ans="";
    if(s=="Sunny") ans = "Cloudy";
    else if (s=="Cloudy") ans = "Rainy";
    else ans = "Sunny";

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


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

map<int, int> bitCount;

void countBit(int num) {
  for (int i = 0; i < 32; i++) {
    if (num>>i & 1) {
      bitCount[i]++;
    }
  }
}

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

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

  for (int i = 0; i < N; i++) {
    countBit(a[i]);
  }

  for (int i = 0; i < N; i++) {
    int ans = 0;
    for (int bits = 0; bits < 32; bits++) {
      if (bitCount[bits]%2==0) {
        if (a[i]>>bits & 1) ans += 1<<bits;
      } else {
        if (!(a[i]>>bits & 1)) ans += 1<<bits;
      }
    }
    cout << ans << " ";
  }

  return 0;
}

Measured memory_bytes: 4312
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>pppp(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
 
int main() {
  int N;
  cin>>N;
  vector<int>a(N);
  map<int,int>k;
  for(int i=0;i<N;i++){
    cin>>a[i];
    k[a[i]]++;
  }
  int sum=0;
  for(auto a:k){
    int s=a.first;
    int b=a.second;
    if(b<s){sum+=b;}
    if(b>s){sum+=b-s;}
  }
  cout<<sum<<endl;
 return 0;
}

Measured memory_bytes: 8272
n = int(input())
a = list(map(int,input().split()))
print(" ".join(map(str,a)))
def insertsort(m,b):
    j = 1
    while j <= m - 1:
        for t in range(0,j):
            if b[t] > b[j]:
                b[t],b[j] = b[j],b[t]
        j += 1
        print(" ".join(map(str,b)))

insertsort(n,a) 




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

public class Hello
{
    public static void Main()
    {
        
        
        int[] a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        int[] b = Console.ReadLine().Split(' ').Select(y => int.Parse(y)).ToArray();
        int H = a[0];
        int W = a[1];
        int h = b[0];
        int w = b[1];
        
        int ans = (H * W) - ((h * W) + (w * (H - h)));
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

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


ll A,B,C,D;

int main(){
    cin>>A>>B>>C>>D;

    ll x=lcm(C,D);
    ll ans=B-A+1-(B/C-(A-1)/C)-(B/D-(A-1)/D)+(B/x-(A-1)/x);

    cout<<ans<<endl;
}

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

int main() {
  int N;
  cin >> N;
  int INF = 100000000;
  vector<int> dp(N+1, INF);
  dp.at(0) = 0;
  // 配る DP
  for (int i = 0; i < N; i++) {
    for (int pow6 = 1; i + pow6 <= N; pow6 *= 6) {
      dp.at(i+pow6) = min(dp.at(i+pow6), dp.at(i) + 1);
    }
    for (int pow9 = 1; i + pow9 <= N; pow9 *= 9) {
      dp.at(i+pow9) = min(dp.at(i+pow9), dp.at(i) + 1);
    }
  }
  cout << dp.at(N) << endl;
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, m, x;
  while (cin >> n >> m >> x) {
    vector<int> a(m);
    cin >> a;
    sort(a.begin(), a.end());
    each (i, a) --i;

    int z = 0;
    for (int i = x - 1; i <= n; ++i) {
      if (binary_search(a.begin(), a.end(), i)) {
        ++z;
      }
    }

    int y = 0;
    for (int i = x - 1; 0 <= i; --i) {
      if (binary_search(a.begin(), a.end(), i)) {
        ++y;
      }      
    }
    
    cout << min(z, y) << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
vector<int> w,v;
vector<long long> f;
int main()
{
    int n,c;
    int i,j;
    scanf("%d %d",&n,&c);
    w.resize(n+1);
    v.resize(n+1);
    f.resize(c+1);
    for(i=1;i<=n;i++)
    {
	scanf("%d %d",&w[i],&v[i]);
    }
    for(i=1;i<=n;i++)
    {
	for(j=c;j>=w[i];j--)
	{
	    f[j]=max(f[j],f[j-w[i]]+v[i]);
	}
    }
    printf("%lld\n",f[c]);
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include<set> 
#include<math.h>
#define pai 3.14159265358979323846264338327950288;
#define keta(n) cout << fixed << setprecision((n));
using ll = long long;
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n){
    cin>>a[i];
  }
  int count = 0;
  
  while(true){
    bool finish = false;
    rep(i,n){
    if(a[i]%2==1)
      finish = true;
    }
    if(finish) break;
    
    
     rep(i,n){
       if(a[i]%2==0)
       a[i] = a[i]/2;
   	 }
       count++;
  }
   
   cout<<count<<endl;



}


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

int main(){
	ll N, A, B;
	cin >> N >> A >> B;
	ll ans = B*(N-1) + A - B - A*(N-1) + 1;
	ans = max(ans, (ll)0);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3612
#include <stdio.h>

int map[30][30];
int W,H;

int head,tail;
typedef struct{
    int x;
    int y;
    int count;   
} step;

step queue[900];

int pop(step **next){
    if(head==tail)return 0;
    *next=&(queue[head]);
    head++;
    return 1;
}

void push(int x,int y, int count){
    queue[tail].x=x;
    queue[tail].y=y;
    queue[tail].count=count;
    tail++;
}

void clear(void){
    head=0;
    tail=0;
}

int isEmpty(void){
    if(head==tail){
        return 1;
    }
    return 0;
}

int isChecked(int x,int y){
    if(map[x][y]&16){
        return 1;
    }else{
        return 0;
    }
}

void setChecked(int x,int y){
    map[x][y]|=16;
}

int main(void){
    while(scanf("%d %d",&W,&H),W||H){
        int i,j,wall,x,y,count;
        step* next;
        for(i=0;i<30;i++){
            for(j=0;j<30;j++){
                map[i][j]=0;
            }
        }
        for(i=0;i<2*H-1;i++){
            if(i%2==0){//?¨?
                for(j=0;j<W-1;j++){
                    scanf("%d",&wall);
                    if(wall){
                        map[j][i/2]+=1;//???
                        map[j+1][i/2]+=2;//???
                    }
                }
            }else{
                for(j=0;j<W;j++){
                    scanf("%d",&wall);
                    if(wall){
                        map[j][i/2]+=4;//???
                        map[j][i/2+1]+=8;//???
                    }
                }
            }
        }        
        clear();
        push(0,0,1);
        int end=0;
        while(pop(&next)){
        //printf("head:%d tail:%d next:%p\n",head,tail,next);
            x=next->x;
            y=next->y;
            count=next->count;
            //printf("x:%d y:%d count:%d\n",x,y,count);
            if(x==W-1&&y==H-1){
                printf("%d\n",count);
                end=1;
                break;
            }
            if((map[x][y]&1)==0&&x+1<W){
                if(!isChecked(x+1,y)){
                    push(x+1,y,count+1);
                    setChecked(x+1,y);
                }
            }
            if((map[x][y]&2)==0&&x>0){
                if(!isChecked(x-1,y)){
                    push(x-1,y,count+1);
                    setChecked(x-1,y);
                }
            }
            if((map[x][y]&4)==0&&y+1<H){
                if(!isChecked(x,y+1)){
                    push(x,y+1,count+1);
                    setChecked(x,y+1);
                }
            }
            if((map[x][y]&8)==0&&y>0){
                if(!isChecked(x,y-1)){
                    push(x,y-1,count+1);
                    setChecked(x,y-1);
                }
            }
        }
        if(end==0){
            printf("%d\n",0);
        }
    }
    
    return 0;
}

Measured memory_bytes: 612
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
	ll n,flag=0;
	cin>>n;
	ll arr[n];
	map<ll,ll> mp;
	for(ll i=0;i<n;i++)
	{
		cin>>arr[i];
		++mp[arr[i]];
	}
	for(ll i=0;i<n;i++)
	{
		if(mp[arr[i]]>1)
		flag=1;
	}
	if(flag==0)
	cout<<"YES"<<endl;
	else
	cout<<"NO"<<endl;
	return 0;
}

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

int main() {
  int A, B, D;
  double C;
  cin >> A >> B;
 
  C = (A+B)/2;
  if ( (A+B)%2 == 0 ){
    cout << C <<endl;
  }else{
      D = C;
      cout << D+1 << endl;
  }
}
 

Measured memory_bytes: 256
import math
import itertools
import heapq
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect, bisect_left, bisect_right
from collections import defaultdict, deque


# d = defaultdict(lambda: 0)
# setrecursionlimit(10**7)
# inf = float("inf")


##### stdin ####
def LM(t, r): return list(map(t, r))
def R(): return stdin.readline()
def RS(): return R().split()
def I(): return int(R())
def F(): return float(R())
def LI(): return LM(int,RS())
def LF(): return LM(float,RS())
def ONE_SL(): return list(input())
def ONE_IL(): return LM(int, ONE_SL())
def ALL_I(): return map(int, stdin)
def ALL_IL(): return LM(int,stdin)

##### tools #####
def ap(f): return f.append
def pll(li): print('\n'.join(LM(str,li)))
def pljoin(li, s): print(s.join(li))

##### main #####

def primes(max_number):
    """
    指定値未満の素数を取得するジェネレータ
    https://qiita.com/Mokkeee/items/93b6b7d59fa256aa1677
    """
    if max_number <= 2:
        raise StopIteration
    yield 2
    is_prime = [1] * max_number
    square_root_of_max = max_number ** 0.5
    for number in range(3, max_number, 2):
        if is_prime[number] is 0:
            continue
        yield number
        if number <= square_root_of_max:
            for multiple in range(number * 2, max_number, number):
                is_prime[multiple] = 0

def main():
	P = list(primes(10**5))
	P = [p for p in P[1:] if (p+1)//2 == P[bisect_left(P, (p+1)//2)]]
	n = I()

	for i in range(n):
		l, r = LI()
		a = bisect_left(P,l)
		b = bisect_right(P,r)
		print(b-a)


if __name__ == '__main__':
	main()

Measured memory_bytes: 4836
# -*- coding: utf-8 -*-

S = str(input())

def word_to_num(word):
    ret = ""
    R_count = word.count('R')
    if len(word) % 2 == 1:
        if R_count - 1 > 0:
            for i in range(R_count-1):
                ret += "0 "
        if R_count % 2 == 1:
            ret += str(len(word) // 2 + 1) + " "
            ret += str(len(word) // 2) + " "
        else:
            ret += str(len(word) // 2) + " "
            ret += str(len(word) // 2 + 1) + " "
        if len(word) - R_count - 1 > 0:
            for i in range(len(word) - R_count - 1):
                ret += "0 "
    else:
        if R_count - 1 > 0:
            for i in range(R_count-1):
                ret += "0 "
        ret += str(len(word) // 2) + " "
        ret += str(len(word) // 2) + " "
        if len(word) - R_count - 1 > 0:
            for i in range(len(word) - R_count - 1):
                ret += "0 "
    return ret

pre = "R"
word = ""
output = ""
for i in range(len(S)):
    if pre != S[i] and S[i] == "R":
        output += word_to_num(word)
        word = "R"
        pre = S[i]
    else:
        word += S[i]
        pre = S[i]
        
output += word_to_num(word)
print(output.rstrip())








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

int parent[100001];
int rnk[100001];

int find(int i) {
  if (i == parent[i]) {
    return i;
  }
  return parent[i] = find(parent[i]);
}
void unite(int i, int j) {
  int x = find(i);
  int y = find(j);
  if (x == y) {
    return;
  }
  if (rnk[x] < rnk[y]) {
    parent[x] = y;
  } else {
    parent[y] = x;
    if (rnk[x] == rnk[y]) {
      ++rnk[x];
    }
  }
}
int n, m;
int main() {
  cin>>n>>m;
  map<int, vector<int> > a;
  for (int i=0; i<n; i++) {
    int k;
    cin>>k;
    for (int j=0; j<k; j++) {
      int l;
      cin>>l;
      a[l].push_back(i);
    }
  }
  for (int i=0; i<n; i++) {
    parent[i] = i;
    rnk[i] = 0;
  }
  for (auto b: a) {
    vector<int> v = b.second;
    int p = v[0];
    for (int i=1; i<v.size(); ++i) {
      int e = v[i];
      unite(e, p);
    }
  }
  set<int> x;
  for (int i=0; i<n; i++) {
    x.insert(find(i));
  }
  if (x.size() == 1) {
    cout<<"YES"<<endl;
  } else {
    cout<<"NO"<<endl;
  }
}

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

int main(){
    long int a[200000],n,cha;
    
    cin>>n;
    for(long int i=0;i<n;i++){
        //scanf("%ld",&s[i]);
        cin>>a[i];
    }
    
    long int back = 0;
    for(long int j=1;j<n;j++){
        back += a[j];
    }
    
    long int front = a[0];
    
    cha = abs(back - front);
    
    for(long int k=1;k<n-1;k++){
        front += a[k];
        back -= a[k];
        if(abs(front - back)<cha){
            cha = abs(front -back);
        }
    }
    cout<<cha<<endl;
    //printf("%ld\n",cha);
}


Measured memory_bytes: 1792
<?php

fscanf(STDIN, "%d%d", $k, $x);

$start = $x - $k + 1;
if($start<-1000000){
    $start = -1000000;
}
$end = $x + $k -1;

if($end > 1000000){
    $end = 1000000;
}
$list = [];
for($i=$start;$i<=$end;$i++){
    $list[] = $i;
}
echo implode(" ", $list);

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

using namespace std ;

#define ll long long

ll a , b ;

bool so ( ll x ){
    if ( x % 2 == 1 ){
        return 1 ;
    }
    return 0 ;
}

int main ()
{
    cin >> a >> b ;
    if ( so ( a ) &&  so ( b ) )
    {
        cout << "Yes" ;
        return 0 ;
    }
    cout << "No" ;
    return 0 ;
}

Measured memory_bytes: 256
PROGRAM piyo
      IMPLICIT NONE
      integer(16) :: n,m,ans
      integer(16) :: a(10**4)
      
      read*,n,m
      read*,a(1:m)
      
      ans = n - sum( a(1:m) )
      
      if( ans>=0 )then
        print*,ans
      else
        print*,'-1'
      end if
      
      
      
      
      
      
      END PROGRAM

Measured memory_bytes: 2992