akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
#define SP << " " <<
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "NO" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  998244353
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------
char S[2020][2020];
ll ao[2020][2020];
ll rentate[2020][2020];
ll renyoko[2020][2020];
ll ren[2020][2020];

ll solve(ll x,ll y,ll x2,ll y2){
    ll res=0;
    res+=ao[x2][y2]-ao[x][y2]-ao[x2][y]+ao[x][y];
    res-=rentate[x2-1][y2]-rentate[x][y2]-rentate[x2-1][y]+rentate[x][y];
    res-=renyoko[x2][y2-1]-renyoko[x][y2-1]-renyoko[x2][y]+renyoko[x][y];
    return res;
}
//--MAIN-----------------------------------
void Main() {
    ll N,M,Q; cin>>N>>M>>Q;
    rep(i,N){
        rep(j,M){
            cin>>S[i][j];
            if(S[i][j]=='1') ao[i+1][j+1]=1;
        }
    }
    rep(i,N){
        rep(j,M){
            if(S[i][j]=='1' and S[i+1][j]=='1') rentate[i+1][j+1]=1;
            if(S[i][j]=='1' and S[i][j+1]=='1') renyoko[i+1][j+1]=1;
        }
    }
    reps(i,1,N+1){
        reps(j,1,M+1){
            ao[i][j]+=ao[i-1][j]+ao[i][j-1]-ao[i-1][j-1];
            rentate[i][j]+=rentate[i-1][j]+rentate[i][j-1]-rentate[i-1][j-1];
            renyoko[i][j]+=renyoko[i-1][j]+renyoko[i][j-1]-renyoko[i-1][j-1];
        }
    }
    while(Q--){
        ll x,y,x2,y2; cin>>x>>y>>x2>>y2;
        cout<< solve(x-1,y-1,x2,y2) <<"\n";
    }
}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 102528
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
using namespace std;
int main()
{/*一日目*/
	int k;cin >> k; char s[101];cin >> s;
	string s1 = "...";
	if (strlen(s) <= k)
		cout << s;
	else if(strlen(s) > k){
		for (int i = 0;i < k;i++)
			cout << s[i];
		cout << s1;
		
		}	
}

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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

ll mod=1000000007;

const ll INF = 1LL << 60;

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

int main(){
  int n;cin>>n;
  vector<int> b(101010);
  rep(i,n){
    int a;cin>>a;
    b[a]=(1-(b[a]+1)%2)+1;
  }
  int odd=0;
  int even=0;
  for(int x:b){odd+=(x==1?1:0);even+=(x==2?1:0);}
  cout<<even/2*2+odd;
}


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

int main() {
  int n;
  cin >> n;
  int s=0;
  int t=0;
  int a[100]; 
  int b[100];
  int c[100];
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i) cin >> b[i];
    for (int i = 1; i <= n-1; ++i) cin >> c[i];
  
        for (int i = 1; i <= n; ++i) {
          s = s + b[i];
        }
        for (int i=1;i<=n;++i){
           if((a[i] - 1) == a[i-1]  ){
             t = a[i-1];
             s = s + c[t];
           }
        }
    
  cout << s << endl;
  }


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		String name=sc.next();
		String board;
		int distant,now,count=0;
		
		for(int i=0;i<n;i++){
			board=sc.next();
		out:	for(int j=0;j<board.length();j++){//看板のj文字目を参照
				if(name.charAt(0)==board.charAt(j)){//名前の１文字目と看板のj文字目が一致したとき
					for(int k=j+1;k<board.length();k++){//次の文字と一致する看板の文字を探す
						if(name.charAt(1)==board.charAt(k)){//2文字目が一致したら
							distant=k-j;//j文字目とj+1文字目の距離をとる
							now=2;
							for(int l=k+distant;l<board.length();l=l+distant){//k（j＋１）文字目からdistantだけ離れた位置に
								if(name.charAt(now)==board.charAt(l)){//3文字目があったとき
									if(now==name.length()-1){//nowが最後の文字を参照していたら
										count++;//その看板は条件をクリアしている
										break out;//次の看板の入力に移る
									}
									now++;//k+2...name.length();　distant間隔に目的の文字があったとき次の文字へ移動？
								}
								else break;//distantの距離に次の文字がなければ、看板の次の２文字目を探す
							}
						}
					}
				}
			}
		}
		System.out.println(count);
	}

}

Measured memory_bytes: 20488
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <queue>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <cmath>
#include <iomanip>
using namespace std;
#define sL(i) i << 1
#define sR(i) i << 1 | 1
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pair<int,int>, int> ppi;
const int MOD = 1e9 + 7;
const int INF = 2e9 + 5;

int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 31, 31, 30, 31};
int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    int cnt = 0;
    for(int i = 1; i <= a; i++){
        for(int j = 1; j <= days[i]; j++){
            if(i == a && j > b) break;
            if(i == j) ++cnt;
        }
    }
    cout << cnt;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;

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

__attribute__ ((constructor))
void init() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
}

int main(){
    int n;
    cin >> n;
    cout << "ABC" << n << endl;
    return 0;
}

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

 using namespace std;

  int Arr[100];
  int  main(){
   int N;
   scanf("%d",&N);
   for(int i=0;i<N;i++){
    scanf("%d",&Arr[i]);
   }
   int Ans,Min = INT_MAX;
   for(int i=-100;i<=100;i++){
        Ans = 0;
    for(int j=0;j<N;j++){
        Ans += (Arr[j]-i)*(Arr[j]-i);
    }
    Min = min(Ans,Min);
   }
   printf("%d",Min);
  }


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

using namespace std;
typedef long long ll;

int main()
{
	//freopen("t.txt","r",stdin);
	int n, l[1111],x,d[1111];
	cin>>n>>x;
	d[1]=0;
	for (int i=1;i<=n;i++){
		cin>>l[i];
	}
	int kq;
	for (int i=2;i<=n;i++){
		d[i]=d[i-1]+l[i-1];
		if (d[i]==x){
			cout<<i; return 0;
		}
		if (d[i]>x){
			cout<<i-1; return 0;
			
		}
		
	}
	cout<<n+1;
	return 0;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
int main(void){
    int a,b;
    int n,s,f;
    int tim[1010]={0};
    cin>>a>>b;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s>>f;
        for(int j=s;j<f;j++){
            tim[j]=1;
        }
    }
    int ans=0;
    for(int i=a;i<b;i++){
        if(tim[i]==1){
            ans=1;
            break;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3108
#include "bits/stdc++.h"
using namespace std;
#define F first
#define S second
#define s(x) #x<<" "<<x<<" | "<<
#define f(i,j,k) for(int i = j;i<=k;i++)
#define fr(i,j,k) for(int i = j;i>=k;i--)
#define ll long long
#define all(A)  A.begin(),A.end()  
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);  
#define endl "\n"
const int MSIZE = 1e5+5;;
const int MOD = 1e9+7;
 
 
int psum[MSIZE];
 
int main(){
 
    FIO
    int arr[5];
    int ans = 0;
    f(i,1,5)   {
        cin>>arr[i];  if(!ans and !arr[i])  ans = i;
    } 
    cout<<ans<<endl;
 
 
} 

Measured memory_bytes: 3632
n,t=gets.split.map(&:to_i)
ab=[]
m=0
n.times do
  a,b=gets.split.map(&:to_i)
  ab << [a,b]
  m=a if a>m
end
dp=[0]*(t+m+1)
ab.sort.each do |a,b|
  (t+a-1).downto(a) do |j|
    if dp[j]<b+dp[j-a]
      dp[j]=b+dp[j-a]
    end
  end
end
puts dp.max


Measured memory_bytes: 2172
#include<stdio.h>
int main(){
    int n;
    int x;
    int i;
    scanf("%d", &n);
    for(i = 1;i <= n;i++){
        x = i;
        if(i % 3 == 0){
            printf(" %d", i);
            continue;
        }
        do{
            if(x % 10 == 3){
                printf(" %d", i);
                break;
            }
            x /= 10;
        }while(x);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2096
def devide(elements):
    cnt = 0
    while True:
        for i, element in enumerate(elements):
            if element % 2 != 0:
                return cnt
            elements[i] = element / 2
        cnt += 1
    return cnt

_ = raw_input()
elements = map(int, raw_input().split())
print devide(elements)

Measured memory_bytes: 2568
<?php
$ans = fgets(STDIN);
$input = explode(" ", $ans);
$input = array_map(function ($i) { return (int)$i; }, $input);

$sum = 0;

for ($i = 1; $i <= $input[0]; $i++) {
  $_5 = $i / 10000 % 10;
  $_4 = $i / 1000 % 10;
  $_3 = $i / 100 % 10;
  $_2 = $i / 10 % 10;
  $_1 = $i % 10;
  $_sum = $_5 + $_4 + $_3 + $_2 + $_1;
  if ($input[1] <= $_sum && $_sum <= $input[2]) {
    $sum += $i;
  }
}

echo $sum;

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

using namespace std;

#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define allarr(a) a , a + n
#define ll long long
#define ull unsigned long long 
#define pb push_back
#define fastio ios_base::sync_with_stdio(false) ; cin.tie(NULL); cout.tie(NULL)
typedef pair<int, int> pi;
typedef pair<ll,ll> pll; 
typedef pair<int,pi> trp ;
typedef vector<pi> vpi;
typedef vector<pll> vpll ;
// int ab  (int  x ) { return (x>0?x:-x); }

vector<pi> ans ; 
int main(){
	int n , k ; 
	cin >> n >> k ; 
	for( int i = 2 ; i <= n ; i++ ){
		ans.pb( {i,1} ); 
	}
	int x = ((ans.size()-1)*ans.size())/2 ; 
	bool solution = 1 ; 
	if( x < k ){
		solution = 0 ; 
	}
	x = x - k ; 
	for(int i = 2 ; i <= n ; i++ ){
		for(int j = i + 1 ; j <= n ;j++ ){
			if( x == 0 )break ; 
			ans.pb({i,j}); 
			x--; 
		}
	}
	if( x || !solution ){
		cout << -1 << endl; 
		return 0 ; 
	}
	cout << ans.size() << endl; 
	for(pi a : ans ) cout << a.fi << " " << a.se << endl; 
}




Measured memory_bytes: 384
#include<stdio.h>

int main(){

  int i,j,k;
  int N,D,X;
  int s=0;
  
  scanf("%d",&N);
  scanf("%d %d",&D,&X);
  int A[N];
  int B[N];
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
	B[i]=A[i];
  }   
  
  s += N;
  
  for(i=2;i<=D;i++){
    for(j=0;j<N;j++){
      if((i) == A[j]+1){
        s++;
        A[j]+=B[j];
      }
    }
  }
  
  printf("%d\n",s+X);
  return 0;
}

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

using namespace std;

int main()
{
    int n;
    map<int, int> count;

    cin >> n;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        count[a]++;
    }

    int ans = 0;
    for (auto p : count) {
        if (p.first == p.second)
            continue;
        int diff = p.first > p.second ? p.second : p.second - p.first;
        ans += diff;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4736
#include<iostream>
#include <functional>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <stdio.h>
using namespace std;


int main(){    
  int N,Y;
  cin >> N >> Y;
  int x,y,z;
  
  for(z=0;z<N+1;z++){
    for(y=0;y<N+1;y++){
      if(0 <= N-y-z && N-y-z <= 2000){
	if((N-y-z)*10000 + y*5000 + z*1000 == Y){
	  cout << N-y-z << " " << y << " " << z << " " << endl;
	  return 0;
	}
      }
    }
  }
  cout << "-1 "<< "-1 "<< "-1 " << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;
map<string, int> mp;
int mx = -1;

void input() {
  ;
  cin >> N;
  rep(i, 1, N) {
    string s;
    cin >> s;
    mp[s]++;
    chmax(mx, mp[s]);
  };
}
void solve() {
  for (auto x : mp) {
    if (x.second == mx) {
      cout << x.first << endl;
    }
  };
  ;
}
signed main() {
  cout << setprecision(12);
  input();
  solve();
  return 0;
}

Measured memory_bytes: 25216
n = int(input())
w = [input() for _ in range(n)]

correct = True
for i in range(len(w)):
    if w[i] in w[i + 1:]:
        correct = False
        break
    if i > 0 and w[i][0] != w[i - 1][-1]:
        correct = False
        break

if correct:
    print("Yes")
else:
    print("No")


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b;
  string s;
  cin >> s;
  cout << s.substr(0,4) + " " + s.substr(4) << endl;
  return 0;
}



Measured memory_bytes: 384
#include <stdio.h>

int main()
{
    int S;
    int h, m, s;

    scanf("%d", &S);

    h = S / 3600;
    S = S % 3600;

    m = S / 60;
    S = S % 60;

    s = S;

    printf("%d:%d:%d\n", h, m, s);

    return 0;
}

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

using namespace std;

int main(){
 string s;
  cin >> s;
  
  int num[3]={0};
  for(int i=0;i<s.size();i++) num[s[i]-'a']++;

  if(max({num[0],num[1],num[2]})-min({num[0],num[1],num[2]})<=1) cout << "YES" << endl;
  else cout << "NO" << endl;
  
}


Measured memory_bytes: 512
n = gets.to_i
a = gets.split.map(&:to_i)
a.unshift(0)
a.push(0)
sum = 0
for i in 1..(n + 1) do
  sum += (a[i] - a[i - 1]).abs
end
for i in 1..n do
  puts sum - (a[i] - a[i - 1]).abs - (a[i + 1] - a[i]).abs + (a[i + 1] - a[i - 1]).abs
end


Measured memory_bytes: 21516
// ------------------------------------
// Date:2018/ 3/20
// Problem:Exactly N points b.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") <<　endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

static const int MOD = 1e9 + 7;
static const int MAX_N = 1e7 + 1;

int main()
{
  int N;
  scanf("%d", &N);
  int t = 1;
  REP(i, MAX_N) {
    ll tmp = (1 + i) * i / 2;
    if (tmp >= N) break;
    t = i + 1;
  }
  for(int i = t; i > 0; --i) {
    if (N >= i) {
      printf("%d\n", i);
      N -= i;
    }
  }
  

  return 0;
}



Measured memory_bytes: 256
/*
💭             💭
    💭        💭
     💭     💭
  💭💭💭☁
💭🌘💭🌘☁
💭💭🌸💭☁
  ☁☁☁☁
      🎀🎀🎀☁
      💭💭💭💭☁
      🍴 💭🍴💭☁ 💭
      📨  ☁📨☁☁





😡😡😡😡😡😡😡
😁I'm so angry!😁
💀💀💀💀💀💀💀
😑😤😤😤😤😤😑
  🔥✂✂✂✂✂🔥
😡😡😡😡😡😡😡
*/#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define print(a) for(auto f:a)cout<<f<<" ";
#define sor(v) sort(v.begin(),v.end());
#define rsor(v) sort(v.rbegin(),v.rend());
#define rev(v) reverse(v.begin(),v.end())
#define all(v) (v.begin(),v.end())
#define fi first
#define se second
#define lp(x,q) for(ll i=x ;i<q;i++)
#define pb(x) push_back(x)
#define pob pop_back()
#define res(v,a) v.resize(a)
#define md(q,w)  (q+w)/2;
#define lp(q,w) for(ll x=q;x<w;x++)
#define MY_TORNADO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define minn(v) *min_element(v.begin(),v.end())
#define maxx(v) *max_element(v.begin(),v.end())
vector<vector<int>>adj;
vector<bool>vis(1e5,false);
vector<int>level(1e4);
//global variable:
ll cou=0,mx=INT_MIN,mn=INT_MAX,sum=0,av=0,hi=0,lo=0,ans=0,w,flag;



int main()
{int a,s;
cin>>a>>s;
vector<int>v(a);
sum=0;
for(int x=0;x<a;x++){
    cin>>v[x];
    sum+=v[x];
}
rsor(v);
for(int x=0;x<a&&x<s;x++){
    sum-=v[x];
}
cout<<sum;


}

















/*😢😖😩😫😩😖😢
😢💔💔😫💔💔😢
💔👤👥💔👤👥💔😢
💔👤👤👤👤👥💔😢
💔👤👤👤👤👥💔😢
😢💔👤👤👥💔😢
😢😖💔👥💔😖😢
😢😖😩💔😩😖😢
😢😖😩😫😩😖😢


*/


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
N,W = list(map(int,input().split()))
vw = [list(map(int,input().split())) for i in range(N)]
value = [i[0] for i in vw]
weight = [i[1] for i in vw]

inf=float("inf")
dp = [[-inf for _ in range(W+1)] for _ in range(N+1)]

dp[0] = [0]*(W+1)
def main():
    for i in range(N):
        w = 0
        while w <= W:
            if weight[i] <= w:
                dp[i+1][w]=max(dp[i][w-weight[i]]+value[i],dp[i][w])
            else:
                dp[i+1][w]=dp[i][w]
            w+=1
main()
print(dp[N][W])



Measured memory_bytes: 42532
#include<stdio.h>
int main(){
	int W, H, x, y, r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	if(x-r>=0&&y-r>=0&&x+r<=W&&y+r<=H){
		printf("Yes\n");
	} else {
		printf("No\n");
	}
	return 0;
}

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

int main() {
	ll a, b, c;
	cin >> a >> b >> c;
	if (c - a - b > 0 && (c - a - b) * (c - a - b) > 4 * a * b)cout << "Yes" << endl;
	else cout << "No" << endl;
	// a + 2root(ab) + b  < c
	//c-a-b>0 4ab<(c-a-b)^2
}


Measured memory_bytes: 256
if __name__ == "__main__":
    alpha = input()

    if alpha in ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']:
        print('A')
    else:
        print('a')

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

int main(){
  int N; cin >> N;
  if(N==1){
    cout << 1 << endl;
    return 0;
  }
  string S; cin >> S;
  int k=S.size();
  sort(S.begin(),S.end());
  S+='A';
  int count=2;
  long long ans=1;
  for(int i=1;i<=k;i++){
    if(S[i]==S[i-1]){
      count++;
    }
    else{
      ans*=count;
      ans%=1000000007;
      count=2;
    }
  }
  cout << ans-1 << endl;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		System.out.println( calc_debt( sc.nextInt() ) );
		sc.close();
	}

	private static long calc_debt(int nextInt) {
		int n = nextInt;
		long d = 100;

			for (int i = 0; i < n; i++) {
				d = (long)Math.ceil( d * 1.05);
			}
			
		long debt = d * 1000;
		return debt;
	}

}


Measured memory_bytes: 26132
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
//ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 1e5;
int A, B, M;
int a[N], b[N];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> A >> B >> M;
  FOR(i, 0, A) cin >> a[i];
  FOR(i, 0, B) cin >> b[i];
  int ans = IINF;
  FOR(_, 0, M){
    int x, y, c;
    cin >> x >> y >> c;
    x--; y--;
    mins(ans, a[x]+b[y]-c);
  }
  sort(a, a+A);
  sort(b, b+B);
  mins(ans, a[0]+b[0]);
  cout << ans << endl;
}

Measured memory_bytes: 4364
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  string a,b;
  while(cin>>a>>b){
    vector<vector<int> >dp(a.size()+1,vector<int>(b.size()+1));
    rep(i,a.size())rep(j,b.size()){
      //dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
      if(a[i]==b[j])dp[i+1][j+1]=max(dp[i][j]+1,dp[i+1][j+1]);
      
    }
    //cout<<" "<<b<<endl;
    //rep(i,a.size()){cout<<a[i];rep(j,b.size())cout<<dp[i+1][j+1];cout<<endl;}
    //cout<<dp[a.size()][b.size()]<<endl;
    int maxi=0;
    rep(i,a.size())rep(j,b.size())maxi=max(maxi,dp[i+1][j+1]);
    cout<<maxi<<endl;
  }
}

Measured memory_bytes: 63836
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  int M = 0, sum = 0;
  for(int i = 0; i < N; i++){
    cin >> a.at(i);
    M = max(M, a.at(i));
    sum += a.at(i);
  }
  cout << sum - M/2 << endl;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
typedef long long int LL;
typedef unsigned long long int ULL;

int main() {
    LL n, m;
    cin >> n >> m;
    vector<LL> a(n);
    vector<pair<LL, LL> > v(m);


    rep(i, n) {
        cin >> a[i];
    }
    rep(i, m) {
        LL b, c;
        cin >> b >> c;
        v[i] = make_pair(b, c);
    }
    sort(a.begin(), a.end());
    sort(v.begin(), v.end(), [](const auto &a, const auto &b){
                                 return a.second > b.second;
                             });

    vector<LL> ans(n, 0);
    LL cnt = 0;
    rep(i, m) {
        LL num_card = 0;
        while (num_card < v[i].first and cnt < n) {
            ans[cnt] = v[i].second;
            num_card++;
            cnt++;
        }
    }
    // rep(i, n) {
    //     cout << a[i] << ' ' << ans[i] << endl;
    // }

    LL index = n - 1;
    for (int i = n - 1; i >= 0; i--) {
        if (ans[i] < a[index]) {
            ans[i] = a[index];
            index--;
        }
    }
    LL sum = 0;
    rep(i, n) {
        sum += ans[i];
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

const long long MOD = 1e9 + 7;

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

	int N;
	cin >> N;

	vector<long long> A(N, 0);
	vector<long long> accumlist(N + 1, 0);

	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
		accumlist[i + 1] = accumlist[i] + A[i];
	}

	long long result = 0;
	for (int i = 0; i < N - 1; i++)
	{
		long long value = (accumlist[N] - accumlist[i + 1]) % MOD;
		value = (value * A[i]) % MOD;

		result = (result + value) % MOD;
	}

	cout << result;

	return 0;
}


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

#define debug(x) cerr << x << " = "(x) << endl;
#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,0,n) cin >> a[i];
    vector<ll> big(n);
    vector<ll> small(n);
    rep(i,0,n){
        big[i] = i-a[i];
        small[i] = i+a[i];
    }
    ll ans = 0;
    sort(all(big));
    sort(all(small));
    rep(i,0,n){
        ans += upper_bound(all(small),big[i]) - lower_bound(all(small),big[i]);
    }
    cout << ans << endl;

}

Measured memory_bytes: 7936
//
//  main.cpp
//  jumping ball
//
//  Created by RMBP on 2019/10/20.
//  Copyright 漏 2019 RMBP. All rights reserved.
//

#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    int n,m,a[100],i,b,c;
    c=1;
    b=0;
    cin>>n>>m;
    for (i=0;i<n;i++){
        cin>>a[i];
        b=b+a[i];
        
        if (b>m){
            break;
            
        }
        else if (b<=m){
            c=c+1;
        }
    }
    cout<<c;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class D
    {
        public static void Main()
        {
            var s = Console.ReadLine();
            var q = int.Parse(Console.ReadLine());

            bool reverse = false;

            var result = new char[s.Length + 2 * q];
            Array.Copy(s.ToCharArray(), 0, result, q, s.Length);


            int head = q;
            int foot = q + s.Length - 1;

            for (int i = 0; i < q; i++)
            {
                var query = Console.ReadLine();
                if (query[0] == '1')
                    reverse = !reverse;
                else if (query[2] == '1' ^ reverse)
                    result[--head] = query[4];
                else
                    result[++foot] = query[4];
            }

            if (reverse)
                for (int i = foot; i >= head; i--)
                    Console.Write(result[i]);
            else
                for (int i = head; i <= foot; i++)
                    Console.Write(result[i]);
            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 16860
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long ll;

const int INF = 1001001001;
int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> key;
    for (int i = 0; i < m; i++)
    {
        int a, b; cin >> a >> b;
        int able = 0;
        for (int j = 0; j < b; j++)
        {
            int c; cin >> c;
            c--;
            able = able | (1<<c);
        }
        key.emplace_back(a, able);
    }
    
    vector<int> dp(1<<n, INF);
    dp[0] = 0;
    for (int before = 0; before < (1<<n); before++) //beforeが遷移前の添字
    {
        for (int i = 0; i < m; i++)
        {
            int after = before | key[i].second;
            int cost = key[i].first + dp[before];
            dp[after] = min(dp[after], cost);
        }
    }
    int ans = dp.back();
    if(ans == INF) ans = -1;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

public class Main
{
    public static void main (String[] args)
    {
        // your code goes here
        Scanner s = new Scanner(System.in);
        int t = s.nextInt();
        if(t>=30)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}


Measured memory_bytes: 35696
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
void solve(); int main() { solve(); return 0; }

void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> A(n);
  loop(i,0,n) cin >> A[i];
  sort(A.begin(), A.end());
  ll total = 0;
  loop(i,0,k) total += A[i];
  cout << total << endl;
}


Measured memory_bytes: 3624
#pragma region include
    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <map>
    #include <string>
    #include <queue>
    #include <stack>
    #include <cmath>
    #include <set>
    #include <cstdio>
    #define ALL(obj) (obj).begin(),(obj).end()
    #define RALL(obj) (obj).rbegin(),(obj).rend()
    #define REP(i, n) for(int i = 0; i < n; i++)
    #define REPR(i, n) for(int i = n; i >= 0; i--)
    #define FOR(i, m, n) for(int i = m; i < n; i++)
    #define MOD 1000000007
    #define INF 1000000000
    #define LLINF 4000000000000000000
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> PII;
    typedef vector<int> VI;
    typedef vector<VI> VVI;
    #pragma endregion
     
    //#define __DEBUG__
    #ifdef  __DEBUG__
    #define dump(x) cerr << #x << " = " << (x) << " [" << __LINE__ << ":" << __FUNCTION__ << "] " << endl;
    // vector出力
    template<typename T>
    ostream& operator << (ostream& os, vector<T>& v) {
        os << "{";
        REP(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
        os << "}";
        return os;
    }
    // pair出力
    template<typename T, typename U>
    ostream& operator << (ostream& os, pair<T, U>& p) {
        return os << "(" << p.first << ", " << p.second << ")";
    }
    // map出力
    template<typename T, typename U>
    ostream& operator << (ostream& os, map<T, U>& map_var) {
        os << "{";
        for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
            os << "(" << itr->first << ", " << itr->second << ")";
            itr++;
            if (itr != map_var.end()) os << ", ";
            itr--;
        }
        os << "}";
        return os;
    }
    // set 出力
    template<typename T>
    ostream& operator << (ostream& os, set<T>& set_var) {
        os << "{";
        for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
            os << *itr;
            ++itr;
            if (itr != set_var.end()) os << ", ";
            itr--;
        }
        os << "}";
        return os;
    }
    #endif
     
    int main() {
        cin.tie(0); ios::sync_with_stdio(false);
        int N, K; cin >> N >> K;
        cout << N - K + 1 << endl;
        getchar(); getchar();
    }

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

int n,a,b;

vi rec(int a, int b, vi& g) {
  if (a == b) return vi{a};

  vi ret;
  for (int i = 0; i < n; i++) {
    if ((a ^ b) & (1<<i)) {
      vi g1, g2;
      int x = a, y = b;
      for (int c : g) {
        if ((a & (1 << i)) == (c & (1 << i))) {
          g1.push_back(c);
          if (popcnt(a)%2 != popcnt(c)%2 && a != c && b != (c ^ (1<<i))) {
            x = c;
            y = c ^ (1<<i);
          }
        } else {
          g2.push_back(c);
          if (popcnt(b)%2 != popcnt(c)%2 && b != c && a != (c ^ (1<<i))) {
            y = c;
            x = c ^ (1<<i);
          }
        }
      }
      ret = rec(a,x,g1);
      vi r2 = rec(y,b,g2);
      ret.insert(ret.end(),r2.begin(),r2.end());
      break;
    }
  }
  return ret;
}

int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  cin >> n >> a >> b;

  if (popcnt(a)%2 == popcnt(b)%2) {
    cout << "NO\n";
    return 0;
  }

  vi g;
  forn (i,1<<n) g.push_back(i);

  vi ans = rec(a,b,g);

  cout << "YES\n";
  forn (i,ans.size())
    cout << ans[i] << " \n"[i+1==(int)ans.size()];

  return 0;
}


Measured memory_bytes: 3096
def main():
    N, M = map(int, input().split())
    lights = []
    for i in range(M):
        lights.append(set(list(map(int, input().split()))[1:]))
    P = list(map(int, input().split()))
    switch_combs = []

    for i in range(2**N):
        tmp_comb = set()
        for j in range(N):
            if (i >> j) & 1:
                tmp_comb.add(j+1)
        switch_combs.append(tmp_comb)
    num_sum = 0

    for comb in switch_combs:
        for i in range(len(lights)):
            num_match = len(lights[i] & comb)
            if not num_match % 2 == P[i]:
                break
        else:
            num_sum += 1
    print(num_sum)


if __name__ == '__main__':
    main()

Measured memory_bytes: 74368
#![allow(non_snake_case,unused_imports,dead_code)]
use std::io::Read;
use std::cmp::max;
use std::cmp::min;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::BinaryHeap;
use std::cmp::Ordering;

fn comp_f64(a: &f64, b: &f64) -> Ordering {
    if a < b {
        return Ordering::Less;
    } else if a > b {
        return Ordering::Greater;
    }
    Ordering::Equal
}

fn main() {

    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut buf_it = buf.split_whitespace();

    let N = buf_it.next().unwrap().parse::<usize>().unwrap();
    let P = (0..N*N).map(|_| buf_it.next().unwrap().parse::<usize>().unwrap() -1).collect::<Vec<_>>();

    let mut ans = 0;
    let mut cost = (0..N).map(|_| (0..N).map(|_| 0).collect::<Vec<_>>()).collect::<Vec<_>>();
    let mut seated = (0..N).map(|_| (0..N).map(|_| 1).collect::<Vec<_>>()).collect::<Vec<_>>();
    for i in 0..N{
        for j in 0..N{
            let mut tmp = min(i,N-1-i);
            tmp = min(tmp,j);
            tmp = min(tmp,N-1-j);
            cost[i][j] = tmp;
        }
    }
    
    for p in P{
        let i = p%N;
        let j = p/N;
        ans += cost[i][j];
        seated[i][j] = 0;
        let mut q = vec![(i,j)];
        while q.len()>0{
            let mut qq = Vec::new();
            while q.len()>0{
                let (i,j) = q.pop().unwrap();
                let c = cost[i][j] + seated[i][j];
                let i = i as isize;
                let j = j as isize;
                for (di,dj) in vec![(1,0),(-1,0),(0,1),(0,-1)]{
                    let i = i+di;
                    let j = j+dj;
                    if i<0 || i>=(N as isize) || j<0 || j>=(N as isize) { continue;}
                    let i = i as usize;
                    let j = j as usize;
                    if cost[i][j] <= c{ continue;}
                    cost[i][j] = c;
                    qq.push((i,j));
                }
            }
            q = qq;
        }
    }

    println!("{}",ans);

}

Measured memory_bytes: 9580
#include <stdio.h>

int main(void){
  int A,B;
  int i,j;
  //read input
  scanf("%d %d",&A,&B);
  
  if(A%3==0){
    printf("Possible\n");
    return 0;
  }
  if(B%3==0){
    printf("Possible\n");
    return 0;
  }
  if((A+B)%3==0){
    printf("Possible\n");
    return 0;
  }
  printf("Impossible\n");
  return 0;
}

Measured memory_bytes: 128
# Sparse table (GCD)
from math import gcd


class SparseTable():
    _data = None
    _lookup = None
    _f = None

    def __init__(self, a):
        data = []
        lookup = []
        f = gcd
        b = 0
        while (1 << b) <= len(a):
            b += 1
        for _ in range(b):
            data.append([0] * (1 << b))
        data[0][:len(a)] = a
        for i in range(1, b):
            j = 0
            di = data[i]
            di1 = data[i - 1]
            while j + (1 << i) <= (1 << b):
                di[j] = f(di1[j], di1[j + (1 << (i - 1))])
                j += 1
        lookup = [0] * (len(a) + 1)
        for i in range(2, len(lookup)):
            lookup[i] = lookup[i >> 1] + 1
        self._data = data
        self._lookup = lookup
        self._f = f

    def query(self, start, stop):
        b = self._lookup[stop - start]
        db = self._data[b]
        return self._f(db[start], db[stop - (1 << b)])


N = int(input())
A = list(map(int, input().split()))

st = SparseTable(A)

result = st.query(1, N)
for i in range(1, N - 1):
    result = max(result, gcd(st.query(0, i), st.query(i + 1, N)))
result = max(result, st.query(0, N - 1))
print(result)


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

int main(){
  int n;
  cin >> n;
  int tmp = n;
  int cnt = 1;
  while (1) {
    tmp -= cnt;
    if (tmp == 0) {
      break;
    }
    if (tmp > 0) {
      cnt++;
    }
    if (tmp < 0) {
      puts("No");
      return 0;
    }
  }
  cout << "Yes" << endl;
  cout << cnt + 1 << endl;
  tmp = n;
  vector<vector<int>> a(cnt + 1);
  while (tmp) {
    for (int i = 0; i < cnt; i++) {
      a[cnt].push_back(tmp);
      a[cnt - i - 1].push_back(tmp);
      tmp--;
    }
    cnt--;
  }
  for (int i = 0; i < a.size(); i++) {
    cout << a[i].size() << " ";
    for (int j = 0; j < a[i].size(); j++) {
      cout << a[i][j];
      if (j != a[i].size() - 1) cout << " ";
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 2304
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		
		int lmax = 0;
		int rmin = n;
		// カードの枚数は、Lの最大値以上Rの最小値以下
		for (int i = 0; i < m; i++) {
			lmax = Math.max(lmax, scanner.nextInt());
			rmin = Math.min(rmin, scanner.nextInt());
		}
		
		System.out.println(Math.max(rmin + 1 - lmax, 0));
	}
}


Measured memory_bytes: 62344
import java.util.*;
public class Main {
   public static void main(String[] args) {  
      Scanner sc = new Scanner(System.in);
      
      int N = sc.nextInt();
      
      int T = sc.nextInt();
      int A = sc.nextInt();
      
      int index = 1;
      double diff = 10000000000.0;
      for(int i = 0; i < N; i++) {
         int H = sc.nextInt();
         
         double d = Math.abs(A - (T - H * .006));
         if(d < diff) {
            diff = d;
            index = i+1;
         }
      }
      System.out.println(index);
   }
}

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

int main(void){

	int N;
	cin >> N;

	vector< vector<int> > arr(3,vector<int>(N,0));

	for(int i=0;i<N;i++){
		cin >> arr[0][i];
		cin >> arr[1][i];
		cin >> arr[2][i];
	}

	vector< vector<int> > ans(3,vector<int>(N,0));

	ans[0][0] = arr[0][0];
	ans[1][0] = arr[1][0];
	ans[2][0] = arr[2][0];

	for(int i=1;i<N;i++){
		ans[0][i] = max(ans[1][i-1],ans[2][i-1])+arr[0][i];
		ans[1][i] = max(ans[0][i-1],ans[2][i-1])+arr[1][i];
		ans[2][i] = max(ans[1][i-1],ans[0][i-1])+arr[2][i];
	}

	int maxi = INT_MIN;
	for(int i=0;i<3;i++){
		maxi = max(maxi,ans[i][N-1]);
	}

	cout << maxi;
}

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using ll = long long int;

int main(){
    int N;
    cin >> N;
    vector<int> vec(N);
    for(int i=0; i<N; i++){
      cin >> vec[i];
    }
    sort(vec.begin(), vec.end());
    double p = vec[0];
    for(int i=1; i<N; i++){
        double k = p/2.0;
        double l = vec[i]/2.0;
        p = k+l;
    }
    cout << p;
}

Measured memory_bytes: 256
#include <stdio.h>

typedef struct dice{
  int men[6];
} Dice;
  
int main(void)
{
  Dice dice, dice_memo;
  int n;
  int q[24][2];
  int ans[24];
  int i, j, k, l, m;
  
  for(i = 0; i < 6; i++)
    scanf("%d", &dice.men[i]);

  for(j = 0; j < 6; j++)
    dice_memo.men[j] = dice.men[j];
  
  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%d %d", &q[i][0], &q[i][1]);
  
    for(k = 0; k < 4; k++){
      for(j = 0; j < 4; j++){
	for(m = 0; m < 4; m++){
	  if(dice.men[0] == q[i][0] && dice.men[1] == q[i][1])
	    ans[i] = dice.men[2];
	  
	  else{
	    dice_memo.men[0] = dice.men[1];
	    dice_memo.men[1] = dice.men[5];
	    dice_memo.men[5] = dice.men[4];
	    dice_memo.men[4] = dice.men[0];
	  }
	
	  for(l = 0; l < 6; l++)
	    dice.men[l] = dice_memo.men[l];
	}
	dice_memo.men[0] = dice.men[3];
	dice_memo.men[3] = dice.men[5];
	dice_memo.men[5] = dice.men[2];
	dice_memo.men[2] = dice.men[0];
	
	for(l = 0; l < 6; l++)
	  dice.men[l] = dice_memo.men[l];
      }
      dice_memo.men[1] = dice.men[2];
      dice_memo.men[2] = dice.men[4];
      dice_memo.men[4] = dice.men[3];
      dice_memo.men[3] = dice.men[1];
      
      for(l = 0; l < 6; l++)
	dice.men[l] = dice_memo.men[l];
    }
  }
  
  for(i = 0; i < n; i++)
    printf("%d\n", ans[i]);
  
  return 0;
}

Measured memory_bytes: 596
#include<stdio.h>

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

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

int in_deg[100005]={0};
vector<int > adj[100005];
vector<int > res;
int main() {
    int n,m;
    cin>>n>>m;
    int x,y;
    while(m--){
        cin>>x>>y;
        adj[x].push_back(y);
        in_deg[y]++;
    }
    queue<int > pq;
    for(int i=1;i<=n;i++){
        if(in_deg[i]==0){
            pq.push(i);
        }
    }
    while(!pq.empty()){
        int x=pq.front();
        pq.pop();
        res.push_back(x);
        for(auto i : adj[x]){
            in_deg[i]--;
            if(in_deg[i]==0){
                pq.push(i);
            }
        }
    }
    int dp[n]={0};
    int f_max=0;
    for(int i=res.size()-1;i>=0;i--){
        //cout<<res[i]<<endl;
        int v=0;
        for(int j=0;j<adj[res[i]].size();j++){
            v=max(v,dp[adj[res[i]][j]]);
        }
        dp[res[i]]=1+v;
        if(f_max<dp[res[i]]){
            f_max=dp[res[i]];
        }
    }
    //for(int i=1;i<=n;i++){cout<<dp[i]<<" ";}
    cout<<f_max-1<<endl;
}


Measured memory_bytes: 9760
#include <bits/stdc++.h>
#define maxn 200010
using namespace std;
typedef long long LL;
int fa[maxn], sz[maxn];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
bool same(int u, int v) { return find(u) == find(v); }
void unionn(int x, int y) {
    x = find(x), y = find(y);
    if (sz[x] > sz[y]) swap(x, y);
    fa[x] = y; sz[y] += sz[x];
}
int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= (n<<1); ++i) fa[i] = i;
    for (int i = 0; i < m; ++i) {
        int u, v;
        scanf("%d%d", &u, &v);
        unionn(u, n+v);
        unionn(n+u, v);
    }
    for (int i = 1; i <= n; ++i) if (same(i, n+i)) { printf("%lld\n", 1LL*n*(n-1)/2-m); return 0; }
    int b = 1, w = 0;
    for (int i = 2; i <= n; ++i) if (same(1, i)) ++b; else ++w;
    printf("%lld\n", 1LL * b * w - m);
    return 0;
}


Measured memory_bytes: 1792
n = int(input())
a = list(map(int,input().split()))
sum = 1
if 0 in a:
    print(0)
else:
    for i in range(n):
        if sum > 10**18:
            break
        else:
            sum *= a[i]
    print(sum if sum <= 10**18 else -1)

Measured memory_bytes: 21644
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
#include<bitset>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
const int N=310,mod=998244353;
char s[N];
int K,ct,n,m;
int w[N];
ll sum,f[N][N][N];
void pls(ll &x,ll y){x+=y;x>=mod?x-=mod:0;}
int main(){
//	freopen("a.in","r",stdin);
	scanf("%s%d",s+1,&K);n=strlen(s+1);
	for(int i=1;i<=n;i++)if(s[i]=='0')m++,w[m]=ct,ct=0;else ct++;
	m++;w[m]=ct;
	f[m+1][0][0]=1;
	for(int i=m;i;i--){sum=min(sum,(ll)K);
		for(int j=0;j<=sum;j++)for(int k=j;k<=sum;k++)for(int c=0;c<=j+w[i];c++){
			if(c<w[i])pls(f[i][j+w[i]-c][k+w[i]-c],f[i+1][j][k]);
			else pls(f[i][j+w[i]-c][k],f[i+1][j][k]);
		}
		sum+=w[i];
	}
	K=min(K,n);
	sum=0;for(int i=0;i<=K;i++)pls(sum,f[1][0][i]);
	cout<<sum;
}


Measured memory_bytes: 32060
#include <bits/stdc++.h>
#define LL              long long
#define SL(n)           scanf("%lld",&n)
#define LF              double
#define SF(n)           scanf("%lf",&n)

#define pb              push_back
#define ff              first
#define ss              second
#define mp              make_pair

#define ON(n,i)         (n|(1<<i))
#define OFF(n,i)        (n&(~(1<<i)))
#define CHK(n,i)        (n&(1<<i))

#define SET(arr)        memset( arr , -1 , sizeof arr)
#define RESET(arr)      memset( arr,0,sizeof arr)

#define srt(v)          sort(v.begin(),v.end())
#define found( s,d )    (s.find(d) != s.end())

#define FOR(i,s,e)      for( LL i = s ; i<=e ; i++ )

#define FILEIN          freopen("in.txt","r",stdin)
#define FILEOUT         freopen("out.txt","w",stdout)

using namespace std;

int main(){
 
  LL w,a,b; SL(w); SL(a); SL(b);
  LL ans = 1e18;

  if( a<=b+w && b+w<=a+w ) ans = 0;
  if( a<=b && b<=a+w ) ans = 0;

  ans = min( ans, abs( a - b ) );
  ans = min( ans, abs( a - (b+w) ) );
  ans = min( ans, abs( a+w - b ) );
  ans = min( ans, abs( a+w - (b+w) ) );
  
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
typedef long long i64;
typedef char str255[256];

#define INF 100100100

int H, N;
int *A, *B;
i64 *MPtoki;

void Solve()
{
  for (int HPmonster = H; HPmonster > 0; --HPmonster){
    for (int i = 0; i < N; ++i){
      int nextHP = HPmonster - A[i];
      if (nextHP < 0) nextHP = 0;
      int nextMP = MPtoki[HPmonster] + B[i];
      if (MPtoki[nextHP] > nextMP) MPtoki[nextHP] = nextMP;
    }
  }
  cout << MPtoki[0] << endl;
}

void Init()
{
  cin >> H >> N;
  A = new int[N + 10];
  B = new int[N + 10];
  for (int i = 0; i < N; ++i)
    cin >> A[i] >> B[i];
  MPtoki = new i64[H + 10];
  for (int i = 0; i < H; ++i)
    MPtoki[i] = INF;
  MPtoki[H] = 0;
}

void Clean()
{
  delete[] MPtoki;
  delete[] B;
  delete[] A;
}

int main(){ Init(); Solve(); Clean(); return 0; }


Measured memory_bytes: 384