akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
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;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

int dp[51][51][3000];
signed main() {
    int n,a;
    cin>>n>>a;
    vector<int> x(n);
    REP(i,n) cin>>x[i];

    dp[0][0][0]=1;
    dp[0][1][x[0]]=1;
    REP(i,n-1) {
        REP(j,n) {
            REP(k,3000) {
                if(dp[i][j][k]==0) continue;
                dp[i+1][j+1][k+x[i+1]]+=dp[i][j][k];
                dp[i+1][j][k]+=dp[i][j][k];
            }
        }
    }
    int ans=0;
    REPF(i,1,n+1) {
        REP(j,3000) {
            if(j==a*i) {
                ans+=dp[n-1][i][j];
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 57728
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
using namespace std;

using ll = long long;
const int INF = 1001001001;

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

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

  ll r=0, g=0, b=0;
  rep(i,n) {
    if (s[i] == 'R') {
      r++;
    } else if (s[i] == 'G') {
      g++;
    } else {
      b++;
    }
  }

  ll count = r*g*b;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int k = 2*j - i;
      if (k >= n || k <= j) continue;
      if (s[i] != s[j] && s[j] != s[k] && s[i] != s[k]) {
        count--;
      }
    }
  }

  cout << count << endl;
}


Measured memory_bytes: 3616
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <math.h>

int main (int argc, char const *argv[])
{
    intmax_t N, W[100];
    intmax_t sum = 0, ans = 0;

    scanf("%jd", &N);
    for (size_t i = 0; i < N; i++) {
        scanf("%jd", &W[i]);
        sum += W[i];
    }

    ans = sum;
    intmax_t tmp = 0;
    for (size_t i = 0; i < N; i++) {
        tmp += W[i];
        if (labs(tmp - (sum - tmp)) < ans) ans = labs(tmp - (sum - tmp));
    }

    printf("%jd\n", ans);
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, ans = 0;
  cin >> n;
  vector<int> a(n << 1);
  for ( int i = 0; i < n; ++ i) {
    cin >> a[i << 1] >> a[i << 1|1];
  }
  sort(a.begin(), a.end());
  for ( int i = 0; i < n; ++ i) {
    ans += a[i << 1];
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main(void){ 
    int i; 
    double x[50], q, absnum;  
    
    while(-1)    
    {    
        scanf("%lf", &q);     
        if(q == -1)       
        {  
            return 0;     
         }        
            
            x[0] = q / 2.0;    
            for(i=0; i < 50; i++)     
            {          
                x[i + 1] = x[i] - (pow(x[i], 3) - q) / ( 3*pow(x[i], 2));     
                absnum = fabs(pow(x[i+1], 3) - q);        
                if(absnum < 0.00001*q)     
                {               
                    printf("%lf\n", x[i+1]);    
                    break;         
                }                  
                
                if(absnum < 0.00001*q)       
                {               
                    break;         
                }     
            }      
    }  

        return 0;   
}




Measured memory_bytes: 2032
o = input()
e = input()

ans = ""
if len(o) == len(e):
    for i in range(len(o)):
        ans += o[i]
        ans += e[i]
else:
    for i in range(len(e)):
        ans += o[i]
        ans += e[i]
    ans += o[-1]
print(ans)



Measured memory_bytes: 3060
#include<iostream>
using namespace std;
bool a[105];
int main(void)
{
    string s[105];
    int h,w;
    cin >> h >> w;
    for(int i=0;i<h;i++)
        cin >> s[i];
    for(int i=0;i<w;i++)
    {
        int cnt=0;
        for(int j=0;j<h;j++)
            if(s[j][i]=='.')
                cnt++;
        if(cnt==h) a[i]=false;
        else a[i]=true;
    }
    for(int i=0;i<h;i++)
        if(s[i].find('#')<(int)s[i].size())
        {
            for(int j=0;j<w;j++)
            {
                if(s[i][j]=='#')
                    cout << s[i][j];
                else if(s[i][j]=='.' && a[j]==true)
                    cout << s[i][j];
            }
            cout << endl;
        }
    return 0;
}

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



int main(){
  int64_t N,M;
  cin>>N>>M;
  
  vector<int64_t> X(M);
  for(int i=0;i<M;i++){
    cin>>X.at(i);
  }
  sort(X.begin(),X.end());
  vector<int64_t> dis(M-1);
  for(int i=1;i<M;i++){
    dis.at(i-1)=X.at(i)-X.at(i-1);
  }
  sort(dis.begin(),dis.end());

  int64_t sum=0;
  for(int i=0;i<M-N;i++){
    sum+=dis.at(i);
  }
  cout<<sum<<endl;
    
    
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> a(N);
  rep(i, M)
  {
    int k;
    cin >> k;
    rep(j, k)
    {
      int s;
      cin >> s;
      s--;
      a[s] |= 1 << i; // | := or (ex) i = 2, s = 1 , a[1] = 000 , 1<<2 = 100
      // 繋がっているスイッチの番号
    }
  }
  int ans = 0;
  int p = 0;
  rep(i, M)
  {
    int x;
    cin >> x;
    p |= x << i;  // pの入力例 1 0 1  p=101
  }
  for (int l = 0; l < (1 << N) /* := 2^N スイッチon off状態全通り*/; l++)
  {
    int t = 0;
    rep(i, N)
    {
      if (l >> i & 1) // l = 110(6), i=2  110>>2  => 1&(AND(*))1 = 1
      {
        t ^= a[i]; // t xor a[i] ここでスイッチのつけ消し
      }
    }
    if (t == p)
    {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
string s,t;
int dp[3010][3010];

int main(){
	cin>>s>>t;
	for(int i=1;i<=s.length();i++){
		for(int j=1;j<=t.length();j++){
			if(s[i-1]==t[j-1]){
				dp[i][j]=1+dp[i-1][j-1];
			}
			else{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	
	int i=s.length(),j=t.length();
	string ans="";
	//cout<<dp[i][j];

	while(true){
		if(dp[i][j]>max(dp[i-1][j],dp[i][j-1])){
			ans.push_back(s[i-1]);
			i--,j--;
		}
		else if(i>0&&dp[i][j]==dp[i-1][j]){
			i--;
		}
		else if(j>0&&dp[i][j]==dp[i][j-1]){
			j--;
		}
		if(i==0||j==0)break;


	}
	reverse(ans.begin(),ans.end());
	cout<<ans;


}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n = in();
  set<string> st;
  char p;
  bool ok = true;
  rep(i,n) {
    string w;
    cin >> w;
    st.insert(w);
    if (i >= 1 && w.front() != p) {
      ok = false;
    }
    p = w.back();
  }
  if (st.size() < n) ok = false;
  if (ok) yn;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

struct UnionFind {
public:
  vector<ll> par; 
  vector<ll> siz; 

    
  UnionFind(ll sz_): par(sz_), siz(sz_, 1) {
    for (ll i = 0; i < sz_; ++i) par[i] = i; 
  }
  void init(ll sz_) {
    par.resize(sz_);
    siz.resize(sz_, 1);
    for (ll i = 0; i < sz_; ++i) par[i] = i;
  }

  ll root(ll x) { 
    while (par[x] != x) {
      x = par[x] = par[par[x]];
    }
    return x;
  }

  bool merge(ll x, ll y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (siz[x] < siz[y]) swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
  }

  bool issame(ll x, ll y) {
    return root(x) == root(y);
  }

  ll size(ll x) {
    return siz[root(x)];
  }
};

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(m), b(m);
  rep(i, m) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
  }

  vector<ll> ans(m);
  ll res = n * (n - 1) / 2;
  UnionFind uf(n);
  uf.init(n);
  repr(i, m - 1) {
    ans[i] = res;
    if (!uf.issame(a[i], b[i])) {
      res -= uf.size(a[i]) * uf.size(b[i]);
      uf.merge(a[i], b[i]);
    }
  }
  rep(i, m) cout << ans[i] << endl;




  
  return 0;
}

Measured memory_bytes: 5248
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


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


def ZIP(n): return zip(*(MAP() for _ in range(n)))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N, M = MAP()
    AB = [LIST() for _ in range(M)]

    conn = [[] for _ in range(N)]
    for x, y in AB:
        conn[y-1].append(x-1)
        conn[x-1].append(y-1)

    # print(conn)

    queue = deque([0])
    ans = [0] * N
    while queue:
        ind = queue.popleft()
        # print(ind)
        for x in conn[ind]:
            if ans[x] < 1:
                ans[x] = ind + 1
                queue.append(x)

    print("Yes")
    for x in ans[1:]:
        print(x)


if __name__ == '__main__':
    main()


Measured memory_bytes: 75160
import java.util.*;

public class Main {
  static int[] par;
  static int[] rank;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    par = new int[n + 1];
    rank = new int[n + 1];

    int[] f = new int[n + 1];
    init(n + 1);
    for(int i = 0; i < m; i++) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      f[a]++;
      f[b]++;
      unite(a, b);
    }

    int[] num = new int[n + 1];

    for(int i = 1; i <= n; i++) {
      num[find(i)]++;
    }


    int answer = 0;
    for(int i = 1; i < n + 1; i++) {
      answer = Math.max(answer, num[i]);
    }
    System.out.println(answer);
  }
  static void init(int m) {
    for(int i = 0; i < m; i++) {
      par[i] = i;
      rank[i] = 1;
    }
  }
  static int find(int x) {
    if(par[x] == x) {
      return x;
    } else {
      return par[x] = find(par[x]);
    }
  }
  static void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x != y) {
      if(rank[x] < rank[y]) {
        par[x] = y;
        rank[y] += rank[x];
      } else {
        if(rank[x] == rank[y]) {
          if(x > y) {
            par[x] = y;
            rank[y] += rank[x];
          } else {
            par[y] = x;
            rank[x] += rank[y];
          }
        } else {
          par[y] = x;
          rank[x] += rank[y];
        }
      }
    }
  }
  static boolean same(int x, int y) {
    return find(x) == find(y);
  }
}

Measured memory_bytes: 61860
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        r: f64
    }

    println!("{}", r * 2.0 * std::f64::consts::PI);
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


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

int MOD(int a){
	return (a %= p) >= 0 ? a : a + p;
}

signed main(){
	int N, i;
	scanf("%lld", &N);
	string S;
	cin >> S;
	vector<int> A(3 * N);
	for(i = 0; i < 3 * N; i++){
		if(S[i] == 'R'){
			A[i] = 0;
		}
		else if(S[i] == 'G'){
			A[i] = 1;
		}
		else{
			A[i] = 2;
		}
	}
	vector<int> now(8);
	vector<int> C(3 * N);
	int ans = 1;
	for(i = 0; i < 3 * N; i++){
		if(now[7 - (1 << A[i])] > 0){
			ans = MOD(ans * now[7 - (1 << A[i])]);
			now[7 - (1 << A[i])]--;
			C[i] = 1;
		}
		else if(A[i] == 0){
			if(now[2] > 0){
				ans = MOD(ans * now[2]);
				now[2]--;
				now[2 + 1]++;
				C[i] = 0;
			}
			else if(now[4] > 0){
				ans = MOD(ans * now[4]);
				now[4]--;
				now[4 + 1]++;
				C[i] = 0;
			}
			else{
				now[1]++;
				C[i] = -1;
			}
		}
		else if(A[i] == 1){
			if(now[1] > 0){
				ans = MOD(ans * now[1]);
				now[1]--;
				now[1 + 2]++;
				C[i] = 0;
			}
			else if(now[4] > 0){
				ans = MOD(ans * now[4]);
				now[4]--;
				now[4 + 2]++;
				C[i] = 0;
			}
			else{
				now[2]++;
				C[i] = -1;
			}
		}
		else{
			if(now[1] > 0){
				ans = MOD(ans * now[1]);
				now[1]--;
				now[1 + 4]++;
				C[i] = 0;
			}
			else if(now[2] > 0){
				ans = MOD(ans * now[2]);
				now[2]--;
				now[2 + 4]++;
				C[i] = 0;
			}
			else{
				now[4]++;
				C[i] = -1;
			}
		}
	}
	int fact = 1;
	for(i = 1; i <= N; i++){
		fact = MOD(fact * i);
	}
	printf("%lld\n", MOD(ans * fact));
	return 0;
}

Measured memory_bytes: 5380
w,h,x,y=map(int,input().split())

if w<h:
    tmp1=w
    tmp2=x
    w=h
    h=tmp1
    x=y
    y=tmp2
if x>w/2:
    x=w-x
if y>h/2:
    y=h-y
a=x*h
b=w*y

if y==0 or x/y>w/h:
    print(h*w/2,0)
elif a!=b :
    print(max(a,b),0)
else:
    print(max(a,b),1)


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	private static Scanner sc;

	public static void main(String[] args) {

		sc = new Scanner(System.in);
		String str = sc.next();
		int len = str.length();
		int midLen = len -2;

		System.out.print(str.substring(0,1) + midLen + str.substring(len-1,len));
	}

}


Measured memory_bytes: 21844
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define endl "\n"
#define fcout cout<<fixed<<setprecision(15)
typedef pair<int, int> P;
//struct edge { int to, cost; };

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

bool prime(int n) {
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0)return false;
    }
    return n != 1;
}
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;
}
int mod_pow(int n, int p, int m) {
    if (p == 0) return 1;
    if (p % 2 == 0) {
        int t = mod_pow(n, p / 2, m);
        return (t * t) % m;
    }
    return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}
int modinv(int a, int m) {
    int b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int modinv2(int a, int mod) {
    return mod_pow(a, mod - 2, mod);
}
int digit(int x) {
    int cnt = 0;
    while (x > 0) {
        cnt += x % 10;
        x /= 10;
    }
    return cnt;
}
int read() {
    int tmp;
    cin >> tmp;
    return tmp;
}
int xor128() {
    static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    int t = (x xor (x << 11));
    x = y; y = z; z = w;
    return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
    map<int, int>ans;
    int now = 2;
    while (now * now <= x) {
        if (x % now == 0) {
            x /= now;
            ans[now]++;
        }
        else now++;
    }
    if (x != 1) ans[x]++;
    return ans;
}
int comb(int n, int k, int mod) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    k = min(k, n - k);
    int x = 1, y = 1;
    rep(i, k) {
        y *= i + 1;
        y %= mod;
    }
    for (int i = n - k + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }
    return x * modinv(y, mod) % mod;
}
signed main() {
    //srand((unsigned)time(NULL));

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

    
    int n, m;
    cin >> n >> m;
    int ki = (m + 1) / 2;
    int gu = m / 2;
    int allcnt = 0;
    int cnt = 1;
    for (int i = ki; i >= 1; i--) {
        cout << i << " " << i + cnt << endl;
        cnt += 2;
        allcnt++;
        if (allcnt == m) return 0;
    }
    cnt -= 2;
    cnt++;
    int a = 2;
    for (int i = cnt + gu; i >= cnt; i--) {
        cout << i << " " << i + a << endl;
        a += 2;
        allcnt++;
        if (allcnt == m) return 0;
    }

    return 0;
}


Measured memory_bytes: 3676
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
    static void Main()
    {
        SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";


    void solve()
    {
        WriteLine(Math.Max(cin.nextint * cin.nextint, cin.nextint * cin.nextint));
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 2776
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 2e5+10;

vector<ll> depth(n_max,-1);

void dfs( vvl &graph, ll pos, ll pre){
    for(auto to : graph[pos]){
        if(to != pre){
            depth[to] = depth[pos] + 1;
            dfs(graph, to, pos);
        }
    }
}

template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}

int main(){
    ll n; cin >> n;
    vector<vector<ll>> graph(n);
    rep(i,n-1){
        ll a,b; cin >> a >> b;
        a--;b--;
        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }
    depth[0] = 0;
    dfs(graph, 0, -1);
    Pll m = {-1,-1};
    rep(i,n){
        chmax(m, {depth[i],i});
    }
    depth.assign(n,-1);
    depth[m.second] = 0;
    dfs(graph, m.second, -1);
    ll leng = 0;
    rep(i,n)chmax(leng, depth[i]);
    cout << (leng % 3 == 1 ? "Second" : "First") << endl;
}

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

int min(int a,int b)
{
  return (a<b?a:b);
}

int min(int a,int b,int c)
{
  return(a<min(b,c)?a:min(b,c));
}
int main()
{
  int p,q,r;
  cin>>p>>q>>r;
  
  cout<<min(p+q,q+r,r+p);
  
 return 0; 
}

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

int dp[51][51][2501];
//i枚目までのカードでj枚選んで合計がkになる組み合わせ

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

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

  dp[0][0][0] = 1;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      for(int k = 0; k < 2501; k++){
        //カードを使わない場合
        dp[i+1][j][k] += dp[i][j][k];
        //カードを使う場合
        dp[i+1][j+1][k + x[i]] += dp[i][j][k];
      }
    }
  }

  int ans = 0;
  for(int j = 1; j <= n; j++){
    ans += dp[n][j][j * a];
  }
  cout << ans << endl;

  return 0;
}


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

class RangeIndex {
public:
	RangeIndex(int n) {
		m_indexes.resize(n);
		for (auto &row : m_indexes) {
			row.resize(n, 0);
		}
	}
	int getTrainsNum(const int p, const int q) {
		return m_indexes[p - 1][q - 1];
	}
	void addTrain(const int l, const int r) {
		for (int i = 0; i <= (l - 1); ++i) {
			for (int j = (r - 1); j < static_cast<int>(m_indexes.size()); ++j) {
				++m_indexes[i][j];
			}
		}
	}
private:
	std::vector<std::vector<int>> m_indexes;
};

int main() {
	int n, m, q;
	std::cin >> n >> m >> q;
	RangeIndex index(n);
	for (int i = 0; i < m; ++i) {
		int l, r;
		std::cin >> l >> r;
		index.addTrain(l, r);
	}
	for (int i = 0; i < q; ++i) {
		int l, r;
		std::cin >> l >> r;
		std::cout << index.getTrainsNum(l, r) << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1920
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sA = sum(a)
sB = sum(b)

# Ai ≤ Bi: Ai++ができるので，問題なし
#  - このとき (Bi - Ai) // 2回数は j として選んでOK
#
# Ai > Bi: i以外を選んで，Biを嵩上げする必要がある
# - 選んだjは A[j] + 2 ≤ B[j] が必要
# - Biは1ずつしか増えないので，これは-d回必要
#


diff = [b[i] - a[i] for i in range(n)]
count = 0
for d in diff:
    if d > 0: # Ai ≤ Bi
        count += d // 2  # 余る分
    else:     # Ai ≥ Bi
        count -= -d      # 嵩上げ

# 余る分が多ければ，嵩上げできる
if count >= 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 40688
import java.util.Scanner;

public class Main {
    public static void main(String[] ar) {
        Scanner sc = new Scanner(System.in);
        for (; ; ) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            if (a == 0 && b == 0)
                break;
            if(a>b) {
                int c=b;
                b=a;
                a=c;

            }
            System.out.println(a+" "+b);
            }
        }
    }


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

int n, q, m, a[20];

bool solve(int i, int m){
    if(m == 0) return true;
    if(i == n) return false;

    bool res = solve(i + 1, m) || solve(i + 1, m - a[i]);
    return res;
}

int main(){

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

    while(q--){
        cin >> m;
        cout << (solve(0, m) ? "yes" : "no") << endl;
    }
}


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

using namespace std;

int main(){
	int n;
	bool ans = 1;
	cin >> n;
	while(n--){
		int tmp; cin >> tmp;
		if(tmp%2==0){
			if((tmp%3)&&(tmp%5))ans = 0;
		}
	}
	if(ans)cout << "APPROVED\n";
	else cout << "DENIED\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<class F>auto recursive(F f){return[f](auto...a){return f(f,a...);};}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int p;fixprec(int p):p(p){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.p);}

struct Paren {
    // l: 括弧レベルの下限, p: 括弧レベルの増減
    int l, p;
    bool operator<(const Paren &x) const {
        int sgn = (p > 0) - (p < 0);
        int sgn_x = (x.p > 0) - (x.p < 0);
        if(sgn != sgn_x) return sgn > sgn_x;
        else {
            if(sgn >= 0) return l > x.l; // 行きはlの大きい順に選んでいく
            if(sgn < 0) {
                int m = l - p, m_x = x.l - x.p;
                if(m != m_x) return m < m_x;
                else return p > x.p;
            }
        }
    }
};

int main() {
    int N;
    cin >> N;
    vector<Paren> paren(N);
    int S = 0;
    for(int i = 0; i < N; i++) {
        string s;
        cin >> s;
        int l = 0, p = 0;
        for(char c : s) {
            p += c == '(' ? 1 : -1;
            l = min(l, p);
        }
        paren[i] = {l, p};
        S += p;
    }
    if(S != 0) {
        cout << "No" << endl;
        return 0;
    }
    sort(WHOLE(paren));
    int level = 0;
    for (int i = 0; i < N; i++) {
        if(level + paren[i].l < 0) {
            cout << "No" << endl;
            return 0;
        }
        level += paren[i].p;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 10960
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh
int a[2][230];
//int t[100005] , x[100005] , y[100005];
int gcd(int a , int b , int c)
{
		int x = __gcd(a ,b);
		return __gcd(x , c);
}
int main(){
	dhoom;
	int k;
	cin >> k;
	ll ans = 0;
	for(int i = 1; i <= k ; i++){
		for(int j = 1 ; j<= k ; j++){
			for(int l = 1; l <= k ; l++ ){
				ans += gcd(i , j , l);
			}
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

int N, M;
int MaxA[MAX_N] = {};       // 位置 i で終わるやつの最大の a の値

signed main()
{
    cin >> N >> M;
    MINUS(MaxA);
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        MaxA[b] = max(MaxA[b], a);
    }
    int ans = 0;
    int last_finished = -1;
    REP(i, N) {
        if(MaxA[i] != -1) {
            if(last_finished <= MaxA[i]) {
                ans++;
                last_finished = i;
            }
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1024
/*********************************************************************
* AUTHOR : ANSHU KUMAR                                               *
* ABOUT :  IT DOESN'T MATTER HOW SLOW I GO, AS LONG AS I NEVER STOP  *
* INSTITUTION : IEM KOLKATA                                          *
**********************************************************************/

//try to think at least 30min(with full concentration).

#include <bits/stdc++.h>

using namespace std;

#define int             long long
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define MOD             1000000007
#define INF             1e18
#define PI              3.1415926535897932384626433832795
#define sp(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define endl            '\n'
#define da(arr,type,n)  type *arr=new type[n];


/********** Euclidean Algorithm for GCD **********/
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }



/********** Fast Power Exponentiation ***********/
int power(int a, int b) {
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res % MOD * a % MOD) % MOD;
		a = (a % MOD * a % MOD) % MOD;
		b >>= 1;
	}
	return res;
}



/********** FAST I/O ************/
void fastIO()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}



/********** PROGRAM START ***********/

int32_t main()
{
	fastIO();
	int x, y;
	cin >> x >> y;
	if (((4 * x - y) % 2 == 0 && (4 * x - y) >= 0) && ((y - 2 * x) % 2 == 0 && (y - 2 * x) >= 0))
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

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

#define cn count
#define pb push_back
#define in insert
#define fs first
#define sc second
#define sz size
#define len length
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define forni(i, n) for (ll i = 1; i < (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;
using ll = long long;
const ll inf = 1e9+7; 
const double PI =  3.141592653589793;

int main(){
	IO;
	ll a,b;
	cin>>a>>b;
	a--;b--;
	cout<<(a+b-1)/a<<"\n";
	return 0;
}


// _   .-')                .-. .-')                 .-')                                               
//( '.( OO )_              \  ( OO )               ( OO ).                                             
// ,--.   ,--.).-'),-----. ,--. ,--.  .-'),-----. (_)---\_) ,--. ,--.     .-----.  ,-.-')  .-'),-----. 
// |   `.'   |( OO'  .-.  '|  .'   / ( OO'  .-.  '/    _ |  |  | |  |    '  .--./  |  |OO)( OO'  .-.  '
// |         |/   |  | |  ||      /, /   |  | |  |\  :` `.  |  | | .-')  |  |('-.  |  |  \/   |  | |  |
// |  |'.'|  |\_) |  |\|  ||     ' _)\_) |  |\|  | '..`''.) |  |_|( OO )/_) |OO  ) |  |(_/\_) |  |\|  |
// |  |   |  |  \ |  | |  ||  .   \    \ |  | |  |.-._)   \ |  | | `-' /||  |`-'| ,|  |_.'  \ |  | |  |
// |  |   |  |   `'  '-'  '|  |\   \    `'  '-'  '\       /('  '-'(_.-'(_'  '--'\(_|  |      `'  '-'  '
// """    """     """""""" """  """"      """""""  """""""  """"""""      """"""   """         """""""



Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;
 
 
int main(int argc, char *argv[]) {
  // C-style stdio functions should not be used.
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);
 
  int X, Y; cin >> X >> Y;
  cout << X + Y / 2 << endl;
 
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i,n) for(int (i) = 0; (i) < (int)(n); (i)++)
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    string s;
    cin >> s;
    cout << 700 + 100 * count(all(s), 'o') << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int H,W;
	int i,j;
	while(scanf("%d %d",&H,&W),H||W){
		for(i=0;i<H;i++){
			for(j=0;j<W;j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
return 0;
}



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

int main(){
  string S;
  cin >> S;
  vector<string> Week{"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

  for (int i=0; i<7; i++){
    if (S == Week[i]){
      cout << 7 - i << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

h, w = map(int, input().split())
e = []
e2 = [[0 for _ in range(w)] for _ in range(h)]
count = 0
for i in range(h):
    t = list(map(str, input().split()))
    e.append(list(t[0]))
    for j in list(t[0]):
        if (j == '#'):
            count += 1
for i in range(1, h):
    for j in range(1, w):
        b = False
        if (e[i][j] == '#'):
            if (i < h - 1):
                if(e[i + 1][j] == '#'):
                    b = True
            if (i > 0):
                if (e[i - 1][j] == '#'):
                    b = True
            if (j < w - 1):
                if (e[i][j + 1] == '#'):
                    b = True
            if (j > 0):
                if (e[i][j - 1] == '#'):
                    b = True
            if not(b):
                print("No")
                sys.exit()

print("Yes")

                

Measured memory_bytes: 6864
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int n; cin >> n;
	int64_t x[n]; for(int i = 0; i < n; ++i) cin >> x[i];
	int64_t ans = LINF;
	for(int64_t i = 0; i <= 110; ++i) {
		int64_t sum = 0;
		for(int j = 0; j < n; ++j) {
			sum += (x[j] - i) * (x[j] - i);
		}
		ans = min(ans, sum);
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#define MAXN 100    // pre-calc max n for phi(m, n)
#define MAXM 10010 // pre-calc max m for phi(m, n)
#define MAXP 40000 // max primes counter
#define MAX 400010    // max prime
#define setbit(ar, i) (((ar[(i) >> 6]) |= (1 << (((i) >> 1) & 31))))
#define chkbit(ar, i) (((ar[(i) >> 6]) & (1 << (((i) >> 1) & 31))))
#define isprime(x) (( (x) && ((x)&1) && (!chkbit(ar, (x)))) || ((x) == 2))

using namespace std;

int a[200005];

int main()
{
	int n, ans = 0;
	scanf("%d",&n);
	for (int i = 0; i < n; i++) {
		int x;
		scanf("%d",&x);
		a[x] = a[x - 1] + 1;
		if (a[x] > ans) {
			ans = a[x];
		}
	}
	printf("%d", n - ans);
	return 0;
}

Measured memory_bytes: 1024
/* ****mittal**** */
#include<bits/stdc++.h>
#define ll          long long int 
#define pb          push_back
#define endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repr(i,a,b)   for(ll int i=a;i>=b;i--)
#define lbnd    lower_bound
#define ubnd        upper_bound
#define mp          make_pair
using namespace std;

#define N  100005
ll dp[N][4];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        ll n;
        cin>>n;
        ll a[4];
        for(int i=1;i<=n;i++)
        {
             cin>>a[1]>>a[2]>>a[3];
             for(int j=1;j<=3;j++)
             {
             	for(int k=1;k<=3;k++)
             	{
             		if(k!=j)
             		{
             			dp[i][j]=max(dp[i][j],dp[i-1][k]+a[j]);
             		}
             	}
             }
        }
        cout<<max(dp[n][1],max(dp[n][2],dp[n][3]));
    }
    return 0;
}

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

#include <iostream>


#define MOD 1000000007

typedef unsigned long long ull;
typedef long long ll;

using namespace std;
auto f=[]()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
};


int main()
{
	f();
	int a;cin>>a;
	string s(to_string(a));
	cout<<((s[0]==s[1] || s[1]==s[2] || s[2]==s[3])?"Bad\n":"Good\n");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-6;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair

int N, K;

void solve()
{
	ll ans = 0;
	const ll L = N/K;
	ans = L*L*L;
	if((K%2)==0){ 
		ll t = 0;
		for(int i=1;i<=N;++i)if(i%K == K/2) t++;
		ans += t*t*t;
	}

	cout << ans << endl;
}

int main()
{
	cin >> N >> K;
	solve();
}


Measured memory_bytes: 256
n=int(input())
h=input().split()
h=[int(h[i]) for i  in range(n)]

ans=0
for i in range(len(h)):
    if i == 0:
        ans+=1
    else:
        high=max(h[:i])
        if h[i]>=high:
            ans+=1

print(ans)

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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    int a, b, c;
    cin >> a >> b >> c;

    // 処理
    // 出力
    if (a == b && b == c) {
        cout << 1 << endl;
    } else if (a == b || a == c || b == c) {
        cout << 2 << endl;
    } else {
        cout << 3 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;

int main() {
	int abc[3],k;
	for (int i = 0; i < 3; i++) {
		cin >> abc[i];
	}
	cin >> k;
	sort(abc, abc + 3);
	for (int i = 0; i < k; i++) {
		abc[2] *= 2;
	}
	int ans = 0;
	for (int i = 0; i < 3; i++) {
		ans += abc[i];
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

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


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

using namespace std;

int main() {
	ios::sync_with_stdio(0);
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++)
		cin >> a[i];
	int x = n;
	while(x >= 1) {
		cout << a[x - 1] << ' ';
		x -= 2;
	}
	if(x == 0) x = 1;
	else x = 2;
	while(x <= n) {
		cout << a[x - 1] << ' ';
		x += 2;
	}
}

Measured memory_bytes: 2944
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <sstream>
using namespace std;

template <typename T>
vector<T> uni(vector<T> v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    return v;
}

int main() {
    int n;
    while (cin >> n, n) {
        map<string, vector<string>> m;
        string f_key; bool init = true;
        while (n--) {
            string s; cin >> s;
            for (auto &c: s) if (c == ':' or c == ',' or c == '.') c = ' ';
            stringstream ss(s);
            string key; ss >> key;
            if (init) f_key = key, init = false;
            while (ss >> s) m[key].emplace_back(s);
        }
        vector<string> members(m[f_key]);
        map<string, bool> sub;
        for (int i = 0; i < members.size(); i++) {
            string s = members[i];
            if (m[s].empty()) continue;
            members.erase(members.begin() + i); i--;
            if (sub[s]) continue;
            sub[s] = true;
            members.insert(members.end(), m[s].begin(), m[s].end());
        }
        cout << uni(members).size() << endl;
    }
    return 0;
}


Measured memory_bytes: 3340
package main

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

//•*¨*•.¸¸♪I/O•*¨*•.¸¸♪

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInt64() int64 {
	sc.Scan()
	a,_ := strconv.ParseInt(sc.Text(),10,64)
	return a
}

func scanFloat64() float64 {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return float64(a)
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

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

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	// sc.Buffer(make([]byte, 10000), 100000000)

	n := scanInt()
	a := scanInts(n)

	sort.Ints(a)

	ans := 0
	p := make([]int, n)
	p[0] = 1
	p[n-1] = 2*(n%2) - 1
	
	for i := 1; i < n-1; i++ {
		if i%2 == 1 {
			p[i] = -2
		} else {
			p[i] = 2
		}
	}
	
	sort.Ints(p)

	for i := 0; i < n; i++ {
		ans += a[i]*p[i]
	}

	tmp := 0
	for i := 0; i < n; i++ {
		tmp += a[i]*(-p[n-1-i])
	}

	fmt.Println(max(ans,tmp))
	// fmt.Println(a,p)

}

func min(a ...int) int {
	res := a[0]
	for i := 1; i < len(a); i++ {
		if res > a[i] { res = a[i] }
	}
	return res
}

func max(a ...int) int {
	res := a[0]
	for i := 1; i < len(a); i++ {
		if res < a[i] { res = a[i] }
	}
	return res
}


Measured memory_bytes: 3712
def get_another_num(data, me):
    if data[0] == me:
        return data[1]
    else:
        return data[0]


if __name__ == '__main__':
    # ??????????????\???
    #v_lines = 5
    #h_lines = 4
    #data = [(2, 4), (3, 5), (1, 2), (3, 4)]
    v_lines = int(input())
    h_lines = int(input())
    data = []
    for i in range(h_lines):
        data.append(tuple(map(int, input().split(','))))


    # ????????????????????????
    results = [0] * (v_lines + 1)
    for i in range(1, v_lines + 1):
        me = i
        for amida in data:
            if me in amida:
                me = get_another_num(amida, me)
        results[me] = i

    # ???????????¨???
    for i in range(1, v_lines + 1):
        print(results[i])

Measured memory_bytes: 7556
N = int(input())
h = list(map(int,input().split()))

cost = [0,abs(h[1]-h[0])]
for i in range(1,N-1):
    cost.append( min(cost[i]+abs(h[i+1]-h[i]), cost[i-1]+abs(h[i+1]-h[i-1])) )
print(cost[-1])


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

using namespace std;

int main()
{
    int s;
    cin >> s;
    
    int s1=s/100;
    int s2=s%100;

    if(0<s1 && s1<13){
        if(0<s2 && s2<13) cout << "AMBIGUOUS" << endl;
        else cout << "MMYY" << endl;
    }
    else{
        if(0<s2 && s2<13) cout << "YYMM" << endl;
        else cout << "NA" << endl;
    }
}

Measured memory_bytes: 256