akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder.Contests.ABC165
{
    /// <summary>
    /// 
    /// </summary>
    static class E
    {
        static void Main(string[] args)
        {
            var n = NextInt();
            var m = NextInt();

            for (int i = 0; i < m; i++)
            {
                if (i % 2 == 0) Console.WriteLine((i/2 + 1) + " " + (n - i/2));
                else Console.WriteLine((n / 2 - i/2) + " " + (n / 2 + 2 + i/2));
            }
        }

        #region Console
        static int _index = 0;
        static string[] _buffer;

        static string Next()
        {
            if (_buffer == null || _index >= _buffer.Length)
            {
                _buffer = Console.ReadLine().Split();
                _index = 0;
            }

            return _buffer[_index++];
        }
        static int NextInt()
        {
            return int.Parse(Next());
        }
        static long NextLong()
        {
            return long.Parse(Next());
        }
        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }
        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
        static int[] ReadIntArray(int n)
        {
            var a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadInt();
            }
            return a;
        }
        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }
        static long[] ReadLongArray(int n)
        {
            var a = new long[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadLong();
            }
            return a;
        }
        static List<T> ReadObjects<T>(int n, Func<int[], T> creator)
        {
            var l = new List<T>(n);

            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                l.Add(creator(a));
            }

            return l;
        }

        static int[,] ReadMatrix(int n, int m)
        {
            var r = new int[n, m];
            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                for (int j = 0; j < m; j++)
                {
                    r[i, j] = a[j];
                }
            }
            return r;
        }
        #endregion
    }
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int n;
  cin >> n;
  int cur;
  cin >> cur;
  int count = 0;
  int ans = 0;
  rep(i, n - 1) {
    int t;
    cin >> t;
    if (cur >= t) {
      count++;
    } else {
      ans = max(count, ans);
      count = 0;
    }
    cur = t;
  }
  ans = max(count, ans);
  cout << ans;
}


Measured memory_bytes: 256
N = int(input())
S = list(map(int,input().split()))

ans = 0
for d in range(1,N):
    max_now = 0
    if (N-1) % d == 0:
        now = 0

        i, j = 0, N-1
        while i < j:
            now += S[i] + S[j]
            max_now = max(now, max_now)
            i += d
            j -= d
    else:
        now = 0

        i, j = 0, N-1
        while i < N-1 and j > d:
            now += S[i] + S[j]
            max_now = max(now, max_now)
            i += d
            j -= d
    
    ans = max(max_now, ans)

print(ans)

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

namespace Atc_0028
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();

            int A = int.Parse(str);

            Console.WriteLine(3 * A * A);

        }
    }
}


Measured memory_bytes: 27436
def matrixChainMultiplication(p):
    # p = [p_0, p_1, ..., p_n]
    n = len(p) - 1
    # n+1 x n+1 zero matrix?????????(0,...,n)
    # cost(i,j): (M_i...M_j)???????°??????????
    cost = [[0 for _ in range(n + 1)] for _ in range(n + 1)]
    for numOfMatrices in range(2, n + 1):
        for i in range(1, n - numOfMatrices + 2):
            j = i + numOfMatrices - 1
            cost[i][j] = float('inf')
            for k in range(i, j):
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k + 1][j] + p[i - 1] * p[k] * p[j])
    print(cost[1][n])

p = []
n = int(input())

for _ in range(n):
    listed_input = input().split()
    p.append(int(listed_input[0]))
p.append(int(listed_input[1]))

matrixChainMultiplication(p)

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

#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define f(i, a, b) for (int i=a; i<(signed)(b); ++i)
#define pc __builtin_popcount // counts number of 1's in bin(num)
#define pb push_back
#define mp make_pair

const double pi = 2*acos(0.0);
//__gcd(n1, n2);
//cout << fixed;
//cout << setprecision(6); //fixes # of dp
//tgamma(i+1) is 1!

void solve(){
    int n;
    cin >> n;
    int lst[n+1];
    memset(lst,0,sizeof(lst));
    f(i,0,n-1){
        int x;
        cin >> x;
        lst[x] += 1;
    }
    f(i,1,n+1){
        cout << lst [i] << "\n";
    }
}


int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
    solve();
}








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

int main(void){
    string abt ="abcdefghijklmnopqrstuvwxyz";
    string s;
    cin >> s;
    rep(i, 26){
        if (s.find(abt[i])==-1){
            cout << abt[i] << endl;
            return 0;
        }
    }
    cout << "None" << endl;
}

Measured memory_bytes: 512
# coding: utf-8
def eratosthenes(n):
    prime_table = [False,False,True]+[False if i%2!=0 else True for i in range(n-2)]
    i=3
    primes=[]
    while i*i<=n:
        if prime_table[i]:
            j=i*i
            while j<=n:
                prime_table[j]=False
                j+=i
        i+=2
    for i in range(len(prime_table)):
        if prime_table[i]:
            primes.append(i)
    return primes

a=eratosthenes(55555)    
n=int(input())
ans=[]
for i in range(len(a)):
    if a[i]%5==1:
        ans.append(a[i])
    if len(ans)==n:
        break
print(*ans)

Measured memory_bytes: 3992
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include <complex>

using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;
const int MOD = 1000 * 1000 * 1000 + 7;

const double EPS = 1e-6;
const int MAX = 33;

int C[MAX];

void go(int x, int cnt)
{
    FOR(i, 0, 26)
    {
        while(C[i] >= x && cnt > 0)
        {
            C[i] -= x;
            cnt--;
        }
    }
    if (cnt != 0)
    {
        cout << "No" << endl;
        exit(0);
    }
}

int main()
{
    //freopen("in.txt", "r", stdin);
    int n, m;
    cin >> n >> m;
    FOR(i, 0, n)
    {
        string s;
        cin >> s;
        FOR(i, 0, SZ(s))
            C[s[i] - 'a']++;
    }
    int cnt1 = (n * m) % 2;
    int cnt2 = (n / 2) * (m % 2) + (m / 2) * (n % 2);
    int cnt4 = (n * m - cnt2 * 2 - cnt1) / 4;
    
   // cout << cnt1 << " " << cnt2 << " " << cnt4 << endl;
    
    go(4, cnt4);
    go(2, cnt2);
    go(1, cnt1);
    
    cout << "Yes" << endl;
    
    return 0;
}


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

using namespace std;


int cnt_alpa[26];
char alpa[] = "abcdefghijklmnopqrstuvwxyz";

bool check() {
	for (int i = 0; i < 26; ++i) {
		if (cnt_alpa[i] >= 2) {
			return false;
		}
	}
	return true;
}

int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); ++i) {
		for (int j = 0; j < 26; ++j) {
			if (s[i] == alpa[j]) {
				cnt_alpa[j]++;
				break;
			}
		}
	}
	if (check()) {
		cout << "yes";
	}
	else {
		cout << "no";
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <map>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <set>
#include <cstring>
#include <string>
using namespace std;
#define LL long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define pii pair < int , int >

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int a,b;
	cin >> a >> b;
	int c = a - b;
	c = max( c, a + b );
	c = max( c, a * b );
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <sstream>
#include <set>
typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}



using namespace std;
int main(){
    int n,x,cnt =0;
    cin >> n;

    map<int, int> mp;
    REP(i,n){
        cin >> x;
        mp[x] ++;
    }

    for(auto x:mp){
        if(x.first == x.second) continue;
        else{
            if(x.first < x.second){
                cnt += x.second - x.first;
            }else{
                cnt += x.second;
            }
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
string pic[10];
int main()
{
  int h,w,k;
  cin>>h>>w>>k;
  int sum=0,cnt=0,ans=0;
  for(int i=0;i<h;i++)
    cin>>pic[i];
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      if(pic[i][j]=='#')
      sum++;
  for(int i=0;i<1<<h;i++)
  {
    for(int j=0;j<1<<w;j++)
    {
      cnt=0;
      for(int i1=1;i1<=h;i1++)
        for(int j1=1;j1<=w;j1++)
          if(i>>h-i1&1||j>>w-j1&1)
            if(pic[i1-1][j1-1]=='#')
              cnt++;
      if(cnt+k==sum) ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

const string YES = "Yes";
const string NO = "No";

void solve(long long N){
  for(ll i=1; i<=9; i++) {
    if(N%i==0 and N/i<=9 and 1<=N/i) {
      std::cout << YES << std::endl;
      return ;
    }

  }
  std::cout << NO << std::endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define rep(i,n) for(int i=0; i<n; i++)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてから使う
#define INF 2147483647
#define LLINF 9223372036854775807LL

int main(){
  ll a;
  double b;
  cin>>a>>b;
  a *= (int)(b*100+0.5);
  cout << a/100 << endl;
}

Measured memory_bytes: 3716
#include<iostream>
#include<string>

using namespace std;

int Atoi(char);

int main(){
  int i, j, na , m, n;
  char c, data[5][6];
  string str, _str;

  c = 97;
  for(i=0; i<5; ++i){
    for(j=0; j<5; ++j){
      data[j][i] = c;
      ++c;
    }
  }
  data[0][5] = c;
  data[1][5] = '.';
  data[2][5] = '?';
  data[3][5] = '!';
  data[4][5] = ' ';

  while(cin >> str){
    if(str.size()%2 == 1){
      cout << "NA" << endl;
    }else{
      na = 0;
      for(i=0; i<str.size(); i+=2){
	if(str[i] > '6'||  str[i] < '1' || str[i+1] > '5' || str[i+1] < '1'){
	  cout << "NA" << endl;
	  na = 1;
	  break;
	}

	n = Atoi(str[i]);
	m = Atoi(str[i+1]);
	_str.push_back(data[m-1][n-1]);
      }

      if(na == 0)
 	cout << _str << endl;

      _str.clear();
    }
  }

  return 0;
}

int Atoi(char c){
  int x;
  x = c - 48;
  return x;
}

Measured memory_bytes: 0
#[allow(unused_imports)]
use std::io::{stdin, Read, StdinLock};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::{HashSet, HashMap, BinaryHeap};
#[allow(unused_imports)]
use std::vec::Vec;

#[allow(dead_code)]
const INF: i32 = 1000_000_000;
#[allow(dead_code)]
const INFLL: i64 = 1000_000_000_000_000_000;
#[allow(dead_code)]
const EPS: f64 = 1.0e-10;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    #[allow(dead_code)]
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }

    #[allow(dead_code)]
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }

    #[allow(dead_code)]
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let n: usize = sc.read();
    let mut a: Vec<i32> = vec![0; n];
    for i in 0..n {
        a[i] = sc.read();
    }
    let mut now: usize = 0;
    let mut ans = 0;
    loop {
        ans += 1;
        match a[now] {
            0 => {
                ans = -1;
                break;
            },
            2 => {
                break;
            },
            nxt => {
                a[now] = 0;
                now = (nxt - 1) as usize;
            }
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<iostream>
#include<string>
using namespace std;
int main(){
  string a;
  int n;
  cin >> a >> n;
  for(int i=0;i<a.size();i++){
    if('z'+1-a[i]<=n&&a[i]!='a'){
      n-='z'+1-a[i];
      a[i]='a';
      //cout << n <<endl;
    }
    if(n==0)break;
    if(i+1==a.size()){
      if(n>=26)n%=26;
      for(int j=0;j<n;j++){
	a[i]++;
	if(a[i]=='z'+1)a[i]='a';
      }
      break;
    }
  }
  cout << a << endl;
  return 0;
}
  

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

int main() {
  
  int A, B;
  
  cin >> A >> B;
  int cnt=0;
  for (int i = A; i <= B; i++) {
    int q = i % 10;
    int p = (i / 10) % 10;
    int r = (i / 1000) % 10;
    int s = (i / 10000) % 10;
    if (q == s && p == r) cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


signed main()
{

ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n,k,s;
    cin>>n>>k>>s;
    if(s==1e9)
    {
        for(int i=1;i<=k;i++)
            cout<<s<<" ";
        for(int i=k+1;i<=n;i++)
            cout<<1<<" ";
    }
    else
    {
        int z=1e9;
        for(int i=1;i<=k;i++)
            cout<<s<<" ";
        for(int i=k+1;i<=n;i++)
            cout<<z<<" ";
        
    }
    

} 



Measured memory_bytes: 1280
#include <iostream>
#include <vector>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL<<60;
 
int main() {
  int H, N; cin >> H >> N;
  vector<int> A(N), B(N);
  for(int i=0; i<N; i++) cin >> A[i] >> B[i];
  
  vector<vector<long long>> dp(N+1, vector<long long>(H+1, INF));
  dp[0][0] =0;
  for(int i=0; i<N; i++){
    for(int j=0; j<=H; j++){
      chmin(dp[i+1][j], dp[i][j]);
      chmin(dp[i+1][min(j+A[i], H)], dp[i+1][j] +B[i]);
    }
  }
  cout << dp[N][H] << endl;
}

Measured memory_bytes: 78592
#include <cstdio>

int main(int argc, char const *argv[]) {
  int count = 0;
  char c, last;

  last = getc(stdin);
  while ((c = getc(stdin)) != '\n'){
    if (c == last) {
      ++count;
      if (c == '0') last = c + 1;
      else last = c - 1;
    } else {
      last = c;
    }
  }
  
  printf("%d\n", count);

  return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>

#include <numeric>

#include <map>

using namespace std;

typedef long long LL;

int n, m, k;

double p[2222], x[2222];

int a[1<<12][1010];

int b[1010][20], c[1010];

int main() {
    
    cin >> n >> m;
    memset(a, 0x3f, sizeof a);

    for (int i = 0; i <= m; ++i)
        a[0][i] = 0;
    
    for (int i = 1; i <= m; ++i) {
        cin >> c[i] >> b[i][0];
        for (int j = 1; j <= b[i][0]; ++j) {
            cin >> b[i][j];
            b[i][j] -= 1;
        }
    }

    for (int i = 1; i <= m; ++i) {
        int tmp = 0;
        for (int j = 1; j <= b[i][0]; ++j) {
            tmp += (1 << b[i][j]);
        }
        for (int k = 0; k < (1<<n); ++k) {
            if ((k | tmp) < (1<<n)) a[(k|tmp)][i] = min(a[(k|tmp)][i], a[k][i-1]+c[i]);// cout <<  k << ' ' << tmp <<' ' << i  << ' ' << a[k][i-1]+c[i] << endl;
            a[k][i] = min(a[k][i], a[k][i - 1]);
        }
    }
    int ans = 0x3f3f3f3f;
    for (int i = 1; i <= m; ++i) ans = min(ans, a[(1<<n)- 1][i]);
    if(ans == 0x3f3f3f3f) ans = -1;
    cout << ans << endl;


}

Measured memory_bytes: 16512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 1e9+7;
const int mx = 107;
void add_self(int& a, int b) {
    a += b;
    if(a >= mod) {
        a -= mod;
    }
}
int mul(int a, int b){
  return (ll)a * b % mod;
}
vector<int> v(mx+7);
int main(){
  int n;
  scanf("%d", &n);
  for(int i=1;i<=n-1;i++){
    scanf("%d", &v[i]);
  }
  int L = v[1];
  v[n] = INT_MAX;
  for(int i=2;i<=n;i++){
    L+=min(v[i],v[i-1]);
  }
  int R = v[n-1];
  for(int i=n-2;i>=1;i--){
    R+=min(v[i],v[i+1]);
  }
  cout<<max(L,R)<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

struct pt{
    int x, y, d;
    void move(int dir){
        x+=dx[dir];
        y+=dy[dir];
        d=dir;
    }
};

int main()
{
    char buf[8];
    bool h[5][4];
    bool v[4][5];
    for(int i=0; i<5; i++){
        cin.getline(buf, 8);
        for(int j=0; j<4; j++) h[i][j]=(buf[j]=='1'?true:false);
        if(i==4) break;
        cin.getline(buf, 8);
        for(int j=0; j<5; j++) v[i][j]=(buf[j]=='1'?true:false);
    }
    
    pt pos={0,0,0};
    do{
        for(int dd=3; dd<=6; dd++){
            int next=(pos.d+dd)%4;
            if(next==0){
                if(pos.x!=4&&h[pos.y][pos.x]){
                    pos.move(0);
                    cout<<'R';
                    break;
                }
            }else if(next==1){
                if(pos.y!=4&&v[pos.y][pos.x]){
                    pos.move(1);
                    cout<<'D';
                    break;
                }
            }else if(next==2){
                if(pos.x!=0&&h[pos.y][pos.x-1]){
                    pos.move(2);
                    cout<<'L';
                    break;
                }
            }else if(next==3){
                if(pos.y!=0&&v[pos.y-1][pos.x]){
                    pos.move(3);
                    cout<<'U';
                    break;
                }
            }
        }
    }while(pos.x!=0||pos.y!=0);
    cout<<'\n';
    return 0;
}

Measured memory_bytes: 2916
def solve():
  N, Q = map(int, input().split())
  S = input()

  count_list = [0] * N
  A_found = False
  count = 0

  for i, s in enumerate(S):
    if A_found and s == 'C':
      count += 1
      A_found = False
    else:
      A_found = s == 'A'
    count_list[i] = count

  for i in range(Q):
    l, r = map(int, input().split())
    print(count_list[r - 1] - count_list[l - 1])

solve()


Measured memory_bytes: 6108
def bb082():
    import sys
    s = list(input())
    t = list(input())

    s.sort()
    t.sort()
    t.reverse()

    if s == t:
        print('No')
        sys.exit()

    u = [s, t]
    u.sort()
    print('Yes' if u[0] == s else 'No')

bb082()

Measured memory_bytes: 3060
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections, copy, heapq


def solve(X: str):
    stack = []
    for s in X:
        if s == 'S':
            stack.append(s)
        if s == 'T':
            if len(stack) == 0:
                stack.append(s)
            elif stack[-1] == 'T':
                stack.append(s)
            elif stack[-1] == 'S':
                stack.pop()
    print(len(stack))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = next(tokens)  # type: str
    solve(X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 7480
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

#define ll long long
#define ull unsigned long long

#define	max	1000000007

ll gcd(ll a, ll b) {
	if (a < b)
		swap(a, b);
	while (ll r = a % b)
		a = b, b = r;
	return b;
}

class mod
{
public:
	ll val;

	mod(ll v)
	{
		val = v % max;
	}

	mod()
	{
		val = 0;
	}

	void operator -=(const mod &v)
	{
		val -= v.val;

		if (val < 0)
			val += max;
	}

	void operator +=(const mod &v)
	{
		if (val + v.val >= max)
			val -= max;
		val += v.val;
	}

	void operator +=(ll &v)
	{
		if (val + v >= max)
			val -= max;
		val += v;
	}

	void operator *=(const mod &v)
	{
		val *= v.val;
		val %= max;
	}

	void operator *=(ll &v)
	{
		val *= v;
		val %= max;
	}

	ll modinv(ll a)
	{
		ll b = max, u = 1, v = 0;
		while (b)
		{
			ll t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= max;
		if (u < 0)
			u += max;
		return u;
	}

	void operator /=(const mod &v)
	{
		val *= modinv(v.val);
		val %= max;
	}

	void operator /=(ll &v)
	{
		val *= modinv(v);
		val %= max;
	}
};

//	for priority queue
//	priority_queue<ipair, vector<ipair>, greater<ipair>>
using ipair = pair<int, pair<int, int>>;
bool operator>(const ipair a, const ipair b) { return a.first > b.first; };
bool operator<(const ipair a, const ipair b) { return a.first < b.first; };

int main()
{
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	long len = (h2 - h1) * 60;
	len += m2 - m1;
	len -= k;
	if (len < 0)
		len = 0;
	printf("%d", len);

	return 0;
}

Measured memory_bytes: 3252
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,a;
    cin>>n;
    std::deque<int> deq;
    for (int i=0;i<n;i++) {
        cin>>a;
        deq.emplace_back(a);
    }
    int count=0;
    for (int i=0;i<n;i++) {
        if ((i+1)%2==1&&deq[i]%2==1) {
            count++;
        }
    }
    cout<<count<<endl;
}


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

int main(){
	int human[5];
	while(cin>>human[0],human[0]){
		bool hand[3]={0,0,0};
		if(human[0]==1) hand[0]++;
		else if(human[0]==2) hand[1]++;
		else hand[2]++;
		for(int i=1;i<5;i++){
			cin>>human[i];
			if(human[i]==1) hand[0]++;
			else if(human[i]==2) hand[1]++;
			else hand[2]++;
		}
		if((hand[0]==true&&hand[0]==hand[1]&&hand[0]==hand[2])||(hand[0]==false&&hand[0]==hand[1])||(hand[0]==false&&hand[0]==hand[2])||(hand[1]==false&&hand[1]==hand[2])){
			for(int i=0;i<5;i++)cout<<'3'<<endl;
		}
		else if(hand[0]==true&&hand[0]==hand[1]){
			for(int i=0;i<5;i++){
				if(human[i]==1)cout<<'1'<<endl;
				else cout<<'2'<<endl;
			}
		}
		else if(hand[0]==true&&hand[0]==hand[2]){
			for(int i=0;i<5;i++){
				if(human[i]==3)cout<<'1'<<endl;
				else cout<<'2'<<endl;
			}
		}
		else if(hand[1]==true&&hand[1]==hand[2]){
			for(int i=0;i<5;i++){
				if(human[i]==2)cout<<'1'<<endl;
				else cout<<'2'<<endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1152
import java.util.*;
 
public class Main{
      public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            String str1 = sc.next();
            String str2 = sc.next();
            int num1 = sc.nextInt();
            int num2 = sc.nextInt();
            String vote = sc.next();
            if(vote.equals(str1)){
              System.out.println((num1 - 1) + " " + num2);
            } else {
              System.out.println(num1 + " " + (num2 - 1));
            }
          }
        }

Measured memory_bytes: 23892
N,K=map(int,input().split())
p=list(map(int,input().split()))

res=[]

res.append((sum(range(1,p[0]+1)))/p[0])

for i in range(1,N):
    res.append(res[i-1]+1+0.5*(p[i]-1))
ans=res[K-1]

for i in range(1,N-K+1):
    ans=max(ans,res[i+K-1]-res[i-1])
print(ans)

Measured memory_bytes: 25060
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<pair<string,pair<int,int>>> SP(N);
    
    for(int i=0;i<N;i++){
        cin >> SP[i].first >> SP[i].second.first;
        SP[i].second.second = i+1;
        SP[i].second.first = SP[i].second.first*-1;
    }
    
    sort(SP.begin(),SP.end());
    
    for(int i=0;i<N;i++){
        cout << SP[i].second.second << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod=1e9+7;
//const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=2e4+10;
const ll inf=0x3f3f3f3f;
const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};


int ans[maxn];
//Dijstra
struct Edge
{
    int u,v,w,next;
}e[maxn];
int head[maxn],cnt,n,m,s,vis[maxn],dis[maxn];
struct node
{
    int w,now;
    inline bool operator <(const node &x)const
    //重载运算符把最小的元素放在堆顶（大根堆）
    {
        return w>x.w;//这里注意符号要为'>'
    }
};
priority_queue<node>q;
//优先队列，其实这里一般使用一个pair，但为了方便理解所以用的结构体
inline void add(int u,int v,int w)
{
    e[++cnt].u=u;
    //这句话对于此题不需要，但在缩点之类的问题还是有用的
    e[cnt].v=v;
    e[cnt].w=w;
    e[cnt].next=head[u];
    //存储该点的下一条边
    head[u]=cnt;
    //更新目前该点的最后一条边（就是这一条边）
}
//链式前向星加边
void dijkstra()
{
    for(int i=1;i<=n;i++)
    {
        dis[i]=inf;
    }
    dis[s]=0;
    //赋初值
    q.push((node){0,s});
    while(!q.empty())
    //堆为空即为所有点都更新
    {
        node x=q.top();
        q.pop();
        int u=x.now;
        if(dis[u]<x.w)continue;
        for(int i=head[u];i;i=e[i].next)
        //搜索堆顶所有连边
        {
            int v=e[i].v;
            if(dis[v]>dis[u]+e[i].w)
            {
                dis[v]=dis[u]+e[i].w;
                //松弛操作
                q.push((node){dis[v],v});
                //把新遍历到的点加入堆中
            }
        }
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int x,y;
    cin>>n>>x>>y;
    for(int i=1;i<n;i++){
        add(i,i+1,1);
        add(i+1,i,1);
    }
    add(x,y,1);add(y,x,1);
    for(int i=1;i<=n;i++){
        s=i;
        dijkstra();
        for(int j=i+1;j<=n;j++)
            ans[dis[j]]++;
    }
    for(int i=1;i<n;i++)
        cout<<ans[i]<<endl;
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>

#define MAX 101
#define INFTY 100000000

int m[MAX][MAX];
int r[MAX];

int main(){

  int i, j, k, n, l;

  scanf("%d", &n);

  for(i = 1; i <= n; i++)
    scanf("%d %d", &r[i - 1], &r[i]);

  for(i = 1; i <= n; i++)
    m[i][i] = 0;

  for(l = 2; l <= n; l++)
    for(i = 1; i <= n - l + 1; i++){

      j = i + l - 1;

      m[i][j] = INFTY;

      for(k = i; k <= j - 1; k++)

        if(m[i][j] >  m[i][k] + m[k + 1][j] + r[i - 1] * r[k] * r[j])

          m[i][j] =  m[i][k] + m[k + 1][j] + r[i - 1] * r[k] * r[j];
          
                else m[i][j] = m[i][j];
    }

  printf("%d\n", m[1][n]);

  return 0;
}


Measured memory_bytes: 2104
A, B = input().split(" ")
A = int(A)
B = int(B)


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])


    if temp!=1:
        arr.append([temp, 1])


    if arr==[]:
        arr.append([n, 1])


    return arr
  
x_A = [x[0] for x in factorization(A)]
x_B = [x[0] for x in factorization(B)]


if x_A == [1] and x_B == [1]:
  print(1)
  exit()


ans = 1
for x in x_A:
  if x in x_B:
    ans += 1


print(ans)

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

int main(){
    string str;
    //freopen("B.txt","r",stdin);
    while(cin>>str){
        int m,n;
        int falg=0;
        m = (str[0]-'0')*10+(str[1]-'0');
        n = (str[2]-'0')*10+(str[3]-'0');
        if(0<=m&&m<=99&&0<n&&n<=12){
            if(0<=n&&n<=99&&0<m&&m<=12){
                    cout<<"AMBIGUOUS"<<endl;
               }
            else{
                cout<<"YYMM"<<endl;
            }
        }
        else if(0<=n&&n<=99&&0<m&&m<=12){
            if(0<=m&&m<=99&&0<n&&n<=12){
                    cout<<"AMBIGUOUS"<<endl;
               }
            else{
                cout<<"MMYY"<<endl;
            }
        }
        else {
            cout<<"NA"<<endl;
        }
    }
    return 0;
}


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


void solve(long long S){
  string str = to_string(S);
  vector<string> vec;
  long long ans = 0;

  // scan all bit pattern
  for (int s = 0; s < (1 << (str.size()-1)); s++) {
    string now = "";
    now += str[0];
    // scan which bit is valid or not
    for (int plus = 0; plus < str.size() - 1; plus++) {
      if (s & (1 << plus)) now += "+";
      now += str[plus + 1];
    }
    
    // calcurate
    long long sum = 0;
    int pos = 0;
    while (now.find("+", pos) != string::npos) {
      int nextpos = now.find("+", pos);
      sum += stoll(now.substr(pos, nextpos - pos));
      pos = nextpos + 1;
    }
    sum += stoll(now.substr(pos));
    ans += sum;
  }
  cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
  long long S;
  scanf("%lld",&S);
  solve(S);
  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict

n, k = map(int, input().split())
a = list(map(lambda x: int(x)-1, input().split()))
s = [0] * (n+1)
for i in range(n):
    s[i+1] = s[i] + a[i]
s = [x % k for x in s]
d = defaultdict(int)
ans = 0

for i in range(n+1):
    j = i - k
    if j >= 0: d[s[j]] -= 1
    ans += d[s[i]]
    d[s[i]] += 1

print(ans)

Measured memory_bytes: 42404
#include <iostream>
#include <cstdio>
using namespace std;
const long long N = 3010;
const long long S = 3010;
const long long mod = 998244353;
long long n, s;
long long a[N];
long long dp[S];
long long ans;
int main() {
    scanf("%lld%lld", &n, &s);
    for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]);
    for (long long i = 1; i <= n; i++) {
        if (s == a[i]) {
            ans += i * (n - i + 1) % mod;
            ans %= mod;
        } else if (s > a[i]) {
            ans += dp[s - a[i]] * (n - i + 1) % mod;
            ans %= mod;
        }
        for (long long j = s; j >= a[i]; j--) {
            dp[j] += (dp[j - a[i]] + (j == a[i] ? i : 0)) % mod;
            dp[j] %= mod;
        }
    } 
    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

    while(--d >= 0){
        int n;
        cin >> n;

        vector<int> e(n);
        for(int i=0; i<n; ++i)
            cin >> e[i];

        vector<int> dp(4*n+1, -1);
        dp[0] = 0;

        for(int i=0; i<n; ++i){
            vector<int> next(4*n+1, -1);
            for(int j=0; j<=4*n; ++j){
                if(dp[j] == -1)
                    continue;

                next[dp[j]] = max(next[dp[j]], e[i]);
                if(dp[j] > 0)
                    next[dp[j]-1] = max(next[dp[j]-1], e[i] + j);
            }
            dp.swap(next);
        }

        int ret = 0;
        for(int i=0; i<=4*n; ++i)
            ret = max(ret, dp[i]);
        cout << ret << endl;
    }

    return 0;
}

Measured memory_bytes: 1196
import java.io.IOException;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main
{
    public static final int MOD = 1_000_000_007;
    public static void main(String[] args) throws IOException {
//        BufferedReader in = new BufferedReader(new FileReader("pathsonagrid.txt"));
        Scanner in = new Scanner(System.in);

//        StringTokenizer line = new StringTokenizer(in.readLine());
        StringTokenizer line = new StringTokenizer(in.nextLine());

        int n = Integer.parseInt(line.nextToken());
        int m = Integer.parseInt(line.nextToken());
        
        char[][] grid = new char[n][m];
        for (int i = 0; i < n; i++)
//            grid[i] = in.readLine().trim().toCharArray();
            grid[i] = in.nextLine().trim().toCharArray();
        
        int[][] paths = new int[n][m];
        paths[0][0] = 1;
        for (int r = 0; r < n; r++) {
            for (int c = 0; c < m; c++) {
                if (grid[r][c] == '#')
                    continue;
                try { //look above
                    paths[r][c] += paths[r-1][c] % MOD;
                } catch (Exception e) {}
                try { //look left
                    paths[r][c] += paths[r][c-1] % MOD;
                } catch (Exception e) {}
            }
        }
        
        System.out.println(paths[n-1][m-1] % MOD);
    }
}

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

int h,w,c;
int panel[10][10], sub[10][10];
vector<int> seq;
bool vis[10][10];
const int dy[] = {-1,0,1,0}, dx[] = {0,1,0,-1};

int dfs(int y, int x, int col){
  if(vis[y][x])return 0;
  vis[y][x] = true;

  int res = 1;
  for(int i=0;i<4;i++){
    int ny = y+dy[i], nx = x+dx[i];
    if(ny<0 || nx<0 || ny>=h || nx>=w)continue;
    if(vis[ny][nx] || panel[ny][nx] != panel[0][0])continue;
    res += dfs(ny,nx,col);
  }

  panel[y][x] = col;
  return res;
}

int sim(void){
  int res = 0;
  for(int i=0;i<5;i++){
    memset(vis,0,sizeof(vis));
    dfs(0,0,seq[i]);
  }
  memset(vis,0,sizeof(vis));
  return dfs(0,0,0);
}

int rec(int depth){
  if(depth == 5){
    if(seq[depth-1] != c)return 0;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++)panel[i][j] = sub[i][j];
    }
    int res = sim();
    return res;
  }

  int res = 0;
  for(int i=1;i<=6;i++){
    seq.push_back(i);
    res = max(res, rec(depth+1));
    seq.pop_back();
  }
  return res;
}

int main(){
  while(cin >> h >> w >> c, h){
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++)cin >> sub[i][j];
    }
    cout << rec(0) << endl;
  }
}

Measured memory_bytes: 1216
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define ll long long
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define fi first
#define se second
#define pr(x) cerr<<#x<<"="<<(x)<<endl
#define pri(x,lo) {cerr<<#x<<"={";for (int ol=0;ol<=lo;ol++)cerr<<x[ol]<<",";cerr<<"}"<<endl;}
#define inf 100000000
#define N 1000
ll a,b,ans;
bool calc(ll xl,ll yl,ll len)
{
	ll xr=xl+len,yr=yl-len;
	if (xr<=yr) return xr*yr<a*b;
	if (xl>=yl) return xl*yl<a*b;
	ll t=(yl+xl)/2;
//	pr(666);
//	pr(t);
	if ((yl-xl)%2==0) return t*t<a*b;
	else return t*(t+1)<a*b;
}
bool check(ll x)
{
	ll y=x;x=1;
	ll o=a-1,p=x-b+1;
	//pr(o),pr(p);
	if (p<=0) 
	{
		if (calc(x,y,o)==0) return 0;
		x+=o,y-=o;x++; 
		if (calc(x,y,y)==0) return 0;
	}
	return 1;		
}
int main()
{
	int T;
	scanf("%d",&T);
	while (T--)
	{
		scanf("%lld %lld",&a,&b);
		if (a>b) swap(a,b);
		ll l=a-1,r=a-1+b-1;
		//pr(calc(9,35,35));return 0;
		//pr(check(42));return 0;
		while (l<=r)
		{
			ll mid=(l+r)/2;
			if (check(mid)) ans=mid,l=mid+1;
			else r=mid-1;
		}
		printf("%lld\n",ans);
	}
}

Measured memory_bytes: 256
N,M = map(int,input().split())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

div = make_divisors(M)
div.sort(reverse = True)

for d in div:
    if d*N > M:continue
    break
print(d)

Measured memory_bytes: 3060
//#include<bits/stdc++.h>
#pragma warning(disable:4996)
#include<stdio.h>
#include<iostream>
#include<set>
#include<vector>
#include<cmath>
#include<list>
#include<map>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>
#include<iomanip> 
#include<cstdlib> 
#include<string>

#define ll long long

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	cout << a * b << endl;

	return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LF double
#define LL long long
#define fo(i,j,k) for(int i=j;i<=k;i++)
#define fd(i,j,k) for(int i=j;i>=k;i--)
#define fr(i,j) for(int i=beg[j];i;i=nex[i])
using namespace std;
int const mn=15e5+3;
int n,d,cnt[25];
LL pw10[25],ans;
void dfs(int x,LL y,LL z){
	if(x>n/2-1){
		if(n&1)z*=10;
		if(y==d)
			ans+=z;
		return;
	}
	int i=-9;
	for(;(i+1<=9)&&(y+(i+1)*(pw10[n-x-1]-pw10[x]))<d;i++);
	dfs(x+1,y+i*(pw10[n-x-1]-pw10[x]),z*(cnt[i+10]-((!x)&&(i>=0))));
	if(i+1<=9)i++,dfs(x+1,y+i*(pw10[n-x-1]-pw10[x]),z*(cnt[i+10]-((!x)&&(i>=0))));
}
int main(){
	scanf("%d",&d);
	pw10[0]=1;
	fo(i,1,19)pw10[i]=pw10[i-1]*10;
	fo(i,0,9)fo(j,0,9)cnt[i-j+10]++;
	fo(i,2,19)n=i,dfs(0,0,1);
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#define rep(i, s, g) for (i = s; i <= g; i++)
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

int main(void)
{
    int H, N;
    int a, b;
    vector<int> dp(100010, MOD);
    int i, j;

    cin >> H >> N;

    dp[0] = 0;

    rep(i, 1, N)
    {
        cin >> a >> b;

        rep(j, 1, H)
        {
            dp[j] = min(dp[max(j - a, 0)] + b, dp[j]);
        }
    }

    cout << dp[H] << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;

const int INF = 1e+9;

struct State {
  int f, v, tickets;
  State(int f, int v, int t) : f(f), v(v), tickets(t) {}
};

struct Node {
  int to, c;
  Node(int to, int c) : to(to), c(c) {}
};

bool operator > (const State& lhs, const State& rhs){
  if(lhs.f == rhs.f)
    return (lhs.v == rhs.v) ? lhs.tickets > rhs.tickets : lhs.v > rhs.v;
  else
    return lhs.f > rhs.f;
}

int N, M, C, d[101][11];
vector<Node> G[101];

void dijkstra(int s){
  for(int i = 0; i <= N; ++i)
    for(int j = 0; j <= C; ++j)
      d[i][j] = INF;
  for(int i = 0; i <= C; ++i)
    d[s][i] = 0;
  priority_queue<State, vector<State>, greater<State> > que;
  que.push(State(0, s, C));
  while(!que.empty()){
    State st = que.top();
    que.pop();
    if(d[st.v][st.tickets] < st.f)
      continue;
    for(int i = 0; i < G[st.v].size(); ++i){
      Node n = G[st.v][i];
      if(d[n.to][st.tickets] > st.f + n.c){
	d[n.to][st.tickets] = st.f + n.c;
	que.push(State(d[n.to][st.tickets], n.to, st.tickets));
      }
      if(d[n.to][st.tickets - 1] > st.f + n.c / 2){
	d[n.to][st.tickets - 1] = st.f + n.c / 2;
	que.push(State(d[n.to][st.tickets - 1], n.to, st.tickets - 1));
      }
    }
  }
}


int main() {
  int s, e, a, b, f;
  while(cin >> C >> N >> M >> s >> e && (N || M || C || s || e)){
    for(int i = 0; i <= 100; ++i)
      G[i].clear();
    for(int i = 0; i < M; ++i){
      scanf("%d%d%d", &a, &b, &f);
      G[a].push_back(Node(b, f));
      G[b].push_back(Node(a, f));
    }
    dijkstra(s);
    int ans = INF;
    for(int i = 0; i <= C; ++i)
      ans = min(ans, d[e][i]);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1280
import java.util.*;

public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = Integer.parseInt(sc.next());
        int r = Integer.parseInt(sc.next());
        int ans = (n >= 10) ? r : r + 100 * (10 - n);
        System.out.println(ans);
    }
}

Measured memory_bytes: 22612
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

vector<string> s;
int main()
{
	string S;
	int K;
	cin >> S >> K;
	for (int i = 0; i < S.size(); i++) {
		for (int j = 1; j <= 5; j++) {
			string tmp = S.substr(i, j);
			s.push_back(tmp);
		}
	}
	sort(s.begin(), s.end());
	int count = 1;
	for (int i = 1; i < s.size(); i++) {
		if (count == K) {
			cout << s[i - 1] << endl;
			return 0;
		}
		if (s[i] != s[i - 1]) {
			count++;
		}
	}
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
#define INF 1<<30

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i,N)cin >> A[i];
    int mae = 0;
    ll step = 0;
    REP(i,N){
        if(A[i]>=mae){
            mae = A[i];
        }
        else{
            step += mae-A[i];
        }
    }
    cout << step << endl;
    return 0;
}

Measured memory_bytes: 3952
#include <iostream>
#include <string>
#include <cmath>
#define rep(i,n) for (int i = 0; i<(n); i++)
using namespace std;
using P = pair<int,int>;
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#define rep(i,n) for (int i = 0; i<(n); i++)
using namespace std;
using P = pair<int,int>;
#include <vector>
#include <algorithm>
#include <stdlib.h>


int main() {
    int temp;
   cin >> temp;
   if(temp >= 30){
       cout <<"Yes";
   }else{
       cout << "No";
   }

    return 0;

}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>   //PBDS
#include <ext/pb_ds/tree_policy.hpp>       //PBDS
#define int long long int
#define vi vector<int>
#define vii vector<pair<int,int>>
#define pi pair<int,int>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define mi map<int,int>
#define PI  3.141592653589
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define f(i,x,n) for(int i=x;i<n;i++)
#define rf(i,x,n) for(int i=n-1;i>=x;i--)
#define check(x)   cerr<<#x<<" : "<<x<<endl;
#define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
#define fbo find_by_order                    //return iterator PBDS
#define ook order_of_key                     //return number :)) PBDS
#define baar exit(0)
using namespace __gnu_pbds;
using namespace std;
int powmod(int base,int exponent,int mod)
{
    int ans=1;
    while(exponent){
        if(exponent&1)ans=(ans*base)%mod;
        base=(base*base)%mod;
        exponent/=2;
    }
    return ans;
}
signed main()
{
//   #ifndef ONLINE_JUDGE
//   freopen("input.txt", "r", stdin);
//   freopen("output.txt", "w", stdout);
//   #endif
    fast
    int t;
    cin>>t;
    if(t>=30)
    {
    	cout<<"Yes";
	}
	else cout<<"No";
	//cerr << "Time elapsed: " << clock() / 1000 << " ms" << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll a[51],p[51],n,k,ans;

void dep(ll now){
	if(k<=0){
		return;
	}		
	if(now==0){
		
		ans++;
		k--;
		return;
	}
	ll next=a[now-1];
	k--;
	if(k<=0){
		return;
	}	
	if(k>=next){
		k-=next;
		ans+=p[now-1];
	}
	else{
		dep(now-1);
	}
	if(k<=0){
		return;
	}	
	ans++;k--;
	if(k<=0){
		return;
	}
	if(k>=next){
		k-=next;
		ans+=p[now-1];
	}
	else{
		dep(now-1);
	}
	if(k<=0){
		return;
	}	
	k--;	if(k<=0){
		return;
	}
}
int main() {
	cin>>n>>k;
	a[0]=p[0]=1;
	for(int i=1;i<51;i++){
		a[i]=2*a[i-1]+3;
		p[i]=2*p[i-1]+1;
	}
	dep(n);
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a == 5){
        if(b == 7){
            if(c == 5){
                cout << "YES" << endl;
            }else {
                cout << "NO" << endl;
                }
        }else if(b == 5){
            if(c == 7){
              cout << "YES"<<endl;
            }else{
                cout <<"NO"<<endl;
                }
        }else{
            cout << "NO"<<endl;
        }
        
    }else if (a == 7){
        if(b == 5 && c == 5){
            cout << "YES" <<endl;
        }else{
            cout << "NO" <<endl;
        }
    }else{
        cout << "NO"<<endl;
    }
}



Measured memory_bytes: 256
#include <stdio.h>
#define MAX 500000
#define INFTY 1000000000

void mergeSort(int A[],int,int);
void merge(int A[],int,int,int);
int left,right,A[MAX],n,count=0;

int main(){
  int i,j;
  
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  left = 0;
  right = n;

  mergeSort(A,left,right);

  for(i=0;i<n-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[n-1]);
  printf("%d\n",count);


  return 0;
}


void mergeSort(int A[],int left,int right){
  if(left+1<right){
    int mid = (left + right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}

void merge(int A[],int left,int mid,int right){
  int n1,n2,i,j,k;
  
  n1 = mid - left;
  n2 = right - mid;
  
  int L[n1],R[n2];
 for(i=0;i<n1;i++){
   L[i] = A[left+i];
 }
 for(j=0;j<n2;j++){
   R[j] = A[mid+j];
 }
 
 L[n1] = INFTY;
 R[n2] = INFTY;
 i = 0;
 j = 0;
 
 for (k=left;k<right;k++){
   count++;
   
   if (L[i] <= R[j]){
    A[k] = L[i];
    i++;
   }
   else{
     A[k] = R[j];
     j++;
   }
   
 }
 
}



Measured memory_bytes: 5604