akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
 
public class Main {
    public static void main(String [] args) {
        FastReader reader = new FastReader();
 
        int N = reader.nextInt();
        int W = reader.nextInt();
        int maxValue = 0;
        int [] weight = new int [N];
        int [] sum = new int [N];
        int [] value = new int [N];
 
        for (int i = 0; i < N; i++) {
            weight[i] = reader.nextInt();
            value[i] = reader.nextInt();
            sum [i] = value[i] + (i > 0 ? sum[i - 1] : 0);
        }
 
        long [][] dp = new long [N + 1][sum[N - 1] + 1];
 
        for (int i = 0; i <= N; i++) {
            Arrays.fill(dp[i], Integer.MAX_VALUE);
            dp[i][0] = 0;
            if (i == 0) continue;
            int wi = weight[i - 1], vi = value[i - 1];
            for (int v = 1; v <= sum[i - 1]; v++) {
                dp[i][v] = dp[i - 1][v];
                int temp = Math.max(0, v - vi);
                dp[i][v] = Math.min(dp[i][v], dp[i - 1][temp] + wi);
                if (dp[i][v] <= W) {
                    maxValue = Math.max(maxValue, v);
                }
            }
        }
 
        System.out.println(maxValue);
 
    }
 
 
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }
 
        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt()
        {
            return Integer.parseInt(next());
        }
 
        long nextLong()
        {
            return Long.parseLong(next());
        }
 
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
 
        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}

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

int main() {
  ll X, A, B;
  cin >> X >> A >>B;
  
  if (B <= A) {
    cout << "delicious" << endl;
  } else if (B <= A+X) {
    cout << "safe" << endl;

  } else {
    cout << "dangerous" <<endl;
  }
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
a = [0]*(2*N)
for i in range(N):
  a[i] = A[i]
  a[i + N] = A[i]
M = [0]*N
M[0] = A[0]
for j in range(int((N+1)/2)):
  M[0] += a[2*j] - a[2*j+1]
for j in range(N - 1):
  M[j + 1] = 2*A[j] - M[j]
for i in range(N):
  print(str(M[i]),end = " ")

Measured memory_bytes: 14400
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    int ab, bc, ca; cin >> ab >> bc >> ca;
    cout << bc * ab / 2 << ln;
}

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

#define ll long long int

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll n, ans = 0;
	cin >> n;
	ll a[n];
	cin >> a[0];
	for(ll i = 1; i < n; i++){
		cin >> a[i];
		if(a[i] < a[i-1]){
			ans += a[i-1] - a[i];
			a[i] = a[i-1];
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 5176
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#include <random>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1'000'000'007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------



int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> cnt(N+1,0);
  for(int i=1; i<200; i++){
    for(int j=1; j<200; j++){
      for(int k=1; k<200; k++){
        int now = i*i + j*j + k*k + i*j + j*k + k*i;
        if(now <= N){
          cnt[now]++;
        }
      }
    }
  }
  for(int i=1; i<=N; i++){
    cout << cnt[i] << "\n";
  }
  return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>

using namespace std;

int main(){
  int n, ans = 0;
  char yubiwa[100][10] = {{0},{0}};
  char s[10] = {0};
  
  scanf("%s%d", s, &n);
  for(int i = 0; i < n; i++){
    scanf("%s", yubiwa[i]);
    int m = 0;
    for(int j = 0; j <25; j++){
      //cout << "j : " << j << " yubiwa : " << yubiwa[i][j % 10] << " s : " << s[m] << endl;
      if(s[m] == 0){
        ans++;
        break;
      }else if(yubiwa[i][j % 10] == s[m]){
        m++;
        //cout << "OK" << endl;
      }else{
        m = 0;
        if(yubiwa[i][j % 10] == s[m]){
          m++;
        }
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}

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

typedef long long ll;

const int mod = 1000000007;
const int Maxl = 26;

int n;
int freq[Maxl];

int main()
{
    scanf("%d", &n);
    string s; cin >> s;
    for (int i = 0; i < n; i++)
        freq[s[i] - 'a']++;
    int res = 1;
    for (int i = 0; i < Maxl; i++)
        res = ll(res) * (freq[i] + 1) % mod;
    res = (res - 1 + mod) % mod;
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 512
/**
 * C - Typical Stairs
 * https://atcoder.jp/contests/abc129/tasks/abc129_c
 * 
 * # 方針
 * 全探索
 * 
 **/
#include<iostream>
#include<vector>

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> a(N+1);
    vector<long long> keiro(N+1);
    for(int i=0; i<M; i++) {
        int ai;
        cin >> ai;
        a[ai] = 1;
    }
    
    for(int i=1; i<N+1; i++) {
        if(a[i] == 1) {
            keiro[i] = 0;
        } else if(i==1) {
            keiro[1] = 1;
        } else if(i==2) {
            keiro[2] = 1 + keiro[1];
        } else {
            keiro[i] = (keiro[i-1] + keiro[i-2])%1000000007;
        }
    }

    cout << keiro[N] << endl;
    return 0;
}


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

#define N 5000 + 10
int f[N][N],n,ans;
char s[N];

int main(){
ios::sync_with_stdio(false);
cin>>n>>s;
for(int i=n-1;i>=0;i--)
for(int j=n-1;j>=0;j--){
if(s[i]==s[j])
f[i][j]=max(f[i][j],f[i+1][j+1]+1);
ans=max(ans,min(f[i][j],j-i));
}
cout<<ans;
}

Measured memory_bytes: 98176
#include <iostream>

using namespace std;

int main(){
  int N, h[100], count = 0;
  cin >> N;
  for (int i = 0; i < N; i++) cin >> h[i];
  
  int n = 0;
  while (n < N)
  {
    if (h[n] != 0)
    {
      for (int i = n; i < N; i++)
      {
        if (h[i] == 0) break;
        h[i]--;
      }
      //for (int i = 0; i < N; i++) cout << h[i] << " ";
      //cout << endl;
      count++;
    }
    else n++;
  }
  cout << count;
}

Measured memory_bytes: 3640
#include <iostream>
#include <map>
#include <bitset>
#include <climits>
#include<algorithm>
#include <vector>
#include <unordered_map>
#define loop for(int i=0;i<n;i++)
#define pb push_back
using namespace std;
typedef   long long int ll;
int main()
{
	ll n;
	cin>>n;
	ll a;
	ll b;
	cin>>a>>b;
   ll	c=a+b;
	cout<<((n/c)*a)+min(n%c,a);
}


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

class UnionFind:
    def __init__(self, n):
        # par = Parent Number or NoV
        self.par = [-1] * (n+1)
        # rank = Tree Height
        self.rank = [0] * (n+1)
    
    # 自分が所属する集合の数を返す
    def size(self, x):
        return -1*self.par[self.find(x)]

    # 根なら番号を返す
    def find(self, x):
        
        if(self.par[x] < 1):
            return x
        self.par[x] = self.find(self.par[x])
        return self.par[x]

    # 親が同じか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    def union(self, x, y):
        # 根を探す
        x = self.find(x)
        y = self.find(y)

        # もう繋がれている
        if(x == y):
            return False

        # つなぎ替える
        if(self.size(x) < self.size(y)):
            x,y = y,x
        
        # xのサイズを更新
        self.par[x] += self.par[y]
        # yのサイズ(おやばんごう)をxに
        self.par[y] = x

        return True 

def solve(N: int, M: int, a: "List[int]", b: "List[int]"):
    
    ans = 0
    for i in range(M):
        uf = UnionFind(N)
        for j in range(M):
            if(i == j):
                continue
            uf.union(a[j], b[j])
        if(not uf.same_check(a[i],b[i])):
            ans += 1
    print(ans)
    return


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.util.*;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner sc = new Scanner(System.in);
      	//数値の入力
		int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
      	//aの倍数をfor文で回す↓
      	//総和をbで割りc余るか
      for(int i = 0; i < b; i++){
        int aTotal = a*(i+1);
        if(aTotal%b ==c){
        System.out.println("YES");
        return;
        }
      }
        System.out.println("NO");
     }
}

Measured memory_bytes: 35696
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
using namespace std;
typedef long long LL;
 
int main() {
	int t, i, j, k;
	int a, b, c ,F=0;
	
	cin >> a;
 
	F = a/100%10+a/10%10+a%10;
 
	cout << F << endl;
	return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9  //
#define LINF (ll)4e18  //
#define MOD (int)(1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define PI 3.1415926535898

//------------------------------------------------------

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



Measured memory_bytes: 256
import math

def number(plist):
    a = 1
    memo = []
    while len(plist) > 0:
        p = plist.pop(0)
        memo.append(p)
        num = len(set(range(1, p)) - set(memo))
        a += math.factorial(len(plist)) * num
    return a

n = int(input())
plist = list(map(int, input().split()))
qlist = list(map(int, input().split()))

a = number(plist)
b = number(qlist)
print(int(math.fabs(a - b)))

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N;cin >> N;
    vector<int> A(N),L(N),R(N);
    rep(i,N)cin >> A[i];
    rep(i,N){       // 左累積和　L 作成
        if(i == 0)L[0] = 0;
        else if(i == 1)L[1] = abs(A[0]);
        else{
            L[i] = L[i-1] + abs(A[i-1] - A[i-2]);       // L は　i番目以前の累積和なので、absの中がA[i-1]-A[i-2]になる。
        }
    }
    for(int i = N-1;i>=0;i--){  // 右累積和　R　作成
        if(i == N-1)R[N-1] = 0;
        else if(i == N-2)R[N-2] = abs(A[N-1]);
        else{
            R[i] = R[i+1] + abs(A[i+1] - A[i+2]);
        }
    }
    rep(i,N){
        if(i == 0){
            cout << L[0] + R[0] + abs(A[1]) << endl;
        }
        else if(i == N-1){
            cout << L[i] + R[i] + abs(A[N-2]) << endl;
        }
        else{
            cout << L[i] + R[i] + abs(A[i-1] - A[i+1]) << endl;
        }
    }
}

Measured memory_bytes: 2432
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

n = int(input())
a = list(map(int, input().split()))
ans = [0 for i in range(n)]
ball = []

for ii in range(n):
    #print(ans)
    i = n-ii
    if(a[i-1]!=ans[i-1]):
        d = make_divisors(i)
        ball.append(i)
        for k in d:
            ans[k-1] = 1-ans[k-1]
print(len(ball))
print(' '.join(map(str,ball)))

Measured memory_bytes: 85620
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
int main(){
  int N,Q;
  cin>>N>>Q;
  dsu D(N);
  while(Q--){
    int a,b,c;
    cin>>a>>b>>c;
    if(a)cout<<D.same(b,c)<<endl;
    else D.merge(b,c);
  }
}

Measured memory_bytes: 4064
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int k = saori.saori_hayami();
		int[] h = new int[n];
		for(int i = 0;i < n;i++){
			h[i] = saori.saori_hayami();
		}
		int[] dp = new int[n];
		dp[0] = 0;
		for(int i = 1;i < n;i++){
			for(int j = 0;j < k;j++){
				if(j < i){
					if(j == 0){
						dp[i] = Math.abs(h[i] - h[i-1-j]) + dp[i-1-j];
					} else {
						dp[i] = Math.min(Math.abs(h[i] - h[i-1-j]) + dp[i-1-j], dp[i]);
					}
				}
			}
		}
		System.out.println(dp[n-1]);
		
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 22412
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y){
  return y == 0 ? x : gcd(y, x % y);
}
ll lcg(ll x, ll y){
  return x * y / gcd(x, y);
}

int main(){
  ll n, k; cin >> n >> k;
  vector<ll> h(n); rep(i, n) cin >> h[i];
  
  //string ans = "Yes";
  //string ans = "No";
  //string ans = "YES";
  //string ans = "NO";
  ll ans = 0;
  rep(i, n) if (h[i] >= k) ans++;
  
  cout << ans << endl;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();

    sc.close();

    for (int i = N; i <= 999; i++) {

      if (i % 111 == 0) {
        System.out.println(i);
        break;
      }

    }

  }

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int tb1[26][26],tb2[26][26];
int main() {
  string s,t;
  cin >> s >> t;
  int n = sz(s);
  rep(i,n){
    int x = s[i]-'a';
    int y = t[i]-'a';
    tb1[x][y]=1;
    tb2[y][x]=1;
  }
  rep(i,26){
    int cnt1 = 0,cnt2=0;
    rep(j,26){
      cnt1+=tb1[i][j];
      cnt2+=tb2[i][j];
    }
    if(cnt1>1 || cnt2 > 1){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}

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

using namespace std;
typedef long long ll;

#define INF (long long)(10e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

set<string> st;

int main(void)
{
    int n;
    cin >> n;
    string s, os;
    bool f = true;
    cin >> os;
    st.insert(os);
    for(int i = 1; i < n; i++) {
        cin >> s;
        if(s[0] != os[os.size()-1]) {
            f = false;
        }
        st.insert(s);
        os = s;
    }
    cout << ((st.size() == n && f) ? "Yes" : "No" ) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mkp make_pair
#define con continue
#define pb push_back
#define pob pop_back
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
int main()
{
	ll a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	ll minu = (c-a)*60;
	minu-=b;
	minu+=d;
	minu-=e;
	cout<<minu<<endl;
	return 0;
 } 

Measured memory_bytes: 3624
/*
[nikkei2019-qual] C - Different Strokes
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 1e5;

int N;
pii AB[MAX_N];

ll solve() {
    sort(AB, AB + N,
         [](pii a, pii b) { return a.first + a.second > b.first + b.second; });

    ll ans = 0;
    for (int i = 0; i < N; i += 2) {
        ans += AB[i].first;
    }
    for (int i = 1; i < N; i += 2) {
        ans -= AB[i].second;
    }

    return ans;
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> AB[i].first >> AB[i].second;
    }

    cout << solve() << endl;

    return 0;
}


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
//typedef long long ll;
typedef long long ll;
//typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e15;
const ll MINF = -10e10;
//const int INF = INT_MAX / 100;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("~/Downloads/02.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;
const int mod = 1000000007;
const double PI = 3.14159265358979323846;

typedef pair<ll, ll> P;

void print_line(vector<vector<int>> &ans) {
    for (int i = 0; i < ans.size(); i++) {
        for (int y = 0; y < ans[i].size(); y++) {
            cout << ans[i][y];
        }
        cout << endl;
    }
}

int main() {

    ll n, k;
    cin >> n >> k;

    vector<ll> mods(k, 0);
    for (ll i = 1; i <= n; i++) {
        mods[i % k]++;
    }

    ll ans = 0;
    for (ll i = 0; i < k; i++) {
        if ((i + i) % k == 0) {
            ans += mods[i] * mods[i] * mods[i];
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 1792
/*AMETHYSTS*/
#pragma comment(linker, "/STACK:1000000000")
#include <cstdio>
#include <iostream>
#include <ctime>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <set>
#include <map>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <bitset>
#include <deque>
#include <stack>
#include <climits>
#include <string>
#include <queue>
#include <memory.h>
#include <unordered_map>
#include <random>

#define ll long long
#define ld double
#define pii pair <int, int>
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define mp make_pair
#define ui unsigned ll
#define pll pair <ll, ll>

using namespace std;

const int maxn = (int)2e5 + 10;
int n;

const int inf = (int)1e9;
int l[maxn];
int r[maxn];

bool cmp(int a, int b) {
	return l[a] < l[b];
}

int go(string a, string b) {
	int ans = inf;
	int last = -1;

	for (int i = n - 1; i >= 0; i--) {
		if (b[i] == '1') {
			last = i;
			break;
		}
	}

	int pre = -1;

	for (int i = 0; i < n; i++) {
		if (last == -1) {
			l[i] = inf;
			continue;
		}

		if (b[i] == '1') {
			pre = i;
		}

		if (pre != -1) {
			l[i] = i - pre;
		} else {
			l[i] = i + n - last;
		}
	}

	last = -1;

	for (int i = 0; i < n; i++) {
		if (b[i] == '1') {
			last = i;
			break;
		}
	}

	pre = -1;

	for (int i = n - 1; i >= 0; i--) {
		if (last == -1) {
			r[i] = inf;
			continue;
		}

		if (b[i] == '1') {
			pre = i;
		}

		if (pre != -1) {
			r[i] = pre - i;
		} else {
			r[i] = n - i + last;
		}
	}

	for (int ii = 0; ii < n; ii++) {
		int res = ii;

		int p = ii;

		vector <int> g;

		for (int i = 0; i < n; i++) {
			if (a[i] != b[p]) {
				res++;

				if (a[i] == '1' && r[i] > ii) {
					g.push_back(i);
				}
			}

			p++;

			if (p == n) {
				p = 0;
			}
		}

		sort(g.begin(), g.end(), cmp);

		vector <pii> z;
		z.resize(g.size());

		int sh = 0;

		for (int i = 0; i < z.size(); i++) {
			sh = max(sh, l[g[i]]);
			z[i].first = sh;
		}

		sh = 0;

		for (int i = (int)z.size() - 1; i >= 0; i--) {
			z[i].second = sh;
			sh = max(sh, r[g[i]] - ii);
		}

		for (int i = 0; i < (int)g.size(); i++) {
			sh = min(sh, z[i].first + z[i].second);
		}

		ans = min(ans, res + 2 * sh);
	}

	return ans;
}

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

	n = (int)a.size();

	int ans = go(a, b);

	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());

	ans = min(ans, go(a, b));

	if (ans == inf) {
		cout << -1 << endl;
	} else {
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 200000;

string s;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> s;
    
    if (s[0] == 'R' && s[0] == s[1] && s[1] == s[2])
        cout << 3;
    else if (s[1] == 'R' && (s[0] == 'R' || s[2] == 'R'))
        cout << 2;
    else
        cout << (s[0] == 'R' || s[1] == 'R' || s[2] == 'R');
    
    return 0;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

typedef pair<double, double> P;
P operator +(P a, P b) { return P(a._1+b._1, a._2+b._2); }
P operator -(P a, P b) { return P(a._1-b._1, a._2-b._2); }
P operator /(P a, double b) { return P(a._1/b, a._2/b); }
P operator *(P a, double b) { return P(a._1*b, a._2*b); }
double dist(P p1, P p2) { return hypot(p1._1-p2._1, p1._2-p2._2); }
P suisen(P p) { return P(p._2, -p._1); }
double abs(P p) { return sqrt(p._1*p._1+p._2*p._2); }
double det(P a, P b) { return a._1*b._2-a._2*b._1; }

P intersection(pair<P, P> a, pair<P, P> b) {
  double x = abs(det(b._2-b._1, a._1-b._1)),
         y = abs(det(b._2-b._1, a._2-b._1));
  return a._1 + (a._2-a._1)*(x/(x+y));
}

bool f(P p1, P p2, P p3, double R) {
  P yo1 = suisen((p2-p1)/abs(p2-p1))*R;
  P yo2 = suisen((p3-p2)/abs(p3-p2))*R;
  P yo3 = suisen((p1-p3)/abs(p1-p3))*R;
  pair<P, P> e1 = make_pair(p1 + yo1, p2 + yo1);
  pair<P, P> e2 = make_pair(p2 + yo2, p3 + yo2);
  pair<P, P> e3 = make_pair(p3 + yo3, p1 + yo3);
  P a = intersection(e1, e2),
    b = intersection(e2, e3),
    c = intersection(e3, e1);
  if (det(b-a, c-b) > 0) return false;
  if (max({abs(a-b), abs(a-c), abs(b-c)}) < 2*R) return false;
  return true;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  P p1, p2, p3;
  cin >> p1._1 >> p1._2 >> p2._1 >> p2._2 >> p3._1 >> p3._2;
  if (det(p2-p1, p3-p2) > 0) swap(p2, p3);
  assert(det(p2-p1, p3-p2) < 0);
  double lo = 0, hi = min({abs(p1-p2), abs(p1-p3), abs(p2-p3)}) / 2.0;
  rep(_, 100) {
    double R = (lo+hi)/2.0;
    if (f(p1, p2, p3, R)) lo = R;
    else hi = R;
  }
  cout << fixed << setprecision(20) << lo << "\n";
  return 0;
}


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

using namespace std;

/* Template file for Online Algorithmic Competitions */
/* Typedefs */
	/* Basic types */
	typedef long long ll;
	typedef unsigned long long ull;
	/* STL containers */
	typedef vector <int> vi;
	typedef vector <ll> vll;
	typedef pair <int,int> pii;
	typedef pair <ll,ll> pll;
	typedef vector < pii > vpii;
	typedef vector < pll > vpll;
/* Macros */
	/* Loops */
	#define fl(i,a,b) for(int i(a);i<(b);i++)
	#define rep(i,n) fl(i,0,n)
	#define rep1(i,n) fl(i,1,n)
	#define rfl(i,a,b) for(int i(a);i>=(b);i--)
	/* Algorithmic functions */
	#define srt(v) sort((v).begin(),(v).end())
	/* STL container methods */
	#define pb push_back
	#define mp make_pair
	/* String methods */
	#define slen(s) s.length()
	/* Shorthand notations */
	#define F first
	#define S second
	#define MOD 1000000007
	#define MAX 1000

int main(){

	
	int a, b; 

	cin >> a >> b;

	int sum[MAX];

	sum[0] = 0;
	
	rep1(i, 1000){
		sum[i] = sum[i - 1] + i;
		if(sum[i - 1] - a == sum[i] - b){
			cout << sum[i] - b;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
import sys
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
    
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return sorted([list(map(int, input().split())) for _ in range(n)])

def warshall_floyd(): # 全点対最短路問題O(N^3)
    n,w = inpm() #n:頂点数　w:辺の数
    d = [[10**10 for i in range(n)] for i in range(n)] 
    #d[u][v] : 辺uvのコスト(存在しないときはinf)
    xyz=[]
    for i in range(w):
        x,y,z = inpm()
        x -= 1
        y -= 1
        xyz.append((x,y,z))
        d[x][y] = z
        d[y][x] = z
    for i in range(n):
        d[i][i] = 0 #自身のところに行くコストは0
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return n,w,d,xyz

def main():
    n=inp()
    a=inplm(n)
    a.sort()
    n1 = 0
    n2 = 0
    minus = n//2

    for i in range(n):
        if i<minus-1:
            n1-=2*a[i]
        elif i==minus-1:
            n1-=(1+n%2)*a[i]
        elif i==minus:
            n1+=a[i]
        elif i==minus+1 and n%2==1:
            n1+=a[i]
        else:
            n1+=2*a[i]

    a.reverse()
    plus = n//2
    for i in range(n):
        if i<plus-1:
            n2+=2*a[i]
        elif i==plus-1:
            n2+=(1+n%2)*a[i]
        elif i==plus:
            n2-=a[i]
        elif i==plus+1 and n%2==1:
            n2-=a[i]
        else:
            n2-=2*a[i]

    print(max(n1,n2))

if __name__ == "__main__":
    main()

Measured memory_bytes: 45020
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int N;
  cin >> N;
  vector<ll> as(N + 1, 0);
  for(int i = 1; i <= N; ++i) {
    cin >> as[i];
  }
  ll S = accumulate(as.begin(), as.end(), 0LL);
  vector<ll> xs(N + 1, 0);
  ll ass = 0;
  for(int i = 2; i <= N; ++i) {
    if(i % 2 == 1)
      continue;
    ass += as[i];
  }
  xs[1] = S - 2 * ass;
  for(int i = 2; i <= N; ++i) {
    xs[i] = 2 * as[i - 1] - xs[i - 1];
  }
  for(int i = 1; i <= N; ++i) {
    cout << xs[i] << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 2944
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <time.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000001
#define mod 1000000009
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)

int main()
{
    int n,a,b;
    string s;
    cin >> n >> a >> b;
    cin >> s;
    int wincount = 0;
    int winoutcount = 0;
    for(int i = 0;i < n; i++){
        if(s[i] == 'c'){
            cout << "No" << endl;
            continue;
        }
        if(s[i] == 'a'){
            if(wincount < (a + b)){
                wincount++;
                cout << "Yes" << endl;
                continue;
            }else{
                cout << "No" << endl;
                continue;
            }
        }
        if(s[i] == 'b'){
            if(wincount < (a + b) && winoutcount < b){
                wincount++;
                winoutcount++;
                cout << "Yes" << endl;
                continue;
            }else{
                cout << "No" << endl;
                continue;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 896
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations

sys.setrecursionlimit(50000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, CN, D, C):
    # for d in D:
    #     error_print(d)
    # for c in C:
    #     error_print(c)

    T = [[], [], []]
    for i, r in enumerate(C):
        for j, c in enumerate(r):
            T[(i + j) % 3].append((i, j, c))
    TC = [[], [], []]
    for j, t in enumerate(T):
        for i in range(CN):
            s = 0
            for c in t:
                s += D[c[2] - 1][i - 1]
            TC[j].append(s)

    ans = sys.maxsize
    for i, j, k in permutations(range(CN), 3):
        ans = min(ans, sum([TC[0][i], TC[1][j], TC[2][k]]))

    return ans


def main():

    N, CN = read_int_n()
    D = [read_int_n() for _ in range(CN)]
    C = [read_int_n() for _ in range(N)]
    print(slv(N, CN, D, C))


if __name__ == '__main__':
    main()


Measured memory_bytes: 32672
package main

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

func main() {
	N, M := nextInt(), nextInt()
	a := make([]int, N)
	for i := 0; i < M; i++ {
		k := nextInt()
		for j := 0; j < k; j++ {
			s := nextInt()
			s--
			a[s] |= 1 << uint(i)
		}
	}

	var p int
	for i := 0; i < M; i++ {
		x := nextInt()
		p |= x << uint(i)
	}

	var ans int
	for s := 0; s < (1 << uint(N)); s++ {
		t := 0
		for i := 0; i < N; i++ {
			if s>>uint(i)&1 == 1 {
				t ^= a[i]
			}
		}

		if t == p {
			ans++
		}
	}

	fmt.Println(ans)
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextFloat() float64 {
	sc.Scan()
	f64, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}

	return f64
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func abs(x int) int {
	return int(math.Abs(float64(x)))
}

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

// ---------- Util.


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define lint long long
#define st first
#define nd second
#define MOD 998244353
using namespace std;

lint  fact[200020];
lint ifact[200020];


lint modpow(lint b, lint e) {
	lint ret = 1;
	for (int i = 1; i <= e; i *= 2, b = b * b % MOD)
		if (i & e) ret = ret * b % MOD;
	return ret;
}

lint modinv(lint a) {
	return modpow(a%MOD, MOD-2);
}

void pre(){
	fact[0] = 1;
	for(int i=1;i<=200010;i++){
		fact[i] = i*fact[i-1];
		fact[i] %= MOD;
	}
	ifact[200010] = modinv(fact[200010]);
	for(int i = 200009; i>=0 ;i--){
		ifact[i] = ((lint)(i+1)*ifact[i+1])%MOD;
	}
}



lint ncr(lint n, lint k){
	if(k<0 || k>n) return 0;
	lint x = (fact[n]*ifact[k])%MOD;
	return (x*ifact[n-k])%MOD;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	pre();
	lint n,m,k;
	cin>>n>>m>>k;
	lint ans = 0;
	for(int i=0;i<=k;i++){
		lint aux = (m*modpow(m-1,n-1-i))%MOD;
		aux = (aux*ncr(n-1,i))%MOD;
		ans = (ans + aux)%MOD;
	}
	if(ans < 0) ans += MOD;
	cout<<ans<<"\n";


	return 0;	
}



Measured memory_bytes: 6780
from operator import mul
from functools import reduce
import bisect

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N = int(input())
A = sorted(list(map(int,input().split())))
maxA = max(A)
A.remove(maxA)
idx = bisect.bisect(A,maxA//2)

if idx == len(A):
  print(maxA,A[-1])
elif idx == 0:
  print(maxA, idx)
else:
  if abs(maxA//2 - A[idx]) > abs(maxA//2 - A[idx-1]):
    print(maxA,A[idx-1])
  else:
    print(maxA,A[idx])

Measured memory_bytes: 62704
#一文字ずつアルファベットを読み込む
#変更するときに特定してi+3にしてずらす
#大文字アルファベット
#入力1行

alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'#alpha[数]
ans = []
n = input()
for i in n:
    p = alpha[alpha.index(i)-3]#alpha[nのiはalpha.index番と等しい]
    ans.append(p)
print(*ans, sep = "")


Measured memory_bytes: 5716
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

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

    //問題の読込
    vector<int> A(N);
    rep(i, M) {
        cin >> A.at(i);
        sum = sum + A.at(i);
    }
    if (sum > N) {
        cout << "-1";
    }
    else {
        cout << N - sum;
    }
}



Measured memory_bytes: 6748
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007


int main() {
  
  long long N;
  cin >> N;

  long long ans = 0;
  for(int i = 1;i <= N;i++) {
    long long num = N/i;
    ans += num*(num+1)/2 * i;
  }

  cout << ans << endl;

}


Measured memory_bytes: 3596
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(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: 21716
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

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

  int n = s.length();
  string sr = s;
  reverse(sr.begin(),sr.end());
  string s1 = s.substr(0, (n-1)/2);
  string s2 = s.substr((n+3)/2-1);
  string s1r = s1;
  string s2r = s2;

  reverse(s1r.begin(),s1r.end());
  reverse(s2r.begin(),s2r.end());

  if(s == sr && s1r == s1 && s2r == s2) cout << "Yes" << endl;
  else cout << "No" << endl;

}


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;

public class Main
{

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		HashSet<Character> set = new HashSet<>();
		for(int i = 0; i < k; i++)
		{
			char c = sc.next().charAt(0);
			set.add(c);
		}
		
		while(true)
		{
			
			String s = Integer.toString(n);
			boolean gud = true;
			for(char c : set)
			{
				int in = s.indexOf(c);
				if(in != -1)
				{
					int or = s.length()-(in+1);
					int mul = 1;
					for(int x = 0; x < or; x++)
						mul*=10;
					n = n + mul;
					n -= n%mul;
					gud = false;
					break;
				}
			}
			if(gud)
			{
				System.out.println(n);
				return;
			}
		}

	}

}


Measured memory_bytes: 21844
import math

def submit():
    n_max = 10**5

    # n_maxまでの素数を数える
    is_prime = {x: True for x in range(1, n_max + 1)}
    is_prime[1] = False
    for x in range(2, math.ceil(math.sqrt(n_max)) + 1):
        if is_prime[x]:
            y = 2 * x
            while y <= n_max:
                is_prime[y] = False
                y += x

    like2017 = {}
    for x in range(1, n_max + 1):
        like2017[x] = x % 2 and is_prime[x] and is_prime[(x + 1) // 2]

    # xまでの2017に似た数の個数を覚えておく
    accumulation = {0: 0}
    for x in range(1, n_max + 1):
        accumulation[x] = accumulation[x - 1] + like2017[x]
    
    # クエリを処理する
    q = int(input())
    queries = []
    for _ in range(q):
        queries.append(list(map(int, input().split())))
        
    for l, r in queries:
        print(accumulation[r] - accumulation[l - 1])
    
submit()
                


Measured memory_bytes: 89828
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();
		int x=sc.nextInt();

		if(a<=x && x<=a+b) System.out.println("YES");
		else System.out.println("NO");

	} 
}

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

int main()
{
	int a, b;
  	cin >> a >> b;
  if (a < 6)	cout << 0 << endl;
  else if (a > 12) cout << b << endl;
  else cout << b/2 << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <math.h>
#define lli long long int
#include <limits.h>
#include <fstream>

using namespace std;

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli i,j,tt=1;
    //cin>>tt;
    while(tt--)
    {
        lli n;
        cin>>n;
        cout<<(1000-n%1000)%1000<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3568
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Arrays;
import java.util.Collections;
import java.util.*;
import java.math.BigInteger;
class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    String c = scan.next();
    String[] split = c.split("");
    int indicate = N - 1;
    int count = 0;
    for (int i = 0;i < indicate;i++) {
      if (split[i].equals("W")) {
        while(split[indicate].equals("W")){
          indicate -= 1;  
          if (indicate < i) {
            System.out.println(count);
            return;
          }
        }
        split[i] = "R";
        split[indicate] = "W";
        count += 1;
      }
    }
    System.out.println(count);
  }
}

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

int main() {
  int N, x;
  cin >> N >> x;
  
  vector<int> needs(N, 0);
    
  for (int i = 0; i < N; i++) cin >> needs.at(i);
  
  sort(needs.begin(), needs.end());
  
  int answer = 0;
  
  for (int i = 0; i < N; i++) {
    if (x < needs.at(i)) break;
    
    if (i < N - 1) {
      x -= needs.at(i);
      answer++;
    } else if (x == needs.at(i)) {
      answer++;
    } 
  }
  
  cout << answer << endl;
  
  return 0;
}

Measured memory_bytes: 256
let () = Scanf.scanf "%d\n" @@ fun n ->
  let ss = Array.to_list @@ Array.init n @@ fun _ -> Scanf.scanf "%s\n" @@ fun s -> s in
  Scanf.scanf "%d\n" @@ fun m ->
  let ts = Array.to_list @@ Array.init m @@ fun _ -> Scanf.scanf "%s\n" @@ fun t -> t in
  List.map (fun s ->
    List.length (List.filter (( = ) s) ss) - List.length (List.filter (( = ) s) ts)) ss
  |> List.fold_left max 0
  |> Printf.printf "%d\n"

Measured memory_bytes: 640
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    n = int(readline())
    act = []
    for _ in range(n):
        a, b, c = map(int, readline().split())
        act.append((a, b, c))

    #dp[i][j]:= 太郎くんがi日目に活動jを行って得る幸福度の総和の最大値

    dp = [[0, 0, 0] for _ in range(n)]
    for j in range(3):
        dp[0][j] = act[0][j]

    for i in range(n-1):
        dp[i+1][0] = max(dp[i][1]+act[i+1][0], dp[i][2]+act[i+1][0])
        dp[i+1][1] = max(dp[i][0]+act[i+1][1], dp[i][2]+act[i+1][1]) 
        dp[i+1][2] = max(dp[i][0]+act[i+1][2], dp[i][1]+act[i+1][2])

    print(max(dp[n-1]))
if __name__ == '__main__':
    main()


Measured memory_bytes: 70236