akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

    int N;
    cin >> N;
    vector<int> x(N), y(N), h(N);
    for (int i = 0; i < N; i++) cin >> x[i] >> y[i] >> h[i];
    for (int cx = 0; cx <= 100; cx++) {
        for (int cy = 0; cy <= 100; cy++) {
            int H = -1;
            bool ok = true;
            for (int i = 0; i < N; i++) {
                if (h[i] > 0) {
                    int tmp = h[i] + abs(x[i] - cx) + abs(y[i] - cy);
                    if (H == -1) H = tmp;
                    else if (H != tmp) {
                        ok = false;
                        break;
                    }
                }
            }
            if (!ok) continue;
            for (int i = 0; i < N; i++) {
                if (h[i] == 0) {
                    if (H - abs(x[i] - cx) - abs(y[i] - cy) > 0) {
                        ok = false;
                        break;
                    }
                }
            }
            if (ok) {
                cout << cx << " " << cy << " " << H << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3608
#include<iostream>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<time.h> 
#define debug(a) cout << "*" << a << "*" << endl
#define ls	(k << 1)
#define rs	((k << 1) | 1)
#define mid	((l + r) >> 1)
using namespace std;
typedef long long ll;
struct node
{
	int x, y;
	friend bool operator < (node a, node b)
	{
		if (a.x != b.x) return a.x < b.x;
		return a.y < b.y;	
	}	
};
node a[105], b[105];
int n, sum;
bool used[105];
int main()
{
	while (~scanf("%d", &n))
	{
		memset(used, 0, sizeof(used));
		sum = 0;
		for (int i = 0; i < n; i++)	scanf("%d%d", &b[i].x, &b[i].y);
		for (int i = 0; i < n; i++)	scanf("%d%d", &a[i].x, &a[i].y);
		sort(a, a + n);
		sort(b, b + n);
		for (int i = 0; i < n; i++)
		{
			int mx = -1;
			for (int j = 0; j < n; j++)
			{
				if (b[j].x >= a[i].x)	break;
				if (!used[j] && b[j].y < a[i].y && (mx == -1 || b[j].y > b[mx].y))
					mx = j;
			}
			if (mx != -1)
			{
				used[mx] = true;
				sum++;
			}
		}
		printf("%d\n", sum);
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
using Graph=vector<vector<int>>;

int gcd(lint x, lint y){
  return y==0 ? x:gcd(y,x % y);
}

int digsum(int n) {
  int res = 0;
  while(n > 0) {
    res += n%10;
    n /= 10;
  }
  return res;
}

int dignum(int n) {
  int res = 0;
  while(n > 0) {
    res++;
    n /= 10;
  }
  return res;
}

int stringcount(string s, char c) {
  return count(s.cbegin(), s.cend(), c);
}

int lcm(lint x, lint y){
  return x/ gcd(x, y) * y;
}

int combi(int n, int r){
  int num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

int main(){
  int n;
  cin>>n;
  map<int,int> m;

  rep(i,n){
    int j;cin>>j;
    m[j]=i;
  }
  for(int i=1;i<=n;i++){
    cout<<m[i]+1<<" ";
  }
}

Measured memory_bytes: 5504
def resolve():
    n = int(input())
    h = list(map(int, input().split()))

    cost = [float("inf")]*n
    cost[0] = 0
    for i in range(n-2):
        cost[i+1] = min(cost[i+1], cost[i] + abs(h[i+1]-h[i]))
        cost[i+2] = min(cost[i+2], cost[i] + abs(h[i+2]-h[i]))
    cost[n-1] = min(cost[n-1], cost[n-2] + abs(h[n-2]-h[n-1]))

    print(cost[n-1])
resolve()

Measured memory_bytes: 52208
unittest
{
	assert( [ "3 2", "4 1 5" ].parse.expand.solve == 3 );
	assert( [ "13 17", "29 7 5 7 9 51 7 13 8 55 42 9 81" ].parse.expand.solve == 6 );
	assert( [
		"10 400000000",
		"1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000"
	].parse.expand.solve == 25 );
}



import std.algorithm;
import std.conv;
import std.functional;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nm = input.front.split.to!( long[] );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( nm[ 1 ], as );
}

auto solve( long m, long[] as )
{
	// 累積和をMで割った余りの配列に変換
	auto c = 0L;
	foreach( ref a; as )
	{
		c += a;
		a = c % m;
	}
	
	// 「自分 - 自分より左にある余りが同じ値」でMの倍数の区間になるので、
	// 自分より左にある余りが同じ値の数をカウントすれば良い。
	auto ans = 0L;
	long[ long ] cs;
	cs[ 0 ]++;		// 余りが0のやつは自分のみの区間もMの倍数になるので加算しておく必要がある
	foreach( a; as )
	{
		if( a !in cs ) cs[ a ] = 0;
		ans += cs[ a ];
		cs[ a ]++;
	}
	
	return ans;
}


Measured memory_bytes: 8400
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

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

typedef long long ll;

// 4,8方向に探索する際に用いる配列
int dx[4] = { 0,  0, 1, -1 };
int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

int main()
{
	int H, W;
	cin >> H >> W;

	vector<vector<char>> table(H, vector<char>(W));

	for (int y = 0; y < H; y++)
	{
		for (int x = 0; x < W; x++)
		{
			cin >> table[y][x];
		}
	}

	for (int y = 0; y < H; y++)
	{
		for (int x = 0; x < W; x++)
		{
			if (table[y][x] == '#')
			{
				int cnt = 0;

				for (int k = 0; k < 4; k++)
				{
					int vy =  y + dy[k];
					int vx =  x + dx[k];

					if (0 <= vy && vy < H && 0 <= vx && vx < W && table[vy][vx] == '#')
					{
						cnt++;
					}
				}
				if (cnt == 0)
				{
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 256
//ref:-  https://codeforces.com/blog/entry/78195
//also see atcoder official editorial
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main ()
{
 ll n,x,y;
 cin>>n;
 ll a[n],b[n];
 for(ll i=0;i<n;i++)
 cin>>a[i]>>b[i];
 sort(a,a+n);
 sort(b,b+n);
 if(n%2)
 {
     x=a[n/2];
     y=b[n/2];
 }
 else
 {
     x=a[n/2]+a[n/2-1];
     y=b[n/2]+b[n/2-1];
 }
 cout<<(y-x)+1;
 return 0;
}

Measured memory_bytes: 6752
#include <bits/stdc++.h>
#include <cstdlib> // abs(x-y)
#include <iomanip> // 出力の桁数指定
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;

int main() {
  long h;
  cin >> h;
  
  if (h == 1)
    cout << 1 << endl;
  
  else {
    long n = 0;
    while (h > 1) {
      h /= 2;
      n++;
    }
    long ans = 0;
    rep (i, 0, n+1) {
      long a = pow(2, i);
      ans += a;
    }
    cout << ans << endl;
    
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define sp std::fixed<<std::setprecision
#define MOD 1000000007
#define MAX 1e18
#define N 1000005
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n , a , b;
    cin >> n >> a >> b;
    cout << min( n * a , b ) << endl;
    return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL n,t,minu[100010],ans;

LL fastpow(LL x,LL a)
{
	LL res=x,ret=1;
	while(a>0)
	{
		if((a&1)==1) ret=ret*res%MOD;
		a>>=1;
		res=res*res%MOD;
	}
	return ret;
}

int main()
{
	cin>>n>>t;
	for(LL i=t;i>0;i--)
	{
		LL num=t/i,val=(fastpow(num,n)-minu[i]+MOD)%MOD;
		ans=(ans+val*i)%MOD;
		for(LL j=1;j*j<=i;j++)
		{
			if(i%j==0)
			{
				if(i/j!=j) minu[i/j]=(minu[i/j]+val)%MOD;
				minu[j]=(minu[j]+val)%MOD;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
  ll n ;
  cin >> n  ;
  ll A[n] ;
  rep(i,n) cin >> A[i] ;
  ll ans = 0 ;
  rep(i,n-1){
    if( A[i] < A[i+1] )continue ;
    else
    {
     ans += A[i] - A[i+1] ;
     A[i+1] = A[i] ;
    }
  }
  cout <<ans <<endl;
} 


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

const ll MOD = 1000000007LL;

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

    sort(a.rbegin(), a.rend());

    ll ans = 0;
    int t = n - 1;
    rep(i, n){
        int lim = 2;
        if(i == 0) lim = 1;
        rep(j, lim){
            if(t > 0){
                ans += (ll)a[i];
                t--;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4048
def is_prime(x):
    answer = True
    if x == 1:
        answer = False
    elif x == 2:
        answer = True
    elif x % 2 == 0:
        answer = False
    else:
        i = 3
        while i <= x ** 0.5:
            if x % i == 0:
                answer = False
                break
            i += 1
    return answer

if __name__ == "__main__":
    n = int(input())
    count = 0
    for _ in range(n):
        x = int(input())
        if is_prime(x):
            count += 1
        
    print(count)



Measured memory_bytes: 5672
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n,m;
    cin>>n>>m;
    vector<int> yaku;
    for(int i=1; i*i<=m; ++i){
        if(m%i==0){
            if(m==i*i) yaku.push_back(i);
            else{
                yaku.push_back(i); yaku.push_back(m/i);
            }
        }
    }
    sort(etob(yaku));
    int ans;
    for(auto& v: yaku){
        if(v>=n) ans=v;
        else break;
    }
    cout<<m/ans<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;

namespace ABC135A
{
    class Program
    {
        static void Main(string[] args)
        {
            var A = RInt;
            var B = RInt;
            var sum = A + B;
            if (sum % 2 == 0) Console.WriteLine(sum / 2);
            else Console.WriteLine("IMPOSSIBLE");

        }


    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String RNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int RInt => int.Parse(RNext());
        public static long RLong => long.Parse(RNext());
        public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
        public static string RString => RNext();
        //以下未テスト
        public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
        public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
        public static char[][] RMap(int h) => Enumerable.Repeat(0, h).Select(x => Console.ReadLine().ToCharArray()).ToArray();
    }

    static class Debug
    {
        static public void Draw2D<T>(T[,] map, int mode = 1)
        {
#if DEBUG
            int W = map.GetLength(0);
            int H = map.GetLength(1);

            string[,] map2 = new string[W + 1, H + 1];
            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map2[i, j] = 0.ToString();
                    else if (i == 0) map2[i, j] = (j - 1).ToString();
                    else if (j == 0) map2[i, j] = (i - 1).ToString();
                    else map2[i, j] = map[i - 1, j - 1].ToString();
                }
            }

            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (mode == 0) Console.Write(map2[i, j].Last());
                    if (mode == 1) Console.Write(map2[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
#endif
        }

        public static void Draw1D<T>(T[] array, int mode = 0)
        {
#if DEBUG
            Console.WriteLine(string.Join(" ", array));
#endif
        }
    }
}


Measured memory_bytes: 11348
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5000;
ll arr[N];
int main(){
    ll a,b;
    cin>>a>>b;
    int index=0;
    for(ll i=a;i<=b;i++){
        if(index>=4038){
            break;
        }
        arr[index]=i%2019;
        index++;
    }
    ll minn=2020;
    for(int i=0;i<index;i++){
        for(int j=0;j<index;j++){
            if(i!=j){
                ll x=arr[i]*arr[j]%2019;
                if(x<minn){
                    minn=x;
                }
            }
        }
    }
    cout<<minn<<endl;
    //system("pause");
}

Measured memory_bytes: 256
def euc(a,b)
  if a>b
    a^=b
    b^=a
    a^=b
  end

  return a if b%a==0
  return euc(a,b%a)
end

n=gets.chomp.to_i
a=gets.chomp.split(" ").map{|s| s.to_i}
ans=euc(a[0],a[1])
for i in 0..n-1
  ans=euc(ans,a[i])
end
p ans


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

	while(1){
	int H, W;
	cin>>H>>W;
	if(H == 0 && W == 0) break;
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
			if(i % 2 == 0 && j % 2 == 0 || i % 2 == 1 && j % 2 ==1) cout<<"#";
			else cout<<".";
			}
		cout<<endl;
		}
	cout<<endl;
	}

	return 0;
}


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

bool is_prime(int n) {
    if (n < 2) return false;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return true;
}

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

    bool not_found = true;
    while (not_found) {
        not_found = !is_prime(X);
        X++;
    }

    cout << X - 1;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define ff(i, c, n) for (ll i = c; i < n; i++)
#define fr(i, c, n) for (ll i = c; i >= n; --i)
#define INF 1e9 + 7

ll modpow(ll a, ll b, ll c)
{ //a^b%c in O(logb)
	ll res = 1;
	while (b > 0)
	{
		if (b & 1)
		{
			res = (res * a) % c;
		}
		a = (a * a) % c;
		b >>= 1;
	}
	return res;
}
ll modinv(ll m, ll n)
{ //modular inverse of n w.r.t m provided 1<=n<=(m-1) in O(logn) and m is prime
	ll inv[n + 1];
	inv[1] = 1;
	for (int i = 2; i < n + 1; ++i)
		inv[i] = (m - (m / i) * inv[m % i] % m) % m;
	return inv[n];
}

//a+b=a^b+2*(a&b)
int main()
{
	// your code goes here
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll x;
	cin>>x;
	ff(i,-120,121){
		ff(j,i,121){
			if(pow(j,5)-pow(i,5)==x){cout<<j<<" "<<i;return 0;}
		}
	}


	return 0;
}


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

using namespace std;

bool odd_count(int i){

    int digit_count = 0;
    while(i){
        i = i/10;
        digit_count++;
    }

    if (digit_count % 2 == 1){
        return true;
    }


    return false;
}

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

    int count = 0;
    for (int i = 1; i<=n; i++){
        if (odd_count(i)){
            count++;
        }
    }

    cout<<count<<endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
map<ll, ll> mp;
int main() {
    int n;
    ll x, sum = 0, ans = 0;
    scanf("%d", &n);
    mp[sum]++;
    for (int i = 0; i < n; i++) {
        scanf("%lld", &x);
        sum += x;
        mp[sum]++;
    }
    for (auto i : mp) {
        ans += i.second * (i.second - 1) / 2;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 12800
def main():
    ABCD = input()
    A = int(ABCD[0])
    B = int(ABCD[1])
    C = int(ABCD[2])
    D = int(ABCD[3])
    for i in range(2):
        for j in range(2):
            for k in range(2):
                ans = 0
                op1 = ""
                op2 = ""
                op3 = ""
                if i % 2 == 0:
                    ans = A + B
                    op1 = "+"
                else:
                    ans = A - B
                    op1 = "-"
                
                if j % 2 == 0:
                    ans = ans + C
                    op2 = "+"
                else:
                    ans = ans - C
                    op2 = "-"
                
                if k % 2 == 0:
                    ans = ans + D
                    op3 = "+"
                else:
                    ans = ans - D
                    op3 = "-"

                if ans == 7:
                    print("{}{}{}{}{}{}{}=7".format(A, op1, B, op2, C, op3, D))
                    exit()
if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
#include<string>
#include<stack>
#include<list>
#include<set>
#define mod 1000000007

using namespace std;

#define DEBUG_FLAG

#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#ifdef DEBUG_FLAG
    #define dbgout(fmt, ...) fprintf(stderr, "\033[1;33mDEBUG(%s:%d):\t\033[0m" fmt, __func__, __LINE__, ##__VA_ARGS__)
#else
    #define dbgout(fmt, ...) 
#endif

int main(void)
{
    int A, B, X;
    cin >> A >> B;
    for (int i = 1; i <= 1000; i++) {
        int j = i * 0.1, k = i * 0.08;
        if (j == B && k == A) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
import math
ini = lambda : int(input())
inm = lambda : map(int,input().split())
inl = lambda : list(map(int,input().split()))
gcd = lambda x,y : gcd(y,x%y) if x%y else y
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
mod = 10**9 + 7

#maincode-------------------------------------------------

n = ini()
a = inl()
A = 10**6+1
b = [0] * A
ans = "pairwise coprime"

for i in a: 
    b[i] += 1

for i in range(2,A): 
    cnt = 0
    for j in range(i,A,i):
        cnt += b[j]
    if cnt >= 2:
        ans = "setwise coprime"
        break

if ans == "setwise coprime":
    g = a[0]
    for i in range(1,n):
        g = gcd(a[i],g)
    if g != 1:
        ans = "not coprime"

print(ans)

Measured memory_bytes: 133564
using System;
class Program2
{
    static void Main(string[] args)
    {
        //入力
        var n = double.Parse(Console.ReadLine());
        double answer = 0;

        //探す
        for (int i = 0; i < n; i++)
        {
            if (n < Math.Pow(2, i))
            {
                answer = Math.Pow(2, i - 1);
                break;
            }
        }

        //出力
        if (n > 1)
        {
            Console.WriteLine(answer);
        }
        else
        {
            Console.WriteLine(n);
        }
    }
}


Measured memory_bytes: 11092
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>
#include<queue>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))

int main(){
	char s[101],o[900];
	int p,l;
	while(~scanf("%s",s)){
		p=0;
		l=strlen(s);
		rep(i,l){
			if(s[i]=='@'){
				int c=s[i+1]-'0';
				rep(j,c)o[i+j+p]=s[i+2];
				p+=c-3;
				i+=2;
			}
			else o[i+p]=s[i];
		}
		o[l+p]=0;
		puts(o);
	}
	
	return 0;
}

Measured memory_bytes: 1116
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
long long MOD = 1000000007;

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

long long factorial(long long n) {
	if (n > 1) {
		return (n * factorial(n - 1)) % MOD;
	}
	else {
		return 1;
	}
}

long long combination(long long n, long long k) {
	long long ans = (factorial(n) * modinv(factorial(n - k), MOD)) % MOD;
	ans = (ans * modinv(factorial(k), MOD)) % MOD;

	return ans;
}

int main() {
	long long n, k;
	
	cin >> n >> k;
	
	for (long long i = 1; i <= k; i++) {

		if (n - k + 1 >= i) {
			long long ans = (combination(n - k + 1, i) * combination(k - 1, i - 1)) % MOD;
			cout << ans << endl;
		}
		else {
			cout << 0 << endl;
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	long long a,b;
	cin>>a>>b;
	ll c = b/2019;
	ll m = c*2019;
	if(a<=m)
	{
		cout<<0<<endl;
	}
	else
	{
		ll k = min(a+2019,b);
		ll mi = 1e17;
		for(ll i=a;i<=k;i++)
		{
			for(ll j=i+1;j<=k;j++)
			{
				ll c;
				c = (i%2019)*(j%2019);
				c %= 2019;
				mi = min(c,mi);
			}
		}
		cout<<mi<<endl;	 
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    vector<vector<int>> dp(N, vector<int>(N+1, 0));

    for (int i = N-2; i >= 0; i--) {
        for (int j = N-1 ; j > i; j--){
            if(S[i] == S[j]){
                dp[i][j] = dp[i+1][j+1]+1;
                // if(j-dp[i+1][j+1]>0)
                //     dp[i][j] = dp[i+1][j+1]+1;
                // else
                //     dp[i][j] = dp[i+1][j+1]
            }
        }
    }

    int ans = 0;
    for (int l = 0; l < N; l++) {
        for (int r = l+1; r < N; r++) 
            ans = max(ans, min(r-l, dp[l][r]));
    }
    pr(ans);
}

Measured memory_bytes: 98176
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		 Scanner sc = new Scanner(System.in);
	     String S = sc.nextLine();
	     String abc ="abcdefghijklmnopqrstuvwxyz";
	     String ans = "None";
	     char C;
	     String com;
	     
		 for(int i=0; i< abc.length(); i++){
		 	com =  String.valueOf(abc.charAt(i));
	     	if (!S.contains(com)){
	     		ans = com;
	     		break;
	     	}
	     }
	     System.out.println(ans);
	}
}


Measured memory_bytes: 27460
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include "bits/stdc++.h"

using namespace std;

typedef unsigned long long ll;
typedef int                     integer;
#define int                     long long
#define ii                      pair<int,int>
#define vii                     vector<pair<int,int>>
#define vi                      vector<int>
#define vvi                     vector<vector<int>>
#define f(a,b,c)                for(int a=b;a<c;a++)
#define s(x)                    in>>x
#define s2(x,y)                 in>>x>>y
#define s3(x,y,z)               in>>x>>y>>z
#define s4(x,y,z,w)             in>>x>>y>>z>>w
#define p(x)                    out<<x<<endl
#define p2(x,y)                 out<<x<<" "<<y<<endl
#define pl(x)                   out<<x
#define p2l(x,y)                out<<x<<" "<<y
#define range(v)                v.begin(),v.end()
#define rst(x)                  memset(x, -1, sizeof(x))
#define UNVISITED               -1
#define VISITED                 0
#define EXPLORED                2


void ssolve(std::istream& in, std::ostream& out){
    int n, d;
    s2(n, d);
    int cnt = 0;
    f(i, 0, n){
        int x, y;
        s2(x, y);
        if(sqrt(x * x + y * y) <= d){cnt++;}
    }
    p(cnt);
    return;
}

class BDistanceEditorial {
public:
void solve(std::istream& in, std::ostream& out) {
    ios_base::sync_with_stdio(false);
    in.tie(0);out.tie(0);
    int t;
    int READ = 0;
    if(READ) s(t);
    else t = 1;
    while(t--){
        ssolve(in, out);
    }
}
};

integer main() {
    BDistanceEditorial solver;
    std::istream& in(std::cin);
     std::ostream& out(std::cout);
     solver.solve(in, out);
}

Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
  ll n;
  cin>>n;
  vector<ll>arr;
  for(int i=0;i<n;i++)
  {
	ll inp;
    cin>>inp;
    arr.push_back(inp);
  }
  sort(arr.begin(),arr.end());
  ll cnt=0;
  for(int i=0;i<n;i++)
  {
    for(int j=i+1;j<n;j++)
    {
      for(int k=j+1;k<n;k++)
      {
        if((arr[i]+arr[j])>arr[k] && arr[i]!=arr[j] && arr[i]!=arr[k] && arr[j]!=arr[k])
          cnt++;
      }
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 3588
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  string S;
  cin>>S;
  map<char, char> amap;
  amap['A'] = 'T';
  amap['T'] = 'A';
  amap['G'] = 'C';
  amap['C'] = 'G';
  for(int i=0;i<S.size();++i) {
    S[i] = amap[S[i]];
  }
  cout<<S<<endl;
}



Measured memory_bytes: 3604
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        long[] a = sc.nextLongArray(n);
        Arrays.sort(a);
        int ans = n;
        for(int i = 1; i < n; i++){
            if(a[i] > a[i-1]*2){
                ans = n-i;
            }
            a[i] += a[i-1];
        }
        System.out.println(ans);
    }
}

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: 40924
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random,resource

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    a = [S() for _ in range(n)]

    c = collections.Counter(a)
    k = ['AC', 'WA', 'TLE', 'RE']
    rr = []
    for s in k:
        rr.append(f"{s} x {c[s]}")

    return JA(rr, "\n")


print(main())




Measured memory_bytes: 17968
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define CMAX(m, x)  m = max(m,x);
#define CMIN(m, x)  m = min(m,x);
#define itn int
typedef long long lint;
const int INF = 1e9;
const lint LINF = 1e18;
int main(){
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    lint sum = 0;
    if(2 * c > a + b){
        sum += a * x + b * y;
    } 
    else{
        if(x > y){
            lint suma = 2 * x * c;
            sum += 2 * y * c;
            sum += (x - y) * a;
            CMIN(sum, suma);
        }else{
            lint sumb = 2 * y * c;
            sum += 2 * x * c;
            sum += (y - x) * b;
            CMIN(sum, sumb);
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m;
int a[2521],b[2521],c[2521];
long long INF = 1000000001;
long long INFLL = (long long)INF * INF;

long long dist[1252];
int over[1252];
int main(void){
    // Here your code !
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++){
        scanf("%d%d%d",a+i,b+i,c+i);
        a[i]--;b[i]--;
    }
    for(int i=0;i<n;i++)dist[i] = -INFLL;
    dist[0] = 0;
    for(int k=0;k<=2*n;k++)for(int i=0;i<m;i++){
        if(dist[a[i]] != -INFLL && dist[b[i]] < dist[a[i]] + c[i]){
            dist[b[i]] = dist[a[i]] + c[i];
            if(k == 2*n){
                over[b[i]] = 1;
            }
        }
    }
    if(over[n-1])printf("inf\n");
    else printf("%lld\n",dist[n-1]);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        long A;
        long B;
        long C;
        try (Scanner sc = new Scanner(System.in)) {
            A = sc.nextLong();
            B = sc.nextLong();
            C = sc.nextLong();
        }

        long AmB = A % B;

        for (int i = 0; i < B; i++) {
            if ((AmB * i) % B == C) {
                System.out.println("YES");
                return;
            }
        }
        System.out.println("NO");
    }
}


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

int main(){
  string s; cin >> s ;
  bool ans = true;
  
  for(int i=0;i<s.size();i++){
    if(i%2==0){
      if(s.at(i) == 'L'){
        ans = false;
        break;
      }
    }
    else{
      if(s.at(i) == 'R'){
        ans = false;
        break;
      }
    }
  }
  
  if(ans) cout << "Yes" << endl;
  else    cout << "No"  << endl;
}

Measured memory_bytes: 384
N = 10**7


def f(x):
    return x


M = 10**5
arr = list(range(M))
for i in range(N):
    t = (i + i * i - i) % M  # 四則演算
    b = arr[t]  # 配列ランダムアクセス
    b = f(b)  # 関数呼び出し

# 答え
a = int(input())
print(a + a**2 + a**3)


Measured memory_bytes: 64976
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

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

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

	sort(h.begin(), h.end());

	int low = h[0];
	int high = h[k - 1];
	int min_value = high - low;
	for (int i = k; i < n; ++i) {
		low = h[i - k + 1];
		high = h[i];
		min_value = min(min_value, high - low);
	}

	cout << min_value << "\n";

	return 0;

}

Measured memory_bytes: 640
#include <stdio.h>

int main(void){
    int a[5000],s[5000],i,n,max_value;
    scanf("%d",&n);
    while(n > 0){
        for(i = 0; i < n; i++)
            scanf("%d",&a[i]);
        s[0] = a[0];
        for(i = 1; i < n; i++){
            s[i] = (s[i-1] > 0) ? (s[i-1] + a[i]) : a[i];
        }
        max_value = s[0];
        for(i = 1; i < n; i++){
            if(s[i] > max_value) max_value = s[i];
        }
        printf("%d\n",max_value);
        scanf("%d",&n);
    }
    return 0;
}

Measured memory_bytes: 636
#include <iostream>
#include <cmath>

main () {
    int k;
    std::cin >> k;
    if (k % 2 == 0) {
        std::cout << ((int)(std::pow ((k / 2), 2))) << std::endl;
    } else {
        std::cout << ((int)((k - 1) / 2) * ((k + 1) / 2)) << std::endl; 
    }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int H, W,i,j;
	while (1)
	{
		scanf("%d %d", &H, &W);
		if (H == 0 && W == 0)
			break;
		for ( i = 0; i < H; i++)
		{
			for ( j = 0; j < W; j++)
			{
				printf("#");
			}
			printf("\n");
		}
printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int N = cin.nextInt();

        for (int i = 0; i < 100 / 7; i++) {
            for (int j = 0; j < 100 / 4; j++) {
                if (N == (i * 7) + (j * 4)) {
                    System.out.println("Yes");
                    return;
                }
            }
        }

        System.out.println("No");
    }
}

Measured memory_bytes: 22608
#include<bits/stdc++.h>
using namespace std;
int main(){
    const int mod=998244353;
    int n,s;
    cin>>n>>s;
    int a[n];
    vector<vector<vector<long long>>>dp(n+1,vector<vector<long long>>(s+1,vector<long long>(3)));
    dp[0][0][0]=1;
    for(int i=0;i<n;i++){
        cin>>a[i];
        for(int j=0;j<=s;j++){
            dp[i+1][j][0]=(dp[i+1][j][0]+dp[i][j][0])%mod;
            dp[i+1][j][1]=(dp[i+1][j][1]+dp[i][j][0]+dp[i][j][1])%mod;
            dp[i+1][j][2]=(dp[i+1][j][2]+dp[i][j][1]+dp[i][j][2])%mod;
            if(j+a[i]<=s){
                dp[i+1][j+a[i]][1]=(dp[i+1][j+a[i]][1]+dp[i][j][0]+dp[i][j][1])%mod;
                dp[i+1][j+a[i]][2]=(dp[i+1][j+a[i]][2]+dp[i][j][0]+dp[i][j][1])%mod;
            }
        }
    }
    cout<<dp[n][s][2]<<endl;
    return 0;
}

Measured memory_bytes: 496032
import collections
cc = collections.Counter()
n,m = map(int, raw_input().split())
c = 0
r = 0


cc[c] += 1 

for ai in map(int, raw_input().split()):
	c += ai % m
	c %= m
	r += cc[c]
	cc[c] += 1
print r

Measured memory_bytes: 92160
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll=long long;
using P = pair<int,int>;
int main(){
    string T,S;
    cin >> S >> T;
    int ans =10000;
    for(int i =0;i<S.size()-T.size()+1;i++){
        int a=0;
        for(int j =0;j<T.size();j++){
            if(S[i+j]!=T[j])a++;
        }
        ans = min(ans,a);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3596
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N=1;
	while (N) {
		cin >> N;
		if (!N)break;
		VI A(N+1);
		REP(i, N+1)cin >> A[i];

		REP(i, N + 1) {
			int tmp;
			if (i > 1)tmp = A[1] - A[0];
			else tmp = A[3] - A[2];
			bool F = 1;
			REP(j, N) {
				if (i != j && j + 1 != i) {
					if (A[j + 1] - A[j] != tmp) {
						F = 0;
					}
				}
				else if (i == j)continue;
				else {
					if (j + 2 != N + 1 && A[j + 2] - A[j] != tmp) {
						F = 0;
					}
				}



			}
			if (F) {
				cout << A[i] << '\n';
				break;
			}
		}



	}

	return 0;
}




Measured memory_bytes: 3164
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define int ll
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
const int mod=998244353;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}
 
void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
}
 
int sub(int a,int b){
	a-=b;
	if(a<0){
		a+=mod;
	}
	return a;
}
 
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1){
			res=mul(res,a);
		}
		b/=2;
		a=mul(a,a);
	}
	return res;
}
 
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}
 
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
	for(auto& i:x)
		output<<i<<' ';
	return output;
}
 
const int N=500002;

int t[N*10],lazy[N*10];

void push(int v) {
    t[v*2] = min(t[v*2], lazy[v]);
    lazy[v*2] = min(lazy[v*2], lazy[v]);
    t[v*2+1] = min(t[v*2+1],lazy[v]);
    lazy[v*2+1] =min(lazy[2*v+1], lazy[v]);
    lazy[v] = 1e18;
}

void update(int v, int tl, int tr, int l, int r, int addend) {
    if (l > r) 
        return;
    if (l == tl && tr == r) {
        t[v] = min (t[v],addend);
        lazy[v] =  min(lazy[v],addend);
    } else {
        push(v);
        int tm = (tl + tr) / 2;
        update(v*2, tl, tm, l, min(r, tm), addend);
        update(v*2+1, tm+1, tr, max(l, tm+1), r, addend);
        t[v] = min(t[v*2], t[v*2+1]);
    }
}

int query(int v, int tl, int tr, int l, int r) {
    if (l > r)
        return 1e18;
    if (l <= tl && tr <= r)
        return t[v];
    push(v);
    int tm = (tl + tr) / 2;
    return min(query(v*2, tl, tm, l, min(r, tm)), 
               query(v*2+1, tm+1, tr, max(l, tm+1), r));
}

void solve(){
	int n,m;
	cin>>n>>m;
	vector<array<int,3>>v(m);
	for(auto &i:v){
		cin>>i[0]>>i[1]>>i[2];
	}
	sort(all(v));
	debug(v);
	for(int i=0;i<n*10;i++){
		t[i]=1e18;
		lazy[i]=1e18;
	}
	update(1,1,n,1,1,0);
	for(int i=0;i<m;i++){
		ll q=query(1,1,n,v[i][0],v[i][0]);
		debug(i,v[i][0],q);
		update(1,1,n,v[i][0],v[i][1],q+v[i][2]);		
		//~ debug(i,query(1,1,n,v[i][0]
	}
	ll z=query(1,1,n,n,n);
	if(z!=1e18){
		cout<<z;
	}
	else{
		cout<<-1;
	}
}
 
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tc=1;
	//~ cin>>tc;
	for(int _=0;_<tc;_++){
		//~ cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1)
		cout<<"\n";
	}
}


Measured memory_bytes: 18944
#include <iostream>
#include <vector>
using namespace std;
long long a[1010],sum[1010][1010] = {0},ans = 1125899906842623;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long i,j,l,n,k;
	cin >> n >> k;
	for(i=0;i<n;i++){
		cin >> a[i];
	}
	for(i=0;i<n;i++){
		for(j=i;j<n;j++){
			if(j==0) sum[i][j] = a[j];
			else sum[i][j] += sum[i][j-1] + a[j];
		}
	}
	for(l=50;l>=0;l--){
		int cnt = 0;
		for(i=0;i<n;i++){
			for(j=i;j<n;j++){
				if((1LL<<l)&sum[i][j]) cnt++;
			}
		}
		if(cnt>=k){
			for(i=0;i<n;i++){
				for(j=i;j<n;j++){
					if(!((1LL<<l)&sum[i][j])) sum[i][j] = 0;
				}
			}
		}
	}
	for(i=0;i<n;i++){
		for(j=i;j<n;j++){
			if(sum[i][j]) ans &= sum[i][j];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 7424
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define d(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(void){
    string S;
    cin>>S;
    int c=0;
    REP(i,4){
        if(S[i]=='-'){
            c--;
        }
        else{
            c++;
        }
    }
    cout<<c<<endl;
    return 0;
}


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

int main() {
  string S,T;
  int A,B;
  cin>>S>>T>>A>>B;
  string U;
  cin>>U;
  if(U==S){
    cout<<A-1<<" "<<B<<endl;
  }
  else{
    cout<<A<<" "<<B-1<<endl;
  }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int d;
    cin >> d;

    if (d == 22)
    {
        cout << "Christmas Eve Eve Eve" << endl;
    }
    else if (d == 23)
    {
        cout << "Christmas Eve Eve" << endl;
    }
    else if (d == 24)
    {
        cout << "Christmas Eve" << endl;
    }
    else if (d == 25)
    {
        cout << "Christmas" << endl;
    }
}


Measured memory_bytes: 256
function Main(input){
  const arr = input.split('\n');
  let data, row, col;
  let pA = '';
  let pB = '';

  for (let i = 0; i < arr.length; i++){
    data = arr[i].split(' ');
    row = Number(data[0]);
    col = Number(data[1]);

    if (row === 0 && col === 0){
      break;
    } else {
    for (let j = 1; j <= col; j++){
      if (j % 2 === 1){pA+='.'; pB+='#';} else { pA+='#'; pB+='.';}}
    for (let k = 1; k <= row ; k++){
        if (k % 2 === 1){console.log(pB);}else{console.log(pA);}}
        pA = '';
        pB = '';
        console.log();
        }
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 17672