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

using namespace std;

typedef short sho;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef string str; 
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll; 
typedef pair<ld,ld> pld;
 
typedef vector<int> vi; 
typedef vector<ll> vl; 
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<pld> vpd;

#define STDIO
#define mp make_pair 
#define FF first
#define SS second
#define sz(x) (int)x.size()
#define begin(x) (x).begin() 
#define end(x) (x).end()
#define rbegin(x) (x).rbegin()
#define rend(x) (x).rend()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front 
#define pb push_back
#define pp push
#define lb lower_bound 
#define ub upper_bound

inline void checkmin(int &x, int y){x = min(x, y);}
inline void checkmax(int &x, int y){x = max(x, y);}
inline void sortsm(int &x, int &y) {int a = min(x, y), b = max(x, y); checkmin(x, a); checkmax(y, b);}
inline void sortbi(int &x, int &y) {sortsm(x, y); swap(x, y);}

const int maxn=1e5+10;

int n,m;
vi G[maxn];
vi topo;
bool vis[maxn];
int dp[maxn];

void tpsort(int x)
{
	vis[x]=true;
	for(auto to : G[x])
	{
		if(!vis[to])
		{
			tpsort(to);
		}
	}
	topo.pb(x);
}

int main() 
{
	#ifndef STDIO
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /* start code */
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
    	int a,b;
    	cin>>a>>b;
    	G[a].pb(b);
	}
	for(int i=1;i<=n;i++)
	{
		if(!vis[i])
		{
			tpsort(i);
		}
	}
	reverse(all(topo));
	for(auto now : topo)
	{
		for(auto to : G[now])
		{
			checkmax(dp[to],dp[now]+1);
		}
	}
	cout<<*max_element(dp+1,dp+1+n)<<endl;
    /* end code */
	return 0;
}

Measured memory_bytes: 8824
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1e18;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

int r;

int main() {
    cin >> r;
    cout << 3 * r * r << endl;
}


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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define int long long
#define itn int
#define pb push_back
#define m_p make_pair
#define m_t meke_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a));reverse(all(a))
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define debg(a) cout<<#a<<" "<<a<<endl;
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define out(a) cout<<(a)<<endl
#define fi first
#define se second
#define Vec vector
#define P pair
typedef long long ll;
typedef string str;
typedef vector<ll> V;
typedef pair<ll,ll> Pi;
typedef vector<Pi> VP;
const long long INF = 1LL<<60;
const long long MOD = 1e9+7;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int max(int a,int b){if(a>b)return a; return b;}
int min(int a,int b){if(a>b)return b; return a;}
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
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;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n,k;
  str s;
  cin>>n>>s>>k;
  char t=s[k-1];
  str a=s;
  rep(i,n){
    if(a[i]!=t)a[i]='*';
  }
  out(a);
  
  
  
  return 0;
}



Measured memory_bytes: 256
//chiragjn
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define gibe_de_fast_io_b0ss ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
const ll mod = 1e9 + 7;
const ll INF = 0x7FFFFFFFFFFFFFFF/2;
long long cache[101][100001] = {{0}};
int main(){
    gibe_de_fast_io_b0ss;
    int n, w;
    cin>>n>>w;
    ll wi, vi;
    for(int i = 1; i <= n; i++) {
    	cin>>wi>>vi;
    	for(int j = 0; j < wi; j++) {
    		cache[i][j] = cache[i - 1][j];
    	}
    	for(int j = wi; j <= w; j++) {
    		cache[i][j] = max(cache[i][j], max(cache[i - 1][j], vi + cache[i - 1][j - wi]));
    	}
    }
    cout<<cache[n][w];
    return 0;
}


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

using namespace std;

long long int w[150];
long long int v[150];
long long int dp[100050];

int main() {                   
	long long int n, W, ans = 0;
	cin >> n >> W;
	long long int v, w;
	cin >> w >> v;
	dp[w] = v;
	ans = v;
	for (long long int i = 1; i < n; i++) {
		cin >> w >> v;
		for (long long int j = W; j >= w; j--) {
			if (dp[j - w] || !(j - w))
				dp[j] = max(dp[j], v + dp[j - w]);
			ans = max(ans, dp[j]);
		}
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <queue>
#include <set>
using namespace std;
using ll = long long;
using Lf = long double;
using plong = pair<ll,ll>;
const int mod = 1000000007;
ll dp[51][51][3010];
int main(){
    ll N,A;
    cin>>N>>A;
    vector<ll> x(N);
    for(ll i=0;i<N;i++)cin>>x[i];
    dp[0][0][0]=1;
    for(ll i=0;i<N;i++){
        for(ll j=0;j<N;j++){
            for(ll k=0;k<2500;k++){
                if(dp[i][j][k]){
                    dp[i+1][j][k] += dp[i][j][k];
                    dp[i+1][j+1][k+x[i]] += dp[i][j][k];
                }
            }
        }
    }
        ll ans = 0;
        for(ll i=1;i<N+1;i++){
            ans+=dp[N][i][i*A];
        }
        cout<<ans<<endl;

}

Measured memory_bytes: 58240
from math import factorial
N, M = map(int, input().split())

if abs(N - M) > 1:
    print(0)
elif abs(N - M) == 1:
    print((factorial(N) * factorial(M)) % (10**9 + 7))
else:
    print((2 * factorial(N) * factorial(M)) % (10**9 + 7))

Measured memory_bytes: 5192
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        Random random = new Random();
        int n = sc.nextInt();
        long k = sc.nextLong();
        
        int[] to = new int[n];
        for (int i = 0; i < n; i++) {
            to[i] = sc.nextInt()-1;
        }
        
        // ans:
        // array = {2,4,<16,256,471,620>}について、
        // 「i=0からスタートし、">"まで来たら"<"に戻る」ルールで、
        // 操作「i = to[i]」をk回したときのi
        
        // array:
        // ex. to = {6,5,2,5,3,2} (1-indexed)
        // array = {1,6,<2,5,3>}
        
        // how: ρの形で考えて3パターンでそれぞれ集計する。
        
        Set<Integer> set = new HashSet<Integer>();
        List<Integer> list = new ArrayList<Integer>();
        int now = 0;
        set.add(now);
        list.add(now);
        int last = 0;
        for (long i = 0; i < k; i++) {
            now = to[now];
            if (set.contains(now)) {
                last = now;
                break;
            } else {
                set.add(now);
                list.add(now);
            }
        }
        // System.out.println(list.toString());
        
        int loop_idx = 0;
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i) == last) {
                loop_idx = i;
            }
        }
        
        int ans = 0;
        
        // [start, loop始点)
        for (int i = 0; i < loop_idx; i++) {
            ans = to[ans];
        }
        k -= loop_idx;
        
        // [loop始点, loop終点] * 何周できるか
        long len = list.size() - loop_idx;
        k %= len;
        
        // [loop始点, 残りの移動回数]
        for (int i = loop_idx; i < loop_idx + k; i++) {
            ans = to[ans];
        }
        
        System.out.println(ans+1);
    }
}

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

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
#define all(x) x.begin(), x.end()
#define rep(i,a,b) for(int i = a; i < b; i++)

int N;
vvi children(100002);
vvi jumps(100002, vi(18, -1));

vi trail(0);
void gen_jumps(int n, int l) {
  trail.push_back(n);
  rep(i,0,18) {
    int dest = (l&(l^(1<<i)))|((1<<i)-1);
    if(dest <= l)
      jumps[n][i] = trail[dest];
  }
  rep(i,0,(int)children[n].size())
    gen_jumps(children[n][i], l+1);
  trail.pop_back();
}

int lca(int u, int v) {
  int lowest = 0;
  for(int i = 17; i >= 0; i--) {
    if(jumps[u][i] == -1 && jumps[v][i] == -1) continue;
    else if(jumps[u][i] == -1) v = jumps[v][i];
    else if(jumps[v][i] == -1) u = jumps[u][i];
    else if(jumps[u][i] == jumps[v][i]) {
      if(jumps[u][i] == u || jumps[v][i] == v) return jumps[u][i];
      lowest = jumps[u][i];
    }
    else {
      u = jumps[u][i];
      v = jumps[v][i];
    }
  }
  return lowest;
}

int main() {
  cin >> N;
  rep(n,0,N) {
    int K, c;
    cin >> K;
    rep(k,0,K) {
      cin >> c;
      children[n].push_back(c);
    }
  }

  gen_jumps(0, 0);
  
  int Q;
  cin >> Q;
  rep(q,0,Q) {
    int u, v;
    cin >> u;
    cin >> v;
    cout << lca(u, v) << '\n';
  }
}



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

int main(){

  int N,M;
  cin >> N >> M;
  vector<int> broken(N+1);

  for(int i = 0;i < M;i++){
    int a;
    cin >> a;
    broken[a] = 1;
  }
  vector<int> dp(N+2);//dp[n+1]は0で初期化
  const int mod = 1000000007;
  dp[N] = 1;
  for(int i = N - 1;i >= 0;i--){
    if(broken[i]){
      dp[i] = 0;
      continue;
    }
    dp[i] = (dp[i + 1] + dp[i + 2]) % mod;//後から決めることと前から決めることは同じ.(後から決めると,dp[1]やdp[2]を壊れている床かどうかを考慮して決めなくてよく,添字の都合上dp(N+2)のようにかけて便利だから.)


  }

  cout << dp[0] << endl;

  return 0;


}


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

int main(){
 std::string str;
 int a ,b;
 cin >> a >> b;
 if(a>b){
    str = std::to_string(b);
    for (int i= 0;i<a;i++){
       cout << b; 
    }
    }else if(a<b){
       str = std::to_string(a);
       for (int i= 0;i<b;i++){
          cout << a;
       }
    }else{
       for(int i= 0;i<a;i++){
          cout << b;
       }
    }

}

Measured memory_bytes: 256
n,k,c=map(int,input().split())
s=input()
#働く日のうちi日目についてそれ以後でないと働けない日をL[i]とする配列を考える
#働く日のうちi日目についてそれ以前でないと働けない日をR[i]とする配列も考える
#その二つが同じとき、必ず働かなければいけない日になる
#L[i]があった時、L[i]+c+1以降からしか働けないことに注意(vice versa)

#バグ？なんで？
l=[-1]*k
r=[-1]*k
nowl=0
indl=0
while nowl<n and indl<k:
    for i in range(nowl,n):
        if s[i]=="o":
            l[indl]=i
            nowl=i+c+1
            indl+=1
            break
nowr=n-1
indr=k-1
while nowr>=0 and indr>=0:
    for i in range(nowr,-1,-1):
        if s[i]=="o":
            r[indr]=i
            nowr=i-c-1
            indr-=1
            break
for i in range(k):
    if l[i]==r[i]:
        print(l[i]+1)

Measured memory_bytes: 20608
import queue
import numpy as np

H, W = map(int, input().split())
maze = [list(input()) for _ in range(H)]
dir4 = [[-1,0],[1,0],[0,-1],[0,1]]


def solveMaze(s):
    q = queue.Queue()
    q.put([s[0],s[1],0])
    times = [[999999999 for j in range(W)] for i in range(H)]
    tmpAns = 0
    times[s[0]][s[1]] = 0
    while not q.empty():
        now = q.get()
        tmpAns = max(tmpAns, now[2])
        for i in range(4):
            nextH = now[0] + int(dir4[i][0])
            nextW = now[1] + int(dir4[i][1])
            nextTime = now[2] + 1

            if nextH < 0 or nextH >= H or nextW < 0 or nextW >=W or maze[nextH][nextW] == "#" or times[nextH][nextW] <= nextTime:
                continue
            else:
                times[nextH][nextW] = nextTime
                q.put([nextH, nextW, nextTime])

    return tmpAns


ans = 0

for sH in range(H):
    for sW in range(W):
        if maze[sH][sW] == ".":
            ans = max(ans, solveMaze([sH, sW]))

print(ans)







Measured memory_bytes: 27100
#pragma GCC optimize("Ofast")
#include <cstring>
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long ll;

int main() {
    ll K, A, B, ans;
    int i, flag=0;

    cin >> K >> A >> B;

    for(i=A; i<=B; i++) {
        ans = i%K;
        if(ans==0) {
            flag = 1;
            break;
        }
    }

    if(flag == 1) {
        cout << "OK";
    } else {
        cout << "NG";
    }

}

Measured memory_bytes: 3596
def resolve():
    from collections import deque
    n = int(input())
    a = list(map(int, input().split()))
    a = sorted(a)[::-1]
    nxt = deque([a[0]])
    ans = 0
    for i in range(1,n):
        b = nxt.popleft()
        ans += b
        nxt.append(a[i])
        nxt.append(a[i])

    print(ans)
resolve()

Measured memory_bytes: 106788
import java.util.*;

public class Main {
    public static void main(String[] args) {
        try (final Scanner sc = new Scanner(System.in)) {
            final double value = sc.nextDouble();
            if (value % 2 == 0) {
                System.out.println(0.5000000000);
                return;
            }
            System.out.println((((value - 1) / 2) + 1) / value);
            return;
        }
    }
}

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

int main()
{
	string temp;
	int t1=0,t2=0,t3=0;
	long long ans=0;
	int flag=0;
	string s;
	int n;
	cin>>temp;
	cin>>s;
	for(int i=0;i<temp.size();i++)
	{
		if(temp[i]>='0'&&temp[i]<='9');
		else
		{
			flag=1;break;
		}
	}
	
	if(flag==0)
	{
		for(int i=0;i<temp.size();i++)
		n=n*10+int(temp[i]-48);
		if(n<4)
		{
			cout<<0<<endl;
		}else if(s.find('R')==string::npos||s.find('G')==string::npos||s.find('B')==string::npos)
		{
			cout<<0<<endl;
		}else
		{
			for(int i=0;i<n;i++)
			{
				if(s[i]=='R')ans+=(t2*t3),t1++;
				if(s[i]=='G')ans+=(t1*t3),t2++;
				if(s[i]=='B')ans+=(t1*t2),t3++;
			}
			for(int i=0;i<n;i++)
			{
				for(int j=i;j<n;j+=2)
				{
					if(s[i]!=s[j]&&s[i]!=s[(i+j)/2]&&s[j]!=s[(i+j)/2])ans--;
				}
			}
			cout<<ans<<endl;
		}
	
		
	}else
	cout<<"Print the number of triplets in question."<<endl;
	
	
	
	
return 0;
 } 

Measured memory_bytes: 3636
#include<iostream>
#include<string.h>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;

typedef complex<double> P;

struct L : public vector<P>{//??´???
  L(const P &a, const P &b){
    push_back(a);push_back(b);
  }
};

struct C{//???
  P c; double r;
  C(const P &c,double r): c(c),r(r){}
};

namespace std{//??????????????????
  bool operator < (const P& a,const P& b){
    return real(a)!= real(b) ? real(a) < real(b) : imag(a) < imag(b);
    //return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b)
  }
  bool operator == (const P& a,const P& b){
    return a.real()==b.real()&&a.imag()==b.imag();
  }
}

double dot(P a,P b){
  return real(conj(a)*b);
}

double cross(P a,P b){
  return imag(conj(a)*b);
}

int ccw(P a, P b, P c){
  b-=a;c-=a;
  if(cross(b,c)>0)   return +1;// counter clockwise 
  if(cross(b,c)<0)   return -1;// clockwise 
  if(dot(b,c)<0)     return +2;// c-a-b on line
  if(norm(b)<norm(c))return -2;// a-b-c on line
  return 0;                    // a-c-b on lone
}

P intersection(P a,P b,P c,P d){//2??´????????????
  return a+(b-a)*(cross(d-c,c-a)/cross(d-c,b-a));
}

int across(P p1,P p2,P p3,P p4){
    P s1(p2-p1);
    P s2(p4-p3);
    if(s1.real()*s2.imag()==s1.imag()*s2.real())return 2;//parallel
    if(dot(s1,s2)==0)return 1;//Orthogonal
    return 0;//others
}


int main()
{
  int i;
  int q;

  cin>>q;

  rep(i,q){
    double xp,yp;

    cin>>xp>>yp;  P p1(xp,yp);
    cin>>xp>>yp;  P p2(xp,yp);
    cin>>xp>>yp;  P p3(xp,yp);
    cin>>xp>>yp;  P p4(xp,yp);

    P s1(p2-p1);
    P s2(p4-p3);

    if(p1==p3 || p1==p4 || p2==p3 || p2==p4){
      cout<<"1"<<endl;
      continue;
    }

    if(s1.real()*s2.imag()==s1.imag()*s2.real()){//parallel
      if(ccw(p1,p3,p4)==2||ccw(p2,p3,p4)==2 || ccw(p3,p1,p2)==2||ccw(p4,p1,p2)==2)
	  cout<<"1"<<endl;
	else
	  cout<<"0"<<endl;

    }else{
      P p=intersection(p1,p2,p3,p4);//??????
      // cout<<p<<endl;
      if(abs(p1-p)>abs(p1-p2) || abs(p2-p)>abs(p1-p2) ||
	 abs(p3-p)>abs(p3-p4) || abs(p4-p)>abs(p3-p4))
	cout<<"0"<<endl;
      else
	cout<<"1"<<endl;
    }
  }

}

Measured memory_bytes: 3244
#include<bits/stdc++.h>
 
using namespace std;
typedef long long int ll;
bool comp(ll a, ll b)
{
   return a>b;
}
int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin>>s;
    for(ll i=0; i<s.length();i++)
        cout<<"x";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#include <string.h>

 

int x;

char y[101];

 

int main(){

	scanf("%d",&x);	scanf("%s",&y);

	int len = strlen(y);

	if(len<=x){

		printf("%s\n",y);

		return 0;

	}

	else{

		for(int i=x; i<len; i++){

			y[i]='\0';

		}

		for(int i=x; i<x+3; i++){

			y[i]='.';

		}

		printf("%s\n",y);

		return 0;

	}

}

Measured memory_bytes: 1608
#include<iostream>
#include<cmath>

using namespace std;

double topos(int in,int num){
  if(num) return in * 6;
  return in*30;
}

void solve(double h, double m){
  double judge =fabs(h-m);
  if(judge > 180) judge = 360 - judge;
  // cout << judge << endl;
  if(judge < 30) cout << "alert" << endl;
  else if(judge < 90) cout << "warning" << endl;
  else cout << "safe" << endl;
}

int main(){
  int in;
  cin >> in;
  for(int i = 0; i < in; i++){
    int hour,minite;
    char trash;
    cin >> hour >> trash >> minite;
    //cout << hour << " " << trash << " " << minite<<endl;
    double pos = topos(minite,1);
    double posh = topos(hour,0);
    posh += (double)minite/2;
    solve(posh,pos);
  }
  return 0;
}

Measured memory_bytes: 0
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 d = sc.nextInt();

    while (true) {
      if (c - b <= 0) {
        System.out.println("Yes");
        return;
      }
      if (a - d <= 0) {
        System.out.println("No");
        return;
      }
      c = c - b;
      a = a - d;
    }
  }
}


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


int main()
{
	int n, m;
	cin >> n >> m;

	vector<int> lights(m, 0);
	vector<int> pVec(m);
	{
		int num = 0;
		int temp = 0;
		for (int i = 0; i < m; ++i) {
			cin >> num;
			for (int j = 0; j < num; ++j) {
				cin >> temp;
				lights[i] += 1 << (temp - 1);
			}
		}

		for (int i = 0; i < m; ++i) {
			cin >> pVec[i];
		}
	}

	vector<int> checker(n);
	for (int i = 0; i < n; ++i) {
		checker[i] = 1 << i;
	}

	int ret = 0;
	int countMax = 1 << n;
	int count = 0;
	while (count < countMax) {
		bool isOk = true;
		for (int i = 0; i < m; ++i) {
			int result = count & lights[i];
			int onCount = 0;
			for (int j = 0; j < n; ++j) {
				if (checker[j] & result) {
					++onCount;
				}
			}
			if((onCount % 2) != pVec[i]){
				isOk = false;
				break;
			}
		}

		if (isOk) {
			++ret;
		}

		++count;
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return list(sys.stdin.readline())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007

#A
"""
a = IR(2)
b = IR(2)
print(min(a)+min(b))
"""

#B
"""
n = I()
d, x = LI()
a = IR(n)
ans = x
for i in a:
    k = 0
    while k * i + 1 <= d:
        ans += 1
        k += 1
print(ans)
"""

#C
n = I()
a = LI()
a.insert(0, 0)
a.append(0)
ans = 0
for i in range(1, n + 2):
    ans += abs(a[i] - a[i - 1])
#print(ans)
for k in range(1, n + 1):
    if a[k - 1] < a[k]:
        if a[k] > a[k + 1]:
            print(ans - 2 * min(abs(a[k] - a[k - 1]), abs(a[k] - a[k + 1])))
        else:
            print(ans)
    if a[k - 1] > a[k]:
        if a[k] < a[k + 1]:
            print(ans - 2 * min(abs(a[k] - a[k - 1]), abs(a[k] - a[k + 1])))
        else:
            print(ans)
    if a[k - 1] == a[k]:
        print(ans)

Measured memory_bytes: 13796
import sys
input = sys.stdin.readline


def main(a, b):
    res = [0]*3
    res[0] = a + b
    res[1] = a - b
    res[2] = a * b

    return max(res)


if __name__ == "__main__":
    a, b = map(int, input().split())
    print(main(a, b))


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
    int N;
    cin >> N;
    int odd_counter         = 0;
    int even_counter        = 0;
    int double_even_counter = 0;

    for(int i = 0; i < N; i++ ) {
        int A;
        cin >> A;
        if( A % 2 != 0) {
            odd_counter++;
            continue;
        }
        if( A % 4 != 0) {
            even_counter++;
            continue;
        }
        double_even_counter++;
    }

    if(double_even_counter < odd_counter - 1 ) {
        cout << "No" << endl;
        return 0;
    }
    if(double_even_counter > odd_counter - 1 ) {
        cout << "Yes" << endl;
        return 0;
    }

    // double_even_counter == odd_counter - 1  の場合
    if( even_counter > 0 ) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}

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

int main()
{
  int n,i;
  multiset< int,greater<int> > s;
  multiset<int>::iterator it;

  for(i=0;i<10;i++){
    cin>>n;
    s.insert(n);
  }
  n=0;
  it=s.begin();
  for(i=0;i<3;i++) n+=*it++;
  cout<<n<<" ";

  s.clear();
  for(i=0;i<10;i++){
    cin>>n;
    s.insert(n);
  }
  n=0;
  it=s.begin();
  for(i=0;i<3;i++) n+=*it++;
  cout<<n<<endl;
}

Measured memory_bytes: 0
#!/usr/bin/env python

def main():
    nx_list = []
    while True:
        n, x = map(int, input().split())
        if n == 0 == x:
            break
        else:
            nx_list.append((n, x))

    for nx in nx_list:
        n, x = nx
        cnt = 0

        for i in range(1, n-1):
            for j in range(i+1, n):
                k = x - i - j
                if j < k <= n:
                    cnt += 1
                elif k <= j:
                    break
        print(cnt)

if __name__ == '__main__':
    main()



Measured memory_bytes: 5600
#include <iostream>
#include <cstring>
#define REP(i,n) for(int i = 0;i < n ;i++)
#define FOR(i,m,n) for(int i= m ;i<n;i++)
using namespace std;

int main(void){
  int i=0;
  int k[10001]={0};
  int count=0;
int o=1;
  for(i=0;o!=0;i++){
    cin >> k[i];
    o=k[i];
    count++;
  }

  for(i=0;i<count-1;i++){
cout << "Case " << i+1 << ':' << ' ' << k[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
int main()
{
   
    string s;
    cin>>s;
    if(s[0] =='S'&&s[1]=='S'&&s[2]=='S')cout<<"0\n";
   else if(s[0] =='S'&&s[1]=='R'&&s[2]=='S')
    cout<<"1\n";
    else if(s[0] =='R'&&s[1]=='R'&&s[2]=='S')
    cout<<"2\n";
    else if(s[0] =='S'&&s[1]=='R'&&s[2]=='R')
    cout<<"2\n";
    else if(s[0] =='R'&&s[1]=='S'&&s[2]=='R')
    cout<<"1\n";
    else if(s[0] =='S'&&s[1]=='S'&&s[2]=='R')
    cout<<"1\n";
    else if(s[0] =='R'&&s[1]=='S'&&s[2]=='S')
    cout<<"1\n";
    else
    cout<<"3\n";
   
    return 0;
    } 

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <unordered_map>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

struct edge {
  int from;
  int to;
};

// I want "to -> from"
// vector<int> from_of_to(

vector<int> from_of_to[223456];
vector<uint64_t> scores(223456, 0);
vector<uint64_t> memo(223456, 0); // This is the score of vertex i.

// void calculate(int i) {
//   if (memo[i] >= 0) { return; } // memo[i] is already calculated.
//
//   memo[i] = 0;
//   for (auto e : from_of_to[i]) {
//     if (memo[e] < 0) { // memo[e] is not calculated.
//       calculate(e);
//     }
//     // Now, memo[e] is calculated
//     memo[i] += memo[e];
//   }
//   memo[i] += scores[i];
// }

int main(int argc, char** argv) {
  int N, Q;
  cin >> N >> Q;
  // vector<edge> edges(N);
  rep(i, N - 1) {
    edge e;
    cin >> e.from >> e.to;
    e.from--;  // For index
    e.to--;    // For index
    // edges.push_back(e);

    from_of_to[e.to].push_back(e.from);
    // // For Debug
    // cout << e.from << ", " << e.to << endl;
  }

  rep(i, Q) {
    int p, x;
    cin >> p >> x;
    p--;  // For index
    scores[p] += x;
  }

  // For Debug
  // rep(i, N) {
  //   cout << "scores[" << i << "]: " << scores[i] << endl;
  // }

  rep(i, N) {
    for (auto e : from_of_to[i]) { // e is smaller than i. so it is alreday calculated.
      memo[i] += memo[e];
    }
    memo[i] += scores[i];
  }

  rep(i, N) {
    cout << memo[i];
    if (i != (N-1)) {
      cout << " ";
    }
  }
  cout << endl;
}


Measured memory_bytes: 17408
raws, columns = map(int, input().strip().split())
a = []
for i in range(raws):
    a.append(list(map(int, input().strip().split())))
for i in range(raws):
    a[i].append(sum(a[i]))
a.append([sum(i) for i in zip(*a)])
for r in a:
    print(' '.join(str(x) for x in r))

Measured memory_bytes: 6728
h, w, n = map(int, input().split())
sr, sc = map(int, input().split())
S = list(input())
T = list(input())
u, d, l, r = 1, h, 1, w
while S:
  aoki = T.pop()
  if aoki == "U":
    if d<h: d += 1
  elif aoki == "D":
    if u>1: u -= 1
  elif aoki == "L":
    if r<w: r += 1
  else:
    if l>1: l -= 1
  takahashi = S.pop()
  if takahashi == "U":
    if u==d:
      print("NO")
      exit()
    u += 1
  elif takahashi == "D":
    if u==d:
      print("NO")
      exit()
    d -= 1
  elif takahashi == "L":
    if l==r:
      print("NO")
      exit()
    l += 1
  else:
    if l==r:
      print("NO")
      exit()
    r -= 1
if u<=sr<=d and l<=sc<=r:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 6704
#include <iostream>
#include <string>

using namespace std;

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

	int cnt = 0;

	for (int i = 0; i < n; ++i) {
		string si; cin >> si;
		int len = si.length();
		for (int j = 0; j < len; ++j) {
			int f = 0;
			for (int k = 1; k < len; ++k) {
				string s = "";
				for (int l = j; l < len; l += k) {
					s += si[l];
					if (s == S) {
						f = 1;
						cnt++;
					}
					if (f) break;
					if (s.length() >= len) break;
				}
				if (f) break;
			}
			if (f) break;
		}
	}

	cout << cnt << endl;
}

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

int main() {
    int n;
    int m;
 
   cin >> n >> m;
   
   int a = n + m;
   int b = n - m;
   int c = n*m;
   
   cout << max({a,b,c}) << endl;
   
   
  
  return 0;
}

Measured memory_bytes: 256
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
# T < S

cnt = 0
for i in T:
    for j in S:
        if i == j:
            cnt += 1
            break

print(cnt)
# LinearSearch: 線形探索
# 線形探索は、配列の先頭から各要素が目的の値と等しいかどうかを順番に調べる。
# 等しいものが見つかった時点でその位置を返し探索を終了する。



Measured memory_bytes: 6312
#include <bits/stdc++.h>
using namespace std;
#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
const static long long int MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

int main(int argc, char *argv[]) {
    //cin.tie(0);
    //ios::sync_with_stdio(false);

    int a, b, k;
    scanf("%d %d %d", &a, &b, &k);
    for (int i = a; i <= min(b, a + k - 1); ++i) {
        cout << i << endl;
    }

    for (int i = max(b - k + 1, a + k); i <= b; ++i) {
        cout << i << endl;
    }

    return 0;
}


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

/* REPmacro */
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define REPR(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define FOR(i,m,n) for(int i=(int)(m);i<(int)(n);++i)

/*alias*/
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair 

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

/*using*/
using ll = long long;
using ull = unsigned long long;
using unsi = unsigned;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using db = double;
using plex = complex<double>;
using vs = vector<string>;

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

/* func */

/*struct*/
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const db EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

//#define int ll
//#define int long long

int findAndreturnAns(string s, int i){

  int first{};
  int last{};

  for(int k = i; k < s.size(); ++k){

     if(s[k] == 'A' || s[k] == 'T' || s[k] == 'G' || s[k] == 'C'){
       first = k;
       break;
     }
  }
  
  for(int k = first; k < s.size(); ++k){

    if(s[k] != 'A' && s[k] != 'T' && s[k] != 'G' && s[k] != 'C'){
      last = k;
      break;
    }
    
    if(k == s.size()-1)
      last = k+1;
  }
  
  return (last)-(first);
}

signed main()
{
  string s{}; cin >> s;
  
  vector<int> v1(s.size());
  
  for(int i = 0; i < s.size(); ++i)
     v1.EB(findAndreturnAns(s,i));
  
  cout << *max_element(ALL(v1));
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define I int
#define S(a) scanf("%d",&a)
#define S2(a,b) scanf("%d%d",&a,&b)
#define P(a) printf("%d\n",a)
#define PL(a) printf("%lld\n",a)
#define PT(t) printf("Case %d: ",t)
#define PB(a) push_back(a)
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define ll long long 
using namespace std;
#define mx 500004
#define md 2000000000000000000ll
typedef pair<int, int >P;
typedef vector<ll>V;

////////define value/////

int main(){
   ll x,y;
   cin>>x>>y;
   ll res =(x*y)/__gcd(x,y);
   cout<<res<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define rando mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
int main(){
	boost;
	string ph;
	cin>>ph;
	string last="",curr="";
	last+=ph[0];
	int ans=1;
	for (int i = 1; i < sz(ph); ++i)
	{
		curr+=ph[i];
		if(curr!=last)ans++,swap(last,curr),curr="";
	}
	cout<<ans;
	return 0;
}
//long long
//array bounds
//special cases
//binary search

Measured memory_bytes: 720
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ll = long long int;
using vec = vector<int>;
using P = pair<int,int>;
const int INF = 1e9+7;

int main() {
  int n; cin >> n;
  map<int, int> mp;
  ll sum = 0;
  rep(i,n) {
    int a; cin >> a;
    mp[a]++;
    sum += a;
  }


  int q; cin >> q;
  rep(i,q) {
    int b, c; cin >> b >> c;
    sum += (c-b) * mp[b];
    mp[c] += mp[b];
    mp[b] = 0;
    printf("%ld\n", sum);
  }
}


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

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)
#define forall(it, c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); ++ it)

template <typename T> inline void read(T &x) {
	x = 0; bool f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	for (;  isdigit(c); c = getchar()) x = x * 10 + (c & 15);
	if (!f) x = -x;
}

int main() {
	int a, b, h, m;
	read(a); read(b); read(h); read(m);
	long double pi = acos(-1.0);
	long double degm = (m / 60.0) * 2 * pi;
	long double degh = ((h + m / 60.0) / 12.0) * 2 * pi;
	long double deg = abs(degh - degm);
	long double c2 = a * a + b * b - cos(deg) * 2 * a * b;
	printf("%.15f\n", (double) sqrt(c2));
	return 0;
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  string b;
  cin >> b;
  rep (i, sz(b)) {
    if (b[i] == 'A') cout << 'T';
    if (b[i] == 'T') cout << 'A';
    if (b[i] == 'C') cout << 'G';
    if (b[i] == 'G') cout << 'C';
  }
  cout << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
	static int mod = 1_000_000_007;
	static long[][] dp = new long[100005][2];

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String L = sc.next();
		int n = L.length();
		dp[0][0] = 1;
		for (int i=0;i<n;i++) {
			if (L.charAt(i) == '0') {
				dp[i+1][0] = dp[i][0];
				dp[i+1][1] = dp[i][1];
			} else {
				dp[i+1][1] = (dp[i][0] + dp[i][1]) % mod;
			}
			if (L.charAt(i) == '0') {
				dp[i+1][1] = (dp[i+1][1] + dp[i][1]*2) % mod;
			} else {
				dp[i+1][0] = (dp[i+1][0] + dp[i][0]*2) % mod;
				dp[i+1][1] = (dp[i+1][1] + dp[i][1]*2) % mod;
			}
		}
		long ans = (dp[n][0]+dp[n][1]) % mod;
		System.out.println(ans);
	}

}

Measured memory_bytes: 27144
#include <stdio.h>
#define NUM 1200

int main(void) {
  char str1[NUM];
  int i,j;
  gets(str1);
  for(i=0;i<NUM;i++){
    if('a'<=str1[i]&&str1[i]<='z')
      str1[i]=str1[i]-32;
    else if('A'<=str1[i]&&str1[i]<='Z')
      str1[i]=str1[i]+32;
  }
  printf("%s\n",str1);
  return 0;
}

Measured memory_bytes: 524
#include <stdio.h>
 
int main(void)
{
    int a, b, c[100000], i;
 
    scanf("%d %d", &a, &b);
 
    for (i = 0; i < b; ++i){
        scanf("%d", &c[i]);
    }
 
    for (i = 0; i < b; ++i){
       a -= c[i]; 
    }
    
    if (a < 0) printf("-1\n");
 
    else printf("%d\n", a);
 
    return 0;
 
}

Measured memory_bytes: 1732
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______      
 * |\  \|\  \  |\  ___ \  |\  ___ \     
 * \ \  \/  /|_\ \   __/| \ \   __/|    
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__  
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \ 
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;


int main(int argc, char** argv) {
#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
#endif
	
	int N;
	cin>>N;
	vector<pair<pair<int,int>,long long> > a(N);
	for(int i = 0;i < N;i++) cin>>a[i].first.first>>a[i].first.second>>a[i].second;
	if(a[0].second == 0) for(int i = 1;i < N;i++) if(a[i].second != 0) {
		swap(a[0],a[i]);
		break;
	}
	for(long long cx = 0;cx <= 100;cx++) {
		for(long long cy = 0;cy <= 100;cy++) {
			bool can = true;
			long long h = -1;
			for(int i = 0;i < N;i++) {
				long long cur = a[i].second + abs(a[i].first.first - cx) + abs(a[i].first.second - cy);
				if(h == -1) {
					h = cur;
				} else {
					if(a[i].second == 0) can &= cur >= h;
					else can &= cur == h;
				}
			}
			if(can) {
				cout<<cx<<' '<<cy<<' '<<h<<'\n';
				return 0;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
using namespace std;

const int N = 2e6;

int x[N], y[N];

int main() {
	clog << "Ready\n";
	int n, m;
	cin >> n >> m;
	
	int X, Y;
	cin >> X >> Y;
	
	const int INF = 1e9;
	
	int mx = -INF;
	
	for (int i = 1; i <= n; ++ i) {
		cin >> x[i];
		mx = max(mx, x[i]);
	}
	
	for (int i = 1; i <= m; ++ i) {
		cin >> y[i];
	}
	
	for (int z = X + 1; z <= Y; ++ z) {
		bool ok = false;
		for (int i = 1; i <= n; ++ i) {
			if (x[i] >= z) {
				ok = true;
				break;
			}
		}
		for (int i = 1; i <= m; ++ i) {
			if (y[i] < z) {
				ok = true;
				break;
			}
		}
		if (!ok)
			return cout << "No War", 0;
	}
	
	cout << "War";
	
	return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define req(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define qer(i,a,n) for (int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=998244353;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

int f[100000];
int main(){
	ll n;int x,m;cin>>n>>x>>m;
  	ll num=x;f[x]=1;int l=0,r=0;
    req(i,2,n){
        num=num*num%m;if(f[num]){l=f[num],r=i;break;}
        f[num]=i;
    }
    ll ans=0;
    rep(i,0,m)if(f[i]){
        if(f[i]<l||l==0)ans+=i;
        else ans+=i*((n-f[i])/(r-l)+1);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3968
## coding: UTF-8

N, P = map(int,input().split())
S = input()[::-1]


remainder = [0] * P
tmp = 0
rad = 1 #10**(i) % P

'''
if(P == 2 or P == 5):
    for i in range(N):
        r = int(S[i])
        tmp += r * rad
        tmp %= P
        remainder[tmp] += 1
        rad *= 10
'''
if(P == 2):
    ans = 0
    for i in range(N):
        r = int(S[i])
        if(r % 2 == 0):
            ans += N-i
    print(ans)
elif(P == 5):
    ans = 0
    for i in range(N):
        r = int(S[i])
        if(r % 5 == 0):
            ans += N-i
    print(ans)
else:
    for i in range(N):
        r = int(S[i])
        tmp += r * rad
        tmp %= P
        remainder[tmp] += 1
        rad *= 10
        rad %= P
    remainder[0] += 1

    #print(remainder)

    ans = 0
    for i in range(P):
        e = remainder[i]
        ans += e*(e-1)/2
    print(int(ans))



Measured memory_bytes: 41968
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define rep(i,l,r) for(int i=0l;i<r;i++)
typedef long long ll;

int asc(const void* a, const void* b) { return -*(int*)a + *(int*)b; }

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

int main() {
	ll s;
	scanf("%lld", &s);
	ll MAX = 1000000000;
	printf("0 0 %lld 1 %lld %lld", MAX, (MAX - s % MAX)%MAX, (s +(MAX-s%MAX)%MAX)/ MAX);

	return 0;
}

Measured memory_bytes: 2136
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){
  int k,x;cin>>k>>x;
  int l,r;
  l = x -k+1;
  r = x+k-1;
  for(int i=l;i<=r;i++){
    cout<<i<<" ";
  }
  cout<<endl;

 

  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        long mod = (long)Math.pow(10,9)+7;
        FastScanner sc = new FastScanner(System.in);
        long n = sc.nextLong();
        long k = sc.nextLong();
        long ans = 0;
        for(int i = 1; i <= k; i++){
            System.out.println(nCk(n-k+1,(long)i,mod)%mod * nCk(k-1,i-1,mod)% mod);
        }
    }
    
    public static long nCk(long n,long k,long M) {
        if(n < 0 || k < 0 || n < k){
            return 0;
        }
        long ret = 1;
        long min = Math.min(k, n-k);
        for(long i=1;i<=min;i++) {
            ret = (ret * pow(i,M-2,M)) % M;
        }
        for(long i=n-min+1;i<=n;i++) {
            ret = (ret * i) % M;
        }
        return ret;
    }

    public static long pow(long a,long b,long M) {
        long ret = 1;
        long tmp = a;
        while(b>0) {
            if((b&1)==1){
                ret = (ret * tmp) % M;
            }
            tmp = (tmp * tmp) % M;
            b = b>>1;
        }
        return ret;
    }
    
    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

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

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

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

            return tokenizer.nextToken("\n");
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
             return Double.parseDouble(next());
         }

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

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


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

int main() {
  int N;
  cin >> N;
  vector<int> V(N);
  for (int i = 0; i < N; i++)
    cin >> V.at(i);
  
  int count = 0;
  for (int j = 0; j < N; j++) {
    if (V.at(j)%2 == 0) {
      if (V.at(j)%3 != 0 && V.at(j)%5 != 0)
        count++;
    }
  }
  
  if (count == 0)
    cout << "APPROVED" << endl;
  else
    cout << "DENIED" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn int(1e6+5)
using namespace std;

int sieve[maxn];
map<int,int> cnt;

int main(){
    int n, v=-1;
    vector<int> a;

    for(int i=2;i<maxn;i++)
        if(!sieve[i])
            for(int j=i;j<maxn;j+=i)
                sieve[j] = i;

    cin >> n;
    a.assign(n,0);
    for(int i=0;i<n;i++){
        cin >> a[i];
        int x = a[i];
        while(x!=1){
            int f = sieve[x];
            cnt[f]++;
            while(sieve[x]==f)
                x/=f;
        }
    }

    bool pairwise = true, setwise=true;
    for(auto p:cnt){
        if(p.second!=1)
            pairwise = false;
            if(p.second==n)
                setwise=false;
    }

    if(pairwise)
        cout << "pairwise coprime" <<'\n';
    else if(setwise)
        cout << "setwise coprime" <<'\n';
    else
        cout << "not coprime" <<'\n';
    
    return 0;
}



Measured memory_bytes: 14700
#include <cstdio>
#include <vector>
#include <algorithm>
#include <array>
#include <set>
#include <map>
#include <queue>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < int(n); ++(i))
#define repeat_reverse(i,n) for (int i = (n)-1; (i) >= 0; --(i))
#define repeat_from_reverse(i,m,n) for (int i = (n)-1; (i) >= int(m); --(i))
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define debug(x) #x << " = " << (x) << " "
using ll = long long;
using namespace std;
template <class T> inline void setmax(T & a, T const & b) { a = max(a, b); }
template <class T> inline void setmin(T & a, T const & b) { a = min(a, b); }
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

constexpr ll inf = ll(1e18)+9;
int main() {
    // input
    int n; scanf("%d", &n);
    vector<ll> a(3*n); repeat (i,3*n) scanf("%lld", &a[i]);
    // compute
    vector<ll> front(3*n+1); {
        reversed_priority_queue<ll> que;
        repeat (i,3*n) {
            que.push(a[i]);
            ll b = 0;
            if (que.size() == n+1) {
                b = que.top(); que.pop();
            }
            front[i+1] = front[i] + a[i] - b;
        }
    }
    vector<ll> back(3*n+1); {
        priority_queue<ll> que;
        repeat_reverse (i,3*n) {
            que.push(a[i]);
            ll b = 0;
            if (que.size() == n+1) {
                b = que.top(); que.pop();
            }
            back[i] = back[i+1] + a[i] - b;
        }
    }
    ll result = - inf;
    repeat_from (i,n,2*n+1) {
        setmax(result, front[i] - back[i]);
    }
    // output
    printf("%lld\n", result);
    return 0;
}


Measured memory_bytes: 9068