akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

// find_by_order(k) returns the iterator to the kth largest element (start from 0)
// order_of_key(k) returns the number of elements in the set which are strictly less than the value k

using namespace std;
using namespace __gnu_pbds;

#define ff              first
#define ss              second
#define all(v)          v.begin(), v.end()
#define int             long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mem(dp,x)       memset(dp,x,sizeof dp);
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define rightmostbit(x) __builtin_ffsll(x)
#define mod             1000000007
#define inf             1e18
#define pi              3.141592653589793238
#define mk(a,n)         int n;cin>>n;vi a(n);for(int i=0;i<n;i++) cin>>a[i]
#define w(x)            int x; cin>>x; while(x--)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int dx[] = { -1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int dx2[] = { -1 , -1 , -1, 0 , 0 , 1 , 1 , 1};
int dy2[] = { -1 , 0 , 1 , -1, 1 , -1, 0, 1};

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void g_b()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
#endif
}
// .Always initialize dp array
// 1, 1, 2, 5, 14, 42, 132, 429, 1430, CATALAN NUMBER
int32_t main()
{
	g_b();
	int n, m;
	cin >> n >> m;
	char a[n][m];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> a[i][j];
	int dp[n][m];
	bool f = 0, f1 = 0;
	if (a[n - 1][m - 1] == '#')
	{
		cout << 0;
		return 0;
	}
	memset(dp, 0, sizeof dp);
	for (int i = n - 1; i >= 0; i--)
	{
		for (int j = m - 1; j >= 0; j--)
		{
			if (i == n - 1)
			{
				if (a[i][j] == '#')
				{
					dp[i][j] = 0;
					f = 1;
				}
				else if (!f)
					dp[i][j] = 1;
			}
			else if (j == m - 1)
			{
				if (a[i][j] == '#')
				{
					dp[i][j] = 0;
					f1 = 1;
				}
				else if (!f1)
					dp[i][j] = 1;
			}
			else
			{
				if (a[i][j] == '#')
					dp[i][j] = 0;
				else
					dp[i][j] = (dp[i + 1][j] + dp[i][j + 1]) % mod;
			}
		}
	}

	cout << dp[0][0] % mod;
	return 0;

}

Measured memory_bytes: 12404
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdlib>
using namespace std;


int main() {
	int n;
	bool flag = false;
	cin >> n;
	for (int k = 0; k <= n / 4 + 1;k++) {
		
 		for(int d = 0;d <= n / 7 + 1;d++) {
			
			if (n == 4 * k + 7 * d)flag = true;
		}
	}
	if (flag) cout << "Yes" << endl;
	else cout << "No" << endl;
	return(0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();
	
	int N; cin >> N;
	ll cnt = 1;
	vector<ll>vec(N);
	bool ok = false;
	rep(i, 0, N) {
		cin >> vec[i];
		if (vec[i] == 0)ok = true;
	}
	if (ok) {
		cout << 0 << "\n";
		return 0;
	}
	rep(i, 0, N) {
		long double a = vec[i];
		if (cnt != 0 && a != 0 && cnt > (long double)1e18 / a) {
			cout << -1 << "\n";
			return 0;
		}
		cnt *= a;
	}
	cout << cnt << "\n";

	return 0;
}

Measured memory_bytes: 3972
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define INF 2147483647 

struct Query{
  int c, x, y;
  Query(int c, int x, int y) : c(c), x(x), y(y){}
};

vector<Query> query;

vector<int> value; 
int N; 

int find(int a, int b, int k = 0, int l = 0, int r = N){
  if(b <= l || r <= a)return INF; 
  else if(a <= l && r <= b)return value[k]; 
  else{ 
    int c1 = find(a, b, 2 * k + 1, l, (l + r) / 2); 
    int c2 = find(a, b, 2 * k + 2, (l + r) / 2, r); 
    return min(c1, c2);
  }
}

void update(int i, int x){
  i += N - 1; 
  value[i] = x;
  while(i > 0){ 
    i = (i - 1) / 2; 
    value[i] = min(value[i * 2 + 1], value[i * 2 + 2]); 
  }
}

int main(){
  int n, q;
  cin >> n >> q;
  N = 1;
  while(N < n)N *= 2; 

  value.assign(2 * N - 1, INF);
  for(int i = 0; i < q; ++i){
    int c, x, y;
    cin >> c >> x >> y;
    query.push_back(Query(c, x, y));
  }

  for(auto qry : query){
    if(qry.c == 0)update(qry.x, qry.y);
    else cout << find(qry.x, qry.y + 1) << endl;
  }
}



Measured memory_bytes: 5496
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a[20000], b[20000];
    int i=0;
    char op[20000];
    while(true){
        cin >> a[i] >> op[i] >> b[i];
        if(op[i]=='?') break;
        i++;
    }
    i=0;
    while(true){
        if(op[i]=='?') break;
        if(op[i]=='+') cout << a[i]+b[i]<<endl;
        else if(op[i]=='*') cout << a[i]*b[i] << endl;
        else if (op[i]=='/') cout << a[i]/b[i] << endl;
        else if(op[i]=='-') cout << a[i]-b[i] << endl;
        i++;
    }
    return 0;
}


Measured memory_bytes: 3112
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
//		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//		String W	 = in.readLine();
//		int num = Integer.parseInt(W.split(" ")[0]);

		Scanner sc = new Scanner(System.in);
		int ans = 0;
		for(int i=1;;i++) {
			int x = sc.nextInt();
			if(x == 0) {
				ans = i;
				break;
			}
		}




		System.out.println(ans);

	}

	//	//二分探索
	//k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, long[] orderedArray){
		int lowerBorder = -1;
		int upperBorder = orderedArray.length;
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedArray[mid]<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//二分探索
	//k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList){
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedList.get(mid)<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	public static long gcd(long a, long b) {
        return b == 0 ? a: gcd(b, a % b);
	}



}


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

int main() {
  int W,H,x,y,r;

  std::cin >> W >> H >> x >> y >> r;

  //W > x + r True
  //H > y + r True
  //y - r > 0
  //x - r > 0

  if (W >= x + r && H >= y + r && y - r >= 0 && x - r >= 0) {
    std::cout << "Yes" << '\n';
  } else {
    std::cout << "No" << '\n';
  }
  return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL--------------------------------- 

//--MAIN-----------------------------------
void Main() {
    ll N; cin>>N;
    bool A[N][N]={};
    bool ok=false;
    ll zenkuro=0;
    bool jkuro[N]={};
    rep(i,N){
        rep(j,N){
            char c; cin>>c;
            if(c=='#') A[i][j]=true, ok=true, jkuro[j]=true;
        }
    }
    if(!ok) dame;
    rep(j,N){
        bool kuro=true;
        rep(i,N){
            if(!A[i][j]) kuro=false;
        }
        if(kuro) ++zenkuro;
    }
    ll ans=INF2;
    rep(i,N){
        ll ct=0;
        rep(j,N){
            if(!A[i][j]) ++ct;
        }
        if(jkuro[i]==false) ++ct;
        mini(ans,N-zenkuro+ct);
    }
    cout<< ans <<"\n";
    // どのi列を全黒にするか選ぶ 調べる jのどこかに黒あればどれとっても同じないとこ黒に
    // その後縦全黒だけ動かない


    


}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 512
import Data.Graph
import qualified Data.ByteString.Char8 as B
import Data.List
import Control.Monad
import qualified Data.Foldable as F
import qualified Data.Vector.Unboxed as U
import qualified Data.Set as S

solve n m p e = sum $ map f cmp where
  f xs = S.size $ S.intersection (S.fromList xs) $
    S.fromList [ p U.! (i-1) | i <- xs ]
  cmp = map F.toList . components $ buildG (1, n) e

main = do
  [n, m] <- readInts
  p <- readIntVec
  e <- replicateM m $ (\[a,b]->(a,b)) <$> readInts
  print $ solve n m p e

readInts
  = unfoldr (B.readInt . B.dropWhile (== ' ')) <$> B.getLine
readIntVec
  = U.unfoldr (B.readInt . B.dropWhile (== ' ')) <$> B.getLine

Measured memory_bytes: 46332
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define md 1000000007
using namespace std;
bool isPrime(ll n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;

    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;

    return true;
}

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n, i = 0, j= 0, k = 0, l = 0, m = 0, a = 0, b = 0, sum = 0, x = 0, y = 0, z = 0, c, p;
    cin >> n;
    while(1){
        if(isPrime(n) == true){
            cout << n;
            return 0;
        }
        n++;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000000000000;

struct Edge{
    int to;
    int cost;

    Edge(int t, int c){
        to = t;
        cost = c;
    }
};

int main(){
    int n;
    cin >> n;
    vector<vector<Edge>> graph(n);

    for (auto i = 0; i < n-1; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        a -= 1;
        b -= 1;
        Edge e1(a, c);
        Edge e2(b, c);
        graph[a].push_back(e2);
        graph[b].push_back(e1);
    }

    int q, k;
    cin >> q >> k;
    k -= 1;

    // dijkstra
    priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> qu;
    vector<long long> d(n, INF);
    d[k] = 0;
    qu.push(pair<long long, int>(0, k));

    while(!qu.empty()){
        auto p = qu.top();
        qu.pop();
        int v = p.second;
        if(d[v] < p.first){
            continue;
        }

        for (auto i = 0; i < graph[v].size(); i++)
        {
            Edge e = graph[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                qu.push(pair<long long, int>(d[e.to], e.to));
            }
        }
    }
    vector<int> x(q);
    vector<int> y(q);

    for (auto i = 0; i < q; i++)
    {
        int x_i, y_i;
        cin >> x_i >> y_i;
        x[i] = x_i - 1;
        y[i] = y_i - 1;        
    }

    for (auto i = 0; i < q; i++)
    {
        cout << d[x[i]] + d[y[i]] << endl;
    }
    
}

Measured memory_bytes: 10736
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int sum1 = 0;
    int sum2 = 0;
    for (int i = 0; i < 4; i++) {
      int score = sc.nextInt();
      sum1 += score;
    }
    for (int i = 0; i < 4; i++) {
      int score = sc.nextInt();
      sum2 += score;
    }
    if (sum1 >= sum2) {
      System.out.println(sum1);
    } else {
      System.out.println(sum2);
    }
  }
}


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

int main() {
  int x1,y1,x2,y2;cin>>x1>>y1>>x2>>y2;
  int x3=x2+y1-y2,y3=y2+x2-x1;
  int x4=x1+y1-y2,y4=y1+x2-x1;
  cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	int n;
	cin >> n;
	
	vector<int> a(n),b(n),c(n);
	for(int i=0; i<n; i++) cin >> a[i];
	for(int i=0; i<n; i++) cin >> b[i];
	for(int i=0; i<n; i++) cin >> c[i];
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());
	
	vector<long long int> bnum(n);
	for(int i=0; i<n; i++){
		vector<int>::iterator it;
		it = lower_bound(c.begin(), c.end(), b[i]+1);
		bnum[i] = c.end() -it;
	}
	for(int i=n-2; i>=0; i--){
		bnum[i] += bnum[i+1];
	}
	
	long long int ans=0;
	for(int i=0; i<n; i++){
		vector<int>::iterator it;
		it = lower_bound(b.begin(), b.end(), a[i]+1);
		if(it == b.end()) continue;
		ans += bnum[it-b.begin()];
	}
	cout << ans << endl;
	return 0;
}

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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(x)	cout << #x << " " << x << endl;

typedef long long int ll;

int main() {

	IOS

	ll d, t, s;
	cin >> d >> t >> s;
	cout << (t*s >= d ? "Yes":"No");

	return 0;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

int main()
{
    ll n, m;
    cin >> n >> m;

    ll ans = 0;
    for (ll i = 1; i * i <= m; i ++)
    if (m % i == 0)
    {
        if (m / i >= n) 
            ans = max(ans, i);
        if (i >= n) 
            ans = max(ans, m / i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import Foundation

extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
}

func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}


/************** main *****************/

let nm = readIntSplit(by: " ")
let (n, m) = (nm[0], nm[1])
var (t, b) = (1, n)
for i in 1...m {
    let lr = readIntSplit(by: " ")
    let (l, r) = (lr[0], lr[1])
    if t < l{
        t = l
    }
    if b > r {
        b = r
    }
}
let ans = b - t + 1
if ans < 0 {
    print(0)
} else {
    print(ans)
}


Measured memory_bytes: 6640
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repn(i,a,b) for (int i = a; i >=b ;i--)
#define MOD 1000000007


int main(){
ios::sync_with_stdio(0);
cin.tie(0);
    int n;cin>>n;
    if(n==1)cout<<"0\n";
    else cout<<"1\n";
 
return 0;
}

Measured memory_bytes: 3608
#include<stdio.h>
#include<string.h>
int main(void)
{
	int n,l,j,i;
	char s[100][101];
	char t[101];
	scanf("%d %d",&n,&l);
	for(i=0;i<n;i++){
    	scanf("%s",&s[i]);
	}
	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			if(strcmp(s[i],s[j])>0){
				strcpy(t,s[i]);
				strcpy(s[i],s[j]);
				strcpy(s[j],t);
			}
		}
	}
	for(i=0;i<n;i++){
		printf("%s",s[i]);
	}
	printf("\n");
	return 0;
}
	

Measured memory_bytes: 128
n=int(input())
s=""
while(n):
    a=n%26
    c=""
    if(a==0):
        c="z"
    else:
        c=chr(96+a)
    s+=c
    n=n//26
    if(c=="z"):
        n-=1
s=s[::-1]
print(s)


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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef long long int ll;
typedef vector< pair<int, int> > vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long int> vll;
typedef pair<int, int> pii;

const ll INF = 1e18;
const int inf = 1e9;
const int MOD = 1e9 + 7;
const int nax = 1000000 + 10;

int main()
{
    ios::sync_with_stdio(0);
    ll n, a, b;
    cin >> n >> a >> b;
     if(b < a)
    {
        cout << 0;
        return 0;
    }
    if(n == 1)
    {
        if(a == b)
            cout << 1;
        else
            cout << 0;
            return 0;
    }
    if(n == 2)
    {
        cout << a + b;
        return 0;
    }
    ll l = (n - 1) * a + b;
    ll r = (n - 1) * b + a;
    cout << r - l + 1;
    return 0;
}


Measured memory_bytes: 256
import Control.Applicative
import Data.List
import Data.Char

strip :: String -> String
strip = reverse . dropWhile isSpace . reverse . dropWhile isSpace

calc :: Int -> Int
calc n = length [True | a <- [0..9],
                        b <- [0..9],
                        c <- [0..9],
                        d <- [0..9],
                        a + b + c + d == n]

main :: IO ()
main = do
  s <- getContents
  let xs = map read $ lines $ strip s :: [Int]
  mapM_ putStrLn $ map (show . calc) xs

Measured memory_bytes: 4112
package main

import (
	"fmt"
)

func main() {
	var N, Y int
	fmt.Scan(&N)
	fmt.Scan(&Y)

	if Y > N * 10000 {
		fmt.Println(-1, -1, -1)
		return
	}

	for i := max(N, Y/10000); i >= 0; i-- {
		for j := N - i; j >= 0; j-- {
			k := N - i - j
			if isValidOtoshidama(Y, i, j, k) {
				fmt.Println(i, j, k)
				return
			}
		}
	}

	fmt.Println(-1, -1, -1)
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func isValidOtoshidama(Y int, a, b, c int) bool {
	return 10000 * a + 5000 * b + 1000 * c == Y
}

Measured memory_bytes: 512
/*
    Written by Nitrogens
    Desire for getting accepted!!
*/
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <bitset>
#include <stack>
#include <set>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 1e2+5;
const int Mod = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e = exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl

ll w[maxn], v[maxn];
ll dp[2][100005];

int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);

    int n, W;
    scanf("%d%d", &n, &W);

    ll answer = 0;
    memset(dp, 0x3f, sizeof(dp));
    dp[0][0] = 0;
    for(int i = 1; i <= n; i++) scanf("%lld%lld", &w[i], &v[i]);
    for(int i = 1; i <= n; i++)
    {
        for(int j = 0; j <= 100000; j++)
        {
            if(j >= v[i])   dp[1][j] = min(dp[0][j], dp[0][j - v[i]] + w[i]);
            else            dp[1][j] = dp[0][j];
            if(dp[1][j] <= W)   answer = max(answer, 1LL * j);
        }
        memcpy(dp[0], dp[1], sizeof(dp[1]));
        memset(dp[1], 0, sizeof(dp[1]));
    }
    printf("%lld\n", answer);


    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


Measured memory_bytes: 1792
package main

import "fmt"

func main() {
	var n int64
	fmt.Scan(&n)

	ans := int64(1)
	mod := int64(1e9) + int64(7)

	for i := int64(1); i <= n; i++ {
		ans *= i
		ans %= mod
	}
	fmt.Println(ans)
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int LL;
typedef LL ll;
typedef long double ld;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;
 
#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))
#define RET(x) { cout << x; exit(0); } 
const ll M=2e5+5,LG=19,SM=600+5,inf=1e18+1;
ll mod=1e9+7;

ll n;
str z[2]={"YES","NO"};
vll g[M];
ll a[M];

ll dfs(ll x,ll p)
{
    //ER(x);
    if (SZ(g[x])==1) return a[x];
    vll s;
    ll su=0;
    for (ll y:g[x])
    {
        if (y==p) continue;
        s.PB(dfs(y,x));
        su+=s.back();
    }
    if (a[x]>su) RET(z[1]);
    ll tp=su-a[x];
    ll fn=su-2*tp;
    sort(s.begin(),s.end());
    ll mx=s.back();
    if (mx<=su-mx) tp-=su/2;
    else tp-=su-mx;
    if (tp>0) RET(z[1]);
    //ER(x);ER(fn);
    return fn;
}

int main()
{
	ios::sync_with_stdio(0);
    cin >> n;
    For(i,0,n)
    {
        cin >> a[i];    
    }
    For(i,1,n)
    {
        ll u,v;
        cin >> u >> v;
        u--;v--;
        g[u].PB(v);g[v].PB(u);
    }
    if (n==2) RET(z[a[0]!=a[1]]);
    ll root;
    For(i,0,n)
    {
        if (SZ(g[i])>1) { root=i; break;}
    }
    root=dfs(root,root);
    RET(z[root!=0]);
}    

Measured memory_bytes: 19584
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod = 1000000007;
const int x[4] = { 0,0,-1,1 }, y[4] = { -1,1,0,0 };

int H, W;
char c[500][500], r[500][500], b[500][500];

int main() {
	cin >> H >> W;
	for (int i = 0; i != H; ++i)
		for (int j = 0; j != W; ++j) {
			cin >> c[i][j];
			r[i][j] = b[i][j] = c[i][j];
		}
	for (int i = 0; i != H; ++i) {
		r[i][0] = b[i][W - 1] = '#';
	}
	for (int i = 0; i < H; i += 2)
		for (int j = 1; j != W - 1; ++j)
			r[i][j] = '#';
	for (int i = 1; i < H; i += 2)
		for (int j = 1; j != W - 1; ++j)
			b[i][j] = '#';
	for (int i = 0; i != H; ++i) {
		for (int j = 0; j != W; ++j)
			cout << r[i][j];
		cout << endl;
	}
	cout << endl;
	for (int i = 0; i != H; ++i) {
		for (int j = 0; j != W; ++j)
			cout << b[i][j];
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1536
#include <stdio.h>

int main(void)
{
	char s[100];
	int count=0;
	int char_num=0;
	
	scanf("%s",s);
	
	for(int i=0;s[i]!='\0';i++){
		for(int j=0;s[j]!='\0';j++){
			if(s[i]==s[j]){
				count++;
			}
		}
		char_num++;
	}
	
	if(count==char_num){
		printf("yes\n");
	}else{
		printf("no\n");
	}
	
	return 0;
}
	

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

#define f first
#define s second
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int N = (int)2e5 + 123, inf = 1e9, mod = 1e9 + 7;
const ll INF = 1e18;

int main()
{
	int n;
	cin >> n;
	cout << (n - 2) * 180;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static final int[] HAIKU = { 5, 7, 5, 7, 7 };
	int n;
	int[] w;

	void run() {
		Scanner scan = new Scanner(System.in);
		while (true) {
			n = scan.nextInt();
			if (n == 0)
				break;
			w = new int[n];
			for (int i = 0; i < n; i++)
				w[i] = scan.next().length();
			solve();
		}
	}

	void solve() {
		int index = 0;
		while (index < n) {
			int sum = 0;
			int count = 0;
			int i = index;
			while (i < n) {
				sum += w[i++];
//				System.out.println(sum + " " + i + " " + count);
				if (sum == HAIKU[count]) {
					sum = 0;
					count++;
				} else if (sum > HAIKU[count]) {
					index++;
					break;
				}
				if (count == HAIKU.length) {
					System.out.println(index + 1);
					return;
				}
			}
		}
	}

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

Measured memory_bytes: 31284
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };



int main() {
	int N,X,m[105];
	int sum = 0;
	scanf("%d%d", &N,&X);
	for (int i = 0; i < N; i++) {
		scanf("%d", &m[i]);
		sum += m[i];
	}

	int minM = c_INF;

	for (int i = 0; i < N; i++) {
		minM = min(minM, m[i]);
	}

	printf("%d", N + (X - sum) / minM);



}





/*         提出前の確認事項

・デバッグ用の関数は＜＜コメント化＞＞しているか？
・すべての＜＜入力例＞＞は試したか？
・＜＜限界値分析＞＞はしたか？
・＜＜出力の改行＞＞の有無は確認したか？
・文字列の＜＜スペル＞＞は確認したか？
　　　　　　　　↓
	 ＜＜提出先＞＞に注意して提出！！
*/

Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


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

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll n, m;
    cin>>n>>m;
    ll x = 0, y = INF;
    for(ll i=0;i<m;++i){
        ll l, r;
        cin>>l>>r;
        x = max(x, l);
        y = min(y, r);
    }
    ll ans = max((ll)0, y-x+1);
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;

int main(){
    ll n, m;
    cin >> n >> m;

    ll ans = 1;
    for(ll d = 1; d * d <= m; ++d){
        if(m % d != 0){ continue; }

        ll d2 = m / d;
        if(d2 >= n){
            ans = max(ans, d);
        }
        if(d >= n){
            ans = max(ans, d2);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 760
#include <iostream>

using namespace std;

int selectionSort(int a[], int n) {
    int sw = 0;
    for (int i = 0; i < n; ++i) {
        int minj = i;
        for (int j = i; j < n; ++j) {
            if (a[j] < a[minj]) minj = j;
        }
        if (i != minj) {
            swap(a[i], a[minj]);
            sw++;
        }
    }
    return sw;
}

void trace(int a[], int n) {
    for (int i = 0; i < n; ++i) {
        if (i > 0) printf(" ");
        printf("%d", a[i]);
    }
    printf("\n");
}

int main() {
    int n;
    int a[100];
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    int sw = selectionSort(a, n);
    trace(a, n);
    cout << sw << endl;
    return 0;
}

Measured memory_bytes: 3256
fun main(args: Array<String>) {
  readLine()!!
  val t = readLine()!!.split(" ").map { it.toInt() }
  val m = readLine()!!.toInt()
  (1..m).forEach {
    val (pi, xi) = readLine()!!.split(" ").map { it.toInt() }
    println(cal(t, pi, xi))
  }
}

fun cal(t: List<Int>, pi: Int, xi: Int) =
        t.sum() - t[pi - 1] + xi

Measured memory_bytes: 37672
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, string> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	ll n,m,i,j,x[123456],y[123456],xsum=0ll,ysum=0ll,t;
	cin >> n >> m;
	for(i=0ll; i<n; ++i){
		cin >> x[i];
	}
	for(j=0ll; j<m; ++j){
		cin >> y[j];
	}
	for(i=1ll; i<n; ++i){
		t = x[i] - x[i-1];
		mul_mod(t,i);
		mul_mod(t,n-i);
		add_mod(xsum,t);
	}
	for(j=1ll; j<m; ++j){
		t = y[j] - y[j-1];
		mul_mod(t,j);
		mul_mod(t,m-j);
		add_mod(ysum,t);
	}
	cout << ((xsum*ysum)%MOD) << endl;
	return 0;
}


Measured memory_bytes: 1920
#include<iostream>
using namespace std;
int main(){
	int x1,y1,x2,y2,ax,ay;
	cin>>x1>>y1>>x2>>y2;
	ax=x2-x1;
	ay=y2-y1;
	cout<<x2-ay<<' '<<y2+ax<<' '<<x1-ay<<' '<<y1+ax;
	return 0;
}

Measured memory_bytes: 256
N=int(input())
L=list(map(int,input().split()))

l=[]
for i in range(N-2):
    for j in range(i+1,N-1):
        if L[i]!=L[j]:
            for k in range(j+1,N):
                if (L[i]!=L[k])&(L[j]!=L[k]):
                    l.append([i+1,j+1,k+1])
                else:
                    continue
        else:
            continue

answer=[]
for m in range(len(l)):
    L_new=[]
    for n in l[m]:
        L_new.append(L[n-1])
    if max(L_new)<(sum(L_new)-max(L_new)):
        answer.append(l[m])
    else:
        continue

print(len(answer))

Measured memory_bytes: 26704
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
  int i,j;
  int w,h;
  while(cin>>w>>h,w||h){
    int a[32][32];
    memset(a,-1,sizeof(a));
    for(i=1;i<h+1;i++)
      for(j=1;j<w+1;j++)
	cin>>a[j][i];
    int b[4];
    for(i=0;i<4;i++)
      cin>>b[i];
    int c[32][32][4];
    memset(c,-1,sizeof(c));
    priority_queue<pair<pair<int,int>,pair<int,int> >,vector<pair<pair<int,int>,pair<int,int> > >,greater<pair<pair<int,int>,pair<int,int> > > > d;
    d.push(make_pair(make_pair(0,0),make_pair(1,1)));
    while(d.empty()==0){
      int x,y,z,s;
      x=d.top().second.first;
      y=d.top().second.second;
      z=d.top().first.first;
      s=d.top().first.second;
      if(x==w&&y==h)
	break;
      d.pop();
      if(a[x][y]!=-1&&c[x][y][s]){
	c[x][y][s]=0;
	if(0){
	}else if(s==0){
	  d.push(make_pair(make_pair(z+(a[x][y]==0?0:b[0]),0),make_pair(x+1,y)));
	  d.push(make_pair(make_pair(z+(a[x][y]==1?0:b[1]),1),make_pair(x,y+1)));
	  d.push(make_pair(make_pair(z+(a[x][y]==2?0:b[2]),2),make_pair(x-1,y)));
	  d.push(make_pair(make_pair(z+(a[x][y]==3?0:b[3]),3),make_pair(x,y-1)));
	}else if(s==1){
	  d.push(make_pair(make_pair(z+(a[x][y]==0?0:b[0]),1),make_pair(x,y+1)));
	  d.push(make_pair(make_pair(z+(a[x][y]==1?0:b[1]),2),make_pair(x-1,y)));
	  d.push(make_pair(make_pair(z+(a[x][y]==2?0:b[2]),3),make_pair(x,y-1)));
	  d.push(make_pair(make_pair(z+(a[x][y]==3?0:b[3]),0),make_pair(x+1,y)));
	}else if(s==2){
	  d.push(make_pair(make_pair(z+(a[x][y]==0?0:b[0]),2),make_pair(x-1,y)));
	  d.push(make_pair(make_pair(z+(a[x][y]==1?0:b[1]),3),make_pair(x,y-1)));
	  d.push(make_pair(make_pair(z+(a[x][y]==2?0:b[2]),0),make_pair(x+1,y)));
	  d.push(make_pair(make_pair(z+(a[x][y]==3?0:b[3]),1),make_pair(x,y+1)));
	}else if(s==3){
	  d.push(make_pair(make_pair(z+(a[x][y]==0?0:b[0]),3),make_pair(x,y-1)));
	  d.push(make_pair(make_pair(z+(a[x][y]==1?0:b[1]),0),make_pair(x+1,y)));
	  d.push(make_pair(make_pair(z+(a[x][y]==2?0:b[2]),1),make_pair(x,y+1)));
	  d.push(make_pair(make_pair(z+(a[x][y]==3?0:b[3]),2),make_pair(x-1,y)));
	}
      }
    }
    cout<<d.top().first.first<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {
	    String[] inputs = Io.read();

	    String[] metas = inputs[0].split(" ");
	    int m = Integer.parseInt(metas[1]);

	    long[][] values = parse(inputs);

        long ans = Calc.calc(m, values);

        Io.write(ans);
    }

    private static long[][] parse(String[] inputs) {
        long[][] parsed = new long[inputs.length - 1][3];

        for (int i = 1; i < inputs.length; i++) {
            String[] line = inputs[i].split(" ");
            parsed[i - 1][0] = Long.parseLong(line[0]);
            parsed[i - 1][1] = Long.parseLong(line[1]);
            parsed[i - 1][2] = Long.parseLong(line[2]);
        }
        return parsed;
    }
}

class Calc {

    public static long calc(int m, long[][] values) {
        int ratio[][] = {
                {1, 1, 1},
                {1, 1, -1},
                {1, -1, 1},
                {1, -1, -1},
                {-1, 1, 1},
                {-1, 1, -1},
                {-1, -1, 1},
                {-1, -1, -1},
        };
        long maxValue = 0;

        for (int[] r : ratio) {
            long candidate = Arrays.stream(values).mapToLong(x -> {
                long v = x[0] * r[0];
                v += x[1] * r[1];
                v += x[2] * r[2];
                return v;
            }).sorted().skip(values.length - m).sum();

            if (maxValue <= candidate) maxValue = candidate;
        }

        return maxValue;
    }
}

class Io {

    /**
     * 標準入力から1行ずつ受け取る
     * @return
     * @throws IOException
     */
    public static String[] read() throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        List<String> inputs = new ArrayList<>();
        String line;
        while ((line = br.readLine()) != null) {
            if (line.equals(""))
                break;

            inputs.add(line);
        }
        br.close();
        return inputs.toArray(new String[0]);
    }

    /**
     * 標準出力
     * @param answer
     */
    public static void write(long answer)
    {
        System.out.println(answer);
    }
}

Measured memory_bytes: 27588
#include <cstdio>
int main(){
	int l,r,x,y;
	int sum=0;
	scanf("%d%d%d%d",&r,&l,&x,&y);
	if(r>=l)sum=(r-l)*y+l*x;
	else sum=r*x;
	printf("%d\n",sum);
}


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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  if (abs(A-B)%2 == 0)
    cout << "Alice" << endl;
  else
    cout << "Borys" << endl;
  return 0;
}
  

Measured memory_bytes: 256
i;main(void){
	char str[20];
	int r = 999;
	gets(str);
	for (; i < 9; i++) {
		char s[5] = {str[i], str[i + 1], str[i + 2]};
		// char s[5] = {};
		// sprintf(s, "%c%c%c", str[i], str[i + 1], str[i + 2]);
		if (abs(753 - atoi(s)) < r) {
			r = abs(753 - atoi(s));
		}
	}
	printf("%d\n", r);
}


Measured memory_bytes: 128
#include <bits/stdc++.h> 
using namespace std ;
int main () {
	int n , m , x ;
	cin >> n >> m >> x ;
	vector < vector <int > > v (n , vector <int> (m)) ;
	vector <int> cost (n) ;
	for (int i = 0 ; i < n ; ++i) {
		cin >> cost[i] ;
		for (int j = 0 ; j < m ; ++j) {
			cin >> v[i][j] ;
		}
	}
	vector <int> sum_till(m) ;
	long long money = 0  ;
	long long ans = LLONG_MAX ;
	for (int mask = 1 ; mask < (1 << n) ; ++mask) {
		money = 0 ;
		for (int i = 0 ; i < m ; ++i) {
			sum_till[i] = 0 ;
		}
		for (int i = 0 ; i < n ; ++i) {
			if ((1 << i) & mask) {
				money += cost[i] ;
				for (int j = 0 ; j < m ; ++j) {
					sum_till[j] += v[i][j] ;
				}
			}
		}
		int cnt = 0 ;
		for (int i = 0 ; i < m ; ++i) {
			if (sum_till[i] >= x) {
				++cnt ;
			}
		}
		if (cnt == m) {
			ans = min(money , ans) ;
		}
	}
	if (ans == LLONG_MAX) {
		cout << -1 ;
	} else {
		cout << ans ;
	}
	return 0 ;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
using namespace std;
unordered_map<string,long>m;
long dp(int a[],int b[],int c[],int n,int turn)
{
		if(n<0)
			return 0;
		  string str=to_string(n)+to_string(turn);
		  if(m.find(str)==m.end())
		  {   long maxx=INT_MIN;
		  	if(turn==-1 || turn==0)
		  	{
              maxx=max(maxx,max(b[n]+dp(a,b,c,n-1,1),c[n]+dp(a,b,c,n-1,2)));
		  	}
		  	if(turn==-1 || turn==1)
		  	{
		  		 maxx=max(maxx,max(a[n]+dp(a,b,c,n-1,0),c[n]+dp(a,b,c,n-1,2)));
		  	}
		  	if(turn==-1 || turn==2)
		  	{
		  		 maxx=max(maxx,max(a[n]+dp(a,b,c,n-1,0),b[n]+dp(a,b,c,n-1,1)));
		  	}
		  	m[str]=maxx;
		  }
		  return m[str];
}

int main()
{
	int n,k,x;
	cin>>n;
	int a[n],b[n],c[n];
	for(int i=0;i<n;i++)
		{  cin>>a[i]>>b[i]>>c[i];
		}
		
			cout<<dp(a,b,c,n-1,-1);
	return 0;
}

Measured memory_bytes: 49268
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
double dp[3000];
int main(){
	int n;cin>>n;
	dp[0]=1;
	double p;
	for (int i = 0; i < n; ++i)
	{
		cin>>p;
		for (int j = i+1; j >0; j--)
		{
			dp[j]=dp[j-1]*p+dp[j]*(1-p);
		}
		dp[0]*=(1-p);
	}
	p=0;
	for (int i = n/2+1; i <=n; ++i)
	{
		p+=dp[i];
	}
	cout<<fixed<<setprecision(10)<<p;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define debug_array(a,n) for (ll bccc=(0); bccc<(n); bccc++) cout<<a[bccc]<<" "<<"\n"
#define debug_vector(a) for(ll bccc=(0); bccc<(a.size());bccc++) cout<<a[bccc]<<" "<<"\n"
#define F           first
#define S           second
#define debug_set(s) for(auto p:s) cout<<p<<" "
#define debug_map(m) for(auto p:m) cout<<p.F<<" "<<p.S<<"\n"
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

/* ll t = 0;
ordered_multiset me;
...
me.insert({x, t++});
me.erase(me.lower_bound({x, 0}));
cout << me.order_of_key({x, 0}) << "\n";

///////////   t is insertion time
*/
//#pragma GCC optimize("Ofast")  // works very well
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long double lld;
lld pi=3.14159265358;
ll powr(ll a,ll b)
{
    ll c=1;
    ll kjk;
    for(kjk=0;kjk<b;kjk++)
        c*=a;
    return c;
}
ll hell=1000000007;
//ll hell=998244353   ;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
//freopen("input.txt", "r", stdin);
//freopen("output3.txt", "w", stdout);
// to generate random number , use rng() ... eg cout<<rng();
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    ll n,m,x,i,j;
    cin>>n>>m>>x;
    ll cost[n];
    ll a[n][m];
    for(i=0;i<n;i++)
    {
        cin>>cost[i];
        for(j=0;j<m;j++)
            cin>>a[i][j];
    }
    ll mincost=hell*hell;
    for(ll mask=0;mask<powr(2,n);mask++)
    {   ll gett[m]={0};
        ll costt=0;
        for(j=0;j<n;j++)
        {
            if(mask&powr(2,j))
            {   costt+=cost[j];
                // buy jth
                for(int k=0;k<m;k++)
                    gett[k]+=a[j][k];
            }
        }
        bool f=1;
        for(i=0;i<m;i++)
            if(gett[i]<x)
                f=0;
        if(f)
            mincost=min(mincost,costt);
    }
    if(mincost == hell*hell)
        cout<<"-1";
    else
        cout<<mincost;
    return 0;
}


Measured memory_bytes: 3660
#include <stdio.h>
#include <string.h>

int main()
{
    char String[11]="",new_String[12]="";
    int fal=0;
    scanf("%s %s",String,new_String);

    for(int i=0;i<strlen(String);i++){
	if(String[i]!=new_String[i]){
	    fal=1;
	    break;
	}
    }

    if(fal==0)
	printf("Yes\n");
    else
	printf("No\n");

    return 0;
}



Measured memory_bytes: 1664
def orderN(N,L,ices):
    upPeak = L - ices[0]
    downPeak = L - ices[0]
    peaks = []
    for i in xrange(len(ices)):
        if i < N-1:
            if ices[i] < ices[i+1]:
                peaks.append(downPeak)
                downPeak = L - ices[i+1]
                upPeak += L - ices[i+1]
            else:
                peaks.append(upPeak)
                upPeak = L - ices[i+1]
                downPeak += L - ices[i+1]
        else:
            peaks.append(upPeak)
            peaks.append(downPeak)
    print(max(peaks))

N,L = map(int,raw_input().strip().split())
ices = [int(raw_input().strip()) for _ in xrange(N)]

orderN(N,L,ices)

Measured memory_bytes: 12604
#C
def gcd(x,y):
    #x>y
    if y==0:
        return x
    else:
        return gcd(y,x%y)
a,b,c,d=map(int,input().split())
a-=1
def f(i):
    ai=a%i
    bi=b%i
    if ai==bi:
        return (b-a)//i
    elif ai>bi:
        return (b-a)//i+1
    else:
        return (b-a)//i
C=c//gcd(c,d)
D=d//gcd(c,d)
H=C*D*gcd(c,d)
print(b-a-f(c)-f(d)+f(H))

Measured memory_bytes: 38384
#160-3 
k, n = map(int,input().split())
ans = 1e18
arr = list(map(int,input().split()))
for i in range(n): 
    dist1=(arr[i-1]-arr[i])%k
    dist2=(arr[i]-arr[(i+1)%n])%k
    ans=min(ans,dist1,dist2)
print(ans)

Measured memory_bytes: 26420
import sys
input = sys.stdin.readline

N=int(input())
p = list(map(float, input().split()))

dp = [[0]*(N+1) for _ in range(N+1)]
dp[0][0]=1
for i in range(N):
    for j in range(N):
        dp[i+1][j+1] += dp[i][j]*p[i]
        dp[i+1][j] += dp[i][j]*(1-p[i])

print(sum(dp[N][N//2+1:]))

Measured memory_bytes: 252168
#include <stdio.h>
#define MAX 100

int main() {
  int AM[MAX][MAX];
  int n, k, u, v;
  int i, j;

  scanf("%d", &n);

  //Initialize Adjacency Matrix
  for ( i = 0; i < n; i++ )
    for ( j = 0; j < n; j++ )
      AM[i][j] = 0;

  for ( i = 0; i < n; i++ ) {
    scanf("%d%d", &u, &k);
    for ( j = 0; j < k; j++ ) {
      scanf("%d", &v);
      AM[u - 1][v - 1] = 1;
    }
  }

  for ( i = 0; i < n; i++ ) {
    for ( j = 0; j < n; j++ ) {
      printf("%d", AM[i][j]);
      if ( j < n - 1 ) printf(" ");
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _repi(i, a, b) for (int i = int(a), i##_hoge = int(b); i < i##_hoge; ++i)
#define _rep(i, n) _repi(i, 0, n)
#define REP(...) _overload3(__VA_ARGS__, _repi, _rep, )(__VA_ARGS__)
#define FOREACH(i, x) for (auto &i : x)
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define print(x) cout << x << endl;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 9;
using ll = long long;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vbool = vector<bool>;
using vvbool = vector<vector<bool>>;
template <class T> using vv = vector<vector<T>>;
// clang-format off
template <class T> bool chmax(T &a, const T &b) {if (a < b) {a = b;return 1;}return 0;}
template <class T> bool chmin(T &a, const T &b) {if (b < a) {a = b;return 1;}return 0;}
// clang-format on


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

    vvint D(C, vint(C));
    REP(i, C) REP(j, C) { cin >> D[i][j]; }

    // cost[i][to] i(mod3)類をすべてtoにするときの違和感の合計
    vvint cost(3, vint(C));

    int c;
    REP(i, N) REP(j, N) {
        cin >> c;
        c--;
        REP(to, C) cost[(i + 1 + j + 1) % 3][to] += D[c][to];
    }

    int ans = INF;
    REP(i, C) REP(j, C) REP(k, C) {
        if (i == j || j == k || k == i) continue;
        chmin(ans, cost[0][i] + cost[1][j] + cost[2][k]);
    }
    print(ans);
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
    int n;
    cin>>n;
    if(n>=105&&n<135) cout<<1<<endl;
    else if(n<105) cout<<0<<endl;
    else if(n>=135&&n<165) cout<<2<<endl;
    else if(n>=165&&n<189) cout<<3<<endl;
    else if(n>=189&&n<195) cout<<4<<endl;
    else cout<<5<<endl;
	return 0;
}


Measured memory_bytes: 256
S = gets.chomp.split('')

sum = 0
(0...2**(S.length - 1)).each do |i|
    s = S.dup
    ev = []
    while s.length > 0
        ev.push(s.shift)
        ev.push('+') if i % 2 == 1
        i >>= 1
    end
    sum += eval(ev.join)
end

puts sum

Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    ll n,a,b;
    cin >> n >> a >> b;
    if((b - a) % 2 == 0) cout << (b - a) / 2 << endl;
    else{
        cout << min({(a + b) / 2, ((n - a) + 1 + (n - b) + 1) / 2, b - 1, n - a}) << endl;
    }
    return 0;
}

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

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

	int i = 0;
	int ans = 0;
	while (i < n) {
		int countu = 1;
		int countd = 1;
		while (i + countu < n&&a[i + countu - 1] <= a[i + countu]) {
			countu++;
		}
		while (i + countd < n&&a[i + countd - 1] >= a[i + countd]) {
			countd++;
		}
		ans++;
		i += max(countu, countd);
	}
	cout << ans << endl;

	return 0;
}

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



int main()
{	
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);
	// cout.tie(NULL);
	// #ifndef ONLINE_JUDGE
 //    	freopen("input.txt", "r", stdin);
 //    	freopen("output.txt", "w", stdout);
	// #endif
    int a,b;
    cin>>a>>b;
    int ans=0;
    if(a<b)
    	swap(a,b);
    ans+=a;
    a--;
    if(a<b)
    	swap(a,b);
    ans+=a;
    cout<<ans;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<62;

ll fact(ll n) {
  ll res=0;
  while(n/2) {
    res+=n/2;
    n/=2;
  }
  return res;
}

ll comb(ll n, ll k) {
  ll res=fact(n)-fact(k)-fact(n-k);
  if(res) res=0;
  else res=1;
  return res;
}

int main() {
  ll n;
  cin >> n;
  string s;
  cin >> s;
  if(n<=4) {
    mat a(n,vec(n));
    for(ll i=0;i<n;i++) {
      a[0][i]=s[i]-'0';
    }
    for(ll i=1;i<n;i++) {
      for(ll j=0;j<n-i;j++) {
        a[i][j]=abs(a[i-1][j]-a[i-1][j+1]);
      }
    }
    cout << a[n-1][0] << endl;
  }
  else {
    ll sum=0;
    ll f=1;
    for(ll i=0;i<n;i++) {
      ll idx=(s[i]-'1');
      if(idx==1) f=0;
      sum+=idx*comb(n-1,i);
      sum%=2;
    }
    if(f) {
      sum=0;
      for(ll i=0;i<n;i++) {
        ll idx=(s[i]-'1')/2;
        sum+=idx*comb(n-1,i);
        sum%=2;
      }
      sum*=2;
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 1412
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		long X = sc.nextLong();

		sc.close();

		long a = X / 500;
		long b = (X % 500) / 5;

		out.println(a * 1000 + b * 5);

	}

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


Measured memory_bytes: 22868
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program {
  
      static List<string> Perms(string s) {
        if (s.Length == 1) return new List<string>() { s };

        var ret = new List<string>();
        for (int i = 0; i < s.Length; i++) {

            foreach (string t in Perms(s.Remove(i, 1))) {
                ret.Add(s[i] + t);
            }
        }
        return ret;
    }
  
      static void Main() {
        var list = new List<string>();
        var x = int.Parse(ReadLine());
        var sub = "";
        
        for(var i = 1;i <= x;i++){
        	sub = sub + i.ToString();
        }  
        
        list = Perms(sub);
        
        var sub1 = ReadLine().Replace(" ","");
        var sub2 = ReadLine().Replace(" ","");
        
        var y = list.IndexOf(sub1);
        var z = list.IndexOf(sub2);
        
        WriteLine(Math.Abs(y - z));
   }
}


Measured memory_bytes: 26560