akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map> 
#include <stack>
#include <sstream>
#include <set>
#pragma GCC optimize(2)

//#define int long long
#define mm(i,v) memset(i,v,sizeof i);
#define mp(a, b) make_pair(a, b)
#define pi acos(-1)
#define fi first
#define se second
//你冷静一点，确认思路再敲！！！ 

using namespace std;
typedef long long ll;
typedef pair<int, int > PII;
priority_queue< PII, vector<PII>, greater<PII> > que;
stringstream ssin; //  ssin << string   while ( ssin >> int)

const int N = 3e5 + 5, M = 2e5 + 5, mod = 1e9 + 9, INF = 0x3f3f3f3f;
char s[N];
int k, n, Max;
int a[N];

inline int read(){
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1; c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0'; c=getchar();}
    return x*f;
}

int main()
{
    cin >> k >> n;
    int Max = -1;
    for (int i = 1; i <= n; ++i) a[i] = read();
    for (int i = 2; i <= n; ++i) {
        int pos = a[i] - a[i - 1];
        Max = max(Max, pos);
    }
    Max = max(Max, a[1] + k - a[n]);
    cout << k - Max << endl;
    // system("pause");
    return 0;
}
/*
niuniu
1
abca
2
abcabc
2
*/

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

int main() {
  int n, c, k;
  cin >> n >> c >> k;

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

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

  int l = 0, ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (i - l >= c || t[i] - t[l] > k) {
      ans++;
      l = i;
    }
  }

  cout << ans << endl;
}


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

using namespace std;

struct node {
	int x, y;
} a[1100];
char ans[1100][41];
int n, now, D[40];

void solve(int x) {
	++now; D[now] = x;
	for(int i = 1; i <= n; i++) {
		if(abs(a[i].x) > abs(a[i].y)) {
			if(a[i].x > 0) ans[i][now] = 'R', a[i].x -= x; 
			else ans[i][now] = 'L', a[i].x += x;
		} else {
			if(a[i].y > 0) ans[i][now] = 'U', a[i].y -= x;
			else ans[i][now] = 'D', a[i].y += x;
		}
	}
}

int main() {
	cin>>n;
	for(int i = 1; i <= n; i++) cin>>a[i].x , cin>>a[i].y ;
	for(int i = 30; i >= 0; i--) solve(1 << i);
	if(a[1].x || a[1].y) solve(1);
	for(int i = 1; i <= n; i++) {
		if(a[i].x || a[i].y) {puts("-1"); return 0;}
	} printf("%d\n", now);
	for(int i = 1; i <= now; i++) printf("%d ", D[i]);
	printf("\n");
	for(int i = 1; i <= n; i++) printf("%s\n", ans[i] + 1);
	return 0;
}



Measured memory_bytes: 384
import scala.io.StdIn._

object Main extends App {

  val Array(n,m) = readLine().split(" ").map(_.toInt)
  val A = Array.fill(n)(readLine())
  val B = Array.fill(m)(readLine())

  def solve() = {
    val aLen = A.length
    val bLen = B.length
    val startPoints = for {
      i <- 0 to aLen-bLen
      j <- 0 to aLen-bLen
    } yield (i, j)

    val points = startPoints.map { case (i, j) =>
      for {
        c <- i until i+bLen
        l <- j until j+bLen
      } yield (c, l)
    }

    val isExist = points.exists { list =>
      val listB = for {
        i <- 0 until bLen
        j <- 0 until bLen
      } yield (i, j)
      list.zip(listB).forall { case ((cA,lA), (cB,lB)) =>
        A(cA)(lA) == B(cB)(lB)
      }
    }
    if(isExist) "Yes" else "No"
  }

  println(solve())

}



Measured memory_bytes: 73088
using System;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = Console.ReadLine();
            var l = a.Split(' ');
            var b = int.Parse(l[0]);
            var c = int.Parse(l[1]);
            int cnt = 0;
            var d = b;
            for (int i = 0; i < b; i++)
            {
                var e = d % c;

                if (b == 1)
                {
                    Console.WriteLine(1);
                    break;

                }
                if (e == 0 && d < c)
                {
                    Console.WriteLine(cnt);
                    break;


                }
                else
                {
                    d = d / c;
                    cnt += 1;
                }
            }
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mst(a,b) memset(a,b,sizeof(a))
#define lowbit(x) ((x)&(-x))
#define X first
#define Y second
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
typedef long long LL;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 200000+10;
const int maxm = 200000+10;
const int mod = 1e9+7;
const double eps = 1e-9;
int main() {
#ifdef local
    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,sum=0; cin>>n;
    int mn=inf;
    for (int i=0;i<n;i++){
        int x; cin>>x;
        sum+=x;
        if (x%10) {
            mn=min(mn,x);
        }
    }
    if (sum%10) cout<<sum<<"\n"; else {
        if (mn<inf) cout<<sum-mn<<"\n"; else cout<<0<<"\n";
    }
    return 0;
}


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

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

long long lcm(long long a, long long b) {
    long long g = gcd(a, b);
    return a / g * b;
}

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

    long long ans = 1;
    for (int i = 0; i < n; i++) {
        long long t;
        cin >> t;
        ans = lcm(ans, t);
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    a = root(a);
    return -Parent[a];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(a < b) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }

  bool issame(int a, int b){
    return root(a) == root(b);
  }
};

int main(){
  int n; cin >> n;
  vl a(n); rep(i,n) cin >> a[i];

  int cnt = 0;
  rep(i,n) {
    if(a[i]%2) cnt++;
  }

  cout << (cnt%2 ? "NO" : "YES")  << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <stdio.h>
using namespace std;
#define ll long long


int main() {
	ll n, a[100010];
	ll hoge = 0;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) {
		hoge = hoge ^ a[i];
	}
	if (hoge == 0)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int w,h;
    
    while(1){
        scanf("%d %d",&w,&h);
        
        if(w==0&&h==0){
            break;
        }
        for(int y=1;y<=w;y++){
            for(int x=1;x<=h;x++){
                if(x==1 || x==h || y==1 || y==w){
                    printf("#");
                }else{
                    printf(".");

                }
            }
            printf("\n");
            
        }
        
        printf("\n");
        
    }
    return 0;
}



Measured memory_bytes: 2032
from heapq import heappop, heapify, heappush
from collections import defaultdict
N, M = map(int,input().split())
d = defaultdict(list)
for i in range(N):
    a, b = map(int, input().split())
    d[a].append(b)
h = []
ans = 0
for i in range(1, M+1):
    if len(d[i]) != 0:
        for x in d[i]:
            heappush(h, -x)
    if len(h) != 0:
        ans -= heappop(h)
print(ans)


Measured memory_bytes: 31948
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll get(ll x)
{
    return x*x*x*x*x;
}
int main()
{
    ll x;
    cin >>x;
    for(ll i=-500;i<=500;i++)
    {
        int flag=0;
        for(ll j=-500;j<=500;j++)
        {
            if(get(i)-get(j)==x)
            {
                flag=1;
                cout <<i<<" "<<j<<endl;
                break;
            }
        }
        if(flag) break;
    }
}


Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;

long long int dp[101][5][5][5];

int main() {
  int n; cin >> n;
  dp[0][4][4][4] = 1;// ttt
  for(int i=0; i<n; i++) {
    for(int a=0; a<5; a++) {
      for(int b=0; b<5; b++) {
        for(int c=0; c<5; c++) {
          for(int d=0; d<4; d++) {
            if(b == 0 && c == 1 && d == 2) continue;
            if(b == 0 && c == 2 && d == 1) continue;
            if(b == 1 && c == 0 && d == 2) continue;
            if(a == 0 && b == 1 && d == 2) continue;
            if(a == 0 && c == 1 && d == 2) continue;
            dp[i+1][b][c][d] += dp[i][a][b][c]%mod;
            dp[i+1][b][c][d] %= mod;
          }
        }
      }
    }
  }

  long long int cnt = 0;
  for(int a=0; a<5; a++) {
    for(int b=0; b<5; b++) {
      for(int c=0; c<5; c++) {
        cnt += dp[n][a][b][c];
        cnt %= mod;
      }
    }
  }
  cout << cnt << endl;

  return 0;
}


//EOF


Measured memory_bytes: 384
n,m=map(int,input().split())
L=list(map(int,input().split()))
LL=sorted(L)[::-1]
cnt=0
for i in range(n):
  if LL[i]>=sum(L)/(4*m):
    cnt=cnt+1
if cnt>=m:
  print('Yes')
else:
  print('No')  
  

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;



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

	ll N,K;
	cin >> N >> K;

	vector<ll> H(N);
	rep(i, N) {
		cin >> H[i];
	}

	sort(H.begin(), H.end(), greater<ll>());

	ll sum = 0;
	if (N <= K) {
		cout << 0 << endl;
		return 0;
	}
	repk(i,K,N) {
		sum += H[i];
	}


	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <queue>

using namespace std;
typedef long long ll;

int main(void) {
	int num, k, i, a, b;
	ll ans = 0;
	priority_queue<int> que;
	cin >> num;
	for (i = 0; i < num; i++) {
		scanf("%d%d", &a, &b);
		ans -= b;
		que.push(a + b);
	}
	for (i = 0; i < (num >> 1) + (num & 1); i++) {
		ans += que.top();
		que.pop();
		if(!que.empty())
			que.pop();
	}
	cout << ans << "\n";
	return 0;
}

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

int main(){

    while(1){

        long long n; cin >> n;
        if(!n) break;
        vector<long long> a(n);
        long long sum = 0LL;
        for(int i = 0; i < n; i++){
            cin >> a[i];
            sum += a[i];
        }

        long long ans = 0LL;
        for(int i = 0; i < n; i++){

            if(sum >= a[i] * n) ans++;
        }

        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3156
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    string n;
    cin >> n;
    for(size_t i=0;i<n.size(); i++)
    {
        if(n[i]=='1') cout << 9;
        else cout << 1;
    }
    cout << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

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

typedef long long LL;
typedef pair<int, int> II;
struct Souvenir {
    int L, R;
    bool operator < (const Souvenir &S) const {
        return R < S.R;
    }
};

const int N = (int) 3e5 + 10;
int n, m, ans[N]; Souvenir S[N];
int ft[N]; vector<int> D[N];

void Update(int i) {
    while (i <= m) {
        ft[i]++;
        i += i & -i;
    }
}

int Query(int i) {
    int ans = 0;
    while (i) {
        ans += ft[i];
        i -= i & -i;
    }
    return ans;
}

int main() {
    #ifdef LOCAL
        freopen("Data.inp", "r", stdin);
        freopen("Data.out", "w", stdout);
    #endif

    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i) scanf("%d%d", &S[i].L, &S[i].R);

    sort(S + 1, S + 1 + n);
    for (int i = 1; i <= m; ++i)
        for (int j = i; j <= m; j += i)
            D[j].push_back(i);

    for (int i = 1; i <= m; ++i) ans[i] = 0;
    for (int k = m, p = n + 1; k >= 1; --k) {
        while (p > 1 && S[p - 1].R >= k) {
            p--;
            Update(S[p].L);
        }
        for (int i = 0; i < (int) D[k].size(); ++i) {
            int x = D[k][i];
            ans[x] += Query(k) - Query(k - x);
        }
    }

    for (int i = 1; i <= m; ++i) printf("%d\n", ans[i]);
    return 0;
}


Measured memory_bytes: 19072
#include <stdio.h>
int main(void){
    int a[4][3][10] = {0};
    int n,b,f,r,v,i,j,k;
    scanf("%d\n",&n);
    
    for (i = 0;i<n;i++){
        scanf("%d %d %d %d\n",&b,&f,&r,&v);
        a[b-1][f-1][r-1] += v;
    }
    for (i = 0;i<4;i++){
        for(j = 0;j<3;j++){
            for (k = 0;k<10;k++){
                printf(" %d",a[i][j][k]);
            }
            printf("\n");
        }
        if (i != 3){
        printf("####################\n");
    }
    }
    return 0;
}


Measured memory_bytes: 2036
#include<bits/stdc++.h>
using namespace std;
#define int long long int
const int N = 1e+6;
const int mod = 1000000007;

int32_t main()
{
	int n,k;
	cin>>n>>k;

	vector<int> v(n);

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

	vector<bool> dp(k+1,false);

	for(int i=1;i<=k;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(v[j]<=i)
			{
				if(!dp[i-v[j]])
				{
					dp[i] = true;
				}
			}
		}
	}

	if(dp[k])
	{
		cout<<"First"<<endl;
	}
	else
	{
		cout<<"Second"<<endl;
	}
}

Measured memory_bytes: 256
n,k=map(int,input().split())
d=[0]*n
s=[0]*n

if k !=0:
    for i in range(k):
        p=int(input())
        d[p-1]=1

if n==1:
    print(1)
    exit()

 
if d[0]==1:
    s[0]=0
else:
    s[0]=1
 
if d[1]==1:
    s[1]=0
else:
    s[1]= s[0]+1
 
 
for i in range(2,n):
    if d[i]==1:
        s[i]=0
    else:
        s[i]=(s[i-1]+s[i-2])%1000000007
 
print( s[n-1] % 1000000007)


Measured memory_bytes: 46536
# Equal Total Scores

ans = []

while True:
    flag = False
    n, m = map(int, input().split())
    if n == 0 and m == 0:
        break
    s = [int(input()) for i in range(n)]
    t = [int(input()) for i in range(m)]

    sum_s = sum(s)
    sum_t = sum(t)

    for i in range(n):
        for j in range(m):
            #print("sum_s = {}, s[i] = {}, t[j] = {}".format(sum_s, s[i], t[j]))
            if (sum_s - s[i] + t[j]) == (sum_t - t[j] + s[i]):
                flag = True
                ans.append([s[i], t[j]])
                break
        if flag:
            break

    if not flag:
        ans.append([-1, -1])

for i in ans:
    if -1 in i:
        print(-1)
    else:
        print("{} {}".format(i[0], i[1]))



Measured memory_bytes: 5604
def solve(N, A):
    ret = 1
    upper = 10**18
    if 0 in A:
      return 0
    for i in A:
        ret *= i
        if upper < ret:
          return -1
    return ret
 
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    print(solve(N, A))

Measured memory_bytes: 21644
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 ln             PIC X(30).
01 S              PIC 9(10).
01 W              PIC 9(10).

PROCEDURE DIVISION.
  ACCEPT ln.
  UNSTRING ln DELIMITED BY SPACE INTO S W.
  IF W < S
      DISPLAY "safe"
  ELSE
      DISPLAY "unsafe"
  END-IF.
  STOP RUN.


Measured memory_bytes: 3732
#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
#define int long long
using namespace std;
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	cout<<(n-1)*n/2<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int count=sc.nextInt();
		for(int i=0;i<count;i++){
			BigInteger a=sc.nextBigInteger();
			BigInteger b=sc.nextBigInteger();
			BigInteger ans=a.add(b);
			System.out.println(80<ans.toString().length() ? "overflow" : ans.toString());
		}
	}
}

Measured memory_bytes: 18748
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1000003 ;

int m[100010];

int main(){
  int n;
  cin >> n;
  int x=0;
  vector<int> v(n);
  rep(i,n){
    cin >> v[i];
    x=max(x,v[i]);
    m[v[i]]++;
  }
  int small=inf;
  int large=0;
  int sum=0;
  int var=0;
  rep(i,x+1){
    if(m[i]>0)var++;
    if(m[i]>=2){
      sum+=m[i]-1;
    }
  }
  if(sum%2==0)cout << var << endl;
  else cout << var-1 << endl;
return 0;}

Measured memory_bytes: 1024
/*
digu_J - Digvijay Janartha
NIT Hamirpur - INDIA
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")

using namespace std;
using namespace __gnu_pbds;

template < typename T > using ordered_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifdef HOME
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    int len = comma - names;
    for (int i = 0; i < len; ++i) {
        cout << names[i];
    }
    cout <<  " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef vector < ll > vll;
typedef vector < int > vi;
typedef complex < double > com;

#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll LINF = LLONG_MAX, base = 1e9, MOD = 1e9 + 7, N = 1e5 + 5, M = 1e3 + 5, LG = 20;
const int INF = INT_MAX;
const db PI = acos(-1), EPS = 1 / db(1e6);
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());

bool is_prime(ll a) {
    if (a < 2) {
        return false;
    } else if (a == 2) {
        return true;
    }
    if (a % 2 == 0) {
        return false;
    }
    for (ll i = 3; i <= sqrt(a); i += 2) {
        if (a % i == 0) {
            return false;
        }
    }
    return true;
}

void test() {
    ll a, b;
    cin >> a >> b;
    vll div;
    for (ll i = 1; i <= sqrt(a); ++i) {
        if (a % i == 0) {
            if (b % i == 0) {
                div.eb(i);
            }
            if (a % (a / i) == 0 and b % (a / i) == 0) {
                div.eb(a / i);
            }
        }
    }
    unique_sort(div);
    vll ans;
    ans.eb(1);
    for (auto &x: div) {
        if (is_prime(x)) {
            ans.eb(x);
        }
    }
    cout << ans.size() << "\n";
}

int main() {
    fast_io();
    #ifdef HOME
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    cout << fixed << setprecision(15);
    test();
    #ifdef HOME
        cout << "Time: " << (int)(clock() * 1000. / CLOCKS_PER_SEC) << "ms";
    #endif
    return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)

typedef long long ll;

class Edge;
class Node {
 public:
  list<Edge *> con_edges;
  // vector<Node *> con_nodes;
};

class Edge {
 public:
  Node *a;
  Node *b;
  int color;

  Node *GetOther(Node *n) {
    if (n != a) return a;
    return b;
  }
};

Edge *EDGE_NIL;

void Paint(Node *node, Edge *parent_edge) {
  int color = 1;
  for (auto itr = node->con_edges.begin(); itr != node->con_edges.end();
       itr++) {
    if (*itr == parent_edge) {
      continue;
    }

    // color
    if (parent_edge != EDGE_NIL) {
      if (parent_edge->color == color) color += 1;
    }
    (*itr)->color = color;
    color++;

    Node *child = (*itr)->GetOther(node);
    Paint(child, *itr);
  }
}

int main() {
  int n;
  cin >> n;
  vector<Node> nodes(n);
  vector<Edge> edges(n - 1);
  FOR(i, 0, n - 1) {
    int a, b;
    cin >> a >> b;
    edges[i].a = &nodes[a - 1];
    edges[i].b = &nodes[b - 1];
    nodes[a - 1].con_edges.push_back(&edges[i]);
    nodes[b - 1].con_edges.push_back(&edges[i]);
  }
  int k = 0;
  FOR(i, 0, n) { k = max(k, (int)nodes[i].con_edges.size()); }

  Node *root = &nodes[0];
  Paint(root, EDGE_NIL);
  cout << k << endl;
  FOR(i, 0, n - 1) { cout << edges[i].color << endl; }
  return 0;
}

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

typedef long long ll;

#define pb push_back
#define mkp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define clr(a, b) memset(a, b, sizeof(a))
#define forn(i, n) for(int i=0; i<(int)(n); ++i)
#define forab(i, a, b) for(int i=(int)(a); i<=(int)(b); ++i)
#define FOR(it,c) for ( __typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++ )
const int cm = 1<<17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha(){
	if(ci-cn == cm){ fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
 
inline int getint(){
	int A = 0;
	if(ci-cn+16 > cm) while((ct=getcha()) >= '0') A = A*10 + ct - '0';
	else while ((ct=*ci++) >= '0') A = A*10 + ct - '0';
	return A;
}
 
const int dm = 1<<20;
char dn[dm], *di = dn;
inline void putint(int x){
	char c[10];
	int d; for(d=0; x; d++, x/=10) c[d] = x%10 + '0';
	for(int i=d-1; i>=0; --i) *di++ = c[i];
	*di++ = '\n';
}


const int N = 1e5 + 5;

vector<int> adj[N];
int visit[N];
int res;

map<pair<int, int>, int> mp;

void dfs(int n, int p) {
      if(visit[n])
          return;
      visit[n] = 1;
      int co = 0;
      for(int x: adj[n]) {
          if(visit[x]) continue;
          ++co;
          if(p == co) 
              ++co;
          if(co > res)
              co = 1;
          mp[{n, x}] = co;
          mp[{x, n}] = co;
          dfs(x, co);
      }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef LOCAL
    clock_t tStart = clock();
#endif
    int n = getint();
    vector<pair<int, int>> v;
    forn(i, n-1) {
        int x = getint(), y = getint();
        adj[x].pb(y);
        adj[y].pb(x);
        v.pb({x, y});
    }
    forab(i, 1, n)
        res = max(res, (int)adj[i].size());
    dfs(1, 0);
    putint(res);
    for(auto p: v) {
        putint(mp[{p.first, p.second}]);
    }
                  
	fwrite(dn, 1, di - dn, stdout);
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * (clock() - tStart)/ CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}



Measured memory_bytes: 20988
from collections import Counter

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def support(n):
    counter = 0
    temp = 1
    while n - temp >= 0:
        n -= temp
        temp += 1
        counter += 1
    return counter

def main():
    n = int(input())
    factors_counter = Counter(prime_factorize(n))
    answer = 0
    for factor in factors_counter.keys():
        factor_count =factors_counter[factor]
        answer += support(factor_count)
    print(answer)





if __name__ == '__main__':
    main()


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

template<typename T>
void fin (T a){
    cout<<a<<endl;
    exit(0);
}

template<typename S>
void print(S a){
    cout<<a<<endl;
}


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

    int n;cin>>n;
    int ans=0;
    while(ans<n){
        ans+=1000;
    }
    fin(ans-n);



}




Measured memory_bytes: 3660
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

string W[7] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};

int main(){
    string S;
    cin >> S;
    for(int i=0;i<7;i++){
        if(W[i]==S){
            cout << 7-i << endl;
        }
    }
}

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

typedef long long ll;

template<class T> inline void chmax(T &a, T b) {if(a < b) a = b;}

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

    ll n;
    cin >> n;
    ll a[100100][3];
    for(int i=1;i<=n;i++) for(int j=0;j<3;j++) cin >> a[i][j];
    ll dp[100100][3];
    for(int i=0;i<100100;i++) for(int j=0;j<3;j++) dp[i][j] = 0;
    for(int i=1;i<=n;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(j!=k) chmax(dp[i+1][k],dp[i][j]+a[i][k]);
            }
        }
    }
    ll ans = max(dp[n+1][0],max(dp[n+1][1],dp[n+1][2]));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define pi 3.14159265358979323846264338327950L
using namespace std;

int main() {
  int64_t N, A, B, ans;
  cin >> N >> A >> B;
  if (A%2==B%2) {
    ans=(B-A)/2;
  }
  else {
    ans=min((A-1),(N-B))+1+(B-A-1)/2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3640
//PDF解説に倣って
#include<bits/stdc++.h>
using namespace std;

int main(){
  int n,m=1e9+7;
  cin>> n;
  vector<int64_t> a(n);
  for (int i=0; i<n; i++) cin>> a[i];
  
  vector<int> one(60);
  for (int i=0; i<n; i++){
    bitset<60> bs(a[i]);
    for (int j=0; j<60; j++){
      one[j]+=bs[j];
    }
  }
  int64_t ans=0;
  for (int i=0; i<60; i++){
    int64_t var=(int64_t)pow(2,i)%m;
    var=(var*one[i])%m;
    var=(var*(n-one[i]))%m;
    ans=(ans+var)%m;
  }
  cout<< ans << endl;
}

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

int main() {
	string str;
	cin >> str;
	if(str.find('N') == string::npos){
		if(str.find('S') != string::npos){
			cout << "No" << endl;
			return 0;
		}
	}
	else
		if(str.find('S') == string::npos){
			cout << "No" << endl;
			return 0;
		}
		
	if(str.find('W') == string::npos){
		if(str.find('E') != string::npos){
			cout << "No" << endl;
			return 0;
		}
	}
	else
		if(str.find('E') == string::npos){
			cout << "No" << endl;
			return 0;
		}
		
	cout << "Yes" << endl;	
	return 0;
}

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

int main(){
    int a;
    vector<int> A;
    while(cin >> a){
      A.push_back(a);
        if(a==0) break;
    }
    
    for(int i=1;i<A.size();i++){
        cout << "Case " << i << ": " << A[i-1] << endl;
    }
    return 0;
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    string X; cin >> X;
    stack<char> stk;
    REP(i,X.size()) {
        if (!stk.empty() && stk.top() == 'S' && X[i] == 'T') stk.pop();
        else stk.push(X[i]);
    }

    OUT(stk.size())

    return 0;
}

Measured memory_bytes: 720
import sys
for i in sys.stdin:
    a,b=map(int,i.split())
    if a<b:a,b=b,a
    def gcd(x,y):
        while y>0:x,y=y,x%y
        return x
    def lcm(x,y):
         return x*y/gcd(x,y)
    print(gcd(a,b),int(lcm(a,b)))

Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}


vector<vector<int> > G;

vector<bool> visited;

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N,M;cin >> N >> M;
  G = vector<vector<int > >(3*N);
  visited = vector<bool>(3*N,false);
  rep(i,M){
    int from,to;cin >> from >> to;
    from--;to--;
    G[from].push_back(to+N);
    G[from+N].push_back(to+2*N);
    G[from+2*N].push_back(to);
  }
  int S,T;cin >> S >> T;
  S--;T--;

  queue<PII> que;
  que.push(PII(S,0));
  visited[S] = true;
  while(!que.empty()){
    int cur = que.front().first;
    int n = que.front().second;
    if(cur == T){
      cout << n/3 << endl;
      return 0;
    }
    que.pop();
    rep(i,G[cur].size()){
      if(visited[G[cur][i]])continue;
      visited[G[cur][i]]=true;
      que.push(PII(G[cur][i],n+1));
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 17276
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define gc getchar
struct node{
	double x,y;
}a,b,c,d;
node operator - (node a,node b)
{
	return (node){a.x-b.x,a.y-b.y};
}
double DJ(node a,node b)
{
	return a.x*b.x+a.y*b.y;
}
double CJ(node a,node b)
{
	return a.x*b.y-a.y*b.x;
}
double len(node a)
{
	return a.x*a.x+a.y*a.y;
}
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
inline int read()
{
    int ret=0,f=0;char c=gc();
    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
    if(f)return -ret;return ret;
}
bool chk(node c,node a,node b)
{
	int x=CJ(b-a,c-a);
	if(x>0)return 0;
	if(x<0)return 0;
	int y=DJ(b-a,c-a);
	if(y<0)return 0;
	double ma=max(len(c-a),len(c-b));
	if(ma>len(b-a))return 0;
	if(ma<=len(b-a))return 1;
}
bool pd(node a,node b,node c,node d)
{
	if(chk(a,c,d))return 1;
	if(chk(b,c,d))return 1;
	if(chk(c,a,b))return 1;
	if(chk(d,a,b))return 1;
	double A=CJ(d-a,b-a),B=CJ(c-a,b-a);
	if(A*B>=0)return 0;
	A=CJ(a-c,d-c),B=CJ(b-c,d-c);
	if(A*B>=0)return 0;
	return 1;	
}
signed main()
{
	int n=read();
	while(n--)
	{
		a=(node){read(),read()};
		b=(node){read(),read()};
		c=(node){read(),read()};
		d=(node){read(),read()};
		if(pd(a,b,c,d))puts("1");
		else puts("0");
	}
	return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(void) {
  int N, x;
  cin >> N >> x;
  vector<ll> a(N);
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    sum += a[i];
  }
  if (sum == x) {
    cout << N << endl;
    return 0;
  }
  sort(a.begin(), a.end());
  ll ans = 0;
  ll subs = 0;
  for (int i = 0; i < N; i++) {
    subs += a[i];
    if (subs <= x) {
      ans = i + 1;
    }
  }
  if (ans == N) ans--;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
#define ll         long long int
#define co         cout
#define ci         cin
#define sf1(n)     scanf("%lld",&n)
#define sf2(n,m)   scanf("%lld %lld",&n,&m);
#define sf3(n,m,p) scanf("%lld %lld %lld",&n,&m,&p);
#define pf1(n)     printf("%lld\n",n);
#define en         cout<<endl;
#define pb         push_back
#define fi         first
#define se         second
#define coy        cout<< "YES"<<endl;
#define con        cout<< "NO"<<endl;
#define f(a,b)     for(ll i=a;i<b;i++)
#define pi         pair<ll,ll>
#define br         break;
#define i64        long long

ll vis[150],a[150];

int main()
{
    ll t,n,g,k,m,mx=0,mn=1e9,c,res,c1,x,y,w,z,c2;
    ci>>x>>n;
    for(ll i=1;i<=n;i++) ci>>a[i],vis[a[i]]=1;
    if(vis[x]==0||n==0)
    {
        co<<x;
        return 0;
    }
    for(ll i=x;i<102;i++)
    {
        if(vis[i]==0)
        {
            c=i;
            br
        }
    }
    for(ll i=x;i>=0;i--)
    {
        if(vis[i]==0)
        {
            y=i;
            br
        }
    }
    w=abs(c-x);
    z=abs(y-x);
    if(w<z) res=c;
    else if(w>z) res=y;
    else res=min(c,y);
    co<<res;
}


Measured memory_bytes: 3640
#require 'prime'
#require 'openssl'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+).to_i end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n=gi
a=gsmi
a.each do |i|
  h[i]+=1
end

1.upto (n) do |i|
  puts h[i]
end

Measured memory_bytes: 41104
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i > 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  ll p = 1;
  for (int i = 1; i <= n; i++) {
    p *= i;
    p %= 1000000007;
  }
  cout << p << endl;
  return 0;
}

Measured memory_bytes: 256
n,w=map(int,input().split())
INF=float('inf')
P=[]
for _ in range(n):
  iw,iv=map(int,input().split())
  P.append([iw,iv])

dp=[[INF for i in range(10**5+1)] for j in range(n+1)]
dp[0][0]=0
for i in range(1,n+1):
  for j in range(10**5+1):
    if j-P[i-1][1]>=0:
      dp[i][j]=min(dp[i-1][j],dp[i-1][j-P[i-1][1]]+P[i-1][0])
    else:
      dp[i][j]=dp[i-1][j]
      
ans=10**5
while dp[n][ans]>w:
  ans-=1
print(ans)

Measured memory_bytes: 243344
N=int(input())
c_dict={}
c=0
for i in range(N):
  s=sorted(input())
  s=''.join(s)
  if s in c_dict.keys():
    c_dict[s]+=1
    c+=c_dict[s]-1
  else:
    c_dict[s]=1
print(c)

Measured memory_bytes: 17848
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    // Write Your Code Below
    ll n;
    cin >> n;
    vector<ll> a(2*n);
    rep(i,2*n) {
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    ll sum =0;
    ll l;
    rep(i,2*n) {
        if(i % 2 == 0){
            l = a[i];
        }else{
            if(a[i] >= l) {
            sum += l;
            }else {
            sum += a[i];
            }
        }
    }
    cout << sum << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int MOD;
struct Mint {
	int val;
	Mint() { val = 0; }
	Mint(const ll& x) {
		val = (-MOD <= x && x < MOD) ? x : x % MOD;
		if (val < 0) val += MOD;
	}
	friend bool operator==(const Mint& a, const Mint& b) { return a.val == b.val; }
	friend bool operator!=(const Mint& a, const Mint& b) { return !(a == b); }
	friend bool operator<(const Mint& a, const Mint& b) { return a.val < b.val; }
	Mint& operator+=(const Mint& m) { if ((val += m.val) >= MOD) val -= MOD; return *this; }
	Mint& operator-=(const Mint& m) { if ((val -= m.val) < 0) val += MOD; return *this; }
	Mint& operator*=(const Mint& m) { val = (ll)val * m.val % MOD; return *this; }
	friend Mint modex(Mint a, ll p) {
		assert(p >= 0);
		Mint ans = 1;
		for (; p; p >>= 1, a *= a) if (p & 1) ans *= a;
		return ans;
	}
	Mint& operator/=(const Mint& m) { return *this *= modex(m, MOD - 2); }
	Mint& operator++() { return *this += 1; }
	Mint& operator--() { return *this -= 1; }
	Mint operator++(int) { Mint result(*this); *this += 1; return result; }
	Mint operator--(int) { Mint result(*this); *this -= 1; return result; }
	Mint operator-() const { return Mint(-val); }
	friend Mint operator+(Mint a, const Mint& b) { return a += b; }
	friend Mint operator-(Mint a, const Mint& b) { return a -= b; }
	friend Mint operator*(Mint a, const Mint& b) { return a *= b; }
	friend Mint operator/(Mint a, const Mint& b) { return a /= b; }
	friend ostream& operator<<(ostream& os, const Mint& x) { return os << x.val; }
};
int main() {
	int n;
	scanf("%d%d", &n, &MOD);
	int k = (n - 1) / 2;
	vector<Mint> dp(n + 1);
	dp[0] = 1;
	for (int i = 2; i <= n; ++i) {
		int c;
		if (i <= k + 2) c = i - 1;
		else c = n - i + 2;
		for (int j = 0; j <= n; ++j) {
			if (j >= c) dp[j] += dp[j - c];
		}
	}
	Mint ans = 0;
	for (int j = 0; j <= n; ++j) {
		ans += dp[j] * (n - j);
	}
	printf("%d\n", ans.val);
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String [] args)throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        int cnt = 0;
        for(int i = 0;i < str.length();i++){
            if((i & 1) == 0){
                if(str.charAt(i) == 'p')--cnt;
            }
            if((i & 1) == 1){
                if(str.charAt(i) == 'g')++cnt;
            }
        }
System.out.print(cnt);
    }
}

Measured memory_bytes: 10956
#include<stdio.h>

// input(a,b) 
// output(x,y) ax+by=gcd(a,b)
template <typename T>
void extendedEuclidAlgo(T a,T b,T& x,T &y) {
    T a0,a1,a2;
    T b0,b1,b2;
    T q1;
    T r0,r1,r2;

    a0 = 1;
    b0 = 0;
    a1 = 0;
    b1 = 1;

    r0 = a;
    r1 = b;

    while(r1 != 0) {
        r2 = r0 % r1;
        q1 = r0 / r1;
        a2 = a0 - q1 * a1;
        b2 = b0 - q1 * b1;

        r0 = r1;
        r1 = r2;

        a0 = a1;
        a1 = a2;
        b0 = b1;
        b1 = b2;
    }

    x = a0;
    y = b0;


}


int main() {
    int a,b;
    int x,y;

    scanf("%d %d",&a,&b);
    extendedEuclidAlgo(a,b,x,y);
    printf("%d %d\n",x,y);


    return 0;

}

Measured memory_bytes: 1024
//
#include<stdio.h>
int a[100][100];
int flag;
int n,m;
int s[10000];
int dfs(int x,int y){
	if(x==y){
		flag++;
		return 0;
	}
	for(int i=1;i<=n;i++){
		if(s[i]==0&&a[x][i]==1){
			s[i]=1;
			dfs(i,y);
			s[i]=0;
		}
	}
}
int main(){
	
	scanf("%d %d",&n,&m);
	int x,y;
	for(int i=0;i<m;i++){
		scanf("%d %d",&x,&y);
		a[x][y]=a[y][x]=1;
	}
	int sum=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(a[i][j]==1){
				flag=0;
				s[i]=1;
				dfs(i,j);
				s[i]=0;
				if(flag==1)
				sum+=flag;
			}
		}
	}
	printf("%d",sum/2);
} 

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define P 31
using namespace std;
vector<int> p;
int ans;

void rot(int x,int y,int z){
  for(int i=0;i<3;i++)swap(p[x],p[x+z]),x+=y;
}

void rota(){
  rot(1,3,23);
  swap(p[10],p[21]);
  swap(p[16],p[18]);
}

void rotb(){
  rot(3,3,19);
  swap(p[12],p[19]);
  swap(p[13],p[15]);
}

void rotc(){
  rot(1,1,27);
  swap(p[19],p[21]);
  swap(p[15],p[16]);
}

void rotd(){
  rot(7,1,15);
  swap(p[13],p[18]);
  swap(p[10],p[12]);
}

bool check(){
  for(int i=1;i<9;i++)
    if(p[i]!=p[i+1])return false;
  for(int i=10;i<12;i++)
    if(p[i]!=p[i+1])return false;
  for(int i=13;i<15;i++)
    if(p[i]!=p[i+1])return false;
  for(int i=16;i<18;i++)
    if(p[i]!=p[i+1])return false;
  for(int i=19;i<21;i++)
    if(p[i]!=p[i+1])return false;
  for(int i=22;i<30;i++)
    if(p[i]!=p[i+1])return false;
  return true;
}

void dfs(int d){
  if(check())ans=min(ans,d);
  if(d==8)return ;
  rota();
  dfs(d+1);
  rota();
  rotb();
  dfs(d+1);
  rotb();
  rotc();
  dfs(d+1);
  rotc();
  rotd();
  dfs(d+1);
  rotd();
}

int main(){
  int n,a;
  cin>>n;
  while(n--){
    p.push_back(-1);
    for(int i=1;i<P;i++)cin>>a,p.push_back(a);
    ans=(1e9);
    dfs(0);
    cout<<ans<<endl;
    p.clear();
  }
  return 0;
}

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

int main()
{
  long long int N,ans=1;
  cin>>N;
  for(int i=1;i<=N;i++){
  ans*=i;
  ans%=1000000007;
  }
  cout<< ans <<endl;
}



Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<locale.h>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long int ll;
 
int main()
{
 string s;
 cin>>s;
 int ans=0;
 if(s[0]=='1'){ans++;}
 if(s[1]=='1'){ans++;}
 if(s[2]=='1'){ans++;}
 printf("%d",ans);
} 

Measured memory_bytes: 3692
#include <stdio.h>
#include <stdlib.h>

int Search(int,int);
int *arrayS,*arrayT;

int N,M;

int main(){
  int count=0,S;
  int i;
  scanf("%d",&N);
  arrayS = (int *)malloc(sizeof(int) * N);
  for(i=0;i<N;i++){
    scanf("%d",&arrayS[i]);
  }
  scanf("%d",&M);
  arrayT = (int *)malloc(sizeof(int) * M);
  for(i=0;i<M;i++){
    scanf("%d",&arrayT[i]);
    S=Search(0,arrayT[i]);
    if(S==1){
      printf("yes\n");
    }
  else printf("no\n");
  }
  free(arrayS);
  free(arrayT);
  return 0;
}

int Search(int i,int key){
  int res;
if(key == 0) return 1;
if(i >= N) return 0;
res = Search(i+1,key) || Search(i+1,key-arrayS[i]);
return res;
}

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

a = [list(map(int,input().split())) for x in range(n)]

b = [int(input()) for x in range(m)]


for x in range(n):
	c = 0
	for y in range(m):
		c += a[x][y]*b[y]
	print(c) 


Measured memory_bytes: 6016
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**7)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
PI = math.pi
# endregion
x1, y1, x2, y2 = ri_()
print(x2 - (y2 - y1), y2 + (x2 - x1), x1 - (y2 - y1), y1 + (x2 - x1))

Measured memory_bytes: 65132
#include <stdio.h>
#include <cstdlib>
#include <cassert>
#include <iostream>
#include <set>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <map>
#include <queue>
#include <array>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<pii> vii;
typedef vector<string> vs;

void out(vi v) {
  for (auto x : v) cerr << x << ' ';
  cerr << endl;
}

int main() {
  int n, m, q;
  cin >> n >> m >> q;
  vi a(q);
  for (int i = 0; i < q; ++i) {
    cin >> a[i];
    --a[i];
  }
  vi was(m), ord;
  for (int i = a.size() - 1; i >= 0; --i) {
    if (!was[a[i]]) ord.push_back(a[i]);
    ++was[a[i]];
  }
  for (int i = 0; i < m; ++i) {
    if (!was[i]) ord.push_back(i);
    ++was[i];
  }
//  out(ord);
  bool ok = ord.size() == m;
  for (int i = 0; i < ord.size(); ++i) if (ord[i] != i) ok = 0;
  if (ok) {
    printf("Yes\n");
    return 0;
  }
  vi c(ord.size()), pos(m);
  for (int i = 0; i < ord.size(); ++i) pos[ord[i]] = i;
  for (int i = a.size() - 1; i >= 0; --i) {
    int x = pos[a[i]];
    if (x == 0) {
      ++c[0];
    } else {
      c[x] = min(c[x] + 1, c[x-1]);
    }
  }
//  out(c);
  for (int i = 0; i < m; ++i) {
    int x = pos[i];
    if (x == 0) {
      c[0] = n;
    } else {
      c[x] = max(c[x], c[x-1]);
    }
  }
//  out(c);
  for (int i = 0; i < c.size(); ++i) if (c[i] < n) {
    printf("No\n");
    return 0;
  }
  printf("Yes\n");
  return 0;
}

Measured memory_bytes: 2296