akhauriyash/Code-Regression huggingface dataset:
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import qualified Data.Array.IO as A
import Debug.Trace
import Data.List
import Control.Monad


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

rp :: IO (Int,Int)
rp  = toTup . unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

toTup [a,b] = (a,b)


main :: IO ()
main = do
    xs <- r'
    print $ sum xs - maximum xs


Measured memory_bytes: 380
S=list(input())
mod=2019
S=list(reversed(S))
N=len(S)
A=[0]*(N)
p=1
for i in range(N):
    if i==0:
        p=1
    else:
        p*=10
        p%=mod
    now=(int(S[i])*p)%mod
    A[i]=now
    #print(now)
rui=[0]*(N+1)
for i in range(1,N+1):
    rui[i]=(rui[i-1]+A[i-1])%mod
total=[0]*2019
for r in rui:
    total[r]+=1
ans=0
for t in total:
    ans+=t*(t-1)//2
print(ans)




Measured memory_bytes: 24456
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int,int> > vp;
#define pb push_back
#define mp make_pair
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
int mk[10010];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m,x;
	cin>>n>>m>>x;
	for(int i=0;i<m;i++){
		int a;
		cin>>a;
		mk[a] = 1;
	}
	int cur = x;
	int ans1 = 0,ans2 = 0;
	while(cur >= 0){
		if(mk[cur])ans1++;
		cur--;
	}
	cur = x;
	while(cur <= n){
		if(mk[cur])ans2++;
		cur++;
	}
	cout<<min(ans1,ans2)<<'\n';


	
}

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

int main(){
	int N;
	cin >> N;
	while(N!=0){
	int c = 1;
	int g = 0;
	int t;
		for(int i = 0; i < N; i++){
			cin >> t;
			if(t < 2){
			g+=t;
			}else c++;
		}
		if(c > 1)cout << c+g<<endl;
		else cout <<"NA"<<endl;
		cin >>N;
	}
	return 0;
}


Measured memory_bytes: 3084
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
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; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion


void Main();
void solve(long long A, long long B);

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main(){
    ll N, M, C;
    cin >> N >> M >> C;
    vec<ll> B(M);
    REP(i, M){
        cin >> B[i];
    }
    ll cnt = 0;
    REP(i, N){
        ll sum = C;
        REP(j, M){
            ll t;
            cin >> t;
            sum += t*B[j];
        }
        if(sum > 0){
            cnt++;
        }
    }
    cout << cnt << el;
}



Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main {
  public static void main(String[] args) throws Exception{
    FastScanner sc = new FastScanner(System.in);
    int r = sc.nextInt();
    new Solution(r);
  }
}

class Solution {
  public Solution(int r) {
    System.out.println(r * 2 * Math.PI);
    // System.out.println(res);
  }
}

class FastScanner {
  private final InputStream in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;

  public FastScanner(InputStream source) {
    in = source;
  }

  private boolean hasNextByte() {
    if (ptr < buflen) {
      return true;
    } else {
      ptr = 0;
      try {
        buflen = in.read(buffer);
      } catch (IOException e) {
        e.printStackTrace();
      }
      if (buflen <= 0) {
        return false;
      }
    }
    return true;
  }

  private int readByte() {
    if (hasNextByte()) return buffer[ptr++];
    else return -1;
  }

  private static boolean isPrintableChar(int c) {
    return 33 <= c && c <= 126;
  }

  public boolean hasNext() {
    while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
    return hasNextByte();
  }

  public String next() {
    if (!hasNext()) throw new NoSuchElementException();
    StringBuilder sb = new StringBuilder();
    int b = readByte();
    while (isPrintableChar(b)) {
      sb.appendCodePoint(b);
      b = readByte();
    }
    return sb.toString();
  }

  public long nextLong() {
    if (!hasNext()) throw new NoSuchElementException();
    long n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while (true) {
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
        throw new NumberFormatException();
      }
      b = readByte();
    }
  }

  public int nextInt() {
    long nl = nextLong();
    if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
      throw new NumberFormatException();
    return (int) nl;
  }

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

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

using namespace std;
int main(){
  string n;
  cin >> n;
  for(int i = 0; i < 3; ++i){
    if( n[i] == '1') n[i] = '9';
    else n[i] = '1';
  }
  
  cout << n << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>

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

using namespace std;

typedef long long int lli;
typedef vector<int> vi;

int main() {
	string s, t, k;
	int i, j;

	cin >> s >> t;

	j = s.length();

	rep(s.length()) {
		if (s == t) {
			cout << "Yes";
			return 0;
		}
		k = t[j-1];
		k += t;
		k.resize(j);
		t = k;
	}
	cout << "No";


	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
  long long int n,i,a[200009],b[200009],m1;
    map<long long int ,long long int>m;
main()
{


    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        m[a[i]]++;
    }
    cin>>m1;
    for(i=0;i<m1;i++)
    {
        cin>>b[i];
        if(m[b[i]]==0)
        {
            cout<<"NO";
            return 0;
        }
        m[b[i]]--;
    }
    cout<<"YES";
}


Measured memory_bytes: 15872
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(); // 1
		int B = sc.nextInt(); // 0
		int C = sc.nextInt(); // -1
		long K = sc.nextLong(); // 取るカードの枚数
		sc.close();
		long answer = 0L;
		if(K <= A) {
			answer = K;
		} else if(K <= (A + B)) {
			answer = A;
		} else {
			answer = A - (K - A - B); 
		}
		System.out.println(answer);
	}
}

Measured memory_bytes: 27036
#include <stdio.h>

int main(void){
    int num;

    scanf("%d",&num);

    for(int i=1; i<=9; i++){
        if(num/i < 10 && num%i == 0){
            printf("Yes\n");
            return 0;
        }
    }
    
    printf("No\n");
    return 0;
}


Measured memory_bytes: 1664
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	d := make(map[int]int)
	for i := 0; i < N; i++ {
		n := getInt()
		d[n]++
	}
	M := getInt()
	ans := true
	for i := 0; i < M; i++ {
		t := getInt()
		if d[t] != 0 {
			d[t]--
		} else {
			ans = false
		}
	}
	if ans {
		out("YES")
	} else {
		out("NO")
	}
}


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

#define ALL(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0, __##i##_length = (n); i < __##i##_length; i++)
#define rep_reverse(i, n) for (ll i = (n)-1; 0 <= i; i--)
#define FOR(i, from, to)                                                       \
  for (ll i = (from), __##i##_end = (to); i < __##i##_end; i++)
#define FOR_REVERSE(i, from, to)                                               \
  for (ll i = (to)-1, __##i##_end = (from); __##i##_end <= i; i--)
#define foreach(e, v) for (const auto e : (v))
#define vfree(v) std::vector<int>().swap(v)
#define DEBUG(x) cout << #x << " = " << (x) << endl

using namespace std;
typedef int64_t ll;
typedef vector<ll> llv;
typedef vector<llv> llvv;

#define MOD (ll)1000000007

// 累積二乗法
ll power_mod(ll a, ll n) {
  ll ret = 1;
  while (n) {
    if (n % 2) {
      ret *= a;
      ret %= MOD;
    }
    n >>= 1;
    a *= a;
    a %= MOD;
  }
  return ret;
}

ll fermato_inv(ll n) { return power_mod(n, MOD - 2); }

ll combination_mod(ll n, ll r) {
  ll ret = 1;
  rep(i, r) {
    ret *= (n - i);
    ret %= MOD;
    ret *= fermato_inv(i + 1);
    ret %= MOD;
  }
  return ret;
}

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  // a,bが十分小さいので愚直に求められる
  ll ans = power_mod(2, n) - 1;
  ans -= combination_mod(n, a);
  ans -= combination_mod(n, b);
  while (ans < 0)
    ans += MOD;

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
#define debug(x) cerr << #x << ":" << x << endl;

int main()
{
  int N, K;
  cin >> N >> K;
  vector< int > x(N);
  for (int i = 0; i < N; ++i) {
    cin >> x[i];
  }

  int ans = 1e9 + 1;
  for (int i = 0; i <= N - K; ++i) {
    int l = abs(x[i]);
    int r = abs(x[i + K - 1]);
    int tmp;

    if (x[i + K - 1] <= 0) {
      // 一番右の要素が0以下の場合、全て0よりも右に存在している
      tmp = l;
    } else if (x[i] >= 0) {
      // 一番左の要素が0以上の場合、全て0よりも左に存在している
      tmp = r;
    } else {
      // それ以外の要素は0を挟んで左右に存在している
      tmp = l + r + min(l, r);
      // debug(min(l, r));
    }
    // debug(tmp);
    ans = min(ans, tmp);
  }

  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Iterator;
import java.util.Collections;
import java.util.Comparator;
import java.util.Random;

class Main{
        public static void main(String args[]){
                Scanner sc = new Scanner(System.in);
                int a,b,c,d;
                a = sc.nextInt();
                b = sc.nextInt();
                c = sc.nextInt();
                d = sc.nextInt();

                if(a+b>c+d){
                        System.out.print("Left");
                }else if(a+b==c+d){
                        System.out.print("Balanced");
                }else{
                        System.out.print("Right");
                }
        }
}


Measured memory_bytes: 25684
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n - 1); 0 <= i; --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

namespace My
{
template <typename ArrayT>
static void DumpArray(const ArrayT &arr)
{
#if defined(HOME)
	for (auto it = std::begin(arr); it != std::end(arr); ++it) {
		cerr << *it << " ";
	}
	cerr << endl;
#endif
}
template <typename T>
static void DumpGrid(const vector<vector<T>> &grid)
{
#if defined(HOME)
	REP (i, grid.size()) {
		REP (j, grid[i].size()) {
			cerr << grid[i][j] << " ";
		}
		cerr << endl;
	}
#endif
}
template <class ArrayT, typename T>
static void InitArray(ArrayT &arr, T initValue)
{
	for (auto &v : arr) {
		v = initValue;
	}
}
template <typename T>
static bool ReplaceIfSmaller(T &target, T value)
{
	if (value < target) {
		target = value;
		return true;
	} else {
		return false;
	}
}
template <typename T>
static bool ReplaceIfBigger(T &target, T value)
{
	if (target < value) {
		target = value;
		return true;
	} else {
		return false;
	}
}

class Solver
{
  public:
	Solver() {}

	// [row][col]
	int dist[10][10];
	void Solve(istream &cin, ostream &cout)
	{
		int H, W;
		cin >> H >> W;

		REP(i, 10){
			REP(j, 10){
				cin >> dist[i][j];
			}
		}

		// 最短経路問題
		// ワーシャル・フロイドで求める
		REP(k, 10){
			REP(i, 10){
				REP(j, 10){
					dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
				}
			}
		}
		// REP(i, 10){
		// 	DumpArray(dist[i]);
		// }

		ll ans = 0;
		REP (i, H) {
			REP (j, W) {
				int n;
				cin >> n;

				if (n == -1 || n == 1) continue;

				ans += dist[n][1];
			}
		}

		cout << ans << endl;
	}
};
} // namespace My

#if !defined(BOOST_TEST_MODULE)
#if !defined(GTEST_INCLUDE_GTEST_GTEST_H_)
int main()
{
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);

	My::Solver solver;
	solver.Solve(std::cin, std::cout);

	return 0;
}
#endif
#endif


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define fastcin() ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(), (x).end()
#define heap priority_queue
using namespace std;
typedef pair<int, int> ii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 300050, INF = 1e18; 
int n, a[maxn], pre[maxn]; 

int sum(int l, int r) {
	return pre[r] - pre[l-1]; 
}

signed main()
{
	cin >> n;  
	for(int i = 1; i <= n; i++) 
		cin >> a[i]; 
	for(int i = 1; i <= n; i++) 
		pre[i] = pre[i-1] + a[i]; 
	int ans = INF; 
	for(int i = 2; i <= n - 2; i++) {
		int suml = pre[i] / 2, sumr = (pre[n] - pre[i]) / 2; 
		int idl = lower_bound(pre + 1, pre + i + 1, suml) - pre; 
		int idr = lower_bound(pre + i + 1, pre + n + 1, sumr + pre[i]) - pre; 
		for(int j = max(1LL, idl - 10); j <= min(i - 1, idl + 10); j++) {
			for(int k = max(i + 1, idr - 10); k <= min(n - 1, idr + 10); k++) {
				int mx = max({sum(1, j), sum(j + 1, i), sum(i + 1, k), sum(k + 1, n)}); 
				int mn = min({sum(1, j), sum(j + 1, i), sum(i + 1, k), sum(k + 1, n)}); 
				ans = min(ans, mx - mn); 
			}
		}
 	}
 	cout << ans; 
}


Measured memory_bytes: 6672
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)

typedef long long int ll;
typedef vector<int>vi;
typedef pair<int,int>pi;



int main()
{

vector<int> s(3);
int a,b;
cin>>a>>b;

s[a-1]++;
s[b-1]++;

for(int index = 0;index < 3 ;index++)
{
    if(!s[index])
    {
        cout<<index+1<<endl;
        break;
    }
}

 return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
#define db double
const db eps = 1e-8;

struct Point{
    db x, y;
    Point(db x=0, db y=0): x(x), y(y) {}    //必须有初始化
    bool operator < (const Point &p){
        return x < p.x || (x == p.x && y < p.y);
    }
};

typedef Point Vector;
Vector operator + (Vector a, Vector b){ return Point(a.x+b.x, a.y+b.y);}
Vector operator - (Point a, Point b){ return Vector(a.x-b.x, a.y-b.y);}
Vector operator * (Vector a, db k){ return Vector(a.x*k, a.y*k);}
Vector operator / (Vector a, db k){ return Vector(a.x/k, a.y/k);}

//inline将函数名为内联函数，不使用栈空间，直接运算，但不能有while,switch等复杂语句
inline db dot(Vector a, Vector b){
    return a.x*b.x + a.y*b.y;
}
inline db cross(Vector a, Vector b){
    return a.x*b.y - b.x*a.y;
}
db length(Vector a){
    return sqrt(dot(a, a));
}
db angle(Vector a, Vector b){
    return acos(dot(a, b) / length(a) / length(b));
}

int dcmp(db x){
    if(fabs(x) < eps) return 0;
    return x < 0? -1: 1;
}
bool operator == (Point a, Point b){
    return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y) == 0;
}

struct Segment{
    Point p1, p2;
};
typedef Segment Line;
vector<Point> Polygon;
Point project(Line l, Point p){
    Vector a = l.p2 - l.p1, b = p - l.p1;
    db len_a = dot(a, a);   //这里不加sqrt，是因为下面算投影长度时，要除以两次len_a
    Vector tmp = a * (dot(a, b) / len_a);
    return Point(tmp.x+l.p1.x, tmp.y+l.p1.y);
}
Point reflect(Line l, Point p){
    Point tmp = project(l, p);
    return p + (tmp - p)*2;
}

void line_relation(Point p1, Point p2, Point p3, Point p4){
    Vector a = p2 - p1, b = p4 - p3;
    if(cross(a, b) == 0)
        puts("parallel");
    else if(dot(a, b) == 0)
        puts("orthogonal");
    else
        puts("others");
}
int com_segment_relation(Point p0, Point p1, Point p2){
    Vector a = p1-p0, b = p2-p0;
    db flag = cross(p1-p0, p2-p0);
    if(flag < 0)  return 2;
    else if(flag > 0)  return 1;
    else{       //重合
        if(a.x*b.x < 0 || a.y*b.y < 0) return 3;
        else if(length(a) < length(b)) return 4;
        else return 5;
    }
}

int segment_intersection(Point p1, Point p2, Point p3, Point p4){
    Point node1[2] = {p1, p2}, node2[2] = {p3, p4};
    sort(node1, node1+2), sort(node2, node2+2);
    if(node2[1] < node1[0] || node1[1] < node2[0])
        return 0;       //同一直线上，最大最小排除
    else if(cross(p2-p1, p3-p1)*cross(p2-p1, p4-p1) > 0 || cross(p4-p3, p1-p3)*cross(p4-p3, p2-p3) > 0)
        return 0;
    else
        return 1;
}

Point cross_point(Point p1, Point p2, Point p3, Point p4){
    if(!segment_intersection(p1, p2, p3, p4))
        exit(0);
    Vector a = p2-p1, b1 = p3-p1, b2 = p4-p1;
    db len = length(a);
    db h1 = fabs(cross(a, b1) / len);   //可以省去除len,求t时会消掉
    db h2 = fabs(cross(a, b2) / len);
    db t = h1 / (h1+h2);
    return p3+(p4-p3)*t;
}
int main()
{
    Point p1, p2, p3, p4;
    int n;
    cin >>n;
    while(n --){
        cin >>p1.x >>p1.y >>p2.x >>p2.y>>p3.x >>p3.y >>p4.x >>p4.y;
        Point ans = cross_point(p1, p2, p3, p4);
        printf("%.10f %.10f\n", ans.x, ans.y);
    }
    return 0;
}



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

bool pairCompare(const pair<int, bool>& a, const pair<int, bool>& b)
{
    return a.first < b.first;
}

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

  int n,h;
  cin >> n >> h;

  vector<pair<int, bool>> ab(n * 2); // second = is B
  rep(i, n * 2) {
    cin >> ab[i].first;
    ab[i].second = i % 2 != 0;
  }

  sort(ab.begin(), ab.end(), pairCompare);

  int i = ab.size() - 1;
  int ans = 0;
  while(h > 0) {
    if(ab[i].second) { // is B
      h -= ab[i].first;
      ans++;
      i--;
      continue;
    }

    ans += ceil((double)h / (double)ab[i].first);
    break;
  }

  cout << ans << endl;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, c = 0;
  cin >> n;
  string s = to_string(n);
  for (auto i : s) {
    if (i == '2') c++;
  }
  cout << c << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] params = sc.nextLine().split(" ");
        int n = Integer.parseInt( params[0] );
        int m = Integer.parseInt( params[1] );
        int[] ss = new int[m];
        int[] cs = new int[m];
        boolean isNg = false;
        for( int i = 0 ; i < m ; i++ ){
            params = sc.nextLine().split(" ");
            ss[i] = Integer.parseInt( params[0] );
            cs[i] = Integer.parseInt( params[1] );
            for( int j = 0 ; j < i ; j++ ){
                if( isNg ){
                    break;
                }
                if( ss[j] == ss[i] ){
                    if( cs[j] != cs[i] ){
                        isNg = true;
                        break;
                    }
                }
            }
        }

        if( isNg ){
            System.out.println(-1);
            return;
        }

        if( n == 1 ){
            int min = 0;
            for( int i = 0 ; i < m ; i++ ){
                    min = cs[i];
            }
            System.out.println( min );
            return;
        }

        if( n == 2 ){
            int ans = 10;
            for( int i = 0 ; i < m ; i++ ){
                if( ss[i] == 2 ){
                    ans = ans / 10 * 10 + cs[i];
                }
                if( ss[i] == 1 ){
                    if( cs[i] == 0 ){
                        System.out.println(-1);
                        return;
                    }
                    ans = cs[i] * 10 + ans % 10;
                }
            }
            System.out.println( ans );
            return;
        }

        if( n == 3 ){
            int ans = 100;
            for( int i = 0 ; i < m ; i++ ){
                if( ss[i] == 3 ){
                    ans = ans / 10 * 10 + cs[i];
                }
                if( ss[i] == 2 ){
                    ans = ans / 100 * 100 + cs[i] * 10 + ans % 10;
                }
                if( ss[i] == 1 ){
                    if( cs[i] == 0 ){
                        System.out.println(-1);
                        return;
                    }
                    ans = cs[i] * 100 + ans % 100;
                }
            }
            System.out.println( ans );
        }

    }

}



Measured memory_bytes: 22996
MOD=1000000007

def fac(x):
    ret=1
    for i in range(1,x+1):
        ret*=i
        ret%=MOD
    return ret

N,M=map(int,input().split())

if N==M:
    print(fac(N)**2*2%MOD)
elif abs(N-M)==1:
    print(fac(N)*fac(M)%MOD)
else:
    print(0)


Measured memory_bytes: 9024
#include <bits/stdc++.h>
#include <sys/time.h>
#define ST first
#define ND second
#define pb push_back
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = a; i >= n; i--)
#define SZ(x) ((int)x.size())
#define ALL(x) (x.begin(), x.end())
#define pii pair <int, int>
#define ll long long
#define LD long double
#define int long long
using namespace std;
int x, y, t[1005][1005], ans;
vector <pair <pii, pii> > v;
main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>y>>x;
    rep(i, 1, y)
    {
        rep(j, 1, x)
        {
            cin>>t[i][j];
        }
    }
    rep(i, 1, y)
    {
        rep(j, 1, x)
        {
            //cout<<i<<" "<<j<<" "<<t[i][j]<<endl;
            if (t[i][j]%2==1)
            {
                if (j<x)
                {
                    v.pb({{i, j}, {i, j+1}});
                    t[i][j+1]++;
                    //cout<<"DODAJE: "<<i<<" "<<j+1<<" "<<t[i][j+1]<<endl;;
                }
                else if (i<y)
                    v.pb({{i, j}, {i+1, j}}), t[i+1][j]++;
            }
        }
    }
    cout<<v.size()<<endl;
    for (auto u: v)
    {
        cout<<u.ST.ST<<" "<<u.ST.ND<<" "<<u.ND.ST<<" "<<u.ND.ND<<endl;
    }
}


Measured memory_bytes: 10220
#include <bits/stdc++.h>
#include <time.h>
#include <tr1/unordered_map>
#include <tr1/unordered_set>
using namespace std::tr1;
using namespace std;
/* cau troi cho Garena nhap de con Bach */
#define FSYNC ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define int long long
#define endl '\n'
#define inf 0x3f3f3f3f
#define lb lower_bound
#define pob pop_back
#define ub upper_bound
#define ite ::iterator
#define db(x) {cout <<"#db " << x << endl;}
#define here() {cout <<"here \n";}
#define mod 1000000007
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
const int MOD = 1e9 + 7;
const int _MOD = 998244353;
const int N = 1e5;
set<ii> plane;
set<ii> check;
int h,w,n;
int cnt[10];
signed main(){
	cin >> h >> w >> n;
	for(int i = 0 ; i < n ; i ++){
		int a,b;
		cin >> a >> b;
		plane.insert(mp(a,b));
		for(int i = -1 ; i <= 1 ; i ++)
			for(int j = -1 ; j <= 1 ; j ++)
				if(a+i >= 2 && b+j >= 2 && a+i <= h - 1 && b+j <= w - 1) check.insert(mp(a+i,b+j));
	}
	cnt[0] = (h-2)*(w-2);
	
	for(ii point:check){
		int total = 0;
		for(int i = -1 ; i <= 1 ; i ++)
			for(int j = -1 ; j <= 1 ; j ++)
				total += plane.count(mp(point.fi + i,point.se + j));
		if(total){
			cnt[0]--;
			cnt[total]++;
		}
	}
	for(int i = 0 ; i < 10 ; i ++) cout << cnt[i] << endl;
	
	return 0;
}


Measured memory_bytes: 62720
#include<cstdio>
using namespace std;
const long long md=1000000007;
char s1[100100],s2[100100];
long long dp[100100][2];
int main(){
//	freopen("B.in","r",stdin);
	int n;
	scanf("%d",&n);
	scanf("%s",s1+1);
	scanf("%s",s2+1);
	for(int i=1;i<=n;i++)
	{
		if(s1[i]==s2[i]){
			if(i==1){
				dp[i][0]=3;
				continue;
			}
			dp[i][0]=(dp[i-1][0]*2%md+dp[i-1][1]%md)%md;
		}
		else{
			if(i==1){
				dp[i+1][1]=6;
				i++;
				continue;
			}
			dp[i+1][1]=(dp[i-1][0]*2%md+dp[i-1][1]*3%md)%md;
			i++;
		}
	}
	printf("%lld\n",(dp[n][0]+dp[n][1])%md);
	return 0;
}


Measured memory_bytes: 128
MOD = 1000000007

n = int(input())
s1 = input()
s2 = input()

if s1[0] == s2[0]:
    ans = 3
    i = 1
    prev = 1
else:
    ans = 6
    i = 2
    prev = 2

while i<n:
    
    if s1[i] == s2[i]:
        i += 1
        if prev == 1:
            ans *= 2
        else:
            prev = 1
    else:
        i += 2
        if prev == 1:
            ans *= 2
            prev = 2
        else:
            ans *= 3
    ans %= MOD

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<bitset>
#include<algorithm>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> data(n);
	rep(i, n)
		cin >> data[i];
	//K回以内にあるlengthで切ることが出来たらokとする。出来なかったらngとする。
	//1<<data[i]<<1e9なので、開始はng=0、ok=1e9+1とする。
	int ng = 0, ok = 1e9 + 1;
	while (ok - ng != 1) {
		int mid = (ng + ok) / 2;
		int cut_count = 0;
		for (int i = 0; i < n; i++) {
			cut_count += data[i] / mid;
			if (data[i] % mid == 0)
				cut_count--;
			if (cut_count > k)
				break;
		}
		if (cut_count > k) {
			ng = mid;
			//cout <<"ng="<< ng << endl; 確認用
		}
		else {
			ok = mid;
			//cout << "ok=" << ok << endl; 確認用
		}
	}

	cout << ok << endl;
	return 0;
}

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

int main() {
  int s;
  cin >> s;
  int count, ans = 0;
  for(int i = 0; i < 1000000; i++) {
    if( s == 4 || s == 2 || s == 1 ) {
      ans = i;
      break;
    }    
    if(s%2 == 0) {
      s = s/2;
    }
    else {
      s = 3*s + 1;
    }

  }
  cout << ans + 4 << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(10000000)

N, K = map(int, raw_input().split())

x = map(int, raw_input().split())

ans = 10 ** 18

for i in range(N - K + 1):
    p1 = x[i]
    p2 = x[i + K - 1]
    if p1 * p2 >= 0:
        ans = min(ans, max(abs(p1), abs(p2)))
    else:
        ans = min(ans, abs(p1) + abs(p2) + min(abs(p1), abs(p2)))

print ans

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

int main()
{
    int n, k;
    cin >> n >> k;
    int h[n];
    long long cnt = 0;
    for (int i = 0; i < n; i++) cin >> h[i];
    sort(h, h+n);
    for (int i = 0; i <= n - 1 - k; i++) {
        cnt += h[i];
    }
    cout << cnt;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 4002, M = 2e5 + 7, MOD = 1e9 + 7;
int f[N][N], g[N][N], a[M], b[M], c[M], d[M];
LL fac[N * 2], inv[N * 2];

LL qpow(LL x, LL y){
	LL z = 1;
	while (y > 0){
		if (y % 2) z = z * x % MOD;
		x = x * x % MOD;
		y /= 2;
	}
	return z;
}
void init(){
	fac[0] = 1;
	for (int i = 1; i < 2 * N; i++) fac[i] = fac[i - 1] * i % MOD;
	inv[2 * N - 1] = qpow(fac[2 * N - 1], MOD - 2);
	for (int i = 2 * N - 2; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % MOD; 
}
LL C(int n, int m){
	return fac[n] * inv[m] % MOD * inv[n - m] % MOD;
}

int main(){
	init();
	int n; LL ans = 0;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d%d", &a[i], &b[i]);
	for (int i = 1; i <= n; i++) ans = (ans - C(2 * (a[i] + b[i]), 2 * a[i]) + MOD) % MOD;
	for (int i = 1; i <= n; i++){
		c[i] = -a[i] + 2000;
		d[i] = -b[i] + 2000;
		a[i] += 2000;
		b[i] += 2000;
	}
	for (int i = 1; i <= n; i++) f[c[i]][d[i]] ++, g[a[i]][b[i]] ++;
	for (int i = 0; i <= 4000; i++){
		for (int j = 0; j <= 4000; j++){
			if (i > 0) f[i][j] += f[i - 1][j];
			if (j > 0) f[i][j] += f[i][j - 1];
			f[i][j] %= MOD;
			ans = (ans + 1LL * g[i][j] * f[i][j] % MOD) % MOD;
		}
	}	
	printf("%lld", ans * qpow(2, MOD - 2) % MOD);
	return 0;
}

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    ll n;
    cin >> n;
    vector<pair<string, PII>> v(n);
    REP(i, n) {
        string s;
        ll p;
        cin >> s >> p;
        v[i] = make_pair(s, PII(-p, i));
    }
    sort(ALL(v));

    REP(i, n) cout << v[i].second.second+1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <queue>
#include <set>
#include <iostream>
#include <iomanip>
using namespace std;
typedef long long LL;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

int main(){
    int n;
    cin >> n;
    vector<LL> a(n);
    REP(i,n)cin>>a[i];

    int count = n - 1;
    while( count >= 0){
        cout << a[count] << " ";
        count -= 2;
    }

    count = (count==-2)? 1:0;
    while(count < n){
        cout << a[count] << " ";
        count+=2;
    }

    return 0;

}

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

using namespace std;

int n;
vector<int> sushi;
vector<double> precomp;
vector<vector<vector<double>>> dp;

double count() {
	double k=0;
	for(int i=0; i<n; i++) {
		if(sushi[i]>0)
			k++;
	}
	return k;
}

double func(int a, int b, int c) {
	double k = a+b+c;
	if(a<0||b<0||c<0||a>n||b>n||c>n)
		return 0;
	if(k==0)
		return 0;
	if(dp[a][b][c]!=-1)
		return dp[a][b][c];

	double ans = precomp[k];
	// cout<<ans<<" " <<a<<" "<<b<<" "<<c<<endl;
	ans+=(a/k)*func(a-1,b,c);
	ans+=(b/k)*func(a+1,b-1,c);
	ans+=(c/k)*func(a,b+1,c-1);

	dp[a][b][c] = ans;
	return ans;
}

// state for dp no. of 1, no. of 2, no. of 3

int main() {
	cin>>n;

	sushi.resize(n);
	precomp.resize(n+1,0);
	dp.resize(n+1, vector<vector<double>>(n+1, vector<double>(n+1,-1)));
	int a=0,b=0,c=0;
	for(int i=0; i<n; i++) {
		cin>>sushi[i];
		if(sushi[i]==1)
			a++;
		else if(sushi[i]==2)
			b++;
		else
			c++;
	}

	for(int i=1; i<=n; i++) {
		precomp[i] = ((double)n)/i;
	}
	// cout<<" " <<a<<" "<<b<<" "<<c<<endl;

	cout<<fixed<<setprecision(10)<<func(a,b,c)<<endl;
}

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

#define INF 1 << 30
#define FIN(S) cout << S << endl
#define FOR(i,a) FORS(i, 0, a)
#define FORS(i, a, b) for(int i = a; i < (int)(b); i++)
#define TEST cout << "test" << endl
#define debug(x) cout << #x << ": " << x << endl
#define P pair<int, int>
#define PQ priority_queue
#define PB push_back
#define MP make_pair
#define ALL(obj) (obj).begin(), (obj).end()

typedef long long ll;

using namespace std;

int StrToInt(string s){stringstream ss;ss << s;int val;ss >> val;return val;}
string IntToStr(int i){stringstream ss;ss << i;return ss.str();}

int n;
vector<ll> v;

int main(){
	cin >> n;
	FOR(i, n){
		int in;
		cin >> in;
		v.PB(in);
	}

	sort(ALL(v), greater<int>());

	ll l = 0, ans = 0;
	FOR(i, n - 1){
		if(v[i] == v[i + 1]){
			if(l > 0){
				ans = l*v[i];
				break;
			}
			l = v[i + 1];
			i++;
		}
	}

	cout << ans << endl;

	return 0;
}


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


int main(){
    int a,b,x;
    cin>>a>>b>>x;
    if (a<=x && x<=a+b) {
        cout<<"YES";
    } else {
        cout<<"NO";
    }
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));
  rep(i, n - 1) if (a[i] == a[i + 1]) {
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;
}


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

unordered_map<long, long> mp;
unordered_map<long, long> mp2;

int main()
{
    int N;
    int A[100];
    int B[100];
    long kane = 1000;
    long kabu = 0;

    cin >> N;

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

    for (int i = 0; i < N - 1; i++)
    {
        kabu = 0;
        if (A[i] < A[i + 1])
        { //買う
            kabu = kane / A[i];
        }
        kane += kabu * (A[i + 1] - A[i]);
    }

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

Measured memory_bytes: 3580
def main():
  a,b,k = list(map(int,input().split()))
  minlist=[]
  maxlist=[]
  ans=[]
  for i in range(0,k):
    if b-i>=a:
      minlist.append(a+i)
    if b-i>=a+k:
      maxlist.insert(0,b-i)
  ans=minlist+maxlist
  set(ans)
  for i in range(0,len(ans)):
    print(ans[i])
main()


Measured memory_bytes: 9176
#include <cstdio>

int main() {
    char a,b,c;
    scanf("%c%c%c", &a, &b, &c);
    if (a == '1') a = '9';
    else a = '1';
    if (b == '1') b = '9';
    else b = '1';
    if (c == '1') c = '9';
    else c = '1';
    printf("%c%c%c\n", a,b,c);
    return 0;
}


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

using namespace std;

int main() {
  int n, k;
  int l[50];
  cin >> n >> k;
  for (int i=0; i<n; ++i) cin >> l[i];

  sort(l, l+n, greater<int>());

  int ans = 0;
  for (int i=0; i<k; ++i) {
    ans += l[i];
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    nums = list(map(lambda x: int(x), inputs[0]))
    OPS = ["+", "-"]
    for temp_op1 in OPS:
        for temp_op2 in OPS:
            for temp_op3 in OPS:
                sum = nums[0]
                if temp_op1 == "+":
                    sum += nums[1]
                else:
                    sum -= nums[1]

                if temp_op2 == "+":
                    sum += nums[2]
                else:
                    sum -= nums[2]

                if temp_op3 == "+":
                    sum += nums[3]
                else:
                    sum -= nums[3]

                if sum == 7:
                    return "%d%s%d%s%d%s%d=7" % (
                        nums[0],
                        temp_op1,
                        nums[1],
                        temp_op2,
                        nums[2],
                        temp_op3,
                        nums[3],
                    )
    return ""


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)


Measured memory_bytes: 3064
import { createInterface } from 'readline';

const main = (lines: string[]) => {
  console.log(solve(lines));
};

export const solve = (lines: string[]): string => {
  const S = parseLines(lines);

  if (S === 'Sunny') {
    return 'Cloudy';
  }
  if (S === 'Cloudy') {
    return 'Rainy';
  }

  return 'Sunny';
};

const parseLines = (lines: string[]) => {
  const obj = lines[0];
  debug(obj);
  return obj;
};

const debug = (message?: any, ...optionalParams: any[]) => {
  if (!!process.env.LOCAL_DEBUG) {
    console.log(message, ...optionalParams);
  }
};

if (!process.env.LOCAL_DEBUG) {
  const { stdin: input, stdout: output } = process;
  input.resume();
  input.setEncoding('utf8');
  const lines: string[] = [];
  createInterface({ input, output })
    .on('line', line => lines.push(line))
    .on('close', () => main(lines));
}


Measured memory_bytes: 7628
#include<bits/stdc++.h>
#define pb push_back
#define pf push_front
#define re(i , n) for(Long i = 0; i < (Long)n ; i++)
#define rer(i, a, b) for (Long i = a, to = b; i < to; i++)
 
using namespace std;
typedef long long Long;
const Long MX=2e5 + 1;
const Long MOD=1000000007;
const Long MX2=9223372036854775806;


int main(){
	ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	Long n,k;cin>>n>>k;
	vector<Long> v(n,0);
	while(k--){
		Long d;cin>>d;
		re(i,d){
			Long l;
			cin>>l;
			v[l-1]++;
		}
	}
	Long conta=0;
	re(i,v.size()){
		if(v[i]==0){
			conta++;
		}
	}
	cout<<conta;
}

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

int q;
int a[100010];
vector<int> p;

bool prime(int n){
	bool f = true;
	for(int i=0; i<p.size() && p[i]*p[i]<=n; ++i)
		if(n % p[i] == 0)
			f = false;
	if(f) p.push_back(n);
	return f;
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> q;
	p.push_back(2);
	for(int i=3; i<100000; ++i){
		if(i % 2 == 0) continue;
		prime(i);
	}
	for(int i=3; i<100000; ++i)
		if(i % 2 == 1 && prime(i) && prime((i+1)/2))
			a[i] = 1;
	for(int i=1; i<100000; ++i)
		a[i] += a[i-1];
	while(q--){
		int l, r;
		cin >> l >> r;
		cout << a[r] - a[l-1] << "\n";
	}
}

Measured memory_bytes: 1280
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>

using namespace std;
#define MAX 100000

int main(){
    int D;

    cin >> D;

    int dif = 25 - D;

    cout << "Christmas";
    int i = 0;
    for (int i = 0; i < dif; i++){
        cout << " Eve";
    }
    cout << endl;    

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<lli, lli> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type> >
#define memst(a,b) memset(a,b,sizeof(a))

vector<vector<int>> r;
vector<bool> u;

void dfs(int k){
	u[k] = true;
	rep(i, r[k].size()) if(u[r[k][i]] == false) dfs(r[k][i]);
	return;
}

int main(void){
	lli n, m;
	cin >> n >> m;
	vector<vector<mp>> v(n);
	r.resize(n); u.assign(n, false);
	rep(i, m){
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		v[a].push_back(mp(b, c));
		r[b].push_back(a);
	}

	dfs(n-1);
	vector<vector<mp>> t(n);
	rep(i, n) if(u[i]){
		rep(j, v[i].size()) if(u[v[i][j].fir]){
			t[i].push_back(v[i][j]);
		}
	}
	
	vector<lli> c(n, -LINF);
	pque(mp) q; q.push(mp(0, 0));
	while(!q.empty()){
		mp p = q.top(); q.pop();
		if(c[p.sec] > p.fir) continue;
		if(m-- < 0) {cout << "inf" << endl; return 0;}
		rep(i, t[p.sec].size()) if(c[t[p.sec][i].fir] < p.fir + t[p.sec][i].sec){
			c[t[p.sec][i].fir] = p.fir + t[p.sec][i].sec;
			q.push(mp(c[t[p.sec][i].fir], t[p.sec][i].fir));
		}
	}

	cout << c[n-1] << endl;
	
	return 0;
}

Measured memory_bytes: 512
import heapq

N, M = map(int, input().split())
vA = list(map(int, input().split()))

vQ = []
for a in vA:
    heapq.heappush(vQ, -a)

res = 0
for _ in range(M):
    if not vQ:
        break
    # heappop は 最小値を取得する
    ma = heapq.heappop(vQ)
    ma = -ma//2
    heapq.heappush(vQ, -ma)

print(-sum(vQ))


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


int main()
{
    int H, W;
    cin >> H >> W;
    vector<vector<int>> a(H, vector<int>(W));
    for( int i = 0; i < H; ++i ){
        for( int j = 0; j < W; ++j ) cin >> a[i][j];
    }


    vector<vector<int>> ans_list;
    for( int i = 0; i < H; ++i ){
        for( int j = 0; j < W; ++j ){
            if( a[i][j]%2 == 1 ){
                --a[i][j];
                if( j+1 < W ){
                    ++a[i][j+1];
                    ans_list.push_back( {i,j,i,j+1} ); 
                }
                if( j == W-1 and i+1 < H ){
                    ++a[i+1][j];
                    ans_list.push_back( {i,j,i+1,j} );
                } 
            }
        }
    }

    cout << ans_list.size() << endl;
    for( auto v: ans_list ){
        for( int i = 0; i < 4; ++i ){
            if( i == 3 ) cout << v[i]+1 << endl;
            else cout << v[i]+1 << " ";
        }
    } 

    return 0;
}

Measured memory_bytes: 9904
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int w, h, n;
    cin >> w >> h >> n;

    vector<int> v(w);
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        v[x] = max(v[x], y);
    }
    for (int i = w - 1; i > 0; i--) v[i - 1] = max(v[i - 1], v[i]);

    int ret = min(w - 1, h - 1);
    for (int i = 0; i < w - 1; i++) ret = min(ret, i + v[i + 1]);

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


Measured memory_bytes: 3108
A, B, C = map(int, input().split())
K = int(input())

k = 0
while True:
    if A < B < C:
        print("Yes")
        break
    else:
        if k == K:
            print("No")
            break

        if B <= A:
            B *= 2
        elif C <= B:
            C *= 2
        k += 1

Measured memory_bytes: 9180
#include <iostream>
#include <set>
#include <string>
using namespace std;
 
int main(){
  int N;
  int count=0;
  string s;
  set<string> cont;
  cin >> N;
  for(int i=0; i<N; i++) {
    cin >> s;
    if(cont.find(s)==cont.end()){
      cont.insert(s);
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 15660
#include<cstdio>
#include<queue>
using namespace std;

int n;
int p[8], q[8], fac[9];

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", &p[i]);
    for (int i = 0; i < n; i++) scanf("%d", &q[i]);
    fac[0] = 1;
    for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i;
     
    int ans1 = 1, ans2 = 1;
    queue<int> que1, que2;
    for (int i = 0; i < n; i++) {
        que1.push(i + 1);
        que2.push(i + 1);
    }
    for (int i = n; i > 1; i--) {
        for (int j = 0; j < i; j++) {
            int a = que1.front(); que1.pop();
            int b = que2.front(); que2.pop();
            if (a < p[n - i]) ans1 += fac[i - 1];
            if (b < q[n - i]) ans2 += fac[i - 1];
            if (a != p[n - i]) que1.push(a);
            if (b != q[n - i]) que2.push(b);
        }
    }

    printf("%d\n", (ans1 < ans2) ? ans2 - ans1 : ans1 - ans2);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
void inline swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
void inline swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }

int n;
vi a;
int main()
{

	cin >> n;
	a.resize(n + 1);

	REP1C(i, n)
		cin >> a[i];

	int tmp{ 1 };
	int ans{ 0 };
	vector<bool> flag(n + 1, false);


	while (!flag[tmp])
	{
		flag[tmp] = true;
		tmp = a[tmp];
		++ans;
		if (tmp == 2)
			break;
	}

	if (tmp == 2)
		cout << ans << endl;
	else
		cout << -1 << endl;

}


Measured memory_bytes: 640
#include <stdio.h>

int main(void){
  char S[11];
  int i=0,res=0;
  scanf("%s",S);
  for(int i=0;S[i]!='\0';i++){
    int sum=0;
    for(int j=i;S[j]!='\0';j++){
      if(S[j]=='A' || S[j]=='C' || S[j]=='G' || S[j]=='T') sum++;
      else break;
    }
    if(sum>res) res=sum;
  }
  printf("%d\n",res);
  return 0;
}

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

int main()
{
    ll A, B, C, K;
    cin >> A >> B >> C >> K;
    ll ans = 0;
    if (K <= A) {
        ans = K;
    }
    else if ((K <= A + B)&&(K>A)) {
        ans = A;
    }
    else {
        ans = A - (K - (A + B));
    }
    cout << ans << endl;
    return 0;
    
}


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

const ll INF = 1LL << 60;

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


int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    ll dp[n+10];
    rep(i, n) dp[i] = INF;
    dp[0] = 0;
    for (int i = 1; i < n; i++) {
        for (int j = 1; j <= k; j++) {
            if (i -j >= 0) chmin(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
        }
    }

    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 4412