akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
  
int main()
{
  int P, Q, R;
  
  cin >> P >> Q >> R;
  
  int PQ = P + Q;
  int QR = Q + R;
  int PR = P + R;
  
  int a = min(min(PQ, QR), PR);
  

  cout << a << endl;

  return 0;
  
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44

/*
const int MOD = ;

inline void mod(int &x) {
    if(x >= MOD)
        x -= MOD;
}

inline void add(int &x, int y) {
    x += y;
    mod(x);
}

inline void sub(int &x, int y) {
    x += MOD - y;
    mod(x);
}


inline void mul(int &x, int y) {
    x = (1LL * x * y) % MOD;
}
*/

using namespace std;

const int MAXN = (int) 1e5;

int fr[MAXN + 1];

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, n;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    cin >> n;

    for(i = 1; i <= n; i++) {
        int d;
        cin >> d;
        fr[d]++;
    }

    int ans = 0;
    for(i = 1; i <= MAXN; i++) {
        fr[i] += fr[i - 1];
        if(2 * fr[i] == n) {
            ans++;
        }
    }

    cout << ans;

    //cin.close();
    //cout.close();
    return 0;
}


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

using ll = long long;

template <typename T> T inf;
template <> constexpr int inf<int> = 1e9;
template <> constexpr ll inf<ll> = 1e18;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> cnt(N);
    for(int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        cnt[a - 1]++;
        cnt[b - 1]++;
    }
    bool ok = true;
    for(int i = 0; i < N; ++i) {
        ok &= cnt[i] % 2 == 0;
    }
    if(ok) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 640
n=int(input())
f=list(map(int,input().split()))
c=0
for i in range(n-1):
    if f[i]==i+1:
        c+=1
        f[i],f[i+1]=f[i+1],f[i]
if f[n-1]==n:
  	f[n-2],f[n-1]=f[n-1],f[n-2]
  	c+=1  
print(c)

Measured memory_bytes: 14008
#include <iostream>
#include <math.h>

using namespace std;

int main() {
    int n;
    double d;
    cin >> n >> d;
    int count = 0;
    while(n--){
        double x, y;
        cin >> x >> y;
        double ans = sqrt(pow(x, 2)+pow(y, 2));
        if(ans <= d){
            count++;
        }
    }
    cout << count << endl;
    
}

Measured memory_bytes: 3776
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
char s[500];
int main(){
	scanf("%s",s+1);
	if (strlen(s+1)<4){
		printf("No\n");
		return 0;
	}
	if (s[1]=='Y'&&s[2]=='A'&&s[3]=='K'&&s[4]=='I'){
		printf("Yes\n");
		return 0;
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<cstring>
#define p pair<int,int>
#define P pair<int,p>
using namespace std;

vector<P>s;
int Par[100], Rank[100];
int find(int a) {
	if (Par[a] == a)return a;
	return Par[a] = find(Par[a]);
}
void unite(int a, int b) {
	a = find(a); b = find(b);
	if (Rank[a] > Rank[b]) {
		Par[b] = a;
	}
	else if (Rank[a] < Rank[b]) {
		Par[a] = b;
	}
	else {
		Rank[a]++;
		Par[b] = a;
	}
}
signed main() {
	int a; cin >> a;
	for (int b = 0; b < a; b++)Par[b] = b;
	for (int b = 0; b < a; b++) {
		for (int c = 0; c < a; c++) {
			int d; scanf("%d", &d);
			if (d != -1 && b <= c) {
				s.push_back(P(d,p(b,c)));
			}
		}
	}
	sort(s.begin(), s.end());
	int cost = 0;
	for (P i : s) {
		if (find(i.second.first) != find(i.second.second)) {
			cost += i.first;
			unite(i.second.first, i.second.second);
		}
	}
	cout << cost << endl;
}

Measured memory_bytes: 3236
c = 0
f = True
N, K = map(int, input().split())
ld = list(map(str, input().split()))
while f:
    i = 0
    N_str = str(N)
    for i in range(K):
        # print(i)
        if ld[i] in N_str:
            N += 1
            break
        elif i == K-1:
            f = False
print(N)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
struct bar{int h,p,q; bool operator>(const bar &b)const{return h>b.h;}};
int main(){
	while(true){
		int n,m,a;
		vector<bar> vbars;
		cin>>n>>m>>a;
		if(n==0&&m==0&&a==0)break;

		for(int i = 0; i < m; ++i){
			bar b;
			cin>>b.h>>b.p>>b.q;
			vbars.push_back(b);
		}
		sort(vbars.begin(),vbars.end(),greater<bar>());
		for(unsigned int i = 0; i < vbars.size(); ++i){
			if( vbars[i].p == a ){
				a = vbars[i].q;
			}else if( vbars[i].q == a ){
				a = vbars[i].p;
			}
		}
		printf("%d\n", a);
	}
	return 0;
}

Measured memory_bytes: 940
# -*- coding: utf-8 -*-
N = int(input())
count = 0
flag = False
for i in range(N):
  Di, Dj = map(int, input().split())
  if Di == Dj:
    count += 1
    if count == 3:
      flag = True
  else:
    count = 0
if flag == True:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 62328
#include <bits/stdc++.h>
#include<iostream>
#include <string>
#include <typeinfo>
using namespace std;
 
int main() {
   int a,b,c,d;
   cin >> a >> b >> c >> d;
  a = a*b;
  c = c*d;
  if(a >c){
    cout << a << endl;
  }else{
    cout << c << endl;
  }
    

} 


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;

const long long INFLL = 1LL << 60;
const int INFI = 1000000000;

bool gumoji(string S){
    int half = S.size()/2;
    for(int i=0;i<S.size()/2; i++){
        if(S[i] != S[i+half]) return false;
    }
    return true;
}

int main() {
    string S; cin >> S;
    int ans;
    int len = S.size();
    for(int i=1;i<=len;i++){
        if ((len-i)%2 == 1) continue;
        if (gumoji(S.substr(0,S.size()-i))) {ans = len-i; break;}
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
package main

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Code for D - Triangles
	var N int
	fmt.Scan(&N)

	sc.Split(bufio.ScanWords)
	l := make([]int, N)
	for i := 0; i < N; i++ {
		l[i] = nextInt()
	}

	sort.Sort(sort.IntSlice(l))

	var count int
	for i := 0; i < N; i++ {
		for j := i + 1; j < N; j++ {
			for k := j + 1; k < N; k++ {
				if l[i] < l[j]+l[k] && l[j] < l[i]+l[k] && l[k] < l[i]+l[j] {
					count++
				}
			}
		}
	}

	fmt.Println(count)
}


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

Measured memory_bytes: 1868
#include <bits/stdc++.h>
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
#define mod 1000000007

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

int main(){
    ll n;
    cin >> n;
    vector<string> a(n);
    rep(i,n) cin >> a[i];
    vector<ll> ans(4,0);
    rep(i,n){
        if(a[i]=="AC") ans[0]++;
        if(a[i]=="WA") ans[1]++;
        if(a[i]=="TLE") ans[2]++;
        if(a[i]=="RE") ans[3]++;
    }
    cout << "AC" << " " << "x" << " " << ans[0] << endl;
    cout << "WA" << " " << "x" << " " << ans[1] << endl;
    cout << "TLE" << " " << "x" << " " << ans[2] << endl;
    cout << "RE" << " " << "x" << " " << ans[3] << endl;

    return 0;
}











Measured memory_bytes: 6368
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
using namespace std;

int main() {
	int N;
	int ans = 0;
	cin >> N;
	vector <int> V(N);
	vector <int> C(N);
	for (int i = 0; i < N; i++) {
		cin >> V.at(i);
	}
	for (int i = 0; i < N; i++) {
		cin >> C.at(i);
	}

	for (int i = 0; i < N; i++) {
		if (V.at(i) > C.at(i)) {
			ans += (V.at(i) - C.at(i));
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int a,b;
  scanf("%d %d",&a,&b);
  if(a>b){
    printf("a > b\n");
  }
  else if(a==b){
    printf("a == b\n");
  }
  else{
    printf("a < b\n");
  }
  
  return 0;
  }

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

int main(){
    string S;
    cin >> S;
    int count = 0;
    int max_count = 0;
    for (int i = 0; i < S.size(); i++){
        if (S.at(i) == 'A' || S.at(i) == 'T' || S.at(i) == 'G' || S.at(i) == 'C'){
            count++;
        }
        else{
            max_count = max(max_count, count);
            count = 0;
        }
    }
    cout << max(max_count, count) << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {

    public static void main(String[] args) throws java.lang.Exception {

        Scanner sc = new Scanner(System.in);
        int count = sc.nextInt();

        for (int i = 0; count > i; i++) {
            int y = sc.nextInt();
            int m = sc.nextInt();
            int d = sc.nextInt();

            System.out.println(Answer(y, m, d));
        }
    }

    public static int Answer(int y, int m, int d) {
        int result = 1;

        if (y % 3 == 0) {
            result += 20 - d;
        } else if (m % 2 == 0) {
            result += 19 - d;
        } else {
            result += 20 - d;
        }

        for (m+=1; m <= 10; m++) {
            if (y % 3 == 0) {
                result += 20;
            } else {
                if (m % 2 == 0) {
                    result += 19;
                } else {
                    result += 20;
                }
            }
        }

        for (y += 1; y < 1000; y++) {
            if (y % 3 == 0) {
                result += 200;
            } else {
                result += 195;
            }
        }
        return result;
    }
}

Measured memory_bytes: 20816
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //NOTE: <a> must be sorted in advance

lng power(lng b, lng n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n

const int MOD = 1000000007; //10^9+7


/*********** variables ************/
int N;
lng a[200010];
/**********************************/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    a[0] = -MOD;
    REP(i, N) cin >> a[i+1];

    FOR(i, 1, N) {
        a[i] -= i;
    }

    sort(a+1, a+N+1);

    int hf = N/2 + 1;

    int p = a[hf];
    FOR(i, 1, N) {
        a[i] -= p;
    }

    lng sum = 0;
    FOR(i, 1, N) {
        sum += max(a[i], -a[i]);
    }

    cout << sum << endl;

}


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

int res,poss;
int n,k,a[200010],dist[200010],nxt[200010];
vector<int> v[200010];
int last[200010];

inline void dfs(int pos,int lvl,bool flag)
{
	if(!flag){
		if(dist[pos]!=-1){
			res=lvl;
			poss=pos;
			return;
		}
		dist[pos]=lvl;
		int u=nxt[pos];
		if(u<=pos){last[lvl]=pos;dfs(u,lvl+1,1);}
		else dfs(u,lvl,1);
	}
	else{
		pos++;
		if(pos<=n){
			dfs(pos,lvl,0);
		}
		else dfs(1,lvl+1,0);
	}
}

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n>>k;
	memset(dist,-1,sizeof(dist));
	memset(last,-1,sizeof(last));
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++) v[a[i]].push_back(i);
	for(int i=1;i<=2e5;i++) if(!v[i].empty()){
		for(int j=0;j<v[i].size()-1;j++){
			nxt[v[i][j]]=v[i][j+1];
		}
		nxt[v[i][v[i].size()-1]]=v[i][0];
	}
	dfs(1,1,0);
	int v1=dist[poss]-1,v2=res-dist[poss],st=0;
	if(k<=v1){
		if(last[k]==-1){
			st=n+1;
		}
		else{
			st=last[k];
		}
	}
	else{
		k-=v1;
		k=(k-1)%v2+1;
		k+=v1;
		if(last[k]==-1){
			st=n+1;
		}
		else{
			st=last[k];
		}
	}
	vector<int> ans;
	for(int i=st;i<=n;i++){
		if(nxt[i]<=i){
			ans.push_back(a[i]);
		}
		else{
			i=nxt[i];
		}
	}
	for(int i=0;i<ans.size();i++) cout<<ans[i]<<" ";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 20340
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,m=map(int,input().split())
    E=[[] for _ in range(n)]
    for _ in range(m):
        s,t=map(int,input().split())
        s-=1; t-=1;
        E[s].append(t)
    dp=[0]*n
    for v in range(n-2,-1,-1):
        res=0
        for nv in E[v]: res+=dp[nv]
        dp[v]=1+res/len(E[v])
    ans=dp[0] # 辺を消さなかった時のscore

    # 各 v に対し、削除する辺 v→u は、dp[u]が最大のもの
    for v in range(n-1):
        if(len(E[v])==1): continue
        u=max(*((dp[nv],nv) for nv in E[v]))[1]
        # vu を削除したときの期待値DPを行う
        dp2=[0]*n
        for x in range(n-2,-1,-1):
            res=0
            for nx in E[x]:
                if(x==v and nx==u): continue
                res+=dp2[nx]
            if(v!=x):
                dp2[x]=1+res/len(E[x])
            else:
                dp2[x]=1+res/(len(E[x])-1)
        ans=min(ans,dp2[0])
    print(ans)
resolve()

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


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define PI 3.1415926535897932384626433
#define mod 1000000007
 
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
 
int lcm(int a, int b) { return a * b / gcd(a, b); }
 
int main(){
    ll n;
    string s;
    ll ans = 1;
    cin >> n >> s;
    vector<ll> num(26, 1);

    for(char c : s){
        num[c - 'a']++;
    }

    for (ll i = 0; i < 26; i++){
        ans *= num[i];
        ans %= mod;
    }

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

Measured memory_bytes: 512
// 解き直し.
// https://img.atcoder.jp/data/agc/003/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
const int MAX = 101010;
LL S[MAX], a[MAX], Norm[MAX], Pair[MAX];
vector<LL> Prime;    // 素数を保存.
vector<LL> vPrime2;  // 素数の二乗を保存.
map<LL, LL> mPrime2; // 素数の二乗を保存.

int main(){
    
    // 1. 入力情報.
    int N;
    scanf("%d", &N);
    rep(i, N) scanf("%lld", &S[i]);
    
    // 2. 素数を取得.
    repx(i, 2, 101010){
        if(a[i]) continue;
        repex(j, i * 2, 101010, i) a[j]++;
    }
    
    // 3. 素数, 素数の二乗 を 保存.
    repx(i, 2, 101010){
        LL p = (LL)i;
        if(!a[i]){
            Prime.pb(p);
            vPrime2.pb(p * p);
            mPrime2[p * p] = p; // 素数の二乗から, 素数を逆引き.
        }
    }
    // for(auto &x : Prime) printf("%d ", x);
    // puts("");
    // for(auto &x : Prime2) printf("%d ", x);
    // puts("");
    
    // 4. 標準系(Norm, Pair), 出現回数 を 保存.
    map<LL, LL> mNorm, mPair, mN2P;
    rep(i, N){
        LL t = S[i];
        // Norm を 保存.
        // 同じ素因数を, 3つ以上含まなくなるまで立方数で割る.
        for(auto &x : Prime){
            LL x3 = x * x * x;
            while(t % x3 == 0) t /= x3;
            if(x3 >= t) break;
        }
        Norm[i] = t;
        
        // 素数 99991 を 100000個 並べた場合, 7716[ms] かかったため, ロジック修正.
        // -> 結果として, 33[ms] に 改善した.
        // Pair を 保存.
        LL p = 1;
        if(mN2P.count(t) > 0){
            p = mN2P[t];
        }else{
            if(t > 101010){
                if(mPrime2.count(t)) p = mPrime2[t];
                else                 p = t * t;
            }else{
                for(auto &x : Prime){
                    if(t % x == 0){
                        LL x2 = x * x;
                        if(t % x2 == 0) t /= x2, p *= x;
                        else            t /= x,  p *= x2;
                    }
                    if(x >= t){
                        break;
                    }
                }
            }
            mN2P[Norm[i]] = p; // {Norm, Pair} を 保存.
        }
        Pair[i] = p;
        
        // 各標準形の出現回数を保存.
        mNorm[Norm[i]]++;
        mPair[Pair[i]]++;
    }
    // rep(i, N) printf("%lld ", Norm[i]);
    // puts("");
    // rep(i, N) printf("%lld ", Pair[i]);
    // puts("");
    
    // 5. 標準形 が Norm となるような要素数 と 標準形が Pair となるような要素数 のうち, 大きいほうをすべて加算.
    LL ans = 0;
    set<LL> nMemo, pMemo; // すでに出現したか確認.
    rep(i, N){
        LL n = Norm[i], p = Pair[i];
        if(nMemo.count(n) == 0 && nMemo.count(p) == 0 && pMemo.count(n) == 0 && pMemo.count(p) == 0){
            // 標準形 が Norm で, Norm が 1 の 場合は, 1回だけ加算.
            if(n == 1) ans++;
            else       ans += max({mNorm[n], mNorm[p], mPair[n], mPair[p]});
            nMemo.insert(n);
            nMemo.insert(p);
            pMemo.insert(n);
            pMemo.insert(p);
        }
    }
    
    // 6. 出力.
    printf("%lld\n", ans);
    return 0;
    
}

Measured memory_bytes: 57520
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
    int ans[100];
    int n;
    cin>>n;
    for(int i = 0 ;i < n;i++)
    {
        cin>>ans[i];
    }
    int maxx = abs(ans[0]),id = 0;
    for(int i = 0; i < n;i++)
    {
        if(abs(ans[i]) > maxx)
            maxx = abs(ans[i]),id = i;
    }
    printf("%d\n",2*n-2);
    if(ans[id] >= 0)
    {
        for(int i = 0;i < n;i++)
        {
            if(i!=id)
                printf("%d %d\n",id+1,i+1);
        }
        for(int i = 0;i < n-1;i++)
            printf("%d %d\n",i+1,i+2);
    }
    else
    {
        for(int i = 0;i < n;i++)
        {
            if(i!=id)
                printf("%d %d\n",id+1,i+1);
        }
        for(int i = n-1;i > 0;i--)
            printf("%d %d\n",i+1,i);
    }

    return 0;
}


Measured memory_bytes: 256
n = gets
*array = gets.chomp.split(' ').map(&:to_i)
puts array.join(' ')

class Array
  def swap!(a, b)
    self[a], self[b] = self[b], self[a]
    self
  end
end

array.each_with_index do |key, key_index|
  next if key_index.zero?
  array[0..key_index].each_with_index do |comp, comp_index|
    if key < comp
      array.swap! key_index, comp_index
      next
    end
  end
  puts array.join(' ')
end



Measured memory_bytes: 6944
//#pragma GCC optimize(2)
// Happy TLE and WA every day!
// by: zxb the vegetable chicken
#include<bits/stdc++.h>
#define mp              make_pair
#define rep(i,n)        for(int i = 0; i < n; i++)
#define foreach(i,c)    for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define BINF            0x7fffffff
#define INF             0x3f3f3f3f
#define LINF            3223372036854775807
#define END(s)          {cout<<s; return 0;}
#define CON(s)          {cout<<s; continue;}
#define BRE(s)          {cout<<s; break;}
#define pb              push_back
#define All(a)          a.begin(), a.end()  //with A in CAPITAL!!!
#define sz(a)           (int)a.size()
#define F               first
#define S               second
#define Time            clock()/CLOCKS_PER_SEC
//#define usingFiles
using namespace std;

typedef unsigned int ui;
typedef pair<int, int> pii;
typedef long long ll;

inline bool Read(int& x){
	x = 0;
	int c;
	int sign = 1;
	while( (c = getchar()) < '0' || c > '9' ) if(c == '-') sign = -1;
	x = c ^ '0';
	while( (c = getchar()) >= '0' && c <= '9' ) x = (x<<3) + (x<<1) + (c ^ '0');
	x *= sign;
	return 1;
}

inline bool Write(int x){
	if(x >= 10) Write(x / 10);
	putchar(x % 10 + '0');
	return 1;
}

const int rp = 666666;
const bool debug = 1;
const bool I_good_vegetable_a = 1;

int n;
int a[100100];
int dp[100100];

signed main(){
	ios::sync_with_stdio(false);
	#ifdef usingFiles
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	cin >> n;
	rep(i, n) cin >> a[i];
	memset(dp, 0x3f, sizeof(dp));
	dp[0] = 0;
	dp[1] = abs(a[1] - a[0]);
	for(int i = 2; i < n; i++){
		dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
	}
	cout << dp[n - 1] << endl;
	return 0;
}

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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

const ll MOD = 1000000007;
const double EPS = 1e-9;

map<ll, ll> d;
priority_queue< Pll, vector<Pll>, greater<Pll> > que;
map<ll, vector<Pll> > edges;

void dijkstra(ll start){
    d[start] = 0;
    que.push(Pll(0, start));

    while(!que.empty()){
        Pll v = que.top(); que.pop();
        if(d.find(v.second) != d.end() && d[v.second] < v.first) continue;
        rep(edges[v.second].size()){
            Pll e = edges[v.second][i];
            if(d.find(e.first) == d.end() || d[e.first] > d[v.second] + e.second){
                d[e.first] = d[v.second] + e.second;
                que.push(Pll(d[e.first], e.first));
            }
        }
    }
}

int main(){
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;

    rep(n){
        ll u, k, c, v;
        cin >> u >> k;
        repp(j, k){
            cin >> v >> c;
            edges[u].emplace_back(v, c);
        }
    }

    dijkstra(0);
    repp(u, n){
        cout << u << " " << d[u] << endl;
    }

}



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

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

    int n; cin >> n;

    unordered_map<int, int> umap;
    for (int i = 0; i < n; ++i) {
        int a; cin >> a;
        umap[a]++;
    }

    int picked = 0;
    for (auto item : umap) {
        int key = item.first;
        int val = item.second;
        if (key > val) picked += val;
        else picked += val - key;
    }

    cout << picked << endl;

    return 0;
}

Measured memory_bytes: 4260
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}

static void AGC043A();

#if 1
int main()
{
	AGC043A();
	fflush(stdout);
	return 0;
}
#endif

static void AGC043A()
{
	int H, W;
	getint(H, W);

	std::vector<std::string> grid(H);
	for (int h = 0; h < H; h++) {
		std::cin >> grid[h];
	}

	std::vector<std::vector<std::pair<int, int>>> path(H, std::vector<std::pair<int, int>>(W, std::pair<int, int>((int)MOD_NUM, (int)MOD_NUM)));
	std::queue<std::pair<int, int>> que;
	que.push(std::pair<int, int>(0, 0));

	path[0][0].first = 0;
	path[0][0].second = (grid[0][0] == '#') ? 1 : 0;
	while (!que.empty()) {
		int dh[] = { 0, 1 };
		int dw[] = { 1, 0 };

		std::pair<int, int> pos = que.front(); que.pop();
		int pathCount = path[pos.first][pos.second].first;
		int blackCount = path[pos.first][pos.second].second;
		for (int i = 0; i < 2; i++) {
			int nh = pos.first + dh[i];
			int nw = pos.second + dw[i];

			if ((nh >= 0) && (nw >= 0) && (nh < H) && (nw < W)) {
				int nbCount = blackCount;
				if ((grid[nh][nw] == '#') && (grid[pos.first][pos.second] != '#')) {
					nbCount++;
				}

				if ((nbCount < path[nh][nw].second) ||
					((nbCount == path[nh][nw].second) && ((pathCount + 1) < path[nh][nw].first))) {
					path[nh][nw].first = pathCount + 1;
					path[nh][nw].second = nbCount;
					que.push(std::pair<int, int>(nh, nw));
				}
			}
		}
	}

	printf("%d\n", path[H - 1][W - 1].second);
}

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

using namespace std;

#define ll long long int
#define get(a) ll a; cin >> a;
#define show(a) cout << a << endl;
#define full(p) p.begin(), p.end()
#define sz(a) (ll)(a.size())
#define pb push_back

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout<<fixed;
	////////////////////////////////
	get(n);
	cout << (n*(n+1))	/2 << endl;

	return 0;
}

Measured memory_bytes: 3616
n = int(input())
k = int(input())
a = list(int(i) for i in input().split())  
ans = 0
for i in range(n):
  if 2*a[i] >= abs(2*(k-a[i])):
    ans += abs(2*(k-a[i]))
  else:
    ans +=  2*a[i] 
print(ans)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int n, a[100000], mode = 0/* 増加:1 減少:2 */, ans = 1;

int main(){
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a[i];

		if (i > 0){
			switch (mode){
			case 0:
				if (a[i] > a[i - 1]){
					mode = 1;
				}
				if (a[i] < a[i - 1]){
					mode = 2;
				}
				break;

			case 1:
				if (a[i] < a[i - 1]){
					ans++;
					mode = 0;
				}

				break;

			case 2:
				if (a[i] > a[i - 1]){
					ans++;
					mode = 0;
				}

				break;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>
#include <functional>
#include <cassert>
#include <fstream>
#include <ctime>

using namespace std;
using ll = long long;

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define ASSERT(cond,mes) assert(cond && mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
    for (int i = 1; i*i <= n; ++i) {
        if (n%i == 0) {
            ret.push_back(i);
            if (i != 1 && i*i != n) {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}

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

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

struct ToUpper {
    char operator()(char c) { return toupper(c); }
};

struct ToLower {
    char operator()(char c) { return tolower(c); }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    string S;
    cin >> S;

    int ans = 0;
    int len = S.length();
    int g = 0, p = 0;
    REP(i, len) {
        if (p + 1 > g) {
            g++;
            if (S[i] == 'p')ans--;
        }
        else if (S[i] == 'g') {
            p++;
            ans++;
        }
        else {
            p++;
        }
    }

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

Measured memory_bytes: 512
n = int(input())
a = [0] * n
b = [0] * n
infob= [[0,0] for _ in range(n)]

for i in range(n):
    a[i],b[i] = map(int,input().split())
    infob[i][0] = a[i]
    infob[i][1] = b[i]

info = sorted(infob,key = lambda x: x[1])

t = 0
ans = "Yes"
for i in range(n):
    t = t + info[i][0]
    if t > info[i][1]:
        ans = "No"
        break

print(ans)

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

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


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

string s[200000];
int c[200000] = {0};

int main() {
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> s[i];
	}
	sort(s, s + n);
	string str = s[0];
	int cnt = 0;
	for(int i = 0; i < n; i++){
		if(s[i] == str){
			c[cnt]++;
		}else{
			cnt++;
			c[cnt]++;
			str = s[i];
		}
	}
	int m = 0;
	for(int i = 0; i <= cnt; i++){
		m = max(m, c[i]);
	}
	int j = 0;
	for(int i = 0; i <= cnt; i++){
		if(c[i] == m){
			cout << s[j] << '\n';
		}
		j += c[i];
	}
}


Measured memory_bytes: 15104
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T &a){int t = 0;for(auto itr :a){if(t++)cout << " "; cout << itr;} cout <<endl; }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    //    std::ios_base::sync_with_stdio(false);
    //    cin.tie(NULL);
    using ps = pair<string,pii>;
    int n; cin >> n;
    vector<ps>v(n);
    int cnt = 1;
    for(auto & e : v){
        cin >> e.first >> e.second.first;
        e.second.first  = -1 * e.second.first;
        e.second.second = cnt++;
    }
    sort(all(v));
    for(auto e : v)
        cout << e.second.second << endl;
    
}




Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>

#define MAXN 8000

using namespace std;

string s;
int x,y;

bool dpx[MAXN+1][(MAXN << 1)];
bool dpy[MAXN+1][(MAXN << 1)];

int main(void) {
    cin>>s;
    cin>>x>>y;
    vector<int> d;

    int sum = 0;
    for(int i = 0;i < s.size();i++) {
        if(s[i] == 'T') {
            d.push_back(sum);
            sum = 0;
            continue;
        }
        sum++;
    }

    if(sum != 0) {
        d.push_back(sum);
    }
 
    if(d.size() == 1 && y > 0) {
        cout<<"No"<<endl;
        return 0;
    } else if(d.size() == 1 && d[0] == x) {
        cout<<"Yes"<<endl;
        return 0;
    }

    dpx[0][MAXN+d[0]] = true;
    dpy[0][MAXN+d[1]] = dpy[0][MAXN-d[1]] = true;
    for(int i = 2;i < d.size();i++) {
        for(int j = 0;j < MAXN<<1;j++) {
            if(i % 2 == 0) {
                if(j-d[i] >= 0)
                    dpx[i/2][j] = dpx[i/2-1][j-d[i]] || dpx[i/2-1][j+d[i]];
                else
                    dpx[i/2][j] = dpx[i/2-1][j+d[i]];
            }
            else {
                if(j-d[i] >=0) {
                    dpy[i/2][j] = dpy[i/2-1][j-d[i]] || dpy[i/2-1][j+d[i]];
                } else {
                    dpy[i/2][j] = dpy[i/2-1][j+d[i]];
                }
            }
        }
    }

    if(d.size() % 2 == 1) {
        if(dpx[d.size()/2][MAXN+x] && dpy[d.size()/2-1][MAXN+y]) {
            cout<<"Yes"<<endl;
        } else {
            cout<<"No"<<endl;
        }
    } else { 
        if(dpx[d.size()/2-1][MAXN+x] && dpy[d.size()/2-1][MAXN+y]) {
            cout<<"Yes"<<endl;
        } else {
            cout<<"No"<<endl;
        }
    }
  
    return 0;
}


Measured memory_bytes: 127232
void main()
{
    long h, w, k;
    rdVals(h, w, k);
    string[] s = h.rdCol!string;

    long result = inf;
    outer: foreach (i; 0 .. 1L<<(h-1))
    {
        long cnt = i._popcnt;
        long[][] list = new long[][](w, cnt+1);
        foreach (j; 0 .. w)
        {
            long idx;
            foreach (l; 0 .. h)
            {
                list[j][idx] += s[l][j] - '0';
                if (list[j][idx] > k) continue outer;
                if ((i>>l)&1) ++idx;
            }
        }

        long[] num = new long[cnt+1];
        foreach (j; 0 .. w)
        {
            num[] += list[j][];
            if (num.any!(x => x > k))
            {
                num = list[j];
                ++cnt;
            }
        }

        result = min(result, cnt);
    }

    result.writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

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

int main() {
  int N, K;
  vector<vector<int>> a(100010, vector<int>(3));
  vector<vector<int>> dp(100010, vector<int>(3));

  int res = 0;

  cin >> N;
  rep(i,N){
    rep(j,3){
      cin >> a.at(i).at(j);
    }
  }  
  
  rep(i,3){
    dp.at(0).at(i) = a.at(0).at(i);
  }
  for(int i = 1; i < N; i++){
    rep(j,3){
      dp.at(i).at(j) = a.at(i).at(j) + max(dp.at(i-1).at((j+1)%3), dp.at(i-1).at((j+2)%3));
    }
  }

  cout << max(max(dp.at(N-1).at(0), dp.at(N-1).at(1)), dp.at(N-1).at(2)) << endl;
  
  return 0;
}

Measured memory_bytes: 11136
from itertools import *
n,*s=open(0).read().split()
u=[[min(accumulate(t,lambda a,b: a+(1 if b=="(" else -1),initial=0)),2*t.count("(")-len(t)] for t in s]
m=0
for c,d in chain(sorted([x for x in u if x[1]>=0])[::-1],sorted([x for x in u if x[1]<0],key=lambda z:z[1]-z[0])[::-1]):
    if m+c<0:
        print("No");break
    m+=d
else:
    print("No" if m else "Yes")

Measured memory_bytes: 119412
#include<stdio.h>
int main(void){
  long int length[100];
  int N;
  int i;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%ld",&length[i]);
  }
  int count=0;
  int j;
  int k;
  int max=0;
  int longest;
  for(i=0;i<N;i++){
    for(j=i;j<N;j++){
      for(k=j;k<N;k++){
        if(length[i]!=length[j]&&length[i]!=length[k]&&length[j]!=length[k]){
          	max=length[i];
          	longest=i;
        	if(length[j]>max){
             max=length[j];
              longest=j;
            }
          	if(max<length[k]){
            	max=length[k];
              longest=k;
            }
          	if(max<length[i]+length[j]+length[k]-length[longest]){
              count++;
            }
        }
      }
    }
  }
  printf("%d",count);
}

Measured memory_bytes: 1700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

int main()
{
    INIT;
    int a, b, c, k;
    int sum = 0;
    cin >> a >> b >> c >> k;
    for(int i = k; i > 0; i--){
        if(a == 0 && b == 0 && c > 0){
            sum--;
            c--;
        }
        if(a == 0 && b > 0) b--; 
        if(a > 0){
            sum++;
            a--;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3636
# mv = 0
# for i in range(10**2-1, 10**3+1):
#     ns = 0
#     si = str(i)
#     n = len(si)
#     for j in range(n):
#         ns += int(si[j])
#     mv = max(mv, ns)
#     print(i, mv)

N = input()
ok = True
for i in range(len(N)-1):
    if N[i+1] != '9':
        ok = False

if len(N) == 1:
    print(int(N))
    exit()
ans = 0
if ok:
    for i in range(len(N)):
        ans += int(N[i])
else:
    if N[0] == '1':
        for i in range(len(N)-1):
            ans += 9
    else:
        ans += int(N[0]) - 1
        for i in range(len(N)-1):
            ans += 9

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long LL;
const int N=2010;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
int f[N][N][2];
//每次把贪心分给序列B
//f[i][j][k] 已经放完了n,n-1,...,i+1,i这些数，遗留了j个数还没有放，最后一个数是给了序列A/B
const int mod=1e9+7;
int main()
{
	int n=gi(),k=gi(),i,j,t;
	f[n][0][0]=1;
	for (i=n;i;i--)
		for (j=n;j>=0;j--) {
			(f[i][j][1]+=f[i][j+1][1])%=mod;
			for (t=0;t<2;t++) {
				(f[i-1][j+1][0]+=f[i][j][t])%=mod;
				(f[i-1][j][1]+=f[i][j][t])%=mod;
			}
		}
	t=f[0][n-k][1];
	for (i=n-k-1;i>0;i--) (t<<=1)%=mod;
	printf("%d\n",t);
	return 0;
}


Measured memory_bytes: 31616
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
    int N;
    bool check=false;
    cin >> N;
    for(int i=1;i<=N;i++){
        if(N%i==0){
            int K=N/i;
            if(K<=9 && i<=9) check=true;
        }
    }
    if(check) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int fact(int n) {
  int res = 1;

  for (int i = 2; i <= n; i++) {
    res = res * i;
  }

  return res;
}

int nCr(int n, int r) { return fact(n) / (fact(r) * fact(n - r)); }

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

  int n;
  cin >> n;

  map<ll, ll> mp;
  map<ll, ll> rv;
  for (int i = 1; i <= n; i++) {
    int head = to_string(i)[0] - '0';
    int tail = i % 10;
    int headTail = head * 10 + tail;

    if (tail == 0) continue;

    mp[headTail] += 1;
  }

  ll ans = 0;

  for (int i = 1; i <= n; i++) {
    int head = to_string(i)[0] - '0';
    int tail = i % 10;
    int tailHead = tail * 10 + head;

    if (tail == 0) continue;

    if (mp[tailHead]) {
      ans += mp[tailHead];
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
// Vivek Rai
// Blazer_007

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/detail/standard_policies.hpp>

#define fastio 		ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp	     make_pair
#define inf         0x3f3f3f3f
//#define INF         0x3f3f3f3f3f3f3f3fLL
#define ll          long long
#define pb          push_back
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define ppi	    pair<ll,pii>
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define see(x)	    cout<<x<<endl;
#define see2(x,y)   cout<<x<<" "<<y<<endl;
#define see3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define bit(x, y)   (((x)>>(y))&1)
#define bpt(x)      (__builtin_popcount(x))
#define bptl(x)     (__builtin_popcountll(x))
#define loop(i,a,b)  for(int i=a;i<b;i++)
#define rloop(i,a,b) for(int i=a;i>=b;i--)
#define N 2000010

using namespace std;
//using namespace __gnu_pbds;

//typedef priority_queue<int> maxHeap;
//typedef priority_queue<int,vector<int>,greater<int>()) minHeap;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
// find_by_order(index) -> value at given index or Kth smallest element in set
// order_of_key(X) -> number of elements strictly less than X
//typedef tree<pii , null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> OST;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

ll dp[3001][3001][2];

ll solve(vi& v,int i,int j,bool turn){
    if(i > j)
        return 0;
    if(dp[i][j][turn] != -1)
        return dp[i][j][turn];
    
    if(turn == 1){
        return dp[i][j][turn] = max(v[i] + solve(v,i+1,j,0) , v[j] + solve(v,i,j-1,0));
    }else{
        return dp[i][j][turn] = min(solve(v,i+1,j,1) , solve(v,i,j-1,1));
    }
}

void solution(){
    int n;
    cin >> n;
    vi arr(n+1);
    memset(dp,-1,sizeof dp);
    ll S = 0;
    loop(i,1,n+1){
        cin >> arr[i];
        S += arr[i];
    }
    ll X = solve(arr,1,n,1);
    ll Y = S - X ;
    cout << X - Y << endl;
}

signed main(){
    fastio
    // #ifndef ONLINE_JUDGE
    // 	freopen("input.txt", "r" , stdin);
    // 	freopen("output.txt", "w", stdout);
    // #endif

    ll t=1;
    // cin>>t;
    loop(i,1,t+1){
    	//cout<<"Case #"<<i<<": ";
    	solution();
    }
}




Measured memory_bytes: 141184
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(int n;cin>>n,n;){
		map<char,char> table;
		rep(i,n){
			char a,b;
			cin>>a>>b;
			table[a]=b;
		}
		int m;
		cin>>m;
		rep(i,m){
			char a;
			cin>>a;
			if(table.find(a)!=table.end())
				cout<<table[a];
			else
				cout<<a;
		}
		cout<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 904
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N,K;
    cin >> N >> K;
    string S;
    cin >> S;
    char c = S.at(K - 1);
    S.at(K - 1) = tolower(c);
    cout << S << endl;
}

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

#define MOD 10000007
#define f first
#define s second
#define es " "
#define pb push_back
#define endl "\n"
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define ll long long int
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

int main(){
    fastio;
    int n, a[25], b[25], c[25], resp=0;
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> a[i];
    }
    for(int i=1; i<=n; i++){
        cin >> b[i];
    }
    for(int i=1; i<n; i++){
        cin >> c[i];
    }
    for(int i=1; i<=n; i++){
        resp+=b[a[i]];
        if(a[i]==a[i-1]+1 && a[i]!=1){
            resp+=c[a[i-1]];
        }
    }
    cout << resp << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
 
int main()
{
    string S; int noC = 0 ,C_location;
    cin >> S;
    if(S[0]!='A'){cout << "WA"; return 0;}
    for(int i=2 ; i<(S.size()-1); i++)
        {
         if(S[i]=='C'){ C_location=i; noC++;}
         
        }
        if(noC==0) {cout<< "WA"; return 0; }
    for(int i=1; i<S.size();i++)
    {
        if(int (S[i])>=65 && int (S[i]) <= 90)
        {   if(i!=C_location){cout<< "WA"; return 0;}
 
        }
    }
     if(noC==1)
     {
         cout << "AC";
     }
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
const int maxN = 2019;
int a[maxN], b[maxN];

int main()
{
    string s;
    cin >> s;
    for (int i = 0; i < 2019; ++i)
    {
        a[i] = 0;
        b[i] = 0;
    }
    long long ans = 0;
    for (int j=0; j<s.size(); j++)
    {
        int x = s[j] - 48; b[x]++;
        for (int i = 0; i < maxN; ++i)
            b[(i * 10 + x) % maxN] += a[i];
        ans += b[0];
        for (int i = 0; i < maxN; ++i)
        {
            a[i] = b[i];
            b[i] = 0;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3376