akhauriyash/Code-Regression huggingface dataset:
module Main where

import Control.Applicative
import Numeric

main :: IO ()
main = do
  { [n] <- getInts
  ; call n
  }

call :: Int -> IO ()
call n = putStr " " >> putInts (filter (\ i -> p i || r i) [1 .. n])
  where
    p i = i `mod` 3 == 0
    r i = '3' `elem` show i 

-- call n = check_num n 1 1

-- check_num :: Int -> Int -> Int -> IO ()
-- check_num n i x = if x `mod` 3 == 0
--   then putStr " " >> putStr (show i) >> end_check_num n i x
--   else include3 n i x

-- include3 :: Int -> Int -> Int -> IO ()
-- include3 n i x = if x `mod` 10 == 3
--   then putStr " " >> putStr (show i) >> end_check_num n i x
--   else let x' = x `div` 10
--        in if x' /= 0 then include3 n i x'
--           else end_check_num n i x'

-- end_check_num :: Int -> Int -> Int -> IO ()
-- end_check_num n i x = let i' = i + 1
--                       in if i'<= n then check_num n i' i'
--                          else putStrLn ""

  
--

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn  .  unwords .  map show

getDoubles :: IO [Double]
getDoubles = map read . words <$> getLine

putDoubles :: [Double] -> IO ()
putDoubles = putStrLn . unwords . map showDouble

showDouble :: Double -> String
showDouble d = showFFloat Nothing d ""




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

using namespace std;
typedef long long ll;
int gcd(int a, int b){
    if(a < b)swap(a, b);
    while(b){
        int tmp = a;
        a = b;
        b = tmp % b;
    }
    return a;
}
int main()
{
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    int ret;
    cin >> ret;
    for(int i = 1; i < n; i ++){
        int tmp;
        cin >> tmp;
        ret = gcd(ret, tmp);
    }
    cout << ret << endl;
    return 0;
}
/*

1
 1 2 2 3 4 0 3 4 4 1 3 1 4 4 1 0 0 0 0 0 4 2 3 2 2 1



*/


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

struct edge { 
    int nextv, cost; 
};

vector<vector<edge>> g;
vector<int> color;
vector<int> d;
bool ans = true;

void dfs(int v, int c) {
    if(color.at(v)==0) {
        color.at(v) = 1;
        d.at(v) = c;
        for(auto ig:g.at(v)) {
            dfs(ig.nextv, c+ig.cost);
        }
    }
    else {
        if(d.at(v)!=c) ans = false;
    }
}

int main(void) {
    int n, m;
    cin >> n >> m;
    g.resize(n, vector<edge>(0));
    color.resize(n, 0);
    d.resize(n, 0);

    int l, r, d;
    for(int im=0;im<m;im++) {
        cin >> l >> r >> d; l--; r--;
        g.at(l).push_back((edge){r, d});
        g.at(r).push_back((edge){l, -d});
    }

    for(int in=0;in<n;in++) {
        if(color.at(in)==0) dfs(in, 0);
        if(!ans) { 
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 11392
#include<bits/stdc++.h>
using namespace std;
#define INF 2e9+5
#define ll long long

bool compare(const pair<string,pair<int,int> >& a,const pair<string,pair<int,int> >& b)
{
    if(a.first<b.first)
        return true;
    if(a.first==b.first)
        return a.second.first>b.second.first;
    return false;
}
int main()
{
    vector<pair<string, pair<int,int> > > v;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        string temp;
        int score;
        cin>>temp;
        cin>>score;
        v.push_back(make_pair(temp,make_pair(score,i)));
    }
    sort(v.begin(),v.end(),compare);
    for(int i=0;i<v.size();i++)
        cout<<v[i].second.second+1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main( void )
{
	int a, i, n;
	long long max, min;
	long long sum = 0;
	
	scanf( "%d", &a );
	
	scanf( "%d", &n );
	max = n;
	min = n;
	sum += n;
	
	for( i = 1; i <= a-1; i++ ){
		scanf( "%d", &n );
		if( n > max ){
			max = n;
		}
		if( n < min ){
			min = n;
		}
		
		sum += n;
	}
	
	printf( "%d %d %ld\n", min, max, sum );
	
	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>

int main() {
	int N=3;
	int i,j,tmp,a[N];
	scanf("%d %d %d",&a[0],&a[1],&a[2]);
	for(i=0;i<N-1;i++){
		for(j=0;j<N-1;j++){
			if(a[j+1]<a[j]){
				tmp=a[j];
				a[j]=a[j+1];
				a[j+1]=tmp;
			}
		}
	}
	printf("%d %d %d\n",a[0],a[1],a[2]);
}


Measured memory_bytes: 2764
#include <bits/stdc++.h>
// atoi : atoi(str.c_str())
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  long n,m;
  cin >> n >> m;
  long g;
  vector<long> yaku;
  for(int i=1;i<100000;i++){
    if(m % i == 0){
      yaku.push_back(i);
      yaku.push_back(m/i);
    }
  }
  sort(yaku.begin(),yaku.end());
  long size = yaku.size();
  for(int i = size-1;i >= 0;i--){
    if(yaku.at(i) <= m/n){
      cout << yaku.at(i) << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
import itertools

N,M = map(int,input().split())
lis = [x+1 for x in range(N-1)]
path = [list(map(int, input().split())) for _ in range(M)]
pb = [[False] * N for i in range(N)]
for i in range(M):
  p = path[i][0]-1
  q = path[i][1]-1
  pb[p][q] = True
  pb[q][p] = True

c = 0
for ps in itertools.permutations(lis):
  if pb[0][ps[0]]:
    for i in range(N-2):
      if not pb[ps[i]][ps[i+1]]:
        break
    else:
      c += 1

print(c)

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

int main()
{
  int N;
  string strN;

  int AC = 0;
  int WA = 0;
  int TLE = 0;
  int RE = 0;

  cin >> N;
  for (int i = 0; i < N; i++)
  {

    cin >> strN;
    switch (strN.at(0))
    {
    case 'A':
      AC++;
      break;

    case 'W':
      WA++;
      break;

    case 'T':
      TLE++;
      break;

    case 'R':
      RE++;
      break;

    default:
      break;
    }
  }

  cout<< "AC x "<<  AC << endl;
  cout<< "WA x " <<  WA << endl;
  cout << "TLE x " <<  TLE << endl;
  cout<< "RE x " <<  RE << endl;
}

Measured memory_bytes: 3532
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vl A(N);
  REP(i, N) {
    ll a;
    cin >> a;
    A[a - 1] = i;
  }
  set<ll> B;
  B.insert(-1);
  B.insert(N);
  ll ans = 0;
  REP(i, N) {
    B.insert(A[i]);
    ll lpos = *prev(B.find(A[i]));
    ll rpos = *next(B.find(A[i]));
    ans += (i + 1) * (rpos - A[i]) * (A[i] - lpos);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 11264
//テスト
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
const ll MOD = 1000000007;
// const ll INF = 1000000000000000000LL;


int main(){
    int d;
    cin >> d;
    vector<int> c(26);
    rep(i,26) cin >> c[i];
    vector<vector<int>> s(d,vector<int>(26));
    rep(i,d){
        rep(j,26){
            cin >> s[i][j];
        }
    }
    //答え入れる配列
    vector<int> ans(d);
    //減少
    ll sum=0;
    vector<int> last(26);
    rep(i,d){
        ll nax=-INF;
        ll nax_i;
        rep(j,26){
            ll now_sum=0;
            now_sum+=s[i][j];
            last[j]=i+1;
            ll minus=0;
            rep(k,26){
                if(k!=j)
                    minus+=c[k]*(i+1-last[k]);
            }
            now_sum-=minus;
            if(nax<now_sum){
                nax_i = j;
                nax = now_sum;
            }
        }
        ans[i] = nax_i+1;
        last[nax_i] = i+1;
    }  
    rep(i,d){
        cout << ans[i] << endl;
    }
	return 0;   
}


Measured memory_bytes: 3644
import java.util.*;
import java.io.*;

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int n = fs.nextInt(), m = fs.nextInt();
		long ans = (long)Math.pow(2, m) * (1900*m + 100*(n-m));
		System.out.println(ans);
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

Measured memory_bytes: 21204
//   //  /////       ///      
//  //   //  //     // //     
// //    //   //   //   //    
////     //   //  //     //   
// //    //   //  /////////    
//  //   //  //   //     //    
//   //  /////    //     //    

#include <bits/stdc++.h>
using namespace std;
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define iter(it,a,b) for(a::iterator it=b.begin(); it!=b.end();++it)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (binary me 1 kitne hai) (if longlong popcount ll)
#define ln "\n"
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define dbg2(x,y) cerr<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;
#define dbgstl32(v) cerr<<#v<<" = \n"; { int c=0; forstl(it,v) \
cerr<<"    Term "<< ++c <<" = "<<it<<ln;} cerr<<endl
#define dbgstlp32(v) cerr<<#v<<" = \n"; { int c=0; forstl(it,v) \
cerr<<"    Term "<< ++c <<" = "<<it.fi<<" , "<<it.se<<ln;} cerr<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(n) n.begin() , n.end() 
#define tfi first.first
#define tse first.second
#define tth second
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
typedef pair< pair<int,int> , int> tri;
typedef vector<bool> vbool;
typedef priority_queue<p32> pq32;
typedef priority_queue<p32, vector<p32>, greater<p32> > pq32l;

#pragma GCC optimize ("-O2")
const ll LIM = 2e5+5;
const ll MOD = 1e9+7;
const ll inf = 1e10;



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

	int n;
	cin >> n;

	ll a[3][n];

	forn(i,n) cin >> a[0][i] >> a[1][i] >> a[2][i];

	ll dp[3][n];

	forn(i,3) dp[i][0] = a[i][0];

	forsn(i,1,n){
		forn(j,3){
			dp[j][i] = max(dp[(j+1)%3][i-1], dp[(j+2)%3][i-1]) + a[j][i];
		}
	}

	cout << max(dp[0][n-1], max(dp[1][n-1], dp[2][n-1]));

}


Measured memory_bytes: 4992
# coding:utf-8

X, N = list(map(lambda x:int(x), input().split()))
p = list(map(lambda x:int(x), input().split()))

i = 0
while(1):
  if(X-i not in p):
    print(X-i)
    break
  if(X+i not in p):
    print(X+i)
    break
  # 範囲拡大
  i+=1


Measured memory_bytes: 9180
from collections import deque

h,w,m=map(int,input().split())
bomb=[list(map(int, input().split())) for _ in range(m)]
res1=[0]*h
res2=[0]*w
for i in range(m):
    bomb1=bomb[i]
    res1[bomb1[0]-1]+=1
    res2[bomb1[1]-1]+=1
ans1=max(res1)
ans2=max(res2)
ans=ans1+ans2
s1=0
l1=deque()
for j in range(h):
    res3=res1[j]
    if res3>s1:
            l1=[j+1]
            s1=res3
    elif res3==s1:
            l1.append(j+1)
s2=0
l2=deque()
for k in range(w):
    res4=res2[k]
    if res4>s2:
            l2=[k+1]
            s2=res4
    elif res4==s2:
            l2.append(k+1)
l3=set(l1)
l4=set(l2)
count=0

for l in range(m):
    bomb2=bomb[l]
    if bomb2[0] in l3 and bomb2[1] in l4:
        count+=1

if count!=len(l1)*len(l2):
    print(ans)
else:
    print(ans-1)


Measured memory_bytes: 218744
#include <stdio.h>

#define max(x, y) ((x) > (y) ? (x) : (y))

int main(void) 
{
	int searching_time;
	int car_in, car_out, car_inside;
	int car_inside_max;
	int i;
	int error = 0;

	scanf("%d", &searching_time);
	scanf("%d", &car_inside);

	car_inside_max = car_inside;

	for (i = 0; i < searching_time; i++) {
		scanf("%d %d", &car_in, &car_out);

		car_inside	   += car_in - car_out;
		car_inside_max	= max(car_inside_max, car_inside);

		if (car_inside < 0) 
			error++;
	}

	if (error) 
		printf("0\n");
	else 
		printf("%d\n", car_inside_max);

	return 0;
}

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

#define int long long

signed main(){
	int n; cin >> n;
	while(n--){
		string s;
		cin >> s;
		vector<int> bit;

		for(int i = 0;i < 8;i++){
			int b;
			if(s[i] < 'a'){
				b = s[i] - '0';
			}else{
				b = s[i] - 'a' + 10;
			}
		
			stack<int> st;
			for(int j = 0;j < 4;j++){
				st.push(b % 2);
				b /= 2;
			}
			while(!st.empty()){
				bit.push_back(st.top());
				st.pop();
			}
		}
		
		reverse(bit.begin(), bit.end());
		
		
		double ans = 0;
		double ans2 =0;
		double tmp = 0.5;
		for(int i = 6;i >= 0;i--){
			if(bit[i]){
				ans += tmp;
			}
			tmp /= 2;
		}
		
		int ansnum = 0;
		int ttmp = 1;
		for(int i = 7;i < 31;i++){
			if(bit[i]) ansnum += ttmp;
			ttmp *= 2;
		}
		
		ans2 = ans;
		ans += ansnum;
		if(bit[31] == 1){
			cout << '-';
		}
		cout << ansnum;
		cout << ".";
		do{
			int tmp = ans2 * 10;
			cout << tmp;
			ans2 *= 10;
			ans2 -= tmp;
		}while(ans2 != 0);
		cout << endl;
			
	}
	return 0;
}


Measured memory_bytes: 3180
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nm[0];
        var m = nm[1];

        List<string> res = new List<string>();
        var pivot = ((n - 1) / 2) / 2;
        var max = pivot;
        for (int i = 1; i <= pivot; i++)
        {
            res.Add($"{pivot - i + 1} {pivot + i + 1}");
            max = Max(max, pivot + i);
        }
        max++;
        var top = n - (n % 2 == 0 ? 1 : 0) - 1;
        while (max < top)
        {
            res.Add($"{max + 1} {top + 1}");
            max++;
            top--;
        }

        Console.WriteLine(string.Join("\n", res.Take(m)));
    }
}

Measured memory_bytes: 42672
#include <bits/stdc++.h>
using namespace std;
int main() {
    int D;
    cin >> D ;

    string ans;
    if(D == 25) ans = "Christmas";
    else if(D == 24) ans = "Christmas Eve";
    else if(D == 23) ans = "Christmas Eve Eve";
    else ans = "Christmas Eve Eve Eve";
    
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <time.h>
#include <stdio.h>
#include <vector>
#define int long long
#define end getchar();getchar();return 0
int inf = 1000000000;
using namespace std;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int mypow(int x, int y) {
	if (y == 0)return 1;
	if (y % 2)return mypow(x, y - 1)*x;
	else return mypow(x, y / 2)*mypow(x, y / 2);
}
int Max(int x, int y) {
	if (x > y)return x;
	else return y;
}
int Min(int x, int y) {
	if (x < y)return x;
	else return y;
}
int kai(int x) {
	int cnt=1;
	if (x == 0)return 1;
	cnt = kai(x - 1);
	return x * cnt;
}
int prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
void prime_factor(int n){
	int cnt = 1;
	map<int, int>res;
	int m = n;
	for (int i = 2; i<= n; i++) {
		if(prime(i)){
			while (m%i == 0) {
				++res[i];
				m /= i;
			}
		}
	}
	cout << n <<":"<< endl;
	for (int i = 2; i<= n; i++) {
		if (res[i]) {
			cout << i << " " << res[i] << endl;
		}
	}
	cout << endl;
}
/*Library End!*/
int n, m;
signed main() {
	cin >> n >> m;
	if (n == 1) {
		cout << abs(m - 2) << endl;
		end;
	}
	else if (m == 1) {
		cout << abs(n - 2) << endl;
		end;
	}
	cout << (n - 2)*(m - 2) << endl;
	end;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int s[17][17],a,b,n,x,y;

int main(){
	while(cin>>a>>b){
		if(a+b==0)return 0;
		for(int i=0;i<=b;i++)for(int j=0;j<=a;j++)s[i][j]=0;
		cin>>n;
		for(int i=0;i<n;i++){cin>>x>>y;s[y][x]=-1;}
		s[1][1]=1;
		for(int i=1;i<=b;i++){
			for(int j=1;j<=a;j++){
				if(s[i][j]==-1)s[i][j]++;
				else if(s[i][j]==0)s[i][j]=s[i-1][j]+s[i][j-1];
			}
		}
		cout<<s[b][a]<<endl;
	}
}

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

int n;
long long a[100000];
bool zero;

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

        if (a[i] == 0)
            zero = true;
    }

    if (zero == true)
        cout << 0;
    else {
        long long prod = 1;
        for (int i = 0; i < n; ++i)
            if (a[i] <= 1000000000000000000/prod)
                prod *= a[i];
            else {
                cout << -1;
                return 0;
            }
        cout << prod;
    }
    return 0;
}

Measured memory_bytes: 4396
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int R, G, B, N;
  int C;
  cin >> R >> G >> B >> N;
  int N1, N2;
  int num = 0;
  for (int r = 0; r <= N/R; r++){
    N1 = N - r*R;
    for (int g = 0; g <=  N/G; g++){
      N2 = N1 - g*G;
      if(N2 >= 0 && N2 % B ==0){
	num ++;
      }
    }
  }
  cout << num << endl;
}


Measured memory_bytes: 256
/*
 _ _ _   _    _   _    _   _ _ _   _    _   _ __ _   __       __
|  _ _| | |  | | | |  | | |  _  | | |  | | |  __  | |   \   /   |
| |_ _  | |__| | | |  | | | |_| | | |__| | | |__| | | |\ \_/ /| |
|_ _  | |  __  | | |  | | |  _ <  |  __  | |  __  | | | \   / | |
 _ _| | | |  | | | |__| | | |_| | | |  | | | |  | | | |  \_/  | |  _   _   _
|_ _ _| |_|  |_| |_ __ _| |_ _ _| |_|  |_| |_|  |_| |_|       |_| |_| |_| |_|

*/

#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define fi first
#define se second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define debug(a) cout << #a << " = " << a << " ";
#define endl "\n"
const int  MOD=1000000007;
const int N=1000100;

void solve(){
    ll N,k;
    cin>>N>>k;
    ll R,S,P;
    cin>>R>>S>>P;
    string mov;
    cin>>mov;
    ll dp[N+2];
    dp[0]=0;
    for(int i=0;i<N;i++){
        if(i<k){
            dp[i+1]=dp[i]+(mov[i]=='r')*P+(mov[i]=='s')*R+(mov[i]=='p')*S;
        } else {
            if(mov[i]=='r' && mov[i-k]=='r') mov[i]='t';
            else if(mov[i]=='s' && mov[i-k]=='s') mov[i]='t';
            else  if(mov[i]=='p' && mov[i-k]=='p') mov[i]='t';
            dp[i+1]=dp[i]+(mov[i]=='r' && mov[i-k]!='r')*P+(mov[i]=='s' && mov[i-k]!='s')*R+(mov[i]=='p' && mov[i-k]!='p')*S;
        }
    }
    cout<<dp[N]<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long int t = 1;
    // cin>>t;
    for (long int tt = 1; tt <= t; tt++) {
        solve();
    }
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int a = 0;
  char S;
  for (int i = 0; i < N; i++) {
    cin >> S;
    if (S == 'Y') {
      cout << "Four" << endl;
      a++;
      break;
    }
  }
  if (a == 0)
    cout << "Three" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

vector<char> march = {'M', 'A', 'R', 'C', 'H'};
int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    map<int, ll> m;
    for (int i = 0; i < N; i++) {
        cin >> S.at(i);
        for (int j = 0; j < 5; j++) {
            if (S[i][0] == march[j]) {
                m[j]++;
            }
        }
    }

    ll ans = 0;
    for (int i = 0; i < 5; i++) {
        for (int j = i + 1; j < 5; j++) {
            for (int k = j + 1; k < 5; k++) {
                ans += m[i] * m[j] * m[k];
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 6144
#include <iostream>
using namespace std;
 
int main() {
    long long n, r;
    cin >> n >> r;
  
  	if(n < 10)
    {
      cout << r + (100 * (10 - n)) << endl;
    }
	else
    {
      cout << r << endl;
    }
  
    return 0;
}

Measured memory_bytes: 256
let split_string ?(pattern="") = Str.split @@ Str.regexp pattern
let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let ax = read_line () |> split_string ~pattern:" " |> List.map int_of_string

let i = int_of_float 1e18

let rec mul ans = function
  | [] -> Printf.printf "%d\n" @@ if ans > i then (-1) else ans
  | x :: xs -> 
      if x = 0 then print_endline "0"
      else if int_of_float (float i /. float ans) < x then print_endline "-1"
      else mul (ans * x) xs

let () = 
  if List.mem 0 ax then print_endline "0"
  else mul 1 ax

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

int main() {
  string S;
  cin >> S;
  vector<regex> Re(8);
  Re[0] = (".*keyence");
  Re[1] = ("k.*eyence");
  Re[2] = ("ke.*yence");
  Re[3] = ("key.*ence");
  Re[4] = ("keye.*nce");
  Re[5] = ("keyen.*ce");
  Re[6] = ("keyenc.*e");
  Re[7] = ("keyence.*");
  bool ans = false;
  for(auto r : Re) ans |= regex_match(S, r);
  cout << (ans ? "YES" : "NO") << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

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

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

ll solve(ll x) {
    if (x == 1) {
        return 1LL;
    }
    return 2 * (solve(x / 2)) + 1;
}

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    ll N;
    cin >> N;

    cout << solve(N) << endl;
    return 0;
}


Measured memory_bytes: 256
MAX = 100
INF = 1 << 21
WHITE = 0 # ?????¢?´¢
GRAY = 1  # ??¢?´¢????±?
BLACK = 2 # ??¢?´¢??????

n = int(input())
M = [list(map(int, input().split())) for i in range(n)]

for i in range(n):
    for j in range(n):
        if M[i][j] == -1:
            M[i][j] = INF

d = [INF for i in range(n)] # ??¢?´¢????±?
p = [-1 for i in range(n)]  # ??????????????????
color = [WHITE for i in range(n)]

def prim():
    global M, d, p, color

    d[0] = 0

    while(1):
        minv, u = INF, -1
        for i in range(n):
            if minv > d[i] and color[i] != BLACK:
                u = i
                minv = d[i]
        if u == -1:
            break
        color[u] = BLACK # ??¢?´¢???????????´??°
        for v in range(n):
            if color[v] != BLACK and M[u][v] != INF:
                if d[v] > M[u][v]:
                    d[v], p[v], color[v] = M[u][v], u, GRAY
    return sum([M[i][p[i]] for i in range(n) if p[i] != -1])


print(prim())

Measured memory_bytes: 7908
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		String s[]=new String[n];

		for(int i=0;i<n;i++) {
			s[i]=sc.next();
		}
		Arrays.sort(s);
		int max=1;
		int c=1;
		String h=s[0];
		int b=0;
		int a[]=new int[n];
		for(int i=1;i<n;i++) {

			if(h.equals(s[i])) {
				c++;
			}else {
				max=Math.max(c, max);
				h=s[i];
				a[b]=c;
				b=i;
				c=1;
			}
			if(i==n-1) {
				max=Math.max(c, max);
				a[b]=c;
			}
		}
		for(int i=0;i<n;i++) {
			if(a[i]==max)
				System.out.println(s[i]);
		}


	}

}


Measured memory_bytes: 77276
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define pii pair<ll,ll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(ll i=a;i<=(ll)b;++i)
#define per(i,a,b) for(ll i=a;i>=(ll)b;--i)
#define ll long long
#define lowbit(x) ((x)&(-x))

int main()
{
    IOS
    int n,m;cin>>n>>m;
    cout<<n*(n-1)/2+m*(m-1)/2<<"\n";
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <string.h>

using namespace std;

int main()
{
	
	
	
	string s;
	int N, L;
	cin >> N >> L;
	
	vector <string> v(N);
	
	for (int i=0; i<N; i++)
	{
		cin >> s;
		v.push_back(s);
	}
	
	sort(v.begin(), v.end());
	
	for (int i= 0; i<v.size(); i++)
	{
		cout << v[i];
	}
	cout << "\n";
	
	
	
	
	
	
	return 0;
}



Measured memory_bytes: 256
def resolve():
    st = input()
    q = int(input())
    for i in range(q):
        s = input().split()
        a = int(s[1])
        b = int(s[2]) + 1
        if s[0] == "replace":
            st = st[:a] + s[3] + st[b:]
        elif s[0] == "reverse":
            st = st[:a] + st[::-1][len(st) - b:len(st) - a] + st[b:]
        else:
            print(st[a:b])


resolve()



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

int main()
{
    string line;
    int count=0;
    cin >> line;
    vector<char> vect;

    for(int i=0; i<line.length(); i++){
        if(line[i]=='0')
            vect.push_back('0');
        else if(line[i]=='1')
            vect.push_back('1');
        else if(line[i]=='B'){
            if(vect.size()>0)
                vect.pop_back();
        }
        count++;
    }
    vector<char>::iterator i; 
    for (i = vect.begin(); i != vect.end(); ++i) 
        cout << *i;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    long a = sc.nextLong();
    long b = sc.nextLong();
    long x = sc.nextLong();

    sc.close();

    long a_ = a/x;

    if (a%x == 0) {
      a_--;
    }

    long b_ = b/x;

    System.out.println(b_ - a_);

  }

}

Measured memory_bytes: 22996
#include <iostream>
main(){int n,i,j;double x[4],y[4];std::cin>>n;for(i=0;i<n;i++){for(j=0;j<4;j++)std::cin>>x[j]>>y[j];if((y[0]-y[1])/(x[0]-x[1])==(y[2]-y[3])/(x[2]-x[3]))std::cout<<"YES\n";else std::cout<<"NO\n";}}

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

using namespace std;

long long int helperfn(vector<pair<long long int,long long int> >&x,long long int W,long long int i,vector<vector <long long int> > &dp)
{
	if(i<0)
		return 0;

	if(dp[i][W]!=-1)
		return dp[i][W];

	if(x[i].first>W)
		dp[i][W]= helperfn(x,W,i-1,dp);
	else
		dp[i][W]= max(helperfn(x,W,i-1,dp),helperfn(x,W-x[i].first,i-1,dp)+x[i].second);

	return dp[i][W];
}
 int main()
{
	long long int N,W;
	cin >> N;
	cin >> W;

	vector<pair<long long int,long long int> > x;

	for(long long int i=0;i<N;i++)
	{
		long long int w,v;
		cin >> w;
		cin >> v;
		x.push_back(make_pair(w,v));
	}
	vector<long long int> ab(W+2,-1);
	vector<vector <long long int> > dp(N+2,ab);
	cout<<helperfn(x,W,N-1,dp);
	return 0;
}

Measured memory_bytes: 81024
from sys import stdin

# ABC
# N = int(stdin.readline().rstrip())


def dfs(x):
    ret = 0
    if int(x) > N:
        return ret
    if '7' in x and '5' in x and '3' in x:
        ret += 1
    for k in '753':
        ret += dfs(x + k)
    return ret


# print(dfs('0'))

# ABC119 C - Synthetic Kadomatsu
N, A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
l = [int(stdin.readline().rstrip()) for _ in range(N)]


def solve(m, a, b, c):
    if m == N:
        if a == 0 or b == 0 or c == 0:
            return 10 ** 7
        else:
            return abs(a - A) + abs(b - B) + abs(c - C) - 30
    return min(solve(m + 1, a, b, c), solve(m + 1, a + l[m], b, c) + 10,
               solve(m + 1, a, b + l[m], c) + 10, solve(m + 1, a, b, c + l[m]) + 10)


print(solve(0, 0, 0, 0))

Measured memory_bytes: 42204
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define N 200100
#define pii pair<int,int>
#define rep(i,k,n) for(int i=k;i<n;i++)
#define vi vector<int>
#define inf 1e9
void solve(){
	int n;
	cin>>n;
	map<string,int> mp;
	rep(i,0,n){
		string s;
		cin>>s;
		mp[s]++;
	}
	int freq=0;
	for(auto i:mp){
		freq=max(freq,i.second);
	}
	vector<string> v;
	for(auto i:mp){
		if(i.second==freq){
			v.push_back(i.first);
		}
	}
	sort(v.begin(),v.end());
	for(auto x:v){
		cout<<x<<endl;
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
}

Measured memory_bytes: 25584
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < int(n); ++ (i))
#define ALL(x) begin(x), end(x)
using namespace std;

int main() {
    // input
    int n, k; scanf("%d%d", &n, &k);
    vector<int> a(n); REP (i, n) scanf("%d", &a[i]);
    // solve
    map<int, int> cnt;
    for (int a_i : a) cnt[a_i] += 1;
    vector<int> b;
    for (auto it : cnt) b.push_back(it.second);
    sort(ALL(b));
    reverse(ALL(b));
    int result = b.size() <= k ? 0 : accumulate(b.begin() + k, b.end(), 0);
    // output
    printf("%d\n", result);
    return 0;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9+7)
ll N,A,B;
ll i,j,k,ans;

void anss(ll nb,ll a,ll b){
    if(__builtin_popcount(nb)==N-1){
        printf("%lld %lld ", a, b);
    }else{
        ll db = 1;
        while((nb&db)||!((a^b)&db)){
            db *= 2;
        }
        ll cb = 1;
        while((cb&nb)||(db==cb)){
            cb *= 2;
        }
        anss(nb | db, a, a ^ cb);
        anss(nb | db, a^cb^db, b);
    }
}

int main(){
    scanf("%lld%lld%lld", &N,&A,&B);
    j = 0;
    if(__builtin_popcount(A^B)%2==0){
        printf("NO");
        return 0;
    }
    printf("YES\n");
    anss(0, A, B);
    return 0;
}

Measured memory_bytes: 1024
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 
 
	public static void main(String[] args) { //Generate sets of [W,B]
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int N  = I.nextInt();
		String S = I.next();
		int[] W = new int[N+1]; //Number of white stones up to index i (exclusive)
		int[] B = new int[N+1]; //Number of black stones up to index i (exclusive)
		//i = 0 is the null set
		long ans = 100001000;
		for (int i = 0; i < N; i++) {
			B[i+1]=B[i];
			W[i+1]=W[i];
			if (S.charAt(i)=='.') W[i+1]++;
			else B[i+1]++;
		}
		for (int chk = 0; chk<=N; chk++) {
			int white = W[chk];
			int black = B[N]-B[chk];
			int changeW = chk-white;
			int changeB = N-chk-black;
			ans=Math.min(ans, changeB+changeW);
		}
		O.pln(ans);
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
	}
}


Measured memory_bytes: 31224
import java.util.Scanner;


public class Main {

    public static String Y = "Yes";
    public static String N = "No";

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        String s = sc.next();

        if (n % 2 == 1) {
            out(N);
        } else {
            if (s.substring(0, n / 2).equals(s.substring(n / 2, n))) {
                out(Y);
            } else {
                out(N);
            }
        }

    }

    /*
     * 以下メソッド集
     */
    static int kaijo(int n) {

        if (n == 0 || n == 1) {
            return 1;
        } else {
            return n * kaijo(n - 1);
        }
    }

    static int fib(int n) {

        return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
    }

    static long lcm(long m, long n) {

        return m * n / gcd(m, n);
    }

    static int lcm(int m, int n) {

        return m * n / gcd(m, n);
    }

    static long gcd(long a, long b) {

        return (b == 0) ? a : gcd(b, a % b);
    }

    static int gcd(int a, int b) {

        return (b == 0) ? a : gcd(b, a % b);
    }

    static void out(String info) {

        System.out.println(info);
    }

    static void out(int info) {

        System.out.println(info);
    }

    static void out(double info) {

        System.out.println(info);
    }

    static void out(long info) {

        System.out.println(info);
    }

}


Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
string s;
using MIte = multimap<int, int>::iterator;



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

	vector<int> vd(N, 0);
	vector<int> vnumd(100001, 0); // vnumd[i] = 難易度iの数
	for (int i = 0; i != N; ++i) {
		int p = 0;
		cin >> p;
		vd[i] = p;
		++vnumd[p];
	}

	vector<int> vnumd2(vnumd);
	for (int i = 0; i != vnumd2.size() - 1; ++i) {
		vnumd2[i + 1] += vnumd2[i];
	}

	const int halfN = N / 2;
	int cnt = 0;
	for (int i = 0; i != vnumd2.size(); ++i) {
		if (vnumd2[i] == halfN) {
			cnt++;
		}
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 1408
#include <stdio.h> 
 #include <ctype.h> 
 
 
 int main(){ 
     int count[26]={0}; 
    char ch; 
    int i, num; 
 
 
     while(scanf("%c", &ch)!=EOF){ 
         if(islower(ch)){ 
             num=ch-'a'; 
         }else if(isupper(ch)){ 
             num=ch-'A'; 
         }else{ 
             continue; 
         } 
         count[num]++; 
     } 
     for(i=0;i<26;i++){ 
         printf("%c : %d\n", 'a'+i, count[i]); 
     } 
 
 
     return 0; 
 } 



Measured memory_bytes: 2724
/// awoooooo

# include <bits/stdc++.h>
# define sz(x) (int)((x).size())

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;

const int N = (int)2e5 + 5;
const int inf = (int)1e9 + 7;

int n;
int a[N], b[N];
int now[N];
set < pii > s;

int get(int i){
  int sum = b[(i + 1) % n] + b[(i + n - 1) % n];
  if(sum > b[i]){
    sum = inf;
  }
  return (b[i] - a[i]) / sum;
}

int main(){
  scanf("%d", &n);
  for(int i = 0; i < n; ++i){
    scanf("%d", a + i);
  }
  for(int i = 0; i < n; ++i){
    scanf("%d", b + i);
    if(a[i] > b[i]){
      printf("-1\n");
      return 0;
    }
  }
  for(int i = 0; i < n; ++i){
    now[i] = get(i);
    if(a[i] != b[i]){
      s.insert(make_pair(now[i], i));
    }
  }
  ll cnt = 0;
  while(!s.empty()){
    auto it = (--s.end());
    if(it -> first == 0){
      printf("-1\n");
      return 0;
    }

    int id = it -> second;
    int sum = b[(id + n - 1) % n] + b[(id + 1) % n];
    b[id] -= sum * now[id];
    cnt += now[id];

    s.erase(make_pair(now[id], id));
    s.erase(make_pair(now[(id - 1 + n) % n], (id - 1 + n) % n));
    s.erase(make_pair(now[(id + 1) % n], (id + 1) % n));

    now[id] = get(id);
    now[(id - 1 + n) % n] = get((id - 1 + n) % n);
    now[(id + 1) % n] = get((id + 1) % n);
    if(a[id] != b[id]){
      s.insert(make_pair(now[id], id));
    }
    if(a[(id + n - 1) % n] != b[(id + n - 1) % n]){
      s.insert(make_pair(now[(id - 1 + n) % n], (id - 1 + n) % n));
    }
    if(a[(id + 1) % n] != b[(id + 1) % n]){
      s.insert(make_pair(now[(id + 1) % n], (id + 1) % n));
    }
  }
  printf("%lld\n", cnt);

  return 0;
}


Measured memory_bytes: 13952
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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; }

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

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

  int n, m, k; cin >> n >> m >> k;

  for(int i=0; i<=n; i++) {
    for(int j=0; j<=m; j++) {
      int now = i*j + (n-i)*(m-j);
      if (k == now) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
inps = input().split()
if len(inps) < 3:
    print("Illegal input.")
else:
    count = 0
    start = int(inps[0])
    end = int(inps[1])
    target = int(inps[2])
    for i in range(start, end+1):
        if target % i == 0:
            count += 1

print(count)

Measured memory_bytes: 7680
import heapq

n, m = map(int, input().split())
a = list(map(lambda x:int(x)*(-1), input().split()))
heapq.heapify(a)

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

Measured memory_bytes: 14252
import java.util.*;

class Main{
	public static void main(String[]$){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int[]a=new int[n],b=new int[n],min=new int[n],max=new int[n];
		Arrays.setAll(a,i->s.nextInt());
		Arrays.setAll(b,i->s.nextInt());
		Arrays.fill(min,1);
		Arrays.fill(max,Integer.MAX_VALUE);
		for(int i=0;i<n;++i) {
			if(i==0||a[i]!=a[i-1])
				min[i]=max[i]=a[i];
			else
				max[i]=Math.min(max[i],a[i]);
		}
		for(int i=n-1;i>=0;--i) {
			if(i==n-1||b[i]!=b[i+1]) {
				if(min[i]>b[i]||max[i]<b[i]) {
					System.out.println(0);
					return;
				}
				min[i]=max[i]=b[i];
			}else {
				max[i]=Math.min(max[i],b[i]);
			}
		}
		
		long r=1;
		for(int i=0;i<n;++i) {
			r*=Math.max(0,max[i]-min[i]+1);
			r%=1000000007;
		}
		System.out.println(r);
	}
}


Measured memory_bytes: 90512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.stream.Stream;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;

	static Map<Long,Long> memo = new HashMap<>();
	static List<Integer>[] graph;
	static int N, M;
	static int[] maxx, color;

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			N = in.nextInt();
			M = in.nextInt();
			graph = new ArrayList[N];
			graph = Stream.generate(ArrayList::new).limit(N).toArray(List[]::new);

			for (int i = 0; i < M; i++) {
				int a = in.nextInt() - 1, b = in.nextInt() - 1;
				graph[a].add(b);
				graph[b].add(a);
			}

			int Q = in.nextInt();
			int[] v = new int[Q];
			int[] d = new int[Q];
			int[] c = new int[Q];
			for (int i = 0; i < Q; i++) {
				v[i] = in.nextInt() - 1;
				d[i] = in.nextInt();
				c[i] = in.nextInt();
			}

			color = new int[N];
			maxx = new int[N];
			Arrays.fill(maxx, -1);
			for (int i = Q - 1; i >= 0; i--) {
				process(v[i], d[i], c[i]);
			}

			for (int i = 0; i < N; i++) {
				out.println(color[i]);
			}
		}

		static void process(int v, int d, int c) {
			if (maxx[v] >= d) return;
			maxx[v] = d;
			if (color[v] == 0) color[v] = c;
			for (int tv : graph[v]) {
				process(tv, d - 1, c);
			}
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 74320
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define pb push_back
#define vl vector
#define ff first
#define ss second
using namespace std;
int main()
{
    ll a,b,i,j,n,t,c,k,r,g;
    cin>>n>>k;
    ll arr[n];
    for(i=0;i<n;i++) cin>>arr[i];
    ll brr[n-k+1];
    ll sum=0;
    for(i=0;i<k;i++) sum+=arr[i];
    brr[0]=sum;
    j=0;
    for(i=k;i<n;i++)
    {
        sum+=arr[i];
        sum-=arr[j];
        j++;
        brr[j]=sum;
    }
    for(i=1;i<n-k+1;i++) 
    {
        if(brr[i]>brr[i-1]) cout<<"Yes";
        else cout<<"No";
        cout<<endl;
    }
    
}

Measured memory_bytes: 6712