akhauriyash/Code-Regression huggingface dataset:
// AtCoder ABC113: B - Palace
// 2020.1.29 bal4u

#include <stdio.h>
#include <math.h>

#define EPS 1e-10
#define EQ(a,b)  (fabs((a)-(b)) <= EPS)

int main()
{
	int i, T, A, N, ans;
	double d;
	
	scanf("%d%d%d", &N, &T, &A);
	T -= A;
	d = 1e20;
	for (i = 1; i <= N; ++i) {
		int H;
		scanf("%d", &H);
		double t = fabs(T - H*0.006);
		if (t < d) d = t, ans = i;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
  int X=0;
  int ans=0;
  cin >> X;
  ans += (X/500)*1000;
  X = X %500;
  ans += (X/5)*5;
  cout << ans <<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int sx = sc.nextInt();
        int sy = sc.nextInt();
        int tx = sc.nextInt();
        int ty = sc.nextInt();
        int dx = tx - sx;
        int dy = ty - sy;
        StringBuilder sb = new StringBuilder();
        go(sb, 'R', dx);
        go(sb, 'U', dy);
        go(sb, 'L', dx);
        go(sb, 'D', dy+1);
        go(sb, 'R', dx+1);
        go(sb, 'U', dy+1);
        go(sb, 'L', 1);
        go(sb, 'U', 1);
        go(sb, 'L', dx+1);
        go(sb, 'D', dy+1);
        go(sb, 'R', 1);

        System.out.println(sb.toString());
        sc.close();
    }

    private static void go(StringBuilder sb, char c, int dx) {
        for (int i = 0; i < dx; i++) {
            sb.append(c);
        }
    }

}


Measured memory_bytes: 23636
import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.conv, std.stdio, std.typecons;

void main()
{
  auto rd = readln.split.map!(to!int);
  auto a = rd[0], b = rd[1], c = rd[2];
  writeln(a < b && b < c ? "Yes" : "No");
}

Measured memory_bytes: 2484
#include<bits/stdc++.h>
using namespace std;
double eps=0.0000001;

double solve(){
  int n,m;
  double a=0,b=0,num=0,p=0;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>num>>p;
    a+=p*num;
    b+=p;
  }
  return a/b;
}

int main(){
  int t;
  cin>>t;
  double maxm=0;
  for(int i=0;i<t;i++)maxm=max(maxm,solve());
  if(maxm>solve()+eps)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}

Measured memory_bytes: 1232
#include <stdio.h>
#include <string.h>

int main(void) {
    char s[100001];
    scanf("%s", s);
    int n = (int)strlen(s);
    int min = 100001;
    for(int i = 0; i <= 1; i++) {
        int count = 0;
        for(int j = 0; j < n; j++) {
            if(i == 0) {
                if(j%2 == 0) {
                    if(s[j] == '1') count++;
                } else {
                    if(s[j] == '0') count++;
                }
            } else if(i == 1) {
                if(j%2 == 1) {
                    if(s[j] == '1') count++;
                } else {
                    if(s[j] == '0') count++;
                }
            }
        }
        if(min >= count) min = count;
     }
    printf("%d\n", min);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long unit = 26;
int main(){
    long long n;
    cin >> n;
    string ans="a";
    n--;
    vector <int> cv;
    do{
        char mod = n%unit;
        char div = n/unit;
        cv.push_back(mod);
        ans[0]+=mod;
        n-=n%unit;
        n/=unit;
        if(n==1){
            cv.push_back(0);
        }
        n--;
    }while(n>0);

    // for(int i = 0; i < cv.size(); i++){
    //     cout << cv[i] << " ";
    // }
    // cout << endl;
    for(int i = cv.size()-1; i >= 0; i--){
        cout << (char)('a'+(char)cv[i]);
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3612
n = int(input())

a_max1 = 0
a_max2 = 0
a_max1_index = 0
for i in range(n):
    a_i = int(input())
    if a_max1 <= a_i:
        a_max2 = a_max1
        a_max1 = a_i
        a_max1_index = i
    elif a_max2 <= a_i: 
        a_max2 = a_i

for i in range(n):
    if i == a_max1_index:
        print(a_max2)
    else:
        print(a_max1)

Measured memory_bytes: 4540
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define all(x) (x.begin()),(x.end())
#define sz(x)  ((ll)x.size())
#define FAST_IO ios_base :: sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
using namespace std;
#ifdef LOCAL
#include "uj.h"
#endif

const ll oo = 1e16;
const int maxn = 1e4;
string s,t;

int N,M;
ll dp[maxn][maxn];

ll Brute(int i,int j){
	if(i == N || j == M) return 0;
	ll & ans = dp[i][j];
	if(ans != -1) return ans;
	
	if(s[i] == t[j]) return ans = Brute(i+1,j+1) + 1;
	ll a = Brute(i+1,j) ;
	ll b = Brute(i,j+1);
	return ans = max(a,b);
}

string res;
void build(int i,int j){
	if(i == N || j == M) return ;
	
	if(s[i] == t[j]){
		res += s[i];
		build(i+1,j+1);
		return;	
	}
	
	ll optimal = Brute(i,j);
	ll a = Brute(i+1,j);
	
	if(optimal == a) build(i+1,j);
	else build(i,j+1);
}
	

void test_case(){
	cin >> s >> t;
	N = sz(s),M = sz(t);
	memset(dp,-1,sizeof(dp));
	ll check = Brute(0,0);
	//debug() << owo(check);
	build(0,0);
	
	cout << res << endl;		
}

	





int main(){
	FAST_IO;
	int tt;
	//cin>>tt;
	tt = 1;
	while(tt--){
		test_case();
	}
#ifndef ONLINE_JUDGE
 	cerr << "Running Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 785176
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int n;
    cin >> n;
    vector<ll> a(n), s(n + 1, 0);

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

    ll ans = 0;

    for (int i = 0; i < n; i++)
    {
        ans += a[i] * ((s[n] - s[i + 1] + MOD) % MOD);
        ans %= MOD;
    }

    cout << ans << endl;
}


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

int main() {
  long N, A, sum, ans = 0, M = 1e9+7;
  cin >> N >> sum;
  while (cin >> A) (ans += sum * A % M) %= M, (sum += A) %= M;
  cout << ans << "\n";
}

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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

struct mint {
  ll v;
  mint() : v(0) {}
  mint(ll v) : v((v % MOD + MOD) % MOD) {}
  operator ll() const { return v; }
  mint pow(ll t) const;
  mint inv() const;
};
mint& operator+=(mint& a, mint b) { return a = a.v + b.v; }
mint& operator-=(mint& a, mint b) { return a = a.v - b.v; }
mint& operator*=(mint& a, mint b) { return a = a.v * b.v; }
mint operator+(mint a, mint b) { return a += b; }
mint operator-(mint a, mint b) { return a -= b; }
mint operator*(mint a, mint b) { return a *= b; }
mint operator-(mint a) { return (mint)0 - a; }
mint& operator/=(mint& a, mint b) { return a *= b.inv(); }
mint operator/(mint a, mint b) { return a /= b; }
mint mint::pow(ll t) const {
  if (!t) return 1;
  mint a = pow(t >> 1);
  a *= a;
  if (t & 1) a *= *this;
  return a;
}
mint mint::inv() const { return pow(MOD - 2); }
bool operator==(mint a, mint b) { return a.v == b.v; }
bool operator!=(mint a, mint b) { return a.v != b.v; }
istream& operator>>(istream& os, mint& a) { return (os >> a.v); }
ostream& operator<<(ostream& os, const mint& a) { return (os << a.v); }

mint mfact(int n) { // n! (mod MOD)
  static vector<mint> fact(1, 1);
  int pn = fact.size();
  if (pn < n + 1) {
    fact.resize(n + 1);
    for (int i = pn; i <= n; i++) fact[i] = fact[i - 1] * (mint)i;
  }
  return fact[n];
}
mint nPk(int n, int k) {
  if (n < 0 || k < 0 || n < k) return 0;
  if (k == 0) return 1;
  return mfact(n) * mfact(n - k).inv();
}
mint nCk(int n, int k) {
  if (n < 0 || k < 0 || n < k) return 0;
  if (k == 0) return 1;
  return mfact(n) * mfact(k).inv() * mfact(n - k).inv();
}

void solve() {
  int n, k;
  cin >> n >> k;
  vi a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  dump(a);
  mint mx = 0;
  mint mn = 0;
  rep(i, n) {
    if (i + 1 < k) continue;
    mx += nCk(i, k - 1) * (mint)a[i];
    dump(i+1, nCk(i,k-1), a[i], mx);
  }
  rep(i, n) {
    int j = n - i - 1;
    if (j + 1 < k) continue;
    mn += nCk(j, k - 1) * (mint)a[i];
    dump(i+1, nCk(j,k-1), a[i], mn);
  }
  mint ans = mx - mn;
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 2168
s = input()
t = input()
slst = []
tlst = []
for i in s:
  slst.append(i)
for i in t:
  tlst.append(i)
slst.sort(key=lambda x: ord(x))
tlst.sort(key=lambda x: ord(x), reverse=True)
s = ''.join(slst)
t = ''.join(tlst)
print('Yes' if s < t else 'No')

Measured memory_bytes: 9032
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


X,Y=map(int,input().split())
mod=10**9+7

if  X>Y*2 or Y>X*2:
    print(0)
    exit()
if (X+Y)%3!=0:
    print(0)
    exit()

count=0
_count=0
while X>0 and Y>0:
    if X>Y:
        X-=2
        Y-=1

        _count+=1
    else:

        X-=1
        Y-=2
    #print(X,Y)
    count+=1

#print(count,_count)
print(cmb(count,_count)%mod)


Measured memory_bytes: 102760
//
//  main.cpp
//  A - Day of Takahashi
//
//  Created by 张栩浩 on 2018/5/5.
//  Copyright © 2018年 张栩浩. All rights reserved.
//

#include <iostream>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(b>=a)
        cout<<a<<endl;
    else
        cout<<a-1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
typedef pair<int,int> P;
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define rep(i, n) for (lint i = 0; i < (n); i++)
#define INF LLONG_MAX
#define all(x) (x).begin(),(x).end()
#define pb push_back
int main(){
    int n,k;
    cin>>n>>k;
    int a[n];
    rep(i,n){
        cin>>a[i];
    }
    cout<<ceil(double(n-1)/(k-1))<<endl;
    return 0;
}


Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int Q = scanner.nextInt();

        long count = 0;
        long minb = Integer.MAX_VALUE;

        int[] A = new int[Q];
        int[] B = new int[Q];

        for (int i = 0; i < Q; i++) {
            A[i] = scanner.nextInt();
            B[i] = scanner.nextInt();
            count += A[i];
            if (A[i] > B[i]) {
                minb = Math.min(minb, B[i]);
            }
        }
        scanner.close();

        if (Arrays.equals(A, B)) {
            System.out.println(0);
            return;
        }

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

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

using namespace std;

#define int long long

const int N = 2e5+1;
int n, a[N], pre[N], f1[N], f2[N];

int sum(int l,int r){
	return pre[r] - pre[l-1];
}

signed main(){
	cin >> n;
	for(int i=1;i<=n;++i) cin >> a[i], pre[i] = pre[i-1] + a[i];
	
	f1[2] = 1;
	for(int i=3,l=1;i<=n-2;++i){
		while(abs(sum(l+1,i)-sum(1,l))>abs(sum(l+2,i)-sum(1,l+1))) ++l;
		f1[i] = l;
	}
	f2[n-1] = n;
	for(int i=n-2,r=n;i>=3;--i){
		while(i<=r-2 && abs(sum(i,r-1)-sum(r,n))>abs(sum(i,r-2)-sum(r-1,n))) --r;
		f2[i] = r;
	}	
	int ans = 1e18;
	for(int i=2;i<=n-2;++i){
		int l1 = sum(1,f1[i]), l2 = sum(f1[i]+1,i);
		int r1 = sum(i+1,f2[i+1]-1), r2 = sum(f2[i+1],n);

		ans = min(max({l1,l2,r1,r2}) - min({l1,l2,r1,r2}), ans);
	}
	cout << ans;
}

Measured memory_bytes: 9856
#include <stdio.h>
#include <stdlib.h>

int main(void){
	int n, i, t[100001]={0}, x[100001]={0}, y[100001]={0}, dt, dx, dy, f=0;
	
	scanf("%d", &n);
	for(i = 1; i <= n; i++){
		scanf("%d %d %d", &t[i], &x[i], &y[i]);
	}
	
	for(i = 1; i <= n; i++){
	    dt = abs(t[i] - t[i-1]);
	    dx = abs(x[i] - x[i-1]);
	    dy = abs(y[i] - y[i-1]);
	    if((dt < (dx + dy)) || ((dt - (dx + dy))%2 != 0)){
	        f = 1;
	    }
	}
	printf("%s\n", f?"No":"Yes");

    return 0;
}


Measured memory_bytes: 1280
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int  long long int
#define pb push_back
#define fe first
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define mi          map<int,int>
#define mii         map<pi,int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 
#define PI 3.14159265358979323846

 const int N=1e6+5;

 int mod= 1e9+7;
 int dx[4]={0,0,+1,-1};
 int dy[4]={+1,-1,0,0};  
 
 
int po(int a, int b) {
	a %= mod;
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a) % mod;
		a =(a*a) % mod;
		b >>= 1;
	}
	 return res;	
  }
  
  
  
  	
void solve() {
    int n;
    cin>>n;
    vi a(n,0);
    rep(i,0,n) cin>>a[i];
    sort(all(a));
    
    vi pr;
    int p=0;
    for(int i=n-1;i>0;i--) { 
		  p+=a[i];
		  pr.pb(p);
		}
	 reverse(all(pr));
	 int maxi=0;
	 rep(i,0,n-1) {
		   int yo=((a[i]%mod)*(pr[i]%mod))%mod;
		   maxi=(maxi%mod+yo%mod)%mod; 
		 }
		 
		 cout<<maxi<<endl;                          
}

    
int32_t main() {
	cool;
	int t=1;	

	//cin>>t;
	while(t--)
	  solve();

  return 0;	   
}


Measured memory_bytes: 6892
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var s = Console.ReadLine().Trim();

        var k = 0;
        int l = 0, r = s.Length - 1;
        while (r - l > 0)
        {
            if (s[l++] == s[r--])
            {
                continue;
            }

            ++k;
        }

        Console.WriteLine(k);
    }
}


Measured memory_bytes: 11092
#068_D
k = int(input())
x = -(-k // 50)
y = x * 50 - k
a = [i+(x-1) for i in range(1, 51)]
for _ in range(y):
    a.sort()
    for i in range(50):
        a[i] += 1
    a[-1] -= 51
a.sort()
print(50)
print(*a)

Measured memory_bytes: 3316
from copy import copy
while True:
    n,p=map(int,input().split())
    if n==0:break
    l=[0 for _ in range(n)]
    a=-1
    p1=copy(p)
    while True:
        a+=1
        if a==n:
            a=0
        if p>0:
            if l[a]+1==p1:
                print(a)
                break
            l[a]+=1
            p-=1
            continue
        if p==0:
            p=l[a]
            l[a]=0

    


Measured memory_bytes: 6332
import sys

def solve():
    input = sys.stdin.readline
    L = [int(i) for i in input().split()]
    L.sort()
    odd, even = 0, 0
    for l in L:
        if l % 2 == 0: even += 1
        else: odd += 1
    count = 0
    if even == 3 or odd == 3: count = 0
    elif even == 2:
        count += 1
        for i in range(3):
            if L[i] % 2 == 0: L[i] += 1
    elif odd == 2:
        count += 1
        for i in range(3):
            if L[i] % 2 == 1: L[i] += 1
    count += (L[2] - L[0]) // 2 + (L[2] - L[1]) // 2
    print(count)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const long long mod = 1e9 + 7;

int main(){
     int n;
     cin >> n;
     string s;
     cin >> s;
     int ans = 1;
     rep(i,s.size()-1){
          if(s[i] != s[i+1])ans++;
     }
     cout << ans << endl;
}

Measured memory_bytes: 512
MOD = 10 ** 9 + 7
C = ['A','G','C','T']
R = /(AGC|ACG|GAC|A.GC|AG.C)/
W4 = C.product(C,C,C).map(&:join).reject{|w4| R =~ w4 }.sort
INDEX = {}
W4.each_with_index do |w4, i|
  INDEX[w4] = i
end
A = W4.map do |w4|
  w3 = w4[1,3]
  C.map{|c| INDEX["#{w3}#{c}"] }
end

N = gets.to_i
if N == 3
  puts  C.product(C,C).map(&:join).reject{|w3| R =~ w3 }.size
  exit
elsif N == 4
  puts W4.size
  exit
end

dp = Array.new(N + 1){ Array.new(W4.size, 0) }
W4.each_index{|i| dp[4][i] = 1 }
(4 ... N).each do |n|
  W4.each_index do |i|
    C.each_index do |j|
      i_ = A[i][j]
      dp[n + 1][i_] = (dp[n + 1][i_] + dp[n][i]) % MOD if i_
    end
  end
end
puts dp[N].inject(0, &:+) % MOD


Measured memory_bytes: 2296
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> p(m);
    vector<string> s(m);
    for(int i=0; i<m; i++) cin >> p[i] >> s[i];
    for(int i=0; i<m; i++) p[i]--;

    vector<int> penalty(n);
    vector<bool> ac(n);
    for(int i=0; i<n; i++) {penalty[i] = 0; ac[i] = false;}

    for(int i=0; i<m; i++){
        if(s[i] == "AC")  ac[p[i]] = true;
        else{
            if(!ac[p[i]]) penalty[p[i]]++;
        }
    }

    int pena = 0, ans = 0;
    for(int i=0; i<n; i++){
        if(ac[i]) {
            ans++;
            pena += penalty[i];
        }
    }

    cout << ans << ' ' << pena << endl;
    return 0;


}

Measured memory_bytes: 7008
l, r = map(int, input().split())

if r - l >= 2019:
    print(0)
else:
    m = 2019
    for i in range(l, r):
        for j in range(i+1, r+1):
            if i*j % 2019 < m:
                m = i*j%2019
    print(m)

Measured memory_bytes: 2940
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0

for a in range(A + 1):
	for b in range(B + 1):
		for c in range(C + 1):
			if X == 500 * a + 100 * b + 50 * c:
				ans += 1
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define endl '\n'
#define pb push_back
const int N=1e5+1;
const int INF=1e9+7;

int32_t main()
{
 ios_base::sync_with_stdio(0);
 cin.tie(0); cout.tie(0);
 int n; cin>>n; int H[n];
 for(int i=0;i<n;i++){cin>>H[i];}
 int dp[n];
 dp[0]=0,dp[1]=abs(H[0]-H[1]);
 for(int i=2;i<n;i++)
 {
     dp[i]=min((dp[i-2]+abs(H[i]-H[i-2])),(dp[i-1]+abs(H[i]-H[i-1])));
 }
 cout<<dp[n-1];
}

Measured memory_bytes: 5144
n, q = map(int, input().split())
s = input()

t = [0] * (n + 1)
for i in range(n):
    t[i + 1] = t[i] + (1 if s[i:i+2] == 'AC' else 0)

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

for a in ans:
    print(a)


Measured memory_bytes: 11876
S = input()

ans = len(S)
for i in range(26):
    c = chr(ord('a') + i)
    if c not in S: continue
    cnt = 0
    s = S
    while any(a!=c for a in s):
        t = ''
        for a,b in zip(s,s[1:]):
            if c==a or c==b:
                t += c
            else:
                t += a
        s = t
        cnt += 1
    ans = min(ans, cnt)
print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <istream>
#include <map>
#include <numeric>
#include <ostream>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>


int clz(long long n);


using namespace std;

typedef long long ll;


class Solution {
 public:
  void solve(std::istream& in, std::ostream& out) {
    int n, k;
    in >> n >> k;
    vector<ll> h_bit[50];
    ll ar[n];
    for (int ctr1 = 0; ctr1 < n; ++ctr1)
      in >> ar[ctr1];
    for (int ctr1 = 0; ctr1 < n; ++ctr1) {
      ll c_sum = 0;
      for (int ctr2 = ctr1; ctr2 < n; ++ctr2) {
        c_sum += ar[ctr2];
        for (ll t = c_sum; t > 0; t -= (1LL << clz(t)))
          h_bit[clz(t)].push_back(c_sum); 
      }
    }
    ll rez = 0;
    for (int ctr1 = 49; ctr1 >= 0; --ctr1) {
      if (h_bit[ctr1].size() >= k) {
        for (int ctr2 = 0; ctr2 < 49; ++ctr2)
          if (ctr2 != ctr1)
            h_bit[ctr2].clear();
        rez |= 1LL << ctr1;
        for (auto num : h_bit[ctr1]) {
          ll next_num = num ^ (1LL << ctr1);
          for (ll t = next_num; t > 0; t -= (1LL << clz(t)))
            h_bit[clz(t)].push_back(next_num); 
        }
        h_bit[ctr1].clear();
      }
    }
    out << rez << "\n";
  }
};

void solve(std::istream& in, std::ostream& out)
{
  out << std::setprecision(12);
  Solution solution;
  solution.solve(in, out);
}
// Powered by caide (code generator, tester, and library code inliner)


#include <fstream>
#include <iostream>


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


  istream& in = cin;


  ostream& out = cout;

  solve(in, out);
  return 0;
}


int clz(long long n) {
      return n ? 63 - __builtin_clzll(n) : -1;
}



Measured memory_bytes: 76140
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 10 10:05:08 2019

@author: shinjisu
"""


# ARC 077 C
def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def zeros(n): return [0]*n


def dmp(x):
    global debug
    if debug:
        print(x)


def probC_TLE():
    N = getInt()
    A = getIntList()
    dmp((N, A))
    b = []
    for i in range(N):
        b.append(A[i])
        b.reverse()
        dmp(b)
    return b


def probC_TLE2():
    N = getInt()
    A = getIntList()
    dmp((N, A))
    former, latter = [], []
    for i in range(-1, -N-1, -1):
        if i % 2 == 0:
            latter = [A[i]] + latter
        else:
            former.append(A[i])
        full = former + latter
        dmp((former, latter, full))
    return full


def probC_TLE3():
    N = getInt()
    A = [x for x in input().split()]
    dmp((N, A))
    former, latter = '', ''
    for i in range(-1, -N-1, -1):
        if i % 2 == 0:
            latter = A[i] + ' ' + latter
        else:
            former = former + ' ' + A[i]
        dmp((former, latter))
    return former[1:] + ' ' + latter


def probC():
    N = getInt()
    A = getIntList()
    dmp((N, A))
    b = zeros(N)
    for i in range(-1, -N-1, -1):
        if i % 2 == 0:
            b[i//2] = A[i]
        else:
            b[-i//2] = A[i]
        dmp(b)
    return b


debug = False
# print(probC())
for n in probC():
    print(n, end=' ', flush=True)


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

int main(){
	int i=0,x;
	while(1){    //while(1)?????????while(0)???????????¨???
		cin >> x;
		i++;
		if(x==0)
			break;
		
		printf("Case %d: %d\n",i,x);

	}

	return 0;
}

Measured memory_bytes: 1144
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int A = sc.nextInt();
		int B = sc.nextInt();
		int X = 0;
		if(A > B){
		X = A + (A - 1);
		}
		if(A == B){
			X = A + B;
		}
    	if(A < B){
    	X =	B + (B - 1);
		}
		System.out.println(X);
	}
}	
		

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long a = in.nextLong();
        long b = in.nextLong();
        long n = in.nextLong();
        long x = Math.min(b-1, n);
        long diff = (long)Math.floor(a * x / (double)b) - a * (long)Math.floor(x / (double)b);
        System.out.println(diff);
    }
}


Measured memory_bytes: 35744
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<vector>
#define L long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pl pair<L,L>
using namespace std;
int n,l[200010],r[200010],a[200010];
vector<pl> x[200010];
inline bool cmp(pl a,pl b)
{
    return a.se<b.se;
}
inline void dfs(int i,L m)
{
    int j,k,u,v;
    if(!l[i])
      x[i].pb(mp(0,0));
    else
      {
       dfs(l[i],m);
       dfs(r[i],m);
       u=x[l[i]].size();
       v=x[r[i]].size();
       if(u>v)
         {
          swap(l[i],r[i]);
          swap(u,v);
         }
       sort(&x[l[i]][0],&x[l[i]][0]+u,cmp);
       sort(&x[r[i]][0],&x[r[i]][0]+v);
       for(j=k=0;j<v;j++)
         if(x[r[i]][j].se<x[r[i]][k].se)
           x[r[i]][++k]=x[r[i]][j];
       v=k+1;
       for(j=0,k=v-1;j<u;j++)
         {
          while(k>=0 && x[l[i]][j].se+x[r[i]][k].fi>m)
            k--;
          if(k<0)
            break;
          x[i].pb(mp(x[l[i]][j].fi,x[r[i]][k].se));
          x[i].pb(mp(x[r[i]][k].se,x[l[i]][j].fi));
         }
      }
    for(j=x[i].size()-1;j>=0;j--)
      {
       x[i][j].fi+=a[i];
       x[i][j].se+=a[i];
      }
}
inline bool check(L m)
{
    int i;
    for(i=1;i<=n;i++)
      x[i].clear();
    dfs(1,m);
    return x[1].size();
}
int main()
{
	int i,j,k;
    long long l=0,r=10000000000ll;
    scanf("%d",&n);
    for(i=2;i<=n;i++)
      {
       scanf("%d%d",&j,&k);
       a[i]=k;
       if(!::l[j])
         ::l[j]=i;
       else
         ::r[j]=i;
      }
    while(l<r)
      if(check(l+r>>1))
        r=(l+r>>1);
      else
        l=(l+r>>1)+1;
    cout<<l<<"\n";
	return 0;
}

Measured memory_bytes: 28916
import math
def main(cell):

    n=cell[0]
    k=cell[1]
    if k==0:
        return n
    else:

        risk=math.floor(n/k)
        if risk ==0:
            n=n
        else:
            n=abs(n-k*risk)
        pren=n
        while 2>0:
            n=abs(n-k)
            if n >pren:
                break
            else:
                pren=n

        return pren
    


cell=list(map(int,input().split()))
pren=main(cell)
print(pren)

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

int main() {
  int64_t n;
  std::cin >> n;

  std::vector<int64_t> a(n);
  std::string s;
  std::cin >> s;

  for (int64_t i = 0; i < n; i++) {
    if (s[i] == '.') {
      a[i] = 1;
    } else {
      a[i] = 0;
    }
  }

  for (int64_t i = 1; i < n; i++) {
    a[i] += a[i - 1];
  }
  std::vector<int64_t> b(n);
  for (int64_t i = 0; i < n; i++) {
    b[i] = i + 1 - a[i];
  }

  int64_t ans = std::min(n - a[n - 1], n - b[n - 1]);

  for (int64_t i = 1; i < n; i++) {
    int64_t t = (i - a[i - 1]) + (n - i - (b[n - 1] - b[i - 1]));
    ans = std::min(t, ans);
  }

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

Measured memory_bytes: 3716
n = int(input())
c = []
s = []
f = []
for i in range(n - 1):
  c += [0]
  s += [0]
  f += [0]
  c[i], s[i], f[i] = [int(x) for x in input().split()]

for i in range(n - 1):
  now = 0
  for j in range(i, n - 1):
    if now <= s[j]:
      now = s[j]
    else:
      if (now - s[j]) % f[j] != 0:
        now += f[j] - (now - s[j]) % f[j]
    now += c[j]
  print(now)

print('0')


Measured memory_bytes: 3064
#include <iostream>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>

using namespace std;

int main()
{
	long long n, m;
	string a, b,u;
	cin >> a >> b;
	cin >> n >> m;
	cin >> u;

	if (u == a)
		n--;
	else if (u == b)
		m--;

	cout << n << " " << m << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MIN INT_MIN
#define MAX INT_MAX
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define endk "\n"
#define rep(i,j,k,inc) for(int i=j;i<k;i+=inc)
#define modd 1000000007
using namespace std;
void solve();
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    time_t start,end;
    time(&start);
    solve();
    time(&end);
    double t= double(end - start); 
/*  cout << fixed<< t<< setprecision(5)<<endl;*/
    return 0; 
}
int n,m,a,b;
int dp[2000][2000];
string base[2000];

void solve(){
	cin>>n>>m;
	rep(i,0,n,1){
		string temp;
		cin>>temp;
		base[i]=temp;
	}
	dp[0][0]=1;
	rep(i,1,n,1){
		if(base[i][0]=='#'){
			dp[i][0]=0;
		}
		else{
			dp[i][0]=dp[i-1][0];
		}
	}
	rep(i,1,m,1){
		if(base[0][i]=='#'){
			dp[0][i]=0;
		}
		else{
			dp[0][i]=dp[0][i-1];
		}
	}
	rep(i,1,n,1){
		rep(j,1,m,1){
			if(base[i][j]=='.'){
				dp[i][j]=(dp[i][j-1]%modd+dp[i-1][j]%modd)%modd;
			}
		}
	}
	cout<<dp[n-1][m-1];
}

Measured memory_bytes: 9472
#include<iostream>
using namespace std;
string s,t;
int nxt[2<<17][26];
int nownxt[26];
main()
{
	cin>>s>>t;
	int N=s.size();
	s+=s;
	for(int i=0;i<26;i++)nownxt[i]=-1;
	for(int i=s.size();i--;)
	{
		for(int j=0;j<26;j++)nxt[i][j]=nownxt[j];
		nownxt[s[i]-'a']=i;
	}
	int p=-1;
	long ans=0;
	for(int i=0;i<t.size();i++)
	{
		int q=(p<0?nownxt:nxt[p])[t[i]-'a'];
		if(q<0)
		{
			cout<<-1<<endl;
			return 0;
		}
		ans+=q-p;
		p=q%N;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 21248
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

int main()
{
	long long A, B, C;
	int X, Y;
	cin >> A >> B >> C >> X >> Y;

	auto cost = 0ull;

	if (A + B > 2 * C)
	{
		auto m = min(X, Y);
		X -= m;
		Y -= m;
		cost += C * 2 * m;
	}
	if (X > 0 && A > 2 * C)
	{
		cost += C * 2 * X;
		Y -= X;
		X = 0;
	}
	if (Y > 0 && B > 2 * C)
	{
		cost += C * 2 * Y;
		X -= Y;
		Y = 0;
	}

	if (X > 0)
	{
		cost += A * X;
	}
	if (Y > 0)
	{
		cost += B * Y;
	}

	cout << cost << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    int a, b;
    cin >> a >> b;

    cout << max(a - b * 2, 0) << endl;

    return 0;
}

Measured memory_bytes: 764
let readIntArray _ =
    stdin.ReadLine().Split(" ") |> Array.map int

()
|> readIntArray
|> fun [| a; b; k |] ->
    let sm =
        seq { a .. b }
        |> Seq.indexed
        |> Seq.takeWhile (fun (i, _) -> i < k)
        |> Seq.map snd

    let lg =
        seq { b .. -1 .. a }
        |> Seq.indexed
        |> Seq.takeWhile (fun (i, _) -> i < k)
        |> Seq.map snd

    Seq.concat [ sm; lg ]
    |> Seq.groupBy id
    |> Seq.map fst
    |> Seq.sort
    |> Seq.map string
    |> Seq.toArray
    |> String.concat "\n"
    |> printfn "%s"


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

int main(){
	int n, m, c[20];
	//input
	scanf(" %d %d", &n, &m);
	for(int i=0; i<m; ++i) scanf(" %d", &c[i]);	
	
	//solve
	
	//dp[i]:=i?????????????????????????????????????????????????°??????°
	int dp[50001] = {0};
	//???????????§????????°??§?????????
	for(int i=1; i<=50000; ++i) dp[i] = 100000;
	
	for(int i=0; i<=50000; ++i){
		for(int j=0; j<m; ++j){
			if(i+c[j]<=n){
				dp[i+c[j]] = min(dp[i+c[j]],dp[i]+1);	
			}
		}	
	}
	
	printf("%d\n", dp[n]);
}

Measured memory_bytes: 3392
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
    // int t;
    // cin>>t;
    // while(t--){
    // }
    ll n,k;
    cin>>n>>k;
    ll a[n],t,sum=0;
    vector<ll>v;
    for(int i=0;i<n;i++)
    {
        cin>>t;
        v.push_back(t);
    }
    sort(v.rbegin(),v.rend());
    
    for(int i=k;i<n;i++)
    {
        sum+=v[i];
    }
    // cout<<s
   cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 2420
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>

using namespace std;

struct cl{
	int min;
	int max;
	int f;
};

int DP[500][200]; // DP[i][j] : ?????\?????????????´?????????????????????????????????§???

int main(){
	
	int D, N, ans;
	
	cin >> D >> N;
	
	int d[500];
	
	cl cloth[500];
	
	for(int i = 1; i <= D; i++){
		cin >> d[i];
	}
	
	for(int i = 0; i < N; i++){
		cin >> cloth[i].min >> cloth[i].max >> cloth[i].f;
	}
	
	for(int i = 0; i <= D; i++){
		for(int j = 0; j <= 100; j++){
			DP[i][j] = -(1 << 30);
		}
	}
	
	DP[0][0] = 0;
	
	for(int j = 0; j < N; j++){
		if(cloth[j].min <= d[1] && cloth[j].max >= d[1]){
			DP[1][cloth[j].f] = 0;
		}
	}
	
	for(int i = 2; i <= D; i++){
		for(int j = 0; j < N; j++){
			if(cloth[j].min <= d[i] && cloth[j].max >= d[i]){
				for(int k = 0; k <= 100; k++){
					if(cloth[j].f - k >= 0){
						DP[i][cloth[j].f] = max(DP[i][cloth[j].f], DP[i - 1][cloth[j].f - k] + k);
					}
					if(cloth[j].f + k <= 100){
						DP[i][cloth[j].f] = max(DP[i][cloth[j].f], DP[i - 1][cloth[j].f + k] + k);
					}
				}
			}
		}
	}
	
	ans = -(1 << 30);
	
	/*
	for(int i = 1; i <= D; i++){
		for(int j = 0; j <= 100; j++){
			if(DP[i][j] < 0){
				printf("0 ");
			}else{
				printf("%d ", DP[i][j]);
			}
		}
		printf("\n");
	}
	*/
	for(int j = 0; j <= 100; j++){
		if(DP[D][j] > ans){
			ans = DP[D][j];
		}
	}
	
	printf("%d\n", ans);
	
	return 0;
}

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

#define F first
#define S second
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 1e5 + 223;
const int mod = 1e9 + 7;

int n, m, num[N];
bool is[N];

int main () { 
	cin >> n >> m;
	for (int i = 1;i <= n;i ++) num[i] = 1;
	is[1] = 1;
	for (int i = 1;i <= m;i ++) {
		int x, y;
		cin >> x >> y;
		if (is[x]) is[y] = 1;
		if (num[x] > 0)
			num[x] --, num[y] ++;
		if (num[x] == 0) is[x] = 0;
	}	
	int res = 0;
	for (int i = 1;i <= n;i ++) res += is[i];
	cout << res;
		

	return 0;       
}


Measured memory_bytes: 768
/*
author: Apoorv Singh
*/
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
 
typedef vector <int> vi;
typedef pair <int, int> pii;
typedef vector <long long> vll;
typedef pair <long long, long long> pll;
#define pb push_back   
#define all(c) c.begin(), c.end()
#define For(i, a, b) for (long long i = a; i < b; ++i)
#define Forr(i, a, b) for (long long i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second
#define ll long long 
#define endl "\n"
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define TRACE
#ifndef ONLINE_JUDGE
#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...);
}
#else
#define trace(...)
#endif

template <class X>
void printarr(X arr[], int n) 
{
	for (int i = 0; i < n; ++i)
		cout << arr[i] << ' ';
	cout << endl;
}
 
template <class T, class cmp = less<T>> using ordered_set = tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;

ll fpow(ll a, ll n, ll modulo) 
{
	ll ans = 1;
	while (n) 
	{
		if (n&1) ans = (ans*a)%modulo;
		a = (a*a)%modulo; n = n >> 1;
	}
	return ans;
}

void solve() 
{
	ll n,p; cin >> n >> p;
	string s; cin >> s;
	ll ans = 0;
	if (p == 2 or p == 5)
	{
		Forr(i,n-1,-1)
		{
			if ((s[i] - '0') % p)
			{
				continue;
			}

			ans += (i + 1); 
		}
		cout << ans << endl;
		return;
	}
	map <ll, ll> d;
	ll curr = 0;
	++d[curr];
	For(i,0,n)
	{
		curr = (curr + ((s[i] - '0') * fpow(10, n - i - 1, p)) % p) % p;
		++d[curr];
	}


	for (pair <ll, ll> a : d)
	{
		ans += (a.S * (a.S - 1)) / 2;
	}

	cout << ans << endl;
}

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


Measured memory_bytes: 1044
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const double EPS = 1e-12;
const double INF = 1e12;


int main(){
	int m,n;
	
	while(cin>>m){
		if(m==0)break;
		long x,y;
		vector<PLL>pic,pi;
		REP(i,m){
			cin>>x>>y;
			pic.PB(MP(x,y));
		}
		cin>>n;
		REP(i,n){
			cin>>x>>y;
			pi.PB(MP(x,y));
		}
		long dx,dy;
		REP(i,n){
			dx=pi[i].first-pic[0].first,dy=pi[i].second-pic[0].second;
			bool c=true;
			FOR(j,1,m){
				bool c2=false;
				REP(k,n)if(pi[k].first==pic[j].first+dx&&pi[k].second==pic[j].second+dy){
					c2=true;
					break;
				}
				if(!c2){
					c=false;
					break;
				}
			}
			if(c)break;
		}
		cout<<dx<<" "<<dy<<endl;
	}
	return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    if (a == b && b != c) cout << "Yes" << endl;
    else if (b == c && b != a) cout << "Yes" << endl;
    else if (a == c && b != c) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;
const ll inf = 8e18;


int n, k;
int p[maxn];
ll c[maxn];

// -1,-2,10,10,-16 (we should end early)

ll solve(int start) {
    vector<ll> v;
    for (int x=p[start]; x!=start; x=p[x]) {
	v.push_back(c[x]);
    }
    v.push_back(c[start]);

    // watch(start);
    // for (int i: v) cout<<i<<",";
    // cout<<endl;
    
    int len = v.size();
    vector<ll> acc(len+1); //acc[i]: value after i moves
    for (int i=0; i<len; i++) {
	acc[i+1]=acc[i]+v[i];
    }
    ll res = -inf;

    // single loop
    for (int i=1; i<=min(k, len); i++) {
	res = max(res, acc[i]);
    }

    int loops = k/len;
    if (loops>0 && acc[len]>=0) {
	{
	    ll tail = 0;
	    for (int i=1; i<=(k-loops*len); i++) {
		tail = max(tail, acc[i]);
	    }
	    res = max(res, 1ll*loops*acc[len] + tail);
	}

	{
	    ll tail = 0;
	    for (int i=1; i<=min(len, k-(loops-1)*len); i++) {
		tail = max(tail, acc[i]);
	    }
	    res = max(res, 1ll*(loops-1)*acc[len] + tail);
	}
    }

    //cout<<start<<": "<<res<<endl;

    return res;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    
    cin>>n>>k;
    for (int i=1; i<=n; i++) {
	cin>>p[i];
    }
    for (int i=1; i<=n; i++) {
	cin>>c[i];
    }

    ll ans = -inf;
    for (int i=1; i<=n; i++) {
	ans = max(ans, solve(i));
    }


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


Measured memory_bytes: 3820
#include<bits/stdc++.h>
using namespace std;
int rd(char c[]){
  int i, sz=0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
char S[55], T[55];
int Slen, Tlen;
int main(){
  int i, j;
  Slen = rd(S);
  Tlen = rd(T);
  for(i=Slen-Tlen;i>=0;i--){
    for(j=0;j<Tlen;j++){
      if(S[i+j]!='?' && S[i+j]!=T[j]){
        break;
      }
    }
    if(j==Tlen){
      for(j=0;j<Tlen;j++){
        S[i+j] = T[j];
      }
      for(i=0;i<Slen;i++){
        if(S[i]=='?'){
          S[i] = 'a';
        }
      }
      wt_L(S);
      putchar_unlocked('\n');
      return 0;
    }
  }
  wt_L("UNRESTORABLE");
  putchar_unlocked('\n');
  return 0;
}
// cLay varsion 20171023-1 [beta]

// --- original code ---
// char S[55], T[55];
// int Slen, Tlen;
// 
// {
//   int i, j;
//   rd(S@Slen, T@Tlen);
//   for(i=Slen-Tlen;i>=0;i--){
//     rep(j,Tlen){
//       if(S[i+j]!='?' && S[i+j]!=T[j]) break;
//     }
//     if(j==Tlen){
//       rep(j,Tlen) S[i+j] = T[j];
//       rep(i,Slen) if(S[i]=='?') S[i] = 'a';
//       wt(S);
//       return 0;
//     }
//   }
//   wt("UNRESTORABLE");
// }


Measured memory_bytes: 256
import java.util.*;
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();
        if((c <= a && c >= b) || (c >= a && c <= b)) System.out.println("Yes");
        else System.out.println("No");
	}
}

Measured memory_bytes: 21204
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n = I()
print(n ** 3)

Measured memory_bytes: 39664
#include<iostream>
#include<string>
#include <cmath>
#include <algorithm>
#include <set>
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){

string s;
cin >> s;

int k;
cin >> k;

set<string> ss;      // 重複した要素を含まない、ソートされたリスト //

for(int j = 0; j < k; j++){
 for(int i = 0; i<s.length() - j; i++){
  ss.insert(s.substr(i,j+1));
 }
}

int _k = 0;
for(auto i : ss){
_k++;
if(_k == k){
 cout << i <<endl;
 return 0;
  }
 }
}

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

long long cnt;
int l;
int A[100000000];
int n;
vector<int> G;

//間隔gを指定した挿入ソート
void insertionSort(int A[], int n, int g) {
    for (int i=g; i<n; i++) {
        int v = A[i];
        int j = i - g;
        while(j >= 0 && A[j] > v) {
            A[j + g] = A[j];
            j -= g;
            cnt++;
        }
        A[j + g] = v;
    }
}

void shellSort(int A[], int n) {
    // 数列G = {1, 4, 13, 40, 121, 364, 1093, ・・・}　を生成
    for (int h=1; ; ) {
        if (h > n) break;
        G.push_back(h);
        h = 3*h + 1;
    }

    for (int i=G.size()-1; i>=0; i--) {
        //逆順にG[i] = gを指定
        insertionSort(A, n, G[i]);
    }
}

int main() {
    cin >> n;
    // より速い入力scanf関数を使用
    for (int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }
    cnt = 0;

    shellSort(A, n);

    cout << G.size() << endl;
    for (int i=G.size()-1; i>=0; i--) {
        printf("%d", G[i]);
        if (i) printf(" ");
    }
    printf("\n");
    printf("%d\n", cnt);
    for (int i=0; i<n; i++) printf("%d\n", A[i]);

    return 0;
}
    
 


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

int main() {
	long long a,b,n;
	cin>>n>>a>>b;
	
	long long ans=0;
	long long t=n/(a+b);
	ans+=t*a;
	n-=t*(a+b);
	ans+=min(n,a);
	cout<<ans<<endl;
	return 0;
}

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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

constexpr int MOD = 1000000007;

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

    string s, t;
    cin >> s >> t;

    vvi dp(s.size() + 1, vi(t.size() + 1, 0));

    rep(i, 0, s.size()) {
        rep(j, 0, t.size()) {
            if (s[i] == t[j]) {
                dp[i + 1][j + 1] = dp[i][j] + 1;
            } else {
                dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
            }
        }
    }

    string ans;
    int i = s.size(), j = t.size();
    while (i > 0 && j > 0) {
        int num = dp[i][j];
        if (num == 0) { break; }
        while (dp[i - 1][j] != num - 1) { --i; }
        while (dp[i][j - 1] != num - 1) { --j; }
        ans.push_back(s[i - 1]);
        --i;
        --j;
    }

    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 35584
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;

int main(){
	char s[20],t;
	for(int i=0;i<20;i++){
		s[i]=0;
	}
	gets(s);
	for(t=0;s[t]!=0;t++){
	}
	for(int i=0;i<t;i++){
		cout << s[t-i-1] ;
	}
	cout << "\n" ;
	
return 0;
}

Measured memory_bytes: 1088