akhauriyash/Code-Regression huggingface dataset:
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define show(n) cerr<<#n<<" = "<<n<<endl
#define showp(n) cerr<<n.fs<<", "<<n.sc<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showsp(n) for(auto z:n){cerr<<z.fs<<" "<<z.sc<<", "}cerr<<endl

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

inline void io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}
template<typename T> inline void in(T &e){cin>>e;}
template<typename T> inline void out(T e){cout<<e<<endl;}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

const int MAX_N=52;

int n;
vector<string> vs(2);
int ans;
bool l;

signed main(){
    io();
    in(n);
    in(vs[0]);
    in(vs[1]);

    if(vs[0][0]==vs[1][0]) {
        l=true;
        ans=3;
    }else{
        l=false;
        ans=6;
    }

    REP(i,l?1:2,n){
        if(vs[0][i]==vs[1][i]){
            if(l){
                ans*=2;
                ans%=MOD;
            }
            l=true;
        }else{
            if(l){
                ans*=2;
                ans%=MOD;
            }else{
                ans*=3;
                ans%=MOD;
            }
            l=false;
            i++;
        }
    }
   
    out(ans);

    return 0;
}


Measured memory_bytes: 256
if __name__ == "__main__":
  N,M = (int(x) for x in input().split())
  vote = [int(x) for x in input().split()]
  vote.sort(reverse=True)
  point = sum(vote)/(4*M)
  flag=1
  for i in vote[:M]:
    if i < point:
      print('No')
      flag=0
      break
  if flag == 1:
    print('Yes')

Measured memory_bytes: 3064
//
//AtCoder Beginner Contest 173
//C
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

int main()
{
    int H ,W ,K;
    cin >> H >> W >> K;

    string t[H][W];
    REP(h, H){
        string s;
        cin >> s;
        REP(w, W){
            t[h][w]=s[w];
        }
    }

    int ans =0;

    REP(bitH, (1 << H)){
        vector<int> hp;
        REP(i, H){
            if (bitH & (1 << i)) {
                hp.push_back(i);
            }
        }

        REP(bitW, (1 << W)){
            vector<int> wp;
            REP(i, W){
                if (bitW & (1 << i)) {
                    wp.push_back(i);
                }
            }

            int b=0;

//            REP(i, hp.size()) cout << hp[i];
//            cout << ":hp" << endl;
//            REP(i, wp.size()) cout << wp[i];
//            cout << ":wp" << endl;
            
            REP(hh, H){
                if (find(ALL(hp), hh) != hp.end()) continue;
                REP(ww, W){
                    if (find(ALL(wp), ww) != wp.end()) continue;
                    if (t[hh][ww]=="#") {
                        b++;
                    }
                }
            }
            if (b==K) {
                //cout << h << " " << w << endl;
                ans++;
            }

        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>

int main(void)
{
	int i,n,min=0,max=0;
	long sum=0;
	int num[10000];
	
	scanf("%d",&n);
	for(i=0;i<10000;i++)
		num[i]=0;
	
	for(i=0;i<n;i++){
		scanf("%d",&num[i]);
	}
	
	min=num[0];
	max=num[0];
	sum+=num[0];
	for(i=1;i<n;i++){
		sum+=num[i];
		if(min>num[i]) min=num[i];
		if(max<num[i]) max=num[i];
	}
	
	printf("%d %d %ld\n",min,max,sum);
	
	return 0;
}
		

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
 
#define mo 1000000007
#define inf 1e18
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rrep(i,s,n) for(ll i=s;i>=n;i--)

ll mod(ll n) { return (n % (ll)mo + (ll)mo)%(ll)mo;}


int main(){

	ll n;
	cin>>n;
	
	ll m1 = 1;
	
	rep(i,1,n+1){
		m1 = mod(m1*10);
	}
	
	ll m2 = 1;
	
	rep(i,1,n+1){
		m2 = mod(m2*8);
	}
	
	ll m3 = 1;
	
	rep(i,1,n+1){
		m3 = mod(m3*9);
	}
	m3 = mod(2*m3 - m2);
	
	cout<<mod(m1-m3);

	
	
}

Measured memory_bytes: 3616
#include<iostream>
using namespace std;
int main() {
	string s; cin >> s;
	if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2])cout << "Yes" << endl;
	else if (s[0] == s[2] && s[1] == s[3] && s[0] != s[1])cout << "Yes" << endl;
	else if (s[0] == s[3] && s[1] == s[2] && s[0] != s[1])cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----

/**
 * Disjoint set data structure, uses compression by height.
 */
class DisjointSet
{
public:
    DisjointSet(int _n)
    {
        n = _n;
        root.resize(n);
        height.resize(n);

        for (int i = 0;i < n; i++) {
            root[i] = i;
            height[i] = 0;
        }
    }

    int getRoot(int x)
    {
        if (root[x] == x)
            return x;

        return root[x] = getRoot(root[x]);
    }

    void merge(int x, int y)
    {
        int rx = getRoot(x), ry = getRoot(y);
        if (rx == ry)
            return;

        if (height[rx] < height[ry]) {
            root[rx] = ry;
        } else if (height[rx] > height[ry]) {
            root[ry] = rx;
        } else {
            root[ry] = rx;
            height[rx]++;
        }
    }
private:
    int n;
    vector<int> root, height;
};
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N;
    cin >> N;
    DisjointSet dset(N);
    int M, K;
    cin >> M >> K;
    VEC(VEC(int)) unfit(N);
    FOR(i, 0, M + K) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        unfit[a].push_back(b);
        unfit[b].push_back(a);
        if (i < M)
            dset.merge(a, b);
    }

    map<int, int> counts;
    FOR(i, 0, N)
        counts[dset.getRoot(i)]++;

    FOR(i, 0, N) {
        int comp = dset.getRoot(i);
        int count = counts[comp];
        for (int c : unfit[i])
            if (dset.getRoot(c) == comp)
                count--;
        cout << --count << " ";
    }

    cout << endl;
    return 0;
};

Measured memory_bytes: 10880
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));

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

	int A[4]={0};
	REP(i,3){
		int a,b;
		cin>>a>>b;
		A[a-1]++;
		A[b-1]++;
	}
	REP(i,4){
		if(A[i]==3 || A[i]==0){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 384
//go:generate echo "https://atcoder.jp/contests/dp/tasks/dp_c"
package main

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

type scanner struct{ *bufio.Scanner }

func newScanner(r io.Reader) *scanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	s.Buffer(nil, 100000000)
	return &scanner{s}
}

func (s *scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *scanner) IntSlice(l int) []int {
	if l == 0 {
		return []int{}
	}
	sl := make([]int, l, l)
	for i := range sl {
		sl[i] = s.Int()
	}
	return sl
}

func (s *scanner) IntSlice2(l, n int) []int {
	if l == 0 {
		return []int{}
	}
	sl := make([]int, l, l)
	for i := 0; i < n; i++ {
		sl[i] = s.Int()
	}
	return sl
}

func solve(n int, u [][]int) int {
	t := make([][]int, n+1, n+1)
	for i := range t {
		t[i] = make([]int, 3, 3)
	}
	for i := 0; i < n; i++ {
		for j := 0; j < 3; j++ {
			for k := 0; k < 3; k++ {
				if j == k {
					continue
				}
				if v := t[i][j] + u[i][k]; t[i+1][k] < v {
					t[i+1][k] = v
				}
			}
		}
	}
	max := math.MinInt64
	for _, v := range t[n] {
		if max < v {
			max = v
		}
	}
	return max
}

func main() {
	scan := newScanner(os.Stdin)
	n := scan.Int()
	u := make([][]int, n+1, n+1)
	for i := 0; i <= n; i++ {
		u[i] = []int{scan.Int(), scan.Int(), scan.Int()}
	}
	fmt.Println(solve(n, u))
}


Measured memory_bytes: 13724
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
using namespace std;

int main(){
	while(1){
		int n;
		cin >> n;
		if(!n) break;
		vector <int> s(n);
		double ave=0, hensa=0;
		for(int i=0;i<n;i++){
			cin >> s[i];
			ave += s[i];
		}
		ave /= n;
		for(int i=0;i<n;i++){
			hensa += (s[i]-ave)*(s[i]-ave);
		}
		hensa = sqrt(hensa/n);
		cout << fixed << setprecision(12) <<  hensa << endl;
	}
	return 0;
}

Measured memory_bytes: 1264
from pprint import pprint
n,m=map(int,input().split())
c=list(map(int,input().split()))
dp=[[10**5]*(n+1) for _ in range(m+1)]
dp[0][0]=0
for i in range(m):
    for j in range(n+1):
        if c[i]>j:
            dp[i+1][j]=dp[i][j]
        else:
            dp[i+1][j]=min(dp[i][j],dp[i][j-c[i]]+1,dp[i+1][j-c[i]]+1)
# pprint(dp)
print(dp[m][n])


Measured memory_bytes: 44560
from collections import defaultdict

d=defaultdict(int)

N=input()
a=list(map(int,input().split(" ")))
ans=0
for z in a:
  d[z]+=1

for k in d:
  if d[k]-k>=0:
    ans+=d[k]-k
  else:
    ans+=d[k]

print(ans)

Measured memory_bytes: 18672
/*starting with the name of almighty ALLAH*/
/*solved by RAKIB JOY*/
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define vc vector
#define vi vc<int>
#define vl vc<ll>
#define dbg(x) cout<<x<<endl;
#define mp(x,y) make_pair(x,y)
#define yes dbg("YES")
#define no dbg("NO")
#define tst int t;cin>>t;while(t--)
#define srt(v) sort(v.begin(),v.end());
#define rsrt(v) sort(v.begin(),v.end(),greater<int>());
#define rj ios::sync_with_stdio(false);cin.tie(0);
#define rvs(v) reverse(v.begin(),v.end());
#define F first
#define S second
using namespace std;
int main()
{
    rj
    long double a,b=3.141592654;
    cin>>a;
    cout<<2LL*a*b<<endl;


    return 0;
}


Measured memory_bytes: 3820
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll a,b,c,k,ans;
	cin>>a>>b>>c>>k;
	if(a>=k)	cout<<k;
	else
	{
		ans=a;
		if(a+b>=k)	cout<<ans;
		else
		{
			ans-=k-a-b;
			cout<<ans;
		}		
	}
return 0;
}



Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a= sc.nextInt(),b= sc.nextInt();
switch (a) {
    case 1:
        if(b==2){
        System.out.println("3");
     }else{
        System.out.println("2");
     }
    break;
    case 2:
        if(b==1){
        System.out.println("3");
     }else{
        System.out.println("1");
     }
    break;
    case 3:
        if(b==1){
        System.out.println("2");
     }else{
        System.out.println("1");
     }
    break;
    default:
    // 式の値がどのcaseの値とも一致しなかったときの処理
}

    }
}

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

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

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll A, B, C, D;

ll gcd(ll A, ll B){
    if(A<B) swap(A, B);
    ll C = B;
    while(C != 0){
        C = A%B;
        A = B;
        B = C;
    }
    return A;
}

ll lcm(ll A, ll B){
    ll C = gcd(A, B);
    return A*(B/C); //()がないとオーバーフローする可能性があるので注意！
}

ll kosu(ll X){
	ll E = lcm(C, D);
	return X - X/C - X/D + X/E;
}

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

    cin >> A >> B >> C >> D;
    cout << kosu(B) - kosu(A-1) << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <limits.h>
#include <assert.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <bitset>
#include <vector>
using namespace std;

#define LL long long

#define fi first
#define se second
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(a,b) (((a)+(b))>>1)
#define maxx(a,b) ((a)<(b)?(b):(a))
#define minx(a,b) ((a)<(b)?(a):(b))
#define absx(a) ((a)<0?-(a):(a))
#define mk(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define itr iterator
#define lowbit(x) ((x)&-(x))

typedef unsigned LL ULL;
typedef unsigned uint;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;

template< typename T > inline void read(T &x) {
    bool f; char ch; f=0; x=0; ch=getchar();
    while(ch<'0' || ch>'9') {if(ch=='-') f=1; ch=getchar();}
    while(ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
    if(f) x=-x;
}

template< typename T > inline void Max(T &a, T b) {if(a<b) a=b;}
template< typename T > inline void Min(T &a, T b) {if(b<a) a=b;}
template< typename T > inline T Abs(T a) {if(a<0) return -a; else return a;}

const double pi=(double) acos(-1.0);
const int MOD=(int) 1e9+7;
const int INF=(int) 0x3f3f3f3f;
const LL  LINF=(LL) INF<<32|INF;
const int SINF=(uint) ~0>>1;
const LL  SLINF=(ULL) (-1)>>1;
const double DINF=(double) 1e50;
const double eps=(double) 1e-12;
const int maxn=(int) 100000+20;
const int maxm=(int) 1e6+20;
const int maxk=(int) 5e2+20;

inline int sig(double x) {return x<-eps?-1:x>eps;}

//--------------start------------------

int n,m;
multiset<int> A,B;

void work()
{
    read(n);
    while(n--)
    {
        int x; read(x);
        A.insert(x);
    }
    read(m);
    while(m--)
    {
        int x; read(x);
        B.insert(x);
    }

    while(B.size())
    {
        if(A.find(*B.begin())==A.end())
        {
            puts("NO");
            return ;
        }
        else
        {
            A.erase(A.find(*B.begin()));
            B.erase(B.begin());
        }
    }
    puts("YES");
}

//--------------end--------------------

int main()
{
#ifdef yukihana0416
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif // yukihana0416
    work();
    return 0;
}


Measured memory_bytes: 18944
#include <bits/stdc++.h>
const long long MOD = 1e9+7;
using namespace std;

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

	int X,T;
	cin >> X >> T;

	if (X-T>=0) {
		cout << X-T << endl;
	} else if (X-T<0) {
		cout << 0 << endl;
	}
}


Measured memory_bytes: 3632
import sys
input = sys.stdin.readline
# Segment Tree
# segfunc : min, +, *, xor, gcd など
# identity_element : 単位元(min:inf, 和:0, 積:1, xor:0, gcd:0)


class Segment:
    def __init__(self, N, init_val):
        """[セグメント木]

        Args:
            N ([int]): [要素数]
            init_val ([list]): [初期化する値]
        """
        self.identity_element = 2 ** 31 - 1  # 変える
        self.N0 = 1 << (N - 1).bit_length()
        # 0-indexedで管理
        self.dat = [self.identity_element] * (2 * self.N0)
        # 値を代入
        for i in range(N):
            self.dat[i + self.N0 - 1] = init_val[i]
        # 構築
        for i in range(self.N0 - 2, -1, -1):
            self.dat[i] = self.segfunc(self.dat[2 * i + 1], self.dat[2 * i + 2])

    # k番目の要素の値をxに変更
    def update(self, k, x):
        k += self.N0 - 1
        self.dat[k] = x
        while k >= 0:
            k = (k - 1) // 2
            self.dat[k] = self.segfunc(self.dat[2 * k + 1], self.dat[2 * k + 2])

    # 区間[l,r)の最小値を求める
    def query(self, l, r):
        L = l + self.N0
        R = r + self.N0
        s = self.identity_element
        # 区間を列挙しながら最小値を求める
        while L < R:
            if R & 1:
                R -= 1
                s = self.segfunc(s, self.dat[R - 1])
            if L & 1:
                s = self.segfunc(s, self.dat[L - 1])
                L += 1
            L >>= 1
            R >>= 1
        return s

    def segfunc(self, x, y):
        return min(x, y)  # 変える


def compress(arr):
    *XS, = set(arr)
    XS.sort()
    return {e: i for i, e in enumerate(XS)}


n, q = map(int, input().split())
s, t, x = [0] * n, [0] * n, [0] * n
for i in range(n):
    s[i], t[i], x[i] = map(int, input().split())
    s[i] -= x[i]
    t[i] -= x[i]
    s[i] = max(s[i], 0)
    t[i] = max(t[i], 0)

d = [int(input()) for i in range(q)]

com = compress(s + t + d)
k = len(com) + 1

for i in range(n):
    s[i] = com[s[i]]
    t[i] = com[t[i]]

for i in range(q):
    d[i] = com[d[i]]
INF = 1 << 30
a = [INF] * k
b = [[] for i in range(k)]
c = [[] for i in range(k)]
seg = Segment(n, [INF] * n)
for i in range(n):
    b[s[i]].append(i)
    c[t[i]].append(i)

for i in range(k):
    for j in b[i]:
        seg.update(j, x[j])
    for j in c[i]:
        seg.update(j, INF)
    a[i] = seg.query(0, n)

for i in d:
    print(-1 if a[i] == INF else a[i])


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

using namespace std;
typedef long long ll;

int a[] = {0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

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

int main(void)
{
    int k;
    cin >> k;
    cout << a[k] << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int a,b;
  cin>>a>>b;
  char c[100][100];
  rep(i,0,50){
    rep(j,0,100){
      c[i][j]='.';
    }
  }
  rep(i,50,100){
    rep(j,0,100){
      c[i][j]='#';
    }
  }
  int cur=1;
  for(int i=0;i<50;i+=2){
    for(int j=0;j<100;j+=2){
      if(cur==b) break;
      c[i][j]='#';
      cur++;
    }
    if(cur==b) break;
  }
  cur=1;
  for(int i=51;i<100;i+=2){
    for(int j=0;j<100;j+=2){
      if(cur==a) break;
      c[i][j]='.';
      cur++;
    }
    if(cur==a) break;
  }
  cout<<100<<' '<<100<<endl;
  rep(i,0,100){
    rep(j,0,100){
      cout<<c[i][j];
    }
    cout<<endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

    int N,M,A,sum = 0;
    scanf("%d %d",&N,&M);

    for (int i = 0;i < M;i++){
        scanf("%d",&A);
        sum += A;

        if (sum > N){
            printf("-1");
            return 0;
        }
    }
    N = N - sum ;
    printf("%d",N);



    return 0;
}

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

using namespace std;

#ifdef SG
	#include <debug.h>
#else
	#define show(...)
	#define debug(...)
	#define deepen(...)
	#define timer(...)
#endif

#define ARG4(_1,_2,_3,_4,...) _4

#define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
#define forn2(i,n) forn3 (i, 0, n)
#define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)

#define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
#define ford2(i,n) ford3 (i, 0, n)
#define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)

#define ve vector
#define pa pair
#define tu tuple
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fs first
#define sc second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)(a).size())

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned char uc;
typedef pa<int, int> pii;
typedef pa<int, ll> pil;
typedef pa<ll, int> pli;
typedef pa<ll, ll> pll;
typedef ve<int> vi;

const ld pi = 3.1415926535897932384626433832795l;

template<typename T> inline auto sqr (T x) -> decltype(x * x) {return x * x;}
template<typename T1, typename T2> inline bool umx (T1& a, T2 b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T1, typename T2> inline bool umn (T1& a, T2 b) {if (b < a) {a = b; return 1;} return 0;}

const int N = 200100;
int p[N];
int l[N], r[N];
int rnd;

int get(int a) {
	if (a == p[a])
		return a;
	return p[a] = get(p[a]);
}

void uni(int L, int R) {
	L = get(L), R = get(R);
	if (L == R)
		return;
	if (rnd ^= 1)
		swap(L, R);
	p[L] = R;
	umx(r[R], r[L]);
	umn(l[R], l[L]);
}

int a[N];
int n;
pii ord[N];

int main () {
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(20);
#ifdef SG
	freopen((problemname + ".in").c_str(), "r", stdin);
//	freopen((problemname + ".out").c_str(), "w", stdout);
#endif
	rnd = 0;
	cin >> n;
	forn(i, n) {
		scanf("%d", &a[i]);
		a[i]--;
	}	
	forn(i, n) {
		ord[i] = mp(a[i], i);
	}
	sort(ord, ord + n);
	reverse(ord, ord + n);
	forn(i, n) {
		p[i]  = i;
		l[i] = i, r[i] = i;
	}
	ll ans = 0;
	forn(i, n) {
		int idx = ord[i].sc, val = ord[i].fs;
		if (idx > 0 && a[idx - 1] > val) {
			uni(idx, idx - 1);
		}
		if (idx + 1 < n && a[idx + 1] > val) {
			uni(idx, idx + 1);
		}
		int root = get(idx);
		ans += 1ll * (r[root] - idx + 1) * (idx - l[root] + 1) * (val + 1);
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	vector<int> X(N), Y(N);
	REP(i, N) scanf("%d %d", &X[i], &Y[i]), --X[i], --Y[i];
	
	vector<pii> P(N); // [i] := X = i, {Y, idx}
	REP(i, N) P[X[i]] = {Y[i], i};
	
	vector<int> ans(N), add(N);
	int sum = 0, pr = -1;
	REP(i, N) {
		if (N - 1 - P[i].first < i) ++sum;
		else ++add[N - 1 - P[i].first];
		sum += add[i];
		if (sum == i + 1) {
			FOR(j, pr + 1, i + 1) ans[P[j].second] = i - pr;
			pr = i;
		}
	}
	
	REP(i, N) printf("%d\n", ans[i]);
	
	return 0;
}


Measured memory_bytes: 8048
N = int(input())
M = list(map(int, input().split()))

S1 = 0
S2 = sum(M)
result = []

for i in range(N-1):
    S1 += M[i]
    S2 -= M[i]
    result.append(abs(S1 - S2))

print(min(result))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define REP(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define FI first
#define SE second
#define PB push_back
#define EB emplace_back
#define SZ(x) (int)(x).size()
#define BN(x) ((1<<x)-1)
#define DUP(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

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

int cnt[200010];

int main () {
  int N, K; cin >> N >> K;
  REP(i,N) {
    int a; cin >> a;
    cnt[a-1]++;
  }

  sort(cnt,cnt+N);
  int ans = 0;
  REP(i,N-K) {
    ans += cnt[i];
  }

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
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; }

const string a = "ATGC";

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int num = 0, ans = 0;
  for (auto e : s) {
    if (a.find(e) < 4)
      num++;
    else {
      chmax(ans, num);
      num = 0;
    }
  }
  chmax(ans, num);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3660
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::collections::HashMap;

fn main() {
    input!{
        n: usize,
        k: usize,
        v: [usize; n]
    }
    let mut sum: Vec<usize> = v.iter().scan(0, |ac, x| {*ac = *ac + x; Some(*ac)}).collect();
    sum.insert(0, 0);
    let mut tab = Vec::new();
    for i in 0..n {
        for j in i + 1..n + 1 {
            tab.push(sum[j] - sum[i]);
        }
    }
    let mut maxbit = HashMap::new();
    let mut count = vec![0; 64];
    for x in tab.clone() {
        let y = maxbit.entry(x).or_insert_with(|| max_bit(x));
        count[*y] += 1;
    }
    let mut i = 63;
    while i > 0 && count[i] < k {
        i -= 1;
    }
    if i == 0 {
        if count[0] < k {
            println!("0");
        } else {
            println!("1");
        }
        return;
    }
    let mut ans = 1 << i;
    let mut tab_i: Vec<usize> = tab.iter().filter(|x| *x & ans != 0).map(|x| *x).collect();
    while i > 0 {
        i -= 1;
        let next: Vec<usize> = tab_i.iter().filter(|x| *x & (1 << i) != 0).map(|x| *x).collect();
        if next.len() >= k {
            ans += 1 << i;
            tab_i = next;
        }
    }
    println!("{}", ans);
}

fn max_bit(n: usize) -> usize {
    let mut ret = 63;
    let mut m = 1 << 63;
    while m > n {
        ret -= 1;
        m >>= 1;
    }
    ret
}


Measured memory_bytes: 48916
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
	int a, b, c, d, n = 0;
	cin >> a >> b >> c >> d;
	if (a < b)
	{
		n = a;
	}
	else
	{
		n = b;
	}
	if (c < d)
	{
		n += c;
	}
	else
	{
		n += d;
	}
	cout << n << endl;
	return 0;
}
/*
死のマウス
.　　あり許せん！
　　　∧＿＿∧
　|| （＃｀Д´ ） ||
　|| ( |　 　| | |||
　从| |　 　| |从从
￣) ⊂ノ￣￣!_つ￣て
　フヘ(　　　　ヽヘ(＼

*/

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int s;
int func(int now,int sum,int num){
	int count=0;
	if(!num)return s==sum?1:0;
	if(now==10 || !num || sum>s) return 0;
	count+=func(now+1,sum+now,num-1);
	count+=func(now+1,sum,num);
	return count;
}

int main(void){
	int n,i;
	while(scanf("%d %d",&n,&s),n){
		printf("%d\n",func(0,0,n));
	}
	return 0;
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define Graph vector<vector<ll>>
#define INF (1ll<<60)
#define mod 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    string N;cin>>N;
    reverse(N.begin(),N.end());
    vector<vector<ll>> dp(1000010,vector<ll>(2/*桁上がりあるか*/,INF));
    dp[0][0]=0;

    N.push_back('0');
    for(ll i=0;i<N.size();i++){
        ll now=N[i]-'0';

        //前桁上がり判定ありの時
        ll nowb=now+1; 
        if(dp[i][1]!=INF){
            //今equal
            chmin(dp[i+1][0],dp[i][1]+nowb);
            
            //今もbigger
            chmin(dp[i+1][1],dp[i][1]+(10-nowb));
        }

        //前桁上がり判定無し
        if(dp[i][0]!=INF){
            //今桁上がり判定無し
            chmin(dp[i+1][0],dp[i][0]+now);
    
            //今桁上がり判定あり
            chmin(dp[i+1][1],dp[i][0]+(10-now));
        }
    }

    cout<<min(dp[N.size()][0],dp[N.size()][1])<<endl; 
    return 0;
}


Measured memory_bytes: 58860
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll INF = 1e10;

int main() {
  int n,w;
  cin>>n>>w;
  int val[n];
  ll wt[n];
  for(int i=0;i<n;i++) cin>>wt[i]>>val[i];
  int vc = n*1000;
  ll dp[n+1][vc+1];
  for(int i=0;i<n+1;i++) dp[i][0]=INF;
  for(int i=1;i<vc+1;i++) dp[0][i]=INF;
  for(int i=1;i<n+1;i++){
  	for(int j=1;j<vc+1;j++) {
    	if(j-val[i-1]>0) {
    	    if(dp[i-1][j-val[i-1]]<INF)
        	    dp[i][j] = min(dp[i-1][j], wt[i-1]+dp[i-1][j-val[i-1]]);	
        	else dp[i][j] = min(dp[i-1][j], INF);
        } 
      	else {
        	dp[i][j] = min(dp[i-1][j], wt[i-1]);
        }
    }
  }
  ll res = 0;
  for(int i=1;i<vc+1;i++) {
  	if(dp[n][i]<=w) {
    	res = i;
    }
  }
  cout<<res<<endl;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); i++)
#define rrep(i, to) for (int i = (to) - 1; i >= 0; i--)
#define repf(i, from, to) for (int i = (from); i < (to); i++)
#define all(v) v.begin(), v.end()
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

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

  int l, r;

  // rr...rww..w の形であれば良い
  l = 0;
  r = n - 1;
  int ans = 0;
  while(true) {
    while(l < n && str[l] == 'R') {
      l++;
    }

    while(l >= 0 && str[r] == 'W') {
      r--;
    }

    if(l <= r) {
      swap(str[l++], str[r--]);
      ans++;
    } else {
      break;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3688
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ll n,k;
    cin>>n>>k;
    ll res=0;
    if(k-1==n){
        cout<<1<<endl;
        return 0;
    }
    rep3(i,k,n+2){
        res+=(2*n-(i-1))*i/2-(i-1)*i/2+1;
        res%=MOD;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 3652
#include<stdio.h>
#include<math.h>
#define pi 3.1415926535897932384

int main(){
  double a,b,x,e,f;
  scanf("%lf%lf%lf",&a,&b,&x);
  x/=a;
  if(a*b*0.5>=x){
    e=2.0*x/b;
    printf("%.12lf\n",90.0-(atan(e/b)/pi)*180.0);
  }
  else{
    e=(2.0*x/a)-b;
    f=b-e;
    printf("%.12lf\n",90.0-(atan(a/f)/pi)*180.0);
  }
  return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

int main(){
	int n;
	int min = 1000000;
	int max = -1000000;
	long int sum = 0;
	cin >> n;
	for(int i = 0; i < n; i++){
		int x;
		scanf("%d", &x);
		if(x<min){
			min = x;
		}
		if(max<x){
			max = x;
		}
		sum += x;
	}
	cout << min << " " << max << " " << sum << "\n";
}


Measured memory_bytes: 3168
N = int(input())
dp = [[0 for i in range(3)] for i in range(N+1)]
for i in range(N):
    a, b, c = map(int, input().split())
    dp[i+1][0] = max(dp[i][1], dp[i][2]) + a
    dp[i+1][1] = max(dp[i][0], dp[i][2]) + b
    dp[i+1][2] = max(dp[i][0], dp[i][1]) + c
print(max(dp[N]))


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

#define fastio  ios::sync_with_stdio(false); cin.tie(0);

struct BeingZero{
    void lcsCalculate(string s1, string s2, vector< vector<int> > &dp){
        for (int i = 1; i <= s1.size(); i++) {
            for (int j = 1; j <= s2.size(); j++) {
                if (s1[i-1] == s2[j-1]) 
                    dp[i][j] = dp[i-1][j-1] + 1;
                dp[i][j] = max(dp[i][j], max(dp[i][j-1], dp[i-1][j]));
            }
        }
    }

    string getLCS(string s1, string s2, vector< vector<int> > &dp){
        string s = "";
        int i = s1.size();
        int j = s2.size();
        while (i > 0 && j > 0){
            if (dp[i-1][j-1] + 1 == dp[i][j] && dp[i-1][j] + 1 == dp[i][j] && dp[i][j-1] + 1 == dp[i][j]){
                i--; 
                j--; 
                s = s1[i] + s; //As we are travelling backward reverse the string
            }
            else if (dp[i][j-1] > dp[i-1][j]) 
                j--;
            else
                i--;
        }
        return s;
    }
};


int main() {
    fastio;
    BeingZero bz;
    string s1, s2;
    while(cin>>s1>>s2){
        int n1=s1.size();
        int n2=s2.size();
        vector< vector<int> > dp(n1+1, vector<int>(n2+1, 0));
        bz.lcsCalculate(s1, s2, dp);
        //cout<<dp[n1][n2]<<"\n";
        cout<<bz.getLCS(s1, s2, dp)<<"\n";
    }
    return 0;
}



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

public class Main{
    public static void main(String[] args){
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    try{
        String str = br.readLine();
        StringTokenizer st = new StringTokenizer(str, " ");
    
        int x = Integer.parseInt(st.nextToken());
        int y = Integer.parseInt(st.nextToken());
        
        int n = 0;
        int m = 0;
        
        n = x * y;
        m = 2 * (x + y);
        
        
        System.out.println(n+" "+m);
       
        
        
    }catch(IOException e){}
    

    }
}

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

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int a, b;
  cin >> a >> b;

  // 解答
  cout << (a <= 8 && b <= 8 ? "Yay!" : ":(") << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>

using namespace std;

typedef pair<long long int,int> P;


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

	string s,t;

	cin >> s >> t;

	bool flag = true;
	int k;

	for(int i=0;i<s.length();i++){
		flag = true;
		for(int j=0;j<s.length();j++){
			if(i+j >= s.length()){
				k = i+j-s.length();
			}else{
				k=i+j;
			}
			if(s[k] != t[j]) {
				flag = false;
				break;
			}
		}
		if(flag){
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";

			
			
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	if (k % 2 == 0) {
		int rec = k / 2;
		ll c1 = 0, c2 = 0;
		for (int i = 1; i <= n; ++i) {
			if (i % k == 0) c1++;
			if (i % k == rec) c2++;
		}
		ll ans = c1 * c1 * c1 + c2 * c2 * c2;
		cout << ans << endl;
	}
	else {
		ll res = n / k;
		ll ans = res * res * res;
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3608
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	

		Scanner sc=new Scanner(System.in);
      
		  int n=sc.nextInt();
      int c1=0,c2=0,c3=0,c4=0;
      
		 for(int i=1;i<=n;i++){
			String s=sc.next();
           if(s.contains("AC")){
				c1++;
		}else if(s.contains("WA")){
c2++;
}else if(s.contains("TLE")){
c3++;
           }else if(s.contains("RE")){
c4++;
           }
                    }
                    System.out.println("AC "+"x "+c1);
                     System.out.println("WA "+"x "+c2);
					 System.out.println("TLE "+"x "+c3);
                     System.out.println("RE "+"x "+c4);
                    }
                    }

Measured memory_bytes: 58000
from sys import stdin
input = stdin.readline
lmi = lambda: list(map(int, input().split()))
mi = lambda: map(int, input().split())

ans = 0
n = int(input())
arr= lmi()
for i in range(n):
    for j in range(i+1, n):
        ans += arr[i]*arr[j]
print(ans)

Measured memory_bytes: 28524
#include <iostream>
#include <vector>
#include <set>
using namespace std;

int main(){
    string s;
    int k;
    cin >> s >> k;
    int n = s.size();
    set<string> st;
    for (int i = 0; i < n; i++){
        for (int j = 1; j <= k && j + i <= n; j++){
            st.insert(s.substr(i, j));
        }
    }
    int count = 0;
    //cout << st.size() << endl;
    for (auto it = st.begin(); it != st.end(); it++){
        count++;
        //cout << *it << endl;
        if (count == k){
            cout << *it << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1664
w,h,n=map(int,input().split())
S=w*h
h1=0
w1=0
xmax=0
ymax=0
xmax_r=0
ymax_r=0



for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        if xmax<x:
            xmax=x
    
    if a==2:
        if xmax_r<w-x:
            xmax_r=w-x
    
    if a==3:
        if ymax<y:
            ymax=y
    
    if a==4:
        if ymax_r<h-y:
            ymax_r=h-y

if (w-xmax-xmax_r)<=0 or (h-ymax-ymax_r)<=0:
    print("0")
else:
    print((w-xmax-xmax_r)*(h-ymax-ymax_r))

Measured memory_bytes: 62280
// javac Main.java && java _

import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) { new Main(); }
	FS in = new FS();
	PrintWriter out = new PrintWriter(System.out);
	
	int n;
	int[] deg;
	ArrayList<int[]>[] adj;
	
	Main() {
		n = in.nextInt();
		deg = new int[n];
		adj = new ArrayList[n];
		for (int i = 0; i < n; i++)
			adj[i] = new ArrayList<>();

		int k = 0;
		for (int i = 0; i < n - 1; i++) {
			int a = in.nextInt() - 1;
			int b = in.nextInt() - 1;
			deg[a]++; adj[a].add(new int[]{b, i});
			deg[b]++; adj[b].add(new int[]{a, i});
		
			k = max(k, deg[a]);
			k = max(k, deg[b]);
		}

		int[] color = new int[n - 1];
		int st = 0;
		for (int i = 0; i < n; i++)
			if (deg[i] == k)
				st = i;

		ArrayDeque<Integer> q = new ArrayDeque<>();
		q.add(st);

		boolean[] vis = new boolean[n];
		vis[st] = true;
		while (q.size() > 0) {
			int node = q.poll();

			int use = 1;
			HashSet<Integer> track = new HashSet<>();
			for (int[] e : adj[node]) {
				if (!vis[e[0]]) {
					vis[e[0]] = true;
					q.add(e[0]);
				}
				if (color[e[1]] != 0) {
					track.add(color[e[1]]);
					continue;
				}
			}

			for (int[] e : adj[node]) {
				if (color[e[1]] != 0)
					continue;
				while (track.contains(use))
					use++;
				color[e[1]] = use;
				track.add(color[e[1]]);
				use++;
			}
		}

		out.println(k);
		for (int i = 0; i < n - 1; i++)
			out.println(color[i]);
		out.close();
	}
	
	

	int min(int a, int b) { if (a < b) return a; return b; }	
	int max(int a, int b) { if (a > b) return a; return b; }	
	long min(long a, long b) { if (a < b) return a; return b; }	
	long max(long a, long b) { if (a > b) return a; return b; }	

	boolean z(int x) { if (x == 0) return true; return false; }
	boolean z(long x) { if (x == 0) return true; return false; }
	
	class FS {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens()) {
				try { st = new StringTokenizer(br.readLine()); }
				catch (Exception e) {}
			} return st.nextToken();
		}
		int nextInt() { return Integer.parseInt(next()); }
		long nextLong() { return Long.parseLong(next()); }
		double nextDouble() { return Double.parseDouble(next()); }
	}
}



Measured memory_bytes: 72024
/*
 *  Lang    : C++
 *  Author  : little_angel
 */
#include <bits/stdc++.h>

using namespace std;
#define ld double

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

    complex<ld> pos(0, 0), npos;
    double x, th = 0;
    cin >> x;
    int k = 0;
    x = x * acos(-1) / 180;
    do {
        npos = pos + polar(1.0, th);
        pos = npos;
        th += x;
        k++;
    } while (abs(pos - complex<ld>(0, 0)) >= 1e-9);
    cout << k << endl;
}

Measured memory_bytes: 4100
#include <bits/stdc++.h>
using namespace std;
#include <bits/stdc++.h>
using namespace std;
const double EPS=1e-10;
double add(double l, double r){
    if(abs(l+r)<EPS*(abs(l)+abs(r))) return 0;
    return l+r;
}
struct Pt{
    double x, y;
    Pt(double xx=0, double yy=0){x=xx; y=yy;}
    Pt& operator=(const Pt &rhs){x=rhs.x; y=rhs.y; return *this;}
    Pt& operator+=(const Pt &rhs){x = add(x,rhs.x); y = add(y,rhs.y); return *this;}
    Pt& operator-=(const Pt &rhs){x = add(x,-rhs.x); y = add(y,-rhs.y); return *this;}
    Pt& operator*=(const double &rhs){x *= rhs; y *= rhs; return *this;}
    Pt& operator/=(const double &rhs){x /= rhs; y /= rhs; return *this;}
};
Pt operator+(const Pt &a){return a;}
Pt operator-(const Pt &a){return Pt(-a.x,-a.y);}
Pt operator+(const Pt &lhs, const Pt &rhs){Pt ans=lhs; ans += rhs; return ans;}
Pt operator-(const Pt &lhs, const Pt &rhs){Pt ans=lhs; ans -= rhs; return ans;}
Pt operator*(const Pt &lhs, const double &rhs){Pt ans=lhs; ans *= rhs; return ans;}
Pt operator*(const double &lhs, const Pt &rhs){Pt ans=rhs; ans *= lhs; return ans;}
Pt operator/(const Pt &lhs, const double &rhs){Pt ans=lhs; ans /= rhs; return ans;}
bool operator==(const Pt &lhs, const Pt &rhs){return add(lhs.x,-rhs.x)==0 && add(lhs.y,-rhs.y)==0;}
bool operator!=(const Pt &lhs, const Pt &rhs){return !(lhs==rhs);}
bool operator<(const Pt &lhs, const Pt &rhs){return add(lhs.x,-rhs.x)!=0 ? add(lhs.x,-rhs.x)<0 : add(lhs.y,-rhs.y)<0;}
bool operator>(const Pt &lhs, const Pt &rhs){return rhs<lhs;}
bool operator<=(const Pt &lhs, const Pt &rhs){return !(lhs>rhs);}
bool operator>=(const Pt &lhs, const Pt &rhs){return !(lhs<rhs);}
istream& operator>>(istream &is, Pt &rhs){double x, y; is >> x >> y; rhs=Pt(x,y); return is;}
ostream& operator<<(ostream &os, const Pt &rhs){ os << rhs.x << " " << rhs.y; return os;}
double norm(const Pt &a){return add(a.x*a.x,a.y*a.y);}
double abs(const Pt &a){return sqrt(norm(a));}

int main(){
	int n; cin >> n;
    vector<Pt> p(n);
    for(Pt &i : p) cin >> i;

    double ans=0;
    for(int i=0; i<n; ++i){
        for(int j=0; j<n; ++j){
            ans += abs(p[i]-p[j]);
        }
    }

    cout << fixed << setprecision(10);
	cout << ans/n << endl;
}

Measured memory_bytes: 256