akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
namespace AtCoder {
    class MainClass {
        public static void Main(string[] args) { new MainClass().solve(); }

        Scanner cin = new Scanner();

        char c;
        void solve() {

            c = cin.Char();

            char[] v = "aiueo".ToCharArray();

            bool isVowel = v.Contains(c);

            Console.WriteLine(isVowel ? "vowel" : "consonant");

        }
        class Scanner {
            string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' };
            public Scanner() { nextBuffer = new string[0]; BufferCnt = 0; }
            public string String() {
                if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++];
                string st = Console.ReadLine();
                while (st == "") st = Console.ReadLine();
                nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
                BufferCnt = 0;
                return nextBuffer[BufferCnt++];
            }
            public char Char() { return char.Parse(String()); }
            public int Int() { return int.Parse(String()); }
            public long Long() { return long.Parse(String()); }
            public double Double() { return double.Parse(String()); }
        }

        class Mathf {
            public int mod = 1000000007;//10^9+7
            public long Pow(long a, long b) {
                if (b == 0) return 1;
                if (b % 2 == 1) return (a % mod * Pow(a % mod, b - 1) % mod) % mod;
                else return Pow(a * a % mod, b / 2) % mod;
            }
            public long Fact(long n) { return n != 0 ? (n % mod * (Fact(n - 1) % mod) % mod) : 1; }
            public long C(long n, long r) {
                if (r == 0 || n == r) return 1;
                else return (Fact(n) % mod * Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) % mod;
            }
            public int GCD(int a, int b) { if (a < b) Swap(ref a, ref b); return b == 0 ? a : GCD(b, a % b); }
            public int GCD(int[] array) { return array.Aggregate((v, next) => GCD(v, next)); }
            public void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; }
        }
    }
}

Measured memory_bytes: 11220
// C - Exception Handling
#include <bits/stdc++.h>

using namespace std;

void rmq_update(vector<int> &tree, int node, int l, int r, int i, int val)
{
	if (l == r) {
		tree[node] = val;
		return;
	} else if (i >= l && i <= r) {
		int c1 = node * 2 + 1, c2 = node * 2 + 2, m = (l + r) / 2;
		if (i <= m) rmq_update(tree, c1, l, m, i, val);
		else rmq_update(tree, c2, m + 1, r, i, val);
		tree[node] = max(tree[c1], tree[c2]);
	}
}

int rmq_get(vector<int> &tree, int node, int l, int r, int ll, int rr)
{
	if (ll > r || rr < l) return -1;
	if (l >= ll && r <= rr) return tree[node];
	int c1 = node * 2 + 1, c2 = node * 2 + 2, m = (l + r) / 2;
	int r1 = rmq_get(tree, c1, l, m, ll, rr);
	int r2 = rmq_get(tree, c2, m + 1, r, ll, rr);
	if (r1 < 0) return r2;
	if (r2 < 0) return r1;
	return max(r1, r2);
}

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];

	vector<int> t(n * 4);
	for (int i = 0; i < n; i++) rmq_update(t, 0, 0, n - 1, i, a[i]);
	for (int i = 0; i < n; i++) {
		int ans = 0;
		if (i == 0) ans = rmq_get(t, 0, 0, n - 1, i + 1, n - 1);
		else if (i == n - 1) ans = rmq_get(t, 0, 0, n - 1, 0, n - 2);
		else ans = max(rmq_get(t, 0, 0, n - 1, 0, i - 1), rmq_get(t, 0, 0, n - 1, i + 1, n - 1));
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 5504
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;
#define int LL
bool isPrime(int n) {
    if (n < 2) return false;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return true;
}

void solve(int a, int d, int n) {
    int cnt = 0;
    for (int i = a; ; i += d) {
        cnt += isPrime(i);
        if (cnt == n) {
            cout << i << endl;
            return;
        }
    }
    return;
}

signed main(void) {
    int n, p, m, w, h;
    string s;
    int a, b, c, d;
    while (cin >> a >> d >> n) {
        if (a == 0 && d == 0 && n == 0) return 0;
        solve(a, d, n);
        //return 0;
    }
}

Measured memory_bytes: 3076
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    E = [[] for _ in range(n)]
    for _ in range(n - 1):
        u, v = map(int,input().split())
        u -= 1; v -= 1
        E[u].append(v)
        E[v].append(u)

    dp = [[1] * 2 for _ in range(n)]
    deg = [len(E[v]) - 1 for v in range(n)]
    deg[0] += 1
    stack = [(~0, -1), (0, -1)]
    while stack:
        v, p = stack.pop()
        if v >= 0:
            for nv in E[v]:
                if nv == p:
                    continue
                stack.append((~nv, v))
                stack.append((nv, v))
        else:
            v = ~v
            if deg[v] == 0:
                white = black = 1
                for nv in E[v]:
                    if nv == p:
                        continue
                    white = white * (dp[nv][0] + dp[nv][1]) % MOD
                    black = black * dp[nv][0] % MOD
                dp[v][0], dp[v][1] = white, black
            deg[p] -= 1

    print((dp[0][0] + dp[0][1]) % MOD)
resolve()

Measured memory_bytes: 85936
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<l_l> vpl;
typedef vector<string> vs;
typedef pair<l_l,ll> lll;
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=1;i<=(n);i++)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
const ll dx[4]={1,-1,0,0};
const ll dy[4]={0,0,1,-1};
template<class T> inline bool chmin(T& a,T b){
if(a>b){
a=b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a,T b){
if(a<b){
a=b;
return true;
}
return false;
}
ll n,q;
vl node;
ll N;
void init(){
    N=1;
    while(N<n)N*=2;
    node.resize(2*N-1,INT_MAX);
}
void update(ll k,ll x){
    k+=N-1;
    node[k]=x;
    while(k){
        k=(k-1)/2;
        node[k]=min(node[2*k+1],node[2*k+2]);
    }
}
ll get_min(ll l,ll r,ll bottom=0,ll top=-1,ll pos=0){
    if(top<0)top=N;
    if(l<=bottom&&top<=r)return node[pos];
    if(r<=bottom||top<=l)return INT_MAX;
    ll mid=(bottom+top)/2;
    return min(get_min(l,r,bottom,mid,2*pos+1),get_min(l,r,mid,top,2*pos+2));
}
int main(){
    cin>>n>>q;
    init();
    vi ans;
    rep(i,q){
        ll query,x,y;cin>>query>>x>>y;
        if(query){
            cout<<get_min(x,y+1)<<endl;
        }
        else update(x,y);
    }
    //rep(i,N+1)cout<<node[i]<<endl;
    return 0;
}


Measured memory_bytes: 4900
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
///----------------------------------string类的一些特点
struct s
{
    char ss[110];
}str[110];
bool cmp(const s &a,const s &b)
{
    return strcmp(a.ss,b.ss)<0?1:0;
}
///char str[110][110];
int main()
{
    int N,L,i,flag=0;
    scanf("%d%d",&N,&L);
    getchar();
    for(i=0;i<N;i++)
        cin >> str[i].ss;
   sort(str,str+N,cmp);
   for(i=0;i<N;i++)
    cout <<str[i].ss;///为什么这样就可以呢
    return 0;
}


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

#ifdef LOCAL
#include "prabh.hpp"
#endif

#define int long long
#define pb push_back
#define range(v) v.begin(),v.end()
#define rrange(v) v.rbegin(), v.rend()
#define mod (int)(1e9 + 7)
#define inf (int)(5e18)
#define N (int)(3e3 + 10)

using namespace std;

int n;
long double a[N];
long double dp[N][N];

long double coins(int pos, int bal) {
	if (pos == n) return bal > 0;
	long double &ans = dp[pos][bal];
	if (abs(ans + 1) < 1e9) return ans;

	ans = coins(pos + 1, bal + 1) * a[pos] + coins(pos + 1, bal - 1) * (1 -  a[pos]);

	return ans;
}

void solve() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	memset(dp, -1.0, sizeof(dp));
	cout << fixed << setprecision(10) << coins(0, 0) << endl;
}
// Remember to clear the global containers

// Got stuck and want to leave ? look at the bottom once..
int32_t main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr);
	int t_c = 1;
	// cin >> t_c;
	while (t_c--)
		solve();
}
/* Come on Dude .. Dont get up until u get the solution
 * Giving up not gonna help ryt ? So get ur lazy ass to code already
 * You can do it ... Stay Calm and Dont Panic :)
 */


Measured memory_bytes: 145588
#include "bits/stdc++.h"

#define MOD 998244353
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct Edge{ll from, to, cost;};
struct node{ll cost, to;
  bool friend operator>(node a, node b){
    return a.cost>b.cost;
  }
};

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

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

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

ll fct[200100];
ll ifct[200100];

void gen(){
  fct[0]=1;
  ifct[0]=1;
  rep(i, 200010){
    fct[i+1] = mod(fct[i]*(i+1), MOD);
    ifct[i+1] = modinv(fct[i+1], MOD);
  }
}

ll comb(ll n, ll k){
  ll tmp = fct[n];
  tmp = mod(tmp*ifct[k],MOD);
  tmp = mod(tmp*ifct[n-k],MOD);
  return tmp;
}

/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N, M, K;
  cin >> N >> M >> K;
  ll ans = 0;
  gen();
  rep(i, K+1){
    ll tmp = mod(M*modpow(M-1, N-1-i, MOD),MOD);
    tmp = mod(tmp*comb(N-1, i), MOD);
    ans = mod(ans + tmp, MOD);
  }

  cout << ans;

  return 0;
}


Measured memory_bytes: 6680
#include<bits/stdc++.h>
using namespace std;
char a,b;
int main()
{
	cin>>a>>b;
	if(a=='H')
	{
		if(b=='H')
		cout<<'H'<<endl;
		else
		cout<<'D'<<endl;
	}
	else
	{
		if(b=='D')
		cout<<'H'<<endl;
		else
		cout<<'D'<<endl;
	}
	return 0;
}

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

int main()
{
  unsigned a, b;
  while ( cin >> a >> b ) {
    unsigned count = 0, n = a + b;
    if ( n )
      count++;
    while ( n /= 10 )
      count++;
    cout << count << endl;
  }

  return 0;
}

Measured memory_bytes: 1152
#include<stdio.h>
int main()
{
    int n,i;
    int x[105],y[105],z[105];
    char a[105];
    scanf("%d",&n);
    getchar();
    scanf("%s",a);
    //for(i=0;i<n;i++)
        //printf("%c",a[i]);
    //printf("\n");
    x[0]=y[0]=0;
    for(i=0;i<n;i++)
        x[i]=y[i]=z[i]=0;
    for(i=0;i<n;i++)
    {
        if(i==0)
            {
            if(a[i]=='I')
            x[0]=1;
            }
        else
         {
             if(a[i]=='I')
             x[i]=x[i-1]+1;
             else
                x[i]=x[i-1];
         }
    }
    for(i=0;i<n;i++)
    {
        if(i==0)
            {
            if(a[i]=='D')
            y[0]=1;
            }
        else
         {
             if(a[i]=='D')
             y[i]=y[i-1]+1;
             else
                y[i]=y[i-1];
         }
    }
    //for(i=0;i<n;i++)
       // printf("%d %d\n",x[i],y[i]);
    int maxn=0;
    for(i=0;i<n;i++)
        {
            z[i]=x[i]-y[i];
            if(z[i]>maxn)
                maxn=z[i];
        }
        printf("%d",maxn);
}


Measured memory_bytes: 128
#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;
    rep(i,s.size()){
        cout << 'x';
    }
}

Measured memory_bytes: 3624
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n,m,Q;
  cin >> n >> m >> Q;
  vvi v(n, vi(n, 0));
  rep(i, m){
    int l,r;
    cin >> l >> r;
    l--; r--;
    v[l][r]++;
  }
  vvi rui(n + 1, vi(n + 1, 0));
  rep(i, n) rep(j, n) rui[i + 1][j + 1] = rui[i + 1][j] + rui[i][j + 1] - rui[i][j] + v[i][j];
  rep(i, Q){
    int p,q;
    cin >> p >> q;
    p--;
    int ans = rui[q][q] - rui[q][p] - rui[p][q] + rui[p][p];
    cout << ans << endl;
  }
}

Measured memory_bytes: 2944
import scala.io.StdIn.readLine

object Main {

  def main(args: Array[String]) = {

    def read:Unit = {
      var n = readLine.split(" ").map(_.toInt)

      if( n(0) != 0 || n(1) != 0) {
        (1 to n(0)).foreach(s=> {
          (1 to n(1)).foreach(t=> {
            if((s+t)%2==0)
              print("#")
            else
              print(".")
          })
          println()
        })
        println()
        read
      }
    }
    read
  }
}

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

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

	vector<vector<int>> jb( M );
	for( int i = 0; i < N; ++i ) {
		int A, B;
		cin >> A >> B;

		if( A <= M ) {
			jb.at( M-A ).push_back( B );
		}
	}

	int result = 0;
	priority_queue<int> q;

	for( int i = M-1; i >= 0; --i ) {
		for( auto v: jb.at( i ) ) {
			q.push( v );
		}

		if( !q.empty() ) {
			result += q.top();
			q.pop();
		}
	}

	cout << result << endl;
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>

#define DIV 1000000007
using namespace std;
using ll = long long;
using ldb = long double;

int N, Q;
string s;
vector<pair<char, char>> qs;
vector<int> ter;
int mv(int n) {
	if (ter[n] != -2)return ter[n];
	int Q = qs.size();
	int now = n;
	//cout << "n=" << n << endl;
	for (int i = 0; i < Q; i++) {
		if (qs[i].first == s[now]) {
			if (qs[i].second == 'L')now--;
			if (qs[i].second == 'R')now++;
		}
		if (now <= -1) return ter[n] = -1;
		if (now >= N)return ter[n] = N;
		//cout << "now=" << now << endl;
	}

	return ter[n] = now;
}

int main() {
	cin >> N >> Q;
	cin >> s;
	qs = vector<pair<char, char>>(Q);
	for (int i = 0; i < Q; i++) {
		cin >> qs[i].first >> qs[i].second;
	}

	ter = vector<int>(N, -2);
	int L = -1;
	int left = 0, right = N - 1;
	while (left < right) {
		int mid = (left + right + 1) / 2;
		if (mv(mid) == -1)left = mid;
		else right = mid - 1;
	}
	if (mv(left) == -1) L = left + 1;
	else L = 0;
	//cout << "L=" << L << endl;


	int R = -1;
	left = 0, right = N - 1;
	while (left < right) {
		int mid = (left + right) / 2;
		if (mv(mid) == N)right = mid;
		else left = mid + 1;
	}
	if (mv(right) == N) R = N - right;
	else R = 0;
	//cout << "R=" << R << endl;

	cout << N - min(N, L + R) << endl;

}


Measured memory_bytes: 4660
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		long a = sc.nextLong();
		// スペース区切りの整数の入力
		long b = 0;
		long c = 7;
      boolean d = true;
		for(long i = 0; i < a && d; i++){
          c = c % a;
			b += c;
          
			c = c * 10;
			if(b % a == 0){
				System.out.println(i + 1);
              d = false;
			}
		} 
      if(d){
			System.out.println("-1");
		}

		
		
	}
}

Measured memory_bytes: 35696
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <stdio.h>

int main(){
  long long n,s=0;
  std::cin >> n;
  for(int i=1;i<=n;i++){
    if(i%3!=0&&i%5!=0){
      s+=i;
    }
  }
  std::cout << s;
  return 0;
}

Measured memory_bytes: 3612
# -*- coding:utf-8 -*-
from itertools import combinations
import copy

def solve2():
    """
    itertools.productを使えばもっとすっきり？
    """
    import itertools as it
    N, M = list(map(int, input().split()))
    K = []
    S = []
    for i in range(M):
        _in = list(map(int, input().split()))
        K.append(_in[0])
        S.append(_in[1:])
    P = list(map(int, input().split()))

    switch_stats = it.product((0,1), repeat=N)

    ans = 0
    for stats in switch_stats:
        is_ok = True
        for i in range(M):  # すべての電球において
            on_num = 0
            for s_i in S[i]:
                on_num += 1 if stats[s_i-1]==1 else 0
            if on_num%2 == P[i]:
                continue
            else:
                is_ok = False
        
        if is_ok:
            ans += 1
    
    print(ans)


def solve():
    N, M = list(map(int, input().split()))
    K = []
    S = []
    for i in range(M):
        _in = list(map(int, input().split()))
        K.append(_in[0])
        S.append(_in[1:])
    P = list(map(int, input().split()))

    """
    全探索
    計算量 O(2^N * M * max(len(S)))
    N=10, M=10でも、1024 * 10 * 10 くらい？
    """
    def dfs(switch_stats):
        if len(switch_stats)==N:
            is_ok = True
            for i in range(M):
                on_num = 0
                for switch_i in S[i]:
                    on_num += 1 if switch_stats[switch_i-1] == 1 else 0
                if on_num%2 == P[i]:
                    continue
                else:
                    is_ok = False
                    break
            
            if is_ok:
                return 1
            else:
                return 0
        switch_stats1 = copy.deepcopy(switch_stats)
        switch_stats1.append(0)
        ret1 = dfs(switch_stats1)
        switch_stats2 = copy.deepcopy(switch_stats)
        switch_stats2.append(1)
        ret2 = dfs(switch_stats2)
        return ret1 + ret2

    ans = dfs([])
    print(ans)


if __name__ == "__main__":
    solve2()


Measured memory_bytes: 3444
N, M, X, Y = list(map(lambda a: int(a), input().split(" ")))
x = list(map(lambda b: int(b), input().split(" ")))
y = list(map(lambda c: int(c), input().split(" ")))
x.append(X)
y.append(Y)
x.sort()
y.sort()
if x[-1] < y[0]:
  print("No War")
else:
  print("War")


Measured memory_bytes: 9048
require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
s,t = gets.chomp.split
a,b = gets.chomp.split.map(&:to_i)
u = gets.chomp

if s == u
  puts [a-1,b].join(' ')
elsif t == u
  puts [a,b-1].join(' ')
end

Measured memory_bytes: 2300
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstring>
#include <deque>
#include <stack>
#include <stdio.h>
#include <map>
#include <set>
#include <time.h>
#include <string>
#include <fstream>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <assert.h>
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define pdd pair<double,double>
#define pii pair<ll,ll>
#define PI 3.14159265358979323846
#define MOD 1000000007
#define MOD2 1000000009
#define INF ((ll)1e+18)
#define x1 fldgjdflgjhrthrl
#define x2 fldgjdflgrtyrtyjl
#define y1 fldggfhfghjdflgjl
#define y2 ffgfldgjdflgjl
#define N 131072
#define SUM 377
#define MAG 33554431
#define RED 0
#define BLUE 1
#define maxlen 300500
typedef long long ll;
typedef long double ld;
using namespace std;
ll i,j,n,k,l,m,tot, flag,r,ans,z, K,x1,y1,x2,y2,x3,y3,x,y,h,num,h2,timer,sz,q,nn;
string s,t;
ll a[100500];
int main() {
	//freopen("input.txt","r",stdin);
 	//freopen("output.txt","w",stdout);
    cin >> n;
    for (i = 0; i < n; i++)
        cin >> a[i];
    ans = 1;
    for (i = 0; i < n; i++)
    {
        if (a[i]+1 == a[i+1] && a[i] <= k*2+1)
        {
            ans = (ans*(k+2))%MOD;
            i++;
        }
        k++;
    }
    for (i = 1; i <= k; i++)
        ans = ans*i%MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
n = int(input())
x = [int(n) for n in input().split()]
y = [int(n) for n in input().split()]
for p in range(1, 4):
    print((sum([abs(a-b)**p for a, b in zip(x, y)])**(1/p)))
print(max([abs(a-b) for a,b in zip(x, y)]))



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

int main() {
  int a, b, c, d;
  double e, f;
  cin >> a >> b >> c >> d >> e >> f;
  double t = 0;
  int p = 0;
  int q = 0;
  bool x = false;
  for (int i = 0; 100 * i <= f; i += a) {
    for (int j = 0; 100 * i + 100 * j <= f; j += b) {
      for (int k = 0; 100 * i + 100 * j + k <= f; k += c) {
        for (int l = 0; 100 * i + 100 * j + k + l <= f; l += d) {
          double w = 100 * i + 100 * j;
          double s = k + l;
          if (w == 0) {
            continue;
          }
          if (s / w > t && s / w <= e / 100) {
            t = s / w;
            p = w + s;
            q = s;
            x = true;
          }
        }
      }
    }
  }
  if (x) cout << p << " " << q << endl;
  else cout << a * 100 << " " << 0 << endl;
}

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

int main(){
  int n;
  long long int l[87];
  cin>>n;
  l[0]=2,l[1]=1;
  rep(i,2,n+1){
    l[i]=l[i-1]+l[i-2];
  }
  
  cout<<l[n];
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
int arr[1001][1001];
const int mod=1000000007;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string v[1001];	
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>v[i];
	}
	arr[0][0]=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(v[i][j]=='.'){
				if(i-1>=0)arr[i][j]+=arr[i-1][j];
				if(arr[i][j]>=mod)arr[i][j]-=mod;
				if(j-1>=0)arr[i][j]+=arr[i][j-1];
				if(arr[i][j]>=mod)arr[i][j]-=mod;
			}
		}
	}
	cout<<arr[n-1][m-1]<<endl;
	return 0;
}

Measured memory_bytes: 5248
#include <stdio.h>

int main(){
  int a,b;
  double x1,y1,x2,y2,x3,y3,x4,y4;
  scanf("%d",&a);
  for(b=0;b<a;b++){
    scanf("%lf %lf %lf %lf %lf %lf %lf %lf",
      &x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
    if((y2-y1)*(x4-x3) == (y4-y3)*(x2-x1)) printf("YES\n");
      else printf("NO\n");
  }
  return 0;
}

Measured memory_bytes: 0
# -*- coding: utf-8 -*-
from functools import reduce

n = int(input())
i = 1

while True:

    a = [int(x) for x in list(str(i))]

    if 3 in a:
        print(" {0}".format(int(reduce(lambda x, y: x + y, [str(x) for x in a]))), end='')
    elif sum(a) % 3 == 0:
        print(" {0}".format(int(reduce(lambda x, y: x + y, [str(x) for x in a]))), end='')

    i += 1
    if i > n:
        print()
        break



Measured memory_bytes: 6532
def isprime(x):
    i = 2
    while i * i <= x:
        if x % i == 0: return False
        i += 1
    return True

n = int(input())
xs = []
for i in range(n):
    x = int(input())
    xs.append(x)

print(sum(1 for x in xs if isprime(x)))


Measured memory_bytes: 5980
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
import std.concurrency;
void times(alias fun)(int n) {
    foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(int n) {
    T[] res = new T[n];
    foreach(ref e; res) e = fun();
    return res;
}
void main() {
    readln.chomp.to!int.pipe!(
        n => n*800 - n/15*200
    ).writeln;
}

// ----------------------------------------------

// fold was added in D 2.071.0
static if (__VERSION__ < 2071) {
    template fold(fun...) if (fun.length >= 1) {
        auto fold(R, S...)(R r, S seed) {
            static if (S.length < 2) {
                return reduce!fun(seed, r);
            } else {
                return reduce!fun(tuple(seed), r);
            }
        }
    }
}

// minElement/maxElement was added in D 2.072.0
static if (__VERSION__ < 2072) {
    auto minElement(alias map, Range)(Range r)
    if (isInputRange!Range && !isInfinite!Range)
    {
        alias mapFun = unaryFun!map;
        auto element = r.front;
        auto minimum = mapFun(element);
        r.popFront;
        foreach(a; r) {
            auto b = mapFun(a);
            if (b < minimum) {
                element = a;
                minimum = b;
            }
        }
        return element;
    }
    auto maxElement(alias map, Range)(Range r)
    if (isInputRange!Range && !isInfinite!Range)
    {
        alias mapFun = unaryFun!map;
        auto element = r.front;
        auto maximum = mapFun(element);
        r.popFront;
        foreach(a; r) {
            auto b = mapFun(a);
            if (b > maximum) {
                element = a;
                maximum = b;
            }
        }
        return element;
    }
}


Measured memory_bytes: 256
#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) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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 N;
vll A, B, C, tmp;

int main()
{
    cin >> N;
    A.resize(N);
    rep(i, N)
    {
        cin >> A[i];
    }
    sort(all(A), greater<int>());
    ll ans1 = 0, ans2 = 0;
    if (N % 2 == 1)
    {
        rep(i, (N - 1) / 2)
        {
            ans1 += 2 * A[i];
            ans2 -= 2 * A[N - 1 - i];
        }
        rep(i, (N - 3) / 2)
        {
            ans1 -= 2 * A[N - 1 - i];
            ans2 += 2 * A[i];
        }
        ans1 -= A[N / 2] + A[N / 2 + 1];
        ans2 += A[N / 2] + A[N / 2 - 1];
    }
    else
    {
        rep(i, (N - 1) / 2)
        {
            ans1 += 2 * A[i];
            ans2 -= 2 * A[N - 1 - i];
        }
        rep(i, (N - 1) / 2)
        {
            ans1 -= 2 * A[N - 1 - i];
            ans2 += 2 * A[i];
        }
        ans1 += abs(A[N / 2] - A[N / 2 - 1]);
        ans2 += abs(A[N / 2] - A[N / 2 - 1]);
    }

    cout << max(ans1, ans2);
    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 10000;
const int MAX_P = 10;

/* typedef */

/* global variables */

int n, m;
int rds[MAX_P + 1];

/* subroutines */

/* main */

int main() {
  for (;;) {
    cin >> n >> m;
    if (n == 0) break;

    memset(rds, 0, sizeof(rds));
    
    for (int i = 0; i < n; i++) {
      int di, pi;
      cin >> di >> pi;
      rds[pi] += di;
    }

    for (int p = MAX_P; p >= 0; p--) {
      if (m >= rds[p]) {
	m -= rds[p];
	rds[p] = 0;
      }
      else {
	rds[p] -= m;
	break;
      }
    }

    int sum = 0;
    for (int p = 0; p <= MAX_P; p++)
      sum += rds[p] * p;

    cout << sum << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>

#define MIN(x, y) (x < y ? x : y)
#define MAX(x, y) (x > y ? x : y)

using namespace std;


int main(){
	string A, B, C;
	cin >> A >> B >> C;

	cout << A[0] << B[1] << C[2] << endl;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;

int main() {
    ull N, A, B, C, D, E, min_abcde;
    cin >> N >> A >> B >> C >> D >> E;

    min_abcde = min({A, B, C, D, E});
    cout << 4 + (N + min_abcde -1) / min_abcde << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<iostream>

using namespace std;

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	int count_5 = 0;
	int count_7 = 0;
	if (A == 5) {
		count_5++;
	}
	if (A == 7) {
		count_7++;
	}
	if (B == 5) {
		count_5++;
	}
	if (B == 7) {
		count_7++;
	}
	if (C == 5) {
		count_5++;
	}
	if (C == 7) {
		count_7++;
	}

	if (count_5 == 2 && count_7 == 1)
		cout << "YES";
	else
		cout << "NO";

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  int n, k, sum=0, temp, i, j;
  scanf("%d %d", &n, &k);
  int a[n];
  for(i=0;i<n;i++)
  {
      scanf("%d", &a[i]);
  }
  for(i=0;i<n;i++)
  {
      for(j=i+1;j<n;j++)
      {
          if(a[i]>a[j])
          {
              temp=a[i];
              a[i]=a[j];
              a[j]=temp;
          }
      }
  }
  for(i=0;i<k;i++)
  {
      sum=sum+a[i];
  }
  printf("%d", sum);
  return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    int a,b,c;
    cin >> a >> b >> c;
    if(a==b)cout << c << endl;
    else if (b==c) cout << a << endl;
    else cout << b << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const int MOD = 1e9+7;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;


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

    cout << ((ceil(n/2))/(int)n) << endl;



    

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define pb          push_back
#define eb 			emplace_back
#define mp 			make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define si          second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define checkbit(n, b) ((n >> b) & 1)
#define mod        1000000007
#define inf        1000000000000000000
#define puts(n)		cout<<n;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define setbits(x) __builtin_popcount(x)
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	ll ans=0;
	while(n-500>=0){
		n-=500;
		ans+=1000;
	}
	while(n-5>=0){
		n-=5;
		ans+=5;
	}
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 256
n = gets.chop.to_i
s = gets.chop.split('')
max = 0
(0..s.length-2).each do |i|
  checked = {}
  count = 0
  left, right = s[0..i], s[i+1..s.length-1]
  left.each do |e|
    next if !checked[e].nil?
    if right.include?(e)
      count += 1
      checked[e] = true
    end
  end
  max = [max, count].max
end

p max


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

using namespace std;

int main()
{
    int n;
    cin>>n;
    int b = n;
    int sum=0;
    while(n!=0){
        sum = sum + n%10;
        n=n/10;
    }
    if(b%sum!=0){
        cout<<"No"<<endl;
    }
    else {
        cout<<"Yes"<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
from itertools import combinations
import sys


def solve(a: int, b: int, c: int, d: int, e: int, k: int):
    print(":(" if any(
        abs(x1 - x2) > k
        for x1, x2 in combinations([a, b, c, d, e], 2)
    ) else "Yay!")


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    c = int(next(tokens))  # type: int
    d = int(next(tokens))  # type: int
    e = int(next(tokens))  # type: int
    k = int(next(tokens))  # type: int
    solve(a, b, c, d, e, k)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        Random rand = new Random();
        int d = ni();
        int[] c = new int[26];
        for (int i = 0; i < 26; i++) {
            c[i] = ni();
        }
        int[][] s = new int[d][26];
        for (int i = 0; i < d; i++) {
            for (int j = 0; j < 26; j++) {
                s[i][j] = ni();
            }
        }

        int count = 0;
        long maxscore = 0;
        int[] best = new int[d];
        while(count<10000){
            int[] t = new int[d];
            for (int i = 0; i < t.length; i++) {
                t[i] = rand.nextInt(26);
            }
            long score = 0;
            int[] last = new int[26];
            for (int i = 1; i <= d; i++) {
                score += s[i-1][t[i-1]];
                last[t[i-1]] = i;
                for (int j = 0; j < 26; j++) {
                    score -= c[j]*(i-last[j]);
                }
            }
            if(maxscore < score){
                System.out.println(score);
                maxscore = score;
                best = t;
            }
            count++;
        }
        for (int i = 0; i < d; i++) {
            out.println(best[i]+1);
        }

    }

 
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i, a, b) for (int i = (a) ; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define sp system("pause")
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
const int N = (int) 1e5 + 10;
void TimeExecution() {
    cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}
int t;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    */
    ll h, res = 0;
    cin >> h;
    ll lim = ceil(log2(h));
    FOR(i, 0, log2(h))
    {
        res += (1LL << i);
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;


int main(){
	int n; cin >> n;
	
	vector<ll> a(n);
	ll mini = INF64; ll maxi = -INF64;
	ll i1,i2;
	for(int i = 0; i < n; ++i){
		cin >> a[i];
		if(maxi < a[i]){maxi =a[i];i1 = i;}
		if(mini >a[i]){mini =a[i];i2=i;}
    }
    
    if(abs(maxi)>=abs(mini)){
cout << 2* n-2 << endl;
    	for(int i = 0; i < n; ++i){
    	    if(i1==i){continue;}
    	    cout << i1+1 << " " << i+1<< endl;
        }
        for(int i = 0; i < n-1; ++i){
        	cout << i+1<< " "  << i+2 << endl;
        }
     }
     else if(abs(maxi)<abs(mini)){
cout << 2* n-2 << endl;
     	for(int i = 0; i < n; ++i){
    	    if(i2==i){continue;}
    	    cout << i2+1 << " " << i+1<< endl;
        }
        for(int i = n-1; i >= 1; --i){
        	cout << i+1 << " " << i << endl;
        }
     }
     else{
     	cout << 0 << endl;
     }
    
    return 0;
}

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

using namespace std;

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;i++)
#define FORVEC(i, v) for(int i = 0;i < v.size();i++)

#define INF 1000000000
#define pb(a) push_back(a)
#define llong long long

int main(){
	char S[7];
	int a=0;
	cin>>S;
	REP(i,6){
		if(S[i]=='1')a++;
	}
	cout<<a<<endl;
	return 0;
}


Measured memory_bytes: 256
def solve(m,k):
    n=2**m
    if k>n-1:
        return [-1]
    if k==0:
        Ret=[]
        for i in range(n):
            Ret.append(i); Ret.append(i)
        return Ret
    if m==1:
        return [-1]
    Used=[False]*n
    Used[0]=True; Used[k]=True
    Pair=[]
    for i in range(1,n):
        if Used[i]:
            continue
        Pair.append([i,k^i])
        Used[i]=True; Used[k^i]=True
    A=[]
    for a,b in Pair:
        A.append(a); A.append(b)
    Ret=A+[0,k,0]+A[::-1]+[k]
    return Ret

m,k=map(int,input().split())
Ans=solve(m,k)
print(*Ans)

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

int main()
{
	int n;
	cin>>n;
	int arr[n],dp[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
		dp[i]=INT_MAX;
	}
	dp[0]=0;
	for(int i=1;i<n;i++)
	{
		if(i==1)
			dp[i]=min(dp[i],dp[0]+abs(arr[0]-arr[1]));
		else
		{
			dp[i]=min(dp[i-1]+abs(arr[i-1]-arr[i]),dp[i-2]+abs(arr[i-2]-arr[i]));
		}
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1024
def index_1_sumall(list):
    return list[1]


n, m = tuple(int(i) for i in input().split(" "))
num_list = [int(i) for i in input().split(" ")]
num_list.sort()
change_list = []
ans_list = []
for j in range(m):
    change_list.append([int(i) for i in input().split(" ")])
change_list.sort(key=index_1_sumall, reverse=1)
break_is = 0
for i in change_list:
    for j in range(i[0]):
        try:
            if i[1] > num_list[0]:
                num_list.pop(0)
                ans_list.append(i[1])
            else:
                break_is = 1
                break
        except IndexError:
            break_is = 1
            break
    if break_is:
        break
num_list.append(0)
print(sum(num_list) + sum(ans_list))


Measured memory_bytes: 26944
# Grid Coloring
H,W = list(map(int, input().split()))
N = int(input())
a = list(map(int, input().split()))

from itertools import chain
b = list(chain.from_iterable( [[i+1]*a[i] for i in range(N)] ))
#print(b)
c = [b[i*W:(i+1)*W] if i%2==0 else b[i*W:(i+1)*W][::-1] for i in range(H)]

for i in range(H):
    print(' '.join(map(str, c[i])))

Measured memory_bytes: 4596
INF = 10**9
nn = [[0,-1], [1,0], [0,1], [-1, 0]]
warp_index = [*-2..2]

h, w = gets.split.map(&:to_i)
c_h, c_w = gets.split.map{ _1.to_i - 1}
d_h, d_w = gets.split.map{ _1.to_i - 1}
s = h.times.map { gets.chomp.chars }

dist = Array.new(h).map { Array.new(w, INF) }
dist[c_h][c_w] = 0
queue = [[c_h, c_w]]
d = 0
loop do
  warp_q = []
  while q = queue.shift
    x, y = q
    nn.each do |nnx, nny|
      nni = x + nnx
      nnj = y + nny
      next if nni < 0 || nnj < 0 || nni >= h || nnj >= w
      next if dist[nni][nnj] <= d
      if s[nni][nnj] == '#'
        warp_q << [x, y]
      else
        queue << [nni, nnj]
      end

      dist[nni][nnj] = d
    end
  end

  d += 1
  warp_q.uniq.each do |wx, wy|
    warp_index.each do |warp_i|
      nni = wx + warp_i
      next if nni < 0 || nni >= h
      warp_index.each do |warp_j|
        nnj = wy + warp_j
        next if nnj < 0 || nnj >= w
        next if dist[nni][nnj] <= d
        next if s[nni][nnj] == '#'

        dist[nni][nnj] = d
        queue << [nni, nnj]
      end
    end
  end
  queue.uniq!
  break if queue.empty?
end

d = dist[d_h][d_w]
puts d == INF ? '-1' : d

Measured memory_bytes: 105424
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

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

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

ll fastpow(ll base, ll index)
{
	ll ret = 1;
	while(index)
	{
		if(index & 1) ret = (ret * base) % MOD;
		index /= 2;
		base = (base * base) % MOD;
	}
	return ret;
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen(".in.txt", "r", stdin);
	freopen(".out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n; cin >> n;
	ll ans = fastpow(10, n) - 2 * fastpow(9, n) + fastpow(8, n);
	while(ans < 0) ans += MOD;
	cout << ans;

	return 0;
}

Measured memory_bytes: 3640
N = int(input())
from collections import defaultdict
res = defaultdict(list)
for i in range(N):
    S1,P1 = input().split()
    res[S1].append([int(P1),i])

for k,v in sorted(res.items()):
    lists = sorted(res[k],reverse=True)
    # print(lists)
    for l in lists:
        print(l[1]+1)

Measured memory_bytes: 3316
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] H = new int[N];
        for (int i = 0; i < N; i++) {
            H[i] = sc.nextInt();
        }

        long ans=0;

        Arrays.sort(H);

        if(H.length <= K){
            System.out.println(0);
        }else{
            for (int i = 0; i < N - K; i++) {
                ans += H[i];
            }
            System.out.println(ans);
        }

    }
}


Measured memory_bytes: 64952
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    n,k = map(int, input().split())
    a = [0] + list(map(int, input().split()))
    a = list(accumulate(a))
    d = {}
    res = 0
    for i in range(n+1):
        b = (i - a[i]) % k
        if i - k < 0:
            if b not in d:
                d[b] = 1
            else:
                res += d[b]
                d[b] += 1
        else:
            j = i - k
            c = (j - a[j]) % k
            d[c] -= 1
            if b not in d:
                d[b] = 1
            else:
                res += d[b]
                d[b] += 1
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 105036
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)
#define INF 1<<29;

int main()
{
    int n,i;
    cin >> n >> i;
    cout << n-i+1 << endl;  
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;

int gcd(int x, int y) {
	int r;
	if (x < y) swap(x, y);

	while (y > 0) {
		r = x%y;
		x = y;
		y = r;
	}
	return x;
}

bool IsK(int N, int K, int A[]) {
	int maximum=0;
	for (int i = 0;i < N;i++) {
		if (maximum < A[i]) maximum = A[i];
	}
	if (K > maximum) return 0;

	int pre;
	pre = gcd(A[0], A[1]);
	for (int i = 2;i < N;i++) {
		pre = gcd(pre, A[i]);
	}

	if (K%pre == 0) return 1;
	else return 0;
}

int main() {
	int N, K, A[100005];
	cin >> N >> K;
	for (int i = 0;i < N;i++) {
		cin >> A[i];
	}

	if(IsK(N,K,A)) cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<math.h>
int main(){
  unsigned long long int in1,in2,in3,in4,r,a,b,lcm,sum = 0;
  scanf("%lld %lld %lld %lld",&in1 ,&in2 ,&in3 ,&in4);
  //sum = in2 - in1 + 1;
  
  if(in3 < in4){
    a = in4; b = in3;
  }else{
    b = in4; a = in3;
  }
  
  sum += (in2 - in1 + 1) - (((in2/in3) - (in1 - 1)/in3) + ((in2/in4) - (in1 - 1)/in4));
  
  r = a % b;
  while(r != 0){
    a = b;
    b = r;
    r = a % b;
  }
  
  lcm = in3 * in4 / b;
  sum += (in2/lcm) - (in1 - 1)/lcm;
  
  printf("%llu\n",sum);

  return 0;
}

Measured memory_bytes: 128