akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define int long long
#define re(i,n) for(i=0;i<n;i++)
#define bre(i,n) for(i=n;i>0;i--)
#define rep(i,l,r) for(i=l;i<r;i++)
#define brep(i,l,r) for(i=r;i>l;i--)
const int inf=1145141919810893;
const int mod=1000000007;
using namespace std;
template<class T>bool chmin(T &a,const T &b){
	if(a>b){
		a=b;
		return true;
	}
	return false;
}
template<class T>bool chmax(T &a,const T &b){
	if(a<b){
		a=b;
		return true;
	}
	return false;
}
template<class T>void debug(T *a,int l,int r,const char *name){
	for(int i=l;i<r;i++)
		cout<<name<<"["<<i<<"]="<<a[i]<<endl;
}
template<int H,int W>int wa(int x1,int y1,int x2,int y2,int(&p)[H][W]){
	return p[y2][x2]-p[y2][x1]-p[y1][x2]+p[y1][x1];
}
struct Unif{
	vector<int> e;
	vector<int> rank;
	Unif(int n):e(n,-1),rank(n,1){}
	void uni(int a,int b){
		if(e[a]!=-1)
			uni(e[a],b);
		else if(e[b]!=-1)
			uni(a,e[b]);
		else{
			if(a==b)
				return;
			int ra=rank[a],rb=rank[b];
			if(ra>=rb){
				e[b]=a;
				if(ra==rb)
					rank[a]++;
			}
			else
				e[a]=b;
		}
	}
	bool find(int a,int b){
		if(e[a]!=-1)
			return find(e[a],b);
		else if(e[b]!=-1)
			return find(a,e[b]);
		else
			return a==b;
	}
	int num(int a){
		if(e[a]!=-1)
			return num(e[a]);
		else
			return a;
	}
};
int A,B,C,D,N,M,K,S,T,H,W;
int p[214514],q[214514];
signed main(){
	int i,j,k;
	cin>>N;
	re(i,N)
		cin>>p[i]>>q[i];
	bool f=false;
	re(i,N)
		if(p[i]!=q[i]){
			f=true;
			break;
		}
	if(!f){
		cout<<0<<endl;
		return 0;
	}
	int u=inf,v;
	int sum=0;
	re(i,N){
		sum+=p[i];
		if(p[i]>q[i]&&q[i]<u){
			u=q[i];
			v=i;
		}
	}
	cout<<sum-q[v]<<endl;
}

Measured memory_bytes: 512
from itertools import accumulate as ac
n,q=map(int,input().split())
s=input()
d=[0]*(n+1)
for i in range(1,n):
    if s[i-1]+s[i]=="AC":
        d[i+1]+=1
d=list(ac(d))
for i in range(q):
    l,r=map(int,input().split())
    print(d[r]-d[l])

Measured memory_bytes: 7944
n, d = gets.split("\s").map(&:to_i)

count = 0
x = []

n.times do |i|
  x << gets.split("\s").map(&:to_i)
end

0.upto(n-1) do |i|
  (i+1).upto(n-1) do |j|
    x_zip = x[i].zip x[j]
    sum = 0
    x_zip.each do |x_y| sum += (x_y[0] - x_y[-1])**2 end
    dist = Math.sqrt(sum)
    
    count += 1 if dist - dist.to_i == 0
  end
end

p count

Measured memory_bytes: 1788
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 100000000
#define INF 300000000000000000
#define MOD 1000000007
#define mod 1000000007
#define INT_MAX_ 2147483647
#define EPS (1e-10)
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,Pll> a,pair<ll,Pll> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se.fi>b.se.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_t=clock();
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //-------------------------------
    int N; cin >> N;
    vector<Pin> res;
    int dame = N;
    if (N % 2 == 1) --dame;

    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= N; ++j) {
            if (j <= i || j == dame) continue;
            res.push_back(Pin(i, j));
        }
        --dame;
    }

    cout << res.size() << endl;
    for (auto p : res) {
        cout << p.first << " " << p.second << endl;
    }
    //-------------------------------  
    //fclose(stdin);
    //fclose(stdout);
    //ll end_t=clock();cout<<"time="<<end_t-begin_t<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------







































Measured memory_bytes: 384
fun main(args: Array<String>) {
    val s = readLine()!!.replace("BC", "D").replace("C", "B").split('B')
    var ans = 0L
    s.forEach {
        var i = 0
        it.forEach {c ->
            if (c == 'A')
                i += 1
            else
                ans += i
        }
    }
    println(ans)
}


Measured memory_bytes: 57932
#include<stdio.h>
int main(){
  int n,m,i,j,k,l;
  char a[100][100],b[100][100];
  scanf("%d %d",&n,&m);
  for(i=0;i<n;i++)scanf("%s",a[i]);
  for(i=0;i<m;i++)scanf("%s",b[i]);
  for(i=0;i+m<=n;i++){
    for(j=0;j+m<=n;j++){
      for(k=0;k<m;k++){
	for(l=0;l<m;l++){
	  if(a[i+k][j+l]-b[k][l])goto NEXT;
	}
      }
      goto END;
    NEXT:;
    }
  }
  printf("No\n");
  return 0;
 END:;
  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <map>
#include <utility>
using namespace std;

int p1[200010], p2[200010];
map<pair<int, int>, int> mp;

int p1_(int x){
  if(x == p1[x]) return x;
  return (p1[x] = p1_(p1[x]));
}
int p2_(int x){
  if(x == p2[x]) return x;
  return (p2[x] = p2_(p2[x]));
}

int main(){
  int N, K, L; scanf("%d%d%d", &N, &K, &L);
  for(int i = 1; i <= N; i++) p1[i] = p2[i] = i;

  for(; K--; ){
    int x, y; scanf("%d%d", &x, &y);
    p1[p1_(y)] = p1_(x);
  }
  for(; L--; ){
    int x, y; scanf("%d%d", &x, &y);
    p2[p2_(y)] = p2_(x);
  }

  for(int i = 1; i <= N; i++){
    int p1v = p1_(i), p2v = p2_(i);
    mp[make_pair(p1v, p2v)]++;
  }

  for(int i = 1; i <= N; i++) printf("%d ", mp[make_pair(p1[i], p2[i])]);
  printf("\n");

  return 0;
}

Measured memory_bytes: 13568
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#define LL long long
LL N,ans;
LL A[310][310];
LL B[310][310];
bool D[310][310];
int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cin>>N;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            std::cin>>A[i][j];
            B[i][j]=A[i][j];
        }
    }
    for(int k=0;k<N;k++){
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                if(i==j||i==k||j==k)continue;
                if(B[i][k]+B[k][j]==A[i][j]){
                    D[i][j]=true;
                    D[j][i]=true;
                }
                B[i][j]=std::min(B[i][j],B[i][k]+B[k][j]);
                if(B[i][j]<A[i][j]){
                    std::cout<<-1<<std::endl;
                    return 0;
                }
            }
        }
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<i;j++){
            if(!D[i][j])ans+=A[i][j];
        }
    }
    std::cout<<ans<<std::endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<math.h>
#include<string>
#include<algorithm>
using namespace std;

int main(){
	string a,b,c;
	cin>>a>>b>>c;
	char value=-'a'+'A';
	printf("%c%c%c\n",a[0]+value,b[0]+value,c[0]+value);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
#include <cstdio>
#include <complex>
#include <cstring>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

int m[100][100];
int sx,sy,gx,gy;
int w,h;
bool dfs(int x,int y,int c){
  if(x==gx&&y==gy)return true;
  if(m[y][x] == 0)return false;
  m[y][x] = 0;
  //cout<<x<<" "<<y<<" "<<c<<endl;
  int dx[] = {0,0,-1,1}, dy[] = {1,-1,0,0};
  bool judge=false;
  rep(i,4){
    if(m[y+dy[i]][x+dx[i]] == c)
      judge |= dfs(x+dx[i],y+dy[i],c);
  }
  return judge;
}


int main(void){
  while(cin>>h>>w,h+w){
    rep(i,h)rep(j,w)m[i][j]=0;
  
    cin>>sx>>sy>>gx>>gy;
 
    int n,c,d,x,y;
    cin>>n;
    rep(i,n){
      cin>>c>>d>>x>>y;
      //cout<<c<<" "<<d<<" "<<x<<" "<<y<<endl;
      if(d){
	rep(i,4)rep(j,2)m[i+y][j+x] = c;
      }else{
	//cout<<x<<" "<<y<<endl;
	rep(i,2)rep(j,4)m[i+y][j+x] = c;      
      }
    }
    //m[sy][sx] = 8; m[gy][gx] = 9;
    //cout<<"  ";rep(i,w)cout<<i%10<<" ";cout<<endl;
    //rep(i,h){cout<<i%10<<" ";rep(j,w)cout<<m[i][j]<<" ";cout<<endl;}
    cout<<(dfs(sx,sy,m[sy][sx])?"OK":"NG")<<endl;
  }
}

Measured memory_bytes: 1196
n = int(input())
s = list(input())
k = int(input())
remain = s[k - 1]
if s[0] == remain:
  ans = remain
else:
  ans = "*"
for i_m in range(n - 1):
  i = i_m + 1
  if s[i] == remain:
    ans += remain
  else:
    ans += "*"
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>


using namespace std;

int main() {

    int N;
    cin >> N;
    vector<int> d(N);
    for (int i = 0; i < N; ++i) {
        cin >> d[i];
    }

    // 重複を削除
    std::sort(d.begin(), d.end());
    d.erase(unique(d.begin(), d.end()), d.end());

    cout << d.size() << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >>s;
  int temp = 0, maxLen = 0, begin = 0;
  for( int i = 0; i < s.length(); ++i ){
    if( s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T' ){
    }else{
		begin = i + 1;
    }
    temp = i - begin + 1;
    maxLen = max( maxLen, temp );
  }
  cout <<maxLen <<endl;
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

struct union_find {
	vector<int> v;
	union_find(int n) : v(n, -1) {}
	int find(int x) { return (v[x] < 0) ? x : (v[x] = find(v[x])); }
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x != y) {
			if (-v[x] < -v[y]) swap(x, y);
			v[x] += v[y]; v[y] = x;
		}
	}
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -v[find(x)]; }
};

int main() {
	for (;;) {
		int n, m; cin >> n >> m;
		if (n == 0) break;
		vector< vector<int> > e(m, vector<int>(3));
		for (int i = 0; i < m; i++) {
			int a, b, w; cin >> a >> b >> w;
			e[i][0] = w; e[i][1] = a - 1; e[i][2] = b - 1;
		}
		sort(e.begin(), e.end());
		int mini = INT_MAX;
		for (int i = 0; i < m; i++) {
			union_find uf(n);
			int cnt = 0, maxi = 0;
			for (int j = i; j < m; j++) {
				int u = e[j][1], v = e[j][2], w = e[j][0];
				if (uf.same(u, v)) continue;
				uf.unite(u, v);
				cnt++;
				maxi = w;
			}
			if (cnt == n - 1)
				mini = min(mini, maxi - e[i][0]);
		}
		cout << (mini < INT_MAX ? mini : -1) << endl;
	}
}

Measured memory_bytes: 1352
//Only the Creator has given me strength!

#include<cstdio>

#include<sstream>

#include<cstdlib>

#include<cctype>

#include<cmath>

#include<algorithm>

#include<set>

#include<queue>

#include<stack>

#include<list>

#include<iostream>

#include<fstream>

#include<numeric>

#include<string>

#include<vector>

#include<cstring>

#include<map>

#include<iterator>

#include<bitset>

typedef long long ll;

#define pi 3.1415926535897931159979635

#define pb push_back

#define vctr vector < int >

#define vvtr vector < vctr >

using namespace std;

ll mod=1e7+7;

void fastio() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

}

int main() {

    fastio();

    int x; cin>>x;

    if(x==0) cout<<1<<"\n";

    else cout<<"0\n";

    return 0;

}

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

int main(){
  int K;
  vector <int> vec;
  vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cin >> K;
  cout << vec.at(K - 1) << endl;
}
 


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
using ll=long long;
const ll MOD=1000000007;



int main() {
    double R;
    cin>>R;
    //小数第10位まで出力
cout<<fixed<<setprecision(10);
    cout<<R*2*3.1415926535<<endl;
}

Measured memory_bytes: 3780
#include<bits/stdc++.h>
using namespace std;
void solve(){
		unordered_map<string,int>m;
		int n;
		cin>>n;
		for(int i=0;i<n;i++)
		{
			string s;
			cin>>s;
			m[s]++;
		}
		cout<<"AC "<<"x "<<m["AC"]<<endl;
		cout<<"WA "<<"x "<<m["WA"]<<endl;
		cout<<"TLE "<<"x "<<m["TLE"]<<endl;
		cout<<"RE "<<"x "<<m["RE"]<<endl;

}
int main()
{
	solve();
}


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

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

using namespace std;
using ll = long long;

typedef struct Node{
    vector<int> edges_to;
    vector<int> edges_cost;

    int id;

    int cost;
    bool done;
} Node;

bool operator > (Node a, Node b){
    return a.cost > b.cost;
}
bool operator < (Node a, Node b){
    return a.cost < b.cost;
}

void init(int N, Node *nodes);

void dijkstra(Node *nodes, int s){

    priority_queue<Node, vector<Node>, greater<Node>> q;
    nodes[s].cost = 0;

    q.push(nodes[s]);
    while(!q.empty()){
        Node doneNode = q.top();
        q.pop();
        if(nodes[doneNode.id].done == true) continue;

        nodes[doneNode.id].done = true;
        int loop = doneNode.edges_to.size();
        rep(i, loop){
            int to = doneNode.edges_to[i];
            int c = doneNode.cost + doneNode.edges_cost[i];
            if(c < nodes[to].cost){
                nodes[to].cost = c;
                q.push(nodes[to]);
            }
        }
    }
}

int main(void){
    int N, M, R;
    cin >> N >> M >> R;
    int matrix[N][N];
    int visit[R]; rep(i, R) {int temp; cin >> temp; visit[i] = temp-1;} sort(visit, visit+R);
    Node nodes[N]; init(N, nodes);
    rep(i, M){
        int a, b, c;
        cin >> a >> b >> c;
        nodes[a-1].edges_to.push_back(b-1); nodes[a-1].edges_cost.push_back(c);
        nodes[b-1].edges_to.push_back(a-1); nodes[b-1].edges_cost.push_back(c);
    }
    rep(i, N){
        dijkstra(nodes, i);
        rep(j, N){
            matrix[i][j] = nodes[j].cost;
            matrix[j][i] = matrix[i][j];
        }
        init(N, nodes);
    }

    int ans = INFINITY;
    do{
        int acc = 0;
        int s = visit[0];
        for(int i = 1; i < R; i++){
            acc += matrix[s][visit[i]];
            s = visit[i];
        }
        if(acc < ans) ans = acc;
    }while(next_permutation(visit, visit+R));
    cout << ans << endl;
    return 0;
}

void init(int N, Node *nodes){
    rep(i, N){
        nodes[i].id = i;
        nodes[i].cost = INFINITY;
        nodes[i].done = false;
    }
}

Measured memory_bytes: 2364
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int> nums(n);
    for(int i=0;i<n;i++)
    {
        cin>>nums[i];
    }
    int pp=0,p=abs(nums[1]-nums[0]),cur;
    for(int i=2;i<n;i++)
    {
        // cout<<pp<<" "<<p<<endl;
        cur=min(pp + abs(nums[i]-nums[i-2]), p + abs(nums[i]-nums[i-1]));
        pp=p;
        p=cur;
    }
    cout<<p<<endl;
    // cout<<pp<<endl;
    // cout<<cur<<endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
//#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define MOD 998244353
#define MAX 6001


ll fact[MAX],inverse_fact[MAX];

ll mod_pow(ll x,ll count, ll mod){

	if(count == 0)return 1;
	ll ret = mod_pow((x*x)%mod,count/2,mod);
	if(count%2 == 1){

		ret = (ret*x)%mod;
	}
	return ret;
}

ll extgcd(ll a,ll b,ll &x,ll &y){
	ll d = a;
	if(b != 0){
		d = extgcd(b,a%b,y,x);
		y -= (a/b)*x;
	}else{
		x = 1;
		y = 0;
	}
	return d;
}

ll mod_inverse(ll a,ll m){
    ll x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}


ll Lagrange(ll table[MAX],ll loc){

	if(loc <= MAX-1){

		return table[loc];
	}

	ll numerator = loc;

	for(int i = 1; i <= MAX-1; i++){

		numerator *= (loc-i);
		numerator %= MOD;
	}

	ll ret = 0;

	for(int i = 0; i <= MAX-1; i++){

		ll tmp = table[i];

		tmp *= numerator;
		tmp %= MOD;

		tmp *= mod_inverse((loc-i),MOD);
		tmp %= MOD;

		ll denominator = (inverse_fact[i]*inverse_fact[(MAX-1)-i])%MOD;

		if(((MAX-1)-i)%2 == 1){

			denominator *= (-1+MOD);
			denominator %= MOD;
		}

		tmp *= denominator;
		tmp %= MOD;

		ret += tmp;
		ret %= MOD;
	}

	return ret;
}

int main(){

	fact[0] = 1;
	for(ll i = 1; i <= MAX-1; i++){
		fact[i] = i*fact[i-1];
		fact[i] %= MOD;
	}

	inverse_fact[MAX-1] = mod_inverse(fact[MAX-1],MOD);
	for(ll i = MAX-1; i >= 1; i--){

		inverse_fact[i-1] = inverse_fact[i]*i;
		inverse_fact[i-1]%= MOD;
	}

	ll N,S;

	scanf("%lld %lld",&N,&S);

	ll ans = ((S+1)*S)/2;
	ans %= MOD;

	//左端 > 右端
	ll tmp = mod_pow(S+1,N-2,MOD);
	ans *= tmp;
	ans %= MOD;

	/*左端 == 右端 && 最小値が奇数の場合の数を求める*/

	ll table[MAX];

	//奇数の、二乗和を求める
	tmp = 0;

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

		tmp += mod_pow(2*i+1,N-1,MOD);
		tmp %= MOD;
		table[i] = tmp;
	}

	ll num_S;

	//最後の奇数項
	if(S%2 == 0){ //Sが偶数の場合

		num_S = Lagrange(table,(S-1)/2);
		ans -= num_S;
		if(ans < 0){
			ans += MOD;
		}
		ans %= MOD;

	}else{

		num_S = Lagrange(table,S/2);
		ans += num_S;
		ans %= MOD;
	}

	//偶数の、二乗和を求める
	tmp = 0;

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

		tmp += mod_pow(2*i,N-1,MOD);
		tmp %= MOD;
		table[i] = tmp;
	}

	//最後の偶数項
	if(S%2 == 0){ //Sが偶数の場合

		num_S = Lagrange(table,S/2);
		ans += num_S;

		ans %= MOD;

	}else{

		num_S = Lagrange(table,S/2);
		ans -= num_S;
		if(ans < 0){

			ans += MOD;
		}

		ans %= MOD;
	}

	printf("%lld\n",ans);

	return 0;
}



Measured memory_bytes: 3352
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let h: Vec<i64> = (0..n).map(|_| input()).collect();

    let mut v: Vec<i64> = vec![i64::max_value(); n];
    v[0] = 0;
    v[1] = (h[0] - h[1]).abs();
    for i in 2..n {
        v[i] = std::cmp::min(
            v[i - 1] + (h[i] - h[i - 1]).abs(),
            v[i - 2] + (h[i] - h[i - 2]).abs(),
        );
    }

    println!("{}", v[n - 1]);
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
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;}
#if loc||local
template<class T>void dump(T&& t){cerr<<t<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  int n;
  cin>>n;
  vector<int> ans(n+1);
  for(int x=1;x*x<=n;++x){
    for(int y=1;y*y<=n;++y){
      if(x*x+y*y+x*y>n)break;
      for(int z=1;z*z<=n;++z){
        ll tmp = x*x+y*y+z*z+x*y+y*z+z*x;
        if(tmp>n)break;
        ans[tmp]++;
      }
    }
  }
  for(int i=1;i<=n;++i)cout<<ans[i]<<endl;

}

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

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

const long INF = -(1L << 60);

int a[100010][3];
long dp[100010][3];

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < 3; j++) {
			scanf("%d", &a[i][j]);
		}
	}
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < 3; j++) {
			for(int k = 0; k < 3; k++) {
				if(j == k) continue;
				chmax(dp[i+1][k], dp[i][j] + a[i][k]);
			}
		}
	}
	long res = 0;
	for(int i = 0; i < 3; i++) {
		chmax(res, dp[n][i]);
	}
	printf("%ld", res);
}


Measured memory_bytes: 3712
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <queue>
using namespace std;

long long N;

int main(){
    cin >> N;
    
    long long x=1;
    int cnt = 1;
    while(x*26+1<=N){
        x=x*26+1;
        cnt++;
    }
    N-=x;
    string ans;
    for(int i=0; i<cnt; i++){
        ans+=char(N%26+int('a'));
        N/=26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

Measured memory_bytes: 3616
import functools
n = int(input())
a = list(map(int, input().split()))


@functools.lru_cache(maxsize=None)
def gcd(a, b):
    while b > 0:
        a, b = b, a % b
    return a


max_gcd = [[0]*n for i in range(3)]
max_gcd[0][0] = a[0]
max_gcd[0][1] = gcd(a[0], a[1])
max_gcd[1][1] = a[0]
max_gcd[2][1] = a[1]

for i in range(2, n):
    max_gcd[0][i] = gcd(max_gcd[0][i-1], a[i])
    max_gcd[1][i] = max(max_gcd[0][i-1], gcd(max_gcd[1][i-1], a[i]))
    max_gcd[2][i] = max(max_gcd[0][i-1], gcd(max_gcd[2][i-1], a[i]))

print(max(max_gcd[1][n-1],max_gcd[2][n-1]))


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

#define pb push_back
#define mp make_pair
typedef long long int ll;

void solve()
{
	ll k;
	cin >> k;

	ll total = 0;
	for (int i = 1; i <= 1e8; i++)
	{
		total = (total * 10 + 7) % k;
		if (total == 0)
		{
			cout << i;
			return;
		}
	}
	cout << -1;

}



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

#ifndef ONLINE_JUDGE
	freopen("1input.txt", "r", stdin);
	freopen("1output.txt", "w", stdout);
#endif

	int t = 1;
	// cin >> t;

	while (t--)
	{
		solve();
		cout << "\n";
	}

	return 0;
}

Measured memory_bytes: 3648
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }
        static void Solve()
        {
            var N = Sarray()[0];
            var s = ReadLine();
            var ans = new int[N + 2];
            var sheep = 0;
            var wolf = 1;
            for (var ai = 0; ai < 2; ++ai)
            {
                for (var aj = 0; aj < 2; ++aj)
                {
                    ans[0] = ai; ans[1] = aj;
                    for (var i = 1; i <= N; ++i)
                    {
                        if (ans[i] == sheep && s[i%(int)N] == 'o' || ans[i] == wolf && s[i%(int)N] == 'x')
                            ans[i + 1] = ans[i - 1];
                        else
                            ans[i + 1] = (ans[i - 1] + 1) % 2;
                    }
                    if (ans[N] == ans[0] && ans[N + 1] == ans[1])
                    {
                        for (var i = 0; i < N; ++i)
                            Write(ans[i] == 0 ? 'S' : 'W');
                        return;
                    }
                }
            }
            WriteLine(-1);
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 28788
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		long a = scan.nextLong();
		double b = scan.nextDouble();
		double b2 = Math.round(b*100);

		long re = (long)b2;


		System.out.println((long)(a*re)/100);

		scan.close();

	}

}


Measured memory_bytes: 28908
n, w = map(int, input().split())
wv = [tuple(map(int, input().split())) for _ in range(n)]

dp = [0] * (w+1)

for i in range(n):
    for j in range(w, wv[i][0]-1, -1):
        dp[j] = max(dp[j], dp[j-wv[i][0]]+wv[i][1])

print(max(dp))

Measured memory_bytes: 68660
import java.util.Scanner;

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

		Scanner scan = new Scanner(System.in);
		String S = scan.next();
		String T = scan.next();
		String result1 = "";
		String result2 ="";
		String result3 = "";
		String ans = "No";

		for (int j = 0; j < S.length() ; j++) {

			result1=S.substring(0, j);
			result2=S.substring(j);
			result3=(result2+result1);

			if (result3.equals(T)) {
				ans = "Yes";
				break;
			}
			result1 = "";
			result2 = "";
			result3 = "";

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

	}
}


Measured memory_bytes: 21844
#include<iostream>
#include<map>
#include<queue>
#include<string>
using namespace std;

static const int N = 3;
static const int N2 = 9;

static const int dx[4] = {-1, 0, 1, 0};
static const int dy[4] = {0, -1, 0, 1};
static const int dir[4] = {'u', 'l', 'd', 'r'};

struct Puzzle {
  int pas[N2], ss;
  string path;

  bool operator < (const Puzzle &p1) const {

    for (int i = 0; i < N2; i++) {
      if (pas[i] == p1.pas[i]) continue;
      return pas[i] > p1.pas[i];
    }
    return false;
  }
};

bool isTarget(Puzzle u) {
  for (int i = 0; i < N2; i++) {
    if (u.pas[i] != i + 1) return false;
  }
  return true;
}

string bfs(Puzzle s) {
  queue<Puzzle> Q;
  map <Puzzle, bool> V;

  Puzzle u, v;
  s.path = "";
  Q.push(s);
  V[s] = true;
  while (!Q.empty()) {
    u = Q.front();
    Q.pop();
    if (isTarget(u)) return u.path;
    int sx = u.ss / N;
    int sy = u.ss % N;
    for (int r = 0; r < 4; r++){
      int tx = sx + dx[r];
      int ty = sy + dy[r];
      if (tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
      v = u;
      swap(v.pas[u.ss], v.pas[tx * N + ty]);
      v.ss = tx * N + ty;
      if (!V[v]) {
	V[v] = true;
	v.path += dir[r];
	Q.push(v);
      }
    }
  }
  return "unsolvable";
}


int main() {
  Puzzle in;
  for (int i = 0; i < N2; i++) {
    cin >> in.pas[i];
    if (!in.pas[i]) {
      in.pas[i] = N2;
      in.ss = i;
    }
  }

  string ans = bfs(in);
  cout << ans.size() << endl;

  return 0;
}



Measured memory_bytes: 30556
#include <bits/stdc++.h>
using namespace std;
int main () {
    int K, A, B;
    cin >> K >> A >> B;
    for (int i = A; i <= B; i++) {
        if (i % K == 0) {
            puts("OK");
            return 0;
        }
    }
    puts("NG");
}

Measured memory_bytes: 3612
#include <stdio.h>
int main ()
{
	char x,y;
	int a,b;
	scanf("%c %c", &x, &y);
	{
		a = x;
        b = y; 
		if(a < b)
		{
			printf("<\n");
		}
		if(a > b)
		{
			printf(">\n");
		}
		if(a == b)
		{
			printf("=\n");
		}
	}
	return 0;
}


Measured memory_bytes: 128
N=int(input())
An=list(map(int,input().split()))
c = 0
for i in range(1, N):
    if An[i] == An[i-1]:
        c += 1
        An[i] = (max(An[i+1], An[i-1]) if i < N-1 else An[i-1]) +1
print(c)

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

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

int MOD = 1e9 + 7;
ll INF = 1e18;

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

int main(){
    int W, H, w, h; cin>>W>>H>>w>>h;
    double x, y; cin>>x>>y;
    
    double X=x, Y=y;
    if(x+w/2>W/2 && y+h/2>H/2){
        X=((x-w/2)+W/2)/2;
        Y=((y-h/2)+H/2)/2;
    }
    else if(y+h/2>=H/2){
        Y=((y-h/2)+H/2)/2;
    }
    else if(x+w/2>=W/2){
        X=((x-w/2)+W/2)/2;
    }
    cout << fixed << setprecision(10) << Y/X << endl;
}


Measured memory_bytes: 3300
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;


typedef pair<int,int> Pii;

int main(){
  long long  N,tmp;
  cin>>N;
  vector <long long int>v(N);
  vector <long long>ans(N+1);
  for (int i = 0; i < N; i++)
  {
        cin>>tmp;
        v[i]=tmp;
        if(!(i&1))ans[0]+=tmp;
        else ans[0]-=tmp;
  }

    for (int j = 1; j <= N; j++)
    {
     ans[j]=2*(v[j-1]-ans[j-1]/2);
    }
  
for(int i=0;i<N;i++){
    cout<<ans[i]<<" ";
}

    return 0;
}

Measured memory_bytes: 2816
#!/usr/bin/python3


(n, m) = map(int, input().split())

xti = {}
yti = {}
xti[0] = -1
yti[0] = -1

lvs = []
for i in range(n):
    (a, b, c) = map(int, input().split())
    yti[a] = -1
    yti[b] = -1   
    xti[c] = -1
    lvs.append((a, b, c))

lhs = []
for i in range(m):
    (d, e, f) = map(int, input().split())
    yti[d] = -1
    xti[e] = -1   
    xti[f] = -1
    lhs.append((d, e, f))

xs = sorted(xti.keys())
for (i, x) in enumerate(xs):
    xti[x] = i
    
ys = sorted(yti.keys())
for (i, y) in enumerate(ys):
    yti[y] = i

xsl = (len(xs) + 1) * 2
ysl = (len(ys) + 1) * 2

fi = [ [ 0 for x in range(xsl) ] for y in range(ysl) ]

for (a, b, c) in lvs:
    x = xti[c] * 2 + 1
    for y in range(yti[a] * 2 + 1, yti[b] * 2 + 1 + 1):
        fi[y][x] = 2

for (d, e, f) in lhs:
    y = yti[d] * 2 + 1
    for x in range(xti[e] * 2 + 1, xti[f] * 2 + 1 + 1):
        fi[y][x] = 2

(cx, cy) = (xti[0] * 2, yti[0] * 2)
q = []
q.append((cx, cy))
fi[cy][cx] = 1
s = (xs[cx // 2] - xs[(cx - 1)// 2]) * (ys[cy // 2] - ys[(cy - 1) // 2])
dxs = [0, 1, 0, -1]
dys = [1, 0, -1, 0]

while q:
    (x, y) = q.pop(-1)

    for i in range(4):
        cx = x + dxs[i] * 2
        cy = y + dys[i] * 2
    
        if fi[cy][cx] != 0:
            continue

        pcx = x + dxs[i]
        pcy = y + dys[i]
        if fi[pcy][pcx] == 2:
            continue
        
        
        if cx == 0 or cx == xsl - 2 or cy == 0 or cy == ysl - 2:
            print('INF')
            exit()

        fi[cy][cx] = 1
        s += (xs[cx // 2] - xs[(cx - 1)// 2]) * (ys[cy // 2] - ys[(cy - 1) // 2])
        q.append((cx, cy))

print(s)

#for xl in fi:
#    print(xl)




Measured memory_bytes: 636904
#include<stdio.h>
#define INFINITY 1000000000

int A[500000];
int num=0;
int n1,n2;
int L[5000000];
int R[5000000];

void merge(int A[],int left,int mid,int right){
  int i,k,j;
  n1=mid-left;
  n2=right-mid;
  for(i=0;i<n1;i++)L[i]=A[left+i];
  for(i=0;i<n2;i++)R[i]=A[mid+i];
  L[n1]=INFINITY;
  R[n2]=INFINITY;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i=i+1;
num++;
    }
   else{
     num++;
  A[k]=R[j];
  j=j+1;
    }
  }
}
void mergesort(int A[],int left,int right){
  if(left+1<right){
    int mid;
    mid = (left + right)/2;
    mergesort(A, left, mid);
    mergesort(A, mid, right);
    merge(A, left, mid, right);
  }
}
int main(){
  int n,i;
  scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&A[i]);
}
mergesort(A,0,n);
for(i=0;i<n;i++){
if(i==n-1){
printf("%d\n",(int)A[i]);
break;
}
printf("%d ",(int)A[i]);
}
printf("%d\n",num);

return 0;
}



Measured memory_bytes: 5768
#include <utility>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    const int VALUES = 10000;

    int A[VALUES], B[VALUES], C = 0;

    while (true)
    {
        cin >> A[C] >> B[C];

        if (A[C] == 0 && B[C] == 0) { goto Exit; }

        if (A[C] > B[C]) { swap(A[C], B[C]); }

        C++;
    }

    Exit:;

    for (int i = 0; i < C; i++)
    {
        cout << A[i] << ' ' << B[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 1188
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    A=LI()
    zeros = A.count(0) 
    if zeros==0 or A[0]!=0 or zeros>=4:
        print(0)
        return 
    elif zeros==1:
        ans = 3
    else:
        ans = 6
    cnt = defaultdict(int)
    cnt2 = defaultdict(int)
    for a in A:
        if a==0:
            cnt[0]+=1
            continue
        ans *= cnt[a-1]
        ans %= mod
        cnt[a-1]-=1
        cnt[a]+=1
        cnt2[a]+=1
        if cnt2[a]>3:
            ans = 0
        # print(a,ans)
    print(ans)
if __name__ == '__main__':
    main()

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

int main()
{
	int64_t x;
	cin >> x;

	for (int64_t n = (x + 105 - 1) / 105; n <= (x + 100 - 1) / 100; n++)
	{
		int64_t y = x - 100 * n;

		if (0 <= y && y <= 5 * n)
		{
			cout << 1 << endl;
			return 0;
		}
	}

	cout << 0 << 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);

    int N = Integer.parseInt(sc.next());

    int h[] = new int[N];
    for (int i = 0; i < N; i++) {
      h[i] = Integer.parseInt(sc.next());
    }

    long ans = 0;

    while (true) {
      int s = -1;
      for (int i = 0; i < N; i++) {
        if (h[i] > 0) {
          s = i;
          break;
        }
      }
      if (s < 0) {
        break;
      }

      ans++;
      for (int i = s; i < N; i++) {
        if(h[i]>0) {
          h[i]--;
        }else {
          break;
        }
      }

    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 23508
s[62][62],q[400];
main(x,y,i,j,f,g,_x,_y){
	for(;scanf("%d%d",&x,&y),x;){
		memset(s,0xff,sizeof(s));
		for(j=1;j<2*y;j++)
			for(i=1;i<2*x;i++)
				s[i][j]=0;
		for(j=1;j<2*y;j++)
			for(i=(j&1)?2:1;i<2*x;i+=2)scanf("%d",s[i]+j);
		q[0]=0x10001;s[1][1]=1;f=0;g=1;
		for(;f!=g;){
			_x=q[f]>>16,_y=q[f]&0xffff;f=(f+1)%400;
			if(s[_x][_y-1]==0&&s[_x][_y-2]==0)q[g]=((_x)<<16)|(_y-2),g=(g+1)%400,s[_x][_y-2]=s[_x][_y]+1;
			if(s[_x][_y+1]==0&&s[_x][_y+2]==0)q[g]=((_x)<<16)|(_y+2),g=(g+1)%400,s[_x][_y+2]=s[_x][_y]+1;
			if(s[_x-1][_y]==0&&s[_x-2][_y]==0)q[g]=((_x-2)<<16)|(_y),g=(g+1)%400,s[_x-2][_y]=s[_x][_y]+1;
			if(s[_x+1][_y]==0&&s[_x+2][_y]==0)q[g]=((_x+2)<<16)|(_y),g=(g+1)%400,s[_x+2][_y]=s[_x][_y]+1;
			if(s[2*x-1][2*y-1])break;
		}
		printf("%d\n",s[2*x-1][2*y-1]);
	}
	exit(0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long       ll;
typedef pair<int,int>   ii;
typedef vector<int>     vi;
typedef set<int>        si;

template<typename T> T sgn (T x)      {return x<0? -1:x!=0; }
template<typename T> T gcd (T a, T b) {return a ? gcd (b % a, a) : b; }
//pi=acos(-1)
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define clr(x,v) memset(x,v,sizeof x)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define popcount __builtin_popcount
#define eb emplace_back
#define emp emplace
#define ss second
#define ff first
#define MOD ((int)1e9+7)
#define N ((int)2e5+123)
void reads(string& x){ char kk[N]; scanf("%s",kk); x = kk;}

ll ans=1;
ll n, m=1e18, v[N], zero;

void solve(){
    scanf("%lld", &n);
    forn(i,0,n){
        scanf("%lld", v+i);
        if(v[i]==0)zero=1;
    }
    sort(v,v+n);
    if(zero){
        printf("0\n");
        return;
    }
    forn(i,0,n){
        if(v[i]>m/ans){
            ans=-1;
            break;
        }
        else ans*=v[i];
        if(ans>1e18)ans=-1;
    }
    
    printf("%lld\n",ans);
}

int main(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;//canf("%d",&t);
    while(t--)solve();
}

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

using namespace std;


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

 int a,b,c,d;
  cin >> a >> b >> c >> d;
 
 if(d==1) cout << 1 << endl;
 else cout << 0 << endl;
}

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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    ll n, m; cin >> n >> m;

    if (n == 1 && m == 1) {
        cout << 1 << endl;
        return 0;
    }

    if (n == 1 && m > 1) {
        cout << m - 2 << endl;
        return 0;
    }

    if (m == 1 && n > 1) {
        cout << n - 2 << endl;
        return 0;
    }

    cout << (n - 2) * (m - 2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N, ans=1;
  cin >> N;
  
  vector<int> P(N);
  for(int i=0; i<N; i++)
    cin >> P.at(i);
  
  if(N==1) cout << 1 << endl;
  else{
  int min = P.at(0);
  for(int i=1; i<N; i++){
    if(P.at(i) < min){
      min = P.at(i);
      ans++;
    }
  }
  cout << ans << endl;
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

const int mod=1000000007;
int n,w,K;
ll dp[101][10];
int main(){
    cin>>n>>w>>K;
    dp[0][0]=1;
    rep(i,n){
        rep(j,w){
            rep(k,1<<(w-1)){
                bool flag=true;
                rep(l,w-2){
                    if((k>>l&1)&&(k>>(l+1)&1)){
                        flag=false;
                        break;
                    }
                }
                if(!flag) continue;
                if(k>>j&1){
                    dp[i+1][j+1]+=dp[i][j];
                    dp[i+1][j+1]%=mod;
                }
                else if(j>0&&(k>>(j-1)&1)){
                    dp[i+1][j-1]+=dp[i][j];
                    dp[i+1][j-1]%=mod;
                }
                else{
                    dp[i+1][j]+=dp[i][j];
                    dp[i+1][j]%=mod;
                }
            }
        }
    }
    cout<<dp[n][K-1]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector <int> xxx;
vector <int> yyy;
int x,y,pozstart=0;

bool solve(int poz, vector <int> vec){
    set <int> wsp;
    wsp.insert(0);
    for(int i=0;i<vec.size();i++){
      set<int>nowy;
            for(auto it:wsp){
                nowy.insert(it + vec[i]);
                nowy.insert(it - vec[i]);
            }
      wsp=nowy;
    }
    if(wsp.count(poz)==0)return false;
    else return true;

}
int main()
{
    string a;
    cin >>a >> x >> y;
    for(int i=0;i<a.size();i++){
        if(a[i]=='F')pozstart++;
        else break;
    }
    a+='T';
    bool wgr = false;
    int k=0;

    for(int i=pozstart+1;i<a.size();i++){
        if(a[i]=='T'){
             if(k>0){
                if(wgr) xxx.push_back(k);
                else yyy.push_back(k);}
             wgr=!wgr;
             k=0;}
        else k++;
    }
    //for(int i=0;i<xxx.size();i++){
    //    cout << "XXX zawiera: " << xxx[i] << "\n";
    //}
    //for(int i=0;i<yyy.size();i++){
    //    cout << "YYY zawiera: " << yyy[i] << "\n";
    //}
    x-=pozstart;
    //cout << "x to: " << x << "\n";

    bool czy=true;
    czy = solve(x,xxx);
    if(!czy){cout << "No";
    return 0;}
    czy = solve(y,yyy);
    if(!czy){cout << "No";
    return 0;}
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 640
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var intArr = cin.ReadLine.Split(' ');
            var age = int.Parse(intArr[0]);
            var value = int.Parse(intArr[1]);
            if (age < 6)
            {
                value = 0;
            }else if (age < 13)
            {
                value = value / 2;
            }
            WriteLine(value);
        }

    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 11220
#include <cmath>
#include <iostream>
using namespace std;
int main() {
    string s; cin >> s;
    int a = 0, b = 0, c = 0;
    for (char x : s) { if (x == 'a') a++; else if (x == 'b') b++; else c++; }
    cout << (abs(a-b) <= 1 && abs(b-c) <= 1 && abs(c-a) <= 1 ? "YES\n" : "NO\n");
}


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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int main(){

  string s;cin>>s;
  int ans=0;
  rep(i,0,s.size()){
    if(i<s.size()-1-i){
    if(s[i]!=s[s.size()-1-i])ans++;
    }else break;
  }

  out(ans);



  return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
#define fastio ios_base::sync_with_stdio(false)
#define ll long long int
#define ld long double
#define ict int t; cin >> t
#define lct ll t; cin >> t;
#define in(a) int a; cin >> a
#define ln(a) ll a; cin >> a
#define loop(i,n) for (ll i = 0; i < n; ++i) 
#define looprev(i,n) for (ll i=n-1; i>=0 ; --i)
#define LOOP(i,k,n) for (ll i = k; i <= n; ++i) 
#define LOOPREV(i,k,n) for (ll i = k; i >= n; --i) 
#define mp make_pair 
#define pa pair <ll,ll>
#define vec vector<ll>
#define vecpa vector<pa>
#define vec2D vector <ll<ll>>
#define que queue<ll>
#define deq deque<ll> 
#define stk stack<ll>
#define iterate vector<ll>::iterator
#define pub push_back
#define pob pop_back
#define pof pop_front
#define puf push_front
#define emp emplace_back

using namespace std;

int main()
{
    fastio;
    cin.tie(NULL);
    cout.tie(NULL);
  	ln(n);
  	ln(d);
  	vector<pa> v;
  	loop(i,n){
      ll x, y;
      cin >> x>>y;
      v.pub(mp(x,y));
    }
  ll count =0;
  loop(i,n){
  	if(pow(abs(v[i].first),2)+ pow(abs(v[i].second),2) <= pow(abs(d),2)) count++;
  }
  cout << count;
}

Measured memory_bytes: 7400
#include<bits/stdc++.h>
// #define int long long
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;

signed main() {
    int n;
    cin >> n;
    vi a(100000);
    rep(i, n){
        int tmp;
        cin >> tmp;
        a[tmp]++;
        a[tmp+1]++;
        if(tmp > 0)a[tmp-1]++;
    }

    int ans = 1;
    for(int i = 0; i <= 100000; i++){
        ans = max(ans, a[i]);
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3788
#include<stdio.h>
#define SIZE10 100000

typedef long long int ll;
typedef unsigned char u8;

int main(void){
    int A[100];
    int B[100];
    int C[100];
    int N = 0;
    int i = 0;
    int j = 0;
    int sum = 0;

    scanf("%d", &N);

    for(i = 0; i < N; i++){
        scanf("%d", &A[i]);
    }
    for(i = 0; i < N; i++){
        scanf("%d", &B[i]);
    }
    for(i = 0; i < N-1; i++){
        scanf("%d", &C[i]);
    }

    sum = B[A[0]-1];

    for(i = 1; i < N; i++){
        if(A[i] - A[i-1] == 1){
            sum += C[A[i]-2]+B[A[i]-1];
        }else{
            sum += B[A[i]-1];
        }
    }

    printf("%d", sum);

    return 0;
}

Measured memory_bytes: 128
from operator import mul
from functools import reduce

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i == 0:
            cnt = 0
            while temp%i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
    if temp != 1:
        arr.append([temp, 1])
    if arr == []:
        arr.append([n, 1])
    return arr

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under 
    
n,m = map(int,input().split())

f = factorization(m)
c = 1

for i in range(len(f)):
  c *= cmb(n+f[i][1]-1,f[i][1])%1000000007

if m != 1:
  print(c%1000000007)
else:
  print(1)








Measured memory_bytes: 38512