akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        int N=cin.nextInt();
        long[] A=new long[N];
        long[] B=new long[N];
        string ans="Yes";
        
        for(int i=0;i<N;i++)
        {
            long[]x=cin.ArrayLong(2,0);
            A[i]=x[0];
            B[i]=x[1];
        }
        Array.Sort(B,A);
        long sum=0;
        for(int i=0;i<N;i++)
        {
            sum+=A[i];
            if(sum>B[i]){ans="No";break;}
        }
      Console.WriteLine("{0}",ans);
        
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public static void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }//Answer.IntArrayAns(x);
    public static void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}

Measured memory_bytes: 20396
N =int(input())
A = list(map(int,input().rstrip().split(" ")))
Aq = []
DP = [0 for i in range(5 * 10 ** 5)]
DPP = []
ans = 0
for i in range(N):
    if i >= A[i]:
        ans += DP[i - A[i]]
    if A[i] <= N:
        DP[A[i] + i] += 1
    
print(ans)


Measured memory_bytes: 32384
#include<stdio.h>
int main()
{
	int a,b,c,x;
	scanf("%d%d%d",&a,&b,&c);
	if(a>b)
	{x=a;
	a=b;
	b=x;}
	if(a>c)
		{x=a;
		a=c;
		c=x;}
	 if(b>c)
		{
		x=b;
		b=c;
		c=x;
		}

	printf("%d %d %d\n",a,b,c);
	return 0;
}



Measured memory_bytes: 1972
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
using ll=long long;
using ld=long double; 
using namespace std;
//const int INF = 7+(1e+9);
ll GCD(ll x, ll y)
{
    if (y == 0)
    {
        return x;
    }
    else
    {
        return GCD(y, x % y);
    }
}
ll LCM(ll x, ll y)
{
    return x / GCD(x, y) * y;
}
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll MOD=1e9+7;

int main(){
    string s;cin>>s;
    ll k;cin>>k;
    if(s.size()==1){
        cout<<k/2<<endl;
        return 0;
    }
    vector<ll> vec(s.size());
    vector<ll> vec1(s.size());
    vec[0]=s[0]-'a';
    ll c=0;
    
    for(int i=1;i<s.size();i++){
        if(s[i]-'a'==vec[i-1]){
            c++;
            vec[i]=1e9+i*2;
        }else{
            vec[i]=s[i]-'a';
           
           // cout<<s[i]-'a'<<" "<<vec[i-1]<<endl;
        }
    }
  //  cout<<c<<endl;
  bool h=true;
    for(int i=0;i<s.size();i++){
        if(s[i]!=s[0]){
             h=false;
        }
    }
    ll x;
    if(h){
        cout<<s.size()*k/2<<endl;
        return 0;
    }
    if(vec[s.size()-1]==vec[0]){
        x=c*k+k-1;
    }else{
        x=c*k;
    }
    vec1[s.size()-1]=s[s.size()-1]-'a';
    ll c1=0;
    for(int i=s.size()-2;i>=0;i--){
        if(s[i]-'a'==vec1[i+1]){
            c1++;
            vec1[i]=1e9+i*2;
        }else{
            vec1[i]=s[i]-'a';
        }
    }
    ll y;
    if(vec1[s.size()-1]==vec1[0]){
        y=c1*k+k-1;
    }else{
        y=c1*k;
    }
    cout<<min(x,y)<<endl;
  //  cout<<x<<" "<<y<<endl;
}


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

namespace ABC134
{
    class C
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int[] A = new int[N];

            for (int i = 0; i < N; i++)
            {
                A[i] = int.Parse(Console.ReadLine());
            }

            int[] Atmp = new int[N];
            Atmp = A.OrderByDescending(x => x).ToArray();

            for (int i = 0; i < N; i++)
            {
                if (A[i] != Atmp[0])
                {
                    Console.WriteLine(Atmp[0]);
                }
                else if (A[i] == Atmp[0])
                {
                    Console.WriteLine(Atmp[1]);
                }
            }
        }
    }
}


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

int main() {
  int N;
  cin >> N;
  int count = 1;
  int max;
  cin >> max;
  for(int i = 1; i < N; i++) {
    int h;
    cin >> h;
    if(h >= max) {
      count++;
      max = h;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3580
from math import ceil, sqrt
from itertools import accumulate
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def eratosthenes(n):
    p = []         # n以下の素数リスト
    t = [-1] * n   # t_iの素因数の内最小のもの
    t[0] = 0
    t[1] = 0

    for i in range(2, ceil(sqrt(n))):
        if t[i] == -1:
            p.append(i)
            #t[i] = i
            for j in range(2*i, n, i):
                if t[j] == -1:
                    t[j] = i
 
    for j in range(i+1, n):
        if t[j] == -1:
            p.append(j)
            #t[j] = j
 
    return p, t
 

def main():
    Q,*lr = map(int, read().split())

    P, T = eratosthenes(10**5+5)
    table2017 = [0] * (10**5+5)
    for p in P:
        if T[(p+1)//2] == -1:
            table2017[p] = 1
    acc = list(accumulate(table2017))

    for l, r in zip(*[iter(lr)]*2):
        print(acc[r] - acc[l-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 25588
#include <iostream>
#define int long long
using namespace std;

int l, k;
int dp[101][2];

int f(int l, int cnt) {
	if (l < 0) return 0;
	if (dp[l][cnt] != -1) return dp[l][cnt];
	if (cnt == 0) {
		return dp[l][cnt] = f(l - k, 1) + f(l - 1, 1);
	}
	return dp[l][cnt] = 1 + f(l - 1, 0);
}

signed main() {
	cin >> l >> k;
	for (int i = 0; i <= l; i++) dp[i][0] = dp[i][1] = -1;
	cout << f(l, 0) << endl;
	return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int s, w;
    cin >> s >> w;
    if (w >= s)
        cout << "unsafe";
    else
        cout << "safe";
    cout << endl;
    return 0;
}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {
	public static void main(String[] arges) {

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] k = new String[Integer.parseInt(line)];

		for (int i = 0; i < k.length; i++) {
			k[i] = sc.nextLine();
		}
		int tarou = 0;
		int hanako = 0;
		for (String string : k) {
			String[] tehuda = string.split(" ");

			if (tehuda[0].compareToIgnoreCase(tehuda[1]) > 0) {
				tarou += 3;
			} else if (tehuda[0].compareToIgnoreCase(tehuda[1]) < 0) {
				hanako += 3;
			} else {
				tarou += 1;
				hanako += 1;
			}
		}System.out.println(tarou+" "+hanako);
	}
}

Measured memory_bytes: 31324
def ans():
    N = int(input())
    A = list(map(int, input().split()))
    result = []
    MAX = max(A)
    MAX_INDEX = A.index(MAX)
    MIN = min(A)
    MIN_INDEX = A.index(MIN)

    if abs(MAX) > abs(MIN):
        # B = [a + MAX for a in A]
        B = []
        for i, v in enumerate(A):
            b = v + MAX
            B.append(b)
            result.append((MAX_INDEX, i))

        for i in range(N):
            if i == 0: continue
            B[i] = B[i] + B[i - 1]
            result.append((i - 1, i))
    else:
        B = []
        for i, v in enumerate(A):
            b = v + MIN
            B.append(b)
            result.append((MIN_INDEX, i))

        for i in range(N - 1, -1, -1):
            if i == N-1: continue
            B[i] = B[i] + B[i + 1]
            result.append((i + 1, i))

    print(len(result))
    for r in result:
        print(r[0]+1, r[1]+1)


ans()


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

#define ll long long
#define ld long double
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define int long long

using namespace std;
const int INF = 2e15;
const int MB = 20;
const int MOD = 1e9 + 7;


void solve() {
	int x, k, d;
	cin >> x >> k >> d;
	if (x < 0) x = -x;
	int y = min(k, x / d);
	if ((k - y) % 2) cout << abs(x - (y + 1) * d);
	else cout << x - y * d;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	//srand(time(0));
	int t = 1;
	//int t;
	//cin >> t;
	while (t--) solve();
}

Measured memory_bytes: 3664
#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 4e18;

int main() {
    //dp[i][j]:=i文字目より左側にj以外のものがいくつあるか
    string s; cin >> s;
    vector<vector<int>> dp(s.size()+1, vector<int>(26,0));
    for(int i = 1; i < s.size()+1; i++) {
        REP(j, 26) {
            dp[i][j] = dp[i - 1][j];
            if ('a' + j != s[i-1]) {
                dp[i][j]++;
            }
        }
    }
    ll ans = 1;
    for (int i = 1; i < s.size() + 1; i++) {
        ans += dp[i][s[i - 1]-'a'];
    }
    cout << ans << endl;
    getchar(); getchar();
}

Measured memory_bytes: 27012
#include <iostream>
#include <vector>
#include <algorithm> 
#include <queue>
#include <functional>
#include <map>
#include <string>
using namespace std;
typedef long long ll;


int main(void){
    string s, t;
    cin >> s >> t;

    for (int i = s.size() - t.size(); i >= 0; i--){
        bool flag = true;
        for (int j = 0; j < t.size(); j++){
            if (s[i + j] != '?' && s[i + j] != t[j]){
                flag = false;
                break;
            }
        }
        if (flag){
            for (int j = 0; j < i; j++){
                if (s[j] == '?'){
                    cout << 'a';
                }
                else{
                    cout << s[j];
                }
            }
            for (int j = 0; j < t.size(); j++){
                cout << t[j];
            }
            for (int j = i + t.size(); j < s.size(); j++){
                if (s[j] == '?'){
                    cout << 'a';
                }
                else{
                    cout << s[j];
                }
            }
            return 0;
        }
    }

    cout << "UNRESTORABLE" << endl;

}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	string s;
	cin >> s;	
	int ans = 0;
	for(int i = 0; i < n-2; i++){
		if(s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C') ans++;
	}
	cout << ans << endl;
	return 0;
} 

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

typedef struct {
	int h;
	int w;
	int D;
} RECTANGLE;

RECTANGLE rectangle[30000];

bool cmp(const RECTANGLE& A, const RECTANGLE& B)
{
	if (A.D == B.D){
		return (A.h < B.h);
	}
	return (A.D < B.D);
}

int main()
{
	int i, n;
	
	for (int w = 2, i = 0; w <= 150; w++){
		for (int h = 1; h < w; h++){
			rectangle[i].h = h;
			rectangle[i].w = w;
			rectangle[i].D = h * h + w * w;
			i++;
			n = i;
		}
	}
	
	sort(rectangle, rectangle + n, cmp);
	
	int h, w;
	while (scanf("%d %d", &h, &w), h + w){
		for (int i = 0; i < n; i++){
			if (h == rectangle[i].h && w == rectangle[i].w){
				printf("%d %d\n", rectangle[i + 1].h, rectangle[i + 1].w);
				break;
			}
		}
	}
	
	return (0);
}

Measured memory_bytes: 1156
#if 1
  #include <bits/stdc++.h>
#else
  #include "../../../../bits/stdc++.h"
#endif

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

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define ft first
#define sd second

ll K;
ll N = 50;
ll a[52];

int main(){
  cin.tie(0);
  
  cin>>K;

  ll k = K/2 + 1;
  if(k<10000000000000000) {
    cout<<2<<endl;
    ll k = K/2 + 1;
    if(K%2==0) {
      cout<<k<<' '<<k<<endl;
    }else {
      cout<<k+1<<' '<<k-1<<endl;
    }
  }else {
    ll Q = K/N, R = K%N;

    FOR(i, 1, R+1)a[i] = Q+N-R+1+N-1;
    FOR(i, R+1, N+1)a[i] = Q-R+N-1;

    cout<<N<<endl;
    FOR(i, 1, N)cout<<a[i]<<' ';
    cout<<a[N]<<endl;
  }


  return 0;
}


Measured memory_bytes: 256
N = int(input())
F = [list(map(int, input().split())) for i in range(N)]
P = [list(map(int, input().split())) for i in range(N)]


ans = -1000000009
for i in range(1, 2 ** 10):
        tmp = 0
        check = [0] * N
        for j in range(10):
                if ((i >> j) & 1):
                        for k in range(N):
                                if F[k][j]:
                                        check[k] += 1
        for k in range(N):
                tmp += P[k][check[k]]
        ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 42224
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const int MOD = 1000000007;
/* テンプレートここまで */

int main() {
  ll X;
  cin >> X;

  ll ng = 0;
  ll ok = 1e9;

  while(ok - ng > 1){
    ll mid =(ok+ng)/2;

    if((ll)mid*(mid+1)/2 >= X){
      ok = mid;
    }else{
      ng = mid;
    }
  }

  cout << ok << endl;
}


Measured memory_bytes: 256
object Main{
  def main(args:Array[String]) = {
    val list = scala.io.StdIn.readLine.split(" ").map(_.toLong).toList;
    if(list(0) % 3 == 0)
      println("Possible")
    else if(list(1) % 3 == 0)
      println("Possible")
    else if((list(0) + list(1)) % 3 == 0)
      println("Possible")
    else
      println("Impossible")
  }
}

Measured memory_bytes: 27080
import java.util.*;
import java.io.PrintWriter;

public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long sum=0;
		int[] num=new int[100001];
		for(int i=0; i<n; i++){
			int a=sc.nextInt();
			num[a]++;
			sum+=a;
		}
		int q=sc.nextInt();
		for(int i=0; i<q; i++){
			int b=sc.nextInt();
			int c=sc.nextInt();
			if(b>c){
				sum-=(b-c)*num[b];
				num[c]+=num[b];
				num[b]=0;
			}else{
				sum+=(c-b)*num[b];
				num[c]+=num[b];
				num[b]=0;
			}
			System.out.println(sum);
		}
	}
}


Measured memory_bytes: 62744
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on
 
template<typename V>
constexpr string join(const V &v, const string &sep) {
  stringstream ss;
  if (v.size()) ss << v[0];
  loop(i, 1, v.size()) ss << sep << v[i];
  return ss.str();
}
 
void solve() {
  int n;
  cin >> n;
  vi a(n);
  deque<int> b;
  rep(i, n) cin >> a[i];
  rep(i, n) {
    if (even(i)) {
      b.push_back(a[i]);
    } else {
      b.push_front(a[i]);
    }
  }
  vi v;
  for (int &x : b) v.pb(x);
  if (odd(n)) reverse(all(v));
  cout << join(v, " ") << endl;
}


Measured memory_bytes: 9064
#if 0

#endif

#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void p(A a){cout << (a) << endl;}
template<class A,class B>void p(A a,B b){cout << a << " "  ;p(b);}
template<class A,class B,class C>void p(A a,B b,C c){cout << a << " " ;p(b,c);}
template<class A,class B,class C,class D>void p(A a,B b,C c,D d){cout << a << " " ;p(b,c,d);}
typedef unsigned long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for copy
// for(int i=0;i<N;++i) {

int main(void) {
  ll n,a,b;cin>>n>>a>>b;
  if(a+b>0) {
    ll cnt = n/(a+b);
    ll rest = n-(a+b)*cnt;
    if(rest > a) rest = a;
    p(cnt*a+rest);
  } else {
    p(0);
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int dp[105][100005];
signed main() {
    int N,W;
    cin >> N >> W;
    for(int i = 0; i < 105; i++) {
        for(int j = 0; j < 100005; j++) {
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;
    for(int i = 0; i < N; i++) {
        int w,v;
        cin >> w >> v;
        for(int j = 0; j < 100005; j++) {
            if(dp[i][j] != INF) {
                if(dp[i][j]+w <= W) {
                    dp[i+1][j+v] = dp[i][j]+w;
                }
            }
            dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
        }
    }
    int ans = 0;
    for(int i = 0; i < 100005; i++) {
        if(dp[N][i] != INF) {
            ans = i;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 85636
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <map>
#include <functional>
#include <cmath>
#include <cstdio>
using namespace std;

#define PI 4*atan(1);

int main(){
  int l, a, b, c, d;
  int cnt = 0;
  cin >> l >> a >> b >> c >> d;
  for(;;){
    a -= c;
    b -= d;
    cnt++;
    if(a <= 0 && b <= 0)break;
  }
  cout << l - cnt << endl;
}

Measured memory_bytes: 1164
#include <stdio.h>

using namespace std;

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

int max(int X, int Y) {
    return X > Y ? X : Y;
}

int main() {
    int A, B, C;
    scanf("%d %d %d", &A, &B, &C);

    int m = max(A, max(B, C));

    int ax = m - A;
    int bx = m - B;
    int cx = m - C;
    int x = ax + bx + cx;

    if (x % 2 == 0) {
        printf("%d\n", x / 2);
    } else {
        printf("%d\n", (x + 3) / 2);
    }

    return 0;
}


Measured memory_bytes: 128
require 'matrix'

N = gets.chomp.to_i
Meters = gets.chomp.split(' ').map(&:to_i)[0..N]
Meters2x = Meters.map{ |i| i*2 }

x1 = Meters.reduce(0, &:+) - Meters2x.select.with_index { |v, i| i.odd? }.reduce(0, &:+)

puts (0.upto(N-2).reduce([x1]) do |solution, i|
  solution.push Meters2x[i] - solution.last
end).join(" ")


Measured memory_bytes: 16764
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <queue>
using namespace std;

typedef pair<int, int> P;
typedef queue<P> Q;
const int INF = 10000000;

int main() {
  char buf[1001];
  char map[1000][1000];
  int d[1000][1000];
  int h, w, n;
  int sx, sy;
  int x, y;
  int nx, ny;
  int dx[4] = {0, 1, 0, -1};
  int dy[4] = {1, 0, -1, 0};
  int count;
  bool flg;
  Q q;

  cin >> h >> w >> n;
  for (int i=0; i<h; i++) {
    cin >> buf;
    memcpy(map[i], buf, w);
  }

  flg = false;
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      if (map[i][j] == 'S') {
        sx = j;
        sy = i;
        flg = true;
        break;
      }
    }
    if (flg) break;
  }

  count = 0;
  for (int i=1; i<=n; i++) {
    for (int j=0; j<h; j++) {
      for (int k=0; k<w; k++) {
        d[j][k] = INF;
      }
    }
    q.push(P(sx, sy));
    d[sy][sx] = 0;
    while (q.size()) {
      P p = q.front();
      q.pop();
      x = p.first;
      y = p.second;
      if (map[y][x] == '0'+i) {
        count += d[y][x];
        while(!q.empty()) q.pop();
        sx = x;
        sy = y;
        break;
      }
      for (int j=0; j<4; j++) {
        nx = x + dx[j];
        ny = y + dy[j];
        if (nx>=0 && nx<=w && ny>=0 && ny<=h && map[ny][nx]!='X' && d[ny][nx]==INF) {
          d[ny][nx] = d[y][x] + 1;
          q.push(P(nx, ny));
        }
      }
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 6100
#!/usr/bin/env ruby
require 'matrix'

A,B,H,M = gets.chomp.split.map(&:to_i)
Hdeg = (30.0 * H - 0.5 * M) * Math::PI / 180.0
Mdeg =   5.0 * M * Math::PI / 180.0

Av = Vector[A * Math.cos(Hdeg), A * Math.sin(Hdeg)]
Bv = Vector[B * Math.cos(Mdeg), B * Math.sin(Mdeg)]

puts (Av - Bv).r

Measured memory_bytes: 15388
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int N=26;
int D;
vector<int> c(N);
vector<vector<int>> s;

lint calc_score(vector<int> &t){
  lint ans=0;
  int last[N];
  REP(n,N)last[n]=-1;
  REP(d,D){
    ans+=s[d][t[d]];
    last[t[d]]=d;
    REP(n,N)ans-=c[n]*(d-last[n]);
  }
  return ans;
}

lint calc_score(int i,set<int> &ss){
  lint ans=0;
  int last=-1;
  for(auto e:ss){
    ans+=s[e][i];
    int w=e-last;
    ans-=c[i]*w*(w-1)/2;
    last=e;
  }
  int w=D-last;
  ans-=c[i]*w*(w-1)/2;
  return ans;
}

int main(){
  cin>>D;
  REP(i,N)cin>>c[i];
  REP(d,D){
    vector<int> v(N);
    REP(n,N)cin>>v[n];
    s.push_back(v);
  }
  vector<int> t(D);
  vector<set<int>> vs(N);
  REP(d,D){
    cin>>t[d];
    t[d]--;
    vs[t[d]].insert(d);
  }
  vector<lint> score(N,0);
  REP(i,N)score[i]=calc_score(i,vs[i]);
  lint temp=0;
  REP(i,N)temp+=score[i];
  // cerr<<temp<<" "<<calc_score(t)<<endl;
  int M;
  cin>>M;
  vector<lint> ans;
  REP(i,M){
    int d,q;
    cin>>d>>q;
    d--;q--;
    int qp=t[d];
    t[d]=q;
    vs[qp].erase(d);
    vs[q].insert(d);
    temp-=score[qp];
    temp-=score[q];
    score[qp]=calc_score(qp,vs[qp]);
    score[q]=calc_score(q,vs[q]);
    temp+=score[qp];
    temp+=score[q];
    ans.push_back(temp);
  }
  for(auto e:ans)cout<<e<<endl;
  return 0;
}


Measured memory_bytes: 4164
N,M=map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(M)]

if N>1:
    s = list('1'+'0'*(N-1))
else:
    s=list('0')
d = {1:-1,2:-1,3:-1}
sw = 0
for i in range(M):
    s[sc[i][0]-1] = str(sc[i][1])
    if d[sc[i][0]]==-1: 
        d[sc[i][0]] = sc[i][1]
    elif d[sc[i][0]]!=sc[i][1]:
        sw=1
if sw==1:
    print(-1)
elif s[0]=='0' and N>1:
    print(-1)
else:
    print(''.join(s))

Measured memory_bytes: 3064
package main

import "fmt"

func main() {
	var N, K int
	fmt.Scan(&N, &K)

	ans := 0
	var h int
	for i := 0; i < N; i++ {
		fmt.Scan(&h)
		if K <= h {
			ans++
		}
	}

	fmt.Println(ans)
}


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

int n[510000];
int x[510000];

void input() {
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		n[s.length() - 1 - i] = s[i] - '0';
	}
}

bool check(int k) {
	int i;
	
	for (i = 0; i < 505000; i++) x[i] = 0;
	for (i = 0; i < 505000; i++) x[i] = n[i] * 9;
	x[0] += 9 * k;
	
	for (i = 0; i < 505000; i++) {
		x[i + 1] += x[i] / 10;
		x[i] %= 10;
	}
	
	int digit_sum = 0;
	for (i = 0; i < 505000; i++) {
		digit_sum += x[i];
	}
	return (digit_sum <= 9 * k);
}

int main() {
	input();
	
	int st = 0, ed = 500001, mid;	//xxxooo, (st, ed]
	while (ed - st >= 2) {
		mid = (st + ed) / 2;
		if (check(mid)) ed = mid;
		else st = mid;
	}
	cout << ed << endl;
	
	return 0;
}

Measured memory_bytes: 4264
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; i++ )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

ll dp[111][111][2];
int a[111];

ll powmod(ll n,ll k){
    ll ret=1;
    while(k>0){
        if(k&1)ret=ret*n%mod;
        n=n*n%mod;
        k>>=1;
    }
    return ret;
}

ll rec(int l,int r,int h,int flag){
    if(dp[l][r][flag]!=-1)return dp[l][r][flag];
    int mi=inf,ma=0;
    REP(i,l,r){
        mi=min(mi,a[i]);
        ma=max(ma,a[i]);
    }
    ll ret1,ret2;
    ret1=ret2=1;
    ll pos=l-1;
    REP(i,l,r){
        if(a[i]==mi){
            ret2=2*ret2%mod;;
            if(i-pos>1){
                ret1*=rec(pos+1,i,mi,1);
                ret2*=(2*rec(pos+1,i,mi,1)+rec(pos+1,i,mi,0));
                ret1%=mod;
                ret2%=mod;
            }
            pos=i;
        }
    }
    if(r-pos>1){
        ret1=ret1*rec(pos+1,r,mi,1)%mod;
        ret2=ret2*(2*rec(pos+1,r,mi,1)+rec(pos+1,r,mi,0))%mod;
    }
    ret2=(ret2-ret1*2+2*mod)%mod;
    return dp[l][r][flag]=flag?ret1*powmod(2,mi-h)%mod:ret2;
}
int main(){
   int n;
   cin>>n;
   rep(i,n)cin>>a[i];
   rep(i,n+1)rep(j,n+1)rep(k,2)dp[i][j][k]=-1;
   ll ans=rec(0,n,0,0)+rec(0,n,0,1);
   cout<<ans%mod<<endl;
   return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int main(){

	int value = 0;

	int N,D;

	scanf("%d %d",&N,&D);

	int tmp;

	for(int i = 0; i < N; i++){
		scanf("%d",&tmp);
		value ^= (tmp-1)%(D+1);
	}

	if(value != 0){
		printf("First\n");
	}else{
		printf("Second\n");
	}

	return 0;
}



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

public class Main {
	
	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		
		int n=s.nextInt();
		
		HashMap<Integer,Long> map=new HashMap<>();
		int[] arr=new int[n];
		
		for(int i=0;i<n;i++)
		{
			int val=s.nextInt();
			
			arr[i]=val;
			
			if(map.containsKey(val))
			{
				map.put(val, map.get(val)+1);
			}
			else
			{
				map.put(val, 1l);
			}
		}
		
		long total=0;
		
		for(Map.Entry<Integer, Long> entry: map.entrySet())
		{
			long val=entry.getValue();
			
			total=total+(val*(val-1))/2;
		}
		
		for(int i=0;i<n;i++)
		{
			long ans=total-map.get(arr[i])+1;
			System.out.println(ans);
		}
		
		
	}
	
}

Measured memory_bytes: 109728
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int N;
  string S;
  cin >> N >> S;
  vector<string> sb(N);
  for (int i = 0; i < N; ++i)
    cin >> sb[i];

  int ans = 0;
  for (int i = 0; i < N; ++i) {
    bool flag = false;
    for (int j = 0; j < sb[i].size() - S.size() + 1; ++j) {
      for (int k = 1; k < sb[i].size(); ++k) {
        string S2;
        for (int l = j; l < sb[i].size(); l += k)
          S2 += sb[i][l];

        if (S2.substr(0, S.size()) == S)
          flag = true;

        if (flag)
          break;
      }

      if (flag)
        break;
    }

    if (flag)
      ++ans;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe



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

int n,ans = 0,max;

cin >> n;

int a[n];

rep(i,n) cin >> a[i];

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

   cout << ans << endl;






//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
def ok(k):
    # 長さkの連続部分列で重ならずに2回以上現れるものがある
    D = {}
    for i in range(n-k+1):
        s = S[i:i+k]
        try:
            if D[s]+k <= i:
                return True
        except:
            D[s] = i
    return False


n = int(input())
S = input()
# 二分探索でTrueになる最大のkを求める
l, r = 0, n+1
while r-l > 1:
    c = (l+r)//2
    if ok(c):
        l = c
    else:
        r = c
print(l)


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

int main(){
    
    string S, T;
    cin >> S >> T;
    
    int i, j, s, t, count, ans;
    s = S.size();
    t = T.size();
    ans = t;

    for (i = 0; i <= s - t; i++){
        count = 0;
        
        for (j = 0; j < t; j++){
            if (S[i + j] != T[j]) count++;
        }
        
        if (count < ans) ans = count;
        
    }
    
    cout << ans;

    return 0;
}


Measured memory_bytes: 3604
s = gets.chomp
cnt=0
if s.length == 1
  puts 0

elsif s.length%2==0
  a=s[0..(s.length/2-1)]
  b=s[(s.length/2)..-1].reverse

  a.chars.each_with_index do |s,i|
    cnt+=1 if a[i] == b[i]
  end
  puts a.length-cnt

else
  c=s[0..(s.length/2-1)]
  d=s[(s.length/2+1)..-1].reverse

  c.chars.each_with_index do |s,i|
    cnt+=1 if c[i] == d[i]
  end
  puts c.length-cnt
end


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

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPr(i, n) for(int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for(int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for(int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
    cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
    int x12345;                                                                \
    cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
const long long MOD = 1e9 + 7;
///////////////////////////////////////////////
// for template
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;
}
///////////////////////////////////////////////
/// 🍈( '-' 🍈 |AC|
int main() {
    int H,W,K; cin >> H >> W >> K;
    int ans = 0;
    char grid[H][W] = {};
    REP(i,H){
        REP(j,W){
            cin >> grid[i][j];
        }
    }

    for (int b = 0; b < (1<<H); b++){
        for(int b2 = 0; b2 < (1 << W); b2++){
            char ngrid[H][W];
            //DB2(b,b2);
            REP(i,H){
                REP(j,W){
                    ngrid[i][j] = grid[i][j];
                    if ((b & (1<<i)) or (b2 & (1<<j))){ 
                        ngrid[i][j] = ',';
			        }
                }
            }
            int bcount = 0;
            REP(i,H){
                REP(j,W){
                    if (ngrid[i][j] == '#') bcount++;
                }
            }
            bool test = (bcount == K);
            //DB(test);
            if (bcount == K) ans++;
        }
	}
    cout << ans << endl;
}

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

#define STR_ACK "Yes"
#define STR_NAK "No"

#define print_is_truth(boolean) \
  do {                          \
    if (boolean) {              \
      std::cout << STR_ACK;     \
    } else {                    \
      std::cout << STR_NAK;     \
    }                           \
    std::cout << std::endl;     \
  } while(0)

inline bool is_square_number (const int& number)
{
  if (number == 0) return true;
  if ((number >> 1) & 1 == 1) return false;
  for (auto i = 1, odd = 3; i <= number; i += odd, odd += 2) {
    if (i == number) return true;
  }
  return false;
}

int main ()
{
  std::string a, b;
  std::cin >> a >> b;
  a += b;
  const auto wanted_number = std::stoi(a);
  print_is_truth(is_square_number(wanted_number));

  return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
 
typedef long long ll;
typedef pair<int, int> ii;

int main() {
	
	int h;
	while(cin >> h , h){
		
		vector<vector<int>> mp(h, vector<int>(5));
		
		for(int i = h-1; i >= 0; i--) rep(j, 5) cin >> mp[i][j];
		
		int ans = 0;
		bool f = true;
		while(f){
			f = false;
			rep(i, h){
				int cnt = 1;
				REP(j, 1, 5){
					if(mp[i][j] == mp[i][j - 1] && mp[i][j] > 0) cnt++;
					else{
						if(cnt >= 3){
							rep(k, cnt){
								ans += mp[i][j-1-k];
								mp[i][j-1-k] = -1;
								f = true;
							}
						}
						cnt = 1;
					}
				}
				if(cnt >= 3){
					rep(k, cnt){
						ans += mp[i][4-k];
						mp[i][4-k] = -1;
						f = true;
					}
				}
				
			}
			
			rep(i, h){
				rep(j, 5){
					if(mp[i][j] == -1){
						int tmp = 0;
						for(int k = 1; i + k < h; k++){
							if(mp[i+k][j] != -1){
								tmp = mp[i+k][j];
								mp[i+k][j] = -1;
								break;
							}
							mp[i+k][j] = -1;
						}
						
						mp[i][j] = tmp;
					}
				}
			}
		}
	
		cout << ans << endl;
		
	}
	
	
	return 0;
}

Measured memory_bytes: 2972
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.IntStream;

public class Main {

	/** 1000以下の素数の配列 */
	private static final int[] PRIMES = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
			73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181,
			191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307,
			311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433,
			439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571,
			577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701,
			709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853,
			857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997 };

	public static void main(String[] args) {

		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] a = new int[n];
			int oneCount = (int) IntStream.range(0, n).map(i -> a[i] = scanner.nextInt()).filter(ai -> 0 == ai).count();
			boolean pairwiseCoprime = true;
			// 因数のセット
			Set<Integer> totalSet = getFactors(a[0]);
			main: for (int i = 1; i < n; i++) {
				Set<Integer> set = getFactors(a[i]);
				for (Integer j : set) {
					if (totalSet.contains(j)) {
						pairwiseCoprime = false;
						break main;
					}
				}
				totalSet.addAll(set);
			}
			if (pairwiseCoprime) {
				System.out.println("pairwise coprime");
				return;
			}
			boolean setwiseCoprime = true;
			if (0 == oneCount) {
				setwiseCoprime = false;
				int gcd = a[0];
				for (int i = 1; i < n; i++) {
					gcd = gcd(gcd, a[i]);
					if (1 == gcd) {
						setwiseCoprime = true;
						break;
					}
				}
			}
			if (setwiseCoprime) {
				System.out.println("setwise coprime");
			} else {
				System.out.println("not coprime");
			}
		}
	}

	private static Set<Integer> getFactors(int n) {
		Set<Integer> set = new HashSet<>();
		int index = 0;
		while (n > 1) {
			if (index == PRIMES.length) {
				set.add(n);
				break;
			}
			while (0 == (n % PRIMES[index])) {
				n /= PRIMES[index];
				set.add(PRIMES[index]);
			}
			index++;
		}
		return set;
	}

	/**
	 * mとnの最大公約数を返す
	 * 
	 * @param m
	 * @param n
	 * @return mとnの最大公約数
	 */
	private static int gcd(int m, int n) {
		if (0 == n) {
			return m;
		}
		return gcd(n, m % n);
	}
}


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

int main()
{
int N,K;
cin>>N>>K;
int arr[1100];
for(int i=0;i<N;++i)
{
    cin>>arr[i];
}
sort(arr,arr+N);

int counter=0;
for(int i=0;i<K;++i)
{

    counter+=arr[i];
}
cout<<counter;
    return 0;
}


Measured memory_bytes: 3616
from math import factorial
N, M = map(int, input().split())
MOD = 10**9 + 7
if N == M:
    print((factorial(N)**2 * 2) % MOD)
elif N + 1 == M:
    print((factorial(M) * factorial(N)) % MOD)
elif M + 1 == N:
    print((factorial(M) * factorial(N)) % MOD)
else:
    print(0)


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


struct P
{
    //string r;
    int x;
    long long y,z;

   /* bool operator<(const P &a)const{
       // if(y!=a.y)
       // return y>a.y;
              return y>a.y;
    }*/
};


vector<int> v[111];
//bitset<4001000> b;
int a,c,i,b,k,n,d,m;//dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};//
int l[12];

int o[5][111455];
int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,-1,1,-1,1},dz[10]={0,0,0,0,1,-1};

int e;

long long x,y,mod=1000000007;
long long z[11];
P j[400];
P u[10],u1[100];
//stack<int> s;
//queue<int> q;
set<int> s;
priority_queue<int,vector<int>,greater<int> > q;
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p;
//list<int> l;
string r1,r;
//char r[5][111][111];
//deque<int> de;

//20921
bool as(P a,P b)
{
    return a.x<b.x;
}

int main()
{
    scanf("%d",&a);
    for(int t=1;t<=a;t++)
    {
        long long x,y,z,n=1,m=1000000000;
        scanf("%lld %lld",&x,&y);
        if(x>y) swap(x,y);
        z=x*y;
        for(;n<m;)
        {
            long long u=(n+m)/2;
            if(u*u>=z) m=u;
            else n=u+1;
        }
        if(n*n==z)
        {
            if(n==x)
            {
                printf("%lld\n",2*n-2);
            }
            else
            {
                printf("%lld\n",2*n-3);
            }
        }
        else
        {
            if((n-1)*n<z) printf("%lld\n",2*n-3);
            else printf("%lld\n",2*n-4);
        }


    }
}


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

typedef long long ll;

int main() {
    int N, ans = 1e6;
    string S;
    cin >> N >> S;
    vector<int> A(N + 1, 0);
    rep(i, N) {
        A[i + 1] = A[i];
        if (S[i] == 'E') A[i + 1]++;
    }
    rep(i, N) {
        ans = min(ans, i - A[i] + A[N] - A[i + 1]);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 4844
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long a = sc.nextLong();
		long max = a;
		for (int i =0;i<N-1;i++) {
			long temp = sc.nextLong();
			if (temp<max) {
				System.out.println("No");
				return ;
			}
			if (temp >= a+1) {
				a = temp-1;
			} else if (a>=temp+2) {
				System.out.println("No");
				return ;
			}
			max = a;
		}
		System.out.println("Yes");
	}
}

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

#define ll long long 

int main(void)
{
    
   ll n,k,i,ans=9999999999;

   cin>>n>>k;
   std::vector<int> a(n+1,0);
   
   for(i=0;i<n;i++)cin>>a[i];

   vector<ll>dp(n+5,99999999);
   
   dp[0]=0;
   dp[1]=abs(a[1]-a[0]);
   for(i=2;i<n;i++)
   {
    ll p=1;
    dp[i]=999999999;
    while(i-p>=0 && p<=k)
    {
      dp[i]=min(dp[i],dp[i-p]+abs(a[i]-a[i-p]));
      p++;
      // cout<<i<<" "<<p<<" "<<dp[i]<<endl;
    }
   }
   
   cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1408
#include "bits/stdc++.h"
#define hhh cerr<<"hhh"<<endl
#define see(x) cerr<<(#x)<<'='<<(x)<<endl
using namespace std;
typedef long long ll;
typedef pair<int,int> pr;
inline int read() {int x=0,f=1;char c=getchar();while(c!='-'&&(c<'0'||c>'9'))c=getchar();if(c=='-')f=-1,c=getchar();while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return f*x;}

const int maxn = 1e6+7;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;

string s[maxn];

vector<pr> v1;

struct P{
    int first, second;
    P(int f=0, int s=0): first(f), second(s) {}
    bool operator < (const P &rhs) const {
        return second+first>rhs.second+rhs.first;
    }
};

vector<P> v2;

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n; cin>>n;
    int tot=0;
    int c1=0, c2=0;
    for(int i=1; i<=n; ++i) {
        cin>>s[i];
        int tmp=0, mi=inf;
        for(int j=0; j<s[i].size(); ++j) {
            tot+=(s[i][j]=='('?1:-1);
            tmp+=(s[i][j]=='('?1:-1);
            mi=min(mi,tmp);
        }
        if(mi>=0) c1+=tmp;
        else {
            if(tmp>=0) v1.push_back(pr(-mi,tmp));
            else v2.push_back(P(-mi,tmp));
        }
    }
    if(tot!=0) return (cout<<"No"<<endl), 0;
    sort(v1.begin(),v1.end());
    for(int i=0; i<v1.size(); ++i) {
        if(c1>=v1[i].first) {
            c1+=v1[i].second;
        }
        else return (cout<<"No"<<endl), 0;
    }
    sort(v2.begin(),v2.end());
    for(int i=0; i<v2.size(); ++i) {
        if(c1>=v2[i].first) {
            c1+=v2[i].second;
        }
        else return (cout<<"No"<<endl), 0;
    }
    assert(c1==0);
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 38964
#include <stdio.h>

void insertionSort(int* A, int N){
	int v, j;
	for (int i = 1; i < N; i++)
	{
		v = A[i];
		j = i-1;
		while(j >= 0 && A[j] > v){
			A[j+1] = A[j];
			j--;
		}
		A[j+1] = v;
		
		for(j = 0; j < N; j++){
			printf("%d", A[j]);
			if(j != N-1) printf(" ");
		}
		printf("\n");
	}
}



int main(int argc, char const *argv[])
{
	int N, A[1000];
	scanf("%d", &N);
	int i;
	for(i = 0; i < N; i++){
		scanf("%d", &A[i]);
	}
	for( i = 0; i < N; i++ ){
        printf("%d", A[i]);
        if( i != N-1 ) printf(" ");
    }
    printf("\n");
    insertionSort(A, N);

	return 0;
}


Measured memory_bytes: 1992
#include <iostream>
using namespace std;
void call(int n){

}
int main(){
	int n;
	int x;
	cin >> n;
	for(int i=1;i<=n;++i){
		x = i;
		if(x%3==0){cout << " " << i;}
		else{
			while(x){
				if(x%10==3){
					cout << " " << i;
					break;
				}
				x/=10;
			}
		}
	}
cout << endl;

}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int one = 0;
		int two = 0;
		int three = 0;
		int four = 0;

		for(int i = 0; i < 6; i++) {
			int c = sc.nextInt();
			if(c == 1) {
				one++;
			} else if(c==2) {
				two++;
			} else if(c==3) {
				three++;
			} else {
				four++;
			}
		}

		int oddCount = 0;

		if(one%2==1) {
			oddCount++;
		}
		if(two%2==1) {
			oddCount++;

		}
		if(three%2==1) {

			oddCount++;
		}
		if(four%2==1) {
			oddCount++;

		}

		if(oddCount == 0 || oddCount ==2) {
			System.out.println("YES");
			return;
		}

		System.out.println("NO");

	}

}


Measured memory_bytes: 23892
#include <bits/stdc++.h> 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define cout(x) cout<<x<<endl
#define all(v) v.begin(), v.end()
using namespace std;
//型エイリアス
using vi = vector<int>;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
const ll inf = 1e18;
const int N = 2e5 + 10;


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

    int l=(int)s.size(),r=0;
    rep(i,(int)s.size()){
        if (s[i] == 'A') l = min(i, l);
        if (s[i] == 'Z') r = max(i, r);
    }
    cout(r - l + 1);

    return 0;
}

Measured memory_bytes: 640