akhauriyash/Code-Regression huggingface dataset:
MOD = 10 ** 9 + 7  # MODは変数に入れてしまったほうが打ち間違えなくていいです

N = int(input())
A = list(map(int, input().split()))

S = sum(A) % MOD
ans = 0

# A_Nも含まれてしまいますが、そのときはs=0なので問題ありません
for x in A:
    S -= x  # 自分と自分自身を掛けないように、先に引く必要があります
    S %= MOD  # MODはいちいち取っておくといいです
    ans += S * x
    ans %= MOD

ans %= MOD  # この行は完全に不要ですが、最後だけMODを取り忘れてWAになるミスは非常によくあるので、必要以上に取っておくと安心できます
print(ans)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
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; }
const ll MOD = 1e9+7;

int main(){
    ll A, B, C, D;
    cin >> A >> B >> C >> D;

    bool taka;
    while(1){
        C -= B;
        if(C <= 0){
            taka = true;
            break;
        }

        A -= D;
        if(A <= 0){
            taka = false;
            break;
        }
    }

    if(taka)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3596
#include<stdio.h>
int main(){
    char N[3+1];
    scanf("%s",N);
    if(N[0]-'0'==7){
        printf("Yes\n");
    }else if(N[1]-'0'==7){
        printf("Yes\n");
    }else if(N[2]-'0'==7){
        printf("Yes\n");
    }else if((N[0]-'0'!=7)&&(N[1]-'0'!=7)&&(N[2]-'0'!=7)){
        printf("No\n");
    }
}

Measured memory_bytes: 1648
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
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 const INF = 1001001001;


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

string str;
cin >> str;
int n = str.size();
vl ans;

for(int bit = 0; bit < (1 << (n-1)); ++bit) {
    ll num = 0, cur = 0;
    rep(i,n) {
        cur = cur * 10 + (int)(str[i]-'0');
        if((bit & (1 << i)) || i == n-1) {
            num += cur;
            cur = 0;
        }
    }
    ans.push_back(num);
}
ll res = 0;
for(ll x:ans) {
    res += x;
}
cout << res << endl;
return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define mkt make_tuple
#define mkp make_pair
#define no {cout << "-1\n"; return;}

const int N = 2e5 + 7, MOD = 998244353;

int psum[N], dp[N];

void solve() {
    dp[1] = psum[1] = 1;
    int n, k;
    cin >> n >> k;
    vector <pi> p(k);
    loop(i, k)
        cin >> p[i].F >> p[i].S;
    for (int i = 2; i <= n; ++i) {
        loop(j, k) {
            if (i - p[j].F <= 0)
                continue;
            dp[i] = (dp[i] + psum[i - p[j].F] - psum[max(0ll, i - p[j].S - 1)] + MOD) % MOD;
        }
        psum[i] = (psum[i - 1] + dp[i]) % MOD;
    }
    cout << dp[n];
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

Measured memory_bytes: 6712
import sys
MAX = 1000000

A = tuple(range(2, MAX))
B = tuple()
while True:
    if (A[0])**2 > MAX:
        break
    B = B + (A[0],)
    A = tuple(x for x in A if x % A[0] != 0)
B = B + A

Lines = sys.stdin.readlines()
for line in Lines:
    print(len([x for x in B if x <= int(line)]))

Measured memory_bytes: 51336
H,W=map(int,input().split())
N=int(input())
A=list(map(int,input().split()))
A_dic={i+1:A[i] for i in range(N)}
Squares=[[0 for i in range(W)] for j in range(H)]

step_w=1
w,h,cnt=0,0,0
for k,v in A_dic.items():
    for i in range(v):
        cnt+=1
        Squares[h][w]=str(k)
        if cnt%W==0:
            h+=1
            step_w*=(-1)
        else:
            w+=step_w

for l in Squares:
    print(' '.join(l))


Measured memory_bytes: 4528
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#define fr first
#define sc second
#define INF (1 << 25)
using namespace std;

typedef pair<int,int> P;
typedef pair<P,int> iP;
struct edge{
  int to,dis,enemy; edge(){}
  edge(int to,int dis,int enemy):to(to),dis(dis),enemy(enemy){}
};

int n,m,money;
int costed[128][128];
vector<vector<edge> >info(128);

void init(){
  for(int i=0;i<128;i++){
    for(int j=0;j<128;j++) costed[i][j] = INF;
  }
  info.resize(0); info.resize(128);
}

void add_info(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  info[a].push_back(edge(b,c,d));
  info[b].push_back(edge(a,c,d));
}

int Dijkstra(){
  priority_queue<iP,vector<iP>,greater<iP> > que;
  que.push(iP(P(0,1),money));
  costed[money][1] = 0;
  while(!que.empty()){
    iP p = que.top(); que.pop();
    int now =  p.fr.sc,att = p.fr.fr,mo = p.sc;
    if(now == n) return att;
    for(int i=0;i<info[now].size();i++){
      edge e = info[now][i];
      if(e.enemy + att < costed[mo][e.to]){
	que.push(iP(P(att + e.enemy,e.to),mo));
	costed[mo][e.to] = e.enemy + att;
      }
      if(mo >= e.dis && att < costed[mo-e.dis][e.to]){
	que.push(iP(P(att,e.to),mo-e.dis));
	costed[mo-e.dis][e.to] = att;
      }
    }
  }
}

int main(){
  while(cin >> n >> m >> money,n||m||money){
    init();
    while(m--) add_info();
    cout << Dijkstra() << endl;
  }
}

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

#define int long long

using namespace std;

#ifdef LOCAL 
#include "/media/brayand/BrayanD/debugger.h"
#else
template<typename... Args>
void db(Args... args){}
#endif

const int MOD = 1e9 + 7;

const int MAXN = 5e5 + 100;

int qpow(int a, int b)
{
	int res = 1;

	while(b)
	{
		if(b&1)res = res*a%MOD;
		a = a*a%MOD;
		b /= 2;
	}

	return res;
}

int fact[MAXN];

int inv(int x)
{
	return qpow(x,MOD-2);
}

int Comb(int n, int k)
{
	if(k > n)return 0;
	return fact[n]*inv(fact[k]*fact[n-k]%MOD)%MOD;
}

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

    fact[0] = 1;

    for(int i = 1 ; i < MAXN ; i++)fact[i] = fact[i-1]*i%MOD;

    int N, M;
    cin >> N >> M;

    int tot = (((Comb(M,N)*fact[N]%MOD)*Comb(M,N)%MOD)*fact[N])%MOD;
    
    for(int i = 1 ; i <= N ; i++)
    {
    	int otro = (((Comb(M-i,N-i)*fact[N-i]%MOD)*Comb(M-i,N-i)%MOD)*fact[N-i])%MOD;
    	int sum = ((Comb(M,i)*otro%MOD)*Comb(N,i)%MOD)*fact[i]%MOD;
    	if(i&1)
    	{
    		tot = (tot + MOD - sum)%MOD;
    	}
    	else
    	{
    		tot = (tot + sum)%MOD;
    	}
    }

    cout << tot << '\n';

    return 0;
}

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

using namespace std;
template <class T> class FenwickTree {
  int limit;
  vector<T> arr;

  T lowbit(T x) { return x & (-x); }

public:
  FenwickTree(int limit) {
    this->limit = limit;
    arr = vector<T>(limit + 1);
  }

  void update(int idx, T delta) {
    for (; idx <= limit; idx += lowbit(idx))
      arr[idx] += delta;
  }

  T query(int idx) {
    T ans = 0;
    for (; idx > 0; idx -= lowbit(idx))
      ans += arr[idx];
    return ans;
  }
};
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  for (int i = 0; i < k; ++i) {
    FenwickTree<int> ft(n);
    for (int j = 0; j < n; ++j) {
      int l = max(1, j + 1 - a[j]);
      int r = min(n, j + 1 + a[j]);
      ft.update(l, 1);
      ft.update(r + 1, -1);
    }
    bool end = true;
    for (int j = 0; j < n; ++j) {
      a[j] = ft.query(j + 1);
      if (a[j] != n)
        end = false;
    }
    if (end)
      break;
  }
  for (int i : a)
    cout << i << " ";
}

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

int main()
{
    vector<int> v;
    int num, g;
    cin >> num >> g;
    for (int i = 0; i < num; i++)
    {
        int n;
        cin >> n;
        v.push_back(n);
    }

    sort(v.begin(), v.end());

    for (auto itr = v.begin(); itr != v.end(); itr++)
    {
        g -= *itr;
    }

    int n = g / v.front();
    
    cout << n + num << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

	public static void atcode() {
		Scanner sc=new Scanner(System.in);
		List<Integer> input=new ArrayList<Integer>();
		while(sc.hasNextLine()) {
			input.add(Integer.valueOf(sc.nextLine()));
		}
		int X=input.get(3);
		Integer count=0;
		for(int a=input.get(0);a>=0;a--) {
			for(int b=input.get(1);b>=0;b--) {
				for(int c=input.get(2);c>=0;c--) {
					Integer price=500*a+100*b+50*c;
					if(price==X){
						count++;
					}
				}
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 23252
//Vacation
import java.io.*;
import java.util.*;

public class Main{
	static int t,n;
	static int[][] mat;	
	static StringBuilder ans=new StringBuilder();
	public static long solve(){
		long[][] dp=new long[n][3];
		for(int i=0;i<3;i++){
			dp[0][i]=mat[0][i];
		}
		for(int i=1;i<n;i++){
			for(int j=0;j<3;j++){
				dp[i][j]=0;
				for(int k=0;k<3;k++){
					if(j==k){
						continue;
					}
					dp[i][j]=Math.max(dp[i][j],dp[i-1][k]);
				}
				dp[i][j]+=mat[i][j];
			}			
		}

		long max_value=0;
		for(int i=0;i<3;i++){
			max_value=Math.max(max_value,dp[n-1][i]);
		}
		return max_value;
	}
	public static void main(String[] args) throws IOException{
		// BufferedReader br = new BufferedReader(new
		// 	FileReader("sampleinp.txt"));
    	BufferedReader br = new BufferedReader( 
                             new InputStreamReader(System.in)); 
		
		n=Integer.parseInt(br.readLine());
		mat=new int[n][3];
		for(int i=0;i<n;i++){
			String str[]=br.readLine().split(" ");
			for(int j=0;j<3;j++){
				mat[i][j]=Integer.parseInt(str[j]);
			}
		}
		ans.append(solve());		 	
		// PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter("sampleout.txt")));
		// pw.write(ans.toString());
		// pw.flush();
	 	System.out.println(ans.toString());
	}
}


Measured memory_bytes: 50220
N = int(input())
A = list(map(int, input().split()))
ans = [0] * N
res = ''

for i in range(N):
  ans[A[i] - 1] = i+1

for i in range(N-1):
  res += str(ans[i])
  res += ' '
  
print(res + str(ans[N-1]))

Measured memory_bytes: 13880
integer N,H
integer,allocatable::s(:),t(:),c(:)
integer,allocatable::sm(:),tt(:)
integer ans
read*,N,H
allocate(s(N),t(N),c(N))
do i=1,N
  read*,s(i),t(i),c(i)
end do

allocate(sm(2*10**5),tt(2*10**5))
sm=0
do i=1,H
  tt=0
  do j=1,N
    if(c(j)==i)then
      tt(s(j)*2-1)=tt(s(j)*2-1)+1
      tt(t(j)*2)=tt(t(j)*2)-1
    endif
  end do
  do j=2,2*10**5
    tt(j)=tt(j)+tt(j-1)
  end do
  do j=1,2*10**5
    if(tt(j)>0)sm(j)=sm(j)+1
  end do
end do

ans=0
do i=1,2*10**5
  ans=max(ans,sm(i))
end do

print"(i0)",ans

end

Measured memory_bytes: 3072
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int N;
int M;
int main(){
  rd(N);
  rd(M);
  if(N==M){
    wt_L("Yes");
    wt_L('\n');
  }
  else{
    wt_L("No");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20200119-1

// --- original code ---
// int N, M;
// {
//   rd(N,M);
//   wt(if[N==M,"Yes","No"]);
// }


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////

	
int main() {

	ll a, b;
	cin >> a >> b;

	if (a <= 8 && b <= 8) { cout << "Yay!"; }
	else { cout << ":("; }

	
	system("PAUSE");
}

Measured memory_bytes: 884
import sys
sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline


def dfs2(conj, p=0, t=0, past_p=None, visit=set(), second_visit=set()):   # 距離と探索経路を返す。デクリメントされている場合は、decrement=True にする
    visit.add(p)
    for q in conj[p]:
        if q == past_p:
            # 逆流した際の処理
            continue
        if q in second_visit:
            # 帰り道に訪れた際の処理
            continue
        if q in visit:
            continue
        # p から q への引継ぎ処理
        X[q] += X[p]
        dfs2(conj, q, t+1, p, visit, second_visit)
    second_visit.add(p)
    return X

######################################################################################################

N, Q = map(int, input().split())  # N:頂点数, M:辺

conj = [set() for _ in range(N)]
for _ in range(N-1):
    u, v = map(int, input().split())
    u -= 1                                    # デクリメントが不要な場合は消す
    v -= 1
    conj[u].add(v)
    conj[v].add(u)                            # 無効グラフの場合は消す

X = [0]*N
for _ in range(Q):
    p, x = map(int, input().split())
    X[p-1] += x

print(*dfs2(conj, p=0))

Measured memory_bytes: 353792
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline



def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [r, D, x] = [long(input_raw[0]), long(input_raw[1]), long(input_raw[2])]
    for i in range(10):
        x = r*x - D

        print x

if __name__ == '__main__':
    main()


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

using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

// Library
ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

ll LCM(ll a, ll b) {
    ll g = GCD(a, b);
    return a / g * b;
}
//

int main() {
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int N; cin >> N;
    vector<ll> T(N);
    for (int i = 0; i < N; ++i) {
        cin >> T[i];
    }

    ll ans = T[0];
    for (int i = 1; i < N; ++i) {
        ans = LCM(ans, T[i]);
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
const int maxn=1e5+10;
int h[maxn];
int main(){
    int n;
    while(~scanf("%d",&n)){
        int maxx=0,flag=1;
        for(int i=1;i<=n;i++){
            scanf("%d",&h[i]);
            if(h[i]>maxx) maxx=h[i];
            if(h[i]+1<maxx) flag=0;
        }
        if(flag==0)
            printf("No\n");
        else printf("Yes\n");
    }
    return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  if(n > m) swap(n, m);
  if(m == 1) cout << "1" << endl;
  else if(n == 1) cout << m - 2 << endl;
  else cout << 1ll * n * m - n * 2 - m * 2 + 4 << endl; 
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(500000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def dfs(u, p, c, color, tree):
    color[(u, p)] = c
    color[(p, u)] = c

    now = 0
    for v in tree[u]:
        if v == p:
            continue
        if now == c:
            now += 1

        dfs(v, u, now, color, tree)
        now += 1


def solve():
    N = int(input())

    tree = [[] for _ in range(N)]
    edges = []
    for _ in range(N - 1):
        A, B = map(int, input().split())
        A -= 1
        B -= 1
        tree[A].append(B)
        tree[B].append(A)
        edges.append((A, B))

    color = dict()
    dfs(0, -1, -1, color, tree)

    print(max(color.values()) + 1)
    for e in edges:
        print(color[e] + 1)


def main():
    solve()


if __name__ == '__main__':
    main()


Measured memory_bytes: 87928
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000

string S;

int get(int l,int r,int k){
	if(k<0)return -100000;
	if(r==l)return 1;
	if(r<l)return 0;
	static vector<vector<vector<int>>> dp(S.size()+1,vector<vector<int>>(S.size()+1,vector<int>(S.size()+1,-1)));
	if(dp[l][r][k]!=-1)return dp[l][r][k];
	int ret = 0;
	ret = max(ret,get(l+1,r,k));
	ret = max(ret,get(l,r-1,k));
	ret = max(ret,get(l+1,r-1,k-1)+2);
	if(S[l]==S[r])ret = max(ret,get(l+1,r-1,k)+2);
	dp[l][r][k]=ret;
	return ret;
}

int main(){
	
	cin>>S;
	
	int K;
	cin>>K;
	
	cout<<get(0,S.size()-1,K)<<endl;
	
	return 0;
}

Measured memory_bytes: 113292
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
const int MAX_N = 10000;
const int INF = 999999999;
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;
using namespace std;

int n;
vector<pair<int, int> > adj[MAX_N];
int color[MAX_N];
int d[MAX_N];

void dijkstra(int s) {
    priority_queue<pair<int, int> > PQ;
    for (int i = 0; i < n; i++) {
        color[i] = WHITE;
        d[i] = INF;
    }

    d[s] = 0;
    PQ.push(make_pair(0, 0));
    color[s] = GRAY;

    while (!PQ.empty()) {
        pair<int, int> edge = PQ.top(); PQ.pop();
        int u = edge.second;
        color[u] = BLACK;

        if (d[u] < edge.first * (-1)) continue;

        for (int i = 0; i < adj[u].size(); i++) {
            int v = adj[u][i].first;
            if (color[v] == BLACK) continue;
            if (d[v] > d[u] + adj[u][i].second) {
                d[v] = d[u] + adj[u][i].second;
                PQ.push(make_pair(d[v]*-1, v));
                color[v] = GRAY;
            }
        }

    }
}

int main(void) {
    cin >> n;
    for (int i = 0; i < n; i++) {
        int u, k; cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v, c; cin >> v >> c;
            adj[i].push_back(make_pair(v, c));
        }
    }

    dijkstra(0);

    for (int i = 0; i < n; i++) {
        cout << i << " " << d[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 6300
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

long long inv(int a, int p) { return a==1 ? 1 : (1-p*inv(p%a,a))/a+p; }
static const int MODVAL = 998244353;
struct mint {
  int val;
  mint():val(0){}
  mint(int x):val(x%MODVAL) { if(val<0) val+= MODVAL; }
  mint(size_t x):val(x%MODVAL) {}
  mint(long long x):val(x%MODVAL) { if(val<0) val+= MODVAL; }
  mint& operator+=(mint y) { val+=y.val; if(val>=MODVAL) val-=MODVAL; return *this; }
  mint& operator-=(mint y) { val-=y.val; if(val<0) val+= MODVAL; return *this; }
  mint& operator*=(mint y) { val=(val*(long long)y.val)%MODVAL; return *this; }
  mint& operator/=(mint y) { val=(val*inv(y.val,MODVAL))%MODVAL; return *this; }
};
inline mint operator+(mint x, mint y) { return x+=y; }
inline mint operator-(mint x, mint y) { return x-=y; }
inline mint operator*(mint x, mint y) { return x*=y; }
inline mint operator/(mint x, mint y) { return x/=y; }
mint POW(mint x, long long n) { mint r(1); for(;n;x*=x,n>>=1) if(n&1) r*=x; return r; }
mint FAC(int n) { static vector<mint> FAC_(1,1);
  while(int(FAC_.size())<=n) FAC_.push_back(FAC_.back()*FAC_.size()); return FAC_[n]; }
inline mint CMB(int n, int k) { return k<0||n<k ? 0 : FAC(n) / (FAC(k) * FAC(n-k)); }
inline ostream& operator<<(ostream& os, mint a) { return os << a.val; }

int vs[3010];
mint dp[3010];

int main(void) {
  int n, s;
  scanf("%d%d", &n, &s);
  REP(i, n) {
    scanf("%d", &vs[i]);
  }
  dp[0] = POW(2, n);
  REP(i, n) {
    int v = vs[i];
    for(int j = s; j-v >= 0; --j) {
      dp[j] += dp[j-v]/2;
    }
  }
  cout << dp[s] << endl;
  return 0;
}


Measured memory_bytes: 3256
/*
Author: Racer5x
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/
 
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include<bits/stdc++.h>
#define int         long long
#define double      long double
#define pb          emplace_back
#define pf          emplace_front
#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 rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define hell        998244353 
#define PI          3.141592653589
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MAX         2000000000000000000
#define M           1000000007
using namespace std;
 
signed main()
{
    tezz

    int n;
    cin>>n;

    vi v(n);
    for(int &x:v) cin>>x;

    vi dp(n + 1);

    for(int i=0;i<n;i++){
        if(i + v[i] < n) dp[i + v[i]]++;
    }    

    int count = 0;
    for(int i=0;i<n;i++){
        if(i - v[i] >= 0) count += dp[i - v[i]];
    }

    cout<<count;
} 

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

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

    int ans = 1;
    for(int i = 2; i*i <= n; i++){
        int exp = i * i;
        while(exp <= n){
            exp *= i;
        }
        ans = max(ans, exp / i);
    }

    cout << ans << endl;
    return 0;
}

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

using namespace std;

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


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

lint N;
lint a[10005];

lint cont2(int t){
  lint temp=a[t];
  lint cont=0;
  while(temp!=0){
    if(temp%2==0)cont++;
    if(temp%2==1)break;
    temp/=2;
  }
  return cont;
}

int main(){
  cin>>N;
  lint sum=0;
  for(int t=0;t<N;t++){
    cin>>a[t];
    sum+=cont2(t);
  }
  cout<<sum<<"\n";
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include<string>
using namespace std;
class Dice{
    public:
    int a[7],n;
    
    Dice(){}
    
    void roll_E(){   //東のとき
        roll(1,4,6,3);
    };   
    
    void roll_W(){  //西のとき
        roll(1,3,6,4);
    };
    
    
    void roll_S(){   //南のとき
        roll(1,5,6,2);
    };
    void roll_N(){  //北のとき
        roll(1,2,6,5);
    };
    
    void roll_H(){      //横回り
        roll(2,3,5,4);
    }
    
    
    void roll(int i, int j, int k, int l){    //転がったときの値の移動
       n = a[i], a[i] = a[j], a[j] = a[k], a[k] = a[l], a[l] = n; 
    }
    
    void way(char m){  //方角を判断
        if(m == 'E') roll_E();
        else if(m == 'W') roll_W();
        else if(m == 'S') roll_S();
        else if(m == 'N') roll_N();
        else if(m == 'H') roll_H();
    }
};
    
    
    


bool equal( Dice c1, Dice c2 ){    //等しいとき
    for(int i = 1; i <= 6; i++){
        if(c1.a[i] != c2.a[i]) return false;    //一致してなかったらfalse
    }
    return true;
}

    
bool compare( Dice c1, Dice c2 ){   //比較  false==0,true==1
    for(int i = 1; i <= 6; i++){   //a[i] == b[i]をする
        //if(a[1] == b[1]) break;
        //if(c1.a[i] != c2.a[i]) return false;   //とりあえず、true == １なので１と出させる
        for(int j = 0; j < 4; j++){    //右面と同じことして回す
            //cout << "i,j,b[1]"  << i << " "<< j << " " << c2.a[1] << endl;;
            if( equal(c1,c2) ) return true;   //一致したら
            c1.roll_H();
                
        }
        if(i%2 == 0) c1.roll_W();
        else c1.roll_N();
    }
            
    return false;
}
    



int main(void){
    // Your code here!
    Dice dice,dice2;
    //char direction; //方向
    //int t,f;   //ｎは質問の数,tは上、ｆは前
    
    for(int i = 1; i <= 6; i++){    //各面に値を入力
        cin >> dice.a[i];
    }
    
    for(int i = 1; i <= 6; i++){  //二個目のサイコロに同じことする
        cin >> dice2.a[i];
        //cout <<"dice2[" << i << "]" << dice2.a[i] << endl;
    }
    
    //cout << dice.compare(dice,dice2) << endl;
    
    if( compare(dice,dice2) ) cout << "Yes" << endl;
    else cout << "No" << endl;
    
}


Measured memory_bytes: 3100
'use strict'

function main(s) {

  const str = s.split('\n')[0];
  const first_A = str.indexOf('A');
  const last_Z  = str.lastIndexOf('Z')
  const ans = last_Z - (first_A - 1);
  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

const int inf = (int) 1e9 + 7;

int A[(1 << 12)];

int main() {

    int N, M;
    cin >> N >> M;

    for(int i=1; i<(1 << N); i++)
        A[i] = inf;

    while(M--)
    {
        int a, b, mask = 0;
        cin >> a >> b;

        while(b--)
        {
            int x;
            cin >> x;
            mask |= (1 << (x - 1));
        }

        A[mask] = min(A[mask], a);
    }

    for(int i=1; i<(1<<N); i++)
    {
        vector<int> submasks;

        for(int j=1; j<i; j++)
            if((i & j) == j)
                submasks.push_back(j);
        
        for(int j=0; j<submasks.size(); j++)
            for(int k=j+1; k<submasks.size(); k++)
                if((submasks[j] | submasks[k]) == i)
                    A[i] = min(A[i], A[ submasks[j] ] + A[ submasks[k] ]);
    }

    if(A[(1<<N)-1] == inf)
        cout << -1 << "\n";
    else
        cout << A[(1<<N)-1] << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (ll i = (ll)(s); i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
const ll MOD = 1e9+7;
ll LLINF = 1LL << 60;
int INF = INT_MAX;

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

    if(b==0) cout<<1<<endl;
    else if(a==0) cout<<b/x + 1LL<<endl;
    else cout<<b/x - (a-1)/x<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define re(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int
int main(void){
    int z,r;
    cin >> z >> r;
    cout << r+100*(max(0,10-z))<< endl;
    return 0;
}


Measured memory_bytes: 256
import sys
from itertools import combinations_with_replacement

def read():
    return sys.stdin.readline().rstrip()

def main():
    n, m, q = map(int, read().split())
    abcd = [[int(i) for i in read().split()] for _ in range(q)]
    s = 0
    for p in combinations_with_replacement(range(1, m + 1), n):
        t = 0
        for a, b, c, d in abcd:
            t += d * (p[b - 1] - p[a - 1] == c)
        s = max(s, t)
    print(s)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9204
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<
//        pair<int, int>, // change type
//        null_type,
//        less<pair<int, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)(x).size()
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
const double PI = 3.14159265358979323846;
const double eps = (1e-8);


// IS ACTUALLY WORSE CODE CHECK FIRST AC BETTER

int n, m;
int needGeneral[10] = {0,2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<int> need, dig, allZeros, negativeInfinity;

vector<int> mem[12][10005];

vector<int> add(vector<int> const &a, vector<int> const &b)
{
    vector<int> ret(a);
    rep(i,0,m + 1)
        ret[i] += b[i];
    return ret;
}

vector<int> findMax(vector<int> const &a, vector<int> const &b)
{
    if (a[m] > b[m])
        return a;
    else if (a[m] < b[m])
        return b;
    for (int i = 0; i < m; ++i)
    {
        if (a[i] > b[i])
            return a;
        if (a[i] < b[i])
            return b;
    }
    return a;
}


vector<int> solve(int i, int rem) // v size is always m + 1 v[m] is amount of digits and v[0, m-1] is amount taken of this digit
{
    if (i == m)
    {
        if (rem == 0)
            return allZeros;
        return negativeInfinity;
    }
    vector<int> &ret = mem[i][rem];
    if (ret[0] != -1)
        return ret;
    ret = solve(i + 1, rem);
    vector<int> cur(m + 1);
    cur[i] = 1, cur[m] = 1;
    if (rem >= need[i])
        ret = findMax(ret, add(cur, solve(i, rem - need[i])));
    return ret;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//    freopen("facebook.txt", "w", stdout);
#endif
    cin >> n >> m;
    rep(i,0,m + 1)
    {
        rep(j,0,n + 1)
            mem[i][j].resize(m + 1, -1); // m digits and number of digits
    }
    allZeros.resize(m + 1);
    negativeInfinity.resize(m + 1, -1000);
    dig.resize(m);
    rep(i,0,m)
        cin >> dig[i];
    sort(dig.rbegin(), dig.rend());
    need.resize(m);
    rep(i,0,m)
        need[i] = needGeneral[dig[i]];
    vector<int> ans = solve(0, n);
    rep(i,0,sz(ans) - 1){
        rep(j,0,ans[i])
            cout << dig[i];
    }
    return  0;
}


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

class Procon
{
  public Procon() {}
  static void Main(string[] agrs)
  {
    new Procon().Do();
  }

  Scanner cin;

  public void Do()
  {
    cin = new Scanner();
    int N = cin.nextInt();
    int[] A = cin.arrayInt();
    
    for (int j=0;; j++) {
      Array.Sort(A);
      int min = 0;
      for (int i=0; i<N; i++) {
        if (i == N-1 && min == 0) {
          Console.WriteLine(A[i]);
          return;
        }
        if (A[i] == 0) {
          continue;
        } else if (min == 0) {
          min = A[i];
        } else {
          A[i] = A[i] % min;
        }
      }
    }
  }
}


class Scanner
{
  string[] s;
  int i;
  int max_i;

  public Scanner()
  {
    s = new string[0];
    max_i = 0;
    i = 0;
  }

  public string nextString()
  {
    if (i >= s.Length) 
    {
      s = Console.ReadLine().Split(' ');
      max_i = s.Length;
      i = 0;
      if (max_i == 0) 
      {
        return "";
      }
      return s[i++];
    } else 
    {
      return s[i++];
    }
  }

  public int nextInt()
  {
    return int.Parse(nextString());
  }


  public long nextLong()
  {
    return long.Parse(nextString());
  }

  public double nextDouble()
  {
    return double.Parse(nextString());
  }

  public string[] arrayString()
  {
    return Console.ReadLine().Split(' ');
  }

  public int[] arrayInt()
  {
    string[] str = Console.ReadLine().Split(' ');
    int[] array = new int[str.Length];
    for (int i=0; i<str.Length; i++) 
    {
      array[i] = int.Parse(str[i]);
    }
    return array;
  }

  public long[] arrayLong()
  {
    string[] str = Console.ReadLine().Split(' ');
    long[] array = new long[str.Length];
    for (int i=0; i<str.Length; i++) 
    {
      array[i] = long.Parse(str[i]);
    }
    return array;
  }

  public double[] arrayDouble()
  {
    string[] str = Console.ReadLine().Split(' ');
    double[] array = new double[str.Length];
    for (int i=0; i<str.Length; i++) 
    {
      array[i] = double.Parse(str[i]);
    }
    return array;
  }
}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    ll n, k; cin >> n >> k;

    vector<ll> v(n);
    for (ll i = 0; i < n; ++i) {
        cin >> v[i];
    }

    ll ans = 0;
    for (ll i = 1; i <= k; ++i) {
        priority_queue<ll, vector<ll>, greater<ll>> q;
        for (ll l = 0; l <= i; ++l) {
            if (i >= n) {
                for (ll j = 0; j < n; ++j) {
                    q.push(v[j]);
                }
            } else {
                for (ll j = 0; j < l; ++j) {
                    q.push(v[j]);
                }

                for (ll r = 0; r < i - l; ++r) {
                    q.push(v[n - 1 - r]);
                }
            }

            for (ll j = 0; j < k - i; ++j) {
                if (q.empty()) break;

                ll t = q.top();
                if (t >= 0) break;
                q.pop();
            }

            ll sum = 0;
            if (!q.empty()) {
                while (!q.empty()) {
                    ll t = q.top();
                    sum += t;
                    q.pop();
                }
            }

            ans = max(ans, sum);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3616
#include<iostream>
using namespace std;
#define F(i,s,e) for(int i=s;i<e;++i)

int main(){
    int n;
    cin >> n;
    string t,h;
    int ct=0,ch=0;
    int i=0;
    while(i<n && cin >> t >> h){
        if(t==h){
            ++ct;
            ++ch;
        }
        else if(t>h) ct+=3;
        else ch+=3;
        ++i;
    }
    cout << ct << ' ' << ch << endl;
    return 0;
}


Measured memory_bytes: 3216
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i = (s);i<(int)(n);i++)

int main(){
    string s,t;
    cin >> s >> t;
    int k = s.size();
    int sum = 0;
    rep(i,k)if(s[i] != t[i])sum++;
    cout << sum << endl;
}

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

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

  int ans = a*n>=b ? b:a*n;
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3596
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

const int INF = 1 << 30;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};

int w, h, field[20][20];

int solve(int x, int y, int t)
{
  if (t > 9)
    return INF;

  int ans = INF;
  for (int i = 0; i < 4; ++i) {
    int xx = x + dx[i];
    int yy = y + dy[i];
    if (xx < 0 || xx >= w || yy < 0 || yy >= h || field[yy][xx] == 1)
      continue;

    bool infield = true;
    while (field[yy][xx] == 0) {
      xx += dx[i];
      yy += dy[i];
      if (xx < 0 || xx >= w || yy < 0 || yy >= h) {
	infield = false;
	break;
      }
    }
    if (!infield)
      continue;

    if (field[yy][xx] == 3)
      return t+1;

    if (field[yy][xx] == 1) {
      field[yy][xx] = 0;
      ans = min(ans, solve(xx-dx[i], yy-dy[i], t+1));
      field[yy][xx] = 1;
    }
  }
  return ans;
}

int main()
{
  while (scanf("%d %d", &w, &h) != EOF) {
    if (w == 0 && h == 0)
      break;

    int x, y;
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
	scanf("%d", &field[i][j]);
	if (field[i][j] == 2) {
	  x = j;
	  y = i;
	  field[i][j] = 0;
	}
      }
    }

    int ans = solve(x, y, 0);
    if (ans == INF)
      ans = -1;
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#include<string>
#include<cmath>
#include<iomanip>
#define fast ios_base::sync_with_stdio(0)
#define fast_in cin.tie(0)
#define fast_out cout.tie(0)
#define ll long long
#define MAX 1000000
#define MAX_MAX 10000000000
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
using namespace std;

int main()
{
  ll n,ans=MAX_MAX,k;
  cin>>n>>k;
  ll a[100000],dp[100000];
  for(ll i=0;i<n;i++)
  {
    cin>>a[i];
  }
  dp[0]=0;
  dp[1]=abs(a[1]-a[0]);
  for(ll i=2;i<n;i++)
  {
    ans=MAX_MAX;
    for(ll j=1;j<=k&&(i-j)>=0;j++)
    {
  	ans=min(ans,dp[i-j]+abs(a[i]-a[i-j]));
    }
    dp[i]=ans;
  }
  cout<<dp[n-1];
}

Measured memory_bytes: 1792
num = gets.to_i
a = []
num.times do | i |
    w = gets.chomp
    if i != 0
        if w[0] != a[-1][-1] || a.include?(w)
            print "No"
            break
        end
    end
    if i == num-1
        print "Yes"
    end
    a << w
end


Measured memory_bytes: 1788
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    inf = 10**17
    #mod = 10**9 + 7

    h,n = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in range(n)]
    dp = [inf] * (3*(10**4))
    dp[0] = 0
    for i in range(3*(10**4)):
        for a,b in ab:
            if i-a >= 0:
                dp[i] = min(dp[i], dp[i-a]+b)
    res = inf
    for i in range(h, 3*(10**4)):
        res = min(res, dp[i])
    print(res)

if __name__ == '__main__':
    main()

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

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#define pi std::pair<int,int>
const int maxN = 5e5+9;
int io(){
	int n,c;
	while((c=getchar_unlocked())<'0');
	n=c-'0';
	while((c=getchar_unlocked())>='0')n=10*n+(c-'0');
	return n;
}
struct Query{
	int l,r,i;
}query[maxN];
int last[maxN],arr[maxN],BIT[maxN],ans[maxN];
void update(int index,int val,int n){
	while(index<=n){
		BIT[index]+=val;
		index+=(index&-index);
	}
}
int ask(int index){
	int ret=0;
	while(index>0){
		ret+=BIT[index];
		index-=(index&-index);
	}
	return ret;
}
int main(){
	int n=io(),q=io();
	for(int i=1;i<=n;i++)arr[i]=io();
	for(int i=0;i<q;i++){
		query[i].l=io();
		query[i].r=io();
		query[i].i=i;
	}
	std::sort(query,query+q,[](Query &q1,Query &q2){ return (q1.r<q2.r);});
	int r=1;
	for(int i=0;i<q;i++){
		while(r<=query[i].r){
			if(last[arr[r]])update(last[arr[r]],-1,n);
			update(r,1,n);last[arr[r]]=r;r++;
		}
		ans[query[i].i] = ask(query[i].r) - ask(query[i].l-1);
	}
	
	for(int i=0;i<q;i++)printf("%d\n",ans[i]);
}


Measured memory_bytes: 17260
#include <stdio.h>

int main (void){
	
	int a[100];
	int b[100];
	char op[100];
	int ans;
	int i,j;
	
	for(i=0;i<100;i++){
		scanf("%d %c %d",&a[i],&op[i],&b[i]);
		if(op[i]=='?'){
			break;
		}
	}
	
	for(j=0;j<i;j++){
		
		if(op[j]=='+'){
			ans = a[j]+b[j];
		}
		
		if(op[j]=='-'){
			ans=a[j]-b[j];
		}
		
		if(op[j]=='*'){
			ans=a[j]*b[j];
		}
		
		if(op[j]=='/'){
			ans=a[j]/b[j];
		}
		
		if(op[j]=='%'){
			ans=a[j]%b[j];
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
const int N = 60;
char s[N][N];
const int M = N * N;
int f[M], c[M];
int find(int x) {
  if (f[x] != f[f[x]]) f[x] = find(f[x]);
  return f[x];
} 
void join(int x, int y) {
  int rx = find(x), ry = find(y);
  if (rx == ry) return;
  f[ry] = rx;
  c[rx] += c[ry];
}

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s", s[i]);
  }
  for (int i = 0; i < n * m; ++i) {
    f[i] = i;
    c[i] = 1;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (s[i][j] == '.') continue;
      if (i + 1 < n && s[i + 1][j] == '#') {
        join(i * m + j, (i + 1) * m + j);
      }
      if (j + 1 < m && s[i][j + 1] == '#') {
        join(i * m + j, i * m + j + 1);
      }
    }
  }
  bool found = false;
  for (int i = 0; i < n * m; ++i) {
    if (s[i / m][i % m] == '.') continue;
    if (find(i) != i) continue;
    if (c[i] == 1) {
      found = true;
      break;
    }
  }
  puts(found ? "No" : "Yes");
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SORT(i) sort((i).begin(),(i).end())
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2000000000;
constexpr int mod = 1000000007;

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

int main() {

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

	int N, Y; cin >> N >> Y;
	vector<int>ans(3, -1);
	REP(i, 0, N + 1) {
		REP(j, 0, N + 1) {
			if (i + j > N)break;
			int m = 10000 * i + 5000 * j + 1000 * (N - i - j);
			if (m == Y) {
				ans[0] = i;
				ans[1] = j;
				ans[2] = N - i - j;
				break;
			}
		}
	}
	rep(i, 3) {
		cout << ans[i];
		if (i != 2)cout << " ";
	}
	cout << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define ll long long int
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(a) (a).begin(), (a).end()
#define OUT(x) out << (x) << endl;
#define M0(x) memset(x, 0, sizeof(x))
#define MINF(x) memset(x, 0x3f, sizeof(x))
#define MMINUS(a) memset(a, 0xff, sizeof(a))
#define ten(n) ((int)1e##n)

const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
const double EPS = 1.0 / INF;
const char ENDL = '\n'; // for JetBrains IDE only supports yen

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

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

using namespace std;

//===================================== template =========================================================

int main() {
    cin.tie(nullptr); ios_base::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> X(N), Y(N), H(N);
    REP(i, N) cin >> X[i] >> Y[i] >> H[i];

    for (int x = 0; x <= 100; ++x) {
        for (int y = 0; y <= 100; ++y) {
            int h;
            REP(i, N) if (H[i] != 0) { h = abs(x - X[i]) + abs(y - Y[i]) + H[i]; break; }
            REP(i, N) {
                if (max(h - abs(x - X[i]) - abs(y - Y[i]), 0) != H[i]) break;
                else if (i == N-1) cout << x << " " << y << " " << h;
            }
        }
    }
}


Measured memory_bytes: 504
import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString.Char8 as B

import           Data.Array.IArray

readi :: B.ByteString -> Int
readi b | Just (n, _) <- B.readInt b = n

solve :: Int -> Array Int Int -> Int
solve n p = go (1, n)
  where
    m :: Array (Int, Int) Int
    m = listArray ((1, 1), (n, n)) [go (i, j) | i <- [1 .. n], j <- [1 .. n]]

    go :: (Int, Int) -> Int
    go (i, j)
        | i > j = error "something wrong"
        | i == j = 0
        | i < j =
            minimum
                [ m ! (i, k) + m ! (k + 1, j) + p ! (i - 1) * p ! k * p ! j
                | k <- [i .. j - 1]
                ]

main :: IO ()
main = do
    n <- readLn :: IO Int
    xss <- fmap (fmap readi . B.words) . B.lines <$> B.getContents
    let ps = listArray (0, n) $ fmap head xss ++ [last xss !! 1]
    print $ solve n ps



Measured memory_bytes: 6180
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string S,T; cin >> S >> T;
    int cnt = 0;
    for(int i = 0; i < S.size(); i++)
    {
        char preserve = S.at(S.size() - 1 );
        for(int j = 1; j < S.size(); j++)
        {
            S.at(S.size() - j ) = S.at(S.size() - j - 1);
        }
        S.at(0) = preserve;
        if(S == T)
        {
            cout << "Yes" << endl;
            cnt = 1;
            break;
        }
    }
    if(cnt == 0)
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;



public class Main {

    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        
        int N=s.nextInt();
        int k=s.nextInt();
        
        int[] arr=new int[N];
        
        for(int i=0;i<N;i++) {
        	int x=s.nextInt();
        	arr[i]=x;
        }
        Arrays.sort(arr);
        int p=0;
        for(int i=0;i<k;i++) {
        	p=p+arr[i];
        }
        System.out.println(p);
        
         s.close();
    }
}


Measured memory_bytes: 38992
N = gets.to_i
A = gets.split.map(&:to_i)

ans = 1000
(0...N-1).each do |i|
  if A[i] < A[i+1]
    kabu = ans / A[i]
    ans = ans - kabu * A[i] + kabu * A[i+1]
  end
end
p ans

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

int main(){
	int N;
	cin >> N;
	vector<int> a(N);
	for(int i = 0; i < N; i++){
		cin >> a[i];
	}
	
	int s = 1;
	int i = 0;
	bool state = false;
	while(i != N){
		//cout << "s:" << s << ", i:" << i << ", a[i]:" <<a[i] <<endl;
		if(a[i] == s){
			s++;
			state = true;
		}
		i++;
	}
	if(state)cout << N-(s-1) << endl;
	else cout << "-1" << endl;
	
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

class Main{

	static char[][] map;
	//	static int N;
	//	static int M;
	static boolean flag;
	static int ans;



	public static void main(String[] args) {



		Scanner sc = new Scanner(System.in);			//文字の入力
		int N =sc.nextInt();
		int M = sc.nextInt();
		int X = sc.nextInt();
		int[] A = new int[N+1];

		for(int i = 0;i < M;i++){
			A[sc.nextInt()] ++;

		}
		int sub = 0;
		for(int i =X+1;i <= N ;i++){
			if(A[i] > 0){
				sub ++;
			}
		}
		
		int sub2 = 0;
		for(int i =X-1;i>= 0 ;i--){
			if(A[i] > 0){
				sub2 ++;
			}
		}
		System.out.println(Math.min(sub, sub2));


	}


}

class Pair implements Comparable{
	String from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}





Measured memory_bytes: 21844