akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main()
{
    int i,flag=0;
    char s[4];
    scanf("%s",s);
    for(i=0;i<4;i++)
    {
        if(s[i]==s[i+1])
        {
            flag = 1;
        }
    }
    if(flag==0)
    {
        printf("Good\n");
    }
    else
    {
        printf("Bad\n");
    }
}


Measured memory_bytes: 128
import sys
input = sys.stdin.readline


# 解説AC
def main():
    N = int(input())
    ans = 0
    x = 0
    for i in range(N):
        a = int(input())
        if a == 0:
            ans += x//2
            x = 0
        else:
            x += a
    ans += x//2
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp> 
//using namespace __gnu_pbds; 
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
typedef long long ll;
typedef long double ld;
#define trace(x)  cerr << #x << ": " << x << endl;
#define rep(i,a)  for(ll i=0; i< a; i++)
#define pb push_back
#define vl vector<ll>
const int N = 1e7+5;
const int MOD = 1e9+7;
int main()
{
	fast;
	ll n;cin>>n;
	vector<ll> a(n);for(ll i=0;i<n;i++)cin>>a[i];
	//sort(a.begin(),a.end());
	ll ans=0;
	for(ll i=0;i<n-2;i++)
	{
		for(ll j=i+1;j<n-1;j++)
		{
			for(ll k=j+1;k<n;k++)
			{
				if((a[i]+a[j] > a[k]) && (a[j]+a[k]>a[i]) && (a[k]+a[i]>a[j]) && a[i]!=a[j] && a[i]!=a[k] && a[j]!=a[k])ans++;
			}
		}
	}
	cout<<ans;
}

Measured memory_bytes: 3660
#include "bits/stdc++.h"
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2152&lang=jp
using namespace std;
typedef pair<int,int> pii;
#define MAX 1000000000

priority_queue<pii, vector<pii>, greater<pii>> emp_secta;
map<int, vector<pii>> sectas;
void Write(int l,int S) {
	while (S) {
		auto q = emp_secta.top(); emp_secta.pop();
		int lx = q.first, rx = q.second;
		if (rx - lx + 1 == S ) {
			sectas[l].push_back(pii(lx, rx));
			S = 0;
		}
		else if(rx - lx + 1 > S) {
			sectas[l].push_back(pii(lx, lx + S - 1));
			emp_secta.push(pii(lx + S, rx));
			S = 0;
		}
		else {
			sectas[l].push_back(pii(lx, rx));
			S -= (rx - lx + 1);
		}
	}
}

void Delete(int l) {
	for (auto e : sectas[l]) {
		emp_secta.push(pii(e.first, e.second));
	}
	sectas[l].clear();
}

void Refer(int P) {
	for (auto it = sectas.begin(); it != sectas.end(); it++) {
		int val = it->first;
		vector<pii> sec = it->second;
		for (int i = 0; i < sec.size();i++) {
			if (sec[i].first <= P && P <= sec[i].second) {
				cout << val << endl;
				return;
			}
		}
	}
	cout << -1 << endl;
}

int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
	int N;
	while (cin >> N, N) {
		sectas.clear();
		priority_queue<pii, vector<pii>, greater<pii>> temp;
		swap(emp_secta, temp);
		emp_secta.push(pii(0,MAX));

		for (int i = 0; i < N;i++) {
			char command; cin >> command;
			if (command == 'W') {
				int l, S; cin >> l >> S;
				Write(l, S);
			}
			if (command == 'D') {
				int l; cin >> l;
				Delete(l);
			}
			if (command == 'R') {
				int P; cin >> P;
				Refer(P);
			}
		}
		cout << endl;
	}
	return 0;
}

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

int main() {
	int N;
	string S;
	cin >> N >> S;
	int cnt = 0;
	for (int i = 0; i + 2 < N; i++) {
		if (S.substr(i, 3) == "ABC") cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

//dp[i] = i円を引き出すのに必要な最小回数
int dp[111111];

//小さい方を返す
int get_min(int a,int b){
	if(a < b)return a;
	else return b;
}

int main(){
	
	int n,i,tmp;
	
	scanf("%d",&n);
	
	//初期化、とりあえず小さい数で埋める
	for(i = 0;i < 111111;i++){
		dp[i] = 1000000000;
	}
	//0円は0回で引き出せる
	dp[0] = 0;
	
	for(i = 0;i < 111111;i++){
		//i円をdp[i]回で引き出せるならi+tmp円はdp[i]+1回で引き出せるので、最小になり得るかを見る
		tmp = 1;
		while(i + tmp < 111111){
			dp[i+tmp] = get_min(dp[i+tmp],dp[i]+1);
			tmp *= 6;
		}
		tmp = 9;
		while(i + tmp < 111111){
			dp[i+tmp] = get_min(dp[i+tmp],dp[i]+1);
			tmp *= 9;
		}
	}
	
	printf("%d\n",dp[n]);
	
	return 0;
}

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

int x_sum(int c){
    int ans = 0;
    while(c > 0){
        ans += (c % 10);
        c /= 10;
    }

    return ans;

}

int main(){
int  n,a,b;
cin >> n >> a >> b;
int sum = 0;
int count = 0;
for (int i = 0; i < n; i++)
{   
    sum = x_sum(i+1);
    

    if(a <= sum && b >= sum){
        count += i + 1;
    }
}





printf("%d\n", count);
   
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define tezina first
#define vrednost second

using namespace std;

int n, kapacitet;
pair<int,ll> predmeti[110];
ll dp[100010][110];

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

    cin>>n>>kapacitet;
    for(int i=1;i<=n;i++)
    {
        int t; ll v;
        cin>>t>>v;
        predmeti[i]=make_pair(t,v);
    }
    sort(predmeti,predmeti+n+1);

    for(int i=1;i<=kapacitet;i++)
    {
        for(int j=1;j<=n;j++)
            dp[i][j]=max(dp[i][j-1], predmeti[j].tezina<=i?dp[i-predmeti[j].tezina][j-1]+predmeti[j].vrednost:0);
    }

    cout<<dp[kapacitet][n];


	return 0;
}


Measured memory_bytes: 86272
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
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 int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

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

    ll A, B, C, X, Y;;
    cin >> A >> B >> C >> X >> Y;
    if(X > Y){
        swap(X, Y);
        swap(A, B);
    }
    /*
    //X <= Y
    ll ans = (Y - X) * B + min(A + B, 2 * C) * X;
    ll ans2 = Y*2*C;
    cout << min(ans, ans2) << endl;
    */
   auto solve = [&](int t) -> ll{
       ll res = 0;
       res += 2*t*C;
       res += max(0LL, X-t)*A+max(0LL, Y-t)*B;
       return res;
   };
   ll ans = INFLL;
   for(int i = 0; i <= Y;i++){
       chmin(ans, solve(i));
   }
   cout << ans << endl;
}

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

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();

    let h: usize = itr.next().unwrap().parse().unwrap();
    let w: usize = itr.next().unwrap().parse().unwrap();
    let mut g: Vec<Vec<usize>> = (0..h)
        .map(|_| {
            (0..w)
                .map(|_| itr.next().unwrap().parse().unwrap())
                .collect()
        })
        .collect();

    let mut cnt = 0;
    let mut out = Vec::new();
    for i in 0..h {
        if h % 2 == 0 {
            for j in 0..w - 1 {
                if g[i][j] % 2 == 1 {
                    cnt += 1;
                    writeln!(out, "{} {} {} {}", i + 1, j + 1, i + 1, j + 2).ok();
                    g[i][j + 1] += 1;
                }
            }
            if i != h - 1 && g[i][w - 1] % 2 == 1 {
                cnt += 1;
                writeln!(out, "{} {} {} {}", i + 1, w, i + 2, w).ok();
                g[i + 1][w - 1] += 1;
            }
        } else {
            for j in (1..w).rev() {
                if g[i][j] % 2 == 1 {
                    cnt += 1;
                    writeln!(out, "{} {} {} {}", i + 1, j + 1, i + 1, j).ok();
                    g[i][j - 1] += 1;
                }
            }
            if i != h - 1 && g[i][0] % 2 == 1 {
                cnt += 1;
                writeln!(out, "{} {} {} {}", i + 1, 1, i + 2, 1).ok();
                g[i + 1][0] += 1;
            }
        }
    }
    println!("{}", cnt);
    stdout().write_all(&out).unwrap();
}


Measured memory_bytes: 6720
#include<stdio.h>
#include <algorithm>
using namespace std;
int main()
{
    int a1,a2,a3,b1,b2,b3,flag=0,m[5][5];
   for(int i=1;i<=3;i++)
    for(int j=1;j<=3;j++)
    scanf("%d",&m[i][j]);
 
for(int a1=0;a1<100;a1++)
{
     int b1=m[1][1]-a1;
        int a2=m[2][1]-b1;
        int a3=m[3][1]-b1;
        int b2=m[1][2]-a1;
        int b3=m[1][3]-a1;
        if(a2+b2==m[2][2] 
            && a2+b3==m[2][3]
            && a3+b2==m[3][2] 
            && a3+b3==m[3][3])
        {
            flag = 1;
            break;
        }
}
if(flag)
printf("Yes");
else
printf("No");
    return 0;
}

Measured memory_bytes: 128
//
// Created by Knight_F on 2019-08-18.
//

//
// Created by Knight_F on 2019-08-18.
//

#include <iostream>
#include <cstring>
using namespace std;
int main() {
    int n; cin>>n;
    double s=0;
    for(int i=1;i<=n;i++){
        int ai; scanf("%d",&ai);
        double a=ai;
        a=1.0/a;
        s+=a;
    }
    s=1.0/s;
    printf("%.5f",s);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <numeric>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>


using namespace std;
using ll = long long;
const ll INF = 1e18;

int main() {
    int N, ans = 0;
    cin >> N;
    map<ll, bool> v;

    for (int i = 0; i < N; i++) {
        ll a;
        cin >> a;

        if (v.find(a) != v.end()) {
            if (v[a] == true) {
                v[a] = false;
                ans--;
            } else {
                v[a] = true;
                ans++;
            }
        } else {
            v[a] = true;
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const double PI = acos(-1);  

int k, cnt=0;
vector<ll> obj;

void dfs(int depth, ll value){
  obj.push_back(value);
  if(depth==10) return;
  if(cnt==k) return;
  for(int i=-1; i<=1; i++){
    int nv = value%10+i;
    if(0<=nv && nv<=9) dfs(depth+1, value*10+nv);
  }
}

int main(){
  cin >> k;
  for(int i=1; i<10; i++)  dfs(0, i);
  sort(obj.begin(), obj.end());
  cout << obj[k-1] << endl;
  
}


Measured memory_bytes: 10604
#include <bits/stdc++.h>
#define int long long
using pii=std::pair<int,int>;
using namespace std;

const int maxn = 2e5 + 5;

int n, q, qtype, x, st[2][4 * maxn]; // st[row / col][node];
bool marked[2][4 * maxn]; 

void build(int v, int tl, int tr, int type) {
    if (tl == tr) {
        st[type][v] = n;
    } else {
        int tm = (tl + tr) / 2;
        build(v*2, tl, tm, type);
        build(v*2+1, tm+1, tr, type);
        st[type][v] = 0;
    }
}

void push(int v, int type) {
    if (marked[type][v]) {
        st[type][v*2] = st[type][v*2+1] = st[type][v];
        marked[type][v*2] = marked[type][v*2+1] = true;
        marked[type][v] = false;
    }
}

void update(int v, int tl, int tr, int l, int r, int new_val, int type) {
    if (l > r) 
        return;
    if (l == tl && tr == r) {
        st[type][v] = new_val;
        marked[type][v] = true;
    } else {
        push(v, type);
        int tm = (tl + tr) / 2;
        update(v*2, tl, tm, l, min(r, tm), new_val, type);
        update(v*2+1, tm+1, tr, max(l, tm+1), r, new_val, type);
    }
}

int get(int v, int tl, int tr, int pos, int type) {
    if (tl == tr) {
        return st[type][v];
    }
    push(v, type);
    int tm = (tl + tr) / 2;
    if (pos <= tm) 
        return get(v*2, tl, tm, pos, type);
    else
        return get(v*2+1, tm+1, tr, pos, type);
}


int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> q;
    build(1, 1, n, 0);
    build(1, 1, n, 1);
    int ans = (n - 2) * (n - 2);
    for(int i = 0; i < q; i++)
    {
        cin >> qtype >> x;
        qtype--;
        int end = get(1, 1, n, x, qtype) - 1;
        ans -= max(end - 1, 0ll);
        int lo = 1, hi = end + 1, mid;
        while(lo < hi)
        {
            mid = (lo + hi) / 2;
            if(get(1, 1, n, mid, qtype ^ 1) < x)
                lo = mid + 1;
            else
                hi = mid;
        }
        assert(lo == hi);
        if(lo < end)
            update(1, 1, n, lo, end, x, qtype ^ 1);
        update(1, 1, n, x, x, 1, qtype);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 12868
# n,mを取得
n,m = map(int, input().split())

# 配列a,bを初期化
a = [[] for i in range (0,n)]
b = [[0]*1 for i in range (0,m)]

for i1 in range(n):
    a[i1] = list(map(int, input().split()))

for i2 in range(m):
    b[i2] = int(input())

# 戻り値の各要素を個々に計算し、戻り値tmpの要素に加える
for i4 in range(n):
    tmp = 0
    for i5 in range(m):
        tmp += a[i4][i5]*b[i5]
    print(tmp)





Measured memory_bytes: 6028
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }

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

  ll h, w;
  cin >> h >> w;
  vector<vector<ll>> a(h, vector<ll>(w, 0));
  rep(i, 0, h) rep(j, 0, w) cin >> a[i][j];

  vector<pll> be, af;
  for(ll i = 0; i < h; i++){
    if(i % 2 == 1){
      for(ll j = w-1; j >= 0; j--){
        if(i == h-1 && j == 0) break;
        if(j != 0){
          if(a[i][j] % 2 == 1){
            a[i][j]--, a[i][j-1]++;
            be.pb(pll(i+1, j+1)), af.pb(pll(i+1, j));
          }
        }else{
          if(a[i][j] % 2 == 1){
            a[i][j]--, a[i+1][j]++;
            be.pb(pll(i+1, j+1)), af.pb(pll(i+2, j+1));
          }
        }
      }
    }else{
      for(ll j = 0; j < w; j++){
        if(i == h-1 && j == w-1) break;
        if(j != w-1){
          if(a[i][j] % 2 == 1){
            a[i][j]--, a[i][j+1]++;
            be.pb(pll(i+1, j+1)), af.pb(pll(i+1, j+2));
          }
        }else{
          if(a[i][j] % 2 == 1){
            a[i][j]--, a[i+1][j]++;
            be.pb(pll(i+1, j+1)), af.pb(pll(i+2, j+1));
          }
        }
      }
    }
  }

  cout << sz(be) << endl;
  for(ll i = 0; i < sz(be); i++){
    cout << be[i].first << ' ' << be[i].second << ' ' << af[i].first << ' ' << af[i].second << endl;
  }
  return 0;
}

Measured memory_bytes: 8120
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);
  
using namespace std;
 
const ll inf = 1e17;
const ll N = 90;
const ll bits = 63;
const ll mod = 1e9+7;

ll dp[N][N][N*N],a[N][N];

int main(){

    ll n,m,x,y;
    cin>>n>>m;


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

    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>y;
            a[i][j]-=y;
            a[i][j] = abs(a[i][j]);
        }
    }

    dp[1][1][a[1][1]] = 1;

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

            for(int k=0;k<=6400;k++){

                if(dp[i][j-1][k]){
                    if(k+a[i][j]<=6400){
                        dp[i][j][k+a[i][j]] = true;
                    }

                    if(abs(k-a[i][j])<=6400){
                        dp[i][j][abs(k-a[i][j])] = true;
                    }
                }

                if(dp[i-1][j][k]){
                    if(k+a[i][j]<=6400){
                        dp[i][j][k+a[i][j]] = true;
                    }

                    if(abs(k-a[i][j])<=6400){
                        dp[i][j][abs(k-a[i][j])] = true;
                    }
                }
            }
            
        }
    }

    // for(int i=1;i<=n;i++){
    //     for(int j=1;j<=m;j++){
    //         cout<<i<<" "<<j<<": ";

    //         for(auto x:dp[i][j]){
    //             cout<<x<<" ";
    //         }

    //         cout<<"\n";
    //     }
    // }

    ll ans = inf;
    for(int i=0;i<=6400;i++){
        if(dp[n][m][i]){
            cout<<i<<"\n";
            return 0;
        }
    }
    cout<<ans<<"\n";



}


Measured memory_bytes: 459008
"""
Nの制約数の少なさてきに、全探索するのがよさそう。
とはいえ、ありうるすべてのグラフパターンを全探索したら、2**(N^2)かかる

N本目以降は、辺の数を増やせば増やすほど、有効なペアの数が減っていく。
逆にいうと、ペアの数を減らしたい場合は、N本目以降を追加する
"""
N,K = map(int,input().split())
if K > N*(N-1)//2-(N-1):
    print(-1)
    exit()
edges = []
base = 1
for i in range(base+1,N+1):
    edges.append(" ".join([str(base),str(i)]))

diff = (N-1)*(N-2)//2 - K
base = 2
while diff:
    for i in range(base+1,N+1):
        if diff == 0:
            break
        else:
            edges.append(" ".join([str(base),str(i)]))
            diff -= 1
    base += 1
print(len(edges))
for ans in edges:
    print(ans)



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

int main()
{
  char b;
  cin >> b;
  
  if (b == 'A') cout << 'T' << endl;
  else if (b == 'T') cout << 'A' << endl;
  else if (b == 'C') cout << 'G' << endl;
  else if (b == 'G') cout << 'C' << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;cin>>n;
    string s;cin>> s;
    // zaatu
    int ans = 0;
    char now_char = '0';
    rep(i,n)
    {
        if (now_char != s[i])
        {
            now_char = s[i];
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(snip_i, n) cin >> a.at(snip_i);
	int ans = 0;
	rep2(i, 1, n){
		if(a.at(i-1) == a.at(i)){
			ans++;
			a.at(i) = -1;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  
  int N;
  cin >> N;
  int A[20];
  int x[20][20];
  int y[20][20];
  for(int i = 0; i < N; i++) {
    cin >> A[i];
    for(int j = 0; j < A[i]; j++)
      cin >> x[i][j] >> y[i][j];
  }
  
  int ans = 0;
  for(int bits = 0; bits < (1 << N); bits++) {
    bool ok = true;
    for(int i = 0; i < N; i++) {
      if(!(bits & (1 << i))) continue; 
      for(int j = 0; j < A[i]; j++)
        if(((bits >> (x[i][j]-1)) & 1) ^ y[i][j]) ok = false;
    }
    if(ok) {
      int ret = 0;
      for(int k = 0; k < N; k++)
        if(bits & (1 << k)) ret++;
      ans = max(ans, ret);
    }
  }
  cout << ans << "\n";
}


Measured memory_bytes: 256
A = input()
if A == 'SAT':
  print(1)
elif A == 'SUN':
  print(7)
elif A == 'MON':
  print(6)
elif A == 'TUE':
  print(5)
elif A == 'WED':
  print(4)
elif A == 'THU':
  print(3)
elif A == 'FRI':
  print(2)


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>

namespace ABC171
{
  class C
  {
  public:
    C() = default;
    ~C() = default;


    void Run()
    {
      long long N;
      std::cin >> N;

      constexpr int KIND_ALPHA = 26;
   
      std::string str = {};

      int count = 1;
      long long m = KIND_ALPHA;
      long long accum = KIND_ALPHA;
      while (accum < N) {
        count++;
        m *= KIND_ALPHA;
        accum += m;
      }

      long long val = N - 1;
      for (int i = 0; i < count; ++i)
      {
        char buf[2] = { static_cast<char>('a' + (val % KIND_ALPHA)), '\0' };
        str += buf;
        val = (val / KIND_ALPHA) - 1;
      }
      std::reverse(str.begin(), str.end());

      std::cout << str << std::endl;
    }
  };
}

int main()
{

  ABC171::C prob;
  prob.Run();

  return 0;
}

Measured memory_bytes: 3128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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

	int a, b, c;
	cin >> a >> b >> c;

	if(b - a == c - b){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>

int main(){
	int n;
	std::cin >> n;
	std::vector<int> v(n);
	long long sum = 0;
	for(int i = 0; i < n; i++){
		std::cin >> v[i];
		sum += v[i];
	}

	long long ans = 1e18;
	long long x = 0;
	long long y;
	for(int i = 0; i < n - 1; i++){
		x += v[i];
		y = sum - x;
		ans = std::min(ans, std::abs(x - y));
	}
	std::cout << ans << std::endl;
}

Measured memory_bytes: 1024
import sys


def main():
    n, m, x, y = map(int, input().split())
    xs = list(map(int, input().split()))
    ys = list(map(int, input().split()))

    x = max(x, max(xs))
    y = min(y, min(ys))

    print('No War' if x < y else 'War')


main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> road(N);
  rep(i, M)
  {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    road[a]++;
    road[b]++;
  }

  rep(i, N)
  {
    cout << road[i] << endl;
  }
  return 0;
}

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

int main() {
int n,d;
cin >> n >> d;
int a = d* 2 + 1;
if(n%a == 0) cout << n/a << endl;
else cout << n/a + 1 << endl;
}
  


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        h: usize, w:usize,
        mat: [[i32; w]; h], // n x m行列
    };

    let mut ans:Vec<(usize,usize,usize,usize)> = Vec::new();
    for i in 0..h {
        for j in 0..w {
            if mat[i][j] % 2 != 0 {
                if j<w-1 {
                    mat[i][j] -= 1;
                    mat[i][j+1] += 1;
                    ans.push((i,j,i,j+1));
                } else
                if i<h-1 {
                    mat[i][j] -=1;
                    mat[i+1][j] +=1;
                    ans.push((i,j,i+1,j));
                }
            }
        } 
    }
    println!("{}", ans.len());
    for (a,b,c,d) in ans {
        println!("{} {} {} {}", a+1,b+1,c+1,d+1);
    }
}


Measured memory_bytes: 12788
N, K = map(int, input().split())
MOD = 10**9+7
C = [[0]*(N+1) for _ in range(N+1)]
C[0][0] = 1

for i in range(1, N+1):
    C[i][0] = 1
    C[i][i] = 1
    
    for j in range(1, i):
        C[i][j] = (C[i-1][j-1]+C[i-1][j])%MOD

for i in range(1, K+1):
    print(C[N-K+1][i]*C[K-1][K-i]%MOD)

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

typedef long long ll;
typedef pair<ll ,ll> pll;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

const ll MOD = 1000000007;
const ll INF = 1e18;//1*10^18

ll powll(ll a,ll n){//O(log n)
  ll res=1;
  while(n>0)
  {
    if(n & 1)//(n & 1)=(n % 2 !=0)
    {
      res=res*a;
    }
    a=a*a;
    n>>=1;//(n & 1)=(n % 2 !=0)
  }
  return res;
}

ll modpow(ll a,ll n,ll mod)//O(log n)
{
  ll res=1;
  while(n>0)
  {
    if(n & 1)//(n & 1)=(n % 2 !=0)
    {
      res=res*a%mod;
    }
    a=a*a%mod;
    n>>=1;//(n>>=1)=(n/2)
  }
  return res;
}

int ReturnDigit(ll num)
{
  string number=to_string(num);
  return number.length();
}

// const ll MAX=INF;
// 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;
// }

ll ReturnYakusuu(ll num)
{
    ll n=0;
    if(num==1)
    {
        return 1;
    }

    for(ll i=2; i<=num; i++)
    {
        if(i%2==0)
        {
            continue;
        }
        
        if(num%i==0)
        {
            do{
                num/=i;
                n++;
            } while(num%i==0);
            return (n+1)*ReturnYakusuu(num);
        }
    }
}

int main() {
// srand((unsigned int)time(NULL));//--> rand()
  ll i,j,k,l;
  ll n,ans=0;
  
  cin >>n; 
  for(i=1; i<=n; i++)
  {
      if(ReturnYakusuu(i)==8)
      {
          ans+=1;
      }
  }

  cout<< ans <<endl;
}

Measured memory_bytes: 256
/*
  ∧,,∧
( 'ω' )つ ＜WA,またお前か！！　
（m9 ＼ 　　
　 ＼　 ＼
　 　 ) ) ＼
　 ／／ ＼ ＼
　 (＿） 　 (＿)
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

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

    vector<int> count(('Z'-'A'), 0);

    for (int i = 0; i < 4; i++)
        count[S[i]-'A']++;

    int flag = 0;
    for (int i = 0; i <= count.size(); i++) {
        if (count[i] == 2 || count[i] == 0) {
            ;
        } else {
            flag = 1;
        }
    }

    if (flag) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    // 
    // for (int i = 0; i <= count.size(); i++)
    //     cout << (char)(i + 'A') << " " << count[i] << endl;
    //

    return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <cmath>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <stdio.h>
#include <queue>
//#include "windows.h"
	
#define pb push_back
#define ppb pop_back
#define mmp make_pair
#define nd second
#define st first
#define ll long long
#define pii pair <int, int>
#define tri pair <pii, int>
#define irt pair <int, pii>
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++)
#define FOR(i, a, n) for (int (i) = (a); (i) < (int)(n); i++)
#define FORN(i, a, n) for (int (i) = (a); (i) > (int)(n); i--)
#define pi 3.1415926535897932384626433832795028841971
//#define LOCAL

using namespace std; 

int main()
{
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	
	int a[3]; 
	int ans; 
	
	cin >> a[0] >> a[1] >> a[2]; 
	sort(a, a + 3); 
	ans = a[2] - a[0]; 
	
	cout << ans << endl; 
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

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

Measured memory_bytes: 580
#include<stdio.h>

int main(){
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if( a < b ){
        if( b < c ){
            printf("Yes\n");
        } else {
        printf("No\n");
        }
    } else {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 2044
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

/**
 * Shopping
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		StringTokenizer st = new StringTokenizer(br.readLine());

		int m, f, b;
		m = parseInt(st.nextToken());
		f = parseInt(st.nextToken());
		b = parseInt(st.nextToken());

		if (m >= b) {
			System.out.println(0);
		} else if (m + f >= b) {
			System.out.println(b - m);
		} else {
			System.out.println("NA");
		}
	}
}

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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n+1);
    for(int i=0;i<a.size();i++)
    {
        cin >> a[i];
    }

    map<int, int> ma;
    vector<int> sum(n+1);
    sum[0] = 0;
    for(int i=0; i<n; i++)
    {
        sum[i+1] = (sum[i] + a[i]) % m;
    }

    long long ans = 0;
    for(int i=0; i<sum.size(); i++)
    {
        ans += ma[sum[i]];
        ma[sum[i]]++;
    }
    cout << ans << endl;
}


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

typedef unsigned long long ull;

int march[5];

int main() {
  string s;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    switch (s[0]) {
    case 'M':
      march[0]++;
      break;
    case 'A':
      march[1]++;
      break;
    case 'R':
      march[2]++;
      break;
    case 'C':
      march[3]++;
      break;
    case 'H':
      march[4]++;
      break;
    }
  }
  ull ans = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = i+1; j < 4; j++) {
      for (int k = j+1; k < 5; k++) {
	// cout << i << " " << j << " " << k << endl;
	ull combinations = march[i] * march[j] * march[k];
	// cout << combinations << endl;
	ans += combinations;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
using ll = long long;
int main(void){
    ll n;
    ll NUM[200001]={};
    cin >> n;
    vector<ll> a(n);
    for(ll i=0;i<n;i++){
        cin >> a[i];
        NUM[a[i]]++;
    }
    ll ans = 0;
    for(ll i=1;i<=n;i++){
        if(NUM[i]>=2)
            ans += NUM[i]*(NUM[i]-1)/2;
    }
    for(ll i=0;i<n;i++){
        if(NUM[a[i]]>=2)
            cout << ans - (NUM[a[i]]*(NUM[a[i]]-1)/2-(NUM[a[i]]-1)*(NUM[a[i]]-2)/2) << endl;
        else 
            cout << ans << endl;
    }
    return 0;
} 

Measured memory_bytes: 5760
import sys

if sys.platform in ['ios','win32','darwin']:
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	H, W = MAP()
	M = [input().rstrip() for _ in range(H)]

	DU = tuple([-1,1])
	LR = tuple([-1,1])
	memo = [[-1]*W for _ in range(H)]
	ans = 0
	for i in range(H):
		for j in range(W):
			if M[i][j] == '#': continue
			tmp = [0,0]
			
			skip = -1
			if memo[i-1][j] != -1:
				tmp[0] = memo[i-1][j][0]
				skip = 1
			if memo[i][j-1] != -1:
				tmp[1] = memo[i][j-1][1]
				skip = 5 if skip == 1 else 2
			
			if skip == 1 or skip == -1:
				lr = 0
				for move in LR:
					nw = j
					dw = move
					while True:
						nw += dw
						# print(i, j, nh, nw)
						if nw>W-1 or nw<0 or M[i][nw] == '#': break
						lr += 1
					tmp[1] = lr

			if skip == 2 or skip == -1:
				du = 0
				for move in DU:
					nh = i
					dh = move
					while True:
						nh += dh
						# print(i, j, nh, nw)
						if nh>H-1 or nh<0 or M[nh][j] == '#': break
						du += 1
					tmp[0] = du
			
			memo[i][j] = tuple(tmp)
			ans = max(ans, sum(tmp)+1)
		
	# for mem in memo:
	# 	print(mem)
	# for m in M:
	# 	print(m)
	print(ans)

if __name__ == "__main__":
	main()

Measured memory_bytes: 396400
n=int(input())
[A,B,C]=[input() for i in range(3)]
num = 0
for i in range(n):
    if A[i] == B[i]:
        if A[i] == C[i]:
            num += 0
        else:
            num += 1
    elif B[i] == C[i]:
        num += 1
    elif A[i] == C[i]:
        num += 1
    else:
        num += 2
print(num)



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

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

    ll a,b,c;cin>>a>>b>>c;
    ll r=c-a-b;
    if(r<0){
        cout<<"No"<<endl;
        return 0;
    }
    if(4*a*b<r*r){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


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

int k;

ll Ceil(ll x, ll y) {
    return (x / y) + !!(x%y);
}

int main() {
    scanf("%d", &k);
    vector<ll> a(k);
    rep(i, k) scanf("%lld", &a[i]);
    if (a[k - 1] != 2) {
        puts("-1"); return 0;
    }
    reverse(a.begin(), a.end());

    ll L = 2, R = 2;
    rep(i, k) {
        L = Ceil(L, a[i]) * a[i];
        R = R / a[i] * a[i] + a[i] - 1;
        if (L > R) break;
    }
    if (L > R) {
        puts("-1"); return 0;
    }
    printf("%lld %lld\n", L, R);
    return 0;
}

Measured memory_bytes: 1024
def main
  answers = []
  loop do
    n = gets.chomp.to_i
    break if n == 0
    src_str = gets.chomp
    dest_str = src_str

    n.times do
      dest_str = conversion(dest_str)
    end

    answers << dest_str
  end

  answers.each {|answer|puts answer}
end

def conversion src_str
  str_ary = get_same_char_string_ary(src_str)
  make_str(str_ary)
end

def get_same_char_string_ary src_str
  scan_result = []
  base_str = src_str
  loop do
    scan_str = get_same_char_string(base_str)
    break if scan_str.empty?
    base_str = base_str[scan_str.length..-1]
    scan_result << scan_str
  end
  scan_result
end

def get_same_char_string src_str
  first_char = src_str[0]
  same_char_string = ''
  src_str.each_char do |c|
    break if c != first_char
    same_char_string << c
  end
  same_char_string
end

def make_str str_ary
  dest_str = ''
  str_ary.each do |str|
    dest_str << str.length.to_s
    dest_str << str.chr
  end
  dest_str
end

main

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

using namespace std;
typedef long long int lli;

const int MAXN = 60;

int n, A, B;

int last[MAXN];

lli ans;

lli v[MAXN];
lli sv[MAXN];
lli ways[MAXN];
lli dp[MAXN][MAXN];

lli solve(int i, int j)
{
	lli& ans = dp[i][j];

	if( ans != -1 ) return ans;

	if( j == 0 ) return ans = 1;
	if( i == 0 ) return ans = 0;

	return ans = solve( i - 1 , j ) + solve( i - 1 , j - 1 );
}

int main()
{
	scanf("%d %d %d",&n,&A,&B);

	memset( dp , -1 , sizeof(dp) );

	for(int i = 1 ; i <= n ; i++)
		scanf("%lld",&v[i]);

	sort( v + 1 , v + n + 1 );

	for(int i = 1 ; i <= n ; i++)
	{
		if( v[i] != v[i - 1] ) last[i] = i;
		else last[i] = last[i - 1];
	}

	int first;

	for(int i = n ; i > 0 ; i--)
	{
		if( v[i] != v[i + 1] ) first = i;

		sv[i] = sv[i + 1] + v[i];
		ways[i] = solve( first - last[i] + 1 , first - i + 1 );
	}

	lli s = sv[n - A + 1];
	lli sz = A;

	lli ans = ways[n - A + 1];

	for(int i = A + 1 ; i <= B ; i++)
	{
		lli curS = sv[n - i + 1];

		if( s*i < sz*curS ) ans = ways[n - i + 1];
		if( s*i == sz*curS ) ans += ways[n - i + 1];
	}	

	double aux = s;
	aux /= sz;

	printf("%.10f\n",aux);
	printf("%lld\n",ans);
}

Measured memory_bytes: 256
import java.util.*;
    public class Main{
	public static void main(String[] args){
	    Scanner scan = new Scanner(System.in);
	    String numM = scan.next();
	    int origin = Integer.parseInt(numM);
	    int startNum = 0;
		
	    for(int i =0;i<numM.length();i++){
		startNum= startNum+Integer.parseInt(String.valueOf(numM.charAt(i)));
	
	    }
	    if(origin%startNum==0){
		System.out.println("Yes");
	    }else{
		System.out.println("No");
	    }
	}
    }


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define gcd __gcd
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
#define pr(n) printf("%d ",n)
#define out(n) printf("%d\n",n)
#define inl(a) cin >> a
#define prl(a) cout << a << " "
#define outl(a) cout << a << endl
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define ck printf("continue\n")
#define all(vec) vec.begin(),vec.end()
#define asc(vec) sort(vec.begin(),vec.end())
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<int,pair<int,int> > >
#define vvii vector<vector<pair<int,int> > >
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define N 100005
typedef long long int ll;
vvi ad(N);
int edge[N],vis[N];
void dfs(int s)
{
    int i,x,a;
    x=ad[s].size();
    vis[s]=1;
    rep(i,x)
    {
        a=ad[s][i];
        if(!vis[a])
            dfs(a);
        if(vis[a])
            edge[s]=max(edge[s],1+edge[a]);
    }
    return ;
}
int main()
{
    int n,m,i,a,b;
    in2(n,m);
    while(m--)
    {
        in2(a,b);
        ad[a].pb(b);
    }
    lp(i,1,n+1)
        if(!vis[i])dfs(i);
    m=0;
    lp(i,1,n+1)
        m=max(m,edge[i]);
    out(m);



}


Measured memory_bytes: 8576
#include<iostream>
#include <string.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  if(s == "SUN")cout<<7;
   else if(s == "MON")cout<<6;
   else if(s == "TUE")cout<<5;
   else if(s == "WED")cout<<4;
   else if(s == "THU")cout<<3;
   else if(s == "FRI")cout<<2;
   else if(s == "SAT")cout<<1;
  return 0;
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.NoSuchElementException;
public class Main {
	public static void main(String[] args)throws Exception{
		PrintWriter out = new PrintWriter(System.out);
		int N=nextInt();
		int M=nextInt();
		long K=nextInt();
		long A[]=new long[N];
		long B[]=new long[M];
		long sum=0,ans=0,now=N;
		int x=0;
		for(int i=0;i<N;i++){
			A[i]=nextInt();
			sum+=A[i];
		}
		for(int i=0;i<M;i++){
			B[i]=nextInt();
		}
		for(int i=0;i<N;i++){
			while(x<M){
				sum+=B[x];x++;
				if(sum>K){
					x--;
					sum-=B[x];
					break;
				}
			}
			if(now+x>ans&&sum<=K)
				ans=now+x;
			sum-=A[N-1-i];now--;
		}
		while(x<M){
			sum+=B[x];x++;
			if(sum>K){
				x--;
				sum-=B[x];
				break;
			}
		}
		if(now+x>ans&&sum<=K)
			ans=now+x;
		System.out.println(ans);
		out.flush();
	}
	static boolean isOK(int index,int key,ArrayList<Integer>a){
		if (a.get(index) >= key) return true;
	    else return false;
	}
	static int binary_search(int key,ArrayList<Integer> a) {
	    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	    int ok = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	    while (Math.abs(ok - ng) > 1) {
	        int mid = (ok + ng) / 2;

	        if (isOK(mid,key,a)) ok = mid;
	        else ng = mid;
	    }
	    return ok;
	}
	//FastScanner
	static InputStream in = System.in;
	static  byte[] buffer = new byte[1024];
	static int length = 0, p = 0;
	public static boolean hasNextByte () {
		if (p < length) return true;
		else {
			p = 0;
			try {length = in.read(buffer);}
			catch (Exception e) {e.printStackTrace();}
			if (length == 0) return false;
		}
		return true;
	}
	public static int readByte () {
		if (hasNextByte() == true) return buffer[p++];
		return -1;
	}
	public static boolean isPrintable (int n) {return 33<=n&&n<=126;}
	public static void skip () {
		while (hasNextByte() && !isPrintable(buffer[p])) p++;
	}
	public static boolean hasNext () {skip(); return hasNextByte();}
	public static String next () {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int temp = readByte();
		while (isPrintable(temp)) {
			sb.appendCodePoint(temp);
			temp = readByte();
		}
		return sb.toString();
	}
	public static int nextInt () {return Math.toIntExact(nextLong());}
	public static int[] nextInts (int n) {
		int[] ar = new int[n];
		for (int i=0; i<n; i++) ar[i] = nextInt();
		return ar;
	}
	public static long nextLong () {
		if (!hasNext()) throw new NoSuchElementException();
		boolean minus = false;
		int temp = readByte();
		if (temp == '-') {
			minus = true;
			temp = readByte();
		}
		if (temp<'0' || '9'<temp) throw new NumberFormatException();
		long n = 0;
		while (isPrintable(temp)) {
			if ('0'<=temp && temp<='9') {
				n *= 10;
				n += temp - '0';
			}
			temp = readByte();
		}
		return minus? -n : n;
	}
}


Measured memory_bytes: 40840
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>
#include <cstdio>
#include <iomanip>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define queint queue<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>//大きい順
#define pqg priority_queue<int,vec,greater<int>>//小さい順
#define pb push_back
#define vec vector<int>
#define vecvec vector<vector<int>>
#define vecll vector<ll>
#define vecvecll vector<vector<ll>>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
#define mp make_pair
using namespace std;
int in(){int x;scanf("%d",&x);return x;}



struct edge {
    int from; //出発点
    int to;   //到達点
    ll cost; //移動コスト
};


int main(){
    int V = in(); //頂点の数
    int side = in(); //辺の数
    int p = in();
    int S = 0; //始点
    int G = V-1; //終点
    vecll d(V,1000000000000); //始点からそこまで行くのにかかるコスト
    vector<edge> edges; //移動の情報を保存する

    d[S] = 0; //始点を0にする
    
    for (int i = 0; i < side; i++) {
        struct edge add;
        int a=in();
        add.from = a-1;
        a=in();
        add.to = a-1;
        int x = in();
        add.cost = p-x;
        edges.push_back(add);
    }
    vector<bool> negative(V,false);
    for (int i = 0; i < V; i++) {
        REP(e,edges){
            if(d[e.from]==1000000000000)continue;
            if (d[e.to] > d[e.from] + e.cost) {  //移動した後のコストが小さいと、頂点のコストを更新
                d[e.to] = d[e.from] + e.cost;
            }
        }
    }
    for (int i = 0; i < V; i++) {
        REP(e,edges){
            if(d[e.from]==1000000000000)continue;
            if (d[e.to] > d[e.from] + e.cost) {  //移動した後のコストが小さいと、頂点のコストを更新
                d[e.to] = d[e.from] + e.cost;
                negative[e.to]=true;
            }
            if(negative[e.from]){
                negative[e.to]=true;
            }
        }
    }
    if(negative[V-1])cout<<-1<<endl;
    else if(d[G]<0)cout<<-d[G]<<endl;
    else cout<<0<<endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

int a[100000];
int main() {
	int n; scanf("%d", &n);
	int g = 0, k = 0;
	rep(i, n) {
		scanf("%d", &a[i]);
		if (a[i] & 1)k++;
		else g++;
	}
	if (k % 2 == 1)puts("NO");
	else puts("YES");
}

Measured memory_bytes: 640
from sys import stdin

N = int(stdin.readline())
A = list(map(int,stdin.readline().split()))
A.sort()
Q = int(stdin.readline())
D = dict()
S = set(A)
sum=0
count=0

for y in range(0,N):
    sum+=A[y]
    if y>0 and A[y]!=A[y-1]:
        D[A[y-1]]=count
        count=1
    elif y==0:
        count=1
    else:
        count+=1
    if y==N-1:
        D[A[y]]=count

for u in range(0,Q):
    U= list(map(int,stdin.readline().split()))
    if U[0] in D:
        sum+=(D[U[0]])*(U[1]-U[0])
        if U[1] in D:
            D[U[1]]+=D[U[0]]
        else:
            D[U[1]]=D[U[0]]
        D[U[0]]=0


    print(sum)

Measured memory_bytes: 21676
N,x,*as=$<.read.split.map(&:to_i)
# N,x,*as = [5,2,1,2,3,4,5]

i = 1
ret = 0
while i < N
    sum = as[i-1] + as[i]
    # p [as, sum]
    if x < sum
        d = sum-x
        if d <= as[i]
            as[i] -= d
        else
            as[i] = 0
        end
        ret += d
    end
    i += 1
end

puts ret

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

H, W = MAP()
A = [LIST() for i in range(H)]

xy = []
xxyy = []
route = []
sum_A = 0

for i in range(H):
    if i % 2 == 0:
        for j in range(W):
            route.append([i, j])
    else:
        for j in range(W-1, -1, -1):
            route.append([i, j])
    sum_A += A[i][j]
# print(route)
ans = []
for i in range(len(route)-1):
    y, x = route[i]
    y_next, x_next = route[i+1]
    if A[y][x] % 2 == 1:
        A[y][x] -= 1
        A[y_next][x_next] += 1
        ans.append([y+1, x+1, y_next+1, x_next+1])
print(len(ans))
for a in ans:
    print(*a)






Measured memory_bytes: 61816