akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    int H,W;
    string[,] s;
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Read();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(s[i,j] == "snuke"){
                    sb.Append((char)(j+'A')+"");
                    sb.Append((int)(i+1)+"\n");
                }
            }
        }
    }
    void Read(){
        string[] str = Console.ReadLine().Split(' ');
        H = int.Parse(str[0]);
        W = int.Parse(str[1]);
        s = new string[H,W];
        for(int i=0;i<H;i++){
            str = Console.ReadLine().Split(' ');
            for(int j=0;j<W;j++){
                s[i,j] = str[j];
            }
        }
    }    
}

Measured memory_bytes: 2776
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int R = sc.nextInt();
        int S = sc.nextInt();
        int P = sc.nextInt();
        String T = sc.next();
        int res = IntStream.range(0, K).map(
            mod->maxValue(mod, T, R, S, P, K)
        ).sum();
        System.out.println(res);
    }

    public static int maxValue(int mod, String T, int R, int S, int P, int K){
        int rock, sci, pap;
        rock=0;sci=0;pap=0;

        int ind=mod;
        while(ind < T.length()){
            int nr, ns, np;
            np = Math.max(rock, sci);
            nr = Math.max(sci, pap);
            ns = Math.max(rock, pap);
            switch(T.charAt(ind)){
                case 'r':
                    np += P;
                    break;
                case 's':
                    nr += R;
                    break;
                case 'p':
                    ns += S;
                    break;
            }
            rock = nr;sci = ns;pap = np;
            ind += K;
        }
        return Math.max(rock, Math.max(sci, pap));
    }
}


Measured memory_bytes: 29496
#include <stdio.h>
#include <stdlib.h>

#define SIZE 2000000

int myatoi(const char* p)
{
  int n=0;
  while (*p!='\n') {
    n = n*10+*p-'0';
    p++;
  }
  return n;
}

int main() {
  int A[SIZE];
  int H=0;
  int i, l, largest, tmp;
  char com[21];
  do {
    fgets(com, 20, stdin);
    if (com[0] == 'i') {
      A[++H] =myatoi(com+7);
      for (i=H; i>1 && A[i/2]<A[i];i/=2) {
        tmp = A[i/2];
        A[i/2] = A[i];
        A[i] = tmp;
      }

    } else if (com[1]=='x') { // extract
      printf("%d\n", A[1]);
      A[1] = A[H];
      i = 1;
      while (1) {
        l = i*2;
        largest = i;
        if (l < H && A[l] > A[i])        largest = l;
        if (l+1 < H && A[l+1] > A[largest])  largest = l+1;
        if (largest == i) break;
        tmp = A[i];
        A[i] = A[largest];
        A[largest] = tmp;
        i = largest;
      }
      H--;
    }
  } while (com[2]!='d');
  return 0;
}


Measured memory_bytes: 5604
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s,t; cin >> s >> t;
    int i,n = s.size(),cnt = 0;
    for(i=0;i<n;i++){
        if(s[i]!=t[i]) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3916
n = int(input())
a = [int(input()) for _ in range(n)]
a.sort()
p1 = []
p2 = []
for i in range(n):
    x = 2
    if i == 0 or i == n-1:
        x = 1
    if i % 2 == 0:
        p1.append(x)
        p2.append(-x)
    else:
        p1.append(-x)
        p2.append(x)
p1.sort()
p2.sort()

ans1 = 0
ans2 = 0
for i in range(n):
    ans1 += a[i]*p1[i]
    ans2 += a[i]*p2[i]

print(max(ans1, ans2))

Measured memory_bytes: 9556
#include <iostream>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    int h[n]; for(int i = 0; i < n; ++i) cin >> h[i];
    int ans = 0, cnt = 0;
    for(int i = 1; i < n; ++i){
        if(h[i] <= h[i-1]) cnt++;
        else{
            ans = max(ans, cnt);
            cnt = 0;
        }
    }
    ans = max(ans, cnt);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3988
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
ll a,b;cin>>a>>b;
for(int i=1;i<a+b;i++){
    if((i*(i-1)/2)-a==(i*(i+1)/2)-b)
    {
        cout<<(i*(i-1)/2)-a<<endl;
    }
}
cout<<endl;

}


Measured memory_bytes: 256
import math
n=int(input())
a=list(map(int,input().split()))
ans=9999999999
hidari=sum(a)
migi=0
for i in range(n):
    hidari-=a[i]
    migi+=a[i]
    sa=math.fabs(hidari-migi)
    if sa<ans:
        ans=sa
print(int(ans))


Measured memory_bytes: 27300
n = gets.chomp.to_i
b = gets.chomp.split(' ').map(&:to_i)

a = [b[0]] + b

(n-1).times do |i|
  a[i] = b[i] if b[i] < a[i]
  a[i+1] = b[i] if b[i] < a[i+1]
end

print(a.reduce(:+))


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

void ABC169E()
{
	int N;
	cin >> N;
	vi A(N), B(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> A[i] >> B[i];
	}
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	int m1 = (N - 1) / 2;
	int m2 = N / 2;
	int l1 = A[m1];
	int h1 = B[m1];
	int l2 = A[m2];
	int h2 = B[m2];
	if (m1 == m2)
	{
		cout << h1 - l1 + 1 << endl;
		return;
	}

	int y1 = l1 + l2;
	int y2 = h1 + h2;
	cout << y2 - y1 + 1 << endl;
}

int main()
{
	ABC169E();
	return 0;
}


Measured memory_bytes: 4840
#include <bits/stdc++.h>
#define meow(args...) fprintf(stderr, args)
typedef unsigned u32;
typedef long long s64;
typedef unsigned long long u64;
template<class T1, class T2> inline bool cmin(T1 &a, const T2 &b) {return b<a?(a=b, true):false;}
template<class T1, class T2> inline bool cmax(T1 &a, const T2 &b) {return a<b?(a=b, true):false;}
template<class Type> Type read() {
	Type a;
	bool b;
	unsigned char c;
	while(c=getchar()-48, (c>9)&(c!=253));
	for(a=(b=c==253)?0:c; (c=getchar()-48)<=9; a=a*10+c);
	return b?-a:a;
}
int (*rd)()=read<int>;

const int N=501;
int l[N], r[N], p[N], f[N];
int main() {
	int n, m, ans=0;
	n=rd(), m=rd();
	for(int i=0; i<n; ++i) {
		l[i]=(int)sqrt(n*n-i*i);
		if(l[i]*l[i]==n*n-i*i) --l[i];
		r[i]=(int)sqrt(4*n*n-i*i);
		if(r[i]==2*n) --r[i];
	}
	for(int i=n; i<2*n; ++i) l[i]=(int)sqrt(4*n*n-i*i);
	for(int i=0; i<2*n; ++i) p[i]=i;
	std::sort(p, p+2*n, [](int x, int y) {return l[x]<l[y]||l[x]==l[y]&&r[x]<r[y];});
	for(int k=0; k<=n; ++k) {
		int cnt=0;
		f[0]=1;
		memset(f+1, 0, k*sizeof(int));
		for(int i=0; i<2*n; ++i)
			if(p[i]<n) {
				for(int j=cnt; j>=0; --j) {
					f[j+1]=(f[j+1]+(s64)f[j]*(l[p[i]]-i-j+cnt+1))%m;
					f[j]=(s64)f[j]*(r[p[i]]-2*n+p[i]-k+j+2)%m;
				}
				++cnt;
			} else
				for(int j=0; j<=cnt; ++j)
					f[j]=(s64)f[j]*(l[p[i]]-i-j+cnt+1)%m;
		ans=(ans+(k&1?-1:1)*f[k])%m;
	}
	if(ans<0) ans+=m;
	printf("%d\n", ans);
	return 0;
}


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

int main() {
  stack<int> s;
  int a, b;
  string token;
  while(cin >> token) {
    if(token == "+") {
      b = s.top(); s.pop();
      a = s.top(); s.pop();
      s.push(a+b);
    } else if (token == "-") {
      b = s.top(); s.pop();
      a = s.top(); s.pop();
      s.push(a-b);
    } else if (token == "*") {
      b = s.top(); s.pop();
      a = s.top(); s.pop();
      s.push(a*b);
    } else {
      s.push(stoi(token));
    }
  }
  cout << s.top() << endl;
  return 0;
}



Measured memory_bytes: 3168
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 1LL << 60;

int main() {
  int N; cin>>N;
  long long candy[2][110];
  long long dp[2][110];
  for(int i=0; i<2; i++){
    for(int j=0; j<N; j++){
      cin>>candy[i][j];
      }
    }
  
  dp[0][0]=candy[0][0];
  for(int j=1; j<N; j++){
    dp[0][j]=dp[0][j-1]+candy[0][j]; //0段目
  }
  
  dp[1][0]=dp[0][0]+candy[1][0]; //左下
  for(int j=1; j<N; j++){
    dp[1][j]=max(dp[0][j]+candy[1][j], dp[1][j-1]+candy[1][j]);
    // chmax(dp[1][j], dp[0][j]+candy[1][j]); //上から
    // chmax(dp[1][j], dp[1][j-1]+candy[1][j]); //左から
  }
    // 答え
    cout << dp[1][N-1] << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
optimal = {'r':'p', 's':'r', 'p':'s'}
point = {'r':R, 's':S, 'p':P}
ans = 0

A = []

for i in range(0, N):
    if i <= K-1:
        A.append(optimal[T[i]])
        ans = ans + point[A[i]]
    elif A[i-K] != optimal[T[i]]:
        A.append(optimal[T[i]])
        ans = ans + point[A[i]]
    elif i + K <= N-1:
        if optimal[T[i]] != 'r' and optimal[T[i+K]] != 'r':
            A.append('r')
        elif optimal[T[i]] != 's' and optimal[T[i+K]] != 's':
            A.append('s')
        else:
            A.append('p')
    else:
        if optimal[T[i]] != 'r':
            A.append('s')
        elif optimal[T[i]] != 's':
            A.append('p')
        else:
            A.append('r')

print(ans)

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

int main(){
  int n;
  cin >> n;
  vector<vector<int>> vec(2,vector<int>(n));
  for(int i=0; i<2; ++i){
    for(int j=0; j<n; ++j){
      cin >> vec[i][j];
    }
  }
  int dp[2][n];
  dp[0][0] = vec[0][0];
  for(int i=1; i<n; ++i){
    dp[0][i] = dp[0][i-1] + vec[0][i];
  }
  for(int i=0; i<n; ++i){
    dp[1][i] = dp[0][i] + vec[1][i];
    if(i) dp[1][i] = max(dp[1][i], dp[1][i-1] + vec[1][i]);
  }
  cout << dp[1][n-1] << endl;
}

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

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {

            while (true)
            {
                int[] intInputNum = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

                if (intInputNum[0] == 0 && intInputNum[1] == 0)
                {
                    break;
                }

                else
                {
                    int intCount = 0;

                    for (int num1 = 1; num1 <= intInputNum[0]; num1++)
                    {
                        for (int num2 = num1 + 1; num2 <= intInputNum[0]; num2++)
                        {
                            for (int num3 = num2 + 1; num3 <= intInputNum[0]; num3++)
                            {
                                if (num1 + num2 + num3 == intInputNum[1])
                                {
 
                                    intCount += 1;
                                    break;
                                }
                            }
                        }
                    }

                    Console.WriteLine(intCount);
                }
            }
        }
    }
}





Measured memory_bytes: 18444
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use proconio::*;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    input! {
        n:usize,
        a:[isize;n],
    }

    let sum = a.iter().sum::<isize>();

    let mut ans = U_INF;
    let mut now = I_INF;

    for i in 0..n {
        if (a[i] * n as isize - sum).abs() < now {
            ans = i;
            now = (a[i] * n as isize - sum).abs() as isize;
        }
    }
    
    println!("{}", ans);
}


Measured memory_bytes: 2188
#include <iostream>
#include <cstdio>
#define N 1005
using namespace std;

int n, x[N], y[N];

int abs(int p) {return p > 0 ? p : -p;}

int main()
{
	int i, j;
	cin >> n;
	for (i = 0; i < n; i++) scanf("%d %d", &x[i], &y[i]);
	for (i = 1; i < n; i++) {
		if (abs(x[i] + y[i]) % 2 != abs(x[i - 1] + y[i - 1]) % 2) {
			puts("-1");
			return 0;
		}
	}
	if (abs(x[0] + y[0]) % 2) {
		puts("31");
		for (i = 30; i >= 0; i--) printf("%d ", 1 << i);
		puts("");
	} else {
		puts("32");
		for (i = 30; i >= 0; i--) printf("%d ", 1 << i);
		puts("1");
	}
    for (i = 0; i < n; i++) {
		for (j = 30; j >= 0; j--) {
			if (abs(x[i]) > abs(y[i])) {
				if (x[i] > 0) {
					printf("R");
					x[i] -= 1 << j;
				} else {
					printf("L");
					x[i] += 1 << j;
				}
			} else {
				if (y[i] > 0) {
					printf("U");
					y[i] -= 1 << j;
				} else {
					printf("D");
					y[i] += 1 << j;
				}
			}
		}
		if (x[i] == 1) printf("R");
		else if (x[i] == -1) printf("L");
		else if (y[i] == 1) printf("U");
		else if (y[i] == -1) printf("D");
		puts("");
    }
    return 0;
}

Measured memory_bytes: 256
#include"iomanip"
#include"iostream"
#include"limits"
#include"cmath"
#include"vector"
#include"algorithm"
#include"list"
#include"queue"
#include"stack"
#include"set"
#include"unordered_set"
#include"map"
#include"unordered_map"
#include"string"
#include"cstring"
#include"assert.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define mp make_pair
#define pb push_back
#define mset(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n;
	cin>>n;
	ld eps=1e-7;
	if(n%2==0)
	{
		cout<<n<<' '<<n<<' '<<n/2<<'\n';
		return 0;
	}
	else
	{
		ld n1=n;
		ld a=1,b=1;
		for(a=1;a<=3501;++a)
		{
			for(b=1;b<=3501;++b)
			{
				ld kk=4/n1-1/a-1/b;
				ld kk1=1/kk-floor(1/kk+2*eps);
				if(kk>0&&kk1<eps&&-eps<kk1)
				{
					ld c=1/kk;
					c=round(c);
					ll c1=c;
					if(c1>=1&&c1<=3501)
					{
						cout<<a<<' '<<b<<' '<<c1<<'\n';
						return 0;
					}
				}
			}
		}
	}
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int num_R=0;
  for (int i=0; i<N; i++){
    char c;
    cin >> c;
    if (c=='R') A.at(i)=1;
    num_R += A.at(i);
  }
  int temp_R=0;
  for (int i=0; i<num_R; i++){
    temp_R += A.at(i);
  }
  cout << num_R-temp_R << endl;
  return 0;
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 1001001;
const ll MOD = 1000000007;
int main()
{
    ll INF = 10000000;
    ll n, h, w;
    cin >> n >> h >> w;
    cout << (n - h + 1) * (n - w + 1) << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define N 1000010
using namespace std;
int cnt=0;
void insertionSort(int *A,int n,int g){
  for(int i=g;i<n;i++){
    int v = A[i];
    int j = i - g;
    while(j>=0 && A[j]>v){
      A[j+g] = A[j];
      j = j - g;
      cnt++;
    }
    A[j+g] = v;
  }
}



void shellSort(int *A,int n){
  cnt = 0 ;
  int m = 1;//
  int G[25] = {1};
  for(int i=1;G[i-1]*3<=n;i++)G[i] = G[i-1]*3,m++;
  for(int i=0;i<m;i++) insertionSort(A,n,G[m-1-i]);
  
  cout<<m<<endl;
  for(int i=0;i<m;i++){
    if(i)printf(" ");
    printf("%d",G[m-1-i]);
  }
  cout<<endl;
}

int main(){
  int n,A[N];
  cin>>n;
  for(int i=0;i<n;i++)scanf("%d",&A[i]);
  
  shellSort(A,n);
  
  cout<<cnt<<endl;
  for(int i=0;i<n;i++) printf("%d\n",A[i]);
  
  return 0;
}

Measured memory_bytes: 7096
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	long long a[n],ans=0;
	cin>>a[0];
	for(int i=1;i<n;i++)
	{
		cin>>a[i];
		if(a[i]<a[i-1])
		{
			ans+=a[i-1]-a[i];
			a[i]=a[i-1];
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 5172
using System;
using System.Linq;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            int n;
            while ((n = int.Parse(Console.ReadLine())) != 0)
            {
                var s = new int[n].Select(_ => int.Parse(Console.ReadLine())).ToArray();
                Console.WriteLine((int)s.OrderBy(i => i).Skip(1).Take(n - 2).Average());
            }
        }
        
    }
}

Measured memory_bytes: 6476
#include "bits/stdc++.h"

typedef long long ll;
using namespace std;

int main() {
    int n;
    cin >> n;
    map<string, int> u;

    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        u[s]++;
    }

    ll sum = 0;
    for (const auto &n : u) {
        int s = n.second;
        sum += (ll) s * (s - 1) / 2;
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 11136
#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 - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll h, w, k;
    cin >> h >> w >> k;

    vvll a(h, vll(w));
    char c;
    vll zero(h);
    REP(i, h) {
        REP(j, w) {
            cin >> c;
            if (c == '#') {
                a[i][j] = 1;
                zero[i] = 1;
            }
        }
    }
    
    vvll used(h, vll(w));
    ll col = 1;
    REP(i, h) {
        REP(j, w) {
            if (a[i][j]) { // イチゴを発見
                ll left = j, right = j;
                // 左に行けるとこまで左へ
                while (left - 1 >= 0) {
                    if (a[i][left - 1] || used[i][left - 1]) break;
                    left--;
                }
                // 右に行けるとこまで右へ
                while (right + 1 < w) {
                    if (a[i][right + 1] || used[i][right + 1]) break;
                    right++;
                }
                ll up = i, down = i;
                while (up - 1 >= 0) {
                    if (zero[up - 1]) break;
                    up--;
                }
                while (down + 1 < h) {
                    if (zero[down + 1]) break;
                    down++;
                }
                for (int y = up; y <= down; y++) {
                    for (int x = left; x <= right; x++) {
                        used[y][x] = col;
                    }
                }
                col++;
            }
        }
    }
    REP(i, h) {
        REP(j, w) cout << used[i][j] << " ";
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 2176
<?php
[$a,$b,$c,$d] = ints();

printf("%d", max($a*$c, $a*$d, $b*$c, $b*$d));

function str(){return trim(fgets(STDIN));}
function ints($n = false){
  if($n===false){
    return array_map('intval',explode(' ',trim(fgets(STDIN))));
  }else{$ret = [];for($i = 0; $i < $n; $i++)foreach(array_map('intval',explode(' ',trim(fgets(STDIN)))) as $j => $v)$ret[$j][] = $v;return $ret;}
}
function int(){return intval(trim(fgets(STDIN)));}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}
function popcount($x){$c=0;while($x){$x&=$x-1;++$c;}return$c;}
function o(...$val){
    if(count($val)==1)$val=array_shift($val);
    echo debug_backtrace()[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0)echo "empty array\n";
        elseif(!is_array(current($val)))echo "array: ",implode(" ", addIndex($val)),"\n";
        else{
            echo "array:array\n";
            if(isCleanArray($val))foreach($val as $row)echo implode(" ", addIndex($row)),"\n";
            else foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row)),"\n";
        }
    }else echo $val."\n";
}
function addIndex($val){if(!isCleanArray($val)){$val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);}return $val;}
function isCleanArray($array){$clean=true;$i = 0;foreach($array as $k=>$v){if($k != $i++)$clean = false;}return $clean;}
// 座圧対象の配列 -> [圧縮された配列,復元用のMap,圧縮用のMap]
function atsu($array){$a = array_flip($array);$fuku=array_flip($a);sort($fuku);$atsu = array_flip($fuku);foreach($array as $i=>$val)$array[$i]=$atsu[$val];return [$array, $fuku, $atsu];}
function gcdAll($array){$gcd=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$gcd=gcd($gcd,$array[$i]);}return $gcd;}
function gcd($m, $n){if(!$n)return $m;return gcd($n, $m % $n);}
function lcmAll($array){$lcm=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$lcm=lcm($lcm,$array[$i]);}return $lcm;}
function lcm($a, $b) {return $a / gcd($a, $b) * $b;}

function dfs($current, $from = -1, $d = 0){
  global $G, $distance;
  $distance[$current] = $d;
  foreach($G[$current] as $to){
    if($from != $to){
      dfs($to, $current, $d + 1);
    }
  }
}

function loadTree($N = false){
  if($N === false)$N = $GLOBALS['N'];
  return loadGraph($N, $N-1);
}
function loadGraph($N = false, $M = false, $both = true){
  if($N === false)$N = $GLOBALS['N'];
  if($M === false)$M = $GLOBALS['M'];
  $G = array_fill(1, $N, []);
  for($i = 0; $i < $M; $i++){
    $values = ints();
    if(count($values) == 2){
      list($a, $b) = $values;
      if($both == 0){
        $G[$a][] = $b;
      }elseif($both == 1){
        $G[$a][] = $b;
        $G[$b][] = $a;
      }else{
        $G[$b][] = $a;
      }
    }else{
      list($a, $b, $d) = $values;
      if($both == 0){
        $G[$a][] = [$b, $d];
      }elseif($both == 1){
        $G[$a][] = [$b, $d];
        $G[$b][] = [$a, $d];
      }else{
        $G[$b][] = [$a, $d];
      }
    }
  }
  return $G;
}

Measured memory_bytes: 16308
from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
#import math

#N=int(input())
#X,Y=map(int,input().split())
#S=list(map(int,input().split()))
#S=[list(map(int,input().split())) for i in range(N)]

N=int(input())
print(N//2+N%2)


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh
ll solve(ll h , ll w){
	if(h % 3 == 0)
		return 0;
	ll ans = w;
	for(int i = 1 ; i <= h - 1 ; i++){
		ll  temp[]= { i * (w/2) , i * (w - w/2) , (h - i)*w};
		sort(temp , temp + 3);
		ans = min(ans , temp[2] - temp[0]);
	}
	return ans;
}
int main()
{
	ll h , w;
	cin >>  h >> w;
	cout << min(solve(h , w) , solve(w , h)) << endl;
	return 0;
} 




Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include <sstream>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include <iomanip>
#include <regex>
#include <initializer_list>
#define DBL_MIN 0.000000000000001
 
#define A_P(n,a,d) (n/2)*(2*a + (n-1)*d)
using namespace std;
 
//ちゃんとlong型でやってる？
 long euclidean_gcd(long a, long b) {
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}

int main(void){
    int N;
    cin >> N;

    int neko;
    cin >> neko;
    for(int i =0; i < N -1; i++){
        int tmp;
        cin >> tmp;
        if(tmp % neko){
            neko = euclidean_gcd(neko,tmp);
        }
    }

    cout << neko << endl;
    return 0;
}

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

using namespace std;

int main(){
    int n;
    cin>>n;
    int count=0;
    for(int i=1;i<=n;i++){
        if (i<10){
            ++count;
        }
    
        else{
            int b=i;       
            int keta=0;
            while(b !=0){
                ++keta;
                b/=10;
            }
            
        if((keta)%2 !=0)++count;

        
        }
    }
    cout<<count<<endl;
    return 0;
}
 





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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int n;
	cin >> n;
	bool f[n][10];
	FOR(i,0,n){
		FOR(j,0,10){
			cin >> f[i][j];
		}
	}
	int p[n][11];
	FOR(i,0,n){
		FOR(j,0,11){
			cin >> p[i][j];
		}
	}
	ll ans = -LLINF;
	for(int i = 1; i < (1 << 10); i++){
		int count[n];
		FOR(j,0,n)count[j] = 0;
		FOR(j,0,10){
			bool joisinoShop = ((i >> j) & 1);
			FOR(k,0,n){
				if(joisinoShop && f[k][j])count[k]++;
			}
		}
		ll profit = 0;
		FOR(j,0,n){
			profit += p[j][count[j]];
		}
		//cout << bitset<10>(i) << " " << profit << "\n";
		ans = max(ans, profit);
	}
	ANS(ans);
	return 0;
}


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

int n;
int a[100000],b[100000],c[100000];
long long int v[3][100000];

long long int dp(int y,int i,int x)
{
	if(i>=n)return 0;
	if(v[y][i] != -1)return v[y][i];
	if(x==1)
	{
		v[y][i] = a[i] + max(dp(1,i+1,2),dp(2,i+1,3));
	}
	if(x==2)
	{
		v[y][i] = b[i] + max(dp(0,i+1,1),dp(2,i+1,3));
	}
	if(x==3) 
	{
		v[y][i] = c[i] + max(dp(0,i+1,1),dp(1,i+1,2));
	}
	return v[y][i];

}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i]>>b[i]>>c[i];
	for(int j=0;j<3;j++)for(int i=0;i<100000;i++)v[j][i] = -1;
	long long int ans = dp(0,0,1);
	ans = max(ans,dp(1,0,2));
	ans = max(ans,dp(2,0,3));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 8448
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int H, A;
    cin >> H >> A;
    cout << (1 + --H / A) << endl;
    return 0;
};

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)






int main() {
	int s,k;
	cin >> s>>k;
	if (k%s==0) {
		s = -s;
	}
	cout << k-s << endl;
}

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

using namespace std;

int main (){
    int n, sum = 0;
    cin >> n;
    for (int i = 0; i < n; i++){
        int l, r;
        cin >> l >> r;
        sum += r - l + 1;
    }
    cout << sum << endl;
    return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define MAX_V 100005



int main(void){
	ll n;
	cin>>n;
	vector<int> ans;
	int plus = -1;
	while(true){
		if(n == 0) break;
		if(n%2 != 0){
			n = n + plus;
			ans.push_back(1);
		}else{
			ans.push_back(0);
		}
		plus *= -1;
		n /= 2;
	}
	REP(i,ans.size()){
		cout<<ans[i];
	}
	if(ans.size() == 0){
		cout<<0;
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Sun Jan 27 18:10:19 2019
//
package main

import (
	"fmt"
	"sort"
)

type pair struct {
	x, v int
}

func max(slice ...int) int {
	sort.Ints(slice)
	return slice[len(slice)-1]
}

func main() {
	var N, C int
	fmt.Scan(&N, &C)

	ps := make([]pair, N)
	for i := range ps {
		fmt.Scan(&ps[i].x, &ps[i].v)
	}

	rV := make([]int, N)
	for i := range ps {
		if i == 0 {
			rV[i] = ps[i].v
		} else {
			rV[i] = rV[i-1] + ps[i].v
		}
	}

	for i := range rV {
		rV[i] -= ps[i].x
		if i > 0 {
			rV[i] = max(rV[i], rV[i-1])
		}
	}

	lV := make([]int, N)
	for i := range ps {
		if i == 0 {
			lV[i] = ps[len(ps)-1-i].v
		} else {
			lV[i] = lV[i-1] + ps[len(ps)-1-i].v
		}
	}

	for i := range lV {
		lV[i] -= C - ps[len(ps)-1-i].x
		if i > 0 {
			lV[i] = max(lV[i], lV[i-1])
		}
	}

	ans := max(0, rV[len(rV)-1], lV[len(lV)-1])
	for i := range rV {
		if i < len(rV)-1 {
			ans = max(ans, rV[i]-ps[i].x+lV[len(lV)-2-i], lV[i]-(C-ps[len(ps)-i-1].x)+rV[len(rV)-2-i])
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 7168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

void solve(istream& cin, ostream& cout) {
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  ll ans = 0;
  int now = a[0];
  FOR(i, 1, n - 1) {
    if (now >= a[i]) ans += now - a[i];
    else {
      now = a[i];
    }
  }
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


Measured memory_bytes: 3928
/*
      author  : nishi5451
      created : 15.08.2020 00:47:50
*/

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


int main(){
    int r,d,x;
    cin >> r >> d >> x;
    rep(i,10){
        x = r*x-d;
        cout << x << endl;
    }
    return 0;
}

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

typedef pair<int,int>P;
const int MAX_N=1e5+1;
P data[MAX_N];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>data[i].first;
		data[i].second=i;
	}
	sort(data,data+n);
	int ans=0;
	for(int i=0;i<n;i++){
		ans+=(data[i].second%2)^(i%2);
	}
	cout<<ans/2<<endl;
}


Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int n,a;cin>>n>>a;
    vin x(n);
    rep(i,n){
        cin>>x[i];
        x[i]-=a;
    }
    vvll dp(55,vll(5050));
    rep(i,110)dp[0][i]=0;
    dp[0][2500]=1;
    rep(i,n)rep(j,5050){
        if(j-5000<=x[i]&&x[i]<=j)dp[i+1][j]=dp[i][j]+dp[i][j-x[i]];
        else dp[i+1][j]=dp[i][j];
    }
    cout<<dp[n][2500]-1<<endl;
}

Measured memory_bytes: 2432
import sys
sys.setrecursionlimit(100000)
input=sys.stdin.readline

n,m=map(int,input().split())

lrd=[[] for _ in range(n)]

for _ in range(m):
    l,r,d=map(int,input().split())
    lrd[l-1].append((r-1,-d))
    lrd[r-1].append((l-1,+d))

def BFD(x):
    global checked,answer,lrd
    checked[x]=1
    #print("x>>>",x,lrd[x])
    for llrrdd in lrd[x]:
        #print(llrrdd,x)
        item=llrrdd[0]
        if answer[item]=="first":
            answer[item]=answer[x]-llrrdd[1]
        else:
            if answer[item]!=answer[x]-llrrdd[1]:
                print("No")
                exit()
        if checked[item]==0:
            BFD(item)

checked=[0]*n
answer = ["first"]*n

for i in range(n):
    if checked[i]==0:
        answer[i]=1
        BFD(i)

print("Yes")


Measured memory_bytes: 129696
#include <stdio.h>

int main(){
	char S[102][102];
	int C[102];
	int N,L,X;
	scanf("%d %d\n",&N,&L);
	
	for(int i=0;i<N;i++)
		scanf("%s\n",&S[i]);
	
	for(int i=0;i<N;i++){
		X=-1;
		for(int j=0;j<N;j++){
			if(C[j]!=0)
				continue;
			if(X==-1){
				X=j;
				continue;
			}
			for(int k=0;k<L;k++){
				if(S[X][k]<S[j][k]){
					break;
				}
				if(S[X][k]>S[j][k]){
					X=j;
					break;
				}
			}
		}
		C[X]=1;
		printf("%s",S[X]);
	}
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>

#define POS(i,j) ((i)*n+(j)%n)

void run(void){
  int n;
  scanf("%d",&n);
  char *board=(char *)calloc(n*n+1,sizeof(char));
  int i,j,k;
  for(i=0;i<n;i++) scanf("%s",board+POS(i,0));
  int ans=0;
  for(k=0;k<n;k++){
    int flag=1;
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	if(board[POS(i,j+k)]!=board[POS(j,i+k)]) flag=0;
      }
    }
    if(flag) ans+=n;
  }
  printf("%d\n",ans);
  return;
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    const int num3=2200;
    vector<ll> a2(num3+1);
    vector<ll> a3(num3+1);

    int i,j;
    for(i=1; i<=num3; i++) {
        a2[i]=(ll)i*i;
        a3[i]=a2[i]*i;
    }

    int n;
    scanf("%d", &n);

    map<ll,int> cnt;
    for(i=0; i<n; i++) {
        ll s;
        scanf("%lld", &s);
        for(j=2; j<=num3; j++) {
            if(s<a3[j]) break;
            while(s%a3[j]==0) {
                s/=a3[j];
            }
        }
        cnt[s]++;
    }

    int ans=0;
    if(cnt.find(1)!=cnt.end()) {
        ans++;
        cnt.erase(1);
    }

    queue<ll> que;
    {
        auto it=cnt.begin();
        for(; it!=cnt.end(); ++it) {
            que.push(it->first);
        }
    }

    while(!que.empty()) {
        ll tt=que.front();
        que.pop();

        auto it=cnt.find(tt);
        if(it==cnt.end()) continue;

        ll curr=it->first;
        ll sub=1;
        for(j=2; j<=num3; j++) {
            if(curr<a2[j]) break;
            while(curr%a2[j]==0) {
                curr/=a2[j];
                sub*=j;
            }
            if(sub>num3 || curr<sub) break;
        }
        if(sub>num3 || curr<sub) continue;
        double chk=(double)curr*curr*sub;
        if(chk>1e12) continue;
        ll tmp=curr*curr*sub;
        auto it2=cnt.find(tmp);
        if(it2!=cnt.end()) {
            ans += MAX(it->second, it2->second);
            ll tmp0=it->first;
            ll tmp1=it2->first;
            cnt.erase(tmp0);
            cnt.erase(tmp1);
        }
    }

    auto it=cnt.begin();
    for(; it!=cnt.end(); ++it) {
        ans+=it->second;
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 9344
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c=0;
  cin>>a>>b;
  int d,f;
  for(int i=a;i<=b;i++){
    d=i/10000;
    f=i%10;
   
    if(d==f){
      d=i/1000;
      d=d%10;
      f=i%100;
      f=f/10;
      if(d==f) c++;
    }
  }
  cout<<c<<"\n";
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#define _GLIBCXX_DEBUG
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <iomanip>
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cmath>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1001001000;
const int MOD = 1000000007;

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

using Graph = vector<vector<int>>;
//再帰とかグラフを使うときは予めNの最大値のグローバル配列を取っておく


//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}
long long nCr(long long n, long long r) {
    long long A = 1, B = 1;
    //Aが分子Bが1/r!
    for (long long i = n - r + 1; i <= n; i++) {
        A = A * i % MOD;
    }
    for (long long i = 1; i <= r; i++) {
        B = B * i % MOD;
    }
    B = mod_pow(B, MOD - 2);
    B %= MOD;
    //Bは割るのではなく掛ける
    return (A * B) % MOD;
}

bool E[2005][2005];
vector<bool> seen;
typedef pair<int,int> P;
//typedef pair<string, int> P;
int D[2005];
//頂点状態を表すcolor[]において、0は未訪問、1は訪問中、2は完了を表す。
int color[101];
int find_time = 0;

int main() {
    int N; cin >> N;
    vector<P> task(N);
    //firstに締め切り、secondに所要時間
    for (int i = 0; i < N; i++) {
        cin >> task.at(i).first >> task.at(i).second;
        swap(task.at(i).first, task.at(i).second);
    }
    sort(task.begin(), task.end());
    long long time = 0;

    for (int i = 0; i < N; i++) {
        time += task.at(i).second;
        if (time > task.at(i).first) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 1792
N = int(input())
S = input()


S1 = []
S2 = []
score = 0
ans = 0
scorelist = []
alphabet = [chr(i) for i in range(97, 97+26)]
for i in range(N-1):
    S1 = S[0:i+1]
    S2 = S[i+1:N]
    score = 0
    for n in range(26):
        if alphabet[n] in S1:
            if alphabet[n] in S2:
                score += 1
        scorelist.append(score)
ans = max(scorelist)
print(ans)


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

using namespace std;

void status(int N)
{
	int a=0,b=0,c=0,d=0;
	for(int i=0;i<N;i++)
	{
		string s;
		cin>>s;
		if(s.compare("AC")==0)
			a++;
		if(s.compare("WA")==0)
			b++;
		if(s.compare("TLE")==0)
			c++;
		if(s.compare("RE")==0)
			d++;
	}
	cout<<"AC x "<<a<<"\n";
	cout<<"WA x "<<b<<"\n";
	cout<<"TLE x "<<c<<"\n";
	cout<<"RE x "<<d<<"\n";
}
int main()
{
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    freopen("err.txt","w",stderr);
  #endif
  int test;
  cin>>test;
  status(test);
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
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 int64_t INF = 1LL << 60;

int main() {
 int h,w;
 cin>>h>>w;
 char a[10][10];
 int count=0;
 for(int i=0;i<h;i++){
   for(int j=0;j<w;j++){
     cin>>a[i][j];
     if(a[i][j]=='#'){count++;}
   }
 }
 if(count==h+w-1){cout<<"Possible"<<endl;}
 else{cout<<"Impossible"<<endl;}

return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define INF 2147483647
using namespace std;
int tree[(1<<18)];
int n,q;
void add(int i,int x) {
  i+=(n-1);
  tree[i] += x;
  while(i!=0){
    i=(i-1)/2;
    tree[i] += x;
  }
}
int getsum(int a ,int b,int ima,int L,int R){
  if(R<=a || b<=L) return 0;
  if(a<=L && R<=b) return tree[ima];
  int M = (R+L)/2;
  return getsum(a,b,ima*2+1,L,M)+getsum(a,b,ima*2+2,M,R);
}

int main(){
  cin >> n >>q;
  int N=1;
  while(N<n)N*=2;
  n=N;
  while(q--){
    int com,x,y;
    cin >>com >> x >> y;
    if(com == 0) add(x-1,y);
    if(com == 1) cout << getsum(x-1,y,0,0,n) <<endl;
  }
  return 0;
}

Measured memory_bytes: 1960
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n)
    cin >> a.at(i);
  sort(all(a));
  int c=2000000000;
  rep(i,n-k+1){
    c=min(c,a.at(k+i-1)-a.at(i));
  }
  cout << c << endl;
}

Measured memory_bytes: 640
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int L = int.Parse(input[0]); ;
        int R = int.Parse(input[1]); ;
        int d = int.Parse(input[2]); ;
        int a = 0;

        for(; L <= R; L++){
            if(L%d == 0){
                a += 1;
            }
        }
        Console.Write(a);
    }
}

Measured memory_bytes: 27476
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int r;cin >> r;
    cout << r*r << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#define ll long long
using namespace std;
int n;
int a[1000010],nx[1000010],last[1000010],pos[1000010];
ll k;
int main(){
	scanf("%d%lld",&n,&k);
	for(register int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(register int i=1;i<=n;i++){
		nx[last[a[i]]]=i;
		last[a[i]]=i;
	}
	for(register int i=1;i<=n;i++){
		if(!nx[last[a[i]]])nx[last[a[i]]]=i;
		last[a[i]]=i;
	}
	int now=0,cnt=1;
	while(now!=n){
		now++;
		if(!pos[cnt])pos[cnt]=now;
		if(nx[now]<=now)cnt++;
		now=nx[now];
	}
	k=k%(1ll*cnt);
	now=pos[(int)k];
	while(now&&now<=n){
		while(nx[now]>now)now=nx[now]+1;
		if(now>n)break;
		cout<<a[now]<<" ";
		now++;
	}
	return 0;
}

Measured memory_bytes: 14592
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

int main(){
  int x,n; cin >> x >> n;
  vector<int> p(n);
  for(int i = 0; i < n; i++){
    cin >> p[i];
  }
  if(n == 0){
    cout << x << endl;
    return 0;
  }
  int ans = -1, mn = 1<<30;
  for(int i = 0; i <= 100; i++){
    bool flg = false;
    for(int pp: p){
      if(i == pp){
        flg = true;
        break;
      }
    }
    if(flg) continue;
    int d = abs(x-i);
    if(d < mn){
      mn = d;
      ans = i;
    }
  }
  int a = abs(x - 101);
  if(a < mn) ans = 101;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
#include<cstdio>
#include<queue>
#include<stack>
#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;
int main() {
	deque <int> deq;
	int n, i;
	cin>>n;
	int t;
	for(i = 1; i<= n; i++) {
		if (i % 2 == 0) {
			cin>>t;
			deq.push_front(t);
		} else {
			cin>>t;
			deq.push_back(t);
		}
	}
	while(!deq.empty()) {
		if(i%2==1) {
			int u;
			u = deq.front();
			deq.pop_front();
			cout<<u<<" ";
		} else {
			int u;
			u = deq.back();
			deq.pop_back();
			cout<<u<<" ";
		}
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 2944
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n;
const int maxN = 305;
int clr[2 * maxN][2 * maxN];
vector<pair<int,int>> shifts;
void dfs(int x, int y) {
    for (auto& it : shifts) {
        int nx = x + it.first;
        int ny = y + it.second;
        if (nx < 0 || nx >= 2 * n || ny < 0 || ny >= 2 * n) continue;
        if (clr[nx][ny] != -1) {
            assert(clr[nx][ny] == clr[x][y] ^ 1);
        }
        else {
            clr[nx][ny] = clr[x][y] ^ 1;
            dfs(nx, ny);
        }
    }
}
int tt[2 * maxN][2 * maxN][2];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    int d1, d2;
    cin >> n >> d1 >> d2;
    vector<int> g = {d1, d2};

    for (int ptr = 0; ptr < 2; ptr++) {
        shifts.clear();
        int C = g[ptr];
        for (int a = -2 * n; a <= 2 * n; a++) {
            for (int b = -2 * n; b <= 2 * n; b++) {
                if (a * a + b * b == C) shifts.emplace_back(a, b);
            }
        }
        memset(clr, -1, sizeof clr);
        for (int i = 0; i < 2 * n; i++) {
            for (int j = 0; j < 2 * n; j++) {
                if (clr[i][j] == -1) {
                    clr[i][j] = 0;
                    dfs(i, j);
                }
            }
        }
        for (int i = 0; i < 2 * n; i++) {
            for (int j = 0; j < 2 * n; j++) {
                tt[i][j][ptr] = clr[i][j];
            }
        }
    }
    vector<pair<int,int>> x[2][2];
    for (int i = 0; i < 2 * n; i++) {
        for (int j = 0; j < 2 * n; j++) {
            x[tt[i][j][0]][tt[i][j][1]].emplace_back(make_pair(i, j));
        }
    }
    for (int r = 0; r < 2; r++) {
        for (int t = 0; t < 2; t++) {
            if (x[r][t].size() >= n * n) {
                x[r][t].resize(n * n);
                for (auto& it : x[r][t]) {
                    cout << it.first << " " << it.second << '\n';
                }
                exit(0);
            }
        }
    }
    assert(false);
    return 0;
}

Measured memory_bytes: 27940