akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		double a = scn.nextDouble();
      double b = scn.nextDouble();
      double h = scn.nextDouble();
      double m = scn.nextDouble();
      double hh = h*30 + m/2;
      double mm = m*6;
      double x =hh - mm; 
      double cosx = Math.cos(Math.toRadians(x));
      double ans2 = a*a + b*b - 2*a*b*cosx;
      double ans = Math.sqrt(ans2);
      System.out.println(ans);
	}
}


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

#define _ << ": " <<
#define watch1(var1) cerr << (#var1) _ var1 << '\n'
#define watch2(var1, var2) cerr << (#var1) _ var1 << ", " << (#var2) _ var2 << '\n'
#define watch3(var1, var2, var3) cerr << (#var1) _ var1 << ", " << (#var2) _ var2 << ", " << (#var3) _ var3 << '\n'
#define wloop(size, arr) cerr << (#arr) << ": "; for (int i = 0; i < int(size); i++) cerr << arr[i] << " \n"[i+1 == int(size)]

template<typename... Args>
void read(Args&... args) { ((cin >> args), ...); }

template<typename... Args>
void show(Args... args) { ((cout << args << " "), ...); }

#define ll long long
#define ints(a...) int a; read(a)
#define IN(a) for (auto &it : a) cin >> it


void solve() {
    ints(n, k);
    vector<int> v(n + 1), dp(100001, 1e9);
    for (int i = 1; i <= n; i++) read(v[i]);

    dp[1] = 0;
    dp[2] = abs(v[2] - v[1]);
    for (int i = 3; i <= n; i++) {
        for (int j = 1; i - j > 0 && j <= k; j++) {
            dp[i] = min(dp[i], dp[i - j] + abs(v[i] - v[i - j]));
        }
    }

    show(dp[n]);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1; 
    // cin >> T;
    while (T--) solve();
    return 0;
}

Measured memory_bytes: 3960
function*stdinIter(){const t=require("fs").readFileSync("/dev/stdin","utf-8").trim().split(/\n|\s/);yield*t}function readMany(t,e){const i=e||this.iter||(this.iter=stdinIter()),n=[];for(let e=0;e<t;e+=1)n.push(i.next().value);return n};

(() => {
    const [ x, n ] = readMany(2).map(it => parseInt(it))
    const p = readMany(n).map(it => parseInt(it)).sort()

    let candidate = -1
    let beforeCandidateAbs = Infinity
    for (let i = 0; i <= 101; i += 1) {
        if (p.includes(i)) continue

        const abs = Math.abs(i - x)
        if (abs < beforeCandidateAbs) {
            beforeCandidateAbs = abs
            candidate = i
        }
    }

    console.log(candidate)
})()


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

int main() {
  int N,A,B,C,D;
  cin >> N;
  A=N/1000;
  B=N%1000/100;
  C=N%1000%100/10;
  D=N%1000%100%10;
  vector<int> alp;
  alp = {A,B,C,D};

  vector<int> X(8,0);
  for (int i=0; i<4; i++) {
    for (int j=0; j<8; j++) {
      int a = pow(2,4-i);
      int b = pow(2,3-i);
      if (j%a < b)
        X.at(j) += alp.at(i);
      else
        X.at(j) -= alp.at(i);
    }
  }
  ///要素7の配列番号を探す(kが見つかったらbreak)、それをkとする
  int k;
  for (int j=0; j<8; j++) {
    if (X.at(j)==7) {
      k=j;
      break;
    }
  }
  ///答えを出力
  cout << alp.at(0);
  for (int i=0; i<3; i++) {
    int a = pow(2,3-i);
    int b = pow(2,2-i);
    if (k%a < b)
      cout << "+" << alp.at(i+1);
    else
      cout << "-" << alp.at(i+1);
  }
  cout << "=7" << endl;
}


Measured memory_bytes: 256
while True:
    m,nmin,nmax = [int(x) for x in input().split()]
    if m == nmin == nmax == 0:
        break
    a = [0]
    for i in range(m):
        a.append(int(input()))

    ans = 0
    ans_index = nmin

    for n in range(nmin,nmax+1):
        if ans <= a[n]-a[n+1]:
            ans = a[n]-a[n+1]
            ans_index=n

    print(ans_index)



Measured memory_bytes: 5620
#include <stdio.h>
#include <string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
  Q[tail] = x;
  tail = (tail+1)%LEN;
}

P dequeue(){
  P x = Q[head];
  head = (head+1)%LEN;
  return x;
}

int main(){
  int q, i;
  int elaps=0, c;
  P u;
  scanf("%d %d", &n, &q);

  for(i=1; i<=n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1;
  tail = n+1;

  while(head!=tail){
    u = dequeue();
    if(q<u.t) c=q;
    else c=u.t;
    //c = min(q, u.t);
    u.t -= c;
    elaps += c;
    if(u.t>0) enqueue(u);
    else printf("%s %d\n", u.name, elaps);
  }
  /*int n, q, i, time[10000]
  scanf("%d %d", &n, &q);
  for(i=0; i=n; i++) scanf("%s %d", &name[i], &time[i]);
  for(i=0; i=n;i++){
    printf("%s %d\n", name[i], time[i]);
    }*/
  return 0;
  }



Measured memory_bytes: 11892
import java.io.*;
import java.util.*;
import java.lang.Math.*;

public class Main{ 
    
    public static void main(String[] args)throws IOException{
	try{
	InputStreamReader isr = new InputStreamReader(System.in);
	BufferedReader br=new BufferedReader(isr);
	String line;
	int n = Integer.parseInt(br.readLine());
	
	for(int i=0;i<n;i++){
	    line=br.readLine();
	    StringTokenizer st=new StringTokenizer(line);
	    int b=0,c=0,x=0;
	    boolean flag=true;
	    while(st.hasMoreTokens()){
		
		if((x=Integer.parseInt(st.nextToken()))>b)
		    b=x;
		else if(x>c)
		    c=x;
		else
		    flag=false;
	    }
	    if(flag)
		System.out.println("YES");
	    else
		System.out.println("NO");
	}
	}catch(java.lang.NumberFormatException e){
	    System.out.println(e);
	}
    }
}

Measured memory_bytes: 16872
import java.util.*;

class Main {
  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int k = sc.nextInt();
    if (k <= a) {
      System.out.println(k);
    } else if (k > a && k <= a + b) {
      System.out.println(a);
    } else {
      System.out.println(a - (k - a - b));
    }
  }
}

Measured memory_bytes: 35860
#include<bits/stdc++.h>
using namespace std;
struct edge{
  vector<long>next;
  long count;
  long added;
  edge(){count=0;added=0;}
};
int main(){
  long N,Q;cin>>N>>Q;
  vector<edge>tree(N,edge());
  for(int i=0;i<N-1;i++){
    long a,b;cin>>a>>b;
    tree[a-1].next.push_back(b-1);
    tree[b-1].next.push_back(a-1);
  }
  for(int i=0;i<Q;i++){
    long p,x;cin>>p>>x;
    tree[p-1].added+=x;
  }
  vector<bool> filled(N,false);filled[0]=true;
  queue<long>q;q.push(0);
  tree[0].count=tree[0].added;
  while(q.size()){
    long f=q.front();q.pop();
    for(long n:tree[f].next){
      if(!filled[n]){
        filled[n]=true;
        q.push(n);
        tree[n].count=tree[f].count+tree[n].added;
      }
    }
  }
  for(int i=0;i<N;i++)cout<<tree[i].count<<" ";
  
}

Measured memory_bytes: 19456
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int n; cin >> n;
    vint a(n);
    rep(i,n) {
        int x; cin >> x;
        a[--x] = i;
    }
    a.push_back(-1);
    int ans = -1;
    int now = 0;
    int ct = 1;
    while (now++ < n) {
        if (a[now] > a[now-1]) ct++;
        if (a[now] < a[now-1]) {
            ans = max(ans,ct);
            ct = 1;
        }
    }
    ans = n - ans;
    cout << ans << endl;
}

Measured memory_bytes: 4840
def func(x,y):
    return x+y

class LazySegmentTree():
    def __init__(self, n):
        n_ = 1
        c_ = 0
        while n_ < n:
            n_ *= 2
            c_ +=1

        self.lv = c_
        self.n = n_
        self.arr = [0] * (2*self.n-1)
        self.lazy = [0] * (2*self.n-1)

    #伝播区間
    def getidx(self, l, r):
        L = (l + self.n) >> 1
        R = (r + self.n) >> 1
        lc = 0 if l & 1 else (L & -L).bit_length()
        rc = 0 if r & 1 else (R & -R).bit_length()
        for i in range(self.lv):
            if rc <= i:
                yield R
            if L < R and lc <= i:
                yield L
            L >>= 1; R >>=1

    #伝播
    def propagate(self,*ids):
        for i in reversed(ids):
            v = self.lazy[i-1]
            if v is 0:
                continue
            self.lazy[2*i-1] += v
            self.arr[2*i-1] += v
            self.lazy[2*i] += v
            self.arr[2*i] += v
            self.lazy[i-1] = 0

    #[l, r] をxで更新
    def update(self,l,r,x):
        #[l, r)に変更
        r+=1
        *ids, = self.getidx(l,r)
        self.propagate(*ids)

        L = self.n + l; R = self.n + r
        while L < R:
            if R & 1:
                R -=1
                self.lazy[R-1] += x
                self.arr[R-1] += x
            if L & 1:
                self.lazy[L-1] += x
                self.arr[L-1] += x
                L += 1
            L >>= 1; R >>= 1

        for i in ids:
            self.arr[i-1] = func(self.arr[2*i-1], self.arr[2*i])

    #[l, r]のクエリに答える
    def query(self,l,r):
        #[l, r)に変更
        r+=1
        self.propagate(*self.getidx(l,r))
        L = self.n + l; R = self.n + r

        s = 0 #初期化！！！
        while L < R:
            if R & 1:
                R -=1
                s = func(s, self.arr[R-1])
            if L & 1:
                s = func(s, self.arr[L-1])
                L += 1
            L >>= 1; R >>= 1
        return s

#0-indexed なので1-からのときは−１する
import sys
input=sys.stdin.readline
n,q=map(int,input().split())
sg=LazySegmentTree(n)
for _ in range(q):
    l=list(map(int,input().split()))
    if l[0]==0:
        c,s,t,x=l
        sg.update(s-1,t-1,x)
    else:
        c,i=l
        print(sg.query(i-1,i-1))



Measured memory_bytes: 20744
#include <iostream>
using namespace std;
int main() {
int A, B, C, K, cnt = 0;
cin >> A >> B >> C >> K;
while (A >= B) { cnt += 1; B *= 2; }
while (B >= C) { cnt += 1; C *= 2; }
if (cnt <= K) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
	string s,t;
	cin>>s>>t;
	int ans = 0;
	for(int i=0;i<s.length();i++){
		if(s[i]!=t[i])ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3916
// vim: set fdm=marker:
// {{{
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <utility>

using namespace std ;

typedef long long ll ;

// }}}

int main()
{
    ll X, Y;
    cin >> X >> Y;
    if(X%Y)
        cout << X << endl;
    else
        cout << -1 << endl;
    return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
# DSL_2_H: RMQ and RAQ
# Range Minimum Query and Range Add Query
# Lazy propagate segment tree

from array import array
import sys


class SegmentTree:
    MAXV = 1000 * 10**5 + 1

    def __init__(self, n):
        size = 1
        while size < n:
            size *= 2
        self.size = 2*size - 1
        self.data = array('i', [0] * self.size)
        self.lazy = array('i', [0] * self.size)

    def add(self, lo, hi, v):
        def _add(r, i, j, lz):
            left, right = r*2 + 1, r*2 + 2
            if lazy[r]:
                lz += lazy[r]
                lazy[r] = 0

            if lo <= i and j <= hi:
                lz += v
                if lz:
                    data[r] += lz
                    if i < j:
                        lazy[left] += lz
                        lazy[right] += lz
            else:
                mid = (i + j) // 2
                if mid >= lo:
                    lv = _add(left, i, mid, lz)
                else:
                    lazy[left] += lz
                    lv = data[left] + lazy[left]

                if mid < hi:
                    rv = _add(right, mid+1, j, lz)
                else:
                    lazy[right] += lz
                    rv = data[right] + lazy[right]

                if lv < rv:
                    data[r] = lv
                else:
                    data[r] = rv

            return data[r]

        lazy = self.lazy
        data = self.data
        _add(0, 0, self.size//2, 0)

    def min(self, lo, hi):
        def _min(r, i, j, lz):
            left, right = r*2 + 1, r*2 + 2
            if lazy[r]:
                lz += lazy[r]
                lazy[r] = 0
            if lz:
                data[r] += lz

            if lo <= i and j <= hi:
                if lz and i < j:
                    lazy[left] += lz
                    lazy[right] += lz
                return data[r]
            else:
                mid = (i + j) // 2
                if mid >= lo:
                    lv = _min(left, i, mid, lz)
                else:
                    lazy[left] += lz
                    lv = self.MAXV

                if mid < hi:
                    rv = _min(right, mid+1, j, lz)
                else:
                    lazy[right] += lz
                    rv = self.MAXV

                if lv < rv:
                    return lv
                else:
                    return rv

        lazy = self.lazy
        data = self.data
        return _min(0, 0, self.size//2, 0)


def run():
    n, q = [int(i) for i in input().split()]

    tree = SegmentTree(n)

    ret = []
    for line in sys.stdin:
        com, *args = line.split()
        if com == '0':
            s, t, x = map(int, args)
            tree.add(s, t, x)
        elif com == '1':
            s, t = map(int, args)
            ret.append(tree.min(s, t))

    sys.stdout.write("\n".join([str(i) for i in ret]))
    sys.stdout.write("\n")


if __name__ == '__main__':
    run()



Measured memory_bytes: 19056
from math import factorial

N, M = map(int, input().split())
mod = 10 ** 9 + 7


def comb(n,r):
  if n >= r:
    numer = factorial(n) % mod
    denom_inv = pow(((factorial(r) % mod)* (factorial(n-r) % mod)), mod-2, mod)
    return (numer * denom_inv) % mod
  else:
    return 0


pp = [0]
div = 2
while M > 1:
    if pp[-1] != 0:
        pp.append(0)
    while M % div == 0:
        pp[-1] += 1
        M = M / div
    div += 1

ans = 1
for p in pp:
    ans = (ans * comb(N+p-1, p)) % mod

print(ans)

Measured memory_bytes: 112220
sx, sy, tx, ty= map(int, input().split())

move = []
temp_x = 0
temp_y = 0


def move_1(sX, sY, gX, gY):
    temp_x = sX
    temp_y = sY
    while temp_y < gY:
        move.append('U')
        temp_y += 1

    while temp_x < gX:
        move.append('R')
        temp_x += 1

def move_2(sX, sY, gX, gY):
    temp_x = sX
    temp_y = sY
    while temp_y > gY:
        move.append('D')
        temp_y -= 1

    while temp_x > gX:
        move.append('L')
        temp_x -= 1



move_1(sx, sy, tx, ty)
move_2(tx, ty, sx, sy)
move.append('L')
move_1(sx - 1, sy, tx, ty + 1)
move.append('DR')
move_2(tx + 1, ty, sx, sy - 1)
move.append('U')
print(''.join(move))



Measured memory_bytes: 3188
#include<iostream>
using namespace std;
int main(){
    int x;
    cin >>x;
    switch(x%10){
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
            cout << "hon";
            break;
        case 0:
        case 1:
        case 6:
        case 8:
            cout << "pon";
            break;
        case 3:
            cout << "bon";
            break;
    }

}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
const int mx=12;
char s[mx][mx];
bool vis[mx][mx];
int dir[2][2]={{1,0},{0,1}};
int n,m;
void dfs(int r,int c){
  vis[r][c]=true;
  for(int i=0;i<2;i++){
    int nr=r+dir[i][0];
    int nc=c+dir[i][1];
    if(0<=nr && nr<n && 0<=nc && nc<m && !vis[nr][nc] && s[nr][nc]=='#'){
      dfs(nr,nc);
      break;
    }
  }
}
int main(){
  scanf("%d %d",&n,&m);
  for(int i=0;i<n;i++){
    scanf("%s",s[i]);
  }
  dfs(0,0);
  bool ok=true;
  for(int i=0;i<n;i++)for(int j=0;j<m;j++){
    if(s[i][j]=='#' && !vis[i][j])ok=false;
  }
  if(ok)puts("Possible");
  else puts("Impossible");
  return 0;
}


Measured memory_bytes: 256
import heapq
n,m = map(int,input().split())
a = list(map(int,input().split()))
a = [ -i for i in a ]
heapq.heapify(a)

for i in range(m):
    tmp_min = heapq.heappop(a)
    heapq.heappush(a, (-1)*(-tmp_min//2))
print(-sum(a))


Measured memory_bytes: 14180
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
using namespace std;

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <stack>
#include <bitset>

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

	cout << (a + b) / 2 + (a + b) % 2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <deque>
#include <stack>
#include <iomanip>
#include <cmath>


using namespace std;


typedef long long ll;
typedef long double ld;


const ll MOD_CONST = 1000000007ll;


ll modSum(ll a, ll b, ll MOD = MOD_CONST) {
  return ((a % MOD) + (b % MOD)) % MOD;
}


ll modSubtract(ll a, ll b, ll MOD = MOD_CONST) {
  return (((a % MOD) - (b % MOD)) + MOD + MOD) % MOD;
}


ll modProd(ll a, ll b, ll MOD = MOD_CONST) {
  return ((a % MOD) * (b % MOD)) % MOD;
}


ll getPowMod(ll x, ll e, ll MOD = MOD_CONST) {
  if (e == 0) return 1;
  if (e % 2 == 0) {
    ll tmp = getPowMod(x, e/2, MOD);
    return modProd(tmp, tmp);
  } else {
    ll tmp = getPowMod(x, e-1, MOD);
    return modProd(tmp, x);
  }
}


ll getPow(ll x, ll e) {
  if (e == 0) return 1;
  if (e % 2 == 0) {
    ll tmp = getPow(x, e/2);
    return tmp * tmp;
  } else {
    ll tmp = getPow(x, e-1);
    return tmp * x;
  }
}


ll getInverse(ll x, ll MOD = MOD_CONST) {
  return getPowMod(x, MOD-2, MOD);
}


bool isEven(ll x) {
  ll tmp = ((x % 2) + 2) % 2;
  return tmp == 0;
}


ll getSumOfDigitsInBase(ll n, ll b) {
  ll ret = 0;
  while (n > 0) {
    ret += n % b;
    n /= b;
  }
  return ret;
}


vector<int> getKMP(string &s) {
  int len = (int)s.size();
  vector<int> ret (len, 0);
  for (int i = 1 ; i < len ; i++) {
    int at = ret[i-1];
    while (at > 0 && s[i] != s[at]) {
      at = ret[at-1];
    }
    if (s[i] == s[at]) {
      at++;
    }
    ret[i] = at;
  }
  return ret;
}


string getSubstring(string &s, int from, int to) {
  int l = to-from+1;
  if (l <= 0) {
    return "";
  }
  return s.substr(from, l);
}

ll gcd(ll a, ll b, ll & x, ll & y) {
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    ll x1, y1;
    ll d = gcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}


pair<ll, ll> getIntersectingRange(ll a1, ll b1, ll a2, ll b2) {
  ll s = max(a1, a2);
  ll e = min(b1, b2);

  return {s, e};
}


bool isNonEmptyIntersection(ll a1, ll b1, ll a2, ll b2) {
  auto p = getIntersectingRange(a1, b1, a2, b2);
  return p.first <= p.second;
}















int N;
string s;


void input() {
  cin >> s;
  N = (int)s.size();
}


void preprocess() {
}


void solve() {
  bool parity = N % 2;
  bool same = (s[0] == s[N-1]);
  if ((parity && same) || ((!parity) && (!same))) {
    cout << "Second\n";
  } else {
    cout << "First\n";
  }
}


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

  int T;
//  cin >> T;
  T = 1;

  for (int i = 0 ; i < T ; i++) {
    input();
    preprocess();
    solve();
  }

  return 0;
}


Measured memory_bytes: 512
As = list(map(int, input().split()))
"""
1,1は偶奇の調整
偶奇が一致したら
2であとは行ける
"""
sAs = sorted(As, reverse=True)
amari = [a%2 for a in As]
amari_a  = sorted([(a%2,a) for a in As])
if sum(amari) == 0 or sum(amari) == 3:
    ans = (2*sAs[0] - sAs[1] - sAs[2])//2
    print(ans)
elif sum(amari) == 1:
    # 偶奇合わせ
    a1 = amari_a[0][1] + 1
    b1 = amari_a[1][1] + 1
    c1 = amari_a[2][1] 
    sAs = sorted([a1,b1,c1],reverse=True)
    ans = (2*sAs[0] - sAs[1] - sAs[2])//2
    print(ans+1)
else:
    # 偶奇合わせ
    a1 = amari_a[1][1] + 1
    b1 = amari_a[2][1] + 1
    c1 = amari_a[0][1] 
    sAs = sorted([a1,b1,c1],reverse=True)
    ans = (2*sAs[0] - sAs[1] - sAs[2])//2
    print(ans+1)


Measured memory_bytes: 3064
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

alias Key = Tuple!(int, "cost", int, "mask");

long calc(int num, Key[] keys) {
    int n = cast(int)keys.length;

    // dp[i 番目の鍵][宝箱の鍵(ビットマスク)]
    auto dp = new long[][](n + 1, 1 << num);
    for (int i = 0; i < dp.length; i++) dp[i][] = int.max;

    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        int cost = keys[i].cost;
        int mask = keys[i].mask;
        for (int j = 0; j < (1 << num); j++) {
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            dp[i+1][j | mask] = min(dp[i+1][j | mask], dp[i][j] + cost);
        }
    }
    auto ans = dp[n][(1 << num) - 1];
    return ans == int.max ? -1 : ans;
}

void main() {
    int n, m; scan(n, m);
    Key[] keys;
    foreach (_; 0..m) {
        int a, b; scan(a, b);
        auto c = readints;
        int mask = 0;
        foreach (e; c) mask |= (1 << (e-1));
        keys ~= Key(a, mask);
    }
    writeln(calc(n, keys));
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;


Measured memory_bytes: 37884
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323846 
int main(void){
    double a,b,h,m,A=0,B=0,H=0,M=0;
    double aaa=0.0,bbb=0.0,sum=0.0,cosai=0.0,ans=0.0;
    cin >> a >> b >> h >> m;
    
    A = (double)a;
    B = (double)b;
    H = (double)h;
    M = (double)m;
    
    sum = abs((60.0*H+M)*0.5-M*6.0);
    if(sum>180.0){
        aaa =360.0-sum;
    }else{
        aaa = sum;
    }
    double radian = aaa*PI/180.0;
    cosai = cos(radian);
    ans = pow(A,2.0)+pow(B,2.0)+(-2.0)*A*B*cosai;
    ans = sqrt(ans);
    
    cout << fixed << setprecision(10) << ans << endl;
    
    return 0;
}


Measured memory_bytes: 4244
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (V)) cout <<x <<" " <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int main() {
  int a,b,c,d; cin >>a >>b >>c >>d;
  while (true){
    c -= b;
    if (c <= 0){
      cout <<"Yes" <<endl;
      return 0;
    }
    a -= d;
    if (a <= 0){
      cout <<"No" <<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3632
// Ivan Zanov
// Template
#include <iostream>
#include <utility>
#include <bitset>
#include <vector>
#include <set>
#include <unordered_map>
#include <map>
#include <assert.h>
#include <cmath>
#include <algorithm>
#include <complex>
#include <deque>
#include <iomanip>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <memory>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <sstream>
#include <exception>
#include <functional>
#include <cstring>
#include <cstdlib>
using namespace std;
#define lowbit(x) ((x)&((x)^((x)-1)))
#define max(a,b) (a<b?b:a)
#define IOS ios_base::sync_with_stdio(0);
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define INF (int)1e9
#define EPS (int)1e-9
#define bit_count __builtin_popcount
#define gcd __gcd
#define size(r) r.size()
#define max3(a, b, c) max(a, max(b,c))
#define min3(a, b, c) min(a, min(b,c))
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
inline void set_bit(int & n, int b) { n |= (1 << (int) b); }
inline void unset_bit(int & n, int b) { n &= ~(1 << (int) b); }
inline bool check_bit(int n, int pos) { return ( n & (1 << (pos))); }
inline ll lcm(ll a, ll b){ return (a * b / gcd(a,b));}
int main() {
    int a, b;
    cin>>a>>b;
    unordered_map<int, bool> cnt;
    cnt[a] = true;
    cnt[b] = true;
    if(cnt[1] == false)
            cout<<1<<endl;
    else if(cnt[2] == false)
        cout<<2<<endl;
    else
        cout<<3<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <string>
#define ll long long
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vvvl vector<vector<vector<ll> > >
#define vd vector<double>
#define vvd vector<vector<double> >
#define vvvd vector<vector<vector<double> > >
#define mod 1000000007
using namespace std;

ll gcd(ll a,ll b){
    ll t = max(a,b);
    b = min(a,b);
    a = t;
    while(min(a,b)){
        t = a;
        a = b;
        b = t % b;
    }
    return a;
}

ll ggcd(vl a){
    ll ret = a[0];
    for(int i=1;i<a.size();++i){
        ret = gcd(ret,a[i]);
    }return ret;
}

int main(void){
    ll n,x; cin>>n>>x;
    vl xmap(n,0);
    for(int i=0;i<n;++i){
        cin>>xmap[i];
        xmap[i] = abs(xmap[i]-x);
    }
    cout<<ggcd(xmap)<<endl;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<math.h>

int main () {
    unsigned long n;
    unsigned long m = 1;

    scanf("%ld", &n);

    unsigned int cl = ceil(sqrt(n));
    for (unsigned int i = 1; i <= cl; ++i) {
        if (n % i == 0 && m + n/m > i + n/i) {
            m = i;
        }
    }

    printf("%ld\n", m + n/m - 2);
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <random>
#include <deque>
#include <bitset>
#include <string>
#include <queue>
#include <complex>
 
//#define int long long
 
#define mp(a, b) make_pair(a, b)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
 
#define endl '\n'
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
mt19937 mrand(random_device{}());
 
double PI = acos((double)-1);
const ld eps = 1e-7;
const ll inf0 = 1023 * 1024 * 1024;
const ll inf = inf0 * inf0;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
	
void solve();
void scan();
 
signed main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
	cout << fixed; cout.precision(15);
	solve();
	return 0;
}

void solve() {
	int h, w;
	cin >> h >> w;
	int k; cin >> k;
	vector<string> f(h);
	for (int i = 0; i < h; i++) {
		cin >> f[i];
	}
	int ans = inf0;
	for (int mask = 0; mask < (1 << (h - 1)); mask++) {
		int cur = 0;
		for (int i = 0; i < (h - 1); i++)
			if ((1 << i) & mask)
				cur++;
		vector<int> cc(cur + 1);
		bool bl = true;
		for (int i = 0; i < w; i++) {
			int id = 0;
			bool fl = false;
			for (int j = 0; j < h; j++) {
				if (f[j][i] == '1') {
					cc[id]++;
					if (cc[id] == k + 1) {
						fl = true;
						break;
					}
				}
				if ((1 << j) & mask)
					id++;
			}
			if (fl) {
				cur++;
				for (int j = 0; j < cc.size(); j++)
					cc[j] = 0;
				id = 0;
				for (int j = 0; j < h; j++) {
					if (f[j][i] == '1') {
						cc[id]++;
						if (cc[id] == k + 1) {
							bl = false;
							break;
						}
					}
					if ((1 << j) & mask)
						id++;
				}
				if (!bl)
					break;
			}
		}
		if (!bl) continue;
		ans = min(ans, cur);
	}
	cout << ans << endl;
    return;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
#include<functional>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define all(v) v.begin(), v.end()
#define P pair<int, int>
const ll  MOD = 1000000007;

int main() {
	ll r;
	cin >> r;
	cout << 3 * r * r;
	return 0;
}

Measured memory_bytes: 256
def read_input():
    n = int(input())
    s = input().strip()

    return n, s

def submit():
    n, s = read_input()

    x = 0
    max = x

    for c in s:
        if c == 'I':
            t = 1
        else:
            t = -1

        x += t

        if max < x:
            max = x

    print(max)


if __name__ == '__main__':
    submit()


Measured memory_bytes: 38256
/**
 * Created by hiramekun at 22:31 on 2020-03-31.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll h, w;
    cin >> h >> w;
    vector<vector<char>> field(h, vector<char>(w));
    vector<vector<ll>> dist(h, vector<ll>(w, -1));
    rep(i, h) rep(j, w) cin >> field[i][j];

    queue<P> que;
    ll ans = 0;
    rep(i, h) rep(j, w) if (field[i][j] == '#') que.push(P(i, j)), dist[i][j] = 0;
    while (!que.empty()) {
        ll x = que.front().first, y = que.front().second;
        que.pop();
        rep(i, 4) {
            ll nx = x + dx[i], ny = y + dy[i];
            if (0 <= nx && nx <= h - 1 && 0 <= ny && ny <= w - 1 && dist[nx][ny] == -1) {
                que.push(P(nx, ny));
                dist[nx][ny] = dist[x][y] + 1;
                ans = max(ans, dist[nx][ny]);
            }
        }
    }
    cout << ans << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 25524
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;



int main() {
    const long long int mod = 1000000007,INF=99999999999999;
	map<long long int, long long int>mp;
    string str[2005],tmp;
	cout << fixed << setprecision(10);
    bool f[505][505] = {};
    
    while(1){
        long long int n,l,r,a[105],res=0;
        cin>>n>>l>>r;
        if(n==0){return 0;}
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        a[n]=1;
        for(int i=l;i<=r;i++){
            for(int j=0;j<=n;j++){
                if(i%a[j]==0&&j%2==0){
                    res++;
                    break;
                }else if(i%a[j]==0){
                    break;
                }
            }
        }
        cout<<res<<endl;
    }
} 



Measured memory_bytes: 3128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    int n, d, x; cin >> n >> d >> x;
    ll ans = x;
    rep(i, n) {
        int a; cin >> a;
        ans += (d-1) / a + 1;
    }
    cout << ans;
}


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

#define __m int mid=(l+r)>>1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1

template<class T>
inline bool rd(T &num) {
    char in;
    bool IsN = false;
    while(in = getchar(), in != '-' && (in < '0' || in > '9'))if(in == EOF)return false;
    in == '-' ? (IsN = true, num = 0) : num = in - '0';
    while(in = getchar(), in >= '0' && in <= '9')num = num * 10 + in - '0';
    return IsN ? num = -num : num, true;
}

#define rep(i,a,b) for(register int i = (a); i< (b); i++)
#define per(i,a,b) for(register int i = (a); i> (b); i--)
#define clr(a) memset(a,0,sizeof(a));
#define inf(a) memset(a,0x3f,sizeof(a));
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define rd2(a,b) rd(a)&&rd(b)
#define rd3(a,b,c) rd(a)&&rd(b)&&rd(c)
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))

string nico;
#ifdef LOCAL
#define bug(x) cout<<#x<<" : "<<x<<endl
#define infile(x) freopen(x,"r",stdin)
#define outfile(x) freopen(x,"w",stdout)
#else
#define bug(x)
#define infile(x)
#define outfile(x)
#endif

const int maxn = 2e5 + 7;
const int inf  = 0x3f3f3f3f;
const LL linf  = (LL)inf << 32 | inf;
const int mod  = 1e9 + 7;

int main() {
    IO;
    int a,b;
    cin>>a>>b;
    if(a+b == 15)
        cout<<"+"<<endl;
    else if(a*b == 15)
        cout<<"*"<<endl;
    else 
        cout<<"x"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <math.h>
using namespace std;
using s64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)

int main()
{
    s64 a,b;
    cin >> a >> b;
    s64 ret = 0;

    s64 mod = 2;
    rep(i,45)
    {
        s64 offset = a % mod;
        s64 width = (b-a+1) % mod;
        
        s64 one_cnt = 0;
        if(mod == 2)
        {
            if(offset == 0)
            {
                if((b-a+1)%4 == 1) one_cnt = 0;
                else if((b-a+1)%4 == 2) one_cnt = 1;
                else if((b-a+1)%4 == 3) one_cnt = 1;
                else one_cnt = 2;
            }
            else
            {
                if((b-a+1)%4 == 1) one_cnt = 1;
                else if((b-a+1)%4 == 2) one_cnt = 1;
                else if((b-a+1)%4 == 3) one_cnt = 2;
                else one_cnt = 2;
            }            
        }
        else
        {
            if(offset < mod / 2)
            {
                if(offset + width < mod/2)
                    one_cnt = 0;
                else if(offset + width < mod)
                    one_cnt = offset + width - mod / 2;
                else
                    one_cnt = mod/2;
            }
            else
            {
                if(offset + width < mod)
                    one_cnt = width;
                else if(offset + width < mod + mod/2)
                    one_cnt = mod - offset;
                else
                    one_cnt = width - mod/2;
            }
        }

        //cout << mod << " " << offset << " " << width << " "<< one_cnt << endl;
        
        if(one_cnt % 2 == 1)
            ret += mod >> 1;

        if(mod > b) break;

        mod *= 2;
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
/*     ####   ####  #               ####  #        ##   #    # #    # ###### #####
      #      #    # #              #      #       #  #  ##  ## ##  ## #      #    #
       ####  #    # #               ####  #      #    # # ## # # ## # #####  #    #
           # #  # # #                   # #      ###### #    # #    # #      #####
      #    # #   #  #              #    # #      #    # #    # #    # #      #   #
       ####   ### # ###### #######  ####  ###### #    # #    # #    # ###### #    #
*/
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef vector<long long> VLL;
typedef vector<string> VS;
typedef vector<pair<LL, LL> > VP;
 
 
#define For(in) for (LLi i = 0; i < (n); i++)
#define FOR(in) for(LLi i=1; i <= (n); i++)
#define pb push_back
#define sr(v) sort(v.begin(), v.end())
#define rev(v) reverse(v.begin(), v.end())
#define uniq(v) v.erase(unique(v.begin(), v.end()), v.end());
#define exit(); return 0;
#define no "NO"
#define yes "YES"
#define con continue;
 

 
 
int main()
{
	
	long long a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a*b >= c*d)cout<<a*b<<endl;
	else cout<<c*d<<endl;
			
			
    exit()
 
 
}


Measured memory_bytes: 3612
(N, M), As = readlines.map{|l| l.split.map(&:to_i)}

class PriorityQueue
  attr_accessor :q
  def initialize
    @q = [nil]
  end

  def bubble_up(i)
    pi = i / 2
    return if i <= 1 || @q[pi] >= @q[i]
    @q[i], @q[pi] = @q[pi], @q[i]
    bubble_up(pi)
  end

  def add(e)
    @q << e
    bubble_up(@q.size - 1)
  end

  def bubble_down(i)
    ci = i * 2
    return if ci > @q.size - 1
    ci += 1 if ci != @q.size - 1 && @q[ci] < @q[ci + 1]
    return if @q[i] >= @q[ci]
    @q[i], @q[ci] = @q[ci], @q[i]
    bubble_down(ci)
  end

  def pop
    @q[1], @q[-1] = @q[-1], @q[1]
    ret = @q.pop
    bubble_down(1)
    ret
  end
end

pq =PriorityQueue.new
As.each{|a| pq.add(a)}
M.times do
  pq.add(pq.pop / 2)
end
puts pq.q.compact.inject(:+)

Measured memory_bytes: 10252
#include <stdio.h>

int main(void) {
	int a,b,c,i,x;
	scanf("%d %d %d",&a,&b,&c);
	for(i=a;i<=b;i++){
		if(c%i==0){
			x++;
		}
	}printf("%d\n",x);
	return 0;
}

Measured memory_bytes: 1828
#include <stdio.h>
#include <algorithm>

using namespace std;

int partition(int A[],int p,int r){
	int x = A[r];
	int i = p-1;
	for(int j = p; j < r; j++){
		if(A[j] <= x){
			i++;
			swap(A[i],A[j]);
		}
	}
	swap(A[i+1],A[r]);
	return i+1;
}

int main(){
	int n,partition_point;
	scanf("%d",&n);
	int A[n];
	for(int i = 0; i < n; i++) scanf("%d",&A[i]);

	partition_point = partition(A,0,n-1);

	for(int i = 0; i < n-1; i++){
		if(i == partition_point){
			printf("[%d] ",A[i]);
		}else{
			printf("%d ",A[i]);
		}
	}
	if(partition_point == n-1){
		printf("[%d]\n",A[n-1]);
	}else{
		printf("%d\n",A[n-1]);
	}
}


Measured memory_bytes: 2976
N, Y = map(int, input().split())

for x in range(2001):
    for y in range(2001):
        z = N - x - y
        if 0 <= z <= N:
            if 10000*x + 5000*y + 1000*z == Y:
                print(x, y, z)
                exit()
print(-1, -1, -1)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60

int x[100001], y[100001];
ll sumx[100001], sumy[100001]; // sum[i] ; 1～iまでの和

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

	int n, m; cin >> n >> m;
	sumx[0] = sumy[0] = 0LL;

	for (int i = 1; i <= n; i++) {
		cin >> x[i];
		sumx[i] = sumx[i - 1] + x[i];
	}

	for (int i = 1; i <= m; i++) {
		cin >> y[i];
		sumy[i] = sumy[i - 1] + y[i];
	}

	ll L = 0LL;
	for (int i = 1; i <= m; i++) {
		L += sumy[m] - sumy[i] - (m - i)*ll(y[i]);
		L %= MOD;
	}

	ll K = 0LL;
	for (int i = 1; i <= n; i++) {
		K += sumx[n] - sumx[i] - (n - i)*ll(x[i]);
		K %= MOD;
	}

	cout << K * L % MOD << endl;

	return 0;
}

Measured memory_bytes: 2560
#coding:utf-8

N = int(input())

ans = [0,0,0,0]

for i in range(N):
    S = str(input())
    if S == 'AC':
        ans[0] += 1
    elif S == 'WA':
        ans[1] += 1
    elif S == 'TLE':
        ans[2] += 1
    elif S == 'RE':
        ans[3] += 1

print("AC x {}".format(ans[0]))
print("WA x {}".format(ans[1]))
print("TLE x {}".format(ans[2]))
print("RE x {}".format(ans[3]))

Measured memory_bytes: 9088
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
const double pi = acos(-1);
typedef pair<int, int> P;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)

/*unsigned int xor128(void)
{
    static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned int t = (x ^ (x << 11));
    x = y;
    y = z;
    z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
unsigned int xor128rnd(unsigned int m)
{
    return xor128() % m;
}*/

bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)
{

    if (a.first == b.first)
        return a.second < b.second;

    return a.first < b.first;
}

int arr[110];

int dp[100010];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    //cout << fixed << setprecision(15);
    int N;
    cin >> N;

    vector<int> v;
    v.push_back(1);

    int t = 6;
    while (t <= N)
    {
        v.push_back(t);
        t *= 6;
    }
    t = 9;
    while (t <= N)
    {
        v.push_back(t);
        t *= 9;
    }

    for (int i = 0; i < 100010; ++i)
        dp[i] = 100000;

    dp[0] = 0;
    for (int i = 0; i < (int)v.size(); ++i)
    {
        for (int j = 0; j <= N; ++j)
        {
            if (j - v[i] >= 0)
            {
                dp[j] = min(dp[j], dp[j - v[i]] + 1);
            }
        }
    }
    cout << dp[N] << endl;
    return 0;
}


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

int main() {
  
  string s, t;
  
  cin >> s >> t;
  
  if(t.size() != s.size()+1) {
    cout << "No" << endl;
  }
  else {
    int mis_cnt = 0;
    for(int i = 0; i < s.size(); i++) {
      if(s.at(i) != t.at(i)) {
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
  }
  
}

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

using namespace std;
using ll = long long;

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; ++i) cin >> a[i];
  int ans = accumulate(begin(a), end(a), 0, [](int acc, int i) { return acc + i - 1; });
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n, m, l = map(int, raw_input().split(" "))
a = [map(int, raw_input().split(" ")) for j in range(n)]
b = [map(int, raw_input().split(" ")) for i in range(m)]

c = [[0 for k in range(l)] for j in range(n)]
for j in range(n):
    for k in range(l):
        for i in range(m):
            c[j][k] += a[j][i] * b[i][k]
for j in range(n):
    print " ".join(map(str, (c[j])))

Measured memory_bytes: 7124
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define all(v) v.begin(), v.end()

int main() {
	ios_base::sync_with_stdio(0);
	ll n, m;
	cin >> n >> m;
	if (2 * n < m) {
		ll l = 0, r = m;
		while (l < r - 1) {
			ll mid = (l + r) / 2;
			if (2 * (n + mid) < m - 2 * mid) l = mid;
			else r = mid;
		}
		m -= 2 * r;
		n += r;
	}
	cout << m / 2;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll int
#define ld long double
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define all(x) x.begin(),x.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
 


/*#define N 10000000
int prime[N+1]; 
void sieve() 
{
  ll i,j;
  prime[1]=1;
  FOR(i,2,N)
    prime[i]=i;
  for(i=4;i<N;i+=2)
    prime[i]=2;
  FOR(i,3,sqrt(N))
    if(prime[i]==i)
    {
      for(j=i*i;j<N;j+=i)
        if(prime[j]=j)
          prime[j]=i;
    }
} */
 


int main()
{
    fastio
    ll i,j;
    
    ll n;
    cin>>n;
    ll a[n];
    map<ll,ll>m;
    
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        
        m[a[i]]++;
    }
    ll res=0;
    /*ll cnt1=0;
    
    for(i=0;i<n;i++)
    {
        if(a[i]==1)
        ++cnt1;
    }
    if(cnt1)
    {
        if(cnt1==1)
        cout<<n-1;
        else 
        cout<<n;
        return 0;
    }*/
    
    
    for(i=0;i<n;i++)
    {
        ll d=sqrt(a[i]);
        int f=0;
        
        for(j=1;j<=d;j++)
        {
            if(j==1)
            {
                if(m[a[i]]>1)
                {
                    f=1;
                    break;
                }
                
                if(m[1]&&a[i]!=1)
                {
                    f=1;
                    break;
                }
                
                if(a[i]==1 && m[1]>1)
                {
                    f=1;
                    break;
                }
            }
            
            else if(a[i]%j==0)
            {
                if(m[j]||m[a[i]/j])
                {
                    f=1;
                    //cout<<a[i]<<" ";
                    break;
                }
            }
        }
        if(f)
        ++res;
    }
    cout<<n-res;
    
    return 0;
}


Measured memory_bytes: 33268
N = int(input())
S = list(input())

alphabet = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
ans = []

for i in range(len(S)):
  num = alphabet.index(S[i])+N
  if num > 25:
    num -= 26
  ans.append(alphabet[num])
  
ans = ''.join(ans)
print(ans)

Measured memory_bytes: 3188