akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;} 
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N, K;
        string S;
        cin >> N >> S >> K;

        char al = S[K-1];

        string ans;
        rep(i, 0, N) {
                if (S[i] != al) {
                        ans += '*';
                } else {
                        ans += S[i];
                }
        }

        cout << ans << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
int dp[1100000][2];
const int INF = 1001001001;
int main()
{
    string s;
    cin >> s ;
    reverse(s.begin(),s.end());
    s += '0';
    int n = s.size();
    rep(i,n+1)rep(j,2) dp[i][j] = INF;
    dp[0][0] = 0;
    rep(i,n)rep(j,2){
        int d = s[i] - '0';
        d += j;
        rep(a,10){
            int ni = i+1,nj = 0;
            int b = a -d;
            if(b < 0){
                b += 10;
                nj = 1;

            }
            dp[ni][nj] = min(dp[ni][nj],dp[i][j] + a+ b);
        }
    }
    int ans = dp[n][0];
    cout << ans << endl;
    return 0;
}

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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

vector<int> l;
bool is_DAG = true;

void tpsort(vector<vector<int>>& edges, vector<int>& used, int i) {
    if (used[i] == 0) {
        is_DAG = false;
        return;
    } else if (used[i] < 0) {
        used[i] = 0;
        for (int& j : edges[i]) tpsort(edges,used,j);
        used[i] = 1;
        l.push_back(i);
    }
}

int main() {
    int n;
    cin >> n;
    vector<vector<int>> edges(n*1000);
    vector<int> used(n*1000,-1);
    vector<int> a(n-1),dp(n*1000,0);
    for (int i = 0;i < n;++i) {
        for (int j = 0;j < n-1;++j) scanf("%d",&a[j]),a[j]--;
        for (int j = 0;j < n-2;++j) edges[max(i,a[j])*1000+min(i,a[j])].push_back(max(i,a[j+1])*1000+min(i,a[j+1]));
    }
    for (int i = 0;i < n;++i) for (int j = i+1;j < n;++j) if (used[j*1000+i] < 0) tpsort(edges,used,j*1000+i);
    reverse(l.begin(),l.end());
    if (is_DAG) {
        for (int& i : l) for (int& j : edges[i]) dp[j] = max(dp[j],dp[i]+1);
        cout << *max_element(dp.begin(),dp.end())+1 << endl;
    } else cout << -1 << endl;
    return 0;
}

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

# define pb push_back
# define fr first
# define sc second
# define mk make_pair

using namespace std;

const long long linf = 1e18 + 7;
const int inf = 1e9 + 7;
const int N = 1e5 + 5;

typedef long long ll;

int n, m;

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

      cout << (n - 1) * (m - 1) << endl;
}


Measured memory_bytes: 256
T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split())
B1,B2 = map(int,input().split())

C1 = (A1-B1)*T1
C2 = (A2-B2)*T2

if C1+C2==0:
    print('infinity')
elif C1*(C1+C2)>0:
    print(0)
else:
    if abs(C1)%abs(C1+C2)==0:
        print(abs(C1)//abs(C1+C2)*2)
    else:
        print(abs(C1)//abs(C1+C2)*2+1)

Measured memory_bytes: 39728
#include<iostream>
using namespace std;
int main() {
	int N, M;
	cin >> N >> M;
	int tp = 1;
	for (int i = 0; i < M; ++i) {
		tp *= 2;
	}
	cout << (long long)(1900 * M + (N - M) * 100)*tp << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long inf=1e10;
long long n, w, V=0, dp[100005], wi[105], vi[105];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie();
	cout.tie();
	cin >> n >> w;
	for(int i=1;i<=n;i++){
		cin >> wi[i] >> vi[i];
		V+=vi[i];
	}
	for(int i=0;i<=V;i++){
		dp[i]=inf;
	}
	dp[0]=0;
	for(int i=1;i<=n;i++){
		for(int j=V;j>=vi[i];j--){
			dp[j]=min(dp[j], dp[j-vi[i]]+wi[i]);
		}
	}
	for(int i=V;i>=0;i--){
		if(dp[i]<=w){
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 4611686018427387903;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

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

Measured memory_bytes: 3916
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;
    return 0;
}

Measured memory_bytes: 3592
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#define int long long
#define mod(int)(1000000007)
using namespace std;
char test[2134][2134];
int cnt[2134][2134], kari[2134][2134];
signed main() {
	int n, m, ans = 0; char a; cin >> n >> m;
	for (int h = 0; h < n; h++) {
		string s; cin >> s;
		for (int i = 0; i < m; i++) {
			test[h][i] = s[i];
		}
	}
	//横
	for (int h = 0; h < n; h++) {
		int b = 1;
		for (int i = 0; i < m; i++) {
			if (test[h][i] == '.') {
				cnt[h][i] = b; b++;
			}
			else { b = 1; }
		}
	}
	for (int h = 0; h < n; h++) {
		int b = 0;
		for (int i = m - 1; i >= 0; i--) {
			if (test[h][i] == '.') {
				b = max(cnt[h][i], b);
				cnt[h][i] = b;
			}
			else { b = 0; }
		}
	}
	//縦
	for (int h = 0; h < m; h++) {
		int b = 1;
		for (int i = 0; i < n; i++) {
			if (test[i][h] == '.') {
				kari[i][h] = b; b++;
			}
			else { b = 1; }
		}
	}
	for (int h = 0; h < m; h++) {
		int b = 0;
		for (int i = n - 1; i >= 0; i--) {
			if (test[i][h] == '.') {
				b = max(kari[i][h], b);
				kari[i][h] = b;
			}
			else { b = 0; }
		}
	}
	for (int h = 0; h < n; h++) {
		for(int i = 0; i < m; i++) {
			ans = max(ans, cnt[h][i] + kari[h][i] - 1);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 75520
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int h = Integer.parseInt(sa[0]);
		int w = Integer.parseInt(sa[1]);
		sa = br.readLine().split(" ");
		int ch = Integer.parseInt(sa[0]) - 1;
		int cw = Integer.parseInt(sa[1]) - 1;
		sa = br.readLine().split(" ");
		int dh = Integer.parseInt(sa[0]) - 1;
		int dw = Integer.parseInt(sa[1]) - 1;
		char[][] s = new char[h][w];
		for (int i = 0; i < h; i++) {
			s[i] = br.readLine().toCharArray();
		}
		br.close();

		int[][] d = new int[h][w];
		for (int i = 0; i < h; i++) {
			Arrays.fill(d[i], Integer.MAX_VALUE);
		}

		Deque<Integer> que = new ArrayDeque<>();
		que.add(ch * w + cw);
		d[ch][cw] = 0;
		while (!que.isEmpty()) {
			int cur = que.poll();
			int cx = cur / w;
			int cy = cur % w;
			for (int nx = cx - 2; nx <= cx + 2; nx++) {
				if (nx < 0 || h <= nx) {
					continue;
				}
				for (int ny = cy - 2; ny <= cy + 2; ny++) {
					if (ny < 0 || w <= ny) {
						continue;
					}
					if (s[nx][ny] == '#') {
						continue;
					}
					if (d[nx][ny] > d[cx][cy] &&
							Math.abs(nx - cx) + Math.abs(ny - cy) <= 1) {
						d[nx][ny] = d[cx][cy];
						que.addFirst(nx * w + ny);
					} else if (d[nx][ny] > d[cx][cy] + 1) {
						d[nx][ny] = d[cx][cy] + 1;
						que.addLast(nx * w + ny);
					}
				}
			}
		}
		if (d[dh][dw] == Integer.MAX_VALUE) {
			System.out.println(-1);
		} else {
			System.out.println(d[dh][dw]);
		}
	}
}


Measured memory_bytes: 57616
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")

using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)

#define ynmes(a) (a) ? mes("Yes") : mes("No")
#define YNmes(a) (a) ? mes("YES") : mes("NO")
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
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; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

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

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

ll nlcm(vector<ll> numbers) {
    ll res;
    res = numbers[0];
    for (ll i = 1; i < (ll)numbers.size(); i++) {
        res = lcm(res, numbers[i]);
    }
    return res;
}


signed main() {
    ll x;
    cin >> x;
    
    ll r = 0;
    
    r += (x/11 +1) *2;
    if (x % 11 == 0) r--;
    if (x > 0 && x % 11 <= 6) r--;
    
    mes(r);
    
    
    
}


Measured memory_bytes: 3632
#include<iostream>

int main(){
	std::string o, e;
	std::cin >> o >> e;

	for(int i = 0; i < o.length() + e.length(); i++){
		if(i % 2 == 0)std::cout << o[i / 2];
		else std::cout << e[i / 2];
	}
	std::cout << std::endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#define pi 3.14159265358
int main(){
  double x,y,R=90;
  int d,r;
  while(1){
    scanf("%d,%d",&d,&r);
    if(d==0 && r==0) break;
    x+=d*cos(R/180.0*pi);
    y+=d*sin(R/180.0*pi);
    R+=r;
    // printf("%lf %lf\n",cos(R/180.0*pi),sin(R/180.0*pi));
    // printf("%d %d\n",(int)x,(int)y);
  }
  printf("%d\n%d\n",(int)-x,(int)y);
  return 0;
}

Measured memory_bytes: 600
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  if (a > 8 || b > 8)
    cout << ":(" << endl;
  else
    cout << "Yay!" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	static int dp[] ,N ,M;
	static List<ArrayList<Integer>> G; 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt(); M = sc.nextInt();
		G = new ArrayList<ArrayList<Integer>>();
		for(int i=0;i<N;i++)G.add(new ArrayList<Integer>());
		for(int i=0;i<M;i++) {
			G.get(sc.nextInt()-1).add(sc.nextInt()-1);
		}
		sc.close();
		dp = new int[N];//nを頂点とする時の最長経路の長さ
		Arrays.fill(dp, -1);
		
		int ans = 0;
		//全頂点を始点にする場合を調べる。
		for(int i=0;i<N;i++) {
			ans = Math.max(ans,rec(i));
		}
		System.out.println(ans);
	}
	//　頂点vを始点とした時の最長経路の長さを返す。
	static int rec(int v) {
		if(dp[v]!=-1)return dp[v];
		int ret = 0;
		for(int to:G.get(v)) {
			ret = Math.max(ret, rec(to)+1); //DAGなので、次のノードを始点とした時の最長に、+1する事で自分始点の最長経路の長さが分かる。
		}
		return dp[v] = ret;
	}
}


Measured memory_bytes: 107616
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
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; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

//171B

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

    int p[n];
    rep(i,n) cin>>p[i];

    sort(p,p+n);
    int m=0;
    rep(i,k){
        m+=p[i];
    }
    cout<<m<<endl;
}

Measured memory_bytes: 3536
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#define ll long long
using namespace std;
int gcd(int a,int b)
{
    return (b>0)?gcd(b,a%b):a;
}
int main(){
	int n;
	cin>>n;
	int a[n];
	ll sum=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum=sum+a[i]-1;
	}
//	int ga=a[0];
//	int gb;
//	for(int i=1;i<n;i++){
//		gb=ga*a[i]/gcd(ga,a[i]);
//		ga=gb;
//	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
l = list(map(int,input().split()))

ans = 0
for i in range(n):
    for j in range(i+1,n):
        if l[i] != l[j]:
            #print(l[i],l[j])
            t = l[i] + l[j]
            for k in range(j+1,n):
                t_2 = l[j] + l[k]
                t_3 = l[i] + l[k]
                if l[k] != l[i] and l[k] != l[j] and l[k] < t and l[i] < t_2 and l[j] < t_3:
                    #print(i+1,j+1,k+1)
                    ans += 1
        else:
            continue

print(ans)


Measured memory_bytes: 73760
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();		
        int x = sc.nextInt();
		int t = sc.nextInt();
        int ans = 0;
        int count = 0;
        while(count<n){count+=x;
                       ans+=t;                            
                      }       
		System.out.println(ans);
	}
}

Measured memory_bytes: 35600
K, A, B = map(int, input().split())
# snuke can biscket add otr huyasu


bis = 1
ad = B - A
starts = 2
if (B - A) > 1:
    bis = A
    K -= (A - 1)
    if K <= 1:
        print(bis + 1)
        exit(0)
    mades = int(K / 2)
    if (K /2- mades) != 0:
        bis += 1
    bis += (mades * ad)
    print(bis)
    exit(0)
else:
    print(K + 1)
    exit(0)


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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  ll h;cin>>h;
  ll res=0;
  ll cnt=0;
  while(h>0){
    res += pow(2,cnt);
    h /= 2;
    cnt++;
  }
  cout<<res<<endl;

  
  return 0;
}


Measured memory_bytes: 256
n, q = map(int, input().split())
s = input()
li = []
a = 0
li.append(0)

for i in range(len(s)-1):
    if s[i] == "A" and s[i+1] == "C":
        a += 1
        li.append(a)
    else:
        li.append(a)

for _ in range(q):
    l, r = map(int, input().split())
    print(li[r-1] - li[l-1])


Measured memory_bytes: 6104
n, k = [int(i) for i in input().split()]

def calc(n, k, b):
    if k == 0:
        return n
    q, r = divmod(n, b)
    s = q * max(0, b-k) + max(0, r-k+1)
    return s


count = 0
b = 1
while b <= n:
    count += calc(n, k, b)
    b += 1

print(count)

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

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

  if(a <= b && b <= a+w || a <= b+w && b+w <= a+w){
    cout << 0 << endl;
  }else if(a+w < b){
    cout << b - (a+w)  << endl;
  }else{
    cout << a - (b+w) << endl;
  }

  return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll a, b, c;
    cin >> a >> b >> c;
    ll rem = a - b;
    cout << max(0LL, c - rem) << endl;
    return 0;
}


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

int main() {
  long n, z, m;
  cin >> n;
  z = 0;
  m = 0;
  while(true){
      z ++;
      if (z % 5 == 0 || z % 3 == 0){

      }else{
          m = m + z;
      }
      if (z >= n){
          break;
      }
  }
  cout << m;

  return 0;
}
//1000000000000000000

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

int log(int a){
  int log = 0;
  while(a%2==0){
    log++;
    a /= 2;
  }
  return log;
}

int main(){
    int N;
    int a[111111];
    int i;
    cin >> N;
    for(i=0;i<=N-1;i++)
      cin >> a[i];
    int ans = 0;
    for(i=0;i<=N-1;i++)
      ans += log(a[i]);
    cout << ans << endl;
}



Measured memory_bytes: 256
s = input()
MOD = 10**9+7
old_dp=[0]*13
new_dp=[0]*13
old_dp[0]=1

for c in s:
    for i in range(13):
        if c == '?':
            for d in range(10):
                new_dp[(10*i+d)%13] += old_dp[i]
        else:
            new_dp[(10*i+int(c))%13] += old_dp[i]
    
    old_dp = [x % MOD for x in new_dp]
    new_dp = [0]*13
print(old_dp[5])

Measured memory_bytes: 43116
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    from collections import defaultdict
    dd = defaultdict(int)
    
    N=I()
    M=0
    for i in range(N):
        s=input()
        dd[s]+=1
        M=max(M,dd[s])
        
        
    ans=[]
    for k,v in dd.items():
        if v==M:
            ans.append(k)
            
    ans.sort()
    for k in ans:
        print(k)
        
    

main()


Measured memory_bytes: 148256
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 #include<deque>
 #include<functional>
 #include<utility>
 
 using namespace std;

 int main()
 {
    int n;
    while(cin>>n)
    {
      long long int sum;
      sum=n*(n+1)/2+1; 
      cout<<sum<<endl;            
    }
   //while(1);
   return 0;
 }

 
  

Measured memory_bytes: 3008
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b)for(int i=(a);i<=(b);i++)
#define repR(i,n) for(int i=n;i>=0;i--)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<int>
#define COUT(x) cout<<(x)<<endl
#define MA map<int,int>
#define SE set<int>
#define PQ priority_queue
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, 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;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 50;

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	VE a(n); rep(i, n)cin >> a[i];
	set<int>st;
	rep(i, n)st.insert(a[i]);
	int ans = st.size();
	if (ans % 2 == 0)cout << ans - 1 << endl;
	else cout << ans << endl;
	return 0;
}

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

int gcd(int x, int y){
    if (x < y)
        swap(x, y);
    if (y == 0)
        return x;
    return gcd(x % y, y);
}

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N){
        cin >> A[i];
    }
    
    vector<int> L(N), R(N);
    rep(i, N - 1){
        L[i + 1] = gcd(L[i], A[i]);
    }
    
    for (int i = N - 1; i >= 1; i--){
        R[i - 1] = gcd(R[i], A[i]);
    }
    
    int Max = 1;
    rep(i, N){
        Max = max(Max, gcd(L[i], R[i]));
    }
    cout << Max << endl;

}


Measured memory_bytes: 1408
#include <stdio.h>
#include <vector>
#include <stack>
#include <functional>
#include <numeric>
#include <complex>
#include <queue>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <assert.h>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
 
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
#define pb(x) push_back(x)
#define FOR(k, n) for (int k = 0; k < n; k++)
#define FORN(k, s, n) for (int k = s; k < n; k++)
#define debug(x) printf("%s = %d\n", #x, x)
#define debug2(x, y) printf("%s = %d, %s = %d\n", #x, x, #y, y)
#define debug3(x, y, z) printf("%s = %d, %s = %d, %s = %d\n", #x, x, #y, y, #z, z)
#define debug4(x, y, z, t) printf("%s = %d, %s = %d, %s = %d, %s = %d\n", #x, x, #y, y, #z, z, #t, t)
 
#pragma warning(disable : 6031)
#pragma warning(disable : 4101)
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
typedef complex<double> cd;
 
const int INF = 1e9;
const long long LINF = 1e18;
const double PI = acos(-1);
 
// Solution

const int MAXN = 1005;

ll n, m, b, x, DP[MAXN][8 * MAXN];
pair<ll, ll> A[MAXN];

void compute_dp() {
    for (int i = 1; i < (1 << n); i++) {
        DP[0][i] = (A[0].Y | i) == A[0].Y ? A[0].X : INF;
    }

    for (int i = 1; i < m; i++) {
        for (int j = 1; j < (1 << n); j++) {
            DP[i][j] = min(DP[i - 1][j], A[i].X + DP[i - 1][j - (A[i].Y & j)]);
        }
    }
}

int main() {
    scanf("%lld%lld", &n, &m);

    for (int i = 0; i < m; i++) {
        scanf("%lld%lld", &A[i].X, &b);

        for (int j = 0; j < b; j++) {
            scanf("%lld", &x);
            A[i].Y += (1 << (x - 1));
        }
    }

    compute_dp();

    printf("%lld\n", (DP[m - 1][(1 << n) - 1] == INF ? -1 : DP[m - 1][(1 << n) - 1]));
    return 0;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(string N)
{
    cout << (N[0] == '7' || N[1] == '7' || N[2] == '7' ? YES : NO) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    string N;
    cin >> N;
    solve(N);
    return 0;
}


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

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

		mojiretu=br.readLine();
		int so=Integer.parseInt(mojiretu);
		mojiretu=br.readLine();
		moji=mojiretu.split(" ");
		int[] suji=new int[moji.length+2];
		suji[0]=0; suji[so]=0;
		for(int i=0; i<so; i++) {
			suji[i+1]=Integer.parseInt(moji[i]);
		}
		int nagasa=0;
		boolean tutuki=true;
		int max=0;


		for(int i=0; i<so+2; i++) {
			if(suji[i]==1 && tutuki==false) {
				tutuki=true;
				nagasa++;
			}

			else if(suji[i]==1 && tutuki==true) {
				nagasa++;
			}

			else if(suji[i]==0 && tutuki==true) {
				tutuki=false;
				if(max<nagasa) {
					max=nagasa;
				}
				nagasa=0;
			}

			else if(suji[i]==0 && tutuki==false) {
				//
			}
		}

		System.out.println(max+1);
	}
}


Measured memory_bytes: 24188
#include <iostream>

using namespace std;

int main(){
  int n;
  cin >> n;
  for( int i = 0; i < n; i++ ){
    int y, m, d;
    cin >> y >> m >> d;
    int ans = 0;
    while( 1 ){
      if( y == 1000 ){ break; }
      ans++;
      d++;
      if( y % 3 == 0 ){
        if( d == 21 ){
          d = 1;
          if( ++m == 11 ){
            y++;
            m = 1;
	  }
	}
      }else{
        if( m % 2 == 0 ){ // little
          if( d == 20 ){
            d = 1;
            if( ++m == 11 ){
              y++;
              m = 1;
	    }
	  }
	}else{
          if( d == 21 ){
            d = 1;
            m++;
	  }
	}
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 868
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#define FI(i, a, b) for (int i = (a); i <= (b); ++i)
#define FD(i, b, a) for (int i = (b); i >= (a); --i)
#define DEBUG(x) cerr << #x << ": " << (x) << endl;

int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  FI(i, 1, n) cin >> a[i - 1];
  sort(a.begin(), a.end());
  vector<PII> ans;
  if (a.front() >= 0) {
    int cur = a[0];
    for (int i = 1; i + 1 < n; i++) ans.emplace_back(cur, a[i]), cur -= a[i];
    ans.emplace_back(a.back(), cur);
    cur = a.back() - cur;
    cout << cur << endl;
  } else if (a.back() <= 0) {
    int cur = a.back();
    for (int i = 0; i + 1 < n; i++) ans.emplace_back(cur, a[i]), cur -= a[i];
    cout << cur << endl;
  } else {
    int cur = a[0];
    for (int i = 1; i + 1 < n; i++)
      if (a[i] >= 0) {
        ans.emplace_back(cur, a[i]);
        cur -= a[i];
      }
    a[0] = cur;
    cur = a.back();
    for (int i = 0; i + 1 < n; i++) {
      if (a[i] < 0) {
        ans.emplace_back(cur, a[i]);
        cur -= a[i];
      }
    }
    cout << cur << endl;
  }
  for (auto p : ans) cout << p.first << ' ' << p.second << '\n';
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int r[1001][1001];
signed main()
{
	int n,m,a,b;
	scanf("%d%d%d%d",&n,&m,&b,&a);
	if(a>n/2||b>m/2)
	{
		printf("-1");
		return 0;
	}
	for(int i=1;i<=a;i++)
		for(int j=1;j<=b;j++)
			r[i][j]=1;
	for(int i=a+1;i<=n;i++)
		for(int j=b+1;j<=m;j++)
			r[i][j]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
			printf("%d",r[i][j]);
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 5120
a, b = map(int, input().split())
yakusu_a = []
import math
for i in range(1, int(math.sqrt(a))+1):
  if a % i == 0:
    yakusu_a.append(i)
    if i != a//i:
      yakusu_a.append(a//i)

cd_list = []
for e in yakusu_a:
  if b % e == 0:
    cd_list.append(e)

cd_list = sorted(cd_list)

def furui(lst):
  data = lst
  ans = []
  while len(data) > 0:
    sentou = data[0]
    ans.append(sentou)
    data = [i for i in data if i % sentou != 0]
  return ans

print(len(furui(cd_list[1:]))+1)


Measured memory_bytes: 3388
#include <bits/stdc++.h>
using namespace std;
  
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 3005, MOD = 1e9 + 7;
int dp[N][N], a[N], tmp[N][N];

ll bp(ll a, ll p) {
	ll r = 1;
	while (p > 0) {
		if (p & 1) {
			r = r * a % MOD;
		}
		a = a * a % MOD;
		p >>= 1;
	}
	return r;
}

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

    int n, q;
    cin >> n >> q;

    for (int i = 0; i < n; i++) {
    	cin >> a[i];
    }

    for (int i = 0; i < n; i++) {
    	for (int j = 0; j < n; j++) {
    		dp[i][j] = (a[i] > a[j]);
    	}
    }

    ll inv_two = bp(2, MOD - 2);

    for (int i = 0; i < q; i++) {
    	int x, y;
    	cin >> x >> y;
    	x--, y--;

    	for (int j = 0; j < n; j++) {
    		tmp[x][j] = dp[x][j];
    		tmp[j][x] = dp[j][x];
    		tmp[y][j] = dp[y][j];
    		tmp[j][y] = dp[j][y];
    	}

    	for (int j = 0; j < n; j++) {
    		if (j != x && j != y) {
    			dp[x][j] = (tmp[x][j] + tmp[y][j]) * inv_two % MOD;
    			dp[j][x] = (tmp[j][x] + tmp[j][y]) * inv_two % MOD;
    		}
    	}

    	for (int j = 0; j < n; j++) {
    		if (j != x && j != y) {
    			dp[y][j] = (tmp[y][j] + tmp[x][j]) * inv_two % MOD;
    			dp[j][y] = (tmp[j][y] + tmp[j][x]) * inv_two % MOD;
    		}
    	}

    	dp[x][y] = (tmp[x][y] + tmp[y][x]) * inv_two % MOD;
    	dp[y][x] = (dp[y][x] + tmp[x][y]) * inv_two % MOD;
    }

    ll ans = 0;
    for (int i = 0; i < n; i++) {
    	for (int j = i + 1; j < n; j++) {
    		ans = (ans + dp[i][j]) % MOD;
    	}
    }

    ans = ans * bp(2, q) % MOD;

    cout << ans;

    return 0;
}

Measured memory_bytes: 70784
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18) + 1;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll n;
vector<ll> a;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    ll ans=0;
    for (int i = 0; i < n; i++)
    {
        ll temp;
        cin >> temp;
        a.push_back(temp);
    }
    ans=a[0]-1;
    ll maxs=2;
    for(int i=1;i<n;i++){
        ans+=(a[i]-1)/maxs;
        if((a[i]-1)/maxs==0){
            chmax(maxs,a[i]+1);
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 1400
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN3(n,m,x);
  vector<bool> A(n);
  REP(i,m){
    int tmp;
    cin >> tmp;
    A[tmp] = true;
  }
  FOR(i,x,n+1){
    if(A[i]) a++;
  }
  for(int i = x; i >= 0; i--){
    if(A[i]) b++;
  }
  OUT(min(a,b));
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main{
  public static void main(String[] args)throws Exception{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    try{
      String[] S = br.readLine().split(" ");
      int X = Integer.parseInt(S[0]);
      int Y = Integer.parseInt(S[1]);
      int A = Integer.parseInt(S[2]);
      int B = Integer.parseInt(S[3]);
      int C = Integer.parseInt(S[4]);
      
      int[] max = new int[X+Y];
      int[] red = new int[A];
      int[] green = new int[B];
      int[] less = new int[C];
      
      S = br.readLine().split(" ");
      for(int i = 0; i < A; i++){
          red[i] = Integer.parseInt(S[i]);
      }
      
      S = br.readLine().split(" ");
      for(int i = 0; i < B; i++){
          green[i] = Integer.parseInt(S[i]);
      }
      
      S = br.readLine().split(" ");
      for(int i = 0; i < C; i++){
          less[i] = Integer.parseInt(S[i]);
      }
      
      Arrays.sort(red);
      Arrays.sort(green);
      Arrays.sort(less);
      
      for(int i = 0; i < X; i++){
          max[i] = red[A-i-1];
      }
      for(int i = 0; i < Y; i++){
          max[i+X] = green[B-i-1];
      }
      
      Arrays.sort(max);
      for(int i = 0; i < X+Y && i < C; i++){
          if(max[i] < less[C-i-1]){
              max[i] = less[C-i-1];
          }
      }
      long ans = 0;
      for(int i = 0; i < X+Y; i++){
          ans += max[i];
      }
      System.out.println(ans);
    }catch(Exception e){
    }
  }
}

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

typedef pair<int,int> P;
typedef pair<int,P> PP;
typedef pair<int,PP> PPP;

const int INF = 1 << 28;

int main () {
    int n, m, l;
    while (cin >> n >> m >> l, n + m + l) {
        vector<vector<PP> > Path(n + 1);
        for (int i = 0; i < m; i++) {
            int a, b, d, e;
            cin >> a >> b >> d >> e;
            Path[a].push_back(PP(b, P(d, e)));
            Path[b].push_back(PP(a, P(d, e)));
        }

        priority_queue<PP, vector<PP>, greater<PP> > pq;
        vector<vector<int> > dp(n + 1, vector<int>(l + 1, INF));

        dp[1][l] = 0;
        pq.push(PP(0, P(l, 1)) );

        int res = INF;
        
        while (pq.size()) {
            PP pp = pq.top(); pq.pop();
            int attack = pp.first;
            int money = pp.second.first;
            int now = pp.second.second;

            if (dp[now][money] < attack) continue;

            for (int i = 0; i < Path[now].size(); i++) {
                int next = Path[now][i].first;
                int M = Path[now][i].second.first;
                int A = Path[now][i].second.second;
                if (money >= M && dp[next][money - M] > attack) {
                    dp[next][money - M] = attack;
                    pq.push(PP(attack, P(money - M, next)));
                    if (next == n) {
                        res = min(res, attack);
                    }
                }

                if (money >= 0 && dp[next][money] > attack + A) {
                    dp[next][money] = attack + A;
                    pq.push(PP(attack + A, P(money, next)));
                    if (next == n) {
                        res = min(res, attack + A);
                    }
                }
            }
        }

        cout << res << endl;
        
    }

    return 0;
}

Measured memory_bytes: 1716
N, K = list(map(int, input().split()))
if N > K:
    p = (N - 1)//K
    N_p = N - p*K
    N_q  = -(N_p - K)
    ans = min(N_p, N_q)
else:
    ans = min(N, K-N)
print(ans)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/
 
const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}


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

    string s,t; cin >> s >> t;
    map<char, int> mps;
    for(int i=0; i<s.size(); ++i) ++mps[s[i]];

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

    vector<ll> pos[30];
    for(int i=0; i<s.size(); ++i){
        pos[s[i]-'a'].push_back(i+1);
    }

    ll slen = s.length();
    ll ans = 0;
    ll now = 1;
    for(int i=0; i<t.size(); ++i){
        int tc = t[i]-'a';
        auto itr = lower_bound(pos[tc].begin(), pos[tc].end(), now);
        if(itr != pos[tc].end()){
            now = *itr;
        }
        else{
            ans += slen;
            now = 1;
            auto itr = lower_bound(pos[tc].begin(), pos[tc].end(), now);
            now = *itr;
        }
        
        if(i == t.size()-1){
            cout << ans+now << endl;
            return 0;
        }
        ++now;
        if(now > slen){
            ans += slen;
            now = 1;
        }
    }



    
    return 0;
}



Measured memory_bytes: 1736
#include <stdio.h>
#include <stdlib.h>


struct Node{
  int key;
  struct Node *right,*parent,*left;
};

void insert(int);
struct Node inorder(struct Node *);
struct Node preorder(struct Node *);
struct Node * find(struct Node *,int);
void delete(struct Node *);
struct Node * getPoint(struct Node *);
struct Node * getmin(struct Node *);

struct Node *root, *NIL;


int main(){
  int n=0;
  int i=0;
  int number=0;
  char word[6];
  char space;
  int print_flag=0;
  struct Node *f;
  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf("%s",word);

    if(word[0]=='i')
      {
	scanf("%d%c",&number,&space);
	insert(number);
      }

    else if(word[0]=='p')
      {
	print_flag=1;
      }

    else if(word[0]=='f')
      {
	scanf("%d",&number);
	f=find(root,number);
	if(f != NIL) printf("yes\n");
	else if(f==NIL) printf("no\n");
	f=NIL;
      }

    else if(word[0]=='d')
      {
	scanf("%d",&number);
	delete(find(root,number));
      }

    if(print_flag==1){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
      print_flag=0;
    }

    print_flag=0;
  }

  return 0;
}

void insert(int number){
  struct Node *y=NIL;
  struct Node *x=root;
  struct Node *z;

  z=(struct Node *)malloc(sizeof(struct Node));
  z->key=number;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL){
    y=x;
    if( z->key < x->key ) x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }
  else{
    if( z->key < y->key){
      y->left=z;
    }
    else{
      y->right=z;
    }
  }
}

struct Node inorder(struct Node *a){
  if(a==NIL)return;
  inorder(a->left);
  printf(" %d",a->key);
  inorder(a->right);
}

struct Node preorder(struct Node *a){
  if(a==NIL)return;
  printf(" %d",a->key);
  preorder(a->left);
  preorder(a->right);
}

struct Node * find(struct Node *a, int number){
  while( a != NIL && number != a->key)
    {
      if(number < a->key) a=a->left;
      else a=a->right;
    }
  return a;
}

void delete(struct Node *a){
  struct Node *b;
  struct Node *c;
  if(a->left==NIL || a->right==NIL) b=a;

  else b=getPoint(a);

  if(b->left!=NIL) c=b->left;
  else c=b->right;

  if(c!=NIL) c->parent=b->parent;

  if(b->parent==NIL) root=c->parent;

  else if(b==b->parent->left) b->parent->left=c;
  else b->parent->right=c;

  if(b!=a) a->key=b->key;
}

struct Node * getPoint(struct Node *a){
  struct Node *b;
  if(a->right != NIL) return getmin(a->right);

  b=a->parent;
  while(b!=NIL && a==b->right){
    a=b;
    b=b->parent;
  }
  return b;
}

struct Node * getmin(struct Node *a){
  while(a->left != NIL) a=a->left;
  return a;
}



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

const int MAX_N=100000;
int n,zero,two,five,tmp;

int main(){
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> tmp;
		if(tmp%4==0) five++;
		else if(tmp%2==0) two++;
		else zero++;
	}
	
	if(five>zero){
		cout << "Yes" << endl;
	}else if(five==zero){
		cout << "Yes" << endl;
	}else if(zero-1==five){	
		if(two)	cout << "No" << endl;
		else cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cmath>
int dp[100001]={0};
using namespace std;
int main(){
  int i,j,N,k,Min,roku,kyu;
  scanf("%d",&N);
  dp[0] = 0;
  for(i=1;i<=N;i++){
    roku = 1;kyu=1;
    Min = 99999999;
    while(i-roku>=0){
      Min = min(dp[i-roku],Min);
      roku*=6;
    }
    while(i-kyu>=0){
      Min = min(dp[i-kyu],Min);
      kyu*=9;
    }
    dp[i] = Min + 1;
  }
  printf("%d\n",dp[N]);
  
  return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
	int H, W = 0; int s=0; int m = 1000000; int a[26][26] = { 0 };
	cin >> H >> W;
	for (int i = 1; i < H+1;  i++) {
		for (int j = 1; j < W+1;  j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 1; i < H + 1; i++) {
		for (int j = 1; j < W + 1; j++) {
			for (int k = 1; k < H + 1; k++) {
				for (int l = 1; l < W + 1; l++) {
					s += a[k][l]*min(abs(i-k), abs(j-l));
				}
			}
			if (s < m)m = s;
			s = 0;
		}
	}
    cout <<m<<endl; 
}


Measured memory_bytes: 3140
#include<map>
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
const int N=200005;
ll load[N];
map<ll,ll>M;
int main()
{
	ll n,k,g=1ll,l=0;
	cin>>n>>k;
	for(int i=1;i<=n;++i)  cin>>load[i];
	while(l<=n)
	{
		if(M.count(g)==0)  M[g]=l;
		else
			break;
		g=load[g];
		++l;
	}
	ll len1=M[g];
	ll len2=l-M[g];
	if(k<=len1)
	{
		ll ans=1;
		while(k--)  ans=load[ans];
		cout<<ans;
		return 0;
	}
	k=(k-len1)%len2;
	ll ans=g;
	for(int i=1;i<=k;++i) ans=load[ans];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 17424
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())|	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import collections
def inpl(): return list(map(int, input().split()))

#### START
n = int(input())
S = [input() for i in range(n)]

c = collections.Counter(S[0])

for s in S[1:]:
  for cs in c.keys():
    c[cs] = min(s.count(cs), c[cs])

ans = [ k*v for k, v in c.items() if len(k*v) != 0]
print(*sorted(ans), sep="")

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)


int main() {
  
  int n,m;
  cin >> n  >> m ;
  int  long long ans = 0;
  vector<pair<int ,int >> v;
  
  for(int i=0;i<n;i++){
    int  long long x ,y ;
    cin >> x >> y;
    v.push_back(make_pair(x,y));  
  }
  
  sort(all(v));
  for(int i=0;i<n;i++){
    int long long  x ,y ;
    tie(x,y) = v.at(i);
    
   // cout << "x:" << x << " y:" << y << " m:" << m << endl; 
    
     if(0<m && m<=y){
      ans += x*m;
      m = 0;
     
    }
     
    if(0<m && y<=m){
      m-=y;
      ans += x*y;
    }
  }
  
  
  cout << ans ;

}


Measured memory_bytes: 1400
import sys
def main():
    # 人数N,おかし種類K
    num_list = list(map(int, input().split()))
    N = num_list[0]
    K = num_list[1]

    # 全員登録したリストを用意しておく
    list1 = [int(s) for s in range(1,N+1,1)]

    for _ in range(K):
        # おかしiを持ってる人数
        d = int(input())
        # おかしiを持ってる人リスト
        listA = list(map(int, input().split()))

        for i in listA:
            # お菓子持ってる人を見つけたら除去
            if i in list1: list1.remove(i)

    print(len(list1))

main()

Measured memory_bytes: 9228
def main():
    nxt = [0] * 5
    for i in range(3):
        a, b = map(int, input().split())
        nxt[a] += 1
        nxt[b] += 1
    edge = 0
    for i in range(1, 5):
        if nxt[i] % 2 == 1:
            edge += 1
    if edge == 2:
        print("YES")
    else:
        print("NO")


if __name__ == "__main__":
    main()


Measured memory_bytes: 38256