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


#define inf (1<<30)-1
#define INF (1LL<<62)-1
#define MOD 1000000007LL
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define PI acos(-1)
#define MEM(x,y) memset(x,y,sizeof (x))
#define debug cout<<"A"<<'\n'
#define REP(i,a,b) for (int i=(a); i<=(b); i++)
#define PER(i,a,b) for (int i=(a); i>=(b); i--)
#define REPL(i,a,b) for (LL i=(a); i<=(b); i++)
#define PERL(i,a,b) for (LL i=(a); i>=(b); i--)
#define print(x) cout<<x<<'\n'
#define itrALL(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define UNIQUE(X) X.erase( unique( X.begin(), X.end() ), X.end() )


typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int>PII;
typedef pair<LL,LL>PLL;
typedef vector<int> VI;
typedef vector<LL> VL;


template <class T> inline T bigmod(T p,T e,T M)
{
    T ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}

template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}
template <class T, class X> inline bool getbit(T a, X i) { T t=1; return ((a&(t<<i))>0);}
template <class T, class X> inline T setbit(T a, X i) { T t=1;return (a|(t<<i)); }
template <class T, class X> inline T resetbit(T a, X i) { T t=1;return (a&(~(t<<i)));}

/*end of header*/

int h,w,n,arr[10009],grid[105][105];

int main()
{
    //freopen("input_file_name.in","r",stdin);
    //freopen("output_file_name.out","w",stdout);
    scanf("%d %d %d",&h,&w,&n);
    REP(i,1,n)scanf("%d",&arr[i]);
    int now=1;
    REP(i,1,h)
    {
        if(i%2)
        {
            REP(j,1,w)
            {
                while(arr[now]==0)now++;
                grid[i][j]=now;
                arr[now]--;
            }
        }
        else
        {
            PER(j,w,1)
            {
                while(arr[now]==0)now++;
                grid[i][j]=now;
                arr[now]--;
            }
        }
    }

    REP(i,1,h)
    {
        bool flag=0;
        REP(j,1,w)
        {
            if(flag)printf(" ");
            flag=1;
            printf("%d",grid[i][j]);
        }
        printf("\n");
    }
    return 0;
}



Measured memory_bytes: 384
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int prime[] = new int[1050];
    for(int i=2;i<=N;i++){
    int x = i;
      for (int j=2;j<=x;j++){
        while(x%j == 0){
          x /= j;
          prime[j] += 1;
        }
      }
    }
    //System.out.println(Arrays.toString(prime));
      int mod = 1_000_000_007;
      long ans = 1;
      for(int i:prime){
        //System.out.println(i);
        ans = ((ans%mod)*(i+1)%mod);
      }
      System.out.println(ans);
        
  }
}


Measured memory_bytes: 21844
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

int steps[100001], n, k;

int search(int now)
{
	if(now >= n+1)
	{
		return 0;
	}
	if(steps[now] == 0)
	{
		int ans = 1;
		for(int i = now+1; i <= 100000; i++)
		{
			if(steps[i] == 1)
				ans++;
			else
				break;
		}
		for(int i = now-1; i > 0; i--)
		{
			if(steps[i] == 1)
				ans++;
			else
				break;
		}
		return max(ans, search(now+1));
	}
	else
	{
		return search(now+1);
	}
}

int main()
{
	while(cin >> n >> k)
	{

		if(n == 0 && k == 0)
			break;

		memset(steps, 0, sizeof(steps));

		int wk;
		for(int i = 0; i < k; i++)
		{
			cin >> wk;
			steps[wk] = 1;
		}
		if(steps[0] == 1)
		{
			cout << search(1) << endl;
		}
		else
		{
			int ans = 0, m;
			for(int i = 1; i <= n+1; i++)
			{
				if(steps[i] == 1)
				{
					ans++;
				}
				else
				{
					m = max(ans, m);
					ans = 0;
				}
			}
			cout << m << endl;
		}
	}
}

Measured memory_bytes: 1864
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>


int main()
{
	char(*s) = (char(*))malloc(200010 * sizeof(char));
	char top;
	long long i=0;
	long long equal = 0;
	long long len;
	long long ans = 0;
	scanf("%s", s);

	top = s[0];
	len = strlen(s);
	while (i < len)
	{
		if (s[i] == top)equal++;
		else
		{
			if (equal == 1)
			{
				ans += 1;
				equal = 0;
				top = s[i];
				i--;
			}
			if (equal == 2)
			{
				ans += 2;
				equal = 0;
				top = s[i + 1];
			}
		}
		if (equal == 3)
		{
			ans += 2;
			equal = 0;
			top = s[i + 1];
		}
		
		i++;
		
	}
	if (equal == 1)ans += 1;
	else if (equal == 2)ans += 1;
	printf("%lld\n", ans);
	free(s);
	return 0;
}

Measured memory_bytes: 384
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [[input().split()] for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n=n0()
s=s2(n)
from collections import Counter
c=Counter(s)
print(len(c))

Measured memory_bytes: 38944
#include <stdio.h>
#define N 30

/*
How to test
% diff <(./a.out < b1in.txt) <(cat b1out.txt) 
$ ./a.out < ain.txt 2>erra.txt

  for( i=0 ; i < n ; i++){
    fprintf(stderr, "%d: C2[%d] = %c%c \n" ,__LINE__ ,i ,C2[i].suit ,C2[i].value );
  }
    fprintf(stderr, "%d:\n" ,__LINE__ );
*/
typedef enum{
  ROOT, INT, LEAF,
} t_e;

typedef struct{
  int left;
  int right;
  int pa;  // parent
  int sib; // sibling
  int deg; // degree
  int dep; // depth
  int h;   // hight
  t_e type;
} tree_t;

int tree_depth = 0;

int geth(tree_t* ,int);
void prew(tree_t *t_p ,int id);
void pr(tree_t *a_p, int n);

int main(){
  int    n, i, j, k;
  int    id;
  int    pid; // parent ID
  tree_t a[N]; // a[id]

  scanf("%d", &n);
  for ( i = 0; i < n; i++ ){
    scanf("%d", &id );
    scanf("%d%d" ,&(a[id].left) ,&(a[id].right) );
  }

  // set parent, degree
  for( i=0 ; i<n ; i++){
    a[i].pa = -1;
    a[i].sib= -1;
    a[i].deg=  0;
    a[i].h  =  0;
  }

  // fprintf(stderr, "%d:\n" ,__LINE__ );

  for( i=0 ; i<n ; i++ ){
    if( a[i].left != -1 ){
      a[(a[i].left)].pa  = i;
      a[i].deg++;
    }
    if( a[i].right != -1 ){
      a[(a[i].right)].pa = i;
      a[i].deg++;
    }
  }

  // fprintf(stderr, "%d:\n" ,__LINE__ );
  // set type, get parent ID
  for( i=0 ; i<n ; i++ ){
    if( a[i].pa == -1 ){
      pid = i;
      a[i].type = ROOT;
    }else if( a[i].left != -1 || a[i].right != -1 ){
      a[i].type = INT;
    }else{
      a[i].type = LEAF;
    }
  }

  // fprintf(stderr, "%d:\n" ,__LINE__ );
  prew(a, pid);
  // fprintf(stderr, "%d:\n" ,__LINE__ );
  
  // set height
  for( i=0 ; i<n ; i++){
    if( n != 1 ){
      a[i].h = geth(a, i);
    }
  }

  // fprintf(stderr, "%d:\n" ,__LINE__ );

  // set sib
  for( i=0 ; i<n ; i++ ){
    if( a[i].left != -1 && a[i].right != -1 ){
      a[(a[i].left)].sib  = a[i].right;
      a[(a[i].right)].sib = a[i].left;
    }
  }

  // fprintf(stderr, "%d:\n" ,__LINE__ );

  pr( a, n);
  return 0; // Don't forget return 0
}

// get hight
int geth(tree_t *t_p ,int id){
  if( t_p[id].type == LEAF || id == -1 ){
    return 0;
  }
  int a = geth(t_p, t_p[id].left);
  int b = geth(t_p, t_p[id].right);
  return 1 + ( a > b ? a : b );
}

void prew(tree_t *t_p ,int id){ // preorder tree walk
  if(id == -1){
    return;
  }

  t_p[id].dep = tree_depth;
  
  tree_depth++;
  prew(t_p, t_p[id].left);
  prew(t_p, t_p[id].right);
  tree_depth--;
}

void pr(tree_t *a_p, int n){
  int i;
  for( i = 0 ; i < n ; i++ ){
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, "
	   ,i ,a_p[i].pa ,a_p[i].sib ,a_p[i].deg ,a_p[i].dep ,a_p[i].h );
    if( a_p[i].type == ROOT ){
      printf("root");
    }else if( a_p[i].type == INT ){
      printf("internal node");
    }if( a_p[i].type == LEAF ){
      printf("leaf");
    }
    printf("\n"); // note the possible of presentation error
  }

}

Measured memory_bytes: 604
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int cnt = 0;
    for(int i=1; i<=N; i++){
      if(String.valueOf(i).length()%2 != 0){
        cnt++;
      }
    }
    System.out.print(cnt);
  }
}

Measured memory_bytes: 26452
#include <stdio.h>

void rotate_x(int* data,int n);
void rotate_y(int* data,int n);
void rotate_z(int* data,int n);
int check(int flag,int* data1,int* data2);

int main(){
    int D[7];//サイコロの盤面(わかりやすさのため[1]~[6]を利用)
    int A[7];
    char cmd[100];//コマンドの文字列
    int cp;//一旦対比させる用の変数
    int flag=0;

    scanf("%d %d %d %d %d %d",&D[1],&D[2],&D[3],&D[4],&D[5],&D[6]);//サイコロの盤面入力
    scanf("%d %d %d %d %d %d",&A[1],&A[2],&A[3],&A[4],&A[5],&A[6]);

    rotate_x(D,1);
    for(int i=0;i<4;i++){
        rotate_z(D,1);
        flag=check(flag,D,A);
    }
    rotate_x(D,1);
    for(int i=0;i<4;i++){
        rotate_z(D,1);
        flag=check(flag,D,A);
    }
    rotate_x(D,1);
    for(int i=0;i<4;i++){
        rotate_z(D,1);
        flag=check(flag,D,A);
    }
    rotate_x(D,1);
    for(int i=0;i<4;i++){
        rotate_z(D,1);
        flag=check(flag,D,A);
    }
    rotate_y(D,1);
    for(int i=0;i<4;i++){
        rotate_z(D,1);
        flag=check(flag,D,A);
    }
    rotate_y(D,2);
    for(int i=0;i<4;i++){
        rotate_z(D,1);
        flag=check(flag,D,A);
    }

    if(flag==1)
        printf("Yes\n");
    else
        printf("No\n");
}

void rotate_x(int* data,int n){
    int cp;
    for(int i=0;i<n;i++){
        cp=data[1];
        data[1]=data[4];
        data[4]=data[6];
        data[6]=data[3];
        data[3]=cp;
    }   
} 

void rotate_y(int* data,int n){
    int cp;
    for(int i=0;i<n;i++){
        cp=data[1];
        data[1]=data[2];
        data[2]=data[6];
        data[6]=data[5];
        data[5]=cp;
    }   
} 

void rotate_z(int* data,int n){
    int cp;
    for(int i=0;i<n;i++){
        cp=data[2];
        data[2]=data[3];
        data[3]=data[5];
        data[5]=data[4];
        data[4]=cp;
    }   
} 

int check(int flag,int* p1,int* p2){
    if(p1[1]==p2[1]&&p1[2]==p2[2]&&p1[3]==p2[3]&&p1[4]==p2[4]&&p1[5]==p2[5]&&p1[6]==p2[6])
        flag=1;
    return flag;
}


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

using namespace std;

int main()
{	
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n,k;
	cin >> n >> k;
	int dp[n],height[n];
	for(int i  = 0;i<n;i++) cin >> height[i];
	dp[0]=0;
	for(int i = 1;i<n;i++){
		dp[i] = 1e9 +7;
		for(int j = 1;j<=k&&j<=i;j++){
			dp[i] = min(dp[i],dp[i-j]+abs(height[i-j]-height[i]));
		}
	}
	cout <<dp[n-1];
	return 0;
}

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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define ii pair<int,int>
#define fi first
#define sc second
#define stoi stoll
#define popcnt __builtin_popcount
#define getBit(x, k) ((x >> k) & 1)
#define all(x) (x).begin(),(x).end()
// ---------------------------------

void Main() {
  int n; cin >> n;
  vector<int> a(n);
  for (auto &i : a) cin >> i;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int t = a[i] / 2;
    a[i] %= 2;
    ans += t;
    if (i != n - 1) {
      t = min(a[i], a[i + 1]);
      a[i + 1] -= t;
      ans += t;
    }
  }
  cout << ans << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  cerr << "i love ------- <3 \n";
#endif
  cin.tie(0)->sync_with_stdio(0);
  int T = 1;
  // cin >> T;
  while (T--) Main();
}


Measured memory_bytes: 3992
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
#include <iomanip>

using namespace std;
#define int long long

signed main(){
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    
    sort(a,a+3);
    
    cout << a[0]+a[1] << endl;
    
    return 0;
}


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

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

    char c;
    while (cin >> c) {
        if (c == '1') {
            cout << '9';
        } else {
            cout << '1';
        }
    }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
//using System.Numerics;
class Program
{     
    
    public void Slove()
    {
        int n = int.Parse(Console.ReadLine());
        int[] cards = 
            Console.ReadLine().Split().Select(int.Parse)
            .Aggregate(new int[100000], (ret, x) => {ret[x]++; return ret;});
        int result = n - (cards.Where(x => x > 1).Sum(x => x - 1) + 1) / 2 * 2;
        System.Console.WriteLine(result);        
    }
    
    static void Main(string[] args)
    {
        new Program().Slove();
    }
}


Measured memory_bytes: 18912
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a;
	cin>>a;
	int b=0;
	for(int i=0;i<3;i++)
	{
		if(a[i]=='o')b+=100;
	}
	cout<<b+700;
	return 0;
}

Measured memory_bytes: 256
package main

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

var (
	s = bufio.NewScanner(os.Stdin)
	w = bytes.Buffer{}
	n = 0
	a = []int{}
)

func main() {
	n = nextInt(s)
	a = atoi(s)
	_ = nextInt(s)
	m := atoi(s)

	for _, v := range m {
		i := 0
		if solve(i, v) {
			w.WriteString("yes\n")
			continue
		}
		w.WriteString("no\n")
	}
	fmt.Println(strings.TrimRight(w.String(), "\n"))
}

func nextInt(s *bufio.Scanner) int {
	s.Scan()
	r, err := strconv.Atoi(s.Text())
	if err != nil {
		panic(err)
	}
	return r
}

func atoi(s *bufio.Scanner) []int {
	s.Scan()
	a := strings.Fields(s.Text())
	i := []int{}

	for _, v := range a {
		j, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		i = append(i, j)
	}
	return i
}

func solve(i, m int) bool {
	if m == 0 {
		return true
	} else if i >= n {
		return false
	}
	return solve(i+1, m) || solve(i+1, m-a[i])
}



Measured memory_bytes: 1196
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <stack>
#include <queue>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
using ld = long double;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll N, i, j, num, ans=1;

    cin >> N;

    vector<ll> x(N+1);

    if(N==1) cout << 1 << endl;

    else{
        for(i=2; i<=N; i++){
            num = i;
            for(j=2; j<=i; j++){
                while(num%j==0){
                    x.at(j)++;
                    num /= j;
                }
            }
        }

        for(i=2; i<=N; i++){
            ans *= (x.at(i)+1);
            ans %= div1;
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void)
{
    char a[10],b[10],c[10],d[3];
    scanf("%s %s %s",a,b,c);
    d[0] = toupper(a[0]);
    d[1] = toupper(b[0]);
    d[2] = toupper(c[0]);
    int i;
    for(i=0;i<3;i++){
        printf("%c",d[i]);
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mn = 2e5+3;
const ll inf = 1e15;
struct node{
	int l,r;
	ll c;
	bool operator<(const node& t)const {return l<t.l;}
}a[mn];
ll T[4*mn],lazy[4*mn];
void pushup(int i){
	T[i]=min(T[i<<1],T[i<<1|1]);
}
void pushdown(int i){
	if(lazy[i]<inf){
		lazy[i<<1]=min(lazy[i<<1],lazy[i]);
		lazy[i<<1|1]=min(lazy[i<<1|1],lazy[i]);
		T[i<<1]=min(T[i<<1],lazy[i]);
		T[i<<1|1]=min(T[i<<1|1],lazy[i]);
		lazy[i]=inf;
	}
}
void build(int i,int l,int r){
	lazy[i]=inf;
	if(l==r){
		T[i]=inf;
		return;
	}
	int m=l+r>>1;
	build(i<<1,l,m);
	build(i<<1|1,m+1,r);
	pushup(i);
}
void update(int i,int L,int R,int l,int r,ll x){
	if(l<=L&&R<=r){
		lazy[i]=min(lazy[i],x);
		T[i]=min(T[i],x);
		return;
	}
	pushdown(i);
	int m=L+R>>1;
	if(l<=m)update(i<<1,L,m,l,r,x);
	if(r>=m+1)update(i<<1|1,m+1,R,l,r,x);
	pushup(i);
}
ll query(int i,int L,int R,int l,int r){
	if(l<=L&&R<=r)return T[i];
	pushdown(i);
	int m=L+R>>1;
	ll ans=inf;
	if(l<=m)ans=min(ans,query(i<<1,L,m,l,r));
	else ans=min(ans,query(i<<1|1,m+1,R,l,r));
	return ans;
}
int main(){
	int n,m;scanf("%d%d",&n,&m);
	for(int i=0;i<m;++i){
		scanf("%d%d%lld",&a[i].l,&a[i].r,&a[i].c);
	}
	build(1,1,n);
	update(1,1,n,1,1,0);
	sort(a,a+m);
	for(int i=0;i<m;++i){
		ll t=query(1,1,n,a[i].l,a[i].r-1)+a[i].c;
		update(1,1,n,a[i].l,a[i].r,t);
	}
	ll t=query(1,1,n,n,n);
	if(t==inf)printf("-1\n");
	else printf("%lld\n",t);


	return 0;
}

Measured memory_bytes: 10496
from collections import deque
n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))
a = deque(sorted(d))
b = deque(sorted(t))
flag = 0
if n >= m:
    for i in range(n):
        if a[0] == b[0]:
            b.popleft()
        a.popleft()
        if len(b) == 0:
            print("YES")
            flag = 1
            break
if flag == 0:
    print("NO")


Measured memory_bytes: 35408
//#include <cmath>
//#include <cstdio>
//#include <vector>
//#include <map>
//#include <iostream>
//#include <algorithm>
//#include <set>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vb = vector<bool>;
using pli = pair<ll,int>; 		
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
int INF = 1e9+7;


void solve(){
	int n,k;
	scanf("%d%d",&n,&k);
	vi h(n);
	for(int i =0; i < n; ++i){
		scanf("%d",&h[i]);
	}
	vi dp(n+1,INF);//dp[i] -> min cost incurred to reach stone N
	dp[n-1] = 0;
	for(int i = n-1;i >=0 ;i--){
		for(int j = 1; j <= k; ++j){
			if(i-j >= 0)
			dp[i-j] = min(dp[i-j], dp[i] + abs(h[i] - h[i-j]));
		}
	}
	printf("%d\n",dp[0]);
	
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	//cin >> t;
	//scanf("%d",&t);
	while(t--){
		solve();
	}
		
			
}


Measured memory_bytes: 3992
/*
  Expr = Term { (+|-) Term}
  Term = Fact { (*|/) Fact}
  Fact = (Expr) | number

*/

#include<iostream>
#include<cstdlib>
using namespace std;


typedef pair<int,const char*>parsed;


parsed expr(const char *p);
parsed term(const char *p);
parsed fact(const char *p);


parsed expr(const char *p)
{
  parsed r=term(p);
 
 while(*r.second=='+'||*r.second=='-'){
    char op =*r.second;
    int tmp=r.first;
    r=term(r.second+1);
    if(op=='+')r.first=tmp+r.first;
    else r.first=tmp-r.first;
  }
  return r;
}

parsed term(const char *p)
{
  parsed r=fact(p);
  while(*r.second=='*'||*r.second=='/'){
    char op=*r.second;
    int tmp=r.first;
    r=fact(r.second+1);
    if(op=='*')r.first=tmp*r.first;
    else r.first=tmp/r.first;
  }
  return r;
}

parsed fact(const char *p)
{
  if(isdigit(*p)){
    int t=*(p++)-'0';
    while(isdigit(*p))t=t*10+*(p++)-'0';
    return parsed(t,p);
  }
  else if(*p=='('){
    parsed r=expr(p+1);
    if(*r.second!=')')exit(0);
    return parsed(r.first,r.second+1);
  }
  else exit(0);
}

int main()
{
  string str;
  int n;
  cin>>n;
  while(n--){
	  cin>>str;
    cout<<expr(str.c_str()).first<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
/*
* @author:  codancer
* @createTime:  2020-02-22, 20:03:29
*/
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define pb push_back
#define SZ(x) ((int)(x).size())
#define fi first
#define se second
typedef vector<int> VI;
typedef pair<int,int> pii;
int main(){
	int n,k;
	cin>>n>>k;
	int ans=0;
	while(n){
		ans++;
		n/=k;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int64_t N, M, X, INF = 100000000000000;
vector<vector<int64_t>> A(13, vector<int64_t>(100010));
vector<int64_t> C(13);

int main()
{
  cin >> N >> M >> X;
  for (int i = 0; i < N; i++)
  {
    cin >> C.at(i);
    for (int j = 0; j < M; j++)
    {
      cin >> A.at(i).at(j);
    }
  }
  int64_t ans = INF;
  for (int bit = 0; bit < (1 << N); bit++)
  {
    int64_t cost = 0;
    vector<int64_t> B(M, 0);
    for (int i = 0; i < N; i++)
    {
      if (bit & (1 << i))
      {
        cost += C.at(i);
        for (int j = 0; j < M; j++)
        {
          B.at(j) += A.at(i).at(j);
        }
      }
    }
    bool ok = true;
    for (int i = 0; i < M; i++)
    {
      if (B.at(i) < X)
      {
        ok = false;
        break;
      }
    }
    if (ok)
    {
      ans = min(ans, cost);
    }
  }
  cout << (ans == INF ? -1 : ans) << endl;
}

Measured memory_bytes: 14148
#include<iostream>
#include<cstdio>
#include<queue>
#include<functional>
#include<vector>
using namespace std;
typedef pair<int, int> P;
const int INF = 2147483647;
struct edge{
	int to;
	int cost;
};
int N, K;
int C[5000]; int R[5000];
vector<edge> G1[5000];
int S[5000];
vector<edge> G2[5000];
void dijkstra1(int s)
{
	int i;
	for (i = 0; i < N; i++)S[i] = INF;
	priority_queue<P, vector<P>, greater<P> >que;
	que.push(P(0,s));
	while (!que.empty()){
		P p = que.top(); que.pop();
		int pf = p.first; int ps = p.second;
		if (S[ps] <= pf)continue;
		S[ps] = pf;
		for (i = 0; i < (int)G1[ps].size(); i++){
			if (S[ps] + G1[ps][i].cost < S[G1[ps][i].to])que.push(P(S[ps] + G1[ps][i].cost, G1[ps][i].to));
		}
	}
}
void dijkstra2(int s)
{
	int i;
	for (i = 0; i < N; i++)S[i] = INF;
	priority_queue<P, vector<P>, greater<P> >que;
	que.push(P(0, s));
	while (!que.empty()){
		P p = que.top(); que.pop();
		int pf = p.first; int ps = p.second;
		if (S[ps] <= pf)continue;
		S[ps] = pf;
		for (i = 0; i < (int)G2[ps].size(); i++){
			if (S[ps] + G2[ps][i].cost < S[G2[ps][i].to])que.push(P(S[ps] + G2[ps][i].cost, G2[ps][i].to));
		}
	}
}
int main()
{
	int i,j;
	scanf("%d%d", &N, &K);
	for (i = 0; i < N; i++)scanf("%d%d", &C[i], &R[i]);
	for (i = 0; i < K; i++){
		int S, E;
		scanf("%d%d", &S, &E);
		G1[S - 1].push_back(edge{ E - 1, 1 });
		G1[E - 1].push_back(edge{ S - 1, 1 });
	}
	for (i = 0; i < N; i++){
		dijkstra1(i);
		for (j = 0; j < N; j++){
			if (i == j)continue;
			if (S[j] <= R[i]){
				G2[i].push_back(edge{ j, C[i] });
			}
		}
	}
	dijkstra2(0);
	printf("%d\n", S[N - 1]);
	return 0;
}

Measured memory_bytes: 192388
#include <bits/stdc++.h>
#define ll long long

using namespace std;
const int N=455;
ll dp[N][N];
ll sum[N];
ll a[N];
int n;
	

int main()
{
	memset(dp,+1,sizeof dp);
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		if(i)
			sum[i]=sum[i-1];
		sum[i]+=a[i];
	}
	for(int k=0,i=0,j=0;;i++,j++)
	{
		if(j==n)
		{
			k++;
			if(k==n)
				break;
			i=0;
			j=k;
		}
		if(i==j)
		{
			dp[i][j]=0;
			continue ;
		}
		for(int K=i;K<j;K++)
			dp[i][j]=min(dp[i][j],dp[i][K]+dp[K+1][j]);
		dp[i][j]+=sum[j];
		if(i)
			dp[i][j]-=sum[i-1];
		
	}
	cout<<dp[0][n-1]<<endl;
			
	return 0;
}


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

// Function to find the number of divisors 
// of all numbers in the range [1, n] 
void findDivisors(int n) 
{ 

	// Array to store the count 
	// of divisors 
	int div[n + 1]; 
	memset(div, 0, sizeof div); 

	// For every number from 1 to n 
	for (int i = 1; i <= n; i++) { 

		// Increase divisors count for 
		// every number divisible by i 
		for (int j = 1; j * i <= n; j++) 
			div[i * j]++; 
	} 

	// Print the divisors 
  int ans=0;
	for (int i = 1; i <= n; i++) 
		ans+= div[i];// << " "; 
  cout<<ans;
} 

// Driver code 
int main() 
{ 
	//int n = 99;
  	int n;
  	cin>>n;
    n--;
	findDivisors(n); 

	return 0; 
} 


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

int main()
{
	int a,b,c,k;
	cin >> a >> b >> c >> k;

	int point=0;

	if (k<=a)
	{
		cout << k << endl;
		return 0;
	}
	if (k<=a+b)
	{
		cout << a << endl;
		return 0;
	}

	cout << a-(k-(a+b)) << endl;
}







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

int main()
{
	int n,m;
	cin >> n >> m;
	vector<vector<int>> v(n, vector<int>(m, 0));
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> v[i][j];
		}
	}
	vector<int> x(m);
	for (int i = 0; i < m; i++)
	{
		cin >> x[i];
	}
	vector<int> ans(n);
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			ans[i] += v[i][j] * x[j];
		}
	}

	for (int i = 0; i < n; i++)
	{
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long x, y;
	cin >> x >> y;
	int cnt = 1;
	for (int i = 1; i < 110; i++) {
		if (x * 2 <= y) {
			x*=2;
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

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

#define fi first
#define se second
#define FO(x, n) for (int x = 0; x < n; ++x)
#define FOR(x, a, b) for (int x = a; x < b; ++x)
#define RFO(x, n) for (int x = n - 1; x >= 0; --x)
#define RFOR(x, a, b) for (int x = b - 1; x >= a; --x)
#define FOR_ITER(x, a) for(auto x = a.begin(); x != a.end(); ++x)



using namespace std;
typedef unsigned char byte;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;
typedef pair<ll, ll> pll;
inline bool feq(const double& a, const double& b) { return fabs(a - b) < 1e-10; }

using namespace std;


int main(){
//    int n, l;
//    cin >> n >> k;
//    vector<bool> dislike(10, false);
//
//    FOR(i, 0, k) {
//        int t;
//        cin >> t;
//        dislike[t] = true;
//    }

    int h, w;
    cin >> h >> w;

    FO(i, h) {
        string str;
        cin >> str;
        cout << str << endl;
        cout << str << endl;
    }


    return 0;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  int p[N];
  for(int i=0; i<N; i++)
    cin >> p[i];
  
  sort(p, p+N);
  int sum = 0;
  for(int i=0; i<K; i++)
    sum += p[i];
  
  cout << sum << endl;
}

Measured memory_bytes: 3620
#include "bits/stdc++.h"

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back

using namespace std;

#define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1 
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : "\n"); return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : "}\n"); return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline void chmax(T& a,T const& b){a=max(a,b);}
template<class T> inline void chmin(T& a,T const& b){a=min(a,b);}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 998244353,LINF=1LL<<60; 

vector<ll> fact;

void init(ll N){
  fact.resize(N+1);
  fact[0]=1;
  rep(i,N) fact[i+1]=((i+1)*fact[i])%lmod;
}

ll ppow(ll a,ll b){
  // aのb乗を求める
  ll res = 1;
  while(b){
    if(b%2) res=(res*a)%lmod;
    a=(a*a)%lmod;
    b>>=1;
  }
  return res;
}

ll imod(ll n){
  // nのmodの逆元を求める
  ll P=lmod;
  return ppow(n,P-2);
}

ll comb_mod(ll n,ll k){
  //nまで埋めた階乗テーブルを渡す
  if(k>n) return 0;
  else return (fact[n] * imod(fact[k]) % lmod) * imod(fact[n-k]) % lmod ;
  //nCk % mod を返す
}


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N,A,B,K;
  cin >> N >> A >> B >> K;
  ll ans = 0LL;
  init(N+2);
  for(ll a = 0; a <= N; a++){
    ll b = K - a * A;
    if(b<0) break;
    if(b%B!=0LL) continue;
    else b /= B;
    ans = (ans + comb_mod(N,a) * comb_mod(N,b)) % lmod;
  }
  cout << ans << endl;
  return 0;
}


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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll a;
  string s;
  cin >> a >> s;
  
  ll b = ((s[0] - '0') * 100 + (s[2] - '0') * 10 + (s[3] - '0'));
  
  cout << (a * b / 100) << '\n';
}


Measured memory_bytes: 3648
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <iostream>
using namespace std;
struct Node {
  Node *prev,*next;
  int key;
};
Node *Nil;
void init(){
  Nil=(Node *)malloc(sizeof(Node));
  Nil->next=Nil;
  Nil->prev=Nil;
}

void Insert(int x){
  Node *node;
  node=(Node *)malloc(sizeof(Node));
  node->key=x;
  node->next=Nil->next;
  Nil->next->prev=node;
  node->prev=Nil;
  Nil->next=node;
}
Node* listsearch(int x){
  Node *del = Nil->next;
  while(del!=Nil && del->key!=x){
    del=del->next;
  }
  return del;
}
void DeleteNode(Node *node){
  if(node==Nil)return ;
  node->prev->next=node->next;
  node->next->prev=node->prev;
  free(node);
  
}
void DeleteFirst(){
  DeleteNode(Nil->next);
}
void DeleteLast(){
  DeleteNode(Nil->prev);
  
}
void print_list(){
  
  Node *node;
  node=Nil->next;
  while(node!=Nil){
    printf("%d",node->key);
    if(node->next!=Nil)printf(" ");
    node=node->next;
  }
  printf("\n");
}
int main(){
  int n;
  string s;
  int x;
  scanf("%d",&n);
  init();
  for(int i=0;i<n;i++){
    cin >> s;
    if(s[0]=='i'){cin >> x;Insert(x);}
    else if(s[0]=='d'){
      if(s.length()==6){cin >> x; DeleteNode(listsearch(x));}
      else if(s.length()==11)DeleteFirst();
      else if(s.length()==10)DeleteLast();
    }
  }
  print_list();
  return 0;
}

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

int main() {
    using namespace std;
    constexpr unsigned long MOD = 1000000007;
    unsigned long r1, r2, c1, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    const auto& modinv = [](unsigned long a, unsigned long b = 1) -> unsigned long {
        unsigned long r{b % MOD};
        a %= MOD;
        unsigned long n{MOD - 2};
        while(n){
            if(n & 1)(r *= a) %= MOD;
            (a *= a) %= MOD;
            n >>= 1;
        }
        return r;
    };
    unsigned long N{r2 + c2 + 4};
    vector<unsigned long> factmod(N + 1, 1);
    for(unsigned long i{1}; i <= N; ++i)factmod[i] = factmod[i - 1] * i % MOD;
    unsigned long f11{modinv(factmod[r1] * factmod[c1], factmod[r1 + c1])}, f12{modinv(factmod[r1] * factmod[c2 + 1], factmod[r1 + c2 + 1])}, f21{modinv(factmod[r2 + 1] * factmod[c1], factmod[r2 + c1 + 1])}, f22{modinv(factmod[r2 + 1] * factmod[c2 + 1], factmod[r2 + c2 + 2])};
    cout << (f22 + f11 + MOD * 2 - f12 - f21) % MOD << endl;
    return 0;
}

Measured memory_bytes: 15872
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main implements Runnable {
    public static void main(String[] args) {
        new Thread(null,new Main(), "" ,Runtime.getRuntime().maxMemory()).start();
    }

    public void run() {
        FastScanner sc = new FastScanner();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int h = sc.nextInt();
        int m = sc.nextInt();

        double newAx = Math.sin(Math.toRadians(360.0 - (360.0 * (h / 12.0) + 30.0 *(m / 60.0)))) * -1.0 * a;
        double newAy = Math.cos(Math.toRadians(360.0 - (360.0 * (h / 12.0) + 30.0 *(m / 60.0)))) * a;
        double newBx = Math.sin(Math.toRadians(360.0 - (360.0 * (m / 60.0)))) * -1.0 * b;
        double newBy = Math.cos(Math.toRadians(360.0 - (360.0 * (m / 60.0)))) * b;

        double ans = Math.sqrt(Math.pow(newAx - newBx, 2) + Math.pow(newAy - newBy, 2));
        System.out.println(ans);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    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: 33292
#include <iostream>
#include <string>

int main()
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  
  std::string s;
  std::cin>>s;
  
  std::string result;
  
  if('A'<=s[0]&&s[0]<='Z')
  {
    result="A";
  }
  else
  {
    result="a";
  }
  
  std::cout<<result<<std::endl;
  
  return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  int m = 0;
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
    m +=  a.at(i);
  }
  m/=n;
  int64_t m1 = m - 1, m2 = m + 1, ans1 = 0, ans = 0, ans2 = 0;
  for(int i = 0; i < n; i++){
    ans1 += pow((a.at(i) - m1),2);
    ans += pow((a.at(i) - m),2);
    ans2 += pow((a.at(i) - m2),2);
  }
  int64_t ansf = min(ans1,min(ans,ans2));
  cout << ansf << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20190315_04 {
    class Program {
        static void Main(string[] args) {
            var line0 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var n = line0[0];
            var m = line0[1];
            var line1 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).OrderBy(x => x).ToArray();
            if (n >= m) {
                Console.WriteLine("0");
                return;
            }
            var range = line1.Last() - line1.First();
            var d = new double[m - 1];
            for (int i = 0; i < m - 1; i++) {
                d[i] = line1[i + 1] - line1[i];
            }
            var max = d.OrderByDescending(x => x).Take(n - 1).Sum();
            Console.WriteLine(range-max);
        }
    }
}


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

int main()
{
	int n, m;
	cin >> n >> m;
	int ans = (n - m) * 100 + m * 1900;
	for(auto i = 0; i < m; ++i){
		ans *= 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif

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

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

int main(void) {
    int64_t llimit, ulimit;
    cin >> llimit >> ulimit;
    int64_t whole = ulimit-llimit+1;
    llimit--;
    int64_t a, b;
    cin >> a >> b;
    if(a > b) swap(a, b);
    int64_t ab = lcm(a, b);
    debug("lcm: %ld\n", ab);
    // principle of inclusion and exclusion
    int64_t right = ulimit/a + ulimit/b - ulimit/ab;
    int64_t left = llimit/a + llimit/b - llimit/ab;
    cout << whole - (right-left) << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
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 N 100005
vp g[N];
void solve(){
    ll v,e,r;cin>>v>>e>>r;
    rep(i,e){
        ll s,t,d;cin>>s>>t>>d;
        g[s].push_back(pl(t,d));
    }
    vl dist(v,LINF);
    dist[r]=0;
    priority_queue<pl,vp,greater<pl> > que;
    que.push(pl(0,r));
    while(!que.empty()){
        pl p1=que.top();que.pop();
        ll d=p1.first,s=p1.second;
        if(dist[s]<d)continue;
        dist[s]=d;
        rep(i,g[s].size()){
            ll t=g[s][i].first,d2=g[s][i].second;
            if(dist[t]<=d+d2)continue;
            dist[t]=d+d2;
            que.push(pl(d+d2,t));
        }
    }
    rep(i,v){
        if(dist[i]==LINF)cout<<"INF"<<endl;
        else cout<<dist[i]<<endl;
    }
}

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



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

const int maxn = 1e5 + 5;
int arr[maxn];
int n;
bool a = true;

int main(){
	scanf("%d",&n);
	arr[0] = 0;
	for(int i=1;i<=n;i++) scanf("%d",&arr[i]);
	for(int i=1;i<=n;i++){
		if(arr[i] < arr[i-1]) a = false;
		if(arr[i] > arr[i-1]) arr[i] --;
	}
	if(a) printf("Yes");
	else printf("No");
	return 0;
}

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

using namespace std;

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, mx = 0, s = 0; cin >> n;
    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        s += a; mx = max(a, mx);
    }
    cout << (s > 2 * mx ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define endl                        '\n'
#define debug(x)                    cerr << #x << ": " <<  x << endl;
#define fast_io;                    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const ll MAXN=1e6 + 10;
const ll LOG=22;
const ll INF=8e18;
const ll MOD=1e9 + 7; // 998244353; // 1e9 + 9;
int main(){
fast_io;
int n,m;
cin>>n;
int a[n],s=0;
for(int i=0;i<n;i++){
      cin>>a[i];
      s+=a[i];
}
cin>>m;
pair<int,int> p;
for(int i=0;i<m;i++){
      cin>>p.first>>p.second;
      s-=a[p.first-1];
      s+=p.second;
      cout<<s<<endl;
      s-=p.second;
      s+=a[p.first-1];
}

return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<string>
#define ll long long
#define dd double
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	ll n, m, t; cin >> n >> m >> t;
	for (ll i = 0; i < 10; i++) {
		cout << n * t - m << endl;
		t = n * t - m;
	}
}

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

int main()
{
	int N;
	int result = 0;
	cin >> N;
	vector<int> H(N, 0), h(N, 0);
	repeat(i, N) {
		cin >> H[i];
	}

	bool is_empty = true;
	int start_idx = 0;
	while(is_empty) {
		repeat(i, N) {
			if (h[i] < H[i]) {
				start_idx = i;
				break;
			}
		}

		for(int i = start_idx; i < N; i++) {
			if (h[i] == H[i]) break;
			h[i] += 1;
		}

		result++;

		repeat(i, N) {
			if (h[i] == H[i]) is_empty = false;
			else {
				is_empty = true;
				break;
			};
		}
	}

	bool is_zero = true;
	repeat(i, N) {
		if (H[i] != 0) {
			is_zero = false;
			break;
		}
	}
	if (is_zero) result = 0;

	cout << result << 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)-1);i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> 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>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))

int main(void){
	int h, w;
	cin >> h >> w;
	char c[w];
	rep(i, h){
		rep(j, w) cin >> c[j];
		rep(j, w) cout << c[j];
		cout << endl;
		rep(j, w) cout << c[j];
		cout << endl;
	}
	
	return 0;
}

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

int main(){
  int n,m;
  cin>>n>>m;
  vector<bool>broken(n+1);
  for(int i=0;i<m;i++){
    int a;
    cin>>a;
    broken[a]=true;
  }
  vector<int>dp(n+2);
  dp[n]=1;
  const int mod=1000000007;
  for(int i=n-1;i>=0;i--){
    if(broken[i]){
      dp[i]=0;
      continue;
    }
    dp[i]=(dp[i+1]+dp[i+2])%mod;
  }
  cout<<dp[0]<<endl;
  return 0;
}
    
  
  
  


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool check_three(int);

int main()
{
  int n; cin >> n;
  int num[n];

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

  for(int i = n-1; i >= 0; i--) {
    cout << num[i];
    if (i != 0) cout << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 3092
from collections import Counter
import itertools

N = int(input())
Ds = list(map(int, input().split())) + [0]

cnt = Counter(Ds)

if max(cnt.values()) >= 3:
    print(0)
    exit()

citys = []
rest = []
for k, v in cnt.items():
    if v == 2:
        if k == 0 or k == 12:
            print(0)
            exit()
        citys.append(k)
        citys.append(24 -k)
    else:
        rest.append(k)


def check(citys):
    if len(citys) <= 1:
        return 24

    citys.sort()

    ans = 24
    prev = citys[-1] - 24
    for c in citys:
        ans = min(ans, c - prev)
        prev = c

    return ans


if check(citys) == 1:
    print(1)
    exit()

ans = 0
for ops in itertools.product('+-', repeat=len(rest)):
    citys2 = citys.copy()
    for i in range(len(rest)):
        if ops[i] == '+':
            citys2.append(rest[i])
        else:
            citys2.append(24 - rest[i])

    ans = max(ans, check(citys2))

print(ans)


Measured memory_bytes: 3444
#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>
#include <queue>
#include <fstream>
 
using namespace std;
 
#define INF 100000000
#define EPS 1e-9
#define PI acos(-1)
 
typedef long long ll;

#define MAX_N 102
#define MAX_M 1002

int N, M, s, g1, g2;

vector<int> ans_list;



int main(){

  
  while(true){
    
    cin >> N >> M >> s >> g1 >> g2;
    if(N == 0)
      break;

    s--;
    g1--;
    g2--;

    int d[MAX_N][MAX_N];
    for(int i = 0; i < N; i++){
      for(int j = 0; j < N; j++){
	d[i][j] = INF;
      }
      d[i][i] = 0;
    }

    for(int i = 0; i < M; i++){
      int b1, b2, c;
      cin >> b1 >> b2 >> c;
      b1--;
      b2--;
      d[b1][b2] = c;
    }

    for(int k = 0; k < N; k++){
      for(int i = 0; i < N; i++){
	for(int j = 0; j < N; j++){
	  d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
	}
      }
    }

    int ans = INF;

    for(int k = 0; k < N; k++){
      ans = min(ans, d[s][k] + d[k][g1] + d[k][g2]);
    }
    
    ans_list.push_back(ans);

  }

  

  for(int i = 0; i < ans_list.size(); i++){
    cout << ans_list[i] << endl;
  }


  return 0;

}

Measured memory_bytes: 1256
import sys

from numba import njit, void, i8
input = sys.stdin.buffer.readline
K = int(input())
A, B = map(int, input().split())


@njit(i8(i8, i8, i8), cache=True)
def main(K, A, B):

    for i in range(A, B + 1):
        if i % K == 0:
            print('OK')
            return 0
    print('NG')
    return 0


if __name__ == '__main__':
    main(K, A, B)


Measured memory_bytes: 109212
//ABC045B
#include <iostream>
#include <string>
#include <list>

using namespace std;

int main(){
    
    string a,b,c;

    cin>>a>>b>>c;

    string now;
    now=a[0];
    a.erase(a.begin());

    while(1){
        if(now=="a"){
            if(a.empty()){
                cout<<"A"<<endl;
                break;
            }
            now=a[0];
            a.erase(a.begin());
        }else if(now=="b"){
            if(b.empty()){
                cout<<"B"<<endl;
                break;
            }
            now=b[0];
            b.erase(b.begin());

        }else if(now=="c"){
            if(c.empty()){
                cout<<"C"<<endl;
                break;
            }
            now=c[0];
            c.erase(c.begin());
        }
    }



}


Measured memory_bytes: 256