akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){

    int N,K,a[2],b = 1,i;
    cin >> N >> K;
    
    for(i = 0; i < N; i++) {
        a[0] = b * 2;
        a[1] = b + K;
        b = min(a[0],a[1]);
    }
    
    cout << b << endl;
    return 0;
}


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

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

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VC> VVC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//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 SQ(a) ((a)*(a))
#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())
#define LB lower_bound
#define UB upper_bound

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

//memo
// setprecision()

LL Gcd(LL a, LL b) {
  return __gcd(a,b);
}

LL Lcm(LL a, LL b) {
  LL abd = Gcd(a,b);
  LL x = a / abd, y = b / abd;
  
  return x*y*abd;
}


LL RepSqu(LL N, LL P, LL M) {
  if(P == 0) {
    return 1;
  }
  if(P%2 == 0) {
    LL t = RepSqu(N, P/2, M);
    return t*t % M;
  }
  return (N * RepSqu(N, P-1, M)) % M;
}


int main() {
  
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string S, T;
  cin >> S >> T;
  
  SORT(S);
  SORT(T);
  reverse(ALL(T));
  
  if(S < T) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

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

vector<long long> d(long long n) {
  vector<long long> numbers;
  for (long long i=1; i<=sqrt(n); i++) {
    if (n % i == 0) {
      numbers.push_back(i);
      if (i != n / i) {
        numbers.push_back(n / i);
      }
    }
  }
  return numbers;
}

int main() {
  long long n;
  cin>>n;
  int cnt = d(n-1).size() - 1;
  for (long long a: d(n)) {
    if (a == 1) {
      continue;
    }
    long long m = n;
    while (m % a == 0) {
      m /= a;
    }
    if (m % a == 1) {
      ++cnt;
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>



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

using namespace std;
string s;

int main(){
  cin >> s;
  cout << s[0] << to_string(s.size()-2) << s[s.size()-1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long n;
int main()
{
	cin>>n;
	for(long long i=1;i<=3500;i++)
	{
		for(long long j=1;j<=3500;j++)
		{
			if((4*i*j-i*n-j*n)>0&&(i*j*n)%(4*i*j-i*n-j*n)==0){cout<<i<<" "<<j<<" "<<	(i*j*n)/(4*i*j-i*n-j*n); return 0;}
		}
	}
	return 0;
}

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

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

        long long int next = max(x-a[i], (long long int) 0);
        c[i] += min(x, a[i]);
        a[i] = max(a[i]-x, (long long int) 0);
        c[i+1] += min(next, a[i+1]);
        a[i+1] = max(a[i+1] - next, (long long int) 0);
    }
    cout << accumulate(c.begin(), c.end(), (long long int) 0) << endl;


    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(){
	int w,h,x,y,r;
	scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
	
	if(x>=r&&x<=(w-r)&&y>=r&&y<=(h-r)){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//STANDARD DATA TYPES
#define ll long long
#define llu unsigned long long
#define ld long double
//ADV DATA TYPES
#define pii pair < int , int >
#define pll pair < ll, ll >
#define mp make_pair
#define ff first
#define ss second
//C ++ DS
#define vi vector < int >
#define vll vector < ll >
#define pb push_back
#define pf push_front
#define iter :: iterator
#define all(x) x.begin(),x.end()

//priority_queue < pii, vector < pii >, greater < pii > > pq;
//lower_bound(v.begin(),v.end(),20);//for any sorted container
//CONSTANTS
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define MAXN (int)(1e5+1)
//MOD OPERATIONS
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
inline ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
inline ll addmod(ll a, ll val, ll p = MOD) {{if ((a = (a + val)) >= p) a -= p;} return a;}
inline ll submod(ll a, ll val, ll p = MOD) {{if ((a = (a - val)) < 0) a += p;}return a;}
inline ll mult(ll a, ll b, ll p = MOD) {return (ll) a * b % p;}
//DEBUG
#define shout()  {cout << "I'm Here...!!!" << endl;}
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
int main()
{
	fastio;
	int n,k,used;
	cin>>n>>k;
	ll dp[MAXN+1],diff[MAXN+1];
	for(int child=1;child<=n;child++)
	{
		cin>>used;
		memset(diff ,0 ,sizeof(diff));
		for(int cand=k;cand>=0;cand--)
		{
			if(child==1)
			{
				if(used>=cand)
					dp[cand]=1;
				continue;
			}
			int l=cand;
			int r=min(cand+used,k);
			if(l>r)continue;
			diff[l]=addmod(diff[l],dp[cand]);
			diff[r+1]=submod(diff[r+1],dp[cand]);
		}
		for(int cand=0;cand<=k;cand++)
		{
			if(child==1){
				break;
			}
			if(cand==0)
				dp[cand]=diff[cand];
			else
			{
				dp[cand]=addmod(dp[cand-1],diff[cand]);
			}
		
		//	cout<<dp[cand]<<" ";
		}
		//cout<<endl;
	}
	cout<<dp[k]<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

  int n;
  string s;
  cin >> n >> s;

  int ans = 0;

  for (int i = 0; i < 1000; i++) {
    vector<int> lmr = {i / 100, (i / 10) % 10, i % 10};
    int lmrIdx = 0;

    for (int j = 0; j < n; j++) {
      char c = '0' + lmr[lmrIdx]; // lmr を作れるか、左から右に文字列を探索
      if (s[j] == c) lmrIdx++;
      if (lmrIdx == 3) break;
    }

    if(lmrIdx == 3) ans++;
  }

  cout << ans << endl;

  return 0;
}

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

namespace ABC120B{
	public class Program{
  		public static void Main(){
  			var ABK = Console.ReadLine().Split().Select(int.Parse).ToList();
          	var count = 0;
			var ans = ABK[0]>ABK[1]?ABK[1]:ABK[0];
			while(count != ABK[2]){
				if(ABK[0]%ans == 0&&ABK[1]%ans == 0)count++;
				ans--;
			}
			Console.WriteLine(ans+1);
        }
	}
}

Measured memory_bytes: 11220
n = int(input())
a = []
xy = [[] for i in range(n)]
for i in range(n):
    a.append(int(input()))
    for j in range(a[i]):
        xy[i].append(list(map(int, input().split())))
ans = 0
for i in range(2**n):
    tf = [False for j in range(n)]
    for j in range(n):
        if (i>>j)&1:
            tf[j] = True
    flag = False
    for j in range(n):
        for k in range(a[j]):
            if tf[j]:
                if xy[j][k][1] != tf[xy[j][k][0]-1]:
                    flag = True
                    break
        if flag:
            break
    else:
        ans = max(ans, tf.count(True))
print(ans)

Measured memory_bytes: 9244
import java.util.Scanner;
import java.util.Deque;
import java.util.ArrayDeque;
public class Main {
	public static void main(String args[]){
		Scanner in=new Scanner (System.in);
		Deque<Character> stack=new ArrayDeque<Character>(100);
		String target;
		while (in.hasNext()) {
			target=in.nextLine();
			if (target.length()==1 && target.charAt(0)=='.') {
				break;
			}
			for (int i=0;i<target.length();i++) {
				if (target.charAt(i)=='[' || target.charAt(i)=='(') {
					stack.add(target.charAt(i));
				}
				if(!(stack.isEmpty())){
					if ((stack.getLast()=='[' && target.charAt(i)==']') || (stack.getLast()=='(' && target.charAt(i)==')')) {
						stack.removeLast();
					}else if (target.charAt(i)==']' || target.charAt(i)==')') {
							stack.add(target.charAt(i));
					}
				}else if (target.charAt(i)==']' || target.charAt(i)==')') {
						stack.add(target.charAt(i));
					}
			}
			if (stack.isEmpty()) {
				System.out.println("yes");
			}else{
				System.out.println("no");
				stack.clear();
			}
		}
	}
}

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

long long gcd(long long m, long long n) {
  long long temp = 0;
  while(m % n != 0) {
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

long long lcm(long long m, long long n) { return m * n / gcd(m, n); }

using ll = long long;

ll solve(ll N, ll c, ll d) {
  ll nd = N / d;
  ll nc = N / c;
  ll ncd = N / lcm(c, d);
  return N - (nd + nc - ncd);
}

int main() {
  ll A, B, C, D;
  cin >> A >> B >> C >> D;

  auto ans = solve(B, C, D) - solve(A - 1, C, D);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#define MOD_TYPE 1

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using multiInt = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
*/
/*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
*/
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
//constexpr ll MOD = 1;
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr double PI = acos(-1.0);
constexpr double EPS = 1e-10;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

inline void init_main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
}
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val)
{
  fill((T *)array, (T *)(array + N), val);
}
template <typename T, typename U>
constexpr ostream &operator<<(ostream &os, pair<T, U> &p) noexcept
{
  os << p.first << " " << p.second;
  return os;
}
#pragma endregion

void solve()
{
  int x;
  cin >> x;
  int n;
  cin >> n;
  set<int> st;
  rep(i, n)
  {
    int a;
    cin >> a;
    st.insert(a);
  }
  int ans;
  int i = x;
  while (st.count(i))
    i++;
  ans = i;
  i = x;
  while (st.count(i))
    i--;
  if (abs(i - x) <= abs(ans - x))
    ans = i;
  cout << ans << "\n";
}

int main()
{
  init_main();

  solve();

  return 0;
}


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

int main()
{
  string N;
  cin >> N;

  char N1 = N.at(N.size() - 1);

  vector<char> hon = {'2', '4', '5', '7', '9'};
  vector<char> pon = {'0', '1', '6', '8'};

  if (N1 == '3')
    cout << "bon" << endl;

  for (int i = 0; i < hon.size(); i++)
  {
    if (N1 == hon.at(i))
      cout << "hon" << endl;
  }

  for (int i = 0; i < pon.size(); i++)
  {
    if (N1 == pon.at(i))
      cout << "pon" << endl;
  }
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define pb push_back
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define cps CLOCKS_PER_SEC
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define ll long long
#define ld double
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define fi first
#define se second
#define bitcount(x) __builtin_popcount(x)
#define PI acos(-1.0)
#define EPS 1e-9
#define mod 1000000007

#define par pair<int, int>
#define maxn 505

using namespace std;
///All indexing is 0-based
using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
///methods: find_by_order(k); & order_of_key(k);
///To make it an ordered_multiset, use pairs of (value, time_of_insertion)
///to distinguish values which are similar

ll a, b;
int main()
{
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> a >> b;

    cout << a*b/__gcd(a,b);



}


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

using namespace std;

using vi=vector<int>;


int main(void)
{
	int n, z, w;

	while(scanf("%d%d%d", &n, &z, &w)==3)
	{
		vi a(n);

		for(int i=0;i<n;i++)
		{
			scanf("%d", &a[i]);
		}
		int sx, sy;
		sx=sy=abs(a[n-1]-w);
		if(n>=2) sy=abs(a[n-2]-a[n-1]);

		printf("%d\n", max(sx, sy));
	}

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
static const int N=100;

int main(){
  int n,i,l,k,p[N+1],m[N+1][N+1];
  cin>>n;
  for(i=1;i<=n;i++){
    cin>>p[i-1]>>p[i];
  }
  for(i=1;i<=n;i++)m[i][i]=0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      int j=i+l-1;
      m[i][j]=(1<<21);
      for(k=i;k<=j-1;k++){
	m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
      }
    }
  }
  cout<<m[1][n]<<endl;
  return 0;
}



Measured memory_bytes: 3164
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>
#include <set>
#include <cmath>
#include <functional>

using namespace std;


int main(void)
{
	map <int, int> m;
	int n, temp;

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> temp;
		m[temp] += 1;
		if (m[temp] == 3)
		{
			m[temp] = 1;
		}
	}

	int minus = 0;

	if (m.size() == 1)
	{
		cout << '1' << endl;
		return 0;
	}

	for (auto iter : m)
	{
			minus = minus - (iter.second - 1);
			if (minus < 0)
			{
				minus *= -1;
			}
	}

	cout << m.size() - minus << endl;
	return 0;
}

Measured memory_bytes: 4992
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

func parseProblem() int {
	n, a, b := scanInt(sc), scanInt(sc), scanInt(sc)
	return max((n-2)*(b-a)+1, 0)
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func resolve(n int) int {
	return n
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}


Measured memory_bytes: 1780
#include <iostream>
using namespace std;
using ll = long long;

int main(int argc, char const *argv[]) {
  ll a,b,c,k;
  cin>>a>>b>>c>>k;
  if(a >= k){
    cout << k << endl;
  }else if((a+b) >= k){
    cout << a << endl;
  }else{
    cout << a - (k - a - b) << endl;
  }
  return 0;
}


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

int main(){
	string input;
	int blood[4] = {}, hoge;
	while (scanf("%d,", &hoge) != EOF){
		cin >> input;
		if (input == "A") blood[0]++;
		else if (input == "B") blood[1]++;
		else if (input == "AB") blood[2]++;
		else blood[3]++;
	}
	for (int i = 0; i < 4; i++){
		printf("%d\n", blood[i]);
	}
	return 0;
}

Measured memory_bytes: 1236
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			
			final long RANGE = 100;
			long[] xs = new long[N];
			for(int i = 0; i < N; i++) {
				xs[i] = sc.nextLong();
			}
			
			long answer = Long.MAX_VALUE;
			for(long cx = 0; cx <= RANGE; cx++) {
				long result = 0;
				
				for(final long x : xs) {
					result += (cx - x) * (cx - x);
				}
				
				answer = Math.min(answer, result);
			}
			
			System.out.println(answer);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 20820
#include <stdio.h> 
int main()
{
char input[4];
int cup[3] = {1};
int p1, p2, c, i;     
while (scanf("%s", input) != EOF){
p1 = input[0] - 'A';
p2 = input[2] - 'A';
c = cup[p1];
cup[p1] = cup[p2];
cup[p2] = c;
}
i = 0;
while (1){
if (cup[i] == 1){
printf("%c\n", 'A' + i);
break;
}
i++;
}    
 return 0;
}

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

int main()
{
    int h,w;
    for( ; ; )
    {
        cin >> h >> w;
        if(h==0 && w==0)
        {
            break;
        }
        for(int i=0;i<h;i++)
        {
            for(int j=0;j<w;j++)
            {
                if(i==0 || i==h-1 || j==0 || j==w-1)
                {
                    cout << "#";
                }
                else
                {
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3060
//atcoder clange
#include <stdio.h>

int main(void){
    int A,B;
      scanf("%d", &A);//数値の取得
      scanf("%d", &B);//数値の取得
	if(A >= 13){
		printf("%d",B);
    }else if(A >= 6){
      B = B/2;
		printf("%d",B);
    }else if(A<=5){
		printf("0");
    }

    //int max = max(a, N);
    return 0;
}




Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
template<typename T> inline bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }
const int MAX_N = 575;
const long long INF = numeric_limits<long long>::max()/2;

int main() {
    int n;
    cin >> n;
    vector<long long> a(n), s(n+1, 0);
    auto sum = [&] (int l, int r) { return s[r] - s[l]; };
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        s[i+1] = s[i] + a[i];
    }
    
    long long dp[MAX_N][MAX_N];
    for (int i = 0; i < MAX_N-1; i++) {
        for (int j = 0; j < MAX_N; j++) dp[i][j] = INF;
        dp[i][i] = dp[i][i+1] = 0;
    }
    
    for (int s = 2; s <= n; s++) {
        for (int l = 0; l < n; l++) {
            int r = l + s;
            if (n < r) continue;
            for (int m = l; m <= r; m++) {
                long long cost = sum(l, m) + sum(m, r);
                chmin(dp[l][r], dp[l][m]+dp[m][r]+cost);
            }
        }
    }

    cout << dp[0][n] << endl;
    return 0;
}


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

m=0
for i in range(n-1):
  if a[i+1]==a[i]+1:
    m=m+c[a[i]-1]

print(sum(b)+m)


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args){
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            String line = br.readLine();
            String[] items = line.split("\\s+");
            int N = Integer.parseInt(items[0]);
            int L = Integer.parseInt(items[1]);

            line = br.readLine();
            List<String> list = new ArrayList<>();
            while(line != null){
                list.add(line);
                line = br.readLine();
            }
            Collections.sort(list);
            for(String s : list){
                System.out.print(s);
            }
            System.out.println();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 24404
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define print(x) cout << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T> >
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}

int d[2020][2020];
int main() {
  int h, w;
  cin >> h >> w;
 
  vector<string> G(h);
  rep(i, h) cin >> G[i];
  rep(i, h) {
    int cnt = 0, idx = 0;
    rep(j, w) {
      if (G[i][j] == '.') cnt++;
      if (G[i][j] == '#' || j == w - 1) {
        srep(k, idx, j + 1) d[i][k] += cnt;
        cnt = 0;
        idx = j + 1;
      }
    }
  }
  rep(j, w) {
    int cnt = 0, idx = 0;
    rep(i, h) {
      if (G[i][j] == '.') cnt++;
      if (G[i][j] == '#' || i == h - 1) {
        srep(k, idx, i + 1) d[k][j] += cnt;
        cnt = 0;
        idx = i + 1;
      }
    }
  }
  int ans = 0;
  rep(i,h){
    rep(j,w){
      maxs(ans,d[i][j]);
    }
  }
  cout<<ans-1<<endl;
  return 0;
}

Measured memory_bytes: 26920
#include <bits/stdc++.h>
using namespace std;
int main()
{
    char a[3];
    cin >> a[0] >> a[1] >> a[2];
    for(int i = 0; i < 3; i++)
    {
        if(a[i] == '1') cout << 9;
        else cout << 1; 
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); ++i)
#define repf(i, from, to) for (int i = (from); i < (to); ++i)
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

int n;
V<int> a;

ll solve(bool first_plus) {
  bool will_plus = first_plus;
  ll manip_count = 0;
  int sum = 0;
  rep(i, n) {
    int not_enough = 0;

    if(will_plus) {
      unless(sum + a[i] > 0) {
        not_enough = 1 - (sum + a[i]);
        manip_count += not_enough;
      }
    } else {
      unless(sum + a[i] < 0) {
        not_enough = -1 - (sum + a[i]);
        manip_count += abs(not_enough);
      }
    }

    sum += a[i] + not_enough;
    will_plus = !will_plus;
  }

  return manip_count;
}

int main() {

  cin >> n;
  a.resize(n);

  rep(i, n) {
    cin >> a[i];
  }

  ll first_plus = solve(true);
  ll first_minus = solve(false);
  cout << min(first_plus, first_minus) << endl;
}

Measured memory_bytes: 3692
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define all(a) (a).begin(), (a).end()


int main(){
    int A, B;
    cin >> A >> B;
    int count = 0;
    int socket = 1;
    while(socket < B){
        socket--;
        socket += A;
        count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 3636
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main(){
  ll N;
  cin >> N;
  vector<ll> h(100010);
  rep(i,N){
    cin >> h[i];
  }
  vector<ll> dp(100010,INFL);
  dp[0] = 0;
  for(int i = 1;i <N;i++){
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i]);
    if(i >= 2)dp[i] = min(dp[i-1]+abs(h[i-1]-h[i]),dp[i-2]+abs(h[i]-h[i-2]));
  }
  cout << dp[N-1] << endl;
}


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

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

struct edge {
	int to, cost;
};
vector<edge>g[114514];
int n;

int a[114514];


signed main() {
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		int u, v, w;
		cin >> u >> v >> w;
		u--, v--;
		edge x = { v,w }, y = { u,w };
		g[u].push_back(x);
		g[v].push_back(y);
	}
	rep(i, n) a[i] = inf;
	queue<P>que;
	que.push(P(0, 0));
	while (!que.empty()) {
		P p = que.front();
		que.pop();
		a[p.second] = p.first;
		for (int i = 0; i < g[p.second].size(); i++) {
			edge x = g[p.second][i];
			if (a[x.to] == inf) {
				que.push(P(a[p.second] + x.cost, x.to));
			}
		}
	}
	for (int i = 0; i < n; i++) {
	//out << a[i] << " ";
		if (a[i] % 2 == 0) {
			cout << 0 << endl;
		}
		else {
			cout << 1 << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 8960
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int K = scan.nextInt();
		ArrayList<Integer> list = new ArrayList<>();
		int ans = 0;

		for (int i = 0; i < N; i++){
			int l = scan.nextInt();
			list.add(l);
		}
		Collections.sort(list, Collections.reverseOrder());

		for (int i = 0; i < K; i++){
			ans += list.get(i);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 35612
"use strict";

function main() {
  var i = 0;

  while (true) {
    var H = parseInt(input[i].split(' ')[1], 10);
    culc(input.slice(i, i + H + 1));
    i += H + 1;

    if (input[i] === '0 0') {
      break;
    }
  }
}

function culc(_input) {
  var args = _input;
  var W = args[0].split(' ')[0];
  var H = args[0].split(' ')[1];
  var graph = new Array(H);
  var seen = new Array(H);

  for (var i = 0; i < H; i++) {
    graph[i] = new Array(W);
    seen[i] = new Array(W);
    var line = args[i + 1].split(' ');

    for (var j = 0; j < W; j++) {
      graph[i][j] = line[j];
      seen[i][j] = false;
    }
  }

  var count = 0;

  for (var _i = 0; _i < H; _i++) {
    for (var _j = 0; _j < W; _j++) {
      if (seen[_i][_j]) continue;
      if (graph[_i][_j] == 0) continue;
      count++;
      dfs(graph, seen, _j, _i);
    }
  }

  console.log(count);
}

var dx = [1, 1, 0, -1, -1, -1, 0, 1];
var dy = [0, 1, 1, 1, 0, -1, -1, -1];

function dfs(graph, seen, startx, starty) {
  seen[starty][startx] = true;

  for (var i = 0; i < 8; i++) {
    var nextx = startx + dx[i];
    var nexty = starty + dy[i];
    if (nextx >= graph[0].length || nextx < 0) continue;
    if (nexty >= graph.length || nexty < 0) continue;
    if (graph[nexty][nextx] == 0) continue;
    if (seen[nexty][nextx]) continue;
    dfs(graph, seen, nextx, nexty);
  }
}

var input = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (chunk) {
  input += chunk;
});
process.stdin.on('end', function () {
  input = input.split('\n');
  main();
});


Measured memory_bytes: 17868
#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define setval(arr,v) memset(arr,v,sizeof(arr));
#define lli long long int
#define ll long long
#define mod 1000000009
#define v vector
#define pb push_back
#define pf pop_front;
#define fi first
#define se second
using namespace std;



void solve()
{
	string s;
	cin>>s;
	lli cnt = 0;
	for (int i = 0; i < s.size(); ++i)
	{
		cnt = (cnt+(s[i]-'0'))%9;
	}
	if(cnt == 0)
		cout<<"Yes";
	else
		cout<<"No";



    
}


int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    // cin>>t;
    while(t--)
    {
        solve();

    }
    return 0;

}



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

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

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

int main(void){
    char a[4];
    cin >> a;
    int num = 0;
    for(int i = 1;i < 4;i++){
        if(a[i-1] == a[i])++num;
    }
    if(num == 0)cout << "Good" << endl;
    else cout << "Bad" << endl;
}

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

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

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

class Main {

    public static void main(String[] args) {

	Scanner stdin = new Scanner(System.in);
	long n = stdin.nextLong();

	long sum = 0;
	for ( int i = 0; i < n; i++ ) {
	    sum += stdin.nextLong();
	}
	System.out.println( sum / n );
    }
    
}

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

#define f(a, n) for (int a = 0; a<n; a++)
#define F(a, n) for (int a = 1; a<= n; a++)

int n;
pair<int, int> L[100005], R[100005];
bool V[100005];
int main() {
	ios::sync_with_stdio(0);
	cin>>n;
	f(i, n) cin>>L[i].first>>R[i].first;
	f(i, n) L[i].second = R[i].second = i;
	sort (L, L+n);
	sort (R, R+n);
	long long ans1 = 0, ans2 = 0, pos = 0;
	int rcnt = 0, lcnt = n-1;
	f(i, n){
		if (i%2){ // move right
			while (V[L[lcnt].second]) lcnt--;
			if (pos < L[lcnt].first){
				ans1 += L[lcnt].first - pos;
				pos = L[lcnt].first;
			}
			V[L[lcnt].second] = 1;
		}
		else{ //move left
			while (V[R[rcnt].second]) rcnt++;
			if (pos > R[rcnt].first){
				ans1 -= R[rcnt].first - pos;
				pos = R[rcnt].first;
			}
			V[R[rcnt].second] = 1;
		}
	}
	ans1 += abs(pos);
	f(i, n) V[i] = 0;
	pos = 0;
	rcnt = 0, lcnt = n-1;
	f(i, n){
		if (i%2 == 0){ // move right
			while (V[L[lcnt].second]) lcnt--;
			if (pos < L[lcnt].first){
				ans2 += L[lcnt].first - pos;
				pos = L[lcnt].first;
			}
			V[L[lcnt].second] = 1;
		}
		else{ //move left
			while (V[R[rcnt].second]) rcnt++;
			if (pos > R[rcnt].first){
				ans2 -= R[rcnt].first - pos;
				pos = R[rcnt].first;
			}
			V[R[rcnt].second] = 1;
		}
	}	
	ans2 += abs(pos);
	cout<<max(ans1, ans2)<<endl;
	
}

Measured memory_bytes: 1920
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

void solve(long long N, std::vector<long long> A, std::vector<long long> B){
    vll sortA = A, sortB = B;
    sort(ALL(sortA)); sort(ALL(sortB));
    if(N % 2){
        cout<< sortB[N/2] - sortA[N/2] + 1 << endl;
    }
    else{
        cout<< sortB[N/2] + sortB[(N-1)/2] - (sortA[N/2] + sortA[(N-1)/2]) + 1 << endl;
    }
}
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(N, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 9168
N,M,X,Y=map(int,input().split())
x=max(map(int,input().split()))
y=min(map(int,input().split()))
P=0
for i in range(X+1,Y+1) :
  if  x < i and i <= y :
    print("No War")
    break
else:
  print("War")

Measured memory_bytes: 3060
W,H,x,y,r = list(map(int, input().split()))
answer = 'Yes'
if x<r:
    answer = 'No'
if y<r:
    answer = 'No'
if W < x+r:
    answer = 'No'
if H < y+r:
    answer = 'No'
print(answer)



Measured memory_bytes: 5596
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
#define rp(i,n) for(int i=0;i< n;i++)
#define rpd(i,n) for(int i=n-1;i >= 0;i--)

using namespace std;


ll a[26];

int main() {

	string s;
	cin >> s;
	rp(i,s.length()){
		a[s[i] - 'a'] ++;
	}
	rp(i,26) if(a[i] %2 != 0) {
		cout << "No"<<endl; return 0;

	}
	cout << "Yes";
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn=1010;
int i,j,k;
struct node
{
    ll a,b,c;
    node(ll _a=0,ll _b=0,ll _c=0)
    {
        a=_a;b=_b;c=_c;
    }
    bool operator<(const node &A)const
    {
        return abs(a)+abs(b)+abs(c)<abs(A.a)+abs(A.b)+abs(A.c);
    }
    node operator+(const node &A)const
    {
        return node(a+A.a,b+A.b,c+A.c);
    }
}a[maxn];
int n,m;

bool cmp(node a,node b)
{
    return a.a*i+a.b*j+a.c*k<b.a*i+b.b*j+b.c*k;
}

ll solve()
{
    node ans;
    for(i=-1;i<=1;i+=2)
    {
        for(j=-1;j<=1;j+=2)
        {
            for(k=-1;k<=1;k+=2)
            {
                sort(a+1,a+1+n,cmp);
                node sum;
                for(int I=1;I<=m;I++)
                    sum=sum+a[I];
                ans=max(ans,sum);
            }
        }
    }
    return abs(ans.a)+abs(ans.b)+abs(ans.c);
}

int main()
{
    //freopen("input.txt","r",stdin);
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%lld %lld %lld",&a[i].a,&a[i].b,&a[i].c);
    printf("%lld\n",solve());
    return 0;
}


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

int main() 
{
    int n;
    cin >> n;
    int h[n];
    rep(i,n) cin >> h[i];

    int top = 0;
    int ans = 0;
    rep(i,n) {
        if (top <= h[i]) ans++;
        top = max(top, h[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
L = list(map(int, input().split()))
K = -1
bool1 = True

while(bool1 == True):
    K +=1
    for k in range(n):
        if L[k] %2 ==0:
            L[k] = L[k]/2

        else:
            bool1 = False
            break

print(K)

Measured memory_bytes: 3060
#include <iostream> 
#include <vector> 
#include <algorithm> 
#include <bits/stdc++.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <functional> 
#include<math.h> 
#include<cstring>
using namespace std;
int main(void){
    // Your code here!
    int a,b,k;
    cin >> a >> b >>k;
    vector<int> vec(110);
    int m = 0;
    for(int i = 100; i > 0; i--){
        if(a % i == 0 && b % i == 0){
            vec.at(m) = i;
            m++;
        }
    }
    cout << vec.at(k-1) << endl;
    
    
    
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int INF = 1<<29;

int dp[256][16][128];
int stones[256][16][2];
int col[256];

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  while (true) {
    int N, M;
    cin >> N >> M;
    if (N == 0 && M == 0) break;
  
    REP(i, N) {
      cin >> col[i];
      REP(j, col[i]) {
	cin >> stones[i][j][0] >> stones[i][j][1];
      }
    }

    REP(i, N) REP(j, col[i]) REP(k, M+1) dp[i][j][k] = INF;
    REP(j, col[0]) dp[0][j][0] = 0;
    REP(j, col[1]) dp[1][j][1] = 0;
    REP(i, N-1) {
      REP(j, col[i]) {
	int x_now = stones[i][j][0], d_now = stones[i][j][1];
	REP(m, M+1) {
	  if (dp[i][j][m] == INF) continue;
	  REP(k, col[i+1]) {
	    int x_next = stones[i+1][k][0], d_next = stones[i+1][k][1];
	    int safe = (d_now + d_next) * abs(x_now - x_next);
	    dp[i+1][k][m] = min(dp[i+1][k][m], dp[i][j][m] + safe);
	  }
	  if (i < N-2 && m < M) {
	    REP(k, col[i+2]) {
	      int x_next = stones[i+2][k][0], d_next = stones[i+2][k][1];
	      int safe = (d_now + d_next) * abs(x_now - x_next);
	      dp[i+2][k][m+1] = min(dp[i+2][k][m+1], dp[i][j][m] + safe);
	    }
	  }
	}
      }
    }

    int ans = INF;
    REP(j, col[N-1]) REP(m, M+1) ans = min(ans, dp[N-1][j][m]);
    REP(j, col[N-2]) REP(m, M) ans = min(ans, dp[N-2][j][m]);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 2416
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#include <iomanip>
#define REP(_i,_a,_n) for(int _i=_a;_i<=_n;++_i)
#define PER(_i,_a,_n) for(int _i=_n;_i>=_a;--_i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 998244353, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head


const int N = 1e6+10;
int n,cnt[N],mu[N],f[N];

int main() {
	mu[1]=1;
	for(int i=1;i<N;++i) {
		for (int j=2*i;j<N;j+=i) mu[j]-=mu[i];
	}
	scanf("%d", &n);
	int ans = 0, M = 0;
	REP(i,1,n) {
		int t;
		scanf("%d", &t);
		++cnt[t];
		ans = (ans-t)%P;
		M = max(M, t);
	}
	REP(i,1,M) PER(x,1,M/i) f[i]=(f[i]+(ll)x*cnt[i*x])%P;
	REP(i,1,M) PER(d,1,M/i) if (mu[d]) { 
		int ret = f[i*d];
		ans = (ans+mu[d]*i*(ll)d%P*d%P*ret%P*ret)%P;
	}
	ans = (ll)ans*(P+1)/2%P;
	if (ans<0) ans += P;
	printf("%d\n", ans);
}







Measured memory_bytes: 15492
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <cassert>

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

int main() {
    int N, M;
    cin >> N >> M;

    vector<int> vp(M);
    vector<int> vy(M);
    map<int, vector<int>> m;
    rep(i, M) {
        cin >> vp[i];
        cin >> vy[i];
        m[vp[i]].push_back(vy[i]);
    }

    for(auto& itr: m) {
        sort(itr.second.begin(), itr.second.end());
    } 

    int P, Y;
    rep(i, M) {
        P = vp[i];
        Y = vy[i];
        auto it = lower_bound(m[P].begin(), m[P].end(), Y);
        auto ret = (it - m[P].begin()) + 1;
        printf("%06d%06d\n", P, (int)ret);

    }

    return 0;
}



Measured memory_bytes: 14388
package main

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

func main()  {
	sc := bufio.NewScanner(os.Stdin)
	
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	flag := "No"
	for x4 := 0; x4 <= 100; x4++ {
		for x7 := 0; x7 <= 100; x7++ {
			if x4*4 + x7*7 == n {
				flag = "Yes"
			}
		}
	}
	fmt.Println(flag)
}

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

int main()
{
    int n, l;
    cin >> n >> l;
    vector<string> s(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> s[i];
    }
    sort(s.begin(), s.end());
    for (auto item : s)
        cout << item;
}


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

int main(){
    char x;
    cin >> x ;
    
    // if(x == 'a' || x == 'i' || x == 'u' || x == 'e' || x == 'o') cout << "vowel" << endl;
    // else cout << "consonant" << endl;

    const string a = "aiueo";

    cout << ((a.find(x) != string::npos) ? "vowel" : "consonant") << endl;
    // cout << (a.find(x) == string::npos) << endl;


    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

priority_queue<ll> divisor(ll n) {
    priority_queue<ll> ret;
    ret.push(1);
    double sq = sqrt(n);
    for(ll i = 1; i <= sq; i++) {
        if(n % i == 0) {
            ret.push(i);
            ret.push(n / i);
        }
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    priority_queue<ll> A = divisor(M);
    while(A.top() * N > M)
        A.pop();
    cout << A.top() << endl;
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

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

	int n, l;cin >> n >> l;

	ll sum = n * (n - 1) / 2 + n * l;
	ll ans, sa = INF;
	REP(i, n){
		ll tmp = sum - (i + l);
		if(abs(sum - tmp) < sa){
			sa = abs(sum - tmp);
			ans = tmp;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
n = int(input())
c = []
s = []
f = []
for i in range(n-1):
    ci, si, fi = map(int, input().split())
    c.append(ci)
    s.append(si)
    f.append(fi)
c.append(0)
s.append(0)
f.append(0)

for i in range(n):
    s_total = 0
    for j in range(i, n-1):
        if s_total < s[j]:
            s_total += s[j] - s_total
        tmp = (s[j] - s_total) % f[j]
        s_total += tmp
        s_total += c[j]

    print(s_total)

Measured memory_bytes: 3064
n,k = map(int,input().split())
a = list(map(int,input().split()))
b0 = [n]*41
b1 = [0]*41
ans = 0
temp = 0
for i in a:
    bit = bin(i)
    for j in range(len(bit)-2):
        t = (int(bit[-j-1]) == 1)
        b0[-j-1] -= t
        b1[-j-1] += t
# print(b1)
# print(b0)
for i in range(41):
    if temp + 2**(40-i) <= k and b0[i] > b1[i]:
        temp += 2**(40-i)
        ans += 2**(40-i) * b0[i]
    else:
        ans += 2**(40-i) * b1[i]

print(ans)

Measured memory_bytes: 69392
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
import re
import math
import collections
import itertools
import functools

DEBUG = True
DEBUG = False

def dbg(*args):
    if DEBUG:
        print("DBG: ", file=sys.stderr, end="")
        print(*args, file=sys.stderr)


def possible(N, M, k):
    if N >= k:
        return M >= 2*k
    else:
        M -= 2*(k-N)
        return M >= 2*k

def main():
    N, M = map(int, input().split())

    # cc -> S はできるが S -> cc はできない

    # [lo, hi)
    # lo では必ず可能、hiでは必ず不可能
    hi = M // 2 + 1
    lo = M // 4
    while hi - lo > 1:
        mid = (hi + lo) // 2
        if possible(N, M, mid):
            lo = mid
        else:
            hi = mid

    print(lo)

if __name__ == "__main__": main()


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

int main() {
	long long n,a,b;
	long long ans = 0;
	cin >> n >> a >> b;
	ans = (b-a) * (n-2) + 1;
	if(n == 1){
		if(a != b){
		 ans = 0;
		}else{
			ans = 1;
		}
	}
	ans = (ans > 0 ? ans : 0);

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


Measured memory_bytes: 256