akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<cstring>
#include<utility>
#include<set>
#include<stack>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PA;
using namespace std;
#define MAX  999999
int main(){
    char ans[][10] = {
        {},
        {'.',',','!','?',' '},
        {'a','b','c'},
        {'d','e','f'},
        {'g','h','i'},
        {'j','k','l'},
        {'m','n','o'},
        {'p','q','r','s'},
        {'t','u','v'},
        {'w','x','y','z'}
    };
    ll n; cin >> n;
    rep(i,n){
        string s(100000,0);
        cin >> s;
        int temp = 0;
        int counter =-1 ;
        for(int k = 0;k<(int)s.size();k++){
            int now = int(s[k]-48);
            if(k == 0){temp = now;counter++;}
            else if(now != 0){
                temp = now;counter++;}
            if(now == 0){
                if(temp  == 9 || temp == 7)
                    counter%=4;
                else if(temp != 1&& temp != 7 && temp!= 9)
                    counter%=3;
                else if(temp == 1)
                    counter %=5;
                if(temp!=0)cout << ans[temp][counter];
                temp = 0;counter =-1;;
            }
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3216
#include <cstdio>
#include <cstring>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#define INF 1e7
using namespace std;
const char *move="UDLR";
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
int n,m,d;
int fie[51][51];
int sx,sy;
int siz;
string out[11];
int next[101][4];
bool ng[101];
int dp[51][51][101];
struct data{
	int x,y,s;
	data(){}
	data(int xx,int yy,int ss){
		x=xx;
		y=yy;
		s=ss;
	}
};
int bfs(){
	queue<data> que;
	que.push(data(sx,sy,0));
	for(int i=0;i<m;i++){
		for(int j=0;j<n;j++){
			for(int k=0;k<=siz;k++){
				dp[i][j][k]=INF;
			}
		}
	}
	dp[sx][sy][0]=0;
	while(que.size()){
		data p=que.front();
		que.pop();
		if(fie[p.x][p.y]==2)return dp[p.x][p.y][p.s];
		for(int i=0;i<4;i++){
			int nx=p.x+dx[i],ny=p.y+dy[i],ns=next[p.s][i];
			if(nx>=0 && nx<m && ny>=0 && ny<n){
				if(fie[nx][ny]>=0 && !ng[ns] && dp[nx][ny][ns]==INF){
					dp[nx][ny][ns]=dp[p.x][p.y][p.s]+1;
					que.push(data(nx,ny,ns));
				}
			}
		}
	}
	return -1;
}

int main(void){
	while(1){
		scanf("%d %d",&n,&m);
		if(n+m==0)break;
		for(int i=0;i<n;i++){
			string str;
			cin >> str;
			for(int j=0;j<m;j++){
				if(str[j]=='.'){
					fie[j][i]=0;
				}
				if(str[j]=='#'){
					fie[j][i]=-1;
				}
				if(str[j]=='S'){
					fie[j][i]=1;
					sx=j,sy=i;
				}
				if(str[j]=='G'){
					fie[j][i]=2;
				}
			}
		}
		scanf("%d",&d);
		for(int i=0;i<d;i++){
			cin >> out[i];
		}
		memset(next,0,sizeof(next));
		memset(ng,false,sizeof(ng));
		vector<string> pfx;
		for(int i=0;i<d;i++){
			for(int j=0;j<=out[i].size();j++){
				pfx.push_back(out[i].substr(0,j));
			}
		}
		sort(pfx.begin(),pfx.end());
		pfx.erase(unique(pfx.begin(),pfx.end()),pfx.end());
		siz=pfx.size();
		for(int i=0;i<siz;i++){
			ng[i]=false;
			for(int j=0;j<d;j++){
				ng[i]|=out[j].length()<=pfx[i].length() && pfx[i].substr(pfx[i].length()-out[j].length(),out[j].length())==out[j];
			}
			for(int j=0;j<4;j++){
				string s=pfx[i]+move[j];
				int k;
				while(1){
					k=lower_bound(pfx.begin(),pfx.end(),s)-pfx.begin();
					if(k<siz && pfx[k]==s)break;
					s=s.substr(1);
				}
				next[i][j]=k;
			}
		}
		printf("%d\n",bfs());
	}
	return 0;
}

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

#define MAX_N 100005
#define pii pair<int ,int>

int n;
vector <pii> xs ,ys;

int par[MAX_N];
int fnd(int u){
    return par[u] = par[u]==u ? u : fnd(par[u]);
}
bool unn(int u ,int v){
    u = fnd(u) ,v = fnd(v);
    if(u != v){
        par[u] = v;
        return 1;
    }
    return 0;
}

int main()
{
    scanf("%d",&n);
    iota(par ,par+n ,0);
    for(int a,b,i=0; i<n; i++){
        scanf("%d%d",&a,&b);
        xs.push_back({a ,i});
        ys.push_back({b ,i});
    }

    sort(xs.begin() ,xs.end());
    sort(ys.begin() ,ys.end());

    vector <pair<int ,pii>> edgs;
    for(int i=1; i<n; i++){
        edgs.push_back({xs[i].first-xs[i-1].first ,pii(xs[i].second ,xs[i-1].second)});
        edgs.push_back({ys[i].first-ys[i-1].first ,pii(ys[i].second ,ys[i-1].second)});
    }

    long long ans = 0LL;
    sort(edgs.begin() ,edgs.end());
    for(int i=0; i<edgs.size(); i++)
        if(unn(edgs[i].second.first ,edgs[i].second.second))
            ans += edgs[i].first;
    printf("%lld\n",ans);
}


Measured memory_bytes: 7528
#include<stdio.h>

int main(){
  int a;
  int ans = 0;
  scanf("%d", &a);
  
  if(a>=0 && a<10){
    ans += a;
  }
  if(a>=10 && a<100){
    ans += 9;
  }
  if(a>=100 && a<1000){
    ans += ((a/100)-1)*100 + a%100 + 10;
  }
  if(a>=1000 && a<10000){
    ans += 909;
  }
  if(a>=10000 && a<100000){
    ans += ((a/10000)-1)*10000 + a%10000 + 910;
  }
  if(a==100000){
    ans += 90909;
  }
  
  printf("%d", ans);
  
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

#define equals(a, b) (fabs((a)-(b)) < EPS)
const double EPS = (1e-10);

class Point {
public:
    double x, y;

    Point(double x = 0, double y = 0): x(x), y(y) {}

    Point operator + (Point p) {
        return Point(x+p.x, y+p.y);
    }
    Point operator - (Point p) {
        return Point(x-p.x, y-p.y);
    }
    Point operator * (double a) {
        return Point(x*a, y*a);
    }
    Point operator / (double a) {
        return Point(x/a, y/a);
    }

    double abs() {
        return sqrt(norm());
    }
    double norm() {
        return x*x + y*y;
    }

    bool operator < (const Point &p) const {
        return x != p.x ? x < p.x : y < p.y;
    }

    bool operator == (const Point &p) const {
        return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
    }
};

typedef Point Vector;
// 内積
double dot(Vector a, Vector b) {
    return a.x*b.x + a.y*b.y;
}
// 外積
double cross(Vector a, Vector b) {
    return a.x*b.y - a.y*b.x;
}

class Segment {
public:
    Point p1, p2;

    Segment(Point p1, Point p2): p1(p1), p2(p2) {}
};
typedef Segment Line;

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
int ccw(Point p0, Point p1, Point p2) {
    Vector a = p1 - p0;
    Vector b = p2 - p0;

    if (cross(a, b) > EPS) return COUNTER_CLOCKWISE;
    if (cross(a, b) < -EPS) return CLOCKWISE;
    if (dot(a, b) < -EPS) return ONLINE_BACK;
    if (a.norm() < b.norm()) return ONLINE_FRONT;

    return ON_SEGMENT;
}

bool intersect(Point p1, Point p2, Point p3, Point p4) {
    return (ccw(p1, p2, p3)*ccw(p1, p2, p4) <= 0 &&
            ccw(p3, p4, p1)*ccw(p3, p4, p2) <= 0);
}
bool intersect(Segment s1, Segment s2) {
    return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}

double getDistanceLP(Line l, Point p) {
    return abs(cross(l.p2-l.p1, p-l.p1) / (l.p2-l.p1).abs());
}
double getDistanceSP(Segment s, Point p) {
    if (dot(s.p2-s.p1, p-s.p1) < 0.0) return (p-s.p1).abs();
    if (dot(s.p1-s.p2, p-s.p2) < 0.0) return (p-s.p2).abs();
    return getDistanceLP(s, p);
}
double getDistance(Segment s1, Segment s2) {
    if (intersect(s1, s2)) return 0.0;
    return min(min(getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2)),
               min(getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2)));
}



int main(void) {
    int q; cin >> q;
    double x0, y0, x1, y1, x2, y2, x3, y3;
    for (int i = 0; i < q; i++) {
        cin >> x0 >> y0 >> x1 >> y1
            >> x2 >> y2 >> x3 >> y3;
        Segment s1(Point(x0, y0), Point(x1, y1));
        Segment s2(Point(x2, y2), Point(x3, y3));

        printf("%.9f\n", getDistance(s1, s2));
    }
    return 0;
}

Measured memory_bytes: 1240
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

ll N, L;
ll A_pre, A_now;

int main() {
    fastio();
    cin >> N >> L;
    cin >> A_pre;
    for(int i = 1; i < N; i++) {
        cin >> A_now;
        if(A_now + A_pre >= L) {
            cout << "Possible\n";
            for(int j = 1; j < i; j++) cout << j << "\n";
            for(int j = N - 1; j > i; j--) cout << j << "\n";
            cout << i << "\n";
            return 0;
        }
        A_pre = A_now;
    }
    cout << "Impossible\n";
 	return 0;
}

Measured memory_bytes: 896
#2019/10/22
#s = open(0).read()
s = input()
display = []
for i in s:
    if i == "0":
        display.append("0")
    elif i == "1":
        display.append("1")
    else:
        if display == []:
            continue
        else:
            display.pop(-1)

#print(display)
ans="".join(display)
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

int H, W;
string S[101];
map<int, ll> E[210];
ll F[210];
int G;
int search(int A, ll B) {
	if (A == G) {
		F[A] = B;
		return 1;
	}
	if (!F[A] || F[A] < B) {
		F[A] = B;
		for (auto i : E[A]) {
			if (i.second > 0) {
				if (search(i.first, min(i.second, B))) {
					E[A][i.first] -= F[G];
					E[i.first][A] += F[G];
					return 1;
				}
			}
		}
	}
	return 0;
}

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


	cin >> H >> W;
	pair<int, int > s, t;
	rep1(i, H) {
		cin >> S[i];
		S[i] = " " + S[i];
		rep1(j, W) {
			if (S[i][j] == 'S') {
				s = mp(i, j);
				E[0][i] = 1e9;
				E[0][100 + j] = 1e9;
			}
			else if (S[i][j] == 'T') {
				E[i][201] = 1e9;
				E[100 + j][201] = 1e9;
				t = mp(i, j);
			}
			else if (S[i][j] == 'o') {
				E[i][100 + j] = 1;
				E[100 + j][i] = 1;
			}
		}
	}

	G = 201;

	ll kotae = 0;
	while (search(0, 1e9)) {
		kotae += F[G];
		memset(F, 0, sizeof(F));
	}
	if (kotae > 1e8) co(-1);
	else co(kotae);

	Would you please return 0;
}

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

bool is_prime_num(int v)
{
    for (int i = 2; i*i <= v; ++i)
        if (v%i == 0)
            return 0;
    return 1;
}


int main()
{
    int n, v, c;
    cin >> n;
    c = 0;
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &v);
        c += is_prime_num(v);
    }
    cout << c << endl;
    return 0;
}



Measured memory_bytes: 3148
#include<stdio.h>

int main() {
   int time[5];
   int min,count;
   count = 0;
   for(int i = 0; i < 5; i++) {
      scanf("%d",&time[i]);
   }
   min = 10;
   for(int i = 0; i < 5; i++) {
      if(min > time[i] % 10 && time[i] % 10 != 0) {
         min = time[i] % 10;
      }
   }
   for(int i = 0; i < 5; i++) {
      if(time[i] % 10 != 0) {
         count += time[i] + 10 - time[i] % 10;
      } else {
         count += time[i];
      }
   }
   printf("%d\n",count - 10 + min);
}
   


Measured memory_bytes: 128
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, M = mapint()
query = [[] for _ in range(N)]
for _ in range(M):
    a, b = mapint()
    query[a-1].append(b-1)
    query[b-1].append(a-1)

checked = [0]*N
ans = False
def dfs(now, cnt):
    global ans
    if cnt==2:
        if now==N-1:
            ans = True
        return
    checked[now] = 1
    for nx in query[now]:
        if not checked[nx]:
            dfs(nx, cnt+1)

dfs(0, 0)
if ans:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 107644
import java.io.*;

public class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        int X = Integer.parseInt (reader.readLine());
        int rem = X % 500;
        System.out.println (X / 500 * 1000 + rem / 5 * 5);
    }
}

Measured memory_bytes: 21332
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int K = Integer.parseInt(sc.next());
    String S = sc.next();
    char[] c1 = S.toCharArray();
    char[] c2 = S.toCharArray();
    char[] c3 = S.toCharArray();
    char[] c4 = S.toCharArray();
    boolean flag = false;
    int count = 0;
    for(int i = 0; i < N; i++){
      if(flag && c1[i] == 'R'){
        flag = false;
        count++;
      }
      if(count == K){
        break;
      }
      
      if(c1[i] == 'L'){
        flag = true;
        c1[i] = 'R';
      }
    }
    flag = false;
    count = 0;
    for(int i = 0; i < N; i++){
      if(flag && c3[i] == 'L'){
        flag = false;
        count++;
      }
      if(count == K){
        break;
      }
      
      if(c3[i] == 'R'){
        flag = true;
        c3[i] = 'L';
      }
    }
    
    flag = false;
    count = 0;
    for(int i = N-1; i >= 0; i--){
      if(flag && c2[i] == 'L'){
        flag = false;
        count++;
      }
      if(count == K){
        break;
      }
      
      if(c2[i] == 'R'){
        flag = true;
        c2[i] = 'L';
      }
    }
    
    flag = false;
    count = 0;
    for(int i = N-1; i >= 0; i--){
      if(flag && c4[i] == 'R'){
        flag = false;
        count++;
      }
      if(count == K){
        break;
      }
      
      if(c4[i] == 'L'){
        flag = true;
        c4[i] = 'R';
      }
    }
    
    String S1 = new String(c1);
    String S2 = new String(c2);
    String S3 = new String(c3);
    String S4 = new String(c4);
    
    count = 1;
    int sum1 = 0;
    char bef = S1.charAt(0);
    for(int i = 1; i < N; i++){
      if(S1.charAt(i) == bef){
        count++;
        if(i == N-1){
          sum1 += count-1;
        }
      }else{
        bef = S1.charAt(i);
        sum1 += count-1;
        count = 1;
      }
    }
    count = 1;
    int sum2 = 0;
    bef = S2.charAt(0);
    for(int i = 1; i < N; i++){
      if(S2.charAt(i) == bef){
        count++;
        if(i == N-1){
          sum2 += count-1;
        }
      }else{
        bef = S2.charAt(i);
        sum2 += count-1;
        count = 1;
      }
    }
    
    count = 1;
    int sum3 = 0;
    bef = S3.charAt(0);
    for(int i = 1; i < N; i++){
      if(S3.charAt(i) == bef){
        count++;
        if(i == N-1){
          sum3 += count-1;
        }
      }else{
        bef = S3.charAt(i);
        sum3 += count-1;
        count = 1;
      }
    }
    
    count = 1;
    int sum4 = 0;
    bef = S4.charAt(0);
    for(int i = 1; i < N; i++){
      if(S4.charAt(i) == bef){
        count++;
        if(i == N-1){
          sum4 += count-1;
        }
      }else{
        bef = S4.charAt(i);
        sum4 += count-1;
        count = 1;
      }
    }
    
    System.out.println(Math.max(sum1, Math.max(sum2, Math.max(sum3, sum4))));
  }
}

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

class Program {
  static void Main(string[] args){
    int n = int.Parse(Console.ReadLine());
    var arr = Console.ReadLine().Split(' ')
      .Select(x => long.Parse(x))
      .Select((x, i) => x - i - 1)
      .OrderBy(x => x)
      .ToArray();
	long b;
    if (n % 2 == 1) {
      b = arr[n/2];
    }else{
      b = (arr[n/2-1] + arr[n/2]) / 2;
    }
    Console.WriteLine(
      arr.Aggregate(0L, (sum, e) => sum + Math.Abs(e - b))
    );
  }
}

Measured memory_bytes: 37536
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a+b+c>=22 )
    cout<<"bust"<<endl;
  
  else 
  cout<<"win"<<endl;
    
  
  
  
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,a,b) for (register int i=(a);i<=(b);i++)
#define For(i,a,b) for (register int i=(a);i>=(b);i--)
#define mem(i,j) memset(i,j,sizeof(i))
using namespace std;
const int N=1e5+5;
int n,k,tmp;
struct P
{
	int a[N];
	P(){mem(a,0);}
}p,q,pi,qi,f[10],A,ans;
P operator *(P x,P y)
{
	P ret;
	FOR(i,1,n) ret.a[i]=x.a[y.a[i]];
	return ret;
}
P operator ^(P x,int y)
{
	P ret;
	FOR(i,1,n) ret.a[i]=i;
	for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;
	return ret;
}
inline P Inv(P x)
{
	P ret;
	FOR(i,1,n) ret.a[x.a[i]]=i;
	return ret;
}
inline P F(P x,P y)
{
	P ret;
	ret=y*Inv(x);
	return ret;
}
inline void Write(P x)
{
	FOR(i,1,n) printf("%d ",x.a[i]);
	puts("");
	return;
}
int main()
{
	scanf("%d%d",&n,&k);
	FOR(i,1,n) scanf("%d",&p.a[i]);
	FOR(i,1,n) scanf("%d",&q.a[i]);
	f[1]=p,f[2]=q;
	pi=Inv(p),qi=Inv(q);
	tmp=(k-1)/6;
	k-=6*tmp;
	A=q*pi*qi*p;
	A=A^tmp;
	FOR(i,3,6) f[i]=F(f[i-2],f[i-1]);
	ans=A*f[k]*Inv(A);
	Write(ans);
	return 0;
}

Measured memory_bytes: 21888
#include<stdio.h>
#include<string.h>
int main(void)
{
	char *num[]={"0",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
	int push_count=0,charcount=0,i,k,s,N;
	char str[100]={0},x[1026],a[10];

	scanf("%d",&N);
	fgets(a,sizeof(a),stdin);
	for(i=0;i<N;i++){
		fgets(x,sizeof(x),stdin);
		
		for(k=0;x[k]!='\n';k++){
			
			if(x[k]=='1'){
				for(s=k+1;x[s]==x[k];s++){
					push_count++;
					if(push_count==5)push_count=0;
				}
				k=s;
				str[charcount++]=num[x[k-1]-'0'][push_count];
				push_count=0;
			}
			else if(x[k]=='9' || x[k]=='7'){
				for(s=k+1;x[s]==x[k];s++){
					push_count++;
					if(push_count==4)push_count=0;
				}
				k=s;
				str[charcount++]=num[x[k-1]-'0'][push_count];
				push_count=0;
			}
			else if(x[k]!='0'){
				for(s=k+1;x[s]==x[k];s++){
					push_count++;
					if(push_count==3)push_count=0;
				}
				k=s;
				str[charcount++]=num[x[k-1]-'0'][push_count];
				push_count=0;
			}
		}
		printf(str);
		putchar('\n');
		memset(str,0,sizeof(str));
		charcount=0;
	}

	return 0;
}

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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int n,k,p[200005],vis[200005];
void solve(){
    cin>>n>>k;
    rep(i,1,n+1) cin>>p[i];
    int cur=1,cnt=0;
    while(vis[cur]==0){
    	vis[cur]=++cnt;
    	cur=p[cur];
    	k--;
    	if(k==0){
    		cout<<cur<<endl;
    		return;
    	}
    }
    int l=cnt-vis[cur]+1;
    k%=l;
    rep(i,0,k) cur=p[cur];
    cout<<cur<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

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

using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	long long int n;
	cin>>n;
	if(n%2==0){
		cout<<n;
	}
	else{
		cout<<n*2;
	}
	return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

const int N=100000;
bool prime[N];
vector<int> p;
int P;

const ll INF=1234567890123LL;

int main()
{
    fill(prime,prime+N,true);
    prime[0]=prime[1]=false;
    for(int i=2; i<N; ++i)
    {
        if(prime[i]) for(int j=2; i*j<N; ++j) prime[i*j]=false;
    }
    rep(i,N) if(prime[i]) p.pb(i);
    P=p.size();

    //素数の2乗
    set<ll> sq;
    rep(i,P) sq.insert((ll)p[i]*p[i]);

    int n;
    scanf(" %d", &n);
    vector<ll> s(n);
    rep(i,n) scanf(" %lld", &s[i]);

    vector<ll> Norm(s), Pair(n,1);
    //s[i]^(1/3)以下のs[i]の素因数
    vector<int> f[100000];
    //Norm(s[i])の計算
    rep(i,n)
    {
        rep(j,P)
        {
            ll cube = (ll)p[j]*p[j]*p[j];
            if(cube>s[i]) break;
            while(Norm[i]%cube==0) Norm[i]/=cube;

            if(s[i]%p[j]==0)
            {
                f[i].pb(p[j]);
                if(Norm[i]%(p[j]*p[j])==0) Pair[i]*=p[j];
                else if(Norm[i]%p[j]==0) Pair[i]*=p[j]*p[j];
            }
        }
    }

    //Pair(s[i])の導出
    rep(i,n)
    {
        ll t=s[i];
        for(const auto &d:f[i]) while(t%d==0) t/=d;

        //素数の2乗
        if(sq.find(t)!=sq.end())
        {
            ll sqt=sqrt(t);

            //オーバーフローがないかチェック
            if(Pair[i] > LLONG_MAX/sqt) Pair[i]=INF;
            else  Pair[i]*=sqt;
        }
        else
        {
            if(t<N)
            {
                if(Pair[i] <= LLONG_MAX/t*t) Pair[i]*=t*t;
            }
            else
            {
                //大きすぎて収まらない
                if(t!=1) Pair[i]=INF;
            }
        }

        if(Pair[i]>10000000000LL) Pair[i]=INF;
    }

    // rep(i,n) printf(" %lld, norm: %lld, pair: %lld\n", s[i], Norm[i], Pair[i]);

    int one=0;
    //normの値,個数
    map<ll,int> Norm_count;
    //norm->pair
    map<ll,ll> Norm_to_Pair;
    rep(i,n)
    {
        if(Norm[i]==1) one=1;
        else
        {
            if(Norm_count.find(Norm[i]) == Norm_count.end())
            {
                Norm_count[Norm[i]]=1;
                Norm_to_Pair[Norm[i]]=Pair[i];
            }
            else ++Norm_count[Norm[i]];
        }
    }

    //答えの導出
    int ans=one;
    set<ll> Not_use;

    for(const auto &x:Norm_count)
    {
        ll norm=x.fi;
        int ct=x.se;

        if(Not_use.find(norm) != Not_use.end()) continue;

        ll pair=Norm_to_Pair[norm];
        if(pair == INF) ans+=ct;
        else
        {
            if(Norm_count.find(pair) != Norm_count.end())
            {
                if(ct>=Norm_count[pair])
                {
                    ans+=ct;
                    Not_use.insert(pair);
                }
            }
            else ans+=ct;
        }
    }

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


Measured memory_bytes: 21120
N = int(input())
A = [int(input()) for i in range(N)]

ans = 0
for i in range(N):
    ans += A[i] // 2
    if A[i] % 2 == 1 and i+1 < N and A[i+1] > 0:
        A[i+1] -= 1
        ans += 1

print(ans)

Measured memory_bytes: 7456
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int main(void) {

	// TODO: submit前にprintf-debugの削除確認！
	unsigned long long int N;
	cin >> N;

	unsigned long long int ans = 0;
	int cnt[3];
	cnt[0] = cnt[1] = cnt[2] = 0;
	{
		unsigned long long int a;
		cin >> a;

		if(a == 0) {
			ans = 3;
		} else {
			ans = 0;
		}
		cnt[0]++;
	}

	for(int i=1; i<N; i++) {
		unsigned long long int a;
		cin >> a;

		int mul = 0;
		for(int j=0; j<3; j++) {
			if(cnt[j] == a) mul++;
		}

		ans = (ans * mul) % 1000000007;

		for(int j=0; j<3; j++) {
			if(cnt[j] == a) {
				cnt[j]++;
				break;
			}
		}
	}

	cout << ans;
	return 0;
}



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

using namespace std;

int a[100005], dp[100005], n;
const int inf = (int)1e9 + 5;

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

return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("tune=native")
using namespace std;
typedef long long ll;
typedef long double ld;

const ll MOD = 1000000007LL;
const int MAX_N = 1000005;

int n;
ll dp[MAX_N][2][2];

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

	cin >> n;
	dp[0][0][0] = 1;
	for (int i = 0; i < n; i++)
		for (int f0 = 0; f0 < 2; f0++)
			for (int f9 = 0; f9 < 2; f9++)
				for (int d = 0; d <= 9; d++)
				{
					dp[i + 1][f0 | (d == 0)][f9 | (d == 9)] += dp[i][f0][f9];
					while (dp[i + 1][f0 | (d == 0)][f9 | (d == 9)] >= MOD)
						dp[i + 1][f0 | (d == 0)][f9 | (d == 9)] -= MOD;
				}
	cout << dp[n][1][1] << '\n';

	return 0;
}

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct Edge{ll from, to, cost;};
struct node{ll cost, to;
  bool friend operator>(node a, node b){
    return a.cost>b.cost;
  }
};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  string S;
  cin >> S;
  ll N = S.size();
  rep(i, N-1){
    if(S[i]==S[i+1]){
      if(i>0){
        cout << i+1 << " " << i+2;
      }else{
        cout << i+1 << " " << i+2;        
      }
      return 0;
    }
    if(i<N-2){
      if(S[i]==S[i+2]){
        cout << i+1 << " " << i+3;
        return 0;
      }
    }
  }
  cout << "-1 -1";
  return 0;

}


Measured memory_bytes: 512
#include <iostream>
#include <string>

using namespace std;

int main(int argc, const char *argv[]) {
  int N;
  string S;
  cin >> N;
  cin >> S;

  for(int i = 0; i < S.length(); i++){
    S[i] += N;
    if(S[i] > 90){
      S[i] = S[i] % 91 + 65;
    }
  }
  cout << S << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <stdio.h>
#include <math.h>
using namespace std;
 
#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
 
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, P> PP;
 
struct edge {
	int to, cost;
	edge(int t, int c) :to(t), cost(c) {}
};
 
int dx[] = { 1,-1,0,0 }, dy[] = { 0,0,1,-1 };
int ddx[] = { 1,1,1,0,-1,-1,-1,0 }, ddy[] = { 1,0,-1,-1,-1,0,1,1 };
 
ll mypow(ll x, ll n, ll m) {	//xのn乗をmで割った余り
	if (n == 0) return 1;
	if (n % 2 == 0) return mypow(x*x%m, n / 2, m);
	else return x*mypow(x, n - 1, m) % m;
}
 
//-----------------------------------------------------------------------------

int a,b;

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

	cin>>a>>b;
	if(a==1)a+=13;
	if(b==1)b+=13;
	cout<<(a<b?"Bob":a>b?"Alice":"Draw")<<endl;
	
	return 0;
}


Measured memory_bytes: 256
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter, deque
#from scipy.misc import comb

N,A,B = map(int, input().split())
v = sorted(list(map(int, input().split())), reverse=True)

ans = 0
for i in range(A,B+1):
    ans = max(sum(v[:i])/i, ans)

cnt = 0
for i in range(A,B+1):
    if sum(v[:i])/i == ans:
        n = v.count(v[i-1])
        r = i-v.index(v[i-1])
        cnt += math.factorial(n)//math.factorial(r)//math.factorial(n-r)

print(ans)
print(cnt)

Measured memory_bytes: 12232
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()
const long long INF = 1e15;
using namespace std;
typedef long long ll;
int main() {
  ll n;
  cin >> n;
  vector<ll> d(n);
  REP(i, n) cin >> d[i];
  ll ans = 0;
  REP(i, n) FOR(j, i + 1, n) { ans += d[i] * d[j]; }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define deg_to_rad(deg) (((deg)/360)*2*3.14159265358979)

int main(){
    double A, B, H, M;
    cin >> A >> B >> H >> M;
    cout << std::fixed << std::setprecision(15) << sqrt(pow(A,2) + pow(B,2) - 2*A*B*cos(fabs(deg_to_rad(M*6)) - deg_to_rad(30*H + 30*(M/60)))) << endl;
}

Measured memory_bytes: 4228
#include<iostream>
#include<vector>
using namespace std;
int main(){
	string s;
	cin >> s;
	vector<char> c;
	for(int i=0;i<s.length();i++){
		if(s[i]=='B'){
			if(c.size()!=0)	c.pop_back();
		}
		else c.push_back(s[i]);
	}
	for(int i=0;i<c.size();i++){
		cout << c[i];
	}
	cout << endl;
	return 0;
}


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

int main(){
    string s;
    cin >> s;
    if(s == "Sunny"){
        cout << "Cloudy" << endl;
    }
    else if(s == "Cloudy"){
        cout << "Rainy" << endl;
    }
    else if(s == "Rainy"){
        cout << "Sunny" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    int ans = INF;
    vector<int> cost(n);
    vector<vector<int>> a(n, vector<int>(m));
    rep(i,n) {
        cin >> cost[i];
        rep(j,m) cin >> a[i][j];
    }
    rep(is,1<<n) {
        vector<int> cf(m);
        int now = 0;
        rep(i,n) {
            if (is>>i&1) {
                rep(j,m) cf[j] += a[i][j];
                now += cost[i];
            }
        }
        bool ok = true;
        rep(i,m) {
            if (cf[i] < x) ok = false;
        }
        if (ok) ans = min(ans, now);
    }
    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define v1 (2 * v + 1)
#define v2 (2 * v + 2)
#define size(a) ((ll)a.size())
typedef long long ll;

const int N = 1e5 + 100;
int a[N], n, b[N];
string s;

bool good(int x, int y) {
	a[0] = x;
	a[1] = y;
	for (int i = 1; i < n; i++) {
		if (a[i]) {
			if (b[i]) a[i + 1] = a[i - 1];
			else a[i + 1] = !a[i - 1];
		} else {
			if (b[i]) a[i + 1] = !a[i - 1];
			else a[i + 1] = a[i - 1];
		}
	}
	bool fl = true;
	for (int i = 0; i <= n; i++) {
		int x = i % n;
		int next = (i + 1) % n;
		int prev = (i - 1 + n) % n;
		if (a[x]) {
			if (b[x]) {
				if (a[prev] != a[next]) fl = false;
			} else {
				if (a[prev] == a[next]) fl = false;
			}
		} else {
			if (b[x]) {
				if (a[prev] == a[next]) fl = false;
			} else {
				if (a[prev] != a[next]) fl = false;
			}
		}
	}
	return fl;
}

int main() {
#ifdef RUZAL
    freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout);
#else
    //freopen("sum0.in", "r", stdin); freopen("sum0.out", "w", stdout);
#endif
	ios_base::sync_with_stdio(0); //cin.tie(NULL);  + 1cout.tie(NULL);

	cin >> n >> s;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'o') b[i] = 1;
		else b[i] = 0;
	}

	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			if (good(i, j)) {
				for (int i = 0; i < n; i++) {
					if (a[i]) {
						cout << "S";
					} else {
						cout << "W";
					}
				}
				return 0;
			}
		}
	}

	cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 1360
#include <stdio.h>
#include <stdlib.h>
#define NUM_TOKENS 128
#define TOKEN_LENGTH 16

typedef int Integer;

enum command_type {
	VALUE,
	OP_ADD,
	OP_SUB,
	OP_MUL,
	OP_DIV,
	END
};
typedef enum command_type CommandType;

struct command_t {
	CommandType type;
	Integer value;
};
typedef struct command_t Command;


char g_tokens[NUM_TOKENS][TOKEN_LENGTH];
int g_tok_index;
char *g_symbol;
Command g_commands[NUM_TOKENS];
Command *g_cmd_iter;


void expression(void);

void command_append(CommandType type, Integer value) {
	g_cmd_iter->type = type;
	g_cmd_iter->value = value;
	g_cmd_iter++;
}

void next_symbol(void) {
	g_symbol = g_tokens[g_tok_index++];
}

void factor(void) {
	if ('0' <= g_symbol[0] && g_symbol[0] <= '9') {
		command_append(VALUE, atoi(g_symbol));
		next_symbol();
	} else if (g_symbol[0] == '(') {
		next_symbol();
		expression();
		if (g_symbol[0] != ')') {
			fprintf(stderr, "SyntaxError: close %s\n", g_symbol);
			exit(1);
		}
		next_symbol();
	} else {
		fprintf(stderr, "SyntaxError: %s\n", g_symbol);
		exit(1);
	}
}

void term(void) {
	char op_sign;

	factor();
	while (g_symbol[0] == '*' || g_symbol[0] == '/') {
		op_sign = g_symbol[0];
		next_symbol();
		factor();
		command_append(op_sign == '*' ? OP_MUL : OP_DIV, 0);
	}
}

void expression(void) {
	char op_sign;

	if (g_symbol[0] == '+' || g_symbol[0] == '-') {
		op_sign = g_symbol[0];
		next_symbol();
		term();
		command_append(op_sign == '+' ? OP_ADD : OP_SUB, 0);
	} else {
		term();
	}
	while (g_symbol[0] == '+' || g_symbol[0] == '-') {
		op_sign = g_symbol[0];
		next_symbol();
		term();
		command_append(op_sign == '+' ? OP_ADD : OP_SUB, 0);
	}
}

void parse(void) {
	g_tok_index = 0;
	g_cmd_iter = &g_commands[0];

	next_symbol();
	while (g_symbol[0] != '=') {
		expression();
	}
	command_append(END, 0);
}


void tokenize(char *in) {
	int n, i;

	for (n = 0; n < NUM_TOKENS; n++) {
		for (i = 0; i < TOKEN_LENGTH; i++) {
			g_tokens[n][i] = '\0';
		}
	}
	n = i = 0;

	for (; *in; in++) {
		if ('0' <= *in && *in <= '9') {
			g_tokens[n][i++] = *in;
		} else {
			if (i) {
				n++;
				i = 0;
			}
			g_tokens[n++][0] = *in;
			if (*in == '=')
				return;
		}
	}
}


Integer run(Command *cmd_iter) {
	Integer stack[128];
	int top = -1;
	CommandType type;

	for (; cmd_iter->type != END; cmd_iter++) {
		type = cmd_iter->type;
		if (type == VALUE) {
			stack[++top] = cmd_iter->value;
		} else {
			top--;
			if (type == OP_ADD) {
				stack[top] += stack[top+1];
			} else if (type == OP_SUB) {
				stack[top] -= stack[top+1];
			} else if (type == OP_MUL) {
				stack[top] *= stack[top+1];
			} else if (type == OP_DIV) {
				stack[top] /= stack[top+1];
			}
		}
	}
	return stack[top];
}


int main(void) {
	int n;
	char in[128];

	fgets(in, 127, stdin);
	n = atoi(in);

	while (n--) {
		fgets(in, 127, stdin);
		tokenize(in);
		parse();
		printf("%d\n", run(g_commands));
	}
	return 0;
}

Measured memory_bytes: 528
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const int INF=1001001001;
const int mod=1000003;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
ll inv(ll n){return modpow(n,mod-2);}
vi fac,finv,invv;
void init(ll n){
    n*=3;
    fac=vi(n);finv=vi(n);invv=vi(n);
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    invv[1] = 1;
    REP(i,2,n){
        fac[i]=fac[i-1]*i%mod;
        invv[i]=mod-invv[mod%i]*(mod/i)%mod;
        finv[i]=finv[i-1]*invv[i]%mod;
    }
}
ll solve(ll x,ll n){
    if(x+n-1>=mod)return 0;
    if(x==0)return 0;
    ll res=fac[x+n-1];
    res*=finv[x-1];
    res%=mod;
    return res;
}
int main(){
    ll q;cin>>q;
    init(mod-1);
    rep(qq,q){
        ll x,d,n;cin>>x>>d>>n;
        if(x==0){
            out(0);continue;
        }
        if(d==0){
            out(modpow(x,n));continue;
        }
        out(solve(x*inv(d)%mod,n)*modpow(d,n)%mod);
    }
}

Measured memory_bytes: 71168
#import heapq
from collections import deque
h,w,k = list(map(int, input().split()))
x1,y1,x2,y2 = list(map(int, input().split()))
x1,y1,x2,y2 = x1-1,y1-1,x2-1,y2-1
dp = [[-1]*w for _ in range(h)]
#que = []
que = deque()
c = [input() for _ in range(h)]

dp[x1][y1] = 0
#heapq.heappush(que, (dp[x1][y1], [x1,y1]))
que.append((x1,y1))
dx = [1,0,-1,0]
dy = [0,1,0,-1]
while que:
  #p= heapq.heappop(que)[1]
  #x,y= p[0],p[1]
  p = que.popleft()
  if (p[0] == x2) & (p[1] == y2):exit(print(dp[x2][y2]))
  for i in range(4):
    for j in range(1,k+1):
      nx = p[0] + dx[i]*j
      ny = p[1] + dy[i]*j
      if not ((0 <= nx < h) & (0 <= ny < w)):break
      if c[nx][ny] == '@':break
      if 0 <= dp[nx][ny] <= dp[p[0]][p[1]]:break
      if dp[nx][ny] == -1:
        #heapq.heappush(que, (dp[nx][ny], [nx,ny]))
        que.append((nx,ny))
      dp[nx][ny] = dp[p[0]][p[1]] + 1

print(-1)

Measured memory_bytes: 36476
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define INF 1e9L
#define EPS 1e-9
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;

class Vec2{
public:
    int x;int y;
    Vec2(int x=0, int y=0) : x(x), y(y){};
    Vec2 operator+(Vec2 v){
        return Vec2(x+v.x, y+v.y);
    }
    Vec2 operator-(Vec2 v){
        return Vec2(x-v.x, y-v.y);
    }
};

int main(void)
{
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    int bl=0;
    REP(i, h){
        cin >> s[i];
        REP(j, w){
            if(s[i][j]=='#') bl++;
        }
    }

    queue<Vec2> q; q.push(Vec2(0,0));
    vector<vector<int>> cost(h, vector<int>(w, 0));
    Vec2 diff[4] = {Vec2(-1,0),Vec2(1,0),Vec2(0,-1),Vec2(0,1)};
    int d=0;
    while(q.size()){
        Vec2 f = q.front(); q.pop();
        REP(i, 4){
            Vec2 a = f + diff[i];
            if(0 <= a.x && a.x < h && 0 <= a.y && a.y < w){
                if(a.x == h-1 && a.y == w-1){
                    d = cost[f.x][f.y]+1;
                    while(q.size())q.pop();
                    break;
                }
                if(s[a.x][a.y] == '.'){
                    cost[a.x][a.y] = cost[f.x][f.y]+1;
                    q.push(a);
                    s[a.x][a.y] = '#';
                }
            }
        }
    }
    if(d) pr(h*w - bl - d - 1);
    else pr(-1);
}

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


#define debug(x) cout << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;
const ll mod = 961748941;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

ll exp(ll a, ll b)
{
  ll ans = 1;
  while(b)
  {
    if(b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

const int maxn = 2e5  + 5;
ll fat[maxn], inv[maxn];

ll C(int n, int k)
{
  if(n < k) 
    return 0;
  if(n < 0 || k < 0) 
    return 0;
  return (((fat[n] * inv[k]) % mod) * inv[n - k]) % mod;
}

void initFactorials()
{
  fat[0] = 1;
  inv[0] = 1;
  for(int i = 1; i < maxn; i++)
  {
    fat[i] = (i * fat[i-1]) % mod;
    inv[i] = exp(fat[i], mod - 2);
  }
}

set<ll>q[26];

int main()
{
  ios::sync_with_stdio(0);
  string s;
  string t;
  cin >> s >> t;
 
  for(int i = 0 ; i < s.size(); i++)
  {
    q[s[i] - 'a'].insert(i + 1);
  }

  int last = 0;
  ll cnt = 0;
  for(int i = 0 ; i < t.size(); i++)
  {
    int val = t[i] - 'a';
    if(q[val].size() == 0)
    {
      cout << "-1\n";
      return 0;
    }
    auto it = q[val].lower_bound(last + 1);
    if(it == q[val].end())
    {
      cnt++;
      last = *q[val].begin();
    }
    else
    {
      last = *it;
    }
  }
  cout << (cnt * s.size() + last) << endl;
  return 0;
}

Measured memory_bytes: 8556
def factrize(x):
    # 試し割りによるxの素因数分解
    f = {}
    tmp = x
    i = 2
    while i**2 <= tmp:
        cnt = 0
        while tmp % i == 0:
            cnt += 1
            tmp = tmp // i
        if cnt > 0:
            f[i] = cnt
        i += 1
    if tmp != 1 or f == {}:
        f[tmp] = 1
    return f


C = []
c = 0
for i in range(50):
    if i in (1, 3, 6, 10, 15, 21, 28, 36, 45):
        c += 1
    C.append(c)

n = int(input())
if n == 1:
    print(0)
else:
    f = factrize(n)
    ans = 0
    for i in f.keys():
        ans += C[f[i]]
    print(ans)


Measured memory_bytes: 9228
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int64_t N, M;
  cin >> N >> M;
  vector<vector<int64_t>> A(N, vector<int64_t>(2));
  for (int64_t i = 0; i < N; i++) {
    cin >> A.at(i).at(0) >> A.at(i).at(1);
  }
  sort (A.begin(), A.end());
  int64_t memo = 0;
  int64_t ans = 0;
  for (int64_t i = 0; i < N; i++) {  
    if (memo == M) {
      break;
    }
    if (M - memo >= A.at(i).at(1)) {
      ans += (A.at(i).at(0) * A.at(i).at(1));
      memo += A.at(i).at(1);
    }
    else {
      ans += (A.at(i).at(0) * (M - memo));
      memo = M;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 8760
#include <iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    int a[n];
    for(int i=0; i<n; i++) cin >> a[i];

    bool flag=0;
    int cnt=0;
    while(true) {
        for(int i=0; i<n; i++) {
            if(a[i]%2==0) a[i]/=2;
            else flag=1;
        }
        if(flag) break;
        cnt++;
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
L=list(input())
L=list(set(L))
L=sorted(L)
R=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
for i in range(min(26,len(L))):
  if L[i]!=R[i]:
    print(R[i])
    exit()
if len(L)<26:
  print(R[len(L)])
  exit()
print("None")

Measured memory_bytes: 9852
#include<bits/stdc++.h>
#define ll long long int
#define ss second
#define ff first
#define Mem(x,val) memset(x,val,sizeof x)
#define pb push_back
#define all(v) v.begin(),v.end()
#define unik(v)  v.erase(unique(v.begin(),v.end()),v.end())
#define cerr(x) cerr << __LINE__ << " th Line : " << #x << " = " << x << "\n"
#define endl '\n'
#define SZ(a) ((int)a.size())
using namespace std;
typedef pair<int, int> pi32;
typedef pair<ll, ll> pi64;
typedef vector<int> vi32;
typedef vector<ll> vi64;
typedef vector<pi32> vp32;
typedef vector<pi64> vp64;
const ll mod = 1e9 + 7;
const ll MX = 2e5 + 10, inf = 1e9 + 7;
ll vis[MX];
vector<ll>adj[MX];
ll H[MX];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	ll n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)cin >> H[i];

	Mem(vis, 0);
	while (m--) {
		int a, b;
		cin >> a >> b;
		adj[a].pb(b);
		adj[b].pb(a);
		vis[a] = 1;
		vis[b] = 1;
	}
	ll cnt = 0;
	for (int i = 1; i <= n; i++)if (!vis[i])cnt++;

	for (int i = 1; i <= n; i++) {
		
		bool f = 1;
		if(adj[i].size()==0)continue;
		//cout<<H[i]<<" : ";
		for (auto it : adj[i]) {
			//cout<<H[it]<<' ';
			if (H[it] >= H[i])f = 0;
		}
		//cout<<endl;
		if (f)cnt++;
	}
	cout << cnt << endl;


	return 0;
}

Measured memory_bytes: 14156