akhauriyash/Code-Regression huggingface dataset:
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)
#文字数が9文字以下のときだけ全探索
s = input()
if len(s)>9:
    print("NO")
    exit()
bool = False
for i in range(2**9):
    cur = ""
    for j in range(9):
        if (i>>j)&1:
            if (j<len(s)):
                cur +="A"+s[j]
            else:
                cur +="A"
        else:
            if j<len(s):
                cur +=s[j]
    if cur =="AKIHABARA":
        bool = True
if bool:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 39664
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(const T a, const T b){return a>=0 ? a/b : (a+1)/b-1;}
template<class T> T div_ceil(const T a, const T b){return a>=0 ? (a-1)/b+1 : a/b;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
    int a[4];
    rep(i, 4) scanf("%d", &a[i]);
    sort(a, a+4);
    int b[4] = {1, 4, 7, 9};
    rep(i, 4){
        if(a[i] != b[i]){
            puts("NO");
            return 0;
        }
    }
    puts("YES");
}

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

const int INF = (int)1e9 + 5;

const int MAXN = 1111;
int N;
int a[MAXN];

void solve() {
  for(int i = 0; i+1 < N; ++i) {
    if(a[i] == INF || a[i+1] == INF) continue;
    if(i % 2 == 0) {
      if(i+1 < N && a[i] >= a[i+1]) {
        cout << "none" << endl;
        return;
      }
    } else {
      if(i+1 < N && a[i] <= a[i+1]) {
        cout << "none" << endl;
        return;
      }
    }
  }
  if(*max_element(a, a+N) != INF) {
    cout << "ambiguous" << endl;
    return;
  }
  int mini = -INF, maxi = INF;
  for(int i = 0; i < N; ++i) {
    if(a[i] != INF) continue;
    if(i+1 < N && a[i+1] == INF) {
      cout << "none" << endl;
      return;
    }
    if(i % 2 == 0) {
      if(i-1 >= 0) maxi = min(maxi, a[i-1]-1);
      if(i+1 <  N) maxi = min(maxi, a[i+1]-1);
    } else {
      if(i-1 >= 0) mini = max(mini, a[i-1]+1);
      if(i+1 <  N) mini = max(mini, a[i+1]+1);
    }
  }
  if(mini > maxi) {
    cout << "none" << endl;
  } else if(mini < maxi) {
    cout << "ambiguous" << endl;
  } else {
    cout << mini << endl;
  }
}

int main() {
  while(cin >> N && N) {
    for(int i = 0; i < N; ++i) {
      string s;
      cin >> s;
      if(s == "x") a[i] = INF;
      else a[i] = atoi(s.c_str());
    }
    solve();
  }
  return 0;
}

Measured memory_bytes: 1220
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits> 

int main()
{
    long X,Y,A,B,C;
    std::cin >> X >> Y >> A >> B >> C;
    std::vector<long> p,q,r;
    long temp;
    for(long i=0; i<A; i++){
        std::cin >> temp;
        p.push_back(temp);
    }
    for(long i=0; i<B; i++){
        std::cin >> temp;
        q.push_back(temp);
    }
    for(long i=0; i<C; i++){
        std::cin >> temp;
        r.push_back(temp);
    }
    std::sort(p.begin(),p.end());
    std::sort(q.begin(),q.end());
    std::sort(r.begin(),r.end());
    
    std::vector<long> result;
    for(long i=0; i<X; i++){
        result.push_back(p[A-1-i]);
    }
    for(long i=0; i<Y; i++){
        result.push_back(q[B-1-i]);
    }

    std::sort(result.begin(),result.end());

    long kouho=0;
    long result2=0;
    for(long i=0; i<X+Y-C; i++){
        result2+=result[X+Y-1-i];            
    }
    
    for(long i=0; i<std::min(C,X+Y); i++){
        if(result[i]<r[C-1-kouho]){
            result2+=r[C-1-kouho];
            kouho++;
        }else{
            result2+=result[i];
        }
    }
std::cout << result2 << std::endl;
    return 0;
}

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

int main()
{
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    int out = INT_MAX;
    for (int i = 0; i <= 100000; i++)
    {
        out = min(out, 2 * c * i + max(0, x - i) * a + max(0, y - i) * b);
    }
    cout << out << endl;
}

Measured memory_bytes: 3644
// ProblemURL : https://atcoder.jp/contests/abc079/tasks/abc079_a
// ---------------------------------------------
package main

import "fmt"

func main() {
	var n string
	fmt.Scan(&n)

	if (n[0] == n[1] && n[1] == n[2]) || (n[1] == n[2] && n[2] == n[3]) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

long long N;
map<long long, long long> memo;
long long fir;
long long sec;

int main(){
	cin >> N;
	for(long long i = 0; i < N; i++){
		long long tmp;
		cin >> tmp;
		memo[tmp]++;
	}

	priority_queue<long long> Q1;
	priority_queue<long long> Q2;
	for(auto me : memo){
		if(me.second >= 2){
			Q1.push(me.first);
		}
		if(me.second >= 4){
			Q2.push(me.first);
		}
	}
	if(Q1.size() < 2 && Q2.size() < 1){
		cout << 0 << endl;
	}else{
		long long ret = 0;
		if(Q1.size() >= 2){
			fir = Q1.top();
			Q1.pop();
			sec = Q1.top();
			ret = max(ret, fir * sec);
		}
		if(Q2.size() >= 1){
			ret = max(ret, Q2.top() * Q2.top());
		}
		cout << ret << endl;
	}
}


Measured memory_bytes: 6528
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<cstdint>
#include<cstddef>
#include<vector>
#include<algorithm>
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using usize = uint_fast64_t;
#define rep(i, n) for (usize i = 0; i < (usize)(n); i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;

int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
usize n;
cin >> n;
vector<usize> a(n),b(n),c(n);
rep(i,n)cin >> a[i];
rep(i,n)cin >> b[i];
rep(i,n)cin >> c[i];
sort(all(a));
sort(all(b));
sort(all(c));
usize ans = 0;
rep(i,n){
    auto v = lower_bound(all(a),b[i]);
    auto u = lower_bound(all(c),b[i] + 1);
    auto it =v -  a.begin();
    auto it2 = c.end() - u;
    ans += it * it2;
}
cout << ans << endl;
}

Measured memory_bytes: 5548
n,x,y = map(int,input().split())
x -= 1
y -= 1

array1 = [0] * n
array2 = [0] * n

for i in range(x, y+1):
  array1[i] = min(i-x, y-i+1)
  array2[i] = min(i-x+1, y-i)

ans = [0] * (n+1)
dis = [[0 for i in range(n)] for i in range(n)]


for i in range(n):
  if i <= x:
    for j in range(i+1,n):
      if y <= j:
        tmp = (x-i) + (j-y) + 1
      elif j <= x:
        tmp = j-i
      else:
        tmp = (x-i) + array1[j]
        
      ans[tmp] += 1
      dis[i][j] = tmp
      
  elif y <= i:
    for j in range(i+1,n):
      ans[j-i] += 1
      dis[i][j] = j-i
      
  else:
    for j in range(i+1,n):
      if y <= j:
        tmp = (j-y) + array2[i]
      else:
        tmp = min(j-i, (y-x+1)-(j-i))
        
      ans[tmp] += 1
      dis[i][j] = tmp

for i in range(1,n):
  print(ans[i])
    

Measured memory_bytes: 84184
N, M, X = map(int,input().split())
book = list(list(map(int,input().split())) for _ in range(N))
ans = float('inf')

for i in range(2**N):
    cost = 0
    skill = [0]*M
    for j in range(N):
        if 1<<(j) & i:
            cost += book[j][0]
            for k in range(M):
                skill[k] += book[j][k+1]
    if min(skill) >= X:
        ans = min(ans,cost)

if ans == float('inf'):
    ans = -1
print(ans)

Measured memory_bytes: 9224
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yosiiii
 */


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

class BCountingOfTrees {
public:
    void solve(std::istream& in, std::ostream& out) {
        ll n;
        in >> n;
        vector<ll> c(n,0);
        int tt;
        rep(i,n){
            int t;
            in >> t;
            c[t]++;
            if(i==0)tt=t;
        }
        if(tt!=0||c[0]>1){
            out << 0 << endl;
            return ;
        }
        ll mo=998244353;
        ll ans=1L;
        for(int i=1;i<n;i++){
            ans*=binpow(c[i-1],c[i],mo);
            ans%=mo;
        }
        out <<ans << endl;
    }
    ll binpow(ll a,ll b,ll mod){
        ll ret=1;
        while(b>0){
            if(b&1){
                ret=ret*a%mod;
            }
            a=a*a%mod;
            b=b>>1;
        }
        return ret;
    }
};


int main() {
	BCountingOfTrees solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

using namespace std;

typedef long long ll;

int main(){
  ll N,C,K; cin >> N >> C >> K;
  vector<ll> T(N); for(int i = 0; i  < N; i++){ cin >> T[i];}
  
  ll res = 0;
  
  sort(T.begin(),T.end());
  
  ll i = 0; ll start = 0;
  while( i  < N){ 
    while( i < N && T[i] - T[start] <= K && i - start < C){ i++;}
    
    start = i;
    res++;}
  
  cout << res << endl; return 0;}

Measured memory_bytes: 1024
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a = read::<i64>();
    let s = read::<String>();
    println!("{}", if a >= 3200 { &s } else { "red" });
}


Measured memory_bytes: 4352
N=int(input())
A=list(map(int,input().split()))
acc=[0]*N
acc[0]=A[0]
for i in range(1,N):
  acc[i]=acc[i-1]+A[i]
def f(x,y):
  if x==0:
    return acc[y]
  else:
    return acc[y]-acc[x-1]
left=0
right=2

import math
ans=math.inf
for mid in range(1,N-2):

  while abs(f(0,left)-f(left+1,mid))>=abs(f(0,left+1)-f(left+2,mid)):
    left+=1
    if left==mid-1:
      break
  while abs(f(mid+1,right)-f(right+1,N-1))>=abs(f(mid+1,right+1)-f(right+2,N-1)):
    right+=1
    if right==N-2:
      break
  list=[f(0,left),f(left+1,mid),f(mid+1,right),f(right+1,N-1)]
  tans=max(list)-min(list)
  ans=min(tans,ans)
print(ans)

Measured memory_bytes: 102556
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> c(n);
    vector<vector<int>> g(n);
    for(int i = 0; i < n; i++) {
        cin >> c[i];
        c[i]--;
    }
    for(int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        g[--a].emplace_back(--b);
        g[b].emplace_back(a);
    }
    // sz[i] := 頂点iを根とする部分木のsize
    vector<int> sz(n, 0);
    // dp[i][c] := 頂点iを根とする部分木の中で、色cを
    // 根とする部分木のsizeの合計
    vector<map<int, int>> dp(n);
    vector<vector<int>> res(n);
    auto dfs = [&](auto &&dfs, int v, int p) -> void {
        for(const int &u : g[v]) {
            if(u != p) {
                dfs(dfs, u, v);
                sz[v] += sz[u];
                int tmp = sz[u];
                if(dp[u].count(c[v])) {
                    tmp -= dp[u][c[v]];
                }
                res[c[v]].emplace_back(tmp);
                if(dp[v].size() < dp[u].size()) {
                    swap(dp[v], dp[u]);
                }
                for(auto &p : dp[u]) {
                    dp[v][p.first] += p.second;
                }
            }
        }
        sz[v]++;
        dp[v][c[v]] = sz[v];
    };
    dfs(dfs, 0, -1);
    for(int i = 0; i < n; i++) {
        res[i].emplace_back(n - dp[0][i]);
    }
    vector<ll> ans(n, (ll)n * (n + 1) / 2);
    for(int i = 0; i < n; i++) {
        for(auto &j : res[i]) {
            ans[i] -= (ll)j * (j + 1) / 2;
        }
    }
    for(const ll &i : ans) {
        cout << i << endl;
    }
}

Measured memory_bytes: 80540
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  
																								   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
																													   
const int INF = 1000000001;																						   
const float PI = 3.14;																								   
typedef long long LL;																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra	   
																													   																				   
vector<ii>::iterator iter;																							   
																													   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////////////GLOBAL DEFINITIONS////////////////////////////////////////////////////////

int licznik[1000];

///////////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	string s;
	cin >> s;
	
	for(int i = 0; i < 4; i++){
		if(s[i+1] == s[i]){
			cout << "Bad" << endl;
			return 0;
		}
	}

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


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

int main(){
	int n;
	cin >> n;
	int x = n%10;
	if(x==3){
		cout << "bon" << endl;
	}
	else if(x==0||x==1||x==6||x==8){
		cout << " pon" << endl;
	}
	else{
		cout << "hon"<< endl;
	}
return 0;
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int n, a, mx;
string s;
int main() {
	cin>>n>>s;
	for(int i=0; s[i]; i++) {
		if(s[i]=='I') mx = max(mx, ++a);
		else --a;
	}
	cout<<mx;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits> 
#include <time.h>

int main()
{
    long N;
    std::vector<std::string> S;
    std::cin >> N;
    for(long i=0; i<N; i++){
        std::string tem;
        std::cin>> tem;
        S.push_back(tem); 
    }
    std:sort(S.begin(),S.end());
    long sum=1;
    for(long i=1; i<N; i++){
        if(S[i]!=S[i-1]){
            sum++;
        }
    }
    std::cout << sum <<  std::endl;
    return 0;
}

Measured memory_bytes: 11664
#include<stdio.h>

int H;

typedef struct{
  int key,oya,sa,yuu;
}ki;

ki T[250];

int main(){
  int i;
  int A[500];

  for(i=0;i<500;i++){
    A[i]=-2000000001;
  }
  
  scanf("%d",&H);

  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }

  for(i=0;i<=H;i++){
    T[i].oya=T[i].key=T[i].sa=T[i].yuu=-2000000001;
  }
  
  T[0].key=A[1];
  T[0].sa=A[2];
  T[0].yuu=A[3];
  
  for(i=2;i<=H;i++){
    T[i-1].key=A[i];
    if(i%2==0)T[i-1].oya=A[i/2];
    else T[i-1].oya=A[(i-1)/2];
    T[i-1].sa=A[2*i];
    T[i-1].yuu=A[2*i+1];
  }

  for(i=1;i<=H;i++){
    printf("node %d:",i);
    printf(" key = %d,",T[i-1].key);
    if(T[i-1].oya!=-2000000001)printf(" parent key = %d,",T[i-1].oya);
    if(T[i-1].sa!=-2000000001)printf(" left key = %d,",T[i-1].sa);
    if(T[i-1].yuu!=-2000000001)printf(" right key = %d,",T[i-1].yuu);
    printf(" \n");
  }
    
  return 0;
}



Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>

#define mod 1000000007

using namespace std;
using ll = long long;

void solve(){
    ll x = 0, y = 0;
    string s;
    cin >> s;
    for(int i = 0; i < s.length(); i++){
        x += s[i]-'0';
        y += (s[i]-'0')*pow(10, s.length()-(i+1));
    }
    //cout << x << ", " << y << endl;
    if(y%x == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

int main(){
    solve();
    return 0;
}


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

void airconditioner(signed int x){
    if(x<30){
        cout << "No";
        return;
    }
    cout << "Yes";
    return;
}

int main(){
    //ifstream myfile;
    //myfile.open("sample.txt");
    signed int x;
    cin >> x;
    airconditioner(x);
    return 0;
}

Measured memory_bytes: 3632
l=[list(map(int,input().split())) for i in range(3)]
al=[l[i][0] for i in range(3)]
bl=[l[0][i]-al[0] for i in range(3)]

for i in range(3):
    for j in range(3):
        if al[i]+bl[j]!=l[i][j]:print("No");exit()
print("Yes")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;

int DP[4001][4001];

int main() {
	string s, t;
	while(cin >> s >> t){
		memset(DP, 0, sizeof(DP));
		int n = s.size(), m = t.size(), ans = 0;
		for(int i = 0; i < n; ++i){
			for(int j = 0; j < m; ++j){
				if(s[i] == t[j]){
					DP[i + 1][j + 1] = DP[i][j] + 1;
					ans = max(DP[i + 1][j + 1], ans);
				}
				else{
					DP[i + 1][j + 1] = 0;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main()
{
	int d;
	while(cin>>d)
	{
	long long ans = 0;
	

	for ( int i=0; i<600; i+=d )
	{
		ans += d*i*i;
	}

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

	

Measured memory_bytes: 0
n,m = map(int,input().split())
data = [list(map(int,input().split())) for _ in range(m)]

for ans in range(1000):
    if len(str(ans)) == n:
        t = True
        for s,c in data:
            if s <= n and str(ans)[s-1] == str(c):
                continue
            else:
                t = False
                break
        if t:
            print(ans)
            exit()

print(-1)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;
void Main()
{
    ll n;
    cin >> n;
    vector<ll> L(n);
    rep(i, n) cin >> L[i];
    
    sort(all(L));

    ll sum = 0;
    for (ll i = 0; i < n - 1; i++) {
        for (ll j = i + 1; j < n; j++) {
            ll a = L[i];
            ll b = L[j];
            ll c_max = a + b - 1;
            ll c_min = abs(a - b) + 1;
            ll k1 = lower_bound(L.begin() + j + 1, L.end(), c_min) - L.begin();
            ll k2 = upper_bound(L.begin() + j + 1, L.end(), c_max) - L.begin();
            sum += k2 - k1;
        }
    }

    put(sum);
}
signed main(){ Main();return 0;}

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

using namespace std;

#define ll long long
#define fo(i,b,n) for(int i=(b); i<(n) ; i++)
#define xx first
#define yy second
#define pb push_back
#define sz(n) int(n.size())
#define pii pair
#define MP make_pair

#define read(x) scanf("%d",&x)
#define read2(x,y) scanf("%d%d",&x,&y)
#define readl(x) scanf("%lld",&x)
#define readl2(x,y) scanf("%lld%lld",&x,&y)
#define readd(x) scanf("%lf",&x)
#define readd2 scanf("%lf%lf",&x,&y)

#define pr(n) printf("%d",n)
#define prn(n) printf("%d\n",n)
#define prl(n) printf("%lld",n)
#define prln(n) printf("%lld\n",n)
#define prd(x) printf("%lf",x)
#define prdn(x) printf("%lf\n",x)


int main()
{
    int a,b,h;
    read2(a,b);
    read(h);
    int mx=max(a,b);
    int mi=min(a,b);
    int ans=mi*h;
    ans+=(h*(mx-mi))/2;
    prn(ans);
    return 0;
}

















Measured memory_bytes: 256
while True:
    n = int(input())
    if n == 0:
        break
    
    for _ in range(n):
        m, e, j = [int(x) for x in input().split()]
        
        if m == 100 or e == 100 or j == 100:
            print("A")
            continue
        if m + e >= 180:
            print("A")
            continue
        if m + e + j >= 240:
            print("A")
            continue
        if m + e + j >= 210:
            print("B")
            continue
        if m + e + j >= 150 and (m >= 80 or e >=80):
            print("B")
            continue
        print("C")


Measured memory_bytes: 5620
use std::io::*;
const INF: u64 = 1u64 << 60;

fn rec(l: usize, r: usize, sum: &Vec<u64>, memo: &mut Vec<Vec<u64>>) -> u64 {
    if memo[l][r] != 0 {
        return memo[l][r];
    }
    if l == r {
        return 0;
    }
    let mut res = INF;
    for i in l..r {
        res = std::cmp::min(res, rec(l, i, &sum, memo) + rec(i + 1, r, &sum, memo));
    }
    res += sum[r + 1] - sum[l];
    memo[l][r] = res;
    res
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<u64> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();
    let mut sum: Vec<u64> = vec![0; n + 1];
    let mut memo: Vec<Vec<u64>> = vec![vec![0; n + 1]; n + 1];
    for i in 0..n {
        sum[i + 1] = sum[i] + a[i];
    }
    println!("{}", rec(0, n - 1, &sum, &mut memo))
}


Measured memory_bytes: 4352
#import <Foundation/Foundation.h>
typedef long long Int;
int main() {
	@autoreleasepool{
		Int N;
		scanf("%lld",&N);
		Int *A = (Int*)malloc((N+1)*sizeof(Int));
		Int *X = (Int*)malloc((N+1)*sizeof(Int));
		for(Int i=1;i<=N;i++){
			scanf("%lld",A+i);
		}
		NSMutableArray *answers = [NSMutableArray array];
		for(Int i=N;i>=1;i--){
			X[i] = A[i];
			for(Int j=2;i*j<=N;j++){
				X[i] -= X[i*j];
			}
			X[i] %= 2;
			if(X[i]!=0) [answers addObject:@(i)];
		}
		printf("%lu\n",[answers count]);
		puts([answers componentsJoinedByString:@" "].UTF8String);
	}
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e18+7;

struct UnionFind{
    ll n;
    vector<ll> sum, par, l, h;

    UnionFind(ll n, vector<ll>& sum) : n(n), sum(sum), par(n, -1), l(n, 0), h(n, 0){}

    bool Unite(ll x, ll y, ll cost){
        x = Find(x);
        y = Find(y);

        if(x == y){
            ++(sum[x] >= cost ? l[x] : h[x]);
            return false;
        }
        if(par[x] > par[y])
            swap(x, y);

        par[x] += par[y];
        par[y] = x;
        l[x] += l[y];
        h[x] += h[y];
        sum[x] += sum[y];
        ++h[x];
        if(sum[x] >= cost){
            l[x] += h[x];
            h[x] = 0;
        }
        return true;
    }

    ll Find(ll x){
        return par[x] < 0 ? x : Find(par[x]);
    }

    ll Sum(){
        ll s = 0;
        for(ll i = 0; i < n; ++i)
            if(par[i] < 0)
                s += h[i];
        return s;
    }

};

signed main(){
    ll n, m;
    cin >> n >> m;
    vector<ll> v(n), a(m), b(m), c(m);
    for(auto& x : v)
        cin >> x;
    vector<pair<ll, pair<ll,ll>>> p;
    for(ll i = 0; i < m; ++i){
        cin >> a[i] >> b[i] >> c[i];
        p.emplace_back(c[i], make_pair(--a[i], --b[i]));
    }

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

    UnionFind u(n, v);
    for(auto& q : p){
        u.Unite(q.second.first, q.second.second, q.first);
    }
    cout << u.Sum() << endl;

}


Measured memory_bytes: 9584
while (square_count = gets.to_i) != 0 do
  orders = []
  (square_count-1).times do
    target_square, direction =gets.split.map(&:to_i)
    orders.push([target_square, direction])
  end
  #p square_count

  positions = [[0, 0]]
  orders.each do |order|
    #p 'order', order
    ref_position = positions[order[0]]
    case order[1]
      when 0
        positions.push([ref_position[0] -1, ref_position[1]])
      when 1
        positions.push([ref_position[0], ref_position[1] -1])
      when 2
        positions.push([ref_position[0] +1, ref_position[1]])
      when 3
        positions.push([ref_position[0], ref_position[1] +1])
    end

  end

#p positions
  max_x = min_x = max_y = min_y = 0

  positions.each do |position|
    max_x = position[0] if position[0] >= max_x
    min_x = position[0] if position[0] <= min_x

    max_y = position[1] if position[1] >= max_y
    min_y = position[1] if position[1] <= min_y
  end

#p max_x, min_x, max_y, min_y

  width =max_x-min_x+1
  height = max_y-min_y + 1

  puts width.to_s + ' ' + height.to_s

end

Measured memory_bytes: 8868
;; ----

(defmacro defsolver (name vars &body body)
  `(defun ,name ()
     (let (,@(mapcar #'list
            vars
            (mapcar (constantly '(read))
                vars)))
       ,@body)))

;; --- solution A

(defsolver sol-a (n a b)
  (let ((x (* n a)))
    (format t "~a"
	    (if (> x b)
		b
		x))))

(sol-a)

Measured memory_bytes: 12640
N, M =map(int,input().split())

X = list(map(int, input().split()))

X.sort()
A = []
for i in range(M-1):
    delta = X[i+1]-X[i]
    A.append(delta)

A.sort()
if len(A) > N-1:
    for i in range(N-1): 
        A.pop()
    print(sum(A))
else:
    print(0)

Measured memory_bytes: 13968
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<algorithm>

using namespace std;

int main()
{
    string s, t;
    cin >> s >> t;

    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());

    if (s.size() < t.size()) {
        bool is_same = true;
        for (int i = 0; i < s.size(); i++) {
            if (s[i] != t[i]) {
                is_same = false;
                break;
            }
        }
        if (is_same) {
            puts("Yes");
            return 0;
        }
    }

    for (int i = 0; i < min(s.size(), t.size()); i++) {
        if (s[i] == t[i]) {
            continue;
        } else if (s[i] < t[i]) {
            puts("Yes");
            return 0;
        } else {
            puts("No");
            return 0;
        }
    }

    puts("No");

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>

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

using namespace std;






int main(){

ll int N;
cin >> N;
ll int ans =0;
	for(ll int i=1;i*i<=N;i++){
		if(N%i==0){
		
			if(ans == 0 || i+N/i<ans){
				ans = i+N/i;
			}
			else{}
		}
		else{}
		
}
cout << ans-2;











	return 0;

}



Measured memory_bytes: 256
// ================
// Himanshu Lal
// MNIT Jaipur
// ================
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define TEZ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rf(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define INF 1e18
#define vi vector<pair<ll,ll>>
#define ff first
#define ss second
#define mp map<ll,ll>
#define test ll t; cin>>t; while(t--)
#define srt(v) sort(v.begin(),v.end())
double pi=acos(-1);
void OJ(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    #endif
}
int main(){
    TEZ;
    ll n;
    cin>>n;
    string s;
    cin>>s;
    if(s.length()>n){
        string ans="";
        f(i,0,n)
            ans+=s[i];
        cout<<ans<<"...";
        return 0;
    }
    cout<<s;
}

Measured memory_bytes: 3616
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        String ans = "x";
        if(a*b==15) ans = "*";
        else if(a+b==15) ans = "+";
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
typedef long long ll;
using namespace std;
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }
pair<int, bool> func(vector<ll> const & a, vector<ll> b) {
    int w = a.size();
    if (a < b) {
        return { 0, false };
    } else if (a[0] > b[0]) {
        return { -1, false };
    } else {
        assert (a[0] == b[0]);
        if (w == 1) {
            return { -1, false };
        } else {
            assert (b[0] >= 1);
            assert (a[1] >= b[1]);
            ll k = (a[1] - b[1] + b[0]-1) / b[0];
            if (b[1] + k * b[0] > a[1]) {
                return { k, false };
            } else {
                assert (b[1] + k * b[0] == a[1]);
                if (w == 2) {
                    return { k, true };
                } else {
                    repeat (j,k) {
                        repeat (i,w-1) {
                            if (b[i] > a[i]) break;
                            b[i+1] += b[i];
                            assert (b[i+1] >= 1);
                        }
                        if (b[2] > a[2]) {
                            b[1] = a[1];
                            break;
                        }
                    }
                    return { k + (a > b), a == b };
                }
            }
        }
    }
}
int main() {
    int h, w; cin >> h >> w;
    vector<vector<ll> > f = vectors(h, w, ll());
    repeat (y,h) repeat (x,w) cin >> f[y][x];
    ll ans = 0;
    ll acc = 0;
    repeat (y,h-1) {
        vector<ll> const & a = f[y];
        vector<ll> const & b = f[y+1];
        if (a < b) {
            int k; bool is_just; tie(k, is_just) = func(b, a);
            if (k == -1) {
                acc = 0;
            } else {
                acc = max<int>(0, acc-k+1);
            }
        } else {
            int k; bool is_just; tie(k, is_just) = func(a, b);
            if (k == -1) {
                ans = -1;
                break;
            } else {
                acc += k + is_just;
            }
        }
        ans += acc;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8192
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    int N;
    int[] x;
    int[] y;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.N = sc.nextInt();
        x = new int[N];
        y = new int[N];
        for (int i=0; i<N; i++) {
        	x[i] = sc.nextInt();
        	y[i] = sc.nextInt();
        }
    }
    
    //解答処理
    private double solve() {
        double answer = 0;
        
        double total = 0;
        double count = 0;
        for (int i=0; i<N-1; i++) {
        	for (int j=i+1; j<N; j++) {
        		double X = Math.pow(x[i]-x[j], 2);
        		double Y = Math.pow(y[i]-y[j], 2);
        		total += Math.sqrt(X+Y);
        		count++;
        	}
        }
        
        answer = total*(N-1) / count;
        return answer;
    }
    
    //出力
    public void show(double answer) {
        System.out.println(answer);
    }

}


Measured memory_bytes: 35832
mod = 10 ** 9 + 7
from math import gcd
N = int(input())
from collections import defaultdict
X = defaultdict(lambda: [0, 0])
x = 0
y = 0
z = 0
for i in range(N):
  a, b = map(int, input().split())
  g = abs(gcd(a, b))
  if a * b > 0:
    X[(abs(a) // g, abs(b) // g)][0] += 1
  elif a * b < 0:
    X[(abs(b) // g, abs(a) // g)][1] += 1
  else:
    if a:
      x += 1
    elif b:
      y += 1
    else:
      z += 1
ans = 1
pow2 = [1]
for i in range(N):
  pow2 += [pow2[-1] * 2 % mod]
for i in X.values():
  ans *= pow2[i[0]] + pow2[i[1]]- 1
  ans %= mod
ans *= pow2[x] + pow2[y] - 1
ans += z - 1
ans %= mod
print(ans)


Measured memory_bytes: 68572
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String in = scan.nextLine();
		String flont = in.substring(0,2);
		String back = in.substring(2);
		int mae = Integer.parseInt(flont);
		int usiro = Integer.parseInt(back);
		if((mae == 0 && usiro == 0) || (mae > 12 && usiro > 12) || (mae == 0 && usiro >12) || (usiro == 0 && mae >12)) {
			System.out.println("NA");
		}else if(((mae > 12) || (mae == 0))&&((usiro > 0)&&(usiro < 13))){
			System.out.println("YYMM");
		}else if(((usiro > 12) || (usiro == 0))&&((mae > 0)&&(mae < 13))) {
			System.out.println("MMYY");
		}else {
			System.out.println("AMBIGUOUS");
		}
	}
}

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    string S;
    cin >> S;
    int c = S.length(), f = -1;
    REP(i, S.length())
    {
        if (S[i] == 'C' && c > i)
            c = i;
        if (S[i] == 'F')
            f = i;
    }
    if (c < f)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    N = input()

    if N[-1] == "3":
        ans = "bon"
    elif N[-1] == "0" or N[-1] == "1" or N[-1] == "6" or N[-1] == "8":
        ans = "pon"
    else:
        ans = "hon"

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 61892
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int 

using namespace std;

int main(){
    int n,W;
    cin>>n>>W;
    ll mat[n+1][W+1];
    for(int i=0;i<=n;i++){
    for(int j=0;j<=W;j++) {
        mat[i][j]=0;
    }}
    for(int i=1;i<=n;i++){
        ll w,v;
        cin >>w>>v;
        for(int j=1;j<=W;j++){
            if(w<=j){
                //mat[i][j]=mat[i-1][j];
                mat[i][j]=max(mat[i-1][j],mat[i-1][j-w]+v);
            }
            else{
                mat[i][j]=mat[i-1][j];
                //mat[i][j]=max(mat[i-1][j],mat[i][j-w]+v);
            }
        }
    }
    /*for(int i=0;i<=n;i++){
    for(int j=0;j<=W;j++) {
        cout <<mat[i][j]<<" "; 
    }
        cout <<endl;
    }*/
    cout <<mat[n][W]<<endl;
}



Measured memory_bytes: 79104
#include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <vector>
    #include <string>
    #include <string.h>
     
    typedef long long ll;
    using namespace std;
    const ll INF = 1000000000000000000ll;
    const ll MOD = 1000000007ll;
     
    const double EPS = 1e-8;
     
    int main()
    {
		ll W,H,N,X,Y,x[2]={},y[2]={},a;
		 
		cin >> W >> H >> N;

		X=3;

		if(W==H||W==N||H==N) X=2;
		if(W==H&&W==N) X=1;

		cout << X;

		return 0;
    }

Measured memory_bytes: 256
<?php
  fscanf(STDIN, "%i", $n);
  for ($i = 1; $i <= $n; $i++)
  {
      fscanf(STDIN, "%i %i", $as[$i], $bs[$i]);
  }
  $count = 0;
  for ($i = $n; $i > 0; $i--)
  {
      if ($bs[$i] !== 1)
          $count += ($bs[$i] - ($count + $as[$i]) % $bs[$i]) % $bs[$i];
  }
  echo $count.PHP_EOL;
?>


Measured memory_bytes: 13932
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var nk = Console.ReadLine().Split(' ');
                int n = int.Parse(nk[0]), k = int.Parse(nk[1]);
                if (n == 0 && k == 0) break;

                var a = new int[n];
                for (int i = 0; i < n; i++)
                {
                    a[i] = int.Parse(Console.ReadLine());
                }

                int sum = 0, r = 0;
                for (int i = 0; i < n; i++)
                {
                    if (i < k)
                    {
                        sum += a[i];
                    }
                    else
                    {
                        sum -= a[i - k];
                        sum += a[i];
                        r = Math.Max(r, sum);
                    }
                }
                Console.WriteLine(r);
            }
        }
    }
}

Measured memory_bytes: 6496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll a,b,c;
	cin>>a>>b>>c;
	swap(a,b);swap(a,c);
	cout << a<< " "<<b<<" "<<c;
	// your code goes here
	return 0;
}

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

int main(){
	int n,m,c,t;
	while(cin >> n >> m,n || m){
		c = 1;
		if(m > n) swap(n,m);
		while(n % m != 0){
			t = n % m;
			n = m;
			m = t;
			++c;
		}
		cout << m << " " << c << endl;
	}
	return 0;
}

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD =   1000000007;

/// Lib
///

int main(){
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int K, X, Y;
    cin >> K >> X >> Y;

    // 1手でいける場合を先に処理
    if(abs(X) + abs(Y) == K){
        cout << "1" << endl;
        cout << X << " " << Y << endl;
        return 0;
    }

    // X >= Y >= 0に変換
    int xsign = 1, ysign = 1;
    bool sw = false;
    if(X < 0){
        X *= -1;
        xsign = -1;
    }
    if(Y < 0){
        Y *= -1;
        ysign = -1;
    }
    if(X < Y){
        swap(X, Y);
        sw = true;
    }

    // nがステップ数。1手で行けないので最小でも2
    int D = X + Y;
    int n = max(2, (D + K - 1)/K);

    // 無駄分が奇数の場合、Kが奇数なら1ステップ増やして偶数に。Kが偶数なら無理
    if((n * K - D) % 2 != 0){
        if(K % 2 != 0){
            n++;
        }
        else{
            cout << -1 << endl;
            return 0;
        }
    }

    vector<P> ans;

    // 構築。n=3のときだけ特別
    int R = (n * K - D)/2;
    if(n == 3){
        int b = R / 2;
        int a = R - b;
        for(int i = 1; i <= n; i++){
            int l = i * K;
            if(l <= a){
                ans.emplace_back(-l, 0);
            }
            else if(l <= a + Y + b){
                l -= a;
                ans.emplace_back(-a, l);
            }
            else if(l <= a + Y + b + a + X){
                l -= a+Y+b;
                ans.emplace_back(l-a, b+Y);
            }
            else{
                l -= a + Y + b + a + X;
                ans.emplace_back(X, Y + (b-l));
            }
        }
    }
    else{
        int a = R;
        for(int i = 1; i <= n; ++i){
            int l = i * K;
            if(l <= Y + a){
                ans.emplace_back(0, l);
            }
            else if(l <= Y + a + X){
                l -= Y + a;
                ans.emplace_back(l, Y + a);
            }
            else{
                l -= Y + a + X;
                ans.emplace_back(X, Y + (a - l));
            }
        }
    }

    // 座標変換を戻して出力
    if(sw){
        for(int i = 0; i < n; ++i){
            swap(ans[i].first, ans[i].second);
        }
    }
    cout << n << endl;
    for(auto& p : ans){
        cout << p.first * xsign << " " << p.second * ysign << endl;
    }

    return 0;
}


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

signed main()
{
  int a, b;
  cin >> a >> b;

  if (a > b){
    cout << "a > b" << endl;
  }
  else if (a < b){
    cout << "a < b" << endl;
  }
  else {
    cout << "a == b" << endl;
  }

  return (0);
}

Measured memory_bytes: 3084
// https://atcoder.jp/contests/dp/tasks/dp_n
#include <bits/stdc++.h>
#define ll long long int
#define pr pair<ll, ll>
#define infinity (ll)4e18
#define tp tuple<ll, ll, ll>
using namespace std;
long long int mod = 1e9 + 7;
ll dp[401][401];

ll sum(ll pre[], ll i, ll j)
{
    if (i == 0)
        return pre[j];
    return pre[j] - pre[i - 1];
}

ll solve(ll pre[], ll a[], ll i, ll j)
{
    if (i > j)
        return infinity;
    if (dp[i][j] != -1)
        return dp[i][j];
    if (j == i)
        return dp[i][j] = 0;
    dp[i][j] = infinity;
    for (ll k = i; k < j; k++)
        dp[i][j] = min(dp[i][j], solve(pre, a, i, k) + solve(pre, a, k + 1, j));
    return (dp[i][j] += sum(pre, i, j));
}

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

    ll n;
    cin >> n;
    ll a[n], pre[n];
    for (ll i = 0; i < n; i++)
        cin >> a[i];
    pre[0] = a[0];
    for (ll i = 1; i < n; i++)
        pre[i] = pre[i - 1] + a[i];
    memset(dp, -1, sizeof(dp));
    cout << solve(pre, a, 0, n - 1) << endl;
    return 0;
}

Measured memory_bytes: 1536
N = int(input())

used_word = []
ans = "Yes"


for i in range(N):
  word = input()
  
  if i == 0:
    used_word.append(word)
  elif i >= 1:  
    if word in used_word:
      ans = "No"
    elif word[0] != used_word[-1][-1]:
      ans = "No"
    else:
      used_word.append(word)
      continue

print(ans)






Measured memory_bytes: 2940
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

/**
 * Final Examination!
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int n = parseInt(line);
			if (n == 0) break;

			boolean[] score = new boolean[501];

			for (int i = 0; i < n; i++) {
				StringTokenizer st = new StringTokenizer(br.readLine());
				int sum = 0;
				while (st.hasMoreElements()) {
					sum += parseInt(st.nextToken());
				}
				score[sum] = true;
			}
			int min = 0, max = 0;
			for (int j = 0; j < score.length; j++) {
				if (score[j]) {
					min = j;
					break;
				}
			}
			for (int j = score.length - 1; j >= 0; j--) {
				if (score[j]) {
					max = j;
					break;
				}
			}
			System.out.println(max + " " + min);
		} // end while
	} // end main
}

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

ll k,n;
int main(){
	cin>>k>>n;
	ll a[n];
	rep(i,n){
		cin>>a[i];
	}
	ll max=0;
	rep(i,n-1)if(max<a[i+1]-a[i])max=a[i+1]-a[i];
	if(max<(k-a[n-1]+a[0]))max=k-a[n-1]+a[0];


	cout<<k-max<<endl;
}


Measured memory_bytes: 5184
import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
#from bisect import bisect_left as bl, bisect_right as br, insort
#from heapq import heapify, heappush, heappop
#from collections import defaultdict as dd, deque, Counter
#from itertools import permutations,combinations
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var) : sys.stdout.write(' '.join(map(str, var))+'\n')
def out(var) : sys.stdout.write(str(var)+'\n')
from decimal import Decimal
#from fractions import Fraction
#sys.setrecursionlimit(100000)
INF = float('inf')
mod = int(1e9)+7

n=int(data())
h=mdata()
m=0
ans=0
for i in h:
    m = max(m, i)
    ans+=m-i
out(ans)

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

using namespace std;

int main(void) {
  int N; cin >> N;
  map<string, int> S;
  vector<string> str;
  for (int i = 0; i < N; i++) {
    string s; cin >> s;
    str.push_back(s);
  }

  sort(str.begin(), str.end());
  S.insert(make_pair(str[0], 1));
  int max = 1;
  for (int i = 1; i < N; i++) {
    if (str[i] == str[i-1]) {
      S[str[i]]++;
    } else {
      if (S[str[i-1]] > max) {
        max = S[str[i-1]];
      }
      S.insert(make_pair(str[i], 1));
    }
  }
  if (S[str[N-1]] > max) {
    cout << str[N-1] << endl;
    return 0;
  }

  for (auto it = S.begin(); it != S.end(); it++) {
    if (it->second == max) {
      cout << it->first << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 26736