akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define repa(i,a,n) for(int i=a;i<=n;i++)
#define repb(i,a,n) for(int i=a;i>=n;i--)
#define trav(a,x) for(auto a=x.begin();a!=x.end();a++)
#define all(x) x.begin(),x.end()
#define fst first
#define snd second
#define pb push_back
#define mp make_pair
typedef long double ld;
typedef pair <int,int> pii;
typedef vector <int> vi;
typedef long long ll;

vi v1;
int m,x;

void kar(vector<vector<int>> arr,int n){
  int cost=0,flag=0,ch=0;

  rep(i,m+1){
    ch=0;
    rep(j,n){
      if(i==0)
        cost+=arr[j][i];
      else
        ch+=arr[j][i];
    }
    if(i!=0){
      if(ch<x) flag=1;
    }
  }
  
  if(flag==0) v1.pb(cost);
}

void chalo(vector<vector<int>> arr,int index,vector<vector<int>> subarr){
  if(index==arr.size()){
    int l=subarr.size();
    if(l!=0)
      kar(subarr,l);
  }
  else{
    chalo(arr,index+1,subarr);
    subarr.pb(arr[index]);
    chalo(arr,index+1,subarr);
  }
  return;
}


void pre(){

}

void solve(){
  int n,temp; cin>>n>>m>>x;
  vector <vector<int>> arr;
  rep(i,n){
    vi lo;
    rep(j,m+1){
      cin>>temp;
      lo.pb(temp);
    }
    arr.pb(lo);
  }
  vector <vector<int>> b;
  chalo(arr,0,b);
  if(v1.size()==0) cout<<-1<<"\n";
  else{
    sort(all(v1));
    cout<<v1[0]<<"\n";
  }
}

int main(){
  #ifndef ONLINE_JUDGE
    // freopen("in.txt","r",stdin);
  #endif
  ios_base::sync_with_stdio(0); cin.tie(0);
  pre();
  int t; t=1;
  rep(i,t) solve();
  return 0;
}


Measured memory_bytes: 3704
N = int(input())

mastar_list = []
for i in range(2 ** N):
    x = "{:0" + str(N) + "b}"
    mastar_list.append(list(map(int,x.format(i))))


current = 1
ans = []
judge = [True for i in range(2 ** N)]
while current <= N:
    now = current -1
    loop_num = int(input())
    for i in range(loop_num):
        a,b = map(int,input().split())
        c = a - 1
        for index, situation in enumerate(mastar_list):
            if situation[now] == 1:
                if situation[c] == b:
                    pass
                else:
                    judge[index] = False
            else:
                pass
    current += 1

ans = []
for index, content in enumerate(judge):
    if content:
        ans.append(sum(mastar_list[index]))
        
print(max(ans))
    

Measured memory_bytes: 17000
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

int main(){
  string  S;
  cin >> S;
  ll T=S.size();
  while(T>0){
    if(T>=5  && S.substr(T-5,5)=="dream"){
      T-=5;
    }
    else if(T>=7 && S.substr(T-7,7)=="dreamer"){
      T-=7;
    }
    else if(T>=6 && S.substr(T-6,6)=="eraser"){
      T-=6;
    }
    else if(T>=5 && S.substr(T-5,5)=="erase"){
      T-=5;
    }
    else{
      cNO;
      return 0;
    }
  }
  cYES;
}

Measured memory_bytes: 512
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;

struct interval{
    int l , r;
    bool friend operator <(interval a , interval b){
        return a.r < b.r;
    }
};

int n;
int m;
int bit[N];
vector < interval > q;

void update( int k, long long v ) {
      if(k == 0)
        return;
      while (k <= n) {
        bit[k] += v;
        k += k & -k;
      }
}

long long query( int k ) {
      long long ret = 0;
      while(k > 0) {
        ret += bit[k];
        k -= k & -k;
      }
      return ret;
}


int main(){
    scanf("%d%d" , &n , &m);
    for(int i = 0; i < m; i++){
        int a , b;
        scanf("%d%d" , &a , &b);
        q.push_back({a , b});
    }
    int ans = 0;
    sort(q.begin() , q.end());
    for(int i = 0; i < m; i++){
        int cnt = query(q[i].r) - query(q[i].l);
        if(cnt == 0){
            ans++;
            update(q[i].r , 1);
        }
    }
    printf("%d\n" , ans);
}


Measured memory_bytes: 1524
# -*- coding: utf-8 -*-
"""
Created on Fri Jan 30 16:58:45 2015

@author: hirose
"""

#Branch on Condition - Circle in a Rectangle

n = map(int, raw_input().split())

W = n[0]
H = n[1]
x = n[2]
y = n[3]
r = n[4]

if(x>=r and y>=r and x<=W-r and y<=H-r):
    print "Yes"
else:
    print "No"

Measured memory_bytes: 4212
n=list(input())
pm=["+","-"]

for op1 in pm:
    for op2 in pm:
        for op3 in pm:
            s = n[0] + op1 + n[1] + op2 + n[2] + op3 + n[3]
            if eval(s) == 7:
                print(s + "=7")
                exit()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<stack>
#include<iostream>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define MOD 1000000007
#define vec(a) vector<int>a
using namespace std;


int main()
{
#ifndef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
	fastio
	ll n,r,i,j;
	cin>>n>>r;
	if(n<10)
		r=r+100*(10-n);
	cout<<r<<"\n";

	return 0;
}


Measured memory_bytes: 3588
class String
  def integer?
    true if Integer(self) rescue false
  end
end

loop do
    w = gets.chomp
    if w.eql?("-") then
        break
    end
    
    n = gets.chomp.to_i
    
    n.times do |i|
        p = gets.chomp.to_i
        k = w.slice!(0...p)
        w = w + k
    end

    print w, "\n"
end



Measured memory_bytes: 6884
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        int pow2 = (int)Math.pow(n,0.5);
        for(int i = pow2; i > 0; i--){
            long il = (long)i;
            if(n % i == 0){
               System.out.println((il-1) + (n/il)-1);
               return;
            } 
        }
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
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; }
const long long INF = 1LL << 60;

int main(){
vll result(0);
while(true){
  int H;
  cin >> H;
  if(H == 0) break;

  vvi a(H, vi(5, 0));
  for(int i = 0; i < H; i++){
    for(int j = 0; j < 5; j++){
      cin >> a.at(i).at(j);
    }
  }
  bool repflag;
  ll res = 0;
  do{
    vector<vector<bool>> flag(H, vector<bool>(5, false));
    repflag = false;

    for(int i = 0; i < H; i++){
      for(int j = 0; j <= 2; j++){
        if(a.at(i).at(j) != 0 && a.at(i).at(j) == a.at(i).at(j+1) && a.at(i).at(j) == a.at(i).at(j+2)){
          repflag = true;
          flag.at(i).at(j) = true; flag.at(i).at(j+1) = true; flag.at(i).at(j+2) = true;
        }
      }
    }

    for(int i = 0; i < H; i++){
      for(int j = 0; j < 5; j++){
        if(flag.at(i).at(j)){
          res += a.at(i).at(j);
          a.at(i).at(j) = 0;
        }
      }
    }

    for(int i = H-1; i >= 1; i--){
      for(int j = 0; j < 5; j++){
        if(a.at(i).at(j) == 0){
          for(int k = i-1; k >= 0; k--){
            if(a.at(k).at(j) != 0){
              a.at(i).at(j) = a.at(k).at(j);
              a.at(k).at(j) = 0;
              break;
            }
          }
        }
      }
    }


  }while(repflag);
  result.push_back(res);
}

for(auto x: result) cout << x << endl;

}


Measured memory_bytes: 3168
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int target = n;
		int sum = 0;
		while (target > 0) {
			sum += target % 10;
			target /= 10;
		}
		System.out.println(n % sum == 0 ? "Yes" : "No");
		sc.close();
	}
}

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

using namespace std;

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v; stringstream ss(s); string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}
#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }
void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);

	string s; ll k;
	cin >> s >> k;

	REPU(i, 0, s.size()) {
		k--;
		if (s[i] == '1') {
			if (k == 0) { puts("1"); return 0; }
		}
		else {
			printf("%c\n", s[i]);
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	
	int w, h, x, y, r;
	int up, down, right, left;
	
	scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);
	
	if((x < -100) || (x > 100)){
		printf("Error:X is out of Range(%d)", x);
	}else if((y < -100) || (y > 100)){
		printf("Error:Y is out of Range(%d)", y);
	}else if((w < 0) || (w > 100)){
		printf("Error:W is out of Range(%d)", w);
	}else if((h < 0) || (h > 100)){
		printf("Error:H is out of Range(%d)", h);
	}else if((r < 0) || (r > 100)){
		printf("Error:R is out of Range(%d)", r);
	}
	
	up = x + r;
	down = x - r;
	right = y + r;
	left = y - r;
	
	if((up > w) || (down < 0) || (right > h) || (left < 0)){
		puts("No");
	}else{
		puts("Yes");
	}
	
	return 0;
}

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

int main() {
   int a,b,c;
   cin >> a >> b >> c;
   if(a==b)cout<< c <<endl;
   if(b==c)cout << a <<endl;
   if(a==c)cout << b <<endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define speed_up ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ll long long
#define ara(A,N) sort(A,A+N)
#define rev(A,N) sort(A,A+N,greater<long long>())
using namespace std;
int main()
{
    speed_up;
    ll n, i;
    cin>>n;
    ll gcd = 0;
    while(n--)
    {
        cin>>i;
        gcd = __gcd(gcd, i);
    }
    cout<<gcd<<endl;



  return 0;
}



Measured memory_bytes: 3600
#include<stdio.h>
int main(void)
{
	int i=0,j=0;
	int a[10]={0};
	int irekae;
	for (i=0;i<10;i++)
	{
		scanf("%d",&a[i]);
	}
	for (i=0;i<10;i++)
	{
		for (j=0;j<9;j++)
		{
			if (a[j]<a[j+1])
			{
				irekae=a[j];
				a[j]=a[j+1];
				a[j+1]=irekae;
			}
		}
	}
	for (i=0;i<3;i++)
	{
		printf("%d\n",a[i]);
	}
	return 0;
}

Measured memory_bytes: 600
import java.util.*;
import java.io.*;

// Template for atcoder
public class Main {

    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    final long MOD = 1000L * 1000L * 1000L + 7;
    private static final int[] dx = {0, -1, 0, 1};
    private static final int[] dy = {1, 0, -1, 0};

    void solve() throws IOException {
        int N = nextInt();
        int K = nextInt();
        int[] arr = nextIntArr(N);
        boolean[] dp = new boolean[K + 1];
        for (int i = 1; i <= K; i++) {
            boolean valid = false;
            for (int v : arr) {
                if (i - v >= 0 && !dp[i - v]) {
                    valid = true;
                }
            }
            dp[i] = valid;
        }
        outln(dp[K] ? "First" : "Second");
    }

    void shuffle(int[] a) {
        int n = a.length;
        for(int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            int tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }
    private void outln(Object o) {
        out.println(o);
    }
    private void out(Object o) {
        out.print(o);
    }
    public Main() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
    public static void main(String[] args) throws IOException {
        new Main();
    }

    public long[] nextLongArr(int n) throws IOException{
        long[] res = new long[n];
        for(int i = 0; i < n; i++)
            res[i] = nextLong();
        return res;
    }
    public int[] nextIntArr(int n) throws IOException {
        int[] res = new int[n];
        for(int i = 0; i < n; i++)
            res[i] = nextInt();
        return res;
    }
    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }
    public String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}


Measured memory_bytes: 33596
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			String[] s = sc.next().split(",");
			double[] a = new double[8];
			for(int i = 0; i < 8; i++) {
				a[i] = Double.parseDouble(s[i]);
			}
			Vec OA = new Vec(a[0], a[1]);
			Vec OB = new Vec(a[2], a[3]);
			Vec OC = new Vec(a[4], a[5]);
			Vec OD = new Vec(a[6], a[7]);
			if(isIn(OA, OB, OC, OD) || isIn(OA, OB, OD, OC) || isIn(OA, OC, OD, OB)
					|| isIn(OB, OC, OD, OA)) {
				System.out.println("NO");
			}else {
				System.out.println("YES");
			}
		}
		sc.close();
	}
	static boolean isIn(Vec OA, Vec OB, Vec OC, Vec OP) {
		Vec AB = new Vec(OB.x - OA.x, OB.y - OA.y);
		Vec BC = new Vec(OC.x - OB.x, OC.y - OB.y);
		Vec CA = new Vec(OA.x - OC.x, OA.y - OC.y);

		Vec AP = new Vec(OP.x - OA.x, OP.y - OA.y);
		Vec BP = new Vec(OP.x - OB.x, OP.y - OB.y);
		Vec CP = new Vec(OP.x - OB.x, OP.y - OB.y);

		double d1 = AB.x * BP.y - AB.y * BP.x;
		double d2 = BC.x * CP.y - BC.y * CP.x;
		double d3 = CA.x * AP.y - CA.y * AP.x;
		if((d1 > 0.0 && d2 > 0.0 && d3 > 0.0) || (d1 < 0.0 && d2 < 0.0 && d3 < 0.0)) {
			return true;
		}
		return false;
	}
	static class Vec{
		double x, y;
		public Vec(double x, double y) {
			this.x = x;
			this.y = y;
		}
	}
}


Measured memory_bytes: 25980
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes, T no) { cout << (val ? yes : no) << "\n"; }

void say(bool val, string yes = "Yes", string no = "No") { say<string>(val, yes, no); }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}

// C++ 17に完全移行したら消す
// 最大公約数を求める
template <class T> T gcd(T n, T m) { return n ? gcd(m % n, n) : m; }

// 最小公倍数を求める
template <class T> T lcm(T n, T m) {
  int g = gcd(n, m);
  return n * m / g;
}

// 重複を消す。計算量はO(NlogN)
template <class T> void unique(std::vector<T> &v) {
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());
}


#line 2 "abc171_c.cpp"

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

  ll n;
  cin >> n;
  string ans = "";

  while (n) {
    n--;
    ans += 'a' + n % 26;
    n /= 26;
  }
  if (n != 0)
    ans += 'a' + (n - 1) % 26;
  reverse(begin(ans), end(ans));
  cout << ans << endl;
}


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

int vs[1000000+10];

int main(void) {
  int n;
  scanf("%d", &n);
  multiset<int> ss;
  REP(i, 1 << n) {
    int v;
    scanf("%d", &v);
    ss.insert(-v);
  }
  bool possible = true;
  vs[0] = *ss.begin();
  ss.erase(ss.begin());
  int ii = 1;
  REP(i, n) {
    REP(j, 1 << i) {
      auto it = ss.upper_bound(vs[j]);
      if(it == ss.end()) {
        // cerr << "> " << i << " " << j << " " << vs[j] << " " << endl;
        possible = false;
        goto OUT;
      }
      vs[ii++] = *it;
      ss.erase(it);
    }
  }
 OUT:
    // REP(i, 1 << n) {
    //   cerr << -vs[i] << " ";
    // }
    // cerr << endl;
    puts(possible ? "Yes" : "No");
  
  return 0;
}


Measured memory_bytes: 13568
#include<iostream>
#include<string>
using namespace std;
main(){
    int i=0,K;
    string S;
    cin >> K >> S;
    if(S.size()<=K){
        cout << S << endl;

    }
    else{
        for(i=0;i<K;++i){
            cout << S.at(i);
        }
        cout << "..." << endl;
    }
    
}

Measured memory_bytes: 3628
// #Sazaの1日1AC
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000000+7;
const long long INF=9e18;
const double PI=3.14159265358979323846;

//マクロ
//型エイリアス
using ll = long long;
using P=pair<long long,long long>;
using vl=vector<long long>;
using vvl=vector<vector<long long>>;
using vP=vector<pair<long long, long long>>;
//ショートカット
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,k,n) for(int i=k;i<n;i++) //半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
//入力
#define vin(v,N) for(long long i=0;i<N;i++) cin>>v.at(i)
#define lin(n) long long n;cin>>n
#define chin(x) char x;cin>>x;
#define sin(s) string s;cin>>s;
#define vlin(v,N) vector<long long>v(N);for(long long i=0;i<N;i++)cin>>v.at(i)

#define max(a,b) max((ll)a,(ll)b)
#define min(a,b) min((ll)a,(ll)b)

//関数
//最大公約数
long long gcd(long long m, long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m, long long n){
  return m*n/gcd(m,n);
}
//xのn乗
long long power(long long x, long long N){
  long long ret=1;
  for(long long i=0;i<N;i++)   
    ret*=x;
  return ret;
}
//繰り返し二乗法
long long repeat_squaring(long long x, long long n){
  if(n==0) return 1;
  else if(n%2==0){
    long long t=repeat_squaring(x,n/2);
    return t*t%mod;
  }
  else
    return x*repeat_squaring(x,n-1);
}
//素因数分解(mapで返す)
map<long long,long long> factor(long long p){
  ll p1=p;
  map<long long,long long>ret;
  for(long long i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//素数判定
bool is_prime(long long N){
  for(long long i=2;i*i<=N;i++){
    if(N%i==0)
      return false;
  }
  return true;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}

//構造体
//Union-Find木
struct UnionFind{
  //メンバ変数 
  vector<long long>par; //par[i]:=頂点iの親
  vector<long long>s; //s[i]:=頂点iが属する集合の個数(iが根のとき)
  
  //コンストラクタ
  UnionFind(long long N):par(N),s(N){
    for(long long i=0;i<N;i++){
      par[i]=i; //最初はすべてが根として初期化
      s[i]=1;
    }
  }
  //メンバ関数
  //root(i):=頂点iの根
  long long root(long long i){
    if(par[i]==i) return i;
    par[i]=root(par[i]); //経路圧縮
    return root(par[i]); //再帰
  }
  //size[i]:=iが属する集合の個数
  long long size(long long i){
    return s[root(i)];
  }
  //same(x,y) xとyが同じ根を持つか(同じ集合に含まれるか)
  bool same(long long x, long long y){
    return root(x)==root(y);
  }
  //unite(x,y) xの根をyの根に繋げる(集合を合併)
  void unite(long long x, long long y){
    if(!same(x,y)){
      long long rx=root(x);
      long long ry=root(y);
      par[rx]=par[ry];
      s[ry]=s[rx]+s[ry];
    }
  }
};
//////////////////ここまでライブラリ///////////////////////

//メイン関数
int main(){
  //doubleの桁数
  cout<<fixed<<setprecision(10);
  
  
  lin(K);lin(N);
  vlin(a,N);
  vl s(N);
  s[0] = K - a[N-1] + a[0];
  rep2(i,1,N)
    s[i] = a[i] - a[i-1];
  
  sort(all(s));
  
  ll res = 0;
  rep(i,N-1)
    res += s[i];
  
  cout << res;
}

Measured memory_bytes: 3328
import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    A,B=mis()
    print(A*B if 0<A<10 and 0<B<10 else '-1')


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include<stdio.h>

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

Measured memory_bytes: 2728
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x) cout << #x << " = " << (x) << endl;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define P pair<int, int>
#define V vector<int>
#define M map<int, int>
#define S set<int>
#define itn int
#define tin int
#define tni int
bool dbg = false;
int N;
void solve()
{
}

signed main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N;
    int ans = 0;
    FORR(i, 1, N)
    {
        if ((i <= 9) || (i >= 100 && i <= 999) || ((i >= 10000) && (i <= 99999))) {
            ans++;
        }
    }
    cout << ans << endl;
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

struct country {
  string name;
  int score;
  bool operator < (const country &c) const {
    return score > c.score;
  }
};

int main() {
  int n;
  bool ok = 0;
  while(cin >> n && n) {
    if(ok) cout << endl;
    ok = 1;
    country team[10];
    for(int i=0; i<n; i++) {
      string s; int win, lose, draw;
      cin >> s >> win >> lose >> draw;
      team[i].name = s;
      team[i].score = win*3 + draw*1;
    }
    
    sort(team, team+n);
    
    for(int i=0; i<n; i++) {
      cout << team[i].name << ',' << team[i].score << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
/* Karen {{{
  ___  ____
 |_  ||_  _|
   | |_/ /    ,--.   _ .--.  .---.  _ .--.
   |  __'.   `'_\ : [ `/'`\]/ /__\\[ `.-. |
  _| |  \ \_ // | |, | |    | \__., | | | |
 |____||____|\'-;__/[___]    '.__.'[___||__]
}}} */
/* cpp template {{{*/
using namespace std;

#define endl '\n'

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()

typedef double D;
typedef long long ll;
typedef long double lb;
typedef complex<D> P;
typedef vector<P> VP;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<string, int> psi;

inline bool inside(int y,int x,int H,int W){return(y>=0&&x>=0&&y<H&&x<W);}
inline int in() {int x; std::cin >> x; return x;}

template <typename T>
void print(std::vector<T>& v, char c = ' ') {
  REP(i, v.size()) {
    if (i != 0) std::cout << c;
    std::cout << v[i];
  }
  std::cout << endl;
}
template <typename T>
void print(T x) {
  std::cout << x << '\n';
}
/* }}} */
/* 定数 {{{*/
const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 9;
const D EPS  = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
/* }}} */

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

  int h = in(), w = in();

  int cnt = 0;
  REP(i, h) REP(j, w){
    char a;
    cin >> a;
    if (a == '#') cnt++;
  }

  cout << (cnt == w + h - 1 ? "Possible" : "Impossible") << endl;

}



Measured memory_bytes: 256
def main():
    n, a, b = map(int, input().split())

    sumv = 0
    for x in range(a, n+1):
        num = sum([int(i) for i in str(x)])
        if num >= a and num <= b: sumv += x
    print(sumv)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int x[100];
for(int i=0;i<n;i++)
	{cin>>x[i];};
for(int i=n-1;1;i--)
	{cout<<x[i]; 
	if(i==0) break;
	cout<<" ";
	};
cout<<endl;
return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

const double PI = acos(-1L);
double rad(const double x) {return x * PI / 180;}

int main(void)
{
    IOS
    double A,B;
    cin >> A >> B;
    double H, M;
    cin >> H >> M;
    double hrad = rad( (H*60+M) / 720 * 360); 
    double mrad = rad(M / 60 * 360); 
    double ay = A * cos(hrad);
    double ax = -A * sin(hrad);
    double by = B * cos(mrad);
    double bx = -B * sin(mrad);
    double ans = sqrt((ax-bx) * (ax-bx) + (ay-by)*(ay-by));

    cout << fixed << setprecision(10) << ans << '\n';

    return 0;
}

Measured memory_bytes: 4060
#include<bits/stdc++.h>
using namespace std;
long long minn=10000000007,n,a[100002],k;
int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
//	for(int i=0;i<n;i++){
//		cout<<a[i]<<" ";
//	}
	for(int i=0;i<=n-k;i++){
//		cout<<a[i+k]-a[i]<<" ";
		minn=min(minn,a[i+k-1]-a[i]);
	}
	cout<<minn;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define mz 998244353
#define pq priority_queue
using namespace std;

struct Node
{
    int no,v;
}a[200005];
struct Nodes
{
    int l,r,mid,maxx;
}tre[800005];
vector <int> vec[200005];
int ans[200005];

bool cmp1(Node x1,Node x2)
{
    return x1.v<x2.v;
}
bool cmp2(Node x1,Node x2)
{
    return x1.no<x2.no;
}
void build(int x,int l,int r)
{
    tre[x].l=l;
    tre[x].r=r;
    tre[x].mid=(l+r)/2;
    if(l!=r)
    {
        build(x*2,tre[x].l,tre[x].mid);
        build(x*2+1,tre[x].mid+1,tre[x].r);
    }
}
int ask(int x,int l,int r)
{
    if(l>r)
        return 0;
    if(l==tre[x].l && r==tre[x].r)
        return tre[x].maxx;
    if(l<=tre[x].mid && r>tre[x].mid)
        return max(ask(x*2,l,tre[x].mid),ask(x*2+1,tre[x].mid+1,r));
    else
    {
        if(r<=tre[x].mid)
            return ask(x*2,l,r);
        else
            return ask(x*2+1,l,r);
    }
}
void add(int x,int p,int y)
{
    if(tre[x].l==tre[x].r)
        tre[x].maxx=y;
    else
    {
        if(p<=tre[x].mid)
            add(x*2,p,y);
        else
            add(x*2+1,p,y);
        tre[x].maxx=max(tre[x*2].maxx,tre[x*2+1].maxx);
    }
}
void dfs(int x,int fa)
{
    ans[x]=ask(1,1,a[x].v-1)+1;
    int temp=ask(1,a[x].v,a[x].v);
    if(ans[x]>temp)
        add(1,a[x].v,ans[x]);
    ans[x]=max(ans[fa],ans[x]);
    for(int i=0;i<vec[x].size();i++)
    {
        if(vec[x][i]!=fa)
            dfs(vec[x][i],x);
    }
    add(1,a[x].v,temp);
}

int main()
{
    int now=0,u,v,n,cnt=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        a[i].no=i;
        scanf("%d",&a[i].v);
    }
    sort(a+1,a+1+n,cmp1);
    for(int i=1;i<=n;i++)
    {
        if(a[i].v!=now)
        {
            now=a[i].v;
            cnt++;
        }
        a[i].v=cnt;
    }
    sort(a+1,a+1+n,cmp2);
    build(1,1,cnt);
    for(int i=1;i<n;i++)
    {
        scanf("%d%d",&u,&v);
        vec[u].push_back(v);
        vec[v].push_back(u);
    }
    dfs(1,0);
    for(int i=1;i<=n;i++)
        printf("%d\n",ans[i]);
    return 0;
}


Measured memory_bytes: 32920
#include<iostream>
using namespace std;
int main(){
	int n,m,k;
	cin>>n>>m>>k;
	int a[n];
	for(int i=0;i<n;++i)
		cin>>a[i];
	int b[m];
	for(int i=0;i<m;++i)
		cin>>b[i];
	int c1[k],c2[k],c3[k];
	for(int i=0;i<k;++i){
		cin>>c1[i]>>c2[i]>>c3[i];
		--c1[i];
		--c2[i];
	}
	int mina=0x7fffffff;
	int minb=0x7fffffff;
	for(int i=0;i<n;++i)
		mina=min(mina,a[i]);
	for(int i=0;i<m;++i)
		minb=min(minb,b[i]);
	int minv=mina+minb;
	for(int i=0;i<k;++i)
		minv=min(minv,a[c1[i]]+b[c2[i]]-c3[i]);
	cout<<minv<<endl;
	return 0;
}

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

int main(){
  string a,b,c,d,ans;
cin>>a;
  for(int i=0;i<a.size();i++){
    for(int j=0;j<i;j++){
      if(a[i]==a[j]){
        cout<<"no"<<endl;
        j=100000;
        i=1000;
      }
      }
    if(i==a.size()-1){
      cout<<"yes"<<endl;
    }
  }
}


Measured memory_bytes: 256
sx,sy,tx,ty = map(int,input().split())
going1 = ''
returning1 = ''
going2 = ''
returning2 = ''
going1 = 'R' * (tx - sx) + 'U' * (ty - sy)
returning1 = 'L' * (tx -sx) + 'D' * (ty - sy)
going2 = 'D' + 'R' * (tx - sx + 1) + 'U' * (ty - sy + 1) + 'L'
returning2 = 'U' + 'L' * (tx - sx + 1) + 'D' * (ty - sy + 1) + 'R' 
print(going1 + returning1 + going2 + returning2)


Measured memory_bytes: 3060
from heapq import *
n, m = map(int, input().split())
jobs = [tuple(map(int, input().split())) for _ in range(n)]
jobs.sort(reverse=True)
ans = 0
q = []
# 残り何日でのごとの仕事の候補をqに追加していく
for i in range(1, m+1):
    while jobs and jobs[-1][0] <= i:
        # -1かけてqに追加
        heappush(q, -jobs.pop(-1)[1])
    if q:
        #　残り何日でごとに、-1かかってるので一番高いお金をもらえる仕事がpopされる
        ans -= heappop(q)
print(ans)

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

int main()
{
    int a,b ;
    cin >> a>>b;


    cout << max({a+b,a-b,a*b}) << endl;
    return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
//#define int ll
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

int keta(int n) {
  int k = 0;
  while(n) {
    n/=10;
    k++;
  }
  return k;
}

ll powd(int k) {
  ll d = 1LL;
  rep(i, k) {
    d *= 10LL;
  }  
  return d;
}

ll counts[10][10];

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  int N;
  cin >> N;
  
  for(int i=1; i<=N; i++) {
    int nls = i % 10;
    int ii = i;
    while(ii/10) {
      ii/=10;
    }
    int nms = ii;
    counts[nms][nls] ++;
  }
  
  ll kosu = 0;
  //回す
  for(int i=0; i<10; i++) {
    for(int j=0; j<10; j++) {
      kosu += counts[i][j] * counts[j][i];
    }
  }
  
  fin(kosu);
}


Measured memory_bytes: 256
S = input()
T = input()

flag = False
start = None
for i in range(len(S) - len(T) + 1):
    flag2 = True
    for j in range(len(T)):
        if S[i + j] == "?" or S[i + j] == T[j]:
            continue
        else:
            flag2 = False

    if flag2:
        flag = True
        start = i

if flag:
    for i in range(len(S)):
        if i < start or start + len(T) <= i:
            if S[i] == "?":
                print("a", end="")
            else:
                print(S[i], end="")
        else:
            print(T[i - start], end="")
else:
    print("UNRESTORABLE")


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
using namespace std;

int main(){
  int m, n, res = 0, in;
  scanf("%d%d", &m, &n);
  rep(i, m){
    int sum = 0;
    rep(j, n){
      scanf("%d", &in);
      sum += in;
    }
    res = max(res, sum);
  }

  printf("%d\n", res);
  return 0;
}

Measured memory_bytes: 1188
#include <stdio.h>
#include <inttypes.h>

int H, W;
char S[3333][3333];

int O[3333][3333], I[3333][3333];

int main(void) {
	int i, j;
	uint64_t horieyui = 0;
	if (scanf("%d%d", &H, &W) != 2) return 1;
	for (i = 0; i < H; i++) {
		if (scanf("%3332s", S[i]) != 1) return 1;
	}
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			if (S[i][j] == 'O') O[i][j]++;
			if (S[i][j] == 'I') I[i][j]++;
		}
	}
	for (i = 0; i < H; i++) {
		for (j = 1; j < W; j++) {
			O[i][j] += O[i][j - 1];
		}
	}
	for (i = 1; i < H; i++) {
		for (j = 0; j < W; j++) {
			I[i][j] += I[i - 1][j];
		}
	}
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			if (S[i][j] == 'J') {
				horieyui += (uint64_t)(O[i][W - 1] - O[i][j]) * (I[H - 1][j] - I[i][j]);
			}
		}
	}
	printf("%" PRIu64 "\n", horieyui);
	return 0;
}



Measured memory_bytes: 89652
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  int l[n];
  for(int i = 0; i < n; i++)
    cin >> l[i];
  std::sort(l, l + n);
  std::reverse(l, (l + n));
  int sum = 0;
  for(int i = 0; i < k ; i++)
  	sum += l[i];
  std::cout << sum << std::endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Text;

namespace Fish.aizu
{
	public static class AizuOnlineJudge
	{
		public static int[] SplitToInts(string line)
		{
			return line.Split(' ').Select(x => int.Parse(x)).ToArray();
		}
		public static double[] SplitToDoubles(string line)
		{
			return line.Split(' ').Select(x => double.Parse(x)).ToArray();
		}
		public static long[] SplitToLongs(string line)
		{
			return line.Split(' ').Select(x => long.Parse(x)).ToArray();
		}
		public static int Main()
		{
			Compute(Console.In, Console.Out);
			return 0;
		}
		
		public static void Compute(TextReader reader, TextWriter writer)
		{
			var str = reader.ReadLine();
			var sb = new StringBuilder(str);
			var n = int.Parse(reader.ReadLine());
			
			for (int i = 0; i < n; i++)
			{
				var line = reader.ReadLine();
				var ary = line.Split(' ');
				var a = int.Parse(ary[1]);
				var b = int.Parse(ary[2]);
				var len = b - a + 1;
				
				switch (ary[0])
				{
					case "replace" : 
					{
						sb.Remove(a, len);
						sb.Insert(a, ary[3]);
						break;
					}
					case "reverse" : 
					{
						var temp = new StringBuilder();
						for (int j = 0; j < len; j++)
						{
							temp.Insert(0, sb[a + j]);
						}
						sb.Remove(a, len);
						sb.Insert(a, temp.ToString());
						break;
					}
					case "print" : 
					{
						writer.WriteLine(sb.ToString().Substring(a, len));
						break;
					}
					default : throw new ApplicationException();
				}
			}
		}
	}
}

Measured memory_bytes: 19832
#include <algorithm>
#include <iostream>
#include <vector>

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

#define INF 1000000000

using namespace std;

int scoring(const vector<int> &c,
            const vector<vector<int>> &s,
            int day,
            int type,
            const vector<int> &previous) {
    int score = s[day][type];

    REP(i, 26) {
        score -= c[i] * (day + 1 - previous[i]);
    }

    return score;
}

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

    vector<int> c(26);
    REP(i, 26)
        cin >> c[i];

    vector<vector<int>> s(D, vector<int>(26, 0));
    REP(i, D)
        REP(j, 26)
            cin >> s[i][j];

    vector<int> previous(26, 0);

    long long score = 0;
    REP(i, D) {
        vector<int> greedy(26, 0);

        REP(j, 26) {
            int backup = previous[j];
            previous[j] = i + 1;
            greedy[j] = scoring(c, s, i, j, previous);
            previous[j] = backup;
        }

        int pos = max_element(ALL(greedy)) - greedy.begin();

        previous[pos] = i + 1;
        score += scoring(c, s, i, pos, previous);
        cout << pos + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 3676
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n,t = m()

li = [l() for i in range(n)]

ma = []
for i in range(n):
    ma.append([li[i][1],i])

ma.sort(reverse = True)

li.sort(key = lambda x:x[0])

dp = [0 for i in range(t + 3000)]

for i in range(n):
    for k in range(li[i][0]+t-1,li[i][0]-1,-1):
        if dp[k] <= dp[k-li[i][0]] + li[i][1]:
            dp[k] = dp[k-li[i][0]] + li[i][1]


dp.sort(reverse = True)
ans = dp[0]

print(ans)




Measured memory_bytes: 46076
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#define N_MAX 100005
using namespace std;

int num[5];

int main()
{
	int A, B, C, D, E;
    cin >> A >> B >> C >> D >> E;
  	int count = 0;
  	num[0] = A;
    num[1] = B;
    num[2] = C;
    num[3] = D;
    num[4] = E;
  	int sum = 0;
  	for(int i = 10; i > 0; i--){
    	for(int j = 0; j < 5; j++){
        	if(num[j]%10 == i%10) {
            	sum += num[j];
          		if(i != 10 && count != 4) sum += (10-num[j]%10);
              	count++;
            }
        }
      	if(count == 5) break;
    }
  	cout << sum << endl;
}

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

int main(){
    string s,t;
    cin >> s >> t;
    int n = s.length();
    int ans=0;
    for (int i = 0; i < n; i++)
    {
        if(s[i]!=t[i]){
            ans++;
        }
    }
    cout << ans;
}

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

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

int main()
{
    int m, f, r;

    while (1)
    {
        cin >> m >> f >> r;
        if (m == -1 && f == -1 && r == -1)
        {
            break;
        }

        if (m == -1 || f == -1)
        {
            cout << "F" << endl;
        }
        else if (m + f >= 80)
        {
            cout << "A" << endl;
        }
        else if (m + f >= 65)
        {
            cout << "B" << endl;
        }
        else if (m + f >= 50)
        {
            cout << "C" << endl;
        }
        else if (m + f >= 30)
        {
            if (r >= 50)
            {
                cout << "C" << endl;
            }
            else
                cout << "D" << endl;
        }
        else
        {
            cout << "F" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10,mod=1e9+7;
int a,b,f[maxn],k,s[maxn],dp2[maxn];
map<int,int,greater<int>> dp;
void plusle(int &a,int b){
    a+=b;if(a>=mod)a-=mod; return;
}
void minun(int &a,int b){
    a-=b; if(a<0)a+=mod; return;
}
int add(int a, int b) {
  a += b;
  if (a >= mod) a -= mod;
  return a;
}
int mul(int a,int b){
    return (int)(((long long)a*b)%mod);
}

int main(){
    int n;
    scanf("%d%d",&n,&k);
    int cc=n,pt=1;
    while(cc){
        int x=n/cc;
        dp[x]=(n/x-n/(x+1));
        cc=(n/(x+1));
    }
    int sum=0;
    int last=-1;
    pt=0;
    for(auto it:dp){
        s[pt]=it.second;
        f[pt]=it.second;
        pt++;
    }
    while(k--){
        last=-1;
    for(int i=0;i<pt;i++){
        dp2[i]=(last==-1)?s[i]:add(last,s[i]);
        last=dp2[i];
    }
    for(int i=0;i<pt;i++){
        s[i]=mul(f[i],dp2[pt-i-1]);
    }
    }
    printf("%d\n",s[0]);
}


Measured memory_bytes: 3968
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<int,int> P;
ll mod=pow(10,9)+7;
ll INF=pow(10,18);

int main(){
    int N,M;scanf("%d %d",&N,&M);
    vec A(M);
    for(int i=0;i<M;i++) scanf("%lld",&A[i]);
    sort(A.begin(),A.end(),greater<ll>());
    vec n={0,2,5,5,4,5,6,3,7,6};
    mat dp(N+1,vec(M+1,0));
    //漸化式
    for(int i=0;i<N-1;i++){
        if(i>0 && dp[i][0]==0) continue;
        vec v;
        for(int j=0;j<M;j++){
            if(i+n[A[j]]>N) continue;
            v=dp[i];v[0]++;v[j+1]++;
            int t=dp[i+n[A[j]]][0];
            if(v[0]>t){
                dp[i+n[A[j]]]=v;
            }
            else if(v[0]==t){
                for(int k=1;k<=M;k++){
                    if(v[k]>dp[i+n[A[j]]][k]){
                        dp[i+n[A[j]]]=v;
                        break;
                    }
                    else if(v[k]<dp[i+n[A[j]]][k]){
                        break;
                    }
                }
            }
        }
    }
    string ans;
    for(int i=0;i<M;i++){
        char c=A[i]+'0';
        for(int j=0;j<dp[N][i+1];j++) ans+=c;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<cmath>
#include<iomanip>
using namespace std;
int main() {
	double x1, y1, x2, y2, r;
	cin >> x1; cin >> y1; cin >> x2; cin >> y2;
	r = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
	cout << fixed << setprecision(6) << r << endl;
	return 0;
}


Measured memory_bytes: 3280
St = input()
n = len(St)
#Stを集合に変換
#集合は同じ要素のダブりはない
#だから要素が何種類あるかすぐにわかる
Se = set(St)

answer = 1
for i in range(n):
    if St.count(St[i]) != 2 :
        answer = 0

#len() は要素の個数がわかる
#だから要素の個数がわかる　つまり　それぞれの文字が文字列中に何個あるかがわかる
#リスト.count(文字)　でリスト中の文字の出現回数がわかる
if len(Se) == 2 and answer == 1:
    print("Yes")
else:
	print("No")

Measured memory_bytes: 3060
def solve():
  n = int(input())
  s = [input() for _ in range(n)]
  l = []
  for si in s:
      lparen = rparen = 0
      for c in si:
          if c == '(':
              lparen += 1
          else:
              if lparen > 0:
                  lparen -= 1
              else:
                  rparen += 1
      l.append((rparen, lparen))
  inc = []
  dec = []
  for p, q in l:
      if p < q:
          inc.append((p, q))
      else:
          dec.append((p, q))
  inc.sort()
  k = 0
  for p, q in inc:
      if k < p:
          print('No')
          return
      k = k - p + q
  dec.sort(key=lambda x: x[1])
  t = 0
  for p, q in dec:
      if t < q:
          print('No')
          return
      t = t - q + p
  if k == t:
      print('Yes')
  else:
      print('No')
  return


solve()


Measured memory_bytes: 163340
# -*- coding: utf-8 -*-
from collections import Counter
N = int(input())
a = [int(n)//400 for n in input().split()]
counter = Counter(a)

colors = 0
for i in range(8):
    if counter[i] > 0:
        colors += 1

rainbow_coder = 0
for i in range(8, 13):
    rainbow_coder += counter[i]

print("{} {}".format(max(1, colors), colors+rainbow_coder))


Measured memory_bytes: 3444