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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll dp[10005][10][2][105];
string K;
ll D;

ll rec(ll idx, ll val, ll tight, ll sum){
	if(dp[idx][val][tight][sum]>=0) return dp[idx][val][tight][sum];
	if(idx == (int)K.size()) return (sum==0);

	ll res = 0;
	ll ub = (tight ? (K[idx]-'0') : 9);
	for(int i=0;i<=ub;i++){
		ll flag;
		if(tight==1 && i==ub) flag = 1;
		else flag = 0;
		res += rec(idx+1, i, flag, (sum+i)%D);
		res %= mod;
	}

	dp[idx][val][tight][sum] = res;
	return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    REP(i, 10005)REP(j, 10)REP(k, 2)REP(l, 105) dp[i][j][k][l] = -1;

    cin >> K >> D;

    cout << (rec(0, 0, 1, 0)-1+mod)%mod << endl;
    return 0;
}

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

N, M, P = map(int, input().split())

INF = 10 ** 9
#入力

# 入力は1-index
# 内部で0-indexにして処理
G = []
for _ in range(M): #M個の辺の情報を受け取る
    A, B, C = map(int, input().split()) #lからrへ重みsの辺が存在
    G += [[A - 1, B - 1, P - C]] #有向グラフのときはここだけ

check = [False] * N
d = [INF] * N #距離を記録

def shortest_path(s): #S番目の頂点から各頂点への最短距離を求める
    s -= 1
    d[s] = 0
    j = 0
    while j < N - 1:
        for i in range(M): #無向グラフのときは辺は実質的には2倍
            e = G[i]
            if d[e[0]] != INF and d[e[1]] > d[e[0]] + e[2]:
                d[e[1]] = d[e[0]] + e[2]
        j += 1
    
    j = 0
    while j < N:
        for i in range(M):
            e = G[i]
            if d[e[0]] == INF:
                continue
            if d[e[0]] != INF and d[e[1]] > d[e[0]] + e[2]:
                d[e[1]] = d[e[0]] + e[2]
                check[e[1]] = True
            if check[e[0]]:
                check[e[1]] = True
        j += 1

shortest_path(1)
if check[N - 1]:
    print (-1)
else:
    ans = d[N - 1]
    print (max(0, -ans))
# print (d)

Measured memory_bytes: 42812
#include<stdio.h>
int main(){
  int i,x,n,p,a[201]={0},ans;
  scanf("%d %d",&x,&n);
  for(i=0;i<n;i++){
    scanf("%d",&p);
    a[p]=1;
  }
  for(i=0;i<100;i++){
    if(a[x-i]==0){
      ans=x-i;
      break;
    }
    if(a[x+i]==0){
      ans=x+i;
      break;
    }
  }
  printf("%d\n",ans);
}

Measured memory_bytes: 1712
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        p: [usize1; n],
    }
    let mut p = p;
    for i in 0..n {
        for j in 0..n {
            p.swap(i, j);
            let ok = (0..n).all(|i| p[i] == i);
            if ok {
                puts!("YES\n");
                return;
            }
            p.swap(i, j);
        }
    }
    puts!("NO\n");
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


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

int k,n,a[1000010],m;

int main(){
    cin>>k>>n;
    for(int i=0;i<n;i++)cin>>a[i+1];
    m=k-a[n]+a[1];
    for(int i=2;i<=n;i++){
        m=max(m,a[i]-a[i-1]);
    }
    cout<<k-m<<endl;
}

Measured memory_bytes: 1024
#C
from collections import deque
import bisect
import math
import heapq
import itertools
#import sys
#input = sys.stdin.readline

inf = float("inf")
mod = 10**9 + 7
#mod = 998244353

#list(map(int,input().split()))

N = int(input())
F = [list(map(int,input().split())) for i in range(N)]
P = [list(map(int,input().split())) for i in range(N)]

ans = -inf
for i in range(1024):
    if i == 0:
        continue
    b = bin(i)
    b = b.lstrip("0b")
    while len(b) < 10:
        b = "0"+b
    
    kari = 0
    for j in range(N):
        f = F[j]
        p = P[j]
        C = 0
        for k in range(10):
            if b[k] == "1" and f[k] == 1:
                C+=1
        kari += p[C]
    ans = max(ans,kari)
    #print(b)
print(ans)
        
    




Measured memory_bytes: 3444
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 100005;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,b;
    cin >> n;
    vector<int> a(n,0);
    rep(i,n-1){
        cin >> b;
        a[b-1]++;
    }
    rep(i,n) PRINT(a[i]);
}


Measured memory_bytes: 3992
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<cctype>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long INF = 1LL << 60;

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int n,a;
	cin>>n>>a;
	if(n%500<=a)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	
	
	return 0;
}

Measured memory_bytes: 256
let (a, b) = Scanf.scanf "%d %d" @@ fun a b -> (a, b)

let solve = function
  | (a, b) when (a * b) mod 2 = 0 -> "Even"
  | _ -> "Odd"

let () =
  (a, b)
    |> solve
    |> Printf.printf "%s\n"

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1<<29;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

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; }

const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};

const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};

vector< vector<int> > Graph;
vector< int > value;






int main(int argc, const char * argv[]) {
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n; cin >> n;
    map<ll,ll> A{};
    for (int i = 0; i < n; i++) {
        ll a; cin >> a;
        A[a]++;
        
    }
    
    ll Ans = 0;
    for (auto it = A.begin(); it != A.end(); it++) {
        if(it->first == it->second) continue;
        else if(it->first < it->second) Ans += ((it->second) - (it->first));
        else Ans += it->second;
    }
    
    cout << Ans << endl;
    
}



Measured memory_bytes: 6272
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

int n, a[200000];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	int rec = 0;
	for(int i = 0; i < n; i++)
		cin >> a[i], rec ^= a[i];
	for(int i = 0; i < n; i++) cout << (rec ^ a[i]) << ((i == n - 1) ? '\n' : ' ');
	return 0;
}


Measured memory_bytes: 4328
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define lld double
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define vc vector
#define rep1(it,v) for(it=v.begin();it!=v.end();it++)
#define ayush ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define input(v) for(auto &it:v)cin>>it
#define inf 100000000007
#define pb push_back

ll dp[100005]; ll v1[100005]; ll n;

ll fun(ll start)
{
    if(start>=n) return inf;
    if(start==n-1) return 0;
    
    if(dp[start]!=-1) return dp[start];
    
    return dp[start]=min(abs(v1[start+1]-v1[start])+fun(start+1), abs(v1[start+2]-v1[start])+fun(start+2));

}

int main()
{
    cin>>n; rep(i,0,n-1) cin>>v1[i];
    rep(i,0,n-1) dp[i]=-1;
    ll ans=fun(0);
    cout<<ans;
}


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

int main() {
  int A,B,C,K,i,J,sum=0;
  cin >> A>>B>>C>>K;
  if(A>=K){
    sum =K;
  }
  else if(A<=K){
    sum += A;
    K -= A;
    if(B>=K){
    }else{
      K -=B;
      sum -= K;
    }
  }
  
  cout << sum << endl;
  return 0;
}


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

using namespace std;

#define int long long
#define FR first
#define SC second
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

typedef pair<int, int> P;

const int inf = 1LL << 55;

typedef vector<int> nvector;
typedef vector<nvector> matrix;

matrix multi(const matrix& A, const matrix& B)
{
  matrix C(A.size(), nvector(B[0].size()));
  for(int i = 0; i < A.size(); i++) {
    for(int j = 0; j < B.size(); j++) {
      for(int k = 0; k < B[0].size(); k++) {
	C[i][k] += A[i][j] * B[j][k];
      }
    }
  }
  return C;
}

matrix power(matrix A, int n)
{
  matrix B(A.size(), nvector(A.size()));
  for(int i = 0; i < A.size(); i++) B[i][i] = 1;
  while(n > 0) {
    if(n & 1) B = multi(B, A);
    A = multi(A, A);
    n >>= 1;
  }
  return B;
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  int N, M, Z;  
  while(cin >> N >> M >> Z, N) {
    vector<P> v = {{1, 1}};
    rep(i, M) {
      int s, d; cin >> s >> d;
      v.emplace_back(s, d);
      v.emplace_back(d, s);
    }

    matrix A(v.size(), nvector(v.size()));
    rep(i, v.size()) reps(j, 1, v.size()) if(i != j) {
      if(v[i].FR != v[j].SC && v[i].SC == v[j].FR) A[i][j] = 1;
    }
    
    matrix B = power(A, Z);
    bool flag = false;
    rep(i, v.size()) if(B[0][i]) {
      if(v[i].SC == N) flag = true;
      if(flag) break;
    }
    
    cout << (flag ? "yes" : "no") << endl;
  }
  return 0;
}

Measured memory_bytes: 3312
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define rev(r) reverse(r.begin(),r.end())
#define SORT(ar) sort(ar.begin(), ar.end())
#define sz(x) (int)(x).size()
#define len(x) (int)x.length()
#define in(a) scanf("%d",&a)
#define pr(x) printf("%d ",x)
#define endl '\n'
#define read(v,n) for(int h=0;h<n;h++) cin>>v[h];
#define fo(i,a,b) for(i=a;i<b;i++)
#define fi(i,a,b) for(i=a;i>=b;i--)
#define mo 1000000007
#define N 300007

int main()
{
    int n,i,j,k;
    cin>>n;
    int a[n],b[n],c[n];
    fo(i,0,n)
    {
        in(a[i]); in(b[i]); in(c[i]);
    }
    int dp[n][3];
    dp[0][0]=a[0]; dp[0][1]=b[0]; dp[0][2]=c[0];
    fo(i,1,n)
    {
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
    }
    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]})<<endl;
}


Measured memory_bytes: 2560
N, M = map(int, input().split())
if N >=3 and M >= 3: print((N-2) * (M-2))
elif N < 3 and M < 3: print(1) if (N * M) % 2 else print(0)
else:
    N, M = max(N,M), min(N,M)
    if M == 1: print(N - 2)
    else: print(0)

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
 
using namespace std;
 
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
using ll = long long;
using P = pair<int,int>;

int main(void) {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  cout << min(a,b) + min(c,d) << endl;
  return 0;
}

Measured memory_bytes: 256
def f(a,b,c,d,e,f,g,h):return ((a-c)*(f-b)+(b-d)*(a-e))*((a-c)*(h-b)+(b-d)*(a-g))
while 1:
    try:x1,y1,x2,y2,x3,y3,xp,yp=map(float,input().split())
    except:break
    x=(x1+x2+x3)/3
    y=(y1+y2+y3)/3
    print(['YES','NO'][f(x1,y1,x2,y2,xp,yp,x,y)<0 or f(x1,y1,x3,y3,xp,yp,x,y)<0 or f(x2,y2,x3,y3,xp,yp,x,y)<0])

Measured memory_bytes: 7416
#include<map>
#include<cmath>
#include<stack>
#include<cstdio>
#include<queue>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int a,b,c,d;
int main(){
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(a+b>c+d)puts("Left");
	else if(a+b==c+d)puts("Balanced");
	else puts("Right");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;using ll=long long;typedef vector<ll> vl;typedef pair<ll, ll> pll;
typedef set<ll> sl;typedef map<ll,ll> mll;typedef vector<pll> vll;
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define endl '\n'
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define sa(v) sort(v.begin(),v.end())
#define sd(v) sort(v.begin(),v.end(),greater<>())
//----------------------------------------------//

int main()
{
    int ts=1;//cin>>ts;
    for(int tss=1;tss<=ts;tss++)
    {
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        ll m=-1000000000000000000;
        m=max(m,max(a,b)*max(c,d));
        m=max(m,min(a,b)*min(c,d));
        m=max(m,max(a,b)*min(c,d));
        m=max(m,min(a,b)*max(c,d));
        cout<<m<<endl;
        return 0;
    }
}
//
//
//
//
//
//
///Struggle goes here....


Measured memory_bytes: 3628
#pragma warning disable
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System;
class E { static void Main() { new J(); } }
class J
{
	void F3() => Console.WriteLine();
	int F() { return int.Parse(Console.ReadLine()); }
	int[] G() { return Console.ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray(); }
	public J()
	{
		Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
		var N = F();
		Console.WriteLine(800 * N - 200 * (N / 15));
		Console.Out.Flush();
	}
	long GCD(long a, long b)
	{
		var n = (ulong)Math.Abs(a); var m = (ulong)Math.Abs(b);
		if (n == 0) return (long)m; if (m == 0) return (long)n;
		int zm = 0, zn = 0;
		while ((n & 1) == 0) { n >>= 1; zn++; }
		while ((m & 1) == 0) { m >>= 1; zm++; }
		while (m != n)
		{
			if (m > n) { m -= n; while ((m & 1) == 0) m >>= 1; }
			else { n -= m; while ((n & 1) == 0) n >>= 1; }
		}
		return (long)n << Math.Min(zm, zn);
	}
}

Measured memory_bytes: 13140
'use strict'

const divisors = n => {
  let dest = []
  for (let i = 1; i < Math.floor(Math.pow(n, 0.5) + 1); i++) {
    if (n % i === 0) {
      dest.push(i)
      if (Math.floor(n / i) !== i) {
        dest.push(Math.floor(n / i))
      }
    }
  }
  return dest.sort((a, b) => a - b)
}

function main(inp) {
  inp = inp.trim().split('\n')
  const N = Number(inp.shift())
  inp = inp[0].split(' ').map(n => Number(n));
  inp.unshift(0)

  let ans = []
  let allBalls = new Array(N+1).fill(0)

  for (let i = N; i > 0; i--) {
    if (inp[i] > 1) return console.log(-1)
    if (allBalls[i] % 2 !== inp[i]) {
      ans.push(i)
      
      let arr = divisors(i)
      for (let j = 0; j < arr.length; j++) {
        allBalls[arr[j]]++
      }
    }
  }
  if (ans.length) {
    console.log(ans.length)
    console.log(ans.reverse().join(' '))
  } else {
    console.log(0)
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 31884
# include <bits/stdc++.h>
# define int long long
# define fi first
# define se second

using namespace std ;

const int N = 1e5 + 1 ;
int v[N], dp[N];

int32_t main() {
    //freopen("haybales.in", "r", stdin ) ;
    //freopen("haybales.out", "w", stdout ) ;
    int t ;
    cin >> t ;
    for( int i = 1 ; i <= t ; i ++ ) {
        cin >> v[i] ;
    }
    dp[2] += abs(v[2] - v[1] ) ;
    for( int i = 3 ; i <= t ; i ++ ) {
        dp[i] = min( abs(v[i]-v[i-1]) + dp[i-1], abs(v[i]-v[i-2]) + dp[i-2] ) ;
    }
    cout << dp[t] << endl;

}



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

int main(){
	int n;cin>>n;
	int odd=0,even=0;
	rep(i,n){
		int a;scanf("%d",&a);
		if(a%2==1)odd++;
		else even++;
	}
	if(odd==0||even==0){
		puts("0");return 0;
	}
	else{
		if(odd%2==0)cout<<n-2<<endl;
		else cout<<n-1<<endl;
	}
}


Measured memory_bytes: 3248
#include<bits/stdc++.h>
using namespace std;
long long a,k[100005],q,r,l;
string n;
int main()
{
	cin>>a>>q>>n;
	for(int s=0;s<a;s++)
	{
		if(n[s]=='A'&&n[s+1]=='C')
		k[s+1]=k[s]+1;
		else k[s+1]=k[s];
	}
	for(int s=0;s<q;s++)
	{
		cin>>r>>l;
		cout<<k[l-1]-k[r-1]<<endl;
	}
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    char a;
    cin >> a;
    if ('a' <= a && a <= 'z')
        cout << "a\n";
    else
        cout << "A\n";
    return 0;
}

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

int main(){
    int n;
    cin>>n;
    vector<int> t(n+1),x(n+1),y(n+1);
    for(int i=1;i<=n;i++) cin>>t[i]>>x[i]>>y[i];

    for(int i=1;i<=n;i++){
        int dt=abs(t[i]-t[i-1]);
        int dx=abs(x[i]-x[i-1]);
        int dy=abs(y[i]-y[i-1]);
        if(dx+dy>dt||(dx+dy)%2!=dt%2){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
using namespace std;





int main() {

	//cout << fixed << setprecision(10);
	int n,t[200000],x[200000],y[200000];
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> t[i] >> x[i] >> y[i];
	}
	for (int i = 1; i <= n; i++) {
		if (t[i] - t[i - 1] < abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1])) {
			cout << "No";
			return 0;
		}
		if (abs(t[i] - t[i - 1] - abs(x[i] - x[i - 1]) - abs(y[i] - y[i - 1]))%2!=0) {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
}


Measured memory_bytes: 2304
import os
import sys

import numpy as np

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

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


# 解説

N, T = list(map(int, sys.stdin.buffer.readline().split()))
A, B = list(zip(*[map(int, sys.stdin.buffer.readline().split()) for _ in range(N)]))

A = np.array(A, dtype=int)
B = np.array(B, dtype=int)

# 移動時間を考えなくて良いようにする
A += 1
B += 1
T += 1

# 使う店を決めたとき、(a - 1) / b の大きい順に使うのが最適
I = np.argsort((A - 1) / B)[::-1]
A = A[I]
B = B[I]

idx_zero = np.searchsorted((A == 1).astype(int), 1, side='left')
A1 = A[:idx_zero]
B1 = B[:idx_zero]
B2 = np.msort(B[idx_zero:])

MAX_COUNT = (10 ** 9).bit_length() + 2
# dp[i][x]: i まで見て、x こ使うときの t の最小値
dp = np.full((idx_zero + 1, MAX_COUNT), T + 1, dtype=int)
dp[:, 0] = 1
for x in range(MAX_COUNT - 1):
    next_col = dp[:-1, x] * A1 + B1
    np.minimum(next_col, T + 1, out=next_col)
    np.minimum.accumulate(next_col, out=next_col)
    dp[1:, x + 1] = next_col

# idx_zero 以降で、B を小さい順に使えるだけ使う
cum = B2.cumsum()
counts = np.searchsorted(cum, T - dp[idx_zero], side='right')
ans = counts + np.arange(dp.shape[1])
print(ans[dp[idx_zero] <= T].max())


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

int main() {
  string s;
  cin>>s;
  sort(s.begin(),s.end());
  if(s[0]=='a' && s[1]=='b' && s[2]=='c') cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
sx,sy,tx,ty = map(int,input().split())
a1 = "U"*(ty-sy) + "R"*(tx-sx)
a2 = "D"*(ty-sy) + "L"*(tx-sx)
a3 = "D"+"R"*(tx-sx+1)+"U"*(ty-sy+1)+"L"
a4 = "U"+"L"*(tx-sx+1)+"D"*(ty-sy+1)+"R"
print(a1+a2+a3+a4)

Measured memory_bytes: 3060
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int swim[n],bug[n],home[n];
    for(int i=0;i<n;i++){
        cin>>swim[i]>>bug[i]>>home[i];
    }
    int dp[n][3];
    dp[n-1][0] = swim[n-1];
    dp[n-1][1] = bug[n-1];
    dp[n-1][2] = home[n-1];
    for(int i=n-2;i>=0;i--){
        dp[i][0] = swim[i] + max(dp[i+1][2],dp[i+1][1]);
        dp[i][1] = bug[i] + max(dp[i+1][0],dp[i+1][2]);
        dp[i][2] = home[i] + max(dp[i+1][1],dp[i+1][0]);
    }
    /*for(int i=0;i<n;i++){
        cout<<dp[i][0]<<" "<<dp[i][1]<<'\n';
    }*/
    cout<<max(dp[0][0],max(dp[0][1],dp[0][2]))<<'\n';
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define bit_count __builtin_popcount
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << '\n';}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
int v[510][510];
void solve() {
	var(int, h, w);
	rep(i, 1, h + 1) {
		rep(j, 1, w + 1) {
			cin >> v[i][j];
		}
	}
	vector<vi> ans;
	rep(i, 1, h) {
		rep(j, 1, w + 1) {
			if (v[i][j] & 1) {
				ans.eb(vi{i, j, i + 1, j});
				++v[i + 1][j];
			}
		}
	}
	rep(j, 1, w) {
		if (v[h][j] & 1) {
			ans.eb(vi{h, j, h, j + 1});
			++v[h][j + 1];
		}
	}
	print(len(ans));
	each(a, ans) {
		print(a[0], a[1], a[2], a[3]);
	}
}
int main() {
	solve();
	return 0;
}


Measured memory_bytes: 10032
#include "bits/stdc++.h"
using namespace std;
template <class T> bool chmax(T &a, const T &b) { return b > a && (a = b, true); }
template <class T> bool chmin(T &a, const T &b) { return b < a && (a = b, true); }

const int MAXN = 1e5;
int N;
vector<long long> p(MAXN), dp1(MAXN), dp2(MAXN), dp3(MAXN);
vector<vector<int>> G(MAXN);

long long res = LLONG_MIN;
void rec(int v, int par) {
    for (const int u: G[v]) if (u != par) rec(u, v);

    dp1[v] = dp2[v] = dp3[v] = p[v];

    vector<long long> best;
    for (const int u: G[v]) {
        if (u == par) continue;
        dp2[v] += max(0LL, dp2[u] - 2);
        best.emplace_back(dp1[u] - 1 - max(0LL, dp2[u] - 2));
    }

    sort(best.begin(), best.end(), greater<>());
    if (best.size() >= 1) chmax(dp1[v], dp2[v] + best[0]);
    if (best.size() >= 2) chmax(dp3[v], dp2[v] + best[0] + best[1]);

    for (const int u: G[v]) {
        if (u == par) continue;
        chmax(dp3[v], dp2[v] - max(0LL, dp2[u] - 2) + dp3[u] - 2);
    }

    chmax(res, dp1[v]);
    chmax(res, dp2[v]);
    chmax(res, dp3[v]);
}

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

    cin >> N;
    for (int i = 0; i < N; ++i) cin >> p[i];
    for (int i = 0; i < N - 1; ++i) {
        int s, t;
        cin >> s >> t;
        s--, t--;
        G[s].emplace_back(t);
        G[t].emplace_back(s);
    }

    rec(0, -1);

    cout << res << "\n";

    return 0;
}



Measured memory_bytes: 24020
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    int ac = 0, wa = 0;

    vector<bool> flag(n, false);
    vector<int> wa_count(n, 0);
    int res_num;
    string result;

    for (int i = 0; i < m; i++)
    {
        cin >> res_num >> result;
        if (flag.at(res_num - 1) == false)
        {
            if (result == "WA")
            {
                wa_count.at(res_num - 1)++;
            }
            else
            {
                wa += wa_count.at(res_num - 1);
                ac++;
                flag.at(res_num - 1) = true;
            }
        }
    }

    cout << ac << " " << wa << endl;
    return 0;
}

Measured memory_bytes: 640
n = int(input())
card = list(map(int,input().split()))
sum = [0]*(n+1)
for i in range(n):
  sum[i+1] = sum[i]+card[i]
miniS = pow(10,20)
for j in range(1,n):
  miniS = min(miniS,abs(sum[n]-2*sum[j]))
print(miniS)

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

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

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

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

	if((a+b)%2 == 0) cout << (a+b)/2 << endl;
	else cout << (a+b)/2+1 << endl;

	return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
typedef vector<int> vec;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
int m,tmp[500010],ts,p[500010],n,ans,now,T,a[500010],b[500010];
LL f[200010][33];
bool cmp(int i,int j){
//	return (a[i]/(a[i]+b[i]+1)>a[j]/(a[j]+b[j]+1));
	return (1ll*a[i]*(a[j]+b[j]+1)>1ll*a[j]*(a[i]+b[i]+1));
}
int main(){
	cin>>n>>T;
	FOR(i,1,n) getint(a[i]),getint(b[i]);
	FOR(i,1,n) p[i]=i;
	sort(p+1,p+n+1,cmp);
	FOR(i,1,n) if (a[p[i]]>0) ++m; else break;
	FOR(i,0,m){
		f[i][0]=0;
		FOR(j,1,30) f[i][j]=T+1;
	}
	FOR(i,0,m-1)
		FOR(j,0,30)
			if (f[i][j]<=T){
				f[i+1][j]=min(f[i+1][j],f[i][j]);
				f[i+1][j+1]=min(f[i+1][j+1],f[i][j]*(a[p[i+1]]+1)+(a[p[i+1]]+b[p[i+1]]+1));
			}
	FOR(i,m+1,n) tmp[++ts]=b[p[i]]+1;
	sort(tmp+1,tmp+ts+1);
	FOR(i,0,30) if (f[m][i]<=T){
		LL t=T-f[m][i];
		int now=i;
		FOR(j,1,ts) if (t>=tmp[j]) t-=tmp[j],++now;
		ans=max(ans,now);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 57600
#include<bits/stdc++.h>
using namespace std;
const int oo = 1e9;
class TaskD {
	int n, m, k, sx, sy, dx, dy;
	vector<vector<int>> d;
	vector<vector<char>> g;
	vector<vector<bool>> v;

public:

	TaskD(int n, int m, int k) {
		this->n = n;
		this->m = m;
		this->k = k;

		g.assign(n, vector<char>(m));
		d.assign(n, vector<int>(m, oo));
		v.assign(n, vector<bool>(m, false));

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

	void init(int sx, int sy, int dx, int dy) {
		this->sx = --sx;
		this->sy = --sy;
		this->dx = --dx;
		this->dy = --dy;
	}

	void solve() {
		queue<pair<int, int>> q;
		q.emplace(sx, sy);
		d[sx][sy] = 0;
		v[sx][sy] = true;

		while(!q.empty()) {
			int x, y;
			tie(x, y) = q.front();
			q.pop();

			for(int i = x - 1, b = 0; b < k and i >= 0 and g[i][y] == '.' and d[i][y] >= d[x][y] + 1; i--, b++) {
				if(!v[i][y]) {
					d[i][y] = d[x][y] + 1;
					v[i][y] = true;
					q.emplace(i, y);
				}
			}

			for(int i = x + 1, b = 0; b < k and i < n and g[i][y] == '.' and d[i][y] >= d[x][y] + 1; i++, b++) {
				if(!v[i][y]) {
					d[i][y] = d[x][y] + 1;
					v[i][y] = true;
					q.emplace(i, y);
				}
			}

			for(int j = y - 1, b = 0; b < k and j >= 0 and g[x][j] == '.' and d[x][j] >= d[x][y] + 1; j--, b++) {
				if(!v[x][j]) {
					d[x][j] = d[x][y] + 1;
					v[x][j] = true;
					q.emplace(x, j);
				}
			}

			for(int j = y + 1, b = 0; b < k and j < m and g[x][j] == '.' and d[x][j] >= d[x][y] + 1; j++, b++) {
				if(!v[x][j]) {
					d[x][j] = d[x][y] + 1;
					v[x][j] = true;
					q.emplace(x, j);
				}
			}
		}

		if(d[dx][dy] == oo) d[dx][dy] = -1;
		cout << d[dx][dy] << '\n';
	}
};
int main(){

	#ifndef ONLINE_JUDGE
	freopen("C:\\Users\\sharr\\Documents\\Input.txt", "r", stdin);
	freopen("C:\\Users\\sharr\\Documents\\Output.txt", "w", stdout);
	#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int n, m, k;
	cin >> n >> m >> k;
	int sx, sy, dx, dy;
	cin >> sx >> sy >> dx >> dy;
	TaskD D(n, m, k);

	D.init(sx, sy, dx, dy);
	D.solve();

}

Measured memory_bytes: 12004
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793238
signed main(){
  double x,y,t,w;
  cin>>x>>y>>t>>w;
  double R=sqrt(x*x+y*y); 
  t*=(2*PI)/360;
  double t1=atan2(y,x),t2=t;
  if(t1<0) t1+=2*PI;
  if(t1>t2) swap(t1,t2);
  double dt=min(t2-t1,t1+2*PI-t2);
  double lb=0,ub=w/360*2*PI*R;
  for(int k=0;k<2000;k++){
    double v=(lb+ub)/2;
    double r=v/(2*PI)*(360/w);
    double e=sqrt(R*R-r*r);
    double th=atan2(e,r);
    if(th<0) th+=2*PI;
    double len=(dt+th)*r;
    if(e<=len) ub=v;
    else lb=v;
  }
  printf("%.12f\n",ub);
  return 0;
}

Measured memory_bytes: 3484
#include <stdio.h>
#define N 100000
 
struct Node{
  int p;
  int left;
  int right;
};
 
struct Node T[N];
int count =0;
int depth(int);
void degree(int);
 
int main(){
  int i,j,n,k,left,right,node,m,c;
   
  scanf("%d",&n);
  for(i=0;i<n;i++) T[i].p = T[i].left = T[i].right = -1;
  for(i=0;i<n;i++){
    scanf("%d%d",&node,&m);
    for(j=0;j<m;j++){
      scanf("%d",&c);
      T[c].p = node;
      if(j!=0) T[left].right = c;
      else T[node].left = c;
      left = c;
    }
  }
   
  for(i=0;i<n;i++){
    count = 0;
    printf("node %d: parent = %d, depth = %d, ",i,T[i].p,depth(i));
    if(T[i].p == -1) printf("root, [");
    else if(T[i].left == -1) printf("leaf, [");
    else  printf("internal node, [");
    count = 0;
    degree(T[i].left);
    printf("]\n");
  }
  return 0;
}
   
int depth(int id){
  if(T[id].p==-1){
 return count;
  }
  else{
    count++;
    return  depth(T[id].p);
  }
}
 
void degree(int id){
  if(id!=-1){
    if(count!=0){
      printf(", ");
    }
    printf("%d",id);
    count++;
    degree(T[id].right);
  }
}

Measured memory_bytes: 3740
n = int(input())
A = [list(map(int,input().split())) for i in range(n-1)]

for i in range(n-1):
    for j in range(2):
        A[i][j] -= 1

M = [[] for i in range(n)]
for i in range(n-1):
    M[A[i][0]].append([A[i][1], i])
    M[A[i][1]].append([A[i][0], i])
    
C = [-1] * n
s = 0
Q = [[0, 0]]
C[0] = 0
while len(Q) > s:
    i = Q[s][0]
    ic = Q[s][1]
    for j in range(len(M[i])):
        if C[M[i][j][0]] == -1:
            C[M[i][j][0]] = ic+1
            Q.append([M[i][j][0], ic+1])

    s += 1
# print(C)
D = []
for i in range(n):
    D.append([C[i], i])
D.sort()
ANS = [0] * (n-1)
NG = [0] * n
# print(D)
for i in range(n):
    c = 1
    v = D[i][1]
    for j in range(len(M[v])):
        if ANS[M[v][j][1]] == 0:
            if NG[v] == c:
                c += 1
            ANS[M[v][j][1]] = c
            NG[M[v][j][0]] = c
            c += 1
# print(ANS)

print(max(ANS))
for i in range(len(ANS)):
    print(ANS[i])

# print(max(C)+1-1)
# for i in range(n-1):
#     print(min(C[A[i][0]], C[A[i][1]]) + 1)

Measured memory_bytes: 119640
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
using namespace std;
map <int ,int> mpa,mpb;
#define MAX 100005
#define NIL -1

struct Node {int p,l,r;};

Node T[MAX];
int n, D[MAX];

void print(int u){
  int i ,c;
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].p << ", ";
  cout << "depth = " << D[u] << ", ";
  if(T[u].p==NIL) cout << "root, ";
  else if(T[u].l==NIL) cout << "leaf, ";
  else cout << "internal node, ";

  cout << "[";
  for(i=0,c=T[u].l;c!=NIL;i++,c=T[c].r){
    if(i) cout << ", ";
    cout << c;
  }
  cout << "]" << endl;
}

int rec(int u,int p){
  D[u]=p;
  if(T[u].r !=NIL) rec(T[u].r,p);//深さを入れてく
  if(T[u].l !=NIL) rec(T[u].l,p+1);
}

int main(){
  int i,j,d,v,c,l,r;
  cin >> n;
  for(i=0;i<n;i++) T[i].p=T[i].l=T[i].r =NIL;//初期化

  for(i=0;i<n;i++){
    cin >> v >> d;
    for(j=0;j<d;j++){
      cin >> c;
      if(j==0) T[v].l=c;
      else T[l].r=c;
      l=c;
      T[c].p=v;
    }
  }
  for(i=0;i<n;i++){
    if(T[i].p==NIL) r=i;
  }
  rec(r,0);
  for(i=0;i<n;i++) print(i);

  return 0;
}


Measured memory_bytes: 7740
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s,h;
  cin>>s>>h; 
  if(s[0]==h[2]&&s[1]==h[1]&&s[2]==h[0]){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
}

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

class dice
{
	public:
		int face[6];
		void rotate(char c);
		void rotw();
		void rots();
		void rotn();
		void rote();
};

void dice::rotate(char c){
	     if(c=='S') rots();
	else if(c=='W') rotw();
	else if(c=='E') rote();
	else if(c=='N') rotn();
}

void dice::rotw(){
	int t[6];
	for(int i=0;i<6;i++) t[i] = face[i];
	t[0] = face[2]; t[2] = face[5]; t[3] = face[0]; t[5] = face[3];
	for(int i=0;i<6;i++) face[i] = t[i];
}
void dice::rots(){
	int t[6];
	for(int i=0;i<6;i++) t[i] = face[i];
	t[0] = face[4]; t[1] = face[0]; t[4] = face[5]; t[5] = face[1];
	for(int i=0;i<6;i++) face[i] = t[i];
}
void dice::rotn(){
	int t[6];
	for(int i=0;i<6;i++) t[i] = face[i];
	t[0] = face[1]; t[1] = face[5]; t[4] = face[0]; t[5] = face[4];
	for(int i=0;i<6;i++) face[i] = t[i];
}
void dice::rote(){
	int t[6];
	for(int i=0;i<6;i++) t[i] = face[i];
	t[0] = face[3]; t[2] = face[0]; t[3] = face[5]; t[5] = face[2];
	for(int i=0;i<6;i++) face[i] = t[i];
}

int main(){
	dice d;
	for(int i=0;i<6;i++) cin >> d.face[i];
	int q;
	cin >> q;
	for(int i=0;i<q;i++){
		int a,b,c;
		cin >> a >> b;
		     if(a==d.face[0]);
		else if(a==d.face[1]) d.rotn();
		else if(a==d.face[2]) d.rotw();
		else if(a==d.face[3]) d.rote();
		else if(a==d.face[4]) d.rots();
		else { d.rotn(); d.rotn(); }
		     if(b==d.face[1]) c = d.face[2];
		else if(b==d.face[2]) c = d.face[4];
		else if(b==d.face[3]) c = d.face[1];
		else                  c = d.face[3];
		cout << c << endl;
	}
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<bits/stdc++.h> 
using namespace std;
const int N = 1e6+3;
#define LL long long
const LL mod = 998244353;
 
struct node
{
	int n,m;
	int id;
	int a,b;
}a[N];
 
 
bool cmp(node a,node b)
{
	if(a.n!=b.n){
		return a.n<b.n;
	}
	return a.m<b.m;
}
bool cmp1(node a,node b)
{
	return a.id<b.id;
}
 
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int k,f;
		scanf("%d%d",&k,&f);
		a[i].n=k;
		a[i].m=f;
		a[i].id=i;
	}
	sort(a+1,a+1+m,cmp);
	int p;
	for(int i=1;i<=m;i++){
		if(a[i].n==a[i-1].n){
			p++;
		}else{
			p=1;
		}
		a[i].a=a[i].n;
		a[i].b=p;
	}
	sort(a+1,a+1+m,cmp1);
	for(int i=1;i<=m;i++)
		printf("%06d%06d\n",a[i].a,a[i].b);
 
	return 0;
}

Measured memory_bytes: 3456
import java.util.Scanner;

/**
 * TITLE : Otoshidama
 * URL : https://atcoder.jp/contests/abc085/tasks/abc085_c
 */
public class Main {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Y = sc.nextInt();
		for (int i = N; i >= 0; i--) {
			if (i * 10000 > Y) continue;
			for (int j = (N - i) * 2; j >= 0; j--) {
				if (i * 10000 + j * 5000 > Y) continue;
				int k = (Y - (i * 10000) - (j * 5000)) / 1000;
				if ((i + j + k) == N && ((i * 10000) + (j * 5000) + (k * 1000)) == Y) {
					System.out.println(i + " " + j + " " + k);
					sc.close();
					return;
				}
			}
		}
		System.out.println("-1 -1 -1");
		sc.close();
	}
}

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

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

 for(int i=0; i<3; i++){
    if(n.at(i)=='9'){
      n.at(i)='1';
    }
    else{
      n.at(i)='9';
    }
 } 

 cout << n << endl;

return 0;  
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
	string s, a = "Yes";
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 0 || i == 0) {
			if (s.at(i) == 'L') {
				a = "No";
				break;
			}
		}
		else if (i % 2 == 1) {
			if (s.at(i) == 'R') {
				a = "No";
				break;
			}
		}
	}
	cout << a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll,int>pii;
//struct _IO { _IO() { ios::sync_with_stdio(0); cin.tie(0); } }_io;
const int maxn=1e5+10;
int a[maxn];
int main(){
	string s;
	cin>>s;
	int l,r;
	for(int i=0;i<s.size();){
		r=i;
		if(s[r]=='R'){
			while(s[r]=='R')  r++;
		}
		l=r;
		if(s[l]=='L'){
			while(s[l]=='L')  l++;
		}
		int c1=r-i,c2=l-r;
		if(~(c1+c2)&1){
			a[r-1]=(c1+c2)/2;
			a[r]=(c1+c2)/2;
		}
		else{
			int k=(c1+c2+1)/2;
			if(c1>c2){
				if(c1&1){
				 a[r-1]=k;
				 a[r]=k-1;
			  }
			  else{
				 a[r-1]=k-1;
				 a[r]=k;
			  }
			}
			else{
		   if(c2&1){
				 a[r-1]=k-1;
				 a[r]=k;
			  }
			  else{
				 a[r-1]=k;
				 a[r]=k-1;
			  }
			}
		}
		i=l;
	}
	for(int i=1;i<=s.size();i++) cout<<a[i-1]<<' ';
}
		

Measured memory_bytes: 4100
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define fast                                                                   \
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define ll long long
#define f(i, n) for (int i = 0; i < n; i++)
#define fo(i,a,n) for (i = a; i <= n; i++)
#define F first
#define S second
#define pii pair<int,int>
#define sz size()
#define all(v) v.begin(),v.end()
#define pb push_back
#define pf push_front    
#define PB pop_back
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<int>
#define mp make_pair
#define mod 1000000007
typedef unsigned long long ull;
const int N = 200005;
const int MOD = 998244353 ;


void solve(){
    int k, n;
    cin>>k>>n;
    int a[n+4];
    f(i,n)cin>>a[i];
    vl v;
    f(i,n-1)v.pb(a[i+1] - a[i]);
    v.pb(k + a[0] - a[n-1]);
    sort(all(v));
    cout<<k - v[v.size() - 1];
}

int32_t main() {
    fast
    int t;
    t = 1;
    //cin >> t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 3956
#include <stdio.h>
const long long int INF=100000000000000000;
int main(){
	int n,m,l,r,c;
	long long int g[110][110];
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)for(int j=0;j<n;j++){
		if(i==j)g[i][j]=0;
		else g[i][j]=INF; 
	}
	while(m--){
		scanf("%d%d%d",&l,&r,&c);
		g[l][r]=c;
	}
	for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++){
		if(g[i][k]==INF||g[k][j]==INF)continue;
	if(g[i][k]+g[k][j]<g[i][j])g[i][j]=g[i][k]+g[k][j];
	}
	for(int i=0;i<n;i++)if(g[i][i]<0){
	printf("NEGATIVE CYCLE\n");
	return 0;
	}
	for(int i=0;i<n;i++){
		if(g[i][0]==INF)printf("INF");
		else printf("%lld",g[i][0]);
		for(int j=1;j<n;j++){
			if(g[i][j]==INF)printf(" INF");
			else printf(" %lld",g[i][j]);
		}
		printf("\n");
	}
}

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

typedef long long ll;
typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
#define rep(i, n) for(int i = 0; i < n; i++)
#define fogg(i,a,b) for(int i = (a); i <= (b); i++)
#define ford(i,a,b) for(int i = (a); i >= (b); i--)
#define test int t; cin >> t; while(t--)
#define debug(x) cout << '>' << #x << ':' << x << "\n";
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair



int main() {
    int n;
    cin >> n;
    long long int h[n];
    rep(i,n){
        cin >> h[i];
    }
    int count =0,ans=0;
    for(int i=n-1;i>0;i--){
        if(h[i]<=h[i-1]){
            count++;
        }
        else{
            ans= max(ans,count);
            count=0;
        }
    }
    ans=max(count,ans);
    cout << ans;

return 0;
}

Measured memory_bytes: 1024
//
// Created by sposa on 19.09.2020.
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
   int arr[100][2];
   int n=0;
    int count = 0;
    scanf("%d",&n);
   for(int i= 0; i <n;i++ ){
       scanf("%d %d",&arr[i][0],&arr[i][1]);
   }

   for(int i = 0; i<n-2; i++){
    if(arr[i][0]==arr[i][1] && arr[i+1][0]==arr[i+1][1] && arr[i+2][0]==arr[i+2][1]){
        printf("Yes");
        return 0;
    }

   }
    printf("No");
    return 0;
}



Measured memory_bytes: 2088
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define RNG(i,from,to) for(ll i=(from); i<(ll)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+
+to_string(p.second)+")"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; } cout << "]"; cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
template<typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; }
template<typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p-2, p); }
const ll DVSR = 1e9+7;
typedef tuple<ll, ll, ll, ll> sc_t;

ll H, W, K;
ll Si, Sj, Gi, Gj;
vector<string> MP;
vector<vector<ll>> RES;
vector<vector<vector<ll>>> RES2;

priority_queue<sc_t, vector<sc_t>, greater<>> PQ;
ll dis[] = {1, 0, -1, 0};
ll djs[] = {0, 1, 0, -1};

void solve() {
  while (PQ.size()) {
    sc_t sc = PQ.top(); PQ.pop();
    ll score = get<0>(sc);
    ll dir = get<1>(sc);
    ll i = get<2>(sc);
    ll j = get<3>(sc);

    RES[i][j] = min(RES[i][j], score);
    if (dir >= 0) RES2[i][j][dir] = min(RES2[i][j][dir], score);
    REP(nd, 4) {
      ll ni = i + dis[nd];
      ll nj = j + djs[nd];
      if (ni >= 0 && ni < H && nj >= 0 && nj < W && MP[ni][nj] == '.') {
        auto next_sc = score;
        if (dir != nd && dir != -1 && (next_sc % K)) {
          next_sc -= (next_sc % K);
          next_sc += K;
        }
        next_sc += 1;

        if (next_sc < RES[ni][nj]) {
          RES[ni][nj] = min(RES[ni][nj], next_sc);
          RES2[ni][nj][nd] = min(RES2[ni][nj][nd], next_sc);
          PQ.push(sc_t(next_sc, nd, ni, nj));
        } else if (next_sc < RES2[ni][nj][nd]) {
          RES2[ni][nj][nd] = min(RES2[ni][nj][nd], next_sc);
          PQ.push(sc_t(next_sc, nd, ni, nj));
        }
      }
    }
  }
}

int main(int argc, char const *argv[])
{
  cin >> H >> W >> K;
  cin >> Si >> Sj >> Gi >> Gj;
  Si--; Sj--; Gi--; Gj--;

  ll INF = 1000000000LL*1000000000LL;
  MP.resize(H);
  RES.assign(H, vector<ll>(W, INF));
  RES2.assign(H, vector<vector<ll>>(W, vector<ll>{ INF, INF, INF, INF }));
  REP(i, H) cin >> MP[i];
  PQ.push(sc_t(0, -1, Si, Sj));
  RES[Si][Sj] = 0;
  solve();  if (RES[Gi][Gj] == INF) {
    cout << -1 << endl;
  } else {
    cout << RES[Gi][Gj]/K + (RES[Gi][Gj]%K > 0) << endl;
  }

  return 0;
}


Measured memory_bytes: 151684
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
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; }
//const ll INF = 1LL << 60;
//const int INF = 1001001001;

int main(void){
    int a,b;
    cin >> a >> b;
    int ans;
    if(max(a,b)>9){
        ans=-1;
    }
    else{
        ans=a*b;
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 3592