akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll INF = 1LL<<58;
 
int main(){
    string s;
  	cin >> s;
  	set<char> chars;
  	for(ll i = 0; i < s.length(); ++i) chars.insert(s[i]);
  
  	if(chars.size() == 1){
      cout << 0 << endl;
      return 0;
    }
  
  	ll res = 100, times;
  	for(auto key = chars.begin(); key != chars.end(); ++key){
      string str = s;
      bool flag = true;
      times = 1;
      
      while(flag){
        string vacant;
        flag = false;
        for(ll i = 0; i < str.length()-1; ++i){
          // shrink
          if(str[i] == *key || str[i+1] == *key){
            vacant += *key;
          } else {
            vacant += str[i];
            flag = true;
          }
        }
        
        if(flag) {
          str = vacant;
          times++;
        }
      }
      chmin(res,times);
    }
  	cout << res << endl;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(abs(c-a)<=d)
	{
		cout<<"Yes";
		return 0;
	}
	else if(abs(b-a)<=d&&abs(c-b)<=d)
	{
		cout<<"Yes";
		return 0;
	}
	cout<<"No";
	return 0;
}

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

using namespace std;

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

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int k;
	cin >> k;
	ll res;
	queue<ll> q;
	rep(i, 9) q.push((ll)i + 1);
	rep (i, k - 1) {
	  ll f = q.front();
	  q.pop();
	  ll d = f % 10;
	  rep (j, 10) {
		if (abs(j - d) <= 1) q.push(f * 10 + j);
	  }
	}
	cout << q.front() << endl;
    
    return 0;
}


Measured memory_bytes: 4768
import sys
import numpy as np

n = int(input())
tasks = np.fromstring(sys.stdin.read(), sep=' ').reshape((n, 2))
a = tasks[:, 0]
b = tasks[:, 1]
i = b.argsort()
print('Yes' if (np.add.accumulate(a[i]) <= b[i]).all() else 'No')


Measured memory_bytes: 20720
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
constexpr ll INF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
template <class T>
void chmin(T &a, T b) { a = min(a, b); }
template <class T>
void chmax(T &a, T b) { a = max(a, b); }
void debug() { cerr << "ok" << endl; }
template <class T>
void printv(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void readv(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
template <class T>
struct Dijkstra {
    int n;
    vector<vector<pair<T, int>>> G;
    Dijkstra(int n) : n(n), G(n) {}
    void addedge(const int &u, const int &v, const T &c) { G[u].emplace_back(v, c); }
    vector<T> dijkstra(const int &st) {
        priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> q;
        vector<T> d(n, INF);
        d[st] = 0;
        q.emplace(0, st);
        while (!q.empty()) {
            int v = q.top().second;
            T dd = q.top().first;
            q.pop();
            if (d[v] < dd) continue;
            for (auto &e : G[v]) {
                if (d[e.first] > d[v] + e.second) {
                    d[e.first] = d[v] + e.second;
                    q.emplace(d[e.first], e.first);
                }
            }
        }
        return d;
    }
};
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n, m, s;
    cin >> n >> m >> s;
    ll w = 3000;
    Dijkstra<ll> g(n * w + 10);
    chmin(s, w - 1);
    for (int i = 0; i < m; i++) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        --u;
        --v;
        for (int j = a; j < w; j++) {
            g.addedge(w * u + j, w * v + j - a, b);
            g.addedge(w * v + j, w * u + j - a, b);
        }
    }
    for (int i = 0; i < n; i++) {
        ll c, d;
        cin >> c >> d;
        for (int j = 0; j + 1 < w; j++) {
            int to = min(j + c, w - 1);
            g.addedge(i * w + j, i * w + to, d);
        }
    }
    V<ll> d = g.dijkstra(s);
    for (int i = 1; i < n; i++) {
        ll res = INF;
        for (int j = 0; j < w; j++) {
            chmin(res, d[i * w + j]);
        }
        cout << res << '\n';
    }
}

Measured memory_bytes: 27380
#include<bits/stdc++.h>
using namespace std;
int g(int a,int b,int c)
{
	int k=min(a,min(b,c));
	for(int i=k;i>=1;i--)
	if(a%i==0 && b%i==0 && c%i==0)
	return i;
}
int main()
{
	int n;
	cin>>n;
	int a=1,b=1,c=1;
	long long s=0;
	while(!(a==n && b==n && c==n+1))
	{
		if(c>n)
		{
			b++;
			c=1;
		}
		if(b>n)
		{
			a++;
			b=1;
			c=1;
		}
		if(a>b || b>c ||a>c)
		{
			c++;
			continue;
		}
		int t=g(a,b,c);
		if(a==b && b==c)
		s+=t;
		else if((a!=b || a!=c || b!=c) && (a==b || b==c || c==a))
		s+=t*3;
		else
		s+=t*6;
		c++;
	}
	cout<<s;
	return 0;
 } 

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define fo(i,a,b) for(int i=a;i<b;i++)
using namespace std;
int dp(int n,int k,int h[])
{
    int d[n];d[0]=0;
    fo(i,1,n)
    d[i]=INT_MAX;
    fo(i,0,n)
    {
        fo(j,1,k+1)
        {
            if(i+j<n)
            d[i+j]=min(d[i+j],d[i]+abs(h[j+i]-h[i]));
        }
    }
    return d[n-1];
}
int main()
{
    fastio;
    int n,k;
    cin>>n>>k;
    int h[n];
    fo(i,0,n)
    cin>>h[i];
    cout<<dp(n,k,h)<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#define MIN 1<<31-1
#define HMAX 1000000000000000000
#define MOD 1000000007
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RSET(s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
typedef long long int ll;
using namespace std;
int main()
{
	ll a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	if(c>(a+b)/2)
		cout<<d*a+e*b;
	else
	{
		int C;
		if(d>e)
		{
			swap(d,e);
			swap(a,b); 
		}
		C=d;
		d-=C;e-=C;
		if(b<2*c)
		cout<<C*2*c+e*b;
		else
		cout<<C*2*c+2*c*e;
	}
}

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

int main()
{
    int n;
    string s;
    cin >> n;
    cin >> s;
    int maxi = 0;
    int value = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'I')
        {
            value += 1;
        }
        else
        {
            value -= 1;
        }
        if (value > maxi)
        {
            maxi = value;
        }

    }
    cout << maxi;
    return 0;
}


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

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map

void doit(){
	ll t, a, k;
	cin >> t >> a >> k;
	ll r = max(0LL,t-k);
	cout << max(0LL,t-k) << " " << max({0LL, a - (k - t + r)});
}

int main(){ 
#ifndef ONLINE_JUDGE
 //   freopen("input1.txt","r",stdin);
  //  freopen("output1.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
     //cin >> t;
    for(ll i = 1; i <= t; i++){
        doit();
    }
}


Measured memory_bytes: 3636
n = int(input())
S = list(input())
C = []
a = 65
z = 90

for s in S:
	sss = ord(s)+n
	if sss > 90:
		sss = sss-26
	C.append(sss)

ans = []
[ans.append(chr(c)) for c in C]
print("".join(ans))

Measured memory_bytes: 3316
import java.util.Scanner

fun main(args: Array<String>){
    val scn = Scanner(System.`in`)
    val v = scn.nextLine().split(" ")
    val K = v[0].toInt()
    val N = v[1].toInt()
    val Ai =  scn.nextLine().split(" ").map { i -> i.toInt() }

    val sortAi = Ai.sorted()

    var max = 0
    var maxInd = 0
    (0 until Ai.size).forEach {i ->
        var tmp = 0
        if(i==0){
            tmp = K - sortAi[Ai.size-1] + sortAi[0]
        }else{
            tmp = sortAi[i]-sortAi[i-1]
        }
        if(tmp >= max){
            max = tmp
            maxInd = i
        }
    }

    var i = maxInd
    val end = if(maxInd==0) Ai.size-1 else maxInd -1
    var result = 0

    do{
        if(i==Ai.size-1){
            result += K - sortAi[Ai.size-1] + sortAi[0]
            i=0
        }else{
            result += sortAi[i+1] - sortAi[i]
            i++
        }
    }while (i!=end)


    print(result)
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    string s;
    cin >> s;
    OP(700 + 100 * count(ALL(s), 'o'));
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String str = br.readLine();
        String[] strs = str.split(" ");
        //--- list?????¨??? ---
        for(int i = strs.length-1; i >= 0; i--){
            if(i != 0){
                System.out.print(strs[i] + " ");
            }else{
                System.out.print(strs[i]);
            }//if
        }//for
        System.out.println();
    }
}

Measured memory_bytes: 17028
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    string s;
    cin>>s;
    rep(i, 19) {
        if (i == 5 || i == 13) cout<<" ";
        else cout<<s[i];
    }
    cout<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a;
	cin >> a;
	int arr[a];
	for(int i=0; i<a; i++)
		cin >> arr[i];
	sort(arr, arr+a);
	int mid = a / 2;
	int ans = arr[mid] - arr[mid - 1];
	printf("%d\n",ans);
	return 0;
}

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

#define ALL(a) begin(a), end(a)
#define SZ(a) ((int)(a).size())

#ifdef __DEBUG
#define debug if (true)
#else
#define debug if (false)
#endif

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vi a(3 * n);
  for (int i = 0; i < 3 * n; i++) {
    cin >> a[i];
  }
  sort(ALL(a));
  ll ans = 0;
  for (int i = 0, j = 3 * n - 1; i <= j; i++, j -= 2) {
    ans += a[j - 1];
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 1408
from collections import deque
N = int(input())
A = list(map(int, input().split()))
#N=3
#A=[1,2,3]
q=deque(A)
#print(q)
ans=0
sums=sum(q)
#print(sums)
for i in range(N-1):
    qwe=q.popleft()
    ans+=qwe *(sums-qwe)
    sums-=qwe
print(ans%(10**9+7))

Measured memory_bytes: 96836
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace At
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Read();
            if (n[0].ToString() == "9")
            {
                WriteLine("Yes");
            }
            else if (n[1].ToString() == "9")
            {
                WriteLine("Yes");
            }
            else
            {
                WriteLine("No");
            }

        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>


#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S,False(1,-1);
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

template<typename A,size_t N,typename T>
void Fill(A(&array)[N],const T &val){
    fill((T*)array,(T*)(array+N),val);
}


int main(){
    int R, G, B, N;
    cin >> R >> G >> B >> N;
    ll res = 0;

    rep(i, 3001){
        rep(j, 3001){
            ll b = N - i * R - j * G;
            if(b < 0)break;
            if(b % B == 0)res++;
        }
    }

    cout << res << endl;
}

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

int main(){
    int N,M;
    while(cin >> N >> M && N){
        vector<vector<int>> P(M+1,vector<int>(N+1,0));
        for(int i=1;i<=M;i++){
            for(int j=1;j<=N;j++){
                cin >> P[i][j];
            }
        }
        int ans = 0;
        for(int j=1;j<=N;j++){
            int sum = 0;
            for(int i=1;i<=M;i++){
                sum += P[i][j];
            }
            ans = max(ans,sum);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3224
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
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;
}
const int MOD = 1000000007;
int main() {
    int R, G, B, N;
    cin >> R >> G >> B >> N;
    int res = 0;
    rep(a, 0, N + 1) {
        rep(b, 0, N - R * a + 1) {
            int nokori = N - (R * a) - (G * b);
            if(nokori >= 0 && nokori % B == 0) {
                // cout << "nokori" << nokori << endl;
                res++;
                // cout << a << "," << b << "," << nokori / B << endl;
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.00000001
#define pi 3.141592653589793
#define pii pair<int,int>
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define sti stack <int>
#define stll stack <ll>
#define mseti multiset <ll>
#define msetd multiset <ll, greater <ll> >
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define stp setprecision(20)//use fixed before stp
#define endl '\n'
int main()
{  
    FAST
    ll n;
    cin>>n;
    ll a[n];
    ll sum=0;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    ll c,b;
    ll ans=sum;
    ll x=0;
    for(ll i=0;i<n;i++)
    {
        x+=a[i];
        sum-=a[i];
        ll y=abs(sum-x);
        if(y<ans)
            ans=y;
    }
    cout<<ans;
}

Measured memory_bytes: 256
def binary_search(lst, x):
    left=0
    right=len(lst)
    while left<right:
        m=(left+right)//2
        if lst[m]==x:
            return True
        elif x<lst[m]:
            right=m
        else:
            left=m+1
    return False

def main():
    n=int(input())
    S=list(map(int,input().split()))
    q=int(input())
    T=list(map(int,input().split()))
    ans=0
    for t in T:
        if binary_search(S,t):
            ans+=1
    print(ans)

main()



Measured memory_bytes: 16712
a, b, c, x, y = map(int, input().split())

res1 = a * x + b * y

if x < y:
    res2 = c * x * 2 + b * (y - x)
else:
    res2 = c * y * 2 + a * (x - y)

res3 = c * max(x, y) * 2

res = min(res1, res2, res3)
print(res)


Measured memory_bytes: 9092
#include <algorithm>
#include <cstdio>
using namespace std;

int main(){
  int A[3];
  for (int i = 0; i < 3; i++) {
    scanf("%d", &A[i]);
  }
  std::sort(A, A + 3);
  printf("%d", A[2]-A[0]);

  return 0;
}


Measured memory_bytes: 128
import sys
入力 = sys.stdin.readline
範囲, 出力 = range, print
真, 偽 = True, False
何もしない = None
一行に複数個の入力 = lambda:map(int, 入力().split())
頂点の数, 操作回数 = 一行に複数個の入力()
辺 = [[] for _ in 範囲(頂点の数)]
カウンター = [0] * 頂点の数
辺の数 = 頂点の数-1
for _ in 範囲(辺の数):
    頂点1, 頂点2 = 一行に複数個の入力()
    頂点1 -= 1
    頂点2 -= 1
    辺[頂点1] += 頂点2,
    辺[頂点2] += 頂点1,
for _ in 範囲(操作回数):
    頂点, 足す値 = 一行に複数個の入力()
    頂点 -= 1
    カウンター[頂点] += 足す値
到達済み = [偽] * 頂点の数
親 = 0
到達済み[親] = 真
スタック = [親]
while スタック:
    親 = スタック.pop()
    for 子 in 辺[親]:
        if 到達済み[子]:
            何もしない
        else:
            到達済み[子] = 真
            カウンター[子] += カウンター[親]
            スタック += 子,
出力(*カウンター)

Measured memory_bytes: 55832
#include <bits/stdc++.h>
#include <iostream>
#include <string.h>
#include <math.h>

using namespace std;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
int dp[105][maxn], a[maxn];
int sum[maxn];

int main() {
//    freopen("in.in", "r", stdin);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    dp[1][0] = 1; sum[0] = 1;
    for (int i = 1; i <= a[1]; i++) {
        dp[1][i] = 1; sum[i] = sum[i -1] + dp[1][i];
    }
    for (int i = 1; i <= m; i++) {
        sum[i] = sum[i - 1] + dp[1][i];
    }
    for (int i = 2; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            if (j > a[i]) {
                dp[i][j] = (sum[j] - sum[j - a[i] - 1] + mod) % mod;
            } else {
                dp[i][j] = sum[j];
            }
        }
        sum[0] = dp[i][0];
        for (int j = 1; j <= m; j++) sum[j] = (sum[j - 1] + dp[i][j]) % mod;

    }
    cout << dp[n][m] << endl;
    return 0;
}

Measured memory_bytes: 40576
X, Y = map(int, input().split())

result = 0

if X < 2:
    result += 300000
elif X < 3:
    result += 200000
elif X < 4:
    result += 100000

if Y < 2:
    result += 300000
elif Y < 3:
    result += 200000
elif Y < 4:
    result += 100000

if X == 1 and Y == 1:
    result += 400000


print(result)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll a[200010];
int main()
{
    int n;
    cin>>n;
    ll sum=0;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i = 2;i <= n;i++){
        if(a[i]<a[i-1]){
            sum+=a[i-1]-a[i];
            a[i]=a[i-1];
        }
    }
    cout<<sum;
    return 0;
}


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

using namespace std;

int main(){
  int n; cin >> n;
  int res = 0, minVal = INT_MAX;
  for(int i = 0; i < n; i++){
     int x; cin >> x;
     minVal = min(minVal, x);
    if(minVal == x) res++;
  }
  
  cout << res;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 100;
const int MOD = 1000000007;

void doc() {
    freopen("OB.inp","r",stdin);
    freopen("OB.out","w",stdout);
    ///cerr << "OK" << '\n';
}

void solve() {
    int n, K;
    cin >> n >> K;
    int a[n];
    for(int i = 0; i < n; i++)
        cin >> a[i];
    long long f[n][K + 1], s[n][K + 1];
    memset(f, 0, sizeof(f));
    memset(s, 0, sizeof(s));
    for(int i = 0; i <= a[0]; i++)
        f[0][i] = 1;
    for(int i = 0; i < n; i++)
        s[i][0] = f[i][0] = 1;
    for(int i = 1; i <= K; i++){
        s[0][i] = (s[0][i - 1] + f[0][i]) % MOD;
       /// cout << i << " " << s[0][i] << '\n';
    }

    for(int i = 1; i < n; i++)
        for(int j = 1; j <= K; j++){
            if (j <= a[i])
                f[i][j] = s[i - 1][j] % MOD;
            else
                f[i][j] = (s[i - 1][j] - s[i - 1][j - a[i] - 1] + MOD) % MOD;
            s[i][j] = (s[i][j - 1] + f[i][j]) % MOD;
           /// cout << i << " " << j << " " << f[i][j] << '\n';
        }

    cout << f[n - 1][K];
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
    //doc();
    solve();
}



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

ll c(ll x){
    if(x < 2) return 0;
    else return (x*(x-1))/2;
}

int main(){
    ll N; cin >> N;
    vector<ll> A(N);
    
    map<ll, ll> m;
    vector<ll> list;
    rep(i,N){
        cin >> A[i];
        if(m[A[i]] == 0) list.push_back(A[i]);
        m[A[i]]++;
    }
    ll sum = 0;
    for(ll i: list) sum += c(m[i]);
    rep(i, N) cout << sum - m[A[i]]+1 << endl;
    return 0;
}

Measured memory_bytes: 12020
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int a, b, c; cin >> a >> b >> c;
  int o = (a & 1) + (b & 1) + (c & 1);
  cout << (o < 2 ? "Tem" : "Hom") << '\n';
}


Measured memory_bytes: 3124
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <ctype.h>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
// const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if(a + b >= 10){
        cout << "error" << endl;
    }
    else {
        cout << a + b << endl;
    }
    return 0;
}

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

const int mod = 10007;
const int MAX_N = 1024;
int dp[MAX_N][8];
const char s[3] = {'J', 'O', 'I'};
const int array[3] = {1, 2, 4};
int bit[1024];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	
	string str;
	cin >> str;
	
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < 3; ++j){
			if(str[i] == s[j]) bit[i] += array[j];
		}
	}
	
	dp[0][1] = 1;
	for(int i = 0; i <= n; ++i){
		for(int j = 0; j < 8; ++j){
			if(bit[i] & j){
				for(int k = 0; k < 8; ++k){
					if(k & j){
						dp[i + 1][j] += dp[i][k];
						dp[i + 1][j] %= mod;
					}
				}
			}
		}
	}
	
	int ans = 0;
	for(int i = 0; i < 8; ++i){
		ans += dp[n][i];
		ans %= mod;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1236
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int X = sc.nextInt();
        int minCost = 1000;
        for (int l = 0; l < N; l++) {
            int m = sc.nextInt();
            minCost = Math.min(minCost,m);
            X -=m;
        }
        System.out.println(N+(X/minCost));
    }
}


Measured memory_bytes: 23892
def test():
    num = {"A":10,"B":11,"C":12,"D":13,"E":14,"F":15}
    x,y = input().split()
    if num[x] < num[y]:
        print("<")
    elif num[x] > num[y]:
        print(">")
    else:
        print("=")


if __name__ == "__main__":
    test()


Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
    unsigned int key;
    struct node *next;
    struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
    struct node *cur = nil->next;
    while(cur != nil && cur->key != key){
        cur = cur->next;
    }
    return cur;
}

void init(){
    nil = malloc(sizeof(struct node));
    nil->next = nil;
    nil->prev = nil;
}

void printList(){
    NodePointer cur = nil->next;
    int isf = 1;
    while(1){
        if ( cur == nil ) break;
        if ( isf == 0)  printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
        isf = 0;
    }
    printf("\n");
}

void deleteNode(NodePointer t){
    if(t==nil)
        return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst(){
   // NodePointer t = nil->next;
    //if ( t == nil ) return;
    deleteNode(nil->next);
}

void deleteLast(){
    deleteNode(nil->prev);
}

void delete(int key){
    deleteNode(listSearch(key));
}

void insert(int key){
    NodePointer x;
    x = malloc(sizeof(struct node));
    x->key = key;
    x->next=nil->next;
    nil->next->prev=x;
    nil->next=x;
    x->prev=nil;
}

int main(){
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();
    for ( i = 0; i < n; i++ ){
        scanf("%s%d", com, &key);
        if ( com[0] == 'i' ) {insert(key); np++; size++;}
        else if ( com[0] == 'd' ) {
            if (strlen(com) > 6){
                if ( com[6] == 'F' ) deleteFirst();
                else if ( com[6] == 'L' ) deleteLast();
            } else {
                delete(key); nd++;
            }
            size--;
        }
    }
    
    printList();
    return 0;
}



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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] AB = Console.ReadLine().Split().Select(i => Convert.ToInt32(i)).ToArray();
            bool isYay = (AB[0] <= 8) && (AB[1] <= 8);
            string res = (isYay) ? "Yay!" : ":(";
            Console.WriteLine(res);
        }
    }
}


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

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

	ll ans = 0;
	for(int i = 1; i <= N; i++) {
		if(i % 3 != 0 && i % 5 != 0)
			ans += i;
	}

	cout << ans << endl;

	return 0;
}

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

#define ll long long int
#define pi 3.141592653589793238
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mod 1000000007
ll dx[4]={0,0,1,-1};
ll dy[4]={-1,1,0,0};
map<int,int> mp;

bool sieve(int x)
{
    for(int i=2;i*i<=x;i++)
    {
        if(x%i==0)
        {
            mp[i]++;
            if(mp[i]>1)
                return false;
            if(x/i!=i)
            {
                mp[x/i]++;
                if(mp[x/i]>1)
                    return false;
            }
        }
    }
    return true;
}


void solve()
{
    ll n;
    cin>>n;
    vector<ll> a(n);
    int g=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        mp[a[i]]++;
        g=gcd(g,a[i]);
    }
    int c=0;
    // cout<<g;
    for(int i=0;i<n;i++)
    {
        if(sieve(a[i])==false)
            c++;
    }
    // cout<<c;
    if(c==0)
    {
            cout<<"pairwise coprime";   
    }   
    else
    {
        if(g==1)
            cout<<"setwise coprime";
        else
            cout<<"not coprime";
    }
        
        
    return;
}

int main()
{
	FAST;
    ll q;
    q=1;
    // cin>>q;
    while(q--)
        solve();
	return 0;
}

Measured memory_bytes: 57788
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;

long calc(int a, int[] xs) {
    int n = cast(int)xs.length;
    int m = xs.sum;
    auto dp = new long[][](n + 1, m + 1);

    foreach (x; xs) {

        for (int i = n-1; i > 0; i--) {
            for (int j = 0; j < m; j++) {
                if (dp[i][j] > 0) {
                    dp[i + 1][j + x] += dp[i][j];
                }
            }
        }

        dp[1][x]++;
    }

    long ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            if (dp[i][j] > 0 && (j % i == 0) && (j / i == a)) {
                ans += dp[i][j];
            }
        }
    }

    return ans;
}

void main() {
    auto na = readints;
    int a = na[1];
    auto xs = readints;

    writeln(calc(a, xs));
}


Measured memory_bytes: 2940
#include <stdio.h>

int main(void) {
    int a,b,i;
    for (i = 0; i < 3000; i++) {
        scanf("%d%d", &a, &b);
        if (a == 0 && b == 0) break;
        if ( a > b ){
            printf("%d %d\n", b, a);
        }
        else{
            printf("%d %d\n", a, b);
        }
    }
    return 0;
}


Measured memory_bytes: 2036
#include <iostream>

int main()
{
    int  n              = 0;
    int  xs[1000][1000] = {};
    int  ys[1000]       = {};
    bool fs[1000]       = {};

    std::cin >> n;

    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n - 1; ++j)
        {
            int x;
            std::cin >> x;
            xs[i][j] = x - 1;
        }
    }

    int r = n * (n - 1) / 2;
    int c = 0;

    while (0 < r)
    {
        int fn = 0;

        for (int i = 0; i < n; ++i)
        {
            if (ys[i] < n - 1)
            {
                int x = xs[i][ys[i]];
                fs[i] = (xs[x][ys[x]] == i);
            }
        }

        for (int i = 0; i < n; ++i)
        {
            if (fs[i] == true)
            {
                ++fn;
                ys[i] += 1;
            }

            fs[i] = false;
        }

        if (fn == 0)
        {
            c = -1;
            break;
        }
        else
        {
            r -= fn / 2;
            c += 1;
        }
    }

    std::cout << c << std::endl;

    return 0;
}

Measured memory_bytes: 4224
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        int x = Integer.parseInt(sc.next());
        int y = Integer.parseInt(sc.next());
        int ans = 2;
        if(a+b <= c*2) {
            ans = a*x + b*y;
        }else {
            if(a <= c*2 && b <= c*2) { 
                if(x >= y) ans = c*2*y + a*(x-y);
                else ans = c*2*x + b*(y-x);
            }else if(a >= c*2 && b <= c*2) {
                if(x >= y) ans = c*2*x;
                else ans = c*2*x + b*(y-x);
            }else if(a <= c*2 && b >= c*2) {
                if(y >= x) ans = c*2*y;
                else ans = c*2*y + a*(x-y);
            }else {
                ans = c*2*max(x,y);
            }
        }
        System.out.println(ans);
    }
    
    static int max(int x, int y) {
        if(x >= y) return x;
        else return y;
    }
    
    static int min(int x, int y) {
        if(x >= y) return y;
        else return x;
    }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n,tmp) vector<tmp> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,10e9));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<auto>& a,int n);

int n;
int cnt = 0;

void insertionSort(vector<int>& a,int n,int g){
    FOR(i,g,n){
        int v = a[i];
        int j = i-g;
        while(j >= 0 && a[j] > v){
            a[j+g] = a[j];
            j = j - g;
            cnt++;
        }
        a[j+g] = v;
    }
}

void shellSort(vector<int>& a,int n,int m,vector<int>& g){
    REP(i,m){
        insertionSort(a, n, g[i]);
    }
}

signed main(){
    cin >> n;
    vec(a,n);
    input(a,n);
    vector<int> g;
    int tmp = 1;
    while(n >= tmp){
        g.push_back(tmp);
        tmp *= 3;
        tmp++;
    }
    Reverse(g);
    shellSort(a,n,g.size(),g);
    print(g.size());
    REP(i,g.size()){
        cout << g[i];
        if(i!=g.size()-1) cout << " ";
        else print("");
    }
    print(cnt);
    REP(i,n){
        print(a[i]);
    }

    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<auto>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}



Measured memory_bytes: 10716
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]

def main():
    デックの長さ, 操作可能回数 = LI()
    デック = LI()

    最大値 = 0
    for 取る数 in range(min(操作可能回数+1, デックの長さ+1)):
        捨てることができる数 = 操作可能回数 - 取る数
        for 左から取る数 in range(取る数+1):
            右から取る数 = 取る数 - 左から取る数
            取ったリスト = デック[:左から取る数] + デック[デックの長さ-右から取る数:]
            取ったリスト = sorted(取ったリスト)
            for _ in range(捨てることができる数):
                if 取ったリスト and 取ったリスト[0] < 0:
                    取ったリスト.pop(0)
                else:
                    break
            最大値 = max(最大値, sum(取ったリスト))

    print(最大値)

main()

Measured memory_bytes: 3188
# -*- coding: utf-8 -*-
s=int(input())
supper=s//100
sunder=s-(s//100)*100
if 1<=supper<=12 and 1<=sunder<=12:
    print("AMBIGUOUS")
elif 1<=supper<=12:
    print("MMYY")
elif 1<=sunder<=12:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 2940
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using P = pair<ll, ll>;
const int MOD = (int)1e9 + 7;
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, pair<T,T> const&P){
    os << P.first;
    os << " ";
    os << P.second;
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
int ans = 0;
//fixed<<setprecision(10)<<ans<<endl;
void merge(vector<int>& A, int left, int mid, int right){
    int n1 = mid-left;
    int n2 = right-mid;
    vector<int> L,R;
    L.assign(A.begin()+left, A.begin()+mid);
    R.assign(A.begin()+mid, A.begin()+right);
    int inf = 1 << 30;
    L.push_back(inf);
    R.push_back(inf);
    int i=0,j=0;
    for(int k=left; k<right; k++){
        ans++;
        if(L[i] <= R[j]){
            A[k] = L[i];
            i++;
        }else{
            A[k] = R[j];
            j++;
        }
    }
}
void mergeSort(vector<int>& A, int left, int right){
    if (left+1 < right){
        int mid = (left+right)/2;
        mergeSort(A,left,mid);
        mergeSort(A,mid,right);
        merge(A,left,mid,right);
    }
}
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i,N) cin >> A[i];
    mergeSort(A, 0, N);
    cout << A;
    cout << ans << endl;
}



Measured memory_bytes: 8660
m, d = map(int, input().split())
ans = 0

for i in range(4, m + 1):
    for j in range(22, d + 1):
        d10 = j//10
        d1 = j%10
        if d10 >= 2 and d1 >= 2:
            if d10*d1 == i:
                ans += 1
print(ans)

Measured memory_bytes: 9120
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    string ans = "";
    if(s == "Sunny") ans = "Cloudy";
    else if(s == "Cloudy") ans = "Rainy";
    else ans = "Sunny";
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int n,p[50],i=0,j=0,tmp,k=0,l,m=0;
    scanf("%d",&n);
    for(l=0;l<n;l++)
        scanf("%d",&p[l]);
    while((i==0)&&(k<n)){
        if(k+1!=p[k])
            i=k;
        k++;
    }
    while((j==0)&&(k<n)){
        if(k+1!=p[k])
            j=k;
        k++;
    }
    if((i!=0)||(j!=0)){
    tmp=p[i];
    p[i]=p[j];
    p[j]=tmp;
    }
    for(l=0;l<n;l++)
        if(l+1==p[l])
            m++;
    if(m==n)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}

Measured memory_bytes: 128
//#include <bits/stdc++.h>
#include<iostream>
#include<numeric>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<ctype.h>
#include <fstream>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
//----------program from here----------

int ctoi(char c) {
  if('0'<=c && c <= '9') return c-'0';
  return 0;
}

int main(){
  int n=0,count=0;
  cin >> n;
  for(int i=1;i<=n;++i){
    if(i%2!=0){
      int x=0;
      for(int y=1;y<=i;++y){
        if(i%y==0){
          ++x;
        }
      }
      if(x==8){
        ++count;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void){
  int i,j,k,l;
  int tmp[10];
  int n;
  int top,bottom;
  int side[4];
  int sum;
  char data[100];

  while(1){

    scanf("%d",&n);
    if(n==0)break;

    top=1;
    bottom=6;
    side[0]=2;
    side[1]=3;
    side[2]=5;
    side[3]=4;

    sum=1;

    for(i=0;i<n;i++){
      scanf("%s",data);
      if(strcmp(data,"North")==0){
	tmp[0]=top;
	tmp[1]=side[0];
	tmp[2]=bottom;
	tmp[3]=side[2];
	
	top=tmp[1];
	side[0]=tmp[2];
	bottom=tmp[3];
	side[2]=tmp[0];
      }
      else if(strcmp(data,"East")==0){
	tmp[0]=top;
	tmp[1]=side[3];
	tmp[2]=bottom;
	tmp[3]=side[1];

	top=tmp[1];
	side[3]=tmp[2];
	bottom=tmp[3];
	side[1]=tmp[0];
      }
      else if(strcmp(data,"West")==0){
	tmp[0]=top;
	tmp[1]=side[1];
	tmp[2]=bottom;
	tmp[3]=side[3];

	top=tmp[1];
	side[1]=tmp[2];
	bottom=tmp[3];
	side[3]=tmp[0];
      }
      else if(strcmp(data,"South")==0){
	tmp[0]=top;
	tmp[1]=side[2];
	tmp[2]=bottom;
	tmp[3]=side[0];

	top=tmp[1];
	side[2]=tmp[2];
	bottom=tmp[3];
	side[0]=tmp[0];
      }
      else if(strcmp(data,"Right")==0){
	tmp[0]=side[0];
	tmp[1]=side[1];
	tmp[2]=side[2];
	tmp[3]=side[3];

	side[0]=tmp[1];
	side[1]=tmp[2];
	side[2]=tmp[3];
	side[3]=tmp[0];
      }
      else if(strcmp(data,"Left")==0){
	tmp[0]=side[0];
	tmp[1]=side[1];
	tmp[2]=side[2];
	tmp[3]=side[3];

	side[0]=tmp[3];
	side[1]=tmp[0];
	side[2]=tmp[1];
	side[3]=tmp[2];
      }
      sum+=top;
    }
    printf("%d\n",sum);
  }
  return(0);
}

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

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

Measured memory_bytes: 3624
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
#define pb push_back
#define fi first
#define se second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int mod = 1e9 + 7;
void solve(){
    int a, b, c;
    cin >> a >> b >> c;
    for (int i = 1; i <= 1000; ++i) {
        if ((a * i) % b == c) {
            cout << "YES";
            return;
        }
    }
    cout << "NO";
}
int main(){
    speed;
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; ++i) {
        solve();
    }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
x, k, d = map(int, input().split())
x = abs(x)
a = x // d
b = x % d
ans = 0
# 0を超えない
if k - a < 0:
  ans = x - k * d
else:
  if (k - a) % 2 == 0:
    ans = b
  else:
    ans = abs(b - d)

print(ans)

Measured memory_bytes: 9144
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
		
		StringTokenizer st = new StringTokenizer(br.readLine());
		
		int N = Integer.parseInt(st.nextToken());
		int M = Integer.parseInt(st.nextToken());
		
		int[] assign = new int[M];
		int vacation = 0, sum = 0;
		st = new StringTokenizer(br.readLine());
		for(int i=0; i<M; i++) {
			assign[i] = Integer.parseInt(st.nextToken());
			sum += assign[i];
		}
		
		vacation = N - sum;
		if(vacation < 0)
			bw.write(-1 + "\n");
		else
			bw.write(vacation + "\n");
		bw.flush();
	}

}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection) (collection).begin(), (collection).end()  // begin to end
#define each(e, collection) for(auto& e: collection)              // for each
#define rep(i, begin, end) for (ll i = begin; i < end; i++)       // repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)      // repeat reverse
#define size(collection) ((ll) (collection).size())               // collection size

#endif

int main(void)
{
	string s; cin >> s;
	ll k; cin >> k;

	ll same = 0;
	rep(i, 1, size(s))
	{
		if (s[i - 1] == s[i])
			same++;
	}
	if (same == size(s) - 1)
	{
		cout << size(s)* k / 2;
		return 0;
	}

	ll sindex = 0;
	while (s[sindex] == s[sindex + 1])
		sindex++;
	ll eindex = size(s)-1;
	while (s[eindex] == s[eindex - 1])
		eindex--;

	ll ans = (sindex + 1) / 2;

	ll mcount = 0;
	rep(i, sindex+2, eindex)
	{
		if (s[i - 1] == s[i])
		{
			mcount++;
			i++;
		}
	}
	ans += (mcount * k);

	if (k >= 2)
	{
		if (s[0] == s.back())
			ans += (sindex + 1 + size(s) - eindex) / 2 * (k - 1);
		else
		{
			ans += (sindex + 1) / 2 * (k - 1);
			ans += (size(s) - eindex) / 2 * (k - 1);
		}
	}

	rep(i, eindex + 1, size(s))
	{
		if (s[i - 1] == s[i])
		{
			ans++;
			i++;
		}
	}

	cout << ans;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
using namespace std;

vector<ll> A;
vector<ll> B;

int main(){
    int N;
    ll tmp;
    ll sum;
    cin >> N;
    A.resize(N);
    B.resize(N);
    rep(i,N){
        cin >> tmp;
        A[i] = tmp;
        B[i] = A[i]-i-1;
        //cout << B[i] << endl;
    }
    sort(B.begin(), B.end());
    if(N%2==1){
        tmp = B[(N-1)/2];
    }else{
        tmp = (B[N/2]+B[N/2-1])/2;
    }
    //cout << tmp << endl;
    sum=0;
    rep(i,N){
        sum+= abs(B[i]-tmp);
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include<queue>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdouble;


int main(int argc, char *argv[]) {

  int n;
  cin >> n;
  vector<int> L(n);
  for(int i=0; i<n; i++){
    cin >> L.at(i);
  }

  sort(L.begin(), L.end());
  ll answer = 0;
  for(int i=0; i<n; i++){
    for(int j=i+1; j<n; j++){
      ll Border = L.at(i) + L.at(j);
      for(int k=j+1; k<n; k++){
        if(Border > L.at(k)){
          answer++;
        }else{
          break;
        }
      }
    }
  }

  cout << answer << endl;
}

Measured memory_bytes: 256