akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
typedef long long int ll;
const int MOD=1e9+7;
const int N=2e3+10;
ll fac[N],ans[N][N];
ll pow(ll a,ll t){
    if(t==0)return 1;
    ll temp=pow(a,t/2);
    temp*=temp;
    temp%=MOD;
    if(t&1){
        temp*=a;
        temp%=MOD;
    }
    return temp;
}
ll rev(ll n){return pow(n,MOD-2);}
ll C(int n,int k){return (fac[n]*((rev(fac[k])*rev(fac[n-k]))%MOD))%MOD;}
ll H(int n,int k){return C(n+k-1,k);}
void init(){
    fac[0]=fac[1]=1;
    for(int i=2;i<N;i++)fac[i]=(fac[i-1]*i)%MOD;
    for(int i=0;i<N;i++)for(int j=0;j<N;j++)ans[i][j]=-1;
    ans[0][0]=1;
    return ;
}
ll dp(int n,int k){
    if(n<0||k<0)return 0;
    if(ans[n][k]>=0)return ans[n][k];
    if(n==k)return ans[n][k]=dp(n-1,k-1);
    return ans[n][k]=(dp(n-1,k-1))%MOD;
}
int main(){
    int n,k,now=1;
    ll ans=0;
    scanf("%d%d",&n,&k);
    if(n<=k)printf("1\n");
    else printf("0\n");
    //    init();
    
}


Measured memory_bytes: 2692
package main

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

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}()

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextInts(n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = nextInt()

	}
	return ints
}

func canBuildNoDecreasingStairs(stairs []int) bool {
	max := stairs[0]
	for i := 1; i < len(stairs); i++ {
		if max <= stairs[i] {
			max = stairs[i]
			continue
		}

		if max-stairs[i] > 1 {
			return false
		}
	}
	return true
}

func main() {
	n := nextInt()
	ints := nextInts(n)
	if canBuildNoDecreasingStairs(ints) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 3072
#include<stdio.h>
int main(void){
    int H,W;
    
    while(1){
        scanf("%d %d",&H,&W);
        if(H==0&&W==0){
            break;
        }
        for(int row=0;row<H;row++){
            for(int col=0;col<W;col++){
                if(row==0||row==H-1||col==0||col==W-1){
                    printf("#");
                }
                else{
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    
    return 0;
}


Measured memory_bytes: 1964
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#define dis(a,b) (a)*(a)+(b)*(b)
using namespace std;
void f(vector<int> v,int d[][1001],int p[],int k[],int c,int e,double s){
  int i;
  vector<int> w=v;
  if(c==e){
    if(p[c]==-1||p[c]>s){
      w.push_back(c);
      for(i=0;i<(int)w.size();i++)
	k[i]=w[i];
      k[i]=0;
      p[c]=s;
    }
  }else if(p[c]==-1||p[c]>s){
    w.push_back(c);
    p[c]=s;
    for(i=1;i<1001;i++){
      if(d[c][i]&&d[c][i]<=2500)
	f(w,d,p,k,i,e,s+sqrt((double)d[c][i]));
    }
  }
  return;
}
int main(){
  int i,j;
  int m,n;
  int k[1001],p[1001],x[1001],y[1001],d[1001][1001];
  int *b,*e,*g;
  vector<int> v;
  for(;;){
    cin>>n;
    if(n==0)
      break;
    memset(d,0,sizeof(d));
    g=new int[n];
    for(i=0;i<n;i++){
      cin>>g[i];
      cin>>x[g[i]]>>y[g[i]];
      for(j=0;j<i;j++){
	d[g[i]][g[j]]=dis(x[g[i]]-x[g[j]],y[g[i]]-y[g[j]]);
	d[g[j]][g[i]]=d[g[i]][g[j]];
      }
    }
    delete[]g;
    cin>>m;
    b=new int[m];
    e=new int[m];
    for(i=0;i<m;i++)
      cin>>b[i]>>e[i];
    for(i=0;i<m;i++){
      v.clear();
      memset(p,-1,sizeof(p));
      k[0]=0;
      f(v,d,p,k,b[i],e[i],0.0);
      if(k[0]){
	for(j=0;k[j+1];j++)
	  cout<<k[j]<<" ";
	cout<<k[j]<<endl;
      }else
	cout<<"NA"<<endl;
    }
    delete[]b;
    delete[]e;
  }
  return 0;
}

Measured memory_bytes: 0
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    String ans = "NO";
    boolean flg = false;
    for(int i = 0; i < b; i++) {
      if((a * i) % b == c) flg = true;
    }
    if(flg) ans = "YES";
    System.out.println(ans);
  }
}

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

int main() {
  int A, B, C, D; cin >> A >> B >> C >> D;
  while (A>0 && C>0) {
    C -= B;
    if (C<=0) {
      cout << "Yes" << endl;
      break;
    }
    A -= D;
    if (A<=0) {
      cout << "No" << endl;
      break;
    }
  }
}

Measured memory_bytes: 3636
import java.util.HashSet;
import java.util.Scanner;

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

            HashSet<Long> used = new HashSet<Long>();
            long l7 = 7;
            for (int i = 1;;) {
                if (l7 % K == 0) {
                    System.out.println(i);
                    return;
                }
                if (l7 < K) {
                    l7 = l7 * 10 + 7;
                    i++;
                    if (!used.add(l7)) {
                        System.out.println(-1);
                        return;
                    }
                } else {
                    l7 %= K;
                }
            }
        }
    }
}


Measured memory_bytes: 98884
#include<stdio.h>
int main(void){
    int c1,c2,c3;
    while(scanf("%d",&c1)!=EOF){
        scanf(" %d %d",&c2,&c3);
        int a,b,i,j,k;
        double x;
        a=20-c1-c2;
        b=0;
        if(a>10)a=10;
        for(i=1;i<=a;i++){
            if(i==c1 || i==c2 || i==c3)continue;
            else b++;
        }


        if(b>=4)puts("YES");
        else puts("NO");
    }
    return 0;
}

Measured memory_bytes: 576
#include<stdio.h>
int main(){
    int a, b;
    scanf("%d %d", &a, &b);
    int higher = a+b;
    if(a-b>higher) higher=a-b;
    if(a*b>higher) higher=a*b;
    printf("%i\n",higher);
    return 0;
} 

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

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

  vll p(n), q(n);
  for (ll i = 0; i < n; i++) cin >> p[i];
  for (ll i = 0; i < n; i++) cin >> q[i];
  if (p > q) swap(p, q);

  ll cnt = 0;
  while (p < q) {
    next_permutation(all(p));
    cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<climits>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
#define MAXN 100000
#define MAXM 100000
#define INF 1000000000000000
struct node
{
    int next,to;
    long long w;
}e[MAXM*2+5];
struct Qr
{
    int xr,dec;
    long long lim;
};
long long T;
int cnt,m,n;
int x,y,z,flag;
long long ri=INF,le=-INF;
long long vis[2][MAXN+5];
int b[MAXN+5];
void fpush(int u,int v,long long w)
{
    e[++cnt].next=b[u];
    e[cnt].w=w;
    e[cnt].to=v;
    b[u]=cnt;
}
int Ch(int x){if(x==-1)x=0;return x;}
int main()
{
    fill(vis[0],vis[0]+MAXN+1,INF);
    fill(vis[1],vis[1]+MAXN+1,INF);
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d%d",&x,&y,&z);
        fpush(x,y,z);fpush(y,x,z);
    }
    queue<Qr> Q;
    Q.push((Qr){1,1,0});
    while(!Q.empty())
    {
        Qr A=Q.front();
        Q.pop();
        int xr=A.xr,dec=A.dec;
        long long lim=A.lim;
        for(int i=b[xr];i;i=e[i].next)
        {
            int xnext=e[i].to;
            long long nlim=e[i].w-lim;
            int FD=Ch(dec);
            if(vis[FD][xnext]!=INF)
            {
                if(vis[FD][xnext]!=nlim){printf("0\n");return 0;}
                else continue;
            }
            vis[FD][xnext]=nlim;
            if(!FD)le=max(le,-vis[FD][xnext]);
            else ri=min(ri,vis[FD][xnext]);
            Q.push((Qr){xnext,-dec,nlim});
        }
    }
    long long T=-1;
    for(int i=1;i<=n;i++)
        if(vis[0][i]!=INF&&vis[1][i]!=INF)
        {
            long long NT=(vis[1][i]-vis[0][i])/2;
            if(NT<0){flag=1;break;}
            if(T==-1)T=NT;
            else if(T!=NT){flag=1;break;}
        }
    if(flag){printf("0\n");}
    if(T!=-1)
    {
        if(T>le&&T<ri)printf("1\n");
        else printf("0\n");
    }
    else printf("%lld",max((long long)0,ri-le-1));
}

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

int H,W;
char s[51][51];//升目の記号の記録
int d[51][51]; //値の記録
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int bfs(){
  queue<P> que;
  //初期化
  rep(i,51){
   rep(j,51){
    d[i][j]=INF;
  
   }
  }
  
  d[0][0]=0;
  que.push(P(0,0));
  //いける点ぜんぶいくまでループ
  while(que.size()){
  	P p=que.front(); que.pop();
  	 if(p.first==H-1&&p.second==W-1){
       break;
     }
  	for(int i=0;i<4;i++){
    	int ny= p.first+dy[i];
      	int nx= p.second+dx[i];
      
    	if(0<=ny && ny<H && 0<=nx && nx<W && s[ny][nx]=='.' && d[ny][nx]==INF){
        	que.push(P(ny,nx));
          	d[ny][nx]=d[p.first][p.second]+1;
        }
    }
  }
  return d[H-1][W-1];
}

int main() {
  //入力
	cin >>H>>W;
  	int count=0;
  	rep(i,H){
    	rep(j,W){
         cin >>s[i][j];
         if('.'==s[i][j]){count++;} 
        }
    }
  if(bfs()!=INF){
   count =count -bfs() -1;
  	cout<<count<<endl;//ok
  }
  else{cout<<"-1"<<endl;}
}

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

int main()
{
    int a[5], b[4];

    while( cin >> a[0] )
    {
        if( a[0] == 0 )
            break;
        for( int i = 0; i < 4; i++ )
            b[i] = 0;
        b[a[0]]++;
        for( int i = 1; i < 5; i++ )
        {
            cin >> a[i];
            b[a[i]]++;
        }

        if( b[1] != 0 && b[2] != 0 && b[3] != 0 || b[1] == 5 || b[2] == 5 || b[3] == 5 )
            for( int i = 0; i < 5; i++ )
                cout << 3 << endl;
        else
        {
            if( b[1] == 0 )
            {
                for( int i = 0; i < 5; i++ )
                    if( a[i] == 2 )
                        cout << 1 << endl;
                    else
                        cout << 2 << endl;
            }
            else if( b[2] == 0 )
            {
                for( int i = 0; i < 5; i++ )
                    if( a[i] == 3 )
                        cout << 1 << endl;
                    else
                        cout << 2 << endl;
            }
            else
            {
                for( int i = 0; i < 5; i++ )
                    if( a[i] == 1 )
                        cout << 1 << endl;
                    else
                        cout << 2 << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3108
n = int(input())
for i in range(n):
    x1, y1, x2, y2, x3, y3, x4, y4 = map(float, input().split())
    if x1 == x2 and x3 == x4:
        print("YES")
    elif x1 == x2 or x3 == x4:
        print("NO")
    elif abs((y2 - y1) / (x2 - x1) - (y4 - y3) / (x4 - x3)) < 1e-10:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 7616
#include <iostream>
#include <cmath>
using namespace std;
int main(){
	long x , y , n , d;
	cin >> n >> d;
	int count=0;
	for (int i=0;i<n;i++){
		cin >> x >> y;
		double p=sqrt(x*x+y*y);
		if (p<=d){
			count++;
		}
		
	}
	cout << count << endl;
}



Measured memory_bytes: 3144
#include <cstdio>
typedef long long LL;
LL x, y, sum ;
int ans;

int main(){
	while(~scanf("%lld %lld", &x, &y)){
		sum = 1, ans = 0;
		for(LL i = x; i <= y; i = sum){
			sum = i * 2;
			if(sum <= y)
				ans++;
			else
				break;
		}
		printf("%d\n", ans + 1);
		}
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
int n1,n2;
int temp;
while(1){
   cin>>n1>>n2;
  if(n1==0 && n2==0){
   break;
  }
  if(n1<n2 || n1==n2){
   cout<<n1<<" "<<n2<<endl;
  }
else{
   temp=n1;
   n1=n2;
   n2=temp;
   cout<<n1<<" "<<n2<<endl;
     temp=0;
  }
}
}






Measured memory_bytes: 3004
#include <math.h>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <functional>
#include <typeinfo>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)
#define mp(a, b) make_pair(a, b)
#define all(vec) (vec).begin(), (vec).end()
#define yn(formula) (formula) ? (cout << "Yes" << endl) : (cout << "No" << endl)
#define YN(formula) (formula) ? (cout << "YES" << endl) : (cout << "NO" << endl)
#define MIN(a, b) ((a) < (b)) ? (a) : (b)
#define LLONG_MAX     9223372036854775807i64

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pii> vp;
typedef vector<pll> vpl;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vp> vvp;
typedef vector<vpl> vvpl;

constexpr double PI = 3.14159265358979323846;
constexpr ll INF = 1 << 29;
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-7;
constexpr int dy[4] = { 0, 1, 0, -1 };
constexpr int dx[4] = { 1, 0, -1, 0 };

struct edge { ll to; ll cost; };

ll Pow(ll a, ll b) {
	ll x = 1;
	while (b > 0) {
		if (b & 1) x = x * a;
		a = a * a;
		b = b >> 1;
	}
	return x;
}

/*<ここから>***********************************************************/




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

	int ans = 0;
	rep(i, b - a) ans += i;

	cout << ans - a << endl;





	return 0;
}

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

int main() {

    while(1){

        int h,w;

        cin >> h >> w;

        int diagonal = h*h + w*w;

        if(h==0 && w==0) break;

        pair<int,int> ans = make_pair(500,500); //first = h , second = w

        for(int i=1; i<151; i++){
            for(int j=i+1; j<151; j++){

                int check_rect_diagonal = i*i + j*j;

                if(diagonal < check_rect_diagonal || (diagonal == check_rect_diagonal && h < i)){

                    int ans_h = ans.first;
                    int ans_w = ans.second;

                    int ans_rect_diagonal = ans_h*ans_h + ans_w*ans_w;

                    if(check_rect_diagonal < ans_rect_diagonal || (check_rect_diagonal == ans_rect_diagonal && i < ans_h )){
                        ans = make_pair(i,j);
                    }



                }
            }
        }

        cout << ans.first << " " << ans.second << endl;




    }



    return 0;
}


Measured memory_bytes: 3012
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    cin >> n;
    n%=10;
    if(n==3)
        cout << "bon";
    else if(n==0||n==1||n==6||n==8)
        cout << "pon";
    else
        cout << "hon";
    return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a.at(i);
    }

    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());

    int ans = 0;

    for (int i = 0; i < N; i++) {
        if (i % 2 == 0) {
            ans = ans + a.at(i);
        } else {
            ans = ans - a.at(i);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;

int N, M;
vector<vector<bool>> adj;
vector<int> out;
vector<double> dp;
vector<double> probability;

double solve_dp() {
    dp.assign(N, 0);

    for (int i = N - 2; i >= 0; i--) {
        double sum = 0;

        for (int j = i + 1; j < N; j++)
            if (adj[i][j])
                sum += dp[j] + 1;

        dp[i] = sum / out[i];
    }

    return dp[0];
}

void solve_probability() {
    probability.assign(N, 0);
    probability[0] = 1;

    for (int i = 0; i < N; i++)
        for (int j = i + 1; j < N; j++)
            if (adj[i][j])
                probability[j] += probability[i] / out[i];
}

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

    cout << fixed << setprecision(12);

    cin >> N >> M;
    adj.assign(N, vector<bool>(N, false));
    out.assign(N, 0);

    for (int i = 0; i < M; i++) {
        int s, t;
        cin >> s >> t;
        s--; t--;
        adj[s][t] = true;
        out[s]++;
    }

    double base = solve_dp();
    double best = base;
    solve_probability();

    for (int s = 0; s < N; s++) {
        if (out[s] <= 1)
            continue;

        double worst = 0;

        for (int t = s + 1; t < N; t++)
            if (adj[s][t])
                worst = max(worst, dp[t]);

        double save = (dp[s] - 1) - ((dp[s] - 1) * out[s] - worst) / (out[s] - 1);
        best = min(best, base - probability[s] * save);
    }

    cout << best << '\n';
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define repd(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>; // グラフ型
using pint = pair<int, int>;

int main()
{
    int A, B ,C, D;
    cin >> A >> B >> C >> D;
    while(A > 0 && C >0){
        C = C - B;
        if (C<=0){
            cout << "Yes" << endl;
            return 0;
        }
        A = A - D;
                if (A<=0){
            cout << "No" << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3636
def MI():return map(int,input().split())
def LI():return list(MI())

x,y,a,b,c=MI()
p=sorted(LI())[::-1][:x]
q=sorted(LI())[::-1][:y]
r=sorted(LI())[::-1]

u=sorted(p+q+r)[::-1][:x+y]
print(sum(u))


Measured memory_bytes: 22528
lst = [1]*999999
for i in range(999999):
    if i == 0:
        lst[i] = 0
    else:
        if lst[i] == 1:
            j = i +1
            k = i
            while True:
                k = k + j
                if k >= 999999:
                    break
                        
                lst[k] = 0

while True:
    try:
        n = int(input())
        anslst = lst[:n]
        print(sum(anslst))
        

    except EOFError:
        break


Measured memory_bytes: 29988
import sys
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
ab=[list(map(int,input().split())) for i in range(n-1)]
li=[0]*(n+1)
for i in range(n-1):
    ab[i].append(i)
ab.sort()
for i in range(n-1):
    li[ab[i][0]]+=1
    li[ab[i][1]]+=1
print(max(li))
ma=max(li)
li2=[1]*(n+1)
ans=[]
for i in range(n-1):
    iro=li2[ab[i][0]]
    ans.append([ab[i][2],iro])
    
    if iro+1>ma:
        iro=0
    li2[ab[i][0]]=iro+1
    li2[ab[i][1]]=iro+1
ans.sort()
for i in range(n-1):
    print(ans[i][1])

Measured memory_bytes: 74844
// AOJ ALDS1_14_C Pattern Search
// 2018.5.13 bal4u

#include <stdio.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

#define MOD 1000000007LL
#define C1  401
#define C2  397

#define MAX_L 1005
char text[MAX_L][MAX_L]; int H, W;
char pat[MAX_L][MAX_L]; int R, C;
int  a[MAX_L][MAX_L], b[MAX_L][MAX_L];
int  t[MAX_L][MAX_L];

void genHash(int res[MAX_L][MAX_L], char s[MAX_L][MAX_L], int h, int w)
{
	int r, c;
	long long x, y, k;

	memset(t, 0, sizeof(t));
	memset(res, 0, sizeof(res));

	x = 1, y = 1;
	for (c = 0; c < C; c++) x = (x*C1) % MOD;
	for (r = 0; r < R; r++) y = (y*C2) % MOD;

	for (r = 0; r < h; r++) {
		k = 0;
		for (c = 0; c < C; c++) k = (k*C1 + s[r][c]) % MOD;
		for (c = 0; c <= w-C; c++) {
			t[r][c] = (int)k;
			if (c + C < w) k = (k*C1-s[r][c]*x+s[r][c+C]) % MOD;
			if (k < 0) k += MOD;
		}
	}

	for (c = 0; c < w; c++) {
		k = 0;
		for (r = 0; r < R; r++) k = (k*C2+t[r][c]) % MOD;
		for (r = 0; r <= h-R; r++) {
			res[r][c] = (int)k;
			if (r+R < h) k = (k*C2-t[r][c]*y+t[r+R][c]) % MOD;
			if (k < 0) k += MOD;
		}
	}
}

int main()
{
	int r, c;
	char ch, *p;

	H = in(), W = in();
	for (r = 0; r < H; r++) {
		p = text[r];
		while ((ch = gc()) > ' ') *p++ = ch;
		*p = 0;
	}

	R = in(), C = in();
	for (r = 0; r < R; r++) {
		p = pat[r];
		while ((ch = gc()) > ' ') *p++ = ch;
		*p = 0;
	}

	genHash(a, text, H, W);
	genHash(b, pat, R, C);

	for (r = 0; r <= H-R; r++) for (c = 0; c <= W-C; c++) {
		if (a[r][c] == b[0][0]) printf("%d %d\n", r, c);
	}
	return 0;
}


Measured memory_bytes: 10644
#include <stdio.h>

int main(){

    int a;
    int b;
    int c;
    int o[2]; //output

    scanf("%d %d %d",&a,&b,&c);
    
    //o[0] > o[1] > o[2]
    if(a > b && a > c){

        o[0] = a;

        if(b > c){
            o[1] = b;
            o[2] = c;
        }else{
            o[1] = c;
            o[2] = b;
        }      

    }else if(b > a && b > c){

        o[0] = b;       

        if(a > c){
            o[1] = a;
            o[2] = c;
        }else{
            o[1] = c;
            o[2] = a;
        }      

    }else{
        o[0] = c;       

        if(a > b){
            o[1] = a;
            o[2] = b;
        }else{
            o[1] = b;
            o[2] = a;
        }      

    }

    printf("%d %d %d\n",o[2],o[1],o[0]);

    return 0;
}

Measured memory_bytes: 1860
#include "iostream"
#include "string"


int main()
{
	int n;
	int max = -100000000;
	int min = 100000000;
	long int sum = 0;
	long int in[10000];
	std::cin >> n;

	for (int i = 0; i < n; i++) std::cin >> in[i];

	for (int i = 0; i < n; i++) sum += in[i];

	for (int i = 0; i < n; i++) {
		if (in[i] < min) min = in[i];
	}

	for (int i = 0; i < n; i++) {
		if (in[i] > max) max = in[i];
	}

	std::cout << min << " " << max << " " << sum << std::endl;

    return 0;
}

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

namespace AtCoder
{
    partial class Program
    {
       
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var n = input[0];
            var a = input[1];
            var b = input[2];

            Console.WriteLine(Math.Min(n * a, b));

        }
    }
}

Measured memory_bytes: 13268
import enum
class Direction(enum.Enum):
    N = "N"
    E = "E"
    W = "W"
    S = "S"

    @classmethod
    def value_of(cls, value):
        return [v for v in cls if v.value == value][0]


class Dice:
    def __init__(self, *value_list):
        self.__value_list = list(value_list)

    def rotate(self, direction):
        l = self.__value_list
        if  direction == Direction.N:
            l[0],l[1],l[5],l[4] = l[1],l[5],l[4],l[0]
        elif  direction == Direction.E:
            l[0],l[2],l[5],l[3] = l[3],l[0],l[2],l[5]
        elif  direction == Direction.W:
            l[0],l[2],l[5],l[3] = l[2],l[5],l[3],l[0]
        elif  direction == Direction.S:
            l[0],l[1],l[5],l[4] = l[4],l[0],l[1],l[5]
        
    def top_value(self):
        return self.__value_list[0]


dice = Dice(*input().split())
for i in input():
    dice.rotate(Direction.value_of(i))
print(dice.top_value())


Measured memory_bytes: 6308
n=int(input())
a=list(map(int,input().split()))

cout=0
while True:

	bre=False
	for i in a:
		if i%2==1:
			bre=True
			break
	if bre:
		break

	cout+=1
	for i in range(n):
		a[i]=a[i]/2


print(cout)

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

using namespace std;

using ll = long long;
using ld = long double;

const ll INF = 1e15;

inline ld calc(ll vmax, ll vmin, ll vmax_r, ll vmin_r, ll vmax_l, ll vmin_l, ld t) {
    return max({(ld)vmax, vmax_r + t, vmax_l - t}) - min({(ld)vmin, vmin_r + t, vmin_l - t});
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> x(n), y(n);
    vector<char> d(n);

    ll xmax = -INF, xmin = INF, ymax = -INF, ymin = INF;
    ll ymax_u = -INF, ymin_u = INF, ymax_d = -INF, ymin_d = INF;
    ll xmax_l = -INF, xmin_l = INF, xmax_r = -INF, xmin_r = INF;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i] >> d[i];
        if (d[i] == 'U') {
            xmax = max(xmax, x[i]);
            xmin = min(xmin, x[i]);
            ymax_u = max(ymax_u, y[i]);
            ymin_u = min(ymin_u, y[i]);
        } else if (d[i] == 'D') {
            xmax = max(xmax, x[i]);
            xmin = min(xmin, x[i]);
            ymax_d = max(ymax_d, y[i]);
            ymin_d = min(ymin_d, y[i]);
        } else if (d[i] == 'L') {
            ymax = max(ymax, y[i]);
            ymin = min(ymin, y[i]);
            xmax_l = max(xmax_l, x[i]);
            xmin_l = min(xmin_l, x[i]);
        } else {
            ymax = max(ymax, y[i]);
            ymin = min(ymin, y[i]);
            xmax_r = max(xmax_r, x[i]);
            xmin_r = min(xmin_r, x[i]);
        }
    }

    ld L = 0, R = 1e8;
    for (int i = 0; i <= 150; i++) {
        ld mid1 = (L * 2 + R) / 3;
        ld x1 = calc(xmax, xmin, xmax_r, xmin_r, xmax_l, xmin_l, mid1);
        ld y1 = calc(ymax, ymin, ymax_u, ymin_u, ymax_d, ymin_d, mid1);
        ld val1 = x1 * y1;

        ld mid2 = (L + R * 2) / 3;
        ld x2 = calc(xmax, xmin, xmax_r, xmin_r, xmax_l, xmin_l, mid2);
        ld y2 = calc(ymax, ymin, ymax_u, ymin_u, ymax_d, ymin_d, mid2);
        ld val2 = x2 * y2;

        if (val1 < val2) R = mid2;
        else L = mid1;    
    }

    ld x1 = calc(xmax, xmin, xmax_r, xmin_r, xmax_l, xmin_l, L);
    ld y1 = calc(ymax, ymin, ymax_u, ymin_u, ymax_d, ymin_d, L);
    ld val1 = x1 * y1;

    ld x2 = calc(xmax, xmin, xmax_r, xmin_r, xmax_l, xmin_l, R);
    ld y2 = calc(ymax, ymin, ymax_u, ymin_u, ymax_d, ymin_d, R);
    ld val2 = x2 * y2;    
    cout << fixed << setprecision(15) << min(val1, val2) << "\n";
    return 0;
}


Measured memory_bytes: 1920
N = input()
K = int(input())

DP = [[[0 for i in range(K+1)] for i in range(2)] for i in range(len(N))]

for d in range(int(N[0])+1):
    DP[0][d<int(N[0])][d!=0] += 1

for i in range(len(N)-1):
    for j in range(2):
        for k in range(K+1):
            for d in range(10 if j else int(N[i+1])+1):
                if k+(d!=0) <= K:
                    DP[i+1][j|(d<int(N[i+1]))][k+(d!=0)] += DP[i][j][k]

print(DP[len(N)-1][0][K]+DP[len(N)-1][1][K])

Measured memory_bytes: 3064
#include <stdio.h>

int main() {
	int H ;
	int A ;
	int c ;
	int d ;
	scanf("%d%d",&H,&A ) ;
	c = H/A ;
	d = H % A ;
	
	d > 0 ? printf("%d", c + 1 ) : printf("%d", c) ;
	return 0;
	
}

Measured memory_bytes: 1696
N = int(input())
#h = map(int, input().split())
h = input().split()
H = [int(i) for i in h]
for i in reversed(range(N-1)):
    if H[i] > H[i+1]:
        H[i] -= 1
is_yes = True
for i in range(N-1):
    if H[i] > H[i+1]:
        is_yes = False
        break
if is_yes:
    print("Yes")
else:
    print("No")
    

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


int main()
{
    int n,k;
    cin >> n >>k;
    int inp[n+10];

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

    vector<int>dp(n+10,INT_MAX);

    dp[0]=0;

    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<=i+k;j++)
        {

            if(j<n)
            {
                dp[j]=min(dp[j],dp[i]+abs(inp[i]-inp[j]));
            }
        }
    }
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();

		System.out.print(A * N < B ? A * N : B);
	}
}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
//#include<boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;

#define int long long
#define cint cpp_int
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) (((a)+(b)-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2
#define PI acos(-1.0)

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;
typedef priority_queue<int> PQi;

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;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vout(Vs &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[i]);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int mypow(int x, int n, int m){if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digit(int k,int i){string s = to_string(k);return s[s.size()-i]-'0';}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());} //vectorの同じ要素消す
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
int leng(int n){string s=to_string(n); return s.size();} //intの桁数
int digitsum(int n){int ret=0; while(n>0){ret+=n%10;n/=10;}return ret;} //桁和
int lesscount(int x,Vi &a){return lower_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx未満の数の個数
int orlesscount(int x,Vi &a){return upper_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx以下の数の個数
int morecount(int x,Vi &a){return a.size()-orlesscount(x,a);} //vector aにおけるxより大きい数の個数
int ormorecount(int x,Vi &a){return a.size()-lesscount(x,a);} //vector aにおけるx以上の数の個数
int count(int x,Vi &a) {return upper_bound(ALL(a),x)-lower_bound(ALL(a),x);} //vector aにおけるxの個数
Vi accum(Vi &v){Vi ret((v).size()+1);REP(i,0,(v).size()) ret[i+1]=ret[i]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);
    int n;
    cin>>n;
    Vi a(n);
    REP(i,0,n) cin>>a[i];

    map<int,int> ball_count;
    REP(i,0,n){
        ball_count[a[i]]++;
    }
    int allans=0;
    for(auto x : ball_count){
        allans += x.second*(x.second-1)/2;
    }
//    cout<<allans<<endl;
    REP(i,0,n){
        int kballs=ball_count[a[i]];
        cout<< allans - kballs*(kballs-1)/2 + (kballs-1)*(kballs-2)/2 <<endl;
    }
    return 0;
}


Measured memory_bytes: 11136
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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

    string S; cin >> S;
    int N = S.size();
    
    string ans = "Yes";
    REP(i,N) {
        if ((i%2==0 && S[i]=='L') ||
            (i%2==1 && S[i]=='R')) {
            ans = "No";
            break;
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 100005
#define pii pair<int,int>
#define endl '\n'
using namespace std;
vector<int> G[maxn];
bool vis[maxn];
int arr[maxn];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	for(int i=1,u,v;i<n;i++) {
		cin >> u >> v;
		G[u].emplace_back(v);
		G[v].emplace_back(u);
	}
	int k;
	cin >> k;
	set<pii> s;
	for(int i=0,u,val;i<k;i++) {
		cin >> u >> val;
		vis[u] = true;
		arr[u] = val;
		s.insert(make_pair(arr[u],u));
	}
	while(!s.empty()) {
		pii now = *s.begin();
		s.erase(now);
		int u = now.second;
		for(int v : G[u])
			if(!vis[v]) {
				vis[v] = true;
				arr[v] = arr[u] + 1;
				s.insert(make_pair(arr[v],v));
			}
	}
	bool ans = true;
	for(int u=1;u<=n;u++)
		for(int v : G[u])
			if(abs(arr[u]-arr[v]) != 1)
				ans = false;
	if(!ans)
		cout << "No" << endl;
	else {
		cout << "Yes" << endl;
		for(int i=1;i<=n;i++)
			cout << arr[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 11648
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C


# See:
# https://beta.atcoder.jp/contests/abc052/submissions/2246922
def get_prime_dict(number: int) -> dict:
    ''' number: 2 or greater.
    '''
    from collections import OrderedDict

    prime_dict = OrderedDict()
    j = 2
    prime_dict[j] = 0

    for i in range(2, number + 1):
        if all(i % j != 0 for j in prime_dict.keys()):
            prime_dict[i] = 0
    return prime_dict


def execute_prime_factorization(primes: dict, number: int):
    for key in primes.keys():
        if number >= key:
            tmp = number

            while tmp >= key:
                if tmp % key == 0:
                    primes[key] += 1
                    tmp = int(tmp / key)
                else:
                    break
    return primes


if __name__ == '__main__':
    number = int(input())

    if number == 1:
        print(1)
        exit()

    # See:
    # https://atcoder.jp/img/arc067/editorial.pdf
    primes = get_prime_dict(number)
    count = 1

    for i in range(2, number + 1):
        execute_prime_factorization(primes, i)

    for value in primes.values():
        count = ((value + 1) * count) % (10 ** 9 + 7)

    print(count)


Measured memory_bytes: 3316
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let N = read int
    let ds = reads int
    let mutable ans = 0
    for i in [0..N-2] do
        let es = Seq.skip i ds
        let f = Seq.head es
        let gs = Seq.tail es
        let h = Seq.fold (fun s x -> s + x * f) 0 gs
        ans <- ans + h
    printfn "%i" ans
    0

Measured memory_bytes: 14172
import java.util.*;
import java.lang.*;
 
public class Main {
    public static void main(String[] args) {
 
        Scanner sc  = new Scanner(System.in);
 
        int N = Integer.parseInt(sc.next());
        if(N==1)  N = 1;
        else if(N>=2 &&N<=3)   N = 2;
        else if(N>=4 &&N<=7)   N = 4;
        else if(N>=8 &&N<=15)  N = 8;
        else if(N>=16&&N<=31)  N = 16;
        else if(N>=32&&N<=63)  N = 32;
        else if(N>=64&&N<=101) N = 64;
        
        System.out.print(N);
 
        System.out.println();
    }
 
}

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

int main(){
    int n, k;
    cin >> n >> k;
    // vector<int> d(k);
    // vector<vector<int>> a(k,vector<int>());
    // for(int i = 0; i < k; i++){
    //     cin >> d[i];
    //     for(int j = 0; j < d[i]; j++){
    //         int tmp;
    //         cin >> tmp;
    //         a[i].push_back(tmp);
    //     }
    // }

    vector<bool> doesOkashiHave(n, false);
    for(int i = 0; i < k; i++){
        int d;
        cin >> d;
        for(int j = 0; j < d; j++){
            int a;
            cin >> a;
            doesOkashiHave[a - 1] = true;
        }
    }

    int ans = 0;
    for(int i = 0; i < n; i++){
        if(doesOkashiHave[i] == false){
            ans++;
        }
    }

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

Measured memory_bytes: 3628
main = do
    [n] <- getInt <$> getLine
    ta <- getIntLines n
    putStrLn $ show $ answer ta
    
getInt :: String -> [Int]
getInt = map read . words

getIntLines :: Int -> IO [[Int]]
getIntLines n = sequence $ take n $ repeat $ getInt <$> getLine

answer :: [[Int]] -> Int
answer (ta:tas) = sum $ foldl foldfunc ta tas

foldfunc :: [Int] -> [Int] -> [Int]
foldfunc [at,aa] [t,a] = let alp = max (ceildiv at t) (ceildiv aa a)
                         in [alp * t, alp * a]

ceildiv :: Int -> Int -> Int
ceildiv x y = x `div` y + (if x `mod` y == 0 then 0 else 1)


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
#define endl "\n"
#define print_array(name,n) for(ll o=0;o<n;o++) cout<<name[o]<<" "
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 2e18
#define pll pair<ll,ll>
#define pii pair<int,int>
bool sortbysecond(const pair<int,int> &a,const pair<int,int> &b){
	return (a.ss>b.ss);
}
 
ll gcd(ll a,ll b){ if(b==0) return a; return gcd(b,a%b) ;} 

template <typename T>
string NumberTostring(T Number )
{
	ostringstream ss;
	ss<<Number;
	return ss.str();
}
 

 
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
 	ll n,k;
 	cin>>n>>k;
 	vector<ll> vec(n,0);
 	for(int i=0;i<n;i++){
 		cin>>vec[i];
 	}
 	sort(vec.begin(),vec.end());
 	ll ans = 0;
 	for(int i=0;i<k;i++){
 		ans+=vec[i];
 	}   
 	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i < (n); i++)

int main(){
    int x;
    cin >> x;
    if(x<30) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 3588
K,N=map(int,input().split())
A=list(map(int,input().split()))
R=[]
for i in range(N):
    if i == N-1:
        R.append(abs(A[i]-(K+A[0])))
    else:
        R.append(abs(A[i]-A[i+1]))
R.sort(key=int)
print(K-R.pop(-1))

Measured memory_bytes: 26444
K,A,B = map(int,input().split())
if A>=B-2 or K<A+1:
    cnt = K+1
else:
    if (K-A-1)%2==0:
        cnt = B+((K-A-1)//2)*(B-A)
    else:
        cnt = B+((K-A-1)//2)*(B-A)+1
print(cnt)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
using namespace std;
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a + b > c + d)
		cout << "Left" << "\n";
	else if (a + b < c + d)
		cout << "Right" << "\n";
	else
		cout << "Balanced" << "\n";
}

Measured memory_bytes: 3556
import sys
import copy
n = int(input())
p = list(map(int,input().split()))
flag = True
for i in range(1,n):
     if p[i] < p[i-1]:
          flag = False
          continue
if flag:
     print('YES')
     sys.exit()

for i in range(n-1):
     for j in range(i,n):
          pp = copy.deepcopy(p)
          pp[i] = copy.deepcopy(p[j])
          pp[j] = copy.deepcopy(p[i])
          flag = True

          for k in range(1, n):
               if pp[k] < pp[k - 1]:
                    flag = False
                    continue
          if flag:
               print('YES')
               sys.exit()

print('NO')


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

int main(){
    long sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    long cx=0,cy=0;
    F(tx-sx+ty-sy){
        if(i<ty-sy){
            cout << 'U';
        }
        else{
            cout << 'R';
        }
    }
    F(tx-sx+ty-sy){
        if(i<ty-sy){
            cout << 'D';
        }
        else{
            cout << 'L';
        }
    }
    F(tx-sx+ty-sy+4){
        if(i==0){
            cout << 'L';
        }
        else if(i<ty-sy+2){
            cout << 'U';
        }
        else if(i<tx-sx+ty-sy+3){
            cout << 'R';
        }
        else{
            cout << 'D';
        }
    }
    F(tx-sx+ty-sy+4){
        if(i==0){
            cout << 'R';
        }
        else if(i<ty-sy+2){
            cout << 'D';
        }
        else if(i<tx-sx+ty-sy+3){
            cout << 'L';
        }
        else{
            cout << 'U';
        }
    }
    cout << endl;
    return 0;
}

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

int main() {
  int n,sum;
  cin>>n;
  int a[n+1],b[n+1],c[n];
  
  for(int i = 1; i <= n; i++) cin>>a[i];
  for(int i = 1; i <= n; i++) cin>>b[i];
  for(int i = 1; i <= n-1; i++) cin>>c[i];
  sum = b[a[1]];
  for(int i = 2; i <= n; i++) {
      sum += b[a[i]];
      if(a[i] == a[i-1] + 1) sum += c[a[i-1]];
  }
  cout<<sum<<"\n";
  
  
  return 0;
}

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

const int INF = 1001001001;
vector<int> to[100005];

int main()
{
    int n, m;
    cin >> n >> m;
    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    queue<int> q;
    vector<int> dist(n, INF);
    vector<int> pre(n, -1);
    dist[0] = 0;
    q.push(0);
    while (!q.empty())
    {
        int v = q.front();
        q.pop();
        for (int e : to[v])
        {
            if (dist[e] != INF)
            {
                continue;
            }
            dist[e] = dist[v] + 1;
            pre[e] = v;
            q.push(e);
        }
    }

    cout << "Yes" << endl;
    rep(i, n)
    {
        if (i == 0)
            continue;
        int ans = pre[i];
        ans++;
        cout << ans << endl;
    }
    return 0;
}


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

#define ll long long
#define ld long double
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define ppb pop_back
#define vll vector<ll>
#define vi vector<int>
#define endl "\n"

const ll INF = 1000000007;

/*
const int max_size = 100001;
int parent[max_size];
int Size[max_size];

int root(int x){
	while(x!=parent[x]){
		parent[x] = parent[parent[x]];
		x = parent[x];
	}
	return x;
}

void sunion(int x,int y){
	int rx = root(x);
	int ry = root(y);
	if(rx != ry){
		if(Size[rx] > Size[ry]){
			parent[ry] = parent[rx];
			Size[rx] += Size[ry];
		}
		else{
			parent[rx] = parent[ry];
			Size[ry] += Size[rx];
		}
	}
}
*/

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin >> t;
	while(t--){
		ll n;
		cin >> n;
		ll sum=0LL;
		for(ll i=1;i<=n;i++){
			if(i%3!=0 && i%5!=0) sum += i;
		}
		cout << sum << endl;
	}
	return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define int  long long
#define tc(t)  int t; cin>>t; while(t--)
#define f(n)    for(int i=1;i<=n;i++)
#define endl   "\n"







int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    vector<int> height(n+1);
    height[0]=0;
    f(n)cin>>height[i];
    vector<int>dp(n+1,0);
    dp[0]=0;
    dp[1]=0;
    dp[2]=abs(height[2]-height[1]);
    for(int i=3;i<=n;i++)
    {
        dp[i]=  min(abs(height[i]-height[i-1])+dp[i-1],abs(height[i]-height[i-2])+dp[i-2]);

    }
    
    cout<<dp[n]<<endl;




}

Measured memory_bytes: 4728
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
static const double EPS = 1e-8;
typedef long long ll;


const int MAX = 501;
bool edge[MAX][MAX];
bool flow[MAX][MAX];

int N, E, Q;

bool used[500];
bool _dfs(int s, int t)
{
	if (s == t)
		return true;

	used[s] = true;
	for (int i = 1; i <= N; ++i)
	{
		if (!used[i] && edge[s][i])
		{
			if (!flow[s][i])
			{
				if (_dfs(i, t))
				{
					if (flow[i][s])
						flow[i][s] = false;
					else
						flow[s][i] = true;
					//flow[s][i] = true;
					return true;
				}
			}
			else if (flow[i][s])
			{
				if (_dfs(i, t))
				{
					flow[i][s] = false;
					return true;
				}
			}
		}
	}
	return false;
}
bool dfs(int s, int t)
{
	fill(used, used+N+1, false);
	return _dfs(s, t);
}

int main()
{
	scanf("%d%d%d", &N, &E, &Q);
	for (int i = 0; i < E; ++i)
	{
		int f, t;
		scanf("%d%d", &f, &t);
		edge[f][t] = edge[t][f] = true;
	}

	int res = 0;
	while (dfs(1, N))
		++res;

	for (int i = 0; i < Q; ++i)
	{
		int	m, a, b;
		scanf("%d%d%d", &m, &a, &b);

		if (m == 1)
		{
			edge[a][b] = edge[b][a] = true;
			if (dfs(1, N))
				++res;
		}
		else
		{
			edge[a][b] = edge[b][a] = false;

			if (flow[a][b] && !dfs(a, b))
			{
				dfs(a, 1);
				dfs(N, b);
				--res;
			}
			if (flow[b][a] && !dfs(b, a))
			{
				dfs(b, 1);
				dfs(N, a);
				--res;
			}
			flow[a][b] = flow[b][a] = false;
		}

		printf("%d\n", res);
	}
	return 0;
}

Measured memory_bytes: 1376
H,W = map(int,input().split())
road = [input()for i in range(H)]
rightest = 0
bottomest = 0
for i in range(H):
    for j in range(W):
        if road[i][j] == '#':
            if j < rightest:
                print('Impossible')
                exit()
            rightest = j
print('Possible')

Measured memory_bytes: 61836
#include <iostream>
#include <vector>

using namespace std;
 struct node
 {
     bool check = false;
     int w = 0;
 }t;

 int main()
 {
     int n, m, p;
     string s;
     cin >> n >> m;
     vector <node> vec(n + 1);
     int right = 0, palanti = 0;
     for(int i = 0; i < m; i++)
     {
         cin >> p >> s;
         if(vec[p].check == false)
         {
             if(s == "AC")
             {
                 right++;
                 vec[p].check = true;
             }
             else{
                vec[p].w++;
             }
         }
     }

     for(int i = 0; i < vec.size(); i++)
     {
         if(vec[i].check)
         {
             palanti = palanti + vec[i].w;
         }
     }

     cout << right << " " << palanti << endl;

     return 0;
 }


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
 
void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}
 
int main(){
  ll N; cin>>N;
  if(N%2==0){
    ld a=N/2;
    ld p=a/N;
    cout<<std::setprecision(10)<<p<<endl;
  }
  else{
    ld a=N/2+1;
    ld p=a/N;
    cout<<std::setprecision(10)<<p<<endl;
  }
}

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

int main(){
    string x;
    cin >> x;

    stack<char> word;
    for(int i=0; i<x.length(); i++){
        if(word.empty() == false && word.top() == 'S' && x[i] == 'T') word.pop();
        else word.push(x[i]);
    }
    cout << word.size() << endl;
    return 0;
}

Measured memory_bytes: 3816