akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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


int main() {
  int w, a, b;
  cin >> w >> a >> b;
  int ans = max(a, b) - (min(a, b) + w);
  if (ans < 0) P(0);
  else P(ans);
  return 0;
}

Measured memory_bytes: 256
from math import sqrt
n,d = map(int,input().strip().split())
cnt = 0
for i in range(n):
	x,y = map(int,input().strip().split())
	# print(x,y)
	if x*x+y*y <= d*d:
		# print(x,y)
		cnt+=1
print(cnt)

Measured memory_bytes: 9092
//2018/7/14
//0x21
#include<bits/stdc++.h>
using namespace std;
int main ()
{
  int n,d;
  cin>>d>>n;
  int sum = 1;
  for(int i =0;i<d;i++)
   sum*=100;
  if(n == 100)
  {
    cout<<101*sum<<endl;
  }
  else {
    cout<<sum*n<<endl;
  }
  return 0 ;
}


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

using namespace std;

int main() {
	int ans = 0;
	string s;
	cin >> s;
	for (int i = 0; i*2 <= s.size() - 1; i++) {
		if (s[i] == 'w'&&s[s.size() - i - 1] == 'w');
		else if (s[i] == 'i'&&s[s.size() - i - 1] == 'i');
		else if (s[i] == '('&&s[s.size() - i - 1] == ')');
		else if (s[i] == ')'&&s[s.size() - i - 1] == '(');
		else ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3136
#include<iostream>
#include<vector>
#include<utility>
#include<deque>
#include<algorithm>
#include <iomanip>
#include<cmath>

using namespace std;
using ll = long long int;
constexpr int INF = 1 << 29;
constexpr ll MOD = ll(1e9 + 7);

int n, a, m;
vector<int> x;
ll ret = 0;
ll dp[51][51][2501];

int main(void) {
	cin >> n >> a;
	x.resize(n + 1);
	dp[0][0][0] = 1;
	for (int i = 1; i <= n; i++) {
		cin >> x[i];
	}
	for (int i = 1; i <= n; i++) {//i番目まで
		for (int j = 0; j <= i; j++) {//枚数
			for (int k = 0; k <= 50 * j; k++) {//合計
				dp[i][j][k] = dp[i - 1][j][k];
				if (k >= x[i])
					dp[i][j][k] += dp[i - 1][j - 1][k - x[i]];
			}
		}
	}

	for (int k = 1; k <= n; k++)
		ret += dp[n][k][a * k];

	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 48640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 9 ;
int a[N] , b[N] ,c[N] , mem[N][5];
int n;
int solve(int day , int curr){
    if(day == n)
        return 0;
    int &ret = mem[day][curr];
    if(~ret)
        return ret ;
    if(curr == 0){
        ret = max(ret , a[day] + solve(day + 1 , 1)) ;
        ret = max(ret , a[day] + solve(day + 1 , 2)) ;
    }
    if(curr == 1){
        ret = max(ret , b[day] + solve(day + 1 , 0)) ;
        ret = max(ret , b[day] + solve(day + 1 , 2)) ;
    }
    if(curr == 2){
        ret = max(ret , c[day] + solve(day + 1 , 0)) ;
        ret = max(ret , c[day] + solve(day + 1 , 1)) ;
    }
    return ret ;

}
int main()
{

    memset(mem ,-1 , sizeof mem);
    cin >> n ;
    for(int i = 0 ; i  <n ; ++i){
        cin >> a[i] >> b[i] >> c[i];
    }
    int ans = 0 ;
    for(int i = 0 ; i < 3 ; ++i)
        ans = max(ans , solve(0 , i));
    cout << ans << endl ;

    return 0;
}


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

int solve(int x)
{
    if(x / 500)
        return solve(x % 500) + (x / 500) * 1000;
    else if(x / 5)
        return solve(x % 5) + (x / 5) * 5;
    else
        return 0;
}


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

    cout << solve(x) << "\n";
    return 0;
}

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  string r,l;
  rep(i,s.length()){
    if(i%2!=0){
      r+='0';
      l+='1';
    }
    else{
      r+='1';
      l+='0';
    }
  }
  int rcnt = 0, lcnt=0;
  rep(i,s.length()){
    if(s[i] != r[i]){
      rcnt++;
    }
    if(s[i] != l[i]){
      lcnt++;
    }
  }
  cout << min(rcnt, lcnt) << endl;
}

Measured memory_bytes: 720
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);

		int gameCount = stdin.nextInt();
		
		for(int i = 0; i < gameCount; i++) {
			
			int k = stdin.nextInt();
			int p = stdin.nextInt();
			int amari = k % p;
			if(amari == 0){ 
			System.out.println(p);
			} else {
				System.out.println(amari);
			}
		}
	}
}

Measured memory_bytes: 26352
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>

using namespace std;
typedef long long ll;
const int LEN = 100000;

struct fastio{
  int it,len;
  char s[LEN + 5];
  fastio(){
    it = len = 0;
  }
  char get(){
    if(it < len) return s[it++];
    it = 0, len = fread(s,1,LEN,stdin);
    return len ? s[it++] : EOF;
  }
  bool notend(){
    char c;
    for(c = get();c == ' ' || c == '\n';c = get());
    if(it) it--;
    return c != EOF;
  }
  void put(char c){
    if(it == LEN) fwrite(s,1,LEN,stdout), it = 0;
    s[it++] = c;
  }
  void flush(){
    fwrite(s,1,it,stdout);
  }
}buff,bufo;
inline int getint(){
  char c; int res = 0, sig = 1;
  for(c = buff.get();c < '0' || c > '9';c = buff.get()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline ll getll(){
  char c; ll res = 0, sig = 1;
  for(c = buff.get();c < '0' || c > '9';c = buff.get()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline void putint(int x,char suf){
  if(!x) bufo.put('0');
  else{
    if(x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[15];
    while(x){
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for(;k;k--) bufo.put(s[k]);
  }
  bufo.put(suf);
}
inline void putll(ll x,char suf){
  if(!x) bufo.put('0');
  else{
    if(x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[25];
    while(x){
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for(;k;k--) bufo.put(s[k]);
  }
  bufo.put(suf);
}
inline char get_char(){
  char c;
  for(c = buff.get();c == ' ' || c == '\n';c = buff.get());
  return c;
}

int main(){
  ll a = getll(), b = getll(), k = getll();
  if(k <= a){
    putll(a - k,' ');
    putll(b,'\n');
  }else{
    k -= a;
    putll(0,' ');
    putll(max(0ll,b - k),'\n');
  }
  bufo.flush();
  return 0;
}


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

int main(){
  long long int n,k, hoge=0;
  scanf("%lld %lld",&n,&k);
  hoge = n % k;
  if(llabs(hoge -k) < hoge) hoge = llabs(hoge -k);
  printf("%lld",hoge);
}


Measured memory_bytes: 128
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;


namespace cfA
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] a = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

            int n = 0;
            for (int i = 0; i < a.Length; i++)
            {
                if (a[i] <= i) continue;
                if (a[a[i] - 1] == i + 1)
                {
                    n++;
                }
            }

            Console.WriteLine(n);

        }
    }
}


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

int main()
{
  int S,T,a,b,c,d;
  cin>>a>>b>>c>>d;
  S=a+b+c+d;
  cin>>a>>b>>c>>d;
  T=a+b+c+d;
  S>=T?cout<<S<<endl:cout<<T<<endl;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<map>
using namespace std;
using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int N = S.size();
    map<int, ll> cnt;
    ll ans = 1;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 26; j++) {
            if (S[i] - 'a' == j) {
                continue;
            }
            else {
                ans += cnt[j];
            }
        }
        cnt[S[i] - 'a']++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 720
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define FFOR(i, a, b) for(int (i)=a;(i)>(b);--(i))
#define rrep(i,n) FFOR(i,0,n)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define lb long double
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 1234567890123456
typedef pair<int, int> P;
typedef pair<int, P> PP;

const int maxn =1e5 + 10;

//initialization here
//
int a[maxn];
//
//initialization finish


// your function is here
//

//
// your function finished

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// your code is here
	//

	int n;cin>>n;
	rep(i,n) cin>>a[i];
	int allcost = abs(a[0]);
	FOR(i,1,n) allcost += abs(a[i-1]-a[i]);
	allcost += abs(a[n-1]);

	rep(i,n)
	{
		int ans = allcost;
		if(i == 0)
		{
			ans -= abs(a[0]) + abs(a[1]-a[0]);
			ans += abs(a[1]);
			Print(ans);
		}
		else if(i == n-1)
		{
			ans -= abs(a[n-1]) + abs(a[n-1]-a[n-2]);
			ans += abs(a[n-2]);
			Print(ans);
		}
		else
		{
			ans -= abs(a[i-1]-a[i]) + abs(a[i]-a[i+1]);
			ans += abs(a[i-1]-a[i+1]);
			Print(ans);
		}
	}
	//
	// your code finished


	return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
int n,m;
int sum;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=m;j++){
			int f=0;
			int p=j;
			int o=1;
			while(p>0){
				o*=p%10;
				if(p%10==1) f=1;
				p/=10;
			}
			if(f==1) continue;
			if(o==i) sum++;
		}
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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 gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

// win: 1, lose: 2
vector<int> dp, a;
int rec_game (int k) {
    if (dp[k] != 0) return dp[k];
    if (k < a[0]) return dp[k] = 2;
    bool win = false;
    for (int i : a) {
        if (i > k) break;
        win |= (rec_game(k - i) == 2);
    }
    return dp[k] = (win ? 1 : 2);
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    
    dp.resize(k + 1); a.resize(n);
    rep (i, n) cin >> a[i]; sort(all(a));
    
    cout << (rec_game(k) == 1 ? "First" : "Second") << "\n";
    return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <map>
#include <cmath>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
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(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
const ll MOD=1e+9+7;
struct mint{
  ll x;
  mint(ll x=0):x(x%MOD){}
  mint& operator+=(const mint a){
    if((x+=a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator-=(const mint a){
    if((x += MOD-a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator*=(const mint a){
    (x*=a.x)%=MOD;
    return *this;
  }
  mint operator+(const mint a) const{
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const{
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const{
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const{
    if(!t) return 1;
    mint a = pow(t>>1);
    a*=a;
    if(t&1) a*=*this;
    return a;
  }
  
  //for prime mod
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint a){
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const{
    mint res(*this);
    return res/=a;
  }
};

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

mint pow2[200010];

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

  pow2[0].x = 1;
  rep(i,200000) {
    pow2[i+1] = pow2[i]*(mint)2;
  }
  
  using pll = pair<ll,ll>;
  map<pll,ll> mp;
  vector<pll> vec(n);
  mint cnt0;
  rep(i,n) {
    if(a[i] == 0 && b[i] == 0) {
      cnt0 += (mint)1;
      continue;
    }    
    ll g = gcd(abs(a[i]), abs(b[i]));
    ll aa = abs(a[i])/g, bb = abs(b[i])/g;
    if((a[i] < 0 && b[i] > 0) || (a[i] > 0 && b[i] < 0) ) {
      vec[i] = {bb, aa};
      mp[{-aa, bb}]++;
    }

    else {
      mp[{aa, bb}]++;      
    }
  }

  mint res(1);
  for(auto m: mp) {
    mint tmp;
    ll aa = m.first.first, bb = m.first.second;
    ll val = m.second;
    if(aa > 0) { // (1,0) もいける
      tmp = pow2[val] + pow2[mp[{-bb, aa}]] - (mint)1;
      mp[{aa, bb}] = 0;
      mp[{-bb, aa}] = 0;
    }
    else if(aa == 0) { // (0,1)
      tmp = pow2[val] + pow2[mp[{bb, aa}]] - (mint)1;
      mp[{aa, bb}] = 0;
      mp[{bb, aa}] = 0;      
    }
    else {
      tmp = pow2[val] + pow2[mp[{bb, -aa}]] - (mint)1;
      mp[{aa, bb}] = 0;
      mp[{bb, -aa}] = 0;            
    }
    res *= tmp;
  }

  res += cnt0 - (mint)1;
  
  cout << res.x << "\n";
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  
  int abv = n / 100;
  int blw = n - abv * 100;
  
  if ((1 <= abv) && (abv <= 12))
  {
    if ((1 <= blw) && (blw <= 12))
    {
      cout << "AMBIGUOUS" << endl;
    }
    else
    {
      cout << "MMYY" <<endl;
    }
  }
  else
  {
     if ((1 <= blw) && (blw <= 12))
     {
      cout << "YYMM" << endl;
    }
    else
    {
      cout << "NA" <<endl;
    }
  }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

def main():

    W, H, x, y = map(int, input().split())

    ans = []

    if x == W / 2 and y == H / 2:
        ans.append(W * H / 2)
        ans.append(1)

    else:
        ans.append(W * H / 2)
        ans.append(0)

    print(ans[0], ans[1])


if __name__ == "__main__":
    main()

Measured memory_bytes: 9012
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>

using namespace std;

#define INF 1000000007
#define LINF 1000000000000000007

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


int k,n,m;
i64 dp1[2020][2020], dp2[2020][2020];

int main(){
	cin >> n >> k;
	
	dp1[0][0] = 1;
	dp2[0][0] = 1;
	for(int i = 1; i <= n-k+1; i++){
		for(int j = 0; j <= i+1; j++){
			dp1[i][j] = dp1[i-1][j] + dp1[i-1][j-1];
			dp1[i][j] %= INF;
		}
	}
	for(int i = 1; i <= k-1; i++){
		for(int j = 0; j <= i+1; j++){
			dp2[i][j] = dp2[i-1][j] + dp2[i-1][j-1];
			dp2[i][j] %= INF;
		}
	}
	
	for(int i = 1; i <= k; i++){
		cout << dp1[n-k+1][i]*dp2[k-1][i-1]%INF << endl;
	}
	
	return 0;
}

Measured memory_bytes: 33664
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll a, b, c; cin >> a >> b >> c;
  if(c - a - b > 0 && 4 * a * b < (c - a - b) * (c - a - b)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

#define endl '\n'
#define int ll
using namespace std;
typedef long long ll;

const int N = 1010;
const ll MOD = 1e9+7;
int R, C;
char maze[N][N];
ll dp[N][N];

void init();
void process();

int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    init();
    process();
    cout.flush();
    return 0;
}

void init()
{
    cin >> R >> C;
    for(int r = 0; r < R; r++)
        for(int c = 0; c < C; c++)
            cin >> maze[r][c];
}

void process()
{
    dp[0][0] = 1;
    for(int r = 0; r < R; r++)
        for(int c = 0; c < C; c++)
        {
            if(maze[r][c] != '.') continue;
            if(r > 0 && maze[r-1][c] == '.') dp[r][c] = (dp[r][c] + dp[r-1][c])%MOD;
            if(c > 0 && maze[r][c-1] == '.') dp[r][c] = (dp[r][c] + dp[r][c-1])%MOD;
        }
    cout << dp[R-1][C-1] << endl;
}



Measured memory_bytes: 9216
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=998244353;
//gcd
ll gcd(ll a,ll b){
    if(min(a,b)==0)return max(a,b);
    if(max(a,b)%min(a,b)==0)return min(a,b);
    return gcd(min(a,b),max(a,b)%min(a,b));
}
int main(){
    ll a,b;cin>>a>>b;
    cout<<a*b/gcd(a,b)<<endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000)
#def input():
#    return sys.stdin.readline()[:-1]

'''
n=int(input())
for i in range(n):
    a[i]=int(input())
    a[i],b[i]=map(int,input().split())
a=[int(x) for x in input().split()]
n,m=map(int,input.split())
from operator import itemgetter
a = [(1, "c", 1), (1, "b", 3), (2, "a", 0), (1, "a", 2)]
print(sorted(a))  # 0 番目の要素でソート、先頭の要素が同じなら 1 番目以降の要素も見る
print(sorted(a, key=itemgetter(0)))  # 0 番目の要素だけでソート
print(sorted(a, key=itemgetter(0, 2)))  # 0 番目と 2 番目の要素でソート
print(sorted(a, key=lambda x: x[0] * x[2]))  # 0 番目の要素 * 2 番目の要素でソート
print(sorted(a, reverse=True))  # 降順にソート
a.sort()  # 破壊的にソート、sorted() よりも高速
try: # エラーキャッチ list index out of range
    for i in range():
        k=b[i]
except IndexError as e:
    print(i)
'''

test_data1 = '''\
A??C
'''

test_data2 = '''\
ACACAC
'''

test_data3 = '''\
????C?????B??????A???????
'''

test_data4 = '''\
?AC?AC
'''
td_num=3

def GetTestData(index):
    if index==1:
        return test_data1
    if index==2:
        return test_data2
    if index==3:
        return test_data3
    if index==4:
        return test_data4
    
if False:
    with open("../test.txt", mode='w') as f:
        f.write(GetTestData(td_num))
    with open("../test.txt") as f:
        # Start Input code ---------------------------------------
        s=f.readline()
        # End Input code ---------------------------------------
else:
    # Start Input code ---------------------------------------
    s=input()
    # End Input code ---------------------------------------
n=len(s)
dc=dict()
dc['A']=0
dc['B']=1
dc['C']=2
dc['?']=3
dp=[[0 for i in range(4)] for j in range(n+1)]
dp[0][0]=1
mo=10**9+7
for i in range(n):
    for t in range(4):
        ch=s[i]
        if dc[ch]==t-1 or dc[ch]==3:
            m=1
        else:
            m=0
        if t!=0:
            dp[i+1][t]+=(dp[i][t-1]*m)%mo
        dp[i+1][t]+=(dp[i][t]*max(int(dc[ch]/3)*3,1))%mo
#print(dp)
ans=dp[n][3]

#mo=2291979612924+1
#print(ans,'n,s=',n,s,'lc(a,w)=',lc_a,lc_w,'rc(c,w)=',rc_c,rc_w)
    #print('i,ans',i,ans)
#print(ans,'n,s=',n,s,'lc(a,w)=',lc_a,lc_w,'rc(c,w)=',rc_c,rc_w)
print(ans%mo)
#ans=count(0)+2^(count(n)-1)

Measured memory_bytes: 27636
def Grid_Repainting(h , w , sl):

    ans = "Yes"
    xl = [1, 0, -1, 0]
    yl = [0 , 1 , 0 , -1]

    for i in range(h):
        for v in range(w):
            count = 0
            countcheck = 4
            if sl[i][v] == "#":
                for q in range(4):
                    x = i + xl[q]
                    y = v + yl[q]
                    if x >= 0 and x < h and y >= 0 and y < w:
                        if sl[x][y] == ".":
                            count += 1
                    else:
                        countcheck -= 1
            if count == countcheck:
                ans = "No"

    return ans

def main():
    h , w = map(int , input().split())
    sl = [list(str(input())) for i in range(h)]
    print(Grid_Repainting(h , w , sl))

if __name__ == '__main__':
    main()

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	vector <int> v;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		v.push_back(a);
	}
	vector <int> dp(n,0);
	dp[1]=abs(v[0]-v[1]);
	for(int i=2;i<n;i++){
		dp[i]=min(abs(v[i]-v[i-1])+dp[i-1],abs(v[i]-v[i-2])+dp[i-2]);
	}
	cout<<dp[n-1]<<endl;
	
} 

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

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

int main() {
  int a;
  string b;
  cin>>a>>b;
  int count=0;
  for(int i=0;i<a-2;i++){
    if(b.at(i)=='A'&&b.at(i+1)=='B'&&b.at(i+2)=='C'){
      count++;
    }
  }
  cout<<count<<endl;
}


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

using namespace std;

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

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

int main() {
  int h, w;
  while (cin >> h >> w) {
    if (h == 0 && w == 0) break;
    REP(i, h) {
      if (i == 0 || i == h - 1) {
        REP(j, w) cout << "#";
      } else {
        REP(j, w) {
          if (j == 0 || j == w - 1)
            cout << "#";
          else
            cout << ".";
        }
      }
      cout << "\n";
    }
    cout << "\n";
  }
  return 0;
}


Measured memory_bytes: 3024
#include <bits/stdc++.h>
using namespace std;
string a;
int i;
int main()
{
    cin>>a;
    for(i=0;i<a.size()-1;i++)
        if(a[i]=='A'&&a[i+1]=='C')cout<<"Yes\n",i=19260817;
    if(i<100000)cout<<"No\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,a[100010]={},b[100010]={},dp[100010]={};
    bool can=true;
    cin>>n>>m;
    rep(i,m){
        cin>>a[i];
        b[a[i]]++;
        if(i>=1 && a[i]==a[i-1]+1) can=false;
    }
    if(!can){
        cout<<0<<endl;
        return 0;
    }
    dp[0]=1;
    if(b[1]!=1) dp[1]=1;
    rep2(i,2,n+1){
        if(b[i]==1) continue;
        else{
            dp[i]=dp[i-1]+dp[i-2];
            dp[i]%=MOD;
        }
    }
    cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 2560
n, a, b = map(int, input().split())

if abs(a - b) % 2 == 0:
    print(abs(a-b) // 2)
else:
    dla, dlb = n-a, n-b
    dra, drb = a-1, b-1
    ansl = min(dla, dlb) + 1 + abs(dla - dlb) // 2
    ansr = min(dra, drb) + 1 + abs(dra - drb) // 2
    print(min(ansl, ansr))

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

struct Juwely {
    int v;
    int c;
    
    Juwely(int a_v, int a_c) {
        v = a_v;
        c = a_c;
    }
};

bool cmp(const Juwely &a, const Juwely &b) {
    return ((double)a.v / a.c) > ((double)b.v / b.c);
}

int main() {
    int n, m;
    cin >> n;
    int x = 0;
    int y = 0;
    
    vector<Juwely> j;
    
    for (int i = 0; i < n; i++) {
        cin >> m;
        j.push_back(Juwely(m, 0));
    }
    
    for (int i = 0; i < n; i++) {
        cin >> j[i].c;
    }
    
    //sort(j.begin(), j.end(), cmp);
    
    for (int i = 0; i < n; i++) {
        if (j[i].v > j[i].c) {
            x += j[i].v;
            y += j[i].c;
        }
    }
    
    cout << (x - y) << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n=I()
A=LI()
for i in range(40):
    #print(i)
    #print(A)
    for j in range(n):
        if A[j]%2==0:
            A[j]//=2
            continue
        else:
            print(i)
            sys.exit()

Measured memory_bytes: 3316
#include<iostream>
const int maxn=1e5+10;
using namespace std;

int a[maxn];
int b[maxn];

int main(){
	int n;cin>>n;
	
	//a[i]表示编号为i的学生进来的时候，一共有多少人了（加这个学生） 
	for(int i=1;i<=n;i++){
		cin>>a[i];
		int num=a[i];
		b[num]=i;
	}
	
	for(int i=1;i<n;i++){
		cout<<b[i]<<" ";
	}
	cout<<b[n];
	
	return 0;
	
} 

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

using namespace std;

struct FlowEdge
{
	int u, v;
	long long c, f = 0;
	FlowEdge(){}
	FlowEdge(int _u,int _v,long long _c)
	{
		u = _u; v = _v; c = _c;
	}
};

struct Template_Dinic
{
	const long long flow_INF = 1e18;	
	vector<FlowEdge> Edges;
	vector<vector<int>> AdjList;
	int n, s, t, m = 0;
	vector<int> d, ptr;
	queue<int> q;

	void init(int _n,int _s,int _t)
	{
		n = _n, s = _s, t = _t;
		AdjList.resize(n + 1); 
		d.resize(n + 1);
		ptr.resize(n + 1);
	}

	void add_edge(int u,int v,long long c)
	{
		Edges.push_back(FlowEdge(u,v,c));
		Edges.push_back(FlowEdge(v,u,c));
		AdjList[u].push_back(m);
		AdjList[v].push_back(m + 1);
		m += 2;
	}

	bool bfs()
	{
		while(!q.empty())
		{
			int u = q.front();
			q.pop();
			for (int i=0;i<AdjList[u].size();i++)
			{
				int id = AdjList[u][i];
				if (Edges[id].f < Edges[id].c && d[Edges[id].v] == -1)
				{
					d[Edges[id].v] = d[u] + 1;
					q.push(Edges[id].v);
				}
			}
		}
		return d[t] != -1;
	}

	long long dfs(int u, long long cur)
	{
		if (cur == 0) return 0;
		if (u == t) return cur;
		for (int& cid = ptr[u];cid < AdjList[u].size();cid++)
		{
			int id = AdjList[u][cid];
			int v = Edges[id].v;
			if (d[u] + 1 == d[v] && Edges[id].f < Edges[id].c)
			{
				long long nxt = dfs(v, min(cur,Edges[id].c - Edges[id].f));
				if (!nxt) continue;
				Edges[id].f += nxt;
				Edges[id ^ 1].f -= nxt;
				return nxt;
			}
		}
		return 0;
	}

	long long flow()
	{
		long long res = 0;
		while(1)
		{
			for (int i=0;i<d.size();i++) d[i] = -1;
			d[s] = 0;
			q.push(s);
			if (!bfs())
				break;
			for (int i=0;i<ptr.size();i++) ptr[i] = 0;
			while(long long cur = dfs(s, flow_INF))
				res += cur; 	
		}
		return res;
	}
}Dinic;

int h,w;

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

	cin >> h >> w;
	Dinic.init(500,0,201);
	for (int i=1;i<=h;i++)
		for (int j=1;j<=w;j++)	
		{
			char c; cin >> c;
			if (c == 'S')
			{
				Dinic.add_edge(0,i,1e9);
				Dinic.add_edge(0,j+100,1e9);	
			}
			else if (c == 'T')
			{
				Dinic.add_edge(i,201,1e9);
				Dinic.add_edge(j+100,201,1e9);
			}
			else if (c == 'o')
				Dinic.add_edge(i,j+100,1);
		}
	long long res = Dinic.flow();
	if (res >= 1e9) cout << -1;
	else cout << res;
}

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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define all(x) x.begin(), x.end()
#define EPS 1e-9
#define INF 2e18
#define ROOT 1
#define M 1000000007
#define curtime chrono::steady_clock::now().time_since_epoch().count
#define rep(i, beg, n, s) for (int i = beg; i < n; i += s)
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m = M)
{
  int ret = n % m;
  if (ret < 0)
    ret += m;
  return ret;
}

int exp(int n, int k)
{
  if (k == 0)
    return 1;
  if (k == 1)
    return n;
  int ax = exp(n, k / 2);
  ax = mod(ax * ax);
  if (k % 2)
    ax = mod(ax * n);
  return ax;
}

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

int v[5005], p[5005];
bool vis[5005];
int dep[5005], cst[5005];

int start, cost, sizez;
void go(int u, int d, int c)
{
  vis[u] = true;
  dep[u] = d;
  cst[u] = c;
  if (vis[p[u]])
  {
    start = p[u];
    sizez = d - dep[p[u]] + 1;
    cost = c - cst[p[u]] + v[p[u]];
    return;
  }
  else
  {
    go(p[u], d + 1, c + v[p[u]]);
  }
}

//#define MULTIPLE_TEST_CASE
void solution()
{
  int n, k;
  cin >> n >> k;
  int ans;
  for (int i = 1; i <= n; i++)
    cin >> p[i];
  for (int i = 1; i <= n; i++)
  {
    cin >> v[i];
    if (i == 1)
      ans = v[i];
    else
      ans = max(ans, v[i]);
  }

  for (int i = 1; i <= n; i++)
  {
    start = -1;
    cost = -1;
    sizez = -1;

    for (int i = 1; i <= n; i++)
    {
      vis[i] = false;
    }

    go(i, 0, 0);
    for (int j = 1; j <= n; j++)
    {
      if (vis[j] && dep[j] <= k && dep[j] > 0)
      {
        ans = max(ans, cst[j]);
      }
    }

    if (start == -1)
      continue;

    if (dep[start] >= k)
      continue;

    // take cycle
    int newk = k - dep[start];

    int cur = cst[start];

    int times = newk / sizez;

    times = max(0LL, times - 1);

    cur += times * cost;

    newk -= sizez * times;

    if (dep[start] != 0 || times > 0)
      ans = max(ans, cur);

    int pos = start;
    while (newk > 0)
    {
      cur += v[p[pos]];
      pos = p[pos];
      ans = max(ans, cur);
      newk--;
    }
  }
  cout << ans << endl;
}

int32_t main()
{
  DESYNC;
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  int t = 1;
#ifdef MULTIPLE_TEST_CASE
  cin >> t;
#endif
  while (t--)
    solution();
}


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

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

  ll N; cin >> N;
  vector<pair<ll, ll>> P(N);
  for (ll i = 0; i < N; i++) {
    ll a; cin >> a;
    P[i] = make_pair(a, i);
  }
  sort(P.rbegin(), P.rend());

  ll INF = 1e18;
  vector<ll> dp(N + 1, 0);
  for (ll i = 0; i < N; i++) {
    vector<ll> dp2 = dp;
    for (ll l = 0; l <= i + 1; l++) {
      ll r = N - (i - l);
      if (l > 0) dp2[l] = max(dp2[l], dp[l - 1] + P[i].first * abs(l - 1 - P[i].second));
      if (r <= N) dp2[l] = max(dp2[l], dp[l] + P[i].first * abs(r - 1 - P[i].second));
    }
    dp = dp2;
  }

  ll ans = *max_element(dp.begin(), dp.end());
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3732
my $s = <STDIN>;
my @dat = split(/ /,$s);

my $count = 0;
for(my $i=1;$i<=$dat[0];$i++){
 for(my $j=21;$j<=$dat[1];$j++){
    my @m = split(//,$j);
    if($m[1]==1 ){ next;}
    if( $i == ($m[0] * $m[1])){
      $count++;
    }
 }
}
print "$count";


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)
#define all(v) v.begin(), v.end()
#define rall(x) (x).rbegin(), (x).rend()
#define pll pair<long long, long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vc vector<char>
#define vvc vector<vc>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
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;}
//snippets:tmp,cl,cvl,cs,co,coy,con,cov,setp
const ll mod=1e9+7;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin >> n;
    if(n%1000==0) cout<<0<<endl;
    else cout<<1000-n%1000<<endl;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;
 
pair<int,char> a[100001],b[100001];
int partition(int l,int r){
    int x=a[r].first,cur=l-1;
    FOR(i,l,r)if(a[i].first<=x){
        ++cur;
        swap(a[cur],a[i]);
    }
    ++cur;
    swap(a[cur],a[r]);
    return cur;
}
void quicksort(int l,int r){
    if(l<r){
        int mid=partition(l,r);
        quicksort(l,mid-1);
        quicksort(mid+1,r);
    }
}
bool cmp(pair<int,char> a,pair<int,char> b){
    return a.first<b.first;
}
int main(){
    int n;
    cin>>n;
    rep(i,n) cin>>a[i].second>>a[i].first,b[i]=a[i];
    quicksort(0,n-1);
    stable_sort(b,b+n,cmp);
    bool flag=true;
    rep(i,n)if(a[i].second!=b[i].second) flag=false;
    if(flag) cout<<"Stable"<<endl;
    else cout<<"Not stable"<<endl;
    rep(i,n) cout<<a[i].second<<" "<<a[i].first<<endl;
    return 0;
}


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

using Graph=vector<vector<int>>;
int main(){
    int n,m;
    cin>>n>>m;
    Graph g(n);
    vector<int> d(n);
    for(int i=0;i<n-1+m;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        g[a].push_back(b);
        d[b]++;
    }

    Graph tree(n);
    queue<pair<int,int>> que;
    for(int i=0;i<n;i++){
        if(d[i]==0) que.push({-1,i});
    }
    vector<int> dp(n);
    vector<int> p(n);
    while(!que.empty()){
        auto tmp=que.front(); que.pop();
        int from=tmp.first;
        int v=tmp.second;
        // cerr<<v<<" "<<from<<endl;
        p[v]=from;
        for(auto to:g[v]){
            d[to]--;
            if(d[to]==0){
                que.push({v,to});
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<p[i]+1<<"\n";
    }

    return 0;
}

Measured memory_bytes: 9856
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

int main(){
    ll n,m;cin >> n >>m;
    UnionFind uf(n);
    rep(i,m){
        ll a,b;cin >> a >> b;a--;b--;
        if(!uf.same(a,b))uf.merge(a,b);
    }
    set<ll> st;
    rep(i,n){
        st.ins(uf.root(i));
    }
    cout << st.size()-1 <<endl;
}

Measured memory_bytes: 7684
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define ANS(ans) cout<<(ans)<<endl;


//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main() {
	
	string s;
	cin >> s;
	int n = s.size();

	cout << s[0] << n - 2 << s[n - 1] << endl;;

	return 0;
}



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

int main(){
  int N;
  cin >> N;
  int M;
  cin >> M;
  vector<int> X(N,0);
  vector<int> D(M*2);
  
  for(int i=0;i < M*2; i++){
	cin >> D.at(i);
  }
  for(int j=0;j < M*2; j++){
  	X.at(D.at(j)-1)++;
  }
  for(int k=0;k < N;k++){
  	cout << X.at(k) << endl; 
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<utility>
#include<vector>


using namespace std;



int main() {
	int n,tmp1,tmp2,size;
	int cnt_arrived=0;
	pair<int, int> ptmp;
	priority_queue<pair<int, int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
	cin >> n;
	int** mat = new int* [n];
	vector<pair<int, int>>* list_adjacent = new vector<pair<int, int>>[n];
	int* dist = new int[n];
	for (int i = 0;i < n;i++) {
		cin >> tmp1 >> size;
		for (int j = 0;j < size;j++) {
			cin >> tmp1 >> tmp2;
			list_adjacent[i].push_back(make_pair(tmp1, tmp2));
		}
		dist[i] = -1;
	}
	pq.push(make_pair(0, 0));
	while (cnt_arrived < n) {
		ptmp = pq.top();
		pq.pop();
		if (dist[ptmp.second] == -1) {
			cnt_arrived++;
			dist[ptmp.second] = ptmp.first;
			for (int i = 0;i < list_adjacent[ptmp.second].size();i++) {
				pq.push(make_pair(ptmp.first + list_adjacent[ptmp.second][i].second, list_adjacent[ptmp.second][i].first));
			}
		}
	}
	for (int i = 0;i < n;i++) {
		cout << i << " " << dist[i] << endl;
	}
}



Measured memory_bytes: 3156
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;
int main()
{
int n;
cin>>n;
int h[100000],dp[100000];
for(int i=1;i<=n;i++)
{
	cin>>h[i];
}
dp[1]=0;
dp[2]=abs(h[1]-h[2]);
for(int i=3;i<=n;i++)
{
		dp[i]=min(dp[i-1]+abs(h[i-1]-h[i]),dp[i-2]+abs(h[i-2]-h[i]));
}
	cout<<dp[n]<<endl;	
	return 0;
}

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

int main() {
	long long n, a, b, ans;
	
	cin >> n >> a >> b;
	
	if ((b - a) % 2 == 0) {
		ans = (b - a) / 2;
	}
	else {
		if (a - 1 < n - b) {
			ans = (a - 1) + (b - a - 1) / 2 + 1;
		}
		else {
			ans = (n - b) + (b - a - 1) / 2 + 1;
		}
	}
	
	cout << ans << endl;
}


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

using namespace std;
using DP = map<pair<int, int>, long>;
vector<int> x;
map<pair<int, int>, bool> seen;

long calculate(DP& dp, int n, int s){
    auto p = make_pair(n, s);
    if (seen[p] == true) return dp[p];
    if (n == 0 && s == 0){
        dp[p] = 1;
    }else if (n > 0){
        dp[p] = calculate(dp, n-1, s) + calculate(dp, n-1, s-x[n-1]);
    }else{
        dp[p] = 0;
    }
    seen[p] = true;
    return dp[p];
}

int main(){
    int N, A;
    cin >> N >> A;
    for (int i=0; i<N; i++){
        int a; cin >> a;
        x.push_back(a-A);
    }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
    DP dp;
    
    long ans = 0;
    ans = calculate(dp, N, 0);
    cout << ans-1 << endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, init, n) for (int i = init; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

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

ll solve(ll x, ll y)
{
    if(x == 0 || y == 0) return 0;

    if(x < y && y % x == 0) return (y / x) * x * 2 - x;
    if(y < x && x % y == 0) return (x / y) * y * 2 - y;

    if(x < y)
        return solve(x, y - (y / x) * x) + (y / x) * x * 2;
    else if(x > y) 
        return solve(x - (x / y) * y, y) + (x / y) * y * 2;
    else 
        return x;
}

int main()
{
    ll N, X;
    cin >> N >> X;

    cout << N + solve(N - X, X) << endl;


    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#define Re register int

int N,A[100005],B[100005],C[100005],f[100005][3];

template <typename T> inline void read(T &var)
{
	T x=0; int w=0; char ch=0;
	while (!isdigit(ch)) w|=ch=='-',ch=getchar();
	while (isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	var=w?-x:x;
}
inline int max(int a,int b) {return a>b?a:b;}
int main(int argc, char const *argv[])
{
	read(N); for (Re i=1; i<=N; ++i)
		read(A[i]),read(B[i]),read(C[i]);
	for (Re i=1; i<=N; ++i)
	{
		f[i][0]=max(f[i-1][1],f[i-1][2])+A[i];
		f[i][1]=max(f[i-1][0],f[i-1][2])+B[i];
		f[i][2]=max(f[i-1][0],f[i-1][1])+C[i];
	} printf("%d\n",max(f[N][0],max(f[N][1],f[N][2])));
	return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>
#include <cstdio>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>()>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
#define mp make_pair
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
string stin(){string s;cin>>s;return s;}
ll lin(){ll x;scanf("%lld",&x);return x;}
int main(){
    int n=in(),k=in();
    cout<<n+1-k<<endl;
}

Measured memory_bytes: 256
$L=0,$|=$R=10,$_=${print("? ",($_*10+($M=$L+$R>>1))*1e9,$/),<>=~Y?$R:$L=$M while$R-$L>1;_}*10+$L while$i++<9;
$_++;s/0*$//;
print"? ",$_+1,$/;
if(<>=~(/^9*$/?Y:N)){0while print("? ",($_*=10)+1,$/),<>=~N}
print"! ",$_,$/

Measured memory_bytes: 852
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define ff first
#define ss second
#define pb push_back
#define N 110

ll inv[N], fac[N], finv[N];

void make()
{
	fac[0] = fac[1] = 1;
	inv[1] = 1;
	finv[1] = finv[0] = 1;
	for(int i = 2; i < N; ++i)
	{
		fac[i] = i * fac[i - 1] % MOD;
		inv[i] = MOD - MOD/i * inv[MOD % i] % MOD;
		finv[i] = inv[i] * finv[i - 1] % MOD;
	}
}

ll C(ll n, ll k)
{
	if(n < k || n < 0) return 0;
	return fac[n] * finv[n - k] % MOD* finv[k] % MOD;
}

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


int dpf(int i, int t, int k)
{

}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin >> s;
	int n = s.size(), max = 0, l = 0;
	for (int i = 0; i < n; ++i)
	{
		l = 0;
		while(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T')
			i++, l++;
		if(l > max)
			max = l;
	}
	cout << max;
	return 0;
}

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

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;

    map<int, int> m;
    int minval = 1000000000;
    for (int i = 0; i < N; ++i) {
        int A;
        cin >> A;
        m[A]++;
        minval = min(minval, A);
    }

    cout << (N - m[minval]) / (K - 1) + ((N - m[minval]) % (K - 1) != 0 ? 1 : 0) << endl;
}

Measured memory_bytes: 4992
grid = [list(map(int, input().split(" "))) for _ in range(3)]

a = [0, 0, 0]
b = [0, 0, 0]

b[0] = grid[0][0] - a[0]
b[1] = grid[0][1] - a[0]
b[2] = grid[0][2] - a[0]

a[1] = grid[1][0] - b[0]
a[2] = grid[2][0] - b[0]

# print(a)
# print(b)

ans_date = []
for i in a:
  date = []
  for j in b:
    num = i +j
    date.append(num)
  ans_date.append(date)
# print(grid)
# print(ans_date)  
if grid == ans_date:
  print("Yes")
else:
  print("No")

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

ll mod = 1e9+7;

ll expo(ll a, ll b){
   ll ans = 1;
   while(b){
       if(b&1){
          ans = (ans*a)%mod;
       }
       a = (a*a)%mod;
       b /= 2;
   }
   return ans;
}

int lev[223456], vis[213456];
vector <int> primes;

void bfs(vector <vector <int> > &vec, int n){
    queue <int> q;
    q.push(n);
    vis[n] = 1;
    lev[n] = 0;
    while(!q.empty()){
          int n1 = q.front();
          q.pop();
          for(int i= 0; i < vec[n1].size(); i++){
              if(!vis[vec[n1][i]]){
                 q.push(vec[n1][i]);
                 vis[vec[n1][i]] = 1;
                 lev[vec[n1][i]] = lev[n1]+1;
              }
          }
    }
}
char arr[12345];

int main()
{
    int n, m;
    cin >> n >> m;
    vector <vector <int> > vec;
    vec.resize(n+1);
    while(m--){
        int u, v;
        cin >> u >> v;
        vec[u].push_back(v);
        vec[v].push_back(u);
    }
    bfs(vec, 1);
    if(vis[n] && lev[n] <= 2) cout << "POSSIBLE";
    else cout << "IMPOSSIBLE";
    return 0;
}


Measured memory_bytes: 13936