akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ll long long
using namespace std;

int main() {
 ll x;
 cin >> x;
 
 ll ans = (x+10)/11;
 ans *= 2;
 if (0 < x%11 && x%11 < 7) ans--;
 cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#define MIN(a,b) ((a>b)?(b):(a))
using namespace std;

int main(void){
	int n;
	int a[1000];
	while(cin>>n,n){
		int d=99999999;
		for(int i=0;i<n;i++)cin>>a[i];
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				d=MIN(d,abs(a[i]-a[j]));
			}
		}
		cout<<d<<endl;
	}
	return 0;
}

Measured memory_bytes: 3040
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int x= sc.nextInt();
        
        int num1 =x/100;
        int num2 =x%100;
        int count=0;

        for(int i=0;i<num1;i++){
            if(num2>= 5){
                num2 -= 5;
            }else if(num2 >= 4){
                num2 -= 4;
            }else if(num2 >= 3){
                num2 -= 3;
            }else if(num2 >= 2){
                num2 -= 2;
            }else if(num2 >= 1){
                num2 -= 1;
            }
        }
        if(num2 == 0){
            
            System.out.println("1");
            
        }else{
            System.out.println("0");
        }
    }
}


Measured memory_bytes: 35736
#include <stdio.h>
#include <inttypes.h>

int main(void) {
	int A, B, C;
	int64_t K;
	if (scanf("%d%d%d%" SCNd64, &A, &B, &C, &K) != 4) return 1;
	printf("%d\n", (A - B) * (K % 2 == 0 ? 1 : -1));
	return 0;
}

/*

高橋君    中橋君    低橋君    答え
a         b         c         a-b
b+c       a+c       a+b       -a+b
2a+b+c    a+2b+c    a+b+2c    a-b
2a+3b+3c  3a+2b+3c  3a+3b+2c  -a+b

*/


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

int main()
{
    string S;
    cin >> S;
    int res = 0;
    for(int i = 0, i_len = S.size(); i < i_len; ++i) 
        if(S[i] == '1') ++res;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
h,w,K=map(int,input().split())
data=[[0 for i in range(w+1)]]
for i in range(h):
    x=list(input())
    x.insert(0,0)
    for j in range(w+1):
        x[j]=int(x[j])
    data.append(x)
    
for i in range(h+1):
    for j in range(1,w+1):
        data[i][j]+=data[i][j-1]
        
for i in range(w+1):
    for j in range(1,h+1):
        data[j][i]+=data[j-1][i]
        


ans=10**10
for _ in range(2**(h-1)):
    st=choice=format(_,"0%ib"%(h-1))
    div=[0]
    sub=0
    for j in range(h-1):
        if st[j]=="1":
            div.append(j+1)
            sub+=1
    div.append(h)
    cnt=0
    nowindex=0
    for j in range(1,w+1):
        flag=True
        if nowindex==0:
            for k in range(1,len(div)):
                if data[div[k]][j]-data[div[k-1]][j]>K:
                    flag=False
                    break
            if flag is False:
                nowindex=j-1
                cnt+=1
                 
        else:
            for k in range(1,len(div)):
                if (data[div[k]][j]-data[div[k]][nowindex])-(data[div[k-1]][j]-data[div[k-1]][nowindex])>K:
                    flag=False
                    break
            if flag is False:
                nowindex=j-1
                cnt+=1
    subflag=True
    for k in range(1,len(div)):
        if (data[div[k]][w]-data[div[k]][nowindex])-(data[div[k-1]][w]-data[div[k-1]][nowindex])>K:
            subflag=False
    if subflag is True:
        ans=min(ans,sub+cnt)
print(ans)
                    
    

    
        
    
    


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

struct Node{
  int key;
  struct Node *next, *prev;
};
struct Node *n;
struct Node* LS(int key){
  struct Node *c=n->next;
  while(c!=n && c->key!=key){
    c=c->next;
  }
  return c;
}

void printList(void);
void ins(void);
void dele(struct Node *);
void dF(void);
void dL(void);
void deke(int);
void inke(int);

int main(){
  int key,n,i,np=0,nd=0;
  int size=0;
  char comm[20];
  scanf("%d",&n);
  ins();
  for(i=0;i<n;i++){
    scanf("%s%d",comm,&key);
    if(comm[0]=='i'){
      inke(key);
      np++;
      size++;
    }
    else if(comm[0]=='d'){
      if(strlen(comm)>6){
	if(comm[6]=='F')dF();
	else if(comm[6]=='L')dL();
      }
      else{
	deke(key);
	nd++;
      }
      size--;
    }
  }
  printList();
  return 0;
}
void printList(void){
  struct Node *c=n->next;
  int is=0;
  while(1){
    if(c==n)break;
    if(is++>0)printf(" ");
    printf("%d",c->key);
    c=c->next;
  }
  printf("\n");
}
void ins(void){
  n=(struct Node *)malloc(sizeof(struct Node));
  n->next=n;
  n->prev=n;
}
void dele(struct Node *ti){
  if(ti==n)return;
  ti->prev->next=ti->next;
  ti->next->prev=ti->prev;
  free(ti);
}
void dF(void){
  dele(n->next);
}
void dL(void){
  dele(n->prev);
}
void deke(int key){
  dele(LS(key));
}
void inke(int key){
  struct Node *x=(struct Node *)malloc(sizeof(struct Node));
  x->key=key;
  x->next=n->next;
  n->next->prev=x;
  n->next=x;
  x->prev=n;
}

Measured memory_bytes: 31788
#include <stdio.h>  //doubly linked list
#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: 31788
#include<iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

const int maxN = 2e5;
long long a[maxN];
long long ans[maxN];
bool used[maxN];

vector <pair <int, int> > v;


int main(void) {
    int n;
    ios_base::sync_with_stdio(0);
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> a[i];
        v.push_back(make_pair(a[i], -i));
    }
    int cur = 0;
    used[0] = 1;
    for (int i = 1; i < n; i++) {
        if (a[i] > a[cur]) {
            cur = i;
            used[cur] = true;
        }
    }
    
    sort(v.begin(), v.end());
    long long sum = 0;
    long long prev = 0;
    for (int i = 0; i < v.size(); i++) {
        int id = -v[i].second;
        if (!used[id]) {
            sum += a[id] - prev;
        } else {
            ans[id] = sum + (v.size() - i) * (a[id] - prev);
            prev = a[id];
            sum = 0;
        }
    }

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

    
    


    return 0;
}

Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimization_level 3
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main(){
	vector<vector<int>> a(3,vector<int>(4));

	vector<vector<int>> is_bng(3,vector<int>(4));

	for (size_t i = 0; i < 3; i++)
	{
		for (size_t ij = 0; ij < 3; ij++)
		{
			cin>>a.at(i).at(ij);
		}
		
	}

	int n;
	cin>>n;
	vector<int> b(n);
	for (size_t i = 0; i < n; i++)
	{
		cin>>b.at(i);
	}

	for (size_t i = 0; i < 3; i++)
	{
		for (size_t j = 0; j < 3; j++)
		{
			for (size_t k = 0; k < n; k++)
			{
				if (a.at(i).at(j)==b.at(k))
				{
					is_bng.at(i).at(j) = 1;
				}
				
			}
			
		}
		
	}
	

	int is_bngs = 0;
	for (size_t i = 0; i < 3; i++)
	{
		for (size_t j = 0; j < 3; j++)
		{
			if (is_bng.at(i).at(j)==1)
			{
				is_bngs++;
			}
			
			
		}
		if (is_bngs==3)
		{
			cout<<"Yes";
			return 0;
		}
		is_bngs=0;
		
		
	}
	
	
	is_bngs = 0;
	for (size_t i = 0; i < 3; i++)
	{
		for (size_t j = 0; j < 3; j++)
		{
			if (is_bng.at(j).at(i)==1)
			{
				is_bngs++;
			}
			
			
		}
		if (is_bngs==3)
		{
			cout<<"Yes";
			return 0;
		}
		is_bngs=0;
		
		
	}



	if (is_bng.at(0).at(0)==1 && is_bng.at(1).at(1)==1 && is_bng.at(2).at(2)==1)
	{
		cout<<"Yes";
		return 0;
	}
	
	
	if (is_bng.at(2).at(0)==1 && is_bng.at(1).at(1)==1 && is_bng.at(0).at(2)==1)
	{
		cout<<"Yes";
		return 0;
	}

	cout<<"No";
	
}


Measured memory_bytes: 256
/*Unknown_Ghost*/
/*Shortest Path on a Line*/
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
using namespace std;

#define LL long long
#define MAXN 500000
#define MAXM 4000000
#define MOD 998244353
#define Pr pair<LL,int>
#define X first
#define Y second
#define INF 1000000000000000000
#define mem(x,p) memset(x,p,sizeof(x))

LL read(){
  LL x=0,F=1;char c=getchar();
  while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
  while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
  return x*F;
}
int add(int x,int y){return (x+y>=MOD)?x+y-MOD:x+y;}
int dec(int x,int y){return (x-y<0)?x-y+MOD:x-y;}
int mul(int x,int y){return 1LL*x*y%MOD;}

int n,m,S,vis[MAXM+5];
LL dis[MAXM+5];
struct Graph{
    struct edge{
        int to,nxt,w;
    }e[MAXM+5];
    int head[MAXM+5],ecnt;
    void init(){
        mem(head,-1);ecnt=0;
    }
    void add(int u,int v,int w){
        e[++ecnt]=(edge){v,head[u],w};
        head[u]=ecnt;
    }
}G;

struct Seg_tree{
    #define Lc (x<<1)
    #define Rc (x<<1|1)
    #define mid ((l+r)>>1)
    void Build(int x,int l,int r){
        if(l==r){
            G.add(x+n,l,0),G.add(l,x+MAXN+n,0);
            return ;
        }
        Build(Lc,l,mid),Build(Rc,mid+1,r);
        G.add(x+n,Lc+n,0),G.add(x+n,Rc+n,0);
        G.add(Lc+MAXN+n,x+MAXN+n,0),G.add(Rc+MAXN+n,x+MAXN+n,0);
    }
    void add(int x,int l,int r,int u,int L,int R,int w,int op){
        if(R<l||r<L)return ;
        if(L<=l&&r<=R){
            if(op==2)G.add(u,x+n,w);
            else G.add(x+n+MAXN,u,w);
            return ;
        }
        add(Lc,l,mid,u,L,R,w,op);
        add(Rc,mid+1,r,u,L,R,w,op);
    }
}T;

void Dij(int s){
    priority_queue<Pr> Q;
    Q.push(Pr(0,s));
    for(int i=1;i<=MAXN*2;i++)dis[i]=INF;
    dis[s]=0;mem(vis,0);
    while(!Q.empty()){
        int x=Q.top().Y;
        Q.pop();if(vis[x])continue;
        vis[x]=1;
        for(int i=G.head[x];i!=-1;i=G.e[i].nxt){
            int nxt=G.e[i].to,w=G.e[i].w;
            if(dis[nxt]>dis[x]+w){
                dis[nxt]=dis[x]+w;
                Q.push(Pr(-dis[nxt],nxt));
            }
        }
    }
}

int main()
{
    G.init();
    n=read(),m=read(),S=1;
    T.Build(1,1,n);
    for(int i=1;i<=m;i++){
        int l=read(),r=read(),w=read();
        T.add(1,1,n,r,l,r-1,w,3);
    }
    Dij(S);
    printf("%lld",dis[n]==INF?-1:dis[n]);
}


Measured memory_bytes: 69752
#include<stdio.h>

int main(void)
{
	int i,j,k,W, H,N, a,x,y,ans,square[100][100];

	scanf("%d%d%d", &W, &H, &N);

	for (i = 0; i < H; i++)
	{
		for (j = 0; j < W; j++)
			square[i][j] = 0;
	}

	for (i = 0; i < N; i++)
	{
		scanf("%d%d%d", &x, &y, &a);

		switch (a)
		{
		case 1:
			for (j = 0; j < H; j++)
			{
				for (k = 0; k < x; k++)
					square[j][k] = 1;
			}

			break;
		case 2:
			for (j = 0; j < H; j++)
			{
				for (k = x; k < W; k++)
					square[j][k] = 1;
			}

			break;
		case 3:
			for (j = 0; j < y; j++)
			{
				for (k = 0; k < W; k++)
					square[j][k] = 1;
			}

			break;
		case 4:
			for (j = y; j < H; j++)
			{
				for (k = 0; k < W; k++)
					square[j][k] = 1;
			}

			break;
		}
	}

	ans = 0;

	for (i = 0; i < H; i++)
	{
		for (j = 0; j < W; j++)
		{
			if (square[i][j] == 0)
				ans++;
		}
	}

	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
using namespace std;
int main(void){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  long long n, k;
  cin >> n >> k;
  
  cout << min(n%k, k-(n%k)) << endl;
  return 0;
}

Measured memory_bytes: 256
//8 パズル
//Ebitani Akira

#include <stdio.h>
#include <stdlib.h>

int array[3][3];
int tmp[3][3];
int Tx[4] = {0,1,0,-1};
int Ty[4] = {1,0,-1,0};


void emp(int *,int *) ;
int calc(void);
void swap(int *, int *);
int dfs(int ,int ,int ,int ,const int );

int main() {
    int i, j;
    int l, flg;
    int x, y;

    for(i = 0 ; i < 3 ; i++){
        for(j = 0 ; j < 3 ; j++) scanf("%d", &array[i][j]);
    }

    emp(&x, &y);
    for(l = 0 ; l < 100 ; l++){
        for(i = 0 ; i < 3 ; i++){
            for(j = 0 ; j < 3 ; j++){
               tmp[i][j] = array[i][j];
             }
        }

        flg = dfs(x, y, -1, 0, l);
        if(flg != -1){
            printf("%d\n", flg);
            break;
        }

        for(i = 0 ; i < 3 ; i++){
            for(j = 0 ; j < 3 ; j++){

            array[i][j] = tmp[i][j];
          }
        }

        flg = -1;


        if(l == 99) printf("%d\n",flg);
    }

    return 0;
}

void emp(int *x,int *y) {

  int i, j;
  for(i = 0 ; i < 3 ; i++) {
    for(j = 0 ; j < 3 ; j++) {
      if(! array[i][j]) {

        *x = j;
        *y = i;
      }
    }
  }

}


void swap(int *s, int *v){

  int tmp;
  tmp = *s;
  *s = *v;
  *v = tmp;

}


int calc(){

  int i;
  int sum=0;
  int X;

  for(i = 0 ; i < 9 ; i++){
    X = array[i/3][i%3];
    if(X){
      X--;
      sum += abs(i/3 - X/3) + abs(i % 3 - X % 3);
    }
  }
  return sum;
}


int dfs(int x,int y,int p,int d,const int l){

    int i,h;
    int x2, y2, res;

    h = calc();
    if(h==0) {
        return d;
    }
    if(d+h > l) {
        return -1;
    }
    for(i = 0 ; i < 4 ; i++){
        x2 = x + Tx[i];
        y2 = y + Ty[i];

        if(~p && i == (p+2) % 4){
          continue;
        }

        if(!(0 <= x2 && 0 <=y2 && x2 < 3 && y2 < 3)){
           continue;
         }

        swap(&array[y][x], &array[y2][x2]);
        res = dfs(x2, y2, i, d+1, l);

        if(~res) {
            return res;
        }
        swap(&array[y][x], &array[y2][x2]);
    }
    return -1;
}



Measured memory_bytes: 2052
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
    var args = chunk.split(' ').map(Number);
    var a = args[0];
    var b = args[1];
    var c = args[2];
    console.log('%s', a < b && b < c ? 'Yes' : 'No');
});

Measured memory_bytes: 7644
#include <bits/stdc++.h>
 
//LIFE IS NOT A PROBLEM TO BE SOLVED
 
#define rep(i,a,b) for( int i = (int) a; i < (int) b; i++ )
#define F first
#define S second
#define pb push_back
#define debug(a) cout << #a << " = " << a << endl;
#define debug2(a,b) cout << #a << " = " << a << " --- " << #b << " = " << b << endl;
#define debugP(a) cout << a.F << " " << a.S << endl;
#define debugV(v, n) { rep( i, 0, n ) { if(i) printf(" "); printf("%d", v[i]); } printf("\n"); }
#define debugM(mat,n,m) rep( i, 0, n ){ rep( j, 0, m ) { if(j) printf(" "); printf("%d", mat[i][j]); } printf("\n"); }
 
using namespace std;
 
typedef long long int ll;
typedef pair<int,int> ii;
	

bool isPrime(int n){
	if(n<=1) return false;
	if(n==2) return true;
	int f = sqrt(n);
	rep(i, 2, f+1) if(n%i==0) return false;
	return true;
}

int main(){
	
	int n; string s, t;
	cin >> n >> s >> t;
	rep(i, 0, n){
		cout << s[i];
		cout << t[i];
	}	cout << '\n';
	
	

	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
	public class Main {
		private static Scanner k;
	
		public static void main(String args[]){ 
			 k = new Scanner(System.in);
			 String stringToCheck= k.nextLine(); 
		        int temp = 0; 
		        int j,kr;
		        String Str;
		        kr=Integer.parseInt(stringToCheck);
		     
		  for (int i=0; i<stringToCheck.length(); i++){ 
		              
		            Str=String.valueOf(stringToCheck.charAt(i));
		            j=Integer.parseInt(Str);
		            temp=temp+j;
		     }  
		  if(kr%temp==0)System.out.println("Yes"); 
		  else {
			  System.out.println("No");
		  }
		        } 
	}
		  

Measured memory_bytes: 23892
#include <iostream>
#include <cstdio>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>

using namespace std;

void solve()
{
	int n, m;
	cin >> n >> m;
	vector<vector<int> > matrix(n, vector<int>(m));
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			cin >> matrix[i][j];
		}
	}
	vector<int> vec(m);
	for (int i = 0; i < m; ++i)
	{
		cin >> vec[i];
	}
	for (int i = 0; i < n; ++i)
	{
		int sum = 0;
		for (int j = 0; j < m; ++j)
		{
			sum += matrix[i][j] * vec[j];
		}
		cout << sum << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    if(n == 0) cout << 0 << endl;
    string ans;
    while(n != 0) {
        int r;
        if(n > 0) {
            r = n%2;
        } else {
            if(n%2 == 0) r = 0;
            else r = 1;
        }
        ans += to_string(r);
        n = (n-r)/(-2);
//        cout << n << " " << ans << endl;
    }
    reverse(all(ans));
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,c;
  scanf("%d %d %d\n",&a,&b,&c);
  if((a==b && b!=c) || (b==c && a!=c) || (a==c && a!=b)){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

struct ST {
  int B, C;
};
bool operator<(const ST& a, const ST& b){
  return a.C > b.C;
}

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> v;
  rep(i,N){
    int a;
    cin >> a;
    v.push_back(a);
  }
  sort(ALLOF(v));

  vector<ST> w;
  rep(i,M){
    int b, c;
    cin >> b >> c;
    w.push_back((ST){b,c});
  }
  sort(ALLOF(w));

  int id = 0;
  rep(i,w.size()){
    if(N <= id) break;
    rep(j,w[i].B){
      if(v[id] < w[i].C){
        v[id] = w[i].C;
        id++;
      } else break;
    }
  }

  ll sum = 0;
  rep(i,v.size()) sum += v[i];
  cout << sum << endl;
  
  return 0;
}


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

using namespace std;

int main(){
  string s;
  cin >> s;
  bool f = false;
  for(auto i : s){
    if(i == 'C'){
      f = true;
    }
    if(i == 'F' && f){
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
}


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

template <typename T, typename U>
struct min_cost_flow_graph_bellman_ford {
	
	struct edge {
		int from, to;
		T cap, f;
		U cost;
	};
	
	vector<edge> edges;
	vector<vector<int>> g;
	int n, st, fin;
	T required_flow, flow;
	U cost;
	
	min_cost_flow_graph_bellman_ford(int n, int st, int fin, T required_flow)
		: n(n), st(st), fin(fin), required_flow(required_flow) {
			assert(0 <= st && st < n && 0 <= fin && fin < n && st != fin);
			g.resize(n);
			flow = 0;
			cost = 0;
	}
	
	void clear_flow() {
		for (const edge &e : edges) {
			e.f = 0;
		}
		flow = 0;
		cost = 0;
	}
	
	void add(int from, int to, T cap = 1, T rev_cap = 0, U cost = 1) {
		assert(0 <= from && from < n && 0 <= to && to < n);
		g[from].emplace_back(edges.size());
		edges.push_back({from, to, cap, 0, cost});
		g[to].emplace_back(edges.size());
		edges.push_back({to, from, rev_cap, 0, -cost});
	}
	
	U min_cost_flow() {
		while (flow < required_flow) {
			vector<int> preve(n);
			vector<U> dist(n, numeric_limits<U>::max() / 2);
			dist[st] = 0;
			for (bool update = true; update; ) {
				update = false;
				for (int i = 0; i < n; i++) {
					for (int id : g[i]) {
						const edge &e = edges[id];
						if (0 < e.cap - e.f && dist[e.from] + e.cost < dist[e.to]) {
							dist[e.to] = dist[e.from] + e.cost;
							preve[e.to] = id;
							update = true;
						}
					}
				}
			}
			if (dist[fin] == numeric_limits<U>::max() / 2) {
				return -1;
			}
			T d = required_flow - flow;
			for (int i = fin; i != st; i = edges[preve[i]].from) {
				d = min(d, edges[preve[i]].cap - edges[preve[i]].f);
			}
			flow += d;
			cost += d * dist[fin];
			for (int i = fin; i != st; i = edges[preve[i]].from) {
				edges[preve[i]].f += d;
				edges[preve[i] ^ 1].f -= d;
			}
		}
		return cost;
	}
};

int main() {
	int n, m, f;
	cin >> n >> m >> f;
	min_cost_flow_graph_bellman_ford<int, int> g(n, 0, n - 1, f);
	for (int i = 0; i < m; i++) {
		int from, to, cap, cost;
		cin >> from >> to >> cap >> cost;
		g.add(from, to, cap, 0, cost);
	}
	cout << g.min_cost_flow() << endl;
	return 0;
}

Measured memory_bytes: 3240
/*
  mail: mleautomaton@foxmail.com
  author: MLEAutoMaton
  This Code is made by MLEAutoMaton
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define REP(a,b,c) for(int a=b;a<=c;a++)
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline int gi(){
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=42,M=1<<17,Mod=1e9+7;
int f[N][M],n,X,Y,Z;
int main(){
	n=gi();X=gi();Y=gi();Z=gi();
	int LIM=1<<(X+Y+Z),ans=1,Q=0;
	f[0][0]=1;Q=1<<X-1;Q<<=Y;Q|=(1<<Y-1);Q<<=Z;Q|=(1<<Z-1);
	for(int i=0;i<n;i++){
		ans=1ll*ans*10%Mod;
		for(int j=0;j<LIM;j++)
			if(f[i][j]){
				for(int k=1;k<=10;k++){
					int trans=((j<<k)|(1<<k-1))&(LIM-1);
					if((trans&Q)!=Q)f[i+1][trans]=(f[i+1][trans]+f[i][j])%Mod;
				}
			}
	}
	for(int i=0;i<LIM;i++)ans=(ans-f[n][i]+Mod)%Mod;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 19328
from enum import Enum
import sys
import math
 
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
 
 
def calc_gcd(a,b):
    if a < b:
        a,b = b,a
    if b == 0:
        return a
    return calc_gcd(b,a%b)
 
 
A,B = map(int,input().split())
print("%d"%(calc_gcd(A,B)))


Measured memory_bytes: 6380
a,b=map(int,input().split())
s=input()

tmp1=s[:a]
tmp2=s[a]
tmp3=s[a+1:]

if all([tmp1[i]!='-' for i in range(len(tmp1))])==True and tmp2=='-' and all([tmp3[i]!='-' for i in range(len(tmp3))])==True:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 38384
/*
 * main.c
 *
 *  Created on: 2019/12/29
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;

typedef struct {
	char title[101];
	int  time;
} PLAY_t;

PLAY_t p[51] = {0};
char X[101] = {0};
int main()
{
	int N = 0, i = 0, count = 0, ans = 0, len = 0;
	scanf("%d", &N);
	for (i = 0; i < N; i++) {

		scanf("%s %d", &(p[i].title[0]), &(p[i].time));
		//printf("%s %d\n", p[i].title, p[i].time);
	}
	scanf("%s", X);
	len = strlen(X);
	for (i = 0; i < N; i++) {
		if (count == 1) {
			ans += p[i].time;
		}
		if (strncmp(X, p[i].title, len) == 0) {
			//printf("countstart %d\n", i);
			count = 1;
		}
	}
	printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
#      
import collections, atexit, math, sys, bisect 

sys.setrecursionlimit(1000000)
def getIntList():
    return list(map(int, input().split()))    

try :
    #raise ModuleNotFoundError
    import numpy
    def dprint(*args, **kwargs):
        #print(*args, **kwargs, file=sys.stderr)
        # in python 3.4 **kwargs is invalid???
        print(*args,  file=sys.stderr)
    dprint('debug mode')
except Exception:
    def dprint(*args, **kwargs):
        pass



inId = 0
outId = 0
if inId>0:
    dprint('use input', inId)
    sys.stdin = open('input'+ str(inId) + '.txt', 'r') #标准输出重定向至文件
if outId>0:
    dprint('use output', outId)
    sys.stdout = open('stdout'+ str(outId) + '.txt', 'w') #标准输出重定向至文件
    atexit.register(lambda :sys.stdout.close())     #idle 中不会执行 atexit
    
N, = getIntList()
#print(N)

A,B  = getIntList()
zp  = getIntList()

zp.sort()
r0 = 0
r1 = 0
r2 = 0
for x in zp:
    if x<= A:
        r0 +=1
    elif x>B:
        r2+=1
    else:
        r1 +=1
print( min(r0,r1,r2))




Measured memory_bytes: 21536
s = input()

s = s.replace("A","0").replace("BC", "1").replace("B"," ").replace("C"," ")
ss = list(s.split())
ans = 0
for e in ss:
    next = 0
    for i in range(len(e)):
        if e[i] == "1":
            ans += (i-next)
            next += 1
print(ans)
    


Measured memory_bytes: 5664
#include<bits/stdc++.h>
#define debug(x) cerr<<#x<<" = "<<x<<endl
#define debug2(a, b) cerr<<#a<<" = "<<a<<" | "<<#b<<" = "<<b<<endl
#define debug3(a, b, c) cerr<<#a<<" = "<<a<<" | "<<#b<<" = "<<b<<" | "<<#c<<" = "<<c<<endl
#define debug4(a, b, c, d) cerr<<#a<<" = "<<a<<" | "<<#b<<" = "<<b<<" | "<<#c<<" = "<<c<<" | "<<#d<<" = "<<d<<endl
#define debug5(a, b, c, d, e) cerr<<#a<<" = "<<a<<" | "<<#b<<" = "<<b<<" | "<<#c<<" = "<<c<<" | "<<#d<<" = "<<d<<" | "<<#e<<" = "<<e<<endl
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
const int N = 1000 + 5;
const int MOD = 1e9 + 7;
const int INF = 2e9;

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


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

int res[maxn];

int main(){
    for(int i=1;i<=100;i++){
        for(int j=1;j<=100;j++){
            for(int k=1;k<=100;k++){
                int x = (i*i) + (j*j) + (k*k) + (i*j) + (j*k) + (k*i);
                res[x] ++;
            }
        }
    }
    int n;
    cin >> n;
    for(int i=1;i<=n;i++){
        cout << res[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3860
//QWsin
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define out(i,u) for(int i=first[u];i!=-1;i=nxt[i])
#define repvc(i,vc) for(int i=0,Sz=vc.size();i<Sz;++i)
using namespace std;
inline int read()
{
	char ch=getchar();int ret=0,f=1;
	while(ch<'0' || ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	for(;ch>='0' && ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret*f;
}

typedef long long ll;
const int INF=1<<30;

int main()
{
//	freopen("std.in","r",stdin);
	ll h,w;cin>>h>>w;
	if(h==1 || w==1){
		cout<<1<<endl;	
	}
	else cout<<((h+1)/2)*((w+1)/2) + (h/2)*(w/2)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cassert>
#include <queue>
#include <vector>
#include <algorithm>
#include <iostream>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

const pair<int,int> INF(1000000, 10000001);


int n;
int vs[200000+10];
int v2i[200000+10];

int hvs[2][100000+10];

// http://www.prefield.com/algorithm/container/range_minimum.html
int *buildRMQ(int *a, int n) {
  int logn = 1;
  for (int k = 1; k < n; k *= 2) ++logn;
  int *r = new int[n * logn];
  int *b = r; copy(a, a+n, b);
  for (int k = 1; k < n; k *= 2) {
    copy(b, b+n, b+n); b += n;
    REP(i, n-k) b[i] = min(b[i], b[i+k]);
  }
  return r;
}
int minimum(int x, int y, int *rmq, int n) {
  int z = y - x, k = 0, e = 1, s; // y - x >= e = 2^k なる最大 k
  s = ( (z & 0xffff0000) != 0 ) << 4; z >>= s; e <<= s; k |= s;
  s = ( (z & 0x0000ff00) != 0 ) << 3; z >>= s; e <<= s; k |= s;
  s = ( (z & 0x000000f0) != 0 ) << 2; z >>= s; e <<= s; k |= s;
  s = ( (z & 0x0000000c) != 0 ) << 1; z >>= s; e <<= s; k |= s;
  s = ( (z & 0x00000002) != 0 ) << 0; z >>= s; e <<= s; k |= s;
  return min( rmq[x+n*k], rmq[y+n*k-e+1] );
}

int* rmq[2];

struct K {
  int bg, ed;
  int i1, i2;
  K(int bg, int ed) : bg(bg), ed(ed) {
    int v1 = minimum(bg/2, (ed-2)/2, rmq[bg%2], n/2);
    i1 = v2i[v1];
    int v2 = minimum((i1+1)/2, (ed-1)/2, rmq[bg%2^1], n/2);
    i2 = v2i[v2];
  }
};
bool operator>(const K& a, const K& b) {
  return vs[a.i1] > vs[b.i1];
}


int main(void) {
  scanf("%d", &n);
  REP(i, n) {
    scanf("%d", &vs[i]);
    v2i[vs[i]] = i;
    hvs[i%2][i/2] = vs[i];
  }
  REP(i, 2) {
    rmq[i] = buildRMQ(hvs[i], n/2);
  }

  vector<int> res;
  priority_queue<K, vector<K>, greater<K> > q;
  q.push(K(0, n));
  while(!q.empty()) {
    K cur = q.top(); q.pop();
    int i1 = cur.i1;
    int i2 = cur.i2;
    res.push_back(vs[i1]);
    res.push_back(vs[i2]);
    if(cur.bg < i1) {
      q.push(K(cur.bg, i1));
    }
    if(i1 + 1 < i2) {
      q.push(K(i1+1, i2));
    }
    if(i2 + 1 < cur.ed) {
      q.push(K(i2+1, cur.ed));
    }
  }
  REP(i, n) {
    printf("%d%c", res[i], i == n-1 ? '\n' : ' ');
  }
  
  return 0;
}

/*
えーと？
逆順に考えるのが筋が良さそうな気はする。
辞書順最小を目指すわけでー
qの0番目になれるのは、pの2*i番目のやつだけだ。
で、1番目になれるのは、2*(i+j)+1番目のやつだけだ。
そうすると、pは3つの列に分かれる。
分離した別パートのやつと組を作ることはできない。
となるとそれぞれの中で独立で、えーと？
うん。列の範囲[a,b]から、辞書順最小な組の列を生み出す問題になった。
これを愚直にやって良ければ簡単だけど、2*10^5だもんな。なるほど。
なんかこうRMQでできそうではある。奇数番目偶数番目が面倒くさいけど。
ええと、先頭に立つべきやつは、(0-originで)偶数番目のやつの最小だ。その相方になるべきは、その位置より右で奇数番目の最小だ。
これにより、分割ステップがO(logN)で行える。
最悪に偏ったとしてもO(NlogN)にはなるんじゃないかな。
あ、ちょい待ち。マージのステップがまずい？
上手く構造化してマージを遅延すればいけるかな...？
えーこれ超面倒では。
...
...
あー、priority queueで探索する感じか！その範囲の先頭となるやつだけ求めて、あとは遅延させれば良い。
これだー！


 */


Measured memory_bytes: 19444
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a)
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;

inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}

const int maxn=305;
//i_am_noob
int n,a[maxn],diff,x,y;

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> n;
    rep(n) cin >> a[i];
    if(n==2){
        if(a[0]<a[1]||(a[0]+a[1])%2==1) print1(-1);
        else print1((a[0]-a[1])/2);
        return 0;
    }
    rep2(i,3,n) a[2]^=a[i];
    if(a[0]+a[1]<a[2]||(a[0]+a[1]+a[2])%2==1){
        print1(-1);
        return 0;
    }
    diff=(a[0]+a[1]-a[2])/2;
    if((diff&a[2])||diff>a[0]){
        print1(-1);
        return 0;
    }
    x=diff,y=diff^a[2];
    rep3(i,60,0) if(a[2]&pow2(i)) if((x^pow2(i))<=a[0]) x^=pow2(i),y^=pow2(i);
    print1(x?a[0]-x:-1);
    return 0;
}


Measured memory_bytes: 3612
/*
https://leetcode.com/problems/maximum-of-absolute-value-expression/discuss/339968/JavaC++Python-Maximum-Manhattan-Distance

Intuition
Take |x[i] - x[j]| + |y[i] - y[j]| as Manhattan distance of two points.
x is the coordinate of points on the x-axis,
y is the coordinate of points on the y-axis.


Explanation 1: Math
Assume i < j, there are four possible expression:
|x[i] - x[j]| + |y[i] - y[j]| = (x[i] - x[j]|) + (y[i] - y[j]) = (x[i] + y[i]|) - (x[j] + y[j])
|x[i] - x[j]| + |y[i] - y[j]| = (x[i] - x[j]|) - (y[i] - y[j]) = (x[i] - y[i]|) - (x[j] - y[j])
|x[i] - x[j]| + |y[i] - y[j]| = -(x[i] - x[j]|) + (y[i] - y[j]) = (-x[i] + y[i]|) - (-x[j] + y[j])
|x[i] - x[j]| + |y[i] - y[j]| = -(x[i] - x[j]|) - (y[i] - y[j]) = (-x[i] - y[i]|) - (-x[j] - y[j])

So we can see, the expression
|x[i] - x[j]| + |y[i] - y[j]| + |i - j| = f(j) - f(i)

where f(i) = p * x[i] + q * y[i] + i
with p = 1 or -1, q = 1 or -1


Explanation 2: Graph
For 3 points on the plane, we always have |AO| - |BO| <= |AB|.
When AO and BO are in the same direction, we have ||AO| - |BO|| = |AB|.

We take 4 points for point O, left-top, left-bottom, right-top and right-bottom.
Each time, for each point B, and find the smallest A point to O,
the Manhattan distance |AB| >= |AO| - |BO|.


*/
#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define debug(...) 42
#endif

void solve() {
	int n, x, y;
	cin >> n;
	vector<int> sum(n), diff(n);
	for (int i = 0; i < n; i++) {
		cin >> x >> y;
		sum[i] = x;
		diff[i] = y;
	}

	int ans = 0;

	for (int p : {1, -1}) {
		for (int q : {1, -1}) {
			int smallest = p * sum[0] + q * diff[0] + 0;
			for (int i = 1; i < n; ++i) {
				int cur = p * sum[i] + q * diff[i];
				ans = max(ans, cur - smallest);
				smallest = min(smallest, cur);
			}
		}
	}

	cout << ans;
}

int32_t main() {
	ios::sync_with_stdio(0); 		cin.tie(0); cout.tie(0);

	solve();
}



Measured memory_bytes: 4772
#!/usr/bin/env python3
import sys
import bisect


def solve(n: int, a: "List[int]"):
    a.sort()
    N = a[-1]
    i = bisect.bisect(a, N // 2)
    candidate = [a[i]]
    if i > 0:
        candidate.append(a[i-1])
    if i < n-1:
        candidate.append(a[i+1])
    m = N*2
    for c in candidate:
        if c == N:
            continue
        if abs(N//2 - c) < abs(N//2 - m):
            m = c
    print(N, m)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(n) ]  # type: "List[int]"
    solve(n, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 59808
n, m =map(int, input().split())
h=list(map(int, input().split()))
h2=[]
for i in range(n):
    h2.append(h[i])
for i in range(m):
    a,b=map(int, input().split())
    a=a-1
    b=b-1
    if h[a]<h[b]:
        h2[a]=0
    elif h[b]<h[a]:
        h2[b]=0
    else:
        h2[a]=0
        h2[b]=0

print(n-h2.count(0))


Measured memory_bytes: 19920
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b){
	while(b){
		a %= b;
		swap(a, b);
	}
	return a;
}
int main(){
	int a, b, c, d; cin >> a >> b >> c >> d;
	a = abs(a - c);
	b = abs(b - d);
	cout << a + b - gcd(a, b) << endl;
	return 0;
}


Measured memory_bytes: 256
import fractions

def calc_lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

A, B, C, D = map(int, input().split())
lcm = calc_lcm(C, D)

ac = (A-1) // C
bc = B // C
ad = (A-1) // D
bd = B // D
alcm = (A-1) // lcm
blcm = (B) // lcm

num_c = bc - ac
num_d = bd - ad
num_lcm = blcm - alcm

ans = (B - A + 1) - (num_c + num_d - num_lcm)

print(ans)


Measured memory_bytes: 5076
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

int main()
{
    string s, t;
    int n;
    cin >> n;
    cin >> s >> t;
    for (int i = n; i >= 0; i--)
    {
        //        cout << "a:" << s.substr(n - i, i) << " " << t.substr(0, i) << endl;
        if (s.substr(n - i, i) == t.substr(0, i))
        {
            string aaaaa= s +t.substr(i);
            cout << aaaaa.length() << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
ll A,B,N;

ll calc(ll x) {
  return (A*x)/B - A*(x/B);
}
  
int main() {
  cin >> A >> B >> N;
  cout << calc(min(N,B-1)) << endl;
  return 0;
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define PB push_back

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVi;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;

int main(){
	ios::sync_with_stdio(false);
    LL n,m;
    cin>>n>>m;

    LL ans=0;
    if(m < 2*n){
        ans+=m/2;
    }
    else{
        ans+=n;
        LL buf=m;
        buf = m - n*2;
        ans += buf/4;
    }
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007 
#define N 100001

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,m,x;
    cin>>n>>m>>x;
    ll ans = x/max(n,m);
    if(x%max(n,m)!=0) ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int n = 5;
int w = 4;
int t = 1;
int tmp;

int right()
{ 
    tmp = n;
    n = w;
    w = 7 - tmp;
    return t;
}
int left()
{
    tmp = w;
    w = n;
    n = 7 - tmp;
    return t;
}
int north()
{
    tmp = n;
    n = t;
    t = 7 - tmp;
    return t;
}
int east()
{
    tmp = t;
    t = w;
    w = 7 - tmp;
    return t;
}
int west()
{
    tmp = w;
    w = t;
    t = 7 - tmp;
    return t;
}
int south()
{
    tmp = t;
    t = n;
    n = 7 - tmp;
    return t;
}
 
int main()
{
    int row;
	
    while (cin >> row, row) {
        int sum = 1;
        n = 5;
        w = 4;
        t = 1;
        string str;
		
        for (int i = 0; i < row; i++) {
            cin >> str;
            if (str == "North") sum += north();
            if (str == "South") sum += south();
            if (str == "West") sum += west();
            if (str == "East") sum += east();
            if (str == "Right") sum += right();
            if (str == "Left") sum += left();
        }
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
#set
n = gets.chomp.to_i
s = gets.chomp.split(" ").map(&:to_i).sort.reverse
count = 0

#main
0.upto(n - 1) do |i|
    j = i + 1
    k = n - 1

    while j < k do
        if s[k] > s[i] - s[j] then
            count += (k - j)
            j += 1
        else
            k -= 1
        end
    end
end

print ("#{count}\n")

Measured memory_bytes: 1912
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define hell 1000000007
#define PI 3.14159265358979323846
using namespace std;

int main()
{
   ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //cin>>t;
    //int c=0;
    while(t--) {

       ll n,i,j,k,ans=0;
       cin>>n;
       for(i=1;i<=n;i++)
       {
           j=n/i;
           if(n%i==0)
            --j;
           ans+=j;
       }
       cout<<ans;
    }

}


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

int main() {
   int X, Y;
   cin >> X >> Y;
   
   for(int i=0; i<=X; i++) {
      int j= X-i;
      if(2 * i + 4 * j == Y) {
         cout << "Yes" << endl;
         return 0;
      }
   }
   cout << "No" << endl;
}

Measured memory_bytes: 3596
/* package whatever; // don't place package name! */

import java.util.*;

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

        int N = sc.nextInt();
        sc.nextLine();
        int[] list = new int[N-1];
        int sum = 0;

        for (int i = 0; i < N-1; i++) {
            list[i] = sc.nextInt();
        }
        sum = list[0] + list [N-2];

        for (int i = 1; i <= N-2; i++) {
            sum += Math.min(list[i-1], list[i]);
        }

        System.out.println(sum);
        sc.close();
    }
}

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

using namespace std;

#define debug(x) cout << '>' << #x << ':' << x << endl;
#define loop0(i,n) for(int i=0; i<(n); i++)
#define loop1(i,n) for(int i=1; i<=(n); i++)
#define fori(a,b,i) for(int i=(a); i<=(b); i++)
#define ford(a,b,i) for(int i=(a); i>=(b); i--)
#define fast_io ios_base::sync_with_stdio(false), cin.tie(NULL);


#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define endl "\n"
#define fir first
#define sec second
#define pb push_back
#define mp make_pair

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MII;
typedef set<int> SI;
typedef long long int llint;
int main(){
        string s;
        cin >> s;
        if(s == "ABC") cout << "ARC\n";
        else cout << "ABC\n";
}

Measured memory_bytes: 3592
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
   
int main()
{
	char a[101],b[101],c[201];
	cin >> a >> b;
	strcpy(c,a);
	strcat(c,a);
	if(strstr(c,b))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;		
	return 0;
}

Measured memory_bytes: 3088
//in the name of ALLAH
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,c,k,s=0;
    cin>>a>>b>>c>>k;

    if(a>=k)
    {
        cout<<k<<endl;
    }
    else
    {
        s=a;
        if(a+b>=k)
            cout<<a<<endl;
        else
        {
            if(a+b+c>=k)
                cout<<a-(k-a-b)<<endl;
            else
                cout<<a-c<<endl;
        }
    }

}



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

#define rep(i, n) for ( ll i = 0; i < (n); ++i )
#define reps(i, n) for ( ll i = 1; i <= (n); ++i )
#define _rep(i, n) for ( ll i = (n) - 1; i >= 0; --i )
#define _reps(i, n) for ( ll i = n; i > 0; --i )
#define all(x) (x).begin(), (x).end()
#define _all(x) (x).rbegin(), (x).rend()

using namespace std;
using ll =  long long;
using P = pair<ll, ll>;

ll n, m, x;
ll c[12], a[12][12];

ll alg[12];
ll tmp;
ll ans = -1;


void dfs( ll d )
{
	int i;
	for( i = 0; i < m; i++ ) {
		if ( alg[i] < x ) {
			break;
		}
	}
	if ( i == m ) {
		if ( (ans == -1) || (ans >= tmp) ) {
			ans = tmp;
		}
		return;
	}

	if ( d >= n ) {
		return;
	}

	// d番目の参考書を選ばない
	dfs( d + 1 );

	// d番目の参考書を選ぶ
	rep( j, m ) {
		alg[j] += a[d][j];
	}
	tmp += c[d];
	dfs( d + 1 );
	rep( j, m ) {
		alg[j] -= a[d][j];
	}
	tmp -= c[d];
}

int main( void )
{
	cin >> n >> m >> x;

	rep( i, n ) {
		cin >> c[i];
		rep( j, m ) {
			cin >> a[i][j];
		}
	}

	dfs( 0 );

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
typedef long long LL;
using namespace std;

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

  string ans;
  if (a > 0) {
    ans = "Positive";
  } else if (a <= 0 && b >= 0) {
    ans = "Zero";
  } else if ((b - a + 1) % 2 == 0) {
    ans = "Positive";
  } else {
    ans = "Negative";
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);

void main()
{
    long n, m;
    scan(n, m);
    // writeln(m);

    auto a = aryread();
    // writeln(a);
    long sum_x;
    sum_x = sum(a);
    // writeln(sum_x);
    long cnt;
    foreach (i; 0 .. n)
    {
        if (sum_x <= a[i] * (4 * m))
        {
            cnt += 1;

        }
    }
    // writeln(cnt);
    if (cnt >= m)
    {
        writeln("Yes");
    }
    else
    {
        writeln("No");
    }

}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}


Measured memory_bytes: 3708