akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<unistd.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long ull;
typedef double db;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef map<int,int> MI;
typedef vector<vector<int,int>> VII;
typedef pair<int,pair<int,int>> PII;

#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define mp make_pair
#define repa(i,a,n) for(ll i=a;i<n;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define pera(i,a,n) for(ll i=a;i>=n;i--)
#define per(i,n) for(ll i=n;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define MS0(x) memset((x), 0, sizeof((x)))
#define MS1(x) memset((x), -1, sizeof((x)))
#define MEM(a, b) memset(a, b, sizeof(a))
#define SZ(x) ((ll)(x).size())
#define TIME    cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";

const ll mod=1e9+7;
const double pi=acos(-1);

ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll power(ll a,ll b,ll p) //log(n)
{
    if(b==0) return 1;
    ll c = power(a,b/2,p);
    if(b%2==0) return (c*c)%p;
    else return (((c*c)%p)*a)%p;
}
ll inv(ll n, ll p){ return power(n,p-2, p); }
bool isPrime(ll n) {
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
            return false;
    return true;
}


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

    string s,t;
  	cin>>s>>t;
    if(t.substr(0,SZ(s))!=s)cout<<"No";
    else cout<<"Yes";
    return 0;
}


Measured memory_bytes: 3636
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
def ddprint(x):
  if DBG:
    print(x)

s = input()
sum = 0
k = len(s)
for i in range(k):
    if s[i] == 'x':
        sum += 1
print('YES' if sum <= 7 else 'NO')


Measured memory_bytes: 3444
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

#define MOD 1000000007;

int main(){
	string s, t;
	cin >> s >> t;
	for(int i=0 ; i<s.size(); i++){
		bool jdg = true;
		for(int j=0; j<s.size(); j++){
			if(s[(j+i)%s.size()]!=t[j])
				jdg = false;
		}
		if(jdg){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	a, b := nextInt(), nextInt()
	ans := 0
	for i := a; i <= b; i++ {
		if isPal(i) {
			ans++
		}
	}
	puts(ans)
	wt.Flush()
}

func isPal(n int) bool {
	s := strconv.Itoa(n)
	for i := 0; i < len(s)/2; i++ {
		if s[i] != s[len(s)-1-i] {
			return false
		}
	}
	return true
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

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

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func nextMega() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,sum=0,cnt=0;
	cin>>n;
	vector<int>v(n);
	for(int i=0;i<n;i++) cin>>v.at(i);
	sort(v.begin(),v.end());
	 for(int i=0;i<n;i++){
		sum+=v.at(i);
		if(v.at(i)%10==0){
			cnt++;
		}
	 }
	 if(cnt==n){
		 cout<<0<<endl;
		 return 0;
	 }
	 if(sum%10==0){
		 for(int i=0;i<n;i++){
			 if(sum%10==0){
				 if(v.at(i)%10!=0){
					 sum-=v.at(i);
				 }
			 }
		 }
	 }
	cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <iostream>

unsigned long long aoki(unsigned long long  x, unsigned long long K){
	return x>K ? x-K : K-x;
}

int main(){
	unsigned long long N, K, x, min, tmp;
	std::cin >> N >> K;

	tmp = N / K;
	x = N - tmp*K;
	while(x > K){
		x = x>K ? x-K : K-x;
	}

	min = x;
	min = aoki(x, K) < x ? aoki(x,K) : x;

	std::cout << min << std::endl;

	return 0;
}

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

vector<int>Z(string s){
	vector<int>z(s.size());
	z[0]=s.size();
	int i=1,j=0;
	while(i<s.size()){
		while(i+j<s.size()&&s[j]==s[i+j])j++;
		if(j==0){
			z[i]=0;i++;continue;
		}
		z[i]=j;
		int k=1;
		while(i+k<s.size()&&k+z[k]<z[i]){
			z[i+k]=z[k];
			k++;
		}
		i+=k;
		j-=k;
	}
	return z;
}

vector<int>E[2000000];
int deg[2000000];
int d[2000000];

int main(){
	string s,t;cin>>s>>t;
	while(s.size()<t.size())s+=s;
	auto v=Z(t+s+s);
	for(int i=t.size();i<t.size()+s.size();i++){
		if(v[i]>=t.size()){
			int a=i-t.size(),b=(a+t.size())%s.size();
			E[b].push_back(a);
			deg[a]=1;
		}
	}
	memset(d,-1,sizeof(d));
	queue<int>que;
	rep(i,s.size()){
		if(!deg[i]){
			d[i]=0;
			que.push(i);
		}
	}
	while(!que.empty()){
		int p=que.front();que.pop();
		for(int u:E[p]){
			if((--deg[u])==0){
				d[u]=d[p]+1;
				que.push(u);
			}
		}
	}
	if(*min_element(d,d+s.size())==-1)puts("-1");
	else cout<<*max_element(d,d+s.size())<<endl;
}

Measured memory_bytes: 103124
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,t;
  cin >> n >> t;
  vector<int> a(n);
  ll ans=t;
  for(int i=0;i<n;++i){
    cin >> a[i];
	}
  for(int i=0;i<n-1;++i){
    ans+=min(t,a[i+1]-a[i]);
  }
  cout << ans <<endl;
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
main()
{
    int k,n,mx=0,i;
    scanf("%d%d",&k,&n);
    int a[n+1];
    for(i=0;i<n;i++) scanf("%d",&a[i]);
    for(i=1;i<n;i++)
    mx=max(mx,a[i]-a[i-1]);
    mx=max(mx,k-a[n-1]+a[0]);
    printf("%d\n",k-mx);
    
}

Measured memory_bytes: 1024
fun main(args: Array<String>) {
    val K = readLine()!!.toInt()
    val inputArray = readLine()!!.split(" ")
    val A = inputArray[0].toInt()
    val B = inputArray[1].toInt()

    for (i in A..B) {
        if (i % K == 0) {
            println("OK")
            return
        }
    }
    println("NG")
}


Measured memory_bytes: 35524
/* I can do this all day. Never Give Up! */
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define M 1000000007
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define MAX 1000000
#define inf 0x7fffffff
using namespace std;
typedef long long int ll;
typedef long double  ld;
typedef unsigned long long int ull;
ll dx[]={-1,0,1,0,-1,1,1,-1};
ll dy[]={0,1,0,-1,1,1,-1,-1};

ll g[200005];
int main()
{

     IOS;
     //freopen("input.txt", "r", stdin);
     //freopen("output.txt", "w", stdout);

     ll n,k,i,ans=0;
     cin >> n >> k;
     for(i=1;i<=n;i++)
     {
         g[i%k]++;
     }

     for(i=1;i<=k-1;i++)
     {
         if((2*(k-i))%k == 0)
         ans += g[i]*g[k-i]*g[k-i];

     }
     ans += max(0LL,g[0]*(g[0])*(g[0]));
     cout << ans;


     return 0;
}


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

#整数値入力 1文字の入力
def input_one_number():
    return int(input())

#整数値龍力　複数の入力
def input_multiple_number():
    return map(int, input().split())

#整数値龍力　複数の入力(配列)
def input_multiple_number_as_list():
    return list(map(int, input().split()))


a= input_multiple_number_as_list()
b= input_multiple_number_as_list()
c = input_multiple_number_as_list()

n= input_one_number()

for i in range(n):
    bq = input_one_number()
    for j in range(3):
        if a[j] == bq:
            a[j] = -1
        if b[j] == bq:
            b[j] = -1
        if c[j] == bq:
            c[j] = -1

if (a[0] == -1 and b[0] == -1 and c[0] == -1) or(a[1] == -1 and b[1] == -1 and c[1] == -1) or (a[2] == -1 and b[2] == -1 and c[2] == -1) or(a[0] == -1 and a[1] == -1 and a[2] == -1) or(b[0] == -1 and b[1] == -1 and b[2] == -1) or(c[0] == -1 and c[1] == -1 and c[2] == -1) or(a[0] == -1 and b[1] == -1 and c[2] == -1) or(a[2] == -1 and b[1] == -1 and c[0] == -1) :
    print("Yes")
else:
    print("No")



Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < i##_len; ++i)

int main()
{
    ll a, b, x;
    cin >> a >> b >> x;
    ll res = b/x;
    if(a > 0) res -= (a-1)/x;
    else res += 1;
    cout << res << endl;
    return 0;
}

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

struct NUM {
    int a;
    int b;

    bool operator<( const NUM& right ) const {
        return a < right.a;
    }
};

int main() {
    int n;
    long long k;
    vector<NUM> num;
    cin >> n >> k;
    for(int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        NUM temp;
        temp.a = a, temp.b = b;
        num.push_back(temp);
    }
    sort(num.begin(), num.end());
    long long sum = 0;
    for(int i = 0; i < n; i++) {
        sum += num[i].b;
        if(sum >= k) {
            printf("%d\n", num[i].a);
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 1400
import java.util.Scanner;
import java.util.ArrayList;
	
public class Main {
	public static void main(String[] args) {
		Scanner scanline = new Scanner(System.in);
		while(scanline.hasNext()){
			String twoDates = scanline.nextLine();
			Scanner scandate = new Scanner(twoDates);
			int y1 = scandate.nextInt();
			int m1 = scandate.nextInt();
			int d1 = scandate.nextInt();
			int y2= scandate.nextInt();
			int m2 = scandate.nextInt();
			int d2 = scandate.nextInt();
			if(y1<0 || m1<0 || d1<0 || y2<0 || m2<0 || d2<0){
				break;
			}
			int datesInYear;
			if(leapyear(y1)){
				datesInYear = 366;
			}else{
				datesInYear = 365;
			}
			int number1 = countDatesByYMD(y1,m1,d1);
			int number3 = countDatesByYMD(y2,m2,d2);
			int number2 = countDatesByYear(y1,y2);
			int totalDates = - number1 + number2 + number3;
			if(y1==y2){
				System.out.println(""+(number3-number1));
			}
			else if(y2-y1==1){
				System.out.println(""+(datesInYear-number1+number3));
			}
			else{
				System.out.println(""+(totalDates + datesInYear));
			}
		}
	}
	public static int countDatesByYear(int y1,int y2){
		if(y2-y1<=1){
			return 0;
		}else{
			int dates=0;
			int datesInYear;
			for (int i=y1+1;i<y2;i++){
				if(leapyear(i)){
					datesInYear = 366;
				}else{
					datesInYear = 365;
				}
				dates += datesInYear;
			}
			return dates;
		}
	}
	public static int countDatesByYMD(int year,int month,int day){
		int dates=0;
		if(leapyear(year)){
		switch(month){
			case 1:
				dates = day;
				break;
			case 2:
				dates = 31+day;
				break;
			case 3:
				dates = 60+day;
				break;
			case 4:
				dates = 91+day;
				break;
			case 5:
				dates = 121+day;
				break;
			case 6:
				dates = 152+day;
				break;
			case 7:
				dates = 182+day;
				break;
			case 8:
				dates = 213+day;
				break;
			case 9:
				dates = 244+day;
				break;
			case 10:
				dates = 274+day;
				break;
			case 11:
				dates = 305+day;
				break;
			case 12:
				dates = 335+day;
				break;
		}
		}else{
			switch(month){
			case 1:
				dates = day;
				break;
			case 2:
				dates = 31+day;
				break;
			case 3:
				dates = 59+day;
				break;
			case 4:
				dates = 90+day;
				break;
			case 5:
				dates = 120+day;
				break;
			case 6:
				dates = 151+day;
				break;
			case 7:
				dates = 181+day;
				break;
			case 8:
				dates = 212+day;
				break;
			case 9:
				dates = 243+day;
				break;
			case 10:
				dates = 273+day;
				break;
			case 11:
				dates = 304+day;
				break;
			case 12:
				dates = 334+day;
				break;			
		}
		}
		return dates;
	}
	public static boolean leapyear(int year){
		if (year%4 == 0){
			if (year%100 == 0){
				if (year%400 ==0 ){
					return true;
				}
				else{
					return false;
				}
			}else{
				return true;
			}
		}else{
			return false;
		}
	}
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;


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

    for(int i = 1; i <= n; i++){
        if((int)(i * 1.08) == n){
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;

    return 0;
}


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

using std::cin;
using std::cout;
using std::endl;
using std::vector;

int main() {
    int n,q,op,t,x;
    cin >> n >> q;
    vector< vector<int> > vector_array(n);
    while (q--) {
        cin >> op >> t;
        switch (op) {
            case 0:
                cin >> x;
                vector_array[t].push_back(x);
                break;
            case 1:
                for (auto itr = vector_array[t].begin();itr != vector_array[t].end();++itr) {
                    cout << *itr;
                    if (itr + 1 != vector_array[t].end()) {
                        cout << " ";
                    }
                }
                cout << endl;
                break;
            default:
                vector_array[t].clear();
        }
    }
}


Measured memory_bytes: 5784
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int64_t n,p;
  cin>>n>>p;
  vector<int64_t> odd{0},even{1};
  for (int i = 1; i <= n; ++i)
  {
    int64_t tmp;
    cin>>tmp;
    int64_t o=odd.back(),e=even.back();
    if(tmp%2==0) //even
    {
      odd.push_back(2*o);
      even.push_back(2*e);
    }
    else //odd
    {
      odd.push_back(e+o);
      even.push_back(e+o);
    }
  }
  cout<<(p==0? even.back():odd.back());
}

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
s = 0
for i in a:
  s += b[i-1] 
  if i -1 == a[a.index(i)-1] and a.index(i)>0:
    s+= c[i-2]
print(s)

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

#define fi first
#define se second
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()

using LL = long long;
using LD = long double;
using pii = pair<int, int>;
using vii = vector<pii>;

const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 404;

int a[N], csum[N];
int dp[N][N];

int sum(int l, int r) {
    return csum[r] - csum[l - 1];
}

int solve(int l, int r) {
    if (l == r) {
        return 0;
    }

    if (dp[l][r] != -1) {
        return dp[l][r];
    }

    int ans = INF;
    for (int i = l; i < r; i++) {
        ans = min(ans, solve(l, i) + solve(i + 1, r) + sum(l, r));
    }

    return dp[l][r] = ans;
}

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);

    int n;
    cin >> n;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        csum[i] = csum[i - 1] + a[i];
    }

    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            dp[i][j] = -1;
        }
    }

    cout << solve(1, n) << "\n";
}

Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <bitset>
#include <string>
#include <array>
#include <random>
#include <chrono>
#include <algorithm>

int64_t dp[2000][2000];
int main(void){
	int n;
	std::cin >> n;
	std::vector<std::pair<int64_t, int64_t>> ab(n);
	for(int i=0;i<n;i++)std::cin >> ab[i].first >> ab[i].second;

	std::sort(ab.begin(), ab.end(), [](const std::pair<int64_t, int64_t>& lhs, const std::pair<int64_t, int64_t>& rhs){
		return lhs.second < rhs.second;
	});
	int64_t time = 0;
	bool ok = true;
	for(int i=0;i<n;i++){
		time += ab[i].first;
		if(time > ab[i].second){
			ok = false;
			break;
		}
	}
	std::cout << (ok? "Yes" : "No") << std::endl;
}


Measured memory_bytes: 3328
import sys
import numpy as np
from math import ceil as C, floor as F, sqrt
from collections import defaultdict as D, Counter as CNT
from functools import reduce as R
 
ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())

n = S()
print('ABC' if n == 'ARC' else 'ARC')

Measured memory_bytes: 27016
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX = 1e6;
const int MOD = 1e9 + 7;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
	int x, y; cin >> x >> y;
	ll res = 0;
	if ((x + y) % 3 == 0) {
		int n = (x + y) / 3;
		int k = min(x, y) - n;
		COMinit();
		res = COM(n, k);
	}
	cout << res << '\n';
    return 0;
}


Measured memory_bytes: 27024
#include<stdio.h>
#include<stdlib.h>

int main()
{
	int x;
	int answer = 1;
	scanf("%d", &x);

		if (x % 2 == 0)
		{
			answer = x;
			goto exit;
		}
		else
		{
			answer = 2 * x;
		}
exit:
	printf("%d", answer);


	return 0;
}

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

int main(){
  string s;
  cin >> s;
  int a1,a2;
  int ans;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == 'A'){ a1 = i; break; }
  }
  for(int i = s.size() - 1; i >= 0; i--){
    if(s[i] == 'Z') { a2 = i; break; }
  }
  cout << a2 - a1 + 1 << endl;
}

Measured memory_bytes: 3752
import math
N, K = map(int, input().split())
S = list(map(int, input().split()))
d = [[0]*(N+1) for _ in range(math.ceil(math.log2(K)))]

for i in range(N):
    d[0][i+1] = S[i]

for i in range(1, math.ceil(math.log2(K))):
    for j in range(1, N+1):
        d[i][j] = d[i-1][d[i-1][j]]

ans = 1
for i in range(math.ceil(math.log2(K))):
    if (K >> i)&1:
        ans = d[i][ans]
print(ans)


Measured memory_bytes: 174424
from collections import Counter

while True:
    n=int(input())
    if n==0:
        break

    scores=[]
    for i in range(n):
        s=input().split(" ")
        team=s[0]
        score=s[1:]
        c=Counter(score)
        c=dict(c)
        result=[team,c.get('0',0),c.get('1',0),c.get('2',0)]
        scores.append(result)
    scores=sorted(scores,key=lambda w: w[1]*100+w[3],reverse=True)
    for s in scores:
        print(s[0])



Measured memory_bytes: 5996
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head

int bin(vector<int> &a, int target){
    int l = 0, r = sz(a)-1;

    while (r >= l){
        int m = (l+r)/2;
        if (a[m] == target) return m;
        if (a[m] > target) r = m-1;
        else l = m+1;
    }
    return -1;
}

void solve(){
    string s;
    cin >> s;
    if (s.find("AB") == string::npos && s.find("BA") == string::npos) cout << "No\n";
    else cout << "Yes\n";
}

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

    //int t; cin >> t; while (t--)
        solve();
}

Measured memory_bytes: 3588
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main(){
  int n;
  double num,bt_sum=0,jp_sum=0;
  string u;
  cin >>n;
  for(int i=0;i<n;i++){
    cin >> num >> u;
    if(u=="JPY"){
      jp_sum+=num;
      }else{
        bt_sum+=num;
      }
  }
  jp_sum+=bt_sum*380000.0;
  printf("%lf\n",jp_sum);
}



Measured memory_bytes: 256
#include<cstdio>
inline int min(const int x,const int y){return x<y?x:y;}
char col[105][105];
bool c[105][105];
int f[105][105][105][105];
int main(){
	int h,w;
	scanf("%d%d",&h,&w);
	for(int i=1;i<=h;++i)scanf("%s",col[i]+1);
	for(int i=1;i<=h;++i)for(int j=1;j<=w;++j)
			f[i][j][i][j]=c[i][j]=col[i][j]=='#'?1:0;
	for(int i=1;i<h;++i)for(int j=1;j<w;++j){
			for(int k=i;k<=h;++k)for(int l=j;l<=w;++l){
				if(k!=i || l!=j)f[i][j][k][l]=100000000;
				if(l!=j)if(c[k][l-1] || !c[k][l])
						f[i][j][k][l]=min(f[i][j][k][l],f[i][j][k][l-1]);
					else f[i][j][k][l]=min(f[i][j][k][l],f[i][j][k][l-1]+1);
				if(k!=i)if(c[k-1][l] || !c[k][l])
						f[i][j][k][l]=min(f[i][j][k][l],f[i][j][k-1][l]);
					else f[i][j][k][l]=min(f[i][j][k][l],f[i][j][k-1][l]+1);
			}
	}
	return printf("%d\n",f[1][1][h][w]),0;
}

Measured memory_bytes: 452736
n = int(input())
e = [0 for i in range(n+1)]
for i in range(2,n+1):
    cur = i
    for j in range(2,i+1):
        while cur%j==0:
            e[j] += 1
            cur //= j

def num(m):
    return len(list(filter(lambda x: x >= m-1, e)))

print(num(75)+num(25)*(num(3)-1)+ num(15)*(num(5)-1)+num(5)*(num(5)-1)*(num(3)-2)//2)


Measured memory_bytes: 3064
/*
  Aizu Vol-0 0098: Maximum Sum Sequence II 
  2017.8.15 bal4u@uu
  ????????????????????§???
*/

#include <stdio.h>

#define MAX 100

int a[MAX + 5][MAX + 5], N;
int s[MAX + 5][MAX + 5];

int main()
{
	int r, c, r2, c2, k, max;

	scanf("%d", &N);
	for (r = 1; r <= N; r++) for (c = 1; c <= N; c++) scanf("%d", a[r] + c);
	for (r = 1; r <= N; r++)
		for (s[r][1] = a[r][1], c = 2; c <= N; c++) s[r][c] += s[r][c-1] + a[r][c];
	max = a[1][1];
	for (r = 1; r <= N; r++) for (c = 1; c <= N; c++) {
		for (c2 = c; c2 <= N; c2++) {
			k = s[r][c2] - s[r][c - 1];	if (k > max) max = k;
			for (r2 = r + 1; r2 <= N; r2++) { k += s[r2][c2] - s[r2][c - 1]; if (k > max) max = k; }
		}
	}
	printf("%d\n", max);
	return 0;
}

Measured memory_bytes: 684
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std;
long long A, B;
int K;
int mapp[210];
int main()
{
    scanf("%lld%lld%d", &A, &B, &K);
    if(A>B)
    {
        int t;
        t = A;
        A = B;
        B = t;
    }
    if((B-A+2)/2<=K)
    {
        int sum = A;
        for(int i=0; i<(B-A+1); i++)
        {
            printf("%d\n", sum++);
        }
    }
    else
    {
        mapp[0] = A;
        mapp[2*K-1] = B;
        for(int i=1; i<=K-1; i++)
        {
            mapp[i] = mapp[i-1]+1;
        }
        for(int i=(2*K-2); i>=K; i--)
        {
            mapp[i] = mapp[i+1]-1;
        }
        for(int i=0; i<2*K; i++)
        {
             printf("%d\n",mapp[i]);
        }
    }
    return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0)
#define mapmax(v) v.rbegin()->first
#define mapmin(v) v.begin()->first
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<string> vs;

typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

void YES(bool b) {cout << (b?"YES\n":"NO\n");}
void Yes(bool b) {cout << (b?"Yes\n":"No\n");}
void yes(bool b) {cout << (b?"yes\n":"no\n");}
void Yay(bool b) {cout << (b?"Yay!\n":":(\n");}

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}



int main()
{
	ll n,k;
	cin >> n >> k;
	cout << min(n%k,abs(n%k-k)) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, j, n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;
 
typedef long long i64;
typedef pair<int, int> pi;
 
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);}

int n;
int ans;

void dfs(string s) {
  if(s.size() > 0 && stoll(s) > n) return;

  if(count(all(s), '7') && count(all(s), '5') && count(all(s), '3')) ans++;

  dfs(s + '3');
  dfs(s + '5');
  dfs(s + '7');
}

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

  cin >> n;
  dfs("");
  cout << ans << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#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 <bitset>

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

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////

void solve() {
	int N,K;
	cin >> N >> K;
	vector<LL> X(N), Y(N);
	for (int i = 0; i < N; ++i) {
		cin >> X[i] >> Y[i];
	}
	LL ans = LINF;
	for (int x0 = 0; x0 < N; ++x0) {
		for (int x1 = 0; x1 < N; ++x1) {
			for (int y0 = 0; y0 < N; ++y0) {
				for (int y1 = 0; y1 < N; ++y1) {
					int cnt = 0;
					for (int i = 0; i < N; ++i) {
						if (X[x0] <= X[i] && X[i] <= X[x1] &&
							Y[y0] <= Y[i] && Y[i] <= Y[y1]) {
							++cnt;
						}
					}
					if (cnt >= K) {
						LL res = (X[x1] - X[x0]) * (Y[y1] - Y[y0]);
						if (ans > res) {
							ans = res;
						}
					}
				}
			}
		}
	}
	cout << ans << 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<bits/stdc++.h>
clock_t t=clock();
namespace my_std{
	using namespace std;
	#define pii pair<int,int>
	#define fir first
	#define sec second
	#define MP make_pair
	#define rep(i,x,y) for (int i=(x);i<=(y);i++)
	#define drep(i,x,y) for (int i=(x);i>=(y);i--)
	#define go(x) for (int i=head[x];i;i=edge[i].nxt)
	#define templ template<typename T>
	#define mod 1000000007ll
	#define sz 101010
	typedef long long ll;
	typedef double db;
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);}
	templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;}
	templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;}
	templ inline void read(T& t)
	{
		t=0;char f=0,ch=getchar();double d=0.1;
		while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
		while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
		if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
		t=(f?-t:t);
	}
	template<typename T,typename... Args>inline void read(T& t,Args&... args){read(t); read(args...);}
	char __sr[1<<21],__z[20];int __C=-1,__zz=0;
	inline void Ot(){fwrite(__sr,1,__C+1,stdout),__C=-1;}
	inline void print(register int x)
	{
		if(__C>1<<20)Ot();if(x<0)__sr[++__C]='-',x=-x;
		while(__z[++__zz]=x%10+48,x/=10);
		while(__sr[++__C]=__z[__zz],--__zz);__sr[++__C]='\n';
	}
	void file()
	{
		#ifdef NTFOrz
		freopen("a.in","r",stdin);
		#endif
	}
	inline void chktime()
	{
		#ifdef NTFOrz
		cout<<(clock()-t)/1000.0<<'\n';
		#endif
	}
	#ifdef mod
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;}
	ll inv(ll x){return ksm(x,mod-2);}
	#else
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;}
	#endif
//	inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;}
}
using namespace my_std;

int n;
int a[sz<<1];

int main()
{
	file();
	read(n);n+=n;
	char c;
	rep(i,1,n) cin>>c,a[i]=(c=='B');
	int k=0;ll w=1;
	drep(i,n,1)
	{
		int j1=k+1,j2=k-1;
		if ((j1-a[i])%2==0) w=w*j1%mod,k=j1;
		else k=j2;
		if (k<0) return puts("0"),0;
	}
	if (k) w=0;
	rep(i,1,n/2) w=w*i%mod;
	cout<<w;
	return 0;
}

Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.NoSuchElementException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskC {
		public void solve(int testNumber, Scanner in, PrintWriter out) {
			int[][] c = new int[3][3];
			int total = 0;
			for (int i = 0; i < 3; i++) {
				for (int j = 0; j < 3; j++) {
					c[i][j] = in.nextInt();
					total += c[i][j];
				}
			}
			boolean flag = total % 3 == 0;
			for (int i = 0; flag && i < 3; i++) {
				for (int j = 0; flag && j < 3; j++) {
					flag =
						(c[i][0] - c[j][0] == c[i][1] - c[j][1]) && (c[i][1] - c[j][1] == c[i][2] - c[j][2]) &&
							(c[0][i] - c[0][j] == c[1][i] - c[1][j]) && (c[1][i] - c[1][j] == c[2][i] - c[2][j]);
				}
			}
			out.println(flag ? "Yes" : "No");
		}

	}

	static class Scanner {
		private final InputStream in;
		private final byte[] buffer;
		private int ptr;
		private int buflen;

		public Scanner(InputStream in) {
			this.in = in;
			this.buffer = new byte[1024];
			this.ptr = 0;
			this.buflen = 0;
		}

		private boolean hasNextByte() {
			if (ptr < buflen) return true;
			else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) return false;
			}
			return true;
		}

		private byte readByte() {
			if (hasNextByte()) return buffer[ptr++];
			return -1;
		}

		private boolean isPrintableChar(byte c) {
			return '!' <= c && c <= '~';
		}

		private void skipUnprintable() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
				ptr++;
			}
		}

		public boolean hasNext() {
			skipUnprintable();
			return hasNextByte();
		}

		public int nextInt() {
			if (!hasNext()) throw new NoSuchElementException();
			int n = 0;
			boolean minus = false;
			byte b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) throw new NumberFormatException();
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}

	}
}



Measured memory_bytes: 23252
n = int(input())

arr = input()
arr = arr.split()
for i in range (len(arr)):
  arr[i] = int(arr[i])

dp = [-1 for i in range(len(arr))]
dp[0] = 0
dp[1] = abs(arr[1]-arr[0])

for i in range(2, len(arr)):
    dp[i] = min(dp[i-2] + abs(arr[i]-arr[i-2]), dp[i-1] + abs(arr[i]-arr[i-1]))
    
print(dp[-1])

Measured memory_bytes: 17396
#include<iostream>
#include<vector>
#include<string>
#include<string.h>
using namespace std;

struct book{
    string t, a;
    int y,m,d;
};
vector<book>vec;
int main(){
    int n;
    string t,a,d,qt,qa,qd1,qd2;
    cin>>n;
    while(n--){
        int ty=0,tm=0,td=0,i;
        cin>>t>>a>>d;
        book b;
        b.t=t;
        b.a=a;
        for(i=0;i<4;i++)
            ty=ty*10+d[i]-'0';
        for(i=5;i<7;i++)
            tm=tm*10+d[i]-'0';
        for(i=8;i<10;i++)
            td=td*10+d[i]-'0';
        b.y=ty,b.m=tm,b.d=td;
        vec.push_back(b);
    }
    cin>>n;
    while(n--){
        string q1,q2,q3,q4;
        cin>>q1>>q2>>q3>>q4;
        int ty1=0,tm1=0,td1=0,ty2=0,tm2=0,td2=0,i;
        if(q3!="*"){
            for(i=0;i<4;i++)
                ty1=ty1*10+q3[i]-'0';
            for(i=5;i<7;i++)
                tm1=tm1*10+q3[i]-'0';
            for(i=8;i<10;i++)
                td1=td1*10+q3[i]-'0';
        }
        if(q4!="*"){
            for(i=0;i<4;i++)
                ty2=ty2*10+q4[i]-'0';
            for(i=5;i<7;i++)
                tm2=tm2*10+q4[i]-'0';
            for(i=8;i<10;i++)
                td2=td2*10+q4[i]-'0';
        }
        else{
            ty2=3000,tm2=50,td2=50;
        }
        for(int i=0;i<vec.size();i++){
            if ((q1!="*" && vec[i].t.find(q1)==string::npos)||
                (q2!="*" && vec[i].a.find(q2)==string::npos))
                continue;
            if((vec[i].y>ty1||(vec[i].y==ty1&&(vec[i].m>tm1||(vec[i].m==tm1&&vec[i].d>=td1))))&&
               (vec[i].y<ty2||(vec[i].y==ty2&&(vec[i].m<tm2||(vec[i].m==tm2&&vec[i].d<=td2))))){
                cout<<vec[i].t<<endl;
            }
        }
        if(n>0)cout<<endl;
    }
}

Measured memory_bytes: 1244
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Vec2(T, n, m, xs, x0) vector<vector<T>> xs(n, vector<T>(m, x0))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n);
    int c = 0;
    Rep(n){
        Cin(int, a);
        if(a % 2) c ++;
    }
    CoutYN(c % 2 == 0);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
void insertionSort(int A[], int N) {
	for (int i = 1; i <= N - 1; i++) {
		for (int j = 0; j < N - 1; j++) {
			cout << A[j] << ' ';
		}
		cout << A[N - 1] << endl;
		int v = A[i];
		int j = i - 1;
		while (j >= 0 && A[j] > v) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
	}
	for (int i = 0; i < N - 1; i++) {
		cout << A[i] << ' ';
	}
	cout << A[N - 1] << endl;
}

int main(void) {
	int N, A[200];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	insertionSort(A, N);
	return 0;
}

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

using namespace std;
using ll = long long;

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

    string s;
    multiset<string> ms;
    for(int i=0; i<N; ++i){
        cin >> s;
        sort(s.begin(), s.end());
        ms.insert(s);
    }

    ll cnt = 0, c = 0; 
    for(auto itr=ms.begin(); itr!=ms.end();){
        c = ms.count(*itr);
        cnt += (c - 1) * c / 2;
        for(int j=0; j<c; ++j) ++itr;
    }

    cout << cnt << endl;

    return 0;
}

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

using edge=pair<int,int64_t>;
using Graph=vector<vector<edge>>;

void dfs(Graph &G,int v,edge p,vector<int64_t> &dep){

  for(auto nv:G[v]){
    if(nv==p) dep[v]=dep[nv.first]+nv.second;
  }

  for(auto nv:G[v]){
    if(nv==p) continue;
    dfs(G,nv.first,make_pair(v,nv.second),dep);
  }
}

int main(){
  //入力
  int N;
  cin>>N;
  Graph G(N+1);
  for(int i=0;i<N-1;++i){
    int a,b;
    int64_t c;
    cin>>a>>b>>c;
    G[a].push_back(make_pair(b,c));
    G[b].push_back(make_pair(a,c));
  }
  int Q,K;
  cin>>Q>>K;
  vector<pair<int,int>> query(Q);
  for(int i=0;i<Q;++i){
    int x,y;
    cin>>x>>y;
    query[i]=make_pair(x,y);
  }

  //Kを頂点としたときの各頂点の深さを求める
  vector<int64_t> depth(N+1);
  depth[0]=0;
  G[K].push_back(make_pair(0,0));
  dfs(G,K,make_pair(0,0),depth);

  //出力
  for(int i=0;i<Q;++i){
    cout<<depth[query[i].first]+depth[query[i].second]<<endl;
  }

}

Measured memory_bytes: 21760
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;

int N,a[4],S,L,cnt;

int main(){
	while(1){
		cnt=0;
		cin>>N;
		if(N==0){break;}
		if(N%1111==0){
			cout<<"NA"<<endl;
			continue;
		}
		while(N!=6174){
			a[0]=N/1000;
			a[1]=(N%1000)/100;
			a[2]=(N%100)/10;
			a[3]=N%10;
			sort(a,a+4);
			L=a[3]*1000+a[2]*100+a[1]*10+a[0];
			S=a[0]*1000+a[1]*100+a[2]*10+a[3];
			N=L-S;
			cnt++;
		}
		cout<<cnt<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1180
/*------------------------- Bism Allah Alruhmin Alrahim -------------------------------*/
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < n; i++)
#define ford(i, n) for (int i = n - 1; i > -1; i--)
#define forl(i, l, r) for (int i = l; i <= r; i++)
#define vc vector
#define f first
#define s second
#define pb(i) push_back(i)
#define mx(ar, n) (*max_element(ar, ar + n))
#define mn(ar, n) (*min_element(ar, ar + n))

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // ----------------------
    int n , m ;
    cin >> n >> m ;
    int a , b ; 
    cin >> a >> b ;
    cout << n * m - (a * m + n*b ) + a*b << endl;
     
    return 0 ;
}

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

#define INF 1e18
// INF を 10^18 というとんでもなくデカイ定数を用意

int main(){

    // 入力部
    int n;
    cin >> n;
    int a[100000];
    for(int i=0;i<n;i++)cin >> a[i];

    //計算部
    long long dp[100000];
    fill(dp,dp+n,INF);
    dp[0] = 0;
    for(int i=0;i<n;i++){
        if(i+1<n)dp[i+1] = min(dp[i+1],dp[i]+abs(a[i+1]-a[i]));
        if(i+2<n)dp[i+2] = min(dp[i+2],dp[i]+abs(a[i+2]-a[i]));
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int dp[3][100005];

int main()
{
    int n;
    cin>>n;
    int a[200005],b[200005],c[200005];
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    for(int i=0;i<n;i++)
    {
        if(i==0)
        {
            dp[0][i]=a[0];
            dp[1][i]=b[0];
            dp[2][i]=c[0];
        }
        dp[0][i]=a[i]+max(dp[1][i-1],dp[2][i-1]);
        dp[1][i]=b[i]+max(dp[0][i-1],dp[2][i-1]);
        dp[2][i]=c[i]+max(dp[0][i-1],dp[1][i-1]);
    }

    int ans=max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1]));
    cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 3712
#include<cstdio>

int k, n;
int a[200005];

int max(int x, int y) {
  return x > y ? x : y;
}

int main() {
  scanf("%d %d", &k, &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  a[n] = a[0] + k;
  int x = 0;
  for (int i = 0; i < n; i++) {
    x = max(x, a[i + 1] - a[i]);
  }
  printf("%d\n", k - x);
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
#define mp make_pair
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define sci(x) scanf("%d",&x)
#define scs(s) scanf("%s",s)
#define scc(c) scanf("%c",c)
#define scd(d) scanf("%lf",&d)
#define scld(ld) scanf("%Lf",&ld)
using namespace std;

//********************************************
//Error tracking
#define show(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }

vector<string> split(const string& s, char c) {
    vector<string> v;
    stringstream ss(s);
    string x;
    while (getline(ss, x, c))
        v.emplace_back(x);
    return move(v);
}

void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
    cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
    err(++it, args...);
}
//********************************************

const int NMAX = 200005;

int n, a[NMAX], fr[NMAX];
int sol;

int main()
{
 //   freopen("input","r",stdin);
  //  freopen("output","w",stdout);
    cin.sync_with_stdio(false);
    
    int i;
    cin >> n;
    for (i = 1; i <= n; i++)
    {
        cin >> a[i];

        a[i]++;

        fr[a[i] - 1]++;
        fr[a[i]]++;
        fr[a[i] + 1]++;
    }

    int ans;
    for (int i = 0; i < NMAX; i++)
        if (fr[i] > sol)
        {
            sol = fr[i];
            ans = i - 1;
        }

    cout << sol << "\n";
    return 0;   
}

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

int main()
{
    int x;
    int a, fx = 0, i;
    
    cin >> x;
    
    a = x;
    do {
        fx = fx + a % 10;
        a = a / 10;
    } while(a != 0);
    
    if((x % fx) == 0) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    
    return 0;
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
  gearup;
  int h,w,k;cin>>h>>w>>k;
  vvs c(h,vs(w));
  //入力
  rep(i,h)rep(j,w){
    char ch;
    cin>>ch;
    c[i][j] = ch;
  }
  
  int num = 1;
  rep(i,h){
    //行においてイチゴがおいているか
    bool check = false;
    rep(j,w)if(c[i][j] == "#")check = true;
    if(!check)continue;
    bool first = true;
    rep(j,w){
      if(c[i][j] !="#")c[i][j]=to_string(num);
      else{
        if(first){
          c[i][j]=to_string(num);
          first = false;
        }
        else c[i][j]=to_string(++num);
      }
    }
    num++;
  }
  
  //上から下に.があれば上の文字で置き換える
  rep(i,h-1)rep(j,w)if(c[i+1][j] == ".")c[i+1][j]=c[i][j];
  //下から上に
  for(int i=h-1;i>0;i--)rep(j,w)if(c[i-1][j] == ".")c[i-1][j]=c[i][j];
  //出力
  rep(i,h){
    rep(j,w){
      if(j)cout << " ";
      cout << c[i][j];
    }
    cout << endl;
  }
}

Measured memory_bytes: 5760
a,b,c,x,y=gets.split.map &:to_i
p=a*x+b*y+[x,y].min*(2*c-a-b)
q=a*x+b*y
r=[x,y].max*(2*c)
if  p<q
if r<p
p r
else
p p
end
else
if q<r
p q
else
p r
end
end

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

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

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (long long)1e18 + 1;

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

    ll N, A, B;
    std::cin >> N >> A >> B;

    std::vector<int> X(N);
    REP(i, N) {
        std::cin >> X[i];
    }

    auto ans = 0LL;
    for(int i = 1; i < N; i++) {
        auto a_cost = (X[i] - X[i - 1]) * A;
        ans += min(a_cost, B);
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int[] A = new int[N];
    int numMinus = 0;
    for (int i = 0; i < N; i++) {
      int a = scanner.nextInt();
      if (a < 0) numMinus--;
      A[i] = Math.abs(a);
    }
    Arrays.sort(A);
    long sum = 0;
    if (numMinus % 2 == 0) {
      sum += A[0];
    } else {
      sum -= A[0];
    }
    for (int i = 1; i < N; i++) sum += A[i];
    System.out.println(sum);
  }
}


Measured memory_bytes: 49344