akhauriyash/Code-Regression huggingface dataset:
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

static class P
{
    static void Main()
    {
        var nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nk[0];
        var k = nk[1];
        var theoritical = (n - 1) * (n - 2) / 2;
        if (theoritical < k)
        {
            Console.WriteLine(-1);
            return;
        }
        List<Tuple<int, int>> edges = new List<Tuple<int, int>>();
        //ベースとなる木の構築
        edges.AddRange(Enumerable.Range(2, n - 1).Select(x => new Tuple<int, int>(1, x)));
        //辺を引いてペアを殺す
        //辺の集合
        edges.AddRange(
            Enumerable.Range(2, n - 1).SelectMany(x => Enumerable.Range(2, x - 2).Select(y => new Tuple<int, int>(y, x))).Take(theoritical - k)
        );
        Console.WriteLine(edges.Count);
        Console.WriteLine(string.Join("\n", edges.Select(x => $"{x.Item1} {x.Item2}")));
    }
}


Measured memory_bytes: 13524
n = int(input())

for i in range(100): #2重ループでケーキ，ドーナツの数を1個ずつ変えていってnドルになった時に終了させる
    for j in range(100):
        if i * 4 + j * 7 == n:
            print("Yes")
            exit()

print("No")

Measured memory_bytes: 2940
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <cmath>

using namespace std;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mp make_pair
#define all(a) (a).begin(), (a).end()
typedef long long ll;

template<typename T>
void vdeb(vector<T> &da){
    int size=da.size();
    for(int i=0;i<size;i++){
        if(i==size-1){
            cout << da[i] << endl;
        }
        else{
            cout << da[i] << ' ';
        }
    }
}

ll nap(int now, vector<ll> &x, vector<ll> &y){
    vector<ll> dp(now + 1,0);
    rip(i,now + 1,0){
        dp[i] = i;
        rip(j,3,0){
            if(i - x[j] < 0){
                continue;
            }
            dp[i] = max(dp[i], dp[i - x[j]] + y[j]);
        }
    }
    //vdeb(dp);
    return dp[now];
}

int main(){
    int n;
    vector<ll> a(3),b(3);
    cin >> n;
    rip(i,3,0){
        cin >> a[i];
    }
    rip(i,3,0){
        cin >> b[i];
    }
    int x = nap(n, a, b);
    ll ans = nap(x, b, a);
    cout << ans << endl;
}

Measured memory_bytes: 195584
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <math.h>
#include <queue>
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;

int main() {
    string s,t;
    cin >> s >> t;
    int cnt=0;
    for(int i=0; i<s.size(); i++) {
        if(s[i]!=t[i]) cnt++;
    }
    cout << cnt << endl;
}

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

using namespace std;

int main()
{  int n,k,i,j;
   string st;
   cin>>n>>k;
   j=0;
   cin>>st;
   for(i=0;i<st.length();i++)
   {
       j++;
       if(j==k)
       {st[i]=st[i]+32;}
       cout<<st[i];
   }
   return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
    Main(){
	Scanner sc =new Scanner(System.in);
	int a ,c;
	for(int i=0;i<4;i++){
	    a=sc.nextInt();
	    c=sc.nextInt();
	    int b=0;
	    switch(a){
	    case 1:
		b+=6000*c;
		break;
	    case 2:
		b+=4000*c;
		break;
	    case 3:
		b+=3000*c;
		break;
	    case 4:
		b+=2000*c;
		break;
	    }
	    System.out.println(b);	
	}
    }
    public static void main (String[]arg){
	new Main();
    }
}

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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    int day = 0;
    for (int i = 0; i < m; i++)
    {
        cin >> a[i];
        day += a[i];
    }
    if (n >= day)
    {
        cout << n - day << endl;
    }
    else
    {
        cout << -1 << endl;
    }
    return 0;
}

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

using namespace std;

const int N = 55;

vector <long long> masks[N][N];
int a[N];
int b[N];

int main() {
  for (int j = 0; j <= 50; ++j) {
    for (int i = 0; i <= 50; ++i) {
      masks[i][j].clear();
    }
    masks[j][j].push_back(0);
    for (int i = j + 1; i <= 50; ++i) {
      for (int k = 1; k <= i; ++k) {
        for (auto e : masks[i % k][j]) {
          masks[i][j].push_back(e | (1LL << k));
        }
      }
    }
  }
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", b + i);
  }
  long long ans = 0;
  for (int bit = 50; bit >= 1; --bit) {
    for (int it = 0; it < 2; ++it) {
      bool can = true;
      for (int i = 0; i < n; ++i) {
        bool any = false;
        for (auto e : masks[a[i]][b[i]]) {
          bool ok = true;
          for (int nbit = bit; nbit <= 50; ++nbit) {
            if (((ans >> nbit) & 1) == 0 && ((e >> nbit) & 1) == 1) {
              ok = false;
              break;
            }
          }
          if (ok) {
            any = true;
            break;
          }
        }
        if (!any) {
          can = false;
          break;
        }
      }
      if (can) {
        break;
      }
      if (it == 1) {
        puts("-1");
        return 0;
      }
      ans |= 1LL << bit;
    }
  }
  printf("%lld\n", ans);
}


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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define FOR(i,m,n) for(int i=(m) ; i<(n) ; i++)
#define FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1000000000;

int main(){
   int a,b;
   cin >> a >> b;
   int ans = 0;
   for(int i=1;i<=b-a;i++){
      ans += i;
   }
   ans -= b;
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    short r, c;

    fscanf(stdin, "%hd %hd", &r, &c);

    short A[r][c];
    short i, j;
    for (i = 0; i < r; i++) {
        for (j = 0; j < c; j++) {
            fscanf(stdin, "%hd", &A[i][j]);
        }
    }

    int sum, sum_t = 0;
    for (i = 0; i < r; i++) {
    sum =  0;
        for (j = 0; j < c; j++) {
            fprintf(stdout, "%hd ", A[i][j]);
            sum += A[i][j];
        }
	sum_t += sum;
        fprintf(stdout, "%d\n", sum);
    }

    for (i = 0; i < c; i++) {
    sum = 0;
        for (j = 0; j < r; j++) {
            sum += A[j][i];
        }
        fprintf(stdout, "%d ", sum);
    }
    fprintf(stdout, "%d\n", sum_t);

    return 0;
}

Measured memory_bytes: 624
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws Exception{
		int num = 998244353;

		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);
 		
	 		StringTokenizer st = new StringTokenizer(bf.readLine());
	 		int x = Integer.parseInt(st.nextToken());
	 		int n = Integer.parseInt(st.nextToken());
	 		
	 		StringTokenizer st1 = new StringTokenizer(bf.readLine());
	 		Set<Integer> no = new HashSet<Integer>();
	 		for(int i = 0;i<n;i++){
	 			no.add(Integer.parseInt(st1.nextToken()));
	 		}
	 		boolean negative = true;
	 		if (!no.contains(x)){
	 			out.println(x);
	 		}
	 		else{
	 		for(int i = 1;i<301;i++){
	 			if (negative == true){
	 				x = x-i;
	 				negative = false;
	 			}
	 			else{
	 				x = x+i;
	 				negative = true;
	 			}
	 			if (!no.contains(x)){
	 				out.println(x);
	 				out.close();
	 			}
	 			
	 		}
 		
	 		}
	 		
 		
 		
 		out.println();
	 		
 		out.close();
 		
 		
 		
 	}
}
 	
 
//StringJoiner sj = new StringJoiner(" "); 
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is

 		
 		
 		
 		
	




Measured memory_bytes: 25704
import math

def koch(n,p1x,p1y,p2x,p2y):
    if n == 0:
        return
    
    sx = (2*p1x+1*p2x)/3
    sy = (2*p1y+1*p2y)/3
    tx = (1*p1x+2*p2x)/3
    ty = (1*p1y+2*p2y)/3
    theta = math.pi/3  #180[deg] == math.pi[rad]
    ux = math.cos(theta)*(tx-sx) - math.sin(theta)*(ty-sy)+sx
    uy = math.sin(theta)*(tx-sx) + math.cos(theta)*(ty-sy)+sy

    koch(n-1, p1x, p1y, sx, sy)
    print("{:.5f} {:.5f}".format(sx, sy))
    koch(n-1, sx, sy, ux, uy)
    print("{:.5f} {:.5f}".format(ux, uy))
    koch(n-1, ux, uy, tx, ty)
    print("{:.5f} {:.5f}".format(tx, ty))
    koch(n-1, tx, ty, p2x, p2y)

n = int(input())
p1x,p1y = 0.0,0.0
p2x,p2y = 100.0,0.0
print("{:.5f} {:.5f}".format(p1x, p1y))
koch(n, p1x, p1y, p2x, p2y)
print("{:.5f} {:.5f}".format(p2x, p2y))



Measured memory_bytes: 5808
import java.util.Scanner;

class Main{



	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int H = sc.nextInt();
		int W = sc.nextInt();
		char[][] map = new char[H][W];
		for(int i =0;i < H;i++){
			String xx = sc.next();
			for(int j = 0;j <W;j++){
				map[i][j] = xx.charAt(j);
			}
		}
//		for(int i = 0;i < H;i++){
//			for(int j = 0;j < W;j++){
//				System.out.print(map[i][j]);
//			}
//			System.out.println();
//		}
//		
//		
		int[] tate = new int[H];
		for(int i =0;i < H;i++){
			int count = 0;
			for(int j = 0;j <W;j++){
				if(map[i][j] == '.'){
					count++;
				}
			}
			if(count == W){
				tate[i] = 1;
			}
		}	
//		for(int i = 0;i < H;i++){
//			System.out.print(tate[i]);
//		}
//		System.out.println();
		
		int[] yoko = new int[W];
		for(int i =0;i < W;i++){
			int count = 0;
			for(int j = 0;j <H;j++){
				if(map[j][i] == '.'){
					count++;
				}
			}
			if(count == H){
				yoko[i] = 1;
			}
		}
//		for(int i = 0;i < W;i++){
//			System.out.print(yoko[i]);
//		}
//		System.out.println();
		
		for(int i =0;i < H;i++){
			int cc = 0;
			for(int j = 0;j <W;j++){
				if(tate[i]==0){
					if(yoko[j] == 0){
						System.out.print(map[i][j]);
						cc++;
					}
				}
				
			}
			if(cc > 0){
				System.out.println();	
			}

		}


	}


}

class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return from - otherpair.from;
	}
}



Measured memory_bytes: 25492
#include <iostream>
#include <sstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
using namespace std;

class position
{
public:
    position(int y0, int x0, int d0){
        y = y0;
        x = x0;
        d = d0;
    }
    int y, x, d;
};

void solve(vector<vector<int> > square, vector<int> cost)
{
    int goalY = square.size() - 2;
    int goalX = square[0].size() - 2;
    multimap<int, position> mmPosition;
    mmPosition.insert(make_pair(0, position(1,1,1)));
    vector<vector<vector<bool> > > check(square.size(), vector<vector<bool> >(square[0].size(), vector<bool>(4, false)));

    int dx[] = {0,1,0,-1};
    int dy[] = {-1,0,1,0};
    for(;;){
        multimap<int, position>::iterator it = mmPosition.begin();
        int c = it->first;
        int y = it->second.y;
        int x = it->second.x;
        int d = it->second.d;
        mmPosition.erase(it);
        if(square[y][x] == -1 || check[y][x][d])
            continue;
        check[y][x][d] = true;
        if(y == goalY && x == goalX){
            cout << c << endl;
            return;
        }

        for(int i=0; i<4; ++i){
            if(i == square[y][x])
                mmPosition.insert(make_pair(c, position(y+dy[d], x+dx[d], d)));
            else
                mmPosition.insert(make_pair(c+cost[i], position(y+dy[d], x+dx[d], d)));
            (++d) %= 4;
        }
    }
}

int main()
{
    for(;;){
        int w, h;
        cin >> w >> h;
        if(w == 0 && h == 0)
            break;

        vector<vector<int> > square(h+2, vector<int>(w+2, -1));
        for(int i=1; i<=h; ++i){
            for(int j=1; j<=w; ++j)
                cin >> square[i][j];
        }
        vector<int> cost(4);
        for(int i=0; i<4; ++i)
            cin >> cost[i];

        solve(square, cost);
    }
    return 0;
}

Measured memory_bytes: 1228
a, b, k = map(int, input().split())
s = set()
for i in range(a, a+k):
    if a <=  i <= b:
        s.add(i)
for i in range(b-k+1, b+1):
    if a <=  i <= b:
        s.add(i)
for i in sorted(s):
    print(i)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;

int main(){
    int n, k, x, y;
    cin>>n>>k>>x>>y;

    if(n<k){
        cout<<x*n<<endl;
    }
    else{
        cout<<x*k+y*(n-k)<<endl;
    }
    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,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int a,b;
    cin >> a >> b;
    if (a > b){
        rep(i,a){
            cout << b;
        }
        cout << endl;
    }
    else{
        rep(i,b){
            cout << a;
        }
        cout << endl;
    }
}



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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<double > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll N;
    string A, B, C;
    cin >> N >> A >> B >> C;

    ll ans = 0;
    for(ll i = 0; i < N; i++){
        if(A[i] == B[i] && B[i] == C[i] && C[i] == A[i]) continue;
        if(A[i] != B[i] && B[i] != C[i] && C[i] != A[i]){
            ans += 2;
        }else{
            ans += 1;
        }
    }

    cout << ans << endl;

}

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

int main(void){
    int a, b, sum, cnt;
    while(cin >> a >> b){
        cnt = 0;
        sum = a+b;
        while(sum){
            sum/=10;
            cnt++;
        }
        cout << cnt <<endl;
    }
    return 0;
}

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

int main() {
    int x;
    cin >> x;
    int ans = 0;
    int now = 0;
    while(now < x) {
        ans++;
        now =(ans*(ans+1))/2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include  <iostream>
using namespace std;
 
int main() {
 
  int n,a[25],b[25];
 
  while(1) {
    cin >> n;
 
    if(n==0) break;
 
    for(int i=0;i<n;i++) {
      cin >> a[i] >> b[i];
 
    }
 
    int t;
    for(int i=0;i<n;i++) {
      for(int j=i;j<n;j++) {
    if(b[i] > b[j]) {
      t = b[i];
      b[i] = b[j];
      b[j] = t;
 
      t = a[i];
      a[i] = a[j];
      a[j] = t;
    }
      }
    }
 
    int sum =0;
    int flag = 0;
    for(int i=0;i<n;i++) {
 
      sum += a[i];
 
      if(sum > b[i]) {
    flag  = 1;
    break;
      }
 
    }
 
    if(flag == 0) cout << "Yes" << endl;
    else cout << "No"<< endl;
 
  }
 
  return 0;
 
}

Measured memory_bytes: 1152
def even(n):
    count = 0
    i = 10
    while(n/i>=1):
        count += n//i
        i *= 5
    return int(count) 

def main():
    N = int(input())

    if N < 2:
        print(0)

    # even
    elif N % 2 == 0:
        print(even(N))
    # odd
    elif N % 2 == 1:
        print(0)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 200000000
int main()
{
	int e;
	while(cin >> e&&e)
	{
		int i,j,t,k,v=0,ans=INF;
		int d[10][10];
		int cost_count[10] = {0};
		for(i=0;i<10;i++)
		{
			for(j=0;j<10;j++)
			{
				d[i][j] = INF;
				if(i==j)
				{
					d[i][j] = 0;
				}
			}
		}
		for(t=0;t<e;t++)
		{
			scanf("%d %d %d",&i,&j,&k);
			v = max(v,max(i,j));
			d[i][j] = k;
			d[j][i] = k;
		}
		for(k=0;k<=v;k++)
		{
			for(i=0;i<=v;i++)
			{
				for(j=0;j<=v;j++)
				{
					d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
				}
			}
		}
		for(i=0;i<=v;i++)
		{
			int cost = 0;
			for(j=0;j<=v;j++)
			{
				cost += d[i][j];
			}
			cost_count[i] = cost;
			ans=min(ans,cost_count[i]);

		}
		for(i=0;i<=v;i++)
		{
			if(cost_count[i]==ans)
			{
				printf("%d %d\n",i,ans);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <math.h>
#include <time.h>
using namespace std;
int main() {
	long long int a, b, c, d[1000], e = 0;
	cin >> a >> b >> c;
	for (int i = 0; i < a; i++) {
		cin >> d[i];
		if (d[i] >= b&&d[i] < c) {
			e++;
		}
	}
	cout << a - e << endl;
	return 0;
}

Measured memory_bytes: 256
use std::io;
use std::str::FromStr;

fn input_tuple() -> (i32, i32, i32, i32) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<i32> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1], vec[2], vec[3])
}


fn main() {
    let (mut a, b, mut c, d) = input_tuple();
    loop {
        // println!("{}, {}", a, c);
        c -= b;
        if c <= 0 {
            println!("Yes");
            return;
        }
        a -= d;
        if a <= 0 {
            println!("No");
            return;
        }
    }
}


Measured memory_bytes: 2108
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int x = sc.nextInt();
			int t = sc.nextInt();

			if (n % x != 0) {
				System.out.println(((n / x) + 1) * t);
			} else {
				System.out.println((n/x) * t);
			}
		}
	}
}


Measured memory_bytes: 35660
n,m,v,p=map(int,input().split())
p-=1
A=sorted(list(map(int,input().split())),reverse=True)[p:]
s=0
for u,a in enumerate(A):
 if a>=A[0]-m and u*a+m*n-m*v>=s:s+=a;p+=1
 else:break
print(p)


Measured memory_bytes: 62704
#include<queue>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
int main(){
  int n,i;
  scanf("%d\n",&n);
  printf("%d:",n);
  for(i=2;i*i<=n;i++){
    while(n%i==0){
      printf(" %d",i);
      n=n/i;
    }
  }
  if(n!=1){
    printf(" %d",n);
  }
  printf("\n");
}


Measured memory_bytes: 3224
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from heapq import heappop, heappush
def resolve():
    n, m = map(int, input().split())
    N = 1 << (n - 1).bit_length()
    N2, now = N << 1, N << 2
    E = [[] for _ in range((N << 2) + (m << 1))]

    # build range-edge graph
    for i in range(N, N2):
        E[i].append((i + N2, 0))
    for i in range(N - 1, 0, -1):
        cl, cr = i << 1, i << 1 | 1
        E[i].append((cl, 0))
        E[i].append((cr, 0))
        E[cl + N2].append((i + N2, 0))
        E[cr + N2].append((i + N2, 0))

    # add range-edge
    for _ in range(m):
        u, v, w = map(int, input().split())
        u -= 1
        # lower
        l, r = u + N, v + N
        while l < r:
            if l & 1:
                E[l + N2].append((now, 0))
                l += 1
            if r & 1:
                r -= 1
                E[r + N2].append((now, 0))
            l >>= 1
            r >>= 1
        # upper
        l, r = u + N, v + N
        while l < r:
            if l & 1:
                E[now + 1].append((l, 0))
                l += 1
            if r & 1:
                r -= 1
                E[now + 1].append((r, 0))
            l >>= 1
            r >>= 1
        # range-edge
        E[now].append((now + 1, w))
        now += 2

    # Dijkstra (source : N, termination : N + n - 1)
    dist = [INF] * now
    dist[N] = 0
    heap = [(0, N)]
    while heap:
        d, v = heappop(heap)
        if dist[v] != d:
            continue
        for nv, w in E[v]:
            if dist[nv] > d + w:
                dist[nv] = d + w
                heappush(heap, (d + w, nv))

    ans = dist[N + n - 1]
    if ans == INF:
        ans = -1
    print(ans)
resolve()

Measured memory_bytes: 294108
#include <bits/stdc++.h>
using namespace std;
int dp[1000000]; //とりまメモリ開放

const vector<string> strings = {"dream", "dreamer", "erase", "eraser"};

bool check(const string &text, int p, const string &pattern)
{
  int i = 0;

  while(i < pattern.size()){
    // patternと同じかどうか一文字ずつチェック
    if(text[p + i] != pattern[i]) return false;
    i++;
  }

  return true;
}

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

  const int N = text.size();

  text = " " + text;

  vector<bool> dp(N+1, false); //結果を収納する．dp={ false, false, false, ... }
  dp[0] = true; //dp = {true, false, false, ...}

  for (int i = 0; i <= N; i++){
    if (dp[i]){
      for (auto &s: strings) //条件の4つの単語それぞれについて
          if (i + s.size() <= N) //残りの文字数が超過していなければ
            dp[i + s.size()] = dp[i + s.size()] || check(text, i+1, s);//論理和．
            // 例えばdream（5文字）だったら，次はi+5文字目以降を確認すればよいので，dp[i+5]をtrueにする．
            // 次の反復ではdp[i+5]文字目以降で同様の動きをする．
            // dreamとdreamerの揺れはここで吸収（どっちの場合についても調べてしまえば問題ない）
    }
  }

  if (dp[N])
    cout << "YES\n";
  else
    cout << "NO\n";

  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int N;
    cin >> N;
    
    vec<int> a(N);
    int x = 0;
    rep(i, N) {
        cin >> a[i];
        x^=a[i];
    }
    rep(i,N){
        int k = x^a[i];
        cout << k << " ";
    }
    cout << endl;
}


Measured memory_bytes: 3968
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, int64_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, int64_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End

using pii = pair<int64_t, int64_t>;

vector<pii> G[int(1e5)]; // {node, cost}
int64_t N, M, K, S;
int64_t p, q;

vector<int64_t> cost(int(1e5), LINF);

int64_t dijkstra() {
    priority_queue<pii, vector<pii>, greater<>> que; // {cost, node}
    cost[0] = 0;
    que.emplace(0, 0);

    while (!que.empty()) {
        int64_t nowcost = que.top().first;
        int64_t nownode = que.top().second;
        que.pop();
        if (cost[nownode] < nowcost) continue;

        for (auto next: G[nownode]) {
            if (chmin(cost[next.first], cost[nownode] + next.second)) {
                que.emplace(cost[next.first], next.first);
            }
        }
    }

    return cost[N - 1];
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N >> M >> K >> S;
    cin >> p >> q;

    queue<size_t> que;
    vector<int64_t> dist(N, LINF);
    vector<int64_t> c(N, p);
    for (size_t i = 0; i < K; ++i) {
        size_t bad; cin >> bad;
        bad--;
        que.emplace(bad);
        c[bad] = LINF;
        dist[bad] = 0;
    }

    vector<size_t> g[N];
    vector<size_t> a(M), b(M);
    for (size_t i = 0; i < M; ++i) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        g[a[i]].emplace_back(b[i]);
        g[b[i]].emplace_back(a[i]);
    }

    while (!que.empty()) {
        size_t now = que.front();
        que.pop();
        for (auto next: g[now]) {
            if (chmin(dist[next], dist[now] + 1)) {
                que.emplace(next);
                if (dist[next] <= S) {
                    c[next] = q;
                }
            }
        }
    }

    c[N - 1] = 0;

    for (size_t i = 0; i < M; ++i) {
        G[a[i]].emplace_back(b[i], c[b[i]]);
        G[b[i]].emplace_back(a[i], c[a[i]]);
    }

    cout << dijkstra() << "\n";

    return 0;
}



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

constexpr int inf = 1e9;

int main() {
    int n; cin >> n;
    vector<int> l(n), sum(n + 1);
    for(int i = 0; i < n; ++i) {
        cin >> l[i];
        sum[i + 1] = sum[i] + l[i];
    }

    const int max_l = n * 1000 + 1;
    vector<vector<int>> dp(n + 1, vector<int>(max_l, inf));
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j < i; ++j) {
            for(int mini_l = 0; mini_l < max_l; ++mini_l) {
                const int nmin = min(mini_l, sum[i] - sum[j]);
                const int nmax = max(dp[j][mini_l], sum[i] - sum[j]);
                dp[i][nmin] = min(dp[i][nmin], nmax);
            }
        }
        if(i != n) {
            dp[i][sum[i]] = sum[i];
        }
    }

    int ans = inf;
    for(int i = 0; i < max_l; ++i) {
        if(dp[n][i] == inf) continue;
        ans = min(ans, dp[n][i] - i);
    }
    cout << ans << endl;
}



Measured memory_bytes: 13180
#include <stdio.h>

int main(){
int i,a[10],b[3],f;
b[0]=0;
b[1]=0;
b[2]=0;
for(i=0;i<10;i++){
scanf("%d",&a[i]);
}
for(i=0;i<10;i++){
if(b[1]>b[0] && b[0]<a[i]){
b[0]=a[i];
continue;
}
if(b[2]>b[1] && b[1]<a[i]){
b[1]=a[i];
continue;
}
if(b[2]<a[i]){
b[2]=a[i];
continue;
}
}
for(i=0;i<2;i++){
if(b[i]<b[i+1]){
f=b[i];
b[i]=b[i+1];
b[i+1]=f;
}
}
if(b[0]<b[1]){
f=b[0];
b[0]=b[1];
b[1]=f;
}
printf("%d\n%d\n%d\n",b[0],b[1],b[2]);

return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
//long long int countt[200003];
#include<ext/pb_ds/assoc_container.hpp> // include the associative containers or group of templates such as set, multimap, map etc.
#include<ext/pb_ds/tree_policy.hpp> // include the tree_order_statistics_node update
using namespace __gnu_pbds; //necessary for the GNU based Policy based data structures.
typedef tree<pair<int,int> ,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define int long long
#define endl "\n"
const int N = 1e6 + 10;


signed main()
{
    FAST;
    int t;
    t=1;
    
    while(t--)
    {
        int i=0,j=0,k=0,n=0,m=0,count=0,temp=0;
        int temp1=0,temp2=0,temp3=0,x=0,l=0,y=0,sum=0;
        int left=0,up=0,down=0,start=0,end=0,r=0,q=0,total=0;
        int maxx=0,minn=0,curr=0,ans=0,places=0,zeroes=0,low=0,high=0;
        int prev=0,mid=0,z=0,d=0,val=0,pos=0,shift=0,h=0,right=0,var=0;
        
        cin>>n;
        int a[n];
        map<int,int> mp,mp1;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            mp[a[i]]++;
        }
        
        ans=0;
        
        if(mp.count(1))
        {
            if(mp[1]==1)
            {
                cout<<1<<endl;
            }
            
            else
            {
                cout<<0<<endl;
            }
            
            return 0;
        }
        
        for(auto it : mp)
        {
            int num = it.first;
            count = it.second;
            
            if(count==1 && mp1.count(num)==0)
            {
                ans++;
            }
            
            if(mp1.count(num)==0)
            {
                for(i=2;i*num<N;i++)
                {
                    mp1[i*num]++;
                }
            }
            
        }
        
        cout<<ans<<endl;
        
        
    }
        
    
    
    
    
}


Measured memory_bytes: 66720
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
struct node
{
	int s,id;
}a[300010];
bool cmp(node x,node y){return x.s>y.s;}
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int x=read(),y=read(),n=read(),m=read(),k=read(),now=0;
    for(int i=1;i<=n;i++)a[++now].s=read(),a[now].id=1;
    for(int i=1;i<=m;i++)a[++now].s=read(),a[now].id=2;
    for(int i=1;i<=k;i++)a[++now].s=read(),a[now].id=3;
    sort(a+1,a+now+1,cmp);
	int uf=0,tot=x+y;long long ans=0;
    for(int i=1;i<=now;i++)
    {
    	if(uf==tot)break;
    	if(a[i].id==1)
		{
			if(x>0)x--,ans+=a[i].s,uf++;
		}
    	else if(a[i].id==2)
    	{
    		if(y>0)y--,ans+=a[i].s,uf++;
    	}
    	else ans+=a[i].s,uf++;
    }printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;
typedef long long int ll;


int main()
{
    int x,t;

    while(scanf("%d%d",&x,&t) != EOF)
    {
        int temp = x-t;
        if(temp <= 0) printf("0\n");
        else printf("%d\n",temp);
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <string.h>
#include <algorithm>
#include <map>

#pragma warning(disable:4996)

#define N_MAX 100000
#define M_MAX 100000

struct Operation {
	int n;
	int v;
};

int main(void) {
	int n, m;
	scanf("%d %d", &n, &m);
	std::map<int, Operation> OP;
	std::map<int, Operation>::iterator it;
	for (int i = 0; i < n; ++i) {
		int a;
		scanf("%d", &a);
		it = OP.find(a);
		if (it == OP.end()) {
			Operation op;
			op.n = 1;
			op.v = a;
			OP[a] = op;
		}
		else {
			OP[a].n++;
		}
	}
	for (int i = 0; i < m; ++i) {
		int n;
		int v;
		scanf("%d %d", &n, &v);
		it = OP.find(v);
		if (it == OP.end()) {
			Operation op;
			op.n = n;
			op.v = v;
			OP[v] = op;
		}
		else {
			OP[v].n += n;
		}
	}
	it = OP.end();
	--it;
	long long sum = 0;
	int remain = n;
	while(1) {
		long long v = it->second.v;
		long long n = it->second.n;
		if (remain > n) {
			sum += v * n;
			remain -= n;
		}
		else {
			sum += v * remain;
			break;
		}
		if (it == OP.begin()) break;
		--it;
	}
	printf("%lld\n", sum);



	return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < (N); i++)
#define vec vector<int>
using namespace std;
int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int x = max(A, C);
    int y = min(B, D);
    cout << max(0, y - x) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <deque>
#include <bits/stdc++.h>
//#include "D:\C++\test_lib_projects\testlib.h"
using namespace std;
#define ll long long
#define pii pair<int,int>

bool debug=true;
/*
   Write In New Computer
    By XiaoGeNintendo
	     gwq2017
	Type:
*/

int n,m;
int a[100005];
int dsu[100005];
int db[100005];
int in[100005];

int getFa(int a){
	if(dsu[a]==a) return a;
	return dsu[a]=getFa(dsu[a]);
}

void Union(int a,int b){
	int fa=getFa(a);
	int fb=getFa(b);
	if(fa==fb){
		return;
	}
	
	dsu[fb]=fa;
}

int main(int argc,char* argv[]){
	
	for(int i=0;i<1e5+2;i++){
		dsu[i]=i;
	}
	
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		a[i]--;
	}
	for(int i=0;i<m;i++){
		int f,s;
		scanf("%d%d",&f,&s);
		f--;s--;
		Union(f,s);
	}
	
	for(int i=0;i<n;i++){
		db[i]=getFa(i);
		in[i]=getFa(a[i]);
	}
//	
//	for(int i=0;i<n;i++){
//		cout<<db[i]<<" "<<in[i]<<endl;
//	}
	int ans=0;
	for(int i=0;i<n;i++){
		ans+=db[i]==in[i];
	}
	
	cout<<ans;
	return 0;
}


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

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

  for(int i=0;i<str.size()-1;i++){
    if(str[i] == str[i+1]){
      cout << i+1 << " " << i+2 << endl;
      return 0;
    }
  }

  for(int i=0;i<str.size()-2;i++){
    if(str[i] == str[i+2]){
      cout << i+1 << " " << i+3 << endl;
      return 0;
    }
  }

  cout << -1 << " " << -1 << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <math.h>
#define rep(i,n) for (int i=0;i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;

int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a+b==c+d){
        cout << "Balanced" << endl;
    } else if(a+b<c+d){
        cout << "Right" << endl;
    } else {
        cout << "Left" << endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	/**
	 * @param n:要素数
	 * @param x_i:要素xの配列
	 * @param y_i:要素yの配列
	 * @param diff_i:xとyの差分の配列
	 */
	public static Scanner inputData = null;
	public static int n = 0;
	public static int[] x_i = new int[1000];
	public static int[] y_i = new int[1000];
	public static int[] diff_i = new int[1000];
	
	public static void main(String[] args) {
		// TODO データ間の距離を測る
//		入力データを取得する処理
		getData();
//		x,yの差分を出す処理
		getDiff();
//		マンハッタン距離(p=1)を求めて出力する処理
		getDist_p1();
//		ユークリッド距離(p=2)を求めて出力する処理
		getDist_p2();
//		p=3の時の距離を求めて出力する処理
		getDist_p3();
//		チェビシェフ距離(p=∞)を求めて出力する処理
		getDist_pinf();
	}

	private static void getDist_pinf() {
		// TODO 自動生成されたメソッド・スタブ
		double dDist_pinf = 0;
		for( int count=0; count<n; count++) {
			dDist_pinf = Math.max( dDist_pinf, diff_i[count]);
		}
		outputResult( dDist_pinf);
	}

	private static void getDist_p3() {
		// TODO 自動生成されたメソッド・スタブ
		double dDist_p3 = 0;
		for( int count=0; count<n; count++) {
			dDist_p3 += Math.pow(diff_i[count], 3);
		}
		dDist_p3 = Math.pow(dDist_p3, ( double)1/3);
		outputResult( dDist_p3);
	}

	private static void getDist_p2() {
		// TODO 自動生成されたメソッド・スタブ
		double dDist_p2 = 0;
		for( int count=0; count<n; count++) {
			dDist_p2 += Math.pow(diff_i[count], 2);
		}
		dDist_p2 = Math.pow(dDist_p2, ( double)1/2);
		outputResult( dDist_p2);
	}

	private static void getDist_p1() {
		// TODO 自動生成されたメソッド・スタブ
		double dDist_p1 = 0;
		for( int count=0; count<n; count++) {
			dDist_p1 += diff_i[count];
		}
		outputResult( dDist_p1);
	}


	private static void outputResult(double dist) {
		// TODO 自動生成されたメソッド・スタブ
		System.out.println( dist);
	}

	private static void getDiff() {
		// TODO 自動生成されたメソッド・スタブ
		for( int count=0; count<n; count++) {
			diff_i[count] = Math.abs( x_i[count] - y_i[count]);
		}
	}

	private static void getData() {
		// TODO 自動生成されたメソッド・スタブ
//		配列の初期化
		for( int count=0; count<x_i.length; count++) {
			x_i[count] = 0;
			y_i[count] = 0;
		}
		inputData = new Scanner( System.in);
		n = inputData.nextInt();
		for( int count=0; count<n; count++) {
			x_i[count] = inputData.nextInt();
		}
		for( int count=0; count<n; count++) {
			y_i[count] = inputData.nextInt();
		}
	}

}



Measured memory_bytes: 26704
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int a = Integer.parseInt(str[0]);
    int b = Integer.parseInt(str[1]);
    int k = Integer.parseInt(str[2]);
    
    int[] divisor_array = new int[k];
    
    for(int i = Math.min(a,b), j = 0; i>=1; i--) {
      if(a%i==0 && b%i==0){
        divisor_array[j] = i;
        j++;
      }
      if(j == k)
        break;
    }
    System.out.println(divisor_array[k-1]);
  }
}

Measured memory_bytes: 21204
#include <iostream>
#include <iomanip>
#include <math.h>
#include <float.h>
using namespace std;

#ifndef M_PI
#define M_PI (4.0*atan(1.0))
#endif

int main() {
	// your code goes here
	
	double r;
	std::cin>>r;
	
	std::cout<<setprecision(16)<<M_PI*r*r<<" "<<M_PI*2*r<<std::endl;
	
	return 0;
}

Measured memory_bytes: 3264
#include <bits/stdc++.h>
using namespace std;
#define ll long long                  // Short form for long long
#define ld long double                // Short form for long double
typedef pair<ll, ll> pii;              // Pair of long long
typedef vector<ll> vi;                // Vector of long long
typedef vector<vi> vvi;               // Vector of vector of long long
typedef vector<pii> vii;               // Vector of pairs
typedef vector<vii> vvii;             // Vector of vector of pairs
#define pq priority_queue             // Max heap (To convert to min heap, use negative sign before every value)
#define ff first                      // For pairs
#define ss second                     // For pairs
#define pb push_back                  // Pushback to vector
#define mp make_pair                  // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end() // Mainly used by me in sorting

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}

ll mod = 1e9 + 7;
ll t=1;

vvi adj;
ll n,m,x,y,k;
vi dp,vis;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // cin>>t;
    while(t--){
        cin>>n>>k;
        vi a(n);
        dp.resize(k+1);
        ll sum=0;
        for(int i=0;i<n;i++){cin>>a[i];sum+=a[i];}
        for(int i=0;i<=k;i++){
            int j=0;
            vi b;
            for(j=0;j<n;j++){
                if(a[j]<=i){b.pb(dp[i-a[j]]);}
                else {break;}
            }
            if(b.size()==0){dp[i]=2;}
            else{
                sort(all(b));
                if(b[b.size()-1]==2){dp[i]=1;}
                else dp[i]=2;
            }
        }
        // for(auto u:dp)cout<<u<<" ";cout<<"\n";
        // cout<<dp[k];
        if(dp[k]==2)cout<<"Second";
        else cout<<"First";
        

        

    }
    return 0;
}    

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

int main()
{
  int N;
  int ans = 0;
  int l,r;
  cin >> N;
  rep(i, N) {
    cin >> l >> r;
    ans += (r-l+1);
  }
  cout << ans << endl;
}


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

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

	rep(i,H) {
		cin >> C;
		cout << C << endl << C << endl;
	}
}

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

#define ll long long
#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define repr(i,n,m) for(int i=m; i<n; i++)
#define MAX 100
#define MOD 1000000007
#define pb push_back
#define debug(x) cout << x << endl;
#define END cout << endl;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n,k; cin >> n >> k;
  vector<ll> a(n);
  vector<ll> sum(n+1), b(n+1);
  sum[0] = b[0] = 0;
  rep(i,n) {
    cin >> a[i];
    sum[i+1] = a[i] + sum[i];
    b[i+1] = max<ll>(0,a[i]) + b[i];
  }
  ll ans = -10e12;
  for (int i = 0; i <= n - k; ++i) {
    int left = i+1, right = i + k;
    ll mmax, tmp_sum = sum[right] - sum[left-1];
    mmax = (max<ll>(tmp_sum,0) > 0) ? tmp_sum : 0;
    mmax += (b[n] - b[right]) + (b[left-1] - b[0]);
    ans = max(ans, mmax);
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> x(N);
    for (int i = 0; i < N; i++) {
        cin >> x.at(i);
    }
    vector<ll> a;
    vector<ll> b(1);
    for (int i = 0; i < N; i++) {
        if (x[i] < 0) {
            a.push_back(x[i]);
        } else {
            b.push_back(x[i]);
        }
    }
    a.push_back(0);
    reverse(ALL(a));

    ll ans = 1e18;
    for (int i = 0; i <= K; i++) {
        if ((int)a.size() > i && (int)b.size() > (K - i)) {
            //cerr << i << " " << a[i] << " " << b[K - i] << endl;
            chmin(ans, abs(a[i]) * 2 + b[K - i]);
            chmin(ans, abs(a[i]) + b[K - i] * 2);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 2424
#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (ll i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (ll i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    string n; cin >> n;

    auto n_rev = n;
    reverse(ALL(n_rev));

    if (n == n_rev) print("Yes");
    else print("No");
}

Measured memory_bytes: 3552
import java.io.*;
import java.util.Scanner;

class Main
{
	public static void main (String[] args) throws IOException
	{
		String A,B,C;
		int a,b,c;
		
		Scanner in = new Scanner(System.in);
		
		A = in.next();
		B = in.next();
		C = in.next();
		
		a = Integer.parseInt(A);
		b = Integer.parseInt(B);
		c = Integer.parseInt(C);
		
		if(a < b && b < c){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 17312
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
using namespace std;

int INF = 1<<29;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする

long long int i,j;

int main(){
	int n,a;
	cin>>n>>a;
	if(n%500 <= a){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
		return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(1, m+1):
    tl = []
    for j in range(len(l)):
        tl.append(i in l[j][1:len(l[j])])
    if False not in tl:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <map>
using namespace std;
map<char,int> cher;
int main(){
	int n;
	cin>>n;
	int ans=0;
	char str[15];
	for(int i=1;i<=n;i++){
		scanf("%s",str);
		if(cher[str[0]] == 0){
			ans ++;
			cher[str[0]] = 1;
		}
	}
	switch(ans){
		case 1:puts("One");break;
		case 2:puts("Two");break;
		case 3:puts("Three");break;
		case 4:puts("Four");break;
		
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int64_t n, m, x, s;
int main() {
    cin >> n >> m;
    for (int i = 1; i <= m; ++i) {
        cin >> x;
        s += x;
    }
    if (n >= s)
        cout << n - s;
    else cout << -1;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define forn(x, n)              for (int x = 0; x < n; x++)
#define forr(x, n)              for (int x = n; x >= 0; x--)
#define fore(x, a, b, c)        for (int x = a; x <= b; x += c)
#define forre(x, a, b, c)       for (int x = a; x >= b; x -= c)
#define clr                     cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define all(container)          (container).begin(), (container).end()
#define rall(container)         (container).rbegin(), (container).rend()
#define devugv(v)               for (auto& x: v) cerr << x << " "; cerr << '\n';
#define debugvp(v)              for (auto& x: v) cerr << x.fi << " - " << x.se << '\n';
#define FILL(x, val)            memset(x, val, sizeof(x))
#define pb                      push_back
#define eb                      emplace_back
#define fi                      first
#define se                      second
#define mod                     (int)1000000007
#define INF                     (int)0x3f3f3f3f

using namespace std;

#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }  

typedef long long i64; 
typedef vector< int > vi;
typedef vector< i64 > vi64;
typedef pair< int, int > pi;
typedef vector< pair< int, int > > vpi;
typedef vector< vector < int > > vvi;

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("in.txt", "r", stdin);
#endif

    string s; cin >> s;
    for (int i = 0; i < (int) s.size(); i++) cout << "x";
  
#ifdef LOCAL_DEFINE
    cout << "time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
#endif
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] w = new int[n];
		for (int i = 0; i < n; i++) {
			w[i] = sc.nextInt();
		}
		int ans = Integer.MAX_VALUE;
		int sum1=0,sum2=0;
		for (int i = 0; i < n; i++) {
			sum1=0;
			sum2=0;
			for(int j=0;j<i;j++) {
				sum1 += w[j];
			}
			for (int j = i; j < n; j++) {
				sum2 += w[j];
			}
			ans = Math.min(Math.abs(sum1-sum2), ans);
		}
		System.out.println(ans);
		
	}

}


Measured memory_bytes: 22996
/*Code by Codercjh*/
#include<bits/stdc++.h>
#define fr(i,a,b) for(int i=(a);i<=(b);++i)
#define rf(i,a,b) for(int i=(a);i>=(b);--i)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
using namespace std;
typedef long long ll;
template<typename T>
inline void read(T &x){
	char c=getchar();T fh=0;bool f=false;
	while(!isdigit(c))f|=(c=='-'),c=getchar();
	while(isdigit(c))fh=(fh<<1)+(fh<<3)+(c^48),c=getchar();
	x=f?-fh:fh;
	return;
}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll ans;
int k;
int main(){
    read(k);
	fr(i,1,k)
	 fr(j,1,k)
	  fr(l,1,k)
	   ans+=gcd(gcd(i,j),l); 
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3676
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    n = INT()
    s = input()
    
    ans = 1

    for i in range(n-1):
        if s[i] != s[i+1]:
            ans += 1

    print(ans)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 5972