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

namespace ABC132
{
    class D
    {

        static int _Mod = 1000000007;

        static void Main(string[] args)
        {
            int[] p = Console.ReadLine().Split(' ').Select(o => int.Parse(o)).ToArray();
            int N = p[0], K = p[1];
            int R = N - K;

            List<long[]> C = PascalTriangle(N);

            for (int i = 1; i <= K; i++)
            {
                long r;
                if (R - i + 1 < 0)
                {
                    r = 0;
                }
                else
                {
                    r = C[R + 1][R - i + 1] * C[K - 1][i - 1];
                    r = r %= _Mod;
                }
                Console.WriteLine(r);
            }

        }

        //パスカルの三角形(O(n^2)
        public static List<long[]> PascalTriangle(int n)
        {
            List<long[]> list = new List<long[]>();
            for (int i = 0; i <= n; i++)
            {
                long[] arr = new long[i + 1];

                arr[0] = 1; arr[i] = 1;
                if (i >= 2)
                {
                    long[] arrBfr = list[i - 1];
                    for (int j = 1; j < arr.Length - 1; j++)
                    {
                        arr[j] = arrBfr[j - 1] + arrBfr[j];
                        arr[j] %= _Mod;
                    }
                }
                list.Add(arr);
            }
            return list;
        }

    }
}


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

#define   M             100005
#define   ll            long long
#define   PI            atan(1.0)*4
#define   mst(x,v)      memset(x,v,sizeof(x))
#define   inf           (int)1e9

typedef   pair<int,int> P;

ll a[M];

int main() {

	ll n,t,d,c,ans,anger;
	scanf("%lld %lld %lld",&n,&t,&d);
	
	for(int i=0;i<n;i++) scanf("%lld",&a[i]); // 到达 

	sort(a,a+n);
	
	anger=a[0]+d; // 当前 我的客人 最极限的 等待时间 
	
	ans=1;c=1; // 有 1 辆车子  
	for(int i=1;i<n;i++) {
		
		if(c<t && a[i]<=anger) { // 坐得下 且不生气 
			c++;
		}
		else {
			anger=a[i]+d;
			c=1;
			ans++;
		}
		
	//	printf("anger:%2lld  now car:%2lld  now ple:%2lld\n",anger,ans,c);
		
	}
	
	printf("%lld\n",ans);
	
}




Measured memory_bytes: 1024
using System;

class Program
{
  static void Main()
  {
    int s = int.Parse(Console.ReadLine());
    int count = 0;
    while(true)
    {
      count ++;
      if(s == 1)
      {
        count ++;
        break;
      }
      else if (s % 2 == 0) s /= 2;
      else s = s * 3 + 1;
    }
    Console.WriteLine(Math.Max(4, count));
  }
}


Measured memory_bytes: 11092
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}
import java.lang

import scala.reflect.ClassTag

object Main {
  def get[T: ClassTag](implicit in: BufferedReader, converter: String => T): T = {
    converter(in.readLine)
  }

  def getArray[T: ClassTag](implicit in: BufferedReader, converter: String => T): Array[T] = {
    get[String].split("\\s+").map(converter)
  }

  implicit val intConverter: String => Int = s => Integer.parseInt(s)
  implicit val longConverter: String => Long = s => lang.Long.parseLong(s)

  def get[T1, T2](
                   implicit in: BufferedReader,
                   converter1: String => T1,
                   converter2: String => T2
                 ): (T1, T2) = {
    getArray[String] match {
      case Array(v1, v2) => (converter1(v1), converter2(v2))
    }
  }

  def get[T1, T2, T3](
                       implicit in: BufferedReader,
                       converter1: String => T1,
                       converter2: String => T2,
                       converter3: String => T3
                     ): (T1, T2, T3) = {
    getArray[String] match {
      case Array(v1, v2, v3) => (converter1(v1), converter2(v2), converter3(v3))
    }
  }

  implicit class TimesInt(val n: Int) {
    def times(f: Int => Unit): Unit = {
      for (i <- 0 until n) {
        f(i)
      }
    }
  }

  def main(args: Array[String]): Unit = {
    implicit val in: BufferedReader = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    
    out.println(
      if(getArray[Int].product % 2 == 0) {
        "No"
      } else {
        "Yes"
      }
    )

    out.flush()
  }
}

Measured memory_bytes: 25416
import sys
(n, m) = [int(i) for i in sys.stdin.readline().split()]
matrix = []
for i in range(0, n):
    a_i = [int(j) for j in sys.stdin.readline().split()]
    matrix.append(a_i)
vector = []
for i in range(0, m):
    b_i = int(sys.stdin.readline())
    vector.append(b_i)

for i in range(0, n):
    c = 0
    for j in range(0, m):
        c += matrix[i][j] * vector[j]
    print(c)

Measured memory_bytes: 7012
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s,s_;cin>>s;
  ll q,head=0,t,f;cin>>q;
  char c;
  rep(i,q) {
    cin>>t;
    if(t==1) head++;
    else {
      cin>>f>>c;
      if(f==1) {
        if(head%2==0) s_+=c;
        else s+=c;
      }
      else {
        if(head%2==0) s+=c;
        else s_+=c;
      }
    }
  }
  reverse(ALL(s_));
  s_+=s;
  if(head%2==1) reverse(ALL(s_));
  print(s_);
  return 0;
}

Measured memory_bytes: 1144
fun main(args: Array<String>) {
  val L = readInt()
  val a = L.toDouble() / 3
  println("%f".format(a * a * a))
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }
fun readLong() = readString().toLong()
fun readLongs() = readStrings().map { it.toLong() }


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

using namespace std;

int h, w;
char grid[10][10];

int main()
{
	cin >> h >> w;
	for (int r = 0; r < h; r++)
		for (int c = 0; c < w; c++)
			cin >> grid[r][c];
	int l = 0;
	for (int r = 0; r < h; r++)
	{
		int state = 0;
		for (int c = 0; c < w; c++)
		{
			if (!state && grid[r][c] == '#')
			{
				if (c != l) {
					cout << "Impossible\n";
					return 0;
				}
				state++;
			}
			else if (state == 1)
			{
				if (grid[r][c] == '.') state++;
				else l++;
			}
			else if (state == 2 && grid[r][c] == '#') {
				cout << "Impossible\n";
				return 0;
			}
		}
	}
	cout << "Possible\n";
	return 0;
}



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


int main(){
  int a,b;
  cin >> a >> b;
  int ans=0;
  for(int i=a;i<=b;++i){
    int s=i%10;
    int t=(i/10000)%10;
    int u=(i/10)%10;
    int v=(i/1000)%10;
    if(s==t && u==v){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
using namespace std;
#define FOR(S,X) for(int i=0;i<X;i++)
#define FOR2(S,X) for(int j=0;j<X;j++)
int main() {
	string s,t;
	int max = 0;
	cin >> s >> t;
	FOR(0, s.length()-t.length()+1) {
		int sum = 0;
		FOR2(0, t.length()) {
			sum += (s[i + j] == t[j]);
		}
		if (max < sum)max=sum;
	}
	cout << t.length()-max<<endl;
	return 0;

}

Measured memory_bytes: 3620
n = int(input())
l = list(map(int, input().split()))

cnt = 0
for i in range(n):
    a = l[i]
    for j in range(i+1, n):
        b = l[j]
        for k in range(j+1, n):
            c = l[k]
            if a == b or a == c or b == c:
                continue
            m = max(a, b, c)
            if m == a and a < b + c:
                cnt += 1
            elif m == b and b < a + c:
                cnt += 1
            elif m == c and c < a + b:
                cnt += 1
print(cnt)

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

struct edge {
    long long to, cost;
};

vector<edge> G[1000];

int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        long long a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        G[a].push_back(edge{b, c});
    }

    vector<long long> x(n);
    x.at(0) = 0;
    for (int i = 1; i < n; i++) {
        x.at(i) = LLONG_MIN;
    }

    for (int l = 0; l < n; l++){
        for (int i = 0; i < n; i++) {
            if (x.at(i) >= 500'000'000'000'000'000ll || x.at(i) <= -500'000'000'000'000'000ll) continue;
            for (int j = 0; j < (int)G[i].size(); j++) {
                x.at(G[i].at(j).to) = max(x.at(G[i].at(j).to), x.at(i) + G[i].at(j).cost);
            }
        }
    }

    long long maximum = x.at(n - 1);
    for (int l = 0; l < n; l++){
        for (int i = 0; i < n; i++) {
            if (x.at(i) >= 500'000'000'000'000'000ll || x.at(i) <= -500'000'000'000'000'000ll) continue; 
            for (int j = 0; j < (int)G[i].size(); j++) {
                x.at(G[i].at(j).to) = max(x.at(G[i].at(j).to), x.at(i) + G[i].at(j).cost);
            }
        }
    }
    
    if (maximum < x.at(n - 1)) cout << "inf" << endl;
    else cout << x.at(n - 1) << endl;
}   

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
#define all(v) v.begin(),v.end()


ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
ll com(ll n,ll r){
    ll x=1,y=1;
    ll tmp=n;
    while(tmp>=n-r+1){
        x=x*tmp%mod;
        tmp--;
    }
    while(r>0){
        y=y*r%mod;
        r--;
    }
    return x*rep_jijo(y,mod-2)%mod;
}
int main(){
    ll x;
    cin >> x;
    ll p=x/11;
    ll r=x%11;
    p*=2;
    if(1<=r&&r<=6) p++;
    if(7<=r&&r<=10) p+=2;
    cout << p << endl;
    return 0;
}


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

using namespace std;

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

    int count = 0;
    for(int i=0;i<3;i++){
        if(s[i] == t[i]){
            count += 1;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define mp make_pair 
#define f(i,n) for(int i=0;i<n;i++) 
#define F first 
#define S second 
#define pb push_back 

using namespace std;

int cal(int n){
	// cout<<n<<" - > ";
	int cnt = 0;
	while(n!=0){
		int m = log2(n) + 1;
		int temp = 0;
		f(i,m){
			if(n&(1LL<<i))temp++;
		}
		n = n%temp;
		cnt++;
	}
	// cout<<cnt<<"\n";
	return cnt;
}

void test(){
	ll n;
	cin>>n;
	string s;
	cin>>s;
	int cnt = 0;
	f(i,n)if(s[i]=='1')cnt++;
	
	
	
	if(cnt<=1){
		if(cnt==0){
			f(i,n)cout<<"1\n";
		}else if(cnt==1){
			int index = 0;
			f(i,n)if(s[i]=='1')index = i;
			f(i,n){
				if(s[i]=='1')cout<<"0\n";
				else {
					if(index==n-1 or i==n-1)cout<<"2\n";
					else cout<<"1\n";
				}
			}
		}
	}else{
		
		int f1 = cnt+1, f2 = cnt-1;
		
		
		int par1[n],par2[n];
		int cur = 1;
		for(int i=n-1;i>=0;i--){
			par1[i] = cur;
			cur = (cur*2)%f1;
		}
		cur = 1;
		for(int i=n-1;i>=0;i--){
			par2[i] = cur;
			cur = (cur*2)%f2;
		}
		
		
		int ar1[n],ar2[n];
		
		ll cur1 = 0, cur2 = 0;
		for(int i=n-1;i>=0;i--){
			cur1 = cur1 + (par1[i]*(s[i]-'0'));
			cur2 = cur2 + (par2[i]*(s[i]-'0'));
			cur1 = cur1%f1;
			cur2 = cur2%f2;
			ar1[i] = cur1 , ar2[i] = cur2 ;
		}
		ll fin[n];
		f(i,n){
			if(s[i]-'0' == 0){
				fin[i] = (ar1[0] + par1[i])%f1 ;
			}else{
				fin[i] = (ar2[0] - par2[i] + f2)%f2;
			}
		}
		f(i,n)cout<<cal(fin[i])+1<<"\n";
	}
}

int main(){
	int tests=1;
	// cin>>tests;
	while(tests--){
		test();
	}
}


Measured memory_bytes: 8540
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

struct M {
  using T = lint;
  using U = lint;
  static void ap(T& a, const U& g) { a += g; }
  // static void ap(U& f, const U& g) { f += g; }
  static constexpr U id() { return 0; }
};

template<class M> struct ST {
  using T = typename M::T;
  using U = typename M::U;
  int n;
  V<T> t;
  V<U> u;

  ST(int n) : n(n) {
    t.resize(n, 0);
    u.assign(n, M::id());
  }

  void _ap(int i, const U& f) {
    if (i < n) M::ap(u[i], f);
    else M::ap(t[i - n], f);
  }

  T get(int i) {
    T res = t[i];
    for (i += n; i >>= 1;) M::ap(res, u[i]);
    return res;
  }

  void set(int l, int r, const U& f) {
    stack<int> s;
    for (int i = l + n; i >>= 1;) s.push(i);
    for (int i = r + n - 1; i >>= 1;) s.push(i);
    while (!s.empty()) {
      int i = s.top(); s.pop();
      _ap(2 * i, u[i]);
      _ap(2 * i + 1, u[i]);
      u[i] = M::id();
    }
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) _ap(l++, f);
      if (r & 1) _ap(--r, f);
    }
  }
};

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  lint n, m; cin >> n >> m;
  V<lint> a(n); for (int i = 0; i < n; i++) cin >> a[i];
  ST<M> st(m + 1);
  for (int i = 0; i < n - 1; i++) {
    if (a[i] < a[i + 1]) {
      st.set(a[i], a[i + 1], -1);
    } else {
      st.set(0, a[i + 1], -1);
      st.set(a[i], m, -1);
    }
    st.set(a[i + 1] - 1, a[i + 1], (a[i + 1] - a[i] + m) % m);
  }
  V<lint> s(m);
  for (int i = 0; i < n - 1; i++) s[0] += min((a[i + 1] - a[i] + m) % m, a[i + 1]);
  for (int i = 0; i < m - 1; i++) s[i + 1] = s[i] + st.get(i);
  cout << *min_element(s.begin(), s.end()) << '\n';
}

Measured memory_bytes: 3456
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string.h>
#include<string>
#include<set>
#include<limits.h>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<functional>
#include<stack>
#include<deque>
#include<queue>
using namespace std;

signed main() {
	int n; cin >> n;
	set<int>S;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		S.insert(a);
	}
	cout << S.size() << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

const ll INF=10e11+1;

ll f(ll b,ll n)
{
	if(n<b)return n;
	return f(b,n/b)+n%b;
}

ll rmin(ll r,ll b)
{
	if(b>1)
	{
		return min(r,b);
	}
	return r;
}


ll mainmain(ll n,ll s)
{
	if(n<s)return -1;

	ll res=INF;
	if(s==1)
		res=rmin(res,n);
	if(n==s)
		res=rmin(res,n+1);

	//blute
	for(ll i=2;i*i<=n;i++)
	{
		if(f(i,n)==s)
		{
			res=rmin(res,i);
			break;
		}
	}

	//blute2
	{
		for(ll p=1;p*p<=n;p++)
		{
			ll b=(n-s)/p+1;
			if(b!=1&&f(b,n)==s)
			{
				res=rmin(res,b);
			}
		}
		
	}
	return res==INF?-1:res;
}

int main()
{
	ll N,S;
	cin>>N>>S;
	cout<<mainmain(N,S)<<endl;
	return 0;
}

Measured memory_bytes: 384
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,m,k = na()
mod = 998244353


fact = [0] * 220000
invfact = [0] * 220000
 
fact[0] = 1
for i in range(1, 220000):
    fact[i] = fact[i-1] * i % mod
 
invfact[220000 - 1] = pow(fact[220000 - 1], mod-2, mod)
 
for i in range(220000 - 2, -1, -1):
    invfact[i] = invfact[i+1] * (i+1) % mod
 
def nCk(n, k):
    if k < 0 or n < k:return 0
    return fact[n] * invfact[k] * invfact[n-k] % mod
 
ans = 0

for i in range(k+1):
    ans += pow(m-1,n-i-1,mod)*nCk(n-1,i)

print(ans*m%mod)

Measured memory_bytes: 26264
// ARC100
// D - Equal Cut

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 200000;
const ll INF = 1e18;

int N;
int A[MAX_N];
ll s[MAX_N + 1];

int search(int a, int b) {
    int l = a + 1, r = b - 1;
    while (r - l > 1) {
        int m = (l + r) / 2;
        if (s[m] - s[a] <= s[b] - s[m]) {
            l = m;
        } else {
            r = m;
        }
    }
    return l;
}

ll solve() {
    s[0] = 0;
    for (int i = 1; i <= N; i++) {
        s[i] = s[i - 1] + A[i - 1];
    }

    ll ans = INF;
    for (int i = 1; i < N; i++) {
        int pq = search(0, i);
        int rs = search(i, N);
        cerr << i << ", " << pq << ", " << rs << endl;
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k < 2; k++) {
                ll pqrs[4] = {
                    s[pq + j] - s[0],
                    s[i] - s[pq + j],
                    s[rs + k] - s[i],
                    s[N] - s[rs + k],
                };
                sort(pqrs, pqrs + 4);
                ans = min(ans, pqrs[3] - pqrs[0]);
            }
        }
    }
    return ans;
}

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

    cout << solve() << endl;

    return 0;
}


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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

#define mod 1e9+7;
#define inf 1e18+7;

typedef long long ll;

int main() {

    ll t,a,k;
    cin>>t>>a>>k;

    t-=k;
    if(t<0){
        a+=t;
        t=0;
    }
    if(a<0){
        a=0;
    }

    cout<<t<<" "<<a<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
#define ull unsigned long long
#define ld long double
#define uint unsigned int
struct debug {
debug() {cerr << "[LINE:" << __LINE__ << "]";}
~debug() {cerr << "\n";}template<class C> debug& operator<<(C c) {cerr << c;return *this;}
};
#define var(x) " [" << #x << ": " << x << "]"

string s;

void tc() {
    cin >> s;
    int ans=0;
    for(int i=0; i+1<s.size(); ++i) {
        if(s[i]=='R'||s[i+1]=='R')
            if(ans==0)
                ans++;
        if(s[i]==s[i+1]&&s[i+1]=='R')
            ans++;
    }
    cout << ans << "\n";
}

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

    tc();
    return 0;
}

Measured memory_bytes: 3656
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll N,Q; cin >> N >> Q;
    for(int i = 0; i < Q;i++){
        ll v,w; cin >> v >> w;
        if(N == 1){
            cout << min(v,w) << endl;
            continue;
        }
        if(v == w){
            cout << v << endl;
            continue;
        }
        ll add = N - 2;
        while(true){
            ll l = min(v,w), r= max(v,w);
            v = l; w = (r + add)/N;
            if(v == w){
                cout << v << endl;
                break;
            }
            if(v == 0 || w == 0){
                cout << 1 << endl;
                break;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int n,t[100005],m,p[100005],x[100005],ans,tot;
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&t[i]),tot+=t[i];
	scanf("%d",&m);
	for(int i=1;i<=m;i++) scanf("%d %d",&p[i],&x[i]),printf("%d\n",tot-(t[p[i]]-x[i]));
	return 0;
}

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

const int MAX_N = 200005;
const int64_t MOD = 1000000007;
int N;
int64_t vals[MAX_N];

int main() {
  scanf("%d", &N);
  int64_t sum = 0;
  for (int i = 0; i < N; ++i) {
    scanf("%lld", vals + i);
    vals[i] %= MOD;
    sum += vals[i];
  }
  sum %= MOD;
  int64_t ans = 0;
  for (int i = 0; i < N - 1; ++i) {
    sum = (sum + MOD - vals[i]) % MOD;
    ans = ((ans % MOD) + (vals[i] * sum) % MOD) % MOD;
  }
  printf("%lld\n", ans % MOD);
}


Measured memory_bytes: 5380
#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 int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;

void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }



int main()
{
	
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, h;
	cin >> n >>h;
	
	VI a(n), b(n);
	rep(i,n) cin >>a[i] >>b[i];
	sort(b.rbegin(), b.rend());
	
	ll mxa = *max_element(all(a));
	
	int ans =0;
	rep(i,n) if(mxa < b[i]){
		ans++; 
		h -= b[i];
		if(h <=0){
			cout << ans <<"\n";
			return 0;
		}
	}
	
	ans += (h + mxa -1) /mxa;

	cout << ans <<"\n";
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define endl '\n'
#define fastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
using namespace std;
int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b,a % b);
}
int combination(int n, int k){
    int spaceOptimize[k+1];
    memset(spaceOptimize, 0, sizeof(spaceOptimize));
    spaceOptimize[0] = 1;
    for(int i=1;i<=n; i++){
        for(int j= min(i,k);j>0;j--){
            spaceOptimize[j] = spaceOptimize[j] + spaceOptimize[j-1];
        }
    }
    return spaceOptimize[k];
}
int count_permutation(int arr[], int n){
    int a[n];
    for(int i=0;i<n;i++){
        a[i] = i+1;
    }
    int count = 0;
    do {
        count++;
        if (equal(a, a + n, arr)){
            return count;
        }
    } while (next_permutation(a, a + n));
    return 0;
}

signed main(){
#ifndef ONLINE_JUDGE
    //freopen("input.txt","r", stdin);
#endif
    fastIO

    int n, k, q;
    cin >> n >> k >> q;
    int qq = q;
    map<int, int> mp;
    while(q--){
        int temp;
        cin >> temp;
        if(mp.count(temp)){
            mp[temp] = mp[temp] + 1;
        }else {
            mp[temp] = 1;
        }
    }
    if(qq < k){
        for(int i=0;i<n;i++){
            cout << "Yes" << endl;
        }
        return 0;
    }
    for(int i=0;i<n;i++){
        if(mp.count(i+1)){
//            cout << "condition = " << (k - (q - mp[i+1])) << " k = " << k << " q = " << q << endl;
            cout << ((k - (qq - mp[i+1])) > 0 ? "Yes" : "No") << endl;
        }else{
            cout << "No\n";
        }
    }

    return 0;
}


Measured memory_bytes: 4608
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;

lli mod197 = 1000000007LL;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {

	lli A, B;
	cin >> A >> B;

	COUT(max({A + B,A * 2 - 1,B * 2 - 1}));

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 500000
#define INFTY 1000000001

int L[MAX/2+1], R[MAX/2+1], count = 0;

void merge(int *A, int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  //L[0...n1], R[0...n2] を生成
  for (i = 0; i < n1; i++)
    L[i] = A[left + i];
  for (i = 0; i < n2; i++)
    R[i] = A[mid + i];
  L[n1] = INFTY;
  R[n2] = INFTY;
  i = 0;
  j = 0;
  for (k = left; k < right; k++) {
    count++;
    if (L[i] <= R[j]) {
      A[k] = L[i];
      i++;
    } else {
      A[k] = R[j];
      j++;
    }
  }
}

void mergeSort(int *A, int left, int right) {
  if (left+1 < right) {
    int mid = (left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

void print_array(int *A, int N) {
  int i;
  for(i = 0; i < N - 1; i++) {
    printf("%d ", A[i]);
  }
  printf("%d\n", A[i]);
}


int main() {
  int A[MAX], n, i;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &A[i]);
  }
  mergeSort(A, 0, n);
  print_array(A, n);
  printf("%d\n", count);
  return 0;
}



Measured memory_bytes: 5584
#include <iostream>
#include <vector>
using namespace std;
int main(){
	int n, k;
  	cin>>n>>k;
  	vector<int> arr(n);
  	for(int i = 0;i<n;i++){
    	cin>>arr[i];
    }
    vector<bool> dp(k+1);
   	for(int j = 0;j<k+1;j++){
		for(int i = 0;i<n;i++){
          	if(j>=arr[i])
        		dp[j] = dp[j] || !dp[j-arr[i]];
        }
      
    }
	if(dp[k]) cout<<"First"<<endl;
  	else cout<<"Second"<<endl;
}

Measured memory_bytes: 3108
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)


signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int(n);
    pri(n * 800 - 200 * (n / 15));

/*/

//*/ break;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define vi vector<int>
#define pi pair<int, int>
#define all(x) (x).begin(), (c).end()

using namespace std;

const int N = 2e5 + 5;



signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++)
        if (s[i] == '?')
            s[i] = 'D';
    cout << s;
    return 0;
}


Measured memory_bytes: 3740
#include <iostream>

int main(){
    int m,d;
    std::cin >> m >> d;
    
    int sum=0;
    
    for(int i=1;i<=m;++i){
        for(int j=1;j<=d;++j){
            int d1=j%10;
            int d10=j/10;
            if(d1>=2&&d10>=2&&(i==d1*d10)){
                sum++;
            }
        }
    }
    std::cout << sum << std::endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        String last = scanner.next();
        if(last.equals("ARC")){
            System.out.println("ABC");
        }else{
            System.out.println("ARC");
        }
    }
} 

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

int main() {
    int N, x;
    cin >> N >> x;
    vector<int> a(N);

    for(int i = 0; i < N; ++i) {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());

    int ans = 0;
    for(int i = 0; i < N - 1; ++i) {
        if(a.at(i) <= x) {
            x -= a.at(i);
            ++ans;
        } else {
            cout << ans << endl;
            return 0;
        }
    }
    if(a.at(N-1) == x) {
        ++ans;        
    }
    cout << ans << endl;

    
}

Measured memory_bytes: 256
// Frog 2 https://atcoder.jp/contests/dp/tasks/dp_b
#include <bits/stdc++.h>
using namespace std;

const int INF = 1e9 + 5;

int n, k;
vector<int> h;
vector<int> memo;
vector<bool> computed;

// rec(x) is best score to get to position x
int rec(int pos) {
	if(pos == 0) {
		return 0;
	}
	if(computed[pos]) {
		return memo[pos];
	}
	int best = INF;
	for(int jump = 1; jump <= k && pos - jump >= 0; ++jump) {
		best = min(best, rec(pos - jump) + abs(h[pos] - h[pos-jump]));
	}
	computed[pos] = true;
	return memo[pos] = best;
}

int solve1() {
	return rec(n-1);
}

int solve2() {
	vector<int> dp(n, INF);
	dp[0] = 0;
	for(int i = 1; i < n; i++) {
		for(int jump = 1; jump <= k && i - jump >= 0; ++jump) {
			dp[i] = min(dp[i], dp[i-jump] + abs(h[i]-h[i-jump]));
		}
	}
	return dp[n-1];
}

int main() {
	cin >> n >> k;
	h.resize(n);
	memo.resize(n, 0);
	computed.resize(n, false);
	for(int& x : h) {
		cin >> x;
	}
	cout << solve2();
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <algorithm>

using namespace std;
using ll = long long;

int main(){
    int x;
    cin>>x;
    if(x >= 30) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}  


Measured memory_bytes: 3604
from collections import deque
N, M = map(int, input().split())
INF = 1001001001
dist = [[INF for _ in range(3)] for _ in range(N)]

# 有向グラフG
G = [[] for _ in range(N)]
for i in range(M):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    G[u].append(v)

S, T = map(int, input().split())
S -= 1
T -= 1

# BFS
q = deque()
q.append((S, 0))
dist[S][0] = 0

while q:
    k, l = q.popleft()
    for i in G[k]:
        nl = (l + 1) % 3
        if dist[i][nl] == INF:
            dist[i][nl] = dist[k][l] + 1
            q.append((i, nl))

ans = dist[T][0]
if ans == INF:
    ans = -1
else:
    ans //= 3
print(ans)


Measured memory_bytes: 39616
N=int(input())
F=[]
for i in range(N):
    F.append(list(map(int,input().split())))

P=[]

for i in range(N):
    P.append(list(map(int,input().split())))

is_open=[]
def count_score(is_open,N,F,P):
    is_open_copy=list(is_open)
    if len(is_open_copy)==10:
        flag = True
        for t in is_open_copy:
            if t:
                flag=False
                break
        if flag:
            return -10**27
        count_N = [0 for i in range(N)]
        for i in range(N):
            for j in range(10):
                if is_open[j] and F[i][j]==1:
                    count_N[i]+=1
        score = 0
        for i in range(N):
            score+=P[i][count_N[i]]
        return score
    return max(count_score(is_open_copy+[True],N,F,P),count_score(is_open_copy+[False],N,F,P))

print(count_score(is_open,N,F,P))

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

int main(){
    ll N; cin >> N;
    vector<ll> A(N+1),B(N+1);
    rep(i,N+1){
        cin >> A[i];
    }
    rep(i,N){
        cin >> B[i];
    }
    B[N] = 0;
    ll ans = 0;
    rep(i,N+1){
        ans += min(A[i],B[i]);
        if(B[i] > A[i] && i+1 <= N){
            B[i] -= A[i];
            ans += min(A[i+1],B[i]);
            A[i+1] -= B[i];
            if(A[i+1] < 0)A[i+1] = 0;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n; cin >> n;
  vi b(n); rep(i,n){ cin >> b[i]; b[i]--; }
  vi ans(n);
  rep(i,n){
    int res = -1;
    rep(j,b.size()) if(j == b[j]) res = j;
    if(res == -1){
      cout << -1;
      return 0;
    }else{
      ans[i] = res;
      b.erase(b.begin()+res);
    }
  }
  reverse(all(ans));
  rep(i,n) cout << ans[i]+1 << endl;
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3656
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;
//|\_
//g++ -std=c++1z temp.cpp
//./a.out


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    int i,n;
    cin>>n;
    vector<int> v(n),w(n);
    rep(i,n){
        cin>>v[i];
        w[i]=v[i];
    }
    int cen=n/2;
    sort(w.begin(),w.end());
    map<int,int> m;
    rep(i,n){
        if(w[i]<w[cen]||w[i]>w[cen]){
            // cout<<w[i]<<endl;
            m[w[i]]=w[cen];
        }
        if(w[i]>=w[cen]&&w[i-1]<w[cen]){
            cen--;
            // cout<<w[i]<<endl;
            m[w[i]]=w[cen];
        }
    }
    rep(i,n)cout<<m[v[i]]<<endl;
//////////////////////////////////////////////////////
return 0;}





Measured memory_bytes: 12928
#include <iostream>
#include <cstdlib>

using namespace std;

int main(void)
{
    int people_count;
    int train_cost;
    int taxi_cost;

    cin >> people_count >> train_cost >> taxi_cost;

    cout << min(train_cost * people_count, taxi_cost) << endl;   

    return 0;
}

Measured memory_bytes: 256
n = int(input())
from operator import itemgetter
a=[]
for i in range(n):
  b,c=map(str,input().split())
  c=int(c)
  a.append([b,c,i])
a1= sorted(a,key=itemgetter(1),reverse=True)
a2=sorted(a1,key=itemgetter(0))
for i in range(n):
  print((a2[i][2]+1))



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }



signed main(){

    int N, T, A; cin >> N >> T >> A;
    vec H(N); readv(H);

    int ans = -1;
    double m = INF;

    REP(i, N){
        double t = (double)T - 0.006 * (double)H[i];
        if(abs((double)A - t) < m){
            m = abs((double)A - t);
            ans = i;
        }
    }
    cout << ans + 1;
    
    return 0;
}

Measured memory_bytes: 256
import scala.io.Source.stdin
 
object Main {
  def sieve(n:Int) = {
    val primes = Array.tabulate(n+1) { _ % 2 }
    primes(1) = 0
    primes(2) = 1
 
    for( i <- 3 to Math.sqrt(n).toInt by 2 )
    {
      if(primes(i) == 1)
        (i*i to n by i*2).foreach { primes(_) = 0 }
      primes(i) = primes(i) + primes(i-1)
      primes(i+1) = primes(i+1) + primes(i)
    }
 
    for(i<-Math.sqrt(n).toInt+1 to n)
      primes(i) = primes(i)+primes(i-1)
 
    primes
  }
 
  def main(args:Array[String]) = {
    val p = sieve(1000000)
    for(i <- stdin.getLines) 
      println(p(i.toInt))
  }
}

Measured memory_bytes: 63568
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

const int inf = 1e9;
vector< int> v;

ll f(int x) {
    ll rv = 0;
    for (int i = 0; i < (int) v.size(); ++i) {
        rv += abs(v[i] - i - x - 1);
    }
    return rv;
}

int main() {
    int n;
    cin >> n;
    v.resize(n);
    for (int &i : v) cin >> i;
    int x = -inf;
    for (int b = 2 * inf; b >= 1; b /= 2) {
        while (x + b <= inf and f(x + b) > f(x + b + 1)) x += b;
    }
    cout << f(x + 1) << endl;
}

Measured memory_bytes: 1024
import bisect
def bisect_right_reverse(a, x):
    '''
    reverseにソートされたlist aに対してxを挿入できるidxを返す。
    xが存在する場合には一番右側のidx+1となる。
    '''
    if a[0] < x:
        return 0
    if x <= a[-1]:
        return len(a)
    # 二分探索
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] < x:
            ok = mid
        else:
            ng = mid
    return ok
def bisect_left_reverse(a, x):
    '''
    reverseにソートされたlist aに対してxを挿入できるidxを返す。
    xが存在する場合には一番左側のidxとなる。
    '''
    if a[0] <= x:
        return 0
    if x < a[-1]:
        return len(a)
    # 二分探索
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] <= x:
            ok = mid
        else:
            ng = mid
    return ok
def main2():
    n = int(input())
    l=[int(i) for i in input().split()]
    l.sort(reverse = True)
    res = 0
    for i in range(n-1):
        for j in range(i+1, n-1):
            #index がj以降で　k < c を満たすcで一番小さいc'を探す
            #index(c')-j - 1が三角形の条件を満たす
            nibu = l[j+1:]
            k = max(l[i]-l[j],l[j]-l[i])
            left=bisect_left_reverse(nibu,k)
            res += left
    print(res)

if __name__ == '__main__':
    main2()


Measured memory_bytes: 78348
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>

 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back

int N;
char S[304][304];
bool DP[304][304][304];//A,Bを選んだ時のA+C行目とA+B列目が一致しているかどうか
signed main(){
    scanf("%lld",&N);
    int ans=0;
    rep(i,N){
        char c;
        scanf("%c",&c);
        rep(j,N){
            scanf("%c",&S[i][j]);
            rep(k,N+1){
                DP[i][j][k]=true;
            }
        }
    }
    
    rep(a,N){
        rep(b,N){
            bool ifsym=true;
            if(a==0||b==0){
                rep(i,N){
                    rep(j,N-i){
                        if(S[(a+i)%N][(b+i+j)%N]!=S[(a+i+j)%N][(b+i)%N]){
                            DP[a][b][i]=false;
                            ifsym=false;
                        }
                    }
                }
            }else{
                rep(c,N){
                    if(!DP[a-1][b-1][c+1]||S[(a+N-1)%N][(b+c)%N]!=S[(a+c)%N][(b+N-1)%N]){
                        DP[a][b][c]=false;
                        ifsym=false;
                    }
                }
            }
            if(ifsym)ans++;
        }
    }
    printf("%lld\n",ans);
}




Measured memory_bytes: 27264
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstring>
#include <string>
#include <sstream>
#include <bitset>
using namespace std;
#define INF	100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define SORT(x) sort((x).begin(), (x).end())
#define clr(a,b) memset((a),(b),sizeof(a))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

int cell[20][20];
int dh[4] = {1,0,-1,0}, dw[4] = {0,1,0,-1};
int w, h;
int ans;
P s;

void dfs(P p, int cnt){
	if(cnt >= min(ans-1,10)) return;
	cnt++;
	rep(i,4){
		int th = p.fi, tw = p.sec;
		if(th+dh[i] < 0 || th+dh[i] >= h || tw+dw[i] < 0 || tw+dw[i] >= w || cell[th+dh[i]][tw+dw[i]] == 1) continue;
		while(true){
			th += dh[i];
			tw += dw[i];
			if(th < 0 || th >= h || tw < 0 || tw >= w) break;
			if(cell[th][tw] == 3){
				ans = min(ans,cnt);
				break;
			} else if(cell[th][tw] == 1){
				cell[th][tw] = 0;
				dfs(P(th-dh[i],tw-dw[i]),cnt);
				cell[th][tw] = 1;
				break;
			}
		}
	}
	return;
}

int main(){
	while(scanf("%d%d", &w, &h),w||h){
		ans = 11;
		rep(i,h) rep(j,w){
			scanf("%d", &cell[i][j]);
			if(cell[i][j] == 2) s = P(i,j);
		}
		dfs(s, 0);
		if(ans == 11) printf("-1\n");
		else printf("%d\n", ans);
	}
}

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

int main()
{
    
    
    int n,k,s=0;
    scanf("%d %d",&n, &k);
    int ar[n];
    for(int i=0;i<n;i++) scanf("%d",&ar[i]);
    sort(ar,ar+n);
    for(int i=0;i<k;i++) s+=ar[i];
   
    printf("%d\n",s);
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl ;
typedef pair<ll,ll> pl;
 
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define rep(i,N) for(int i=0; i < (N); i++)
#define all(v) (v).begin(),(v).end()

int main(){
	ll X, Y, A, B, C;
	cin >> X >> Y >> A >> B >> C;
	vl p(A), q(B), r(C);
	rep(i,A) cin >> p[i];
	rep(i,B) cin >> q[i];
	rep(i,C) cin >> r[i];
	sort(p.rbegin(), p.rend());
	sort(q.rbegin(), q.rend());

	vl t;
	rep(i,X) t.push_back(p[i]);
	rep(i,Y) t.push_back(q[i]);
	rep(i,C) t.push_back(r[i]);
	sort(t.rbegin(), t.rend());

	ll ans = 0;
	rep(i, X+Y) ans += t[i];
	
	cout << ans << endl;
	
}

Measured memory_bytes: 8560
N = int(input())
S = list(input())
max_count = 0
for i in range(1, N-1):
    ans = []
    cnt = 0
    for j in S[:i]:
        if j not in ans and j in S[i:]:
            ans.append(j)
            cnt += 1
    if cnt > max_count:
        max_count = cnt

print(max_count)

Measured memory_bytes: 3060
#coding:utf-8
import bisect
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = True


def com(a, b, p):
    if a < b or a < 0 or b < 0:
        return 0
    fac = [1]*(a+1)
    inv = [1]*(a+1)
    finv = [1]*(a+1)

    for i in range(2, a+1):
        fac[i] = fac[i-1] * i % p
        inv[i] = p - (inv[p%i] * (p//i) )% p
        finv[i] = finv[i-1] * inv[i] % p

    return fac[a] * (finv[b] * finv[a - b] % p) % p


def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    x, y = LMIIS()

    if (x+y)%3!=0:
      print(0)
      exit()
    n = (x+y)//3
    if 0 > x-n or 0 > y-n:
      print(0)
      exit()

    m = min(x-n,y-n)
    mod = 10**9 + 7

    print(com(n, m, mod))


if __name__ == '__main__':
    main()


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

using namespace std;

int main(){
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout.setf(ios::fixed); cout.precision(17);
    
  int n; cin >> n;
  vector<vector<int>> a(n, vector<int>(3)), dp(n, vector<int>(3,0));
  for(int i = 0; i < n; i++){
    cin >> a[i][0] >> a[i][1] >> a[i][2];
  } 
  dp[0][0] = a[0][0], dp[0][1] = a[0][1], dp[0][2] = a[0][2];
  for(int i = 1; i < n; i++){
    for(int j = 0; j < 3; j++){
      for(int k = 0; k < 3; k++){
        if(j == k) continue;
        dp[i][j] = max(dp[i][j], dp[i-1][k] + a[i][j]);
      }
    }
  } 
  cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) << '\n';

  return 0;
}


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

int main()
{
    double a, b, h, m;
    cin >> a >> b >> h >> m;

    double arfa, beta;

    arfa  = 2.0* M_PI * h /12.0 + 2.0*M_PI/12.0/60.0*m;
    beta = 2.0*M_PI * m /60.0;

    double ans;
    ans = sqrt(a*a + b*b - 2*a*b*cos(arfa - beta));
    printf("%4.22lf\n",ans);

}

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

int main(){
  long long H; cin >> H;
  long long ans = 1;
  while (H >= ans) ans *= 2;
  cout << ans - 1 << endl;
}


Measured memory_bytes: 256
n = gets.to_i
ans = 100000
for i in 0..n/6
  temp = 0
  k = 6*i
  while k != 0
    6.downto(1) do |j|
      temp += k/(6**j)
      k = k%(6**j)
    end
  end
  m = n-6*i
  while m != 0
    5.downto(0) do |j|
      temp += m/(9**j)
      m = m%(9**j)
    end
  end
  ans = [ans,temp].min
end
puts ans

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#define FOR(a,b) for(int (a) =0 ; a < int (b) ;a++)
using namespace std;
int main()
{
  int price[1000],i,n,k,sum=0;
  cin>>n >>k;
  
  FOR(i,n)
    cin>>price[i];
  
  sort(price,price+n);
  
  FOR(i,k)
    sum += price[i];
  
  cout<<sum;
  
  return 0;
  
}


Measured memory_bytes: 3184
#include<iostream>
#include<algorithm>
using namespace std;
int n,x[100010];
long long a,b,ans;
int main(){
	cin>>n>>a>>b;
	for(int i=0;i<n;i++)cin>>x[i];
	ans=0;
	for(int i=0;i<n-1;i++){
		ans+=min((x[i+1]-x[i])*a,b);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 764
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

typedef unsigned long long ULLONG;
typedef long long LLONG;

static const LLONG MOD_NUM = 1000000007;

template <class _T> static _T tp_abs(const _T& a) {
	//	usage:  tp_abs<type name>(a);
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
template <class _T> static _T tp_pow(int base, int exp)
{
	_T ans = 1;

	for (int i = 0; i < exp; i++) {
		ans *= base;
	}
	return ans;
}

static void ABC078C_HSI();

#if 1
int main()
{
	ABC078C_HSI();
	fflush(stdout);
	return 0;
}
#endif

static void ABC078C_HSI()
{
	int N, M;
	get2int(N, M);

	LLONG allAC = 100LL * (LLONG)(N - M) + (1900LL * M);
	LLONG inv = tp_pow<LLONG>(2, M);

	printf("%lld\n", allAC * inv);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
		int a,b;
		int d,r;
		double f;

		a = sc.nextInt();
		b = sc.nextInt();

		d = a/b;
		r =a%b;
		f = (double)a/(double)b;

		System.out.print(d+" "+r+" ");
		System.out.println(String.format("%.5f", f));


		sc.close();
	}

}


Measured memory_bytes: 26456