akhauriyash/Code-Regression huggingface dataset:
# @oj: atcoder
# @id: hitwanyang
# @email: 296866643@qq.com
# @date: 2020-05-17 20:03
# @url:
import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string
# region fastio

BUFSIZE = 8192

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
def main():
    k=int(input())
    s=str(input())
    if k>=len(s):
        print (s)
    else:
        print (s[0:k]+"...")
if __name__ == "__main__":
    main()

Measured memory_bytes: 68572
#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;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  cout << (n-1)*(m-1) << endl;
  return 0;
}

Measured memory_bytes: 256
s = input()
ans = [0] * len(s)
ruiseki = 0
for i in range(len(s)):
    if s[i] == 'R':
        ruiseki += 1
        if s[i + 1] == 'L':
            ans[i] += (ruiseki + 1) // 2
            ans[i + 1] += ruiseki // 2
    else:
        ruiseki = 0

ruiseki = 0
for i in range(len(s) - 1, 0, -1):
    if s[i] == 'L':
        ruiseki += 1
        if s[i - 1] == 'R':
            ans[i] += (ruiseki + 1) // 2
            ans[i - 1] += ruiseki // 2
    else:
        ruiseki = 0
print(*ans)

Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n);(i)>0;(i)--)
#define INF (1ll<<60)
typedef long long lint;
const lint MOD =1000000007;

int main(){
    lint N;
    vector <lint> a;
 vector <lint> b;
    vector <lint> c;
    cin>>N;
    lint dp[N][3];
    rep(i,N){
                lint d,e,f;
                cin>>d>>e>>f;
                a.push_back(d);
                b.push_back(e);
                c.push_back(f);
        
    }

rep(i,N){
    if(i==0){
        dp[i][0]=a[i];
         dp[i][1]=b[i];
          dp[i][2]=c[i];
          continue;
    }
    rep(j,3){
           if(j==0) dp[i][j]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
           if(j==1) dp[i][j]=max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]);
           if(j==2) dp[i][j]=max(dp[i-1][1]+c[i],dp[i-1][0]+c[i]);
        
    }
}
cout<<max({dp[N-1][0],dp[N-1][1],dp[N-1][2]});

    
}

Measured memory_bytes: 5216
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <cctype>
#include <functional>
#include <string>
#include <cstring>
#include <sstream>
#include <deque>
#define fir first
#define sec second
using namespace std;

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

const int inf1=1e9+9;
const ll inf2=1e16+9;
const ll mol=1e9+7;
const int maxn=1e5+9;
const ll maxx=1e12+9;

int n,x,t;

int main()
{
    cin>>n>>x>>t;
    int ans=t*ceil(n*1.0/x);
    cout<<ans<<endl;
}


Measured memory_bytes: 3288
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

char dif = 'A' - 'a';

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x, y;
    cin >> x >> y;
    if(abs(x-y)>1)
        cout << "Alice" << endl;
        else
            cout << "Brown" << endl;
        return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	static public void main(String args[]) {

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		
		ArrayList<Integer> list = new ArrayList<>();
		for(int i=0; i<n; i++) {
			list.add(scan.nextInt());
		}

		int m = scan.nextInt();

		for(int i=0; i<m; i++){

			int query = scan.nextInt();

			int lowerResult = ~Collections.binarySearch(list, query, (x, y) -> x.compareTo(y) >= 0 ? 1 : -1);			
			System.out.print(lowerResult + " ");
//				System.out.println("debug");
			int upperResult = ~Collections.binarySearch(list, query, (x, y) -> x.compareTo(y) > 0 ? 1 : -1);
			System.out.println(upperResult);
				
		}
	}
}



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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	vi v(n);
	REP(i, n)cin >> v[i];
	vi dp(n, INF);
	dp[0] = 0;
	REP(i, n) {
		REP(j, k) {
			if (i + j + 1 < n)dp[i + j + 1] = min(dp[i + j + 1], dp[i] + abs(v[i] - v[i + j + 1]));
		}
	}
	cout << dp[n-1] << endl;
	
}

Measured memory_bytes: 1024
import java.io.*;
import java.io.ObjectInputStream.*;
import java.util.*;
import java.util.regex.*;


public class Main {

	final static long MOD = 1000000007;
	//final static long MOD = 998244353;

	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws Exception {
		solutionA(args);
		if(in!=null){
			in.close();
		}
		pw.flush();
		pw.close();
	}

	public static void solutionA(String[] args) throws Exception{

		int H = nextInt();
		int W = nextInt();
		int K = nextInt();

		int[][] map = new int[H][W];
		int seq=1;
		for(int h=0;h<H;h++) {
			String s = nextString();
			int n=0;
			//左から右に埋める
			for(int w=0;w<W;w++) {
				if(s.charAt(w)=='#') {
					n=seq;
					seq++;
				}
				map[h][w]=n;
			}
			//右から左に埋める
			for(int w=W-2;w>=0;w--) {
				if(map[h][w]==0) {
					map[h][w]=map[h][w+1];
				}
			}
		}
		//上から下に埋める
		for(int h=1;h<H;h++) {
			for(int w=0;w<W;w++) {
				if(map[h][w]==0) {
					map[h][w]=map[h-1][w];
				}
			}
		}
		//下から上に埋める
		for(int h=H-2;h>=0;h--) {
			for(int w=0;w<W;w++) {
				if(map[h][w]==0) {
					map[h][w]=map[h+1][w];
				}
			}
		}

		for(int h=0;h<H;h++) {
			String s = "";
			for(int w=0;w<W;w++) {
				s+=map[h][w]+" ";
			}
			pw.println(s.trim());
		}


	}


	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}



Measured memory_bytes: 154560
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n, m;
  cin >> n >> m;
  // y = x + (1 - 2^-m) * y
  // y = x / (1 - (1 - 2^-m))
  // y = x * 2^m
  // y = x * 2^m
  cout << (m * 1900 + (n - m) * 100) * (1 << m) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

signed main(){
	IO_STREAM;
	int N;
	cin>>N;
	map<string,int>mp;
	rep(i,0,N){
		string S;
		cin>>S;
		mp[S]++;
	}
	int max_cnt=0;
	int cnt=0;
	vector<string>T(N);
	for(auto u:mp){
		DBG("u=",u.first,u.second,max_cnt);
		if(u.second>max_cnt){
			cnt=0;
			T[cnt]=u.first;
			cnt++;
			max_cnt=u.second;
		}
		else if(u.second==max_cnt){
			T[cnt]=u.first;
			cnt++;
		}
	}
	rep(i,0,N){
		DBG("i=",i,"T=",T[i]);
	}
//	sort(&T.at(0),&T.at(cnt-1));
	rep(i,0,N){
		DBG("sort i=",i,"T=",T[i]);
	}
	DBG("cnt=",cnt,"","");
	rep(i,0,cnt){
		cout<<T[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 25472
//    https://youtu.be/zRIbf6JqkNc

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

typedef long long ll;
typedef long double ld;
typedef long long unsigned llu;
typedef pair<long long, long long> pll;
const long long inf = 2000000000000000000LL;	// 2e18
#define pi                  acos(-1.0)
#define fast                ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define shesh               "\n"
#define ff                  first
#define ss                  second
#define pb                  push_back
#define bp                  pop_back
#define pf                  push_front
#define fp                  pop_front
#define ub                  upper_bound
#define lb                  lower_bound
#define all(x)              x.begin(), x.end()
#define debug(x)            cout<<"debug "<<x<<"\n"
#define mest(a,b)           memset(a,b,sizeof(a))
ll fun(ll h){
    if(h==1) return 1;
    else return 1+(2*fun(h/2));
}
int main(){
    fast;
    ll h,t,n,m,i,j,k,temp,flag,ans;
    cin>>h;
    cout<<fun(h);
    return 0;
}


Measured memory_bytes: 256
#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 main(){
  int a,b;
  cin >> a >> b;
  if(a%2 == 1 && b%2 == 1) puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <math.h>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll INF = 1000000000000000000LL;
using namespace std;

const int MOD = 1000000007;

//agc003b
//前から見ていって、前の物をあまりなく使う、がよさそう
//同じもの同士でもペアを作れることに注意


int main(){

    int N;
    cin >> N;
    vector <int> a(N);
    REP(i,N)cin >> a[i];
    ll res = 0;

    for(int i = 0; i < N - 1; ++i)
    {
        //全部なくすのでなく、奇数をなくしたほうがよい?
        if(a[i] % 2 == 1 && a[i+1] > 0)
        {
            res += 1;
            --a[i];
            --a[i+1];
        }
    }


    for(int i = 0; i < N; ++i)
    {
        if(a[i] >= 2)
        {
            res += a[i] / 2;
        }
    }
    cout << res << endl;

    return 0;    
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n; cin >> n;
    vector<P> p(n);
    rep(i,n) {
        cin >> p[i].first >> p[i].second;
    }
    double sum = 0;
    sort(all(p));
    do {
        rep(i,n-1) {
            sum += sqrt((p[i].first-p[i+1].first)*(p[i].first-p[i+1].first)+(p[i].second-p[i+1].second)*(p[i].second-p[i+1].second));
        }
    } while (next_permutation(all(p)));
        

    int total = 1;
    for (int i=n; i>=1; i--) {
        total *= i;
    }
    printf("%.7f\n",sum/total);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);

		int tateLine = sc.nextInt();
		int yokoLine = sc.nextInt();
		int[] numList = new int[tateLine];
		
		for (int i = 0; i < tateLine; i++) {
			numList[i] = i + 1;
		}
		
		int[][] yoko = new int[yokoLine][2];
		
		for (int i = 0; i < yokoLine; i++) {
			String[] s = sc.next().split(",");

			yoko[i][0] = Integer.parseInt(s[0]) - 1;
			yoko[i][1] = Integer.parseInt(s[1]) - 1;

		}

		for (int i = 0; i < yokoLine; i++) {
			int b = numList[yoko[i][0]];
			numList[yoko[i][0]] = numList[yoko[i][1]];
			numList[yoko[i][1]] = b;
		}

		for (int i = 0; i < tateLine; i++) {
			System.out.println(numList[i]);
		}
	}

}

Measured memory_bytes: 26216
def main():
    x, k, d = map(int,input().split())
    abs_x = abs(x)
    times = abs_x // d
    if(times > k):
        print(abs_x - k * d)
    else:
        if((k - times) % 2 == 0):
            print(abs_x - times * d)
        else:
            print(abs(abs_x - (times + 1) * d))
if __name__ == '__main__':
    main()

Measured memory_bytes: 61884
#include <stdio.h>
#define R register
namespace IO{
	char buf[1<<15],*S,*T;
	inline char gc(){
		if (S==T){
			T=(S=buf)+fread(buf,1,1<<15,stdin);
			if (S==T) return EOF;
		}return *S++;
	}
	inline char getdigit(){
		R char c;for (;(c=gc())<'0'||c>'9';);
		return c;
	}
	inline int read(){
		R int x; R bool f; R char c;
		for (f=0; (c=gc())<'0'||c>'9'; f=c=='-');
		for (x=c^'0'; (c=gc())>='0'&&c<='9'; x=(x<<1)+(x<<3)+(c^'0'));
		return f?-x:x;
	}
	const int outlim=1<<20;
	char outbuf[outlim+5];int _cnt=0;
	inline void pc(char c){
		outbuf[_cnt++]=c;
		if (_cnt==outlim)
			fwrite(outbuf,1,_cnt,stdout),_cnt=0;
	}
	inline void write(int x){
		if (x>9) write(x/10);
		pc(x%10^'0');
	}
	void endfile(){
		if (_cnt)
			fwrite(outbuf,1,_cnt,stdout);
	}
}
#define MN 2005
int n,m,q,f[MN][MN],er[MN][MN],ed[MN][MN];bool b[MN][MN];
int main(){
	n=IO::read(),m=IO::read(),q=IO::read();
	for (R int i=1; i<=n; ++i)
		for (R int j=1; j<=m; ++j)
			b[i][j]=IO::getdigit()=='1';
	for (R int i=1; i<=n; ++i)
		for (R int j=1; j<=m; ++j){
			f[i][j]=f[i-1][j]+f[i][j-1]-f[i-1][j-1]+b[i][j];
			er[i][j]=er[i-1][j]+er[i][j-1]-er[i-1][j-1]+(b[i][j]&&b[i][j+1]);
			ed[i][j]=ed[i-1][j]+ed[i][j-1]-ed[i-1][j-1]+(b[i][j]&&b[i+1][j]);
		}
	while(q--){
		R int xl=IO::read(),yl=IO::read(),xr=IO::read(),yr=IO::read();
		R int tmp=f[xr][yr]+f[xl-1][yl-1]-f[xl-1][yr]-f[xr][yl-1];
		tmp-=er[xr][yr-1]+er[xl-1][yl-1]-er[xl-1][yr-1]-er[xr][yl-1];
		tmp-=ed[xr-1][yr]+ed[xl-1][yl-1]-ed[xl-1][yr]-ed[xr-1][yl-1];
		IO::write(tmp);IO::pc('\n');
	}IO::endfile();return 0;
}

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

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
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;
}

void solve(long long K, std::string S) {
    if( S.size() <= K ){
        cout << S << endl;
    }else{
        cout << S.substr(0, K) << "..." << endl;
    }
}

int main() {
  long long K;
  scanf("%lld", &K);
  std::string S;
  std::cin >> S;
  solve(K, S);
  return 0;
}


Measured memory_bytes: 3676
#include <iostream>
using namespace std;
int main(void){
   int count[4][3][10] = {{{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0}},
                           {{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0}},
                           {{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0}},
                           {{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0}}};
   int n,b,f,r,v;
   cin >> n;

   for(int i = 0; i < n; i++){
       cin >> b >> f >> r >> v;
       count[b-1][f-1][r-1] += v;
   }
   for(b = 1; b <= 4; b++){
       for(f = 1; f <= 3; f++){
           for(r = 1; r <= 10; r++){
               cout << " " << count[b-1][f-1][r-1];
           }
           cout << endl;
       }
       if(b < 4) cout << "####################" <<endl;
   }

}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s,ss;
	cin >> s;
	cin >> ss;
	int l=s.size();
	int k=ss.size();
	int ind=-1;
	for(int i=0;i<=l-k;i++)
	{
		int f=0;
		for(int j=i;j<i+k;j++)
		{
			if(s[j]=='?')
				continue;
			if(s[j]!=ss[j-i])
			{
				f=1;
				break;
			}
		}
		//printf("%d\n",f);
		if(f==0)
		{
			ind=i;
		}
		
	}
	if(ind==-1)
	{
		printf("UNRESTORABLE\n");
		return 0;
	}
	for(int j=ind;j<ind+k;j++)
	{
		s[j]=ss[j-ind];
	}
	for(int j=0;j<l;j++)
	{
		if(s[j]=='?')
			printf("a");
		else
			printf("%c",s[j]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int k = sc.nextInt();
		sc.close();

		TreeSet<String> strSet = new TreeSet<String>();
		for (int i = 0; i < s.length(); i++) {
			for (int len = 1; len <= 5 && len + i <= s.length(); len++) {
				String str = s.substring(i, i + len);
				strSet.add(str);
			}
		}
		System.out.println(strSet.toArray(new String[0])[k - 1]);
	}
}


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

int main(){
  int n; cin >> n;
  int a[n], b[n], c[n];
  rep(i, n) cin >> a[i] >> b[i] >> c[i];
  int dp[3];
  rep(i ,3) dp[i] = 0;
  rep(i, n){
    int p = max(dp[1]+a[i], dp[2]+a[i]);
    int q = max(dp[2]+b[i], dp[0]+b[i]);
    int r = max(dp[0]+c[i], dp[1]+c[i]);
    dp[0] = p; dp[1] = q; dp[2] = r;
  }
  cout << max(max(dp[0], dp[1]), dp[2]) << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;

//少数点表示
//cout <<std::fixed << std::setprecision(14) <<double値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    ll h,w;
    cin >> h >> w;
    if(h == 1 || w == 1){
        cout << 1;
        return 0;
    }
    ll s=h*w;
    if(s%2!=0){
        cout << s/2+1;
    }else{
        cout << s/2;
    }


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,sum = 0;
  cin >> a >> b;
  for (int i = a;i<=b;i++){
    if(i/10000 == i%10){
      if((i%10000)/1000 == (i/10)%10){
      sum++;
     }
    }
  }
  cout << sum << endl;
}

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

using namespace std;

#define mem(a,i) memset(a,i,sizeof(a))
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;

const int maxn=10;
vector<int> e[maxn];
int dep[maxn];
void dfs(int u,int fa) {
    dep[u]=dep[fa]+1;
    for(auto v:e[u]) {
        if(v==fa) continue;
        dfs(v,u);
    }
}

int main() {
    rep(i,1,3) {
        int u,v;
        scanf("%d%d",&u,&v);
        e[u].pb(v);
        e[v].pb(u);
    }
    rep(i,1,4) {
        dep[0]=0;
        dfs(i,0);
        rep(j,1,4) {
            if(dep[j]==4) {
                return 0*puts("YES");
            }
        }
    }
    puts("NO");
    return 0;
}

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

int main(void) {
  int A, B, K;
  cin >> A >> B >> K;
  int cnt = 0;
  for (int i = max(A, B); i >= 1; i--) {
    if (A % i == 0 && B % i == 0) {
      cnt++;
    }
    if (cnt == K) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
constexpr long long MAX = 1e15;

vector<long long> dijkstra(const vector<vector<pair<int, long long>>> &g, int s){
    using P = pair<long long, int>;
    constexpr long long inf = INT64_MAX;
    long long last = 0, sz = 0;
    vector<pair<long long, int>> v[65]; 
    auto bsr = [&](long long x) -> int { return (x == 0LL) ? -1 : 63-__builtin_clz(x); };
    auto push = [&](long long x, int u) { sz++; v[bsr(x^last)+1].emplace_back(x, u); };
    auto pop = [&]() {
        if (!v[0].size()) {
            int i = 1;
            while (!v[i].size()) { i++; }
            last = min_element(v[i].begin(), v[i].end())->first;
            for (const auto& x : v[i]) { v[bsr(x.first^last)+1].emplace_back(x); }
            v[i].clear();
        }
        pair<long long, int> res = v[0].back();
        sz--; v[0].pop_back(); return res;
    };
    vector<long long> ret((int)g.size(), inf); ret[s] = 0;
    push(ret[s], s);
    while (sz) {
        long long c; int v;
        tie(c, v) = pop();
        if (ret[v] < c) continue;
        for (const auto &e : g[v]) {
            int u; long long nc; tie(u, nc) = e;
            if (ret[u] > ret[v] + nc) {
                ret[u] = ret[v] + nc; push(ret[u], u);
            }
        }
    }
    return ret;
}

int main() {
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    s--; t--;
    vector<vector<pair<int, long long>>> g1(n), g2(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        long long c1, c2;
        cin >> a >> b >> c1 >> c2;
        a--; b--;
        g1[a].emplace_back(b, c1);
        g1[b].emplace_back(a, c1);
        g2[a].emplace_back(b, c2);
        g2[b].emplace_back(a, c2);
    }
    
    vector<long long> d1 = dijkstra(g1, s); // yen
    vector<long long> d2 = dijkstra(g2, t); // snuuk
    vector<long long> d(n);
    for (int i = 0; i < n; i++) d[i] = d1[i] + d2[i];
    for (int i = n-1; i > 0; i--) d[i-1] = min(d[i-1], d[i]);
    
    for (auto& ans : d) cout << MAX - ans << '\n';
    return 0;
}

Measured memory_bytes: 19108
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    int n;
    while(cin >> n, n){
        string s[n];
        vector<int> app[n], cnt(30, n+1);
        for(int i = 0; i < n; i++){
            cin >> s[i];
            int k;  cin >> k;
            while(k-- > 0){
                int x;  cin >> x;
                app[i].push_back(x);
                cnt[x]--;
            }
        }
        vector<pair<int,string>> ans;
        for(int i = 0; i < n; i++){
            int tmp = 0;
            for(int k : app[i]){
                tmp += cnt[k];
            }
            ans.push_back({tmp, s[i]});
        }
        sort(ans.begin(), ans.end());
        cout << ans[0].first << " " << ans[0].second << endl;
    }
    return 0;
}


Measured memory_bytes: 3192
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <utility>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <map>
#include <unordered_map>
#include <limits>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const ll lim = 1e18;

int main()
{
    ll N, res;
    scanf("%lld", &N);
    scanf("%lld", &res);
    for (ll i = 1; i < N; i++)
    {
        ll A, pre = res;
        scanf("%lld", &A);
        if (res != -1 || A == 0)
            res *= A;
        if ((pre != 0 && A > 0xffffffffffffffff / pre) || res > lim)
        {
            res = -1;
        }
        if (res == 0)
            break;
    }

    printf("%lld\n", res);
}


Measured memory_bytes: 3752
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    ll a, b;
    cin >> a >> b;
    for(int i = 0; i < 50000; i++) {
        int aa = int(floor(double(i)*0.08));
        int bb = int(floor(double(i)*0.10));
        if (aa == a && bb == b) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

  bool ok = true;
  rep(i, S.size()) {
    if (i % 2 == 0) {
      if (S[i] == 'L')
        ok = false;
    } else {
      if (S[i] == 'R')
        ok = false;
    }
  }
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vv vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 100000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;
int food[5];
int foodT[5];
int last = 10;
int total = 0;
int A;
int B;

signed main(void) {
    cin >> A >> B;
    if(A>B) {
        cout << 2*A-1 << endl;
    }
    if(B>A) {
        cout << 2*B-1 << endl;
    }
    if(A==B) {
        cout << 2 * A << endl;
    }







    return 0;
}



Measured memory_bytes: 256
/*
      author  : nishi5451
      created : 14.08.2020 21:36:40
*/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;


int main(){
    int l;
    cin >> l;
    double a = l/3.0;
    printf("%.12lf\n",a*a*a);
    return 0;
}

Measured memory_bytes: 3804
#include <stdio.h>

int main()
{
    long a, b ,c, k;
    scanf("%ld %ld %ld %ld", &a, &b, &c, &k);
    
    if(k%2==0) printf("%d", a-b);
    else printf("%d", (a-b)*(-1));

    return 0;
}

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

int main()
{
    int k , n , i; 
    cin>>k>>n;
    long long int a[n] , min=1000000009;
    for(i = 0 ; i < n ; i++) cin>>a[i];
    for(i= 0 ; i < n-1 ; i++)
    {
        if((k-(a[i+1]-a[i]))<min)
        {
            min=(k-(a[i+1]-a[i]));
        }
    }
    
    if(k-(a[0]+k-a[n-1])<min) min=k-(a[0]+k-a[n-1]);
    cout<<min<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "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; }

template<class T> inline auto __lcm(T& a, T& b) 
{ return a * b / __gcd(a, b); }

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


int main() {
    int N;  cin >> N;
    vector<int> L(N);  rep(i, N) cin >> L[i];

    sort(L.begin(), L.end());

    ll cnt = 0;
    rep(i, L.size()-2) {
        for (int j = i+1; j < L.size()-1; j++) {
            ll tmp = L[i] + L[j];
            for (int k = j+1; k < L.size(); k++) {
                if (tmp <= L[k]) break;
                else {
                    cnt++;
                }
            }
        }
    }

    print(cnt);

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

ll cnt(vector<ll>& c) {
	ll ret=0;
	REP(i,(1<<(ll)c.size())) {
		bitset<64> bi(i);
		if(bi.count()%2) continue;
		vector<ll> tmp;
		REP(j,c.size()) {
			if(bi[j]) tmp.pb(c[j]);
		}
		bool d=true;
		REP(i,tmp.size()/2) if(tmp[i]!=tmp[tmp.size()/2+i]) d=false;
		if(d&&tmp.size()) ret++;
	}
	return ret;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin>>n;
	vector<ll> v;
	ll _n=n;
	while(_n>0) {
		v.pb(_n);
		_n=(_n-1)/2;
	}
	reverse(ALL(v));
	vector<ll> a;
	vector<ll> b;
	ll tmp=0;
	if(v[0]==1) {
		a.pb(1);
		b.pb(1);
		tmp=2;
	} else {
		a.pb(2);
		a.pb(1);
		b.pb(1);
		b.pb(2);
		tmp=3;
	}
	FOR(j,1,v.size()) {
		if(v[j]==v[j-1]*2+1) {
			a.insert(a.begin(),tmp);
			b.insert(b.begin(),tmp);
			tmp++;
		} else {
			a.insert(a.begin(),tmp);
			b.insert(b.begin(),tmp);
			tmp++;
			a.insert(a.begin(),tmp);
			b.push_back(tmp);
			tmp++;
		}
		vector<ll> c;
		REP(i,a.size()) c.pb(a[i]);
		REP(i,b.size()) c.pb(b[i]);
		//cout<<cnt(c)<<endl;
	}
	cout<<a.size()+b.size()<<endl;
	REP(i,a.size()) {
		cout<<a[i]<<" ";
	}
	REP(i,b.size()) {
		cout<<b[i];
		if(i==(ll)b.size()-1) cout<<endl;
		else cout<<" ";
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    int n, m;
    cin >> n >> m;
    dsu d(n);
    rep(i,m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        d.merge(a,b);
    }
    int ans = 0;
    rep(i,n) if (d.leader(i) == i) ans++;
    ans--;
    cout << ans << endl;
    return 0;  
}

Measured memory_bytes: 3816
#include <iostream>
#include <vector>
#include <queue>
#define to first
#define cost second
const int inf=1e9+7;
using namespace std;
int main(){

  int n,tmp,r=0,now=0,flag[100]={};
  cin>>n;
  vector <pair<int,int> > gl[n];
  priority_queue < pair<int,int>, vector< pair<int,int> >, greater< pair<int,int> > >q;

  for(int i=0;i<n;i++) for(int j=0;j<n&&cin>>tmp;j++) if(tmp!=-1) gl[i].push_back(make_pair(j,tmp));
  for(int j=0;j<n-1;j++){
    for(int i=0;i<gl[now].size();i++) if(!flag[gl[now][i].to]) q.push(make_pair(gl[now][i].cost,gl[now][i].to));
    flag[now]=1;
    for(;flag[q.top().second];) q.pop();
    r+=q.top().first;
    now=q.top().second;
    q.pop();
  }
  cout<<r<<endl;
  return 0;

}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(ll i=a;i<n;i++)
#define ve vector
#define ss second 
#define ff first
#define pf pop_front
#define pob pop_back
#define psf push_front
#define res(x) cout<<x<<'\n'
#define read(t) ll t;cin>>t

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    ll n;
    cin>>n;
    map<ll,ll>m;
    ll a[n];
    f(i,0,n){
        cin>>a[i];
        m[a[i]]++;
    }
    map<ll,ll>m2;
    ll ans=0;
    for(ll i=0;i<n;i++){
        if(m2[a[i]]==0&&m[a[i]]>1){
            ans=ans+m[a[i]]*(m[a[i]]-1)/2;
        }
        m2[a[i]]=1;
    }
    for(ll i=0;i<n;i++){
        if(m[a[i]]>1){
            ll temp=ans-m[a[i]]*(m[a[i]]-1)/2 +(m[a[i]]-1)*(m[a[i]]-2)/2;
            cout<<temp<<endl;
        }
        else{
            cout<<ans<<endl;
        }
    }
    


   

}

Measured memory_bytes: 18944
#include<iostream>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a<b){
		cout<<"a < b"<<endl;
	}else if(a>b){
		cout<<"a > b"<<endl;
	}else{
		cout<<"a == b"<<endl;
	}
return 0;
}


Measured memory_bytes: 3072
#include<cstdio>
#include<deque>
#include<vector>
#include<algorithm>
using namespace std;

typedef long long ll;

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

	vector<char> v;
	while (N){
		if (N % 2){
			N = (N - 1) / 2;
			v.push_back('R');
		}
		else{
			N--;
			v.push_back('L');
		}
	}

	reverse(v.begin(), v.end());

	deque<int> dq;
	for (int i = 0; i < v.size(); i++){
		char q = v[i];
		if (q == 'L') dq.push_front(i + 1);
		else dq.push_back(i + 1);
	}

	printf("%d\n", dq.size() * 2);
	for (int i = 1; i <= dq.size(); i++) printf("%d ", i);
	for (int x : dq){
		printf("%d ", x);
	}
	printf("\n");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

ll need(const vecll& a, const vecll& f, ll th) {
  ll sum = 0;
  for (auto&& p : index(a)) {
    ll fi = f[p.index()];
    ll must = th / fi;
    sum += std::max(0l, p.value() - must);
  }
  return sum;
}

int main()
{
  ll n,k;
  cin>>n>>k;
  vecll a(n);
  for(auto& e:a) cin>>e;
  vecll f(n);
  for(auto& e:f) cin>>e;
  boost::sort(a);
  boost::sort(f);
  boost::reverse(f);
  ll hi = 1ll << 40;
  ll lo = 0;
  while ((hi-lo) > 1) {
    ll mid = (hi+lo) / 2;
    if (need(a,f,mid) <= k) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  if (need(a,f,0) <= k) {
    cout<<0<<endl;
  } else {
    cout<<hi<<endl;
  }
  return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define MOD2 1494318097
#define SEED 131
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXN 200005

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unordered_map<int,int> umii;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

mt19937 g1(time(0));

int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}
ll randlong(ll a,ll b){return uniform_int_distribution<long long>(a, b)(g1);}

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

int num_nodes,num_q,in[MAXN],out[MAXN],cnt;
ll diff[MAXN];
vector<int> connections[MAXN];

void dfs(int node, int prev){
	in[node] = ++cnt;
	for(int check:connections[node]){
		if(check == prev) continue;
		dfs(check,node);
	}
	out[node] = cnt;
}

int main(){
	scanf("%d %d",&num_nodes,&num_q);
	for(int i=1; i<num_nodes; i++){
		int a,b; scanf(" %d %d",&a,&b);
		connections[a].pb(b);
		connections[b].pb(a);
	}
	dfs(1,-1);
	while(num_q--){
		int n,v; scanf(" %d %d",&n,&v);
		diff[in[n]]+=v;
		diff[out[n]+1]-=v;
	}
	for(int i=1; i<=cnt; i++)
		diff[i]+=diff[i-1];
	for(int i=1; i<=num_nodes; i++)
		printf("%lld ",diff[in[i]]);
}

Measured memory_bytes: 25856
#include <bits/stdc++.h>
#define x first
#define y second
#define int int long long // 2e9 & 9e18
using namespace std; const int inf = numeric_limits<int>::max();
struct __io{__io(){ios_base::Init i; ios_base::sync_with_stdio(0); cin.tie(0);}} __io; // fast I/O
#ifdef LOCAL // setting up print debugging (yes lol)
template<class K, class V>ostream& operator<<(ostream&s,const pair<K,V>&p){s<<'<'<<p.x<<", "<<p.y<<'>';return s;}
template<class T, class=typename T::value_type, class=typename enable_if<!is_same<T,string>::value>::type>
ostream& operator<<(ostream&s,const T&v){s<<'[';for(auto&x:v){s<<x<<", ";}if(!v.empty()){s<<"\b\b";}s<<']';return s;}
void __prnt(){cerr<<endl;} template<class T, class...Ts>void __prnt(T&&a,Ts&&...etc){cerr<<a<<' ';__prnt(etc...);}
#define print(...) __prnt(__VA_ARGS__)
#else
#define print(...)
#endif

signed main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < k; ++i) {
        int d;
        cin >> d;
        for (int j = 0; j < d; ++j) {
            int tmp;
            cin >> tmp;
            a[tmp-1] = 1;
        }
    }
    int count = 0;
    for (int i = 0; i < n; ++i) {
        if (!a[i]) ++count;
    }
    cout << count << endl;
}


Measured memory_bytes: 3644
#include <cstdio>

#include <cmath>
#include <cstring>
#define ll long long
#define f(x,y,z) for(int x=y;x<=z;x++)
using namespace std;
int n,m,x,y,t;
bool a[200005],b[200005],ok;
int main()
{
	scanf("%d%d",&n,&m);
	f(i,1,m)
	{
		scanf("%d%d",&x,&y);
		if(x>y)
		{
			t=x;x=y;y=t;
		}
		if(x==1)a[y]=1;
		if(y==n)b[x]=1;
	}
	f(i,1,n)if(a[i]&&b[i])ok=1;
	if(ok)printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");
}

Measured memory_bytes: 512
#LIS
n=int(input())
lists=[0]*n
for i in range(n):
    lists[i]=int(input())
import bisect
counter=0
lislist=[lists[-1]]
for i in range(2,n+1):
    a=lists[-i]
    index=bisect.bisect_right(lislist,a)
    if index<len(lislist):
        lislist[index]=a

    elif index==len(lislist):
        lislist.append(a)

print(len(lislist))

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

const int dir_h[] = {-1, 0, 1, 0};
const int dir_w[] = { 0,-1, 0, 1};

int main(){
	int X, Y;
	cin >> X >> Y;
	int money = 0;
	if(1 == X) money += 300000;
	if(2 == X) money += 200000;
	if(3 == X) money += 100000;
	if(1 == Y) money += 300000;
	if(2 == Y) money += 200000;
	if(3 == Y) money += 100000;
	if(1 == X && 1 == Y) money += 400000;
	cout << money << endl;
	return 0;
}


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

int main() {
    ll N;
    cin >> N;
    map<string, int> items;
    for(int i=0;i<N;i++){
        string S;
        cin >> S;
        items[S] = 1;
    }
    cout << items.size() << endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  bool finish=false;
  for(int i=0;i<1000;i++){
    for(int j=1;j<1000;j++){
      int B=i-j;
      if(i*i*i*i*i-B*B*B*B*B==N){
        cout << i << " " << B << endl;
        finish=true;
        break;
      }
    }
    if(finish){
      break;
    }
  }
}

        
        
        

Measured memory_bytes: 3636
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4,avx")
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int x[100000],y[100000],x_mod_k[100000],x_div_k[100000];
char s[100000][2];
int cnt[100000];
int n,k;

void add(int x,int t){//(x+??)/k%2=t
	if((x_div_k[x]&1)==0){
		if(t==0){//たさない
			cnt[0]++;
			cnt[k-x_mod_k[x]]--;
		}
		else{//たす
			cnt[k-x_mod_k[x]]++;
		}
	}
	else{
		if(t==0){
			cnt[k-x_mod_k[x]]++;
		}
		else{
			cnt[0]++;
			cnt[k-x_mod_k[x]]--;
		}
	}
}
signed main(){
	scanf("%d%d",&n,&k);
	rep(i,n){
		scanf("%d%d%s",&x[i],&y[i],s[i]);
		x_mod_k[i]=y[i]%k;
		x_div_k[i]=y[i]/k;
	}
	int Max=0;
	rep(i,k){
		memset(cnt,0,sizeof(cnt));
		rep(j,n){
			if(s[j][0]=='B'){
				if(((x[j]+i)/k)%2==0){//(y[j]+t)/K%2=0
					add(j,0);
				}
				else{
					add(j,1);
				}
			}
			else{
				if(((x[j]+i)/k)%2==0){//(y[j]+t)/K%2=1
					add(j,1);
				}
				else{
					add(j,0);
				}
			}
		}
		rep(j,k){
			if(j)cnt[j]+=cnt[j-1];
			Max=max({Max,cnt[j],n-cnt[j]});
		}
	}
	cout<<Max<<endl;
}

Measured memory_bytes: 2432
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>
#include<math.h>
using namespace std;

int main() {
	int money,cake, donut;
	cin >> money >> cake >> donut;
	cout << (money-cake)%donut << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
import bisect
def input():
    return sys.stdin.readline()[:-1]
s=input()
t=input()
ss=s+s
al=[-1]*26
for i in range(len(ss)):
    tmp=ord(ss[i])-ord("a")
    if al[tmp]==-1:
        al[tmp]=[i]
    else:
        al[tmp].append(i)
ans=0
now=0
for i in range(len(t)):
    tmp=ord(t[i])-ord("a")
    if al[tmp]==-1:
        print(-1)
        exit()
    tmp2=bisect.bisect_left(al[tmp],now)
    # print(al[tmp],tmp2)
    ans+=al[tmp][tmp2]-now+1
    now=al[tmp][tmp2]+1
    if now>=len(s):
        now-=len(s)
    # print(ans,now)
print(ans)

Measured memory_bytes: 54640
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		long ans = 0;

		for(int i = 1; i <= k; i++) {
			for(int j = 1; j <= k; j++) {
				for(int a = 1; a <= k; a++) {
					int temp = getGcd(i, j);
					ans += getGcd(a, temp);
				}
			}
		}

		System.out.println(ans);
		sc.close();
	}

	private static int getGcd(int p, int q){
		while(q != 0){
			int r = p % q;
			p = q;
			q = r;
		}
		return p;
	}

}

Measured memory_bytes: 35796
// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
// never rely on floating point calculation
#include<bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                    long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                   1000000007
#define eps                   0.000000000000001
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define pll                  pair < ll , ll >
#define endl                 '\n'
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
vector<int> adj[200010],vis(200010,0),dis(200010,inf),fin(200010,0),col(200010,0),par(200010,0);
int myrandom (int i) { return std::rand()%i;}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    string s,t;
    cin>>s>>t;
    int cnt=0;
    f(i,3)
    {
        if(s[i]==t[i])
        {
            cnt++;
        }
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 9468
package main

import (
	"fmt"
	"sort"
)

func main() {
	var (
		n, alice, bob int
	)
	fmt.Scan(&n)
	cards := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&cards[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(cards)))
	for i := 0; i < n; i += 2 {
		alice += cards[i]
		if i+1 < n {
			bob += cards[i+1]
		}
	}
	fmt.Println(alice - bob)
}


Measured memory_bytes: 512