akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main()
{
  int i, j, k, v, n, a[100];

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

  for(i=1; i<n; i++)
    {
      for(k=0; k<n; k++)
	{
	  printf("%d", a[k]);
	  if(k+1<n)printf(" ");
	}
      printf("\n");
  
      v = a[i];
      j = i-1;
      while(j>=0 && a[j]>v)
	{
	  a[j+1] = a[j];
	  j--;
	}
      a[j+1] = v;
    }

  for(i=0; i<n; i++)
    {
      printf("%d", a[i]);
      if(i+1<n)printf(" ");
    }
  printf("\n");
  
  return 0;
}

Measured memory_bytes: 604
// Template
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
#include <complex>
#define rep(i, x) for (int i = 0; i < (x); ++i)
#define rng(i, x, y) for (int i = (x); i < (y); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
void solve();
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solve();
    return 0;
}

// Main Code
ll func(ll left, ll mx, ll right, ll t) {
    left *= 2; mx *= 2; right *= 2; t *= 2;
    vector<ll> speed(t + 1);
    rep(i, t + 1) speed[i] = min({left + i, mx, right + (t - i)});
    ll res = 0;
    rep(i, t) res += speed[i] + speed[i + 1];
    return res;
}

void solve() {
    int n;
    cin >> n;
    vector<ll> t(n), v(n);
    rep(i, n) cin >> t[i];
    rep(i, n) cin >> v[i];
    vector<ll> left(n, 0), right(n, 0);
    for (int i = 1; i < n; ++i) left[i] = min(left[i - 1] + t[i - 1], v[i - 1]);
    for (int i = n - 2; i >= 0; --i) right[i] = min(right[i + 1] + t[i + 1], v[i + 1]);
    ll ans = 0;
    rep(i, n) ans += func(left[i], v[i], right[i], t[i]);
    cout << ans / 8. << "\n";
    return;
}


Measured memory_bytes: 3848
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
 
using namespace std;
 
typedef pair<string,int> P;
map<string,int> M;
vector<P> V;
 
bool comp(const P p1, const P p2){
  if(p1.first.length() != p2.first.length())return p1.first.length()<p2.first.length();
  return p1.first == min(p1.first,p2.first);
}
 
int main(){
  int n;
  cin >> n;
  while(n--){
    string s;
    int a;
    cin >> s >> a;
    M[s] += a;
  }
 
  map<string,int>::iterator ite;
 
  for(ite = M.begin(); ite != M.end(); ite++){
    V.push_back(P(ite->first,ite->second));
  }
   
  sort(V.begin(),V.end(),comp);
   
  for(int i = 0; i < V.size(); i++)
    cout << V[i].first << " " << V[i].second << endl;
  return 0;
}

Measured memory_bytes: 1236
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<long double,long double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-10;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

string a,b;

int main(){
	cin>>a>>b;
	string s=a+b;
	int t=0;
	for(int i=0;i<s.size();i++) t=t*10+(s[i]-'0');
	for(int i=1;i<1000;i++) if(i*i==t){
		cout<<"Yes"<<endl;
		return 0;
	}
	cout<<"No"<<endl;
}

Measured memory_bytes: 384
from collections import deque
 
H,W = map(int,input().split())
 
N = H*W
 
data = ["#" * (W+2)]
for i in range(H):
  data.append("#"+input()+"#")
data.append("#" * (W+2))
 
offsets = [(0,1),(0,-1),(1,0),(-1,0),]
 
tree = {}
for i in range(1,H+1):
  for j in range(1,W+1):
    if data[i][j] != ".":
      pass
    else:
      tree[(i,j)] = []
      for o in offsets:
        i_ = i+o[0]
        j_ = j+o[1]
        if data[i_][j_] == "." :
          tree[(i,j)].append((i_,j_))


nodes = list(tree.keys())
  
FARTHEST = 0



for start_node in nodes:
  d = [[9999999]*(W+2) for _ in range(H+2)]
  # キューを作成して初期ノード(root)を入れる
  q = deque()
  q.append(start_node)
  d[start_node[0]][start_node[1]] = 0
  res = 0 

  # キューが空になるまで繰り返す
  while len(q) > 0:
    
      # キューの先頭（左端）からnodeを取り出す
      node = q.popleft()
      if node is not None:
          nd = d[node[0]][node[1]] + 1
          childs = tree[node]
          for child in childs:
            if nd < d[child[0]][child[1]]:
              d[child[0]][child[1]] = nd
              res = nd
              q.append(child)
 
      if FARTHEST < res:
        FARTHEST = res
      
print(FARTHEST)

Measured memory_bytes: 44396
#include <array>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <stack>
using namespace std;

constexpr int H = 12;
constexpr int W = 6;
typedef array<string, H> field;

constexpr array<int, 4> dx{1, -1, 0, 0};
constexpr array<int, 4> dy{0, 0, 1, -1};

inline bool out(int x, int y) {
	return x < 0 || y < 0 || x >= W || y >= H;
}

void fall(field &state) {
	for(int x = 0; x < W; ++x) {
		for(int y = 1; y < H; ++y) {
			if(state[y][x] == '.') {
				for(int ny = y - 1; ny >= 0; --ny) {
					if(state[ny][x] == '.') break;
					swap(state[ny][x], state[ny + 1][x]);
				}
			}
		}
	}
}

field puyo_puyo(const field &state) {
	field res(state);

	vector<vector<int>> label(H, vector<int>(W, -1));
	vector<int> cnt(H * W, 0);
	int next_index = 0;

	for(int i = 0; i < H; ++i) {
		for(int j = 0; j < W; ++j) {
			if(label[i][j] == -1 && res[i][j] != 'O' && res[i][j] != '.') {
				stack<pair<int, int>> sta;
				sta.push({j, i});
				label[i][j] = next_index++;

				while(!sta.empty()) {
					const int x = sta.top().first, y = sta.top().second;
					sta.pop();
					++cnt[label[y][x]];

					for(unsigned d = 0; d < dx.size(); ++d) {
						const int nx = x + dx[d], ny = y + dy[d];
						if(out(nx, ny)) continue;
						if(res[ny][nx] == res[y][x] && label[ny][nx] == -1) {
							sta.push({nx, ny});
							label[ny][nx] = label[y][x];
						}
					}
				}
			}
		}
	}

	for(int i = 0; i < H; ++i) {
		for(int j = 0; j < W; ++j) {
			if(label[i][j] != -1 && cnt[label[i][j]] >= 4) {
				res[i][j] = '.';
				for(unsigned d = 0; d < dx.size(); ++d) {
					const int nx = j + dx[d], ny = i + dy[d];
					if(out(nx, ny)) continue;
					if(res[ny][nx] == 'O') res[ny][nx] = '.';
				}
			}
		}
	}

	fall(res);
	return res;
}

int solve() {
	field current;
	for(auto &line : current) cin >> line;

	for(int i = 0;; ++i) {
		field next = puyo_puyo(current);
		if(next == current) return i;
		current = move(next);
	}
}

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

	int t;
	cin >> t;
	while(t--) cout << solve() << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
ll mod = 1000000007;
ll INF = 1000000099;



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

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	char str[10], board[3][3], result;
	int i, f;
	
	while (scanf("%s", str) != EOF){
		f = 0;
		
		for (i = 0; i < 9; i++){
			board[i / 3][i % 3] = str[i];
		}
		
		if ((board[0][0] == board[1][1] && board[1][1] == board[2][2] || board[0][2] == board[1][1] && board[0][2] == board[2][0]) && board[1][1] != 's'){
			result = board[1][1];
			f = 1;
		}
		else {
			for (i = 0; i < 3; i++){
				if (((board[i][0] == board[i][1] && board[i][1] == board[i][2]) || (board[0][i] == board[1][i] && board[1][i] == board[2][i])) && board[i][i] != 's'){
					result = board[i][i];
					f = 1;
					break;
				}
			}
		}
		
		if (f == 0){
			result = 'd';
		}
		
		printf("%c\n", result);
	}
	
	return (0);
}

Measured memory_bytes: 540
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
#define all(a) (a).begin(),(a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0;i < (n);i++)
#define rep2(i,n) for(ll i = 0;i < (n);i++)
#define rep3(i,a,b) for(ll i = (a);i < (b);i++)
#define rep4(i,a,b,c) for(ll i = (a);i < (b);i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n)-1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n)-1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (a)-1;i >= (b);i--)
#define rrep4(i,a,b,c) for(ll i = (a)-1;i >= (b);i -= (c))
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define SHOW(x) cout << #x << ": " << x << endl;
template<class T> ll sumArr(const T& a){ return accumulate(all(a), 0LL);}
template<class T> auto minArr(const T& a){ return *min_element(all(a));}
template<class T> auto maxArr(const T& a){ return *max_element(all(a));}
template<class T> void DEBUG_PRINT(T tmp){cout<<tmp<<endl;}
template<class T1,class... T2> void DEBUG_PRINT(T1 tmp,T2... tmp2){cout<<tmp<<" ";DEBUG_PRINT(tmp2...);}
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;

int dp[2][2020];

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

    string s;
    cin>>s;
    ll ans = 0;
    dp[0][s[0] - '0'] = 1;
    rep(i,1,s.size()){
        int dig = s[i] - '0';
        rep(j,2020)dp[i%2][j] = 0;
        dp[i%2][dig]++;
        rep(j,2019){
            dp[i%2][(dig + j * 10) % 2019] += dp[(i-1)%2][j];
            if((dig + j * 10) % 2019 == 0)ans+= dp[(i-1)%2][j];
        }
    }
    cout<<ans<<endl;

    return 0;
}


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

const int MAX = 100000;

int n;
int a[MAX], p[MAX];

int main(void) {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        p[a[i]]++;
        p[a[i]+1]++;
        p[a[i]+2]++;
    }
    int ans = 0;
    for (int i = 0; i < sizeof(p) / sizeof(p[0]); i++)
    {
        ans = max(ans, p[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <bitset>
#include <utility>
#include <complex>
#include <assert.h>
#include <limits.h>
#include <iomanip>
//#include <bits/stdc++.h>
using namespace std;
#define rank rankk
#define mp make_pair
#define pb push_back
#define xo(a,b) ((b)&1?(a):0)
#define tm tmp

//#define LL ll
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,int> pli;
typedef pair<int,ll>pil;
typedef pair<ll,ll> pll;
//const double INF=1e20;
const int INF=0x3f3f3f3f;
//const int INF= 0x7fffffff;
//const ll INF=0x3f3f3f3f3f3f3f3fll;
const ll INFF=0x3f3f3f3f3f3f3fll;
//const ll INFF=1e14+5;
const int MAX=4e5+5;
//const ll MAXN=2e8;
//const int MAX_N=MAX;
const ll MOD=1e9+7;
//const ll MOD=998244353;
//const long double pi=acos(-1.0);
//const double eps=0.00000001;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
//#define double long double
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
inline ll powMM(ll a,ll b,ll M){
    ll ret=1;
    a%=M;
//    b%=M;
    while (b){
        if (b&1) ret=ret*a%M;
        b>>=1;
        a=a*a%M;
    }
    return ret;
}
//const long double eps=-1.0;
//clock_t t1 = clock();
//fprintf(stderr, "%ld ms\n", clock() - t1);
void open()
{
    freopen("in2.txt","r",stdin);
    freopen("out2.txt","w",stdout);
}
const int MAXN=1e6+5;
ll fi[MAXN],inv[MAXN];
ll quick(ll a,ll b)
{
    ll an=1LL;
    while(b)
    {
        if(b&1)
        {
            an=an*a%MOD;
        }
        a=a*a%MOD;
        b/=2;
    }
    return an%MOD;
}
ll C(ll a,ll b)
{
    if(a<0||b<0||b>a)
        return 0LL;
    return (fi[a]*inv[b]%MOD)*inv[a-b]%MOD;
}
ll n;
int main()
{

    for(ll i=0;i<=1000000;i++)
        fi[i]=i?(fi[i-1]*i%MOD):1;
    inv[1000000]=quick(fi[1000000],MOD-2);
    for(ll i=1e6-1;i>=0;i--)
        inv[i]=(i+1)*inv[i+1]%MOD;
    scanf("%lld",&n);
    ll an=fi[n-1]*(n-1LL)%MOD;
    for(ll k=(n+1)/2LL;k<n-1;k++)
        an=(an+MOD-(C(k-1,n-k-1)%MOD*fi[k]%MOD*fi[n-k-1]%MOD))%MOD;
    printf("%lld\n",an);

}

/*



4 1 1 3 1 5 5 1 3
*/


Measured memory_bytes: 15872
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, d[60];

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> d[i];
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            sum += d[i]*d[j];
        }
    }
    cout << sum << E;
    system("pause");
    return 0;
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
int dp[100005];
int ind[100005]={0};

vector<int> v[100005];
int solve(int i){

    if(dp[i]!=-1){
        return dp[i];
    }
    bool leaf=1;
    int maxchild=0;
    for(auto child: v[i]){
        leaf=0;
        maxchild=max(maxchild,solve(child));
    }
    return dp[i]=leaf ? 0 : 1+maxchild; 
}
int main(){
    int n,m;
    cin>>n>>m;
    memset(dp,-1,sizeof(dp));
    
    int x,y;
    for(int i=1;i<=m;i++){
        cin>>x>>y;
        v[x].push_back(y);
        ind[y]+=1;
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        ans=max(ans,solve(i));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 8576
#include <iostream>
#include <cstdlib>
#include <queue>
#include <set>
#include <map>

using namespace std;

struct state {
  pair< int, int > pos;
  int steps;
  state( pair<int, int>pos, int steps) {
    this->pos = pos;
    this->steps = steps;
  }
};

int main() {
  while( 1 ) {
    bool vw[ 35 ][ 35 ];
    bool hw[ 35 ][ 35 ];

    int w, h;
    cin >> w >> h;
    if( !w && !h ) {
      break;
    }
    for( int j = 0; j <= w; j++ ) {
      hw[ h ][ j ] = true;
      hw[ 0 ][ j ] = true;
    }
    for( int i = 0; i < h; i++ ) {
      // v
      vw[ i ][ 0 ] = true;
      for( int j = 1; j < w; j++ ) {
        cin >> vw[ i ][ j ]; // false: 0, true: other
      }
      vw[ i ][ w ] = true;

      // h
      if( i != h - 1 ) {
        for( int j = 0; j < w; j++ ) {
          cin >> hw[ i + 1 ][ j ];
        }
      }
    }
    
    queue< state > q;
    set< pair<int, int> > s;
    q.push( state( pair<int,int>( 0, 0 ), 0 ) );
    int ans = 0;
    while( !q.empty() ) {
      state st = q.front();
      q.pop();
      if( s.find( st.pos ) != s.end() ) {
        continue;
      }
      s.insert( st.pos );

      int i = st.pos.first;
      int j = st.pos.second;
      if( i == h - 1 && j == w - 1 ) {
        ans = st.steps + 1;
        break;
      }

      // up
      if( !hw[ i ][ j ] ) {
        q.push( state( pair<int,int>( i - 1, j ), st.steps + 1 ) );
      }

      // down
      if( !hw[ i + 1 ][ j ] ) {
        q.push( state( pair<int,int>( i + 1, j ), st.steps + 1 ) );
      }

      // left
      if( !vw[ i ][ j ] ) {
        q.push( state( pair<int,int>( i, j - 1 ), st.steps + 1 ) );
      }

      // right
      if( !vw[ i ][ j + 1 ] ) {
        q.push( state( pair<int,int>( i, j + 1 ), st.steps + 1 ) );
      }

    }

    cout << ans << endl;
  }

  return EXIT_SUCCESS;
}

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

using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
// end of Template

char x,y;
int a,b;
int main(){

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

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>x>>y;
    a=numerize(x);
    b=numerize(y);

    if(a<b)cout<<"<\n";
    else if(a>b)cout<<">\n";
    else cout<<"=\n";

}


Measured memory_bytes: 256
from sys import stdin
import numpy as np


# noinspection PyShadowingBuiltinsInspection

def main():
    N = int(input())
    S = input()
    s = S[0]
    for i in range(1, len(S)):
        if not s[-1] == S[i]:
            s += S[i]
    print(len(s))
    return


if __name__ == "__main__":
    main()

Measured memory_bytes: 12696
import scala.io.StdIn._

/**
 * ABC090B
 */
object Main extends App {

  val in = readLine().split(" ").toSeq

  val issame: (String => Boolean) = (str: String) => {
    (0 until str.length() / 2)
      .map(v => (str.charAt(v) == str.charAt(str.length() - 1 - v)))
      .forall(_ == true)
  }: Boolean

  val ans = (in(0).toInt to in(1).toInt)
    .map(_.toString)
    .count(issame)

  println(ans)
}


    

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

#define LL long long

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    LL n; cin >> n; LL a[n]; for(LL &i : a) cin >> i;
    bool b = 1; LL last=a[n-1]; 
    for(int i = 0; i < n-1; i++) {
        if(b) last -= a[i];
        else last += a[i];
        b ^= 1;
    }    
    LL ans[n]; ans[n-1] = last;
    for(int i = n - 2; i >= 0; i--) {
        ans[i] = a[i] * 2LL - ans[i+1];
    }
    for(auto x : ans) cout << x << " ";
}

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

int main() {
    string s;
    long long k;
    cin >> s >> k;
    rep(i,k){
        if(s.at(i) != '1'){
            cout << s.at(i) << endl;
            return 0;
        }
    }
    cout << 1 << endl;
}

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

int LSearch(int x,int A[],int N){
  for(int i=0;i<N;i++){
    if(A[i]==x){
      return i;
    }
  }
  return -1;
}

int main(){
  int n;
  cin >> n;
  int S[n];
  for(int i=0;i<n;i++){
    cin >> S[i];
  }

  int q;
  cin >> q;
  int T[q];
  for(int i=0;i<q;i++){
    cin >> T[i];
  }

  int ans=0;

  for(int i=0;i<q;i++){
    if(LSearch(T[i],S,n)!=-1){
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3116
import java.util.Scanner;

public class Main {

    public Main() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        long K = scanner.nextLong();

        int MAX = 0;

        long[] A = new long[N+1];
        A[0] = 0;

        for (int i = 1; i <= N; i++) {
            A[i] = scanner.nextLong() + A[i-1];
            if(A[i] <= K) MAX = i;
        }

        long T = 0;
        for (int i = 1; i <= M; i++) {
            T += scanner.nextLong();

            if(T > K) break;

            int L=-1, R = N+1;
            while(R-L > 1){
                int mid = L + (R-L)/2;
                if(T + A[mid] <= K){
                    L = mid;
                } else {
                    R = mid;
                }
            }
            if(T + A[L] <= K && MAX < i+L){
                MAX = i + L;
            }
        }

        System.out.println(MAX);
    }

    public static void main(String[] args) {
        new Main();
    }
}


Measured memory_bytes: 62388
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;


namespace atcorder2
{
    class Program
    {
        public static long Read()
        {

            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }

       
         public static long GCM(long x,long y)
        {
            if (x < y)  GCM(y, x);


            while (y > 0)
            {
                var z = y;
                y = x % y;
                x = z;
            }
            
            return x;
        }

        



        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);


            var n = Read();
            var d = Reads();
            var m = Read();
            var t = Reads();
            var dd = new Dictionary<long, long>();
            var td = new Dictionary<long, long>();
            for (int i = 0; i <n; i++)
            {
                if (dd.ContainsKey(d[i])) dd[d[i]]++;
                else dd.Add(d[i], 1);
            }
            for (int i = 0; i < m; i++)
            {
                if (td.ContainsKey(t[i])) td[t[i]]++;
                else td.Add(t[i], 1);
            }
            bool f = true;
            foreach(KeyValuePair<long,long> x in td)
            {
                if (!dd.ContainsKey(x.Key)) f = false;
                else if (dd[x.Key] < x.Value) f = false;
            }
            WriteLine(f ? "YES" : "NO");



            Console.Out.Flush();
        }
    }
}




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

char a[100][101], b[102][102];

int main() {
  int H, W;
  cin >> H >> W;


  for(int i=0; i<H; i++)
    scanf ("%s" , a [ i ]);

  for(int i = 0; i < H + 2 ; i++)
    for( int j=0; j < W + 2; j++)
      b[i][j] = '#';


  for( int i = 0; i < H; i++)
    for( int j=0; j < W; j++)
      b[i+1][j+1] = a[i][j];


  for (int i = 0; i<H + 2; i++){
    for(int j=0; j<W + 2; j++)
      cout << b[i][j];
    cout<< endl;

  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int h[100010];
int main() {
	cin>>n;
	for(int i=1;i<=n;i++)
		scanf("%d",&h[i]);
	for(int i=2;i<=n;i++) {
		if(h[i]>h[i-1]) h[i]--;
		else if(h[i]==h[i-1]) continue;
		else {
			if(h[i]-1==h[i-1]) h[i]--;
			else {
				printf("No");
				exit(0);
			}
		}
	}
	printf("Yes");
	return 0;
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using vec_b = vector<bool>;
using vec_str = vector<string>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back


int main()
{
    ll N, M, k;
    cin >> N >> M;
    vec p(M);
    vector<vec> s(M);
    REP(i,0,M) {
        cin >> k;
        ll _s;
        REP(j,0,k) {
            cin >> _s;
            s[i].pb(_s - 1);
        }
    }
    REP(i,0,M) cin >> p[i];

    ll sw, on, cnt = 0;
    bool f;
    REP(i,0,1<<N) {
        REP(j,0,M) {
            on = 0;
            f = true;
            FORR(m,s[j]) {
                if(i & (1 << m)) ++on;
            }
            if(on % 2 != p[j]) {
                f = false;
                break;
            }
        }
        if(f) ++cnt;
    }
    _PR(cnt);

    return 0;
}

/*



*/

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

struct EDGE
{
	int from, to, cost;
	bool operator < (const EDGE& t) const {
		return cost < t.cost;
	}
};

int par[100];
vector<EDGE> v;

void init()
{
	for (int i = 0; i < 100; i++) par[i] = i;
	v.clear();
}

int find(int x)
{
	if (par[x] == x) return x;
	return par[x] = find(par[x]);
}

void _union(int x, int y)
{
	x = find(x);
	y = find(y);
	if (x == y) return;
	par[x] = y;
}

bool same(int x, int y)
{
	return find(x) == find(y);
}

int main()
{
	int n, m;
	while (scanf("%d %d", &n, &m), n + m){
		init();
		
		for (int i = 0; i < m; i++){
			int a, b, c;
			scanf("%d %d %d", &a, &b, &c);
			v.push_back((EDGE){a, b, c});
			v.push_back((EDGE){b, a, c});
		}
		sort(v.begin(), v.end());
		
		int res = 0;
		for (int i = 0; i < v.size(); i++){
			EDGE& e = v[i];
			if (same(e.from, e.to)) continue;
			_union(e.from, e.to);
			res += e.cost;
		}
		
		printf("%d\n", res);
	}
	
	return 0;
}

Measured memory_bytes: 1224
#include<iostream>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	int d=0,e=0;
	if(a==5)
	{
		d++;
	}
	if(a==7)
	{
		e++;
	}
	if(b==5)
	{
		d++;
	}
	if(b==7)
	{
		e++;
	}
	if(c==5)
	{
		d++;
	}
	if(c==7)
	{
		e++;
	}
	if(d==2&&e==1)
	{
		cout<<"YES";
		return 0;
	}
	cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE TypeApplications #-}

main = do
  k <- readLn @Int
  print $ sum [ if ab == 1 then k else sum [ gcd ab c | c <- [1..k] ]
              | a <- [1..k]
              , b <- [1..k]
              , let ab = gcd a b
              ]


Measured memory_bytes: 3936
def gcd(x, y):
  if y==0: return x
  return gcd(y, x%y)
K = int(input())
res = 0
for a in range(1, K+1):
  for b in range(a, K+1):
    for c in range(b, K+1):
      if len(set([a, b, c]))==3: res += gcd(gcd(a, b), c) * 6
      elif len(set([a, b, c]))==2: res += gcd(gcd(a, b), c) * 3
      else: res += gcd(gcd(a, b), c)
print(res)

Measured memory_bytes: 9128
import math
 
K = input()
 
Sum = 0
k = int(K)
 
for A in range(k):
    a = A + 1
    for B in range(k):
        b = B + 1
        gcd_ab = math.gcd(a, b)
        for C in range(k):
            c = C + 1
 
            Sum = Sum + math.gcd(gcd_ab, c)
 
print(Sum)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
#define printvector(v,n) for(int i=1;i<=n;i++) cout<<v[i]<<" "; cout<<ln;
#define printint(v) copy(begin(v), end(v), ostream_iterator<int>(cout," "))
#define printintv(s,e) copy(s,e, ostream_iterator<int>(cout," "))
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (for ints only diff for int64)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define ln "\n"
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define RFOR(i,b,a) for(int i=b; i>=a; i--)
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define setPresent(x,s) (s.find(x)!=s.end())
typedef long long ll;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
typedef map<ll,ll> m64;
#pragma GCC optimize ("-O2")
template<class T> using min_heap = priority_queue<T, std::vector<T>, std::greater<T> >; 

int main()
{    
    ios_base::sync_with_stdio(0); cin.tie(0);
	int a[4];
	FOR(i,0,3){
		cin>>a[i];
	}
	sort(a,a+4);
	if(a[0]==1&&a[1]==4&&a[2]==7&&a[3]==9) cout<<"YES\n";
	else cout<<"NO\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const double eps=1e-9;
typedef vector<int> vi;
typedef long long ll;
int A[5],B[5];
string rule[5][5];
#define pb push_back

int main(void)
{
  for(int i=0;i<4;i++)
    {
      if(i==0)
	{
	  rule[i][0]="1",rule[i][1]="i",rule[i][2]="j",rule[i][3]="k";
	}
      if(i==1)
	{
	  rule[i][0]="i",rule[i][1]="-1",rule[i][2]="k",rule[i][3]="-j";
	}
      if(i==2)
	{
	  rule[i][0]="j",rule[i][1]="-k",rule[i][2]="-1",rule[i][3]="i";
	}
      if(i==3)
	{
	  rule[i][0]="k",rule[i][1]="j",rule[i][2]="-i",rule[i][3]="-1";
	}
    }
  int n;
  while(cin >> n && n)
    {
      for(int loop=0;loop<n;loop++)
	{
	  int i=0,j=0,k=0,num=0;
	  cin >> A[0] >> A[1] >> A[2] >> A[3] >> B[0] >> B[1] >> B[2] >> B[3];
	  for(int a=0;a<4;a++)
	    {
	      for(int b=0;b<4;b++)
		{
		  int tmp=A[a]*B[b];
		  if(rule[a][b]=="1")num+=tmp;
		  else if(rule[a][b]=="-1") num-=tmp;
		  else if(rule[a][b]=="i") i+=tmp;
		  else if(rule[a][b]=="-i") i-=tmp;
		  else if(rule[a][b]=="j") j+=tmp;
		  else if(rule[a][b]=="-j") j-=tmp;
		  else if(rule[a][b]=="k") k+=tmp;
		  else if(rule[a][b]=="-k") k-=tmp;
		}
	    }
	  cout << num << ' ' << i << ' ' << j << ' ' << k << endl;
	}
    }
  return 0;
}



Measured memory_bytes: 3116
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <map>
#include <iomanip>
#include <stdio.h>
#include <bitset>

typedef long long ll;

constexpr long long INFLL = 1e18;

using namespace std;

int main()
{
    int n;
    cin >> n;
    int ans = 0;

    for (int i = 1; i <= n; i++)
    {
        ans = 0;
        for (int a = 1; a < sqrt(i); a++)
        {
            for (int b = a; b < sqrt(i); b++)
            {
                int temp = i - a * a - b * b - a * b;
                if (temp >= 1)
                {
                    for (int c = b; c < sqrt(temp); c++)
                    {
                        if (c * c + c * (a + b) == temp)
                        {
                            if (c == a && b == a)
                            {
                                ans++;
                            }
                            else if (c != a && c != b && a != b)
                            {
                                ans += 6;
                            }
                            else
                            {
                                ans += 3;
                            }
                        }
                    }
                }
            }
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3168
H,W = map(int,input().split())
grid = [["#"]*(W+2) for i in range(H+2)]
for i in range(H):
    s = input()
    for j in range(W):
        grid[i+1][j+1] = s[j]
dp = [[0]*(W+2) for i in range(H+2)]
dp[1][1] = 1
for i in range(H):
    for j in range(W):
        if (i,j) == (0,0):
            continue
        dp[i+1][j+1] = 0
        if grid[i+1][j] == ".":
            dp[i+1][j+1] += dp[i+1][j]
        if grid[i][j+1] == ".":
            dp[i+1][j+1] += dp[i][j+1]
ans = dp[H][W] % (10**9 + 7)   
print(ans)

Measured memory_bytes: 164408
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scan = new Scanner(System.in);
		while (true) {
			int H = scan.nextInt();
			if (H == 0) {
				scan.close();
				break;
			}
			int W = scan.nextInt();

			char[][] table = new char[H][];
			for (int i = 0; i < table.length; i++) {
				table[i] = scan.next().toCharArray();
			}

			String answer = "";
			int[] dir = { -1, 0, 1 };
			@SuppressWarnings("unchecked")
			ArrayList<String>[][] parts = new ArrayList[26][201];
			for (int i = 0; i < parts.length; i++) {
				for (int j = 0; j < parts[i].length; j++) {
					parts[i][j] = new ArrayList<String>();
				}
			}

			for (int i = 0; i < table.length; i++) {
				for (int j = 0; j < table[i].length; j++) {
					for (int k = 0; k < dir.length; k++) {
						for (int l = 0; l < dir.length; l++) {
							if (dir[k] == dir[l] && dir[k] == 0) {
								continue;
							}
							int nowi = i;
							int nowj = j;
							StringBuilder builder = new StringBuilder();
							builder.append(table[nowi][nowj]);
							while (true) {
								nowi = (nowi + dir[k] + H) % H;
								nowj = (nowj + dir[l] + W) % W;

								if (nowi == i && nowj == j) {
									break;
								}

								builder.append(table[nowi][nowj]);
								if (parts[table[i][j] - 'A'][builder.length()]
										.contains(builder.toString())) {
									if (builder.length() > answer.length()) {
										answer = builder.toString();
									} else if (builder.length() == answer
											.length()) {
										if (answer
												.compareTo(builder.toString()) > 0) {
											answer = builder.toString();
										}
									}
								} else if (builder.length() >= 2) {
									parts[table[i][j] - 'A'][builder.length()]
											.add(builder.toString());
								}
							}
						}
					}

				}
			}
			if (answer.equals("")) {
				System.out.println(0);
			} else {
				System.out.println(answer);
			}
		}

	}
}

Measured memory_bytes: 256712
/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>

typedef long long LL;
typedef unsigned long long ULL;
using namespace std;

const int mxn = 1e5 + 24;
LL sum[mxn], v[mxn];

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	int n;
	cin >> n;
	memset(sum, 0, sizeof(sum));
	for(int i = 1; i <= n; i++) cin >> v[i];
	sort(v+1, v+n+1);
	sum[0] = 0;
	for(int i = 1; i <= n; i++) sum[i] = sum[i-1] + v[i];
	for(int i = n-1; i >= 1; i--) {
		if(sum[i] * 2 < v[i+1]) { cout << n - i << "\n"; return 0;}
	}
	cout << n << "\n";
	return 0;
}
/*
    input:
    output:
    modeling:
    methods:
    complexity:
    summary:
*/

Measured memory_bytes: 1792
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scanln(&s)

	fmt.Println(logic(s))
}

func logic(s string) string {
	m := make(map[string]int)
	for _, c := range s {
		m[string(c)]++
	}

	if len(m) != 2 {
		return "No"
	}

	for _, i := range m {
		if i != 2 {
			return "No"
		}
	}
	return "Yes"
}


Measured memory_bytes: 512
import Data.Char

main = getContents >>= putStrLn.show.sum.findNums

findNums :: String -> [Int]
findNums str = case num of
                    "" -> []
                    otherwise -> read num : findNums rest
  where prenum = dropWhile (not.isDigit) str
        (num,rest) = span isDigit prenum

Measured memory_bytes: 3748
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
int n;
string s;
void solve() {
	cin >> n;
	cin >> s;
	int ans = 0;
	for (int i = 1; i < n; ++i) {
		int cnt = 0;
		//check all ascii character(small)
		for (char c = 'a'; c <= 'z'; ++c) {
			bool left = false, right = false;
			//search left
			for (int j = 0; j < i; ++j) {
				if (s[j] == c) {
					left = true;
				}
			}
			//search right
			for (int j = i; j < n; ++j) {
				if (s[j] == c) {
					right = true;
				}
			}
			if (left && right) {
				cnt++;
			}
		}
		ans = cnt > ans ? cnt : ans;
	}
	cout << ans << endl;
	return;
}
//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
	  fac[i] = fac[i-1] * i % MOD;
	  inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
	  finv[i] = finv[i-1] * inv[i] % MOD;
	}
}
//組み合わせ
long long COM (int n, int k) {
	if(n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
int main(int args, char* argv[]) {
	solve();
}

Measured memory_bytes: 256
/*input
2018
218
*/
#include <bits/stdc++.h>
using namespace std;
const long long md=1e9+7;
long long a[1000005],n;

int main(){
	#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	#endif
	long long q,m,k,h,ans=0,sum=0,p,x,y;
	cin>>n>>x;
	if(n%500<=x) cout<<"Yes";
	else cout<<"No";
}

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

using namespace std;

#define endl "\n"
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define f first
#define se second
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PI 3.14159265358979323846264338327950L
#define MOD 1000000007

typedef long long ll;

void solve(){
    int x;
    cin>>x;
    int sum=0,cnt=0;
    for(int i=1;;++i){
        if(sum>=x)break;
        sum+=i;
        cnt++;
    }
    cout<<cnt<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    //int t;
    //cin>>t;
    //while(t--)
        solve();
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int a,b;
	char o;
	while(1){
		scanf("%d %c %d",&a, &o, &b);
		if(o == '?')break;
		else if(o == '+'){
			printf("%d\n",a + b);
		}else if(o == '-'){
			printf("%d\n",a - b);
		}else if(o == '*'){
			printf("%d\n",a * b);
		}else if(o == '/'){
			printf("%d\n",a / b);
		}
		}
	return 0;
}

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

using namespace std;

int n, m;
int s[1000020];

int Check(int x) {
  int count = 0;
  int level = 1;
  int index = 0;
  while (true) {
    if (level + x > s[n - 1]) {
      count++;
      break;
    }
    int maxexp = x - abs(level - s[index]);
    while(true){
        if(level + x <= s[index + 1])break;
        else{
            if(maxexp < x - abs(level - s[index + 1])){
                index++;
                maxexp = x - abs(level - s[index]);
            }else{
                break;
            }
        }
    }
    count++;
    level += max(1,maxexp);
  }
  
  return count;
}


signed main() {
  while (true) {
    cin >> n >> m;
    if (n + m == 0) {
      break;
    }
    for (int i = 0; i < n; i++)  {
        cin>>s[i];
    }
    
    int l = s[0], r = s[n-1] + 1;
    while(abs(r-l) > 1) {
      int x = (l + r) / 2;
      int check = Check(x);
      if (check >= m) {
        l = x;
      } else {
        r = x;
      }
    }

    if (Check(l) >= m) cout << l << endl;
    else cout << -1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3404
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::{i32, i64, u32, u64, f64};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{VecDeque, HashMap, BTreeMap, HashSet, BTreeSet};
#[allow(unused_imports)]
use std::io::{stdout, Write, BufWriter};
#[allow(unused_imports)]
use std::mem::{swap};

fn main() {
    input!{
        a: i32,
        b: i32,
        c: i32,
    }
    for i in 1..lcm(a, b) / a + 1 {
        if a * i % b == c {
            println!("YES");
            return;
        }
    }
    println!("NO");
}

type SomeInt = i32;
fn gcd(x: SomeInt, y: SomeInt) -> SomeInt {
    if y == 0 {
        x
    } else {
        gcd(y, x % y)
    }
}

fn lcm(x: SomeInt, y: SomeInt) -> SomeInt {
    x * y / gcd(x, y)
}


Measured memory_bytes: 4352
def checkWays(n,x)
  count = 0
  catch(:stop) do
    n.downto(1) do |n1|
      (n1-1).downto(1) do |n2|
        n3 = x - n1 - n2
        count += 1 if (n3 < n2) && (n3 > 0)
        throw :stop if (n3 > n1)
        break if (n3 > n2)
      end
    end
  end
  puts count
end

while ((n,x = gets.split(" ").map(&:to_i)) != [0,0]) do
  checkWays(n,x)
end

Measured memory_bytes: 8572
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline

h, w = map(int,input().split())
a = [list(map(int,input().split())) for i in range(h)]
b = [list(map(int,input().split())) for i in range(h)]

ab = [[0]*w for i in range(h)]
for ch in range(h):
    for cw in range(w):
        ab[ch][cw] = abs(a[ch][cw] - b[ch][cw])

ab0 = ab[0][0]
size = 80*(h+w)
dp = [[0]*w for hh in range(h)]
dp[0][0] |= 2**(size + ab0)
dp[0][0] |= 2**(size - ab0)
for ch in range(h):
    for cw in range(w):
        if ch < h-1:
            dp[ch+1][cw] |= dp[ch][cw] << ab[ch+1][cw]
            dp[ch+1][cw] |= dp[ch][cw] >> ab[ch+1][cw]
        if cw < w-1:
            dp[ch][cw+1] |= dp[ch][cw] << ab[ch][cw+1]
            dp[ch][cw+1] |= dp[ch][cw] >> ab[ch][cw+1]

a = dp[h-1][w-1]>>size
m = a&(-a)
print(m.bit_length()-1)

Measured memory_bytes: 26408
#pragma av
#include <bits/stdc++.h>

using namespace std;

#define DEBUG(...) fprintf(stderr,__VA_ARGS__)

#define rep(i , l , r) for(int i = (l) , ___ = (r) ; i <= ___ ; ++i )
#define per(i , r , l) for(int i = (r) , ___ = (l) ; i >= ___ ; --i )

// using LL = long long;
// using uLL = unsigned long long;
typedef long long LL;
typedef unsigned long long uLL;

const int Mod = 998244353; 

template<typename T>inline bool chkmin(T &x , const T &y) { return x > y ? (x = y , 1) : 0; }
template<typename T>inline bool chkmax(T &x , const T &y) { return x < y ? (x = y , 1) : 0; }

template<typename T>inline T sq(const T &x) { return x * x; }

template<typename T>inline T read(T &f)
{
    f = 0; int x = 1 ; char c = getchar();
    while(!isdigit(c)) x = (c == '-' ? -1 : 1) , c = getchar();
    while(isdigit(c)) (f *= 10) += c & 15 , c = getchar();
    return f = x * f;
}
template<typename T , typename ... Args>inline void read(T &x , Args&& ... y) { read(x) , read(y...); }

const int N = 10;

int n , k , top , vis[N] , d[N] , s[N];

int divi(int x)
{
	while(x)
	{
		if(vis[x % 10]) return 1;
		x /= 10;
	}
	return 0;
}

int main()
{
	read(n) , read(k);
	rep(i , 1 , k) vis[read(d[i])] = 1;
	while(divi(n)) n++;
	cout << n << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define what_is(x) cerr<<#x <<" is "<<x<<endl;
#define ll long long 
#define gcd(a,b) __gcd(a,b)
#define pi 2*acos(0.0)
#define endl "\n"
//use emplace_back() instead of push_back()
const ll mod=1e9+7;
template<typename T>
void print(T t)
{
    for(const auto& e:t)cout<<e<<" ";
    cout<<endl;
}
ll power(ll x, ll y, ll p) 
{ 
    int res = 1;
    x = x % p;
    while (y > 0) 
    {
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;
        x = (x*x) % p;   
    } 
    return res; 
} 
vector<int>g[1000001];
int vis[1000001];    
int in[100001];
int low[100001];
int timer=0;
vector<pair<int,int> >v;
int f;
void dfs(int n,int p)
{
    vis[n]=1;
    low[n]=in[n]=timer++;    
    if(timer!=1)v.push_back({p,n});
    for(auto ch:g[n])
    {
        if(ch==p)continue;
        if(vis[ch])
        {
            low[n]=min(low[n],in[ch]);
            if(in[n]>in[ch])v.push_back({n,ch});
        }
        else
        {
            dfs(ch,n);
            if(in[n]<low[ch]){f=1;return;}            
            low[n]=min(low[n],low[ch]);
        }
    }    
}
ll josephus(ll n) 
{
    ll p = 1; 
    while (p <= n) 
        p *= 2; 
    return (2 * n) - p + 1; 
}

bool isprime(ll n)
{
    if(n==1)return false;
    for(ll i=2;i*i<=n;i++)
    if(n%i==0)return false;
    return true;
}
vector<ll>aa;
void printallpf(ll n)
{
    for(ll i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            while(n%i==0)
            {
                aa.push_back(i);
                if(i!=n/i)
                if(isprime(n/i))aa.push_back(n/i),n=i;
                n=n/i;
            }
            
        }
    }    
}
void primeFactors(int n)  
{
       while (n % 2 == 0)  
    {  
        cout << 2 << " ";  
        n = n/2;  
    }  
  for (int i = 3; i <= sqrt(n); i = i + 2)  
    {    
        while (n % i == 0)  
        {  
            cout << i << " ";  
            n = n/i;  
        }  
    }
    if (n > 2)  
        cout << n << " ";  
}  
int dsu[100001];
void dsuunion(int u,int v)
{
	dsu[v]+=dsu[u];
	dsu[u]=v;
}
ll find(int a)
{
	if(dsu[a]<0)return a;
	else
	return dsu[a]=find(dsu[a]);
}
ll nod(ll x)
{
	ll cnt=0;
	while(x)
	{
		x=x>>1;
		cnt++;
	}
	return cnt;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin>>s;
    if(s=="ABC")
    cout<<"ARC\n";
    else
    cout<<"ABC\n"; 
	
    return 0;
}


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

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


Measured memory_bytes: 256