akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int MAXN=1e5+5;
int read()
{
    int s=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
    return s*f;
}
int main()
{
    string s;
    while(cin>>s)
    {

        int n=s.size();
        if(n%2){cout<<"No\n";continue;}
        bool flag=true;
        for(int i=0;i<n;i+=2)
        {
            if(s[i]=='h'&&s[i+1]=='i')continue;
            flag=false;break;
        }
        if(flag)cout<<"Yes\n";
        else cout<<"No\n";
    }
    return 0;
}


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

using namespace std;

#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

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

const int N = 5e3 + 5;

typedef bitset<N> bit;
int n, k, A[N], ans;

bit Add(bit b, int l, int r) {
	for (int i = l; i < r; i++) b |= (b << A[i]);
	return b;
}
void Build(int l, int r, bit b) {
	if (r - l < 2) {
		bool flag = false;
		for (int i = k - A[l]; i < k; i++) flag |= b[i];
		ans += !flag;
		return;
	}
	int md = (l + r) / 2;
	bit b1 = Add(b, l, md);
	bit b2 = Add(b, md, r);
	Build(l, md, b2);
	Build(md, r, b1);
}

int main() {

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

	cin >> n >> k;
	for (int i = 0; i < n; i++) cin >> A[i], A[i] = min(A[i], k);
	bit b; b[0] = 1;
	Build(0, n, b);
	cout << ans << endl;

	return 0;
}

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

int main(){
	int N;
	cin >> N;
	string s;
	cin >> s;
  	if(N%2){
      puts("No");
      return 0; 
    }
    for(int i=0; i<N/2; i++){
      if(s[i] == s[i+N/2]) continue;
      puts("No");
      return 0; 
    }
 	puts("Yes");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
int main() 
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
	long long int a,s,c,ans;
	cin>>a;
	s=a*a;
	c=s*a;
	ans=a+s+c;
	cout<<ans<<"\n";
}

Measured memory_bytes: 3652
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    for i in range(H):
        if i%2!=0:
            if W%2==0:
                print('.#'*int(W/2))
                
            else:
                print('.#'*int((W-1)/2) + '.')
        else:
           
           if W%2==0:
               
               print('#.'*int(W/2))
                
           else:
               
               print('#.'*int(W//2) + '#')       
                
    print()    


Measured memory_bytes: 5612
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=9e18;
typedef pair<ll,ll> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,h[100005]={},dp[100005]={};
  cin >> n;
  for(int i=1; i<=n; i++) {
    cin >> h[i];
  }
  for(int i=0; i<=n; i++) {
    dp[i]=inf;
  }
  dp[0]=dp[1]=0;
  dp[2]=abs(h[2]-h[1]);
  for(int i=3; i<=n; i++) {
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
  }
  cout << dp[n] << endl;
}

Measured memory_bytes: 1024
//どうかACをお恵みくださいお願いしますお願いしますお願います何もしませんから
using System;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();
            int x = 0;
            if (S[0] == T[0])
            {
                x = x + 1;
            }
            if(S[1]==T[1])
            {
                x = x + 1;
            }
            if(S[2]==T[2])
            {
                x = x + 1;
            }
            Console.WriteLine(x);
        }
    }
}

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

int main() {
	int n, m, ans;
	char c[3] = "IO";
	string s;
	while(1) {
		cin >> n;
		if(!n) break;
		cin >> m >> s;
		ans = 0;
		for(int i=0, p=0; i<m; ++i) {
			if(c[p%2]==s[i]) {
				p++;
				if(p%2&&p>=2*n+1) {
					ans++;
				}
			}else p=(c[0]==s[i]?1:0);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
int main() {
	int r, c;
	cin >> r >> c;
	vector<vector<int>> vec(r + 1, vector<int>(c + 1));
	for (int i = 0; i < r; i++) {
		int sum = 0;
		for (int j = 0; j < c; j++) {
			int a = 0;
			cin >> a;
			vec.at(i).at(j) = a;
			sum += a;
		}
		vec.at(i).at(c) = sum;
	}
	for (int i = 0; i < c; i++) {
		int sum = 0;
		for (int j = 0; j < r; j++) {
			sum += vec.at(j).at(i);
		}
		vec.at(r).at(i) = sum;
	}
	int sum = 0;
	for (int i = 0; i < c; i++) {
		sum += vec.at(r).at(i);
	}
	vec.at(r).at(c) = sum;
	for (int i = 0; i <= r; i++) {
		cout << vec.at(i).at(0);
		for (int j = 1; j <= c; j++) {
			cout << " " << vec.at(i).at(j);
		}
		cout << endl;
	}
}


Measured memory_bytes: 3192
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int H, W;
  cin >> H >> W;
  char s[H][W];
  int black = 0;
  int d[H][W];
  int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1};
  REP(i, H)
  REP(j, W)
  {
    cin >> s[i][j];
    if (s[i][j] == '#')
      black++;
    d[i][j] = -1;
  }
  queue<P> que;
  que.push(make_pair(0, 0));
  d[0][0] = 1;
  while (que.size())
  {
    P p = que.front();
    que.pop();
    if (p.first == H - 1 && p.second == W - 1)
      break;
    REP(i, 4)
    {
      int ny = p.first + dy[i], nx = p.second + dx[i];
      if (0 <= ny && ny < H && 0 <= nx && nx < W && s[ny][nx] != '#' && d[ny][nx] == -1)
      {
        que.push(make_pair(ny, nx));
        d[ny][nx] = d[p.first][p.second] + 1;
      }
    }
  }
  if (d[H - 1][W - 1] == -1)
    cout << -1 << endl;
  else
    cout << (H * W) - d[H - 1][W - 1] - black << endl;
  return 0;
}


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

int b[100];

int main()
{
  int n, m;
  int a[100];
  
  cin >> n >> m;

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

  int cnt;
  int x;

  for (int i = 0; i < m; i++){
    cnt = 0;
    for (int j = 0; j < n; j++){
      cin >> x;
      if (x == a[i]){
        b[j]++;
      }
      else {
        cnt++;
      }
    }
    b[a[i] - 1] += cnt;
  }

  for (int i = 0; i < n; i++){
    cout << b[i] << endl;
  }
  
  return 0;
} 

Measured memory_bytes: 1164
n=int(input())
a=[[0,0,0]]
for i in range(n):
  a.append(list(map(int,input().split())))
for i in range(n):
  time=(a[i+1][0]-a[i][0])
  dis=abs(a[i+1][1]-a[i][1])+abs(a[i+1][2]-a[i][2])
  if time-dis>=0 and (time-dis)%2==0:
    continue
  else:
    print('No')
    exit()
print('Yes')

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

if N<10:
    print(N)
elif N<100:
    print(9)
elif N<999:
    print(N-99+9)
elif N<9999:
    print(900+9)
elif N<99999:
    print(N-9999+900+9)
else:
    print(99999-9999+900+9)

Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int main(){
   int a, b;
   
   cin >> a >> b;
   
   if(a > b)
   cout<<"a > b"<< endl;
   else if(a < b)
   cout<<"a < b"<< endl;
   else if(a == b)
   cout<<"a == b"<< endl;
   return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int i[500][500];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=1,f=0;
  cin  >>a>>b>>c;
  a=a-b;
  if(c-a>=0)
    cout <<c-a<<'\n';
  else cout <<0<<'\n';
  return (0);
}


Measured memory_bytes: 256
x, y = map(int, input().split())
ans = 0
if abs(x) == abs(y):
    if x * y > 0:
        ans = 0
    else:
        ans = 1
elif abs(x) < abs(y):
    if x >= 0 and y >= 0:
       ans = y - x
    elif x >= 0 and y < 0:
        ans += abs(y) - x
        ans += 1
    elif x < 0 and y >= 0:
        ans += 1
        ans += y + x
    else:
        ans += 1
        ans += x - y
        ans += 1
else:
    if x >= 0 and y > 0:
        ans += 1
        ans += x - y
        ans += 1
    elif x >= 0 and y <= 0:
        ans += 1
        ans += x + y
    elif x < 0 and y > 0:
        ans += abs(x) - y
        ans += 1
    elif x < 0 and y == 0:
        ans += abs(x) - y
    else:
        ans += y - x
print(ans)

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

int main(){
  int n, k ;
  cin >> n >> k ;
  int sunuke[n] = {0} ;
  int d[k] ;
  int a ;
  for(int i=0;i<k;i++){
    cin >> d[i] ;
    for(int j=0;j<d[i];j++){
      cin >> a ;
      sunuke[a-1] = 1 ;
    }
  }
  int ans = 0 ;
  for(int i=0;i<n;i++){
    if(sunuke[i] == 0) ans ++ ;
  }
  cout << ans ;
  return 0 ;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define fast() ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define lp(i, n) for(int i = 0; i < n; i++)
#define rlp(i, n) for(int i = n-1; i >= 0; i--)
#define loop(i, a, b) for(int i = a; i <= b; i++)
#define rloop(i, a, b) for(int i = a; i >= b; i--)
#define mem(a, val) memset(a, val, sizeof a);
#define all(v) v.begin(),v.end()
#define ll long long
#define ld long double
#define mp_ make_pair
#define sz(s) (int)s.size()
#define pb push_back
const int MAX = 1e5 + 5;
const int inf = 1e9+1;
const ll OO = 1e18;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;


int main(){

    int d, t, s;
    cin>> d >> t >> s;
    cout<< (d / (double)s <= t ? "Yes" : "No");
    return 0;
}


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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

signed main()
{
    int n, k;
    cin >> n >> k;
    if (k == 1)
        cout << 0 << endl;
    else
        cout << n - k << endl;
}

Measured memory_bytes: 256
def run():
  bit = 60
  N = int(input())
  a_li = list(map(int, input().split()))
  ans = 0
  dp = [[0]*bit for i in range(N)]
  for i in range(bit):
    dp[0][i] = (a_li[0] >> i) & 1
  for i in range(1, N):
    for j in range(bit):
      a_j = (a_li[i] >> j) & 1
      dp[i][j] = dp[i-1][j] + a_j
      ans += abs(a_j*i - dp[i-1][j]) << j
  print(ans%(10**9+7))

if __name__ == '__main__':
  run()

Measured memory_bytes: 203212
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	void run(){
		int n=8;
		String[] ss=new String[n];
		for(int j=0; j<n; j++){
			ss[j]=sc.next();
		}
		println("90");
		for(int i=0; i<n; i++){
			for(int j=n-1; j>=0; j--){
				print(""+ss[j].charAt(i));
			}
			println("");
		}
		println("180");
		for(int j=n-1; j>=0; j--){
			for(int i=n-1; i>=0; i--){
				print(""+ss[j].charAt(i));
			}
			println("");
		}
		println("270");
		for(int i=n-1; i>=0; i--){
			for(int j=0; j<n; j++){
				print(""+ss[j].charAt(i));
			}
			println("");
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
double EPS=1e-10;
double EQ(double a,double b){
    return abs(a-b)<EPS;
}
void fast_stream(){
  std::ios_base::sync_with_stdio(0);
}
template<class T>
string IntToString(T num){
  string res;stringstream ss;ss<<num;
  return ss.str();
}
ll StringToInt(string &str){
  ll res=0;
  for(int i=0;i<(int)str.size();i++)
    res=(res*10+str[i]-'0');
  return res;
}

set<string> st;
int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    st.insert(s);
  }
  int m;
  cin>>m;
  bool op=false;
  for(int i=0;i<m;i++){
    string s;
    cin>>s;
    if(st.count(s)>0){
      if(!op)cout<<"Opened by ";
      else cout<<"Closed by ";
      op^=1;
    }
    else
      cout<<"Unknown ";
    cout<<s<<endl;
  }
  return 0;
}

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

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    int arr[n];
    for(int i=0; i<n; i++) cin >> arr[i];
    
    int cnt = 0;
    int num;
    for (int i=0; i<n; i++) {
        num = arr[i];
        while (num % 2 == 0)
        {
            cnt++;
            num /= 2;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
string s, t;
cin >> s >> t;
int len = s.size();
bool ans = false;
for(int i = 0; i < len; i++){
  if(s == t){
    ans = true;
    break;
  }else{
    s = s.back() + s.substr(0, len - 1);
  }
}
if(ans)cout << "Yes " << endl;
else cout << "No" << endl;

}

Measured memory_bytes: 256
#include<cstdio>
int min(int a,int b){
	if(a>b) return b;
	else return a;
}
int main(){
	int x,a1,b1,c1,i,j,k;
	scanf("%d %d %d %d",&a1,&b1,&c1,&x);
	int sum=0;
	for(i=0;i<=min(x/500,a1);i++)
		for(j=0;j<=min((x-500*i)/100,b1);j++)
			for(k=0;k<=min((x-500*i-100*j)/50,c1);k++)
				if(500*i+100*j+50*k==x)
					sum++;
	printf("%d",sum); 
	return 0;
} 

Measured memory_bytes: 128
n=gets.to_i
c = 0
3.upto(n.to_s.size-1) do |i|
  c += 3 ** i - 2 ** i * 3 + 3
end
[3,5,7].repeated_permutation(n.to_s.size) do |b|
  if b.join.to_i <= n && b.count(3)*b.count(5)*b.count(7)>0
    c += 1
  elsif b.join.to_i > n
    break
  end
end
p c

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int MAX_H = 205, MAX_W = 205;
const int INF = 1000100100;

int d[10][10];

void init(){
    rep(i,MAX_H){
        rep(j,MAX_W){
            d[i][j] = ((i==j) ? 0 : INF);
        }
    }
}

int main()
{
    int H, W; cin >> H >> W;
    rep(i,10){
        rep(j,10){
            int cij; cin >> cij;
            d[i][j] = cij;
        }
    }
    rep(k,10){
        rep(i,10){
            rep(j,10){
                d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
            }
        }
    }
    /*
    rep(i,10){
        rep(j,10) cout << d[i][j] << " ";
        cout << endl;
    }
    */
    int cost = 0;
    rep(i,H){
        rep(j,W){
            int Aij; cin >> Aij;
            if(Aij == -1 || Aij == 1) continue;
            else{
                cost += d[Aij][1];
            }
        }
    }
    cout << cost << endl;
}

Measured memory_bytes: 256
import sys
import bisect
input()
arr = list(map(int, input().split()))
nq = int(input())
lines = sys.stdin.readlines()
ans = [None] * nq
for i in range(nq):
    q = int(lines[i])
    ans[i] = '{} {}'.format((bisect.bisect_left(arr, q)), bisect.bisect_right(arr, q))
print('\n'.join(ans))


Measured memory_bytes: 43772
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

seq = 0
ans = 0
for i in range(N):
    A[i] -= i+1
    if A[i] == 0:
        seq += 1
    else:
        ans += (seq+1)//2
        seq = 0
ans += (seq+1)//2
print(ans)


Measured memory_bytes: 13876
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    _ = int(input())
    A = list(map(int, input().split()))
    A_abs = [abs(a) for a in A]
    mc = sum([1 for a in A  if a < 0])

    ans = sum(A_abs)
    if mc % 2 != 0:
        ans -= min(A_abs) * 2
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 14412
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  int N, M;;
  cin >> N >> M;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  int sum = accumulate(all(A), 0);
  int cnt = 0;
  rep(i, N) if(A[i] >= 1.0*sum/(4*M)) cnt++;
  if(cnt >= M) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

using namespace std;

int main(){
	set<int> vis;
	int h, w;
	cin >>h >>w;
	for(int r = 0; r < h; ++r){
		for(int c = 0; c < w; ++c){
			char v;
			cin >>v;
			if(v == '#'){
				vis.insert(r*w+c);
			}
		}
	}
	
	int dest = (h - 1) * w + w - 1;
	int steps = h + w - 2;
	int mx_mask = (1 << steps) - 1;
	
	bool poss = false;
	for(int msk = 0; msk < mx_mask; ++msk){
		int r = 0, c = 0;
		bool bad = false;
		set<int> cur_vis{0};
		for(int stp = 0; stp < steps; ++stp){
			if(msk & (1 << stp)){
				++r;
			}
			else{
				++c;
			}
			int loc = r * w + c;
			if(vis.find(loc) == end(vis)){
				bad = true;
			}
			cur_vis.insert(loc);
		}
		int fin = r * w + c;
		if(fin == dest && !bad && vis.size() == cur_vis.size())
			poss = true;
	}
	if(poss)
		cout <<"Possible\n";
	else
		cout <<"Impossible\n";
	
	return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>

using namespace std;

int main(){

    int A;
    char op;
    int B;

    cin >> A >> op >> B;

    if(op == '+'){
    	cout << A + B << endl;
    }else if(op == '-'){
    	cout << A - B << endl;
    }

	return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);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;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n;
int m;
int main(){
    cin>>n>>m;
    int ansl=1;
    int ansr=1e5+9;
    int l,r;
    for(int i = 0;i < m; i++){
        cin>>l>>r;
        if(ansl<l) ansl=l;
        if(r<ansr) ansr=r;
        //cout<<ansl<<" "<<ansr<<endl;
    }
    if(ansr-ansl+1>=0)cout<<ansr-ansl+1<<endl;
    else cout<<'0'<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	Scanner sc = new Scanner(System.in);
	
	void run(){
		int n = sc.nextInt();
		long ans = 1;
		while(n>0) ans *= n--;
		System.out.println(ans);
	}
	
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 17164
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    let hs: Vec<i32> = buf.trim().split(" ").map(|x| x.parse().unwrap()).collect();
    let mut ans = 0;
    let mut max = 0;
    for h in hs {
        if h >= max {
            ans += 1;
            max = h;
        }
    }
    println!("{}", ans);
}


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

int main() {
    int n; cin >> n;
    vector<int> l(n);
    rep(i,n) cin >> l[i];

    sort(l.begin(),l.end());
    int lmax = l[n-1];
    int lsum = 0;
    rep(i,n-1){
        lsum += l[i];
    }
    if(lmax < lsum) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int x;
    int num = 1;
    while (1)
    {
        cin >> x;
        if (x == 0)
            break;
        printf("Case %d: %d\n", num++, x);
    }
}


Measured memory_bytes: 3120
import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    # https://qiita.com/drken/items/97e37dd6143e33a64c8c#3-%E3%82%81%E3%81%90%E3%82%8B%E5%BC%8F%E4%BA%8C%E5%88%86%E6%8E%A2%E7%B4%A2%E3%81%AE%E3%81%95%E3%82%89%E3%81%AA%E3%82%8B%E5%88%A9%E7%82%B9

    n,a,b=map(int,input().split())
    h=[int(input()) for _ in range(n)]
    def is_ok(t):
        cnt=0
        for i in h:
            i-=b*t
            if i>0:
                cnt+=math.ceil(i / (a-b))
        return cnt<=t

    def bin_search_meguru():
        """
        初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
        まずis_okを定義すべし
        ng, okは,とり得る最小の値-1,とり得る最大の値+1
        """
    
        # 適当にいじる
        ng = 0  # ind=0が条件を満たすこともあるため
        ok = 10**18  # ind=len(a)-1が条件を満たさないこともあるため
    
        # いじらない
        # okとngのどちらが大きいかわからないことを考慮
        while (abs(ok - ng) > 1):
            mid = (ok + ng) // 2
            if is_ok(mid):
                ok = mid
            else:
                ng = mid
        return ok
    print(bin_search_meguru())
    

    
resolve()

Measured memory_bytes: 77976
#include <iostream>
#include <stack>
using namespace std;
static const int N=100;
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int n,M[N][N];
int color[N],d[N],f[N],tt;
int nt[N];

//按编号顺序获取与u相邻的v
int next(int u){
    for(int v=nt[u]; v<n; v++){
        nt[u] = v+1;
        if(M[u][v]) return v;
    }
    return -1;
}


//用栈实现的深度优先搜索
void dfa_visit(int r){
    for(int i=0; i<n; i++) nt[i] = 0;

    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    d[r] = ++tt;

    while(!S.empty()){
        int u = S.top();
        int v = next(u);
        if(v!=-1){
            if(color[v] == WHITE){
                color[v] = GRAY;
                d[v] = ++tt;
                S.push(v);
            }
        }else{
            S.pop();
            color[u] = BLACK;
            f[u] = ++tt;
        }
    }
}



void dfs(){
    //初始化
    for(int i=0; i<n; i++){
        color[i] = WHITE;
        nt[i] = 0;
    }
    tt=0;

    //以未访问的u为起点进行深度搜索优先搜索
    for(int u=0; u<n; u++){
        if(color[u] == WHITE) dfa_visit(u);
    }

    for(int i=0; i<n; i++){
        cout << i+1 <<" "<<d[i]<<" "<<f[i]<<endl;
    }
}



int main(){
    int u,k,v;
    cin>>n;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++) M[i][j] = 0;
    }


    for(int i=0; i<n; i++){
        cin>>u>>k;
        u--;
        for(int j=0; j<k; j++){
            cin>>v;
            v--;
            M[u][v]=1;
        }
    }

    dfs();

    return 0;
}


Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define sf scanf
#define pf printf
#define pb push_back
#define MP make_pair
#define llu unsigned long long
#define U unsigned int
#define ff first
#define ss second
#define SIZE 100005
#define pie 3.14159265358979323
#define minuss 1e-6
#define pair pair<ll,ll>
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define BIG 1000000000
#define INF 1000000000000005
#define N 10000
vector<ll>vec;
map<string,ll> mps;
map<ll,string> mpss;
set<ll>s1;
set<string>s2;
map<string,ll>::iterator str;
set<ll>::iterator itr;
/*
std::cout << std::fixed;
std::cout << std::setprecision(1);
std::cout << VALUE NAME<<endl;
*/
ll tra[100006],tra1[100006];


int main()
{

    map<ll,ll>mp;
    map<ll,ll>::iterator it;
    string s,s1;
    ll n,m,lock=0,a,b,c,d;
    cin>>a>>b>>c>>d;

    ll ans=min(a,d);
    if(ans<d)
    {
        ll sec=min(d,(ans+b));
        if(sec<d)
        {
            ll div=d-sec;
            cout<<a-div<<endl;
        }
        else
            cout<<a<<endl;
    }
    else
        cout<<ans<<endl;

}



Measured memory_bytes: 3568
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast", "unroll-loops")
using namespace std;
#define ll long long
#define int ll
#define FOR(i,a,b) for (int i = (a); i<(b); i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define RREP(i,n) for (int i=(n)-1; i>=0; i--)
#define f first
#define s second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define SQ(x) (x)*(x)
#define pii pair<int, int>
#define pdd pair<double ,double>
#define pcc pair<char, char> 
#define endl '\n'
#define PI 3.14159265
//#define TOAD
#ifdef TOAD
#define bug(x) cerr<<__LINE__<<": "<<#x<<" is "<<x<<endl
#define IOS()
#else
#define bug(...)
#define IOS() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#endif
const ll inf = 1ll<<60;
const int iinf=2147483647;
const ll mod = 1e9+7;
const ll maxn=2e5+5;
ll pw(ll x, ll p){
    ll ret=1;
    while (p>0){
        if (p&1){
            ret*=x;
            ret%=mod;
        }
        x*=x;
        x%=mod;
        p>>=1;
    }
    return ret;
}

ll inv(ll a, ll b){
    return 1<a ? b - inv(b%a,a)*b/a : 1;
}
int tre[4*maxn];

int QU(int l, int r, int nl, int nr, int x){
    if (nl>r||nr<l){
        return 0;
    }
    if (nl>=l&&nr<=r){
        return tre[x];
    }
    int mid=(nl+nr)/2;
    return max(QU(l, r, nl, mid, x+x), QU(l, r, mid+1, nr, x+x+1));
}
void MO(int l, int r, int pos, int x, int val){
    if (l==r){
        tre[x]+=val;
        return;
    }
    int mid=(l+r)/2;
    if (l<=pos&&pos<=mid){
        MO(l, mid, pos, x+x, val);
    }
    else MO(mid+1, r, pos, x+x+1, val);
    tre[x]=max(tre[x+x], tre[x+x+1]);
}

signed main (){
    IOS();
    int n; cin>>n;
    vector<int> h(n), a(n);
    REP(i,n) cin>>h[i];
    REP(i,n) cin>>a[i];
    int ans=0;
    REP(i,n){
        int prev=QU(1, h[i], 1, n , 1); //can also do h[i]-1

        bug(prev);
        MO(1, n, h[i], 1, prev+a[i]);
    }
    cout<<QU(1, n, 1, n, 1)<<endl;
}

Measured memory_bytes: 10516
#include<cstdio>
#include<string>
#include<iostream>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<vector>
#include<list>
#include<deque>
#include<functional>
#include<sstream>
#include<numeric>
#include<complex>

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DUMP(x) if(DBG){cerr << #x << " = " << (x) << endl;}
#define CLR(a) memset((a), 0 ,sizeof(a))
#define rep(i,n) for(int i=0;i<(int)n;i++)

#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define INF 1<<27
#define EPS 1e-8

#define DBG 0

using namespace std;

inline int to_int(string s) {int v; istringstream istr(s);istr>>v;return v;}
template<class T> inline string to_string(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;

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

int main()
{
	int h[5], k;

	rep(i, 5) {
		cin >> h[i];
	}

	cin >> k;

	rep(i, 5) {
		rep(j, 5) {
			if(abs(h[i]-h[j]) > k) {
				cout << ":(" << endl;
				return 0;
			}
		}
	}

	cout << "Yay!" << endl;
	return 0;
}


Measured memory_bytes: 256
s = gets.chomp
ss = s.length
le = s.length/2
(le-1).downto(0) do |i|
  s1 = s[0..i]
  s2 = s[i+1..i*2+1]
  if s1 == s2 && ss != s.length
    puts ss
    exit
  end
 ss -= 2
end

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ll long long
using namespace std;


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

}


Measured memory_bytes: 256
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <iomanip>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv << endl;
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
inline void YES(bool cond) { cond ? puts("YES") : puts("NO"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline void reverse(Type& arr) { reverse(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
template<typename Type> inline void unique(Type& arr) { sort(arr); arr.erase(unique(arr.begin(), arr.end()), arr.end()); }
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr ll BIGP = 1000000007L;
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
using P = pair<ll, ll>;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //
    ll N, M;
    cin >> N >> M;
    set<ll> A;
    rep(i, M)
    {
        ll a;
        cin >> a;
        A.insert(a);
    }
    vector<ll> dp(N + 2, 0);
    dp[0] = 1;
    if (A.find(1) == A.end())
    {
        dp[1] = 1;
    }
    rep(i, N)
    {
        if (A.find(i+2) != A.end())
        {
            continue;
        }
        dp[i+2] = (dp[i+1] + dp[i+0]) % BIGP;
    }
    cout << dp[N];
    //
    return 0;
}

Measured memory_bytes: 8236
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
#include <string>
#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define REP(i, x, y) for(int i = (int)x; i <= (int)y; i ++)
#define FOR(i, x, y) for(int i = (int)x; i <  (int)y; i ++)
#define PER(i, x, y) for(int i = (int)x; i >= (int)y; i --)
#define trace(x) cerr << #x << " " << x << endl;
#define dprintf(...) fprintf(stderr, __VA__ARGS__)
#define dln()        fprintf(stderr, "\n")
using namespace std;
typedef long long LL;
typedef long double db;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
const	int N = 500005;
const	int P = 1e9 + 7;
const	int inf = 1e9;
const	LL Inf = 1e15;

inline int IN(){
	char ch = getchar(); int x = 0, f = 0;
	while(ch < '0' || ch > '9') ch = getchar(), f = (ch == '-');
	while(ch >= '0' && ch <= '9'){
		x = (x << 1) + (x << 3) + ch - 48;
		ch = getchar();
	}
	return f ? (-x) : x;
}

inline int Pow(int x, int y, int p){
	int an = 1;
	for(; y; y >>= 1, x = (LL)x * x % p) if(y & 1) an = (LL)an * x % p;
	return an;
}

void renew(int &x, int y){
	x += y;
	if(x < 0) x += P;
	else if(x >= P) x -= P;
}

template<typename T> inline void chkmin(T &a, const T &b) {if(a > b) a = b;}
template<typename T> inline void chkmax(T &a, const T &b) {if(a < b) a = b;}

int deg[N];
int n, k, a[N], b[N];
VI e[N];

struct seg{
	int sum[N << 2];

	int ql, qr, qx, qv;
	
	#define ls ((x) << 1)
	#define rs ((ls) | 1)
	#define md (((L) + (R)) >> 1)
	
	void M(int x, int L, int R){
		if(L == R){
			sum[x] = 1;
			return;
		}
		if(qx <= md) M(ls, L, md);
		else M(rs, md + 1, R);
		sum[x] = sum[ls] + sum[rs];
	}

	void D(int x, int L, int R){
		if(!sum[x]) return;
		if(L == R){
			e[L].pb(qv);
			deg[qv] ++;
			sum[x] = 0;
			return;
		}
		if(ql <= L && R <= qr){
			D(ls, L, md);
			D(rs, md + 1, R);
			sum[x] = sum[ls] + sum[rs];
			return;
		}
		if(ql <= md) D(ls, L, md);
		if(md <  qr) D(rs, md + 1, R);
		sum[x] = sum[ls] + sum[rs];
	}

	void Modify(int x){
		qx = x;
		M(1, 1, n);
	}
	void Delete(int L, int R, int v){
		if(L > R) return;
		ql = L;
		qr = R;
		qv = v;
		D(1, 1, n);
	}
}L, R;

set<int> fres;
int lab[N], tim;

int main(){
	scanf("%d%d", &n, &k);	
	REP(i, 1, n) scanf("%d", a + i);
	REP(i, 1, n) b[a[i]] = i;
	REP(i, 1, n){
		int x = b[i];
		L.Delete(max(1, x - k + 1), x - 1, x);
		R.Delete(x + 1, min(n, x + k - 1), x);
		L.Modify(x);
		R.Modify(x);
	}
	REP(i, 1, n) if(!deg[i]) fres.insert(i);
	
	while(!fres.empty()){
		int x = *fres.begin();
		lab[x] = ++ tim;
		fres.erase(x);
		for(int v : e[x]){
			-- deg[v];
			if(!deg[v]) fres.insert(v);
		}
	}
	REP(i, 1, n) printf("%d\n", lab[i]);
	return 0;
}





















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

using namespace std;

typedef long long ll;

const int unit[5] = {20 * 20 * 18 * 20, 20 * 18 * 20, 18 * 20, 20, 1};
const int month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

bool is_leap(int y)
{
    if (y % 400 == 0) return 1;
    if (y % 100 == 0) return 0;
    if (y % 4 == 0) return 1;
    return 0;
}

ll fairfield(ll y, ll m, ll d)
{
    if (m <= 2) y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + 153 * (m + 1) / 5 + d- 428;
}
 
void a2m(vector<int> &v)
{
    ll y = v[0], m = v[1], d = v[2];

    ll day = (fairfield(y, m, d) - fairfield(2012, 12, 21)) % 1872000LL;    
    for (int i = 0; i < 5; i++) {
        if (i > 0) cout << ".";
        cout << day / unit[i];
        day %= unit[i];
    }
    cout << endl;
}

void m2a(vector<int> &v)
{
    int day = 0;
    for (int i = 0; i < 5; i++) {
        day += v[i] * unit[i];
    }

    int y = 2012, m = 12, d = 21;
    for (int i = 0; i < 11; i++) {
        if (day == 0) break;
        day--; d++;
    }
    
    if (d == 32) y++, d = 1, m = 1;
    
    bool update = 1;
    while (update) {
        update = 0;
        if (is_leap(y)) {
            if (day >= 366) {
                day -= 366;
                y++;
                update = 1;
            } 
        } else {
            if (day >= 365) {
                day -= 365;
                y++;
                update = 1;
            }            
        }
    }
    
    for (int i = 1; i <= 12; i++, m++) {
        int md = month[i];
        if (is_leap(y) && i == 2) md++;
        if (day >= md) {
            day -= md;
        } else {
            break;
        }
    }
    
    cout << y << "." << m << "." << d + day << endl;
}

int s2i(string &s)
{
    stringstream ss(s);
    int num;
    ss >> num;
    return num;
}

int main()
{
    string s;
    while (cin >> s, s != "#") {
        stringstream ss(s);
        vector<int> v;
        while (getline(ss, s, '.')) {
            v.push_back(s2i(s));
        }
        (v.size() == 3 ? a2m(v) : m2a(v));
    }
    return 0;
}

Measured memory_bytes: 1248
import java.util.Scanner;
 
class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        while(true){
            int x=sc.nextInt();
            int y=sc.nextInt();
            if(x==0&&y==0){
                break;
            }else if(x<y){
                System.out.println(x+" "+y); 
            } else { 
                System.out.println(y+" "+x); 
            } 
        } 
    } 
}


Measured memory_bytes: 35724
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
vector<int>G[1010000];
int n, Mod = 998244353, w[210000], P[1010000];
long long S[1010000], C[1010000], res;
int main() {
	int i, j;
	for (i = 1; i <= 1000000; i++) {
		for (j = i; j <= 1000000; j += i)G[j].push_back(i);
	}
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		scanf("%d", &w[i]);
		for (auto &t : G[w[i]]) {
			S[t] += w[i];
		}
	}
	for (i = 1; i <= n; i++) {
		int x = w[i];
		int sz = G[x].size();
		for (j = 0; j < sz; j++) {
			C[G[x][j]] = S[G[x][j]];
		}
		for (j = sz - 1; j >= 0; j--) {
			int y = G[x][j];
			res = (res + C[y] % Mod*(x / y)) % Mod;
			for (auto &t : G[y]) {
				if (t == y)continue;
				C[t] -= C[y];
			}
		}
	}
	for (i = 1; i <= n; i++)res = (res + Mod - w[i]) % Mod;
	res = res * (Mod / 2 + 1) % Mod;
	printf("%lld\n",res);
}

Measured memory_bytes: 133632
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int y,l,u;
    char k;
    int s[14]={};
    int h[14]={};
    int c[14]={};
    int d[14]={};
    cin>>y;
    for(int j=1;j<=y;j++){
        cin>>k>>l;
        if(k=='S') s[l]=1;
        if(k=='H') h[l]=1;
        if(k=='C') c[l]=1;   
        if(k=='D') d[l]=1;
    }
    u=0;
    for(int i=1;i<=52;i++){
        u++;
        if(i<=13){
            if(s[u]==0) cout<<"S "<<u<<endl;
        }else if(i<=26){
            if(h[u]==0) cout<<"H "<<u<<endl;
        }else if(i<=39){
            if(c[u]==0) cout<<"C "<<u<<endl;
        }else{
            if(d[u]==0) cout<<"D "<<u<<endl;
        }
        if(u%13==0){
            u=0;
        }
    }
}


Measured memory_bytes: 3072
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

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

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}"<<endl;
  return o;
}

//逆元　a/b の modをとるとき -> a*modinv(b)%mod
long long modinv(long long a, long long m = 1e9+7) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m; 
  if (u < 0) u += m;
  return u;
}
ll const mod = 1e9+7;

// combination
const int MAX = 510000;
const ll MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// べき乗
ll modpow(ll x, ll n) {
    x = x%MOD;
    if(n==0) return 1;  //再帰の終了条件

    else if(n%2==1) {
        return (x*modpow(x, n-1))%MOD;  //nが奇数ならnを1ずらす
    }
    else return modpow((x*x)%MOD, n/2)%MOD;  //nが偶数ならnが半分になる
}

int main() {
  int N,K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i,N) cin >> A[i];
  vector<int> c(N+1,0);
  rep(i,N) {
    auto t = A[i];
    c[max(0,i-t)]++;
    c[min(N-1,i+t)+1]--;
  }
  
  rep(i,K) {
    int now = 0;
    vector<int> ta(N,0),tc(N+1,0);
    rep(j,N) {
      now += c[j];
      ta[j] = now;
      auto t = ta[j];
      tc[max(0,j-t)]++;
      tc[min(N-1,j+t)+1]--; 
    }
    if (A==ta) break;
    A = ta;
    c = tc;
  }
  for (auto i:A) cout << i << ' ';
  cout << endl;
}


Measured memory_bytes: 6376
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
int main() {
  int cnt;
  vector<int> v(3);
  rep(i,3) cin>>v[i];
  sort(v.begin(),v.end());
  cnt=v[2]*2-v[0]-v[1];
  if(cnt%2==0) cout<<cnt/2<<endl;
  else cout<<cnt/2+2<<endl;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
count = [0 for i in range(110000)]
sum_ = sum(A)
for i in range(N):
  count[A[i]] += 1

Q=int(input())
for i in range(Q):
  b,c = map(int,input().split())
  count[c] += count[b]
  sum_ += (c-b)*count[b]
  count[b] = 0
  print(sum_)

Measured memory_bytes: 20884
#include<bits/stdc++.h>
#include<queue>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<int>A(N);
  vector<int>B(N);
  vector<int>Bnum(N + 1, 0);
  for (int i = 0; i < N; i ++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i ++) {
    cin >> B[i];
    Bnum[B[i]] ++;
  }
  int r = 0;
  for (int l = 0; l < N; l ++) {
    while (A[l] == B[r] && r < N - 1) r ++;
    swap(B[l], B[r]);
    if (l == r) r ++;
  }
  int l = N - 1;
  for (int r = N - 1; r >= 0; r --) {
    while (A[r] == B[l] && l > 0) l --;
    swap(B[r], B[l]);
    if (l == r) l --;
  }
  for (int i = 0; i < N; i ++) {
    if (A[i] == B[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  /*priority_queue<pair<int, int>>que;
  for (int i = 1; i <= N; i ++) {
    que.push(make_pair(Bnum[i], i));
  }
  for (int i = 0; i < N; i ++) {
    int pre, kj_;
    tie(pre, kj_) = que.top();
    que.pop();
    if (kj_ == A[i]) {
      int now, kj;
      tie(now, kj) = que.top();
      que.pop();
      if (now == 0) {
        cout << "No" << endl;
        return 0;
      }
      que.push(make_pair(pre, kj_));
      pre = now;
      kj_ = kj;
    }
    B[i] = kj_;
    Bnum[kj_] --;
    que.push(make_pair(pre - 1, kj_));
    cout << kj_ << endl;
  }*/
  cout << "Yes" << endl;
  for (int i = 0; i < N; i ++) {
    cout << B[i];
    if (i < N - 1) cout << ' ';
  }
  cout << endl;
}

Measured memory_bytes: 5640
#include <cstdio>
#include <vector>
 
using namespace std;
 
typedef vector<int> vi;
 
int n;
 
int f(vi a, int n, int idx)
{
	vi kesu;
 
	for (int i = idx + 1; i < n; ++i) {
		if (a[i] != a[idx]) break;
		kesu.push_back(i);
	}
	for (int i = idx - 1; i >= 0; --i) {
		if (a[i] != a[idx]) break;
		kesu.push_back(i);
	}
 
	if (kesu.size() < 3) return n;
 
	while (!kesu.empty()) {
		a[kesu.back()] = 0;
		kesu.pop_back();
	}
	a[idx] = 0;
 
	vi b;
 
	int nextidx = -1;
 
	for (int i = 0; i < n; ++i) {
		if (a[i]) {
			b.push_back(a[i]);
			if (nextidx == -1 && i >= 1 && a[i - 1] == 0) {
				nextidx = b.size() - 1;
			}
		} else {
			if (nextidx == -1) {
				if (!b.empty()) {
					nextidx = i - 1;
				}
			}
		}
	}
 
   return f(b, b.size(), nextidx); 
}
 
int calc(vi a, int n, int idx)
{
	vi b = a;
	if (idx >= 3 && a[idx - 1] == a[idx - 2] && a[idx - 2] == a[idx - 3]) {
		b[idx] = b[idx - 1];
	} else if (idx <= n - 4 && a[idx + 1] == a[idx + 2] && a[idx + 2] == a[idx + 3]) {
		b[idx] = b[idx + 1];
	} else if (idx >= 2 && idx <= n - 2 && a[idx - 1] == a[idx - 2] && a[idx - 1] == a[idx + 1]) {
		b[idx] = b[idx - 1];
	} else if (idx >= 1 && idx <= n - 3 && a[idx - 1] == a[idx + 1] && a[idx - 1] == a[idx + 2]) {
		b[idx] = b[idx - 1];
	} else {
		return n;
	}
 
	return f(b, b.size(), idx);
}
 
int main()
{
	while (scanf("%d", &n), n) {
		vi arr;
 
		for (int i = 0; i < n; ++i) {
			int a; scanf("%d", &a);
			arr.push_back(a);
		}
 
		int mi = 10001;
 
		for (int i = 0; i < n; ++i) {
			mi = min(mi, calc(arr, arr.size(), i));
		}
 
		printf("%d\n", mi);
	}
}

Measured memory_bytes: 37624
#include <iostream>
#include <queue>
#include <string>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int H,W;
string s[1000];
int main()
{
    cin >> H >> W;
    rep(i,H)cin >> s[i];
    rep(i,H) cout << s[i] << endl << s[i] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define INF 10e12
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b + c >= 22)
        cout << "bust" << endl;
    else
        cout << "win" << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )
#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define DRANGE( c, p ) (c).begin(), (c).begin() + p, (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

// <equation> := <fomula>'='<fomula>
// <fomula> := <constant> | '-'<fomula> | '('<inner>')'
// <inner> := <fomula>'*'<fomula> | <fomula>'+'<fomula> | <fomula>"->"<fomula>
// <constant> := 'T' | 'F'

PII equation( const string &, int p );
PII fomula( const string &, int p );
PII inner( const string &, int p );
PII constant( const string &, int p );

PII equation( const string &s, int p = 0 )
{
	const PII r1 = fomula( s, p );
	const PII r2 = fomula( s, r1.snd + 1 );
	return MP( r1.fst == r2.fst, r2.snd );
}

PII fomula( const string &s, int p = 0 )
{
	if ( s[p] == '-' )
	{
		PII res = fomula( s, p + 1 );
		res.fst = !res.fst;
		return res;
	}
	else if ( s[p] == '(' )
	{
		PII res = inner( s, p + 1 );
		res.snd ++;
		return res;
	}
	else
	{
		return constant( s, p );
	}
}

const int table_and[][2] = {
	0, 0,
	0, 1
};
const int table_or[][2] = {
	0, 1,
	1, 1
};
const int table_imp[][2] = {
	1, 1,
	0, 1
};

PII inner( const string &s, int p = 0 )
{
	const PII r1 = fomula( s, p );
	const char op = s[ r1.snd ];
	const PII r2 = fomula( s, r1.snd + ( op != '-' ? 1 : 2 ) );

	int res;
	switch ( op )
	{
		case '*':
			res = table_and[ r1.fst ][ r2.fst ];
			break;
		case '+':
			res = table_or[ r1.fst ][ r2.fst ];
			break;
		case '-':
			res = table_imp[ r1.fst ][ r2.fst ];
			break;
	}
	return MP( res, r2.snd );
}

PII constant( const string &s, int p = 0 )
{
	return MP( s[p] == 'T' ? 1 : 0, p + 1 );
}

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

	for ( string line; cin >> line, line != "#"; )
	{
		int res = 0;
		REP( i, 0, 1 << 11 )
		{
			string tmp = line;
			REP( j, 0, 11 )
			{
				replace( ALL( tmp ), (char)( 'a' + j ), ( i & 1 << j ) ? 'T' : 'F' );
			}
			res += equation( tmp ).fst;
		}

		cout << ( res == 1 << 11 ? "YES" : "NO" ) << endl;
	}

	return 0;
}

Measured memory_bytes: 1212