akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int gcd(int a,int b,int d){
	int c;
    c = a%b;
    while( c > 0 )
    {
        a = b;
        b = c;
        c = a%b;
    }
    a = d;
    c = a%b;
    while( c > 0 )
    {
        a = b;
        b = c;
        c = a%b;
    }
  return b;
}
int main(){
	int n;
	scanf("%d",&n);
	int i,j,k;
	int sum=0;
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			for(k=1;k<=n;k++){
				sum+=gcd(i,j,k);
		}
	}
	
}
printf("%d",sum);
}

Measured memory_bytes: 1732
import java.util.Scanner;

public class Main {
    static int c;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] dp = new int[30];
        dp[0] = 1;
        dp[1] = 2;
        dp[2] = 4;
        for (int i = 3; i < 30; i++)
            dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3];
        for (;;) {
            int n = sc.nextInt();
            if (n == 0) {
                break;
            }
            System.out.println((int)Math.ceil((double)dp[n-1]/3650.0));
        }
    }

}


Measured memory_bytes: 26168
p=1
mx=1000000000000000000
n=int(input())
num=input().split()
z=num.count('0')
if(z!=0):
    print('0')
else:    
    for i in num:
        p*=int(i)
        if(p>mx):
            p=-1
            break
    print(p)

Measured memory_bytes: 19488
import java.util.*; 
import java.lang.*; 


public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
                
                int N = scan.nextInt();
               
                int C0 = 0;
                int C1 = 0;
                int C2 = 0;
                int C3 = 0;
                
                for(int i=0; i<N; i++){
                    String S = scan.next();
                    if(S.equals("AC")){
                        C0++;
                    }else if(S.equals("WA")){
                        C1++;
                    }else if(S.equals("TLE")){
                        C2++;
                    }else if(S.equals("RE")){
                        C3++;
                    }
                }
                
                System.out.println("AC x " + C0);
                System.out.println("WA x " + C1);
                System.out.println("TLE x " + C2);
                System.out.println("RE x " + C3);
             
        }               
}

Measured memory_bytes: 57896
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
int H[1000];
int main() {
	int N;
	int T, A;
	cin >> N;
	cin >> T >> A;
	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}
	int ans;
	double dif = 1e10;
	for (int i = 0; i < N; i++) {
		if (dif > abs(A - (T - H[i] * 0.006))) {
			dif = abs(A - (T - H[i] * 0.006));
			ans = i;
		}
	}
	cout << ans + 1 << endl;
}

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

int main(){
  int n,x;
  cin >> n;
  vector<int> X1, X2;
  for(int i=0;i<n;i++){
    cin >> x;
    X1.push_back(x);
  }
  X2 = X1;
  sort(X2.begin(), X2.end());
  for(int i=0;i<n;i++){
    if(X1[i]<=X2[n/2-1]){
      cout << X2[n/2] << endl;
    }else{
      cout << X2[n/2-1] << endl;
    }
  }
  return 0;

}


Measured memory_bytes: 3828
#include <stdio.h>

int main (int argc,char **argv)
{
	int a,b;
	int c;

	scanf("%d%d",&a,&b);
	c = a + b;

	if (c >= 24)
	{
		printf("%d\n",c-24);
	}

	else
	{
		printf("%d\n",c);
	}

	return 0;


}

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

typedef long long ll;

int main(){
	ll n,a[82];
	scanf("%lld",&n);
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
	
	ll ret[2]={1000,0};
	for(int i=0;i<n;i++){
		if(i==n-1||a[i]>a[i+1]){
			ret[0]+=a[i]*ret[1];
			ret[1]=0;
		}
		else {
			ret[1]+=ret[0]/a[i];
			ret[0]%=a[i];
		}
	}
	cout<<ret[0]<<endl;
}

Measured memory_bytes: 3764
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define pie 3.141592653589793238462643383279
#define int long long
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1)*x%mod;
}

int mod_pow(int x, int y, int mood) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%mood;
		x = x * x%mood;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

int n,a[300][300];
int cnt[310][310];
int ans;

signed main() {
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin>>a[i][j];
			cnt[i][j]=a[i][j];
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			for(int k=0;k<n;k++){
				cnt[i][j]=min(cnt[i][j],cnt[i][k]+cnt[k][j]);
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i==j)continue;
			int mi=INF;
			for(int k=0;k<n;k++){
				if(i==k||j==k)continue;
				mi=min(mi,cnt[i][k]+cnt[k][j]);
			}
			if(mi<a[i][j]){
				cout<<-1<<endl;
				return 0;
			}
			if(mi>a[i][j])ans+=a[i][j];
		}
	}
	cout<<ans/2<<endl;
}



Measured memory_bytes: 1664
N = gets.to_i
p = gets.split.map(&:to_i)

s = Array.new(N)
N.times do |i|
  
  s[i] = p[i]-1 != i ? true : false
  
end


ans = 0
N.times do |i|
  
  if s[i] == false
    s[i] = true
    ans += 1
    
    if i+1 <= N - 1 
      s[i+1] = true
    end
  end
      
end

puts ans

Measured memory_bytes: 8836
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#define int long long
#define MAX(a,b) ((a) > (b)) ? (a) : (b)
#define MIN(a,b) ((a) < (b)) ? (a) : (b)
using namespace std;

//131072 = 1<<17 = 2^17
#define SEG_MAX (1 << 17)
int seg[SEG_MAX * 2] = { 0 };

//[a,b]にxを加算 (節点kをベースに[l,r]を足す)
void add(int a, int b, int x, int k = 0, int l = 0, int r = SEG_MAX - 1)
{
	if (a <= l && r <= b)
	{
		seg[k] += x;
	}
	else
	{
		int l0 = l;
		int r0 = l + (r - l) / 2;
		int l1 = r0 + 1;
		int r1 = r;
		if (a <= r0)
		{
			int kk = 2 * k + 1;
			add(a, b, x, kk, l0, r0);
		}
		if (l1 <= b)
		{
			int kk = 2 * k + 2;
			add(a, b, x, kk, l1, r1);
		}
	}
}

int get(int index)
{
	int sum = 0;
	int k = SEG_MAX - 1 + index; //根
	while (true)
	{
		sum += seg[k];
		if (k == 0) break;
		k = (k - 1) / 2;
	}
	return sum;
}


struct St
{
	int l;
	int r;
	int sub;
	
	bool operator <(const St& st) const
	{
		return sub > st.sub;
	}
};

priority_queue<St> q;
vector<St> end_list;
int a[100001] = { 0 };

signed main()
{
	int n, m;
	cin >> n >> m;
	
	for (int i = 0; i < n; i++)
	{
		St st;
		cin >> st.l >> st.r;
		st.sub = st.r - st.l;
		q.push(st);
	}

	for (int i = 0; i < m; i++)
	{
		int step = i + 1;
		while (q.size() > 0)
		{
			const St& top = q.top();
			if (top.sub + 1 < step)
			{
				//for (int i = top.l; i <= top.r; i++)
				//{
				//	a[i]++;
				//}
				add(top.l, top.r, 1);
				q.pop();
			}
			else
			{
				break;
			}
		}

		int cnt = 0;
		for (int j = step; j <= m; j += step)
		{
			//cnt += a[j];
			cnt += get(j);
		}

		cnt += q.size();
		cout << cnt << endl;
	}
}


Measured memory_bytes: 12652
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define MAX 10000005
#define mod 1000000007
#define sp fixed<<setprecision(12)
using namespace std;
/*
vector<int> primes;
ll sumprime[MAX];
bool is_prime[MAX];
void sieve(){
    is_prime[0]=is_prime[1]=true;
    for(int i=4;i<MAX;i+=2){
        is_prime[i]=true;
    }
    for(int i=3;i*i<MAX;i+=2){
        if(!is_prime[i]){
            for(int j=i*i;j<MAX;j+=i){
                is_prime[j]=true;
            }
        }
    }
    for(int i=0;i<MAX;i++){
        if(!is_prime[i]){
            sumprime[i]=sumprime[i-1]+i;
        }else{
            sumprime[i]=sumprime[i-1];
        }
    }
}
*/

void lcs(char s1[],char s2[]){
    int n=strlen(s1);
    int m=strlen(s2);
    vector<vector<int>> dp(n+1,vector<int>(m+1,0));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            int sum=0;
            if(s1[i-1]==s2[j-1]){
                sum=1+dp[i-1][j-1];
            }
            else{
                sum=max(dp[i-1][j],dp[i][j-1]);
            }
            dp[i][j]=sum;
        }
    }
    
    int index=dp[n][m];
    //cout<<index<<endl;
    char ans[index+1];
    ans[index]='\0';
    index--;
    int x=n;
    int y=m;
    while(x>0 and y>0){
        if(dp[x-1][y]==dp[x][y-1] and dp[x-1][y]!=dp[x][y]){
            ans[index]=s1[x-1];
            index--;
            x--;
            y--;
        }else if(dp[x-1][y]>dp[x][y-1]){
            x--;
        }else{
            y--;
        }

    }
    //reverse(ans.begin(),ans.end());

    cout<<ans;
    return;
}

using namespace std;
int32_t main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    //double    pi=3.14159265358979323846;
    //sieve();
    int t=1;
    //cin>>t;
    for(int tc=1;tc<=t;tc++){
        char s1[3001],s2[3001];
        cin>>s1>>s2;
        lcs(s1,s2);

    }
    
    
    
    
    
    return 0;
    
}

Measured memory_bytes: 73660
#include<bits/stdc++.h>
#define ll long long
using namespace std;
char s[1000010];
int main()
{
	ios::sync_with_stdio(false);
	int n;cin>>n;cin>>s+1;
	if(n&1)
	{
		cout<<"No"<<endl;
		return 0;
	}
	for(int i=1;i<=(n+1)/2;++i)
		if(s[i]!=s[i+n/2])
		{
			cout<<"No"<<endl;
			return 0;
		}
		cout<<"Yes"<<endl;	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
    
class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long x = sc.nextLong();
        sc.close();

        System.out.println((b+x)/x-(a-1+x)/x);
    }
}

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




int main(){
    string s; cin>>s;
    ll cnt=0;
    rep(i,s.size()){
        cnt+=(s[i]-'0');
    }
    if(cnt%9==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3688
# -*- coding:utf-8 -*-
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
count=0
for i in range(N,0,-1):
    if A[i]<=B[i-1]:
        count=count+A[i]
        B[i-1]=B[i-1]-A[i]
        if A[i-1]>=B[i-1]:
            count=count+B[i-1]
            A[i-1]=A[i-1]-B[i-1]
        else:
            count=count+A[i-1]
            A[i-1]=0
    else:
        count=count+B[i-1]
        B[i-1]=0
print(count)

Measured memory_bytes: 18828
n, m = map(int, input().split())
A = []
for i in range(n):
  A.append(list(map(int, input().split())))
cost = 0
count = 0
A.sort(key = lambda x:x[0])
for i in range(n):
  if count == m:
    break
  elif count + A[i][1] <= m:
    cost += A[i][1] * A[i][0]
    count += A[i][1]
  else:
    while count < m:
      cost += A[i][0]
      count += 1
print(cost)

Measured memory_bytes: 29024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[][][] ar = new int[4][3][10];
		for ( int i = 0; i < n; i++) {
			int b = scan.nextInt();
			int f = scan.nextInt();
			int r = scan.nextInt();
			int v = scan.nextInt();
			ar[b-1][f-1][r-1] += v;
		}
		for (int b = 0; b < 4; b++) {
			for (int i = 0; i < 3; i++) {
				for(int j = 0; j < 10; j++){
					System.out.print(" " + ar[b][i][j]);
				}
				System.out.println();
			}
			if (b != 3) {
				System.out.println("####################");
			}
		}
	}
}

Measured memory_bytes: 29872
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N, K;
  string S;
  cin >> N >> K >> S;
  if(S.at(K-1) == 'A'){
    S.at(K-1) = 'a';
  } else if(S.at(K-1) == 'B'){
    S.at(K-1) = 'b';
  } else if(S.at(K-1) == 'C'){
    S.at(K-1) = 'c';
  }
  cout << S << endl;
    
  return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

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

    cout << max({a, b, c}) - min({a, b, c}) << endl;
    return (0);
}


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

using namespace std;

int main()
{
    int pasta[3], juice[2];

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

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

    sort(pasta, pasta + 3);
    sort(juice, juice + 2);

    cout << pasta[0] + juice[0] - 50 << endl;
}




Measured memory_bytes: 3120
import java.util.*;
import java.awt.geom.*;

import static java.lang.Math.*;
public class Main {
	final Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main().init();
	}
	void init(){
		new AOJ1174();
	}
	class AOJ1174{
		AOJ1174(){
			while(sc.hasNext()){
				H=sc.nextInt();
				W=sc.nextInt();
				C=sc.nextInt();
				if((H|(W|C))==0)	break;
				solve();
			}
		}
		int H,W,C;
		int[][][] b;
		final int[] vx={0,-1,0,1},vy={-1,0,1,0};
		void solve(){
			b=new int[6][W][H];
			for(int h=0; h<H; ++h)for(int w=0; w<W; ++w)	b[0][w][h]=sc.nextInt();
			System.out.println(dfs(b,0,b[0][0][0]));
		}
		int dfs(int[][][] b,int depth,int last){
			if(depth>=4)	return cnt(change(depth, C));
			int ret=0;
			for(int c=1; c<=6; ++c){
				if(c==last)	continue;
				change(depth, c);
				ret=max(ret, dfs(b, depth+1, c));
			}
			return ret;
		}
		int[][] change(int d,int target){
			for(int w=0; w<W; ++w)for(int h=0; h<H; ++h)	b[d+1][w][h]=b[d][w][h];
			LinkedList<Pair> open=new LinkedList<Pair>();
			open.add(new Pair(0,0));
			b[d+1][0][0]=target;
			while(!open.isEmpty()){
				Pair now=open.poll();
				for(int v=0; v<4; ++v){
					int xx=now.x+vx[v], yy=now.y+vy[v];
					if(!(0<=xx&&xx<W && 0<=yy&&yy<H))	continue;
					if(b[d][xx][yy]!=b[d][0][0])	continue;
					if(b[d+1][xx][yy]==target)	continue;
					b[d+1][xx][yy]=target;
					open.add(new Pair(xx,yy));
				}
			}
			return b[d+1];
		}
		int cnt(int[][] a){
			LinkedList<Pair> open=new LinkedList<Pair>();
			open.add(new Pair(0,0));
			boolean[][] closed=new boolean[W][H];
			closed[0][0]=true;
			int cnt=1;
			while(!open.isEmpty()){
				Pair now=open.poll();
				for(int v=0; v<4; ++v){
					int xx=now.x+vx[v], yy=now.y+vy[v];
					if(!(0<=xx&&xx<W && 0<=yy&&yy<H))   continue;
					if(a[xx][yy]!=a[0][0])  continue;
					if(closed[xx][yy])  continue;
					open.add(new Pair(xx,yy));
					closed[xx][yy]=true;
					++cnt;
				}
			}
			return cnt;
		}
		class Pair{
			int x,y;
			Pair(int x,int y){
				this.x=x;
				this.y=y;
			}
		}
	}
}

Measured memory_bytes: 123596
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in=new Scanner(System.in);
		int N=in.nextInt();
		while(N-->0)
		{
			double xa=in.nextDouble(),ya=in.nextDouble(),ra=in.nextDouble();
			double xb=in.nextDouble(),yb=in.nextDouble(),rb=in.nextDouble();
			double l=Math.sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb));
			if(l>ra+rb)
				System.out.println(0);
			else if(ra>l+rb)
				System.out.println(2);
			else if(rb>l+ra)
				System.out.println(-2);
			else
				System.out.println(1);
		}
	}
}

Measured memory_bytes: 12000
import java.util.Scanner;

public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String line =sc.nextLine();
char change;


int length = line.length();

for (int i = 0; i < length; i++) {
char ch = line.charAt(i);

if(Character.isLowerCase(ch)){//これだけで小文字なら、が判別できる
   change= Character.toUpperCase(ch);
}else if(Character.isUpperCase(ch)){
   change= Character.toLowerCase(ch);
}else{
    change=ch;
}

    System.out.printf("%c",change);

}
System.out.printf("\n");


    sc.close();
}

}


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

//TLE
int gcd(int aa,int bb){
    int r=0;
    int a,b;
    if(aa>bb){
        a=aa;b=bb;
    }else{
        a=bb;b=aa;
    }
    r=a%b;
    if(r==0)return b;
    if(r==1)return 1;
    return gcd(r,b);
}


int main() {
    int N;
    cin >>N;
    vector<int> A(N);

    for(int i=0;i<N;i++){
        cin >> A.at(i);
    }
//----------------------
//Aにおいて特定要素を除いたGCDの最大値
//累積GCD
    vector<int> B(N,0);//.at()を除いたGCD
    
    vector<int> Gs(N,0);//累積GCD昇順
    vector<int> Gu(N,0);//累積GCD降順
    Gs.at(0)=A.at(0);
    Gu.at(N-1)=A.at(N-1);
    for(int i=1;i<N;i++){
        Gs.at(i)=gcd(Gs.at(i-1),A.at(i));
        Gu.at(N-i-1)=gcd(Gu.at(N-i),A.at(N-i-1));
    }
    B.at(0)=Gu.at(1);
    for(int i=1;i<N-1;i++)
        B.at(i)=gcd(Gs.at(i-1),Gu.at(i+1));
    B.at(N-1)=Gs.at(N-2);
    
    /*
    for(int i=0;i<N;i++)cout <<" "<< Gs.at(i);
    cout << endl;
    for(int i=0;i<N;i++)cout <<" " << Gu.at(i);
    cout << endl;
    for(int i=0;i<N;i++)cout <<" " << B.at(i);
    cout << endl;*/


    int maxs=B.at(0);
    for(int i=1;i<N;i++){maxs=max(maxs,B.at(i));}
    cout << maxs << endl;
}

Measured memory_bytes: 1792
/*input
4 3
1 2 6
3 4 5
2 3 7
*/
import java.util.Scanner;
import java.lang.*;
import java.util.Arrays;
import java.util.function.BinaryOperator;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;

class value {
	long h, p;
	value(long h, long p) {
		this.h = h;
		this.p = p;
	}
}

class cmp implements Comparator<value> {
	public int compare(value a, value b) {
		return (int)(a.h + a.p) - (int)(b.h + b.p);
	}
}

public class Main {
	private static final int N = (int)5e3 + 100;
	private static final long oo = (long) 1e18;

	static int n;
	static value[] a = new value[N];

	static Comparator<Long> CmpLong = new Comparator<Long>() {
		public int compare(Long x, Long y) {
			return (int)(y - x);
		}
	};

	public static void main(String[] args) {
		Scanner inp = new Scanner(System.in);
		n = inp.nextInt();
		for(int i = 1; i <= n; i += 1) {
			long h = inp.nextLong();
			long p = inp.nextLong();
			a[i] = new value(h, p);
		}
		ArrayList<value> tmp = new ArrayList<value>();
		for(int i = 1; i <= n ; ++i) tmp.add(a[i]);
		Collections.sort(tmp, new cmp());

		PriorityQueue<Long> pq = new PriorityQueue<Long>(CmpLong);
		long sum = 0L, ans = 0L;
		for(value v: tmp) {
			sum += v.p;
			pq.add(v.p);

			while(sum > v.h + v.p) {
				sum -= pq.remove();
			}
			ans = Math.max(ans, pq.size());
		}
		System.out.print(ans);
	}	
}

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

struct node{
  int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int);
void init(void);
void printList(void);
void deleteFirst(void);
void deleteLast(void);
void delete(int);
void insert(int);

int main(){
  int n,i,num,np,nd,size;
  char order[11];

  init();
  size = np = nd = 0;

  scanf("%d" ,&n);
  for(i = 0 ; i < n ; i++){
    scanf("%s %d" ,order ,&num);

    if(order[0] == 'i'){
      insert(num);
      np++; 
      size++;
    }else if(order[0] == 'd'){
      if(strlen(order) > 6){
	if(order[6] == 'F'){
	  deleteFirst();
	}else if(order[6] == 'L'){
	  deleteLast();
	}
      }else{
	delete(num);
	nd++;
      }
      size--;
    }
  }
  printList();

  return 0;
}

NodePointer listSearch(int key){
  NodePointer x,y;

  y = nil;
  x = y->next;

  while(x != nil){
    if(x->key == key){
      return y;
    }
    y = x;
    x = y->next;
  }
  return NULL;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
  nil->key = -1;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;

  while(1){
    if(cur == nil) break;
    if(isf == 0) printf(" ");
    printf("%d" ,cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteFirst(){
  NodePointer x,y;

  x = nil->next;
  y = x->next;
  y->prev = nil;
  nil->next = y;
  free(x);
}

void deleteLast(){
  NodePointer x,y;

  x = nil->prev;
  y = x->prev;
  y->next = nil;
  nil->prev = y;
  free(x);
}

void delete(int key){
  NodePointer x,y,z;

  if(nil->next->key == key){
    deleteFirst();
    return;
  }

  x = listSearch(key);
  if(x == NULL){
    return;
  }
  z = x->next;

  y = x->next->next;
  x->next = y;
  y->prev = x;
  
  free(z);
}

void insert(int key){
  NodePointer x,y;
  x = malloc(sizeof(struct node));
  x->key = key;
  
  y = nil->next;
  nil->next = x;
  x->prev = nil;
  x->next = y;
  y->prev = x;
}


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

#define for_(i,a,b) for(int i=a;i<b;++i)

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

int n, a[3], p;

int main() {
	cin >> n;
	for_(i,0,n) cin >> a[i];
	
	p = gcd(a[0], a[1]);
	if (n == 3) p = gcd(a[2], p);
	
	vector< int > c;
	for_(i,1,0 || i*i <= p) {
		if (p % i == 0) {
			c.push_back(i);
			if (p/i != i) c.push_back(p/i);
		}
	}
	
	sort(c.begin(), c.end());
	
	for_(i,0,(int)c.size()) {
		bool ok = 1;
		for_(j,0,n) ok &= (a[j] % c[i] == 0);
		if (ok) cout << c[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1220
S = input()

for i in range(len(S)):
    #奇数番目の文字
    if i % 2 == 0:
        if not (S[i] == 'R' or S[i] == 'U' or S[i] == 'D'):
            print('No')
            exit()
    #偶数番目の文字
    else:
        if not (S[i] == 'L' or S[i] == 'U' or S[i] == 'D'):
            print('No')
            exit()

print('Yes')


Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
#define MAX 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ub upper_bound
#define lb lower_bound
#define zoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main() {

    zoom;
    ll N, i, j, ans = 1;
    cin >> N;
    vector<ll> look(3, -1);
    for(i = 0; i < N; i += 1) {
        ll temp, cnt = 0;
        cin >> temp;
        for(j = 0; j < 3; j += 1) {
            if(temp - look[j] == 1)
                cnt += 1;
        }
        ans = (ans * cnt) % MOD;
        for(j = 0; j < 3; j += 1) {
            if(temp - look[j] == 1) {
                look[j] += 1;
                break;
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import heapq
def dijkstra_path(V, source, target):

    visited = [False] * V
    prev = [-1 for i in range(V)]


    dist = [float('inf')] * V
    dist[source] = 0

    h = [(0, source)]
    while h:
        c, v = heapq.heappop(h)
        if visited[v]:
            continue
        visited[v] = True
        for i in range(len(graph[v])):
            t = graph[v][i]
            nc = c + 1
            if dist[t] > nc:
                dist[t] = nc
                heapq.heappush(h, (nc, t))
                prev[t] = v
    path = [target]
    while path[-1] != source and path[-1] != -1:
        path.append(prev[path[-1]])
    return path[::-1]

def all_contains(s, a):
    return all([x in s for x in a])

n,m=map(int, input().split())
graph = [[] for i in range(n)]
cnt = [0 for i in range(n)]
for i in range(m):
    a,b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
    cnt[a-1] += 1
    cnt[b-1] += 1
start = 0
end = 1
for i in range(n):
    if cnt[i]<=cnt[start]:
        end = start
        start = i


def main():
    v = start
    path = [start]
    moved = [0 for i in range(n)]
    pre = [float('inf') for i in range(n)]
    while True:
        if path[-1] != v:
            path.append(v)
        # print(path[- min(len(path), 4):])
        if all_contains(path, graph[v]) and all_contains(path, graph[start]):
            return path

        while moved[v] < len(graph[v]):
            nv = graph[v][moved[v]]
            if nv not in path:
                pre[nv] = v
                moved[v] += 1
                v = nv
                break
            else:
                moved[v] += 1
        else:
            path.pop()
            moved[v] = 0
            v = pre[v]



def allow_path(path):
    for i in range(len(path)-1):
       if not path[i+1] in graph[path[i]]:
           print(i+1, path[i+1], 'not in ', graph[path[i]])
           return False
    return True

if __name__ == '__main__':
    if cnt[end] == 1:
        res = dijkstra_path(n, start, end)
    else:
        res = main()
    # print(allow_path(res))
    print(len(res))
    print(' '.join([str(x+1) for x in res]))


Measured memory_bytes: 85280
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>
#include <fstream>
#include <cassert>
using namespace std;

//common
typedef long long i64,ll;

#define BR "\n"
#define ALL(c) (c).begin(),(c).end()
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,r) for(int i=(l);i<(int)(r);++i)
#define EACH(it,o) for(auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l,v,r) ((l)<=(v) && (v)<(r))

//debug
#ifdef NDEBUG
#define DUMP(x)
#define DUMPLN(x)
#define DEBUG(x)
#define DEBUGLN(x)
#define LINE()
#define LINELN()
#define CHECK(exp,act)
#define STOP(e)
#else
#define DUMP(x)  cerr << #x << " = " << (x)
#define DUMPLN(x)  DUMP(x) <<endl
#define DEBUG(x) DUMP(x) << LINE() << " " << __FILE__
#define DEBUGLN(x) DEBUG(x)<<endl
#define LINE()    cerr<< " (L" << __LINE__ << ")"
#define LINELN()    LINE()<<endl
#define CHECK(exp,act)  if(exp!=act){DUMPLN(exp);DEBUGLN(act);}
#define STOP(e)  CHECK(e,true);if(!(e)) exit(1);
#endif

template<class T> inline string toString(const vector<T>& x) {
	stringstream ss;
	REP(i,x.size()){
		if(i!=0)ss<<" ";
		ss<< x[i];
	}
	return ss.str();
}

template<class T> inline string toString(const vector<vector<T> >& map) {
	stringstream ss;
	REP(i,map.size()){
		if(i!=0)ss<<BR;
		ss<< toString(map[i]);
	}
	return ss.str();
}
template<class K,class V>  string toString(map<K,V>& x) {
	string res;stringstream ss;
	for(auto& p:x)ss<< p.first<<":" << p.second<<" ";
	return ss.str();
}

string BITtoString(int bit){
    stringstream ss;
    while(bit!=0){ss<<(bit%2);bit/=2;}
    string res=ss.str();reverse(ALL(res));
    return res;
}

template<typename T,typename V> inline T pmod(T v,V MOD){
	return (v%MOD+MOD)%MOD;
}


namespace MGraph{
	typedef int Cost;Cost CINF=1<<28;
	typedef  vector<vector<Cost> > Mat;
}
namespace ShortestPath{
    using namespace MGraph;
    // O(n^3) n≦100
    void warshall_floyd(Mat& d){
        const int V=d.size();
        REP(k,V)
            REP(i,V)REP(j,V){
                if(d[i][j]>d[i][k] + d[k][j]){
                    d[i][j]=d[i][k] + d[k][j];
                }
            }
    }
}
using namespace ShortestPath;

Cost INF=1<<28;

class Main{
public:

	void run(){
		while(true){
			int M;cin >> M;if(M==0)break;
			int n;cin >> n;
			vector<int> ds(n+2);REP(i,n) cin >> ds[i+1];
			
			Mat g(n+2,vector<Cost>(n+2,INF));
			REP(i,n+2){
				for(int r=1;r<=M;r++){
					int npos=min(i+r,n+1);
					npos+=ds[npos];npos=max(npos,0);npos=min(npos,n+1);
					g[i][npos]=0;
				}
			}
			warshall_floyd(g);
			bool ok=true;
			REP(i,n+2){
				if(g[0][i]<INF && g[i][n+1]>=INF)ok=false;
			}
			cout << (ok?"OK":"NG")<<endl;
		}
	}
};

 int main(){
	//ios::sync_with_stdio(false);
 	Main().run();
 	return 0;
 }

Measured memory_bytes: 1340
N,*A=map(int,open(0).read().split())
A=[0]+A+[0]
f=lambda i:abs(A[i]-A[i+1])
s=sum(f(i)for i in range(N+1))
print(*[s-f(i)-f(i+1)+abs(A[i]-A[i+2])for i in range(N)])

Measured memory_bytes: 13804
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let a: f64 = iter.next().unwrap().parse().unwrap();
    let b: f64 = iter.next().unwrap().parse().unwrap();
    let x: f64 = iter.next().unwrap().parse().unwrap();

    let box_volume = a * a * b;
    let x_area = x / a;

    let ans = if x as i64 == box_volume as i64 {
        0f64
    } else if x >= box_volume / 2f64 {
        let area = a * b;
        // x_area == area -  a * length / 2
        let length = (area - x_area) * 2f64 / a;
        length.atan2(a).to_degrees()
    } else {
        // x_area == b * length / 2
        let length = x_area * 2f64 / b;
        90f64 - length.atan2(b).to_degrees()
    };

    println!("{}", ans);
}


Measured memory_bytes: 4476
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int L;
    cin >> L;
    double max=0;
    double v=0;
    
    double t=0.05;
    
    if(L<5){
        t=0.0001;
    }
    
    for(double a=0;a<L;a=a+t){
        for(double b=0;b<L-a;b=b+t){
            v=a*b*(L-a-b);
            
            
            if(max<v){
                max=v;
            }
        }
    }
    cout << fixed;
    cout << setprecision(7) << max << endl;
    
    
    }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<static_cast<int>(n);++i)
#define per(i, n) for(int i=static_cast<int>(n)-1;i>=0;--i)
#define eee(a) (cerr<<(#a)<<": "<<(a)<<'\n');
#define ppp(a) (cout<<(a)<<'\n'); 
#define cop(a) for(auto x:(a)){cerr<<(x)<<'\n';}
using ll = long long;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
constexpr ll MOD = 1e9+7;
constexpr ll Mod = 998244353;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll inverse(ll n,ll m=MOD){ll a=n,b=m,x=1,y=0;while(b){ll t=a/b;a-=t*b;swap(a,b);x-=t*y;swap(x,y);}return (a%m+m)%m;}
inline void Yes(){puts("Yes");}
inline void No(){puts("No");}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){puts("YES");}
inline void NO(){puts("NO");}
inline void JUDGE(bool b){b?YES():NO();}
inline ll powmod(ll b, ll e, ll m=MOD){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
inline double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
inline double d2r(double d){return d*pi/180;}
inline double r2d(double r){return r*180/pi;}
template<class T>inline bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
template<typename T1,typename T2>ostream& operator<<(ostream& s,const pair<T1, T2>& p){return s <<"("<<p.first<<", "<<p.second<<")";}
template<typename T> ostream& operator<<(ostream& s,const vector<T>& v){s<<'[';for(size_t i=0;i<v.size();++i){s<<v[i];if(i<v.size()-1)s<<", ";}s<<']';return s;}

int main(){
    cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    
    
    string s;
    cin >> s;

    int n = s.size(); 
    int ans = 0;
    int cnt = 0;
    s.push_back('#');
    string atgc = "ATGC";

    for(int i = 0; i <= n; ++i){
        if(atgc.find(s[i]) != string::npos){
            ++cnt;
        }else{
            ans = max(ans, cnt);
            cnt = 0;
        }

    }
    cout << ans << '\n';
    
    
    return 0;
}


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

using namespace std;

//#define MD 100010

int main(){
    vector<int> ans(30,0);
    string s;
    cin>>s;
    for(int i=0;i<s.length();i++){
        ans[s[i]-'a']++;
    }
    for(int i=0;i<29;i++){
        if(ans[i]%2==1){
            cout<<"No"<<endl;
            return 0;
        }
    }
   cout<<"Yes"<<endl;
    return 0;
}

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

using namespace std;
using ll = long long;

int main()
{
  int N; cin >> N;
  vector<int> a(N); REP(i, N) cin >> a[i];
  sort(ALL(a));
  int n = a[N-1], r = a[0], rr = n;
  REP(i, N-1) {
    if (rr >= abs(n/2-a[i])) {
      r = a[i];
      rr = abs(n/2-a[i]);
    }
  }
  printf("%d %d\n", n, r);
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 99999999

string data[10]={"","',.!?","abcABC","defDEF","ghiGHI","jklJKL","mnoMNO","pqrsPQRS","tuvTUV","wxyzWXYZ"};

string solve(char ch,int c){
    c--;
    int a=ch-'0';
    if(a==0){
        if(c==0)return "\0";
        return string(c,' ');
    }
    if(a==1)c%=5;
    else if(a==7||a==9)c%=8;
    else if(a!=0)c%=6;
    return string(1,data[a][c]);
}

int main(){
    string s;
    while(cin>>s){
        string ans="";
        char buf=' ';
        int c=0;
        rep(i,s.size()){
            if(c==0||s[i]!=s[i-1]){
                if(c!=0)ans+=solve(buf,c);
                buf=s[i];
                c=1;
            }else{
                c++;
            }
        }
        ans+=solve(buf,c);
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 1196
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	MyScanner sc = new MyScanner();
	Scanner sc2 = new Scanner(System.in);
	final int MOD = 1000000007;
	int[] dx = { 1, 0, 0, -1 };
	int[] dy = { 0, 1, -1, 0 };

	void run() {
		int W = sc.nextInt();
		int H = sc.nextInt();
		int N = sc.nextInt();
		int startW = sc.nextInt();
		int startH = sc.nextInt();
		int score = 0;
		for (int i = 0; i < N - 1; i++) {
			int nextW = sc.nextInt();
			int nextH = sc.nextInt();
			if ((startW <= nextW && startH <= nextH)
					|| (startW >= nextW && startH >= nextH)) {
				int disX = Math.abs(startW - nextW);
				int disY = Math.abs(startH - nextH);
				score += Math.max(disX, disY);
			} else {
				int disX = Math.abs(startW - nextW);
				int disY = Math.abs(startH - nextH);
				score += disX + disY;
			}
			startW = nextW;
			startH = nextH;
		}
		System.out.println(score);
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	void debug2(int[][] array) {
		for (int i = 0; i < array.length; i++) {
			for (int j = 0; j < array[i].length; j++) {
				System.out.print(array[i][j]);
			}
			System.out.println();
		}
	}

	class MyScanner {
		int nextInt() {
			try {
				int c = System.in.read();
				while (c != '-' && (c < '0' || '9' < c))
					c = System.in.read();
				if (c == '-')
					return -nextInt();
				int res = 0;
				do {
					res *= 10;
					res += c - '0';
					c = System.in.read();
				} while ('0' <= c && c <= '9');
				return res;
			} catch (Exception e) {
				return -1;
			}
		}

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

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

		String next() {
			try {
				StringBuilder res = new StringBuilder("");
				int c = System.in.read();
				while (Character.isWhitespace(c))
					c = System.in.read();
				do {
					res.append((char) c);
				} while (!Character.isWhitespace(c = System.in.read()));
				return res.toString();
			} catch (Exception e) {
				return null;
			}
		}
	}
}

Measured memory_bytes: 18180
#include <iostream>
using namespace std;
 
int main() {
	int n; cin >> n; bool OK = false;
	for (int j = 0; j <= n / 4; j++) {
		for (int k = 0; k <= n / 7; k++) {
			if (4 * j + 7 * k == n) OK = true;
		}
	}
	if (OK == false) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

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

#define TASKNAME ""

using namespace std;

const int INF = 1e9 + 7;
const int MAXN = 1e6 + 7;
const double EPS = 1e-8;

int dsum(int x) {
    int sum = 0;
    while (x > 0) {
        sum += x % 10;
        x /= 10;
    }
    return sum;
}

int main() {
    #ifdef MY
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #else
        //freopen(TASKNAME".in", "r", stdin);
        //freopen(TASKNAME".out", "w", stdout);
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    #endif // MY
    int n;
    cin >> n;
    int mink = INF;
    for (int i = 1; i < n; i++) {
        mink = min(mink, dsum(i) + dsum(n - i));
    }
    cout << mink;
}


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

int main() {
	
	int i,m,s,sum;
	
	for(i=1;i<=4;i++){
		cin>>s;
		sum=sum+s;
	}
	m=sum/60;
	s=sum%60;
	
	cout<<m<<endl<<s<<endl;
	return 0;
}

Measured memory_bytes: 1160
program bm
    implicit none
    integer::N
    integer,allocatable,dimension(:)::A
    integer,allocatable,dimension(:,:)::x,y
    logical::check

    integer::ANS
    integer::i,j,k
    read*,N
    allocate(A(N))
    allocate(X(N,N-1),Y(N,N-1))
    do i=1,N
        read*,A(i)
        do j=1,A(I)
            read*,x(i,j),y(i,j)
        end do
    end do
    ans=0
    do i=0,2**N-1
        check=.true.
        do j=1,N
            if(.not.btest(i,j-1))cycle
            do k=1,A(j)
                if(btest(i,x(j,k)-1).and.y(j,k)==0)check=.false.
                if(.not.btest(i,x(j,k)-1).and.y(j,k)==1)check=.false.
            end do
        end do
        if(check)ans=max(ans,cnt(i))
    end do
    print"(i0)",ans
contains
integer function CNT(K)
integer::K
integer::i
CNT=0
do i=1,bit_size(K)
    if(btest(K,i-1))cnt=cnt+1
end do
end function
end program bm

Measured memory_bytes: 384
// Dont hack this or I hack ur mama
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#define ll long long 
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define EPS (1e-9)
using namespace std;

////////////// END OF TEMPLATE
const int nmax = 200010;
ll sum;
int a[nmax],n;
void read()
{
	cin >> n;
	for(int i = 0 ; i < n; ++i)
	{
		cin >> a[i];
		sum+=a[i];
	}
}
void solve()
{
	ll preSum = 0;
	ll ans = abs(2LL*a[0] - sum);
	for(int i = 0;i < n-1 ; ++i)
	{
	
		preSum+=a[i];
		sum-=a[i];
		ans = min(ans, abs(preSum - sum));
	}
	cout << ans << endl;
}
int main()
{
	std::ios::sync_with_stdio(false);
	read();
	solve();
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long int
mt19937 rng(chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int N=3005;
#define M 998244353
#define double long double
#define BINF 10000000000001
#define init(arr,val) memset(arr,val,sizeof(arr))
#define MAXN 5000004
#define deb(x) cout << #x << " " << x << "\n";
const int LG = 22;

int suf[N];
int dp[N][N][2];
int n, S, a[N];

int foo(int pos, int sum, int f){
    if(sum < 0)
        return 0;
    if(sum == 0){
        return n - pos + 1;
    }
    if(pos == n){
        if(sum == 0)
            return 1;
        return 0;
    }
    if(dp[pos][sum][f] != -1){
        if(f == 0){
            suf[pos] = (suf[pos] + dp[pos][sum][f]) % M;
        }
        return dp[pos][sum][f];
    }

    int x = foo(pos + 1, sum, f);
    int y = foo(pos + 1, sum - a[pos], f | 1);

    if(f == 0){
        suf[pos] = (suf[pos] + y) % M;
    }

    return dp[pos][sum][f] = (x + y) % M;
}



#undef int 
int main() {
#define int long long int
ios_base::sync_with_stdio(false); 
cin.tie(0); 
cout.tie(0);


    cin >> n >> S;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    init(dp, -1);

    int ans = foo(0, S, 0);
    for(int i = n - 2; i >= 0; i--){
        suf[i] = (suf[i] + suf[i + 1]) % M;
    }

    ans = 0;
    for(int i = 0; i < n; i++)
        ans = (ans + suf[i]) % M;
    cout << ans << endl;
    
    

return 0;  
}


Measured memory_bytes: 141568
#include <bits/stdc++.h>
#define SIZE 500000
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;
void merge(int *array, int left, int mid, int right, int &count)
{
    int n1 = mid - left;  //1
    int n2 = right - mid; //1
    int L[n1 + 1], R[n2 + 1];
    rep(i, n1) L[i] = array[left + i];
    rep(i, n2) R[i] = array[mid + i];
    L[n1] = 2147383657, R[n2] = 2147383657;
    int i(0), j(0);
    for (int k = left; k < right; ++k)
    {
        count++;
        if (L[i] <= R[j])
            array[k] = L[i++];
        else
            array[k] = R[j++];
    }
}
void mergesort(int *array, int left, int right, int &count)
{
    if (left + 1 < right)
    {
        int mid = (left + right) / 2;
        mergesort(array, left, mid, count);
        mergesort(array, mid, right, count);
        merge(array, left, mid, right, count);
    }
}
int main()
{
    int n;
    cin >> n;
    int s[n];
    int count(0);
    rep(i, n) cin >> s[i];
    mergesort(s, 0, n, count);
    rep(i, n)
    {
        cout << s[i] << flush;
        if (i < n - 1)
            cout << ' ' << flush;
    }
    cout << endl
         << count << endl;
}


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

using namespace std;
long long a,b;
long long mod=1e9+7;
long long solve()
{
    long long p1=1,p2=1;
    for(long long i=1;i<=a;i++)
    {
        p1=p1*i;
        p1=p1%mod;
    }
    for(long long i=1;i<=b;i++)
    {
        p2=p2*i;
        p2=p2%mod;
    }
    return ((p1*p2)%mod);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>a>>b;
    if(abs(a-b)>1)
    {
        cout<<0<<endl;
        return 0;
    }
    long long ans=solve();
    if(a==b) ans=(ans+solve())%mod;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1111111111;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int X;
	cin >> X;

	cout << X / 500 * 1000 + X % 500 / 5 * 5 << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

const int INF = 1<<30;

int main(){
    int n;
    cin >> n;
    vector<int> m;
    m.push_back(1);
    int x = 6;
    while(x <= n){
        m.push_back(x);
        x *= 6;
    }
    x = 9;
    while(x <= n){
        m.push_back(x);
        x *= 9;
    }
    sort(all(m));

    // vector<int> dp(n+1, INF);
    // dp[0] = 0;
    // for(int i = 0; i < m.size(); i++){
    //     int x = m[i];
    //     for(int j = 0; j <= n; j++){
    //         if (j+x > n) break;
    //         dp[j+x] = min(dp[j+x], dp[j]+1);
    //     }
    // }
    // cout << dp[n] << endl;

    vector<vector<int>> dp(m.size()+1, vector<int>(n+1, INF));
    dp[0][0] = 0;
    for(int i = 0; i < m.size(); i++){
        int x = m[i];
        for(int j = 0; j <= n; j++){
            dp[i+1][j] = min(dp[i][j], dp[i+1][j]);
            if (j + x <= n){
                dp[i+1][j+x] = min(dp[i+1][j+x], dp[i+1][j]+1);
            }
        }
    }
    cout << dp[m.size()][n] << endl;
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }
template <class T1, class T2, class Pred = std::less<T2> >
struct sort_pair_second {
    bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
        Pred p;
        return p(left.second, right.second);
    }
};

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

    ll H, W;
    cin >> H >> W;
    if (W == 1 || H == 1) {
        cout << 1 << endl;
        return 0;
    }
    if (H % 2 && W % 2) {
        cout << H * W / 2 + 1 << endl;
    } else {
        cout << H * W / 2 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000001

int main() {
    string s,t;
    cin >> s >>t;
    if(t.size()>s.size()){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    string ans="{";
    for(int i = 0; i < s.size()-t.size()+1; i++) {
        bool a=true;
        for(int j = 0; j < t.size(); j++) {
            if(s[i+j]!=t[j] && s[i+j]!='?'){
                a=false;
            }
        }

        if(a){
            vector<char> y(s.size());
            for(int j = 0; j < s.size(); j++) {
                y[j]=s[j];
            }
            for(int j = i; j < i+t.size() ; j++) {
                y[j]=t[j-i];
            }
            for(int j = 0; j < s.size(); j++) {
                if(y[j]=='?') y[j]='a';
            }

            string q;
            for(int j = 0; j < s.size(); j++) {
                q += y[j];
            }
            if(ans>q) ans=q;
        }
    }

    if(ans=="{") cout << "UNRESTORABLE" << endl;
    else cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main() {
	int n, k, x, y,a,b;
	cin >> n;
	cin >> k;
	cin >> x;
	cin >> y;
	if (n - k >= 0) {
		a = k*x;
	}else{
		a = n*x;
	}
		if (n-k>0) {
			b = y*(n - k);
		}
		cout << a + b << endl;
}


Measured memory_bytes: 256
#include "stdio.h"
#include "string.h"

char st1[5000];
char st2[5000];
char flg[15000];
int ans[1000];

int main()
{
  int nw = 0;
  while(1)
    {
      if(NULL == gets(st1))
	{
	  break;
	}
      gets(st2);
      int st1l,st2l;
      st1l = strlen(st1);
      st2l = strlen(st2);
      int m = 0;
      for(int i = 0; i < st1l + st2l; i++)
	{
	  for(int ii = 0; ii < 15000; ii++)
	    {
	      flg[ii] = 1;
	    }
	  for(int ii = 0; ii < st1l; ii++)
	    {
	      flg[ii + st2l] = st1[ii];
	    }
	  for(int ii = 0; ii < st2l; ii++)
	    {
	      if(flg[i + ii] == st2[ii])
		{
		  flg[i + ii] = 0;
		}
	      else
		{
		  flg[i + ii] = 1;
		}
	    }
	  int n = 0;
	  for(int ii = 0; ii < 15000; ii++)
	    {
	      if(flg[ii] == 0)
		{
		  n++;
		  if(n > m)
		    {
		      m = n;
		    }
		}
	      else
		{
		  n = 0;
		}
	    }
	}
      ans[nw] = m;
      nw++;
    }
  for(int i = 0; i < nw; i++)
    {
      printf("%d\n",ans[i]);
    }
  return 0;
}

Measured memory_bytes: 968