akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    char X, Y;
    cin >> X >> Y;
    if (X < Y) {
        cout << '<' << endl;
    } else if (X > Y) {
        cout << '>' << endl;
    } else {
        cout << '=' << endl;
    }
    return 0;
}


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

int main()
{
  int A, B;
  std::cin >> A >> B;
  
  int ans = -1;
  if((A < 10) && (B < 10))
    ans = A * B;
  
  std::cout << ans << std::endl;
  
  return 0;
}

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

int main() {
  int n;
  cin>>n;
  vector<int> s(n);
  for (int i=0;i<n;i++) {
    cin>>s[i];
  }
  int count=0;
  for (int i=1;i<n-1;i++) {
    if (s[i] > s[i-1] && s[i] < s[i+1]) count++;
    else if (s[i] < s[i-1] && s[i] > s[i+1]) count++;
  }
  cout<<count<<endl;
}


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

int main() {
	char b;
	cin >> b;
	if (b == 'A') cout << 'T';
	if (b == 'C') cout << 'G';
	if (b == 'G') cout << 'C';
	if (b == 'T') cout << 'A';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    int a[n];
    rep(i, n)
    {
        cin >> a[i];
    }
    int f = 0;
    rep(i, n)
    {
        if (a[i] != i + 1)
            f++;
    }
    if (f <= 2)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ll long long
#define all(a) a.begin(),a.end()
#define endl '\n'
#define y1 y123123
#define int ll

using namespace std;

const int N = 3e3 + 3;
const int inf = 1e9 + 3;
const int md = 1e9 + 7;


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

    int a;
    string s;
    cin >> a >> s;
    if(a >= 3200)cout << s;
    else cout << "red";

}


Measured memory_bytes: 384
n = int(input())
ans = 0
ten = 10**(len(str(n))-1)
if len(str(n)) % 2:
    ans += n-ten+1
n = ten
while n > 10:
    ten = 10**(len(str(n))-2)
    if len(str(n)) % 2 == 0:
        ans += n-ten
    n = ten 
 
if n >= 10:
    ans += 9
print(ans)

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

using namespace std;

int main(){
    int N;
    long long int ans=0,now=1,x=0,n,add;
    cin >> N;
    n = N;
    vector<long long int> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
        A[i] <<= 1;
    }

    for(int i=0;i<61;i++){
        x=0;
        for(int j=0;j<N;j++){
            A[j] >>= 1;
            if((A[j]&1) == 1){
                x++;
            }
        }
        add = x*(n-x);
        ans %= 1000000007;
        for(int j=0;j<i;j++){
            add *= 2;
            add %= 1000000007;
        }

        ans += add;
    }

    ans %= 1000000007;

    cout << ans << endl;
}

Measured memory_bytes: 2560
use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    };

    let a_e = {
        let mut res = 0_i64;
        let mut sum = 0_i64;
        for (i, &a_i) in a.iter().enumerate() {
            sum += a_i;
            if i % 2 == 0 {
                if sum <= 0 {
                    res += 1 - sum;
                    sum = 1;
                }
            } else {
                if sum >= 0 {
                    res += 1 + sum;
                    sum = -1;
                }
            }
        }
        res
    };

    let a_o = {
        let mut res = 0_i64;
        let mut sum = 0_i64;
        for (i, &a_i) in a.iter().enumerate() {
            sum += a_i;
            if i % 2 == 0 {
                if sum >= 0 {
                    res += 1 + sum;
                    sum = -1;
                }
            } else {
                if sum <= 0 {
                    res += 1 - sum;
                    sum = 1;
                }
            }
        }
        res
    };

    let ans = std::cmp::min(a_e, a_o);
    println!("{}", ans);
}


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  VLL a(n+1),b(n);
  rep(i,n+1) cin >> a[i];
  rep(i,n) cin >> b[i];
  ll ans = 0;
  rep(i,n){
    if(a[i] > 0) ans+=min(a[i],b[i]),b[i] -= min(a[i],b[i]);

    if(b[i] > 0) ans += min(a[i+1],b[i]),a[i+1] -= min(a[i+1],b[i]);

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


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define endl "\n";
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=5e5+10;
int32_t main()
{
    IOS;
    int n;
    map<int,int>mp;
    int ans=0;
    cin>>n;
    int a[n+5];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        mp[i-a[i]]++;
    }
    for(int i=1;i<=n;i++)
    {
        ans+=mp[a[i]+i];
    }
    cout<<ans<<endl;
    
    
}

Measured memory_bytes: 27772
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long K;
    cin >> K;
    vector<long long> A(K);
    for(int i=0; i<K; i++) cin >> A[i];
    long long l = 2, r = 2;
    for(int i=K-1; i>=0; i--){
        long long tmp1 = l / A[i];
        long long tmp2 = r / A[i];
        if(l % A[i] != 0) tmp1++;
        if(tmp1 > tmp2){
            cout << -1 << endl;
            return 0;
        }
        l = tmp1 * A[i];
        r = tmp2 * A[i] + A[i] - 1;
    }
    cout << l << " " << r << endl;
    return 0;
}

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


using namespace std;


using ll = long long;


mt19937 mt(736);


int foo(const string &s, const string &last = "", int p = 0)
{
	static map<pair<int, string>, int> dp;

	if (p == s.size())
		return 0;

	if (!dp.count({p, last}))
		for (int i = p + 1; i <= s.size() && i < p + 4; i++)
			if (s.substr(p, i - p) != last)
				dp[{p, last}] = max(dp[{p, last}], 1 + foo(s, s.substr(p, i - p), i));

	return dp[{p, last}];
}


void solve(istream &cin = std::cin, ostream &cout = std::cout)
{
	string s;

	cin >> s;

	cout << foo(s) << endl;
}


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

	cout << fixed;

#ifdef LOCAL
	auto st = clock();

	ifstream fin("../input.txt");

	solve(fin);

	cout << "clock: " << setprecision(4) << (clock() - st) / (double) CLOCKS_PER_SEC << endl;
#else
	solve();
#endif

	return 0;
}


Measured memory_bytes: 111252
#
# abc060 a
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """rng gorilla apple"""
        output = """YES"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """yakiniku unagi sushi"""
        output = """NO"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """a a a"""
        output = """YES"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """aaaaaaaaab aaaaaaaaaa aaaaaaaaab"""
        output = """NO"""
        self.assertIO(input, output)


def resolve():
    A, B, C = input().split()

    if A[-1] == B[0] and B[-1] == C[0]:
        print("YES")
    else:
        print("NO")


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16332
inf=10**10
n,ma,mb=map(int,input().split())
abc=[list(map(int,input().split())) for _ in range(n)]
memo=[[inf]*401 for _ in range(401)]
memo[0][0]=0
for a,b,c in abc:
  for i in range(400,-1,-1):
    for j in range(400,-1,-1):
      if memo[i][j]!= inf :
        memo[i+a][j+b]= min(memo[i+a][j+b], memo[i][j] + c)


ans=inf
for i in range(1,min(400//ma,400//mb)):
  ans=min(ans, memo[ma*i][mb*i])

if ans==inf:
  print(-1)
else:
  print(ans)


Measured memory_bytes: 42972
N, A = [int(i) for i in input().split()]
X = [int(i) - A for i in input().split()]

memo = {0:1}
for x in X:
    for k, v in list(memo.items()):
        memo[x + k] = memo.get(x + k, 0) + v

print(memo[0] - 1)


Measured memory_bytes: 3188
///*
#include<iostream>
using namespace std;

int main() {

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

	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 3; j++) {
			if (x[j] > x[j + 1]) {
				int tmp = x[j];
				x[j] = x[j + 1];
				x[j + 1] = tmp;
			}
		}
	}
	if (x[0] == 1 && x[1] == 4 && x[2] == 7 && x[3] == 9) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}

	return 0;

}
//*/

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using uInt = long long unsigned int;
using Double = long double;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    Int N;

    bool check(Int v) {
        Int x = N;
        while (x % v == 0) {
            x /= v;
        }
        x %= v;

        if (x == 1) return true;
//        x = abs(x - v);
//        return x == 1;


        return false;
    }


    void solve() {
        cin >> N;

        Int ans = 0;
        if (N <= 100000) {
            rep(i, 2, N + 1) {
                if (check(i)) {
                    ans++;
//                    cerr << i << endl;
                }
            }
        } else {
            ans += 2;
            for (Int i = 2; i * i <= N; ++i) {
                if (check(i)) ans++;
//                if (check(N / i)) ans++;
                if ((N - 1) % i == 0) {
                    Int tmp = (N - 1) / i;
                    if (1. * tmp * tmp > N || tmp * tmp > N) {
                        ans++;
                    }
                }
            }
        }
        cout << ans << endl;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    Solve().solve();


    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int n,i;
  scanf("%d",&n);
  int res=n;
  for(i=0;i<=n;i++)
    {
      int cc=0,t=i;
      while(t>0)
	{
	  cc += t%6;
	  t /= 6;
	}
      t = n-i;
      while(t>0)
	{
	  cc += t%9;
	  t /= 9;
	}
      if(res > cc)
	{
	  res = cc;
	}
    }
  printf("%d\n",res);
  return 0;
}
      


Measured memory_bytes: 128
n,*a=$<.read.split.map &:to_i
a.sort!
b=[0]
n.times do |i|
  b<< b[-1]+a[i]
end
b.shift
c=1
(n-2).downto(0) do |i|
  if b[i]*2>=a[i+1]
    c+=1
  else
    break
  end
end
p c

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

int main()
{
    int n,m;
    cin >> n >> m;
    vector<int> a;
    double sum = 0;
    for (int i=0; i<n; ++i) {
        int ai;
        cin >> ai;
        sum += ai;
        a.push_back(ai);
    }
    sort(a.begin(),a.end(),greater<int>());
    if (a.at(m-1) < (double)sum/(4*m)) {
        cout << "No" << endl;
        return 0;
    }else {
        cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int h,m,s,ss;
    scanf("%d",&ss);
    h = ss / 3600;
    ss = ss - 3600 * h;
    m = ss / 60;
    ss = ss - 60 * m;
    s = ss;
    printf("%d:%d:%d\n", h, m, s);
    return 0;
}

Measured memory_bytes: 592
n=int(input())
arr=list(map(int,input().split()))
dic,cnt={},0
for i in arr:
    dic[i]=dic.get(i,0)+1
for i in dic:
    if dic[i]>i:
        cnt+=dic[i]-i
    elif dic[i]<i:
        cnt+=dic[i]
print(cnt)
    

Measured memory_bytes: 21644
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")

#include <iostream>
#include <string>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <tuple>
#include <queue>
#define PII pair<int, int>
#define T3I tuple<int, int, int>
using namespace std;

typedef long long ll;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;

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

    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }
}


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

int main(void){
  int N,K,i;
  char str[100],*p,s[100];
  
  fgets(str,sizeof(str),stdin);
  p=strtok(str," \n");
  N=atoi(p);
  p=strtok(NULL," \n");
  K=atoi(p);
  
  fgets(str,sizeof(str),stdin);
  p=strtok(str," \n");
  strcpy(s,p);
  
  if(s[K-1]=='A'){
    s[K-1]='a';
  }
  if(s[K-1]=='B'){
    s[K-1]='b';
  }
  if(s[K-1]=='C'){
    s[K-1]='c';
  }
  
  printf("%s\n",s);
  
  
  return 0;
}

Measured memory_bytes: 128
A, B, C = map(int, input().split())

ans = 0
while max(A, B, C) > min(A, B, C):
    A, B, C = sorted([A, B, C])
    if B == C:
        A += 2
    else:
        A += 1
        B += 1
    ans += 1
print(ans)

Measured memory_bytes: 38384
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMax = 1e12 + 1;
constexpr ll kMod = 1e9 + 7;
constexpr long double kPI = 3.14159265358979323846;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  double V, H, X, Y;
  cin >> V >> H >> X >> Y;

  cout << V * H / 2 << " " << ((X * 2 == V && Y * 2 == H) ? 1 : 0) << endl;

  return 0;
}


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

using namespace std;
using ll = long long;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount


int main() {
    int N; cin>>N;
    vector<ll>a(3*N);
    for (int i = 0; i < 3*N; i++) cin>>a[i];
    ll res=0;
    sort(all(a));
    reverse(all(a));

    for(int i = 1; i < 2*N; i+=2)
    {
        res+=a[i];
    }
    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 2560
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool in_range(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool in_range(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double EPS = 1e-9;
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//

int main() {
	lint N;
	cin >> N;
	
	lint x = N;
	int dig = 0;
	while (x) {
		x /= 10;
		++dig;
	}
	
	lint ini = 0, mul[20];
	mul[0] = 1;
	for_(i,0,dig) {
		ini = ini * 10 + 9;
		mul[i+1] = mul[i] * 10;
	}
	
	int max_d = 0;
	for_(i,0,dig) for_(d,0,10) {
		lint cur = ini - 9 * mul[i] + d * mul[i];
		if (cur <= N) maxUpdate(max_d, d);
	}
	cout << 9 * dig - 9 + max_d << endl;
}
//--------------8---------------->> coding space <<-----------------8-------------//

Measured memory_bytes: 256
N, y = gets.split.map(&:to_i)
Y = y / 1000
x, y, z = -1, -1, -1


(0..N).each do |i|
  (0..(N-i)).each do |j|
    if (10 * (N - i - j)) + 5 * j + 1 * i == Y
      x, y, z = N - i - j, j, i
    end
  end
end
printf("%s %s %s\n", x, y, z)

Measured memory_bytes: 1916
#include<iostream>

int main(){
  int a, b, d, r;
  double f ;

  std::cin >> a >> b;

  if(!(1 <= a && a <= 1000000000)) return 0;
  if(!(1 <= b && b <= 1000000000)) return 0;

   d = a / b;
   r = a % b;
   f = 1.00000 * a / b;

   std::cout << std::fixed;

   std::cout << d << " " << r << " " << f << std::endl;
   
   return 0;
   
}


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

#define ll          long long
#define ld          long double
#define pb          push_back
#define pf          push_front
#define mp          make_pair
#define pll         pair<ll,ll>
#define vl          vector<ll>
#define sl          set<ll> 
#define vll         vector<pll>
#define ml          map<ll,ll>
#define mll         map<pll,ll>
#define all(a)      a.begin(),a.end()
#define x           first
#define y           second
#define sz(x)       (ll)x.size()
#define dl          '\n'
#define mod         (ll)1000000007
//#define mod         (ll)998244353
#define lp(i,a,b)   for(ll i=a;i<b;++i)
#define lpr(i,a,b)  for(ll i=a;i>=b;i--)
#define lpd(i,x)    for(auto i:x)
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll inf = 1e18;
ld pi = 3.141592653589;
ll hell;
// ll expo(ll base, ll exponent, ll mod) {                                //return base^exponent modulo modulus
//     ll ans = 1;
//     while(exponent !=0 ) {
//         if((exponent&1) == 1) {
//             ans = ans*base ;
//             ans = ans%mod;
//         }
//         base = base*base;
//         base %= mod;
//         exponent>>= 1;
//     }
//     return ans%mod;
// }

ll solve(){ 
    ll n,k; cin>>n>>k;
    if(n<=k){
        cout<<min(n,abs(n-k));
        return 0;
    }
    cout<<min(k-n%k,(n%k));
}   

int main(){
    ios
    ll t=1; 
    //cin>>t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 256
N,K = map(int,input().split())

A = list(map(int,input().split()))

X = A.index(1) #Xは1のindex

if X<K or N-K<=X:
    ans = 1+((N-K)//(K-1))
    if (N-K)%(K-1)>0: ans += 1
    print(ans)
else:
    min_ans = N
    for i in range(K):
        LR = [X-K+i+1,N-X-1-i]
        #print(LR)
        ans = 1
        for a in LR:
            ans += a//(K-1)
            if a%(K-1)>0: ans += 1
        if ans < min_ans: min_ans = ans
    print(min_ans)

Measured memory_bytes: 14008
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto D = RD;
	auto X = new long[][](N);
	foreach (i; 0..N)
	{
		X[i] = RDR.ARR;
	}

	long ans;
	foreach (i; 0..N)
	{
		foreach (j; i+1..N)
		{
			double d = 0.0;
			foreach (k; 0..D)
			{
				d += (X[i][k] - X[j][k])^^2;
			}
			d = sqrt(d);
			if (d == cast(long)d)
				++ans;
		}
	}

	writeln(ans);
	stdout.flush();
	debug readln();
}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int N;
    Scd(N);
    char s[123];
    Scs(s);
    bool ans = true;

    if( N%2 ) ans = false;
    Rep(i,N/2) if( s[i] != s[i+N/2] ) ans = false;
    YesNo(ans);

    return 0;
}





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

int dt[100001][3], n;
int main(){
    scanf("%d", &n);
    scanf("%d %d %d", &dt[1][0], &dt[1][1], &dt[1][2]);

    for(int i=2; i<=n; i++){
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        dt[i][0] = max(dt[i-1][1], dt[i-1][2]) + a;
        dt[i][1] = max(dt[i-1][0], dt[i-1][2]) + b;
        dt[i][2] = max(dt[i-1][0], dt[i-1][1]) + c;
    }
    printf("%d", max(max(dt[n][0], dt[n][1]),dt[n][2]));
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 1000010, LOG=20;

ll n, m, k, u, v, x, y, t, a, b, ans;
ll F[MAXN], I[MAXN];

ll powmod(ll a, ll b){
	if (!b) return 1;
	if (b&1) return a*powmod(a*a%mod, b>>1)%mod;
	return powmod(a*a%mod, b>>1);
}

ll C(ll n, ll r){
	if (r<0 || r>n) return 0;
	return (F[n]*I[r]%mod)*I[n-r]%mod;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	F[0]=1;
	for (int i=1; i<MAXN; i++) F[i]=F[i-1]*i%mod;
	I[MAXN-1]=powmod(F[MAXN-1], mod-2);
	for (int i=MAXN-1; i; i--) I[i-1]=I[i]*i%mod;
	
	cin>>n>>m;
	ll tmp=n+m;
	if (tmp%3) kill(0)
	tmp/=3;
	n-=tmp;
	m-=tmp;
	cout<<C(n+m, n)<<'\n';
	
	
	return 0;
}


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

int main(){
    ll N,ans;
    cin >> N;
    vector<tuple<ll, ll, ll>> a;
    for (int i = 1; i <= N; i++){
        ll X;
        ll L;
        cin >> X >> L;
        a.emplace_back(X+L,X,L);
    }
    sort(a.begin(),a.end());
    int b = -1e10;
    rep(i,N){
        if(b <= get<1>(a[i]) - get<2>(a[i])){
            ans++;
            b = get<0>(a[i]);
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

struct UnionFind {
    UnionFind(int n) {
        rank.assign(n, 0);
        parent.resize(n);
        for (int i = 0; i < n; ++i) {
            parent[i] = i;
        }
    }

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

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

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

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

    vector<int> rank;
    vector<int> parent;
};

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

    ll N, Q;
    cin >> N >> Q;
    UnionFind uf(N + 5);
    REP(_, Q) {
        ll a, b, c;
        cin >> a >> b >> c;
        if (a == 0) {
            uf.unit(c, b);
        }
        else {
            cout << (ll) uf.same(b, c) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4724
s = int(input())

a = s

a_list = [a]

while True:
    if a %2 == 0:
        a = a/2
    else:
        a = 3*a + 1
        
    if a in a_list:
        break
    
    a_list += [a]

print(len(a_list) + 1)

Measured memory_bytes: 3060
//*in the name of GOD*\\

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef long double ld;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int main(){
  int n;
  string s;
  cin >> n >> s;
  if(n < 3200){
    cout << "red";
  }else{
    cout << s;
  }
}


Measured memory_bytes: 256
IDENTIFICATION                    DIVISION.
PROGRAM-ID.                       PROGRAM_ID.
DATA                              DIVISION.
WORKING-STORAGE                   SECTION.
01 LN           PIC X(8).
01 N            PIC 9(3).
01 R            PIC 9(4).
01 ans          PIC Z(3)9.

PROCEDURE                         DIVISION.
    ACCEPT LN.
    UNSTRING LN DELIMITED BY SPACE INTO N R.
    IF 10 <= N
        MOVE R TO ans
    ELSE
        COMPUTE ans = R + 100 * (10 - N)
    END-IF.
    DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans)).
    STOP RUN.


Measured memory_bytes: 892
import java.util.Scanner;

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

		for(int i = 1;i <= count;i++ ) {
			int num = 0;
			if(i % 3 == 0) {
				num = i;
			} else if(i % 10 == 3) {
				num = i;
			} else if((i / 10) %  10 == 3 || (i / 100) %  10 == 3 || (i / 1000) %  10 == 3) {
				num = i;
			}

			if(num != 0) {
				System.out.print(" " + num);
			}

		}
		System.out.println();
		sc.close();

	}
}

Measured memory_bytes: 28656
//私たちはN人で旅行しようとしており、その交通手段として電車とタクシーがあります。
//電車を使うと1人あたりA円かかります。
//タクシーを使うとN人でB円かかります。
//全員の交通費の合計は最小でいくらになるでしょうか。

import java.util.*;

  public class Main{
    public static void main(String[]args){
      Scanner sc=new Scanner(System.in);
      while(sc.hasNext()){
      int N=sc.nextInt(); //人数
      int A=sc.nextInt(); //電車を使った時の値段
      int B=sc.nextInt(); //タクシーを使った時の値段
      if(N*A>B){
        System.out.println(B);
      }else{
        System.out.println(N*A);
      }
    }
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=INT_MAX,MOD=1e9+7;

int n,m;
bool edge[55][55];
bool used[55];

void search(int from){
    used[from]=1;
    for(int to=1;to<=n;to++){
        if(!used[to]&&edge[from][to]){
            search(to);
        }
    }
}

int main(){
    cin>>n>>m;
    vector<pair<int,int>> p;
    rep(i,m){
        int a,b; cin>>a>>b;
        edge[a][b]=edge[b][a]=1;
        p.push_back(make_pair(a,b));
    }
    int cnt=0;
    for(auto i:p){
        int a=i.first,b=i.second;
        edge[a][b]=edge[b][a]=0;
        rep(i,55) used[i]=0;
        search(1);
        bool all=0;
        for(int i=1;i<=n;i++){
            if(!used[i]) all=1;
        }
        if(all) cnt++;
        edge[a][b]=edge[b][a]=1;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
//============================================================================
//Everyone has a different way of thinking, so God Created us
//   Hope You Respect My Way..,Thank You ):
// Author      : Murad
// Name        : Codeforces.cpp & Atcoder.cpp
// Description : Problem name
//============================================================================
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define ULL unsigned long long
#define MP make_pair
#define ff first
#define ss second
#define endl '\n'
#define INF 1e9 + 1
#define _INF INT32_MIN
#define PQ priority_queue
#define MM multimap
#define PB push_back
#define vii vector<int>
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define MAXN 100004
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
char alphz[27] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
float Euclidean(LL x1, LL x2, LL y1, LL y2) {
	return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}
LL gcd(LL a,LL b) {
	LL c;
	while (a != 0) {
		c = a;
		a = b % a;
		b = c;
	}
	return b;
}
LL LCM(LL a, LL b) {
	return (a*b) / gcd(a, b);
}
void PrimeFactor(LL n)
{
	while (n % 2 == 0) {
		printf("%d ", 2);
		n /= 2;
	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		if (n%i == 0) {
			printf("%d ", i);
			n /= i;
		}
	}
	if (n > 2)printf("%d ", n);
}
bool is_square(LL x) {
	LL l = 0, r = x;
	while (l <= r) {
		LL mid = l + (r - l) / 2;
		if (mid*mid == x)return true;
		if (mid*mid > x)r = mid - 1;
		else l = mid + 1;
	}
	return false;
}
LL power(LL x, LL y)
{
	LL temp;
	if (y == 0)return 1;
	temp = power(x, y / 2);
	if (y % 2 == 0)
		return temp*temp;
	else return x*temp*temp;
}
bool is_Prime(int x) {
	if (x == 2)return 1;
	else if (x % 2 == 0 || x < 2)return 0;
	for (int i = 3; i*i <= x; i += 2)
		if (x%i == 0)return 0;
	return 1;
}
map<ipair, int>mpp;
map<int, int>last;
int main()
{
	El3zba;
	/***  بسم الله الرحمن الرحيم   ***/
	int n, m;
	cin >> n >> m;
	vector<ipair>a;
	for (int i = 0; i < m; i++)
	{
		int x, y;
		cin >> x >> y;
		a.PB({ x,y });
		mpp[{y, x}]=0;
	}
	int idx = 1;
	auto &v = *mpp.begin();
	int prev = v.ff.ss;
	for (auto&x : mpp)
	{
		if (x.ff.ss == prev)
		{
			mpp[{x.ff.ff,x.ff.ss}] = idx;
			last[x.ff.ss] = idx;
			idx++;
		}
		else
		{
			prev = x.ff.ss;
			idx = last[x.ff.ss];
			mpp[{x.ff.ff, x.ff.ss}] = idx+1;
			last[prev] = idx + 1;
			idx+=2;
		}
	}
	for (auto&x : a)
	{
		string ans = "";
		int v = mpp[{x.ss, x.ff}];
		string wal = to_string(x.ff);
		ans += wal;
		wal = to_string(v);
		while ((int)ans.size() < 6)
		{
			ans.insert(0, "0");
		}
		for (int i = (int)ans.size(); i <= 11 - (int)wal.size(); i++)
			ans.insert(i, "0");
		ans += wal;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 13172
#include<bits/stdc++.h>
#define pb push_back
#define ld long double
#define vl vector<ll> 
#define ll long long int 
using namespace std;
void solve()
{
    string str1, str2;
    cin>>str1>>str2;
    if(str1.length()>=1&&str1.length()<=10)
    if(str2.length()==str1.length()+1)
    {
        if(std::string(str1)==std::string(str2.substr(0, str1.length())))
        {
            cout<<"Yes\n";
            return;
        }
    }
    cout<<"No\n";
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
        solve();
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
ll P = 1000000007;
ll dp[101010] = {0};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<ll> a(m);
  set<ll> s;
  for (int i = 0; i < m; i++) {
    cin >> a[i];
    s.insert(a[i]);
  }
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    if (s.find(i) != s.end()) continue;
    dp[i + 1] += dp[i];
    dp[i + 1] %= P;
    dp[i + 2] += dp[i];
    dp[i + 2] %= P;
  }
  cout << dp[n] << endl;
  return 0;
}


Measured memory_bytes: 5760
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**7)
inf = float('inf')
mod = 10**9+7
ans = inf ;count = 0 ;pro = 1
a,b,c=map(int,input().split())
if a+b>=c:
    print("Yes")
else:
    print("No")

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

int main() {
  int N;
  cin >> N;
  int sum = 0, M = 0;
  
  for (int i = 0; i < N; i++) {
    int L;
    cin >> L;
    
    sum += L;
    if (L > M) {
      M = L;
    }
  }
  if (sum > M * 2) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
	cin>>s;
	int n=s.size();
	for(int i=n-2;i>=0;i--)
	{
		if((i+1)&1)continue;
		int x=(i+1)/2;
		if(s.substr(0,x)==s.substr(x,x))
		{
			printf("%d\n",x*2);
			return 0;
		}
	}
	printf("0\n");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

signed main() {
	int l;
	string s;
	cin >> l >> s;

	int ans = 0;
	range(i, 0,s.size()) {
		if (s[i] == '.') {
			
			bool f = false;
			for(int j = i - 1; j >= 0; j--){
				if(s[j] == 'B'){
					f = true;
					break;
				}else if(s[j] == 'W');
				else{
					break;
				}
			}
			if(f) continue;

			range(j, i + 1, s.size()) {
				if (s[j] == 'W') {
					ans = max(ans, j - i - 1);
					break;
				} else if (s[j] == '.') {
					break;
				}
			}
		}
	}
	for (int i = l - 1; i >= 0; i--) {
		if (s[i] == '.') {

			bool f = false;
			range(j,i + 1, l){
				if(s[j] == 'B'){
					f = true;
					break;
				}else if(s[j] == 'W');
				else{
					break;
				}
			}
			if(f) continue;

			if(i + 1 < l and s[i + 1] == 'B') continue;
			for (int j = i - 1; j >= 0; j--) {
				if (s[j] == 'W') {
					ans = max(ans, i - j - 1);
					break;
				} else if (s[j] == '.') {
					break;
				}
			}
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 3212
import bisect


n = int(input())
a = list(map(int, input().split()))
a.sort()
b = list(map(int, input().split()))
b.sort()
c = list(map(int, input().split()))
c.sort()

b_list = []
c_list = []

for i in b:
    b_list.append(bisect.bisect_left(a, i))

for i in c:
    c_list.append(bisect.bisect_left(b, i))

b_sum = []
bbb = 0
for i in b_list:
    bbb += i
    b_sum.append(bbb)
sum = 0
for i in c_list:
    if i == 0:
        sum += 0
    else:
        sum += b_sum[i-1]

print(sum)


Measured memory_bytes: 28532
//https://onlinejudge.u-aizu.ac.jp/challenges/sources/JOI/Prelim/0610?year=2015

#include <bits/stdc++.h>

using namespace std;

const auto INF = (int) 1e9;

int main() {
    int h, w;
    cin >> h >> w;

    int dp[110][110];
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            char c;
            cin >> c;
            if (c == 'c') {
                dp[i][j] = 0;
            } else {
                dp[i][j] = INF;
            }
        }
    }

    for (int i = 0; i < h; ++i) {
        for (int j = 1; j < w; ++j) {
            dp[i][j] = min(dp[i][j - 1] + 1, dp[i][j]);
        }
    }

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (dp[i][j] >= INF) dp[i][j] = -1;
            cout << dp[i][j];
            if (j != w - 1) cout << " ";
        }
        cout << endl;
    }
    return 0;
}

/*
 * 行ごとに左から決めていく。
 * dp[i][j] = min(dp[i][j - 1] + 1, dp[i][j])
 *
 */


Measured memory_bytes: 3148
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <tuple>
#include <list>
#include <deque>
#include <stack>
#include <complex>
#include <functional>
#include <regex>
#include <map>
#include <numeric>

using namespace std;

#define REP(i,a,b) for(int i=(a); i<(b); ++(i))
#define rep(i,n) REP(i,0,n)

const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

using ll = long long;
using ld = long double;
using ull = unsigned long long;

int N;

inline int nd(int val) {
  return int(log10(val));
}

inline int lsd(int val) {
  if (val < 10) return val;
  return val / int(pow(10, nd(val)));
}

inline int msd(int val) {
  return val % 10;
}

int C(int i, int j) {
  int cnt = 0;
  REP(n, 1, N + 1) {
    if (msd(n) == i && lsd(n) == j)
      cnt++;
  }
  return cnt;
}

int main(void) {
  cin >> N;
  int cnt = 0;
  rep(i, 10) rep(j, 10)
    cnt += C(i, j) * C(j, i);
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int x = 0;
		int i = 1;
		while (true) {

			x = sc.nextInt();

			if (x == 0) {
				break;
			}

			System.out.println("Case " + i + ": " + x);

			i++;

		}

		sc.close();

	}

}


Measured memory_bytes: 42696
#include <stdio.h>

int main(void){
  while(1){
    int n,math,eng,lan;
    scanf("%d",&n);
    if(n == 0)
      break;
    while(n){
      scanf("%d %d %d",&math,&eng,&lan);
      if((math+eng)/2 >= 90 || math == 100 || eng ==100 || lan==100 || (math+eng+lan)/3 >= 80)
	printf("A\n");
      else if( (math+eng+lan)/3 >= 70 || ((math+eng+lan)/3 >= 50 && (math >= 80 || eng >= 80)))
	printf("B\n");
      else
	printf("C\n");
      n--;
    }
  }
  return 0;
}

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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  int a;
  ll sum = 0;
  map<int, int> mp;
  for (int i = 0; i < N; i++) {
    cin >> a;
    sum = (sum + a) % M;
    mp[sum]++;
  }
  mp[0]++;

  ll ans = 0;
  for (auto m : mp) {
    if (m.second > 1)
      ans += 1LL * m.second * (m.second - 1) / 2;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3200
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
 int N, A[3][3], b[10];
 bool appear[3][3];
 int main() {
 for(int i = 0; i < 3; i++) {
 for(int j = 0; j < 3; j++) cin >> A[i][j];
 }
 cin >> N;
 for(int i = 0; i < N; i++) cin >> b[i];
 for(int i = 0; i < N; i++) {
 for(int j = 0; j < N; j++) {
 appear[i][j] = false;
 for(int k = 0; k < N; k++) {
 if(A[i][j] == b[k]) appear[i][j] = true;
 }
 }
 }
 string ANS = "No";
 for(int i = 0; i < 3; i++) {
 if(appear[i][0] and appear[i][1] and appear[i][2]) ANS = "Yes";
 }
 for(int i = 0; i < 3; i++) {
 if(appear[0][i] and appear[1][i] and appear[2][i]) ANS = "Yes";
 }
 if(appear[0][0] and appear[1][1] and appear[2][2]) ANS = "Yes";
 if(appear[0][2] and appear[1][1] and appear[2][0]) ANS = "Yes";
 cout << ANS << endl;
 return 0;
 }

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var dg = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToList();

            dg.Sort();
            dg.Reverse();

            var a = int.Parse("" + dg[0] + dg[1]);
            var c = dg[2];

            Console.WriteLine(a + c);
        }
    }
}


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

const long long K = 1e5 + 15;
long long n, m, x, y, dp[K][2];
vector<pair<long long, pair<long long, long long> > > v[K];

void dfs(long long dg, long long up) {
    dp[dg][0] = 1;
    for(long long i = 0; i < v[dg].size(); ++i) {
        if(v[dg][i].first != up) {
            dfs(v[dg][i].first, dg);
            (dp[dg][0] *= dp[v[dg][i].first][0] + 1) %= m;
        }
    }
    if(!v[dg].size()) return;
    for(long long i = 0; i < v[dg].size(); ++i) {
        if(v[dg][i].first != up) v[dg][i].second.first = dp[v[dg][i].first][0] + 1;
        else v[dg][i].second.first = 1;
        if(i) (v[dg][i].second.first *= v[dg][i - 1].second.first) %= m;
    }
    for(long long i = (int)v[dg].size() - 1; i > 0; --i) {
        v[dg][i].second.first = v[dg][i - 1].second.first;
    }
    v[dg][0].second.first = 1;
    for(long long i = (int)v[dg].size() - 1; i >= 0; --i) {
        if(v[dg][i].first != up) v[dg][i].second.second = dp[v[dg][i].first][0] + 1;
        else v[dg][i].second.second = 1;
        if(i + 1 < v[dg].size()) (v[dg][i].second.second *= v[dg][i + 1].second.second) %= m;
    }
    for(long long i = 0; i + 1 < v[dg].size(); ++i) {
        v[dg][i].second.second = v[dg][i + 1].second.second;
    }
    v[dg][v[dg].size() - 1].second.second = 1;
    for(long long i = 0; i < v[dg].size(); ++i) {
        (v[dg][i].second.first *= v[dg][i].second.second) %= m;
    }
}

void Dfs(long long dg, long long up, long long ri) {
    if(up) (dp[dg][1] = dp[up][1] * v[up][ri].second.first + 1) %= m;
    else dp[dg][1] = 1;
    for(long long i = 0; i < v[dg].size(); ++i) {
        if(v[dg][i].first != up) {
            Dfs(v[dg][i].first, dg, i);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for(long long i = 1; i < n; ++i) {
        cin >> x >> y;
        v[x].push_back({y, {0, 0}});
        v[y].push_back({x, {0, 0}});
    }
    dfs(1, 0);
    Dfs(1, 0, 0);
    for(int i = 1; i <= n; ++i) {
        cout << (dp[i][0] * dp[i][1]) % m << endl;
    }
    return 0;
}

Measured memory_bytes: 18560
#include <iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

int prim()  {
  int u, minv;
  int d[MAX], p[MAX], color[MAX];
  
  for(int i = 0; i < n; i++)  {
    d[i] = INFTY;
    p[i] = -1;
    color[i] = WHITE;
  }
  
  d[0] = 0;
  
  while (1)  {
    minv = INFTY;
    u = -1;
    for (int i = 0; i < n; i++)  {
      if (minv > d[i] && color[i] != BLACK )  {
        u = i;
        minv = d[i];
      }
    }
    if (u == -1)  break;
    color[u] = BLACK;
    for (int v = 0; v < n; v++)  {
      if (color[v] != BLACK && M[u][v] != INFTY )  {
        if (d[v] > M[u][v] ) {
          d[v] = M[u][v];
          p[v] = u;
          color[v] = GRAY;
        }
      }
    }
  }
  int sum = 0;
  for ( int i = 0; i < n; i++)  {
    if (p[i] != -1)  sum += M[i][p[i]];
  }
  return sum;
}

int main()  {
  cin >> n;

  for (int i = 0; i < n; i++)  {
    for (int j = 0; j < n; j++)  {
      int e; 
      cin >> e;
      M[i][j] = (e == -1) ? INFTY : e;
    }
  }
 
  cout << prim() << endl;

  return 0;
}

Measured memory_bytes: 3112
#include<iostream>
#include<string>
#include<algorithm>
typedef long long ll;
using namespace std;
int main(void){
   ll n;
   cin >> n;
   ll a[3*n];
   for(ll i=0;i<3*n;++i){
	  cin >> a[i];
   }
   std::sort(a,a+3*n,greater<ll>());
   ll sum1=0;
   for(ll i=0;i<2*n;++i){
	  if(i%2==1){
	  	sum1 += a[i];
	  }
	 }
   cout << sum1 <<endl;
return 0;
}


Measured memory_bytes: 2560