akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define INF 1000000000000000
#define fi first
#define se second
int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };
struct edge { int to, cost; };
typedef pair<int, int> P;
int a, b;
signed main() {
	cin >> a >> b;
	if (a == b)cout << a * 2 << endl;
	else cout << max(a, b) + max(a, b) - 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int n, t, a[100000] = { 0 };
	cin >> n;
	for (int i = 1; i <= n; ++i)
	{
		cin >> t;
		a[t] = i;
	}
	for (int i = 1; i <= n; ++i)
		cout << a[i] << ' ';
	return 0;
}

Measured memory_bytes: 1280
// AtCoder Beginner Contest 149 C.cpp

#include <iostream>

using namespace std;

int main() {
	int a, f, i;
	cin >> a;

	if (a == 2) {
		cout << a << endl;
		return 0;
	}

	if (a % 2 == 0) {
		f = a + 1;
	}
	else {
		f = a;
	}

	while (true) {
		for (i = 2; i < f; i++) {
			
			if (f % i == 0) {
				break;
			}
		}
		if (i == f) {
			cout << f << endl;
			break;
		}
		f += 2;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, k, m = 1;
    cin >> n;
    int a[n + 1];
    bool used[n + 1], trained = false;
    for (int i = 1; i <= n; i++) 
    {
        cin >> a[i];
        used[i] = false;
    }
    used[1] = true;
    k = a[1];
    for (int i = 0; i < n; i++)
    {
        if (k == 2)
        {
            trained = true;
            break;
        }
        if (used[k] == true) break;
        used[k] = true;
        int l = a[k];
        k = l;
        m++;
    }
    if (trained == true) cout << m;
    else cout << "-1";
}

Measured memory_bytes: 4088
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll count1[101];
int main() {
    ll n;
    cin>>n;
    if(n<10)
    {
        cout<<"0";
        return 0;
    }
    for(ll i=2;i<=n;i++)
    {
        ll temp=i;
        for(ll j=2;j<=temp;j++)
        {
            while(temp%j==0)
            {
                count1[j]+=1;
                temp/=j;
            }
        }
    }
    ll ans=0;
    for(ll i=1;i<=100;i++)
    {
        if(count1[i]>=74)
        {
            ans+=1;
        }
    }
    vector<ll>v14;
    vector<ll>v4;
    vector<ll>v24;
    vector<ll>v2;
    for(ll i=1;i<=100;i++)
    {
        if(count1[i]>=2)
        {
            v2.push_back(i);
        }
        if(count1[i]>=4)
        {
            v4.push_back(i);
        }
        if(count1[i]>=14)
        {
            v14.push_back(i);
        }
        if(count1[i]>=24)
        {
            v24.push_back(i);
        }
    }
    set<pair<ll,ll>>s1;
    for(ll i=1;i<=100;i++)
    {
        if(count1[i]>=14)
        {
            for(ll j=1;j<=100;j++)
            {
                if(count1[j]>=4 && j!=i)
                {
                    ans+=1;
                   // s1.insert(make_pair(min(i,j),max(i,j)));
                }
            }
        }
    }
//    ans=ans+s1.size();
    s1.clear();
    for(ll i=1;i<=100;i++)
    {
        if(count1[i]>=24)
        {
            for(ll j=1;j<=100;j++)
            {
                if(count1[j]>=2 && j!=i)
                {
                    ans+=1;
                    //s1.insert(make_pair(min(i,j),max(i,j)));
                }
            }
        }
    }
  //  ans+=s1.size();
    set<tuple<ll,ll,ll>>s2;
    for(ll i=1;i<=100;i++)
    {
        if(count1[i]>=4)
        {
            for(ll j=i+1;j<=100;j++)
            {
                if(i!=j && count1[j]>=4)
                {
                    for(ll k=1;k<=100;k++)
                    {
                        if(k!=i && k!=j && count1[k]>=2)
                        {
                            ans+=1;
                            ll mini=min(i,j);
                            ll maxi=max(i,j);
                         //   s2.insert(make_tuple(min(mini,k),max(maxi,k),i+j+k-min(mini,k)-max(maxi,k)));
                        }
                    }
                }
            }
        }
    }
    cout<<ans;//+s2.size();
}

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

const long long MOD = 1e9 + 7;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    long long n, k;
    cin >> n >> k;
    
    vector<int> v(n);
    for (int i = 0; i < n; i++){
        cin >> v[i];
    }

    long long ans = 0;
    for (int i = 0; i < n; i++){
        long long cnt = 0;
        for (int j = 0; j < n; j++){
            if (v[j] < v[i])
                cnt += 1;
        }
        
        long long tmp = 0;
        for (int j = i + 1; j < n; j++){
            if (v[j] < v[i]){
                tmp += 1;
            }
        }

        tmp = (tmp * k) % MOD;
        ans = (ans + tmp) % MOD;
        
        ans = (ans + ((((k * (k - 1) / 2) % MOD) * cnt) % MOD)) % MOD;
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#define int long long

using namespace std;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    vector< tuple<int, int, int> > v(0);
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        v.push_back(make_tuple(a,b, i));
    }
    sort(v.begin(), v.end());
    vector<int> fq(n+1,0);
    vector<string> rep(m);
    for(int i = 0; i < m; i++){
        int a = get<0>(v[i]);
        int b = get<1>(v[i]);
        int c = get<2>(v[i]);
        string a1 = to_string(a);
        string b1 = to_string(fq[a]+1);
        fq[a]++;
        int sz= a1.size();
        for(int i = 0; i < 6-sz; i++){
            a1 = '0'+a1;
        }
        sz = b1.size();
        for(int i = 0; i < 6-sz; i++){
            b1 = '0'+b1;
        }
        rep[c] = a1+b1;
    }
    for(string s : rep) cout << s << endl;
}


Measured memory_bytes: 12016
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

int main(void) {
	int64_t A, B, C, K;

	scanf("%"PRId64"\n%"PRId64" %"PRId64" %"PRId64, &A, &B, &C, &K);

	printf("%"PRId64, (K % 2 == 0) ? A - B : B - A);

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n;
  cin >> n;
  vector<ll> vec(n);
  vector<ll> d;
  rep(i, n) {
    cin >> vec[i];
    ll t = vec[i] - i - 1;
    d.push_back(t);
  }
  sort(d.begin(), d.end());
  ll ans = 0;
  ll med = d[n/2];
  rep(i, n) {
    ans += abs(d[i] - med);
  }
  cout << ans << endl;

  return 0;
}

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

n = int(input())
dp = [sys.maxsize] * 110000
dp[0] = 0

for i in range(1, n+1):
  pow6 = 1
  while pow6 <= i:
    dp[i] = min(dp[i], dp[i-pow6] + 1)
    pow6 *= 6
    
  pow9 = 1
  while pow9 <= i:
    dp[i] = min(dp[i], dp[i-pow9] + 1)
    pow9 *= 9
    
print(dp[n])

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

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

   int max = 0;
   for (int i=0; i<S.size(); i++){
      if ((S.at(i) == 'A') || (S.at(i) == 'C') || (S.at(i) == 'G') || (S.at(i) == 'T')){
         if (max == 0){
            max = 1;
         }
         for (int i2=i+1; i2<S.size(); i2++){
            if (!((S.at(i2) == 'A') || (S.at(i2) == 'C') || (S.at(i2) == 'G') || (S.at(i2) == 'T'))){
               if (i2-i > max){
                  max = i2-i;
               }
               break;
            }
            else {
               if (i2 == S.size()-1){
                  if (i2+1-i > max){
                     max = i2+1-i;
                  }
               }
            }
         }
      }
   }
   cout << max << endl; 
}



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

double length( double x1, double y1, double x2, double y2 )
{
    return sqrt( pow(x2-x1,2) + pow(y2-y1,2) );
}

double Surface_Area( double a, double b, double c )
{
    double sin, cos;
    cos = ( a * a - b * b - c * c ) / ( -2 * b * c );
    sin = sqrt( 1 - cos*cos );
    return 0.5 * c * b * sin;
}

int main() 
{
    double x1,y1,x2,y2,x3,y3,xp,yp;

    //a(x1,y1) b(x2,y2) c(x3,y3) p(xp,yp)
    while( cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp )
    {
        double ab = length( x1, y1, x2, y2 ), bc = length( x2, y2, x3, y3 ), ca = length( x1, y1, x3, y3 );
        double ap = length( x1, y1, xp, yp ), bp = length( x2, y2, xp, yp ), cp = length( x3, y3, xp, yp );

        double s1, s2, s3, s4;
        s1 = Surface_Area( bc, ca, ab );
        s2 = Surface_Area( cp, ca, ap );
        s3 = Surface_Area( bp, cp, bc );
        s4 = Surface_Area( ap, ab, bp );

        if( fabs( s1 - ( s2 + s3 + s4 ) ) < 0.0000001 )         //fabsは絶対値を返す関数
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
}



Measured memory_bytes: 3192
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
public static class P {
  public static void Main() {
    var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int n = nm[0];
    int m = nm[1];
    var graph = new List< List < int > >();
    foreach (int _ in Enumerable.Range(0, n)) {
      graph.Add(new List< int >());
    }
    foreach (int _ in Enumerable.Range(0, m)) {
      var st = Console.ReadLine().Split().Select(int.Parse).ToArray();
      int s = st[0] - 1;
      int t = st[1] - 1;
      graph[s].Add(t);
    }

    var dp = new List < double >();
    dp.AddRange(Enumerable.Repeat(0.0, n));
    foreach (int i in Enumerable.Range(0, n - 1).Reverse()) {
      foreach (int j in graph[i]) {
        dp[i] += dp[j];
      }
      dp[i] /= graph[i].Count();
      dp[i] += 1;
    }

    var ep = new List < double >();
    ep.AddRange(Enumerable.Repeat(0.0, n));
    ep[0] = 1;
    foreach (int i in Enumerable.Range(0, n)) {
      foreach (int j in graph[i]) {
        ep[j] += ep[i] / graph[i].Count();
      }
    }

    double full = dp[0];
    double ans = full;
    foreach (int i in Enumerable.Range(0, n)) {
      int sz = graph[i].Count();
      if (sz < 2) continue;
      double sum = 0;
      double max = 0;
      foreach (int j in graph[i]) {
        sum += dp[j];
        max = Max(max, dp[j]);
      }
      double x = sum / sz;
      double y = (sum - max) / (sz - 1);
      ans = Min(ans, full - ep[i] * (x - y));
    }
    Console.WriteLine(ans);
  }
}


Measured memory_bytes: 21864
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>

#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}


int main(void) {

	string s;
	cin >> s;
	int count = 0;
	for (int i = 0; i < s.size() / 2; i++) {
		if (s[i] != s[s.size() - i - 1])
			count++;
	}

	COUT(count);


	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

#define PrintLn(X) cout << X << endl
#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)

double d[1002][1002];
double x[1002];
double y[1002];
double r[1002];
double cost[1002];
int done[1002] = {0};

int main(void)
{
	cin >> x[0] >> y[0];
	double xt, yt;
	cin >> xt >> yt;
	int N;
	cin >> N;
	x[N + 1] = xt;
	y[N + 1] = yt;

	Rep(i, N){
		cin >> x[i + 1] >> y[i + 1] >> r[i + 1];
	}
	Rep(a, N + 2){
		cost[a] = -1;
		Rep(b, N + 2){
			double dd = sqrt(pow(x[a] - x[b], 2) + pow(y[a] - y[b], 2)) - r[a] - r[b];
			if(dd < 0) dd = 0;
			d[a][b] = d[b][a] = dd;
		}
	}

	cost[0] = 0;
	while(1){
		int p = -1;
		Rep(i, N + 2){
			if(done[i] || cost[i] < 0){
				continue;
			}

			if(p == -1){
				p = i;
			}else if(cost[i] < cost[p]){
				p = i;
			}
		}

		if(p == -1){
			break;
		}

		done[p] = 1;

		Rep(i, N + 2){
			if(i == p) continue;
			double cost_ = cost[p] + d[p][i];
			if(cost[i] < 0 || cost[i] > cost_){
				cost[i] = cost_;
			}
		}
	}

	printf("%.10f\n", cost[N + 1]);
	return 0;
}


Measured memory_bytes: 8064
N = int(input())
A = [int(input()) for _ in range(N)]

digits = set()

for a in A:
    digits.add((a & -a).bit_length() - 1)

xor = 0
for a in A:
    xor ^= a

ans = 0

for digit in range(xor.bit_length() + 1)[:: -1]:
    if (xor & (1 << digit)) > 0:
        if digit in digits:
            ans += 1
            xor ^= ((1 << (digit + 1)) - 1)
        else:
            print(-1)
            exit()

print(ans)

Measured memory_bytes: 7072
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <deque>
using ll = long long;
using namespace std;

int main(){
    string a, b, c;
    cin >> a >> b >> c;
    int na = a.size(), nb = b.size(), nc = c.size();
    int i=0, j=-1, k=-1;
    string cur = a;
    char ans = 'A';
    int cnt = i;
    while(i<na && j<nb & k<nc){
        if(cur[cnt]=='a'){
            i++;
            cur = a;
            cnt = i;
            ans = 'A';
        }
        else if(cur[cnt]=='b'){
            j++;
            cur = b;
            cnt = j;
            ans = 'B';
        }
        else{
            k++;
            cur = c;
            cnt = k;
            ans = 'C';
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 768
n=int(input())
b=[1,6,36,216,1296,7776,46656]
q=[9,81,729,6561,59049]
d=[100000]*(n+1)
d[0]=0
for i in range(n):
  for j in b:
    if i+j<=n:
      d[i+j]=min(d[i+j],d[i]+1)
  for k in q:
    if i+k<=n:
      d[i+k]=min(d[i+k],d[i]+1)
print(d[n])

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;

#pragma GCC optimize("O3")
#ifdef LOCAL
#include "/Users/lbjlc/Desktop/coding/debug_utils.h"
#else
#define print(...) ;
#define printn(...) ;
#define fprint(...) ;
#define fprintn(...) ;
#endif

#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
// #define mp make_pair
#define fi first
#define se second
#define maxi(x, y) x = max(x, y)
#define mini(x, y) x = min(x, y)
// long long fact(long long n) { if(!n) return 1; return n*fact(n-1); }
// #define endl '\n'
#define solve_testcase int T;cin>>T;for(int t=1;t<=T;t++){solve(t);}

// long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }

typedef unsigned long long ull;
typedef long long ll;
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;
typedef vector<long long> vll;
#define bd(type,op,val) bind(op<type>(), std::placeholders::_1, val)

const int MAXN = 1e6+10;


void solve(int tt) {
    // cout<<"Case #"<<tt<<": ";
}

int n;
int a[MAXN];
vvi valid, d;

int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
int main(int argc, char * argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    // solve_testcase;

    cin>>n;
    rep(i,0,n*n) cin>>a[i];
    valid=vvi(n+2,vi(n+2,1));
    d=vvi(n+2,vi(n+2));
    rep(i,1,n+1) rep(j,1,n+1) {
        d[i][j]=min({i,n+1-i,j,n+1-j});
    }

    int res=0;
    rep(i0,0,n*n) {
        int i=(a[i0]-1)/n+1;
        int j=(a[i0]-1)%n+1;

        valid[i][j]=0;
        d[i][j]--;
        res+=d[i][j];
        // cout<<d[i][j]<<' ';

        set<pii> pre,cur({{i,j}}),vis({{i,j}});
        while(cur.size()) {
            swap(pre,cur); cur.clear();
            for(auto & p:pre) {
                int ii=p.first;
                int jj=p.second;
                rep(i1,0,4) {
                    int iii=ii+dx[i1];
                    int jjj=jj+dy[i1];
                    if(iii<=0||jjj<=0||iii>n||jjj>n) continue;
                    if(d[iii][jjj]>d[ii][jj]+valid[iii][jjj]) {
                        cur.insert({iii,jjj});
                        d[iii][jjj]=d[ii][jj]+valid[iii][jjj];
                    }
                }
            }
        }
    }
    // cout<<endl;
    cout<<res<<endl;

    return 0;
}




















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

using namespace std;

typedef long long LL;

const int N = 110;

int k, x;

int main()
{
    cin >> k >> x;

    k = k - 1;
    for(int i = max(x - k, -1000000); i <= min(x + k, 1000000); i++)
        cout << i << ' ';
    puts("");
    return 0;
}


Measured memory_bytes: 384
fun main(arr:Array<String>) {
    val n = readLine()!!.toInt()
    val base = (n / 1.08).toInt()
    val ans = listOf(base, base+1).filter { (it*1.08).toInt() == n }
    if(ans.isEmpty()) {
        println(":(")
    } else {
        println(ans.first())
    }
}

Measured memory_bytes: 34012
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader bis=new BufferedReader(new InputStreamReader(System.in));
        String s= bis.readLine();
        int l=s.length();
        int ans=0;
        for (int i = 0; i < l; i++)
        {
            char c=s.charAt(i);
            if(c=='+')
            {
                ans+=1;
            }
            if(c=='-')
            {
                ans-=1;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 20436
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <iostream>

using namespace std;

#define N 1000000000000000

int main() {
    int A, B;
    cin >> A >> B;

    if(A + B == 15)
        cout << "+" << endl;
    else if(A * B == 15)
        cout << "*" << endl;
    else
        cout << "x" << endl;

    return 0;
}


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

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

		int h = sc.nextInt();
		int n = sc.nextInt();
		
		int sum = 0;
		for(int i=0;i<n;i++) {
			int a = sc.nextInt();
			sum+=a;
		}
		
		System.out.println(sum>=h ? "Yes" : "No");
	}
}


Measured memory_bytes: 47336
n = int(input())
d = {}
for i in range(n):
      s = input()
      if not s in d.keys():
            d.setdefault(s,0)
      d[s]+=1
m = int(input())
for i in range(m):
      s = input()
      if s in d.keys():
            d[s] -= 1
ans = 0
for i in d.keys():
      ans = max(ans, d[i])
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

static const int MAX = 2e5;
int n, m;
set<int> adj[MAX];
vector<bool> visited(MAX);
int ans = 0;

void bfs(int s){
    int cnt = 0;
    queue<int> q;
    q.push(s);
    visited[s] = true;
    while(!q.empty()){
        int u = q.front();
        q.pop();
        cnt++;
        for(auto v : adj[u]){
            if(visited[v]) continue;
            q.push(v);
            visited[v] = true;
        }
    }
    ans = max(ans, cnt);
}

int main(){
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        adj[a-1].insert(b-1);
        adj[b-1].insert(a-1);
    }
    for(int i = 0; i < n; i++){
        if(!visited[i]) bfs(i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 31912
from collections import Counter
def factorization(n):
    a=[]
    for i in range(2,int(n**.5)+1):
        while n%i==0:
            n//=i
            a.append(i)
    if n!=1:
        a.append(n)
    return a
n=int(input())
A=factorization(n)
B=Counter(A)
count=0
for key,value in B.items():
    for i in range(1,value+1):
        if n%(key**i)==0:
            count+=1
            n//=(key**i)
        else:break
print(count)

Measured memory_bytes: 9680
#include <bits/stdc++.h>
#define REP(i, a, b) for (long long i = a; i <= b; ++i)
#define ll long long
#define N 110
using namespace std;

ll n, ans, a[N];

inline ll read(){										//快读 
	ll s = 0, w = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9'){
		if (ch == '-') w *= -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9'){
		s = s * 10 + ch - '0';
		ch = getchar();
	}
	return s * w;
}

int main(){
	n = read();											//有n朵花 
	REP(i, 1, n) a[i] = read();							//最后要求第i朵花的高度 
	REP(i, 1, n)
		if (a[i - 1] < a[i]) ans += a[i] - a[i - 1];	//如果这朵花比前1朵花的矮那就加上这2朵的高度之差 
	printf("%lld\n", ans);
	return 0;
}

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


int main()
{
   int S,sec,min,hour;

   cin >> S;

   sec = S % 60;
   min = S / 60;

   hour = min / 60;
   min = min % 60;

   cout << hour << ":" << min << ":" << sec << endl;

   return 0;
} 

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

int main() {
  string s;
  cin >> s;
  string s1, s2;
  for(int i = 0; i < s.size(); i++) {
    if(i % 2 == 0) {
      s1 += '0';
      s2 += '1';
    } else {
      s1 += '1';
      s2 += '0';
    }
  }
  int d1 = 0, d2 = 0;
  for(int i = 0; i < s.size(); i++) {
    if(s[i] != s1[i]) {
      d1++;
    } if(s[i] != s2[i]) {
      d2++;
    }
  }
  cout << min(d1, d2);
}

Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>
using namespace std;
int a,b;
int main()
{
    cin>>a>>b;
    if(a % b)cout<<a;
    else cout<<-1;
}


Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val s = sc.nextLine.toCharArray
    val first = s(0)
    var ans = true
    for (i <- 1 until 3) {
      if (s(i) != first) {
        ans = false
      }
    }
    println(if (ans) "No" else "Yes")
  }
}


Measured memory_bytes: 25652
import sys
import numpy as np

sys.setrecursionlimit(10 ** 7)

r1, c1, r2, c2 = map(int, input().split())


# 階乗、Combinationコンビネーション(numpyを使う)

def cumprod(arr, MOD):
    L = len(arr)
    Lsq = int(L**.5+1)
    arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
    for n in range(1, Lsq):
        arr[:, n] *= arr[:, n-1]
        arr[:, n] %= MOD
    for n in range(1, Lsq):
        arr[n] *= arr[n-1, -1]
        arr[n] %= MOD
    return arr.ravel()[:L]


def make_fact(U, MOD):
    x = np.arange(U, dtype=np.int64)
    x[0] = 1
    fact = cumprod(x, MOD)
    x = np.arange(U, 0, -1, dtype=np.int64)
    x[0] = pow(int(fact[-1]), MOD-2, MOD)
    fact_inv = cumprod(x, MOD)[::-1]
    return fact, fact_inv


MOD = 10 ** 9 + 7
U = 10**6 * 2 + 10
fact, fact_inv = make_fact(U, MOD)


def mod_comb_k(n, k, mod):
    return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod


def calc_rc(r, c):
    a = mod_comb_k(r + c + 2, r + 1, MOD)
    b = 1
    return a-b


ans = calc_rc(r2, c2) + calc_rc(r1-1, c1-1) - \
    calc_rc(r1-1, c2) - calc_rc(r2, c1-1)
ans %= MOD

print(ans)


Measured memory_bytes: 90496
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

alias Item = Tuple!(int, "weight", long[], "values");

long calc(int W, Item[] items) {

    long rec(int p, long weight, long value) {
        if (p == items.length) return value;

        long ans = rec(p + 1, weight, value); // p 番目は使わないときの解
        auto w = items[p].weight;
        auto v = items[p].values;
        for (int i = 0; i < v.length; i++) {
            long w2 = weight + w * (i + 1);
            if (w2 > W) break;

            long v2 = value + v[i];
            ans = max(ans, rec(p + 1, w2, v2));
        }
        return ans;
    }

    return rec(0, 0, 0);
}

void main() {
    auto nw = readints;
    int n = nw[0], W = nw[1];

    int[][int] d;
    for (int i = 0; i < n; i++) {
        auto wv = readints;
        int w = wv[0], v = wv[1];
        d[w] ~= v;
    }

    Item[] items;
    foreach (k, v; d) {
        long[] t = v.dup.to!(long[]);
        t.sort();
        t.reverse();
        for (int i = 1; i < t.length; i++) {
            t[i] += t[i-1];
        }
        items ~= Item(k, t);
    }

    writeln(calc(W, items));
}


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

int selectinsert(int A[], int n){
  int i,j,minv;
  int sw=0;
    for ( i = 0;i<n-1;i++){
      minv=i;
      for (j=i;n>j;j++){
        if(A[minv]>A[j]){
        minv=j;
        }
      }
      swap(A[i],A[minv]);
      if(i != minv){
      sw +=1;
      }
  }
  return sw;
}

int main(){
  int n, i, j,sw;
  int A[100];
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) scanf("%d", &A[i]);
  sw=selectinsert(A,n);
  for ( i = 0; i < n; i++ ){
    if ( i > 0 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
  printf("%d\n", sw);
  return 0;
}

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

int main(){
  int n,sum=0; cin>>n;
  for(int i=1;i<n+1;i++){
    int sum2=0;
    for(int j=1;j<i+1;j++){
      if(i%j==0) sum2++;
    }
    if(sum2==8 &&i%2==1) sum++;
  }
  cout<<sum<<endl;
}  


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<(b)?(a=b,1):0)
#define chmin(a,b) (a>(b)?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
const int INF = 1<<29;
const double EPS = 1e-8;
const double PI = acos(-1);
typedef pair<int,int> pii;
typedef long long ll;

int t[101][101];

int dis(pii p, pii q) {
  return abs(p.first - q.first) + abs(p.second - q.second);
}
int main() {
  int n;
  int a[101];
  while(cin>>n) {
    memset(a,-1,sizeof(a));
    REP(i,4) {
      int x; cin >> x;
      x--;
      a[x] = i;
    }
    int ans = INF;
    for (int w=1; w<=n; ++w) {
      memset(t,0,sizeof(t));
      pii p[4];
      int cx = 0, cy = 0;
      int cnt = 0;
      while(cnt<n) {
        if (a[cnt] >= 0) {
          p[a[cnt]] = pii(cy,cx);
        }
        
        cx++;
        if (cx == w) {
          cx = 0;
          cy++;
        }
        cnt++;
      }
      // cout << w << endl;
      // REP(i,4) cout << p[i].first << " " << p[i].second << endl;
      chmin(ans, dis(p[0],p[1])+dis(p[2],p[3]));
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define loop(i,a,b) for(ll i = (ll)a ; i < (ll)b ; i++)
#define rtloop(i,a,b) for(ll i = (ll)a; i >= (ll)b; i--)
#define pb push_back
#define mp make_pair
#define yo(a) cerr <<#a <<" = " << a <<"\n";
#define COOL ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);



void solve(){
    ll s, w;
    cin >> s >> w;
    if(s <= w)cout <<"unsafe\n";
    else cout <<"safe\n";



    
}



int main() {
    // #ifndef ONLINE_JUDGE
    //     freopen("inn.txt", "r", stdin);
    //     freopen("op.txt", "w", stdout);
    // #endif
    // COOL
    // ll t;
    // cin >> t;
    // while(t--)
        solve();
    
        


    return 0;
}





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

using namespace std;

const int MAX = 100000;

int parent(int table[], int child) {
	queue<int> q;

	while (table[child] != -1) {
		q.push(child);
		child = table[child];
	}
	while (!q.empty()) {
		table[q.front()] = child;
		q.pop();
	}
	return child;
}

int main() {
	int n, m, q;
	int table[MAX];

	cin >> n >> m;

	for (int i = 0; i < n; i++)table[i] = -1;
	for (int i = 0; i < m; i++) {
		int s, t;
		cin >> s >> t;
		
		int ps = parent(table, s);
		int pt = parent(table, t);
		if (ps != pt) {
			table[ps] = pt;
		}
	}

	cin >> q;

	for (int i = 0; i < q; i++) {
		int s, t;
		cin >> s >> t;

		int ps = parent(table, s);
		int pt = parent(table, t);

		if (ps == pt) {
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3672
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 15;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

ll X[100050];
ll Y[100050];
ll getv(int N, ll* a) {
	ll rv = 0;
	for (int i = 1; i <= N; i++) {
		ll v = a[i] * (2 * i - N - 1);
		v = (v%MOD + MOD) % MOD;
		rv = (rv + v) % MOD;
	}
	return rv;
}
int main() {
	int N, M, i;
	scanf("%d %d", &N, &M);
	for (i = 1; i <= N; i++) scanf("%lld", &X[i]);
	for (i = 1; i <= M; i++) scanf("%lld", &Y[i]);

	return !printf("%lld\n", getv(N, X) * getv(M, Y) % MOD);
}

Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<Long> aa = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            long tmp = sc.nextLong();
            if(n % 2 == 0) {
                if(i % 2 == 1) {
                    aa.add(0, tmp);
                } else {
                    aa.add(tmp);
                }
            } else {
                if(i % 2 == 0) {
                    aa.add(0, tmp);
                } else {
                    aa.add(tmp);
                }
            }

        }
        for (Long long1 : aa) {
            System.out.print(long1 + " ");
        }
    }
}

Measured memory_bytes: 67668
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <vector>

using namespace std;

#define debug(x) (cout << # x ": " << x << endl)
#define int long long int
#define repeat(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()

int dp[201][201] = {0};
int mgcd(int a, int b) {
    if (dp[a][b] > 0) {
        return dp[a][b];
    }

    dp[a][b] = gcd(a, b);
    return gcd(a, b);
}

signed main() {
    int k;
    cin >> k;

    int ans = 0;
    repeat(a, k) {
        repeat(b, k) {
            repeat(c, k) {
                ans += mgcd(mgcd(a + 1, b + 1), c + 1);
            }
        }
    }

    cout << ans;
    
    return 0;
}

Measured memory_bytes: 3436
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int MAXN = 1e5  + 10;
long long dp[MAXN];
long long h[MAXN];
int main() {
  int n;
	cin >> n;
  	for (int i = 1; i <= n; i++) {
    	cin >> h[i];
      dp[i] = INF;
    }
  	dp[1] = 0;
  for (int i = 1; i <= n; i++) {
  	for (int j = 1; j <= 2 && i + j <= n; j++) {
    	dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
    }
  }
                        
  cout << dp[n];
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;

const int N = 1e5;
const int INF = 1e9;
typedef long long int ll;
typedef pair<int,int> ii;


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

	int r;
	cin>>r;
	cout<<r*r<<"\n";

}

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

int main() {
  int W, H, N; // <= 100
  cin >> W >> H >> N;

  int x_begin = 0;
  int x_end = W;
  int y_begin = 0;
  int y_end = H;

  for (int i = 0; i < N; i++) {
    int x, y, a;
    cin >> x >> y >> a;

    // 長方形の x < xi を満たす領域を黒く塗りつぶす
    if (a == 1) {
      x_begin = max(x_begin, x);
    // 長方形の x > xi を満たす領域を黒く塗りつぶす
    } else if (a == 2) {
      x_end = min(x_end, x);
    // 長方形の y < xi を満たす領域を黒く塗りつぶす
    } else if (a == 3) {
      y_begin = max(y_begin, y);
    // 長方形の y > xi を満たす領域を黒く塗りつぶす
    } else if (a == 4) {
      y_end = min(y_end, y);
    } else {
      cout << "error: a = " << a << endl;
      return 1;
    }
  }

  if (x_end > x_begin && y_end > y_begin) {
    cout << ((x_end - x_begin) * (y_end - y_begin)) << endl;
  } else {
    cout << 0 << endl;
  }

  return 0;
}

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

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

const int N = 200001 * 2 + 200001;
struct edge{ int to,cost; };
vector< edge > G[N];

void dikstra(int s,int t){
  typedef pair<int, int> P;
  const int INF = 1 << 30;

  priority_queue<P,vector<P>,greater<P>> que;
  vector<int> d(N,INF); //sからの最短距離
  d[s] = 0;
  que.push({0,s}); //{最短距離,頂点}

  while( !que.empty() ){
    P p = que.top(); que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    for(auto e : G[v]){
      if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push( {d[e.to],e.to} );
      }
    }
  }
  if(d[t] == INF) cout << -1 << endl;
  else cout << d[t] << endl;
}

using P = pair<int,int>;

signed main(){

  int n,m; cin >> n >> m;
  vector<int> p(m),q(m),c(m);
  vector<vector<int>> station(n);
  vector<P> v;
  for(int i = 0; i < m; i++){
    cin >> p[i] >> q[i] >> c[i];
    p[i]--,q[i]--,c[i]--;
    station[p[i]].push_back(c[i]);
    station[q[i]].push_back(c[i]);
    v.push_back({p[i],c[i]});
    v.push_back({q[i],c[i]});
  }

  for(int i = 0; i < n; i++){
    v.push_back({i,-1});
  }
  // sort(v.begin(),v.end());
  // v.erase(unique(v.begin(),v.end()),v.end());

  map<pair<int,int>,int> mp;
  for(int i = 0; i < v.size(); i++){
    mp[v[i]] = i;
  }

  for(int i = 0; i < n; i++){
    for(int c : station[i]){
      int u = mp[{i,c}];
      int v = mp[{i,-1}];
      G[v].push_back({u,0});
      G[u].push_back({v,1});
    }
  }

  for(int i = 0; i < m; i++){
    int u = mp[{p[i],c[i]}];
    int v = mp[{q[i],c[i]}];
    G[u].push_back({v,0});
    G[v].push_back({u,0});
  }
  dikstra(mp[{0,-1}],mp[{n-1,-1}]);

  return 0;
}


Measured memory_bytes: 105320
#include<iostream>
#include<stdlib.h>
#include<iomanip>
#include<string>
#include<math.h>
 
using namespace std;
 
int main(){
    bool ans=false;
    bool check=true;
    int n,m,k;
    string a[51],b[51];
    cin>>n>>m;
    k=n-m+1;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<m;i++){
        cin>>b[i];
    }
    for(int y=0;y<k;y++){
        for(int x=0;x<k;x++){
            check=true;
            for(int yy=0;yy<m;yy++){
                for(int xx=0;xx<m;xx++){
                    if(a[y+yy][x+xx]!=b[yy][xx])check=false;
                }
            }
            if(check)ans=true;
        }
    }
    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
 
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll N,M; cin >> N >> M;
    vector<pll> AB(M);
    for(int i = 0; i < M;i++){
        cin >> AB[i].first >> AB[i].second;
    }
    sort(AB.begin(),AB.end());
    reverse(AB.begin(), AB.end());
    ll res = 0;
    for(int i = 0; i < M-1;i++){
        if(AB[i].first >= N)continue;
        else{
            res += N - AB[i].first;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3164
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <utility>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cassert>
#include <string.h>

using namespace std;
#define  rep(i,n) for(int i=0;i<n;i++)
#define  rrep(i,n) for(int i=n;i>0;i--)
#define  REP(i,a,b) for(int i=a;i<b;i++)
typedef long long int lld;
typedef vector<lld> vl;
typedef vector<int> vi;
typedef vector<string> vs;



//int arr[N]
////sort(arr,arr +N)

//vector <int> hoge
////sort(hoge.begin(),hoge.end());
///min_element(hoge.begin(),hoge.end();　最小値　　　最大値はmax_element();

int main() {

	int a,count=0,flag=0;
	vi x(100,0);
	cin>>a;
	rep(i,a){
		cin>>x[i];
	}
	rep(i,a){
		REP(m,0,i) {
			if (x[i] - x[m] < 0)
				flag=1;

		}
		if(flag==0)
			count++;
		flag=0;
	}
	cout<<count;
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int n,count1=0,count2=0,j;
    scanf("%d",&n);
    int arr[n];
    for(int i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    for(int i=0;i<n;i++)
    {
        if((arr[i]==(i+1)))
        {
            count1++;
        }
        if(arr[i]!=(i+1))
        {
            count2++;
        }
    }
    if((count1==n))
    {
        printf("YES\n");
    }
    else if(count2<=2)
    {
        printf("YES\n");
    }
    else
    {
        printf("NO\n");
    }


    return 0;
}

Measured memory_bytes: 1636
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define M 1000000007
#define enter ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define test ll t; cin>>t; while(t--)
#define pb push_back
#define mp make_pair 
typedef long long int ll;
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    enter
    // test
    // {
        
    // }
    ll n;   cin>>n;
    ll a=0, b=0, c=0, d=0;
    for(ll i=0; i<n; i++)
    {
        string x;   cin>>x;
        if(x == "AC")
            a++;
        else if(x == "WA")
            b++;
        else if(x == "TLE")
            c++;
        else
            d++;
    }
    cout<<"AC x "<<a<<endl<<"WA x "<<b<<endl;
    cout<<"TLE x "<<c<<endl<<"RE x "<<d<<endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define INT(name) int name; scanf("%d",&name);
#define VINT(name,n) vector<int> name(n); for(int i = 0;i < n;i++) scanf("%d",&name[i]);

using namespace std;

int main(int argc, char const *argv[]){
	INT(n)
	int a,b,c;
	while(n--){
		VINT(data,3)
		sort(data.begin(),data.end());
		if(pow(data[2],2) == pow(data[0],2) + pow(data[1],2)){
			printf("YES\n");
		}else{
			printf("NO\n");
		}

	}
}

Measured memory_bytes: 1184
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
const int MOD = 1e9+7;
const int MAX = 1e6+10;
const int INF = 0x3fffffff;
struct node{
	int t;
	int x,y;
}p[MAX];
int n;
int main(){
	while(scanf("%d",&n)!=EOF){
		p[0].t=0;
		p[0].x=0;
		p[0].y=0;
		for(int i=1;i<=n;i++){
			scanf("%d%d%d",&p[i].t,&p[i].x,&p[i].y);
		}
		int flag=1;
		for(int i=1;i<=n;i++){
			int ts = p[i].t-p[i-1].t;
			int tot = abs(p[i].x-p[i-1].x)+abs(p[i].y-p[i-1].y);
			if(ts>=tot&&(ts-tot)%2==0){
				continue;
			}
			else {
				flag=0;
				break;
			}
		}
		if(flag==0)	printf("No\n");
		else printf("Yes\n");
	}
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <numeric>
using namespace std;

int main(int argc, char const *argv[])
{
  int N;
  vector<pair<long, long>> D;
  using pii = pair<long, long>;

  cin >> N;
  D.reserve(N);
  for (int i = 0; i < N; ++i)
  {
    int a, b;
    cin >> a >> b;
    D.push_back(make_pair(a, b));
  }
  vector<int> A(N);
  iota(A.begin(), A.end(), 0);

  sort(A.begin(), A.end(), [&](int x, int y) {
    long xs = D[x].first + D[x].second;
    long ys = D[y].first + D[y].second;
    return xs > ys;
  });

  long answer = 0;

  int turn = 0;
  for (int &i : A)
  {
    answer += turn++ % 2 ? -D[i].second : D[i].first;
  }

  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>

using namespace std;
using ll = long long;

struct Block {
    ll w;
    ll s;
    ll v;
};

const int NNODES = 1009;
const int NWEIGHTS = 2e4 + 7;
Block b[NNODES];
ll dp[NWEIGHTS];
ll t[NWEIGHTS];

bool cmp(Block a, Block b) {
    return (a.s + a.w) < (b.s + b.w);
}

ll solve(int n) {
    ll maxV = 0;
    dp[b[0].w] = b[0].v;
    for (int i = 1; i < n; i++) {
        for (int j = 1; j <= b[i].s+b[i].w; j++) {
            if (j-b[i].w > 0 && dp[j-b[i].w] > 0) {
                t[j] = max(t[j], dp[j-b[i].w] + b[i].v);
                // printf("rrr %d %lld %lld\n", j, b[i].w, dp[j]);
            }
        }
        t[b[i].w] = max(t[b[i].w], b[i].v);
        // printf("rrr %lld %lld\n", b[i].w, dp[b[i].w]);

        for (int j = 1; j <= b[i].s+b[i].w; j++) {
            dp[j] = max(dp[j], t[j]);
            t[j] = 0;
        }
    }
    
    for (int j = 0; j <= NWEIGHTS; j++) {
        maxV = max(maxV, dp[j]);
        // if (dp[j] > 0) {
        //     printf("sss %d %lld\n", j, dp[j]);
        // }
    }
    return maxV;
}
int main() {
    memset(dp, 0, sizeof(dp));
    memset(t, 0, sizeof(t));
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        ll tw, ts, tv;
        cin >> tw >> ts >> tv;
        b[i] = Block{tw, ts, tv};
    }
    sort(b, b+n, cmp);
    // for (int i = 0; i < n; i++) {
    //     printf("%lld %lld %lld\n", b[i].w, b[i].s, b[i].v);
    // }
    printf("%lld\n", solve(n));
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_cxx;
#define dprint(v) cout << #v"=" << v << endl //;)
#define sz(c) ((int)c.size())
#define zero(v) memset(v, 0, sizeof(v))
#define forall(it,v) for(auto it=v.begin();it!=v.end();++it)
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define INF (ll)1e16
#define endl '\n'
#define isin(x,y) ((y).find(x)!=(y).end())

typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
const double EPS = 1e-9;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll n;
    cin>>n;
    forn(i,50006)if((ll)(EPS+(double)i*1.08)==n){
        cout<<i<<endl;
        return 0;
    }
    cout<<":("<<endl;
	return 0;
}


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

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 1000000000
#define MOD 1000000007

typedef  long long ll;

using namespace std;

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

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

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return a;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    cout<<  ans << endl;
    }
}

void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}

void solve(void){
    int n;
    cin >> n;
    int  dp[n+1]; //i円の時の回数
    dp[0] = 0;

    rep(i,1,n+1){
        dp[i] = INF;
    }
    
    rep(i,1,n+1){
        chmin(dp[i],dp[i-1]+1);
        for(int j = 6;j < 10;j+=3){
            int k = j;
            while(i >= k){
                chmin(dp[i],dp[i-k]+1);
                k*=j;
            }
        }
    }
    cout << dp[n] << endl;

}

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

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

int dp[10010];
int v[105], w[105], m[105];
signed main(void)
{
  int n, W;
  cin >> n >> W;
  REP(i, n) cin >> v[i] >> w[i] >> m[i];
  REP(i, n) {
    int num = m[i];
    for(int k=1; num > 0; k <<= 1) {
      int mu = min(k, num);
      for(int j=W; j>=w[i]*mu; --j) {
        dp[j] = max(dp[j], dp[j-w[i]*mu]+v[i]*mu);
      }
      num -= mu;
    }
  }
  cout << dp[W] << endl;
  return 0;
}

Measured memory_bytes: 3132
def getN():
    return int(input())

def getMN():
    return list(map(int, input().split()))

def getlist():
    return list(map(int, input().split()))

n, m = getlist()
imos = [0 for i in range(n+1)]
for i in range(m):
    a, b = getlist()
    imos[a-1] += 1
    imos[b] -= 1

accum = [0]
tmp = 0
for val in imos:
    tmp += val
    accum.append(tmp)

ans = 0
for v in accum:
    if v == m:
        ans += 1

print(ans)

Measured memory_bytes: 8104
l = list(input())
n = len(l)

ans = 0
for i in reversed(range(n)):
    if l[i] == '?':
        if not i==0:
            if l[i-1]=="P":
                l[i] = "D"
                continue
        if not i==n-1:
            if l[i+1] == "D":
                l[i] = "P"
                continue
        l[i] = "D"
        
print("".join(l))

Measured memory_bytes: 10904
#include<cstdio>
using namespace std;
int main(void)
{
	int n,a,b,c,x;
	scanf("%d",&n);
	a=n/100;
	b=(n/10)%10;
	c=n%10;
	x=a+b+c;
	printf("%d\n",x);
	return 0;
}

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

using namespace std;

int n, c[500], s[500], f[500];

int main(){
	cin >> n;
	for(int i = 0; i < n - 1; ++i) cin >> c[i] >> s[i] >> f[i];
	for(int i = 0; i < n - 1; ++i){
		int t = s[i];
		for(int j = i; j < n - 1; ++j){
			if(s[j] <= t && t % f[j] == 0) t = t + c[j];
			else{
				t++;
				j--;
			}
		}
		cout << t << endl;
	}
	cout << 0 << endl;
}

Measured memory_bytes: 256