akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

const int N = 2e5 + 1;
int n;
int h[N], a[N];
ll dp[N];
ll bit[N];

ll query(int idx) {
	ll ret = 0;
	while (idx > 0) {
		ret = max(ret, bit[idx]);
		idx -= idx & -idx;
	}
	return ret;
}

void update(int idx, ll val) {
	while (idx <= n) {
		bit[idx] = max(bit[idx], val);
		idx += idx & -idx;
	}
}

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);

	for (int i = 1; i <= n; i++) {
		dp[i] = query(h[i]) + a[i];
		update(h[i], dp[i]);
	}

	ll answer = 0;
	for (int i = 1; i <= n; i++) answer = max(answer, dp[i]);
	printf("%lld\n", answer);
}


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

using namespace std;

typedef long long ll;

ll N, p[5005], A, B, dp[5005][5005];
ll pos[5005];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> N >> A >> B;
	for (int i = 1; i <= N; ++i){
		cin >> p[i];
	}
	for (int i = 1; i <= N; ++i){
		pos[p[i]] = i;
	} 
	for (int i = 1; i <= N+1; ++i){
		if (i < pos[1]) dp[1][i] = B;
		else if (i > pos[1]) dp[1][i] = A;
		else dp[1][i] = 0;
	} 
	for (int i = 2; i <= N; ++i){
		deque<pair<ll,int> > f;
		for (int j = 1; j <= N+1; ++j){
			while (!f.empty() && f.back().first > dp[i-1][j]){
				f.pop_back();
			}
			f.push_back(make_pair(dp[i-1][j],j));
			if (j == pos[i]) dp[i][j] = dp[i-1][j];
			else dp[i][j] = 1e16;
			if (!f.empty()){
				if (j > pos[i]) dp[i][j] = min(dp[i][j],A+f.front().first);
				else if (j < pos[i]) dp[i][j] = min(dp[i][j],B+f.front().first);
				else dp[i][j] = min(dp[i][j],f.front().first);
			}
			
		}
	} 
	for (int i = 1; i <= N; ++i){
		for (int j = 1; j <= N+1; ++j){
			//cout << dp[i][j] << ' ';
		}
		//cout << '\n';
	} 
	ll M = 1e16;
	for (int i = 1; i <= N+1; ++i){
		M = min(M,dp[N][i]);
	}
	cout << M << '\n';
}

Measured memory_bytes: 195968
# ALDS1_8_B Binary Search Tree II
import sys

# ALDS1_8_A Binary Search Tree 1
import sys


class Node:
    def __init__(self, x):
        self.parent = None
        self.left = None
        self.right = None
        self.key = x


class Tree:
    def __init__(self):
        self.root = None

    def insert(self, x):
        new = Node(x)
        x_parent = self.root
        next = self.root

        while next is not None:
            x_parent = next
            if x < x_parent.key:
                next = x_parent.left
            else:
                next = x_parent.right

        if x_parent is None:
            self.root = new
        elif x < x_parent.key:
            new.parent = x_parent
            x_parent.left = new
        else:
            new.parent = x_parent
            x_parent.right = new
        return

    def preorder(self, node):
        print(' {}'.format(node.key), end='')

        if node.left:
            self.preorder(node.left)
        if node.right:
            self.preorder(node.right)
        return

    def inorder(self, node):
        if node.left:
            self.inorder(node.left)

        print(' {}'.format(node.key), end='')

        if node.right:
            self.inorder(node.right)

    def find(self, num, node):
        if num < node.key:
            if node.left:
                self.find(num, node.left)
            else:
                print('no')
        elif num > node.key:
            if node.right:
                self.find(num, node.right)
            else:
                print('no')
        else:
            print('yes')
            return


m = int(input())
tree = Tree()

for i in range(m):
    command = list(sys.stdin.readline().strip().split())
    if command[0] == 'print':
        tree.inorder(tree.root)
        print()
        tree.preorder(tree.root)
        print()
    else:
        num = command[1]
        command = command[0]
        num = int(num)
        if command == 'insert':
            tree.insert(num)
        else:
            tree.find(num, tree.root)



Measured memory_bytes: 85744
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++) 
#define ALL(n) (n).begin,(n).end
/*???????±±?????????3?????????*/
int main()
{
    vector<int> vc;
    int N;
    while( cin >> N )
    {
        vc.push_back( N );
    }
    sort( vc.begin(), vc.end(), greater<int>() );
    REP( i, 3 )
    {
        cout << vc[ i ] << endl;
    }
    return 0;
}

Measured memory_bytes: 3140
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();
			// 文字列の入力
			if(a*b%2==0){
				System.out.println("Even");
			}else {
				System.out.println("Odd");
			}
		}
	}	

Measured memory_bytes: 20556
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define RG register
#define ll long long
using namespace std;
const int N=102;
struct node{
	int x,y; ll h;
}pt[N];
int n;
inline ll abss(ll x){return x>0 ? x : -x;}
inline ll read(){
	char ch=getchar(); ll x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;}
inline bool cmp(node a,node b){return a.h>b.h;}
int main()
{
//	freopen("Pyramid.in","r",stdin);
//	freopen(".out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++)
	{
		pt[i]=(node){read(),read(),read()};
	}
	sort(pt+1,pt+1+n,cmp);
	for(int i=0;i<=100;i++)
	{
		for(int j=0;j<=100;j++)
		{
			int flg=0;
			ll tt=abss(i-pt[1].x)+abss(j-pt[1].y)+pt[1].h;
			for(int k=2;k<=n;k++)
			{
				ll re=abss(i-pt[k].x)+abss(j-pt[k].y)+pt[k].h;
				if(pt[k].h==0)
				{
					if(tt>re-pt[k].h)
					{
						flg=1;
						break;
					}
					continue;
				}
				if(re!=tt)
				{
					flg=1;
					break;
				}
			}
			if(!flg) 
			{
				printf("%d %d %lld\n",i,j,tt);
				return 0;
			}
		}
	}
//	fclose(stdin); fclose(stdout);
	return 0;
}


Measured memory_bytes: 256
X, K, D = map(int, input().split())

X = abs(X)
reach_or_before = X // D


if K <= reach_or_before:
    print(X - D * K)
else:
    #remaining jump
    remain = K - reach_or_before
    before_dist = X % D #(>0)
    after_dist = D - before_dist
    if remain % 2 == 0:
        print(before_dist)
    else:
        print(after_dist)


Measured memory_bytes: 9040
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll N, K, T, W, H, M, C;

const int MAX = 5100000;
const ll MOD = 1e9 + 7;

const double PI=3.14159265358979323846;


long long fac[MAX], finv[MAX], inv[MAX];

vector<double> cx, cy, c;
 ll MM = 1e12;

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

std::vector<int> Eratosthenes(int n ){
    std::vector<bool> is_prime( n + 1 );
    for( int i = 0; i <= n; i++ ) is_prime[ i ] = true;
    std::vector<int> P;
    for( int i = 2; i <= n; i++ ){
        if( is_prime[ i ] ){
            for( int j = 2 * i; j <= n; j += i ){
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
    return P;
}

ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

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

  /*
int main(){
    string str;
    cin >> str;
    N = str.size();
    int sub = 0;
    int p10 = 1;
    vector<int> v(2019, 0);
    for(int i = N-1; i >= 0; --i){
        sub = (sub + (str[i] - '0')*p10) % 2019;
        ++v[sub];
        p10 = (p10 * 10) % 2019;
    }
    ll ans = 0;
    for(auto u:v) ans += u*(u-1)/2;
    if(v[0] == 1) ++ans;
    cout << ans;
    return 0;
}
*/
int main(){
    int a,b,c,d;
    cin >> a >> b>> c >> d;
    int parity = 0;
    while(b > 0 and c>0){
        if(parity == 0) c-=b;
        else a -=d;
        ++parity; parity %= 2;
    }
    if(a <= 0) cout << "No";
    else cout << "Yes";
    return 0; 
}

Measured memory_bytes: 3624
#include <iostream>
#define int long long
using namespace std;

int dp[1 << 12];

signed main(){
	int m,w;
	while(cin >> m >> w,m){
		int a[12],b[12];
		for(int i = 0;i < m;i++) cin >> a[i];
		for(int i = 0;i < w;i++) cin >> b[i];
		if(m > w){
			for(int i = 0;i < 12;i++) swap(a[i],b[i]);
			swap(m,w);
		}
		for(int i = 0;i < (1 << w);i++) dp[i] = 0;
		for(int i = 0;i < (1 << w);i++){
			int cnt = 0;
			for(int j = 0;j < w;j++) if(i >> j & 1) cnt++;
			if(cnt >= m) continue;
			for(int j = 0;j < w;j++){
				if(i >> j & 1) continue;
				dp[i | (1 << j)] = max(dp[i | (1 << j)],dp[i] + abs(a[cnt] - b[j]) * (abs(a[cnt] - b[j]) - 30) * (abs(a[cnt] - b[j]) - 30));
			}
		}
		int ma = 0;
		for(int i = 0;i < (1 << w);i++) ma = max(ma,dp[i]);
		cout << ma << endl;
	}
	return 0;
}

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

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


typedef long long ll;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;

int main() {
    vi primes;
    bool is_prime;
    unordered_map<int,int> found_prime;
    bool pairwise{true}, setwiset{true};

    rep(i, 2, 1000) {
        is_prime = true;
        for(int p:primes) {
            if (i%p==0) {
                is_prime = false;
                break;
            }
        }
        if (is_prime) primes.push_back(i);
    }
    
    int N,a;
    vi arr;
    cin >> N;

    rep(i,1,N) {
        cin >> a;
        arr.push_back(a);
    }
    int pr;
    rrep(i,N-1,0) {
        for(int j=0; j<primes.size(); j++)  {
            pr = primes[j];
            if (arr[i]%pr==0) {
                while (arr[i]%pr==0){
                    arr[i]/=pr;
                }
                found_prime[pr]++;
                if (found_prime[pr] > 1) pairwise = false;
                if (found_prime[pr] == N) setwiset = false;
            }
            if (arr[i]==1) break;
        }
        if (arr[i]!=1) {
            found_prime[arr[i]]++;
            if (found_prime[arr[i]] > 1) pairwise = false;
            if (found_prime[arr[i]] == N) setwiset = false;
        }
    }

    if (pairwise) cout << "pairwise coprime";
    else if (setwiset) cout << "setwise coprime";
    else cout << "not coprime";

    return 0;
}


Measured memory_bytes: 10464
#!/usr/bin/env python3
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    N = int(readline())
    S = readline().rstrip().decode()
    ans = 0
    for i in range(N - 2):
        if S[i:i+3] == 'ABC':
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
n = gets.chomp.to_i
arr = gets.chomp.split.map { |i| i.to_i }

if n.odd? && (arr.count(0) != 1)
  puts 0
  exit
end

if n.even? && (arr.count(0) >= 1 )
  puts 0
  exit
end

unless arr.uniq.count == (n.to_f / 2).ceil
  puts 0
  exit
end

puts (2 ** (n / 2)) % (10 ** 9 + 7)

Measured memory_bytes: 13196
#include<bits/stdc++.h>
#include<boost/lambda/lambda.hpp>
using namespace std;

int main(){
    int n,m;
    while(cin>>n>>m,n){
        vector<int> s(m);
        vector<int> k(m);
        vector<vector<int>> c(m);
        for(int i=0;i<m;i++){
            cin>>s[i]>>k[i];            
            c[i].assign(k[i],0);
            for(int j=0;j<k[i];j++){
                cin>>c[i][j];
                c[i][j]--;
            }
        }
        vector<pair<int,int>> bsc(n);
        for(int i=0;i<n;i++) bsc[i].first=0,bsc[i].second=i;
        for(int i=0;i<m;i++){
            if(k[i]==1) bsc[c[i][0]].first+=s[i];
        }
        vector<int> gsc(n);
        for(int i=0;i<m;i++){
            for(int j=0;j<k[i];j++){
                gsc[c[i][j]]+=s[i];
            }
        }
        sort(bsc.begin(),bsc.end());
        int res=0;
        for(int i=0;i<n;i++){            
            if(bsc[0].second==i){
                res=max(res,gsc[i]-bsc[1].first+1);
            }
            else{
                res=max(res,gsc[i]-bsc[0].first+1);
            }
        }
        cout<<res<<endl;
    }
    return 0;
}



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

int a[100005];

int main()
{
  int n, sum=0;
  scanf("%d",&n);
  for(int i=1;i<=n;i++) {
    scanf("%d",a+i);
    sum += abs(a[i]-a[i-1]);
  }
  sum += abs(a[n]);
  for(int i=1;i<=n;i++) {
    printf("%d\n",sum - abs(a[i]-a[i-1]) - abs(a[i]-a[i+1]) + abs(a[i+1]-a[i-1]));
  }
}


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

namespace Cs
{

    class hutatu
    {
        int a, b = 0;
        public hutatu(int a,int b)
        {
            this.a = a;this.b = b;
        }
        public bool doti(int c)
        {
            return a == c || b == c;
        }
        public int gyaku(int c)
        {
            if (a == c) { return b; }
            if (b == c) { return a; }
            return -1;
                    }
    }
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine().Split(' ');
            int n = int.Parse(str[0]);
            int m = int.Parse(str[1]);
            List<hutatu> ab = new List<hutatu>();

            int[] dye = new int[n];
            for (int i = 0; i < m; i++)
            {
                var str2 = Console.ReadLine().Split(' ');
                ab.Add(new hutatu(int.Parse(str2[0]), int.Parse(str2[1])));
            }
            Console.WriteLine(mycheck(1, dye, ab));

        }

        static int mycheck(int me, int[] die,List<hutatu>newab)
        {
            die[me-1] = 1;
            if (die.All(c => c == 1)) { return 1; }
            int count = 0;
            List<hutatu> ne = newab.ToList();
            ne.RemoveAll(c => c.doti(me));
            bool botti = true;
            for (int i = 0; i < newab.Count; i++)
            {
                int k = newab[i].gyaku(me);
                if (k == -1) { continue; }
                botti = false;
                count += mycheck(k, die.ToArray(), ne);
            }
            if (botti) { return 0; }
            return count;
        }


    }
}


Measured memory_bytes: 15316
PROGRAM Vacation
      IMPLICIT NONE
      integer :: n
      integer,allocatable :: abcTable(:,:)
      integer :: day,Yday,Today
      integer,allocatable :: dp(:,:)
      
      read*,n
      allocate(abcTable(n,3),dp(0:n,3) )
      do day = 1,n
        read*,abcTable(day,:)
      end do
      
      dp = 0
      !dp(day,abc)当日に行動abcをとった場合のday(終了時)での最大値
      
      !abcHielaux,abcHodiaux
      do day = 1,n
        do Today = 1,3
          do Yday = 1,3
            if( Today==Yday )cycle
            dp(day,Today) = max( dp(day,Today), &
              &dp(day-1,Yday)+abcTable(day,Today) )
          end do
        end do
      end do
      
      print*,maxval(dp(n,:))
      
      
      END PROGRAM

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
int32_t main(){
	if(fopen("input.txt", "r"))
	freopen("input.txt", "r", stdin),
	freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0),cin.tie(0);
	int n,m;
	cin >> n >> m;
	cout << n*(n-1)/2+m*(m-1)/2;
}

Measured memory_bytes: 256
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <iomanip>
#include <cmath>
#include <ctgmath>
#include <math.h>
#include <cassert>
#include <chrono>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define GFOR(i,a,n) for (i=a;i<n;i++)
#define FOR(i,a,n) for (int i=a;i<n;i++)
#define RFOR(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<long long int> vll;
typedef vector<pair<int, int> > vpi;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head

void solve() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(max(a*c, a*d), max(b*c, b*d)) << "\n";
}

int main() {
    #ifdef LOCAL
    auto t1 = std::chrono::high_resolution_clock::now();
    #endif

    io;
    solve();

    #ifdef LOCAL
    auto t2 = std::chrono::high_resolution_clock::now();
    auto duration = std::chrono::duration_cast<std::chrono::milliseconds>( t2 - t1 ).count();

    std::cout << "Time Taken: " << duration << "\n";
    #endif

}
// check for edge cases in limits
// printing double may print 1.223232e9 like values, beware of that
// carefully observe simulation of test cases
// multiset erase is does not do what it is supposed to


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

const int N = 2e5 + 10;

char s[N], t[N];
int n;

bool check(int len, int p, char sub, char add){
	int l = 1, r = len;
	for (int i = n; i >= 1; i--){
		if (t[i] == add) l = max(l - 1, 1);
		else if (t[i] == sub) r = min(r + 1, len);
		if (s[i] == add) r--;
		else if (s[i] == sub) l++;
		if (l > r) return false;
	}
	return p >= l && p <= r;
}

int main(){
	int h, w, x, y;
	scanf("%d %d %d",&h,&w,&n);
	scanf("%d %d",&x,&y);
	scanf("%s", s + 1);
	scanf("%s", t + 1);
	if (check(h, x, 'U', 'D') && check(w, y, 'L', 'R')) printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 640
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n, a, b int
	var users string
	fmt.Scan(&n, &a, &b, &users)
	totalPass := a + b
	var passedNum int
	curForeignStudentRank := 1
	for _, u := range strings.Split(users, "") {
		if u == "a" {
			if passedNum < totalPass {
				fmt.Println("Yes")
				passedNum++
				continue
			}
		}
		if u == "b" {
			if passedNum < totalPass && curForeignStudentRank <= b {
				fmt.Println("Yes")
				passedNum++
				curForeignStudentRank++
				continue
			}
		}
		fmt.Println("No")
	}
}


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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
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 dy[]={0, 0, 1, -1, 1, -1, -1, 1};
int dx[]={1, -1, 0, 0, 1, 1, -1, -1};


int main() {
    cout<<fixed<<setprecision(10);

    ll n; cin>>n;

    vint b(n),c(n);
    vint idx(n); rep(i,n) idx[i] = i;

    rep(i,n){
        string s; cin>>s;
        b[i] = 0;
        ll cnt = 0;
        for(auto e:s){
            if(e == '(') cnt++;
            else cnt--;
            chmin(b[i], cnt);
        }
        c[i] = cnt;
    }

    sort(ALL(idx), [&](const ll l, const ll r){
        if((c[r])*(c[l])<=0){
            return c[l] > c[r];
        }else{
            if(c[l] > 0){
                return b[l] > b[r];
            }else{
                return c[l] - b[l] > c[r] - b[r];
            }
        }
    });

    ll x = 0;
    for(auto i:idx){
        if(x + b[i] < 0){ puts("No"); return 0; }
        x += c[i];
    }
    if(x == 0) puts("Yes");
    else puts("No");


    return 0;

}

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

int main(){
  string s,t;
  cin >> s >> t;
  if(s[0] == t[2]){
    if(s[1] == t[1]){
      if(s[2] == t[0]){
        puts("YES");
        return 0;
      }
    }
  }
  puts("NO");
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<map>
using namespace std;

#define PB push_back
#define MP make_pair

void Input(int*,int*,queue<pair<string,int> >&);
void Calc(int*,int*,queue<pair<string,int> >&);

int main(int argc,char* argv[]){
  queue<pair<string,int> > qpair;
  int n,q;

  Input(&n,&q,qpair);
  Calc(&n,&q,qpair);

  return 0;
}

void Input(int *pn,int *pq,queue<pair<string,int> >&qpair){
  pair<string,int> tmp;

  cin>>*pn>>*pq;

  for(int i=0;i<*pn;i++){
    cin>>tmp.first>>tmp.second;
    qpair.push(tmp);
  }
}

void Calc(int *pn,int *pq,queue<pair<string,int> > &qpair){
  pair<string,int> tmp;
  double time=0;

  while(!qpair.empty()){
    tmp=qpair.front();qpair.pop();

    if(tmp.second<=*pq){
      time+=tmp.second;
      cout<<tmp.first<<" "<<static_cast<int>(time)<<endl;
    }
    else{
      time+=*pq;
      tmp.second-=*pq;
      qpair.push(tmp);
    }
  }
}

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

int main() {
	string s;
	while (getline(cin, s)) {
		
		int x = 1;
		for (unsigned i = 0; i < s.size(); i++) {
			if (s[i] == '@') {
				x = s[i + 1] - '0';
				i++;
			}
			else {
				cout << string(x, s[i]);
				x = 1;
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int a, b;
    cin >> a >> b;
    if (a + b >= 10)
        cout << "error" << endl;
    else
        cout << a + b << endl;
}

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

using namespace std;

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define FOR(i,m,n) for(int i=(m) ; i<(n) ; i++)
#define FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)

#define All(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1e9;

int main(){
   int h,w;
   cin >> h >> w;
   string s[h];
   rep(i,h)cin >> s[i];
   int x[] = {1,1,0,-1,-1,-1,0,1};
   int y[] = {0,1,1,1,0,-1,-1,-1};
   rep(i,h){
      rep(j,w){
         if(s[i][j] == '#')continue;
         int cnt = 0;
         rep(k,8){
            int xa = j + x[k];
            int ya = i + y[k];
            if(xa >= w || xa < 0)continue;
            if(ya >= h || ya < 0)continue;
            if(s[ya][xa] == '#')cnt++;
         }
         s[i][j] = char('0' + cnt);
      }
   }
   rep(i,h)cout << s[i] << endl;
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-3223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int main() {
	iostream::sync_with_stdio(false);

while(true){

	int n,m;
	cin >> n >> m;
	if(n == 0 && m == 0) return 0;
	vector<pair<int,int> > all;
	for(int i=0; i<m; i++) all.push_back(MP(0, i+1));
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			int tmp;
			cin >> tmp;
			if(tmp == 1) all[j].first--;
		}
	}
	sort(all.begin(), all.end());
	for(int i=0; i<m; i++) cout << (i==0?"":" ") << all[i].second;
	cout << endl;

}

	return 0;
}



Measured memory_bytes: 3176
#include<stdio.h>

int main(void){
    int N;
    //数の上限
    scanf("%d",&N);
    int num[N];
    for(int i = 0;i < N;i++){
        scanf("%d",&num[i]);
    }
    int minv = num[0];
    int maxv = num[1] - num[0];
    for(int j = 1;j < N;j++){
      maxv = maxv > (num[j] - minv)?maxv:num[j] - minv;
      minv = minv < num[j]?minv:num[j];
    }
    printf("%d\n",maxv);
}



Measured memory_bytes: 3516
#include <stdio.h>
int main(){
    int i,j;
    int tmp=0;
    char str[26];

    scanf("%s",str);
    for(i=0; i<strlen(str); i++){
        for(j=i+1; j<strlen(str); j++){
            if(str[i] == str[j]){
                tmp = 1;
            }
        }
    }
    if(tmp == 1){
        printf("no\n");
    }else if(tmp == 0){
        printf("yes\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
using namespace std; //std::の省略のため
using ll = long long;

ll MOD = 1000000007;

ll m;
string s;

int solve(ll n)
{
    ll count = 0;
    for (ll i = n; i < m; i++)
    {
        if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T')
        {
            count++;
        }
        else
        {
            break;
        }
    }

    return count;
}

int main()
{

    cin >> s;

    m = s.size();

    ll ans = 0, tmp = 0;

    for (ll i = 0; i <= m; i++)
    {
        tmp = solve(i);
        if (tmp > ans)
        {
            ans = tmp;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3640
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define p(p) cout<<(p)<<" ";
#define pb push_back
#define mp make_pair
#define INF 1e18

typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pi;

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

int N,M,l,r;
vi a,b,c,d;
vvi F;
vvi R;
void input(){
	cin>>N;
	F.resize(N+1);
	R.resize(N+1);
	rep(i,N){
		rep(j,10){
			int t;
			cin>>t;
			F[i].pb(t);
		}
	}
	rep(i,N){
		rep(j,11){
			int t;
			cin>>t;
			R[i].pb(t);
		}
	}

}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	input();
	vi v;
	int ans=-INF;
	REP(i,1,1<<10){
		int tmp=0;
		vi open(10,0);
		rep(j,10){
			open[j]=(i>>j)&1;
		}
		rep(j,N){
			int cnt=0;
			rep(k,10){
				if(F[j][k]==1&&open[k]==1){
					cnt++;	
				};
			}
			tmp+=R[j][cnt];
		}
		ans=max(ans,tmp);
	}
	P(ans)
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int h, w, i, j;
	scanf("%d%d", &h, &w);
	char s[h][w];
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			scanf("%c", &s[i][j]);
			if(s[i][j]=='.')s[i][j]='0';
			if(s[i][j]=='\n')j--;
		}
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(s[i][j]=='#'){
				for(int k=-1;k<2;k++){
					for(int l=-1;l<2;l++){
						if(i+k<0 || i+k>=h || j+l<0 || j+l>=w || s[i+k][j+l]=='#')continue;
						s[i+k][j+l]+=1;
					}
				}
			}
		}
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++)printf("%c", s[i][j]);
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
    using namespace std;
    typedef long long int ll ;
     
    #define pb     push_back
    #define mp     make_pair
    #define all(v) v.begin() , v.end()
    #define allr(v) v.rbegin(), v.rend()
    const ll INF =  0x3f3f3f3f3f3f3f3f;
    const int inf = 0x3f3f3f3f;
    const int MOD = 1e9+7;
    const int MAX = 1e5+5;
     
    int r, c;
    char ch;
    int cnt[30];
     
    int main(int argc, char const *argv[])
    {
      scanf("%d %d" , &r, &c);
      for(int i = 0 ; i < r ; i++){
      	for(int j = 0 ; j < c ; j++){
      		scanf(" %c" , &ch);
      		cnt[ch-'a']++;
      	}
      }
     
      int f, t, o;
      f = t = o = 0;
     
      for(int i = 0 ; i < 26 ; i++){
      	f += (cnt[i]/4);
      	cnt[i] = cnt[i]%4;
      	t += (cnt[i]/2);
      	cnt[i] = cnt[i]%2;
      	o += cnt[i];
      }
     
      if((r%2 == 0) && (c%2 == 0)){
      	if(4*f == r*c)
      		printf("Yes");
      	else
      		printf("No");
      }
      else if((r%2 == 0) && (c%2 == 1)){
      	if((o == 0) && (4*f >= r*c - r) && (4*f + 2*t == r*c))
      		printf("Yes");
      	else
      		printf("No");
      }
      else if((r%2 == 1) && (c%2 == 0)){
      	if((o == 0) && (4*f >= r*c - c) && (4*f + 2*t == r*c))
      		printf("Yes");
      	else
      		printf("No");
      }
      else{
      	if((4*f >= (r*c - r - c - 1)) && (o == 1) && (4*f + 2*t + o == r*c) )
      		printf("Yes");
      	else
      		printf("No");
      }
     
      return 0;
    }  

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

int main() {
    
    int N;
    cin >> N;
    
    vector<pair<int, int>> A(N);
    for (int i = 0, a; cin >> a; i++) A.at(i) = {a, i + 1};
    
    sort(A.begin(), A.end());
    
    for (auto a : A) cout << a.second << endl;
    
}

Measured memory_bytes: 1664
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.traits;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    auto as = readln.split.to!(long[]);
    auto G = new int[][N];
    foreach (_; 0..M) {
        auto xy = readln.split.to!(int[]);
        auto x = xy[0];
        auto y = xy[1];
        G[x] ~= y;
        G[y] ~= x;
    }
    auto F = new bool[](N);
    long[][] xs;
    foreach (i; 0..N) {
        if (F[i]) continue;
        F[i] = true;
        xs ~= [as[i]];
        void walk(int i) {
            foreach (j; G[i]) if (!F[j]) {
                xs[$-1] ~= as[j];
                F[j] = true;
                walk(j);
            }
        }
        walk(i);
    }
    auto len = xs.length;
    if (len == 1) {
        writeln(0);
        return;
    }
    long r;
    auto Q = heapify!"a > b"([long.max]);
    foreach (ref x; xs) {
        sort(x);
        r += x[0];
        foreach (a; x[1..$]) Q.insert(a);
    }
    foreach (_; 0..(len-1)*2 - len) {
        if (Q.front == long.max) {
            writeln("Impossible");
            return;
        }
        r += Q.front;
        Q.removeFront();
    }
    writeln(r);
}

Measured memory_bytes: 21096
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int[] a = new int[s.length()];
		for(int i = 0; i < s.length(); i++) {
			a[i] = 0;
		}
		int ini = 0;
		int r = 0;
		boolean change = false;
		for(int i = 0; i < s.length(); i++) {
			char masu = s.charAt(i);
			if(masu == 'L' && !change && i != s.length() - 1) {
				r = i - 1;
				change = true;
			} else if((masu == 'R' && change) || i == s.length() - 1) {
				if(!change) {
					r = i - 1;
				}
				int even = r - ini;
				if(even % 2 == 0) {
					even++;
					a[r] += even / 2 + 1;
					a[r + 1] += even / 2;
				} else {
					even++;
					a[r] += even / 2;
					a[r + 1] += even / 2;
				}
				if(i == s.length() - 1)
					even = i - (r + 1);
				else
					even = i - 1 - (r + 1);
				if(even % 2 == 0) {
					even++;
					a[r] += even / 2;
					a[r + 1] += even / 2 + 1;
				} else {
					even++;
					a[r] += even / 2;
					a[r + 1] += even / 2;
				}
				ini = i;
				change = false;
			}
		}
		for(int i = 0; i < s.length(); i++) {
			System.out.print(a[i] + " ");
		}
		System.out.println();
	}

}


Measured memory_bytes: 46140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


int main(){
    ll n,m;
    cin >> n >> m;
    map<ll,ll> mp;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        mp[a[i]] += 1;
    }
    for(int i = 0; i < m; i++){
        ll b,c;
        cin >> b >> c;
        mp[c] += b;
    }
    ll ans = 0;
    for(auto itr = mp.rbegin(); itr != mp.rend(); ++itr){
        if((itr->second) <= n){
            ans += (itr->first)*(itr->second);
        }else{
            ans += (itr->first)*n;
            break;
        }
        n -= itr->second;
    }

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


Measured memory_bytes: 13568
import java.util.*;
import java.io.*;

public class Main {
	static int n;
	static int a;
	static int b;
	static int c;
	static int[] l;
	private static void solve(){
	//Implement solution here.
		n = ni();
		a = ni();
		b = ni();
		c = ni();
		l = new int[n];
		for(int i = 0; i<n; i++)l[i] = ni();		
		System.out.println(dfs(0,0,0,0));
	}

	private static int dfs(int cur, int ta, int tb, int tc) {
		if(cur == n) {
			if(ta <= 0 || tb <= 0 || tc <= 0) {
				return Integer.MAX_VALUE - 10;
			}else {
				return Math.abs(ta -a) + Math.abs(tb -b) + Math.abs(tc - c) - 30;
			}			
		}else {
			int ret0 = dfs(cur + 1, ta, tb, tc);//Don't use l[n]
			int ret1 = dfs(cur + 1, ta + l[cur], tb, tc) + 10;//Use l[n] to A
			int ret2 = dfs(cur + 1, ta, tb + l[cur], tc) + 10;//Use l[n] to B
			int ret3 = dfs(cur + 1, ta, tb, tc + l[cur]) + 10;//Use l[n] to C
			return Math.min(Math.min(ret0, ret1),Math.min(ret2, ret3));
		}
	}
    //Switch input source (stdin/file)
	private static Scanner scanner = new Scanner(System.in);
	public static void main(String[] args){
        String debugDataPath = System.getenv("DD_PATH");        
        if(debugDataPath != null){
            try{
                scanner = new Scanner(new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath)))));
            }catch(Exception e){
                throw new RuntimeException(e);
            }
        }
        solve();
	}

    //Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(scanner.nextLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
    //Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
    //Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
    //Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
    //Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
    //Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

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

const int MOD=1e9+7;
int n,ans;
int C[2005][2005];

int main(){
	C[0][0]=1;
	for(int i=1;i<=2000;i++) for(int j=0;j<=i;j++){
		if(j==0||j==i) C[i][j]=1;
		else C[i][j]=(1ll*C[i-1][j]+C[i-1][j-1])%MOD;
	}
	scanf("%d",&n);
	for(int i=1;i*3<=n;i++) ans=(1ll*ans+C[n-i*2-1][i-1])%MOD;
	printf("%d\n",ans);
	return 0;
}

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

using ll = long long;
typedef unsigned long long ull;
typedef std::pair<int, int>p;

ll min(ll a, ll b) {
	if (a >= b)return b;
	else return a;
}
ll max(ll a, ll b) {
	if (a >= b)return a;
	else return b;
}
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;
}

const ll Z = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
const ull INF3 = 18000000000000000000LL;
bool flag = true;
bool fl = false;
bool f = false;
bool used[210];
bool graph[100][100];
bool visited[8];
int abc[26] = { 0 };

int main() {
	ll n, k, a[100000];
	std::cin >> n >> k;
	ll s = 0;
	for (int i = 0;i < n;i++) {
		std::cin >> a[i];
		if (a[i] > s)s = a[i];
	}
	ll t = a[0];
	for (int i = 0;i < n - 1;i++) {
		t = gcd(t, a[i + 1]);
	}
	if (k <= s&&k%t == 0)std::cout << "POSSIBLE" << std::endl;
	else std::cout << "IMPOSSIBLE" << std::endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include<algorithm>
#include <stdio.h>
#include <string>
#include <string.h>
#include <map>
#include <math.h>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <deque>
//#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
const int N=1e5+7;
int main()
{
    char ch[10];
    cin>>ch;
    map<int,int>mp;
    int ans=0;
    for(int i=0;i<4;i++)
    {
        mp[ch[i]]++;
    }
    int f=1;
   for(int i=65;i<=90;i++)
   {
       if(mp[i]!=0)
       {
           ans++;
           if(mp[i]!=2)
           {
               f=0;
               break;
           }
       }
   }
   if(f==0||ans!=2)
       cout<<"No"<<endl;
   else
       cout<<"Yes"<<endl;
    return 0;
}

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

// #define pr16 

#ifdef pr16
  #define pr(x)                 cerr << #x << ": " << x << endl;
  #define pr2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
  #define pr3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
  #define pr4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
  #define pr5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
  #define pr6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
  #define prdd(a,r,c) for(long long i=0;i<(r);i++) { for(long long j = 0;j<(c);j++) cerr<<a[i][j]<<" "; cerr<<endl; } cerr<<endl;
  #define prc(a) tr(a, it) cerr<<*(it)<<" "; cerr<<endl
  #define pra(a,n) for(long long i=0; i<(n); i++) cerr<<((a)[i])<<" "; cerr<<"\n"
  #define prdd(a,r,c) for(long long i=0;i<(r);i++) { for(long long j = 0;j<(c);j++) cerr<<a[i][j]<<" "; cerr<<endl; } cerr<<endl; 
  #define prddd(a,x,y,z) for(long long i=0;i<x;i++) {cerr<<"layer "<<i<<":\n";prdd(a[i],y,z)}
 
#else
  #define pr(x)
  #define pr2(x, y)
  #define pr3(x, y, z)
  #define pr4(a, b, c, d)
  #define pr5(a, b, c, d, e)
  #define pr6(a, b, c, d, e, f)
  #define prc(a)
  #define pra(a,n)
  #define prdd(a, r, c)
  #define prddd(a,x,y,z)
#endif

long long  get(std::vector<long long> v, long long k) {
  if(v.size() == 0)
    return 0;


  long long ans = 0;
  long long sm = 0;
  long long n = v.size();
  for(long long i = 0; i < n; i++)
    sm += v[i];
  for(long long i = 0; i < n; i++)
    v.push_back(v[i]);
  
  for(long long i = 0; i < n; i++)
    v.push_back(v[i]);
  long long cnt = max(0LL, k / n-1);

  if (sm > 0)
    ans += 1LL * sm * cnt;
  k -= cnt*n;

  long long tmp = 0, mx = 0;
for(int i = 0; i <2* n; i++)
  pr2(v[i],k); 
  for(int i = 0; i < n; i++) {
    tmp = 0;
    for (int j = 0; j < k; j++)
      tmp += v[i+j], mx = max(mx, tmp);

  }
  return ans + mx;
}

int main()
{
  long long n,k;
  cin>>n>>k;
  long long p[n],c[n];
  long long mx = -1e9-100;
  for(long long i = 0; i < n; i++)
    cin >> p[i], p[i]--;
  for(long long i = 0; i < n; i++)
    cin >> c[i], mx = max(mx, c[i]);

  vector<long long> v[n];

  for(long long i = 0; i < n; i++) {
    if (p[i] == -1)
      continue;
    long long idx = i;
    while(p[idx] != -1)
    {
      v[i].push_back(c[idx]);
      long long tmp = idx;
      idx = p[idx];
      p[tmp] = -1;
    }
  }

  long long ans = 0;

  for(long long i = 0; i < n; i++) 
    ans = max(ans, get(v[i], 1LL* k));

  if (ans == 0)
    ans = mx; 

  cout<<ans;
}

Measured memory_bytes: 3996
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
    /*
    a1         a2=c22-c12+a1 a3=c33-c13+a1
    b1=c11-a11 b2=c12-a1     b3=c13-a1

    c11             c12             c13
    c21=c22+c11-c12 c22             c23=c22+c13-c12
    c31=c33+c11-c13 c32=c33+c12-c13 c33
    */
    ll c[3][3]; REP(i, 3)REP(j, 3)c[i][j] = in();
    cout << (
        c[1][0] == c[1][1] + c[0][0] - c[0][1] &&
        c[1][2] == c[1][1] + c[0][2] - c[0][1] &&
        c[2][0] == c[2][2] + c[0][0] - c[0][2] &&
        c[2][1] == c[2][2] + c[0][1] - c[0][2]
        ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
S=input()
Sl=list(S)
if Sl[0] == Sl[1] == Sl[2] == "R":
    print("3")
elif Sl[0] == Sl[1] == "R":
    print("2")
elif Sl[1] == Sl[2] == "R":
    print("2")
elif Sl[0] == Sl[1] == Sl[2] == "S":
    print("0")
else:
    print("1")

Measured memory_bytes: 9060
#include <stdio.h>

typedef struct {
	int parent;
	int left, right;
}Node;

int linear_search(int* xs, int size, int x)
{
	int i;
	for (i = 0; i < size; i++) {
		if (xs[i] == x) {
			return i;
		}
	}
	return -1;
}

Node tree[50];

int prewalked[50];
int inwalked[50];

int n;

int reconstruction_tree(int from, int to, int root_pos, int parent)
{
	int i;
	int v;

	for (i = from; i < to; i++) {
		if ((v = inwalked[i]) == prewalked[root_pos]) {
			tree[v].parent = parent;

			tree[v].left = reconstruction_tree(from, i, root_pos + 1, v);
			tree[v].right = reconstruction_tree(i+1, to, root_pos +  (i - from) + 1, v);

			return v;
		}
	}

	return -1;
}

int result[50];
int resultcnt;

void postorder_walk(int p)
{
	if (p > n || p < 0) {
		return;
	}
	postorder_walk(tree[p].left);
	postorder_walk(tree[p].right);

	result[resultcnt++] = p;
}

int main()
{
	int i;
	int root;

	for (i = 0; i < 50; i++) {
		tree[i].parent = -1;
	}

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%d", &(prewalked[i]));
	}
	for (i = 0; i < n; i++) {
		scanf("%d", &(inwalked[i]));
	}

	root = reconstruction_tree(0, n, 0, -1);

	postorder_walk(root);

	for (i = 0; i < resultcnt; i++) {
		if (i == 0) {
			printf("%d", result[i]);
		}
		else {
			printf(" %d", result[i]);
		}
	}

	printf("\n");

	return 0;
}

Measured memory_bytes: 600
n = int(input())
List = []
for i in range(n):
    sp = list(map(str, input().split()))
    sp[1] = int(sp[1])
    sp.append(i+1)
    List.append(sp)
List.sort(key=lambda List:(List[0],-List[1]))

for i in range(len(List)):
    print(List[i][2])

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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) (((x)&1)==0?(0):(1))
#define sign(x) (((x) > 0) - (x < 0))
#define dbg(x) cerr << #x"= " << x << endl

std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(bool _local){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    if (_local)
        freopen ("in.txt", "r", stdin);
#endif
}

int getfirst(int i){
    if (i<10) return i;
    return getfirst(i/10);
}

int main() {
    READ(0);
    int n;cin>>n;
    vvi cnt(10,vi(10,0));
    int last=1;
    for(int i=1;i<=n;++i,++last){
        if (last==10){
            last=0;
            continue;
        }
        cnt[getfirst(i)][last]++;
    }
    ll ret=0;
    for(int i=1;i<10;++i){
        for(int j=1;j<10;++j){
            ret += (ll) cnt[i][j] * cnt[j][i];
        }
    }
    cout << ret;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
 
 
int main() {
vector<vector<double>> dp(100011, vector<double>(22));
vector<double> dp2(100001);
  dp[1][1] = 1;
 
  REP(i, 1, 100001) {
    rep(j, 20) {
      dp[i+1][j+1] = dp[i][j] * pow(0.5, j);
      dp[i+1][0] += dp[i][j] * (1.0 - pow(0.5, j));
    }
  }
 
  rep(i, 100001) {
    double sum = 0.0;
    REP(j, 1, 20) sum += dp[i+1][j];
    dp2[i+1] = sum + dp2[i];
  }
   
  int n;
  while(cin >> n && n)
    printf("%.10f\n", dp2[n]);
 
  return 0;
}

Measured memory_bytes: 24592
from sys import stdin


def f(x, k, d):
    if k == 0:
        return x

    absX = abs(x)
    tmp = absX // d

    if tmp > k:
        return absX - d * k
    else:
        absX = absX - d * tmp
        k = k - tmp
        if k % 2 == 0:
            return absX
        else:
            return abs(absX - d)


if __name__ == '__main__':
    X, K, D = [int(x) for x in stdin.readline().rstrip().split()]
    print(f(X, K, D))


Measured memory_bytes: 8944