akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<queue>
using namespace std;
#define rep(i, n) for ( int i = 0; i < n; i++)
#define mp(a, b) make_pair(a, b)
typedef pair<pair<int, int>, int> State;

static const int MAX = 60;
static const int N =  2*MAX+1;
static const int dx[6] = {1, 1, 0, -1, -1, 0};
static const int dy[6] = {0, 1, 1, 0, -1, -1};
main(){
  bool O[N][N];
  int t, n, x, y, sx, sy;
  while(1){
    cin >> t >> n;
    if ( t == 0 && n == 0 ) break;
    rep(i, N) rep(j, N) O[i][j] = false;
    rep(i, n){
      cin >> x >> y;
      O[x+MAX][y+MAX] = true;
    }
    cin >> sx >> sy;
    sx += MAX;
    sy += MAX;
    queue<State> Q;
    State u;
    Q.push(mp(mp(sx, sy), 0));
    O[sx][sy] = true;
    int cnt = 0;
    while(!Q.empty()){
      u = Q.front(); Q.pop();

      cnt++;
      for ( int r = 0; r < 6; r++ ){
	int nx = u.first.first + dx[r];
	int ny = u.first.second + dy[r];
	if ( O[nx][ny] || u.second+1 > t) continue;
	O[nx][ny] = true;
	Q.push(mp(mp(nx, ny), u.second+1));
      }
    }
    cout << cnt << endl;
  }

}

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

using namespace std;

int main(void){
    int N,A,B;

    cin>>N;
    if(N==1){
        cout<<"Hello World"<<endl;
    }else{
        cin>>A;
        cin>>B;
        cout<<A+B<<endl;    
    }
    return 0;
}

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

int main(){
    long long int n;
    cin>>n;
    vector<int> A(n);
    int f=0;
    for(int i=0;i<n;i++){
        cin>>A[i];
        if(A[i]<0)f++;
    }
    int mi = 1e9;
    if(f%2==0){
        long long int ans = 0;
        for(int i=0;i<n;i++){
            if(A[i]<0)A[i]*=-1;
            ans += A[i];
        }
        cout<<ans<<endl;
    }
    else{
        long long int ans = 0;
        for(int i=0;i<n;i++){
            if(A[i]<0)A[i]*=-1;
            ans += A[i];
        }
        sort(A.begin(),A.end());
        ans -= A[0]*2;
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using pii = pair<int, int>;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);


    int x; cin >> x;
    cout << (x == 0 ? 1 : 0) << endl;


    return 0;
}


Measured memory_bytes: 3636
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<ll, int> P;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, k;
int a[100100];
ll b[100100];

ll calc(int m) {
    ll ret = 0;
    for (int i = 0; i < n; i++) {
        if ((m & a[i]) == a[i])
            ret += b[i];
    }
    return ret;
}

ll solve() {
    ll res = calc(k);
    for (int i = 0; i < 30; i++) {
        if ((k>>i)&1) {
            res = max(res, calc((k ^ (1<<i)) | ((1<<i)-1)));
        }
    }
    return res;
}

void input() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 1408
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
 
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
 
 
 
using namespace std;
void file(){
	#ifndef ONLINE_JUDGE
    	freopen("tst.txt", "r", stdin);
	#endif	
}
int tc;
const int N=3e5+5,M=3e5+5,MOD=1e9+7,OO=1e9;

int n,m,p;
std::vector<int> g[N];
bool vis[N];
void dfs(int u){
	if(vis[u])return;
	vis[u]=1;
	for(auto v : g[u])dfs(v);
}

int main()
{	
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 //	file();
 	
 	scanf("%d %d %d",&n,&m,&p);
 	std::vector<ll> dist(n+1,-1e18);
 	vector<pair<pair<int,int>,int>>edge(m);
 	for(int i=0,u,v;i<m;i++){
 		scanf("%d %d %d",&edge[i].first.first,&edge[i].first.second,&edge[i].second);
 		u = edge[i].first.first;
 		v = edge[i].first.second;
 		g[u].pb(v);
 		edge[i].second-=p;
 	}
 	dist[1]=0;
 	for(int i=1;i<n;i++){
 		for(auto p : edge){
 			int u = p.first.first , v = p.first.second;
 			int w = p.second;
 			if(dist[u]>-1e18)
 				dist[v]=max(dist[v],dist[u]+w);
 		}
 	}

 	for(auto p : edge){
 		int u = p.first.first , v = p.first.second;
 		int w = p.second;
 		if(dist[u]>-1e18)
 		if(dist[v]<dist[u]+w){
 			dist[v]=dist[u]+w;
 			dfs(v);
 			if(vis[n] || vis[1])return !printf("-1\n");
 			for(int i=1;i<=n;i++)vis[i]=0;
 		}
 	}
 	printf("%lld\n",max(dist[n],0LL));
 	
}

Measured memory_bytes: 7552
#!/usr/bin/python3
# ABC058_C, ARC071_A
"""
怪文書 / Dubious Document
・入力される文字列にA-Zのどれが何回含まれるか確認する。(1~n, a~zの平面リスト)
・一番短い文字列を探して、それに含まれる文字だけ使う。
"""
from string import ascii_lowercase as abc

test = False


def answer():
    """
    答え
    例:l_count[0]は'a'の最少回数。
    """
    n = int(input())
    l_count = [51] * 26

    for _ in range(n):
        """
        各アルファベットの、含まれる最少回数のリストを作る。
        例：l_count[0] は 'a' の最少回数
        """
        temp_S = input()
        for i in range(26):
            """
            各アルファベットについて、含まれる回数が最少だった場合はリストに記録する。
            """
            temp_count = temp_S.count(abc[i])
            l_count[i] = min(l_count[i], temp_count)

    if test:
        print('l_count =', l_count)
    # ここまでで回数確認終わり

    # 答えの文字列の生成・出力
    temp_answer = ''
    for j in range(26):
        temp_answer += l_count[j] * abc[j]

    print(temp_answer)


def main():
    """
    main関数
    """
    answer()


if __name__ == '__main__':
    main()


Measured memory_bytes: 3768
/*

宣告——
汝身在我之下，托付吾之命运于汝之剑，
遵从圣杯之名，若汝遵从此意志此理，回应吧。
在此起誓，吾是成就世间一切行善之人，吾是肃清世间一切罪恶之人，
被狂乱之槛所囚的囚徒。吾是此锁链的操纵者，
汝为身缠三大言灵之七天，从抑止之轮显现吧，天秤之守护者！

*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cassert>
#include<vector>
#include<cmath>
#define N 1000
using namespace std;
typedef long long ll;
inline int read(){
	int re=0,flag=1;char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(isdigit(ch)) re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
char c[N][N]; 
ll _s[N][N+N]; 
int _gg[N][N+N],n,m;
struct P{
int ORZ,SJK;
}a[N*N];
inline bool cmp1(P ORZ,P SJK){return ORZ.SJK<SJK.SJK;}
inline bool cmp2(P ORZ,P SJK){return ORZ.ORZ<SJK.ORZ;}
vector<P> v1[N],_v2[N+N];
#define s(ORZ,SJK) _s[ORZ][SJK+N]
#define gg(ORZ,SJK) _gg[ORZ][SJK+N]
#define v2(ORZ) _v2[ORZ+N]
inline int S(int x1,int y1,int x2,int y2){
	if(x1>x2||y1>y2||x1<2||x2>n+m||y1<1-m||y2>n-1)
		return 0;
	return s(x2,y2)-s(x2,y1-1)-s(x1-1,y2)+s(x1-1,y1-1);
}
int main(){
	int t=0,i,j,k; 
ll s1=0,s2=0; 
n=read();m=read();
	for(i=1;i<=n;i++){
		scanf("%s",c[i]+1);
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			if(c[i][j]!='.'){
				a[++t]=P{i+j,i-j};
				v1[i+j].push_back(a[t]);
				v2(i-j).push_back(a[t]);
				gg(i+j,i-j)++;
			}
		}
	}
	for(i=2;i<=n+m;i++) 
		sort(v1[i].begin(),v1[i].end(),cmp1);
	for(i=1-m;i<=n-1;i++) 
		sort(v2(i).begin(),v2(i).end(),cmp2);
	for(i=2;i<=n+m;i++){
		for(j=1-m;j<=n-1;j++) 
			s(i,j)=s(i-1,j)+s(i,j-1)-s(i-1,j-1)+gg(i,j);
	}
	for(i=2;i<=n+m;i++){
		for(j=0;j<v1[i].size();j++){
			for(k=j+1;k<v1[i].size();k++){
				P ORZ=v1[i][j],SJK=v1[i][k];
				int d=SJK.SJK-ORZ.SJK;
				s1+=S(ORZ.ORZ+d,ORZ.SJK+1,ORZ.ORZ+d,SJK.SJK-1);
				s2+=S(ORZ.ORZ+d,ORZ.SJK,ORZ.ORZ+d,ORZ.SJK);
				s2+=S(ORZ.ORZ+d,SJK.SJK,ORZ.ORZ+d,SJK.SJK);
				s1+=S(ORZ.ORZ-d,ORZ.SJK+1,ORZ.ORZ-d,SJK.SJK-1);
				s2+=S(ORZ.ORZ-d,ORZ.SJK,ORZ.ORZ-d,ORZ.SJK);
				s2+=S(ORZ.ORZ-d,SJK.SJK,ORZ.ORZ-d,SJK.SJK);
			}
		}
	}
	for(i=1-m;i<=n-1;i++){
		for(j=0;j<v2(i).size();j++){
			for(k=j+1;k<v2(i).size();k++){
				P ORZ=v2(i)[j],SJK=v2(i)[k];
				int d=SJK.ORZ-ORZ.ORZ;
				s1+=S(ORZ.ORZ+1,ORZ.SJK+d,SJK.ORZ-1,ORZ.SJK+d);
				s2+=S(ORZ.ORZ,ORZ.SJK+d,ORZ.ORZ,ORZ.SJK+d);
				s2+=S(SJK.ORZ,ORZ.SJK+d,SJK.ORZ,ORZ.SJK+d);
				s1+=S(ORZ.ORZ+1,ORZ.SJK-d,SJK.ORZ-1,ORZ.SJK-d);
				s2+=S(ORZ.ORZ,ORZ.SJK-d,ORZ.ORZ,ORZ.SJK-d);
				s2+=S(SJK.ORZ,ORZ.SJK-d,SJK.ORZ,ORZ.SJK-d);
			}
		}
	}		
	cout<<s1+s2/2;
}


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

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()

#define MOO(i, a, b) for (int i=a; i<b; i++)
#define M00(i, a) for (int i=0; i<a; i++)
#define MOOd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define M00d(i,a) for (int i = (a)-1; i >= 0; i--)

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << '\n', 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _<< " _ " <<

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pd;
typedef complex<ld> cd;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() { FAST
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	int d, t, s;
	cin >> d >> t >> s;
	if(t * s >= d) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}


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


def main():
    n = int(input())
    a = list(map(int, input().split()))
    
    ma = 0
    ans = 0
    for i in range(n):
        if i != 0:
            ans += max(0, ma-a[i])
        ma = max(ma, a[i])
    
    print(ans)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 92028
using System;
using System.Collections.Generic;

public class p0013
{
	p0013(){
		string str;
		Stack<string> stk = new Stack<string>();
		
		while((str=Console.ReadLine()) != null){
			if(str != "0") stk.Push(str);
			else if(stk.Count > 0) Console.WriteLine(stk.Pop());
		}
	}
	
	public static int Main(string[] args){
		new p0013();
		return 0;
	}
}

Measured memory_bytes: 5552
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1000000000000000000

using namespace std;

int main(void){
  ll n, k, s;
  cin >> n >> k >> s;
  
  if (s == 1000000000){
    for (int i = 0; i < n; i++){
      if (i < k){
        cout << s;
      }
      else 
        cout << 1;

      if (i == n - 1)
        cout << endl;
      else
        cout << " ";
    }
  }
  else {
    for (int i = 0; i < n; i++){
      if (i < k){
        cout << s;
      }
      else 
        cout << s + 1;

      if (i == n - 1)
        cout << endl;
      else
        cout << " ";
    }
  }

  return 0;
}


Measured memory_bytes: 3644
using System;
using System.Linq;

public class Hello
{
    public static void Main()
    {
        // Your code here!
        
        int[] a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        Array.Sort(a);
        int answer = a[2] * 10 + a[1] + a[0];
        Console.WriteLine(answer);
        
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
	string str1, str2;

	cin >> str1 >> str2;
	
	int len = (int)str1.size();
	bool flag = false;
	REP(i, len){
		if(str1 == str2){
			flag = true;
			break;
		}
		else {
			str1.insert(str1.begin(), str1.back());
			str1.erase(len, 1);
		}
	}
	cout << (flag == true ? "Yes" : "No") << endl;

}


Measured memory_bytes: 256
n = int(input())
l = []
for i in range(n):
    x,y = map(int,input().split())
    l.append([x, y])

sm = 0
for i in range(n):
    for j in range(n):
        sm += ((l[i][0] - l[j][0]) ** 2 + (l[i][1] - l[j][1]) ** 2) ** 0.5
print(sm / n)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
	while(1){
		int a[10]={0};
		int n;
		cin>>n;
		if(n==0) return 0;
		for(int i=0;i<n;i++){
			int num;
			cin>>num;
			a[num]++;
		}
		for(int i=0;i<10;i++){
			for(int j=0;j<a[i];j++) cout<<"*";
			if(a[i]==0) cout<<"-";
			cout<<"\n";
		}
	}
}

Measured memory_bytes: 3052
#include <cstring>
#include <cstdio>
#include <cstdlib>
int a[100];
int main() {
	int n;
	int mn = 1 << 30, mx = -1;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		if (mn > a[i]) {
			mn = a[i];
		}
		if (mx < a[i]) {
			mx = a[i];
		}
	}
	printf("%d\n", mx - mn);
	return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
int main() {
	while (1) {
		long long int A, B, D; cin >> A >> B >> D;
		if (!A)break;
		pair<long long int, long long int >ans = make_pair(1e9, 1e9);
		for (int i = -100000; i < 100000; ++i) {
			const int anum = abs(i);
			long long int rest = D - A*i;
			if (!(rest%B)) {
				long long int bnum = abs(rest / B);
				if (anum + bnum < ans.first + ans.second)ans = make_pair(anum, bnum);
				if (anum*A + bnum*B < ans.first*A + ans.second*B)ans = make_pair(anum, bnum);
			}
		}
		cout << ans.first << " " << ans.second << endl;
	}
	return 0;
}

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

using namespace std;

using int64 = long long;

int main() {
  int W, H;
  while(cin >> W >> H, W) {
    string C[70];
    for(int i = 0; i < H; i++) {
      cin >> C[i];
    }
    const int vy[] = {1,
                      0}, vx[] = {0, 1};
    string dp[70][70];
    fill_n(*dp, 70 * 70, "~");
    function< string(int, int) > dfs = [&](int y, int x) {
      if(dp[y][x] != "~") return dp[y][x];
      string ret = "";
      for(int i = 0; i < 2; i++) {
        int ny = y + vy[i], nx = x + vx[i];
        if(ny >= H || nx >= W) continue;
        if(!isdigit(C[ny][nx])) continue;
        string beet;
        beet += C[ny][nx];
        beet += dfs(ny, nx);
        if(ret.size() < beet.size()) ret = beet;
        else if(ret.size() == beet.size()) ret = max(ret, beet);
      }
      return dp[y][x] = ret;
    };
    string ret = "0";
    for(int i = 0; i < H; i++) {
      for(int j = 0; j < W; j++) {
        if(isdigit(C[i][j]) && C[i][j] != '0') {
          string beet;
          beet += C[i][j];
          beet += dfs(i, j);
          if(ret.size() < beet.size()) ret = beet;
          else if(ret.size() == beet.size()) ret = max(ret, beet);
        }
      }
    }
    cout << ret << endl;
  }

}



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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i);
    }
    vector<pair<ll,ll>> b;
    for(i = 0;i < n;++i){
        b.emplace_back(a.at(i), i);
    }
    sort(all(b), greater<pair<ll,ll>>());
    vector<vector<ll>> dp(n+1,vector<ll>(n+1,0));
    for(i = 0;i < n;++i){
        auto x = b.at(i);
        ll val = x.first;
        ll ind = x.second;
        rep(j,i+1){
            chmax(dp.at(i+1).at(j+1), dp.at(i).at(j) + val*abs(ind - j));
            chmax(dp.at(i+1).at(j), dp.at(i).at(j) + val*abs(ind - (n-1-(i-j))));
        }
    }
    ll ans = 0;
    for(i = 0;i <= n;++i){
        ans = max(ans, dp.at(n).at(i));
    }
    cout << ans << endl;
    return 0;
}

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


int main()
{
  int n;
  cin >> n;
  vector<int> l(n);
  rep(i, n) cin >> l[i];

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

  int ans = 0;

  for (int i = 0; i < n;i++){
    for (int j = i + 1; j < n;j++){
      if(l[i]==l[j])
        continue;
      for (int k = j + 1; k < n; k++)
      {
        if(l[j]==l[k])
          continue;
        if (l[i] + l[j] > l[k])
        {
          if(l[i]!=l[j] || l[j]!=l[k])
            ans++;
        }
      }
    }
  }

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


Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define si(n) scanf("%d",&n);
#define PI acos(-1.0)
#define sl(n) scanf("%lld",&n);
#define sf(n) scanf("%lf",&n);
#define ss(n) scanf("%s",n);
#define for0(i,n) for(ll i=0;i<n;i++)
#define for1(i,n) for(ll i=1;i<=n;i++)
#define forc(i,j,n) for(ll i=j;i<n;i++)
#define pb push_back
#define sor(n) sort(n.begin(),n.end())
#define sorcmp(n) sort(n.begin(),n.end(),cmp)
#define rev(n) reverse(n.begin(),n.end())
#define pi(x)  prllf("%d",x);
#define pl(x)  prllf("%lld",x);
#define pf(x)  prllf("%.10lf",x);
#define ps(x)  prllf("%s",x);
#define en() prllf("\n");
#define random_shuffle(r...)random_shuffle(r,[](int _){return rand()%_;})
#define SQR(a) (a)*(a)
#define mod 1000000007
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
template <typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
ll powmod(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%mod;a = a*a%mod;b >>= 1;}return ans;}

ll prime[1000000];bool visprime[1000000];
void sieve(){int k=0;for(int i=2;i*i<=1000000;i++) {if(visprime[i]==false) {for(int j=i*i;j<=1000000;j+=i){ visprime[j]=true;}}}for(int i=2;i<=1000000;i++){if(visprime[i]==false) prime[k++]=i;}}

map<ll,ll>m;
vector<ll>pf[100000+5];

ll powll(ll n,ll m){
   return m?((m&1)?n:1)*powll(n*n,m>>1):1;
}

void primefactor(ll x,ll indx)
{
    //ll temp=x;
    for(int i=0;prime[i]*prime[i]<=x;i++)
    {
        ll p=prime[i];
        if(x%p==0)
        {
            ll cnt=0;
            while(x%p==0)
            {
                //if(x%p!=0) break;
                x/=p;
                cnt++;
            }
             m[p]=max(m[p],cnt);

            pf[indx].pb(p);


        }

        //if(x/p==0) break;
    }
    if(x>1) pf[indx].pb(x);
    m[x]=max(m[x],(ll)1);

}

ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}
ll visit[1000000];

int main()
{

 sieve();
 ll n;
 cin>>n;
 ll arr[n];
 //ll Md=1000000007;

 for(int i=0;i<n;i++)
 {
     cin>>arr[i];
     primefactor(arr[i],i);


 }


 ll ans=1;


  for(ll i=0;i<n;i++)
  {
      for(ll j=0;j<pf[i].size();j++)
      {
          ll temp=pf[i][j];
          if(visit[temp]==0){ans=(ans%mod)*(powll(temp,m[temp])%mod);
          visit[temp]++;
          }
          ans%=mod;

      }

  }
    ll sum=0;
  for(ll i=0;i<n;i++)
  {
      sum=sum%mod+(ans*modinv(arr[i],mod))%mod;
      sum%=mod;
  }


  cout<<sum<<endl;













}


Measured memory_bytes: 12928
#include <iostream>
using namespace std;
typedef long long ll;
ll Q,H,S,D,N;

int main(){
	cin >> Q >> H >> S >> D >> N;
	Q *= 8;
	H *= 4;
	S *= 2;
	ll ans = 0;
	ll two = min(min(Q,H),min(S,D));
	ans += (N/2)*two;
	if(N%2==1){
		Q /= 2;
		H /= 2;
		S /= 2;
		ll one = min(S,min(Q,H));
		ans += one;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main (void){
	int n,b,f,r,v,i,j,k;
	scanf("%d",&n);
	int a[100][100][100]={};//????£?????????????????????¨?±?
	for(i=1;i<=n;i++){
		scanf("%d %d %d %d",&b,&f,&r,&v);
		a[b][f][r]+=v;
	}
	for(j=1;j<=4;j++){
		for(i=1;i<=3;i++){
			for(k=1;k<=10;k++){
				printf(" %d",a[j][i][k]);
			}
			printf("\n");
		}
		if(j==4){
			break;
		}
		printf("####################\n");
	}
	return 0;
}

Measured memory_bytes: 4528
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
	int ans = 0, n;
	cin >> n;
	vector<int> a(n);
	rep(i, 0, n){
		cin >> a[i];
		a[i]--;
	}
	rep(i, 0, n){
		if(a[a[i]] == i) ans ++;
	}
	cout << ans / 2 << endl;
}

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

main() {
    int N,X; cin >> N >> X;
    int height=0; bool can = true;
    rep(i,N){
        int L; cin >> L;
        height += L;
        if(height>X){can = false; cout << i+1 << endl; break;}
    }
    if(can)cout << N+1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<tuple>
#include<vector>
#include<algorithm>
#include<cmath>
#include<complex>
#include<limits>

using std::begin;
using std::end;

using Compl = std::complex<float>;

auto comp_x = [](Compl const& l, Compl const& r) { return std::real(l) < std::real(r); };
auto comp_y = [](Compl const& l, Compl const& r) { return std::imag(l) < std::imag(r); };

using It = std::vector<Compl>::iterator;

int closest_pair(It begin, It end) {
  if (end - begin <= 1) return std::numeric_limits<int>::max();

  auto mid{begin + (end - begin) / 2};
  int x{static_cast<int>(std::real(*mid))};
  int d{std::min(closest_pair(begin, mid), closest_pair(mid, end))};
  std::inplace_merge(begin, mid, end, comp_y);
  std::vector<Compl> t;
  for(auto it{begin}; it != end; ++it) {
    if(std::abs(std::real(*it) - x) >= d) continue;

    for(int i{static_cast<int>(t.size()) - 1}; i >= 0; --i) {
      int dx{static_cast<int>(std::real(*it) - std::real(t[i]))};
      int dy{static_cast<int>(std::imag(*it) - std::imag(t[i]))};
      if(dy >= d) break;

      d = std::min(d, dx * dx + dy * dy);
    }
    t.push_back(*it);
  }
  return d;
}

int main(int, char**) {
  int n;
  std::cin >> n;
  std::vector<Compl> v;
  std::vector<int> rs;

  for(int i{0}; i < n; ++i) {
    int x, y;
    std::cin >> x >> y;
    v.emplace_back(x, y);
  }

  std::sort(begin(v), end(v), comp_x);
  std::cout << closest_pair(begin(v), end(v)) << std::endl;

  return 0;
}


Measured memory_bytes: 12528
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;

public class Main {
    static final int MAX = Integer.MAX_VALUE;
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        HashMap<Integer, Integer>[] d = new HashMap[n+1];
        for (int i = 0; i <= n; i++) {
            d[i] = new HashMap<Integer, Integer>();
        }
        
        for (int i = 0; i < m; i++) {
            int xLi = sc.nextInt();
            int xRi = sc.nextInt();
            int xDi = sc.nextInt();
            d[xLi].put(xRi, xDi);
            d[xRi].put(xLi, -xDi);
        }

        
        Queue<Integer> q = new LinkedList<Integer>();
        long[] pos = new long[n+1];
        boolean[] visited = new boolean[n+1];
        
        for (int i = 1; i <= n; i++) {
            if (visited[i]) continue;
            
            q.add(i);
            pos[i] = 0;
            while (!q.isEmpty()) {
                int first = q.poll();
                Set<Integer> keys = d[first].keySet();
                for (int k : keys) {
                    Integer costFK = d[first].get(k);
//                    U.println(costFK);
                    if (costFK != null && costFK != MAX) {
                        d[first].put(k, MAX);
                        if (visited[k]) {
                            if (pos[k] != pos[first] + costFK) {
                                System.out.println("No");
                                return;
                            }
                        } else {
                            visited[k] = true;
                            q.add(k);
                            pos[k] = pos[first] + costFK;
                        }
                    }
                }
            }
        }
        System.out.println("Yes");
    }
}


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

using namespace std;
const int N = 1e5 +3;
int dp[N],height[N];
int main()
{	
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n;
	cin >> n;
	for(int i = 1;i<=n;i++) cin >> height[i];
	dp[2] = abs(height[1]-height[2]);
	for(int i = 3;i<=n;i++) dp[i] = min(dp[i-1]+abs(height[i-1]-height[i]),dp[i-2]+abs(height[i-2]-height[i]));
	cout <<dp[n]<<endl;  
	return 0;
}



Measured memory_bytes: 4348
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>

using namespace std;

const int maxn = 200010;

typedef long long ll;
int a[maxn], n;
ll ans = 0;

int lft = 0;

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {scanf("%d", &a[i]);}
    lft = n;
    for (int i = n; i >= 1; i--) {
        int x;
        if (i >= lft) {
            x = i-lft;
        } else x = 0;
        if (x > a[i]) {
            puts("-1");
            return 0;
        }
        if (x == a[i]) continue;
        lft = i-a[i];
        if (lft > 0) {
            ans += a[i];
        } else {
            puts("-1");
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define sz(s) (int)s.size()

int main() {
    int n, a;
    cin >> n >> a;
    for (int i = 0; i <= 10000; ++i) {
        int t = i * 500;
        if (t <= n && n - t <= a) {cout << "Yes"; return 0;}
    }
    cout << "No";
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

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


    for(int i=0;i<k;i++){
        auto pre = a;

        vector<int> sum(n+1);
        for(int i=0;i<n;i++){
            int l=max(i-a[i],0);
            int r=min(i+a[i]+1,n);
            sum[l]++;
            sum[r]--;
        }

        for(int i=0;i<n;i++){
            a[i]=sum[i];
            sum[i+1]+=sum[i];
        }
        if(pre==a) break;
    }
    
    for(int i=0;i<n;i++) cout<<a[i]<<" ";

    return 0;
}


Measured memory_bytes: 5628
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    FastScanner in;
    PrintWriter out;

    void solve() {
        long X = 26;
        long[] cnt = new long[100];
        cnt[1] = X;
        for (int i = 2; i < cnt.length; i++) {
            cnt[i] = cnt[i - 1] * X;
        }
        long n = in.nextLong() - 1;
        for (int len = 1; ;len++) {
            if (n < cnt[len]) {
                char[] res = new char[len];
                for (int i = 0; i < len; i++) {
                    res[len - 1 - i] = (char) ('a' + (n % X));
                    n /= X;
                }
                out.println(new String(res));
                break;
            } else {
                n -= cnt[len];
            }
        }
    }

    final int mod = 998244353;

    int mul(int x, int y) {
        return (int) ((x * 1L * y) % mod);
    }

    int add(int x, int y) {
        x += y;
        return x >= mod ? (x - mod) : x;
    }

    void run() {
        try {
            in = new FastScanner(new File("Main.in"));
            out = new PrintWriter(new File("Main.out"));

            solve();

            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    void runIO() {

        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();
        out.close();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

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

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

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

    public static void main(String[] args) {
        new Main().runIO();
    }
}

Measured memory_bytes: 32856
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <utility>

#define INF 1000000000

using namespace std;

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

struct edge{
	int to, cost;
};

int V, E;
vector<edge> e[10000];
priority_queue< P, vector<P>, greater<P> > que;
bool used[10000];


int main(void){
	cin >> V >> E;

	for(int i = 0;i < V;i++){
		used[i] = false;
	}

	for(int i = 0;i < E;i++){
		int a, b, c;
		cin >> a >> b >> c;
		edge d;
		d.to = b;
		d.cost = c;
		e[a].push_back(d);
		d.to = a;
		e[b].push_back(d);
	}


	que.push(P(0, 0));
	long long int res = 0;

	while(!que.empty()){

		P a = que.top();
		que.pop();
		if(used[a.second]) continue;
		used[a.second] = true;
		res += a.first;

		for(int u = 0;u < e[a.second].size();u++){
			if(!used[e[a.second][u].to])
				que.push(P(e[a.second][u].cost, e[a.second][u].to));
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 5020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int main() {
    ll N; cin >> N;
    vector<ll> v;
    map<ll, ll> input;

    // input
    for (int i = 0; i < N; ++i) {
        ll a; cin >> a;
        if (!input.count(a)) {
            v.push_back(a);
            input[a] = 1;
        }
        else {
            input[a]++;
        }
    }

    sort(v.begin(), v.end());
    ll input_max = v[v.size() - 1];
    vector<bool> valid(input_max, true);

    // ふるい
    for (auto i: v) {
        for (int j = 2; j * i <= input_max; j++) {
            valid[i * j - 1] = false;
        }
    }

    // ans
    ll ans = 0;
    for (int i = 0; i < input_max; i++) {
        if (input.count(i + 1) && input.at(i + 1) == 1 && valid[i]) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 17292
S = int(input())

LIMIT = S // 3
AA = 1000000007

# M[項数-1][合計-1] = 項数で和が合計、各項数が3以上である数列の総数

M = [[0 for _ in range(S)] for _ in range(LIMIT)]

for i in range(len(M)):
    n = i + 1
    start = (n - 1) * 3
    SSS = 0
    for j in range(len(M[i])):
        X = j + 1
        if i == 0:
            if X >= 3:
                M[i][j] = 1
            else:
                M[i][j] = 0
        else:
            M[i][j] = 0
            end = X - 3
            if start <= end:
                SSS += M[i - 1][end - 1]
                SSS = SSS % AA
                M[i][j] = SSS
             

ANS = 0

for i in range(1, LIMIT + 1):
    ANS += M[i - 1][S - 1]
ANS = ANS % AA

print(ANS)


Measured memory_bytes: 40356
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>

#include <algorithm>
#include <numeric>
#include <cmath>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
const long double PI = (acos(-1));
const long long MOD = 1000000007;
#define rep(i,n) REP(i,0,n)
#define REP(i,x,n) for(int i=x;i<n;++i)

///////////////////////////////////////////////////
// -------------------- I/O -------------------- //
///////////////////////////////////////////////////
// https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords
template<typename T> void outputVec(const std::vector<T>& vec, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	for (auto it = vec.begin(); it != vec.end() - 1; ++it) { std::cout << *it << " "; }
	std::cout << *(vec.end() - 1) << "\n";
}
template<typename T> void outputVal(const T& res, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	std::cout << res << "\n";
}
template<typename T> T inputVal() { T a; std::cin >> a; return a; }
template<typename T> std::vector<T> inputVec(int N) {
	std::vector<T> vec(N);
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
	return vec;
}
template<typename T> void inputVec(std::vector<T>& vec) {
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
}

///////////////////////////////////////////////////
// ------------------- utils ------------------- //
///////////////////////////////////////////////////
// change min/max
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; }

///////////////////////////////////////////////////
// ------------------- main -------------------- //
///////////////////////////////////////////////////
void Main() {
	const int N = inputVal<int>();
	vector<pair<pair<string, int>, int> > vec(N);

	rep(i, N) {
		string s; cin >> s;
		int rate; cin >> rate;
		vec[i] = make_pair(make_pair(s, -rate), i + 1);
	}

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

	for (auto v : vec) {
		cout << v.second << endl;
	}

}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout << std::fixed << std::setprecision(15);
	Main();

	return 0;
}


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

int main(){
    int n,A[100]={},i,j,l,v;
    cin >> n;

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

        if (i == n-1){
            cout << A[i] << '\n';
        }
        else {
            cout << A[i] << " ";
        }
    }
    for (int i = 1; i < n; i++){
        v = A[i];
        j = i - 1;
        while (j >= 0 && A[j] > v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        for (int i = 0; i < n-1; i++){
            cout << A[i] << " ";
        }
        cout << A[n-1] << '\n';
    }

    return 0;
}


Measured memory_bytes: 3076
/*
 ╔═══╦═══╦═══╗
 ║╔═╗║╔══╩╗╔╗║
 ║║░║║╚══╗║║║║
 ║║░║║╔══╝║║║║
 ║╚═╝║╚══╦╝╚╝║
 ╚══╗╠═══╩═══╝
 ░░░╚╝░░░░░░░░
 */

#include <bits/stdc++.h>
#define ll					long long
#define MOD					1000000007
#define MAX					1e9
#define MIN                 -1e9
#define PI					acos(-1.0)
#define vi					vector<int>
#define vii					vector<vi>
#define vll					vector<ll>
#define mid(s,e)			(s+(e-s)/2)

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
template<typename T>
void printVec(const T &v, char sep=' ') {for (auto &i: v) cout << i << sep;}
template<typename T>
void printVecPair(const T &v, char sep=' ') {for (auto &i: v) cout << i.first <<" " << i.second<< sep;}


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

int main() {
	ios::sync_with_stdio(false);
 	cin.tie(0);
	int h,n;
	cin>>h>>n;
	int s=0;
	for(int i=0;i<n;i++) {int a; cin>>a; s+=a;}
	if(s>=h) cout<<"Yes";
	else cout<<"No";
	return 0;
}





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

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;i++)
#define rep2(i, m, n) for(int i=m;i<n;i++)
#define rrep(i, n, m) for(int i=n;i>=m;i--)
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll MOD = 1000000007;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int r;
    cin >> r;
    cout << (int)pow(r, 2) * 3 << endl;

}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K,sum=1;
  cin>>N>>K;
  for(int i=0;i<N;i++){
  	if(sum+K <= sum*2){
    	sum+=K;
    }
    else{
    sum*=2;}
    //cout<<sum<<endl;
  }
	cout<< sum << endl;
}

Measured memory_bytes: 3608
/**
 * @author: Mackenzie
**/
#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    int n;
    cin >> n;
    set<int> st;
    forn(i, n) {
        int v;
        cin >> v;
        st.insert(v);
    }
    if (sz(st) == n)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

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

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

    if (N % 2 == 0 && S.substr(0, N/2) == S.substr(N/2, N/2)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

   return 0;
}

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

#define pan(i,n) for(int i=0;i<n;i++)
#define pans(i,n,a) for(int i=a;i<n;i++)
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define INF 1e9+7
#define PI 3.141592653
#define inf 200007
#define P pair<ll,ll>

using namespace std;
int n;
ll k;
vl a;

int main(){
    string ans;
    cin>>n>>k;
    pan(i,n){
        ll x;
        cin>>x;
        a.pb(x);
    }
    sort(a.begin(),a.end());
    ll x=a[0],m=a[n-1];
    if(k>m) ans="IMPOSSIBLE";
    else{
        pans(i,n,1){
            if(a[i]==k){
                ans="POSSIBLE";
                break;
            }
            if(a[i]%x!=0){
                ll g=a[i]/x,z=a[i]%x;
                while(g--){
                    if((g*(x)+z)<x){
                        x=g*(x)+z;
                        break;
                    }
                }
                if(g==0) x=z;
            }
        }
        if(k%x==0) ans="POSSIBLE";
        else ans="IMPOSSIBLE";
    }
    cout<<ans;
}   

Measured memory_bytes: 1400
//============================================================================
// Name        : AOJ.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	int H,W;

	while(1){
		cin>>H>>W;
		if (H==0 && W==0)break;
		for (int i=0; i<H; i++){
			for (int j=0; j<W; j++){
				if (i==0||i==H-1||j==0||j==W-1){
					cout<<"#";
				}
				else cout<<".";
			}
			cout<<"\n";
		}
		cout<<endl;
	}

	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> card(n), scard;
  for (int i = 0; i < n; i++) {
    cin >> card.at(i);
  }
  for (int i = 0; i < n; i++) {
    int tcard = card.at(i);
    for (int j = 0; j < scard.size(); j++) {
      if (scard.at(j) >= tcard) {
        vector<int> nscard(scard.size() + 1);
        for (int k = 0; k < j; k++) {
          nscard.at(k) = scard.at(k);
        }
        nscard.at(j) = tcard;
        for (int l = j + 1; l < nscard.size(); l++) {
          nscard.at(l) = scard.at(l - 1);
        }
        scard = nscard;
        break;
      }
    }
    if (scard.size() == i) {
      scard.push_back(tcard);
    } 
  }
  int asum = 0, bsum = 0;
  for (int i = scard.size() - 1; i >= 0; i -= 2) {
    asum += scard.at(i);
  }
  for (int i = scard.size() - 2; i >= 0; i -= 2) {
    bsum += scard.at(i);
  }
  cout << asum - bsum << endl;
}

Measured memory_bytes: 256
from fractions import gcd
A,B = map(int,input().split())
g = gcd(A,B)

from collections import Counter
def factorize(n):
    d = Counter()
    m = 2
    while m*m <= n:
        while n%m == 0:
            n //= m
            d[m] += 1
        m += 1
    if n > 1:
        d[n] += 1
    return d
f = factorize(g)
print(len(f) + 1)

Measured memory_bytes: 5048
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	long MODULO = 1_000_000_000 + 7;

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] e = new int[n][3];
		for (int i = 0; i < n; ++i) {
			e[i][0] = sc.nextInt();// x
			e[i][1] = sc.nextInt();// v
			e[i][2] = -1;
		}
		Arrays.sort(e, new Comparator<int[]>() {
			@Override
			public int compare(int[] o1, int[] o2) {
				return Integer.compare(o1[1], o2[1]);
			}
		});
		for (int i = 0; i < n; ++i) {
			e[i][2] = i;
		}

		Arrays.sort(e, new Comparator<int[]>() {
			@Override
			public int compare(int[] o1, int[] o2) {
				return Integer.compare(o1[0], o2[0]);
			}
		});

		int[][] min = new int[n][2];
		int[][] max = new int[n][2];
		for (int i = 0; i < n; ++i) {
			min[i][0] = Integer.MAX_VALUE;
			max[i][0] = -Integer.MAX_VALUE;
			min[i][1] = -1;
			max[i][1] = -1;
		}
		for (int i = 0; i < n; ++i) {
			if (i == 0 || max[i - 1][0] < e[i][1]) {
				max[i][0] = e[i][1];
				max[i][1] = e[i][2];
			} else {
				max[i][0] = max[i - 1][0];
				max[i][1] = max[i - 1][1];
			}
		}
		for (int i = n - 1; i >= 0; --i) {
			if (i == n - 1 || min[i + 1][0] > e[i][1]) {
				min[i][0] = e[i][1];
				min[i][1] = e[i][2];
			} else {
				min[i][0] = min[i + 1][0];
				min[i][1] = min[i + 1][1];
			}
		}
		long[] f = new long[n];
		long s = 0;
		int t = 0;
		for (int i = 0; i < n; ++i) {
			while (min[i][1] - max[t][1] > 1) {
				s = (s - f[t] + MODULO) % MODULO;
				++t;
			}
			f[i] = s;
			if (min[i][1] == min[0][1]) {
				++f[i];
			}
			s += f[i];
			s %= MODULO;
			f[i] %= MODULO;
		}
		long ans = 0;
		for (int i = 0; i < n; ++i) {
			if (max[n - 1][1] == max[i][1]) {
				ans += f[i];
			}
			while (ans >= MODULO) {
				ans -= MODULO;
			}
		}
		System.out.println(ans);
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}

Measured memory_bytes: 133100
#include <iostream>
using namespace std;
int main() {
	int N, m = 0, ans = 0;
	cin >> N;
	for (int i = 0, p; i < N; i++) {
		cin >> p;
		ans += p;
		if (p > m) m = p;
	}
	ans -= m / 2;
	cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main()
{
    int n,a[10005],b[10005];
    cin>>n;
    for (int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for (int i=0;i<n;i++)
    {
        cin>>b[i];
    }
    long long a1=0,b1=0;
    for (int i=0;i<n;i++)
        if (a[i]>b[i]) b1+=a[i]-b[i];
        else if ((b[i]-a[i])%2==1) a1+=b[i]-a[i]-1;
        else a1+=b[i]-a[i];
    a1-=2*b1;
    if (a1<0) cout<<"No";
    else cout<<"Yes";
    return 0;
}


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

class DisjointSet {
public:
    vector<int> par, rank;

    DisjointSet(int n) {
        par.resize(n, 0);
        rank.resize(n, 0);
        for (int i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
        }
    }

    int find(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return  par[x] = find(par[x]);
        }
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;

        if (rank[x] < rank[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

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

    DisjointSet ds = DisjointSet(n);

    for (int i = 0; i < q; i++) {
        int com, x, y;
        cin >> com >> x >> y;
        if (com == 0) {
            ds.unite(x, y);
        } else {
            if (ds.same(x, y)) {
                cout << 1 << endl;
            } else {
                cout << 0 << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n, m, r;
    cin >> n >> m >> r;
    vector<vector<ll>> dp(n, vector<ll>(n, inf));
    vector<ll> v(r);
    rep(i, r){
        cin >> v[i];
        v[i]--;
    }
    sort(all(v));
    rep(i, m){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        dp[a][b] = c;
        dp[b][a] = c;
    }
    rep(i, n)dp[i][i] = 0;
    rep(k, n)rep(i, n)rep(j, n){
        dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j]);
    }
    ll ans = inf;
    do{
        ll now = 0;
        rep(i, r-1){
            now += dp[v[i]][v[i+1]];
        }
        ans = min(ans, now);
    }while(next_permutation(all(v)));
    cout << ans << endl;
}


Measured memory_bytes: 512
S = input()
T = input()

cumSA = [0] * (len(S) + 1)
cumSB = [0] * (len(S) + 1)
cumTA = [0] * (len(T) + 1)
cumTB = [0] * (len(T) + 1)

for i, s in enumerate(S, start=1):
    cumSA[i] = cumSA[i - 1]
    cumSB[i] = cumSB[i - 1]

    if s == 'A':
        cumSA[i] += 1
    else:
        cumSB[i] += 1

for i, t in enumerate(T, start=1):
    cumTA[i] = cumTA[i - 1]
    cumTB[i] = cumTB[i - 1]

    if t == 'A':
        cumTA[i] += 1
    else:
        cumTB[i] += 1

Q = int(input())
ans = []
for _ in range(Q):
    lS, rS, lT, rT = map(int, input().split())

    sA = cumSA[rS] - cumSA[lS - 1]
    sB = cumSB[rS] - cumSB[lS - 1]
    tA = cumTA[rT] - cumTA[lT - 1]
    tB = cumTB[rT] - cumTB[lT - 1]

    if (sA - sB) % 3 == (tA - tB) % 3:
        ans.append('YES')
    else:
        ans.append('NO')

print(*ans, sep='\n')



Measured memory_bytes: 16020