akhauriyash/Code-Regression huggingface dataset:
/*
    Problem 26
    https://atcoder.jp/contests/abc138/tasks/abc138_d
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 200005;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
vector<vector<int>> G(MAX, vector<int>());
vector<bool> visited(MAX);
vector<int> counter(MAX, 0);
/* function */
void bfs(int st) {
    queue<int> q;
    q.push(st);
    visited[st] = true;
    while (!q.empty()) {
        int from = q.front();
        q.pop();
        for (int to : G[from]) {
            if (visited[to]) continue;
            visited[to] = true;
            counter[to] += counter[from];
            q.push(to);
        }
    }
}
void dfs(int from) {
    visited[from] = true;
    for (int to : G[from]) {
        if (visited[to]) continue;
        counter[to] += counter[from];
        dfs(to);
    }
}
/* main */
int main(){
    int N, Q;
    cin >> N >> Q;
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for (int i = 0; i < Q; i++) {
        int a, c;
        cin >> a >> c;
        a--;
        counter[a] += c;
    }
    // bfs(0);
    dfs(0);

    for (int i = 0; i < N; i++)
        cout << counter[i] << (i == N-1 ? '\n' : ' ');
}

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

#define int long long
#define inf 1e7

int n, m, x, c[12], a[12][12];

int f(int i, array<int, 12> b, int d) {
	bool flag = true;
	for (int j = 0; j < m; ++j) {
		if (b[j] < x) {
			flag = false;
			break;
		}
	}
	if (flag) return d;

	if (i == n) return inf;

	array<int, 12> e = b;
	for (int j = 0; j < m; ++j) e[j] += a[i][j];
	return min(f(i + 1, b, d), f(i + 1, e, d + c[i]));
}

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

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

	array<int, 12> b;
	for (int i = 0; i < m; ++i) b[i] = 0;

	int o = f(0, b, 0);
	if (o != inf)
		cout << f(0, b, 0);
	else
		cout << -1;
}


Measured memory_bytes: 3660
# https://atcoder.jp/contests/agc015/tasks/agc015_a

n, a, b = map(int, input().split())

if b < a:
    print(0)
elif a != b and n == 1:
    print(0)
else:
    MIN = a * (n - 1) + b
    MAX = a + (n - 1) * b
    ans = MAX - MIN + 1
    print(ans)

Measured memory_bytes: 38256
#C
x,k,d=map(int, input().split())
 
#直線のみに進行すればいい場合の回数
s = abs(x)//d
 
#最短回数よりも移動可能回数の方が少ない場合
if s >= k:
    print(abs(x) - k*d)
 
#最短回数よりも多く移動する場合
else:
    if (k-s) %2 == 0:
        print(abs(x) - s*d)
    else:
        print(d-(abs(x) - s*d)) 

Measured memory_bytes: 9076
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h> //STL include
typedef long long ll;// long long int
const ll INF = 10000000000;//INFinity
using namespace std;//namespace

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}//transform
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//#define int long long // yabai

#define dump(x)  cout << #x << " = " << (x) << endl;// debug cout

#define FOR(i,a,b) for(int i=(a);i<(b);++i)// for macro
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define ALL(obj) (obj).begin(),(obj).end()// iterator

#define pb(a) push_back(a)//push_back
#define mp make_pair// make_pair


int main(){

    int h,w,n;
    cin>>h>>w>>n;

    vector<int>a(n);
    vector<int>b(n);
    REP(i,n)cin>>a[i]>>b[i];
    map<pair<int,int>,ll> map_;

    REP(i,n)REP(j,3)REP(k,3)if(a[i]-2+j>=0&&a[i]-2+j<h&&b[i]-2+k>=0&&b[i]-2+k<w)map_[mp(a[i]-2+j,b[i]-2+k)]++;

    vector<ll> ans(10,0);
    for(auto t:map_)if(t.first.first!=0&&t.first.second!=0&&t.first.first!=h-1&&t.first.second!=w-1)ans[t.second]++;
    ans[0]=1LL*(h-2)*(w-2)-accumulate(ALL(ans),0LL);
    for(auto a:ans)cout<<a<<endl;




    return 0;
}


Measured memory_bytes: 57344
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func main() {
	n := scanInt()
	xm := make(map[int]bool)
	cnt := 0
	for i := 0; i < n; i++ {
		a := scanInt()
		if a < 400 {
			xm[1] = true
		} else if a < 800 {
			xm[2] = true
		} else if a < 1200 {
			xm[3] = true
		} else if a < 1600 {
			xm[4] = true
		} else if a < 2000 {
			xm[5] = true
		} else if a < 2400 {
			xm[6] = true
		} else if a < 2800 {
			xm[7] = true
		} else if a < 3200 {
			xm[8] = true
		} else {
			cnt++
		}
	}
	fmt.Println(max(len(xm), 1), len(xm)+cnt)
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cstdio>
#include<string>
using namespace std;

typedef long long ll;
typedef pair<ll,int> P;

#define rep(i,x) for(int i = 0 ; i < x ; i ++)
#define rep1(i,x) for(int i = 1 ; i <= x ; i ++)
#define rrep(i,x) for(int i = x-1 ; i >= 0 ; i --)
#define pb push_back
#define sor(vec) sort(vec.begin(),vec.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define fr first
#define sc second

int a[32][32];
bool used[32][32];
int solve(int h,int w,int k){
	//cout << h << " " << w << " " << k << endl;
	int H = 0;
	rep(j,w){
		vector<int> vec;
		rep(i,h){
			if(!used[i][j]){
				vec.pb(a[i][j]);
			}
		}
		H = max ( H , (int)vec.size() );
		rep(i,vec.size()){
			a[i][j] = vec[i];
			used[i][j] = false;
		}
		for(int i = vec.size() ; i < h ; i ++){
			used[i][j] = true;
		}
	}
	
	/*rep(i,h){
		rep(j,w)cout << a[i][j];
		cout << endl;
	}*/
	
	int cnt = 0;
	rep(i,H){
		int K = 0;
		rep(j,w){
			if(!used[i][j]){
				if(j == 0 || a[i][j] == a[i][j-1]){
					K ++;
					if(K == k){
						for(int t = j-k+1 ; t <= j ; t ++){
							used[i][t] = true;
							cnt += a[i][t];
						}
					}
					else if(K > k){
						used[i][j] = true;
						cnt += a[i][j];
					}
				}
				else K = 1;
			}
			else K = 0;
		}
	}
	if(cnt == 0)return 0;
	//cout << "DEBUG" << endl;
	return cnt+2*solve(H,w,k);
}

int main(){
	int h,w,k;
	int A[32][32];
	cin >> h >> w >> k;
	rrep(i,h){
		string X;
		cin >> X;
		rrep(j,w){
			A[i][j] = X[j]-'0';
		}
	}
	
	int ret = 0;
	rep(i,h)rep(j,w){
		//puts("-----------");
		//cout << i << " " << j << endl;
		rep(I,h)rep(J,w){
			a[I][J] = A[I][J];
			used[I][J] = false;
		}
		used[i][j] = true;
		ret = max ( ret , solve(h,w,k) );
	}
	cout << ret << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define ff(i, c, n) for (ll i = c; i < n; i++)
#define fr(i, c, n) for (ll i = c; i >= n; --i)
#define INF 1e9 + 7

ll modpow(ll a, ll b, ll c)
{ //a^b%c in O(logb)
	ll res = 1;
	while (b > 0)
	{
		if (b & 1)
		{
			res = (res * a) % c;
		}
		a = (a * a) % c;
		b >>= 1;
	}
	return res;
}
ll modinv(ll m, ll n)
{ //modular inverse of n w.r.t m provided 1<=n<=(m-1) in O(logn) and m is prime
	ll inv[n + 1];
	inv[1] = 1;
	for (int i = 2; i < n + 1; ++i)
		inv[i] = (m - (m / i) * inv[m % i] % m) % m;
	return inv[n];
}

//a+b=a^b+2*(a&b)
int main()
{
	// your code goes here
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,m;
	cin>>n>>m;
	ll a[n],s=0,sum=0;
	ff(i,0,n){
		cin>>a[i];
		sum+=a[i];
	}
	sum=(sum%(4*m)==0)?sum/(4*m):(sum/(4*m))+1;
	ff(i,0,n){
		if(a[i]>=sum) s++;
	}
	if(s<m) cout<<"No";
	else cout<<"Yes";
	


	return 0;
}


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

int main() {
	// int型の2次元配列(3×3要素の)の宣言
	vector<vector<int>> A(3, vector<int>(3));

	// 入力 (2重ループを用いる)
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> A.at(i).at(j);
        }
    }
  
	// 選ばれた数字の数の読み込み
	int N;
  	cin >> N;
	vector<int> b(N); // N個の数データ
	
	// 数データを受け取る
	for (int i = 0; i < N; i++) {
		cin >> b.at(i);
	}

   // 同じ数字であるか確認
	for (int k=0; k<N; k++){
  		for (int i=0; i<3; i++){
			for (int j=0; j<3; j++){
				if (b.at(k) == A.at(i).at(j)){
					A.at(i).at(j) = 200;
                }
            }
		}
	}

   // ビンゴの確認
	if( (A.at(0).at(0)+A.at(0).at(1)+A.at(0).at(2)==600) ||
        (A.at(1).at(0)+A.at(1).at(1)+A.at(1).at(2)==600) ||
        (A.at(2).at(0)+A.at(2).at(1)+A.at(2).at(2)==600) ||
        (A.at(0).at(0)+A.at(1).at(0)+A.at(2).at(0)==600) ||
        (A.at(0).at(1)+A.at(1).at(1)+A.at(2).at(1)==600) ||
        (A.at(0).at(2)+A.at(1).at(2)+A.at(2).at(2)==600) ||
        (A.at(0).at(0)+A.at(1).at(1)+A.at(2).at(2)==600) ||
        (A.at(0).at(2)+A.at(1).at(1)+A.at(2).at(0)==600)){
      cout << "Yes" << endl;
    }
    else cout << "No" << endl;  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define fr first
#define sc second
#define ll long long int
#define bit(idx) idx&(-idx)
#define bin(x, a) bitset<a>(x)
#define all(A) A.begin(), A.end()
#define debug(x) cout << #x << " = " << x << endl;
using namespace std;



int main(){
	ios_base::sync_with_stdio(NULL); cin.tie(); cout.tie();
    int n, k; cin >> n >> k;
    set<int> c;
    for(int i = 0; i < k; i ++){
        int d; cin >> d;
        for(int j = 0; j < d; j ++){
            int x; cin >> x;
            c.insert(x);
        }
    }
    cout << n - c.size() << endl;
}
/**

*/



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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (a % 2 == 0 && a % 3 && a % 5) {
			cout << "DENIED";
			return 0;
		}
	}
	cout << "APPROVED";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int l;
  cin>>l;
  double v,x;
  x=(l/3.0);
  v=(x*x*x);
   cout << fixed << showpoint;
    cout << setprecision(12);
    cout<<v<<endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("Ofast")
//*********************************************DO IT NOW****************************************************************
#include<bits/stdc++.h> 
#include<random>
#define int long long   
#define pp pair<int,int> 
#define ss second 
#define ff first 
#define pb push_back
#define mod 1000000007
#define pi 3.14159265359
#define mk(arr,n,type)  type *arr=new type[n];
#define sl s1.length();
#define yes cout<< "YES"<<endl
#define no  cout<< "NO"<<endl
#define all(v) (v).begin(),(v).end()
#define s(v)   sort(v,v+n)
#define  mt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define print(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" "
#define for1(i,a,n)  for(int i=0;i<n;i++)
#define rep(i, c) for(int i = 0; i < (int)c; i++)
#define set(x) cout<<fixed<<setprecision(x);
using namespace std;
//**********************************************DO IT NO****************************************************************
void fastio()
{  
  #ifndef ONLINE_JUDGE
  freopen("INPUT.txt","r",stdin);
  freopen("OUTPUT.txt","w",stdout); 
  #endif
  ios_base :: sync_with_stdio(false); 
  cin.tie(NULL) ; 
  cout.tie(NULL);
}
int dp[101][1001],ans1=1e9,dp1[1000001];
int num[10];
int a[1000000];
signed main()
{   
    fastio();
    int t=1;
   // cin>>t;
    while(t--)
    {  
       string s;
       cin>>s;
       int x=0;
       for(int i=0;i<s.length();i++)
       {
           if(s[i]=='o')
           x++;
       }
       int ans=700+100*x;
       cout<<ans;
    }
}
// 🍪 🍪 🍪


Measured memory_bytes: 3572
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;

const int N = (int) 2e5 + 7;

int n, m;
vector<int> g[N];
bool used[N];

int dfs(int v) {
	used[v] = 1;
	int q = 1;
	for (int i = 0; i < g[v].size(); ++i) {
		int to = g[v][i];
		if (!used[to]) {
			q += dfs(to);
		}
	}
	return q;
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		int x, y;
		cin >> x >> y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	int ans = -1;
	for (int i = 1; i <= n; ++i) {
		if (!used[i]) {
			ans = max(ans, dfs(i));
		}
	}
	cout << ans;
}

Measured memory_bytes: 20532
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using STR = System.String;
using INT = System.Int32;
using DEC = System.Double;

class Program
{
    public static IO IO = new IO();
    static void Main(string[] args)
    {
        STR s = IO.S();
        int i = 0;
        int o = 0;
        for (;i < 6; i++)
        {
            if (s[i] == '1') { o++; }
        }
        IO.W(o);
        IO.F();
    }
}

public class IO
{
    private const int WMAX = 1000;
    private StringBuilder SB = new StringBuilder();
    private T R<T>(Func<STR, T> f) { return f(Console.ReadLine()); }
    private T[] R<T>(Func<STR, T> f, char c) { return S().Split(c).Select(f).ToArray(); }
    private T[] R<T>(Func<STR, T> f, INT l) { T[] r = new T[l]; for (INT i = 0; i < l; i++) { r[i] = R(f); } return r; }
    private T[][] R<T>(Func<STR, T> f, INT l, char c) { T[][] r = new T[l][]; for (INT i = 0; i < l; i++) { r[i] = R<T>(f, c); } return r; }
    private void W<T>(Func<T, STR> f, T v, bool lf = true) { SB.Append(f(v)); if (lf) { SB.Append('\n'); } if (SB.Length >= WMAX) { F(); } }
    public STR S() { return R(s => s); }
    public STR[] S(char c) { return R(s => s, c); }
    public STR[] S(INT l) { return R(s => s, l); }
    public STR[][] S(INT l, char c) { return R(s => s, l, c); }
    public INT I() { return R(INT.Parse); }
    public INT[] I(char c) { return R(INT.Parse, c); }
    public INT[] I(INT l) { return R(INT.Parse, l); }
    public INT[][] I(INT l, char c) { return R(INT.Parse, l, c); }
    public DEC D() { return R(DEC.Parse); }
    public DEC[] D(char c) { return R(DEC.Parse, c); }
    public DEC[] D(INT l) { return R(DEC.Parse, l); }
    public DEC[][] D(INT l, char c) { return R(DEC.Parse, l, c); }
    public void W(object s, bool lf = true) { W(v => v.ToString(), s, lf); }
    public void F() { Console.Write(SB); SB.Length = 0; }
}

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

int main(){
	int month, date;
	int c[11] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30};
	string s[7] = {"Wednesday","Thursday","Friday","Saturday","Sunday","Monday","Tuesday"};
	while(cin >> month >> date && month){
		int t = date;
		for(int i = 0;i < month-1;i++)t += c[i];
		cout << s[t%7] << endl;
	}
	return 0; 
}

Measured memory_bytes: 3048
#include <iostream>
#include <vector>
#include <string>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;

typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int a, b;
	cin >> a >> b;

	int ret = a - b * 2;
	if (ret < 0) ret = 0;
	cout << ret;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<atcoder/all>

using namespace std;
using namespace atcoder;

int main(){
    int n, q;
    fenwick_tree<long long> fw(500050);
    cin >> n >> q;
    for (int i = 0; i < n;i++){
        int a;
        cin >> a;
        fw.add(i, a);
    }
    int t, u, v;

    for (int i = 0; i < q;i++){
        cin >> t >> u >> v;
        if(t == 0){
            fw.add(u, v);
        }else{
            fw.sum(u, v);
            cout << fw.sum(u, v) << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 8224
#include<stdio.h>
int main(void)
{
 int i, j;
 
 for(i=1 ; i<10 ; i++)
 {
  for(j=1; j<10 ;j++)
  {
   printf("%dx%d=%d\n", i, j ,i*j);
  }
 }

 return 0;

}

Measured memory_bytes: 520
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> cs = new ArrayList<>();
        List<Integer> ss = new ArrayList<>();
        List<Integer> fs = new ArrayList<>();

        for (int i = 0; i < n - 1; i++) {
            int c = sc.nextInt();
            int s = sc.nextInt();
            int f = sc.nextInt();
            cs.add(c);
            ss.add(s);
            fs.add(f);
        }

        for (int i = 0; i < n - 1; i++) {
            int ans = 0;
            for (int j = i; j < n - 1; j++) {
                int mininum = ss.get(j);
                while (ans > mininum) {
                    mininum += fs.get(j);
//                    System.out.println(mininum);
                }
                ans = mininum;
                ans += cs.get(j);
//                System.out.println(ans);
            }
            System.out.println(ans);
        }
        System.out.println(0);
    }
}


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

int n, m, k[10], s[10][10], p[10];
int main() {
    cin >> n >> m;
    for(int i=0; i<m; i++) {
        cin >> k[i];
        for(int j=0; j<k[i]; j++) {
            int x; cin >> x;
            s[i][x - 1]++;
        }
    }
    for(int i=0; i<m; i++) cin >> p[i];
    int ans = 0;
    for(int bit=0; bit<(1<<n); bit++) {
        int as[m] = {0};
        bool flag = true;
        for(int i=0; i<n; i++) {
            if(bit>>i & 1) {
                for(int j=0; j<m; j++) as[j] += s[j][i];
            }
        }
        for(int j=0; j<m; j++) if(as[j] % 2 != p[j]) flag = false;
        if(flag) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << x << endl;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
// O(n^2m)
// bipartite graph O(\sqrt{n}m)
// capacityが同じ O(min{m^1/2,n^2/3}*m)
#include <cstring>  //for memset
#define MAX_V 100000
#define INF 10000000
struct edge {
    int to, cap, rev;
};
vector<edge> G[MAX_V];
int level[MAX_V];  // sからの距離
int iter[MAX_V];   //どこまで調べ終わったか

void add_edge(int from, int to, int cap) {
    G[from].push_back((edge){to, cap, static_cast<int>(G[to].size())});
    G[to].push_back((edge){from, 0, static_cast<int>(G[from].size() - 1)});
}

void bfs(int s) {
    memset(level, -1, sizeof(level));
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while (!que.empty()) {
        int v = que.front();
        que.pop();
        for (int i = 0; i < G[v].size(); ++i) {
            edge &e = G[v][i];
            if (e.cap > 0 && level[e.to] < 0) {
                level[e.to] = level[v] + 1;
                que.push(e.to);
            }
        }
    }
}

int dfs(int v, int t, int f) {
    if (v == t) return f;
    for (int &i = iter[v]; i < G[v].size(); ++i) {
        edge &e = G[v][i];
        if (e.cap > 0 && level[v] < level[e.to]) {
            int d = dfs(e.to, t, min(f, e.cap));
            if (d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s, int t) {
    int flow = 0;
    for (;;) {
        bfs(s);
        if (level[t] < 0) return flow;
        memset(iter, 0, sizeof(iter));
        int f;
        while ((f = dfs(s, t, INF)) > 0) {
            flow += f;
        }
    }
}
int main(){
    int n;
    cin >> n;
    vector<int>d(n);
    rep(i,n){
        cin >> d[i];
    }
    sort(d.begin(),d.end());
    int ans = 0;
    int mae = -1;
    rep(i,n){
        if(mae < d[i]){
            ans++;
            mae = d[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3192
n=gets.to_i
as=gets.split.map(&:to_i)

0.upto(as.length-1) do |i|
  as[i] -= (i+1)
end

as.sort!
c = as.length / 2
targets = []
targets << as[c+1] if as[c+1]
targets << as[c]
targets << as[c-1] if 0 <= c-1


bs = []
targets.each do |m|
  bs << as.map {|a| (a-m).abs}.inject(&:+)
end

p bs.min

Measured memory_bytes: 20600
import sys
from collections import *
from heapq import *
from fractions import gcd
import itertools
import math

sys.setrecursionlimit(10**6)

def InMap(): return list(map(int, input().split(' ')))
def In(): return int(input())
def InS(): return input()

S = InS()

res = {"SUN":7, "MON":6, "TUE":5, "WED":4, "THU":3, "FRI":2, "SAT":1}

print(res[S])


Measured memory_bytes: 6012
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,M;
  cin>>N>>M;
  
  map<int,pair<bool,int>>R;
  for(int i=0;i<M;i++){
  int x; string s;
    cin>>x>>s;
    if(s=="AC"){
    if(!R.count(x))
      R[x]=make_pair(true,0);
      else
        R[x]=make_pair(true,R.at(x).second);
    }else{
    if(!R.count(x))
      R[x]=make_pair(false,1);
      else{if(!R.at(x).first)
        R[x]=make_pair(false,1+R[x].second);}
    }
  }int ans=0;
   int ans1=0;
  for(auto p:R){
   auto k=p.first;
    auto v=p.second;
    if(v.first){
      ans++;
      ans1+=v.second;}
  }cout<<ans<<" "<<ans1<<endl;
  
  
  return 0;
}

Measured memory_bytes: 6528
#include<iostream>
#include<vector>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;
int main() {
	int N;
	int A = 0;
	cin >> N;
	vector<int> p(N);
	for (int i = 0; i < p.size(); i++) {
		cin >> p.at(i);
	}
	for (int i = 0; i < N - 2; i++) {
		if ((p.at(i) < p.at(i + 1) && p.at(i + 1) < p.at(i + 2)) || (p.at(i + 2) < p.at(i + 1) && p.at(i + 1) < p.at(i))) {
			A++;
		}
		else {
			continue;
		}
	}
	cout << A << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main ()
{
    int n,k,i,j,a[1005];
    cin>>n>>k;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    int sum=0;
    for(i=0;i<k;i++)
    {
        sum+=a[i];
    }
    cout<<sum<<endl;
    return 0;
}


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

int a[101];
int b[101];
int main(){
	int n,d,x;
	
	cin >> n >> d >> x;
	for(int i = 0;i < n;i++){
		cin >> a[i];
		b[i] = 1;
	}
	int ans = n;
	for(int i = 0;i < n;i++){
		while(b[i]+a[i]<=d){
			b[i]+=a[i];
			ans++;
		}
	}
	cout << ans+x;
}

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

#define vec(v) vector<int>(v)
#define be(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define mapci(mp) map<char*,int>(mp)
#define mapcc(mp) map<char*,char*>(mp)
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int g=a[0],ma=a[0];
    for(int i=1;i<n;i++){
        ma=max(ma,a[i]);
    }
    if(ma<k){
        cout << "IMPOSSIBLE"<<endl;
    }
    else{
        g=a[0];
        for(int i=1;i<n;i++){
            g=__gcd(g,a[i]);
        }
        if(k%g==0){
            cout <<"POSSIBLE"<<endl;
        }
        else{
            cout <<"IMPOSSIBLE"<<endl;
        }
    }
    return 0;
}


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

typedef long long ll;
#define pb push_back
#define ii pair<int ,int >
#define vi vector<int >
#define vii vector < pair<int ,int > >
#define IO ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define IOfiles freopen("input.txt","r+",stdin) ; freopen("output.txt","w+",stdout)
#define PI 3.14159265
const double eps = 1e-9;

int main()
{
	IO;
	int k,n;
	cin>>k>>n;
	int tab[n];
	for(int i=0;i<n;i++)
		cin>>tab[i];
	int md=k-tab[n-1]+tab[0];
	for(int i=0;i<n-1;i++){
		md=max(md,tab[i+1]-tab[i]);
	}
	cout<<k-md<<endl;

}

Measured memory_bytes: 1532
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int main(){
  int n;cin>>n;
  int a[n];
  int ans=0;
  rep(i,n){
    cin>>a[i];
    while(a[i]%2==0){
      a[i]/=2;
      ans++;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int N = s.length();
        int x = sc.nextInt();
        int y = sc.nextInt();
        ArrayList<Integer> x_axis = new ArrayList<Integer>();
        ArrayList<Integer> y_axis = new ArrayList<Integer>();
        int cnt = 0;
        int flag = 1;
        for (int i=0;i<N;i++) {
            if (s.charAt(i)=='F') {
                cnt++;
                if (i==N-1) {
                    if (flag==1) {
                        x_axis.add(cnt);
                    } else { // flag==-1
                        y_axis.add(cnt);
                    }
                }
            } else { // s.charAt(i)=='T'
                if (cnt!=0) {
                    if (flag==1) {
                        x_axis.add(cnt);
                    } else { // flag==-1
                        y_axis.add(cnt);
                    }
                }
                flag*=(-1);
                cnt=0;
            }
        }
        int x_size = x_axis.size();
        int y_size = y_axis.size();
        int[][] dp_x = new int[20000][x_size+1];
        int[][] dp_y = new int[20000][y_size+1];
        dp_x[10000][0]=1;
        for (int i=1;i<=x_size;i++) {
            for (int j=0;j<20000;j++) {
                if (dp_x[j][i-1]==1) {
                    dp_x[j+x_axis.get(i-1)][i]=1;
                    if (!(s.charAt(0)=='F' && i==1)) {
                        dp_x[j-x_axis.get(i-1)][i]=1;
                    }
                }
            }
        }
        dp_y[10000][0]=1;
        for (int i=1;i<=y_size;i++) {
            for (int j=0;j<20000;j++) {
                if (dp_y[j][i-1]==1) {
                    dp_y[j+y_axis.get(i-1)][i]=1;
                    dp_y[j-y_axis.get(i-1)][i]=1;
                }
            }
        }
        if (dp_x[x+10000][x_size]==1 && dp_y[y+10000][y_size]==1) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
        // System.out.println("x_axis: " + x_axis);
        // System.out.println("y_axis: " + y_axis);
    }
}

Measured memory_bytes: 457596
import sys
 
stdin = sys.stdin

mod = 1000000007
inf = 1 << 60
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n = ni()

p = n - 1
ans = p * (p + 1) // 2
print(ans)

Measured memory_bytes: 3060
N = int(input())
X = list(int(x) for x in input().split())
N_sum_HP = []


for p in range(min(X), max(X) + 1):
    sum_HP = 0
    for x in X:
        sum_HP += (x - p) ** 2
    N_sum_HP.append(sum_HP)
print(min(N_sum_HP))


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

bool is_prime(long long x) {
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      return false;
    }
  }
  return x != 1;
}

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

  for (int i = x; ; i++) {
    if (is_prime(i)) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
const ll MOD = 1000000007;//998244353;
ll dp[3001][3001];
int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int n;cin >> n;
   vector<int> a(n);
   rep(i,n)cin>>a[i];
   rep(i,n){
      dp[i][i] = (n%2==1) ? a[i] : -a[i];
   }
   for (int i = 1; i < n; i++){
      for (int j = 0; j+i < n; j++){
         if ((n-i)%2==1)
            dp[j][j+i] = max(dp[j+1][j+i]+a[j], dp[j][j+i-1]+a[j+i]);
         else
            dp[j][j+i] = min(dp[j+1][j+i]-a[j], dp[j][j+i-1]-a[j+i]);
      }
   }
   cout << dp[0][n-1] << endl;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
#define pb push_back

ll mod = 1000000007;

int main(){
    string L;
    cin >> L;

    int len = L.length();

    vector<ll> dp1(len);
    vector<ll> dp2(len);
    dp1[0] = 2;
    dp2[0] = 1;
    for (int i = 1; i < len; i++)
    {
        if (L[i] == '1'){
            dp1[i] = (dp1[i-1] * 2) % mod;
            dp2[i] = (dp1[i-1] + dp2[i-1] * 3) % mod;
        }
        else{
            dp1[i] = dp1[i-1];
            dp2[i] = (dp2[i-1] * 3) % mod;
        }
    }
    cout << (dp1[len-1] + dp2[len-1])%mod << endl;
    return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include<map>
#include<string>
#include<algorithm>
using namespace std;


int main() {
	string s;
	string st;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'B'&&!st.empty()) {
			st.pop_back();
		}
		else if(s[i]!='B'){
			st.push_back(s[i]);
		}
	}
	cout << st;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
n = input()
A = {}
for i in xrange(2, n+1):
    v = int(raw_input())
    A.setdefault(v, []).append(i)
f = lambda v: (v in A)/1 and 1+max(e+i for i,e in enumerate(sorted(map(f,A[v]))[::-1]))
print f(1)


Measured memory_bytes: 194104
use std::io;
use std::cmp;


fn main() {
    let (n, a, b) = {
        let i = read::<usize>();
        (i[0], i[1], i[2])
    };
    println!("{}", cmp::min(a * n, b));
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));
  int ans = 0;
  rep(i, n) if (x >= a[i]) {
    ans++;
    x -= a[i];
  }
  if (x != 0 && ans == n) ans--;
  cout << ans << endl;
}


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


int main() {
  string s;
  cin >> s;

  vector<ll> cnt(26, 0);
  ll n = s.size();
  ll res = n * (n - 1) / 2;
  rep(i,n) cnt[s[i] - 'a']++;
  rep(i,26) res -= cnt[i] * (cnt[i] - 1) / 2;
  cout << res + 1 << endl;
  return 0;
} 

Measured memory_bytes: 3732
w,h,n = map(int,input().split())
a_1 = []
a_2 = []
a_3 = []
a_4 = []
for i in range(n):
  x,y,a = map(int,input().split())
  if a == 1:
    a_1.append(x)
  elif a == 2:
    a_2.append(x)
  elif a == 3:
    a_3.append(y)
  else:
    a_4.append(y)
    
left_black = max(a_1,default = 0)
right_black = min(a_2,default = w)
under_black = max(a_3,default = 0)
upper_black = min(a_4,default = h)

answer = (right_black - left_black)*(upper_black - under_black)
if left_black > right_black or under_black > upper_black:
  answer = 0
print(answer)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string inputs = Console.ReadLine();
            long N = long.Parse(inputs.Split(new char[] { ' ' })[0]);
            long Y = long.Parse(inputs.Split(new char[] { ' ' })[1]);

            for (int y = 0; y <=  8; ++y) {
                var S = Y - y * 5000;
                var z = (10000 * N - 5000*y - Y) / 9000;
                var x = N - y - z;
                
                if (x < 0 || z < 0) continue;

                if (Y == x * 10000 + y * 5000 + z * 1000) {
                    Console.WriteLine(string.Format("{0} {1} {2}", x, y, z));
                    return;
                }
            }
            Console.WriteLine("-1 -1 -1");
        }
    }
}


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

int main()
{
	int a, b;
	cin >> a >> b;
	if ((a * b * 3) % 2 != 0) printf("Yes");
	else printf("No");
}

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

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

typedef long long ll;
typedef long long int64;

int main() {
  string s;
  cin >> s;

  int num = atoi(s.c_str());

  int top = floor(num/100);
  int bottom = floor(num%100);

  if((top > 12 || top == 0) && (bottom > 12 || bottom == 0)) {
    cout << "NA" << endl;
  }
  else if(top > 12 || top == 0) {
    cout << "YYMM" << endl;
  }
  else if(bottom > 12 || bottom == 0) {
    cout << "MMYY" << endl;
  }
  else {
    cout << "AMBIGUOUS" << endl;
  }

  return 0;
}


Measured memory_bytes: 764
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct BoolName : numpunct<char> {
  string t, f;
  BoolName (string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const {return t;}
  string do_falsename() const {return f;}
};

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

void set_bool_name(string t, string f) {
  cout.imbue(locale(cout.getloc(), new BoolName(t, f)));
}

template<typename T> bool chmin(T& a, T b) {return a > b ? a = b, true : false;}

template<typename T> bool chmax(T& a, T b) {return a < b ? a = b, true : false;}

int main() {
  int n, res = 0;
  cin >> n;
  unordered_map<int, int> m;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    ++m[a];
  }
  for (auto i : m) {
    int k = i.first;
    for (int j = -2; j <= 0; ++j) chmax(res, m[k + j] + m[k + j + 1] + m[k + j + 2]);
  }
  cout << res << endl;
}



Measured memory_bytes: 4388
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
#define MAX 120
typedef long long ll;

int main(){
  int N,countR=0,countB=0;
  string s;
  cin>>N>>s;
  for(int i=0;i<N;i++){
    if(s[i]=='R') countR++;
    else countB++;
  }
  if(countR>countB) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>

typedef long long ll;
//vector<int>


using namespace std;

int main() {
    ll q,h,s,d;
    cin>>q>>h>>s>>d;
    ll n;
    cin>>n;

    ll ans=0;
    while(n>=2){
        ans+=n/2*min(min(8*q,4*h),min(2*s,d));
        n=n-n/2*2;
    }
    while(n>=1){
        ans+=ll(n)*min(min(4*q,2*h),min(2*h,s));
        n=n-ll(n);
    }
    if(n==0.5){
        ans+=min(2*q,h);
    }
    else if(n==0.25){
        ans+=q;
    }
    cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
c = 0
A = ['.' * (W + 2)]
for _ in range(H):
    a = input()
    c += a.count('#')
    A.append('.' + a + '.')
A.append('.' * (W + 2))

right = [0, 1]
under = [-1, 0]
goal = [H, W]
now = [1, 1]
ans = 1
while now != goal:
    if A[now[0] + 1][now[1]] == '#' and A[now[0]][now[1] + 1] == '#':
        break
    if A[now[0] + 1][now[1]] == '#':
        ans += 1
        now[0] += 1
    else:
        if A[now[0]][now[1] + 1] == '#':
            ans += 1
            now[1] += 1
        else:
            break

if ans == c:
    print('Possible')
else:
    print('Impossible')


Measured memory_bytes: 3064
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
import std.concurrency;
void times(alias fun)(int n) {
    foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(int n) {
    T[] res = new T[n];
    foreach(ref e; res) e = fun();
    return res;
}
void main() {
    readln;
    int ans = 0;
    readln.chomp.map!"a=='I'?1:-1".fold!((a, b) {
        ans = max(ans, a+b);
        return a+b;
    })(0);
    ans.writeln;
}

// ----------------------------------------------

// fold was added in D 2.071.0
static if (__VERSION__ < 2071) {
    template fold(fun...) if (fun.length >= 1) {
        auto fold(R, S...)(R r, S seed) {
            static if (S.length < 2) {
                return reduce!fun(seed, r);
            } else {
                return reduce!fun(tuple(seed), r);
            }
        }
    }
}

// minElement/maxElement was added in D 2.072.0
static if (__VERSION__ < 2072) {
    auto minElement(alias map, Range)(Range r)
    if (isInputRange!Range && !isInfinite!Range)
    {
        alias mapFun = unaryFun!map;
        auto element = r.front;
        auto minimum = mapFun(element);
        r.popFront;
        foreach(a; r) {
            auto b = mapFun(a);
            if (b < minimum) {
                element = a;
                minimum = b;
            }
        }
        return element;
    }
    auto maxElement(alias map, Range)(Range r)
    if (isInputRange!Range && !isInfinite!Range)
    {
        alias mapFun = unaryFun!map;
        auto element = r.front;
        auto maximum = mapFun(element);
        r.popFront;
        foreach(a; r) {
            auto b = mapFun(a);
            if (b > maximum) {
                element = a;
                maximum = b;
            }
        }
        return element;
    }
}


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

long long memo[500][500][50];
long long N, MA, MB;
long long a[100];
long long b[100];
long long c[100];

int main(){
	cin >> N >> MA >> MB;
	for(long long i = 0; i < N; i++){
		cin >> a[i] >> b[i] >> c[i];
	}
	for(long long i = 0; i < 500; i++){
		for(long long j = 0; j < 500; j++){
			for(long long k = 0; k < 50; k++){
				memo[i][j][k] = INT_MAX;
			}
		}
	}

	memo[0][0][0] = 0;
	for(long long k = 0; k < N; k++){
		long long av = a[k];
		long long bv = b[k];
		long long cv = c[k];
		for(long long i = 0; i < 400; i++){
			for(long long j = 0; j < 400; j++){
				//使う
				if(memo[i][j][k] < INT_MAX)
					memo[i+av][j+bv][k+1] = min(memo[i+av][j+bv][k+1], memo[i][j][k] + cv);

				//使わない
				memo[i][j][k+1] = min(memo[i][j][k+1], memo[i][j][k]);

			}
		}
	}

	long long ans = INT_MAX;
	for(long long i = 1; i < 500; i++){
		for(long long j = 1; j < 500; j++){
			if(i%MA == 0 && j%MB == 0 && i/MA == j/MB)
				ans = min(ans, memo[i][j][N]);
		}
	}
	if(ans == INT_MAX){
		ans = -1;
	}
	cout << ans << endl;
}


Measured memory_bytes: 97920
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int L = 6;

int H[6][6] = {
    {1,5,2,3,0,4}, // 0 : North : ?\\????§????   ( y:-1 )
    {3,1,0,5,4,2}, // 1 : East  : ???????§????   ( x:+1 )
    {2,1,5,0,4,3}, // 2 : West  : ???????§????   ( x:-1 )
    {4,0,2,3,5,1}, // 3 : South : ??????????§???? ( y:+1 )
    {0,2,4,1,3,5}, // 4 : Right : ?????????????????¢ (?§??????????)
    {0,3,1,4,2,5}  // 5 : Left  : ?????????????????¢ (?§??????????)
};
 
// d[0] := top,   d[1] := front 
// d[2] := right, d[3] := left
// d[4] := back,  d[5] := bottom
enum{TOP, FRONT, RIGHT, LEFT, BACK, BOTTOM};
struct Cube{
    vector<string> d;
    Cube(vector<string> v) { d = v; }
    Cube(){ d = vector<string>(6); }
    void roll(int dir){
        vector<string> nd(6);
        for(int i = 0 ; i < 6 ; i++ ) nd[i] = d[ H[dir][i] ];
        d = nd;
    }
};

bool preCompareCube(Cube &a, Cube b){
  if(a.d == b.d) return true;
  b.roll(4);
  if(a.d == b.d) return true;
  b.roll(4);
  if(a.d == b.d) return true;
  b.roll(4);
  if(a.d == b.d) return true;
  b.roll(4);
  return false;
}

bool compareCube(Cube &a, Cube b){
  if(preCompareCube(a, b)) return true;
  b.roll(0);
  if(preCompareCube(a, b)) return true;
  b.roll(0);
  if(preCompareCube(a, b)) return true;
  b.roll(0);
  if(preCompareCube(a, b)) return true;
  b.roll(0);

  b.roll(1);
  if(preCompareCube(a, b)) return true;
  b.roll(1);
  if(preCompareCube(a, b)) return true;
  b.roll(1);
  if(preCompareCube(a, b)) return true;
  return false;
}

int main() {
  int N;
  while(cin >>N && N){
    Cube c; REP(i, L) cin >>c.d[i];
    vector<Cube> res;
    res.push_back(c);
    FOR(n, 1, N){
      bool f = true;
      REP(i, L) cin >>c.d[i];
      REP(i, res.size()) if(compareCube(res[i], c)) f = false;
      if(f) res.push_back(c);
    }
    cout <<N - res.size() <<endl;
  }
  return 0;
}

Measured memory_bytes: 1236
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#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 <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stdio.h>


using namespace std;

int main(void) {
    string S,T;
    cin>>S>>T;

    bool ans=false;
    for(int i=0;i<S.size();i++){
        if(S==T){
            ans=true;
            break;
        }
        S=S.back()+S.substr(0,S.size()-1);
    }

    if(ans){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    

}




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

#define pb push_back
#define fr(i, n) for(int i = 0; i < n; i++)
#define frr(i, n) for(int i = 1; i <= n; i++)

#define dbg(x) cout << #x << " = " << x << endl
#define all(x) x.begin(),x.end()
#define ms(x, i) memset(x, i, sizeof(x))

#define p(x) cout << x << "\n"
#define pv(x) fr(i, x.size()) cout << x[i] << " \n"[i==x.size()-1]

#define f first
#define s second

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f;

int main() {
    fastio;

    string s;
    cin >> s;

    int l = 0, r = s.size()-1;
    while (s[l] != 'A') l++;
    while (s[r] != 'Z') r--;

    p((r-l+1));
}


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

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

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

int main() {
    int n;
    int id = 0;
    while(cin >> n && n) {
        int a[15][15];
        memset(a,0,sizeof(a));

        bool up = true;
        int b = 0, c = 0,v = 1;

        rep(i,n) {
            if(i % 2 == 0) {
                b = i;
                c = 0;

                a[b][c] = v;
                v++;

                while(!(b == 0 && c == i)) {
                    b--;
                    c++;

                    a[b][c] = v;
                    v++;
                }
            } else {
                b = 0;
                c = i;

                a[b][c] = v;
                v++;

                while(!(b == i && c == 0)) {
                    b++;
                    c--;

                    a[b][c] = v;
                    v++;
                }
            }
        }

        rep(i,n-1) {
            if(i % 2 == !(n%2)) {
                b = i + 1;
                c = n - 1;
        
                a[b][c] = v;
                v++;

                while(!(b == n - 1 && c ==  i + 1)) {
                    b++;
                    c--;
        
                    a[b][c] = v;
                    v++;
                }
            } else {
                b = n - 1;
                c = i + 1;
        
                a[b][c] = v;
                v++;

                while(!(b == i + 1 && c == n - 1)) {
                    b--;
                    c++;
        
                    a[b][c] = v;
                    v++;
                }
            }
        }

        cout << "Case " << id+1 << ":" << endl;
        id++;
        rep(i,n) {
            rep(j,n) {
                cout.width(3);
                cout << a[i][j];
            }
            cout << endl;
        }
    }

    return 0;
}

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

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



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

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

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int h,w,n;cin>>h>>w>>n;
  int a[n],hoge[h][w],cnt=0;
  rep(i,n)cin>>a[i];
  rep(i,h){
    rep(j,w){
      if(a[cnt]==0)++cnt;
      --a[cnt];

      //奇数
      if(i%2==0){
        hoge[i][j]=cnt+1;
      //偶数
      }else{
        hoge[i][w-j-1]=cnt+1;
      }
    }
  }
  rep(i,h){
    rep(j,w){
      j!=w-1?cout<<hoge[i][j]<<" ":cout<<hoge[i][j];
    }
    cout<<endl;
  }
}

Measured memory_bytes: 3716
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

const int MAXN = 300 + 10;
int N, M;
int A[MAXN][MAXN], B[MAXN];
int cnt[MAXN]; bool u[MAXN];

int main() {
	register int i, j;
	scanf("%d%d", &N, &M);
	for(i = 1; i <= N; ++i)
		for(j = 1; j <= M; ++j)
			scanf("%d", A[i] + j);
	int ans = N; u[0] = 1;
	for(i = 1; i <= M; ++i) {
		for(j = 1; j <= M; ++j) cnt[j] = 0;
		for(j = 1; j <= N; ++j) {
			for(; u[A[j][B[j]]]; ++B[j]);
			++cnt[A[j][B[j]]];
		}
		int k = 0;
		for(j = 1; j <= M; ++j)
			k = cnt[j] > cnt[k] ? j : k;
		ans = cnt[k] < ans ? cnt[k] : ans;
		u[k] = 1;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 512