akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vector<pair<PII,string> > p,e,m;
  rep(i,n){
    string s;
    cin>>s;
    int num=0;
    rep(j,s.size() ){
      if(s[j]==')') num++;
      else num--;
    }
    if(num<0) p.push_back(make_pair(make_pair(0,num),s));
    else if(num==0)  e.push_back(make_pair(make_pair(0,num),s));
    else m.push_back(make_pair(make_pair(0,num),s));
  }
  rep(i,p.size() ){
    int x=0;
    rep(j,p[i].S.size() ){
      if(p[i].S[j]==')') x++;
      else x--;
      p[i].F.F=max(x,p[i].F.F);
    }
  }
  rep(i,m.size() ){
    int x=0;
    repn(j,m[i].S.size()-1 ){
      if(m[i].S[j]==')') x++;
      else x--;
      m[i].F.F=min(x,m[i].F.F);
    }
  }
  sort(p.begin(),p.end());
  sort(m.begin(),m.end() );
  int cnt=0;
  //cout<<endl;
  rep(i,p.size() ){
    // cout<<p[i].S<<endl;
    rep(j,p[i].S.size() ){
      if(p[i].S[j]==')') cnt++;
      else cnt--;
      if(cnt>0){
	cout<<"No"<<endl;return 0;
      }
    }
  }
  rep(i,e.size() ){
    // cout<<e[i].S<<endl;
    rep(j,e[i].S.size() ){
      if(e[i].S[j]==')') cnt++;
      else cnt--;
      if(cnt>0){
	cout<<"No"<<endl;return 0;
      }
    }
  }
  rep(i,m.size() ){
    // cout<<m[i].S<<endl;
    rep(j,m[i].S.size() ){
      if(m[i].S[j]==')') cnt++;
      else cnt--;
      if(cnt>0){
	cout<<"No"<<endl;return 0;
      }
    }
  }
  if(cnt==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  

  return 0;
}


Measured memory_bytes: 50404
#include<bits/stdc++.h>
using namespace std;
int n;
const int maxn=1e5+10;
struct data
{
    int l,r;
    bool operator < (const data &b)const
    {
        return r<b.r;
    }
}q[maxn];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        int x,l;
        scanf("%d%d",&x,&l);
        q[i].l=x-l,q[i].r=x+l;
    }
    sort(q+1,q+1+n);
    int R=q[1].r,cnt=1;
    for(int i=2;i<=n;i++)
    if(q[i].l>=R)cnt++,R=q[i].r;
    printf("%d\n",cnt);
    //system("pause");
}

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

int main(){
    int N;
    string S;
    cin >> N;
    cin >> S;
    int cnt=0;
    for(int i=0;i<N-2;i++){
        if(S[i]=='A'){
            if(S[i+1]=='B'&&S[i+2]=='C'){
                cnt++;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb=new StringBuilder();
		while(true){
			String s=br.readLine();
			if(s.equals("0 0")) break;
	        int x=Integer.parseInt(s.substring(0, s.indexOf(" ")));
	        int y=Integer.parseInt(s.substring(s.indexOf(" ")+1));
	        if(x>y){
	        	sb.append(y+" "+x+"\n");
	        }else{
	        	sb.append(x+" "+y+"\n");
	        }
		}
		System.out.print(sb);
	}
}

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

int main()
{
    ll n;
    cin >> n;
    map<string, ll> data;
    rep(i, n)
    {
        string s;
        cin >> s;
        data[s] += 1;
    }
    ll count = 0;
    for (auto x : data)
    {
        count += 1;
    }
    cout << count << endl;
}


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

int main() {
    ll N, K; cin >> N >> K;
    vector<ll> A(N); for (int i = 0; i < N; i++) cin >> A[i];

    while (K--) {
        vector<ll> inout(N+1, 0);
        for (int i = 0; i < N; i++) {
            inout[max((ll)0, i - A[i])]++;
            inout[min(N, i+A[i]+1)]--;
        }
        A[0] = inout[0];
        for (int i = 1; i < N; i++) {
            A[i] = A[i-1] + inout[i];
        }
        bool f = true;
        for (int i = 0; i < N; i++) {
            f = f && (A[i] == N);
        }
        if (f) break;
    }
    for (int i = 0; i < N; i++) {
        cout << A[i] << ' ';
    }
    cout << endl;
}

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

int main() {
  int d = 0;
  int N, K, x;
  cin >> N >> K;
  
  for(int i = 0; i < N; i++){
    cin >> x;
    int kx = K - x;
    if (x < kx)
      d += x * 2;
    else d += kx * 2;
  }
  cout << d << endl;
}

Measured memory_bytes: 3540
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, C, X = ii(), ii(), ii(), ii()

    ret = 0
    for a in range(A+1):
        for b in range(B+1):
            for c in range(C+1):
                if a * 500 + b * 100 + c * 50 == X:
                    ret += 1
    print(ret)


if __name__ == '__main__':
    main()


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

#define nl '\n'

using namespace std;

typedef long long ll;

void solve() {
  int H, W, K;
  cin >> H >> W >> K;
  string grid[H];
  for (int i = 0; i < H; i++)
    cin >> grid[i];

  int choices = 0;
  for (int mask1 = 0; mask1 < 1 << H; mask1++) {
    for (int mask2 = 0; mask2 < 1 << W; mask2++) {
      int black = 0;
      for (int i = 0; i < H; i++) {
        if (mask1 & (1 << i))
          continue;
        for (int j = 0; j < W; j++) {
          if (mask2 & (1 << j))
            continue;
          if (grid[i][j] == '#')
            black++;
        }
      }
      if (black == K)
        choices++;
    }
  }

  cout << choices;
}

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

  // int t;
  // cin >> t;
  // while (t--) {
  solve();
  cout << nl;
  // }

  return 0;
}

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

int cmp(const void *a, const void *b);//比較関数

int main(void){
    int i, N;
    double VALUE[51];
    scanf("%d", &N);
    for(i=0; i<N; i++) scanf("%lf", VALUE+i);
    qsort(VALUE, N, sizeof(double), cmp);//昇順ソート
    for(i=0; i<N-1; i++){
        VALUE[i+1] = (VALUE[i]+VALUE[i+1]) / 2.0;
    }
    printf("%f\n", VALUE[N-1]);
    return 0;
}

int cmp(const void *a, const void *b){
    double A=*(double *)a, B=*(double *)b;
    if(A==B) return 0;
    else if(A>B) return 1;
    else return -1;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll n,k;
  cin >> n >> k;
  ll a,b;
  ll cnt=0;
  FOR(b,k+1,n+1){
    cnt +=n/b*(b-k)+max((ll)0,n%b-k+1);
    if(k==0){
      cnt--;
    }
  }
  cout << cnt << endl;
}

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

int main() {

  int N;
  cin>>N;
  int a;
  int before, count = 0;
  for(int i = 0; i < N; i++) {
    cin>>a;
    if(before >= a && i != 0) count++;
    before = a;
  }
  count++;

  cout<<count<<endl<<N<<endl;
  return  0;
}



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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);i++)
#define FOR2(i,a,b) for (int i=(a);i<(b);i++)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define ROF2(i,x,y) for(int i = (y) ; i >= (x) ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) (((x)&1)==0?(0):(1))
#define sign(x) ((x > 0) - (x < 0))
#define FAST ios_base::sync_with_stdio(false); cin.tie(0)

template<class T,class U>
ostream &operator<<(ostream &os,const pair<T,U> &x) {
    return os<<"("<<x.first<<","<<x.second<<")";
}

template<class T>
ostream &operator<<(ostream &os,const vector<T> &x) {
    os << '[';
    if ( !x.empty() ) {
        std::copy (x.begin(), x.end(), std::ostream_iterator<T>(os, ","));
        os << "\b";
    }
    os << "]";
    return os;
}
template<class T>
ostream &operator<<(ostream &os,const vector<vector<T> > &x) {
    os << '[';
    if ( !x.empty() ) {
        os << x[0];
        for (int i=1;i<x.size();i++) os << endl << " " << x[i];
    } else os << "[]";
    os << "]";
    return os;
}

int main() {
    FAST;
    //freopen ("in.txt", "r", stdin);
    int n;cin>>n;
    ll f=0;
    FOR(i,n){
        int x;cin>>x;
        f += x-1;
    }
    cout << f;
    return 0;
}



Measured memory_bytes: 256
inf = 0x10101010
def solve(A,strt):
    cost = [inf]*m
    visited = [False]*m
    cost[strt] = 0
    while 1:
        min = inf
        next = -1
        visited[strt] = True
        for i in range(m):
            if visited[i]: continue
            if A[strt][i]:
                d = cost[strt] + A[strt][i]
                if d < cost[i]:
                    cost[i] = d
            if min > cost[i]:
                min = cost[i]
                next = i
        strt = next
        if next == -1: break
    return cost
      
while 1:
    n,m = map(int,raw_input().split())
    if n == 0: break
    T = [[0]*m for i in range(m)]
    C = [[0]*m for i in range(m)]
    for i in range(n):
        a,b,c,t = map(int,raw_input().split())
        T[a-1][b-1] = T[b-1][a-1] = t
        C[a-1][b-1] = C[b-1][a-1] = c
    TS = [solve(T,i) for i in range(m)]
    CS = [solve(C,i) for i in range(m)]
    for i in range(input()):
        a,b,q = map(int,raw_input().split())
        if q == 0:
            print CS[a-1][b-1]
        else:
            print TS[a-1][b-1]

Measured memory_bytes: 4812
mod = 10 ** 6 + 3

W = [1] * (mod)
for i in range(mod - 1):
	W[i + 1] = ((i + 1) * W[i]) % mod

def rev(a):
	return pow(a, mod - 2, mod)

def f(x, d, n):
	if d == 0:
		return pow(x, n, mod)
	else:
		d_r = rev(d)
		xdr = d_r * x % mod
		if xdr == 0:
			return 0
		elif (xdr + n - 1) >= mod:
			return 0
		else:
			return (W[xdr + n - 1] * rev(W[xdr - 1]) % mod) * pow(d, n, mod) % mod

ans = []
q = int(input())
for _ in range(q):
    x,d,n = map(int,input().split())
    ans.append(f(x,d,n))
for i in ans:
    print(i)

Measured memory_bytes: 47120
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define LOWER(a,x) lower_bound(ALL(a), x) - a.begin() - 1;
#define COUNT(a,x)  upper_bound(ALL(a), x) - lower_bound(ALL(a), x);
#define MCOUNT(a,x,y) upper_bound(ALL(a), y) - lower_bound(ALL(a), x);
#define SCAN(x) scanf("%lld",&x);
#define INF 5555555555555555555
#define MOD 1000000007
#define pb push_back
#define F first
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool flag, ok;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111



int main(void) {
  cin >> n;
  MAP mp;
  FOR(i, 0, n) {
	cin >> tmp;
	mp[tmp]++;
	mp[tmp - 1]++;
	mp[tmp + 1]++;
  }

  for (auto it : mp) {
	ans = max(ans, it.S);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 6144
n, m = map(int, input().split())
h = [None] + [int(x) for x in input().split()]

res = [0] + ([1] * n)

for _ in range(m):
    a, b = map(int, input().split())
    if h[a] >= h[b]:
        res[b] = 0
    if h[a] <= h[b]:
        res[a] = 0

print(sum(res))


Measured memory_bytes: 20112
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
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")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;
type I = usize;

fn main() {
    input!{
      mut s: chars,
    }
    let mut ans1 = 0;
    let mut ans2 = 0;
    for i in 0..s.len() {
        if i%2==0 {
            if s[i] == '1' {
                ans1 += 1;
            } else {
                ans2 += 1;
            }
        } else {
            if s[i] == '1' {
                ans2 += 1;
            } else {
                ans1 += 1;
            }
        }
    }
    println!("{}", min(ans1, ans2));
}


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

using namespace std;


int main(){
  int n;
  int m;
  int ans=0;
  int total=0;
  cin >> n >> m;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
    total += a.at(i);
  }
  for(int i=0;i<n;i++){
    if((double)a.at(i) >= total/(4.0*m)){
      ans++;
    }
  }
  if(ans>=m){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}


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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(int i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const ll powll = 1LL<<1;

int main(){
    while(1){
        int n; cin >> n;
        if(n == 0) break;
        int a[n];
        rep(i,0,n) cin >> a[i];
        sort(a,a+n);
        int ans = MOD;
        rep(i,0,n-1){
            ans = min(ans, abs(a[i]-a[i+1]));
        }
        cout << ans << "\n";
    }
	
}


Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  int a,b;
  int ans=0;
  cin >> n >> a >> b;
  for(int i=1;i<=n;i++){
    int cal=i;
    int cnt=0;
    while(cal!=0){
      cnt+=cal%10;
      cal/=10;
    }
    if(cnt>=a && cnt<=b){
      ans+=i;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String imp = scan.next();
		switch (imp) {
		case "A":
			System.out.println("T");
			break;
		case "T":
			System.out.println("A");
			break;
		case "C":
			System.out.println("G");
			break;
		case "G":
			System.out.println("C");
		}
	}

}

Measured memory_bytes: 21716
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using E = System.Linq.Enumerable;
class Program
{
    static char[] abc = "abcdefghijklmnopqrstuvwxyz".ToCharArray();
    static long mod = 1000000007;
    static void Main(string[] args)
    {

        //var NM = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        var S = Console.ReadLine().ToCharArray();
        var T = Console.ReadLine().ToCharArray();
        Array.Sort(S);
        Array.Sort(T);
        Array.Reverse(T);
        var sS = String.Join("", S);
        var sT = String.Join("",T);
        var ans = false ;
        if (string.Compare(sS,sT) == -1)
        {
            ans = true;
        }


        Console.WriteLine(ans ? "Yes" : "No") ;
    }
        

    
}


Measured memory_bytes: 26292
#include <stdio.h>

int A[101][101];
int n;

int main() {
  int i, j, u, k, v;

  scanf("%d\n", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d %d", &u, &k);
    for (j = 1; j <= k; j++) {
      scanf("%d ", &v);
      A[u][v] = 1;
    }
  }

  for (i = 1; i <= n; i++) {
    printf("%d", A[i][1]);
    for (j = 2; j <= n; j++) {
      printf(" %d", A[i][j]);
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 644
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 1000005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N;
char s[MAXN],t[MAXN];
int pos[MAXN],suf[MAXN],to[MAXN],turn[MAXN];
void Solve() {
    read(N);
    scanf("%s",s + 1);
    scanf("%s",t + 1);
    bool f = 1;
    for(int i = 1 ; i <= N ; ++i) {
	if(s[i] != t[i]) {f = 0;break;}
    }
    if(f) {puts("0");return;}
    int p = N;
    for(int i = N ; i >= 1 ; --i) {
	p = min(p,i);
	while(p >= 1 && s[p] != t[i]) --p;
	if(p == 0) {puts("-1");return;}
	if(!pos[p]) pos[p] = i;
	to[i] = p;
    }
    int cnt = 0,t = 0;
    int ans =  0;
    for(int i = N ; i >= 1 ; --i) {
	suf[i] = suf[i + 1];
	if(pos[to[i]] == i) {
	    ++suf[i];++cnt;++t;
	}
	ans = max(suf[i],ans);
	if(pos[i]) {
	    --cnt;
	    turn[i - cnt + t]++;
	}
	suf[i] -= turn[i + t];turn[i + t] = 0;
    }
    out(ans);enter;
}

int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 16768
import sys
from collections import Counter

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

counter = Counter(A)
ans = 0
pair = []
for l, count in sorted(counter.items(), reverse=True):
    # print(l, count)
    if count < 2:
        continue
    if count >= 4 and len(pair) == 0:
        pair = [l, l]
        break
    pair.append(l)
    if len(pair) == 2:
        break
if len(pair) == 2:
    print(pair[0] * pair[1])
else:
    print(0)

Measured memory_bytes: 26200
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto x:v)cerr<<x<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define EPS 1e-9
typedef long long ll;

signed main(){
  int N;
  cin >> N;
  ll x[N],y[N],h[N];
  FOR(i,0,N)cin >> x[i] >> y[i] >> h[i];
  FOR(Cx,0,101)FOR(Cy,0,101){
    ll minH = LINF;
    ll H = 0;
    bool flag = 0;
    FOR(i,0,N){
      if(h[i] == 0){
        minH = min(minH,abs(x[i]-Cx)+abs(y[i]-Cy));
      }
      else{
        if(H && H != h[i]+abs(x[i]-Cx)+abs(y[i]-Cy)){
          flag = 1;
          break;
        }
        H = h[i]+abs(x[i]-Cx)+abs(y[i]-Cy);
      }
    }
    if(flag)continue;
    if(H <= minH){
      printf("%lld %lld %lld\n",Cx,Cy,H);
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include<cstdio>

int h, n;
long long dp[10004][10004];
long long w[10004];

long long min(long long x, long long y) {
  return x < y ? x : y;
}

long long max(long long x, long long y) {
  return x > y ? x : y;
}

int main() {
  scanf("%d %d", &h, &n);
  for (int i = 1; i <= 10000; i++) {
    w[i] = 1000000000;
  }
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    w[a] = min(w[a], b);
  }
  for (int i = 1; i <= 10000; i++) {
    for (int j = 1; i * j <= 10000; j++) {
      w[i * j] = min(w[i * j], w[i] * j);
    }
  }
  for (int j = 1; j <= 10000; j++) {
    dp[0][j] = -1000000000;
  }
  for (int i = 1; i <= 10000; i++) {
    for (int j = 1; j <= 10000; j++) {
      if (j >= i) {
        dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - i] - w[i]);
      } else {
        dp[i][j] = max(dp[i - 1][j], -w[i]);
      }
    }
  }
  printf("%lld\n", -dp[10000][h]);
}


Measured memory_bytes: 781824
/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/+---test
3 5
---+/

void main(string[] args) {
  long X, A;
  readf(" %d %d ", &X, &A);

  (X < A? "0": "10").writeln;
}


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

int main(){
  int n;
  cin >> n;
  long long p=1;
  int mod = pow(10,9) +7;
  for (int i=1 ; i<=n; i++){
    p = (p*i)%mod;
  }
  cout << p << endl;
}

Measured memory_bytes: 256
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define fi first
#define se second

int gcd(int x, int y){
  if (x % y == 0) return y;
  else return gcd(y, x % y);
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n; cin >> n;
  int a[n];
  rep(i, n) cin >> a[i];

  int ans = a[0];

  rep(i, n){
    ans = gcd(ans, a[i]);
  }

  print(ans);
  
  return 0;
}

Measured memory_bytes: 640
#include<map>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<fstream>
#include<iostream>
#include<algorithm>
#define re register
#define ll long long
using namespace std;
ll R,P,len,sum;
char a[200000];
int main(){
	scanf("%s",a);
	len=strlen(a);
	int i;
	if(a[0]=='p'){
		sum--;
		R++;
	}
	if(a[0]=='g'){
		R++;
	}
	for(i=1;i<len;i++){
		if(a[i]=='g'){
			if(P<R){
				sum++;
				P++;
			}
			else{
				R++;
			}
		}
		if(a[i]=='p'){
			if(P<R){
				P++;
			}
			else{
				R++;
				sum--;
			}
		}
	}
	printf("%lld",sum);
}

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

int main() {
  char t[200002];
  scanf("%s", &t);

  for(int i=0;i<strlen(t);i++){
    if(t[i]=='?') t[i]='D';
  }

  printf("%s", t);
  return 0;
}


Measured memory_bytes: 2348
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

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

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}


int main(){
  int a, b;
  cin >> a >> b;
  int ans = max(a+b, max(a-b, a*b));
  cout << ans << endl;
}






Measured memory_bytes: 256
N = int(input())
S = input()
con = 0

for i in range(10):
  if str(i) in S:
    p = S.index(str(i))
    S2 = S[p + 1:]
    for j in range(10):
      if str(j) in S2:
        q = S2.index(str(j))
        S3 = S2[q + 1:]
        for k in range(10):
          if str(k) in S3:
            con += 1

print(con)


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

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

const double PI = 3.14159265358979323846;
int main()
{
        double R;
        cin >> R;
        double ans;
        ans = R * 2 * PI;
        cout << ans << endl;
	
        return 0;
}

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

int main() {
  int n, count = 0;
  int data[200];
  
  cin >> n;
  rep(i, n)
    cin >> data[i];
  
  int j = 0;
  while(1){
    if(data[j] % 2 == 0)
      data[j] /= 2;
    else
      break;
    
    if(++j == n){
      count++;
      j = 0;
    }
  }
  
  cout << count << endl;   
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline
INF = float("inf")


def main():
    N, M = map(int, input().split())
    keys = [None] * M
    for i in range(M):
        a, b = map(int, input().split())
        s = 0
        for c in map(int, input().split()):
            c -= 1
            s |= 1 << c
        keys[i] = (s, a)

    dp = [INF] * (2 ** N)
    dp[0] = 0
    for s in range(2 ** N):
        for key, a in keys:
            t = s | key
            dp[t] = min(dp[t], dp[s] + a)

    ans = dp[-1] if dp[-1] != INF else -1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9312
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            var isCalculatable = false;
            for (var i = 1; i < 10; i++)
            {
                if (n % i != 0) continue;
                var div = n / i;
                if (div < 10)
                {
                    isCalculatable = true;
                    break;
                }
            }
            Console.WriteLine(isCalculatable ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 11092
// Undone
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
#define MOD 1000000007
using namespace std;
signed main() {
  int N, a, cnt = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a;
    if (a != i+1) cnt++;
  }
  if (cnt <= 2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}



Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <climits>
#include <cmath>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define pb push_back
#define fst first
#define snd second

typedef long long ll;
typedef pair<int,int> pii;
template<typename T> using min_queue=priority_queue<T,vector<T>,greater<T>>;

const ll MOD=1e9+7;

int N,K;
string s;

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

  cin>>N>>K>>s;

  int cnt=0;
  char lst = -1;

  for(char c:s) {
    if (c != lst) cnt++;
    lst=c;
  }

  cnt = max(cnt-2*K, 1);
  cout<<N-cnt<<endl;

  return 0;
}


Measured memory_bytes: 512
#include <map>
#include <set>
#include <unordered_set>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <climits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#define _USE_MATH_DEFINES
#include <math.h>
#include <complex>
#include <atomic>
#include <thread>

using namespace std;
typedef long long ll;
#define ln '\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define drep(i,n) int i = 0;for(;i<(n);++i)
#define FOR(i,s,e) for(int i=s;i<=(e);++i)
#define DFOR(i,s,e) int i = s;for(;i<=(e);++i)
#define FORR(i,s,e) for(int i=s;i>=(e);--i)
#define DFORR(i,s,e) int i = s;for(;i>=(e);--i)
#define fore(a, x) for(auto& a : x)
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ft first
#define sd second
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define Fill(a,b) memset(a,b,sizeof(a))
template<typename T1, typename T2> bool Max(T1& a, T2 b) { return a<b ? a = b, 1 : 0; }
template<typename T1, typename T2> bool Min(T1& a, T2 b) { return a>b ? a = b, 1 : 0; }



const int N = 100001, inf = 10000;
int a[N];


void solve() {
  int n, z, w;
  cin >> n >> z >> w;
  rep(i, n)cin >> a[i];
  if (n == 1) {
    cout << abs(a[0] - w) << ln;
    return;
  }
  int t1 = abs(a[n - 1] - w);
  int t2 = abs(a[n - 2] - a[n - 1]);
  cout << max(t1, t2) << ln;
  
}


void init() {
  
}

int main(void) {
  ios::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20);
  //freopen("C:\\Users\\LENOVO\\Documents\\Visual Studio 2015\\Projects\\Test\\Input\\in.in", "r", stdin);

  init();
  int TC = 1;
#if 0
  cin >> TC; cin.get();
#endif
  FOR(TI, 1, TC) {
    //cout << "Case #" << TI << ": ";
    solve();
  }
  
  
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

constexpr ll mod=1e9+7;

ll mod_pow(ll a,ll b){
	a%=mod;
	if(b==0)return 1;
	if(b==1)return a;
	ll res=mod_pow(a,b/2)%mod;
	res*=res; res%=mod;
	if(b%2)res*=a;
	return res%mod;
}


int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	ll n; cin >> n;
	cout << ((mod_pow(10,n)-mod_pow(9,n)-mod_pow(9,n)+mod_pow(8,n))%mod+mod)%mod << endl;
}

Measured memory_bytes: 3648
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		String s = scan.next();
		scan.close();

		char[] c = s.toCharArray();
		for (int i = 0; i < s.length(); i++) {
			int c1 = c[i] + n;
			if (c1 > 90)
				c1 = c1 - 26;
			System.out.print((char) c1);

		}
	}
}

Measured memory_bytes: 24788
#include <iostream>
using namespace std;
#define MAX_N 11000

int main() {
  int N;
  cin >> N;
  int a[N];
  for (int i = 1; i <= N; i++) cin >> a[i];
  bool seen[N];

  int cur = 1, cnt = 0;
  while (a[cur] != 2) {
    seen[cur] = true;
    cur = a[cur];
    cnt++;
    if (cnt > N) break;
  }

  if (a[cur] == 2)
    cout << cnt + 1 << endl;
  else
    cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 768
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

enum MAX = 1_000_100;
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias Pass = Tuple!(long, "x", long, "y");

void main()
{
    auto n = lread();
    auto a = aryread();
    long flag, iter, ans;
    while (flag < n)
    {
        flag = 0;
        long cntzero, cntone;
        foreach (e; a)
        {
            e >>= iter;
            auto tmp = e & 1;
            if (e < 1)
                flag++;
            if (tmp)
                cntone++;
            else
                cntzero++;
        }
        ans += powmod(2, iter, MOD) * ((cntone * cntzero) % MOD) % MOD;
        ans %= MOD;
        iter++;
    }
    ans.writeln();
}

auto powmod(T)(T a, T b, long mod = MOD)
{
    auto ret = 1;
    while (b--)
    {
        ret *= a;
        ret %= mod;
    }
    return ret % mod;
}

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


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

#define pb push_back
#define fr first
#define sc second
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,pii> pip; 
const int INF = (1<<25);
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int n;
vector<pii> seg;

void init(int n_){
  n=1;
  while(n<n_) n*=2;
  seg.resize(n*2-1,pii(-1,-1));
}

void update(int k, int a){
  int id=k+n-1;
  seg[id].first+=a;
  seg[id].second=-k;
  while(id>0){
    id=(id-1)/2;
    seg[id]=max(seg[id*2+1], seg[id*2+2]);
  }
}

int main(){
  int N,R,L;
  int d,t,x;
  cin>> N>> R>> L;
  init(N);
  for(int i=0;i<N;i++){
    update(i,0);
  }

  vector<int> time(N,0);
  int now=0,most=0;
  while(R--){
    cin>> d>> t>> x;
    d--;
    time[most]+=t-now;
    update(d,x);
    now=t;
    most=-seg[0].second;
  }
  time[most]+=L-now;

  int maxt=0, maxg;
  for(int i=0;i<N;i++){
    if(time[i]>maxt){
      maxt=time[i];
      maxg=i;
      
    }
  }

  cout<< maxg+1<< endl;
}

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

struct N_struct {
  int Num;
  int A;
};


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

  vector<N_struct> N_st;

  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    N_st.push_back({i+1,a});
  }

  sort(N_st.begin(), N_st.end(), 
     [](const N_struct& x, const N_struct& y)  { return x.A < y.A;});  

  for (int i = 0; i < N; ++i) {
    cout << N_st[i].Num << ' ';
  }  
}
  

Measured memory_bytes: 1780
//皆さん、第9回シンデレラガール総選挙は、トップでオンリーワンを目指す城ヶ崎美嘉に
//そしてボイスアイドルオーディションは、プログラミングが趣味の才女大石泉に、ぜひ投票をお願いします！
//#城ヶ崎美嘉を009のシンデレラに
//#大石泉の必勝プログラム
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int main()
{
	int n,m,a;cin>>n>>m;
	rep(i,m){
		cin>>a;n-=a;
	}
	cout<<max(n,-1)<<endl;
}


Measured memory_bytes: 3636
from copy import deepcopy
H, W, K = map(int, input().split())
board = [[0]*(W+1) for _ in range(H+1)]
for i in range(1,H+1):
    board[i] = list(map(int, list(input())))+[0]
def drop(board_copy):
    change = True
    score = 0
    p = 0
    while change:
        change = False
        for i in range(2,H+1):
            ser = 1
            for j in range(1,W+1):
                if board_copy[i][j]>0 and board_copy[i][j]==board_copy[i][j-1]:
                    ser += 1
                else:
                    if ser>=K:
                        score += 2**p*board_copy[i][j-1]*ser
                        change = True
                        for k in range(i,0,-1):
                            board_copy[k][j-ser:j] = board_copy[k-1][j-ser:j]
                    ser = 1
        p += 1
    return score
ans = 0
for h in range(1,H+1):
    for w in range(W):
        board_copy = deepcopy(board)
        for k in range(h,0,-1):
            board_copy[k][w] = board[k-1][w]
        ans = max(ans,drop(board_copy))
print(ans)

Measured memory_bytes: 54236
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {

    int h, w, n;
    cin >> h >> w >> n;
    vector<int> a(n);
    rep(i, n){
        cin >> a[i];
    }

    vector<vector<int>> grid(h, vector<int>(w));
    int idx = 0;
    rep(i, h){
        if(i%2 == 0){
            rep(j, w){
                grid[i][j] = idx+1;
                if(--a[idx] == 0){
                    idx++;
                }
            }
        }
        else{
            for(int j=w-1; j>=0; --j){
                grid[i][j] = idx+1;
                if(--a[idx] == 0){
                    idx++;
                }
            }
        }
    }
    
    rep(i, h){
        rep(j, w){
            if(j != w-1){
                cout << grid[i][j] << " ";
            }
            else{
                cout << grid[i][j] << endl;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 384
n = gets.chomp.to_i
a = Array(1..9)
b = Array(1..9)
ab = []
(0..a.length-1).each do |n|
    (0..b.length-1).each do |m|
        ab << a[n]*b[m]
    end
end
if ab.include?(n)
  puts 'Yes'
else
  puts 'No'
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  int N,A[100000];
  cin>>N;
  for (int i(0);i<N;i++){
    cin>>A[i];
  }
  sort(A,A+N);
  int ans(0),tmp(1e9),maxi = A[N-1];
  for (int i(0);i<N-1;i++){
    if (abs(A[i]*2 - maxi) < tmp){
      tmp = abs(A[i]*2 - maxi);
      ans = A[i];
    }
  }
  cout << maxi << " " << ans << endl;
  return 0;
}



Measured memory_bytes: 640
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import comb

# 再帰がやばいとき
# import sys
# sys.setrecursionlimit(10**9)

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e50)
MOD = int(1e9)+7 # 10^9 + 7

# field[H][W]
def create_grid(H, W, value = 0):
    return [[ value for _ in range(W)] for _ in range(H)]

########

def main():
    H, M = l_inpl()
    A = l_inpl()
    d = {
        "1": 2,
        "2": 5,
        "3": 5,
        "4": 4,
        "5": 5,
        "6": 6,
        "7": 3,
        "8": 7,
        "9": 6
    }

    new_d = {}
    for Ai in A:
        new_d[Ai] = d[str(Ai)]

    dp = [-INF] * (H+1) # ちょうどi本のマッチ棒を使って，条件を満たす整数を作るときの最大桁数
    dp[0] = 0

    for i in range(1, H+1):
        tmp = []
        for k, v in new_d.items():
            if i-v < 0:
                tmp.append(-INF)
            else:
                tmp.append(dp[i-v]+1)
        dp[i] = max(tmp)

    s = sorted(new_d.items(), key=lambda x:-x[0])

    ans = ""
    remain = H

    while remain > 0:
        for k, v in s:
            if remain >= v and dp[remain-v] != -INF and dp[remain-v] == dp[remain] - 1: # 一桁だけ減少している
                ans += str(k)
                remain -= v
                break
    print(ans)
if __name__ == "__main__":
    main()


Measured memory_bytes: 41692
#include <stdio.h>

int	main(void)
{
	int a,b,c;
	scanf("%d%d%d", &a, &b, &c);
	int x;
	scanf("%d", &x);
	int i = 0;
	int j;
	int k;
	int count = 0;
	while (i <= a)
	{
		j = 0;
		while (j <= b)
		{
			k = 0;
			while (k <= c)
			{
				if ((i*500) + (j*100) + (k*50) == x)
					count++;
				k++;
			}
			j++;
		}
		i++;
	}
	printf("%d", count);
	return (0);
}


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

#define INF 1e9
#define pb push_back
#define mp make_pair
#define nl '\n'

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

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

	ll n,m;
	ll sum=0;
	cin >> n >> m;
	for(ll i=0,tmp;i<m;i++){
		cin >> tmp;
		n-=tmp;
	}
	
	if(n<0) n=-1;
	cout << n;

	return 0;
}

Measured memory_bytes: 3656
/*I MAY NOT GET THE SUCCESS IMMEDIATELY BUT I WILL GET IT FOR SURE*/
#include<bits/stdc++.h>
#define opt std::ios_base::sync_with_stdio(false)
#define I int
#define li		int32_t
#define lli		long long
#define ulli unsigned long long

#define pn			 printf("\n")
#define nl			 cout<<'\n'
#define sf(N)        scanf("%lld",&N)
#define pf(N)        printf("%lld",N)
#define sf1(N1,N2)    scanf("%lld %lld",&N1,&N2)
#define pf1(N1,N2)    printf("%lld %lld",N1,N2)
#define sf2(N1,N2,N3) scanf("%lld %lld %lld",&N1,&N2,&N3)
#define pf2(N1,N2,N3) printf("%lld %lld %lld",N1,N2,N3)

#define sl          cout<<' '
#define ps          printf(" ")

#define rep(i,a,b)	for(i=a;i<b;i++)
#define repr(i,a,b)	for(i=a;i>b;i--)
#define elif		else if
#define mset(a,b)	memset(a,b,sizeof(a))

#define pb		push_back
#define pob		pop_back
#define itr		iterator
#define sz()	size()
#define szof    sizeof
#define lb		lower_bound
#define ub		upper_bound
#define mp		make_pair
#define vlli    vector<lli>
#define plli	pair<lli,lli>
#define vplli	vector<plli >
#define F   	first
#define S		second
#define Dup     erase(unique(V.begin(),V.end()),V.end())

#define bs      binary_search
#define ub      upper_bound
#define lb      lower_bound

#define ALL(V)  V.begin(),V.end()

#define MX1     100000
#define MX2     1000000
#define Inf     1000000000000000
#define mod		1000000007
using namespace std;

lli Power(lli a,lli b)
{
    lli result=1;

    while(b)
    {
        if(b%2)
        {
            result=(result*a)%mod;
        }

        b=b>>1;
        a=(a*a)%mod;
    }

 return result;
}

int main()
{
    opt;
    
    /*#ifndef ONLINE_JUDGE
    freopen("double_squares.txt","r",stdin);
    freopen("double_squares_out.txt","w",stdout);
    #endif // ONLINE_JUDGE*/
    
    lli N,i;
    cin>>N;
    
    string s1,s2;
    cin>>s1>>s2;
    
    lli Product=1,cnt=0;
    while(i<N)
    {
        if(s1[i]==s2[i])
        {
            i++;
            
            if(cnt==0)
            {
                Product=(Product*3LL)%mod;
            }
            elif(cnt==1)
            {
                Product=(Product*2LL)%mod;
            }
            
            cnt=1;
        }
        else
        {
            if(cnt==0)
            {
                Product=(Product*6LL)%mod;
            }
            elif(cnt==1)
            {
                Product=(Product*2LL)%mod;
            }
            else
            {
                Product=(Product*3LL)%mod;
            }
            
            cnt=2;
            i+=2;
        }
    }
    
    cout<<Product;




 return 0;
}


Measured memory_bytes: 256