akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

ll n;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    n++;
    deque <int> ans;
    int b = 0;
    for(int i = 45 ; i >= 0 ; i--){
        if(b == 0 && (n >> i) & 1){
            b = 1;
            continue;
        }
        if(b == 0) continue;
        int x = ans.size();
        ans.push_back(x);
        if((n >> i) & 1){
            int x = ans.size();
            ans.push_front(x);
        }
    }
    int x = ans.size();
    for(int i = 0 ; i < x ; i++){
        ans.push_back(i);
    }
    cout << ans.size() << endl;
    for(auto &i : ans) cout << i + 1 << " ";
    cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
using namespace std;
using ll =long long;
const int mod = 1000000007;

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint & a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator-=(const mint & a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator*=(const  mint & a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint & a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint & a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint & a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint & a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint & a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream & os, const mint & m) {
		os << m.x;
		return os;
	}
};
void ini_func(vector<ll>& a, vector<ll>& b,ll N) {
	ll k, c;
	for (ll i = 0; i < N; i++) {
		cin >> k >> c;
		a.push_back(k);
		b.push_back(c);
	}


}
ll Nmap[501][501];
int main() {
	ll N, M, Q;
	cin >> N >> M >> Q;
	vector<ll>L,R,p,q;
	ini_func(L,R,M);
	ini_func(p,q,Q);
	
	for (int i = 0; i < M; i++) {
		Nmap[L[i] - 1][R[i] - 1]++;
	}
	for (int i = 1; i < 500;i++) {
		Nmap[i][0] += Nmap[i - 1][0];
		Nmap[0][i] += Nmap[0][i-1];

	}
	for (int i = 1; i < 500; i++) {
		for (int t = 1; t < 500; t++) {
			Nmap[i][t] += Nmap[i - 1][t] + Nmap[i][t - 1] - Nmap[i - 1][t - 1];
		}
	}
	for (int i = 0; i < Q; i++) {
		if (q[i] - 2 >= 0 && p[i] - 2 >= 0) {
			cout << Nmap[q[i] - 1][q[i] - 1] - Nmap[q[i] - 1][p[i] - 2] - Nmap[p[i] - 2][q[i] - 1] + Nmap[p[i] - 2][p[i] - 2] << endl;
		}
		else{
			cout << Nmap[q[i] - 1][q[i] - 1]<<endl;

		}
	}
}

Measured memory_bytes: 8932
fn main() {
    let n: usize = read();
    let mut s: Vec<usize> = Vec::new();
    let a = (0..n).map(|_| read::<usize>());
    for aa in a {
        if s.is_empty() {
            s.push(aa);
            continue;
        }
        if s[0] >= aa {
            s.insert(0, aa);
            continue;
        }
        let mut lb = 0;
        let mut ub = s.len();
        while ub - lb > 1 {
            let mid = (ub + lb) / 2;
            if s[mid] < aa {
                lb = mid;
            } else {
                ub = mid;
            }
        }
        s[lb] = aa;
    }
    println!("{}", s.len());
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

int main(){
  ll A;
  string S,T;
  cin >> A >> S >> T;
  rep(i,A){
    cout << S[i] << T[i];
  }
}

Measured memory_bytes: 3600
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lc (x<<1)
#define rc (x<<1|1)
#define gc (p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=1e5+10,size=1<<20,mod=998244353;

char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

struct edge{int y,next;}a[N];int len,last[N];
void ins(int x,int y) {a[++len]=(edge){y,last[x]};last[x]=len;}

void upd(int &x) {x+=x>>31&mod;}

ll power(ll a,ll b=mod-2) {
	ll c=1;
	for(   ;b;b>>=1,a=a*a%mod)
		if(b&1) c=c*a%mod;
	return c;
}

int n,m,f[N],sum[3][N],sz[3],g[N],num,ans,fir,inv=power(fir=power(10,18));

int main() {
	qr(n);
	for(int graph=0;graph<3;graph++) {
		if(len) memset(last+1,0,n<<2),len=0;
		qr(m); for(int j=1,x,y;j<=m;j++) {
			qr(x),qr(y);
			if(x>y) swap(x,y);
			ins(x,y);
		}
		int now=power(fir,n);
		for(int i=n; i;i--) {
			//求sg函数(f)
			++num;
			for(int k=last[i];k;k=a[k].next)
				g[f[a[k].y]]=num;
			f[i]=0;
			while(g[f[i]]==num) f[i]++;
			sz[graph]=max(sz[graph],f[i]);
			upd(sum[graph][f[i]]+=now-mod);
			now=(ll)now*inv%mod;
		}
	}
	for(int i=0;i<=sz[0];i++)
		for(int j=0,k;j<=sz[1];j++) {
			k=i^j;
			upd(ans+=(ll)sum[0][i]*sum[1][j]%mod*sum[2][k]%mod-mod);
		}
	pr2(ans);
	return 0;
}


Measured memory_bytes: 2816
#include<stdio.h>
#include<vector>
#include<iostream>

using namespace std;

int L,N;
int X[100];
int W[100];
int sum;
int flag;
vector<int> weight;

void input(){
	scanf("%d%d", &L, &N);
	for (int i = 0; i < N; ++i){
		scanf("%d%d", &X[i], &W[i]);
		sum += X[i] * W[i];
	}
}

void process(){
	flag = sum > 0 ? -1 : 1;
	
	int x = sum > 0 ? sum : -sum;
	while (x > 30) {
		x -= 30;
		weight.push_back(30);
	}
	if (x > 0) {
		weight.push_back(x);
	}
}

void output(){
	printf("%d\n", weight.size());
	for (auto it = weight.begin(); it != weight.end(); ++it){
		printf("%d %d\n", flag, *it);
	}
}

int main() {
	input();
	process();
	output();
	return 0;
}

Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2000000000;
constexpr ll mod = 1000000007;

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() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int x; cin >> x;
	int n = 1000000;
	vector<bool>p(n,true);
	REP(i, 2, n) {
		if (p[i]) {
			int j = i + i;
			while(j<n) {
				p[j] = false;
				j += i;
			}
		}
	}
	REP(i, x, n) {
		if (p[i]) {
			cout << i << "\n";
			return 0;
		}
	}


	return 0;
}


Measured memory_bytes: 508
package main

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

var sc = bufio.NewScanner(os.Stdin)

func read() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	// sc.Split(bufio.ScanLines)

	n, _ := strconv.Atoi(read())
	i, _ := strconv.Atoi(read())

	fmt.Println(n - i + 1)
}


Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
#include <utility>

#define ff(i,a,b) for (int i=(a);i<=(b);i++)
using namespace std;
typedef pair<int,int> ii;
const int N=2e5+10;
int w,h,n;
struct kien {
    int x,y,huong,id;
};
ii T[N]; int tmp[N];
kien a[N];
int cmpVal (const kien& k) {
    if (k.huong==0) ///Đông
        return (k.x&1)?3:1;
    return (k.x&1)?2:4;
}
bool cmpKien (const kien& k1, const kien& k2) {
    ///Đầu tiên sort theo đường chéo.
    if (k1.x+k1.y != k2.x+k2.y)
        return k1.x+k1.y < k2.x+k2.y;

    int xxk1 = (k1.x & 1), xxk2 = (k2.x & 1);
    if (((k1.x+k1.y)&1) == 0) { ///Ô trắng.
        if (xxk1 != xxk2) return xxk1<xxk2;
        else return k1.huong<k2.huong;
    }
    else {
        int tmp1=cmpVal (k1), tmp2 = cmpVal (k2);
        return tmp1 < tmp2;
    }
}
bool cungNhom (const kien &k1, const kien &k2) {
    if (k1.x+k1.y != k2.x+k2.y) return 0;
    int xxk1=k1.x&1, xxk2=k2.x&1;
    if (!((k1.x+k1.y)&1)) {
        return xxk1 == xxk2;
    }
    int val1=(k1.huong<<1)+xxk1, val2=(k2.huong<<1)+xxk2;
    return ((val1^val2)==0 || (val1^val2)==3);
}
bool cmp2 (const kien &k1, const kien &k2) {
    if (k1.huong != k2.huong) return k1.huong < k2.huong;
    if (k1.huong == 0)
        return k1.y < k2.y;
    else
        return k1.x > k2.x;
}
int tgRoi (const kien &k) {
    return (k.huong==0)?w-k.x:h-k.y;
}
bool cmp3 (const kien &k1, const kien &k2) {
    return k1.x-k1.y > k2.x-k2.y;
}
int main() {/*
    freopen("10.inp","r",stdin); freopen("10.out","w",stdout); //*/
    scanf("%d %d %d\n",&w,&h,&n);
    ff(i,1,n) {
        int x,y; char c; scanf("%d %d %c\n",&x,&y,&c);
        a[i] = {x,y,(c=='E')?0:1,i};
    }
    sort(a+1, a+n+1, cmpKien);
    int l=1, r=1;
    do {
        if (l>n) break;
        while (r<=n && cungNhom(a[l], a[r])) r++;
        sort(a+l, a+r, cmp2);
        ff(i,l,r-1) tmp[i]=tgRoi(a[i]);
        sort(a+l, a+r, cmp3);
        ff(i,l,r-1) T[a[i].id] = ii(tmp[i], a[i].id);
        l=r;
    } while (1);
    sort(T+1, T+n+1);
    ff(i,1,n) printf("%d\n",T[i].second);
    return 0;
}



Measured memory_bytes: 8216
#include <iostream>

int hist[100002];

int main() {
    int n, m;
    std::cin >> n >> m;
    while (m--) {
        int a, b; std::cin >> a >> b;
        hist[a]++; hist[b]++;
    }
    for (int i=1; i<=n; ++i) {
        if (hist[i]%2) {
            std::cout << "NO";
            return 0;
        }
    }
    std::cout << "YES";
}


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

int main() {
    string s, t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    string u;
    cin >> u;
    if(s == u) cout << --a << " " << b << endl;
    else       cout << a << " " << --b << endl;
}

Measured memory_bytes: 256
#include <iostream>

int min(int x, int y)
{
	return x>y ? y : x;
}

int main()
{
	int n; std::cin >> n;
	int* A = new int[n];
	for (int i=0; i<n; i++) std::cin >> A[i];
	
	int m; std::cin >> m;
	int* B = new int[m];
	for (int i=0; i<m; i++) std::cin >> B[i];
	
	int comp = -1;
	for (int i=0; i<min(n,m); i++) {
		if (B[i] > A[i]) {
			comp = 1; break;
		} else if (B[i] < A[i]) {
			comp = 0; break;
		}
	}
	if (comp < 0) comp = m>n ? 1 : 0;
	
	std::cout << comp << std::endl;
	
	delete[] A;
	delete[] B;
	
	return 0;
}
		



Measured memory_bytes: 3112
n, d = map(int, input().split())
x = [[int(x) for x in input().split()] for _ in range(n)]

def isqrt(n):
    x = n
    y = (x + 1) // 2
    while y < x:
        x = y
        y = (x + n // x) // 2
    return x

count = 0
for i in range(n-1):
  for j in range(i+1, n):
    distance = sum([(y-z) * (y-z) for y, z in zip(x[i], x[j])])
    if isqrt(distance) ** 2 == distance:
      count += 1
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1<<30
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define RREP(i,a,b) for(ll i=(a); i>=(b); i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef int64_t in;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef pair<ll, ll> p;
typedef vector<pair<ll, ll>> vpl;

vvl m(105, vl(105,0));
vl d(105, INF);
ll n;

void bfs(ll s){
    queue<ll> q;
    q.push(s);
    d[s] = 0;
    ll u;
    while(!q.empty()){
        u = q.front(); q.pop();
        rep(v,n){
            if(m[u][v] == 1){
                if(d[v] == INF){
                    d[v] = d[u] + 1;
                    q.push(v);
                }
            }
        }
    }
    rep(i,n){
        if(d[i] != INF) cout << i+1 << " " << d[i] << endl; 
        else cout << i+1 << " " << -1 << endl;
    }
}

int main(){
    ll u,k,v;
    cin >> n;
    rep(i,n){
        cin >> u >> k;
        rep(j,k){
            cin >> v;
            m[u-1][v-1] = 1;
        }
    }
    bfs(0);
    
    return 0;
}



Measured memory_bytes: 3256
o=->a,n{n<1?1:a**n[0]*o[a,n/2]**2%M}
eval'N,A,B='+`dd`.split*?,
a=o[A*=t=o[A+B,-2+M=10**9+7],N]
b=o[B*=t,N]
[g=k=1,*(1...N).map{|i|g=k=k*i%M}].map{|f|$.=($.+o[g*f,M-2]*(a+b)*100*t*k=k*N%M)%M
N+=1
a=a*B%M
b=b*A%M}
p$.

Measured memory_bytes: 4360
#include<bits/stdc++.h>
using namespace std;
 
int main() {
	
	int n;
	cin >> n;
	int ans = INT_MAX;
	
	for(int  i =0; i < n; i++){
		int a, b;
		cin >> a >> b;
		ans = min(ans, a+b);
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
while True:
    num = int(input())
    if num == 0:
        break
    else:
        numa = 0
        numb = 0
        for j in range(num):
            a,b = input().split(" ")
            if int(a) > int(b):
                numa += int(a) + int(b)
                continue
            if int(a) < int(b):
                numb += int(a) + int(b)
                continue
            if int(a) == int(b):
                numa += int(a)
                numb += int(b)
                continue
    print(str(numa) + " " + str(numb))


Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  int cnt = 0;
  for(int i=0; i<n; i++){
    cin >> a.at(i);
    if(a.at(i)%2 == 1){
      cnt++;
    }
  }
  if(cnt%2==0){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

long long int A[1000007];
long long int d[100007];
long long int g[1000007];
int main()
{
    int N,K;
    scanf("%d %d\n",&N,&K);
    for(int i=0;i<N;i++){ scanf("%lld ",&A[i]); }

    long long int maxA=0, maxGCD=1;
    for(int i=0;i<N;i++){ maxA+=abs(A[i]); }
    sort(A,A+N);

    int count=0;
    for(int i=1;i*i<=maxA;i++)
    {
        if(maxA%i==0)
        {
            d[count++]=i;
            if(i*i!=maxA){ d[count++]=maxA/i; }
        }
    }
    sort(d,d+count);

    for(int i=0;i<count;i++)
    {
        for(int k=0; k<N; k++)
        {
            g[k]=A[k]%d[i];
        }
        sort(g,g+N);
        long long int dif1=0, dif2=0;
        for(int k=0; k<N; k++)
        {
            dif1+=d[i]-g[k];
        }
        for(int k=0; k<N; k++)
        {
            dif1-=d[i]-g[k]; dif2+=g[k];
            if(max(dif1,dif2)<=K){ maxGCD=d[i]; break; }
        }
        //printf("%d %d\n",difA,absA);
        //if(absA%2==1||absA/2>K||difA!=0){ continue; }    
    }

    printf("%lld\n",maxGCD);
    return 0;
}

Measured memory_bytes: 4224
s = input()
cut = [0]
for i in range(len(s)-1):
    if(s[i:i+2] == '><'):
        cut.append(i+1)
cut.append(len(s)+1)

ans = 0
for i in range(len(cut)-1):
    ss = s[cut[i]:cut[i+1]]
    left = ss.count('<')
    right = ss.count('>')
    ans += left*(left+1)//2 + right*(right+1)//2 - min(left,right)

print(ans)

Measured memory_bytes: 9180
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		int s;
		Scanner scan = new Scanner(System.in);
		s = scan.nextInt();
		int hour = (s / 60) / 60;
		int min =  (s / 60) % 60;
        int sec = (s % 60);

		System.out.println(hour + ":" + min + ":" + sec);
	}

}

Measured memory_bytes: 26124
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI2(N, L);
  vector<string> S(N);
  FOR(i, N) cin >> S[i];
  sort(ALL(S));
  for (string s : S)
    cout << s;
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


import numpy as np
import bisect
from collections import defaultdict

N, M = map(int, input().split())
A = np.array(list(map(int, input().split())), dtype=np.int64)


d = defaultdict(int)
for i in range(N):
    d[A[i]] += 1

for _ in range(M):
    b, c = map(int, input().split())
    d[c] += b

keys = sorted(d.keys())

num = N
i = 0
S = 0
while num > 0:
    i -= 1
    value = keys[i]
    n = d[keys[i]]

    S += value * n
    num -= n
S += value * num
print(S)

Measured memory_bytes: 39424
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

string a, b;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> a >> b;
	FOR(i, a.size()+b.size()) {
		if (i & 1) cout << b[i/2];
		else cout << a[i/2];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
N, MOD = int(input()), 10 ** 9 + 7
dp = [[[[0 for k in range(4)] for k in range(4)] for j in range(4)] for i in range(101)]
dp[0][3][3][3] = 1

for length in range(N):
  for i in range(4):
    for j in range(4):
      for k in range(4):
        if dp[length][i][j][k] == 0: continue
        for a in range(4):
          if a == 2 and i == 1 and j == 0: continue
          if a == 2 and i == 0 and j == 1: continue
          if a == 1 and i == 2 and j == 0: continue
          if a == 2 and i == 1 and k == 0: continue
          if a == 2 and j == 1 and k == 0: continue

          dp[length + 1][a][i][j] += dp[length][i][j][k]
          dp[length + 1][a][i][j] %= MOD

ans = 0
for i in range(4):
  for j in range(4):
    for k in range(4):
      ans += dp[N][i][j][k]
      ans %= MOD

print(ans)


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

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

	int Q = S.size();
	if (Q <= K) {
		cout << S << endl;
	}
	else {
		string ans = S.substr(0, K);
		cout << ans << "..." << endl;
	}
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define leading zero str.erase(0, min(str.find_first_not_of('0'), str.size()-1));
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
string text="abcdefghijklmnopqrstuvwxyz";
const int maxn=1e6+7;
//        .--------------.
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'
ll bin_pow(ll a,ll b,ll m)
{
    ll res=1;
    a%=m;
    while(b>0)
    {
        if(b&1)
            res=res*a%m;
        b>>=1;
        a=a*a%m;
    }
    return res;
}
bool miller_rabin(ll d,ll n)
{
    ll a=2+rand()%(n-4);
    ll x=bin_pow(a,d,n);
    if(x==1 || x==n-1)
        return true;
    while(d!=n-1)
    {
        x=(x*x)%n;
        d*=2;
        if(x==1)
            return false;
        if(x==n-1)
            return true;
    }
    return false;
}
bool prime(ll n,ll k)
{
    if(n==1 || n==4)
        return false;
    if(n<=3)
        return true;
    ll d=n-1;
    while(d%2==0)
        d/=2;
    for(int i=0; i<k; i++)
    {
        if(!miller_rabin(d,n))
            return false;
    }
    return true;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll sum=0;
    for(int i=0;i<n;i++){
        ll x;
        cin>>x;
        sum+=x-1;
    }
   cout<<sum;
}


Measured memory_bytes: 3644
def comb(n, r, p):
    x, y = 1, 1
    for i in range(n, n - r, -1):
        x *= i
        y *= i + r - n
        x %= p
        y %= p
    return pow(y, p - 2, p) * x % p

r1, c1, r2, c2 = map(int, input().split())
mod = pow(10, 9) + 7
s1, s2 = c1 + r1, c1 + r2 + 1
t1, t2 = min(c1 + 1, r1 - 1), min(c1 + 1, r2)
comb1 = comb(s1, t1, mod)
comb2 = comb(s2, t2, mod)
u1, u2 = s1 - r1 + 1, s2 - r2
ans = comb2 - comb1
for i in range(1, c2 - c1 + 1):
    comb1 = comb1 * (s1 + i) * pow(u1 + i, mod - 2, mod)
    comb1 %= mod
    comb2 = comb2 * (s2 + i) * pow(u2 + i, mod - 2, mod)
    comb2 %= mod
    ans += comb2
    ans -= comb1
    ans %= mod
print(ans)

Measured memory_bytes: 73560
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

int T, GX, GY;
int P, dp[20][20];
bool disable[20][20][20][20];
const string blah = "Miserable Hokusai!";

int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &GX, &GY);
    scanf("%d", &P);

    memset(disable, 0, sizeof disable);
    memset(dp, 0, sizeof dp);
    
    int x1, y1, x2, y2;
    rep(i,P) {
      scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
      disable[x1][y1][x2][y2] = disable[x2][y2][x1][y1] = true;
    }

    dp[0][0] = 1;

    for (int i = 1; i <= 15; ++i) {
      if (!disable[i-1][0][i][0])
        dp[i][0] = dp[i-1][0];
      if (!disable[0][i-1][0][i])
        dp[0][i] = dp[0][i-1];
    }

    for (int i = 1; i <= 15; ++i) {
      for (int j = 1; j <= 15; ++j) {
        if (!disable[i-1][j][i][j])
          dp[i][j] += dp[i-1][j];
        if (!disable[i][j-1][i][j])
          dp[i][j] += dp[i][j-1];
      }
    }

    if (dp[GX][GY] > 0) {
      printf("%d\n", dp[GX][GY]);
    } else {
      printf("%s\n", blah.c_str());
    }
    
  }
  return 0;
}

Measured memory_bytes: 1384
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

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

    if (a == b) {
        cout << 2 * a << "\n";
    } else {
        cout << max(a, b) * 2 - 1 << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int a=0;
	int b=0;
	int k=0;
	scanf("%d",&k);
	scanf("%d",&a);
	scanf("%d",&b);
	if(a%k==0||b%k==0||a/k!=b/k)
	{
		printf("OK");
	}
	else printf("NG");
}

Measured memory_bytes: 1736
using System;

public class Hello
{
    public const int P = 1000000007;
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        long ret;
        var t = Math.Abs(n - m);
        if (t >= 2) ret = 0;
        else if (t == 1) ret = (getFact(n) * getFact(m)) % P;
        else ret = (2 * getFact(n) * getFact(m)) % P;
        Console.WriteLine(ret);
    }
    public static long getFact(int n)
    {
        var ret = 1L;
        for (int i = n; i >= 1; i--)
        {
            ret *= i;
            ret %= P;
        }
        return ret;
    }
}


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

using namespace std;

int n,l;

void solve(){
    cin >> n;
    vector<int> dp(n);
    vector<int> h(n);
    for(int i = 0;i < n;i++) cin >> h[i];
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    for(int i = 2;i < n;i++) dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
    cout << dp[n-1] << endl;
}

int main(){
    solve();
}


Measured memory_bytes: 1024
from fractions import gcd
from functools import reduce

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

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
  
ans = lcm_list(a) - 1
print(sum([ans % ai for ai in a]))

Measured memory_bytes: 5332
import java.io.*; 
import java.util.*; 

public class Main{ 
	
	static class FastReader{ 
		BufferedReader br; 
		StringTokenizer st; 

		public FastReader() 
		{ 
			br = new BufferedReader(new
					InputStreamReader(System.in)); 
		} 

		String next() 
		{ 
			while (st == null || !st.hasMoreElements()) 
			{ 
				try
				{ 
					st = new StringTokenizer(br.readLine()); 
				} 
				catch (IOException e) 
				{ 
					e.printStackTrace(); 
				} 
			} 
			return st.nextToken(); 
		} 

		int nextInt() 
		{ 
			return Integer.parseInt(next()); 
		} 

		long nextLong() 
		{ 
			return Long.parseLong(next()); 
		} 

		double nextDouble() 
		{ 
			return Double.parseDouble(next()); 
		} 

		String nextLine() 
		{ 
			String str = ""; 
			try
			{ 
				str = br.readLine(); 
			} 
			catch (IOException e) 
			{ 
				e.printStackTrace(); 
			} 
			return str; 
		} 
	}

	public static void main(String[] args) 
	{ 
        FastReader sc = new FastReader(); 
        //PrintWriter out = new PrintWriter(System.out); 

        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] arr = new int[n];
        int[] dp = new int[k+1];

        for(int i=0;i<n;i++)
        	arr[i] = sc.nextInt();

        dp[0] = 0;
        for(int i=1;i<=k;i++){
        	for(int val: arr){
        		if(val<=i)
        			dp[i] = (dp[i] | (dp[i-val]==0?1:0));
        	}
        }
        
        System.out.println( dp[k]==1?"First":"Second" );
	}
}


Measured memory_bytes: 22100
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<utility>
#include<vector>

int main(void) {
	using uint32 = unsigned int;
	uint32 n, ans = 0;
	scanf("%u", &n);
	std::vector<uint32> a(n), b(n), c(n), d(n);
	for (auto &e : a)
		scanf("%u", &e);
	for (auto &e : b)
		scanf("%u", &e);
	if (n & 1) {
		for (const auto e : a)
			ans ^= e;
		for (const auto e : b)
			ans ^= e;
	}
	for (auto &e : a)
		e = ~e;
	for (uint32 i = 0;i < 28;++i) {
		uint32 midA = n, midB = n;
		for (const auto e : a)
			midA -= e >> i & 1;
		for (const auto e : b) 
			midB -= e >> i & 1;
		uint32 lA = 0, lB = 0;
		const auto pbit = static_cast<uint32>(1) << i;
		for (const auto e : a)
			c[e & pbit ? midA++ : lA++] = e;
		for (const auto e : b)
			d[e & pbit ? midB++ : lB++] = e;
		std::swap(a, c);
		std::swap(b, d);
		lA = 0;
		lB = 0;
		const auto mask = (pbit << 1) - 1;
		while (lA < n) {
			while (lB < n && (a[lA] & mask) >= (b[lB] & mask))
				++lB;
			if (n - lB & 1)
				ans ^= pbit << 1;
			++lA;
		}
	}
	printf("%u\n", ans);
	return 0;
}


Measured memory_bytes: 3328
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <utility>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define each(e,c) for(auto&e:c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif
template<class T> ostream& operator<<(ostream& os, vector<T> const& v){
    rep(i,v.size()) os << v[i] << (i+1==v.size()?"":" ");
    return os;
}

struct Tree {
    Tree* ch[2];
};

Tree * parse(string::iterator b, string::iterator e){
    if(b==e) return nullptr;
    auto res = new Tree;
    res->ch[0] = res->ch[1] = nullptr;
    int d = 0;
    for(auto it = b; it != e; ++it){
        if(*it=='('){
            d++;
        } else if(*it==','){
            if(d==1){
                res->ch[0] = parse(b+1,it);
                res->ch[1] = parse(it+1,e-1);
            }
        } else if(*it==')'){
            d--;
        }
    }
    return res;
}

Tree * intersect(Tree * t, Tree * u){
    Tree * res = new Tree;
    res->ch[0] = res->ch[1] = nullptr;
    rep(i,2){
        if(t->ch[i]!=nullptr && u->ch[i]!=nullptr){
            res->ch[i] = intersect(t->ch[i],u->ch[i]);
        }
    }
    return res;
}

Tree * unite(Tree * t, Tree * u){
    if(t==nullptr && u==nullptr) return nullptr;
    Tree * res = new Tree;
    res->ch[0] = res->ch[1] = nullptr;
    if(t!=nullptr && u!=nullptr){
        rep(i,2){
            res->ch[i] = unite(t->ch[i], u->ch[i]);
        }
    } else {
        if(t==nullptr) swap(t,u);
        rep(i,2){
            res->ch[i] = unite(t->ch[i], nullptr);
        }
    }
    return res;
}

void print(Tree* t){
    cout << "(";
    if(t->ch[0] != nullptr) print(t->ch[0]);
    cout << ",";
    if(t->ch[1] != nullptr) print(t->ch[1]);
    cout << ")";
}

int main(){
    char c;
    while(cin>>c){
        string s,t; cin >> s >> t;
        auto a = parse(all(s)), b = parse(all(t));
        if(c=='i') print(intersect(a,b));
        else print(unite(a,b));
        cout << endl;
    }
}

Measured memory_bytes: 1200
N, M = map(int, input().split())
L = [True] * (N+1)
for i in range(M):
    a, b = map(int, input().split())
    L[a] = not L[a]
    L[b] = not L[b]
if False in L:
    print("NO")
else:
    print("YES")


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


int main() {
    int N;
    cin>>N;
    map<string,int>mp;
    rep(i,N){
        string S;
        cin >>S;
        mp[S]++;
    }
    int M;
    cin>>M;
    rep(i,M){
        string T;
        cin>>T;
        mp[T]--;
    }
    int mx=0;
    for(auto p:mp){
        mx =max(mx,p.second);
    }
    cout <<mx<<endl;
}


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

int main() {
    int r, c, table[110][110] = {};
    cin >> r >> c;
    for (int i = 0; i < r; ++i) {
        for (int j = 0; j < c; ++j) {
            cin >> table[i][j];
            table[i][c] += table[i][j];
            table[r][j] += table[i][j];
            table[r][c] += table[i][j];
        }
    }
    for (int i = 0; i <= r; ++i) {
        for (int j = 0; j < c; ++j) {
            cout << table[i][j] << ' ';
        }
        cout << table[i][c] << endl;
    }
    
    return 0;
}


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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
//Write From this Line

int main()
{
	vector<int> x(5);
	rep(i,5) cin >> x[i];
	int ans = 15;
	rep(i,5){
		ans -= x[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 3504
from math import floor
from math import sqrt
N = int(input())
def f(x):
  return (floor((-1+sqrt(1+8*x))/2.0))
ans = 0
i = 2
while N > 1:
  x = 0
  while N % i == 0:
    N = N // i
    x = x + 1
  if x != 0:
    ans = ans + f(x)
  i = i + 1
  if i > 10 ** 6:
    ans = ans + 1
    break
print(ans)

Measured memory_bytes: 9208
/*


*/
#include <cstdio>
#include <cctype>
#include <algorithm>
#define gc() getchar()
#define mod 998244353
typedef long long LL;
const int N=305;

int A[N][N],B[N][N];

inline int read()
{
	int now=0;register char c=gc();
	for(;!isdigit(c);c=gc());
	for(;isdigit(c);now=now*10+c-48,c=gc());
	return now;
}
inline int FP(int x,int k)
{
	int t=1;
	for(; k; k>>=1,x=1ll*x*x%mod)
		if(k&1) t=1ll*t*x%mod;
	return t;
}

int main()
{
	int n=read(),m=read();
	for(int i=1; i<=n; ++i)
		for(int j=1; j<=m; ++j) A[i][j]=read();
	int r=0;
	for(int i=1; i<=n; ++i)
		for(int j=1; j<=m; ++j)
			if(A[i][j])//x>>j&1
			{
				if(B[j][j]) for(int k=j; k<=m; ++k) A[i][k]^=B[j][k];
				else
				{
					for(int k=j; k<=m; ++k) B[j][k]=A[i][k];
					++r; break;
				}
			}
	printf("%d\n",(FP(2,n+m-1)+mod-FP(2,n-r+m-1))%mod);

	return 0;
}

Measured memory_bytes: 896
package main

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

const (
	maxBufSize = 1024 * 1024
)

var (
	sc = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, 1)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
	out = bufio.NewWriter(os.Stdout)
)

func solve(x int64, y int64, z int64) []int64 {
	t := x
	x = y
	y = t

	t = x
	x = z
	z = t

	ret := make([]int64, 3)
	ret[0] = x
	ret[1] = y
	ret[2] = z
	return ret
}

func main() {
	defer out.Flush()

	x := nextInt()
	y := nextInt()
	z := nextInt()
	res := solve(x, y, z)
	for i, v := range res {
		fmt.Fprint(out, v)
		if i < 2 {
			fmt.Fprint(out, " ")
		}
	}
	fmt.Fprintln(out)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextStringAsBytes() []byte {
	sc.Scan()
	return []byte(sc.Text())
}

func nextInt() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int64) []int64 {
	ret := make([]int64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

func nextFloats(n int64) []float64 {
	ret := make([]float64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextFloat()
	}
	return ret
}
func nextStrings(n int64) []string {
	ret := make([]string, n)
	for i := int64(0); i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "orz")
	}
}

// mapからkeysとvaluesを返す
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "orz")
	}
	return
}


Measured memory_bytes: 640
#include<string>
#include<iostream>
#include<cstdio>

using namespace std;

int main(){
	string s;
	cin>>s;
	
	for(int i=0;i<s.size();i++){
		s[i] -= 3;
		if(s[i]<'A')s[i] += 'Z' - 'A' + 1;
	}
	
	cout<<s<<endl;
}

Measured memory_bytes: 1180
#include <iostream>
#include <algorithm>
#include <climits>
using namespace std;

int main(){
  int n, ws; cin >> n >> ws;
  int v[n+1], w[n+1];
  for(int i=1; i<=n; i++) cin >> v[i] >> w[i];

  int dp[n+1][ws+1];
  for(int i=0; i<=n; i++) {
    for(int j=0; j<=ws; j++) dp[i][j]=0;
  }

  for(int k=1; k<=n; k++){
    for(int i=0; i<=ws; i++){
      if(i<w[k]) dp[k][i] = dp[k-1][i];
      else dp[k][i]=max(dp[k-1][i], dp[k][i-w[k]]+v[k]);
    }
  }

  cout << dp[n][ws] << endl;
  return 0;
}



Measured memory_bytes: 7048
#include <iostream>
using namespace std;
int d[512];
#define N 10
#define M 20
int main( void )
{
  int x,y,s,a,mx=0,n=0;
  char c1,c2;
  int *p = d+256;
  while( 1 ){
    cin>>x>>c1>>y>>c2>>s;
    if( cin.eof() ) break;
    a = y*M+x;
    p[a]++; p[a-1]++; p[a+1]++; p[a+M]++; p[a-M]++;
    if( s > 1 ){ p[a+1+M]++; p[a-1+M]++; p[a+1-M]++; p[a-1-M]++; }
    if( s > 2 ){ p[a+2]++; p[a-2]++; p[a+2*M]++; p[a-2*M]++; }
  }
  for( y=0; y<N; y++ ) for( x=0; x<N; x++ ){
    a = p[y*M+x];
    if( mx < a ) mx = a;
    if( a == 0 ) n++;
  }
  cout << n << endl;
  cout << mx << endl;
  return 0;
}

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

struct query {
    int t;
    int f;
    char c;
};

int main() {
    string S;
    cin >> S;
    int Q;
    cin >> Q;
    vector<query> Query(Q);
    for (int i = 0; i < Q; i++) {
        int t;
        cin >> t;
        if (t == 1) {
            Query[i].t = 1;
        } else {
            int f;
            char c;
            cin >> f >> c;
            Query[i].f = f;
            Query[i].c = c;
        }
    }

    vector<int> cnt(Q + 1, 0);
    for (int i = Q - 1; i >= 0; i--) {
        cnt[i] += cnt[i + 1];
        if (Query[i].t == 1) {
            cnt[i]++;
        }
    }

    string ans;
    if (cnt[0] % 2 == 0) {
        ans = S;
    } else {
        reverse(S.begin(), S.end());
        ans = S;
    }

    string prefix = "";
    string suffix = "";
    for (int i = 0; i < Q; i++) {
        if (Query[i].t == 1) {
            continue;
        }

        if (Query[i].f == 1) {
            if (cnt[i] % 2 == 0) {
                prefix = prefix + Query[i].c;
            } else {
                suffix = suffix + Query[i].c;
            }
        } else {
            if (cnt[i] % 2 == 1) {
                prefix = prefix + Query[i].c;
            } else {
                suffix = suffix + Query[i].c;
            }
        }
    }

    reverse(prefix.begin(), prefix.end());

    cout << prefix + ans + suffix << endl;
}


Measured memory_bytes: 4704
#include <stdio.h>

int main(void)
{
    int s;
    int c=0;
    scanf("%d",&s);
    if(s/100==1)
        c++;
    if((s/10)%10==1)
        c++;
    if(s%10==1)
        c++;
    printf("%d\n",c);
    return 0;
}


Measured memory_bytes: 128
#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)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n;
    cin>>n;
    vector<int> b(n);
    rep(i,n)cin>>b[i];
    rep(i,n){
        if(b[i]>i+1){
            cout<<-1<<endl;
            return 0;
        }
    }
    vector<int> ans;
    while(b.size()){
        int k=b.size();
        vector<int> nb;
        int ok=0;
        for(int i=k-1;i>=0;i--){
            if(!ok&&b[i]==i+1){
                ans.push_back(b[i]);
                ok=1;
            }
            else  nb.push_back(b[i]);
        }
        reverse(nb.begin(),nb.end());
        b.swap(nb);
    }
    reverse(ans.begin(),ans.end());
    rep(i,n)cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

from collections import defaultdict
from sys import exit
import math


def main():
    a,b,x = getList()
    if x < b:
        print(math.floor( (a*x) / b) - a * math.floor(x/b) )
    else:
        k = b - 1
        print(math.floor( (a * k) / b) - a * math.floor(k / b) )
        
if __name__ == "__main__":
    main()

Measured memory_bytes: 65392
#include <stdio.h>

int main(void){

	char mark[9];
	int num[9], r_num[9], b_num[9], g_num[9], set, i, j;
	
	scanf("%d", &set);	/* ???????????°?????\??? */
	int ans[set];

	for(i = 0 ; i < 9 ; i++){	/* ????????????????????? */
		r_num[i] = 0;
		g_num[i] = 0;
		b_num[i] = 0;
	}

	for(i = 0 ; i < set ; i++){
		ans[i] = 0;
	}

	for(i = 0 ; i < set ; i++){	/* ???????????°?????°????????? */
		for(j = 0 ; j < 9 ; j++){
			scanf("%d", &num[j]);
		}
			for(j = 0 ; j < 9 ; j++){
				if(j == 9){
					scanf("%c", &mark[j]);
				}
		else{
			scanf(" %c", &mark[j]);
		}
	}

	for(j = 0 ; j < 9 ; j++){		/* ????????¨?????????????????? */
		if(mark[j] == 'R'){
			r_num[j] = num[j];
	}
			else if(mark[j] == 'G'){
				g_num[j] = num[j];
			}
			else if(mark[j] == 'B'){
				b_num[j] = num[j];
			}
		}

	sort(r_num);	/* ??????????????? */
	sort(g_num);	/* ??????????????? */
	sort(b_num);	/* ??????????????? */

		if(judge(r_num) == 1 && judge(g_num) == 1 && judge(b_num) == 1){	/* ???????????? */
			ans[i] = 1;
			}
	else{

		ans[i] = 0;
	}

		for(j = 0 ; j < 9 ; j++){	/* ????????????????????? */
			r_num[j] = 0;
			g_num[j] = 0;
			b_num[j] = 0;
		}
	}

		for(i = 0 ; i < set ; i++){
			printf("%d\n", ans[i]);
		}
	return 0;
}

void sort(int num[]){

	int p, q, tmp;

	for(p = 0; p < 8; p++){
		for(q = p + 1; q < 9; q++){
			if(num[p] > num[q]){
				tmp = num[p];
				num[p] = num[q];
				num[q] = tmp;
				}
			}
		}   
	}

int judge(int num[]){

	int cnt = 0;
	int i, j, k;

	for(i = 0; i < 9; i++){
		if(num[i] == 0){
			cnt++;			/* ???????????????0?????°??????????????? */
		}
	}
		if(cnt % 3 != 0){		/* 0?????°???3????????°??§???????????°0????????? */
	return 0;
}

	for(i = cnt; i < 9; i++){	/* ???????????¶?????????????????????????????? */
		if(num[i] != 0){
			for(j = cnt; j < 9; j++){
				if(num[j] != 0 && j != i){
					if(num[i] == num[j]){
						for(k = cnt; k < 9; k++){
							if(num[k] != 0 && (k != i && k != j)){
								if(num[i] == num[k]){
									num[i] = 0;
									num[j] = 0;
									num[k] = 0;
								}
							}
						}
					}

					else if(num[j] - num[i] == 1){
						for(k = cnt; k < 9; k++){
							if(num[k] != 0 && (k != i && k != j)){
								if(num[k] - num[j] == 1){
									num[i] = 0;
									num[j] = 0;
									num[k] = 0;
								}
							}
						}
					}
				}
			}
		}
	}
	cnt = 0;
		for(i = 0; i < 9; i++){
			if(num[i] == 0){
				cnt++;
			}
		}
			if(cnt == 9){
				return 1;
			}
	else{
	return 0;
	}
}

Measured memory_bytes: 596
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.Scanner;
import java.util.Queue;
import java.util.LinkedList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author varunvats32
 */
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);
        DMazeMaster solver = new DMazeMaster();
        solver.solve(1, in, out);
        out.close();
    }

    static class DMazeMaster {
        static int[][] a;
        static int r;
        static int c;
        static int max;
        static int[][] dir = new int[][]{{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            r = in.nextInt();
            c = in.nextInt();

            // Skip
            in.nextLine();

            a = new int[r][c];
            max = 0;

            for (int i = 0; i < r; i++) {
                String s = in.nextLine();
                for (int j = 0; j < c; j++) {
                    if (s.charAt(j) == '.') {
                        a[i][j] = 1;
                    } else {
                        a[i][j] = 0;
                    }
                }
            }

            for (int i = 0; i < r; i++) {
                for (int j = 0; j < c; j++) {
                    if (a[i][j] == 1) {
                        bfs(i, j);
                    }
                }
            }

            out.println(max);
        }

        private void bfs(int i, int j) {
            int[][] dist = new int[r][c];
            Queue<DMazeMaster.Pair> q = new LinkedList<>();
            q.add(new DMazeMaster.Pair(i, j));
            while (!q.isEmpty()) {
                DMazeMaster.Pair p = q.remove();
                for (int k = 0; k < dir.length; k++) {
                    int ki = p.x + dir[k][0];
                    int kj = p.y + dir[k][1];
                    if (notPossible(ki, kj) || dist[ki][kj] > 0 || (ki == i && kj == j)) continue;
                    q.add(new DMazeMaster.Pair(ki, kj));
                    dist[ki][kj] = dist[p.x][p.y] + 1;
                    if (dist[ki][kj] > max) {
                        max = dist[ki][kj];
                    }
                }
            }
        }

        private boolean notPossible(int i, int j) {
            return i >= r || j >= c || i < 0 || j < 0 || a[i][j] == 0;
        }

        static class Pair {
            int x;
            int y;

            public Pair(int x, int y) {
                this.x = x;
                this.y = y;
            }

        }

    }
}



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

int main(){
  int n;
  cin >> n;
  int ans=0,m=n+1,b;
  for(int i=0;i<n;i++){
    cin >> b;
    if(m>b){
      ans++;
      m=b;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;

/*
dp(i,j)=sのi文字とtのj文字目が先頭
*/

ll mod=1e9+7;
ll n,m,a[2010],b[2010],dp[2010][2010],dp2[2010][2010];

void init(){
	cin>>n>>m;
	reg(i,1,n)cin>>a[i];
	reg(i,1,m)cin>>b[i];
	reg(i,0,n)reg(j,0,m){
		dp[i][j]=0;
		dp2[i][j]=0;
	}
	dp[0][0]=1;
	dp2[0][0]=1;
	reg(i,0,n)dp2[i][0]=1;
	reg(j,0,m)dp2[0][j]=1;
}

int main(void){
	init();
	reg(i,1,n)reg(j,1,m){
		//累積和
		dp2[i][j]=(dp2[i][j]+dp2[i-1][j])%mod;
		dp2[i][j]=(dp2[i][j]+dp2[i][j-1])%mod;
		dp2[i][j]=(dp2[i][j]+mod-dp2[i-1][j-1])%mod;
		//
		if(a[i]==b[j])dp[i][j]=dp2[i-1][j-1];
		dp2[i][j]=(dp2[i][j]+dp[i][j])%mod;
	}
	cout<<dp2[n][m]<<endl;
	return 0;
}

Measured memory_bytes: 63232