akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mood) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mood;
		}
		x = x * x % mood;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

long double getRadian(double x, double y, double x2, double y2) {
	double radian = atan2(y2 - y, x2 - x);
	return radian;
}

int n, m;
vector<int> e[600];
long double dp[610];
long double ans = INF * 1.0;

signed main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int s, t;
		cin >> s >> t;
		e[s].push_back(t);
	}
	dp[n] = 0.0;
	for (int i = n - 1; i >= 1; i--) {
		long double cnt = 0.0;
		for (int j = 0; j < (int)e[i].size(); j++) {
			cnt += dp[e[i][j]];
		}
		dp[i] = cnt / (long double)e[i].size() + 1.0;
	}
	for (int i = 1; i < n; i++) {
		long double cnt = 0.0;
		long double ma = 0.0;
		for (int j = 0; j < (int)e[i].size(); j++) {
			cnt += dp[e[i][j]];
			ma = max(ma, dp[e[i][j]]);
		}
		if (e[i].size() <= 1)dp[i] = cnt + 1.0;
		else dp[i] = (cnt - ma) / ((long double)e[i].size() - 1) + 1.0;
		for (int j = i - 1; j >= 1; j--) {
			cnt = 0.0;
			for (int k = 0; k < (int)e[j].size(); k++) {
				cnt += dp[e[j][k]];
			}
			dp[j] = cnt / (long double)e[j].size() + 1.0;
		}
		ans = min(ans, dp[1]);
	}
	printf("%.10Lf", ans);
}

Measured memory_bytes: 2560
n,m = map(int,input().split())
d = [None]*n
for i in range(n):
    a,b = map(int,input().split())
    d[i] = [a,b]

d.sort(key=lambda x: x[0])

ryoukin = 0
cnt = 0
for lst in d:
    for i in range(lst[1]):
        ryoukin += lst[0]
        cnt += 1
        if cnt == m:
            print(ryoukin)
            exit()

Measured memory_bytes: 57432
package main

import "fmt"

func main(){

	var r int

	fmt.Scan(&r)

	var ans string

	if r < 1200 {
		ans = "ABC"
	} else if r < 2800 {
		ans = "ARC"
	} else {
		ans = "AGC"
	}

	fmt.Println(ans)
}

Measured memory_bytes: 512
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long int 
#define pb push_back
#define vv vector<ll>
#define MAX 105000
#define fr(i,x) for(int i=0;i<x;i++)
int dx[4] = {-1,0,0,1};
int dy[4] = {0,-1,1,0};

bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    
    if(a.first == b.first) return a.second<b.second;
    return (a.first < b.first); 
}
ll ar[MAX];
void divisor(){
    for (int i = 1; i <= MAX; i++)
    {
        for (int j = i; j <= MAX;j+=i)
        {
            ar[j]++;
            
        }
        
        
    }
    
}
int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    
    ll h,n,k,x,c = 0;
    cin >>n;
    string str;
    map<string,ll>m;
    for (int i = 0; i < n; i++)
    {
        cin >> str;
        m[str]++;
        c = max(c,m[str]);
        
    }
    for(auto i:m){
        if(i.second==c){
            cout << i.first << endl;
            
        }
    }
    
    
    
        
}

Measured memory_bytes: 19276
import java.util.Scanner;

public class Main {
  static String str;

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    str = sc.next();
    int n = str.length();
    char s = str.charAt(0), t = str.charAt(n - 1);

    if((n % 2 == 0 && s != t) || (n % 2 == 1 && s == t)){
      System.out.println("Second");
    }
    else{
      System.out.println("First");
    }
  }
}


Measured memory_bytes: 13700
#include <iostream>
#define rep(i,a) for(int i=0;i<a;++i)

using namespace std;

int main(void)
{
	int n;
	while(cin >> n)
	{
		int a[4] = {};
		int count = 0;
		rep(i,10)
		{
			rep(j,10)
			{
				rep(c,10)
				{
					rep(d,10)
					{
						if(i+j+c+d == n)
							++count;
					}
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 0
n=int(input())
s=list(input())

cntw=[0]*n
cnte=[0]*n

if s[0]=="W":
    cntw[0]=1
    cnte[0]=0
else:
    cntw[0]=0
    cnte[0]=1

for i in range(1,n):
    if s[i]=="W":
        cntw[i]=cntw[i-1]+1
        cnte[i]=cnte[i-1]
    else:
        cntw[i]=cntw[i-1]
        cnte[i]=cnte[i-1]+1

nmin=cnte[n-1]-cnte[0]

for i in range(n):
    cntwi=cntw[i-1]    
    cntei=cnte[n-1] -cnte[i]    
    if nmin>cntwi+cntei:
        nmin=cntwi+cntei
print(nmin)        


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

int main() {
	int n; cin >> n;
	deque<int>a;
	for (int i = 0,tmp; i < n; i++) {
		cin >> tmp;
		if (n % 2 == 0) {
			if (i % 2 != 0)a.push_front(tmp);
			else a.push_back(tmp);
		}
		else {
			if (i % 2 == 0)a.push_front(tmp);
			else a.push_back(tmp);
		}
	}
	for (auto&& x : a)cout << x << ' '; cout << endl;

	return 0;
}

Measured memory_bytes: 2944
#include<iostream>
#include<vector>
#include<assert.h>

using namespace std;

int main(void) {
    int i,j,k;
    int n,m;
    cin >> n >> m;
    int a[n][m];
    vector<bool> sp(m, true);
    vector<int> number(m, 0);
    for (i=0; i<n; i++) {
        for (j=0; j<m; j++) {
            cin >> a[i][j];
        }
    }
    int memo;
    int max = n;
    int memoMin = n;

    for (k=0; k<m; k++) {
        if (max < memoMin) {
            memoMin = max;
        }
        for (i=0; i<n; i++) {
            for (j=0; j<m; j++) {
                if (sp[a[i][j] - 1]) {
                    number[a[i][j] - 1]++;
                    break;
                }
            }
        }
        max = 0;
        for (i=0; i<m; i++) {
            if (number[i] > max) {
                max = number[i];
                memo = i;
            }
        }
        sp[memo] = false;
        for (i=0; i<m; i++) {
            number[i] = 0;
        }
    }
    cout << memoMin << endl;
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if (a==1||b==1)
	{
		if (a==1&&b!=1)
		{
			printf("Alice\n");
		}if (b==1&&a!=1)
		{
			printf("Bob\n");
		}if (a==1&&b==1)
		{
			printf("Draw\n");
		}
	}else if (a>b)
	{
		printf("Alice\n");
	}else if (a<b)
	{
		printf("Bob\n");
	}else
	{
		printf("Draw\n");
	}
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int64 a,b,x;
    cin >> a >> b >> x;

    int64 bdiv = b/x + 1;
    int64 adiv = (a==0? 0 : (a-1)/x+1);
    cout << bdiv - adiv << endl;
}

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

using namespace std;

long long n,m,a,b,p,q;

long long mul(long long a,long long b){
  __int128 r=a;
  r*=b;
  if(r>1e18)throw 0;
  return r;
}

int main(){
  cin>>n>>m>>a>>b>>p>>q;
  if(a==1&&b==1){
    long long c=m/(p+q);
    cout<<min(m-min(n,c)*(p+q),llabs(min(n,c+1)*(p+q)-m))<<endl;
  }else{
    long long t[55]={};
    t[0]=p+q;
    long long ak=1,bk=1;
    try{
      for(int i=1;i<min(n,42ll);i++){
	ak=mul(ak,a);
	bk=mul(bk,b);
	t[i]=mul(p,ak)+mul(q,bk);
      }
    }catch(...){
    }
    vector<long long> s(1<<21);
    for(int i=0;i<1<<21;i++){
      long long c=0;
      for(int j=0;j<21;j++){
	c+=(i>>j&1)*t[j+21];
      }
      s[i]=c;
    }
    sort(begin(s),end(s));
    s.erase(unique(begin(s),end(s)),end(s));
    long long ans=1e18;
    for(int i=0;i<1<<21;i++){
      long long c=0;
      for(int j=0;j<21;j++){
	c+=(i>>j&1)*t[j];
      }
      auto it=lower_bound(begin(s),end(s),m-c);
      if(it!=s.end()){
	ans=min(ans,llabs(m-*it-c));
      }
      if(it!=s.begin()){
	it--;
	ans=min(ans,llabs(m-*it-c));
      }
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 17420
#include <iostream>
#include <queue>
#include <cstring>
using namespace std;

struct edge{
    int node;
    edge *next;
}nodes[105];

int n,d[105],v[105];
queue<edge> E;

void bfs(){
    edge *e=E.front().next;
    while(e!=NULL){
        int num=e->node;
        if(v[num]==0){
            v[num]=1;
            d[num]=d[E.front().node]+1;
            E.push(nodes[num]);
        }
        e=e->next;
    }
    E.pop();
}

int main(){
    memset(v,0,sizeof(v));
    memset(d,-1,sizeof(d));
    cin>>n;
    int i,j;
    for(i=1;i<=n;i++){
        int ii,n_i;
        cin>>ii>>n_i;
        nodes[ii].node=ii;
        edge *first=&nodes[ii];
        for(j=0;j<n_i;j++){
            edge *e=new edge();
            cin>>e->node;
            first->next=e;
            first=e;
        }
    }
    d[1]=0;
    v[1]=1;
    E.push(nodes[1]);
    while(E.size()!=0){
        bfs();
    }
    for(i=1;i<=n;i++)cout<<i<<" "<<d[i]<<endl;
    return 0;
}

Measured memory_bytes: 3088
N, K = list(map(int, input().split()))

left = 0
right = 0
A = []
for k in range(0, N+1):
    left += k
    right += N - k
    A.append((right - left + 1) % (10 ** 9 + 7))

# print(A)
print(sum(A[K-1:]) % (10 ** 9 + 7))


Measured memory_bytes: 18636
#include <iostream>

using namespace std;

int main() {
    double v, t, y;
    int n;

    while (cin >> v) {
        t = v /9.8;
        y = 4.9 * t * t;
        n = 0;
        while(5 * n - 5 < y) n++;

        cout << n << endl;
    }

}

Measured memory_bytes: 1224
n = int(input())
a = list(map(int, input().split()))

u, v = [], []
for i in range(0, n, 2):
    u.append(a[i])
for i in range(1, n, 2):
    v.append(a[i])
cu = dict()
for i in u:
    if i in cu:
        cu[i] += 1
    else:
        cu[i] = 1
cv = dict()
for i in v:
    if i in cv:
        cv[i] += 1
    else:
        cv[i] = 1
ua, ub = (sorted(cu.items(), key=lambda x: x[1], reverse=True) + [(-1, 0)])[:2]
va, vb = (sorted(cv.items(), key=lambda x: x[1], reverse=True) + [(-2, 0)])[:2]
if ua[0] == va[0]:
    print(min(len(u) - ua[1] + len(v) - vb[1], len(u) - ub[1] + len(v) - va[1]))
else:
    print(len(u) - ua[1] + len(v) - va[1])

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

int main(void){
    
	int N, K;
    cin >> N >> K;

	vector< int > p( N );
	for ( int &pi : p )
	{
		cin >> pi;
	}

    //P1を求める
    int p1_ksum = accumulate(p.begin(), p.begin()+K, 0) + K;

    int ksum = p1_ksum;
    int sum_max = p1_ksum;
    for(int i=1; i<=N-K; i++){
        ksum = ksum - p[i-1] + p[i+K-1];
        if(ksum > sum_max){
            sum_max = ksum;
        }        
    }

    if(K == 1){
        sum_max = *max_element(p.begin(), p.end()) + K;
    }

    printf("%f\n", (double)sum_max/2.0);

    return 0;
}

Measured memory_bytes: 1024
n = int(input())
h = [0] + list(map(int, input().split())) + [0]
ans = 0
mn, mx = 1000, -1
cnt = 1
for i in range(n + 1):
    if h[i] <= h[i + 1]:
        mn = min(mn, h[i])
        mx = max(mx, h[i + 1])
        cnt += 1
    else: 
        if cnt > 1:
            ans += mx - mn
            mn, mx = 1000, -1
            cnt = 1
print(ans)


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

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define PB push_back
#define MP make_pair
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;

const int maxm = 1e5 + 5;

ll n;
int x, m, s, ans, tot;
int nxt[maxm];
ll sum[maxm];

int main(){
	scanf("%lld%d%d", &n, &x, &m);
	memset(nxt, -1, sizeof(nxt));
	for(s = x; !~nxt[s]; s = 1ll * s * s % m)
		nxt[s] = 1ll * s * s % m;
	for(int t = x; t != s && n; --n, t = nxt[t])
		ans += t;
	if(!n){
		printf("%lld\n", ans);
		return 0;
	}
	sum[1] = s; tot = 1;
	for(int t = nxt[s]; t != s; t = nxt[t]){
		++tot;
		sum[tot] = sum[tot - 1] + t;
	}
	printf("%lld\n", ans + 1ll * sum[tot] * (n / tot) + sum[n % tot]);
	return 0;
}


Measured memory_bytes: 4584
for x in range(4):
    t,n=map(int,input().split())
    
    if t==1:
        print(6000*n)
        
    if t==2:
        print(4000*n)
        
    if t==3:
        print(3000*n)
    
    if t==4:
        print(2000*n)


Measured memory_bytes: 5592
package main

import "fmt"
import "os"
import "io/ioutil"
import "unsafe"
import "strings"
import "math"

func main() {
	input, _ := ioutil.ReadAll(os.Stdin)
	r := strings.NewReader(bstring(input))

	var N, A, B float64
	fmt.Fscanf(r, "%v %v %v", &N, &A, &B)

	plan1 := N * A
	plan2 := B

	fmt.Println(math.Min(plan1, plan2))
}

func bstring(b []byte) string {
	return *(*string)(unsafe.Pointer(&b))
}

Measured memory_bytes: 640
#include <iostream>
#include <cstring>

using namespace std;

int ans, w, h;
int a[20][20];

void search(int pos){
	for(int i=pos;i<=w*h;i++){
		if(i==w*h) { ans++; return; }
		int x = i%w, y = i/w;
		if(a[x][y]!=-1) continue;
		if(x!=0&&y!=0&&a[x-1][y]!=a[x-1][y-1]&&a[x-1][y-1]!=a[x][y-1]) return;
		a[x][y] = i;
		if(y!=h-1&&a[x][y+1]==-1){
			a[x][y+1] = i;
			search(pos+1);
			a[x][y+1] = -1;
		}
		if(x!=w-1&&a[x+1][y]==-1){
			a[x+1][y] = i;
			search(pos+2);
			a[x+1][y]  = -1;
		}
		a[x][y] = -1;
		break;
	}
}

int main(){
	while(cin >> w >> h, w){
		memset(a, -1, sizeof(a));
		ans = 0;
		search(0);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 872
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let s: i64 = read();
    let mut xseq = vec![0 as i64; n];
    let mut pseq = vec![0 as i64; n];
    for i in 0..n {
        xseq[i] = read();
        pseq[i] = read();
    }
    if s < xseq[0] {
        println!("{}", (s - xseq[n - 1]).abs());
        return;
    } else if xseq[n - 1] < s {
        println!("{}", (s - xseq[0]).abs());
        return;
    }
    let mut sums = vec![0 as i64; n];
    for i in 0..n {
        sums[i] = pseq[i];
    }
    let mut left: i32 = 0;
    let mut right: i32 = n as i32 - 1;
    let mut poss: Vec<usize> = vec![];
    loop {
        if s < xseq[left as usize] {
            while left <= right {
                sums[right as usize - 1] = sums[right as usize];
                // println!("win right: {}", right);
                poss.push(right as usize);
                right -= 1;
            }
            break;
        } else if xseq[right as usize] < s {
            while left <= right {
                sums[left as usize + 1] = sums[left as usize];
                // println!("win left: {}", left);
                poss.push(left as usize);
                left += 1;
            }
            break;
        }
        if sums[left as usize] >= sums[right as usize] {
            sums[left as usize] += sums[right as usize];
            // println!("lose right: {}", right);
            poss.push(right as usize);
            right -= 1;
        } else {
            sums[right as usize] += sums[left as usize];
            // println!("lose left: {}", left);
            poss.push(left as usize);
            left += 1;
        }
    }
    // println!("{:?}", poss);
    let mut ans = 0;
    let mut prev = s;
    for &pos in poss.iter().rev() {
        ans += (prev - xseq[pos]).abs();
        prev = xseq[pos];
    }
    println!("{}", ans);
}


Measured memory_bytes: 8444
# Clock Short Hand and Long Hand

n = int(raw_input())

for i in range(n):
    h, m = map(int, raw_input().split(':'))

    h *= 30.0
    h += m * 0.5
    m *= 6.0

    d = abs(m - h)
    if d > 180:
        d = 360 - d

    if 0 <= d < 30:
        print "alert"
    elif 90 <= d <= 180:
        print "safe"
    else:
        print "warning"

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

int main() {
  string line;
  getline(cin, line);
  for (int i = 0; i < line.length(); i++) {
    if (isupper(line[i]))
      cout << (char)tolower(line[i]);
    else
      cout << (char)toupper(line[i]);
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3244
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
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 (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, A, B; cin >> N >> A >> B;
	if (N == 1) {
		if (A == B)cout << 1 << endl;
		else cout << 0 << endl;
	}
	else {
		if (A <= B)cout << 1 + (B - A)*(N - 2) << endl;
		else cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
  int i,all,A,B,C,D;
  long ans,X,sum;
  bool can;
  can=false;
  //  string S,A;
  
  cin>>X;

  ans=0;
  sum=100;
  
  for(;;){
   sum*=1.01;
   ans+=1;
   if(sum>=X){
    break;
   }
  }
  cout<<ans<<endl;
  return 0;
}


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

int main(){
  int N, K;
  cin >> N >> K;
  int x = 1;
  rep(i, N){
    if((x * 2) <= (x + K)){
      x *= 2;
    }else{
      x += K; 
    }
  }
  cout << x << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int dp[105][105];
int a[105][105];
int main(int argc, char** argv) {
	int n,m;
	cin >> n >> m;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			char c;
			cin >> c;
			if(c=='#') a[i][j]=1;
		}
	}
	dp[1][1]=a[1][1];
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(i!=1||j!=1) dp[i][j]=1e9;
			if(i-1) dp[i][j]=dp[i-1][j]+(a[i][j]&&!a[i-1][j]);
			if(j-1) dp[i][j]=min(dp[i][j],dp[i][j-1]+(a[i][j]&&!a[i][j-1]));
		}
	}
	cout << dp[n][m];
	return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)    FOR (i,0,n)
#define ALL(f,x,...) ([&](decltype((x)) ALL) {                          \
            return (f)(begin(ALL), end(ALL), ## __VA_ARGS__); })(x)

using namespace std;

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

    int ans = 1;
    FOR (i, 1, X + 1)
    {
        int b = i * i;
        FOR (j, 2, X + 1)
        {
            if (X < b) break;

            ans = max(ans, b);

            b *= i;
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {

	buf := make([]byte, 1000000)
	sc.Buffer(buf, 1400000000)

	N := inputLineAsNumArray(1)[0]
	spots := inputLineAsNumArray(N)

	spots = append([]int{0}, spots...)
	spots = append(spots, 0)
	// var dirs []bool
	// var diffs []int
	var costs []int
	base := int(math.Abs(float64(spots[0])))
	for i := 0; i < N+1; i++ {
		// if spots[i] < spots[i+1] {
		// 	dirs = append(dirs, true)
		// } else if spots[i] > spots[i+1] {
		// 	dirs = append(dirs, false)
		// } else {
		// 	if i == 0 {
		// 		dirs = append(dirs, true)
		// 	} else {
		// 		dirs = append(dirs, dirs[i-1])
		// 	}
		// }
		costs = append(costs, int(math.Abs(float64(spots[i]-spots[i+1]))))
		base += costs[i]

		// if i > 0 {
		// 	diff := 0
		// 	if dirs[i] != dirs[i-1] {
		// 		diff = int(math.Abs(float64(spots[i]-spots[i-1]))) + int(math.Abs(float64(spots[i]-spots[i+1]))) - int(math.Abs(float64(spots[i+1]-spots[i-1])))
		// 	}
		// 	diffs = append(diffs, diff)
		// }
	}

	for i := 0; i < N; i++ {
		fmt.Println(base + int(math.Abs(float64(spots[i]-spots[i+2]))) - costs[i] - costs[i+1])
	}

}

func inputLineAsNumArray(length int) []int {
	line := strings.Split(readLine(), " ")
	var nums []int
	for i := 0; i < length; i++ {
		num, _ := strconv.Atoi(line[i])
		nums = append(nums, num)
	}
	return nums
}

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


Measured memory_bytes: 9728
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr)
#define digit(N) cout << fixed << setprecision((N))
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
 
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
int H, W, K;
vector<string> grid;
vector<vector<int>> d;
 
void bfs(int sx, int sy)
{
	queue<pair<int, int>> que;
	que.push({sx, sy});
	d[sx][sy] = 0;
 
	while (!que.empty())
	{
		auto v = que.front();
		que.pop();
		int vx = v.first, vy = v.second;
 
		for (int i = 0; i < 4; i++)
		{
			for (int j = 1; j <= K; j++)
			{
				int nx = vx + dx[i] * j, ny = vy + dy[i] * j;
 
				if (nx < 0 || nx >= H || ny < 0 || ny >= W) // grid の外
					break;
 
				if (grid[nx][ny] == '@') // 行き止まり
					break;
 
				if (d[nx][ny] != -1 && d[nx][ny] <= d[vx][vy]) // 行く意味なし
					break;
 
				if (d[nx][ny] != -1) // 最短ではない
					continue;
 
				d[nx][ny] = d[vx][vy] + 1;
				que.push({nx, ny});
			}
		}
	}
}
 
int main()
{
	fast();
 
	cin >> H >> W >> K;
	int sx, sy, gx, gy;
 
	cin >> sx >> sy >> gx >> gy;
	sx--, sy--, gx--, gy--;
	grid = vector<string>(H);
	d = vector<vector<int>>(H, vector<int>(W, -1));
 
	for (int i = 0; i < H; i++)
	{
		cin >> grid[i];
	}
 
	bfs(sx, sy);
 
	cout << d[gx][gy] << "\n";
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

lli dp[101000];

int main(){

	lli n,k;
	cin>>n>>k;
	vector<lli> v;
	v.resize(n+k+10);

	REP(i,0,101000)dp[i]=INF;
	dp[0]=0;

	REP(i,0,n)cin>>v[i];
	REP(i,n,n+k+10)v[i]=INF;

	REP(i,0,n){
		REP(j,1,k+1)dp[i+j] = min(dp[i+j],dp[i] + abs(v[i]-v[i+j]));
	}
	cout<<dp[n-1]<<endl;

    return 0;
}


Measured memory_bytes: 1792
/*
    It is the level of one's commitment that determines the success, far more than the knowledge one possess.
    
    I never lose, I either win or I learn.
                - Competitive Programming

*/

import javax.print.DocFlavor;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

class Item {
    int v;
    int w;
    Item(int a, int b) {
        v = a;
        w = b;
    }
}

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        PrintWriter pw = new PrintWriter(System.out);

        st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int c = Integer.parseInt(st.nextToken());
        long[][] dp = new long[n+1][c+1];

        Item[] it = new Item[n];

        for(int i=0 ; i<n ; i++) {
            st = new StringTokenizer(br.readLine());
            int w = Integer.parseInt(st.nextToken());
            int v = Integer.parseInt(st.nextToken());
            it[i] = new Item(v, w);
        }

        for(int i=1 ; i<=n ; i++) {
            for(int j=1 ; j<=c ; j++) {
                dp[i][j] = dp[i-1][j];
                if(j >= it[i-1].w) {
                    dp[i][j] = Math.max(dp[i][j], dp[i-1][j-it[i-1].w] + it[i-1].v);
                }
            }
        }

        pw.println(dp[n][c]);



        
        
        
        
        
        
        
        pw.flush();
        pw.close();
    }
}


Measured memory_bytes: 126292
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int n;
vector<int> edge[100010];
int a[100010];
int b[100010];
queue<int> q;
int main()
{
	cin >>n;
	for (int i=0;i<n-1;i++)
	{
		int x,y;
		cin >>x>>y;
		edge[x].push_back(y);
		edge[y].push_back(x);
	}
	fill(a+1,a+n+1,-1);
	fill(b+1,b+n+1,-1);
	a[1]=0;
	q.push(1);
	while (!q.empty())
	{
		int x=q.front(); q.pop();
		int t=a[x];
		for (int i=0;i<edge[x].size();i++)
		{
			int xi=edge[x][i];
			if (a[xi]==-1) q.push(xi),a[xi]=t+1;
		}
	}
	b[n]=0;
	q.push(n);
	while (!q.empty())
	{
		int x=q.front(); q.pop();
		int t=b[x];
		for (int i=0;i<edge[x].size();i++)
		{
			int xi=edge[x][i];
			if (b[xi]==-1) q.push(xi),b[xi]=t+1;
		}
	}
	int r1=0,r2=0;
	for (int i=1;i<=n;i++)
	{
		//cout <<a[i]<<" "<<b[i]<<"\n";
		if (a[i]<=b[i]) r1++;
		else r2++;
	}
	if (r1>r2) cout <<"Fennec";
	else cout <<"Snuke";
	return 0;
}

Measured memory_bytes: 6656
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

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

int main(){

  int n;
  vector<int> a(100);
  int alice = 0, bob = 0;
  
  cin >> n;
  
  rep(i, n){
    cin >> a[i];
  }
  
  sort(a.begin(), a.end(), greater<int>());
  
  rep(i, n){
    if(i % 2){
      bob += a[i];
    }
    else{
      alice += a[i];
    }
  }
  
  cout << alice - bob << endl;  
  
  return 0;
}

Measured memory_bytes: 256
from itertools import accumulate


def Li():
    return list(map(int, input().split()))


N = int(input())
A = Li()
A.sort()
Asum = list(accumulate(A))
ans = 0
for i in range(N-1):
    if Asum[i]*2 >= A[i+1]:
        ans += 1
    else:
        ans = 0
print(ans+1)


Measured memory_bytes: 20532
#include<stdio.h>
int main(void)
{
	int m,f,b;
	scanf("%d %d %d",&m,&f,&b);
	if(m>=b){
		printf("0\n");
	}
	else if(m+f<b){
		printf("NA\n");
	}
	else {
		printf("%d\n",b-m);
	}
	return 0;
}
	


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define CEIL(a, b) (a) / (b) + (((a) % (b))?1:0)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 300;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

LL graph[305][305], ngraph[305][305];

void WarshallFloyd(int n) {
    for( int k = 1; k <= n; ++k ) {
        for( int i = 1; i <= n; ++i ) {
            for( int j = 1; j <= n; ++j ) {
                if( graph[i][k] == LINF || graph[k][j] == LINF ) {
                    continue;

                }
                graph[i][j] = min( graph[i][j], 
                                    graph[i][k] + graph[k][j] );

            }
        }
    }
    return;

}

void WarshallFloyd_2(int n) {
    for( int k = 1; k <= n; ++k ) {
        for( int i = 1; i <= n; ++i ) {
            for( int j = 1; j <= n; ++j ) {
                if( ngraph[i][k] == LINF || ngraph[k][j] == LINF ) {
                    continue;

                }
                ngraph[i][j] = min( ngraph[i][j], 
                                    ngraph[i][k] + ngraph[k][j] );

            }
        }
    }
    return;

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

    int n, m, l;
    cin >> n >> m >> l;
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= n; ++j) {
            if(i == j) {
                graph[i][j] = ngraph[i][j] = 0;

            } else {
                graph[i][j] = ngraph[i][j] = LINF;

            }

        }
    }

    while(m--) {
        int a, b;
        LL c;
        cin >> a >> b >> c;
        graph[a][b] = graph[b][a] = c;

    }

    WarshallFloyd(n);
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= n; ++j) {
            if(graph[i][j] <= l) {
                ngraph[i][j] = 1;

            }
        }
    }

    WarshallFloyd_2(n);

    int q;
    cin >> q;
    while(q--) {
        int s, t;
        cin >> s >> t;
        if(ngraph[s][t] == LINF) {
            cout << -1 << endl;

        } else {
            cout << max(ngraph[s][t] - 1, 0ll) << endl;

        }
    }
    return 0;
}



Measured memory_bytes: 2048
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 
 
int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int E[N]={0},W[N]={0};
  for(int i=0;i<N;++i){
    if(S[i]=='E'){
      E[i]=1;
    }
    else{
      W[i]=1;
    }
  }
  for(int i=1;i<N;++i){
      E[i]+=E[i-1];
      W[i]+=W[i-1];
  }
  int ans=3000000;
  int sm=0;
  for(int i=0;i<N;++i){
    sm=0;
    if(i>0) sm+=W[i-1];
    sm+=E[N-1] - E[i];
    ans=min(ans,sm);
  }
  cout << ans;
  }

Measured memory_bytes: 2948
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;

int main(void) {
	string S;
	cin >> S;
	if (S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) {
		cout << "Yes" << "\n";
	} else if (S[0] == S[2] && S[1] == S[3] && S[0] != S[1]) {
		cout << "Yes" << "\n";
	} else if (S[0] == S[3] && S[1] == S[2] && S[0] != S[1]) {
		cout << "Yes" << "\n";
	} else {
		cout << "No" << "\n";
	}
	return 0;
}


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

int main()
{
    long long N,m;
    m = 0;
    cin >> N;
    rep(i,N){
        if((i+1)%5==0){
            continue;
        }else if((i+1)%3==0){
            continue;
        }else{
            m += i + 1;
        }
    }
        cout << m;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n;
 cin >> n;
 int a[n],i;
 for(i=0;i<n;i++)
 cin >> a[i];
 int c=0;
  for(i=1;i<n-1;i++)
  {
      if((a[i]>a[i-1] && a[i]<a[i+1]) || (a[i]<a[i-1] && a[i]>a[i+1]))
      c++;
  }
  cout << c;
  return 0;   
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<utility>
#include<map>
#include<deque>
#include<numeric>
#include<algorithm>
#include<unordered_map>
#include<cmath>
#include<string>

using namespace std;
using ll = long long int;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(1e9 + 7);

int n, m;
vector<vector<int>> node;
vector<int> dp;

int f(int i) {
	int ni_size = node[i].size();
	if (ni_size == 0) {
		dp[i] = 0;
		return 0;
	}
	else {
		if (dp[i] == -1) {
			int tmp = 0;
			for (int j = 0; j < ni_size; j++) {
				tmp = max(tmp, f(node[i][j]) + 1);
			}
			dp[i] = tmp;
			return tmp;
		}
		else
			return dp[i];
	}
}

int main(void) {
	cin >> n >> m;
	dp = vector<int>(n + 1, -1);
	node = vector<vector<int>>(n + 1);
	for (int i = 0; i < m; i++) {
		int xi, yi;
		cin >> xi >> yi;
		node[xi].push_back(yi);
	}

	for (int i = 1; i < n + 1; i++)
		f(i);
	cout << *max_element(dp.begin(), dp.end()) << endl;
	return 0;
}

Measured memory_bytes: 11112
A, B = map(int, input().split())

def XOR(n):
  if n%2 == 0:
    if (n/2)%2 == 0:
      return n ^ 0
    else:
      return n ^ 1
  else:
    if ((n+1)/2)%2 == 0:
      return 0
    else:
      return 1

print(XOR(A-1) ^ XOR(B))

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

using vi = vector<int>;
using vll = vector<long long>;

constexpr long long mod = 1000000007;

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

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

    int n;
    cin >> n;

    vi a(n);
    rep(i, n) cin >> a[i];
    map<int, int> mp;

    rep(i, n){
        mp[a[i]] = 0;
    }

    if(mp.size()%2==0){
        cout << mp.size() - 1 << endl;
    }else{
        cout << mp.size() << endl;
    }

    // rep(i, n){
    //     mp[a[i]]++;
    // }

    // int cnt = 0;

    // for(auto itr=mp.begin(); itr!=mp.end(); ++itr){
    //     if(itr->second>=3){
    //         if(itr->second%2==0){
    //             itr->second = 2;
    //         }else{
    //             itr->second = 1;
    //         }
    //     }

    //     if(itr->second==2){
    //         cnt++;
    //     }
    // }

    // if(cnt%2==0){
    //     cout << mp.size() << endl;
    // }else{
    //     cout << mp.size() - 1 << endl;
    // }

}

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

const int MAXN = 105;
int n, a[MAXN];

int main(){
	scanf("%d", &n);
	
	int cnt = 0;
	for(int i = 0; i < n; i++){
		scanf("%d", &a[i]);
		if(a[i] % 2 == 1 && i % 2 == 0)cnt++;
	}
	printf("%d\n", cnt);
	
	return 0;
}


Measured memory_bytes: 3808
#include<bits/stdc++.h>
using namespace std;
#define LL long long
LL n,m;
int main(){
    cin>>n>>m;
    if((n+m)%3==0||n%3==0||m%3==0) cout<<"Possible";
    else cout<<"Impossible";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <unordered_set>

int main(void) {
  int n;
  std::string s;

  std::cin >> n; /* 1 to 3*10^5 */
  std::cin >> s;

  const char* str = s.c_str();
  size_t min = 3*100000;

  size_t* lcounts = new size_t[n];
  size_t* rcounts = new size_t[n];

  lcounts[0] = 0;
  rcounts[n-1] = 0;
  for (size_t i = 1; i < n; i++) {
    if (str[i-1] == 'W') {
      lcounts[i] = lcounts[i-1] + 1;
    } else {
      lcounts[i] = lcounts[i-1];
    }
    if (str[n-i] == 'E') {
      rcounts[n-1-i] = rcounts[n-i] + 1;
    } else {
      rcounts[n-1-i] = rcounts[n-i];
    }
  }

  for (size_t i = 0; i < n; i++) {
    auto sum = lcounts[i] + rcounts[i];
    if (sum < min) {
      min = sum;
    }
  }


#if 0
  /* w->e | e->w  */
  for (size_t i = 0; i < n; i++) {
    size_t lcount = 0;
    size_t rcount = 0;
    for (size_t j = 0; j < i; j++) {
      if (str[j] == 'W') {
        lcount++;
      }
    }
    for (size_t j = i+1; j < n; j++) {
      if (str[j] == 'E') {
        rcount++;
      }
    }
    auto sum = lcount + rcount;
    if (sum < min) {
      min = sum;
    }
  }
#endif

  std::cout << min << std::endl;;

  return 0;
}

Measured memory_bytes: 5508
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 100000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;

int bucket[N];
int main() {
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int x;
        scanf("%d",&x);
        x++;//向右偏移
        bucket[x]++;
        bucket[x-1]++;
        bucket[x+1]++;
    }

    int maxx=-INF;
    int res=0;
    for(int i=1;i<=1E5+1;i++)
        maxx=max(maxx,bucket[i]);
    
    printf("%d\n",maxx);

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define square(n) ((n)*(n))

double pythag(pll p1, pll p2) {
	ll x1 = p1.X, x2 = p2.X, y1 = p1.Y, y2 = p2.Y;
	return sqrt(square(x2 - x1)+square(y2-y1));
}

pll pos[1011];
ll radius[1011];
double best[1011];



int main() {
	fill(best,best+1011,INFINITY);
	ll xs, ys, xt, yt;
	cin >> xs >> ys >> xt >> yt;
	int N;
	cin >> N;
	// let [0] be start
	// let [N+1] be end
	pos[0] = {xs, ys};
	pos[N+1] = {xt, yt};
	radius[0] = radius[N+1] = 0;
	for (int i = 0; i < N; i++) {
		cin >> pos[i+1].X >> pos[i+1].Y;
		cin >> radius[i+1];
	}

	typedef pair<double, int> pdi;
	priority_queue<pdi, vector<pdi>, greater<pdi> > pq;
	pq.push({0, 0});

	double out;

	while (!pq.empty()) {
		pdi p = pq.top();
		pq.pop();
		//cerr << p.Y << endl;
		//cerr << p.X << " " << best[p.Y] << endl;
		if (p.X >= best[p.Y]) {
			continue;
		}
		if (p.Y == N+1) {
			out = p.X;
			cout << setprecision(19) << fixed;
			cout << out << endl;
			return 0;
		}
		best[p.Y] = p.X;
		for (int i = 0; i <= N+1; i++) {
			if (i == p.Y) {
				continue;
			}
			double dist = max(pythag(pos[i], pos[p.Y]) - radius[p.Y] - radius[i], 0.0);
			pq.push({dist+p.X, i});
		}
	}


	cout << "error" << endl;
	return 1;
}


Measured memory_bytes: 16744
#include <stdio.h>
typedef struct{
	int f1;
	int f2;
	int f3;
	int f4;
	int f5;
	int f6;
	int tmp;
}Dice;
int main(void)
{
	int i;
	Dice D0, D1;
	scanf("%d%d%d%d%d%d", &D0.f1, &D0.f2, &D0.f3, &D0.f4, &D0.f5, &D0.f6);
	scanf("%d%d%d%d%d%d", &D1.f1, &D1.f2, &D1.f3, &D1.f4, &D1.f5, &D1.f6);
	i=0;
	while(D1.f1 != D0.f1){
		D0.tmp = D0.f1;
		i++;
		switch(i%2){
			case 0:
				D0.f1 = D0.f4;
				D0.f4 = D0.f6;
				D0.f6 = D0.f3;
				D0.f3 = D0.tmp;
				break;
			case 1:
				D0.f1 = D0.f2;
				D0.f2 = D0.f6;
				D0.f6 = D0.f5;
				D0.f5 = D0.tmp;
		}
	}
	for(i=0; i<3; i++){
		if(D1.f2 != D0.f2){
			D0.tmp = D0.f2;
			D0.f2 = D0.f3;
			D0.f3 = D0.f5;
			D0.f5 = D0.f4;
			D0.f4 = D0.tmp;
		}
	}
	D1.f3 == D0.f3 && D1.f5 == D0.f5 && D1.f4 == D0.f4 ? puts("Yes") : puts("No");
	return 0;
}

Measured memory_bytes: 580
S = input()
mod = 10 ** 9 + 7
abc = 0
bc = 0
c = 0
q = 0

for i in S[::-1]:
    if i == 'A':
        abc = (bc + abc) % mod
    if i == 'B':
        bc = (c + bc) % mod
    if i == 'C':
        c = (pow(3, q, mod) + c ) % mod
    if i == '?':
        abc = (abc * 3 + bc) % mod
        bc = (bc * 3 + c) % mod
        c = (pow(3, q, mod) + c * 3) % mod
        q += 1
        
print(int(abc))

Measured memory_bytes: 3188
/*"Success isn't permanent, failure isn't fatal,
                                      it's the courage to continue that counts"*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const int mod=1e9+7;         
const int N=2e5+4;

int main()
{
	int a,b,c;

	cin>>a>>b>>c;

	cout<<c<<" "<<a<<" "<<b;
	
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>
#include <queue>
#include <sstream>
#include <iomanip>

using namespace std;
typedef long long ll;

#define PI 3.14159265359

int main()
{
	int A, B, Q;
	cin >> A >> B >> Q;

	ll INF = 1e11;

	vector<ll> As(A);
	vector<ll> Bs(B);
	vector<ll> Qs(Q);

	for (int ai = 0; ai < A; ai++) {
		cin >> As[ai];
	}
	for (int bi = 0; bi < B; bi++) {
		cin >> Bs[bi];
	}
	for (int qi = 0; qi < Q; qi++) {
		cin >> Qs[qi];
	}

	ll ll,rr,lr,q,al,ar,bl,br,ans;

	int ai, bi;
	for (int qi = 0; qi < Q; qi++) {
		q = Qs[qi];
		ai = lower_bound(As.begin(), As.end(), q) - As.begin();
		bi = lower_bound(Bs.begin(), Bs.end(), q) - Bs.begin();
		
		if (ai == 0) {
			al = INF;
		}
		else {
			al = q - As[ai - 1];
		}
		if (bi == 0) {
			bl = INF;
		}
		else {
			bl = q - Bs[bi - 1];
		}


		if (ai == A) {
			ar = INF;
		}
		else {
			ar = As[ai]- q;
		}
		if (bi == B) {
			br = INF;
		}
		else {
			br = Bs[bi] - q;
		}

		ll = max(al, bl);
		rr = max(ar, br);
		lr = min( min(2*al + br , 2*bl + ar), min(2 * ar + bl, 2 * br + al));

		ans = min(min(ll, rr), lr);
		cout << ans << endl;
	}

	//cout << sum;

	return 0;
}



Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];
    int x = 0;
    for(int i = 40; i >= 0; i--){
        int c0 = 0, c1 = 0;
        rep(j, 0, n){
            if(a[j] & (1LL << i)){
                c1++;
            }else{
                c0++;
            }
        }
        if(c0 > c1){
            int tmp = x + (1LL << i);
            if(tmp <= k) x = tmp;
        }
    }
    int ans = 0;
    rep(i, 0, n){
        ans += x ^ a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
typedef long long ll;
using namespace std;
int main()
{
	string a;
	int count = 0;
	cin >> a;
	for (int l = 0; l < 3; l++)
	{
		if (a[l] == '1')
		{
			count++;
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 256
using System;

namespace _1_D
{
    class Program
    {
        static void Main(string[] args)
        {
            int S = Int32.Parse(Console.ReadLine());
            int h = S / 3600;
            int m = S % 3600 / 60;
            int s = S % 60;
            Console.WriteLine(h.ToString() + ":" + m.ToString() + ":" + s.ToString());
        }
    }
}

Measured memory_bytes: 9200
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <cfloat>
#include <utility>
#define norm(X) ((X) * (X))

typedef long long ll;
typedef struct {
	ll x, y;
	ll r;
} Circle;

double cost(int a, int b);
void dijkstra(void);

ll n;
std::vector<Circle> node(1005);
std::vector<double> min_cost(1005, DBL_MAX / 2);

int main()
{
	std::cin >> node[0].x >> node[0].y >> node[1].x >> node[1].y;
	node[0].r = node[1].r = 0;
	std::cin >> n;

	for (int i = 2; i <= n + 1; i++) {
		std::cin >> node[i].x >> node[i].y >> node[i].r;
	}

	dijkstra();

	printf("%.*lf\n", DBL_DIG, min_cost[1]);

	return 0;
}

double cost(int a, int b)
{
	double dist = sqrt(norm(node[a].x - node[b].x) + norm(node[a].y - node[b].y));

	if (dist > node[a].r + node[b].r) {
		return dist - (node[a].r + node[b].r);
	}
	else {
		return 0;
	}
}

void dijkstra(void)
{
	for (int i = 0; i < 1005; i++) {
		min_cost[i] = DBL_MAX / 2;
	}
	
	std::priority_queue<std::pair<double, int>,
		std::vector<std::pair<double, int> >, 
		std::greater<std::pair<double, int> > > p_que;

	p_que.push(std::pair<double, int>(0, 0));
	min_cost[0] = 0;

	while (!p_que.empty()) {
		std::pair<double, int> state = p_que.top(); p_que.pop();

		if (min_cost[state.second] < state.first) {
			continue;
		}

		for (int i = 1; i <= n + 1; i++) {
			if (min_cost[i] > state.first + cost(state.second, i)) {
				min_cost[i] = state.first + cost(state.second, i);

				p_que.push(std::pair<double, int>(min_cost[i], i));
			}
		}
	}

	return;
}


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

int main(){
	int a,b[10000];
	long long sum=0;
	cin>>a;
	for(int i=0;i<a;i++) cin>>b[i];
	for(int j=0;j<a;j++) sum+=b[j];
	sort(b,b+a);
	cout<<b[0]<<' '<<b[a-1]<<' '<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3144
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

vector<int> primes;
bool isPrime[60000];

void erats(){
	fill(isPrime,isPrime+60000,true);
	isPrime[0]=false;
	isPrime[1]=false;
	for(int i = 2; i < 60000; i++){
		if(isPrime[i]){
			primes.push_back(i);
			for(int j = 2*i; j < 60000; j+=i){
				isPrime[j]=false;
			}
		}
	}
}


int main(){

	int n;
	erats();
	while(cin>>n&&n!=0){
		for(int j = n-1; ; j--){
			if(isPrime[j]){
				cout<<j<<" "<<flush;
				break;
			}
		}
		for(int j = n+1; ;j++){
			if(isPrime[j]){
				cout<<j<<endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int N=330;
int n,P,L,T,ans,s1,s2,f[N][N],g[N][N][N];
void chk(int&x){x-=P;x+=(x>>31)&P;}
void work0(){
	f[0][0]=1;L>>=1;
	FOR(i,1,n)FOR(j,0,L){
		chk(f[i][0]+=f[i-1][j]);
		chk(f[i][j+1]+=f[i-1][j]);
	}
	FOR(j,0,L) chk(s1+=f[n>>1][j]),chk(s2+=f[n+1>>1][j]);
	cout<<1ll*s1*s2%P<<'\n';
}
void work1(){
	T=n+(++L)>>1;g[0][0][0]=1;
	FOR(i,1,T)FOR(j,0,L)FOR(k,0,i){
		int w=g[i-1][j][k],x=2*i-1;
		chk(g[i][0][0]+=w);
		if(x>=L) chk(g[i][j?j+1:0][0]+=w);
		if(x<=n) chk(g[i][0][k+1]+=w);
		if(L<=x && x<=n) chk(g[i][max(j+1,k+2)][k+1]+=w);
	}
	FOR(j,0,L)FOR(k,0,n) chk(ans+=g[T][j][k]);
	cout<<ans<<'\n';
}
int main(){
	//freopen("1.in","r",stdin);
	scanf("%d%d%d",&n,&L,&P);
	L%2==0?work0():work1();
}

Measured memory_bytes: 63744