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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define All(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
template<class T> T gcd(T a,T b) {return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b) {return a/gcd(a,b)*b; }
template<class T> bool isPrime(T num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (T i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

using namespace std;

int a,n;

main()
{
    cin>>n;
    int cnt=1;
    bool f=false;
    rep(i,n)
    {
        cin>>a;
        if(a==cnt)cnt++;
        if(a==1)f=true;
    }
    if(!f)cout<<-1<<endl;
    else cout<<n-cnt+1<<endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
edges = [[] for _ in range(N)]

for _ in range(M):
    fr, to, dist = map(int, input().split())
    fr -= 1
    to -= 1
    edges[fr].append((to, dist))
    edges[to].append((fr, -dist))

INF = 10**18
minDist = [INF] * N
for s in range(N):
    if minDist[s] < INF:
        continue
    st = [s]
    minDist[s] = 0
    while st:
        now = st.pop()
        dist = minDist[now]
        for to, d in edges[now]:
            if minDist[to] == INF:
                minDist[to] = dist + d
                st.append(to)
                continue
            if minDist[to] != dist + d:
                print('No')
                exit()
print('Yes')


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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var DG = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var D = DG[0];
            var G = DG[1];
            var pc = new List<int[]>();

            for (var i = 0; i < D; i++)
            {
                pc.Add(Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray());
            }
            var min = int.MaxValue;
            for(var bt=0;bt<(1<<D);bt++)
            {
                int cc = 0, sum = 0;
                for(var i =0;i<D;i++)
                {
                    if((bt&(1<<i))!=0)
                    {
                        cc += pc[i][0];
                        sum += pc[i][0] * (i + 1) * 100 + pc[i][1];
                    }
                }
                var diff = Math.Max(0, G - sum);
                for (var i = D - 1; i >= 0; i--)
                {
                    if ((bt & (1 << i)) != 0) continue;
                    var pt = (i + 1) * 100;
                    var tmp = Math.Min((diff + pt - 1) / pt, pc[i][0] - 1);
                    cc += tmp;
                    diff = Math.Max(0, diff - pt * tmp);
                }
                if (diff > 0) continue;
                min = Math.Min(min, cc);
            }
            Console.WriteLine(min);
        }
    }
}


Measured memory_bytes: 13396
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] p = new long[2*N+1];
        long D = 0;
        
        for(int i = 0; i < 2*N+1; i++){
            p[i] = sc.nextLong();
        }
        
        for(int i = 0; i < N; i++){
            if(p[i] - p[N+1+i] >= 0){
                D = D + p[N+1+i];
            }else{
                if(p[i+1] - (p[N+1+i] - p[i]) >= 0){
                    D = D + p[N+1+i];
                    p[i+1] = p[i+1] - (p[N+1+i] - p[i]);
                }else{
                    D = D + p[i] + p[i+1];
                    p[i+1] = 0;
                }
            }
        }
        
        System.out.println(D);
    }
}

Measured memory_bytes: 87316
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pw(x) (1ll << (x))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(i=(l);i<(r);++i)
#define per(i,l,r) for(i=(r)-1;i>=(l);--i)
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl
//-----
const int N=100005;
ll pre[N],rpre[N];
int vec[N],sz=0;
ll qry(int l,int r) {
  return pre[r]-pre[l-1];
}
ll mymax(ll a,ll b) {
  return a>b?a:b;
}
int main() {
  int i;
  sz=0;
  int n,a;scanf("%d%d",&n,&a);pre[1]=rpre[1]=a;
  rep(i,2,n+1) {
    char s[5];
    int a;scanf("%s%d",s,&a);
    pre[i]=pre[i-1]+a;
    if(s[0]=='-') {
      rpre[i]=rpre[i-1]-a;
      vec[sz++]=i;
    }
    else rpre[i]=rpre[i-1]+a;
  }
  ll ans=rpre[n];
  rep(i,0,sz-1)ans=mymax(ans,rpre[vec[i]-1]-qry(vec[i],vec[i+1]-1)+qry(vec[i+1],n));
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 2176
n=int(input())
a=[int(i) for i in input().split()]

ans=0
b=0
j=0
for i in range(n):
	while j<n and b^a[j]==b+a[j]:
		b^=a[j]
		j=j+1
	ans += j-i
	b^=a[i]
print(ans)


Measured memory_bytes: 23560
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0; i < n; i++)
#define repd(i, n) for (int i = n-1; i > -1; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;
using LP = pair<ll,ll>;
using P = pair<ll,int>;

int main()
{
    ll a, b, x;
    cin >> a >> b>> x;
    auto div = [&](ll y){
        ll ret = y/x+1;
        if (y < 0) ret = 0;
        return ret;
    };
    ll ans = div(b)-div(a-1);
    cout << ans << endl;
}

Measured memory_bytes: 3624
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debugg cout<<"debugged\n";
#define setpr(xval) cout<<fixed<<setprecision(12)<<xval<<endl;
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll n,m,k,ans;
void solve()
{
    cin>>n>>m;
    vector<ll> ar(m+1,0);
    for(ll i=0;i<n;i++)
    {
        cin>>k;
        for(int j=0;j<k;j++)
        {
            ll a;cin>>a;
            ar[a]++;
        }
    }
    for(ll i=1;i<=m;i++)
    {
        if(ar[i]==n)
            ans++;
    }
    cout<<ans<<endl;
}

int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
//#define MOD 1000000007
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
    int a,b,c,d; cin >> a >> b >> c >> d;
    bool ok = false;
    if(abs(a-c) <= d) ok = true;
    if(abs(a-b) <= d && abs(b-c) <= d) ok = true;
    cout << (ok?"Yes":"No") << endl;
}

    



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

int main(void){
    double v;
    while(cin >> v) {
        for(int n=1; ; ++n) {
            double t = sqrt((5*n-5)/4.9);
            if(9.8*t > v) {
                cout << n << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 1228
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			String s = sc.nextLine();
			if(s.compareTo(".")==0) break;
			
			ArrayList<String> list = new ArrayList<String>();
			
			for(int i=0;i<s.length();i++) list.add(s.substring(i,i+1));
			
			boolean flag = true;
			boolean out = true;

			for(int i=0;i<list.size();i++){
				if(list.indexOf(")")==-1 && list.indexOf("]")==-1 && list.indexOf("(")==-1 && list.indexOf("[")==-1) break;
				if(list.get(i).compareTo(")")==0){
					out = true;
					for(int j=i;j>=0;j--){
						if(list.get(j).compareTo("(")==0){
							list.remove(i);
							list.remove(j);
							i-=2;
							out = false;
							break;
						}else if(list.get(j).compareTo("[")==0){
							break;
						}
					}
					if(out==true) flag = false;
				}else if(list.get(i).compareTo("]")==0){
					out = true;
					for(int j=i;j>=0;j--){
						if(list.get(j).compareTo("[")==0){
							list.remove(i);
							list.remove(j);
							i-=2;
							out = false;
							break;
						}else if(list.get(j).compareTo("(")==0){
							break;
						}
					}
					if(out==true) flag = false;
				}
				if(flag==false) break;
				
			}
			if(list.indexOf(")")!=-1 || list.indexOf("]")!=-1 || list.indexOf("(")!=-1 || list.indexOf("[")!=-1) flag = false;
			
			if(flag==true) System.out.println("yes");
			else System.out.println("no");
		}
	}	
}

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

int main() {
  int N, M;
  cin >> N;
  vector<string> vec1(N);
  for (int i = 0; i < N; i++){
   cin >> vec1.at(i);
  }
  cin >> M;
  vector<string> vec2(M);
  for (int i = 0; i < M; i++){
   cin >> vec2.at(i);
  }
  string chcck;
  int Max = 0;
  for (int i = 0; i < N; i++){
    
    chcck = vec1.at(i);
    int kaunt = 0;
    for (int i = 0; i < N; i++){
      if (vec1.at(i) == chcck){
        kaunt++;
      }
    }
    for (int i = 0; i < M; i++){
      if (vec2.at(i) == chcck){
        kaunt--;
      }
    }
    if (Max < kaunt){
      Max = kaunt;
    }
  }
  cout << Max << endl;
}

Measured memory_bytes: 256
def inp():
    return input()
def iinp():
    return int(input())
def inps():
    return input().split()
def miinps():
    return map(int,input().split())
def linps():
    return list(input().split())
def lmiinps():
    return list(map(int,input().split()))
def lmiinpsf(n):
    return [list(map(int,input().split()))for _ in range(n)]

k,n = miinps()
a = lmiinps()

l = -1

for i in range(n-1):
  l = max(l,a[i+1]-a[i])

if a[0] == 0:
    l = max(l,k-a[n-1])
else:
    l = max(l,(k-a[n-1])+a[0])

print(k-l)

Measured memory_bytes: 26444
open Printf
open Scanf

let id x = x

let rec seq s t f =
  if s > t then []
  else
    let x = f s in
    x :: seq (s + 1) t f

let solve x =
  let dp = Array.init (x + 1) @@ fun _ -> 0 in
  begin
    dp.(0) <- 1;
    List.iter (fun i ->
        List.iter (fun j ->
            if dp.(j) = 1 && i + j <= x then dp.(i + j) <- 1 else ()
          ) @@ seq 0 x id
      ) @@ seq 100 105 id;
    dp.(x)
  end                              

let () =
  scanf "%d " solve |> printf "%d\n"


Measured memory_bytes: 21084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int maxn=1e6+5;
const int mod=2;
char buff[maxn];
int cnt[maxn],sum[maxn];
int main() {
    int n;cin>>n>>(buff+1);bool one=0;
    for(int i=1;i<=n;i++) {
        buff[i]-='1';if(buff[i]==1) one=1;
        if(i%2==0) cnt[i]=cnt[i/2]+1;
        sum[i]=sum[i-1]+cnt[i];
    }
    if(!one) for(int i=1;i<=n;i++) buff[i]/=2;
    int ans=0;
    for(int i=1;i<=n;i++) if(sum[n-1]==sum[i-1]+sum[n-i]) ans=ans+buff[i];
    ans%=2;
    cout<<ans*(one?1:2)<<endl;
    return 0;
}

Measured memory_bytes: 12408
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin >> s;
    int n = s.length();
    int g = 0;
    for(int i = 0; i < n; i++)
    {
        if(s[i] != s[n-i-1])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    for(int i = 0; i < (n-1)/2; i++)
    {
        if(s[i] != s[(n-1)/2-i-1])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    for(int i = (n+3)/2 - 1; i < n; i++)
    {
        if(s[i] != s[n-i-1])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;

}


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

#define INF 100100100
#define MOD 1000000007

using namespace std;
using ll = long long;
using ull = unsigned long long ;

#define FOR(i,n) for(ll i=0;i<n;i++)


int main(int argc, char const* argv[]){
   ios::sync_with_stdio(false);
   cin.tie(0); 
   ull N;
   cin>>N;
   map<ull,ull>A;
   ull MAX1=0,MAX2=0;
   FOR(i,N){
      ull a;
      cin>>a;
      A[a]++;
      if(A[a]==2){
         if(MAX1<=a){
            MAX2=MAX1;
            MAX1=a;
         }
         else if(MAX2<=a)MAX2=a;
      }
      if(A[a]==4){
         if(MAX1<=a){
            MAX2=MAX1;
            MAX1=a;
         }
         else if(MAX2<=a)MAX2=a;
      }
   }
   cout<<MAX1*MAX2<<endl;
   return 0;
}


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

int BinarySearch(int x, int S[], int N){
  int B = 0;
  int T = N-1;

  while(B<=T){
    int mid = (B+T)/2;
    int count=0;

    if(S[mid]==x){
      count++;
      return count;
    }
    else if(S[mid]<x){
      B = mid+1;
    }
    else{
      T = mid-1;
    }
  }

  return -1;
}
int main(){
  int a;
  cin >> a;
  int A[a];
  for(int i=0; i<a; i++){
    cin >> A[i];
  }

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

  int cnt=0;
  for(int j=0; j<b; j++){
    int x = BinarySearch(B[j], A, a);
    if(x==1)
      cnt++;
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 3620
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>
using namespace std;

int main() {
	int N, M, R, A, B, C, ans = INT_MAX;
	cin >> N >> M >> R;
	vector<int> r(R);
	for (int& i : r) cin >> i;
	sort(r.begin(), r.end());
	vector<vector<int>> a(N, vector<int>(N, INT_MAX));
	for (int i = 0; i < M; i++) {
		cin >> A >> B >> C;
		a[A - 1][B - 1] = C;
		a[B - 1][A - 1] = C;
	}
	for (int i = 0; i < N; i++) a[i][i] = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (a[j][i] == INT_MAX) continue;
			for (int k = 0; k < N; k++) {
				if (a[i][k] == INT_MAX) continue;
				a[j][k] = min(a[i][k] + a[j][i], a[j][k]);
			}
		}
	}
	do {
		int b = 0;
		for (int i = 1; i < R; i++) b += a[r[i - 1] - 1][r[i] - 1];
		ans = min(b, ans);
	} while (next_permutation(r.begin(), r.end()));
	cout << ans;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include <chrono>
using namespace std::chrono;
using namespace std;
#define fr(x,i,n) for(int x = i; x < n; ++x)
#define fb(x,i,n) for(int x = i; x >= n; --x)
#define pr pair<int,int>
#define ll long long int
const int mod=1e9+7;
/*    auto start = high_resolution_clock::now();
    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop - start);
    cout << "\nduration="<<duration.count()/1e6 << endl;
*/
void solve(){
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll ans=0;
    if(k>0){
        ans+=min(a,k);
        k-=min(a,k);
    }
    if(k>0){
        k-=min(b,k);
    }
    if(k>0){
        ans-=min(c,k);
    }
    cout<<ans;

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;
//    cin>>t;
    while(t--)
    solve();

}


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

using namespace std;

typedef long long ll;
typedef long double ld;

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

    ld x1,y1,x2,y2,x3,y3;
    cin>>x1>>y1>>x2>>y2>>x3>>y3;
    ld a=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    ld b=sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
    ld c=sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1));
    ld s = (a+b+c)/2;
    ld S = sqrt(s*(s-a)*(s-b)*(s-c));
    ld r = 2*S/(a+b+c);
    ld ma=max(a,max(b,c));
    ld x = ma/(2+ma/r);
    cout<<fixed<<setprecision(15)<<x<<endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#define rep(i,n) for(int i=0;i<n;i++)
#define ck(a,b) abs(a-b)<0.0001
using namespace std;
double x[30],y[30],z[30],qr,rp,pq;
double d(int a,int b){
	double r=(x[a]-x[b])*(x[a]-x[b]);
	r+=(y[a]-y[b])*(y[a]-y[b]);
	r+=(z[a]-z[b])*(z[a]-z[b]);
	return sqrt(r);
}
int main(){
	int c,n;cin>>c;
	while(c--){
		cin>>qr>>rp>>pq>>n;
		rep(i,n)cin>>x[i]>>y[i]>>z[i];
		rep(p,n)rep(q,n)rep(r,n)if(p!=q&&p!=r&&q!=r)
		if(ck(d(r,p)/d(q,r),rp/qr)&&ck(d(p,q)/d(q,r),pq/qr)){
			cout<<p+1<<" "<<q+1<<" "<<r+1<<endl;
			goto END;
		}
		END:;
	}
	return 0;
}

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

int main() {
  int h1,m1,h2,m2,k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  int a = ((60 * h2 + m2)-(60 * h1 + m1) - k);
  cout << a << endl;
    
}

Measured memory_bytes: 3612
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
using namespace std;

#define ll long long
#define mst(a) memset(a, 0, sizeof a)

const int mod = 1e9+7;
const int maxn = 1e5+50;
const int inf = 1e9;

struct city
{
    int id;
    int y;
    friend bool operator < (const city &a, const city &b)
    {
        return a.y < b.y;
    } 
    city(int _id, int _y)
    {
        id = _id;
        y = _y;
    }
};

vector<city> P[maxn];
int ansp[maxn], ansc[maxn];

int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; ++i)
    {
        int p, y;
        scanf("%d %d", &p, &y);
        P[p].push_back(city(i, y));
    }
    for (int i = 1; i <= n; ++i)
    {
        sort(P[i].begin(), P[i].end());
        for (int j = 0; j < P[i].size(); ++j)
        {
            ansp[P[i][j].id] = i;
            ansc[P[i][j].id] = j + 1;
        }
    }
    for (int i = 0; i < m; ++i)
        printf("%06d%06d\n", ansp[i], ansc[i]);
    return 0;
}

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

#define CO const
#define IN inline
typedef long long int64;

template<class T> IN T read(){
	T x=0,w=1;char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-') w=-w;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*w;
}
template<class T> IN T read(T&x){
	return x=read<T>();
}

CO int N=2e3+10,inf=1e9;
char s[N];
int a[N];
vector<int> e[N];
int dis[N],siz[N],f[N];

void dfs(int u,int fa){
	siz[u]=a[u];
	int maxp=0;
	for(int v:e[u])if(v!=fa){
		dfs(v,u);
		siz[u]+=siz[v];
		dis[v]+=siz[v],dis[u]+=dis[v];
		if(dis[v]>dis[maxp]) maxp=v;
	}
	if(!maxp) return;
	if(dis[u]>=2*dis[maxp]) f[u]=dis[u]/2;
	else f[u]=dis[u]-dis[maxp]+min(f[maxp],(2*dis[maxp]-dis[u])/2);
}
int main(){
	int n=read<int>();
	scanf("%s",s+1);
	for(int i=1;i<=n;++i) a[i]=s[i]-'0';
	for(int i=1;i<n;++i){
		int u=read<int>(),v=read<int>();
		e[u].push_back(v),e[v].push_back(u);
	}
	int ans=inf;
	for(int i=1;i<=n;++i){
		for(int j=1;j<=n;++j) dis[j]=siz[j]=f[j]=0;
		dfs(i,0);
		if(dis[i]&1) continue;
		if(f[i]*2>=dis[i]) ans=min(ans,dis[i]/2);
	}
	printf("%d\n",ans==inf?-1:ans);
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
using namespace std;

long long N, L[1000009];

int main() {
	cin >> N;
	for (long long i = 0; i < N; i++) cin >> L[i];

	sort(L + 0, L + N);

	if (N % 2 != 0) {
		cout << 0;
		return 0;
	}

	long long h = (long long)(N / 2);
	cout <<  L[h] - L[h - 1];

	return 0;
}

Measured memory_bytes: 3940
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

vector<int> G[100100], H[100100];
int N, M;
bool used[100100] = {false};
vector<int> topo;

void dfs(int s) {
  if(used[s] == true) return;
  used[s] = true;
  for(int i = 0; i < G[s].size(); i++) dfs(G[s][i]);
  topo.push_back(s);
}

void tpsort() {
    rep1(i, N) dfs(i);
    reverse(topo.begin(), topo.end());
}

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

  cin >> N >> M;
  rep(i, N + M - 1) {
      int s, t; cin >> s >> t;
      G[s].push_back(t);
      H[t].push_back(s);
  }
  
  tpsort();
  map<int, int> tp;
  rep(i, N) {
      tp[topo[i]] = i;
  }
  rep1(i, N) {
    int k = -1;
    for(int j: H[i]) {
        k = max(k, tp[j]);
    }
    if(k == -1) {
        cout << 0 << "\n";
        continue;
    } else {
        cout << topo[k] << "\n";
    }
  }
  return 0;
}

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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main() {
  ll N;
  cin>>N;
  vector<ll> A(N+1);
  A[0]=-1;
  for(ll i = 1; i <= N; i++) cin>>A[i];
  bool can = true;
  for(ll i = 1;i <= N; i++){
    if(A[i]>A[i-1]+1) can = false;
  }
  if(can){
    ll ans = 0LL;
    for(ll i = 0; i <= N; i++){
      if(i==N) ans+=A[N];
      else{
        if(A[i+1]<=A[i]) ans+=A[i];
      }
    }
    cout<<ans<<endl;
  }
  else cout<<-1<<endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int llu;
typedef long double ld;
typedef float fl;
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pair<int,int>>
#define pb push_back
#define pf push_front
#define mp map<ll,ll>
#define INF 1000000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
ll gcd(ll a,ll b)
{
    if(a==0)
    {
        return b;
    }
    else
    {
        return gcd(b%a,a);   
    }
}
ll lcm(ll a,ll b)
{
    return a*b/gcd(a,b);
}
int f(char c)
{
    return (int)c-96;
}
/**********************************************************************
***********************************************************************
*********************ACTUAL CODE BEGINS HERE***************************/
int main()
{   
    fast;
    ll i;
    ll n;
    cin>>n;
    ll x=0;
    for(i=1;i<=999998;i++)
    {
       x=((x%n)*(10%n)+(7%n))%n;
       if(x%n==0)
       {
           cout<<i;
           return 0;
       }
    }
    cout<<-1;
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
using namespace std;
int main()
{
    int x;
    x=1;
    if(x>=1 && x<=9)
    {
        cin>>x;
        if(x==3||x==5||x==7)
        {
            cout<<"YES";
        }
        else
        {
            cout<<"NO";
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int k = sc.nextInt();
      int r = sc.nextInt();
      int s = sc.nextInt();
      int p = sc.nextInt();
      String t = sc.next();
      char[] chs = t.toCharArray();

      Map<Character, Long> freq = new HashMap<>();
      freq.put('r', 0L);
      freq.put('s', 0L);
      freq.put('p', 0L);
      for(int i = 0; i < chs.length; i++) {
        if(i >= k) {
          if(chs[i] == chs[i-k]) {
            chs[i] = '-';
            continue;
          }
        }
        freq.put(chs[i], freq.get(chs[i]) + 1);
      }
      System.out.println(p * freq.get('r') + r * freq.get('s') + s * freq.get('p'));
  }
}

Measured memory_bytes: 26924
#include <stdio.h>

int main(void){
    long long N, A[100005], B[100005], k, i;
    scanf("%lld", &N);
    for (i=1; i<=N+1; i++) {
        scanf("%lld", &A[i]);
    }
    for (i=1; i<=N; i++) {
        scanf("%lld", &B[i]);
    }
    k=0;
    for (i=1; i<=N; i++) {
        if (B[i]<=A[i]) {
            k+=B[i];
            // printf("%d, 1\n", i);
        }
        else if (A[i]<B[i] && B[i]<=A[i]+A[i+1]) {
            k+=B[i]; A[i+1]-=B[i]-A[i];
            // printf("%d, 2\n", i);
        }
        else if (A[i]+A[i+1]<B[i]) {
            k+=A[i]+A[i+1]; A[i+1]=0;
            // printf("%d, 3\n", i);
        }
    }
    printf("%lld", k);
    return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i = (ll)(a); i < (ll)(b); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1LL << 60;
using bs = bitset<55>;

struct Edge {
    int to, id; //行き先のnode, 辺のid
    Edge(int to, int id): to(to), id(id){}
};
vector<Edge> g[55];
vector<int> es;
//from node, to node, parent
bool dfs(int v, int tv, int p=-1){
    if(v==tv) {
        es = vector<int>();
        return true;
    }
    for(Edge e : g[v]){
        if(e.to==p) continue;
        if(dfs(e.to, tv, v)) {
            es.push_back(e.id);
            return true; //行き先に1つでも正解があれば
        }
    }
    return false; //v==tvを満たさない、行き先もない
}
int main(){
    int n,m; cin >> n;
    
    rep(i,n-1){
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].emplace_back(b,i);
        g[b].emplace_back(a,i);
    }
    cin >> m;
    vector<bs> eset(m);
    rep(i,m) eset[i].reset();
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--; b--;
        dfs(a,b);
        for(auto e : es){
            eset[i] |= 1LL<<e;
        }
    }

    ll ans = 0;
    rep(i,1<<m){
        bs mask(0);
        rep(j,m){
            if(i>>j&1) mask |= eset[j];
        }
        int ct = __builtin_popcount(i); //mのうちいくつ使ってるか
        int fr = n - 1 - mask.count(); //freeな辺の数
        ll now = 1;
        rep(_,fr) now*=2;
        if(ct % 2 == 0) ans += now;
        else ans -= now;
    }

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

Measured memory_bytes: 384
import java.awt.geom.Point2D;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		
		int students = Integer.parseInt(scan.next());
		int checkpoints = Integer.parseInt(scan.next());
		
		Point2D[] Students = new Point2D[students];
		for(int i = 0;i < students;i++){
			int x = Integer.parseInt(scan.next());
			int y = Integer.parseInt(scan.next());
			Students[i] = new Point2D.Double(x,y);
		}
		Point2D[] CheckPoints = new Point2D[checkpoints];
		for(int i = 0;i < checkpoints;i++){
			int x = Integer.parseInt(scan.next());
			int y = Integer.parseInt(scan.next());
			CheckPoints[i] = new Point2D.Double(x,y);
		}
		
		int man = 0;
		int bef = -1;
		int p = 1;
		
		for(int i = 0;i < students;i++){
			bef = -1;
			p = 0;
			for(int k = 0;k < checkpoints;k++){
				int sx = (int)Students[i].getX();
				int sy = (int)Students[i].getY();
				int cx = (int)CheckPoints[k].getX();
				int cy = (int)CheckPoints[k].getY();
				
				man = Math.abs(sx - cx) + Math.abs(sy - cy);
				if(bef == -1 || bef > man){
					bef = man;
					p = k + 1;
					continue;
				}
				
			}
			System.out.println(p);
			
		}
		
		

	}
	
	

}


Measured memory_bytes: 23764
#include <algorithm>
#include <cmath>
#include <iostream>


using namespace std;

int main() {
  int n, i, k, x[105], ans = 0;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (i = 0; i < n; i++) {
    ans += 2 * min(abs(x[i]), abs(x[i] - k));
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
S = sum(B)

for i in range(N - 1):
    if A[i + 1] == A[i] + 1:
        S += C[A[i] - 1]
print(S)


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

void Array_Out(int *A, int N);

int main(){

  int N;
  cin >> N;
  int *A = new int(N);
  int i;
  for(i=0;i<N;i++){
    cin >> A[i];
  }
  Array_Out(A,N);
  int tmp;
  int j;
  for(i= 1; i < N; i++){
    tmp = A[i];
    j = i-1;
    while(j >= 0 && tmp < A[j]){
      A[j+1] = A[j];
      A[j] = tmp;
      j--;
    }
    Array_Out(A,N);
  }
  return 0;
}

void Array_Out(int *A, int N){
  int i;
  for(i=0;i<N;i++){
    cout << A[i];
    if(i==N-1) break;
    cout << " ";
  }
  cout << endl;
}

Measured memory_bytes: 1188
# -*- coding: utf-8 -*-
import sys
import os
import itertools
from math import *

ctime = []
for i in range(5):
  ctime.append(int(input()))
  
max_diff = 10
max_index = 100
for i in range(5):
  diff_time = (ctime[i]) % 10
  if diff_time < max_diff and diff_time > 0:
    max_index = i
    max_diff = ctime[i] % 10

time = 0
for i in range(5):
  if i != max_index:
    if ctime[i] % 10 == 0:
      time = time + ctime[i]
    else:
      time = time + ((ctime[i] // 10)+1) * 10
  else:
    time = time + ctime[i]
    
print(time)

Measured memory_bytes: 3064
def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
def inps() a=gets.chomp.split(" ")end  
def copy(a) Marshal.load(Marshal.dump(a)) end
def kaizyo(n)(n < 2)? 1 : (2..n).inject(:*) end
def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end
def na(n,d=0) Array.new(n,d)end
def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end
def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
def bit(n) n.to_s(2).split("").map(&:to_i) end
def inp() a=gets.chomp.split(" ").map(&:to_i)end
n = inp[0]
t = inp
num = 0
ans = 1
t.sort!{|a,b|b<=>a}
i = 0
while true
  break if(num == 2)
  break if(i >= t.size)
  if(t[i] == t[i+1])
    ans *= t[i]
    i += 1
    num +=1
  end
  i += 1
end
puts (num == 2)? ans : 0

Measured memory_bytes: 11544
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

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

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int n, W; cin>>n>>W;
    vector<int> v(n), w(n);
    for(int i=0; i<n; i++) cin>>v[i]>>w[i];

    vector<vector<int>> dp(n+1, vector<int>(W+1, 0));

    for(int i=0; i<n; i++){
        for(int j=0; j<=W; j++){
            chmax(dp[i+1][j], dp[i][j]);

            if(j + w[i] <= W){
                dp[i+1][j+w[i]] = max(dp[i][j+w[i]], dp[i+1][j] + v[i]);
            }
        }
    }

    cout << dp[n][W] << endl;
}


Measured memory_bytes: 6844
from collections import defaultdict

n, m = map(int, input().split())
ac_dict = defaultdict(int)
wa_dict = defaultdict(int)
ac_p, wa_p = set(), set()
for _ in range(m):
    p, s = input().split()
    p = int(p)
    if s == 'AC':
        ac_p.add(p)
        ac_dict[p] = 1
    elif ac_dict[p] != 1:
        wa_p.add(p)
        wa_dict[p] += 1

wa = 0
for pi in ac_p:
    wa += wa_dict[pi]

print(sum(ac_dict.values()), wa)


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

using namespace std;

typedef long long llong;
typedef unsigned long long ullong;
#define inf 1ll<<60
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
#define int llong
#define be(x) x.begin(), x.end()
typedef pair<int, int> P;


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

	cout << min(a,b) << " " << max(int(0), a+b-n) << endl;

	return 0;
}

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

using namespace std;

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

	int n;
	cin >> n;

	vector<int> a(n);
	for(int &i : a) {
		cin >> i;
	}

	map<int, int> mp;

	long long ans = 0;

	for(int i = 0; i < n; ++i) {
		ans += mp[i - a[i]];
		++mp[i + a[i]];
	}

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 20976
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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



int main()
{
  ll H,W,A,B; cin>>H>>W>>A>>B;
  string str=""; rep(i,W) str+='.';
  vector<string> grid(H,str);
  
  rep(i,H){
    rep(j,W){
      if(i<B&&j<A) grid[i][j]='0';
      else if(i>=B&&j>=A) grid[i][j]='0';
      else grid[i][j]='1';
    }
  }
  
  for(auto s:grid) cout<<s<<endl;
  return 0;
}

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

int main() {int n,i,a,b,max,min,sum,answer;
while(cin >> n, n ) {
i =2;
cin >> a;
max=a;
min=a;
sum =a;
while(i<=n)
{cin >> b;
if(b>max){max=b;}
if(b<min){min=b;}
sum = sum+b;
i++;
}
//if(b==0){break;}
answer=(sum-max-min)/(n-2);
cout << answer << endl;
}
	// your code goes here
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
 
#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main() {
    LL H, W;
    cin >> H >> W;
    if(H == 1 || W == 1) {
        cout << 1 << endl;
    } else {
        cout << (H * W / 2 + (H * W % 2)) << endl;
    }
}

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

//vector <long long> v;

long long int  x[1000000], y, pot[30], czy=0, w, n, m;
char s;

int main()
{
    long long int a, b, c, d, k, i, j, q, t, p;

//    q=1;
//    scanf("%lld", &q);
//    for(t=0; t<q; t++)
    {
        scanf("%lld%lld", &n, &k);

        for(i=0; i<n; i++)
        {
            scanf("%lld", &x[i]);
        }

        sort(x, x+n);

        w=0;

        for(i=0; i<k; i++)
        {
            w+=x[i];
        }

        printf("%lld\n", w);
    }

    return(0);
}


Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define REP(i,n) for(int i=0; i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    int N;cin>>N;
    vector<ll> L(2*N);
    REP(i,2*N)cin>>L[i];
    sort(L.begin(),L.end());
    ll res=0LL;
    REP(i,N)res+=L[2*i];
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import math
from collections import Counter
import itertools
import fractions
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################
 
N=II()
V=LI()
V.sort()

ans=V[0]
for i in range(N-1):
    ans = (ans + V[i+1])/2
print(ans)

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

int main() {
  int n, count;
  cin >> n;
  int a[n+1];

  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }

  int i = 1;
  count = 1;
  while(count < n){
    if (a[i] == 2) break;
    count++;
    i = a[i];
  }

  if (count == n) count = -1;

  cout << count << endl;
}

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

int main(){
    int M,D;
    cin >> M >> D;
    int d1,d10,cnt=0;
    for (int i=1;i<=M;++i){
        for(int j=1;j<=D;++j){
            d1 = j%10;
            d10 = j/10;
            if(d1*d10==i && d1>=2 && d10>=2){
                cnt+=1;
            }
        }
    }
    cout << cnt << endl;
}




Measured memory_bytes: 256
N,A,B = map(int,input().split())
if A == 0 and B == 0:
    print(A)
    exit()
a_b = A + B
h = int(N / a_b)
if N % a_b == 0:
    print(A*h)
else:
    s = N % a_b
    if s > A:
        print(h * A + A)
    else:
        print(h * A + s)


Measured memory_bytes: 38384
use proconio::input;

fn gcd(a:isize, b:isize) -> isize {
  if b == 0 {
    a
  } else {
    gcd(b, a % b)
  }
}

fn main() {
  input! {
    n: usize,
    ms: [isize;n]
  }

  let mut next = ms[0];
  for i in 1..n {
    next = gcd(next, ms[i]);
  }
  println!("{}", next);
}

Measured memory_bytes: 3628
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main(){
    int A,B;
    cin>>A>>B;
    cout<<6-A-B<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
 typedef long long ll;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;

 int main() {
   ll N, ans = 1;
   cin >> N;

   map<ll, ll> PF;

   for (ll i = 2; i <= N; i++) {
     ll tmp = i;
     if (tmp == 2 || tmp == 3) {
       PF[tmp]++;
       continue;
     }
     for (ll p = 2; p * p <= tmp; p++) {
         if (tmp % p != 0) continue;
         ll num = 0;
         while (tmp % p == 0) {
            tmp /= p;
            PF[p]++;
         }
     }
     if (tmp != 1) PF[tmp]++;
   }

   for (auto q : PF) {
     ans = ans * (q.second + 1) % MOD;
   }

   cout << ans << endl;
 }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int a[100005][4];
int dp[100005][4];
//int mx=INT_MIN;
int solve(int i,int f){
    if(i==n)return 0;
    if(dp[i][f]!=-1)return dp[i][f];
    int mx=INT_MIN;
    if(f==0){
        mx=max(mx,a[i][1]+solve(i+1,1));
        mx=max(mx,a[i][2]+solve(i+1,2));
        mx=max(mx,a[i][3]+solve(i+1,3));
    }
    else if(f==1){
        mx=max(mx,a[i][2]+solve(i+1,2));
        mx=max(mx,a[i][3]+solve(i+1,3));
    }
    else if(f==2){
        mx=max(mx,a[i][1]+solve(i+1,1));
        mx=max(mx,a[i][3]+solve(i+1,3));
    }
    else{
        mx=max(mx,a[i][1]+solve(i+1,1));
        mx=max(mx,a[i][2]+solve(i+1,2));
    }
    return dp[i][f]=mx;
}

int main(){
   //int n;
   cin>>n;
   //int a[n][3];
   for(int i=0;i<n;i++)
   for(int j=1;j<=3;j++)
       cin>>a[i][j];
       memset(dp,-1,sizeof(dp));
   cout<<solve(0,0);
}

Measured memory_bytes: 9600
fun main(args: Array<String>) {
    val S = next().map { it - '0' }
    fun count(d: Int) = S.withIndex().sumBy { if (it.index % 2 == d) it.value else 1 - it.value }
    println(Math.min(count(0), count(1)))
}
fun next() = readLine()!!

Measured memory_bytes: 38916
/*
Hanit Banga
*/

#include <iostream>
#include <vector>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false)

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

const int N = 1e5 + 5;

bool solve(int *a, int n);
int gcd(int x, int y);

int main()
{
	int n, a[N];
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i];

	if (solve(a, n))
		cout << "First\n";
	else
		cout << "Second\n";	
}

bool solve(int *a, int n)
{
	int odd = 0, even = 0;
	for (int i = 0; i < n; ++i)
	{
		if (a[i] % 2)
			++odd;
		else
			++even;
	}

	if (!even)
		return false;

	if (even % 2)
		return true;

	if (odd > 1)
		return false;

	int g = 0;
	for (int i = 0; i < n; ++i)
	{
		if (a[i] % 2)
		{
			if (a[i] == 1)
				return false;
			--a[i];	
		}

		g = gcd(g, a[i]);
	}

	for (int i = 0; i < n; ++i)
		a[i] /= g;

	return !solve(a, n);
}

int gcd(int x, int y)
{
	if (!y)
		return x;

	return gcd(y, x % y);
}

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

namespace Atcoder
{
    class Program
    {

        static void Main(string[] args)
        {
            var N = ReadInt();
            var r = ReadIntArray();
            for (int i = 0; i < N; i++)
            {
                if (r[i] % 2 == 0 &&
                    !(r[i] % 3 == 0 || r[i] % 5 == 0))
                {
                    Console.WriteLine("DENIED");
                    return;
                } 
            }

            Console.WriteLine("APPROVED");
        }
        private static readonly Func<string> Read = () => Console.ReadLine();
        private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split();
        private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine());
        private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine());
        private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
        private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
        private static readonly Action<string> Cw = str => Console.WriteLine(str);
    }
}

Measured memory_bytes: 13268
import java.util.Arrays;

public class Main {

  private static void solve() {
    char[] s = ns();
    int max = 0;
    
    for (char c : s) {
      max += c - '0';
    }

    for (int i = 0; i < s.length; i ++) {
      String t = new String(Arrays.copyOf(s, i + 1));
      long x = Long.parseLong(t.equals("") ? "0" : t);
      x -= 1;
      int now = 0;
      while (x > 0) {
        now += x % 10;
        x /= 10;
      }
      for (int j = i + 1; j < s.length; j ++) {
        now += 9;
      }
      max = Math.max(now, max);
    }
    System.out.println(max);
    
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = System.getProperty("debug");
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


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

int main ()
{
	int N;
	char S;
	bool flag=false;
	cin>>N;
	for(int i=0;i<N;++i){
		cin>>S;
	    if(S=='Y')
		{flag=true;}
	}
	if(flag){cout<<"Four"<<endl;}
	else{cout<<"Three"<<endl;}

	fflush(stdin);
	getchar();
	return 0;
}


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

using namespace std;

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

template <typename T>
int sz(T &x) {
  return (int)(x.size());
}

int power(int x, int y, int mod) {
  if (y == 0) {
    return 1;
  }
  int z = power(x, y >> 1, mod);
  z = z * 1ll * z % mod;
  if (y & 1) {
    z = z * 1ll * x % mod;
  }
  return z;
}

const int mod = 998244353;
const int inf = 1'000'000'007;

void solve() {

  int n;
  cin >> n;

  vector<int> x(n * n + 1, 0);
  vector<pii> e;

  for (int i = 1; i <= n; ++i) {
    int pos;
    cin >> pos;
    x[pos] = i;
    e.push_back(make_pair(pos, i - 1));
  }

  sort(e.begin(), e.end());

  int ptr = 1;
  for (auto &i : e) {
    while (i.second--) {
      while (ptr <= n * n && x[ptr]) {
        ++ptr;
      }
      if (ptr >= i.first) {
        cout << "No\n";
        return;
      }
      x[ptr] = x[i.first];
    }
  }

  for (auto &i : e) {
    i.second = n - x[i.first];
  }
  reverse(e.begin(), e.end());

  ptr = n * n;
  for (auto i : e) {
    while (i.second--) {
      while (ptr >= 1 && x[ptr]) {
        --ptr;
      }
      if (ptr <= i.first) {
        cout << "No\n";
        return;
      }
      x[ptr] = x[i.first];
    }
  }

  cout << "Yes\n";
  for (int i = 1; i <= n * n; ++i) {
    cout << x[i] << " ";
  }
  cout << "\n";

}

int main() {
  #ifndef LOCAL58
    // don't forget to remove if interactive
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
  #endif

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

  return 0;
}


Measured memory_bytes: 4296