akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.io.IOException;
import java.util.*;

@SuppressWarnings({"rawtypes", "unchecked"})
class Main {
    final static int INF = 1 << 28;
    final static long LNF = 1L << 60;
    final static double EPS = 1e-9;
    final static double GOLDEN_RATIO = (1.0 + Math.sqrt(5)) / 2.0;

    static final long MOD = 1_000_000_007;

    public static void main(String[] args) throws Exception {
        final MyScanner sc = new MyScanner();
        long X;
        X = sc.nextLong();
        solve(X);
    }

    static void solve(long X){
        if(X == 2) {
            System.out.println(2);
            return;
        }

        boolean flag = true;
        while(flag) {
            flag = false;
            for (int i = 2; i < X; i++) {
                if(X % i == 0) {
                    X++;
                    flag = true;
                    break;
                }
            }
        }
        System.out.println(X);
    }


    static class MyScanner {
 
        BufferedReader br;
        StringTokenizer st;
 
        MyScanner(FileReader fileReader) {
            br = new BufferedReader(fileReader);
        }
 
        MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
 
        String nn() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        String next() {
            String ans = "";
            try {
                ans = br.readLine();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            return ans;
        }
 
        char nextChar() {
            return nn().charAt(0);
        }
 
        int nextInt() {
            return Integer.parseInt(nn());
        }
 
        long nextLong() {
            return Long.parseLong(nn());
        }
 
        double nextDouble() {
            return Double.parseDouble(nn());
        }
 
        Integer[] niArr0(int n) {
            Integer[] ar = new Integer[n];
            for (int i = 0; i < n; i++) {
                ar[i] = nextInt();
            }
            return ar;
        }
 
        Integer[] niArr1(int n) {
            Integer[] ar = new Integer[n + 1];
            for (int i = 1; i <= n; i++) {
                ar[i] = nextInt();
            }
            return ar;
        }
 
        Long[] nlArr0(int n) {
            Long[] ar = new Long[n];
            for (int i = 0; i < n; i++) {
                ar[i] = nextLong();
            }
            return ar;
        }
 
        Long[] nlArr1(int n) {
            Long[] ar = new Long[n + 1];
            for (int i = 1; i <= n; i++) {
                ar[i] = nextLong();
            }
            return ar;
        }
    }

}


Measured memory_bytes: 21204
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<long long> A(N), B(N), C(N-1);
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    for(int i = 0; i < N; i++){
        cin >> B[i];
    }
    for(int i = 0; i < N-1; i++){
        cin >> C[i];
    }

    long long ans = 0;
    for(int i = 0; i < N; i++){
        ans += B[A[i]-1];
        if(i > 0){
            if(A[i-1] + 1 == A[i]){
                ans += C[A[i-1]-1];
            }
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

void	solve()
{
	ll a;
	long double b;
	cin >> a >> b;

	cout << (ll) (a * b) << endl;
}

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

	solve();
}


Measured memory_bytes: 3760
#!/usr/bin/env python
# -*- coding: utf-8 -*-

N = int(input())
s = list(map(int,input().split()))


partial_sum = 0
i = 0

for i in range(N):
    if(partial_sum < sum(s)/2.):
        partial_sum += s[i]
    else:
        break

ans1 = abs(2*(partial_sum - sum(s)/2.))

ans2=abs(2*(sum(s)/2. - (partial_sum - s[i-1])))

print(int(min([ans1, ans2])))


Measured memory_bytes: 3064
#include<stdio.h>
int main(){
    int A,B;
    scanf("%d %d",&A,&B);
    if(13<=A){
        printf("%d",B);
    } else if(6<=A&&A<=12){
        printf("%d",B/2);
    } else if(A<=5){
        printf("0");
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  int arr[n+1]{0};
  for (int i=0;i<k;i++)
  {
    int d;
    cin>>d;
    for (int j=1;j<=d;j++)
    {
      
      int a;
      cin>>a;
      arr[a]=1;
    }
  }
  int count=0;
  for (int i=1;i<=n;i++)
  {
    if (arr[i]==0)
      count++;
  }
  cout<<count;
}


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

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define mp make_pair
#define F first
#define S second


ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}


void init(long long* a,long long n,long long val){
	for(long long i=0;i<n;i++)
		a[i]=val;
}



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);	
	ll n;
	cin>>n;
	ll i,j;
	if(n==0||n==1){
	    cout<<0<<endl;
	    return 0;
	}
	ll a=0,b=0;
	if(n%2){
	    cout<<0<<endl;
	    return 0;
	}
	a+=n/2;
	n/=2;
	
	j=5;
	i=1;
	while(j<=n){
	    b+=(n/j);
	    j=j*5;
	    
	}j=2;
	while(j<=n){
	    a+=(n/j);
	    j*=2;
	    
	}
	cout<<min(a,b)<<endl;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
elevations=[0]+[x for x in map(int,input().split())]
connections={x:[] for x in range(1,N+1)}

roads=list()
for i in range(M):
    roads.append(tuple(map(int,input().split())))

for i in roads:
    connections[i[0]].append(i[1])
    connections[i[1]].append(i[0])

notgood=0   
for i in connections:
    if len(connections[i])>0:
        for j in connections[i]:
            if elevations[i]<=elevations[j]:
                notgood+=1
                break

print(N-notgood)
            
            
        


Measured memory_bytes: 44608
use std::cmp;

const INF: i64 = 1e15 as i64;

fn main() {
    let sc = std::io::stdin();
    let mut sc = Scanner { reader: sc.lock() };

    let n = sc.read();
    let k: usize = sc.read();
    let h: Vec<i64> = sc.read_vec(n);
    let mut dp = vec![INF; n];
    dp[0] = 0;
    for i in 0..n {
        for k in 1..(k + 1) {
            if i + k < n {
                dp[i + k] = cmp::min(dp[i + k], dp[i] + (h[i + k] - h[i]).abs());
            }
        }
    }
    println!("{}", dp[n - 1]);
}

pub struct Scanner<R> {
    reader: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 6396
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>

template <typename Container, class T>
bool contains(const Container& c, T v)
{
  return std::find(c.begin(), c.end(), v) != c.end();
}

class Graph {
public:
  // key: to
  using Edges = std::vector<int>;

  // n_v: number of verteces
  Graph(int n) : n_v_(n) {
    edges_.resize(n);
  }

  // add edge
  // return true: success, false: failed
  bool add_edge(int from,
                int to)
  {
    edges_[from].push_back(to);
    return true;
  }

  int n_v_;
  std::vector<Edges> edges_;
};

void find_path_dijistra2(const Graph &g,
                         std::vector<int> &ptr)
{
  ptr[0] = 0;

  std::queue<int> ts;
  for(auto e : g.edges_[0]) {
    ts.push(e);
    ptr[e] = 0;
  }

  while(!ts.empty()) {
    auto t = ts.front();
    ts.pop();

    Graph::Edges edges = g.edges_[t];
    for(auto it = edges.begin(); it != edges.end(); it++) {
      if(ptr[*it] < 0) {
        // std::cout << "edge: " << t << " -> "<< *it << std::endl;
        ptr[*it] = t;
        ts.push(*it);
     }
    }
  }
}

void find_path_dijistra(const Graph &g,
                        const std::set<int> &ts,
                        std::vector<bool> &seen,
                        std::vector<int> &ptr)
{
  /*
  std::cout << "find_path_dijistra handle: " << std::endl;
  std::for_each(ts.begin(), ts.end(),
                [](auto x) { std::cout << x << ","; });
  std::cout << std::endl;
  */
  std::set<int> nexts;
  for(auto _t=ts.begin(); _t != ts.end(); _t++) {
    auto t = *_t;
    if(seen[t]) continue;

    Graph::Edges edges = g.edges_[t];
    seen[t] = true;
    for(auto it = edges.begin(); it != edges.end(); it++) {
      if(ptr[*it] < 0) {
        ptr[*it] = t;
      }
      if(!seen[*it] && !contains(ts, *it)) {
        nexts.insert(*it);
      }
    }
  }

  if(!nexts.empty()) {
    find_path_dijistra(g, nexts, seen, ptr);
  }
}

int main()
{
  int N, M;
  std::cin >> N >> M;
  Graph g(N);
  // std::cout << "N = " << N << "M =" << M << std::endl;;

  for(int i=0; i<M; i++) {
    int f, t;
    std::cin >> f >> t;
    f--;
    t--;
    // std::cout << "f =" << f << " t=" << t << std::endl;
    g.add_edge(f, t);
    g.add_edge(t, f);
  }

  std::vector<int> ptr(N);
  std::for_each(ptr.begin(), ptr.end(),
                [](auto &x) -> void { x = -1; });

  // std::vector<bool> seen(N);
  // find_path_dijistra(g, {0}, seen, ptr);
  find_path_dijistra2(g, ptr);

  bool has_no_reachable = std::any_of(
      ptr.begin(), ptr.end(),
      [](auto x)->bool { return x < 0; });

  if(has_no_reachable) {
    std::cout << "No" << std::endl;
    return 0;
  }

  std::cout << "Yes" << std::endl;
  for(int i=1; i<N; i++) {
    std::cout << ptr[i] + 1 << std::endl;
  }
  return 0;
}



Measured memory_bytes: 10208
#include<stdio.h>
int main(){
  int m,t,p,R,a,b,c,d,i,j,r[51];
  while(scanf("%d %d %d %d",&m,&t,&p,&R),m||t||p||R){
    int pn[51][11]={0};
    int s[51]={0};
    while(R--){
      scanf("%d %d %d %d",&a,&b,&c,&d);
      if(d)pn[b][c]+=20;
      else s[b]+=(100000-a-pn[b][c]);
    }
    for(i=1;i<=t;i++)s[i]=s[i]*100+i;
    for(i=1;i<=t;i++){
      r[i]=i;
      for(j=i;j>1;j--){
	if(s[r[j-1]]<s[r[j]]){
	  m=r[j];
	  r[j]=r[j-1];
	  r[j-1]=m;
	}
      }
    }
    for(i=1;i<=t;i++){
      if(i-1){
	if(s[r[i-1]]/100==s[r[i]]/100)printf("=");
	else                          printf(",");
      }
      printf("%d",r[i]);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 604
N=int(input())
XA=0
BA=0
BX=0
internalAB=0
for t in range(N):
    i=input()
    headUsed=False
    footUsed=False
    for x,j in enumerate(i):
        if x==len(i)-1:break
        if j=="A" and i[x+1]=="B":
            internalAB+=1
            if x==0:headUsed=True
            if x==len(i)-2:footUsed=True
    if i[0]=="B" and not headUsed:
        if i[-1]=="A" and not footUsed:
            BA+=1
        else:BX+=1
    elif i[-1]=="A" and not footUsed:
        XA+=1
if XA or BX:
    externalAB=max(0,BA+min(XA,BX))
else:externalAB=max(0,BA-1)
ans=internalAB+externalAB
print(ans)


Measured memory_bytes: 3064
R = []
n = int(input())

for i in range(n):
  R.append(int(input()))

max_profit = -1000000000
minmum_value = R[0]

for i in range(1, n):
  max_profit = max(max_profit, R[i] - minmum_value)
  minmum_value = min(minmum_value, R[i])

print(max_profit)



Measured memory_bytes: 13596
#include <stdio.h>

int main(void)
{
    int i, j, t, a[5];
    for(i=0; i<5; i++) scanf("%d", &a[i]);

    for(i=0; i<5; i++) {
        for(j=0; j<4; j++) {
            if(a[j] < a[j+1]) {
                t = a[j];
                a[j] = a[j+1];
                a[j+1] = t;
            }
        }
    }

    printf("%d %d %d %d %d\n",a[0],a[1],a[2],a[3],a[4]);
    return (0);
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}/*char to int*/
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}/*MAX*/
int lcm(ll a,ll b){return a*b/gcd(a,b);}/*MIN*/
bool primecheck(ll n){/*sosuu*/if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
int  main(){
ll n;
cin >> n;
vector<ll>a(n);
ll zenntai=0;
for(int i=0;i<n;i++){
    cin >> a.at(i);
    zenntai+=a.at(i);
}
ll ans = 10e17;
ll migi=0;
for(int i=0;i<n-1;i++){
    migi+=a.at(i);
    zenntai-=a.at(i);
    ans =min(ans,abs(migi-zenntai));
}
cout << ans << endl;
}





Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
  int n,m,i,j = 0;cin >> n >> m;
  int x[m];long long dp[n+1];dp[0] = 1;
  for(i=0;i<m;i++) cin >> x[i];
  for(i=1;i<=n;i++){
    if(x[j]==i){
      dp[i] = 0;j++;
    } else if(i==1) dp[i] = 1;
    else dp[i] = dp[i-2]+dp[i-1];
    dp[i] %= 1000000007;
  }
  cout << dp[n] << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define forn(b) for(int i = 0; i < b; i++)
#define rforn(b) for(int i = b - 1 ;i >= 0; i--)
#define It(m) for(auto it = m.begin(); it != m.end(); it++)
#define N 500500
#define PI 3.14159265358979323846264338327950L
#define speed ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
const ll mod = (ll)1e9 + 7;
    
int main(){
    speed;
    int n; cin >> n;
    vi v(n);
    int mx = 1000001;
    forn(n) {
        cin >> v[i];
        mx = max(mx, v[i]);
    }
    vector<bool> er(mx + 1, false);
    map<int, bool> m;
    sort(all(v));
    int cnt = 0;
    for(int i = 1; i < n; i++) {
        if(v[i] == v[i - 1]) er[v[i]] = true;
    }
    for(int i = 0; i < n; i++) {
        if(er[v[i]] == false) cnt++;
        if(m[v[i]] == false) {
            for(int j = v[i]; j <= mx; j += v[i]) {
                er[j] = true;
            }
            m[v[i]] = true;
        }

    }
    if(n == 1) cnt = 1;
    cout << cnt;
    return 0;
}

Measured memory_bytes: 13416
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,y;
    int a[]={0,1,3,1,2,1,2,1,1,2,1,2,1};
    cin>>x>>y;
    cout<< (a[x]==a[y] ? "Yes":"No") <<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;                      


class Main {

	public enum Alfa{
		a(0),b(1),c(2),d(3),e(4),f(5),g(6),h(7),i(8),j(9),k(10),l(11),m(12),n(13),
		o(14),p(15),q(16),r(17),s(18),t(19),u(20),v(21),w(22),x(23),y(24),z(25) ;//アルファベットに数字を対応させる

		private final int id;
		private Alfa(final int id){this.id=id;}//数字の習得
		
		

		public int getId(){
			return id;
		}

		public static Alfa getById(int id) {//指定された数字の列挙子を返す
			for (Alfa p : Alfa.values()) {
				if (p.getId() == id) return p;
			}
			return null;
		}

	}


	public static void main(String[] args) {   
	     
		Scanner scanner = new Scanner(System.in);
		
		String x="";
		while (scanner.hasNextLine()) {

			String y= scanner.nextLine();
			x=x+y;
		if (y.length() == 0) { 
			break;
		}}
		
		String x1= x.toLowerCase();//入力された文字をすべて小文字に変換
		char[] a; 
		a=new char[x.length()];//配列の最大値は文字数		
		
		String[] st;
		st=new String[x.length()];
		
		String[] st2;
		st2=new String[x.length()];
		int t=0;
		
		int[] sum;//この配列の番号と列挙型のアルファベットがリンクしている。
		sum=new int[Alfa.values().length];
		
		
		
		
		for(int i=0;i < x.length();i++){//桁数分くりかえす
			a[i]=x1.charAt(i);//文字列を1文字ずつ配列に格納
			st[i]=String.valueOf(a[i]);//String型に変換
			
			String regex = "^[a-z]+$";
			Pattern p = Pattern.compile(regex);
			Matcher m = p.matcher(st[i]); //正規表現にマッチするか検査

			if (m.matches()) {
				st2[t]=st[i];//マッチした場合st2に格納
				t=t+1;//マッチした数だけループの回数を制御する
			}
		}
		
		for(int i=0;i < t;i++){
			
		Alfa frt=Alfa.valueOf(st2[i]);
        sum[frt.ordinal()]=sum[frt.ordinal()]+1; //配列sumの各アルファベットに対応した位置に格納
      
		}
		
		for(int i=0;i < Alfa.values().length;i++){
			System.out.println(Alfa.getById(i)+" : "+sum[i]);
			
		}
		
		
		scanner.close();

	


}
}




Measured memory_bytes: 29524
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<numeric>
#include<map>

#define REP(i, a) for(int i=0;i<(int)a;++i)
#define ALL(a) (a).begin(),(a).end()
#define VI vector<int>
#define INF 1145141919

template<class T, size_t N>
size_t countof(const T (&array)[N]) { return N; }

typedef long long ll;
typedef long double ld;

using namespace std;

int info[10][3][4];

void solver() {
    REP(i, 10)REP(j, 3)REP(k, 4)info[i][j][k] = 0;
    int n, b, f, r, v;
    cin >> n;
    REP(i, n) {
        cin >> b >> f >> r >> v;
        info[r - 1][f - 1][b - 1] += v;
    }
    REP(i, 4) {
        REP(j, 3) {
            REP(k, 10) {
                cout << " " << info[k][j][i];
            }
            cout << endl;
        }
        if (i != 4 - 1)cout << "####################" << endl;
    }
}

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


Measured memory_bytes: 3092
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n+1) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 

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> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
  
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n,k;
    vector<int> p(3);
    vector<char> c = {'r','s','p'};
    string t;
    cin >> n >> k >> p[0] >> p[1] >> p[2] >> t;
    vector<bool> r(n);
    int sum = 0;
    rep(j,n){
        if(j < k){
            if(t[j] == 'r') sum += p[2];
            else if(t[j] == 's') sum += p[0];
            else sum += p[1];
            r[j] = true;
        }else{
            if(t[j] == 'r'){
                if(!(r[j-k] && t[j-k] == t[j])){
                    sum += p[2];
                    r[j] = true;
                }
            }else if(t[j] == 's'){
                if(!(r[j-k] && t[j-k] == t[j])){
                    sum += p[0];
                    r[j] = true;
                }
            }else{
                if(!(r[j-k] && t[j-k] == t[j])){
                    sum += p[1];
                    r[j] = true;
                }
            }
        }
    }
    cout << sum << '\n';
	return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <ios>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int a, b, h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << "\n";
}

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

namespace Volume0018
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] num = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            Array.Sort(num);
            Array.Reverse(num);
            Console.Write(num[0]);
            for (int i = 1; i < num.Length; ++i)
            {
                Console.Write(" " + num[i]);
            }
            Console.WriteLine();
        }
    }
}



Measured memory_bytes: 16352
// Undone
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
#define MOD 1000000007
using namespace std;
vector<string> blocks[4];

bool judge(vector<string> ban, vector<int> perm) {
  int success = 0;
  for (int i = 0; i < 3; i++) {
    for (int y = 0; y < 4; y++) {
      for (int x = 0; x < 10; x++) {
        int cnt = 0;
        for (int h = 0; h < blocks[perm[i]].size(); h++) {
          for (int w = 0; w < blocks[perm[i]][0].size(); w++) {
            if (y+h >= 4 || x+w >= 10) {
              h=100;
              break;
            }
            if (ban[y+h][x+w] == '#' && blocks[perm[i]][h][w] == '#') {
              h=100;
              break;
            }
            if (blocks[perm[i]][h][w] == '#') {
              cnt++;
            }
          }
        }
        if (cnt == 4) {
          for (int h = 0; h < blocks[perm[i]].size(); h++) {
            for (int w = 0; w < blocks[perm[i]][0].size(); w++) {
              if (y+h >= 4 || x+w >= 10) {
                break;
              }
              if (blocks[perm[i]][h][w] == '#') {
                ban[y+h][x+w] = '#';
              }
            }
          }
          x = y = 100;
          success++;
        }
      }
    }
    if(success!=i+1) return 0;
  }
  //cout << perm[0] << perm[1] << perm[2] << perm[3] << endl;
  return (success == 3);
}

signed main() {
  ios::sync_with_stdio(0);cin.tie(0);
  int x, y;
  for (int i = 0; i < 4; i++) {
    cin >> x >> y;
    string s;
    for (int j = 0; j < x; j++) {
      cin >> s;
      blocks[i].push_back(s);
    }
  }

  int n; cin >> n;
  for (int i = 0; i < n; i++) {
    vector<int> perm = { 0, 1, 2, 3 };
    vector<string> ban(4);
    for (int j = 0; j < 4; j++) {
      cin >> ban[j];
    }
      
    int yes = 0;
    do {
      if (judge(ban, perm)) {
        cout << "Yes" << endl;
        yes = 1;
        break;
      }
    } while(next_permutation(perm.begin(), perm.end()));
    if (!yes) {
      cout << "No" << endl;
    }
  }
}





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

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
#define TRACE(x) cerr << #x << " = " << x << endl

typedef long long ll;
typedef pair<int, int> point;

const int mod = 1e9 + 7;

int add(int x, int y) {x += y; if(x >= mod) return x - mod; return x;}
int sub(int x, int y) {x -= y; if(x < 0) return x + mod; return x;}
int mul(int x, int y) {return (ll) x * y % mod;}

const int MAXN = 1e5 + 5;

int n, m;
bool done[MAXN];
int cnt[MAXN];

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

  cin >> n >> m;
  int sol = 0, penalty = 0;
  REP(i, m){
    int p; string s; cin >> p >> s;
    if(done[p]) continue;
    if(s == "WA")
      cnt[p] ++;
    else{
      sol ++;
      penalty += cnt[p];
      done[p] = true;
    }
  }
  cout << sol _ penalty;
}


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


public class Main {
	static int N;
	static long[] T;
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
			 N = sc.nextInt();
			 T = new long[N];
			 for(int i = 0 ; i < N ; i++){
				 T[i] = sc.nextInt();
			 }
		  sc.close();

		  Arrays.sort(T);

		  long ans = T[((N-1))] - T[0];

		  for(int i = 0 ; i < (N-2)/2 ; i++){
			  ans += T[((N-1)-i)] - T[i+1];
			  ans += T[((N-1)-i-1)] - T[i];

		  }
		  if(N%2 != 0){
			  ans += Math.max(T[(N/2)+1]-T[N/2], T[N/2]-T[(N/2)-1]);
		  }
		  System.out.println(ans);
	}
}

Measured memory_bytes: 60596
#include<cstdio>
using namespace std;
int main(){
    int n,a,b;
    scanf("%d",&n);
    a=n/100;
    b=n%100;
    if(a&&b&&a<=12&&b<=12){
        printf("AMBIGUOUS\n");
    }
    else if(b&&b<=12){
        printf("YYMM\n");
    }
    else if(a&&a<=12){
        printf("MMYY\n");
    }
    else{
        printf("NA\n");
    }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#define l first
#define r second
#define int long long

const int maxn = 1e7 + 1, maxk = 1500101;

using namespace std;

int a[maxn];

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, k;
    cin >> k >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    int ans = k;
    for (int i = 1; i < n; i++)
        ans = min(ans, k - (a[i] - a[i - 1]));
    ans = min(ans, a[n - 1] - a[0]);
    cout << ans;
    return 0;
}


Measured memory_bytes: 1792
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

const int A = 1000000;
int is_prime[A + 10], rec[A + 10], ans[A + 10];
signed main() {
    int L, R; cin >> L >> R;
    int rng = R - L + 1;

    fill(is_prime, is_prime + A + 10, 1);
    iota(rec, rec + rng + 1, L);
    is_prime[0] = is_prime[1] = false;
    for(int i=2; i<=A; i++) {
        if(is_prime[i]) {
            for(int k=2*i; k<=A; k+=i) {
                is_prime[k] = false;
            }
            // L 以上の i で割り切れるものの中で最小のもの
            for(int k=(L+i-1)/i*i; k<=R; k+=i) {
                int idx = k - L;
                // fprintf(stderr, "k = %lld, idx = %lld, rec = %lld\n", k, idx, rec[idx]);
                while(rec[idx] % i == 0) {
                    rec[idx] /= i;
                    ans[idx]++;
                }
            }
        }
    }

    int out = 0;
    for(int i=0; i<rng; i++) {
        int fac = ans[i] + (rec[i] > 1);
        // fprintf(stderr, "v = %lld, fac = %lld\n", i + L, fac);
        if(is_prime[fac]) out++;
    }
    cout << out << endl;
    return 0;
}



Measured memory_bytes: 26536
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#define ll long long
const int MOD = 1e9+7;
using namespace std;

int bingo[3][3];
bool bing[3][3];


int main(){
	int n;
	for (int i = 0; i < 3; i++){
		for (int j = 0; j < 3; j++){
			cin >> bingo[i][j];
		}
	}
	cin >> n;
	vector<int> b(n);
	for (int i = 0; i < n; i++){
		cin >> b[i];
		for (int j = 0; j < 3; j++){
			for (int k = 0; k < 3; k++){
				if (b[i] == bingo[j][k]){
					bing[j][k] = true;
				}
			}
		}
	}

	for (int i = 0; i < 3; i++){
		int ana1 = 0, ana2 = 0, ana3 = 0, ana4 = 0;
		for (int j = 0; j < 3; j++){
			if (bing[i][j] == true){
				ana1++;
			}
			if (bing[j][i] == true){
				ana2++;
			}
			if (bing[j][j] == true){
				ana3++;
			}
			if (bing[2-j][j] == true){
				ana4++;
			}
		}
		if (ana1 == 3 || ana2 == 3 || ana3 == 3 || ana4 == 3){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}

int n;

int f(int a, int b){
    if(a > b)swap(a,b);
    return a*n+b;
}

signed main(void) {
    cin >> n;
    vector<vector<int> > g(n*n);
    vi num(n*n,0),used(n*n,0);
    rep(i,n){
        vi a(n-1);
        rep(j,n-1)cin >> a[j],a[j]--;
        rep(j,n-2){
            g[f(i,a[j])].push_back(f(i,a[j+1]));
            num[f(i,a[j+1])]++;
            used[f(i,a[j])]++;
            used[f(i,a[j+1])]++;
        }
    }
    queue<int> q;
    //rep(i,n*n)cout << " " << used[i];cout << endl;
    //rep(i,n*n)cout << " " << num[i];cout << endl;
    rep(i,n*n)if(used[i] && num[i] == 0)q.push(i);
    int ans = 1;
    vi day(n*n,-1);
    while(q.size()){
        int v = q.front();
        q.pop();
        int a = v%n, b = v/n;
        if(day[a] == ans || day[b] == ans)ans++;
        day[a] = day[b] = ans;
        //cout << v << " " << a << " " << b << " " << ans << endl;
        rep(i,g[v].size()){
            int ne = g[v][i];
            num[ne]--;
            if(num[ne] == 0)q.push(ne);
        }
    }
    rep(i,n*n)if(num[i]){
        cout << -1 << endl;
        return 0;
    }
    cout << ans << endl;
}


Measured memory_bytes: 62720
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>
// 多倍長整数型
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */

 
#define INF 1e9
#define LINF 1e19
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
     
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
     
const ll MOD = 1e9 + 7;
const ll ZER = 0;
 


int main(){
  Bint x, k, d;
  cin >> x >> k >> d;
  x = abs(x);
  Bint cnt = x / d;

  if(k < cnt){
    Bint res = x - d * k;
    cout << res << endl;
  }
  else {
    Bint res;
    if(x > 0){
      Bint l = x - d * (cnt + 1), r = x - d * cnt;
      k -= cnt;
      if(k % 2 == 0)cout << r << endl;
      else cout << -l << endl;
    }
    else{
      Bint l = x - d * cnt, r = x - d * (cnt - 1);
      k += cnt;
      if(k % 2 == 0)cout << -l << endl;
      else cout << r << endl;
    }
  }
}
 

Measured memory_bytes: 3704
#include<stdio.h>
#define MAX 3500000
int A,B,N,i,j,P[MAX],F[MAX]={1,1},p;
int main()
{
	int N;
	for(i=2;i<MAX;i++)
		if(!F[i])
		{
			P[p++]=i;
			for(j=i*2;j<MAX;j+=i)
				F[j]=1;
		}
	for(;scanf("%d%d%d",&A,&B,&N),A+B;)
	{
		for(i=0;i<N;A+=B)
			if(!F[A])
				i++;
		printf("%d\n",A-B);
	}
	return 0;
}

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

int main(){

   string str;

   int joi=0,ioi=0,i=0;

   bool check = true;

   while(cin >> str){ 

    joi = 0; ioi = 0;

    i = 0;
  
    if(str[0] == '0') break;

    check = true;

    while(check){

     if(str.find("JOI",i) >= 0 && str.find("JOI" , i) < str.size()){

   
      i =  str.find("JOI",i) + 1; 

      joi++;

      check = true;
      
     }

     else check = false;

    }

   i = 0;

   check = true;

   while(check){

     if(str.find("IOI",i) >= 0 && str.find("IOI" , i) < str.size()){
   
     i =  str.find("IOI",i) + 1;

     ioi++;

     check = true;

     }

    else check = false;

   }

   cout << joi <<endl << ioi <<endl;

  }

  
  return 0;
 

  
}

Measured memory_bytes: 1200
N,M = map(int,input().split())
s = [0]*M
c = [0]*M
X = [0]*int((str(N)))
a = 0
for i in range (M):
    s[i],c[i] = map(int,input().split()) 
for i in range(M):
    if X[s[i] - 1] != 0 and X[s[i] - 1] != c[i]:
        a = -1
        break
    elif s[i] == 1 and c[i] == 0 and N != 1:
        a = -1
        break
    else:
        X[s[i] - 1] = c[i]
if a == -1:
    print(a)
else:
    if N == 1:
        print(X[0])
    if N == 2:
        print(max(1,X[0])*10 + X[1])
    if N == 3:
        print(max(1,X[0])*100 + X[1]*10 + X[2])

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

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

	int k = 0;
	k = n % 7;
	if (k == 2)
	{
		cout << "sat" << endl;
	}
	else if (k == 1)
	{
		cout << "fri" << endl;
	}
	else if (k == 0)
	{
		cout << "thu" << endl;
	}
	else if (k == 6)
	{
		cout << "wed" << endl;
	}
	else if (k == 5)
	{
		cout << "tue" << endl;
	}
	else if (k == 4)
	{
		cout << "mon" << endl;
	}
	else
	{
		cout << "sun" << endl;
	}
}



Measured memory_bytes: 3096
N = int(input())
A = sorted(list(map(int,input().split())))
amari = 10**9 + 7
ans = []
han = 0

if N % 2 == 0:
    han = 1
else:
    han = 0
    A.insert(0,0)


ans = list(int(i) for i in range(han,N,2))
ans += ans
ans.sort()

if ans == A:
    print(2**(N//2) % amari)
else:
    print("0")

Measured memory_bytes: 14008
#include <bits/stdc++.h>
using namespace std;
int n,c;
char s[101];
int main(){
    while(cin>>s[n]){
        n++;
    }n--;
    for(int i=0;i<=(n/2);i++){
        if(s[i]!=s[(n-i)])c++;
    }
    cout<<c<<endl;
}


Measured memory_bytes: 256
use std::cmp;
use std::fmt::Debug;
use std::str::FromStr;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where
    T: FromStr,
    <T as FromStr>::Err: Debug,
{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim()
        .split_whitespace()
        .map(|c| T::from_str(c).unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_as_string() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
    let line = read_as_vec::<usize>();
    let (d, t, s) = (line[0], line[1], line[2]);

    if d <= t * s {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll factorial(ll n) {
  ll answer = 1;
  while (n > 1) {
    answer *= n;
    answer %= mod;
    n--;
  }
  return answer;
}

ll combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

ll permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
// for (auto p : prime_factor(n)) {
//	while (p.second--) {
//		cout << p.first << endl;
//	}
//}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

int main() {
  int n, k;
  cin >> n >> k;
  ivec l(n);
  REP(i, n) { cin >> l[i]; }
  sort(RALL(l));
  int ans = 0;
  REP(i, k) { ans += l[i]; }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
#最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
  
#最小公倍数
def lcm(a, b):
    return a * b // gcd (a, b)

#全体の最小公倍数は？
l = a[0]  
for i in range(1,n):
  l = lcm(l,a[i])

#答えは(最小公倍数−１)%a[i]の合計  
ans = 0  
for i in range(n):
  ans += (l-1) % a[i]
print(ans)  
  
  
  

  
  

Measured memory_bytes: 3316
# 累積和による解法
def resolve():
    N, K = list(map(int, input().split()))
    S = input()
    seq = []
    cnt = 0
    if S[0] != "1":
        seq.append(0)
    for i in range(len(S)-1):
        if S[i] != S[i+1]:
            seq.append(cnt+1)
            cnt = 0
        else:
            cnt += 1
    seq.append(cnt+1)
    if S[-1] != "1":
        seq.append(0)
    #print(seq)

    cum = [0]
    cur = 0
    for c in seq:
        cur += c
        cum.append(cur)
    #print(cum)
    
    maxlen = len(S) if len(cum) <= (2*K+1) else 0
    for i in range(0, len(cum)-(2*K+1), 2):
        l = cum[i+(2*K+1)] - cum[i]
        maxlen = max(maxlen, l)
    print(maxlen)
    

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 7924
#include <vector>
#include <iostream>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	bool valid = true;
	for (int i = 0; i < n; ++i) {
		if (a[i] > i + 1) valid = false;
	}
	if (!valid) {
		cout << -1 << endl;
	}
	else {
		vector<int> perm(n);
		for (int i = n - 1; i >= 0; --i) {
			vector<bool> flag(n, false);
			for (int j = i + 1; j < n; ++j) {
				flag[perm[j]] = true;
			}
			int cnt = 0;
			for (int j = 0; j < n; ++j) {
				if (!flag[j]) ++cnt;
				if (cnt == a[i]) {
					perm[i] = j;
					break;
				}
			}
		}
		vector<int> ip(n);
		for (int i = 0; i < n; ++i) {
			ip[perm[i]] = i;
		}
		for (int i = 0; i < n; ++i) {
			cout << a[ip[i]] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
while True:
    a,b = (int(x) for x in input().split())
    if a == 0 and b == 0:
        break
    for j in range(b):
        print("#",end='')
    print()
    for i in range(a-2):
        print("#",end='')
        for j in range(b-2):
            print(".",end='')
        print("#",end='')
        print()
    for j in range(b):
        print("#",end='')
    print()
    print()


Measured memory_bytes: 7008
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll n,l,t,a[maxn],w[maxn],ans[maxn],num;

int main()
{
	n=read(); l=read(); t=read(); rep(i,1,n) a[i]=read(),w[i]=read();
	rep(i,1,n)
	{
		if(w[i]==1)
		{
			num+=(a[i]+t)/l; num%=n;
			a[i]=(a[i]+t)%l;
		}
		else
		{
			num+=(a[i]-t)/l; num%=n; if(num<0) num+=n;
			a[i]=(a[i]-t)%l; if(a[i]<0) a[i]+=l,num--;
		}
	}
	sort(a+1,a+n+1);
	rep(i,1,n)
	{
		int tmp=(i+num)%n; if(tmp==0) tmp=n;
		printf("%d\n",a[tmp]);
	}
	return 0;
}

Measured memory_bytes: 9344
#135_D
s=input()
mod=10**9+7

#dp[i][j]...i桁目までで余りがj
dp=[[0 for _ in range(13)] for _ in range(len(s)+1)]
dp[0][0]=1

for i in range(0,len(s)):
    if s[i]=='?':
        for j in range(13):
            for x in range(10):
                dp[i+1][(j*10+x)%13]+=dp[i][j]
                dp[i+1][(j*10+x)%13]%=mod
    else:
        x=int(s[i])
        for j in range(13):
            dp[i+1][(j*10+x)%13]+=dp[i][j]
            dp[i+1][(j*10+x)%13]%=mod
    
print(dp[len(s)][5])

Measured memory_bytes: 66140
#include<stdio.h>


int main(){
	int n,v[20],c[20],i, a[20];
	int cnt = 0;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &v[i]);
	}for (i = 0; i < n; i++) {
		scanf("%d", &c[i]);
		a[i] = v[i] - c[i];
	}
	
	for (i = 0; i < n; i++) {
		for (int j = i - 1; j > i; j--) {
			if (a[j] > a[j - 1]) {
				int cmp = a[j];
				a[j] = a[j - 1];
				a[j - 1] = cmp;

			}
		}

	}
	
	for (i = 0; i < n; i++) {
		if (a[i] > 0)cnt+=a[i];
		
	}
	printf("%d",cnt );
	


	return 0;

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) < (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n) - 1; (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;
#define all(x) (x).begin(),(x).end()

ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll fac(ll n){
    ll t = 1;
    rep1(i, n + 1)t *= i;
    return t;
}

int main()
{
    string s;
    ll w = 0,l = 0,g = 0,p = 0;
    cin >> s;
    rep0(i, s.size()){
        if (g > p) {
            if (s[i] == 'g') {
                ++w;
            }
            ++p;
        }else{
            if (s[i] == 'p') {
                ++l;
            }
            ++g;
        }
    }
    cout << w - l << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }

int main()
{
    ll A, B, N;
    cin >> A >> B >> N;
    ll c = A / B, d = A % B;
    ll r = min(N, B - 1), drB = (d * r) / B;
    ll ret = c * r + drB;
    cout << ret << "\n";
    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
using namespace std;
int main(void){
   int n,a[100]={0};
   cin>>n;
   for(int i=0;i<n;i++){
       cin>>a[i];
   }
   int j=n-1;
   cout<<a[j];

   for(int i=0;i<n-1;i++){
       j=n-1-i;
       cout<<" "<<a[j-1];
   }
   cout<<endl;

}




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

using namespace std;

char s[10];

int main(void)
{
    scanf("%s", s);
    if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) printf("Bad\n");
    else printf("Good\n");
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
//const long long mod = 1000000007;
//const long long mod = 998244353;

int main() {
	long long A, B;
	scanf("%lld %lld", &A, &B);
	std::vector<long long>pa, pb;
	long long a = A;
	for (long long i = 2; i*i <= a; i++) {
		if (a%i == 0) {
			pa.push_back(i);
			while (a%i == 0)a /= i;
		}
	}
	if (a != 1)pa.push_back(a);
	long long b = B;
	for (long long i = 2; i*i <= b; i++) {
		if (b%i == 0) {
			pb.push_back(i);
			while (b%i == 0)b /= i;
		}
	}
	if (b != 1)pb.push_back(b);
	long long cnt = 1;
	int ia = 0, ib = 0;
	while (1) {
		if (ia == pa.size())break;
		if (ib == pb.size())break;
		if (pa[ia] == pb[ib]) {
			cnt++;
			ia++;
			ib++;
		}
		else if (pa[ia] > pb[ib]) {
			ib++;
		}
		else {
			ia++;
		}
	}
	printf("%lld", cnt);
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)




ll gcd(ll a, ll b){
    if(b == 0)return a;
    return gcd(b, a % b);
}

int main() {
    ll t;
    cin >> t;
    
    REP(i, t){
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        
        if(a < b || b > d){
            cout << "No" << '\n';
            continue;
        }

        if(b == d || d % b == 0){
            if(a % b <= c){
                cout << "Yes" << endl;
            }
            else{
                cout << "No" << endl;
            }
            continue;
        }
        
        
        ll x = gcd(b, d);
        if(c + x >= b){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
        
        /*
        ll x = (a % b) + (d % b) * ((b - (a % b)) / (d % b) - (((b - (a % b)) % (d % b) == 0)? 1 : 0));
        if(c < x && x < b){
            cout << "No" << endl;
        }
        else{
            cout << "Yes" << endl;
        }
        */
    }
}


Measured memory_bytes: 256