akhauriyash/Code-Regression huggingface dataset:
import math
n=int(input())
x=[0]*n
y=[0]*n
for i in range(n):
  x[i],y[i]=map(int,input().split())
sum=0
for i in range(n-1):
  for j in range(i+1,n):
    sum += math.sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)
print(2*sum/n)



Measured memory_bytes: 3060
#include <iostream>
//#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n, maxNum = 10000000,count=0;
    
    cin>>n;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin>>x;

        if (x<=maxNum)
        {
            count++;
        }
        maxNum = min(x,maxNum);
        

    }

    cout<<count<<endl;
    
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>
#define typeof(x) __typeof__(x)
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) UB(c,x)-LB(c,x)
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define PB push_back
#define MP make_pair
#define vec vector

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

using namespace std;

typedef pair<int,int> P;
struct edge {
  int to, cost;
};

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

template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
  int len = v.size();
  s << "[";
  for (int i = 0; i < len; i++) {
    s << v[i]; if (i < len - 1) s << " ";
  }
  s << "]";
  return s;
}


signed main()
{
  int N, W; cin >> N >> W;
  int w0;
  vec< vec<int> > v(4, vec<int>());
  rep(i, 0, N) {
    int x, y; cin >> x >> y;
    if (i == 0) {
      w0 = x;
    }
    v[x-w0].PB(y);
  }
  rep(i, 0, 4) {
    RSORT(v[i]);
  }

  vec< vec<int> > s(4, vec<int>());
  rep(i, 0, 4) {
    s[i].PB(0);
    rep(j, 0, SZ(v[i])) {
      s[i].PB(s[i][j] + v[i][j]);
    }
  }

  int vmax = 0;
  rep(a, 0, SZ(s[0])) {
    rep(b, 0, SZ(s[1])) {
      rep(c, 0, SZ(s[2])) {
        rep(d, 0, SZ(s[3])) {
          if (a*w0 + b*(w0+1) + c*(w0+2) + d*(w0+3) <= W) {
            vmax = max(vmax, s[0][a] + s[1][b] + s[2][c] + s[3][d]);
          }
        }
      }
    }
  }
  cout << vmax << endl;

  return 0;
}


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

int main(void){
    // Your code here!
    
    string s;
    string t;
    cin>>s>>t;
    
    int cnt=0;
    for(int i=0;i<s.size();i++){
        if(s[i]!=t[i]) cnt++;
    }
    
    cout<<cnt<<endl;
}


Measured memory_bytes: 3916
#include<stdio.h>
#include<math.h>
int main()
{long long int n,t;
scanf("%lld",&n );
int l1,cnt=0;
t=n;
while(t!=0)
{
    l1=t%10;
    cnt+=l1;
    t=t/10;
    
}
if(n%cnt==0){printf("Yes\n");}
else{printf("No\n");}
return 0;
}


Measured memory_bytes: 128
n,c=map(int,input().split())
arrd=[list(map(int,input().split())) for i in range(c)]
arrc=[list(map(int,input().split())) for i in range(n)]
field = [[0,0,0] for _ in range(c+1)]
ans = 10**9

for i in range(n):
  for j in range(n):
    field[arrc[i][j]][(i+j)%3] += 1
    
for p in range(1, c+1):
  for q in range(1, c+1):
    for r in range(1, c+1):
      if q != p:
        if r != p and r != q:
          tmp = 0
          for i in range(1, c+1):
            tmp += field[i][0]*arrd[i-1][p-1]
            tmp += field[i][1]*arrd[i-1][q-1]
            tmp += field[i][2]*arrd[i-1][r-1]
          ans = min(tmp, ans)
          
print(ans)
            
      

Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

ll check[110000];

int main() {
  ll n, x, m;
  cin >> n >> x >> m;
  vll v;
  ll cnt = 0LL;
  ll a = x;
  rep(i,m*2) {
    v.push_back(a);
    cnt += a;
    check[a] = true;
    a *= a;
    a %= m;
    if(check[a]) break;
    if(a==0) {
      cout << cnt << endl;
      return 0;
    }
  }
  ll ans = 0LL;
  bool swi = true;
  vll vv;
  rep(i,v.size()) {
    if(v[i]==a) swi = false;
    if(swi) {
      ans += v[i];
      n--;
    }
    else vv.push_back(v[i]);
  }
  ll s = vv.size();
  ll sum = 0LL;
  rep(i,s) sum += vv[i];
  ans += sum*(n/s);
  rep(i,n%s) ans += vv[i];
  cout << ans << endl;
  return 0;
}


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

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

using namespace std;
using ll = long long;
int mod = 1000000007;

void solve();

int main(void){
    ll a, b, x; cin >> a >> b >> x;
    //aをa以上のxの倍数にする
    if(a % x > 0) a += x - (a % x);
    b -= a;
    if(b < 0) cout << 0 << endl;
    else cout << b/x + 1 << endl;
    return 0;
}

void solve(){}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderC
{
    static void Main()
    {
        var sc = new Scanner();

        int k = sc.NextInt();
        int n = sc.NextInt();

        int[] a = sc.IntArray();

        Array.Sort(a);

        int max = 0;

        for (int i = 0; i < n - 1; i++)
        {
            int dist;
            if (i == 0)
            {
                dist = a[i] + (k - a[n - 1]);
            }
            else
            {
                dist = a[i + 1] - a[i];
            }
            max = Math.Max(max, dist);
        }

        Console.WriteLine(k - max);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 34396
N, C, K = [int(_) for _ in input().split()]
times = sorted([int(input()) for _ in range(N)], reverse=True)
count = 0
while times:
    t = times.pop()
    count += 1
    num = 1
    while times:
        if times[-1] <= t + K and num < C:
            times.pop()
            num += 1
        else:
            break
print(count)


Measured memory_bytes: 8280
S = raw_input()
s1 = int(S[2:])
s2 = int(S[:2])
if(s1 == 0 or s1 > 12):
	s1 = 0
else:
	s1 = 1
if(s2 == 0 or s2 > 12):
	s2 = 0
else:
	s2 = 1
if(s1 == 0 and s2 == 0):
	print("NA")
elif(s1 == 0 and s2 == 1):
	print("MMYY")
elif(s1 == 1 and s2 == 0):
	print("YYMM")
else:
	print("AMBIGUOUS")

Measured memory_bytes: 2568
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

double dp[3030][3030];

int main(){
  int n;
  cin>>n;
  double p[n+1]={};
  for(int i=1;i<=n;i++){
    cin>>p[i];
  }

  dp[0][0]=1.0;
  for(int i=1;i<=n;i++){
    for(int j=0;j<=i;j++){
      dp[i][j]=dp[i][j]+dp[i-1][j]*(1-p[i]);
      if(j>0)dp[i][j]=dp[i][j]+dp[i-1][j-1]*p[i];

      /*dp[i][j+1]=max(dp[i][j+1],dp[i-1][j]*p[i]);
      dp[i][j+1]=max(dp[i][j+1],dp[i-1][j+1]*(1-p[i]));
      dp[i][j]=max(dp[i][j],dp[i-1][j]*(1-p[i]));
      if(j>0) dp[i][j]=max(dp[i][j],dp[i-1][j-1]*p[i]);*/
    }
  }

  double ans=0.0;
  for(int i=0;i<=n;i++){
    if(i+i>n) ans=ans+dp[n][i];
    //cout<<dp[n][i]<<endl;
  }

  cout<<fixed<<setprecision(12)<<ans<<endl;

  return 0;
}


Measured memory_bytes: 70272
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
int main()
{
    vector<string> str;
    int num,length;
    string current;
    cin >> num >> length;
    for(int i=0;i<num;i++){
        cin >> current;
        str.push_back(current);
    }

    sort(str.begin(),str.end(),greater<string>());
    for(int i=num-1;i>=0;i--){
        cout << str.at(i);
    }
    cout << endl;

    return 0;


}

Measured memory_bytes: 256
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;

class Main {

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		L = sc.nextLong();
		String[] s = new String[n];
		Tree tree = new Tree();
		for (int i = 0; i < n; ++i) {
			s[i] = sc.next();
			tree.set(s[i]);
		}
		tree.dfs(tree.root);
		if (grundy == 0) {
			System.out.println("Bob");
		} else {
			System.out.println("Alice");
		}
	}

	long grundy = 0;
	long L;

	class Tree {
		Node root = new Node();

		void set(String s) {
			Node cur = root;
			for (int i = 0; i < s.length(); ++i) {
				if (s.charAt(i) == '0') {
					cur.appendLeft();
					cur = cur.left;
				} else if (s.charAt(i) == '1') {
					cur.appendRight();
					cur = cur.right;
				}
			}
			cur.hit();
		}

		void dfs(Node cur) {
			if (cur.hit > 0)
				return;
			if (cur.left != null)
				dfs(cur.left);
			else {
				grundy ^= (L - cur.depth) & -(L - cur.depth);
			}
			if (cur.right != null) {
				dfs(cur.right);
			} else {
				grundy ^= (L - cur.depth) & -(L - cur.depth);
			}
		}

		class Node {
			Node right = null;
			Node left = null;
			int hit = 0;
			int depth = 0;

			void appendLeft() {
				if (left == null) {
					left = new Node();
					left.depth = depth + 1;
				}
			}

			void appendRight() {
				if (right == null) {
					right = new Node();
					right.depth = depth + 1;
				}
			}

			void hit() {
				++hit;
			}
		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

	public static void main(String[] args) throws FileNotFoundException {
		new Main().run();
	}
}


Measured memory_bytes: 39816
using System;
using System.Linq;

namespace ABC140B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N =  int.Parse(Console.ReadLine());
            var As = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray();
            var Bs = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            var Cs = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            var ans = 0;

            var bef = int.MinValue;
            for (var i = 0; i < N; i++)
            {
                var A = As[i];
                ans += Bs[A];

                if (bef == A - 1)
                    ans += Cs[bef];

                bef = A;
            }

            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13268
//
// Created by Hideaki Imamura on 2020-03-08.
//
# include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

string S;
int main() {
    cin >> S;
    if (S.length() % 2) {
        cout << "No" << endl;
        return 0;
    }
    for (int i = 0; i < S.length() / 2; ++i) {
        if (S[2 * i] != 'h' || S[2 * i + 1] != 'i') {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int cnt[31][100002];
int num[100001];

int main()
{
	int N, C, ans = 0;

	cin >> N >> C;
	rep(i, N) {
		int s, t, c;
		cin >> s >> t >> c;

		repc(j, s, t) cnt[c][j] = 1;
	}

	repc(i, 1, 100000) repc(j, 1, C) num[i] += cnt[j][i];
	repc(i, 1, 100000) ans = max(ans, num[i]);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 12416
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

    int n, r;
    cin >> n >> r;

    if(n<10) cout << r + 100 * (10 - n) << endl;
    else cout << r << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;

//bool ans[10000000];

int N;
int sumn;
int maxnum;
int sa = -1;
int main(){
	scanf("%d", &N);
	for (int i = 1; i <= N; i++){
		
		sumn += i;
		maxnum = i;
		if (sumn == N){ maxnum = i; break; }
		else if (sumn > N){
			maxnum = i;
			sa = sumn - N;
			break;
		}
	}
	if (N == 1){
		printf("1\n");
	}
	else{
		for (int i = 1; i <= maxnum; i++){
			if (i != sa){
				printf("%d\n", i);
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 128
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
using namespace std;
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
int dx[4]={0,0,-1,1},dy[4]={1,-1,0,0};


int main(int argc, char const *argv[]) {
  ll x,y;
  std::cin >> x >> y;
  ll absX = abs(x);
  ll absY = abs(y);
    
    // 同じ符号
    if (x > 0 && y > 0 && absX > absY) {
        // ともに正
        cout << (absX - absY) + 2;
 
    } else if (x > 0 && y > 0 && absX < absY) {
        // ともに正
        cout << absY - absX;
    } else if (x < 0 && y < 0 && absX > absY) {
        // ともに負
        cout << absX - absY;
    } else if (x < 0 && y < 0 && absX < absY) {
        // ともに負
        cout << (absY - absX) + 2;
    }
    // 異なる符号
    // 符号が異なる場合は一度反転がいる
    if (x > 0 && y < 0 && absX >= absY) {
        // x正 y負
        cout << (absX - absY) + 1;
    } else if (x > 0 && y < 0 && absX <= absY) {
        // x正 y負
        cout << (absY - absX) + 1;
    } else if (x < 0 && y > 0 && absX >= absY) {
        // x負 y正
        cout << (absX - absY) + 1;
    } else if (x < 0 && y > 0 && absX <= absY) {
        // x負 y正
        cout << (absY - absX) + 1;
    }
 
    // y = 0パターン
    if (y == 0) {
        if (x > 0) {
            cout << absX + 1;
        } else {
            cout << absX;
        }
    }
 
    // x = 0パターン
    if (x == 0) {
        if (y > 0) {
            cout << absY;
        } else {
            cout << absY + 1;
        }
    }
 
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <memory>
#include <random>
using namespace std;

// Randomized Binary Search Tree
// infix, 0-based

typedef int type;
constexpr int INF = (1 << 29);
constexpr type INIT = INF;

mt19937 engine;
uniform_int_distribution<int> rnd;

// update function
inline type func(type a, type b) {
	return min(a, b);
}

struct RBST {
	type value, res;
	int size;
	RBST *left, *right;

	RBST(int v):value(v), res(v), size(1), left(nullptr), right(nullptr) {}

	void update() {
		size = 1;
		res = value;

		if(left) {
			size += left->size;
			res = func(res, left->res);
		}

		if(right) {
			size += right->size;
			res = func(res, right->res);
		}
	}
};

inline int node_size(const RBST *x) {
	return x ? x->size : 0;
}

RBST *merge(RBST * x, RBST * y) {
	if(!x) return y;
	if(!y) return x;

	if(rnd(engine) % (x->size + y->size) < x->size) {
		x->right = merge(x->right, y);
		x->update();
		return x;
	}
	else {
		y->left = merge(x, y->left);
		y->update();
		return y;
	}
}

typedef pair<RBST *, RBST *> P;

P split(RBST *x, int num) {
	if(!x) return P(nullptr, nullptr);

	const int l_size = node_size(x->left);
	if(l_size < num) {
		const P tmp = split(x->right, num - l_size - 1);
		x->right = tmp.first;
		x->update();
		return P(x, tmp.second);
	}
	else {
		const P tmp = split(x->left, num);
		x->left = tmp.second;
		x->update();
		return P(tmp.first, x);
	}
}

RBST *insert(RBST *x, int pos, type value) {
	RBST *new_node = new RBST(value);
	const P tmp = split(x, pos);
	return merge(merge(tmp.first, new_node), tmp.second);
}

RBST *erase(RBST *x, int pos) {
	P tmp = split(x, pos);
	RBST *left = tmp.first;
	tmp = split(tmp.second, 1);
	delete tmp.first;
	return merge(left, tmp.second);
}

// [l, r)

// x, [0, x-size)
type query(RBST *x, int l, int r) {
	if(!x) return INIT;
	if(r <= 0 || x->size <= l) return INIT;
	if(l <= 0 && x->size <= r) return x->res;

	const int l_size = node_size(x->left);
	const type res = (l <= l_size && l_size < r ? x->value : INIT);
	const type vl = query(x->left, l, r);
	const type vr = query(x->right, l - l_size - 1, r - l_size - 1);
	return func(res, func(vl, vr));
}

enum { SHIFT, QUERY, UPDATE };

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

	int n, q;
	cin >> n >> q;

	RBST *root = nullptr;
	for(int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		root = insert(root, i, a);
	}

	while(q--) {
		int x, y, z;
		cin >> x >> y >> z;
		switch(x) {
		case SHIFT:
		{
			const auto value = query(root, z, z + 1);
			root = erase(root, z);
			root = insert(root, y, value);
			break;
		}
		case QUERY:
		{
			cout << query(root, y, z + 1) << '\n';
			break;
		}
		case UPDATE:
		{
			root = erase(root, y);
			root = insert(root, y, z);
			break;
		}
		}
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 10588
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int D;
  cin >> D;
  vector<int> c(26);
  REP(i, 26) cin >> c[i];
  vector<vector<int>> s(D, vector<int>(26));
  REP(i, D) { REP(j, 26) cin >> s[i][j]; }
  ll score = 0;
  vector<pair<ll, int>> ans(0);
  // unordered_map<int, int> lastday{};
  /*REP(i, D) {
    vector<pair<ll, int>> tmp(26);
    REP(j, 26) {
      //貪欲に選ぶ
      tmp[j].first = score + s[i][j];
      tmp[j].second = j;
      REP(k, 26) {
        if (j == k) continue;
        tmp[j].first -= c[k] * (i + 1 - lastday[k]);
      }
    }
    sort(tmp.begin(), tmp.end());
    ans.push_back(tmp[25]);
  }
  REP(i, D) { cout << ans[i].first << " " << ans[i].second + 1 << endl; }*/
  REP(ld, 26) {
    int a = ld + 1;
    vector<int> tk(0);
    REP(i, D) {
      tk.push_back(a);
      a %= 26;
      a += 1;
    }
    score = 0;
    unordered_map<int, int> lastday{};
    REP(i, D) {
      ll mx = -1e15;
      ll mxi = -1;
      int t = tk[i];
      mx = s[i][t];
      mxi = t;
      lastday[mxi] = i + 1;
      score += mx;
      REP(j, 26) { score -= c[j] * (i + 1 - lastday[j]); }
    }
    ans.push_back(make_pair(score, ld + 1));
  }
  sort(ans.begin(), ans.end());

  int al = ans[25].second;
  REP(i, D) {
    cout << al << endl;
    al %= 26;
    al += 1;
  }
}


Measured memory_bytes: 3676
from collections import deque
n,q = map(int, input().split())
S = []

for i in range(n):
    S.append(deque())
for i in range(q):
    a = input().split()
    t = int(a[1])
    
    if a[0] == '0':
        S[t].append(a[2])
    elif a[0] == '1' and S[t]:
        print(S[t][-1])
    elif a[0] == '2' and S[t]:
        S[t].pop()
    


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

using namespace std;

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef long long ll; typedef vector<int> VI; typedef pair<ll,int> pii;
const ll mod = 1e9+7;


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

	int n;
	cin >>n;
	VI a(n);
	rep(i,n) cin>>a[i];
	sort(all(a));
	printf("%d\n", a.back()-a.front());
	
	
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define LIMIT(d_in, d_min, d_max) max(d_min, min(d_max, d_in))
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int N, K;
	cin >> N >> K;
	lint ans = 0;
	vector<lint> data(N);

	for (int i = 0; i < N; i++)
	{
		cin >> data[i];
	}

	sort(all(data));

	for (int i = 0; i < N - K; i++)
	{
		ans += data[i];
	}

	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

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

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

using namespace std;

int main(){
  string s;cin>>s;

  bool result=true;
  string subs = s.substr(2,s.size()-2);
  if(s[0]!='A' || s[s.size()-1]=='C' || count(subs.begin(), subs.end(), 'C')!=1){cout<<"WA";return 0;}

  rep(i,s.size()-1){
    int c=i+1;
    if( !(s[c]=='C' || s[c]!='C' && 'a' <= s[c] && s[c]<'z') )result=false;
//    cout<<s[c]<<' '<<result<<endl;
  }

  if(result){
    cout<<"AC";
  }else{
    cout<<"WA";
  }

  return 0;
}

Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn with_stdout_lock<F: FnOnce(std::io::BufWriter<std::io::StdoutLock>)>(f: F) {
    let out = std::io::stdout();
    let w = std::io::BufWriter::new(out.lock());
    f(w);
}

fn main() {
    let s: Vec<char> = input::<String>().chars().collect();
    let n = s.len();

    let mut v = vec![vec![0; n]; 21];
    for j in 0..n {
        v[0][j] = if s[j] == 'R' { j + 1 } else { j - 1 };
    }
    for i in 0..20 {
        for j in 0..n {
            v[i + 1][j] = v[i][v[i][j]];
        }
    }

    let mut ans = vec![0; n];
    for j in 0..n {
        ans[v[20][j]] += 1;
    }

    with_stdout_lock(|mut w| {
        for i in 0..n {
            write!(w, "{}{}", ans[i], if i == n - 1 { '\n' } else { ' ' }).unwrap();
        }
    });
}


Measured memory_bytes: 27004
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    int mod = 1000000007;
    long long sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        sum += A[i];
        sum %= mod;
    }
 
    long ans = 0;
 
    //i について全探索する
    for (int i = 0; i < N; i++)
    {
        //A[i+1] ... A[N] の値を更新する
        sum -= A[i];
        if (sum < 0) sum += mod;
 
        ans += A[i] * sum;
        ans %= mod;
    }
 
    cout << ans << endl;
}

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

#define MAX 100001

typedef struct{
  char mark;
  int number;
  int sta;
} card;

int partition(card *,int,int);
void quicksort(card *,int,int);

int main(){
  int n,i,flag=0;
  card A[MAX];
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %c%d",&A[i].mark,&A[i].number);
    A[i].sta=i;
  }

  quicksort(A,0,n-1);

  for(i=0;i<n;i++){
    if(A[i].number==A[i+1].number){
      if(A[i].sta>A[i+1].sta){
	flag=1;
      }
    }
  }

  if(flag==0){
    printf("Stable\n");
  }else{ 
    printf("Not stable\n");
  }

  for(i=0;i<n;i++){
    printf("%c %d\n",A[i].mark,A[i].number);
  }

  return 0;
}

int partition(card *A,int p,int r){
  int x,i,j;
  card tmp1,tmp2;

  x=A[r].number;
  i=p-1;

  for(j=p;j<=r-1;j++){
    if(A[j].number<=x){
      i=i+1;
      tmp1=A[i];
      A[i]=A[j];
      A[j]=tmp1;
    }
  }

  tmp2=A[i+1];
  A[i+1]=A[r];
  A[r]=tmp2;

  return i+1;
}

void quicksort(card *A,int p,int r){
  int q;
  
  if(p<r){
    q=partition(A,p,r);
    quicksort(A,p,q-1);
    quicksort(A,q+1,r);
  }
}

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

using namespace std;

using ll = long long;

template <typename T> class BinaryIndexedTree { // 1-indexed
  int N;
  std::vector<T> bit;

public:
  BinaryIndexedTree(int n) : N(n), bit(n + 1, 0) {}

  void add(int index, T num) {
    for (int x = index; x <= N; x += x & -x)
      bit[x] += num;
  }

  T sum(int index) {
    T ret = 0;
    for (int x = index; x > 0; x -= x & -x)
      ret += bit[x];
    return ret;
  }
  T sum(int left, int right) { return sum(right) - sum(left - 1); }
};

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  BinaryIndexedTree<ll> BIT(n + 100), BIT2(n + 100);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    BIT.add(i + 1, a[i]);
    BIT2.add(i + 1, max(0LL, a[i]));
  }
  ll ans = 0;
  for (int i = 1; i + k - 1 <= n; ++i) {
    ll buf =
        BIT2.sum(i - 1) + max(0LL, BIT.sum(i, i + k - 1)) + BIT2.sum(i + k, n);
    ans = max(ans, buf);
  }
  cout << ans << endl;
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n, k;
    cin >> k >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    long long ans = 1e18;
    for (int i = 0; i < n; ++i) {
        if (i == 0) {
            ans = min(ans, a[n - 1] - a[i]);
            ans = min(ans, a[0] + (k - a[1]));
            continue;
        }
        if (i == n - 1) {
            ans = min(ans, a[n - 1] - a[0]);
            ans = min(ans, a[n - 2] + (k - a[n - 1]));
            continue;
        }
        ans = min(ans, a[i] + k - a[i + 1]);
        ans = min(ans, a[i - 1] + k - a[i]);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1792
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

from math import gcd
N, K = mapint()
As = list(mapint())

if max(As)<K:
    print('IMPOSSIBLE')
else:
    g = 0
    for a in As:
        g = gcd(g, a)
    else:
        if K%g==0:
            print('POSSIBLE')
        else:
            print('IMPOSSIBLE')

Measured memory_bytes: 86016
#include<cstdio>
int abs(int x) {return x>0?x:-x;}
int main()
{
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	if(abs(n-a)<abs(n-b)) printf("A\n");
	else printf("B\n");
	return 0;
}

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

template<typename T> T GCD(T x, T y){
    if(x < y)swap(x, y);
    if(y == 0)return x;
    return GCD(x % y, y);
}

template<typename T> T LCM(T x, T y){
  return x/GCD(x, y)*y;
}

int main()
{
  int n;
  cin >> n;
  vector<ll> v(n);
  rep(i, n) cin >> v[i];
  for(int i = 0; i < n-1; i++){
    v[i+1] = LCM(v[i], v[i+1]);
  }
  cout << v[n-1] << endl;
  system("pause");
}


Measured memory_bytes: 504
n = int(input())
d = dict()
for _ in range(n):
  l = "".join(sorted(list(input()))) 
  if l not in d:
    d[l] = 0
  d[l] += 1
ans = 0
for x in d.values():
  ans += x*(x-1)//2
print(ans)

Measured memory_bytes: 17808
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int N = 5;
    vi a(N);
    rep(i, N) in(a[i]);

    int k;
    in(k);

    rep(i, N)
    {
        reps(j, i + 1, N)
        {
            if (abs(a[i] - a[j]) > k)
            {
                outl(":(");
                return 0;
            }
        }
    }

    outl("Yay!");
    return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
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;
}
void print() { std::cout << '\n'; }
void vprint() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
template <class H, class... T> void vprint(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << '\n';
    vprint(std::forward<T>(args)...);
}
template <class T> void vprint(std::vector<T> &v) {
    for (auto &&i : v) {
        std::cout << i << '\n';
    }
}
template <class T> void mprint(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << "";
        }
    }
}

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

    int N;
    cin >> N;
    vector<int> p(N);
    for (auto &&i : p) {
        cin >> i;
    }

    int ans = 0;
    if (p[0] == 1) {
        swap(p[0], p[1]);
        ans++;
    }
    FOR(i, 1, N) {
        if (p[i] == i + 1) {
            ans++;
            if (p[i + 1] == i + 2) {
                i++;
            }
        }
    }
    print(ans);

    return 0;
}

Measured memory_bytes: 640
//raja1999
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string> 
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false); 
ll a[105];
int main(){
	std::ios::sync_with_stdio(false);
	int t;
	t=1;
	while(t--){
		ll n,val=0,i,minn=inf,id;
		cin>>n;
		rep(i,n){
		    cin>>a[i];
		    val+=a[i];
		}
		rep(i,n){
			if(abs(a[i]*n-val)<minn){
				minn=abs(a[i]*n-val);
				id=i;
			}
		}
		cout<<id<<endl;
	}
} 
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int const MX = 2e5 + 2, MOD = 1e9 + 7;

int main()
{
    int t = 1;
//    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int l[101];
        for(int i = 0; i < n; i++){
            cin>>l[i];
        }
        int cnt = 0;
        for(int i = 0; i < n - 2; i++){
            for(int j = i + 1; j < n-1; j++){
                for(int k = j + 1; k < n; k++){
                    if(l[i] == l[j] || l[i] == l[k] || l[j] == l[k]) continue;
                    if(l[i] + l[j] > l[k] && l[i] + l[k] > l[j] && l[k] + l[j] > l[i]) cnt++;
                }
            }
        }
        cout<<cnt;
    }
}




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

inline unsigned encode(unsigned n[2][4])
{
	unsigned ret = 0;
	REP(i, 2)REP(j, 4)ret += n[i][j] << (21 - i * 12 - j * 3);
	return ret;
}
inline void slide(unsigned c, unsigned ret[4])
{
	REP(i, 4)ret[i] = 0;
	unsigned n[2][4];
	int x, y;
	REP(i, 2) {
		REP(j, 4) {
			unsigned foo = (c >> (21 - i * 12 - j * 3)) & 0b111;
			if (foo == 0) {
				x = j;
				y = i;
			}
			n[i][j] = foo;
		}
	}
	if (x != 0) {
		swap(n[y][x], n[y][x - 1]);
		ret[0] = encode(n);
		swap(n[y][x], n[y][x - 1]);
	}
	if (x != 3) {
		swap(n[y][x], n[y][x + 1]);
		ret[1] = encode(n);
		swap(n[y][x], n[y][x + 1]);
	}
	if (y != 0) {
		swap(n[y][x], n[y - 1][x]);
		ret[2] = encode(n);
		swap(n[y][x], n[y - 1][x]);
	}
	if (y != 1) {
		swap(n[y][x], n[y + 1][x]);
		ret[3] = encode(n);
		swap(n[y][x], n[y + 1][x]);
	}
}
map<unsigned, int>push_back_all()
{
	map<unsigned, int>mp;
	queue<pair<unsigned, int>>que; que.push(make_pair(0b000001010011100101110111, 0));
	set<unsigned>appeared;
	while (!que.empty()) {
		auto q = que.front(); que.pop();
		mp[q.first] = q.second;
		unsigned sl[4];
		slide(q.first, sl);
		REP(i, 4) {
			if (sl[i] != 0) {
				if (appeared.count(sl[i]) == 0) {
					appeared.insert(sl[i]);
					que.push(make_pair(sl[i], q.second + 1));
				}
			}
		}
	}
	return mp;
}
signed main()
{
	auto mp = move(push_back_all());
	unsigned inpt[2][4];
	while (cin >> inpt[0][0] >> inpt[0][1] >> inpt[0][2] >> inpt[0][3] >> inpt[1][0] >> inpt[1][1] >> inpt[1][2] >> inpt[1][3]) {
		cout << mp[encode(inpt)] << endl;
	}
}


Measured memory_bytes: 5020
#include<stdio.h>
#include<math.h>
int main()
{
  int a,b;
  scanf("%d %d", &a, &b);
  double x=sqrt(a*pow(10, (int)log10(b) + 1) + b);
  if (ceil(x) != floor(x)){
	printf("No\n");
  }else printf("Yes\n");
  return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] strArray = new String[n];
        int taroSum = 0;
        int hanacoSum = 0;
        for(int i = 0; i < n; i++){
            String a = sc.next();
            String b = sc.next();
            int result = a.compareTo(b);
            if(result == 0){
                taroSum++;
                hanacoSum++;
            }else if(result < 0){
                hanacoSum += 3;
            }else{
                taroSum += 3;
            }
        }
        System.out.println(taroSum + " " + hanacoSum);
    }
}


Measured memory_bytes: 29664
#include <bits/stdc++.h>
    using namespace std;
	typedef long long int ll; 
     
    int main() {
      ll N,K;
      ll P = 1000*1000*1000+7;
      cin >> N >> K; 
      ll A = N-K+1;  
      ll B = K-1; 
      ll C[A+1][A+1]; 
      ll D[B+1][B+1];
      
      for(int i=0; i<=A; i++){
        for(int j=0; j<=i; j++){
          if(j==0 || j==i){ 
            C[i][j]=1;
          }else{
            C[i][j]= (C[i-1][j-1]+C[i-1][j]) % P;
          }
        }
      }
      
      for(int i=0; i<=B; i++){
        for(int j=0; j<=i; j++){
          if(j==0 || j==i){ 
            D[i][j]=1;
          }else{
            D[i][j]= (D[i-1][j-1]+D[i-1][j]) % P;
          }
        }
      }
      
      for(int i=1; i<=K; i++){
        if(i>N-K+1){
          cout<<0<<endl; 
        }else{
          cout<< (C[A][i] * D[B][i-1])%P << endl; 
        }
      }
    }

Measured memory_bytes: 30848
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 500000
ll MOD=1e9+7;

main(){
    int n=in(),c=in();
    vec a,b;
    rep(i,n){
        a.pb(in());
    }
    rep(i,n)b.pb(in());
    vector<vector<ll>> r(505);
    vector<vector<ll>> pw(505);
    rep2(i,1,500){
        ll temp=1;
        rep2(j,1,500){
            pw[i].pb(temp);
            temp=temp*i%MOD;
        }
    }
    rep2(i,0,500){
        r[i].pb(0);
        rep2(j,1,500){
            r[i].pb(((r[i].back())+pw[j][i])%MOD);
        }
    }
    vector<vector<ll>> dp(505,vector<ll>(505));
    dp[0][0]=1ll;
    rep2(i,1,n){
        rep2(j,0,c){
            rep2(k,0,j){
                dp[i][j]=(dp[i][j]+(dp[i-1][k]*((r[j-k][b[i-1]]-r[j-k][a[i-1]-1]+MOD)%MOD))%MOD)%MOD;
                //cout<<i<<" "<<j<<" "<<dp[i-1][k]<<" "<<r[j-k][b[i-1]]-r[j-k][a[i-1]-1]<<" "<<dp[i][j]<<endl;
            }
        }
    }
    cout<<dp[n][c];
}



Measured memory_bytes: 6272
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<deque>
using namespace std;
typedef pair<int, int>P;
typedef pair<int, pair < int, int > > PP;
typedef long long ll;
ll inf = -1;
ll mod = pow(10, 9) + 7;
 
int main() {
	int n,l;cin>>n>>l;
	int sum=0,choose=300;
	int c;
	for(int i=1;i<=n;i++){
		sum+=l+i-1;
		if(choose>abs(l+i-1)){
			choose=abs(l+i-1);
			c=l+i-1;
		}
	}
	cout<<sum-c<<endl;
	return 0;
}

Measured memory_bytes: 256
n,k=map(int, input().split())
x=0
a=list(range(0,n+1))
aa=list(range(1,n+2))
mod=10**9+7
from itertools import accumulate
A=list(accumulate(a))
for i in range(k-1,n+1):
    x+=(2*A[i]-1)%mod
    x%=mod
print(((sum(aa[k-1:])%mod*n)%mod-x+mod)%mod)

Measured memory_bytes: 81960
#include<iostream>

int main(){
    int X, A, B;
    std::cin >> X >> A >> B;
    if(A >= B){
        std::cout << "delicious" << std::endl;
    }else{
        if(A + X >= B){
            std::cout << "safe" << std::endl;
        }else{
            std::cout << "dangerous" << std::endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())

taka = T1 * A1 + T2 * A2
aoki = T1 * B1 + T2 * B2
if taka == aoki:
    print("infinity")
    quit()
if taka > aoki:
    taka, aoki = aoki, taka
    A1, B1 = B1, A1
    A2, B2 = B2, A2
if A1 < B1:
    print(0)
    quit()
if A1 == B2:
    print(1)
    quit()
first_diff = A1 * T1 - B1 * T1
diff = aoki - taka
print(first_diff // diff * 2 + (first_diff % diff != 0))


Measured memory_bytes: 3064
#include <algorithm>
#include <cstdio>
using namespace std;

int par[100005];
int Rank[100005];

void init(int n){
  for(int i=0;i<n;i++){
    par[i]=i;
    Rank[i]=0;
  }
}

int find(int x){
  if(par[x]==x){
    return x;
  }else{
    return par[x]=find(par[x]);
  }
}

void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y)return;
  if(Rank[x]<Rank[y]){
    par[x]=y;
  }else{
    par[y]=x;
    if(Rank[x]==Rank[y])Rank[x]++;
  }
}

bool same(int x,int y){
  return find(x)==find(y);
}

int main(){
  int n,m,q,s,t;
  scanf("%d%d",&n,&m);
  init(n);
  for(int i=0;i<m;i++){
    scanf("%d%d",&s,&t);
    unite(s,t);
  }
  scanf("%d",&q);
  for(int i=0;i<q;i++){
    scanf("%d%d",&s,&t);
    if(same(s,t))printf("yes\n");
    else printf("no\n");
  }
  return 0;
}

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

int main(){
  int N;
  cin >> N;
  char s[N];
  for (int i; i < N; i++){
    cin >> s[i];
  }
  
  int P_num = 0;
  int W_num = 0;
  int G_num = 0;
  int Y_num = 0;
  
  for (int i; i < N; i++){
    if (P_num == 0 && s[i] == 'P'){
      P_num++;
    } else if (W_num == 0 && s[i] == 'W'){
      W_num++;
    } else if (G_num == 0 && s[i] == 'G'){
      G_num++;
    } else if (Y_num == 0 && s[i] == 'Y'){
      Y_num++;
    }
  }
  
  int sum = P_num + W_num + G_num + Y_num;
  if (sum == 3){
    cout << "Three" << endl;
  } else if (sum == 4){
    cout << "Four" << endl;
  }
}
      

Measured memory_bytes: 256
import           Control.Monad
import           Data.IORef
import           Data.List.Split
import           Data.Maybe
import           Data.List

main :: IO ()
main = do
  n <- readLn
  ts <- map read . words <$> getLine
  m <- readLn
  pxs <- replicateM m $ map read . words <$> getLine

  forM_ [(p, x) | (p:x:_) <- pxs] $ \px -> do
    let s = sum (solve ts px [0..n - 1] [])
    print s


solve :: [Int] -> (Int, Int) -> [Int] -> [Int] -> [Int]
solve _ _ [] ans = ans
solve ts (p, x) (i:is) ans
  | i == p - 1 = solve ts (p, x) is ans ++ [x]
  | otherwise = solve ts (p, x) is ans ++ [ts !! i]



Measured memory_bytes: 1020
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main(){
    string s;
    cin >> s;
    for(int i=0; i<s.size(); i++){
        for(int j=0; j<s.size()-i; j++){
            string t;
            if(j!=0){
                t=s.substr(0,j-1);
            }
            t+=s.substr(j+i);
            if(t=="keyence"){
                cout << "YES"<< endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 256