akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
};

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main() {
    string s; cin >> s;
    int K; cin >> K;
 
    ll n = s.size();
    REP(i,n){
        int d = 'z' - s[i] + 1;
        if(i != n-1){
            if(s[i] == 'a') continue;
 
            if(d <= K){
                s[i] = 'a';
                K -= d;
            }
        } else {
            K %= 26;
            if(K < d) s[i] = (char)(s[i]+K);            
            else s[i] = (char)('a' + K - d);
        }
    }
    std::cout << s << endl;

    return 0;
}

Measured memory_bytes: 512
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); bool s=false; if(c=='-'){s=true;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); int s=0; if(c=='-'){s=1;c=getchar_unlocked();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }

int f[55]={11,31,41,61,71,101,131,151,181,191,211,241,251,271,281,311,331,401,421,431,461,491,521,541,571,601,631,641,661,691,701,751,761,811,821,881,911,941,971,991,1021,1031,1051,1061,1091,1151,1171,1181,1201,1231,1291,1301,1321,1361,1381};
int main(void){
	int n=nextint();
	for(int i=0; i<n; i++){
		printf("%d ", f[i]);
	}
	putchar(10);
}


Measured memory_bytes: 128
import std.stdio;
import std.array;
import std.string;
import std.algorithm;
import std.conv;

int[] g;

int insertionSort(ref int[] arr, int n, int g) {
  int cnt = 0;
  for (auto i = g; i < n; i++) {
    int v = arr[i];
    int j = i - g;
    while (j >= 0 && arr[j] > v) {
      arr[j+g] = arr[j];
      j = j - g;
      cnt++;
    }
    arr[j+g] = v;
  }
  return cnt;
}

int shellSort(ref int[] arr, int n) {
  int cnt = 0;
  int n_ = n;
  do {
    int g_ = n_ / 2;
    g ~= g_;
    n_ -= g_;
  } while (n_ != 1);
  for (auto i = 0; i < g.length; i++) {
    cnt += insertionSort(arr, n, g[i]);
  }
  return cnt;
}

void main(string[] args)
{
  int n = to!int(strip(readln()));
  int[] arr;
  for (int i = 0; i < n; i++) arr ~= to!int(strip(readln()));
  int cnt = shellSort(arr, n);
  writeln(g.length);
  writeln(join(g.map!(text), " "));
  writeln(cnt);
  foreach(i; arr) { writeln(i); }
}

Measured memory_bytes: 7152
package main

import (
        "fmt"
        "math"
)

func main() {
        var (
                n, t, a int
                nearest int
        )
        minDiff := math.MaxFloat64
        fmt.Scan(&n, &t, &a)
        base := float64(a - t)
        for i := 0; i < n; i++ {
                var tmp int
                fmt.Scan(&tmp)
                diff := math.Abs(base + float64(tmp)*0.006)
                if diff < minDiff {
                        minDiff = diff
                        nearest = i + 1
                }
        }
        fmt.Printf("%d\n", nearest)
}

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

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

    double t, x;
    cin >> t >> x;

    printf("%.10f\n", t/x);
}

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

int main(){
#ifdef _DEBUG
	freopen("in" , "r", stdin );
	freopen("out", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0);
	double a, b, c; cin >> a >> b >> c;
	cout << (int)((a + b) / 2.0 * c) << '\n';
}


Measured memory_bytes: 3680
#include <cstdio>

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

    int nine_present = false;
    while(n > 0)
    {
        if(n%10 == 9)
            nine_present = true;
        n = n/10;
    }

    printf(nine_present ? "Yes\n" : "No\n");
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 100005
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}
using namespace std;
typedef long long LL;
int n;
char in[M],tmp[M];
bool check(int t1,int t2)
{
	tmp[1] = t1;
	tmp[2] = t2;
 
	REP(i,2,n-1)
	{
		if(in[i]=='o')
			tmp[i+1] = tmp[i-1] ^ (tmp[i]?0:1);
		else
			tmp[i+1] = tmp[i-1] ^ (tmp[i]?1:0);
	}
	
	//1
	bool ans = (tmp[n]==tmp[2]) == (in[1]=='o');
	if(tmp[1] != ans) return false;
 
	ans = (tmp[n-1]==tmp[1]) == (in[n]=='o');
	if(tmp[n]!=ans) return false;
	
	return true;
}
int main()
{
	bool flg;
	while(~scanf("%d",&n))
	{
		flg = false;
		scanf("%s", in+1);
 
		REP(i,0,1)
		{
			if(flg) break;

			REP(j,0,1) if( check(i,j) )
			{
				flg = true;
				break;
			}
		}
 
		if(!flg) puts("-1");
		else
		{
			REP(i,1,n) printf("%c", tmp[i]?'S':'W');
			puts("");
		}
	}
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
using ll = long long;

int main(){
    ll N,M,X;
    cin >> N >> M >> X;
    vector<ll> C(N);
    vector<vector<ll>> A(N, vector<ll>(M));
    for(int i=0; i<N; i++){
        cin >> C.at(i);
        for(int j=0; j<M; j++){
            cin >> A.at(i).at(j);
        }
    }
    ll min=10000000;
    for(ll i=0; i<pow(2,N); i++){
        vector<int> list(N);
        ll num=i;
        for(int j=0; j<N; j++){
            list.at(N-1-j)=num%2;
            num = num/2;
        }
        ll sum=0;
        vector<ll> know(M,0);
        for(int j=0; j<N; j++){
            if(list.at(j)==1){
                sum+=C.at(j);
                for(int k=0; k<M; k++){
                    know.at(k) += A.at(j).at(k);
                }
            }
        }
        bool check=true;
        for(int j=0; j<M; j++){
            if(know.at(j)<X) check=false;
        }
        if(check){
            if(sum<min) min = sum;
        }
    }
    if(min == 10000000) cout << -1;
    else cout << min;

    return 0;
}

Measured memory_bytes: 4112
#include <stdio.h>
int main(void)
{
    int m,f,r,t;
    for(;;){
        scanf("%d %d %d",&m,&f,&r);
        t=m+f;
        if(m+f+r==-3) return 0;
        if(m==-1||f==-1) puts("F");
        else if(t>=80) puts("A");
        else if(t>=65) puts("B");
        else if(t>=50||r>=50) puts("C");
        else if(t>=30) puts("D");
        else puts("F");
    }
    return 0;
}


Measured memory_bytes: 2136
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;

#define rep(i,n)  for(int i = 0; i < (int)(n);    i++)
#define sz(x)     ((int)(x).size())
#define all(x)    (x).begin(),(x).end()

using ll = long long;

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 * b / gcd(a, b); }

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  std::string S; std::cin >> S;
  const int n = sz(S);

  std::unordered_map<int,int> map;
  map[0] = 1;
  int tens = 1;
  std::vector<int> T(n+1);
  ll ans = 0;
  for(int i=n-1; i>=0; i--) {
    int t = S[i] - '0';
    T[i] = (tens * t + T[i+1]) % 2019;
    tens *= 10; tens %= 2019;
    ans += map[T[i]];
    map[T[i]]++;
  }
  std::cout << ans << std::endl;
  return 0;
}



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

int main(){
  int n;
  string s, t;
  cin >> n;
  std::cin >> s >> t;
  rep(i, n){
    std::cout << s.at(i) << t.at(i);
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;

int n,m,ans;
int x[111],y[111],h[111];
int cnt[111][111];
int ke[111][111];
signed main(){
	
	cin>>n;
	rep(i,n)cin>>x[i]>>y[i]>>h[i];
	
	rep(i,101){
		rep(j,101){
			int maxh=INF*2,H=-1;
			bool f=true;
			rep(k,n){
				if(h[k]==0){
					maxh=min(maxh,abs(x[k]-i)+abs(y[k]-j));
				}
				else{
					if((H!=-1 && H!=h[k]+abs(x[k]-i)+abs(y[k]-j)) || h[k]+abs(x[k]-i)+abs(y[k]-j)<1){
						f=false;
						break;
					}
					else H=h[k]+abs(x[k]-i)+abs(y[k]-j);
				}
			}
			if(maxh>=H && f){
				cout<<i<<" "<<j<<" "<<H<<endl;
				return 0;
			}
		}
	}
	
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {    
    int k; string s; cin >> k >> s;
    if(s.size() <= k) cout << s << ln;
    else{
        string t = s.substr(0,k) + "...";
        cout << t << ln;
    }
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <list>
#include <set>
using namespace  std;

#define int long long int

constexpr int INF = std::numeric_limits<int>::max();

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, K;
    cin >> A >> B >> K;

    for (int i= 100; i > 0; i--) {
        if (A % i == 0 && B % i == 0) {
            K--;
            if (K == 0) {
                cout << i << endl;
            }
        }
    }
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var array = Console.ReadLine().Split().ToArray();
            var S = array[0];
            var T = array[1];

            var sb = new StringBuilder();

            for (int i = 0; i < N; i++)
            {
                sb.Append(S[i]);
                sb.Append(T[i]);
            }

            Console.WriteLine(sb.ToString());
        }
    }
}


Measured memory_bytes: 13268
#include <cstdio>
#include <cstring>
#include <queue>

using namespace std;
int g[101][101], d[101];
bool vis[101];
int dis = 0, n;

void bfs(int u)
{
  queue<int> Q;
  Q.push(u);
  vis[u] = true;
  d[u] = 0;
  while (!Q.empty())
  {
    int tmp = Q.front();
    Q.pop();
    for (int i = 0; i < n; i++)
    {
      if (g[tmp][i] != 0 && !vis[i])
      {
        vis[i] = true;
        Q.push(i);
        d[i] = d[tmp] + 1;
      }
    }
  }
}

int main()
{
  memset(g, 0, sizeof(g));
  memset(d, -1, sizeof(d));
  memset(vis, false, sizeof(vis));
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
  {
    int u, adj_num;
    scanf("%d%d", &u, &adj_num);
    while (adj_num--)
    {
      int v;
      scanf("%d", &v);
      g[u - 1][v - 1] = 1;
    }
  }
  bfs(0);
  for (int i = 0; i < n; i++)
  {
    printf("%d %d\n", i + 1, d[i]);
  }
}



Measured memory_bytes: 2764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll a;
  cin >> a;
  if(a<1200) cout << "ABC" << endl;
  else if(a<2800) cout << "ARC" << endl;
  else cout << "AGC" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  static char[] s, t;

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    s = sc.next().toCharArray();
    t = sc.next().toCharArray();

    int last = -1;
    for(int i = 0; i + t.length - 1 < s.length; i++){
      boolean match = true;
      for(int j = 0; j < t.length; j++){
        if(s[i + j] == '?'){
          continue;
        }
        if(s[i + j] != t[j]){
          match = false;
          break;
        }
      }
      if(match){
        last = i;
      }
    }

    if(last == -1){
      System.out.println("UNRESTORABLE");
      return;
    }

    for(int i = 0; i < s.length; i++){
      if(s[i] == '?'){
        s[i] = 'a';
      }
    }
    for(int i = 0; i < t.length; i++){
      s[last + i] = t[i];
    }

    System.out.println(s);
  }
}

Measured memory_bytes: 22484
S = input()
a = [0] * (len(S) + 1)

for i in range(len(S)):
    if S[i] == '<':
        a[i + 1] = max(a[i + 1], a[i] + 1)
for i in reversed(range(len(S))):
    if S[i] == '>':
        a[i] = max(a[i], a[i + 1]+1)
ans = sum(a)

print(ans)

Measured memory_bytes: 23336
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
      int N;
      string S;
      cin >> N;
      cin >> S;

      int index;
      vector<int> init(26);
      for (int i=0; i<26; i++)
            init[i] = 0;
      vector<vector<int > > vv(0);
      vv.push_back(init);

      vector<vector<int > > vtmp;
      vector<int> l, r(26);

      for (int i=0; i<N; i++){
            vv.push_back(vv[i]);
            index = S[i] - 97;
            //cout << index <<endl;
            vv[i+1][index] += 1;
      }

      int max = 0;
      int count = 0;
      for (int i=0; i<N+1; i++){
            l = vv[i];
            std::transform(vv[N].begin(), vv[N].end(), l.begin(), r.begin(), std::minus<int>());
            count = 0;
            //cout << i <<endl;
            for (int j=0; j<26; j++){
                  if (l[j] > 0 && r[j] > 0)
                        count += 1;
            }
            if (max < count)
                  max = count;
      }
      
      cout << max << endl;
      return 0;
}

      


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

using namespace std;

int main(){
	int i,n,ans,a[100010],b;
	pair<int, int> p[100010];
	cin >> n;
	for(i=0;i<n;i++){
		cin >> b;
		p[i] = make_pair(b,i);
	}
	
	sort(p, p+n);
	for(i=0;i<n;i++){
		if(i%2==0){
			a[p[i].second] = 0;
		}else{
			a[p[i].second] = 1;
		}
	}

	ans = 0;
	for(i=0;i<n;i++){
		if((a[i]+i)%2==1){
		ans += 1;
		}
	}
	
	cout << ans/2 << endl;
}

Measured memory_bytes: 1408
N=int(input())
XY=[list(map(int,input().split())) for i in range(N)]
value=0
for i in range(N):
    for m in range(i+1,N):
        x0,y0,x1,y1=XY[i][0],XY[i][1],XY[m][0],XY[m][1]
        value+=(((x0-x1)**2+(y0-y1)**2)**0.5)
print(value*2/N)


Measured memory_bytes: 38256
#include <stdio.h>
int main(){
    int a, b, c;
    int i = 0;
    scanf("%d %d %d", &a, &b, &c);
    while(a<=b){
      if(c%a == 0){
        i += 1;
      }else{
        i += 0;
      }
      a++;
    }
    printf("%d\n", i);
    return 0;
}



Measured memory_bytes: 2092
# 葉ノードが3つ以上あると、一筆で通過できない
# -> 道が1本以下(0含む)の町が3つ以上あると、一筆で通過できない
# 前提: 2つの町の間に存在する道は複数ない

path_list = [list(map(int, input().split())) for _ in range(3)]
path = {}
for p in path_list:
    if not p[0] in path:
        path[p[0]] = []
    path[p[0]].append(p[1])
    if not p[1] in path:
        path[p[1]] = []
    path[p[1]].append(p[0])
count = 0
for k, v in path.items():
    if 2 > len(v):
        count += 1
print("YES" if 3 > count else "NO")

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int x = scanner.nextInt(),a = scanner.nextInt(),b = scanner.nextInt();
		if(Math.abs(x - a) < Math.abs(x - b)){
			System.out.println("A");
		}else{
			System.out.println("B");
		}
	}

}


Measured memory_bytes: 20948
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
inline int read(){
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9'){ if(ch == '-') f = -1; ch = getchar(); }
	while(ch >= '0' && ch <= '9'){ x = x * 10 + (ch ^ 48); ch = getchar(); }
	return x * f;
}
int n, m, k, x, a[110], ans; 
int main(){
	n = read(); m = read();
	for(int i = 1; i <= m; ++i){
		k = read();
		for(int j = 1; j <= k; ++j){
			x = read();
			a[x]++;
		}
	}
	for(int i = 1; i <= n; ++i) if(!a[i]) ans++;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3720
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

typedef long long ll;

int main(){

	string s;

	cin >> s;
	int count = 0;

	for (int i = 0; i < 3; i++)
	{
		if(s[i] == '1') count += 1;
	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int n,q;
	scanf("%d %d\n",&n,&q);
	char s[n];
	int count[n],l[q],r[q];
  	count[0]=0;
	for (int i = 0; i < n; i++){
		scanf("%c\n",&s[i]);
	}
	for (int j = 0; j < n; j++){
		if (s[j]=='A' && s[j+1]=='C')
		{
			count[j+1] = count[j] + 1;
		}else{
			count[j+1] = count[j];
		}
	}
	for (int i = 0; i < q; i++)
	{
		scanf("%d %d\n",&l[i] ,&r[i]);
		printf("%d\n",count[r[i]-1]-count[l[i]-1] );
	}
	return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
long long n,m;
const long long N=1e5+5;
bool vs[N];
vector<long long> adj[N];
vector<long long> nadj[N];
vector<pair<long long,long long> > ans;
long long odd[N];
vector<pair<long long, long long> > inp;
map<long long, map<long long, long long> > edge;
void dfs(long long e){
	vs[e]=true;
	for(auto x: adj[e]){
		if(vs[x]==false){
			edge[e][x]=1;
			edge[x][e]=1;
			dfs(x);
			nadj[e].push_back(x);
		}
	}
}
void DFS(long long e, long long par){
	vs[e]=true;
	for(auto x: nadj[e]){
		DFS(x,e);
	}
	if(odd[e]==0&&e!=1){
		odd[par] = (odd[par]+1)%2;
		ans.push_back({par,e});
	}
	else if(e!=1&&odd[e]==1){
		odd[e] = (odd[e]+1)%2;
		ans.push_back({e,par});
	}
}
signed main(){
	cin >> n >> m;
	for(int i=1;i<=m;i++){
		long long a,b;
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
		inp.push_back({a,b});
	}
	if(m%2==1){
		cout << "-1";
		return 0;
	}
	dfs(1);
	for(auto x:inp){
		if(edge[x.fi][x.se]==0){
			odd[x.fi] = (odd[x.fi]+1)%2;
			ans.push_back({x.fi,x.se});
		}
	}
	memset(vs,false,sizeof(vs));
	DFS(1,1);
	if(odd[1]==1){
		cout << "-1";
	}
	else{
		for(auto x : ans){
			cout << x.fi << " " << x.se<<endl;
		}
	}
}

Measured memory_bytes: 47984
#include <stdio.h>

main(){

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

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define int long long
#define lint long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e,v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

int N;
int P[100010];
int invP[100010];
set<int> S;
int ans = 0;

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    cin >> N;
    REP(i, N) {
        cin >> P[i + 1];
        invP[P[i + 1]] = i + 1;
    }
    S.insert(0);
    S.insert(N + 1);
    for (int i = N; i >= 1; i--) {
        int j = invP[i];
        assert(1 <= j && j <= N);
        int L = *(--S.lower_bound(j));
        int R = *S.upper_bound(j);
        if (L != 0) {
            int LL = *(--S.lower_bound(L));
            ans += i * (L - LL) * (R - j);
        }
        if (R != N + 1) {
            int RR = *S.upper_bound(R);
            ans += i * (j - L) * (RR - R);
        }
        S.insert(j);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long LL;

const int N = 405;
const int D = 4;

int dir[D][2] = {{1 , 0} , {0 , 1} , {-1 , 0} , {0 , -1}};

int que[N * N][2];
bool vis[N][N];
char mp[N][N];
int n , m , head , tail;
LL ans;

int main()
{
	//freopen("c.in" , "r" , stdin) , freopen("c.out" , "w" , stdout);
	scanf("%d%d" , &n , &m);
	for (int i = 1;i <= n;++ i) scanf("%s" , mp[i] + 1);
	for (int x = 1;x <= n;++ x)
		for (int y = 1;y <= m;++ y)
			if (!vis[x][y])
			{
				int black_cnt = 0 , white_cnt = 0;
				vis[que[1][0] = x][que[1][1] = y] = 1 , head = 0 , tail = 1;
				for (int x_ , y_ , x__ , y__;head < tail;)
				{
					++ head , x_ = que[head][0] , y_ = que[head][1];
					black_cnt += mp[x_][y_] == '#' , white_cnt += mp[x_][y_] == '.';
					for (int d = 0;d < D;++ d)
					{
						x__ = x_ + dir[d][0] , y__ = y_ + dir[d][1];
						if (1 <= x__ && x__ <= n && 1 <= y__ && y__ <= m && mp[x_][y_] != mp[x__][y__] && !vis[x__][y__])
							++ tail , vis[que[tail][0] = x__][que[tail][1] = y__] = 1;
					}
				}
				ans += 1ll * black_cnt * white_cnt;
			}
	printf("%lld\n" , ans);
	//fclose(stdin) , fclose(stdout);
	return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

#define int long long
int N, K;
int X[50], Y[50];
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> K;
  vector<int> xs, ys;
  rep(i, N) {
    cin >> X[i] >> Y[i];
    xs.pb(X[i]);
    ys.pb(Y[i]);
  }
  sort(all(xs)); uniq(xs);
  sort(all(ys)); uniq(ys);
  rep(i, N) X[i] = index(xs, X[i]), Y[i] = index(ys, Y[i]);
  int W = xs.size(), H = ys.size();
  long long m = 1LL<<62;
  for (int lx=0; lx<W; lx++) {
    for (int rx=lx; rx<W; rx++) {
      for (int ly=0; ly<H; ly++) {
        for (int ry=ly; ry<H; ry++) {
          int ctr = 0;
          rep(i, N) if (lx <= X[i] && X[i] <= rx && ly <= Y[i] && Y[i] <= ry) ctr++;
          if (ctr >= K) m = min(m, 1LL*(xs[rx]-xs[lx])*(ys[ry]-ys[ly]));
        }
      }
    }
  }
  cout << m << "\n";
  return 0;
}


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

int main(){
  int n, m, count;
  cin >> n;
  m = 1;
  count = 0;
  vector<int> button(n);
  for(int i = 0; i < n; i++){
    int a;
    cin >> a;
    button.at(i) = a;
  }
  for(int i = 0; i < 100000; i++){
    m = button.at(m - 1);
    count++;
    if(m == 2){
      cout << count << endl;
      break;
    }
    else if(i == 99999){
      cout << -1 << endl;
    }
  }
}

Measured memory_bytes: 640
# No DP No LIFE
# 配るDP, 要復習
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    H, N = MAP()
    L = [LIST() for i in range(N)]
    A = []
    B = []
    for i in range(N):
        A.append(L[i][0])
        B.append(L[i][1])

    dp = [INF] * 20010
    dp[0] = 0
    for i in range(10010):
        for j in range(N):
            dp[i+A[j]] = min(dp[i+A[j]], dp[i]+B[j])
    ans = INF
    for i in range(H, 20010):
        ans = min(ans, dp[i])
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 66264
#include <bits/stdc++.h>
using namespace std;
const int MAX_H=11,MAX_W=21;
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

int h,w,x,y; string now,ans;
string S[MAX_H];
int visited[MAX_H][MAX_W];
set<string> cnt;

void solve(){
    ans=""; cnt.clear();
    for (int i=0;i<h;++i){
        for (int j=0;j<w;++j){
            for (int k=0;k<8;++k){
                for (int l=0;l<h;++l)
                    for (int m=0;m<w;++m)
                        visited[l][m]=0;
                x=i,y=j; now="";
                while(!visited[x][y]){
                    now+=S[x][y]; visited[x][y]=1;
                    (x+=dx[k]+h)%=h; (y+=dy[k]+w)%=w;
                    if (!cnt.count(now)){cnt.emplace(now); continue;}
                    if (ans.size()<now.size()) ans=now;
                    else if (ans.size()==now.size()&&now<ans) ans=now;
                }
            }
        }
    }
    if (ans.size()<2) cout << 0 << '\n';
    else cout << ans << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> h >> w,h){
        for (int i=0;i<h;++i) cin >> S[i];
        solve();
    }
}


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

typedef long long int llint;

int main()
{
  int a, b, c, x;
  cin>> a >> b >> c >> x;

  int ans = 0;

  for(int i = 0; i <= a; i++) {
    for(int j = 0; j <= b; j++) {
      for(int k = 0; k <= c; k++) {
	if(500 * i + 100 * j + 50 * k == x) ans++;
      }
    }
  }

  cout<< ans <<endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    // int[] A = new int[N - 1];
    int[] B = new int[N];
    for (int i = 0; i < N; i++) {
      B[i] = 0;
    }
    for (int i = 0; i < N -1; i++) {
      int tmp = Integer.parseInt(sc.next()) -1;
      B[tmp] = B[tmp] +1;
    }
    for (int i = 0; i < N; i++) {
      System.out.println(B[i]);
    }

  }
}



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

int main()
{
    int a, b;
    cin >> a >> b;

    if (a > b)
        cout << "a > b" << endl;
    else if (a < b)
        cout << "a < b" << endl;
    else
        cout << "a == b" << endl;
}

Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
int s[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	cout<<s[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int K;cin>>K;
    string S;cin>>S;
    int N=si(S);
    if(K>=N){
        cout<<S<<endl;
    }else{
        for(int i=0;i<K;i++){
            cout<<S[i];
        }
        cout<<"...\n";
    }
}



Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <string>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    string s;   cin >> s;
    int n = s.size();
    vector<int[2]>dp(n);
    dp[0][0] = s[0] - '0';
    dp[0][1] = 11 - (s[0] - '0');
    rep(i, n-1){
        int d = s[i+1] - '0';
        dp[i+1][0] = min(dp[i][0], dp[i][1]) + d;
        dp[i+1][1] = min(dp[i][0]+11-d, dp[i][1]+9-d);
    }
    cout << min(dp[n-1][0], dp[n-1][1]) << endl;
}


Measured memory_bytes: 9220
#include <iostream>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int len=s.length();
	if(s[0]!='A')
	{
		cout<<"WA\n";
		return 0;
	}
	if(s[1]>='A'&&s[1]<='Z')
	{
		cout<<"WA\n";
		return 0;
	}
	if(s[len-1]>='A'&&s[len-1]<='Z')
	{
		cout<<"WA\n";
		return 0;
	}
	int num=0;
	for(int i=2;i<len-1;i++)
	{
		if(s[i]=='C')
			num++;
		if(s[i]>='A'&&s[i]<'C'&&s[i]>'C'&&s[i]<='Z')
		{
			cout<<"WA\n";
			return 0;
		}
	}
	if(num==0||num>1)
	{
		cout<<"WA\n";
		return 0;
	}
	cout<<"AC\n";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=998244353 ;

int n;

void dfs(string s, int mx){
  if(s.size() == n){
    cout << s << endl;
    return;
  }
  for(char i='a'; i<='a'+mx+1; i++){
    string t = s + i;
    int ma = max(mx, (int)i - 'a');
    dfs(t, ma);
  }
}


int main(){
  cin >> n;
  dfs("", -1);
}

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

int main(void) {
  int X,Y;
  scanf("%d %d",&X,&Y);

  if(X < 0 || X > 100){
	  return -1;
  }
  if(Y < 0 || Y > 100){
  	  return -1;
  }
     if(Y % 2 == 1){
	   printf("No");
	   return 0;
      }else{
    	  int i;
    	  for(i=0;i<=X;i++){
    		  int sum = 0;
    		  sum = 2*i + 4*(X - i);
    		  if(Y == sum){
    			  printf("Yes");
    			  return 0;
    		  }
    	  }
    	  printf("No");
      }
   return 0;
}


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

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

int n,k,c;
char s[252521];
int lwork[252521], rwork[252521];

int main(){
  scanf("%d%d%d", &n, &k, &c);
  scanf("%s", s);
  REP(i,n){
    int add = s[i]=='x' ? 0 : 1;
    if(i==0){
      lwork[i] = add;
    }else if(i<c+1){
      lwork[i] = max(lwork[i-1], add);
    }else{
      lwork[i] = max(lwork[i-1], lwork[i-c-1] + add);
    }
  }
  REP(_i,n){
    int i = n-1-_i;
    int add = s[i]=='x' ? 0 : 1;
    if(_i==0){
      rwork[i] = add;
    }else if(_i<c+1){
      rwork[i] = max(rwork[i+1], add);
    }else{
      rwork[i] = max(rwork[i+1], rwork[i+c+1] + add);
    }
  }
  REP(i,n){
    int works = 0;
    if(i>0)works += lwork[i-1];
    if(i<n-1)works += rwork[i+1];
    if(works < k){
      printf("%d\n", i+1);
    }
  }
  return 0;
}



Measured memory_bytes: 3328
// ARC092
// D - Two Sequences

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int K = 28;

int N;
vector<int> a, b;

int main() {
    cin >> N;
    a.resize(N);
    b.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> b[i];
    }

    int ans = 0;
    for (int k = 0; k <= K; k++) {
        vector<int> q(N);
        for (int i = 0; i < N; i++) {
            q[i] = b[i] & ((1 << (k + 1)) - 1);
        }
        sort(q.begin(), q.end());

        int cnt = 0;
        for (int i = 0; i < N; i++) {
            int p = a[i] & ((1 << (k + 1)) - 1);
            cnt += lower_bound(q.begin(), q.end(), (4 << k) - p) -
                   // cnt += q.end() -
                   lower_bound(q.begin(), q.end(), (3 << k) - p);
            cnt += lower_bound(q.begin(), q.end(), (2 << k) - p) -
                   lower_bound(q.begin(), q.end(), (1 << k) - p);
        }
        if (cnt & 1) {
            ans |= (1 << k);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        long[] inpt = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).OrderBy(a=>a).ToArray();

        long ans = inpt[0] * inpt[1];
        if (inpt.Any(a => a % 3 == 0))
        {
            ans = 0;
        }
        else 
        {
            long totalCount = inpt[0] * inpt[1];

            long baseSize = totalCount / 3;

            int start = Math.Max(0, (int)(baseSize/inpt[0])-2);
            for(int i = start; i<= Math.Min(start + 4, inpt[1]-1); i++) {
                long p1 = inpt[0]*i;
                long[][] list = Divide(inpt[0], inpt[1]-i);

                foreach(long[] item in list) {
                    long[] subList = item.Union(new long[]{p1}).ToArray();
                    ans = Math.Min(subList.Max()-subList.Min(), ans);
                }
            }
            start = Math.Max(0, (int)(baseSize/inpt[1])-2);
            for(int i = start; i<= Math.Min(start + 4, inpt[0]-1); i++) {
                long p1 = inpt[1]*i;
                long[][] list = Divide(inpt[0]-i, inpt[1]);

                foreach(long[] item in list) {
                    long[] subList = item.Union(new long[]{p1}).ToArray();
                    ans = Math.Min(subList.Max()-subList.Min(), ans);
                }
            }
        }
        Console.WriteLine(ans);
    }

    private long[][] Divide(long x, long y)
    {
        long[][] ret;
        long total = x * y;
        if (x % 2 == 0 || y%2 ==0)
        {
            ret = new long[1][];
            ret[0] = new long[] { total / 2, total / 2 };
            return ret;
        }
        long[] tmp1 = new long[] { (x / 2) * y, (x - (x / 2)) * y };
        long[] tmp2 = new long[] { (y / 2) * x, (y - (y / 2)) * x };
        ret = new long[2][];
        ret[0] = tmp1;
        ret[1] = tmp2;
        return ret;
    }


 


    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"

100000 100000


";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}

Measured memory_bytes: 13652
# -*- coding: utf-8 -*-
"""
Created on Sat Oct  6 08:39:16 2018
DSL_1_A
@author: maezawa
"""

class djset:
    def __init__(self, size):
        self.rank = [0]*size
        self.parent = [0]*size
        for i in range(size):
            self.makeset(i)
            
    def makeset(self, x):
        self.parent[x] = x
        self.rank[x] = 0
        
    def same(self, x, y):
        return self.findset(x) == self.findset(y)
    
    def unite(self, x, y):
        self.link(self.findset(x), self.findset(y))
        
    def link(self, x, y):
        if self.rank[x] > self.rank[y]:
            self.parent[y] = x
        else:
            self.parent[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1
                
    def findset(self, x):
        if self.parent[x] != x:
            self.parent[x] = self.findset(self.parent[x])
        return self.parent[x]
               

n, q = list(map(int, input().split()))
ds = djset(n)

for i in range(q):
    com, xq, yq = list(map(int, input().split()))
    if com == 0:
        ds.unite(xq, yq)
    elif com == 1:
        if ds.same(xq, yq):
            print(1)
        else:
            print(0)



Measured memory_bytes: 6052
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

typedef long long int lli;

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;}

#ifdef LOCAL
	#define eprintf(...) printf(__VA_ARGS__)
#else 
	#define eprintf(...) 1
#endif

#define ROUNDUP(a, b) 		( ((a) + ((b) - 1) ) / b)
#define SET_ZERO(a)	 		( memset((a), 0, sizeof(a)))
#define SET_NUM_ARRAY(a,b)	( memset((a), b, sizeof(a)))
//#define int long long int //dont forget to change int to signed

int c[50][50];
int was[50];

bool check(int N, int s) {
	SET_ZERO(was);
	queue<int> que;
	que.push(s);

	while (!que.empty()) {
		int u = que.front(); que.pop();
		was[u] = 1;
		for (int i = 0; i < N; i++) {
			if (c[u][i] == 1)
				if (was[i] != 1)
					que.push(i);
		}
	}

	int cnt = 0;
	for (int i = 0; i < N; i++) {
		cnt += was[i];
	}
	return cnt - N != 0;
}


int main() {
	int N, M;
	scanf("%d %d", &N, &M);
	SET_ZERO(c);
	for (int i = 0; i < M; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		c[a-1][b-1] = 1;
		c[b-1][a-1] = 1;
	}

	int ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i+1; j < N; j++) {
			if (c[i][j]) {
				c[i][j] = 0;
				c[j][i] = 0;
				if (check(N, i)) {
					eprintf("ans i = %d j = %d\n", i+1, j+1);
					ans++;
				}
				c[i][j] = 1;	
				c[j][i] = 1;
			}
		}
	}

	printf("%d\n", ans);
	return 0;
}
					


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);

        final int r = sc.nextInt();
        final int D = sc.nextInt();
        final int[] x = new int[11];
        x[0] = sc.nextInt();
        for (int i = 1; i <= 10; i++) {
            x[i] = (r * x[i-1]) - D;
            System.out.println(x[i]);
        }
    }
}


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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var c1List = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var c2List = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var c3List = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            for (var a1 = 0; a1 <= c1List.Max(); a1++)
            {
                for (var a2 = 0; a2 <= c2List.Max(); a2++)
                {
                    for (var a3 = 0; a3 <= c3List.Max(); a3++)
                    {
                        var b1 = c1List[0] - a1 == c2List[0] - a2
                            && c1List[0] - a1 == c3List[0] - a3;

                        var b2 = c1List[1] - a1 == c2List[1] - a2
                            && c1List[1] - a1 == c3List[1] - a3;

                        var b3 = c1List[2] - a1 == c2List[2] - a2
                            && c1List[2] - a1 == c3List[2] - a3;

                        if (b1 && b2 && b3)
                        {
                            Console.WriteLine("Yes");
                            return;
                        }
                    }
                }
            }

            Console.WriteLine("No");
        }

        static int SumOfDigits(int x)
        {
            var sum = 0;
            while (x > 0)
            {
                sum += x % 10;
                x /= 10;
            }

            return sum;
        }
    }
}


Measured memory_bytes: 17484
#include <bits/stdc++.h>
using namespace std;
#include <math.h> 
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll so[1000010];
int main() {
	so[1]=1;
	for(ll i=2;i<1000010;i++){
		ll now=i;
		if(so[i]!=0){
			continue;
		}
		for(ll j=1;j*i<1000010;j++){
			so[i*j]=now;
		}
	}
	ll n;
	cin>>n;
	ll ch[10010];
	for(ll i=0;i<n;i++){
		cin>>ch[i];
	}
	ll ke[1000010]={};
	for(ll i=0;i<n;i++){
		ll now=ch[i];
		map<ll,ll>q;
		while(now!=so[now]){
			q[so[now]]++;
			now/=so[now];
		}
		q[now]++;
		for(auto itr=q.begin();itr!=q.end();itr++){
			ll num=itr->first;
			ll val=itr->second;
			ke[num]=max(ke[num],val);
		}
	}
	ll lcm=1;
	for(ll i=2;i<1000010;i++){
		lcm*=modpow(i,ke[i],inf);
		lcm%=inf;
	}
	//cout <<lcm;
    // a を 10000000007 で割ってから b の逆元をかけて計算
    //a %= MOD;
    //cout << a * modinv(b, MOD) % MOD << endl;
    ll ans=0;
    for(ll i=0;i<n;i++){
    	ll now=ch[i];
    	ll cnt=lcm*modinv(now,inf)%inf;
    	ans+=cnt;
    	ans%=inf;
    }
    cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 19332
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = a;i < n;i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
    int a[1000],b[1000],c[1000],d[1000],n,m,memo[1000] = {0};
    
    while(1){
        
        cin >> a[0] >> b[0] >> c[0];
        if(a[0]+b[0]+c[0] == 0) break;
        else m = a[0]+b[0]+c[0];
        
        cin >> n;
        
        rep(i,0,m){
            memo[i] = 2;
        }
        
        rep(i,0,n){
            cin >> a[i] >> b[i] >> c[i] >> d[i];
            
            if(d[i] == 1){
                memo[a[i]-1] = 1;
                memo[b[i]-1] = 1;
                memo[c[i]-1] = 1;
            }
            
        }
        
        
        rep(i,0,n){
            int cnt = 0,temp = 0;
            
            if(memo[a[i]-1] == 1) cnt++;
            else temp = a[i]-1;
            
            if(memo[b[i]-1] == 1) cnt++;
            else temp = b[i]-1;
            
            if(memo[c[i]-1] == 1) cnt++;
            else temp = c[i]-1;
            
            if(cnt == 2){
                memo[temp] = 0;
            }
        }
        
        
        rep(i,0,m){
            cout << memo[i] << endl;
        }
        
        
    }
    
    
    return 0;
}


Measured memory_bytes: 3020
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int N;
  string S;
  int K;
  
  cin >> N >> S >> K;
  char target = S.at(K-1);
  for (char &c: S) {
    if (c != target) { c = '*'; }
  }
  cout << S;
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = input()
    t = input()
    l = len(s)

    if s == t[:l]:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61676