akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{

    static class Program
    {
        static void Main()
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            //

            int N;long T;
            Multi(out N, out T);
            long[] t = GetLongArray();

            long ans = 0;
            for(int i = 0; i < N - 1; i++)
            {
                ans += t[i + 1] - t[i] > T ? T : t[i + 1] - t[i];
            }
            ans += T;

            Console.WriteLine(ans);

            //
            Console.Out.Flush();
            Console.ReadKey();
        }

        static void Solve()
        {

        }

        static long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; }


        static public string GetStr() { return Console.ReadLine().Trim(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public char[] GetCharArray() { return Console.ReadLine().Split(' ').Select(char.Parse).ToArray(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
        static string yesno(this bool b) { return b ? "yes" : "no"; }
        static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c, out V d)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<V>(ar[3]);
        }
    }
}

Measured memory_bytes: 30880
using System;

public class hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var n = int.Parse(line[0]);
            var k = int.Parse(line[1]);
            if (n == 0 && k == 0) break;
            var ary = new int[n];
            for (int i = 0; i < n; i++) ary[i] = int.Parse(Console.ReadLine().Trim());
            var totalmax = 0;
            var tempmax = 0;
            for (int i = 0; i < k; i++)
                tempmax += ary[i];
            for (int i = k; i < n; i++)
            {
                tempmax += ary[i];
                tempmax -= ary[i - k];
                totalmax = Math.Max(totalmax, tempmax);
            }
            Console.WriteLine(totalmax);
        }
    }
}

Measured memory_bytes: 10064
N, M, Q = list(map(int, input().split()))
A = []
B = []
C = []
D = []

for i in range(Q):
    a,b,c,d = map(int, input().split())
    A.append(a)
    B.append(b)
    C.append(c)
    D.append(d)

listA = list(range(1,N+1))
ANS = 0

import itertools
for i in itertools.combinations_with_replacement(range(1,M+1), N):
    f = 0
    for j in range(len(i)-1):
        if not i[j] <= i[j+1]:
            f=1
    if f == 0:
        #print(i)
        ans = 0
        for q in range(Q):
            if i[B[q]-1] - i[A[q]-1] == C[q]:
                ans += D[q]
        ANS = max([ANS, ans])
print(ANS)
#print(ANS)

Measured memory_bytes: 9196
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func cmb(x, y int) int {
	if y > x {
		return 0
	}

	nu, de := 1, 1
	for i := 0; i < y; i++ {
		nu = nu * (x - i)
		de = de * (i + 1)
		if nu%de == 0 {
			nu /= de
			de = 1
		}
	}
	return nu / de
}

func main() {
	n, p := scanInt(), scanInt()
	e, o := 0, 0
	for i := 0; i < n; i++ {
		a := scanInt()
		if a%2 == 0 {
			e++
		} else {
			o++
		}
	}
	ans := 0
	for i := 0; i <= n; i++ {
		for j := p; j <= i; j += 2 {
			ans += cmb(o, j) * cmb(e, i-j)
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll i,j,k,n,t,m,p;
	cin>>n;
	ll maxim=INT_MIN;
	for(i=2;i<=n;i++)
	{
		k=i;
		while(k<=n)
		{
			k=k*i;
			if(k<=n)
			maxim=max(maxim, k);
		}
	}
	if(maxim==INT_MIN)
	cout<<"1"<<endl;
	else
	cout<<maxim<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define inputv(arr,n) for(ll i=0;i<n;i++){ll value;cin>>value;arr.pb(value);}
#define sz(a) ((ll)(a).size())
#define len(a) ((ll)(a).length())
#define precise cout<<fixed<<setprecision(0); 
#define F first
#define S second
#define vi vector <int> 
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define YES cout<<"Yes\n"
#define NO cout<<"No\n"
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
inline ll max(ll a,ll b)
{return ((a>b)?a:b);}
inline ll min(ll a,ll b)
{return ((a>b)?b:a);}
inline ll gcd(ll a ,ll b)
{if(b==0) return a;a%=b;return gcd(b,a);}
#define nl cout<<"\n"
using namespace std;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
// hashing for pairs
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};
//sort in reverse order
bool compare(ll x, ll y){
    return x>y;
}
void solve()
{
  ll k;
  cin>>k;
  ll val=7;
  rep(i,k)
  {
    if(val%k==0)
    {
      cout<<i+1;nl;
      return;
    }
    else
    {
      val = (val*10+7)%k;
    }
    
  }
  cout<<-1;nl;
  return;
}
int main()
{
    IOS;
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 3816
#include <stdio.h>

int main(void) {
	int n,i,j,h,a,b,c,x,y,k;
	int d[9999];
	int e[9999];
	k=0;
	for(i=0;;i++){
	scanf("%d",&n);
	if(n==0){
		break;
	}
	for(j=0;j<n;j++){
		scanf("%d %d %d",&a,&b,&c);
		if(j==0){
			x=a;
			y=b+c;
		}else if(j>0){
			if(y<b+c){
				x=a;
				y=b+c;
			}
		}
	}
	d[i]=x;
	e[i]=y;
	k=k+1;
	}
	for(h=0;h<k;h++){
	printf("%d %d\n",d[h],e[h]);
	}
	return 0;
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mod 1000000007
#define ll long long int
#define pi 3.141592653589793238
int val[5];
int main(){
	ll s;
    cin>>s;
    if(s<3)
    {
        cout<<0;
        return 0;
    }
    else
    {
        vector<ll> dp(s+1,0);
        dp[0]=1;
        for(int i=3;i<=s;i++)
            for(int j=i-3;j>=0;j--)
                dp[i]=(dp[i]+dp[j])%mod;
        cout<<dp[s]%mod;
    }
    return 0;
}




Measured memory_bytes: 3620
#include<iostream>
using namespace std;
main()
{
    string a,b;
    cin>>a;
    cin>>b;
    int length=a.size();
    int i,days=0;
    for(i=0;i<length;i++)
    {
        if(a[i]==b[i])
        {
            days++;
        }
    }
    cout<<days;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
using namespace std;
#define ll long long

int main () {
  int d;
  cin >> d;
  if (d == 25) {
    cout << "Christmas" << endl;  
  }
  if (d == 24) {
    cout << "Christmas Eve" << endl;  
  }
  if (d == 23) {
    cout << "Christmas Eve Eve" << endl;  
  }
  if (d == 22) {
    cout << "Christmas Eve Eve Eve" << endl;
  }
  
}

Measured memory_bytes: 888
import sys
import math
import bisect

def main():
    n, m = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort(reverse=True)
    total = sum(A)
    #print('A: %s' % str(A))
    ans = True
    for i in range(m):
        if A[i] * 4 * m < total:
            ans = False
            break
    if ans:
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define endl "\n"
#define ll long long int
#define ain cin>>
#define aout cout<<
#define avec vector<int>
#define aloop(i,k,n) for(int i=k;i<n;i++)
using namespace std;


int error(string s)
{	
	if(count(s.begin(),s.end(),'R')==0) return 0; //no R
	if(count(s.begin(),s.end(),'R')==1) return 1; //only one R
	if(count(s.begin(),s.end(),'R')==3) return 3; //no s
	if((s[0]=='R' && s[1]=='R')||(s[1]=='R' && s[2]=='R')) return 2;
	return 1;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 
    string str;
    ain(str);
    cout<<error(str)<<endl;
   return 0;
}

Measured memory_bytes: 3624
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

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

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

  vector<int> vec;
  vec.PB(a);
  vec.PB(b);
  vec.PB(c);

  sort(ALL(vec));

  cout << vec[0] << " " << vec[1] << " " << vec[2] << endl;

  return 0;
}

Measured memory_bytes: 1220
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

# import numpy as np
# from scipy.special import perm
# from scipy.special import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

########

N, W = l_inpl()
w, v = [], []
item = [[] for i in range(4)]

for i in range(N):
    wi, vi = l_inpl()
    if i == 0:
        item[0].append(vi)
        w_base = wi
    else:
        item[wi - w_base].append(vi)

w0, w1, w2, w3 = item
w0 = [0] + list(accumulate(sorted(w0, reverse=True)))
w1 = [0] + list(accumulate(sorted(w1, reverse=True)))
w2 = [0] + list(accumulate(sorted(w2, reverse=True)))
w3 = [0] + list(accumulate(sorted(w3, reverse=True)))

ans = 0
for i in range(len(w0)):
    for j in range(len(w1)):
        for k in range(len(w2)):
            tmp_weight = w_base * i + (w_base + 1) * j + (w_base + 2) * k
            if tmp_weight > W:
                continue
            l = min((W - tmp_weight) // (w_base + 3), len(w3) - 1)
            tmp_ans = w0[i] + w1[j] + w2[k] + w3[l]
            ans = max(ans, tmp_ans)

print(ans)


Measured memory_bytes: 40944
#include<stdio.h>
#include<string.h>
int main()
{
    int m1,d1,m2,d2;
    scanf("%d %d",&m1,&d1);
    scanf("%d %d",&m2,&d2);
    if(m1!=m2)
    {
    	printf("1\n");
    	
	}
	else
	{
		printf("0\n");
	}
	
}

Measured memory_bytes: 1608
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int A[200010];
    rep(i, N) cin >> A[i];
    ll ans = 0;
    int h = A[0];
    rep(i, N - 1) {
        ans += max(0, h - A[i + 1]);
        h = max(h, A[i + 1]);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4392
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <limits>
#include <iterator>
#include <cmath>
#include <numeric>
#include <stack>
#include <queue>
#include <cassert>
#include <forward_list>
#include <chrono>
#include <deque>
#include <list>
#include <random>
#include <cstdio>
#include <sstream>

using namespace std;

//最大公約数
template<class T>
inline T GCD(T m, T n)
{
	T temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

//最小公倍数
template<class T>
inline T LCM(T m, T n)
{
	return m * n / GCD(m, n);
}



int main()
{
	int n; cin >> n;
	vector<int> h(n);
	for (int i = 0; i < n; i++) { cin >> h[i]; }

	int ans = 0;
	while (true)
	{
		auto mid = find(h.begin(), h.end(), 0);
		int m = *min_element(h.begin(), distance(h.begin(),mid)? mid-1:mid);

		for (auto it = h.begin(); it < mid; ++it)
		{
			*it = *it - m > 0 ? *it - m : 0;
		}

		ans += m;

		auto iter = h.begin();
		for (auto it : h)
		{
			if (it != 0) { break; }
			iter++;
		}
		h.erase(h.begin(), iter);

		if (h.size() == 0) { break; }
	}

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

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

int main(){
	double r = 6378.1;
	double a,b,c,d;
	while( cin >> a >> b >> c >> d && b != -1 ){
		double theta = (90.0-a) * M_PI / 180.0;
		double phi = b * M_PI / 180.0;
		
		double x1 = r * sin(theta) * cos(phi);
		double y1 = r * sin(theta) * sin(phi);
		double z1 = r * cos(theta);
		theta =(90.0-c) * M_PI / 180.0;
		phi = d * M_PI / 180.0;
		double x2 = r * sin(theta) * cos(phi);
		double y2 = r * sin(theta) * sin(phi);
		double z2 = r * cos(theta);
		double co = (x1*x2+y1*y2+z1*z2) / (r*r);
		double rad = acos(co);
		printf("%.lf\n",rad*r);
	}
}

Measured memory_bytes: 1284
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define len(a) (int)a.size()
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
    int n; cin >> n;
    vector<ll> a(n); rep(i, n) cin >> a[i];
    vector<ll> s = a;
    rep(i, n-1) {
        s[i+1] += s[i];
        s[i+1] %= MOD;
    }
    ll ans = 0;
    for (int i = 1; i < n; i++) {
        ans += a[i] * s[i-1] % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 6356
import java.util.Scanner;

public class Main {
    public static int maximalValue(int[] A, int[] B) {
        A[0] = B[0];
        A[1] = B[0];
        for (int i = 1; i < B.length; i++) {
            if (B[i] > B[i-1]) {
                A[i+1] = B[i];
            } else {
                A[i+1] = B[i];
                A[i] = B[i];
            }
        }
        int res = 0;
        for (Integer i : A) res += i;
        return res;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int[] B = new int[N-1];
        int[] A = new int[N];
        for (int i = 0; i < B.length; i++) B[i] = in.nextInt();

        System.out.println(maximalValue(A, B));
    }
}


Measured memory_bytes: 21844
h, w = map(int, input().split())
s = []
for i in range(h):
    s.append(list(input()))

flag = False
for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            continue
        if i - 1 >= 0:
            if s[i - 1][j] == '#':
                continue
        if j - 1 >= 0:
            if s[i][j - 1] == '#':
                continue
        if i + 1 < h:
            if s[i + 1][j] == '#':
                continue
        if j + 1 < w:
            if s[i][j + 1] == '#':
                continue
        flag = True
        break
    if flag:
        break

if flag:
    print('No')
else:
    print('Yes')



Measured memory_bytes: 3064
N, M = list(map(int, input().split()))
H = list(map(int, input().split()))
AB = []
for i in range(M):
    _A, _B = list(map(int, input().split()))
    AB.append((_A, _B))
bad_tower_set = set()
for ab in AB:
    a, b = ab
    a -= 1
    b -= 1
    if H[a] <= H[b]:
        bad_tower_set.add(a)
    if H[b] <= H[a]:
        bad_tower_set.add(b)
print(N - len(set(bad_tower_set)))

Measured memory_bytes: 33020
#include <iostream>
#define llint long long
#define mod 1000000007

using namespace std;

llint n, k;
llint a[105];
llint dp[105][100005];
llint sum[100005];

int main(void)
{
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	dp[0][0] = 1;
	for(int i = 1; i <= n; i++){
		sum[0] = dp[i-1][0];
		for(int j = 1; j <= k; j++) sum[j] = sum[j-1]+dp[i-1][j], sum[j] %= mod;
		for(int j = 0; j <= k; j++){
			dp[i][j] += sum[j], dp[i][j] %= mod;
			if(j-a[i] > 0) dp[i][j] += mod - sum[j-a[i]-1], dp[i][j] %= mod;
		}
	}
	cout << dp[n][k] << endl;
	
	return 0;
}

Measured memory_bytes: 79360
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  while(1){
  int n,i,a[10000],b[10000],c=0,m,j,d[1000000]={0},y=1,e=1,g=0,w=0;
    cin >> n >> m;
    if(n==0 && m==0){
      break;
    }
    for(i=1;i<=m;i++){
      cin >> a[i] >> b[i];
    }
    for(i=1;i<=m;i++){
      if(a[i]==1){
	d[y]=b[i];
	y++;
      }
      else if(b[i]==1){
	d[y]=a[i];
	y++;
      }
    }
    w=y;
    for(i=1;i<w;i++){
      for(j=1;j<=m;j++){
	if(d[i]==a[j] && b[j]!=1){
	  d[y]=b[j];
	  y++;
	}
	if(d[i]==b[j] && a[j]!=1){
	  d[y]=a[j];
	  y++;
	}
      }
    }
    sort(d,d+y);
    for(i=1;i<y;i++){
      if(c!=d[i]){
	g++;
      }
      c=d[i];
    }

    cout << g << endl;
  }
}

Measured memory_bytes: 5168
words = lambda t : list(map(t, input().split()))
n = int(input())
s = input()

a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

def conv(c,n):
    co = ord(c)
    co += n
    if co > 90:
        co -= 26
    #print(co)
    return chr(co)

ans = ""
for c in s:
    ans += conv(c,n)
print(ans)


Measured memory_bytes: 41452
#include <iostream>
#include <string>

using namespace std;

int main() {
  int animal_num, animal_leg_num;
  cin >> animal_num >> animal_leg_num;

  bool found = false;
  for(int turtle_num = 0; turtle_num <= animal_num; turtle_num++) {
    int vine_num = animal_num - turtle_num;

    if(animal_leg_num == turtle_num * 4 + vine_num * 2) {
      found = true;
      break;
    }
  }

  if(found) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

int fib(int n);
int main(){
  int n;
  int dp[45];

  dp[0]=1;
  dp[1]=1;
  cin >> n;

  for (int i= 2;i<= n; i++){
    dp[i]=dp[i-1]+dp[i-2];
  }

  cout << dp[n]<< endl;

  return 0;
}


Measured memory_bytes: 3120
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

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















int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> h(n);
    REP(i, n){
        cin >> h[i];
    }
    sort(h.begin(), h.end(), greater<ll>());
    ll ans = 0;
    for(ll i = k; i < n; i++) ans += h[i];
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int64_t>A(N),L(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }
  int64_t ans=0;
  L.at(0)=A.at(0);
  for(int i=1;i<N;i++){
    if(A.at(i)>=L.at(i-1)){
      L.at(i)=A.at(i);
    }
    else{
      L.at(i)=L.at(i-1);
      ans+=L.at(i-1)-A.at(i);
    }
  }
  cout<<ans<<endl;
}
    

Measured memory_bytes: 6372
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int k = Integer.parseInt(sc.next());
    int[] h = new int[n];

    for(int i=0; i<n; i++){
      h[i] = Integer.parseInt(sc.next());
    }
    Arrays.sort(h);
    int[] ans = new int[n-k+1];
    for(int j=0; j<n-k+1; j++){
      ans[j] = h[j+k-1] - h[j];
    }  
    Arrays.sort(ans);
    System.out.println(ans[0]);

  }
}

Measured memory_bytes: 48408
li = list(map(int,input().split()))
a=li[0]
b=li[1]
k=li[2]
if a<k:
    if b<k-a:
        a=0
        b=0
    else:
        b=b-k+a
        a=0
        
else:
    a=a-k

print(str(a)+" "+str(b))

Measured memory_bytes: 3060
#include <iostream>
#include<vector>
int main()
{
    int N=0;
    std::cin>>N;
    std::vector<int>K(N);
    std::vector<int>P(N);
	for(int i=0 ;i<N;i++)std::cin>>K[i]>>P[i];
    for(int i=0 ;i<N;i++){
        if(K[i]%P[i]!=0)std::cout<<K[i]%P[i]<<std::endl;   
        else std::cout<<P[i]<<std::endl;
    }
    return 0;        
}	

Measured memory_bytes: 1196
#abc126d
n=int(raw_input())
t=[[] for i in range(n+1)]
for i in range(n-1):
 u,v,w=map(int,raw_input().split())
 t[u].append([v,w])
 t[v].append([u,w])
d=[-1]*(n+1)
d[1]=0
q=[1]
while q:
 now=q.pop()
 for ni,nl in t[now]:
  if d[ni]==-1:
   d[ni]=d[now]+nl
   q.append(ni)
for l in d[1:]:
 print l%2


Measured memory_bytes: 47832
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
long long ans,n,m,i,j,k;
int main(){//freopen("1.in","r",stdin);freopen("1.out","w",stdout);
	scanf("%lld",&n);for (ans=1000;n;n=n/10) ans=min(ans,(long long)abs(1LL*753-n%1000));printf("%lld\n",ans);return 0;
}

Measured memory_bytes: 256
//To include everything you need
#include <bits/stdc++.h>
using namespace std;
typedef std::vector<int>  vi;
typedef std::vector<std::pair<int,int> > vpi;
typedef std::vector<string>  vs;
typedef std::vector<char>  vc;

double distance_between_towns(pair<int,int> t1, pair<int,int> t2){
    double x = t1.first-t2.first;
    double x_squared = pow(x,2);
    double y = t1.second-t2.second;
    double y_squared = pow(y,2);
    double distance = sqrt(x_squared+y_squared);
    return distance;   
}
int main(){

    int n;
    long factorial = 1;
    cin>>n;
    double average_distance = 0.0;
    std::vector<int> towns(n);
    std::vector<std::pair<int,int> > townsLocation(n);

    for(int i =1;i<=n;i++){
        factorial *= i;
    }
    for(int i=0;i<n;i++){
        int posX,posY;
        cin>>posX>>posY;
        pair<int,int> location(posX,posY);
        townsLocation[i] = location;
        towns[i] = i;
    }
    do{
        double path_distance = 0;
        for(int i =0 ; i<n-1;i++){
             pair<int,int> firstTown = townsLocation[towns[i]];
             pair<int,int> secondTown = townsLocation[towns[i+1]];
             path_distance += distance_between_towns(firstTown,secondTown);
        }
        average_distance += (path_distance/factorial);        
    }
    while(std::next_permutation(towns.begin(),towns.end()));
    cout<<setprecision(25)<<average_distance;
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> sushi;
const int MAXN = 100001;

int main() {
    ll n,k;
    cin >> n >> k;
    vector<sushi> v;
    for(int i=0; i< n ;i++) {
        ll t,d;
        cin >> t >> d;
        v.push_back(sushi(t,d));
    }
    sort(v.begin(), v.end(), [](const sushi &s1, const sushi &s2) {
        return s1.second > s2.second;
    });
    ll curNs = 0; //current syurui of neta
    ll curN[MAXN]; //current num for each neta
    ll curBS = 0; //current base score 
    for(int i=0; i< MAXN;i++) {curN[i] = 0;}
    for(int i=0;i<k;i++) {
        if (curN[v[i].first] == 0) {
            curNs++;
        }
        curN[v[i].first]++;
        curBS+=v[i].second;
    }
    ll res = curBS + curNs * curNs;
    ll addPtr = k - 1;
    ll delPtr = (k-1) + 1;
    while(true) {
        while(addPtr < n) {
            addPtr++;
            if (curN[v[addPtr].first] == 0) {
                break;
            }
        }
        if (addPtr>=n) {break;}
        while(delPtr >= 0) {
            delPtr--;
            if (curN[v[delPtr].first] > 1) {
                break;
            }
        }
        if (delPtr < 0) {break;}
        curBS += v[addPtr].second - v[delPtr].second;
        curN[v[addPtr].first]++;
        curN[v[delPtr].first]--;
        curNs++;
        ll cur = curBS + curNs * curNs;
        res = max(cur, res);
    }
    cout << res << endl;
    return 0;
}  

Measured memory_bytes: 2672
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

const int sign[2]={1,-1};

int N;
int A[100000];
int ans[100000];

int main(){
    cin>>N;
    rep(i,N) cin>>A[i];

    rep(i,N){
        ans[0]+=A[i]*sign[i%2];
    }

    for(int i=1;i<N;i++){
        ans[i]=2*(A[i-1]-ans[i-1]/2);
    }

    rep(i,N) cout<<ans[i]<<' ';
    cout<<endl;
}

Measured memory_bytes: 2048
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()
S = [S() for i in range(N)]

a = 0
b = 0
c = 0
d = 0
for i in range(N):
    if S[i] == 'AC':
        a += 1
    elif S[i] == 'WA':
        b += 1
    elif S[i] == 'TLE':
        c += 1
    else:
        d += 1

print('AC x {}'.format(a))
print('WA x {}'.format(b))
print('TLE x {}'.format(c))
print('RE x {}'.format(d))

Measured memory_bytes: 79272
#include <stdio.h>
#include <math.h>
 
int main (void)
{
  int n;
  scanf("%d", &n);
  
  if(n % 1000 == 0){
    printf("%d\n", 0);
  }else{
    printf("%d\n", 1000-n%1000);
  }
  
  return 0;
}

Measured memory_bytes: 1736
// ABC132-D
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
namespace you {
    std::string to_string(char val) {
        return std::string(1, val);
        // return std::string{val};
        // you::to_string(char)
    }
}

ll mod=pow(10,9)+7;
ll num=3*pow(10,3);
vector<ll> fact(num);
vector<ll> invfact(num);

ll modpow(ll x,ll y,ll mod){ //x^y
    if(y==0) return 1;
    if(y==1) return x%mod;
    if(y%2==1) return x*modpow(x,y-1,mod)%mod;
    ll t=modpow(x,y/2,mod);
    return (t*t)%mod;
}
ll nck(ll n,ll k,ll mod){
    return fact[n]*invfact[k]%mod*invfact[n-k]%mod;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    ll n,k;
    cin>>n>>k;
    if(k==1) cout<<n-k+1<<endl;
    else{
        fact[0]=1;
        for(int i=1;i<num;i++){
            fact[i]=fact[i-1]*i%mod;
        }
        invfact[num-1]=modpow(fact[num-1],mod-2,mod);
        for(int i=num-2;i>-1;i=i-1){
            invfact[i]=invfact[i+1]*(i+1)%mod;
        }
        for(int i=1;i<=k;i++){
            ll ans=0;
            if(i<=n-k+1) ans=nck(n-k+1,i,mod)*nck(k-1,i-1,mod)%mod;
            cout<<ans<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
//const int N = 1e5 + 5;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    char ch;
    cin>>ch;
    cout<<(char)(ch+1)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep2(i,n) for(int i=1; i<=(n); ++i)
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(),(x).end())
#define Sort2(x) sort((x).begin(),(x).end(), greater<int>())
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main()
{
    double n; cin >> n;
    cout << fixed << setprecision(5);
    cout << n * 2 * 3.14159 << endl;

}

/*
Ctrl+@ でコンソールを開け、以下で実行。
g++ a.cpp
./a.out

サンプルのダウンロードは oj d URL
テストは oj t
コード変えたらコンパイルする
不正解ならWAが出る
*/


Measured memory_bytes: 3784
/*
Author: Babin Dutta
*/
 
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,n) for(int i=0;i<n;i++)
#define ff(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 endl "\n"
#define inf 1e18
#define mm 998244353
 
ll power(ll x, ll y, ll p)
{
    ll res = 1;  
    x = x % p;  
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; 
        x = (x*x) % p;  
    }
    return res;
}
ll modInverse(ll A,ll M)
{
    return power(A,M-2,M);
}

void solve(){
    int n,m,k; cin>>n>>m>>k;
    int b = 0, ans = 0;
    char a[n][m];
    f(i,n) f(j,m){
    	cin>>a[i][j];
    	if(a[i][j] == '#') b++;
	}
    int xx = pow(2,n+m);
    for(int i=0;i<xx;i++){
    	int j=0;
    	int z = i;
    	vector<int> r,c;
    	while(z>0){
    		if(z%2 == 1){
    			if(j < n) r.pb(j);
    			else c.pb(j-n);
			}
			z /= 2;
			j++;
		}
		int tmp = 0;
		f(x,r.size()){
			for(int k=0;k<m;k++) if(a[r[x]][k] == '#') tmp++;
		}
		f(x,c.size()){
			for(int k=0;k<n;k++) if(a[k][c[x]] == '#') tmp++;
		}
		for(int l=0;l<r.size();l++){
			for(int p=0;p<c.size();p++){
				if(a[r[l]][c[p]] == '#') tmp--;
			}
		}
		if(b-tmp == k) ans++;
	}
	cout<<ans<<endl;
}
 
int main(){
	#ifdef JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    #endif
	boost;
	int t=1; //cin>>t;
	for(int i=1;i<=t;i++) solve();
	return 0;
}

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

ll gcd(ll a,ll b){
  while(b!=0){
    a%=b;
    swap(a,b);
  }
  return a;
}

int main() {
  ll A,B; cin>>A>>B;
  ll x=gcd(A,B);
  ll ans=1;
  for(ll i=2; i*i<=x; i++){
    if(x%i==0){
      ans++;
      while(x%i==0){
        x/=i;
      }
    }
  }
  if(x!=1){
    ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int a ,b;

  scanf("%d %d",&a, &b);
  if (a < b){
    printf("a < b\n");
      }else if(a > b){
    printf("a > b\n");
      }else{
    printf("a == b\n");}
    
  return 0;

 }

Measured memory_bytes: 580
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<vector<ll> > mat;

vii go(ll n)
{
	if(n==1)
	{
		vii v;
		v.pb(1);
		return v;
	}
	if(n%2==0)
	{
		vii v1=go(n-1);
		int mx=0;
		tr(v1,it)mx=max(mx,*it);
		mx++;
		vii v;
		v.pb(mx);
		tr(v1,it)
		v.pb(*it);
		return v;
	}
	else
	{
		vii v1=go(n/2);
		int mx=0;
		tr(v1,it)mx=max(mx,*it);
		mx++;
		v1.pb(mx);
		return v1;
	}
}

int main()
{ios_base::sync_with_stdio(false);
ll n;
cin>>n;

vii v=go(n);

int sz=v.size();
ol(2*sz);on;
tr(v,it)
{
	ol(*it);os;
}

rep(i,1,sz)
{
	ol(i);os;
}

return 0;
}


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

#define lli long long int
#define pb push_back


int main()
{
    int a , b ;
    cin >> a >> b ;
    
    for (int i = 0 ; i < max(a , b) ;  i++)
    {
        cout << min(a , b) ;
    }

    cout << endl ;
    return 0 ;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'
const int N = 1e6;

int main() {
    ios_base::sync_with_stdio(0);
    int a,b,c,d,n,T,cas=0;
    cin>>a>>b>>c>>d;
    int x = (c+b-1)/b;
    int y = (a+d-1)/d;
    if(x<=y) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <queue>
#include <utility>
using namespace std;

int main(void){
  long long N,max = 0;
  cin >> N;
  long long H[N];
  for(long long i=0;i<N;i++){
    cin >> H[i];
  }

  for(long long i=0;i<N;i++){
    if(H[i] > max){
      max = H[i];
    }
    //cout << "max=" << max << " H[i]=" << H[i] << endl;
    if(max-1 > H[i]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}



Measured memory_bytes: 1024
n, m = list(map(int, input().split()))

a = 1
b = n

if n%2==1:
    for i in range(m):
        print(a, b)
        a += 1
        b -= 1
else:
    pair = 0
    while b-a > n//2 and pair < m:
        print(a, b)
        pair += 1
        a += 1
        b -= 1
    a += 1
    while pair < m:
        print(a, b)
        pair += 1
        a += 1
        b -= 1   

Measured memory_bytes: 9220
#include <stdio.h>  
int main(void) { 
    int H,W,i,j,k; 
    for(k=0; k<300; k++){
        scanf("%d %d",&H,&W);
        if(H==0 && W==0)
        break;
        for(j=0; j<H; j++){
            for(i=0; i<W; i++){
                printf("#");
                }
                printf("\n");}
                printf("\n");
    }
    return 0; 
} 



Measured memory_bytes: 2048
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    string s;
    cin >> N;
    cin >> s;
    vector<int> L(N + 1), R(N + 1);
    
    int cur = 0;
    rep(i, N) {
        if(s[i] == 'W') cur++;
        L[i + 1] = cur;
    }
    cur = 0;
    for(int i = N - 1; i >= 0; i--) {
        if(s[i] == 'E') cur++;
        R[i] = cur;
    }
    
    int ans = inf;
    rep(i, N) {
        ans = min(ans, L[i] + R[i + 1]);
    }
    output(ans);
    
    
    return 0;
}


Measured memory_bytes: 2964
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;

const char A[][9]{
  "..rr....",
  "..rr....",
  "ggyybbww",
  "ggyybbww",
  "..oo....",
  "..oo....",
};

void rotate(string s[6],int x,int y,int cnt){
  const int T[8]={0,0,1,0,1,1,0,1};
	string tmp;
	for(int i=0;i<4;++i)tmp+=s[y+T[2*i+1]][x+T[2*i]];
	tmp=(tmp+tmp).substr(4-cnt,4);
	for(int i=0;i<4;++i)s[y+T[2*i+1]][x+T[2*i]]=tmp[i];
}

int main(void){
  string s,r[6];
  cin>>s;
  for(int i=0;i<6;++i) r[i]=string(A[i]);
  for(int i=0;i<s.size();++i){
    if(s[i]=='U'){
      rotate(r,2,0,1);
      string tmp=r[2];
      r[2]=(tmp+tmp).substr(2,8);
    }else if(s[i]=='F'){
    	rotate(r,2,2,1);
    	const int F[16]={2,1,3,1,4,2,4,3,3,4,2,4,1,3,1,2};
    	string tmp;
    	for(int j=0;j<8;++j) tmp+=r[F[j*2+1]][F[j*2]];
    	tmp=(tmp+tmp).substr(6,8);
    	for(int j=0;j<8;++j) r[F[j*2+1]][F[j*2]]=tmp[j];
    }else if(s[i]=='R'){
    	rotate(r,4,2,1);
    	const int R[16]={3,0,3,1,3,2,3,3,3,4,3,5,6,3,6,2};
    	string tmp;
    	for(int j=0;j<8;++j) tmp+=r[R[j*2+1]][R[j*2]];
    	tmp=(tmp+tmp).substr(2,8);
    	for(int j=0;j<8;++j) r[R[j*2+1]][R[j*2]]=tmp[j];
    }else if(s[i]=='D'){
    	rotate(r,2,4,1);
      string tmp=r[3];
      r[3]=(tmp+tmp).substr(6,8);
    }else if(s[i]=='B'){
    	rotate(r,6,2,1);
    	const int B[16]={2,0,3,0,5,2,5,3,3,5,2,5,0,3,0,2};
    	string tmp;
    	for(int j=0;j<8;++j) tmp+=r[B[j*2+1]][B[j*2]];
    	tmp=(tmp+tmp).substr(2,8);
    	for(int j=0;j<8;++j) r[B[j*2+1]][B[j*2]]=tmp[j];
    }else if(s[i]=='L'){
    	rotate(r,0,2,1);
    	const int L[16]={2,0,2,1,2,2,2,3,2,4,2,5,7,3,7,2};
    	string tmp;
    	for(int j=0;j<8;++j) tmp+=r[L[j*2+1]][L[j*2]];
    	tmp=(tmp+tmp).substr(6,8);
    	for(int j=0;j<8;++j) r[L[j*2+1]][L[j*2]]=tmp[j];
    }
  }
  for(int i=0;i<6;++i) cout<<r[i]<<endl;;
  return 0;
}

Measured memory_bytes: 1196
N, H, D = map(int, input().split())
P, a, s = 10**9+7, 1, 0
for i in range(1, N+1):
    a = a*i%P
    s = (s+a)%P

X = [a]
for i in range(1, H):
    X.append(a*s%P)
    a += X[-1]
    if i >= D: a -= X[-D-1]
    a %= P

print(a)

Measured memory_bytes: 42644
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<string>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define rep(i,x) for(int i = 0 ; i < x ; i ++)
#define rep1(i,x) for(int i = 1 ; i <= x ; i ++)
#define rrep(i,x) for(int i = x-1 ; i >= 0 ; i --)
#define rrep1(i,x) for(int i = x ; i > 0 ; i --)
#define sor(vec) sort(vec.begin(),vec.end())
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define min_3(a,b,c) min(min(a,b),c)
#define max_3(a,b,c) max(max(a,b),c)
#define mp1(a,b,c) P1(a,P(b,c))
#define fr first
#define sc second
#define pb push_back

const int INF = 1000000000;
const int dir_4[4][2] = { {1,0} , {0,1} , {-1,0} , {0,-1} };

int r;
int w[2],h[2],x[2],y[2];
int l[2][502][502];

int a[502][502];

int dfs(int X,int Y){
	if(a[X][Y] != 0)return 0;
	a[X][Y] = 1;
	int ret = 1;
	rep(i,4){
		ret += dfs(X+dir_4[i][0],Y+dir_4[i][1]);
	}
	return ret;
}

/*int f(int t,int m){
	rep(i,502){
		rep(j,502){
			a[i][j] = 1;
		}
	}
	rep1(i,h[t]){
		rep1(j,w[t]){
			if(l[t][i][j] <= m)a[i][j] = 0;
		}
	}
	return dfs(y[t],x[t]);
}*/

int C;
bool comp(P1 a,P1 b){
	if(a.fr != b.fr)return a <= b;
	if(a.sc.fr == y[C] && a.sc.sc == x[C])return true;
	if(b.sc.fr == y[C] && b.sc.sc == x[C])return false;
	return a <= b;
}

int main(){
	while(1){
		scanf("%d",&r); if(r == 0)break;
		rep(i,2){
			scanf("%d%d%d%d",&w[i],&h[i],&x[i],&y[i]);
			rep1(j,h[i]){
				rep1(k,w[i]){
					scanf("%d",&l[i][j][k]);
				}
			}
		}
		
		static int cost[2][250010];
		vector<P1> vec[2];
		
		vec[0].clear();
		vec[1].clear();
		
		rep(k,2){
			vec[k].pb( mp1 ( 0 , -1 , -1 ) );
			rep1(i,h[k]){
				rep1(j,w[k]){
					vec[k].pb( mp1 ( l[k][i][j] , i , j ) );
				}
			}
			C = k;
			sort(vec[k].begin(),vec[k].end(),comp);
			
			rep(i,502){
				rep(j,502){
					a[i][j] = -1;
				}
			}
			
			cost[k][0] = 0;
			a[y[k]][x[k]] = 1;
			cost[k][1] = 1;
			
			for(int i = 2; i < vec[k].size() ; i ++){
				P p = vec[k][i].sc;
				a[p.fr][p.sc] = 0;
				cost[k][i] = cost[k][i-1];
				bool t = false;
				rep(j,4){
					t |= (a[p.fr+dir_4[j][0]][p.sc+dir_4[j][1]] == 1);
				}
				if(t)cost[k][i] += dfs(p.fr,p.sc);
			}
			
			/*rep(i,vec[k].size()){
				printf("%d %d\n",vec[k][i].fr,cost[k][i]);
			}*/
		}
		
		int ret = INF;
		int k = vec[1].size()-1;
		rep(i,vec[0].size()){
			while(k > 0 && cost[0][i] + cost[1][k-1] >= r)k --;
			if(cost[0][i] + cost[1][k] >= r){
				ret = min ( ret , vec[0][i].fr + vec[1][k].fr );
			}
		}
		
		printf("%d\n",ret);
		
		/*int L = 0,R = 100000000;
		while(L < R){
			int M = (L+R)/2;
			if(f(0,M)+f(1,M) < r)L = M+1;
			else R = M;
		}
		
		printf("%d\n",L);*/
	}
}

Measured memory_bytes: 13180
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;



int main() 
{
  ll N; cin>>N;
  ll sum=0;
  vector<ll> A(N);
  rep(i,N)
  {
    cin>>A.at(i);
    sum+=A.at(i);
  }
  vector<ll> sa(N-1);
  ll sum2=0;
  rep(i,N-1)
  {
    sum2+=A.at(i);
    sa.at(i)=abs(sum-2*sum2);
  }
  sort(sa.begin(),sa.end());
  cout<<sa.at(0)<<endl;
  return 0;
}

Measured memory_bytes: 3456
#include<iostream>
#include<cstdlib>
#include<string>
#include<cmath>
#include<cstdio>
using namespace std;
const int SIZE = 50;
string a[SIZE];
void dfs(int i,int j)
{
    int cnt=0;
    if(a[i][j]=='.')
    {
        if(i>0&&j>0&&a[i-1][j-1]=='#')
            ++cnt;
        if(i>0&&a[i-1][j]=='#')
            ++cnt;
        if(i>0&&a[i-1][j+1]=='#')
            ++cnt;
        if(j>0&&a[i][j-1]=='#')
            ++cnt;
        if(a[i][j+1]=='#')
            ++cnt;
        if(j>0&&a[i+1][j-1]=='#')
            ++cnt;
        if(a[i+1][j]=='#')
            ++cnt;
        if(a[i+1][j+1]=='#')
            ++cnt;
        a[i][j]=(char)(cnt+48);
    }
}
int main()
{
    int H,W;
    int i,j;
    cin>>H>>W;
    for(i=0;i<H;++i)
        cin>>a[i];
    for(i=0; i<H; ++i)
    {
        for(j=0; j<W; ++j)
        {
            dfs(i,j);
        }
    }
    for(i=0; i<H; ++i)
        cout<<a[i]<<endl;
}


Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N = I()
    A = I()

    print(N ** 2 - A)

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 9192
import math
import sys
import collections
import bisect
readline = sys.stdin.readline


def main():
    a, v = map(int, readline().rstrip().split())
    b, w = map(int, readline().rstrip().split())
    t = int(readline().rstrip())
    if v <= w:
        print('NO')
        return
    print('YES' if abs(b - a) / (v - w)
          <= t else 'NO')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9392
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True

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

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

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

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

    return result


def main():
    N, M, X_SUM = MI()
    C = [0] * N
    A = [None] * N

    for i in range(N):
        b = LI()
        C[i] = b[0]
        A[i] = b[1:]

    ans = 10**19
    for i in range(1, N+1):
        for select_idx in combinations(range(N), i):
            X = [0] * M
            price = 0
            for book_idx in select_idx:
                for x_idx in range(M):
                    X[x_idx] += A[book_idx][x_idx]
                price += C[book_idx]

            if all([x >= X_SUM for x in X]):
                ans = min(ans, price)

    if ans == 10**19:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 70048