akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import java.io.*;
 
class Main {
    public static void main(String[] args)throws IOException{ 
        InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader read = new BufferedReader(in);
 
       String number = read.readLine();
       String[] spli1 = number.split(" ");
       int [] dICE = new int [8];
       int dcount,num,count;
       for(dcount = 0; dcount < 8; dcount++){ 
    	   dICE[dcount] = 0;
       }
       for(num = 0; num < 6; num++){
    	   dICE[num] = Integer.parseInt(spli1[num]); 
       }


       String com = read.readLine();
       char [] command = com.toCharArray();
       
       

       for(count = 0; count < command.length; count++){

                if(command[count] =='N'){
                	dICE[6] = dICE[0];
                	dICE[7] = dICE[4];
                	dICE[0] = dICE[1];
                	dICE[1] = dICE[5];
                	dICE[2] = dICE[2];
                	dICE[3] = dICE[3];
                	dICE[4] = dICE[6];
                	dICE[5] = dICE[7];                         
                }
                else if(command[count] == 'E'){
                	dICE[6] = dICE[0];
                	dICE[7] = dICE[2];
                	dICE[0] = dICE[3];
                	dICE[1] = dICE[1];
                	dICE[2] = dICE[6];
                	dICE[3] = dICE[5];
                	dICE[4] = dICE[4];
                	dICE[5] = dICE[7];       
                }
                else if(command[count] == 'S'){
                	dICE[6] = dICE[0];
                	dICE[7] = dICE[1];
                	dICE[0] = dICE[4];
                	dICE[1] = dICE[6];
                	dICE[2] = dICE[2];
                	dICE[3] = dICE[3];
                	dICE[4] = dICE[5];
                	dICE[5] = dICE[7];     
                }
                else if(command[count] == 'W'){
                	dICE[6] = dICE[0];
                	dICE[7] = dICE[3];
                	dICE[0] = dICE[2];
                	dICE[1] = dICE[1];
                	dICE[2] = dICE[5];
                	dICE[3] = dICE[6];
                	dICE[4] = dICE[4];
                	dICE[5] = dICE[7];     
                
            }
       }
       System.out.println(dICE[0]);
    }
}

Measured memory_bytes: 24192
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int N, M;
    cin >> N >> M;
    int ans[N+3];
    for(int i = 0; i < N+3; i++) ans[i] = 0;
    for(int i = 0; i < M; i++){
        int a;
        cin >> a;
        ans[a] = -1;
    }
    ans[0] = 1;
    
    for(int i = 0; i <= N; i++){
        if(ans[i] == -1) continue;
        if(ans[i+1] != -1) ans[i+1] += ans[i]%mod;
        if(ans[i+2] != -1) ans[i+2] += ans[i]%mod;
    }
    
    cout << ans[N]%mod << "\n";
    return 0;
}

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

using namespace std;

#define int long long

signed main()
{
  int x, y;
  cin >> x >> y;
  if (((y - 2 * x) % 2 == 0) && ((y - 2 * x) <= 2 * x) && ((y - 2 * x) >= 0))
    printf("Yes\n");
  else 
    printf("No\n");
  return 0;
}


Measured memory_bytes: 3636
import java.io.*;
class Main {
    public static void main(String[] args) {
        try {
                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String str = br.readLine();
            int n = Integer.parseInt(str.split(" ")[0]);
            int k = Integer.parseInt(str.split(" ")[1]);
            int[] nimotu = new int[n];
            int totalWeight = 0;
            for (int i = 0; i < n; i++) {
                nimotu[i] = Integer.parseInt(br.readLine());
                totalWeight += nimotu[i];
            }
            int aver = totalWeight / k;
            int maxweight = aver;
            int tracknum;
            while(maxweight <= totalWeight){
                int weight = 0;
                tracknum = 1;
                boolean flg = true;
                for(int i = 0;i < n && tracknum <= k;) {
                    if(weight + nimotu[i] <= maxweight){
                        weight += nimotu[i];
                        i++;
                    } else if(weight > 0){
                        if(maxweight < weight){
                            maxweight = weight;
                        }
                        weight = 0;
                        tracknum++;
                    } else {
                        flg = false;
                        break;
                    }
                }
                if(tracknum <= k && flg){
                    System.out.println(maxweight);
                    break;
                }
                maxweight++;
            }
        } catch (IOException e) {
            System.out.println("error");
        }
    }
}

Measured memory_bytes: 29372
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define int long long
#define V vector
#define vel V<int>
#define rep(i,n) for(int i=0;i<n;i++)
vel solve(V<vel>& ab, int ex) {
	if (ex == 0) { return { 1, 0 }; }
	V<vel> ab0, ab1;
	for (auto x : ab) {
		int a1 = x[0];
		int b1 = x[1];
		if (b1 % 2 == 0) {
			ab0.push_back({ a1 / 2, b1 / 2 });
			if (a1 % 2 == 1) { ab1.push_back({ a1 / 2, b1 / 2 }); }
		}
		else {
			ab1.push_back({ a1 / 2, b1 / 2 });
			if (a1 % 2 == 1) { ab0.push_back({ a1 / 2, (b1 + 1) / 2 }); }
		}
	}
	vel c0(2), c1(2);
	for (auto x : ab0) {
		int qc = (3 - x[0] + x[1]) % 3; qc = (qc + 3) % 3;
		if (qc == 0) { c0[0] ^= 1; }
		if (qc == 1) { c0[1] ^= 1; }
		if (qc == 2) { c0[0] ^= 1; c0[1] ^= 1; }
	}
	for (auto x : ab1) {
		int qc = (3 - x[0] + x[1]) % 3; qc = (qc + 3) % 3;
		if (qc == 0) { c1[0] ^= 1; }
		if (qc == 1) { c1[1] ^= 1; }
		if (qc == 2) { c1[0] ^= 1; c1[1] ^= 1; }
	}
	vel ze(2, 0);
	if (c0 == ze) {
		vel ans = solve(ab1, ex - 1);
		ans[0] *= 2; ans[1] *= 2;ans[1]++;
		return ans;
	}
	if (c1 == ze) {
		vel ans = solve(ab0, ex - 1);
		ans[0] *= 2; ans[1] *= 2;
		return ans;
	}
	rep(i, ab.size()) { ab[i][0]++; }
	vel ans = solve(ab, ex); ans[0]--;
	return ans;
}
signed main() {
	int inf = 1;
	rep(i, 57) { inf *= 2; }
	int n; cin >> n;
	V<vel> ab(n);
	rep(i, n) {
		int a, b; cin >> a >> b;
		ab[i] = { a + inf,b + inf };
	}
	vel ret = solve(ab, 70);
	cout << ret[0] - inf << " " << ret[1] - inf << "\n";
}

Measured memory_bytes: 37564
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();

        if (A >= 13) {
            System.out.println(B);
        }
        else if (A >= 6 && A <= 12) {
            System.out.println(B/2);
        }
        else {
            System.out.println(0);
        }

    }
}


Measured memory_bytes: 23124
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

    vector<string> title(n);
    vector<int> t(n);

    rep(i, n)
    {
        cin >> title[i] >> t[i];
    }

    string x;
    cin >> x;

    int result = 0;
    bool c = false;
    rep(i, n)
    {
        if (c) {
            result += t[i];
        }
        c = c || (x == title[i]);
    }
    cout << result << endl;
    return 0;
}

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

int main(){
    // 変数を準備
    int N;
    cin >> N;     
    int A[N];
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    
    for(int i = 0; i < N; i++){
        if(i != N - 1){
            cout << A[i] << " ";
        }else{
            cout << A[i] << endl;
        }    
    }
    
    for(int i = 1; i < N; i++){
        int v = A[i];
        int j = i - 1;
        while(j >= 0 && A[j] > v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        for(int k = 0; k < N; k++){
            if(k != N - 1){
                cout << A[k] << " ";
            }else{
                cout << A[k] << endl;
            }  
        }
    }
    return 0;
}


Measured memory_bytes: 3088
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;

namespace AtCoder
{
	public class Program
	{
		static void Main()
		{
			var tx = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

			int t = tx[0];
			int x = tx[1];

			double ans = (double)t / x;
			Console.WriteLine(ans);
		}
	}
}

Measured memory_bytes: 13396
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        List<Integer> list = check(100003);
        int ans = 0;
        for(int i=0;i<list.size();i++){
            if(list.get(i) >= X) {
                System.out.println(list.get(i));
                return;
            }
        }
    }

    public static List<Integer> check(int n) {
        // 探索リスト生成
        boolean[] search = new boolean[n+1];
        Arrays.fill(search, true);

        // 素数でないものはfalseにする
        for(int i=2; i<Math.sqrt(n); i++){
            // 素数の倍数なら何もしない
            if(!search[i]){
                continue;
            }

            // 素数の倍数をふるい落とし
            for(int j=2; i*j <= n; j++){
                search[i*j] = false;
            }
        }

        List<Integer> primeList = new ArrayList<>();
        for(int i=2; i<search.length; i++) {
            if (search[i]) {
//                System.out.println(i);
                primeList.add(i);
            }
        }
        return primeList;
    }
}

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

int n,a,b;

signed main(){
    cin >> n >> a >> b;
    int ans = 0;
    for(int i=1 ; i<=n ; i++){
        int temp = i;
        int sum = 0;
        while(temp){
            sum += temp%10;
            temp /= 10;
        }
        if(a <= sum && sum <= b)
            ans += i;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
	Q[tail] = x;
	tail = (tail + 1) % (LEN + 1);
}

P dequeue(){
  int i = head;
  head = (head + 1) % (LEN + 1);
  return Q[i];
}


int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  
  head = 1;
  tail = n + 1;

  c = 0;
  while (head != tail) {
  	u = dequeue();
  	if (u.t > q) {
  	  c += q;
  	  u.t -= q;
  	  enqueue(u);
  	} else {
  	  c += u.t;
  	  printf("%s %d\n", u.name, c);
  	}
  }
  
  return 0;
}

Measured memory_bytes: 10756
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner kbd = new Scanner(System.in);
        int n = kbd.nextInt();
        int m = kbd.nextInt();
        int maxL = 0;
        int minR = n + 1;

        for (int i = 0; i < m; i++) {
            // L
            int tempL = kbd.nextInt();
            // R
            int tempR = kbd.nextInt();

            if (tempL > maxL) {
                maxL = tempL;
            }
            if (minR > tempR) {
                minR = tempR;
            }
        }
        if(minR-maxL<0){
            System.out.println(0);
        }else{
            System.out.println((minR - maxL)+1);
        }
    }
}

Measured memory_bytes: 63792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String A = sc.next();
		String B = sc.next();
		String C = sc.next();

		System.out.println("A" + B.substring(0, 1) + "C");
	}
}

Measured memory_bytes: 10192
#include <iostream>

using namespace std;

int main() {
	unsigned long long k, a, b;
	cin >> k >> a >> b;
	
	unsigned long long result = 0;
	
	if (a > b || b - a < 2 || a > k || k - a < 1) {
		result = 1 + k;
	} else {
		k -= a - 1;
		result = a;
		result += (k / 2) * (b - a) + (k % 2);
	}
	
	cout << result << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;
import java.util.ArrayList;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String input = "";
		
		while((input = br.readLine()) != null){
			String[] arr = input.split(" ");
			
			long a = Integer.parseInt(arr[0]);
			long b = Integer.parseInt(arr[1]);
			
			long x = gcd(a, b);
			
			System.out.print(x + " ");
			System.out.println((a * b) / x);
		}
	}
	
	static long gcd(long a, long b){
		long k = a;
		long m = b;
		
		while(k != m){
			if(k > m){
				k = k - m;
			}
			else{
				m = m - k;
			}
		}
		return k;
	}

}

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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int count1 = 0;
  int count2 = 0;
  int count3 = 0;
  int temp = 0;
  for (int i = 0; i < N; i++) {
    cin >> temp;
    if (temp <= A) {
      count1++;
    }
    if (temp > A && temp <= B) {
      count2++;
    }
    if (temp > B) {
      count3++;
    }
  }

  int result = count1;
  if (result > count2) {
    result = count2;
  }
  if (result > count3) {
    result = count3;
  }
  cout << result << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

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

    public int nextInt() {
      return Integer.parseInt(next());
    }

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

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    String s = sc.next();
    String t = sc.next();
    int a = sc.nextInt();
    int b = sc.nextInt();
    String u = sc.next();
    if (u.equals(s)) {
      System.out.println((a - 1) + " " + b);
    } else {
      System.out.println(a + " " + (b - 1));
    }
  }
}

Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 2000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define dum(x) cout<<#x<<'='<<x<<endl
#define dum2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl

//ifstream in("Text.txt");cin.rdbuf(in.rdbuf());

int D[10];

int main() {
    int N, K;
    cin >> N >> K;
    rep(i, K)cin >> D[i];

    for (int i = N; i < 100000; i++) {
        int dimi = i;
        int flag = true;
        while (dimi != 0) {
            rep(j, K) {
                int remi = dimi % 10;
                if (remi == D[j]) {
                    flag = false;
                    break;
                }
            }
            if (!flag)break;
            dimi /= 10;
        }
        if (flag) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n+1],b[n+1],c[n];
  for(int i=1;i<=n;i++)
    cin>>a[i];
  
  for(int i=1;i<=n;i++)
    cin>>b[i];
  
  for(int i=1;i<=n-1;i++)
    cin>>c[i];
 int sum=b[a[1]];
  for(int i=2;i<=n;i++)
           {
            sum+=b[a[i]];
             if(a[i]-1==a[i-1])
               sum+=c[a[i]-1];
             
           }
           cout<<sum;
             
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ld long double
#define mx 200005
#define fr first
#define se second
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
ll dp[100005],coin[100005];
ll n,k;
ll func(ll i)
{
    if(i>=n) return 0;
    if(dp[i]!=-1) return dp[i];
    ll ans1=INT_MAX;
        for(int j=1; j<=k; j++){
            if(i+j<=n) ans1 = min(ans1,abs(coin[i]-coin[i+j])+func(i+j));
        }
    return dp[i] = ans1;
}

int main()
{
   fast;
   cin >> n >> k;
   memset(dp,-1,sizeof dp);
   for(ll i=1; i<=n; i++) cin >> coin[i];
   cout << func(1) << "\n";
   return 0;
}


Measured memory_bytes: 6528
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdbool.h>


int main() {
	int x[12],d,r;
	scanf("%d%d%d",&r,&d, &x[0]);
	for (int i = 1; i <= 10; i++) {
		x[i] = r * x[i - 1] - d;
		printf("%d\n", x[i]);
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <array>
#include <map>
#include <set>

using namespace std;

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <tuple>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#define int long long
#define all(v) v.begin(),v.end()
using namespace std;

signed main(){
	int n,a,b;
	cin>>n>>a>>b;
	if((b-a)%2==0){
		cout<<(b-a)/2<<endl;
	}
	else if(a-1>=n-b){
		cout<<(n-a+n-b+1)/2<<endl;
	}
	else{
		cout<<(a+b-1)/2<<endl;
	}
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#include <iostream>

using namespace std;

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch) {
    if(ch == 'A') return 1;
    if(ch == 'C') return 2;
    if(ch == 'G') return 3;
    if(ch == 'T') return 4;
    return 0;
}

long long getKey(char str[]) {
    long long sum = 0, p = 1;
    for(int i = 0; i < strlen(str); i++) {
        sum += p*(getChar(str[i]));
        // cout << "getKey: " << p << " : " << sum << endl;
        p *= 5;
    }
    return sum;
}

int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }

int find(char str[]) {
    long long key = getKey(str);
    for(int i = 0; ; i++) {
        // 計算結果は i に依存する h2 ずつずれていく
        long long h = (h1(key) + i*h2(key)) % M;
        if(strcmp(H[h], str) == 0) return 1;
        else if(strlen(H[h]) == 0) return 0;
    }
}

int insert(char str[]) {
    long long key = getKey(str);
    for(int i = 0; ; i++) {
        long long h = (h1(key) + i*h2(key)) % M;
        // 同じ値が存在すれば終わり
        if(strcmp(H[h], str) == 0) return 0;
        // 中身が空であれば挿入
        else if(strlen(H[h]) == 0) {
            strcpy(H[h], str);
            return 0;
        }
    }
    return 0;
}

int main() {
    for(int i = 0; i < M; i++) H[i][0] = '\0';
    int n;
    scanf("%d", &n);
    // 処理
    for(int i = 0; i < n; i++) {
        char str[L], com[9];
        scanf("%s %s", com, str);
        if(com[0] == 'i') {
            insert(str);
        } else {
            if(find(str)) {
                printf("yes\n");
            }else {
                printf("no\n");
            }
        }
    }

    return 0;
}


Measured memory_bytes: 17460
#include<bits/stdc++.h>
using namespace std;
int MaxKouyaku(int divider,int divided){
    int amari;
    int MaxKouyaku=1;
    if(divider>divided) swap(divider,divided);
    while(1){
        amari = divided%divider;
        if(amari==0){
            MaxKouyaku = divider;
            break;
        }else{
            divided=divider;
            divider=amari;
        }
    }
    return MaxKouyaku;
}
int main(){
    int n;
    int A,B;
    int i;
    scanf("%d", &n);
    scanf("%d", &A);
    for(i=1; i<n; i++){
        scanf("%d", &B);
        A=MaxKouyaku(A,B);
    }
    printf("%d",A);
    return 0;
}

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

int main() {
	int N;
	double M, sum=0;
	cin >> N >> M;

	vector<double> A(N);
	for(int i=0;i<N;i++){
		cin >> A.at(i);
		sum += A.at(i);
	}
	sort(A.begin(), A.end(), greater<int>());
	bool flg=true;

	for(int i=0;i<M;i++){
		if(A.at(i) < sum / (4 * M)){
			flg = false;
			break;
		}
	}

	if(flg){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <cstdio>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int N = 400000;
bool arr[400000];
vector<int> pr;
void Eratosthenes(){
	for(int i = 0; i < N; i++){
		arr[i] = 1;
	}
	for(int i = 2; i < sqrt(N); i++){
		if(arr[i]){
			for(int j = 0; i * (j + 2) < N; j++){
				arr[i *(j + 2)] = 0;
			}
		}
	}

	for(int i = 2; i < N; i++){
		if(arr[i]){
			pr.push_back(i);
		}
	}
}


int main(){
    int n;
    cin >> n;
    Eratosthenes();
    int cnt = 0;
    int x = 0;
    vector<int>ans;
    while(cnt!=n){
        if(pr[x]%10==3){
            ans.PB(pr[x]);
            cnt++;
        }
        x++;
    }
    rep(i,n){
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MOD 1000000007

using namespace std;

int l[305][305],num[305][305],cnt[305];

int f[2][305][305];

inline bool check(int x,int y,int z,int k) {
  for(int i=1;i<=cnt[k];i++)
    if ((x>=l[k][i])+(y>=l[k][i])+(z>=l[k][i])!=num[k][i]) return false;
  return true;
}

int dp(int n) {
  int cur=0;
  f[0][0][0]=1;
  for(int i=0;i<n;i++) {
  	cur^=1;
  	memset(f[cur],0,sizeof(f[cur]));
  	for(int j=0;j<=i;j++)
  	for(int k=0;k<=j;k++)
  	if (f[cur^1][j][k]) {
  		if (check(i+1,j,k,i+1)) f[cur][j][k]=(f[cur][j][k]+f[cur^1][j][k])%MOD;
  		if (check(i+1,i,k,i+1)) f[cur][i][k]=(f[cur][i][k]+f[cur^1][j][k])%MOD;
  		if (check(i+1,i,j,i+1)) f[cur][i][j]=(f[cur][i][j]+f[cur^1][j][k])%MOD;
	  }
  }
  int ans=0;
  for(int i=0;i<=n;i++)
    for(int j=0;j<=i;j++) ans=(ans+f[cur][i][j])%MOD;
  return ans;
}

int main() {
  int n,m;
  scanf("%d%d",&n,&m);
  for(int i=1;i<=m;i++) {
  	int x,y,z;
  	scanf("%d%d%d",&x,&y,&z);
  	cnt[y]++;
  	l[y][cnt[y]]=x;num[y][cnt[y]]=z;
  }
  printf("%d\n",dp(n));
  return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vii;
typedef vector<pair<int,int>> vip;

#define ZOOM ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define ff it->first
#define ss it->second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(auto i=0;i<n;++i)
#define LOOP_IT(it,s) for(auto it=(s).begin();it!=(s).end();++it)






void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif




int main(int argc,char* argv[])
{
    ZOOM

    ll k,n;
    cin>>k>>n;
    vector<ll> v(n);
    rep(i,n)
    cin>>v[i];
    ll d = -1,x,i1,i2,s,ans=0;

    for(ll i=0;i<n-1;++i)
    {
        x = v[i+1]-v[i];
        if(d<x)
        {
            s = i+1;
            d=x;
        }
    }
    x = (k-v[n-1])+v[0];
    if(d<x)
        s = 0;
    for(ll j=s;j<n+s-1;++j)
    {
        i1 = (j%n),i2=(j+1)%n;
        if(j==n-1)
            ans+=(k-v[j])+v[0];
        else
            ans+=(v[i2]-v[i1]);
    }
    cout<<ans;

    return 0;
}



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

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		static int num[40];
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (*num = 0; x; x /= 10) {
			num[++*num] = x % 10;
		}
		while (*num){
			putchar(num[*num] ^ '0');
			--*num;
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

const int N = 200005, P = 1000000007;

int n, a, b, c;

int qpow(int a, int b) {
	int s = 1;
	for (; b; b >>= 1) {
		if (b & 1) {
			s = 1ll * s * a % P;
		}
		a = 1ll * a * a % P;
	}
	return s;
}

int fac[N], inv[N];

void init(int n) {
	fac[0] = 1;
	for (int i = 1; i <= n; ++i) {
		fac[i] = 1ll * fac[i - 1] * i % P;
	}
	inv[n] = qpow(fac[n], P - 2);
	for (int i = n; i; --i) {
		inv[i - 1] = 1ll * inv[i] * i % P;
	}
}

int C(int n, int m) {
	if (m < 0 || m > n) {
		return 0;
	}
	return 1ll * fac[n] * inv[m] % P * inv[n - m] % P;
}

int solve(int a, int b) {
	int t = qpow((a + b) % P, P - 2);
	a = 1ll * a * t % P, b = 1ll * b * t % P;
	int s = 1, ans = 0;
	for (int i = 0; i < n; ++i) {
		ans = (ans + 1ll * C(n - 1 + i, i) * s % P * (i + n) % P * t) % P;
		s = 1ll * s * b % P;
	}
	return 1ll * ans * qpow(a, n) % P;
}

int main() {
	read(n), read(a), read(b), read(c);
	a = 1ll * a * qpow(100, P - 2) % P;
	b = 1ll * b * qpow(100, P - 2) % P;
	init(n << 1);
	print((solve(a, b) + solve(b, a)) % P);
}


Measured memory_bytes: 5160
n,m = gets.split.map &:to_i
$node = Array.new(n){ [] }
m.times do
  a,b = gets.split.map(&:to_i).sort
  $node[a-1] << b
  $node[b-1] << a
end

link = Array.new(n){ nil }

def bfs(link)
  q = [0]
  while !q.empty?
    visit = q.shift
    $node[visit].each do |i|
      next_node = i - 1 
      next unless link[next_node].nil?
      link[next_node] = visit
      q.push next_node 
    end
  end
end

bfs(link)
link.shift

if link.any?{|v| v.nil?}
  puts 'No'
else
  puts 'Yes'
  link.each do |v|
    puts v + 1
  end
end




Measured memory_bytes: 32812
#include <iostream>
using namespace std;
int main()
{
	int x, y;
	char op;
	cin >> x >> op >> y;
	switch (op)
	{
	case '+':
		cout << x + y << endl;
		break;
	case'-':
		cout << x - y << endl;
	default:
		break;
	}
	return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    int n; scanf("%d", &n);
    vector<int> a(n);
    for(int i = 0; i < n; i++) scanf("%d", &a[i]);

    vector<int> L(n, a[0]), R(n, a[n - 1]);

    for(int i = 1; i < n; i++) L[i] = __gcd(L[i - 1], a[i]);
    for(int i = n - 2; i >= 0; i--) R[i] = __gcd(R[i + 1], a[i]);

    int ans = 0;
    for(int i = 0; i < n; i++){
        if(i == 0) ans = max(ans, R[1]);
        else if(i == n - 1) ans = max(ans, L[n - 2]);
        else ans = max(ans, __gcd(L[i - 1], R[i + 1]));
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 4596
s=input()
cnt=0
cntlen=[]
for i in range(len(s)):
    if s[i]=='A' or s[i]=='C' or s[i]=='G' or s[i]=='T':
        cnt+=1
    else:
        cntlen.append(cnt)
        cnt=0
cntlen.append(cnt)
print(max(cntlen))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
template<typename T1, typename T2> istream& operator>>(istream& is, pair<T1, T2>& a){ return is >> a.first >> a.second; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1, T2>& a){ return os << a.first << " "<<a.second; }
template<typename T> istream& operator>>(istream& is, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) is >> vc[i]; return is; }
template<typename T> ostream& operator<<(ostream& os, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) os << vc[i] << endl; return os; }

main()
{
  vector< int > b(3);
  cin >> b;
  if(b[0] & b[1] || b[2]) {
    cout << "Open" << endl;
  } else {
    cout << "Close" << endl;
  }
}

Measured memory_bytes: 1188
package main

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

var (
	scanner = bufio.NewScanner(os.Stdin)
	w       = bufio.NewWriter(os.Stdout)
)

func readInt() (read int) {
	scanner.Scan()
	read, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return
}

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func main() {
	const maxCapacity = 2*1e5 + 10
	buf := make([]byte, maxCapacity)
	scanner.Buffer(buf, maxCapacity)
	scanner.Split(bufio.ScanWords)
	defer w.Flush()
	s := readString()
	t := readString()

	cnt := 0
	fmt.Scan(&s, &t)
	for i := 0; i < len(s); i++ {
		if s[i] != t[i] {
			cnt++
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 2476
from bisect import bisect_left

n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        k = l[i] + l[j]
        pos = bisect_left(l, k)
        ans += max(0, pos - j - 1)
print(ans)

Measured memory_bytes: 9304
#include <bits/stdc++.h>
 
using namespace std;
 
int mod=1e9+7;  ///A simpler way to write 1,000,000,007
 
int main()
{
    int n,k;
    cin >> n >> k;
    int a[n+1];
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    int dp[n+1][k+1];
    dp[0][0]=1;
    for(int i=1;i<=k;i++)  /// Set the initial values
    {
        dp[0][i]=0;
    }
    for(int i=1;i<=n;i++)
    {
        int sums[k+1];
        sums[0]=dp[i-1][0];
        for(int j=1;j<=k;j++)
        {
            sums[j]=(sums[j-1]+dp[i-1][j])%mod;  ///Calculate the prefix sums for i-1
        }
        for(int j=0;j<=k;j++)
        {
            int tr=sums[j];  ///Sum of dp[i-1][0...j]
            int unreachable=j-a[i]-1;  ///We need to subtract the sum of the first "unreachable" elements (dp[i-1][0...unreachable])
            if(unreachable>=0)
            {
                tr=(tr-sums[unreachable]+mod)%mod;  ///Add mod to make sure that "tr-sums[unreachable]" is not negative.
            }
            dp[i][j]=tr;
        }
    }
  	cout << dp[n][k];
    return 0;
}


Measured memory_bytes: 40064
from functools import reduce
MOD = 10**9 + 7
n, a, b = map(int, input().split())

def comb(n, k):
    def mul(a, b):
        return a*b%MOD
    x = reduce(mul, range(n, n-k, -1))
    y = reduce(mul, range(1, k+1))
    return x*pow(y, MOD-2, MOD) % MOD

ans = (pow(2, n, MOD)-1-comb(n,a)-comb(n,b)) % MOD

print(ans)

Measured memory_bytes: 73764
def main():
    s = input().split(' ')
    x = int(s[0])
    k = int(s[1])
    d = int(s[2])

    if x == 0:
        if k % 2:
            print(d)
        else:
            print(0)
    else:
        x = abs(x)
        if x <= d:
            if k % 2:
                print(d - x)
            else:
                print(x)
        else:
            n = x // d
            if n >= k:
                print(x - k * d)
            else:
                newK = k - n
                x = x - n * d
                if newK % 2:
                    print(d - x)
                else:
                    print(x)

if __name__ == '__main__':
    main()


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

int main()
{
	vector<int> as(4), bs({1, 4, 7, 9});
	for (auto &a : as)
	{
		cin >> a;
	}
	sort(as.begin(), as.end());
	cout << ((as == bs) ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <iomanip>
#include <sstream>
using namespace std;

#define MAX 100

int main()
{
    int M, D, sqrtm, d_1, d_10;
    long long int count;
    cin >> M >> D;
    count =0;
    if(M <= 3){
        cout << 0 << endl;
    }else{
        for(int m=4; m<=M; m++){
            sqrtm = sqrt(m);
            if(m==100){
                sqrtm = 9;
            }
            for(int i=2; i<=sqrtm; i++){
                //cout << i << ":" ;
                d_10=m/i;
                if(m%i==0 && d_10<10){
                    if(10*(d_10)+i<=D){
                        //cout<< "pattern1 " << 10*(m/i)+i << " ";
                        count++;
                    }if((i!=(d_10))&&(10*i+(d_10)<=D)){
                        //cout <<"pattern2 " << 10*i + (m/i) << " ";
                        count++;
                    }
                }
            }
        }
        cout <<count<< endl;
    }
    return 0;
}

Measured memory_bytes: 256
S=input()
N=len(S)
ans=0
T=""
U=""
if N%2==0:
  T=S[:N//2]
  U=S[N//2:][::-1]
else:
  T=S[:N//2]
  U=S[N//2+1:][::-1]
for i in range(N//2):
  if T[i]!=U[i]:
    ans+=1
print(ans)

Measured memory_bytes: 9012
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#include <cmath>
#include <string>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
typedef long long ll;
using namespace std;
//================================================

int a = 0, b = 0, c, d, n, k = 0;
string s, t;



int main()
{
	double a, b;
	cin >> a >> b;
	double mi = a / 0.08;
	double ma = b / 0.1;
	rep(i,1001)
	{if(i*0.08>=a&& i * 0.08 < a+1 &&i*0.1>=b&&i*0.1<b+1)
		{
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e9
#define INFLL 1ull<<60u
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;

const int mod = 1e9+7;

template< int mod >
struct ModInt {
    int x;

    ModInt() : x(0) {}

    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt &operator+=(const ModInt &p) {
        if((x += p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator-=(const ModInt &p) {
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &p) {
        x = (int) (1LL * x * p.x % mod);
        return *this;
    }

    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }

    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

    bool operator==(const ModInt &p) const { return x == p.x; }

    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const {
        ModInt ret(1), mul(x);
        while(n > 0) {
            if(n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t;
        is >> t;
        a = ModInt< mod >(t);
        return (is);
    }

    static int get_mod() { return mod; }
};
// 階乗を求める
ModInt<mod> facctorialMethod(ModInt<mod> k){
    ModInt<mod> sum(1);
    for (ll i = 1; i <= k.x; ++i)
    {
        sum *= i;
    }
    return sum;
}

void solve() {
    int S; cin >> S;
    if (S <= 2) {
        cout << 0 << endl;
        return;
    }
    ModInt<mod> ans(0);
    FOR(kou,1,(S/3)+1) {
        auto buf = S - (kou * 3);
        if(buf == 0) ans += ModInt<mod>(1);
        else {
            ModInt<mod> mb(buf),ko(kou);
            auto a = facctorialMethod(mb+kou-1);
            auto b = facctorialMethod(kou-1);
            auto c = facctorialMethod(mb);
            ans += ModInt<mod>((a/(b*c)));
        }
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 3604
#include <stdio.h>
#include <string.h>


int val[10];
int s;

int getWay(int x, int n, int sum)
{
	int ret = 0;
	int i;
	
	if (n == 0){
		if (sum == s){
			return (1);
		}
		return (0);
	}
	
	for (i = x; i < 10; i++){
		if (val[i] == 0 && sum + i <= s){
			val[i] = 1;
			ret += getWay(i, n - 1, i + sum);
			val[i] = 0;
		}
	}
	
	return (ret);
}

int main(void)
{
	while (1){
		int n;
		
		scanf("%d%d", &n, &s);
		memset(val, 0, sizeof(val));
		
		if (n == 0 && s == 0){
			break;
		}
		
		printf("%d\n", getWay(0, n, 0));
	}
	
	return (0);
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    vector<vector<int>>c(3,vector<int>(3));
    rep(i,3){rep(j,3)cin >> c[i][j];}
    bool ok = true;
    rep(i,2){
        int s0 = c[i+1][0]-c[i][0];
        int s1 = c[i+1][1]-c[i][1];
        int s2 = c[i+1][2]-c[i][2];
        if(s0!=s1)ok = false;
        if(s1!=s2)ok = false;
        if(s0!=s2)ok = false;
    }
    rep(i,2){
        int s0 = c[0][i+1]-c[0][i];
        int s1 = c[1][i+1]-c[1][i];
        int s2 = c[2][i+1]-c[2][i];
        if(s0!=s1)ok = false;
        if(s1!=s2)ok = false;
        if(s0!=s2)ok = false;
    }
    if(ok)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
h, w = gets.split.map(&:to_i)
s = Array.new(h + 1).map{Array.new(w + 1, 0)}
1.upto(h) do |i|
  c = 0
  l = 1
  b = gets
  1.upto(w) do |j|
    if b[j - 1] == '.'
      l = j if c == 0
      c += 1
    elsif c > 0
      l.upto(j - 1) do |k|
        s[i][k] = c
      end
      c = 0
    end
    if j == w && c > 0
      l.upto(j) do |k|
        s[i][k] = c
      end
    end
  end
end
ans = 0
1.upto(w) do |j|
  c = 0
  l = 1
  1.upto(h) do |i|
    if (s[i][j] > 0)
      l = i if c == 0
      c += 1
    elsif c > 0
      l.upto(i - 1) do |k|
        ans = s[k][j] + c if ans < s[k][j] + c
      end
      c = 0
    end
    if i == h && c > 0
      l.upto(i) do |k|
        ans = s[k][j] + c if ans < s[k][j] + c
      end
    end
  end
end
puts ans - 1

Measured memory_bytes: 47236
def factorize(m):
  facs=[]
  i=2
  if m==1:
    return [0]
  while m>1:
    j=0
    if m%i!=0:
      i+=1
    while m%i==0:
      j+=1
      m/=i
      if m%i!=0:
        facs.append(j)
        i+=1
        break
  return facs

def GCM(m,n):
  if m>n:
    m,n=n,m
  gcm=m
  while gcm>1:
    if n%gcm==0 and m%gcm==0:
      return gcm
    else:
      gcm-=1
  return 1

def GCM_many(s):
  gcm=s[0]
  for i in range(1,len(s)):
    gcm=GCM(gcm,s[i])
  return gcm

n=int(input())
if n==1:
  print(1)
  exit()
for i in range(1, n+1)[::-1]:
  facs=factorize(i)
  if GCM_many(facs)>1:
    print(i)
    exit()
print(1)

Measured memory_bytes: 3064
n, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(n)]


def dfs(i, a, b, c):
    if i == n:
        if a == 0 or b == 0 or c == 0:
            return 10 ** 18
        return abs(A - a) + abs(B - b) + abs(C - c)
    res = dfs(i + 1, a, b, c)
    res = min([res, dfs(i + 1, a + l[i], b, c) + (10 if a > 0 else 0)])
    res = min([res, dfs(i + 1, a, b + l[i], c) + (10 if b > 0 else 0)])
    res = min([res, dfs(i + 1, a, b, c + l[i]) + (10 if c > 0 else 0)])
    return res


print(dfs(0, 0, 0, 0))


Measured memory_bytes: 3064
#pragma GCC optimize("O3") 

#include <bits/stdc++.h>
using namespace std;

typedef long long int           ll;
typedef unsigned long long int  ull;
typedef long double             ld;

typedef pair<int, int>          pii;
typedef pair<ll,ll>             pll;
typedef vector<int>             vi;
typedef vector<ll>              vll;
typedef vector<pii>             vpii;
typedef vector<pll>             vpll;

#define test(t)		        int t; cin >> t; while(t--)
#define f(i, a, b)	        for(int (i) = (a); (i) < (b); ++(i))
#define all(a)		        (a).begin(), (a).end()
#define endl 		        "\n"
#define maxvec(vec)             *max_element(all(vec))
#define minvec(vec)             *min_element(all(vec))
#define maxarr(arr)             *max_element(arr, arr + n)
#define minarr(arr)             *min_element(arr, arr + n)
#define deb(x)		        cout << #x << ": " << x << endl;
#define deb2(x,y)	        cout << #x << ": " << x << " ~ " <<  #y << ": " << y << endl;
#define deba(arr)	        cout << #arr << " ~ [ "; for(auto n: arr) cout << n << " "; cout << "]" << endl;
#define debap(arr)	        cout << #arr << " ~ [ "; for(auto n: arr) cout << n.first << "-" << n.second << " "; cout << "]" << endl;
#define fast 		        ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define mx9		1000000007
#define mx7		10000007
#define mx6		1000006
#define mx5		200005
#define inf		1<<30                                 
#define eps		1e-9
#define mod		1000000007
#define PI		3.141592653589793238462643383279502884L

void solve()
{
    string s, t;
    cin >> s >> t;
    ll n = s.length(), m = t.length(), ans = n;
    f(i, 0, n - m + 1)
    {
        string test = (s.substr(i, m));
        // deb(t)
        ll cnt = 0;
        f(j, 0, m)
            if(test[j] != t[j])
                cnt += 1;
        ans = min(cnt, ans);
    }
    cout << ans << endl;
}

int main()
{
    fast;
    // test(t)
        solve();
    return 0;
}

Measured memory_bytes: 3624
use proconio::input;

fn main() {
    input! {
        r#as: [u128],
    }

    if r#as.iter().any(|&a| a == 0) {
        println!("0");
        return;
    }

    let mut ans = 1;
    for a in r#as {
        ans *= a;
        if ans > 10u128.pow(18) {
            println!("-1");
            return;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 5336
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
#define ll long long
#define ld long double
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i,j,k) mkp(i,mkp(j,k))
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define mkp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
#define ssp(i,n) (i==n-1?"\n":" ")
const int mod = 1e9 + 7;
const int Mod = 998244353;
const ll Inf = 3 * 1e18;
const int inf = 15 * 1e8;
ll read() {
	ll u, k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}
ll bcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
const int fn_ = 2000000;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll Mod = mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) {
			fact_[i] = fact_[i - 1] * i % Mod;
			comp_[i] = mod_pow(fact_[i], Mod - 2, Mod);
		}
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % Mod * comp_[y] % Mod;
}
//---------------------------------------------------
int n;
int a[300000];
signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int res = 1;
	for (int i = 0; i < n; i++) {
		if (a[i] == res) {
			res++;
		}
	}
	if (res == 1) {
		cout << -1 << endl;
	}
	else {
		cout << n - res + 1 << endl;
	}
}

Measured memory_bytes: 3840