akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
import java.math.BigInteger;
 
public class Main {
	
	public static void main(String[] args) {
	Scanner s = new Scanner(System.in);
	int N = s.nextInt();
	String S = s.next();

	int count = 0;
	int abc = 0;
	for(int i = 0; i < S.length()-2; i++){
		if(S.charAt(i) == 'A' && S.charAt(i+1) == 'B' && S.charAt(i+2) == 'C'){
			count++;
		}
		
	}
	System.out.println(count);
    
  }
}

Measured memory_bytes: 35804
#include <stdio.h>

int check(char* str)
{
    int i = 0;
    for(i = 1; str[i] != '\0'; i++)
    {
        switch(str[i-1]){
        case 'A':
            if(!(str[i] == 'B' || str[i] == 'D' ))
            {
                return 0;
            }
            break;
        case 'B':
            if(!(str[i] == 'A' || str[i] == 'E' || str[i] == 'C'))
            {
                return 0;
            }
            break;
        case 'C':
            if(!(str[i] == 'B' || str[i] == 'F'))
            {
                return 0;
            }
            break;
        case 'D':
            if(!(str[i] == 'A' || str[i] == 'E' || str[i] == 'G'))
            {
                return 0;
            }
            break;
        case 'E':
            if(!(str[i] == 'B' || str[i] == 'D' || str[i] == 'H' || str[i] == 'F'))
            {
                return 0;
            }
            break;
        case 'F':
            if(!(str[i] == 'C' || str[i] == 'E' || str[i] == 'I'))
            {
                return 0;
            }
            break;
        case 'G':
            if(!(str[i] == 'D' || str[i] == 'H'))
            {
                return 0;
            }
            break;
        case 'H':
            if(!(str[i] == 'G' || str[i] == 'E' || str[i] == 'I'))
            {
                return 0;
            }
            break;
        case 'I':
            if(!(str[i] == 'H' || str[i] == 'F'))
            {
                return 0;
            }
            break;
        }
    }
    return 1;
}

int main(void){
    int i;
    for(i = 0; i < 1000; i++)
    {
        char str[11];
        scanf("%s", str);
        if(check(str))
        {
            printf("%s", str);
            printf("\n");
        }
    }
    return 0;
}

Measured memory_bytes: 540
while True:
    n = int(input())
    if n == 0:
        break
    score = {"A": 0, "B": 0}
    for _ in range(n):
        A, B = map(int, input().split())
        if A > B:
            score["A"] += A+B
        elif A < B:
            score["B"] += A+B
        else:
            score["A"] += A
            score["B"] += B
    print(score["A"], score["B"])

Measured memory_bytes: 5612
#include<stdio.h>
int main()
{
    int a,b,c,k,x=0,y=0;
    scanf("%d%d%d",&a,&b,&c);
    scanf("%d",&k);
    while(b<=a)
    {
        b=b*2;
        x++;
    }
    while(c<=b)
    {
        c=c*2;
        y++;
    }
    if(x+y<=k)
        printf("Yes");
    else
        printf("No");
    return 0;
}

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

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;

constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

/*-------------------------------------------*/

int N;
V<V<int>> G;

bool without[100009];
int dp[100009];

void dfs(int v, int p) {
    int mx = 0;
    for(int u : G[v]) {
        if(u != p) {
            dfs(u, v);
            dp[v] += dp[u];
            if(without[u]) chmax(mx, dp[u]);
        }
    }
    dp[v] -= mx;
    if(dp[v] == 0) {
        dp[v] = 1;
        without[v] = true;
    }
}

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

    cin >> N;
    G.resize(N);
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    int r = -1;
    rep(i, N) if(G[i].size() >= 3) r = i;

    if(r == -1) {
        cout << 1 << endl;
        return 0;
    }

    dfs(r, -1);

    cout << dp[r] << endl;

    return 0;
}

Measured memory_bytes: 10624
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t n,a,b;
  cin >> n >> a >> b;
  int64_t ans=0;
  int64_t part1=n/(a+b);
  int64_t part2=n%(a+b);
  int64_t part3;
  if(part2<=a){
    part3=part2;
  }else{
    part3=a;
  }
  ans=part1*a+part3;
  cout << ans << endl;
}
  


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

using namespace std;

double co[3010];
double dp[3010][3010];

void solve(){
    int n;
    
    cin >> n;
    
    for(int i = 1;i <= n;++i){
        cin >> co[i];
    }
    
    dp[1][1] = co[1];
    dp[1][0] = 1 - co[1];
    
    for(int i = 2;i <= n;++i){
        for(int j = 0;j <= n;++j){
            dp[i][j + 1] += dp[i - 1][j] * co[i];
            dp[i][j] += dp[i - 1][j] * (1 - co[i]);
        }
    }
    
    double sum = 0.0;
    
    for(int i = (n + 1)/ 2; i <= n;++i){
        sum += dp[n][i];
    }
    
    cout << fixed << setprecision(9) << sum;
}

int main(){
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 70784
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    Int D; cin >> D;
    if (D == 25) cout << "Christmas" << endl;
    if (D == 24) cout << "Christmas Eve" << endl;
    if (D == 23) cout << "Christmas Eve Eve" << endl;
    if (D == 22) cout << "Christmas Eve Eve Eve" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
ll n;
int main()
{
	cin >>n;
	ll t=1,sum=0,cnt=0;
	while (sum<n) cnt++,t*=26,sum+=t;
	sum-=t;
	n-=sum+1;
	string s="";
	while (cnt--)
	{
		s+=(char)(n%26+'a');
		n/=26;
	}
	reverse(s.begin(),s.end());
	cout <<s;
	return 0;
} 

Measured memory_bytes: 3628
/***************************************** 
****       Solution by SlavicG        ****
*****************************************/
 
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm> 
#include <set>
#include <utility>
#include <queue>
#include <map>
#include <assert.h>
#include <stack>
using namespace std;
#define ll long long
#define forn(i,n) for(int i=0;i<n;++i)
#define MX 10000000001
#define pow2(a) ((a)*(a))
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define endl "\n"
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 int longestIncreasingSubsequenceLenghtDP(int a[],int n){
    int dp[n],ans=0;
    for(int k = 0;k<n;k++){
        dp[k] = 1;
        for(int i = 0;i<k;i++){
            if(a[i] <= a[k]){
                dp[k] = max(dp[k],dp[i] + 1);
                ans = max(dp[k],ans);
            }
        }
    }
    return ans;
 }
int result[1000] = {0};
int factDP(int n) 
{
   if (n >= 0) {
      result[0] = 1;
      for (int i = 1; i <= n; ++i) {
         result[i] = i * result[i - 1];
      }
      return result[n];
   }
}
bool checkPrime(int n)
{
    if(n<2) return false;
    for(int x = 2;x*x <=n;x++)
    {
        if(n%x == 0)return false;
    }
    return true;
}
vector<int> primeFactors(int n){
    vector<int> f;
    for(int x = 2;x*x<=n;x++){
        while(n%x==0){
            f.push_back(x);
            n/=x;
        }
    }
    if(n>1)f.push_back(n);
    return f;
}
int binary_Search_Classic(int n, int arr[],int target){
	int l,r,mid;
	l=0;
	r=n-1;
	while(l<=r){
		mid= l+(r-l)/2;
		if(arr[mid] == target){
			return mid;
		}
		if(arr[mid] < target){
			l=mid+1;
		}else
		{
			r=mid-1;
		}
	}
	return -1;
}
int binary_Search_First_Greater(int n, int arr[],int target){
	int l,r,ans,mid;
	l = 0;
	r = n-1;
	ans=-1;
	while(l<=r){
		mid = l + (r-l)/2;
		if(arr[mid] > target){
			ans=mid;
			r=mid-1;
		}else{
			l = mid+1;
		}
	}
	return ans;
}
int countDistinctCharsString(string s) {
    unordered_map<char, int> m; 
    for (int i = 0; i < s.length(); i++) { 
        m[s[i]]++; 
    }
    return m.size(); 
} 
int main()
{
	int n;
	cin >> n;
	ll a[n];
	for(int i = 0;i<n;i++)
	{
		cin >> a[i];
	}
	int cnt=0;
	for(int i = 0;i<n;i++)
	{
		while(a[i] %2==0)
		{
			a[i]/=2;
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3704
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int,int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=1e9+7;
//
struct poi{
  int X;int Y;int Z;
  bool operator<(const poi&R)const{
    return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
  }
};
/*
ll GCD(ll A,ll B){
  return (B==0)?(A):(GCD(B,A%B));
}
ll LCM(ll A,ll B){
  return A/GCD(A,B)*B;
}
*/
ll kai[202020];
ll gya[202020];
ll nck[202020];
//
ll pow(ll x,ll n,ll mod){
	ll res=1;
  	if(n>0){
		res=pow(x,n/2,mod);
    	if(n%2==0){
    		res=(res*res)%mod;
    	}else{
    		res=(((res*res)%mod)*x)%mod;
    	}
  	}
	return res;
}
//
ll inv(ll n,ll mod){
	return pow(n,mod-2,mod);
}
//
void nCk(ll N,ll mod){
    kai[N]=N;
    ROF(i,1,N){
		(kai[i]=kai[i+1]*i)%=mod;
    }
    gya[1]=inv(1,mod);
    FOR(i,2,N+1){
        (gya[i]=gya[i-1]*inv(i,mod))%=mod;
    }
    FOR(i,1,N){
        (nck[i]=kai[N+1-i]*gya[i])%=mod;
    }
    nck[0]=1;nck[N]=1;
}
//
ll a[202020],b[202020];
int main(){
	ll H,W,A,B;
	cin>>H>>W>>A>>B;
	nCk(H-A+B-1,mod);
	FOR(i,0,H-A){
		a[i]=nck[i];
	}
	nCk(W-B+A-1,mod);
	FOR(i,0,W-B){
		b[i]=nck[i];
	}
	//
	ll ans=0;
	ll aa=H-A-1,bb=W-B-1;
	while(aa>=0&&bb>=0){
		(ans+=(a[aa]*b[bb]%mod))%=mod;
		aa--;bb--;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6784
#include "bits/stdc++.h"

using namespace std;

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

    int x,y,s;
    while(cin>>x>>y>>s,x||y||s){
        int res=0;
        for(int p=1;p<=s/2;p++){
            int q=s-p;
            for(int i=1;i<=p;i++){
                for(int j=1;j<=q;j++){
                    if(i*(100+x)/100 != p || j*(100+x)/100 != q)continue;
                    res =max(res,i*(100+y)/100+j*(100+y)/100);
                }
            }
        }
        cout<<res<<endl;
    }
}

Measured memory_bytes: 3084
n, m, x = map(int,input().split())
ca = []
for _ in range(n):
    ca.append(list(map(int,input().split())))

purchase_l = [0]*n
cost = float('inf')
flag = True

while flag:
    skill = [0]*m
    cost_tmp = 0
    for i in range(n):
        for j in range(m):
            skill[j] += purchase_l[i]*ca[i][j+1]
    for s in skill:
        if s < x:
            break
    else:
        for i in range(n):
            cost_tmp += purchase_l[i]*ca[i][0]
        cost = min(cost, cost_tmp)
    for k in range(1,n+1):
        purchase_l[-k] += 1
        if purchase_l[-k] == 2:
            purchase_l[-k] = 0
        else:
            break
    else:
        flag = False

if cost == float('inf'):
    print(-1)
else:
    print(cost)

Measured memory_bytes: 9244
#include<stdio.h>
#include<iostream>
#include<cstring>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<algorithm>
#define ll long long
#define maxn 25
using namespace std;
int n;
ll a[maxn];

int read()
{
	int num,sign=1;
	char c;
	while((c=getchar())<'0'||c>'9')
		if(c=='-')sign=-1;
	num=c-'0';
	while((c=getchar())>='0'&&c<='9')
		num=(num<<1)+(num<<3)+c-'0';
	return num*sign;
}

ll dfs(int l,int r,int x,int y)
{
	if(l+1>=r)return 0;
	ll ans=1e17;
	for(register int i=l+1;i<r;++i)
		ans=min(ans,dfs(l,i,x,x+y)+dfs(i,r,x+y,y)+a[i]*(x+y));
	return ans;
}

int main()
{
	n=read();
	for(register int i=1;i<=n;++i)a[i]=read();
	cout<<a[1]+a[n]+dfs(1,n,1,1)<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	scanInit()

	s := nextStr()
	t := nextStr()
	s = sortString(s)
	t = reverse(sortString(t))

	if s < t {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
	return
}

// 文字列単体を昇順にする
func sortString(s string) string {
	r := []rune(s)
	sort.Slice(r, func(i, j int) bool { return r[i] < r[j] })
	s = string(r)
	return s

}

// 文字列単体を逆順にする
func reverse(s string) string {
	rns := []rune(s)
	for i, j := 0, len(rns)-1; i < j; i, j = i+1, j-1 {
		rns[i], rns[j] = rns[j], rns[i]
	}
	return string(rns)
}

// ---- readfunc
var sc = bufio.NewScanner(os.Stdin)

func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1804
var s:string;
    n,i,ans,max:longint;
begin
        readln(n);
        readln(s);
        max:=0;
        for i:=1 to n do
        begin
                if s[i]='I' then inc(ans)
                        else dec(ans);
                if ans>max then max:=ans;
        end;
        writeln(max);
end.

Measured memory_bytes: 128
#include<stdio.h>
int main(){
  int N;
  scanf("%d",&N);
  int A[N];
  int arr[N];
  for(int i=0;i<N;i++){
    scanf("%d",&A[i]);
    arr[A[i]-1]=i+1;    
  }
  for(int i=0;i<N;i++){
    printf("%d ",arr[i]);
  }
  return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

ll N, M, V, P, A[100000];

bool func(int m) {
	if (A[m] + M < A[N - P])return false;
	if (V <= P + m)return true;
	ll t = (V - P - m)*M;
	for (int i = m + 1; i <= N - P; i++) {
		t -= min(M, A[m] + M - A[i]);
	}
	return(t <= 0);
}

int main() {
	cin >> N >> M >> V >> P;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A, A + N);
	int l, r;
	l = -1;
	r = N - P;
	while (l + 1 != r) {
		int m = (l + r) / 2;
		if (func(m)) {
			r = m;
		}
		else {
			l = m;
		}
	}
	cout << N - r << endl;
}

Measured memory_bytes: 1024
def main():
    import sys
    input=sys.stdin.buffer.readline
    n=int(input())
    dp=[0]*-~n
    for h,a in zip(map(int,input().split()),map(int,input().split())):
        i,s=h,0
        while i:
            t=dp[i]
            if t>s:s=t
            i-=i&-i
        s+=a
        i=h
        while i<=n:
            if s>dp[i]:dp[i]=s
            i+=i&-i
    print(max(dp))
main()

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

vector<int> a(1000001);

int main()
{
    int N;
    cin >> N;
    a[1] = 7 % N;
    for (int i = 2; i <= N; i++) a[i] = (a[i - 1] * 10 + 7) % N;

    for (int i = 1; i <= N; i++)
    {
        if (a[i] == 0)
        {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;

    return 0;
}

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

int dp[3010][3010];
vector<char> res;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    string s,t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            if(s[i-1] == t[j-1]) dp[i][j] = 1 + dp[i-1][j-1];
            else dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
        }
    }
    while(n > 0 && m > 0)
    {
        if(s[n-1]==t[m-1])
        {
            res.push_back(s[n-1]);
            n--;
            m--;
        }
        else if(dp[n-1][m] > dp[n][m-1]) n--;
        else m--;
    }
    for(int i = res.size()-1; i >= 0; i--) cout << res[i];
    
    
    return 0;
}

Measured memory_bytes: 35584
import java.util.Scanner;

/*

*/

public class Main {
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] L = new int[N];

        for (int i = 0; i < N; i++) {
            L[i] = sc.nextInt();
        }

        int count = 0;

        for (int i = 0; i < N-2; i++) {
            int a = L[i];
            for (int j = i+1; j < N-1; j++) {
                int b = L[j];
                for (int k = j+1; k < N; k++) {
                    int c = L[k];
                    if (a+b>c && b+c>a && c+a>b) {
                    	if (a != b && b != c && c != a) {
                            count++;

                    	}
                    }
                }
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 36236
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp(a,b) make_pair(a,b)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
const int MOD=1000000007;
vector<int> G[300000];
int64_t dist[100001];
bool visited[100001];
map<pair<int,int>,int64_t> p;
void dfs(int k){//地点kから距離を探索
    visited[k]=true;
    rep(i,G[k].size()){//kの隣接点を探索
        int next = G[k][i];
        if(!visited[next]){//まだ探索してない
            visited[next]=true;
            dist[next] = dist[k] + p[mp(next,k)];
            dfs(next);
        }
    }
}
int main(){
    int n;
    cin>>n;
   vector<int> a(n),b(n),c(n);
    rep(i,n-1){
        cin >> a[i]>>b[i]>>c[i];
        a[i]--,b[i]--;
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
        p[mp(a[i],b[i])]=c[i];
        p[mp(b[i],a[i])]=c[i];
    }
    rep(i,n){
        visited[i]=false;
    }
    int q,k;
    cin>>q>>k;
    k--;
    dist[k]=0;
    dfs(k);
    rep(i,q){
        int x,y;
        cin>>x>>y;
        x--,y--;
        cout<<dist[x]+dist[y]<<endl;
    }
}

Measured memory_bytes: 40500
n,k = map(int,input().split())
li = list(map(int,input().split()))

li = li + [0]*k
dp = [10**9]*(n+k)
dp[0] = 0
for i in range(n):
  for j in range(k):
    dp[i+j+1] = min(dp[i+j+1],dp[i] + abs(li[i]-li[i+j+1]))
print(dp[n-1])

Measured memory_bytes: 53216
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
 
const int Maxn = 110;
const int Maxm = 1010;
const int INF = (int) 1e7;
 
int g[Maxn][Maxn];
int a[Maxm], b[Maxm], c[Maxm];
int n, m;
 
int main() {
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        fill(g[i], g[i] + n, INF);
        g[i][i] = 0;
    }
    for (int i = 0; i < m; ++i) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--, b[i]--;
        g[a[i]][b[i]] = g[b[i]][a[i]] = c[i];
    }
 
    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                if (g[i][k] == INF || g[k][j] == INF) continue;
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
            }
 
        }
    }
 
    int cnt = 0;
    for (int i = 0; i < m; ++i) {
        bool use = false;
        for (int j = 0; j < n; ++j) {
            if (g[j][b[i]] == g[j][a[i]] + c[i]) use = true;
        }
        if (use) cnt++;
    }
 
    cout << m - cnt;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=100010,mod=998244353;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
inline int qmo(int x){return x+(x>>31?mod:0);}
int n,m,el,head[maxn],to[maxn*2],nxt[maxn*2],w[maxn*2],col[maxn],cnt[3],ecnt;
ll ans;
bool flag;
inline void add(int u,int v,int w_){
	to[++el]=v;nxt[el]=head[u];head[u]=el;w[el]=w_;
}
void dfs(int u){
	cnt[col[u]]++;
	for(int i=head[u];i;i=nxt[i]){
		int v=to[i];
		ecnt++;
		if(col[v]==-1) col[v]=(col[u]+w[i]+3)%3,dfs(v);
		else if(col[v]!=(col[u]+w[i]+3)%3) flag=false;
	}
}
int main(){
	n=read();m=read();
	FOR(i,1,m){
		int u=read(),v=read();
		add(u,v,1);add(v,u,-1);
	}
	MEM(col,-1);
	FOR(i,1,n) if(col[i]==-1){
		col[i]=0;
		flag=true;
		cnt[0]=cnt[1]=cnt[2]=ecnt=0;
		dfs(i);
		if(flag){
			if(cnt[0] && cnt[1] && cnt[2]) ans+=1ll*cnt[0]*cnt[1]+1ll*cnt[0]*cnt[2]+1ll*cnt[1]*cnt[2];
			else ans+=ecnt/2; 
		}
		else{
			int tot=cnt[0]+cnt[1]+cnt[2];
			ans+=1ll*tot*tot;
		}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 13096
n, m, q = map(int, input().split())
a = [0]*q
b = [0]*q
c = [0]*q
d = [0]*q
for i in range(q):
  a[i], b[i], c[i], d[i] = map(int, input().split())
A = [1] * 10

def check(A, ans):
  t = 0
  for i in range(q):
    if A[b[i]-1] - A[a[i]-1] == c[i]:
      t += d[i]
  if ans < t:
    return t
  else:
    return ans

ans = 0
for i1 in range(1, m+1):
  A[1] = i1
  if n >= 3:
    for i2 in range(i1, m+1):
      A[2] = i2
      if n >= 4:
        for i3 in range(i2, m+1):
          A[3] = i3
          if n >= 5:
            for i4 in range(i3, m+1):
              A[4] = i4
              if n >= 6:
                for i5 in range(i4, m+1):
                  A[5] = i5
                  if n >= 7:
                    for i6 in range(i5, m+1):
                      A[6] = i6
                      if n >= 8:
                        for i7 in range(i6, m+1):
                          A[7] = i7
                          if n >= 9:
                            for i8 in range(i7, m+1):
                              A[8] = i8
                              if n >= 10:
                                for i9 in range(i8, m+1):
                                  A[9] = i9
                                  ans = check(A, ans)
                              else:
                                ans = check(A, ans)
                          else:
                            ans = check(A, ans)
                      else:
                        ans = check(A, ans)
                  else:
                    ans = check(A, ans)
              else:
                ans = check(A, ans)
          else:
            ans = check(A, ans)
      else:
        ans = check(A, ans)
  else:
    ans = check(A, ans)
print(ans)

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

const int N=100005;
long long X,A[N],L,R;
int n,m,cnt,T[N],vis[N];
int h[N],to[N+N],las[N+N],c[N+N];

void dfs(int i,long long a,int t)
{
	if(!vis[i])
	{
		A[i]=a,T[i]=t;
		if(X!=-1)
			if(a+1ll*t*X<=0)
			{
				printf("0");
				exit(0);
			}
		if(t>0)L=max(L,-a/t+1);
		else R=min(R,-a/t-1);
		vis[i]=1;
	}
	else
	{
		if(A[i]!=a&&T[i]==t)
		{
			printf("0");
			exit(0);
		}
		if(A[i]!=a||T[i]!=t)
		{
			if((a-A[i])%(T[i]-t))
			{
				printf("0");
				exit(0);
			}
			if(X==-1||((a-A[i])/(T[i]-t)==X))
    			X=(a-A[i])/(T[i]-t);
    		else
			{
				printf("0");
				exit(0);
			}
		}
		return ;
	}
	for(int x=h[i];x;x=las[x])
	    dfs(to[x],c[x]-a,t*-1);
}

int main()
{
	X=-1;
	scanf("%d%d",&n,&m);
	int i,u,v,w;
	L=-1,R=(1<<30);
	for(i=1;i<=m;i++)
	{
		scanf("%d%d%d",&u,&v,&w);
		las[++cnt]=h[u],h[u]=cnt,to[cnt]=v,c[cnt]=w;
		las[++cnt]=h[v],h[v]=cnt,to[cnt]=u,c[cnt]=w;
	}
	dfs(1,0,1);
	if(X!=-1)printf("1");
	else printf("%lld",max(0ll,R-L+1));
	return 0;
}


Measured memory_bytes: 7680
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    N = int(input())
    inf = 10**17

    def dijkstra_heap(start,edge):
        #始点から各頂点への最短距離(頂点番号:0~N-1)
        d = [inf]*N
        used = [False]*N
        d[start] = 0
        used[start] = True
        edgelist = []
        #a:重み(//), b:次の頂点(%)
        for a,b in edge[start]:
            heappush(edgelist,a*(10**6)+b)

        while len(edgelist):
            #まだ最短距離が決まっていない頂点の中から最小の距離のものを探す
            minedge = heappop(edgelist)
            if used[minedge%(10**6)]:
                continue
            node = minedge%(10**6)
            d[node] = minedge//(10**6)
            used[node] = True

            for e in edge[node]:
                if not used[e[1]]:
                    heappush(edgelist,(e[0]+d[node])*(10**6)+e[1])
        return d

    #N:頂点数   W:辺数
    edge = [[] for i in range(N)]
    #edge[i] : iから出る道の[重み,行先]の配列
    for _ in range(N-1):
        x,y,z = map(int,input().split())
        edge[x-1].append((z,y-1))
        edge[y-1].append((z,x-1))

    q,k = map(int, input().split())
    d = dijkstra_heap(k-1, edge)

    for _ in range(q):
        x,y = map(int, input().split())
        print(d[x-1]+d[y-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 43788
#include<cstdio>
using namespace std;
typedef long long ll;
const int N=110,P=1000000007;
const ll oo=1000000000000000000ll;
int a,i,j,k,n,m,ch,Test,nm;
int nn[N];
ll t,x,y,ans,ta,tb;
ll fib[N];
struct cc { ll a,b;} A[N][N];
void R(ll &x) {
	x=0;ch=getchar();
	while (ch<'0' || '9'<ch) ch=getchar();
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
}
void W(ll x) {
	if (x>=10) W(x/10);
	putchar(x%10+'0');
}
ll min(ll x,ll y) {
	if (x<y) return x;
	return y;
}
bool check(ll a,ll b,int c) {
	//printf("%lld %lld %d\n",a,b,c);
	if (!c) return 1;
	if (a==0) {
		if (c==1) {
			if (b>x) return 0;
			return 1;
		}
		a=b;b=a+b;
		if (a>x || b>y) return 0;
		c--;
	}
	while (c) {
		ll t=a;a=b;b=t+b;
		if (b%a!=t) return 0;
		if (a>x || b>y) return 0;
		c--;
	}
	return 1;
}
void dfs(ll a,ll b,int c) {
	//if (i==5) printf("%lld %lld %d\n",a,b,c);
	if (c==1) {
		nn[i]++;
		A[i][nn[i]].a=b;
		A[i][nn[i]].b=a+b;
		return;
	}
	if (a==0) {
		if (check(b,b,c-1)) dfs(b,b,c-1);
		a=b;
	}
	for (ll i=a+b;i<=y;i+=b) {
		if (check(b,i,c-1)) dfs(b,i,c-1);
		else break;
	}
}
int main() {
	fib[0]=0;
	fib[1]=1;
	nm=1;
	while (fib[nm]<=oo) {
		nm++;
		fib[nm]=fib[nm-2]+fib[nm-1];
	}
	for (i=2;i+2<=nm;i++) {
		x=fib[i+1];y=fib[i+2];
		for (j=1;j<=y;j++) {
			if (check((ll) 0,(ll) j,i-1)) dfs(0,j,i-1);
			else break;
		}
	}
	scanf("%d",&Test);
	while (Test--) {
		R(x);R(y);ans=0;
		if (x==1 && y==1) {
			puts("1 1");
			continue;
		}
		if (x>y) {
			t=x;x=y;y=t;
		}
		a=0;
		while (fib[a+1]<=x && fib[a+2]<=y) a++;
		for (i=1;i<=nn[a];i++) {
			ta=A[a][i].a;
			tb=A[a][i].b;
			//printf("%lld %lld\n",ta,tb);
			if (ta<=x && tb<=y) ans=((y-tb)/ta+1+ans)%P;
			if (ta<=x && tb<=x) ans=((x-tb)/ta+1+ans)%P;
		}
		if (a==2) ans=(ans+P-x)%P;
		W(a-1);putchar(' ');W(ans);puts("");
	}
}

Measured memory_bytes: 4096
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	double w, h; cin >> w >> h;
	double area = (w * h) / 2;
	cout << area << " ";
	double x, y; cin >> x >> y;
	if (x == w / 2 && y == h / 2)cout << 1 << endl;
	else cout << 0 << endl;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long a,b;
  cin >> a >> b;
  int sum =1;
  
  for(int i=min(a,b);i>1;i--){
    if(a%i==0 && b%i==0){
      a=a/i;
      b=b/i;
      sum *= i;
    }
  }
  cout << a*b*sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define eb emplace_back
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define whole(v) begin(v),end(v)
#define print(c,n) for(int i=0;i<n;i++) cout << c[i] << " ";cout << "\n";
#define MOD 1000000007
#define INF 0x3f3f3f3f
void solve(){
	int n;
	cin >> n;
	vector<int > v;
	v.reserve(n);
	for(int i=0;i<n;i++){
		int temp;cin >> temp;
		v.eb(temp);
	}
	auto it = max_element(whole(v));
	int pos1 = it-begin(v);
	int val1 = *it;
	v.erase(it);
	auto it1 = max_element(whole(v));
	int pos2 = it1-begin(v);
	int val2 = *it1;
	for(int i=0;i<n;i++){
		if(i==pos1){
			cout << val2 << "\n";
		}
		else cout << val1 << "\n";
	}
}
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 2432
from collections import Counter
import sys
from random import randint
from time import time
start = time()
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline


def get_sat():
    sat = 0
    when = [-1] * 26
    for i in range(d):
        sat += s[i][t[i]]
        when[t[i]] = i
        for j in range(26):
            sat -= c[j] * (i - when[j])
    return sat


d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
t = [randint(0, 25) for i in range(d)]
ans = get_sat()
while time() - start < 1.8:
    p, q = randint(0, d - 1), randint(0, 25)
    x = t[p]
    t[p] = q
    if ans >= get_sat():
        t[p] = x
for i in t:
    print(i + 1)


Measured memory_bytes: 81748
#include<stdio.h>

int main(void){
    int x,y,r;
    scanf("%d",&x);
    scanf("%d",&y);
    
    if(x==y) printf("%d\n",x);
    else{
    r=x%y;
    x=y%r;
    while(x>0){
        y=r;
        r=x;
        x=y%r;
    }
    printf("%d\n",r);
    }
    
    return(0);
}


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

using namespace std;

using ll = long long;

const int INF = 1145141919;

int n, z, w;
int a[2005];
int dp[2][2005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> z >> w;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = n - 1; i >= 0; i--) {
        dp[0][i] = abs((i == 0 ? w : a[i]) - a[n]);
        dp[1][i] = abs((i == 0 ? z : a[i]) - a[n]);
        for (int j = i + 1; j < n; j++) {
            dp[0][i] = max(dp[0][i], dp[1][j]);
            dp[1][i] = min(dp[1][i], dp[0][j]);
        }
    }
    cout << dp[0][0] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 
int main()
{
  int N, T, A;
  cin >> N >> T >> A;

  vector<int> H(N);
  REP(i, N) cin >> H[i];
  
  vector<double> D(N);
  REP(i,N){
    D.at(i) = max(A - (T - H.at(i)*0.006),(T - H.at(i)*0.006) - A);
  }
  
  sort(ALL(D));
  REP(i,N){
    if(D.at(0) == max(A - (T - H.at(i)*0.006),(T - H.at(i)*0.006) - A)){
      cout << i+1 << endl;
    }
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
#define ALL(x) (x).begin(), (x).end()
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
int main(void) {
    int x;
    cin >> x;
    if (x >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define input freopen("1.txt","r",stdin);
#define output freopen("output.txt","w",stdout);
#define ll long long int
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define vi vector<int>
#define vii vector<vi>
#define vl vector<ll>
#define vll vector<vl>
#define pii pair<int, int>
#define pll pair<ll,ll>
#define mp make_pair
#define vpi vector<pii>
#define vpl vector<pll> 
using namespace std;
 
int p;
const int maxn=1e5+2;
inline int mul(int a,int b) { 
    ll x= (a*1ll*b);
    if(x>=p) return x%p;
    return x;
}

void solve() {
    int K;
    cin>>K;
    p = K * 9;
    int ans = 7 % p;
    if(p & 1) {
        int ten = 10 ;
        bool  poss = false;
        for(int i = 1; i <= K; i++, ten = mul(ten, 10)) {
            if(mul(ans, ten-1) == 0) {
                cout << i;
                poss = true;
                break;
            }
        }
        if(! poss) cout << -1;
    }
    else cout << -1;
}

int main() {
    fast 
    // input output
    int t = 1; 
    // cin>>t; 
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cmath>
#define endl '\n'
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	int digit = log10((double)b) +1;
	double p = pow(10,digit);
	//cout<<p<<" ";
    int n = (a*p)+b;
    //cout<<n;
	int c = floor(sqrt(n));
	//cout<<" "<<c;
	if(c == sqrt(n))puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 512
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let s = scan!();
    for c in s.chars() {
        match c {
            'a' | 'i' | 'u' | 'e' | 'o' => {
                println!("vowel");
            }
            _ => println!("consonant"),
        }
    }
}


Measured memory_bytes: 4352
/*
coded by : Bissultanov Yedyge;
:)
¤
•
¦
§
*/
#include <bits/stdc++.h>
 
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
 
#define mp make_pair
#define np next_permutation
 
#define bg begin()
#define ed end()
 
#define int long long
#define ioi return 0;
 
#define sz size()
#define fix fixed<<setprecision
 
#define lb lower_bound
#define ub upper_bound
 
#define fr first
#define sc second
 
#define pb push_back
#define ppb pop_back
 
#define pf push_front
#define ppf pop_front
 
typedef long double ld;
typedef unsigned long long ull;
 
const int N = (int)5e5 + 7;
const int INF = (int)1e9 + 7;
 
using namespace std;
 
int ans, cnt;
int n , m , k;
int a[N];

main(){
	ios
		cin >> n;
		for ( int i = n ; i <= 1e5 ; i ){
			for ( int j = 2 ; j <= n ; ++j ){
				if ( i % j == 0 && i != j ){
					i++;
					j=2;
				}
			}
			cout << i;
			ioi
		}
	ioi	
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String str1 = sc.next();
    String str2;
    for(int i = 0; i<2; i++) {
      str2 = sc.next();
      if(str1.charAt(str1.length() - 1) == str2.charAt(0)) {
        str1 = str2;
        continue;
      }else {
        System.out.println("NO");
        return;
      }
    }
    System.out.println("YES");
  }
}


Measured memory_bytes: 21716
#include <cstdio>
#include <vector>
#include <algorithm>
#include <vector>
#include <utility>

bool valid(std::vector<int>& b) {
  int n = b.size();
  bool res = true;
  for (int i = 0; i < n; ++i) {
    if (b[i] != i+1) {
      res = false;
      break;
    }
  }
  if (res) return true;

  for (int i = 0; i < n; ++i) --b[i];
  b.push_back(n);
  std::vector<int> c;
  for (auto bi: b)
    if (bi) c.push_back(bi);

  b = std::move(c);
  return false;
}

int testcase_ends() {
  size_t n;
  scanf("%zu", &n);
  if (n == 0) return 1;

  std::vector<int> b(n);
  for (auto& bi: b) scanf("%d", &bi);

  int res = 0;
  while (res <= 10001 && !valid(b)) ++res;
  if (res > 10000) res = -1;
  printf("%d\n", res);
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 2796
import bisect, collections, copy, functools, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    K = I()

    # [0, N]で、non0の数字がK個あるものの数
    @functools.lru_cache
    def f(N, K):
        if N == K == 0:
            ret = 1
        elif N > 0 and K >= 0:
            ret = f(N // 10, K) + N % 10 * f(N // 10, K - 1) + (9 - N % 10) * f(N // 10 - 1, K - 1)
        else:
            ret = 0
        return ret
    
    ans = f(N, K)
    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10120
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = Long.parseLong(sc.next());
        long m = Long.parseLong(sc.next());
        if (n == 1 && m == 1) {
            System.out.println(1);
        } else if (n == 1 || m == 1) {
            if (n > 1) {
                System.out.println(n - 2);
            } else {
                System.out.println(m - 2);
            }
        } else {
            System.out.println((n - 2) * (m - 2));
        }
    }
}

Measured memory_bytes: 23124
// DP
package main

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

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

type intSlice []int

func (s intSlice) fill(x int) {
	for i := 0; i < len(s); i++ {
		s[i] = x
	}
}

func main() {
	N := readInt()
	W := readInt()

	dp := make(intSlice, 100001)
	dp.fill(1000000001)
	dp[0] = 0

	for i := 0; i < N; i++ {
		w := readInt()
		v := readInt()
		for j := 100000 - v; j >= 0; j-- {
			if dp[j] == 1000000001 {
				continue
			}
			if dp[j]+w <= W {
				dp[j+v] = min(dp[j+v], dp[j]+w)
			}
		}
	}
	for j := 100000; j >= 0; j-- {
		if dp[j] == 1000000001 {
			continue
		}
		fmt.Println(j)
		break
	}
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
#define X first
#define Y second
#define LL long long
#define ULL unsigned long long
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define IN freopen("in", "r", stdin);
#define OUT freopen("out", "w", stdout);
 
int main()
{
	int n;
	scanf("%d",&n);
	int last=0;
	LL ans=0;
	for (int j=1;j<=n;++j)
	{
		int x;
		scanf("%d",&x);
		last+=x;
		ans+=last/2;
		last%=2;
		if (x==0) last=0;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M = map(int, readline().split())
    S = list(map(int, readline().split()))
    T = list(map(int, readline().split()))

    dp = [1] * (M + 1)

    for i in range(N):
        dp_prev = dp[:]
        for j in range(M):
            if S[i] == T[j]:
                dp[j + 1] = (dp_prev[j + 1] + dp[j]) % MOD
            else:
                dp[j + 1] = (dp_prev[j + 1] + dp[j] - dp_prev[j]) % MOD

    print(dp[M])
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 74160
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ALL(x) x.begin(),x.end()
const ll MOD=1000000007;
const long double PI=3.14159265358979;

int main(){
  string s;
  ll c=1;
  cin>>s;
  sort(ALL(s));
  for(int i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      c=0;
    }
  }
  if(c){
    cout<<"yes";
  }
  else{
    cout<<"no";
  }
  
}

Measured memory_bytes: 256
#!/usr/bin/env ruby
#
N, D = gets.chomp.split.map(&:to_i)

d = D ** 2

count = 0

N.times do |i|
  x, y = gets.chomp.split.map(&:to_i)
  count += 1 if x ** 2 + y ** 2 <= d
end

puts count


Measured memory_bytes: 14368
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int m;
	cin >> m;
	int ans = 24 + (24 - m);
	cout << ans << endl;
}

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

static const int N_MAX = 100;

int selectionSort(int a[], int n) {
    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        int minj = i;
        for (int j = i; j < n; j++) {
            if (a[j] < a[minj]) {
                minj = j;
            }
        }
        if (i != minj) {
            swap(a[i], a[minj]);
            cnt++;
        }
    }
    return cnt;
}

void trace(int a[], int n) {
    for (int i = 0; i < n-1; i++) {
        cout << a[i] << " ";
    }
    cout << a[n-1] << endl;
}

int main() {
    int n, a[N_MAX];

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

    int cnt = selectionSort(a, n);
    trace(a, n);
    cout << cnt << endl;
}


Measured memory_bytes: 3084