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

#define OnlineJudge1

#define loop(x,a,n) for(int x = a;x < n;x++)
#define NumofDigits(n) ((int)log10(n)+1)
#define CountofNumber(array,n,x)  (upper_bound(array, array+n, x)-lower_bound(array, array+n, x))
#define readline(s) getline(cin,s)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define EPS 1e-7
//#define modulo ll (1e9 + 7)
#define modulo ll (1e6 + 3)
const long double PI = 3.141592653589793238L;


typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,ll> pill;

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

#define time__(d) \
    for ( \
        auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \
        blockTime.second; \
        debug("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false \
    )

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
#ifdef OnlineJudge
    freopen("in.in","r",stdin);
    freopen("out.txt","w",stdout);
#endif
}

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

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

    sort(arr, arr + n);

    int b = arr[n / 2];

    ll sum = 0;
    for(int i = 0;i < n;i++){
        sum += abs(arr[i] - b);
    }

    cout << sum;
}

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

int main(){

    int n, i;
    long int sum=0;
    cin >> n;

    for(i=1;i<=n;i++){
        if(i%3!=0 && i%5!=0){
            sum += i;
        }
    }

    cout << sum << endl;
    return 0;

}

Measured memory_bytes: 3636
#include <stdio.h>

int main() {
  int coin_a, coin_b, price;
  scanf("%d %d %d", &coin_a, &coin_b, &price);
  if(coin_a + coin_b >= price) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 128
w,h,n = gets.chomp.split(" ").map(&:to_i)
l = 0
b = 0
n.times do
  x,y,a = gets.chomp.split(" ").map(&:to_i)
  case a
    when 1
    	l = [l,x].max
    when 2
    	w = [w,x].min
    when 3 
    	b = [b,y].max
    when 4
        h = [h,y].min
  end
end
puts [w-l,0].max*[h-b,0].max

Measured memory_bytes: 1788
#include <iostream>
#include <cmath>
#include <cstdio>
 
int main(){
  int N, M;
  std::cin >> N >> M;
  int L, R;
  std::cin >> L >> R;
  for (int i=1; i<M; ++i){
    int Ltmp, Rtmp;
    std::cin >> Ltmp >> Rtmp;
    if(L < Ltmp) L=Ltmp;
    if(R > Rtmp) R=Rtmp;
  }
  if( R+1-L>0) std::cout << R+1-L <<std::endl;
  else std::cout << 0 << std::endl; 
  return 0;
}

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

void _130() {
    int n, x;
    int l[100];
    cin >> n >> x;
    for (int i = 0; i < n; ++i) { 
        cin >> l[i];
    }

    int d = 0;
    for (int i = 0; i < n; ++i) {
        d = d + l[i];
        // cout << d << endl;
        if (d > x) {
            cout << i + 1 << endl;
            return;
        }
    }
    cout << n + 1 << endl;
}

void _131() {
    int n, l;
    cin >> n >> l;

    int sum = (l - 1) * n + (1 + n) * n / 2;
    // cout << sum << endl;

    int taste = 0;
    int min_taste = 100;
    for (int i = 0; i < n; ++i) {
        taste = l + (i + 1) - 1;
        // cout << "taste" << taste << endl;
        if (abs(taste) < abs(min_taste))
            min_taste = taste;
        // cout << min_taste << endl;
    }
    cout << sum - min_taste << endl;
}

void _132() {
    int n;
    cin >> n;
    int p[20];
    for (int i = 0; i < n; ++i) 
        cin >> p[i];

    int count = 0;
    int second_value = 0;
    for (int i = 0; i < n - 2; ++i) {
        if ((p[i] < p[i + 1]) && (p[i + 1] < p[i + 2])){
            // cout << "1:" << p[i] << " " << p[i + 1] << " " << p[i + 2] << endl;
            count++;
        }
        else if ((p[i] > p[i + 1]) && (p[i + 1] > p[i + 2])){
            // cout << "2:" << p[i] << " " << p[i + 1] << " " << p[i + 2] << endl;
            count++;
        }
    }
    cout << count << endl;
}

void _133() {
    int n, d;
    cin >> n >> d;
    int x[10][10];
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < d; ++j) {
            cin >> x[i][j];
        }
    }

    int count = 0;
    float distance = 0;
    for (int i = 0; i < n - 1; ++i) {
        for (int j = i + 1; j < n; ++j) {
            distance = 0;
            for (int k = 0; k < d; ++k) {
                distance += pow(x[i][k] - x[j][k], 2);
                // cout << x[i][k] << " " << x[j][k] << " " << distance << endl;
            }
            distance = pow(distance, 0.5);
            // cout << distance << endl;

            if (abs(distance - ceil(distance)) <= 1e-6)
                count++;
        }
    }

    cout << count << endl;
}

void _134() {
    int n, d;
    cin >> n >> d;

    cout << (n + 2 * d + 1 -1) / (2 * d + 1) << endl;
}

void _135() {
    int n, p[50];
    cin >> n;
    int conflict_count = 0;
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
        if (p[i] != (i + 1))
            conflict_count++;
    }

    if (conflict_count != 0 && conflict_count != 2){
        cout << "NO" << endl;
        return;
    }

    cout << "YES" << endl;
}

int main()
{
    _135();
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> pii;
typedef std::pair<long long, long long> pll;

using namespace std;

const long long mod = 1000000007;

struct primeFactor {
	long long prime;
	long long power;
};

std::vector<primeFactor> primeFactorization(long long number) {
	std::vector<primeFactor> primeFactors;

	if (number == 0) {
		primeFactor pf;
		pf.prime = 0;
		pf.power = 1;
		primeFactors.push_back(pf);
		return primeFactors;
	}

	long long quotient = number;
	for (long long i = 2; i*i <= quotient; ++i) {
		if (quotient%i == 0) {
			primeFactor pf;
			pf.prime = i;
			pf.power = 1;

			quotient /= i;
			while (quotient%i == 0) {
				++pf.power;
				quotient /= i;
			}

			primeFactors.push_back(pf);
		}
	}
	if (quotient != 1) {
		primeFactor pf;
		pf.prime = quotient;
		pf.power = 1;
		primeFactors.push_back(pf);
	}

	return primeFactors;
}

int countDivisor(std::vector<primeFactor> primeFactors) {
	int counter = 1;
	for (int i = 0; i < primeFactors.size(); ++i) {
		counter *= (primeFactors[i].power + 1);
	}

	return counter;
}

std::vector<long long> findDivisor(long long number) {
	std::vector<primeFactor> primeFactors = primeFactorization(number);

	std::vector<long long> divisor(countDivisor(primeFactors));
	divisor[0] = 1;

	int counter = 1;
	for (int i = 0; i < primeFactors.size(); ++i) {
		int currentSize = counter;
		for (int j = 1; j <= primeFactors[i].power; ++j) {
			long long x = 1;
			for (int k = 0; k < j; ++k) {
				x *= primeFactors[i].prime;
			}

			for (int k = 0; k < currentSize; ++k) {
				divisor[counter + k] = divisor[k] * x;
			}
			counter += currentSize;
		}
	}
	sort(divisor.begin(), divisor.end());

	return divisor;
}

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

	ll n;
	cin >> n;

	vector<ll> divisor = findDivisor(n);

	ll t = n + 2;
	ll ans;
	rep(i, divisor.size()) {
		ll p = divisor[i];
		ll q = n / p;
		if (p+q < t) {
			ans = p + q - 2;
			t = p + q;
		}
		else {
			break;
		}
	}

	cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
#include <map>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
ll a[200000];
ll rui[200001];
map<ll,int> mp;//自分より左の累積和をキーとする
int main()
{
	int n;
	ll ans=0;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	rui[0]=0;
	for(int i=0;i<n;i++)
		rui[i+1]=rui[i]+a[i];
	mp[rui[0]]++;
	for(int i=1;i<n+1;i++)
	{
		ans+=mp[rui[i]];
		mp[rui[i]]++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 15872
#include <iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[100000+5]={0};
	for(int i=0;i<n;i++)
	{
		int shu;
		cin>>shu;
		a[shu-1]++;
		a[shu]++;
		a[shu+1]++;
	}
	int max=0;
	for(int i=0;i<100000+5;i++)
		if(a[i]>max)max=a[i];
	cout<<max<<endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.*;
import java.util.stream.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);

	static void solve() {
		int w = in.nextInt();
		int h = in.nextInt();
		int x = in.nextInt();
		int y = in.nextInt();
		int r = in.nextInt();
		if (x - r < 0 || y - r < 0 || w < x + r || h < y + r) {
			out.println("No");
		} else {
			out.println("Yes");
		}
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();

		solve();
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		in.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}


Measured memory_bytes: 26404
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ll 				long long
#define int             long long int
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define modp            998244353
#define inf             (ll)1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define FIO           	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl 			'\n'
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void solve()
{
	int x, k, d;
	cin >> x >> k >> d;
	x = abs(x);
	int steps = x/d;
	if(k < steps)
		cout << x-k*d;
	else
	{
		int one = x-steps*d;
		k = k-steps;
		int second = abs(one-d);
		if(k%2)
		cout << second;
		else
			cout << one;
	}
}
 
int32_t main()
{
	FIO
    // w(t)
    {
    	solve();
    }
    return 0;
}
	

	

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7ll;

int n,m;
int a[200005],b[200005];

int main(){

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

cin>>n>>m;

for(int i=0; i<m; i++){
  int x,y;
  cin>>x>>y;
  if(x==1) a[y]=1;
  if(y==n) b[x]=1;
}

for(int i=1; i<=n; i++){
  if(a[i]==1){
    if(a[i]==b[i]){
      cout<<"POSSIBLE"<<endl;
      return 0;
    }
  }
}

cout<<"IMPOSSIBLE"<<endl;

}



Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;
using static Atcoder.IO;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
                Out.Flush();
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var N = RLong;
            var A = RSLong;

            long sum = 0;
            for (int i = 0; i < N; i++)
            {
                sum = Mod.Add(sum, A[i]);
            }
            long ans = 0;
            for (int i = 0; i < N; i++)
            {
                sum = Mod.Sub(sum, A[i]);
                long tmp = Mod.Multi(sum, A[i]);
                ans = Mod.Add(ans, tmp);
            }
            WriteLine(ans);
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a + b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

Measured memory_bytes: 47916
# get a string
s = raw_input()

if len(s) % 2 == 0:
    i, j = len(s)/2-1, len(s)/2
else:
    i, j = len(s)/2-1, len(s)/2 + 1 

ans = 0 
while i >= 0:
    if s[i] != s[j]:
        ans += 1
    i -= 1
    j += 1

print ans 

Measured memory_bytes: 2568
#include<stdio.h>

int main(void)
{
	int H;
	int W;
	int i;
	int j;
	
	while(1){
		scanf("%d %d",&H, &W);
		if(H == 0 && W == 0){
			break;
		}
		for(i = 0;i < H;i++){
			for(j = 0;j < W;j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	
	return (0);
}

Measured memory_bytes: 572
f_ = lambda: [int(x)-1 for x in input().split()]

n = int(input())
from collections import defaultdict
P = defaultdict(list)

for _ in range(n-1):
    a,b,c, = f_(); c += 1
    P[a].append((b,c))
    P[b].append((a,c))

q,k = f_(); q += 1
from collections import deque
que = deque([k])
dist = [None for i in range(n)]; dist[k] = 0

while que:
    p = que.popleft()
    for a,c in P[p]:
        if dist[a] is None:
            dist[a] = dist[p] + c
            que.append(a)

ans = []
for _ in range(q):
    x, y = f_()
    ans.append(dist[x]+dist[y])
print(*ans, sep='\n')


Measured memory_bytes: 55408
#include <iostream>


bool crible[100001];


int main()
{
  int queries; std::cin >> queries;
  crible[0] = crible[1] = true;
  
  for (int i = 2; i < 100001; i++)
  {
  	for (int j = i * 2; j < 100001; j += i)
      crible[j] = true;
  }
  
  int sim[100001];
  sim[0] = 0;
  
  for (int i = 1; i < 100001; i++)
    sim[i] = ((!crible[(i + 1) / 2]) && !crible[i]) + sim[i - 1];
  
  for (int i = 0; i < queries; i++)
  {
  	int l, r;
    std::cin >> l >> r;
    std::cout << sim[r] - sim[l - 1] << '\n';
  }
  
  return 0;
}

Measured memory_bytes: 1152
s = input()
n = len(s)
#各Lについて、自分より左でもっとも右のR
n_r = [-1 for i in range(n)]
#各Rについて、自分より右でもっとも左のL
n_l = [-1 for i in range(n)]

nearest_r = 0

for i in range(n):
    if s[i] == "R":
        nearest_r = i
    else:
        n_r[i] = nearest_r

nearest_l = n-1

for i in range(n-1,-1,-1):
    if s[i] == "L":
        nearest_l = i
    else:
        n_l[i] = nearest_l

answers = [0 for i in range(n)]

for i in range(n):
    if s[i] == "R":
        if (n_l[i] - i)%2 == 0:
            answers[n_l[i]] += 1
        else:
            answers[n_l[i]-1] += 1
    else:
        if (i - n_r[i])%2 == 0:
            answers[n_r[i]] += 1
        else:
            answers[n_r[i]+1] += 1

ans  =""
for i in range(n):
    ans += str(answers[i])
    if i != n-1:
        ans += " "

print(ans)

Measured memory_bytes: 9340
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  vector<ll> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  ll ans = 0;
  for(int i = 0; i < n - 1; i++) {
    ll d = x[i + 1] - x[i];
    if (d * a < b) {
      ans += d * a;
    } else {
      ans += b;
    }
  }
  cout << ans << endl;
  return 0;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define BiSearchRangeNum(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y)

int main() {
  ll A, B;
  cin >> A >> B;
  ll a = max(A, B);
  ll b = min(A, B);
  bool flag = false;
  if ((a + b) % 2 == 0) {
    cout << (a + b) / 2ll << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
};


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

int main(){
  int a[10],ans=-1;
  for(int i=0;i<6;i++){
    cin>>a[i];
  }
  for(int i=0;i<6;i++){
    for(int j=i+1;j<6;j++){
      if(abs(a[i]-a[j])>a[5]){
        cout<<":(";
        return 0;
      }
    }
  }
  cout<<"Yay!";

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
//typedef tree<int,null_type,less<int >,rb_tree_tag,tree_order_statistics_node_update>indexed_set;
template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);
#define debug(a) cout<<#a<<" --> "<<(a)<<endl;
#define fastInput ios_base::sync_with_stdio(false);cin.tie(0)
#define INPUT freopen("input.txt","r",stdin)
#define OUTPUT freopen("output.txt","w",stdout)
#define Error  1e-9
#define pi (2*acos(0))
const ll mod =998244353  ;
const int N = 100+5;
int h, w;
vector<string>s;
int dp[N][N][N+N+1];
bool is_safe(int x, int y)
{
    return (x>=0 && x<h && y>=0 && y<w);
}
int fun(int posx, int posy, int prefix)
{
    if(posx==h-1 && posy==w-1)
    {
        if(prefix || s[posx][posy]=='#')
            return 1;
        else
            return 0;
    }
    int &ret = dp[posx][posy][prefix];
    if(ret!=-1)
        return ret;

    int ans = 1e7;

    int x= posx, y= posy;
    if(s[x][y]=='#')
    {
        if(is_safe(x+1,y))
            ans = min(ans,fun(x+1,y,prefix+1));
        if(is_safe(x,y+1))
            ans = min(ans,fun(x,y+1,prefix+1));
    }
    else if(s[x][y]=='.')
    {
        int add =0;
        if(prefix)
            add++;
        if(is_safe(x+1,y))
            ans = min(ans,add+ fun(x+1,y,0));
        if(is_safe(x,y+1))
            ans = min(ans,add+ fun(x,y+1,0));
    }

    return ret = ans;


}
void Solve(int cas)
{
    memset(dp,-1,sizeof dp);
    scanf("%d %d",&h,&w);
    s.resize(h);
    for(int i=0; i<h; i++)
    {
        cin>>s[i];
    }
    printf("%d\n",fun(0,0,0));




}



int main()
{
    //INPUT;
    //OUTPUT;
    int t=1,cas=0;
    //scanf("%d",&t);
    while(t--)
    {
        Solve(++cas);
    }

    return 0;
}
/*

*/


//os.order_of_key(v): returns how many elements strictly less than v
//os.find_by_order()

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(int i=0; i<v.size(); i++)
    {
        os<<v[i]<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os, set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}


Measured memory_bytes: 9344
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#define INF (1e9)
#define se second
#define f first
#define N 505
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
int dijkstra();
int w,h,n,sy,sx,gy,gx,ay,ax,t,c[4][N][N],d[N][N];
 
int main(){
  string s;
  cin>>w>>h>>n;
  cin>>sx>>sy>>gx>>gy;
  while(n--){
    cin>>ax>>ay;
    cin>>t>>s;
    string a=s;
    while(--t) s+=a;
    for(int i=0;i<s.size();i++){
      if(s[i]=='L'&&ax!=0) c[3][ay][ax]++,c[1][ay+1][ax]++,ax--;
      if(s[i]=='U'&&ay!=0) c[2][ay][ax]++,c[0][ay][ax+1]++,ay--;
      if(s[i]=='R'&&ax!=w-1) c[1][ay+1][ax+1]++,c[3][ay][ax+1]++,ax++;
      if(s[i]=='D'&&ay!=h-1) c[0][ay+1][ax+1]++,c[2][ay+1][ax]++,ay++;
    }
  }
  cout<<dijkstra()<<endl;
  return 0;
}
 
int dijkstra(){
  priority_queue<P1,vector<P1>,greater<P1> > q;
  int dy[4]={0,-1,0,1},dx[4]={-1,0,1,0};
  for(int i=0;i<=h;i++)
    for(int j=0;j<=w;j++) d[i][j]=INF;
  for(int i=0;i<4;i++) d[sy][sx]=0,q.push(P1(0,P(sy,sx)));
  while(!q.empty()){
    P1 t=q.top(); q.pop();
    int cost=t.f,y=t.se.f,x=t.se.se;
    if(d[y][x]<cost) continue;
    for(int i=0;i<4;i++){
      int ny=y+dy[i],nx=x+dx[i],co=c[i][y][x];
      if(ny<0||nx<0||h<ny||w<nx) continue;
      if(d[ny][nx]>cost+co){
    d[ny][nx]=cost+co;
    q.push(P1(cost+co,P(ny,nx)));
      }
    }
  }
  return d[gy][gx];
}

Measured memory_bytes: 10980
#include<stdio.h>
#include<string.h>
 
int main(int argc, char* argv[])
{
  char s[400];
  int h, i, j, k,len;
 
  scanf("%s", s);
  while(strcmp(s, "-")){
	scanf("%d", &h);
    i = 0;
    len = strlen(s);
    for(j = 0; j < h; j++){
      scanf("%d", &k);
      i = (i + k) % len;
    }
    j = i;
    do{
      putchar(s[i]);
      i = (i + 1) % len;
    }while(j != i);
    putchar('\n');
    scanf("%s", s);
  }

  return(0);
}

Measured memory_bytes: 568
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		HashMap<Integer, Integer> Ai = new HashMap<Integer, Integer>();
		for (int i=0; i<N; i++) {
			int a = sc.nextInt();
			if (Ai.containsKey(a)) {
				Integer val = Ai.get(a);
				val++;
				Ai.put(a, val);
			}
			else {
				Ai.put(a, 1);
			}
		}
		int cnt = 0;
		for (Map.Entry<Integer, Integer> entry : Ai.entrySet()) {
			if (entry.getValue() % 2 == 1 ) {
				cnt++;
			}

		}
		System.out.println(cnt);
	}

}


Measured memory_bytes: 61488
import java.util.Scanner;

public class Main {

    
    public static void main(String[] args) {
       
        Scanner sc = new Scanner(System.in);
        
        int val1 = sc.nextInt();
        int val2 = sc.nextInt();
        
        System.out.println(val1*val2 + " " + (val1*2 + val2*2) );
        
        
    }
    
}




Measured memory_bytes: 26204
#include<bits/stdc++.h>
using namespace std;
struct node{
	int day,money;
}s[100005];
priority_queue <int> q;
int n,m;
bool cmp(node X,node Y){
	return X.day < Y.day;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i = 1;i <= n;i++)
		scanf("%d%d",&s[i].day,&s[i].money);
    int ans = 0;
	int now = 1;
	sort(s + 1,s + 1 + n,cmp);
	for(int i = 1;i <= m;i++){
		while(now <= n && s[now].day <= i){
			q.push(s[now].money);	
			now++;		
		}
		if (!q.empty()){
			ans += q.top();
			q.pop();
		}
	}
	printf("%ld\n",ans);
	return 0;
}

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

int main(){
  int n,c,k;
  cin>>n>>c>>k;
  vector<pair<int,int>> t(n);
  rep(i,n){
    int T;
    cin>>T;
    t[i]=make_pair(T,T+k);
  }
  sort(t.begin(),t.end());
  int right;
  int tmp=c;
  int ans=0;
  rep(i,n){
    if(t[i].first <= right && tmp!=c){
      tmp++;
    }else{
      right = t[i].second;
      tmp=1;
      ans++;
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 4040
s=int(input())
a=[s]
def f(s):
    if s%2==0:
        return s//2
    else:
        return 3*s+1
for i in range(1000001):
    if f(a[i]) in a:
        print(i+2)
        break
    else:
        a.append(f(a[i]))

Measured memory_bytes: 3060
// https://atcoder.jp/contests/agc028/tasks/agc028_c
//
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::fmt::*;
use std::io::*;
use std::str::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn solve(v: Vec<(u64, u64)>) -> u64 {
    let mut edges = vec![];
    let n = v.len();
    for i in 0..n {
        edges.push((v[i].0, i, 0));
        edges.push((v[i].1, i, 1));
    }
    edges.sort();

    let mut ans = 0;
    let mut flag = vec![0; n];
    for i in 0..n {
        ans += edges[i].0;
        let idx = edges[i].1;
        flag[idx] |= 1 << edges[i].2;
    }

    let mut types = vec![0; 4];
    for i in 0..n {
        types[flag[i]] += 1;
    }

    assert!(types[0] == types[3]);

    if types[1] == n || types[2] == n {
        return ans;
    }
    if types[0] >= 1 {
        return ans;
    }

    let mut best = std::u64::MAX;
    for i in n - 2..n {
        let eidx = edges[i].1;
        for j in n..2 * n {
            if edges[j].1 != eidx {
                best = min(best, ans + edges[j].0 - edges[i].0);
                break;
            }
        }
    }
    return best;
}

fn main() {
    input! {
        n: usize,
        v: [(u64, u64); n]
    };

    let ans = solve(v);
    println!("{}", ans);
}


Measured memory_bytes: 17268
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int get_bit(LL x,int v){return (x>>v)&1;}
int main(){
    int N;
    LL K;
    R(N,K);
    LL cnt[40]={};
    REP(i,N){
        LL v;
        R(v);
        REP(j,40){
            cnt[j]+=get_bit(v,j);
        }
    }
    LL now=0,ma=-1e18;
    for(int i=39;i>=0;i--){
        if(get_bit(K,i)){
            ma=max(ma+(max(cnt[i],N-cnt[i])<<i),now+(cnt[i]<<i));
            now+=(N-cnt[i])<<i;
        }
        else{
            now+=cnt[i]<<i;
            ma+=(max(cnt[i],N-cnt[i])<<i);
        }
    }
    ma=max(ma,now);
    W(ma);
    return 0;
}


Measured memory_bytes: 256
/* 
 * File:   main.cpp
 * Author: freebsd
 *
 * Created on 2014/08/28, 10:07
 */

#include <cstdio>

using namespace std;

int main() {
    while (true) {
        int s1[5] = {0}, s2[5] = {0};
        
        char store[5] = {'A', 'B', 'C', 'D', 'E'};
        
        for(int i = 0; i < 5; i++) {
            scanf("%d %d", &s1[i], &s2[i]);
            if(s1[0] == 0 && s2[0] == 0) return 0;
        }
        
        for(int i = 0; i < 5; i++) {
            s1[i] += s2[i];
        }
        
        int i = 0;
        char tempc;
        int max;
        
        max = s1[0];
        tempc = store[0];
        
        while(i != 4) {
            
            if(max < s1[i + 1]) {
                max = s1[i + 1];
                tempc = store[i + 1];
            }
            i++;
        }
        
        printf("%c %d\n", tempc, max);
    }
}

Measured memory_bytes: 1028
#include <stdio.h>
int main(){
  long long int t;
  scanf("%lld", &t);
  long long input[t];
  
  for(long long int i = 0; i < t; i++){
  	scanf("%lld", &input[i]);
	}
	for(long long int i = 0; i < t; i++){
		if(input[i] == 0){
			printf("0\n");
			return 0;
		}
	}
	long long int sum = 1;
	for(int i = 0; i < t; i++){
		if(input[i] <= 1000000000000000000/sum){
			sum *= input[i];
		}else{
			printf("-1\n");
			return 0;
		}
	}
	printf("%lld\n", sum);
	
  return 0;
}

Measured memory_bytes: 2508
/*input

*/
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits>
#include <random>

using namespace std; 

template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
int GCD(int x,int y){return y?GCD(y,x%y):x;}
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,a,b) for(int i=(a);i<(b);i++)
#define repm(i,a,b) for(int i=(a);i>(b);i--)
#define rept(v) for(auto it=v.begin();it<v.end();it++)
#define all(v) v.begin(),v.end()
const int INF = 1<<30;
typedef long long ll;
typedef pair<int,int> pii;

int const MOD = 1e9+7;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
	int n;
	cin >> n;
	int a[n];
	memset(a, 0, sizeof(a));
	rep(i, n) {
		int one, two;
		cin >> one >> two;
		if(one == two) a[i]=1;
	}
	int mx=0, cur=0;
	rep(i, n) {
		if(a[i]==1) cur++;
		else cur=0;
		mx=max(mx, cur);
	}
	if(3<=mx) cout << "Yes";
	else cout << "No";
	return 0;	
}

Measured memory_bytes: 3648
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		int x = 0,y = 0,q = 1;
		for(int i = 0;i < n;i++)
		{
			int t,a,b;
			scanf("%d%d%d",&t,&a,&b);
			int c = x - a,d = y - b;
			if(c < 0) c = 0-c;
			if(d < 0) d = 0-d;
			int num = c + d;
			if(t < num||(t-num)%2!=0)
			{
				q = 0;
			}
		}
		if(q == 1) printf("Yes\n");
		else printf("No\n");
	}
return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

template<typename T> bool InRange(T t, T l, T r){ return l <= t && t < r; }

int main(){
	
	int N;
	cin >> N;
	vector<ll> A(N),B(N);
	for(int i=0;i<N;i++) cin >> A[i] >> B[i];
	
	ll ma = 0;
	int idx = -1;
	for(int i=0;i<N;i++){
		if(A[i] > ma){
			ma = A[i];
			idx = i;
		}
	}
	
	cout << (A[idx] + B[idx]) << endl;
	
	
	
	
    return 0;
}

Measured memory_bytes: 1792
//headers
#include <bits/stdc++.h>
#define ll long long
using namespace std;

void solve() 
{
    ll n,k;cin>>n>>k;
    vector<ll> arr(n,0);
    for(ll i = 0;i<n;i++){cin>>arr[i];}
    sort(arr.begin(),arr.end());
    ll ans = 0;
    for(ll i = 0;i<k;i++){ans += arr[i];}
    cout << ans << endl;
} 

//driver
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ll test = 1;
    // cin>>test;
    for(ll i = 0;i<test;i++)
    {
        solve();
    }
}    

Measured memory_bytes: 3668
N = int(input())
DP = [i for i in range(N+1)]
for i in range(N+1):
    j = 0
    while i - 9**j >= 0:
        DP[i] = min(DP[i - 9**j] + 1, DP[i])
        j += 1;
    j = 0
    while i - 6**j >= 0:
        DP[i] = min(DP[i - 6**j] + 1, DP[i])
        j += 1;
print(DP[N])


Measured memory_bytes: 7064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
// template<class t, class u>
// ostream& operator<<(ostream& os, const pair<t, u>& p) {
//   return os << "{" << p.first << ", " << p.second << "}";
// }
// template<class t> ostream& operator<<(ostream& os, const vector<t>& v) {
//   os << "{";
//   rep(i, v.size()) { if(i) os << ", "; os << v[i]; }
//   return os << "}";
// }
// template<class t> ostream& operator<<(ostream& os, const set<t>& se) {
//   os << "{";
//   auto itr = se.begin();
//   rep(i, se.size()) { if(i) os << ", "; os << *itr; itr++; }
//   return os << "}";
// }
// template<class t, class u>
// ostream& operator<<(ostream& os, const map<t, u>& mp) {
//   os << "{";
//   auto itr = mp.begin();
//   rep(i, mp.size()) { if(i) os << ", "; os << *itr; itr++; }
//   return os << "}";
// }
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N, M;
  cin >> N >> M;
  if(N == M) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi > 
const int N=200005;

int main()
{
  
  int n,k,x;
  cin>>n>>k;
  vi v;
  for(int i=1;i<=n;i++)
  {
  	cin>>x;
  	v.pb(x);
  }
  sort(v.begin(),v.end());
  ll s=0;
  for(int i=0;i<n-k;i++) s+=v[i];
  	cout<<s;


	return 0;
}

Measured memory_bytes: 1400
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  map<char,int> mp;
  string s;
  cin >> s;
  REP(i,s.size()) mp[s[i]]++;
  bool flag = true;
  for(auto p : mp) {
    int a = p.second;
    if(a % 2 != 0) flag = false;
  }
  YesorNo(flag);
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
import qualified Data.Vector.Unboxed as V
import Data.Array.IArray (listArray, accumArray, (!))
import Data.Array.MArray
import Data.Array.ST (STUArray, runSTUArray)
import Data.Array.Unboxed (UArray)
import Data.List (sortOn, sortBy, unfoldr, partition)
import Data.Char (isSpace)
import Control.Monad.ST (ST)
import Control.Monad.Trans.State (StateT(..))
import qualified Data.ByteString.Char8 as B

-- utility functions

--   Input functions
readInt = B.readInt . B.dropWhile isSpace

readInts :: Int -> B.ByteString -> [Int]
readInts n = take n . unfoldr readInt

readIntsV :: Int -> B.ByteString -> V.Vector Int
readIntsV n = V.unfoldrN n readInt

readIntsA :: Int -> B.ByteString -> UArray Int Int
readIntsA n bs = runSTUArray $ do
  arr <- newArray_ (0,n-1)
  go arr 0 bs
  return arr
  where
    go :: STUArray s Int Int -> Int -> B.ByteString -> ST s ()
    go arr i bs
      | i==n = return ()
      | otherwise = do
        let Just (x,bs') = readInt bs
        writeArray arr i x
        go arr (i+1) bs'

readTsV :: Int -> B.ByteString -> V.Vector (Int,Int)
readTsV n = V.unfoldrN n $ runStateT ((,) <$> StateT readInt <*> StateT readInt)

readTs :: Int -> B.ByteString -> [(Int,Int)]
readTs n = take n . unfoldr readT where
  readT = runStateT ((,) <$> StateT readInt <*> StateT readInt)

-- main

solv n s
  | null s' = 0
  | otherwise = minimum $ go 0 bnum s'
  where
    s' = reverse s
    go wn bn [] = [bnum]
    go wn bn ('.':xs) = bn + (wn+1) : (go (wn+1) bn xs)
    go wn bn ('#':xs) = (bn-1) + wn : (go wn (bn-1) xs)
    bnum = length . filter (=='#') $ s'

main = do
  n <- read <$> getLine :: IO Int
  s <- getLine
  print $ solv n s


Measured memory_bytes: 13948
#include<bits/stdc++.h>
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ff(i,a,b) for(register int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
//const ll mod = 1e9 + 7;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;

const int N = 2e5 + 10;
int t;
ll a[N];
int main() 
{
	int n;
	ll x;
	while (cin >> n)
	{
		ll ans = 1;
		f(i, 1, n)cin >> a[i];
		int fg = 0;
		int fgg = 0;
		ll ju = 1e18;
		f(i, 1, n)
		{
			if (a[i] == 0)fg = 1;
			ll nt = ans * a[i];
			if (nt<ans || nt>ju) { fgg = 1; }
			ans *= a[i];
		}
		if (fg)puts("0");
		else if (fgg)puts("-1");
		else cout << ans << endl;
	}
}

Measured memory_bytes: 4420
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, C, K = MAP()
A = [INT() for i in range(N)]
num = 0
A.sort()
B = []
ans = 0
mi = 0
# print(A)
for i in range(N):
    if len(B) == C:
        # 超えていたら
        B = [A[i]]
        ans += 1
        mi = A[i]
    elif len(B) == 0:
        B = [A[i]]
        mi = A[i]
    else:
        gap = A[i] - mi
        if gap <= K:
            B.append(A[i])
        else:
            B = [A[i]]
            ans += 1
            mi = A[i]
    # print(B)
if len(B) != 0:
    ans += 1
print(ans)
            
    


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

int main()
{
	std::string n;
	std::cin >> n;

	bool ispal = true;
	for( int i = 0; i < n.size(); i++ ) {
		if( n[ i ] != n[ n.size() - 1 - i ] ) {
			ispal = false;
		}
	}
	std::cout << ( ispal ? "Yes" : "No" ) << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef vector<int> vi;

signed main()
{
    int n;
    cin >> n;
    int mg = (n / 1000);
    mg += (int)(n % 1000 != 0);
    cout << mg * 1000 - n << endl;
}

Measured memory_bytes: 3572
import java.util.*;
import java.io.*;

class Main {
  public static void main(String[] args) throws Exception{
    try (Scanner sc = new Scanner(System.in)){
      int A = sc.nextInt();
      int B = sc.nextInt();
      if (A % 2 == 0 || B % 2 == 0) {
        System.out.println("No");
      } else {
        System.out.println("Yes");
      }
    }
  }
}


Measured memory_bytes: 21076
#include  <iostream>
#include  <vector>
#include  <numeric>
#include  <algorithm>
using namespace std;

typedef vector<vector<int> > Graph;
#define rep(i, n) for(int i = 0; i < n; i++)

int main()
{
	int n, m;
	cin >> n >> m;
	Graph G(n, vector<int>(n, 0));
	rep(i, m) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		G[u][v] = 1;
		G[v][u] = 1;
	}

	int ans = 0;
	vector<int> perm(n - 1);
	iota(perm.begin(), perm.end(), 1);
	do {
		int z = 0;
		bool flag = true;
		for (int i = 0; i < n - 1; i++) {
			if (G[z][perm[i]] == 0)  flag = false;
			z = perm[i];
		}
		if (flag)  ans++;
	} while (next_permutation(perm.begin(), perm.end()));

	cout << ans << endl;
}

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

int main () {
  char a;
  while(1){
    scanf("%C",&a);
    if(isalpha(a)){
      if(islower(a)) printf("%c",toupper(a)) ;
      else printf("%c",tolower(a)) ;
    }else printf("%c",a) ;
    if(a=='\n') break ;
  }
}


Measured memory_bytes: 3144
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {

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

        String[] t = new String[n];
        for (int i = 0 ; i < n ; i++) {
            char[] d = new char[10];
            for (int j = 0 ; j < 10 ; j++) {
                d[j] = s[i].charAt(j);
            }
            Arrays.sort(d);
            StringBuilder sBuilder = new StringBuilder();
            for (int j = 0 ; j < 10 ; j++ ) {
                sBuilder.append(d[j]);
            }
            t[i] = sBuilder.toString();
        }

        Map<String, Integer> map = new HashMap<String, Integer>();
        for (int i = 0 ; i < n ; i++) {
            if (map.containsKey(t[i])) {
                map.put(t[i], map.get(t[i]) + 1);
            } else {
                map.put(t[i], 1);
            }
        }
        long ans = 0;
        for (Entry<String, Integer> entry : map.entrySet()) {
            int v = entry.getValue();
            ans += (long) v * (v - 1) / 2;
        }

        System.out.println(ans);

    }

}


Measured memory_bytes: 62932
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_C
#include <iostream>
#include <cstdio>
#include <queue> // 入れた順番に出していく玉突き構造。
using namespace std;

int G[110][110];
int n;
int u, k, v;

void print_matrix(int N) {
  for(int i=0; i<N; i++) {
    for(int j=0; j<N; j++) {
      printf("%d", G[i][j]);
      if (j < N-1) {
	printf(" ");
      }
    }
      printf("\n");
  }
}

void make_matrix() {
  fill(&G[0][0], &G[0][0]+110*110, 0);
  scanf("%d", &n);
  for (int i=0; i<n; i++) {
    scanf("%d%d", &u, &k);
    u--;
    for (int j=0; j<k; j++) {
      scanf("%d", &v);
      v--;
      G[u][v] = 1;
    }
  }
}

void bfs(int src) {
  // cerr << "bfs root is " << src << endl;
  queue<int> Q; // 整数管理用(ナマの番地に入れる(-1しない))
  int D[110]; // 距離管理用(ナマの番地に入れる)
  fill(D, D+110, -1);
  D[src] = 0;
  Q.push(src); // rootだけは入れる。
  while (! Q.empty()) {
    int cur = Q.front(); // 先頭要素を取り出す。
    Q.pop(); // 先頭要素を消す。
    // cerr << "visiting " << cur << " whose dist is " << D[cur] << endl;
    for (int i=1; i<=n; i++) { // i:訪問先
      if (G[cur-1][i-1] == 1 && D[i] == -1) {
	D[i] = D[cur] + 1;
	Q.push(i);
      }
    }
  }
  for (int i=1; i<=n; i++) {
    printf("%d %d\n", i, D[i]);
  }
}

int main() {
  make_matrix();
  bfs(1);
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

    string s;
    cin >> s;
    ll n = s.size();
    ll ans = 0;
    ll na = 0;
    for(ll i = 0; i < n-1; i++){
        if(s[i] == 'A') na++;
        else if(s[i] == 'B'){
            string t = s.substr(i,2);
            if(t == "BC"){
                ans += na;
                i++;
            } else na = 0;
        } else na = 0;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

ll dp[110][100010];

int main() {
	ll n,w;
	cin >> n >> w;
	
	for(int i=0; i< n; i++) {
		ll val, wgt;
		cin >> wgt >> val;
		for(int k=0; k <= w; k++) {
			if(k >= wgt) dp[i+1][k] = max(dp[i][k-wgt] + val, dp[i+1][k]);
			dp[i+1][k] = max(dp[i+1][k], dp[i][k]);
		}
	}
	
	cout << dp[n][w];


	return 0;
}

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

int main(){

  int n; cin>>n;

  int mochi;

  vector<int> cou(101,0);

  rep(i,n){

    cin>>mochi;

    cou.at(mochi) = 1;

    

  }
    
  int ans =0; 

  rep(i,101) ans += cou.at(i);

  cout<<ans<<endl;

  return 0;
           
}


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

int main(){
  int n, m;
  cin >> n >> m;
  
  vector<int> x(m);
  rep(i,m) {
    cin >> x.at(i);
    //cout << x.at(i) << endl;
  }
  sort(x.begin(), x.end());
  
  vector<int> l(m-1);
  rep(i,m-1){
    l.at(i) = x.at(i+1)-x.at(i);
    //cout << l.at(i) << endl;
  }
  sort(l.begin(), l.end());
  
  int ans = 0;
  rep(i,m-n){
    ans += l.at(i);
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 1024