akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<utility>
#include<array>
#include<cassert>
#include<list>
#include<experimental/any>
#include<cstring>
#include<cctype>
#include<ctime>
#include<cstdbool>
#include<cstdint>
#include<cstddef>
#include<set>
#include<unordered_set>
#include<bitset>
 
using namespace std;
using experimental::any;
 
#define SPEEDY cin.tie(0);ios::sync_with_stdio(false);
 
#define REP(i,n) for(int i=0;i<(n);i++)
#define ARREP(i,n,X) for(int i=0;i<(n);i++)cin>>X[i]
#define FOR(i,X,n) for(int i=(X);i<(n);i++)
#define EREP(i,n) for(int i=1;i<=n;i++)
#define BitFOR(N) REP(Bit,1<<(N))
 
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define TFDEB(f) (f)? cout<<"true ":cout<<"false ";
#define FORDEB(n,X) for(int i=0;i<(n);i++)ARDEB(i,X)
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define ARDEB(i,X) {}
#define TFDEB(f) {}
#define FORDEB(n,X) {}
#define END {}
#endif
 
typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
#define ALL(X) X.begin(),X.end()
struct edge{int to,cost;};
//struct edge{int from,cost,to;};
struct P2{int x,y;};
#define BIT(Bit,n) bitset<n>(Bit)
#define Endl endl
 
const int MOD7=1000000007;
const int INF=100000000;
const int SET=1000;
 
int main(){
	int a,b,c,n,sum=0,ans=0;
	cin>>a>>b>>c>>n;
	sum=a+b+c;
	for(int i=0;i<=a;i++){
		for(int j=0;j<=b;j++){
			for(int k=0;k<=c;k++){
				if(i*500+j*100+k*50==n&&i+j+k<=sum){
					ans++;
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Long n = Long.parseLong(sc.next());
		
		Long cnt = 0l;
		if(n != 1) {
			cnt = (n*(n-1)/2);
		}
		
		System.out.println(cnt);
	}
}


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

#ifdef DEBUG
    #include "debug.h"
    #define dump(...)                                                              \
        DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
                << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
                << endl                                                            \
                << "    ",                                                         \
            dump_func(__VA_ARGS__)
#else
    #define dump(...)
#endif


// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//////////////////

#define int long long
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
#define ALL(v) (v).begin(), (v).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
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 (a>b) { a=b; return 1; } return 0; }

//*
#define mod 1000000007 /*/
#define mod 998244353 //*/

typedef pair<int, int> P;
#define INF (1LL<<60)

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

struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;

void solve(){
    int H, W, M;
    cin >> H >> W >> M;
    vector<int> ch(H), cw(W);
    map<int,map<int,int>> m;
    rep(i,M){
        int h, w;
        cin >> h >> w;
        h--; w--;
        ch[h]++;
        cw[w]++;
        m[h][w]=1;
    }
    
    int ans = 0;
    int mah = -INF, maw = -INF;
    rep(i,H) chmax(mah, ch[i]);
    rep(i,W) chmax(maw, cw[i]);
    
    vector<int> vx, vy;
    rep(i,H) if(ch[i]==mah) vx.push_back(i);
    rep(i,W) if(cw[i]==maw) vy.push_back(i);
    
    for(int xx: vx)for(int yy : vy){
        if(m[xx][yy]==0){
            cout << mah + maw << endl;
            return;
        }
    }
    cout << mah + maw -1 << endl;
}


signed main(){
    cout << fixed << setprecision(18);
//    cerr << fixed << setprecision(18);
    solve();
}


Measured memory_bytes: 63180
MOD = 10**9 + 7

n = int(input())

a = list(map(int,input().split()))

sum = [0 for i in range(n+1)]
dp = [0 for i in range(n+1)]

fac = [1 for i in range(n+1)]
finv = [1 for i in range(n+1)]
inv = [1 for i in range(n+1)]

for i in range(2,n+1):
    fac[i] = fac[i-1]*i%MOD
    inv[i] = MOD - inv[MOD%i]*(MOD // i)%MOD
    finv[i]=finv[i-1]*inv[i]%MOD

for i in range(1,n+1):
    sum[i] = (sum[i-1]+inv[i]) % MOD
sum[0] = 1
for i in range(1,n+1):
    dp[i] = (sum[i]+sum[n+1-i]-1) % MOD

ans = 0
for i in range(1,n+1):
    ans = (ans + dp[i]*a[i-1])% MOD

print((ans * fac[n]) % MOD)

Measured memory_bytes: 66968
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;
 
ll gcd(ll a, ll b) {
    return b ? gcd(b, a % b) : a;
}
 
int main() {
    int n;
    int a[101000];
    int l[101000] = {0};
    int r[101000] = {0};
    ll ans = 0;
    
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    for (int i = 1; i < n; i++) {
        l[i] = gcd(l[i - 1], a[i - 1]);
    }
    
    for (int i = (n - 2); i >= 0; i--) {
        r[i] = gcd(r[i + 1], a[i + 1]);
    }
    
    for (int i = 0; i < n; i++) {
        ans = max(ans, gcd(l[i], r[i]));
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
const double EPS=1e-8;
const double PI=acos(-1);
const int N=105;
int n;double x[N],y[N],z[N];
bool vis[N];
struct Node {
    double x,y;int id;
    Node(double x=0,double y=0,int id=0):x(x),y(y),id(id){}
    bool operator < (const Node &b) const {
        if(x!=b.x) return x<b.x;
        return y<b.y;
    }
    Node operator - (const Node &b) {
        return Node(x-b.x,y-b.y);
    }
    double det(const Node &b) {
        return x*b.y-y*b.x;
    }
    double dot(const Node &b) {
        return x*b.x+y*b.y;
    }
    double dis() {
        return sqrt(x*x+y*y);
    }
}point[N],ans[N];
int solve(int num) {
    std::sort(point,point+num);
    int k=0;
    for(int i=0;i<num;i++) {
        while(k>1&&(ans[k-1]-ans[k-2]).det(point[i]-ans[k-1])<EPS) k--;
        ans[k++]=point[i];
    }
    for(int i=num-2,t=k;~i;i--) {
        while(k>t&&(ans[k-1]-ans[k-2]).det(point[i]-ans[k-1])<EPS) k--;
        ans[k++]=point[i];
    }
    return k;
}
double res[N];
int main() {
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%lf%lf",&point[i].x,&point[i].y),point[i].id=i;
    int num=solve(n)-1;
    for(int i=0;i<n;i++) res[i]=0;
    if(num==2) res[ans[0].id]=res[ans[1].id]=0.5;
    else {
        double tmp;
        for(int i=0;i<num;i++) {
            tmp=(ans[i]-ans[(i-1+num)%num]).dot(ans[i]-ans[(i+1)%num]);
            tmp=acos(tmp/(ans[i]-ans[(i-1+num)%num]).dis()/(ans[i]-ans[(i+1)%num]).dis());
            res[ans[i].id]=(PI-tmp)/PI/2;
        }
    }
    for(int i=0;i<n;i++) printf("%.12f\n",res[i]);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int main(void){
	int N;
	int X[100];
	int leng = 0;
	int ansA=0;
	int ansB=0;
	scanf("%d",&N);
	for(int a=0;a<N;a++){
		scanf("%d",&X[a]);
		leng+=X[a];
	}
	leng=leng/N;
	for(int a=0;a<N;a++){
		ansA+=(leng-X[a])*(leng-X[a]);
	}
	leng++;
	for(int a=0;a<N;a++){
		ansB+=(leng-X[a])*(leng-X[a]);
	}
	if(ansA>ansB)	ansA=ansB;
	printf("%d",ansA);
}

Measured memory_bytes: 128
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt()%500;
        int a = sc.nextInt();
        System.out.println(n <= a ? "Yes" : "No");
        
        
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

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

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
            return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) a[i] = nextLong();
        return a;
    } 
}


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

int main() {
  int N = 3;
  vector<int> num(N);
  for (int i = 0; i < N; ++i) {
    cin >> num.at(i);
  }
  sort(num.begin(), num.end());
  for (int i = 0; i < N; ++i) {
    cout << num.at(i);
    if (i == N - 1) cout << endl;
    else cout << " ";
  }

  return 0;
}


Measured memory_bytes: 3136
import * as fs from 'fs';

namespace AtCoder.abc087 {

    export class Program {

        constructor(private readonly args: string[][]) {
        }

        /**
         * in
         *
         * out
         *
         */
        main(this: Program): void {
            const x: number = parseInt(this.args[0][0], 10);
            const a: number = parseInt(this.args[1][0], 10);
            const b: number = parseInt(this.args[2][0], 10);

            let wk: number = x - a;

            console.log(wk % b);

        }
    }
}

const args: string[][] = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n').map(r => r.split(' '));
const prg: AtCoder.abc087.Program = new AtCoder.abc087.Program(args);
prg.main();


Measured memory_bytes: 7372
import java.util.*;
public class Main {
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int r = sc.nextInt();
		if (n<10) {
          System.out.println(r+(10-n)*100);

          
        }else {
          System.out.println(r);
        }
    }
}

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

using namespace std;

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


const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()

//計算量はNで行きたい
//配列で殴れるか……？
//むり

int main(){
    int N,ANS=0;
    cin>>N;
    vector<ll> X(N,0),L(N,0);
    vector<pair<ll,ll>> p;
    rep(i,N){
        cin>>X[i]>>L[i];
        p.pb(make_pair(X[i]+L[i],X[i]-L[i]));
    }
    sort(ALL(p));
    int C=-INF;

    rep(i,N){
        if(C<=p[i].second){//比較してるp[i]が腕の最前よりも前にあるなら、
            ANS++;
            C=p[i].first;//残すと決めた腕の一番最前を更新
        }
    }
    cout<<ANS<<endl;

    return 0;
}

//a=97,z=122

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
#define lli long long
#define pb push_back
#define mp make_pair
using namespace std;
#define fin ios_base::sync_with_stdio(false); cin.tie(NULL);
int main()
{
  fin;
  int n,i,j;
  double ans=0;
  cin>>n;
  double a[n];
  double dp[n+1][n+1];
  memset(dp,0.0,sizeof(dp));
  for(i=0;i<n;i++)
    cin>>a[i];
  dp[1][0]=1-a[0];
  dp[1][1]=a[0];
  for(i=2;i<=n;i++)
  {
    for(j=0;j<=n;j++)
    {
      if(j==0)
        dp[i][j]=dp[i-1][0]*(1-a[i-1]);
      else if(j>i)
        dp[i][j]=0;
      else
        dp[i][j]=dp[i-1][j]*(1-a[i-1]) + dp[i-1][j-1]*a[i-1];
    }
  }
  for(i=n/2+1;i<=n;i++)
    ans+=dp[n][i];
  cout<<fixed<<setprecision(10)<<ans<<"\n";
  }


Measured memory_bytes: 70656
#include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <vector>
    #include <cmath>
    #include <map>

    #define ll long long
    #define mod 1000000007
    using namespace std;

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

        string s;
        cin>>s;
        long ans=700;
        for(int i=0;i<s.length();i++){
            if(s[i]=='o') ans+=100;
        }
        cout<<ans<<"\n";
        return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int x1, y1, x2, y2;
  scanf("%d %d %d %d", &x1, &y1, &x2, &y2);	int i;
  for (i = 0; i < x2 - x1; i++){
  	printf("R");
  }
  for (int i = 0; i < y2 - y1; i++){
  	printf("U");
  }

  for (i = 0; i < x2 - x1; i++){
  	printf("L");
  }
  for (i = 0; i < y2 - y1; i++){
  	printf("D");
  }

  	printf("D");
  for (i = 0; i < x2 - x1 + 1; i++){
  	printf("R");
  }
  for (i = 0; i < y2 - y1 + 1; i++){
  	printf("U");
  }
  	printf("L");

  	printf("U");
  for (i = 0; i < x2 - x1 + 1; i++){
  	printf("L");
  }
  for (i = 0; i < y2 - y1 + 1; i++){
  	printf("D");
  }
  printf("R\n");

}

Measured memory_bytes: 256
N, M, X, Y = map(int, input().split())
l1 = [i for i in range(X+1, Y+1)]
s1 = set(l1)
X_list = list(map(int, input().split()))
Y_list = list(map(int, input().split()))
X_max = max(X_list)
Y_min = min(Y_list)
if X_max < Y_min:
    l2 = [i for i in range(X_max+1, Y_min+1)]
    s2 = set(l2)
    if s1 & s2:
        print('No War')
    else:
        print('War')
else:
    print('War')

Measured memory_bytes: 3064
// J4180449 三宅亮輔
// 問題名
// - Area of Polygon
// 問題URL
// - https://onlinejudge.u-aizu.ac.jp/problems/0079
// 所要時間
// -
// 学んだこと
//
//
//

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

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

int n;

vector<P> p;

double nijo(double a) { return a * a; }

double dist(P a, P b) {
    return sqrt(nijo(a.first - b.first) + nijo(a.second - b.second));
}

double calc(P a, P b, P c) {
    double x = dist(a, b);
    double y = dist(b, c);
    double z = dist(c, a);
    double s = (x + y + z) / 2;

    return sqrt(s * abs(s - x) * abs(s - y) * abs(s - z));
}

int main() {
    double x, y;
    string s;
    while(cin >> s) {
        int id = 0;
        for(int i = 0; i < s.size(); i++) {
            if(s[i] == ',')
                id = i;
        }

        double x = stod(s.substr(0, id));
        double y = stod(s.substr(id + 1, s.size() - id - 1));

        p.push_back(P(x, y));
        n++;
    }

    double ans = 0;
    for(int i = 1; i + 1 < n; i++) {
        ans += calc(p[0], p[i], p[i + 1]);
    }
    cout << ans << endl;
}



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

#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i, m, n) for(int i = (int)m; i < (int)n; i++)
typedef unsigned long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;


/*FUNCs=================================================*/


/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    ll n, cnt = 0; cin >> n;
    vll a(3*n);
    rep(i,3*n) cin >> a[i];
    sort(a.begin(), a.end());
    for(int i = n; i < 3*n; i += 2) cnt += a[i];
    cout << cnt <<endl;
}


Measured memory_bytes: 2560
n = int(input())
S = [input() for _ in range(n)]

f_inf = float("inf")
ans = [f_inf] * 26
for i in range(26):
    subs = 97 + i
    for s in S:
        ans[i] = min(ans[i], s.count(chr(subs)))

for i in range(26):
    for j in range(ans[i]):
        print(chr(97 + i), end="")


Measured memory_bytes: 3060
import sys
n,m,k =map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

t = k
i = 0
asum = [0]* (n+1)
bsum = [0]* (m+1)
suma = 0
sumb = 0

for  i in range(n):
    suma += a[i]
    asum[i+1]= suma


for  i in range(m):
    sumb += b[i]
    bsum[i+1] = sumb

count = 1
ans = 0

for i in range(n+1):
    if ans < i :
        if asum[i] <= k:
            ans=i
    else:
        for j in range(ans-i,m+1,1):
            if asum[i] + bsum[j]<=k:
                if i+j>ans:
                    ans=i+j
            else:
                break

print(min(ans,m+n))

Measured memory_bytes: 111088
#include <bits/stdc++.h>
        #define ll  long long int
        #define pb push_back
        #define mp make_pair
        #define ff first
        #define ss second
        #define vi vector<int>
        #define br cout <<"\n";
        #define all(x)  (x).begin(),(x).end()
        #define tr(c,i) for(auto i : c)
        #define pii pair< int,int >
        #define fast_io() ios_base::sync_with_stdio(false);cin.tie(nullptr)
        #define pq priority_queue< pair<ll,pii> ,vector<pair<ll,pii>>,greater <pair<ll,pii>> >p;//container adapter makes ascending q
        #define er(x) cout << x << " "
        #define err(x,y) cout << x << " "<<y
        const int M = 200005;
        using namespace std;
        clock_t time_p=clock();
        void dem()
        {
            time_p=clock()-time_p;
            cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
        }

        using namespace std ;
        const int N =  5 * 1000 + 10   ;
        const int dx[] = { 1, -1 , 0 , 0  };
        const int dy [] = { 0 ,0 , 1 , -1  };
        int lcp [N][N] ;
        int main (){
        int n ;
        cin >> n ;
        string s ;
        cin >>s ;
        int res  = 0 ;
        for ( int i = 1 ; i < n  ; ++i ){

            for ( int j = 0 ; j < i; ++ j ){
                lcp[i][j] = s[i] == s[j] ? 1 + lcp [i-1][j-1] :  0 ;
                res =  max ( min (  i  - j , lcp[i][j] ) , res ) ;

            }

        }

        cout << res ;
        return 0 ;

        }


Measured memory_bytes: 96512
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
const int MAXN=100000+5;
vector<int>g[MAXN];
pair<int,int>e[MAXN];
int n,K,col[MAXN],up[MAXN];
void dfs(int x,int ff)
{
    int now=0;
    for(int i=0;i<g[x].size();i++)
    {
        int v=g[x][i];
        int t=e[v].first+e[v].second-x;
        if(t==ff) continue;
        now++;
        if(now==up[x]) now++;
        col[v]=now;
        up[t]=now;
        dfs(t,x);
    }
}

int main()
{
    scanf("%d",&n);
    for(int i=1,x,y;i<n;i++)
    {
        scanf("%d%d",&x,&y);
        g[x].push_back(i);
        e[i]=make_pair(x,y);
        g[y].push_back(i);
    }
    for(int i=1;i<=n;i++)
    K=max(K,(int)g[i].size());
    dfs(1,0);
    printf("%d\n",K);
    for(int i=1;i<n;i++)
    printf("%d\n",col[i]);
    return 0;
}


Measured memory_bytes: 9984
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  ios_base::sync_with_stdio(false); 
  cin.tie(0);
  cout.tie(0);
  long long int a,b,n,product;
  cin>>a>>b>>n;
  if(b<=n)
  {
      cout<<(a*(b-1))/b;
  }
  else
  {
      cout<<(a*n)/b;
  }
  return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<double> v(1001);
  int i;
  for(i=0;i<n;i++){
    cin >> v[i];
  }
  sort(v.begin(),v.begin()+n);
  double nabe = v[0] + v[1];
  nabe /= 2;
  for(i=2;i<n;i++){
    nabe += v[i];
    nabe /= 2;
  }
  cout << nabe << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<iterator>
#include<queue>
#include<algorithm>
#include<functional>
#include<cmath>
#include<unordered_map>

typedef long long ll;
typedef std::map<char, int> string_type;
typedef std::map<string_type, int> type_occurences;
typedef std::map<int, std::map<int, int> > type_lamp_map;

struct tokiomarine2020_c {
	// 1-origin
	std::string run(int N, int K, std::vector<int> A) {
		std::stringstream ss;
		long double km1ln2 = (K - 1) * std::log(2);
		long double lnN = std::log(N);

		if(N == 1) {
			// K > 0
			return "1 ";
		}

		if(km1ln2 > lnN * 3) {
			for(int i = 0; i < N; ++i) {
				ss << N << " ";
			}
			return ss.str();
		}

		std::vector<int> Bn1, Bn2;
		std::vector<int> *Bn_cur, *Bn_next, *Bn_temp;
		Bn1.resize(N);
		Bn2 = A;
		Bn_cur = &Bn1;  // dummy
		Bn_next = &Bn2;

		for(int round = 0; round < K; ++round) {
			// update
			Bn_temp = Bn_cur;
			Bn_cur = Bn_next;
			Bn_next = Bn_temp;

			// renew
			Bn_next->clear();
			Bn_next->resize(N);

			// current
			// for(int i = 0; i < N; ++i) {
			// 	std::cout << (*Bn_cur)[i] << "\t";
			// }
			// std::cout << std::endl;

			// loop

			for(int i = 0; i < N; ++i) {
				const int jmin = std::max(0, i - (*Bn_cur)[i]);
				const int jmax = std::min(N-1, i + (*Bn_cur)[i]);
				// lamp_map[jmin][jmax] += 1;
				(*Bn_next)[jmin] += 1;
				if(jmax+1 <= N) {
					(*Bn_next)[jmax+1] -= 1;
				}
				// for(int j = jmin; j <= jmax; ++j) {
				// 	(*Bn_next)[j] += 1;
				// }
			}
			for(int i = 1; i < N; ++i) {
				(*Bn_next)[i] += (*Bn_next)[i-1];
			}

			// fin if all N
			bool allN = true;
			for(int i = 0; i < N; ++i) {
				if((*Bn_next)[i] != N) {
					allN = false;
					break;
				}
			}
			if(allN) break;
		}

		for(int i = 0; i < N; ++i) {
			ss << (*Bn_next)[i] << " ";
		}

		return ss.str();
	}
};

int main(void) {
	tokiomarine2020_c solver;
	int N, K, t;
	std::vector<int> A;

	std::cin >> N >> K;
	for(int i = 0; i < N; ++i) {
		std::cin >> t;
		A.push_back(t);
	}

	std::cout << solver.run(N, K, A) << std::endl;

	return 0;
}


Measured memory_bytes: 9364
N,W = map(int,input().split())
Value = []
weight = []
inf=float("inf")
dp=[[-inf for i in range(W+1)] for j in range(N+1)]
for i in range(W+1): dp[0][i]=0

for i in range(N):
    w,v = map(int,input().split())
    Value.append(v)
    weight.append(w)


for i in range(N):
  for w in range(W+1):
    if w>=weight[i]:
      dp[i+1][w] = max(dp[i][w-weight[i]]+Value[i],dp[i][w])
    else:
      dp[i+1][w] = dp[i][w]

print(dp[N][W])

Measured memory_bytes: 310452
/*
  GOOD is not Enough
  You've got to be GREAT.
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mod 1000000007
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<=n;i++)
#define fr(i,k,n) for(int i=k;i>=n;i--)
#define pb push_back
#define F first
#define S second
#define all(a) a.begin(),a.end()
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;


void solve()
{ 
    int n;
    double m;
    cin >> n >> m;
   double a[n],sum=0;
   f(i,n)
    {cin >> a[i];sum+=a[i];}
  double cnt=0;
  double x;
  x=(double)sum/(4.0*m);
//   cout << x << '\n';
  f(i,n)
  {
      if(a[i]>=x)
        cnt++;
  }
//   cout << cnt << '\n';
  if(cnt>=m)
    cout << "Yes\n";
  else
   cout << "No\n";
 return;
}

signed main()
{
  int T=1;
  // cin >> T;
  while(T--)
  {
    solve();
  }
  return 0;
}


Measured memory_bytes: 256
int main(){
    int n,m,a,b;
    int vA[101][101]={};
    int vB[101]={};
    int vC[101]={};
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            scanf("%d",&a);
            vA[i][j]=a;
        }
    }
    
    for(int j=1;j<=m;j++){
        scanf("%d",&b);
        vB[j]=b;
    }
    
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            vC[i]+=(vA[i][j])*(vB[j]);
        }
    }
    for(int i=1;i<=n;i++){
        printf("%d\n",vC[i]);
    }
    return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s,t;
	cin>>s>>t;
	bool a=true,b=true;
	int pos=0;
	rep(i,s.size()){
		if(i%2==0){
			while(true){
				if(pos==t.size()){
					a=false;
					break;
				}
				else{
					if(t[pos++]==s[i])break;
				}
			}
		}
	}
	pos=0;
	rep(i,s.size()){
		if(i%2==1){
			while(true){
				if(pos==t.size()){
					b=false;
					break;
				}
				else{
					if(t[pos++]==s[i])break;
				}
			}
		}
	}
	Yn(a|b);
}



Measured memory_bytes: 3248
#include <iostream>

#define REP(i,n) for(int i=0;i<n;i++)
#define lli long long int

lli max(lli a,lli b){
	if(a>=b)return a;
	else return b;
}

lli min(lli a,lli b){
	if(a>=b)return b;
	else return a;
}

using namespace std;

int main(){

	int colorNum[9]={1,400,800,1200,1600,2000,2400,2800,3200};

	int colorFlag[9]={0,0,0,0,0,0,0,0,0};

	int n;
	cin>>n;

	int *a;
	a = new int[n];

	REP(i,n){
		int tmp;
		cin>>tmp;
		for(int j=8;j>=0;j--){
			if(tmp>=colorNum[j]){
				colorFlag[j]++;
				break;
			}
		}
	}

	int minAns=0;
	int maxAns=0;

	for(int i=0;i<8;i++){
		if(colorFlag[i]>0){
			minAns++;
			maxAns++;
		}
	}

	maxAns = maxAns+colorFlag[8];
	minAns = max(1,minAns);

	cout << minAns<<" "<<maxAns<<endl;


	return 0;


}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;
#define inf 1000000000
int n,m;
int d[101][101];
int edge[101][101];
void wf(){
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            if(d[i][k]==inf)continue;
            for(int j=0;j<n;j++){
                if(d[k][j]==inf)continue;
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
}
int main(void){
    int a[1000],b[1000],c[1000];
    cin>>n>>m;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i==j)d[i][j]=0;
            else d[i][j]=inf;
        }
    }
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i]>>c[i];
        a[i]--;b[i]--;
    }
    for(int i=0;i<m;i++){
        d[a[i]][b[i]]=c[i];
        d[b[i]][a[i]]=c[i];
    }
    wf();
    int ans=m;
    for(int i=0;i<m;i++){
        bool shortest=false;
        for(int j=0;j<n;j++)
            if(d[j][a[i]]+c[i]==d[j][b[i]])shortest=true;
            if(shortest==true){
                ans--;
            }
        }
    
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int N, Q;
	string S;
	cin >> N >> Q >> S;
	int l[100010], r[100010];

	for (int i = 1; i <= Q; i++) {
		cin >> l[i] >> r[i];
	}

	int ruisekiwa[100010] = { 0 }; ruisekiwa[0] = 0;

	for (int i = 1; i <= N - 1; i++) {
		if (S[i] == 'C' && S[i - 1] == 'A') ruisekiwa[i] = ruisekiwa[i - 1] + 1;
		else ruisekiwa[i] = ruisekiwa[i - 1];
	}

	for (int i = 1; i <= Q; i++) {
		cout << ruisekiwa[r[i] - 1] - ruisekiwa[l[i] - 1] << "\n";
	}
	return 0;
}

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

#define pb push_back
#define vi vector < int >
#define ii pair < int, int >
#define vii vector < pair < int, int > >
#define vvi vector < vector < int > >
#define ll long long
#define x first
#define y second
#define mp make_pair
#define FOR( i, lo, hi ) for( int i = (lo);i < (hi);i++ )
#define DFOR( i, hi, lo ) for( int i = (hi);i >= (lo);i-- )
#define pqueue priority_queue

using namespace std;

const long long int MOD = 1e9 + 7;

ll REM( ll a )
{
	a %= MOD;
	if ( a < 0 ) a += MOD;
	return a;
}

ll ADD( ll a, ll b )
{
	return REM( REM( a ) + REM( b ) );
}

ll SUB( ll a, ll b )
{
	return REM( REM( a ) - REM( b ) );
}

ll MUL( ll a, ll b )
{
	return REM( REM( a ) * REM( b ) );
}

ll POT( ll n, ll k )
{
	if ( k == 0 ) return 1;

	ll ret = POT( n, k / 2 );
	ret = MUL( ret, ret );

	if ( k % 2 ) return MUL( ret, n );
	return ret;
}

ll DIV( ll a, ll b )
{
   return MUL( a, POT( b, MOD - 2 ) );
}

bool isPrime( ll x )
{
   if ( x == 1 )
	   return 0;
	for ( ll i = 2;i <= sqrt( x ); i++ )
		if ( x % i == 0 )
		   return 0;
	return 1;
}

const int MAXN = 2e5 + 10;

ll x, y;

int main()
{
   ios_base::sync_with_stdio( false );
   cin.tie( 0 );
   	
	cin >> x >> y;
	puts( x * 500 >= y ? "Yes" : "No" );

   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const ll MOD=1000000007,INF=1ll<<60;
int dx[]={0,0,1,-1},dy[]={-1,1,0,0};

int N,A,B,C,M,K,Q;
string s,t;

signed main() {
    IOS();
    cin>>N>>s;
    int cnt=0;
    rep(i,0,N){
        if(s[i]=='R')cnt++;
        else cnt--;
    }
    
    if(cnt>0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

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

int main() {
    cin.tie(NULL);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int temp;
    bool flag=true;
    while(n--){
        cin>>temp;
        if(temp%2==0){
            if(temp%3&&temp%5)
                flag=false;
        }
    }
    if(flag)cout<<"APPROVED";
    else cout<<"DENIED";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
const int INF= 10000;
  vector<int> dx={1,0,-1,0};
  vector<int> dy={0,1,0,-1};
int bfs(int h, int w, int sx, int sy,vector<string> maze){
  queue<P> que;
  int ans=0;
  vector<string> tmpmaze=maze;
  vector<vector<int>> d(h, vector<int>(w));
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      d.at(i).at(j)=INF;
    }
  }
  que.push(make_pair(sx,sy));
  d.at(sx).at(sy)=0;
  while(!que.empty()){
    P p=que.front();
    que.pop();
    for(int i=0; i<4; i++){
      int nx=p.first+dx.at(i);
      int ny=p.second+dy.at(i);
      if(0<=nx &&nx<h && 0<=ny && ny<w && tmpmaze.at(nx).at(ny)=='.'
         &&d.at(nx).at(ny) == INF){
        que.push(make_pair(nx,ny));
        d.at(nx).at(ny)= d.at(p.first).at(p.second) +1;
        ans=max(ans,d.at(nx).at(ny));
      }
    }
  }
  return ans;
}
int main(){
  int h,w;
  cin>>h>>w;
  vector<string> m(h);
  for(int i =0; i<h; i++){
    string s;
    cin>>s;
    m.at(i)=s;
  }
  int ans=0;
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      if(m.at(i).at(j)=='.'){
        ans = max(ans, bfs(h,w,i,j,m));
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/

#include<bits/stdc++.h>
#define pll              pair<long,long>
#define pii              pair<int,int>
#define scn(a)           scanf("%d", &a)
#define scn2(a, b)       scanf("%d%d", &a, &b)
#define scn3(a, b, c)    scanf("%d%d%d", &a, &b, &c)
#define pairl            pair<ll , ll >
#define scnl(a)          scanf("%lld", &a)
#define scnl2(a, b)      scanf("%lld%lld", &a, &b)
#define scnl3(a, b, c)   scanf("%lld%lld%lld", &a, &b, &c)
#define scns(s)          scanf("%s",s)
#define prts(s)          printf("%s\n",s)
#define prt(a)           printf("%d\n", a)
#define prtl(a)          printf("%lld\n", a)
#define prs(a)           printf("%d ", a)
#define prt2(a, b)       printf("%d %d\n", a, b)
#define prt3(a, b, c)    printf("%d %d %d\n", a, b, c)
#define prsl(a)          printf("%lld ", a)
#define prtl2(a, b)      printf("%lld %lld\n", a, b)
#define prtl3(a, b, c)   printf("%lld %lld %lld\n", a, b, c)
#define ptcs(a)          printf("Case %d: ", a)
#define pf               printf
#define sc               scanf
#define vi               vector<int >
#define vil              vector<ll >
#define pb               push_back
#define mem(a, b)        memset((a), (b), sizeof(a))
#define lg2(n)           (31-__builtin_clz(n))
#define inf              9999999
#define ll               long long
#define ull              unsigned long long
#define MIN              INT_MIN
#define MAX              INT_MAX
#define fast             ios_base::sync_with_stdio(false),cin.tie(NULL)
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree<pair<int, int> , null_type, less<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update> odrst;
ll gcd(ll a, ll b){if(b==0) {return a;}return gcd(b, a % b);}
ll BigMod(ll B,ll P,ll M){     ll R=1; while(P>0)      {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;}
//___________________________________________________________________________________________________________________
const int N = 2e5 + 9;
const int mod = 1e9 + 7;
ll t,x,n,m,y,z,x1,x2,x3,k;
ll mp[11],ar[11];
int main()
{
    fast;
    cin>>n>>m;
    bool ok=true;
    ar[1]=1;
    for(int i=0;i<m;i++)
    {
        cin>>x>>y;
        if(mp[x])
        {
            if(y!=ar[x]) ok=false;
        }
        else
        {
            ar[x]=y;
            mp[x]=1;
        }
    }
    if(ar[1]==0 && n!=1) ok=false;
    if(!ok) cout<<-1<<endl;
    else
    {
        if(n==1 && m==0) cout<<0<<endl;
        else
        {
            for(int i=1;i<=n;i++) cout<<ar[i];
            cout<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long 
int n,W,we[101],v[101],dp[101][100001];

int knapsack(int ind,int w){
	if(w == W)return 0;
	else if(w > W)return INT_MIN;
	else if(ind == n)return 0;
	
	if(dp[ind][w] != -1)return dp[ind][w];
	int p = v[ind] + knapsack(ind+1,w+we[ind]);
	int np = knapsack(ind+1,w);
	
	return dp[ind][w] = max(p,np);
}

signed main(){
	cin >> n >> W;
	for(int i = 0;i<n;i++)cin >> we[i] >> v[i];
	for(int i = 0;i<101;i++){
		for(int j = 0;j<100001;j++){
			dp[i][j] = -1;
		}
	}
	
	cout << knapsack(0,0);
	
	return 0;
}

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


int n;

#define MAX 500002

char buf[MAX];

string s;

int dp[MAX][27];

int can[MAX];


int lc[22][MAX];

bool search(int lef, int goal){
	for (int i = 21; i >= 0; i--){
		if (lc[i][lef] == -1)continue;
		if (lc[i][lef]==goal){
			return true;
		}
		if (lc[i][lef] < goal){
			lef = lc[i][lef];
			lef++;
		}
	}
	return false;
}
int main(){
	scanf("%s", buf);
	s = buf;
	n = s.size();
	memset(dp, -1, sizeof(dp));
	memset(lc, -1, sizeof(lc));
	for (int i = n - 1; i >= 0; i--){
		dp[i][s[i] - 'a'] = i;
		int id = s[i] - 'a';
		for (int j = id; j + 'a' <= 'z'; j++){
			dp[i][j + 1] = dp[dp[i][j] + 1][j];
			if (dp[i][j + 1] == -1)break;
		}
		if (dp[i][26] != -1){
			for (int j = 0; j < 26; j++){
				if (dp[i][j] == -1){
					dp[i][j] = dp[dp[i][26] + 1][j];
				}
			}
		}
	}
	for (int i = n-1; i>=0; i--){
		lc[0][i] = dp[i][26];
		if (lc[0][i] > 0){
			can[i] = 1 + can[dp[i][26] + 1];
		}
	}
	for (int i = 1; i < 22; i++){
		for (int j = 0; j < n; j++){
			if (lc[i - 1][j] == -1){
				lc[i][j] = -1;
				continue;
			}
			lc[i][j] = lc[i - 1][lc[i - 1][j]+1];
		}
	}
	int q;
	cin >> q;
	while (q--){
		int l, r;
		scanf("%d%d", &l, &r);
		l--;
		r--;
		if (dp[l][26] == -1){
			puts("No");
			continue;
		}
		if (search(l, r)){
			puts("Yes");
		}
		else{
			puts("No");
		}
	}
	return 0;
}

Measured memory_bytes: 99328
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

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

ll lcm(ll m,ll n){
	return ((m / gcd(m, n)) * n);
}

int main(){
	ll n,m,count=0,count2;
	map<ll,char> h;
	set<ll> u;
	string s,t;
	cin>>n>>m>>s>>t;
	ll dim=lcm(n,m);
	for(ll i=0;i<n;i++){
		h[(dim/n)*i+1]=s[i];
		u.insert((dim/n)*i+1);
	}
	for(ll i=0;i<m;i++){
		if(u.find((dim/m)*i+1)!=u.end()&&h[(dim/m)*i+1]!=t[i]){
			cout<<-1<<endl;
			return 0;
		}
	}
	cout<<dim<<endl;
	return 0;
}


Measured memory_bytes: 10368
import sys

#入力する値の個数N
N = input()

#入力される値 A
A = list(map(int, input().split()))

#print(N)
#print(A)
ans = 1
if 0 in A:
    print(0)
    sys.exit()


for i in A:
    #print(i)
    ans *= i
    #print(ans)
    if ans > 10**18:
        print(-1)
        sys.exit()

print(ans)

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v) {
    for (auto &e:u) fill_v<T>(e, v...);
}

int64 N, K;
vector<int64> G[112345];
vector<int64> V;
vector<PLL> poss;

PLL dfs(int64 v, int64 p) {
    if (p != -1 && poss[p].fs != -INF) {
        chmax(poss[v].fs, poss[p].fs-1);
        chmin(poss[v].sc, poss[p].sc+1);
        if (poss[v].fs > poss[v].sc) {
            cout << "No" << endl;
            exit(0);
        }
    }
    for (auto &u : G[v]) {
        if (u == p) continue;
        PLL ret = dfs(u, v);
        if (poss[v] == PLL(-INF, INF)) {
            poss[v] = ret;
        } else {
            chmax(poss[v].fs, ret.fs);
            chmin(poss[v].sc, ret.sc);
            if ((ret.fs > -INF && abs(poss[v].fs)%2 != abs(ret.fs)%2) || poss[v].sc < poss[v].fs) {
                cout << "No" << endl;
                exit(0);
            }
        }
    }
//    cout << v << " " << p << " (" << poss[v].fs << " " << poss[v].sc << ") " << endl;
    return PLL(poss[v].fs-1, poss[v].sc+1);
}

int main(void) {
    cin >> N;
    REP(i, N-1) {
        int64 a, b;
        cin >> a >> b; a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    V.resize(N, -1);
    poss.resize(N, PLL(-INF, INF));
    cin >> K;
    REP(i, K) {
        int64 v, p;
        cin >> v >> p; v--;
        V[v] = p;
        poss[v] = PLL(p, p);
    }
    dfs(0, -1);
    poss[0].fs = poss[0].sc;
    dfs(0, -1);
    cout << "Yes" << endl;
    REP(i, N) {
        cout << poss[i].sc << endl;
    }
}


Measured memory_bytes: 13696
#include <bits/stdc++.h>
using namespace std;
long long n,m,x,sk[20][20],ski[20],s,ans=1000000000000;
bool b,tr;
void rec(int ind)
{
  if(ind==n)
  {
      for(int i=1;i<=m;i++)
      {
          if(ski[i]<x)
          {
              b=1;
          }
      }
      if(b==0)
      {
          tr=1;
          ans=min(ans,s);
      }
      b=0;
  }
  else
  {
        s+=sk[ind][0];
        for(int i=1;i<=m;i++)
        {
        ski[i]+=sk[ind][i];
        }
        rec(ind+1);
        s-=sk[ind][0];
        for(int i=1;i<=m;i++)
        {
        ski[i]-=sk[ind][i];
        }
        rec(ind+1);
  }

}
int main()
{
  cin>>n>>m>>x;
  for(int i=0;i<n;i++)
  {
      for(int j=0;j<=m;j++)
      {
          cin>>sk[i][j];
      }
  }
  rec(0);
  if(tr==0)
  {
      cout<<"-1";
      return 0;
  }
  cout<<ans;
}

Measured memory_bytes: 3644
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main (string[] args)
        {
            string[] str = Console.ReadLine ().Split (' ');
            int N = int.Parse (str[0]);
            int M = int.Parse (str[1]);

            int[] H = new int[N];
            List<int> Flag = new List<int> ();
            for (int i = 0; i < N; i++) Flag.Add (1);

            str = Console.ReadLine ().Split (' ');
            for (int i = 0; i < N; i++)
            {
                H[i] = int.Parse (str[i]);
            }
            for (int i = 0; i < M; i++)
            {
                str = Console.ReadLine ().Split (' ');
                int A = int.Parse (str[0]) - 1;
                int B = int.Parse (str[1]) - 1;

                if (H[A] < H[B]) { Flag[A] = -1; }
                else if (H[A] > H[B]) { Flag[B] = -1; }
                else { Flag[A] = Flag[B] = -1; }

            }

            int count = 0;

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

                if (Flag[i] == 1) count++;
            }

            Console.WriteLine (count);

        }
    }

    class MyLibrary
    {

        // 自作の関数
        public static int MyFunction (int n)
        {
            return 0;
        }
    }
}

Measured memory_bytes: 46780
x = int(input())
k = [[0], [0], [i*i for i in range(32) if i*i <= x]]
i = 2
while(len(k[i]) > 2):
  k.append([k[i][j]*j for j in range(len(k[i])) if k[i][j]*j <= x])
  i += 1
print(max([l[-1] for l in k]))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
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; }
int main(){
    ios::sync_with_stdio(false);
    int h,w;
    cin >> h >> w;
    struct edge {
        int from, to, cost;
    };
    vector<edge> G(9*9);
    rep(i,10) rep(j,10) {
        int c;
        cin >> c;
        if(i == j) continue;
        G.push_back({i,j,c});
    }
    vector<int> A;
    rep(i,h) rep(j,w) {
        int a;
        cin >> a;
        A.push_back(a);
    }
    const int INF = INT32_MAX>>3;
    vector<int> d_min(10);
    rep(i, 10) {
        vector<int> d(10, INF);
        d[i] = 0;
        rep(j, 10) {
            //ベルマンフォード法
            for(auto e: G) {
               if(d[e.from] != INF && d[e.from] + e.cost < d[e.to]){
                   d[e.to] = d[e.from] + e.cost;
               }
            }
        }
        d_min[i] = d[1];
    }
    int ans = 0;
    rep(i, A.size()) {
        if(A[i] != -1) {
            ans+=d_min[A[i]];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define maxn 4000005
using namespace std;
bitset<maxn>bit;
typedef long long ll;
int main()
{
    int n;
    scanf("%d",&n);
    int sum=0;
    bit[0]=1;
    for(int i=1;i<=n;i++){
        int num;
        scanf("%d",&num);
        sum+=num;
        bit|=bit<<num;
    }
    int j=(sum+1)>>1;
    for(int i=j;i<=sum;i++){
        if(bit[i]){
            printf("%d\n",i);
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 1664
grid =  [list(map(int, input().split())) for i in range(3)]
n = int(input())
possi = []
for i in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if grid[i][j] == b:
                grid[i][j] = 0
can = True
for i in range(3):
    possi.append([grid[i][0], grid[i][1], grid[i][2]])
for i in range(3):
    possi.append([grid[0][i], grid[1][i], grid[2][i]])
possi.append([grid[0][0], grid[1][1], grid[2][2]])
possi.append([grid[0][2], grid[1][1], grid[2][0]])
for a, b, c in possi:
    if a == 0 and b == 0 and c== 0:
        print("Yes")
        can = False
        break
if can:
    print("No")

Measured memory_bytes: 3188