akhauriyash/Code-Regression huggingface dataset:
function main(input) {
    const args = input.split('\n');
    const N = parseInt(args[0], 10),
          S = args[1];
    var str = S.substr(0, N / 2);
    if (str + str == S) {
      console.log("Yes");
    } else {
      console.log("No");
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE BangPatterns #-}
module Main where

import Control.Arrow
import Control.Monad
import Control.Monad.ST
import Control.Monad.State.Strict
import Data.Char
import Data.Function
import Data.List
import Data.Maybe
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as C
import qualified Data.ByteString.Unsafe as B

type Parser a = C.ByteString -> Maybe (a, C.ByteString)

parseInt :: Parser Int
parseInt = C.readInt . C.dropWhile isSpace

parseInt2 :: Parser (Int, Int)
parseInt2 = runStateT $
    (,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)
 
parseInt3 :: Parser (Int, Int, Int)
parseInt3 = runStateT $
    (,,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)
 
parseInt4 :: Parser (Int, Int, Int, Int)
parseInt4 = runStateT $
    (,,,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)

main :: IO ()
main = do
  !a <- readLn :: IO Int
  !s <- C.getLine
  C.putStrLn $ if a >= 3200 then s else "red"


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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  string sa, sb, sc;
  cin >> sa >> sb >> sc;
  queue<char> saq, sbq, scq;
  rep(i, sa.size()) saq.push(sa[i]);
  rep(i, sb.size()) sbq.push(sb[i]);
  rep(i, sc.size()) scq.push(sc[i]);

  char next = 'a';
  bool exists = true;
  string res;
  while (exists) {
    switch (next) {
      case 'a':
        if (saq.empty()) {
          res = 'A';
          exists = false;
        } else {
          next = saq.front();
          saq.pop();
        }
        break;
      case 'b':
        if (sbq.empty()) {
          res = 'B';
          exists = false;
        } else {
          next = sbq.front();
          sbq.pop();
        }
        break;
      case 'c':
        if (scq.empty()) {
          res = 'C';
          exists = false;
        } else {
          next = scq.front();
          scq.pop();
        }
        break;
    }
  }

  cout << res << endl;

  return 0;
}


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

using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;

int main(){
    string S;
    int N,K;
    cin >> N >> K;
    cin >> S;

    if(S[K-1] == 'A'){
        S[K-1] = 'a';
    }else if(S[K-1] == 'B'){
        S[K-1] = 'b';
    }else{
        S[K-1] = 'c';
    }

    cout << S << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
int main()
{
	ll h,w;
	cin>>h>>w;
	if(h==1ll||w==1ll)
	{
		cout<<1<<endl;
		return 0;
	}
	cout<<(h*w+1ll)/2ll;
	return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
int main() {
  int N,i;
  cin>>N;
  int H[N]={0};
  int Hm[N]={0};
  for(i=0;i<N;i++){
  cin>>H[i];
  }
  Hm[1]=abs(H[1]-H[0]);
  Hm[2]=abs(H[2]-H[0]);
  for(i=2;i<N;i++){
  Hm[i]=min(Hm[i-1]+abs(H[i]-H[i-1]),Hm[i-2]+abs(H[i]-H[i-2]));
  }
  cout<<Hm[N-1]<<endl;
}

Measured memory_bytes: 1024
from sys import stdin
from collections import Counter
data = Counter([i for i in range(1, 101)])
for line in stdin:
    data[int(line.replace('\n', ''))] += 1
mode = data.most_common(1)[0][1]

for po in range(1, 101):
    if data[po] == mode:
        print(po)
    else:
        pass

Measured memory_bytes: 6016
// Atcoder Beginner Contest 174 C 
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;

#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define one 1.0
#define inf 1000000000000000000
#define all(vl) vl.begin(),vl.end()
#define m_p make_pair 
#define sz(a) sizeof(a)
#define forn(mp,it) for(it = mp.begin();it!=mp.end();it++)
#define FOR(i,a,n) for(int i=a;i<n;i++) 
#define FORE(i,a,n) FOR(i,a,n+1)
#define Endl endl
#define eNdl endl
#define enDl endl
#define endL endl
#define PI 3.14159265358979323846

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
 	ll n;
 	cin>>n;
 	ll ans = 1;
 	ll yu = 0;
 	for(ans = 1;ans<=n+10;ans++)
 	{
 		yu = (yu*10+7)%n;
 		if(yu == 0) break;
	 }
	cout<<(yu == 0?ans:-1)<<endl;
	return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
#define max(a,b) a>b?a:b
#define min(a,b) a<b?a:b
#define pb push_back
//#define IM_N00B ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;


int main(){

ll n;
cin >> n;
ll num = 0;
while (n>>=1) num++;
ll sum = 0;
ll xd = 1;
for(int i=0;i<=num;i++){
	sum += (xd<<i);
}
cout << sum;
return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <utility>
#include <typeinfo>
#include <string>
#include <sstream>

using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;

int main()
{
    cin.tie(0);
	ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    cout << (A - 1) * (B - 1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MAX_INF 0x7f
#define MAX_INF_VAL 0x7f7f7f7f
#define pi 3.141592653589
#define eps 1e-6
//#define p 2173412051LL
#define sz 2

using namespace std;

map< string, int > mp;
vector< string > a;

int main() {
	int n;
	int ma = 0;
	string s;
	map< string, int >::iterator it;
	cin >> n;
	while( n-- ) {
		cin >> s;
		if( mp.count( s ) == 0 )
			mp[ s ] = 1;
		else
			++mp[ s ];
	}
	for( it = mp.begin(); it != mp.end(); ++it ) {
		if( it -> second >= ma )
			ma = it -> second;
	}
	for( it = mp.begin(); it != mp.end(); ++it ) {
		if( it -> second == ma )
			a.push_back( it -> first );
	}
	sort( a.begin(), a.end() );
	for( int i = 0; i < a.size(); ++i )
		cout << a[ i ] << endl;
	return 0;
}

Measured memory_bytes: 26868
#include <bits/stdc++.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

int main() {
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  int M=max({a,b,c});
  int sum=a+b+c-M;
  for(int i=0;i<k;i++){
    M*=2;
  }
  cout<<M+sum<<endl;
  return 0;
}


Measured memory_bytes: 3540
n = int(input())
s = input()

from collections import defaultdict
l = defaultdict(int)
r = defaultdict(int)
for si in s:
    r[si] += 1
r[s[0]] -= 1

ans = l['W'] + r['E']
for i in range(1, n):
    l[s[i-1]] += 1
    r[s[i]] -= 1
    #print(l['W'] , r['E'])
    ans = min(ans, l['W'] + r['E'])
print(ans)


Measured memory_bytes: 41840
n = gets.to_i
a = gets.chomp.chars.map{|c| c == 'o'}
b = Array.new(n)
(0..3).each do |i|
  b[0] = i & 1 > 0
  b[1] = i & 2 > 0
  (1...(n-1)).each do |j|
    b[j + 1] = a[j]^b[j]^b[j-1]
  end
  if a[n-1]^b[n-1]^b[n-2] == b[0] && a[0]^b[0]^b[n-1] == b[1]
    puts b.map{|c|c ? 'S' : 'W'}.join
    exit
  end
end
p -1


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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()

template<typename T=ll>
void warshall(vector<vector<T>> &v, function<bool(const T&, const T&)> comp=less<T>()){
    ll n = v.size();
    rep(i, n) rep(j, n) rep(k, n){
        v[j][k] = comp(v[j][k], v[j][i]+v[i][k])? v[j][k] : (v[j][i]+v[i][k]);
    }
}

int main(){
    ll n, m, l;
    cin >> n >> m >> l;
    vvll d(n, vll(n, INT_MAX));
    rep(i, n) d[i][i] = 0;
    rep(i, m){
        ll a, b, c;
        cin >> a >> b >> c;
        d[a-1][b-1] = d[b-1][a-1] = c;
    }
    ll q;
    cin >> q;
    vll s(q), t(q);
    rep(i, q) cin >> s[i] >> t[i];

    warshall(d);
    rep(i, n) rep(j, n){
        d[i][j] = i==j? 0 : d[i][j]<=l? 1 : INT_MAX;
    }
    warshall(d);

    rep(i, q){
        ll res = d[s[i]-1][t[i]-1];
        cout << (res<INT_MAX? (res-1) : -1) << endl;
    }
}


Measured memory_bytes: 2688
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int A = in.nextInt();
    int B = in.nextInt();
    int K = in.nextInt();

    List<Integer> list = new ArrayList<Integer>();

    for (int i = 1; i <= Math.min(A, B); i++) {
      if (A % i == 0 && B % i == 0) {
        list.add(i);
      }
    }

    System.out.println(list.get(list.size() - K));
  }
}

Measured memory_bytes: 23764
#include <cstdio>
typedef long long int64;
static const int MAXN = 502;

int H, W, h, w;
int a[MAXN][MAXN] = {{ 0 }};

int main()
{
    scanf("%d%d%d%d", &H, &W, &h, &w);
    if (h == 1 && w == 1) { puts("No"); return 0; }

    for (int i = 0; i < H; i += h) {
        for (int j = 0; j < W; j += w) {
            a[i][j] = 1e9 - 1;
            if (i + h - 1 < H && j + w - 1 < W)
                a[i + h - 1][j + w - 1] = -1e9;
        }
    }

    int64 sum = 0;
    for (int i = 0; i < H; ++i)
        for (int j = 0; j < W; ++j) sum += a[i][j];
    if (sum > 0) {
        puts("Yes");
        for (int i = 0; i < H; ++i)
            for (int j = 0; j < W; ++j)
                printf("%d%c", a[i][j], j == W - 1 ? '\n' : ' ');
    } else {
        puts("No");
    }

    return 0;
}


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

int main(){
	int i;
	char str[256];
	char n[256];
	scanf("%s", str);
	int l = strlen(str);
	for(i=0;i<l;i++)
		n[i] = str[l-i-1];
	printf("%s\n", n);
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
int greater1(int a, int b){
   if(a > b){
        return a;
    } 
    else if(b > a){
        return b;
    }
    else{
        return '=';
    }
}


int main(){
    int a, b, k, greater, smaller;
    scanf("%d %d", &a, &b);
    greater = greater1(a, b);
    if(greater == a){
        smaller = b;
    }
    else if(greater == b){
        smaller = a;
    }
    else{
        printf("0\n");
        return 0;
    }

    k = smaller;
    while(k != greater){
        if(abs(a - k) == abs(b - k)){
            printf("%d\n", k);
            return 0;
        }
        else{
            k++;
        }
    }

    printf("IMPOSSIBLE\n");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <sstream>
#include <map>
#include <deque>
#include <queue>
#include <set>
using namespace std;
int swh=0;
int hs(int n){
	while(n!=0){
		swh+=n%10;
		n/=10;
	}
	return swh;
}
int main(){
	int n;
	cin>>n;
	int mod=hs(n);
	if(n%mod==0) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


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

bool isMonth(int num)
{
    if (num == 0 or num > 12)
        return false;
    else
        return true;
}

int main()
{
	std::ios::sync_with_stdio(false);
    string S;
    int a, b;
    cin >> S;
    a = stoi(S.substr(0, 2));
    b = stoi(S.substr(2, 2));


    string ans;
    bool f1, f2;
    f1 = isMonth(a);
    f2 = isMonth(b);
    if (!f1 and !f2)
        ans = "NA";
    else if (f1 and f2)
        ans = "AMBIGUOUS";
    else if (f1)
        ans = "MMYY";
    else
        ans = "YYMM";

    // cout << f1 << ' ' << f2 << endl;
    cout << ans << endl;
  	return 0;
}

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

const long long MOD = 1000000007;

long long modpow(long long a, long long n, long long mod) {
    if (n == 0) return 1;
    
    if (n == 1) return a % mod;
    
    if (n % 2 == 0) {
        long long half = modpow(a, n / 2, mod) % mod;
        return half * half % mod;
    }
    else return modpow(a, 1, mod) * modpow(a, n - 1, mod);
}

int main() {
    string s;
    cin >> s;
    long long len = (int)s.size();

    long long x;
    vector<vector<long long>> dp(13, vector<long long>(len + 1));
    dp.at(0).at(len) = 1;
    for (int i = len - 1; i >= 0; i--) {
        long long p = modpow(10, len - i - 1, 13) % 13;
        for (int j = 0; j < 13; j++) {
            if (s.at(i) == '?') {
                for (int k = 0; k <= 9; k++) {
                    x = j - (p * k % 13);
                    x %= 13;
                    if (x < 0) x += 13;
                    
                    dp.at(j).at(i) += dp.at(x).at(i + 1) % MOD;
                    dp.at(j).at(i) %= MOD;
                }
            }
            else {
                x = j - (p * (s.at(i) - '0') % 13);
                x %= 13;
                if (x < 0) x += 13;
                
                dp.at(j).at(i) += dp.at(x).at(i + 1) % MOD;
                dp.at(j).at(i) %= MOD;
            }
        }
    }

    cout << dp.at(5).at(0) << endl;
}   

Measured memory_bytes: 11392
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using namespace std;

void yesno(bool b) {
    if (b) {
        cout << "Yes" << endl;
    }     else {
        cout << "No" << endl;
    }

}

int main() {
    ll N, K;
    cin >> N >> K;

    ll t = N/K;
    ll tmp = K * (N / K);
    cout << min(N - tmp, tmp+K - N) << endl;

}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL){
    x = x->right;
  }
  return x;
}

Node treeSearch(Node u, int k){
  while(u != NIL && k != u->key){
    if(k < u->key) u = u->left;
    else u = u->right;
  }
  return u;
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL) return treeMinimum(x->right);

  y = x->parent;
  while(y !=NIL && x == y->right){
    x = y; 
    y = y->parent;
  }
  return y;
}
void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  
  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL) x = y->left;
  else x = y->right;

  if(x != NIL) x->parent = y->parent;

  if(y->parent == NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;

  if(y != z) z->key = y->key;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;

  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

void inorder(Node u){
    if(u != NIL){
      inorder(u->left);
      printf(" %d",u->key);
      inorder(u->right);
    }
  }
  
  void preorder(Node u){
    if(u != NIL){
      printf(" %d",u->key);
      preorder(u->left);
      preorder(u->right);
    }
  }
 
  int main(){
    int n, i, x;
    char com[20];
    scanf("%d", &n);

    for ( i = 0; i < n; i++ ){
      scanf("%s", com);
      if ( com[0] == 'f' ){
	scanf("%d", &x);
	Node t = treeSearch(root, x);
	if ( t != NIL ) printf("yes\n");
	else printf("no\n");
      } else if ( com[0] == 'i' ){
	scanf("%d", &x);
	insert(x);
      } else if ( com[0] == 'p' ){
	inorder(root);
	printf("\n");
	preorder(root);
	printf("\n");
      } else if ( com[0] == 'd' ){
	scanf("%d", &x);
	treeDelete(treeSearch(root, x));
      }
    }

    return 0;
  }

Measured memory_bytes: 24040
#include <stdio.h>
                                                                                                
  
int main(void){
                                                                                                
   
    int w, h, n, i;
   
    int x[101], y[101], a[101];



    int xo = 0;



    int yo = 0;
   
      
    scanf("%d %d %d", &w, &h, &n );


    int xn = w;

    int yn = h;
   

    for( i = 0 ; i < n ; i = i + 1 ){

        scanf("%d %d %d", &x[i], &y[i], &a[i] );

        if( a[i] == 1 && xo <= x[i] ) xo = x[i];

        else if( a[i] == 2 && x[i] <= xn && xo < x[i] ) xn = x[i];

        else if( a[i] == 2 && x[i] <= xo ) xo = xn;

        else if( a[i] == 3 && yo <= y[i] ) yo = y[i];

        else if( a[i] == 4 && y[i] <= yn && yo < x[i] ) yn = y[i];

        else if( a[i] == 4 && y[i] <= yo ) yo = yn;

        }


    printf("%d\n", (xn - xo) * (yn - yo) );


    return 0;
                                                          
}

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

#define PI 4*atan(1)
#define INF 1e8

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

int main(){
  int n, m;
  while(cin >> n >> m, n || m){
    vector<int> s_t(n), s_h(m);
    for(int i = 0; i < n; i++){
      cin >> s_t[i];
    }
    for(int i = 0; i < m; i++){
      cin >> s_h[i];
    }
    sort(s_t.begin(), s_t.end());
    sort(s_h.begin(), s_h.end());
    int sum_t = accumulate(s_t.begin(), s_t.end(), 0);
    int sum_h = accumulate(s_h.begin(), s_h.end(), 0);
    
    int t = 0, h = 0, sum = INF;
    for(int i = 0; i < n; i++){
      for(int j = 0; j < m; j++){
        if(sum_t - s_t[i] + s_h[j] == sum_h - s_h[j] + s_t[i]){
          if(sum >= s_t[i] + s_h[j]){
            t = s_t[i];
            h = s_h[j];
            sum = s_t[i] + s_h[j];
          }
        }
      }
    }
    if(sum == INF)cout << "-1" << endl;
    else cout << t << " " << h << endl;
  }

}

Measured memory_bytes: 3024
#include<iostream>
int main() {
    int i;
    char S[3];
    for (i = 0; i < 3; i++) {
      std::cin >> S[i];
    }
      if (S[0] != S[1] && S[1] != S[2] && S[0] != S[2])
          std::cout << "Yes";
      else
          std::cout << "No";
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        exec();
    }

    static void exec() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        long saishoko = 1;
        for (int i = 0; i < n; i++) {
           saishoko = lcm(saishoko,a[i]);
        }

        long tmpsum = 0;
        for (int i = 0; i < n; i++) {
            tmpsum += saishoko / a[i];
        }

        System.out.println((double)saishoko / tmpsum);




    }

    static int lcm (long a, long b) {
        long temp;
        long c = a;
        c *= b;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return (int)(c/b);
    }

}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

#define ll long long
#define pb push_back

ll MIN(ll num1,ll num2){
    return num1<num2?num1:num2;
}

int main(){

    while(1){
        int n,r;
        vector<int> P,C,card;
        cin>>n>>r;
        if(n==0&&r==0)break;
        for(int i=n;i>0;i--){
            card.pb(i);
        }
        //for(int j=0;j<n;j++)cout<<card[j]<<" ";
        //cout<<endl;
        for(int i=0;i<r;i++){
            int p,c;
            cin>>p>>c;
            vector<int> tmp;
            for(int j=0;j<c;j++){
                tmp.pb(card[p-1+j]);
                //cout<<card[p-1+j]<<" ";
            }
            //cout<<endl;
            for(int j=0;j<p-1;j++){
                tmp.pb(card[j]);
                //cout<<card[j]<<" ";
            }
            //cout<<endl;
            for(int j=0;j<n-p+1-c;j++){
                tmp.pb(card[p-1+c+j]);
                //cout<<card[p-1+c+j]<<" ";
            }
            //cout<<endl;
            card=tmp;
            //for(int j=0;j<n;j++)cout<<card[j]<<" ";
            //cout<<endl<<endl;
        }
        cout<<card[0]<<endl;
    }

    return 0;
}


Measured memory_bytes: 3060
keymap = [
    [".",",","!","?"," "],
    ["a","b","c"],
    ["d","e","f"],
    ["g","h","i"],
    ["j","k","l"],
    ["m","n","o"],
    ["p","q","r","s"],
    ["t","u","v"],
    ["w","x","y","z"]
]

n = int(input())

for i in range(n):
    keys = str(input())
    message = ""
    currentChar = ""
    currentKey = "X"
    push_counter = 0
    for key in keys:
        if key == "0":
            message += currentChar
            currentChar = ""
            currentKey = "0"
            continue
        if currentKey == key:
            push_counter += 1
        else:
            push_counter = 0
            currentKey = key
        key_int = int(currentKey) - 1
        count = push_counter % len(keymap[key_int])
        currentChar = keymap[key_int][count]
    print(message)



Measured memory_bytes: 5612
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(){
    int n;
    cin >> n;
    vector<int> vec={ 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << vec[n-1] << endl; 
    return 0;
}

Measured memory_bytes: 256
def do_code():
    s = input()
    weekday = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
    weekday.reverse()
    i = weekday.index(s)
    print((i + 1) % 8)


if __name__ == "__main__":
    do_code()


Measured memory_bytes: 2940
# -*- coding: utf-8 -*-
import sys

n = 0
s = 0

def combination(n, k):
    max = 2 ** n

    for i in xrange(max):
        result = [0] * n
        for j in xrange(n):
            result[j] = i >> j & 1
        cnt = 0
        for b in result:
            if b == 1:
                cnt += 1
        if cnt == k:
            yield result


for line in sys.stdin:
    l = map(int, line.strip().split())
    n = l[0]
    s = l[1]

    if n == 0 and s == 0:
        break

    ans = 0

    for ar in combination(10, n):
        sm = 0
        for i in xrange(len(ar)):
            if ar[i] == 1:
                sm += i

        if sm == s:
            ans += 1

    print ans

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

int main()
{
  int N;
  cin >> N;
  long long int ans = 1000000000000000;
  long long int sum = 0;
  vector<long long int> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A[i];
    sum += A[i];
  }
  vector<long long int> S(N);
  S[0] = A[0];
  for (int i = 1; i < N; i++)
  {
    S[i] += S[i - 1] + A[i];
  }
  for (int i = 0; i < N - 1; i++)
  {
    long long int left = S[i];
    long long int right = sum - S[i];
    long long int now = 0;
    if (left >= right)
      now = left - right;
    else
      now = right - left;
    ans = min(now, ans);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3328
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

const long double PI = (acos(-1));
const long double eps = 0.0000000001;


long double check(long double a, long double b, long double theta) {

  // if(theta > PI / 2.0 - eps) return 0.0;
  
  long double tmp;
    if(a * tan(theta) <= b) {
      tmp = a * a * b - a * a * a * tan(theta) / 2.0;
    }
    else {
      tmp = a * b * b / tan(theta) / 2.0;
    }
    return tmp;
}

int main() {
  long double a,b,x;
  cin >> a >> b >> x;

  long double l = 0.0;
  long double r = PI / 2.0;


 
    for(int i = 0; i < 1000; i++) {
      long double mid = (l + r) / 2.0;
      if(check(a,b,mid) < x) {
	r = mid;
      }
      else l = mid;
    
    }

  

    cout << fixed << setprecision(10) << r * 180.0 / PI << endl;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

int main() {
	IOS;
	int m = 3;
	vector<vector<int>> a(m, vector<int>(m));
	vector<vector<int>> c(m, vector<int>(m, 0));
	REP(i, m) {
		REP(j, m) {
			cin >> a[i][j];
		}
	}
	int n;
	cin >> n;
	vector<int> b(n);
	REP(i, n) {
		cin >> b[i];
		REP(j, m) {
			REP(k, m) {
				if (a[j][k] == b[i]) {
					c[j][k] = 1;
				}
			}
		}
	}
	REP(i, m) {
		bool flag = true;
		REP(j, m) {
			if (c[i][j] == 0) {
				flag = false;
			}
		}
		if (flag) {
			put("Yes");
			return 0;
		}
	}
	REP(i, m) {
		bool flag = true;
		REP(j, m) {
			if (c[j][i] == 0) {
				flag = false;
			}
		}
		if (flag) {
			put("Yes");
			return 0;
		}
	}
	bool flag = true;
	REP(i, m) {
		if (c[i][i] == 0) {
			flag = false;
		}
	}
	if (flag) {
		put("Yes");
		return 0;
	}
	flag = true;
	REP(i, m) {
		if (c[i][m-1-i] == 0) {
			flag = false;
		}
	}
	if (flag) {
		put("Yes");
		return 0;
	}
	put("No");
	return 0;
}

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

int main() {
    string s;
    cin >> s;
    int ans = 0;
    rep(i,6) ans += s[i] - '0';
    cout << ans << endl; 
}

Measured memory_bytes: 256
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<deque>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define ll __int64
//#define __int64 long long
#define P pair<int,int>

string s;

int main(){
	cin>>s;
	int cnt=0;
	int ns=s.size();
	rep(i,ns)if(s[i]=='p')cnt++;
	cout<<max(0,ns/2-cnt)<<endl;
}

Measured memory_bytes: 512
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=1e6+50;
const int mod=1e9+7;
using namespace std;
int n,a[20],b[20],f[nmax][55],lm,nr,x,i,j,t,pr,rs=inf;
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n;
	for(i=0;i<n;i++)cin>>a[i];
	for(i=0;i<n;i++)cin>>b[i];
	for(i=0;i<(1<<n);i++)
	{
		nr=__builtin_popcount(i),pr=0;
		if(i)for(t=1;t<=50;t++)f[i][t]=inf;
		for(j=0;j<n;j++)
		{
			if(i&(1<<j))
			{
				pr++;
				x=abs(nr-1-(j+nr-pr));
				if(((nr-1)&1)==(j&1))lm=a[j];
				else lm=b[j];
				for(t=1;t<=lm;t++)if(f[i^(1<<j)][t]!=inf)f[i][lm]=min(f[i][lm],f[i^(1<<j)][t]+x);
				if(i==(1<<n)-1)rs=min(rs,f[i][lm]);
			}
		}
	}
	if(rs==inf)rs=-1;
	cout<<rs<<endl;
	return 0;
}


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

int main () {
 
 int a,b;
 char op;
 
 while (cin >> a >> op >> b) {
  if (op == '?') {
   break;
  }
  switch (op) {
   case '+' : cout << a+b ; break;
   case '-' : cout << a-b ; break;
   case '/' : cout << a/b ; break;
   case '*' : cout << a*b ; break;
  }
  cout << endl;
 }

 return 0;
}

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

typedef long long ll;

struct str{
    ll a,b;
};

bool operator<(str a,str b){
    return a.b<b.b;
}

int main()
{

    ll n,a,b,ans,t,i;
    vector<str>v;
    cin >> n >> t;
    for(i=0; i<n; i++){
        cin >> a >> b;
        v.push_back({a,b});
    }
    sort(v.begin(),v.end());
    if(v[0].b>t)cout << "TLE\n";
    else {
        for(i=0; i<v.size(); i++){
            a=v[i].a,b=v[i].b;
            if(b>t)break;
            if(i==0)ans=a;
            else ans=min(a,ans);
        }
        cout << ans << "\n";
    }


    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};


int main(){
  int n,d;
  cin>>n>>d;
  int x[n][d];
  REP(i,n){
    REP(j,d){
      cin>>x[i][j];
    }
  }
  
  int ans=0;
  int dis=0;
  bool flag = false;
  REP(i,n){
    REP(j,i){
      dis = 0;
      flag = false;
      REP(k,d){
        dis += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
      }
      REPP(k,200){
        if(k*k==dis){
          flag = true;
          break;
        }
      }
      if(flag){
        ans++;
      }
    }
  }
  
  cout<<ans<<endl;
  return 0;
}


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

int num_divisor(int num){
    int res = 0;
    for(int i = 1; i * i <= num; i++){
        if (num % i == 0){
            res++;
            if(i * i != num) res++;
        }
    }
    return res;
}

int main(void){
    int N; cin >> N;
    int ans = 0;
    
    for(int i = 1; i <= N; i++){
        if (i % 2 == 0) continue;
        if(num_divisor(i)==8) ans++;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1] * (n + 1)
        self.rnk = [0] * (n + 1)

    def find_root(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find_root(self.root[x])
            return self.root[x]

    def unite(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return
        elif self.rnk[x] > self.rnk[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rnk[x] == self.rnk[y]:
                self.rnk[y] += 1

    def isSameGroup(self, x, y):
        return self.find_root(x) == self.find_root(y)

    def size(self, x):
        return -self.root[self.find_root(x)]


def main():
    N = int(input())
    xy_list = []
    x_list = []
    y_list = []
    for i in range(N):
        x, y = map(int, input().split())
        xy_list.append((x, y))
        x_list.append(x)
        y_list.append(y)

    x_list = list(set(x_list))
    y_list = list(set(y_list))
    x_list.sort()
    y_list.sort()
    dictX = {}
    dictY = {}
    for i, x in enumerate(x_list):
        dictX[x] = i
    for i, y in enumerate(y_list):
        dictY[y] = i

    xy_c = [[] for _ in range(len(x_list))]
    for x, y in xy_list:
        xc, yc = dictX[x], dictY[y]
        xy_c[xc].append(yc)

    UF = UnionFind(len(y_list) + 1)
    for i in range(len(x_list)):
        j_list = xy_c[i]
        if len(j_list) > 1:
            j0 = j_list[0]
            for j in j_list[1:]:
                UF.unite(j0, j)

    ans = 0
    for i in range(len(x_list)):
        j0 = xy_c[i][0]
        ans += UF.size(j0) - len(xy_c[i])
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 101332
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int cnt = 0;
  bool flag = false;
  for (int i = 0; i < n; ++i) {
    int d1, d2;
    cin >> d1 >> d2;
    if (d1 == d2)
      ++cnt;
    else
      cnt = 0;
    if (3 <=cnt)
      flag = true;
  }

  cout << (flag ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3632
// #1140935 Solution for 0515: School Road by ryogo 
#include<iostream>
using namespace std;
int dp[17][17];
int main(){
	int a, b ,i, j, x, y;
	while(cin >> a >> b){
		if(a == 0 && b == 0) { break; }
		int n;
		cin>>n;
		for(i=1; i<=16; i++)for(j=1; j<=16; j++){dp[i][j] = 0;}
		for(i=1; i<=n ; i++){
			cin >> x >> y; dp[y][x] = -1;
		}
		dp[1][1] = 1;
		for(i=1; i<=b; i++){
			for(j=1; j<=a; j++){
				if(i==1 && j==1)continue;
				if(dp[i][j] != -1){
					dp[i][j] = dp[i][j-1] + dp[i-1][j];
				}
				else dp[i][j] = 0;
			}
		}
 
		cout << dp[b][a] << endl;
	}
}


Measured memory_bytes: 2968
S = list(input())
count = 0
for i in range(len(S) - 1):
    if S[i] == "0" and S[i+1] == "0":
        S[i+1] = "1"
        count += 1
    if S[i] == "1" and S[i+1] == "1":
        S[i+1] = "0"
        count += 1
print(count)

Measured memory_bytes: 49520
// --------------
// Tejas Pandey  |
// 01 - 12 - 19  |
// SUMOMITO PC'19|
// --------------

#include <bits/stdc++.h>
using namespace std;

#define mod 1000000007
#define vi vector<int>
typedef long long int ll;

int main (void)
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	//cin >> t;
	while(t--)
	{
		//cout << "Case #" << c-t << ": ";
		int n;
		cin >> n;
		string s;
		cin >> s;
		string ser = "000";
		int ans = 0;
		for(int i = 0;i < 1000;i++){
			int cur = 0;
			for(int j = 0;j < s.size();j++){
				if(s[j] == ser[cur]) cur++;
				if(cur == 3) break;
			}
			//if(ser == "024") cout << s[0] << " " << ser[cur] << "\n";
			if(cur == 3) ans++;
			if(ser[2] == '9'){
				ser[2] = '0';
				if(ser[1] == '9') ser[1] = '0',ser[0]++;
				else ser[1]++;
			}
			else{
				ser[2]++;
			}
			//cout << ser << "\n";
		}
		cout << ans << "\n";
	}
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<bits/stdc++.h>
#include<string.h>
#define SAT 1
#define SUN 2
#define MON 3
#define TUE 4
#define WED 5
#define THU 6
#define FRI 7
using namespace std;
int main()
{
    int a,b;
    string s;
    cin>>s;
    if(s=="SUN") cout<<7<<endl;
    else if(s=="SAT") cout<<1<<endl;
    else if(s=="MON") cout<<6<<endl;
    else if(s=="TUE") cout<<5<<endl;
    else if(s=="WED") cout<<4<<endl;
    else if(s=="THU") cout<<3<<endl;
    else if(s=="FRI") cout<<2<<endl;
}


Measured memory_bytes: 3584
fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let _n: i32 = sc.read();
    let a: i32 = sc.read();
    let b: i32 = sc.read();

    let ans = (a + b) % 2;
    let ans_str = vec!["Alice", "Borys"];
    println!("{}", ans_str[ans as usize]);
}

// thanks, ir5
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}


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

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n), div(1000010), cnt(1000010);
    for(int i=0; i<n; i++) {
        cin >> a[i];
        cnt[a[i]]++;
    }
    for(int i=1; i<=1000000; i++) {
        for(int j=i; j<=1000000; j+=i) {
            div[j] += cnt[i];
        }
    }
    int ans = 0;
    for(int i=0; i<n; i++) {
        if(div[a[i]] == 1) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 20420
#include <bits/stdc++.h>
using namespace std;
#define pb                push_back
#define int               long long
#define M                 1000000007
#define MM                998244353
#define fr                first
#define sc                second
#define vc                vector
#define pii               pair<int,int>
#define msi               map<string,int>
#define mii               map<int,int>
#define psi               pair<string,int>
#define pis               pair<int,string>
#define piii              pair<int,pii>

	signed main() {
	
		   int t=1;
		  //cin>>t;
		   while(t--)
		   {
		   		
		   	int n,k,w,mx=0,sum=0,xx=0;
		             string s;

		        cin>>n>>k;
		        int a[k];
		        for(int i=0;i<k;i++){
		        	cin>>a[i];
		        	sum+=a[i];}
		        	if(sum<=n)cout<<n-sum<<endl;
else cout<<-1<<endl;
	
}
 
	} 

Measured memory_bytes: 3672
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
  ll n,k;
  cin>>n>>k;
  ll i,x;
  vector<ll> v;
  for(i=0;i<n;i++)
  {
    cin>>x;
    v.push_back(x);
  }
  ll dp[n+7];
  for(i=0;i<n+7;i++)
  {
    dp[i]=LLONG_MAX;
  }
  dp[0]=0;
  dp[1]=abs(v[1]-v[0]);
  for(i=2;i<n;i++)
  {
    for(ll j=i-1;j>=max((ll)0,i-k);j--)
    {
      dp[i]=min(dp[i],dp[j]+abs(v[i]-v[j]));
    }
  }
  cout<<dp[n-1];
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

ll match[10] = {INF, 2, 5, 5, 4, 5, 6, 3, 7, 6};  // 必要なマッチの本数
string num = "0123456789";
string strmax(string s, string t) {
  if (s.size() > t.size()) return s;
  if (s.size() < t.size()) return t;

  if (s >= t)
    return s;
  else
    return t;
}

// ====================================================================

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(m);
  for (int i = 0; i < m; i++) cin >> v[i];
  sort(v.begin(), v.end());

  vector<vector<string>> dp(m, vector<string>(n + 1));
  // m番目の数字まででn本のマッチを使って作れる最大の数字
  for (int i = 0; i < m; i++)
    for (int j = 0; j <= n; j++)
      dp[i][j] = "";
  dp[0][0] = ".";

  // 貰うDP
  for (int i = 0; i < m; i++) {        // k番目の数字まで見ていく
    for (int c = 0; c <= n; c++) {     // cはコスト
      string l = "", ld = "", d = "";  // 左と左下と下とを対決させる
      if (i > 0 && dp[i - 1][c] != "")
        l = dp[i - 1][c];
      if (i > 0 && c - match[v[i]] >= 0 && dp[i - 1][c - match[v[i]]] != "")
        ld = num[v[i]] + dp[i - 1][c - match[v[i]]];
      if (c - match[v[i]] >= 0 && dp[i][c - match[v[i]]] != "")
        d = num[v[i]] + dp[i][c - match[v[i]]];
      dp[i][c] = strmax(dp[i][c], strmax(l, strmax(ld, d)));
    }
  }

  dp[m - 1][n].erase(prev(dp[m - 1][n].end(), 1));
  cout << dp[m - 1][n] << endl;
}


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

#define int long long

signed main() {
    int n; cin >> n;
    int m = n / 100;

    if(m * 100 + m * 10 + m < n) {
        cout << (m + 1) * 100 + (m + 1) * 10 + m + 1 << endl;
    } else {
        cout << m * 100 + m * 10 + m << endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		
			int a = stdin.nextInt();
			int b = stdin.nextInt();
			int c = stdin.nextInt();
			int d = stdin.nextInt();
		
		
		if(a == b && c == d) {
			System.out.println("yes");
		} else if(a == c && b == d) {
			System.out.println("yes");
		} else if(a == d && b == c) {
			System.out.println("yes");
		} else {
			System.out.println("no");
		}

	}
}

Measured memory_bytes: 26216
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
#include <cctype>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)n; ++i)

int main()
{
	string st;
	stack<int> q;
	int lhs, rhs;

	while(cin >> st) {
		if(st == "+") {
			rhs = q.top();
			q.pop();
			lhs = q.top();
			q.pop();
			q.push(lhs + rhs);
		}

		else if(st == "-") {
			rhs = q.top();
			q.pop();
			lhs = q.top();
			q.pop();
			q.push(lhs - rhs);
		}
		else if(st == "*") {
			rhs = q.top();
			q.pop();
			lhs = q.top();
			q.pop();
			q.push(lhs * rhs);
		}


		else {
			q.push(atoi(st.c_str()));
		}
	}

	cout << q.top() << endl;

	return 0;
}

Measured memory_bytes: 1204
const [a, b] = require("fs").readFileSync("/dev/stdin", "utf8").split(" ");
const result = (BigInt(parseInt(a, 10)) * BigInt(parseInt(b.split(".").join(""), 10))).toString().slice(0, -2);
if (result === "") {
  console.log(0);
} else {
  console.log(result);
}


Measured memory_bytes: 29376
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static System.Console;

namespace ConsoleApp2
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static void Main(string[] args)
        {
            var S = ReadLine().Distinct().ToArray();
            if (S.Contains('N') && S.Contains('S') && S.Contains('W') && S.Contains('E'))
            {
                WriteLine("Yes");
                return;
            }
            if (S.Contains('N') && S.Contains('S') && !S.Contains('W') && !S.Contains('E'))
            {
                WriteLine("Yes");
                return;
            }
            if (!S.Contains('N') && !S.Contains('S') && S.Contains('W') && S.Contains('E'))
            {
                WriteLine("Yes");
                return;
            }
            WriteLine("No");
        }

    }
}


Measured memory_bytes: 13268
import std.stdio; import std.algorithm; import std.array; import std.conv; import std.string; import std.uni; import std.range; import std.algorithm; void main() { while (!stdin.eof) { auto a = readln.strip; if (a == "-") break; auto m = readln.strip.to!int; foreach (x; iota(m).map!(x => readln.strip.to!int)) { a = a[x..$] ~ a[0..x]; } writeln(a); } } 





Measured memory_bytes: 2440
n = int(input())
t, a = list(map(int, input().split()))
h_list = list(map(int, input().split()))
t_list = list(map((lambda h: t-h*0.006), h_list))
diff_list = list(map((lambda t: abs(a-t)), t_list))
print(diff_list.index(min(diff_list))+1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=5e5+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
#endif
}
ll n,D,a[N];
void input()
{
	n=read<ll>();D=read<ll>();
	For(i,1,n)a[i]=read<ll>();
}
ll dis[N],f[N];
void work()
{
	dis[0]=D;
	For(i,1,n)
	{
		dis[i]=dis[i-1];
		if(dis[i]>abs(dis[i]-a[i]))dis[i]=abs(dis[i]-a[i]);
	//	cout<<pos[i]<<endl;
	}
	//couit<<endl;
	f[n+1]=1;
	Fordown(i,n,1)
	{
		f[i]=f[i+1];
		if(a[i]<f[i]*2)f[i]+=a[i];
	//	cout<<f[i]<<endl;
	}
	int x,q=read<int>();
	For(i,1,q)
	{
		x=read<int>();
		if(dis[x-1]>=f[x+1])puts("YES");
		else puts("NO");
	}
}
int main()
{
//	file();
	input();
	work();
	return 0;
}


Measured memory_bytes: 13696
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
#define rrep(i,n) for(int i = n-1; i >= 0 ; i--)
typedef long long ll;
constexpr auto INFI = 2147483647;
const ll INFL = 9223372036854775807;

int main(){
    int n, n_tmp, tmp;
    ll ans = 0;
    cin >> n;
    n_tmp = n;
    priority_queue<ll> member;
    rep(i,n) {
        cin >> tmp;
        member.push(tmp);
    }

    ans += member.top();
    member.pop();
    n_tmp -= 2;

    while (true) {
        int now = member.top();
        member.pop();
        if (n_tmp >= 2) {
            ans += now * 2;
            n_tmp -= 2;
        } else if (n_tmp == 1) {
            ans += now;
            break;
        } else {
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5364