akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;

namespace Testcode
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
                if (x[0] == 0 && x[1] == 0)
                {
                    break;
                }
                for (int i = 0; i < x[0]; i++)
                {
                    for (int I = 0; I < x[1]; I++)
                    {
                        if ((I + i) % 2 == 0)
                        {
                            Console.Write("#");
                        }
                        else
                        {
                            Console.Write(".");
                        }
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
        }
    }
}


Measured memory_bytes: 8268
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var T = Console.ReadLine();
            var count = 0;

            for (int i = 0; i < S.Length; i++)
            {
                if (T[i] == S[i])
                    continue;
                count++;
            }

            Console.Write(count);

        }
    }
}


Measured memory_bytes: 18208
import sys

n, m = map(int, raw_input().split())
cnt = [0 for _ in range(n)]
cntS = [[0 for _ in range(n)] for _ in range(m)]

for i in range(n):
  k = input()-1
  cnt[k] += 1
  cntS[k][i] = 1

for k in range(m):
  for i in range(n-1):
    cntS[k][i+1] += cntS[k][i]

dp = [sys.maxint/4 for _ in range(1<<m)]
dp[0] = 0

idx = [0 for _ in range(1<<m)]
for S in range((1<<m)-1):
  for i in range(m):
    if S>>i&1:
      idx[S] += cnt[i]

for S in range((1<<m)-1):
  for k in range(m):
    if not (S>>k&1):
      if idx[S]+cnt[k] <= n:
        dp[S|1<<k] = min(dp[S|1<<k], dp[S] + cnt[k]-(cntS[k][idx[S]+cnt[k]-1]-(cntS[k][idx[S]-1] if idx[S]-1>=0 else 0)))
     
print dp[(1<<m)-1]

Measured memory_bytes: 168368
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define all(cont) cont.begin(), cont.end()
#define unique(a)  sort(all(a)) , (a).erase(unique((a).begin(), (a).end()),(a).end())
#define rall(cont) cont.rbegin(), cont.rend()
#define sz(x) (int)(x).size()
#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PB push_back
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
const int N = 2e5 + 5;
#define PI acos(-1.0)
typedef long long ll;
#define int long long
typedef long double ld;
typedef vector<int> VI;
#define pqll_max priority_queue<ll> // max heap. push(),pop(),top(),size(),empty()
#define pqll_min priority_queue<ll,vector<ll>,greater<ll> >
#define lb(v,val)   lower_bound(v.begin(),v.end(),val) //first equal to or lower than [------------
#define ub(v,val)   upper_bound(v.begin(),v.end(),val) //first greater than ------------)
#define bs(v,x) binary_search(v.begin(),v.end(),x)
inline ll add(ll x, ll y) { x += y; if (x >= mod) x -= mod; return x; }
inline ll sub(ll a, ll b) { if (a < b)swap(a, b); return (((a%mod) - (b%mod) + mod) % mod); }
inline ll mul(ll x, ll y) { return (x%mod * 1ll * y%mod) % mod; }
inline ll pwr(ll a, ll b) { ll x = 1 % mod; while (b) { if (b & 1) x = mul(x, a); a = mul(a, a); b >>= 1; }return x % mod; }
inline ll inv(ll a) { return pwr(a, mod - 2) % mod; }
ll gcd(ll a, ll b) { if (!a)return b % mod; return gcd(b%a, a) % mod; }
#define debug(x) cout << #x << " = " << x << endl;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout << name << " : " << arg1 << endl;
}
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...);
}
#define in(container) for (auto &it : container) cin>>it;
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
ld  maxvolume(ld s)
{
	// finding length 
	ld length = s / (ld)3;

	s -= length;

	// finding breadth 
	ld breadth = s / (ld)2;

	// finding height 
	ld height = s - breadth;

	return length * breadth * height;
}

signed main()
{
	fastio;
	 ld n;
	cin >> n;
	ld l = n / (ld)3;
	ld b = n / (ld)3;
	ld h = n / (ld)3;
	int n1 = n;
	if (n1 % 3 == 1) {
		l += 1;
	}
	if (n1 % 3 == 2) {
		b += 1;
	}
	ld ans = (l)*(b)*(h);

	cout << setprecision(10) << fixed << maxvolume(n)<< endl;


}

Measured memory_bytes: 256
use std::io;

fn read_line()-> String {
    let mut s = String::new();
    let _ = io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
	let abx = read_line().split_whitespace().map(|e|e.parse().unwrap())
	.collect::<Vec<i32>>();

	let a = abx[2]-abx[0];
	let b = a+abx[0];
	if abx[0] > abx[2] {
		println!("NO");
	}else if abx[1] >= a && abx[2] == b {
		println!("YES");
	}else{
		println!("NO");
	}

}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    long long int a[3];

    cin >> a[0] >> a[1] >> a[2];

    if (!(a[0]%2) || !(a[1]%2) || !(a[2]%2)) {
        cout << 0 << endl;
    }
    else {
        sort(a, a+3);

        cout << a[0]*a[1] << endl;
    }
}

Measured memory_bytes: 256
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.insert(0, 0)
b.insert(0, 0)
ans = 0
num_a = n
num_b = 0
flg = True

total_time = sum(a)
if total_time <= k:
    ans = n

for i in range(n+1):
    for j in range(num_b, m):
        if total_time + b[num_b+1] > k:
            break
        else:
            total_time += b[num_b+1]
            num_b += 1
        if num_a + num_b > ans:
            ans = num_a + num_b
    total_time -= a[num_a]
    num_a -= 1

print(ans)

Measured memory_bytes: 40656
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;

const int mod = 1e9 + 7;
long long N, M;

long long fact(long long k){
  if(k == 0)
    return 1;
  return ((k%mod)*(fact(k-1)%mod))%mod;
}
int main(){
  ios_base::sync_with_stdio(false); 
  cin >> N >> M;
  if(abs(N-M) > 1){
    cout << 0 << "\n";
  }
  else if(abs(N-M) == 1){
    cout << ((fact(N)%mod)*(fact(M)%mod))%mod << "\n";
  } 
  else{
    cout << 2*((fact(N)%mod)*(fact(M)%mod))%mod << "\n";
  }
  return 0;
}



Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<set>

#define ll long long

using namespace std;

int main(){
    int A,P;
    cin >> A >> P;
    cout << (A*3+P)/2 << endl;
    return 0;
}


Measured memory_bytes: 256
row1 = input().split(' ')
row2 = input().split(' ')
row3 = input().split(' ')

index = []
index.append(row1)
index.append(row2)
index.append(row3)

a = [] 
b = []

Ans = 'Yes'
for j in range(2):
    for i in range(3):
        a.append(int(index[i][j]) - int(index[i][j+1]))
    if max(a) != min(a):   
        Ans = 'No'
    a = []

for i in range(2):
    for j in range(3):
        b.append(int(index[i][j]) - int(index[i+1][j]))
    if max(b) != min(b):   
        Ans = 'No'
    b = []
    
print(Ans)


Measured memory_bytes: 3064
def main():
    import sys
    readline = sys.stdin.readline
    # readlines = sys.stdin.readlines
    from collections import deque
    from bisect import bisect_left

    N, M = map(int, input().split())
    tate = []
    yoko = []
    X = set()
    Y = set()
    for _ in range(N):
        A, B, C = map(int, readline().split())
        X.add(A)
        X.add(B)
        Y.add(C)
        tate.append((C, A, B))
    for _ in range(M):
        D, E, F = map(int, readline().split())
        X.add(D)
        Y.add(E)
        Y.add(F)
        yoko.append((D, E, F))

    X = sorted(list(X))
    Y = sorted(list(Y))
    H = len(X)
    W = len(Y)

    ix = {}
    for i, x in enumerate(X):
        ix[x] = i
    jy = {}
    for j, y in enumerate(Y):
        jy[y] = j

    wall = [[15] * W for _ in range(H)]

    for c, a, b in tate:
        ia = ix[a]
        ib = ix[b]
        jc = jy[c]
        for i in range(ia, ib):
            wall[i][jc - 1] &= 15 - (1 << 1)
            wall[i][jc] &= 15 - (1 << 3)
    for d, e, f in yoko:
        i_d = ix[d]
        je = jy[e]
        jf = jy[f]
        for j in range(je, jf):
            wall[i_d - 1][j] &= 15 - (1 << 2)
            wall[i_d][j] &= 15 - (1 << 0)

    q = deque()
    x0 = bisect_left(X, 0) - (0 not in ix)
    y0 = bisect_left(Y, 0) - (0 not in jy)
    if x0 == H - 1 or y0 == W - 1:
        print('INF')
        exit()

    path = [True] * (W * H)
    path[x0 * W + y0] = False
    q.append((x0, y0))
    direction = ((-1, 0), (0, 1), (1, 0), (0, -1))
    cnt = 0
    while q:
        x, y = q.popleft()
        cnt += (X[x + 1] - X[x]) * (Y[y + 1] - Y[y])
        for i, (dx, dy) in enumerate(direction):
            if wall[x][y] & (1 << i):
                nx = x + dx
                ny = y + dy
                if 0 <= nx < H - 1 and 0 <= ny < W - 1:
                    if path[nx * W + ny]:
                        path[nx * W + ny] = False
                        q.append((nx, ny))
                else:
                    print('INF')
                    exit()
    print(cnt)


if __name__ == "__main__":
    main()


Measured memory_bytes: 352720
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;
 
int GCD(int a, int b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
 
    int main(){
      string a[3];
      rep(i,3) cin >> a[i];
      cout << a[0][0] << a[1][0] << a[2][0] << endl;
      return 0;}

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

#define sqr(x) ((x)*(x))
typedef long long ll;
const ll INFINT = numeric_limits<int>::max();

int main(){
    ll n,ans = INFINT, ans2 = 0;
    cin >> n;
    vector<ll> values(n);

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

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

    for(int i = -100 ; i <= 100 ; i++){
        ans2 = 0;

        for(int j = 0; j < n ; j++){
            ans2 += sqr(i  - values[j]);
        }

        ans = min(ans, ans2);
    }

    cout << ans;

    return 0;
}

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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL0(x) memset(x,0,sizeof(x))

using namespace std;

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

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; }
 
int used[200010];

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

    int go =0;
    int loop=0;
    int N;
    ll K;
    cin >> N >> K;
    vector<int>A(N);
    rep(i, N)
    {
        int a;
        cin >> a;
        a--;
        A[i]=a;
    }

    int cnt = 0;
    int cp=0;
    bool flag=false;
    for(;cnt<K;cp=A[cp], cnt++)
    {
        if(used[cp]!=0)
        {
            go=cnt;//-1?

            loop=cnt-used[cp];
            flag=true;
            break;
        }
        used[cp]=cnt;
    }

    if(!flag)
    {
        cout << cp+1 << endl;
    }
    else
    {
        K-=go;
        K%=loop;

        for(int cnto=0; cnto<K; cnto++, cp=A[cp])
        {
            
        }

        cout << cp+1 << endl;





    }
    

 

 

    return 0;
}



Measured memory_bytes: 4864
def main():
    N, W = map(int, input().split())
    wv = [list(map(int, input().split())) for _ in range(N)]
    dp = [[0] * (W+10) for _ in range(N+1)]
    for i in range(N):
        for w in range(W+1):

            # i番目の商品を選ぶ場合
            if w - wv[i][0] >= 0:
                dp[i+1][w] = max(dp[i+1][w], dp[i][w-wv[i][0]] + wv[i][1])

            # i番目の商品を選ばない場合
            dp[i+1][w] = max(dp[i+1][w], dp[i][w])
    print(dp[N][W])


if __name__ == '__main__':
    main()


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

int main(){
  int n;
  bool flag=false;
  cin>>n;
  char color[n];
  for(int i=0;i<n;i++){
    cin>>color[i];
    if(color[i]=='Y'){
      flag=true;
    }
  }
  if(flag){
    cout<<"Four"<<endl;
  }else{
    cout<<"Three"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
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():
    A, B = map(int, readline().split())

    ans = 0
    for n in range(A, B + 1):
        n = str(n)
        if n == n[::-1]:
            ans += 1

    print(ans)
    return


if __name__ == '__main__':
    main()


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

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

  int x, y, z;
  int total = 0;
  for(int x = 0; x <= N; x++){
    for(int y = 0; y <= N - x; y++){
      z = N - x - y;
      total = 10000 * x + 5000 * y + 1000 * z;
      if(total == Y){
        cout << x << " " << y << " " << z << endl;
        return 0;
      }
    }
  }

  cout << -1 << " " << -1 << " " << -1 << endl;

  return 0;
}

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

int main()
{

	int m, f, r;

	while( cin >> m >> f >> r ) {

		if( m == -1 && f == -1 && r == -1 ) break;

		if( m == -1 || f == -1 ) cout << "F";
		else if( m + f >= 80 ) cout << "A";
		else if( m + f <  80 && m + f >= 65 ) cout << "B";
		else if( m + f <  65 && m + f >= 50 ) cout << "C";
		else if( m + f <  50 && m + f >= 30 ) {
			if( r >= 50 ) cout << "C";
			else cout << "D";
		}
		else cout << "F";

		cout << endl;

	}

	return 0;

}

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

int main(){
int R, G, B, N;
int sum = 0, ans = 0, i=0;
cin >> R >> G >> B >> N;
while(true){
    sum = R * i;
    if (sum > N) break;
    for (int j=0; sum<=N; j++){
        if((N-sum)%B==0) ans++;
        sum += G;
    }
    i++;
}

cout << ans << endl;

}


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

int main(){
    char S[10],T[10];
    int A,B;
    char U[10];
    cin >>S>>T;
    cin >> A>>B;
    cin >> U;
    if(strcmp(S,U)==0){
        cout << A-1 << " "<<B;
    }else{
        cout << A<< " "<<B-1;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using ll=long long;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF=1LL<<60;

ll n;

int main(){
    cin>>n;
    n--;
    ll ans=(n*n+n)/2;
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define ll long long
using namespace std;
signed main(){
  ll n,m,h[1000000],a[1000000],b[1000000];
  ll f[1000000]={},ans=0;
  cin>>n>>m;
  for(ll i=1;i<=n;i++){
    cin>>h[i];
  }
  for(ll i=1;i<=m;i++){
    cin>>a[i]>>b[i];
  }
  for(ll i=1;i<=m;i++){
    if(h[a[i]]>h[b[i]]){
      f[b[i]] = 1;
    }else if(h[a[i]]<h[b[i]]){
      f[a[i]] = 1;
    }else{
      f[a[i]] = 1;
      f[b[i]] = 1;
    }
  }
  for(ll i=1;i<=n;i++){  
    if(f[i]==1){
      ans++;
    }
  }
  cout<<n-ans<<"\n";
  return 0;
}

Measured memory_bytes: 13800
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    long long int num, n;
    cin >> num >> n;
    
    vector<long long int> vec(n);
    for(int i=0; i<n; ++i) cin >> vec.at(i);
    
    sort(vec.begin(), vec.end());
    
    int sum = 0;
    for(int i=0; i<n; ++i) sum+=vec.at(i);
    
    if(sum >= num) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<fstream>
#define rep(i,start,n) for(int i=start;i<n;i++)             //??????????????????

using namespace std;

int main(){

while(1){

  int a=0,b=0;
  string number;         // number??¨???????????????????????°?????????
  cin >> number;


  if(number == "0") break;           //???????????¶

rep(i , 0 ,number.length()){              //?????????
  a += number[i]-'0';                      //???????????????????????°???????¶???????
}

cout << a << endl;                   //??¨???

}

return 0;

}

Measured memory_bytes: 1192
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
	int N; cin >> N;
    queue<int> A[N];
    rep(i,N)rep(j,N-1){
        int B; cin >> B;
        A[i].push(B);
    }
    int ans = 0;
    int used[N];
    memset(used,0,sizeof(used));
    while(true){
        bool ok = false;
        rep(j,N){
            if(A[j].front()-1 >= 0 && A[A[j].front()-1].front() == j+1 && used[j] == 0 && used[A[j].front()-1] == 0){
                used[j] = 1;
                used[A[j].front()-1] = 1;
                A[A[j].front()-1].pop();
                A[j].pop();
                ok = true;
            }
        }
        if(!ok) break;
        rep(i,N) used[i] = 0;
        ans++;
    }
    rep(i,N){
        if(A[i].size() != 0){
            cout << -1 << '\n';
            return 0;
        }
    }
    cout << ans << '\n';
}
   


Measured memory_bytes: 6784
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


# show_flg = False
show_flg = True


def main():
    N, M = MI()
    ab = [None] * M

    for i in range(M):
        a, b = MI()
        ab[i] = [a, b]

    ab = sorted(ab, key=lambda v: v[1])
    bridges = [ab[0]]
    # print(ab)

    for i in range(1, M):
        if bridges[-1][1] <= ab[i][0]:
            bridges.append(ab[i])

    print(len(bridges))


if __name__ == '__main__':
    main()


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<long long, long long> ll_ll;
typedef pair<double, double> d_d;
typedef vector<int> Vint;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define rep2d(i, j, n) for(i = 0;i < n;++i)for(j = i + 1;j < n;++j)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << x << "\n"
#define pri2(x, y) cout << x << " " << y << "\n"
#define pri3(x, y, z) cout << x << " " << y << " " << z << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << x << "\n"
#define debug2(x, y) cout << " --- " << x << " " << y << "\n"
#define debug3(x, y, z) cout << " --- " << x << " " << y << " " << z << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

struct edge{
  int to, cap, inv;
};

vector<edge> G[202];
bool vsted[202];
int inf = 123456789; //???????°´??????

int dfs(int v, int e, int now, int t, int w){
  if(now == t)return w;
  vsted[now] = true;
  for(int i = 0;i < G[now].size();++i){
    edge tmp = G[now][i];
    if(!vsted[tmp.to] && tmp.cap > 0){
      int d = dfs(v, e, tmp.to, t, min(w, tmp.cap));
      if(d > 0){
        G[now][i].cap -= d;
        G[tmp.to][tmp.inv].cap += d;
        return d;
      }
    }
  }
  return 0;
}

ll edmondskarp(int v, int e, int s, int t){
  ll res = 0;
  for(;;){
    for(int i = 0;i < v;++i)vsted[i] = false;
    int x = dfs(v, e, s, t, inf);
    if(x == 0)return res;
    res += x;
  }
  return res;
}

signed main(void){
  int i, j, k;

  int3(x, y, e);
  int v = x + y + 2;
  rep(i, e){
    int2(l, r); /*--l; --r;*/ r += x;
    G[l].pb((edge){r, 1, G[r].size()});
    G[r].pb((edge){l, 0, G[l].size() - 1});
  }

  rep(i, x){
    int r = i, l = x + y;
    G[l].pb((edge){r, 1, G[r].size()});
    G[r].pb((edge){l, 0, G[l].size() - 1});
  }
  rep(i, y){
    int l = i + x, r = x + y + 1;
    G[l].pb((edge){r, 1, G[r].size()});
    G[r].pb((edge){l, 0, G[l].size() - 1});
  }

  cout << edmondskarp(v, e, x + y, v - 1) << endl;

  return 0;
}

Measured memory_bytes: 1556
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();
		int count = 0;
		if(a != b) {
			count = 2*(Math.max(a, b))-1;
		}else {
			count = a + b;
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 21712
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
#define INF 1e9
typedef pair<int, int> P;



/* 　"assert"    assert(A：条件式)で　Aが真なら処理は続行、偽ならプログラムを終了する　*/

/*　　ラムダ式　　 auto a = [キャプチャ](パラメータ){ 処理 }  */

/* string型　メンバ関数　substr()    replace()  */

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

    map<int, int> m;
    rep(i,n) {
        int a; cin >> a;
        if(m[a] > 0){
            cout << "NO" << endl;
            return 0;
        }
        m[a]++;
    }
    cout << "YES" << endl;
    
    
}


Measured memory_bytes: 9600
n = int(input())
ans = n
for i in range(n // 2):
  j = i + 1
  k = n - j
  sumj = []
  sumk = []
  for l in range(len(str(j))):
    strj = str(j)
    sumj.append(int(strj[l]))
    
  for l in range(len(str(k))):
    strk = str(k)
    sumk.append(int(strk[l]))
  if sum(sumj) + sum(sumk) < ans:
    ans = sum(sumj) + sum(sumk)
print(ans)

Measured memory_bytes: 9100
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N;
    string S;
    cin >> N;
    cin >> S;
    int Ans=0;
    int now=0;
    REP(i,N){
        if(S[i]=='I'){
            now++;
        }else{
            now--;
        }
        Ans=max(Ans,now);
    }
    cout << Ans << endl;
    return 0;
}



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

#define MOD 1000000007
int smallPrimeFactor[1000008];

void seive(){
    for( int i = 1; i <= 1000000; i++ ){
        smallPrimeFactor[i] = i;
    }
    for( int i = 2; i < 1000001; i++ ){
        if( smallPrimeFactor[i] == i ){
            for( int j = i*2; j < 1000001; j += i ){
                smallPrimeFactor[j] = min( smallPrimeFactor[j], i );
            }
        }
    }
}

ll bigMode( ll a, ll b ){
    ll ans = 1;
    while( b ){
        if( b%2 == 1 ){
            ans = (ans*a)%MOD;
        }
        a = (a*a)%MOD;
        b /= 2;
    }
    return ans%MOD;
}

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

        vector<ll>v(n);
        map<int,int>lcm;

        for( int i = 0; i < n; i++ ){
            cin >> v[i];
            int tempN = v[i];
            while( smallPrimeFactor[tempN] != tempN ){
                int pf = smallPrimeFactor[tempN];
                int cnt = 0;
                while( tempN%pf == 0 ){
                    cnt++;
                    tempN /= pf;
                }
                lcm[pf] = max( lcm[pf], cnt );
            }
            if( tempN > 1 ){
                lcm[tempN] = max( lcm[tempN], 1 );
            }
        }
        ll lc = 1;
        for( auto it : lcm ){
            int a = it.first;
            int b = it.second;
            for( int j = 0; j < b; j++ ){
                lc = lc*a;
                lc = lc%MOD;
            }
        }
        ///cout << "lcm " << lc << endl;
        ll ans = 0;
        for( int i = 0; i < n; i++ ){
            int b = v[i];
            ll ib = bigMode( b, MOD-2 );
            ///cout << b << " " << ib << endl;
            ans = (ans+(lc*ib)%MOD)%MOD;
        }
        cout << ans%MOD << endl;
    }
}


Measured memory_bytes: 4736
#include <iostream>
#include <unordered_map>
#include <algorithm>

#define ll long long

using namespace std;
int x, k, q, t, a, low, up, add, delta, now, ans, r[100007];
bool flag;

int cal(int tt, int lower = 0, int upper = x) {
    if (tt < lower) return lower;
    if (tt > upper) return upper;
    return tt;
}

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

    cin >> x >> k;
    for (int i = 1; i <= k; i++) cin >> r[i];
    cin >> q;

    low = x, now = 1;
    while (q--) {
        cin >> t >> a;
        while (t >= r[now] && now <= k) {
            delta = (flag ? 1 : -1) * (r[now] - r[now - 1]), add += delta;
            up = cal(delta + up), low = cal(delta + low);
            flag = !flag, now++;
        }
        ans = cal((flag ? 1 : -1) * (t - r[now - 1]) + cal(a + add, up, low));
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 1664
N = int(input())
A = [0] + [int(i) for i in input().split()] + [0]
R = A[::-1]
s = [0]
t = [0]
for i in range(N):
  s.append(s[i] + abs(A[i] - A[i + 1]))
  t.append(t[i] + abs(R[i] - R[i + 1]))
for i in range(N):
  print(s[i] + t[N - 1 - i] + abs(A[i] - A[i + 2]))

Measured memory_bytes: 18216
import java.util.*;

public class Main {
	static long memo[] = new long[90];

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		System.out.println(lucas(N));
	}

	private static long lucas(int i) {
		if (i == 0) return 2;
		else if (i == 1) return 1;
		else return memo[i] = (memo[i] != 0 ? memo[i] : lucas(i-1) + lucas(i-2));
	}
}

Measured memory_bytes: 21844
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = sum(b)
for i in range(n-1):
  if a[i] + 1 == a[i+1]:
    ans += c[a[i]-1]
print(ans)

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int vx[] = {
  -2, -2, -2,
  -1, -1, -1, -1,
  +0, +0, +0, +0, +0,
  +1, +1, +1, +1,
  +2, +2, +2
};
int vy[] = {
  +0, +1, +2,
  -1, +0, +1, +2,
  -2, -1, +0, +1, +2,
  -2, -1, +0, +1,
  -2, -1, +0
};

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

string c;
int image[5][5];
int image2[5][5];

void makeImage(int bit) {
  rep(i, 19) image[2+vy[i]][2+vx[i]] = ((bit>>i)&1);
}
void filtering(int y, int x) {
  int nb = 0;
  rep(i, 7) nb |= (image[2+y+dy[i]][2+x+dx[i]]<<i);
  image2[2+y][2+x] = c[nb];
}
void swaping() {
  rep(i, 5) rep(j, 5) swap(image[i][j], image2[i][j]);
}

bool solve() {
  rep(i, 1<<19) {
    makeImage(i);
    rep(j, 7) filtering(dy[j], dx[j]);
    swaping();
    filtering(0, 0);
    if(image[2][2] != image2[2][2]) return false;
  }
  return true;
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while(cin >> c, c != "#") {
    rep(i, 128) c[i] -= '0';
    cout << (solve() ? "yes" : "no") << endl;
  }

  return 0;
}

Measured memory_bytes: 3216
#include <iostream>
using namespace std;
const int maxn=(1<<18);
int n, ans=0;

struct T
{
    int x, y;
};
T a[maxn];

void Update(int i,int v)
{
    if(v>a[i].y)a[i].y=v;
    if(a[i].y>a[i].x)swap(a[i].x,a[i].y);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n;
    n=1<<n;
    for(int i=0;i<n;i++)
        cin>>a[i].x;
    for(int j=0;(1<<j)<n;j++)
        for(int i=0;i<n;i++)
            if(i>>j&1)
            {
                Update(i,a[i^(1<<j)].x);
                Update(i,a[i^(1<<j)].y);
            }
    for(int i=1;i<n;i++)
    {
        ans=max(ans,a[i].x+a[i].y);
        cout<<ans<<'\n';
    }
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>

void view(const std::vector<T> &v)
{
#ifndef ONLINE_JUDGE
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
#endif
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    vint a(n);
    int no = 0, ne = 0;
    rep(i, n)
    {
        if (s[i] == 'R')
        {
            no += i % 2;
            ne += (i + 1) % 2;
        }
        else
        {
            if (i % 2)
            {
                a[i] += no;
                a[i - 1] += ne;
            }
            else
            {
                a[i] += ne;
                a[i - 1] += no;
            }
            no = 0;
            ne = 0;
        }
    }
    reverse(s.begin(), s.end());
    reverse(a.begin(), a.end());
    rep(i, n)
    {
        if (s[i] == 'L')
        {
            no += i % 2;
            ne += (i + 1) % 2;
        }
        else
        {
            if (i % 2)
            {
                a[i] += no;
                a[i - 1] += ne;
            }
            else
            {
                a[i] += ne;
                a[i - 1] += no;
            }
            no = 0;
            ne = 0;
        }
    }
    reverse(a.begin(), a.end());

    rep(i, n) cout << a[i] << " ";
    cout << endl;

    return 0;
}

Measured memory_bytes: 3788
#include<stdio.h>

int main(){
    int i, j, k;
    int N, A, B, C, D;
    char s[210000];
    int numN=0, maxN=0, numR=0, maxR=0;
    int ans, tmp;

    scanf("%d %d %d %d %d", &N, &A, &B, &C, &D);
    scanf("%s", &s);
    if(C>D){
        tmp=D;
    }else{
        tmp=C;
    }
    for(i=B-2; i<tmp+1; i++){
        if(s[i]=='.'){
            if(numR>0){
                numR=0;
            }
            numN++;
            if(numN>maxN){
                maxN=numN;
            }
        }else{
            numR++;
            numN=0;
        }
    }
    numR=0;
    numN=0;
    if(C>D){
        tmp=C;
    }else{
        tmp=D;
    }
    for(i=A; i<tmp; i++){
        if(s[i]=='#'){
            if(numN>0){
                numN=0;
            }
            numR++;
            if(numR>maxR){
                maxR=numR;
            }
        }else{
            numN++;
            numR=0;
        }
    }
    //printf("%d %d", maxN, maxR);

    if(C>D){
        if(maxN>=3 && maxR<=2){
            printf("Yes");
        }else{
            printf("No");
        }
    }else{
        if(maxR<=2){
            printf("Yes");
        }else{
            printf("No");
        }
    }

    return 0;
}

Measured memory_bytes: 384
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

//const long long int MOD = 1000000007;
const long long int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	string s;
	cin >> s;
	vector<int>v;
	vector<int>w;
	for (auto i : s)v.push_back({ i - '0' });
	for (auto i : v)w.push_back(2 - i);
	N = s.size();
	M = accumulate(v.begin(), v.end(),0);
	vector<vector<long long int>>dp(N * 2 + 1, vector<long long int>(M + 1));
	dp[0][0] = 1;
	int box = 0, bag = 0;
	int bbox = 0, bbag = 0;
	for (int i = 1; i <= N * 2; i++) {
		for (int j = 0; j < min(i, (int)v.size()); j++) {
			if (v[j]) {
				v[j]--;
				box++;
				break;
			}
		}
		for (int j = 0; j < min(i, (int)w.size()); j++) {
			if (w[j]) {
				w[j]--;
				bag++;
				break;
			}
		}
		for (int j = i - bag; j <= M; j++) {
			if (i - 1 - bbag <= j && j <= bbox)dp[i][j] += dp[i - 1][j];
			if (i - 1 - bbag <= j - 1 && j - 1 <= bbox)dp[i][j] += dp[i - 1][j - 1];
			dp[i][j] %= MOD;
		}
		bbox = box;
		bbag = bag;
	}
	cout << dp.back().back() << endl;
}

Measured memory_bytes: 125440
import math

def countPoints():
    s = input()
    N,D = s.split(' ')
    N = int(N)
    D = int(D)
    count = 0
    for i in range(0, N):
        s = input()
        x,y = s.split(' ')
        x = int(x)
        y = int(y)
        if math.sqrt((x*x)+(y*y)) <= (D):
            count+=1
    return(count)

if __name__ == '__main__':
    print(countPoints())

Measured memory_bytes: 9212
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	ll n, k;
	scanf("%ld %ld", &n, &k);
	k = std::min(k, 41l);
	std::vector<V> a(k+1, V(n+1, 0));
	REP(i, 0, n) scanf("%ld", &a[0][i]);
	for(int i=n; i>0; i--) a[0][i] -= a[0][i-1];
	
	REP(i, 0, k){
		REP(j, 0, n){
			a[i+1][std::max(0l, j-a[i][j])]++;
			a[i+1][std::min(n, j+a[i][j]+1)]--;
			a[i][j+1] += a[i][j];
		}
	}
	REP(i, 0, n){
		printf("%ld ", a[k][i]);
		a[k][i+1] += a[k][i];
	}
	puts("");
	return 0;
}



Measured memory_bytes: 70584
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

int main(void)
{
	bool judge1 = false, judge2 = false;
	int s, ver[4] = { 0,0,0,0 };
	cin >> s;
	for (int i = 0; i < 4; i++) { ver[i] = s % 10; s *= 0.1; }
	if (ver[1] == 0 && 0 < ver[0]) { judge1 = true; }
	if (ver[1] == 1 && 0 <= ver[0] && ver[0] <= 2) { judge1 = true; }
	if (ver[3] == 0 && 0 < ver[2]) { judge2 = true; }
	if (ver[3] == 1 && 0 <= ver[2] && ver[2] <= 2) { judge2 = true; }

	if (judge1) { if (judge2) { cout << "AMBIGUOUS" << endl; } else { cout << "YYMM" << endl; } }
	else { if (judge2) { cout << "MMYY" << endl; } else { cout << "NA" << endl; } }
	return 0;
}


Measured memory_bytes: 256
S = input()

idx_end = len(S)
while True:
    if idx_end >= 5 and S[idx_end-5:idx_end] == "dream":
        idx_end -= 5
    elif idx_end >= 7 and S[idx_end-7:idx_end] == "dreamer":
        idx_end -= 7
    elif idx_end >= 5 and S[idx_end-5:idx_end] == "erase":
        idx_end -= 5
    elif idx_end >= 6 and S[idx_end-6:idx_end] == "eraser":
        idx_end -= 6
    else:
        break

    if idx_end == 0:
        break

if idx_end == 0:
    print("YES")
else:
    print("NO")


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

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n-1; i >= 0; i--)
#define FOR(i, n, m) for(int i = n; i < (int)(m); i++)
#define PRINT(x) cout << x << endl
#define ALL(v) v.begin(), v.end()
#define INF (ll)1e18
#define PI 3.14159265358979

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll MOD = 1000000007;

int main()
{
    ll N, K;
    cin >> N >> K;
    vector<ll> V(N);
    REP(i, N) cin >> V[i];
    ll ma = 0;
    REP(i, min(N, K)+1) {
        REP(j, min(N, K)+1) {
            if (i+j > min(N, K)) continue;
            vector<ll> tmp;
            REP(k, i) tmp.push_back(V[k]);
            REP(k, j) tmp.push_back(V[N-1-k]);
            sort(ALL(tmp));
            ll sum = 0;
            ll cnt = 0;
            REP(k, tmp.size()) {
                if (tmp[k] < 0 && cnt < K - (i+j)) {
                    cnt++;
                } else {
                    sum += tmp[k];
                }
            }
            ma = max(ma, sum);
        }
    }
    PRINT(ma);
    return 0;
}


Measured memory_bytes: 256
s = gets.chomp

if s.size == 2
  if s[0] == s[1]
    puts '1 2'
  else
    puts '-1 -1'
  end
  exit
end

(s.size-2).times do |i|
  if s[i] == s[i+1] || s[i] == s[i+2] || s[i+1] == s[i+2]
    puts [i+1, i+3].join(' ')
    exit
  end
end

puts '-1 -1'


Measured memory_bytes: 2044
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		int max = a;
		if(max < b)
			max = b;
		if(max < c)
			max = c;
		
		System.out.println(a + b + c + 9*max);
	}

}

Measured memory_bytes: 23124
abc = input().split()
a = abc[0]
b = abc[1]
c = abc[2]

d = eval((a + b) + '+' + c)
e = eval((b + a) + '+' + c)
f = eval((a + c) + '+' + b)
g = eval((c + a) + '+' + b)
h = eval((b + c) + '+' + a)
i = eval((c + b) + '+' + a)

h = [d, e, f, g, h, i]

print(max(h))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define F first 
#define S second
#define int long long int
signed main() 
{ 
    fast;
    int n;
    cin>>n;
    int a[n+1];
    for(int i=1;i<=n;i++)
        cin>>a[i];
    int ans = 0;
    int af[n+1];
    for(int i=1;i<=n;i++)
        af[i] = i;
    int i = 1;
    int j = 1;
    while(i<=n)
    {
        if(a[i] == af[j])
        {
            i++;
            j++;
        }
        else i++;
    }
    j--;
    if(j==0)
        cout<<-1;
    else cout<<n-j;
} 

Measured memory_bytes: 3968
#include<iostream>
using namespace std;
#define ll long long
ll pow_ans (ll x,ll n){
    ll res =1;
    while(n>0){
        if(n&1){
            res *=x;
            res = res % 1000000007;
        }
        x *= (x%1000000007);
        x %= 1000000007;
        n >>=1;
    }
    return res;
}
int main(){
    ll x,n;
    cin >> x >> n;
    cout << pow_ans(x,n) << endl;
}


Measured memory_bytes: 3096
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner stdIn=new Scanner(System.in);
    int N=stdIn.nextInt();
    int[] n=new int[3];
    for(int i=0;i<3;i++){
      n[i]=N%10;
      N/=10;
    }
    if(n[0]==n[2]){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 21716
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        Map<Long, Long> map = primeFactorization(n);
        System.out.print(n + ":");
        map.entrySet().stream().sorted(Map.Entry.comparingByKey()).forEach(e -> {
            for (int i = 0; i < e.getValue(); i++) {
                System.out.print(" " + e.getKey());
            }
        });
        System.out.println();
    }

    Map<Long, Long> primeFactorization(long n) {
        Map<Long, Long> map = new HashMap<>();
        for (long i = 2; i * i <= n; i++) {
            if (n % i != 0) continue;
            long count = 0;
            while (n % i == 0) {
                count++;
                n = n / i;
            }
            map.put(i, count);
        }
        if (n != 1) map.put(n, 1L);
        return map;
    }


    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }

}



Measured memory_bytes: 32480
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define debug(x) cout << #x << " = " << x << endl
#define print(x) cout << x << endl;
const ll MOD = 1000000007;

int main()
{
    int N;
    cin >> N;
    set<string> got;

    rep(i, N)
    {
        string temp;
        cin >> temp;
        got.insert(temp);
    }

    cout << got.size() << endl;
}


Measured memory_bytes: 19124
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>
#include<unordered_map>
#include<deque>
#include<cmath>





using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const ll INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
//const ll mod = 1000 * 1000 * 1000 + 7;




void solve() {
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    int r = 0;
    ll res = 0;
    for (int i = 0; i < n; ++i) {
        int y = r + a[i];
        int z = max(0, y - x);
        a[i] -= z;
        res += z;
        r = a[i];
    }
    cout << res << endl;

}


//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    solve();



#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}


Measured memory_bytes: 640
/*
 * c.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 1000;

typedef long long ll;

const ll BS0 = 2549;
const ll BS1 = 4283;
const ll MOD = 1000000007;

/* typedef */

/* global variables */

string s[MAX_N], p[MAX_N];
ll es0[MAX_N + 1], es1[MAX_N + 1];
ll shs[MAX_N + 1][MAX_N + 1], phs[MAX_N + 1][MAX_N + 1];

/* subroutines */

void makehash(int h, int w, ll hs[MAX_N + 1][MAX_N + 1], string s[]) {
  for (int y = 0; y < h; y++)
    for (int x = 0; x < w; x++)
      hs[y + 1][x + 1] =
	(es0[y] * es1[x] % MOD * s[y][x] % MOD +
	 hs[y][x + 1] + hs[y + 1][x] - hs[y][x] + MOD) % MOD;
}

/* main */

int main() {
  es0[0] = es1[0] = 1;
  for (int i = 1; i <= MAX_N; i++) {
    es0[i] = (es0[i - 1] * BS0) % MOD;
    es1[i] = (es1[i - 1] * BS1) % MOD;
  }

  int h, w;
  cin >> h >> w;
  for (int y = 0; y < h; y++) cin >> s[y];

  int r, c;
  cin >> r >> c;
  for (int y = 0; y < r; y++) cin >> p[y];

  makehash(h, w, shs, s);
  makehash(r, c, phs, p);

  for (int y = 0; y <= h - r; y++)
    for (int x = 0; x <= w - c; x++) {
      ll sh =
	(shs[y + r][x + c] + shs[y][x]
	 - shs[y][x + c] + MOD - shs[y + r][x] + MOD) % MOD;
      ll ph = phs[r][c] * es0[y] % MOD * es1[x] % MOD;
      if (sh == ph) printf("%d %d\n", y, x);
    }
  return 0;
}

Measured memory_bytes: 18968