akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll offset = 1ll << 58;
const int LOG = 60;
int main() {
  do {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
  } while (false);
  int n;
  cin >> n;
  vector<ll> x(n), y(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
    x[i] += offset;
    y[i] += offset;
  }
  auto calc = [&] (ll sum, int mod) {
    vector<bool> F(3), G(3), new_F(3), new_G(3);
    bool res = false;
    for (int i = 0; i < n; i++) {
      if (y[i] < sum) {
        ll limit = sum - y[i];
        fill(F.begin(), F.end(), false);
        fill(G.begin(), G.end(), false);
        F[0] = true;
        for (int j = LOG; j >= 0; j--) {
          fill(new_F.begin(), new_F.end(), false);
          fill(new_G.begin(), new_G.end(), false);
          for (int k = 0; k < 3; k++) {
            if (F[k]) {
              for (int value = 0; value <= min((limit >> j) & 1, (x[i] >> j) & 1); value++) {
                int nxt = (k + value + value * (j & 1)) % 3;
                if (value != ((limit >> j) & 1)) {
                  new_G[nxt].flip();
                } else {
                  new_F[nxt].flip();
                }
              }
            }
            if (G[k]) {
              for (int value = 0; value <= ((x[i] >> j) & 1); value++) {
                int nxt = (k + value + value * (j & 1)) % 3;
                new_G[nxt].flip();
              }
            }
          }
          F.swap(new_F);
          G.swap(new_G);
        }
        res ^= G[(mod - y[i] % 3 + 3) % 3];
      }
    }
    return res;
  };
  int mod = 0;
  while (!calc(1ll << LOG, mod)) {
    mod++;
  }
  ll start = 0;
  for (int i = LOG; i >= 0; i--) {
    if (calc(start, mod) == calc(start + (1ll << i), mod)) {
      start += 1ll << i;
    }
  }
  auto check = [&] (ll pos) {
    bool res = false;
    for (int i = 0; i < n; i++) {
      if (y[i] <= pos && pos <= x[i] + y[i] && (x[i] & (pos - y[i])) == pos - y[i]) {
        res ^= 1;
      }
    }
    return res;
  };
  ll L = start, R = start;
  for (int i = LOG; i >= 0; i--) {
    if (check(L - (1ll << i))) {
      L -= 1ll << i;
    }
    if (check(R + (1ll << i))) {
      R += 1ll << i;
    }
  }
  cout << R - L - offset << " " << L - offset << endl;
  return 0;
}


Measured memory_bytes: 512
//package cp;
import java.util.*;
import java.io.*;
public class Main {
	long gcd(long a,long b) {if(b==0)return a;else return gcd(b,a%b);}
	void swap(long a,long b) {long temp=a;a=b;b=temp;}
	StringBuilder sb=new StringBuilder();
	Integer[] ARR=new Integer[5];
	//Integer sort-TLE-Initialize object elements i.e a[0].
	void divisor(long n,int start) {
		int cnt=0;for(int i=start;i<=Math.sqrt(n);i++) {
		if(n%i==0) {if(i==n/i)cnt++;else cnt+=2;}}}
	
	public static void main(String[] args) throws IOException {	
		PrintWriter out = new PrintWriter(System.out);
		Readers.init(System.in);
		Main obj=new Main();
		int n=Readers.nextInt();
		long[] a=new long[n+1];
		for (int i = 1; i < a.length; i++) {
			a[i]=Readers.nextLong();
		}
		long[] dp=new long[n+1];
		dp[1]=0;
		dp[2]=Math.abs(a[2]-a[1]);
		
		for (int i = 3; i <=n; i++) {
			long minn=Math.min(dp[i-1]+Math.abs(a[i]-a[i-1]),dp[i-2]+Math.abs(a[i]-a[i-2]));
			dp[i]=minn;
		}
		System.out.println(dp[n]);
		out.flush();
	}
}
class Readers {
 
    static BufferedReader reader;
 
    static StringTokenizer tokenizer;
 
 
 
    /** call this method to initialize reader for InputStream */
 
    static void init(InputStream input) {
 
        reader = new BufferedReader(
 
                     new InputStreamReader(input) );
 
        tokenizer = new StringTokenizer("");
 
    }
 
 
 
    /** get next word */
 
    static String next() throws IOException {
 
        while ( ! tokenizer.hasMoreTokens() ) {
 
            //TODO add check for eof if necessary
 
            tokenizer = new StringTokenizer(
 
                   reader.readLine() );
 
        }
 
        return tokenizer.nextToken();
 
    }
 
 
 
    static int nextInt() throws IOException {
 
        return Integer.parseInt( next() );
 
    }
 
	
 
    static double nextDouble() throws IOException {
 
        return Double.parseDouble( next() );
 
    }
    
    
    static long nextLong() throws IOException{
    	
		return Long.parseLong(next());
	}
 
}


Measured memory_bytes: 44072
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vll vector<ll>
#define vllv vector<vector<ll>> 
#define sz size()
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll fact(ll n){ll s=1; for(ll i=1;i<=n;i++)s*=i; return s;}
ll ceil1(ll n,ll m){if(n%m==0){return n/m;}return n/m +1;}
vll factor(ll n){
    vll ans;
    if(n>0)ans.pb(1);if(n==2)ans.pb(2);
    for(ll i=2;i*i<=n;i++){if(n%i==0){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}if(n>2)ans.pb(n);
    return ans;
}
ll nCr(ll n, ll r) 
{ 
    return fact(n) / (fact(r) * fact(n - r)); 
} 
void dfs(vllv &v,ll k,vll &par,vll &dis,ll p)
{
 
    par[k]=p;
    dis[k]=dis[p]+1;
    for(ll i=0;i<v[k].sz;i++){
        if(v[k][i]!=p){
            dfs(v,v[k][i],par,dis,k);
        }
    }
}
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second<b.second);} 


void solve()
{
    double n;
    cin>>n;
    cout<<2.0*3.14159265358979323846*n;
    return;
}

int main()
{
    ll q;
    q=1;
    // cin>>q;
    while(q--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head

void solve(){
    int n;
    cin >> n;
    vector<ll> d(n);
    for (int i = 0; i < n; i++) cin >> d[i];
    ll ans = 0;
    for (int i = 0; i < n; i++){
        for (int j = i+1; j < n; j++){
            ans += d[i]*d[j];
        }
    }
    cout << ans << '\n';
}

int main(void){ 
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    //int t; cin >> t; while (t--)
        solve();
}

Measured memory_bytes: 3624
a, b, c = map(int, input().split())

li = [a, b, c]
li.sort()

ans = 0
for i in range(2):
    cnt = (li[2] - li[i]) // 2
    li[i] += 2 * cnt
    ans += cnt

ans += li.count(max(li)) % 3
print(ans)


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

const int N = 100500;

typedef long long llong;

int A[N];

int main() {
    int n;
    scanf("%d", &n);
    llong l = 2, r = 2;
    for (int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }
    for (int i = n - 1; i >= 0; i--) {
        llong a = A[i];
        llong pl = l + (a - l % a) % a;
        llong pr = r - r % a + a - 1;
        l = pl, r = pr;
        if (l > r) {
            puts("-1");
            return 0 ;
        }
    }
    printf("%lld %lld\n", l, r);
}


Measured memory_bytes: 512
import collections
H, W = map(int, input().split())
S = [input() for _ in range(H)]

def dfs(sy, sx, gy, gx):
    q = collections.deque()
    q.append((sy, sx))
    dist = [[float("inf")] * W for _ in range(H)]
    dist[sy][sx] = 0
    dx = [(1, 0), (0, 1)]
    while len(q) != 0:
        h, w = q.popleft()
        d = dist[h][w]
        for x, y in dx:
            h2 = h + y
            w2 = w + x
            if h2 >= 0 and h2 < H and w2 >= 0 and w2 < W:
                if S[h2][w2] == "#" and dist[h2][w2] == float("inf"):
                    dist[h2][w2] = d+1
                    q.append((h2, w2))
    return dist[gy][gx]

count = dfs(0, 0, H-1, W-1)+1
count2 = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            count2 += 1
if count == count2:
    print('Possible')
else:
    print('Impossible')

Measured memory_bytes: 38512
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <math.h>
using namespace std;

#define rep(i, o) for (int i = 0; i < (o); ++i)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)

typedef long long ll;


ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int main() {
  int s, w;
  cin >> s >> w;

  string ans = (w >= s) ? "unsafe" : "safe";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
using namespace std;
int main() {
    int n;      // ????????????????????°
    /*
    ?????????????????????
    ??????????????°??????
        0: ????????????
        1: ?????????
        2: ?????????
        3: ????????¢
    ??????????????????????????°???
        0??????????¬????
    */
    bool card[4][14] = {};
    cin >> n;
   // ????????????????????????????????????????????§??????????????????
    for (int i = 0; i < n; i++) {
        char suit;      // ??????????????????
        int  num;       // ??°????????????
        cin >> suit >> num;
        switch (suit) {
            case 'S' :
                card[0][num] = 1;
                break;
            case 'H' :
                card[1][num] = 1;
                break;
            case 'C' :
                card[2][num] = 1;
                break;
            case 'D' :
                card[3][num] = 1;
                break;
        }
    }
    // ?????§??????????????????????????????????????¢???????????????
    for (int i = 0; i < 4; i++) {
        for (int j = 1; j <= 13; j++) {
            if(card[i][j] == 0) {
                switch (i) {
                    case 0 :
                        cout << "S";
                        break;
                    case 1 :
                        cout << "H";
                        break;
                    case 2 :
                        cout << "C";
                        break;
                    case 3 :
                        cout << "D";
                        break;
                }
                cout << " " << j << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<set>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int j;
cin>>j;
double a[j],m;
for(int i = 0;i < j;i++)cin>>a[i];
sort(a,a+j);
for(int i = 0;i < j-1;i++){
    m= (a[i]+a[i+1])/2;
    a[i+1] = m;
}
cout<<a[j-1];
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<string>
#include<cassert>
using namespace std;
#define N 4
#define N2 16
#define LIMIT 100

static const int dx[4] = {0, -1, 0, 1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = { 'r', 'u', 'l', 'd'};
int MDT[N2][N2];

struct Puzzle{int f[N2], space, MD;};

Puzzle state;
int limit;
int path[LIMIT];

int getAllMD(Puzzle pz){
  int sum = 0;
  for(int i = 0 ; i < N2 ; i++){
    if(pz.f[i] == N2) continue;
    sum += MDT[i][pz.f[i] - 1];
  }
  return sum;
}

bool isSolved(){
  for(int i = 0 ; i < N2 ; i++) if(state.f[i] != i + 1) return false;
  return true;
}

bool dfs(int depth, int prev){
  if(state.MD == 0) return true;
  if(depth + state.MD > limit) return false;

  int sx = state.space / N;
  int sy = state.space % N;
  Puzzle tmp;

  for(int r = 0 ; r < 4 ; r++){
    int tx = sx + dx[r];
    int ty = sy + dy[r];
    if(tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
    if(max(prev, r)-min(prev, r) == 2) continue;
    tmp = state;
    state.MD -= MDT[tx * N + ty][state.f[tx * N + ty] - 1];
    state.MD += MDT[sx * N + sy][state.f[tx * N + ty] - 1];
    swap(state.f[tx * N + ty], state.f[sx * N + sy]);
    state.space = tx * N + ty;
    if(dfs(depth + 1, r)) {path[depth] = r; return true;}
    state = tmp;
  }

  return false;
}

string iterative_deepening(Puzzle in){
  in.MD = getAllMD(in);

  for(limit = in.MD ; limit <= LIMIT ; limit++){
    state = in;
    if(dfs(0, -100)){
      string ans = "";
      for(int i = 0 ; i < limit ; i++) ans += dir[path[i]];
      return ans;
    }
  }

  return "ubsolvable";
}

int main(){
  for(int i = 0 ; i < N2 ; i++)
    for(int j = 0 ; j < N2 ; j++)
      MDT[i][j] = abs(i / N - j / N) + abs(i % N - j % N);

  Puzzle in;

  for(int i = 0 ; i < N2 ; i++){
    cin >> in.f[i];
    if(in.f[i] == 0){
      in.f[i] = N2;
      in.space = i;
    }
  }
  string ans = iterative_deepening(in);
  cout << ans.size() << endl;

  return 0;
}

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

int Partition(int a[], int p, int r)
{
    int x = a[r];
    int i = p - 1;

    for (int j = p; j < r; j++)
    {
        if (a[j] <= x)
        {
            i++;
            int tmp = a[i];
            a[i] = a[j];
            a[j] = tmp;
        }
    }
    int tmp = a[i + 1];
    a[i + 1] = a[r];
    a[r] = tmp;
    return i + 1;
}

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

    for (int i = 0; i < n; i++)
    {
        if (i == q)
            cout << '[';
        cout << a[i];
        if (i == q)
            cout << ']';
        if (i != n - 1)
            cout << ' ';
    }
    cout << endl;
}


Measured memory_bytes: 3400
#include<iostream>
#include<map>
#include<vector>
using namespace std;

//前処理は O(n)、毎回の二項係数計算は O(1)

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

map<int, int>prime_factor(int n) {
	map<int, int>res;
	for (int i = 2; i*i <= n; i++) {
		while (n%i == 0) {
			res[i]++;
			n /= i;
		}
	}
	if (n != 1)res[n]++;//nは素数
	return res;
}


int main() {
	// 前処理
	COMinit();
	int n, m;
	cin >> n >> m;
	map<int, int>mp = prime_factor(m);
	long long ans = 1;
    long long d = 1;
	for (int i = 2; i*i <= m; i++) {
		if (mp[i] > 0) {
			//iの素因数
			ans *= COM(n + mp[i] - 1, mp[i]);
			ans %= MOD;
            for (int j = 0; j < mp[i]; j++) {
                d *= i;
            }
			//n/iの素因数
			if ((m / d)*(m / d) > m  ) {
				ans *= COM(n + mp[m / d] - 1, mp[m / d]);
				ans %= MOD;
			}
		}
	}
	if (mp[m] == 1)ans = n;
	cout << ans << endl;
}

Measured memory_bytes: 13696
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(ll i=0;i<N;++i)
typedef long long int ll;
ll INF = 1LL<<60;

string S;

int main(){
    cin >> S;
    ll cnt = 1;
    string cur = S.substr(0,1);
    string tar = "";
    for(int i = 0;i < S.size();i++){
        for(int j=1;i+j < S.size();j++){
            if(i + j < S.size()){
                tar = S.substr(i+1,j);

            }else{
                //cout << cur << " " << tar << endl;
                cnt ++;
                cur = tar;
                tar = "";
                i += j-1;
                break;
            }
            if(cur != tar){
                //cout << cur << " " << tar << endl;
                cnt ++;
                cur = tar;
                tar = "";
                i += j-1;
                break;
            }
        }
    }
    cout << cnt << endl;
}

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

/************* Using *************/
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using graph_t = vector<vector<ll>>;

/*********** Constants ***********/
const auto INF  = static_cast<int>(1e10);
const auto INFL = static_cast<ll>(1e18);
const auto MOD  = static_cast<ll>(1e9 + 7);
const auto NIL  = nullptr;

/*********** Variables ***********/
ll N, D, ANS;

/************* Utils *************/

/*********** Functions ***********/
bool init() {
    cin >> N >> D;
    return true;
}

void solve() {
    ANS = N / (2 * D + 1);
    if (N % (2 * D + 1)) {
        ANS++;
    }
}

void output() {
    cout << ANS << endl;
}

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


Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int A = sc.nextInt();
	int B = sc.nextInt();
	int C = sc.nextInt();
	int X = sc.nextInt();
	int cnt = 0;
	for(int i = 0 ; i<=A; i++) {
	    for(int j = 0; j<=B; j++) {
		for(int k = 0; k<=C; k++) {
		    if(i*500+j*100+k*50 == X) cnt++;
		}
	    }
	}
	System.out.println(cnt);
    }
}

Measured memory_bytes: 23252
N=int(input())
A=list(map(int,input().split()))
n_minus=sum([a<0 for a in A])
abs_A=[abs(a) for a in A]
ans=sum(abs_A)
if n_minus%2==0:
        print(ans)
else:
        print(ans-2*min(abs_A))

Measured memory_bytes: 14412
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
const ll INF = 1LL<<60;
const ll M = pow(10,9)+7;
/*template*/


int main()
{
  ll r;cin>>r;
  printf("%.5lf",3.14159265*2*r);
  return 0;
}


Measured memory_bytes: 3764
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;
	int32_t res = 0;
	for (size_t i = 0; i < N; i++)
	{
		int32_t a;
		in >> a;
		res += a - 1;
	}
	out << res << endl;

	return 0;
}
#endif


Measured memory_bytes: 888
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
bc = [map(int, input().split()) for _ in range(m)]
cb = sorted([[c, b] for b, c in bc])
j = len(cb) - 1
for i in range(n):
    if j >= 0 and a[i] < cb[j][0]:
        a[i] = cb[j][0]
        cb[j][1] -= 1
    if cb[j][1] == 0:
        j -= 1
print(sum(a))

Measured memory_bytes: 61868
import fractions
a, b = map(int, input().split())
common_num = fractions.gcd(a, b)
 
ans = 1
for i in range(2,int(1+common_num**0.5)):
  if common_num % i == 0:
    ans += 1
    while common_num % i == 0:
      common_num //= i
if common_num > 1:
  ans += 1
      
print(ans)

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

int main() 
{
    string s;
    cin>>s;
    int ans=0;
    
    for(int i=0;i<s.size();i++){
        if(s[i]=='+') ans++;
        else ans--;
    }
    
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 764
#include<iostream>

using namespace std;

int n, m, k, p;
char a[100][101];
int b[102];

int main() {
	for (int i = 0; i < 101; i++)b[i] = 100;
	cin >> n >> m;
	p = 0;

	for (int i = 0; i < n; i++) {
		k = 0;
		cin >> a[p];
		for (int j = 0; j < m; j++) {
			if (a[p][j] == '.')k++;
		}
		if (k == m)p--;
		p++;
	}
	n = p;
	
	p = 0;
	for (int j = 0; j < m; j++) {
		k = 0;
		for (int i = 0; i < n; i++) {
			if (a[i][j] == '.')k++;
		}
		if (k == n) {
			b[p] = j;
			p++;
		}
	}
	for (int i = 0; i < n; i++) {
		p = 0;
		for (int j = 0; j < m; j++) {
			if (b[p] != j) {
				cout << a[i][j];
			}
			else {
				p++;
			}
		}
		cout << '\n';
	}
	cin >> n;
	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

int main() {
  int a, b, c;
  
  cin >> a >> b >> c;
  
  if (a == b && a == c && b == c) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

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

int main(void) {

	int a,b;

	scanf("%d%d",&a,&b);

	if(a<b){
		printf("a < b\n");
	}
	else if(a>b){
		printf("a > b\n");
	}
	else{
		printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define pb push_back
#define pf pop_front
#define mp make_pair
#define mod 1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mat vector<vector<int>>
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define fo(i,n) for(int i=0;i<n;i++)
#define inp(a) int a;cin>>a;
#define inpa(a,n)vector<int> a(n);fo(i,n)cin>>a[i];
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;
#define int ll


auto max(auto a){auto ans=a[0];for(auto i:a)if(i>ans)ans=i;return ans;}
auto min(auto a){auto ans=a[0];for(auto i:a)if(i<ans)ans=i;return ans;}
void print(auto a){for(auto i:a)cerr<<i<<' ';cerr<<'\n';}

int dp[3000][3000];
int n;
vector<int> a;

int fdp(int l,int r)
{
	if(l==r)
		return a[l];
	if(dp[l][r]!=-1)
		return dp[l][r];
	dp[l][r]=max(a[l]-fdp(l+1,r),-fdp(l,r-1)+a[r]);
	return dp[l][r];
}

signed main()
{
	fio
	cin>>n;
	memset(dp,-1,sizeof(dp));
	a.resize(n);
	fo(i,n)
		cin>>a[i];
	cout<<fdp(0,n-1)<<'\n';
	printclock;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
#define LL long long
const double epsilon=double(1e-9);
int main(int argc,char *argv[]){
	if(argc>=2){freopen(argv[1],"r",stdin);}
	if(argc>=3){freopen(argv[2],"w",stdout);}
	
	LL x;cin>>x;
	LL y=(LL)((sqrt(x*8+1)-1)/2+epsilon);
	if((y+1)*y/2<x)++y;
	cout<<y;
	fclose(stdin);fclose(stdout);
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long
#define inf 1000000007 //10^9+7
#define sort(vec) sort(vec.begin(),vec.end());
#define rever(vec) reverse(vec.begin(),vec.end());
#define unsort(vec) sort(vec); rever(vec);
#define gcd __gcd
using namespace std;
bool pri(ll p);
int main() {
  ll n;
  cin>>n;
  ll a=0;
  ll cnt=0;
  ll ans=1;
  vector<ll>vec(1010);
  for(ll i=2;i<=n;i++) {
    a=i;
    for(ll j=2;j<=n;j++) {
      if(pri(j)) {
        while(a%j==0) {
          a/=j;
          cnt++;
        }
      }
      if(cnt) {
        vec.at(j)+=cnt;
      }
      cnt=0;
    }
  }
  for(ll i=0;i<1010;i++) {
    if(vec.at(i)) {
      ans*=(vec.at(i)+1);
    }
    ans%=inf;
  }
  cout<<ans<<endl;
}
bool pri(ll p) {
  if(p==1) {
    return 0;
  }
  else {
    ll ans=0;
    for(ll i=2;i<=sqrtl(p);i++) {
      if(p%i==0) {
        ans++;
        break;
      } 
    }
    if(ans==0) {
      return 1;
    }
    else {
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define M 1000000007
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define f first
#define s second
#define b begin
#define e end
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a;i<b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define itfr(it,x) for(it=x.begin();it!=x.end();it++)
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;

int main()
{
    flash;
    //sieve();
    ll T=1,t,n,m,q,k,i,j;
    // cin>>T;
    while(T--)
    {
      string st;
      cin>>st;
      int fl=1;
      n = st.size();
      vector<int> ind(26,-10);
      FOR(i,0,n)
      {
        int x = ind[st[i]-'a'];
        if((i-x)<3){
          cout<<x+1<<" "<<i+1<<endl;
          fl=0;
          break;
        }
        ind[st[i]-'a']=i;
      }
      if(fl)
        cout<<-1<<" "<<-1<<endl;
    }
}

Measured memory_bytes: 3796
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
s = sum(A)
flag = False
def make_divisors(n):
    divisors = []
    for i in range(int(n**0.5), 0, -1):
        if n%i == 0:
            divisors.append(i)
            if i != n//i:
                divisors.append(n//i)
    return sorted(divisors, reverse=True)
divs = make_divisors(s)
for x in divs:
    if flag:
        break
    sortedA = sorted([a%x for a in A])
    sumA = sum(sortedA)
    index_len = len(sortedA)
    sump = 0
    for i, a in enumerate(sortedA):
        sump += a
        summ = x*(index_len - (i+1)) - (sumA - sump)
        if sump == summ and sump <= K:
            print(x)
            flag = True
            break



Measured memory_bytes: 3192
import java.util.*;
 
class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    int l = sc.nextInt();
    String[] s = new String[n];
    for(int i=0; i<n; i++){
      s[i] = sc.next();
    }
    Arrays.sort(s);
    String ans = "";
    for(int i=0; i<n; i++){
      ans += s[i];
    }
    System.out.println(ans);

    sc.close();
  }
}

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

int main() {
  int N, Y;
  cin >> N >> Y;
  for (int i = 0; i <= N; ++i) {
    for (int j = 0; j <= N - i; ++j) {
      if (10000 * i + 5000 * j + 1000 * (N - i - j) == Y) {
        cout << i << ' ' << j << ' ' << N - i - j << '\n';
        return 0;
      }
    }
  }
  cout << "-1 -1 -1\n";
}

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

//		Using bottom up approach

using namespace std;

int main(void){

    int n;
    cin >> n;
    long long int a[n], b[n], c[n];
    long long int x[n], y[n], z[n];

    for(int i=0;i<n;++i){
        cin >> a[i] >> b[i] >> c[i];
        x[i] = 0;
        y[i] = 0;
        z[i] = 0;
    }

    for(int i=n-1; i>=0; --i){
        if(n-i==1){
            x[i] = a[i];
            y[i] = b[i];
            z[i] = c[i];
        }else{
            x[i] = a[i] + max(y[i+1], z[i+1]);
            y[i] = b[i] + max(x[i+1], z[i+1]);
            z[i] = c[i] + max(y[i+1], x[i+1]);
        }
    }
    cout << max(max(x[0], y[0]), z[0]);
    return 0;
}

Measured memory_bytes: 4864
def main():
    n = int(input())
    h_list = list(map(int, input().split()))
 
    dp = [100000]*n
 
    dp[0] = 0
    for i in range(1,n):
 
        tmp_dp1 = 1000000
        tmp_dp2 = 1000000
        if i - 1 >= 0:
            tmp_dp1 = dp[i-1] + abs(h_list[i] - h_list[i-1])
 
        if i - 2 >= 0:
            tmp_dp2 =  dp[i-2] + abs(h_list[i] - h_list[i-2])
        dp[i]=min(tmp_dp1, tmp_dp2)
    print(dp[n-1])
main()

Measured memory_bytes: 20524
/* Author - thiolhub */

#include <bits/stdc++.h>

using namespace std;

#define ll              long long int
#define ld              long double
#define db              double
#define pi              3.1415926535897932384626
#define PI              acos(-1.0)
#define endl            "\n"
#define mod             1000000007
#define mk              make_pair
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            ll t; cin>>t; while(t--)
#define sc(a)	        scanf("%lld",&a);
#define pr(a)	        printf("%lld\n",a)
#define f(i,a,n)		for(ll i=a;i<n;i++)
#define m(a)		    memset(a,0,sizeof(a))
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)



int main(){ FastIO;

unordered_map<int,int> h;
int a,b,c;
cin>>a>>b>>c;
h[a]++;h[b]++;h[c]++;
int res=0;
for(auto x:h) res++;
if(res==2) cout<<"Yes";
else cout<<"No";

return 0;
}

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

using namespace std;
#define IOS cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

using ll = long long;
using ld = long double;

const ll INFL = 1e18L+5;

void min_self(ll &a, ll b){
    a = min(a, b);
}

int main(){
    IOS

    int n, W;
    cin>>n>>W;

    int w[n+5], v[n+5];
    int sum = 0;

    for(int i = 0; i < n; i++){
        cin>>w[i]>>v[i], sum+= v[i];
    }

    ll dp[sum+5];

    for(int i = 0; i <= sum; i++){
        dp[i] = INFL;
    }

    dp[0] = 0;
    for(int j = 0; j < n; j++){
        for(int i = sum-v[j]; i >= 0; --i){
            min_self(dp[i+v[j]], w[j] + dp[i]);
        }
    }

    int ans = -1;
    for(int i = sum; i >= 0 ; --i){
        if(dp[i]<= W){
            ans = i;
            break;
        }
    }

    cout<<ans<<"\n";


}


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

int main() {
    
    int len, cnt=0;
    string s1, s2;
    cin >> s1 >> s2;
    len = s1.length();
    
    for(int i=0; i<len; i++){
        if(s1[i] != s2[i]) ++cnt;
    }
    cout << cnt << endl;
    
    
	return 0;
}

Measured memory_bytes: 3828
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

template<class T, class S>
bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S>
bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}


int main(){
    string S, T; cin >> S >> T;
    int A, B; cin >> A >> B;
    string U; cin >> U;
    if(S == U) --A;
    else --B;
    cout << A << " " << B << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	long long int a[3000000],Min,Max,total=0;
	int n,i;

	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%lld",&a[i]);
		if (i==0) {
			Min=a[i];
			Max=a[i];
		}
		if( Min>a[i] ){
			Min=a[i];
		}
		if ( Max<a[i] ) {
			Max=a[i];
		}
		total+=a[i];
	}


	printf("%lld %lld %lld\n",Min,Max,total);



	return 0;
}



Measured memory_bytes: 2000
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - Meal Delivery
            var line = ReadLine();
            int x = line[0];
            int a = line[1];
            int b = line[2];

            if (Math.Abs(x - a) < Math.Abs(x - b))
            {
                Console.WriteLine("A");
            }
            else
            {
                Console.WriteLine("B");
            }
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

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

using namespace std;

int main(){
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif

	int a[5], ans = 0;

	for (int i = 0; i < 5; i++){
		scanf("%d", &a[i]);
		if (a[i] == 0) ans = i + 1;
	}

	printf("%d\n", ans);

	return 0;
}

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

using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;
    int p[M];
    string S[M];
    for (int i = 0; i < M; i++)
    {
        cin >> p[i] >> S[i];
    }
    bool is_ac[N + 1];
    for (int i = 0; i < N + 1; i++)
    {
        is_ac[i] = false;
    }

    int pena[N + 1] = {0};
    for (int i = 0; i < M; i++)
    {
        if (is_ac[p[i]] == false && S[i] == "AC")
        {
            is_ac[p[i]] = true;
        }
        if (is_ac[p[i]] == false && S[i] == "WA")
        {
            pena[p[i]]++;
        }
    }
    int cnt_ac = 0;
    int cnt_pena = 0;
    for (int i = 0; i < N + 1; i++)
    {
        if (is_ac[i])
        {
            cnt_ac++;
            cnt_pena += pena[i];
        }
    }
    cout << cnt_ac << " " << cnt_pena << endl;
}

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

typedef struct{
  double x,y;
}Point;

void koch(int n, Point p1, Point p2){
  Point s, t, u;
  double th = M_PI * 60 / 180;
  
  if(n == 0) return;
  
  s.x = (2 * p1.x + 1 * p2.x) / 3;
  s.y = (2 * p1.y + 1 * p2.y) / 3;
  t.x = (1 * p1.x + 2 * p2.x) / 3;
  t.y = (1 * p1.y + 2 * p2.y) / 3;
  u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
  u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

  koch(n-1,p1,s);
  printf("%.8f %.8f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  koch(n-1,t,p2);
}


int main(){
  Point a,b;
  int n;

  a.x = 0;
  a.y = 0;
  b.x = 100;
  b.y = 0;
  
  scanf("%d",&n);

  printf("%.8f %.8f\n",a.x,a.y);
  koch(n,a,b);
  printf("%.8f %.8f\n",b.x,b.y);

  return 0;
}
  



Measured memory_bytes: 2104
#include<stdio.h>

int search(int , int);

int n,A[20];


int main(){
int q, M[2000], i;

scanf("%d",&n);
for(i = 0; i < n; i++)
scanf("%d",&A[i]);
scanf("%d",&q);
for(i = 0;i < q; i++){
scanf("%d",&M[i]);
if( search(0,M[i]) == 1) printf("yes\n");
else printf("no\n");
}
return 0;
}

int search(int i, int m){
if(m == 0) return 1;
if(i >= n) return 0;
int res = search(i + 1, m) || search(i + 1, m - A[i]);
return res;
}

Measured memory_bytes: 588
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using namespace std;


int main(){
  string S,T,U;
  int A,B;
  cin>>S>>T>>A>>B>>U;
  
  
  if(S==U) cout<<A-1<<" "<<B<<endl;
  if(T==U) cout<<A<<" "<<B-1<<endl;
}

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

int main() {

  while( true ) {

    long long int h;
    cin >> h;
    if ( h == 0 ) break;

    vector< vector< long long int > > v;

    for ( long long int y = 0; y < h; y++ ) {

      vector< long long int > w;
      w.push_back( 0 );

      for ( long long int x = 0; x < 5; x++ ) {

	long long int in;
	cin >> in;
	w.push_back( in );

      }

      w.push_back( 0 );

      v.push_back( w );

    }

    long long int ans = 0;

    while( true ) {

      bool f = false;

      for ( long long int y = 0; y < h; y++ ) {

	long long int cnt = 0;
	long long int num = 0;

	for ( long long int x = 0; x < 7; x++ ) {

	  if ( v[y][x] != num ) {
	    if ( cnt >= 3 && num != 0 ) {
	      ans += cnt * num;
	      f = true;
	      for ( long long int k = 0; k < cnt; k++ ) {
		v[y][x-k-1] = 0;
	      }
	    }
	    cnt = 1;
	    num = v[y][x];
	  }else {
	    cnt++;
	  }

	}

      }

      if ( f == false ) {
	cout << ans << endl;
	break;
      }

      for ( long long int x = 1; x <= 5; x++ ) {

	long long int m = -1;

	for ( long long int y = h - 1; y >= 0; y-- ) {

	  if ( v[y][x] == 0 && m == -1 ) {
	    m = y;
	  }
	  if ( v[y][x] != 0 && m != -1 ) {
	    v[m][x] = v[y][x];
	    v[y][x] = 0;
	    m--;
	  }

	}

      }

    }

  }

  return 0;

}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
#define I inline int
#define V inline void
#define ll long long int
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
const int N=2e2+5;
struct bas{
	ll a[64];
	V init(){FOR(i,0,63)a[i]=0;}
	V ins(ll x){
		ROF(i,63,0)if(x>>i&1){
			if(!a[i])return void(a[i]=x);
			else x^=a[i];
		}
	}
	I find(ll x){
		ROF(i,63,0)if(x>>i&1){
			if(a[i])x^=a[i];
			else return false;
		}
		return true;
	}
}now;
ll a[N];
char st[N];
int T,n,ans;
int main(){
	for(scanf("%d",&T);T--;cout<<ans<<'\n'){
		scanf("%d",&n),now.init(),ans=0;
		FOR(i,1,n)scanf("%lld",a+i);
		scanf("%s",st+1);
		ROF(i,n,1)
			if(st[i]=='0')now.ins(a[i]);
			else if(!now.find(a[i]))ans=1;
	}
	return 0;
}

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

int res[10];
int top = 0;

void push(int x){
	res[top] = x;
	top++;
}

void pop(){
	res[top] = -1;
	if(top > 0)top--;
}

int main(void){
	char s[11];
	int i;
	scanf("%s",s);
	for(i=0;i<10;i++){
		if(s[i]=='0'){
			push(0); 
		}else if(s[i]=='1'){
			push(1);
		}else if(s[i]=='B'){
			pop();
		}
	}
	for(i=0;i<top;i++){
		printf("%d",res[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
import math
a,b,x=map(int,input().split())
if a*a*b/2<=x:
    ans=math.degrees(math.atan((2*a*a*b-2*x)/(a**3)))
else:
    ans=math.degrees(math.atan((a*b*b)/(2*x)))
print(ans)

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

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

  if (N*A%2) {
    cout << "Odd" << endl;
  }
  else{
    cout << "Even" << endl;
  }
  // ここにプログラムを追記
}

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

const int INF = 1<<30;
int N, Q;
string S;
vector<set<int> > pls;

void solve() {
    pls.assign(26, set<int>({INF}));
    for (int i = 0; i < N; ++i) pls[S[i] - 'a'].insert(i);

    while (Q--) {
        int type; cin >> type;
        if (type == 1) {
            int ind; char nc; cin >> ind >> nc; --ind;
            auto pc = S[ind];
            S[ind] = nc;
            pls[pc - 'a'].erase(ind);
            pls[nc - 'a'].insert(ind);
        }
        else {
            int l, r; cin >> l >> r; --l;
            int res = 0;
            for (int c = 0; c < 26; ++c) {
                if (pls[c].empty()) continue;
                int lid = *pls[c].lower_bound(l);
                int rid = *pls[c].lower_bound(r);
                if (rid > lid) ++res;
            }
            cout << res << endl;
        }
    }
}

int main() {
    cin >> N >> S >> Q;
    solve();
}

Measured memory_bytes: 26244
#include <bits/stdc++.h>
using namespace std;
const int N = 111;
int ans[N][N];
int h, w;
int n;
int a[N * N];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> h >> w;
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	int i = 0, j = 0;
	for(int c = 1; c <= n; c++){
		while(a[c]--){
			ans[i][j] = c;
			if(i & 1){
				j--;
				if(j == -1){
					j = 0;
					i++;
				}
			}
			else{
				j++;
				if(j == w){
					j = w - 1;
					i++;
				}
			}
		}
	}
	for(int i = 0; i < h; i++)
		for(int j = 0; j < w; j++)
			cout << ans[i][j] << " \n"[j == w - 1];
	return 0;
}


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

void printv(vector<ll> v) {
  for (ll i : v)
    cout << i << endl;
}

int main() {
	ll n;
	cin>>n;
	cout<<n*(n-1)/2<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<int> a(M), b(M);
  vector<set<int>> E(N);
  for (int i = 0; i < M; i++){
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    E[a[i]].insert(b[i]);
    E[b[i]].insert(a[i]);
  }
  int count = 0;
  for (int i = 0; i < M; i++){
    int A = a[i];
    int B = b[i];
    queue<int> Q;
    Q.push(0);
    vector<bool> F(N, false);
    F[0] = true;
    int n = 1;
    while (!Q.empty()){
      int v = Q.front();
      Q.pop();
      for (auto w : E[v]){
        if ((v != A || w != B) && (v != B || w != A) && !F[w]){
          Q.push(w);
          F[w] = true;
          n++;
        }
      }
    }
    if (n != N){
      count++;
    }
  }
  cout << count;
}

Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    let handle = std::io::stdin();
    handle.read_line(&mut buf).unwrap();
    let n: isize = buf.trim().parse().unwrap();
    buf.clear();

    match n {
        1 => { println!("{}", "Hello World");},
        2 => {
            handle.read_line(&mut buf).unwrap();
            handle.read_line(&mut buf).unwrap();
            let v: Vec<isize> = buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
            println!("{}", v[0] + v[1]);
        },
        _ => {},
    }

}

Measured memory_bytes: 4352
use std::io;
use std::collections::HashMap;
use std::collections::BinaryHeap;
use std::mem;
use std::cmp;

fn read_line() -> String{
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn read_ints() -> Vec<i64>{
    let s = read_line();
    let split:Vec<&str> = s.split(" ").collect();
    split.iter().map(|&x| x.to_string().parse().unwrap()).collect()
}


fn main(){
    let n = read_ints()[0];
    let mut xs = read_ints();
    let mut m  = 0;
    let mut out_x = Vec::new();
    let mut out_y = Vec::new();
    
    for i in 0..xs.len(){
        m = if xs[i].abs() < xs[m].abs(){m}else{i};
    }
    
    
    
    //println!("{},{}",m,xs[m]);
    
    if xs[m] > 0 {
        let mut idx = 0;
        
        loop{
            if idx == xs.len()-1{
                break;
            }
            
            if xs[idx] <= xs[idx+1]{
                idx += 1;
            }else{
                out_x.push(m+1);
                out_y.push(idx+1+1);
                
                xs[idx+1] += xs[m];
                m = if xs[idx+1].abs() < xs[m].abs(){m}else{idx+1};
            }
        }
    }else{
        let mut idx = xs.len()-1;
        
        loop{
            if idx == 0{
                break;
            }
            
            if xs[idx-1] <= xs[idx]{
                idx -= 1;
            }else{
                out_x.push(m+1);
                out_y.push(idx-1+1);
                
                xs[idx-1] += xs[m];
                m = if xs[idx-1].abs() < xs[m].abs(){m}else{idx-1};
            }
        }
    }
    
    println!("{}",out_x.len());
    
    for i in 0..out_x.len(){
        println!("{} {}",out_x[i],out_y[i]);
    }
}



/*
DOCS


let mut h = HashMap::new();
let a = 5;
h.insert(a,true);
match h.get(&a){
    Some(v) => println!("{}",v),
    None    => println!("none"),
}


use std::mem;

let mut x = 5;
let mut y = 1;
mem::swap(&mut x,&mut y);


let v = vec![0;2]; // [0,0]

s.chars().nth(i as usize).unwrap();


// priority queue
// https://doc.rust-lang.org/std/collections/struct.BinaryHeap.html
use std::collections::BinaryHeap;
let mut heap = BinaryHeap::new();

heap.push(1);
heap.push(5);
heap.push(2);

assert_eq!(heap.pop(), Some(5));
assert_eq!(heap.pop(), Some(2));
assert_eq!(heap.pop(), Some(1));
assert_eq!(heap.pop(), None);


let mut vs = heap.into_vec();
vs.reverse();



*/

Measured memory_bytes: 4352
#include <iostream>
#include <cmath>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <stack>
#include <algorithm>
#include <map>
#include <numeric>
#include <set>
using namespace std;

#define ll long long
#define ld long double
// v:vector  type:型  order:greater or less
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
// vector 要素の総和算出
// v:vector  default_value:初期値
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
// vector 最大値( return ite )
#define _max_element(v) max_element(v.begin(),v.end())
// vector 最大値が格納されている要素値
#define _max_element_number(v) distance(v.begin(),max_element(v.begin(),v.end()))

//set<uint32_t> member;	// 重複するデータを保持する事はできない member.insert(2) member.insert(2) ⇒ member.count(2)は1
//multiset<uint32_t> v;	// 重複するデータも保持する事はできる   member.insert(2) member.insert(2) ⇒ member.count(2)は2

// 丸め
#define _round(v) round(v)
// 2乗 / 3乗
#define _square(v) pow(v,2)
#define _cube(v)   pow(v,3)
// 大小判定
#define _max(x,y) max(x,y)
#define _min(x,y) min(x,y)
// string ⇒ int
#define _stringtoi(s) stoi(s)
// double 平方根
#define _sqrt(x) sqrt(x)
// double 引数 x 以上で最小の整数値 ex) 3.30303 ⇒ 4
#define _ceil(x) ceil(x)
// 指定された要素以上の値が現れる最初の位置のイテレータを取得する
#define _lower_bound(v,min) lower_bound(v.begin(), v.end(), min)
// 指定された要素より大きい値が現れる最初の位置のイテレータを取得する
#define _upper_bound(v,min) upper_bound(v.begin(), v.end(), min)

// 順列 n個の数が与えられる
// 0,1,2,...,n-1
// 全ての並べ方を1行ごとに出力する
// ex 0 1 2 / 0 2 1 / 1 0 2 / 1 2 0 / 2 0 1 / 2 1 0
#define _next_permutation(v) do {   \
	for (auto num : v) {            \
		printf("%d ", num);         \
	}                               \
	printf("\n");                   \
} while (next_permutation(v.begin(), v.end()))

// 絶対値
static int32_t _abs(const int32_t x) { return  (x > 0 ? x : -x); }
// 最大公約数
static int gcd(int a, int b)
{
	if (a < b) {
		a ^= b;
		b ^= a;
		a ^= b;
	}
	return b ? gcd(b, a % b) : a;
}
// 最小公倍数
static int lcm(int a, int b) { return a * b / gcd(a, b); }
// 多次元 std::vector 生成
template<class T>
vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
// ex) auto dp = make_vec<uint64_t>(SIZE + 1, 2, 2);

int main()
{
	uint32_t n,k;
	cin >> n >> k;

	vector<uint32_t> v(n+1,0);

	for (uint32_t i = 0; i < k; i++) {
		uint32_t d;
		cin >> d;
		for (uint32_t j = 0; j < d; j++) {
			uint32_t temp;
			cin >> temp;
			v[temp]++;
		}
	}

	uint32_t result = 0;
	for (uint32_t i = 1; i < n+1; i++) {
		if (!v[i]) { result++; }
	}

	printf("%d\n",result);
	return 0;
}


Measured memory_bytes: 3708
#include <iostream>

using namespace std;

int main()
{
	int a, b;
	
	cin >> a >> b;
	
	if ((a * b) % 2 == 0){
		cout << "Even" << "\n";
	}
	else {
		cout << "Odd" << "\n";
	}
	
	return (0);
	
}

Measured memory_bytes: 256
s=input()
if 1 <= int(s[2:]) <= 12 and 1 <= int(s[:2]) <= 12:
  print('AMBIGUOUS')
elif 1 <= int(s[2:]) <= 12:
  print('YYMM')
elif 1 <= int(s[:2]) <= 12:
  print('MMYY')
else:
  print('NA')

Measured memory_bytes: 3060