akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}

using namespace std;
// now

struct UnionFind {
    vector<int> d;
    UnionFind(int n=0) : d(n,-1){}
    int Find (int x){//根の番号を探す
        if(d[x] < 0) return x;
        return d[x] = Find(d[x]);
    }
    bool unite (int x, int y){
        x = Find(x); y = Find(y);
        if(x == y ) return false;
        if(d[x] < d[y]){
            swap(x,y);
        }
        d[x] += d[y];
        d[y] = x;
        return true;
    } 

    bool same(int x, int y){
        return Find(x) == Find(y);
    }
    int size(int x) {
        return (-d[Find(x)]);
    }
};


ll nCr (ll n, ll r){
    ll ans = 1;
    for(ll i = n ; i > n-r ; i --){
        ans *= i;
    }
    for(ll i = 1 ; i<= r; i ++){
        ans /= i;
    }
    return ans ;
}

int nPr (int n,int r){
    int ans = 1;
    for(int i = n ; i > n-r ; i --){
        ans *= i;
    }
    return ans ;
}
 ll modd = 1e9+ 7;
ll wa (ll n,ll mi, ll ma){
    ll ans  = n * (mi+ma) /2;
    return ans;
}


int main(){

ll n,m,k;

cin >> n  >> m >> k;
vector<ll> vec1(n), vec2(m),rui(m+1);
REP(i,n){
    cin >> vec1[i]; 
}
rui[0] =0;

REP(i,m){
    cin >> vec2[i];
    rui[i+1] = rui[i] + vec2[i];
}

ll ans = 0,sum = 0;

REP(i,n+1){
    ll tmp = 0;
    if(i == 0){
        
        auto it = upper_bound(rui.begin(),rui.end(),k);
        tmp = distance(rui.begin(),it)-1;
        
    }else{
        sum += vec1[i-1];
        auto it = upper_bound(rui.begin(), rui.end(), k-sum);
        
        tmp = distance(rui.begin(),it) + i-1;
    }

    if(sum > k )break;
    ans = max(ans, tmp);
}
    cout << ans <<endl;
}





Measured memory_bytes: 7972
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>
#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222






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



  cin >> n;
  cout << (n - 1)*n / 2 << endl;




  return 0;
}


Measured memory_bytes: 256
import heapq
n,m = map(int, input().split())
a = list(map(int, input().split()))
hq = []
for j in range(n):
    aa = a[j] * -1
    heapq.heappush(hq, aa)
for i in range(m):
    maxim = heapq.heappop(hq) * -1
    maxim //= 2
    maxim *= -1
    heapq.heappush(hq, maxim)
print(-1 * sum(hq))


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

public class Main {
	private static void solve(){
	//Implement solution here.
		long n = nl();
		long[] ta = new long[5];
		long mint = Long.MAX_VALUE;
		for(int i = 0; i < 5; i++) {
			mint = Math.min(mint, nl());
		}				
		System.out.println(n % mint == 0 ? n / mint + 4 : n / mint + 5);		
	}

    //Switch input source (stdin/file)
	private static BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args){
        String debugDataPath = System.getenv("DD_PATH");        
        if(debugDataPath != null){
            try{
            	br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
            }catch(Exception e){
                throw new RuntimeException(e);
            }
        }
        solve();
	}

    //Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
    //Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
    //Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
    //Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
    //Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
    //Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 22868
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int many = scan.nextInt();
		int kind = scan.nextInt();
		int yen;
		int[] yenbox = new int[many];
		for(int i=0;i<many;i++) {
			yen = scan.nextInt();
			yenbox[i] = yen;
		}
		int min;
		for(int i=0;i<many;i++) {
			for(int j=i;j<many;j++) {
				if(yenbox[i]>yenbox[j]) {
					min = yenbox[i];
					yenbox[i] = yenbox[j];
					yenbox[j] = min;
				}
			}
		}
		int answer = 0;
		for(int i=0;i<kind;i++) {
			answer += yenbox[i];
		}
		System.out.print(answer);
	}

}

Measured memory_bytes: 38472
#include<stdio.h>
#include<string.h>
#include<math.h>

int main(void) {
	int n,m,i,a=0;
	char s[100];

	scanf("%d", &n);
	
	for (i = 1; i <= 9; i++) {
		if (((n % i) == 0) && (n / i >= 1) && (n / i <= 9)) {
			a++;
		}
	}
	if (a > 0) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>

using namespace std;

int main(int argc, char **argv)
{
	int n;
	float x1, y1, x2, y2, x3, y3, a1, a2, b1, b2, c1, c2;
	cin >> n;
	while(n--){
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
		a1 = 2*(x2-x1);
		b1 = 2*(y2-y1);
		c1 = x1*x1 - x2*x2 + y1*y1 - y2*y2;
		a2 = 2*(x3-x1);
		b2 = 2*(y3-y1);
		c2 = x1*x1 - x3*x3 + y1*y1 - y3*y3;
		
		x3 = (b1*c2-b2*c1)/(a1*b2-a2*b1);
		y3 = (c1*a2-c2*a1)/(a1*b2-a2*b1);
		a1 = sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
		printf("%.3f %.3f %.3f\n", x3, y3, a1);
	}
	
	return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;

  if (K > N) {
    cout << 1 << endl;
  } else if (N % K == 0) {
    cout << 0 << endl;
  } else {
    cout << 1 << endl;
  }
}


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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<char> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
void print_line(vector<ll> &line) {
    for (int i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}

typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;
const int mod = 1000000007;

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

    while (s.size() < t.size()) {
        s += s;
    }
    s += s;

    if (s.find(t) == -1) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 3228
#include <iostream>

using namespace std;

int main (){
    int x,y;
    
    while(1){
        cin >> x >> y ;
        
       if(x == 0 && y == 0) break ;
           if(x<y){
               cout << x << " " << y << endl;
           }  else {
                   cout << y << " " << x << endl;
               }
       }
        
    
 
    return 0;
    
}

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

#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int

const int maxr = 1e5+5;


int32_t main()
{
	GO;
	int n;
	cin>>n;
	cout << ceil(n/2.0)<<endl;	
	return 0;
}

//!

Measured memory_bytes: 256
def main():
    n = int(input())
    a = list(input())
    b = list(input())
    c = list(input())
    cnt = 0
    for i in range(n):
        if a[i] == b[i] == c[i]:
            continue
        if a[i] == b[i] or b[i] == c[i] or a[i] == c[i]:
            cnt += 1
            continue
        cnt += 2
    print(cnt)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define SZ(X) ((int)(X).size())
#define endl "\n";
typedef long long ll;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ll a,b,k;
	cin>>a>>b>>k;
	if(k<=a){
		cout<<a-k<<" "<<b;;
	}else if(k<=a+b){
		cout<< 0 <<' '<<b- (k-a) <<endl;
	}else{
		cout<<0<<" "<<0;
	}

   return 0;
}


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

int main() {

	int a, b,c,abc;

	cin >> a >> b>>c;

	if (a > b) {
		abc = a;
		a = b;
		b = abc;
	}
	if (b > c) {
		abc = b;
		b = c;
		c = abc;
	}
	if (a > b) {
		abc = a;
		a = b;
		b = abc;
	}


	cout << a << " " << b << " " << c << endl;
	return 0;

}



Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define mod 1000000007
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define inp_vecN for(int i=0;i<n;i++)cin>>v[i]; 
vector<int> get_Factors(ll n)
{
      vector <int> v;
      for(ll i=1; i<=sqrt(n)+1; i++)
      {
            if(n%i==0)
            {
                  v.push_back(i);
                  v.push_back(n/i);
            }
      }

      return v;
}
string get_bin(ll n)
{
    string s = "";
    while(n > 0)
    {
        s += ('0' + n%2);
        n /= 2;
    }
    reverse(s.begin(), s.end());
    return s;
}

ll bin_to_dec(string s)
{
    ll ans = 0;
    for(auto ch: s)
    {
        ans *= 2;
        ans += (ch - '0');
    }
    return ans;
}
void PrintVector(vector<int> v,int n)
{

    for(int i=0;i<n;i++)
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;
}
int no_of_primeFactors(int n)  
{ 
    int count=0;
    while (n % 2 == 0)  
    {  
        count++;
        n = n/2;  
    }  
   
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    { 
        while (n % i == 0)  
        {  
           count++;
            n = n/i;  
        }  
        
    }  
    if (n > 2)  
        count++;
    return count;
} 
 ll gcd(int a, int b)
{ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
} 
   
  ll lcm(int a, int b)  
{  
    return (a/gcd(a, b)*b);  
}  



ll pwr(ll base,ll expo,ll m)
{
    if(base==0) return 0LL;
    if(expo==0) return (1LL%m);
    if((expo&1)==0) {ll temp=pwr(base,expo>>1,m); return (temp*temp)%m;}
    return ((base%m)*pwr(base,expo-1,m))%m;
}

int main(int argc, char const *argv[])
{
    ios;
    int k,a,b,c;
    cin>>k>>a>>b;

    for(int i=a;i<=b;i++)
    {
      if(i%k==0)
      {
            cout<<"OK"<<endl;
            return 0;
      }
    }
    cout<<"NG"<<endl;
   
    return 0;
}

Measured memory_bytes: 3624
#include<iomanip>
#include<algorithm>

// from iostream
#include<iostream>
using std::cout;
using std::cin;
using std::cerr;
using std::flush;
using std::endl;
// from vector
#include<vector>
using std::vector;
// from queue
#include<queue>
using std::deque;
using std::priority_queue;
// from tuple
using std::tuple;
using std::get;
using std::tie;
using std::make_tuple;
using std::forward_as_tuple;
// from string
#include<string>
using std::string;


// type definitions
typedef signed long long INT;
typedef tuple<INT,INT> TII;
typedef tuple<INT,INT,INT> TIII;
typedef tuple<double,double> TDD;
typedef tuple<double,double,double> TDDD;
typedef vector<INT>  VI;
typedef vector<TII>  VII;
typedef vector<TIII> VIII;
typedef vector<double> VD;
typedef vector<TDD>    VDD;
typedef vector<TDDD>   VDDD;

// macros
#define rep(i,n) for( INT i = 0 ; i <  n ; ++i )
#define REP(i,n) for( INT i = 1 ; i <= n ; ++i )
#define ALL(a) (a).begin(),(a).end()


// main

// begin global variables
// end global varieble;

int main(){
  std::ios::sync_with_stdio(false);
  // begin main
  INT N;
  string S;
  cin >> N >> S;
  VI v(N);
  rep(i,N) v[i] = ( S[i]=='(' ? 1 : -1 );
  INT min = +1000;

  INT count=0;
  rep(i,N){
    count += v[i];
    min = std::min(count,min);
  }

  if( min < 0 ){
    rep(i,-min) cout << '(';
    count += -min;
  }
  cout << S ;
  if( count > 0 ) rep(i,count) cout << ')';
  cout << endl;
  // end main
  return 0;
}


Measured memory_bytes: 256
from numpy import*
def main():
  t,*h=open(0)
  _,a,b=int32(t.split())
  h=int32(h)
  i,j=0,2**30
  while~i+j:
    k=(j+i)//2
    t=(b*k-h)//(a-b)
    if-k>sum(t[t<0]):i=k
    else:j=k
  print(j)
main()

Measured memory_bytes: 24572
import math

n = int(input())
ab = [list(map(int,input().split())) for _ in range(n)]

al = []
bl = []
for a,b in ab:
  al.append(a)
  bl.append(b)
al.sort()
bl.sort()

if n%2==0:
  mn = (al[n//2-1]+al[n//2])/2
  mx = (bl[n//2-1]+bl[n//2])/2
  ans = math.floor((mx-mn)*2+1)
else:
  mn = al[n//2]
  mx = bl[n//2]
  ans = mx-mn+1

print(ans)


Measured memory_bytes: 49364
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int[] num = new int[3];

		for (int i = 0; i < num.length; i++) {
			num[i] = scanner.nextInt();
		}

		for (int i = 0; i < num.length - 1; i++) {
			for (int j = 1; j < num.length; j++) {
				if (num[i] > num[j]) {
					int buf = num[i];
					num[i] = num[j];
					num[j] = buf;
				}
			}
		}

		for (int i = 0; i < num.length; i++) {
			System.out.print(num[i]);
			if (i < num.length - 1)
				System.out.print(" ");
			else
				System.out.print("\n");
		}
	}
}



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

ll X, Y;

int main(void){
	
	scanf("%lld %lld", &X, &Y);
	
	if(abs(X - Y) <= 1) printf("Brown\n");
	else printf("Alice\n");
	
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list()
xy = list()
flag = True
num = 0
output=0
for i in range(N):
  A.append(int(input()))
  xy.append([list(map(int,input().split())) for _ in range(A[i])])
  
for i in range(2**N):
  flag = True
  num = str(format(i, 'b').zfill(N))
  for j in range(N):
    if ((i>>j)&1) == 1:
      for k in range(len(xy[N-j-1])):
        if int(num[xy[N-1-j][k][0]-1]) !=  xy[N-1-j][k][1]:
          flag = False
          break
    if flag == False:
      break
  if flag == True and output <= str(bin(i)).count('1') :
    output = str(bin(i)).count('1')
print(output)
        

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

using namespace std;

#define fastio ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define foo(i,a,n) for(ll i = (a); i <= n; i++)
#define frr(i,a,n) for(ll i = (a); i >= n; i--)
#define fr(i,n) for(ll i = n-1; i >= 0; i--)
#define fo(i,n) for(ll i = 0; i < n; i++)
#define newl cout<<"\n"
#define pb push_back
#define mp make_pair
#define s second
#define f first

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vpll;

const ll MOD=1e+9+7;
const ll MAXN=1e+5+7;
const ll INF=1e+18;

//<<-----Declare Variable Here------->>//
ll n, a[MAXN];

//<<-----Implement Functions Here---->>//


//<<-----Start of Main--------------->>//

int main(){
	fastio;
	cin>>n;
	fo(i,n)cin>>a[i];

	a[n]=INF;
	ll res=-INF;
	ll rr=0;
	fo(i,n){
		//i--;
		//cout<<a[i]<<" "<<a[i+1]<<" "<<rr;
		//newl;
		if(a[i]>=a[i+1]){
			rr++;
		}
		else{
			res=max(res,rr);
			rr=0;
			//i--;
		}
	}
	cout<<res;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
char s[200005];
int read() {
	char c=getchar(); int x=0,f=1;
	while (c<'0' || c>'9') {
		if (c=='-') f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9') {
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
int main() {
	scanf("%s", s);
	int len=strlen(s);
	string t="";
	for (int i=0; i<len; ) {
		if (i<len-1 && s[i]=='B' && s[i+1]=='C') {
			t+='D';
			i+=2;
		}
		else {
			t+=s[i];
			++i;
		}
	}
	int cnt=0;
	long long ans=0;
	for (int i=0; i<t.size(); i++) {
		if (t[i]=='A') ++cnt;
		else if (t[i]=='D') ans+=cnt;
		else cnt=0;
	}
	printf("%lld\n", ans);
	return 0;
}

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

int main(){
	int a,b,c,d;
  	cin >> a >> b >> c >> d;
    cout << (
    abs(a-b)<=d&&abs(b-c)<=d ? "Yes":
    abs(a-c)<=d ? "Yes":"No"
    );
}

Measured memory_bytes: 256
// Problem : D - Leaping Tak
// Contest : AtCoder - AtCoder Beginner Contest 179
// URL : https://atcoder.jp/contests/abc179/tasks/abc179_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl '\n'
#define pb push_back
#define mod 998244353
ll power(ll x, ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % mod; 
    p = (p * p) % mod; 
  
    return (y%2 == 0)? p : (x * p) % mod; 
} 
ll factorial[1000007];
void fact(ll n)
{
    memset(factorial,0,sizeof(factorial));
    factorial[0]=1;
factorial[1]=1;

    for(int i=1;i<n;i++)
    {
        factorial[i]=(factorial[i-1]*i)%mod;
    }
    
}
ll ncr(ll n,ll r)
{
    ll ans=1;
    ll i;
    ans=factorial[n];
    ll ans1=power(factorial[n-r],mod-2);
    ll ans2=power(factorial[r],mod-2);
    ans=((ans*ans1)%mod*ans2)%mod;
    return ans;
}
ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 

bool prime[100000006];
void sieve(ll n){
    memset(prime,true,sizeof(prime));
	prime[1]=false; 
    for (ll p=2;p*p<=n;p++){
        if (prime[p]){  
            for (ll i=p*p;i<=n;i+=p)
                prime[i]=false;
        }
    }
}
void bfs(vector<int> v[],int o,int n,int dp[]){
	queue<int> q;
	q.push(o);
	dp[o]=0;
	bool visited[n+1]={0};
	visited[o]=true;
	while(q.empty()==false){
		int a=q.front();
		q.pop();
		for(int i=0;i<v[a].size();i++){
			if(visited[v[a][i]]==false){
				visited[v[a][i]]=true;
				q.push(v[a][i]);
				dp[v[a][i]]=dp[a]+1;
			}
		}
	}
}
int nov[1000001];
bool visited[1000001];
int dp[1000001];
int dfs(vector<int> v[],int o)
{
    if(visited[o]==0)
    {
        visited[o]=1;
        for(int i=0;i<v[o].size();i++)
        {
            if(visited[v[o][i]]==0)
            {
            dp[v[o][i]]=dp[o]+1;
            nov[o]+=dfs(v,v[o][i]);
            }
        }
        return nov[o]+1;
    }
    else
    return 0;
}
// string s=bitset<64>(n).to_string();
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	ll n,k;
	cin>>n>>k;
	vector<pair<ll,ll>> v;
	for(int i=0;i<k;i++)
	{
		ll a,b;
		cin>>a>>b;
		v.pb({a,b});
	}
	sort(v.begin(),v.end());
	ll dp[n+1];
	memset(dp,0,sizeof(dp));
	dp[1]=1;
	// for(int j=0;j<v.size();j++)
	// {
		// cout<<j<<" ";
	// }
	// cout<<endl;
	for(int i=1;i<=n;i++)
	{
		if(i>2)
		{
			dp[i]+=dp[i-1];
		}
		for(int j=0;j<v.size();j++)
		{
			if(i+v[j].first<=n)
			dp[i+v[j].first]=(dp[i+v[j].first]+dp[i]+mod)%mod;
			if(i+v[j].second+1<=n)
			{
				dp[i+v[j].second+1]=(dp[i+v[j].second+1]-dp[i]+mod)%mod;
			}
			
		}
		// for(int i=1;i<=n;i++)
		// {
			// cout<<dp[i]<<" ";
		// }
		// cout<<endl;
	}
	cout<<(dp[n]+mod)%mod<<endl;
	return 0;
}


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

int main() {
	int h, w;
	cin >> h >> w;
	char s[52][52];
	//s[h][w]
	for (int i = 1; i <= h; i++)
		for (int j = 1; j <= w; j++)
			cin >> s[i][j];
	for (int i = 0; i <= w + 1; i++) {
		s[0][i] = '.';
		s[h + 1][i] = '.';
	}
	for (int i = 1; i <= h; i++) {
		s[i][0] = '.';
		s[i][w + 1] = '.';
	}
	int t[52][52];
	int count = 0;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (s[i - 1][j - 1] == '#')
				count++;
			if (s[i - 1][j] == '#')
				count++;
			if (s[i][j - 1] == '#')
				count++;
			if (s[i + 1][j + 1] == '#')
				count++;
			if (s[i + 1][j] == '#')
				count++;
			if (s[i][j + 1] == '#')
				count++;
			if (s[i + 1][j - 1] == '#')
				count++;
			if (s[i - 1][j + 1] == '#')
				count++;
			t[i][j] = count;
			count = 0;
		}
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (s[i][j] == '.')
				s[i][j] = t[i][j] + 48;
			cout << s[i][j];
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int K;
    cin >> K;
    int N;
    cin  >> N; 
    int A[N];
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    int  m=0;
    for(int i=0;i<N-1;i++){
        m = max(m,A[i+1]-A[i]);
    }
    m=max(m,K+A[0]-A[N-1]);
    int Ans = K-m;
    cout << Ans << endl;
}


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

int main()
{
    int n;

    while( cin >> n )
    {
        if( n == 0 )
            break;

        int max = 0, max2 = -1000000;
        int sum = 0;
        int a[n];
        for( int i = 0; i < n; i++ )
        {    
            cin >> a[i];

            if( a[i] > 0 )
            {
                sum += a[i];
                if( max < sum )
                    max = sum;
            }
            else
            {
                if( sum + a[i] > 0 )
                    sum += a[i];
                else
                    sum = 0;
            }
            
            if( max2 < a[i] )           //全てが負の値だった時に、その中でも最大の値を格納。
                max2 = a[i];
        }
        if( max == 0 )
            cout << max2 << endl;
        else
            cout << max << endl;
    }
    return 0;
}


Measured memory_bytes: 3140
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			bool[] p = Enumerable.Repeat(true, 105000).ToArray();
			p[0] = p[1] = false;
			for (int i = 2; i < Math.Sqrt(p.Length); i++)
				if (p[i])
					for (int j = i * 2; j < p.Length; j++)
						if (j % i == 0)
							p[j] = false;
			var ps = p.Select((v, i) => new { v, i }).Where(v => v.v).Select(v => v.i).ToArray();

			var n = 0;
			while((n=int.Parse(Console.ReadLine()))!=0)
			{
				var r = ps.Take(n).Sum();
				Console.WriteLine(r);
			}
		}
	}
}

Measured memory_bytes: 6304
import java.io.*;
import java.util.stream.*;

public class Main {
  public static void main(String[] args) {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    br.lines()
      .map(line -> line.split(" "))
      .map(ar -> Stream.of(ar).mapToInt(Integer::parseInt).sum())
      .map(String::valueOf)
      .mapToInt(str -> str.length())
      .forEach(System.out::println);
  }
}

Measured memory_bytes: 30232
#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;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int dp[100100][3];

int solve(int n, vector<vector<int>> v) {
	memset(dp, 0, sizeof(dp));
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < 3; j++) {
			dp[i][j] = v[i-1][j] + max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3]);
		}
	}
	int res = 0;
	rep(j,3) res = max(res, dp[n][j]);
	return res;
}

int main() {
	int n;
	cin >> n;
	vector<vector<int>> v(n, vector<int>(3));
	rep(i,n) cin >> v[i][0] >> v[i][1] >> v[i][2];
	cout << solve(n, v) << endl;
}

Measured memory_bytes: 15388
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,e)for(int i=0;i<e;i++)
using namespace std;

int main(){
    int n, i, a;
    cin >> n;
    vector<int> v;
    rep(i, n){
        cin >> a;
        v.push_back(a);
    }
    for(i=n-1;i>0;i--) cout << v[i] << " ";
    cout << v[0] << endl;
    return 0;
}


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

int main() {
    int A,B,C,D,E,F;
    cin>>A>>B>>C>>D>>E>>F;

    float max=0.0;
    int max_water=0;
    int max_sugar=0;

    for(int a=0; a*100*A<=F; a++) {
        for(int b=0; a*100*A+b*100*B<=F; b++) {
            int water=a*100*A+b*100*B;
            for(int c=0; c*C<=E*water/100 ;c++) {
                for(int d=0; c*C+d*D<=E*water/100; d++) {
                    int sugar=c*C+d*D;
                    float nodo=(water==0?0.0:(float)sugar/((float)water+(float)sugar));
                    if(water+sugar<=F && max<nodo) {
                        max=nodo;
                        max_water=water;
                        max_sugar=sugar;
                    }
                }

            }
        }
    }
    if(max==0.0) max_water=100*A;
    cout<<max_water+max_sugar<<' '<<max_sugar<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<iomanip>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#define INF  int(1e6+1)
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

int main()
{
	int n;
	cin >> n;
	cout << 8 - (n - 400) / 200 << endl;
}



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

int main() {
    int k, n; cin >> k >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    a.push_back(a[0] + k);
    int l = 0;
    for (int i = 0; i < n; i++) {
        l = max(l, a[i+1] - a[i]);
    }
    cout << k - l << endl;
    return 0;
}

Measured memory_bytes: 1792
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,m = LI()
x = LI()
x.sort()
lst = []
for i in range(m-1):
    lst.append(x[i+1]-x[i])
lst.sort(reverse=1)
if n >= m:
    print(0)
    quit()
print(sum(lst[n-1:]))

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

int main() {
    
   unsigned long long int i,k,a,b,n,n1,ff;
    
    cin>>n1;
    
    b=0;
    n=1;
    k=0;
    for(i=0;i<n1;i++)
    {
        cin>>a;
        
        if(a==0)
        {
          k=2;    
            
        }
        
       if(b!=2)
       {
           ff=a*n;
           
           if(ff/n==a)
           {
               
              if(a*n<=1000000000000000000)
              {
                  n=a*n;
                  
                  
                  
              }
              
              else
              b=2;
              
               
           }
          
           
           
         else
       {
          
           b=2;
           
       }
           
       }
       
      
        
        
        
    }
    
    if(k==2)
    cout<<0;
    
    else if(b!=2)
    cout<<n;
    
    else
    cout<<-1;
	// your code goes here
	return 0;
}


Measured memory_bytes: 3632
#include <cstdio>
#include <cstring>
int main()
{
	int a , b;
	char  ch;
	while(~scanf("%d %c %d",&a , &ch ,&b))
	{
		 if(ch == '+')
		    printf("%d\n",a+b);
		    else
		    {
		    	      printf("%d\n",a-b);
			}
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    Int N, K; cin >> N >> K;
    vector<int> A(N); for (auto &a : A) cin >> a;
    vector<int> B(2*(int)1e5+1);
    iota(begin(B), end(B), 0);
    map<int, set<int>> M;
    for (int i = 0; i < B.size(); i++) M[B[i]].insert(i);
    for (int i = 0; i < N; i++) {
        vector<tuple<int, int, bool>> ops;
        for (auto j : M[0]) {
            B[j] = A[i];
            ops.emplace_back(0, j, false);
            ops.emplace_back(A[i], j, true);
        }
        for (auto j : M[A[i]]) {
            B[j] = 0;
            ops.emplace_back(A[i], j, false);
            ops.emplace_back(0, j, true);
        }
        for (auto t : ops) {
            int k, item; bool op;
            tie(k, item, op) = t;
            if (!op) {
                M[k].erase(item);
            } else {
                M[k].insert(item);
            }
        }
    }
    vector<int> C = {0};
    map<int, int> M2; M2[0] = 0;
    for (;;) {
        C.push_back(B[C.back()]);
        if (M2.count(C.back())) break;
    }
    int start = M2[C.back()];
    C.pop_back();
    int looplen = C.size() - start;
    K--;
    if (K >= start) {
        K = (K - start) % looplen + start;
    }
    vector<int> X;
    set<int> S;
    if (C[K]) {
        X.push_back(C[K]);
        S.insert(C[K]);
    }
    for (int i = 0; i < N; i++) {
        if (S.count(A[i])) {
            while (X.back() != A[i]) {
                S.erase(X.back());
                X.pop_back();
            }
            S.erase(X.back());
            X.pop_back();
        } else {
            S.insert(A[i]);
            X.push_back(A[i]);
        }
    }
    for (auto x : X) cout << x << ' ';
    cout << endl;
    return 0;
}

Measured memory_bytes: 42104
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		int n = scan.nextInt();
		int[] x = new int[n];
		int[] y = new int[n];
		for(int i = 0; i < n; i++){
			x[i] = scan.nextInt();
		}
		for(int i = 0; i < n; i++){
			y[i] = scan.nextInt();
		}

		double d1 = 0;
		double sum2 = 0;
		double sum3 = 0;
		double dd = 0;
		for(int i = 0; i < n; i++){
			d1 += Math.abs(x[i] - y[i]);
			sum2 += Math.pow(Math.abs(x[i] - y[i]), 2);
			sum3 += Math.pow(Math.abs(x[i] - y[i]), 3);
			dd = Math.max(dd, Math.abs(x[i] - y[i]));
		}
		double d2 = Math.sqrt(sum2);
		double d3 = Math.cbrt(sum3);
		System.out.printf("%f\n", d1);
		System.out.printf("%f\n", d2);
		System.out.printf("%f\n", d3);
		System.out.printf("%f\n", dd);
	}
}



Measured memory_bytes: 26584
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		for(; ; )
		{
			int n = scanner.nextInt();
			if(n == 0)
			{
				break;
			}
			
			int[][] a = new int[n][n];
			for(int i=0; i<n; i++)
			{
				for(int j=0; j<n; j++)
				{
					a[i][j] = scanner.nextInt();
				}
			}
			int[] sw = new int[n];
			int[] sh = new int[n];
			for(int i=0; i<n; i++)
			{
				for(int j=0; j<n; j++)
				{
					sw[i] += a[i][j];
					sh[i] += a[j][i];
					System.out.printf("%1$5d", a[i][j]);
				}
				System.out.printf("%1$5d\n", sw[i]);
			}
			
			int sum = 0;
			for(int i=0; i<n; i++)
			{
				sum += sh[i];
				System.out.printf("%1$5d", sh[i]);
			}
			System.out.printf("%1$5d\n", sum);
		}
	}
}

Measured memory_bytes: 32060
#include <stdio.h>
 
int main(void){
  int a,b,c,d,i;
  int count1=0;
  int count2=0;
  scanf("%d %d %d %d", &a, &b, &c, &d);

  for(i=0; c>0; i++){
    c -= b;
    count1++; //高橋くんの攻撃回数
  }
  for(i=0; a>0; i++){
    a -= d;
    count2 ++;//青木くんの攻撃回数
  }

  if(count1<=count2)
  printf("Yes");
  else
  printf("No");
  
  
  return 0;
}

Measured memory_bytes: 1684
#include <bits/stdc++.h>
using namespace std;
#define FIND(c, e) ((c).find(e) != (c).end())
#define NFIND(c, e) ((c).find(e) == (c).end())
#define ALL(t) (t).begin(), (t).end()
#define ALLR(t) (t).rbegin(), (t).rend()
#define MP make_pair
template<class T> T max(T a,T b,T c){return max(max(a,b),c);}
template<class T> T min(T a,T b,T c){return min(min(a,b),c);}
const int MOD = int( 1e9 ) + 7;
const int N = int( 1e5 ) + 42;

set<string> vs;
void __answer()
{
    int k;
    string s;
    cin >> s >> k;
    for(int i = 0; i < s.size(); i++) {
        for(int j = 0; j < k; j++) {
            vs.insert(s.substr(i, j + 1));
        }
    }
    set<string>::iterator i = vs.begin();
    while(--k) i++;
    cout << *i;
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cout << setprecision(1) << fixed;
    #ifdef LOCAL
        freopen("TEST2.txt", "r", stdin);
    #endif
    __answer();
    return 0;
}


Measured memory_bytes: 1664
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

struct Point{
	double x,y;
};

typedef Point Vector;

struct Segment{
	void set(double x1,double y1,double x2,double y2){
		p1.x = x1;
		p1.y = y1;
		p2.x = x2;
		p2.y = y2;
	}
	Point p1,p2;
};

typedef Segment Line;

int func(double x1,double y1,double x2, double y2, double xp, double yp){
	double naiseki,norm1,norm2,gaiseki;
	norm1 = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
	norm2 = sqrt((xp-x1)*(xp-x1)+(yp-y1)*(yp-y1));
	naiseki = (xp-x1)*(x2-x1)+(yp-y1)*(y2-y1);
	gaiseki = (x2-x1)*(yp-y1)-(xp-x1)*(y2-y1);
	if(gaiseki > EPS){
		return 1;
	}else if(gaiseki < -EPS){
		return -1;
	}
	if(naiseki < -EPS){
		return 2;
	}

	if(norm1 < norm2){
		return -2;
	}
	return 0;
}

double cross(Vector a,Vector b){
	return a.x*b.y-a.y*b.x;
}

double dot(Vector a,Vector b){
	return a.x*b.x + a.y*b.y;
}

Point calc_minus(Point a,Point b){
	Point ret;

	ret.x = a.x-b.x;
	ret.y = a.y-b.y;

	return ret;
}

double calc_len(Vector a){
	return sqrt(a.x*a.x+a.y*a.y);
}

double getDistanceLP(Line l,Point p){
	return fabs(cross(calc_minus(l.p2,l.p1),calc_minus(p,l.p1))/calc_len(calc_minus(l.p2,l.p1)));
}

double getDistanceSP(Segment s,Point p){
	if(dot(calc_minus(s.p2,s.p1),calc_minus(p,s.p1)) < 0.0)return calc_len(calc_minus(p,s.p1));
	if(dot(calc_minus(s.p1,s.p2),calc_minus(p,s.p2)) < 0.0)return calc_len(calc_minus(p,s.p2));
	return getDistanceLP(s,p);
}

double getDistance(Segment s1,Segment s2){
	return min(min(getDistanceSP(s1,s2.p1),getDistanceSP(s1,s2.p2)),
			min(getDistanceSP(s2,s1.p1),getDistanceSP(s2,s1.p2)));
}

int main(){
	double x1,x2,x3,x4,y1,y2,y3,y4;
	int q;
	scanf("%d",&q);

	for(int i=0;i<q;i++){
		scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);

		if(func(x1,y1,x2,y2,x3,y3)*func(x1,y1,x2,y2,x4,y4) <= 0 &&
				func(x3,y3,x4,y4,x1,y1) * func(x3,y3,x4,y4,x2,y2) <= 0){
			printf("0.0000000000\n");
			continue;
		}

		Segment s1,s2;
		s1.set(x1,y1,x2,y2);
		s2.set(x3,y3,x4,y4);

		printf("%.10lf\n",getDistance(s1,s2));
	}

    return 0;
}

Measured memory_bytes: 3144
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int h,n;
	cin>>h>>n;
	int arr[n];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	
	long long sum=0;
	for(int i=0;i<n;i++){
		sum+=arr[i];
	}

	if(sum>=h){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}

	return 0;

	

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, k;
    cin >> n >> k;
    int cnt = 0;
    if (n == 0) {
        cout << 1;
        return 0;
    }
    while (n) {
        n /= k;
        cnt++;
    }
    cout << cnt;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
const ll INF=1e18+7;
const ll MOD=1e9+7;
const ll N = 2003;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n,a,b,c,d;
	cin>>n>>a>>b>>c>>d;
	bool ans = false;
	FOR(i,0,n){
		ll l = c*(n-1-i)-d*i;
		ll r = d*(n-1-i)-c*i;
		if(l<=(b-a)&&(b-a)<=r)ans = true;
	}
	if(ans)pri("YES");
	else pri("NO");
}

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

int gcm(int a, int b){
    if(b > a){
        int tmp = a;
        a = b;
        b = tmp;
    }
    
    if(a % b == 0)return b;
    else return gcm(b, a % b);
}

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i= 0; i < n; i++){
        cin >> a.at(i);
    }
    
    int g = gcm(a.at(0), a.at(1));
    
    for(int i = 2; i < n; i++){
        g = gcm(g,a.at(i));
    }
    
    cout << g << endl;
    
}

Measured memory_bytes: 640
#include<stdio.h>
#define N 100

int main(){
  int n, a[N], i;
  
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&a[i]);
  for(i=n-1;i>0;i--) printf("%d ",a[i]);
  printf("%d\n",a[0]);
  
  return 0;
}



Measured memory_bytes: 2148
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <numeric>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
int INF = 1e9;

int h,w,k;

// vector<int> del(vector<int> v,int &score){
// 	int n = v.size();
// 	vector<int> ret(n);
// 	ret = v;
// 	rep(i,n-k+1){
// 		int temp = ret[i];
// 		if(temp == 0) continue;
// 		bool flag = true;
// 		rep(j,k) {
// 			if(ret[i+j] != temp){
// 				flag = false;
// 				break;
// 			}
// 		}
// 		if(flag) {
// 			int ind = i;
// 			while(ret[ind]==temp){
// 				ret[ind]=0;
// 				ind++;
// 			}
// 			score += (ind-i)*temp;
// 		}
// 	}
// 	return ret;
// }
bool del(vector<int> &v,int &score){
	int n = v.size();
	int ad = 0;
	rep(i,n-k+1){
		int temp = v[i];
		if(temp == 0) continue;
		bool flag = true;
		rep(j,k) {
			if(v[i+j] != temp){
				flag = false;
				break;
			}
		}
		if(flag) {
			int ind = i;
			while(v[ind]==temp){
				v[ind]=0;
				ind++;
			}
			ad += (ind-i)*temp;
		}
	}
	//cout << ad << " ad" << endl;

	if(ad > 0) {
		score += ad;
		return true;
	}else{
		return false;
	}
}

int clr(vector<vector<int>> &G){
	int score = 0;
	int num = 0;
	for(int i = h;i>0;i--){
		if(del(G[i],score)) num++;
	}
	rep(nu,num){
		rep(j,w){
			for(int i = h;i > 0;i--){
				if(G[i][j]==0){
					int dummy = G[i-1][j];
					G[i-1][j] = G[i][j];
					G[i][j] = dummy;
				}
			}
		}
	}
	return score;
}

int main(){
	cin >> h >> w >> k;
	vector<vector<int>> G(33,vector<int>(33,0));
	rep(i,h){
		string s;cin >> s;
		rep(j,w) G[i+1][j] = s[j]-'0';
	}

	int ans = 0;
	for(int i = 1;i<=h;i++)rep(j,w){
		vector<vector<int>> H;
		H = G;
		H[i][j] = 0;
		for(int y = i;y>0;y--){
			int dummy = H[y-1][j];
			H[y-1][j] = H[y][j];
			H[y][j] = dummy;
		}
		// rep(y,h){
		// 	cout << endl;
		// 	rep(x,w) cout << H[y+1][x] << " ";
		// }
		// int du;cin >> du;
		int ind = 1;
		int score = 1;
		int sum = 0;
		while(score != 0){
			score = clr(H)*ind;
			sum += score;
			ind*=2;
		}
		//printf("%d %d %d\n",i,j,sum);
		ans = max(ans,sum);
	}
	cout << ans << endl;

}
 
 

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const unsigned long MAX = 1000000000000000000;
signed main()
{   
  gearup;
  int n; cin >> n;
  vl a(n);
  rep(i,n){
    cin >> a[i];
    if(a[i] == 0){
      out(0);
      return 0;
    }
  }
  ll now = a[0];
  ll ma = a[0];
  rep1(i,n){
    now *= a[i];
    ma = max(now,ma);
    if(ma > now || now > MAX){
      out(-1);
      return 0;
    }
  }
  out(now);
}

Measured memory_bytes: 3960
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if (c<=a) cout << 0 << endl;
  else if (c>a+b) cout << "NA" << endl;
  else cout << c-a << endl;
}



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

using namespace std;
long long sum(long long n)
{
    return (n * (n+1))/2;
}

int main()
{
    long long n;
    cin>>n;
    long long cn = n;
    long long cn1, cn2;
    cn1 = n;
    cn2 = n;
    while(cn%3!=0)
    {
        cn--;
    }
    while(cn1%5!=0)
    {
        cn1--;
    }
    while(cn2%15!=0)
    {
        cn2--;
    }
    long long s  = 0;
    s = s + sum(n) - 3* sum(cn/3) - 5*sum (cn1/5) + 15*sum(cn2/15);
    cout<<s<<"\n";

    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int n,A,B,C,l[15];

int dfs(int a,int b,int c,int cur){
  int res=1e9;
  if (cur==n){
    if (a==0 || b==0 || c==0) return 1e9;
    else return abs(A-a)+abs(B-b)+abs(C-c)-30;
  }
  res=min(res,dfs(a+l[cur],b,c,cur+1)+10);
  res=min(res,dfs(a,b+l[cur],c,cur+1)+10);
  res=min(res,dfs(a,b,c+l[cur],cur+1)+10);
  res=min(res,dfs(a,b,c,cur+1));
  return res;
}


int main(void){
  int i;
  
  cin >> n >> A >> B >> C;
  for (i=0;i<n;i++) cin >> l[i];
  
  cout << dfs(0,0,0,0) << endl;
  
  return 0;
}

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

  int64_t A,B,K;cin>>A>>B>>K;
  
  if(K<=A){
    cout<<A-K<<" "<<B<<endl;
  }
  else if(A<K && K-A<B){
    cout<<0<<" "<<B-K+A<<endl;
  }
  else{
    cout<<0<<" "<<0<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

int main(){
    ll n;
    cin >> n;
    if (n%2!=0){
        cout << n*2 << endl;
        return 0;
    }
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxN = 2e5+7;
const int maxV = 90010;
//const int INF = 1e9+9;
//const ll INF = (1ll)<<60;
const int INF = 2e9+9;
const int MOD = 998244353;

int n;
int a[maxN];
int b[maxN];
vector<int> v[maxN];
int vis[maxN];
int c[maxN];
ll d[maxN];
int main()
{
	//scanf("%d",&n);
	for(int i=1;i<=3;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a+1,a+4);
	int ans = a[1] + a[2];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int q, n;
  cin >> q >> n;
  vector<vector<int>> wt(n, vector<int>(n, 0));
  for (int _ = 0; _ < q; _++) {
    int i, j;
    cin >> i >> j;
    i %= 2 * n;
    j %= 2 * n;
    int par = 0;
    if (i >= n) {
      i -= n;
      par ^= 1;
    }
    if (j >= n) {
      j -= n;
      par ^= 1;
    }
    char clr;
    cin >> clr;
    par ^= (clr == 'W');
    if (!par) {
      wt[i][j]++;
    } else {
      wt[i][j]--;
    }
  }
  vector<vector<int>> ac(n + 1, vector<int>(n + 1, 0));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      ac[i][j] = ac[i - 1][j] + ac[i][j - 1] - ac[i - 1][j - 1] + wt[i - 1][j - 1];
    }
  }
  int ans = 0;
  for (int di = 0; di < n; di++) {
    for (int dj = 0; dj < n; dj++) {
      int tmp = ac[n][n] - 2 * ac[n][dj] - 2 * ac[di][n] + 4 * ac[di][dj];
      ans = max(ans, abs(tmp));
    }
  }
  ans = (ans + q) / 2;
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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; }


vector<ll> v;
ll mid = -1;

void enum_div(ll n)//nの約数を列挙
{
	for(ll i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			v.push_back(i);
			if(i!=1)
			{
				v.push_back(n/i);
        if((n/i+i-2)<mid) mid = n/i+i-2;
        // if(i>100000) cout << i << " " << mid << endl;
			}
		}
	}
}


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

  mid = a-1;

  enum_div(a);

  cout << mid << endl;



}



Measured memory_bytes: 384