akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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 h[2010][2010];
int v[2010][2010];
int hh[4000010];
int vv[4000010];

void _main()
{
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    rep(i, 0, H) cin >> S[i];

    // h scan
    int idx = 0;
    int num = 0;
    rep(r, 0, H)
    {
        rep(c, 0, W)
        {
            if (S[r][c] == '#')
            {
                h[r][c] = -1;
                if (num > 0)
                {
                    hh[idx] = num;

                    ++idx;
                    num = 0;
                }
            }
            else
            {
                h[r][c] = idx;
                ++num;
            }

            if (c == W - 1)
            {
                if (num > 0)
                {
                    hh[idx] = num;

                    ++idx;
                    num = 0;
                }
            }
        }
    }
/*
    rep(r, 0, H)
    {
        rep(c, 0, W)
        {
            printf("%2d", h[r][c]);
        }
        cout << endl;
    }
    cout << endl;*/

    // w scan
    idx = 0;
    num = 0;
    rep(c, 0, W)
    {
        rep(r, 0, H)
        {
            if (S[r][c] == '#')
            {
                v[r][c] = -1;
                if (num > 0)
                {
                    vv[idx] = num;

                    ++idx;
                    num = 0;
                }
            }
            else
            {
                v[r][c] = idx;
                ++num;
            }

            if (r == H - 1)
            {
                if (num > 0)
                {
                    vv[idx] = num;

                    ++idx;
                    num = 0;
                }
            }
        }
    }
/*
    rep(r, 0, H)
    {
        rep(c, 0, W)
        {
            printf("%2d", v[r][c]);
        }
        cout << endl;
    }
    cout << endl;*/

    int ans = 0;
    rep(r, 0, H)
    {
        rep(c, 0, W)
        {
            if (S[r][c] == '#') continue;
            int hhh = hh[h[r][c]];
            int vvv = vv[v[r][c]];
            chmax(ans, hhh + vvv - 1);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 46720
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ss second
#define ff first
#define all(a) a.begin(), a.end()
#define All(a) a.rbegin(), a.rend()
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.precision(10), cout << fixed
int main()
{
     ios;
     int a, b;
     cin >> a >> b;
     cout << (a > 9 || b > 9 ? -1 : a * b) << '\n';
     return 0;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=1000000007;
int N,X,Y,Z;

bool ok(deque<int>&v){
    while(true){
        int cur=0;
        int sum=0;
        while(cur<v.size()&&sum<X)sum+=v[cur++];
        if(sum<X)return true;
        if(sum>X){
            v.pop_front();
            continue;
        }
        sum=0;
        while(cur<v.size()&&sum<Y)sum+=v[cur++];
        if(sum<Y)return true;
        if(sum>Y){
            v.pop_front();
            continue;
        }
        sum=0;
        while(cur<v.size()&&sum<Z)sum+=v[cur++];
        if(sum<Z)return true;
        if(sum>Z){
            v.pop_front();
            continue;
        }
        if(cur==v.size())return false;
        v.pop_front();
    }
}

vector<deque<int>>vec;
deque<int>deq;
void dfs(){
    vec.pb(deq);
    for(int d=1;d<=7;d++){
        deq.push_back(d);
        deque<int>dd=deq;
        if(ok(dd)&&dd==deq){
            dfs();
        }
        deq.pop_back();
    }
}

int to[20000][10];
int dp[50][20000];
signed main(){

    cin>>N>>X>>Y>>Z;
    dfs();
    sort(all(vec));
    rep(i,vec.size()){
        rep(j,10){
            deq=vec[i];
            deq.pb(j+1);
            if(ok(deq)){
                to[i][j]=lower_bound(all(vec),deq)-vec.begin();
            }
            else{
                to[i][j]=-1;
            }
        }
    }

    dp[0][0]=1;
    rep(i,N){
        rep(j,vec.size()){
            rep(k,10){
                if(to[j][k]!=-1)dp[i+1][to[j][k]]=(dp[i+1][to[j][k]]+dp[i][j])%mod;
            }
        }
    }

    int ans=0;
    rep(i,vec.size())ans=(ans+dp[N][i])%mod;
    int hoge=1;
    rep(i,N)hoge=hoge*10%mod;
    cout<<(hoge-ans+mod)%mod<<endl;

    return 0;
}


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

int main(){
  int n,x;
  cin >> n >> x;
  vector<int> L(n);
  rep(i,n){
    cin >> L[i];
  }
  
  int ans = 1;
  int kyo = 0;
  for(int i=0;i<n;i++){
    kyo += L[i];
    if(kyo<=x) ans ++;
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cctype>
#include<vector>
#include <ctype.h>
#include<algorithm>
#include<queue>
#include<string>
#include <math.h>
#include <iomanip>
using namespace std;
long long  n, a, b, c,d,ans=0;
int main() {
	cin >> n >> a >> b>>d;
	for (size_t i = 0; i < n-1; i++)
	{
		cin >> c;
		ans += min((c - d)*a, b);
		d=c;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
//constexpr int MOD=1000000007;
constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    lint N,K;
    cin >> N >> K;
    lint X=K;
    lint P[N],C[N];
    rep(i,N) cin >> P[i];
    rep(i,N) P[i]--;
    rep(i,N) cin >> C[i];
    lint now=0;
    lint ans=-LINF;
    rep(i,N){
        K=X;
        now=i;
        lint reach[N]={};
        lint syuki;
        lint cnt=1;
        lint rfst=INF;
        vector<lint> A;
        while(true){
            now=P[now];
            if(reach[now]){
                syuki=cnt-reach[now];
                break;
            }
            reach[now]=cnt;
            A.push_back(C[now]);
            if(cnt==1) rfst=now;
            cnt++;
        }
        lint cmp=0;
        lint len=A.size();
        lint fst=len-syuki;
        if(K<=fst){
            rep(j,K){
                cmp+=A[j];
                ans=max(ans,cmp);
            }
            continue;
        }
        if(K<10000){
            rep(j,K){
                cmp+=A[j%len];
                ans=max(ans,cmp);
            }
            continue;
        }
        else{
            lint sum[len+1-fst]={};
            lint fcmp=0;
            rep(j,fst){
                fcmp+=A[j];
                ans=max(ans,fcmp);
            }
            K-=fst;
            for(lint j=fst;j<len;j++){
                sum[j-fst+1]=sum[j-fst]+A[j];
                ans=max(ans,sum[j-fst+1]+fcmp);
            }
            if(sum[len-fst]>0){
                lint cmp2=-LINF;
                lint ok=K%syuki;
                rep(j,ok) cmp2=max(cmp2,sum[j+1]+fcmp);
                if(ok==0) cmp2=0;
                ans=max(ans,cmp2+(K/syuki)*sum[len-fst]);
                rep(j,syuki){
                    cmp2=max(cmp2,sum[j+1]+fcmp);
                }
                cmp2+=((K/syuki)-1)*sum[len-fst];
                ans=max(ans,cmp2);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3844
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define ARR_MAX 300000
#define BUF_SIZE (ARR_MAX*11+50)
#define DIVISOR 1000000007

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
#ifdef BUF_SIZE
    char line[BUF_SIZE];
    char *tmpbuf = line;
    int i;
    if(!fgets(line, BUF_SIZE, stdin)) return -1;
    for(i = 0; i < size; i++) {
        char *tmp = strtok(tmpbuf, " ");
        arr[i] = strtol(tmp, NULL, 10);
        tmpbuf = NULL;
    }
#else
#error
#endif
    return 0;
}

#define HEAP_MAX (ARR_MAX+50)
int heap[HEAP_MAX];
int hidx = 1;

int cmp(int a1, int a2) {
    return a1 < a2;
}

void swap(int *a1, int *a2) {
    int tmp = *a1;
    *a1 = *a2;
    *a2 = tmp;
}

void enqueue(int num) {
    int node = hidx;
    heap[hidx++] = num;
    int parent;
    while((parent = node/2)) {
        if(cmp(heap[parent], heap[node])) break;
        swap(&heap[parent], &heap[node]);
        node = parent;
    }
    return;
}

int dequeue_min(void) {
    int node = 1;
    int ans = heap[1];
    heap[1] = heap[--hidx];

    while(1) {
        int smallest = node;
        int left = node * 2;
        int right = node * 2 + 1;
        if(left < hidx && !cmp(heap[smallest], heap[left])) {
            smallest = left;
        }
        if(right < hidx && !cmp(heap[smallest], heap[right])) {
            smallest = right;
        }
        if(smallest == node) break;
        swap(&heap[smallest], &heap[node]);
        node = smallest;
    }
    return ans;
}

void reset_heap(void) {
    hidx = 1;
}

#define ANS_MIN INT64_MIN

void record(int *arr, int64_t *sum, int num) {
    reset_heap();
    sum[0] = arr[0];
    enqueue(arr[0]);
    int i;
    for(i = 1; i < num*2; i++) {
        int diff = arr[i];
        enqueue(arr[i]);
        if(i >= num) {
            int tmp = dequeue_min();
            diff -= tmp;
        }
        sum[i] = sum[i-1] + (int64_t)diff;
    }
    return;
}

int main(void) {
    static int arr[ARR_MAX];
    int num = get_int();
    int size = num*3;
    fget_array(arr, size);
    static int rarr[ARR_MAX];
    int i;

    // for using same priority heap
    for(i = 0; i < size; i++) rarr[i] = -arr[size-1-i];
    static int64_t sum[ARR_MAX];
    static int64_t rsum[ARR_MAX];

    record(arr, sum, num);
    record(rarr, rsum, num);

    int64_t ans = ANS_MIN;
    for(i = num-1; i < 2*num; i++) {
#ifdef DEBUG
        // sum of [0, .. , i](i) + [i+1, ... size](size-1-(i+1))
        printf("%lld %lld\n", sum[i], rsum[size-2-i]);
#endif
        ans = max(ans, sum[i] + rsum[size-2-i]);
    }
    printf("%lld\n", ans);

    return 0;
}

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

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

	vector<int> v;
	int a;
	rep(i, n) {
		cin >> a;
		v.push_back(a);
	}

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

	rep(i, n - 1) {
		if (v[i] == v[i + 1]) {
			cout << "NO" << endl;
			return 0;
		}
	}

	cout << "YES" << endl;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
int n, m;
 
struct Node{
	int lazy, ch[3], va;
}p[3030303];


int cnt = 1;
 
void ins(int x)
{
	int now = 1;
	int _x = x;
	for(int i = 0; i < n; i++)
	{
		p[now].va = -1;
		int q = x%3;
		if(!p[now].ch[q])
			p[now].ch[q] = ++cnt;
		x /= 3;
		now = p[now].ch[q];
	}
	p[now].va = _x;
}
int ans[1010101];

int _3 = 1, sum = 0;

void dfs(int now)
{
	if(p[now].lazy)
	{
		swap(p[now].ch[1], p[now].ch[2]);
		for(int j = 0; j < 3; j++)
			p[p[now].ch[j]].lazy ^= 1;
		p[now].lazy = 0;
	}
	if(p[now].va != -1)
	{
		ans[p[now].va] = sum;
		return;
	}
	for(int j = 0; j < 3; j++)
	{
		sum += _3 * j;
		_3 *= 3;
		dfs(p[now].ch[j]);
		_3 /= 3;
		sum -= _3 * j;
	}
}

char s[202020];
int main()
{
	scanf("%d", &n);
	int N = 1;
	for(int i = 0; i < n; i++)
		N *= 3;
	scanf("%s", s);
	m = strlen(s);
	for(int i = 0; i < N; i++)
		ins(i);
	for(int j = 0; j < m; j++)
	{
		if(s[j] == 'S')
			p[1].lazy ^= 1;
		else
		{
			int now = 1;
			for(int i = 0; i < n; i++)
			{
				if(p[now].lazy)
				{
					swap(p[now].ch[1], p[now].ch[2]);
					for(int j = 0; j < 3; j++)
						p[p[now].ch[j]].lazy ^= 1;
					p[now].lazy = 0;
				}
				int nxt = p[now].ch[2];
				p[now].ch[2] = p[now].ch[1];
				p[now].ch[1] = p[now].ch[0];
				p[now].ch[0] = nxt;
				now = nxt;
			}
		}
	}
	dfs(1);
	for(int i = 0; i < N; i++)
		printf("%d ", ans[i]);
	puts("");
	return 0;
}

Measured memory_bytes: 21964
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main
{
	public static void main(String arg[])
	{
		Scanner scan = new Scanner(System.in);

		String a[] = new String[10000];
		String b[] = new String[10000];
		int i =0;
		while(scan.hasNext())
		{

			String str = scan.next();
			StringTokenizer st = new StringTokenizer(str, ",");

			a[i+1]=st.nextToken();
			b[i+1]=st.nextToken();

			i++;
		}

		int A=0;
		int B=0;
		int AB=0;
		int O=0;
		for(int j=1; j<=i; j++)
		{
			if(b[j].equals("A"))
				A++;
			else if(b[j].equals("B"))
				B++;
			else if(b[j].equals("AB"))
				AB++;
			else if(b[j].equals("O"))
				O++;
		}

		System.out.println(A);
		System.out.println(B);
		System.out.println(AB);
		System.out.println(O);

	}

}

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

int main() {
  int n, h, m;
  cin >> n;

  h = n / 3600;
  n = n % 3600;
  m = n / 60;
  n = n % 60;

  cout << h << ":" << m << ":" << n << endl;

  return 0;
}


Measured memory_bytes: 3084
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

long calc(long n, long a, long b) {
    if (n == 1) {
        return a == b ? 1 : 0;
    }
    if (a > b) {
        return 0;
    }
    return (n - 2) * (b - a) + 1;
}

void main() {
    auto nab = readints;
    int n = nab[0], a = nab[1], b = nab[2];

    writeln(calc(n, a, b));
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cctype>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 2e5+5, M = 4000+5, B = 2001, P = 1e9+7;
int n, a[N], b[N], fac[N], inv[N], ifac[N];
int f[M][M], ans;
int C(int n, int m) { return 1ll*fac[n]*ifac[n-m]%P*ifac[m]%P; }
int main()
{
    n = N-5, inv[1] = fac[0] = ifac[0] = 1;
    for(int i = 2; i <= n; ++i) inv[i] = 1ll*(P-P/i)*inv[P%i]%P;
    for(int i = 1; i <= n; ++i) fac[i] = 1ll*fac[i-1]*i%P, ifac[i] = 1ll*ifac[i-1]*inv[i]%P;
    n = read();
    for(int i = 1; i <= n; ++i) a[i] = read(), b[i] = read(), ++f[B-a[i]][B-b[i]];
    for(int i = 1; i < M; ++i)
        for(int j = 1; j < M; ++j)
            f[i][j] = (f[i][j]+(f[i-1][j]+f[i][j-1])%P)%P;
    for(int i = 1; i <= n; ++i) 
        ans = (ans+f[B+a[i]][B+b[i]])%P, 
        ans = (1ll*ans+P-C(2*(a[i]+b[i]), 2*a[i]))%P;
    ans = 1ll*ans*inv[2]%P;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 66688
def swap(array)
  array[0], array[1] = array[1], array[0]
end
seats = gets.chomp.to_i
queries = []
results = []
puts 0
STDOUT.flush
result = gets.chomp
exit if result == "Vacant"
queries.push(0)
results.push(result)
half =  (seats - 1) / 2
puts half
STDOUT.flush
result = gets.chomp
exit if result == "Vacant"
queries.push(half)
results.push(result)
if (results[0] == results [1] && half % 2 == 0) || (results[0] != results [1] && half % 2 != 0)
  swap(queries)
  swap(results)
  queries[1] = seats
end

18.times do |i|
  next_index = queries[0] + ((queries[1] - queries[0]) / 2)
  puts next_index
  STDOUT.flush
  result = gets.chomp
  break if result == "Vacant"
  if (results[0] == result && (next_index - queries[0]) % 2 == 0) || (results[0] != result && (next_index - queries[0]) % 2 != 0)
    queries[0] = next_index
    results[0] = result
  else
    queries[1] = next_index
    results[1] = result
  end
end

Measured memory_bytes: 2384
#include<stdio.h>
int main()
{
    int a,b,c,f=0;
    // 整数の入力
    // スペース区切りの整数の入力
    scanf("%d %d %d",&a,&b,&c);
    // 出力
  for(int i=1;i<=b;i++){
    if((a*i-c)%b==0){
      printf("YES");
      f=1;
      break;
    }
  }
    if(f==0)printf("NO");
    return 0;
}

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

int main(){
	int n; cin >> n;
	ll ans = 1;
	for(int i = 0; i < n; ++i) ans *= 3;
	ll po = 1;
	for(int i = 0; i < n; ++i){
		int a; cin >> a;
		if(!(a % 2)) po *= 2;
	}
	cout << ans - po << endl;
	return 0;
}

Measured memory_bytes: 256
def generate(n):
    ans = []
    for i in range(2,n+1):
        flag = True
        for j in range(2,i):
            if(i%j == 0):
                flag = False
        if flag:
            ans.append(i)
    return ans

def factorial(n):
    ans = 1
    for i in range(1,n+1):
        ans *= i
    return ans

ans = 1
N = int(input())
l = generate(N)
N = factorial(N)
for p in l:
    q = 1
    while(N%p == 0):
        q += 1
        N = N // p
    ans *= q
print(ans%1000000007)


Measured memory_bytes: 3064
import java.io.*
import java.util.*

val pw = PrintWriter(System.out)
fun solve(N: Int, X: IntArray){
    val x = X.sorted()
    val a = x[N/2 - 1]
    val b = x[N/2]
    repeat(N){
        if(X[it] <= a){
            pw.println(b)
        }else pw.println(a)
    }
    pw.flush()
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val X = IntArray(N)
    for (i in 0 until N) {
        X[i] = sc.next().toInt()
    }
    solve(N, X)
}



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

int main () {
    string N;
    cin >> N;
    char a=N.at(0);
    char b=N.at(1);
    char c=N.at(2);
    
    if (a=='7' || b=='7' || c=='7') {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


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

string t = "bcdefghijklmnopqrstuvwxyza";
string alphabet = "abcdefghijklmnopqrstuvwxyz";

int main(){
	string s;
	cin >> s;
	ll k;
	cin >> k;
	map<char,int> mp;
	map<char,int> alpha;
	rep(i,26){
		mp[t[i]] = 25-i;
		alpha[alphabet[i]] = i;
	}
	
	string ans;
	ll count = k;
	rep(i,s.size()-1){
		if(mp[s[i]] <= count){
			ans.push_back('a');
			count -= mp[s[i]];
		}else{
			ans.push_back(s[i]);
		}
	}
	
	ans.push_back(alphabet[(alpha[s[s.size()-1]]+count)%26]);
	
	cout << ans << endl;
	
    return 0;
}



Measured memory_bytes: 768
import java.util.Scanner;

public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] mat = new int[n][m];
        int[] vec = new int[m];
        int[] res = new int[n];
        
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                mat[i][j] = sc.nextInt();
            }
        }
        
        for (int i = 0; i < m; i++) {
            vec[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                res[i] += mat[i][j] * vec[j];
            }
            System.out.println(res[i]);
        }
        
    }
}

Measured memory_bytes: 40492
from itertools import combinations
import sys

N = int(input()) 
X_Y = [0] * N

for i in range(N):
    X_Y[i] = tuple(map(int, input().split()))


if N == 1:
    print(1)
    sys.exit()

combo = list(combinations(X_Y, 2))
diff = [0] * (len(combo))

dict_diff = {}

for i, item in enumerate(combo):
    x_dif = item[0][0] - item[1][0]
    y_dif = item[0][1] - item[1][1]
    diff[i] = [x_dif, y_dif]
    if str(diff[i]) in dict_diff:
        dict_diff[str(diff[i])] += 1
    else:
        dict_diff[str(diff[i])] = 1
    
    x_dif = item[1][0] - item[0][0]
    y_dif = item[1][1] - item[0][1]
    diff[i] = [x_dif, y_dif]
    if str(diff[i]) in dict_diff:
        dict_diff[str(diff[i])] += 1
    else:
        dict_diff[str(diff[i])] = 1

print((N) - max(dict_diff.values()))



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

int main() {
  int A,B;
  int n=0;
  cin>>A>>B;
  for(int i=A;i<=B;i++){
    int a,b,c,d,e;
    
      a=i/10000;
      b=(i-a*10000)/1000;
      c=(i-a*10000-b*1000)/100;
      d=(i-a*10000-b*1000-c*100)/10;
      e=(i-a*10000-b*1000-c*100-d*10);
    if(a==e && b==d)
      n++;
  }
  cout<<n<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define rall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

	int a, b;
	cin >> a >> b;
	if(a>b){
		for(int i = 0; i < a; i++){
			cout << b;
		}
	}
	else{
		for(int i = 0; i < b; i++){
			cout << a;
		}
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 3556
a, b, c, d = map(int, input().split())
if a <= 0 and b >= 0:
    print(max(a*c, a*d, b*c, b*d, 0))
elif c <= 0 and d >= 0:
    print(max(a*c, a*d, b*c, b*d, 0))
else :
    print(max(a*c, a*d, b*c, b*d))

Measured memory_bytes: 61904
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t a,b,k;
    cin >> a >> b >> k;
    for(int64_t i=a; i<=b; i++){
        if(i-a<k || b-i<k) cout << i << endl;
    }
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

int main() {

    ll N,M,K;
    cin >> N >> M >> K;
    ll A[N+1];
    rep(i,N+1){
        if(i==0) A[0] = 0;
        else{
            ll a;
            cin >> a;
            A[i] = A[i-1]+a;
        }
    }
    ll B[M];
    rep(i,M){
        ll b;
        cin >> b;
        if(i==0) B[0] = b;
        else B[i] = B[i-1]+b;
    }
    ll out = 0;
    ll bMax = M;
    rep(i,N+1){
        rep(j,bMax){
            if(A[i]+B[bMax-1-j]<=K){
                out = max(out,i+bMax-j);
                bMax = bMax-j;
                break;
            }
            if(j==bMax-1) bMax = 0;
        }
        if(bMax==0){
            if(A[i]<=K) out = max(out,i);
            else break;
        };
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 6732
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>

const long long int Z = 1000000007;
const long long int INF = 1 << 30;
int flag = 0;
using ll = long long;

 ll gcd(ll a, ll b) {
	 if (b == 0) return a;
	 return gcd(b, a%b);

}
 ll lcm(ll a, ll b) {
	 ll g = gcd(a, b);
	 return a / g * b;
 }

 int main() {
	 std::string w, s;
	 std::cin >> w;
	 std::transform(w.begin(), w.end(), w.begin(), tolower);
	 int ans = 0;
	 while (std::cin >> s) {
		 if (s == "END_OF_TEXT")break;
		 std::transform(s.begin(), s.end(), s.begin(), tolower);
		 if (w == s) {
			 ans += 1;
		 }
	 }
	 std::cout << ans << std::endl;
	return 0;
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll x; cin>>x;
  if(x) cout<<0<<endl;
  else cout<<1<<endl;
  
}

Measured memory_bytes: 3648
#include <iostream>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a[1002][1002] = {0};
  int h,w;
  int m=0;
  char Q;
  cin >> h >> w;
  for (int i=1;i<h+1;i++){
    for (int j=1;j<w+1;j++){
      cin >> Q;
      if (Q == '.') a[i][j]=3000;
    }
  }
  for (int i=1;i<h+1;i++){
    for (int j=1;j<w+1;j++){
      if (a[i][j-1] > a[i][j])  a[i][j-1]=a[i][j]+1;
      if (a[i][j+1] > a[i][j])  a[i][j+1]=a[i][j]+1;
      if (a[i+1][j] > a[i][j])  a[i+1][j]=a[i][j]+1;
      if (a[i-1][j] > a[i][j])  a[i-1][j]=a[i][j]+1;
    }
  }
  for (int i=h;i>0;i--){
    for (int j=w;j>0;j--){
      if (a[i][j-1] > a[i][j])  a[i][j-1]=a[i][j]+1;
      if (a[i][j+1] > a[i][j])  a[i][j+1]=a[i][j]+1;
      if (a[i+1][j] > a[i][j])  a[i+1][j]=a[i][j]+1;
      if (a[i-1][j] > a[i][j])  a[i-1][j]=a[i][j]+1;
    }
  }
  for (int i=1;i<h+1;i++){
    for (int j=1;j<w+1;j++){
      if (m < a[i][j]) m = a[i][j];
    }
  }
 cout << m;
 return 0;
}

Measured memory_bytes: 4224
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int main() {
	int n,t,a,b;
	vector<int> x;
	cin >> n >> t;
	for (int i = 0; i < n; i++)
	{
		cin >> a >> b;
		if (b <= t) x.push_back(a);
	}
	x.push_back(0);
	sort(x.begin(), x.end());
	if (x.size() == 1) cout << "TLE"<<endl;
	else cout << x[1] << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
const int maxn = 2600;
vector<pair<int,int>> g[maxn];
vector<int> inv_g[maxn];
int dis[maxn]; 
bool vis[maxn];
const int inf = 1e9;
bool bellman_ford(int s,int n)
{
	for(int i=1;i<=n;++i)dis[i] = inf;
	dis[s] = 0;
	for(int t=1;t<n;++t) 
		for(int i=1;i<=n;++i)
			for(pair<int,int> x:g[i])
				if(dis[i] != inf && dis[i] + x.second < dis[x.first])
					dis[x.first] = dis[i] + x.second;
	for(int i=1;i<=n;++i)
		for(pair<int,int> x:g[i])
			if(dis[i] != inf && vis[x.first] && dis[i] + x.second < dis[x.first])
				return false;
	return true;
}
void dfs(int x)
{
	if(vis[x])return;
	vis[x] = 1;
	for(int y:inv_g[x])
		dfs(y);
}
int main()
{
	int n,m,p;
	cin>>n>>m>>p;
	for(int i=1;i<=m;++i)
	{
		int x,y,w;
		cin>>x>>y>>w;
		g[x].push_back(make_pair(y,p-w));
		inv_g[y].push_back(x);
	}
	dfs(n);
	if(!bellman_ford(1,n))
		cout<<-1<<endl;
	else
		cout<<max(-dis[n],0)<<endl;
}

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

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> a(h, vector<char>(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> a.at(i).at(j);
        }
    }

    int nx = 0, ny = 0;
    a.at(0).at(0) = '.';
    for (int i = 0; i < h + w - 2; i++) {
        if (nx + 1 < w && a.at(ny).at(nx + 1) == '#') nx++;
        else if (ny + 1 < h && a.at(ny + 1).at(nx) == '#') ny++;
        else {
            cout << "Impossible" << endl;
            return 0;
        }
        a.at(ny).at(nx) = '.';
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (a.at(i).at(j) == '#') {
                cout << "Impossible" << endl;
                return 0;
            }
        }
    }
    cout << "Possible" << endl;
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define zeroes(x) memset(x,0,sizeof(x))
typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn=100000;



int main()
{		
	
    
    IOS
    ll n;
    cin>>n;
    ll a[n],sum=0;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    sum/=2;
    for(ll i=0;i<n-1;i+=2)
    {
        sum-=a[i];
    }

    cout<<2*(a[n-1]-sum)<<" ";
    sum=a[n-1]-sum;
    for(ll i=0;i<n-1;i++)
    {
        cout<<2*(a[i]-sum)<<" ";
        sum=a[i]-sum;
    }


    return 0;



}


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

using namespace std;

int N;
vector<int> Trampoline;

int main() {
	int d, nextPos;

	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> d;
		Trampoline.push_back(d/10);
	}

	for (int cnt = 0; cnt < 2; ++cnt) {
		nextPos = 0;
		for (int startPos = 0; startPos < N; ++startPos) {
			if (nextPos < startPos) {
				cout << "no" << endl;
				return 0;
			}
			nextPos = max(nextPos, startPos + Trampoline[startPos]);
		}
		reverse(Trampoline.begin(), Trampoline.end());
	}
	cout << "yes" << endl;

	return 0;
}


Measured memory_bytes: 4980
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define files(name) name!=""?freopen(name".in","r",stdin),freopen(name".out","w",stdout):0
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define elif else if
#define mp make_pair
#define pb push_back
#define fir first
#define sec second

using namespace std;
#define int long long

typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;

const int arr=2e5+10;
const int ar=2e3+10;
const ld pi=acos(-1);
const ld eps=1e-10;
const ll md=1e9+7;

///---program start---///

main()
{
    #ifdef Barik
        files("barik");
        freopen("debug.txt","w",stderr);
    #endif

    string s;
    cin>>s;
    map<char,bool> cnt;
    for (auto i:s){
        cnt[i]=1;
    }
    if ((cnt['N']^cnt['S'])){
        cout<<"No"<<"\n";
        return 0;
    }
    if ((cnt['W']^cnt['E'])){
        cout<<"No"<<"\n";
        return 0;
    }
    cout<<"Yes"<<"\n";
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  double xA, yA, xB, yB, xC, yC, xD, yD;
  double xAB, yAB, xCD, yCD;
  double AB, CD;

  while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &xA, &yA, &xB, &yB, &xC, &yC, &xD, &yD) != EOF){
    xAB = xA - xB;
    yAB = yA - yB;
    xCD = xC - xD;
    yCD = yC - yD;

    if(yAB == 0 && yCD == 0){
      printf("NO\n");
    }else if(xAB == 0){
      if(yCD == 0)
        printf("YES\n");
      else
        printf("NO\n");
    }else if(xCD == 0){
      if(yAB == 0)
        printf("YES\n");
      else
        printf("NO\n");
    }else{
      AB = yAB / xAB;
      CD = yCD / xCD;

      if(AB == -1.0/CD)
        printf("YES\n");
      else
        printf("NO\n");
    }
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
	int n,x,a,b,c,d,e;
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

	cin>>n>>a>>b;
	for(int i=0;i<n;i++)
	{
		cin>>x;
		if(x<=a)c++;
		else if(x>=a+1&&x<=b)d++;
		else if(x>=b+1)e++;
	}
	int ans=min(c,d);
	cout<<min(ans,e);
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}


int main(void) {
  ll W, H, x, y;
  cin >> W >> H >> x >> y;
  
  ll f;
  if(x*2==W && y*2==H) f=1;
  else f=0;
  
  printf("%.10f %lld\n", (double)W*H/2, f);
  
  
}







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

char bomb(vector<string> box, int a, int b){
    int count = 0;
    
    if(box.at(a).at(b) == '#'){
        return '#';
    }else{
        for(int i=-1; i<=1; i++){
            for(int j=-1; j<=1; j++){
                if(a+i<0 or a+i>=box.size());
                else if(b+j<0 or b+j>=box.at(0).size());
                else if(i==0 and j==0);
                else if(box.at(a+i).at(b+j) == '#')
                    count++;
                else;
            }
        }
        return ('0'+count);
    }
}

int main(){
    int h,w; cin>>h>>w;
    vector<string>  strvec(h);
    for(int i=0; i<h; i++)
        cin>>strvec.at(i);
    
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            strvec.at(i).at(j) = bomb(strvec, i, j);
        }
        cout<<strvec.at(i)<<endl;
    }
}



Measured memory_bytes: 256
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int main() {
  vector<int> v(3);
  REP(i,3)
  {
    cin >> v[i];
  }

  int count = 0;
  while(true)
  {
  SORT(v);
    if(v[0]==v[1]&&v[0]+1==v[2])
    {
      count++;
      break;
    }
    if(v[0]==v[1]&&v[0]==v[2])
    {
      break;
    }
    v[0] += 2;
    count++;
  }

  cout << count << endl;
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint operator-() const { return mint(-x); }

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }

    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

int main() {
    int N;
    cin >> N;
    vector<int> D(N);
    rep(i, N) cin >> D[i];

    if (D[0] != 0) {
        cout << 0 << endl;
        return 0;
    }

    int ma = 0;
    map<int, int> mp;
    rep(i, N) {
        int d = D[i];
        if (i != 0 && d == 0) {
            cout << 0 << endl;
            return 0;
        }

        chmax(ma, d);
        mp[d]++;
    }

    mint ans = 1;
    for (int i = 1; i <= ma; i++) {
        if(mp[i] == 0) {
            cout << 0 << endl;
            return 0;
        }

        ans *= mint(mp[i-1]).pow(mp[i]);
    }

    cout << ans.x << endl;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
 
/* {{{ */
#define CL(N) cout << N << endl
#define DCT(N) cout << "debug " << N << endl
#define REP(i, N) for (int i = 0; i < N; i++)
/* }}} */
 
int main()
{
    int w, h, n;
 
    cin >> w >> h >> n;
 
    int a[10000], b[10000];
    REP(i, n){
        cin >> a[i] >> b[i];
    }
 
    int sum = 0;
    REP(i, n - 1){
        if (a[i] < a[i + 1] && b[i] < b[i + 1]){
            sum += max(a[i + 1] - a[i], b[i + 1] - b[i]);
        }
        else if (a[i] > a[i + 1] && b[i] > b[i + 1]){
            sum += max(a[i] - a[i + 1], b[i] - b[i + 1]);
        }
        else {
            sum += abs(a[i + 1] - a[i]) + abs(b[i + 1] - b[i]);
        }
    }
 
    CL(sum);
     
    return (0);
}

Measured memory_bytes: 3024
n, q = map(int, input().split())
s = input()
sum_array = [0 for _ in range(n)]

for j in range(0,n-1):
    if((s[j] == 'A') and s[j+1] == 'C'):
        sum_array[j+1] = sum_array[j] + 1
    else:
        sum_array[j+1] = sum_array[j]

for i in range(q):
    l,r = map(int, input().split())
    ans = sum_array[r-1] - sum_array[l-1]
    print(ans)


Measured memory_bytes: 6180
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
 var hw = lines[0].split(' ');
 var h = Number(hw[0]);
 var w = Number(hw[1]);
 var ans = 0;
 
 
 if((h * w) % 2 == 0){
   ans = h*w / 2;
 }else{
   ans = Math.round(h*w / 2);   
 }

 if(h==1 || w==1){
   ans = 1;
 }
 
 console.log(ans);
});

Measured memory_bytes: 21320
#include <iostream>
typedef long long ll;
using namespace std;

int main(void) {
    ll H,W;cin>>H>>W;
    if (H == 1 || W == 1) {
        cout << 1 << endl;
        return 0;
    }
    if (H % 2 == 0 || W % 2 == 0) cout << H * W / 2  << endl;
    else cout << H * W / 2 + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
#include <cstring>
#include <numeric>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define repll(i,n) for(long long int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
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 int INF = INT_MAX;
const long long LLINF = 1LL<<60;
template <typename T_char>
char ToUpper (char cX) { return toupper(cX); }
//g++ -std=c++1z temp.cpp
//./a.exe
ll digit(ll a){
    ll count = 0;
    for (ll i = 0; i < a; i++)
    {   if (a == 0)
        {
            break;
        }else
        {
            a = a/10;
            count++;
        }
    }
    return count;
}
//桁数のカウント
//pow(x,n) == x^n
//sum = accumulate(v.begin(),v.end(),0);
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;}



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

ll r,d,x;
cin >> r >> d >> x;

rep(i,10){
    x = r*x - d;
    cout << x << endl;
}


//////////////////////////////////////////////////////
return 0;}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vch = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
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;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;

int main(){
	ll n;
	cin >> n;
	set<st> s;
	rep(i, 0, n){
		st ss;
		cin >> ss;
		s.insert(ss);
	}
	cout << s.size() << endl;
}

Measured memory_bytes: 19180
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#define rip(i,n) for(int i=0;i<n;i++)
#define ll long long
#define lb long double
#define vec vector<int>
#define vec2 vector<vector<int>>
#define set setprecision
#define mod 1000000007
#define pi 3.14159265
#include<numeric>
using namespace std;
int gcd(int a, int b)
{
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
int lcm(int a, int b)
{
	return a * b / gcd(a, b);
}
ll pow(ll a, ll b) {
	ll k = b % 30000, h = b / 30000, s = 1;
	rip(i, 30000)s = (s * a) % mod; ll j = 1;
	if (h != 0)rip(i, h)j = j * s % mod;
	if (k != 0)rip(i, k)j = j * a % mod;
	return(j);
}
int main() {
	int n;
	cin >> n;
	vec a(n);
	int k;
	rip(i, n)cin >> a[i];
	if (n < 10) {
		int maxxx = 0;
		rip(i, n) {
			if (i != 0) k = a[0];
			else  k = a[1];
			rip(j, n) {
				if (j != i)k = gcd(k, a[j]);
			}
			maxxx = max(maxxx, k);
		}
		cout << maxxx << endl;
	}
	else {
		int p[100009], r[100009];
		int l = a[0];//subetenosaidaikouyakusuu
		rip(i, n) {
			l = gcd(l, a[i]);
			p[i] = l;
		}
		int k = a[n - 1];
		rip(i, n) {
			int j = n - 1 - i;
			k = gcd(k, a[j]);
			r[j] = k;
		}
		p[-1] = l;
		r[n] = l;
		int maxx = 0;
		rip(i, n) {
			maxx = max(maxx, gcd(p[i - 1], r[i + 1]));
		}
		cout << maxx << endl;
	}
}


Measured memory_bytes: 1408
n,m=[int(i) for i in input().split()]
a=sorted([int(i) for i in input().split()])
bc=sorted([[int(i) for i in input().split()] for _ in range(m)],key=lambda x:x[1])[::-1]
d=[]
ans=0
for b,c in bc:
    d+=[c]*b
    if len(d)>=n:
        break
for i in range(n):
    try:
        #元のカード列と置き換えるカード列で大きい方を選ぶ
        ans+=max(a[i],d[i])
    except:
        ans+=a[i]
print(ans)

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

long long n;

string solve();

int main() {
  cin >> n;
  cout << solve() << endl;
  return 0;
}

string solve() {
  if(n == 0) return "0";
  string ans;
  while(n != 0) {
    ans += '0' + abs(n) % 2;
    n -= abs(n) % 2;
    n /= -2;
  }
  reverse(ans.begin(), ans.end());
  return ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <functional>

using namespace std;

int main() {
    string n;

    cin >> n;

    if(n[0] == 'Y' && n[1] == 'A' && n[2] == 'K' && n[3] == 'I'){
        cout << "Yes" << endl;
    }

    else {
        cout << "No" << endl;
    }
    
  return 0;
  
}


Measured memory_bytes: 256