akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1LL<<62)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

const int MAX_N = 1<<17;

int n;
ll dat[2 * MAX_N - 1];

void init(int n_){
  n = 1;
  while(n < n_) n *= 2;
  for (int i=0;i< 2 * n -1; i++) dat[i] = -INF;
}

void update(int k, ll a){
  k += n - 1;
  dat[k] = a;
  while(k > 0){
    k = (k - 1) / 2;
    dat[k] = max(dat[k*2+1], dat[k*2+2]);
  }
}

ll query(int a, int b, int k, int l, int r){
  if (r <= a || b <= l) return -INF;
  if (a <=  l && r <= b) return dat[k];
  else{
    ll vl = query(a, b, k*2+1, l, (l + r) / 2);
    ll vr = query(a, b, k*2+2, (l + r) / 2, r);
    return max(vl, vr);
  }
}

int N;
ll C;
ll x[100005];
ll v[100005];

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

  rep(i, N){
    cin >> x[i] >> v[i];
  }

  ll res = 0;
  init(N);
  ll sv = 0;
  
  rep(i, N){
    sv += v[i];
    update(i, sv - x[i]);
  }
  sv = 0;
  rep(i, N){
    sv += v[N - i - 1];
    ll d = C - x[N-i-1];
    res = max(res, max(query(0, N - i - 1, 0, 0, n)- d, 0LL) + sv - d);
    //    cout << i << " " << max(query(0, N - i - 1, 0, 0, n) - d, 0LL) << " " << sv << " " <<  d << endl;
  }

  sv = 0;  
  rep(i, N){
    sv += v[N-i-1];
    update(i, sv - (C - x[N-i-1]));
  }
  sv = 0;
  rep(i, N){
    sv += v[i];
    ll d = x[i];
    res = max(res, max(query(0, N - i - 1, 0, 0, n) - d, 0LL) + sv - d);
    //    cout << i << " " << max(query(0, N - i - 1, 0, 0, n) - d, 0LL) << " " << sv << " " <<  d << endl;
  }

  cout << res << endl;
  return 0;
}



Measured memory_bytes: 3840
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll MOD=1e9+7;
const int INF=1<<30;

int main(){
  int A,B;
  string S;
  cin >> A >> B >> S;
  S[B-1]+=32;
  cout << S << endl;
  
}

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

int main(){
  int X,Y;
  char a[4];
  for(int i=0; i<4; i++) cin>>a[i];
  if(a[0]==a[1] && a[1]==a[2]) cout<<"Yes"<<endl;
  else if(a[1]==a[2] && a[2]==a[3]) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

int main(){
  int N;
  cin>>N;
  int mi=N+100;
  int sum=0;
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    if(a<mi){
      sum++;
      mi=a;
    }
  }
  cout<<sum<<endl;
  
  
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>

using namespace std;

int main(){

long long A,B;
cin >> A >>B;
if((A+B)%2==0){
    cout<<(A+B)/2<<endl;
}
else{
    cout<<"IMPOSSIBLE"<<endl;
}
    

 return 0;
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return ~n & 1; }
template<typename T> int len(const T &v) { return v.size(); }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main() {
  int n = in();
  vector<int> a(n);
  cin >> a;
  int m = in();
  vector<int> b(m);
  cin >> b;
  cout << (a < b) << endl;
}



Measured memory_bytes: 3104
N = input()
N0 = list(N)

A = 0

for i in N0:   #N0の中身はlistで一桁ずつ並んでいる，iはi番目のN0の要素を示す
    A = A + int(i)

B = int(N) % A    #BはNをAで割ったときの余り

if B == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> pll;
const ll inf = 1LL << 60;

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    ll A; cin>>A;
    double B; cin >>B;
    ll big =  (A / 100);
    ll small = A % 100;
    ll ansbig = big * (ll)(B * 100.0001);
    double anssmall = small * B;
    cout << ansbig + (ll)anssmall << endl;

}

Measured memory_bytes: 3760
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.PriorityQueue;
 
 
 
public class Main {
  public static void main(String[] args) {
    InputReader sc = new InputReader(System.in);
 
    int[] ar = new int[3];
    ar[0] = sc.nextInt();
    ar[1] = sc.nextInt();
    ar[2] = sc.nextInt();
    Arrays.sort(ar);
    System.out.println(ar[2]-ar[0]);
 
  }
 
 //ここからテンプレ
  static class InputReader {
      private InputStream stream;
      private byte[] buf = new byte[1024];
      private int curChar;
      private int numChars;
      private SpaceCharFilter filter;
 
      public InputReader(InputStream stream) {
          this.stream = stream;
      }
 
      public int next() {
          if (numChars == -1)
              throw new InputMismatchException();
          if (curChar >= numChars) {
              curChar = 0;
              try {
                  numChars = stream.read(buf);
              } catch (IOException e) {
                  throw new InputMismatchException();
              }
              if (numChars <= 0)
                  return -1;
          }
          return buf[curChar++];
      }
 
      public String nextStr() {
        int c = next();
        while(isSpaceChar(c)){c = next();}
        StringBuffer str = new StringBuffer();
        do{
          str.append((char)c);
          c = next();
        }while(!isSpaceChar(c));
        return str.toString();
      }
 
      public char nextChar() {
        int c = next();
        while(isSpaceChar(c)){c = next();}
        char ret;
        do{
          ret = (char)c;
          c = next();
        }while(!isSpaceChar(c));
        return ret;
      }
 
      public int nextInt() {
          int c = next();
          while (isSpaceChar(c))
              c = next();
          int sgn = 1;
          if (c == '-') {
              sgn = -1;
              c = next();
          }
          int res = 0;
          do {
              if (c < '0' || c > '9')
                  throw new InputMismatchException();
              res *= 10;
              res += c - '0';
              c = next();
          } while (!isSpaceChar(c));
          return res * sgn;
      }
 
      public boolean isSpaceChar(int c) {
          if (filter != null)
              return filter.isSpaceChar(c);
          return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
      }
 
      public interface SpaceCharFilter {
          public boolean isSpaceChar(int ch);
      }
  }
}

Measured memory_bytes: 22356
n,m = map(int,input().split())
lScope = []
rScope = []
ans = 0
for i in range(m):
    l,r = map(int,input().split())
    lScope.append(l)
    rScope.append(r)
# k in keyScope[i] (i= 0~m) を確かめたい
if min(rScope) >= max(lScope):
    print(min(rScope) - max(lScope) + 1)
else:
    print(0)

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  LL n,a,b,c,d;
  cin >> n >> a >> b >> c >> d;
  n--;
  a=a-b;
  for(LL i=0;i<=n;i++){
    // cout << i*c-(n-i)*d SP i*d-(n-i)*c << endl;
    if(i*c-(n-i)*d<=a&&a<=i*d-(n-i)*c){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <set>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cstdio>
#include <cstring>

using namespace std;

constexpr long long mod = 1000000007;
constexpr double eps = 0.0000000001;

typedef long long ll;
typedef long long unsigned ull;

int main() {
    int n;
    cin >> n;
    vector<pair<string, int>> s(n);
    for (auto &e:s) {
        cin >> e.first;
        e.second = 1;
    }
    sort(s.begin(), s.end());
    int m = 0;
    for (auto itr = s.begin(); itr != s.end() - 1; itr++) if (itr->first == (itr + 1)->first) (itr + 1)->second += itr->second;
    for (auto &e:s) m = max(m, e.second);
    for (auto &e:s) if (e.second == m) cout << e.first << endl;
}

Measured memory_bytes: 16000
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n, z, w;
    cin >> n >> z >> w;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    if(n == 1){
        cout << abs(w-v[0]) << "\n";
    }else {
        cout << max(abs(w-v[n-1]), abs(v[n-1]-v[n-2]));
    }
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
import numpy as np

A, B, M = map(int, input().split())
a = np.array(list(map(int, input().split())))
b = np.array(list(map(int, input().split())))

ans = a.min() + b.min()

for i in range(M):
    x, y, c = map(int, input().split())
    ans = min(ans, a[x-1] + b[y-1] - c)

print(ans)

Measured memory_bytes: 24284
var toInt = x=>parseInt(x,10);
var toIntArr = arr=>arr.map(x=>toInt(x));
var abs = x=>x>0?x:-x;
function min(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]<val)val = rest[i];return val}
function max(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]>val)val = rest[i];return val}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
 
function Main(input){
	var input = input.split('\n');
	var temp = toIntArr(input[0].split(' '));
	var n = temp[0];
	var x = temp[1];
	var xs = toIntArr(input[1].split(' '));

	var ys = xs.map(e=>abs(e-x));

	function gcd(a,b){
		if(b===0) return a;
		return gcd(b,a%b);
	}

	var ans = ys[0];
	for(var i = 0; i < n-1; i++){
		ans = gcd(ans,ys[i+1]);
	}
	console.log(ans);
}

Measured memory_bytes: 30248
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <string.h>

using namespace std;
const int maxn = 2e5+1 ;
vector<int> arr[maxn] ;
int len[maxn] ;
int n ;
int bfs(int x){
    memset(len,0,sizeof(len)) ;
    len[x] = 1 ;
    queue<int> q ;
    q.push(x) ;
    int z = 1 ;
    int flog = 1 ;
    while(!q.empty()) {
        int y = q.front() ;
        q.pop() ;
        for (int i = 0 ; i < arr[y].size() ;  i++ ) {
            z = arr[y][i] ;
            if (!len[z]){
                len[z] = len[y]+1 ;
                flog++ ;
                q.push(z) ;
            }
            if (flog == n) return z ;
        }
        if (flog == n) return z ;
    }
    if (flog == n) return z ;
}

int main()
{
    cin >> n ;
    for (int i = 1 ; i < n ; i++) {
        int a , b ;
        cin >> a >> b ;
        arr[a].push_back(b) ;
        arr[b].push_back(a) ;
    }
    int temp = bfs(1) ;
    int ans = bfs(temp) ;
    if (len[ans]%3==2) cout << "Second" << endl ;
    else cout << "First" << endl ;
    return 0;
}


Measured memory_bytes: 13556
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<complex>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
#define PI 3.1415926535897932384626433832795028
typedef long long Int;
typedef pair<Int, Int> P;
typedef long double Real;
typedef complex<Real> CP;

int main(){
    int n, k;
    int snuke = 0;
    vector<int> v(100, 1);
    cin >> n >> k ;

    while (k--) {
        // cout << 'k' << k << endl;
        int d;
        cin >> d;
        while (d--) {
            // cout << 'd' << d << endl;
            int A;
            cin >> A;
            v[--A] = 0; 
        }
    }
    for (int i = 0; i < n; i++) {
        snuke += v[i];
    }
    cout << snuke << endl;

    return 0;
}

Measured memory_bytes: 3168
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void){
  int n;
  cin>>n;
  
  vector<int>data(n);
  for(int i=0;i<n;i++){
   cin>>data.at(i); 
  }
  
  sort(data.begin(),data.end());
  
  int ans=0;
  
  for(int i=0;i<n;i++){
    ans+=data.at(i); 
  }
  
  if(ans%10==0){
   for(int i=0;i<n;i++){
    if(data.at(i)%10!=0){
      ans-=data.at(i);
      break;
    }
   }
  }
  
  if(ans%10!=0)cout<<ans<<endl;
  else cout<<'0'<<endl;
  
  return 0;
}

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

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

int main(){
  int n,k;
  cin>>n>>k;
  int a[n];
  rep(i,n)
    cin>>a[i];
  int hoge=k,count=1;;
  for(int i=0;;i++){ 
    if(hoge<n)
    count++;
    else  if(hoge>=n){
      cout<<count<<endl;
      return 0;
    }
    hoge+=k-1;
  }



  return 0;
}


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

using namespace std;

int main(){
  int N;
  cin >> N;
  N %= 10;
  if(N == 0 || N == 1 || N == 6 || N ==8)
    cout << "pon";
  else if(N == 3)
    cout << "bon";
  else
    cout << "hon";
    
  return 0;
}

Measured memory_bytes: 3600
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<string>
using namespace std;
#define INF 0x3f3f3f3f
#define eps 1e-8
#define maxn 100005
#define mod 1000000009

char s[505][15];
vector<int>g[30];
int deg[30];
bool v[30];
void topo()
{
    queue<int>q;
    for(int i=0;i<26;i++)   if(deg[i]==0)   q.push(i);
    int all=0;
    while(!q.empty())
    {
        int now=q.front();
        if(v[now]==1)
        {
            q.pop();
            continue;
        }
        v[now]=1;
        all++;
        q.pop();
        for(int i=0;i<g[now].size();i++)
        {
            int temp=g[now][i];
            deg[temp]--;
            if(deg[temp]==0)    q.push(temp);
        }
    }
    if(all==26) printf("yes\n");
    else printf("no\n");
}
int main()
{
    while(1)
    {
        int n;
        scanf("%d",&n);
        if(n==0)    break;
        bool flag=0;
        for(int i=0;i<26;i++)   g[i].clear();
        for(int i=0;i<26;i++)
        {
            deg[i]=0;
            v[i]=0;
        }
        for(int i=0;i<n;i++)
        {
            scanf("%s",s[i]);
        }
        for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<n;j++)
            {
                int leni=strlen(s[i]),lenj=strlen(s[j]);
                bool sign=0;
                for(int k=0;k<min(leni,lenj);k++)
                {
                    if(s[i][k]!=s[j][k])
                    {
                        g[s[i][k]-'a'].push_back(s[j][k]-'a');
                        deg[s[j][k]-'a']++;
                        sign=1;
                        break;
                    }
                }
                if(sign==0)
                {
                    if(leni>lenj)
                    {
                        flag=1;
                        break;
                    }
                }
            }
            if(flag==1) break;
        }
        if(flag==1) printf("no\n");
        else topo();

    }
}

Measured memory_bytes: 6496
#include <bits/stdc++.h>
using namespace std;
int A[3][3];
bool B[3][3];
int main() {
    int N,a, intento;
    for (int i = 0; i < 3; i++){
        for (int j = 0; j < 3; j++){
            cin >> a;
            A[i][j] = a;
        }
    }
    cin >> N;
    for (int k = 0; k < N; k++){
        cin >> intento;
        for (int m = 0; m < 3; m++){
            for (int n = 0; n < 3; n++){
                if (A[m][n] == intento) B[m][n] = true;
            }
        }
    }
    if (B[0][0] && B[0][1] && B[0][2]) cout << "Yes ";
    else if (B[1][0] && B[1][1] && B[1][2]) cout << "Yes ";
    else if (B[2][0] && B[2][1] && B[2][2]) cout << "Yes ";
    
    else if (B[0][0] && B[1][0] && B[2][0]) cout << "Yes ";
    else if (B[0][1] && B[1][1] && B[2][1]) cout << "Yes ";
    else if (B[0][2] && B[1][2] && B[2][2]) cout << "Yes ";
    
    else if (B[0][0] && B[1][1] && B[2][2]) cout << "Yes ";
    else if (B[0][2] && B[1][1] && B[2][0]) cout << "Yes ";
    
    else cout << "No ";
    return 0;
}


Measured memory_bytes: 256
f=lambda: map(int,input().split())
    
V,E,P=f()
G=[]
for _ in range(E):
    s,t,d=f()
    G.append((s,t,-(d-P)))

INF=float('inf')
res=[INF]*(V+1)
res[1]=0

def Bellman_Ford():
    for s,t,d in G:
        res[t]=min(res[t],res[s]+d)
        
negative_flg=False
r=INF
for _ in range(V):
    tmp=res[:]
    Bellman_Ford()
    r=min(res[-1],r)
    if tmp==res:
        break
else:
    r0=res[-1]
    for _ in range(V):
        tmp=res[:]
        for s,t,d in G:
            if res[t]>res[s]+d:
                res[t]=-INF
    if r0!=res[-1]:
        negative_flg=True
if negative_flg:
    print(-1)
else:
    print(max(-r,0))

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

int main(){
    int N,Q;
    int i, j;
    int count = 0;
    cin>>N>>Q;
    int ruikei=0;
    char S[N+1];
    int num[N+1];
    for(i=0;i<N+1;i++){
        S[i]='\0';
        num[i]=0;
    }
    cin>>S;

    int l, r;
    for(i=0;i<N+1;i++){
        if(S[i]=='A'){
            num[i]=ruikei;
            i++;
            if(S[i]=='C'){
                ruikei++;
                num[i]=ruikei;
            }
            else{
                i--;
            }
        }
        else{
            num[i]=ruikei;
        }
    }
    for(i=0;i<Q;i++){
        cin>>l>>r;
        cout<<num[r-1]-num[l-1]<<endl;
    }


    
    return 0;
}

Measured memory_bytes: 1280
#include "bits/stdc++.h"
using namespace std;

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define isin(a, b, c) (b <= a && a <= c)
#define println cout << "\n";
#define sz(v) (int)v.size()


/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;
typedef map<int, int> mi;
typedef set<int> si;


/* constant */
const int inf = 1LL << 62;
const int mod = 1e9 + 7;
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 string alphabet = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T, class U, class V> void printx(tuple<T, U, V> t){cout << "{" << get<0>(t) << "," << get<1>(t) <<"," << get<2>(t) << "}" << endl;}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}
template<class T> void printans(vec<T> v){rep(i,0,sz(v)){cout << v[i] << (i == sz(v) - 1 ? "" : " ");}cout << endl;}


/* general_method */
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>T cut(T &a, int l, int r){return T(a.begin()+l, a.begin()+r);}

/* main */

int n;
vi arr;
void in(){
    cin >> n;
    rep(i,0,n) arr.push_back(input());
}

void solve(){

    int l = 0;
    int ans = 0;
    while(l < n){
        int state = -1; //up..1 down..0 neither..-1
        int r = l + 1;

        while(r < n){
            if(state == 0 && arr[r - 1] < arr[r]) break;
            if(state == 1 && arr[r - 1] > arr[r]) break;

            if(state == -1 && arr[l] != arr[r]){
                if(arr[l] > arr[r]) state = 0;
                else state = 1;
            }

            r++;
        }

        l = r;
        ans++;

    }

    print(ans);
    


}

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    in();
    solve();
    
}

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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] NM = Console.ReadLine().Split(' ');
            int N = int.Parse(NM[0]);
            int M = int.Parse(NM[1]);

            string[] A = Console.ReadLine().Split(' ');

            int answer = N;

            for(int i = 0; i < M; i++)
            {
                answer -= int.Parse(A[i]);
            }

            if(answer < 0)
            {
                Console.WriteLine("-1");
            }
            else
            {
                Console.WriteLine(answer);
            }
        }
    }
}


Measured memory_bytes: 28340
from collections import deque
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
ans = 0
que = deque()
que.append(a[0])
for i in range(1,n):
    ans+=que.popleft()
    que.append(a[i])
    que.append(a[i])
print(ans)

Measured memory_bytes: 93800
#include <stdio.h>
int main(){
	char s [8];
	scanf("%s",&s);
	getchar();
	
	if (s[2] == s[3] && s[4] == s[5])
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 1700
N = int(input())
F = []
P = []
for i in range(N):
    F += [list(map(int, input().split()))]
for i in range(N):
    P += [list(map(int, input().split()))]
ans = float('-inf')

for b in range(2**10):
    tmp = 0
    sumc = 0
    for i in range(N):
        c = 0
        for j in range(10):
            if (b >> j) & 1 and F[i][j]:
                c += 1
        tmp += P[i][c]
        sumc += c
    if sumc:
        ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 42220
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n;
  R n;
  ll a[n];
  rep(i,n) R a[i];
  sort(a,a+n,greater<ll>());
  ll ans=0;
  while(1) {
    ll sum=0,c[n];
    mem(c);
    rep(i,n) {
      sum+=a[i]/n;
      c[i]=a[i]/n;
      a[i]-=c[i]*n;
    }
    ans+=sum;
    bool f=1;
    rep(i,n) {
      a[i]+=sum-c[i];
      if(a[i]>=n) f=0;
    }
    if(f) break;
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define db double
using namespace std;
 
const int MAXN = 200200;
const int MAXE = 400400;
const int INF = 0x3f3f3f3f;
 
template<typename T> inline void CheckMax(T &A, T B) {
	A < B ? A = B : A;
}
 
template<typename T> inline void CheckMin(T &A, T B) {
	A > B ? A = B : A;
}
 
template <typename T> inline void read(T &x) {
    int c = getchar();
    bool f = false;
    for (x = 0; !isdigit(c); c = getchar()) {
        if (c == '-') {
            f = true;
        }
    }
    for (; isdigit(c); c = getchar()) {
        x = x * 10 + c - '0';
    }
    if (f) {
        x = -x;
    }
}
 
int n, k;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
#define X first
#define Y second

int a[MAXN];
 
signed main() {
	read(n), read(k);
	for(int i = 1; i <= n; i++) read(a[i]);
	sort(a + 1, a + n + 1);
	int ans = 0x7FFFFFFF;
	for(int i = 1; i <= n - k + 1; i++) {
		ans = min(ans, a[i + k - 1] - a[i]);
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    int n, k, i, r = 0, c = 0;
    char m;
    string s;
    cin >> n >> k >> s;
    queue<int> p, q;
    m = s[0];
    if(m == '0'){
        p.push(0);
    }
    for(i=0; i<n; i++){
        if(s[i] == m){
            c++;
        }else{
            p.push(c);
            c = 1;
            m = s[i];
        }
    }
    p.push(c);
    i = 0;
    while(i != 2*k+1 && !p.empty()){
        r += p.front();
        q.push(p.front());
        p.pop();
        i++;
    }
    c = r;
    while(!p.empty()){
        c += p.front();
        q.push(p.front());
        p.pop();
        c -= q.front();
        q.pop();
        if(p.empty()){
            c -= q.front();
            r = max(r,c);
            break;
        }
        c += p.front();
        q.push(p.front());
        p.pop();
        c -= q.front();
        q.pop();
        r = max(r, c);
    }
    
    cout << r << '\n';
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod = 1000000007;

ll N, M, res;

int main() {
	cin >> N >> M;
	if (N > M)
		swap(N, M);
	if (N == 1) {
		if (M == 1) {
			res = 1;
		}
		else
			res = M - 2;
	}
	else {
		res = (N - 2)*(M - 2);
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
if H == 1 or W == 1:
  print(1)
elif H%2 == 0:
  print(H//2 * W)
elif W%2 == 0:
  print((H//2 + 1) * int(W//2) + int(H//2) * int(W//2))
else:
  print(int(H//2 + 1) * int(W//2 + 1) + int(H//2) * int(W//2))

Measured memory_bytes: 3060
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
LL mod=1000000007;
LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


struct edge {int to;int cost;};
const int M_N=300;
int L;

vector<edge> G[M_N+1];

struct Dijkstra{

    P d[M_N+1];

    void dijkstra(int s){
        for (int i = 0; i < M_N; i++) {
            d[i] = mp(INF,INF);
        }
        priority_queue<pair<P,int> ,vector<pair<P,int>>,greater<pair<P,int>>> que;
        que.push({{0,-L},s});
        while(!que.empty()){
            pair<P,int> p=que.top();que.pop();
            int v=p.second;
            int t=-p.first.second;
            int l=p.first.first;
            if(d[v].first<l) continue;
            else if(d[v].first==l&&d[v].second>t) continue;
            d[v] = P(l,t);
            for(int i=0;i<G[v].size();i++){
                edge e=G[v][i];
                if(e.cost>t){
                    if(d[e.to].fs>l+1||(d[e.to].fs==l+1&&d[e.to].sc<L-e.cost)) que.push({{l+1,-(L-e.cost)},e.to});
                }
                else{
                    if(d[e.to].fs>l||(d[e.to].fs==l&&d[e.to].sc<t-e.cost)) que.push({{l,-(t-e.cost)},e.to});
                }
            }
        }
    }

};




int main(){
    int n,m;cin >> n >> m >> L;
    for (int i = 0; i < m; i++) {
        int x,y;cin >> x >> y;
        x--,y--;
        int c;cin >> c;
        if(c>L) continue;
        G[x].pb({y,c});
        G[y].pb({x,c});
    }
    Dijkstra Ds[M_N];
    for (int i = 0; i < n; i++) {
        Ds[i].dijkstra(i);
    }
    int q;cin >> q;
    for (int i = 0; i < q; i++) {
        int x,y;cin >> x >> y;
        x--,y--;
        int ans = Ds[x].d[y].first;
        if(ans == INF) cout << -1 << endl;
        else cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3536
#pragma GCC optimize("O3")
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>ll(b);i--)
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
#define INF 1000000000000 
#define MOD 1000000007 
#define MAXR 100000 
#define PB push_back 
#define MP make_pair 
#define F first 
#define S second 
#define Umap unordered_map
#define Uset unordered_set


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

    int X;
    cin >> X;

    int ans;
    if (X <= 599) ans = 8;
    else if (X <= 799) ans = 7;
    else if (X <= 999) ans = 6;
    else if (X <= 1199) ans = 5;
    else if (X <= 1399) ans = 4;
    else if (X <= 1599) ans = 3;
    else if (X <= 1799) ans = 2;
    else if (X <= 1999) ans = 1;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3612
def main():

    H, N = map(int, input().split())
    AB = []
    for _ in range(N):
        A, B = map(int ,input().split())
        AB.append([A, B])

    dp = [float('inf') for _ in range(H+1)]
    dp[0] = 0
    for i in range(0, H):
        if dp[i] != float('inf'):
            for j in range(N):
                if AB[j][0] + i >= H:
                    dp[H] = min(dp[H], dp[i]+AB[j][1])
                else:
                    dp[AB[j][0]+i] = min(dp[AB[j][0]+i], dp[i] + AB[j][1])
    if dp[H] == float('inf'):
        return -1
    return dp[H]

if __name__ == '__main__':
    print(main())


Measured memory_bytes: 42844
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		 Scanner scan = new Scanner(System.in);
		 int a = scan.nextInt();
		 int b = scan.nextInt();
		 int ans1 = a * b;
		 int ans2 = 2 * (a + b);
		 System.out.println(""+ans1+" "+ans2);
	}
}


Measured memory_bytes: 26168
/*
      Ashraful Islam Paran
      22-August-2020
      19:49:07
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(n) for (int i = 0; i < n; i++)
#define fo(i, x, n) for (int i = x; i < n; i++)
#define fb(i, x, n) for (int i = n - 1; i <= 0; i--)
#define w(t) int t; cin >> t; while (t--)


typedef unsigned long long ull;
typedef vector<long long> vi;
#define ull unsigned long long
#define msi map<string, long long>
#define mii map<long long, long long>
const int MX = 2e5 + 5;
const int INF = 1e18;
#define pb push_back
#define endl "\n"
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define all(x) x.begin(), x.end()
#define ff first
#define ss second

int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    // online submission
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    int a[n];
    f(n)
    {
        cin>>a[i];
    }
    int x=*max_element(a,a+n);
    int cnt{0};
    f(n-1)
    {
        if(a[i]>a[i+1])
        {
            cnt+=a[i]-a[i+1];
            swap(a[i],a[i+1]);
        }
    }
    cout<<cnt<<endl;

    

    
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
    return 0;
}

Measured memory_bytes: 5340
n = int(input())
d = dict()
name_list = []
for j in range(n):
    s, i = input().split()
    if s not in d.keys():
        d[s] = []
    d[s].append([int(i), j])
    name_list.append(s)
name_list = list(set(name_list))
name_list.sort()
for t in name_list:
    tar = sorted(d[t], reverse=True)
    for ans in tar:
        print(ans[1] + 1)


Measured memory_bytes: 3064
using System;

namespace ABC123A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c, d, e, k;

            a = int.Parse(Console.ReadLine());
            b = int.Parse(Console.ReadLine());
            c = int.Parse(Console.ReadLine());
            d = int.Parse(Console.ReadLine());
            e = int.Parse(Console.ReadLine());
            k = int.Parse(Console.ReadLine());
            if (e - a <= k)
                Console.WriteLine("Yay!");
            else
                Console.WriteLine(":(");
            Console.ReadKey();
        }
    }
}

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

int main()
{
    string s;
    cin >> s;
    int A, Z;
    int ssize = s.size();
    for (int i = 1; i < ssize + 1; i++)
    {
        if (s.at(i - 1) == 'A')
        {
            A = i;
            break;
        }
    }
    for (int i = ssize; ssize >= 1; i--)
    {
        if (s.at(i - 1) == 'Z')
        {
            Z = i;
            break;
        }
    }
    //    cout << A << " " << Z << endl;
    cout << Z - A + 1 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const long long INF = 1LL<<60;
int H, W;
vector<string> fi;

long long solve() {
    vector<vector<long long>> dp(H, vector<long long>(W, INF));
    if (fi[0][0] == '#') dp[0][0] = 1;
    else dp[0][0] = 0;

    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            for (int dir = 0; dir < 2; ++dir) {
                int ni = i + dx[dir], nj = j + dy[dir];
                if (ni >= H || nj >= W) continue;
                int add = 0;
                if (fi[ni][nj] == '#' && fi[i][j] == '.') add = 1;
                chmin(dp[ni][nj], dp[i][j] + add);
            }
        }
    }
    return dp[H-1][W-1];
}

int main() {
    while (cin >> H >> W) {
        fi.resize(H);
        for (int i = 0; i < H; ++i) cin >> fi[i];
        cout << solve() << endl;
    }
}

















Measured memory_bytes: 384
/*
ID: rchalam1
LANG: C++14
TASK:
*/
// For train.usaco.org, fill the template above.

// Competitive Coding Template

// GCC OPTIMIAZTION FLAGS
#ifdef ONLINE_JUDGE
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#endif

#include <bits/stdc++.h>

/*
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
*/
// All Includes for Competitive Coding Template

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

using vi = std::vector<int>;
using vll = std::vector<long long>;
using vull = std::vector<unsigned long long>;

#define FOR(i, a, b) for (auto i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (auto i = (a); i >= (b); --i)
#define R0F(i, a) ROF(i, a, 0)
#define ITR(a, x) for (auto& a: x)

#define FSRT(set) sort((set).begin(),(set).end())
#define RSRT(set) sort((set).rbegin(),(set).rend())
#define CSRT(set, function) sort((set).begin(),(set).end(), (function))
#define TRS(set) sort((set).begin(),(set).end(), greater<>())
#define REV(set) reverse((set).begin(),(set).end());

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

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

// For stdio, call setIO() or setIO("").
void setIO(std::ifstream &readFile, std::ofstream &writeFile, const std::string &name = "", bool stdIO = false)
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);
	if(!name.empty() && !stdIO)
	{
		readFile.open(name + ".in");
		if(readFile.fail()) return;
		writeFile.open(name + ".out");
		std::cin.rdbuf(readFile.rdbuf());
		std::cout.rdbuf(writeFile.rdbuf());
	}
}

// To time program, create object Timer  to start timing, and call Timer.elapsed().
#include <chrono>

class Timer
{
	std::chrono::time_point<std::chrono::high_resolution_clock> m_beg;
public:
	Timer() : m_beg(std::chrono::high_resolution_clock::now())
	{}

	void reset()
	{ m_beg = std::chrono::high_resolution_clock::now(); }

	[[nodiscard]] long double elapsed() const
	{
		return std::chrono::duration_cast<std::chrono::duration<long double, std::ratio<1> >>(
				std::chrono::high_resolution_clock::now() - m_beg).count();
	}
};

// Defines datatype
using dt = int;
// Defines MAXN value
constexpr dt MAXN = 1e5 + 1;
// Defines Modulus
constexpr dt MOD = 1e9 + 7;
// Defines Floating Point Correction
constexpr long double EPS = 1e-9;

//*****
//START CODE BELOW
//*****

int main(int argc, char *argv[])
{
	static std::ifstream readFile;
	static std::ofstream writeFile;
	setIO(readFile, writeFile);
	int n;
	cin >> n;
	vector<int> problems;
	for(int i = 0; i < n; ++i)
	{
		int problem;
		cin >> problem;
		problems.push_back(problem);
	}
	sort(problems.begin(), problems.end());
	cout << (problems[problems.size() / 2] - problems[problems.size() / 2 - 1]) << '\n';
}

Measured memory_bytes: 3888
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

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

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int h,w;
  cin >> h >> w;
  vector<string> A(h);
  rep(i,h) cin >> A[i];
  queue<P> que;
  que.push(P(0,0));
  vector<vector<bool> > visited(h,vector<bool>(w,false));
  visited[0][0] = true;
  bool ok = true;
  while(!que.empty()) {
    P p = que.front(); que.pop();
    rep(i,2) {
      int nx = p.second + dx[i];
      int ny = p.first + dy[i];
      if (nx < 0 || ny < 0 || nx >= w || ny >= h) continue;
      if (visited[ny][nx] || A[ny][nx] == '.') continue;
      visited[ny][nx] = true;
      que.push(P(ny,nx));
      break; //ここまできたら抜ける
    }
  }
  rep(y,h) rep(x,w) {
    if (!visited[y][x] && A[y][x] == '#') {
      ok = false; break;
    }
  }
  if (ok) cout << "Possible\n";
  else cout << "Impossible\n";
  return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  cout << (a + b) % 24 << endl;
  return 0;
}

Measured memory_bytes: 256
n,tl = map(int,input().split())
cs = []
ts = []

for i in range(n):
  c, t = map(int,input().split())
  if t <= tl:
    cs.append(c)

min = 10000000
if len(cs) == 0:
  print('TLE')
else:
  for i in cs:
    if i < min:
      min = i
  print(min)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <map>
using namespace std;

long long N, W;
long long w[111];
long long v[111];
long long dp[111111];
int main(){
    cin >> N >> W;
    for(int i=0; i<N; i++)
        cin >> w[i] >> v[i];

    for(int i=0; i<N; i++)
        for(int j=W; j>=0; j--){
            if(j+w[i] > W) continue;
            dp[j+w[i]] = max(dp[j+w[i]], dp[j]+v[i]);
        }

    long long ans = 0;
    for(int i=0; i<=W; i++)
        ans = max(ans, dp[i]);
    cout << ans << endl;
    return 0;
}

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

mylist=list(map(int,input().split()))

#print(N)
#print(mylist)

answer=0

for i in range(1,N+1):
    for j in range(i+1,N+1):
        if i==j:
            nothing=0
        else:
            answer+=mylist[i-1]*mylist[j-1]
            
print(answer)

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

//piに含まれない整数の内Xに最も近いものを出力
//複数の場合は小さい方を出力
//piが空行の場合もある
int main(){
    int X,N;
    cin >> X >> N;
    int* p = new int[N];
    for(int i=0;i<N;++i){
        cin >> p[i];
    }

    int dis=0;
    while(true){
        int now=X-dis;
        bool exist=false;
        for(int i=0;i<N;++i){
            if(p[i] == now){
                exist=true;
                break;
            }
        }
        if(!exist){
            cout << now << endl;
            break;
        }
        now=X+dis;
        exist=false;
        for(int i=0;i<N;++i){
            if(p[i] == now){
                exist=true;
                break;
            }
        }
        if(!exist){
            cout << now << endl;
            break;
        }
        ++dis;
    }
}

Measured memory_bytes: 3636
using System;
public class Hello{
    public static void Main(){
        // Your code here!
        var N =int.Parse(Console.ReadLine());
        int n = 0;
        char[] stArrayData = Console.ReadLine().ToCharArray();
        for(int i=0 ; i<N;i++)
        {
            if(i==0){
                n++;
            }else{
                if(stArrayData[i]!=stArrayData[i-1])
                {
                    n++;
                }
            }
        }
        Console.WriteLine(n);
    }
}

Measured memory_bytes: 11488
n = int( input() )
x = list(map(int, input().split()))
y = list(map(int, input().split()))
for i in range(1,4):
    s=0
    m=0
    for j in range(n):
        s+=(abs(x[j]-y[j]))**i
        if (abs(x[j]-y[j])) > m:
            m=(abs(x[j]-y[j]))
    print(s**(1/i))
print(m)

Measured memory_bytes: 7796
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union{
  vector<ll> par;
  Union(ll a){
  par=vector<ll>(a,-1);
  }
  ll find(ll a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(ll a,ll b){
    return (find(a)==find(b));
  }
  ll size(ll a){
    return -par[find(a)];
  }
  void unite(ll a,ll b){
    ll c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
ll Nagaemon1;
void swap(ll i,ll j){
  Nagaemon1=i;
  i=j;
  j=Nagaemon1;
}
ll euclidean_gcd(ll a, ll b) {
  if(a < b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
int main(void){
  ll n,k;
  cin >> n >> k;
  ll p[n];
  rep(i,n)cin >> p[i];
  sort(p,p+n);
  ll ans=0;
  rep(i,k)ans+=p[i];
  cout << ans;
}

Measured memory_bytes: 3636
import math

a, b, h, m = map(int, input().split())

jisin_rad = 2 * math.pi * (h + m / 60) / 12
hunsin_rad =  2 * math.pi * m / 60

rad = abs(jisin_rad - hunsin_rad)

c = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(rad))
print(c)

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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b,c,d; cin>>a>>b>>c>>d;
	cout << ((abs(a-c)<=d||(abs(a-b)<=d&&abs(b-c)<=d)) ? "Yes" : "No") << endl;
	return 0;
}


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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7,INF=mod*mod*3;
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll N,M;
P bdg[100005];
ll par[100005];
ll rnk[100005];
ll cnt[100005];
ll ans[100005];
bool love[100005];
void init(ll n){
	for(ll i=0; i<n; i++){
		par[i]=i;
		rnk[i]=0;
	}
}
ll find(ll x){
	if(par[x]==x){
		return x;
	}else{
		return par[x]=find(par[x]);
	}
}
void unite(ll x,ll y){
	x=find(x);
	y=find(y);
	if(x==y) return;
	if(rnk[x]<rnk[y]){
		par[x]=y;
	}else{
		par[y]=x;
		if(rnk[x]==rnk[y]) rnk[x]++;
	}
}
bool same(ll x,ll y){
	return find(x)==find(y);
}

int main(){

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

cin>>N>>M;
rep(j,M){
	cin>>bdg[j].first>>bdg[j].second;
	bdg[j].first--; bdg[j].second--;
}
ll unko=N*(N-1)/2;
init(N);
for(ll i=M-1;i>=0;i--){
	ll x=bdg[i].first,y=bdg[i].second;
	ans[i]=unko;
	if(same(x,y)){
		ll root=find(x);
		if(!love[x]){
			cnt[root]++; love[x]=true;
		}
		if(!love[y]){
			cnt[root]++; love[y]=true;
		}
	}else{
		ll root1=find(x); 
		ll root2=find(y); 
		if(!love[x]){
			cnt[root1]++; love[x]=true;
		}
		if(!love[y]){
			cnt[root2]++; love[y]=true;
		}
		unko-=cnt[root1]*cnt[root2];
		unite(x,y);
		ll root=find(x);
		if(root==root1){
			cnt[root]+=cnt[root2];
		}
		else if(root==root2){
			cnt[root]+=cnt[root1];
		}
	}
}

rep(i,M) cout<<ans[i]<<endl;

}
	


Measured memory_bytes: 8360