akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

vector< int > divisor( int n) {
  vector< int > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

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

  //vector<vector<int>> x(n + 5, vector<int>());
  /*
  for (int i = 0; i < n; i++){
    x[i] = divisor(i + 1);
    /*
    for (int j = 0; j < x[i].size(); j++){
      cout << x[i][j] << " ";
    }
    cout << endl;
  }
  */
  
  //cout << endl;
  //vector<int> c(n, 0);

  for (int i = n - 1; i >= 0; i--){
    /*
    if (a[i] == 1){      
      b[i] += 1;
    }
    */
    int k = i;
    int tmp = 0;
    while(k<n){
      tmp += b[k];
      k += i + 1;
    }

    if(a[i] == 1 && tmp%2 == 0 || a[i] == 0 && tmp%2 == 1){
      b[i] = 1;
    }
  }
  int m = 0;
  

  for(int i=0; i<n; i++){
    if(b[i] == 1){
      m++;
    }
  }

  cout << m << "\n";

  for(int i=0; i<n; i++){
    if(b[i] == 1){
      cout << i + 1 << " ";
    }
  }
  cout << "\n";

  return 0;
}

Measured memory_bytes: 2432
def main():
    n,m=map(int,input().split())
    ks=[list(map(int,input().split())) for _ in range(m)]
    p=list(map(int,input().split()))
    ans=0
    for i in range(2**n):
        for j in range(m):
            cnt,flg=0,1
            for k in ks[j][1:]:
                if i>>(k-1)&1:
                    cnt+=1
            if cnt%2==p[j]:
                continue
            else:
                flg=0
                break
        ans+=flg
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
def main():
    N, K = map(int, input().split())

    LR = [list(map(int, input().split())) for _ in range(K)]
    MOD = 998244353

    dp = [0]*(N+1)
    S = [0]*(N+1)
    dp[1] = 1
    S[1] = 1

    for i in range(2, N+1):
        for l, r in LR:
            if i-l < 0:
                continue
            else:
                dp[i] += S[i-l] - S[max(i-r-1, 0)]
        dp[i] %= MOD
        S[i] = S[i-1] + dp[i]
    print(dp[-1]%MOD)

if __name__ == '__main__':
    main()


Measured memory_bytes: 27976
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int>> a(n, vector<int>(m));
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            cin >> a[i][j];
            a[i][j]--;
        }
    }
    vector<int> pos(n, 0);
    int ans = n;
    set<int> s;
    for(int i = 0; i < m-1; i++)
    {
        vector<int> cnt(m, 0);
        for(int j = 0; j < n; j++)
        {
            int p = pos[j];
            int c = a[j][p];
            cnt[c]++;
        }
        int ma = 0;
        int color = 0;
        for(int j = 0; j < m; j++)
        {
            if(cnt[j] > ma)
            {
                ma = cnt[j];
                color = j;
            }
        }
        s.insert(color);
        ans = min(ans, ma);
        for(int j = 0; j < n; j++)
        {
            int p = pos[j];
            int c = a[j][p];
            while(s.find(c) != s.end())
            {
                pos[j]++;
                c = a[j][pos[j]];
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3928
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7;
const ll LINF=1e18;
using namespace std;
#define int long long
//template
int dp[2003][2003];
std::vector<int> gy(100000);

std::vector<int> w(1000000);
int pw(int n,int k){
  int res=1;
  while(k){
    if(k%2)res*=n;res%=MOD;
    n*=n;n%=MOD;
    k/=2;
  }
  return res;
}
int nCk(int n,int k){
  if(n<k)return 0;
  int res=w[n];
  res*=gy[k];res%=MOD;
  res*=gy[n-k];res%=MOD;
  return res;
}

int qwe(int a,int b,int c){
  return nCk(c,a*b)*w[a*b]%MOD*pw(pw(w[a],b),MOD-2)%MOD*gy[b]%MOD;
}

//main
signed main(){
  int N,A,B,C,D;cin>>N>>A>>B>>C>>D;
  w[0]=1;for(int i=1;i<1000000;i++)w[i]=w[i-1]*i%MOD;
  for(int i=0;i<100000;i++)gy[i]=pw(w[i],MOD-2);
  memset(dp,0,sizeof(dp));dp[A-1][N]=1;
  for(int i=A;i<=B;i++){
    for(int j=0;j<=N;j++)dp[i][j]=dp[i-1][j];
    for(int j=C;j<=D;j++){
      for(int k=N-i*j;k>=0;k--){
        dp[i][k]+=qwe(i,j,k+i*j)*dp[i-1][k+i*j]%MOD;
        dp[i][k]%=MOD;
      }
    }
  }
  /*
  for(int i=0;i<=5;i++){
    for(int j=0;j<7;j++)cout<<dp[i][j]<<" ";cout<<endl;
  }
  */
  cout<<dp[B][0]<<endl;
}


Measured memory_bytes: 40192
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
  string S;
  cin >> S;
  
  string mae, usiro;
  int ans = 0;
  int maesize = 0;
  int strsize = (int)S.size();
  if( strsize % 2 == 1 ) strsize--;
  for( int i = strsize - 1; i >= 0; i-=2 ){
    mae = S.substr(0, (i+1)/2);
    usiro = S.substr((i+1)/2, (i+1)/2);
    if( mae.size()*2 != S.size() && mae == usiro ){
      maesize = (int)mae.size();
      ans = max(ans, maesize*2);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#define FOR(i, a, b)  for(int i=a;i<b;++i)
#define rep(i, n) for(int i=0;i<n;++i)
using namespace std;


int main(){
  int n, m;
  int max=0;
  map<string, int> mp;
  cin >> n;
  string s[n];
  rep(i,n){
    cin >> s[i];
    mp[s[i]]++;
  }
  cin >> m;
  string t[m];
  rep(i,m){
    cin >> t[i];
    mp[t[i]]--;
  }
  for(auto itr = mp.begin(); itr != mp.end(); ++itr){
    if(max < itr->second) max = itr->second;
  }
  cout << max << endl;
}

Measured memory_bytes: 256
/*input
3
1
*/
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
#define watch(x) cout << (#x) << " is " << (x) << endl
#define N 100002

using namespace std;
int main()
{
	fastio
	ll T=1,n,m;string str;
	// cin>>T;
	// cin.ignore(); put after cin, just b4 a getline(cin, s) to avoid getline() directly getting \n
	while(T--)
	{
		ll p=0,q=0,tmp=0,sum=0,count=0; //tmp variable
		int flag=0;
		
		ll a[3] = { 0 };
		for (int i = 0; i < 2; ++i)
		{
			cin >> tmp;
			a[tmp-1]=1;
		}
		for (int i = 0; i < 3; ++i)
		{
			if(a[i]==0)
			{
				cout << i+1 << endl;
			}
		}
		
	}
	return 0;
}

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

using namespace std;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n, k;
	cin>>n>>k;
	int A[n];
	int INF = 1e9+5;
	int dp[n];
	for (int i=0; i<n; i++){
		cin>>A[i];
		dp[i] = INF;
	}
	dp[0] = 0;
	for (int i=0; i<n; i++){
		for (int j=i; j<=i+k; j++){
			if(j == n) break;
			dp[j] = min(dp[j], dp[i] + abs(A[j] - A[i]));
		}
	}
	cout<<dp[n - 1];
}

Measured memory_bytes: 4356
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, n) ;for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) ;for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF (922337203685477587+1)
#define sosuu 1000000007

int main() {
  lli X;
  cin >> X;
  lli ans;
  cout << X/500*1000+(X%500)/5*5 << endl;
}

Measured memory_bytes: 256
let solve n = 1

let _ =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let s = Scanf.scanf "%s\n" (fun s -> s) in
  let k = Scanf.scanf "%d\n" (fun k -> k) in
  let c = String.get s (k-1) in
  let s' = ref "" in
  for i = 0 to n - 1 do
    let c' = String.get s i in
    s' := !s' ^ (if c = c' then String.make 1 c' else "*")
  done;
  print_string !s'


Measured memory_bytes: 384
import sys

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

for i in range(len(heights) - 1):
    if (heights[i] < heights[i+1]) and heights[i+1] != 1:
        heights[i+1] += -1
    if heights[i] > heights[i+1]:
        print('No')
        sys.exit(0)

print('Yes')


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

int main() {
    queue<pair<string, int>> prs;
    int n, q;
    cin >> n >> q;
    for (int i = 0; i < n; i++) {
        string str;
        int num;
        cin >> str >> num;
        
        prs.push(make_pair(str, num));
    }

    int total = 0;
    while(!prs.empty()) {
        string f;
        int s;
        tie (f, s) = prs.front();
        if (s > q) {
            s -= q;
            total += q;
            prs.push(make_pair(f, s));
        } else {
            total += s;
            cout << f << " " << total << endl;
        }
        prs.pop();
    }

    return 0;
}


Measured memory_bytes: 6340
c1 = [int(i) for i in input().split()]
c2 = [int(i) for i in input().split()]
c3 = [int(i) for i in input().split()]
if (len(set([c1[i] - c2[i] for i in range(3)])) == 1) & ((len(set([c2[i] - c3[i] for i in range(3)])) == 1)):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
d, g = map(int, input().split())
p = []
c = []
for _ in range(d):
    px, cx = map(int, input().split()) 
    p.append(px)
    c.append(cx)

ans = 2<<9

for m in range(1<<d):
    s = 0
    num = 0
    rest_max = -1
    for i in range(d):
        if m>>i & 1:
            s += 100 * (i+1) * p[i] + c[i]
            num += p[i]
        else:
            rest_max = i
    if s < g:
        s1 = 100 * (rest_max + 1)
        need = (g - s + s1 - 1) // s1
        if need >= p[rest_max]:
            continue
        num += need
    ans = min(ans, num)
print(ans)


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

using namespace std;

#define LL long long
#define N 320

int n,m,mod,c[N][N],f[N][N],g[N][N];

int main(){
	scanf("%d%d%d",&n,&m,&mod);
	c[0][0]=1;
	for (int i=1;i<=n+1;++i){
		c[i][0]=1;
		for (int j=1;j<=i;++j) c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
	}
	for (int i=m;i>=0;--i){f[1][i]=1; g[1][i]=(g[1][i+1]+f[1][i])%mod;}
	for (int i=2;i<=n+1;++i){
		for (int j=0;j<=m;++j)
			for (int k=1;k<i;++k)
				f[i][j]=(f[i][j]+(LL)f[i-k][j]*g[k][j+1]%mod*c[i-2][k-1])%mod;
		for (int j=m;j>=0;--j) g[i][j]=(g[i][j+1]+f[i][j])%mod;
	}
	printf("%d\n",f[n+1][0]);
	
	return 0;
}
			

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}
/*ll fac[100007],finv[100007],inv[100007];
void cominit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<100007;i++){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
ll com(ll n,ll k){
    if(n<k)return 0;
    if(n<0 || k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a[n];
    cin>>a[0];
    for(int i=1;i<n;i++){
        cin>>a[i];
        if(a[i]==a[i-1]){
            i--;
            n--;
        }
    }    
    vector<vector<ll> > v(200000);
    ll c[n];
    memset(c,-1,sizeof(c));
    for(ll i=0;i<n;i++){
        v[a[i]-1].pb(i);
    }
    for(ll i=0;i<200000;i++){
        ll niko=v[i].size();
        for(ll j=niko-1;j>0;j--){
            c[v[i][j]]=v[i][j-1];
        }
    }
    ll dp[n];
    dp[0]=1;
    for(ll i=1;i<n;i++){
        dp[i]=dp[i-1];
        if(c[i]!=-1){
            dp[i]+=dp[c[i]];
            dp[i]%=mod;
        }
    }
    cout << dp[n-1]<<endl;
    
    return 0;
}



Measured memory_bytes: 15872
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.Collections;
import java.math.BigDecimal;
import java.util.LinkedList;

public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double c = sc.nextDouble();
        
        double area = area(a, b, c);
        double len = len(a, b, c);
        double height = height(area, a);
        System.out.println(area);
        System.out.println(len);
        System.out.println(height);
    }
    
    static double area(double a, double b, double c) {
        return a*b*Math.sin(Math.toRadians(c))/2;
    }
    
    static double len(double a, double b, double c) {
        return Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2) - 2*a*b*Math.cos(Math.toRadians(c))) + a + b;
    }
    
    static double height(double area, double a) {
        return area / a * 2;
    }
}

Measured memory_bytes: 28172
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef pair<ll,int> P;
const ll INF = 1e17;

vector<P> g[100005];

ll dist[100005];

int main() {
  int n,m;
  cin >> n >> m;

  for(int i = n - 1; i > 0; i--) {
    g[i].push_back(P(0,i-1));
  }
  

  for(int i = 0; i < m; i++) {
    int l,r,c;
    cin >> l >> r >> c;
    l--; r--;
    g[l].push_back(P(c,r));
  }

  for(int i = 0; i < n; i++) dist[i] = INF;

  priority_queue<P,vector<P>, greater<P> > q;

  dist[0] = 0;
  q.push(P(0,0));

  while(!q.empty()) {
    P v = q.top();
    q.pop();

    if(v.first > dist[v.second]) continue;

    for(int i = 0; i < g[v.second].size(); i++) {
      P u = g[v.second][i];
      if(dist[u.second] > dist[v.second] + u.first) {
	dist[u.second] = dist[v.second] + u.first;
	q.push(P(dist[u.second],u.second));
      }
    }
  }

  if(dist[n-1] == INF) cout << -1 << endl;
  else cout << dist[n-1] << endl;
}
    







    


Measured memory_bytes: 10104
import std.stdio, std.string, std.array, std.conv, std.algorithm, std.typecons, std.range, std.container, std.math, std.algorithm.searching, std.functional,std.mathspecial;

void main(){
    auto a=readln.chomp.to!int;
    auto b=readln.chomp.to!int;
    auto h=readln.chomp.to!int;
    writeln((a+b)*h/2);
}


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

using namespace std;

typedef long long ll;

int A, B, C;
int X, Y;
int main() {
  scanf("%d %d %d %d %d", &A, &B, &C, &X, &Y);
  int res = 2e9;
  for (int i = 0; i <= 2 * max(X, Y) + 2; i += 2) {
    int a = max(0, X - i / 2), b = max(0, Y - i / 2);
    res = min(res, A * a + B * b + C * i);
  }
  printf("%d\n", res);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n;
    cin >> n;

    vector<tuple<string, ll, ll>> tup;
    rep(i, n) {
        string s;
        ll p;
        cin >> s >> p;
        tup.emplace_back(s, -p, i+1);
    }
    sort(all(tup));

    for(auto u : tup) {
        out(get<2>(u));
    }

    re0;
}

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

int main(){
	int n;
	cin >> n;
	int a[n],b[n],c[n];
	string ans[n];
	for(int i = 0;i < n;i++){
		cin >> a[i] >> b[i] >> c[i];
		if(a[i]*a[i] == b[i]*b[i] + c[i]*c[i] || b[i]*b[i] == c[i]*c[i] + a[i]*a[i] || c[i]*c[i] == a[i]*a[i] + b[i]*b[i]) ans[i] = "YES";
		else ans[i] = "NO";
	}

	for(int i = 0;i < n;i++){cout << ans[i] << endl;}

	return 0;
}

Measured memory_bytes: 1252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;
long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}
int main(){
    int N,K;cin >> N >> K;
    string S;cin >> S;
    K--;
    rep(i,N){
        if(i==K)cout << (char)(S[i]+32);
        else cout << S[i];
    }
    // cout << (int)'a' << endl;
    cout << endl;
    return 0;
}

Measured memory_bytes: 3572
main :: IO ()
main = do
  [sx, sy, tx, ty] <- map (read :: String -> Int) . words <$> getLine
  putStrLn $ solve (tx - sx) (ty - sy)
solve :: Int-> Int -> String
solve diffX diffY = r ++ u ++ l ++ d ++ "D"
                    ++ r ++ "R" ++ u ++ "U" ++ "LUL" ++ l
                    ++ d ++ "DR"
  where
    r = replicate diffX 'R'
    u = replicate diffY 'U'
    l = replicate diffX 'L'  
    d = replicate diffY 'D'


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int n, q;
string s, t, d;

int fdo(int pos){
	rep(i, q){
		if(s[pos] != t[i]) continue;
		pos += d[i]=='L'? -1: 1;
		if(pos < 0 ) return 2;
		if(pos >=n ) return 3;
	}
	return 1;
}

int fncl(){
	int hi=n, lw=-1;
	while(hi - lw >1){
		int md = (hi + lw) >>1;
		(fdo(md) == 2? lw: hi) = md;
	}
	return hi;
}
int fncr(){
	int hi=n, lw=-1;
	while(hi - lw >1){
		int md = (hi + lw) >>1;
		(fdo(md) == 3? hi: lw) = md;
	}
	return hi;
}


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

	cin >>n>>q>>s;

	rep(i,q){
		string x,y; cin >>x >>y;
		t+=x; d+=y;
	}
	//dbg(fncl(), fncr());
	cout << n - fncl() - (n -fncr())<<"\n";
	
}



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

using namespace std;

const int N = 500017;

int n;
int a[N];

bool read() {
    if (!(cin >> n))
        return false;

    for (int i = 0; i < n; ++i)
        cin >> a[i];

    return true;
}

void solve() {
    vector<long long> sums(2, 0ll);

    for (int i = 0; i < n; ++i)
        if (a[i] > 0)
            sums[i % 2] += a[i];

    if (sums[0] == 0 && sums[1] == 0) {
        int i = max_element(a, a + n) - a;
        cout << a[i] << endl << n - 1 << endl;

        for (int j = n - 1; j > i; --j)
            cout << j + 1 << endl;

        for (int j = 0; j < i; ++j)
            cout << 1 << endl;

        return ;
    }

    int p = sums[0] > sums[1] ? 0 : 1;
    cout << sums[p] << endl;
    vector<int> ans;

    for (int i = n - 1; i >= 0; --i)
        if (a[i] <= 0 || i % 2 != p)
            ans.push_back(i + 1);
        else
            break;

    vector<int> ids;

    for (int i = 0; i < n; ++i)
        if (i % 2 == p && a[i] > 0)
            ids.push_back(i);

    for (int i = ids.size() - 2; i >= 0; --i) {
        int l = ids[i], r = ids[i + 1];

        for (; r != l + 2; ----r)
            ans.push_back(l + 3);

        ans.push_back(l + 2);

        if (i == 0)
            for (int j = 0; j < l; ++j)
                ans.push_back(1);
    }

    cout << ans.size() << endl;

    for (auto i : ans)
        cout << i << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 256
# ABC109D - Make Them Even
import sys
input = sys.stdin.readline

def main():
    H, W = tuple(map(int, input().split()))
    A = list(list(map(lambda x: int(x) % 2, input().split())) for _ in range(H))
    ans = []
    for i in range(H):  # move left to right
        for j in range(W - 1):
            if A[i][j]:
                A[i][j] ^= 1
                A[i][j + 1] ^= 1
                ans += ["{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2)]

    for i in range(H - 1):  # move up to down
        if A[i][W - 1]:
            A[i][W - 1] ^= 1
            A[i + 1][W - 1] ^= 1
            ans += ["{} {} {} {}".format(i + 1, W, i + 2, W)]
    print(len(ans))
    for i in ans:
        print(i)


if __name__ == "__main__":
    main()

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    ll n;cin >>n;
    vector<ll>c(n-1);
    vector<ll>s(n-1);
    vector<ll>f(n-1);
    for (int i = 0; i < n-1; ++i) {
        cin>>c[i]>>s[i]>>f[i];
    }
    for (int i = 0; i < n; ++i) {
        if(i==n-1){
            cout <<0<<endl;
            return 0;
        }
        ll now=0;
        for (int j = i; j <n ; ++j) {
            if(j==n-1){
                cout <<now<<endl;
            }
            else {
                if (now < s[j])now = s[j];
                else {
                    now += (now%f[j]==0)?0:(f[j]-now % f[j]);
                }
                now += c[j];
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	int N;
	while (cin >> N) {
		vector<int>anss;
		for (int i = 0; i < 100; ++i) {
			if (N % 2) {
				anss.push_back(1<<i);
			}
			N /= 2;
		}
		for (int i = 0; i < anss.size(); ++i) {
			cout << anss[i];
			if (i == anss.size() - 1)cout << endl;
			else cout << " ";
		}
	}
	return 0;
}

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


using namespace std;



const int MAXN = 17;






vector<int> operator + (vector<int> v, vector<int> u) {
	for (auto i : u) v.push_back(i);
	return v;
}





int n, a, b;

vector<int> cal(int f, int g, int mask) {
	int z = -1, zz = -1;
	for (int i = 0; i < MAXN; i++) if ((f ^ g) & (1 << i))	{
		z = i;
		break;
	}
	if (z == -1) return {f};
	for (int i = 0; i < MAXN; i++) if (i != z && mask & (1 << i)) {
		zz = i;
		break;
	}
	if (zz == -1) return {f, g};
	return cal(f, f ^ (1 << zz), mask ^ (1 << z)) + cal(f ^ (1 << zz) ^ (1 << z), g, mask ^ (1 << z));
}




int main() {
	cin >> n >> a >> b;
	if ((__builtin_popcount(a ^ b) & 1) == 0) return cout << "NO", 0;
	cout << "YES\n";
	for (auto i : cal(a, b, (1 << n) - 1)) cout << i << ' ';
	return 0;
}

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

int main() { /* ここに書く */
  
  long long N,C,f,b;
  f = 0;
  C = 0;
  
  cin >> N;
  
  for(int i = 0; i<N ; i++){
    
    cin >> b;
    
    if( f>b ){
      C =  C + f - b;
    }
    else{
    f = b;
    }
   
  }
  
  cout << C << endl;
  
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef pair<int, int> pii;
 
#define PB push_back
#define MP make_pair
 
#define FOR(prom, a, b) for(int prom = (a); prom < (b); prom++)
#define FORDE(prom, a, b) for(int prom = (a); prom >= (b); prom--)
#define R1(a) do{scanf("%d", &(a));}while(0)
#define R2(a, b) do{scanf("%d%d", &(a), &(b));}while(0)
#define R3(a, b, c) do{scanf("%d%d%d", &(a), &(b), &(c));}while(0)
#define SV(vec) do{int __sv;scanf("%d", &(__sv));vec.PB(__sv);}while(0)
#define ALL(vec) (vec).begin(), (vec).end()
#define MM(co, cim) memset((co), (cim), sizeof((co)))
#define DEB(x) cerr << ">>> " << #x << " : " << x << endl;
#define INF   1000000007
#define INFLL 1000000000000000007LL
 
int n, a[200014], res[200014];
vector<int> g[200014];
multiset<int> s;
 
void go (int x, int p)
{
  s.insert(a[x]);
  auto it = s.find(a[x]);
  ++it;
  int erased = -1;
  if (it != s.end()) 
  {
    erased = *it;
    s.erase(it);
  }
  res[x] = s.size();
  //handle neighbors
  for (auto y : g[x]) if (y != p) go(y, x);
  //remove lis stuff
  if (erased != -1) s.insert(erased);
  s.erase(s.find(a[x]));
}
 
int main ()
{
  R1(n);
  FOR(i, 0, n) R1(a[i]);
  FOR(i, 0, n - 1)
  {
    int from, to;
    R2(from, to);--from;--to;
    g[from].PB(to);
    g[to].PB(from);
  }
  go(0, -1);
  FOR(i, 0, n) printf("%d\n", res[i]);
  return 0;
}

Measured memory_bytes: 33404
#include <iostream>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;

// prototype
bool big_equal( double a, double b );

// constraint
const int size = 31;
const double eps = 1e-9;
const double inf = (double)(1<<24);

//
// global
//

// dijkstra
class Node {
public:
    double time;
    int town, prev, v;
    bool operator < ( const Node& right ) const
    {
        return fabs( time - right.time ) < eps ? v < right.v : time > right.time;
    }
    Node(){}
    Node( double time_, int town_, int prev_, int v_ )
    {
        time = time_;
        town = town_;
        prev = prev_;
        v = v_;
    }
};
double MC[size][size][size];
typedef priority_queue <Node > QUEUE;

// data
int n;
int CN[size][size]; // connection
int CNcnt[size];
double D[size][size]; // distance of path
int L[size][size]; // speed limit

bool big_equal( double a, double b )
{
    return fabs( a - b ) < eps ? true : a < b;
}

void solve( int start, int goal )
{
    // init
    QUEUE Q;
    Node start_node( 0.0, start, -1, 1 );
    Q.push( start_node );

    // proc
    while ( !Q.empty() ) {
        Node node = Q.top();
        Q.pop();

        // proc init
        double time = node.time;
        int town = node.town;
        int prev = node.prev;
        int v = node.v;

        if ( town == goal && v == 1 ) {
            printf( "%.5f\n", time );
            return;
        }

        // move
        for ( int i = 0; i < CNcnt[town]; i++ ) {
            int next_town = CN[town][i];
            int next_prev = town;
            if ( next_town == prev ) continue;

            for ( int j = -1; j <= 1; j++ ) {
                int next_v = v + j;
                if ( prev == -1 && j != 0 ) continue;
                if ( next_v <= 0 || next_v > L[town][next_town] ) continue;
                double next_time = time + (double)D[town][next_town] / next_v;

                if ( big_equal( MC[next_town][next_prev][next_v], next_time ) ) continue;
                MC[next_town][next_prev][next_v] = next_time;
                Node next_node( next_time, next_town, next_prev, next_v );
                Q.push( next_node );
            }
        }
    }

    cout << "unreachable" << endl;
}

int main( void )
{
    while ( cin >> n && n ) {
        // init
        for ( int i = 0; i < size; i++ ) {
            CNcnt[i] = 0;
            for ( int j = 0; j < size; j++ ) {
                for ( int k = 0; k < size; k++ ) {
                    MC[i][j][k] = inf;
                }
            }
        }

        // input
        int m;
        cin >> m;
        int s, g;
        cin >> s >> g;
        for ( int i = 0; i < m; i++ ) {
            int x, y, d, c;
            cin >> x >> y >> d >> c;
            x--;
            y--;
            D[x][y] = D[y][x] = d;
            L[x][y] = L[y][x] = c;
            CN[x][CNcnt[x]++] = y;
            CN[y][CNcnt[y]++] = x;
        }

        // proc
        solve( s-1, g-1 );
    }
    return 0;
}

Measured memory_bytes: 1712
#include<stdio.h>

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


Measured memory_bytes: 2040
# import sys
import math

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
# INF = sys.maxsize

# ===CODE===
q = int(input())

condition = 10 ** 5

data = []
for i in range(q):
    l, r = map(int, input().split())
    data.append((l, r))

kodoku = {2}
kodoku_2 = [2]

for i in range(3, condition + 5, 2):
    lim = i ** (1 / 2)
    flg = True
    for div in kodoku_2:
        if div > lim:
            break
        if i % div == 0:
            flg = False
            break

    if flg:
        kodoku.add(i)
        kodoku_2.append(i)

ruisekiwa = [0] * (condition + 5)

for i in range(3, condition + 5):
    ruisekiwa[i] = ruisekiwa[i - 1]
    if i in kodoku and (i + 1) // 2 in kodoku:
        ruisekiwa[i] += 1

for l, r in data:
    ans = ruisekiwa[r] - ruisekiwa[max(0, l - 1)]
    print(ans)


Measured memory_bytes: 19268
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No"); }
void Yes() { cout << "Yes"; }
void No() { cout << "No"; }
//max_element


signed main()
{
	string S, T;
	cin >> S >> T;
	cout << T << S << endl;
}




Measured memory_bytes: 760
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <stack>
#include <unordered_set>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int maxn = 2e6 + 10;
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const ull base = 131;
const ull mod1 = 1e9 + 9;
const ull mod2 = 1610612741;

inline int read()
{
    int x = 0, f = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9'){
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9'){
        x = (x<<1) + (x<<3) + (ch^48);
        ch = getchar();
    }
    return x * f;
}

ll a, b;

int main()
{
    scanf("%lld%lld", &a, &b);
    if (b < 0)
    {
        if ((b-a+1)%2) printf("Negative\n");
        else printf("Positive\n");
    }
    else if (a > 0) printf("Positive\n");
    else printf("Zero\n");
    
    return 0;
}


Measured memory_bytes: 3096
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
const int N=200005;
struct node
{
	char a;
	char b;
}stringss[N];
int inc1(const void *a, const void *b)
{
    struct node m = *(struct node *)a;
    struct node n = *(struct node *)b;
    return m.a-n.a;
}
int inc2(const void *a, const void *b)
{
    struct node m = *(struct node *)a;
    struct node n = *(struct node *)b;
    return m.b-n.b;
}
int main()
{
	char str1[N],str2[N];
	scanf("%s",str1);
	scanf("%s",str2);
	int len=strlen(str1);
	for(int i=0;i<len;i++)
	{
		stringss[i].a=str1[i];
		stringss[i].b=str2[i];
	}
	qsort(stringss,len,sizeof(struct node),inc1);
	for(int i=0;i<len;i++)
	{
		if(stringss[i].a==stringss[i+1].a&&stringss[i].b!=stringss[i+1].b)
		{
			printf("No\n");
			return 0;
		}
	}
	qsort(stringss,len,sizeof(struct node),inc2);
	for(int i=0;i<len;i++)
	{
		if(stringss[i].b==stringss[i+1].b&&stringss[i].a!=stringss[i+1].a)
		{
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
}

Measured memory_bytes: 1412
/**
*    created: 14.05.2020 13:47:38
**/
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    vector<int> d(5);
    rep(i,5) cin >> d[i];
    int k; cin >> k;
    bool ok = true;
    rep(i,5) rep(j,i) {
        if (abs(d[i]-d[j]) > k) ok = false;
    }
    if (ok) cout << "Yay!" << endl;
    else cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll l,n,ans=0; cin>>l>>n;
    vector<ll> x(n,0),lx(n,0),xsum(n+1,0),lsum(n+1,0);
    rep(i,n){
        cin>>x[i]; lx[n-1-i]=l-x[i];
    }
    rep(i,n){
        xsum[i+1]=xsum[i]+x[i];
        lsum[i+1]=lsum[i]+lx[i];
    }
    ll cnt=0;
    for(int i=1;i<=n;i++){
        if((n-i)%2==0)
        cnt=xsum[(n-i)/2+i-1]*2-xsum[i-1]*2+x[i-1+(n-i)/2]+lsum[(n-i)/2]*2;
        else
        cnt=xsum[(n-i)/2+i]*2-xsum[i-1]*2+lsum[(n-i)/2]*2+lx[(n-i)/2];
        ans=max(ans,cnt);
    }
    for(int i=1;i<=n;i++){
        if((n-i)%2==0)
        cnt=lsum[(n-i)/2+i-1]*2-lsum[i-1]*2+lx[i-1+(n-i)/2]+xsum[(n-i)/2]*2;
        else
        cnt=lsum[(n-i)/2+i]*2-lsum[i-1]*2+xsum[(n-i)/2]*2+x[(n-i)/2];
        ans=max(ans,cnt);
    }
    cout<<ans<<endl;
}


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

using namespace std;
using ll=long long;

void solve() {
    int n; cin >> n;
    ll res = 0;
    for (int i = 0; i < n; i++) {
        res += (n-i) *1ll* (i+1);
    }
    for (int _ = 1; _ < n; _++) {
        int x,y;
        cin >> x >> y;
        --x;--y;
        if (x > y) swap(x, y);
        res -= (x+1) *1ll* (n-y);
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 3640
import java.util.*;
public class Main{
	public static void main(String[] args){
		int ans = 0;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		int[] trees = new int[n];
		for(int i=0; i<n; i++){
			trees[i] = sc.nextInt();
		}
		
		quick_sort(trees, 0, n-1);
		
		int min = trees[n-1];
		for(int i=0; i<n-k+1; i++){
			if(trees[i+k-1] - trees[i] < min){
				min = trees[i+k-1] - trees[i];
			}
		}
		
		System.out.println(min);
	}
	
	static void quick_sort(int[] d, int left, int right) {
		if(left>=right){
				return;
		}
		int p = d[(left+right)/2];
		int l = left, r = right, tmp;
		while(l<=r){
			while(d[l] < p){ l++; }
			while(d[r] > p){ r--; }
			if (l<=r) {
				tmp = d[l]; d[l] = d[r]; d[r] = tmp;
				l++;
				r--;
			}
		}
		quick_sort(d, left, r);
		quick_sort(d, l, right);
	}
}

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

char c[1001][1002];
int d[10000001];

int main(){
  int n, m;
  scanf("%d%d", &n, &m);
  for(int i=1; i<=n; i++) scanf("%s", c[i] + 1);
  queue<int> q;
  for (int i=1; i<=n; i++){
    for (int j=1; j<=m; j++){
      if (c[i][j] == '#'){
        q.push((i-1) * m + j);
        d[(i-1) * m + j] = 1;
      }
    }
  }
  int ans = 0;
  while (!q.empty()){
    int u = q.front();
    q.pop();
    ans = max(ans, d[u]);
    rep(i, 4){
      int v = u;
        if (i == 0 && u <= m || i == 1 && u % m == 1 % m ||
            i == 2 && u >= (n-1) * m + 1 || i == 3 && u % m == 0) continue;
        if (i == 0) v -= m;
        else if (i == 1) v--;
        else if (i == 2) v += m;
        else v++;
        if (!d[v]){
          d[v] = d[u] + 1;
          q.push(v);
        }
    }
  }
  printf("%d\n", ans - 1);
  return 0;
}


Measured memory_bytes: 12212
fun main(args: Array<String>) {
    readLine()!!.toInt()
    val A = readLine()!!.split(" ").map(String::toInt)
    val B = readLine()!!.split(" ").map(String::toInt)
    val C = readLine()!!.split(" ").map(String::toInt)
    var old = 100000
    var p = 0
    for (a in A) {
        val i = a - 1
        p += B[i]
        if (i == old + 1) p += C[i-1]
        old = i
    }
    println(p)
}

Measured memory_bytes: 37932
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<numeric>
#include<iomanip>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define ll long long

using namespace std;

//最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

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

int main() {
	int n, k, r, s, p;
	cin >> n >> k >> r >> s >> p;
	string t;
	cin >> t;

	ll ans = 0;
	rep(i, n - k) {
		if (t[i] == t[i + k]) {
			t[i + k] = 'f';
		}
	}

	rep(i,n){
		if (t[i] == 'r') {
			ans += p;
		}
		else if (t[i] == 's') {
			ans += r;
		}
		else if (t[i] == 'p') {
			ans += s;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int a,b;
  cin >> a >> b;
  int d = b-a;
  cout << d*(d+1)/2-b << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

    S = str(input())
    ls=len(S)


    # bit全探索
    # https://qiita.com/gogotealove/items/11f9e83218926211083a#%E4%BE%8B%E9%A1%8C-1
    n = ls-1
    # 昇順での探索だよ
    val = 0
    for i in range(2 ** n):
        split=[]
        for j in range(n):  # このループが一番のポイント
            if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
                split.append(j)
        temp=0
        for k in range(len(split)):
            val+=int(S[temp:split[k]+1])
            temp=split[k]+1
            if k==len(split)-1:
                val+=int(S[split[k]+1:])
    print(val+int(S))


resolve()

Measured memory_bytes: 40176
using System;

namespace _3_D
{
    class Program
    {
        static void Main(string[] args)
        {
            var abc = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var a = abc[0];
            var b = abc[1];
            var c = abc[2];
            var count = 0;
            for (var i = a; i <= b; i++)
            {
                if (c % i == 0)
                {
                    count++;
                }
            }
            Console.WriteLine(count);
        }
    }
}



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n[10];
	REP(i, 4){
		cin>>n[i];
	}
	sort(n, n+4);
	if(n[0]==1 && n[1]==4 && n[2]==7 && n[3]==9){
		cout<<"YES"<<'\n';
	}
	else{
		cout<<"NO"<<'\n';
	}
	return 0;
}


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

fn read<T: FromStr>(s: &mut StdinLock) -> T {
    let s = s.by_ref().bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().unwrap_or_else(|_| panic!("Faild to parse {}", s))
}

fn main(){
    let s = stdin();
    let mut s = s.lock();

    let n: usize = read(&mut s);
    let m: usize = read(&mut s);
    let mut from1 = vec![false; n + 1];
    let mut fromn = vec![false; n + 1];
    for _ in 0..m {
        let a: usize = read(&mut s);
        let b: usize = read(&mut s);
        from1[b] |= a == 1;
        from1[a] |= b == 1;
        fromn[b] |= a == n;
        fromn[a] |= b == n;
    }
    let flg = from1.iter().zip(fromn.iter()).fold(false, |acc, (&a, &b)| acc || a && b);
    println!("{}", if flg { "POSSIBLE" } else { "IMPOSSIBLE" });
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
//#define INF 1e18
#define MOD 1000000007

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


int n,W;
int v[105],w[105];
int dp[105][10005];

int main(){
  cin >> n >> W;
  rep(i,0,n){
    cin >> v[i+1] >> w[i+1];
  }

  rep(i,1,n+1){
    rep(j,0,W+1){
      int a = dp[i-1][j];
      int b=0;
      if(j - w[i] >= 0) b = dp[i-1][j-w[i]] + v[i];
      dp[i][j] = max(a,b);
    }
  }

  cout << dp[n][W] << endl;

  return 0;
}



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

typedef long long ll;

int main() {
    int r, g, b;
    cin >> r >> g >> b;
    if ((r * 100 + g * 10 + b) % 4 == 0) cout << "YES\n";
    else cout << "NO\n";
}

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

int main(){
    int n,i;
    string s;
    cin>>n;
    map<string,int> m;
    for(i=0;i<n;i++){
        cin>>s;
        m.count(s) ? m[s]+=1 : m[s]=1;
    }
    int max_freq=0;
    for(auto p : m) if(max_freq<p.second ) max_freq=p.second ;
    for(auto p : m) if(p.second==max_freq ) cout<<p.first<<endl;
    return 0;
}


Measured memory_bytes: 25216
#include "bits/stdc++.h"
using namespace std;
typedef long long lint;
#define rep(i,n) for(int i=0;i<n;++i)
#define MAXN 100010
#define all(v) v.begin(),v.end()
#define inf 2147483647
#define linf 1152921504606846976

lint dp[MAXN],a[MAXN];

int main(){
	lint n;cin>>n;
	rep(i,n)cin>>a[i];
	rep(i,n+1)dp[i]=linf;dp[0]=0;
	rep(i,n){
		dp[i+1]=min(dp[i+1],dp[i]+abs(a[i+1]-a[i]));
		dp[i+2]=min(dp[i+2],dp[i]+abs(a[i+2]-a[i]));
	}cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
	vector<vector<int>> a(3, vector<int>(3, 0));
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> a[i][j];
		}
	}
	int n, t;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> t;
		for (int y = 0; y < 3; y++) {
			for (int x = 0; x < 3; x++) {
				if (a[y][x] == t)	a[y][x] = -1;
			}
		}
	}

	bool bingo = false;
	if (a[0][0] == -1 && a[0][1] == -1 && a[0][2] == -1)		bingo = true;
	else if (a[1][0] == -1 && a[1][1] == -1 && a[1][2] == -1)	bingo = true;
	else if (a[2][0] == -1 && a[2][1] == -1 && a[2][2] == -1)	bingo = true;
	else if (a[0][0] == -1 && a[1][0] == -1 && a[2][0] == -1)	bingo = true;
	else if (a[0][1] == -1 && a[1][1] == -1 && a[2][1] == -1)	bingo = true;
	else if (a[0][2] == -1 && a[1][2] == -1 && a[2][2] == -1)	bingo = true;
	else if (a[0][0] == -1 && a[1][1] == -1 && a[2][2] == -1)	bingo = true;
	else if (a[0][2] == -1 && a[1][1] == -1 && a[0][2] == -1)	bingo = true;

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

	return 0;
}

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

/*
前から処理していき，rgbが揃ったら消すことを考える
rrgbgbと来た時に，
r  ->   rr  ->   rr -> r -> r -> 
                 g          g 
題意より，コストは文字の存在時間である(ここがポイント)
これをふまえると，できるだけ早くrgb揃えて消すのが最善．
よってrが来た時に，gbがあれば消す．g or bがあればそれとくっつけて消す
(この時，gとb両方が存在することはない．くっついてgbになっているはず)
よってrが来た時にgbがk個あるならans=ans*kとしてあげていい．k個の中の1個にくっつける．
最後に出来たセットをどの子に分配するかでN!をかけて終わり
*/

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

    int n;cin>>n;
    string s;cin>>s;
    int m=3*n;

    ll ans=1;
    for(ll i=1;i<=n;i++) ans=ans*i%mod;
    ll r=0,g=0,b=0,rg=0,gb=0,br=0;
    rep(i,m){
        if(s[i]=='R'){
            if(gb){
                ans=ans*gb%mod;
                gb--;
            }
            else if(g){
                ans=ans*g%mod;
                g--;
                rg++;
            }
            else if(b){
                ans=ans*b%mod;
                b--;
                br++;
            }
            else{
                r++;
            }
        }
        if(s[i]=='G'){
            if(br){
                ans=ans*br%mod;
                br--;
            }
            else if(r){
                ans=ans*r%mod;
                r--;
                rg++;
            }
            else if(b){
                ans=ans*b%mod;
                b--;
                gb++;
            }
            else{
                g++;
            }
        }
        if(s[i]=='B'){
            if(rg){
                ans=ans*rg%mod;
                rg--;
            }
            else if(r){
                ans=ans*r%mod;
                r--;
                br++;
            }
            else if(g){
                ans=ans*g%mod;
                g--;
                gb++;
            }
            else{
                b++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

const long long INF = 1LL << 60;

int main()
{
    int n;
    cin >> n;
    if (n % 2 == 0)
    {
        cout << n << endl;
    }
    else
    {
        cout << n * 2 << endl;
    }
    return 0;
}


Measured memory_bytes: 3624
/*
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0004
 */
#include <iomanip>
#include <iostream>
#include <sstream>
#include <vector>

#define N 2
#define L N*(N+1)

using namespace	std;

int
main()
{
	string line;
	while (getline(cin, line)) {
		istringstream iss(line);
		vector <float> coef(L);
		for (int i = 0; i < L; i++)
			iss >> coef[i];
		float pivot, mul;
		for (int i = 0; i < N; i++) {
			pivot = coef[i * (N + 1) + i];
			for (int j = 0; j < N + 1; j++) {
				coef[i * (N + 1) + j] = (1 / pivot) * coef[i * (N + 1) + j];
			}
			for (int k = i + 1; k < N; k++) {
				mul = coef[k * (N + 1) + i];
				for (int l = i; l < N + 1; l++) {
					coef[k * (N + 1) + l] = coef[k * (N + 1) + l] - mul * coef[i * (N + 1) + l];
				}
			}
		}
		for (int i = N - 1; i > 0; i--) {
			for (int k = i - 1; k >= 0; k--) {
				mul = coef[k * (N + 1) + i];
				for (int l = i; l < N + 1; l++) {
					coef[k * (N + 1) + l] = coef[k * (N + 1) + l] - mul * coef[i * (N + 1) + l];
				}
			}
		}
		for (int i = 0; i < N; i++) {
			if (i > 0) cout << ' ';
			cout << fixed << setprecision(3) << coef[i * (N + 1) + N];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3200