akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int p[n];
    for(int i=0;i<n;i++)
    {
        cin>>p[i];
    }
    sort(p,p+n);
    int sum=0;
    for(int i=0;i<k;i++)
    {
        sum+=p[i];
    }
    cout<<sum;
}


Measured memory_bytes: 3640
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    S = input().strip().split("S")
    print(max(len(s) for s in S))


if __name__ == "__main__":
    main()



Measured memory_bytes: 67900
N = gets.to_i
a = gets.split.map(&:to_i)
csum = [0]*(N+1)
N.times do |i|
	csum[i+1] = csum[i] + a[i]
end
ans = (csum[N]-csum[1]*2).abs
2.upto(N-1) do |i|
	t = (csum[N]-csum[i]*2).abs
	#p t
	ans = t if t < ans
end
p ans


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

bool f(vector<vector<bool>> &x) {
  bool ret = false;
  // horizontal line
  for (int i = 0; i < 3; i++) {
    bool keep = true;
    for (int j = 0; j < 3; j++) {
      if (!x.at(i).at(j)) keep = false;
    }
    ret |= keep;
  }
  // vertical line
  for (int j = 0; j < 3; j++) {
    bool keep = true;
    for (int i = 0; i < 3; i++) {
      if (!x.at(i).at(j)) keep = false;
    }
    ret |= keep;
  }
  // crossing line
  if (x.at(0).at(0) && x.at(1).at(1) && x.at(2).at(2)) ret = true;
  if (x.at(0).at(2) && x.at(1).at(1) && x.at(2).at(0)) ret = true;
  // return
  return ret;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  vector<vector<int>> a(3, vector<int>(3));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> a.at(i).at(j);
    }
  }
  
  int n;
  cin >> n;
  
  vector<vector<bool>> x(3, vector<bool>(3, false));
  for (int i = 0; i < n; i++) {
    int b;
    cin >> b;
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        if (a.at(j).at(k) == b) x.at(j).at(k) = true;
      }
    }
  }
  
  if (f(x)) cout << "Yes\n";
  else cout << "No\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <numeric> // accumulate(begin,end,初期値)

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl;
#define rep(i,n) for(ll i = 0;i < n;++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0);

const ll INF = 1e9+7;

// 各桁の和
template<typename T>
T digit(T num){
  T sum = 0;
  while(num){
    sum += num % 10;
    num /= 10;
  }
  return sum;
}

int main(){
  int N,M;
  cin>>N>>M;
  
  rep(i,N+1){
    rep(j,N+1){
      int tmp = i * 10000 + j * 5000;
      if(tmp > M)break;
      int k = (M - tmp) / 1000;

      if(i + j + k == N){
        cout<<i<<' '<<j<<' '<<k<<endl;
        return 0;
      }
      
    }
  }
  
  cout<<-1<<' '<<-1<<' '<<-1<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef long long llong;
char moji[26]={'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'};
char moji2[26]={'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'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl; 


int main(){
    llong n,m;
    cin >> n >> m;
    llong tmp;
    tmp = (max(llong(0),(m-2*n))/4);
    m -=tmp *2;
    n+= tmp;
    print( min(m/2,n));
}

Measured memory_bytes: 256
(function(input) {
    var lines = input.split('\n');
    var n = Number(lines[0]);
    var items = lines[1].split(' ').map(Number);
    var min = Infinity, max = -Infinity, sum = 0;
    for (var i = 0; i < items.length; i++) {
        var a = items[i];
        if (a < min) {
            min = a;
        }
        if (a > max) {
            max = a;
        }
        sum += a;
    }
    console.log('%d %d %d', min, max, sum)
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 9120
#include <bits/stdc++.h>
#include <set>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 100000000
#define MOD 1000000007
#define writeln(n) cout<<n<<endl
//setprecision(10);
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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

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

llong pownew(llong m, llong n) {
    if (n == 0) { return 1; }
    if (n % 2 == 0) { return pow(m*m, n/2); }
    return pow(m, n-1) * m;
}

bool isprime(int p) {
    if (p == 1) return false;
    for (int i = 2; i < p; i++) {
        if (p%i == 0) return false;
    }
    return true;
}

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

const int inf=100000000;

long long modpow(long long a, long long n, long long mod) //a^n
{
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

llong gcd(llong a, llong b) {
        return b != 0 ? gcd(b, a % b) : a;
    }

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s; cin>>s;
    string ans="Good";
    REP(i,4)
    {
        if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3]) ans="Bad";
    }
    cout<<ans<<endl;

    return  0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt(), h = sc.nextInt(), n = sc.nextInt();
		int xmax = w, ymax = h, xmin = 0, ymin = 0;
		for(int i = 0 ; i < n ; i++) {
			int x = sc.nextInt(), y = sc.nextInt(), a = sc.nextInt();
			if (a == 1) xmin = Math.max(xmin,x);
			if (a == 2) xmax = Math.min(xmax,x);
			if (a == 3) ymin = Math.max(ymin,y);
			if (a == 4) ymax = Math.min(ymax,y);
		}
		if (xmax - xmin < 0 || ymax - ymin < 0) {
			System.out.println("0");
		}else {
			System.out.println((xmax - xmin) * (ymax - ymin));
		}
	}
} 

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


#define  SZ(items) (int)items.size()
#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))
#define  nl "\n";

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



template <class T> inline T biton(T n, T pos)
{
	return n | ((T)1 << pos);
}
template <class T> inline T bitoff(T n, T pos)
{
	return n & ~((T)1 << pos);
}
template <class T> inline T ison(T n, T pos)
{
	return (bool)(n & ((T)1 << pos));
}
template <class T> inline T gcd(T a, T b)
{
	while (b)
	{
		a = a % b;
		swap(a, b);
	}
	return a;
}
template <class T> inline T bigmod(T p, T e, T m)
{
	T ret = 1;
	for (; e > 0; e >>= 1)
	{
		if (e & 1)
			ret = (ret * p) % m;
		p = (p * p) % m;
	}
	return (T)ret;
};



#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1)
{
	cerr << name << " is " << arg1 << std::endl;
}
template < typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " is " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define debug(...)
#endif




void solve()
{
	int n, m;
	cin >> n >> m;

	int cnt = 0;
	vector<long long> items(n);
	long long sum = 0;

	for (int i = 0; i < n; i++) {

		cin >> items[i];
		sum += items[i];

	}

	for (int i = 0; i < n; i++) {


		if (items[i] * 4 * m >= sum) {
			cnt++;
		}
	}
	if (cnt >= m) {
		cout << "Yes" << endl;
		return;
	}
	cout << "No" << endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cout.setf(ios::fixed);
	cout.precision(10);
	cout.tie(nullptr);
	cin.tie(nullptr);

	int t = 1;

	while (t--)
	{
		solve();
	}

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

const double PI=acos(-1);
const double EPS=1e-9; //うまくいかなかったらゆるめる

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    string s;
    cin >> s;
    rep(i,s.size()){
        if(s[i] == '?')cout << "D";
        else cout << s[i];
    }
    cout << endl;
}


Measured memory_bytes: 3752
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <iomanip>
#include <map>
#include <cstdio>
#include <sstream>
#define ll long long
using namespace std;

int main(){
   ios_base::sync_with_stdio(false);
   char c;
   cin >> c;

   cout << char(((int) c)+1) << '\n';
}
/* 


*/

Measured memory_bytes: 256
import sys

cin = sys.stdin
# cin = open("in.txt", "r")


S = cin.readline().strip()
T = cin.readline().strip()
q = int(cin.readline())

def ABcnt(S):
    ls = len(S)
    cnt = 0
    Rcnt = [0]*(ls+1)
    for i in range(ls):
        if S[i]=='A':
            cnt += 1
        else:
            cnt -= 1
        Rcnt[i+1] = cnt
    return Rcnt

Scnt = ABcnt(S)
Tcnt = ABcnt(T)

for i in range(q):
    a,b,c,d = map(int, cin.readline().split())
    Stotal = (Scnt[b]-Scnt[a-1]) % 3
    Ttotal = (Tcnt[d]-Tcnt[c-1]) % 3
    if Stotal==Ttotal:
        print('YES')
    else:
        print('NO')


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

using namespace std;

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define endl "\n"

#define aim_cpo do{ios::sync_with_stdio(false);\
cin.tie(nullptr);cout.precision(10);cout<<fixed;}while(0)

#define LOCAL_INPUT do{FILE *stream1;\
stream1=freopen("/Users/aim_cpo/CLionProjects/competitive/in.txt","r",stdin);\
if(stream1==nullptr)return 0;}while(0)

#define LOCAL_OUTPUT do{FILE *stream2;\
stream2 = freopen("out.txt", "w", stdout);\
if (stream2 == nullptr) return 0;}while(0)

#ifdef LOCAL_DEFINE
#define show(x) cerr << #x << " = " << (x) << endl
#else
#define show(x)
#endif

typedef long long ll;
typedef unsigned long long ull;

constexpr const int INT_INF=0x3f3f3f3f; // 1061109567
constexpr const ll LL_INF=0x3f3f3f3f3f3f3f3f; // 4557430888798830399

template <typename T> bool chmin(T &a, T b){return a>b?(a=b,true):false;}

template <typename T> bool chmax(T &a, T b){return a<b?(a=b,true):false;}

// INT
#define GCD(a, b) __gcd(a, b)
template <typename T> T LCM(T a, T b) {return a / GCD(a, b) * b;}
template <typename T> T EXTGCD(T a, T b, T& x, T& y) {
    T d = a;
    if (b != 0) {d=EXTGCD(b,a%b,y,x);y-=(a/b)*x;}
    else x=1,y=0;
    return d;
}
template <typename T> bool is_prime(T a) {
    for(int i=2;i*i<=a;i++)if(a%i==0)return 1;
    return 0;
}

// MOD
ll MOD = 1000000000L + 7L;
#define add(a, b) ((a % MOD) + (b % MOD)) % MOD
#define mul(a, b) ((a % MOD) * (b % MOD)) % MOD
#define sub(a, b) ((a % MOD) + MOD - (b % MOD)) % MOD
template <typename T> T mod_inverse(T a, T mod, bool prime){ // if mod is prime, "prime" is true.
    if(prime){
        T tmp=mod-2,now=a,res=1;while(tmp){if(tmp&1)res=mul(res,now);now=mul(now,now);tmp>>=1;}
        return res;
    }else{T x,y;EXTGCD(a,mod,x,y);return (mod+x%mod)%mod;}
}
#define divide(a, b) ((a % MOD) * (mod_inverse(b, MOD, true))) % MOD

//LLの数値をつかう時は最後にLをつける癖をつけよう
//
//  ┏┓┏┓　┓　┏┓
//  ┏┛┃┃　┃　┗┫
//  ┗┛┗┛　┻　┗┛
//
//   謹┃賀┃新┃年┃
//   ━┛━┛━┛━┛
//WWWWWWWWWWWWWWWWWWWWWW

int n;
int a[3];

int main() {
    aim_cpo; // インタラクティブのときは消すように.
#ifdef LOCAL_DEFINE
    LOCAL_INPUT; // インタラクティブのときは消すように.
//    LOCAL_OUTPUT; // ファイルに出力したいときのみ
    show(MOD);
#endif
    cin >> n;
    int a1, b; cin >> a1 >> b;
    for (int i = 0; i < n; i++) {
        int p; cin >> p;
        if (p <= a1) a[0]++;
        else if (p <= b) a[1]++;
        else a[2]++;
    }
    cout << min(a[0], min(a[1], a[2])) << endl;
#ifdef  LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s." << endl;
#endif
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f40;
const long long mod=2e9+7;
const long double PI = acos(0);
// }}} End Header
int main() {
	int d, t, s;
	cin >> d >> t >> s;
	if(d <= t*s) cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 3652
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int T = in.nextInt();
		int A = in.nextInt();
		List<Integer> H = new ArrayList<>(N);
		for (int i = 0; i < N; ++i) {
			H.add(in.nextInt());
		}
		in.close();

		List<Double> temps = new ArrayList<>(N);
		for (int i = 0; i < N; ++i) {
			double temp = (double) T - (double) (H.get(i)) * 0.006;
			temps.add(temp);
		}
		double diff = Double.MAX_VALUE;
		int result = -1;
		for (int i = 0; i < H.size(); ++i) {
			if (Math.abs(temps.get(i) - (double) A) < diff) {
				diff = Math.abs(temps.get(i) - (double) A);
				result = i;
			}
		}
		System.out.println((result + 1));
	}

}

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

struct Node {
  int key;
  Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k) {
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL) {
    y = x;
    if (z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }

  z->parent = y;
  if (y == NIL) {
    root = z;
  } else {
    if (z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void inorder(Node *u) {
  if (u == NIL) return;
  inorder(u->left);
  cout << " " << u->key;
  inorder(u->right);
}

void preorder(Node *u) {
  if (u == NIL) return;
  cout << " " << u->key;
  preorder(u->left);
  preorder(u->right);
}

int main() {
  int n, x;
  string com;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> com;
    if (com == "insert") {
      cin >> x;
      insert(x);
    } else if (com == "print") {
      inorder(root);
      cout << endl;
      preorder(root);
      cout << endl;
    }
  }

  return 0;

}


Measured memory_bytes: 26632
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
ll choose2(ll n)
{
    if(n<0)
    {
        return 0;
    }
    return n*(n-1)/2;
}
long long modpow(long long a,long long n,long long p)
{
    if(n==1)
    {
        return a%p;
    }
    if(n%2==1)
    {
        return a*modpow(a,n-1,p)%p;
    }
    long long t = modpow(a,n/2,p);
    return t*t%p;
}
 
//O(K)でnCkを求める
int comb( int N, int K ){
  int X = 1; //分子
  int Y = 1; //分母
  for( int i = N; i > N-K; i-- ){
    X = (X*i)%MOD;
  }
  for( int i = 1; i <= K; i++ ){
    Y = (Y*i)%MOD;
  }
  return X * modpow(Y, MOD-2, MOD)%MOD;   //Aの逆元を取る場合、modpow(A, MOD-2, MOD) https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a 3-4参照
}

int main()
{
    /*A
    int n,m;
    cin>>n>>m;
    int count;
    count = (n*(n-1)/2+m*(m-1)/2);
    cout<<count<<endl;
    */

    /*B
    string s;
    cin>>s;
    int n = s.size();
    bool flag = true;
    for(int i=0;i<n/2;i++)
    {
        if(s[i]!=s[n-1-i])
        {
            flag = false;
        }
    }
    
    for(int i=0;i<(n-1)/2;i++)
    {
        if(s[i]!=s[(n-1)/2-(i+1)])
        {
            flag = false;
        }
    }
    for(int i=(n+3)/2;i<n;i++)
    {
        if(s[i]!=s[n-(i+1)])
        {
            flag = false;
        }
    }

    if(flag)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    */
    /*
    int l;
    cin>>l;
    double a;
    a = (double) l/3;

    cout<<setprecision(12)<<a*a*a<<endl;
    */

    int n;
    cin>>n;
    vector <int> a(n);
    rep(i,n)
    {
        cin>>a[i];
    }
    rep(i,n)
    {
        a[i]--;
    }
    vector <int> cnt(n);
    rep(i,n)
    {
        cnt[a[i]]++;
    }
    ll sum = 0;
    rep(i,n)
    {
        sum+=choose2(cnt[i]);
    }
    rep(i,n)
    {
        ll ans = sum;
        ans-=choose2(cnt[a[i]]);
        ans+=choose2(cnt[a[i]]-1);
        cout<<ans<<endl;;
    }


    return 0;
}

Measured memory_bytes: 4096
#include <stdio.h>

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

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

int main(){
  int n;
  cin >> n;
  
  vector<int> l(n);
  int sum = 0 ;
  for ( int i = 0 ; i < n ; i++ ){
  	cin >> l.at(i);
    sum += l.at(i);
  }
  
  sort(l.begin(),l.end());
  int max_l = l.at(n-1);
  if ( max_l < sum - max_l )
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

#define ll long long
#define vi vector<int>
#define vll vector<long long> 
#define str string 
#define ch char
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair

ll dp[1001][1001];
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int h, w;
    cin>>h>>w;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            ch c;
            cin>>c;
            if(c=='#'){
                dp[i][j] = -1;
            }
        }
    }
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if((i==0)&&(j==0)){
                dp[i][j]=1;
                continue;
            }
            if(dp[i][j]!=-1){
                if((i==0)&&(j>0)){
                    if(dp[i][j-1]!=-1 && dp[i][j-1]!=0){
                        dp[i][j]=1;
                    }
                }
                else if(j==0&&i>0){
                    if(dp[i-1][j]!=-1 && dp[i-1][j]!=0){
                        dp[i][j]=1;
                    }
                }
                else{
                    ll sum = dp[i-1][j] + dp[i][j-1];
                    if(dp[i-1][j]==-1) sum+=1;
                    if(dp[i][j-1]==-1) sum+=1;
                    dp[i][j] = sum % 1000000007;
                }
            }
        }
    }
    cout<<dp[h-1][w-1]%(1000000000 + 7);
}



Measured memory_bytes: 11384
import sys
X,Y = map(str,input().split())

list = ['A','B','C','D','E','F']
if X not in list or Y not in list:
    sys.exit()

if ord(X) < ord(Y):
    print("<")
if ord(X) == ord(Y):
    print("=")
if ord(X) > ord(Y):
    print(">")


Measured memory_bytes: 9112
#include <iostream>

using namespace std;

int main(int argc, const char *argv[])
{
  int r, d, x;
  cin >> r >> d >> x;
  for (int i = 2001; i <= 2010; i++) {
    x = r * x - d;
    cout << x << "\n";
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <iomanip>
#include <utility>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;

pair<int, int> p;
int a[31];

int main()
{
	int w, n, r;
	cin >> w >> n;
	for (int i = 1; i < w + 1; i++)
		a[i] = i;
	for (int i = 0; i < n; i++)
	{
		scanf("%d,%d", &p.first, &p.second);
		r = a[p.first];
		a[p.first] = a[p.second];
		a[p.second] = r;
	}
	for (int i = 1; i < w + 1; i++)
	{
		cout << a[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3144
N = int(input())
A = []
B = []
for n in range(N):
  temp = int(input())
  A.append(temp)
  B.append(temp)
list.sort(A, reverse = True)
for n in range(N):
  if B[n] == A[0]:
    print(A[1])
  else:
    print(A[0])

Measured memory_bytes: 14120
#include <queue>
#include <cstdio>
using namespace std;
#define Maxn 50
int v[Maxn+5];
int n;
priority_queue<double,vector<double>,greater<double> > q;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&v[i]);
		q.push(v[i]*1.0);
	}
	double x,y;
	while((int)q.size()>1){
		x=q.top();
		q.pop();
		y=q.top();
		q.pop();
		x+=y;
		x/=2;
		q.push(x);
	}
	printf("%.7lf\n",q.top());
	return 0;
}


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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

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

  ll m;
  cin >> m;

  cout << 48-m << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MAXN=100010;
int r,g,b,n;
inline int read(){
    int f=1,x=0;
    char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
    return f*x;
}
ll ans;
int main(){
    r=read();g=read();b=read();n=read();
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            if((n-(i*r+j*g))%b==0&&n>=(i*r+j*g)){
                ans++;
                //cout<<i<<" "<<j<<endl;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
# input = sys.stdin.readline

def resolve():
    N,M=map(int,input().split())
    l, r = map(int, input().split())
    for i in range(1,M):
        ll,rr=map(int,input().split())
        l=max(l,ll)
        r=min(r,rr)

    print(r-l+1 if r-l+1>=0 else 0)


resolve()

Measured memory_bytes: 46696
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    int n; cin >> n;
    vector<int> x(n+1,0);

    if(n==1){
        cout << 1 << endl;
        return 0;
    }

    for(int i=2; i<=n; i++){
        int num = i;
        for(int j=2; j<=i; j++){
            while(num%j==0){
                x.at(j)++;
                num/=j;
            }
        }
    }

    ll ans = 1;
    ll mod = 1e9+7;
    for(int i=2; i<=n; i++){
        ans *= x.at(i)+1;
        ans %= mod;
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
const int INF = 2e9;
 
int main(){
    int n, m, k[11], p[11], s[11][11];
    cin >> n >> m;
    for(int i=0; i<m; i++){
        cin >> k[i];
        for(int j=0; j<k[i]; j++){
            cin >> s[i][j];
            s[i][j]--;
        }
    }
    for(int i=0; i<m; i++){
        cin >> p[i];
    }
    int ans = 0;
    for(int bit=0; bit<(1<<n); bit++){
        int count = 0;
        for(int i=0; i<m; i++){
            int sum = 0;
            for(int j=0; j<k[i]; j++){
                if(bit & (1<<s[i][j])){
                    sum++;
                }
            }
            if(sum%2==p[i]){
                count++;
            }
        }
        if(count==m){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
	using namespace std;
	#define sim template < class c
	#define ris return * this
	#define dor > debug & operator <<
	#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
	sim > struct rge { c b, e; };
	sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
	sim > auto dud(c* x) -> decltype(cerr << *x, 0);
	sim > char dud(...);
	struct debug {
	#ifdef LOCAL
	~debug() { cerr << endl; }
	eni(!=) cerr << boolalpha << i; ris; }
	eni(==) ris << range(begin(i), end(i)); }
	sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
	}
	sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
	}
	#else
	sim dor(const c&) { ris; }
	#endif
	};
	#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
	#define lel debug()
	#define kek(...) lel << " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
	#define ll long long
	#define all(x) (x).begin(), (x).end()
	extern ll mod;
	ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} 
	// 
using namespace std;
const int N = 400005;
ll mod = 1e9 + 7;


int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int x, y, z;
	cin >> x >> y >> z;
	cout << z << " " << x << " " << y << endl; 
	return 0;
}

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

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>

typedef long long ll;
typedef unsigned long long ull;

#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)

const double INF = 1e+09;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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


int main(void){
  ios::sync_with_stdio(false);

  int n, k, c;
  cin >> n >> k >> c;

  string s;
  cin >> s;
  vector<int> l, r;
  int before_work_day = -INF;
  REP(i, n){
    if (s[i] == 'o' and i - before_work_day > c){
      l.push_back(i+1);
      before_work_day = i;
    }
  }
  int after_work_day = INF;
  REP(i, n){
    if (s[n-i-1] == 'o' and after_work_day - n + i  + 1> c){
      r.push_back(n-i);
      after_work_day = n-i-1;
    }}
  sort(r.begin(), r.end());
  int size = l.size();
  vector<ll> ans;
  if (l.size() == k || r.size() == k){
  REP(i, size){
    if (l[i] == r[i])ans.push_back(l[i]);
  }}

  for(ll x : ans){cout << x << endl;}

  return 0;
}



Measured memory_bytes: 5000
#include<iostream>
#include <functional>
#include <algorithm>
#include<cstdint>
using namespace std;
#define MAX 100 // 最大の個数
#define PATURN 4 // 重さの種類
// int W:バッグの容量
// int w:今バッグに入れている物の重さ
// int wm:一個目の物の重さ
// int ws[x]:x番目の重さの物の個数
// int s[x][y]:x番目の重さの物の中でy番目に価値が高い物までの価値の総和
// int c:今入れようとしている重さ
// int v:現在までにバッグに入れた物の価値の総和
int knapsack(int W, int w, int wm, int *ws, int s[][MAX+1], int c, int v) {
	int ret = v;
	if (c >= PATURN) return v; // 範囲外ならv返す
	for (int i = 0;i <= ws[c];i ++) { // 重さwm+cをi個かばんに入れてみる
		if (w + (wm + c) * i > W) break; // 入らなかったら諦める
		ret = max(ret, knapsack(W, w + (wm + c) * i, wm, ws, s, c + 1, v + s[c][i])); // 入るようなら、その時更にもっと重い荷物にトライ
	}
	return ret; // 既に0~c-1までの荷物を入れ終わっていて重さwのとき、その後最善手を打った時の価値の最大値
}
int main() {
	int n, w, wm, ws[PATURN], wv[PATURN][MAX], wc, s[PATURN][MAX + 1];
	for (int i = 0;i < PATURN;i ++) {
		ws[i] = 0;
	}
	cin >> n >> w;
	cin >> wm >> wv[0][0];
	ws[0] ++;
	for (int i = 1;i < n;i ++) {
		cin >> wc;
		cin >> wv[wc - wm][ws[wc - wm]]; // 重さごと(=4種類)に別々に価値を記録する
		ws[wc - wm] ++;
	}
	for (int i = 0;i < PATURN;i ++) {
		sort(wv[i], wv[i] + ws[i], greater<int>()); // 各重さで価値の高い順に並べる
		s[i][0] = 0;
//		cout << i + wm << "(" << ws[i] << "):0";
		for (int j = 0;j < ws[i];j ++) {
			s[i][j + 1] = s[i][j] + wv[i][j]; // 累積和。価値の高い順に足している
//			cout << "," << s[i][j + 1];
		}
//		cout << endl;
	}
	cout << knapsack(w, 0, wm, ws, s, 0, 0); // 答えて終了
}

Measured memory_bytes: 256
n = int(input())
x = []
u = []
for i in range(n):
    a,b = input().split()
    x.append(float(a))
    u.append(b)

s = 0    
for j in range(n):
    if u[j] == 'JPY':
        s += x[j]
    else:
        s += x[j] * 380000
print(s)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define f first
#define s second
#define _ << ' ' <<
#define int long long

using namespace std;

int mod = 1e9 + 7;

vector<int> f(1e7, 1);

int predp(){
    for(int i = 1; i < 1e7; i++)
        f[i] = f[i - 1] * i % mod;
}

int pw(int x, int y){
    if(y == 0) return 1;
    if(y % 2 == 0) return pw(x * x % mod, y / 2);
    return pw(x, y - 1) * x % mod;
}

int obr(int c){
    return pw(c, mod - 2);
}

void solve() {
    predp();
    int x, y;
    cin >> x >> y;
    if((2 * x - y) % 3 != 0){
        cout << 0;
        return;
    }
    int b = (2 * x - y) / 3;
    int a = x - b * 2;
    if(a < 0 || b < 0){
        cout << 0;
        return;
    }
    cout << f[a + b] * obr(f[a]) % mod * obr(f[b]) % mod;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}







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

int main(){
        int h, w;
        scanf("%d %d", &h, &w);

        vector<string> flg(h);
        for(int i=0; i<h; i++) cin>>flg[i];

        int wbr[h][3] = {0};
        for(int i=0; i<h; i++){
                for(int j=0; j<w; j++){
                        if(flg[i][j]=='W')wbr[i][0]++;
                        if(flg[i][j]=='B')wbr[i][1]++;
                        if(flg[i][j]=='R')wbr[i][2]++;
                }
        }
        for(int i=1; i<h; i++)for(int j=0; j<3; j++) wbr[i][j]+=wbr[i-1][j];

        int ans = 1e9;
        for(int i=0; i<h-2; i++){
                for(int j=i+1; j<h-1; j++){
                        int white = wbr[i][0], blue = wbr[j][1]-wbr[i][1], red = wbr[h-1][2]-wbr[j][2];
                        ans = min(ans, h*w - white - blue - red);
                }
        }
        printf("%d\n", ans);
        return 0;
}


Measured memory_bytes: 3292
#include<bits/stdc++.h>
 
using namespace std;
 
int n, a[200020], w[1000010], in[1000010];
int MOD = 998244353;
vector<int> num[1000010];
vector<int> List[1000010];
 
int addMod(int x, int y) {
    return ((x + y) >= MOD ? x + y - MOD : x + y);
}
 
int subMod(int x, int y) {
    return ((x - y) < 0 ? x - y + MOD : x - y);
}
 
int mulMod(int x, int y) {
    return (int) (((long) x * y) % MOD);
}
 
int powMod(int x, long p) {
    if (p == 0) return 1;
    int t = powMod(x, p / 2);
    if ((p & 1) == 1)
        return mulMod(mulMod(t, t), x);
    return mulMod(t, t);
}
 
int inv(int x) {
    return powMod(x, MOD - 2);
}
 
int cal(vector<int> v) {
    int res = 0;
    int sum[v.size() + 1];
    sum[0] = 0;
    for (int i = 1; i <= v.size(); i++){
        sum[i] = 0;
        sum[i] = addMod(sum[i - 1], v[i - 1]);
    }
    for (int i = 1; i <= v.size(); i++)
        res = addMod(res, mulMod(v[i - 1], subMod(sum[v.size()], sum[i])));
    return res;
}
 
int main(){
    cin >> n;
    in[1] = 1;
    for (int i = 2; i <= 1000000; i++) {
        in[i] = mulMod((MOD - MOD / i), in[MOD % i]);
    }

    for(int i = 1; i <= n; i++) 
        cin >> a[i];
    
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j * j <= a[i]; j++) {
            if(a[i] % j == 0) {
                num[j].push_back(a[i]);
                if(a[i]/j != j){
                    num[a[i]/j].push_back(a[i]);
                }           
            }
        }
    }
    for (int i = 1; i <= 1000; i++)
        for (int j = i * i; j <= 1000000; j += i) {
            List[j].push_back(i);
        }

    w[1] = 1;
    for (int i = 2; i <= 1000000; i++) {
        int sum = 0;
        for (int j : List[i]) {
            sum = addMod(sum, w[j]);
            if (i / j != j) {
                sum = addMod(sum, w[i / j]);
            }
        }
        w[i] = subMod(in[i], sum);
    }
  
    
    int ans = 0;
    for(int i = 1; i <= 1000000; i++) if(num[i].size() != 0){
        ans = addMod(ans, mulMod(w[i], cal(num[i])));
    }
    cout << ans << "\n";
}   

Measured memory_bytes: 156628
#include<bits/stdc++.h>
using namespace std;
bool check(string &str, int st ,int end)
{
	while(st <= end)
	{
		if(str[st] != str[end])
			return false;
		st ++;
		end--;
	}
	return 1;
}
int main(){
	string str;
	cin >> str;
	int n = str.size();
	bool flag = check(str, 0 , n-1) && check(str , 0 , (n/2)-1) && check(str,(n/2)+1, n-1);
	if(flag)
		cout<<"Yes\n";
	else
		cout<<"No\n";
}	

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

int N,R,S,P,K;
int score;
string T,ans;

string multiK(int k) {
    string multiString = T.substr(k,1);
    rep (i, (N-k)/K) {
        multiString = multiString + T.substr(k+K*(i+1),1);
    }
    return multiString;
}

int main() {
    cin >> N >> K;
    cin >> R >> S >> P;
    cin >> T;

    rep (i, N) {
        if (T.substr(i,1) == "r") {
            ans = ans + "p";
            score = score + P;
        } else if (T.substr(i,1) == "s") {
            ans = ans + "r";
            score = score + R;
        } else if (T.substr(i,1) == "p") {
            ans = ans + "s";
            score = score + S;
        }
    }

    rep (i, K) {
        string M = multiK(i);
        rep (j, M.size()) {
            if (M.substr(j,1) == M.substr(j+1,1)) {
                if (M.substr(j,1) == "r") {
                    score = score - P;
                } else if (M.substr(j,1) == "s") {
                    score = score - R;
                } else if (M.substr(j,1) == "p") {
                    score = score - S;
                }
                j++;
            }
        }
    }
    cout << score << endl;
}


Measured memory_bytes: 776
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
#include<functional>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	REP(i, n) cin >> a[i];
	bitset<40> bi(0);
	for(ll i = 39; i >= 0; i--) {
		ll cnt1 = 0, cnt2 = 0;
		REP(j, n) {
			bitset<40> bi2(a[j]);
			if(bi2[i]) cnt1++;
			else cnt2++;
		}
		if(cnt1 > cnt2) bi[i] = 0;
		else {
			bi[i] = 1;
			if(bi.to_ullong() > k) bi[i] = 0;
		}
	}
	ll num = bi.to_ullong();
	ll ans = 0;
	REP(i, n) ans += num ^ a[i];
	cout << ans << endl;
	return 0;
}

/* --------------------------------------- */


Measured memory_bytes: 1024
import java.util.*;

public class Main{
    
    public static final int MOD = (int)1e9+7;
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int r = Integer.parseInt(sc.next());
        int g = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int n = Integer.parseInt(sc.next());
        
        int ans = 0;
        for(int i=0; i<=3000; i++){
            for(int j=0; j<=3000; j++){
                int tmp = n - (r*i + g*j);
                if(tmp >= 0 && tmp%b==0){
                    ans++;
                }
            }
        }
        
        System.out.println(ans);
    }
    
}


Measured memory_bytes: 23892
#include <iostream>
#include <string>//
#include <vector>//
#include <map>
#include <cstdlib>
#include <numeric>
#include <algorithm>//ソート等に使用
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <thread>///////////////////
#include <queue>//幅優先等のキュー
#include <stack>
#include <bitset>

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

#define MOD 1000000007
//#define MOD 998244353
#define MAX 

using namespace std;

using ll = long long int;
using ld = long double;
using std::swap;

vector<int> v;
vector<int> w;
vector<long long int> vll;
vector<long long int> wll;
//vector<vector<int>> vec(50, vector<int>(4, 0));
vector<vector<int>> vv;
vector<vector<int>> ww;
//vector<char> vc;
vector<string> vs;



int main() {
	int n;
	cin >> n;
	vector<bitset<30>> vbi(n);
	bitset<30> tot(0);
	rep(i, 0, n) {
		int x; cin >> x;
		bitset<30> bi(x);
		vbi[i] = bi;
		tot = tot ^ bi;
	}
	rep(i, 0, n) {
		vbi[i] = tot ^ vbi[i];
		cout << vbi[i].to_ulong() << '\n';
	}
	return 0;
}

Measured memory_bytes: 4848
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define watch(x) cout << #x << " is " << x << endl;
#define print(a, l, r)          \
	for (int i = l; i < r; i++) \
		cout << a[i] << (i == (r - 1) ? endl : " ");
const long long M = 1000000007;
int main()
{

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

	long long n, m;
	cin >> n >> m;

	map<int, vector<int>> mp;
	for (int i = 0; i < n; i++)
	{
		int a, b;
		cin >> a >> b;
		mp[a].push_back(b);
	}
	long long ans = 0;
	priority_queue<int> que;
	for (int i = 1; i <= m; i++)
	{
		for (auto j : mp[i])
		{
			que.push(j);
		}
		if (!que.empty())
		{
			ans += que.top();
			/* 	cout << (que.top()) << endl; */
			que.pop();
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 10880
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = a;i < n;i++)
	
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
	int n;
	double t,a,memo,ans_n = 0,ans = 0;
	cin >> n >> t >> a;
	int h[n];
	
	rep(i,0,n){
		cin >> h[i];
		memo = t - (double)h[i]*0.006;
		if(i == 0){
			ans_n = 1;
			ans = memo;
		}
		else if(abs(a-ans) > abs(a-memo)){
			ans_n = i+1;
			ans = memo;
		}
	}
	
	cout << ans_n << endl;
	
  	return 0;
}





Measured memory_bytes: 384
#include <iostream>
static const int INFNTY = 1e9 + 1;
using namespace std;

int main(){
  int n, k;

  cin >> n >> k;
  int h[n];
  int dp[n];
  for (int i = 0; i < n; i++) {
    cin >> h[i];
    dp[i] = INFNTY;
  }

  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);

  for (int i = 2; i < n; i++) {
    for (int j = 1; (j <= i) && (j <= k); j++) {
      dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
    }
  }
  cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();

		int N = Integer.parseInt(W);

		String S = in.readLine();

		//各文字の発生位置の格納
		ArrayList<Integer>[] list = new ArrayList[10];
		for(int i = 0;i<10;i++){
			list[i] = new ArrayList<Integer>();
		}

		for(int i=0;i<N;i++){
			list[S.charAt(i)-'0'].add(i);
		}
		HashMap<String,Boolean> map = new HashMap<String,Boolean>();
		String find ;
		int indx1 = -1;
		int indx2 = -1;
		int indx3 = -1;

		for(int i1=0;i1<10;i1++){
			if(list[i1].size()==0){
				continue;
			}
			indx1 = list[i1].get(0);
			for(int i2=0;i2<10;i2++){
				indx2=-1;
				//2桁目の値を探す
				for(int k = 0;k<list[i2].size();k++){
					if(indx1 < list[i2].get(k)){
						indx2 = list[i2].get(k);
						break;
					}
				}
				if(indx2 == -1){
					continue;
				}

				for(int i3=0;i3<10;i3++){
					indx3=-1;
					//3桁目の値を探す
					for(int k = 0;k<list[i3].size();k++){
						if(indx2 < list[i3].get(k)){
							indx3 = list[i3].get(k);
							break;
						}
					}
					if(indx3 != -1){
						find = S.substring(indx1,indx1+1)+S.substring(indx2,indx2+1)+S.substring(indx3,indx3+1);
						map.put(find, true);
						continue;
					}
				}
			}
		}

		System.out.println(map.keySet().size());



	}


}


Measured memory_bytes: 25908
#include <bits/stdc++.h>
 
using namespace std;
 
#define pii pair<int,int>
#define ll long long
#define s second
#define f first
 
double r;
 
int main(){
  cin >> r;
  cout << setprecision(10) << r*2*acos(-1) << endl;
  return 0;
}

Measured memory_bytes: 3800
while True:
    n = int(input())
    if not n:
        break
    m = int(input())
    li = [[] for _ in range(n + 1)]
    for _ in range(m):
        a, b = [int(i) for i in input().split()]
        li[a].append(b)
        li[b].append(a)
    ans = set()
    for i in li[1]:
        ans.add(i)
        for j in li[i]:
            ans.add(j)
    if 1 in ans:
        ans.remove(1)
    print(len(ans))



Measured memory_bytes: 5980
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  string S;
  cin >> S;
  if(S == "ARC") cout << "ABC" << endl;
  else cout << "ARC" << endl;
  return 0;
}


Measured memory_bytes: 3628
def main():
    n = int(input())
    INF = 10 ** 12
    dp = [INF] * (n + 1)
    dp[0] = 0

    for i in range(1, n + 1):
        dp[i] = min(dp[i], dp[i - 1] + 1)
        j = 6
        while True:
            if i - j < 0:
                break
            dp[i] = min(dp[i], dp[i - j] + 1)
            j *= 6
        k = 9
        while True:
            if i - k < 0:
                break
            dp[i] = min(dp[i], dp[i - k] + 1)
            k *= 9

    print(dp[-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 74216
arr =[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5,
      1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

K = int(input())

print(arr[K - 1])

Measured memory_bytes: 3060
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

int main(void){
    int n, k;
    std::cin >> n >> k;
    std::vector<bool> v(n, true);
    for(int i = 0; i < k; ++i){
        int d;
        std::cin >> d;
        for(int j = 0; j < d; ++j){
            int a;
            std::cin >> a;
            if(v[a - 1]) v[a - 1] = false;
        }
    }
    k = 0;
    for(int i = 0; i < v.size(); ++i) if(v[i]) ++k;
    std::cout << k << std::endl;

    return 0;
}

Measured memory_bytes: 3616
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    int n,k;cin>>n>>k;
    int num=1;
    for(int i=0;i<n;i++){
        num = min(num*2, num+k);
    }
    cout<<num<<endl;
}


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
M=1000
K=0
S=False
for i in range(N-1):
    
    if S==False:
        if A[i]<A[i+1]:
            temp=0
            temp=M//A[i]
            M-=temp*A[i]
            K+=temp
            S=True
            
    else:
        if A[i]>A[i+1]:
            M+=K*A[i]
            K=0
            S=False
M+=K*A[i+1]
        
print(M)


Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }



int main() {
	IOS;
	ll n, a, b;
	cin >> n >> a >> b;
	ll c = b - a;
	ll res;
	if (c % 2 == 0) {
		res = c / 2;
	} else {
		ll tmp = min(a - 1, n - b);
		ll tmp2 = max(a - 1, n - b);
		res = tmp+1;
		res += c / 2;
	}
	put(res);
	return 0;
}

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

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

  int N, M;
  cin >> N >> M;

  const int ZERO = 3 * N + 2;
  vector<vector<int>> dp(3 * N + 1, vector<int>(6 * N + 10));

  dp[3 * N][ZERO] = 1;
  for (int i = 3 * N; i > 0; i--) { // construct P backwards
    for (int j = 0; j < 6 * N + 5; j++) {
      dp[i - 1][j + 1] = (dp[i - 1][j + 1] + dp[i][j]) % M; // Make block of size 1 (highest)
      if (i >= 2 && j >= 1) {
        // Make block of size 2 (the first element is the highest, the second one is free), 
        // put it after a block 1
        dp[i - 2][j - 1] = (dp[i - 2][j - 1] + (1ll * (i - 1) * dp[i][j] % M)) % M; 
      }
      if (i >= 3) {
        dp[i - 3][j] = (dp[i - 3][j] + (1ll * (i - 1) * (i - 2) % M * dp[i][j] % M)) % M; // Make block of size 3
      }
    }
  }

  int ans = 0;
  for (int i = ZERO; i < 6 * N + 5; i++) {
    ans = (ans + dp[0][i]) % M;
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 284888
import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
     
    public class Main {
     
    	public static void main(String[] args) throws IOException, Exception{
    		BufferedReader st = new BufferedReader(new InputStreamReader(System.in));
    		long n = getInt(st);
    		long t = n*(n-1)/2;
    		System.out.println(t);
    	}
     
    	private static int getInt(BufferedReader st) throws Exception, IOException {
    		int num = Integer.parseInt(st.readLine());
    		return num;
    	}
    }

Measured memory_bytes: 23124