akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <stdlib.h>

int main(){
	int n,l,total=0;
	scanf("%d%d",&n,&l);
	for(int i=1;i<=n;i++){
		total+=l+i-1;
	}
	if(l>0){
		printf("%d", total-l);
	}else if(l+n-1<0){
		printf("%d", total-(l+n-1));
	}else{
		printf("%d", total);
	}
	return 0;
}


Measured memory_bytes: 128
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { it.toInt() }
    val b = readLine()!!.split(" ").map { it.toInt() }
    val c = readLine()!!.split(" ").map { it.toInt() }
    var ans = 0
    for (i in 0 until n) {
        ans += b[a[i] - 1]
        if (i > 0 && a[i-1] + 1 == a[i]) ans += c[a[i - 1] - 1]
    }
    println(ans)
}

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

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

struct E {
	int v, a, b;
	E(int _v, int _a, int _b): v(_v), a(_a), b(_b) {}
};

const int mx = 5000;

int n, m, s;
vector <E> g[55];
int C[55], D[55];
int id[55][5555], vu[255555], vs[255555], cnt;
ll dis[255555];

int main() {
	scanf("%d %d %d", &n, &m, &s);
	rep(i, m) {
		int u, v, a, b;
		scanf("%d %d %d %d", &u, &v, &a, &b);
		-- u; -- v;
		g[u].pb(E(v, a, b));
		g[v].pb(E(u, a, b));
	}
	rep(i, n) scanf("%d %d", &C[i], &D[i]);
	rep(i, n) rep(j, mx + 1) {
		id[i][j] = cnt;
		vu[cnt] = i; vs[cnt] = j;
		cnt ++;
	}
	memset(dis, 0x3f, sizeof(dis));
	dis[id[0][min(s, mx)]] = 0;
	priority_queue <pair <ll, int> > pq;
	pq.push(mp(0, id[0][min(s, mx)]));
	while (!pq.empty()) {
		int u = vu[pq.top().second];
		int s = vs[pq.top().second];
		ll d = -pq.top().first;
		pq.pop();
		if (d != dis[id[u][s]]) continue;
		rep(i, g[u].size()) {
			int v = g[u][i].v, a = g[u][i].a, b = g[u][i].b;
			if (s < a) continue;
			int to = id[v][s - a];
			if (dis[to] > d + b) {
				dis[to] = d + b;
				pq.push(mp(-dis[to], to));
			}
		}
		int to = id[u][min(s + C[u], mx)];
		if (dis[to] > d + D[u]) {
			dis[to] = d + D[u];
			pq.push(mp(-dis[to], to));
		}
	}
	rep(u, n) if (u) {
		ll ans = 1e18;
		rep(j, mx + 1) ans = min(ans, dis[id[u][j]]);
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 12288
//AtCoder ABC052 B - Increment Decrement
#include <bits/stdc++.h>
using namespace std;
using lli=int64_t;

int main() {
    int N;
    string S;
    cin>>N>>S;
    int v=0;
    int ans=0;
    for(auto&& s:S){
        if(s=='I') ++v;
        else --v;
        ans=max(v,ans);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

string S;

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

  cin >> S;
  int N = S.size();

  int ans = 0;
  if (N%2 == 0) {
    int mid = N/2;
    int count = 0;
    for (int i = mid-1; i >= 0; --i) {
      if (S[i] == S[2*mid-i-1]) {
        count += 2;
      } else {
        break;
      }
    }
    ans = (N-count)/2 + count;
  } else {
    int mid = N/2;
    int count = 1;
    for (int i = 1; mid-i >= 0; ++i) {
      if (S[mid-i] == S[mid+i] && S[mid] == S[mid-1]) {
        count += 2;
      } else {
        break;
      }
    }
    ans = (N-count)/2 + count;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
<?php
    list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
    $a = str_split($a);
    $b = str_split($b);
    $c = str_split($c);
    if($a[count($a)-1] == $b[0] && $b[count($b)-1] == $c[0]) echo "YES";
    else echo "NO";
?>

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

def solve():
    N, M = map(int, input().split())
    max_int = 2**32-1
    dp = [max_int]*2**N
    dp[0] = 0
    for i in range(M):
        a, b = map(int, input().split())
        d = sum(2**c for c in map(int, input().split()))>>1
        for j in range(2**N+1):
            if j|d == d:
                dp[j] = min(dp[j],a)
            elif j&d:
                dp[j] = min(dp[j], dp[j-(j&d)]+a)

    res = dp[-1] if dp[-1] < max_int else -1
    return str(res)

if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ROCK ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f first
#define sec second
using namespace std;
using namespace __gnu_pbds;
const long long int linf =(long long)9223372036854775807;
const int dx[8] =  {0,0,1,-1,1,-1,1,-1},dy[9] = {1,-1,0,0,1,-1,-1,1};
typedef long long int ll;

const int N=1e5+3;
ll arr[N],dp[N],n;

ll solve(int pos){
    if(pos==n-1)return 0;
    if(dp[pos]!=-1)return dp[pos];
    ll onestep=1e9;
    ll twostep=1e9;
    if(pos+1<n)onestep=solve(pos+1)+abs(arr[pos]-arr[pos+1]);
    if(pos+2<n)twostep=solve(pos+2)+abs(arr[pos]-arr[pos+2]);
    ll ans=min(onestep,twostep);
    return dp[pos]=ans;
}

int main()
{
    ROCK;
    memset(dp,-1,sizeof dp);
    cin>>n;
    for(int i=0;i<n;i++)cin>>arr[i];
    cout<<solve(0)<<endl;
    return 0;
}












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

def input_one_number():
    return int(input())

def input_multiple_number():
    return map(int, input().split())

def input_multiple_number_as_list():
    return list(map(int, input().split()))


A , V = input_multiple_number()
B, W = input_multiple_number()
T = input_one_number()

D = abs(B-A)
v = V-W

if D - v*T > 0 :
	print("NO")
else:
	print("YES")



Measured memory_bytes: 9124
#include<string>
#include<iomanip>
#include<iostream>
using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); i++)
		cout << "x";
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
struct P
{
    //string r;
    int x,y,z;

    bool operator<(const P &a)const{
       // if(y!=a.y)
       // return y>a.y;
       return x>a.x;
//        return z>a.z;
    }
};

vector<P> v[5555];
//bitset<4001000> b;
int a,c,i,b,k,d,n,m,e;//dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};//
int l[115555];
int o[115400];
int dx[10]={0,1,0,-1},dy[10]={1,0,-1,0},dz[10]={0,0,0,0,1,-1};

long long x,y,z,mod=1000000007;
P u[111111];
double j[111];

stack<int> s;
queue<P> q;
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
map<int,int > p;
//list<int> l;
string r;
//char r[333][333];


bool as(P a,P b)
{
    if(a.x!=b.x) return a.x<b.x;
    return a.y>b.y;
}

int main()
{
    scanf("%d %d",&a,&b);
    for(int t=1;t<=a;t++)
        scanf("%d",&o[t]);
    for(int t=1;t<a;t++)
        if(o[t]+o[t+1]>=b) k=t;
    if(k)
    {
        puts("Possible");
        for(int t=1;t<k;t++)
            printf("%d\n",t);
        for(int t=a-1;t>k;t--)
            printf("%d\n",t);
        printf("%d",k);

    }
    else puts("Impossible");
}


Measured memory_bytes: 1408
#include <stdio.h>

void print(int dn, char c1, char c2, char c3, char c4);

int main(void) {
	int sx, sy, tx, ty, dx, dy, i;
	scanf("%d%d%d%d", &sx, &sy, &tx, &ty);
	dx = tx - sx;
	dy = ty - sy;

	if (dy == 0) {
		print(dx, 'U', 'D', 'R', 'L');
		return 0;
	}
	if (dx == 0) {
		print(dy, 'R', 'L', 'U', 'D');
		return 0;
	}
	if (dy > 0) {
		for (i = 0; i < dy; i++) {
			printf("U");
		}
	}
	else {
		for (i = 0; i < -dy; i++) {
			printf("D");
		}
	}
	if (dx > 0) {
		for (i = 0; i < dx; i++) {
			printf("R");
		}
	}
	else {
		for (i = 0; i < -dx; i++) {
			printf("L");
		}
	}

	if (dy > 0) {
		for (i = 0; i < dy; i++) {
			printf("D");
		}
	}
	else {
		for (i = 0; i < -dy; i++) {
			printf("U");
		}
	}
	if (dx > 0) {
		for (i = 0; i < dx; i++) {
			printf("L");
		}
	}
	else {
		for (i = 0; i < -dx; i++) {
			printf("R");
		}
	}

	if (dx > 0) {
		printf("L");
	}
	else {
		printf("R");
	}
	if (dy > 0) {
		for (i = 0; i <= dy; i++) {
			printf("U");
		}
	}
	else {
		for (i = 0; i <= -dy; i++) {
			printf("D");
		}
	}
	if (dx > 0) {
		for (i = 0; i <= dx; i++) {
			printf("R");
		}
	}
	else {
		for (i = 0; i <= -dx; i++) {
			printf("L");
		}
	}
	if (dy > 0) {
		printf("D");
	}
	else {
		printf("U");
	}

	if (dx > 0) {
		printf("R");
	}
	else {
		printf("L");
	}
	if (dy > 0) {
		for (i = 0; i <= dy; i++) {
			printf("D");
		}
	}
	else {
		for (i = 0; i <= -dy; i++) {
			printf("U");
		}
	}
	if (dx > 0) {
		for (i = 0; i <= dx; i++) {
			printf("L");
		}
	}
	else {
		for (i = 0; i <= -dx; i++) {
			printf("R");
		}
	}
	if (dy > 0) {
		printf("U");
	}
	else {
		printf("D");
	}
	return 0;
}

// U, D, R, L
void print(int dn, char c1, char c2, char c3, char c4) {
	int i;

	if (dn > 0) {
		for (i = 0; i < dn; i++) {
			printf("%c", c1);
		}
	}
	else {
		for (i = 0; i < -dn; i++) {
			printf("%c", c2);
		}
	}
	printf("%c", c3);
	if (dn > 0) {
		for (i = 0; i < dn; i++) {
			printf("%c", c2);
		}
	}
	else {
		for (i = 0; i < -dn; i++) {
			printf("%c", c1);
		}
	}
	printf("%c", c4);
	printf("%c", c4);
	if (dn > 0) {
		for (i = 0; i < dn; i++) {
			printf("%c", c1);
		}
	}
	else {
		for (i = 0; i < -dn; i++) {
			printf("%c", c2);
		}
	}
	printf("%c", c3);
	
	if (dn > 0) {
		printf("%c", c1);
	}
	else {
		printf("%c", c2);
	}
	printf("%c", c3);
	printf("%c", c3);
	if (dn > 0) {
		for (i = 0; i < dn + 2; i++) {
			printf("%c", c2);
		}
	}
	else {
		for (i = 0; i < -dn + 2; i++) {
			printf("%c", c1);
		}
	}
	printf("%c", c4);
	printf("%c", c4);
	if (dn > 0) {
		printf("%c", c1);
	}
	else {
		printf("%c", c2);
	}
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
	
	int n,k,ans = 1;
	cin >> n >> k;
	for(int i = 0 ; i<n ; i++){
		if(ans <= k){
			ans += ans; 
		}
		else{
			ans += k;
		}
	}
	cout << ans;
	
	return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import sys
import itertools
import math

n=int(input())
point=[]

for i in range(n):
    arr=list(map(int,input().split()))
    point.append(arr)
ans=[]
l = [i for i in range(n)]

for v in itertools.permutations(l, n):
    dist=0
    for j in range(len(v)-1):
        dist+=math.sqrt(math.pow((point[v[j]][0]-point[v[j+1]][0]),2)+math.pow((point[v[j]][1]-point[v[j+1]][1]),2))
    ans.append(dist)
print(sum(ans)/len(ans))

Measured memory_bytes: 10600
#include <stdio.h>

int main() {
	int N, p[10], max = 0, sum = 0, i;

	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d", &p[i]);
		sum = sum + p[i];
		if (p[i] > max) max = p[i];
	}

	sum = sum - max / 2;
	printf("%d", sum);

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
using namespace std;

#define INT long long int

using namespace std;
string s;

INT dp(int x, INT v, INT z) {
    if (x == s.size()) return z + v;
    return dp(x + 1, v * 10 + (s[x] - '0'), z) + dp(x + 1, (s[x] - '0'), z + v);
}

int main() {
    cin >> s;
    cout << dp(1, s[0] - '0', 0);
}

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

int main(){
	string s;
	cin >> s;
	int i, count=0, max=0;
	for(i=0; i<s.size(); i++){
		if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T'){
			count++;
			if(max<count){
				max=count;
			}
		}
		else{
			count=0;
		}
	}
	
	cout << max << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rem(i, s, n) for (int i = (s); i >= (n); --i)
using ll = long long;
const int MAX = 1e9+7;

int main(){
    int n, k; cin >> n >> k;
    vector<ll> h(n); rep(i, 0, n) cin >> h[i];

    vector<ll> v(n, MAX); v[0] = 0;
    rep(i, 1, n){
        rep(j, 1, k+1){
            if(i >= j) v[i] = min(v[i], v[i-j] + abs(h[i-j] - h[i]));
        }
    }

    cout << v[n-1] << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <limits.h>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> pii;

int n, q;
vector<int> v;

int query(int a, int b, int k, int l, int r) {
	if(r <= a || b <= l) return INT_MAX;
	if(a <= l && r <= b) return v[k];
	int vl = query(a, b, k*2+1, l, (l+r)/2);
	int vr = query(a, b, k*2+2, (l+r)/2, r);
	return min(vl, vr);
}

int main() {
	cin >> n >> q;
	int _n = n;
	n = 1;
	while(n < _n) n *= 2;
	v.resize(2*n-1, INT_MAX);
	rep(i, q) {
		int c, x, y;
		cin >> c >> x >> y;
		if(c == 0) {
			x += n-1;
			v[x] = y;
			while(x > 0) {
				x = (x-1) / 2;
				v[x] = min(v[x*2+1], v[x*2+2]);
			}
		}
		else {
			cout << query(x, y+1, 0, 0, n) << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 2060
#include <stdio.h>

int main(void) {

	int i = 0, j;
	int data[10000];
	
	while (1) {
		scanf("%d", &data[i]);
		if (data[i] == 0) {
			break;
		}
		else {
			i++;
		}
	}
	
	for (j = 0; j <= i; j++) {
		if (data[j] != 0) {
			printf("Case %d: %d\n", j + 1, data[j]);
		}
	}

	return 0;
}

Measured memory_bytes: 2720
#Code festival 2017 qual B
from collections import Counter
n = int(input())
d = Counter(map(int,input().split()))
m = int(input())
t = Counter(map(int,input().split()))

#print(d)
#print(t)
flg = True
for i in t.keys():
    if t[i] > d[i]:
        print('NO')
        flg = False
        break
        
if flg:
    print('YES')
        

Measured memory_bytes: 67032
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=4999999996000000001;

int main(){
    int x;
    cin>>x;
    if(x==1){
        cout<<0<<endl;
    }else{
        cout<<1<<endl;
    }


}

Measured memory_bytes: 3192
/**
 * @brief  0-1ナップサック問題(0-1 knapsack problem)は次の問題である
 *
 *         泥棒がある店に盗みに入ってn個の品物を見つけた. i番目の品物はviドルの価値があり、重さはwiポンドである
 *         ただし、viとwiは整数である. 彼はできるだけ高価な品物を盗りたいが、彼のナップサックでは高々Wポンド(Wは整数)の荷物しか運べない
 *
 *         各品物は盗るか残すかのどちらかなので、この問題は0-1ナップサック問題と呼ばれる
 *         この泥棒は品物の一部だけを盗ったり、同じものを複数回盗ることはできない
 *
 * @note   n個の各品物について、「盗る」か「残す」かの組み合わせをすべて調べるアルゴリズムの計算効率はΟ(2^n)となってしまい、　
 *         大きな入力nに対して解くことができないが、品物の大きさw, ナップサックの大きさWがともに整数であれば、
 *         0-1ナップサック問題は動的計画法によりΟ(nW)の計算効率で厳密解を求めることができる
 *
 * @note   次のような変数を用意する
 *
 *           v[n+1]       i番目の品物の価値が記録されている1次元配列
 *           w[n+1]       i番目の品物の重さが記録されている1次元配列
 *           C[n+1][W+1]  i個目までの品物を考慮して大きさjのナップサックに入れる場合の価値の合計の最大値をC[i][j]とする2次元配列
 *
 *         考慮する品物の数i, 各iにおけるナップサックの重さjを増やしていき、C[i][j]を変更していく. C[i][j]の値は、
 *
 *           1. C[i - 1][j - 品物iの重さ] + 品物iの価値
 *           2. C[i - 1][j]
 *
 *         の大きい方となる. ここで1.はこの時点で品物iを盗る、2.はこの時点で品物iを残す、という処理に対応する
 *         ただし、1.の場合は、品物iの重さがjを超えない場合に限る
 *
 * @date   2016/05/05
 */



//********************************************************************************
// 必要なヘッダファイルのインクルード
//********************************************************************************

#include <iostream>
#include <vector>
#include <cstdint>
#include <algorithm>



//********************************************************************************
// 型シノニム
//********************************************************************************

using index_t  = int;
using value_t  = int;
using weight_t = int;

using indices_t = std::vector<index_t>;
using values_t  = std::vector<value_t>;
using weights_t = std::vector<weight_t>;

using dptbl_t   = std::vector<values_t>;



//********************************************************************************
// 関数の定義
//********************************************************************************

/**
 * @brief  動的計画法を用いて0-1ナップサック問題(0-1 knapsack problem)を解きます
 *
 * @param  const value_t& v i番目の品物の価値が記録されている1次元配列v
 * @param  const value_t& w i番目の品物の重さが記録されている1次元配列w
 * @param  weight_t       W ナップサックに詰めこめる最大の重さW
 */
value_t __01_knapsack__(const values_t& v, const weights_t& w, weight_t W)
{    
    index_t n = v.size();              // n = v.length
    dptbl_t C(n+1, values_t(W+1, 0));  // Cを(n+1) x (W+1)型の新しい行列とする

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

        for (weight_t j = 1; j <= W; j++) {

            if (w[i] <= j) {
                C[i][j] = std::max(C[i - 1][j - w[i]] + v[i], C[i - 1][j]);
            }
            else {
                C[i][j] = C[i - 1][j];
            }
        }
    }
    
    return C[n][W];
}



//********************************************************************************
// エントリポイント
//********************************************************************************

int main()
{
    using namespace std;

    int n, W;
    cin >> n >> W;
    
    values_t  v(n + 1);
    weights_t w(n + 1);

    for (int i = 1; i <= n; i++) {
        cin >> v[i] >> w[i];
    }
    
    cout << __01_knapsack__(v, w, W) << endl;
    
    
    return 0;
}

Measured memory_bytes: 6788
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
const int maxn=1e6+5;
const int INF=0x3f3f3f3f;
const int dx[]={0,0,1,-1};
const int dy[]={1,-1,0,0};
vector<bool> gra[maxn];
vector<int> eg;
vector<vector<int> > dis;
queue<pair<int,int> > que;
int n,m,k,x1,y1,x2,y2;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin>>n>>m>>k;
    eg.resize(m,INF);
    dis.resize(n,eg);
    cin>>x1>>y1>>x2>>y2;
    x1--; y1--; x2--; y2--;
    for(int i=0;i<n;i++)
    {
        string ss;
        cin>>ss;
        for(int j=0;j<m;j++)
            gra[i].emplace_back(ss[j]=='@');
    }
    dis[x2][y2]=0;
    que.emplace(x2,y2);
    while(que.size())
    {
        pair<int,int> cur=que.front(); que.pop();
        int x=cur.first,y=cur.second,now=dis[x][y];
        if(now>dis[x1][y1]) continue;
        for(int i=0;i<4;i++)
            for(int d=1;d<=k;d++)
            {
                int p=x+d*dx[i],q=y+d*dy[i];
                if(p<0||p>=n||q<0||q>=m||gra[p][q]) break;
                if(now+1<dis[p][q])
                {
                    dis[p][q]=now+1;
                    que.emplace(p,q);
                }
                else if(now+1>dis[p][q])
                    break;
            }
    }
    cout<<(dis[x1][y1]==INF?-1:dis[x1][y1])<<'\n';
    return 0;
}


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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e5 + 5;

int32_t main()
{
	IOS;
	int n;
	cin >> n;
	int a[n+5];
	rep(i,1,n)
	{
		cin >> a[i];
	}
	int c=0;
	rep(i,1,n)
	{
		if(a[i]!=i)
		{
			c++;
		}
	}
	if(c<=2)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}


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

#define M_PI       3.14159265358979323846

using namespace std;

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

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

//container util

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

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()


struct Edge {
    int to, cost, nm;
    Edge(int to, int cost, int nm): to(to), cost(cost), nm(nm) {}
};

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<Edge>> AdjList;
AdjList graph;
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
const int INF = 100000000;

ll GCD(ll a, ll b){
    if(a < b) swap(a, b);
    if(b == 0) return a;
    return GCD(b, a%b);
}

bool cmp(const pii& a, const pii& b){
    if(a.first == b.first){
        return a.second < b.second;
    }
    return a.first < b.first;
}

vector<string> matrix;
int main() {

   ll n; cin >> n;
   ll sum =0;
   for(int i=0; i<n; ++i){
       ll a; cin >> a;
       sum += a;
   }
   cout << sum/n << endl;
    return 0;
}


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

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

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

ll powmod(ll a, ll p, ll MOD) {
	ll ans = 1;
	ll mul = a;
	for (; p > 0; p >>= 1, mul = (mul * mul) % MOD) {
		if ((p & 1) == 1)ans = (ans * mul) % MOD;
	}
	return ans;
}

int main() {

    ll N;
    cin >> N;
    vector<ll> C(N);
    REP(i, N) cin >> C[i];

    sort(C.begin(), C.end(), greater<ll>());

    ll tmp = powmod(2, N - 1, MOD);
    ll tmp2 = powmod(2, N - 2, MOD);

    //cout << tmp << " " << tmp2 << endl;
    ll ans = 0;
    ll hoge = tmp, hoge2;
    REP(i, N){
        hoge2 = (hoge * C[i]) % MOD;
        ans = (ans + hoge2) % MOD;
        hoge = (hoge + tmp2) % MOD;
    }

    //cout << ans << endl;
    tmp = (tmp * 2) % MOD;
    ans = (ans * tmp) % MOD;

    cout << ans << endl;




    return 0;
}

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

const int MOD = 1000000007;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define _sort(a) sort(a.begin(), a.end())
#define _sortd(a) sort(a.rbegin(), a.rend())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template<class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template<class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

void py(bool isUpper = false) {
  if (isUpper) {
    p("YES");
  } else {
    p("Yes");
  }
}

void pn(bool isUpper = false) {
  if (isUpper) {
    p("NO");
  } else {
    p("No");
  }
}

int main() {
  long a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << max(max(max(b * d, a * c), a * d), b * c) << endl;
}

Measured memory_bytes: 3636
import math
N = int( input())
di = [[-1] * 101 for i in range(101)]



ps = []
basep=0
for k in range(N):
    temp = list(map(int,input().split(" ")))
    ps.append(temp)
    if temp[2] != 0:
        basep = temp
# print(ps)
basex = basep[0]
basey = basep[1]
baseh = basep[2]
# print(basep)
flag = True
for i in range(101):
    for j in range(101):
        flag = True
        X = i
        Y = j
        H = abs(basex - X) + abs(basey - Y) + baseh
        for l,p in enumerate(ps):
            x = p[0]
            y = p[1]
            h = p[2]
        #     print(l,":",p)       
            if max(H -abs(X-x)-abs(Y-y),0) != h: 
                flag = False
                # print("x,y,h:",x,y,h)
                # print("X,Y,H:",X,Y,H)

                # print("break")
                break
        if flag:
                print(X,Y,H)
                break
    if flag:
        break

#         di[i][j].append(h + abs(x-i)  + abs(y-j))
#         print
# for i in range(0,101):
# for j in range(0,101):
#         if len(list(set(di[i][j]))) == 1:
#         print(i,j,di[i][j][0])


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int test;
	//cin>>test;
	test=1;
	while(test--){
		int a,b,h,m;
		cin>>a>>b>>h>>m;
		const double pi=3.1415926535897932384626433;
		double dis;
		double angle=h*(pi)/6-m*(pi)/30+m*pi/360;
		dis=sqrt(a*a+b*b-2*a*b*cos(abs(angle)));
		printf("%.9f\n",dis);
	}
		
}
	



Measured memory_bytes: 4184
N=int(input())
an=map(int,input().split())
Cards=[]
for a in an:
    Cards.append(int(a))
SortedCards=sorted(Cards,reverse=True)
AliceCards=SortedCards[0::2]
BobsCards=SortedCards[1::2]
print(sum(AliceCards)-sum(BobsCards))

Measured memory_bytes: 3060
<?php
fscanf(STDIN,'%d%d',$N,$T);
$costmin = 10000;
for ($i=0; $i <=$N-1 ; $i++) {
  // code...
  fscanf(STDIN,'%d%d',$Cx,$Tx);
  if($Tx<=$T && $costmin > $Cx){
    $costmin = $Cx;
  }
}
if($costmin==10000){
  echo "TLE";
}else {
  // code...
  echo $costmin;
}



 ?>


Measured memory_bytes: 3700
import java.util.*;

class Main {

  static int LENGTH = 100000;
  static int [] queue = new int[LENGTH];
  static String [] name = new String[LENGTH];
  static int tail = 0;
  static int head = 0;
  public static void main(String args[]){
    //宣言
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int max = sc.nextInt();
    int out;
    int count=0;
    //input
    for(int i = 0; i<n; i++){
      name[i] = sc.next();
      queue[i] = sc.nextInt();
      tail++;
    }
    //loop
    while(isEmpty() != true){
      out = dequeue();
      if((out-max)>0){
        enqueue(out-max);//
        count += max;
      }else{
        count += out;
        System.out.println(name[head-1]+" "+count);
      }
    }
  }
  //enqueue
  static void enqueue(int num){
    queue[tail] = num;
    if(head != 0){
    name[tail] = name[head-1];//
  }else{
    name[tail] = name[LENGTH-1];
  }
    if(tail == LENGTH-1){
      tail=0;
    }else{
      tail++;
    }
  }
  //dequeue
  static int dequeue(){
    if(head == LENGTH-1){
      head = 0;
      return queue[LENGTH-1];
    }
    return queue[head++];
  }
  //キューの中身がなくなったかどうかの判定
  static boolean isEmpty(){
    return head == tail;
  }

}


Measured memory_bytes: 76692
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(), vec.end()
#define rever(vec) reverse(all(vec));
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>
struct edge { int to, cost; };
using P = pair<int, int>;
using PP = pair<P, int>;
using D = pair<double, double>;
const int mod2 = 998244353;
const int mod = (int)1e9 + 7, inf = (int)1e16;
const string sp = " ";

int modpow(int x, int n) {
	int ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (mod <= ans) ans %= mod;
		}
		x *= x;
		if (mod <= x) x %= mod;
		n >>= 1;
	}
	return ans;
}

int fact[1000000];
void f_init(int n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= n; ++i) {
		fact[i] *= fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

int comb(int n, int r) {
	if (n < r) return 0;
	int ans = fact[n] * modpow(fact[n - r], mod - 2) % mod * modpow(fact[r], mod - 2);
	if (ans < 0) return ans + mod;
	return ans;
}

int perm(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	int ans= fact[n] * modpow(fact[n - r], mod - 2) % mod;
	if (ans < 0) return ans + mod;
	return ans;
}

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

int lcm(int a, int b) {
	return a * b / gcd(a, b);
}

bool pri(int p) {
	for (int i = 2; i * i <= p; ++i) if (p % i == 0) return false;
	return p > 1;
}

map<int, int> factring(int n) {
	map<int, int>ans;
	for (int i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

P operator+(const P& a, const P& b) {
	return P(a.first + b.first, a.second + b.second);
}
P operator-(const P& a, const P& b) {
	return P(a.first - b.first, a.second - b.second);
}

class unionfind {
private:
	int par[200010], rankth[200010], sizeth[200020];
public:
	void init(int n) {
		rep(i, n) {
			par[i] = i;
			rankth[i] = 0;
			sizeth[i] = 1;
		}
	}
	int root(int x) {
		while (par[x] != x) {
			x = par[x] = par[par[x]];
		}
		return x;
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	void unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x == y) return;
		if (rankth[x] < rankth[y]) {
			par[x] = y;
			sizeth[y] += sizeth[x];
		}
		else {
			par[y] = x;
			if (rankth[x] == rankth[y]) rankth[x]++;
			sizeth[x] += sizeth[y];
		}
	}
};

int n, w, ans;
string s, a;
vector<string>v;
signed main() {
	cin >> s;
	n = s.size();
	while (w < n) {
		if (s[w] == 'A') a += 'A';
		else if (w < n - 1 && s[w] == 'B' && s[w + 1] == 'C') {
			a += "D";
			w++;
		}
		else {
			if (!a.empty()) v.push_back(a);
			a = "";
		}
		w++;
	}
	if (!a.empty()) v.push_back(a);
	for (string i : v) {
		int cnt = 0;
		rep(j, i.size()) {
			if (i[j] == 'D') {
				ans += j - cnt;
				cnt++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3196
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>


int main(void) {
    int N, X;
    scanf("%d %d", &N, &X);
    int *L = (int*)malloc(N * sizeof(int));

    int i = 0;
    for(i=0; i<N; i++) {
        scanf("%d", &L[i]);
    }

    int D = 0;
    i=0;
    int count = 1;
    while(i<N) {
        D += L[i];
        if(D <= X) {
            count++;
        }
        else {
            break;
        }
        i++;
    }
    printf("%d\n", count);
    free(L);
    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int H,W,N;
int X[202020],Y[202020];
vector<int> Ys[202020];
set<pair<int,int>> S;
set<int> fail[202020];

bitset<201010> B;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W>>N;
	FOR(i,N) {
		cin>>Y[i]>>X[i];
		Y[i]--;
		X[i]--;
		Ys[Y[i]].push_back(X[i]);
		S.insert({Y[i],X[i]});
	}
	
	FORR(s,S) {
		y=s.first-1;
		x=s.second;
		if(y>=0 && (S.count({y+1,x})||y==H-1)) fail[y].insert(x);
	}
	
	B[0]=1;
	for(y=0;y<H-1;y++) {
		FORR(f,fail[y]) if(B[f]) {
			cout<<y+1<<endl;
			return;
		}
		FORR(x,Ys[y+1]) B[x]=0;
		B |= B<<1;
		FORR(x,Ys[y+1]) B[x]=0;
		
		
	}
	
	cout<<H<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 41728
#include<iostream>
using namespace std;
int main()
{
    long long x;
    cin >> x;
	
  	long long happy=0, y;
  	y = x/500;
    x -= 500*y;
  	happy += 1000*y;
    y = x/5;
    happy += 5*y;
    cout << happy << endl; 
    return 0;
}

Measured memory_bytes: 3132
#include <stdio.h>

using namespace std;

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

int abs(int n) {
    return (n > 0) ? n : -n;
}

int main() {
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);

    if (abs(c - a) <= d || (abs(c - b) <= d && abs(b - a) <= d)) printf("Yes\n");
    else printf("No\n");

    return 0;
}


Measured memory_bytes: 128
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, C: int, B: "List[int]", A: "List[List[int]]"):
    ret = 0
    for i in range(N):
        tmp = 0
        for j in range(M):
            tmp += A[i][j] * B[j]
        tmp += C
        if tmp > 0:
            ret += 1
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    B = [ int(next(tokens)) for _ in range(M) ]  # type: "List[int]"
    A = [ [ int(next(tokens)) for _ in range(M) ] for _ in range(N) ]  # type: "List[List[int]]"
    solve(N, M, C, B, A)

if __name__ == '__main__':
    main()


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

int main(){
	
	int n, h[100010], dp[100010], k;
	scanf("%d %d", &n, &k);
	
	for(int i = 0; i < n; i++){
		scanf(" %d", &h[i]);
		
		dp[i] = (i != 0) * 1000000000;
		
		for(int j = i - 1; j >= 0 && j >= i - k; j--) dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
	}
	
	printf("%d\n", dp[n - 1]);
	return 0;
}


Measured memory_bytes: 4512
($N,$M)=glob<>;
/ /,${$`}{$'+0}=${$'+0}{$`}=1for<>;

sub f{
	my$c=$c[$_];
	for(keys%$_){
		if($c[$_]){
			if($c[$_]==$c){
				exit!print$N*($N-1)/2-$M
			}
		}else{
			$c[$_]=-$c;
			&f
		}
	}
}
$c[1]=1;
f$_=1;

print grep($_>0,@c)*grep($_<0,@c)-$M


Measured memory_bytes: 94976
//g++でビルド

#include "bits/stdc++.h"

using namespace std;


int main(){
    int n, y;
    cin >> n >> y;
    int result[3] = {-1, -1, -1};
    
    for(int i = 0; i <= n; ++i){
        for(int j = 0; j <= n-i; ++j){
            int k = n - i - j;
                if((10000*i + 5000*j + 1000*k) == y){
                    result[0] = i;
                    result[1] = j;
                    result[2] = k;
                    break;
                }
            
        }
            
    }
        

    cout << result[0] << " " << result[1] << " " << result[2] << endl;
    return 0;
}

Measured memory_bytes: 256
import math

n,m = map(int, input().split())
yakusu=[]
for i in range(1, int(math.sqrt(m))+1):
	if m % i == 0:
		yakusu.append(i)
		if i*i != m:
			yakusu.append(m//i)
			
ans=0
for i in yakusu:
	if m//i >= n:
		ans = max(i, ans)
		
print(ans)

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

#define vi vector<int>
#define tests int t; cin>>t; while(t--)
#define ll long long
#define vll vector<long long>
#define srt(v) sort(v.begin(), v.end())
#define srtg(v) sort(v.begin(), v.end(), greater<int> ())
#define FOR(k, n) for(int k=0; k<n; k++)
#define pb push_back


using namespace std;
using namespace std::chrono;

char nums[10] = { '0','1','2','3','4','5','6','7','8','9' };
char alphsl[26] = { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };
const int MOD = 1000000007;
char alphs[26] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };


void solve() {

    int n, k;
    cin>>n>>k;
    vi v(n);
    for(auto& x : v) cin>>x;
    
    srt(v);
    int sum=0;
    for(int i=0; i<k; i++) sum+=v[i];
    cout<<sum<<endl;
    
    
}


int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);

        
        solve();


    return 0;
}

Measured memory_bytes: 3604
#include <cstdio>
#include <algorithm>

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

using namespace std;

int n, m;
int a[100];

int main(){
	scanf("%d%d", &n, &m);
	rep(i, n){
		scanf("%d", &a[i]);
	}

	for(int i = 1; i <= m; ++i){
		rep(j, n - 1){
			if(a[j] % i > a[j + 1] % i){
				swap(a[j], a[j + 1]);
			}
		}
	}

	rep(i, n){
		printf("%d\n", a[i]);
	}
	return 0;
}

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

int main() {
    ll h, w;
    cin >> h >> w;
    if (h == 1 || w == 1) cout << 1 << endl;
    else if (h % 2 == 0 || w % 2 == 0) cout << h * w / 2 << endl;
    else cout << (h * w + 1) / 2 << endl;
}


Measured memory_bytes: 256
n,m = gets.split.map(&:to_i)
x = [0]*n
m.times{
  a,b = gets.split.map(&:to_i)
  x[a-1]+=1
  x[b-1]+=1
}

puts (x.all?{|t|t%2==0})? "YES" : "NO"


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

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pi;

ll N, M, Q, A, B, C, D, E, X, Y, Z, arr[100005];

string s;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> N >> M >> X;
	for (int i = 1; i <= 10; ++i){
		X = N*X - M;
		cout << X << '\n';
	}

}

Measured memory_bytes: 256
MOD=1000000007
def modpow(a,n,mod):
    res=1
    a=a%mod
    while(n>0):
        if(n&1):
            res=res*a%mod
        a=a*a%mod
        n>>=1
    return res

N=int(input())
A=list(map(int,input().split()))
cnt=[0]*100001
for i in range(N):
    cnt[A[i]]+=1
if(N%2==1):
    if(cnt[0]!=1):
        print(0)
        exit()
    for i in range(2,N,2):
        if(cnt[i]!=2):
            print(0)
            exit()
elif(N%2==0):
    for i in range(1,N,2):
        if(cnt[i]!=2):
            print(0)
            exit()
print(modpow(2,N//2,MOD))

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  ll ans = 0;
  
  vector<int> a(n);
  rep(i, 0, n) cin >> a.at(i);
  vector<int> b(n);
  rep(i, 0, n) {
    cin >> b.at(i);
    ans += b.at(i);
  }
  vector<int> c(n);
  rep(i, 0, n) cin >> c.at(i);
  
  rep (i, 0, n-1) {
    if (a.at(i+1) == a.at(i) + 1)
      ans += c.at(a.at(i) - 1);
  }
    
  cout << ans << "\n";

}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
  
/**
 * @author penguin_410
 *         Date: 2014/03/06
 */
public class Main {
    public static void main(String... args) throws IOException {
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final StringBuilder sb = new StringBuilder();
        while (true) {
            final String line = br.readLine();
            final int index = line.indexOf(" ");
            final int x = Integer.parseInt(line.substring(0, index));
            final int y = Integer.parseInt(line.substring(index+1, line.length()));
            if (x == 0 && y == 0) break;
            sb.append(x < y ? x + " " + y : y + " " + x).append("\n");
        }
        System.out.print(sb);
    }
}

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

int main() {
    ll n;
    double x[10];
    string u[10];
    std::cin >> n;
    double result = 0;
    for (int i = 0; i < n; i++) {
        std::cin >> x[i] >> u[i];
        if( u[i] == "JPY" ){
            result += x[i];
        }else{
            result += x[i] * 380000;
        }
    }
    std::cout << setprecision(19);
    std::cout << result << std::endl;
    
}

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

int main() {
  stack<int> S;
  int a, b, x;
  string s;

  while( cin >> s ) {
    if ( s[0] == '+' ) {
      b = S.top(); S.pop();
      a = S.top(); S.pop();
      S.push(a + b);
    } else if ( s[0] == '-' ) {
      b = S.top(); S.pop();
      a = S.top(); S.pop();
      S.push(a - b);
    } else if ( s[0] == '*' ) {
      b = S.top(); S.pop();
      a = S.top(); S.pop();
      S.push(a * b);
    } else {
      S.push(atoi(s.c_str()));
    }
  }

  cout << S.top() << endl;

  return 0;
}


Measured memory_bytes: 3136
fn main() {
    let i = input();
    println!("{}", solve(i));
}

fn input() -> usize {
    let mut buf = String::from("");
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.pop();
    let i: usize = buf.parse().unwrap();
    i
}

fn solve(input: usize) -> usize {
    if input == 0 {
        return 0;
    }

    let number_500 = input / 500;
    let remain = input - (number_500 * 500);
    let number_5 = remain / 5;

    number_500 * 1000 + number_5 * 5
}

Measured memory_bytes: 4352
import java.util.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main implements Runnable
{
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};
    static long mod=1000000007;
    
    public static void main(String[] args) {        
        new Thread(null, new Main(), "", 200 * 1024 * 1024).start();        
    }

    public void run() {
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        
//        int n=sc.nextInt();
        if(sc.nextString().equals("ABC"))ret("ARC");
   
        out.println("ABC");
     	out.flush();
    }
    
    static void ret(String ans) {
    	System.out.println(ans);
    	System.exit(0);
    }

    static void ret(long ans) {
    	System.out.println(ans);
    	System.exit(0);
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

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

//class P {
//	int x,c;long s;
//	P(int  x, int c, long s) {
//	  this.x=x;
//	  this.c=c;
//	  this.s=s;
//	}
//}


class P implements Comparable<P>{
	int x,c;long s;
	P(int  x, int c, long s) {
	  this.x=x;
	  this.c=c;
	  this.s=s;
	}

    public int compareTo(P p){
        return Long.signum(s-p.s);
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString()
    {
        while( st==null || !st.hasMoreTokens() )
			try {
				st = new StringTokenizer(x.readLine());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        return st.nextToken();
    }
    public int nextInt()
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) {
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) {
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public char[] getCharSet() {
        return this.nextString().toCharArray();
    }    
    public long nextLong()
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 32988
#include<iostream>
#include <vector> 
#include <algorithm>
#include<iomanip>
#include<math.h>
#include<string>
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
using namespace std;

int main() {
    char szBuf[2][20] = { NULL };
    cin >> szBuf[0];
    cin >> szBuf[1];
    for (int x = 0;; x++) {
        if (szBuf[0][x] ==NULL  || szBuf[1][x] == NULL) {
            cout << "Yes" << endl;
            return 0;
        }
        if (szBuf[0][x] != szBuf[1][x]) {
            cout << "No" << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3596
#include <cstdio>

int main() {
    int W, H, x, y, r;
    scanf("%d%d%d%d%d", &W, &H, &x, &y, &r);
    if(x + r <= W && 0 <= x - r && y + r <= H && 0 <= y - r) { //内側
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
}


Measured memory_bytes: 2676
# def bubbleSort(A):
#     flag = 1
#     counter = 0
#     while flag:
#         flag = 0
#         for j in range(len(A) -1, 0, -1):
#             if A[j] <  A[j-1]:
#                 A[j], A[j - 1] = A[j - 1], A[j]
#                 flag = 1
#                 counter += 1
#     return A, counter

def bubbleSort(A):
    flag = 1
    counter = 0
    while flag:
        flag = 0
        for j in range(len(A) - 1, 0, -1):
            if A[j] <  A[j-1]:
                A[j], A[j - 1] = A[j - 1], A[j]
                flag = 1
                counter += 1
    return A, counter
    
N = int(input())
A = list(map(int, input().split()))

ans = bubbleSort(A)
print(' '.join(str(num) for num in ans[0]))
print(ans[1])


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

int main() {
    using namespace std;

    constexpr unsigned long MOD = 998244353;

    unsigned long N;
    cin >> N;
    string S;
    cin >> S;

    array<unsigned long, 3> dp{};
    unsigned long ans{1};
    constexpr char hoge = 'R' ^ 'G' ^ 'B';
    char char1{'.'}, char2{'.'};
    for(const auto& c : S){
        if(c == char2){
            (ans *= dp[1]) %= MOD;
            --dp[1];
            if(!dp[1])char2 = '.';
            (ans *= ++dp[2]) %= MOD;
        }else if(char1 == '.' || c == char1){
            ++dp[0];
            char1 = c;
        }else{
            (ans *= dp[0]) %= MOD;
            if(!dp[1])char2 = hoge ^ c ^ char1;
            --dp[0];
            if(!dp[0])char1 = '.';
            ++dp[1];
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main()
{
    string s = "";

    while( cin >> s )
    {
        if( s == "0" )
            break;
        int a = 0, b = 0;
        for( int i = 0; i < s.size() - 1; i++ )
        {
            if( s[i+1] == 'A' )
                a++;
            else
                b++;
        }
        if( a > b )
            cout << ++a << " " << b << endl;
        else
            cout << a << " " << ++b << endl;
    }
    return 0;
}



Measured memory_bytes: 3180
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	H,W,h,w = readline() |> split |> parseMap
	if H%h==0&&W%w==0
		println("No")
	else
		println("Yes")
		if 1==2
		else
			k = 0
			for i in 1:H
				for j in 1:W
					if i%h==0&&j%w==0
						k += 1
					end
				end
			end
			y = 1
			while div((H*W-k)*y-k*(h*w-1)*y,k)<=1
				y+=1
			end
			x = (h*w-1)*y+1
			for i in 1:H
				for j in 1:W-1
					if i%h!=0||j%w!=0
						print(y," ")
					else
						print(-x, " ")
					end
				end
				if i%h!=0||W%w!=0
					println(y)
				else
					println(-x)
				end
			end
		end
	end
end

main()

Measured memory_bytes: 142224