akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);

#define N 10000
#define nl "\n"
#define f first
#define s second
#define pi acos(-1.0)
#define MOD 1000000007
#define pb push_back

typedef long long ll;
typedef double db;

using namespace std;

int main()
{
    io;
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt" , "w" , stdout);

    ///Let the showdown begin


    int n;
    cin >> n;

    if(n==1)
        cout << "0" << nl;
    else if(n==0)
        cout << "1" << nl;


    ///Happily DONE

    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int64_t abs(int64_t n) {
  if (n < 0) {
    n = -n;
  }
  return n;
}

int main() {
  int64_t a, b, c;
  cin >> a >> b >> c;
  int64_t ans = 0;
  vector <int64_t> v = {a, b, c};
  sort(v.begin(), v.end());
  while ((a%2==0)&&(b%2==0)&&(c%2==0)) {
    ans++;
    int tmp_a = a/2, tmp_b = b/2, tmp_c = c/2;
    a = tmp_b+tmp_c;
    b = tmp_c+tmp_a;
    c = tmp_a+tmp_b;
    vector <int64_t> test = {a, b, c};
    sort(test.begin(), test.end());
    if (v == test) {
      ans = -1;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def read_input():
    a, b = map(int, input().split())

    return a, b


def submit():
    a, b = read_input()

    if a % 3 == 0:
        print('Possible')
        return

    if b % 3 == 0:
        print('Possible')
        return

    if (a + b) % 3 == 0:
        print('Possible')
        return

    print('Impossible')

if __name__ == '__main__':
    submit()

Measured memory_bytes: 38256
#include<bits/stdc++.h>
#include<string>
//#include <boost/math/common_factor.hpp> 
using namespace std;
 
typedef long long ll;
#define endl "\n"
#define pb push_back
#define fp(i,a,b) for(int i=a;i<b;++i)
#define fq(i,a,b) for(int i=a;i<=b;++i)
#define fst ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)



void sol()
{
    ll n;
    cin>>n;
    vector<pair<ll,ll>> v;
    for(ll i=0;i<n;++i)
    {
        ll x,y;cin>>x>>y;
        v.push_back({x,y});
    }
    sort(v.begin(),v.end(),[&](pair<ll,ll> a,pair<ll,ll> b){
        return a.first+a.second<b.first+b.second;}
    );
    ll ans=abs(v[0].first-v[n-1].first) + abs(v[0].second-v[n-1].second);

    sort(v.begin(),v.end(),[&](pair<ll,ll> a,pair<ll,ll> b){
        return a.first-a.second < b.first-b.second;
    });

    ans=max(ans,abs(v[0].first-v[n-1].first) + abs(v[0].second-v[n-1].second));
    cout<<ans<<endl;
    

}

int main() {
    sol();
}

Measured memory_bytes: 7460
#include <bits/stdc++.h>
                using namespace std;
                #define int long long
                #define fi first
                #define se second
                #define pi pair<int,int>  
                #define pb push_back

                // dont forget to initialize global variables inside main() ;
                int mod = 1e9 + 7;

                vector<int > v(1000001,1);
                void fac( int a,unordered_map<int,int>&m ){
                    for(int i=2;i*i<=a;i++){
                        if( v[a]==1 ){
                            break;
                        }
                        if( a%i==0 ){
                            m[i]++;
                        }
                        while( a%i==0 )
                            a = a/i;
                    }
                    if( a!=1 )
                        m[a]++;
                }
                
                void seive( int n ){
                    
                    for(int i=2;i*i<=n;i++){
                    if( v[i] == 1 ){
                        for(int j=i*i;j<=n;j=j+i){
                            if( j%i == 0 )
                                v[j] = 0;
                            }
                        }
                    }
                }

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

                int tt=1;//;cin>>tt; 
                
                
                seive(1000000);
                v[1]=0;
                while( tt-- ){

                    int n;cin>>n;
                    vector<int > a(n);
                    for(int i=0;i<n;i++)
                        cin>>a[i];
                    unordered_map<int,int> m;
                    for(int i=0;i<n;i++){
                        if( v[a[i]]==1 ){
                            m[a[i]]++;
                            continue;
                        }
                        fac(a[i],m);
                    }
                    int f=0;
                    for(auto i : m){
                        if( i.second>1 ){
                            f=1;
                            break;
                        }
                    }
                    if( f==0 ){
                        cout<<"pairwise coprime"<<endl;
                        return 0;
                    }
                    int gcd = a[0];
                    for(int i=1;i<n;i++){
                        gcd = __gcd(gcd,a[i]);
                    }
                    if( gcd==1 ){
                        cout<<"setwise coprime"<<endl;
                        return 0;
                    }
                    else
                        cout<<"not coprime"<<endl;
                }
                return 0;
            }

                        


Measured memory_bytes: 22144
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		//input H and W
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();

		//prepare input and answer string as array
		char[][] mines = new char[h + 2][w + 2];
		char[][] ans = new char[h][w];

		//initialize mines
		for (int i = 0; i < h + 2; i++) {
			for (int j = 0; j < w + 2; j++) {
				mines[i][j] = '.';
			}
		}

		//fill mines
		for (int i = 0; i < h; i++) {
			//read string and convert it array
			String s = sc.next();
			char[] line = s.toCharArray(); //string -> char array
			for (int j = 0; j < w; j++) {
				if (line[j] == '#') {
					mines[i + 1][j + 1] = '#';
				} else {
					mines[i + 1][j + 1] = '.';
				}
			}
		}
		//fill answer
		for (int i = 1; i < h + 1; i++) {
			for (int j = 1; j < w + 1; j++) {
				int counter = 0;
				//mineがある場所の答えはそのままmine
				if (mines[i][j] == '#') {
					ans[i - 1][j - 1] = '#';
				} else {
					//前後左右のmineの数をcountに入れる
					for (int k = i - 1; k <= i + 1; k++) {
						for (int k2 = j - 1; k2 <= j + 1; k2++) {
							if (mines[k][k2] == '#') {
								counter++;
							}
						}
					}
					//char配列のansにintデータを入れるために、char型にキャスト
					ans[i - 1][j - 1] = (char) ('0' + counter);
				}
			}
		}

		for (int i = 0; i < h; i++) {
			String output = new String(ans[i]);
			System.out.println(output);
		}
		sc.close();
	}
}


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

int main() {
	int k, a, b;
  cin >> k >> a >> b;
  if(a/k < b/k){
    cout << "OK";
  }
  if(a % k == 0){
    cout << "OK";
  }
  if(a / k == b / k && a % k != 0){
    cout << "NG";
  }
	return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<iostream>
using namespace std;
int map[800][800],n,d1,d2,z;
void expt(int d)
{
	int now=0;
	while(d%4==0){
		d/=4;//如果整除4，则x,y均为偶数，可以缩点。 
		now++;
	}
	if(d&1){//除二余一，x,y一奇一偶。可以黑白染色 
		for(int i=0;i<2*n;i++)
			for(int j=0;j<2*n;j++)
				if((i>>now)+(j>>now)&1)
				map[i][j]=1;
	}
	else//除四余二，x,y均为奇数 
	{
		for(int i=0;i<2*n;i++)
			for(int j=0;j<2*n;j++)
			if((i>>now)&1)
			map[i][j]=1;
	}
}
int main()
{
	scanf("%d%d%d",&n,&d1,&d2);
	expt(d1);
	expt(d2);
	for(int i=0;i<2*n;i++)
		for(int j=0;j<2*n;j++)
		if(z<n*n && !map[i][j])
		{
			printf("%d %d\n",i,j);
			z++; 
		}
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    long long int a[n+1];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    long long int dp[n+1];
    
    dp[1]=0;
    
    for(int i=2;i<=n;i++){
        long long int mn=INT_MAX;
        if(i<k){
            for(int j=1;j<i;j++){
            mn=min(mn,dp[i-j]+abs(a[i]-a[i-j]));
        }
            
        }
        else{
        for(int j=1;j<=k;j++){
            mn=min(mn,dp[i-j]+abs(a[i]-a[i-j]));
        }
        }
        dp[i]=mn;
    }
    cout<<dp[n];
}

            



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
const int N=155;
int n,K,MD;
void add(int &x,int y) {
	x+=y;
	if(x>=MD) x-=MD;
}
int f[N][N];
void solve1() {
	K>>=1,f[0][0]=1;
	for(int i=1;i<=n;i++) {
		for(int j=0;j<=K;j++) add(f[i][0],f[i-1][j]);
		for(int j=0;j<K;j++) add(f[i][j+1],f[i-1][j]);
	}
	int s1=0,s2=0;
	for(int i=0;i<=K;i++) add(s1,f[n/2][i]);
	for(int i=0;i<=K;i++) add(s2,f[(n+1)/2][i]);
	printf("%d\n",1LL*s1*s2%MD);
}
int g[N*2][N][N];
void solve2() {
	int p;
	g[0][0][0]=1;
	for(int i=2;i-K<=n;i+=2) {
		for(int j=0;j<=n;j++) {//不选
			for(int k=0;k<=K+1;k++) {
				add(g[i][0][0],g[i-2][j][k]);
			}
		}
		if(i<=n) {//右
			for(int j=0;j<=n;j++) {
				for(int k=0;k<=K+1;k++) {
					add(g[i][j+1][0],g[i-2][j][k]);
				}
			}
		}
		if(i-K>=1) {//左
			for(int j=0;j<=n;j++) {
				for(int k=1;k<=K;k++) {
					add(g[i][0][k+1],g[i-2][j][k]);
				}
				add(g[i][0][0],g[i-2][j][0]);
			}
		}
		if(i<=n&&i-K>=1) {
			for(int j=0;j<=n;j++) {
				for(int k=0;max(k,j+1)<=K;k++) {
					add(g[i][j+1][max(k,j+1)+1],g[i-2][j][k]);
				}
			}
		}
		p=i;
	}
	int ans=0;
	for(int i=0;i<=n;i++) {
		for(int j=0;j<=K+1;j++) {
			add(ans,g[p][i][j]);
		}
	}
	printf("%d\n",ans);
}
int main() {
	scanf("%d%d%d",&n,&K,&MD);
	if(K%2==0) solve1();
	else solve2();
	return 0;
}

Measured memory_bytes: 27776
#ifdef LOCAL
#include "libs/debug/print_list.hpp"
#define debug(x) (cout << # x ": " << x << endl)
#define dev(v, m, n) for(int i=0;i<n;++i){for(int j=0;j<m;++j){cout<<"|"<<v[j][i];}cout<<"|"<<endl;}
#else
#define debug(x) ;
#define dev(v, m, n) ;
#endif

// :----------------------------------------

#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define int long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define capi(x) int x;cin>>x
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using vi = vector<int>;
using pi = pair<int, int>;
using vp = vector<pi>;

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

#define P (1'000'000'007)

signed main() {
    capi(n);

    int a, b, c;
    cin >> a >> b >> c;

    vi vl;

    rep(i, n) {
        capi(l);
        vl.push_back(l);
    }

    int ans = INT_MAX;

    rep(i, 1 << n) {
        rep(j, 1 << n) {
            vector<int> sa, sb, sc;
            rep(k, n) {
                int bx = (i >> k) & 1;
                int by = (j >> k) & 1;
                if (bx == 1 && by == 0) sa.push_back(vl[k]);
                else if (bx == 0 && by == 1) sb.push_back(vl[k]);
                else if (bx == 1 && by == 1) sc.push_back(vl[k]);
            }

            if (sa.empty() || sb.empty() || sc.empty()) continue;

            int res = (sa.size() + sb.size() + sc.size() - 3) * 10;
            int acc = 0;
            rep(i, sa.size()) {
                acc += sa[i];
            }
            res += abs(acc - a);
            acc = 0;

            rep(i, sb.size()) {
                acc += sb[i];
            }
            res += abs(acc - b);
            acc = 0;

            rep(i, sc.size()) {
                acc += sc[i];
            }
            res += abs(acc - c);

            chmin(ans, res);
        }
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 3200
N,m=input().split()
M=int(m)
As_org=[]
As_org=input().split()
As=sorted([int(i) for i in As_org], reverse=True)

Amax = int(max(As))
total=sum(As)

frag=0
i=0

while i <=M-1:
    Ai=As[i]
    if Ai < total/ (4*M):
        frag +=1
        break
    i+=1
if frag>0:
    print("No")
else:
    print("Yes")
    

Measured memory_bytes: 3064
n,x,m = map(int,input().split())

li = [i%m for i in range(m)]
lin = [i**2%m for i in li]
fra = [0]*m

def calc(num):
    return lin[num]

count = 1
now = x
point = x
kakutei = 0
poilis = [x]

for _ in range(n-1):
    now = calc(now)
    if fra[now] == 1:
        kakutei = poilis.index(now)
        break
    fra[now] = 1
    count += 1
    poilis.append(now)
    point += now

poipoi = poilis[kakutei:]

point2 = sum(poilis[:kakutei])
point -= point2

kai = 0

kai += point2

kai += sum(poipoi)*((n-kakutei)//(count-kakutei))+sum(poipoi[:(n-kakutei)%(count-kakutei)])

print(kai)

Measured memory_bytes: 78632
func readIntPair() -> (Int, Int) {
    let line = readLine()!.split(separator: " ").map({Int($0)!})
    return (line[0], line[1])
}

func readDistSquare() -> Int {
    let (X, Y) = readIntPair()
    return X * X + Y * Y
}

let (N, D) = readIntPair()
let threshold = D * D
print((1...N).reduce(0) { i, j in
    i + (threshold < readDistSquare() ? 0 : 1)
})


Measured memory_bytes: 8180
while True:
    n = input()
    if n == 0:
        break
    candidate = {}
    for i in range(n):
        words = raw_input().split(" ")
        for word in words:
            for key in candidate.iterkeys():
                if key == word:
                    candidate[key] += 1
                    break
            else:
                candidate[word] = 1
    head = raw_input()
    find_words = {}
    for key in candidate.iterkeys():
        if key[0] == head:
            find_words[key] = candidate[key]
    size_of_words = len(find_words)
    if size_of_words == 0:
        print "NA"
    else:
        for_print = []
        i = 1
        while len(find_words) != 0:
            eq_num_list = []
            for key in sorted(find_words.items()):
                s = key[0]
                if find_words[key[0]] == i:
                    eq_num_list.append(s)
                    find_words.pop(key[0])

            i += 1
            eq_num_list.reverse()
            for_print += eq_num_list

        for_print.reverse()
        print " ".join(for_print[0:5])

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

int N,K;
vector<P> g[100010];
int col[100010];

void dfs(int v,int pre,int c,int idx){
  col[idx]=c;
  int crt=0;
  for(P e : g[v]){
    if(e.fi==pre)continue;
    if(crt==c)crt++;
    dfs(e.fi,v,crt++,e.se);
  }
}

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

  cin>>N;
  int r=-1;
  rep(i,N-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    g[a].push_back(P(b,i));
    g[b].push_back(P(a,i));
  }
  rep(i,N){
    if(K<g[i].size()){
      K=g[i].size();
      r=i;
    }
  }
  int crt=0;
  for(P e : g[r]){
    dfs(e.fi,r,crt++,e.se);
  }
  cout<<K<<endl;
  rep(i,N-1)cout<<col[i]+1<<endl;

  return 0;
}


Measured memory_bytes: 10496
from fractions import gcd
n = int(input())
a = [int(x) for x in input().split()]
g = a[0]
for i in a:
    g = i*g//gcd(i,g)
ans = 0
for i in range(n):
    ans+=int(g//a[i])
print(ans%(10**9+7))

Measured memory_bytes: 6112
from collections import Counter


def solve(string):
    n, *rest = string.split()
    n = int(n)
    count = Counter(rest[:n])
    m = rest[n]
    count -= Counter(rest[n + 1:])
    return str(max(max(count.values()), 0)) if len(count) > 0 else "0"


if __name__ == '__main__':
    n = int(input())
    ins = '{}\n'.format(n) + '\n'.join([input() for _ in range(n)])
    m = int(input())
    print(solve(ins + '\n{}\n'.format(m) + '\n'.join([input() for _ in range(m)])))


Measured memory_bytes: 3316
n,k = map(int,input().split())
# n,k = map(int,"8 5".split())
xn = list(map(int,input().split()))
# xn = list(map(int,"-9 -7 -4 -3 1 2 3 4".split()))

ans = float("inf")
for i in range(n-k+1):
#     print(xn[i],xn[n-k+i])
#     print(xn[i:i+k])
    tmp = min(abs(xn[i]),abs(xn[k+i-1])) + xn[k+i-1] - xn[i]
#     print("始点 is {}, 終わり is {}, 始まり is {}".format(min(abs(xn[i]),abs(xn[k+i-1])), xn[k+i-1],xn[i]))
#     print("tmp is {}".format(tmp))
    if tmp < ans:
        ans=tmp
print(ans)

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

vector<vector<ll>> ds;

void calc(vector<ll> v, ll n, ll m) {
  if (v.size() == n) {
    ds.push_back(v);
    return;
  }

  for (ll i = v[v.size()-1]; i <= m; ++i) {
    vector<ll> vv = v;
    vv.push_back(i);
    calc(vv, n, m);
  }
}


int main() {
  ll n, m, q;
  cin >> n >> m >> q;

  vector<ll> a(q);
  vector<ll> b(q);
  vector<ll> c(q);
  vector<ll> d(q);
  for (ll i = 0; i < q; ++i) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--;
    b[i]--;
  }

  ll ans = 0;
  vector<ll> v(1, 1);
  calc(v, n, m);
  each (v, ds) {
    ll cnt = 0;
    for (ll i = 0; i < q; ++i) {
      if (v[b[i]]-v[a[i]] == c[i]) {
        cnt += d[i];
      }
    }

    ans = max(ans, cnt);
  }

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


Measured memory_bytes: 8988
S = list(input())
ans = []
count_ = []
for i in range(4):
	if S[i] not in ans:
		ans.append(S[i])
		count_.append(1)
	else:
		count_[ans.index(S[i])] += 1

if count_[0] == 2 and count_[1] == 2:
	print("Yes")
else:
	print("No")

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

using namespace std;

typedef long long ll;

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

    int a, b, t;
    cin >> a >> b >> t;

    int sum = 0;
    for (int i = 0; i < t / a; i++) {
        sum += b;
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
import sys

k,n = (int(i) for i in input().split())

a = [int(i) for i in input().split()]



kyori = [None]*(n-1)

kyori[0] = a[0]-a[-1]+k
for i in range(1,n-1):
    kyori[i] = a[i+1]-a[i]

max = max(kyori)

print(k-max)


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

int main(){

  int n,s;
  int ans=1000000,sum=0,cnt=0,j=0;
  vector<int> a;

  cin >> n >> s;
  a.resize(n);

  for(int i=0; i<n; i++)cin >> a[i];


  for(int i=0; i<n; i++){

    while(sum<s && j<n){
      sum += a[j];
      cnt++;
      j++;
    }

    if(sum>=s)
      ans = min(ans,cnt);


    sum -= a[i];
    cnt--;
  }

  (ans!=1000000)?cout << ans << endl:cout << 0 << endl;


  return 0;
}

Measured memory_bytes: 3096
s = int(input())

f_n = [s]

while True:
  if f_n.count(f_n[-1]) == 2:
    break
  
  if f_n[-1] % 2 == 0:
    f_n.append(f_n[-1] / 2)
  else:
    f_n.append(3 * f_n[-1] + 1)

print(len(f_n))

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

int main() {
  int intA, intB, intC, intD;
  cin >> intA >> intB >> intC >> intD;

  if ((intA + intB) > (intC + intD)) {
    cout << "Left" << endl;
  }
  else if ((intA + intB) == (intC + intD)) {
    cout << "Balanced" << endl;
  }
  else{
    cout << "Right" << endl;
  }    

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(int X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end() 
#define CERR if(false) cerr

using namespace std;

ll manhattan(int y1, int x1, int y2, int x2){
    return abs(y1 - y2) + abs(x1 - x2);
}

int main(){

    int h,w,d,q,l,r,tmp;
    cin >> h >> w >> d;
    map<int, pair<int,int>> m;

    rep(i,h){
        rep(j,w){
            cin >> tmp;
            m[tmp] = mpair(i,j);
        }
    }

    vector<vector<ll>> v;
    vector<ll> tmpv(1);

    rep(i,d){
        v.pback(tmpv);
    }

    rep(i,d){
        int index = i + 1 + d;
        int prevy = m[i + 1].first;
        int prevx = m[i + 1].second;
        int nexty, nextx;
        int k = 0;
        while(index <= h * w){
            nexty = m[index].first;
            nextx = m[index].second;
            v[i].pback(v[i][k] + manhattan(prevy, prevx, nexty, nextx));
            index += d;
            k++;
            prevy = nexty;
            prevx = nextx;
        }
    }

    cin >> q;
    
    rep(i,q){
        cin >> l >> r;

        int mod = (l - 1) % d;
        int lindex = (l - 1) / d;
        int rindex = (r - 1) / d;
        ll ans = v[mod][rindex] - v[mod][lindex];

        cout << ans << endl;

    }

    return 0; 
}

Measured memory_bytes: 12084
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String t = sc.next();
    int count = 0;
    for(int i = 0; i < s.length(); i++){
      if(s.charAt(i) != t.charAt(i)){
        count++;
      }
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 41308
#include <bits/stdc++.h>
using namespace std;
#define sc scanf
#define pr printf
int n;
int dpt[5][5][5][101];
// proibidos: agc, acg, gac, a*gc, ag*c
int dp(int a, int b, int c, int d) {
    if(d == n) { return 1;}
    if(dpt[a][b][c][d] != -1) return dpt[a][b][c][d];
    set<int> s = {1, 2, 3, 4};
    if((a == 1 && c == 3) || (a == 1 && b == 3) || (b == 1 && c == 3) || (b == 3 && c == 1)) {
        s.erase(2);
    }
    if (b == 1 && c == 2) {
        s.erase(3);
    }
    int r = 0;
    for(set<int>::iterator it = s.begin(); it != s.end(); it++) {
        r = (r + dp(b, c, *it, d+1)) % 1000000007;
    }
    dpt[a][b][c][d] = r;
    return r;
}
 
int main(){
    memset(dpt, -1, sizeof dpt);
 	sc("%d", &n);
    pr("%d\n", dp(0, 0, 0, 0));
 	return 0;
}


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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, X, Y; cin >> N >> X >> Y;
    int cnt[N] = {};
    for(int i = 1; i <= X; i++){
        for(int j = i+1; j <= N; j++){
            int dist = min(j-i, (X-i) + 1 + abs(Y-j));
            cnt[dist]++;
        }
    }
    for(int i = X+1; i < Y; i++){
        for(int j = i+1; j <= N; j++){
            int dist = min(j-i, (i-X) + 1 + abs(Y-j));
            cnt[dist]++;
        }
    }
    for(int i = Y; i < N; i++){
        for(int j = i+1; j <= N; j++){
            cnt[j-i]++;
        }
    }

    for(int i = 1; i < N; i++) cout << cnt[i] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const ll MOD = 998244353;

string trs(string& s) {
    vector<int> cs(27, -1);
    int cnt = -1;
    string ret = "";
    for(char c : s) {
        int ic = c - 'a';
        if (cs[ic] == -1) {
            cs[ic] = ++cnt;
        }  
        ret += cs[ic] + 'a';
    }
    return ret;
}

int main() {
    string s, t;
    cin >> s >> t;
    string ret = trs(s) == trs(t) ? "Yes" : "No";
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 1168
import math

k = int(input())
mp = [[-1] * k for _ in range(k)]

def gcd(a, b):
    if b == 0:
        return a
    if mp[a - 1][b - 1] == -1:
        mp[a - 1][b - 1] = gcd(b, a % b)
        return mp[a - 1][b - 1]
    return mp[a - 1][b - 1]


ans = 0

for i in range(1, k + 1):
    for j in range(1, k + 1):
        for k in range(1, k + 1):
            ans += gcd(k, gcd(j, i))

print(ans)

Measured memory_bytes: 68992
fn main(){
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).unwrap();
	let vec: Vec<&str> = s.trim().split(' ').collect();
	if vec[0] == vec[1] {
		println!("{}", vec[2]);
	} else if vec[1] == vec[2] {
		println!("{}", vec[0]);
	} else if vec[0] == vec[2] {
		println!("{}", vec[1]);
	}
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		while (true) {
			int h = scanner.nextInt();
			int m = scanner.nextInt();
			int s = scanner.nextInt();
			if (h == -1 && m == -1 && s == -1) {
				break;
			}
			int sc = 7200 - (h * 3600 + m * 60 + s);
			int sc3 = sc * 3;
			System.out.println(String.format("%02d:%02d:%02d", sc / 3600,
					sc / 60 % 60, sc % 60));
			System.out.println(String.format("%02d:%02d:%02d", sc3 / 3600,
					sc3 / 60 % 60, sc3 % 60));
		}
	}
}

Measured memory_bytes: 18420
/* **********************************JAI SAI RAM ************************************* */
//HELP IN CODEFORCES ROUND 641
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll i,j,k,l,m,n,t,p,o,a,b,u,v;
    cin>>a>>u;
    cin>>b>>v;
    cin>>t;
    long double x=(abs(a-b));
    long double y=u-v,z;
    if(x==0)
    {
        cout<<"YES\n";
        return 0;
    }
    if(y<=0)
    {
        cout<<"NO\n";
        return 0;
    }
    z=x/y;
    if(z<=t)
    {
        cout<<"YES\n";
    }
    else
    cout<<"NO\n";
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define N_MAX 200002

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

class ModInt{
    public:
    ll v;
    ModInt(ll _v = 0){
        v = _v;
    }
    ModInt operator+(ll n){
        return ModInt((v+n)%MOD);
    }
    ModInt operator-(ll n){
        return ModInt((v-n+MOD)%MOD);
    }
    ModInt operator*(ll n){
        return ModInt((v*n)%MOD);
    }
    ModInt operator/(ll n){
        return ModInt((ModInt(n).inv()*v).v%MOD);
    }

    void operator+=(ll n){
        v = (v+n)%MOD;
    }
    void operator-=(ll n){
        v = (v-n+MOD)%MOD;
    }
    void operator*=(ll n){
        v = (v*n)%MOD;
    }
    
    
    ModInt operator+(ModInt n){
        return ModInt((v+n.v)%MOD);
    }
    ModInt operator-(ModInt n){
        return ModInt((v-n.v+MOD)%MOD);
    }
    ModInt operator*(ModInt n){
        return ModInt((v*n.v)%MOD);
    }
    ModInt operator/(ModInt n){
        return ModInt((n.inv()*v).v%MOD);
    }

    void operator+=(ModInt n){
        v = (v+n.v)%MOD;
    }
    void operator-=(ModInt n){
        v = (v-n.v+MOD)%MOD;
    }
    void operator*=(ModInt n){
        v = (v*n.v)%MOD;
    }

    void operator=(ModInt n){
        v = n.v;
    }
    void operator=(ll n){
        v = n;
    }

    ModInt inv(){
        if(v == 1) return ModInt(1);
        else return ModInt(MOD-ModInt(MOD%v).inv().v*(MOD/v)%MOD);
    }
};

ostream& operator<<(ostream& os, const ModInt& m){
    os << m.v;
    return os;
}

istream & operator >> (istream &in,  ModInt &m){
    in >> m.v;
    return in;
}

ModInt pow(ModInt a, ll n) {
	ModInt ans = 1;
	ModInt tmp = a;
	for (int i = 0; i <= 60; i++) {
		ll m = (ll)1 << i;
		if (m & n) {
		ans *= tmp;
		}
		tmp *= tmp;
	}
	return ans;
}

ModInt inv[N_MAX],fac[N_MAX],finv[N_MAX];

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

ModInt comb(ll n, ll r){
  if(n < r){
      return ModInt(0);
  }else{
      return fac[n]*finv[r]*finv[n-r];
  }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    ll S; cin >> S;
    init();
    ModInt ans = 0;
    for(int i = 1; 3*i <= S; i++){
        ll m = S-3*i;
        ans += comb(m+i-1, i-1);
    }
    cout << ans << endl;
}

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


int main(){
  int n;
  while(cin>>n){
    if(n==0) break;
    int s =0;
    vector<int>a(n);
    for(int i=0;i<n;i++){
      cin>>a[i];
      s+=a[i];
    }
   int d=s/n;
   int ans=0;
   for(int i=0;i<n;i++){
     if(a[i]<=d){
       ans++;
     }
   }
    cout<<ans<<endl;
    
  }
  
}




Measured memory_bytes: 3024
#include <stdio.h>
#include <string.h>

#define MAX_KETA 501

/*
[Êu][±êÜÅÌðMÅÁ½]è][OÌ]
[OÍñÂO©çÁ©¸­©][±êÜÅÌÍBÆêvµÄ¢é©]
OÍñÂO©çÁ©¸­©ÉÂ¢Ä
0FOÍ0ÈÌÅÖWÈ¢
1FÁ
2F¸­ 
*/
int memo[MAX_KETA][500][10][3][2];

int waru_amari(const char* a,int b) {
	int current=0;
	int i;
	for(i=0;a[i]!=0;i++) {
		current=(current*10+(a[i]-'0'))%b;
	}
	return current;
}

int is_zigzag(const char* a) {
	int i;
	int len;
	len=strlen(a);
	if(len==1)return 1;
	if(len==2) {
		if(a[0]!=a[1])return 1; else return 0;
	}
	for(i=2;i<len;i++) {
		if((a[i-2]-a[i-1])*(a[i-1]-a[i])>=0)return 0;
	}
	return 1;
}

int calc_zigzag(const char* max,int waru,int now,int amari,
		int pnum,int pisup,int ismax);

int main(void) {
	char input_A[MAX_KETA+1];
	char input_B[MAX_KETA+1];
	int waru_kazu;
	int result_A;
	int result_B;
	int result;
	scanf("%s",input_A);
	scanf("%s",input_B);
	scanf("%d",&waru_kazu);
	result_A=calc_zigzag(input_A,waru_kazu,0,0,0,0,1)+
		calc_zigzag(input_A,waru_kazu,0,0,0,1,1);
	memset(memo,0,sizeof(memo));
	result_B=calc_zigzag(input_B,waru_kazu,0,0,0,0,1)+
		calc_zigzag(input_B,waru_kazu,0,0,0,1,1);
	result=result_B-result_A;
	if(is_zigzag(input_A) && waru_amari(input_A,waru_kazu)==0) {
		result++;
	}
	if(result<0)result+=10000;
	printf("%d\n",result);
	return 0;
}

/*
waruF Üèðæé½ßÉé 
nowF»ÝÌÊu
amariFOÌÜÅÌ Üè 
pnumFOÌ
pisupFOÍÁµÄ¢é© 
*/
int calc_zigzag(const char* max,int waru,int now,int amari,
		int pnum,int pisup,int ismax) {
	int i;
	int start,end;
	int result=0;
	int next_pisup;
	if(max[now]==0) {
		if(amari==0)return 1; else return 0;
	}
	if(memo[now][amari][pnum][pisup][ismax]>0) {
		return memo[now][amari][pnum][pisup][ismax]-1;
	}
	if(pisup==1) {
		/*¸­³¹é*/
		start=0;
		end=pnum-1;
	} else if(pisup==2) {
		/*Á³¹é*/
		start=pnum+1;
		end=9;
	} else {
		/*OÍ0*/
		start=0;
		end=9;
	}
	if(ismax && end>max[now]-'0')end=max[now]-'0';
	for(i=start;i<=end;i++) {
		if(pisup==0) {
			if(pnum==0)next_pisup=0;
			else if(i<pnum)next_pisup=2;
			else if(i>pnum)next_pisup=1;
			else continue;
		} else {
			if(pisup==1)next_pisup=2; else next_pisup=1;
		}
		result+=calc_zigzag(max,waru,now+1,(amari*10+i)%waru,
			i,next_pisup,(ismax && i==max[now]-'0')?1:0);
	}
	result%=10000;
	memo[now][amari][pnum][pisup][ismax]=result+1;
	return result;
}

Measured memory_bytes: 57000
import java.util.*
import java.math.*
fun main(args: Array<String>) {

    var (N, K) = readLine()!!.split(" ").map { it.toInt() }
//    var N = readLine()!!.toInt()
//    val D = readLine()!!.split(" ").map { it.toLong() }
//    val A = readLine()!!.split(" ").map { it.toInt() }.toIntArray()

    val mod = 1000000007L
    val coin = IntArray(N){1}

    for (n in 1..N) {
        var k = n
        while (k < K) {
            k *= 2
            coin[n-1] *= 2
        }
    }

    var ans = 0.00000000000
    for (c in coin) {
        ans += 1.0/c.toDouble()
    }
    ans /= N.toDouble()
    println("%.9f".format(ans))
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int64_t rll() {
	long long n;
	scanf("%lld", &n);
	return n;
}

int main() {
	int a = ri();
	int b = ri();
	std::cout << (a - 1) / (2 * b + 1) + 1 << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int a[210000];

int main() {
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	if(n % 2) {
		for(int i = n - 1; i >= 0; i -= 2) cout << a[i] << ' ';
		for(int i = 1; i < n; i+= 2) cout << a[i] << ' ';
	} else {
		for(int i = n - 1; i >= 1; i -= 2) cout << a[i] << ' ';
		for(int i = 0; i < n; i += 2) cout << a[i] << ' ';
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 2944
from sys import stdin
input = lambda: stdin.readline().rstrip("\r\n")
from collections import defaultdict as vector, deque as que
read = lambda: list(map(int,input().split()))
from bisect import bisect
from heapq import heappush as hpush,heappop as hpop

n,=read()
ans=0
for i in range(1,n+1):
	c=n//i 
	k=(c*(c+1))//2
	ans+=i*k 
print(ans)


Measured memory_bytes: 66336
using System;

namespace Sample101
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var line = Console.ReadLine().Split(' ');
                var H = int.Parse(line[0]);
                var W = int.Parse(line[1]);
                if (H == 0 && W ==0)
                {
                    return;
                }

                for (int j = 0; j < H; j++)
                {
                    for (int i = 0; i < W; i++)
                    {
                        if (i == 0 || i == W - 1 || j == 0 || j == H - 1)
                        {
                            Console.Write("#");
                        }
                        else
                        {
                            Console.Write('.');
                        }
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
        }
    }
}


Measured memory_bytes: 13948
#include <iostream>

using namespace std;

int main() {
    int N; cin >> N;
    for (int i = 0; i < N; i++) {
        int cx = 0, cy = 0;
        int mx = 0, my = 0, md = 0;
        int dx, dy;
        while (cin >> dx >> dy) {
            if (dx == 0 && dy == 0) break;
            cx += dx, cy += dy;
            int cd = cx*cx + cy*cy;
            if (md < cd) {
                md = cd;
                mx = cx;
                my = cy;
            } else if (md == cd) {
                if (mx < cx) {
                    mx = cx;
                    my = cy;
                }
            } 
        }
        cout << mx << ' ' << my << endl;
    }
    return 0;
}

Measured memory_bytes: 0
H,W = map(int,input().split())
S = [ list(input()) for i in range(H)]

for i in range(H):
  for j in range(W):
    if S[i][j]=="#":
      if   i>=1 and S[i-1][j]=="#":
        continue
      elif i<=H-2 and S[i+1][j]=="#":
        continue
      elif j>=1 and S[i][j-1]=="#":
        continue
      elif j<=W-2 and S[i][j+1]=="#":
        continue
      else:
        print("No");exit()
print("Yes")


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

int main(){
  string S[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
  reverse(S, S+7);
  // mapでどの曜日が日曜日から何日後かを管理
  map <string, int> X;
  rep(i, 7) X[S[i]] = i + 1;

  string s;
  cin >> s;
  cout << X[s] << endl;
}


Measured memory_bytes: 3604
IDENTIFICATION DIVISION.
PROGRAM-ID. 152B.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP  PIC X(10).
01 A    PIC 9(1).
01 B    PIC 9(1).
01 N    PIC 9(1).
01 I    PIC 9(2).
01 OUT  PIC X(10).
*>
PROCEDURE DIVISION.
  ACCEPT INP.
  UNSTRING INP DELIMITED BY ' '
      INTO A B.
  IF (A <= B)
    MOVE B TO N
  ELSE
    MOVE A TO N
    MOVE B TO A
  END-IF.   
*>
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    MOVE A TO OUT(I:1)
  END-PERFORM.
*>
  DISPLAY OUT(1:N).
*>
  STOP RUN.


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

bool check(int t, int x, int y){
  if(x + y > t) return false;
  if((t - x - y) % 2 == 0) return true;
  return false;
}

int main(){
  int N;
  cin >> N;
  vector<int>t(N + 1);
  vector<int>x(N + 1);
  vector<int>y(N + 1);
  for(int i = 1; i <= N; i++){
    cin >> t.at(i) >> x.at(i) >> y.at(i);
  }
  bool a = true;
  int i = 0;
  for(int i = 0; i < N; i++){
    a = check(t.at(i + 1) - t.at(i), x.at(i + 1) - x.at(i), y.at(i + 1) - y.at(i));
    if(!a) break;
  } 
  if(a) {
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
}


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

int main() {
  int N, sum;
  cin >> N;
  sum = 0;
  for(int i = 1; i <= N; i*=10) {
    sum += N / i - N / (i * 10) * 10;
  }
  if(N % sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3608
#include <iostream>

using namespace std;

int main() {
    string s;
    cin >> s;
    string t;
    cin >> t;
    int count = 0;
	for(int i = 0; i < s.size(); i++) {
		if(s[i] != t[i])
		    count++;
	}
	cout << count;
}

Measured memory_bytes: 3912
#include<iostream>
#include<algorithm>
using namespace std;
int a[1312],b[1225];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;++i)cin>>a[i];
	sort(a+1,a+n+1);
	int now=0,tot=0,tmp;
	for(int i=n;i>=1;--i)
	if(a[i]%10)tot++,tmp=i;
	if(tot==0){cout<<0;return 0;}
	long long ans=0;
	for(int i=1;i<=n;++i)ans+=a[i];
	
	if(ans%10==0)ans-=a[tmp];
	cout<<ans;
	return 0;
}

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

using namespace std;

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

  vector<int> va(n);
  bool has_neg = false, has_pos = false;
  for (int i = 0; i < n; ++i) {
    cin >> va[i];
    if (va[i] >= 0) {
      has_pos = true;
    } else {
      has_neg = true;
    }
  }

  if (has_pos && !has_neg) {
    cout << n - 1 << '\n';
    for (int i = 0; i < n - 1; ++i) {
      cout << i + 1 << ' ' << i + 2 << '\n';
    }
    return 0;
  } else if (!has_pos && has_neg) {
    cout << n - 1 << '\n';
    for (int i = n - 1; i > 0; --i) {
      cout << i + 1 << ' ' << i << '\n';
    }
    return 0;
  }

  auto max_abs = [&]() {
    int max_a = va.front(), idx = 0;
    for (int i = 0; i < va.size(); ++i) {
      if (abs(max_a) < abs(va[i])) {
        max_a = va[i];
        idx = i;
      }
    }

    return idx;
  };

  int idx = max_abs();
  int max_a = va[idx];
  cout << (n - 1) * 2 << '\n';
  for (int i = 0; i < n; ++i) {
    if (idx != i) {
      cout << idx + 1 << ' ' << i + 1 << '\n';
    }
  }

  if (max_a >= 0) {
    for (int i = 0; i < n - 1; ++i) {
      cout << i + 1 << ' ' << i + 2 << '\n';
    }
    return 0;
  } else if (max_a < 0) {
    for (int i = n - 1; i > 0; --i) {
      cout << i + 1 << ' ' << i << '\n';
    }
    return 0;
  }
}

Measured memory_bytes: 3592
#include<iostream>
#include<string>
#include<cstring>
using namespace std;

int main(){
	int m, h;
	string str, str1, str2;

	while (1){
		cin >> str;

		if (str == "-") break;

		cin >> m;

		for (int i = 0; i < m; i++){
			cin >> h;

			str1 = str.substr(0, h);
			str2 = str.substr(h, str.size() - h);

			str = str2 + str1;
		}

		cout << str << endl;

	}
	
	return 0;
}

Measured memory_bytes: 1216
A, B, M = map(int, input().split())
a, b = [], []
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x, y, c = [], [], []
for i in range(M):
  tmp = list(map(int, input().split()))
  x.append(tmp[0])
  y.append(tmp[1])
  c.append(tmp[2])

# 割引券なし
min_a, min_b, min_total_wo = 10**5+1, 10**5+1, 0
for i in range(A):
  if min_a > a[i]:
    min_a = a[i]
for i in range(B):
  if min_b > b[i]:
    min_b = b[i]
min_total_wo = min_a + min_b
  
# 割引券あり
min_total_w = 2*10**5+1
for i in range(M):
  tmp = a[x[i]-1] + b[y[i]-1] - c[i]
  if min_total_w > tmp:
    min_total_w = tmp
if min_total_wo < min_total_w:
  print(min_total_wo)
else:
  print(min_total_w)

Measured memory_bytes: 24748
#include<stdio.h>
int main(void)
{
	int n,m,i,j,w,x,flg;
	int a[1001],b[1001],c[1001];
	while(1){
		scanf("%d %d",&n,&m);
		if(n==0&&m==0) break;
		for(i=1;i<=n;i++) scanf("%d",&a[i]);
		for(i=1;i<=m;i++) scanf("%d",&b[i]);
		w=1; x=0; 
		for(j=1;j<=m;j++){
			w+=b[j]; w+=a[w];
			if(w<=0) w=1;
			if(w>=n){
				x=j;  break;
			}
		}
		printf("%d\n",x);
	}
	return 0;
}

Measured memory_bytes: 2608
import sys

n = int(sys.stdin.readline().strip())
t, a = map(int, sys.stdin.readline().strip().split(" ", 2))
H = map(int, sys.stdin.readline().strip().split(" "))

temp = map(lambda h: abs(a-(t-h*0.006)), H)

min_temp = 99999
min_i = -1
for i, t in enumerate(temp):
    if min_temp > t:
        min_temp = t
        min_i = i+1

print min_i



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

int main() {
  int N,box;
  int a=0;
  cin >>N;
  vector <int>v(N);
  int x;
  cin >>v[0];
  for(int i=1;i<N;i++){
    cin >>x;
    for(int j=0;j<i;j++){
       if(v[j]>x){
         box=v[j];
         v[j]=x;
         x=box;
       }
     }
     v[i]=x;
  }
  for(int i=0;N-i-1>=0;i++){
    a=a+v[N-i-1]*pow((-1),i);
  }
  cout<<a<<endl;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define int long long
int32_t main()
{
 int n,m,x; cin>>n>>m>>x;
 int f[n]={0};
 for(int i=0; i<m; i++){
  int x; cin>>x;
  f[x]=1; 
 }
 int ans=0, ans2=0;
 for(int i=x+1; i<=(n-1); i++){
  if(f[i]==1) ans+=1;
 }
 for(int i=x-1; i>=1; i--){
  if(f[i]==1) ans2+=1;
 }

 cout<< min(ans, ans2) <<endl;
 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/
int digits(ll m){
    int re = 0;
    while(m > 0){
        m /= 10;
        re++;
    }
    return re;
}
int main(){
    string s, t; cin >> s >> t;
    int n = s.size();
    bool flag = true;
    map<char,char> mas, mat;
    char a, b;
    for(int i = 0; i < n; i++){
        a = s[i];
        b = t[i];
        if(mas.count(a)){
            if(mas[a] != b) flag = false;
        }
        if(mat.count(b)){
            if(mat[b] != a) flag = false;
        }
        mas[a] = b;
        mat[b] = a;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 776
import sys
h, w = [int(i) for i in sys.stdin.readline().split()]
s_ls = []
for y in range(h):
    s = input()
    s_ls.append(s)
r_ij = [[0 for i in range(w)] for j in range(h)]
l_ij = [[0 for i in range(w)] for j in range(h)]
d_ij = [[0 for i in range(w)] for j in range(h)]
u_ij = [[0 for i in range(w)] for j in range(h)]
for y in range(h):
    for x in range(w):
        if s_ls[y][x] == "#":
            continue
        r_ij[y][x] = r_ij[y][max(0, x-1)] + 1
        d_ij[y][x] = d_ij[max(0, y-1)][x] + 1
for y in range(h-1,-1,-1):
    for x in range(w-1,-1,-1):
        if s_ls[y][x] == "#":
            continue
        l_ij[y][x] = l_ij[y][min(w-1, x+1)] + 1
        u_ij[y][x] = u_ij[min(y+1, h-1)][x] + 1

best = -1e10
for y in range(h):
    for x in range(w):
        res = r_ij[y][x] + l_ij[y][x] + u_ij[y][x] + d_ij[y][x] - 3
        if res > best:
            best = res
print(best)

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


int main()
{
  string s;
  cin>>s;
  char dummy =s[s.length()-1];
  if(dummy=='s')
  {
  
  		cout<<s<<"es"<<endl;
  }
  else
  {
  	cout<<s<<"s"<<endl;
  }
  
  
return 0;
}



Measured memory_bytes: 3632
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL N;
	in >> N;
	std::vector<LL>M(N);
	std::vector<std::vector<LL>>c(N);
	rep(i, N)
	{
		in >> M[i];
		c[i].resize(M[i]);
		rep(j, M[i]) in >> c[i][j];
	}

	LL ans = 0;
	std::priority_queue<LL, std::vector<LL>>queue;
	for (LL i = N - 1; i >= 0; --i)
	{
		rep(j, M[i]) queue.push(c[i][j]);
		ans += queue.top();
		queue.pop();
	}

	out << ans << std::endl;
}



Measured memory_bytes: 21476
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに実装したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			// 町と町の間の移動最短距離
			int[][] a = new int[n][n];
			IntStream.range(0, n).forEach(i -> IntStream.range(0, n).forEach(j -> a[i][j] = scanner.nextInt()));
			if (!warshallFloyd(a, n)) {
				System.out.println(-1);
				return;
			}
			System.out.println(IntStream.range(0, n)
					.mapToLong(i -> IntStream.range(i + 1, n).mapToLong(j -> getResult(i, j, a, n)).sum()).sum());
		}
	}

	/**
	 * 町と町の間の移動最短距離をワーシャル–フロイド法で計算する
	 * 
	 * @param d 町と町の間の移動最短距離の配列
	 * @param n 町の数
	 * @return すでに最短距離であるかどうか
	 */
	private static boolean warshallFloyd(int[][] d, int n) {
		for (int k = 0; k < n; k++) {
			for (int j = 0; j < n; j++) {
				for (int i = 0; i < n; i++) {
					if (d[i][k] + d[k][j] < d[i][j]) {
						return false;
					}
				}
			}
		}
		return true;
	}

	/**
	 * @param u 始点の町
	 * @param v 終点の町
	 * @param a 町の町の間の最短距離
	 * @param n 町の数
	 * @return uとvの間に道路が存在する場合、その長さ。存在しない場合は0
	 */
	private static long getResult(final int u, final int v, final int[][] a, final int n) {
		if (u == v) {
			return 0L;
		}
		for (int i = 0; i < n; i++) {
			if ((i != u) && (i != v) && (a[u][i] + a[i][v] == a[u][v])) {
				return 0L;
			}
		}
		return a[u][v];
	}
}


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

int main()
{

        int n;
        cin >> n;
        int a[210000];
        for (int i = 0; i < n; ++i) {
                cin >> a[i];
        }
        std::sort(a, a+n);
         for (int i = 0; i < n-1; ++i) {
                if (a[i] == a[i+1]) {
                        cout << "NO" << endl;
                        return 0;
                }
        }
        cout << "YES" << endl;

}


Measured memory_bytes: 1024
#include <math.h>
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#include<stdio.h>
#include <iostream>
#include <vector>
#include <set>
//#include <string.h>
using namespace std;
using Graph = vector<vector<int>>;
queue<long>que;

int main(){
    long n, k;
    vector<int>a;
    cin >> n>>k;
    rep(i,n){
        int a1;
        cin >> a1;
        a.push_back(a1-1);
    }
    //return 1
    int now = 0;
    //int cnt = 0;
    int preloop=0,loopnum=0;
    //bool loop = true;
    vector<int>jump;
    vector<int>been(n,-1);
    rep(i,n){
        int next = a[now];
        been[now] = i;
        //i+1回目jump
        jump.push_back(next);
        if(been[next]>=0){
            preloop=been[next];
            loopnum=i+1-preloop;
            break;
        }
        now =next;
    }
    
    int ans;
    //
    if(k<=preloop){
        ans = jump[k-1];
    }
    else{
        k = k-preloop;
        k = k%loopnum;
        jump.erase(jump.begin(),jump.begin()+preloop);
        if(k==0)k=loopnum;
        ans =jump[k-1];
    }
    
    cout<< ans+1 <<endl;
}


Measured memory_bytes: 6360