akhauriyash/Code-Regression huggingface dataset:
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define INF 1e9+7
#define roop(i,m,n) for(int i=m;i<n;i++)
#define mroop(i,m,n) for(int i=m;i<n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;

//(int)'a'は97 (int)'A'は65
//おまじない



int main() {

	int n[100] = { 0 };
	int N = 0;
	

	cin >> N;
	roop(i, 0, N) {
		cin >> n[i];
	}

	ll ans = INF;
	ll sum = 0;

	roop(i, -1000, 1000) {
		sum = 0;
		roop(j, 0, N) {
			sum += abs(i - n[j])*abs(i - n[j]);
		}
		ans = min(ans, sum);
	}


	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
use std::vec::Vec;
use std::cmp::*;
use std::collections::HashSet;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let s: Vec<char> = read::<String>().chars().collect();
    let k: usize = read();
    let mut h: HashSet<String> = HashSet::new();
    let n: usize = s.len();
    for i in 0..n+1 {
      for j in 1..min(n-i+1, 6) {
        let tmp = s[i..j+i].iter().cloned().collect::<String>();
        h.insert(tmp);
      }
    }

    let mut v = h.iter().cloned().collect::<Vec<String>>();
    v.sort();
    println!("{}", v[k-1]);
}


Measured memory_bytes: 6396
import java.util.Arrays;

public class Main {

  private static void solve() {
    int n = ni();
    int m = ni();

    int[] a = na(n);
    Arrays.sort(a);

    int sum = Arrays.stream(a).sum();

    int cnt = 0;
    for (int v : a) {
      if (v * 4 * m >= sum) {
        cnt++;
      }
    }

    System.out.println(cnt >= m ? "Yes" : "No");
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 37400
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    vector<long>a(m);
    vector<long>b(m);
    vector<long>c(m);
    for(int i=0;i<m;i++){
        cin >> a[i] >> b[i] >> c[i];
    }
    vector<long>score(n+1,-9999999999999999);
    bool chk = true;
    int count = 0;
    score[1] = 0;
    while(chk){
        chk = false;
        bool chkk = false;
        count++;

        for(int i=0;i<m;i++){
            if(score[a[i]]+c[i] > score[b[i]]){
                score[b[i]] = score[a[i]] + c[i];
                chk = true;
                if(b[i]==n)chkk=true;
            }
        }

        if(!chkk && count > 10*m)chk = false;
        if(count > 10*m)break;
    }
    if(!chk)cout<<score[n]<<endl;
    else cout<<"inf"<<endl;
}

Measured memory_bytes: 256
argList = list(map(int, input().split())) 

n = argList[0]
m = argList[1]

citys = [0]*n

for i in range(m):
    arg = list(map(int, input().split())) 
    citys[arg[0]-1] +=1 
    citys[arg[1]-1] +=1 

for c in citys:
    print(c)

Measured memory_bytes: 3060
#include<stdio.h>

int search(int s[],int n,int t){
  int i;
  for(i=0;i<n;i++){
    if(s[i]==t){
      return 1;
    }
  }
      return 0;
}

int main(){

  int i,n,s[10001],q,t,count=0,flag;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&s[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&t);
    flag=search(s,n,t);
    if(flag==1){
      count++;
      flag=0;
    }
  }

  printf("%d\n",count);
  
  return 0;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  cin >> N >> K;
  int x=1;
  for(int i=0; i<N ; i++){
    if (x + K < x*2){
      x += K;
    }
    else {
      x *= 2;
    }
  }
  cout << x << endl;
}
  
      
      

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


double Fact(int a){
    long double t = a;
    if(a==0) return 1;
    for(int i=a-1; i>=1; i--){
        t *= i;
    }
    return t;
}

double Combi(int a, int b){
    return Fact(a) / Fact(a - b) / Fact(b);
}

int main() {
    int N, A, B; cin >> N >> A >> B;
    vector<ll> V(N);
    map<ll, int> M;
    for(ll &v:V){
        cin >> v;
        M[v]++;
    }
    
    sort(V.begin(), V.end(), greater<>());
    double av = 0;
    bool same = true;
    int same_num = M[V[0]];
    double cnt = 1;
    int mncnt = 0;
    
    for(int i=0; i<A; i++){
        av += V[i];
        if(V[i] == V[A-1]) mncnt++;
        if(V[i] != V[0]) same = false;
    }
    
    cnt = Combi(M[V[A-1]], mncnt);
    av /= A;

    if(same){
        cnt = 0;
        for(int i=A; i<=min(same_num, B); i++){
            cnt += Combi(same_num, i);
        }
    }
    cout << fixed << setprecision(10) << av << endl;
    cout << fixed << setprecision(0) << cnt << endl;
    return 0;
    
}


Measured memory_bytes: 256
n, k = map(int, input().split())
a = [int(x) for x in input().split()]

an = []
az = []
ap = []

for i in range(n):
    if a[i] < 0:
        an.append(a[i])
    elif a[i] == 0:
        az.append(a[i])
    else:
        ap.append(a[i])

an = sorted(an)
ap = sorted(ap)

an_rev = sorted(an, reverse=True)


def count(x):
    cnt = 0
    if x < 0:
        r = 0
        for t in ap:
            while r < len(an) and t*an[r] <= x:
                r += 1
            cnt += r
    elif x == 0:
        cnt += len(az)*(len(az)-1)//2 + len(az)*(n-len(az)) + len(ap)*len(an)
    else:
        r = 0
        for t in ap[::-1]:
            while r < len(ap) and t*ap[r] <= x:
                r += 1
            cnt += r
            if t*t <= x:
                cnt -= 1
        r = 0
        for t in an:
            while r < len(an) and t*an_rev[r] <= x:
                r += 1
            cnt += r
            if t*t <= x:
                cnt -= 1
        cnt //= 2
        cnt += len(az)*(len(az)-1)//2 + len(az)*(n-len(az)) + len(ap)*len(an)
    return cnt


bottom = -10**18-1
top = 10**18+1

while top - bottom > 1:
    mid = (top + bottom) // 2
    if count(mid) >= k:
        top = mid
    else:
        bottom = mid

print(top)

Measured memory_bytes: 113752
#include <algorithm>
#include <cstdio>
#include <ctype.h>
#include <functional>
#include <iostream>
#include <cassert>
#include <cfloat>
#include <climits>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

int main() {
	string S;


	cin >> S;
	int a = 0;
	int b = 0;
	int res=0;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'S') {
			a++;
		}
		else {
			if (a == 0) {
				res+=2;
			}
			else {
				a--;
			}
			b++;
		}
		
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
    string s;
    cin >> s;
    int len = s.size();
    vector<int> g(len, 1);
    g[1] = s[0] == s[1] ? 1 : 2;
    g[2] = g[1] + (s[0] == s[1] || s[1] != s[2]);
    for (int i = 3; i < len; i++) {
        if (s[i] != s[i - 1]) g[i] = g[i - 1] + 1;
        else g[i] = g[i - 3] + 2;
    }
    cout << g[len - 1] << endl;
}


Measured memory_bytes: 1412
N=int(input())
music=[['', 0] for j in range(N)]
for i in range(N):
  s, t = map(str, input().split())
  music[i][0] = s
  music[i][1] = int(t)
X = input()

count = 0
flag=False
for i in range(N):
  if flag:
    count+=music[i][1]
  if music[i][0]==X:
    flag=True
print(count)

Measured memory_bytes: 3064
//https://atcoder.jp/contests/abc151/tasks/abc151_c
//C - Welcome to AtCoder
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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 main() {
    ll N, M; cin>>N>>M;
    vector<pair<int,string>> psm(M);
    for(auto&& ps:psm){
        cin>>ps.first>>ps.second;
    }
    struct Info{
        ll wa_tmp=0;
        ll ac=0, wa=0;
    };
    map<int,Info> tbl;
    for(const auto& ps:psm){
        ll n=ps.first;
        if(ps.second=="WA"){
            if (tbl[n].ac){
            }else{
                tbl[n].wa_tmp++;
            }
        }else{
            if (!tbl[n].ac){
                tbl[n].ac=1;
                tbl[n].wa=tbl[n].wa_tmp;
            }
        }
    }
    ll ans_ac=0, ans_wa=0;
    for(const auto& t:tbl){
        ans_ac += t.second.ac;
        ans_wa += t.second.wa;
    }
    cout<<ans_ac<<" "<<ans_wa<<endl;
    return 0;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
long long int n,a,b;
int main()
{
	scanf("%lld %lld %lld",&n,&a,&b);
	long long int k=n-2;
	long long int l=b-a;
	long long int m=k*l;
	if(a>b)
		printf("0");
	else if(a==b)
		printf("1");
	else if(a!=b && n==1)
		printf("0");
	else
		printf("%lld",m+1);
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let n = get!(usize);
    let ss = get!(String; n);

    let mut map = HashMap::new();
    for s in ss {
        let mut vec = vec![0usize; 26];
        for c in s.chars() {
            vec[(c as u8 - 'a' as u8) as usize] += 1;
        }
        *map.entry(vec).or_insert(0) += 1; 
    }
    let mut count = 0usize;

    for (_,v) in map {
        count += v*(v-1)/2;
    }
    println!("{}", count);

}


Measured memory_bytes: 40884
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<vector<int>> C(3,vector<int>(3));
  for(int i=0;i<3;i++){
    for(int j =0;j<3;j++){
      cin >>C.at(i).at(j);
    }
  }
  string ans="Yes";
  if(C.at(1).at(0) +C.at(0).at(1) -C.at(0).at(0) != C.at(1).at(1) ){
    ans ="No";
  }
  if(C.at(1).at(0) +C.at(0).at(2) -C.at(0).at(0) != C.at(1).at(2) ){
    ans ="No";
  }
  if(C.at(2).at(0) +C.at(0).at(1) -C.at(0).at(0) != C.at(2).at(1) ){
    ans ="No";
  }
  if(C.at(2).at(0) +C.at(0).at(2) -C.at(0).at(0) != C.at(2).at(2) ){
    ans ="No";
  }
  cout << ans <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate, gcd など
#include <cassert>    // assert
#include <stdexcept>
#include <bitset>
using namespace std;

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

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

//////////////// //////////////// //////////////// //////////////// ////////////////
//////////////// //////////////// //////////////// //////////////// ////////////////

// constexpr inline ll mod = 1'000'000'007;
constexpr int max_n = 200'000 + 5;

int n;
vector<int> as(max_n);
map<int, int> bs;
ll res;

int main()
{
    // 高速な入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(15); // 浮動小数の表示の精度

    cin>>n;
    as.resize(n);
    rep(i,n) { cin>>as[i]; }

    rep(j,n) {
        res += bs[j - as[j]];
        bs[j + as[j]]++;
    }
    cout << res << '\n';

    return 0;
}


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

using namespace std;

const int Nmax = 2e5 + 5;
int n, x, i;
bool ap[Nmax];

int main()
{
    cin >> n >> x;
    if(n == 1)
    {
        cout << "Yes\n1\n";
        return 0;
    }

    if(n == 2)
    {
        if(x == 2) cout << "Yes\n1\n2\n3\n";
            else cout << "No\n";
        return 0;
    }

    if(x == 1 || x == 2 * n - 1)
    {
        cout << "No\n";
        return 0;
    }

    cout << "Yes\n";

    if(x == 2 * n - 2)
    {
        ap[x-2] = ap[x+1] = ap[x] = ap[x-1] = 1;

        int cnt = n - 3;
        for(i=1; cnt; ++i)
            if(!ap[i]) cout << i << '\n', ap[i] = 1, cnt--;

        cout << x-2 << '\n' << x+1 << '\n' << x << '\n' << x-1 << '\n';

        cnt = (2*n-1) - (n+1);
        for(i=1; cnt; ++i)
            if(!ap[i]) cout << i << '\n', cnt--;

        return 0;
    }

    ap[x-1] = ap[x] = ap[x+1] = ap[x+2] = 1;

    int cnt = n - 3;
    for(i=1; cnt; ++i)
        if(!ap[i]) cout << i << '\n', ap[i] = 1, cnt--;

    cout << x+2 << '\n' << x-1 << '\n' << x << '\n' << x+1 << '\n';

    cnt = (2*n-1) - (n+1);
    for(i=1; cnt; ++i)
        if(!ap[i]) cout << i << '\n', cnt--;

    return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];

    sort(A.begin(), A.end());

    if (A[0] == 0) {
        cout << 0 << endl;
        return 0;
    }

    long long IMAX = 1000000000LL;
    for (int i = N - 1; i >= 1; i--) {
        if (A[i] > IMAX && A[i - 1]) {
            cout << -1 << endl;
            return 0;
        }
    }

    long long ans = 1;
    long long LMAX = 1000000000000000000LL;
    for (int i = 0; i < N; i++) {
        if (ans > LMAX / A[i]) {
            cout << -1 << endl;
            return 0;
        }
        ans *= A[i];
    }

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

Measured memory_bytes: 4052
#include<bits/stdc++.h>
using namespace std;
int n;
int k;
vector <int> v(100005);
int dp[100005];
int solve(int i){
    if(i==n){
        return 0;
    }
    if(i>n){
        return 2e9;
    }
    if(dp[i]!=-1){
        return dp[i];
    }
    int q =2e9;
    for(int j=1; j<=k;j++){
        q = min(q, abs(v[i]-v[i+j])+solve(i+j));
    }
    dp[i]=q;
    return q;
}
void initialize(){
    for(int i=0; i<100005;i++){
        dp[i]=-1;
    }
}
int main(){
    initialize();
    cin>>n;
    cin>>k;
    for(int i=1; i<=n;i++){
        cin>>v[i];
    }
    cout<<solve(1)<<endl;
}


Measured memory_bytes: 8832
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define lamsort(v,p) sort(v.begin(),v.end(),[](p a, p b){return a.num < b.num;});
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお
vector<pair<ll,int>> factorize(ll n) {
    vector<pair<ll,int>> res;
    for(ll i = 2; i*i <= n; ++i) {
        if(n%i) continue;
        res.emplace_back(i,0);
        while(n%i == 0) {
            n/=i;
            res.back().second++;
        }
    }
    if(n!=1) res.emplace_back(n,1);
    return res;
}
ll gcd(ll x, ll y){
    return y?gcd(y,x%y):x;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll a, b; cin >> a >> b;
    int ans = factorize(gcd(a,b)).size();
    cout << ans +1 << endl;
    return 0;
}

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

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

int main(void)
{
  int n, t[100001], x[100001], y[100001];
  cin >> n;
  t[0] = x[0] = y[0] = 0;
  REP(i, n) cin >> t[i+1] >> x[i+1] >> y[i+1];

  bool can = true;
  REP(i, n)
  {
    int time = t[i+1] + t[i];
    int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
    if (dist > time || dist % 2 != time % 2) can = false;
  }
  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 1408
/*
	  Chase
	   Your
	  Legend

	英雄志逐传奇
*/

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <stdio.h>

#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;


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

	if (a * b > c * d) {
		cout << a * b << endl;
	}
	else {
		cout << c * d << endl;
	}
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = 99999999;
const ll linf = 999999999999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////



int main(){
	
    int n;
    cin >> n;
    set<int> s;
    rep(i,0,n){
        int a;
        cin >> a;
        if(s.count(a) == 0)s.it(a);
        else s.erase(a);
    }
    P(sz(s));
	return  0;
}

Measured memory_bytes: 4864
def dfs(tree, v, tv, p, es):
    if v == tv:
        return True
    for e in tree[v]:
        if e[0] == p:
            continue
        if dfs(tree, e[0], tv, v, es):
            es.append(e[1])
            return True
    return False


def main():
    n = int(input())
    tree = [[] for i in range(n)]
    for i in range(n-1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        tree[a].append((b, i))
        tree[b].append((a, i))
    m = int(input())
    eset = [0]*m
    for i in range(m):
        u, v = map(int, input().split())
        es = []
        dfs(tree, u-1, v-1, -1, es)
        for e in es:
            eset[i] |= 1 << e

    ans = 0
    for i in range(1 << m):
        mask = 0
        for j in range(m):
            if i >> j & 1:
                mask |= eset[j]
        white = bin(mask).count('1')
        now = 1 << (n-1-white)
        if bin(i).count('1') % 2 == 0:
            ans += now
        else:
            ans -= now
    print(ans)


main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>

using namespace std;


int main()
{
  int n;
  cin >> n;
  vector<int>v(n);
  vector<int>v2(n);

  v2[0] = -1;
  for (int i = 1; i < n; i++) {
    cin >> v[i];
    v[i]--;
    v2[i] = 0;
  }

  for (int j = 0; j < n; j++) {
    v2[v[j]% n]++;
  }

  for (int k = 0; k < n; k++) {
    cout << v2[k]<<"\n";
  }
  cin >> n;

  return 0;
}

Measured memory_bytes: 4792
def makelist2(n,m):
    return[[0 for k in range(m)]for i in range(n)]

n,a = map(int,input().split())
x = list(map(int,input().split()))
X = max(x)
X = max(X,a)
b=[]
for i in range(n):
    b.append(x[i]-a)


dp =makelist2(n+1,2*n*X+1)
dp[0][n*X] = 1
for j in range(n+1):
    for t in range(2*n*X+1):
        if j>=1 and (t-b[j-1] < 0 or t-b[j-1]>2*n*X):
            dp[j][t] = dp[j-1][t]
        elif j>= 1:
            dp[j][t] = dp[j-1][t] + dp[j-1][t-b[j-1]]
print(dp[n][n*X]-1)

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

#define int long long
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()

const int mod = 1e9+7;
const int inf = 2e18;



int32_t main()
{	
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	double r;
	cin>>r;

	r = 2*r;
	cout<<(double)(3.141592)*r<<'\n';

	return 0;
}	

Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

string s,t;
int k;
ll dfs() {
  char c=s[k++];
  if(c=='[') {
    ll x=dfs();
    k++;
    return x;
  } else if(isalpha(c)) return t[c-'a']-'0';
  ll x=0,y=0;
  if(s[k]=='[') {
    k++;
    x=dfs();
    k++;
  } else x=t[s[k++]-'a']-'0';
  if(s[k]=='[') {
    k++;
    y=dfs();
    k++;
  } else y=t[s[k++]-'a']-'0';
  if(c=='*') x&=y;
  else if(c=='+') x|=y;
  else x^=y;
  return x;
}

void Main() {
  while(cin >> s && s!=".") {
    cin >> t;
    k=0;
    int x=dfs();
    int ans=0;
    rep(i,10000) {
      stringstream ss;
      ss << i;
      ss >> t;
      while(t.size()<4) t='0'+t;
      k=0;
      if(dfs()==x) ans++;
    }
    pr(x,ans);
  }
}

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



Measured memory_bytes: 3232
#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<climits>
using namespace std;

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

typedef long long ll;

int n;
vector<ll> v;

void solve(){
  if(n < 6){
    cout<<0<<endl;
    return;
  }

  int i = 0;
  ll sum1 = 0;
  int cnt = 0;

  for(int j=0;j<2;j++){
    for(;i<=n-3;i++){
      if(v[i] < v[i+1] + v[i+2]){
        sum1 += v[i] + v[i+1] + v[i+2];
        i += 3;
        cnt++;
        break;
      }
    }
  }

  if(cnt != 2) sum1 = 0;

  ll sum2 = 0;

  for(i=0;i<=n-6;i++){
    if(v[i] < v[i+1] + v[i+2] && v[i+3] < v[i+4] + v[i+5] ||
       v[i] < v[i+1] + v[i+3] && v[i+2] < v[i+4] + v[i+5] ||
       v[i] < v[i+1] + v[i+4] && v[i+2] < v[i+3] + v[i+5] ||
       v[i] < v[i+1] + v[i+5] && v[i+2] < v[i+3] + v[i+4] ||
       v[i] < v[i+2] + v[i+3] && v[i+1] < v[i+4] + v[i+5] ||
       v[i] < v[i+2] + v[i+4] && v[i+1] < v[i+3] + v[i+5] ||
       v[i] < v[i+2] + v[i+5] && v[i+1] < v[i+3] + v[i+4] ||
       v[i] < v[i+3] + v[i+4] && v[i+1] < v[i+2] + v[i+5] ||
       v[i] < v[i+3] + v[i+5] && v[i+1] < v[i+2] + v[i+4] ||
       v[i] < v[i+4] + v[i+5] && v[i+1] < v[i+2] + v[i+3]){
      sum2 = v[i] + v[i+1] + v[i+2] + v[i+3] + v[i+4] + v[i+5];
      break;
    }
  }

  cout<<max(sum1,sum2)<<endl;
}

int main(){
  cin>>n;
  v = vector<ll>(n);
  rep(i,n) cin>>v[i];
  sort(v.rbegin(),v.rend());
  solve();

  return 0;
}

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

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
//vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
    if(x == 0) return 0;
    return counter_1(x >> 1) + (x & 1);
}*/

//int Counter(int x)
int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}
int main(){
   int n, a=0, b=0;
   cin >> n;
   VI p(n), q(n);
   REP(i,n){
       cin >> p[i];
   } 
   REP(i,n){
       cin >> q[i];
   }
   REP(i,n-1){
       int maep=p[i]-1, maeq=q[i]-1;
       REP(j, i){
           if(p[j]<p[i]){
               maep--;
           }
           if(q[j]<q[i]){
               maeq--;
           }
       }
       a+=(maep)*factorial(n-i-1);
       b+=(maeq)*factorial(n-i-1);
   }
   //if(p[n-1]==1) a++;
  // if(q[n-1]==1) b++;
   //cout << a << ' ' << b << endl;
   //cout << c << endl;
   cout << abs(a-b) << endl; 

}

    



Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
using namespace std;


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

    n = 25 - n;
    if(n < 0 || n > 3) return 0;
    cout << "Christmas";
    for(int i;i<n;i++){
        cout << " Eve";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
n=gets.to_i
hs=gets.split.map &:to_i
dp=[0,(hs[1]-hs[0]).abs]
(n-2).times do |i|
  dp[i+2]=[dp[i]+(hs[i+2]-hs[i]).abs,dp[i+1]+(hs[i+2]-hs[i+1]).abs].min
end
p dp[n-1]

Measured memory_bytes: 11524
#include <stdio.h>
#include <limits.h>

#ifndef KOTAISUU
#define KOTAISUU 18
#endif
#ifndef SEDAISUU
#define SEDAISUU 10000
#endif
#ifndef KAKURITU
#define KAKURITU 10 /* * 0.01 % */
#endif

static unsigned int x=123456789;
static unsigned int y=362436069;
static unsigned int z=521288629;
static unsigned int w=88675123;

void seed(unsigned int a,unsigned int b,unsigned int c,unsigned int d) {
	if((a|b|c|d)==0)return;
	x=a;y=b;z=c;w=d;
}

unsigned int randint(void) {
	unsigned int t;
	t=(x^(x<<11));
	x=y;y=z;z=w;
	w=(w^(w>>19))^(t^(t>>8));
	return w;
}

unsigned int randint2(unsigned int max) {
	unsigned int amari = ((UINT_MAX % max) + 1) % max;
	unsigned int ret;
	do {
		ret = randint();
	} while (ret < amari);
	return ret % max;
}

#define KIND 26
#define MAX 365

struct horieyui {
	int mamegu[MAX];
};

int D;
int c[KIND];
int s[MAX][KIND];

int mizuhasu(const struct horieyui* kitaeri) {
	int sumipe = 0;
	int i, j;
	int last[KIND] = {0};
	for (i = 0; i < D; i++) {
		sumipe += s[i][kitaeri->mamegu[i]];
		last[kitaeri->mamegu[i]] = i + 1;
		for (j = 0; j < KIND; j++) {
			sumipe -= c[j] * ((i + 1) - last[j]);
		}
	}
	return sumipe;
}

int main(void) {
	int i, j;
	struct horieyui otehon;
	struct horieyui saikyou;
	int saikyou_score = 0;
	if (scanf("%d", &D) != 1) return 1;
	for (i = 0; i < KIND; i++) {
		if (scanf("%d", &c[i]) != 1) return 1;
	}
	for (i = 0; i < D; i++) {
		for (j = 0; j < KIND; j++) {
			if (scanf("%d", &s[i][j]) != 1) return 1;
		}
	}

	for (i = 0; i < KIND; i++) {
		int score;
		for (j = 0; j < D; j++) otehon.mamegu[j] = (i + j) % KIND;
		score = mizuhasu(&otehon);
		if (i == 0 || score > saikyou_score) {
			saikyou = otehon;
			saikyou_score = score;
		}
	}
	otehon = saikyou;

	for (i = 0; i < SEDAISUU; i++) {
		struct horieyui saituyo;
		int saituyo_score = 0;
		for (j = 0; j < KOTAISUU; j++) {
			struct horieyui kore = otehon;
			int k;
			int score;
			for(k = 0; k < D; k++) {
				if (randint2(10000) < KAKURITU) {
					kore.mamegu[k] = randint2(KIND - 1);
					if (kore.mamegu[k] >= otehon.mamegu[k]) kore.mamegu[k]++;
				}
			}
			score = mizuhasu(&kore);
			if (j == 0 || score > saituyo_score) {
				saituyo = kore;
				saituyo_score = score;
			}
		}
		otehon = saituyo;
		if (saituyo_score > saikyou_score) {
			saikyou = saituyo;
			saikyou_score = saituyo_score;
		}
	}
	for (i = 0; i < D; i++) {
		printf("%d\n", saikyou.mamegu[i] + 1);
	}
#ifdef PRINT_SCORE
	printf("score = %d\n", saikyou_score < -1000000 ? 0 : 1000000 + saikyou_score);
#endif
	return 0;
}


Measured memory_bytes: 1776
#include <bits/stdc++.h>
using namespace std;
int main(void){
  string S;
  cin >> S;
  int N = S.size();

  char x = '1';
  int numOneZero = 0;
  for(int i=0; i<N; i++){
    if(S[i] != x) numOneZero++;
    if(x == '1') x = '0';
    else x = '1';
  }
  
  x = '0';
  int numZeroOne = 0;
  for(int i=0; i<N; i++){
    if(S[i] != x) numZeroOne++;
    if(x == '1') x = '0';
    else x = '1';
  }
  int ans = min(numZeroOne, numOneZero);
  cout << ans << endl;
}

Measured memory_bytes: 512
import Control.Applicative

type Data = (Int, Int)

type Problem = [Data]

type Result = [Int]

count :: Data -> Int

count (n, x)
    = length $ filter (\xs -> sum xs == x) sets where
        sets = enum 3 1 n []

enum :: Int -> Int -> Int -> [Int] -> [[Int]]

enum 1 from to xs
    = [x:xs | x <- [from..to]]
    
enum n from to xs
    = concat [enum (n - 1) (x + 1) to (x:xs) | x <- [from..to]]

solve :: Problem -> Result

solve xs
    = map count xs

output :: Result -> String

output xs
    = concat $ map (\x -> show x ++ "\n") xs
    
input :: IO Problem

input
    = return =<< inputProblem []
    
inputProblem :: Problem -> IO Problem

inputProblem xs
    = do
        [n, x] <- map read.words <$> getLine
        if (n, x) /= (0, 0)
            then inputProblem $ xs ++ [(n, x)]
            else return xs
    
main :: IO ()

main
    = putStr.output =<< solve <$> input

Measured memory_bytes: 5516
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		if("AAA".equals(s)||"BBB".equals(s)) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
	}

}


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

int main() {
    int N;
    cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    long long sum1 = 0, sum2 = 0;
    for (int i = 0; i < N / 2; i++) {
        sum1 += A[i];
        sum2 += A[N - 1 - i];
    }

    if (N % 2 == 0) {
        cout << sum2 - sum1 + (sum2 - A[N / 2]) - (sum1 - A[N / 2 - 1]) << endl;
    } else {
        cout << sum2 - sum1 + max(sum2 - (sum1 - A[N / 2 - 1] + A[N / 2]), (sum2 - A[N / 2 + 1] + A[N / 2]) - sum1) << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <map>
#include <string.h>
#include <algorithm>
#include <bits/stdc++.h>
#include <vector>

using namespace std;
#define set_precision cout << fixed << setprecision(10)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define repit(arr) for (auto it = arr.begin(); it != arr.end(); it++)
#define vi vector<int>
#define vl vector<long long int>
#define Vi vector<vector<int>>
#define vpi vector<pair<int,int>>
#define seti set<int>
#define setl set<ll>
#define dseti set<int, greater<int>>
#define dsetl set<ll, greater<ll>>
#define mseti multiset<int>
#define msetl multiset<ll>
#define dmseti multiset<int, greater<int>>
#define dmsetl multiset<ll, greater<ll>>
#define sortA(arr) sort(arr.begin(), arr.end())
#define dsortA(arr) sort(arr.begin(), arr.end(), greater<int>())
#define ssort(arr) stable_sort(arr.begin(), arr.end())
#define nth(v,n) nth_element(v.begin,v.begin+n-1,v.end())
#define dnth(v,n) nth_element(v.begin,v.begin+n-1,v.end(), greater<int>())
#define pb push_back
#define ll long long

int fact(int n) 
{ 
    int res = 1; 
    for (int i = 2; i <= n; i++) 
        res = res * i; 
    return res; 
}
int nCr(int n, int r) 
{ 
    return fact(n) / (fact(r) * fact(n - r)); 
}
int cel(int a,int b){return((a-1)/b+1);} 
int gcd(int a, int b)
{
    if (a < b)
        swap(a, b);
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}
int lcm(int a,int b){
    return (a*b)/gcd(a,b);
}
void dfs(int u,vi &visited,vi adj[]) {
    visited[u] = 1; 
	for (int i=0; i<adj[u].size(); i++) 
		if (visited[adj[u][i]] == 0) 
			dfs(adj[u][i],visited,adj); 
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,x,y,d,c=0;
    cin>>n>>d;
    rep(i,0,n){
        cin>>x>>y;
        if(x*x+y*y<=d*d){c++;}
    }
    cout<<c;
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>

using namespace std;

int calc(int x) {
  int res = 0;
  while (x > 0) {
    res += x % 10;
    x /= 10;
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  int ans = 1'000'000'000;
  for (int i = 1; i < n; ++i) {
    ans = min(ans, calc(i) + calc(n - i));
  }
  cout << ans << endl;
}


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

char field[8][8];

char own[] = { 'o', 'x' };
char enemy[] = { 'x', 'o' };

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

int countReverse(int x, int y, int turn) {
	if (field[y][x] != '.') return 0;
	int sum = 0;
	for (int i = 0; i < 8; i++) {
		int nx = x, ny = y;
		int cnt = 0;
		bool ok = true;
		while (ok) {
			nx += dx[i], ny += dy[i];
			if (nx < 0 || nx >= 8 || ny < 0 || ny >= 8) ok = false;
			else if (field[ny][nx] == '.') ok = false; //????????????
			else if (field[ny][nx] == own[turn]) break; //???????????????????¢????
			else if (field[ny][nx] == enemy[turn]) cnt++;
		}
		if (ok) sum += cnt;
	}
	return sum;
}

void reverse(int x, int y, int turn) {
	if (field[y][x] != '.') return;
	//??????
	field[y][x] = own[turn];
	for (int i = 0; i < 8; i++) {
		int nx = x, ny = y;
		bool ok = true;
		while (ok) {
			nx += dx[i], ny += dy[i];
			if (nx < 0 || nx >= 8 || ny < 0 || ny >= 8) ok = false;
			else if (field[ny][nx] == '.') ok = false; //????????????
			else if (field[ny][nx] == own[turn]) break; //???????????????????¢????
		}
		if (ok) {
			nx = x, ny = y;
			while (ok) {
				nx += dx[i], ny += dy[i];
				if (field[ny][nx] == own[turn]) break; //???????????????????¢????
				else if (field[ny][nx] == enemy[turn]) field[ny][nx] = own[turn]; //?????¢
			}
		}
	}
}

int main() {
	for (int i = 0; i < 8; i++) {
		std::string s; std::cin >> s;
		for (int j = 0; j < 8; j++) {
			field[i][j] = s[j];
		}
	}

	int turn = 0;
	bool isReverse = false;
	while (1) {
		isReverse = false;
		int max = 0, x, y;
		if (turn == 0) { //????????????
			for (int i = 0; i < 8; i++) {
				for (int j = 0; j < 8; j++) {
					int cnt = countReverse(j, i, turn);
					if (max < cnt) {
						max = cnt;
						x = j; y = i;
						isReverse = true;
					}
				}
			}
		}
		if (max) reverse(x, y, turn);
		turn = !turn;
		max = 0;
		if (turn == 1) { //CHARLOTTE 
			for (int i = 7; i >= 0; i--) {
				for (int j = 7; j >= 0; j--) {
					int cnt = countReverse(j, i, turn);
					if (max < cnt) {
						max = cnt;
						x = j; y = i;
						isReverse = true;
					}
				}
			}
		}
		if (max) reverse(x, y, turn);
		turn = !turn;
		if (!isReverse) break;//??????pass
	}

	for (int i = 0; i < 8; i++) {
		for (int j = 0; j < 8; j++) {
			std::cout << field[i][j];
		}
		std::cout << std::endl;
	}

	return 0;
}

Measured memory_bytes: 3200
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
X = [0] * N
X[N - 1] = sum(A) + B[N - 1]
for i in range(N - 1):
	X[i] = sum(A[: i + 1]) + sum(B[i:])
print(max(X))


Measured memory_bytes: 3060
li = []
for i in range(0, 3000):
    buf = list(map(int, input().split(' ')))
    if buf[0] == buf[1] == 0:
        break

    li.append(buf)

for i in li:
    if i[0] < i[1]:
        print('%d %d' % (i[0], i[1]))
    else:
        print('%d %d' % (i[1], i[0]))



Measured memory_bytes: 5984
#include<stdio.h>
int main(void){
  int n,k,i,j;
  scanf("%d%d",&n,&k);
  for(i=0;i<=n;i++){
    for(j=0;j<=n;j++){
      int a=n-i-j;
      if(0<=a&&a<=n&&10000*j+5000*i+1000*a==k){
        printf("%d %d %d",j,i,a);
        return 0;
      }
    }
  }
  printf("-1 -1 -1");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define si(x) ((int)(x).size())
#define int ll
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

#define W first
#define V second

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,lim; cin>>n>>lim;
	pii item[n];
	For(i,0,n-1) cin>>item[i].W>>item[i].V;
	int mem[n+1][lim+1];
	For(i,0,n) mem[i][0]=0;
	For(i,0,lim) mem[0][i]=0;
	For(i,1,n)
	{
		For(j,1,lim)
		{
			if(j>=item[i-1].W) mem[i][j]=max(mem[i-1][j],mem[i-1][j-item[i-1].W]+item[i-1].V);
			else mem[i][j]=mem[i-1][j];
		}
	}
	cout<<mem[n][lim]<<"\n";
	return 0;
}






Measured memory_bytes: 79232
/**

サイコロの各面には図のとおりに 1 から 6 のラベルが割りあてられています。

入力としてサイコロの各面のラベルに対応する数字と、転がす命令の列が与えられるので、サイコロの上面の数字を出力してください。シミュレーションの初期状態は、図のとおりのラベルの位置でサイコロが置かれているものとします。

 */

//スキャナつかうため

import java.util.Scanner;

public class Main {
	// プログラムのエントリポイント
	public static void main(String[] args) {
		// 入力ストリームの生成

		Scanner sc = new Scanner(System.in);
		// 6桁の数字を受け取る配列diceを作る
		int[] dice = new int[6];
		int intUemen = 0;
		int intMaemen = 0;
		int intKekka = 0;
		// 6個入力された数字を受け取る
		for (int i = 0; i < 6; i++) {
			dice[i] = sc.nextInt();
		}
		int situ = sc.nextInt();
		for (int i = 0; i < situ; i++) {
			intUemen = sc.nextInt();
			intMaemen = sc.nextInt();

			if (intUemen == dice[0]) {
				if (intMaemen == dice[1]) {
					intKekka = dice[2];
				} else if (intMaemen == dice[2]) {
					intKekka = dice[4];
				} else if (intMaemen == dice[3]) {
					intKekka = dice[1];
				} else if (intMaemen == dice[4]) {
					intKekka = dice[3];
				}
			} else if (intUemen == dice[1]) {
				if (intMaemen == dice[0]) {
					intKekka = dice[3];
				} else if (intMaemen == dice[2]) {
					intKekka = dice[0];
				} else if (intMaemen == dice[3]) {
					intKekka = dice[5];
				} else if (intMaemen == dice[5]) {
					intKekka = dice[2];
				}
			} else if (intUemen == dice[2]) {
				if (intMaemen == dice[0]) {
					intKekka = dice[1];
				} else if (intMaemen == dice[1]) {
					intKekka = dice[5];
				} else if (intMaemen == dice[4]) {
					intKekka = dice[0];
				} else if (intMaemen == dice[5]) {
					intKekka = dice[4];
				}
			} else if (intUemen == dice[3]) {
				if (intMaemen == dice[0]) {
					intKekka = dice[4];
				} else if (intMaemen == dice[1]) {
					intKekka = dice[0];
				} else if (intMaemen == dice[4]) {
					intKekka = dice[5];
				} else if (intMaemen == dice[5]) {
					intKekka = dice[1];
				}
			} else if (intUemen == dice[4]) {
				if (intMaemen == dice[0]) {
					intKekka = dice[2];
				} else if (intMaemen == dice[2]) {
					intKekka = dice[5];
				} else if (intMaemen == dice[3]) {
					intKekka = dice[0];
				} else if (intMaemen == dice[5]) {
					intKekka = dice[3];
				}
			} else if (intUemen == dice[5]) {
				if (intMaemen == dice[1]) {
					intKekka = dice[3];
				} else if (intMaemen == dice[2]) {
					intKekka = dice[1];
				} else if (intMaemen == dice[3]) {
					intKekka = dice[4];
				} else if (intMaemen == dice[4]) {
					intKekka = dice[2];
				}
			}
			System.out.println(intKekka);
		}
	}
}

Measured memory_bytes: 17268
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int ans = 0;
        int key = 1;
        for (int i = 0; i < N; i++) {
            int a = sc.nextInt();
            if (a == key) {
                key++;
            } else {
                ans++;
            }
        }

        System.out.println(key == 1 ? -1 : ans);
    }
}


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

ll dp[500][500];

int main() {
    int N;
    cin >> N;
    vector<vector<ll>> A(N, vector<ll>(N));
    vector<vector<bool>> direct(N, vector<bool>(N, true));
    rep(i, N) rep(j, N) cin >> A[i][j];

    for(int k = 0; k < N; ++k) {
        for(int i = 0; i < N; ++i) {
            for(int j = 0; j < N; ++j) {
                if (i != k && j != k && A[i][j] == A[i][k] + A[k][j]) direct[i][j] = false;
            }
        }
    }

    ll ans = 0;
    rep(i, N) rep(j, N) dp[i][j] = 10000000000000000;
    rep(i, N) rep(j, N) {
        if (i != j && direct[i][j] == true) {
            dp[i][j] = A[i][j];
            if (i > j) ans += A[i][j];
        }
    }

    for(int k = 0; k < N; ++k) {
        for(int i = 0; i < N; ++i) {
            for(int j = 0; j < N; ++j) dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
        }
    }

    bool ok = true;
    rep(i, N) rep(j, N) {
        if (i != j && dp[i][j] != A[i][j]) ok = false;
    }
    if (ok) cout << ans << endl;
    else cout << -1 << endl;
}

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

int main(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	int x = (a+d-1)/d;
	int y = (c+b-1)/b;
	if(x>=y){
		cout << "Yes" << "\n";
	}else{
		cout << "No" << "\n";
	}
}


Measured memory_bytes: 3640
N = int(input())
X = list(map(int, input().split()))
M = int(input())
A = list(map(int, input().split()))

MAX = 2019
MIN = 1

for i in range(M):
    if (X[A[i] - 1] + 1 in X) == False and X[A[i] - 1] != MAX:
        X[A[i] - 1] += 1

for i in range(N):
    print(X[i])


Measured memory_bytes: 5604
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int main() {
    int n;
    cin >> n;
    ll sum = 0;
    map<ll, ll> mp;
    for (int i = 0; i < n; ++i) {
        ll x;
        cin >> x;
        sum += x;
        mp[x]++;
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        ll b, c;
        cin >> b >> c;
        sum += (c - b) * mp[b];
        cout << sum << endl;
        mp[c] += mp[b];
        mp[b] = 0;
    }
}


Measured memory_bytes: 9380