akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()

typedef tree<pair<ll,ll> ,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest
//cout << k << "kth smallest: " << *A.find_by_order(k-1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

const int MAXN = 3005;

ll n, a[MAXN], dp[MAXN][MAXN][2];        // Value of X - Y for a(st to en) when player pl is to move

ll rec(ll st, ll en, ll pl)
{
	if(st > en) return 0;
	if(dp[st][en][pl] != -1) return dp[st][en][pl];
	if(pl == 0)
		return dp[st][en][pl] = max(a[st] + rec(st + 1, en, pl ^ 1), a[en] + rec(st, en - 1, pl ^ 1));
	else
		return dp[st][en][pl] = min(rec(st + 1, en, pl ^ 1) - a[st], rec(st, en - 1, pl ^ 1) - a[en]);
}

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

	cin >> n;
	for(int i=0;i<n;i++) cin >> a[i];
	memset(dp, -1, sizeof(dp));
	cout << rec(0, n-1, 0) << endl;
    return 0;
}

Measured memory_bytes: 141568
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 100000;

int h, w;
int dp[2][2][100][100];

main(){
  while(cin >> w >> h && (h || w)){
    fill(dp[0][0][0], dp[2][0][0], 0);
    dp[1][0][0][1] = dp[1][1][1][0] = 1;
    for(int i=0;i<h;++i){
      for(int j=0;j<w;++j){
	if(i+1<h){
	  dp[1][1][i+1][j] += dp[1][1][i][j];
	  dp[1][1][i+1][j] %= N;
	}
	if(j+1<w){
	  dp[0][0][i][j+1] += dp[1][1][i][j];
	  dp[0][0][i][j+1] %= N;
	}
	if(j+1<w){
	  dp[1][0][i][j+1] += dp[1][0][i][j];		
	  dp[1][0][i][j+1] %= N;
	}
	if(i+1<h){
	  dp[0][1][i+1][j] += dp[1][0][i][j];
	  dp[0][1][i+1][j] %= N;
	}
	if(j+1<w){
	  dp[1][0][i][j+1] += dp[0][0][i][j];
	  dp[1][0][i][j+1] %= N;
	}
	if(i+1<h){
	  dp[1][1][i+1][j] += dp[0][1][i][j];
	  dp[1][1][i+1][j] %= N;
	}
      }
    }
    int ans = 0;
    for(int i=0;i<2;i++){
      for(int j=0;j<2;j++){
	ans += dp[i][j][h-1][w-1];
	ans %= N;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
def dfs(v, p, a):
    global ans
    if pre[v] != -1:
        low[a] = min(low[a], low[v])
        return low[a]
    pre[v] = p
    low[v] = p
    for u in links[v]:
        if u == a:
            continue
        low[v] = min(low[v], dfs(u, p + 1, v))
    if pre[v] == low[v]:
        ans += 1
    return low[v]
  
n, m = map(int, input().split())
links = [set() for _ in range(n)]
 
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    links[a].add(b)
    links[b].add(a)
 
ans = 0
pre = [-1] * n
low = [-1] * n
dfs(0, 0, None)
print(ans - 1)
'''
まず、頂点を１つ選び、DFSを開始する。
各頂点には、pre、lowという２つのデータを記録する。
preは、DFS木の行きがけ順（pre-order）の値を保持する。
lowは、DFS木でその頂点から到達しうる頂点のpreの最小値を保持する。
初期値はその頂点のpreである。
次の頂点が、すでに訪れてある（preの値が存在する）場合は、
自分のlowを、次の頂点のlowと比べて小さい方に更新する。
次の頂点をまだ訪れていない場合は、その頂点に対してDFSを続ける。
そして、その頂点へのDFSが終了した際に、lowがpreより小さくなっていれば、
その頂点へ向かう辺は橋である。
'''

Measured memory_bytes: 3064
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <sstream>
#include <string>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define EPS 1e-14
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) FOR(i, 0, n)
#define PI 2*acos(0.0)
#define ALL(a) (a).begin(),(a).end()
#define DEBUG(x) cout<<#x <<": "<< x << "\n"
#define DEBUG_ARR(a) REP(i, size(a)){ cout << #a << "[" << i << "]: " << a[i] << "\n"; }
const int VX[] = { 0, 1, 0, -1 };
const int VY[] = { 1, 0, -1, 0 };
const long MOD = 1000000007;

int main() {
	//	--- I/O 高速化 ---
	cin.tie(0);
	ios::sync_with_stdio(false);
	// --- ここまで ---

	int A, B;
	cin >> A >> B;

	if (A + B >= 24) {
		cout << A + B - 24 << endl;
	}
	else {
		cout << A + B << endl;
	}

	return 0;
}



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

int main() {
  string s;
  cin >> s;
  s = "0" + s;
  int x = 0;
  for (int i = s.length() - 1; i > -1; --i) {
    int t = s[i] - '0';
    int r = i == 0 ? 10 : s[i - 1] - '0';
    if (t == 10) {
      if (i) s[i - 1]++;
      t = 0;
    }
    if (t > 5 || (t == 5 && r >= 5)) {
      if (i) s[i - 1]++;
      x += 10 - t;
    } else {
      x += t;
    }
  }
  cout << x << endl;
}

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

#define ll       long long
#define ull      unsigned ll
#define pii      pair<int, int>
#define pll      pair<ll, ll>
#define mp       make_pair
#define ff       first
#define ss       second
#define sz(x)    (int) x.size()
#define all(v)   v.begin(), v.end()

template <typename T> inline void smin(T &a, T b) {a = a < b ? a : b;}
template <typename T> inline void smax(T &a, T b) {a = a > b ? a : b;}

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << ", ";
    err(++it, args...);
}

template <typename T> inline void Int(T &n) {
    n = 0; int f = 1; register int ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
    n = n * f;
}

template <typename T, typename TT> inline void Int(T &n, TT &m) { Int(n); Int(m); }
template <typename T, typename TT, typename TTT> inline void Int(T &n, TT &m, TTT &l) { Int(n, m); Int(l); }

const int mod = (int) 1e9 + 7;

inline int add(int a, int b) {a += b; return a >= mod ? a - mod : a;}
inline int sub(int a, int b) {a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b) {return (ll) a * b % mod;}

const int inf = (int) 2e9 + 5;
const ll  Inf = (ll) 2e18 + 5;
const int N   = (int) 2e5 + 5;

const double pi = acos(-1.0);

std::vector<int> g[N];
int sz[N];

void dfs(int u, int p = -1) {
	sz[u] = 1;
	for(int v : g[u]) {
		if(p != v) {
			dfs(v, u);
			sz[u] += sz[v];
		}
	}
}

int solve() {
   int x; cin >> x;
   double ans = 2.0 * pi * x;
   printf("%.10f\n", ans);
    return 0;
}

int main() {
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int test = 1, tc = 0;
    //Int(test);
    //cin >> test;
    while (test--) {
        //printf("Case %d: ", ++tc);
        solve();
    }
    return 0;
}


Measured memory_bytes: 8412
#include<iostream>
#include <algorithm>
#include <set>
using namespace std;

int main(){
    int N;
    set<int> st;
    int d[110];
    cin >> N;
    for(int i=0; i<N; i++){
        cin >>d[i];
    }
    for(int i = 0; i < N; i++){
        st.insert(d[i]);
    }
    cout << st.size() << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
if(N%2==1):
  ans = A[0]
  for i in range(1, (N-1)//2):
    ans += A[i] * 2
  ans += A[N//2]
  print(ans)
else:
  ans = A[0]
  for i in range(1, (N+1)//2):
    ans += A[i] * 2
  print(ans)

Measured memory_bytes: 93984
#include<iostream>
#include<cstdio>
#include<cstring>
#include <fstream>
#include<string>
#include<sstream>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
#include <math.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long long int MOD = 1000000007;
const int INF = 1000000007;
const double EPS = 1e-10;
const double PI = 3.14159265359;
const int N = 100005;
//cout << fixed << std::setprecision(9)
//--------------------------

ll dp[N][2];
vector<int> edge[N];
int n, u, v;

void dfs(int x, int last)
{
	dp[x][0] = dp[x][1] = 1;
	for (auto to : edge[x]) {
		if (to == last) continue;
		dfs(to, x);
		dp[x][0] = dp[x][0] * ((dp[to][0] + dp[to][1]) % MOD) % MOD;
		dp[x][1] = dp[x][1] * dp[to][0] % MOD;
	}
}

int main()
{
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		cin >> u >> v;
		edge[u].push_back(v);
		edge[v].push_back(u);
	}

	dfs(1, -1);
	cout << (dp[1][0] + dp[1][1]) % MOD << endl;

	return 0;
}


Measured memory_bytes: 17532
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>

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

ll gcd(ll a, ll b) {
	if (b == 0)return a;

	return gcd(b, a%b);
}
int main() {
	int k;
	cin >> k;
	int g[300][300][300] = { 0 };

	int h = 0;
	for (int a = 1; a <= k;a++) {
		for(int b = 1; b <= k; b++) {
			h = gcd(a, b);
			for (int c = 1; c <= k; c++) {
				g[a][b][c] = gcd(h, c);
			}
		}
	}
	int sum = 0;
	for (int a = 1; a <= k; a++) {
		for (int b = 1; b <= k; b++) {
			for (int c = 1; c <= k; c++) {
				sum += g[a][b][c];
			}
		}
	}
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 109104
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define mod 998244353
#define inf 10000000000000007
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
#define ll long long
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int r, g, b, n;
int ans;

signed main() {
	cin >> r >> g >> b >> n;
	for (int i = 0; i <= n/g; i++) {
		for (int j = 0; j <= n / b; j++) {
			if (i*g+j*b<=n&&(n - i * g - j * b) % r == 0)ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi(a) scanf("%d",&a);
#define fli(a) scanf("%ld",&a);
#define fll(a) scanf("%lld",&a);
#define pi(a) printf("%d\n",a);
#define ppi(i,a) printf("Case %d: %d\n",i,a);
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
void FI()
{
#ifndef ONLINE_JUDGE
    freopen("C:\\Users\\SHIHAB\\Desktop\\input.in","r",stdin);
#endif // ONLINE_JUDGE
}

int main()
{
    fast
    FI();
    string s1,s2;
    cin >> s1;
    cin >> s2;
    s2.erase(s2.size()-1);
    if(s1==s2) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}



Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;


int dp[300][300];
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h,w;
    cin>>h>>w;
    string s[h];
    rep(i,h)cin>>s[i];
    int ret=0;
    if(s[0][0]!='.')++ret;
    if(s[h-1][w-1]!='.')++ret;
    rep(i,h)rep(j,w)dp[i][j]=inf;
    dp[0][0]=0;
    rep(i,h)rep(j,w){
        if(i+1<h ){
            dp[i+1][j]=min(dp[i+1][j],dp[i][j]+(s[i+1][j]!=s[i][j]));
        }
        if(j+1<w ){
            dp[i][j+1]=min(dp[i][j+1],dp[i][j]+(s[i][j+1]!=s[i][j]));
        }
    }
    ret += dp[h-1][w-1];
    cout<<ret/2<<endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
double a[3005],dp[3005][3005];
int main(){
	int n;
	while(~scanf("%d",&n)){
		for(int i=1;i<=n;i++) scanf("%lf",&a[i]);
		for(int i=1;i<=n;i++) for(int j=0;j<=n;j++) dp[i][j]=0;
		dp[1][0]=1-a[1];
		dp[1][1]=a[1];
		for(int i=2;i<=n;i++) for(int j=0;j<=n;j++){
			if(j==0){
				dp[i][j]=dp[i-1][0]*(1-a[i]);
			}else{
				dp[i][j]=dp[i-1][j-1]*a[i]+dp[i-1][j]*(1-a[i]);
			}
		}
		double ans=0;
		for(int i=n/2+1;i<=n;i++) ans+=dp[n][i];
		printf("%.10lf\n",ans);
	}
}


Measured memory_bytes: 70656
n = int(input())
xy = [tuple(map(int, input().split())) for _ in range(n)]
s = set([(x + y) % 2 for x, y in xy])
if len(s) > 1:
    print(-1)
    exit(0)

d = []
w = ["" for _ in xy]
if s.pop() == 0:
    d = [1]
    w = ["L" for _ in xy]
    xy = [(x + 1, y) for x, y in xy]

b = 1
while True:
    if all(abs(x) + abs(y) == 1 for x, y in xy):
        d.append(b)
        for i in range(len(xy)):
            x, y = xy[i]
            if x > 0:
                w[i] += 'R'
            elif x < 0:
                w[i] += 'L'
            elif y > 0:
                w[i] += 'U'
            else:
                w[i] += 'D'
        break
    d.append(b)
    for i in range(len(xy)):
        x, y = xy[i]
        if x % 2 == 1:
            if y % 4 == 2 and (x - 1) % 4 == 0 or y % 4 == 0 and (x - 1) % 4 == 2:
                w[i] += 'R'
                xy[i] = ((x - 1) // 2, y // 2)
            else:
                w[i] += 'L'
                xy[i] = ((x + 1) // 2, y // 2)
        else:
            if x % 4 == 2 and (y - 1) % 4 == 0 or x % 4 == 0 and (y - 1) % 4 == 2:
                w[i] += 'U'
                xy[i] = (x // 2, (y - 1) // 2)
            else:
                w[i] += 'D'
                xy[i] = (x // 2, (y + 1) // 2)
    b *= 2

print(len(d))
print(*d)
for t in w:
    print(t)



Measured memory_bytes: 45552
#include <cstdio>

using namespace std;

double l[10],v1, v2;

int main()
{
    loop:
    while ( scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf\n", &l[0], &l[1], &l[2], &l[3], &l[4], &l[5], &l[6], &l[7], &l[8], &l[9], &v1, &v2 ) != EOF )
    {
        v2 += v1;
        for( int i = 0; i < 10; i++ )
        {
            l[i] += ( ( i == 0 ) ? 0 : l[i - 1] );
        }
        double t = l[9] / v2;
        double dis = v1 * t;
        for( int i = 0; i < 10; i++ )
        {
            if( dis == l[i] )
            {
                printf( "%d\n", i + 1 );
                goto loop;
            }
            else if( dis < l[i] )
            {
                printf( "%d\n", i + 1 );
                goto loop;
            }
        }
        /* for( int i = 0; i < 10; i++ )
        {
            if( l[i] <= dis && dis <= l[i + 1] )
            {
                printf( "%d\n", i + 2 );
                return 0;
            }
        } */
    }
    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin >> n;
  if(n==3){
    cout << 2 << " " << 5 << " " << 63 << endl;
    return 0;
  }
  if(n==4){
    cout << 2 << " " << 5 << " " << 20 << " " << 63 << endl;
    return 0;
  }
  if(n==5){
    cout << 2 << " " << 5 << " " << 20 << " " << 50 << " " << 63 << endl;
    return 0;
  }
  vector<int> a(n);
  int cnt=0;
  int sum=0;
  for(int i=1;i<=30000;i++){
    if(i%2==0||i%3==0){
      a[cnt]=i;
      cnt++;
      sum+=i;
    }
    if(cnt==n){
      break;
    }
  }
  if(sum%6==2){
    a[4]=30000;
  }
  if(sum%6==3){
    a[5]=30000;
  }
  if(sum%6==5){
    a[5]=29998;
  }
  for(int i=0;i<n;i++){
    cout << a[i] << " ";
  }
  cout << endl;
}

Measured memory_bytes: 384
//Jai Sai Ram 
// Please help me in every situation 
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl "\n"
ll P=1e9+7;
vector<ll> adj[100001];
ll a[100001],b[100001];
ll find(ll x)
{
    if(a[x]==x)
    {
        return x;
    }
    return a[x]=find(a[x]);
}
ll unions(ll x,ll y)
{
    ll xp=find(x);
    ll yp=find(y);
    if(xp==yp)
    {
        return 0;
    }
    if(b[xp]>b[yp])
    {
        a[yp]=xp;
    }
    else 
    {
        a[xp]=yp;
        if(b[xp]==b[yp])
        b[yp]++;
    }
    return 1;
}
void solve()
{
    ll i,j,k,l,m,n,o,p,q,r,t,s;
    cin>>n>>m;
    for(i=1;i<=n;i++)
    {
        a[i]=i;
        b[i]=0;
    }
    for(i=0;i<m;i++)
    {
          cin>>j>>k;
          unions(j,k);
    }
    set<ll> se;
    for(i=1;i<=n;i++)
    se.insert(find(i));
    cout<<se.size()-1<<endl;
}
int main()
{
    ll t=1;
    ios_base::sync_with_stdio(false);
    cin.tie(0);

   //cin>>t;
   ll i=1;
    while(t--)
    {
      
        solve();
        i++;
    }
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    map<string,ll> mp;
    rep(i,n){
        string s;
        cin >> s;
        sort(s.begin(),s.end());
        mp[s]++;
    }
    ll total = 0;
    for(pair<string,ll> p : mp){
        total += p.second * (p.second-1) / 2;
        // cout << p.first  << " : " << p.second << endl;
    }
    cout << total << endl;

    return 0;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN=2010;
ll f[MAXN],a[MAXN],x;
int n;
int main()
{
	scanf("%d",&n);
	scanf("%lld",&x);
	for (int i=1;i<=n;i++) {
		scanf("%lld",&a[i]);
	}
	ll sum=1000000000000000000;
	for (int i=1;i<=n;i++) f[i]=a[i];
	for (int i=0;i<n;i++)
	{
		ll ans=(long long)i*x;
		for (int j=1;j<=n;j++)
		{
			f[j]=min(f[j],a[(i+j-1)%n+1]);
			ans+=f[j];
		}
		sum=min(sum,ans);
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main{
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int[] n = new int[5];
		int prt=0;
		for(int i=0;i<5;i++){
			n[i]=sc.nextInt();
		}
		int mai=0;
		for(int i=1;i<5;i++){
			if(n[i]%10!=0){
				if(n[mai]%10==0)mai=i;
				if(10-n[i]%10>10-n[mai]%10)mai=i;
			}
		}
		for(int i=0;i<5;i++){
			if(i!=mai)prt+=n[i]%10==0?n[i]:n[i]-n[i]%10+10;
		}
		prt+=n[mai];
		System.out.print(prt);
	}
}

Measured memory_bytes: 35756
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;


public class Main {

    public static void main(String[] args) {
    
    	FastScanner scan = new FastScanner();
    	
    	int k = scan.nextInt(); String str = scan.next();
    	if(str.length() <= k) System.out.println(str);
    	else {
    		char [] ch = str.toCharArray();
    		str = "";
    		for(int i=0; i<k; i++) str += ch[i];
    		System.out.println(str + "...");
    	}
    	
    }

   
    static class FastScanner{
    	
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	StringTokenizer st = new StringTokenizer("");
    	String next() {
    		while(!st.hasMoreTokens())
    			try {
    				st = new StringTokenizer(br.readLine());
    			} catch (IOException e){
    				e.printStackTrace();
    			}
    		return st.nextToken();
    	}
    	
    	int nextInt() {
    		return Integer.parseInt(next());
    	}
    	
    	int [] readArray(int n) {
    		int [] a = new int[n];
    		for(int i=0; i<n ; i++) a[i] = nextInt();
    		return a;
    	}
    	
    	long nextLong() {
    		return Long.parseLong(next());
    	}
    	
    	
    }
    
   
}



Measured memory_bytes: 37504
def solve(N,K,A):
    for i in range(K):
        arr = [0] * (N + 1)

        for ind,j in enumerate(A):
            arr[max(ind-j,0)] += 1
            arr[min(ind+j+1, N)] -= 1

        A[0] = arr[0]
        for k in range(N-1):
            A[k+1] = A[k] + arr[k+1]

        if arr[0] ==N and arr[-1] == -N:
            return A
    return A


if __name__ == "__main__":
    n,k = map(int, input().split())
    a = list(map(int, input().split()))
    ans = solve(n,k,a)
    print(*ans)

Measured memory_bytes: 140944
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    Stack<String> stack = new Stack<String>();
    String s;
    
    while (in.hasNext()) {
      s = in.next();
      if (s.equals("+")) {
        int x = Integer.parseInt(stack.pop());
        int y = Integer.parseInt(stack.pop());
        stack.push(Integer.toString(y + x));
      }
      else if (s.equals("-")) {
        int x = Integer.parseInt(stack.pop());
        int y = Integer.parseInt(stack.pop());
        stack.push(Integer.toString(y - x));
      }
      else if (s.equals("*")) {
        int x = Integer.parseInt(stack.pop());
        int y = Integer.parseInt(stack.pop());
        stack.push(Integer.toString(y * x));
      }
      else {
        int num = Integer.parseInt(s);
        stack.push(Integer.toString(num));
      }
    }
    System.out.println(stack.pop());
  }
}

class Stack<Item> {
  private Node first = null;
  
  private class Node {
    Item item;
    Node next;
  }
  
  public boolean isEmpty() { return first == null; }
  
  public void push(Item item) {
    Node oldfirst = first;
    first = new Node();
    first.item = item;
    first.next = oldfirst;
  }
  
  public Item pop() {
    Item item = first.item;
    first = first.next;
    return item;
  }
}

Measured memory_bytes: 19024
# coding: utf-8
while True:
    n, x = map(int, input().split())
    comb = 0
    
    if n == 0 and x == 0:
        exit()

    for i in range(1, n+1):
        for j in range(i+1, n+1):
            for k in range(j+1, n+1):
                # print('{} {} {}'.format(i, j, k))
                if i + j + k == x:
                    comb += 1
    print(comb)



Measured memory_bytes: 5600
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)


def main():
    N, K = map(int, input().split())
    S = [0 for _ in range(N)]
    for i in range(K):
        d = int(input())
        A = list(map(int, input().split()))
        for a in A:
            S[a - 1] += 1
    ans = 0
    for s in S:
        if s == 0:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9196
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "PP.hpp"
#define deb(x...) cerr << "[" << #x << "] = " << x << "\n";
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long lint;
typedef vector<lint> vlint;
typedef vector<vlint> vvlint;
typedef pair<lint, lint> plint;
typedef double ld;

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

int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a, b;
	cin >> a >> b;
	cout << (a <= b? a: a - 1) << '\n';
	return 0;
}



Measured memory_bytes: 256
main :: IO ()
main = do
  let
    f :: Int -> Int -> Int
    f k m = (2 * k) `min` (m - 1)
  [n, k] <- map read . words <$> getLine :: IO [Int]
  ds <- getLine :: IO String
  let
    (m, s) = foldl step (1, 0) . (zipWith (==) <$> id <*> tail) $ ds :: (Int, Int)
      where
        step :: (Int, Int) -> Bool -> (Int, Int)
        step (m, s) b | b         = (m, s + 1)
                      | otherwise = (m + 1, s)
  print $ s + f k m


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

int main()
{
	int h,w,k;
	cin>>h>>w>>k;
	char c[h][w];
	for(int i = 0; i < h; i++)
	{
		for(int j = 0; j < w; j++)
		{
			cin>>c[i][j];
		}
	}
	int ans = 0;
	for(int m = 0; m < 1<<h; m++)
		for(int t = 0; t < 1<<w; t++)
		{
			int cnt = 0;
			for(int i = 0; i < h; i++)
			{
				for(int j = 0; j < w; j++)
				{
					if(c[i][j] == '#' && !(m & 1<<i) && !(t & 1<<j))
					{
						cnt++;
					}
				}
			}
			if(cnt == k) ans++;
		}
	cout<< ans<<endl;
}


Measured memory_bytes: 3560
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;

const int maxn = 5005;
const int maxm = 1E4 + 10;
typedef long long LL;
const LL mo = 1000000007;

int n,k,x,tail,Ans = 1,s[maxn],f[maxn][maxm];

inline int Mul(const LL &x,const LL &y) {return x * y % mo;}
inline int Add(const int &x,const int &y) {return x + y < mo ? x + y : x + y - mo;}
inline int Dec(const int &x,const int &y) {return x - y >= 0 ? x - y : x - y + mo;}

int main()
{
	#ifdef DMC
		freopen("DMC.txt","r",stdin);
	#endif
	
	f[0][1] = 1; cin >> n >> k >> x;
	for (int i = 0; i < k; i++) scanf("%d",&s[i]);
	for (int i = 1; i < k; i++) tail = max(tail,s[i] - s[i - 1]);
	for (int i = 1; i <= 2 * x; i++)
	{
		int sum = 0,Max = i + (i & 1);
		for (int j = 1; j <= tail; j++)
		{
			sum = Add(sum,f[i - 1][j - 1]);
			if (j - Max - 1 >= 0) sum = Dec(sum,f[i - 1][j - Max - 1]);
			f[i][j] = sum; if (i + 1 >= j) f[i][j] = Add(f[i][j],1);
		}
	}
	for (int i = 1; i < k; i++) Ans = Mul(Ans,f[2 * x - 2 * i + 1][s[i] - s[i - 1]]);
	cout << Ans << endl;
	return 0;
}

Measured memory_bytes: 195712
# -*- coding: utf-8 -*-
#ABC121C
import sys
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
n=hoge[0]
m=hoge[1]

a=[]
for i in range(0,n):
	tmp = input().split()
	hoge = list(map(lambda a: int(a), tmp))
	a.append((hoge[0],hoge[1]))
a.sort()

#print(m)
total=0
for i in range (0,n):
	if(a[i][1]<=m):
		total+=a[i][0]*a[i][1]
		m-=a[i][1]
	else:
		total+=m*a[i][0]
		m=0
	if(m==0):
		break


#print("---")
#print(m)
print(total)
#print(a)



Measured memory_bytes: 16984
{-# LANGUAGE
    BangPatterns, MultiWayIf, TupleSections, TypeApplications #-}
{-# OPTIONS_GHC -O2 #-}


import Control.Arrow
import Control.Concurrent
import Control.Monad
import qualified Data.ByteString.Builder as B
import qualified Data.ByteString.Char8 as C
import Data.Complex
import Data.Char
import Data.Function
import Data.Function.HT
import qualified Data.IntMap.Strict as IM
import qualified Data.IntSet as IS
import Data.List
import Data.Monoid
import Data.Ord
import qualified Data.Sequence as Sq
import Data.Vector.Algorithms.Search
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import Debug.Trace
import System.IO


------------------
-- #   Read   # --
------------------

r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine



main :: IO ()
main = do
    s <- getLine
    print $ case s of   "SSS" -> 0
                        "RRS" -> 2
                        "SRR" -> 2
                        "RRR" -> 3
                        _     -> 1


Measured memory_bytes: 3688
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>

using namespace std;

int main()
{
   int n,num,cnt=0;
   cin>>n;
   for(int i=1;i<=n;i++){
    cin>>num;
    if(num%2!=0&&i%2!=0)cnt++;
   }
   cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main()
{
    int N;
    cin >> N;
    vll A(N);
    map<int, int> C;
    rep(i, N)
    {
        cin >> A[i];
        C[A[i]]++;
    }
    if (C.size() % 2)
    {
        cout << C.size();
    }
    else
    {
        cout << C.size() - 1;
    }

    return 0;
}

Measured memory_bytes: 5760
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int i;
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int q = sc.nextInt();
			List<Queue<Integer>> array = new ArrayList<>();
			for(i = 0; i < n; i++) {
				array.add(new PriorityQueue<Integer>(4 ,Comparator.reverseOrder()));
			}
			for(i = 0; i < q; i++) {
				int order_number = sc.nextInt();
				int t = sc.nextInt();
				//命令1と2は配列が空なら処理しない
				if(array.get(t).isEmpty() && order_number != 0) {
					continue;
				}
				switch(order_number) {
				case 0 :
					array.get(t).add(sc.nextInt());
					break;
				case 1 :
					System.out.println(array.get(t).peek());
					break;
				case 2 :
					array.get(t).remove();
					break;
				}
			}
		}
	}
}


Measured memory_bytes: 169680
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
#include<set>

using namespace std;

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

int main(){
	while(1){
		int n,m;
		
		cin>>n>>m;
		if(n==0)break;
		
		
		int froid[111][111][2];
		rep(i,111)rep(j,111)rep(k,2)froid[i][j][k]=1010000000;
		
		
		rep(i,n){
			int a,b,c,d;
			cin>>a>>b>>c>>d;
			
			froid[a][b][0]=c;
			froid[b][a][0]=c;
			froid[a][b][1]=d;
			froid[b][a][1]=d;
			
		}
		
		rep(p,2){
			reps(k,m){
				reps(i,m){
					reps(j,m){
						froid[i][j][p] = min(froid[i][j][p],froid[i][k][p]+froid[k][j][p]);
					}
				}
			}
		}
		
		int k;
		cin>>k;
		
		rep(i,k){
			int a,b,c;
			cin>>a>>b>>c;
			
			printf("%d\n",froid[a][b][c]);
		}
	}
}

Measured memory_bytes: 968
#include <stdio.h>
#define N 100002

typedef struct node{
  char mark;
  int num;
} data;

int n;
data a[N],b[N],l[N/2],r[N/2];

void quick(int,int);
int partition(int,int);
void merge(int,int,int);
void mergesort(int,int);

int main(){
  int i,flag=0;

  scanf("%d",&n);
  for(i = 0;i < n;i++){
    scanf(" %c %d",&a[i].mark,&a[i].num);
    //printf("[%d:%d,%c]\n",i,a[i].mark,a[i].mark);
    b[i] = a[i];
  }

  quick(0, n-1);
  mergesort(0,n);
  

  for(i = 0;i < n;i++){
    if(a[i].mark != b[i].mark){
      flag++;
      break;
    }
  }
  if(flag == 0) printf("Stable\n");
  else printf("Not stable\n");
  for(i = 0;i < n;i++){
    printf("%c %d\n",a[i].mark,a[i].num);
  }
  
  return 0;
}

void quick(int p,int r){
  int q;
  if(p < r){
    q = partition(p, r);
    quick(p, q-1);
    quick(q+1, r);
  }
}

int partition(int p,int r){
  int i,j;
  data put,x;
  x = a[r];
  i = p - 1;
  for(j = p;j < r;j++){
    if(a[j].num <= x.num){
      i++;
      put = a[i];
      a[i] = a[j];
      a[j] = put;
    }
  }
    put = a[i+1];
    a[i+1] = a[r];
    a[r] = put;
    return i+1;
}

void merge(int left,int mid,int right){
  int n1,n2,i,j,k;
  n1 = mid - left;
  n2 = right - mid;
  for(i = 0;i < n1;i++){
    l[i] = b[left + i];
  }
  for(i = 0;i < n2;i++){
    r[i] = b[mid + i];
  }
  l[n1].num = 1000000000;
  r[n2].num = 1000000000;
  i = 0;
  j = 0;
  for(k = left;k < right;k++){
    if(l[i].num <= r[j].num){
      b[k] = l[i];
      i += 1;
    }
    else{
      b[k] = r[j];
      j += 1;
    }
  }
}


void mergesort(int left,int right){
  int mid,i,c=0;
  if(left + 1 < right){
    mid = (left + right)/ 2;
    mergesort(left, mid);
    mergesort(mid, right);
    merge(left, mid, right);
    c++;
  }
}



Measured memory_bytes: 4044
import java.io.PrintWriter
import java.util.*
import java.math.*
import java.lang.*

val pw = PrintWriter(System.out)
val MOD: Long = (1e+9 + 7).toLong()

fun main(args: Array<String>) {
   val (a, b) = readListOfInt() 
   val ans = Math.abs(b-a) / 2 + Math.min(a, b)
    println(if(Math.abs(b-a) % 2 == 0) ans else "IMPOSSIBLE")
    pw.flush()
}

/****** Decrared Functions and Data Structures ******/
// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }

fun Double.format(digits: Int) = String.format("%.${digits}f", this)
fun Float.format(digits: Int) = String.format("%.${digits}f", this)

fun print(value: Any) { pw.print(value) }
fun println(value : Any) { pw.println(value) }

fun<T> permutations(src: List<T>): List<List<T>> {
    if(src.size == 1) return listOf(src)
    val perms = mutableListOf<List<T>>()
    val insertElement = src[0]
    permutations(src.drop(1)).forEach { perm ->
        for(i in 0..perm.size) {
            val newPerm = perm.toMutableList()
            newPerm.add(i, insertElement)
            perms.add(newPerm.toList())
    }
    }
    return perms
}

// return nCr, if you want nCr, please access v[n][r]
fun combinations(n: Long): List<List<Long>> {
    val v = (0..n).map { (0..n).map{0L}.toMutableList() }.toMutableList()
    for(i in 0 until v.size) {
        v[i][0] = 1L
        v[i][i] = 1L
    }
    for(i in 0 until v.size) {
        for(j in 1 until i) {
            v[i][j] = (v[i-1][j-1] + v[i-1][j] % MOD)
        }
    }
    return v.map { it.toList() }.toList()
}

fun gcd(a: Long, b: Long): Long = 
    if(b != 0L) a else gcd(b, a % b)

fun lcm(a: Long, b: Long) = 
    (a * b) / gcd(a, b)

fun sumDigits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

fun isDecimal(v: Double): Boolean = ((v - Math.floor(v)) != 0.0)

// Data Structures
class Stack<T>(private var st: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = st.isEmpty()
    fun top(): T = st.last()
    fun push(e: T) { st.add(e) }
    fun pop() { st = st.dropLast(1).toMutableList() }
}

class Queue<T>(private var que: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = que.isEmpty()
    fun top(): T = que.first()
    fun push(e: T) { que.add(e) }
    fun pop() { que = que.drop(1).toMutableList() }
}


Measured memory_bytes: 37820
/*
START BY THE NAME OF ALMIGHTY ALLAH
THIS WONT BE ACCEPTED
STOP_GIVING_UP

██╗███████╗████████╗██╗ █████╗ ██╗  ██╗
██║██╔════╝╚══██╔══╝██║██╔══██╗██║ ██╔╝
██║███████╗   ██║   ██║███████║█████╔╝
██║╚════██║   ██║   ██║██╔══██║██╔═██╗
██║███████║   ██║   ██║██║  ██║██║  ██╗
╚═╝╚══════╝   ╚═╝   ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝

*/
#include<bits/stdc++.h>
#define l(i,a,n)for(int i=a;i<n;i++)
#define pb push_back
#define in insert
#define mp make_pair
#define lw(v) sort(v.begin(),v.end());
#define hi(v) sort(v.begin(),v.end(),greater<long long>());
#define all(v) v.begin(),v.end()
#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    double t,r=1,r1=0,r2=0,k=0,a,b,c=1,m,d=0,n,e,f,x=0,g,p=0,q=0,y=0,z=0;
    vector<long long>v;
    vector<long long>u;
    set<long long>s;
    std::vector<int>::iterator it;
    string  s1,s2,s3,s4;
    cin>>n>>d;
    cout<<ceil(n/((d*2)+1))<<endl;
}


Measured memory_bytes: 3804
N = int(input())

DENOM = 10 ** 9 + 7

memo = [{} for i in range(N + 1)]

BASE = "ACGT"
AGC = "AGC"


def check(last4):
  for i in range(4):
    tmp = list(last4)
    if i >= 1:
      tmp[i-1], tmp[i] = tmp[i], tmp[i-1]
    if AGC in "".join(tmp):
      return False
  return True


def dfs(cur, last3):
  ret = 0
  if last3 in memo[cur]:
    return memo[cur][last3]
  if cur == N:
    return 1
  for c in BASE:
    if check(last3 + c):
      ret = (ret + dfs(cur + 1, last3[1:] + c)) % DENOM

  memo[cur][last3] = ret
  return ret

print(dfs(0, "TTT"))

Measured memory_bytes: 3888
/**************************************************************************
Coded by: Saba Karimi(_VINTAGE)
Institution: AIT PUNE
***************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int 
/**************************************************************************/
bool cmp(pair<pair<string,int>,int> &p1,pair<pair<string,int>,int> &p2)
{
    if(p1.first.first<p2.first.first)
        return true;
    if(p1.first.first == p2.first.first)
        if(p1.first.second>=p2.first.second)
            return true;
    return false;
}
signed main()
{
    fast;
    int n;
    cin>>n;
    vector<pair<pair<string,int>,int>> vp;
    for(int i=1;i<=n;i++)
    {
        string s;
        int score;
        cin>>s>>score;
        vp.pb({{s,score},i});
    }
    sort(all(vp),cmp);
    for(auto it:vp)
        cout<<it.second<<"\n";
}   

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

using namespace std;

#define llong long long int
#define ldouble long double
#define fore(i, x) for (auto &i : n)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repr(i, n) for (int i = n; i >= 0; --i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int mod = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = LLONG_MAX / 2;
const static double eps = 1e-10;
const static int dx[] = {1, 0, -1, 0};
const static int dy[] = {0, 1, 0, -1};

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

char field[501][501];

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

    vector<vector<int> > coins;
    int h, w;
    cin >> h >> w;
    rep(i, h) {
        vector<int> c;
        rep(j, w) {
            int a;
            cin >> a;
            c.push_back(a);
        }
        coins.push_back(c);
    }

    vector<pair<pair<int, int>, pair<int, int> > > ans;
    rep(i, h) {
        rep(j, w - 1) {
            if (coins[i][j] % 2) {
                ans.push_back({{i, j}, {i, j + 1}});
                --coins[i][j];
                ++coins[i][j + 1];
            }
        }
    }

    rep(i, h - 1) {
        if (coins[i][w - 1] % 2 == 1) {
            ans.push_back({{i, w - 1}, {i + 1, w - 1}});
            --coins[i][w - 1];
            ++coins[i + 1][w - 1];
        }
    }

    cout << ans.size() << endl;
    stl_rep(itr, ans) {
        cout << itr->first.first + 1 << " " << itr->first.second + 1 << " " << itr->second.first + 1 << " " << itr->second.second + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 5232
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[sc.nextInt() - 1] = i + 1;
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
			if (i != 0) {
				sb.append(" ");
			}
			sb.append(arr[i]);
		}
		System.out.println(sb);
	}
}


Measured memory_bytes: 50476
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;

namespace M_SOLUTIONS
{
    class Program
    {
        static public int[] SIn() { return ReadLine().Split().Select(int.Parse).ToArray(); }
        static void Main(string[] args)
        {
            var N = SIn()[0];
            WriteLine($"{(N - 2) * 180}");
        }
    }
}

Measured memory_bytes: 13396
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
 
typedef long long ll;
const ll MOD = 1e9+7;
const ll INF = 1e18;


#define PB push_back
#define MP make_pair
#define F first
#define S second

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}

vector<ll> firvis(200010,-1);
int main(){
    ll n,k;
    cin >> n >> k;
    ll to[n];
    for(ll i=0;i<n;i++){
        ll tmp;
        cin >> tmp;
        to[i]=tmp-1;
    }

    ll now=0,cycle=INF,st;
    firvis[0]=0;
    for(ll i=1;i<n;i++){
        now = to[now];
        if(firvis[now]==-1){
            firvis[now]= i;
        }else{
            cycle=i-firvis[now];
            st = i;
            break;
        }
        if(i==k){
            cout << now+1 << endl;
            return 0;
        }
    }
    for(ll i=0;i<(k-st)%cycle;i++){
        now = to[now];
    }
    cout << now+1  << endl;
}

Measured memory_bytes: 6360
#include<bits/stdc++.h>
#define rep(i,a,n) for(int _tmp=n,i=a;i<=_tmp;++i)
#define dep(i,a,n) for(int _tmp=n,i=a;i>=_tmp;--i)
#define re(i,a,n) for(int _tmp=n,i=a;i<_tmp;++i)
#define fec(i,a) for(__typeof a.begin() i=a.begin();i!=a.end();++i)
#define For(i,v,u) for(int i=H[u],v=to[i];i;i=nxt[i],v=to[i])
#define si(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define X first
#define Y second
#define inf 1000000000
using namespace std;
template<class T> inline void read(T&x){char c;bool fu=0;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x*=-1;}
template<class T> inline void read(T&x,T&y){read(x);read(y);}
template<class T> inline void read(T&x,T&y,T&z) {read(x,y);read(z);}
template<class T> inline void MAX(T&x,T y){if(x<y)x=y;}
template<class T> inline void MIN(T&x,T y){if(x>y)x=y;}
typedef long long ll;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;
const int N=211111;
//head
bool bad=0;
int a[N],l[N],r[N],n;
int cnt,to[N],nxt[N],H[N];
void ins(int x,int y){
	to[++cnt]=y;nxt[cnt]=H[x];H[x]=cnt;
}
void dfs(int u,int fa,int od){
	if(~a[u]){
		l[u]=r[u]=a[u];
		if(a[u]%2!=od)bad=1;
	}else {
		l[u]=-1e9;
		r[u]=1e9;
	}
	For(i,v,u)if(v!=fa){
		dfs(v,u,od^1);
		MAX(l[u],l[v]-1);
		MIN(r[u],r[v]+1);
	}
	if(l[u]>r[u])bad=1;
}
int rt,ans[N];
void dfs2(int u,int fa){
	For(i,v,u)if(v!=fa){
		if(ans[u]+1<=r[v])ans[v]=ans[u]+1;else ans[v]=ans[u]-1;
		dfs2(v,u);
	}
}
int main(){
	read(n);rep(i,1,n-1){
		int u,v;read(u,v);
		ins(u,v);ins(v,u);
	}
	rep(i,1,n)a[i]=-1;
	int _;read(_);rep(i,1,_){
		int x,y;read(x,y);
		a[x]=y;rt=x;
	}
	dfs(rt,0,a[rt]%2);
	if(bad)puts("No");
	else {
		ans[rt]=a[rt];
		dfs2(rt,0);
		puts("Yes");
		rep(i,1,n)printf("%d\n",ans[i]);
	}
	return 0;
}

Measured memory_bytes: 11136
#include<stdio.h>
int main ()
{ long long n;
  scanf("%lld",&n);
  long long  i=0;
    long long sum=100;
 while(1)
 {   if(sum>=n) {printf("%lld",i);return 0;}
    sum*=1.01;
    //printf("%lld\n",sum);
    i++;
 }
}

Measured memory_bytes: 1728
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int[] a = new int[n];
            int s_left[] = new int[n + 1];
            for (int i = 0; i < n; i++) {
                a[i] = Integer.parseInt(in.next());
                s_left[i + 1] = s_left[i] + a[i];
            }

            int ptr_l = 0;
            int ptr_r = n - 1;
            long sum_l = 0;
            long sum_r = 0;

            while (ptr_l <= ptr_r) {
                if (sum_l <= sum_r) {
                    sum_l += a[ptr_l];
                    ptr_l++;
                } else {
                    sum_r += a[ptr_r];
                    ptr_r--;
                }
            }

            long ans = Math.abs(sum_l - sum_r);
            // 出力
            out.println(ans);

        }

    }
}



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

int main() {
  int k;
  cin >> k;
  int x = 7%k;
  set<int> s;
  int i = 1;
  while (s.count(x) == 0) {
    if(x == 0){
      cout << i << endl;
      return 0;
    }
    s.insert(x);
    x = (x*10+7)%k;
    i++;
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 50372
#include<iostream>
#include<algorithm>

using namespace std;

int main(void)
{
	int n,t;
	cin >> n >> t;
	int m=1001;
	for(int i=1;i<=n;i++)
	{
		int cost,time;
		cin >> cost >> time;
		m=(time<=t ? min(m,cost):m);
	}
	if(m==1001)
		cout << "TLE" << endl;
	else
		cout << m << endl;
}

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

using namespace std;

const long long inf = 1e16;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n, m, l;
	cin >> n >> m >> l;

	vector<vector<long long> > d;
	d.resize(n);
	for(int i = 0; i < n; ++i) {
		d[i].resize(n, inf);
	}
	for(int i = 0; i < n; ++i) {
		d[i][i] = 0;
	}

	for(int i = 0; i < m; ++i) {
		int a, b, c;
		cin >> a >> b >> c;
		--a;
		--b;

		if(c <= l) {
			d[a][b] = min(d[a][b], (long long)c);
			d[b][a] = min(d[b][a], (long long)c);
		}
	}

	for(int k = 0; k < n; ++k) {
		for(int i = 0; i < n; ++i) {
			for(int j = 0; j < n; ++j) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}

	vector<vector<long long> > cost;
	cost.resize(n);
	
	for(int i = 0; i < n; ++i) {
		cost[i].resize(n, inf);
	}

	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			if(d[i][j] <= l) {
				cost[i][j] = 1;
			}
		}
	}

	for(int k = 0; k < n; ++k){
		for(int i = 0; i < n; ++i) {
			for(int j = 0; j < n; ++j) {
				cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
			}
		}
	}

	int q;
	cin >> q;

	while(q--) {
		int s, t;
		cin >> s >> t;
		--s;
		--t;

		if(cost[s][t] == inf) {
			cout << -1 << '\n';
		} else {
			cout << cost[s][t] - 1 << '\n';
		}
	}
	return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
int main(){
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(),a.end());
    int x = a[2]-a[1], y = a[2]-a[0];
    int ans = x/2 + y/2;
    if(x&1 && y&1){ans += 1;}
    else if(x&1 || y&1){ans += 2;}
    cout << ans << endl;
    return 0;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	int sum=0,mx=0;
	for(int i=0;i<n;++i){
		int L; cin>>L;
		sum+=L;
		mx=max(mx,L);
	}
	cout<<(sum-mx>mx?"Yes"s:"No"s)<<"\n"s;
}

Measured memory_bytes: 256