akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author MaxHeap
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AmbDoc solver = new AmbDoc();
        solver.solve(1, in, out);
        out.close();
    }

    static class AmbDoc {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            char[] s = in.next().toCharArray();
            char[] t = in.next().toCharArray();
            int pos = -1;
            for (int i = 0; i < s.length; i++) {
                if (canPlace(s, t, i)) {
                    pos = i;
                }
            }
            if (pos == -1) {
                out.println("UNRESTORABLE");
            } else {
                place(s, t, pos);
                for (int i = 0; i < s.length; i++) if (s[i] == '?') s[i] = 'a';
                out.println(new String(s));
            }
        }

        private boolean canPlace(char[] s, char[] t, int pt) {
            if (s.length - pt < t.length) return false;
            for (int i = pt, j = 0; j < t.length; j++, i++) {
                if (s[i] != '?' && s[i] != t[j]) return false;
            }
            return true;
        }

        private void place(char[] s, char[] t, int pt) {
            for (int i = pt, j = 0; j < t.length; j++, i++) {
                s[i] = t[j];
            }
        }

    }

    static class FastReader {
        BufferedReader reader;
        StringTokenizer st;

        public FastReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

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

    }
}



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

int main(void)
{
	int x[5];
	
	for(int i = 0; i < 5; i++)
	{
		cin >> x[i];
	}
	
	for(int i = 0; i < 5; i++)
	{
		cin >> x[i];
		if(x[i] == 0)
		{
			cout << (i + 1) << endl;
			break;
		}
	}
	return 0;
}


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

int main() {
  int N,M;
  cin>>N>>M;
  vector<int> city(N),road(2*M);
  
  for(int i;i<2*M;i++){
    cin>>road.at(i);
  }
  
  for(int i;i<2*M;i++){
    city.at(road.at(i)-1)+=1;
  }
  
  for(int i;i<N;i++){
    cout<<city.at(i)<<endl;
  } 
}

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

int main(){
  int A, B, C, D;
  cin >> A>> B>> C>>D;
  
  if((A+B)>(C+D))cout <<"Left";
  else if((A+B)<(C+D))cout << "Right";
  else cout<< "Balanced";
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=998244353;
const int siz=1e5;
const long inf=1e9;
int main(){
	int N; cin>>N;
	int A[N+1],B[N+1]; A[0] = B[N] = 0;
	rep(i,0,N) cin>>A[i+1];
	rep(i,0,N) cin>>B[i];
	rep(i,0,N) A[i+1] += A[i];
	for(int i = N; i > 0; i--) B[i-1] += B[i];
	int ans = 0;
	rep(i,0,N) ans = max(ans, A[i+1] + B[i]);
	cout<<ans<<endl;
}

Measured memory_bytes: 256
def eratosthenes(n):
    l = [i for i in range(2, n + 1)]
    for i in range(2, int(n ** 0.5) + 1):
        l = [j for j in l if j % i != 0 or i == j]
    return l

x = int(input())
l = eratosthenes(2 * (10 ** 5))
for i in l:
    if x <= i:
        print(i)
        exit()

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


int main() {
    int d,g;
    cin >> d >> g;
    vector<int> p(d),c(d);
    rep(i,d) cin >> p[i] >> c[i];

    int ans = 100000000;
    
    for (int bit=0; bit < (1<<d); bit++) {
        int sum = 0;
        int num = 0;
        for (int i=0; i < d; i++) {
            if(bit & (1<<i)) {
                sum += c[i] + (i+1)*100*p[i];
                num += p[i];
            }
        }
        // cout << sum << endl;

        for (int i=d; i > 0; i--) {
            if (sum >= g) break;
            if(!(bit & (1<<(i-1)))) {
                for(int j=0; j<p[i-1]; j++) {
                    sum += i*100;
                    num += 1;
                    // cout << sum << endl;
                    if (sum >= g) break;
                }
            }
        }
        // cout << num << endl;
        // cout << "***" << endl;

        if (num < ans) ans = num;

    }

    cout << ans << endl;




    return 0;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws Exception {
    try (final var stdin = new InputStreamReader(System.in);
         final var br = new BufferedReader(stdin)) {
      final var s = br.readLine();
      if (s.equals("RRR")) {
        System.out.println(3);
      } else if (s.contains("RR")) {
        System.out.println(2);
      } else if (s.contains("R")) {
        System.out.println(1);
      } else {
        System.out.println(0);
      }
    }
  }
}


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


int main(){
    int n,k;
    cin >> n >> k;
    vector<int> l(n);
    for(int i=0;i<n;i++){
        cin >> l[i];
    }
    sort(l.begin(),l.end(),greater<int>());
    
    int ans=0;
    for(int i=0;i<k;i++){

        ans+=l[i];
    }
    cout << ans << endl;
    return 0;
    
}

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

typedef long long ll;
const ll mo = 998244353;
const int maxn = 4096;

int n, s, a[maxn];
ll ans, dp[maxn];

int main() {
    scanf("%d%d", &n, &s);
    for(int i = 0; i < n; ++i)
        scanf("%d", a + i);
    dp[0] = 1;
    dp[a[0]] = 1;
    ans = dp[s];
    for(int i = 1; i < n; ++i) {
        for(int j = s; j >= a[i]; --j)
            dp[j] = (dp[j] + dp[j - a[i]]) % mo;
        dp[0] = (dp[0] + 1) % mo;
        dp[a[i]] = (dp[a[i]] + 1) % mo;
        ans = (ans + dp[s]) % mo;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 256
def main():
	while True:
		n,r=map(int,input().split())
		if n==0 and r==0:
			break
		ls=list(range(n,0,-1))
		for i in range(r):
			p,c=map(int,input().split())
			p-=1
			tmp=ls[p:p+c]
			del ls[p:p+c]
			ls=tmp+ls
		print(ls[0])


if __name__=="__main__":
	main()



Measured memory_bytes: 5616
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  int H[N];
  REP(i,N)cin>>H[i];
  int ans=0;
  int temp=0;
  FOR(i,1,N){
    if(H[i]<=H[i-1]){
      temp++;
    }else{
      ans=max(ans,temp);
      temp=0;
    }
  }
  ans=max(ans,temp);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 640
/*
	Created by Faisal Ahmed
*/

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef long double ld;

int arr1[10], arr2[10], n, cnt, x, y;

void display(int a[], int n) 
{ 
	cnt++;
	bool flag = true;
    for (int i = 0; i < n; i++) { 
         if(a[i] != arr1[i]){
         	flag = false;
         	break;
		 }
    } 
    if(flag){
    	x = cnt;
	}
	
	flag = true;
    for (int i = 0; i < n; i++) { 
         if(a[i] != arr2[i]){
         	flag = false;
         	break;
		 }
    }
	
	if(flag){
    	y = cnt;
	}
	 
} 
  
// Function to find the permutations 
void findPermutations(int a[], int n) 
{ 
  
    // Sort the given array 
    sort(a, a + n); 
  
    // Find all possible permutations 
  //  cout << "Possible permutations are:\n"; 
    do { 
        display(a, n); 
    } while (next_permutation(a, a + n)); 
} 

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(NULL);
	
	cin >> n;
	
	for(int i = 0; i < n; i++){
		cin >> arr1[i];
	}
	for(int i = 0; i < n; i++){
		cin >> arr2[i];
	}
	
	int a[10];
	for(int i = 0; i < n; i++){
		a[i] = i + 1;
	}
	
	findPermutations(a, n);
	
	cout << abs(x - y) << endl;
	
	return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<stack>

using namespace std;

int main()
{
    stack<int> s;

    int n;

    cin>>n;

    int a;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        s.push(a);
    }

    int i=0;

    while(!s.empty())
    {
        if(i++)
        {
            cout<<" ";
        }
        a=s.top();
        s.pop();
        cout<<a;
    }
    cout<<endl;

    return 0;
}



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

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

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
   int i,n,x;
   long long max,min,sam;
   sam = 0;

   cin >> n;

   cin >> x;

   sam += x;
   min = x;
   max = x;

   for(i=1; i<n; i++){
	cin >> x;

	sam += x;

	if(x <= min){
		min = x;
	}else if(x >= max){
		max = x;
	}
   }

   cout << min << " " << max << " " << sam << endl;

   return 0;
}

	

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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 (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int H, W;
	cin >> H >> W;

	string smap[51];

	int ans = H * W;
	rep(i, 0, H)
	{
		cin >> smap[i];
		rep(j, 0, W)
		{
			if (smap[i][j] == '#')ans--;
		}
	}

	queue<pair<pair<int, int>, int>> q;
	q.push(mp(mp(0, 0), 1));
	bool used[3000] = { false };

	int res = -1;
	while (!q.empty())
	{
		auto p = q.front();
		q.pop();
		if (p.first.first == W - 1 && p.first.second == H - 1)
		{
			res = p.second;
			break;
		}
		static const int dx[] = { 0,1,0,-1 };
		static const int dy[] = { 1,0,-1,0 };
		rep(i, 0, 4)
		{
			int nx = p.first.first + dx[i];
			int ny = p.first.second + dy[i];
			if (0 <= nx && 0 <= ny && nx < W&&ny < H && !used[ny*W + nx]&&smap[ny][nx]=='.')
			{
				used[ny*W + nx] = true;
				q.push(mp(mp(nx, ny), p.second + 1));
			}
		}
	}

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

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    int d[n];
    for (int i=0;i<n;i++){
        scanf("%d",&d[i]);
    }
    int store; //降順にソート
    for (int i=n-1;i>0;i--){
        for (int j=0;j<i;j++){
            if (d[j]<d[j+1]){
                store=d[j];
                d[j]=d[j+1];
                d[j+1]=store;
            }
        }
    }
    int sum=1,mochi=d[0];
    for (int i=1;i<n;i++){
        if (mochi>d[i]){
            sum++;
            mochi=d[i];
        }
    }
    printf("%d\n",sum);
    return 0;
}


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

using namespace std;

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

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

vector<vector<int>> edge;
int dfs(int node, vector<bool>& is_visited) {
  is_visited[node] = true;

  int odd = 0;
  for (int e : edge[node]) {
    if (!is_visited[e]) {
      int r = dfs(e, is_visited);
      if (r < 0) {
        return -1;
      }
      odd += r;
    }
  }
  if (odd >= 2) {
    return -1;
  } else if (odd == 1) {
    return 0;
  } else {
    return 1;
  }
}

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

  edge.resize(N);
  rep(i, N - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }

  vector<bool> is_visited(N, false);
  int result = dfs(0, is_visited);
  cout << (result != 0 ? "First" : "Second") << endl;

  return 0;
}

Measured memory_bytes: 8368
import sys
# gcd
from fractions import gcd
# 切り上げ，切り捨て
# from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
# from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
# from collections import Counter
# import math
# from functools import reduce
#
# input関係の定義
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


N = ii()
A = lmi()
Leftgcd = list(accumulate(A, gcd))
Rightgcd = list(accumulate(reversed(A), gcd))
Leftgcd.insert(0, 0)
Rightgcd.insert(0, 0)
maxgcd = 1
for i in range(N):
    maxgcd = max(maxgcd, gcd(Leftgcd[i], Rightgcd[N - 1 - i]))
print(maxgcd)


Measured memory_bytes: 16076
from collections import defaultdict
class myUnionFind():
    def __init__(self,size):
        self.table = [-1 for i in range(size)]

    def find(self,x):
        if self.table[x]<0:
            return x
        self.table[x] = self.find(self.table[x])
        return self.table[x]

    def is_same(self,x,y):
        return self.table[x]==self.table[y]

    def union(self,x,y):
        x,y = self.find(x),self.find(y)
        if x != y:
            if self.table[x] > self.table[y]:
                y,x = x,y
            self.table[x] += self.table[y]
            self.table[y] = x
        return x!=y

N,K,L = map(int,input().split())
R,T = myUnionFind(N),myUnionFind(N)
for i in range(K):
    p,q = map(int,input().split())
    R.union(p-1,q-1)
for i in range(L):
    r,s = map(int,input().split())
    T.union(r-1,s-1)
both = defaultdict(int)
for i in range(N):
    both[(R.find(i),T.find(i))] += 1
ans = [both[(R.find(i),T.find(i))] for i in range(N)]
print(*ans)


Measured memory_bytes: 119836
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty |) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty | $n:expr) => {
        (0..$n).map(|_| get!($t |)).collect::<Vec<_>>()
    };
}
macro_rules! tern {
    ($condition: expr, $_true: expr, $_false: expr) => {
        if $condition {
            $_true
        } else {
            $_false
        }
    };
}
fn main() {
    let (M1, D1) = get!(usize, usize);
    let (M2, D2) = get!(usize, usize);
    if D2 == 1 {
        println!("1");
    } else {
        println!("0");
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include <cmath>
#include<string>
//#include <bits/stdc++.h>

typedef long double ld;
typedef long long ll;

using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
 //   freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
    ll sum=0;string s;
    cin>>s;
    for(auto i:s){
        sum+=(i-'0');
    }
    cout<<(sum%9==0? "Yes":"No");
    return 0;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n,i,c=1;
  cin>>n;
  vector<string> s(n);
  for(i=0;i<n;i++) cin>>s.at(i);
  sort(s.begin(),s.end());
  for(i=1;i<n;i++) if (s.at(i-1)!=s.at(i)) c++;
  cout<<c<<endl;
}

Measured memory_bytes: 9596
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	for (int i=0; i<3; i++)
		if (s[i]=='1') cout<<"9";
		else if (s[i]=='9') cout<<"1";
		else cout<<s[i]<<endl;
	cout<<endl;	
	return 0;
}


Measured memory_bytes: 256
from operator import itemgetter
from heapq import heappush, heappop

N, K = map(int, input().split())
a = []
for i in range(N):
    ta,tb = map(int, input().split())
    a.append([i,ta,tb])
a = sorted(a, key=itemgetter(2), reverse=True)

neta_count = 0
umai = []
umai_append = umai.append
used_i = set()
add_i = used_i.add# add is append in set()
used_neta = set()
add_neta = used_neta.add
#ネタの重複しないもののみ選んでいるつまり各ネタの種類から一種類ずつ
for i, neta, uma in a:
    if neta not in used_neta:
        umai.append(uma)
        neta_count += 1
        add_i(i)
        add_neta(neta)
    if neta_count == K:
        break
#print(umai)
m = neta_count
umai.sort()#昇順注意
for i, neta, uma in filter(lambda x: x[0] not in used_i, a):
    #print(i, neta, uma)
    if m < K:
        heappush(umai, uma)
        m += 1
    elif uma > umai[0]:
        if neta in used_neta and uma - umai[0] > neta_count**2 - (neta_count-1)**2:
            #そのネタを入れるのと種類ボーナスどっちが大きいか計算してる
            heappop(umai)
            heappush(umai, uma)
            neta_count -= 1

print(sum(umai) + neta_count**2)

Measured memory_bytes: 28304
#include<cstdio>
#include<cstring>
const int N=2005;
int n,m,he[N],to[N*2],nx[N*2],f[N][N],g[N],h[N],fa[N],sz[N],a=1e9;
inline void wk(int w,int x,int y){to[w]=y,nx[w]=he[x],he[x]=w;}
inline int mn(int x,int y){return x<y?x:y;}
void dfs(int x)
{
	memset(f[x],0x3f,sizeof(f[x])),f[x][0]=0,sz[x]=1;
	for(int i=he[x],y;i;i=nx[i])if((y=to[i])!=fa[x])
	{
		fa[y]=x,dfs(y),sz[x]+=sz[y],g[0]=f[x][0],h[0]=f[y][0];
		for(int j=1;j<=m;++j)g[j]=mn(g[j-1],f[x][j]),h[j]=mn(h[j-1],f[y][j]);
		f[x][m]=mn(f[x][m]+f[y][0]+1,f[y][m-1]+f[x][0]);
		for(int j=m-1;j;--j)f[x][j]=mn(f[x][j]+h[mn(j-1,m-j-1)],f[y][j-1]+g[mn(j,m-j)]);//
		f[x][0]+=f[y][0]+1;
	}
	for(int i=0;i<=m;++i)a=mn(a,n-sz[x]+f[x][i]);
}
int main()
{
//	freopen("t.in","r",stdin);
	scanf("%d%d",&n,&m);
	for(int i=1,x,y;i<n;++i)
		scanf("%d%d",&x,&y),wk(i*2,x,y),wk(i*2+1,y,x);
	return dfs(1),printf("%d",a),0;
}

Measured memory_bytes: 17644
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define pb push_back
typedef long long ll;
typedef vector<long long> vll;
#define fo(i,a) for(ll i=0;i<a;i++)
#define Fo(i,a,b) for(ll i=a;i<b;i++)
#define deb(x) cout<<#x<<" = "<<x<<"\n"

void solve(){
    ll n,k,in,sum=0;
    vll v;
    cin>>n>>k;
    fo(i,n){
        cin >> in;
        v.pb(in);
    }
    sort(v.begin(),v.end());
    fo(i,k){
        sum += v[i];
    }
    cout<<sum;
}


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

	ll t=1;
//	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}



Measured memory_bytes: 3672
import sys
import math
import bisect
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


# A
def A():
    K, X = LI()
    if K * 500 >= X:
        print("Yes")
    else:
        print("No")
    return


# B
def B():
    n = I()
    s = S()
    cnt = 0
    for i in range(n - 2):
        if s[i] == "A":
            if s[i + 1] == "B" and s[i + 2] == "C":
                cnt += 1
    print(cnt)
    return


# C
def C():
    n = I()
    p = LI()
    q = LI()
    a_cnt = [1] * n
    b_cnt = [1] * n
    a = 0
    b = 0
    for i in range(1, n + 1):
        num = 1
        for j in range(1, n + 1 - i):
            num *= j
        a += sum(a_cnt[:p[i - 1]]) * num
        b += sum(b_cnt[:q[i - 1]]) * num
        a_cnt[p[i - 1] - 1] = 0
        b_cnt[q[i - 1] - 1] = 0
    print(abs(a - b))
    return


# D
def D():
    def GCD(a, b):
        if (b == 0):
            return a
        else:
            return GCD(b, a % b)

    n, m = LI()
    a = list(int(x) // 2 for x in sys.stdin.readline().split())
    b = a[0]
    for i in range(1, n):
        b = b * a[i] // GCD(b, a[i])
        if (b // a[i]) % 2 == 0:
            print(0)
            return
    if b > m:
        print(0)
    else:
        print((m - b) // (b * 2) + 1)
    return


# E
def E():
    return


# F
def F():
    return


# Solve
if __name__ == "__main__":
    D()


Measured memory_bytes: 59760
#include<bits/stdc++.h>
using namespace std;
 
template<typename T1, typename T2> istream& operator>>(istream& is, pair<T1,T2>& a){ return is >> a.first >> a.second; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1,T2>& a){ return os << a.first << " "<<a.second; }
template<typename T> istream& operator>>(istream& is, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) is >> vc[i]; return is; }
template<typename T> ostream& operator<<(ostream& os, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) os << vc[i] << endl; return os; }
 
#define ForEach(it,c) for(__typeof (c).begin() it = (c).begin(); it != (c).end(); it++)
#define ALL(v) (v).begin(), (v).end()
#define UNQ(s) { sort(ALL(s)); (s).erase( unique( ALL(s)), (s).end());}
#define fr first
#define sc second
 
typedef pair< int , int > Pi;
typedef pair< int , Pi > Pii;
 
typedef long long int64;
const int INF = 1 << 30;

vector< string > ret;
string s;

void rec( int idx, int used, string str){
  if(idx == s.size()){
    ret.push_back(str);
    return;
  }
  char c = s[idx];
  if(c == 'a' || ((used >> (c - 'a')) & 1)){ /* cが始めて現れてない */
    rec( idx + 1, used|(1 << (c - 'a')), str + c);
  }

  if(c != 'z' && !((used >> (c + 1 - 'a')) & 1)) rec( idx + 1, used|(1 << (c + 1 - 'a')), str + (char)(c + 1));
}

int main(){
  while(cin >> s, s != "#"){
    rec( 0, 0, "");
    cout << ret.size() << endl;
    if(ret.size() > 10){
      for(int i = 0; i < 5; i++){
        cout << ret[i] << endl;
      }
      for(int i = ret.size() - 5; i < ret.size(); i++){
        cout << ret[i] << endl;
      }
    } else {
      for(int i = 0; i < ret.size(); i++){
        cout << ret[i] << endl;
      }
    }
    ret.clear();
  }
}

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

int main(){
  int n;
  int check = 0;
  scanf("%d",&n);
  int x,y,t,x_p,y_p,t_p;
  x_p=0;
  y_p=0;
  t_p=0;
  int del_t,del_x,del_y;
  for(int i=1;i<=n;++i){
    scanf("\n%d %d %d",&t,&x,&y);
    del_t = t - t_p;
    del_x = abs(x - x_p);
    del_y = abs(y - y_p);
    if((del_t + del_x + del_y) % 2 == 1){
      check = 1;
      break;
    }else if(del_t < del_x+del_y){
      check = 1;
      break;
    }
    //printf("%d %d %d %d\n",del_t,del_x,del_y,check);
    t_p = t;
    x_p = x;
    y_p = y;
  }
  if(check == 0) printf("Yes");
  else printf("No");
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main() {
 int h, w;
 cin >> h >> w;

 string board[50];

 for (int i = 0; i < h; ++i) cin >> board[i];

 const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
 const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

 for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
if (board[i][j] == '#') continue;

 int num = 0;
 for (int d = 0; d < 8; ++ d) {
 const int ni = i + dy[d];
 const int nj = j + dx[d];

 if (ni < 0 or h <= ni) continue;
 if (nj < 0 or w <= nj) continue;
 if (board[ni][nj] == '#') num++;
 }

 board[i][j] = char(num + '0');

 }
 }

 for (int i = 0; i < h; ++i) cout << board[i] << endl;

 return 0;
 }

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int N;
    scanf("%d", &N);

    int i, j, tmp;
    for(i=1; i<=(N/4); i++) {
        tmp = 4*i;
        if(tmp==N) {
            printf("Yes\n");
            return 0;
        }
        for(j=1; j<=i; j++) {
            tmp += 3;
            if(tmp==N) {
                printf("Yes\n");
                return 0;
            }
        }
    }

    printf("No\n");

    return 0;

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, k, n) for(ll i = k; i < (ll)(n); i++)
using ll = long long;

int main(){
    int n, m;
    cin >> n >> m;
    int l = 0;
    int r = n+1;
    rep(i, 0, m){
        int a, b;
        cin >> a >> b;
        l = max(l, a);
        r = min(r, b);
    }
    if (r >= l) cout << r - l + 1<< endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
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: 3568
#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    string s;
    cin >> s;
    if (s == "AAA" || s == "BBB") cout << "No" << endl;
    else cout << "Yes" << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, n) for (int i = (n - 1); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1000000007;

int main() {
  int n;
  ll d;
  cin >> n >> d;
  int cnt = 0;
  rep(i, n) {
    ll a, b;
    cin >> a >> b;
    if (sqrt(a * a + b * b) <= d) cnt++;
  }
  cout << cnt << endl;
}


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

bool isVowel(char c) {
    return c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o';
}

int solve(const int& n, const vector<string>& s) {
    vector<string> nukidashi;
    for (auto&& name : s) {
        bool use[name.size()] = {};
        use[0] = true;
        for (size_t i = 1; i < name.size(); i++) {
            use[i] = isVowel(name[i - 1]);
        }
        string namee = "";
        for (size_t i = 0; i < name.size(); i++) {
            if (use[i]) {
                namee += name[i];
            }
        }
        nukidashi.push_back(namee);
    }

    for (int k = 1;; k++) {
        bool great = true;
        set<string> codes;
        for (auto&& nukidash : nukidashi) {
            codes.insert(nukidash.substr(0, min((int)nukidash.size(), k)));
            great &= (nukidash.size() < k);
        }
        if (codes.size() == n) {
            return k;
        }
        if (great) {
            return -1;
        }
    }
}

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            return 0;
        }

        vector<string> s(n);
        for (size_t i = 0; i < n; i++) {
            cin >> s[i];
        }

        cout << solve(n, s) << endl;
    }
}


Measured memory_bytes: 3180
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cstdio>

//#include <cstdint>
#include <cstdlib>
#include <cassert>
#include <cctype>
#include <climits>
#include <functional>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <ctime>

#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <list>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <array>

using namespace std;

#define forn(i, n) for(int i = 0; i < int(n); i++)
#define forn1(i, n) for(int i = 1; i <= int(n); i++)
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define pb push_back
#define x first
#define y second

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

const int INF = int(1e9);
const li INF64 = li(1e18);
const ld PI = acosl(ld(-1));
const ld EPS = 1e-11;

template <typename T> inline T sqr(const T& x) {
	return x * x;
}

template <typename T> inline T abs(const T& x) {
	return x > 0 ? x : -x;
}

inline bool inside(int x, int y, int n, int m) {
	return x >= 0 && x < n && y >= 0 && y < m;
}

inline int rnd() {
	return abs(rand() ^ (rand() << 15));
}

inline int rnd(int n) {
	assert(n > 0);
	return rnd() % n;
}

inline int rnd(int lf, int rg) {
	return lf + rnd(rg - lf + 1);
}

inline li rndLL() {
	return rnd() * 1LL * rnd() + rnd();
}

const int dx[4] = { -1, 0, +1, 0 };
const int dy[4] = { 0, +1, 0, -1 };

const int N = int(2e5) + 555;



inline void gen() {
	return;
}

inline bool read() {
	return true;
}

inline void solve() {
	int k, n;
	cin >> k >> n;
	int * a = new int[n + 1];
	forn1(i, n) cin >> a[i];
	int * ans = new int[k + 1];
	forn(i, k + 1) ans[i] = 0;
	forn1(kk, k) {
		int pref = ans[kk - 1];
		int mx = 0;
		int pos = 0;
		forn1(i, n) {
			if (a[i] == 0) continue;
			if (a[i] > mx && i != pref) {
				mx = a[i];
				pos = i;
			}
		}

		if (pos == 0) pos = pref;
		ans[kk] = pos;
		a[pos]--;
	}

	//forn1(i, k) cerr << ans[i] << ' '; cerr << endl;
	int res = 0;
	forn1(i, k) res += ans[i] == ans[i - 1];
	cout << res << endl;
	return;
}

int main() {
#ifdef _DEBUG
	assert(freopen("input.txt", "rt", stdin));
	assert(freopen("output.txt", "wt", stdout));
#endif

	cout << setprecision(10) << fixed;
	cerr << setprecision(10) << fixed;

	srand(int(time(NULL)));

	int T = 1;
	//#define MULTITEST
#ifdef MULTITEST
	assert(scanf("%d", &T) == 1);
#endif

	forn(i, T) {
#ifdef _DEBUG
		cerr << "TEST == " << i << endl;
#endif
		assert(read());
		solve();
	}

#ifdef _DEBUG
	cerr << "TIME == " << clock() << " ms" << endl;
#endif
	return 0;
}

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

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433;

template <class T> vector<T> make_v(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto make_v(size_t N,T... t){return vector<decltype(make_v(t...))>(N,make_v(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    ll N; cin >> N;
    cout << ((N-1)*N)/2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
queue<pair<int,int> > qu;
vector<int> v[111];
int root;
int b;
int d[111];
pair<int, int> pa;
int g;
 
void wide(int num){
 
  memset(d,-1,sizeof(d));
  d[num] = 0;
  qu.push(make_pair(num,d[1]));
 
  while(!qu.empty()){
 
    pa = qu.front();
    qu.pop();
    int id = pa.first;
 
    for(int i = 0; i < (int)v[id].size(); i++){
      if(d[v[id][i]] == -1){
    d[v[id][i]] = pa.second + 1;
    qu.push(make_pair(v[id][i],d[v[id][i]]));
      }
    }
  }
  for(int i = 1; i <= g; i++){
    cout << i << " " << d[i] << endl;
  }
 
}
 
int main(){
 
  
  cin >> g;
  int n;
  for(int i = 0; i < g; i++){
    cin >> n >> b;
    for(int j = 0; j < b; j++){
      cin >> root;
      v[n].push_back(root);
    }
  }
 
  wide(1);
 
}

Measured memory_bytes: 1224
import std.stdio, std.conv, std.string;
import std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

int DEBUG_LEVEL = 0;
void print()(){ writeln(""); }
void print(T, A ...)(T t, lazy A a){ write(t), print(a); }
void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }

void main(string[] args){
	if(args.length > 1 && args[1] == "-debug"){
		if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;
		else DEBUG_LEVEL = 1;
	}
	
	int n = read.to!int;
	
	int[2][] es;
	if(n % 2 == 0){
		foreach(i; 1 .. n + 1) foreach(j; i + 1 .. n + 1){
			if(i + j != n + 1) es ~= [i, j];
		}
	}
	else{
		foreach(i; 1 .. n) foreach(j; i + 1 .. n){
			if(i + j != n) es ~= [i, j];
		}
		foreach(i; 1 .. n) es ~= [i, n];
	}
	
	es.length.writeln;
	foreach(e; es) writeln(e[0], " ", e[1]);
}

/*

Nが偶数（たとえば6）のときは
→たして7になるもの同士をペアにして、自分のペア相手以外の全てと手をつなぐ

Nが奇数（たとえば7）のときは
→減らして6で考え、上記の通りにした上で、最後に7は自分以外の全てと手をつなぐ


*/


Measured memory_bytes: 380
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int l = sc.nextInt();
        String[] s = new String[n];
        for (int i = 0; i < n; i++) {
            s[i] = sc.next();
        }
        Arrays.sort(s);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            sb.append(s[i]);
        }
        System.out.println(sb.toString());
        sc.close();

    }

}


Measured memory_bytes: 21588
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <queue>
#include <bitset>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = (a); i < (n); i++)
#define MP make_pair
#define all(s) (s).begin(), (s).end()
#define rev(s) (s).rbegin(), (s).rend()
#define X first
#define Y second

using namespace std;

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

void test(){freopen("test.txt", "r", stdin);}

int main(){
	int N, T, E;
	cin >> N >> T >> E;
	rep(i, N){
		int x;
		cin >> x;
		if((T+E)%x <= E){
			cout << i+1 << endl;
			return 0;
		}
	}
	cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define yes(n) cout << ((n) ? "yes" : "no") << endl

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

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) {
    ll g = GCD(a, b);
    return a / g * b;
}


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

    if (n % 2 != 0) {
        cout << "No" << endl;
    } else {
        int half = n / 2;
        bool ok = true;
        rep (i, half) {
            if (s[i] != s[i + half]) {
                ok = false;
                break;
            }
        }
        Yes(ok);
    }
}

Measured memory_bytes: 256
//██████╗ ██╗   ██╗██╗      ██████╗ ███████╗
//██╔══██╗██║   ██║██║      ██╔══██╗██╔════╝
//██████╔╝██║   ██║██║█████╗██║  ██║█████╗
//██╔══██╗██║   ██║██║╚════╝██║  ██║██╔══╝
//██║  ██║╚██████╔╝██║      ██████╔╝███████╗
//╚═╝  ╚═╝ ╚═════╝ ╚═╝      ╚═════╝ ╚══════╝

#include <iostream>
#include <random>
#include <vector>
#include <set>
#include <algorithm>
#include <iomanip>
#include <chrono>
#include <cstdio>
#include <map>
#include <memory.h>


// #pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;

#define fst first
#define snd second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back

#define all(v) (v).begin(), (v).end()
#define sz(v) ((int)(v).size())
#define sqr(x) ((x) * (x))

typedef long long ll;
typedef  double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;

#define next ajksdslk
#define prev aklsfjk

mt19937_64 mt_rand(chrono::system_clock::now().time_since_epoch().count());

template<typename T1, typename T2> inline bool upmax(T1& a, T2 b) { return (a < b ? (a = b, true) : false); }
template<typename T1, typename T2> inline bool upmin(T1& a, T2 b) { return (b < a ? (a = b, true) : false); }

const int maxn = (int) 5e6 + 100;
const int maxlog = 21;
const int base = 998244353;
const ld eps = (ld) 1e-9;
const ld PI = acos(-1.);
//const int pp = 41;
const int inf = 2e9;
const ll llinf = 1e18;

vector<string> w {
    "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#ifdef LOCAL
  freopen ("input.txt", "r", stdin);
#endif
  string s; cin >> s;
  int kek;
  for (int i = 0; i < sz(w); i ++) {
    if (s == w[i]) {
      kek = i;
    }
  }
  cout << 7 - kek;



  return 0;
}

Measured memory_bytes: 256
public class Main {
	public static void main(String[] args) {
		try (java.util.Scanner sc = new java.util.Scanner(System.in)) {
			int n = sc.nextInt();

			java.util.stream.IntStream.rangeClosed(1, n)
					.filter(num -> num % 3 == 0 || String.valueOf(num).contains("3"))
					.forEachOrdered(num -> System.out.print(" " + num));
			System.out.println("");
		}
	}
}


Measured memory_bytes: 34872
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        int x = Math.abs(a - b);
        int y = Math.abs(b - c);
        int z = Math.abs(c - a);

        if (x <= y) {
            if (y <= z) {
                System.out.println(x + y);
            } else {
                System.out.println(x + z);
            }
        } else {
            if (x <= z) {
                System.out.println(x + y);
            } else {
                System.out.println(y + z);
            }
        }

    }
}



Measured memory_bytes: 22484
#include <bits/stdc++.h>
using namespace std;
bool isValid(int value){
    bool ret = true;
    vector <int> digit;
    while(value>0){
        digit.push_back(value%10);
        value/=10;
    }
    if(digit.size()<=1){
        ret = true;
    }else{
        for(int i = 0; i < digit.size()/2; i++){
            if(digit[i]!=digit[digit.size()-1-i]){
                ret = false;
                break;
            }
        }
    }
    return ret;
}
int main(){
    int a,b;
    cin >> a >> b;
    int ans = 0;
    for(int i = a; i <= b; i++){
        if(isValid(i))ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
        int w, h;
        scanf("%d %d", &w, &h);
        vector<pair<int, bool>> es;
        for (int i = 0; i < w; i ++) {
                int p;
                scanf("%d", &p);
                es.emplace_back(p, true);
        }
        for (int i = 0; i < h; i ++) {
                int q;
                scanf("%d", &q);
                es.emplace_back(q, false);
        }
        sort(es.begin(), es.end());
        long long ans = 0;
        int esp = 0;
        w ++, h ++;
        while (w >= 0 && h >= 0 && esp < (int) es.size()) {
                if (es[esp].second) {
                        ans += (long long) es[esp].first * h;
                        w --;
                } else {
                        ans += (long long) es[esp].first * w;
                        h --;
                }
                esp ++;
        }
        printf("%lld\n", ans);
        return 0;
}


Measured memory_bytes: 3444
#include <iostream>
#include <cmath>

using namespace std;

const int MAX = 5100000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


bool checkInteger(double d) {
    if (ceil(d) != d && floor(d) != d) {
        return false;
    }
    else {
        return true;
    }
}

int main()
{
    /*a,bをそれぞれ(2,1),(1,2)で進んだ回数を表すものとする。
    (X,Y)から(a,b)を求める。
    (X,Y)に対し
    2a+b=X;
    a+2b=Y; 
    (a>=0,b>=0,a,b,x,yは整数)
    を満たす(a,b)は、
    a=(2X-Y)/3
    b=(2Y-X)/3
    で求められる。解が無い場合（必要十分条件は？）は移動させる方法の数はゼロが回答となる.
    解が無い必要十分条件は、
    (2X-Y)/3が整数でない　|| (2Y-X)/3が整数でない
    である。
    a,bが求まると,答えは(a+b)C(a)となる。
    */
    int X, Y;
    cin >> X >> Y;

    COMinit();

    bool flag1 = checkInteger((2 * X - Y) / 3.0);
    bool flag2 = checkInteger((2 * Y - X) / 3.0);

    if (!flag1 || !flag2) {
        cout << 0 << endl;
    }
    else {
        int a = (2 * X - Y) / 3;
        int b = (2 * Y - X) / 3;
        cout << COM(a + b, a) << endl;
    }

    return 0;
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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; }

typedef pair<int, int> PP;

bool pairCompare(const PP& firstElof, const PP& secondElof)
{
    return firstElof.first > secondElof.first;
}

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

    int N;
    cin >> N;

    vector<string> S(N);
    vector<int>    P(N);
    set<string>    S_set;

    string tmp_S;
    for(int i = 0; i < N; i++){
        cin >> tmp_S >> P[i];
        S[i] = tmp_S;
        S_set.insert(tmp_S);
    }

    for(auto itr = S_set.begin(); itr != S_set.end(); ++itr) {
        tmp_S = *itr;
        vector<pair<int, int>> tmp_v;
        for(int i = 0; i < N; i++){
            if(S[i] == tmp_S){
                tmp_v.push_back(PP(P[i], i+1));
            }
        }

        sort(tmp_v.begin(), tmp_v.end(), pairCompare);

        for(int i = 0; i < tmp_v.size(); i++){
            cout << tmp_v[i].second << endl;
        }
    }


    return 0;
}


Measured memory_bytes: 256
/**
 *   
 *   Date: 22 December 2019
 *   Time: 17:51:58
**/
#pragma GCC optimize("O3")
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cmath>
#include <cstring>
#include<queue>
#include<stack>
#include<climits>
#include<iomanip>
#define endl "\n"
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vec;
typedef vector<vector<ll> > matrix;
ll const mod=1000000007;

int main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	string st,pat,st1="";
	ll n;
	cin>>n;
	cin>>st;
	cin>>pat;
	for(ll i=0;i<st.length();i++)
	{
		st1+=st[i];
		st1+=pat[i];
	}
	cout<<st1<<endl;

return 0;
}

Measured memory_bytes: 256
s=input()
t=input()
sr=[-1]*26
tr=[-1]*26
ans="Yes"
for S,T in zip(s,t):
    if sr[ord(S)-97]>=0:
        if sr[ord(S)-97]!=ord(T):
            ans="No"
    if tr[ord(T)-97]>=0:
        if tr[ord(T)-97]!=ord(S):
            ans="No"
    if sr[ord(S)-97]<0:
        sr[ord(S)-97]=ord(T)
    if tr[ord(T)-97]<0:
        tr[ord(T)-97]=ord(S)
print(ans)

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<cstdlib>
#include <cmath>
using namespace std;

int main(){
  int i,j,k,d,n,a,ans;
  cin >> d>>n;

  a=pow(100,d);

  if(n==100){
    for(i=0;i<n;i++){
      ans+=a;
    }
    ans+=a;
  }else{
    for(i=0;i<n;i++){
      ans+=a;
    }
  }

  cout <<ans<<endl;
  return 0;
}

Measured memory_bytes: 384