akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	// ABC138D X
	public class ABC
	{
		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			long A = vs[0];
			long B = vs[1];

			long[] fa = PrimeFactorization(A);
			long[] fb = PrimeFactorization(B);

			long tmp;
			List<long> pa = new List<long>();
			if (fa.Length > 0) {
				pa.Add(fa[0]);
				tmp = fa[0];
				for (int i = 1; i < fa.Length; i++) {
					if (tmp != fa[i]) {
						pa.Add(fa[i]);
						tmp = fa[i];
					}
				}
			}
			List<long> pb = new List<long>();
			if (fb.Length > 0) {
				pb.Add(fb[0]);
				tmp = fb[0];
				for (int i = 1; i < fb.Length; i++) {
					if (tmp != fb[i]) {
						pb.Add(fb[i]);
						tmp = fb[i];
					}
				}
			}
			int ans = 1;
			int ia = 0, ib = 0;
			while (ia < pa.Count && ib < pb.Count) {
				if (pa[ia] == pb[ib]) {
					ans++;
					ia++;
					ib++;
				} else if (pa[ia] < pb[ib]) {
					ia++;
				} else {
					ib++;
				}
			}
			Console.WriteLine(ans);


			Console.Out.Flush();
		}

		#region 素因数分解
		static long[] PrimeFactorization(long x)
		{
			if (x < 2) { return new long[] { }; }

			List<long> ans = new List<long>();
			while (x % 2 == 0) {
				ans.Add(2);
				x /= 2;
			}
			for (int i = 3; i <= Math.Sqrt(x); i += 2) {
				while (x % i == 0) {
					ans.Add(i);
					x /= i;
				}
			}
			if (x > 1) {
				ans.Add(x);
			}
			return ans.ToArray();
		}
		#endregion

	}
}

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

typedef long long int ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define sz(x) int(x.size())
const ll mod = 1000000007;
const ll INF = 1001001001001001000;
const int M = 12801;
const int d = 6400;

bool dp[80][80][M];

int main() {
    int h,w; cin >> h >> w;
    int grid[h][w]; rep(i,h) rep(j,w) cin >> grid[i][j];
    rep(i,h) rep(j,w) {
        int b; cin >> b;
        grid[i][j] -= b;
    }
    rep(i,h) rep(j,w) rep(k,M) dp[i][j][k] = false;
    rep(i,h) {
        rep(j,w) {
            if (i == 0 && j == 0) {
                dp[0][0][grid[0][0]+d] = true;
                dp[0][0][-grid[0][0]+d] = true;
                continue;
            }
            rep(k,M) {
                bool reach = 0;
                if ((i > 0) && dp[i-1][j][k]) reach = 1;
                if ((j > 0) && dp[i][j-1][k]) reach = 1;
                if (reach) {
                    if ((0 <= k+grid[i][j]) && (k+grid[i][j] < M)) dp[i][j][k+grid[i][j]] = true;
                    if ((0 <= k-grid[i][j]) && (k-grid[i][j] < M)) dp[i][j][k-grid[i][j]] = true;
                }
            }
        }
    }

    int ans = 100100100;
    rep(k,M) {
        if (dp[h-1][w-1][k]) {
            ans = min(ans, abs(k-d));
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(void){
    int a,b,c;
    cin >> a >> b >> c;
    int cnt = 0;
    while (true) {
        if (a > b || c == 0) break;
        b -= a;
        c--;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> c(N);//各すぬけのお菓子の個数
  vector<int> d(K);//各お菓子の総数
  
  for(int i = 0; i < K; i++){
    cin >> d.at(i);//お菓子iの個数
    vector<int> A(d.at(i));//お菓子を受け取るすぬけの番号
    
    for(int j = 0; j < d.at(i); j++){
      cin >> A.at(j);
      c.at(A.at(j) - 1)++;
    }
  }
  
  int t = 0;//いたずら
  for(int i = 0; i < N; i++){
    if(c.at(i) == 0){
      t++;
    }
  }
  
  cout << t << endl;
}

Measured memory_bytes: 3632
#include <stdio.h>

int main(void){
  	int a;
    char line[5];
    fgets(line, 5, stdin);
    sscanf(line, "%d", &a);


    while(a >= 1){
       a -= 1000;
    }
    a = a * -1;
    printf("%d\n",a );

    return 0;
    }


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



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

int main() {
   int A,B,C,K;
   cin >> A >> B >> C >> K;
   int count=0;
   for (int i=0; i<K; i++) {
       if (A>=B) B*=2;
       else C*=2;
   }
   if (A<B && B<C) cout << "Yes" << endl;
   else cout << "No" << endl;
}

Measured memory_bytes: 3628
import java.util.*;
import java.io.*;

class Main{
    public static void main(String args[])throws IOException{
      try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
      
        //for_output
        int result = 0;
        List<Integer> result_list = new ArrayList<>();

        // input
        int num = Integer.parseInt(br.readLine());
        List<Integer> people = new ArrayList<>(num);

        Answer[] ans = new Answer[num];
        for(int i = 0; i < num; i++){
          ans[i] = new Answer();
          people.add(i);
        }

        for(int i = 0; i < num; i++){
          int speak = Integer.parseInt(br.readLine());
          for(int j = 0; j < speak; j++){
            String[] answer = br.readLine().split(" ");
            ans[i].mp.put(Integer.parseInt(answer[0])-1, Integer.parseInt(answer[1]));
          }  
        }

        // for_algorithm
        int pattern = (int)Math.pow(2.0, (double)num);
        boolean false_flag = false;

        //algorithm
        for(int i = 0; i < pattern; i++){
          List<Integer> true_list = new ArrayList<>();
          List<Integer> false_list = new ArrayList<>();
 
          for(int j = 0; j < num; j++){
            if((1&i>>j) == 1){
              true_list.add(j);
            }else{
              false_list.add(j);
            }
          }

          result = 0;
          //false_flag = false;

          if(true_list.size() == 0){
            result = 0;
            result_list.add(result);
          }else{
            loop:for(int t = 0; t < true_list.size(); t++){
              if(ans[true_list.get(t)].mp.isEmpty()){
                result = true_list.size();
              }else{
                for (Integer key : ans[true_list.get(t)].mp.keySet()) {
                  if(true_list.contains(key)){
                    if(ans[true_list.get(t)].mp.get(key) == 1){
                      result = true_list.size();
                    }else{
                      result = 0;
                      break loop;
                      //false_flag = true;
                    }
                  }else if(false_list.contains(key)){
                    if(ans[true_list.get(t)].mp.get(key) == 0){
                      result = true_list.size();
                    }else{
                      result = 0;
                      break loop;
                      //false_flag = true;
                    }
                  }
                }
              }
            }
            /*if(false_flag){
              result = 0;
            }*/
            //System.out.println(result);
            result_list.add(result);
          }
        }
        //System.out.println(result_list);
        System.out.println(Collections.max(result_list));
      }
    }

    public static class Answer{
      Map<Integer, Integer> mp;

      Answer(){
        this.mp = new HashMap<>();
      }
    } 
}


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

int N;
int a[2000000];
int all = 0;

int main(){
	scanf("%d",&N);
	for(int i = 0; i < N; i++){
		scanf("%d",&a[i]);
		all = all ^ a[i];
	}
	printf("%d",a[0]^all);
	for(int i = 1; i < N; i++){
		printf(" %d",a[i]^all);
	}
	puts("");
	return 0;
}


Measured memory_bytes: 4580
#include <iostream>
#include <vector>
using namespace std;
vector<vector<bool>> check(int b, vector<vector<int>> A, vector<vector<bool>> bing) {
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (b == A[i][j]) {
        bing[i][j] = true;
      }
    }
  }
  return bing;
}
int main()
{
  vector<vector<int>> A = {{0,0,0},
                           {0,0,0},
                           {0,0,0}};
  for (int i = 0; i < 3; i++){
    for (int j = 0; j < 3; j++) {
      cin >> A[i][j];
    }
  }
  int N = 0;
  cin >> N;
  vector<int> B;
  for (int k = 0; k < N; k++) {
    int b;
    cin >> b;
    B.push_back(b);
  }
  vector<vector<bool>> bing = {{false,false,false},
                              {false,false,false},
                              {false,false,false}};
  for (int i = 0; i < N; i++) {
    bing = check(B[i], A, bing);
  }
  for (int i = 0; i < 3; i++) {
    if (bing[i][0] == true && bing[i][1] == true &&bing[i][2] == true) {
      cout << "Yes";
      return 0;
    }
    if (bing[0][i] == true && bing[1][i] == true && bing[2][i] == true) {
      cout << "Yes";
      return 0;
    }
  }
  if (bing[0][0] == true && bing[1][1] == true && bing[2][2] == true) {
    cout << "Yes";
    return 0;
  }
  if (bing[0][2] == true && bing[1][1] == true && bing[2][0] == true) {
    cout << "Yes";
    return 0;
  }
  cout << "No";
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
typedef pair<int, int> PII;
typedef long long ll;
template<typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;


int n;

void dfs(string s, char mx) {
	if (s.size() == n) {
		cout << s << endl;
	}
	else {
		for (char c = 'a'; c <= mx; c++) {
			dfs(s + c, ((c == mx) ? (char)(mx + 1) : mx));
		}
	}
}

int main() {

	cin >> n;

	dfs("", 'a');

	return 0;
}


Measured memory_bytes: 1536
#include <iostream>

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

int main() {

    int N, A, B, tmp;
    scanf("%d%d%d", &N, &A, &B);

    int ans = 0;

    REP(n, N){
        tmp = (n+1) % 100000 / 10000 + (n+1) % 10000 / 1000 + (n+1) % 1000 / 100 + (n+1) % 100 / 10 + (n+1) % 10;
        if (A <= tmp and tmp <= B) {
            ans += (n+1);
        }
    }

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


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

int main() {
	int N,Y;
  	cin >> N >> Y;
  
  	int x = -1;
  	int y = -1;
  	int z = -1;
  
  	for(int i = 0; i <= N; i++){
      for(int j = 0; j <= N - i; j++){
          int k = N - i - j;
          int total = 10000 * i + 5000 * j + 1000 * k;
          if(total == Y) {
            x = i;
            y = j;
            z = k;
          }
        }
       }
  
  	cout << x << " " << y << " " << z << endl;
}

Measured memory_bytes: 256
N = gets.chomp.to_i
spots = gets.chomp.split(" ").map(&:to_i)

spots.unshift(0).push(0)

distance = 0
spots.inject { |from, current| distance += (current - from).abs; current }

(1..N).each do |i|
  from = spots[i-1]
  current = spots[i]
  to = spots[i+1] 
  puts distance - (((to - current).abs + (current - from).abs) - (to - from).abs)
end


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

signed main()
{
  string S; int K;
  cin >> S;
  cin >> K;

  if(S.size() == 1) {
    cout << K/2 << endl;
    return 0;
  }

  string T = S + S;

  int ans1 = 0, ans2 = 0;

  bool flag = true;
  FOR(t,1,T.size()) {
    if(T[t] == T[t-1]) {
      if(t < S.size()) {
        ans1++;
      } else {
        ans2++;
      }
      t++;
    } else {
      flag = false;
    }
  }

  if(flag) {
    cout << S.size() * K / 2 << endl;
    return 0;
  }

  cout << ans1 + (K-1) * ans2 << endl;

  return 0;
}


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

int main()
{
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a+b>c+d){
    cout<<"Left"<<endl;
  } else if(a+b==c+d){
    cout<< "Balanced"<<endl;
  } else {
    cout<< "Right"<<endl;
  }
}

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

struct BiconectedGraph{
  typedef pair<int,int> P;
  vector<vector<int> > G,C,T;
  vector<int> ord,low,belong;
  vector<P> B;
  int n;
  BiconectedGraph(){}
  BiconectedGraph(int n):n(n){
    G.clear();
    C.clear();
    T.clear();
    G.resize(n);
    C.resize(n);
    T.resize(n);
  }
  
  void add_edge(int u,int v){
    G[u].push_back(v);
    G[v].push_back(u);
  }

  void input(int m,int offset){
    int a,b;
    for(int i=0;i<m;i++){
      cin>>a>>b;
      add_edge(a+offset,b+offset);
    }
  }
  
  bool is_bridge(int u,int v){
    if(ord[u]>ord[v]) swap(u,v);
    return ord[u]<low[v];
  }
  
  void dfs(int u,int p,int &k){
    ord[u]=low[u]=k;
    ++k;
    for(int v:G[u]){
      if(v==p) continue;
      if(ord[v]>=0){
	low[u]=min(low[u],ord[v]);
      }else{
	dfs(v,u,k);
	low[u]=min(low[u],low[v]);
      }
      if(is_bridge(u,v)) B.push_back(P(u,v));
    }
  }
  
  void fill_component(int c,int u){
    C[c].push_back(u);
    belong[u]=c;
    for(int v:G[u]){
      if(belong[v]>=0||is_bridge(u,v)) continue;
      fill_component(c,v);
    }
  }
  
  void add_component(int u,int &k){
    if(belong[u]>=0) return;
    fill_component(k++,u);
  }
  
  int build(){
    int k=0;
    ord.clear();
    low.clear();
    belong.clear();
    ord.resize(n,-1);
    low.resize(n);
    belong.resize(n,-1);
    for(int u=0;u<n;u++){
      if(ord[u]>=0) continue;
      dfs(u,-1,k);
    }
    k=0;
    for(int i=0;i<(int)B.size();i++){
      add_component(B[i].first,k);
      add_component(B[i].second,k);
    }
    for(int u=0;u<n;u++) add_component(u,k);
    for(int i=0;i<(int)B.size();i++){
      int u=belong[B[i].first],v=belong[B[i].second];
      T[u].push_back(v);
      T[v].push_back(u);
    }
    return k;
  }
};

signed main(){
  int n,m;
  cin>>n>>m;
  BiconectedGraph bg(n);
  bg.input(m,0);
  int k=bg.build();
  auto& G=bg.T;
  vector<int> c(k);
  for(int i=0;i<k;i++) c[i]=bg.C[i].size();
  vector<vector<int> > dp(2,vector<int>(k,0));
  vector<int> used(k,0);
  function<void(int,int)> dfs=[&](int v,int p){
    if(used[v]) return;
    used[v]=1;
    dp[0][v]=0;
    dp[1][v]=c[v];
    for(int u:G[v]){
      if(u==p) continue;
      dfs(u,v);
      dp[0][v]+=max(dp[0][u],dp[1][u]);
      dp[1][v]+=dp[0][u];
    }
    return;
  };
  int ans=0;
  for(int i=0;i<k;i++){
    if(used[i]) continue;
    dfs(i,-1);
    ans+=max(dp[0][i],dp[1][i]);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 22840
#include <bits/stdc++.h>
using namespace std;
const int m = 1e9+7;
int h, w;
char sq[1005][1005];
long long dp[1005][1005];
int main(){
	scanf("%d%d", &h, &w);
	for (int i=1;i<=h;i++){
		for (int j=1;j<=w;j++){
			scanf(" %c", &sq[i][j]);
		}
	}
	
	dp[1][1] = 1;
	for (int i=1;i<=h;i++){
		for (int j=1;j<=w;j++){
			if (i==1 && j==1){
				continue;
			} else if (sq[i][j] == '.'){
				dp[i][j] = (dp[i-1][j]%m + dp[i][j-1]%m) % m;
			}
		}
	}
	
	printf("%d\n", dp[h][w]);
}

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

int main() {
    
    string s;
    cin >> s;
    if(s=="SAT") cout << "1" << endl;
    else if(s=="SUN") cout << "7" << endl;
    else if(s=="MON") cout << "6" << endl;
    else if(s=="TUE") cout << "5" << endl;
    else if(s=="WED") cout << "4" << endl;
    else if(s=="THU") cout << "3" << endl;
    else if(s=="FRI") cout << "2" << endl;
    
    
    
	return 0;
}

Measured memory_bytes: 3564
use std::io;

fn solve(cards: &mut Vec<i32>) -> i32 {
    let mut alice = 0;
    let mut bob = 0;
    let mut alices_turn = true;
    cards.sort();
    for i in cards.iter().rev() {
        if alices_turn {
            alice += *i;
        } else {
            bob += *i;
        }
        alices_turn = !alices_turn;
    }
    alice - bob
}

#[test]
fn test_solve() {
    assert_eq!(solve(&mut vec![3, 1]), 2);
    assert_eq!(solve(&mut vec![2, 7, 4]), 5);
    assert_eq!(solve(&mut vec![20, 18, 2, 18]), 18);
}

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let n: usize = input.trim().parse().unwrap();
    let mut cards: Vec<i32> = Vec::with_capacity(n);
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let mut iter = input.split_whitespace();
    for _ in 0..n {
        cards.push(iter.next().unwrap().parse().unwrap());
    }
    println!("{}", solve(&mut cards));
}


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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pop pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define b begin()
#define e end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;





int arr[g_size],arr1[g_size];



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

	int n,m,T,res;

	int maxi=-mx,mini=mx,count=0;

	int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000];

	int ara[n_size],ara2[n_size];

    f(i,0,27){
        arr1[i]=mx;
    }

	cin>>n;
	f(i,0,n-1)
	{
	    cin>>s;
	    mem(arr);
	    f(j,0,strlen(s)-1)
	    {
	        arr[s[j]-'a']++;
	    }

	    f(i,0,27){
            arr1[i]=min(arr1[i],arr[i]);
	    }

	}

	f(i,0,27)
	{
	   if(arr1[i]>=0 && arr1[i]<=50) {
        k=arr1[i];
        f(j,1,k)
	    {
	        char c=i+'a';
	        cout<<c;
	    }
	}
	}
	cout<<endl;


}


Measured memory_bytes: 40060
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N,M,K;
	cin >> N >> M >> K;
	for(int i=0;i<=N;++i){
		for(int j=0;j<=M;++j){
			int res = i*M;
			res += ((N-i)-i)*j;
			if(res == K){
				cout << "Yes" << endl;
				return;
			}
		}
	}
	cout << "No" << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int MOD = (int)1e9 + 7;
#define bit(n, k) ((n) >> (k) & 1)

int main() {
    int n; cin >> n;
    vector<long long> a(n);
    for (auto &ai: a) cin >> ai;
    long long ans = 0;
    for (int k = 0; k < 60; k++) {
        vector<long long> cnt(2);
        for (auto &ai: a) {
            long long pow = (1LL << k) % MOD;
            (ans += cnt[bit(ai, k) ^ 1] * pow % MOD) %= MOD;
            cnt[bit(ai, k)]++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;

int main() {
	int N,K,l[52]={};
	cin >> N >> K;
	REP(i,N) cin >> l[i];
	sort(l,l+N);
	reverse(l,l+N);
	int ans=0;
	REP(i,K) ans+=l[i];
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long,long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

ll INF = 1LL << 60;

int main() {
    int N; cin >> N;
    vecl A(N); REP(i,N) cin >> A[i];
    int cnt = 0;
    int p;
    ll cur = INF;
    REP(i,N) {
        if(A[i] < 0) cnt++;
        if(abs(A[i]-0) <= cur) {
            p = i;
            cur = abs(A[i]);
        }
    }
    //cout << cur << endl;
    ll ans = 0;
    if(cnt%2 == 0) REP(i,N) ans += abs(A[i]);
    else {
        REP(i,N) if(i == p) ans -= abs(A[i]); else ans += abs(A[i]);
    }
    cout << ans << endl;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000000
using namespace std;
using ll = long long;
int main()
{
    int n,m;
    cin >> n >> m;
    vector<int> s(m), c(m);
    rep(i,m){
        cin >> s[i] >> c[i];
    }
    bool flag = false;
    int a = 1;
    rep(i,n-1){
        a *= 10;
    }
    int b = a;
    if(a==1){
        a = 0;
    }
    for (int i = a; i < b * 10;i++){
        string str = to_string(i);
        bool tmp = true;
        rep(j,m){
            if(str[(s[j]-1)] != c[j] + '0'){
                tmp = false;
            } 
        }
        if(tmp){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef long long ll;
ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

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

	ll n, midNum1 = 0, midNum2 = 0;
	double midmid = 0;
	cin >> n;
	vector<ll>x(n);
	rep(i,n)cin >> x[i];
	vector<pair<ll, ll>>a(n);
	rep(i, n)a[i] = make_pair(x[i],i);
	sort(all(a));
	midNum1 = a[a.size()/2-1].first;
	midNum2 = a[a.size() / 2].first;
	midmid = (midNum1 + midNum2) / 2.0;
	for (ll i = 0; i < n; i++) {
		if (x[i] <= midmid)cout << midNum2 << endl;
		else cout << midNum1 << endl;
	}
}


Measured memory_bytes: 6912
#include <stdio.h>
#include <string.h>
#define N 259

int main(void)
{
    char a[N], b[N];
    int k = 0, go = 0;

    while (fgets(a, 259, stdin))
    {
        int c = strlen(a) - 1;

        for (int i = c, j = 0; j < c; i++, j++)
        {
            a[i] = a[j];
        }

        fgets(b, 259, stdin);
        for (int i = 0; i < strlen(a); i++)
        {
            k = 0;
            for (int j = 0; j < strlen(b) - 1; j++)
            {
                if (a[i + j] == b[j])
                {
                    k++;
                }
                else
                {
                    break;
                }
            }

            if (k == strlen(b) - 1)
            {
                go = 1;
                break;
            }
        }
        if (go == 1)
        {
            printf("Yes\n");
        }
        else
        {
            printf("No\n");
        }
    }
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes                \
    cout << "Yes" << endl; \
    return 0;
#define No                \
    cout << "No" << endl; \
    return 0;
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template <typename T>
void print(const T &v);

int main()
{
    int N;
    cin >> N;
    vector<int> vec(N);
    vector<bool> seen(N, false);
    for (int i = 0; i < N; i++)
    {
        int a;
        cin >> a;
        a--;
        vec.at(i) = a;
    }
    int now = 0;
    seen[0] = true;
    int cnt = 0;
    while (true)
    {
        now = vec[now];
        cnt++; // 押した回数を増やす
        if (now == 1)
        {
            cout << cnt << endl;
            return 0;
        }
        if (seen[now] == true)
        {
            cout << -1 << endl;
            return 0;
        }
        seen[now] = true;
    }
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 768
import java.io.PrintWriter

val pw = PrintWriter(System.out)
fun main(args: Array<String>) {
    func()
    pw.flush()
}
fun println(value: Any) { pw.println(value) }

fun func() {
    val N = nextInt()
    val S = listOfInt()
    var ans = 0L
    for (C in 1 until N) {
        var score = 0L
        var X = 0
        while (C * X < N) {
            val n = C * X
            val a = (N - 1) - n
          //val b = a - C
            if (n >= a && (N - 1) % C == 0) break
            if (a <= C) break
            score += S[n] + S[a]
            ans = Math.max(ans, score)
            X++
        }
    }
    println(ans)
}

fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) } //{ it.toInt() }


Measured memory_bytes: 53828
# -*- coding: utf-8 -*-

import io
import sys
import math

def solve():
    # implement process
    pass

def main():
    # input
    m, n = map(int, input().split())
    
    # process
    ans = "Yes" if m == n else "No"
    
    # output
    print(ans)
    return ans
        
### DEBUG I/O ###
_DEB = 0   # 1:ON / 0:OFF

_INPUT = """\
2 3
"""
_EXPECTED = """\
Yes
"""

def logd(str):
    """usage:
    if _DEB: logd(f"{str}")
    """
    if _DEB: print(f"[deb] {str}")

### MAIN ###
if __name__ == "__main__":
    if _DEB:
        sys.stdin = io.StringIO(_INPUT)
        print("!! Debug Mode !!")

    ans = main()

    if _DEB:
        print()
        if _EXPECTED.strip() == ans.strip(): print("!! Success !!")
        else: print(f"!! Failed... !!\nANSWER:   {ans}\nExpected: {_EXPECTED}")

Measured memory_bytes: 9116
#include<bits/stdc++.h>
#define re register
#define ui unsigned int
#define ull unsigned long long
int main()
{
	puts("36213");
	puts("+ 1 1 3");
	for(re int i=1;i<=29;i++)puts("+ 3 3 3");
	puts("< 1 3 4");puts("< 3 0 3");puts("+ 3 4 3");
	puts("+ 5 5 4");
	puts("+ 1 3 1");
	puts("+ 0 3 233");
	for(re int i=30;i>=0;i--)
	{
		puts("+ 30 3 11");
		for(re int j1=1;j1<=i;j1++)puts("+ 11 11 11");
		puts("+ 11 22 11");
		puts("< 11 1 20");
		puts("+ 100 100 14");
		for(re int j=30;j>=0;j--)
		{
			puts("+ 20 21 12");
			for(re int j1=1;j1<=j;j1++)puts("+ 12 12 12");
			puts("+ 12 14 12");
			puts("< 12 233 13");
			puts("+ 13 20 13");
			puts("< 3 13 13");
			for(re int j1=1;j1<=j;j1++)puts("+ 13 13 13");
			puts("+ 14 13 14");
		}
		for(re int j1=1;j1<=i;j1++)puts("+ 14 14 14"),puts("+ 20 20 20");
		puts("+ 14 2 2");
		puts("+ 22 20 22");
	}
}

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	int cnt = 0;
	for(int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		if(a == b) {
			cnt++;
			if(cnt == 3) {
				cout << "Yes" << endl;
				return 0;
			}
		}
		else cnt = 0;
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>
	int main(){
		int i,n,data[10000],min,max;
		long long int sum=0;
		scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%d",&data[i]);
			}
			min=data[0];
			max=data[0];
			for(i=0;i<n;i++){
				if(min>data[i]){
					min=data[i];
					}if(max<data[i]){
						max=data[i];
						}
						sum+=data[i];
				}
				printf("%d %d %lld\n",min,max,sum);
				return 0;
				}

Measured memory_bytes: 2724
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i <= (n); i++)
#define repi(i,a,b) for (int i = (a); i < (b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;

int main() {
  string O, E; cin >> O >>E;
  rep(i,E.size()) {
    cout << O.at(i) << E.at(i);
  }
  if(O.size()-E.size() == 1)
    cout << O.at(O.size()-1);
  cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};
//fixed << setprecision(2)
bool  Array_check(ll y, ll x,ll d,ll w) {
	if (x < 0 || x >= w || y<0 || y>=d) {
		return false;
	}
	else {
		return true;
	}
	
}

//小文字=大文字+32
int main()
{ll H;
cin >> H;
ll ans=1;//モンスターの数
ll tmp=1;
while(1){	ans *= 2;
	if (ans > H) {
		break;
	}
tmp += ans;
}
cout << tmp;

}



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

int main(){
    int n,m,a[10],s,c;
    map<int,int>q;
    cin>>n>>m;
    int flag=1;
    memset(a,-1,sizeof(a));
    while(m--){
        cin>>s>>c;
        if(q.count(s)==0){
            q[s]=c;
            a[s]=c;
        }
        else{
            if(q[s]!=c) flag=0;
        }
    }
    if(a[1]==0 && n>1) flag=0;
    if(flag==0) puts("-1");
    else{
        if(n>1){
            for(int i=1;i<=n;i++){
                if(a[i]==-1 && i==1) cout<<1;
                else if(a[i]==-1 && i>1) cout<<0;
                else cout<<a[i];
            }
        }
        else{
            if(a[1]==-1) cout<<0;
            else cout<<a[1];
        }
    }
    return 0;
}


Measured memory_bytes: 256
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math
from collections import deque
import itertools
import heapq
#import bisect
from fractions import Fraction
import copy
from functools import lru_cache
from collections import defaultdict
import pprint

#oo=list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
# ko=list("abcdefghijklmnopqrstuvwxyz")

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)

def soinsubunkai(n):
    a = []
    i = 1
    while i*i <= n:
        if n % i == 0 and i!=1:
            a.append(i)
            n=n//i

        if n% i !=0 or i==1:
            i += 1
    nokori=[n]
    return a + nokori


def main():
    s=list(str(input()))
    t=list(str(input()))
    count=0
    for i in range(len(s)):
        if s[i]!=t[i]:
            count+=1
    print(count)


if __name__ == "__main__":

    main()

Measured memory_bytes: 87164
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

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

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

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

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

order = (A + B).argsort()[::-1]
a = A[order[::2]].sum()
b = B[order[1::2]].sum()
print(a - b)


Measured memory_bytes: 66632
#include <iostream>
using namespace std;
int main() {
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;
  if(x-r >= 0 && x+r <= W && y+r <= H && y-r >= 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

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

int main() {
    string s;
    cin >> s;
    for (int i = s.size() / 2 - 1; i > 0; i--) {
        if (equal(begin(s), begin(s) + i, begin(s) + i, begin(s) + 2*i)) {
            cout << i * 2 << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>

using namespace std;

#define MAX_D 210
#define MAX_N 210

int D, N;
int T[201];
int A[201], B[MAX_N], C[MAX_N];
bool suit[MAX_D][MAX_N];
int dp[MAX_D][MAX_N];

int main() {
    int i, j, k;
    
    scanf("%d%d", &D, &N);
    for (i = 0; i < D; ++i) {
        scanf("%d", &T[i]);
    }
    for (j = 0; j < N; ++j) {
        scanf("%d%d%d", &A[j], &B[j], &C[j]);
    }
    
    for (i = 0; i < D; ++i) for (j = 0; j < N; ++j) {
        suit[i][j] = (A[j] <= T[i] && T[i] <= B[j]);
    }
    
    for (i = 0; i < D; ++i) for (j = 0; j < N; ++j) {
        //	-1 : impossible
        dp[i][j] = -1;
    }
    for (j = 0; j < N; ++j) if (suit[0][j]) {
        dp[0][j] = 0;
    }
    for (i = 0; i < D - 1; ++i) for (j = 0; j < N; ++j) if (dp[i][j] >= 0) {
        for (k = 0; k < N; ++k) if (suit[i + 1][k]) {
            if (dp[i + 1][k] < dp[i][j] + abs(C[j] - C[k])) {
                dp[i + 1][k] = dp[i][j] + abs(C[j] - C[k]);
            }
        }
    }
    
    int ans = -1;
    for (j = 0; j < N; ++j) {
        if (ans < dp[D - 1][j]) {
            ans = dp[D - 1][j];
        }
    }
    printf("%d\n", ans);
    
    return 0;
}

Measured memory_bytes: 2908
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

bool check(int k){
    int m=sqrt(k);
    return m*m==k;
}

signed main()
{
    int a,b; cin>>a>>b;
    int k;
    if(b<=9) k=a*10+b;
    else if(b<=99) k=a*100+b;
    else k=a*1000+b;

    if(check(k)) 
        cout<<"Yes"<<endl;
    else 
        cout<<"No"<<endl;
}


Measured memory_bytes: 256
S = input()
K = int(input())

if len(S)==1:
    print(S[0])
    
else:
    lst = []
    for i in range(len(S)):
        if S[i]!='1':
            lst.append(i)
        
    if lst==[]:
        print('1')
    else:
        if K<lst[0]+1:
            print('1')
        else:
            print(S[lst[0]])

Measured memory_bytes: 3060
#include<stdio.h>
#include<iostream>
#include<iomanip>

using namespace std;

int main(){
  int a,b,d,r;
  double f;
  cin>>a>>b;
  d=a/b;
  r=a%b;
  f=(double)a/b;
  printf("%d %d %lf\n",d,r,f);
  return 0;
}

Measured memory_bytes: 3212
def solve(B,G,x):
  sums = 0
  for i in range(N):
    req = B[i] - x//G[i] 
    sums += max(0,req)
  if sums <= K:
    return True
  else:
    return False

N,K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
A.sort(reverse=True)
F.sort()

if sum(A) <= K:
  print("0")
  exit(0)

L = []
MAX = 0
for i in range(N):
  temp = A[i]*F[i]
  MAX = max(MAX,temp)
ng = 1
ok = MAX+1
while abs(ng-ok) > 1:
  mid = (ok+ng)//2
  #print(mid,solve(A,F,mid))
  if solve(A,F,mid):
    ok = mid
  else:
    ng = mid
print(ok)
  


Measured memory_bytes: 119500
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ff first
#define ss second
#define INF (ll) (1e9)
#define mod (ll) (1e9 + 7)
#define endl "\n"
#define tt ll testcase; cin>>testcase; while(testcase--)
 
int main(){
	fast;
	ll n;
	cin>>n;
	vector<vector<int>>a(n+1, vector<int>(3, 0));
	vector<vector<int>>dp(n+1, vector<int>(3, 0));
	for(int i=1; i<=n; i++){
		cin>>a[i][0]>>a[i][1]>>a[i][2];
	}
	for(int i=1; i<=n; i++){
		dp[i][0] = a[i][0] + max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] = a[i][1] + max(dp[i-1][0], dp[i-1][2]);
		dp[i][2] = a[i][2] + max(dp[i-1][1], dp[i-1][0]);
	}
	cout<<*max_element(dp[n].begin(), dp[n].end());
}

Measured memory_bytes: 11264
S = str(input())
N = len(S)
B = [[0 for k in range(N)] for k in range(N)]

t = 1
for p in range(N):
    for q in range(N):
        if p == q:
            t *= 2
        if p >= q:
            B[q][p] = t//2

ans = 0
for k in range(N):
    for j in range(N):
        ans += int(S[k])*B[k][j]*10**(N-j-1)

print(ans)

Measured memory_bytes: 3064
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
const long long llinf=LLONG_MAX;
const int inf=INT_MAX;
const int nmax=1e5+5;
const int mod=1e9+7;
using namespace std;
int n,i;
ll a,b,ans,x[nmax];
int main()
{
    //freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>n>>a>>b;
    for(i=1;i<=n;i++)cin>>x[i];
    for(i=2;i<=n;i++)ans+=min((x[i]-x[i-1])*a,b);
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")
using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int  INF = (1 << 30) - 1;
const ll INFL = 1LL << 60;
const ll mod = 10000000007;


std::chrono::system_clock::time_point start;
std::chrono::system_clock::time_point owari;

double calc_time() {
	owari = std::chrono::system_clock::now();
	return std::chrono::duration_cast<std::chrono::milliseconds>(owari - start).count();
}

/*
inline unsigned long long xor128() {
	static unsigned long long rx = 411111789, ry = 9471111169, rz = 5212488629, rw = 886575123;
	unsigned long long rt = (rx ^ (rx << 11));
	rx = ry;
	ry = rz;
	rz = rw;
	return (rw = (rw ^ (rw >> 19)) ^ (rt ^ (rt >> 8)));
}
*/
inline uint32_t xor128() {

	static uint32_t seed = 2;
	seed = seed ^ (seed << 7);
	seed = seed ^ (seed >> 12);
	return seed = seed & (~1);
}

double rand128() {
	return (double)(xor128() & 0xFFFF) / 0xFFFF;
}

int D;


int pena[26];
int s[365][26];
int ans[365];
int pe[26];
int score = 0;

inline int calc() {
	int cur = 0;
	REP(i, 365) {
		cur += s[i][ans[i]];
	}
	VI a(26, -1);
	REP(i, 365) {
		cur -= (i - a[ans[i]])*(i - a[ans[i]] - 1) / 2 * pena[ans[i]];
		a[ans[i]] = i;
	}
	REP(i, 26) {
		cur -= (365 - a[i])*(364 - a[i]) / 2 * pena[i];
	}
	return cur;

}


int main() {
	cin >> D;

	start = std::chrono::system_clock::now();
	REP(i, 26)cin >> pena[i];
	REP(i, 365)REP(j, 26) {
		cin >> s[i][j];
	}



	REP(i, D) {
		ans[i] = i % 26;
	}


	score = calc();

	REP(_, 2) {
		REP(i, 365) {
			REP(j, 26) {
				int tmp = ans[i];
				ans[i] = j;
				int cur = calc();
				if (cur < score) {
					ans[i] = tmp;
				}
				else score = cur;
			}
		}
	}


	FOR(j, 1, 40) {
		REP(i, 365) {
			if (calc_time() > 1900)break;
			if (j > 364)continue;
			REP(k, 26)REP(l, 26) {
				int tmp1 = ans[i];
				int tmp2 = ans[i + j];
				ans[i] = k;
				ans[i + j] = l;
				int cur = calc();
				if (cur < score) {
					ans[i] = tmp1;
					ans[i + j] = tmp2;
				}
				else score = cur;
			}
		}
	}
	cerr << score << endl;

	REP(i, 365) {
		cout << ans[i] + 1 << endl;
	}

}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define fir first
#define sec second
using namespace std;
const int MAXN = 3007;
const int mod = 1e9 + 7;
const int N = 2e5;
inline int add(int x, int y) {int res = x + y; if (res >= mod) res -= mod; return res;}
inline int mul(int x, int y) {ll res = (ll)x * y; res -= res / mod * mod; return res;}
pii p[MAXN];
int fac[N + 1], inv[N + 1], dp[MAXN];
inline int C(int n, int m) 
{
    if (n < m) return 0;
    return mul(fac[n], mul(inv[m], inv[n - m]));
}
int ksm(int a, int b)
{
    int res = 1;
    while (b)
    {
        if (b & 1) res = mul(res, a);
        a = mul(a, a);
        b /= 2;
    }
    return res;
}
int main()
{
    fac[0] = 1; for (int i = 1; i <= N; i++) fac[i] = mul(fac[i - 1], i);
    inv[N] = ksm(fac[N], mod - 2); for (int i = N; i; --i) inv[i - 1] = mul(inv[i], i);
    int H, W, n; scanf("%d%d%d", &H, &W, &n);
    for (int i = 1; i <= n; i++) scanf("%d%d", &p[i].fir, &p[i].sec);
    sort(p + 1, p + 1 + n);
    for (int i = 1, x, y; i <= n; i++)
    {
        x = p[i].fir, y = p[i].sec;
        dp[i] = C(x - 1 + y - 1, x - 1);
        for (int j = 1; j < i; j++) if (p[j].fir <= x && p[j].sec <= y)
            dp[i] = add(dp[i], mod - mul(dp[j], C(x - p[j].fir + y - p[j].sec, x - p[j].fir)));
    }
    int ans = C(H - 1 + W - 1, H - 1);
    for (int i = 1; i <= n; i++) ans = add(ans, mod - mul(dp[i], C(H - p[i].fir + W - p[i].sec, H - p[i].fir)));
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    vector<vector<int>> cnt(10, vector<int>(10, 0));
    for (int i = 1; i <= n; ++i) {
        string s = to_string(i);
        cnt[s.front()-'0'][s.back()-'0']++;
    }

    int ans = 0;
    for (int i = 0; i < 10; ++i) {
        for (int j = 0; j < 10; ++j) {
            ans += cnt[i][j]*cnt[j][i];
        }
    }
    

    cout << ans << '\n';
    return 0;
} 

Measured memory_bytes: 256
//2018.09.15 1.5min

#include <iostream>
using namespace std;

int main() {

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

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

    return 0;
}

Measured memory_bytes: 256