akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof a)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define all(a) (a).begin(),(a).end()
const ll mod=998244353;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int main(){
    fast;
    string s1,s2;
    cin>>s1;
    cin>>s2;
    int ans=0;
    for(int i=0;i<s1.length();i++){
        if(s1[i]!=s2[i]) ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 3800
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define empb emplace_back
#define all(x) (x).begin(),(x).end()
#define lbd(a, x) lower_bound(all(a), x)
const int mod = 1e9 + 7;
map<ll, ll> mp;
ll solve(ll n) {
	if(n == 0) return 1;
	if(n == 1) return 2;
	if(mp.find(n) != mp.end()) return mp[n];
  if(n & 1) {
    return mp[n] = (2 * solve(n / 2) + solve(n / 2 - 1)) % mod;
  } else {
    return mp[n] = (2 * solve(n / 2 - 1) + solve(n / 2)) % mod;
  }
}
int main() {
#ifdef local
	freopen("in.txt", "r", stdin);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	ll n; cin >> n;
	cout << solve(n) << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <functional>
#include <stack>
#include <utility>
#include <map>
#include <queue>
#include <set>
#include <array>
#include <climits>

using namespace std;

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

const ll MOD = 10e9 + 7;
const ll INF = LLONG_MAX;
const ll MAX_V = 10e3;
const double EPS = 10e-6;
const double PI = 3.14159265359;

//int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };
//int d[] = {0,1,0,-1};
//int nx = x + d[i];
//int ny = y + d[(i+1)%4]



int main() {
	ll a, b, c, x, y, ans = 0;
	cin >> a >> b >> c >> x >> y;
	if (c * 2 < a + b) {
		ll m = min(x, y);
		ans += c * 2 * m;
		x -= m;
		y -= m;
	}
	if (c * 2 * x < a*x) {
		ans += c * 2 * x;
	}
	else {
		ans += a * x;
	}
	if (c * 2 * y < b*y) {
		ans += c * 2 * y;
	}
	else {
		ans += b * y;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		long X = sc.nextLong();
		long Y = 100;
		long ans=0;
		
		while (Y<X) {
			Y=(long) (Y*1.01);
			ans=ans+1;
		}
		System.out.println(ans);
    }
}

Measured memory_bytes: 35792
#include <stdio.h>
int main()
{
	int a, b, c, k, soma=0, maior=0;
	scanf("%d %d %d %d", &a, &b, &c, &k);
	for (int i = 0; i < k; ++i)
	{
		if (a > b && a > c)
		{
			a*=2;
		}else if (b > c)
		{
			b*=2;
		}else
			c*=2;
	}
	soma = a + b + c;
	printf("%d\n", soma);
return 0;
}

Measured memory_bytes: 128
As = []
As.append(list(map(lambda x: int(x), input().split(" "))))
As.append(list(map(lambda x: int(x), input().split(" "))))
As.append(list(map(lambda x: int(x), input().split(" "))))
N = int(input())
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if As[i][j] == b:
                As[i][j] = 0

flag = False
for i in range(3):
    if flag:
        break
    temp_flag = True
    for j in range(3):
        if As[i][j] != 0:
            temp_flag = False
    flag = temp_flag
for i in range(3):
    if flag:
        break
    temp_flag = True
    for j in range(3):
        if As[j][i] != 0:
            temp_flag = False
    flag = temp_flag

if As[0][0] == 0 and As[1][1] == 0 and As[2][2] == 0:
    flag = True

if As[0][2] == 0 and As[1][1] == 0 and As[2][0] == 0:
    flag = True

if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
N, H = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

AB.sort(key=lambda x: x[1], reverse=True)

a_max = 0
for i in range(N):
    a_max = max(a_max, AB[i][0])

cnt = 0
sum_throw = 0
for i in range(N):
    if AB[i][1] > a_max:
        sum_throw += AB[i][1]
        cnt += 1

        if sum_throw >= H:
            print(cnt)
            exit()


rem = H - sum_throw

q, r = divmod(rem, a_max)
if r == 0:
    cnt += q
else:
    cnt += q + 1

print(cnt)


Measured memory_bytes: 28460
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000)
INF = 1<<32


def solve(x: int, y: int):
    ans = 0
    
    if x == y:
        ans = 0
    elif abs(x) == abs(y):
        ans = 1
    elif x < y <= 0:
        ans = abs(y-x)
    elif 0 <= x < y:
        ans = abs(y-x) 
    elif x < 0 <= y:
        ans = min(y-x, abs(abs(x)-abs(y))+1)
    elif y < x <= 0:
        if x == 0:
            ans = -y+1
        else:
            ans = 1-y+x+1
    elif 0 <= y < x:
        if y == 0:
            ans = x+1
        else:
            ans = 2+x-y
    elif y < 0 <= x:
        if x == 0:
            ans = -y-x+1
        else:
            ans = abs(abs(x)-abs(y))+1

    print(ans)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    x = int(next(tokens))  # type: int
    y = int(next(tokens))  # type: int
    solve(x, y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  vector<int> vec;

  int t;

  for ( int i = 0; i < 3; i++ ) {
    cin >> t;
    vec.push_back(t);
  }

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

  cout << vec[0] << " " << vec[1] << " " << vec[2] << endl;

  return 0;
}

Measured memory_bytes: 1220
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define EPS 1e-8
#define LL_INF 0x3fffffffffffffff
#define INF 0x3f3f3f3f3f3f3f3f
#define MEM(a, b) memset(a, b, sizeof(a))
#define PPER(i, n, m) for (int i = n; i >= m; i--)
#define REPP(i, n, m) for (int i = n; i <= m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define PER(i, n, m) for (int i = n; i > m; i--)
#define SA(n) scanf("%d", &(n))
#define SLLA(n) scanf("%lld", &(n))
#define MP make_pair
#define FF first
#define SS second
#define PB push_back
#define DE(val) cout << #val << ": " << val << endl;
 
const int dx44[6] = {0, -1, -1, 1, 1};
const int dy44[6] = {0, -1, 1, -1, 1};
const int dx4[6] = {0, 1, 0,-1};
const int dy4[6] = {1, 0, -1,0};
const int dx8[9] = {0, -1, 0, 1, 0, 1, 1, -1, -1};
const int dy8[9] = {0, 0, 1, 0, -1, 1, -1, 1, -1};
const int dx82[9] = {0, -1, -1, 1, 1, 2, 2, -2, -2};
const int dy82[9] = {0, 2, -2, 2, -2, 1, -1, 1, -1};

void update(ll& x,ll v){
    if(x==-1)x=v;
    else if(x>v)x=v;
}
 
ll po(ll a, ll b, ll mod)
{
    ll res = 1;
    a %= mod;
    for (; b; b >>= 1)
    {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}
ll gcd(ll a, ll b)
{
    if (a == 0)
    {
        return b;
    }
    else
    {
        return gcd(b % a, a);
    }
}
void extgcd(ll a, ll b, ll &d, ll &x, ll &y)
{
    if (!b)
    {
        d = a;
        x = 1;
    }
    else
    {
        extgcd(b, a % b, d, y, x);
        y -= x * (a / b);
    }
}
ll inverse(ll a, ll n)
{
    ll d, x, y;
    extgcd(a, n, d, x, y);
    return d == 1 ? (x + n) % n : -1;
}
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const int maxn = 2e5 + 15;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
/*************************************************************************/

int n;
int val[maxn];
void solve() {
    SA(n);
    REPP(i,1,n) {
        SA(val[i]);
    }
    int cur = 1;
    REPP(i,1,n) {
        if(val[i] == cur) {
            cur++;
        }
    }
    int sur = n - cur + 1;
    if(sur == n) {
        sur = -1;
    }
    printf("%d\n", sur);
}
  
int main()
{   
    //freopen("i.txt", "r", stdin);
    // freopen("o.txt", "w", stdout);
    solve();
    return 0;
 
}
 

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;



int main() {

    long long  h,n;
    cin>>h>>n;

    long long sum=0;
    long long temp;

    for(int i=0;i<n;i++){
        cin>>temp;
        sum+=temp;
    }
    if(sum>=h){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
int v[20];
int c[20];
int n;
int sum1=0;
int x;
cin>>n;
 for(int i=0;i<n;i++)
 cin>>v[i];
for(int i=0;i<n;i++)
 cin>>c[i];
for(int i=0;i<n;i++){
if(v[i]>=c[i]){
x = v[i] - c[i];
sum1= sum1 + x;}
}
cout<<sum1;
 return 0;
}


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

int main() {
    ll n, m;
    cin >> n >> m;
    ll ans = 0;
    
    if ((n == 1) && (m == 1)) {
        ans = 1;
    }
    else if ((n == 1) || (m == 1)) {
        ans = max(n, m) - 2;
    }
    else {
        ans = (n - 2) * (m - 2);
    }
    
    cout << ans << endl;
    return 0;
}

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

int main() {
 int n,m;
  cin>>n>>m;
  vector<int> x(m),y(m); //1
  rep(i,m) cin>>x[i]>>y[i];
  //////////
  vector<int> num(n,1);//0
  
  vector<bool> red(n,false);//0
  red[0]=true;
  rep(i,m){
    num[x[i]-1]--;
    num[y[i]-1]++;
    if(red[x[i]-1]){
      
     red[y[i]-1]=true; 
      
      if(num[x[i]-1]==0) red[x[i]-1]=false;
    }
  }
  int ans=0;
  rep(i,n){
    if(red[i]) ans++;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 1408
/****************************************************************************************************
                                        SUBMITTED BY-

                                                AISH_07

****************************************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define ll long long
#define sl set<ll>
#define vs vector<string>
#define pb push_back
#define vl vector<ll>
#define vi vector<int>
#define PI  3.14159265
#define mod 998244353
vl v;
int main()
{
   ll n;
   cin>>n;

   if(n==0)
     cout<<""<<"\n";
   else
   {   string res;
       ll x=n;
       while(x>0)
       {   x--;
           ll rem=x%26;
           ll quo=x/26;
           char ch='a'+rem;
           res+=ch;
           x=quo;
       }
       reverse(res.begin(),res.end());
       cout<<res<<"\n";
   }

  return 0;

}



Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

void solve(){
    ll a,b;cin>>a>>b;
    if(a>b) swap(a,b);
    if(a==b){
        cout<<2*(a-1)<<endl;
        return ;
    }

    ll r=floor(sqrt(a*b));
    ll ans=2*r-2-(r*r==a*b)+((r+1)*r<a*b);
    cout<<ans<<endl;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int q;cin>>q;
    while(q--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main()
{
	int n;
	int a,b;
	scanf("%d",&n);
	if(n==1)
		puts("Hello World");
	else{
		scanf("%d%d",&a,&b);
		printf("%d\n",a+b);
	}
	return 0;
}

Measured memory_bytes: 128
K,N = map(int,input().split())
A = list(map(int,input().split()))

#print(len(A))
#print(A[0]-A[1])
#Maxの差
Ma=0
for i in range(N-1):
    if Ma < A[i+1]-A[i]:
        Ma = A[i+1]-A[i]

if Ma < A[0]+ K-A[N-1]:
    Ma = A[0]+ K-A[N-1]

#k-n
ans = K-Ma
#print(Ma)
print(ans)

Measured memory_bytes: 26420
def make_tree(n):
    i = 2
    while True:
        if i >= n * 2:
            tree = [-1] * i
            break
        else:
            i *= 2
    return tree

def initialization(a):
    l = len(tree) // 2
    for i in range(l, l + len(a)):
        tree[i] = a[i - l]
    for i in range(l - 1, 0, -1):
        tree[i] = max(tree[2 * i], tree[2 * i + 1])
    return

def update(i, x):
    i += len(tree) // 2
    tree[i] = x
    i //= 2
    while True:
        if i == 0:
            break
        tree[i] = max(tree[2 * i], tree[2 * i + 1])
        i //= 2
    return

def find(s, t):
    s += len(tree) // 2
    t += len(tree) // 2
    ans = -1
    while True:
        if s > t:
            break
        if s % 2 == 0:
            s //= 2
        else:
            ans = max(ans, tree[s])
            s = (s + 1) // 2
        if t % 2 == 1:
            t //= 2
        else:
            ans = max(ans, tree[t])
            t = (t - 1) // 2
    return ans

n = int(input())
a = list(map(int, input().split()))
x1, x2 = [0] * n, [0] * n
tree = make_tree(n)
for i in range(n):
    update(a[i] - 1, i)
    x1[i] = find(0, a[i] - 2)
initialization([-1] * n)
for i in range(n):
    j = n - i - 1
    update(a[j] - 1, i)
    x2[j] = n - find(0, a[j] - 2) - 1
ans = 0
for i in range(n):
    ans += a[i] * (i - x1[i]) * (x2[i] - i)
print(ans)

Measured memory_bytes: 119872
#include<stdio.h>
int main()
{
  char b;
  
  scanf("%c",&b);
  
  if(b == 'A'){
    puts("T");
  }else if(b == 'T'){
    puts("A");
  }else if(b == 'C'){
    puts("G");
  }else
    puts("C");
  
  return 0;
}

Measured memory_bytes: 128
N = int(input())
a = [int(input()) for i in range(N)]

can = False
cnt = 0
idx = a[0]-1
while True:
    cnt += 1
    if cnt > N:
        break
    if idx == 1:
        can = True
        break
    idx = a[idx] - 1

if can:
    print(cnt)
else:
    print(-1)

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

import sys
import os

#input_text_path = __file__.replace('.py', '.txt')
#fd = os.open(input_text_path, os.O_RDONLY)
#os.dup2(fd, sys.stdin.fileno())

lst = list(map(int, input().split()))
lst.sort()
s_lst = list(map(str, lst))
s = ' '.join(s_lst)
print(s)

Measured memory_bytes: 7656
#include<bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
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;
}
ll gcd(ll x,ll y){
    if(x<y) swap(x,y);
    //xの方が常に大きい
    ll r;
    while(y>0){
        r=x%y;
        x=y;
        y=r;
    }
    return x;
}
std::vector<ll> sieve(int n) {
  std::vector<ll> res(n);
  std::iota(res.begin(), res.end(), 0);
  for (ll i = 2; i*i < n; ++i) {
    if (res[i] < i) continue;
    for (ll j = i*i; j < n; j += i)
      if (res[j] == j) res[j] = i;
  }
  return res;
}

int main(){
    string P="pairwise coprime";
    string S="setwise coprime";
    string N="not coprime";
    bool flag1=false;
    bool flag2=false;
    ll n;
    cin>>n;
    vector<ll>A(n);
    for(ll i=0;i<n;i++){
        cin>>A[i];
    }
    sort(A.begin(),A.end());
    vector<ll>B=A;
    for(ll i=1;i<n;i++){
        B[i]=gcd(B[i],B[i-1]);
        if(B[i]==1){
            flag1=true;
            break;
        }
    }
    if(!flag1){
        cout<<N<<endl;
    }
    else{
        flag2=true;
        set<ll>C;
        bool flag=true;
        for(ll i=0;i<n;i++){
            ll M=A[i];
            for(ll i=1;i*i<M;i++){
                if(M%i==0){
                    if(i!=1&&C.count(i)){
                        flag=false;
                        break;
                    }
                    C.insert(i);
                    if(i*i!=M){
                        if(C.count(M/i)){
                            flag=false;
                            break;
                        }
                        C.insert(M/i);
                    }
                }
            }
            if(flag==false){
                flag2=false;
                break;
            }
        }
        if(flag2){
            cout<<P<<endl;
        }
        else{
            cout<<S<<endl;
        }
    }
}

Measured memory_bytes: 18816
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <unordered_map>
using namespace std;
#define INF 100000000
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
int main(){
    int N,M;cin>>N>>M;
    if(N>M){
        cout<<"0"<<endl;
        return 0;
    }
    vector<int>X(M);
    for(int i = 0; i < M; i++)
    {
        cin>>X[i];
    }
     sort(X.begin(),X.end());
     vector<int>space(M-1);
     for(int i = 0; i < M-1; i++)
     {
         space[i] = X[i+1] - X[i];
     }
     sort(space.begin(),space.end());
     for(int i = 0; i < N-1; i++)
     {
         space.pop_back();
     }
     cout<<accumulate(space.begin(),space.end(),0);
}

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

#define int long long

int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int N, M, Q;
int dp[11][100001] = {};
vector<int> adj[100001];
int c[100001] = {};

signed main() {
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    cin >> Q;
    for (int i = 1; i <= Q; i++) {
        int v, d;
        cin >> v >> d >> c[i];
        dp[d][v] = i;
    }
    for (int i = 10; i > 0; i--) {
        for (int j = 1; j <= N; j++) {
            if (dp[i][j] != 0) {
                dp[i - 1][j] = max(dp[i - 1][j], dp[i][j]);
                for (int k = 0; k < adj[j].size(); k++) {
                    dp[i - 1][adj[j][k]] = max(dp[i - 1][adj[j][k]], dp[i][j]);
                }
            }
        }
    }
    for (int i = 1; i <= N; i++) {
        cout << c[dp[0][i]] << endl;
    }
    return 0;
}


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

// Define
using ll = int64_t;
using ul = uint64_t;
using ld = long double;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ul MAX = ULONG_MAX;
const char nl = '\n';

#define elif else if
#define def inline auto
#define run __attribute__((constructor)) def _

// Debug
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i < _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i > _##i; --i)
#define rep(i, n) inc(i, 0, n)
#define be(c) begin(c), end(c)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("-O3")
#pragma GCC target("avx")

// Math
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

signed main(){
    using pii = pair<int, int>;
    int N, M;
    cin >> N >> M;
    vector<int> ps(M);
    vector<pii> ys[N+1];
    rep(i, M) {
        int y;
        cin >> ps[i] >> y;
        ys[ps[i]-1].emplace_back(y, i);
    }
    vector<int> yearn(M);
    rep(i, N) {
        sort(be(ys[i]));
        int ord = 0;
        for(auto& p : ys[i]) {
            yearn[p.second] = ++ord;
        }
    }
    rep(i, M) {
        printf("%06d%06d\n", ps[i], yearn[i]);
    }

}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
int main(void){
  string A, B, C;
  cin >> A >> B >> C;
  if(A.at(A.size() - 1) == B.at(0) && B.at(B.size() - 1) == C.at(0)){
    cout << "YES";
  } else {
    cout << "NO";
  }
}

Measured memory_bytes: 256
#include <math.h>
#include <regex>
#include "bits/stdc++.h"
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX / 2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vb = vector<bool>;
using vvb = vector<vb>; 
using vvvb = vector<vvb>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using psi = pair<string, int>;


int bs_cnt_less(vl& A, const ll X, bool equal) {
    int N = A.size();
    int l = 0, r = N; // [l,r)
    //       l|r
    // ooo..oo|xxx..xx
    if (equal){
        while(l < r-1) {
            int m = (l + r) / 2;

            if (A[m] <= X) l = m;
            else r = m;
        }
    } else {
          while(l < r-1) {
            int m = (l + r) / 2;

            if (A[m] < X) l = m;
            else r = m;
        }
    }
    return l+1; // count = index+1
}


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

  int N; cin >> N;
  vl L(N); REP(i,N) cin >> L[i];

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

  int cnt = 0;
  REP(i,N-2) {
    FOR(j,i+1,N-1) {
      cnt += bs_cnt_less(L, L[i]+L[j], false) - (j+1);
    }
  }

  int ans = cnt;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

typedef struct item_t
{
	long long int weight;
	long long int value;
}item_t;

long long int dp[110][100100];

int main()
{
	int N;
	int W;
	double Wlimit = pow(10.0, 5.0);
	int Nlimit = 100;
	double itemValueLimit = pow(10.0, 9.0);
	long long int maxSum = 0;

	long long int temp = 0;
	item_t *item;

	if (scanf("%d %d", &N, &W) != 2)
	{
		exit(1);
	}

	if (1 <= N && N <= Nlimit)
	{
	}
	else
	{
		exit(1);
	}

	if (1 <= W && W <= Wlimit)
	{
	}
	else
	{
		exit(1);
	}

	item = (item_t*)malloc(sizeof(item_t)* N);

	for (int i = 0; i < N; i++)
	{

		if (scanf("%lld %lld", &item[i].weight, &item[i].value) != 2)
		{
			exit(1);
		}

		if (1 <= item[i].weight && item[i].weight <= W)
		{
		}
		else
		{
			exit(1);
		}

		if (1 <= item[i].value && item[i].value <= itemValueLimit)
		{
		}
		else
		{
			exit(1);
		}
	}

	for (int i = 0; i < 110; i++)
	{
		for (int j = 0; j < 10010; j++)
		{
			dp[i][j] = 0;
		}
	}

	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < (W + 1); j++)
		{
			if (item[i].weight <= j)
			{
				temp = item[i].value + dp[i][j - item[i].weight];
				if (dp[i][j] < temp)
				{
					dp[i + 1][j] = temp;
				}
				else
				{
					dp[i + 1][j] = dp[i][j];
				}
			}
			else
			{
				dp[i + 1][j] = dp[i][j];
			}
		}
	}

	for (int i = 0; i < (W + 1); i++)
	{
		if (maxSum < dp[N][i])
		{
			maxSum = dp[N][i];
		}
	}

	printf("%lld", maxSum);

	return 0;
}

Measured memory_bytes: 85504
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
struct act{
int a,b,c;};
int main() {
	//code


	    int n;
	    cin>>n;
	    vector<act>arr(n+1);
	    for(int i=1;i<=n;i++)
	    {
	        cin>>arr[i].a>>arr[i].b>>arr[i].c;
	    }

	  int dp[n+1][3];
	    dp[1][0]=arr[1].a;
	        dp[1][1]=arr[1].b;
	        dp[1][2]=arr[1].c;
	    for(int i=2;i<=n;i++)
	    {
	      dp[i][0]=arr[i].a+max(dp[i-1][1],dp[i-1][2]);
	      dp[i][1]=arr[i].b+max(dp[i-1][0],dp[i-1][2]);
	      dp[i][2]=arr[i].c+max(dp[i-1][1],dp[i-1][0]);

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


Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    string S;
    cin >> S;
    if(S == "AAA" || S == "BBB") cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

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

using namespace std;

#define nmax 200005

int a[nmax], n, l[nmax], dp[nmax], mod = 1000000007;
vector<int> conn[nmax];

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

int main() {

    int n;
    scanf("%d", &n);

    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);

        if (0 < l[a[i]] && l[a[i]] < i-1)
            conn[i].push_back(l[a[i]]);

        l[a[i]] = i;
    }

    dp[0] = 1;
    for (int i = 1; i <= n; ++i) {
        add(dp[i] , dp[i-1]);
        for (auto it: conn[i]) add(dp[i], dp[it]);
    }

    cout << dp[n] << "\n";

    return 0;
}

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

#define ll                  long long
#define ld                  long double
#define inf             1e18
#define w(x)            int x; cin>>x; while(x--)
#define en           "\n"
#define boostUP     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fsr(i,n)        for(int i=0;i<n;i++)
#define fcr(i,a,b)      for(int i=a;i<b;i++)
#define pb              push_back
#define sz(arr)         sizeof(arr)/sizeof(arr[0])
#define mod             1e9+7
#define setbits(x)      __builtin_popcountll(x)
#define COMPUTE_GCD(a, b)       std :: __gcd((a), (b))
#define COMPUTE_LCM(a, b)       (a * ((b) / COMPUTE_GCD(a, b)))


#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





int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w",  stdout);
#endif
	boostUP;
	int n;
	cin >> n;
	vector<int> h(n, mod);
	vector<int> a(n, mod);

	for (int i = 0; i < n; i++)
	{
		cin >> h[i];
		if (i == 0)
		{
			a[i] = 0;
		}
		else if (i == 1)
		{
			a[i] = abs(h[i] - h[i - 1]);
		}
		else
		{
			a[i] = min(abs(h[i] - h[i - 1]) + a[i - 1], abs(h[i] - h[i - 2]) + a[i - 2]);
		}
	}
	cout << a.back();




	return 0;

}



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

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<char>());
  if (s < t)
    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;
typedef vector<int> Vec;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define sum(v) accumulate(ALL(v),0)

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

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

struct SegTree {
private:
    int N;
    int *dat;
public:
    SegTree(int n) {
//        to parent n-1/2
//        to child 2n+1, 2n+2
        N=1;
        while (N<n) N*=2;
        dat = (int *)malloc((2*N+4) * sizeof(int));
        for(int i=0; i<2*N-1; i++)
            dat[i]=-1;
    }

    void debug(int n) {
        rep(i, 2*n-1) {
            cout<<dat[i]<<endl;
        }
    }

    void update(int k, int a) {
        k+=N-1;
        dat[k]=a;
        while (k>0) {
            k=(k-1)/2;
            dat[k]=max(dat[k*2+1], dat[k*2+2]);
        }
    }

    // max [a, b) a以上b未満
    int query(int a, int b) { return query(a, b, 0, 0, N); }
    int query(int a, int b, int k, int l, int r) {
        if(r<=a||b<=l) return -1;
        if(a<=l&&r<=b) return dat[k];
        int m=(l+r)/2;
        return max(query(a, b, k*2+1, l, m), query(a, b, k*2+2, m, r));
    }

};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin>>n>>m;
    vector<pair<int, int>> v(n);
    priority_queue<int, vector<P>, function<bool(P, P)>> q([](P a, P b)->int {
        if(a.second==b.second) {
            return a.first<b.first;
        } else {
            return a.second<b.second;
        }
    });

    rep(i, n) {
        int an, bn;
        cin>>an>>bn;
        q.push(make_pair(an, bn));
    }

//    while(q.size()){
//        cout << q.top() << endl;
//        q.pop();
//    }

    ll ans=0;
    ll count=0;
    SegTree st(m);

    rep(i, m) {
        st.update(i, i);
    }

    while (q.size()&&count<m) {
        P p=q.top();
        //dbg(p);
        //最後の日から逆算する
        int ind;
        ind=st.query(0, m-p.first+1);
        //dbg(ind);
        if(ind!=-1) {
            st.update(ind, -1);
            ans+=p.second;
            count++;
            //st->debug(m);
        }
        q.pop();
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2932
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int n;
    cin >> n;
    cout << "ABC" << n << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(ll i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;
constexpr int MOD = 1000000009;

// + - * / ^
int mod(int a)
{
    int res = a % MOD;
    if(res < 0) {
        return res + MOD;
    }
    return res;
}
int mul_mod(int a, int b)
{
    ll res = ((ll)a * (ll)b) % MOD;
    return mod((int)res);
}
int pow_mod(int a, int b)
{
    ll res = 1;
    while (b > 0) {
        if(b & 1) {
            res = res * (ll)a % (ll)MOD;
        }
        a = mul_mod(a, a);
        b >>= 1;
    }
    return (int)res;
}
int inv_mod(int a)
{
    return pow_mod(a, MOD - 2);
}
int div_mod(int a, int b)
{
    return mul_mod(a, inv_mod(b));
}

// ! C
constexpr int FAC_MAX = 100000;
ll fac[FAC_MAX], finv[FAC_MAX], inv[FAC_MAX];
void com_init()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < FAC_MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll com_mod(int a, int b){
    if (a < b) return 0;
    if (a < 0 || b < 0) return 0;
    return fac[a] * (finv[b] * finv[a - b] % MOD) % MOD;
}

int main(void)
{    
    string str;
    cin >> str;
    ll n;
    cin >> n;
    vector<int> len;
    int tmp = 0, has = 0;
    bool flg = false;
    rep(i, str.size()){
        if(i == 0) tmp = 1;
        else if(str[i - 1] != str[i]) {
            len.push_back(tmp);
            tmp = 1;
        } else {
            tmp++;
        }
    }
    len.push_back(tmp);
    if(str[0] == str[str.size() - 1]) {
        flg = true;
        has = len.front() + len.back();
    }
    // cout << len.size() << endl;
    // cout << flg << " " << has << endl;
    if (!flg) {
        ll a = 0;
        rep(i, len.size()) {
            a += len[i] / 2;
        }
        cout << a * n << endl;
    } else if(len.size() == 1) {
        cout << (str.size() * n) / 2 << endl;
    } else {
        ll a = 0;
        repp(i, 1, len.size() - 1) {
            a += len[i] / 2;
        }
        cout << a * n + (has / 2) * (n - 1) + len.front() / 2 + len.back() / 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
A.insert(0,0)
A.append(0)
C=0
for i in range(1,N+2):
    sa=A[i]-A[i-1]
    C+=abs(sa)
i=0
for i in range(N):
    print(C-abs(A[i+2]-A[i+1])-abs(A[i+1]-A[i])+abs(A[i+2]-A[i]))


Measured memory_bytes: 13920
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    n,a,b = map(int, input().split())
    print(min(n*a,b))

if __name__ == '__main__':
    main()


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

uint_fast32_t N, M, a[101010], A;
unordered_map<uint_fast32_t, uint_fast32_t> m;

int main(){
    scanf("%u%u", &N, &M);
    m[0] = 1;
    for(int i = 1; i <= N; ++i){
        scanf("%u", a + i);
        a[i] += a[i - 1];
        a[i] %= M;
        A += m[a[i]]++;
    }
    cout << A << endl;
    return 0;
}

Measured memory_bytes: 4108
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p = sorted(p)
q = sorted(q)
r = sorted(r)
p = p[-x:]
q = q[-y:]
q.extend(r)
p.extend(q)
al = sorted(p)

ans = 0
for i in range(x+y):
    ans += al[-(i+1)]

print(ans)


Measured memory_bytes: 22952
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int X; cin >> X;
	bool dp[100001];
	int price[] = { 100,101,102,103,104,105 };
	memset(dp, false, sizeof(dp));
	dp[0] = true;
	rep(i, 0, sizeof dp) {
		if (!dp[i])continue;
		rep(j, 0, 6) {
			if (i + price[j] > X)continue;
			dp[i + price[j]] = true;
		}
	}
	cout << (dp[X] ? 1 : 0) << "\n";

	return 0;
}

Measured memory_bytes: 3748
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	S = list(input())
	ans = 1
	for i in range(N - 1):
		if S[i] != S[i + 1]:
			ans += 1
	print(ans)

if __name__ == '__main__':
	main()

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

// a より b の方が小さかったら，a の値を b の値に置き換える (そして true を返す)
// そうでなかったら、何もしない (そして false を返す)
template<class T> inline bool change_min(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

// a より b の方が大きかったら，a の値を b の値に置き換える
// そうでなかったら、何もしない (そして false を返す)
template<class T> inline bool change_max(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

// 無限大の値を設定
const long long INF = 1LL << 60;

// 高さテーブルを用意
long long h[100010];

// DP テーブルを用意
long long dp[100010];

int main(void) {
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> h[i];
    }
    // DP テーブル全体を初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 100010; ++i) {
        dp[i] = INF;
    }
    // 初期条件を設定
    dp[0] = 0;
    for (int i = 0; i < N; ++i) {
        change_min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
        change_min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
    }
    cout << dp[N - 1] << '\n';
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <queue>
#include<iomanip>
#include <cmath>
#include <set>
#include <unordered_set>

#define ABS(x) ((x)>0?(x):-(x))
#define MIN(x,y) ((x)>(y)?(y):(x))
#define MAX(x,y) ((x)<(y)?(y):(x))

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

#define INF 1000000000

using namespace std;
typedef long long ll;

ll newton(long long int a, long long int  b)
{
	if(a==b)
		return a;
	while(a != 0 && b != 0)
	{
		if(a > b)
		{
			b += a;
			a = b-a;
			b -= a;
		}
		b %= a;
	}
	return a;
}

struct UnionFind {
	vector<int> p;
	UnionFind(int N):p(N)
	{
		for(int i=0; i< N; i++)
		{
			p[i] = i;
		}
	}
	int root(int x)
	{
		if(p[x] == x)
			return x;
		return p[x] = root(p[x]);
	}
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		p[rx] = ry;
	}
	bool issame(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

//大きな数に対する割り算をするとき、MODを指定することで掛け算の値に変換できる

ll div2mul_calc(ll a, ll b, ll m)
{
	if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll d = div2mul_calc(a, b / 2, m);
        return (d * d) % m;
    } else {
        return (a * div2mul_calc(a, b - 1, m)) % m;
    }
}
ll div2mul(ll n, ll mod)
{
	return div2mul_calc(n, mod-2, mod);
}

ll twoRow(ll a, ll b, ll mod)
{
	ll ret = 1;
	for(ll i = 1 ;i <= a+b;++i)
	{
		ret *= i;
		ret %= mod;
	}
	for(ll i = 1 ;i <= a;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	for(ll i = 1 ;i <= b;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	return ret;
}

struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return (ret);
}
/*
*/

int main()
{
	string S;
	ll i,j,k,a,b;
	ll N,M,K;
	vector<int> v[256];
	cin>>N;
	char ch;
	int m[256][256] = {0};
	for(i=0;i<N;++i)
	{
		for(j=0;j<N;++j)
		{
			cin>>ch;
			if(ch=='1')
			{
				v[i].push_back(j);
				v[j].push_back(i);
				m[i][j]=1;
				m[j][i]=1;
			}

		}
	}
	//check
	k = 1;
	int mp[256] = {0};
	queue<int> q;
	q.push(0);
	mp[0]=1;
	while(!q.empty())
	{
		int p=q.front();
		q.pop();
		for(i=0;i<v[p].size();++i)
		{
			j=v[p][i];
			if(mp[j]==0)
			{
				mp[j]=mp[p]*-1;
				q.push(j);
			}
			else
			{
				if(mp[j]==mp[p])
				{
					k=0;
					break;
				}
			}
		}
		if(!k)
			break;
	}
	if(!k)
	{
		cout << -1 << endl;
		return 0;
	}
	int len[256][256]={0};
	for(i=0;i<N;++i)
	{
		for(j=0;j<N;++j)
		{
			len[i][j]=1000000;
			if(i==j)
				len[i][j]=0;
			if(m[i][j])
				len[i][j]=1;
		}
	}
	for(k=0;k<N;++k)
	for(i=0;i<N;++i)
	for(j=0;j<N;++j)
	{
		if(len[i][j] > len[i][k]+len[k][j])
			len[i][j] = len[i][k]+len[k][j];
	}
	int mx = 0;
	for(i=0;i<N;++i)
	for(j=0;j<N;++j)
	{
		if(len[i][j] > mx)
			mx = len[i][j];
	}
	cout << mx+1 << endl;



	return 0;
}




















Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=200+10;
int vis[maxn][maxn];
struct Node
{
    int x,y;
    Node(){}
    Node(int a,int b):x(a),y(b){}
};
vector<Node >G;
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    if(n==0)
    {
         printf("-1\n");
        return 0;
    }
    int m=n-1;
    int sum=(m)*(m-1)/2;
    if(k>sum)
    {
        printf("-1\n");
        return 0;
    }
    for(int i=1;i<=m;i++)
    {
        G.push_back(Node(i,n));
    }

    int i=1,j=2;
    while(sum!=k)
    {
        sum--;
        G.push_back(Node(i,j));
        j++;
        if(j==m+1) i++,j=i+1;
    }

    printf("%d\n",G.size());
    for(int i=0;i<G.size();i++)
    {
        printf("%d %d\n",G[i].x,G[i].y);
    }
}


Measured memory_bytes: 384
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#define GYOU_MAX 256
void sort_string(char Text[], int size, int sign) {
	char a;

	for (int i = 0; i < size - 1; i++) {
		for (int j = 0; j < size - 1 - i; j++) {
			if (sign > 0) {
				if (Text[j] > Text[j + 1]) {

					a = Text[j];
					Text[j] = Text[j + 1];
					Text[j + 1] = a;
				}
			}
			else {
				if (Text[j] < Text[j + 1]) {

					a = Text[j];
					Text[j] = Text[j + 1];
					Text[j + 1] = a;

				}
			}
		}

	}

}

int main(void){

	char s[101], t[101];
	scanf("%s%s", s, t);
	sort_string(s, strlen(s),1);
	sort_string(t, strlen(t), 0);
	if (strcmp(s, t) < 0) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main (void){
  int n,i,max=0,sum=0,max_i=0;
  int p[10000];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&p[i]);
    if(max<p[i]){
      max=p[i];
      max_i=i;
    }
  }
  for(i=0;i<max_i;i++){
    sum+=p[i];
  }
  sum+=p[max_i]/2;
  for(i=max_i+1;i<n;i++){
    sum+=p[i];
  }
  printf("%d",sum);
  return 0;
}

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

using namespace std;

int main()
{
	string S;
	int N;
	bool flag1 = true;
	cin >> S;
	N = S.length();
	for (int count = 0; count < N / 2; count++)
	{
		if (S.at(count) != S.at(N - count - 1))
		{
			flag1 = false;
			break;
		}
	}
	if (flag1)
	{
		vector<char> A(N / 2);
		vector<char> B(N / 2);
		int tmp = (N + 3) / 2;
		for (int count = 0; count < N / 2; count++)
		{
			A.at(count) = S.at(count);
			B.at(count) = S.at(tmp + count - 1);
		}
		for (int count = 0; count < A.size() / 2; count++)
		{
			if (A.at(count) != A.at(A.size() - count - 1))
			{
				flag1 = false;
				break;
			}
		}
		if (flag1)
		{
			for (int count = 0; count < B.size() / 2; count++)
			{
				if (B.at(count) != B.at(B.size() - count - 1))
				{
					flag1 = false;
					break;
				}
			}
		}
	}
	if (flag1)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>

using namespace std;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());

using ll = long long int;

ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}

int main(){
    int n, now = 1;
    cin >> n;
    vector<int> a(n);
    in_arr(int, a, n);

    rep(i, n) {
        if(a[i] == now) {
            //cout << now << endl;
            ++now;
        }
    }
    if(now == 1) {
        cout << -1 << endl;
    } else {
        cout << n - now + 1 << endl;
    }
    //cout << n << now << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
const long long MOD = 1000000007;
const int MAX = 2000001;
long long fac[MAX];
long long finv[MAX];
long long inv[MAX];
 
void comb_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long comb(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long power(long long m, long long n){
    long long res = 1;
    while(n > 0){
        if(n & 1) {
            res = (res * m) % MOD;
        }
        m = (m * m) % MOD;
        n >>= 1;
    }
    return res;
}

long long inverse(long long a){
    return power(a, MOD - 2);
}
/*
long long get_sum_sq(long long a){
  long long ret = 0;
  long long two_power = 1;
  for(long long i = 0; i < a * 2 - 1; i++){
    ret = (ret + two_power) % MOD;
    two_power = (two_power * 2) % MOD;
  }

  long long tmp = 0;
  for(long long i = 0; i < a - 1; i++){
    tmp = ((tmp * 2) % MOD + comb(a + i - 1, i)) % MOD;
    ret = (ret - (tmp * 2) % MOD + MOD) % MOD;
  }

  return ret;
}
*/

long long get_sum(long long r, long long c){

  long long ret = 0;
  long long two_power = 1;
  for(long long i = 0; i < r + c - 1; i++){
    ret = (ret + two_power) % MOD;
    two_power = (two_power * 2) % MOD;
  }

  long long tmp = 0;
  for(long long i = 0; i < c - 1; i++){
    //cout << "tmp: " << tmp << endl;
    tmp = ((tmp * 2) % MOD + comb(r + i - 1, i)) % MOD;
    ret = (ret - tmp + MOD) % MOD;
  }
  tmp = 0;
  for(long long i = 0; i < r - 1; i++){
    tmp = ((tmp * 2) % MOD + comb(c + i - 1, i)) % MOD;
    ret = (ret - tmp + MOD) % MOD;
  }

  /*
  long long ret = get_sum_sq(c);
  long long tmp = get_sum_sq(r);
  cout << "get_sum: " << ret << " " << tmp << endl;

  long long rest = (((tmp - ret + MOD) % MOD) * inverse(2)) % MOD;
  ret = (ret + rest) % MOD;
  */
  return ret;
}

int main(){
  long long r1;
  long long r2;
  long long c1;
  long long c2;
  cin >> r1 >> c1 >> r2 >> c2;

  comb_init();

  long long ans = get_sum(r2 + 1, c2 + 1);
  ans = (ans - get_sum(r1, c2 + 1) + MOD) % MOD;
  ans = (ans - get_sum(r2 + 1, c1) + MOD) % MOD;
  ans = (ans + get_sum(r1, c1)) % MOD;
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 47104
#!/usr/bin/env python3
import bisect
import collections
import sys
import math
from fractions import Fraction

sys.setrecursionlimit(1000000)
ACMOD = 1000000007
INF = 1 << 62

MOD = 1000000007  # type: int


def solve(N: int, A: "List[int]", B: "List[int]"):
    ab = collections.defaultdict(lambda: [0, 0])  # [posi][nega]
    zeros = 0
    for i in range(N):
        if A[i] == B[i] == 0:
            zeros += 1
        elif A[i] == 0:
            ab[0][1] += 1
        elif B[i] == 0:
            ab[0][0] += 1
        elif A[i] * B[i] >= 0:
            v = math.gcd(A[i], B[i])
            ab[(abs(B[i]) // v, abs(A[i]) // v)][0] += 1
        else:
            v = math.gcd(A[i], B[i])
            ab[(abs(A[i]) // v, abs(B[i]) // v)][1] += 1

    # check B[i] ==0
    ans = 1
    for x, y in ab.values():
        pattern = 1  # not select
        pattern += 2 ** x - 1
        pattern += 2 ** y - 1
        ans = ans * pattern % MOD
    print((ans - 1) % MOD + zeros)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 117332