akhauriyash/Code-Regression huggingface dataset:
h, w = map(int, input().split())
s = [] # h, w
for i in range(h):
    s += [','.join(input()).split(',')]

cost = [[10000 for i in range(w)] for j in range(h)]

# h: j,  w: i - j
for hh in range(h):
    for ww in range(w):
        # 初期地点
        if hh == ww == 0:
            cost[0][0] = 0 if s[0][0] == '.' else 1

        if hh < h - 1:
            if s[hh][ww] == '.' and s[hh + 1][ww] == '#':
                cost[hh + 1][ww] = min(cost[hh][ww] + 1, cost[hh + 1][ww])
            else:
                cost[hh + 1][ww] = min(cost[hh][ww], cost[hh + 1][ww])
        if ww < w - 1:
            if s[hh][ww] == '.' and s[hh][ww + 1] == '#':
                cost[hh][ww + 1] = min(cost[hh][ww] + 1, cost[hh][ww + 1])
            else:
                cost[hh][ww + 1] = min(cost[hh][ww], cost[hh][ww + 1])

print(cost[h - 1][w - 1])

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define PI acos(-1)
#define falcon ios_base::sync_with_stdio(false) ; cin.tie(NULL) ;
typedef long long ll ;
using namespace std ;

vector <int> g[100001] , d(100001 , -1) ;
int maxlength = INT_MIN ;

void DFS(int s)
{
    d[s] = 0 ;
    for(int i = 0 ; i < g[s].size() ; i++)
    {
        int n = g[s][i] , length = 0 ;
        if(d[n] == -1) DFS(n) ;
        length = 1 + d[n] ;
        d[s] = max(d[s] , length) ;
    }
    maxlength = max(maxlength , d[s]) ;
}

int main()
{
    falcon ;

    int n , m ;
    cin >> n >> m ;
    for(int i = 0 ; i < m ; i++)
    {
        int u , v ;
        cin >> u >> v ;
        g[u].push_back(v) ;
    }
    for(int i = 1 ; i <= n ; i++) DFS(i) ;
    cout << maxlength << "\n" ;
}

Measured memory_bytes: 11060
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define in auto&it
#define out auto it
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
const double pi = acos(-1);
#define err(x) cerr<<#x<<" = "<<x<<'\n';
int main() {
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
		freopen("error.txt", "w", stderr);
	#endif
	fastio
	string s,t;
	cin>>s>>t;
	int mi=INT_MAX;
	for(int i=0;i<s.size()-t.size()+1;++i){
		int cnt=0;
		for(int j=0;j<t.size();++j){
			if(s[i+j]!=t[j]) ++cnt;
		}
		mi=min(cnt,mi);
	}
	cout<<mi;
	return 0;
}		

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 2e5+5;
const ll M = 1e9+7;
inline void fastio() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

int _;
ll qpow(ll a,ll b)
{
    ll s = 1;
    while(b)
    {
        if(b&1) s=(s*a)%M;
        a = (a*a)%M;
        b>>=1;
    }
    return s;
}
int main()
{
    fastio();
    ll n,K;
    cin>>n>>K;
    ll ans = 0;
    for(ll i=K;i<=n+1;i++)
    {
        ll L = (i-1)*i/2;
        ll R = (2*n-i+1)*i/2;
        ans = (ans+R-L+1+M)%M;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3656
#pragma GCC optimze("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#ifndef rd
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
// const int mod=998244353;
//const int mod=1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}

int powm(int a, int b, int mod) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}

char a[105][105];
int dp[105][105];

void solve() {
	int n,m;
	cin>>n>>m;
	fr(i,1,n)
		fr(j,1,m)
			cin>>a[i][j];
	memset(dp,0x3f,sizeof(dp));
	dp[1][1]=0;
	if(a[1][1]=='#')
		dp[1][1]=1;
	fr(i,1,n) {
		fr(j,1,m) {
			if(a[i][j]==a[i+1][j]||a[i][j]=='#') {
				dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
			} else {
				dp[i+1][j]=min(dp[i+1][j],dp[i][j]+1);
			}
			if(a[i][j]==a[i][j+1]||a[i][j]=='#') {
				dp[i][j+1]=min(dp[i][j+1],dp[i][j]);
			} else {
				dp[i][j+1]=min(dp[i][j+1],dp[i][j]+1);
			}
		}
	}
	cout<<dp[n][m]<<endl;


}

signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(8);
	int t=1;
//	cin>>t;
	while(t--)
		solve();
#ifdef rd
	cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}


Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    C = LS()

    j = N-1
    cnt = 0
    # print(C)
    for i in range(N):
        if i >= j: break
        ci = C[i]
        if ci == 'W':
            # change
            # print(i, j)
            for k in range(j, i, -1):
                j = k-1
                ck = C[k]
                if ck == 'R':
                    # print(i, j)
                    # C[i], C[k] = ck, ci
                    cnt += 1
                    break

    # print(C)
    print(cnt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 77624
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    int a, b, c;
    cin >> a >> b >> c ;
    //*/

    /*
    vector<int> vec(3);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;
    
    sort(vec.begin(), vec.end());
    //*/
    
    /*
    if( abs(a - b) % 2 != 0 ){
        cout << "IMPOSSIBLE" << endl;
    } else {
        cout << abs(a - b) / 2 + min(a, b) << endl;
    }
    //*/
    
    cout << min(a * b, c ) << endl;

    return 0; 
}


Measured memory_bytes: 3588
N,A,B = map(int,input().split())

b = 0
r = 0

if A >= N:
    print(N)
else:
    C = A * (N // (A+B) )
    D = N % (A+B) 
    if D <= A:
        print(C+D)
    else:
        print(C+A)



Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;

ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

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

  vector<int> push(n, 0);
  int ans = 0;
  int cur = 0;
  while(cur != 1){
    if(push[cur] == 0){
      push[cur] = 1;
      cur = a[cur] - 1;
      ans++;
    }
    else{
      cout << -1 << endl;
      return 0;
    }
  }

  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 1024
/*我是萌新*/
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <iomanip> 
#include<map>
typedef long long ll;
const int mod = 1e9+7;
using namespace std;
ll gcd(ll a, ll b){
    return b?gcd(b,a%b):a;
}
ll lcm(ll a, ll b){
    return a/gcd(a,b)*b;
}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll n,m;
    while(cin>>n>>m)
    {
        ll ans=0;
        for(int i=0;i<m;i++)
        {
            int x;
            cin>>x;
            ans+=x;
        }
        if(ans>n)cout<<"-1\n";
        else cout<<n-ans<<'\n';
    }
}



Measured memory_bytes: 3644
// Author : MohamedSameh
#include <bits/stdc++.h>
typedef long long ll ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define IN(n) scanf("%d" , &n )
#define debug(x) cout<<#x<<" = { "<<x<<" }\n"
void fo (){fflush(stdout);}
using namespace std;
int main ()
{
  ll l , r ;
  cin >> l >> r ;
  ll ans = min (  (l*r)%2019 , ((l+1) * (l))%2019 );
  ans = min (ans , ((r - 1 ) * r)%2019 );
  r  = min (r , l + 9000 );
  for (int i = l ; i < r ; i++)
  {
    for (int j = i+1 ; j<=r;j++)
    {
      ans = min (ans , 1LL * i * j % 2019 ); 
    }
  }
  cout << ans <<"\n";
  cerr << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}


Measured memory_bytes: 256
n=int(input())
l=[]
for i in range(n):
    s=input().split()
    s[1]=int(s[1])
    l.append(s)
l1=sorted(l, key=lambda l:l[1], reverse=True)
l2=sorted(l1, key=lambda l:l[0])
for i in l2:
    print(l.index(i)+1)

Measured memory_bytes: 9068
#include<iostream>

using namespace std;

using ll =  long long;

constexpr int N_MAX = 1000;
constexpr int M_MAX = 1000;
constexpr ll MOD = 1000000007;

namespace stirling {
    int n, m; // ボールの個数，グループ数
    ll s[N_MAX+1][M_MAX+1];
    
    void init(int nn, int mm) {
        n = nn;
        m = mm;
        s[0][0] = 1;
        for(int j=1;j<=m;++j) s[0][j] = 0;
        for(int i=1;i<=n;++i) s[i][0] = 0;
        for(int i=1;i<=n;++i) {
            for(int j=1;j<=m;++j) {
                s[i][j] = (s[i-1][j-1] + (s[i-1][j]*j) % MOD) % MOD;
            }
        }
    }

    const ll get(int i, int j) {
        return s[i][j];
    }
}

namespace bell {
    int n, m; // ボールの個数，グループ数
    ll b[N_MAX+1][M_MAX+1];
    
    void init(int nn, int mm) {
        n = nn;
        m = mm;
        stirling::init(n, m);
        for(int i=0;i<=n;++i) {
            b[i][0] = stirling::get(i, 0);
            for(int j=1;j<=m;++j) {
                b[i][j] = (b[i][j-1] + stirling::get(i, j)) % MOD;
            }
        }
    }

    const ll get(int i, int j) {
        return b[i][j];
    }
}

int main() {
    int n, m;
    cin >> n >> m;
    bell::init(n, m);
    cout << bell::get(n, m) << endl;
}


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 4e5 + 5;

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


  int H, W, h, w;
  cin>>H>>W;
  cin>>h>>w;
  cout<<H*W - h*W - w*H + h*w<<endl;
  

  return 0;
}


Measured memory_bytes: 256
s = list(input())

if len(s)%2!=0:
  point = int((len(s)-1)/2)
  count = 0
  for i in range(0,int((len(s)-1)/2+1)):
    if s[point-i]!=s[point+i]:
      count += 1
  print(count)
  exit()
elif len(s)%2==0:
  point1 = int(len(s)/2-1)
  point2 = int(len(s)/2)
  count = 0
  for i in range(0,int(len(s)/2)):
    if s[point1-i]!=s[point2+i]:
      count += 1
  print(count)

Measured memory_bytes: 3064
s = int(input())
d = set([s])
i = 1
while True:
    if s % 2 == 0:
        s = s // 2
    else:
        s = 3 * s + 1
    i += 1
    if s in d:
        print(i)
        break
    else:
        d.add(s)


Measured memory_bytes: 2940
import java.util.*;

public class Main {
//    private static final String ex = "0 75 25 100";
    private static final String ex = "10 90 20 80";

    public static void main(String[] args) {
        System.out.println(solve(new Scanner(System.in)));
//        System.out.println(solve(new Scanner(ex)));
    }

    private static int solve(Scanner scanner) {
        String[] split = scanner.nextLine().split(" ");

        int A = Integer.parseInt(split[0]);
        int B = Integer.parseInt(split[1]);
        int C = Integer.parseInt(split[2]);
        int D = Integer.parseInt(split[3]);

        if (B <= C || D <= A) return 0;
        else if (C <= A && B <= D) return B - A;
        else if (A <= C && D <= B) return D - C;
        else if (A <= C) return B - C;
        else if (C <= A) return D - A;
        else throw new RuntimeException();
    }
}


Measured memory_bytes: 23632
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
using namespace std;
#define INF 100000
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/

int main(){
    int A,B;
    cin>>A>>B;
    if(A<10 && B<10) cout<<A*B<<endl;
    else cout<<-1<<endl;
}



Measured memory_bytes: 256
#include <cmath>
#include <iostream>
using namespace std;
const double pi = acos(-1.0);

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

  double h = b * sin(C / 180 * pi);
  double L = a + b + sqrt(a * a - 2 * a * b * cos(C / 180 * pi) + b * b);
  double S = 0.5 * a * h;

  printf("%.9f\n", S);
  printf("%.9f\n", L);
  printf("%.9f\n", h);
}


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

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

    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());

    if(s < t)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define INF 1<<20
int main() {
	int N, W;
	cin >> N >> W;
	
	int v[N+1], w[N+1];
	for (int i=1; i<=N; i++) {
		cin >> v[i] >> w[i];
	}
	
	int d[N+1][W+1]={};
	for (int i=1; i<=N; i++) {
		for (int j=0; j<=W; j++) {
			if (j>=w[i]) {
				d[i][j]=max(d[i-1][j], d[i-1][j-w[i]]+v[i]);
			} else {
				d[i][j]=d[i-1][j];
			}
		}
	}
	cout << d[N][W] << endl;
}


Measured memory_bytes: 7032
#include<cstdio>
#include<queue>
#include<utility>
using namespace std;
char map[1000][1001];
int visited[1000][1000] = {};
int vec[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
struct point {
	int x; int y; int count;
};
int main() {
	int H, W, N;
	int i, j, k, x, y;
	int count, life;
	int factory[9][2];
	while (scanf("%d %d %d", &H, &W, &N) != EOF) {
		for (i = 0; i < H; i ++) scanf("%s", map[i]);
		life = 0;
		queue<struct point> q;
		for (i = 0; i < H; i ++) {
			for (j = 0; j < W; j ++) {
				visited[i][j] = 0;
				if (map[i][j] == 'S') {
					x = i, y = j;
				} else if (0 < map[i][j] - '0' && map[i][j] - '0' <= N) {
					factory[map[i][j] - '1'][0] = i; factory[map[i][j] - '1'][1] = j;
				}
			}
		}
		struct point p = {x, y, 0};
		q.push(p);
		visited[x][y] = 1;
		int flag = 1;
		while (flag) {
			struct point p = q.front(); q.pop();
			for (k = 0; k < 4; k ++) {
				x = p.x + vec[k][0]; y = p.y + vec[k][1];
				if (-1 < x && x < H && -1 < y && y < W && !(visited[x][y]) && map[x][y] != 'X') {
					if (x == factory[life][0] && y == factory[life][1]) {
						if (life == N - 1) {
							flag = 0; count = p.count + 1;
						}
						life ++;
						for (;!q.empty(); q.pop());
						for (i = 0; i < 1000; i ++) for (j = 0; j < 1000; j ++) visited[i][j] = 0;
						struct point pp = {x, y, p.count + 1};
						q.push(pp); visited[x][y] = 1;
						break;
					}
					struct point pp = {x, y, p.count + 1};
					q.push(pp); visited[x][y] = 1;
				}
			}
		}
		printf("%d\n", count);
	}
	return 0;
}

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

int main() {
	int count;
  vector<int> sinamono;
  cin >> count;
  for(int i=0;i<count;i++){
	int now;
    cin >> now;
    sinamono.emplace_back(now);
  }
  sort(sinamono.begin(), sinamono.end());
  int hangaku = sinamono.back() / 2;
  int sum = accumulate(sinamono.begin(), sinamono.end(), 0);
  cout << sum - hangaku;
}

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

// @author: pashka

int main() {
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<vector<pair<int, int>>> a(n);
    for (int i = 0; i < n; i++) {
        int k; cin >> k;
        for (int j = 0; j < k; j++) {
            int x, y;
            cin >> x >> y;
            x--;
            a[i].push_back({x, y});            
        }        
    }
    int res = 0;
    for (int x = 0; x < (1 << n); x++) {
        bool ok = true;
        for (int i = 0; i < n; i++) {
            if (x & (1 << i)) {
                for (auto p : a[i]) {
                    if (((x >> (p.first)) & 1) != p.second) {
                        ok = false;
                    }                    
                }                
            }
        }
        if (ok) {
            res = max(res, __builtin_popcount(x));
        }        
    }
    cout << res << "\n";

    return 0;
}

Measured memory_bytes: 256
n=io.read("*n", "*l")
t={}
for i=1, n do
    t[i]=io.read("*n")
end
total=0
for i=1, n do
    total=total+t[i]
end
m=io.read("*n", "*l")
for i=1, m do
    p,x=io.read("*n","*n","*l")
    print(total-t[p]+x)
end

Measured memory_bytes: 760
A, B, C = [int(s) for s in input().split()]
K = int(input())

i = 0
while B <= A:
    B = 2 * B
    i += 1

j = 0
while C <= B:
    C = 2 * C
    j += 1

if i + j <= K:
    print('Yes')
else:
    print('No')

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

int main() {
  string masume;
  cin >> masume;
    
  int ans = 0;
    
  if (masume[0] == '1') {
   ans++; 
  }
  if (masume[1] == '1') {
   ans++;
  }
  if (masume[2] == '1') {
   ans++; 
  } 
  cout << ans << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
string s;
int main(void){
    int n,a;
    cin>>n>>s;
    n=0;
    rep(i,0,s.size()){
        if(s[i]=='(') n++;
        else n--;
        if(n<0){
            s="("+s;
            n++;
            i++;
        }
    }
    while(n){
        s+=")";
        n--;
    }
    cout<<s;
    return 0;
}


Measured memory_bytes: 256
import sys
s = list(input())
k = int(input())
if len(s) == 1:
    print(s[0])
elif k == 1:
    print(s[0])
else:
    for i in range(k):
        if s[i] != "1":
            print(s[i])
            sys.exit()
    print(1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> as(n);
  for(Int i=0;i<n;i++) cin>>as[i];

  Int sum=0;
  for(Int a:as) sum^=a;
  for(Int &a:as) a&=~sum;

  Int res=0;
  const Int MAX = 60;
  for(Int j=MAX,k=0;j>=0;j--){
    for(Int i=k+1;i<n;i++)
      if((as[i]>>j)&1) swap(as[k],as[i]);

    if((~as[k]>>j)&1) continue;

    for(Int i=k+1;i<n;i++)
      if((as[i]>>j)&1) as[i]^=as[k];

    if((~res>>j)&1) res^=as[k];
    k++;
  }

  cout<<res+(sum^res)<<endl;
  return 0;
}


Measured memory_bytes: 1024
import java.security.KeyStore.TrustedCertificateEntry
import java.util
import java.util.{ArrayList, Collections, Comparator, List => JList}

import scala.collection.mutable
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.util.{Failure, Success, Try}

object Main{
  val LINE_SEPARATOR = "\n"
  def main(args: Array[String]): Unit = {
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString(LINE_SEPARATOR);
      println(solve(input).trim());
    }
  }

  def init (nRows: Int, nCols: Int, default: Int) = Array.tabulate(nRows,nCols)( (x,y) =>  default)

  def sortIgnoreCase1(list: JList[String]): JList[String] = {
    val r = new ArrayList[String](list)
    Collections.sort(r, new Comparator[String] {
      override def compare(o1: String, o2: String): Int = o1.compareToIgnoreCase(o2)
    })
    r
  }

  def solve(input: String): String = {
    val k = input.split(LINE_SEPARATOR).head.toInt
    val s = input.split(LINE_SEPARATOR).tail.head
    if (s.length > k) s.dropRight(s.length - k) + "..." else s
  }

  val tests=List(
    """40
      |ferelibenterhominesidquodvoluntcredunt""".stripMargin -> """ferelibenterhominesidquodvoluntcredunt
                                                                      |""".stripMargin,
    """7
      |nikoandsolstice""".stripMargin -> """nikoand...
                                               |
                                     |""".stripMargin
  )

  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}
      .zipWithIndex.map{
      case ((input,outputExpect),i)=>{
        val output=solve(input).trim();
        s"test${i+1}:"+(if(output==outputExpect){
          "Passed"
        }else{
          s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
        })
      }}
      .mkString("\n");
  }
}

Measured memory_bytes: 55268
#include<bits/stdc++.h>
using namespace std;
int a[3],cnt=3;
int main(){
	cin>>a[0]>>a[1]>>a[2];sort(a,a+3);
	if(a[0]==a[1])cnt--;
	if(a[1]==a[2])cnt--;
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;

struct Node {
	long long key;
	Node* left;
	Node* right;
};

void inseart(Node** root, Node* data) {
	if (*root == NULL) {
		*root = data;
		return;
	}
	Node* prev = NULL;
	Node* node = *root;
	while (node != NULL) {
		prev = node;
		if (node->key > data->key) {
			node = node->left;
		}
		else {
			node = node->right;
		}
	}
	if (prev->key > data->key) {
		prev->left = data;
	}
	else {
		prev->right = data;
	}
}

void visit(Node* root, vector<int>& pre,vector<int>& ino) {
	pre.push_back(root->key);
	if (root->left != NULL) {
		visit(root->left, pre, ino);
	}
	ino.push_back(root->key);
	if (root->right != NULL) {
		visit(root->right, pre, ino);
	}
}

void print(vector<int>& v) {
	for (int i = 0; i < v.size(); i++) {
		cout << " " << v[i];
	}
}


int main() {
	int n;
	int cnt = 0;
	Node node[500000];
	Node* root = NULL;

	cin >> n;
	for (int i = 0; i < n; i++) {
		string buf;
		vector<int> pre;
		vector<int> ino;
		int k;
		cin >> buf;
		if (buf == "insert") {
			cin >> k;
			node[cnt].key = k;
			node[cnt].left = NULL;
			node[cnt].right = NULL;
			inseart(&root, &node[cnt]);
			cnt++;
		}
		else {
			visit(root, pre, ino);
			print(ino);
			cout << endl;
			print(pre);
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 18836
#include <bits/stdc++.h>
#define ll long long int
#define mood (1000000007)
using namespace std;



int main()
{
    ll l,t,r,k,m,p,n,a,b,c,s;
  cin>>n>>m;
  string s1;
  ll arr[n][3]={0};
  s=0;
  c=p=0;
  for(int i=0;i<m;i++)
  {
      cin>>a>>s1;
      
      if(s1=="AC"&&arr[a-1][0]==0) 
      {
          arr[a-1][0]=1;
          c++;
          
      }
      else
      if(s1=="WA"&&arr[a-1][0]==0) 
      {
          arr[a-1][1]++;
          
          
      } 
      
      //cout<<a<<" "<<s1<<"\n";
      
  }
  for(int i=0;i<n;i++)
  {
      if(arr[i][0]==1) p+=arr[i][1];
  }
  
  
  
  /*
  for(int i=0;i<m;i++)
  {
      cin>>a>>s1;
      
      if(s1=="AC"&&arr[a]==0) 
      {
          
          (hhh[a].first)++;
          arr[a]=1;
      cout<<hhh[a].first<<"\n";
      }
      else
      if(s1=="WA"&&arr[a]==0) 
      {
          
          (hhh[a].second)++;
          //arr[a]=1;
      cout<<hhh[a].second<<"\n";
      } 
      cout<<a<<" "<<s1<<"\n";
      
  }
  c=0;
  p=0;
  for(int i=0;i<n;i++)
  {
      if(arr[i]==1) c++;
      a=hhh[i].second;
      p+=a;
  }*/
  cout<<c<<" "<<p;
  
    return 0;
}



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

using namespace std;

const double pi = 3.14159265358979323846;

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	double A, B, H, M;
	cin >> A >> B >> H >> M;
	double hx, hy, mx, my;
	double minutes_angle = (M / 60) * 360;
	double hour_angle = (H / 12 ) * 360 + M / 2.0;
	// cout << minutes_angle << ' ' << hour_angle << '\n';
	hy = A * cos(hour_angle * (pi / 180.0));
	hx = A * sin(hour_angle * (pi / 180.0));
	my = B * cos(minutes_angle * (pi / 180.0));
	mx = B * sin(minutes_angle * (pi / 180.0));
	// cout << hx << ' ' << hy << ' ' << mx << ' ' << my << '\n';
	cout << setprecision(15) << sqrt(pow(hx - mx, 2) + pow(hy - my, 2)) << '\n';


	return 0;
}

Measured memory_bytes: 4096
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (H, W): (usize, usize) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };
    let A: Vec<Vec<i64>> = {
        let mut A = vec![];
        for _ in 0..H {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            A.push(
                line.split_whitespace()
                    .map(|x| x.parse().unwrap())
                    .collect()
            );
        }
        A
    };
    let B: Vec<Vec<i64>> = {
        let mut B = vec![];
        for _ in 0..H {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            B.push(
                line.split_whitespace()
                    .map(|x| x.parse().unwrap())
                    .collect()
            );
        }
        B
    };

    let S = 80 * 160;
    let mut dp = vec![vec![vec![false; 2 * S + 1]; W]; H];
    let d_00 = (A[0][0] - B[0][0]).abs() as usize;
    dp[0][0][S + d_00] = true;
    dp[0][0][S - d_00] = true;
    for j in 1..W {
        let d_0j = (A[0][j] - B[0][j]).abs() as usize;
        for k in 80..(2 * S - 80 + 1) {
            dp[0][j][k] |= dp[0][j - 1][k + d_0j] || dp[0][j - 1][k - d_0j];
        }
    }
    for i in 1..H {
        let d_i0 = (A[i][0] - B[i][0]).abs() as usize;
        for k in 80..(2 * S - 80 + 1) {
            dp[i][0][k] |= dp[i - 1][0][k + d_i0] || dp[i - 1][0][k - d_i0];
        }
        for j in 1..W {
            let d = (A[i][j] - B[i][j]).abs() as usize;
            for k in 80..(2 * S - 80 + 1) {
                dp[i][j][k] |= dp[i - 1][j][k + d] || dp[i - 1][j][k - d] || dp[i][j - 1][k - d] || dp[i][j - 1][k + d];
            }
        }
    }
    let ans = (0..(2 * S + 1)).filter(|&k| dp[H -1][W - 1][k]).map(|k| (S as i64 - k as i64).abs()).min().unwrap();

    println!("{}", ans);
}

Measured memory_bytes: 215292
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

    if(s=="AAA" or s=="BBB")cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}





Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 266666;const ll inf=1e16;
int n,l[N],r[N];ll res;
priority_queue<ll>a;ll A;//x+A
priority_queue<ll,vector<ll>,greater<ll> >b;ll B;//x+B

int main() {
	read(n);rep(i,1,n)read(l[i]),read(r[i]);
	res=0;a.push(-inf);a.push(l[1]);b.push(l[1]);b.push(inf);
	rep(i,2,n){
		A-=r[i]-l[i];B+=r[i-1]-l[i-1];
	//	printf("%lld %lld\n",a.top()+A,b.top()+B);
		if(l[i]<=a.top()+A){
			res+=a.top()+A-l[i];
			b.push(a.top()+A-B);a.pop();
			a.push(l[i]-A);a.push(l[i]-A);
		}
		else if(l[i]>=b.top()+B){
			res+=max(l[i]-(b.top()+B),0LL);
			a.push(b.top()+B-A);b.pop();
			b.push(l[i]-B);b.push(l[i]-B);
		}
		else a.push(l[i]-A),b.push(l[i]-B);
	}
	cout<<res;return 0;
}


Measured memory_bytes: 2812
#include "iostream"
#include "vector"
#include "string"
#include <iomanip>
#include <algorithm>
#define rep(i,n) for (int i= 0; i < (n); ++i)
using ll = long long;
using namespace std;
const double PI = 3.14159265358979323846;


int main() {
	double N;
	string S;
	cin >> S;

	if (S.back() == 's') {
		S.append("es");
	}
	else {
		S.push_back('s');
	}

	cout << S << endl;

	return 0;

}

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

int main(){
  long double w,h,x,y;
  cin>>w>>h>>x>>y;
  double kotae=w*h/2;
  ll ans=0;
  if(2*x==w&&2*y==h){
    ans=1;
  }
  cout<<fixed<<setprecision(10)<<kotae<<" "<<ans<<endl;
}

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

int main(){
	int t,temp=0;
	cin >> t;
	bool cnt=0;
	while(t--){
		int a,b;
		cin >> a >> b;
		if(a==b) temp++;
		else temp=0;
		if(temp==3){
			cout << "Yes\n";
			cnt=1;
		}
	}
	if(!cnt) cout << "No\n";
}

Measured memory_bytes: 3632
import java.math.BigInteger;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.nio.charset.StandardCharsets;
public class Main {
  
  
   public static void main(String[] args) {
    UltraFast uf=new UltraFast();
    String st="ACL";
    int K=uf.nextInt();
    StringBuilder sb=new StringBuilder();
    for(int i=0;i<K;i++){
      sb.append(st);

    }
    System.out.println(sb);
   }







    
    
  static  class UltraFast {
      BufferedReader br;
      StringTokenizer st;

      public UltraFast() {
        BufferedInputStream bis = new BufferedInputStream(System.in);
        br = new BufferedReader(new InputStreamReader(bis, StandardCharsets.UTF_8));
      }

      String next() {
        while (st == null || !st.hasMoreElements()) {
          try {
            st = new StringTokenizer(br.readLine());
          } catch (IOException e) {
            e.printStackTrace();
          }
        }
        return st.nextToken();
      }

      int nextInt() {
        return Integer.parseInt(next());
      }

      long nextLong() {
        return Long.parseLong(next());
      }

      double nextDouble() {
        return Double.parseDouble(next());
      }

      String nextLine() {
        String str = "";
        try {
          str = br.readLine();
        } catch (IOException e) {
          e.printStackTrace();
        }
        return str;
      }

      int[] readintarray(int n) {
        int res[] = new int[n];
        for (int i = 0; i < n; i++)
          res[i] = nextInt();
        return res;
      }

      Integer[] readIntegerArray(int n) {
        Integer res[] = new Integer[n];
        for (int i = 0; i < n; i++)
          res[i] = nextInt();
        return res;
      }

      long[] readlongarray(int n) {
        long res[] = new long[n];
        for (int i = 0; i < n; i++)
          res[i] = nextLong();
        return res;
      }

      Long[] readLongArray(int n) {
        Long res[] = new Long[n];
        for (int i = 0; i < n; i++)
          res[i] = nextLong();
        return res;
      }
    }

  }

  

Measured memory_bytes: 32556
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    String T = sc.next();
    int A = sc.nextInt();
    int B = sc.nextInt();
    
    String U = sc.next();
    if (U.equals(S)) {
      A--;
    } else {
      B--;
    }
    System.out.println(String.format("%d %d", A, B));
  }
}


Measured memory_bytes: 22868
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

const int MOD = 1000000007;

int n,m;
int dp[100005];
bool a[100005];

int main(){
  cin >> n >> m;
  rep(i,100005) a[i] = true;
  rep(i,m){
    int tmp; cin >> tmp;
    a[tmp] = false;
  }
  dp[0] = 1;
  rep(i,n){
    if(a[i+1]) dp[i+1] += dp[i];
    if(a[i+2]) dp[i+2] += dp[i];
    dp[i+1] %= MOD;
    dp[i+2] %= MOD;
  }
  
  cout << dp[n] << endl;
  
  return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=1e6;
string S;
int N;
int Q;
int cpsm[MAX_N+1],mpsm[MAX_N+1];
int main(){
	cin>>N>>S>>Q;
	REP(i,N){
		cpsm[i+1]=cpsm[i]+(S[i]=='C');
		mpsm[i+1]=mpsm[i]+(S[i]=='M');
	}
	REP(q,Q){
		int k;
		cin>>k;
		ll mccnt=0;
		ll ans=0;
		int lb=0,ub=0;
		while(lb<N){
			while(lb<N && S[lb]!='D'){
				if (S[lb]=='M'){
					mccnt-=cpsm[ub]-cpsm[lb];
				}
				lb++;
			}
			if(lb==N)break;
			if(ub<lb){
				ub=lb;
				mccnt=0;
			}
			while(ub<N && ub-lb<k){
				if(S[ub]=='C'){
					mccnt+=mpsm[ub]-mpsm[lb];
				}
				ub++;
			}
			ans+=mccnt;
			lb++;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 9220
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) std::begin(x), std::end(x)
#define dump(x) cerr << #x " = " << x << endl
using namespace std;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
template <class T, class U> inline void chmax(T & a, U const & b) { a = max<T>(a, b); }
template <class T, class U> inline void chmin(T & a, U const & b) { a = min<T>(a, b); }
template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); }
template <typename T> ostream & operator << (ostream & out, vector<T> const & xs) { REP (i, (int)xs.size() - 1) out << xs[i] << ' '; if (not xs.empty()) out << xs.back(); return out; }

vector<bool> solve(int n, const vector<vector<pair<int, int64_t> > > & g) {
    vector<bool> color(n);
    function<void (int, int, int64_t)> go = [&](int x, int parent, int64_t depth) {
        color[x] = depth % 2;
        for (auto e : g[x]) {
            int y; int64_t d; tie(y, d) = e;
            if (y != parent) {
                go(y, x, depth + d);
            }
        }
    };
    go(0, -1, 0);
    return color;
}

int main() {
    int n; cin >> n;
    vector<vector<pair<int, int64_t> > > g(n);
    REP (i, n - 1) {
        int x, y; int64_t d; cin >> x >> y >> d;
        -- x;
        -- y;
        g[x].emplace_back(y, d);
        g[y].emplace_back(x, d);
    }
    vector<bool> color = solve(n, g);
    REP (i, n) {
        cout << color[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 10880
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;

#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
const double pi = 3.14159265358979;



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

    ll sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;

    ll x = tx - sx;
    ll y = ty - sy;

    rep(i,x){
        cout << "R";
    }
    rep(i,y){
        cout << "U";
    }
    rep(i,x){
        cout << "L";
    }
    rep(i,y){
        cout << "D";
    }
    cout << "D";
    rep(i,x+1){
        cout << "R";
    }
    rep(i,y+1){
        cout << "U";
    }
    cout << "LU";
    rep(i,x+1){
        cout << "L";
    }
    rep(i,y+1){
        cout << "D";
    }
    cout << "R" << endl;

}

Measured memory_bytes: 3588
//q015.cpp
//Thu Sep 24 21:38:09 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i,n) for (int i=0;i<(n);++i)

using namespace std;
using ll=long long;
typedef pair<double,double> P;

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

	P a[n];
	rep(i,n){
		double x,y;
		cin >> x >> y;
		a[i] = P(x,y);
	}

	sort(a,a+n);
	double ans = 0;
	double count = 0;
	do{
		rep(i,n-1){
			ans+=sqrt((a[i+1].first-a[i].first)*(a[i+1].first-a[i].first)+(a[i+1].second-a[i].second)*(a[i+1].second-a[i].second));
		}
		count++;
	}while(next_permutation(a,a+n));

	ans = ans/count;
	printf("%.10f\n",ans);
}

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

int A[100010];
int n;

int partition(int left,int right){
	int i=left-1;
	for(int j=left;j<right;j++){
		if(A[j]<=A[right]) {
			swap(A[i+1],A[j]);
			i++;
		}
	}
	swap(A[right],A[i+1]);
	return i+1;	
}

int main (){
	cin>>n;
	for(int i =0;i<n;i++) cin>>A[i];
	int x=partition(0,n-1);
	for(int i =0;i<n;i++) {
		if(i==0) cout<<A[i];
		else if(i==x) cout<<" ["<<A[i]<<"]";
		else cout<<" "<<A[i];
	}
	cout<<endl;
	return 0;
}


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

int n,k,ans;
int a[100];
int dp[100][100][100];

int main(){

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

    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            for(int l=0;l<=k;l++){
                dp[i][j][l]=-1e9;
            }
        }
    }
    dp[0][0][0]=0;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n-i;j++){
            for(int l=0;l<=k;l++){
                dp[i+1][j][l+1]=max(dp[i+1][j][l+1],dp[i][j][l]+a[i+1]);
                dp[i][j+1][l+1]=max(dp[i][j+1][l+1],dp[i][j][l]+a[n-j]);
                dp[i+1][j][l+2]=max(dp[i+1][j][l+2],dp[i][j][l]);
                dp[i][j+1][l+2]=max(dp[i][j+1][l+2],dp[i][j][l]);
            }
        }
    }
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n-i;j++){
            for(int l=0;l<=k;l++){
                if(dp[i][j][l]>ans){
                    ans=dp[i][j][l];
                    //cout<<i<<' '<<j<<' '<<l<<' '<<ans<<endl;
                }
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1536
n,k=[int(i) for i in raw_input().split()]
l=[[int(i) for i in raw_input().split()]for j in range(k)]
dp=[0 for i in range(n+1)]
dp[1]=1
dp1=[0 for i in range(n+1)]
dp1[1]=1
m=998244353
for i in range(2,n+1):
    dp1[i]=dp1[i-1]
    for j in l:
        if(i-j[1]>0):
            dp[i]+=dp1[i-j[0]]-dp1[i-j[1]-1]
        else:
            dp[i]+=dp1[i-j[0]]
    dp1[i]+=dp[i]
    dp1[i]%=m
    dp[i]%=m
print dp[n]%m


Measured memory_bytes: 75912
#include<iostream>
using namespace std;
int main(){
    int n,t,k,sum=0;
    cin>>n>>k;
    int a[n+1];
    for(int i=1;i<=n;i++)
    cin>>a[i];
    for(int i=1;i<=n-1;i++)
    for(int j=1;j<=n-i;j++)
    if(a[j]>a[j+1]){
    	t=a[j];
    	a[j]=a[j+1];
    	a[j+1]=t;
	}
	for(int i=1;i<=k;i++)
	sum+=a[i];
	cout<<sum;
	return 0;
} 

Measured memory_bytes: 3172
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
                Scanner scan = new Scanner(System.in);
                int iNumA = scan.nextInt();
                int iNumB = scan.nextInt();
                int iNumC = scan.nextInt();
                int count = 0;
                for(int i=iNumA; i<=iNumB; i++){
                	if(iNumC%i == 0)
                		count++;
                }
                System.out.println(count);
	}
}

Measured memory_bytes: 17356
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>

using namespace std;

int main(){
    long int n,m,d,t;
    cin>>n;
    map<int,int>a;
    for(int i=0;i<n;i++){
        cin>>d;
        auto itr=a.find(d);
        if(itr!=a.end()){
            a[d]++;
        }else a[d]=1;
    }
    cin>>m;
    for(int i=0;i<m;i++){
        cin>>t;
        if(a[t]>0)a[t]--;
        else{
            cout<<"NO\n";
            return 0;
        }
    }
    cout<<"YES\n";
}

Measured memory_bytes: 12816
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
const ll INF = 1e9;
inline ll read(){
    ll X = 0,w = 0 ;
    char ch = 0;
    while(!isdigit(ch)) {w |= ch == '-';ch = getchar();}
    while(isdigit(ch)) X = (X<<3) + (X<<1) + (ch ^ 48),ch = getchar();
    return w ? -X : X;
}
ll mod=1e9+7;
ll n;
ll dp[30][2100005];
ll a[30][30];
ll compute(ll i,ll cur)
{
    if(i==n)
    {
        if(cur==pow(2,n)-1)
        {
            return 1LL;
        }
        return 0LL;
    }
    if(dp[i][cur]!=-1)
    {
        return dp[i][cur];
    }
    ll ans=0;
    for(ll j=0;j<n;j++)
    {
        if(!((1<<j)&cur) and a[i][j])
        {
            ans+=compute(i+1,(1<<j)|cur);
            ans%=mod;
        }
    }
    return dp[i][cur]=ans;
}
int main()
{
    cin>>n;
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<n;j++)
        {
            cin>>a[i][j];
        }
    }
    memset(dp,-1,sizeof dp);
    cout<<compute(0,0);
    return 0;
}

Measured memory_bytes: 492544
#include<stdio.h>
int main(){
	int a,b,c,tmp;
	scanf("%d %d %d",&a,&b,&c);
	if(a>b){
		tmp=a;
		a=b;
		b=tmp;
	}
	if(b>c){
		tmp=b;
		b=c;
		c=tmp;
	}
	if(a>c){
		tmp=a;
		a=c;
		c=tmp;
	}
	if(a>b){
		tmp=a;
		a=b;
		b=tmp;
	}
	printf("%d %d %d\n",a,b,c);
	return 0;
}

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

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const ull MAX_N = 1000, MOD = 1e9+7;
ull N, A, B, C, D;
ull dp[MAX_N+1][MAX_N+1];
ull fact[MAX_N+1];
ull inv_fact[MAX_N+1];
ull inv_fact_pow[MAX_N+1];

//整数a,bに対し、ax + by = gcd(a,b) を満たす整数x,y,gcd(a,b) を計算する
ll extgcd(ll a, ll b, ll& x, ll& y) {
  ll d = a;
  if (b != 0) {
    d = extgcd(b, a%b, y, x);
    y -= (a/b) * x;
  } else {
    x = 1; y = 0;
  }
  return d;
}

//ax ≡ gcd(a,m) (mod m) を満たすxを計算する。
ll mod_inverse(ll a, ll m) {
  ll x, y;
  extgcd(a, m, x, y);
  return (m + x%m) % m;
}

void calc_fact(int n) {
  fact[0] = 1;
  for (int i = 1; i <= n; ++i) {
    fact[i] = (fact[i-1]*i)%MOD;
  }
}

void calc_inv_fact(int n) {
  for (int i = 0; i <= n; ++i) {
    inv_fact[i] = mod_inverse(fact[i], MOD);
  }
}

void calc_inv_fact_pow(int n, int c) {
  for (int k = 1; k <= n; ++k) {
    inv_fact_pow[k] = 1;
    for (int i = 1; i < c; ++i) {
      (inv_fact_pow[k] *= inv_fact[k]) %= MOD;
    }
  }
}


int main() {
  cin >> N >> A >> B >> C >> D;
  calc_fact(N);
  calc_inv_fact(N);
  calc_inv_fact_pow(N, C);


  for (int k = 0; k <= N; ++k) dp[k][0] = 1;
  for (int k = 1; k <= N; ++k) {
    for (int n = 1; n <= N; ++n) {
      if (A <= k && k <= B) {
        dp[k][n] = dp[k-1][n];
        ull t = inv_fact_pow[k];
        for (int x = C; x <= D; ++x) {
          if (n-k*x < 0) break;
          (t *= inv_fact[k]) %= MOD;
          (dp[k][n] += dp[k-1][n-k*x] * fact[n] % MOD * inv_fact[n-k*x] % MOD * t % MOD * inv_fact[x] % MOD) %= MOD;
        }
      } else {
        dp[k][n] = dp[k-1][n];
      }
    }
  }

  cout << dp[N][N] << endl;

  return 0;
}


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

typedef unsigned long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;

#define INF (int)(1e9)

#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,start,end) for(int i=(start);i<=(end);i++)
#define all(n) begin(n),end(n)

#define DEBUG

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

	if((abs(a-b) <= d && abs(b-c) <= d) || abs(a-c) <= d)
	{
		cout << "Yes" <<endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    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;
    }
}
ll 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 gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}

vector<pair<int,ll>> vec[100000];
ll cost[100000];
void dfs(int now,ll COST){
    cost[now]=COST;
    int next;
    REP(i,vec[now].size()){
        next=vec[now][i].first;
        if(cost[next]<0){
            dfs(next,COST+vec[now][i].second);
        }
    }
}
int counter(int x){
    if(!x)return 0;
    return counter(x>>1)+(x&1);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N=in();
    vector<int> A(N);
    for(auto&i:A){
        cin>>i;
    }
    int m;
    m=*max_element(all(A));
    int max_n=0;
    int second_max=0;
    REP(i,N){
        if(A[i]==m){
            max_n++;
        }else{
            second_max=max(second_max,A[i]);
        }
    }
    if(max_n>1)second_max=m;
    REP(i,N){
        if(A[i]==m){
            cout<<second_max<<endl;
        }else{
            cout<<m<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 5760
N, M = map(int, input().split())
switch_list=[input().split() for i in range(M)]
switch_list=[[int(i[m+1]) for m in range(len(i)-1)] for i in switch_list]
P_list=input().split()
P_list=[int(i) for i in P_list]
count=0
z=N
for i in range(1 << z):
    switch=[0 for i in range(N)]
    for j in range(z):
        if ((i >> j) & 1) == 1:
            switch[j]=1
    count+=sum([sum([switch[m-1] for m in switch_list[x]])%2==P_list[x] for x in range(M)])==M
print(count)


Measured memory_bytes: 3064