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

using namespace std;

#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second

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

ll modpow(ll a, ll b){

    ll ans=1;
    while(b){
        if(b&1){
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b=b/2;
    }
    return ans;
}


int sm[1000010];
bool chk[1000010];

int pw[1000010];


int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    for(int i = 2; i < 1000010; i++) {
        if(chk[i] == 0) {
            sm[i] = i;

            for(int j = 2; j*i < 1000010; j++) {
                if(chk[i*j] == 0) {
                    chk[i*j] = 1;
                    sm[i*j] = i;
                }
            }
        }
    }

    int n;
    cin>>n;

    vector<ll> inp(n);

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

        map<int, int> fct;

        int x = inp[i];
        while(x > 1) {
            fct[sm[x]]++;
            x = x / sm[x];
        }

        for(auto it : fct) {
            pw[it.first] = max(pw[it.first], it.second);
        }

    }

    ll mult = 1;

    for(int i = 2; i < 1000010; i++) {
        if(pw[i]) {
            mult = (mult * modpow(i, pw[i]))%mod;
        }
    }

    vector<ll> ans(n);

    ll sum = 0;

    for(int i = 0; i < n; i++) {
        ans[i] = (mult * modpow(inp[i], mod - 2))%mod;
        sum = (sum + ans[i])%mod;
    }

    cout<<sum<<endl;


}


Measured memory_bytes: 8960
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

struct before_main{before_main(){cin.tie(0); ios::sync_with_stdio(false);}} before_main;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

namespace math { namespace integer {

template<class value_type> value_type mod_mul(value_type x, value_type k, ll m) { if(k == 0) { return 0; } if(k % 2 == 0) { return mod_mul((x+x) % m, k/2, m); } else { return (x + mod_mul(x, k-1, m)) % m; } }
template<class value_type> value_type mod_pow(value_type x, value_type n, ll mod) { if(n == 0) { return 1; } if(n % 2 == 0) { return mod_pow(mod_mul(x, x, mod) % mod, n / 2, mod); } else { return mod_mul(x, mod_pow(x, n - 1, mod), mod); } }
template<class value_type> value_type extgcd(value_type a, value_type b, value_type& x, value_type& y) { value_type d = a; if(b != 0) { d = extgcd(b, a%b, y, x); y -= (a / b) * x;} else { x = 1, y = 0; } return d; }
template<class value_type> value_type mod_inverse(value_type x, ll mod) { return mod_pow(x, value_type(mod-2), mod); /* use fermat */ }
template<class value_type> value_type mod_inverse_composite_num_mod(value_type a, ll mod) { value_type x, y; extgcd(a, mod, x, y); return (mod + x % mod) % mod; }

}}
using namespace math::integer;
template<class T>
T lcm(T x, T y) {
  return x / __gcd(x, y) * y;
}

int main() {

  for(int A, B, d; cin >> A >> B >> d && (A|B|d);) {
    int G = __gcd(__gcd(A, B), d);
    A /= G, B /= G, d /= G;
    ll ans = 1e18, axby = 1e18; int tx = -1, ty = -1;
    for(int sgn=-1; sgn<2; sgn+=2) {
      int a = sgn * A, b = -sgn * B;
      int x, y; int g = extgcd(a, b, x, y);
      x *= d / g, y *= d / g;
      ll L = lcm(a, b);
      for(int i=0; i<50000; i++) {
        if(x >= 0 || y >= 0) {
          if(minimize(ans, abs(x) + abs(y))) {
            axby = a * x + b * y;
            tx = x, ty = y;
          }
          else if(ans == abs(x) + abs(y)) {
            if(minimize(axby, (ll)a * x + b * y)) {
              tx = x, ty = y;
            }
          }
        }
        x += L / abs(a);
        y += L / abs(b);
      }
    }
    cout << abs(tx) << " " << abs(ty) << endl;

  }
  
  return 0;
}

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

typedef long long ll;

#define PB push_back
#define MP make_pair

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
    char a; cin >> a;
    if (isupper(a)) cout << 'A' << "\n";
    else cout << 'a' << "\n";
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* print new lines
*/

Measured memory_bytes: 3648
// abc149_a
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(int argc, char *argv[])
{
  string s,t;
  cin>>s>>t;
  cout<<t<<s<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>



int main() {
    int w, a, b, rez;
    scanf("%d%d%d", &w, &a, &b);
    if (a < b) {
        if (a + w < b) {
            rez = b - a - w;
            printf("%d", rez);
        }
        else
            printf("0");

    } else {
        if (b + w < a) {
            rez = a - b - w;
            printf("%d", rez);
        }
        else
            printf("0");
    }
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

class Main{
  static void trace(int[] a){
    int i;
    for(i = 0; i < a.length - 1; i++)
      System.out.print(a[i] + " ");
    System.out.println(a[i]);
  }

  public static void main(String[] args){
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int a[] = new int[n];
    for(int i = 0; i < n; i++)
      a[i] = stdIn.nextInt();

    int count = 0;
    for(int i = 0; i < n; i++)
      for(int j = n-1; j > i; j--){
        if(a[j] < a[j-1]){
          int tmp = a[j];
          a[j] = a[j-1];
          a[j-1] = tmp;
          count++;
        }
      }

    trace(a);
    System.out.println(count);

  }
}

Measured memory_bytes: 26308
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  string s;
  vector<string> v;
  map<string,int> m;
  for(int i=0;i<n;i++)
  {
    cin>>s;
    m[s]++;
    
  }
  map<string,int>::iterator itr;
  int max=INT_MIN;
  for(itr=m.begin();itr!=m.end();itr++)
  {
    
    if(itr->second>max)
      max=itr->second;
    
    
  }
  for(itr=m.begin();itr!=m.end();itr++)
  {
    if(itr->second==max)
      v.push_back(itr->first);
    
  }
  sort(v.begin(),v.end());
  for(int i=0;i<v.size();i++)
  {
    cout<<v[i]<<endl;
  }
  
  
  
  
}

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

void print(int A[],char a){ 
    for(int i=1;i<14;i++){
        if(A[i]==0)cout<<a<<" "<<i<<"\n";
    }   
}

int main(){
    int n,tmp;
    char mark;
    int S[14],H[14],C[14],D[14];

    for(int i=1;i<14;i++)S[i]=H[i]=C[i]=D[i]=0;
    cin>>n;
    for(int i=0;i<n;i++){                                  
      cin>>mark>>tmp;  
      switch(mark){
        case 'S':
            S[tmp]=1;
            break;
        case 'H':
            H[tmp]=1;
            break;
        case 'C':
            C[tmp]=1;
            break;
        case 'D':
            D[tmp]=1;
            break;
                
      }   

    }   
    print(S,'S');
    print(H,'H');
    print(C,'C');
    print(D,'D');
    return 0;
        
}



Measured memory_bytes: 3068
#include "bits/stdc++.h"
using namespace std;
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2233&lang=jp
typedef long long ll;
typedef long double ld;
#define INF 1<<30
#define LINF 1<<60
const double eps = 1e-9;

inline double calc_w(int c1,int pre_c1, int c2,int pre_c2, vector<pair<int, int>>& city) {
	double l1_x = city[c1].first - city[pre_c1].first;
	double l1_y = city[c1].second - city[pre_c1].second;

	double l2_x = city[c2].first - city[pre_c2].first;
	double l2_y = city[c2].second - city[pre_c2].second;

	double _cos = (l1_x*l2_x + l1_y*l2_y) / (double)(hypot(l1_x, l1_y)*hypot(l2_x, l2_y));
	if (1 - _cos < eps)return 0.0;
	if (1 + _cos < eps)return 180.0;
	return abs(acos(_cos) * 180 / acos(-1));
}

struct edge {
	int now_city;
	int pre_city;
	int have_carrot;
	double full_len;
	edge() {}
	edge(int now, int pre,int car, double len) :now_city(now), pre_city(pre),have_carrot(car),full_len(len) {}
};

int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
	/* input */
	int n; cin >> n;
	double r, theta; cin >> r >> theta;
	vector<pair<int, int>> city(n);
	for (int i = 0; i < n;i++) { int x, y; cin >> x >> y; city[i] = { x,y }; }

	/* initialize */
	vector<vector<double>> dist(n, vector<double>(n,0));
	vector<vector<vector<int>>> G(n, vector<vector<int>>(n));
	vector<vector<vector<double>>> dp(n, vector<vector<double>>(n, vector<double>(10010, INF)));

	int ans = 0;
	queue<edge> q;
	for (int i = 0; i < n;i++) {
		for (int j = i + 1; j < n;j++) {
			double d = hypot(city[i].first - city[j].first, city[i].second - city[j].second);
			dist[i][j] = dist[j][i] = d;
			if ((i == 0) && (d <= r)) {
				dp[j][i][1] = d;
				q.push(edge(j, i, 1, d));
				ans = 1;
			}
		}
	}

	for (int i = 0; i < n;i++) {
		for (int j = 0; j < n;j++) {
			for (int k = 0; k < n;k++) {
				if (i == j || j == k || i == k)continue;
				if (calc_w(j, i, k, j, city) < theta + eps) G[j][i].push_back(k);
			}
		}
	}

	while (!q.empty()) {
		auto p = q.front(); q.pop();
		int now_city = p.now_city, pre_city = p.pre_city;
		int have_carrot = p.have_carrot;
		double len = p.full_len;
		if (len > dp[now_city][pre_city][have_carrot]) continue;
		for (int next_city : G[now_city][pre_city]) {
			if (next_city == now_city || next_city == pre_city)continue;
			if (dist[now_city][next_city] + len < r + eps) {
				if (dp[next_city][now_city][have_carrot + 1] > len + dist[next_city][now_city]) {
					dp[next_city][now_city][have_carrot + 1] = len + dist[next_city][now_city];
					q.push(edge(next_city, now_city, have_carrot + 1, dist[next_city][now_city] + len));
					ans = max(ans, have_carrot + 1);
				}
			}
		}
	}
	cout << ans << endl;
}

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

int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  while(true){
   C = C - B;
    if(C <= 0){
      cout << "Yes" << endl;
      break;
    }
   A = A - D;
    if(A <= 0){
      cout << "No" << endl;
      break;
    }
  }
  
  return 0;
  
}

Measured memory_bytes: 3596
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int n, k;
string s;

void solve() {
  char t = s[k - 1];
  for (auto c : s) {
    if (c == t)
      cout << c;
    else
      cout << '*';
  }
  cout << endl;
}

int main() {
  cin >> n >> s >> k;
  solve();
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 101
#define INF 99999999
#define WHITE 0
#define BLACK 1
#define GRAY 2


int n,A[MAX][MAX],d[MAX],color[MAX],pi[MAX];




void dijkstra(void){
  int mincost,i,v,u;

  
  for(i=0;i<n;i++){
    d[i]=INF;
    color[i]=WHITE;
  }
  d[0]=0;
  color[0]=GRAY;

  while(1){
    mincost=INF;
    for(i=0;i<n;i++){
      if(color[i]!=BLACK && d[i]<mincost){
	mincost=d[i];
	u=i;
      }
    }
    if(mincost==INF){
      break;
    }
    color[u]=BLACK;
    for(v=0;v<n;v++){
      if(color[v]!=BLACK && d[u]+A[u][v]<d[v]){
	pi[v]=u;
	d[v]=d[u]+A[u][v];
      }
    }
  }
}


int main(){
  int i,j,u,k,v,c;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      A[i][j]=INF;
    }
  }
  
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&v,&c);
      A[u][v]=c;
    }
  }

  dijkstra();

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


  



Measured memory_bytes: 2048
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

using namespace std;

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

	string a, b;
	cin >> a >> b;

	int ia = a[0] - '0';
	int ib = b[0] - '0';

	string sa;
	for (int i = 0; i < ia; i++)
	{
		sa.push_back(b[0]);
	}

	string sb;
	for (int i = 0; i < ib; i++)
	{
		sb.push_back(a[0]);
	}

	cout << ((sa < sb) ? sa : sb);

	return 0;
}

Measured memory_bytes: 3616
using System;
using System.Text;

namespace ALDS1_2_B
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int N = int.Parse(input);
            int[] list = new int[N];
            input = Console.ReadLine();
            string[] num = input.Split(' ');
            for (int i = 0; i < N; i++)
            {
                list[i] = int.Parse(num[i]);
            }

            selectionSort(list, N);

        }

        public static void selectionSort(int[] arr, int N)
        {
            int tmp, minj;
            int count = 0;
            
            for (int i = 0; i < N; i++)
                {
                    minj = i;
                    for (int j = i; j < N; j++)
                    {
                        if (arr[j] < arr[minj])
                        {
                            minj = j;
                        }
                    }
                    if (i != minj)
                    {
                        tmp = arr[i];
                        arr[i] = arr[minj];
                        arr[minj] = tmp;
                        count++;
                    }
                }

            string output = ArrayJoin(arr);
            Console.WriteLine(output);
            Console.WriteLine(count);

        }

        private static string ArrayJoin(int[] arr)
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < arr.Length; i++)
            {
                if (sb.Length > 0)
                {
                    sb.Append(" ");
                }
                sb.Append(arr[i]);
            }
            return sb.ToString();
        }
    }
}

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

typedef long long ll;
string S;
int main()
{
    cin >> S;
    ll res = 0;
    int Sl = S.length();
    map<ll, ll> V;
    for(int i = 0; i < 2019; i++) V.insert(make_pair(i, 0));
    ll MOD = 1;
    ll Ti;
    for(int i = Sl; i >= 0; i--)
    {
        if(i == Sl) 
        {
            Ti = 0;
            V[Ti]++;
        }
        else
        {
            MOD *= Sl - 1 - i > 0 ? 10 : 1;
            MOD %= 2019;
            Ti = MOD * (S[i] - '0') + Ti;
            Ti %= 2019;
            V[Ti]++; 
        }
    }
    for(int i = 0; i < 2019; i++)
    {
        res += V[i] * (V[i] - 1) / 2;
    }



    cout << res << endl;
}

Measured memory_bytes: 3704
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 2e5 + 10;
char label[maxn];
struct edge{
	int v,next;
	edge(int v = 0,int next = 0) : v(v), next(next) {}
} e[maxn * 2];
int hd[maxn] , ek = 1;
inline void adde(int u,int v){
	e[ek] = edge(v,hd[u]);
	hd[u] = ek++;
}
int clock;
bool dfs(int len,char pas,int u){
	++clock;
	if(clock >= 3e7) return 0;
	for(int i = hd[u];i;i = e[i].next){
		int v = e[i].v;
		if(label[v] == pas) continue;
		if(len >= 3e5) return 1;
		if(dfs(len + 1,label[u],v)) return 1;
	}
	return 0;
}
int main(){
	int n,m;
	scanf("%d%d%s",&n,&m,label + 1);
	for(int i = 1;i <= m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		adde(u,v); adde(v,u);
	}
	for(int i = 1;i <= n;i++)if(dfs(1,'$',i)) return !printf("Yes"); 
	return !printf("No");
} 

Measured memory_bytes: 18304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int infint = 1e9;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)803;
int h, w, k, dist[MAXN][MAXN], x[4] = {-1, 1, 0, 0}, y[4] = {0, 0, 1, -1};
char c[MAXN][MAXN];
int saboon(int x, int y)
{
	int T = min(min(x, y), min(h - 1 - x, w - 1 - y));
	return T / k + (T % k > 0);
}
bool valid(int x, int y)
{
	return x >= 0 && x < h && y >= 0 && y < w;
}
void bfs(int u, int v)
{
	queue< pair<int, int> > q;
	q.push({u, v});
	while(!q.empty())
	{
		pair<int, int> st = q.front();
		q.pop();
		int X = st.first, Y = st.second;
		for (int i = 0; i < 4; i++)
		{
			int nwx = X + x[i], nwy = Y + y[i];
			if(valid(nwx, nwy) && c[nwx][nwy] == '.' && dist[nwx][nwy] > dist[X][Y] + 1)
			{
				dist[nwx][nwy] = dist[X][Y] + 1;
				q.push({nwx, nwy});
			}
		}
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> h >> w >> k;
	int stx = -1, sty = -1;
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
		{
			cin >> c[i][j];
			dist[i][j] = infint;
			if(c[i][j] == 'S')
				dist[i][j] = 0, stx = i, sty = j;
		}
	int ans = saboon(stx, sty);
	//javab ya ans e ya ans + 1 pas mikhaim bebinim ans hast ya na.
	bfs(stx, sty);
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			if(dist[i][j] <= k && saboon(i, j) == ans - 1)
				return cout << ans, 0;
	cout << ans + 1;
}

Measured memory_bytes: 3456
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))


INF = float("inf")
MOD = 10**9 + 7


def main():
    from bisect import bisect_right
    from itertools import accumulate
    N, M, K = MAP()
    A = LIST()
    B = LIST()

    A = [0] + list(accumulate(A)) + [INF]
    B = [0] + list(accumulate(B)) + [INF]

    ans = 0
    for i in range(N + 1):
        j = bisect_right(B, K - A[i]) - 1
        if j < 0:
            continue
        ans = max(i + j, ans)
    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 41304
//g++ -std=c++17 -Wshadow -Wall -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g PROGRAM -o OUTPUT -DLOCAL -lasan -lubsan
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define alli(a, n, k) (a + k), (a + n + k)
#define FP(i, a, b, k) for (__typeof(a) i = a; i < b; i += k)
#define FS(i, a, b, k) for (__typeof(a) i = a; i > b; i -= k)
#define IT(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template <class T>
inline T gcd(T x, T y)
{
    if (!y)
        return x;
    return gcd(y, x % y);
}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef vector<pair<int, PII>> VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;


inline ll modulo(ll a, ll m)
{
    return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
    assert(__gcd(a, m) == 1);
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m, a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
    if (y == 0)
        return 1LL;
    else if (y == 1)
        return x;
    else
    {
        ll ans = modPow(x, y / 2, m) % m;
        if (y & 1)
        {
            return (((ans * ans) % m) * x) % m;
        }
        else
        {
            return (ans * ans) % m;
        }
    }
}

vector<string> split(char d,string s)
{
    stringstream ss(s);
    string t;
    vector<string> words;
    while(getline(ss,t,d))
    {
        words.pb(t);
    }

    return words;
}

int main(int argc, char *argv[])
{
#ifdef LOCAL
    auto start = chrono::high_resolution_clock::now();
#endif
    
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int n,x,t;
    cin >> n >> x >> t;
    int v = 0,c=0;
    while(v<n)
        v += x, c += t;

    cout << c;

    exit(0);
#ifdef LOCAL
    auto end = chrono::high_resolution_clock::now();
    double time_taken =
        chrono::duration_cast<chrono::nanoseconds>(end - start).count();

    time_taken *= 1e-9;

    cerr << "\nTime taken by program is : " << fixed
         << time_taken << setprecision(9);
    cerr << " sec" << endl;
#endif
    return 0;
}


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

int X[101], Y[101];

int main(){
	int n, m, x, y;
	cin >> n >> m >> x >> y;
	
	for(int i=0; i<n; i++) cin >> X[i];
	for(int i=0; i<m; i++) cin >> Y[i];
	
	bool exist = false;
	
	if(y <= x){
		cout << "War" << endl;
		return 0;
	}
	
	for(int z=x+1; z<=y; z++){
		exist = true;
		for(int i=0; i<n; i++) if(X[i] >= z) exist=false;
		for(int i=0; i<m; i++) if(Y[i] < z) exist=false;
		if(exist){
			cout << "No War" << endl;
			return 0;
		}
	}
	cout << "War" << endl;
	
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;
ll fact[2001],inv_fact[2001];
ll mod_pow(ll a, ll n) {
	if(n==0) return 1;
	if(n%2==0) {
		ll tmp=mod_pow(a,n/2);
		return (tmp*tmp)%MOD;
	}
	return (a*mod_pow(a,n-1))%MOD;
}
ll comb(ll n, ll k) {
	if(n<k) return 0;
	ll tmp=fact[n];
	(tmp*=inv_fact[k])%=MOD;
	(tmp*=inv_fact[n-k])%=MOD;
	return tmp;
}
int main() {
	int N,K;
	cin>>N>>K;
	fact[0]=inv_fact[0]=1;
	for(int i=1;i<=N;i++) {
		fact[i]=fact[i-1]*i%MOD;
		inv_fact[i]=inv_fact[i-1]*mod_pow(i,MOD-2)%MOD;
	}
	for(int i=1;i<=K;i++) {
		ll ans=comb(N-K+1,i);
		(ans*=comb(K-1,i-1))%=MOD;
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
a=A[0]
b=A[N-1]
hidari=1
migi=N-2

for i in range(N-2):
    if a<=b:
        a+=A[hidari]
        hidari+=1
    
    elif a>b:
        b+=A[migi]
        migi-=1

print(abs(a-b))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define debug(...) { printf("#  "); printf(__VA_ARGS__); puts(""); }
#define fi first
#define se second
#define endl "\n" 
using ll = long long;
using pII = pair <int, int>;
using pLL = pair <ll, ll>;
using VI = vector <int>;
using VL = vector <ll>;
constexpr int mod = 1e9 + 7;
template <class T1, class T2> inline void chadd(T1 &x, T2 y) { x += y; while (x >= mod) x -= mod; while (x < 0) x += mod; } 
template <class T1, class T2> inline void chmax(T1 &x, T2 y) { if (x < y) x = y; }
template <class T1, class T2> inline void chmin(T1 &x, T2 y) { if (x > y) x = y; }
inline int rd() { int x; cin >> x; return x; }
template <class T> inline void rd(T &x) { cin >> x; }
template <class T> inline void rd(vector <T> &vec) { for (auto &it : vec) cin >> it; }
template <class T> inline void out(T s) { cout << s << "\n"; }
template <class T> inline void out(vector <T> &vec) { for (auto &it : vec) cout << it << " "; cout << endl; } 
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll qpow(ll base, ll n) { ll res = 1; while (n) { if (n & 1) res = res * base % mod; base = base * base % mod; n >>= 1; } return res; }
constexpr int N = 1e5 + 10;
int n, m;   
void run() {
	priority_queue <int> pq;
	for (int i = 1, x; i <= n; ++i) {
		cin >> x;
		pq.push(x);
	}
	while (m-- && !pq.empty()) {
		int t = pq.top();
		pq.pop();
		if (t / 2) pq.push(t / 2);
	}
	ll res = 0;
	while (!pq.empty()) {
		res += pq.top();
		pq.pop();
	}
	cout << res << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	cout << fixed << setprecision(20);
	while (cin >> n >> m) run();
	return 0;
}


Measured memory_bytes: 892
//#include <bits/stdc++.h>
 
#include <iostream>
#include <algorithm>
 
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <cstring>
#include <string>
#include <utility>
#include <array>
#include <complex>
#include <valarray>
 
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <chrono>
#include <random>
#include <numeric>
 
 
using namespace std;
#define int long long
 
typedef long long ll;
typedef unsigned long long ull;
//typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef pair<ll,pll> plpll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;
 
#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
 
const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const int INF = 1<<30;
const ll INFLL = 1LL<<62;
const double EPS = 1e-12;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;
 
#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod
#define inside(y, x, h, w) (0 <= (y) && (y) < (h) && 0 <= (x) && (x) < (w)) ? true : false

int n, q;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
	cin >> n >> q;
	rep(i, q) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		if (n == 1) {
			cout << min(u + 1, v + 1) << endl;
			continue;
		}
		while (u != v) {
			if (u > v) {
				u = (u - 1) / n;
				continue;
			}
			if (v > u) {
				v = (v - 1) / n;
				continue;
			}
		}
		cout << u + 1 << endl;
	}
}


Measured memory_bytes: 1280
def get_num_inversions(A, left, right):
    num_inversions = 0
    if right - left <= 1:
        return num_inversions

    mid = (left+right) // 2
    num_inversions += get_num_inversions(A, left, mid)
    num_inversions += get_num_inversions(A, mid, right)
    num_inversions = merge(A, left, mid, right, num_inversions)

    return num_inversions


def merge(A, left, mid, right, num_inversions):
    n1 = mid - left
    n2 = right - mid
    L = [A[left+i] for i in range(n1)]
    R = [A[mid+i] for i in range(n2)]

    L.append(1e10)
    R.append(1e10)

    i = 0
    j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
            num_inversions += len(L) - i - 1 # -1はappendした1e10の分

    return num_inversions


def main():
    n = int(input())
    A = list(map(int, input().split()))
    print(get_num_inversions(A, 0, n))


if __name__ == '__main__':
    main()


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

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


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    string s,t;
    cin >> s >> t;
    ll tplace = -1;
    repd(i,0,s.length()-t.length()+1){
      bool good = true;
      rp(j,t.length()){
        if(s[i+j] != t[j] && s[i+j] != '?'){
          good = false;
          break;
        }
      }
      if(good){
        tplace = i;
        break;
      }

    }
    if(tplace == -1) cout << "UNRESTORABLE"<<endl;
    else {
      rep(i,tplace,tplace+t.length()){
        s[i] = t[i-tplace];
      }
      rp(i,s.length()){
        if(s[i] == '?') s[i] = 'a';
      }
      cout << s << endl;
    }

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)
colors = {}
special = 0
for i in 0...n do
  if a[i] < 3200
    c = a[i] / 400
    colors[c] = true
  else
    special += 1
  end
end
puts "#{[colors.size, 1].max} #{colors.size + special}"


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

int main() {
  int N, ans = 1000, index;
  double sum = 0;
  int a[100];
  cin >> N;
  for(int i=0;i<N;++i) {
    cin >> a[i];
    sum += a[i];
  }

  sum/=N;

  for(int i=0; i<N; ++i) {
    if(abs(ans-sum)>abs(a[i]-sum)) {
      ans = a[i];
      index = i;
    }
  }

  cout << index << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int c[3],comp[4],ans;
int abs(int n)
{
	return n>0?n:-n;
}
void dfs(int ceng,int last,int has_cost)
{
	if(ceng==3){ans=(ans>has_cost || ans==0)?has_cost:ans;return;}
	for(int i=0;i<3;i++)
	{
		if(comp[i])continue;
		comp[i]=1;
		//cout<<ceng<<" "<<has_cost<<" "<<abs(c[last]-c[i])<<endl;
		if(ceng==0)dfs(ceng+1,i,0);
		else dfs(ceng+1,i,has_cost+abs(c[i]-c[last]));
		comp[i]=0;
	}
	return;
}
int main()
{
	cin>>c[0]>>c[1]>>c[2];
	dfs(0,0,0);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main() {
  int a, b;
  cin >> a >> b;
  cout << ceil((double)(b-1)/(double)(a-1)) << endl;
  return 0;
}

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

using namespace std;

#define int long long
#define MKP make_pair
typedef pair<int, int> pii;

constexpr int MAX_N = 305;
constexpr int INF = 1LL << 60;

int n, mem[MAX_N][MAX_N], w[MAX_N];

int solve(int l, int r) {
    if (r - l <= 1) {
        return 0;
    }
    if (mem[l][r] != -1) {
        return mem[l][r];
    }

    int res = 0;
    for (int i = l + 1; i < r; ++i) {
        res = max(res, solve(l, i) + solve(i, r));
    }

    if (abs(w[l] - w[l + 1]) <= 1) {
        res = max(res, solve(l + 2, r) + 2);
    }
    if (abs(w[r - 1] - w[r - 2]) <= 1) {
        res = max(res, solve(l, r - 2) + 2);
    }
    if (abs(w[l] - w[r - 1]) <= 1) {
        int tmp = solve(l + 1, r - 1);
        if (tmp == r - l - 2) {
            res = max(res, tmp + 2);
        }
    }

    return mem[l][r] = res;
}

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

    while(1) {
        cin >> n;
        if (n == 0) {
            return 0;
        }
        memset(mem[0], -1, sizeof(mem));

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

        cout << solve(0, n) << endl;
    }
}



Measured memory_bytes: 3976
#include <iostream>
#include <vector>
using namespace std;
 
int main(){
	int N, amesum, tmpame, tmpsum, minsum = 20000;
	cin >> N;
	vector<int>Ame(2*N);
	for(int i = 0; i < 2*N; i++){
		cin >> tmpame;
		Ame[i] = tmpame;
		amesum = amesum + tmpame;
	}
	for(int i = 1; i <= N; i++){
		tmpsum = 0;
		for(int j = 0; j < N-1; j++){
			tmpsum = tmpsum + Ame[i+j];
		}
		if(tmpsum < minsum)minsum = tmpsum;
	}
	cout << amesum - minsum;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
l = []
sumB = 0
for i in range(N):
    a, b = map(int, input().split())
    l.append(a + b)
    sumB += b
l.sort(reverse=True)
A = 0
for i in range(0, N, 2):
        A += l[i]
print(A - sumB)

Measured memory_bytes: 7388
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

int main(){
    ll x;
    cin >> x;
    ll now = 100;
    int cnt = 0;
    while(1){
        if(now >= x){
            cout << cnt << enld;
            return 0;
        }
        now += now/100;
        cnt++;
    }
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define pa pair<int,int>
const int N=1e6+10;
const int mod=1e9+7;
using namespace std;

int main()
{   
     int n; scanf("%d",&n);
     vector<pa> v;
     for(int i=1;i<=n;i++)
     {
        for(int j=i+1;j<=n;j++)
        {
          if(i+j==n/2*2+1) continue;
          v.pb(mkp(i,j));
        }
     }
     printf("%d\n",(int)v.size());
     for(auto e:v) printf("%d %d\n",e.fi,e.se);
return 0;
}
/*
*/

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define M 1000000007
#define pb push_back
#define ll long long int
using namespace std;

int main()
{
	int n,W;
	cin>>n>>W;
	long long dp[n][W+1];
	int i,j;
	int w[n],v[n];
	for(i=0;i<n;i++)
		cin>>w[i]>>v[i];

	for(i=0;i<n;i++)
	{
		for(j=0;j<=W;j++)
		{
			if(i==0)
			{
				if(w[i]>j)
					dp[i][j] = 0;
				else
					dp[i][j] = v[i];
				continue;
			}

			if(w[i]>j)
			{
				dp[i][j] = dp[i-1][j];
			}
			else
				dp[i][j] = max(dp[i-1][j],v[i]+dp[i-1][j-w[i]]);
		}
	}
	cout<<dp[n-1][W];
	return 0;

}


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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

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

    const int MAX = 3500;
    for (int x = 1; x <= MAX; x++) {
        for (int y = 1; y <= MAX; y++) {
            double z1 = ((double)N * x * y);
            double z2 = (4.0 * x * y - (double)N * y - (double)N * x);

            if (z2 == 0) { // ０で割ることはできないから
                continue;
            }

            double z = z1 / z2;
            // zが正の整数ならそれが正解
            if (z > 0) { // まず、zが正である
                int z_cp = (int)z;
                if (z - z_cp == 0) { // zが整数である
                    cout << x << " " << y << " " << z_cp << endl;
                    return 0;
                }
            }

        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
	  result=(result*base)%modulus;
	  exponent=exponent>>1;
	  base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
	if(N<K)return 0;
	if(K==0)return 1;
	if(N==0)return 0;

	ll den=1;
	for(ll i=1;i<=K;i++)den*=i;
	ll num=1;
	while(K--){
		num*=N;
		if(num%den==0){
			num/=den;
			den=1;
		}
		N--;
	}

	return num;
}
*/
ll a[MAX];
ll n;
int main(){FAST;
cin>>n;
for(ll i=1;i<=n;i++){
	cin>>a[i];
}
for(ll i=n;i>=1;i--){
	if(a[i]<a[i-1]){
		a[i-1]--;
	}
}
for(ll i=1;i<=n-1;i++){
	if(a[i+1]<a[i]){
		cout<<"No";
		return 0;
	}
}
cout<<"Yes";
return 0;
}

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

// ゴリ押し
int main() {
  int input;
  cin >> input;
  int a = input / 1000;
  int b = (input - a * 1000) / 100;
  int c = (input - a * 1000 - b * 100) / 10;
  int d = input % 10;

  int t1 = a + b + c + d;
  int t2 = a + b + c - d;
  int t3 = a + b - c + d;
  int t4 = a - b + c + d;
  int t5 = a + b - c - d;
  int t6 = a - b - c + d;
  int t7 = a - b + c - d;
  int t8 = a - b - c - d;

  if (t1 == 7) {
    cout << a << "+" << b << "+" << c << "+" << d << "=7" << endl;
    return 0;
  } else if (t2 == 7) {
    cout << a << "+" << b << "+" << c << "-" << d << "=7" << endl;
    return 0;
  } else if (t3 == 7) {
    cout << a << "+" << b << "-" << c << "+" << d << "=7" << endl;
    return 0;
  } else if (t4 == 7) {
    cout << a << "-" << b << "+" << c << "+" << d << "=7" << endl;
    return 0;
  } else if (t5 == 7) {
    cout << a << "+" << b << "-" << c << "-" << d << "=7" << endl;
    return 0;
  } else if (t6 == 7) {
    cout << a << "-" << b << "-" << c << "+" << d << "=7" << endl;
    return 0;
  } else if (t7 == 7) {
    cout << a << "-" << b << "+" << c << "-" << d << "=7" << endl;
    return 0;
  } else if (t8 == 7) {
    cout << a << "-" << b << "-" << c << "-" << d << "=7" << endl;
    return 0;
  }

}


Measured memory_bytes: 256
N, Q = [int(i) for i in input().split()]
S = input()

cnt = [0] * (N+1)
for i in range(1, N):
    cnt[i+1] = cnt[i]
    if S[i-1:i+1] == 'AC':
        cnt[i+1] = cnt[i+1] + 1
        
for _ in range(Q):
    l, r = [int(i) for i in input().split()]
    ans = cnt[r] - cnt[l-1] - (S[l-2:l] == 'AC')
    print(ans)
    
        


Measured memory_bytes: 6096
#include <iostream>
#include <cstdlib>

using namespace std;

int a, b;

int main()
{
    while(true){
        cin >> a >> b;
        if(a==0 && b==0) break;
        if(a>b){
            cout << b << " " << a << endl;
        } else {
            cout << a << " " << b << endl;
        }
    }
}




Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1003;
const ll D=1e18;

ll odl[N];
ll kr[N][N];

bool pos[N],bl[N];

vector<int> G[N];

bool df(int v);

 int main()
 {
	ll n,m,i;
	scanf("%lld%lld",&n,&m);

	ll a,b,c;

	for(i=1;i<=n;i++)
	{
		odl[i]=D;
		for(int j=1;j<=n;j++) kr[i][j]=D;
	}

	for(i=1;i<=m;i++)
	{
		scanf("%lld%lld%lld",&a,&b,&c);
		G[a].push_back(b);
		kr[a][b]=min(kr[a][b],-c);
	}

	for(i=1;i<=n;i++) pos[i]=false, bl[i]=false;
	pos[n]=true;
	bl[n]=true;

	for(i=1;i<=n;i++)
	{
		if(!bl[i])
		{
			df(i);
		}
	}


	odl[1]=0;
	int z;
	z=2*n;

	while(z--)
	{
		for(i=1;i<=n;i++)
		{
			if(odl[i]!=D)
			{
				for(int j=0;j<(int)G[i].size();j++)
				{
					odl[G[i][j]]=min(odl[G[i][j]],odl[i]+kr[i][G[i][j]]);
				}
			}
		}
	}

	for(i=1;i<=n;i++)
	{
		if((odl[i]!=D)&&(pos[i]))
		{
			for(int j=0;j<(int)G[i].size();j++)
			{	
				if(odl[G[i][j]]>odl[i]+kr[i][G[i][j]])
				{
					printf("inf\n");
					return 0;
				}
			}
		}
	}

	printf("%lld\n",-odl[n]);
	return 0;
 }
/////
 bool df(int v)
 {
	bl[v]=true;

	for(int i=0;i<(int)G[v].size();i++)
	{
		if(!bl[G[v][i]])
		{
			df(G[v][i]);
		}

		if(pos[G[v][i]])
		{
			pos[v]=true;
			return true;
		}
	}

	return false;
 }


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

const int MX = 100005;

int main(){
    int h,w,k;
    cin >> h >> w >> k;
    int zenbu = 0;
    int kotae = 0;
    int cnt = 0;

    vector<vector<int>> banmen(h,vector<int>(w));
    for(int i = 0;i<h;i++){
        string atai;
        cin >> atai;        
        for(int j =0;j<w;j++){
            if(atai[j] == '#'){
                banmen[i][j] = 1;
                cnt++;
                zenbu++;
            }
            else{
                banmen[i][j] = 0;
            }
        }
    }

    if(cnt < k){
        cout << "0" << endl;
        return 0;
    }

/*
    if(cnt == k){
        kotae++;
    }
    */

    int hw = h+w;
    int saidai = pow(2,hw);

    for(int l = 0;l<saidai;l++){
        bitset<12> ss(l+1);
//        string s = ss.str();
        cnt = 0;
        for(int i = 0;i<h;i++){
            for(int j =0;j<w;j++){
                //if((ss[(12-hw)+i] != 1)&&(ss[(12-hw)+h+j] != 1)){
                if((ss[i] != 1)&&(ss[h+j] != 1)){
                    if(banmen[i][j] == 1){
                        cnt++;
                    }
                }
            }
        }
        if(cnt == k){
            kotae++;
        }
    }

    cout << kotae << endl;

    return 0;
}


Measured memory_bytes: 4016
#include <iostream>
#include <set>
using namespace std;
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main(){
  int c,n;cin>>c>>n;
  int ans = 0;
  char mp[n][n];
  for(int i = 0; n > i; i++){
    for(int j = 0; n > j; j++){
      cin>>mp[i][j];
    }
  }
  set<int> all;
  set<int> a[n*n/4];
  for(int i = 0; n/2 > i; i++){
    for(int j = 0; n/2 > j; j++){
      if(mp[i][j]=='1')a[i*n/2+j].insert(1);
      if(mp[n-i-1][j]=='1')a[i*n/2+j].insert(2);
      if(mp[i][n-j-1]=='1')a[i*n/2+j].insert(3);
      if(mp[n-i-1][n-j-1]=='1')a[i*n/2+j].insert(4);
      if(a[i*n/2+j].size()%4==0)all.insert(i*n/2+j);
    }
  }
  bool ok = true;
  //cout << endl;
  for(int i = 0; n*n/4 > i; i++){
    //cout << a[i].size() << " ";
    if(a[i].size()%4!=0){
      ok = false;
      //break;
    }
  }
  //cout << endl;
  if(ok)ans++;
  for(int i = 1; c > i; i++){
    int d;cin>>d;
    for(int j = 0; d > j; j++){
      int y,z;cin>>y>>z;
      y--;z--;
      if(y >= n/2){
        if(z >= n/2){
          //4
          if(a[(n-y-1)*n/2+(n-z-1)].count(4)==0)a[(n-y-1)*n/2+(n-z-1)].insert(4);
          else a[(n-y-1)*n/2+(n-z-1)].erase(4);
          if(a[(n-y-1)*n/2+(n-z-1)].size()%4==0)all.insert((n-y-1)*n/2+(n-z-1));
          else all.erase((n-y-1)*n/2+(n-z-1));
        }else{
          //2
          if(a[(n-y-1)*n/2+z].count(2)==0)a[(n-y-1)*n/2+z].insert(2);
          else a[(n-y-1)*n/2+z].erase(2);
          if(a[(n-y-1)*n/2+z].size()%4==0)all.insert((n-y-1)*n/2+z);
          else all.erase((n-y-1)*n/2+z);
        }
      }else{
        if(z >= n/2){
          if(a[y*n/2+(n-z-1)].count(3)==0)a[y*n/2+(n-z-1)].insert(3);
          else a[y*n/2+(n-z-1)].erase(3);
          if(a[y*n/2+(n-z-1)].size()%4==0)all.insert(y*n/2+(n-z-1));
          else all.erase(y*n/2+(n-z-1));
          //3
        }else{
          if(a[y*n/2+z].count(1)==0)a[y*n/2+z].insert(1);
          else a[y*n/2+z].erase(1);
          if(a[y*n/2+z].size()%4==0)all.insert(y*n/2+z);
          else all.erase(y*n/2+z);
          //1
        }
      }
    }
    if(all.size()==n*n/4)ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 74452
#include <iostream>
using namespace std;
int main()
{
   int A , B;
   string S , T ,U;
   cin>> S >> T;
   cin>> A >> B;
   cin>> U;
   if (U==S)
    cout<< A-1 <<" "<< B << endl;
   else
    cout<< A <<" "<< B-1 << endl;
}


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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 13;

int n;
int a[MAXN];

void init ();
void input ();
void work ();



int main ()
{
	init ();
	input ();
	work ();
}



void init ()
{
	// Init Everything Here

	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method

	cin >> n;
	lpi ( i, 1, n ) cin >> a[i];
}

void work ()
{
	// main work

	int ans = 1, no = 1;
	lpi ( i, 1, n ) {
		if ( !( a[i] & 1 ) ) no <<= 1;
		ans *= 3;
	}

	cout << ( ans - no ) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(void)
{
    const long long MOD = 1e+9 + 7;

    int N = 0; cin >> N;

    vector<long long> a(N);

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

    long long result = 0;

    int bit = 0;

    for(int d = 0; d < 60; d++) {
        for(int i = 0; i < N; i++) {
            if(a[i] & (1ll << d)) {
                bit++;
            }
        }
        result += ((long long)bit * (N - bit) % MOD) * ((1ll << d) % MOD) % MOD;
        bit = 0;
    }

    cout << result % MOD << endl;

    return 0;
}


Measured memory_bytes: 2560
s=input()
t=input()
ls=len(s)
lt=len(t)
sa=[]

def change_to_a(sd):
    new_sd=""
    for i in range(len(sd)):
        if sd[i]=="?":
            new_sd+="a"
        else:
            new_sd+=sd[i]
    return new_sd

if lt > ls:
    print("UNRESTORABLE")
elif lt==ls:
    for i in range(ls):
        if s[i]!=t[i] and s[i]!="?":
            print("UNRESTORABLE")
            break
    else:
        print(t)
else:
    for i in range(0,ls-lt+1):
        for j in range(i,i+lt):
            if s[j]!=t[j-i] and s[j]!="?":
                break
            if j==i+lt-1:
                if i==0:
                    #print(0)
                    sa.append(t+change_to_a(s[lt:]))
                elif i==ls-lt:
                    #print(0)
                    sa.append(change_to_a(s[:ls-lt])+t)
                else:
                    #print(0)
                    sa.append(change_to_a(s[:i])+t+change_to_a(s[i+lt:]))

    if sa == []:
        print("UNRESTORABLE")
    else:
        print(min(sa))


Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <cmath>
int main(){
	int n, k, x, y, p;
	scanf("%d %d %d %d",&n ,&k ,&x ,&y);
	if(n <= k){
	p = n * x;
	}
	if(n >= k){
    p = k * x + (n - k) * y;
	}
	printf("%d",p);
	return 0;
}

Measured memory_bytes: 128