akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
 
class Main {
    public static void main(String[] args) {

    	Scanner sc = new Scanner(System.in);
    	DiceCtrl dc = new DiceCtrl();

    	for(int i = 0; i < 6; i++) {
    		dc.numList[i] = sc.nextInt();
    	}
    	
    	int q = sc.nextInt();
    	int top, front;
    	int[] rightList = new int[q];
    	for(int i = 0; i < q; i++) {
    		top = sc.nextInt();
    		front = sc.nextInt();
    		rightList[i] = dc.getRight(top, front);
    	}
    	
    	for(int i = 0; i < q; i++) {
    		System.out.println(rightList[i]);
    	}
    }
}
class DiceCtrl {
	public int[] numList = new int[6];
	private int tmp = 0;
	
	void ctrlE() {
		tmp = numList[0];
		numList[0] = numList[3];
		numList[3] = numList[5];
		numList[5] = numList[2];
		numList[2] = tmp;
	}
	void ctrlN() {
		tmp = numList[0];
		numList[0] = numList[1];
		numList[1] = numList[5];
		numList[5] = numList[4];
		numList[4] = tmp;
	}
	void ctrlS() {
		tmp = numList[0];
		numList[0] = numList[4];
		numList[4] = numList[5];
		numList[5] = numList[1];
		numList[1] = tmp;
	}
	void ctrlW() {
		tmp = numList[0];
		numList[0] = numList[2];
		numList[2] = numList[5];
		numList[5] = numList[3];
		numList[3] = tmp;
	}
	void ctrlR() {
		tmp = numList[1];
		numList[1] = numList[2];
		numList[2] = numList[4];
		numList[4] = numList[3];
		numList[3] = tmp;
	}
	int getRight(int t, int f) {
		for(int i = 0; i < 3; i++) {
			if(t == numList[0]) {
				break;
			}
			ctrlN();
			if(t == numList[0]) {
				break;
			}
			ctrlW();
		}
		for(int i = 0; i < 3; i++) {
			if(f == numList[1]) {
				break;
			}
			ctrlR();
		}
		return numList[2];
	}
}

Measured memory_bytes: 26364
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,m,x,y = LI()
    a = LI()
    b = LI()
    t = max(a)
    u = min(b)
    for i in range(x+1,y+1):
        if t < i <= u:
            return 'No War'

    return 'War'


print(main())


Measured memory_bytes: 5464
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int v[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;cin>>k;
	cout << v[k - 1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;
int main() {
	vector<long long> data;
	long long n;
	cin >> n;
	for (int i = 0; i < 5; i++) {
		long long temp;
		cin >> temp;
		data.push_back(temp);
	}
	long long min = *min_element(data.begin(), data.end());
	long long amari = n % min == 0 ? n / min : n / min + 1;
	cout << 4 + amari << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100005];
int main()
{
	bool flag=1;
	int t,mx,mn;
	scanf("%d",&t);
	scanf("%d",a+1);
	mx=mn=a[1];
	for(int i=2;i<=t;++i)
	{
		scanf("%d",a+i);
		if(a[i]!=a[i-1]) flag=0;
		mx=max(mx,a[i]);mn=min(mn,a[i]);
	}
	if(mx>mn+1) {puts("No");return 0;}
	int n=0,m=0;
	for(int i=1;i<=t;++i)
	if(a[i]==mx) ++n;
	else ++m;
	if(!flag)
	{
		if(mx-m==0) {puts("No");return 0;}
		if(2*(mx-m)==n) puts("Yes");
		else puts("No");
	}
	else
	{
		if(mx==t-1) {puts("Yes");return 0;}
		if(mx<=t/2) puts("Yes");
		else puts("No");
	}
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
struct island{
	int x, y;
}a[maxn];
int cmp(island a, island b)
{
	return a.y<b.y;	
}
int main()
{
	int n, m;
	cin >> n >> m;
	for(int i=1;i<=m;i++)cin >>a[i].x >> a[i].y;
	int ans=0;
	sort(a+1,a+m+1,cmp);
	int t=0;
	for(int i=1;i<=m;i++)
	{
		if(a[i].x>=t)
		{
			t=a[i].y;
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
use std::cmp::max;

fn main() {
    input! {
        k: i32,
        a: [i64; k]
    }

    let mut res_min: i64 = 2;
    let mut res_max: i64 = 2;

    for i in a.iter().rev() {
        if *i > res_max {
            println!("{}", -1);
            return;
        }
        res_min = (res_min + i - 1) / i * i;
        res_max = (res_max / i) * i + i - 1;
        if res_min > res_max {
            println!("{}", -1);
            return;
        }
    }
    println!("{} {}", res_min, res_max);
}

#[macro_export(local_inner_maccros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[macro_export(lcal_inner_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

#[macro_export(lcal_inner_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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


Measured memory_bytes: 3868
#include<bits/stdc++.h>
using namespace std;
using li = long long int;

int N;
li A[100010];
li Mountain[100010];
li total_vol = 0;     //the total vol of rain
li total_vol_o = 0;  //odd number's total vol

int main(){
    cin >> N;
    for(int i = 1; i <= N; i++){ 
        cin >> A[i]; 
        total_vol += A[i];
        if(i & 1) total_vol_o += A[i];
    }

    Mountain[1] = 2 * total_vol_o - total_vol;

    li neighbour = Mountain[1] / 2;
    cout << Mountain[1] << endl;
    for(int i = 1; i <= N-1; i++){
        Mountain[i+1] = 2 * (A[i] - neighbour);
        cout << Mountain[i+1] << endl;
        neighbour = Mountain[i+1] / 2;
    }
    return 0;
}

Measured memory_bytes: 2816
n,k = map(int,input().split())
s = list(input())
c = 0
a = 0

for i in range(n-1):
	if s[i] == s[i+1]:
		c += 1
	if a < k:
		if s[i] == 'R' and s[i+1] == 'L':
			c += 2
			a += 1
if a < k and a + 2 <= k:
	if s[0] == 'L':
		c += 1
	if s[-1] == 'R':
		c += 1
if a < k and a + 1 >= k:
	if s[0] == 'L' or s[-1] == 'R':
		c += 1
print(min(c,n-1))

Measured memory_bytes: 4084
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n;
int main() {
  cin >> n;
  for (i64 i = 1; i <= n; i <<= 1) {
    if (i == n) {
      cout << "No\n";
      return 0;
    }
  }
  
  vector<pair<i64, i64>> e;

  if (n % 2 == 0) {
    i64 u = 1;
    for (; (u << 1) < n; u <<= 1);
    i64 v = n + ((n & ~u) | 1);
    e.emplace_back(n, u);
    e.emplace_back(n + n, v);
  }

  e.emplace_back(3, n + 1);
  for (i64 i = 2; i < n; i += 2) {
    e.emplace_back(1, i);
    e.emplace_back(i, i + 1);
    e.emplace_back(1, n + i + 1);
    e.emplace_back(n + i + 1, n + i);
  }

  cout << "Yes\n";
  for (auto p : e) {
    cout << p.first << ' ' << p.second << '\n';
  }
  return 0;
}


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

int main(void){
   int N;
   cin>>N;
   vector<long long> L(N);
   for(int i=0;i<N;i++){
      cin>>L[i];
   }
   sort(L.begin(),L.end());
   long long ans=0;
   for(int i=0;i<N;i++){
      for(int j=i+1;j<N;j++){
         for(int k=j+1;k<N;k++){
            if(L[i]!=L[j]&&L[j]!=L[k]&&L[k]!=L[i]&&L[i]+L[j]>L[k]){
               ans++;
            }
         }
      }
      
   }
   cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 3628
#include<stdio.h>
#include<stdlib.h>
#
int n,v,e[100001][3],i,p[10001],r=0;

int c(const void *x,const void *y)
{
	return ((int*)x)[2]-((int*)y)[2];
}

int a(int x)
{
	return p[x]==x?x:a(p[x]);
}

int main()
{
	scanf("%d%d",&n,&v);
	for(i=0;i<=n;i++)
		p[i]=i;
	for(i=0;i<v;i++)
		scanf("%d%d%d",&e[i][0],&e[i][1],&e[i][2]);
	qsort(e,v,sizeof(int[3]),c);
	for(i=0;i<v;i++)
		if(a(e[i][0])!=a(e[i][1]))
		{
			r+=e[i][2];
			p[a(e[i][0])]=p[a(e[i][1])];
		}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 2872
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		String[] s = saori.nextHayami().split("");
		System.out.println(s[0]+s[1]+s[2]);
		
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 37168
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
  ll n;
  cin >> n;
  ll dp[1000000][3];
  rep(i, n) {
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    rep(j, 3) {
      rep(k, 3) {
        if(j != k) {
          dp[i+1][j] = max(dp[i][k]+a[j], dp[i+1][j]);
        }
      }
    }
  }
  cout << max(dp[n][0], max(dp[n][1], dp[n][2]));
}

Measured memory_bytes: 4480
from heapq import heappush, heappop


def dijkstra(N, adj, start=0):
    ans = [float("inf")] * N
    q = [(0, start)]
    while len(q):
        cost, i = heappop(q)
        if ans[i] <= cost:
            continue
        ans[i] = cost
        for nxt in adj[i]:
            if ans[nxt] == float("inf"):
                heappush(q, (cost + adj[i][nxt], nxt))
    return ans


def main():
    n, m, s, t = map(int, input().split())
    adj1 = [{} for _ in range(n)]
    adj2 = [{} for _ in range(n)]
    for _ in range(m):
        u, v, a, b = map(int, input().split())
        adj1[u-1][v-1] = a
        adj1[v-1][u-1] = a
        adj2[u-1][v-1] = b
        adj2[v-1][u-1] = b
    d1 = dijkstra(n, adj1, s-1)
    d2 = dijkstra(n, adj2, t-1)
    ans = [float("inf")] * n
    ans[n-1] = d1[n-1] + d2[n-1]
    for i in range(n-2, -1, -1):
        ans[i] = min(d1[i] + d2[i], ans[i+1])
    for i in range(n):
        print(10**15 - ans[i])


if __name__ == "__main__":
    main()


Measured memory_bytes: 125036
#include<stdio.h>
int main(void)
{
    int m[10],i,j,tmp;
    for(i=0;i<=9;i++){
        scanf("%d",&m[i]);
    }
    for(i=1;i<=9;i++)
    {
        for(j=0;j<=9;j++)
        {
            if(m[j+1]<m[j])
            {
                tmp = m[j];
                m[j] = m[j+1];
                m[j+1] = tmp;
            }
        }
    }
    for(i=9;i>=7;i--)
    {
        printf("%d\n",m[i]);
    }
    return 0;
}

Measured memory_bytes: 600
# coding: utf-8
s=set({})
n=int(input())
a=list(map(int,input().split()))
def check(i,sm):
    if i==n:
        s.add(sm)
        return
    check(i+1,sm+a[i])
    check(i+1,sm)
check(0,0)
input()
for i in map(int,input().split()):
    if i in s:
        print('yes')
    else:
        print('no')



Measured memory_bytes: 5660
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout << #x << ": " << x << endl
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b-c >= 0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	int n, m;
	cin >> n >> m;
	vi v(m); REP(i, m)
	{
		cin >> v[i];
		v[i]--;
	}
	vi b(n), c(n), p(n);
	REP(i, n - 1) cin >> b[i] >> c[i] >> p[i];
	vi s(n);
	REP(i, m - 1)
	{
		int l = v[i], r = v[i + 1];
		if (l > r) swap(l, r);
		s[l]++; s[r]--;
	}
	REP(i, n - 1) s[i + 1] += s[i];
	ll ans = 0;
	REP(i, n - 1) ans += min(s[i] * b[i], p[i] + c[i] * s[i]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6792
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>

using namespace std;

int main() {
	int a, b;

	cin >> a >> b;

	if (a + b >= a * b && a + b >= a - b) {
		cout << a + b;
	}
	else if (a - b >= a + b && a - b >= a * b) {
		cout << a - b;
	}
	else {
		cout << a * b;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;
int main(){
    int n,d,count=0;
    cin >> n >>d;
    for(int i=0;i<n;i++){
        double x=0.0;
        double y=0.0;
        cin >> x >> y;
        double p=0.0,P=0.0;
        p=x*x+y*y;
        P=sqrt(p);
        
        if(P<=d){
            count+=1;
        }
    }
    cout << count;
    

    
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>


typedef long double ld;
typedef long long ll;
using namespace std;
const ll MX=5e6+9;
const ld pi = acos(-1);
const ll mod = 1e9+7;

//bool cmp ( int a,int b ) { return a>b; }

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

ll gcd (  ll a , ll b )
{
    if ( b==0 ) return a;
    else { gcd( b , a%b ); }
}
bool cmp ( int a , int b ) { return (a>b); }
int dx[]={ 0 , 0 , -1 , 1 , 1 , -1 , -1 , 1 };
int dy[]={ 1 , -1 , 0 , 0 , 1 , -1 , 1 , -1 };

int n,a,b;
ll c[MX];
ll dp[MX];

ll solve ( int id )
{
    if ( id>=n-1 ) { return 0; }
    ll &ans = dp[id];
    if ( ans!=-1 ) { return ans; }
    ans = 1e18;
    ans = min ( ans , 1ll*(c[id+1]-c[id])*a+solve ( id+1 ) );
    ans = min ( ans , b+solve( id+1 ) );
    return ans;
}


int main()
{
    memset ( dp , -1 , sizeof(dp) );
    cin>>n>>a>>b;
    for ( int i=0 ; i<n ; i++ ) { scanf ( "%d" , &c[i] ); }
    cout<<solve( 0 );

	return 0;
}


Measured memory_bytes: 43264
// AtCoder Regular Contest 074
// C - Chocolate Bar

#include <cstdio>
#include <algorithm>
#define INF ((ll)1e17)
using namespace std;
typedef long long int ll;


ll hw[2];
ll ans;

int main() {

  ll x, a, b, c;

  scanf("%lld%lld", &hw[0], &hw[1]);

  ans = INF;
  for (int i = 0; i < 2; i++) {
    ans = min(ans, ((hw[0] + 2) / 3 - (hw[0] / 3)) * hw[1]);
    for (int j = 0; j < 2; j++) {
      x = max((hw[0] + j) / 3, (ll)1);
      a = x * hw[1];
      b = (hw[0] - x) * (hw[1] / 2);
      c = (hw[0] - x) * ((hw[1] + 1) / 2);
      ans = min(ans, max(a, max(b, c)) - min(a, min(b, c)));
    }

    swap(hw[0], hw[1]);
  }

  printf("%lld\n", ans);

  return 0;

}




Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define reg register
#define MaxN 405

int N;
long long psum[MaxN], f[MaxN][MaxN];

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N;
	memset(f, 63, sizeof f);
	for(int i = 1; i <= N; ++i)
		cin >> psum[i], psum[i] += psum[i - 1];
	for(int i = 1; i <= N; ++i)
		f[i][i] = 0;
	for(reg int i = 2; i <= N; ++i)
		for(reg int j = 1; j <= N; ++j) {
			int rlim = j + i - 1;
			if(rlim > N) break;
			long long ad = psum[rlim] - psum[j - 1];
			for(reg int k = j; k < rlim; ++k)
				f[j][rlim] = min(f[j][rlim], ad + f[j][k] + f[k + 1][rlim]);
		}
	cout << f[1][N] << endl;
	return 0;
}

Measured memory_bytes: 1536
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    for(int i = 0;i < n;i++)a[i]=sc.nextInt();
    Arrays.sort(a);
    int cnt = 1;
    int ans = 0;
    for(int i =1;i < n;i++)if(a[i]!=a[i-1])cnt++;
    if(cnt%2==1)ans=cnt;
    else ans=cnt-1;
    System.out.println(ans);
  }
}

Measured memory_bytes: 50384
#include <bits/stdc++.h>
#include <atcoder/all>

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

using namespace std;
using namespace atcoder;

using mint=modint998244353;

mint ten[2000001],one[2000001];

using S=pair<mint,int>;
using F=int;
S op(S x,S y){
	return make_pair(x.first*ten[y.second]+y.first,x.second+y.second);
}
S e(){ return make_pair(mint(0),0); }
S mapping(F f,S x){
	if(f==0){
		return x;
	}
	else{
		int len=x.second;
		return make_pair(f*one[len],len);
	}
}
F composition(F f,F g){ return f==0?g:f; }
F id(){ return 0; }

int main(){
	int n,q; scanf("%d%d",&n,&q);

	ten[0]=1;
	one[0]=0;
	rep(i,n){
		ten[i+1]=10*ten[i];
		one[i+1]=10*one[i]+1;
	}

	lazy_segtree<S,op,e,F,mapping,composition,id> ST(n);
	rep(i,n) ST.set(i,make_pair(mint(1),1));

	rep(i,q){
		int l,r,d; scanf("%d%d%d",&l,&r,&d); l--;
		ST.apply(l,r,d);
		printf("%d\n",ST.all_prod().first.val());
	}

	return 0;
}


Measured memory_bytes: 25736
#include<iostream>

using namespace std;

int main(){

  int data[7], n;

  while(1){

    cin >> n;

    if(n == -1) break;
  
    for(int i = 0; i < 7; i++) data[i] = 0;

      
    for(int i = 0; i < n; i++){
      int num, indata[7];
      cin >> num;
      if(num == 0){
	indata[0] = 0;
	indata[1] = 1;
	indata[2] = 1;
	indata[3] = 1;
	indata[4] = 1;
	indata[5] = 1;
	indata[6] = 1;
      }else if(num == 1){
	indata[0] = 0;
	indata[1] = 0;
	indata[2] = 0;
	indata[3] = 0;
	indata[4] = 1;
	indata[5] = 1;
	indata[6] = 0;
      }else if(num == 2){
	indata[0] = 1;
	indata[1] = 0;
	indata[2] = 1;
	indata[3] = 1;
	indata[4] = 0;
	indata[5] = 1;
	indata[6] = 1;
      }else if(num == 3){
	indata[0] = 1;
	indata[1] = 0;
	indata[2] = 0;
	indata[3] = 1;
	indata[4] = 1;
	indata[5] = 1;
	indata[6] = 1;
      }else if(num == 4){
	indata[0] = 1;
	indata[1] = 1;
	indata[2] = 0;
	indata[3] = 0;
	indata[4] = 1;
	indata[5] = 1;
	indata[6] = 0;
      }else if(num == 5){
	indata[0] = 1;
	indata[1] = 1;
	indata[2] = 0;
	indata[3] = 1;
	indata[4] = 1;
	indata[5] = 0;
	indata[6] = 1;
      }else if(num == 6){
	indata[0] = 1;
	indata[1] = 1;
	indata[2] = 1;
	indata[3] = 1;
	indata[4] = 1;
	indata[5] = 0;
	indata[6] = 1;
      }else if(num == 7){
	indata[0] = 0;
	indata[1] = 1;
	indata[2] = 0;
	indata[3] = 0;
	indata[4] = 1;
	indata[5] = 1;
	indata[6] = 1;
      }else if(num == 8){
	indata[0] = 1;
	indata[1] = 1;
	indata[2] = 1;
	indata[3] = 1;
	indata[4] = 1;
	indata[5] = 1;
	indata[6] = 1;
      }else if(num == 9){
	indata[0] = 1;
	indata[1] = 1;
	indata[2] = 0;
	indata[3] = 1;
	indata[4] = 1;
	indata[5] = 1;
	indata[6] = 1;
      }

      for(int j = 0; j < 7; j++){
	if(data[j] == indata[j]){
	  cout << "0";
	}else{
	  cout << "1";

	  if(data[j] == 0) data[j] = 1;
	  else data[j] = 0;
	}
      }
      cout << endl;
    }
  }

  return 0;

}

Measured memory_bytes: 0
import static java.lang.System.out;                                                                                                        
public class Main {
     public static void main(String[] args){
         String str = new java.util.Scanner(System.in).nextLine();
         String[] tmp = str.split(" ");
         int a = Integer.parseInt(tmp[0]);
         int b = Integer.parseInt(tmp[1]);
 
         if (a < b){
             out.println("a < b");
         }         
         else if(a > b){
             out.println("a > b");
         }
         else {
             out.println("a == b");
         }
 
     }
}

Measured memory_bytes: 26328
#include<iostream>
#include<string>

using namespace std;

string str;

int main(){
	cin >> str;
	bool flg = true;

	int count1 = 0;
	int count2 = 0;
	if(str[0] != 'A') flg = false;
	if(str[1] == 'C' || str[str.size() - 1] == 'C') flg = false;
	for(int i = 1; i < str.size(); i++){
		if(str[i] == 'C') count1++;
		if('a' <= str[i] && str[i] <= 'z') count2++;
	}
	if(count1 != 1 || count2 != str.size() - 2) flg = false;

	if(flg){
		cout << "AC" << endl;
	}else{
		cout << "WA" << endl;
	}
	return 0;

}


Measured memory_bytes: 256
import Data.List

main = interact $ unlines . map (show' . uncurry equal_total_scores) . read' . lines
 where
  read' ("0 0":_) = []
  read' (nm:xs) = splitAt n (map read th) : read' xs'
   where
    [n,m] = (map read . words) nm
    (th,xs') = splitAt (n+m) xs
  show' r = case r of {Nothing -> "-1"; Just (t,h) -> show t ++ " " ++ show h} 

equal_total_scores :: [Int] -> [Int] -> Maybe (Int,Int)
equal_total_scores taro hanako = select (sort taro) (sort hanako)
 where
  diff = sum hanako - sum taro
  
  select [] _ = Nothing
  select _ [] = Nothing
  select (t:ts) (h:hs)
   | (h-t)*2 == diff = Just (t,h)
   | (h-t)*2 < diff = select (t:ts) hs
   | (h-t)*2 > diff = select ts (h:hs)

Measured memory_bytes: 4136
import bisect,sys
input = sys.stdin.readline
 
while True :
    n,m = map(int , input().split())
    p = [0]
 
    if (n == 0) : break
     
    for i in range(n):
        pp = int(input())
        p.append(pp)
 
    pt1 = []
    for i,ii in enumerate(p):
        for jj in p[i:]:
            pt1.append(ii+jj)
 
    pt1.sort()
 
    ans = 0
    for i in pt1:
        if (i > m) : break
        amari = m - i
        ans = max(ans , i+ pt1[bisect.bisect_right(pt1,amari)-1])
 
    print(ans)


Measured memory_bytes: 28680
n,m = map(int,input().split())
x = [tuple(map(int,input().split())) for i in range(m)]
f=True
for i in range(0,1001):
    i = str(i)
    if len(i)==n:
        if all([i[t[0]-1]==str(t[1]) for t in x]):
            print(i)
            f=False
            break
if f:
    print(-1)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
char a[10];
int main()
{
	scanf("%s",a);
	int len=strlen(a);
	for(int i=1;i<len;i++)
	{
		if(a[i-1]=='A'&&a[i]=='C')	
		{
			printf("Yes\n");
			return 0;
		}
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 128
// Ver19.02
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int n;
  int maybe = 0;
  scanf("%d", &n);
  for (int i = 0; maybe < n; i++)
  {
    maybe = 0;
    for (int j = 0; maybe < n; j++)
    {
      maybe = 7 * i + 4 * j;
      if (maybe == n)
      {
        puts("Yes");
        return 0;
      }
    }
    maybe = 7 * i;
  }
  puts("No");
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
long long book[200008];
int main()
{
    long long a,n;
    cin>>a>>n;
    long long num=0;
    for(int i=1;i<=n;i++)
    {cin>>book[i];
    num=max(num,book[i]-book[i-1]);
    }
    num=max(num,a-book[n]+book[1]);
        cout<<a-num;
    return 0;
}


Measured memory_bytes: 1792
s = input()
b1 = False
b2 = False

if s[0] == '1':
    b1 = s[1] <= '2'
elif s[0] == '0':
    b1 = s[1] != '0'

if s[2] == '1':
    b2 = s[3] <= '2'
elif s[2] == '0':
    b2 = s[3] != '0'

if b1:
    print("AMBIGUOUS" if b2 else "MMYY")
else:
    print("YYMM" if b2 else "NA")

Measured memory_bytes: 3060
#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
import math
import itertools
from collections import defaultdict
from collections import Counter
import numpy as np

import heapq

s=input()
t=input()
if t[:len(s)]==s:
    print("Yes")

else:
    print("No")

Measured memory_bytes: 27132
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
bool isq(long long q,long long &B){
    bool res =false;
    if(q<0){
        rep2(i,-1000,0){
            if(pow(i,5)==q){
                res=true;
                B=i;
            }
        }
    }else{
        rep(i,1000){
            if(pow(i,5)==q){
                res=true;
                B=i;
            }            
        }
    }
    return res;
}
int main(){
    long long X;
    cin>>X;
    long long A,B;
    //A=1~1000に対して、A^5-Xが5乗数になっているか確認する
    rep(i,1000){
        if(isq(pow(i,5)-X,B)){
            cout << i <<" "<<B<<endl;
            return 0;
        }

    }
    return 0;
}

Measured memory_bytes: 4076
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []
    n = I()
    ni = 0
    d = '0123456789'

    while ni < n:
        ni += 1
        s = S()
        m = S()
        l = len(m)
        for c in s[::-1]:
            if c == 'J':
                m = m[-1] + m[:-1]
            elif c == 'C':
                m = m[1:] + m[0]
            elif c == 'E':
                if l % 2 == 0:
                    m = m[l//2:] + m[:l//2]
                else:
                    m = m[l//2+1:] + m[l//2] + m[:l//2]
            elif c == 'A':
                m = m[::-1]
            elif c == 'P':
                m = ''.join([t if not t in d else d[d.index(t)-1] for t in m])
            elif c == 'M':
                m = ''.join([t if not t in d else d[(d.index(t)+1)%10] for t in m])

        rr.append(m)

    return '\n'.join(map(str, rr))


print(main())




Measured memory_bytes: 9028
// D.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<string>
#include<vector>

using namespace std;
int main()
{
    int k;
    cin >> k;
    vector<int>v(k + 1, 0);
    int cnt = 2;
    int x = 7;
    int y;
    if (x % k == 0) {
        cout << 1 << endl;
        return 0;
    }
    x = x % k;
    v[x] = 1;
    while (1) {

        y = (10*x+7) % k;

        if (y == 0) {
            break;
        }
        if (v[y] == 0) {
            v[y] = 1;
        }
        else {
            cout << -1 << endl;
            return 0;
        }
        x = y;
        cnt++;
        
    }

    cout << cnt << endl;
}


Measured memory_bytes: 7148
using System;
using System.Linq;

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            bool flag = true;
            while (flag)
            {
                char[] input = Console.ReadLine().ToCharArray();
                int[] numbers = (Array.ConvertAll(input, new Converter<char, int>(s => int.Parse(s.ToString()))));

                if (input[0] != '0')
                {
                    Console.WriteLine(numbers.Sum());
                }
                else
                {
                    flag = false;
                }
            }
        }
    }
}

Measured memory_bytes: 9520
// 23:46
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 

int a[100005];
 
int32_t main()
{
    fast;
    int n, x, total = 0, sum = 0; cin >> n >> x;
    Rep(i, 1, n) cin >> a[i];
    Rep(i, 1, n) {
        if(a[i] + a[i-1] > x) {
            total = (a[i] + a[i-1] - x);
            sum += total;
            a[i] -= total;
        }
    }
    cout << sum << "\n"; 
    

    
    
    
    return 0;
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int di2[] = {1, 1, -1, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1};
const int dj2[] = {1, -1, 1, -1, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1, 0, 1, 2, 2};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;


int main(){
  int x; cin >> x;
  int ans = 1;
  for(int b = 2; b <= 100; ++b) {
    for(int p = 2; (int)pow(b, p) <= x; ++p) chmax(ans, (int)pow(b, p));
  }
  cout << ans << endl;
}

Measured memory_bytes: 4064
#include<cstdio>
int h[10000000+5];
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	for(int i=1;i<=999;i++)
		h[i]=h[i-1]+i;
	int s=b-a;
	printf("%d\n",h[s]-b);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
// #include <vector>
// #include <string>
// #include <set>
// #include <algorithm>

using namespace std;
// typedef unsigned long long ull;


bool in_out(int H, int W, int x, int y) {
    return (x >= 0 && x <= W && y >= 0 && y <= H);
}

int main(int argc, char const *argv[]) {
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;

    if (in_out(H, W, x - r, y) && in_out(H, W, x + r, y) && in_out(H, W, x, y - r) && in_out(H, W, x, y + r)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}



Measured memory_bytes: 3108
# AtCoder Beginner Contest 123
# https://atcoder.jp/contests/abc123
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

import math
def main():
    N = i2n()
    ABCDE = ii2nn(5)
    m = min(ABCDE)
    n = int(math.ceil(N / m)) + 4
    print(n)

main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
/*
#include<algorithm>
#include<array>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<typeinfo>
#include<utility>
#include<vector>
*/
#define int long long int
#define double long double
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define REP(i, n) for (int(i) = 0, i##_len = (n); (i) < i##_len; (i)++)
#define REPS(i, x) for (int(i) = 1; (i) <= (int)(x); (i)++)
#define RREP(i, x) for (int(i) = ((int)(x)-1); (i) >= 0; (i)--)
#define RREPS(i, x) for (int(i) = ((int)(x)); (i) > 0; (i)--)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define BIT(n) ((int)(1) << (n))
#define ALL(x) (x).begin(), (x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl
#define nint int

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef pair<int, int> pii;
typedef pair<double, double> dop;
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;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct aaa {
    aaa()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} aaaaaaa;


signed main()
{
    int n;
    cin >> n;
    int sum = 0;
    for (int i = 1; i <= n; i++) {
        int last = n / i;
        sum += last * (i + i * last) / 2;
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 3592
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    
    System.out.println(c +" " + a +" " +b);
}
}


Measured memory_bytes: 20948
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n; cin >> n;
	vector<int> v(n);
	for(int i = 0; i < n; i++)cin >> v[i];
	sort(v.begin(), v.end());
	int ans = v[n/2] - v[n/2 - 1];
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
#include <bitset>

using namespace std;

int main(void)
{
  int zton[10];
  
  while (true) {
    
    int num;
    int l;
    cin >> num >> l;
    
    if (num == 0 && l == 0) break;

    vector<int> v;
    v.push_back(num);
    
    for (int i = 0; i < 20; i++) {
      memset(zton, 0, sizeof(zton));
      num = v[i];
      //cout << "          " << num << endl;
      // count z to n
      for (int j = 0; j < l; j++) {
	zton[num%10]++;
	num /= 10;
      }
      int min, max;
      min = max = 0;
      //create min
      for (int j = 0; j < 10; j++) {
	for (int k = zton[j]; k > 0; k--) {
	  min *= 10;
	  min += j;
	}
      }
      
      //create max
      for (int j = 9; j >= 0; j--) {
	for (int k = zton[j]; k > 0; k--) {
	  max *= 10;
	  max += j;
	}
      }

      //cout << "max " << max << endl;
      //cout << "min " << min << endl;
      
      int dif = max - min;
      //cout << "       "  << dif << endl;
      
      bool flag = false;
      for (int j = 0; j < v.size(); j++) {
	if (dif == v[j]) {
	  cout << j << " " << dif << " " << i-j+1 << endl;
	  flag = true;
	  break;
	}
      }

      if (flag)
	break;
      else
	v.push_back(dif);
    }
    
  }
  return 0;	
}

Measured memory_bytes: 3068
//By Ralif Rakhmatullin
#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<math.h>
#include<cassert>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<ctime>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<bitset>
#include<valarray>
#include<iterator>
#include<list>
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define S second
#define ld long double
#define F first
#define y1 LOL
#define ld long double
#define pb push_back
#define len length
#define sz size
#define beg begin
const ll INF = (ll)1e18 + 123;
const int inf=(int)2e9 + 123; 
const int mod=1e9+7;
using namespace std;
ll n;
ll k;
ll a[100011], sum = 0, diff[100011];
int main(){
	unsigned int FOR;
 	asm("rdtsc" : "=A"(FOR));
  	srand(FOR);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	/*
	d[i] - (k - x) + (n - 1) * x = 0;
	d[i] - k + x + x * (n - 1) = 0;
	d[i] - k + x * n = 0;
	k - d[i] = x * n;       */
	cin >> n;
	for(int i = 1; i <= n; i ++){
		cin >> a[i];
		sum += a[i];
	}
	a[n + 1] = a[1];
	for(int i = 1; i <= n; i ++)
		diff[i] = a[i + 1] - a[i];
	if(sum % (n * (n + 1) / 2) != 0){
		cout << "NO";
		return 0;
	}
	k = sum / (n * (n + 1) / 2);
	for(int i = 1; i <= n; i ++){
		if((k - diff[i]) < 0 || (k - diff[i]) % n > 0){
			cout << "NO";
			return 0;
		}
	}
	cout << "YES";
	return 0;
}

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

int main(){
	int n,k;cin>>n>>k;
	int cnt=0;
	rep(i,n){
		int x;scanf("%d",&x);
		cnt+=min(x,k-x)*2;
	}
	cout<<cnt<<endl;
}

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

long long mod = 998244353;

long long mpow(long long x, long long y){
  if(y==0) return 1;
  
  long long res = mpow(x,y/2);
  res *= res;
  res %= mod;
  if(y%2==1) res *= x;
  res %= mod;
  return res;
}

int main(){
  long long N,S;
  cin >> N >> S;
  vector<long long> A(N);
  for(int i=0;i<N;i++) cin >> A[i];
  
  vector<vector<long long>> dp(N+1,vector<long long>(S+1,-1));
  dp[0][0] = mpow(2,N);
  long long x = mpow(2,mod-2);
  for(int i=0;i<N;i++){
    for(int j=0;j<=S;j++){
      if(dp[i][j]==-1) continue;
      
      if(dp[i+1][j]==-1) dp[i+1][j] = 0;
      dp[i+1][j] += dp[i][j];
      dp[i+1][j] %= mod;
      
      if(j+A[i]>S) continue;
      long long now = dp[i][j] * x;
      now %= mod;
      if(dp[i+1][j+A[i]]==-1) dp[i+1][j+A[i]] = 0;
      dp[i+1][j+A[i]] += now;
      dp[i+1][j+A[i]] %= mod;
    }
  }
  
  if(dp[N][S]==-1) cout << 0 << endl;
  else cout << dp[N][S] << endl;
  return 0;
}


Measured memory_bytes: 73696
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
F = sorted(list(map(int, input().split())), reverse=True)
 
def isEaten(x):
    temp = 0
    for i in range(N):
        t = x // F[i]
        if t < A[i]:
            temp += (A[i] - t)
    return temp <= K
 
 
def bitSearch(r, l):
    m = (r+l) // 2
    if m == l:
        if isEaten(l):
            print(l)
        else:
            print(r)
        exit()
    elif isEaten(m):
        bitSearch(m, l)
    else:
        bitSearch(r, m)
 
 
target = max([A[i]*F[i] for i in range(N)])
bitSearch(target, 0)

Measured memory_bytes: 121292
#include <bits/stdc++.h>
#define INF 99999999
using namespace std;

typedef long long ll;
int n, a, b, c;
int l[8];
int ans = INF;
void dfs(int aa, int bb, int cc, int mp, int t){
	if(t == n){
		if(aa && bb && cc)
			ans = min(ans, mp+abs(a-aa)+abs(b-bb)+abs(c-cc)-30);
		return;
	}
	dfs(aa+l[t], bb, cc, mp+10, t+1);
	dfs(aa, bb+l[t], cc, mp+10, t+1);
	dfs(aa, bb, cc+l[t], mp+10, t+1);
	dfs(aa, bb, cc, mp, t+1);
	return;
}

int main(){
	cin >> n >> a >> b >> c;
	for(int i = 0; i < n; i++)cin >> l[i];
	dfs(0, 0, 0, 0, 0);
	cout << ans << endl;
	return 0;
}

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

int main() {
  long long n;
  cin>>n;
long long ans[n+2]={0};
long long temp;
for(long long i=1;i<=n;i++){
  for(long long j=1;j<=n;j++){if(i*i+j*j>n){
    break;
  }
    for(long long k=1;k<=n;k++){
      temp=i*i+j*j+k*k+i*j+j*k+k*i;
      if(temp>n){
        break;
      }
      ans[temp]++;
    }
  }
}
for(long long i=1;i<=n;i++){
  cout<<ans[i]<<endl;
}
    return 0;
}

Measured memory_bytes: 3480
import java.util.Scanner;
class Main {
  static public void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    if (-40 <= X && 40 >= X) {
      if (X >= 30) {
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }
    }
  }
}


Measured memory_bytes: 35640
#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;

int main(){
  int a[3];

  for(int i = 0;i<3;i++){
    cin>>a[i];
  }
  sort(a,a+3);
  int b[] ={5,5,7};
  for(int i = 0;i<3;i++){
    if(a[i] != b[i]){
      cout<<"NO"<<endl;
      return 0;
    }
  }
  
  cout<<"YES"<<endl;


  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main( void )
{
	int N ;	// num
	int M ;	// kaisuu
	int hito[ 100 ][ 100 ] ;
	int target[100] ;
	int point[100] = {0} ;
	scanf( "%d", &N ) ;
	scanf( "%d", &M ) ;
	for ( int i = 0 ; i < M ; i++ )
	{
		scanf( "%d", &target[ i ] ) ;
	}
	for( int i = 0 ; i < M ; i++ )
	{
		for( int j = 0 ; j < N ; j++ )
		{
			scanf( "%d", &hito[ i ][ j ] ) ;
			if( hito[ i ][ j ] == target[ i ] )
			{
				point[ j ]++ ;
			}
			else
			{
				point[ target[ i ] - 1 ]++ ;
			}
		}
	}
	for( int i = 0 ; i < N ; i++ )
	{
		printf( "%d\n", point[ i ] ) ;
	}
	return 0 ;
}

Measured memory_bytes: 2736
//Depth First Serch
//2019-01-25
//Ebitani Akira

#include <stdio.h>
#include <stdlib.h>

#define N 100
#define AN 128

void DepthSerch(void);
void DepthVisit(int);

int array[AN][AN];
int visit[AN];
int times = 0;
int D[AN], F[AN];
int n;

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

  scanf("%d", &n);
  if(n > N || n < 1){
    printf("頂点の数が適当ではありません。\n");
    exit(1);
  }

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

  DepthSerch();

  return 0;
}

void DepthSerch(void){
  int i;

  for(i = 0 ; i < n ;i++){
    visit[i] = 0;
  }

  for(i = 0 ; i < n ;i++){
    if(visit[i] == 0)
      DepthVisit(i);
  }
  for(i = 1 ; i <= n ;i++){
    printf("%d %d %d\n", i, D[i-1], F[i-1]);
  }
}

void DepthVisit(int a){
  int v;
  
  visit[a] = 1;
  D[a] = ++times;
  
  for(v = 0 ; v < n ; v++){
    if(array[a][v] == 0) continue;
    if(visit[v] == 0){
      DepthVisit(v);
    }
  }
  visit[a] = 2;
  F[a] = ++times;
}



Measured memory_bytes: 2048
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    l = [0] * 87
    l[0] = 2
    l[1] = 1
    for i in range(2, 87):
        l[i] = l[i-1] + l[i-2]
    print(l[n])


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38612
#include <iostream>
#include <algorithm>
using namespace std;
string s, t;
int dp[3100][3100];

int main() {
    cin >> s >> t;
    for (int i = 0; i < s.size(); i++) {
        for (int j = 0; j < t.size(); j++) {
            if (s[i] == t[j]) dp[i+1][j+1] = max(dp[i][j], dp[i][j] + 1);
            dp[i+1][j+1] = max({dp[i+1][j+1], dp[i+1][j], dp[i][j+1]});
        }
    }

    int i = s.size(), j = t.size();
    string ans = "";
    while (i > 0 && j > 0) {
        if (dp[i-1][j] == dp[i][j]) i--;
        else if (dp[i][j-1] == dp[i][j]) j--;
        else { ans = s[i-1] + ans; i--; j--; }
    }
    cout << ans << endl;
}

Measured memory_bytes: 37120
#include <bits/stdc++.h>
using namespace std;
int n, m, t;
int main() {
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
	#endif
	long long D, T, S, ok;
	cin >> D >> T >> S;
	ok = T * S;
	if(D > ok)
		cout << "No\n";
	else
		cout << "Yes\n";
	return 0;
}

Measured memory_bytes: 3588
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int n,m,dp[5][10010];

int dfs(int now,int sy)
{
	if(now>3) return !sy;
	if(dp[now][sy]!=-1) return dp[now][sy];
	int i,res=0;
	for(i=0;i<=min(n,m);i++)
	{
		res+=dfs(now+1,sy-i);
	}
	return dp[now][sy]=res;
}

int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	cout<<(a+b)*c/2;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int x,i;
  i = 1;
  while(1) {
      cin >> x;
      if(x == 0){
          break;
      }else{
          cout << "Case " << i << ": " << x << "\n";
      }
      i+=1;
  }
  return 0;
}



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

int main()
{
  int K,A,B;
  string std = "NG";
  
  cin >> K;
  cin >> A;
  cin >> B;
  
  for(int i = 1; i*K <= B; i++){
    if(i*K >= A && i*K <= B){
      std = "OK";
      break;
    }
  }
  
  cout << std << endl;
}
    
    

Measured memory_bytes: 3584