akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int main(void){
    ll n, a;
    cin >> n >> a;
    if (n % 500 <= a) cout << "Yes";
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()
A = []
B = []
for i in range(N):
    A.append(s())
for i in range(M):
    B.append(s())

for i in range(N-M+1):
    col = A[i].find(B[0])
    if col >= 0:
        found = True
        for j in range(1, M):
            if A[i+j][col:col+M] != B[j]:
                found = False
                break
        if found:
            print('Yes')
            import sys
            sys.exit()

print('No')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
using ll = long long;
int main(){ 
    ll n;
    cin>>n;
    vector<ll> a(n);
    REP(i,n) cin>>a[i];
    ll b=0,c=0,d=0;
    for(int i=c;i<n-1;i++){
        if(a[i]>=a[i+1]){
            b++;
        }else{
         d=max(d,b);
         b=0;
         c=i+1;
        }
    }
  d=max(d,b);
    cout<<d;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
using namespace std;
int n, m, d[1009], c[1009], dp[1009][1009];
int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) cin >> d[i];
	for (int i = 0; i < m; i++) cin >> c[i];
	fill(dp[0] + 1, dp[0] + n + 1, 999999999);
	for (int i = 1; i <= m; i++) {
		for (int j = 0; j <= n; j++) {
			dp[i][j] = dp[i - 1][j];
			if (j >= 1) dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + c[i - 1] * d[j - 1]);
		}
	}
	cout << dp[m][n] << endl;
	return 0;
}

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

int main()
{
    vector<vector<int>> data(3, vector<int>(3));

    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> data.at(i).at(j);
        }
    }

    if ((data.at(0).at(0) - data.at(0).at(1)) != (data.at(1).at(0) - data.at(1).at(1)))
    {
        cout << "No" << endl;
        return 0;
    }

    if ((data.at(0).at(1) - data.at(0).at(2)) != (data.at(1).at(1) - data.at(1).at(2)))
    {
        cout << "No" << endl;
        return 0;
    }

    if ((data.at(1).at(0) - data.at(2).at(0)) != (data.at(1).at(1) - data.at(2).at(1)))
    {
        cout << "No" << endl;
        return 0;
    }

    if ((data.at(1).at(1) - data.at(2).at(1)) != (data.at(1).at(2) - data.at(2).at(2)))
    {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int a,b;
    cin >> a >> b;
    if(a < b){
    cout << "a < b" << endl;
    }else if(a > b){
    cout << "a > b" << endl;
    }else if(a == b){
    cout << "a == b" << endl;
    }
    
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
typedef pair<int, int> pint;
#define mp make_pair

int main() {
    int n;
    cin >> n;
    vector<pint> red(n), blue(n);
    for (int i = 0; i < n; ++i) {
        cin >> red[i].second >> red[i].first;
    }
    for (int j = 0; j < n; ++j) {
        cin >> blue[j].first >> blue[j].second;
    }
    sort(red.rbegin(), red.rend());
    sort(blue.begin(), blue.end());
    int ans = 0;
    for (pint i : blue) {
        for (int j = 0; j < n; ++j) {
            if (i.first > red[j].second and i.second > red[j].first) {
                ans++;
                red[j] = mp(10000000, 100000000);
                sort(red.rbegin(), red.rend());
                break;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n,x;
  cin>>n>>x;
  int a[114514]={};
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  long long int ans=0;
  for(int i=1;i<n;i++){
    if(a[i]+a[i-1]>x){
		ans+=a[i]+a[i-1]-x;
      	a[i]=x-a[i-1];
      	if(a[i]<0){
			a[i-1]=-a[i];
          a[i]=0;
          ans+=-a[i];
        }
    }
  }
  cout<<ans<<endl;
}

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

int main(){
  int x;
  cin >> x;
  int mx = 1;
  for (int i = 1; i <= 40; i++) {
    int num = i;
    for (int j = 2; j <= 10; j++) {
      num *= i;
      if (num <= x) {
        mx = max(mx, num);
      } else break;
    }
  }
  cout << mx << endl;
  return 0;
}


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

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

  ll h;
  cin >> h;
  ll cnt = 0;
  ll nmon = 0;

  ll atk = 0;
  while (h > 0) {
    h /= 2;
    atk += pow(2, cnt);
    cnt++;
  }
  cout << atk;

  return 0;
}


Measured memory_bytes: 256
def r(val):
	v = val
	m = 1
	if val<0 : m=-1
	val = int(abs(val)*1000+0.51)*m
	return val/1000

def solve():
	[a,b,c,d,e,f] = list(map(int,input().split()))
	[x,y] = [e*c - b*f,a*f - c*d]
	di = a*e-b*d
	x /= di
	y /= di
	x = r(x)
	y = r(y)
	print("%.3f %.3f"%(x,y))


while True:
	try: solve()
	except: break

Measured memory_bytes: 7692
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

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

from heapq import heappush, heappop

t = n_in()

for _ in range(t):
    n = n_in()

    sheeps = []
    for i in range(n):
        k,l,r = l_in()
        sheeps.append((i,k-1,l,r))


    res = 0
    base = 0

    memo = []
    for i in range(n):
        memo.append(set())

    base = 0
    for i,k,l,r in filter(lambda x: x[2] > x[3], sheeps):
        memo[k].add(i)
        base += r

    res += base

    q = []
        
    for pos in range(n):
        for s in memo[pos]:
            _,k,l,r = sheeps[s]
            heappush(q, (l-r, s))

        while len(q) > pos+1:
            heappop(q)

    for delta, i in q:
        res += delta

        
    memo = [set() for _ in range(n+1)]

    base = 0
    for i,k,l,r in filter(lambda x: x[2] <= x[3], sheeps):
        memo[k+1].add(i)
        base += l

    res += base

    q = []
        
    for pos in reversed(range(n)):
        for s in memo[pos]:
            _,k,l,r = sheeps[s]
            heappush(q, (r-l, s))

        while len(q) > n-pos:
            heappop(q)
    for delta, i in q:
        res += delta

    print(res)

    
        


Measured memory_bytes: 177156
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long k = sc.nextLong();
    long[] a = new long[n];
    long ans = 0;
    long m = 0;
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextLong();
      m = Math.max(m, a[i]);
    }
    ans = m;
    long left = 1;
    long right = m;
    while(left < right) {
      long med = (left + right) / (long)2;
      long t = 0;
      for(int i = 0; i < n; i++) {
        t += (((a[i] + med - 1) / med) - 1);
      }
      if(t <= k) {
        ans = med;
        right = med;
      } else {
        left = med + 1;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 61048
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

string st;
int a;

void check(pair<int, int>p) {
	if (abs(p.first)>10000 || abs(p.second)>10000)throw(false);
}
pair<int, int>num() {
	if (st[a] == 'i') {
		a++;
		return make_pair(0,1);
	}
	else {
		int num=0;
		while (a != st.size() && isdigit(st[a])) {
			num*=10;
			num+=st[a]-'0';
			a++;
			if(num>10000000)throw(false);
		}
		
		auto ans=make_pair(num,0);
		check(ans);
		return ans;
	}
}
pair<int,int>calc();
pair<int, int>kkou() {
	if (st[a] == '(') {
		a++;
		auto now(calc());
		assert(st[a]==')');
		a++;
		check(now);
		return now;
	}
	else {
		auto now(num());
		check(now);
		return now;
	}
}
pair<int, int>kou() {
	auto now(kkou());
	check(now);
	while (a != st.size() && st[a] != '+'&&st[a] != '-'&&st[a] != ')') {
		assert(st[a]=='*');
		a++;
		auto p(kkou());
		auto next(now);
		next.first=now.first*p.first-now.second*p.second;
		next.second=now.first*p.second+now.second*p.first;
		check(next);
		now=next;
	}
	return now;
}
pair<int, int>calc() {
	auto now(kou());
	check(now);
	while (a != st.size()&&st[a]!=')') {
		assert(st[a]=='+'||st[a]=='-');
		bool is_minus=st[a]=='-';
		a++;
		auto p(kou());

		if (is_minus) {
			now.first-=p.first;
			now.second-=p.second;
		}
		else {

			now.first += p.first;
			now.second += p.second;
		}
		check(now);
	}
	return now;
}

int main() {
	while (cin>>st) {
		a=0;
		pair<int,int>ans;
		bool flag=true;
		try {
			ans=calc();
		}
		catch (...) {
			flag=false;
		}
		if (flag) {

			if (ans.first == 0) {
				if (ans.second == 0) {

					cout << 0 << endl;
				}
				else {
					cout<<ans.second<<'i'<<endl;
				}
			}
			else {
				if (ans.second == 0) {
					cout<<ans.first<<endl;
				}
				else {
					if (ans.second > 0) {
						cout<<ans.first<<'+'<<ans.second<<'i'<<endl;
					}
					else {
						cout<<ans.first<<ans.second<<'i'<<endl;
					}
				}
			}
		}
		else {
			cout<<"overflow"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long ll;

void test_case(){
    
}

int main() {
    ios::sync_with_stdio(false); cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    int s; 
    char c;
    vector< pair<int, char > > req;
    rng(i, 0, m){
		cin >> s >> c;
		req.push_back({s, c});
	}
	string res = "";
	rng(i, 0,n )
		res += 'a';
    
    bool flag = true;
    rng(i, 0, m){
		s = req[i].first;
		c = req[i].second;
		s--;
		
		if(res[s] != 'a' ){
			if(res[s] != c){
				res = "-1";
				i = m+1;
				flag = false;
				break;
			}
		}
		if( s == 0 && c == '0' && n != 1){
			res = "-1";
			break;
		}
		if(flag == true)
			res[s] = c;
	}
	if(res != "-1"){
		rng(i, 0, n){
			if( res[i] == 'a'){
				if( i == 0 && n == 1){
					res[i] = '0';
				}
				else if( i == 0 )
					res[i] = '1';
				else
					res[i] = '0';
			}
		}
	}
	cout<<res<<endl;
    
	return 0;
}






Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

int main(){
  int N; cin >> N;
  vector<int> b(N); rep(i,N) cin >> b[i];
  
  vector<int> a(N);
  bool possible = true;
  for (int i=N-1;i>=0;i--){
    bool check = false;
    for (int j=i;j>=0;j--){
      if (b[j]==j+1){
        a[i] = b[j];
        b.erase(b.begin()+j);
        check = true;
        break;
      }
    }
    if (check==false) {
      possible = false;
      break;
    }
  }
  if (possible==false) cout << -1 << endl;
  else {
    rep(i,N) cout << a[i] << endl;
  }




  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 3576
package main

import (
	"fmt"
	"math"
	"strconv"
)

func main() {
	var s string
	fmt.Scanln(&s)

	min := 1000
	for i := 0; i < len(s)-2; i++ {
		n, _ := strconv.Atoi(s[i : i+3])
		diff := int(math.Abs(float64(n - 753)))
		if diff < min {
			min = diff
		}
	}

	fmt.Println(min)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int x,y,n;
     map<string,int>mp;

     cin>>n;
     string s;
     while(n--)
     {
         cin>>s;
         mp[s]++;
     }
     cout<<"AC x "<<mp["AC"]<<endl;
     cout<<"WA x "<<mp["WA"]<<endl;
     cout<<"TLE x "<<mp["TLE"]<<endl;
     cout<<"RE x "<<mp["RE"]<<endl;


    return 0;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int64_t n, k;
  cin >> n >> k;
  std::vector<std::pair<int64_t, int64_t>> vec(n);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    vec[i] = std::make_pair(a, b);
  }
  std::sort(vec.begin(), vec.end());
  int64_t cum = 0;
  for (int i = 0; i < n; i++) {
    int64_t a, b;
    a = vec[i].first;
    b = vec[i].second;
    cum += b;
    if (cum >= k) {
      cout << a << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>

#define Maxn 200010
#define LL long long

using namespace std;

inline LL read() {
    LL x = 0, f = 1;
    char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while('0' <= c && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}

int n;
LL a[Maxn];

int cmp(LL fir, LL sec) {
    return fir > sec;
}

int main() {
    n = read();
    for(int i = 1; i <= n; ++i) a[i] = read();
    sort(a + 1, a + n + 1, cmp);
    LL ans = 0;
    for(int i = 1; i <= n; ++i) {
        if(i == 1) continue;
        else if(i == 2) ans += a[1];
        else ans += a[(i + 1) / 2];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5192
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <utility>
#include <functional>
#include <map>
#include <string>
#include <set>
#include <math.h>

using namespace std;

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

  int a, b;
  cin >> a >> b;

  cout << max({a + (a - 1), a + b, b + (b - 1)}) << endl;
}

Measured memory_bytes: 256
class Dice:
    def __init__(self, label):
        self.label = label.copy()
    
    def rotateS(self):
        """[1, 2, 6, 5] -> [5, 1, 2, 6]"""
        t = self.label[1]
        self.label[1] = self.label[5]
        self.label[5] = self.label[6]
        self.label[6] = self.label[2]
        self.label[2] = t

    def rotateN(self):
        t = self.label[1]
        self.label[1] = self.label[2]
        self.label[2] = self.label[6]
        self.label[6] = self.label[5]
        self.label[5] = t
    
    def rotateW(self):
        t = self.label[1]
        self.label[1] = self.label[3]
        self.label[3] = self.label[6]
        self.label[6] = self.label[4]
        self.label[4] = t
    
    def rotateE(self):
        t = self.label[1]
        self.label[1] = self.label[4]
        self.label[4] = self.label[6]
        self.label[6] = self.label[3]
        self.label[3] = t

    def rotateR(self):
        t = self.label[3]
        self.label[3] = self.label[2]
        self.label[2] = self.label[4]
        self.label[4] = self.label[5]
        self.label[5] = t

    def rotateL(self):
        t = self.label[3]
        self.label[3] = self.label[5]
        self.label[5] = self.label[4]
        self.label[4] = self.label[2]
        self.label[2] = t

def debugprint(dice1, dice2, label=''):
    debug=False
    if (debug):
        print(label)
        print('dice1: {}'.format(dice1.label))
        print('dice2: {}'.format(dice2.label))
        print('')

def compare(dice1, dice2):
    if (dice1.label == dice2.label):
        return True
    else:
        return False

def verify(dice1, dice2):
    dice_t = Dice(dice2.label)
    numS = 0
    for i in range(0,4):
        numR = 0
        for _ in range(0,4):
            debugprint(dice1, dice_t)
            if (compare(dice1, dice_t)):
                return True
            dice_t.rotateR()
            numR += 1
        #print(numR)
        dice_t.rotateS()
        numS += 1
    #print(numS)

    dice_t.rotateE()
    for _ in range(0,4):
        debugprint(dice1, dice_t)
        if (compare(dice1, dice_t)):
            return True
        dice_t.rotateR()

    dice_t.rotateE()
    dice_t.rotateE()
    for _ in range(0,4):
        debugprint(dice1, dice_t)
        if (compare(dice1, dice_t)):
            return True
        dice_t.rotateR()

    return False


## Main

label1 = []
label1.append(-1)
label1[1:] = map(int,input().split())
dice1 = Dice(label1)
#print(dice1.label)

label2 = []
label2.append(-1)
label2[1:] = map(int,input().split())
dice2 = Dice(label2)
#print(dice2.label)

debugprint(dice1, dice2, 'before rotate')

label1.sort()
label2.sort()
if (label1 != label2):
    print("No")
    exit()

if (verify(dice1, dice2)):
    print('Yes')
else:
    print('No')



Measured memory_bytes: 5628
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int IMAX=((1<<30)-1)*2+1;
const double EPS=1e-10;
//int mod=1000000007



string s;

int main(){
	for(int i=0; i<32; i++){
		if(i<26)s+=('A'+i);
		if(i==26)s+=(' ');
		if(i==27)s+='.';
		if(i==28)s+=',';
		if(i==29)s+='-';
		if(i==30)s+='\'';
		if(i==31)s+='?';
	}
	map<char,string> m;
	m[' ']="101";
	m['\'']="000000";
	m[',']="000011";
	m['-']="10010001";
	m['.']="010001";
	m['?']="000001";
	m['A']="100101";
	m['B']="10011010";
	m['C']="0101";
	m['D']="0001";
	m['E']="110";
	m['F']="01001";
	m['G']="10011011";
	m['H']="010000";
	m['I']="0111";
	m['J']="10011000";
	m['K']="0110";
	m['L']="00100";
	m['M']="10011001";
	m['N']="10011110";
	m['O']="00101";
	m['P']="111";
	m['Q']="10011111";
	m['R']="1000";
	m['S']="00110";
	m['T']="00111";
	m['U']="10011100";
	m['V']="10011101";
	m['W']="000010";
	m['X']="10010010";
	m['Y']="10010011";
	m['Z']="10010000";
	string t;
	while(getline(cin,t)){
		string u,ans;
		rep(i,t.size()){
			u+=m[t[i]];
		}
		while(u.size()%5!=0)u+='0';
		//cout<<u<<endl;
		for(int i=0; i<u.size(); i+=5){
			string v;
			int n=0;
			v=u.substr(i,5);
			//cout<<v<<"=";
			rep(j,5){
				n*=2;
				n+=(v[j]-'0');
				//cout<<n<<endl;
			}
			//cout<<n<<endl;
			ans+=s[n];
			//cout<<ans<<endl;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1196
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////

int main() {
	ll N;
	cin >> N;
	vll a(N + 1);
	repn(i, N) cin >> a[i];
	sort(++a.begin(), a.end());

	mint ans = a[1];
	repn(i, N - 1) {
		ans *= gcd(a[i + 1], i);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3988
N = int(input())
S = [input() for _ in range(N)]
S.sort()

res = 0
cnt = 1
for i in range(N-1):
    if S[i] == S[i+1]:
        cnt+=1
    else:
        res = max(res,cnt)
        cnt = 1

res = max(res,cnt)

cnt = 1
ans = []
for i in range(N-1):
    if S[i] == S[i+1]:
        cnt+=1
    else:
        if res == cnt:
            ans.append(S[i])
        cnt = 1

if cnt == res:
    ans.append(S[i+1])

for i in range(len(ans)):
    print(ans[i])


Measured memory_bytes: 25128
// https://atcoder.jp/contests/abc143/tasks/abc143_a

#include "algorithm"
#include "iostream"
#include "set"
#include "vector"
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

void solve() {
  ll A;
  ll B;
  cin >> A >> B;

  ll res = max(A - 2 * B, (ll)0);
  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, 0, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


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

int n;
string s, t;

int main() {
    cin >> n >> s >> t;
    if (s == t) { cout << "0" << endl; exit(0); }
    int up = n - 1, down = n - 1, ans = 0;
    queue<int> q;
    while (down >= 0) {
        while (down && t[down - 1] == t[down]) down--;
        while (up >= 0 && (up > down || s[up] ^ t[down])) up--;
        if (up < 0) { cout << "-1" << endl; exit(0); }
        while (!q.empty() && q.front() - q.size() >= down) q.pop();
        if (up ^ down) q.push(up);
        ans = max(ans, (int)q.size() + 1), down--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6280
import sys

# import re
import math
import collections
# import decimal
import bisect
# import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()

    ans = 0
    for i in range(1, int(n ** (1 / 2) + 1)):
        if n % i == 0:
            diff = n // i - n // (i + 1) - 1
            if diff * i >= i:
                ans += n // i - 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 64620
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

const ll MOD = 998244353;

vector<ll> sil(1000000);

ll Pot(ll a, ll b)
{
    if (b == 0)
        return 1;
    if (b % 2 == 0)
    {
        ll x = Pot(a, b / 2);
        return x * x % MOD;
    }
    else
        return Pot(a, b - 1) * a % MOD;
}

ll Inv(ll a)
{
    return Pot(a, MOD - 2);
}

ll C(ll n, ll k)
{
    return sil[n] * Inv(sil[n - k] * sil[k] % MOD) % MOD;
}

int main()
{
    ios_base::sync_with_stdio(0);
    sil[0] = 1;
    for (ll i = 1; i < 1000000; ++i)
        sil[i] = (sil[i - 1] * i) % MOD;
    ll n, a, b, k;
    cin >> n >> a >> b >> k;
    ll odp = 0;
    for (ll x = 0; x <= n; ++x)
    {
        if ((k - x * a) % b == 0 && k - x * a >= 0 && (k - x * a) / b <= n)
        {
            ll y = (k - x * a) / b;
            odp = (odp + C(n, x) * C(n, y)) % MOD;
        }
    }
    cout << odp;
    return 0;
}


Measured memory_bytes: 8064
import * as fs from 'fs';

const input = fs.readFileSync("/dev/stdin", "utf8").split(" ");
const d = +input[0];
const t = +input[1];
const s = +input[2];

const a = s * t;

if (d <= a) {
    console.log("Yes");
} else {
    console.log("No");
}


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

int main()
{
    string s;

    while(1){
        cin>>s;
        if(s=="-")
          break;
      
        int m;
        cin>>m;
        for(int i=0;i<m;i++){
            int wk;
            cin>>wk;
            string swk1,swk2;
            swk1=s.substr(0,wk);
            swk2=s.substr(wk,s.size()-wk);
            s=swk2+swk1;
        }
        cout<<s<<endl;
    }


    return 0;
}  


Measured memory_bytes: 3224
#include <stdio.h>
int main() {
	int d, nd, s;
	while (scanf(" %d", &d) != EOF) {
		s = 0;
		for (nd = 0; nd < 600; nd += d) {
			s += d * nd * nd;
		}
		printf("%d\n", s);
	}
	return 0;
}

Measured memory_bytes: 596
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<numeric>
#include<vector>
#include<tuple>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
typedef long long ll;
const int MOD = 1e9 + 7;
string a, b;
int s[8][8];
int main(void)
{
	int H, W,cnt=0;
	cin >> H >> W;
	FOR(i, 0, H) {
		FOR(k, 0, W) {
			char tes;
			cin >> tes;
			if (tes == '#')cnt++;
		}
	}
	if (cnt == H + W - 1)cout << "Possible" << endl;
	else cout << "Impossible" << endl;

	return 0;
}


Measured memory_bytes: 256
s = input()
s1 = s[:2]
s2 = s[2:]
li = ["01","02","03","04","05","06","07","08","09","10","11","12"]

if s1 in li and s2 in li:
    print("AMBIGUOUS")
elif s1 in li and not s2 in li:
    print("MMYY")
elif s2 in li and not s1 in li:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end(), greater<int>());
	int sum = accumulate(a.begin(), a.end(), 0);

	int count = 0;
	for (int i = 0; i < n; i++) {
		if (4 * m * a[i] < sum) continue;
		else count++;
	}
	cout << (m <= count ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define D 100000000
int main() {
	double a[1001], b[1001], c[2],min1=D,min2=D;
	int n,i2=0,i3=0;
	memset(a, 0, sizeof(a));
	memset(b, 0, sizeof(b));
	memset(c, 0, sizeof(c));
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	sort(a, a + n);
	for (int i = 1; i < n - 2; i++) {
		if (a[i] - a[i - 1] < min1) {
			min1 = a[i] - a[i - 1];
		}
	}
	for (int i = 1; i < n ; i++) {
		if (a[i] - a[i - 1] < min2) {
			min2 = a[i] - a[i - 1];
			b[i2] = 0; b[i3] = 0;
			i2 = i;
			i3 = i - 1;
			b[i2] = 1; b[i3] = 1;
		}
	}
	//cout << "kita" << endl;
	int j = 0;
	for (int i = n-1; i >-1; i--) {
		if (j == 2)break;
		if (b[i] == 0) {
			c[j] = a[i];
			j++;
		}
	}
	double SUM = max((a[n - 1] + a[n - 2]) / (double)min1, (c[0]+c[1])/ (double)min2);
	printf("%.5f\n", SUM);
}

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


int main(void){
 int H, W;
  cin >> H >> W;
  vector<string> s(H);
  for(int i = 0; i < H; i++){
    cin >> s[i];
  }
  int flag = 0;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(s[i][j] == '#'){
        if((i > 0 && s[i - 1][j] == '#')
           ||(i < H -1 && s[i + 1][j] == '#')
           ||(j > 0 && s[i][j - 1] == '#')
           ||(j < W - 1 && s[i][j + 1] == '#')){
             flag = 0;
           }
           else{
             cout << "No";
             return 0;
           }
      }       
    }
  }
  cout << "Yes";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 10000000;
typedef pair<int,int> P;
typedef long long ll;
/*Aの累積和を取り(s[i]=Aの第i-1項までの和とする),s[i] == s[j](i>j)なら
A[j]~A[i-1]までの部分和は0になるので、

*/

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  vector<int> sk(N);//Sのi文字目までの#の個数
  int count = 0;
  rep(i,N){
    if(S[i] == '#') count++;
    sk[i] = count;
  }
  

  vector<int> ss(N);//Sのi文字目までの.の個数
  int count2 = 0;
  rep(i,N){
    if(S[i] == '.') count2++;
    ss[i] = count2;
  }
  int ans = sk[N-1];
  rep(i,N){
    int res = sk[i-1] + ss[N-1]-ss[i-1];
    ans = min(res,ans);
  }
  ans = min(ans,ss[N-1]);
  cout << ans << endl;
}

Measured memory_bytes: 2180
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main(){
    cin>>a>>b;
    if(a>0) puts("Positive");
    else if(b>=0) puts("Zero");
    else if((a&1)^(b&1)) puts("Positive");
    else puts("Negative");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    cout << (a < 10 and b < 10 ? a * b : -1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;

using f80 = long double;
using i64 = long long;
using pii = pair<i64, i64>;

const f80 PI = 3.141592653589793238462643383279502884197169399375105820974L;

vector<pii> v;
vector<i64> lis;

int main() {
#ifdef HOME
	freopen("agc09c.in", "r", stdin);
	freopen("agc09c.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	f80 res;
	i64 x0, y0, x1, y1, tx, ty, n;
	int ant;

	cin >> x0 >> y0 >> x1 >> y1;

	tx = x0 > x1 ? -1 : 1;
	ty = y0 > y1 ? -1 : 1;

	x0*= tx, y0*= ty;
	x1*= tx, y1*= ty;

	cin >> n, v.resize(n);
	for (auto &i: v) {
		cin >> i.x >> i.y;
		i.x*= tx, i.y*= ty; }

	for (int i = 0; i < v.size(); ++i) {
		if (!(min(x0, x1) <= v[i].x && v[i].x <= max(x0, x1)) || !(min(y0, y1) <= v[i].y && v[i].y <= max(y0, y1))) {
			swap(v[i], v.back());
			v.pop_back();
			--i; } }

	sort(begin(v), end(v));
	lis = vector<i64>(n, 1e9);
	for (int i = 0; i < v.size(); ++i)
		*lower_bound(begin(lis), end(lis), v[i].y) = v[i].y;
	ant = lower_bound(begin(lis), end(lis), 1e9) - begin(lis);

	if (ant == 1 + min(abs(x0 - x1), abs(y0 - y1)))
		res = 100 * (abs(x1 - x0) + abs(y1 - y0)) + (ant - 1) * (10 * PI / 2.0 - 20) + (10 * PI - 20);
	else
		res = 100 * (abs(x1 - x0) + abs(y1 - y0)) + ant * (10 * PI / 2.0 - 20);

	cout << setprecision(20) << fixed;
	cout << res << endl;

	return 0; }


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

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

const ull mod = (ull)1e9 + 7;

int main(void)
{
	ll n, m;
	cin >> n >> m;
	vector<ll> vs(n);
	rep(i, n) cin >> vs[i];
	vector<ll> sums(n+1, 0);
	rep(i, n) {
		sums[i + 1] = sums[i] + vs[i];
		sums[i + 1] %= m;
	}
	map<ll, ll> cnt;
	ll sum = 0;
	for (int i = 1; i <= n; i++) {
		if (sums[i] == 0) {
			sum++;
		}
		sum += cnt[sums[i]];
		cnt[sums[i]]++;
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 5760
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N, W;
ll w[200], v[200];
ll dp[200][200][400];

int main() {
  std::cin >> N >> W;

  rep( i, N ) {
    std::cin >> w[i] >> v[i];
  }

  rep( i, N ) rep( j, i+1 ) rep( k, 400 ) {
    if( (k+w[i]-w[0])+w[0]*(j+1) <= W )
      chmax( dp[i+1][j+1][k+w[i]-w[0]], dp[i][j][k]+v[i] );

    chmax( dp[i+1][j][k], dp[i][j][k] );
  }

  ll ans = 0;

  rep( j, N+1 ) rep( k, 400 )
    chmax( ans, dp[N][j][k] );

  std::cout << ans << endl;

  return 0;
}

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

using ll = long long;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	ll a, b, c = 0;
	cin >> a >> b;
	for(; a <= b; a *= 2) c++;
	cout << c << endl;
}

Measured memory_bytes: 256
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//																				NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first 
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define LINF 98765432123456789
#define mod 1000000007
#define testcases() ll t; cin>>t; while(t--)
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
 
//----------------------------------------------------------------------------------------------------------------------------------------------------

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

		
			



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int ans,u,v,w,len;
string one[10],two[100],thr[1000],s;
string tmp;
map<string,bool>ex;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>len;
	for(char i='0';i<='9';++i)
	{
		u=i-'0';
		one[u]=i;
		for(char j='0';j<='9';++j)
		{
			v=j-'0';
			two[u*10+v]=one[u]+j;
			for(char k='0';k<='9';++k)
			{
				w=k-'0';
				thr[u*100+v*10+w]=two[u*10+v]+k;
			}
		}
	}
	cin>>s;
	for(int i=0;i<len;++i)
	{
		for(int j=0;j<100;++j)
		if(ex.count(two[j]))ex[(two[j]+s[i])]=1;
		for(int j=0;j<10;++j)
		if(ex.count(one[j]))ex[(one[j]+s[i])]=1;
		tmp=s[i];ex[tmp]=1;
	}
	for(int i=0;i<1000;++i)
	if(ex.count(thr[i]))ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>
// #include <fstream>
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(c) (c).begin(),(c).end()
#define SIZE(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define LB(c,x) lower_bound(ALL(c),x)
#define UB(c,x) upper_bound(ALL(c),x)
#define COUNT(c,x) (int)(UB(c,x)-LB(c,x))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

using namespace std;

typedef pair<int,int> P;
struct edge {
  int to, cost;
};

const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " ";
  }
  return s;
}


signed main()
{
  // string filename; cin >> filename;
  // ifstream in(filename);
  // cin.rdbuf(in.rdbuf());

  int N, K;
  cin >> N >> K;
  int ans;
  if (K % 2 == 0) {
    ans = (N/K) * (N/K) * (N/K) + ((N+K/2)/K) * ((N+K/2)/K) * ((N+K/2)/K);
  } else {
    ans = (N/K) * (N/K) * (N/K);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
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; }
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};

int main(){
  string S;
  cin>>S;
  ll ans=0;
  for(ll i=0;i<S.size();i++){
    if(i%2==0){
      if(S[i]=='p') ans--;
    }else{
      if(S[i]=='g') ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 512
N=int(input())
list=[]
for t in range(1,int(N**(1/2)+2)):
  if N%t==0:
    list+=[(t,int(N/t))]
mini=N+1
for (p,q) in list:
  if p+q<mini:
    mini=p+q
print(mini-2)

Measured memory_bytes: 3432
import numpy as np
N, M = map(int, input().split())
S = input().split()
T = np.array(input().split(), dtype = np.int32)
mod = 10 ** 9 + 7
dp = np.ones(M + 1, dtype = np.int64)
 
for s in S:
  dp[1:] = ((dp[:-1] * (T == int(s))).cumsum() + dp[1:]) % mod

print(dp[M])

Measured memory_bytes: 13460
def main():
    N,W = map(int, input().split())
    w,v = [0]*N,[0]*N
    for i in range(N):
        w[i],v[i] = map(int, input().split())
    # dp[i][w] := 容量をwとして荷物0~iの中から荷物を選んだ時の価値の最大値
    # 初期値dp[0][W] = 0の価値(もし0の重さがMAXを超えるなら選べない)
    dp = [[0]*(W+1) for i in range(N)]
    for x in range(W+1):
        dp[0][x] = 0 if w[0]>x else v[0]
    for i in range(N-1):
        for j in range(W+1):
            if w[i+1]<=j:
                # i+1番目を選ぶ
                dp[i+1][j] = max(dp[i+1][j], (dp[i][j-w[i+1]])+v[i+1])
            # i+1番目を選ばない
            dp[i+1][j] = max(dp[i+1][j], dp[i][j])
    print(dp[-1][W])

main()


Measured memory_bytes: 118512
#!/usr/bin/env python3
import sys


def solve(N: int, K: int):
    n = N % K
    for _ in range(100):
        n = min(n, abs(n - K))
    print(n)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

bool in(vll l, ll p){
    rep(i, l.size()) if(l[i]==p) return true;
    return false;
}

int main(){

    ll n, m, x; cin >> n >> m >> x;
    vll c(n);
    vvll a(n, vll(m));
    rep(i, n){
        cin >> c[i];
        rep(j, m){
            cin >> a[i][j];
        }
    }

    ll min_price = INF;
    rep(i, 1<<n){
        bitset<12> bs(i);
        vll skill(m, 0);
        ll price = 0;
        rep(j, n){
            if(bs.test(j)){
                price += c[j];
                rep(k, m){
                    skill[k] += a[j][k];
                }
            }
        }

        bool f = true;
        rep(k, m){
            if(skill[k]>=x){
                f &= true;
            }
            else{
                f &= false;
                break;
            }
        }
        if(f) min_price = min(min_price, price);
    }

    cout << (min_price==INF?-1:min_price) << endl;

    return 0;
}

Measured memory_bytes: 3632
// C++ includes used for precompiling -*- C++ -*-

// Copyright (C) 2003-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file stdc++.h
 *  This is an implementation file for a precompiled header.
 */

// 17.4.1.2 Headers

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long ll;

ll a, b, c, n, k, x;
string s;

int main()
{
  ll count = 0;
  cin >> a >> b >> c >> x;
  for (ll i = 0; i <= a; i++)
  {
    for (ll j = 0; j <= b; j++)
    {
      ll num = x - (500 * i) - (100 * j);

      if (num >= 0 && num % 50 == 0 && num / 50 <= c)
      {
        count++;
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
from collections import Counter, defaultdict


class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


S = input()
N = len(S)
C = Counter(S)
if len(S) % 2 == 0:
    for x in C.values():
        if x % 2 == 1:
            print(-1)
            exit()
else:
    cnt = 0
    for x in C.values():
        if x % 2 == 1:
            cnt += 1
        if cnt > 1:
            print(-1)
            exit()

cnt1 = 1
cnt2 = (N + 1) // 2 + 1
cnt_char = defaultdict(int)
seq = [0] * N
S1 = []
S2 = []
for i, s in enumerate(S):
    cnt_char[s] += 1
    if C[s] % 2 == 1:
        if cnt_char[s] == C[s] // 2 + 1:
            seq[i] = N // 2 + 1
            continue
    if cnt_char[s] <= C[s] // 2:
        seq[i] = cnt1
        cnt1 += 1
        S1.append(s)
    else:
        seq[i] = cnt2
        cnt2 += 1
        S2.append(s)
S2.reverse()

ans = 0
seq.reverse()
bit1 = Bit(N+1)
for i in range(N):
    ans += bit1.sum(seq[i])
    bit1.add(seq[i], 1)

char2idx = defaultdict(list)
for i, s1 in enumerate(S1):
    char2idx[s1].append(i+1)
for x in char2idx.keys():
    char2idx[x].reverse()

seq_ = []
for i, s2 in enumerate(S2):
    seq_.append(char2idx[s2].pop())

bit2 = Bit(N+1)
seq_.reverse()
for i in range(len(seq_)):
    ans += bit2.sum(seq_[i])
    bit2.add(seq_[i], 1)

print(ans)


Measured memory_bytes: 67660
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int a[100001];
int main(){
    int n,cnt=1;
    cin>>n;
    rep(i,n) cin>>a[i];
    int flag=-1;
    FOR(i,0,n-1){
        if(a[i]<a[i+1]){
            if(flag==0) ++cnt,flag=-1;
            else flag=1;
        }
        else if(a[i]>a[i+1]){
            if(flag==1) ++cnt,flag=-1;
            else flag=0;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	string s;
	cin >> s;
	int q;
	cin >> q;
	for (int i = 0; i < q; i++){
		string s1;
		cin >> s1;
		if (s1 == "print"){
			int a, b;
			cin >> a >> b;
			cout << s.substr(a, b-a+1) << endl;
		} else if (s1 == "reverse"){
			int a, b;
			cin >> a >> b;
			reverse(s.begin()+a, s.begin()+b+1);
		} else {
			int a, b;
			string p;
			cin >> a >> b >> p;
			s.replace(a, (int)p.size(), p);
		}
	}
}






Measured memory_bytes: 3184
// Aizu Vol-5 0522: JOI and IOI
// 2017.8.30 bal4u@uu

#include <stdio.h>

char s[10005];

int main()
{
	int joi, ioi;
	char *p;

	while (scanf("%s", s) != EOF) {
		p = s, joi = ioi = 0;
		while (*p) {
			if (*(p+1) == 'O' && *(p+2) == 'I') {
				if      (*p == 'J') joi++, p++;
				else if (*p == 'I') ioi++, p++;
			}
			p++;
		}
		printf("%d\n%d\n", joi, ioi);
	}
	return 0;
}

Measured memory_bytes: 548