akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;

int maxHappinessFrom(int curr, int prevAction, const vector<int>& a, const vector<int>& b, const vector<int>& c
        , vector<vector<int> >& memo) {
    if (curr == a.size()) {
        return 0;
    }
    if (prevAction == -1) {
        int ha = maxHappinessFrom(curr + 1, 0, a, b, c, memo) + a[curr];
        int hb = maxHappinessFrom(curr + 1, 1, a, b, c, memo) + b[curr];
        int hc = maxHappinessFrom(curr + 1, 2, a, b, c, memo) + c[curr];
        return max(max(ha, hb), hc);
    }
    if (memo[curr][prevAction] >= 0) {
        return memo[curr][prevAction];
    }

    int ret = 0;
    if (prevAction == 0) {
        int hb = maxHappinessFrom(curr + 1, 1, a, b, c, memo) + b[curr];
        int hc = maxHappinessFrom(curr + 1, 2, a, b, c, memo) + c[curr];
        ret = max(hb, hc);
    }
    else if (prevAction == 1) {
        int ha = maxHappinessFrom(curr + 1, 0, a, b, c, memo) + a[curr];
        int hc = maxHappinessFrom(curr + 1, 2, a, b, c, memo) + c[curr];
        ret = max(ha, hc);
    }
    else { // if (prevAction == 2) {
        int ha = maxHappinessFrom(curr + 1, 0, a, b, c, memo) + a[curr];
        int hb = maxHappinessFrom(curr + 1, 1, a, b, c, memo) + b[curr];
        ret = max(ha, hb);
    }
    memo[curr][prevAction] = ret;
    return ret;
}

void Main() {
    int N;
    cin >> N;
    vector<int> a(N, 0), b(N, 0), c(N, 0);
    for (int i = 0; i < N; ++i) {
        cin >> a[i] >> b[i] >> c[i];
    }

    vector<vector<int> > memo(N, vector<int>(3, -1));
    int ans = maxHappinessFrom(0, -1, a, b, c, memo);
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 14720
N = int(input())
S = list(map(int,input()))
count = 0

for x100 in range(10):
    if x100 in S[:N-2]:
        ind_100 = S.index(x100)
        
        for x10 in range(10):
            if x10 in S[ind_100+1:N-1]:
                ind_10 = S[ind_100+1:N-1].index(x10) + ind_100 + 1
                
                for x1 in range(10):
                    if x1 in S[ind_10 + 1:]:
                        count += 1
print(count)    

Measured memory_bytes: 3652
import math
def isprime(x):
    if x==2:
        return 1
    elif x<2 or x%2==0:
        return 0
    else:
        i=3
        while i<=math.sqrt(x):
            if x%i==0:
                return 0
            i=i+2
        return 1

n=int(input())
count=0
for i in range(n):
    a=int(input())
    if isprime(a)==1:
        count+=1
    else :
        pass
    
print(count)


Measured memory_bytes: 5676
#include<iostream>

#define INF 1000000

std::pair<int,int>list[101][101];
int cost[101];
bool used[101];
int n,m,k;

int dijkstra(int s,int g,int r){
	used[s]=true;
	if(used[g])return cost[g];
	for(int i=1;i<=m;i++){
		if(r==0){
			if(list[s][i].first!=INF){
				if(cost[i]>cost[s]+list[s][i].first){
					cost[i]=cost[s]+list[s][i].first;
				}
			}
		}else if(r==1){
			if(list[s][i].second!=INF){
				if(cost[i]>cost[s]+list[s][i].second){
					cost[i]=cost[s]+list[s][i].second;
				}
			}
		}
	}
	int min=0;
	for(int i=1;i<=m;i++){
		if(!used[i]){
			if(cost[min]>cost[i])min=i;
		}
	}
	dijkstra(min,g,r);
}

int main(){
	while(std::cin>>n>>m){
		if(n==0&&m==0)break;
		for(int i=0;i<=m;i++){
			for(int j=0;j<=m;j++){
				list[i][j].first=INF;
				list[i][j].second=INF;
			}
		}
		for(int i=0;i<n;i++){
			int a,b,c,d;
			std::cin>>a>>b>>c>>d;
			list[a][b].first=c;list[a][b].second=d;
			list[b][a].first=c;list[b][a].second=d;
		}
		std::cin>>k;
		for(int i=0;i<k;i++){
			for(int j=0;j<=m;j++)cost[j]=INF,used[j]=false;
			int p,q,r;
			std::cin>>p>>q>>r;
			cost[p]=0;
			std::cout<<dijkstra(p,q,r)<<std::endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1244
#include <stdio.h>
#include <string.h>

char str[16];
int serve(int num){
    sprintf(str, "%d", num);
    for(int i = 0; i < 5; ++i){
        if(str[i]!=str[4-i]) return 0;
    }
    return 1;
}
/*
int intostring(int num){
    int digito = 0;
    printf("0\n");
    while(num != 0){
        instr[digito] = num%10+'0';
        num /= 10;
        digito++;
    }
    
    printf("1\n");
    str[digito] = instr[digito] = '\0';
    printf("2\n");
    int len = --digito;
    printf("3\n");
    while(digito >= 0){
        str[digito] = instr[len-digito];
        digito-= 1;
    }
    printf("4");
    return strcmp(str, instr) == 0 ? 1: 0;
}*/

int main() {
    //printf("-3\n");
    int sum = 0, a, b;
    //printf("-4\n");
    scanf("%d%d", &a, &b);
    //printf("-1\n");
    for(int i = a; i <= b; ++i){
        //printf("-2\n");
        sum += serve(i);
    }
    printf("%d\n", sum);
}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int k = sc.nextInt();
		int[] x = {a, b, c};
		Arrays.sort(x);
		for(int i = 0 ; i < k ; i++) x[2] *= 2;
		int sum = 0;
		for(int i = 0 ; i < 3 ; i++) sum += x[i];
		System.out.println(sum);

	}
}


Measured memory_bytes: 21332
input_lines = gets.chop.split.map(&:to_i)

count = 0
top = 0
second = 0
multiplication = 0 
for mon in 1...(input_lines[0] + 1) 
    for day in 20...(input_lines[1] + 1)

        top = day/10
        second = day%10
        if second < 2 
            next
        end
        multiplication = top * second
        if multiplication == mon 
            count = count + 1 
        end
    end 
end
puts count

Measured memory_bytes: 1788
#include<algorithm>
#include<functional>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

typedef unsigned long long UInt64;
typedef long long Int64;

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

using namespace std;

typedef pair<int ,int > P;


int main()
{
	int n,y;
	while(cin>>n)
	{
		if(!n) return 0;
		int b,r,t;
		cin>>y;
		double max=-1.0;
		int max_index;

		rep(i,n)
		{
			cin>>b>>r>>t;
			if(t==1)
			{
				if(max<(1.0+(double)y*(double)r/100.0))
				{
					max=(1.0+(double)y*(double)r/100.0);
					max_index=b;
				}
			}
			else
			{
				if(max<(pow(1.0+(double)r/100.0,y)))
				{
					max=((pow(1.0+(double)r/100.0,y)));
					max_index=b;
				}
			}
		}
		cout<<max_index<<endl;

	}
		return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
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;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int a; cin >> a;
    string s; cin >> s;
    if (a >= 3200) cout << s << endl;
    else cout << "red" << endl;
    return 0;
}

Measured memory_bytes: 256
/*Author : Sambhu show(jgec)*/
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define itc ll t;cin>>t;while(t--)
#define PI 3.141592653589793238
#define Max(a,b,c) max(a,max(b,c));
#define Min(a,b,c) min(a,min(b,c));
#define all(v) v.begin(),v.end()
#define ll long long int
#define ld long double
#define pb push_back
#define eb emplace_back
#define gcd(a,b) __gcd(a,b)
#define fi first
#define se second
#define endl "\n"
int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};
int XX[8] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
int tc = 0;
void solve()
{
	int r, b, g;
	cin >> r >> g >> b;
	int c = 0, c2 = 0;
	int k;
	cin >> k;

	if (g <= r)
	{
		while (g <= r)
		{	g *= 2;
			c++;
		}
	}

	if (b <= g)
	{
		while (b <= g)
		{
			b *= 2;
			c2++;
		}
	}
	if (c + c2 <= k)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

}
int main()
{
	fio
	//itc
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 3608
//************************
//*  Date: 6.8.2018      *
//*  Problem: 104A       *
//*  Author: xuziyuan    * 
//************************

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int main()
{
	int r;
	scanf("%d",&r);
	if(r<1200) puts("ABC");else
	if(r<2800) puts("ARC");else
	puts("AGC");
	rt0;
}

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

#define rep(i,n) for(int i = 0;i < (int)(n);i++)
#define Rep(i,n,m) for(int i = (int)(n); i < (int)(m);i++)
#define rrep(i,n) for(int i = (int)(n); i > -1;i--)

#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V))

#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;

template<typename T>
void swap(T*,T*);

string ciper(string s, int n) 
{ 
    string result = ""; 
    for (int i=0;i<s.length();i++) 
    { 
        if (isupper(s[i])) 
            result += char(int(s[i]+n-65)%26 +65); 
        else
            result += char(int(s[i]+n-97)%26 +97); 
    } 
    return result; 
}

int main()
{
    int N;
    cin >> N;
    string s;
    cin >> s;
    cout << ciper(s,N) << endl;
}
    


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  double ans = 0.0;
  for (int i = 1; i <= n; i++) {
    int x = i;
    double cur = 1.0;
    while (x < k) {
      x *= 2;
      cur /= 2.0;
    }
    ans += cur;
  }
  cout << fixed << setprecision(10) << ans / (double) n << '\n';
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int a,b,c,d;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>a>>b>>c>>d;
    
    if(a>c){
        swap(a,c);
        swap(b,d);
    }
    
    chmax(a,c);
    chmin(b,d);
    
    int ans=max(0,b-a);
    cout1(ans)
}

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

vector <int> kmp(string k){
	vector <int> pref(k.size()+1, -1);
	for (int i = 0, j = -1; i < k.size(); ++i){
		while (j >= 0 && k[j] != k[i])
			j = pref[j];
		pref[i+1] = ++j;
	}
	return pref;
}

const int maxS = 1e6;
set <int> G[maxS+5];
bool odw[maxS+5];

bool cykl = false;

set <int> vis;
void dfs(int v){
	odw[v] = true;
	vis.insert(v);
	for (auto u: G[v]){
		if (vis.find(u) != vis.end()){
			cykl = true;
			continue;
		}
		dfs(u);
	}
}

int deg[maxS+5];
vector <int> topo_kol;
int dp[maxS+5];

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	string s, t; // maksymalizujemy kolejne wystapienia t w substr(s)
	cin >> s >> t;
	while (s.size() < t.size())
		s += s;
	int t_sz = t.size();
	int old_sz = s.size();
	s += s;
	string w = t + "#" + s;
	//cout << w << "\n";
	vector <int> vec = kmp(w);

	for (int i = 2+t_sz; i < vec.size(); ++i){
		if (vec[i] == t_sz){
			int b = i - t_sz;
			int a = b - t_sz;

			if (b > old_sz)
				b -= old_sz;
			if (a > old_sz)
				a -= old_sz;
			//cout << a << " -> " << b << "\n";
			G[a].insert(b);
		}
	}
	cykl = false;
	for (int i = 1; i <= old_sz; ++i)
		if (! odw[i]){
			vis.clear();
			dfs(i);
		}

	if (cykl){
		cout << "-1\n";
		return 0;
	}

	for (int i = 1; i <= old_sz; ++i){
		for (auto u: G[i])
			deg[u]++;
	}
	queue <int> Q;

	for (int i = 1; i <= old_sz; ++i){
		if (G[i].size() == 0)
			continue;
		if (deg[i] == 0)
			Q.push(i);
	}
	while (! Q.empty()){
		int v = Q.front();
		Q.pop();
		topo_kol.push_back(v);
		for (auto u: G[v]){
			deg[u]--;
			if (deg[u] == 0)
				Q.push(u);
		}
	}
	int wynik = 0;
	for (auto v: topo_kol){
		wynik = max(wynik, dp[v]);
		for (auto u: G[v])
			dp[u] = max(dp[u], dp[v]+1);
	}
	cout << wynik << "\n";
	return 0;
}

Measured memory_bytes: 160208
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
	// your code goes here
	ll n;
	cin>>n;
	ll out=1e18;
	for(ll i=1;i<=sqrt(n);i++)
	{
		if(n%i==0)
		{
			out=min(out,i-1+(n/i)-1);
		}
	}
	cout<<out;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PB push_back
#define PII pair<int,int>
#define PLL pair<long long,long long>
#define FI first
#define SE second
#define mem(a) memset(a,0,sizeof(a))
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 0x3f3f3f3f;
const double pi=acos(-1),eps=1e-8;
const LL maxn = 1<<17;
const int mod = 1e9+7;
const int N = 4e5+5;
LL gcd(LL a,LL b) {
	return b?gcd(b,a%b):a;
}
LL lcm(LL a,LL b) {
	return a*b/gcd(a,b);
}
int main() {
	ios;
	int a[105];
	int n,cnt=0;cin>>n;
	for(int i=1;i<=n;i++){
		int x;cin>>x;
		if((i&1)&&(x&1))cnt++;
	}
	cout<<cnt;
	return 0;
}


Measured memory_bytes: 3576
#include <iostream>
    #include <vector>
    #include <bits/stdc++.h>
    #define rep(i,n) for (int i = 0; i < (n); ++i)
    using namespace std;
    typedef long long ll;
    typedef pair<int,int> P;
     
    int main(){
        int n,l;
        long ans;
      vector<int> v1;
      vector<int> v2;
        cin >> n;
        
        rep(i,n+1){
            cin>>l;
          	v1.push_back(l);
    ;    }
          rep(i,n){
            cin>>l;
          	v2.push_back(l);
    ;    }
      for(int i=0;i<n+1;i++){
      if(v1[i]>=v2[i]){
       ans+=v2[i];
      }else{
      ans+=v1[i];
        if(v1[i+1]<=(v2[i]-v1[i])){
         ans+=v1[i+1];
          v1[i+1]=0;
        }else{
        ans+=v2[i]-v1[i];
        v1[i+1]-=(v2[i]-v1[i]);
        }
      }
      }
      
      cout << ans <<endl;
    }

Measured memory_bytes: 1400
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <fstream>
using namespace std;

int n, p1, p2;
int a[100001], b[100001];
int main() {
	cin >> n;
	if (n % 2 == 0) {
		for (int i = 1; i <= n; i++) {
			int t;
			cin >> t;
			if (i % 2 == 0) b[++p2] = t;
			else a[++p1] = t;
		}
		reverse(b + 1, b + 1 + p2);
		for (int i = 1; i <= p2; i++) {
			cout << b[i] << ' ';
		}
		for (int i = 1; i <= p1; i++) {
			cout << a[i] << ' ';
		}		
	}
	else {
		for (int i = 1; i <= n; i++) {
			int t;
			cin >> t;
			if (i % 2 == 0) b[++p2] = t;
			else a[++p1] = t;
		}
		reverse(a + 1, a + 1 + p1);
		for (int i = 1; i <= p1; i++) {
			cout << a[i] << ' ';
		}
		for (int i = 1; i <= p2; i++) {
			cout << b[i] << ' ';
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 2944
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

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


int main(){
  int n;
  cin>>n;
  
  string a,b;

  while(n--){
    cin>>a>>b;
    reverse(ALL(a));
    reverse(ALL(b));
    vector<int> c(81,0),d(81,0),e(81,0),f(81,0);
    if(a.size()>80 || b.size()>80) cout<<"overflow"<<endl;
    else{
      for(int i=0;i<(int)a.size();i++){
        c[i]=a[i]-'0';
      }
      for(int i=0;i<(int)b.size();i++){
        d[i]=b[i]-'0';
      }
      rep(i,80){
        e[i]=(c[i]+d[i]+f[i])%10;
        f[i+1]=(c[i]+d[i]+f[i])/10;
      }
      if(f[80]==1) cout<<"overflow"<<endl;
      else{
        reverse(ALL(e));
        if(e[80-max(a.size(),b.size())]!=0){
          for(int i=80-max(a.size(),b.size());i<81;i++) cout<<e[i];
        }
        else{
          for(int i=81-max(a.size(),b.size());i<81;i++) cout<<e[i];
        }
        cout<<endl;
      }
    }
  }
  
  return 0;
}


Measured memory_bytes: 3196
#include<cmath>
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<cctype>
#include<cstring>
#include<string>
using namespace std;



int main() {
	char s[11],r[22],rc[22];
	int n,cnt=0;
	cin >> s >> n;
	for (int i = 0; i < n; i++) {
		
		cin >> r;

		strcpy(rc, r);
		strcat(r, rc);
		if (strstr(r, s) != NULL)cnt++;
	}
	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 1184
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


void ng()
{
  std::cout << -1 << std::endl;

  exit(0);
}


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, A[222222];

  std::cin >> N;

  for (int i = 0; i < N; i ++)
    std::cin >> A[i];

  A[N] = A[N - 1];

  if (A[0])
    ng();

  std::reverse(A, A + N + 1);

  long long C = 0;

  for (int i = 1; i < N; i ++)
    if (A[i] != A[i - 1] - 1) {
      if (A[i] >= A[i - 1]) {
        C += A[i];
      }
      else {
        ng();
      }
    }

  std::cout << C << std::endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<pll> vpl;
typedef vector<int> vi;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0 ? a : gcd(b, a%b));}
ll exp(ll a,ll b,ll m){
    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
 
}

const int MAXN = 200100;

int32_t main(){
  fastio;
  int k;
  cin>>k;
  int s=0;
  for(int a=1;a<=k;a++){
    for(int b=1;b<=k;b++){
      for(int c=1;c<=k;c++){
        s+=gcd(gcd(a,b),c);
      }
    }
  }
  cout<<s<<endl;
  // Math -> gcd it all // chack MAXN // check ll
  //did you check N=1? Did you mix up N,M?
}

Measured memory_bytes: 3648
i_num = int(input())
factorial_dict = {}
total_res = 1

def do_factorial(n) :
    res = 1

    for i in range(2, n + 1) :
        cnt = 0
        while n%i == 0 :
            n //= i
            cnt += 1

        if i in factorial_dict.keys() :
            factorial_dict[i] += cnt
        else :
            factorial_dict[i] = cnt
            
        # print(factorial_dict)

for i in range(2, i_num + 1) :
    do_factorial(i)
    
for k, v in factorial_dict.items() :
    total_res *= (v + 1)
    
print(total_res % (10 ** 9 + 7))

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 2000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

bool debug=false;
/*---------------------------------------------------*/

int main(){
  int n,miss=0,tmp=0;
  ll a[100005];
  cin>>n;
  rep(i,n)cin>>a[i];
  rep(i,n){
    if(a[i]%4!=0){
      miss++;
      if(a[i]%2==0)tmp++;
    }
  }
  miss-=tmp/2;
  int x;
  if(n%2==0)x=n/2;
  else x=n/2+2;
  if(miss<=x)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


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

int main() {
  int  a, b, c, d;
  cin >> a >> b;
  d = b;
  bool e = 1;
  while(d > 0){
    a *= 10;
    d /= 10;
  }
  c = a + b;
  rep(i,  1000){
    if(i*i == c) break;
    else if(i*i > c){
      e = 0;
      break;
    }
  }
  if(e) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;

int main() {
	int a, b, c, d, e, f, g, h, i;
	string s;


	cin >> a >>b >> c;
	d = 0;



	for (i = 1; i <11 ; i++) {
		d = c * a - b;
		cout << d<< "\n";
		c = d;
	
	
	
	}



	return 0;

}

Measured memory_bytes: 256
//https://misteer.hatenablog.com/entry/ARC096-D
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

int main()
{
    ll N, C;
    cin >> N >> C;

    vector<ll> x(N + 2), v(N + 2);
    for (ll i = 1; i <= N; i++)
    {
        cin >> x[i] >> v[i];
    }
    x[0] = 0;
    x[N + 1] = C;

    ll cal = 0;
    vector<vector<ll>> dp(2, vector<ll>(100010, 0));

    for (ll i = 1; i <= N; i++)
    {
        cal -= x[i] - x[i - 1];
        cal += v[i];
        dp[0][i] = max(dp[0][i - 1], cal);
        // ここでそれまでのカロリーの最大値をメモ
    }

    cal = 0;
    for (ll i = N; i >= 1; i--)
    {
        cal -= x[i + 1] - x[i];
        cal += v[i];
        dp[1][i] = max(dp[1][i + 1], cal);
    }

    ll maxcal = 0;
    for (ll i = 0; i <= N; i++)
    {
        // 時計回り
        cal = dp[0][i] + dp[1][i + 1] - x[i];
        maxcal = max(maxcal, cal);

        // 反時計回り
        cal = dp[0][i] + dp[1][i + 1] - C + x[i + 1];
        maxcal = max(maxcal, cal);
    }

    cout << maxcal << endl;

    return 0;
}

Measured memory_bytes: 4096
program main
	implicit none
    character(10**5)::s
    integer(8)::i,len1,ans
    read(*,*) s
    len1=len_trim(s)
    ans=0
    if (s(1:1)=='1')then
    
    	do i=1,len1
        	if(mod(i,2)==0)then
            	if(s(i:i)/='0')then
                	ans=ans+1
                end if
            else
            	if(s(i:i)/='1')then
                	ans=ans+1
                end if
            end if
        end do
    else
    	do i=1,len1
        	if(mod(i,2)==0)then
            	if(s(i:i)/='1')then
                	ans=ans+1
                end if
            else
            	if(s(i:i)/='0')then
                	ans=ans+1
                end if
            end if
        end do
    end if
    write(*,*) ans
    stop
end program main

    	



Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
#define ll long long                  // Short form for long long
#define ld long double                // Short form for long double
typedef pair<ll, ll> pii;              // Pair of long long
typedef vector<ll> vi;                // Vector of long long
typedef vector<vi> vvi;               // Vector of vector of long long
typedef vector<pii> vii;               // Vector of pairs
typedef vector<vii> vvii;             // Vector of vector of pairs
#define pq priority_queue             // Max heap (To convert to min heap, use negative sign before every value)
#define ff first                      // For pairs
#define ss second                     // For pairs
#define pb push_back                  // Pushback to vector
#define mp make_pair                  // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end() // Mainly used by me in sorting

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
vvi adj;
ll n,m,x,y,k;
// vi dp,vis;
ll mod = 1e9 + 7;
ll t=1;
bool isPrime(ll n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false;   
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false;   
    return true; 
} 

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // cin>>t;
    while(t--){
        cin>>n>>k;
        vi a(n+1),s(n+1);
        s[0]=0;
        for(int i=1;i<=n;i++){cin>>a[i];s[i]=s[i-1]+a[i];}
        sort(all(a));
        ll dp[k+1][n+1]={0};
        for(int i=0;i<=n;i++)dp[0][i]=1;
        for(int i=1;i<=k;i++)dp[i][0]=0;
        for(int i=1;i<=k;i++){
            for(int j=1;j<=n;j++){
                
                // if(i>s[j])continue;
                
                ll x = min((ll)i,a[j]);
                
                // else if(i==s[j]){dp[i][j]=1;continue;}
                // if(i==2 && j==1){cout<<x<<"\n";}
                
                if(x==i)dp[i][j] = dp[i-1][j] + dp[i][j-1];
                
                else{
                    dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-x-1][j-1];
                }
                if(dp[i][j]<0)dp[i][j]+=mod;
                dp[i][j]%=mod;
                
                // while(x>=0){dp[i][j]+=dp[i-x][j-1];x--;dp[i][j]%=mod;}
            }
        }
        
        dp[k][n]%=mod;
        cout<<dp[k][n];
    }
    return 0;
}    

Measured memory_bytes: 79232
from collections import Counter
n, k, q = map(int, input().split())
a = [int(input()) for _ in range(q)]
a_cnt = Counter(a)
ans = [k+a_cnt[i+1]-q for i in range(n)]
for i in range(n):
    if ans[i] > 0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 15060
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
//  ba;
signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  string s;
  cin >> s;
  rep(i, SIZE(s)) {
    if (i % 2 == 0 and (s[i] == 'L')) {
      cout << "No" << endl;
      return 0;
    }
    if (i % 2 == 1 and (s[i] == 'R')) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

int main() {
  char b;
  cin>>b;
  if (b=='A')puts("T");
  else if (b=='T')puts("A");
  else if (b=='C')puts("G");
  else if (b=='G')puts("C");
  return 0;
}


Measured memory_bytes: 256
def divisor(n): 
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n //= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

n = int(input())
a = sorted(divisor(n))
cnt = 0
for i in range(1, len(a)):
    b = prime_decomposition(a[i])
    if len(list(set(b))) == 1:
        if n % a[i] == 0:
            n //= a[i]
            cnt += 1
print(cnt)

Measured memory_bytes: 9244
#include<iostream>

#include <vector>
#include <list>
#include<stack>
#include<queue>
#include<array>

#include <set>
#include<map>

#include<string>
#include<stdlib.h>

#include<algorithm>
#include <functional>
#include<math.h>

#include<fstream>
#include<iomanip>

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7


//変数
int N;
vector<pair<ll, ll>> xy;






//サブ関数
//入力
void input()
{
	cin >> N;

	ll a, b;
	REP(i, N) {
		cin >> a >> b;
		xy.push_back({ a,b });
	}
}

ll calc_res2(const vector<ll>& minv) {
	ll res = minv.back() - minv.front();
	ll last = minv.back();
	priority_queue<pair<ll, ll>,
		vector<pair<ll,ll>>,
		greater<pair<ll,ll>>> pq;

	REP(i, N) {
		pq.push({ min(xy[i].first,xy[i].second),i });
	}

	bool ignore = true;
	set<int> st;
	REP(i, N) {
		auto best = pq.top(); pq.pop();
		if (st.find(best.second) != st.end()) {
			res = min(res, last - best.first);
			break;
		}
		st.insert(best.second);
		
		if (ignore) {
			ignore = false;
		}
		else {
			res = min(res, last - best.first);
		}
		auto next = max(xy[best.second].first, xy[best.second].second);
		last = max(last, next);
		pq.push({ next,best.second });
	}
	return res;
}

//計算
void calc()
{
	vector<ll>  minv, maxv;
	for (auto p : xy) {
		ll a = p.first;
		ll b = p.second;
		minv.push_back(min(a, b));
		maxv.push_back(max(a, b));
	}
	sort(minv.begin(), minv.end());
	sort(maxv.begin(), maxv.end());

	ll res1 = abs(minv.back() - minv.front())
		* abs(maxv.back() - maxv.front());

	ll tmp = maxv.back() - minv.front();
	ll res2 = calc_res2(minv)*tmp;
	cout << min(res1, res2) << endl;
} 


//出力
void output()
{

}


//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	input();
	calc();
	output();
	debug();
	
	return 0;
}


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

const string judge[4] = { "AC", "WA", "TLE", "RE" };
const string txt = " x ";
int N;
int C[4];

int main(void) {
	cin >> N;
	for (int i = 0; i < 4; ++i)
		C[i] = 0;
	for (int i = 0; i < N; ++i) {
		string str;
		cin >> str;
		for (int j = 0; j < 4; ++j) {
			if (str == judge[j]) {
				++(C[j]);
				break;
			}
		}
	}
	for (int i = 0; i < 4; ++i)
		cout << judge[i] << txt << C[i] << '\n';
	return 0;
}


Measured memory_bytes: 3632
<?php
fscanf(STDIN, "%d %d", $H, $W);
$str = "";
for ($i = 0; $i < $H; $i++) {
    $s = trim(fgets(STDIN));
    $str .= $s;
}
$c[4] = ($H - $H % 2) * ($W - $W % 2) / 4;
$c[2] = ($H % 2) * ($W - $W % 2) / 2 + ($H - $H % 2) * ($W % 2) / 2;
$c[1] = ($H % 2) * ($W % 2);

$a = array_count_values(str_split($str));

$ans = true;

foreach ($c as $n => $cnt) {
    for ($i = 0; $i < $cnt; $i++) {
        $bool = false;
        foreach ($a as $k => $v) {
            if ($v >= $n) {
                $a[$k] -= $n;
                $bool = true;
                break;
            }
        }
        if (! $bool) {
            $ans = false;
        }
    }
}
echo $ans ? "Yes" : "No";


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

int main()
{
  int n ;
  cin >> n;
  int a;
  cin >> a;
  int ans = 0;
  ans = n % 500;
  if(a >= ans){
      cout << "Yes" << endl;
  }else {
      cout << "No" << endl;
  }

}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp13
{
	class Program
	{
		static void Main(string[] args)
		{
			String[] input = Console.ReadLine().Split(' ');
			int n = int.Parse(input[0]);
			int k = int.Parse(input[1]);
			int[] A = new int[n];
			for (int i = 0; i < k; i++)
			{
				int h = int.Parse(Console.ReadLine());
				string[] w = Console.ReadLine().Split(' ');
				for (int j = 0; j < h; j++)
				{
					A[int.Parse(w[j]) - 1] = 1;

				}
			}
			int count = 0;
			for (int i = 0; i < n; i++)
			{
				//Console.Write(A[i]);
				if (A[i] == 0)
				{
					count++;
				}
				



			}
			Console.WriteLine(count);
			

		}
	}
}

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

using namespace std;
mt19937_64 rng(58);

typedef long long ll;

int k;
string s;
// find b s.t. a * b = 1 (mod m)
template <typename T>
T inverse(T a, T m) {
  T u = 0, v = 1;
  while (a != 0) {
    T t = m / a;
    m -= t * a; swap(a, m);
    u -= t * v; swap(u, v);
  }
  assert(m == 1);
  return u;
}

template<long long mod = 1000000007>
struct modint{
	long long a;
	modint() : a(0){}
	modint(long long t) { a = t % mod; if(a < 0) a += mod; }
	operator long long() const{ return a; }
	bool operator==(const modint &x) const{ return a == x.a; }
	bool operator!=(const modint &x) const{ return a != x.a; }
	modint operator-() const{ return modint(a ? (mod - a) : 0); }
	modint operator~() const{ return inverse(a, mod); }

	modint operator+(const modint &x) const{ return modint(*this) += x; }
	modint operator-(const modint &x) const{ return modint(*this) -= x; }
	modint operator*(const modint &x) const{ return modint(*this) *= x; }
	modint operator/(const modint &x) const{ return modint(*this) /= x; }

	modint &operator+=(const modint &x){
		a += x.a;
		if(a >= mod) a -= mod;
		return *this;
	}
	modint &operator-=(const modint &x){
		a -= x.a;
		if(a < 0) a += mod;
		return *this;
	}
	modint &operator*=(const modint &x){
		a = a * x.a % mod;
		return *this;
	}
	modint &operator/=(const modint &x){
		a = a * (~x).a % mod;
		return *this;
	}

	friend ostream &operator<<(ostream &os,const modint &x){
		return os << x.a;
	}
	friend istream &operator>>(istream &is,modint &x){
		long long t;
		is >> t;
		x = modint(t);
		return is;
	}

	modint pow(long long x) const{
		modint ret = 1,tmp = a;
		for(;x;tmp *= tmp,x >>= 1){
			if(x & 1) ret *= tmp;
		}
		return ret;
	}
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin >> k >> s;

    modint<> f[k+s.length() + 1], finv[k+s.length() + 1];
    f[0] = finv[0] = 1;
    for (int i=1; i<=k+s.length(); i++) {
        f[i] = i * f[i - 1];
        finv[i] = ~f[i];
    }

    modint<> ans = 0;
    for (int idx = s.length()-1; idx < k+s.length(); idx++) {
        ans += f[idx] * finv[s.length() - 1] * finv[idx - s.length() + 1] *
        modint<>(25).pow(idx - s.length() + 1) *
        modint<>(26).pow(s.length() + k - 1 - idx);
    }
    cout << ans << endl;
}

Measured memory_bytes: 35656
n,m = map(int,input().split())

conds = []
for i in range(m):
    s,c = map(int,input().split())
    conds.append([s-1,c])

flag = False
if n == 1:
    for i in range(10):
        t = str(i)
        temp = True
        for c in conds:
            if int(t[c[0]]) == c[1]:
                continue
            else:
                temp = False

        if temp:
            flag = True
            print(i)
            break
else:
    for i in range(10**(n-1),10**n):
        t = str(i)
        temp = True
        for c in conds:
            if int(t[c[0]]) == c[1]:
                continue
            else:
                temp = False

        if temp:
            flag = True
            print(i)
            break

if not flag:
    print(-1)


Measured memory_bytes: 3064
// #pragma GCC optimize(2)
// #pragma G++ optimize(2)
// #pragma comment(linker,"/STACK:102400000,102400000")

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

typedef long long LL;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef float fl;
typedef long double ld;
typedef pair<int,int> pii;
#if (WIN32) || (WIN64) || (__WIN32) || (__WIN64) || (_WIN32) || (_WIN64) || (WINDOWS)
#define lld "%I64d"
#define llu "%I64u"
#else
#define lld "%lld"
#define llu "%llu"
#endif
#define ui(n) ((unsigned int)(n))
#define LL(n) ((long long)(n))
#define ull(n) ((unsigned long long)(n))
#define fl(n) ((float)(n))
#define ld(n) ((long double)(n))
#define char(n) ((char)(n))
#define Bool(n) ((bool)(n))
#define fixpoint(n) fixed<<setprecision(n)

const int INF=1061109567;
const int NINF=-1044266559;
const LL LINF=4557430888798830399;
const ld eps=1e-15;
#define MOD (1000000007)
#define PI (3.1415926535897932384626433832795028841971)

#define MP make_pair
#define MT make_tuple
#define All(a) (a).begin(),(a).end()
#define pall(a) (a).rbegin(),(a).rend()
#define Log(x,y) log(x)/log(y)
#define SZ(a) ((int)(a).size())
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define rep1(i,n) for(int i=1;i<=((int)(n));i++)
#define repd(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define repd1(i,n) for(int i=((int)(n));i>=1;i--)
#define repv(itr,v) for(__typeof((v).begin()) itr=(v).begin();itr!=(v).end();itr++)
#define repV(i,v) for(auto i:v)
#define repE(i,v) for(auto &i:v)
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x) MS(x,0)
#define MINF(x) MS(x,63)
#define MCP(x,y) memcpy(x,y,sizeof(y))
#define UN(v) sort(All(v)),v.erase(unique(All(v)),v.end())
#define filein(x) freopen(x,"r",stdin)
#define fileout(x) freopen(x,"w",stdout)
#define fileio(x)\
	freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout)
#define filein2(filename,name) ifstream name(filename,ios::in)
#define fileout2(filename,name) ofstream name(filename,ios::out)
#define fileio2(filename,name) fstream name(filename,ios::in|ios::out)
#define sqr(x) ((x)*(x))
#define Pause system("pause")
#define Cls system("cls")
#define fs first
#define sc second
#define SF scanf
#define PF printf

const int maxn=2000010;

int n,m;
string s;
LL fac[maxn],inv[maxn],ans;

inline LL powmod(LL a,LL b)
{
	LL res=1;a%=MOD;

	for(;b;b>>=1)
	{
		if(b&1) res=res*a%MOD;
		a=sqr(a)%MOD;
	}

	return res;
}

inline LL C(int a,int b)
{
	if(b>a) return 0ll; else return fac[a]*inv[b]%MOD*inv[a-b]%MOD;
}

int main()
{
	fac[0]=fac[1]=1;
	for(int i=2;i<=2000000;i++) fac[i]=fac[i-1]*i%MOD;

	inv[2000000]=powmod(fac[2000000],MOD-2);
	for(int i=2000000-1;i>=0;i--) inv[i]=inv[i+1]*(i+1)%MOD;

	cin>>n>>s;m=SZ(s);

	for(int i=0;i<=n;i++) ans=(ans+powmod(26,i)*C(n+m-i-1,m-1)%MOD*powmod(25,n-i)%MOD)%MOD;
	
	cout<<ans;

	return 0;
}

Measured memory_bytes: 36588
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

vector<int> dp(mx,inf);

int main(){
  int n,co;
  cin >> n >> co;
  vector<vector<int>> d(50, vector<int>(50));
  vector<vector<int>> c(3, vector<int>(50,0));
  rep(i,co)rep(j,co){ cin>>d[i][j]; }
  rep(i,n)rep(j,n){
    int k; cin>>k; k--; 
    c[(i+j)%3][k]++;
  }
  int ans=inf;
  rep(i,co)rep(j,co)if(i!=j)rep(k,co)if(i!=k&&j!=k){
    int cur=0;
    rep(p,co){ cur += d[p][i]*c[0][p]; }
    rep(p,co){ cur += d[p][j]*c[1][p]; }
    rep(p,co){ cur += d[p][k]*c[2][p]; }
    ans = min(ans,cur);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
import java.util.ArrayDeque;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int N, E;
	static boolean[][] g;

	public static void main(String[] args) {
		N = sc.nextInt();
		g = new boolean[N][N];
		E = 0;
		for (int i = 0; i < N; ++i) {
			char[] row = sc.next().toCharArray();
			for (int j = 0; j < N; ++j) {
				g[i][j] = row[j] == 'Y';
				if (g[i][j]) ++E;
			}
		}
		E /= 2;
		System.out.println(solve() ? "Taro" : "Hanako");
	}

	static boolean solve() {
		if (N % 2 == 1) {
			return ((N * (N - 1)) / 2 - E) % 2 != 0;
		}
		if (E == 0) return false;
		boolean[] visited = new boolean[N];
		int ec = 0;
		int oc = 0;
		for (int i = 0; i < N; ++i) {
			if (visited[i]) continue;
			int count = 1;
			visited[i] = true;
			ArrayDeque<Integer> q = new ArrayDeque<Integer>();
			q.add(i);
			while (!q.isEmpty()) {
				int pos = q.poll();
				for (int j = 0; j < N; ++j) {
					if (!visited[j] && g[pos][j]) {
						++count;
						q.add(j);
						visited[j] = true;
					}
				}
			}
			if (count % 2 == 0) {
				++ec;
			} else {
				++oc;
			}
		}
		boolean taroEven = ((N * (N - 1)) / 2 - E) % 2 != 0;
		if (taroEven) {
			int turnTaro = ((ec + oc) - 1) / 2;
			return oc <= turnTaro * 2;
		} else {
			int turnHanako = ((ec + oc) - 2) / 2;
			return !(oc <= turnHanako * 2);
		}
	}

}

Measured memory_bytes: 30544
#include<stdio.h>
int main(void)
{
	int a,b,d=0,i,s=0,sum=0,average=0;
	while(scanf("%d,%d",&a,&b) !=EOF){
	sum+=a*b;
	s+=b;
	d++;
	}
	average=(double)s/(double)d+0.5;
	printf("%d\n%d\n",sum,average);
	
	return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long int;

const int MOD = 1000000007;
int main() {
    int N, M; cin >> N >> M;
    vector<int> A(N), B(M);
    for(int i=0; i<N; i++) cin >> A[i];
    for(int i=0; i<M; i++) cin >> B[i];

    ll ans = 1;
    vector< vector<ll> > dp(N+1, vector<ll>(M+1));
    for(int i=0; i<=M; i++) dp[0][i] = 1;
    for(int i=0; i<N; i++) {
        for(int j=0; j<M; j++) {
            ll add = (A[i] == B[j] ? dp[i][j] : 0);
            (ans += add) %= MOD;
            (dp[i+1][j+1] += dp[i+1][j] + add) %= MOD;
        }
        for(int j=0; j<=M; j++) {
            (dp[i+1][j] += dp[i][j]) %= MOD;
        }
    }
    (ans += MOD) %= MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 31616
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("O2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
////
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#include <bits/stdc++.h>

#include <random>

#define all(x) (x).begin(), (x).end()
#define allp(x) (x)->begin(), (x)->end()

#define pb push_back


using namespace std;
void dout() { cerr << endl; }
//typedef long long ll;
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

using ll = long long;
//#ifdef __int128
//using hll = __int128;
//#endif
using pii = pair<ll, ll>;
using ld = long double;
using pll = pair<long long, long long>;

template <typename T>
void do_uniq(vector<T> vec){
    sort(all(vec));
    vec.resize(unique(all(vec)) - vec.begin());
}

clock_t timestamp_start = clock();
void time_calc()
{
    cerr << (ld)(clock() - timestamp_start) / CLOCKS_PER_SEC << "\n";
}


#ifdef _getchar_nolock
#else
#define _getchar_nolock getchar_unlocked
#endif

//#define solvsh
//#define multi

#ifdef solvsh
#else

ll mod = 998244353;

ll add(ll a, ll b){
    return (a + b) % mod;
}
ll ml(ll a, ll b) {
    return (a * b) % mod;
}

ll sub(ll a, ll b) {
    return add(a, mod - b);
}

ll b_p(ll b, ll p) {
    if (p == 0) return 1;
    if (p & 1) return ml(b, b_p(b, p ^ 1));
    ll v = ml(b, p >> 1);
    return ml(v, v);
}
const int MAXN = 2e5 + 121;

ll dp[MAXN];

ll t[4 * MAXN];

int sum (int v, int tl, int tr, int l, int r) {
    if (l > r)
        return 0;
    if (l == tl && r == tr)
        return t[v];
    int tm = (tl + tr) / 2;
    return add(sum(v * 2, tl, tm, l, min(r, tm)), sum(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}

void update (int v, int tl, int tr, int pos, int new_val) {
    if (tl == tr)
        t[v] = new_val;
    else {
        int tm = (tl + tr) / 2;
        if (pos <= tm)
            update(v * 2, tl, tm, pos, new_val);
        else
            update(v * 2 + 1, tm + 1, tr, pos, new_val);
        t[v] = add(t[v * 2], t[v * 2 + 1]);
    }
}

void solve() {

    int n, k;
    cin >> n >> k;

    vector<pair<int, int>> v;

    for (int i = 0; i < k; ++i) {
        int x, y;
        cin >> x >> y;
        v.push_back({x, y});
    }

    update(1, 0, n, 1, 1);

    for (int i = 2; i <= n; ++i) {
        ll acc = 0;
        for (auto e : v) {
            int x = e.first;
            int y = e.second;

            if (i - x < 0) continue;

            acc = add(acc, sum(1, 0, n, max(0, i - y), max(0, i - x)));
        }

        update(1, 0, n, i, acc);
    }

    cout << sum(1, 0, n, n, n);
}

#endif

void multisolve() {
    int t;
    cin >> t;

    int i = 1;
    while (t--) {
        solve();
        i++;
    }
}

#define int int
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cout << fixed << setprecision(20);

#ifdef multi
    //        gen();
    multisolve();
#else
    solve();
//    gen();
#endif
//    time_calc();
}


Measured memory_bytes: 7740